Skip to content

Commit

Permalink
create: split the creation into 2 phases
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]>
  • Loading branch information
lxbsz committed Jul 2, 2019
1 parent 419d752 commit 1ba5278
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions rpc/block_svc_routines.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;

typedef enum operations {
CREATE_SRV = 1,
CREATE_SO_SRV,
CREATE_TG_SRV,
DELETE_SRV,
MODIFY_SRV,
MODIFY_TPGC_SRV,
Expand Down Expand Up @@ -4056,13 +4058,17 @@ blockValidateCommandOutput(const char *out, int opt, void *data)


switch (opt) {
case CREATE_SRV:
case CREATE_SO_SRV:
/* backend create validation */
GB_OUT_VALIDATE_OR_GOTO(out, out, "backend creation failed for: %s", cblk,
cblk->volume,
"Created user-backed storage object %s size %zu.",
cblk->block_name, cblk->size);

ret = 0;
break;

case CREATE_TG_SRV:
/* target iqn create validation */
GB_OUT_VALIDATE_OR_GOTO(out, out, "target iqn creation failed for: %s",
cblk, cblk->volume, "Created target %s%s.",
Expand Down Expand Up @@ -4306,6 +4312,11 @@ block_create_common(blockCreate *blk, char *rbsize, char *volServer, char *prio_
}
reply->exit = -1;

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

if (prio_path && prio_path[0]) {
prioCap = true;
}
Expand All @@ -4317,6 +4328,17 @@ block_create_common(blockCreate *blk, char *rbsize, char *volServer, char *prio_
goto out;
}

if (GB_ASPRINTF(&exec, "targetcli <<EOF\n%s\nEOF", backstore) == -1) {
goto out;
}

GB_CMD_EXEC_AND_VALIDATE(exec, reply, blk, blk->volume, CREATE_SO_SRV);
if (reply->exit) {
snprintf(reply->out, 8192, "configure StorageObject failed");
goto out;
}
GB_FREE(exec);

if (GB_ASPRINTF(&backstore_attr,
"%s/%s set attribute cmd_time_out=%d",
GB_TGCLI_GLFS_PATH, blk->block_name, GB_CMD_TIME_OUT) == -1) {
Expand Down Expand Up @@ -4478,9 +4500,9 @@ block_create_common(blockCreate *blk, char *rbsize, char *volServer, char *prio_
goto out;
}

GB_CMD_EXEC_AND_VALIDATE(exec, reply, blk, blk->volume, CREATE_SRV);
GB_CMD_EXEC_AND_VALIDATE(exec, reply, blk, blk->volume, CREATE_TG_SRV);
if (reply->exit) {
snprintf(reply->out, 8192, "configure failed");
snprintf(reply->out, 8192, "configure Target failed");
}

out:
Expand Down

0 comments on commit 1ba5278

Please sign in to comment.