Browse Source

[LibOS] Fix an ambiguous intepretation of a shim handle

It's interpreted both as a chroot file handle and as a directory handle.
Chia-Che Tsai 4 years ago
parent
commit
f98966265d

+ 2 - 1
LibOS/shim/include/shim_handle.h

@@ -349,7 +349,6 @@ struct shim_handle {
         struct shim_dev_handle    dev;
         struct shim_pipe_handle   pipe;
         struct shim_sock_handle   sock;
-        struct shim_dir_handle    dir;
         struct shim_shm_handle    shm;
         struct shim_msg_handle    msg;
         struct shim_sem_handle    sem;
@@ -358,6 +357,8 @@ struct shim_handle {
         struct shim_epoll_handle  epoll;
     } info;
 
+    struct shim_dir_handle    dir_info;
+
     int                 flags;
     int                 acc_mode;
     IDTYPE              owner;

+ 1 - 1
LibOS/shim/src/bookkeep/shim_handle.c

@@ -470,7 +470,7 @@ void close_handle (struct shim_handle * hdl)
 
     if (!opened) {
         if (hdl->type == TYPE_DIR) {
-            struct shim_dir_handle * dir = &hdl->info.dir;
+            struct shim_dir_handle * dir = &hdl->dir_info;
 
             if (dir->dot) {
                 put_dentry(dir->dot);

+ 11 - 11
LibOS/shim/src/fs/shim_namei.c

@@ -620,18 +620,18 @@ int dentry_open (struct shim_handle * hdl, struct shim_dentry * dent,
 
         // Set dot and dot dot for some reason
         get_dentry(dent);
-        hdl->info.dir.dot = dent;
+        hdl->dir_info.dot = dent;
 
         if (dent->parent) {
             get_dentry(dent->parent);
-            hdl->info.dir.dotdot = dent->parent;
+            hdl->dir_info.dotdot = dent->parent;
         } else
-            hdl->info.dir.dotdot = NULL;
+            hdl->dir_info.dotdot = NULL;
 
         // Let's defer setting the DENTRY_LISTED flag until we need it
         // Use -1 to indicate that the buf/ptr isn't initialized
-        hdl->info.dir.buf = (void *)-1;
-        hdl->info.dir.ptr = (void *)-1;
+        hdl->dir_info.buf = (void *)-1;
+        hdl->dir_info.ptr = (void *)-1;
     }
     path = dentry_get_path(dent, true, &size);
     if (!path) {
@@ -771,15 +771,15 @@ int list_directory_handle (struct shim_dentry * dent, struct shim_handle * hdl)
     int nchildren = dent->nchildren, count = 0;
     struct shim_dentry * child;
 
-    assert(hdl->info.dir.buf == (void *)-1);
-    assert(hdl->info.dir.ptr == (void *)-1);
+    assert(hdl->dir_info.buf == (void *)-1);
+    assert(hdl->dir_info.ptr == (void *)-1);
 
     // Handle the case where the handle is on a rmdir-ed directory
     // Handle is already locked by caller, so these values shouldn't change
     // after dcache lock is acquired
     if (dent->state & DENTRY_NEGATIVE) {
-        hdl->info.dir.buf = NULL;
-        hdl->info.dir.ptr = NULL;
+        hdl->dir_info.buf = NULL;
+        hdl->dir_info.ptr = NULL;
         return 0;
     }
 
@@ -804,8 +804,8 @@ int list_directory_handle (struct shim_dentry * dent, struct shim_handle * hdl)
     }
     children[count] = NULL;
 
-    hdl->info.dir.buf = children;
-    hdl->info.dir.ptr = children;
+    hdl->dir_info.buf = children;
+    hdl->dir_info.ptr = children;
 
     unlock(&dcache_lock);
 

+ 2 - 2
LibOS/shim/src/sys/shim_open.c

@@ -353,7 +353,7 @@ size_t shim_do_getdents (int fd, struct linux_dirent * buf, size_t count)
        updated */
     lock(&hdl->lock);
 
-    struct shim_dir_handle * dirhdl = &hdl->info.dir;
+    struct shim_dir_handle * dirhdl = &hdl->dir_info;
     struct shim_dentry * dent = hdl->dentry;
     struct linux_dirent * b = buf;
     int bytes = 0;
@@ -459,7 +459,7 @@ size_t shim_do_getdents64 (int fd, struct linux_dirent64 * buf, size_t count)
 
     lock(&hdl->lock);
 
-    struct shim_dir_handle * dirhdl = &hdl->info.dir;
+    struct shim_dir_handle * dirhdl = &hdl->dir_info;
     struct shim_dentry * dent = hdl->dentry;
     struct linux_dirent64 * b = buf;
     int bytes = 0;