summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPrasanna Kumar Kalever <prasanna.kalever@redhat.com>2017-01-23 14:36:28 +0530
committerPrasanna Kumar Kalever <prasanna.kalever@redhat.com>2017-01-30 19:31:50 +0530
commit562f4d1e1a0f8e8419b9ed56d3bbd06d296a984a (patch)
treec3bde505df2b6b7d6ab03351ca4fa2e6c9e599a9
parent05ab127cf7cbc09b58958f1c1923e674c697944f (diff)
gluster-block: support multiple block-host
Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
-rw-r--r--gluster-block.c8
-rw-r--r--gluster-blockd.c142
2 files changed, 131 insertions, 19 deletions
diff --git a/gluster-block.c b/gluster-block.c
index 23e98f9..632fcef 100644
--- a/gluster-block.c
+++ b/gluster-block.c
@@ -819,7 +819,7 @@ glusterBlockParseArgs(int count, char **options)
int optFlag = 0;
char *block = NULL;
char *blkServers = NULL;
- blockServerDefPtr list = NULL;
+ //blockServerDefPtr list = NULL;
char *liststr;
while (1) {
@@ -886,10 +886,10 @@ glusterBlockParseArgs(int count, char **options)
opt:
if (blkServers) {
- list = blockServerParse(blkServers);
+ //list = blockServerParse(blkServers);
liststr = blkServers;
} else {
- list = blockServerParse("localhost");
+ //list = blockServerParse("localhost");
liststr = "localhost";
}
@@ -920,7 +920,7 @@ glusterBlockParseArgs(int count, char **options)
MSG("Hint: %s --help", options[0]);
}
- blockServerDefFree(list);
+ //blockServerDefFree(list);
return ret;
}
diff --git a/gluster-blockd.c b/gluster-blockd.c
index 48786ca..238f249 100644
--- a/gluster-blockd.c
+++ b/gluster-blockd.c
@@ -39,6 +39,12 @@ typedef enum opterations {
EXEC_SRV = 5
} opterations;
+typedef struct blockServerDef {
+ size_t nhosts;
+ char **hosts;
+} blockServerDef;
+typedef blockServerDef *blockServerDefPtr;
+
static void
gluster_block_1(char *host, void *cobj, opterations opt, blockResponse **reply)
{
@@ -99,6 +105,58 @@ gluster_block_1(char *host, void *cobj, opterations opt, blockResponse **reply)
clnt_destroy (clnt);
}
+void
+blockServerDefFree(blockServerDefPtr blkServers)
+{
+ size_t i;
+
+ if (!blkServers)
+ return;
+
+ for (i = 0; i < blkServers->nhosts; i++)
+ GB_FREE(blkServers->hosts[i]);
+ GB_FREE(blkServers->hosts);
+ GB_FREE(blkServers);
+}
+
+static blockServerDefPtr
+blockServerParse(char *blkServers)
+{
+ blockServerDefPtr list;
+ char *tmp = blkServers;
+ size_t i = 0;
+
+ if (!blkServers)
+ blkServers = "localhost";
+
+ if (GB_ALLOC(list) < 0)
+ return NULL;
+
+ /* count number of servers */
+ while (*tmp) {
+ if (*tmp == ',')
+ list->nhosts++;
+ tmp++;
+ }
+ list->nhosts++;
+ tmp = blkServers; /* reset addr */
+
+
+ if (GB_ALLOC_N(list->hosts, list->nhosts) < 0)
+ goto fail;
+
+ for (i = 0; tmp != NULL; i++) {
+ if (GB_STRDUP(list->hosts[i], strsep(&tmp, MSERVER_DELIMITER)) < 0)
+ goto fail;
+ }
+
+ return list;
+
+fail:
+ blockServerDefFree(list);
+ return NULL;
+}
+
static char *
getCfgstring(char* name, char *blkServer)
{
@@ -129,9 +187,12 @@ blockResponse *
block_create_cli_1_svc(blockCreateCli *blk, struct svc_req *rqstp)
{
int ret;
+ size_t i = 0;
+ char savereply[8096] = {0,};
uuid_t out;
static blockCreate *cobj;
- static blockResponse *reply;
+ static blockResponse *reply = NULL;
+ blockServerDefPtr list = NULL;
char *gbid = CALLOC(UUID_BUF_SIZE);
uuid_generate(out);
@@ -153,10 +214,20 @@ block_create_cli_1_svc(blockCreateCli *blk, struct svc_req *rqstp)
cobj->size = blk->size;
strcpy(cobj->gbid, gbid);
- //for
+ list = blockServerParse(blk->block_hosts);
- gluster_block_1(blk->block_hosts, cobj, CREATE_SRV, &reply);
+ for (i = 0; i < list->nhosts; i++) {
+ gluster_block_1(list->hosts[i], cobj, CREATE_SRV, &reply);
+ if (!reply || reply->exit) {
+ ERROR("%s on host: %s",
+ FAILED_GATHERING_INFO, list->hosts[i]);
+ goto out;
+ }
+ /* TODO: aggrigate the result */
+ strcat(savereply, reply->out);
+ }
+ strcpy(reply->out, savereply);
out:
return reply;
}
@@ -363,10 +434,13 @@ block_create_1_svc(blockCreate *blk, struct svc_req *rqstp)
blockResponse *
block_delete_cli_1_svc(blockDeleteCli *blk, struct svc_req *rqstp)
{
+ size_t i = 0;
+ char savereply[8096] = {0,};
+ blockServerDefPtr list = NULL;
char *cfgstring;
static blockCreate *blkcfg;
static blockDelete *cobj;
- static blockResponse *reply;
+ static blockResponse *reply = NULL;
if(GB_ALLOC(cobj) < 0)
goto out;
@@ -389,7 +463,21 @@ block_delete_cli_1_svc(blockDeleteCli *blk, struct svc_req *rqstp)
}
strcpy(cobj->gbid, blkcfg->gbid);
- gluster_block_1(blk->block_hosts, cobj, DELETE_SRV, &reply);
+
+
+ list = blockServerParse(blk->block_hosts);
+
+ for (i = 0; i < list->nhosts; i++) {
+ gluster_block_1(list->hosts[i], cobj, DELETE_SRV, &reply);
+ if (!reply || reply->exit) {
+ ERROR("%s on host: %s",
+ FAILED_GATHERING_INFO, list->hosts[i]);
+ goto out;
+ }
+ /* TODO: aggrigate the result */
+ strcat(savereply, reply->out);
+ }
+ strcpy(reply->out, savereply);
if (glusterBlockDeleteEntry(blkcfg)) {
ERROR("%s volume: %s host: %s",
@@ -470,16 +558,28 @@ blockResponse *
block_list_cli_1_svc(blockListCli *blk, struct svc_req *rqstp)
{
char *cmd;
- blockResponse *reply;
+ blockResponse *reply = NULL;
+ size_t i = 0;
+ char savereply[8096] = {0,};
+ blockServerDefPtr list = NULL;
asprintf(&cmd, "%s %s", TARGETCLI_GLFS, LUNS_LIST);
- gluster_block_1(blk->block_hosts, cmd, EXEC_SRV, &reply);
- if (!reply || reply->exit) {
- ERROR("%s on host: %s",
- FAILED_GATHERING_CFGSTR, blk->block_hosts);
+ list = blockServerParse(blk->block_hosts);
+
+ for (i = 0; i < list->nhosts; i++) {
+ gluster_block_1(list->hosts[i], cmd, EXEC_SRV, &reply);
+ if (!reply || reply->exit) {
+ ERROR("%s on host: %s",
+ FAILED_GATHERING_INFO, list->hosts[i]);
+ goto out;
+ }
+ /* TODO: aggrigate the result */
+ strcat(savereply, reply->out);
}
+ strcpy(reply->out, savereply);
+out:
return reply;
}
@@ -487,16 +587,28 @@ blockResponse *
block_info_cli_1_svc(blockInfoCli *blk, struct svc_req *rqstp)
{
char *cmd;
- blockResponse *reply;
+ blockResponse *reply = NULL;
+ size_t i = 0;
+ char savereply[8096] = {0,};
+ blockServerDefPtr list = NULL;
asprintf(&cmd, "%s/%s %s", TARGETCLI_GLFS, blk->block_name, INFO);
//for
- gluster_block_1(blk->block_hosts, cmd, EXEC_SRV, &reply);
- if (!reply || reply->exit) {
- ERROR("%s on host: %s",
- FAILED_GATHERING_CFGSTR, blk->block_hosts);
+ list = blockServerParse(blk->block_hosts);
+
+ for (i = 0; i < list->nhosts; i++) {
+ gluster_block_1(list->hosts[i], cmd, EXEC_SRV, &reply);
+ if (!reply || reply->exit) {
+ ERROR("%s on host: %s",
+ FAILED_GATHERING_INFO, list->hosts[i]);
+ goto out;
+ }
+ /* TODO: aggrigate the result */
+ strcat(savereply, reply->out);
}
+ strcpy(reply->out, savereply);
+out:
return reply;
}