Whamcloud - gitweb
LU-9505 llapi: treat MDT index as a hex number
[fs/lustre-release.git] / lustre / utils / liblustreapi.c
index 4194b54..2df30c6 100644 (file)
@@ -1235,8 +1235,7 @@ int llapi_get_poollist(const char *name, char **poollist, int list_size,
        char *fsname;
         char *ptr;
         DIR *dir;
-        struct dirent pool;
-        struct dirent *cookie = NULL;
+       struct dirent *pool;
         int rc = 0;
         unsigned int nb_entries = 0;
         unsigned int used = 0;
@@ -1288,20 +1287,16 @@ int llapi_get_poollist(const char *name, char **poollist, int list_size,
                goto free_path;
        }
 
-       while(1) {
-               rc = readdir_r(dir, &pool, &cookie);
-               if (rc != 0) {
+       do {
+               errno = 0;
+               pool = readdir(dir);
+               if (pool == NULL) {
                        rc = -errno;
-                       llapi_error(LLAPI_MSG_ERROR, rc,
-                                   "Error reading pool list for '%s'", name);
-                       goto free_path;
-               } else if ((rc == 0) && (cookie == NULL)) {
-                       /* end of directory */
-                       break;
+                       goto free_dir;
                }
 
                 /* ignore . and .. */
-                if (!strcmp(pool.d_name, ".") || !strcmp(pool.d_name, ".."))
+               if (!strcmp(pool->d_name, ".") || !strcmp(pool->d_name, ".."))
                         continue;
 
                 /* check output bounds */
@@ -1311,19 +1306,22 @@ int llapi_get_poollist(const char *name, char **poollist, int list_size,
                }
 
                 /* +2 for '.' and final '\0' */
-               if (used + strlen(pool.d_name) + strlen(fsname) + 2
+               if (used + strlen(pool->d_name) + strlen(fsname) + 2
                    > buffer_size) {
                        rc = -EOVERFLOW;
                        goto free_dir;
                }
 
-                sprintf(buffer + used, "%s.%s", fsname, pool.d_name);
+               sprintf(buffer + used, "%s.%s", fsname, pool->d_name);
                 poollist[nb_entries] = buffer + used;
-                used += strlen(pool.d_name) + strlen(fsname) + 2;
+               used += strlen(pool->d_name) + strlen(fsname) + 2;
                 nb_entries++;
-        }
+       } while (1);
 
 free_dir:
+       if (rc)
+               llapi_error(LLAPI_MSG_ERROR, rc,
+                           "Error reading pool list for '%s'", name);
        closedir(dir);
 free_path:
        cfs_free_param_data(&pathname);
@@ -2620,6 +2618,32 @@ static void lov_dump_comp_v1_header(struct find_param *param, char *path,
                llapi_printf(LLAPI_MSG_NORMAL, "components:\n");
 }
 
+static void comp_flags2str(__u32 comp_flags)
+{
+       bool found = false;
+       int i = 0;
+
+       if (!comp_flags) {
+               llapi_printf(LLAPI_MSG_NORMAL, "0");
+               return;
+       }
+       for (i = 0; i < ARRAY_SIZE(comp_flags_table); i++) {
+               if (comp_flags & comp_flags_table[i].cfn_flag) {
+                       if (found)
+                               llapi_printf(LLAPI_MSG_NORMAL, ",");
+                       llapi_printf(LLAPI_MSG_NORMAL, "%s",
+                                    comp_flags_table[i].cfn_name);
+                       comp_flags &= ~comp_flags_table[i].cfn_flag;
+                       found = true;
+               }
+       }
+       if (comp_flags) {
+               if (found)
+                       llapi_printf(LLAPI_MSG_NORMAL, ",");
+               llapi_printf(LLAPI_MSG_NORMAL, "%#x", comp_flags);
+       }
+}
+
 static void lov_dump_comp_v1_entry(struct find_param *param,
                                   enum lov_dump_flags flags, int index)
 {
@@ -2653,7 +2677,7 @@ static void lov_dump_comp_v1_entry(struct find_param *param,
                if (verbose & ~VERBOSE_COMP_FLAGS)
                        llapi_printf(LLAPI_MSG_NORMAL,
                                     "%4slcme_flags:          ", " ");
-               llapi_printf(LLAPI_MSG_NORMAL, "%#x", entry->lcme_flags);
+               comp_flags2str(entry->lcme_flags);
                separator = "\n";
        }
 
@@ -4482,42 +4506,42 @@ static int get_mdtname(char *name, char *format, char *buf)
 int root_ioctl(const char *mdtname, int opc, void *data, int *mdtidxp,
               int want_error)
 {
-        char fsname[20];
-        char *ptr;
+       char fsname[20];
+       char *ptr;
        int fd, rc;
        long index;
 
-        /* Take path, fsname, or MDTname.  Assume MDT0000 in the former cases.
-         Open root and parse mdt index. */
-        if (mdtname[0] == '/') {
-                index = 0;
-                rc = get_root_path(WANT_FD | want_error, NULL, &fd,
-                                   (char *)mdtname, -1);
-        } else {
-                if (get_mdtname((char *)mdtname, "%s%s", fsname) < 0)
-                        return -EINVAL;
-                ptr = fsname + strlen(fsname) - 8;
-                *ptr = '\0';
-                index = strtol(ptr + 4, NULL, 10);
-                rc = get_root_path(WANT_FD | want_error, fsname, &fd, NULL, -1);
-        }
-        if (rc < 0) {
-                if (want_error)
-                        llapi_err_noerrno(LLAPI_MSG_ERROR,
-                                          "Can't open %s: %d\n", mdtname, rc);
-                return rc;
-        }
+       /* Take path, fsname, or MDTname.  Assume MDT0000 in the former cases.
+        Open root and parse mdt index. */
+       if (mdtname[0] == '/') {
+               index = 0;
+               rc = get_root_path(WANT_FD | want_error, NULL, &fd,
+                                  (char *)mdtname, -1);
+       } else {
+               if (get_mdtname((char *)mdtname, "%s%s", fsname) < 0)
+                       return -EINVAL;
+               ptr = fsname + strlen(fsname) - 8;
+               *ptr = '\0';
+               index = strtol(ptr + 4, NULL, 16);
+               rc = get_root_path(WANT_FD | want_error, fsname, &fd, NULL, -1);
+       }
+       if (rc < 0) {
+               if (want_error)
+                       llapi_err_noerrno(LLAPI_MSG_ERROR,
+                                         "Can't open %s: %d\n", mdtname, rc);
+               return rc;
+       }
 
-        if (mdtidxp)
-                *mdtidxp = index;
+       if (mdtidxp)
+               *mdtidxp = index;
 
-        rc = ioctl(fd, opc, data);
-        if (rc == -1)
-                rc = -errno;
-        else
-                rc = 0;
-        close(fd);
-        return rc;
+       rc = ioctl(fd, opc, data);
+       if (rc == -1)
+               rc = -errno;
+       else
+               rc = 0;
+       close(fd);
+       return rc;
 }
 
 int llapi_fid2path(const char *device, const char *fidstr, char *buf,