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 BV with the same NAME, the second time it will fail
due to the targetcli cache db only allows one [user/$NAME] exist,
but will leave the iqn not deleted correctly.

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

2, For the case above we will also find that after the second
creation failing the /etc/target/saveconfig.json will be one
StorageObject with the second Target in pairs and exist.

In theory, there should be one StorageObject with 2 Targets.

This patch will split the creation into 2 phases: CREATE_SO_SRV
and CREATE_TG_SRV, since in the targetcli it will build the cache
by using the key = [usr/$NAME], so only the StorageObject is
successfully created the second phase will make sense.

Signed-off-by: Xiubo Li <[email protected]>
Reviewed-by: Prasanna Kumar Kalever <[email protected]>
  • Loading branch information
lxbsz committed Jul 15, 2019
1 parent e499f3d commit 8c7c6f8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
28 changes: 21 additions & 7 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 @@ -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 '%s' is already exist", blk->block_name);
tmp = NULL;
goto out;
}
GB_FREE(exec);
GB_FREE(save);
tmp = NULL;

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 8c7c6f8

Please sign in to comment.