summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common.h8
-rw-r--r--glfs-operations.c32
-rw-r--r--gluster-block.c54
-rw-r--r--gluster-blockd.c102
-rw-r--r--utils.h49
5 files changed, 149 insertions, 96 deletions
diff --git a/common.h b/common.h
index 4898fe7..4698348 100644
--- a/common.h
+++ b/common.h
@@ -14,8 +14,12 @@
# include "utils.h"
-# define LOG_FILE "/var/log/gluster-block/block.log"
-# define LOG_LEVEL 7
+# define DAEMON_LOG_FILE "/var/log/gluster-block/gluster-blockd.log"
+# define CLI_LOG_FILE "/var/log/gluster-block/gluster-block-cli.log"
+
+# define GFAPI_LOG_FILE "/var/log/gluster-block/gluster-block-gfapi.log"
+# define GFAPI_LOG_LEVEL 7
+
size_t glusterBlockCreateParseSize(char *value);
diff --git a/glfs-operations.c b/glfs-operations.c
index 1f6352c..251c73b 100644
--- a/glfs-operations.c
+++ b/glfs-operations.c
@@ -22,25 +22,25 @@ glusterBlockVolumeInit(char *volume, char *volfileserver)
glfs = glfs_new(volume);
if (!glfs) {
- ERROR("%s", "glfs_new: returned NULL");
+ LOG("gfapi", ERROR, "%s", "glfs_new: failed");
return NULL;
}
ret = glfs_set_volfile_server(glfs, "tcp", volfileserver, 24007);
if (ret) {
- ERROR("%s", "glfs_set_volfile_server: failed");
+ LOG("gfapi", ERROR, "%s", "glfs_set_volfile_server: failed");
goto out;
}
- ret = glfs_set_logging(glfs, LOG_FILE, LOG_LEVEL);
+ ret = glfs_set_logging(glfs, GFAPI_LOG_FILE, GFAPI_LOG_LEVEL);
if (ret) {
- ERROR("%s", "glfs_set_logging: failed");
+ LOG("gfapi", ERROR, "%s", "glfs_set_logging: failed");
goto out;
}
ret = glfs_init(glfs);
if (ret) {
- ERROR("%s", "glfs_init: failed");
+ LOG("gfapi", ERROR, "%s", "glfs_init: failed");
goto out;
}
@@ -61,7 +61,7 @@ glusterBlockCreateEntry(blockCreateCli *blk, char *gbid)
glfs = glusterBlockVolumeInit(blk->volume, blk->volfileserver);
if (!glfs) {
- ERROR("%s", "glusterBlockVolumeInit: failed");
+ LOG("gfapi", ERROR, "%s", "glusterBlockVolumeInit: failed");
goto out;
}
@@ -69,17 +69,17 @@ glusterBlockCreateEntry(blockCreateCli *blk, char *gbid)
O_WRONLY | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR);
if (!fd) {
- ERROR("%s", "glfs_creat: failed");
+ LOG("gfapi", ERROR, "%s", "glfs_creat: failed");
ret = -errno;
} else {
ret = glfs_ftruncate(fd, blk->size);
if (ret) {
- ERROR("%s", "glfs_ftruncate: failed");
+ LOG("gfapi", ERROR, "%s", "glfs_ftruncate: failed");
goto out;
}
if (glfs_close(fd) != 0) {
- ERROR("%s", "glfs_close: failed");
+ LOG("gfapi", ERROR, "%s", "glfs_close: failed");
ret = -errno;
}
}
@@ -98,13 +98,13 @@ glusterBlockDeleteEntry(char *volume, char *gbid)
glfs = glusterBlockVolumeInit(volume, "localhost");
if (!glfs) {
- ERROR("%s", "glusterBlockVolumeInit: failed");
+ LOG("gfapi", ERROR, "%s", "glusterBlockVolumeInit: failed");
goto out;
}
ret = glfs_unlink(glfs, gbid);
if (ret) {
- ERROR("%s", "glfs_unlink: failed");
+ LOG("gfapi", ERROR, "%s", "glfs_unlink: failed");
goto out;
}
@@ -122,19 +122,19 @@ glusterBlockCreateMetaLockFile(struct glfs *glfs)
ret = glfs_mkdir (glfs, "/block-meta", 0);
if (ret && errno != EEXIST) {
- ERROR("%s", "glfs_mkdir: failed");
+ LOG("gfapi", ERROR, "%s", "glfs_mkdir: failed");
goto out;
}
ret = glfs_chdir (glfs, "/block-meta");
if (ret) {
- ERROR("%s", "glfs_chdir: failed");
+ LOG("gfapi", ERROR, "%s", "glfs_chdir: failed");
goto out;
}
lkfd = glfs_creat(glfs, "meta.lock", O_RDWR, S_IRUSR | S_IWUSR);
if (!lkfd) {
- ERROR("%s", "glfs_creat: failed");
+ LOG("gfapi", ERROR, "%s", "glfs_creat: failed");
goto out;
}
@@ -222,9 +222,9 @@ blockGetMetaInfo(struct glfs* glfs, char* metafile, MetaInfo *info)
char line[48];
char *tmp;
- tgfd = glfs_open(glfs, metafile, O_RDWR);
+ tgfd = glfs_open(glfs, metafile, O_RDONLY);
if (!tgfd) {
- ERROR("%s", "glfs_open failed");
+ LOG("gfapi", ERROR, "%s", "glfs_open failed");
return -1;
}
diff --git a/gluster-block.c b/gluster-block.c
index fc749a9..4b89997 100644
--- a/gluster-block.c
+++ b/gluster-block.c
@@ -45,8 +45,8 @@ gluster_block_cli_1(void *cobj, opterations opt, char **out)
blockResponse *reply = NULL;
if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
- perror("client: socket");
- exit(1);
+ LOG("cli", ERROR, "socket creation failed (%s)", strerror (errno));
+ goto out;
}
saun.sun_family = AF_UNIX;
@@ -55,38 +55,42 @@ gluster_block_cli_1(void *cobj, opterations opt, char **out)
len = sizeof(saun.sun_family) + strlen(saun.sun_path);
if (connect(sockfd, (struct sockaddr *) &saun, len) < 0) {
- perror("client: connect");
- exit(1);
+ 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_pcreateerror ("localhost");
- exit (1);
+ LOG("cli", ERROR, "%s, unix addr %s",
+ clnt_spcreateerror("client create failed"), ADDRESS);
}
switch(opt) {
case CREATE_CLI:
reply = block_create_cli_1((blockCreateCli *)cobj, clnt);
if (reply == NULL) {
- clnt_perror (clnt, "call failed gluster-block");
+ 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) {
- clnt_perror (clnt, "call failed gluster-block");
+ 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) {
- clnt_perror (clnt, "call failed gluster-block");
+ 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) {
- clnt_perror (clnt, "call failed gluster-block");
+ LOG("cli", ERROR, "%s", clnt_sperror(clnt, "block list failed"));
+ goto out;
}
break;
}
@@ -99,7 +103,7 @@ gluster_block_cli_1(void *cobj, opterations opt, char **out)
out:
if (!clnt_freeres(clnt, (xdrproc_t) xdr_blockResponse, (char *) reply))
- clnt_perror (clnt, "clnt_freeres failed");
+ LOG("cli", ERROR, "%s", clnt_sperror (clnt, "clnt_freeres failed"));
clnt_destroy (clnt);
@@ -139,8 +143,8 @@ glusterBlockCreate(int count, char **options, char *name)
static blockCreateCli cobj;
if (!name) {
- ERROR("%s", "Insufficient arguments supplied for"
- "'gluster-block create'");
+ LOG("cli", ERROR, "%s", "Insufficient arguments supplied for"
+ "'gluster-block create'");
ret = -1;
goto out;
}
@@ -191,7 +195,7 @@ glusterBlockCreate(int count, char **options, char *name)
case 's':
cobj.size = glusterBlockCreateParseSize(optarg);
if (cobj.size < 0) {
- ERROR("%s", "failed while parsing size");
+ LOG("cli", ERROR, "%s", "failed while parsing size");
ret = -1;
goto out;
}
@@ -199,8 +203,8 @@ glusterBlockCreate(int count, char **options, char *name)
break;
case '?':
- MSG("unrecognized option '%s'", options[optind-1]);
- MSG("%s", "Hint: gluster-block --help");
+ MSG("unrecognized option '%s'\n", options[optind-1]);
+ MSG("%s", "Hint: gluster-block --help\n");
goto out;
default:
@@ -210,7 +214,7 @@ glusterBlockCreate(int count, char **options, char *name)
/* Print any remaining command line arguments (not options). */
if (optind < count) {
- ERROR("%s", "non-option ARGV-elements: ");
+ LOG("cli", ERROR, "%s", "non-option ARGV-elements: ");
while (optind < count)
printf("%s ", options[optind++]);
putchar('\n');
@@ -220,7 +224,7 @@ glusterBlockCreate(int count, char **options, char *name)
}
if (ret != 5) {
- ERROR("%s", "Insufficient arguments supplied for"
+ LOG("cli", ERROR, "%s", "Insufficient arguments supplied for"
"'gluster-block create'\n");
ret = -1;
goto out;
@@ -333,7 +337,7 @@ glusterBlockParseArgs(int count, char **options)
case 'c':
ret = glusterBlockCreate(count, options, optarg);
if (ret && ret != EEXIST) {
- ERROR("%s", FAILED_CREATE);
+ LOG("cli", ERROR, "%s", FAILED_CREATE);
goto out;
}
break;
@@ -348,7 +352,7 @@ glusterBlockParseArgs(int count, char **options)
break;
case 'm':
- MSG("option --modify yet TODO '%s'", optarg);
+ MSG("option --modify yet TODO '%s'\n", optarg);
break;
case 'h':
@@ -365,27 +369,27 @@ glusterBlockParseArgs(int count, char **options)
case 'l':
ret = glusterBlockList(volume);
if (ret)
- ERROR("%s", FAILED_LIST);
+ LOG("cli", ERROR, "%s", FAILED_LIST);
break;
case 'i':
ret = glusterBlockInfo(block, volume);
if (ret)
- ERROR("%s", FAILED_INFO);
+ LOG("cli", ERROR, "%s", FAILED_INFO);
break;
case 'd':
ret = glusterBlockDelete(block, volume);
if (ret)
- ERROR("%s", FAILED_DELETE);
+ LOG("cli", ERROR, "%s", FAILED_DELETE);
break;
}
out:
if (ret == 0 && optind < count) {
- ERROR("%s", "Unable to parse elements: ");
+ LOG("cli", ERROR, "%s", "Unable to parse elements: ");
while (optind < count)
printf("%s ", options[optind++]);
putchar('\n');
- MSG("Hint: %s --help", options[0]);
+ MSG("Hint: %s --help\n", options[0]);
}
return ret;
diff --git a/gluster-blockd.c b/gluster-blockd.c
index f12eee8..e9ed6e7 100644
--- a/gluster-blockd.c
+++ b/gluster-blockd.c
@@ -23,8 +23,6 @@
# define UUID_BUF_SIZE 38
# define CREATE "create"
-# define LIST "list"
-# define INFO "info"
# define DELETE "delete"
# define GLFS_PATH "/backstores/user:glfs"
@@ -32,8 +30,6 @@
# define TARGETCLI_ISCSI "targetcli /iscsi"
# define TARGETCLI_SAVE "targetcli / saveconfig"
# define ATTRIBUTES "generate_node_acls=1 demo_mode_write_protect=0"
-# define BACKEND_CFGSTR "ls | grep ' %s ' | cut -d'[' -f2 | cut -d']' -f1"
-# define LUNS_LIST "ls | grep -v user:glfs | cut -d'-' -f2 | cut -d' ' -f2"
# define IQN_PREFIX "iqn.2016-12.org.gluster-block:"
# define MSERVER_DELIMITER ","
@@ -63,14 +59,14 @@ gluster_block_1(char *host, void *cobj, opterations opt, char **out)
struct sockaddr_in sain;
if ((sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
- perror("gluster-blockd: socket");
- exit(1);
+ LOG("mgmt", ERROR, "socket creation failed (%s)", strerror (errno));
+ goto out;
}
server = gethostbyname(host);
if (server == NULL) {
- fprintf(stderr,"ERROR, no such host\n");
- exit(0);
+ LOG("mgmt", ERROR, "gethostbyname failed (%s)", strerror (errno));
+ goto out;
}
bzero((char *) &sain, sizeof(sain));
@@ -79,27 +75,30 @@ gluster_block_1(char *host, void *cobj, opterations opt, char **out)
sain.sin_port = htons(24006);
if (connect(sockfd, (struct sockaddr *) &sain, sizeof(sain)) < 0) {
- perror("gluster-blockd: connect");
- exit(1);
+ LOG("mgmt", 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 == NULL) {
- clnt_pcreateerror ("localhost");
- exit (1);
+ LOG("mgmt", ERROR, "%s, inet host %s",
+ clnt_spcreateerror("client create failed"), host);
+ goto out;
}
switch(opt) {
case CREATE_SRV:
reply = block_create_1((blockCreate *)cobj, clnt);
if (reply == NULL) {
- clnt_perror (clnt, "call failed gluster-block");
+ 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) {
- clnt_perror (clnt, "call failed gluster-block");
+ LOG("mgmt", ERROR, "%s", clnt_sperror (clnt, "block delete failed"));
+ goto out;
}
break;
}
@@ -112,7 +111,7 @@ gluster_block_1(char *host, void *cobj, opterations opt, char **out)
out:
if (!clnt_freeres(clnt, (xdrproc_t) xdr_blockResponse, (char *) reply))
- clnt_perror (clnt, "clnt_freeres failed");
+ LOG("mgmt", ERROR, "%s", clnt_sperror (clnt, "clnt_freeres failed"));
clnt_destroy (clnt);
@@ -178,7 +177,7 @@ block_create_remote(struct glfs_fd *tgfd, blockCreate *cobj, char *addr, char **
{
char *write = NULL;
char *out = NULL;
- char *tmp = NULL;
+ char *tmp = *reply;
int ret;
METAUPDATE(tgfd, write, "%s: CONFIGINPROGRESS\n", addr);
@@ -186,7 +185,7 @@ block_create_remote(struct glfs_fd *tgfd, blockCreate *cobj, char *addr, char **
ret = gluster_block_1(addr, cobj, CREATE_SRV, &out);
if (ret) {
METAUPDATE(tgfd, write, "%s: CONFIGFAIL\n", addr);
- ERROR("%s on host: %s", FAILED_CREATE, addr);
+ LOG("mgmt", ERROR, "%s on host: %s", FAILED_CREATE, addr);
*reply = out;
goto out;
@@ -247,14 +246,14 @@ block_cross_check_request(struct glfs *glfs,
spare = list->nhosts - spent; /* spare after spent */
morereq = blk->mpath - success_count; /* needed nodes to complete req */
if (spare == 0) {
- ERROR("%s", "No Spare nodes: rewining the creation of target");
+ LOG("mgmt", WARNING, "%s", "No Spare nodes: rewining the creation of target");
return -1;
} else if (spare < morereq) {
- ERROR("%s", "Not enough Spare nodes: rewining the creation of target");
+ LOG("mgmt", WARNING, "%s", "Not enough Spare nodes: rewining the creation of target");
return -1;
} else {
/* create on spare */
- MSG("%s", "trying to serve the mpath from spare machines");
+ 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);
}
@@ -274,15 +273,15 @@ block_delete_remote(struct glfs_fd *tgfd, blockDelete *cobj, char *addr, char **
{
char *write = NULL;
char *out = NULL;
- char *tmp = NULL;
+ char *tmp = *reply;
int ret;
METAUPDATE(tgfd, write, "%s: CLEANUPINPROGRES\n", addr);
ret = gluster_block_1(addr, cobj, DELETE_SRV, &out);
if (ret) {
METAUPDATE(tgfd, write, "%s: CLEANUPFAIL\n", addr);
- ERROR("%s on host: %s",
- FAILED_GATHERING_INFO, addr);
+ LOG("mgmt", ERROR, "%s on host: %s",
+ FAILED_GATHERING_INFO, addr);
goto out;
}
METAUPDATE(tgfd, write, "%s: CLEANUPSUCCESS\n", addr);
@@ -300,7 +299,7 @@ block_delete_remote(struct glfs_fd *tgfd, blockDelete *cobj, char *addr, char **
static int
blockCleanUp(struct glfs *glfs, char *blockname,
- bool deleteall, char **reply)
+ bool deleteall, char **reply)
{
MetaInfo *info = NULL;
int ret = -1;
@@ -322,12 +321,11 @@ if (GB_ALLOC(info) < 0)
strcpy(cobj->block_name, blockname);
strcpy(cobj->gbid, info->gbid);
- tgfd = glfs_open(glfs, blockname, O_RDWR);
+ tgfd = glfs_open(glfs, blockname, O_WRONLY|O_APPEND);
if (!tgfd) {
- ERROR("%s", "glfs_open: failed");
+ LOG("mgmt", ERROR, "%s", "glfs_open: failed");
goto out;
}
- glfs_lseek (tgfd, 0, SEEK_END); /* append at end of file */
for (i = 0; i < info->nhosts; i++) {
switch (blockMetaStatusEnumParse(info->list[i]->status)) {
@@ -359,12 +357,12 @@ if (GB_ALLOC(info) < 0)
if( cleanup_success == info->nhosts) {
if (glusterBlockDeleteEntry(info->volume, info->gbid)) {
- ERROR("%s volume: %s host: %s",
+ LOG("mgmt", ERROR, "%s volume: %s host: %s",
FAILED_DELETING_FILE, info->volume, "localhost");
}
ret = glfs_unlink(glfs, blockname);
if (ret && errno != ENOENT) {
- ERROR("%s", "glfs_unlink: failed");
+ LOG("mgmt", ERROR, "%s", "glfs_unlink: failed");
goto out;
}
}
@@ -372,9 +370,9 @@ if (GB_ALLOC(info) < 0)
out:
blockFreeMetaInfo(info);
- if (glfs_close(tgfd) != 0)
- ERROR("%s", "glfs_close: failed");
-
+ if (glfs_close(tgfd) != 0) {
+ LOG("mgmt", ERROR, "%s", "glfs_close: failed");
+ }
GB_FREE(cobj);
return ret;
@@ -400,13 +398,13 @@ block_create_cli_1_svc(blockCreateCli *blk, struct svc_req *rqstp)
glfs = glusterBlockVolumeInit(blk->volume, blk->volfileserver);
if (!glfs) {
- ERROR("%s", "glusterBlockVolumeInit failed");
+ LOG("mgmt", ERROR, "%s", "glusterBlockVolumeInit failed");
goto out;
}
lkfd = glusterBlockCreateMetaLockFile(glfs);
if (!lkfd) {
- ERROR("%s", "glusterBlockCreateMetaLockFile failed");
+ LOG("mgmt", ERROR, "%s", "glusterBlockCreateMetaLockFile failed");
goto out;
}
@@ -423,7 +421,7 @@ block_create_cli_1_svc(blockCreateCli *blk, struct svc_req *rqstp)
tgfd = glfs_creat(glfs, blk->block_name, O_RDWR, S_IRUSR | S_IWUSR);
if (!tgfd) {
- ERROR("%s", "glfs_creat: failed");
+ LOG("mgmt", ERROR, "%s", "glfs_creat: failed");
goto out;
}
@@ -434,7 +432,7 @@ block_create_cli_1_svc(blockCreateCli *blk, struct svc_req *rqstp)
ret = glusterBlockCreateEntry(blk, gbid);
if (ret) {
METAUPDATE(tgfd, write, "ENTRYCREATE: FAIL\n");
- ERROR("%s volume: %s host: %s",
+ LOG("mgmt", ERROR, "%s volume: %s host: %s",
FAILED_CREATING_FILE, blk->volume, blk->volfileserver);
goto out;
}
@@ -460,6 +458,7 @@ block_create_cli_1_svc(blockCreateCli *blk, struct svc_req *rqstp)
/* 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);
}
@@ -471,12 +470,12 @@ out:
reply->exit = ret;
if (glfs_close(tgfd) != 0)
- ERROR("%s", "glfs_close: failed");
+ LOG("mgmt", ERROR, "%s", "glfs_close: failed");
METAUNLOCK(lock, lkfd);
if (glfs_close(lkfd) != 0)
- ERROR("%s", "glfs_close: failed");
+ LOG("mgmt", ERROR, "%s", "glfs_close: failed");
glfs_fini(glfs);
blockServerDefFree(list);
@@ -525,7 +524,7 @@ block_create_1_svc(blockCreate *blk, struct svc_req *rqstp)
if (fp != NULL) {
size_t newLen = fread(obj->out, sizeof(char), 4096, fp);
if (ferror( fp ) != 0) {
- ERROR("%s", "Error reading command output\n");
+ LOG("mgmt", ERROR, "Reading command %s output", exec);
} else {
obj->out[newLen++] = '\0';
}
@@ -555,13 +554,13 @@ block_delete_cli_1_svc(blockDeleteCli *blk, struct svc_req *rqstp)
glfs = glusterBlockVolumeInit(blk->volume, "localhost");
if (!glfs) {
- ERROR("%s", "glusterBlockVolumeInit failed");
+ LOG("mgmt", ERROR, "%s", "glusterBlockVolumeInit failed");
goto out;
}
lkfd = glusterBlockCreateMetaLockFile(glfs);
if (!lkfd) {
- ERROR("%s", "glusterBlockCreateMetaLockFile failed");
+ LOG("mgmt", ERROR, "%s", "glusterBlockCreateMetaLockFile failed");
goto out;
}
@@ -585,7 +584,7 @@ ret = blockCleanUp(glfs, blk->block_name, TRUE, &savereply);
METAUNLOCK(lock, lkfd);
if (glfs_close(lkfd) != 0)
- ERROR("%s", "glfs_close: failed");
+ LOG("mgmt", ERROR, "%s", "glfs_close: failed");
glfs_fini(glfs);
@@ -621,7 +620,7 @@ block_delete_1_svc(blockDelete *blk, struct svc_req *rqstp)
if (fp != NULL) {
size_t newLen = fread(obj->out, sizeof(char), 4096, fp);
if (ferror( fp ) != 0) {
- ERROR("%s", "Error reading command output\n");
+ LOG("mgmt", ERROR, "reading command %s output", exec);
} else {
obj->out[newLen++] = '\0';
}
@@ -653,13 +652,13 @@ block_list_cli_1_svc(blockListCli *blk, struct svc_req *rqstp)
glfs = glusterBlockVolumeInit(blk->volume, "localhost");
if (!glfs) {
- ERROR("%s", "glusterBlockVolumeInit failed");
+ LOG("mgmt", ERROR, "%s", "glusterBlockVolumeInit failed");
goto out;
}
lkfd = glusterBlockCreateMetaLockFile(glfs);
if (!lkfd) {
- ERROR("%s", "glusterBlockCreateMetaLockFile failed");
+ LOG("mgmt", ERROR, "%s", "glusterBlockCreateMetaLockFile failed");
goto out;
}
@@ -667,7 +666,7 @@ block_list_cli_1_svc(blockListCli *blk, struct svc_req *rqstp)
tgfd = glfs_opendir (glfs, "/block-meta");
if (!tgfd) {
- ERROR("%s", "glusterBlockVolumeInit failed");
+ LOG("mgmt", ERROR, "%s", "glusterBlockVolumeInit failed");
goto out;
}
@@ -688,7 +687,7 @@ out:
if (GB_ALLOC(reply) < 0)
goto out;
- reply->out = filelist? filelist:strdup("*Nil*");
+ reply->out = filelist? filelist:strdup("*Nil*\n");
reply->exit = ret;
glfs_closedir (tgfd);
@@ -696,7 +695,7 @@ out:
METAUNLOCK(lock, lkfd);
if (glfs_close(lkfd) != 0)
- ERROR("%s", "glfs_close: failed");
+ LOG("mgmt", ERROR, "%s", "glfs_close: failed");
glfs_fini(glfs);
@@ -719,13 +718,13 @@ block_info_cli_1_svc(blockInfoCli *blk, struct svc_req *rqstp)
glfs = glusterBlockVolumeInit(blk->volume, "localhost");
if (!glfs) {
- ERROR("%s", "glusterBlockVolumeInit failed");
+ LOG("mgmt", ERROR, "%s", "glusterBlockVolumeInit failed");
goto out;
}
lkfd = glusterBlockCreateMetaLockFile(glfs);
if (!lkfd) {
- ERROR("%s", "glusterBlockCreateMetaLockFile failed");
+ LOG("mgmt", ERROR, "%s", "glusterBlockCreateMetaLockFile failed");
goto out;
}
@@ -749,6 +748,7 @@ block_info_cli_1_svc(blockInfoCli *blk, struct svc_req *rqstp)
tmp = out;
}
}
+ asprintf(&out, "%s\n", tmp);
ret = 0;
out:
@@ -764,7 +764,7 @@ block_info_cli_1_svc(blockInfoCli *blk, struct svc_req *rqstp)
METAUNLOCK(lock, lkfd);
if (glfs_close(lkfd) != 0)
- ERROR("%s", "glfs_close: failed");
+ LOG("mgmt", ERROR, "%s", "glfs_close: failed");
glfs_fini(glfs);
diff --git a/utils.h b/utils.h
index 590eec9..4cefa28 100644
--- a/utils.h
+++ b/utils.h
@@ -17,6 +17,7 @@
# include <stdbool.h>
# include <string.h>
# include <errno.h>
+#include <time.h>
/* Target Create */
@@ -45,14 +46,58 @@
# define FAILED_DELETING_IQN "failed while deleting IQN"
# define FAILED_DELETING_FILE "failed while deleting block file from gluster volume"
+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 */
+} 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,
+};
# define ERROR(fmt, ...) \
fprintf(stderr, "Error: " fmt " [at %s+%d :<%s>]\n", \
__VA_ARGS__, __FILE__, __LINE__, __FUNCTION__)
# define MSG(fmt, ...) \
- fprintf(stdout, fmt "\n", __VA_ARGS__)
-
+ 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)); \