From: Thomas Stibor Date: Thu, 15 Oct 2015 11:07:00 +0000 (+0200) Subject: LU-7299 utils: allow mkfs.lustre --index to specify in hex/dec X-Git-Tag: 2.7.63~37 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=069a25b61ecdfc7b01edfa302ff49b1a6897928a LU-7299 utils: allow mkfs.lustre --index to specify in hex/dec 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 Change-Id: I9f7564e3d674353fbebef18bde1598c01bb5bb2c Reviewed-on: http://review.whamcloud.com/16831 Tested-by: Jenkins Reviewed-by: Nathaniel Clark Tested-by: Maloo Reviewed-by: Andreas Dilger --- diff --git a/lustre/doc/mkfs.lustre.8 b/lustre/doc/mkfs.lustre.8 index 6100656..2ac2991 100644 --- a/lustre/doc/mkfs.lustre.8 +++ b/lustre/doc/mkfs.lustre.8 @@ -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. diff --git a/lustre/utils/mkfs_lustre.c b/lustre/utils/mkfs_lustre.c index 76974e8..627e659 100644 --- a/lustre/utils/mkfs_lustre.c +++ b/lustre/utils/mkfs_lustre.c @@ -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(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));