Skip to content

Commit

Permalink
create: check the StorageObject's existence before creating
Browse files Browse the repository at this point in the history
This will fix the following issues:

1, When the StorageObject creation failed the iqn will still be
created and won't be deleted in case of:

When creating BVs with the same NAME, the second time it will
fail duing to the targetcli cache db only allows one [user/$NAME]
exist, and then fails it leaving the IQN not deleted correctly.

That means there will be two different IQNs both mapped to the
same StorageObject.

2, For the case above we will also find that after the second
creation failing in the /etc/target/saveconfig.json there will be
one StorageObject with the two Targets.

In theory, there should be one StorageObject with only 1 Target.

This patch will check all the StorageObjects in saveconfig.json
before creating, if there already has one StorageObject with the
same NAME requested, it will fail directly.

Signed-off-by: Xiubo Li <[email protected]>
Reviewed-by: Prasanna Kumar Kalever <[email protected]>
  • Loading branch information
lxbsz authored and pkalever committed Jul 17, 2019
1 parent 873ac1e commit 34b65ea
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
32 changes: 23 additions & 9 deletions rpc/block_svc_routines.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"'%s' ls | grep -e tpg -e '%s' | grep -B1 '%s' | grep -o 'tpg\\w'"
# define GB_CHECK_PORTAL "targetcli /iscsi/" GB_TGCLI_IQN_PREFIX \
"'%s' ls | grep '%s' > " DEVNULLPATH
# define GB_SAVECONFIG_SO_CHECK "grep -m 1 '\"config\":.*/block-store/%s\",' " GB_SAVECONFIG " > " DEVNULLPATH
# define GB_SAVECFG_GBID_CHECK "grep -m 1 '\"config\":.*/block-store/%s\",' " GB_SAVECONFIG " > " DEVNULLPATH
# define GB_SAVECFG_NAME_CHECK "grep -csh '\"name\": \"%s\",' " GB_SAVECONFIG " " GB_SAVECONFIG_TEMP

# define GB_ALUA_AO_TPG_NAME "glfs_tg_pt_gp_ao"
# define GB_ALUA_ANO_TPG_NAME "glfs_tg_pt_gp_ano"
Expand Down Expand Up @@ -294,7 +295,7 @@ blockCheckBlockLoadedStatus(char *block_name, char *gbid, blockResponse *reply)
}
GB_FREE(exec);

if (GB_ASPRINTF(&exec, GB_SAVECONFIG_SO_CHECK, gbid) == -1) {
if (GB_ASPRINTF(&exec, GB_SAVECFG_GBID_CHECK, gbid) == -1) {
ret = -1;
goto out;
}
Expand Down Expand Up @@ -3138,7 +3139,7 @@ glusterBlockAuditRequest(struct glfs *glfs,
ret = glusterBlockAuditRequest(glfs, blk, cobj, list, reply);
if (ret) {
LOG("mgmt", GB_LOG_ERROR, "glusterBlockAuditRequest: return %d"
"volume: %s hosts: %s blockname %s", ret,
" volume: %s hosts: %s blockname %s", ret,
blk->volume, blk->block_hosts, blk->block_name);
}

Expand Down Expand Up @@ -4078,7 +4079,7 @@ block_create_cli_1_svc_st(blockCreateCli *blk, struct svc_req *rqstp)
errCode = glusterBlockAuditRequest(glfs, blk, &cobj, list, &savereply);
if (errCode) {
LOG("mgmt", GB_LOG_ERROR, "glusterBlockAuditRequest: return %d"
"volume: %s hosts: %s blockname %s", errCode,
" volume: %s hosts: %s blockname %s", errCode,
blk->volume, blk->block_hosts, blk->block_name);
} else if (!resultCaps[GB_CREATE_LOAD_BALANCE_CAP] && cobj.prio_path[0]) {
blockIncPrioAttr(glfs, blk->volume, cobj.prio_path);
Expand Down Expand Up @@ -4375,6 +4376,24 @@ block_create_common(blockCreate *blk, char *control, char *volServer, char *prio
}
reply->exit = -1;

if (GB_ALLOC_N(reply->out, 8192) < 0) {
goto out;
}

if (GB_ASPRINTF(&exec, GB_SAVECFG_NAME_CHECK, blk->block_name) == -1) {
goto out;
}

save = gbRunnerGetOutput(exec);
if (save && atol(save)) {
snprintf(reply->out, 8192,
"block with name '%s' already exist (Hint: may be hosted on a different block-hosting volume)",
blk->block_name);
goto out;
}
GB_FREE(exec);
GB_FREE(save);

if (prio_path && prio_path[0]) {
prioCap = true;
}
Expand Down Expand Up @@ -4573,11 +4592,6 @@ block_create_common(blockCreate *blk, char *control, char *volServer, char *prio
}
GB_FREE(tmp);

if (GB_ALLOC_N(reply->out, 8192) < 0) {
GB_FREE(reply);
goto out;
}

GB_CMD_EXEC_AND_VALIDATE(exec, reply, blk, blk->volume, CREATE_SRV);
if (reply->exit) {
snprintf(reply->out, 8192, "configure failed");
Expand Down
1 change: 1 addition & 0 deletions utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

# define DEVNULLPATH "/dev/null"
# define GB_SAVECONFIG "/etc/target/saveconfig.json"
# define GB_SAVECONFIG_TEMP "/etc/target/saveconfig.json.temp"

# define GB_METADIR "/block-meta"
# define GB_STOREDIR "/block-store"
Expand Down

0 comments on commit 34b65ea

Please sign in to comment.