From aa861a01de2f89aec61dddeba13b929222143a52 Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Kalever Date: Fri, 27 Jan 2017 13:56:01 +0530 Subject: gluster-block: clean block_exec procedure This was a hack to implement list and info commands, now that both list and info reads the metadata from the volume, we don't need block_exec anymore. Signed-off-by: Prasanna Kumar Kalever --- glfs-operations.c | 6 +-- glfs-operations.h | 2 +- gluster-blockd.c | 154 +++--------------------------------------------------- rpc/block.h | 6 --- rpc/block.x | 1 - rpc/block_clnt.c | 15 ------ rpc/block_svc.c | 7 --- 7 files changed, 11 insertions(+), 180 deletions(-) diff --git a/glfs-operations.c b/glfs-operations.c index 5b99045..d567605 100644 --- a/glfs-operations.c +++ b/glfs-operations.c @@ -91,18 +91,18 @@ glusterBlockCreateEntry(blockCreateCli *blk, char *gbid) int -glusterBlockDeleteEntry(blockCreate *blk) +glusterBlockDeleteEntry(char *volume, char *gbid) { struct glfs *glfs; int ret = -1; - glfs = glusterBlockVolumeInit(blk->volume, blk->volfileserver); + glfs = glusterBlockVolumeInit(volume, "localhost"); if (!glfs) { ERROR("%s", "glusterBlockVolumeInit: failed"); goto out; } - ret = glfs_unlink(glfs, blk->gbid); + ret = glfs_unlink(glfs, gbid); if (ret) { ERROR("%s", "glfs_unlink: failed"); goto out; diff --git a/glfs-operations.h b/glfs-operations.h index 8fe1bd6..c2bf076 100644 --- a/glfs-operations.h +++ b/glfs-operations.h @@ -63,7 +63,7 @@ int glusterBlockCreateEntry(blockCreateCli *blk, char *gbid); int -glusterBlockDeleteEntry(blockCreate *blk); +glusterBlockDeleteEntry(char *volume, char *gbid); struct glfs_fd * glusterBlockCreateMetaLockFile(struct glfs *glfs); diff --git a/gluster-blockd.c b/gluster-blockd.c index bedd8db..27602fa 100644 --- a/gluster-blockd.c +++ b/gluster-blockd.c @@ -48,10 +48,7 @@ typedef blockServerDef *blockServerDefPtr; typedef enum opterations { CREATE_SRV = 1, - LIST_SRV = 2, - INFO_SRV = 3, - DELETE_SRV = 4, - EXEC_SRV = 5 + DELETE_SRV = 2, } opterations; @@ -105,15 +102,6 @@ gluster_block_1(char *host, void *cobj, opterations opt, char **out) clnt_perror (clnt, "call failed gluster-block"); } break; - case INFO_SRV: - case LIST_SRV: - break; - case EXEC_SRV: - reply = block_exec_1((char **)&cobj, clnt); - if (reply == NULL) { - clnt_perror (clnt, "call failed gluster-block"); - } - break; } if (GB_STRDUP(*out, reply->out) < 0) { @@ -186,30 +174,6 @@ fail: } -static char * -getCfgstring(char* name, char *blkServer) -{ - char *cmd; - char *exec; - char *out = NULL; - int ret = -1; - - asprintf(&cmd, "%s %s", TARGETCLI_GLFS, BACKEND_CFGSTR); - asprintf(&exec, cmd, name); - - ret = gluster_block_1(blkServer, exec, EXEC_SRV, &out); - if (ret) { - ERROR("%s on host: %s", - FAILED_GATHERING_CFGSTR, blkServer); - } - - GB_FREE(cmd); - GB_FREE(exec); - - return out; -} - - blockResponse * block_create_cli_1_svc(blockCreateCli *blk, struct svc_req *rqstp) { @@ -325,67 +289,6 @@ out: } -static int -glusterBlockParseCfgStringToDef(char* cfgstring, - blockCreate *blk) -{ - int ret = 0; - char *p, *sep; - - /* part before '@' is the volume name */ - p = cfgstring; - sep = strchr(p, '@'); - if (!sep) { - ret = -1; - goto fail; - } - - *sep = '\0'; - strcpy(blk->volume, p); - - /* part between '@' and '/' is the server name */ - p = sep + 1; - sep = strchr(p, '/'); - if (!sep) { - ret = -1; - goto fail; - } - - *sep = '\0'; - strcpy(blk->volfileserver, p); - - /* part between '/' and '(' is the filename */ - p = sep + 1; - sep = strchr(p, '('); - if (!sep) { - ret = -1; - goto fail; - } - - *(sep - 1) = '\0'; /* discard extra space at end of filename */ - strcpy(blk->gbid, p); - - /* part between '(' and ')' is the size */ - p = sep + 1; - sep = strchr(p, ')'); - if (!sep) { - ret = -1; - goto fail; - } - - *sep = '\0'; - blk->size = glusterBlockCreateParseSize(p); - if (blk->size < 0) { - ERROR("%s", "failed while parsing size"); - ret = -1; - goto fail; - } - - fail: - return ret; -} - - blockResponse * block_create_1_svc(blockCreate *blk, struct svc_req *rqstp) { @@ -453,8 +356,6 @@ block_delete_cli_1_svc(blockDeleteCli *blk, struct svc_req *rqstp) char *savereply = NULL; char *tmp = NULL; blockServerDefPtr list = NULL; - char *cfgstring; - static blockCreate *blkcfg; static blockDelete *cobj; static blockResponse *reply = NULL; struct glfs *glfs = NULL; @@ -462,6 +363,7 @@ block_delete_cli_1_svc(blockDeleteCli *blk, struct svc_req *rqstp) struct glfs_fd *tgfd; struct flock lock = {0, }; char *write; + MetaInfo *info = NULL; glfs = glusterBlockVolumeInit(blk->volume, "localhost"); if (!glfs) { @@ -490,28 +392,17 @@ block_delete_cli_1_svc(blockDeleteCli *blk, struct svc_req *rqstp) } glfs_lseek (tgfd, 0, SEEK_END); - //for - cfgstring = getCfgstring(blk->block_name, blk->block_hosts); - if (!cfgstring) { - ERROR("%s", "failed while gathering CfgString"); - goto out; - } - - if (GB_ALLOC(blkcfg) < 0) + if (GB_ALLOC(info) < 0) goto out; - if(glusterBlockParseCfgStringToDef(cfgstring, blkcfg)) { - ERROR("%s", "failed while parsing CfgString to glusterBlockDef"); - goto out; - } + blockGetMetaInfo(glfs, blk->block_name, info); if(GB_ALLOC(cobj) < 0) goto out; strcpy(cobj->block_name, blk->block_name); - - strcpy(cobj->gbid, blkcfg->gbid); + strcpy(cobj->gbid, info->gbid); list = blockServerParse(blk->block_hosts); for (i = 0; i < list->nhosts; i++) { @@ -532,9 +423,9 @@ block_delete_cli_1_svc(blockDeleteCli *blk, struct svc_req *rqstp) GB_FREE(out); } - if (glusterBlockDeleteEntry(blkcfg)) { + if (glusterBlockDeleteEntry(blk->volume, info->gbid)) { ERROR("%s volume: %s host: %s", - FAILED_DELETING_FILE, blkcfg->volume, blkcfg->volfileserver); + FAILED_DELETING_FILE, blk->volume, "localhost"); } if (GB_ALLOC(reply) < 0) @@ -561,8 +452,6 @@ out: glfs_fini(glfs); blockServerDefFree(list); - GB_FREE(cfgstring); - GB_FREE(blkcfg); GB_FREE(cobj); return reply; @@ -613,35 +502,6 @@ out: } -blockResponse * -block_exec_1_svc(char **cmd, struct svc_req *rqstp) -{ - FILE *fp; - static blockResponse *obj; - - if(GB_ALLOC(obj) < 0) - return NULL; - - if (GB_ALLOC_N(obj->out, 4096) < 0) { - GB_FREE(obj); - return NULL; - } - - fp = popen(*cmd, "r"); - if (fp != NULL) { - size_t newLen = fread(obj->out, sizeof(char), 4996, fp); - if (ferror( fp ) != 0) { - ERROR("%s", "Error reading command output\n"); - } else { - obj->out[newLen++] = '\0'; - } - obj->exit = WEXITSTATUS(pclose(fp)); - } - - return obj; -} - - blockResponse * block_list_cli_1_svc(blockListCli *blk, struct svc_req *rqstp) { diff --git a/rpc/block.h b/rpc/block.h index 132cf63..98ec806 100644 --- a/rpc/block.h +++ b/rpc/block.h @@ -115,9 +115,6 @@ extern blockResponse * block_create_1_svc(blockCreate *, struct svc_req *); #define BLOCK_DELETE 2 extern blockResponse * block_delete_1(blockDelete *, CLIENT *); extern blockResponse * block_delete_1_svc(blockDelete *, struct svc_req *); -#define BLOCK_EXEC 3 -extern blockResponse * block_exec_1(char **, CLIENT *); -extern blockResponse * block_exec_1_svc(char **, struct svc_req *); extern int gluster_block_1_freeresult (SVCXPRT *, xdrproc_t, caddr_t); #else /* K&R C */ @@ -127,9 +124,6 @@ extern blockResponse * block_create_1_svc(); #define BLOCK_DELETE 2 extern blockResponse * block_delete_1(); extern blockResponse * block_delete_1_svc(); -#define BLOCK_EXEC 3 -extern blockResponse * block_exec_1(); -extern blockResponse * block_exec_1_svc(); extern int gluster_block_1_freeresult (); #endif /* K&R C */ diff --git a/rpc/block.x b/rpc/block.x index e5c1984..21c30aa 100644 --- a/rpc/block.x +++ b/rpc/block.x @@ -57,6 +57,5 @@ program GLUSTER_BLOCK { version GLUSTER_BLOCK_VERS { blockResponse BLOCK_CREATE(blockCreate) = 1; blockResponse BLOCK_DELETE(blockDelete) = 2; - blockResponse BLOCK_EXEC(string) = 3; } = 1; } = 21215311; /* B2 L12 O15 C3 K11 */ diff --git a/rpc/block_clnt.c b/rpc/block_clnt.c index 2e96709..4c10231 100644 --- a/rpc/block_clnt.c +++ b/rpc/block_clnt.c @@ -98,18 +98,3 @@ block_delete_1(blockDelete *argp, CLIENT *clnt) } return (&clnt_res); } - -blockResponse * -block_exec_1(char **argp, CLIENT *clnt) -{ - static blockResponse clnt_res; - - memset((char *)&clnt_res, 0, sizeof(clnt_res)); - if (clnt_call (clnt, BLOCK_EXEC, - (xdrproc_t) xdr_wrapstring, (caddr_t) argp, - (xdrproc_t) xdr_blockResponse, (caddr_t) &clnt_res, - TIMEOUT) != RPC_SUCCESS) { - return (NULL); - } - return (&clnt_res); -} diff --git a/rpc/block_svc.c b/rpc/block_svc.c index 345581f..1a908ea 100644 --- a/rpc/block_svc.c +++ b/rpc/block_svc.c @@ -91,7 +91,6 @@ gluster_block_1(struct svc_req *rqstp, register SVCXPRT *transp) union { blockCreate block_create_1_arg; blockDelete block_delete_1_arg; - char *block_exec_1_arg; } argument; char *result; xdrproc_t _xdr_argument, _xdr_result; @@ -114,12 +113,6 @@ gluster_block_1(struct svc_req *rqstp, register SVCXPRT *transp) local = (char *(*)(char *, struct svc_req *)) block_delete_1_svc; break; - case BLOCK_EXEC: - _xdr_argument = (xdrproc_t) xdr_wrapstring; - _xdr_result = (xdrproc_t) xdr_blockResponse; - local = (char *(*)(char *, struct svc_req *)) block_exec_1_svc; - break; - default: svcerr_noproc (transp); return; -- cgit