Whamcloud - gitweb
LU-7576 llapi: use dirname() in opendir_parent() 96/17796/4
authorJohn L. Hammond <john.hammond@intel.com>
Mon, 4 Jan 2016 18:24:00 +0000 (12:24 -0600)
committerOleg Drokin <oleg.drokin@intel.com>
Tue, 2 Feb 2016 04:31:11 +0000 (04:31 +0000)
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 <john.hammond@intel.com>
Change-Id: I330717da540618052bc5efbb5df9cbe6c4194050
Reviewed-on: http://review.whamcloud.com/17796
Reviewed-by: Bob Glossman <bob.glossman@intel.com>
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Dmitry Eremin <dmitry.eremin@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/tests/sanity.sh
lustre/utils/liblustreapi.c

index f9371d6..d150cf3 100755 (executable)
@@ -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
index 988d9f4..dd236a8 100644 (file)
@@ -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 *)&param->fp_mdt_index;
@@ -3090,6 +3092,8 @@ out:
        if (parent == NULL)
                closedir(tmp_parent);
 
+       free(path_copy);
+
        return ret;
 }