Whamcloud - gitweb
LU-8314 lfs: improve getdirstripe interface 19/24319/4
authorLai Siyao <lai.siyao@intel.com>
Tue, 13 Dec 2016 15:57:40 +0000 (23:57 +0800)
committerOleg Drokin <oleg.drokin@intel.com>
Sun, 1 Jan 2017 01:57:49 +0000 (01:57 +0000)
* remove unused options '-v' '-R' '-q' for "lfs getdirstripe".
* add "[--mdt-hash|-t]" option for "lfs getdirstripe", and print
  hash_type by default.

Signed-off-by: Lai Siyao <lai.siyao@intel.com>
Change-Id: Ib7eaf00744d0cd5dec13e683c39e2ecf1d54808b
Reviewed-on: https://review.whamcloud.com/24319
Tested-by: Jenkins
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Niu Yawei <yawei.niu@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/include/lustre/lustre_idl.h
lustre/include/lustre/lustre_user.h
lustre/include/lustre/lustreapi.h
lustre/llite/dir.c
lustre/mdt/mdt_handler.c
lustre/mdt/mdt_lib.c
lustre/utils/lfs.c
lustre/utils/liblustreapi.c

index 4b5b0e4..aa8853f 100644 (file)
@@ -2655,6 +2655,18 @@ static inline int lmv_mds_md_stripe_count_get(const union lmv_mds_md *lmm)
        }
 }
 
        }
 }
 
