From 450f7e89116ed104f092dd1a709c0f057150a4f7 Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Kalever Date: Wed, 7 Feb 2018 21:40:13 +0530 Subject: create: support [storage ] option $ gluster-block help gluster-block (0.3) usage: gluster-block [] [--json*] commands: create [ha ] [auth ] [prealloc ] [storage ] create block device [defaults: ha 1, auth disable, prealloc no, size in bytes] [...] supported JSON formats: --json|--json-plain|--json-spaced|--json-pretty Fixes: #18 Change-Id: I5d9b4abb58596bd2297cffb294c6d31f752d53e9 Signed-off-by: Prasanna Kumar Kalever --- cli/gluster-block.c | 106 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 62 insertions(+), 44 deletions(-) (limited to 'cli/gluster-block.c') diff --git a/cli/gluster-block.c b/cli/gluster-block.c index 33d4003..dcf22a1 100644 --- a/cli/gluster-block.c +++ b/cli/gluster-block.c @@ -16,13 +16,13 @@ # define GB_CREATE_HELP_STR "gluster-block create " \ "[ha ] [auth ] " \ - "[prealloc ] " \ - " [--json*]" - -# define GB_DELETE_HELP_STR "gluster-block delete [force] [--json*]" + "[prealloc ] [storage ] " \ + " [--json*]" +# define GB_DELETE_HELP_STR "gluster-block delete " \ + "[force] [--json*]" # define GB_MODIFY_HELP_STR "gluster-block modify " \ " [--json*]" -# define GB_REPLACE_HELP_STR "gluster-block replace " \ +# define GB_REPLACE_HELP_STR "gluster-block replace " \ " [force] [--json*]" # define GB_INFO_HELP_STR "gluster-block info [--json*]" # define GB_LIST_HELP_STR "gluster-block list [--json*]" @@ -202,6 +202,7 @@ glusterBlockHelp(void) " create [ha ]\n" " [auth ]\n" " [prealloc ]\n" + " [storage ]\n" " \n" " create block device [defaults: ha 1, auth disable, prealloc no, size in bytes]\n" "\n" @@ -356,6 +357,8 @@ glusterBlockCreate(int argcount, char **options, int json) int ret = -1; ssize_t sparse_ret; blockCreateCli cobj = {0, }; + bool TAKE_SIZE=true; + bool PREALLOC_OPT=false; if (argcount <= optind) { @@ -373,18 +376,12 @@ glusterBlockCreate(int argcount, char **options, int json) goto out; } - if (argcount - optind >= 2) { /* atleast 2 needed */ - /* if ha given then collect count which is next by 'ha' arg */ - if (!strcmp(options[optind], "ha")) { - optind++; + while (argcount - optind > 2) { + switch (glusterBlockCLICreateOptEnumParse(options[optind++])) { + case GB_CLI_CREATE_HA: sscanf(options[optind++], "%u", &cobj.mpath); - } - } - - if (argcount - optind >= 2) { /* atleast 2 needed */ - /* if auth given then collect boolean which is next by 'auth' arg */ - if (!strcmp(options[optind], "auth")) { - optind++; + break; + case GB_CLI_CREATE_AUTH: ret = convertStringToTrillianParse(options[optind++]); if(ret >= 0) { cobj.auth_mode = ret; @@ -396,16 +393,12 @@ glusterBlockCreate(int argcount, char **options, int json) cobj.volume, cobj.block_name); goto out; } - } - } - - if (argcount - optind >= 2) { /* atleast 2 needed */ - /* if prealloc given then collect boolean which is next by 'prealloc' arg */ - if (!strcmp(options[optind], "prealloc")) { - optind++; + break; + case GB_CLI_CREATE_PREALLOC: ret = convertStringToTrillianParse(options[optind++]); if(ret >= 0) { cobj.prealloc = ret; + PREALLOC_OPT=true; } else { MSG("%s\n", "'prealloc' option is incorrect"); MSG("%s\n", GB_CREATE_HELP_STR); @@ -414,39 +407,64 @@ glusterBlockCreate(int argcount, char **options, int json) cobj.volume, cobj.block_name); goto out; } + break; + case GB_CLI_CREATE_STORAGE: + GB_STRCPYSTATIC(cobj.storage, options[optind++]); + TAKE_SIZE=false; + break; } } - if (argcount - optind < 2) { /* left with servers and size so 2 */ - MSG("Inadequate arguments for create:\n%s\n", GB_CREATE_HELP_STR); - LOG("cli", GB_LOG_ERROR, - "failed creating block %s on volume %s with hosts %s", - cobj.block_name, cobj.volume, cobj.block_hosts); - goto out; + if (TAKE_SIZE) { + if (argcount - optind != 2) { + MSG("Inadequate arguments for create:\n%s\n", GB_CREATE_HELP_STR); + LOG("cli", GB_LOG_ERROR, + "failed with Inadequate args for create block %s on volume %s with hosts %s", + cobj.block_name, cobj.volume, cobj.block_hosts); + goto out; + } + } else { + if (PREALLOC_OPT) { + MSG("Inadequate arguments for create:\n%s\n", GB_CREATE_HELP_STR); + MSG("%s\n", "Hint: do not use [prealloc ] in combination with [storage ] option"); + LOG("cli", GB_LOG_ERROR, + "failed with Inadequate args for create block %s on volume %s with hosts %s", + cobj.block_name, cobj.volume, cobj.block_hosts); + goto out; + } + + if (argcount - optind != 1) { + MSG("Inadequate arguments for create:\n%s\n", GB_CREATE_HELP_STR); + MSG("%s\n", "Hint: do not use in combination with [storage ] option"); + LOG("cli", GB_LOG_ERROR, + "failed with Inadequate args for create block %s on volume %s with hosts %s", + cobj.block_name, cobj.volume, cobj.block_hosts); + goto out; + } } - /* next arg to 'ha count' will be servers */ if (GB_STRDUP(cobj.block_hosts, options[optind++]) < 0) { LOG("cli", GB_LOG_ERROR, "failed while parsing servers for block <%s/%s>", cobj.volume, cobj.block_name); goto out; } - /* last arg will be size */ - sparse_ret = glusterBlockParseSize("cli", options[optind]); - if (sparse_ret < 0) { - MSG("%s\n", "'' is incorrect"); - MSG("%s\n", GB_CREATE_HELP_STR); - LOG("cli", GB_LOG_ERROR, "failed while parsing size for block <%s/%s>", - cobj.volume, cobj.block_name); - goto out; - } else if (sparse_ret < GB_DEFAULT_SECTOR_SIZE) { - MSG("minimum acceptable block size is %d bytes\n", GB_DEFAULT_SECTOR_SIZE); - LOG("cli", GB_LOG_ERROR, "minimum acceptable block size is %d bytes <%s/%s>", - GB_DEFAULT_SECTOR_SIZE, cobj.volume, cobj.block_name); - goto out; + if (TAKE_SIZE) { + sparse_ret = glusterBlockParseSize("cli", options[optind]); + if (sparse_ret < 0) { + MSG("%s\n", "'' is incorrect"); + MSG("%s\n", GB_CREATE_HELP_STR); + LOG("cli", GB_LOG_ERROR, "failed while parsing size for block <%s/%s>", + cobj.volume, cobj.block_name); + goto out; + } else if (sparse_ret < GB_DEFAULT_SECTOR_SIZE) { + MSG("minimum acceptable block size is %d bytes\n", GB_DEFAULT_SECTOR_SIZE); + LOG("cli", GB_LOG_ERROR, "minimum acceptable block size is %d bytes <%s/%s>", + GB_DEFAULT_SECTOR_SIZE, cobj.volume, cobj.block_name); + goto out; + } + cobj.size = sparse_ret; /* size is unsigned long long */ } - cobj.size = sparse_ret; /* size is unsigned long long */ ret = glusterBlockCliRPC_1(&cobj, CREATE_CLI); if (ret) { -- cgit