From d723907c8eaa25f107c7fadd79ca5f9bc6596edf Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Kalever Date: Wed, 2 Aug 2017 23:42:29 +0530 Subject: gluster-block: support force delete option $ gluster-block help gluster-block (0.2.1) usage: gluster-block [] [--json*] commands: [...] delete [force] delete block device. [...] Change-Id: I64ac01ec148e2e1d4d0ba0d4c5560df9334d58f5 Signed-off-by: Prasanna Kumar Kalever --- cli/gluster-block.c | 21 +++++++++++++++++---- docs/gluster-block.8 | 2 +- rpc/block_svc_routines.c | 45 ++++++++++++++++++++++++++------------------- rpc/rpcl/block.x | 1 + 4 files changed, 45 insertions(+), 24 deletions(-) diff --git a/cli/gluster-block.c b/cli/gluster-block.c index 21ad44f..04f081f 100644 --- a/cli/gluster-block.c +++ b/cli/gluster-block.c @@ -20,7 +20,7 @@ "[prealloc ] "\ " [--json*]" -# define GB_DELETE_HELP_STR "gluster-block delete [--json*]" +# define GB_DELETE_HELP_STR "gluster-block delete [force] [--json*]" # define GB_MODIFY_HELP_STR "gluster-block modify "\ " [--json*]" # define GB_INFO_HELP_STR "gluster-block info [--json*]" @@ -202,7 +202,7 @@ glusterBlockHelp(void) " info \n" " details about block device.\n" "\n" - " delete \n" + " delete [force]\n" " delete block device.\n" "\n" " modify \n" @@ -458,7 +458,20 @@ glusterBlockDelete(int argcount, char **options, int json) int ret = -1; - GB_ARGCHECK_OR_RETURN(argcount, 3, "delete", GB_DELETE_HELP_STR); + if (argcount < 3 || argcount > 4) { + MSG("Inadequate arguments for delete:\n%s\n", GB_DELETE_HELP_STR); + return -1; + } + + if (argcount == 4) { + if (strcmp(options[3], "force")) { + MSG("unknown option '%s' for delete:\n%s\n", options[3], GB_DELETE_HELP_STR); + return -1; + } else { + cobj.force = true; + } + } + cobj.json_resp = json; if (glusterBlockParseVolumeBlock (options[2], cobj.volume, @@ -518,7 +531,7 @@ glusterBlockParseArgs(int count, char **options) opt = glusterBlockCLIOptEnumParse(options[1]); if (!opt || opt >= GB_CLI_OPT_MAX) { - MSG("unknown option: %s\n", options[1]); + MSG("Unknown option: %s\n", options[1]); return -1; } diff --git a/docs/gluster-block.8 b/docs/gluster-block.8 index 05f86c9..a23598f 100644 --- a/docs/gluster-block.8 +++ b/docs/gluster-block.8 @@ -55,7 +55,7 @@ details about block device. .PP .SS -\fBdelete\fR +\fBdelete\fR [force] delete block device. .PP diff --git a/rpc/block_svc_routines.c b/rpc/block_svc_routines.c index d04d2cf..b309e79 100644 --- a/rpc/block_svc_routines.c +++ b/rpc/block_svc_routines.c @@ -1131,7 +1131,7 @@ glusterBlockModifyRemoteAsync(MetaInfo *info, static int glusterBlockCleanUp(struct glfs *glfs, char *blockname, - bool deleteall, blockRemoteDeleteResp *drobj) + bool deleteall, bool forcedel, blockRemoteDeleteResp *drobj) { int ret = -1; size_t i; @@ -1190,7 +1190,7 @@ glusterBlockCleanUp(struct glfs *glfs, char *blockname, } } - if (cleanupsuccess == info->nhosts) { + if (forcedel || cleanupsuccess == info->nhosts) { GB_METAUPDATE_OR_GOTO(lock, glfs, blockname, info->volume, ret, errMsg, out, "ENTRYDELETE: INPROGRESS\n"); if (glusterBlockDeleteEntry(glfs, info->volume, info->gbid)) { @@ -1216,6 +1216,11 @@ glusterBlockCleanUp(struct glfs *glfs, char *blockname, blockFreeMetaInfo(info); GB_FREE (errMsg); + /* ignore asyncret if force delete is used */ + if (forcedel) { + asyncret = 0; + } + return asyncret?asyncret:ret; } @@ -1275,7 +1280,7 @@ glusterBlockAuditRequest(struct glfs *glfs, "No Spare nodes to create (%s): rollingback creation of target" " on volume %s with given hosts %s", blk->block_name, blk->volume, blk->block_hosts); - glusterBlockCleanUp(glfs, blk->block_name, TRUE, (*reply)->obj); + glusterBlockCleanUp(glfs, blk->block_name, TRUE, FALSE, (*reply)->obj); needcleanup = FALSE; /* already clean attempted */ ret = -1; goto out; @@ -1284,7 +1289,7 @@ glusterBlockAuditRequest(struct glfs *glfs, "Not enough Spare nodes for (%s): rollingback creation of target" " on volume %s with given hosts %s", blk->block_name, blk->volume, blk->block_hosts); - glusterBlockCleanUp(glfs, blk->block_name, TRUE, (*reply)->obj); + glusterBlockCleanUp(glfs, blk->block_name, TRUE, FALSE, (*reply)->obj); needcleanup = FALSE; /* already clean attempted */ ret = -1; goto out; @@ -1315,7 +1320,7 @@ glusterBlockAuditRequest(struct glfs *glfs, out: if (needcleanup) { - glusterBlockCleanUp(glfs, blk->block_name, FALSE, (*reply)->obj); + glusterBlockCleanUp(glfs, blk->block_name, FALSE, FALSE, (*reply)->obj); } blockFreeMetaInfo(info); @@ -1948,7 +1953,7 @@ block_create_cli_1_svc(blockCreateCli *blk, struct svc_req *rqstp) " rollingback the create request for block %s on volume %s with hosts %s", errCode, blk->block_name, blk->volume, blk->block_hosts); - glusterBlockCleanUp(glfs, blk->block_name, TRUE, savereply->obj); + glusterBlockCleanUp(glfs, blk->block_name, TRUE, FALSE, savereply->obj); goto exist; } @@ -2355,23 +2360,25 @@ block_delete_cli_1_svc(blockDeleteCli *blk, struct svc_req *rqstp) goto out; } - if (GB_ALLOC(info) < 0) { - goto out; - } + if (!blk->force) { + if (GB_ALLOC(info) < 0) { + goto out; + } - ret = blockGetMetaInfo(glfs, blk->block_name, info, NULL); - if (ret) { - goto out; - } + ret = blockGetMetaInfo(glfs, blk->block_name, info, NULL); + if (ret) { + goto out; + } - ret = glusterBlockConnectAsync(blk->block_name, info, - glusterBlockDeleteFillArgs(info, true, NULL, NULL, NULL), - &errMsg); - if (ret) { - goto out; + ret = glusterBlockConnectAsync(blk->block_name, info, + glusterBlockDeleteFillArgs(info, true, NULL, NULL, NULL), + &errMsg); + if (ret) { + goto out; + } } - errCode = glusterBlockCleanUp(glfs, blk->block_name, TRUE, savereply); + errCode = glusterBlockCleanUp(glfs, blk->block_name, TRUE, TRUE, savereply); if (errCode) { LOG("mgmt", GB_LOG_WARNING, "glusterBlockCleanUp: return %d " "on block %s for volume %s", errCode, blk->block_name, blk->volume); diff --git a/rpc/rpcl/block.x b/rpc/rpcl/block.x index a47901a..66d1e32 100644 --- a/rpc/rpcl/block.x +++ b/rpc/rpcl/block.x @@ -47,6 +47,7 @@ struct blockCreateCli { struct blockDeleteCli { char block_name[255]; char volume[255]; + bool force; enum JsonResponseFormat json_resp; }; -- cgit