diff options
author | Prasanna Kumar Kalever <prasanna.kalever@redhat.com> | 2017-02-22 14:49:55 +0530 |
---|---|---|
committer | Prasanna Kumar Kalever <prasanna.kalever@redhat.com> | 2017-02-24 14:58:50 +0530 |
commit | 9f1c8a5ba49e7cad67b7ebf6e3e119eeb32a7ff0 (patch) | |
tree | 4834de8c226e382c0d342be47b19badb17cf2c94 | |
parent | c1c22333819f744287fb78fb317ff70fa82beab8 (diff) |
cli: change in synopsis for gluster-block commands
from now we will have fixed formats for commands.
The new outfit will look like:
$ gluster-block help
gluster-block (3ba7ec5)
usage:
gluster-block <command> <volname[/blockname]> [<args>]
commands:
create <volname/blockname> [ha <count>] <host1[,host2,...]> <size>
create block device.
list <volname>
list available block devices.
info <volname/blockname>
details about block device.
delete <volname/blockname>
delete block device.
help
show this message and exit.
version
show version info and exit.
Example usage:
$ gluster-block create volume/blockname 192.168.0.1 1GiB
$ gluster-block create volume/blockname ha 2 192.168.0.1,192.168.0.2 1GiB
$ gluster-block list volume
$ gluster-block info volume/blockname
$ gluster-block delete volume/blockname
Change-Id: Idc6b55c26432ed1ac3f002c2a2b3dbb81b180ec2
Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
-rw-r--r-- | README.md | 47 | ||||
-rw-r--r-- | cli/gluster-block.c | 257 | ||||
-rwxr-xr-x | tests/basic.t | 8 | ||||
-rw-r--r-- | utils/utils.c | 42 | ||||
-rw-r--r-- | utils/utils.h | 38 |
5 files changed, 161 insertions, 231 deletions
@@ -66,23 +66,28 @@ managing the command ring buffers - [x] *In all nodes gluster-blockd.service is running* ```script -# gluster-block help -gluster-block (57f0509) +# gluster-block (3ba7ec5) usage: - gluster-block <command> [<args>] <volume=volname> - -commands and arguments: - create <name> create block device - size <size> size in KiB|MiB|GiB|TiB.. - [mpath <count>] multipath requirement for high availability(default: 1) - servers <IP1,IP2,IP3...> servers in the pool where targets are exported - list list available block devices - info <name> details about block device - modify <resize|auth> modify metadata - delete <name> delete block device - volume <volname> volume that hosts the block device - help show this message and exit - version show version info and exit + gluster-block <command> <volname[/blockname]> [<args>] + +commands: + create <volname/blockname> [ha <count>] <host1[,host2,...]> <size> + create block device. + + list <volname> + list available block devices. + + info <volname/blockname> + details about block device. + + delete <volname/blockname> + delete block device. + + help + show this message and exit. + + version + show version info and exit. ``` #### Example: @@ -94,8 +99,8 @@ Create a gluster volume by pooling 3 nodes (192.168.1.11, 192.168.1.12 and 192.1 Read More on how to [create a gluster volume](https://access.redhat.com/documentation/en-US/Red_Hat_Storage/2.1/html/Administration_Guide/sect-User_Guide-Setting_Volumes-Replicated.html)* <pre> -Create 1G gluster block storage -<b># gluster-block create sample-block volume block-test size 1GiB mpath 3 servers 192.168.1.11,192.168.1.12,192.168.1.13</b> +Create 1G gluster block storage with name 'sample-block' +<b># gluster-block create block-test/sample-block ha 3 192.168.1.11,192.168.1.12,192.168.1.13 1GiB</b> Created user-backed storage object sample-block size 1073741824. Created target iqn.2016-12.org.gluster-block:6b60c53c-8ce0-4d8d-a42c-5b546bca3d09. Created TPG 1. @@ -117,10 +122,10 @@ Created LUN 0. Using default IP port 3260 Created network portal 192.168.1.13:3260. -<b># gluster-block list volume block-test</b> +<b># gluster-block list block-test</b> sample-block -<b># gluster-block info sample-block volume block-test</b> +<b># gluster-block info block-test/sample-block</b> NAME: sample-block VOLUME: block-test GBID: 6b60c53c-8ce0-4d8d-a42c-5b546bca3d09 @@ -151,7 +156,7 @@ On initiator node # iscsiadm -m node -u On the gluster-block node -<b># gluster-block delete sample-block volume block-test</b> +<b># gluster-block delete block-test/sample-block</b> Deleted storage object sample-block. Deleted Target iqn.2016-12.org.gluster-block:6b60c53c-8ce0-4d8d-a42c-5b546bca3d09. diff --git a/cli/gluster-block.c b/cli/gluster-block.c index 28ce99b..304a116 100644 --- a/cli/gluster-block.c +++ b/cli/gluster-block.c @@ -32,6 +32,7 @@ const char *argp_program_version = "" \ "or later), or the GNU General Public License, version 2 (GPLv2),\n"\ "in all cases as published by the Free Software Foundation."; + static int glusterBlockCliRPC_1(void *cobj, clioperations opt, char **out) { @@ -151,20 +152,26 @@ glusterBlockHelp(void) MSG("%s", PACKAGE_NAME" ("PACKAGE_VERSION")\n" "usage:\n" - " gluster-block <command> [<args>] <volume=volname>\n" + " gluster-block <command> <volname[/blockname]> [<args>]\n" + "\n" + "commands:\n" + " create <volname/blockname> [ha <count>] <host1[,host2,...]> <size>\n" + " create block device.\n" + "\n" + " list <volname>\n" + " list available block devices.\n" + "\n" + " info <volname/blockname>\n" + " details about block device.\n" "\n" - "commands and arguments:\n" - " create <name> create block device\n" - " size <size> size in KiB|MiB|GiB|TiB..\n" - " [mpath <count>] multipath requirement for high availability(default: 1)\n" - " servers <IP1,IP2,IP3...> servers in the pool where targets are exported\n" - " list list available block devices\n" - " info <name> details about block device\n" - " modify <resize|auth> modify metadata\n" - " delete <name> delete block device\n" - " volume <volname> volume that hosts the block device\n" - " help show this message and exit\n" - " version show version info and exit\n" + " delete <volname/blockname>\n" + " delete block device.\n" + "\n" + " help\n" + " show this message and exit.\n" + "\n" + " version\n" + " show version info and exit.\n" ); } @@ -172,88 +179,82 @@ glusterBlockHelp(void) static int glusterBlockCreate(int argcount, char **options) { - size_t opt; size_t optind = 2; - int ret = 0; + int ret = -1; + ssize_t sparse_ret; char *out = NULL; - static blockCreateCli cobj = {0, }; + blockCreateCli cobj = {0, }; + char *argcopy; + char *sep; - if(argcount <= optind) { + if (argcount <= optind) { MSG("%s\n", "Insufficient arguments for create:"); - MSG("%s\n", "gluster-block create <block-name> volume <volname> " - "size <bytes> [mpath <count>] servers <IP1,IP2,...>"); + MSG("%s\n", "gluster-block create <volname/blockname> [ha <count>]" + " <HOST1[,HOST2,...]> <size>"); return -1; } - /* name of block */ - strcpy(cobj.block_name, options[optind++]); - /* default mpath */ cobj.mpath = 1; - while (1) { - if(argcount <= optind) { - break; - } - - opt = glusterBlockCLICreateOptEnumParse(options[optind++]); - if (opt == GB_CLI_CREATE_OPT_MAX) { - MSG("unrecognized option '%s'\n", options[optind-1]); - return -1; - } else if (opt && !options[optind]) { - MSG("%s: require argument\n", options[optind-1]); - return -1; - } + if (GB_STRDUP (argcopy, options[optind++]) < 0) { + goto out; + } + /* part before '/' is the volume name */ + sep = strchr(argcopy, '/'); + if (!sep) { + MSG("%s\n", + "first argument '<volname/blockname>' doesn't seems to be right"); + MSG("%s\n", "gluster-block create <volname/blockname> [ha <count>] " + " <HOST1[,HOST2,...]> <size>"); + LOG("cli", GB_LOG_ERROR, "%s", + "create failed while parsing <volname/blockname>"); + goto out; + } + *sep = '\0'; + strcpy(cobj.volume, argcopy); - switch (opt) { - case GB_CLI_CREATE_VOLUME: - strcpy(cobj.volume, options[optind++]); - ret++; - break; + /* part after / is blockname */ + strcpy(cobj.block_name, sep + 1); - case GB_CLI_CREATE_MULTIPATH: + 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++; sscanf(options[optind++], "%u", &cobj.mpath); - break; - - case GB_CLI_CREATE_SIZE: - cobj.size = glusterBlockCreateParseSize("cli", options[optind++]); - if (cobj.size < 0) { - LOG("cli", GB_LOG_ERROR, "failed while parsing size for block %s", - cobj.block_name); - ret = -1; - goto out; - } - ret++; - break; - - case GB_CLI_CREATE_BACKEND_SERVESRS: - if (GB_STRDUP(cobj.block_hosts, options[optind++]) < 0) { - LOG("cli", GB_LOG_ERROR, "failed while parsing servers for block %s", - cobj.block_name); - ret = -1; - goto out; - } - ret++; - break; - - default: - MSG("unrecognized option '%s'\n", options[optind-1]); - MSG("%s", "Hint: gluster-block help\n"); - ret = -1; - goto out; } } - /* check all options required by create command are specified */ - if(ret < 3) { - MSG("%s\n", "Insufficient arguments for create:"); - MSG("%s\n", "gluster-block create <block-name> volume <volname> " - "size <bytes> [mpath <count>] servers <IP1,IP2,...>"); - ret = -1; + if (argcount - optind < 2) { /* left with servers and size so 2 */ + MSG("%s\n", "Insufficient arguments for create"); + MSG("%s\n", "gluster-block create <volname/blockname> [ha <count>]" + " <HOST1[,HOST2,...]> <size>"); + 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; } + /* 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", + cobj.block_name); + goto out; + } + + /* last arg will be size */ + sparse_ret = glusterBlockCreateParseSize("cli", options[optind]); + if (sparse_ret < 0) { + MSG("%s\n", "last argument '<size>' doesn't seems to be right"); + MSG("%s\n", "gluster-block create <volname/blockname> [ha <count>] " + " <HOST1[,HOST2,...]> <size>"); + LOG("cli", GB_LOG_ERROR, "failed while parsing size for block %s", + cobj.block_name); + goto out; + } + cobj.size = sparse_ret; /* size is unsigned long long */ + ret = glusterBlockCliRPC_1(&cobj, CREATE_CLI, &out); if (ret) { LOG("cli", GB_LOG_ERROR, @@ -261,11 +262,12 @@ glusterBlockCreate(int argcount, char **options) cobj.block_name, cobj.volume, cobj.block_hosts); } - if(out) { + if (out) { MSG("%s", out); } out: + GB_FREE(argcopy); GB_FREE(cobj.block_hosts); GB_FREE(out); @@ -276,37 +278,26 @@ glusterBlockCreate(int argcount, char **options) static int glusterBlockList(int argcount, char **options) { - size_t opt; - size_t optind = 2; - static blockListCli cobj; + blockListCli cobj; char *out = NULL; int ret = -1; - if(argcount <= optind) { + if (argcount != 3) { MSG("%s\n", "Insufficient arguments for list:"); - MSG("%s\n", "gluster-block list volume <volname>"); + MSG("%s\n", "gluster-block list <volname>"); return -1; } - opt = glusterBlockCLICommonOptEnumParse(options[optind++]); - if (opt == GB_CLI_COMMON_OPT_MAX) { - MSG("unrecognized option '%s'\n", options[optind-1]); - MSG("%s\n", "List needs 'volume' option"); - return -1; - } else if (!options[optind]) { - MSG("%s: require argument\n", options[optind-1]); - return -1; - } + strcpy(cobj.volume, options[2]); - strcpy(cobj.volume, options[optind]); ret = glusterBlockCliRPC_1(&cobj, LIST_CLI, &out); if (ret) { LOG("cli", GB_LOG_ERROR, "failed listing blocks from volume %s", cobj.volume); } - if(out) { + if (out) { MSG("%s", out); } @@ -319,43 +310,50 @@ glusterBlockList(int argcount, char **options) static int glusterBlockDelete(int argcount, char **options) { - size_t opt; - size_t optind = 2; - static blockDeleteCli cobj; + blockDeleteCli cobj; char *out = NULL; + char *argcopy; + char *sep; int ret = -1; - if(argcount <= optind) { + if (argcount != 3) { MSG("%s\n", "Insufficient arguments for delete:"); - MSG("%s\n", "gluster-block delete <block-name> volume <volname>"); + MSG("%s\n", "gluster-block delete <volname/blockname>"); return -1; } - /* name of block */ - strcpy(cobj.block_name, options[optind++]); - opt = glusterBlockCLICommonOptEnumParse(options[optind++]); - if (opt == GB_CLI_COMMON_OPT_MAX) { - MSG("unrecognized option '%s'\n", options[optind-1]); - MSG("%s\n", "Delete needs 'volume' option"); - return -1; - } else if (!options[optind]) { - MSG("%s: require argument\n", options[optind-1]); - return -1; + if (GB_STRDUP (argcopy, options[2]) < 0) { + goto out; + } + /* part before '/' is the volume name */ + sep = strchr(argcopy, '/'); + if (!sep) { + MSG("%s\n", "argument '<volname/blockname>' doesn't seems to be right"); + MSG("%s\n", "gluster-block delete <volname/blockname>"); + LOG("cli", GB_LOG_ERROR, "%s", + "delete failed while parsing <volname/blockname>"); + goto out; } + *sep = '\0'; + strcpy(cobj.volume, argcopy); + + /* part after / is blockname */ + strcpy(cobj.block_name, sep + 1); - strcpy(cobj.volume, options[optind]); ret = glusterBlockCliRPC_1(&cobj, DELETE_CLI, &out); if (ret) { LOG("cli", GB_LOG_ERROR, "failed deleting block %s on volume %s", cobj.block_name, cobj.volume); } - if(out) { + if (out) { MSG("%s", out); } + out: + GB_FREE(argcopy); GB_FREE(out); return ret; @@ -365,33 +363,38 @@ glusterBlockDelete(int argcount, char **options) static int glusterBlockInfo(int argcount, char **options) { - size_t opt; - size_t optind = 2; - static blockInfoCli cobj; + blockInfoCli cobj; char *out = NULL; + char *argcopy; + char *sep; int ret = -1; - if(argcount <= optind) { + if (argcount != 3) { MSG("%s\n", "Insufficient arguments for info:"); - MSG("%s\n", "gluster-block info <block-name> volume <volname>"); + MSG("%s\n", "gluster-block info <volname/blockname>"); return -1; } - /* name of block */ - strcpy(cobj.block_name, options[optind++]); - opt = glusterBlockCLICommonOptEnumParse(options[optind++]); - if (opt == GB_CLI_COMMON_OPT_MAX) { - MSG("unrecognized option '%s'\n", options[optind-1]); - MSG("%s\n", "Info needs 'volume' option"); - return -1; - } else if (!options[optind]) { - MSG("%s: require argument\n", options[optind-1]); - return -1; + if (GB_STRDUP (argcopy, options[2]) < 0) { + goto out; + } + /* part before '/' is the volume name */ + sep = strchr(argcopy, '/'); + if (!sep) { + MSG("%s\n", "argument '<volname/blockname>' doesn't seems to be right"); + MSG("%s\n", "gluster-block info <volname/blockname>"); + LOG("cli", GB_LOG_ERROR, "%s", + "info failed while parsing <volname/blockname>"); + goto out; } + *sep = '\0'; + strcpy(cobj.volume, argcopy); + + /* part after / is blockname */ + strcpy(cobj.block_name, sep + 1); - strcpy(cobj.volume, options[optind]); ret = glusterBlockCliRPC_1(&cobj, INFO_CLI, &out); if (ret) { LOG("cli", GB_LOG_ERROR, @@ -399,10 +402,12 @@ glusterBlockInfo(int argcount, char **options) cobj.block_name, cobj.volume); } - if(out) { + if (out) { MSG("%s", out); } + out: + GB_FREE(argcopy); GB_FREE(out); return ret; diff --git a/tests/basic.t b/tests/basic.t index c2b381c..9d01154 100755 --- a/tests/basic.t +++ b/tests/basic.t @@ -39,7 +39,7 @@ function cleanup() echo -e "\nRunning test cleanup ..." # Block delete - gluster-block delete ${BLKNAME} volume ${VOLNAME} + gluster-block delete ${VOLNAME}/${BLKNAME} gluster --mode=script vol stop ${VOLNAME} gluster --mode=script vol del ${VOLNAME} @@ -77,12 +77,12 @@ TEST systemctl restart gluster-blockd.service sleep 1; # Block create -TEST gluster-block create ${BLKNAME} volume ${VOLNAME} size 1GiB mpath 1 servers ${HOST} +TEST gluster-block create ${VOLNAME}/${BLKNAME} ha 1 ${HOST} 1GiB # Block list -TEST gluster-block list volume ${VOLNAME} +TEST gluster-block list ${VOLNAME} # Block info -TEST gluster-block info ${BLKNAME} volume ${VOLNAME} +TEST gluster-block info ${VOLNAME}/${BLKNAME} cleanup; diff --git a/utils/utils.c b/utils/utils.c index 3441e54..cb0e96e 100644 --- a/utils/utils.c +++ b/utils/utils.c @@ -34,48 +34,6 @@ glusterBlockCLIOptEnumParse(const char *opt) int -glusterBlockCLICreateOptEnumParse(const char *opt) -{ - int i; - - - if (!opt) { - return GB_CLI_CREATE_OPT_MAX; - } - - /* i = 11, enum start look gbCmdlineCreateOption */ - for (i = 11; i < GB_CLI_CREATE_OPT_MAX; i++) { - if (!strcmp(opt, gbCmdlineCreateOptLookup[i])) { - return i; - } - } - - return i; -} - - -int -glusterBlockCLICommonOptEnumParse(const char *opt) -{ - int i; - - - if (!opt) { - return GB_CLI_COMMON_OPT_MAX; - } - - /* i = 21, enum start look gbCmdlineCreateOption */ - for (i = 21; i < GB_CLI_COMMON_OPT_MAX; i++) { - if (!strcmp(opt, gbCmdlineCommonOptLookup[i])) { - return i; - } - } - - return i; -} - - -int blockMetaKeyEnumParse(const char *opt) { int i; diff --git a/utils/utils.h b/utils/utils.h index 77a6de0..3a0521e 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -184,25 +184,6 @@ gbFree(1 ? (void *) &(ptr) : (ptr)) -typedef enum gbCmdlineCreateOption { - /* needed by create option */ - GB_CLI_CREATE_VOLUME = 11, - GB_CLI_CREATE_SIZE = 12, - GB_CLI_CREATE_MULTIPATH = 13, - GB_CLI_CREATE_BACKEND_SERVESRS = 14, - - GB_CLI_CREATE_OPT_MAX -} gbCmdlineCreateOption; - - -typedef enum gbCmdlineCommonOption { - /* common to all the cli options */ - GB_CLI_COMMON_VOLUME = 21, - - GB_CLI_COMMON_OPT_MAX -} gbCmdlineCommonOption; - - typedef enum gbCmdlineOption { GB_CLI_UNKNOWN = 0, @@ -232,21 +213,6 @@ static const char *const gbCmdlineOptLookup[] = { [GB_CLI_OPT_MAX] = NULL, }; -static const char *const gbCmdlineCreateOptLookup[] = { - [GB_CLI_CREATE_VOLUME] = "volume", - [GB_CLI_CREATE_SIZE] = "size", - [GB_CLI_CREATE_MULTIPATH] = "mpath", - [GB_CLI_CREATE_BACKEND_SERVESRS] = "servers", - - - [GB_CLI_CREATE_OPT_MAX] = NULL -}; - -static const char *const gbCmdlineCommonOptLookup[] = { - [GB_CLI_COMMON_VOLUME] = "volume", - - [GB_CLI_COMMON_OPT_MAX] = NULL -}; typedef enum LogLevel { GB_LOG_NONE = 0, @@ -325,10 +291,6 @@ static const char *const MetaStatusLookup[] = { int glusterBlockCLIOptEnumParse(const char *opt); -int glusterBlockCLICreateOptEnumParse(const char *opt); - -int glusterBlockCLICommonOptEnumParse(const char *opt); - int blockMetaKeyEnumParse(const char *opt); int blockMetaStatusEnumParse(const char *opt); |