Whamcloud - gitweb
LU-13460 lfs: make function print_failed_tgt() work correctly
[fs/lustre-release.git] / lustre / utils / liblustreapi.c
index 92cb3d3..5575b78 100644 (file)
@@ -4210,26 +4210,35 @@ static int check_mdt_match(struct find_param *param)
  * not active, just print the object affected by this
  * failed target
  **/
-static int print_failed_tgt(struct find_param *param, char *path, int type)
+static void print_failed_tgt(struct find_param *param, char *path, int type)
 {
        struct obd_statfs stat_buf;
        struct obd_uuid uuid_buf;
-       int ret;
+       int tgt_nr, i, *indexes;
+       int ret = 0;
 
-       if (type != LL_STATFS_LOV && type != LL_STATFS_LMV)
-               return -EINVAL;
+       if (type != LL_STATFS_LOV && type != LL_STATFS_LMV) {
+               llapi_error(LLAPI_MSG_NORMAL, ret, "%s: wrong statfs type(%d)",
+                           __func__, type);
+               return;
+       }
 
-       memset(&stat_buf, 0, sizeof(struct obd_statfs));
-       memset(&uuid_buf, 0, sizeof(struct obd_uuid));
-       ret = llapi_obd_statfs(path, type,
-                              type == LL_STATFS_LOV ? param->fp_obd_index :
-                              param->fp_mdt_index, &stat_buf,
-                              &uuid_buf);
-       if (ret)
-               llapi_error(LLAPI_MSG_NORMAL, ret, "obd_uuid: %s failed",
-                            param->fp_obd_uuid->uuid);
+       tgt_nr = (type == LL_STATFS_LOV) ? param->fp_obd_index :
+                param->fp_mdt_index;
+       indexes = (type == LL_STATFS_LOV) ? param->fp_obd_indexes :
+                 param->fp_mdt_indexes;
 
-       return ret;
+       for (i = 0; i < tgt_nr; i++) {
+               memset(&stat_buf, 0, sizeof(struct obd_statfs));
+               memset(&uuid_buf, 0, sizeof(struct obd_uuid));
+
+               ret = llapi_obd_statfs(path, type, indexes[i], &stat_buf,
+                                      &uuid_buf);
+               if (ret)
+                       llapi_error(LLAPI_MSG_NORMAL, ret,
+                                   "%s: obd_uuid: %s failed",
+                                   __func__, param->fp_obd_uuid->uuid);
+       }
 }
 
 static int find_check_stripe_size(struct find_param *param)
@@ -4422,38 +4431,45 @@ static int find_check_foreign(struct find_param *param)
 static int find_check_pool(struct find_param *param)
 {
        struct lov_comp_md_v1 *comp_v1 = NULL;
-       struct lov_user_md_v1 *v1 = &param->fp_lmd->lmd_lmm;
-       struct lov_user_md_v3 *v3 = (void *)v1;
+       struct lov_user_md_v3 *v3 = (void *)&param->fp_lmd->lmd_lmm;
        int i, count = 1;
        bool found = false;
 
-       if (v1->lmm_magic == LOV_USER_MAGIC_COMP_V1) {
-               comp_v1 = (struct lov_comp_md_v1 *)v1;
+       if (v3->lmm_magic == LOV_USER_MAGIC_COMP_V1) {
+               comp_v1 = (struct lov_comp_md_v1 *)v3;
                count = comp_v1->lcm_entry_count;
                /* empty requested pool is taken as no pool search */
-               if (count == 0 && param->fp_poolname[0] == '\0')
+               if (count == 0 && param->fp_poolname[0] == '\0') {
                        found = true;
+                       goto found;
+               }
        }
 
        for (i = 0; i < count; i++) {
-               if (comp_v1 != NULL)
-                       v1 = lov_comp_entry(comp_v1, i);
+               if (comp_v1 != NULL) {
+                       if (!(comp_v1->lcm_entries[i].lcme_flags &
+                             LCME_FL_INIT))
+                               continue;
 
-               if (v1->lmm_magic == LOV_USER_MAGIC_FOREIGN)
+                       v3 = (void *)lov_comp_entry(comp_v1, i);
+               }
+
+               if (v3->lmm_magic == LOV_USER_MAGIC_FOREIGN)
                        continue;
 
-               if (((v1->lmm_magic == LOV_USER_MAGIC_V1) &&
+               if (((v3->lmm_magic == LOV_USER_MAGIC_V1) &&
                     (param->fp_poolname[0] == '\0')) ||
-                   ((v1->lmm_magic == LOV_USER_MAGIC_V3) &&
+                   ((v3->lmm_magic == LOV_USER_MAGIC_V3) &&
                     (strncmp(v3->lmm_pool_name,
                              param->fp_poolname, LOV_MAXPOOLNAME) == 0)) ||
-                   ((v1->lmm_magic == LOV_USER_MAGIC_V3) &&
+                   ((v3->lmm_magic == LOV_USER_MAGIC_V3) &&
                     (strcmp(param->fp_poolname, "*") == 0))) {
                        found = true;
                        break;
                }
        }
 
+found:
        if ((found && !param->fp_exclude_pool) ||
            (!found && param->fp_exclude_pool))
                return 1;
@@ -5140,7 +5156,7 @@ static int cb_migrate_mdt_init(char *path, DIR *parent, DIR **dirp,
        ret = llapi_ioctl_pack(&data, &rawbuf, sizeof(raw));
        if (ret != 0) {
                llapi_error(LLAPI_MSG_ERROR, ret,
-                           "llapi_obd_statfs: error packing ioctl data");
+                           "%s: error packing ioctl data", __func__);
                goto out;
        }
 
@@ -5470,7 +5486,7 @@ int llapi_obd_fstatfs(int fd, __u32 type, __u32 index,
        rc = llapi_ioctl_pack(&data, &rawbuf, sizeof(raw));
        if (rc != 0) {
                llapi_error(LLAPI_MSG_ERROR, rc,
-                           "llapi_obd_statfs: error packing ioctl data");
+                           "%s: error packing ioctl data", __func__);
                return rc;
        }