Whamcloud - gitweb
LU-14472 quota: skip non-exist or inact tgt for lfs_quota
[fs/lustre-release.git] / lustre / utils / lfs.c
index 048b958..68a74da 100644 (file)
@@ -416,7 +416,7 @@ command_t cmdlist[] = {
         "     [[!] --mirror-state <[^]state>]\n"
         "     [[!] --name|-n <pattern>] [[!] --newer[XY] <reference>]\n"
         "     [[!] --ost|-O <uuid|index,...>] [[!] --perm [/-]mode]\n"
-        "     [[!] --pool <pool>] [--print|-P] [--print0|-0]\n"
+        "     [[!] --pool <pool>] [--print|-P] [--print0|-0] [--printf <format>]\n"
         "     [[!] --projid <projid>] [[!] --size|-s [+-]N[bkMGTPE]]\n"
         "     [[!] --stripe-count|-c [+-]<stripes>]\n"
         "     [[!] --stripe-index|-i <index,...>]\n"
@@ -444,7 +444,8 @@ command_t cmdlist[] = {
         "Usage: getname [--help|-h] [--instance|-i] [--fsname|-n] [path ...]"},
 #ifdef HAVE_SYS_QUOTA_H
        {"setquota", lfs_setquota, 0, "Set filesystem quotas.\n"
-        "usage: setquota [-t][-d] {-u|-U|-g|-G|-p|-P} {-b|-B|-i|-I LIMIT} [--pool POOL] FILESYSTEM"},
+        "usage: setquota [-t][-D] {-u|-U|-g|-G|-p|-P} {-b|-B|-i|-I LIMIT} [--pool POOL] FILESYSTEM\n"
+        "       setquota {-u|-g|-p} --delete FILESYSTEM\n"},
        {"quota", lfs_quota, 0, "Display disk usage and limits.\n"
         "usage: quota [-q] [-v] [-h] [-o OBD_UUID|-i MDT_IDX|-I OST_IDX]\n"
         "             [{-u|-g|-p} UNAME|UID|GNAME|GID|PROJID]\n"
@@ -459,7 +460,7 @@ command_t cmdlist[] = {
         "         set project ID and/or inherit flag for specified file(s) or directories\n"
         "       project -c [-d|-r [-p id] [-0]] <file|directory...>\n"
         "         check project ID and flags on file(s) or directories, print outliers\n"
-        "       project -C [-r] [-k] <file|directory...>\n"
+        "       project -C [-d|-r] [-k] <file|directory...>\n"
         "         clear the project inherit flag and ID on the file or directory\n"
        },
 #endif
@@ -591,11 +592,10 @@ static int check_hashtype(const char *hashtype)
        int i;
 
        /* numeric hash type */
-       if (hashtype && strlen(hashtype) == 1 &&
-           (type_num > 0 && type_num < LMV_HASH_TYPE_MAX))
+       if (hashtype && lmv_is_known_hash_type(type_num))
                return type_num;
        /* string hash type */
-       for (i = LMV_HASH_TYPE_ALL_CHARS; i < LMV_HASH_TYPE_MAX; i++)
+       for (i = LMV_HASH_TYPE_ALL_CHARS; i < ARRAY_SIZE(mdt_hash_name); i++)
                if (strcmp(hashtype, mdt_hash_name[i]) == 0)
                        return i;
 
@@ -1047,7 +1047,7 @@ int lfs_layout_compid_by_pool(char *fname, const char *pool, int *comp_id)
                rc = -errno;
                goto free_layout;
        }
