From e110f9ed6ea52f9be999c9cdf0ec9c8c67b6f0ea Mon Sep 17 00:00:00 2001 From: "John L. Hammond" Date: Mon, 4 Jan 2016 12:24:00 -0600 Subject: [PATCH] LU-7576 llapi: use dirname() in opendir_parent() In opendir_parent() pass the path through dirname() so that the resulting directory may be used with basename(). Add test_230i() to sanity.sh to ensure that lfs migrate -m tolerates trailing slashes. Signed-off-by: John L. Hammond Change-Id: I330717da540618052bc5efbb5df9cbe6c4194050 Reviewed-on: http://review.whamcloud.com/17796 Reviewed-by: Bob Glossman Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Dmitry Eremin Reviewed-by: Oleg Drokin --- lustre/tests/sanity.sh | 14 ++++++++++++++ lustre/utils/liblustreapi.c | 32 ++++++++++++++++++-------------- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index f9371d6..d150cf3 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -13102,6 +13102,20 @@ test_230h() { } run_test 230h "migrate .. and root" +test_230i() { + [ $PARALLEL == "yes" ] && skip "skip parallel run" && return + [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return + + mkdir -p $DIR/$tdir/migrate_dir + + $LFS migrate -m 1 $DIR/$tdir/migrate_dir/ || + error "migration fails with a tailing slash" + + $LFS migrate -m 0 $DIR/$tdir/migrate_dir// || + error "migration fails with two tailing slashes" +} +run_test 230i "lfs migrate -m tolerates trailing slashes" + test_231a() { # For simplicity this test assumes that max_pages_per_rpc diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index 988d9f4..dd236a8 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -1359,21 +1359,21 @@ static int cb_common_fini(char *path, DIR *parent, DIR **dirp, void *data, } /* set errno upon failure */ -static DIR *opendir_parent(char *path) +static DIR *opendir_parent(const char *path) { - DIR *parent; - char *fname; - char c; + char *path_copy; + char *parent_path; + DIR *parent; - fname = strrchr(path, '/'); - if (fname == NULL) - return opendir("."); - - c = fname[1]; - fname[1] = '\0'; - parent = opendir(path); - fname[1] = c; - return parent; + path_copy = strdup(path); + if (path_copy == NULL) + return NULL; + + parent_path = dirname(path_copy); + parent = opendir(parent_path); + free(path_copy); + + return parent; } static int cb_get_dirstripe(char *path, DIR *d, struct find_param *param) @@ -3018,6 +3018,7 @@ static int cb_migrate_mdt_init(char *path, DIR *parent, DIR **dirp, struct obd_ioctl_data data = { 0 }; int fd; int ret; + char *path_copy; char *filename; bool retry = false; @@ -3038,7 +3039,8 @@ static int cb_migrate_mdt_init(char *path, DIR *parent, DIR **dirp, fd = dirfd(tmp_parent); - filename = basename(path); + path_copy = strdup(path); + filename = basename(path_copy); data.ioc_inlbuf1 = (char *)filename; data.ioc_inllen1 = strlen(filename) + 1; data.ioc_inlbuf2 = (char *)¶m->fp_mdt_index; @@ -3090,6 +3092,8 @@ out: if (parent == NULL) closedir(tmp_parent); + free(path_copy); + return ret; } -- 1.8.3.1