Skip to content

Commit

Permalink
daemon: Update to inotify handling of files
Browse files Browse the repository at this point in the history
dnf install creates tmp files and then does 'mv' to the actual files.
As a result new packages added using dnf were not detected by daemon
since shell.json would not exist. Take care of it in the move notification.

While at it, change list output to show number of slots as 0 for flat shell
designs.

Signed-off-by: Puja Gupta <pujag@xilinx.com>
  • Loading branch information
pujag-xlnx committed Aug 12, 2021
1 parent 50fd8b7 commit 9866844
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ the corresponding path to cmake in build.sh.
$ cd build
$ ../build.sh
```
After build succesfully completes, library can be found under `build/usr/local/lib`
After build successfully completes, library can be found under `build/usr/local/lib`
and binary can be under `build/usr/local/bin`.

## Known limitations
Expand Down
2 changes: 1 addition & 1 deletion example/sys/linux/dfx-mgr-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ int main(int argc, char *argv[])
if (ret <= 0)
printf("No message recieved\n");
if (atoi(recv_message.data) == 0)
printf("Accelerator succesfully removed.\n");
printf("Accelerator successfully removed.\n");
else
printf("Error trying to remove accelerator.\n");
} else if(!strcmp(argv[1],"-listPackage")) {
Expand Down
57 changes: 39 additions & 18 deletions src/daemon_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct basePLDesign *findBaseDesign_path(const char *path){
for (i = 0; i < MAX_WATCH; i++) {
if (base_designs[i].base_path[0] != '\0') {
if(!strcmp(base_designs[i].base_path, path)) {
acapd_print("%s: Found base design %s\n",__func__,base_designs[i].base_path);
acapd_debug("%s: Found base design %s\n",__func__,base_designs[i].base_path);
return &base_designs[i];
}
for (j=0;j <10; j++){
Expand Down Expand Up @@ -386,6 +386,13 @@ char *listAccelerators()
if (base_designs[i].base_path[0] != '\0' && base_designs[i].num_slots > 0) {
for (j = 0; j < 10; j++) {
if (base_designs[i].accel_list[j].path[0] != '\0') {
int slots;
/* Internally flat shell is treated as one slot to make the code generic and save info of the active design */
if (!strcmp(base_designs[i].type,"XRT_FLAT"))
slots = 0;
else
slots = base_designs[i].num_slots;

if (base_designs[i].active) {
char active_slots[20] = "";
char tmp[4];
Expand All @@ -398,15 +405,15 @@ char *listAccelerators()
}
if (strcmp(active_slots, ""))
sprintf(msg,"%32s%32s%15s%10d%20s\n",base_designs[i].accel_list[j].name, base_designs[i].name,
base_designs[i].type, base_designs[i].num_slots,active_slots);
base_designs[i].type, slots,active_slots);
else
sprintf(msg,"%32s%32s%15s%10d%20d\n",base_designs[i].accel_list[j].name,base_designs[i].name,
base_designs[i].type,base_designs[i].num_slots,-1);
base_designs[i].type, slots,-1);
strcat(res,msg);
}
else {
sprintf(msg,"%32s%32s%15s%10d%20d\n",base_designs[i].accel_list[j].name,base_designs[i].name,
base_designs[i].type,base_designs[i].num_slots,-1);
base_designs[i].type, slots,-1);
strcat(res,msg);
}
}
Expand Down Expand Up @@ -540,8 +547,12 @@ void add_base_design(char *name, char *path, char *parent, int wd)
return;
}
for (i = 0; i < MAX_WATCH; i++) {
if (!strcmp(base_designs[i].base_path,path)){
acapd_debug("Base design %s already exists\n",path);
return;
}
if (base_designs[i].base_path[0] == '\0') {
acapd_debug("adding base design %s\n",path);
acapd_debug("Adding base design %s\n",path);
strncpy(base_designs[i].name, name, sizeof(base_designs[i].name)-1);
base_designs[i].name[sizeof(base_designs[i].name) - 1] = '\0';
strncpy(base_designs[i].base_path, path, sizeof(base_designs[i].base_path)-1);
Expand Down Expand Up @@ -721,15 +732,15 @@ void *threadFunc()
acapd_debug("%s: add inotify watch on %s\n",__func__,new_dir);
wd = inotify_add_watch(inotifyFd, new_dir, IN_ALL_EVENTS);
if (wd == -1)
printf("inotify_add_watch failed on %s\n",new_dir);
acapd_perror("inotify_add_watch failed on %s\n",new_dir);
add_to_watch(wd, new_dir);
add_base_design(event->name, new_dir, parent, wd);

}
else if(!strcmp(event->name,"shell.json")) {
parent = wd_to_pathname(event->wd);
base = findBaseDesign_path(parent);
sprintf(fname,"%s/%s",parent,"shell.json");
sprintf(fname,"%s/%s",parent,event->name);
initBaseDesign(base, fname);
parse_packages(base,parent);
}
Expand All @@ -740,7 +751,6 @@ void *threadFunc()
break;
sprintf(new_dir,"%s/%s",parent, event->name);
acapd_debug("Removing watch on %s parent %s\n",event->name, parent);
acapd_debug("%s:removing watch on %s \n",__func__,new_dir);
remove_watch(new_dir);
remove_base_design(new_dir, parent);
}
Expand All @@ -751,16 +761,27 @@ void *threadFunc()
sprintf(new_dir,"%s/%s",parent, event->name);
remove_base_design(new_dir, parent);
}
else if((event->mask & IN_MOVED_TO) && (event->mask & IN_ISDIR)) {
char * parent = wd_to_pathname(event->wd);
if (parent == NULL)
break;
sprintf(new_dir,"%s/%s",parent, event->name);
add_base_design(event->name, new_dir, parent, event->wd);
base = findBaseDesign_path(new_dir);
sprintf(fname,"%s/%s",new_dir,"shell.json");
initBaseDesign(base, fname);
parse_packages(base,new_dir);
else if(event->mask & IN_MOVED_TO){
/*
* 'dnf install' creates tmp filenames and then does 'mv' to desired filenames.
* Hence IN_CREATE notif will be on tmp filenames, add logic in MOVED_TO notification for
* shell.json
*/
if(event->mask & IN_ISDIR || !strcmp(event->name,"shell.json")){
char * parent = wd_to_pathname(event->wd);
if (parent == NULL)
break;
if (event->mask & IN_ISDIR){
sprintf(new_dir,"%s/%s",parent, event->name);
add_base_design(event->name, new_dir, parent, event->wd);
} else {
sprintf(new_dir,"%s",parent);
}
base = findBaseDesign_path(new_dir);
sprintf(fname,"%s/%s",new_dir,"shell.json");
initBaseDesign(base, fname);
parse_packages(base,new_dir);
}
}
p += sizeof(struct inotify_event) + event->len;
}
Expand Down
2 changes: 2 additions & 0 deletions src/sys/linux/json-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ int initBaseDesign(struct basePLDesign *base, const char *shell_path)
base->load_base_design = 0;
}
}
if (!strcmp(base->type,"XRT_FLAT"))
base->num_slots = 1;
return 0;
}

Expand Down

0 comments on commit 9866844

Please sign in to comment.