Whamcloud - gitweb
LU-13460 lfs: make function print_failed_tgt() work correctly
[fs/lustre-release.git] / lustre / utils / liblustreapi.c
index 705b544..5575b78 100644 (file)
@@ -63,6 +63,7 @@
 #include <time.h>
 #include <fnmatch.h>
 #include <libgen.h> /* for dirname() */
+#include <linux/limits.h>
 #ifdef HAVE_LINUX_UNISTD_H
 #include <linux/unistd.h>
 #else
@@ -539,23 +540,21 @@ static int get_param_lmv(const char *path, const char *param,
 
 static int get_mds_md_size(const char *path)
 {
-       char buf[PATH_MAX], inst[PATH_MAX];
        int md_size = lov_user_md_size(LOV_MAX_STRIPE_COUNT, LOV_USER_MAGIC_V3);
-       int rc;
-
-       rc = llapi_getname(path, inst, sizeof(inst));
-       if (rc != 0)
-               return rc;
 
-       /* Get the max ea size from llite parameters. */
-       rc = get_lustre_param_value("llite", inst, FILTER_BY_EXACT,
-                                   "max_easize", buf, sizeof(buf));
-       if (rc != 0)
-               return rc;
+       /*
+        * Rather than open the file and do the ioctl to get the
+        * instance name and close the file and search for the param
+        * file and open the param file and read the param file and
+        * parse the value and close the param file, let's just return
+        * a large enough value. It's 2020, RAM is cheap and this is
+        * much faster.
+        */
 
-       rc = atoi(buf);
+       if (md_size < XATTR_SIZE_MAX)
+               md_size = XATTR_SIZE_MAX;
 
-       return rc > 0 ? rc : md_size;
+       return md_size;
 }
 
 int llapi_get_agent_uuid(char *path, char *buf, size_t bufsize)
@@ -4211,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)
@@ -4423,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;
@@ -4597,7 +4612,7 @@ static int fget_projid(int fd, int *projid)
        struct fsxattr fsx;
        int rc;
 
-       rc = ioctl(fd, LL_IOC_FSGETXATTR, &fsx);
+       rc = ioctl(fd, FS_IOC_FSGETXATTR, &fsx);
        if (rc)
                return -errno;
 
@@ -5141,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;
        }
 
@@ -5471,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;
        }