Whamcloud - gitweb
LU-13826 utils: fix compatibility for LL_IOC_MDC_GETINFO
[fs/lustre-release.git] / lustre / utils / liblustreapi.c
index dbf46bb..5686811 100644 (file)
@@ -1289,7 +1289,7 @@ int get_root_path(int want, char *fsname, int *outfd, char *path, int index)
        char buf[PATH_MAX], mntdir[PATH_MAX];
        char *ptr, *ptr_end;
        FILE *fp;
-       int idx = 0, len = 0, mntlen, fd;
+       int idx = 0, mntlen = 0, fd;
        int rc = -ENODEV;
        int fsnamelen, mountlen;
 
@@ -1345,16 +1345,19 @@ int get_root_path(int want, char *fsname, int *outfd, char *path, int index)
                        rc = 0;
                        break;
                /* Otherwise find the longest matching path */
-               } else if ((strlen(path) >= mntlen) && (mntlen >= len) &&
+               } else if ((strlen(path) >= mntlen) &&
                           (strncmp(mnt.mnt_dir, path, mntlen) == 0)) {
+                       /* check the path format */
+                       if (strlen(path) > mntlen && path[mntlen] != '/')
+                               continue;
                        strncpy(mntdir, mnt.mnt_dir, sizeof(mntdir) - 1);
                        mntdir[sizeof(mntdir) - 1] = '\0';
-                       len = mntlen;
                        if ((want & WANT_FSNAME) && fsname != NULL) {
                                strncpy(fsname, ptr, mountlen);
                                fsname[mountlen] = '\0';
                        }
                        rc = 0;
+                       break;
                }
        }
        endmntent(fp);
@@ -1362,8 +1365,8 @@ int get_root_path(int want, char *fsname, int *outfd, char *path, int index)
        /* Found it */
        if (rc == 0) {
                if ((want & WANT_PATH) && path != NULL) {
-                       strncpy(path, mntdir, PATH_MAX);
-                       path[strlen(mntdir)] = '\0';
+                       strncpy(path, mntdir, mntlen);
+                       path[mntlen] = '\0';
                }
                if (want & WANT_FD) {
                        fd = open(mntdir, O_RDONLY | O_DIRECTORY | O_NONBLOCK);
@@ -2000,20 +2003,21 @@ int get_lmd_info_fd(const char *path, int parent_fd, int dir_fd,
                 * LL_IOC_LOV_GETSTRIPE returns only struct lov_user_md.
                 */
                if (type == GET_LMD_INFO)
-                       cmd = use_old_ioctl ? LL_IOC_MDC_GETINFO_OLD :
-                                             LL_IOC_MDC_GETINFO;
+                       cmd = use_old_ioctl ? LL_IOC_MDC_GETINFO_V1 :
+                                             LL_IOC_MDC_GETINFO_V2;
                else
                        cmd = LL_IOC_LOV_GETSTRIPE;
 
 retry_getinfo:
                ret = ioctl(dir_fd, cmd, lmdbuf);
-               if (ret < 0 && errno == ENOTTY && cmd == LL_IOC_MDC_GETINFO) {
-                       cmd = LL_IOC_MDC_GETINFO_OLD;
+               if (ret < 0 && errno == ENOTTY &&
+                   cmd == LL_IOC_MDC_GETINFO_V2) {
+                       cmd = LL_IOC_MDC_GETINFO_V1;
                        use_old_ioctl = true;
                        goto retry_getinfo;
                }
 
-               if (cmd == LL_IOC_MDC_GETINFO_OLD && !ret)
+               if (cmd == LL_IOC_MDC_GETINFO_V1 && !ret)
                        ret = convert_lmdbuf_v1v2(lmdbuf, lmdlen);
        } else if (parent_fd >= 0) {
                const char *fname = strrchr(path, '/');
@@ -2039,21 +2043,21 @@ retry_getinfo:
                        errno = EINVAL;
                else {
                        if (type == GET_LMD_INFO)
-                               cmd = use_old_ioctl ? IOC_MDC_GETFILEINFO_OLD :
-                                                     IOC_MDC_GETFILEINFO;
+                               cmd = use_old_ioctl ? IOC_MDC_GETFILEINFO_V1 :
+                                                     IOC_MDC_GETFILEINFO_V2;
                        else
                                cmd = IOC_MDC_GETFILESTRIPE;
 
 retry_getfileinfo:
                        ret = ioctl(parent_fd, cmd, lmdbuf);
                        if (ret < 0 && errno == ENOTTY &&
-                           cmd == IOC_MDC_GETFILEINFO) {
-                               cmd = IOC_MDC_GETFILEINFO_OLD;
+                           cmd == IOC_MDC_GETFILEINFO_V2) {
+                               cmd = IOC_MDC_GETFILEINFO_V1;
                                use_old_ioctl = true;
                                goto retry_getfileinfo;
                        }
 
-                       if (cmd == IOC_MDC_GETFILEINFO_OLD && !ret)
+                       if (cmd == IOC_MDC_GETFILEINFO_V1 && !ret)
                                ret = convert_lmdbuf_v1v2(lmdbuf, lmdlen);
                }
        }
@@ -4210,26 +4214,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)
@@ -5147,7 +5160,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;
        }
 
@@ -5477,7 +5490,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;
        }
 
@@ -5671,6 +5684,9 @@ int llapi_quotactl(char *mnt, struct if_quotactl *qctl)
        rc = ioctl(root, OBD_IOC_QUOTACTL, qctl);
        if (rc < 0)
                rc = -errno;
+       if (rc == -ENOENT && LUSTRE_Q_CMD_IS_POOL(qctl->qc_cmd))
+               llapi_error(LLAPI_MSG_ERROR | LLAPI_MSG_NO_ERRNO, rc,
+                           "Cannot find pool '%s'", qctl->qc_poolname);
 
        close(root);
        return rc;