-       rc = llapi_layout_sanity(layout, fname, false, true);
+       rc = llapi_layout_sanity(layout, false, true);
        if (rc < 0) {
                llapi_layout_sanity_perror(errno);
                goto free_layout;
@@ -1126,14 +1126,29 @@ static int lfs_component_del(char *fname, __u32 comp_id,
 {
        int     rc = 0;
 
-       if (flags && neg_flags)
+       if (flags && neg_flags) {
+               fprintf(stderr,
+                       "%s: cannot specify both positive and negative flags\n",
+                       progname);
                return -EINVAL;
+       }
 
        if (!flags && neg_flags)
                flags = neg_flags | LCME_FL_NEG;
 
-       if ((flags && comp_id) || (!flags && !comp_id))
+       if (flags && comp_id) {
+               fprintf(stderr,
+                       "%s: cannot specify component ID and flags at the same time\n",
+                       progname);
+               return -EINVAL;
+       }
+
+       if (!flags && !comp_id) {
+               fprintf(stderr,
+                       "%s: neither flags nor component ID is specified\n",
+                       progname);
                return -EINVAL;
+       }
 
        if (flags) {
                if (flags & ~LCME_KNOWN_FLAGS) {
@@ -1355,7 +1370,9 @@ static int mdthash_input(char *string, __u32 *inflags,
                __u32 flag;
        } mhflist[] = {
                {"migrating", LMV_HASH_FLAG_MIGRATION},
+               {"bad_type", LMV_HASH_FLAG_BAD_TYPE},
                {"badtype", LMV_HASH_FLAG_BAD_TYPE},
+               {"lost_lmv", LMV_HASH_FLAG_LOST_LMV},
                {"lostlmv", LMV_HASH_FLAG_LOST_LMV},
        };
 
@@ -1497,7 +1514,7 @@ static int mirror_create_sanity_check(const char *fname,
                        return -ENODATA;
                }
 
-               rc = llapi_layout_sanity(layout, fname, false, true);
+               rc = llapi_layout_sanity(layout, false, true);
 
                llapi_layout_free(layout);
 
@@ -1529,7 +1546,7 @@ static int mirror_create_sanity_check(const char *fname,
                        }
                }
 
-               rc = llapi_layout_sanity(list->m_layout, fname, false, true);
+               rc = llapi_layout_sanity(list->m_layout, false, true);
                if (rc) {
                        llapi_layout_sanity_perror(rc);
                        return rc;
@@ -2099,7 +2116,7 @@ static int mirror_split(const char *fname, __u32 id, const char *pool,
                return -EINVAL;
        }
 
-       rc = llapi_layout_sanity(layout, fname, false, true);
+       rc = llapi_layout_sanity(layout, false, true);
        if (rc) {
                llapi_layout_sanity_perror(rc);
                goto free_layout;
@@ -2313,7 +2330,7 @@ again:
        data->lil_ids[1] = mirror_id;
        rc = llapi_lease_set(fd, data);
        if (rc <= 0) {
-               if (rc == -EINVAL && purge) {
+               if ((rc == -EINVAL || rc == -EBUSY) && purge) {
                        /* could be old MDS which prohibit fd==fdv */
                        purge = false;
                        goto again;
@@ -3315,6 +3332,7 @@ static void lfs_mirror_list_free(struct mirror_args *mirror_list)
 }
 
 enum {
+       LFS_SETQUOTA_DELETE = 1,
        LFS_POOL_OPT = 3,
        LFS_COMP_COUNT_OPT,
        LFS_COMP_START_OPT,
@@ -3334,6 +3352,7 @@ enum {
        LFS_NEWERXY_OPT,
        LFS_INHERIT_RR_OPT,
        LFS_FIND_PERM,
+       LFS_PRINTF_OPT,
 };
 
 #ifndef LCME_USER_MIRROR_FLAGS
@@ -3648,11 +3667,11 @@ static int lfs_setstripe_internal(int argc, char **argv,
                                goto usage_error;
                        }
                        lsa.lsa_pattern = LLAPI_LAYOUT_OVERSTRIPING;
-                       /* fall through */
+                       fallthrough;
                case 'c':
                        errno = 0;
                        lsa.lsa_stripe_count = strtoul(optarg, &end, 0);
-                       if (errno != 0 || *end != '\0'||
+                       if (errno != 0 || *end != '\0'|| optarg == end ||
                            lsa.lsa_stripe_count < -1 ||
                            lsa.lsa_stripe_count > LOV_MAX_STRIPE_COUNT) {
                                fprintf(stderr,
@@ -3738,7 +3757,7 @@ static int lfs_setstripe_internal(int argc, char **argv,
                case 'i':
                        errno = 0;
                        lsa.lsa_stripe_off = strtol(optarg, &end, 0);
-                       if (errno != 0 || *end != '\0' ||
+                       if (errno != 0 || *end != '\0' || optarg == end ||
                            lsa.lsa_stripe_off < -1 ||
                            lsa.lsa_stripe_off > LOV_V1_INSANE_STRIPE_COUNT) {
                                fprintf(stderr,
@@ -4419,19 +4438,25 @@ static time_t set_time(struct find_param *param, time_t *time, time_t *set,
                switch (*endptr) {
                case  'y':
                        unit *= 52; /* 52 weeks + 1 day below */
-               case  'w':      /* fallthrough */
+                       fallthrough;
+               case  'w':
                        unit *= 7;
                        if (param->fp_time_margin == FP_DEFAULT_TIME_MARGIN)
                                param->fp_time_margin *= (1 + unit / 52);
                        unit += (*endptr == 'y'); /* +1 day for 365 days/year */
+                       fallthrough;
                case '\0': /* days are default unit if none used */
-               case  'd':      /* fallthrough */
+                       fallthrough;
+               case  'd':
                        unit *= 24;
-               case  'h':      /* fallthrough */
+                       fallthrough;
+               case  'h':
                        unit *= 60;
-               case  'm':      /* fallthrough */
+                       fallthrough;
+               case  'm':
                        unit *= 60;
-               case  's':      /* fallthrough */
+                       fallthrough;
+               case  's':
                        break;
                        /* don't need to multiply by 1 for seconds */
                default:
@@ -4900,6 +4925,8 @@ static int lfs_find(int argc, char **argv)
                        .name = "pool",         .has_arg = required_argument },
        { .val = '0',   .name = "print0",       .has_arg = no_argument },
        { .val = 'P',   .name = "print",        .has_arg = no_argument },
+       { .val = LFS_PRINTF_OPT,
+                       .name = "printf",       .has_arg = required_argument },
        { .val = LFS_PROJID_OPT,
                        .name = "projid",       .has_arg = required_argument },
 /* getstripe { .val = 'q', .name = "quiet",    .has_arg = no_argument }, */
@@ -4912,11 +4939,10 @@ static int lfs_find(int argc, char **argv)
        { .val = 'T',   .name = "mdt-count",    .has_arg = required_argument },
        { .val = 'u',   .name = "uid",          .has_arg = required_argument },
        { .val = 'U',   .name = "user",         .has_arg = required_argument },
+/* getstripe { .val = 'v', .name = "verbose",  .has_arg = no_argument }, */
        { .val = 'z',   .name = "extension-size",
                                                .has_arg = required_argument },
        { .val = 'z',   .name = "ext-size",     .has_arg = required_argument },
-/* getstripe { .val = 'v', .name = "verbose",  .has_arg = no_argument }, */
-/* getstripe { .val = 'y', .name = "yaml",     .has_arg = no_argument }, */
        { .name = NULL } };
        int optidx = 0;
        int pathstart = -1;
@@ -4932,7 +4958,7 @@ static int lfs_find(int argc, char **argv)
 
        /* when getopt_long_only() hits '!' it returns 1, puts "!" in optarg */
        while ((c = getopt_long_only(argc, argv,
-               "-0A:b:B:c:C:D:E:g:G:hH:i:L:m:M:n:N:O:Ppqrs:S:t:T:u:U:vz:",
+               "-0A:b:B:c:C:D:E:g:G:hH:i:L:m:M:n:N:O:Ppqrs:S:t:T:u:U:z:",
                long_opts, &optidx)) >= 0) {
                xtime = NULL;
                xsign = NULL;
@@ -4975,6 +5001,7 @@ static int lfs_find(int argc, char **argv)
                        xsign = &param.fp_asign;
                        param.fp_exclude_atime = !!neg_opt;
                        /* no break, this falls through to 'B' for btime */
+                       fallthrough;
                case 'B':
                        if (c == 'B') {
                                xtime = &param.fp_btime;
@@ -4982,6 +5009,7 @@ static int lfs_find(int argc, char **argv)
                                param.fp_exclude_btime = !!neg_opt;
                        }
                        /* no break, this falls through to 'C' for ctime */
+                       fallthrough;
                case 'C':
                        if (c == 'C') {
                                xtime = &param.fp_ctime;
@@ -4989,6 +5017,7 @@ static int lfs_find(int argc, char **argv)
                                param.fp_exclude_ctime = !!neg_opt;
                        }
                        /* no break, this falls through to 'M' for mtime */
+                       fallthrough;
                case 'M':
                        if (c == 'M') {
                                xtime = &param.fp_mtime;
@@ -5522,6 +5551,9 @@ err_free:
                        break;
                case 'P': /* we always print, this option is a no-op */
                        break;
+               case LFS_PRINTF_OPT:
+                       param.fp_format_printf_str = optarg;
+                       break;
                case LFS_PROJID_OPT:
                        rc = name2projid(&param.fp_projid, optarg);
                        if (rc) {
@@ -5676,6 +5708,8 @@ err_free:
                        goto err;
                }
        }
+       if (!param.fp_verbose)
+               param.fp_verbose = VERBOSE_DEFAULT;
 
        if (pathstart == -1) {
                fprintf(stderr, "error: %s: no filename|pathname\n",
@@ -6190,12 +6224,13 @@ static int lfs_getdirstripe(int argc, char **argv)
                case 't':
                        fprintf(stderr,
                                "warning: '-t' deprecated, use '--mdt-hash' or '-H' instead\n");
-                       /* fallthrough */
+                       fallthrough;
 #endif
                case 'H':
                        param.fp_verbose |= VERBOSE_HASH_TYPE;
                        break;
-               case 'i': /* fallthrough */
+               case 'i':
+                       fallthrough;
                case 'm':
                        param.fp_verbose |= VERBOSE_STRIPE_OFFSET;
                        break;
@@ -6226,7 +6261,7 @@ static int lfs_getdirstripe(int argc, char **argv)
                default:
                        fprintf(stderr, "%s: unrecognized option '%s'\n",
                                progname, argv[optind - 1]);
-                       /* fallthrough */
+                       fallthrough;
                case 'h':
                        return CMD_HELP;
                }
@@ -6488,13 +6523,14 @@ static int mntdf(char *mntdir, char *fsname, char *pool, enum mntdf_flags flags,
                if (!(tp->st_op & ops))
                        continue;
 
-               for (index = 0; ; index++) {
+               for (index = 0; index < LOV_ALL_STRIPES &&
+                    (!lsb || lsb->sb_count < LL_STATFS_MAX); index++) {
                        memset(&stat_buf, 0, sizeof(struct obd_statfs));
                        memset(&uuid_buf, 0, sizeof(struct obd_uuid));
                        type = flags & MNTDF_LAZY ?
                                tp->st_op | LL_STATFS_NODELAY : tp->st_op;
                        rc2 = llapi_obd_fstatfs(fd, type, index,
-                                              &stat_buf, &uuid_buf);
+                                               &stat_buf, &uuid_buf);
                        if (rc2 == -ENODEV)
                                break;
                        if (rc2 == -EAGAIN)
@@ -6717,13 +6753,13 @@ static int lfs_setdirstripe(int argc, char **argv)
                case 't':
                        fprintf(stderr,
                                "warning: '--hash-type' and '-t' deprecated, use '--mdt-hash' or '-H' instead\n");
-                       /* fallthrough */
+                       fallthrough;
 #endif
                case 'H':
                        lsa.lsa_pattern = check_hashtype(optarg);
                        if (lsa.lsa_pattern == 0) {
                                fprintf(stderr,
-                                       "%s %s: bad stripe hash type '%s'\n",
+                                       "%s %s: bad directory hash type '%s'\n",
                                        progname, argv[0], optarg);
                                return CMD_HELP;
                        }
@@ -6814,7 +6850,7 @@ static int lfs_setdirstripe(int argc, char **argv)
                default:
                        fprintf(stderr, "%s: unrecognized option '%s'\n",
                                progname, argv[optind - 1]);
-                       /* fallthrough */
+                       fallthrough;
                case 'h':
                        return CMD_HELP;
                }
@@ -6876,6 +6912,21 @@ static int lfs_setdirstripe(int argc, char **argv)
                previous_mode = umask(0);
        }
 
+       /* check max-inherit and warn user in some cases */
+       if (default_stripe &&
+           (lsa.lsa_stripe_count < 0 || lsa.lsa_stripe_count > 1)) {
+               if (max_inherit == LMV_INHERIT_UNLIMITED)
+                       fprintf(stderr,
+                       "%s %s: unrecommended max-inherit=-1 when default stripe-count=%lld\n",
+                       progname, argv[0], lsa.lsa_stripe_count);
+               else if (max_inherit > LMV_INHERIT_DEFAULT_STRIPED + 2 &&
+                        max_inherit != LMV_INHERIT_NONE)
+                       fprintf(stderr,
+                               "%s %s: unrecommended max-inherit=%d when default stripe-count=%lld\n",
+                               progname, argv[0], max_inherit,
+                               lsa.lsa_stripe_count);
+       }
+
        if (max_inherit_rr != LAYOUT_INHERIT_UNSET &&
            lsa.lsa_stripe_off != LLAPI_LAYOUT_DEFAULT &&
            lsa.lsa_stripe_off != LMV_OFFSET_DEFAULT) {
@@ -6935,10 +6986,15 @@ static int lfs_setdirstripe(int argc, char **argv)
                param->lsp_stripe_pattern = LMV_HASH_TYPE_UNKNOWN;
        param->lsp_pool = lsa.lsa_pool_name;
        param->lsp_is_specific = false;
-       if (max_inherit == LAYOUT_INHERIT_UNSET)
-               max_inherit = LMV_INHERIT_DEFAULT;
+       if (max_inherit == LAYOUT_INHERIT_UNSET) {
+               if (lsa.lsa_stripe_count == 0 || lsa.lsa_stripe_count == 1)
+                       max_inherit = LMV_INHERIT_DEFAULT_PLAIN;
+               else
+                       max_inherit = LMV_INHERIT_DEFAULT_STRIPED;
+       }
        param->lsp_max_inherit = max_inherit;
        if (default_stripe) {
+
                if (max_inherit_rr == LAYOUT_INHERIT_UNSET)
                        max_inherit_rr = LMV_INHERIT_RR_DEFAULT;
                param->lsp_max_inherit_rr = max_inherit_rr;
@@ -7286,7 +7342,7 @@ static int lfs_getname(int argc, char **argv)
                default:
                        fprintf(stderr, "%s: unrecognized option '%s'\n",
                                progname, argv[optind - 1]);
-                       /* fallthrough */
+                       fallthrough;
                case 'h':
                        return CMD_HELP;
                }
@@ -7578,7 +7634,7 @@ quota_type:
                default:
                        fprintf(stderr, "%s: unrecognized option '%s'\n",
                                progname, argv[optind - 1]);
-                       /* fallthrough */
+                       fallthrough;
                case 'h':
                        return CMD_HELP;
                }
@@ -7626,6 +7682,8 @@ int lfs_setquota(int argc, char **argv)
        { .val = 'B',   .name = "block-hardlimit",
                                                .has_arg = required_argument },
        { .val = 'd',   .name = "default",      .has_arg = no_argument },
+       { .val = LFS_SETQUOTA_DELETE,
+                       .name = "delete",       .has_arg = no_argument },
        { .val = 'g',   .name = "group",        .has_arg = required_argument },
        { .val = 'G',   .name = "default-grp",  .has_arg = no_argument },
        { .val = 'h',   .name = "help",         .has_arg = no_argument },
@@ -7663,8 +7721,7 @@ int lfs_setquota(int argc, char **argv)
                                   * so it can be used as a marker that qc_type
                                   * isn't reinitialized from command line
                                   */
-
-       while ((c = getopt_long(argc, argv, "b:B:dg:Ghi:I:p:Pu:U",
+       while ((c = getopt_long(argc, argv, "b:B:dDg:Ghi:I:p:Pu:U",
                long_opts, NULL)) != -1) {
                switch (c) {
                case 'U':
@@ -7722,9 +7779,19 @@ quota_type_def:
                        }
                        qctl->qc_type = qtype;
                        break;
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
                case 'd':
-                       qctl->qc_cmd = LUSTRE_Q_SETDEFAULT;
+#if LUSTRE_VERSION_CODE > OBD_OCD_VERSION(2, 15, 53, 0)
+                       fprintf(stderr, "'-d' deprecatd, use '-D' or '--default'\n");
+#endif
+                       /* falltrrough */
+#endif
+               case 'D':
                        use_default = true;
+                       qctl->qc_cmd = LUSTRE_Q_SETDEFAULT;
+                       break;
+               case LFS_SETQUOTA_DELETE:
+                       qctl->qc_cmd = LUSTRE_Q_DELETEQID;
                        break;
                case 'b':
                        ARG2ULL(dqb->dqb_bsoftlimit, optarg, 1024);
@@ -7787,7 +7854,7 @@ quota_type_def:
                        fprintf(stderr,
                                "%s setquota: unrecognized option '%s'\n",
                                progname, argv[optind - 1]);
-                       /* fallthrough */
+                       fallthrough;
                case 'h':
                        rc = CMD_HELP;
                        goto out;
@@ -7802,7 +7869,8 @@ quota_type_def:
                goto out;
        }
 
-       if (!use_default && limit_mask == 0) {
+       if (!use_default && qctl->qc_cmd != LUSTRE_Q_DELETEQID &&
+           limit_mask == 0) {
                fprintf(stderr,
                        "%s setquota: at least one limit must be specified\n",
                        progname);
@@ -7810,9 +7878,10 @@ quota_type_def:
                goto out;
        }
 
-       if (use_default && limit_mask != 0) {
+       if ((use_default || qctl->qc_cmd == LUSTRE_Q_DELETEQID)  &&
+           limit_mask != 0) {
                fprintf(stderr,
-                       "%s setquota: limits should not be specified when using default quota\n",
+                       "%s setquota: limits should not be specified when using default quota or deleting quota ID\n",
                        progname);
                rc = CMD_HELP;
                goto out;
@@ -7826,6 +7895,14 @@ quota_type_def:
                goto out;
        }
 
+       if (qctl->qc_cmd == LUSTRE_Q_DELETEQID  && qctl->qc_id == 0) {
+               fprintf(stderr,
+                       "%s setquota: can not delete root user/group/project\n",
+                       progname);
+               rc = CMD_HELP;
+               goto out;
+       }
+
        if (optind != argc - 1) {
                fprintf(stderr,
                        "%s setquota: filesystem not specified or unexpected argument '%s'\n",
@@ -7850,33 +7927,48 @@ quota_type_def:
        } else if ((!(limit_mask & BHLIMIT) ^ !(limit_mask & BSLIMIT)) ||
                   (!(limit_mask & IHLIMIT) ^ !(limit_mask & ISLIMIT))) {
                /* sigh, we can't just set blimits/ilimits */
-               struct if_quotactl tmp_qctl = {.qc_cmd  = LUSTRE_Q_GETQUOTA,
-                                              .qc_type = qctl->qc_type,
-                                              .qc_id   = qctl->qc_id};
+               struct if_quotactl *tmp_qctl;
 
-               rc = llapi_quotactl(mnt, &tmp_qctl);
-               if (rc < 0)
+               tmp_qctl = calloc(1, sizeof(*qctl) + LOV_MAXPOOLNAME + 1);
+               if (!tmp_qctl)
+                       goto out;
+
+               if (qctl->qc_cmd == LUSTRE_Q_SETQUOTAPOOL) {
+                       tmp_qctl->qc_cmd = LUSTRE_Q_GETQUOTAPOOL;
+                       strncpy(tmp_qctl->qc_poolname, qctl->qc_poolname,
+                               LOV_MAXPOOLNAME);
+               } else {
+                       tmp_qctl->qc_cmd  = LUSTRE_Q_GETQUOTA;
+               }
+               tmp_qctl->qc_type = qctl->qc_type;
+               tmp_qctl->qc_id = qctl->qc_id;
+
+               rc = llapi_quotactl(mnt, tmp_qctl);
+               if (rc < 0) {
+                       free(tmp_qctl);
                        goto out;
+               }
 
                if (!(limit_mask & BHLIMIT))
-                       dqb->dqb_bhardlimit = tmp_qctl.qc_dqblk.dqb_bhardlimit;
+                       dqb->dqb_bhardlimit = tmp_qctl->qc_dqblk.dqb_bhardlimit;
                if (!(limit_mask & BSLIMIT))
-                       dqb->dqb_bsoftlimit = tmp_qctl.qc_dqblk.dqb_bsoftlimit;
+                       dqb->dqb_bsoftlimit = tmp_qctl->qc_dqblk.dqb_bsoftlimit;
                if (!(limit_mask & IHLIMIT))
-                       dqb->dqb_ihardlimit = tmp_qctl.qc_dqblk.dqb_ihardlimit;
+                       dqb->dqb_ihardlimit = tmp_qctl->qc_dqblk.dqb_ihardlimit;
                if (!(limit_mask & ISLIMIT))
-                       dqb->dqb_isoftlimit = tmp_qctl.qc_dqblk.dqb_isoftlimit;
+                       dqb->dqb_isoftlimit = tmp_qctl->qc_dqblk.dqb_isoftlimit;
 
                /* Keep grace times if we have got no softlimit arguments */
                if ((limit_mask & BHLIMIT) && !(limit_mask & BSLIMIT)) {
                        dqb->dqb_valid |= QIF_BTIME;
-                       dqb->dqb_btime = tmp_qctl.qc_dqblk.dqb_btime;
+                       dqb->dqb_btime = tmp_qctl->qc_dqblk.dqb_btime;
                }
 
                if ((limit_mask & IHLIMIT) && !(limit_mask & ISLIMIT)) {
                        dqb->dqb_valid |= QIF_ITIME;
-                       dqb->dqb_itime = tmp_qctl.qc_dqblk.dqb_itime;
+                       dqb->dqb_itime = tmp_qctl->qc_dqblk.dqb_itime;
                }
+               free(tmp_qctl);
        }
 
        dqb->dqb_valid |= (limit_mask & (BHLIMIT | BSLIMIT)) ? QIF_BLIMITS : 0;
@@ -8216,6 +8308,28 @@ static int print_obd_quota(char *mnt, struct if_quotactl *qctl, int is_mdt,
                                goto out;
                        }
 
+                       /* no target for this index yet */
+                       if (rc == -ENODEV) {
+                               rc = 0;
+                               continue;
+                       }
+
+                       /* inactive target */
+                       if (rc == -ENODATA) {
+                               char name[UUID_MAX+8];
+
+                               snprintf(name, sizeof(name), "%s[inact]",
+                                       obd_uuid2str(&qctl->obd_uuid));
+                               memset(&qctl->qc_dqinfo, 0,
+                                      sizeof(qctl->qc_dqinfo));
+                               memset(&qctl->qc_dqblk, 0,
+                                      sizeof(qctl->qc_dqblk));
+                               print_quota(name, qctl, qctl->qc_valid, 0, h,
+                                           false);
+                               rc = 0;
+                               continue;
+                       }
+
                        if (!rc1)
                                rc1 = rc;
                        fprintf(stderr, "quotactl %s%d failed.\n",
@@ -9426,7 +9540,7 @@ static int lfs_data_version(int argc, char **argv)
                        fprintf(stderr,
                                "%s data_version: unrecognized option '%s'\n",
                                progname, argv[optind - 1]);
-                       /* fallthrough */
+                       fallthrough;
                case 'h':
                        return CMD_HELP;
                }
@@ -9570,7 +9684,7 @@ static int lfs_hsm_change_flags(int argc, char **argv, int mode)
                default:
                        fprintf(stderr, "%s: unrecognized option '%s'\n",
                                progname, argv[optind - 1]);
-                       /* fallthrough */
+                       fallthrough;
                case 'h':
                        return CMD_HELP;
                }
@@ -9804,7 +9918,7 @@ static int lfs_hsm_request(int argc, char **argv, int action)
                default:
                        fprintf(stderr, "%s: unrecognized option '%s'\n",
                                progname, argv[optind - 1]);
-                       /* fallthrough */
+                       fallthrough;
                case 'h':
                        return CMD_HELP;
                }
@@ -10104,7 +10218,7 @@ static int lfs_ladvise(int argc, char **argv)
                default:
                        fprintf(stderr, "%s: unrecognized option '%s'\n",
                                progname, argv[optind - 1]);
-                       /* fallthrough */
+                       fallthrough;
                case 'h':
                        return CMD_HELP;
                }
@@ -10293,7 +10407,7 @@ static int lfs_heat_set(int argc, char **argv)
                default:
                        fprintf(stderr, "%s: unrecognized option '%s'\n",
                                progname, argv[optind - 1]);
-                       /* fallthrough */
+                       fallthrough;
                case 'h':
                        return CMD_HELP;
                }
@@ -10746,7 +10860,7 @@ static inline int lfs_mirror_resync(int argc, char **argv)
                default:
                        fprintf(stderr, "%s: unrecognized option '%s'\n",
                                progname, argv[optind - 1]);
-                       /* fallthrough */
+                       fallthrough;
                case 'h':
                        rc = CMD_HELP;
                        goto error;
@@ -10892,7 +11006,7 @@ static inline int lfs_mirror_read(int argc, char **argv)
                default:
                        fprintf(stderr, "%s: unrecognized option '%s'\n",
                                progname, argv[optind - 1]);
-                       /* fallthrough */
+                       fallthrough;
                case 'h':
                        return CMD_HELP;
                }
@@ -11057,7 +11171,7 @@ static inline int lfs_mirror_write(int argc, char **argv)
                default:
                        fprintf(stderr, "%s: unrecognized option '%s'\n",
                                progname, argv[optind - 1]);
-                       /* fallthrough */
+                       fallthrough;
                case 'h':
                        return CMD_HELP;
                }
@@ -11307,7 +11421,7 @@ static inline int lfs_mirror_copy(int argc, char **argv)
                default:
                        fprintf(stderr, "%s: unrecognized option '%s'\n",
                                progname, argv[optind - 1]);
-                       /* fallthrough */
+                       fallthrough;
                case 'h':
                        return CMD_HELP;
                }
@@ -11533,13 +11647,13 @@ void print_chunks(const char *fname, struct verify_chunk *chunks,
  * Return: void.
  */
 static inline
-void print_checksums(struct verify_chunk *chunk, unsigned long *crc)
+void print_checksums(struct verify_chunk *chunk, unsigned long *crc,
+                    unsigned long long pos, unsigned long long len)
 {
        int i;
 
        fprintf(stdout,
-               "CRC-32 checksum value for chunk "DEXT":\n",
-               PEXT(&chunk->chunk));
+               "CRC-32 checksum value for chunk "DEXT":\n", pos, pos + len);
        for (i = 0; i < chunk->mirror_count; i++)
                fprintf(stdout, "Mirror %u:\t%#lx\n",
                        chunk->mirror_id[i], crc[i]);
@@ -11691,8 +11805,6 @@ int lfs_mirror_prepare_chunk(struct llapi_layout *layout,
                                goto error;
                        }
 
-                       chunks[idx].mirror_id[i] = mirror_id;
-                       i++;
                        if (i >= ARRAY_SIZE(chunks[idx].mirror_id)) {
                                fprintf(stderr,
                                        "%s: mirror_id array is too small.\n",
@@ -11700,6 +11812,8 @@ int lfs_mirror_prepare_chunk(struct llapi_layout *layout,
                                rc = -EINVAL;
                                goto error;
                        }
+                       chunks[idx].mirror_id[i] = mirror_id;
+                       i++;
 
 next:
                        rc = llapi_layout_comp_use(layout,
@@ -11805,7 +11919,7 @@ int lfs_mirror_verify_chunk(int fd, size_t file_size,
                }
 
                if (verbose)
-                       print_checksums(chunk, crc_array);
+                       print_checksums(chunk, crc_array, pos, buflen);
 
                /* compare CRC-32 checksum values */
                for (i = 1; i < chunk->mirror_count; i++) {
@@ -12073,7 +12187,7 @@ static inline int lfs_mirror_verify(int argc, char **argv)
                default:
                        fprintf(stderr, "%s: unrecognized option '%s'\n",
                                progname, argv[optind - 1]);
-                       /* fallthrough */
+                       fallthrough;
                case 'h':
                        rc = CMD_HELP;
                        goto error;
@@ -12180,7 +12294,7 @@ static int lfs_getsom(int argc, char **argv)
                default:
                        fprintf(stderr, "%s: unrecognized option '%s'\n",
                                progname, argv[optind - 1]);
-                       /* fallthrough */
+                       fallthrough;
                case 'h':
                        return CMD_HELP;
                }
@@ -12283,7 +12397,7 @@ static int lfs_pcc_attach(int argc, char **argv)
                default:
                        fprintf(stderr, "%s: unrecognized option '%s'\n",
                                progname, argv[optind - 1]);
-                       /* fallthrough */
+                       fallthrough;
                case 'h':
                        return CMD_HELP;
                }
@@ -12360,7 +12474,7 @@ static int lfs_pcc_attach_fid(int argc, char **argv)
                default:
                        fprintf(stderr, "%s: unrecognized option '%s'\n",
                                progname, argv[optind - 1]);
-                       /* fallthrough */
+                       fallthrough;
                case 'h':
                        return CMD_HELP;
                }
@@ -12423,7 +12537,7 @@ static int lfs_pcc_detach(int argc, char **argv)
                default:
                        fprintf(stderr, "%s: unrecognized option '%s'\n",
                                progname, argv[optind - 1]);
-                       /* fallthrough */
+                       fallthrough;
                case 'h':
                        return CMD_HELP;
                }
@@ -12476,7 +12590,7 @@ static int lfs_pcc_detach_fid(int argc, char **argv)
                default:
                        fprintf(stderr, "%s: unrecognized option '%s'\n",
                                progname, argv[optind - 1]);
-                       /* fallthrough */
+                       fallthrough;
                case 'h':
                        return CMD_HELP;
                }