+static inline int lmv_mds_md_hash_type_get(const union lmv_mds_md *lmm)
+{
+       switch (__le32_to_cpu(lmm->lmv_magic)) {
+       case LMV_MAGIC_V1:
+               return __le32_to_cpu(lmm->lmv_md_v1.lmv_hash_type);
+       case LMV_USER_MAGIC:
+               return __le32_to_cpu(lmm->lmv_user_md.lum_hash_type);
+       default:
+               return -EINVAL;
+       }
+}
+
 enum fld_rpc_opc {
        FLD_QUERY       = 900,
        FLD_READ        = 901,
 enum fld_rpc_opc {
        FLD_QUERY       = 900,
        FLD_READ        = 901,
index 3ec5a6e..4f3f74f 100644 (file)
@@ -441,11 +441,14 @@ enum lmv_hash_type {
        LMV_HASH_TYPE_UNKNOWN   = 0,    /* 0 is reserved for testing purpose */
        LMV_HASH_TYPE_ALL_CHARS = 1,
        LMV_HASH_TYPE_FNV_1A_64 = 2,
        LMV_HASH_TYPE_UNKNOWN   = 0,    /* 0 is reserved for testing purpose */
        LMV_HASH_TYPE_ALL_CHARS = 1,
        LMV_HASH_TYPE_FNV_1A_64 = 2,
+       LMV_HASH_TYPE_MAX,
 };
 
 #define LMV_HASH_NAME_ALL_CHARS        "all_char"
 #define LMV_HASH_NAME_FNV_1A_64        "fnv_1a_64"
 
 };
 
 #define LMV_HASH_NAME_ALL_CHARS        "all_char"
 #define LMV_HASH_NAME_FNV_1A_64        "fnv_1a_64"
 
+extern char *mdt_hash_name[LMV_HASH_TYPE_MAX];
+
 /* Got this according to how get LOV_MAX_STRIPE_COUNT, see above,
  * (max buffer size - lmv+rpc header) / sizeof(struct lmv_user_mds_data) */
 #define LMV_MAX_STRIPE_COUNT 2000  /* ((12 * 4096 - 256) / 24) */
 /* Got this according to how get LOV_MAX_STRIPE_COUNT, see above,
  * (max buffer size - lmv+rpc header) / sizeof(struct lmv_user_mds_data) */
 #define LMV_MAX_STRIPE_COUNT 2000  /* ((12 * 4096 - 256) / 24) */
index 1aee03a..73a76a1 100644 (file)
@@ -142,10 +142,11 @@ extern int llapi_file_lookup(int dirfd, const char *name);
 #define VERBOSE_COMP_END       0x1000
 #define VERBOSE_COMP_ID                0x2000
 #define VERBOSE_DFID           0x4000
 #define VERBOSE_COMP_END       0x1000
 #define VERBOSE_COMP_ID                0x2000
 #define VERBOSE_DFID           0x4000
+#define VERBOSE_HASH_TYPE      0x8000
 #define VERBOSE_DEFAULT                (VERBOSE_COUNT | VERBOSE_SIZE | \
                                 VERBOSE_OFFSET | VERBOSE_POOL | \
                                 VERBOSE_OBJID | VERBOSE_GENERATION | \
 #define VERBOSE_DEFAULT                (VERBOSE_COUNT | VERBOSE_SIZE | \
                                 VERBOSE_OFFSET | VERBOSE_POOL | \
                                 VERBOSE_OBJID | VERBOSE_GENERATION | \
-                                VERBOSE_LAYOUT)
+                                VERBOSE_LAYOUT | VERBOSE_HASH_TYPE)
 
 struct find_param {
        unsigned int             fp_max_depth;
 
 struct find_param {
        unsigned int             fp_max_depth;
index d7e8d19..f6104e3 100644 (file)
@@ -1350,6 +1350,7 @@ lmv_out_free:
                tmp->lum_magic = LMV_MAGIC_V1;
                tmp->lum_stripe_count = 0;
                tmp->lum_stripe_offset = mdt_index;
                tmp->lum_magic = LMV_MAGIC_V1;
                tmp->lum_stripe_count = 0;
                tmp->lum_stripe_offset = mdt_index;
+               tmp->lum_hash_type = lmv_mds_md_hash_type_get(lmm);
                for (i = 0; i < stripe_count; i++) {
                        struct lu_fid   fid;
 
                for (i = 0; i < stripe_count; i++) {
                        struct lu_fid   fid;
 
index 45be626..db90982 100644 (file)
@@ -1084,6 +1084,7 @@ static int mdt_getattr_internal(struct mdt_thread_info *info,
                        if (!mdt_is_striped_client(req->rq_export))
                                RETURN(-ENOTSUPP);
                        LASSERT(S_ISDIR(la->la_mode));
                        if (!mdt_is_striped_client(req->rq_export))
                                RETURN(-ENOTSUPP);
                        LASSERT(S_ISDIR(la->la_mode));
+                       mdt_dump_lmv(D_INFO, ma->ma_lmv);
                        repbody->mbo_eadatasize = ma->ma_lmv_size;
                        repbody->mbo_valid |= (OBD_MD_FLDIREA |
                                               OBD_MD_DEFAULT_MEA);
                        repbody->mbo_eadatasize = ma->ma_lmv_size;
                        repbody->mbo_valid |= (OBD_MD_FLDIREA |
                                               OBD_MD_DEFAULT_MEA);
index 557204f..23726da 100644 (file)
@@ -616,10 +616,12 @@ void mdt_dump_lmv(unsigned int level, const union lmv_mds_md *lmv)
                return;
 
        lmm1 = &lmv->lmv_md_v1;
                return;
 
        lmm1 = &lmv->lmv_md_v1;
-       CDEBUG(level, "magic 0x%08X, master %#X stripe_count %#x\n",
+       CDEBUG(level,
+              "magic 0x%08X, master %#X stripe_count %#x hash_type %#x\n",
               le32_to_cpu(lmm1->lmv_magic),
               le32_to_cpu(lmm1->lmv_master_mdt_index),
               le32_to_cpu(lmm1->lmv_magic),
               le32_to_cpu(lmm1->lmv_master_mdt_index),
-              le32_to_cpu(lmm1->lmv_stripe_count));
+              le32_to_cpu(lmm1->lmv_stripe_count),
+              le32_to_cpu(lmm1->lmv_hash_type));
 
        if (le32_to_cpu(lmm1->lmv_magic) == LMV_MAGIC_STRIPE)
                return;
 
        if (le32_to_cpu(lmm1->lmv_magic) == LMV_MAGIC_STRIPE)
                return;
index 0f9cd3c..da0ccf7 100644 (file)
@@ -160,7 +160,7 @@ static int lfs_ladvise(int argc, char **argv);
        "               [--mdt-count|-c stripe_count>\n"        \
        "               [--mdt-index|-i mdt_index]\n"           \
        "               [--mdt-hash|-t mdt_hash]\n"             \
        "               [--mdt-count|-c stripe_count>\n"        \
        "               [--mdt-index|-i mdt_index]\n"           \
        "               [--mdt-hash|-t mdt_hash]\n"             \
-       "               [--default_stripe|-D] [--mode|-m mode] <dir>\n" \
+       "               [--default|-D] [--mode|-m mode] <dir>\n"        \
        "\tstripe_count: stripe count of the striped directory\n"       \
        "\tmdt_index: MDT index of first stripe\n"                      \
        "\tmdt_hash:  hash type of the striped directory. mdt types:\n" \
        "\tstripe_count: stripe count of the striped directory\n"       \
        "\tmdt_index: MDT index of first stripe\n"                      \
        "\tmdt_hash:  hash type of the striped directory. mdt types:\n" \
@@ -198,9 +198,9 @@ command_t cmdlist[] = {
        {"getdirstripe", lfs_getdirstripe, 0,
         "To list the striping info for a given directory\n"
         "or recursively for all directories in a directory tree.\n"
        {"getdirstripe", lfs_getdirstripe, 0,
         "To list the striping info for a given directory\n"
         "or recursively for all directories in a directory tree.\n"
-        "usage: getdirstripe [--obd|-O <uuid>] [--quiet|-q] [--verbose|-v]\n"
-        "               [--count|-c ] [--index|-i ] [--raw|-R]\n"
-        "               [--recursive | -r] [ --default_stripe | -D ] <dir> "},
+        "usage: getdirstripe [--obd|-O <uuid>] [--mdt-count|-c]\n"
+        "                    [--mdt-index|-i] [--mdt-hash|-t]\n"
+        "                    [--recursive|-r] [--default|-D] <dir> ..."},
        {"mkdir", lfs_setdirstripe, 0,
         "To create a striped directory on a specified MDT. This can only\n"
         "be done on MDT0 with the right of administrator.\n"
        {"mkdir", lfs_setdirstripe, 0,
         "To create a striped directory on a specified MDT. This can only\n"
         "be done on MDT0 with the right of administrator.\n"
@@ -1966,9 +1966,68 @@ static int lfs_getstripe(int argc, char **argv)
 static int lfs_getdirstripe(int argc, char **argv)
 {
        struct find_param param = { 0 };
 static int lfs_getdirstripe(int argc, char **argv)
 {
        struct find_param param = { 0 };
+       struct option long_opts[] = {
+               {"mdt-count",   no_argument,            0, 'c'},
+               {"mdt-index",   no_argument,            0, 'i'},
+               {"recursive",   no_argument,            0, 'r'},
+               {"mdt-hash",    no_argument,            0, 't'},
+               {"default",     no_argument,            0, 'D'},
+               {"obd",         required_argument,      0, 'O'},
+               {0, 0, 0, 0}
+       };
+       int c, rc;
 
        param.fp_get_lmv = 1;
 
        param.fp_get_lmv = 1;
-       return lfs_getstripe_internal(argc, argv, &param);
+
+       while ((c = getopt_long(argc, argv, "cirtDO:", long_opts, NULL)) != -1)
+       {
+               switch (c) {
+               case 'O':
+                       if (param.fp_obd_uuid) {
+                               fprintf(stderr,
+                                       "error: %s: only one obduuid allowed",
+                                       argv[0]);
+                               return CMD_HELP;
+                       }
+                       param.fp_obd_uuid = (struct obd_uuid *)optarg;
+                       break;
+               case 'c':
+                       param.fp_verbose |= VERBOSE_COUNT;
+                       break;
+               case 'i':
+                       param.fp_verbose |= VERBOSE_OFFSET;
+                       break;
+               case 't':
+                       param.fp_verbose |= VERBOSE_HASH_TYPE;
+                       break;
+               case 'D':
+                       param.fp_get_default_lmv = 1;
+                       break;
+               case 'r':
+                       param.fp_recursive = 1;
+                       break;
+               default:
+                       return CMD_HELP;
+               }
+       }
+
+       if (optind >= argc)
+               return CMD_HELP;
+
+       if (param.fp_recursive)
+               param.fp_max_depth = -1;
+
+       if (!param.fp_verbose)
+               param.fp_verbose = VERBOSE_DEFAULT;
+
+       do {
+               rc = llapi_getstripe(argv[optind], &param);
+       } while (++optind < argc && !rc);
+
+       if (rc)
+               fprintf(stderr, "error: %s failed for %s.\n",
+                       argv[0], argv[optind - 1]);
+       return rc;
 }
 
 /* functions */
 }
 
 /* functions */
@@ -2005,7 +2064,10 @@ static int lfs_setdirstripe(int argc, char **argv)
                {"hash-type",   required_argument, 0, 't'},
 #endif
                {"mdt-hash",    required_argument, 0, 't'},
                {"hash-type",   required_argument, 0, 't'},
 #endif
                {"mdt-hash",    required_argument, 0, 't'},
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
                {"default_stripe", no_argument, 0, 'D'},
                {"default_stripe", no_argument, 0, 'D'},
+#endif
+               {"default",     no_argument, 0, 'D'},
                {0, 0, 0, 0}
        };
 
                {0, 0, 0, 0}
        };
 
@@ -2101,15 +2163,23 @@ static int lfs_setdirstripe(int argc, char **argv)
                previous_mode = umask(0);
        }
 
                previous_mode = umask(0);
        }
 
-       if (stripe_hash_opt == NULL ||
-           strcmp(stripe_hash_opt, LMV_HASH_NAME_FNV_1A_64) == 0) {
+       if (stripe_hash_opt == NULL) {
                hash_type = LMV_HASH_TYPE_FNV_1A_64;
                hash_type = LMV_HASH_TYPE_FNV_1A_64;
-       } else if (strcmp(stripe_hash_opt, LMV_HASH_NAME_ALL_CHARS) == 0) {
-               hash_type = LMV_HASH_TYPE_ALL_CHARS;
        } else {
        } else {
-               fprintf(stderr, "error: %s: bad stripe hash type '%s'\n",
-                       argv[0], stripe_hash_opt);
-               return CMD_HELP;
+               int i;
+
+               for (i = LMV_HASH_TYPE_ALL_CHARS; i < LMV_HASH_TYPE_MAX; i++)
+                       if (strcmp(stripe_hash_opt, mdt_hash_name[i]) == 0)
+                               break;
+
+               if (i == LMV_HASH_TYPE_MAX) {
+                       fprintf(stderr,
+                               "error: %s: bad stripe hash type '%s'\n",
+                               argv[0], stripe_hash_opt);
+                       return CMD_HELP;
+               }
+
+               hash_type = i;
        }
 
        /* get the stripe count */
        }
 
        /* get the stripe count */
index 44747e6..c1fab34 100644 (file)
 
 static int llapi_msg_level = LLAPI_MSG_MAX;
 
 
 static int llapi_msg_level = LLAPI_MSG_MAX;
 
+char *mdt_hash_name[] = { "none",
+                         LMV_HASH_NAME_ALL_CHARS,
+                         LMV_HASH_NAME_FNV_1A_64 };
+
 void llapi_msg_set_level(int level)
 {
         /* ensure level is in the good range */
 void llapi_msg_set_level(int level)
 {
         /* ensure level is in the good range */
@@ -2332,7 +2336,8 @@ void lmv_dump_user_lmm(struct lmv_user_md *lum, char *pool_name,
        /* show all information default */
        if (!verbose) {
                if (lum->lum_magic == LMV_USER_MAGIC)
        /* show all information default */
        if (!verbose) {
                if (lum->lum_magic == LMV_USER_MAGIC)
-                       verbose = VERBOSE_POOL | VERBOSE_COUNT | VERBOSE_OFFSET;
+                       verbose = VERBOSE_POOL | VERBOSE_COUNT |
+                                 VERBOSE_OFFSET | VERBOSE_HASH_TYPE;
                else
                        verbose = VERBOSE_OBJID;
        }
                else
                        verbose = VERBOSE_OBJID;
        }
@@ -2358,6 +2363,24 @@ void lmv_dump_user_lmm(struct lmv_user_md *lum, char *pool_name,
                        llapi_printf(LLAPI_MSG_NORMAL, "lmv_stripe_offset: ");
                llapi_printf(LLAPI_MSG_NORMAL, "%d",
                             (int)lum->lum_stripe_offset);
                        llapi_printf(LLAPI_MSG_NORMAL, "lmv_stripe_offset: ");
                llapi_printf(LLAPI_MSG_NORMAL, "%d",
                             (int)lum->lum_stripe_offset);
+               if (verbose & VERBOSE_HASH_TYPE)
+                       separator = " ";
+               else
+                       separator = "\n";
+       }
+
+       if (verbose & VERBOSE_HASH_TYPE) {
+               unsigned int type = lum->lum_hash_type;
+
+               llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
+               if (verbose & ~VERBOSE_HASH_TYPE)
+                       llapi_printf(LLAPI_MSG_NORMAL, "lmv_hash_type: ");
+               if (type < LMV_HASH_TYPE_MAX)
+                       llapi_printf(LLAPI_MSG_NORMAL, "%s",
+                                    mdt_hash_name[type]);
+               else
+                       llapi_printf(LLAPI_MSG_NORMAL, "%d",
+                                    (int)type);
                separator = "\n";
        }
 
                separator = "\n";
        }