From acd4965776507abe1102b3a2bfa5ed9cd0340e14 Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Kalever Date: Thu, 2 Feb 2017 16:45:10 +0530 Subject: gluster-block: refresh logging add more meaningful log messages minor code changes such as renaming, indentation and et cetera. Signed-off-by: Pranith Kumar Karampuri Signed-off-by: Prasanna Kumar Kalever --- common.c | 12 ++- common.h | 2 +- glfs-operations.c | 92 +++++++++++------ glfs-operations.h | 2 +- gluster-block.c | 38 +++---- gluster-blockd.c | 301 +++++++++++++++++++++++++++++++----------------------- rpc/block_svc.c | 19 ++-- utils.c | 63 +++++++----- utils.h | 142 ++++++++++++++------------ 9 files changed, 382 insertions(+), 289 deletions(-) diff --git a/common.c b/common.c index aa9ad82..2efc127 100644 --- a/common.c +++ b/common.c @@ -13,12 +13,12 @@ -size_t +ssize_t glusterBlockCreateParseSize(char *value) { char *postfix; char *tmp; - size_t sizef; + ssize_t sizef; if (!value) return -1; @@ -30,8 +30,9 @@ glusterBlockCreateParseSize(char *value) } tmp = postfix; - if (*postfix == ' ') + if (*postfix == ' ') { tmp = tmp + 1; + } switch (*tmp) { case 'Y': @@ -64,8 +65,9 @@ glusterBlockCreateParseSize(char *value) return sizef; break; default: - ERROR("%s", "You may use k/K, M, G or T suffixes for " - "kilobytes, megabytes, gigabytes and terabytes."); + /*TODO: Log this instead of printing + ERROR("%s", "You may use k/K, M, G or T suffixes for " + "kilobytes, megabytes, gigabytes and terabytes."); */ return -1; } } diff --git a/common.h b/common.h index d24a490..c230df8 100644 --- a/common.h +++ b/common.h @@ -22,6 +22,6 @@ -size_t glusterBlockCreateParseSize(char *value); +ssize_t glusterBlockCreateParseSize(char *value); # endif /* _COMMON_H */ diff --git a/glfs-operations.c b/glfs-operations.c index dba924e..9712f64 100644 --- a/glfs-operations.c +++ b/glfs-operations.c @@ -23,27 +23,32 @@ glusterBlockVolumeInit(char *volume, char *volfileserver) struct glfs *glfs; int ret; + glfs = glfs_new(volume); if (!glfs) { - LOG("gfapi", ERROR, "%s", "glfs_new: failed"); + LOG("gfapi", GB_LOG_ERROR, "glfs_new(%s) from %s failed[%s]", volume, + volfileserver, strerror(errno)); return NULL; } ret = glfs_set_volfile_server(glfs, "tcp", volfileserver, 24007); if (ret) { - LOG("gfapi", ERROR, "%s", "glfs_set_volfile_server: failed"); + LOG("gfapi", GB_LOG_ERROR, "glfs_set_volfile_server(%s) of %s " + "failed[%s]", volfileserver, volume, strerror(errno)); goto out; } ret = glfs_set_logging(glfs, GFAPI_LOG_FILE, GFAPI_LOG_LEVEL); if (ret) { - LOG("gfapi", ERROR, "%s", "glfs_set_logging: failed"); + LOG("gfapi", GB_LOG_ERROR, "glfs_set_logging(%s, %d) on %s failed[%s]", + GFAPI_LOG_FILE, GFAPI_LOG_LEVEL, volume, strerror(errno)); goto out; } ret = glfs_init(glfs); if (ret) { - LOG("gfapi", ERROR, "%s", "glfs_init: failed"); + LOG("gfapi", GB_LOG_ERROR, "glfs_init() on %s failed[%s]", volume, + strerror(errno) ); goto out; } @@ -60,29 +65,36 @@ int glusterBlockCreateEntry(blockCreateCli *blk, char *gbid) { struct glfs *glfs; - struct glfs_fd *fd; + struct glfs_fd *tgfd; int ret = -1; + glfs = glusterBlockVolumeInit(blk->volume, blk->volfileserver); if (!glfs) { - LOG("gfapi", ERROR, "%s", "glusterBlockVolumeInit: failed"); + LOG("gfapi", GB_LOG_ERROR, "glusterBlockVolumeInit(%s): failed", + blk->volume); goto out; } - fd = glfs_creat(glfs, gbid, - O_WRONLY | O_CREAT | O_TRUNC, + tgfd = glfs_creat(glfs, gbid, + O_WRONLY | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); - if (!fd) { - LOG("gfapi", ERROR, "%s", "glfs_creat: failed"); + if (!tgfd) { + LOG("gfapi", GB_LOG_ERROR, "glfs_creat(%s) on volume %s failed[%s]", + gbid, blk->volume, strerror(errno)); } else { - ret = glfs_ftruncate(fd, blk->size); + ret = glfs_ftruncate(tgfd, blk->size); if (ret) { - LOG("gfapi", ERROR, "%s", "glfs_ftruncate: failed"); + LOG("gfapi", GB_LOG_ERROR, "glfs_ftruncate(%s): on volume %s " + "of size %zu failed[%s]", gbid, blk->volume, blk->size, + strerror(errno)); goto out; } - if (glfs_close(fd) != 0) { - LOG("gfapi", ERROR, "%s", "glfs_close: failed"); + if (glfs_close(tgfd) != 0) { + LOG("gfapi", GB_LOG_ERROR, "glfs_close(%s): on volume %s failed[%s]", + gbid, blk->volume, strerror(errno)); + goto out; } } @@ -98,15 +110,18 @@ glusterBlockDeleteEntry(char *volume, char *gbid) struct glfs *glfs; int ret = -1; + glfs = glusterBlockVolumeInit(volume, "localhost"); if (!glfs) { - LOG("gfapi", ERROR, "%s", "glusterBlockVolumeInit: failed"); + LOG("gfapi", GB_LOG_ERROR, "glusterBlockVolumeInit(%s): failed", + volume); goto out; } ret = glfs_unlink(glfs, gbid); if (ret) { - LOG("gfapi", ERROR, "%s", "glfs_unlink: failed"); + LOG("gfapi", GB_LOG_ERROR, "glfs_unlink(%s) on volume %s failed[%s]", + gbid, volume, strerror(errno)); goto out; } @@ -117,26 +132,30 @@ glusterBlockDeleteEntry(char *volume, char *gbid) struct glfs_fd * -glusterBlockCreateMetaLockFile(struct glfs *glfs) +glusterBlockCreateMetaLockFile(struct glfs *glfs, char *volume) { struct glfs_fd *lkfd; int ret; + ret = glfs_mkdir (glfs, METADIR, 0); if (ret && errno != EEXIST) { - LOG("gfapi", ERROR, "%s", "glfs_mkdir: failed"); + LOG("gfapi", GB_LOG_ERROR, "glfs_mkdir(%s) on volume %s failed[%s]", + METADIR, volume, strerror(errno)); goto out; } ret = glfs_chdir (glfs, METADIR); if (ret) { - LOG("gfapi", ERROR, "%s", "glfs_chdir: failed"); + LOG("gfapi", GB_LOG_ERROR, "glfs_chdir(%s) on volume %s failed[%s]", + METADIR, volume, strerror(errno)); goto out; } lkfd = glfs_creat(glfs, TXLOCKFILE, O_RDWR, S_IRUSR | S_IWUSR); if (!lkfd) { - LOG("gfapi", ERROR, "%s", "glfs_creat: failed"); + LOG("gfapi", GB_LOG_ERROR, "glfs_creat(%s) on volume %s failed[%s]", + TXLOCKFILE, volume, strerror(errno)); goto out; } @@ -152,10 +171,11 @@ blockFreeMetaInfo(MetaInfo *info) { int i; + if (!info) return; - for (i = 0; i< info->nhosts; i++) + for (i = 0; i < info->nhosts; i++) GB_FREE(info->list[i]); GB_FREE(info->list); @@ -171,20 +191,21 @@ blockStuffMetaInfo(MetaInfo *info, char *line) int Flag = 0; size_t i; + switch (blockMetaKeyEnumParse(opt)) { - case VOLUME: + case GB_META_VOLUME: strcpy(info->volume, strchr(line, ' ')+1); break; - case GBID: + case GB_META_GBID: strcpy(info->gbid, strchr(line, ' ')+1); break; - case SIZE: + case GB_META_SIZE: sscanf(strchr(line, ' ')+1, "%zu", &info->size); break; - case HA: + case GB_META_HA: sscanf(strchr(line, ' ')+1, "%zu", &info->mpath); break; - case ENTRYCREATE: + case GB_META_ENTRYCREATE: strcpy(info->entry, strchr(line, ' ')+1); break; @@ -219,28 +240,31 @@ blockStuffMetaInfo(MetaInfo *info, char *line) GB_FREE(tmp); } + int blockGetMetaInfo(struct glfs* glfs, char* metafile, MetaInfo *info) { size_t count = 0; - struct glfs_fd *tgfd; - char line[48]; + struct glfs_fd *tgmfd; + char line[1024]; char *tmp; - tgfd = glfs_open(glfs, metafile, O_RDONLY); - if (!tgfd) { - LOG("gfapi", ERROR, "%s", "glfs_open failed"); + + tgmfd = glfs_open(glfs, metafile, O_RDONLY); + if (!tgmfd) { + LOG("gfapi", GB_LOG_ERROR, "glfs_open(%s) on volume %s failed[%s]", + metafile, info->volume, strerror(errno)); return -1; } - while (glfs_read (tgfd, line, 48, 0) > 0) { + while (glfs_read (tgmfd, line, sizeof(line), 0) > 0) { tmp = strtok(line,"\n"); count += strlen(tmp) + 1; blockStuffMetaInfo(info, tmp); - glfs_lseek(tgfd, count, SEEK_SET); + glfs_lseek(tgmfd, count, SEEK_SET); } - glfs_close(tgfd); + glfs_close(tgmfd); return 0; } diff --git a/glfs-operations.h b/glfs-operations.h index 3c2e4c9..214a71c 100644 --- a/glfs-operations.h +++ b/glfs-operations.h @@ -50,7 +50,7 @@ int glusterBlockDeleteEntry(char *volume, char *gbid); struct glfs_fd * -glusterBlockCreateMetaLockFile(struct glfs *glfs); +glusterBlockCreateMetaLockFile(struct glfs *glfs, char *volume); int blockGetMetaInfo(struct glfs *glfs, char *metafile, MetaInfo *info); diff --git a/gluster-block.c b/gluster-block.c index 3a3cab7..4acf498 100644 --- a/gluster-block.c +++ b/gluster-block.c @@ -48,7 +48,7 @@ glusterBlockCliRPC_1(void *cobj, operations opt, char **out) if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { - LOG("cli", ERROR, "socket creation failed (%s)", strerror (errno)); + LOG("cli", GB_LOG_ERROR, "socket creation failed (%s)", strerror (errno)); goto out; } @@ -57,7 +57,7 @@ glusterBlockCliRPC_1(void *cobj, operations opt, char **out) if (connect(sockfd, (struct sockaddr *) &saun, sizeof(struct sockaddr_un)) < 0) { - LOG("cli", ERROR, "connect failed (%s)", strerror (errno)); + LOG("cli", GB_LOG_ERROR, "connect failed (%s)", strerror (errno)); goto out; } @@ -65,7 +65,7 @@ glusterBlockCliRPC_1(void *cobj, operations opt, char **out) GLUSTER_BLOCK_CLI, GLUSTER_BLOCK_CLI_VERS, &sockfd, 0, 0); if (!clnt) { - LOG("cli", ERROR, "%s, unix addr %s", + LOG("cli", GB_LOG_ERROR, "%s, unix addr %s", clnt_spcreateerror("client create failed"), ADDRESS); goto out; } @@ -74,28 +74,28 @@ glusterBlockCliRPC_1(void *cobj, operations opt, char **out) case CREATE_CLI: reply = block_create_cli_1((blockCreateCli *)cobj, clnt); if (!reply) { - LOG("cli", ERROR, "%s", clnt_sperror(clnt, "block create failed")); + LOG("cli", GB_LOG_ERROR, "%s", clnt_sperror(clnt, "block create failed")); goto out; } break; case DELETE_CLI: reply = block_delete_cli_1((blockDeleteCli *)cobj, clnt); if (!reply) { - LOG("cli", ERROR, "%s", clnt_sperror(clnt, "block delete failed")); + LOG("cli", GB_LOG_ERROR, "%s", clnt_sperror(clnt, "block delete failed")); goto out; } break; case INFO_CLI: reply = block_info_cli_1((blockInfoCli *)cobj, clnt); if (!reply) { - LOG("cli", ERROR, "%s", clnt_sperror(clnt, "block info failed")); + LOG("cli", GB_LOG_ERROR, "%s", clnt_sperror(clnt, "block info failed")); goto out; } break; case LIST_CLI: reply = block_list_cli_1((blockListCli *)cobj, clnt); if (!reply) { - LOG("cli", ERROR, "%s", clnt_sperror(clnt, "block list failed")); + LOG("cli", GB_LOG_ERROR, "%s", clnt_sperror(clnt, "block list failed")); goto out; } break; @@ -107,7 +107,7 @@ glusterBlockCliRPC_1(void *cobj, operations opt, char **out) out: if (!clnt_freeres(clnt, (xdrproc_t)xdr_blockResponse, (char *)reply)) - LOG("cli", ERROR, "%s", clnt_sperror(clnt, "clnt_freeres failed")); + LOG("cli", GB_LOG_ERROR, "%s", clnt_sperror(clnt, "clnt_freeres failed")); if (clnt) clnt_destroy (clnt); @@ -152,7 +152,7 @@ glusterBlockCreate(int count, char **options, char *name) if (!name) { - LOG("cli", ERROR, "%s", "Insufficient arguments supplied for" + LOG("cli", GB_LOG_ERROR, "%s", "Insufficient arguments supplied for" "'gluster-block create'"); ret = -1; goto out; @@ -171,7 +171,7 @@ glusterBlockCreate(int count, char **options, char *name) }; optchar = getopt_long(count, options, "b:v:h:s:", - long_options, &option_index); + long_options, &option_index); if (optchar == -1) break; @@ -184,7 +184,7 @@ glusterBlockCreate(int count, char **options, char *name) case 'b': if (GB_STRDUP(cobj.block_hosts, optarg) < 0) { - LOG("cli", ERROR, "%s", "failed while parsing size"); + LOG("cli", GB_LOG_ERROR, "%s", "failed while parsing size"); ret = -1; goto out; } @@ -204,7 +204,7 @@ glusterBlockCreate(int count, char **options, char *name) case 's': cobj.size = glusterBlockCreateParseSize(optarg); if (cobj.size < 0) { - LOG("cli", ERROR, "%s", "failed while parsing size"); + LOG("cli", GB_LOG_ERROR, "%s", "failed while parsing size"); ret = -1; goto out; } @@ -223,7 +223,7 @@ glusterBlockCreate(int count, char **options, char *name) /* Print any remaining command line arguments (not options). */ if (optind < count) { - LOG("cli", ERROR, "%s", "non-option ARGV-elements: "); + LOG("cli", GB_LOG_ERROR, "%s", "non-option ARGV-elements: "); while (optind < count) MSG("provided options: %s", options[optind++]); putchar('\n'); @@ -233,7 +233,7 @@ glusterBlockCreate(int count, char **options, char *name) } if (ret != 5) { - LOG("cli", ERROR, "%s", "Insufficient arguments supplied for" + LOG("cli", GB_LOG_ERROR, "%s", "Insufficient arguments supplied for" "'gluster-block create'\n"); ret = -1; goto out; @@ -350,7 +350,7 @@ glusterBlockParseArgs(int count, char **options) case 'c': ret = glusterBlockCreate(count, options, optarg); if (ret && ret != EEXIST) { - LOG("cli", ERROR, "%s", FAILED_CREATE); + LOG("cli", GB_LOG_ERROR, "%s", FAILED_CREATE); goto out; } break; @@ -382,23 +382,23 @@ glusterBlockParseArgs(int count, char **options) case 'l': ret = glusterBlockList(volume); if (ret) - LOG("cli", ERROR, "%s", FAILED_LIST); + LOG("cli", GB_LOG_ERROR, "%s", FAILED_LIST); break; case 'i': ret = glusterBlockInfo(blockname, volume); if (ret) - LOG("cli", ERROR, "%s", FAILED_INFO); + LOG("cli", GB_LOG_ERROR, "%s", FAILED_INFO); break; case 'd': ret = glusterBlockDelete(blockname, volume); if (ret) - LOG("cli", ERROR, "%s", FAILED_DELETE); + LOG("cli", GB_LOG_ERROR, "%s", FAILED_DELETE); break; } out: if (ret == 0 && optind < count) { - LOG("cli", ERROR, "%s", "Unable to parse elements: "); + LOG("cli", GB_LOG_ERROR, "%s", "Unable to parse elements: "); while (optind < count) MSG("provided options: %s", options[optind++]); putchar('\n'); diff --git a/gluster-blockd.c b/gluster-blockd.c index 1f75f41..ef27dbd 100644 --- a/gluster-blockd.c +++ b/gluster-blockd.c @@ -62,13 +62,15 @@ glusterBlockCallRPC_1(char *host, void *cobj, if ((sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { - LOG("mgmt", ERROR, "socket creation failed (%s)", strerror (errno)); + LOG("mgmt", GB_LOG_ERROR, "socket creation failed (%s)", + strerror (errno)); goto out; } server = gethostbyname(host); if (!server) { - LOG("mgmt", ERROR, "gethostbyname failed (%s)", strerror (errno)); + LOG("mgmt", GB_LOG_ERROR, "gethostbyname failed (%s)", + strerror (errno)); goto out; } @@ -79,14 +81,14 @@ glusterBlockCallRPC_1(char *host, void *cobj, sain.sin_port = htons(24006); if (connect(sockfd, (struct sockaddr *) &sain, sizeof(sain)) < 0) { - LOG("mgmt", ERROR, "connect failed (%s)", strerror (errno)); + LOG("mgmt", GB_LOG_ERROR, "connect failed (%s)", strerror (errno)); goto out; } clnt = clnttcp_create ((struct sockaddr_in *) &sain, GLUSTER_BLOCK, GLUSTER_BLOCK_VERS, &sockfd, 0, 0); if (!clnt) { - LOG("mgmt", ERROR, "%s, inet host %s", + LOG("mgmt", GB_LOG_ERROR, "%s, inet host %s", clnt_spcreateerror("client create failed"), host); goto out; } @@ -95,29 +97,35 @@ glusterBlockCallRPC_1(char *host, void *cobj, case CREATE_SRV: reply = block_create_1((blockCreate *)cobj, clnt); if (!reply) { - LOG("mgmt", ERROR, "%s", clnt_sperror(clnt, "block create failed")); + LOG("mgmt", GB_LOG_ERROR, "%s", + clnt_sperror(clnt, "block create failed")); goto out; } break; case DELETE_SRV: reply = block_delete_1((blockDelete *)cobj, clnt); if (!reply) { - LOG("mgmt", ERROR, "%s", clnt_sperror(clnt, "block delete failed")); + LOG("mgmt", GB_LOG_ERROR, "%s", + clnt_sperror(clnt, "block delete failed")); goto out; } break; } - if (GB_STRDUP(*out, reply->out) < 0) + if (GB_STRDUP(*out, reply->out) < 0){ goto out; + } ret = reply->exit; out: - if (!clnt_freeres(clnt, (xdrproc_t)xdr_blockResponse, (char *)reply)) - LOG("mgmt", ERROR, "%s", clnt_sperror(clnt, "clnt_freeres failed")); + if (!clnt_freeres(clnt, (xdrproc_t)xdr_blockResponse, (char *)reply)) { + LOG("mgmt", GB_LOG_ERROR, "%s", + clnt_sperror(clnt, "clnt_freeres failed")); + } - if (clnt) + if (clnt) { clnt_destroy (clnt); + } close(sockfd); @@ -131,13 +139,15 @@ blockServerDefFree(blockServerDefPtr blkServers) size_t i; - if (!blkServers) + if (!blkServers) { return; + } - for (i = 0; i < blkServers->nhosts; i++) + for (i = 0; i < blkServers->nhosts; i++) { GB_FREE(blkServers->hosts[i]); - GB_FREE(blkServers->hosts); - GB_FREE(blkServers); + } + GB_FREE(blkServers->hosts); + GB_FREE(blkServers); } @@ -149,28 +159,33 @@ blockServerParse(char *blkServers) size_t i = 0; - if (GB_ALLOC(list) < 0) + if (GB_ALLOC(list) < 0) { return NULL; + } - if (!blkServers) + if (!blkServers) { blkServers = "localhost"; + } /* count number of servers */ while (*tmp) { - if (*tmp == ',') + if (*tmp == ',') { list->nhosts++; + } tmp++; } list->nhosts++; tmp = blkServers; /* reset addr */ - if (GB_ALLOC_N(list->hosts, list->nhosts) < 0) + 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) + if (GB_STRDUP(list->hosts[i], strsep(&tmp, MSERVER_DELIMITER)) < 0) { goto fail; + } } return list; @@ -180,25 +195,29 @@ blockServerParse(char *blkServers) return NULL; } + static void -glusterBlockCreateRemote(struct glfs_fd *tgfd, blockCreate *cobj, - char *addr, char **reply) +glusterBlockCreateRemote(struct glfs_fd *tgmfd, char *volume, + blockCreate *cobj, char *addr, char **reply) { - int ret = -1; + int ret; char *out = NULL; char *tmp = *reply; - METAUPDATE(tgfd, "%s: CONFIGINPROGRESS\n", addr); + GB_METAUPDATE_OR_GOTO(tgmfd, cobj->gbid, volume, ret, out, + "%s: CONFIGINPROGRESS\n", addr); ret = glusterBlockCallRPC_1(addr, cobj, CREATE_SRV, &out); if (ret) { - METAUPDATE(tgfd, "%s: CONFIGFAIL\n", addr); - LOG("mgmt", ERROR, "%s on host: %s", FAILED_CREATE, addr); + GB_METAUPDATE_OR_GOTO(tgmfd, cobj->gbid, volume, ret, out, + "%s: CONFIGFAIL\n", addr); + LOG("mgmt", GB_LOG_ERROR, "%s on host: %s", FAILED_CREATE, addr); goto out; } - METAUPDATE(tgfd, "%s: CONFIGSUCCESS\n", addr); + GB_METAUPDATE_OR_GOTO(tgmfd, cobj->gbid, volume, ret, out, + "%s: CONFIGSUCCESS\n", addr); out: asprintf(reply, "%s%s\n", (tmp==NULL?"":tmp), out); @@ -206,9 +225,10 @@ glusterBlockCreateRemote(struct glfs_fd *tgfd, blockCreate *cobj, GB_FREE(out); } + static int glusterBlockAuditRequest(struct glfs *glfs, - struct glfs_fd *tgfd, + struct glfs_fd *tgmfd, blockCreateCli *blk, blockCreate *cobj, blockServerDefPtr list, @@ -224,20 +244,22 @@ glusterBlockAuditRequest(struct glfs *glfs, MetaInfo *info; - if (GB_ALLOC(info) < 0) + if (GB_ALLOC(info) < 0) { goto out; + } ret = blockGetMetaInfo(glfs, blk->block_name, info); - if (ret) + if (ret) { goto out; + } for (i = 0; i < info->nhosts; i++) { switch (blockMetaStatusEnumParse(info->list[i]->status)) { - case CONFIGSUCCESS: + case GB_CONFIG_SUCCESS: successcnt++; break; - case CONFIGINPROGRESS: - case CONFIGFAIL: + case GB_CONFIG_INPROGRESS: + case GB_CONFIG_FAIL: failcnt++; } } @@ -251,26 +273,27 @@ glusterBlockAuditRequest(struct glfs *glfs, spare = list->nhosts - spent; /* spare after spent */ morereq = blk->mpath - successcnt; /* needed nodes to complete req */ if (spare == 0) { - LOG("mgmt", WARNING, "%s", + LOG("mgmt", GB_LOG_WARNING, "%s", "No Spare nodes: rewining the creation of target"); ret = -1; goto out; } else if (spare < morereq) { - LOG("mgmt", WARNING, "%s", + LOG("mgmt", GB_LOG_WARNING, "%s", "Not enough Spare nodes: rewining the creation of target"); ret = -1; goto out; } else { /* create on spare */ - LOG("mgmt", INFO, "%s", + LOG("mgmt", GB_LOG_INFO, "%s", "trying to serve the mpath from spare machines"); for (i = spent; i < list->nhosts; i++) { - glusterBlockCreateRemote(tgfd, cobj, list->hosts[i], reply); + glusterBlockCreateRemote(tgmfd, info->volume, cobj, + list->hosts[i], reply); } } } - ret = glusterBlockAuditRequest(glfs, tgfd, blk, cobj, list, reply); + ret = glusterBlockAuditRequest(glfs, tgmfd, blk, cobj, list, reply); out: blockFreeMetaInfo(info); @@ -279,23 +302,26 @@ glusterBlockAuditRequest(struct glfs *glfs, static void -glusterBlockDeleteRemote(struct glfs_fd *tgfd, blockDelete *cobj, - char *addr, char **reply) +glusterBlockDeleteRemote(struct glfs_fd *tgmfd, MetaInfo *info, + blockDelete *cobj, char *addr, char **reply) { int ret = -1; char *out = NULL; char *tmp = *reply; - METAUPDATE(tgfd, "%s: CLEANUPINPROGRES\n", addr); + GB_METAUPDATE_OR_GOTO(tgmfd, info->gbid, info->volume, ret, out, + "%s: CLEANUPINPROGRES\n", addr); ret = glusterBlockCallRPC_1(addr, cobj, DELETE_SRV, &out); if (ret) { - METAUPDATE(tgfd, "%s: CLEANUPFAIL\n", addr); - LOG("mgmt", ERROR, "%s on host: %s", + GB_METAUPDATE_OR_GOTO(tgmfd, info->gbid, info->volume, ret, out, + "%s: CLEANUPFAIL\n", addr); + LOG("mgmt", GB_LOG_ERROR, "%s on host: %s", FAILED_GATHERING_INFO, addr); goto out; } - METAUPDATE(tgfd, "%s: CLEANUPSUCCESS\n", addr); + GB_METAUPDATE_OR_GOTO(tgmfd, info->gbid, info->volume, ret, out, + "%s: CLEANUPSUCCESS\n", addr); out: asprintf(reply, "%s%s\n", (tmp==NULL?"":tmp), out); @@ -311,41 +337,43 @@ glusterBlockCleanUp(struct glfs *glfs, char *blockname, int ret = -1; size_t i; static blockDelete cobj; - struct glfs_fd *tgfd = NULL; + struct glfs_fd *tgmfd = NULL; size_t cleanupsuccess = 0; MetaInfo *info; - if (GB_ALLOC(info) < 0) + if (GB_ALLOC(info) < 0) { goto out; + } ret = blockGetMetaInfo(glfs, blockname, info); - if (ret) + if (ret) { goto out; + } strcpy(cobj.block_name, blockname); strcpy(cobj.gbid, info->gbid); - tgfd = glfs_open(glfs, blockname, O_WRONLY|O_APPEND); - if (!tgfd) { - LOG("mgmt", ERROR, "%s", "glfs_open: failed"); + tgmfd = glfs_open(glfs, blockname, O_WRONLY|O_APPEND); + if (!tgmfd) { + LOG("mgmt", GB_LOG_ERROR, "%s", "glfs_open: failed"); goto out; } for (i = 0; i < info->nhosts; i++) { switch (blockMetaStatusEnumParse(info->list[i]->status)) { - case CLEANUPINPROGRES: - case CLEANUPFAIL: - case CONFIGFAIL: - case CONFIGINPROGRESS: - glusterBlockDeleteRemote(tgfd, &cobj, - info->list[i]->addr, reply); + case GB_CLEANUP_INPROGRES: + case GB_CLEANUP_FAIL: + case GB_CONFIG_FAIL: + case GB_CONFIG_INPROGRESS: + glusterBlockDeleteRemote(tgmfd, info, &cobj, + info->list[i]->addr, reply); break; } if (deleteall && - blockMetaStatusEnumParse(info->list[i]->status) == CONFIGSUCCESS) { - glusterBlockDeleteRemote(tgfd, &cobj, - info->list[i]->addr, reply); + blockMetaStatusEnumParse(info->list[i]->status) == GB_CONFIG_SUCCESS) { + glusterBlockDeleteRemote(tgmfd, info, &cobj, + info->list[i]->addr, reply); } } blockFreeMetaInfo(info); @@ -358,18 +386,19 @@ glusterBlockCleanUp(struct glfs *glfs, char *blockname, goto out; for (i = 0; i < info->nhosts; i++) { - if (blockMetaStatusEnumParse(info->list[i]->status) == CLEANUPSUCCESS) + if (blockMetaStatusEnumParse(info->list[i]->status) == GB_CLEANUP_SUCCESS) { cleanupsuccess++; + } } if (cleanupsuccess == info->nhosts) { if (glusterBlockDeleteEntry(info->volume, info->gbid)) { - LOG("mgmt", ERROR, "%s volume: %s host: %s", + LOG("mgmt", GB_LOG_ERROR, "%s volume: %s host: %s", FAILED_DELETING_FILE, info->volume, "localhost"); } ret = glfs_unlink(glfs, blockname); if (ret && errno != ENOENT) { - LOG("mgmt", ERROR, "%s", "glfs_unlink: failed"); + LOG("mgmt", GB_LOG_ERROR, "%s", "glfs_unlink: failed"); goto out; } } @@ -377,8 +406,8 @@ glusterBlockCleanUp(struct glfs *glfs, char *blockname, out: blockFreeMetaInfo(info); - if (glfs_close(tgfd) != 0) { - LOG("mgmt", ERROR, "%s", "glfs_close: failed"); + if (glfs_close(tgmfd) != 0) { + LOG("mgmt", GB_LOG_ERROR, "%s", "glfs_close: failed"); } return ret; @@ -397,20 +426,21 @@ block_create_cli_1_svc(blockCreateCli *blk, struct svc_req *rqstp) static blockResponse *reply; struct glfs *glfs; struct glfs_fd *lkfd = NULL; - struct glfs_fd *tgfd = NULL; + struct glfs_fd *tgmfd = NULL; blockServerDefPtr list = NULL; - if (GB_ALLOC(reply) < 0) + if (GB_ALLOC(reply) < 0) { goto out; + } list = blockServerParse(blk->block_hosts); /* Fail if mpath > list->nhosts */ if (blk->mpath > list->nhosts) { - LOG("mgmt", ERROR, "block multipath request:%d is greater than " - "provided block-hosts:%s", - blk->mpath, blk->block_hosts); + LOG("mgmt", GB_LOG_ERROR, "block multipath request:%d is greater " + "than provided block-hosts:%s", + blk->mpath, blk->block_hosts); asprintf(&reply->out, "multipath req: %d > block-hosts: %s\n", blk->mpath, blk->block_hosts); reply->exit = ENODEV; @@ -419,17 +449,18 @@ block_create_cli_1_svc(blockCreateCli *blk, struct svc_req *rqstp) glfs = glusterBlockVolumeInit(blk->volume, blk->volfileserver); if (!glfs) { - LOG("mgmt", ERROR, "%s", "glusterBlockVolumeInit failed"); + LOG("mgmt", GB_LOG_ERROR, "%s", "glusterBlockVolumeInit failed"); goto out; } - lkfd = glusterBlockCreateMetaLockFile(glfs); + lkfd = glusterBlockCreateMetaLockFile(glfs, blk->volume); if (!lkfd) { - LOG("mgmt", ERROR, "%s", "glusterBlockCreateMetaLockFile failed"); + LOG("mgmt", GB_LOG_ERROR, "%s", + "glusterBlockCreateMetaLockFile failed"); goto out; } - METALOCK(lkfd); + GB_METALOCK_OR_GOTO(lkfd, blk->volume, ret, out); if (!glfs_access(glfs, blk->block_name, F_OK)) { asprintf(&reply->out, "BLOCK with name: '%s' already EXIST\n", @@ -438,28 +469,31 @@ block_create_cli_1_svc(blockCreateCli *blk, struct svc_req *rqstp) goto exist; } - tgfd = glfs_creat(glfs, blk->block_name, O_RDWR, S_IRUSR | S_IWUSR); - if (!tgfd) { - LOG("mgmt", ERROR, "%s", "glfs_creat: failed"); + tgmfd = glfs_creat(glfs, blk->block_name, O_RDWR, S_IRUSR | S_IWUSR); + if (!tgmfd) { + LOG("mgmt", GB_LOG_ERROR, "%s", "glfs_creat: failed"); goto out; } uuid_generate(uuid); uuid_unparse(uuid, gbid); - METAUPDATE(tgfd, "VOLUME: %s\n" - "GBID: %s\nSIZE: %zu\nHA: %d\nENTRYCREATE: INPROGRESS\n", - blk->volume, gbid, blk->size, blk->mpath); + GB_METAUPDATE_OR_GOTO(tgmfd, blk->block_name, blk->volume, ret, exist, + "VOLUME: %s\nGBID: %s\nSIZE: %zu\nHA: %d\n" + "ENTRYCREATE: INPROGRESS\n", + blk->volume, gbid, blk->size, blk->mpath); ret = glusterBlockCreateEntry(blk, gbid); if (ret) { - METAUPDATE(tgfd, "ENTRYCREATE: FAIL\n"); - LOG("mgmt", ERROR, "%s volume: %s host: %s", + GB_METAUPDATE_OR_GOTO(tgmfd, blk->block_name, blk->volume, ret, + exist, "ENTRYCREATE: FAIL\n"); + LOG("mgmt", GB_LOG_ERROR, "%s volume: %s host: %s", FAILED_CREATING_FILE, blk->volume, blk->volfileserver); goto out; } - METAUPDATE(tgfd, "ENTRYCREATE: SUCCESS\n"); + GB_METAUPDATE_OR_GOTO(tgmfd, blk->block_name, blk->volume, ret, exist, + "ENTRYCREATE: SUCCESS\n"); strcpy(cobj.volume, blk->volume); strcpy(cobj.volfileserver, blk->volfileserver); @@ -468,14 +502,15 @@ block_create_cli_1_svc(blockCreateCli *blk, struct svc_req *rqstp) strcpy(cobj.gbid, gbid); for (i = 0; i < blk->mpath; i++) { - glusterBlockCreateRemote(tgfd, &cobj, list->hosts[i], &savereply); + glusterBlockCreateRemote(tgmfd, blk->volume, &cobj, + list->hosts[i], &savereply); } /* Check Point */ - ret = glusterBlockAuditRequest(glfs, tgfd, blk, + ret = glusterBlockAuditRequest(glfs, tgmfd, blk, &cobj, list, &savereply); if (ret) { - LOG("mgmt", ERROR, "%s", + LOG("mgmt", GB_LOG_ERROR, "%s", "even spare nodes have exhausted rewinding"); ret = glusterBlockCleanUp(glfs, blk->block_name, FALSE, &savereply); @@ -484,16 +519,17 @@ block_create_cli_1_svc(blockCreateCli *blk, struct svc_req *rqstp) out: reply->out = savereply; - if (glfs_close(tgfd) != 0) - LOG("mgmt", ERROR, "%s", "glfs_close: failed"); + if (glfs_close(tgmfd) != 0) + LOG("mgmt", GB_LOG_ERROR, "%s", "glfs_close: failed"); exist: - METAUNLOCK(lkfd); + GB_METAUNLOCK(lkfd, blk->volume, ret); reply->exit = ret; - if (glfs_close(lkfd) != 0) - LOG("mgmt", ERROR, "%s", "glfs_close: failed"); + if (glfs_close(lkfd) != 0) { + LOG("mgmt", GB_LOG_ERROR, "%s", "glfs_close: failed"); + } glfs_fini(glfs); @@ -534,8 +570,9 @@ block_create_1_svc(blockCreate *blk, struct svc_req *rqstp) asprintf(&exec, "%s && %s && %s && %s && %s", backstore, iqn, lun, attr, TARGETCLI_SAVE); - if (GB_ALLOC(reply) < 0) + if (GB_ALLOC(reply) < 0) { goto out; + } if (GB_ALLOC_N(reply->out, 4096) < 0) { GB_FREE(reply); @@ -546,7 +583,7 @@ block_create_1_svc(blockCreate *blk, struct svc_req *rqstp) if (fp != NULL) { size_t newLen = fread(reply->out, sizeof(char), 4096, fp); if (ferror( fp ) != 0) { - LOG("mgmt", ERROR, "Reading command %s output", exec); + LOG("mgmt", GB_LOG_ERROR, "Reading command %s output", exec); } else { reply->out[newLen++] = '\0'; } @@ -574,22 +611,24 @@ block_delete_cli_1_svc(blockDeleteCli *blk, struct svc_req *rqstp) struct glfs_fd *lkfd; - if (GB_ALLOC(reply) < 0) + if (GB_ALLOC(reply) < 0) { return NULL; + } glfs = glusterBlockVolumeInit(blk->volume, "localhost"); if (!glfs) { - LOG("mgmt", ERROR, "%s", "glusterBlockVolumeInit failed"); + LOG("mgmt", GB_LOG_ERROR, "%s", "glusterBlockVolumeInit failed"); goto out; } - lkfd = glusterBlockCreateMetaLockFile(glfs); + lkfd = glusterBlockCreateMetaLockFile(glfs, blk->volume); if (!lkfd) { - LOG("mgmt", ERROR, "%s", "glusterBlockCreateMetaLockFile failed"); + LOG("mgmt", GB_LOG_ERROR, "%s", + "glusterBlockCreateMetaLockFile failed"); goto out; } - METALOCK(lkfd); + GB_METALOCK_OR_GOTO(lkfd, blk->volume, ret, out); if (glfs_access(glfs, blk->block_name, F_OK)) { GB_STRDUP(reply->out, "BLOCK Doesn't EXIST"); @@ -602,12 +641,12 @@ block_delete_cli_1_svc(blockDeleteCli *blk, struct svc_req *rqstp) out: reply->out = savereply; - METAUNLOCK(lkfd); + GB_METAUNLOCK(lkfd, blk->volume, ret); reply->exit = ret; if (glfs_close(lkfd) != 0) - LOG("mgmt", ERROR, "%s", "glfs_close: failed"); + LOG("mgmt", GB_LOG_ERROR, "%s", "glfs_close: failed"); glfs_fini(glfs); @@ -633,8 +672,9 @@ block_delete_1_svc(blockDelete *blk, struct svc_req *rqstp) asprintf(&exec, "%s && %s && %s", backstore, iqn, TARGETCLI_SAVE); - if (GB_ALLOC(reply) < 0) + if (GB_ALLOC(reply) < 0) { goto out; + } if (GB_ALLOC_N(reply->out, 4096) < 0) { GB_FREE(reply); @@ -645,7 +685,7 @@ block_delete_1_svc(blockDelete *blk, struct svc_req *rqstp) if (fp != NULL) { size_t newLen = fread(reply->out, sizeof(char), 4096, fp); if (ferror( fp ) != 0) { - LOG("mgmt", ERROR, "reading command %s output", exec); + LOG("mgmt", GB_LOG_ERROR, "reading command %s output", exec); } else { reply->out[newLen++] = '\0'; } @@ -667,7 +707,7 @@ block_list_cli_1_svc(blockListCli *blk, struct svc_req *rqstp) blockResponse *reply; struct glfs *glfs; struct glfs_fd *lkfd = NULL; - struct glfs_fd *tgfd = NULL; + struct glfs_fd *tgmfd = NULL; struct dirent *entry; char *tmp = NULL; char *filelist = NULL; @@ -676,25 +716,26 @@ block_list_cli_1_svc(blockListCli *blk, struct svc_req *rqstp) glfs = glusterBlockVolumeInit(blk->volume, "localhost"); if (!glfs) { - LOG("mgmt", ERROR, "%s", "glusterBlockVolumeInit failed"); + LOG("mgmt", GB_LOG_ERROR, "%s", "glusterBlockVolumeInit failed"); goto out; } - lkfd = glusterBlockCreateMetaLockFile(glfs); + lkfd = glusterBlockCreateMetaLockFile(glfs, blk->volume); if (!lkfd) { - LOG("mgmt", ERROR, "%s", "glusterBlockCreateMetaLockFile failed"); + LOG("mgmt", GB_LOG_ERROR, "%s", + "glusterBlockCreateMetaLockFile failed"); goto out; } - METALOCK(lkfd); + GB_METALOCK_OR_GOTO(lkfd, blk->volume, ret, out); - tgfd = glfs_opendir (glfs, "/block-meta"); - if (!tgfd) { - LOG("mgmt", ERROR, "%s", "glusterBlockVolumeInit failed"); + tgmfd = glfs_opendir (glfs, "/block-meta"); + if (!tgmfd) { + LOG("mgmt", GB_LOG_ERROR, "%s", "glusterBlockVolumeInit failed"); goto out; } - while ((entry = glfs_readdir (tgfd))) { + while ((entry = glfs_readdir (tgmfd))) { if (strcmp(entry->d_name, ".") && strcmp(entry->d_name, "..") && strcmp(entry->d_name, "meta.lock")) { @@ -707,19 +748,21 @@ block_list_cli_1_svc(blockListCli *blk, struct svc_req *rqstp) ret = 0; out: - if (GB_ALLOC(reply) < 0) + if (GB_ALLOC(reply) < 0) { return NULL; + } reply->out = filelist? filelist:strdup("*Nil*\n"); - glfs_closedir (tgfd); + glfs_closedir (tgmfd); - METAUNLOCK(lkfd); + GB_METAUNLOCK(lkfd, blk->volume, ret); reply->exit = ret; - if (glfs_close(lkfd) != 0) - LOG("mgmt", ERROR, "%s", "glfs_close: failed"); + if (glfs_close(lkfd) != 0) { + LOG("mgmt", GB_LOG_ERROR, "%s", "glfs_close: failed"); + } glfs_fini(glfs); @@ -742,31 +785,34 @@ block_info_cli_1_svc(blockInfoCli *blk, struct svc_req *rqstp) glfs = glusterBlockVolumeInit(blk->volume, "localhost"); if (!glfs) { - LOG("mgmt", ERROR, "%s", "glusterBlockVolumeInit failed"); + LOG("mgmt", GB_LOG_ERROR, "%s", "glusterBlockVolumeInit failed"); goto out; } - lkfd = glusterBlockCreateMetaLockFile(glfs); + lkfd = glusterBlockCreateMetaLockFile(glfs, blk->volume); if (!lkfd) { - LOG("mgmt", ERROR, "%s", "glusterBlockCreateMetaLockFile failed"); + LOG("mgmt", GB_LOG_ERROR, "%s", + "glusterBlockCreateMetaLockFile failed"); goto out; } - METALOCK(lkfd); + GB_METALOCK_OR_GOTO(lkfd, blk->volume, ret, out); - if (GB_ALLOC(info) < 0) + if (GB_ALLOC(info) < 0) { goto out; + } ret = blockGetMetaInfo(glfs, blk->block_name, info); - if (ret) + if (ret) { goto out; + } asprintf(&tmp, "NAME: %s\nVOLUME: %s\nGBID: %s\nSIZE: %zu\n" "MULTIPATH: %zu\nBLOCK CONFIG NODE(S):", blk->block_name, info->volume, info->gbid, info->size, info->mpath); for (i = 0; i < info->nhosts; i++) { - if (blockMetaStatusEnumParse(info->list[i]->status) == CONFIGSUCCESS) { + if (blockMetaStatusEnumParse(info->list[i]->status) == GB_CONFIG_SUCCESS) { asprintf(&out, "%s %s", (tmp==NULL?"":tmp), info->list[i]->addr); GB_FREE(tmp); tmp = out; @@ -776,20 +822,23 @@ block_info_cli_1_svc(blockInfoCli *blk, struct svc_req *rqstp) ret = 0; out: - if (GB_ALLOC(reply) < 0) + if (GB_ALLOC(reply) < 0) { return NULL; + } - if (!out) + if (!out) { asprintf(&out, "No Block with name %s", blk->block_name); + } reply->out = out; - METAUNLOCK(lkfd); + GB_METAUNLOCK(lkfd, blk->volume, ret); reply->exit = ret; - if (glfs_close(lkfd) != 0) - LOG("mgmt", ERROR, "%s", "glfs_close: failed"); + if (glfs_close(lkfd) != 0) { + LOG("mgmt", GB_LOG_ERROR, "%s", "glfs_close: failed"); + } glfs_fini(glfs); diff --git a/rpc/block_svc.c b/rpc/block_svc.c index 1a908ea..3722d51 100644 --- a/rpc/block_svc.c +++ b/rpc/block_svc.c @@ -20,9 +20,6 @@ -pthread_t p_thread1, p_thread2; - - static void gluster_block_cli_1(struct svc_req *rqstp, register SVCXPRT *transp) { @@ -134,7 +131,7 @@ gluster_block_1(struct svc_req *rqstp, register SVCXPRT *transp) } void * -cli_thread(void *vargp) +cli_thread_proc (void *vargp) { register SVCXPRT *transp; struct sockaddr_un saun; @@ -173,7 +170,7 @@ cli_thread(void *vargp) } void * -server_thread(void *vargp) +server_thread_proc(void *vargp) { register SVCXPRT *transp; struct sockaddr_in sain; @@ -213,14 +210,18 @@ server_thread(void *vargp) int main (int argc, char **argv) { + pthread_t cli_thread; + pthread_t server_thread; + + pmap_unset (GLUSTER_BLOCK_CLI, GLUSTER_BLOCK_CLI_VERS); pmap_unset (GLUSTER_BLOCK, GLUSTER_BLOCK_VERS); - pthread_create(&p_thread1, NULL, cli_thread, NULL); - pthread_create(&p_thread2, NULL, server_thread, NULL); + pthread_create(&cli_thread, NULL, cli_thread_proc , NULL); + pthread_create(&server_thread, NULL, server_thread_proc , NULL); - pthread_join(p_thread1, NULL); - pthread_join(p_thread2, NULL); + pthread_join(cli_thread, NULL); + pthread_join(server_thread, NULL); fprintf (stderr, "%s", "svc_run returned"); diff --git a/utils.c b/utils.c index c98923c..ee3515f 100644 --- a/utils.c +++ b/utils.c @@ -16,38 +16,40 @@ int blockMetaKeyEnumParse(const char *opt) { - int i; + int i; - if (!opt) { - return METAKEY__MAX; - } - for (i = 0; i < METAKEY__MAX; i++) { - if (!strcmp(opt, MetakeyLookup[i])) { - return i; - } + if (!opt) { + return GB_METAKEY_MAX; + } + + for (i = 0; i < GB_METAKEY_MAX; i++) { + if (!strcmp(opt, MetakeyLookup[i])) { + return i; } + } - return i; + return i; } int blockMetaStatusEnumParse(const char *opt) { - int i; + int i; - if (!opt) { - return METASTATUS__MAX; - } - for (i = 0; i < METASTATUS__MAX; i++) { - if (!strcmp(opt, MetaStatusLookup[i])) { - return i; - } + if (!opt) { + return GB_METASTATUS_MAX; + } + + for (i = 0; i < GB_METASTATUS_MAX; i++) { + if (!strcmp(opt, MetaStatusLookup[i])) { + return i; } + } - return i; + return i; } @@ -56,11 +58,12 @@ gbAlloc(void *ptrptr, size_t size, const char *filename, const char *funcname, size_t linenr) { *(void **)ptrptr = calloc(1, size); + if (*(void **)ptrptr == NULL) { - ERROR("%s", "Error: memory allocation failed"); errno = ENOMEM; return -1; } + return 0; } @@ -70,11 +73,12 @@ gbAllocN(void *ptrptr, size_t size, size_t count, const char *filename, const char *funcname, size_t linenr) { *(void**)ptrptr = calloc(count, size); + if (*(void**)ptrptr == NULL) { - ERROR("%s", "Error: memory allocation failed"); errno = ENOMEM; return -1; } + return 0; } @@ -84,8 +88,9 @@ gbFree(void *ptrptr) { int save_errno = errno; - if(*(void**)ptrptr == NULL) + if(*(void**)ptrptr == NULL) { return; + } free(*(void**)ptrptr); *(void**)ptrptr = NULL; @@ -97,13 +102,15 @@ int gbStrdup(char **dest, const char *src, const char *filename, const char *funcname, size_t linenr) { - *dest = NULL; - if (!src) - return 0; - if (!(*dest = strdup(src))) { - ERROR("%s", "Error: string duplication failed"); - return -1; - } + *dest = NULL; + if (!src) { return 0; + } + + if (!(*dest = strdup(src))) { + return -1; + } + + return 0; } diff --git a/utils.h b/utils.h index 0366b8d..fc088ce 100644 --- a/utils.h +++ b/utils.h @@ -72,39 +72,46 @@ fprintf(fd, "[%lu] %s: " fmt " [at %s+%d :<%s>]\n", \ (unsigned long)time(NULL), LogLevelLookup[level],\ __VA_ARGS__, __FILE__, __LINE__, __FUNCTION__); \ - fclose(fd); \ + if (fd != stderr) \ + fclose(fd); \ } while (0) -# define METALOCK(lkfd) \ +# define GB_METALOCK_OR_GOTO(lkfd, volume, ret, label) \ do { \ struct flock lock = {0, }; \ - memset (&lock, 0, sizeof(lock)); \ lock.l_type = F_WRLCK; \ if (glfs_posix_lock (lkfd, F_SETLKW, &lock)) { \ - LOG("mgmt", ERROR, "%s", "glfs_posix_lock: failed"); \ + LOG("mgmt", GB_LOG_ERROR, "glfs_posix_lock() on " \ + "volume %s failed[%s]", volume, strerror(errno)); \ ret = -1; \ - goto out; \ + goto label; \ } \ } while (0) -# define METAUPDATE(a, ...) \ +# define GB_METAUPDATE_OR_GOTO(tgmfd, fname, volume, ret, label,...)\ do { \ char *write; \ - asprintf(&write, __VA_ARGS__); \ - if(glfs_write (a, write, strlen(write), 0) < 0) { \ - LOG("mgmt", ERROR, "%s", "glfs_write: failed"); \ + if (asprintf(&write, __VA_ARGS__) < 0) { \ ret = -1; \ - goto out; \ + goto label; \ + } \ + if(glfs_write (tgmfd, write, strlen(write), 0) < 0) { \ + LOG("mgmt", GB_LOG_ERROR, "glfs_write(%s): on " \ + "volume %s failed[%s]", fname, volume, \ + strerror(errno)); \ + ret = -1; \ + goto label; \ } \ GB_FREE(write); \ } while (0) -# define METAUNLOCK(lkfd) \ +# define GB_METAUNLOCK(lkfd, volume, ret) \ do { \ struct flock lock = {0, }; \ lock.l_type = F_UNLCK; \ - if (glfs_posix_lock(lkfd, F_SETLKW, &lock)) { \ - LOG("mgmt", ERROR, "%s", "glfs_posix_lock: failed"); \ + if (glfs_posix_lock(lkfd, F_SETLK, &lock)) { \ + LOG("mgmt", GB_LOG_ERROR, "glfs_posix_lock() on " \ + "volume %s failed[%s]", volume, strerror(errno)); \ ret = -1; \ } \ } while (0) @@ -130,74 +137,77 @@ typedef enum LogLevel { - NONE = 0, - EMERGENCY = 1, - ALERT = 2, - CRITICAL = 3, - ERROR = 4, - WARNING = 5, - NOTICE = 6, - INFO = 7, - DEBUG = 8, - TRACE = 9, - - LOGLEVEL__MAX = 10 /* Updata this when add new level */ + GB_LOG_NONE = 0, + GB_LOG_EMERGENCY = 1, + GB_LOG_ALERT = 2, + GB_LOG_CRITICAL = 3, + GB_LOG_ERROR = 4, + GB_LOG_WARNING = 5, + GB_LOG_NOTICE = 6, + GB_LOG_INFO = 7, + GB_LOG_DEBUG = 8, + GB_LOG_TRACE = 9, + + GB_LOG_MAX } LogLevel; static const char *const LogLevelLookup[] = { - [NONE] = "NONE", - [EMERGENCY] = "EMERGENCY", - [ALERT] = "ALERT", - [CRITICAL] = "CRITICAL", - [ERROR] = "ERROR", - [WARNING] = "WARNING", - [NOTICE] = "NOTICE", - [INFO] = "INFO", - [DEBUG] = "DEBUG", - [TRACE] = "TRACE", - - [LOGLEVEL__MAX] = NULL, + [GB_LOG_NONE] = "NONE", + [GB_LOG_EMERGENCY] = "EMERGENCY", + [GB_LOG_ALERT] = "ALERT", + [GB_LOG_CRITICAL] = "CRITICAL", + [GB_LOG_ERROR] = "ERROR", + [GB_LOG_WARNING] = "WARNING", + [GB_LOG_NOTICE] = "NOTICE", + [GB_LOG_INFO] = "INFO", + [GB_LOG_DEBUG] = "DEBUG", + [GB_LOG_TRACE] = "TRACE", + + [GB_LOG_MAX] = NULL, }; typedef enum Metakey { - VOLUME = 0, - GBID = 1, - SIZE = 2, - HA = 3, - ENTRYCREATE = 4, - - METAKEY__MAX = 5 /* Updata this when add new Key */ + GB_META_INVALID = 0, + GB_META_VOLUME = 1, + GB_META_GBID = 2, + GB_META_SIZE = 3, + GB_META_HA = 4, + GB_META_ENTRYCREATE = 5, + + GB_METAKEY_MAX } Metakey; static const char *const MetakeyLookup[] = { - [VOLUME] = "VOLUME", - [GBID] = "GBID", - [SIZE] = "SIZE", - [HA] = "HA", - [ENTRYCREATE] = "ENTRYCREATE", - [METAKEY__MAX] = NULL, + [GB_META_INVALID] = NULL, + [GB_META_VOLUME] = "VOLUME", + [GB_META_GBID] = "GBID", + [GB_META_SIZE] = "SIZE", + [GB_META_HA] = "HA", + [GB_META_ENTRYCREATE] = "ENTRYCREATE", + + [GB_METAKEY_MAX] = NULL }; typedef enum MetaStatus { - CONFIGSUCCESS = 0, - CONFIGFAIL = 1, - CONFIGINPROGRESS = 2, - CLEANUPSUCCESS = 3, - CLEANUPFAIL = 4, - CLEANUPINPROGRES = 5, - - METASTATUS__MAX = 6 /* Updata this when add new Status type */ + GB_CONFIG_SUCCESS = 0, + GB_CONFIG_FAIL = 1, + GB_CONFIG_INPROGRESS = 2, + GB_CLEANUP_SUCCESS = 3, + GB_CLEANUP_FAIL = 4, + GB_CLEANUP_INPROGRES = 5, + + GB_METASTATUS_MAX } MetaStatus; static const char *const MetaStatusLookup[] = { - [CONFIGINPROGRESS] = "CONFIGINPROGRESS", - [CONFIGSUCCESS] = "CONFIGSUCCESS", - [CONFIGFAIL] = "CONFIGFAIL", - [CLEANUPINPROGRES] = "CLEANUPINPROGRESS", - [CLEANUPSUCCESS] = "CLEANUPSUCCESS", - [CLEANUPFAIL] = "CLEANUPFAIL", - - [METASTATUS__MAX] = NULL, + [GB_CONFIG_SUCCESS] = "CONFIGSUCCESS", + [GB_CONFIG_FAIL] = "CONFIGFAIL", + [GB_CONFIG_INPROGRESS] = "CONFIGINPROGRESS", + [GB_CLEANUP_INPROGRES] = "CLEANUPINPROGRESS", + [GB_CLEANUP_SUCCESS] = "CLEANUPSUCCESS", + [GB_CLEANUP_FAIL] = "CLEANUPFAIL", + + [GB_METASTATUS_MAX] = NULL, }; -- cgit