summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPrasanna Kumar Kalever <prasanna.kalever@redhat.com>2017-08-17 11:21:11 +0530
committerPrasanna Kumar Kalever <prasanna.kalever@redhat.com>2017-08-17 14:22:55 +0530
commitb535c44fdd2b71c50a8fcbcf1e1e1c2d1c0340e9 (patch)
tree208d639723c7a8bfc1b928ee7843155c69fe8a5e
parentd723907c8eaa25f107c7fadd79ca5f9bc6596edf (diff)
logger: support logdir choosing via Environment variable
Currently the default logdir is DATADIR /log/gluster-block/ This patch will provide a way to change this default logdir via Env variable $ export GB_LOGDIR=/var/log/gluster-block-new-path/ Note: make sure to restart the processes (cli & daemon) after you set GB_LOGDIR Change-Id: Id142e4a4dfe7b6ebc9cf8296b8ceb8bff37691b8 Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
-rw-r--r--cli/gluster-block.c5
-rw-r--r--daemon/gluster-blockd.c36
-rw-r--r--rpc/block_svc_routines.c11
-rw-r--r--rpc/glfs-operations.c4
-rw-r--r--utils/common.h22
-rw-r--r--utils/utils.c63
-rw-r--r--utils/utils.h46
7 files changed, 123 insertions, 64 deletions
diff --git a/cli/gluster-block.c b/cli/gluster-block.c
index 04f081f..85b0e80 100644
--- a/cli/gluster-block.c
+++ b/cli/gluster-block.c
@@ -607,6 +607,11 @@ main(int argc, char *argv[])
{
if (argc <= 1) {
glusterBlockHelp();
+ exit(EXIT_FAILURE);
+ }
+
+ if(initLogging()) {
+ exit(EXIT_FAILURE);
}
return glusterBlockParseArgs(argc, argv);
diff --git a/daemon/gluster-blockd.c b/daemon/gluster-blockd.c
index 02ed642..c96e4bd 100644
--- a/daemon/gluster-blockd.c
+++ b/daemon/gluster-blockd.c
@@ -50,30 +50,6 @@ glusterBlockDHelp(void)
}
-static bool
-glusterBlockLogdirCreate(void)
-{
- DIR* dir = opendir(GB_LOGDIR);
-
-
- if (dir) {
- closedir(dir);
- } else if (errno == ENOENT) {
- if (mkdir(GB_LOGDIR, 0755) == -1) {
- LOG("mgmt", GB_LOG_ERROR, "mkdir(%s) failed (%s)",
- GB_LOGDIR, strerror (errno));
- return FALSE;
- }
- } else {
- LOG("mgmt", GB_LOG_ERROR, "opendir(%s) failed (%s)",
- GB_LOGDIR, strerror (errno));
- return FALSE;
- }
-
- return TRUE;
-}
-
-
void *
glusterBlockCliThreadProc (void *vargp)
{
@@ -266,8 +242,8 @@ glusterBlockDParseArgs(int count, char **options)
MSG("option '%s' needs argument <LOG-LEVEL>\n", options[optind-1]);
return -1;
}
- logLevel = blockLogLevelEnumParse(options[optind]);
- if (logLevel >= GB_LOG_MAX) {
+ gbConf.logLevel = blockLogLevelEnumParse(options[optind]);
+ if (gbConf.logLevel >= GB_LOG_MAX) {
MSG("unknown LOG-LEVEL: '%s'\n", options[optind]);
return -1;
}
@@ -291,12 +267,12 @@ main (int argc, char **argv)
int errnosv = 0;
- if (glusterBlockDParseArgs(argc, argv)) {
- LOG("mgmt", GB_LOG_ERROR, "%s", "glusterBlockDParseArgs() failed");
- return -1;
+ if(initLogging()) {
+ exit(EXIT_FAILURE);
}
- if (!glusterBlockLogdirCreate()) {
+ if (glusterBlockDParseArgs(argc, argv)) {
+ LOG("mgmt", GB_LOG_ERROR, "%s", "glusterBlockDParseArgs() failed");
return -1;
}
diff --git a/rpc/block_svc_routines.c b/rpc/block_svc_routines.c
index b309e79..70f0b3e 100644
--- a/rpc/block_svc_routines.c
+++ b/rpc/block_svc_routines.c
@@ -33,7 +33,7 @@
# define GB_TGCLI_GLOBALS "targetcli set " \
"global auto_add_default_portal=false " \
"auto_enable_tpgt=false " \
- "logfile=" CONFIGSHELL_LOG_FILE " > " DEVNULLPATH
+ "logfile=%s > " DEVNULLPATH
# define GB_TGCLI_SAVE "targetcli / saveconfig > " DEVNULLPATH
# define GB_TGCLI_ATTRIBUTES "generate_node_acls=1 demo_mode_write_protect=0 > " DEVNULLPATH
# define GB_TGCLI_IQN_PREFIX "iqn.2016-12.org.gluster-block:"
@@ -2072,6 +2072,7 @@ block_create_1_svc(blockCreate *blk, struct svc_req *rqstp)
char *attr = NULL;
char *authcred = NULL;
char *exec = NULL;
+ char *global_opts = NULL;
blockResponse *reply = NULL;
blockServerDefPtr list = NULL;
size_t i;
@@ -2168,11 +2169,17 @@ block_create_1_svc(blockCreate *blk, struct svc_req *rqstp)
goto out;
}
if (!tmp) {
+ if (GB_ASPRINTF(&global_opts, GB_TGCLI_GLOBALS, gbConf.configShellLogFile) == -1) {
+ goto out;
+ }
+
if (GB_ASPRINTF(&exec, "%s && %s && %s && %s && %s %s && %s && %s %s",
- GB_TGCLI_GLOBALS, backstore, backstore_attr, iqn, tpg?tpg:"", lun,
+ global_opts, backstore, backstore_attr, iqn, tpg?tpg:"", lun,
portal, attr, blk->auth_mode?authcred:"") == -1) {
+ GB_FREE(global_opts);
goto out;
}
+ GB_FREE(global_opts);
tmp = exec;
} else {
if (GB_ASPRINTF(&exec, "%s && %s && %s && %s %s",
diff --git a/rpc/glfs-operations.c b/rpc/glfs-operations.c
index 0509f7f..d5d3aba 100644
--- a/rpc/glfs-operations.c
+++ b/rpc/glfs-operations.c
@@ -45,13 +45,13 @@ glusterBlockVolumeInit(char *volume, int *errCode, char **errMsg)
goto out;
}
- ret = glfs_set_logging(glfs, GFAPI_LOG_FILE, GFAPI_LOG_LEVEL);
+ ret = glfs_set_logging(glfs, gbConf.gfapiLogFile, GFAPI_LOG_LEVEL);
if (ret) {
*errCode = errno;
GB_ASPRINTF (errMsg, "Not able to add logging for volume %s[%s]", volume,
strerror(*errCode));
LOG("gfapi", GB_LOG_ERROR, "glfs_set_logging(%s, %d) on %s failed[%s]",
- GFAPI_LOG_FILE, GFAPI_LOG_LEVEL, volume, strerror(*errCode));
+ gbConf.gfapiLogFile, GFAPI_LOG_LEVEL, volume, strerror(*errCode));
goto out;
}
diff --git a/utils/common.h b/utils/common.h
index 6503218..2d1202a 100644
--- a/utils/common.h
+++ b/utils/common.h
@@ -15,28 +15,6 @@
# include "utils.h"
# include "block.h"
-# define GB_LOGDIR DATADIR "/log/gluster-block"
-# define GB_INFODIR DATADIR "/run"
-
-# define GB_LOCK_FILE GB_INFODIR "/gluster-blockd.lock"
-# define GB_UNIX_ADDRESS GB_INFODIR "/gluster-blockd.socket"
-# define GB_TCP_PORT 24006
-
-# define DAEMON_LOG_FILE GB_LOGDIR "/gluster-blockd.log"
-# define CLI_LOG_FILE GB_LOGDIR "/gluster-block-cli.log"
-#define DEVNULLPATH "/dev/null"
-
-# define GFAPI_LOG_FILE GB_LOGDIR "/gluster-block-gfapi.log"
-# define GFAPI_LOG_LEVEL 7
-
-# define CONFIGSHELL_LOG_FILE GB_LOGDIR "/gluster-block-configshell.log"
-
-# define GB_METADIR "/block-meta"
-# define GB_STOREDIR "/block-store"
-# define GB_TXLOCKFILE "meta.lock"
-
-# define SUN_PATH_MAX (sizeof(struct sockaddr_un) - sizeof(unsigned short int)) /*sun_family*/
-
static const char *const JsonResponseFormatLookup[] = {
[GB_JSON_NONE] = "",
diff --git a/utils/utils.c b/utils/utils.c
index d66db8d..3c2b9ad 100644
--- a/utils/utils.c
+++ b/utils/utils.c
@@ -9,11 +9,14 @@
*/
+# include <dirent.h>
+# include <sys/stat.h>
+
# include "utils.h"
# include "config.h"
-size_t logLevel = GB_LOG_INFO;
+struct gbConf gbConf = {GB_LOG_INFO, GB_LOGDIR, '\0', '\0', '\0', '\0'};
const char *argp_program_version = "" \
PACKAGE_NAME" ("PACKAGE_VERSION")" \
@@ -172,6 +175,64 @@ out:
}
+static bool
+glusterBlockLogdirCreate(void)
+{
+ DIR* dir = opendir(gbConf.logDir);
+
+
+ if (dir) {
+ closedir(dir);
+ } else if (errno == ENOENT) {
+ if (mkdir(gbConf.logDir, 0755) == -1) {
+ fprintf(stderr, "mkdir(%s) failed (%s)", gbConf.logDir, strerror (errno));
+ return 0; /* False */
+ }
+ } else {
+ fprintf(stderr, "opendir(%s) failed (%s)", gbConf.logDir, strerror (errno));
+ return 0; /* False */
+ }
+
+ return 1;
+}
+
+
+int
+initLogging(void)
+{
+ char *logDir = NULL;
+
+
+ logDir = getenv("GB_LOGDIR");
+ if (!logDir) {
+ logDir = GB_LOGDIR;
+ }
+
+ if (strlen(logDir) > PATH_MAX - GB_MAX_LOGFILENAME) {
+ fprintf(stderr, "strlen of logDir Path > PATH_MAX: %s\n", logDir);
+ return EXIT_FAILURE;
+ }
+
+ /* set logfile paths */
+ snprintf(gbConf.logDir, PATH_MAX,
+ "%s", logDir);
+ snprintf(gbConf.daemonLogFile, PATH_MAX,
+ "%s/gluster-blockd.log", logDir);
+ snprintf(gbConf.cliLogFile, PATH_MAX,
+ "%s/gluster-block-cli.log", logDir);
+ snprintf(gbConf.gfapiLogFile, PATH_MAX,
+ "%s/gluster-block-gfapi.log", logDir);
+ snprintf(gbConf.configShellLogFile, PATH_MAX,
+ "%s/gluster-block-configshell.log", logDir);
+
+ if(!glusterBlockLogdirCreate()) {
+ return EXIT_FAILURE;
+ }
+
+ return 0;
+}
+
+
int
gbAlloc(void *ptrptr, size_t size,
const char *filename, const char *funcname, size_t linenr)
diff --git a/utils/utils.h b/utils/utils.h
index 1d82963..8e951fd 100644
--- a/utils/utils.h
+++ b/utils/utils.h
@@ -22,8 +22,28 @@
# include <unistd.h>
# include <errno.h>
# include <time.h>
+# include <limits.h>
# include <sys/time.h>
+# define GB_LOGDIR DATADIR "/log/gluster-block"
+# define GB_INFODIR DATADIR "/run"
+
+# define GB_LOCK_FILE GB_INFODIR "/gluster-blockd.lock"
+# define GB_UNIX_ADDRESS GB_INFODIR "/gluster-blockd.socket"
+# define GB_TCP_PORT 24006
+
+# define GFAPI_LOG_LEVEL 7
+
+# define DEVNULLPATH "/dev/null"
+
+# define GB_METADIR "/block-meta"
+# define GB_STOREDIR "/block-store"
+# define GB_TXLOCKFILE "meta.lock"
+
+# define GB_MAX_LOGFILENAME 64 /* max strlen of file name */
+
+# define SUN_PATH_MAX (sizeof(struct sockaddr_un) - sizeof(unsigned short int)) /*sun_family*/
+
# define GB_TIME_STRING_BUFLEN \
(4 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 6 + 1 + 5)
/* Yr Mon Day Hour Min Sec Ms NULL Round-off(32)
@@ -83,19 +103,29 @@
fprintf(stdout, fmt, __VA_ARGS__); \
} while (0)
-extern size_t logLevel;
+
+struct gbConf {
+ int logLevel;
+ char logDir[PATH_MAX];
+ char daemonLogFile[PATH_MAX];
+ char cliLogFile[PATH_MAX];
+ char gfapiLogFile[PATH_MAX];
+ char configShellLogFile[PATH_MAX];
+};
+
+extern struct gbConf gbConf;
# define LOG(str, level, fmt, ...) \
do { \
FILE *fd; \
char timestamp[GB_TIME_STRING_BUFLEN] = {0}; \
- if (level <= logLevel) { \
+ if (level <= gbConf.logLevel) { \
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"); \
+ fd = fopen (gbConf.daemonLogFile, "a"); \
+ else if (!strcmp(str, "cli")) \
+ fd = fopen (gbConf.cliLogFile, "a"); \
+ else if (!strcmp(str, "gfapi")) \
+ fd = fopen (gbConf.gfapiLogFile, "a"); \
else \
fd = stderr; \
if (fd == NULL) { \
@@ -406,6 +436,8 @@ int blockRemoteCreateRespEnumParse(const char *opt);
void logTimeNow(char* buf, size_t bufSize);
+int initLogging(void);
+
int gbAlloc(void *ptrptr, size_t size,
const char *filename, const char *funcname, size_t linenr);