From 8eaecd2b99e686dbf6acd401b55f04220f3149d0 Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Kalever Date: Tue, 14 Feb 2017 22:05:30 +0530 Subject: gluster-block: add portal creation The portal that target listens on by default will be 0.0.0.0; With this patch we will be changing that to hostname of local machine. Signed-off-by: Prasanna Kumar Kalever --- cli/gluster-block.c | 4 ++-- rpc/block_svc_routines.c | 23 ++++++++++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/cli/gluster-block.c b/cli/gluster-block.c index 75bf0d0..129467d 100644 --- a/cli/gluster-block.c +++ b/cli/gluster-block.c @@ -133,8 +133,8 @@ glusterBlockHelp(void) " create Create the gluster block\n" " volserver [gluster-node] node addr from gluster pool(default: localhost)\n" " size block storage size in KiB|MiB|GiB|TiB..\n" - " mpath multi path requirement for high availablity\n" - " servers block servers, clubbed with any option\n" + " mpath multipath requirement for high availability\n" + " servers block servers, where targets are exported\n" "\n" " list List available gluster blocks\n" "\n" diff --git a/rpc/block_svc_routines.c b/rpc/block_svc_routines.c index cb9a6e8..f77fbb3 100644 --- a/rpc/block_svc_routines.c +++ b/rpc/block_svc_routines.c @@ -25,6 +25,7 @@ # define GLFS_PATH "/backstores/user:glfs" # define TARGETCLI_GLFS "targetcli "GLFS_PATH # define TARGETCLI_ISCSI "targetcli /iscsi" +# define TARGETCLI_GLOBALS "targetcli set global auto_add_default_portal=false" # define TARGETCLI_SAVE "targetcli / saveconfig" # define ATTRIBUTES "generate_node_acls=1 demo_mode_write_protect=0" # define IQN_PREFIX "iqn.2016-12.org.gluster-block:" @@ -695,9 +696,11 @@ blockResponse * block_create_1_svc(blockCreate *blk, struct svc_req *rqstp) { FILE *fp; - char *backstore = NULL;; + char hostname[255]; + char *backstore = NULL; char *iqn = NULL; char *lun = NULL; + char *portal = NULL; char *attr = NULL; char *exec = NULL; blockResponse *reply = NULL; @@ -707,6 +710,12 @@ block_create_1_svc(blockCreate *blk, struct svc_req *rqstp) goto out; } + if (gethostname(hostname, 255)) { + LOG("mgmt", GB_LOG_ERROR, "gethostname failed (%s)", strerror(errno)); + reply->exit = -1; + goto out; + } + if (asprintf(&backstore, "%s %s %s %zu %s@%s%s/%s %s", TARGETCLI_GLFS, CREATE, blk->block_name, blk->size, blk->volume, blk->volfileserver, GB_STOREDIR, blk->gbid, blk->gbid) == -1) { @@ -728,6 +737,13 @@ block_create_1_svc(blockCreate *blk, struct svc_req *rqstp) goto out; } + if (asprintf(&portal, "%s/%s%s/tpg1/portals create %s", + TARGETCLI_ISCSI, IQN_PREFIX, blk->gbid, + hostname) == -1) { + reply->exit = -1; + goto out; + } + if (asprintf(&attr, "%s/%s%s/tpg1 set attribute %s", TARGETCLI_ISCSI, IQN_PREFIX, blk->gbid, ATTRIBUTES) == -1) { @@ -736,8 +752,8 @@ block_create_1_svc(blockCreate *blk, struct svc_req *rqstp) } - if (asprintf(&exec, "%s && %s && %s && %s && %s", backstore, iqn, - lun, attr, TARGETCLI_SAVE) == -1) { + if (asprintf(&exec, "%s && %s && %s && %s && %s && %s && %s", TARGETCLI_GLOBALS, + backstore, iqn, lun, portal, attr, TARGETCLI_SAVE) == -1) { reply->exit = -1; goto out; } @@ -761,6 +777,7 @@ block_create_1_svc(blockCreate *blk, struct svc_req *rqstp) out: GB_FREE(exec); GB_FREE(attr); + GB_FREE(portal); GB_FREE(lun); GB_FREE(iqn); GB_FREE(backstore); -- cgit