Whamcloud - gitweb
b=24039 lfs setstripe --pool broken
authorElena Gryaznova <elena.gryaznova@oracle.com>
Wed, 8 Dec 2010 13:35:29 +0000 (16:35 +0300)
committerVitaly Fertman <vitaly.fertman@oracle.com>
Fri, 10 Dec 2010 23:55:28 +0000 (02:55 +0300)
i=Andreas.Dilger
i=Vladimir.Saveliev

fix llapi_search_fsname() to handle relative pathname

lustre/tests/sanity.sh
lustre/utils/liblustreapi.c

index ae75d58..8b828d7 100644 (file)
@@ -7447,6 +7447,18 @@ test_200g() {
 }
 run_test 200g "lfs df a pool ============================================"
 
+test_200h() { # b=24039
+       mkdir -p $POOL_DIR || error "unable to create $POOL_DIR"
+
+       local file="/..$POOL_DIR/$tfile-1"
+       $SETSTRIPE -p $POOL $file || error "unable to create $file"
+
+       cd $POOL_DIR
+       $SETSTRIPE -p $POOL $tfile-2 || \
+               error "unable to create $tfile-2 in $POOL_DIR"
+}
+run_test 200h "Create files in a pool with relative pathname ============"
+
 test_201a() {
        remote_mgs_nodsh && skip "remote MGS with nodsh" && return
        TGT=$($LCTL get_param -n lov.$FSNAME-*.pools.$POOL | head -1)
index 233c7b0..4f46c54 100644 (file)
@@ -606,19 +606,42 @@ int llapi_search_mounts(const char *pathname, int index, char *mntdir,
 /* Given a path, find the corresponding Lustre fsname */
 int llapi_search_fsname(const char *pathname, char *fsname)
 {
-        char *path = (char*)pathname, buf[PATH_MAX + 1];
+        char *path;
+        int rc;
 
-        if (pathname[0] != '/') { /* Need a absolute path */
-                memset(buf, '\0', sizeof(buf));
-                if (realpath(pathname, buf) == NULL) {
-                        llapi_err(LLAPI_MSG_ERROR, "pathname '%s' cannot expand",
-                                  pathname);
-                        return -EINVAL;
+        path = realpath(pathname, NULL);
+        if (path == NULL) {
+                char buf[PATH_MAX + 1], *ptr;
+
+                buf[0] = 0;
+                if (pathname[0] != '/') {
+                        /* Need an absolute path, but realpath() only works for
+                         * pathnames that actually exist.  We go through the
+                         * extra hurdle of dirname(getcwd() + pathname) in
+                         * case the relative pathname contains ".." in it. */
+                        if (getcwd(buf, sizeof(buf) - 1) == NULL)
+                                return -errno;
+                        strcat(buf, "/");
+                }
+                strncat(buf, pathname, sizeof(buf) - strlen(buf));
+                path = realpath(buf, NULL);
+                if (path == NULL) {
+                        ptr = strrchr(buf, '/');
+                        if (ptr == NULL)
+                                return -ENOENT;
+                        *ptr = '\0';
+                        path = realpath(buf, NULL);
+                        if (path == NULL) {
+                                llapi_err(LLAPI_MSG_ERROR,
+                                          "pathname '%s' cannot expand",
+                                          pathname);
+                                return -errno;
+                        }
                 }
-                path = buf;
         }
-        return get_root_path(WANT_FSNAME | WANT_ERROR, fsname, NULL,
-                             path, -1);
+        rc = get_root_path(WANT_FSNAME | WANT_ERROR, fsname, NULL, path, -1);
+        free(path);
+        return rc;
 }
 
 /* return the first file matching this pattern */