Whamcloud - gitweb
LU-7299 utils: allow mkfs.lustre --index to specify in hex/dec 31/16831/6
authorThomas Stibor <t.stibor@gsi.de>
Thu, 15 Oct 2015 11:07:00 +0000 (13:07 +0200)
committerOleg Drokin <oleg.drokin@intel.com>
Wed, 28 Oct 2015 13:52:37 +0000 (13:52 +0000)
The mkfs.lustre --index argument should be able to handle hex
index values as well as decimal values, especially since the
OSTxxxx identifiers are printed in hexadecimal as well.

Signed-off-by: Thomas Stibor <t.stibor@gsi.de>
Change-Id: I9f7564e3d674353fbebef18bde1598c01bb5bb2c
Reviewed-on: http://review.whamcloud.com/16831
Tested-by: Jenkins
Reviewed-by: Nathaniel Clark <nathaniel.l.clark@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
lustre/doc/mkfs.lustre.8
lustre/utils/mkfs_lustre.c

index 6100656..2ac2991 100644 (file)
@@ -81,6 +81,8 @@ length is 8 characters. Required for all targets other than MGS.
 .TP
 .BI \--index= index
 Specify a particular OST or MDT index. Required for all targets other than the MGS.
+The index parameter may either be a decimal number or a hexadecimal number
+starting with '0x'.
 .TP
 .BI \--mkfsoptions= opts
 Format options for the backing fs. For example, ext3 options could be set here.
index 76974e8..627e659 100644 (file)
@@ -132,7 +132,9 @@ void usage(FILE *out)
                "\t\t--ost: object storage, mutually exclusive with mdt, mgs\n"
                "\toptions (in order of popularity):\n"
                "\t\t--index=#N: numerical target index (0..N)\n"
-               "\t\t\trequired for all targets other than the MGS\n"
+               "\t\t\trequired for all targets other than the MGS,\n"
+               "\t\t\ttarget index may either be a decimal number or\n"
+               "\t\t\thexadecimal number starting with '0x'\n"
                "\t\t--fsname=<8_char_filesystem_name>: fs targets belong to\n"
                "\t\t\trequired for all targets other than MGS\n"
                "\t\t--mgsnode=<nid>[,<...>]: NID(s) of remote MGS\n"
@@ -406,10 +408,23 @@ int parse_opts(int argc, char *const argv[], struct mkfs_opts *mop,
                 case 'h':
                         usage(stdout);
                         return 1;
-                case 'i':
+               case 'i': {
+                       char *endptr = NULL;
+                       int base;
                        index_option = true;
                        /* LU-2374: check whether it is OST/MDT later */
-                       mop->mo_ldd.ldd_svindex = atol(optarg);
+                       base = (strlen(optarg) > 1 &&
+                               !strncmp(optarg, "0x", 2)) ? 16 : 10;
+                       /* Allowed input are base 16 and base 10 numbers only */
+                       mop->mo_ldd.ldd_svindex = strtoul(optarg,
+                                                         &endptr, base);
+                       if (*endptr != '\0') {
+                               fprintf(stderr, "%s: wrong index %s. "
+                                       "Target index must be decimal or "
+                                       "hexadecimal.\n",
+                                       progname, optarg);
+                               return 1;
+                       }
                        if (mop->mo_ldd.ldd_svindex >= INDEX_UNASSIGNED) {
                                fprintf(stderr, "%s: wrong index %u. "
                                        "Target index must be less than %u.\n",
@@ -418,7 +433,8 @@ int parse_opts(int argc, char *const argv[], struct mkfs_opts *mop,
                                return 1;
                        }
                        mop->mo_ldd.ldd_flags &= ~LDD_F_NEED_INDEX;
-                        break;
+                       break;
+               }
                 case 'k':
                         strscpy(mop->mo_mkfsopts, optarg,
                                 sizeof(mop->mo_mkfsopts));