From: Elena Gryaznova Date: Wed, 8 Dec 2010 13:35:29 +0000 (+0300) Subject: b=24039 lfs setstripe --pool broken X-Git-Tag: 2.0.59.0~29 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=2b5caa112fcc4361b255105fa331b8fcbc11799a b=24039 lfs setstripe --pool broken i=Andreas.Dilger i=Vladimir.Saveliev fix llapi_search_fsname() to handle relative pathname --- diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index ae75d58..8b828d7 100644 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -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) diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index 233c7b0..4f46c54 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -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 */