Browse Source

[LibOS] Allow __path_lookup(start != NULL, abspath)

__path_lookupat(start!=NULL, path=absolute) incorrectly handled
lookup at start dir. Resolution should start directly at the root
of the thread.
Isaku Yamahata 6 years ago
parent
commit
dee669b84f
2 changed files with 22 additions and 5 deletions
  1. 10 4
      LibOS/shim/src/bookkeep/shim_handle.c
  2. 12 1
      LibOS/shim/src/fs/shim_namei.c

+ 10 - 4
LibOS/shim/src/bookkeep/shim_handle.c

@@ -55,8 +55,7 @@ static inline int init_tty_handle (struct shim_handle * hdl, bool write)
     /* XXX: Try getting the root FS from current thread? */
     /* XXX: Try getting the root FS from current thread? */
     assert(cur_thread);
     assert(cur_thread);
     assert(cur_thread->root);
     assert(cur_thread->root);
-    if ((ret = path_lookupat(cur_thread->root, "/dev/tty", LOOKUP_OPEN, &dent,
-                             cur_thread->root->fs)) < 0)
+    if ((ret = path_lookupat(NULL, "/dev/tty", LOOKUP_OPEN, &dent, NULL)) < 0)
         return ret;
         return ret;
 
 
     int flags = (write ? O_WRONLY : O_RDONLY)|O_APPEND;
     int flags = (write ? O_WRONLY : O_RDONLY)|O_APPEND;
@@ -95,8 +94,15 @@ static inline int init_exec_handle (struct shim_thread * thread)
 
 
     struct shim_mount * fs = find_mount_from_uri(PAL_CB(executable));
     struct shim_mount * fs = find_mount_from_uri(PAL_CB(executable));
     if (fs) {
     if (fs) {
-        path_lookupat(fs->root, PAL_CB(executable) + fs->uri.len, 0,
-                      &exec->dentry, fs);
+        const char * p = PAL_CB(executable) + fs->uri.len;
+        /*
+         * Lookup for PAL_CB(executable) needs to be done under a given
+         * mount point. which requires a relative path name.
+         * On the other hand, the one in manifest file can be absolute path.
+         */
+        while (*p == '/')
+            p++;
+        path_lookupat(fs->root, p, 0, &exec->dentry, fs);
         set_handle_fs(exec, fs);
         set_handle_fs(exec, fs);
         if (exec->dentry) {
         if (exec->dentry) {
             size_t len;
             size_t len;

+ 12 - 1
LibOS/shim/src/fs/shim_namei.c

@@ -272,9 +272,19 @@ int __path_lookupat (struct shim_dentry * start, const char * path, int flags,
     bool no_fs = false; // fs not passed
     bool no_fs = false; // fs not passed
     struct shim_thread * cur_thread = get_cur_thread();
     struct shim_thread * cur_thread = get_cur_thread();
 
 
+    if (cur_thread && *path == '/') {
+        /*
+         * Allow (start != NULL, absolute path) for *at() system calls.
+         * which are common case as normal namei path resolution.
+         */
+        start = cur_thread->root;
+        no_start = true;
+        get_dentry(start);
+        fs = NULL;
+    }
     if (!start) {
     if (!start) {
         if (cur_thread) {
         if (cur_thread) {
-            start = *path == '/' ? cur_thread->root : cur_thread->cwd;
+            start = cur_thread->cwd;
         } else {
         } else {
             /* Start at the global root if we have no fs and no start dentry.
             /* Start at the global root if we have no fs and no start dentry.
              * This shoud only happen as part of initialization.
              * This shoud only happen as part of initialization.
@@ -285,6 +295,7 @@ int __path_lookupat (struct shim_dentry * start, const char * path, int flags,
         no_start = true;
         no_start = true;
         // refcount should only be incremented if the caller didn't do it
         // refcount should only be incremented if the caller didn't do it
         get_dentry(start);
         get_dentry(start);
+        assert(fs == NULL);
     }
     }
 
 
     assert(start);
     assert(start);