From 683b6ba3f17a9bbf876c66f5d4b7a9d573d8853f Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Kalever Date: Fri, 20 Jan 2017 12:13:37 +0530 Subject: gluster-block: listen on unix and inet from now We basically have 2 RPC connections, 1. Between gluster block CLI and local gluster-blockd This connection is basically UNIX/local netid ,listening on /var/run/gluster-blockd.socket file. The CLI always Send/Receive the commands to/from the local gluster-blockd via local rpc. 2. Between gluster-blockd's, i.e local (to cli) gluster-blockd and the gluster-blockd's running on remote(blockhost) This is the tcp connection. The rpc requests are listening on 24006 Also from now gluster-blockd is multi threaded (As of now 2 threads) Lets consider the Create Request to understand what each thread solves Thread1 (THE CLI THREAD) * Listening on local RPC * Generate the GBID (UUID) and create the entry with name GBID in the given volume with a requested size. * And Send the Configuration requests to remote hosts, waits for the replies (HINt: after this point Read Thread2 and come back) * Return to CLI. Thread 2 (THE SERVER THREAD) * Listens on 24006 * On Receiving an event, read the structure. * Executes the required "targetcli bla bla bla" command locally * Fills the command exitcode and the output in the RPC reply structure and send reply Signed-off-by: Prasanna Kumar Kalever --- gluster-block.c | 104 ++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 70 insertions(+), 34 deletions(-) (limited to 'gluster-block.c') diff --git a/gluster-block.c b/gluster-block.c index 9a2564e..e6dc0fc 100644 --- a/gluster-block.c +++ b/gluster-block.c @@ -12,6 +12,7 @@ # define _GNU_SOURCE /* See feature_test_macros(7) */ # include +# include # include # include @@ -53,21 +54,40 @@ typedef blockServerDef *blockServerDefPtr; static void -gluster_block_1(char *host, char *cmd, blockTrans **reply) +gluster_block_cli_1(blockCreateCli cobj, blockResponse **reply) { CLIENT *clnt; + int sockfd, len; + struct sockaddr_un saun; - clnt = clnt_create (host, GLUSTER_BLOCK, GLUSTER_BLOCK_VERS, "tcp"); + if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { + perror("client: socket"); + exit(1); + } + + saun.sun_family = AF_UNIX; + strcpy(saun.sun_path, ADDRESS); + + len = sizeof(saun.sun_family) + strlen(saun.sun_path); + + if (connect(sockfd, (struct sockaddr *) &saun, len) < 0) { + perror("client: connect"); + exit(1); + } + + clnt = clntunix_create ((struct sockaddr_un *) &saun, GLUSTER_BLOCK_CLI, GLUSTER_BLOCK_CLI_VERS, &sockfd, 0, 0); if (clnt == NULL) { - clnt_pcreateerror (host); + clnt_pcreateerror ("localhost"); exit (1); } - *reply = block_exec_1(&cmd, clnt); + *reply = block_create_cli_1(&cobj, clnt); if (*reply == NULL) { - clnt_perror (clnt, "call failed"); + clnt_perror (clnt, "call failed gluster-block"); } + printf("%s\n", (*reply)->out); + clnt_destroy (clnt); } @@ -249,16 +269,20 @@ glusterBlockCreate(int count, char **options, char *name) { int c; int ret = 0; - char *cmd = NULL; - char *exec = NULL; - char *iqn = NULL; - char *blkServers = NULL; - blockServerDefPtr list; - uuid_t out; - glusterBlockDefPtr blk; - blockTrans *reply; - size_t i; +// char *cmd = NULL; +// char *exec = NULL; +// char *iqn = NULL; +// char *blkServers = NULL; +// blockServerDefPtr list; +// uuid_t out; +// glusterBlockDefPtr blk; + blockResponse *reply; + static blockCreateCli cobj; +// size_t i; +/* + if (GB_ALLOC(&cobj) < 0) + return -1; if (GB_ALLOC(blk) < 0) return -1; @@ -266,6 +290,7 @@ glusterBlockCreate(int count, char **options, char *name) uuid_generate(out); uuid_unparse(out, blk->filename); +*/ if (!name) { ERROR("%s", "Insufficient arguments supplied for" @@ -274,6 +299,8 @@ glusterBlockCreate(int count, char **options, char *name) goto out; } + strcpy(cobj.block_name, name); + while (1) { static const struct option long_options[] = { {"volume", required_argument, 0, 'v'}, @@ -294,22 +321,23 @@ glusterBlockCreate(int count, char **options, char *name) switch (c) { case 'b': - blkServers = optarg; + //blkServers = optarg; + GB_STRDUP(cobj.block_hosts, optarg); break; case 'v': - GB_STRDUP(blk->volume, optarg); + strcpy(cobj.volume, optarg); ret++; break; case 'h': - GB_STRDUP(blk->host, optarg); + strcpy(cobj.volfileserver, optarg); ret++; break; case 's': - blk->size = glusterBlockCreateParseSize(optarg); - if (blk->size < 0) { + cobj.size = glusterBlockCreateParseSize(optarg); + if (cobj.size < 0) { ERROR("%s", "failed while parsing size"); ret = -1; goto out; @@ -326,13 +354,13 @@ glusterBlockCreate(int count, char **options, char *name) break; } } - +/* if (blkServers) { list = blockServerParse(blkServers); } else { list = blockServerParse("localhost"); } - +*/ /* Print any remaining command line arguments (not options). */ if (optind < count) { ERROR("%s", "non-option ARGV-elements: "); @@ -351,6 +379,13 @@ glusterBlockCreate(int count, char **options, char *name) goto out; } + gluster_block_cli_1(cobj, &reply); + + + + + +/* ret = glusterBlockCreateEntry(blk); if (ret) { ERROR("%s volume: %s host: %s", @@ -363,7 +398,6 @@ glusterBlockCreate(int count, char **options, char *name) blk->filename, blk->filename) < 0) goto out; - /* Created user-backed storage object LUN size 2147483648. */ for (i = 0; i < list->nhosts; i++) { MSG("[OnHost: %s]", list->hosts[i]); gluster_block_1(list->hosts[i], cmd, &reply); @@ -429,8 +463,10 @@ glusterBlockCreate(int count, char **options, char *name) GB_FREE(iqn); glusterBlockDefFree(blk); blockServerDefFree(list); +*/ - return ret; + out: + return 0; } @@ -527,12 +563,12 @@ getCfgstring(char* name, char *blkServer) char *cmd; char *exec; char *buf = NULL; - blockTrans *reply; + blockResponse *reply = NULL; asprintf(&cmd, "%s %s", TARGETCLI_GLFS, BACKEND_CFGSTR); asprintf(&exec, cmd, name); - gluster_block_1(blkServer, exec, &reply); + //gluster_block_1(blkServer, exec, &reply); if (!reply || reply->exit) { ERROR("%s on host: %s", FAILED_GATHERING_CFGSTR, blkServer); @@ -559,7 +595,7 @@ glusterBlockList(blockServerDefPtr blkServers) char *size; char *cfgstring = NULL; glusterBlockDefPtr blk = NULL; - blockTrans *reply; + blockResponse *reply = NULL; MSG("%s", "BlockName Volname Host Size Status"); @@ -567,7 +603,7 @@ glusterBlockList(blockServerDefPtr blkServers) for (i = 0; i < blkServers->nhosts; i++) { MSG("[OnHost: %s]", blkServers->hosts[i]); - gluster_block_1(blkServers->hosts[i], cmd, &reply); + //gluster_block_1(blkServers->hosts[i], cmd, &reply); if (!reply || reply->exit) { ERROR("%s on host: %s", FAILED_LIST_BACKEND, blkServers->hosts[i]); @@ -632,7 +668,7 @@ glusterBlockDelete(char* name, blockServerDefPtr blkServers) char *cfgstring = NULL; char *iqn = NULL; glusterBlockDefPtr blk = NULL; - blockTrans *reply; + blockResponse *reply = NULL; asprintf(&cmd, "%s %s %s", TARGETCLI_GLFS, DELETE, name); @@ -647,7 +683,7 @@ glusterBlockDelete(char* name, blockServerDefPtr blkServers) goto fail; } - gluster_block_1(blkServers->hosts[i], cmd, &reply); + //gluster_block_1(blkServers->hosts[i], cmd, &reply); if (!reply || reply->exit) { ERROR("%s on host: %s", FAILED_DELETING_BACKEND, blkServers->hosts[i]); @@ -669,7 +705,7 @@ glusterBlockDelete(char* name, blockServerDefPtr blkServers) asprintf(&iqn, "%s%s", IQN_PREFIX, blk->filename); asprintf(&exec, "%s %s %s", TARGETCLI_ISCSI, DELETE, iqn); - gluster_block_1(blkServers->hosts[i], exec, &reply); + //gluster_block_1(blkServers->hosts[i], exec, &reply); if (!reply || reply->exit) { ERROR("%s on host: %s", FAILED_DELETING_IQN, blkServers->hosts[i]); @@ -680,7 +716,7 @@ glusterBlockDelete(char* name, blockServerDefPtr blkServers) GB_FREE(exec); GB_FREE(iqn); - gluster_block_1(blkServers->hosts[i], TARGETCLI_SAVE, &reply); + //gluster_block_1(blkServers->hosts[i], TARGETCLI_SAVE, &reply); if (!reply || reply->exit) { ERROR("%s on host: %s", FAILED_SAVEING_CONFIG, blkServers->hosts[i]); @@ -691,7 +727,7 @@ glusterBlockDelete(char* name, blockServerDefPtr blkServers) putchar('\n'); } - ret = glusterBlockDeleteEntry(blk); + //ret = glusterBlockDeleteEntry(blk); if (ret) { ERROR("%s volume: %s host: %s", FAILED_DELETING_FILE, blk->volume, blk->host); @@ -713,13 +749,13 @@ glusterBlockInfo(char* name, blockServerDefPtr blkServers) size_t i; int ret = 0; char *cmd; - blockTrans *reply; + blockResponse *reply = NULL; asprintf(&cmd, "%s/%s %s", TARGETCLI_GLFS, name, INFO); for (i = 0; i < blkServers->nhosts; i++) { MSG("[OnHost: %s]", blkServers->hosts[i]); - gluster_block_1(blkServers->hosts[i], cmd, &reply); + //gluster_block_1(blkServers->hosts[i], cmd, &reply); if (!reply || reply->exit) { ret = -1; ERROR("%s on host: %s", -- cgit