Whamcloud - gitweb
LU-6674 utils: fix of uninitilized lmm structure usage 09/15109/4
authorDmitry Eremin <dmitry.eremin@intel.com>
Tue, 2 Jun 2015 17:17:46 +0000 (20:17 +0300)
committerOleg Drokin <oleg.drokin@intel.com>
Wed, 8 Jul 2015 17:12:49 +0000 (17:12 +0000)
Fill with "fake" the "use the default" values since the lmm struct
is zeroed out at this point and not filled by ioctl.

Change-Id: I9df005446c5d03bdf561823842afe98ab8d352c1
Signed-off-by: Dmitry Eremin <dmitry.eremin@intel.com>
Reviewed-on: http://review.whamcloud.com/15109
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: jacques-Charles Lafoucriere <jacques-charles.lafoucriere@cea.fr>
Reviewed-by: Fan Yong <fan.yong@intel.com>
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Reviewed-by: James Simmons <uja.ornl@yahoo.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/utils/liblustreapi.c

index c2dcbda..74ab27f 100644 (file)
@@ -1549,7 +1549,7 @@ static int common_param_init(struct find_param *param, char *path)
                lum_size = PATH_MAX + 1;
 
        param->fp_lum_size = lum_size;
                lum_size = PATH_MAX + 1;
 
        param->fp_lum_size = lum_size;
-       param->fp_lmd = malloc(sizeof(lstat_t) + param->fp_lum_size);
+       param->fp_lmd = calloc(1, sizeof(lstat_t) + param->fp_lum_size);
        if (param->fp_lmd == NULL) {
                llapi_error(LLAPI_MSG_ERROR, -ENOMEM,
                            "error: allocation of %zu bytes for ioctl",
        if (param->fp_lmd == NULL) {
                llapi_error(LLAPI_MSG_ERROR, -ENOMEM,
                            "error: allocation of %zu bytes for ioctl",
@@ -1558,7 +1558,8 @@ static int common_param_init(struct find_param *param, char *path)
        }
 
        param->fp_lmv_stripe_count = 256;
        }
 
        param->fp_lmv_stripe_count = 256;
-       param->fp_lmv_md = malloc(lmv_user_md_size(param->fp_lmv_stripe_count,
+       param->fp_lmv_md = calloc(1,
+                                 lmv_user_md_size(param->fp_lmv_stripe_count,
                                                   LMV_MAGIC_V1));
        if (param->fp_lmv_md == NULL) {
                llapi_error(LLAPI_MSG_ERROR, -ENOMEM,
                                                   LMV_MAGIC_V1));
        if (param->fp_lmv_md == NULL) {
                llapi_error(LLAPI_MSG_ERROR, -ENOMEM,
@@ -3025,6 +3026,22 @@ static int cb_find_init(char *path, DIR *parent, DIR **dirp,
        if (decision == 0) {
                ret = get_lmd_info(path, parent, dir, param->fp_lmd,
                                   param->fp_lum_size);
        if (decision == 0) {
                ret = get_lmd_info(path, parent, dir, param->fp_lmd,
                                   param->fp_lum_size);
+               if (ret == 0 && param->fp_lmd->lmd_lmm.lmm_magic == 0 &&
+                   (param->fp_check_pool || param->fp_check_stripe_count ||
+                    param->fp_check_stripe_size || param->fp_check_layout)) {
+                       struct lov_user_md *lmm = &param->fp_lmd->lmd_lmm;
+
+                       /* We need to "fake" the "use the default" values
+                        * since the lmm struct is zeroed out at this point. */
+                       lmm->lmm_magic = LOV_USER_MAGIC_V1;
+                       lmm->lmm_pattern = 0xFFFFFFFF;
+                       if (!param->fp_raw)
+                               ostid_set_seq(&lmm->lmm_oi,
+                                             FID_SEQ_LOV_DEFAULT);
+                       lmm->lmm_stripe_size = 0;
+                       lmm->lmm_stripe_count = 0;
+                       lmm->lmm_stripe_offset = -1;
+               }
                if (ret == 0 && param->fp_mdt_uuid != NULL) {
                        if (dir != NULL) {
                                ret = llapi_file_fget_mdtidx(dirfd(dir),
                if (ret == 0 && param->fp_mdt_uuid != NULL) {
                        if (dir != NULL) {
                                ret = llapi_file_fget_mdtidx(dirfd(dir),