summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPrasanna Kumar Kalever <prasanna.kalever@redhat.com>2017-01-30 14:52:04 +0530
committerPrasanna Kumar Kalever <prasanna.kalever@redhat.com>2017-01-30 19:31:50 +0530
commitff74a2144e02af11373375f8d40e9b312a0dd0c6 (patch)
treeafc7d16d2d5fc1e2a562467dd619beb65712c5dc
parent46e546b65a717fcf9a17d905152e861d05a4a9be (diff)
gluster-block: walk through the cleanups
better naming of variables and functions, variable initialization, also fix few leaks Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
-rw-r--r--Makefile17
-rw-r--r--common.h2
-rw-r--r--glfs-operations.c17
-rw-r--r--gluster-block.c136
-rw-r--r--gluster-blockd.c463
-rw-r--r--utils.c4
-rw-r--r--utils.h145
7 files changed, 427 insertions, 357 deletions
diff --git a/Makefile b/Makefile
index e37b737..cb9e5a2 100644
--- a/Makefile
+++ b/Makefile
@@ -10,13 +10,16 @@
# #
########################################################################
+
CC = gcc
+COMMON = utils.o common.o rpc/block_xdr.o
+
CLIENT = gluster-block
-CDEP = glfs-operations.o utils.o common.o rpc/block_clnt.c rpc/block_xdr.c gluster-block.o
+CDEP = rpc/block_clnt.o gluster-block.o
SERVER = gluster-blockd
-SDEP = rpc/block_svc.o rpc/block_clnt.c rpc/block_xdr.o gluster-blockd.o utils.o common.o glfs-operations.o
+SDEP = glfs-operations.o rpc/block_svc.o rpc/block_clnt.o gluster-blockd.o
CFLAGS = -g -ggdb -Wall -lpthread
LIBS := $(shell pkg-config --libs uuid glusterfs-api)
@@ -28,16 +31,16 @@ MKDIR_P = mkdir -p
INSTALL = /usr/bin/install -c
INSTALLDATA = /usr/bin/install -c -m 644
SYSTEMD_DIR = /usr/lib/systemd/system
-LOGDIR = /var/log/
+LOGDIR = /var/log/gluster-block
-all: $(CLIENT) $(SERVER)
+all: $(SERVER) $(CLIENT)
-$(CLIENT): $(CDEP)
+$(CLIENT): $(CDEP) $(COMMON)
@$(MKDIR_P) $(LOGDIR)$@
$(CC) $(CFLAGS) $(LIBS) $^ -o $@
-$(SERVER): $(SDEP)
+$(SERVER): $(SDEP) $(COMMON)
$(CC) $(CFLAGS) $(LIBS) $^ -o $@
glfs-operations.o: glfs-operations.c glfs-operations.h
@@ -51,7 +54,7 @@ glfs-operations.o: glfs-operations.c glfs-operations.h
$(CLIENT).o: $(CLIENT).c
$(CC) $(CFLAGS) -c $< -o $@
-install: $(CLIENT) $(SERVER)
+install: $(SERVER) $(CLIENT)
$(INSTALL) $^ $(PREFIX)/
@if [ -d $(SYSTEMD_DIR) ]; then \
$(MKDIR_P) $(SYSTEMD_DIR); \
diff --git a/common.h b/common.h
index 4698348..d24a490 100644
--- a/common.h
+++ b/common.h
@@ -21,7 +21,7 @@
# define GFAPI_LOG_LEVEL 7
-size_t glusterBlockCreateParseSize(char *value);
+size_t glusterBlockCreateParseSize(char *value);
# endif /* _COMMON_H */
diff --git a/glfs-operations.c b/glfs-operations.c
index 251c73b..dba924e 100644
--- a/glfs-operations.c
+++ b/glfs-operations.c
@@ -12,13 +12,16 @@
# include "common.h"
# include "glfs-operations.h"
+# define METADIR "/block-meta"
+# define TXLOCKFILE "meta.lock"
+
struct glfs *
glusterBlockVolumeInit(char *volume, char *volfileserver)
{
struct glfs *glfs;
- int ret = 0;
+ int ret;
glfs = glfs_new(volume);
if (!glfs) {
@@ -48,6 +51,7 @@ glusterBlockVolumeInit(char *volume, char *volfileserver)
out:
glfs_fini(glfs);
+
return NULL;
}
@@ -70,7 +74,6 @@ glusterBlockCreateEntry(blockCreateCli *blk, char *gbid)
S_IRUSR | S_IWUSR);
if (!fd) {
LOG("gfapi", ERROR, "%s", "glfs_creat: failed");
- ret = -errno;
} else {
ret = glfs_ftruncate(fd, blk->size);
if (ret) {
@@ -80,7 +83,6 @@ glusterBlockCreateEntry(blockCreateCli *blk, char *gbid)
if (glfs_close(fd) != 0) {
LOG("gfapi", ERROR, "%s", "glfs_close: failed");
- ret = -errno;
}
}
@@ -120,19 +122,19 @@ glusterBlockCreateMetaLockFile(struct glfs *glfs)
struct glfs_fd *lkfd;
int ret;
- ret = glfs_mkdir (glfs, "/block-meta", 0);
+ ret = glfs_mkdir (glfs, METADIR, 0);
if (ret && errno != EEXIST) {
LOG("gfapi", ERROR, "%s", "glfs_mkdir: failed");
goto out;
}
- ret = glfs_chdir (glfs, "/block-meta");
+ ret = glfs_chdir (glfs, METADIR);
if (ret) {
LOG("gfapi", ERROR, "%s", "glfs_chdir: failed");
goto out;
}
- lkfd = glfs_creat(glfs, "meta.lock", O_RDWR, S_IRUSR | S_IWUSR);
+ lkfd = glfs_creat(glfs, TXLOCKFILE, O_RDWR, S_IRUSR | S_IWUSR);
if (!lkfd) {
LOG("gfapi", ERROR, "%s", "glfs_creat: failed");
goto out;
@@ -150,6 +152,9 @@ blockFreeMetaInfo(MetaInfo *info)
{
int i;
+ if (!info)
+ return;
+
for (i = 0; i< info->nhosts; i++)
GB_FREE(info->list[i]);
diff --git a/gluster-block.c b/gluster-block.c
index 4b89997..3a3cab7 100644
--- a/gluster-block.c
+++ b/gluster-block.c
@@ -11,38 +11,41 @@
# define _GNU_SOURCE /* See feature_test_macros(7) */
+# include <unistd.h>
# include <getopt.h>
# include "common.h"
# include "rpc/block.h"
-# define LIST "list"
-# define CREATE "create"
-# define DELETE "delete"
-# define INFO "info"
-# define MODIFY "modify"
-# define BLOCKHOST "block-host"
-# define VOLUME "volume"
-# define HELP "help"
+# define LIST "list"
+# define CREATE "create"
+# define DELETE "delete"
+# define INFO "info"
+# define MODIFY "modify"
+# define BLOCKHOST "block-host"
+# define VOLUME "volume"
+# define HELP "help"
-typedef enum opterations {
+
+typedef enum operations {
CREATE_CLI = 1,
LIST_CLI = 2,
INFO_CLI = 3,
DELETE_CLI = 4
-} opterations;
+} operations;
static int
-gluster_block_cli_1(void *cobj, opterations opt, char **out)
+glusterBlockCliRPC_1(void *cobj, operations opt, char **out)
{
- CLIENT *clnt;
- int sockfd, len;
+ CLIENT *clnt = NULL;
int ret = -1;
+ int sockfd;
struct sockaddr_un saun;
- blockResponse *reply = NULL;
+ blockResponse *reply;
+
if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
LOG("cli", ERROR, "socket creation failed (%s)", strerror (errno));
@@ -52,60 +55,64 @@ gluster_block_cli_1(void *cobj, opterations opt, char **out)
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) {
+ if (connect(sockfd, (struct sockaddr *) &saun,
+ sizeof(struct sockaddr_un)) < 0) {
LOG("cli", ERROR, "connect failed (%s)", strerror (errno));
goto out;
}
- clnt = clntunix_create ((struct sockaddr_un *) &saun, GLUSTER_BLOCK_CLI, GLUSTER_BLOCK_CLI_VERS, &sockfd, 0, 0);
- if (clnt == NULL) {
+ clnt = clntunix_create ((struct sockaddr_un *) &saun,
+ GLUSTER_BLOCK_CLI, GLUSTER_BLOCK_CLI_VERS,
+ &sockfd, 0, 0);
+ if (!clnt) {
LOG("cli", ERROR, "%s, unix addr %s",
clnt_spcreateerror("client create failed"), ADDRESS);
+ goto out;
}
+
switch(opt) {
case CREATE_CLI:
reply = block_create_cli_1((blockCreateCli *)cobj, clnt);
- if (reply == NULL) {
+ if (!reply) {
LOG("cli", ERROR, "%s", clnt_sperror(clnt, "block create failed"));
goto out;
}
break;
case DELETE_CLI:
reply = block_delete_cli_1((blockDeleteCli *)cobj, clnt);
- if (reply == NULL) {
+ if (!reply) {
LOG("cli", ERROR, "%s", clnt_sperror(clnt, "block delete failed"));
goto out;
}
break;
case INFO_CLI:
reply = block_info_cli_1((blockInfoCli *)cobj, clnt);
- if (reply == NULL) {
+ if (!reply) {
LOG("cli", ERROR, "%s", clnt_sperror(clnt, "block info failed"));
goto out;
}
break;
case LIST_CLI:
reply = block_list_cli_1((blockListCli *)cobj, clnt);
- if (reply == NULL) {
+ if (!reply) {
LOG("cli", ERROR, "%s", clnt_sperror(clnt, "block list failed"));
goto out;
}
break;
}
- if (GB_STRDUP(*out, reply->out) < 0) {
- ret = -1;
+ if (GB_STRDUP(*out, reply->out) < 0)
goto out;
- }
ret = reply->exit;
-out:
- if (!clnt_freeres(clnt, (xdrproc_t) xdr_blockResponse, (char *) reply))
- LOG("cli", ERROR, "%s", clnt_sperror (clnt, "clnt_freeres failed"));
+ out:
+ if (!clnt_freeres(clnt, (xdrproc_t)xdr_blockResponse, (char *)reply))
+ LOG("cli", ERROR, "%s", clnt_sperror(clnt, "clnt_freeres failed"));
+
+ if (clnt)
+ clnt_destroy (clnt);
- clnt_destroy (clnt);
+ close(sockfd);
return ret;
}
@@ -137,10 +144,12 @@ glusterBlockHelp(void)
static int
glusterBlockCreate(int count, char **options, char *name)
{
- int c;
int ret = 0;
+ int optchar;
+ int option_index = 0;
char *out = NULL;
- static blockCreateCli cobj;
+ static blockCreateCli cobj = {0, };
+
if (!name) {
LOG("cli", ERROR, "%s", "Insufficient arguments supplied for"
@@ -161,24 +170,24 @@ glusterBlockCreate(int count, char **options, char *name)
{0, 0, 0, 0}
};
- /* getopt_long stores the option index here. */
- int option_index = 0;
-
- c = getopt_long(count, options, "b:v:h:s:",
+ optchar = getopt_long(count, options, "b:v:h:s:",
long_options, &option_index);
- if (c == -1)
+ if (optchar == -1)
break;
- switch (c) {
+ switch (optchar) {
case 'm':
sscanf(optarg, "%u", &cobj.mpath);
ret++;
break;
case 'b':
- if (GB_STRDUP(cobj.block_hosts, optarg) < 0)
- return -1;
+ if (GB_STRDUP(cobj.block_hosts, optarg) < 0) {
+ LOG("cli", ERROR, "%s", "failed while parsing size");
+ ret = -1;
+ goto out;
+ }
ret++;
break;
@@ -216,25 +225,25 @@ glusterBlockCreate(int count, char **options, char *name)
if (optind < count) {
LOG("cli", ERROR, "%s", "non-option ARGV-elements: ");
while (optind < count)
- printf("%s ", options[optind++]);
+ MSG("provided options: %s", options[optind++]);
putchar('\n');
-
+ MSG("Hint: %s --help\n", options[0]);
ret = -1;
goto out;
}
if (ret != 5) {
LOG("cli", ERROR, "%s", "Insufficient arguments supplied for"
- "'gluster-block create'\n");
+ "'gluster-block create'\n");
ret = -1;
goto out;
}
- ret = gluster_block_cli_1(&cobj, CREATE_CLI, &out);
+ ret = glusterBlockCliRPC_1(&cobj, CREATE_CLI, &out);
MSG("%s", out);
- out:
+ out:
GB_FREE(cobj.block_hosts);
GB_FREE(out);
@@ -249,9 +258,10 @@ glusterBlockList(char *volume)
char *out = NULL;
int ret = -1;
+
strcpy(cobj.volume, volume);
- ret = gluster_block_cli_1(&cobj, LIST_CLI, &out);
+ ret = glusterBlockCliRPC_1(&cobj, LIST_CLI, &out);
MSG("%s", out);
GB_FREE(out);
@@ -267,10 +277,11 @@ glusterBlockDelete(char* name, char* volume)
char *out = NULL;
int ret = -1;
+
strcpy(cobj.block_name, name);
strcpy(cobj.volume, volume);
- ret = gluster_block_cli_1(&cobj, DELETE_CLI, &out);
+ ret = glusterBlockCliRPC_1(&cobj, DELETE_CLI, &out);
MSG("%s", out);
GB_FREE(out);
@@ -286,10 +297,11 @@ glusterBlockInfo(char* name, char* volume)
char *out = NULL;
int ret = -1;
+
strcpy(cobj.block_name, name);
strcpy(cobj.volume, volume);
- ret = gluster_block_cli_1(&cobj, INFO_CLI, &out);
+ ret = glusterBlockCliRPC_1(&cobj, INFO_CLI, &out);
MSG("%s", out);
GB_FREE(out);
@@ -301,12 +313,13 @@ glusterBlockInfo(char* name, char* volume)
static int
glusterBlockParseArgs(int count, char **options)
{
- int c;
+ int optchar;
int ret = 0;
int optFlag = 0;
- char *block = NULL;
+ char *blockname = NULL;
char *volume = NULL;
+
while (1) {
static const struct option long_options[] = {
{HELP, no_argument, 0, 'h'},
@@ -322,14 +335,14 @@ glusterBlockParseArgs(int count, char **options)
/* getopt_long stores the option index here. */
int option_index = 0;
- c = getopt_long(count, options, "hc:b:d:lim:",
+ optchar = getopt_long(count, options, "hc:b:d:lim:",
long_options, &option_index);
/* Detect the end of the options. */
- if (c == -1)
+ if (optchar == -1)
break;
- switch (c) {
+ switch (optchar) {
case 'v':
volume = optarg;
break;
@@ -345,10 +358,10 @@ glusterBlockParseArgs(int count, char **options)
case 'l':
case 'd':
case 'i':
- if (optFlag) /* more than one main opterations ?*/
+ if (optFlag) /* more than one main operations ? */
goto out;
- optFlag = c;
- block = optarg;
+ optFlag = optchar;
+ blockname = optarg;
break;
case 'm':
@@ -372,12 +385,12 @@ glusterBlockParseArgs(int count, char **options)
LOG("cli", ERROR, "%s", FAILED_LIST);
break;
case 'i':
- ret = glusterBlockInfo(block, volume);
+ ret = glusterBlockInfo(blockname, volume);
if (ret)
LOG("cli", ERROR, "%s", FAILED_INFO);
break;
case 'd':
- ret = glusterBlockDelete(block, volume);
+ ret = glusterBlockDelete(blockname, volume);
if (ret)
LOG("cli", ERROR, "%s", FAILED_DELETE);
break;
@@ -387,7 +400,7 @@ glusterBlockParseArgs(int count, char **options)
if (ret == 0 && optind < count) {
LOG("cli", ERROR, "%s", "Unable to parse elements: ");
while (optind < count)
- printf("%s ", options[optind++]);
+ MSG("provided options: %s", options[optind++]);
putchar('\n');
MSG("Hint: %s --help\n", options[0]);
}
@@ -399,11 +412,8 @@ glusterBlockParseArgs(int count, char **options)
int
main(int argc, char *argv[])
{
- int ret;
if (argc <= 1)
glusterBlockHelp();
- ret = glusterBlockParseArgs(argc, argv);
-
- return ret;
+ return glusterBlockParseArgs(argc, argv);
}
diff --git a/gluster-blockd.c b/gluster-blockd.c
index e9ed6e7..1f75f41 100644
--- a/gluster-blockd.c
+++ b/gluster-blockd.c
@@ -8,6 +8,7 @@
cases as published by the Free Software Foundation.
*/
+
# define _GNU_SOURCE /* See feature_test_macros(7) */
# include <stdio.h>
@@ -42,36 +43,39 @@ typedef struct blockServerDef {
} blockServerDef;
typedef blockServerDef *blockServerDefPtr;
-typedef enum opterations {
+typedef enum operations {
CREATE_SRV = 1,
DELETE_SRV = 2,
-} opterations;
+} operations;
static int
-gluster_block_1(char *host, void *cobj, opterations opt, char **out)
+glusterBlockCallRPC_1(char *host, void *cobj,
+ operations opt, char **out)
{
- CLIENT *clnt;
- int sockfd;
+ CLIENT *clnt = NULL;
int ret = -1;
- blockResponse *reply = NULL;
+ int sockfd;
+ blockResponse *reply;
struct hostent *server;
struct sockaddr_in sain;
+
if ((sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
LOG("mgmt", ERROR, "socket creation failed (%s)", strerror (errno));
goto out;
}
server = gethostbyname(host);
- if (server == NULL) {
+ if (!server) {
LOG("mgmt", ERROR, "gethostbyname failed (%s)", strerror (errno));
goto out;
}
bzero((char *) &sain, sizeof(sain));
sain.sin_family = AF_INET;
- bcopy((char *)server->h_addr, (char *)&sain.sin_addr.s_addr, server->h_length);
+ bcopy((char *)server->h_addr, (char *)&sain.sin_addr.s_addr,
+ server->h_length);
sain.sin_port = htons(24006);
if (connect(sockfd, (struct sockaddr *) &sain, sizeof(sain)) < 0) {
@@ -79,8 +83,9 @@ gluster_block_1(char *host, void *cobj, opterations opt, char **out)
goto out;
}
- clnt = clnttcp_create ((struct sockaddr_in *) &sain, GLUSTER_BLOCK, GLUSTER_BLOCK_VERS, &sockfd, 0, 0);
- if (clnt == NULL) {
+ clnt = clnttcp_create ((struct sockaddr_in *) &sain, GLUSTER_BLOCK,
+ GLUSTER_BLOCK_VERS, &sockfd, 0, 0);
+ if (!clnt) {
LOG("mgmt", ERROR, "%s, inet host %s",
clnt_spcreateerror("client create failed"), host);
goto out;
@@ -89,31 +94,32 @@ gluster_block_1(char *host, void *cobj, opterations opt, char **out)
switch(opt) {
case CREATE_SRV:
reply = block_create_1((blockCreate *)cobj, clnt);
- if (reply == NULL) {
+ if (!reply) {
LOG("mgmt", ERROR, "%s", clnt_sperror(clnt, "block create failed"));
goto out;
}
break;
case DELETE_SRV:
reply = block_delete_1((blockDelete *)cobj, clnt);
- if (reply == NULL) {
- LOG("mgmt", ERROR, "%s", clnt_sperror (clnt, "block delete failed"));
+ if (!reply) {
+ LOG("mgmt", ERROR, "%s", clnt_sperror(clnt, "block delete failed"));
goto out;
}
break;
}
- if (GB_STRDUP(*out, reply->out) < 0) {
- ret = -1;
+ 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", ERROR, "%s", clnt_sperror(clnt, "clnt_freeres failed"));
- clnt_destroy (clnt);
+ if (clnt)
+ clnt_destroy (clnt);
+
+ close(sockfd);
return ret;
}
@@ -124,6 +130,7 @@ blockServerDefFree(blockServerDefPtr blkServers)
{
size_t i;
+
if (!blkServers)
return;
@@ -141,6 +148,7 @@ blockServerParse(char *blkServers)
char *tmp = blkServers;
size_t i = 0;
+
if (GB_ALLOC(list) < 0)
return NULL;
@@ -167,159 +175,156 @@ blockServerParse(char *blkServers)
return list;
-fail:
+ fail:
blockServerDefFree(list);
return NULL;
}
-static int
-block_create_remote(struct glfs_fd *tgfd, blockCreate *cobj, char *addr, char **reply)
+static void
+glusterBlockCreateRemote(struct glfs_fd *tgfd, blockCreate *cobj,
+ char *addr, char **reply)
{
- char *write = NULL;
+ int ret = -1;
char *out = NULL;
char *tmp = *reply;
- int ret;
-
- METAUPDATE(tgfd, write, "%s: CONFIGINPROGRESS\n", addr);
- ret = gluster_block_1(addr, cobj, CREATE_SRV, &out);
- if (ret) {
- METAUPDATE(tgfd, write, "%s: CONFIGFAIL\n", addr);
- LOG("mgmt", ERROR, "%s on host: %s", FAILED_CREATE, addr);
- *reply = out;
- goto out;
- }
+ METAUPDATE(tgfd, "%s: CONFIGINPROGRESS\n", addr);
- METAUPDATE(tgfd, write, "%s: CONFIGSUCCESS\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);
+ goto out;
+ }
- asprintf(reply, "%s%s\n", (tmp==NULL?"":tmp), out);
- if (tmp)
- GB_FREE(tmp);
- tmp = *reply;
- GB_FREE(out);
+ METAUPDATE(tgfd, "%s: CONFIGSUCCESS\n", addr);
out:
- return ret;
+ asprintf(reply, "%s%s\n", (tmp==NULL?"":tmp), out);
+ GB_FREE(tmp);
+ GB_FREE(out);
}
static int
-block_cross_check_request(struct glfs *glfs,
- struct glfs_fd *tgfd,
- blockCreateCli *blk,
- blockCreate *cobj,
- blockServerDefPtr list,
- char **reply)
+glusterBlockAuditRequest(struct glfs *glfs,
+ struct glfs_fd *tgfd,
+ blockCreateCli *blk,
+ blockCreate *cobj,
+ blockServerDefPtr list,
+ char **reply)
{
- MetaInfo *info;
- size_t success_count = 0;
- size_t fail_count = 0;
+ int ret = -1;
+ size_t i;
+ size_t successcnt = 0;
+ size_t failcnt = 0;
size_t spent;
size_t spare;
size_t morereq;
- size_t i;
- int ret;
+ MetaInfo *info;
+
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:
- success_count++;
+ successcnt++;
break;
case CONFIGINPROGRESS:
case CONFIGFAIL:
- fail_count++;
+ failcnt++;
}
}
/* check if mpath is satisfied */
- if(blk->mpath == success_count) {
- return 0;
+ if (blk->mpath == successcnt) {
+ ret = 0;
+ goto out;
} else {
- spent = success_count + fail_count; /* total spent */
+ spent = successcnt + failcnt; /* total spent */
spare = list->nhosts - spent; /* spare after spent */
- morereq = blk->mpath - success_count; /* needed nodes to complete req */
+ morereq = blk->mpath - successcnt; /* needed nodes to complete req */
if (spare == 0) {
- LOG("mgmt", WARNING, "%s", "No Spare nodes: rewining the creation of target");
- return -1;
+ LOG("mgmt", WARNING, "%s",
+ "No Spare nodes: rewining the creation of target");
+ ret = -1;
+ goto out;
} else if (spare < morereq) {
- LOG("mgmt", WARNING, "%s", "Not enough Spare nodes: rewining the creation of target");
- return -1;
+ LOG("mgmt", WARNING, "%s",
+ "Not enough Spare nodes: rewining the creation of target");
+ ret = -1;
+ goto out;
} else {
/* create on spare */
- LOG("mgmt", INFO, "%s", "trying to serve the mpath from spare machines");
- for(i = spent; i < list->nhosts; i++) {
- block_create_remote(tgfd, cobj, list->hosts[i], reply);
+ LOG("mgmt", INFO, "%s",
+ "trying to serve the mpath from spare machines");
+ for (i = spent; i < list->nhosts; i++) {
+ glusterBlockCreateRemote(tgfd, cobj, list->hosts[i], reply);
}
}
}
- blockFreeMetaInfo(info);
- ret = block_cross_check_request(glfs, tgfd, blk, cobj, list, reply);
+ ret = glusterBlockAuditRequest(glfs, tgfd, blk, cobj, list, reply);
out:
+ blockFreeMetaInfo(info);
return ret;
}
-static int
-block_delete_remote(struct glfs_fd *tgfd, blockDelete *cobj, char *addr, char **reply)
+static void
+glusterBlockDeleteRemote(struct glfs_fd *tgfd, blockDelete *cobj,
+ char *addr, char **reply)
{
- char *write = NULL;
+ int ret = -1;
char *out = NULL;
char *tmp = *reply;
- int ret;
- METAUPDATE(tgfd, write, "%s: CLEANUPINPROGRES\n", addr);
- ret = gluster_block_1(addr, cobj, DELETE_SRV, &out);
+
+ METAUPDATE(tgfd, "%s: CLEANUPINPROGRES\n", addr);
+ ret = glusterBlockCallRPC_1(addr, cobj, DELETE_SRV, &out);
if (ret) {
- METAUPDATE(tgfd, write, "%s: CLEANUPFAIL\n", addr);
+ METAUPDATE(tgfd, "%s: CLEANUPFAIL\n", addr);
LOG("mgmt", ERROR, "%s on host: %s",
FAILED_GATHERING_INFO, addr);
goto out;
}
- METAUPDATE(tgfd, write, "%s: CLEANUPSUCCESS\n", addr);
+ METAUPDATE(tgfd, "%s: CLEANUPSUCCESS\n", addr);
+ out:
asprintf(reply, "%s%s\n", (tmp==NULL?"":tmp), out);
- if (tmp)
- GB_FREE(tmp);
- tmp = *reply;
+ GB_FREE(tmp);
GB_FREE(out);
-
- out:
- return ret;
}
static int
-blockCleanUp(struct glfs *glfs, char *blockname,
- bool deleteall, char **reply)
+glusterBlockCleanUp(struct glfs *glfs, char *blockname,
+ bool deleteall, char **reply)
{
- MetaInfo *info = NULL;
int ret = -1;
- static blockDelete *cobj;
- size_t i = 0;
- struct glfs_fd *tgfd;
- size_t cleanup_success = 0;
+ size_t i;
+ static blockDelete cobj;
+ struct glfs_fd *tgfd = NULL;
+ size_t cleanupsuccess = 0;
+ MetaInfo *info;
-if (GB_ALLOC(info) < 0)
- goto out;
- ret = blockGetMetaInfo(glfs, blockname, info);
- if(ret)
+ if (GB_ALLOC(info) < 0)
goto out;
- if(GB_ALLOC(cobj) < 0)
+ ret = blockGetMetaInfo(glfs, blockname, info);
+ if (ret)
goto out;
- strcpy(cobj->block_name, blockname);
- strcpy(cobj->gbid, info->gbid);
+ strcpy(cobj.block_name, blockname);
+ strcpy(cobj.gbid, info->gbid);
tgfd = glfs_open(glfs, blockname, O_WRONLY|O_APPEND);
if (!tgfd) {
@@ -333,12 +338,14 @@ if (GB_ALLOC(info) < 0)
case CLEANUPFAIL:
case CONFIGFAIL:
case CONFIGINPROGRESS:
- ret = block_delete_remote(tgfd, cobj, info->list[i]->addr, reply);
+ glusterBlockDeleteRemote(tgfd, &cobj,
+ info->list[i]->addr, reply);
break;
}
- if(deleteall &&
- blockMetaStatusEnumParse(info->list[i]->status) == CONFIGSUCCESS) {
- ret = block_delete_remote(tgfd, cobj, info->list[i]->addr, reply);
+ if (deleteall &&
+ blockMetaStatusEnumParse(info->list[i]->status) == CONFIGSUCCESS) {
+ glusterBlockDeleteRemote(tgfd, &cobj,
+ info->list[i]->addr, reply);
}
}
blockFreeMetaInfo(info);
@@ -347,18 +354,18 @@ if (GB_ALLOC(info) < 0)
goto out;
ret = blockGetMetaInfo(glfs, blockname, info);
- if(ret)
+ if (ret)
goto out;
for (i = 0; i < info->nhosts; i++) {
- if(blockMetaStatusEnumParse(info->list[i]->status) == CLEANUPSUCCESS)
- cleanup_success++;
+ if (blockMetaStatusEnumParse(info->list[i]->status) == CLEANUPSUCCESS)
+ cleanupsuccess++;
}
- if( cleanup_success == info->nhosts) {
+ if (cleanupsuccess == info->nhosts) {
if (glusterBlockDeleteEntry(info->volume, info->gbid)) {
LOG("mgmt", ERROR, "%s volume: %s host: %s",
- FAILED_DELETING_FILE, info->volume, "localhost");
+ FAILED_DELETING_FILE, info->volume, "localhost");
}
ret = glfs_unlink(glfs, blockname);
if (ret && errno != ENOENT) {
@@ -373,7 +380,6 @@ if (GB_ALLOC(info) < 0)
if (glfs_close(tgfd) != 0) {
LOG("mgmt", ERROR, "%s", "glfs_close: failed");
}
- GB_FREE(cobj);
return ret;
}
@@ -383,18 +389,33 @@ blockResponse *
block_create_cli_1_svc(blockCreateCli *blk, struct svc_req *rqstp)
{
int ret = -1;
- size_t i = 0;
- char *savereply = NULL;
+ size_t i;
uuid_t uuid;
- static blockCreate *cobj;
- static blockResponse *reply = NULL;
- blockServerDefPtr list = NULL;
- char *gbid = CALLOC(UUID_BUF_SIZE);
- struct glfs *glfs = NULL;
- struct glfs_fd *lkfd;
+ char *savereply = NULL;
+ char gbid[UUID_BUF_SIZE];
+ static blockCreate cobj;
+ static blockResponse *reply;
+ struct glfs *glfs;
+ struct glfs_fd *lkfd = NULL;
struct glfs_fd *tgfd = NULL;
- struct flock lock = {0, };
- char *write = NULL;
+ blockServerDefPtr list = NULL;
+
+
+ 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);
+ asprintf(&reply->out, "multipath req: %d > block-hosts: %s\n",
+ blk->mpath, blk->block_hosts);
+ reply->exit = ENODEV;
+ goto optfail;
+ }
glfs = glusterBlockVolumeInit(blk->volume, blk->volfileserver);
if (!glfs) {
@@ -408,15 +429,13 @@ block_create_cli_1_svc(blockCreateCli *blk, struct svc_req *rqstp)
goto out;
}
- METALOCK(lock, lkfd);
-
- uuid_generate(uuid);
- uuid_unparse(uuid, gbid);
+ METALOCK(lkfd);
if (!glfs_access(glfs, blk->block_name, F_OK)) {
- GB_STRDUP(reply->out, "BLOCK Already EXIST");
- reply->exit = EEXIST;
- goto out;
+ asprintf(&reply->out, "BLOCK with name: '%s' already EXIST\n",
+ blk->block_name);
+ ret = EEXIST;
+ goto exist;
}
tgfd = glfs_creat(glfs, blk->block_name, O_RDWR, S_IRUSR | S_IWUSR);
@@ -425,61 +444,61 @@ block_create_cli_1_svc(blockCreateCli *blk, struct svc_req *rqstp)
goto out;
}
- METAUPDATE(tgfd, write, "VOLUME: %s\n"
+ 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);
ret = glusterBlockCreateEntry(blk, gbid);
if (ret) {
- METAUPDATE(tgfd, write, "ENTRYCREATE: FAIL\n");
+ METAUPDATE(tgfd, "ENTRYCREATE: FAIL\n");
LOG("mgmt", ERROR, "%s volume: %s host: %s",
- FAILED_CREATING_FILE, blk->volume, blk->volfileserver);
+ FAILED_CREATING_FILE, blk->volume, blk->volfileserver);
goto out;
}
- METAUPDATE(tgfd, write, "ENTRYCREATE: SUCCESS\n");
-
- if(GB_ALLOC(cobj) < 0)
- goto out;
-
- strcpy(cobj->volume, blk->volume);
- strcpy(cobj->volfileserver, blk->volfileserver);
- strcpy(cobj->block_name, blk->block_name);
- cobj->size = blk->size;
- strcpy(cobj->gbid, gbid);
+ METAUPDATE(tgfd, "ENTRYCREATE: SUCCESS\n");
- list = blockServerParse(blk->block_hosts);
+ strcpy(cobj.volume, blk->volume);
+ strcpy(cobj.volfileserver, blk->volfileserver);
+ strcpy(cobj.block_name, blk->block_name);
+ cobj.size = blk->size;
+ strcpy(cobj.gbid, gbid);
- /* TODO: Fail if mpath > list->nhosts */
for (i = 0; i < blk->mpath; i++) {
- block_create_remote(tgfd, cobj, list->hosts[i], &savereply);
+ glusterBlockCreateRemote(tgfd, &cobj, list->hosts[i], &savereply);
}
/* Check Point */
- ret = block_cross_check_request(glfs, tgfd, blk, cobj, list, &savereply);
- if(ret) {
- LOG("mgmt", ERROR, "%s", "even spare nodes have exhausted rewinding");
- ret = blockCleanUp(glfs, blk->block_name, FALSE, &savereply);
+ ret = glusterBlockAuditRequest(glfs, tgfd, blk,
+ &cobj, list, &savereply);
+ if (ret) {
+ LOG("mgmt", ERROR, "%s",
+ "even spare nodes have exhausted rewinding");
+ ret = glusterBlockCleanUp(glfs,
+ blk->block_name, FALSE, &savereply);
}
-out:
- if(GB_ALLOC(reply) < 0)
- goto out;
-
+ out:
reply->out = savereply;
- reply->exit = ret;
if (glfs_close(tgfd) != 0)
LOG("mgmt", ERROR, "%s", "glfs_close: failed");
- METAUNLOCK(lock, lkfd);
+ exist:
+ METAUNLOCK(lkfd);
+
+ reply->exit = ret;
if (glfs_close(lkfd) != 0)
LOG("mgmt", ERROR, "%s", "glfs_close: failed");
glfs_fini(glfs);
+
+ optfail:
blockServerDefFree(list);
- GB_FREE(cobj);
return reply;
}
@@ -489,46 +508,49 @@ blockResponse *
block_create_1_svc(blockCreate *blk, struct svc_req *rqstp)
{
FILE *fp;
- char *backstore = NULL;
- char *iqn = NULL;
- char *lun = NULL;
- char *attr = NULL;
- char *exec = NULL;
- blockResponse *obj = NULL;
+ char *backstore;
+ char *iqn;
+ char *lun;
+ char *attr;
+ char *exec;
+ blockResponse *reply = NULL;
+
asprintf(&backstore, "%s %s %s %zu %s@%s/%s %s", TARGETCLI_GLFS,
- CREATE, blk->block_name, blk->size, blk->volume, blk->volfileserver,
- blk->gbid, blk->gbid);
+ CREATE, blk->block_name, blk->size, blk->volume,
+ blk->volfileserver, blk->gbid, blk->gbid);
- asprintf(&iqn, "%s %s %s%s", TARGETCLI_ISCSI, CREATE, IQN_PREFIX, blk->gbid);
+ asprintf(&iqn, "%s %s %s%s", TARGETCLI_ISCSI, CREATE,
+ IQN_PREFIX, blk->gbid);
- asprintf(&lun, "%s/%s%s/tpg1/luns %s %s/%s",
- TARGETCLI_ISCSI, IQN_PREFIX, blk->gbid, CREATE, GLFS_PATH, blk->block_name);
+ asprintf(&lun, "%s/%s%s/tpg1/luns %s %s/%s", TARGETCLI_ISCSI,
+ IQN_PREFIX, blk->gbid, CREATE, GLFS_PATH, blk->block_name);
asprintf(&attr, "%s/%s%s/tpg1 set attribute %s",
TARGETCLI_ISCSI, IQN_PREFIX, blk->gbid, ATTRIBUTES);
- asprintf(&exec, "%s && %s && %s && %s && %s", backstore, iqn, lun, attr, TARGETCLI_SAVE);
+ asprintf(&exec, "%s && %s && %s && %s && %s", backstore, iqn, lun,
+ attr, TARGETCLI_SAVE);
- if(GB_ALLOC(obj) < 0)
+ if (GB_ALLOC(reply) < 0)
goto out;
- if (GB_ALLOC_N(obj->out, 4096) < 0) {
- GB_FREE(obj);
+ if (GB_ALLOC_N(reply->out, 4096) < 0) {
+ GB_FREE(reply);
goto out;
}
fp = popen(exec, "r");
if (fp != NULL) {
- size_t newLen = fread(obj->out, sizeof(char), 4096, fp);
+ size_t newLen = fread(reply->out, sizeof(char), 4096, fp);
if (ferror( fp ) != 0) {
LOG("mgmt", ERROR, "Reading command %s output", exec);
} else {
- obj->out[newLen++] = '\0';
+ reply->out[newLen++] = '\0';
}
- obj->exit = WEXITSTATUS(pclose(fp));
+ reply->exit = WEXITSTATUS(pclose(fp));
}
out:
@@ -538,7 +560,7 @@ block_create_1_svc(blockCreate *blk, struct svc_req *rqstp)
GB_FREE(iqn);
GB_FREE(backstore);
- return obj;
+ return reply;
}
@@ -548,9 +570,12 @@ block_delete_cli_1_svc(blockDeleteCli *blk, struct svc_req *rqstp)
int ret = -1;
char *savereply = NULL;
static blockResponse *reply = NULL;
- struct glfs *glfs = NULL;
+ struct glfs *glfs;
struct glfs_fd *lkfd;
- struct flock lock = {0, };
+
+
+ if (GB_ALLOC(reply) < 0)
+ return NULL;
glfs = glusterBlockVolumeInit(blk->volume, "localhost");
if (!glfs) {
@@ -564,7 +589,7 @@ block_delete_cli_1_svc(blockDeleteCli *blk, struct svc_req *rqstp)
goto out;
}
- METALOCK(lock, lkfd);
+ METALOCK(lkfd);
if (glfs_access(glfs, blk->block_name, F_OK)) {
GB_STRDUP(reply->out, "BLOCK Doesn't EXIST");
@@ -572,16 +597,14 @@ block_delete_cli_1_svc(blockDeleteCli *blk, struct svc_req *rqstp)
goto out;
}
-ret = blockCleanUp(glfs, blk->block_name, TRUE, &savereply);
+ ret = glusterBlockCleanUp(glfs, blk->block_name, TRUE, &savereply);
out:
- if (GB_ALLOC(reply) < 0)
- goto out;
-
reply->out = savereply;
- reply->exit = ret;
- METAUNLOCK(lock, lkfd);
+ METAUNLOCK(lkfd);
+
+ reply->exit = ret;
if (glfs_close(lkfd) != 0)
LOG("mgmt", ERROR, "%s", "glfs_close: failed");
@@ -596,55 +619,56 @@ blockResponse *
block_delete_1_svc(blockDelete *blk, struct svc_req *rqstp)
{
FILE *fp;
- char *iqn = NULL;
- char *backstore = NULL;
- char *exec = NULL;
- blockResponse *obj = NULL;
+ char *iqn;
+ char *backstore;
+ char *exec;
+ blockResponse *reply = NULL;
+
- asprintf(&iqn, "%s %s %s%s", TARGETCLI_ISCSI, DELETE, IQN_PREFIX, blk->gbid);
+ asprintf(&iqn, "%s %s %s%s", TARGETCLI_ISCSI, DELETE,
+ IQN_PREFIX, blk->gbid);
asprintf(&backstore, "%s %s %s", TARGETCLI_GLFS,
DELETE, blk->block_name);
asprintf(&exec, "%s && %s && %s", backstore, iqn, TARGETCLI_SAVE);
- if(GB_ALLOC(obj) < 0)
+ if (GB_ALLOC(reply) < 0)
goto out;
- if (GB_ALLOC_N(obj->out, 4096) < 0) {
- GB_FREE(obj);
+ if (GB_ALLOC_N(reply->out, 4096) < 0) {
+ GB_FREE(reply);
goto out;
}
fp = popen(exec, "r");
if (fp != NULL) {
- size_t newLen = fread(obj->out, sizeof(char), 4096, fp);
+ size_t newLen = fread(reply->out, sizeof(char), 4096, fp);
if (ferror( fp ) != 0) {
LOG("mgmt", ERROR, "reading command %s output", exec);
} else {
- obj->out[newLen++] = '\0';
+ reply->out[newLen++] = '\0';
}
- obj->exit = WEXITSTATUS(pclose(fp));
+ reply->exit = WEXITSTATUS(pclose(fp));
}
-out:
+ out:
GB_FREE(exec);
GB_FREE(backstore);
GB_FREE(iqn);
- return obj;
+ return reply;
}
blockResponse *
block_list_cli_1_svc(blockListCli *blk, struct svc_req *rqstp)
{
- blockResponse *reply = NULL;
+ blockResponse *reply;
struct glfs *glfs;
- struct glfs_fd *lkfd;
- struct glfs_fd *tgfd;
- struct flock lock = {0, };
- struct dirent *entry = NULL;
+ struct glfs_fd *lkfd = NULL;
+ struct glfs_fd *tgfd = NULL;
+ struct dirent *entry;
char *tmp = NULL;
char *filelist = NULL;
int ret = -1;
@@ -662,7 +686,7 @@ block_list_cli_1_svc(blockListCli *blk, struct svc_req *rqstp)
goto out;
}
- METALOCK(lock, lkfd);
+ METALOCK(lkfd);
tgfd = glfs_opendir (glfs, "/block-meta");
if (!tgfd) {
@@ -671,28 +695,28 @@ block_list_cli_1_svc(blockListCli *blk, struct svc_req *rqstp)
}
while ((entry = glfs_readdir (tgfd))) {
- if(strcmp(entry->d_name, ".") &&
+ if (strcmp(entry->d_name, ".") &&
strcmp(entry->d_name, "..") &&
strcmp(entry->d_name, "meta.lock")) {
- asprintf(&filelist, "%s%s\n", (tmp==NULL?"":tmp), entry->d_name);
- if (tmp)
- GB_FREE(tmp);
+ asprintf(&filelist, "%s%s\n", (tmp==NULL?"":tmp), entry->d_name);
+ GB_FREE(tmp);
tmp = filelist;
}
}
ret = 0;
-out:
+ out:
if (GB_ALLOC(reply) < 0)
- goto out;
+ return NULL;
reply->out = filelist? filelist:strdup("*Nil*\n");
- reply->exit = ret;
glfs_closedir (tgfd);
- METAUNLOCK(lock, lkfd);
+ METAUNLOCK(lkfd);
+
+ reply->exit = ret;
if (glfs_close(lkfd) != 0)
LOG("mgmt", ERROR, "%s", "glfs_close: failed");
@@ -706,16 +730,16 @@ out:
blockResponse *
block_info_cli_1_svc(blockInfoCli *blk, struct svc_req *rqstp)
{
- blockResponse *reply = NULL;
+ blockResponse *reply;
char *out = NULL;
char *tmp = NULL;
struct glfs *glfs;
- struct glfs_fd *lkfd;
- struct flock lock = {0, };
+ struct glfs_fd *lkfd = NULL;
MetaInfo *info = NULL;
int ret = -1;
size_t i;
+
glfs = glusterBlockVolumeInit(blk->volume, "localhost");
if (!glfs) {
LOG("mgmt", ERROR, "%s", "glusterBlockVolumeInit failed");
@@ -728,23 +752,23 @@ block_info_cli_1_svc(blockInfoCli *blk, struct svc_req *rqstp)
goto out;
}
- METALOCK(lock, lkfd);
+ METALOCK(lkfd);
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\nMULTIPATH: %zu\n"
- "BLOCK CONFIG NODE(S):",
- blk->block_name, info->volume, info->gbid, info->size, info->mpath);
+ 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) {
- asprintf(&out, "%s %s", (tmp==NULL?"":tmp), info->list[i]->addr);
- if (tmp)
- GB_FREE(tmp);
+ asprintf(&out, "%s %s", (tmp==NULL?"":tmp), info->list[i]->addr);
+ GB_FREE(tmp);
tmp = out;
}
}
@@ -753,15 +777,16 @@ block_info_cli_1_svc(blockInfoCli *blk, struct svc_req *rqstp)
out:
if (GB_ALLOC(reply) < 0)
- goto out;
+ return NULL;
- if(!out)
+ if (!out)
asprintf(&out, "No Block with name %s", blk->block_name);
reply->out = out;
- reply->exit = ret;
- METAUNLOCK(lock, lkfd);
+ METAUNLOCK(lkfd);
+
+ reply->exit = ret;
if (glfs_close(lkfd) != 0)
LOG("mgmt", ERROR, "%s", "glfs_close: failed");
diff --git a/utils.c b/utils.c
index aa2e3b8..c98923c 100644
--- a/utils.c
+++ b/utils.c
@@ -12,6 +12,7 @@
# include "utils.h"
+
int
blockMetaKeyEnumParse(const char *opt)
{
@@ -83,6 +84,9 @@ gbFree(void *ptrptr)
{
int save_errno = errno;
+ if(*(void**)ptrptr == NULL)
+ return;
+
free(*(void**)ptrptr);
*(void**)ptrptr = NULL;
errno = save_errno;
diff --git a/utils.h b/utils.h
index 4cefa28..0366b8d 100644
--- a/utils.h
+++ b/utils.h
@@ -17,7 +17,7 @@
# include <stdbool.h>
# include <string.h>
# include <errno.h>
-#include <time.h>
+# include <time.h>
/* Target Create */
@@ -46,6 +46,89 @@
# define FAILED_DELETING_IQN "failed while deleting IQN"
# define FAILED_DELETING_FILE "failed while deleting block file from gluster volume"
+
+# define ERROR(fmt, ...) \
+ do { \
+ fprintf(stderr, "Error: " fmt " [at %s+%d :<%s>]\n", \
+ __VA_ARGS__, __FILE__, __LINE__, __FUNCTION__); \
+ } while (0)
+
+# define MSG(fmt, ...) \
+ do { \
+ fprintf(stdout, fmt, __VA_ARGS__); \
+ } while (0)
+
+# define LOG(str, level, fmt, ...) \
+ do { \
+ FILE *fd; \
+ if (!strcmp(str, "mgmt")) \
+ fd = fopen (DAEMON_LOG_FILE, "a"); \
+ else if (strcmp(str, "cli")) \
+ fd = fopen (CLI_LOG_FILE, "a"); \
+ else if (strcmp(str, "gfapi")) \
+ fd = fopen (GFAPI_LOG_FILE, "a"); \
+ else \
+ fd = stderr; \
+ fprintf(fd, "[%lu] %s: " fmt " [at %s+%d :<%s>]\n", \
+ (unsigned long)time(NULL), LogLevelLookup[level],\
+ __VA_ARGS__, __FILE__, __LINE__, __FUNCTION__); \
+ fclose(fd); \
+ } while (0)
+
+# define METALOCK(lkfd) \
+ 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"); \
+ ret = -1; \
+ goto out; \
+ } \
+ } while (0)
+
+# define METAUPDATE(a, ...) \
+ do { \
+ char *write; \
+ asprintf(&write, __VA_ARGS__); \
+ if(glfs_write (a, write, strlen(write), 0) < 0) { \
+ LOG("mgmt", ERROR, "%s", "glfs_write: failed"); \
+ ret = -1; \
+ goto out; \
+ } \
+ GB_FREE(write); \
+ } while (0)
+
+# define METAUNLOCK(lkfd) \
+ 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"); \
+ ret = -1; \
+ } \
+ } while (0)
+
+
+# define CALLOC(x) \
+ calloc(1, x)
+
+# define GB_ALLOC_N(ptr, count) \
+ gbAllocN(&(ptr), sizeof(*(ptr)), (count), \
+ __FILE__, __FUNCTION__, __LINE__) \
+
+# define GB_ALLOC(ptr) \
+ gbAlloc(&(ptr), sizeof(*(ptr)), \
+ __FILE__, __FUNCTION__, __LINE__)
+
+# define GB_STRDUP(dst, src) \
+ gbStrdup(&(dst), src, \
+ __FILE__, __FUNCTION__, __LINE__)
+
+# define GB_FREE(ptr) \
+ gbFree(1 ? (void *) &(ptr) : (ptr))
+
+
typedef enum LogLevel {
NONE = 0,
EMERGENCY = 1,
@@ -76,66 +159,6 @@ static const char *const LogLevelLookup[] = {
[LOGLEVEL__MAX] = NULL,
};
-# define ERROR(fmt, ...) \
- fprintf(stderr, "Error: " fmt " [at %s+%d :<%s>]\n", \
- __VA_ARGS__, __FILE__, __LINE__, __FUNCTION__)
-
-# define MSG(fmt, ...) \
- fprintf(stdout, fmt, __VA_ARGS__)
-
-# define LOG(str, level, fmt, ...) {\
- static FILE *fd; \
- if (!strcmp(str, "mgmt")) \
- fd = fopen (DAEMON_LOG_FILE, "a"); \
- else if (strcmp(str, "cli")) \
- fd = fopen (CLI_LOG_FILE, "a"); \
- else if (strcmp(str, "gfapi")) \
- fd = fopen (GFAPI_LOG_FILE, "a"); \
- else \
- fd = stderr; \
- fprintf(fd, "[%lu] %s: " fmt " [at %s+%d :<%s>]\n", \
- (unsigned long)time(NULL), LogLevelLookup[level], \
- __VA_ARGS__, __FILE__, __LINE__, __FUNCTION__); \
- fclose(fd); \
- }
-
-# define METALOCK(a, b) {\
- memset (&a, 0, sizeof(a)); \
- a.l_type = F_WRLCK; \
- if (glfs_posix_lock (b, F_SETLKW, &a)) {\
- ERROR("%s", "glfs_posix_lock: failed");\
- goto out;\
- }\
- }
-
-# define METAUPDATE(a, b, ...) {\
- asprintf(&b, __VA_ARGS__);\
- if(glfs_write (a, b, strlen(b), 0) < 0) {\
- ERROR("%s", "glfs_write: failed");\
- goto out;\
- }\
- GB_FREE(b); \
- }
-
-# define METAUNLOCK(a, b) {\
- a.l_type = F_UNLCK; \
- glfs_posix_lock(b, F_SETLKW, &a); \
- }
-
-
-# define CALLOC(x) calloc(1, x)
-
-# define GB_ALLOC_N(ptr, count) gbAllocN(&(ptr), sizeof(*(ptr)), (count), \
- __FILE__, __FUNCTION__, __LINE__)
-
-# define GB_ALLOC(ptr) gbAlloc(&(ptr), sizeof(*(ptr)), \
- __FILE__, __FUNCTION__, __LINE__)
-
-# define GB_STRDUP(dst, src) gbStrdup(&(dst), src, \
- __FILE__, __FUNCTION__, __LINE__)
-
-# define GB_FREE(ptr) gbFree(1 ? (void *) &(ptr) : (ptr))
-
typedef enum Metakey {
VOLUME = 0,
GBID = 1,