Whamcloud - gitweb
b=24039 lfs setstripe --pool broken
authorElena Gryaznova <elena.gryaznova@oracle.com>
Mon, 20 Dec 2010 11:48:38 +0000 (14:48 +0300)
committerAndrew Perepechko <andrew.perepechko@oracle.com>
Mon, 20 Dec 2010 20:18:27 +0000 (23:18 +0300)
i=Andreas.Dilger
i=Vladimir.Saveliev

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

index 8dfe525..a526068 100644 (file)
@@ -6798,6 +6798,19 @@ test_200g() {
 }
 run_test 200g "lfs df a pool ============================================"
 
+test_200h() { # b=24039
+       test_pools || return 0
+       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() {
        test_pools || return 0
 
index 16ef8b9..5c70064 100644 (file)
@@ -607,19 +607,42 @@ int llapi_search_mounts(const char *pathname, int index, char *mntdir,
 
 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 */