Skip to content

Commit

Permalink
delete: support [unlink-storage <yes|no>] option
Browse files Browse the repository at this point in the history
$ gluster-block help
gluster-block (0.3)
usage:
  gluster-block <command> <volname[/blockname]> [<args>] [--json*]

commands:
[...]

  delete  <volname/blockname> [unlink-storage <yes|no>] [force]
        delete block device.
[...]
supported JSON formats:
  --json|--json-plain|--json-spaced|--json-pretty

Change-Id: I64bc99a8519be6f90a7e8bc5558b0d7518661995
Fixes: #19
Signed-off-by: Prasanna Kumar Kalever <[email protected]>
  • Loading branch information
Prasanna Kumar Kalever committed Feb 8, 2018
1 parent 450f7e8 commit 7008073
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 23 deletions.
57 changes: 40 additions & 17 deletions cli/gluster-block.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
"[prealloc <full|no>] [storage <filename>] " \
"<HOST1[,HOST2,...]> <size> [--json*]"
# define GB_DELETE_HELP_STR "gluster-block delete <volname/blockname> " \
"[force] [--json*]"
"[unlink-storage <yes|no>] [force] [--json*]"
# define GB_MODIFY_HELP_STR "gluster-block modify <volname/blockname> " \
"<auth enable|disable> [--json*]"
"<auth enable|disable> [--json*]"
# define GB_REPLACE_HELP_STR "gluster-block replace <volname/blockname> " \
"<old-node> <new-node> [force] [--json*]"
"<old-node> <new-node> [force] [--json*]"
# define GB_INFO_HELP_STR "gluster-block info <volname/blockname> [--json*]"
# define GB_LIST_HELP_STR "gluster-block list <volname> [--json*]"

Expand Down Expand Up @@ -212,7 +212,7 @@ glusterBlockHelp(void)
" info <volname/blockname>\n"
" details about block device.\n"
"\n"
" delete <volname/blockname> [force]\n"
" delete <volname/blockname> [unlink-storage <yes|no>] [force]\n"
" delete block device.\n"
"\n"
" modify <volname/blockname> <auth enable|disable>\n"
Expand Down Expand Up @@ -505,36 +505,59 @@ glusterBlockList(int argcount, char **options, int json)
static int
glusterBlockDelete(int argcount, char **options, int json)
{
blockDeleteCli cobj = {0};
blockDeleteCli dobj = {0};
size_t optind = 2;
int ret = -1;


if (argcount < 3 || argcount > 4) {
if (argcount < 3 || argcount > 6) {
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;
dobj.json_resp = json;

/* default: delete storage */
dobj.unlink = 1;

if (glusterBlockParseVolumeBlock (options[optind++], dobj.volume,
dobj.block_name, sizeof(dobj.volume),
sizeof(dobj.block_name), GB_DELETE_HELP_STR,
"delete")) {
goto out;
}

if ((argcount - optind) && !strcmp(options[optind], "unlink-storage")) {
optind++;
ret = convertStringToTrillianParse(options[optind++]);
if(ret >= 0) {
dobj.unlink = ret;
} else {
cobj.force = true;
MSG("%s\n", "'unlink-storage' option is incorrect");
MSG("%s\n", GB_DELETE_HELP_STR);
LOG("cli", GB_LOG_ERROR, "Delete failed while parsing argument "
"to unlink-storage for <%s/%s>",
dobj.volume, dobj.block_name);
goto out;
}
}

cobj.json_resp = json;
if ((argcount - optind) && !strcmp(options[optind], "force")) {
optind++;
dobj.force = true;
}

if (glusterBlockParseVolumeBlock (options[2], cobj.volume, cobj.block_name,
sizeof(cobj.volume), sizeof(cobj.block_name),
GB_DELETE_HELP_STR, "delete")) {
if (argcount - optind) {
MSG("Unknown option: '%s'\n%s\n", options[optind], GB_DELETE_HELP_STR);
LOG("cli", GB_LOG_ERROR, "Delete failed parsing argument unknow option '%s'"
" for <%s/%s>", options[optind], dobj.volume, dobj.block_name);
goto out;
}

ret = glusterBlockCliRPC_1(&cobj, DELETE_CLI);
ret = glusterBlockCliRPC_1(&dobj, DELETE_CLI);
if (ret) {
LOG("cli", GB_LOG_ERROR, "failed deleting block %s on volume %s",
cobj.block_name, cobj.volume);
dobj.block_name, dobj.volume);
}

out:
Expand Down
12 changes: 6 additions & 6 deletions rpc/block_svc_routines.c
Original file line number Diff line number Diff line change
Expand Up @@ -2270,7 +2270,7 @@ block_replace_cli_1_svc_st(blockReplaceCli *blk, struct svc_req *rqstp)

static int
glusterBlockCleanUp(struct glfs *glfs, char *blockname,
bool deleteall, bool forcedel, blockRemoteDeleteResp *drobj)
bool deleteall, bool forcedel, bool unlink, blockRemoteDeleteResp *drobj)
{
int ret = -1;
size_t i;
Expand Down Expand Up @@ -2328,7 +2328,7 @@ glusterBlockCleanUp(struct glfs *glfs, char *blockname,
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)) {
if (unlink && glusterBlockDeleteEntry(glfs, info->volume, info->gbid)) {
GB_METAUPDATE_OR_GOTO(lock, glfs, blockname, info->volume,
ret, errMsg, out, "ENTRYDELETE: FAIL\n");
LOG("mgmt", GB_LOG_ERROR, "%s %s for block %s", FAILED_DELETING_FILE,
Expand Down Expand Up @@ -2415,7 +2415,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, FALSE, (*reply)->obj);
glusterBlockCleanUp(glfs, blk->block_name, TRUE, FALSE, TRUE, (*reply)->obj);
needcleanup = FALSE; /* already clean attempted */
ret = -1;
goto out;
Expand All @@ -2424,7 +2424,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, FALSE, (*reply)->obj);
glusterBlockCleanUp(glfs, blk->block_name, TRUE, FALSE, TRUE, (*reply)->obj);
needcleanup = FALSE; /* already clean attempted */
ret = -1;
goto out;
Expand Down Expand Up @@ -2455,7 +2455,7 @@ glusterBlockAuditRequest(struct glfs *glfs,

out:
if (needcleanup) {
glusterBlockCleanUp(glfs, blk->block_name, FALSE, FALSE, (*reply)->obj);
glusterBlockCleanUp(glfs, blk->block_name, FALSE, FALSE, TRUE, (*reply)->obj);
}

blockFreeMetaInfo(info);
Expand Down Expand Up @@ -3616,7 +3616,7 @@ block_delete_cli_1_svc_st(blockDeleteCli *blk, struct svc_req *rqstp)
goto out;
}

errCode = glusterBlockCleanUp(glfs, blk->block_name, TRUE, TRUE, savereply);
errCode = glusterBlockCleanUp(glfs, blk->block_name, TRUE, TRUE, blk->unlink, savereply);
if (errCode) {
LOG("mgmt", GB_LOG_WARNING, "glusterBlockCleanUp: return %d "
"on block %s for volume %s", errCode, blk->block_name, blk->volume);
Expand Down
1 change: 1 addition & 0 deletions rpc/rpcl/block.x
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ struct blockCreateCli {
struct blockDeleteCli {
char block_name[255];
char volume[255];
bool unlink;
bool force;
enum JsonResponseFormat json_resp;
};
Expand Down

0 comments on commit 7008073

Please sign in to comment.