Whamcloud - gitweb
LU-7628 lfs: fix NULL pointer check in cb_migrate_mdt_init() 14/17814/3
authorEmoly Liu <emoly.liu@intel.com>
Tue, 5 Jan 2016 03:55:40 +0000 (11:55 +0800)
committerOleg Drokin <oleg.drokin@intel.com>
Mon, 25 Jan 2016 01:58:27 +0000 (01:58 +0000)
After calling opendir() at the end of cb_migrate_mdt_init(), we should
check *dirp rather then dirp, and we should close temporary parent
directory before return error.
Also, this patch improves the code a little to make it more readable.

Signed-off-by: Emoly Liu <emoly.liu@intel.com>
Change-Id: I2507cbd6464ea56fba7793431905cdf51136413f
Reviewed-on: http://review.whamcloud.com/17814
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Reviewed-by: wangdi <di.wang@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/utils/liblustreapi.c

index bac6a68..f7feed1 100644 (file)
@@ -3007,10 +3007,10 @@ decided:
 }
 
 static int cb_migrate_mdt_init(char *path, DIR *parent, DIR **dirp,
 }
 
 static int cb_migrate_mdt_init(char *path, DIR *parent, DIR **dirp,
-                     void *param_data, struct dirent64 *de)
+                              void *param_data, struct dirent64 *de)
 {
        struct find_param       *param = (struct find_param *)param_data;
 {
        struct find_param       *param = (struct find_param *)param_data;
-       DIR                     *dir = parent;
+       DIR                     *tmp_parent = parent;
        char                    raw[OBD_MAX_IOCTL_BUFFER] = {'\0'};
        char                    *rawbuf = raw;
        struct obd_ioctl_data   data = { 0 };
        char                    raw[OBD_MAX_IOCTL_BUFFER] = {'\0'};
        char                    *rawbuf = raw;
        struct obd_ioctl_data   data = { 0 };
@@ -3023,8 +3023,8 @@ static int cb_migrate_mdt_init(char *path, DIR *parent, DIR **dirp,
                closedir(*dirp);
 
        if (parent == NULL) {
                closedir(*dirp);
 
        if (parent == NULL) {
-               dir = opendir_parent(path);
-               if (dir == NULL) {
+               tmp_parent = opendir_parent(path);
+               if (tmp_parent == NULL) {
                        *dirp = NULL;
                        ret = -errno;
                        llapi_error(LLAPI_MSG_ERROR, ret,
                        *dirp = NULL;
                        ret = -errno;
                        llapi_error(LLAPI_MSG_ERROR, ret,
@@ -3033,7 +3033,7 @@ static int cb_migrate_mdt_init(char *path, DIR *parent, DIR **dirp,
                }
        }
 
                }
        }
 
-       fd = dirfd(dir);
+       fd = dirfd(tmp_parent);
 
        filename = basename(path);
        data.ioc_inlbuf1 = (char *)filename;
 
        filename = basename(path);
        data.ioc_inlbuf1 = (char *)filename;
@@ -3066,16 +3066,15 @@ out:
                 * on the client side, and re-open to get the
                 * new directory handle */
                *dirp = opendir(path);
                 * on the client side, and re-open to get the
                 * new directory handle */
                *dirp = opendir(path);
-               if (dirp == NULL) {
+               if (*dirp == NULL) {
                        ret = -errno;
                        llapi_error(LLAPI_MSG_ERROR, ret,
                                    "%s: Failed to open '%s'", __func__, path);
                        ret = -errno;
                        llapi_error(LLAPI_MSG_ERROR, ret,
                                    "%s: Failed to open '%s'", __func__, path);
-                       return ret;
                }
        }
 
        if (parent == NULL)
                }
        }
 
        if (parent == NULL)
-               closedir(dir);
+               closedir(tmp_parent);
 
        return ret;
 }
 
        return ret;
 }