diff options
author | ShyamsundarR <srangana@redhat.com> | 2013-12-20 13:19:00 +0530 |
---|---|---|
committer | Vijay Bellur <vbellur@redhat.com> | 2014-03-28 04:53:37 -0700 |
commit | 31e34cfd72712c76c127509d14d50eb008743fd5 (patch) | |
tree | 9d70b7768cb705215f7054df6069cb626ce4b189 /glusterfsd | |
parent | 326b77695f15444f79cea9822e35361e6bd167d5 (diff) |
log: enhance gluster log format with message ID and standardize errno reporting
Currently there are quite a slew of logs in Gluster that do not
lend themselves to trivial analysis by various tools that help
collect and monitor logs, due to the textual nature of the logs.
This FEAT is to make this better by giving logs message IDs so
that the tools do not have to do complex log parsing to break
it down to problem areas and suggest troubleshooting options.
With this patch, a new set of logging APIs are introduced that
take additionally a message ID and an error number, so as to
print the message ID and the descriptive string for the error.
New APIs:
- gf_msg, gf_msg_debug/trace, gf_msg_nomem, gf_msg_callingfn
These APIs follow the functionality of the previous gf_log*
counterparts, and hence are 1:1 replacements, with the delta
that, gf_msg, gf_msg_callingfn take additional parameters as
specified above.
Defining the log messages:
Each invocation of gf_msg/gf_msg_callingfn, should provide an ID
and an errnum (if available). Towards this, a common message id
file is provided, which contains defines to various messages and
their respective strings. As other messages are changed to the
new infrastructure APIs, it is intended that this file is edited
to add these messages as well.
Framework enhanced:
The logging framework is also enhanced to be able to support
different logging backends in the future. Hence new configuration
options for logging framework and logging formats are introduced.
Backward compatibility:
Currently the framework supports logging in the traditional
format, with the inclusion of an error string based on the errnum
passed in. Hence the shift to these new APIs would retain the log
file names, locations, and format with the exception of an
additional error string where applicable.
Testing done:
Tested the new APIs with different messages in normal code paths
Tested with configurations set to gluster logs (syslog pending)
Tested nomem variants, inducing the message in normal code paths
Tested ident generation for normal code paths (other paths
pending)
Tested with sample gfapi program for gfapi messages
Test code is stripped from the commit
Pending work (not to be addressed in this patch (future)):
- Logging framework should be configurable
- Logging format should be configurable
- Once all messages move to the new APIs deprecate/delete older
APIs to prevent misuse/abuse using the same
- Repeated log messages should be suppressed (as a configurable
option)
- Logging framework assumes that only one init is possible, but
there is no protection around the same (in existing code)
- gf_log_fini is not invoked anywhere and does very little
cleanup (in existing code)
- DOxygen comments to message id headers for each message
Change-Id: Ia043fda99a1c6cf7817517ef9e279bfcf35dcc24
BUG: 1075611
Signed-off-by: ShyamsundarR <srangana@redhat.com>
Reviewed-on: http://review.gluster.org/6547
Reviewed-by: Krutika Dhananjay <kdhananj@redhat.com>
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Raghavendra G <rgowdapp@redhat.com>
Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'glusterfsd')
-rw-r--r-- | glusterfsd/src/Makefile.am | 2 | ||||
-rw-r--r-- | glusterfsd/src/glusterfsd-messages.h | 111 | ||||
-rw-r--r-- | glusterfsd/src/glusterfsd.c | 275 |
3 files changed, 221 insertions, 167 deletions
diff --git a/glusterfsd/src/Makefile.am b/glusterfsd/src/Makefile.am index 05a10dee328..1797c32be35 100644 --- a/glusterfsd/src/Makefile.am +++ b/glusterfsd/src/Makefile.am @@ -6,7 +6,7 @@ glusterfsd_LDADD = $(top_builddir)/libglusterfs/src/libglusterfs.la \ $(top_builddir)/rpc/xdr/src/libgfxdr.la \ $(GF_LDADD) $(GF_GLUSTERFS_LIBS) glusterfsd_LDFLAGS = $(GF_LDFLAGS) -noinst_HEADERS = glusterfsd.h glusterfsd-mem-types.h +noinst_HEADERS = glusterfsd.h glusterfsd-mem-types.h glusterfsd-messages.h AM_CPPFLAGS = $(GF_CPPFLAGS) \ -I$(top_srcdir)/libglusterfs/src -DDATADIR=\"$(localstatedir)\" \ diff --git a/glusterfsd/src/glusterfsd-messages.h b/glusterfsd/src/glusterfsd-messages.h new file mode 100644 index 00000000000..48a0b17f6fb --- /dev/null +++ b/glusterfsd/src/glusterfsd-messages.h @@ -0,0 +1,111 @@ +/* + Copyright (c) 2013 Red Hat, Inc. <http://www.redhat.com> + This file is part of GlusterFS. + + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. +*/ + +#ifndef _GLUSTERFSD_MESSAGES_H_ +#define _GLUSTERFSD_MESSAGES_H_ + +#ifndef _CONFIG_H +#define _CONFIG_H +#include "config.h" +#endif + +#include "glfs-message-id.h" + +/* NOTE: Rules for message additions + * 1) Each instance of a message is _better_ left with a unique message ID, even + * if the message format is the same. Reasoning is that, if the message + * format needs to change in one instance, the other instances are not + * impacted or the new change does not change the ID of the instance being + * modified. + * 2) Addition of a message, + * - Should increment the GLFS_NUM_MESSAGES + * - Append to the list of messages defined, towards the end + * - Retain macro naming as glfs_msg_X (for redability across developers) + * NOTE: Rules for message format modifications + * 3) Check acorss the code if the message ID macro in question is reused + * anywhere. If reused then then the modifications should ensure correctness + * everywhere, or needs a new message ID as (1) above was not adhered to. If + * not used anywhere, proceed with the required modification. + * NOTE: Rules for message deletion + * 4) Check (3) and if used anywhere else, then cannot be deleted. If not used + * anywhere, then can be deleted, but will leave a hole by design, as + * addition rules specify modification to the end of the list and not filling + * holes. + */ + +#define GLFS_COMP_BASE GLFS_MSGID_COMP_GLUSTERFSD +#define GLFS_NUM_MESSAGES 33 +#define GLFS_MSGID_END (GLFS_COMP_BASE + GLFS_NUM_MESSAGES + 1) +/* Messaged with message IDs */ +#define glfs_msg_start_x GLFS_COMP_BASE, "Invalid: Start of messages" +/*------------*/ +#define glusterfsd_msg_1 (GLFS_COMP_BASE + 1), "Could not create absolute" \ + " mountpoint path" +#define glusterfsd_msg_2 (GLFS_COMP_BASE + 2), "Could not get current " \ + "working directory" +#define glusterfsd_msg_3 (GLFS_COMP_BASE + 3), "failed to set mount-point" \ + " to options dictionary" +#define glusterfsd_msg_4 (GLFS_COMP_BASE + 4), "failed to set dict value" \ + " for key %s" +#define glusterfsd_msg_5 (GLFS_COMP_BASE + 5), "failed to set 'disable'" \ + " for key %s" +#define glusterfsd_msg_6 (GLFS_COMP_BASE + 6), "failed to set 'enable'" \ + " for key %s" +#define glusterfsd_msg_7 (GLFS_COMP_BASE + 7), "Not a client process, not" \ + " performing mount operation" +#define glusterfsd_msg_8 (GLFS_COMP_BASE + 8), "MOUNT-POINT %s" \ + " initialization failed" +#define glusterfsd_msg_9 (GLFS_COMP_BASE + 9), "loading volume file %s" \ + " failed" +#define glusterfsd_msg_10 (GLFS_COMP_BASE + 10), "xlator option %s is" \ + " invalid" +#define glusterfsd_msg_11 (GLFS_COMP_BASE + 11), "Fetching the volume" \ + " file from server..." +#define glusterfsd_msg_12 (GLFS_COMP_BASE + 12), "volume initialization" \ + " failed." +#define glusterfsd_msg_13 (GLFS_COMP_BASE + 13), "ERROR: glusterfs uuid" \ + " generation failed" +#define glusterfsd_msg_14 (GLFS_COMP_BASE + 14), "ERROR: glusterfs %s" \ + " pool creation failed" +#define glusterfsd_msg_15 (GLFS_COMP_BASE + 15), "ERROR: '--volfile-id' is" \ + " mandatory if '-s' OR '--volfile-server'" \ + " option is given" +#define glusterfsd_msg_16 (GLFS_COMP_BASE + 16), "ERROR: parsing the" \ + " volfile failed" +#define glusterfsd_msg_17 (GLFS_COMP_BASE + 17), "pidfile %s open failed" +#define glusterfsd_msg_18 (GLFS_COMP_BASE + 18), "pidfile %s lock failed" +#define glusterfsd_msg_19 (GLFS_COMP_BASE + 19), "pidfile %s unlock failed" +#define glusterfsd_msg_20 (GLFS_COMP_BASE + 20), "pidfile %s truncation" \ + " failed" +#define glusterfsd_msg_21 (GLFS_COMP_BASE + 21), "pidfile %s write failed" +#define glusterfsd_msg_22 (GLFS_COMP_BASE + 22), "failed to execute" \ + " pthread_sigmask" +#define glusterfsd_msg_23 (GLFS_COMP_BASE + 23), "failed to create pthread" +#define glusterfsd_msg_24 (GLFS_COMP_BASE + 24), "daemonization failed" +#define glusterfsd_msg_25 (GLFS_COMP_BASE + 25), "mount failed" +#define glusterfsd_msg_26 (GLFS_COMP_BASE + 26), "failed to construct" \ + " the graph" +#define glusterfsd_msg_27 (GLFS_COMP_BASE + 27), "fuse xlator cannot be" \ + " specified in volume file" +#define glusterfsd_msg_28 (GLFS_COMP_BASE + 28), "Cannot reach volume" \ + " specification file" +#define glusterfsd_msg_29 (GLFS_COMP_BASE + 29), "ERROR: glusterfs context" \ + " not initialized" +#define glusterfsd_msg_30 (GLFS_COMP_BASE + 30), "Started running %s" \ + " version %s (args: %s)" +#define glusterfsd_msg_31 (GLFS_COMP_BASE + 31), "Could not create new" \ + " sync-environment" +#define glusterfsd_msg_32 (GLFS_COMP_BASE + 32), "received signum (%d)," \ + " shutting down" +/*------------*/ +#define glfs_msg_end_x GLFS_MSGID_END, "Invalid: End of messages" + + +#endif /* !_GLUSTERFSD_MESSAGES_H_ */ diff --git a/glusterfsd/src/glusterfsd.c b/glusterfsd/src/glusterfsd.c index 6a4655fc6fb..449fadda60d 100644 --- a/glusterfsd/src/glusterfsd.c +++ b/glusterfsd/src/glusterfsd.c @@ -50,6 +50,7 @@ #include "glusterfs.h" #include "compat.h" #include "logging.h" +#include "glusterfsd-messages.h" #include "dict.h" #include "list.h" #include "timer.h" @@ -240,14 +241,13 @@ set_fuse_mount_options (glusterfs_ctx_t *ctx, dict_t *options) ret = gf_asprintf (&mount_point, "%s/%s", cwd, cmd_args->mount_point); if (ret == -1) { - gf_log ("glusterfsd", GF_LOG_ERROR, - "Could not create absolute mountpoint " - "path"); + gf_msg ("glusterfsd", GF_LOG_ERROR, errno, + glusterfsd_msg_1); goto err; } } else { - gf_log ("glusterfsd", GF_LOG_ERROR, - "Could not get current working directory"); + gf_msg ("glusterfsd", GF_LOG_ERROR, errno, + glusterfsd_msg_2); goto err; } } else @@ -255,8 +255,7 @@ set_fuse_mount_options (glusterfs_ctx_t *ctx, dict_t *options) ret = dict_set_dynstr (options, ZR_MOUNTPOINT_OPT, mount_point); if (ret < 0) { - gf_log ("glusterfsd", GF_LOG_ERROR, - "failed to set mount-point to options dictionary"); + gf_msg ("glusterfsd", GF_LOG_ERROR, 0, glusterfsd_msg_3); goto err; } @@ -265,9 +264,8 @@ set_fuse_mount_options (glusterfs_ctx_t *ctx, dict_t *options) cmd_args->fuse_attribute_timeout); if (ret < 0) { - gf_log ("glusterfsd", GF_LOG_ERROR, - "failed to set dict value for key %s", - ZR_ATTR_TIMEOUT_OPT); + gf_msg ("glusterfsd", GF_LOG_ERROR, errno, + glusterfsd_msg_4, ZR_ATTR_TIMEOUT_OPT); goto err; } } @@ -276,8 +274,7 @@ set_fuse_mount_options (glusterfs_ctx_t *ctx, dict_t *options) ret = dict_set_double (options, ZR_ENTRY_TIMEOUT_OPT, cmd_args->fuse_entry_timeout); if (ret < 0) { - gf_log ("glusterfsd", GF_LOG_ERROR, - "failed to set dict value for key %s", + gf_msg ("glusterfsd", GF_LOG_ERROR, 0, glusterfsd_msg_4, ZR_ENTRY_TIMEOUT_OPT); goto err; } @@ -287,8 +284,7 @@ set_fuse_mount_options (glusterfs_ctx_t *ctx, dict_t *options) ret = dict_set_double (options, ZR_NEGATIVE_TIMEOUT_OPT, cmd_args->fuse_negative_timeout); if (ret < 0) { - gf_log ("glusterfsd", GF_LOG_ERROR, - "failed to set dict value for key %s", + gf_msg ("glusterfsd", GF_LOG_ERROR, 0, glusterfsd_msg_4, ZR_NEGATIVE_TIMEOUT_OPT); goto err; } @@ -298,8 +294,7 @@ set_fuse_mount_options (glusterfs_ctx_t *ctx, dict_t *options) ret = dict_set_int32 (options, "client-pid", cmd_args->client_pid); if (ret < 0) { - gf_log ("glusterfsd", GF_LOG_ERROR, - "failed to set dict value for key %s", + gf_msg ("glusterfsd", GF_LOG_ERROR, 0, glusterfsd_msg_4, "client-pid"); goto err; } @@ -309,8 +304,7 @@ set_fuse_mount_options (glusterfs_ctx_t *ctx, dict_t *options) ret = dict_set_int32 (options, "uid-map-root", cmd_args->uid_map_root); if (ret < 0) { - gf_log ("glusterfsd", GF_LOG_ERROR, - "failed to set dict value for key %s", + gf_msg ("glusterfsd", GF_LOG_ERROR, 0, glusterfsd_msg_4, "uid-map-root"); goto err; } @@ -320,8 +314,7 @@ set_fuse_mount_options (glusterfs_ctx_t *ctx, dict_t *options) ret = dict_set_int32 (options, ZR_STRICT_VOLFILE_CHECK, cmd_args->volfile_check); if (ret < 0) { - gf_log ("glusterfsd", GF_LOG_ERROR, - "failed to set dict value for key %s", + gf_msg ("glusterfsd", GF_LOG_ERROR, 0, glusterfsd_msg_4, ZR_STRICT_VOLFILE_CHECK); goto err; } @@ -331,8 +324,7 @@ set_fuse_mount_options (glusterfs_ctx_t *ctx, dict_t *options) ret = dict_set_static_ptr (options, ZR_DUMP_FUSE, cmd_args->dump_fuse); if (ret < 0) { - gf_log ("glusterfsd", GF_LOG_ERROR, - "failed to set dict value for key %s", + gf_msg ("glusterfsd", GF_LOG_ERROR, 0, glusterfsd_msg_4, ZR_DUMP_FUSE); goto err; } @@ -341,8 +333,8 @@ set_fuse_mount_options (glusterfs_ctx_t *ctx, dict_t *options) if (cmd_args->acl) { ret = dict_set_static_ptr (options, "acl", "on"); if (ret < 0) { - gf_log ("glusterfsd", GF_LOG_ERROR, - "failed to set dict value for key acl"); + gf_msg ("glusterfsd", GF_LOG_ERROR, 0, glusterfsd_msg_4, + "acl"); goto err; } } @@ -350,8 +342,8 @@ set_fuse_mount_options (glusterfs_ctx_t *ctx, dict_t *options) if (cmd_args->selinux) { ret = dict_set_static_ptr (options, "selinux", "on"); if (ret < 0) { - gf_log ("glusterfsd", GF_LOG_ERROR, - "failed to set dict value for key selinux"); + gf_msg ("glusterfsd", GF_LOG_ERROR, 0, glusterfsd_msg_4, + "selinux"); goto err; } } @@ -360,8 +352,7 @@ set_fuse_mount_options (glusterfs_ctx_t *ctx, dict_t *options) ret = dict_set_static_ptr (options, "virtual-gfid-access", "on"); if (ret < 0) { - gf_log ("glusterfsd", GF_LOG_ERROR, - "failed to set dict value for key " + gf_msg ("glusterfsd", GF_LOG_ERROR, 0, glusterfsd_msg_4, "aux-gfid-mount"); goto err; } @@ -370,8 +361,8 @@ set_fuse_mount_options (glusterfs_ctx_t *ctx, dict_t *options) if (cmd_args->enable_ino32) { ret = dict_set_static_ptr (options, "enable-ino32", "on"); if (ret < 0) { - gf_log ("glusterfsd", GF_LOG_ERROR, - "failed to set dict value for key enable-ino32"); + gf_msg ("glusterfsd", GF_LOG_ERROR, 0, glusterfsd_msg_4, + "enable-ino32"); goto err; } } @@ -379,8 +370,8 @@ set_fuse_mount_options (glusterfs_ctx_t *ctx, dict_t *options) if (cmd_args->read_only) { ret = dict_set_static_ptr (options, "read-only", "on"); if (ret < 0) { - gf_log ("glusterfsd", GF_LOG_ERROR, - "failed to set dict value for key read-only"); + gf_msg ("glusterfsd", GF_LOG_ERROR, 0, glusterfsd_msg_4, + "read-only"); goto err; } } @@ -390,8 +381,7 @@ set_fuse_mount_options (glusterfs_ctx_t *ctx, dict_t *options) ret = dict_set_static_ptr(options, "fopen-keep-cache", "on"); if (ret < 0) { - gf_log("glusterfsd", GF_LOG_ERROR, - "failed to set dict value for key " + gf_msg ("glusterfsd", GF_LOG_ERROR, 0, glusterfsd_msg_4, "fopen-keep-cache"); goto err; } @@ -400,17 +390,15 @@ set_fuse_mount_options (glusterfs_ctx_t *ctx, dict_t *options) ret = dict_set_static_ptr(options, "fopen-keep-cache", "off"); if (ret < 0) { - gf_log("glusterfsd", GF_LOG_ERROR, - "failed to set dict value for key " + gf_msg ("glusterfsd", GF_LOG_ERROR, 0, glusterfsd_msg_4, "fopen-keep-cache"); goto err; } break; case GF_OPTION_DEFERRED: /* default */ default: - gf_log ("glusterfsd", GF_LOG_DEBUG, - "fopen-keep-cache mode %d", - cmd_args->fopen_keep_cache); + gf_msg_debug ("glusterfsd", 0, "fopen-keep-cache mode %d", + cmd_args->fopen_keep_cache); break; } @@ -418,8 +406,8 @@ set_fuse_mount_options (glusterfs_ctx_t *ctx, dict_t *options) ret = dict_set_int32(options, "gid-timeout", cmd_args->gid_timeout); if (ret < 0) { - gf_log("glusterfsd", GF_LOG_ERROR, "failed to set dict " - "value for key gid-timeout"); + gf_msg ("glusterfsd", GF_LOG_ERROR, 0, glusterfsd_msg_4, + "gid-timeout"); goto err; } } @@ -427,8 +415,8 @@ set_fuse_mount_options (glusterfs_ctx_t *ctx, dict_t *options) ret = dict_set_int32 (options, "background-qlen", cmd_args->background_qlen); if (ret < 0) { - gf_log("glusterfsd", GF_LOG_ERROR, "failed to set dict " - "value for key background-qlen"); + gf_msg ("glusterfsd", GF_LOG_ERROR, 0, glusterfsd_msg_4, + "background-qlen"); goto err; } } @@ -436,8 +424,8 @@ set_fuse_mount_options (glusterfs_ctx_t *ctx, dict_t *options) ret = dict_set_int32 (options, "congestion-threshold", cmd_args->congestion_threshold); if (ret < 0) { - gf_log("glusterfsd", GF_LOG_ERROR, "failed to set dict " - "value for key congestion-threshold"); + gf_msg ("glusterfsd", GF_LOG_ERROR, 0, glusterfsd_msg_4, + "congestion-threshold"); goto err; } } @@ -447,8 +435,7 @@ set_fuse_mount_options (glusterfs_ctx_t *ctx, dict_t *options) ret = dict_set_static_ptr (options, ZR_DIRECT_IO_OPT, "disable"); if (ret < 0) { - gf_log ("glusterfsd", GF_LOG_ERROR, - "failed to set 'disable' for key %s", + gf_msg ("glusterfsd", GF_LOG_ERROR, 0, glusterfsd_msg_5, ZR_DIRECT_IO_OPT); goto err; } @@ -457,16 +444,15 @@ set_fuse_mount_options (glusterfs_ctx_t *ctx, dict_t *options) ret = dict_set_static_ptr (options, ZR_DIRECT_IO_OPT, "enable"); if (ret < 0) { - gf_log ("glusterfsd", GF_LOG_ERROR, - "failed to set 'enable' for key %s", + gf_msg ("glusterfsd", GF_LOG_ERROR, 0, glusterfsd_msg_6, ZR_DIRECT_IO_OPT); goto err; } break; case GF_OPTION_DEFERRED: /* default */ default: - gf_log ("", GF_LOG_DEBUG, "fuse direct io type %d", - cmd_args->fuse_direct_io_mode); + gf_msg_debug ("glusterfsd", 0, "fuse direct io type %d", + cmd_args->fuse_direct_io_mode); break; } @@ -500,8 +486,8 @@ set_fuse_mount_options (glusterfs_ctx_t *ctx, dict_t *options) ret = dict_set_static_ptr (options, "sync-to-mount", "enable"); if (ret < 0) { - gf_log ("glusterfsd", GF_LOG_ERROR, - "failed to set dict value for key sync-mtab"); + gf_msg ("glusterfsd", GF_LOG_ERROR, 0, glusterfsd_msg_4, + "sync-mtab"); goto err; } } @@ -510,8 +496,8 @@ set_fuse_mount_options (glusterfs_ctx_t *ctx, dict_t *options) ret = dict_set_str (options, "use-readdirp", cmd_args->use_readdirp); if (ret < 0) { - gf_log ("glusterfsd", GF_LOG_ERROR, "failed to set dict" - " value for key use-readdirp"); + gf_msg ("glusterfsd", GF_LOG_ERROR, 0, glusterfsd_msg_4, + "use-readdirp"); goto err; } } @@ -530,14 +516,13 @@ create_fuse_mount (glusterfs_ctx_t *ctx) cmd_args = &ctx->cmd_args; if (!cmd_args->mount_point) { - gf_log ("", GF_LOG_TRACE, - "mount point not found, not a client process"); + gf_msg_trace ("glusterfsd", 0, + "mount point not found, not a client process"); return 0; } if (ctx->process_mode != GF_CLIENT_PROCESS) { - gf_log("glusterfsd", GF_LOG_ERROR, - "Not a client process, not performing mount operation"); + gf_msg ("glusterfsd", GF_LOG_ERROR, 0, glusterfsd_msg_7); return -1; } @@ -551,8 +536,7 @@ create_fuse_mount (glusterfs_ctx_t *ctx) goto err; if (xlator_set_type (master, "mount/fuse") == -1) { - gf_log ("glusterfsd", GF_LOG_ERROR, - "MOUNT-POINT %s initialization failed", + gf_msg ("glusterfsd", GF_LOG_ERROR, errno, glusterfsd_msg_8, cmd_args->mount_point); goto err; } @@ -570,8 +554,7 @@ create_fuse_mount (glusterfs_ctx_t *ctx) ret = dict_set_static_ptr (master->options, ZR_FUSE_MOUNTOPTS, cmd_args->fuse_mountopts); if (ret < 0) { - gf_log ("glusterfsd", GF_LOG_ERROR, - "failed to set dict value for key %s", + gf_msg ("glusterfsd", GF_LOG_ERROR, 0, glusterfsd_msg_4, ZR_FUSE_MOUNTOPTS); goto err; } @@ -579,7 +562,8 @@ create_fuse_mount (glusterfs_ctx_t *ctx) ret = xlator_init (master); if (ret) { - gf_log ("", GF_LOG_DEBUG, "failed to initialize fuse translator"); + gf_msg_debug ("glusterfsd", 0, + "failed to initialize fuse translator"); goto err; } @@ -608,21 +592,19 @@ get_volfp (glusterfs_ctx_t *ctx) ret = sys_lstat (cmd_args->volfile, &statbuf); if (ret == -1) { - gf_log ("glusterfsd", GF_LOG_ERROR, - "%s: %s", cmd_args->volfile, strerror (errno)); + gf_msg ("glusterfsd", GF_LOG_ERROR, errno, glusterfsd_msg_9, + cmd_args->volfile); return NULL; } if ((specfp = fopen (cmd_args->volfile, "r")) == NULL) { - gf_log ("glusterfsd", GF_LOG_ERROR, - "volume file %s: %s", - cmd_args->volfile, - strerror (errno)); + gf_msg ("glusterfsd", GF_LOG_ERROR, errno, glusterfsd_msg_9, + cmd_args->volfile); return NULL; } - gf_log ("glusterfsd", GF_LOG_DEBUG, - "loading volume file %s", cmd_args->volfile); + gf_msg_debug ("glusterfsd", 0, "loading volume file %s", + cmd_args->volfile); return specfp; } @@ -658,8 +640,8 @@ gf_remember_backup_volfile_server (char *arg) } if (!server->volfile_server) { - gf_log ("", GF_LOG_WARNING, - "xlator option %s is invalid", arg); + gf_msg ("glusterfsd", GF_LOG_WARNING, 0, glusterfsd_msg_10, + arg); goto out; } @@ -700,8 +682,7 @@ gf_remember_xlator_option (char *arg) dot = strchr (arg, '.'); if (!dot) { - gf_log ("", GF_LOG_WARNING, - "xlator option %s is invalid", arg); + gf_msg ("", GF_LOG_WARNING, 0, glusterfsd_msg_10, arg); goto out; } @@ -714,8 +695,7 @@ gf_remember_xlator_option (char *arg) equals = strchr (arg, '='); if (!equals) { - gf_log ("", GF_LOG_WARNING, - "xlator option %s is invalid", arg); + gf_msg ("", GF_LOG_WARNING, 0, glusterfsd_msg_10, arg); goto out; } @@ -727,8 +707,7 @@ gf_remember_xlator_option (char *arg) strncpy (option->key, dot + 1, (equals - dot - 1)); if (!*(equals + 1)) { - gf_log ("", GF_LOG_WARNING, - "xlator option %s is invalid", arg); + gf_msg ("", GF_LOG_WARNING, 0, glusterfsd_msg_10, arg); goto out; } @@ -1124,8 +1103,7 @@ cleanup_and_exit (int signum) if (!ctx) return; - gf_log_callingfn ("", GF_LOG_WARNING, - "received signum (%d), shutting down", signum); + gf_msg_callingfn ("", GF_LOG_WARNING, 0, glusterfsd_msg_32, signum); if (ctx->cleanup_started) return; @@ -1190,20 +1168,19 @@ reincarnate (int signum) cmd_args = &ctx->cmd_args; if (cmd_args->volfile_server) { - gf_log ("glusterfsd", GF_LOG_INFO, - "Fetching the volume file from server..."); + gf_msg ("glusterfsd", GF_LOG_INFO, 0, glusterfsd_msg_11); ret = glusterfs_volfile_fetch (ctx); } else { - gf_log ("glusterfsd", GF_LOG_DEBUG, - "Not reloading volume specification file on SIGHUP"); + gf_msg_debug ("glusterfsd", 0, + "Not reloading volume specification file" + " on SIGHUP"); } /* Also, SIGHUP should do logrotate */ gf_log_logrotate (1); if (ret < 0) - gf_log ("glusterfsd", GF_LOG_ERROR, - "volume initialization failed."); + gf_msg ("glusterfsd", GF_LOG_ERROR, 0, glusterfsd_msg_12); return; } @@ -1253,8 +1230,7 @@ glusterfs_ctx_defaults_init (glusterfs_ctx_t *ctx) ctx->process_uuid = generate_glusterfs_ctx_id (); if (!ctx->process_uuid) { - gf_log ("", GF_LOG_CRITICAL, - "ERROR: glusterfs uuid generation failed"); + gf_msg ("", GF_LOG_CRITICAL, 0, glusterfsd_msg_13); goto out; } @@ -1262,22 +1238,19 @@ glusterfs_ctx_defaults_init (glusterfs_ctx_t *ctx) ctx->iobuf_pool = iobuf_pool_new (); if (!ctx->iobuf_pool) { - gf_log ("", GF_LOG_CRITICAL, - "ERROR: glusterfs iobuf pool creation failed"); + gf_msg ("", GF_LOG_CRITICAL, 0, glusterfsd_msg_14, "iobuf"); goto out; } ctx->event_pool = event_pool_new (DEFAULT_EVENT_POOL_SIZE); if (!ctx->event_pool) { - gf_log ("", GF_LOG_CRITICAL, - "ERROR: glusterfs event pool creation failed"); + gf_msg ("", GF_LOG_CRITICAL, 0, glusterfsd_msg_14, "event"); goto out; } ctx->pool = GF_CALLOC (1, sizeof (call_pool_t), gfd_mt_call_pool_t); if (!ctx->pool) { - gf_log ("", GF_LOG_CRITICAL, - "ERROR: glusterfs call pool creation failed"); + gf_msg ("", GF_LOG_CRITICAL, 0, glusterfsd_msg_14, "call"); goto out; } @@ -1287,22 +1260,19 @@ glusterfs_ctx_defaults_init (glusterfs_ctx_t *ctx) /* frame_mem_pool size 112 * 4k */ ctx->pool->frame_mem_pool = mem_pool_new (call_frame_t, 4096); if (!ctx->pool->frame_mem_pool) { - gf_log ("", GF_LOG_CRITICAL, - "ERROR: glusterfs frame pool creation failed"); + gf_msg ("", GF_LOG_CRITICAL, 0, glusterfsd_msg_14, "frame"); goto out; } /* stack_mem_pool size 256 * 1024 */ ctx->pool->stack_mem_pool = mem_pool_new (call_stack_t, 1024); if (!ctx->pool->stack_mem_pool) { - gf_log ("", GF_LOG_CRITICAL, - "ERROR: glusterfs stack pool creation failed"); + gf_msg ("", GF_LOG_CRITICAL, 0, glusterfsd_msg_14, "stack"); goto out; } ctx->stub_mem_pool = mem_pool_new (call_stub_t, 1024); if (!ctx->stub_mem_pool) { - gf_log ("", GF_LOG_CRITICAL, - "ERROR: glusterfs stub pool creation failed"); + gf_msg ("", GF_LOG_CRITICAL, 0, glusterfsd_msg_14, "stub"); goto out; } @@ -1373,43 +1343,36 @@ logging_init (glusterfs_ctx_t *ctx, const char *progpath) { cmd_args_t *cmd_args = NULL; int ret = 0; - char ident[1024] = {0,}; - char *progname = NULL; - char *ptr = NULL; cmd_args = &ctx->cmd_args; if (cmd_args->log_file == NULL) { ret = gf_set_log_file_path (cmd_args); if (ret == -1) { - fprintf (stderr, "ERROR: failed to set the log file path\n"); + fprintf (stderr, "ERROR: failed to set the log file " + "path\n"); return -1; } } -#ifdef GF_USE_SYSLOG - progname = gf_strdup (progpath); - snprintf (ident, 1024, "%s_%s", basename(progname), - basename(cmd_args->log_file)); - GF_FREE (progname); - /* remove .log suffix */ - if (NULL != (ptr = strrchr(ident, '.'))) { - if (strcmp(ptr, ".log") == 0) { - /* note: ptr points to location in ident only */ - ptr[0] = '\0'; + if (cmd_args->log_ident == NULL) { + ret = gf_set_log_ident (cmd_args); + if (ret == -1) { + fprintf (stderr, "ERROR: failed to set the log " + "identity\n"); + return -1; } } - ptr = ident; -#endif - if (gf_log_init (ctx, cmd_args->log_file, ptr) == -1) { + /* finish log set parameters before init */ + gf_log_set_loglevel (cmd_args->log_level); + + if (gf_log_init (ctx, cmd_args->log_file, cmd_args->log_ident) == -1) { fprintf (stderr, "ERROR: failed to open logfile %s\n", cmd_args->log_file); return -1; } - gf_log_set_loglevel (cmd_args->log_level); - return 0; } @@ -1453,9 +1416,7 @@ parse_cmdline (int argc, char *argv[], glusterfs_ctx_t *ctx) /* Make sure after the parsing cli, if '--volfile-server' option is given, then '--volfile-id' is mandatory */ if (cmd_args->volfile_server && !cmd_args->volfile_id) { - gf_log ("glusterfs", GF_LOG_CRITICAL, - "ERROR: '--volfile-id' is mandatory if '-s' OR " - "'--volfile-server' option is given"); + gf_msg ("glusterfs", GF_LOG_CRITICAL, 0, glusterfsd_msg_15); ret = -1; goto out; } @@ -1473,9 +1434,8 @@ parse_cmdline (int argc, char *argv[], glusterfs_ctx_t *ctx) and exit */ ret = stat (cmd_args->volfile, &stbuf); if (ret) { - gf_log ("glusterfs", GF_LOG_CRITICAL, - "ERROR: parsing the volfile failed (%s)\n", - strerror (errno)); + gf_msg ("glusterfs", GF_LOG_CRITICAL, errno, + glusterfsd_msg_16); /* argp_usage (argp.) */ fprintf (stderr, "USAGE: %s [options] [mountpoint]\n", argv[0]); @@ -1551,9 +1511,8 @@ glusterfs_pidfile_setup (glusterfs_ctx_t *ctx) pidfp = fopen (cmd_args->pid_file, "a+"); if (!pidfp) { - gf_log ("glusterfsd", GF_LOG_ERROR, - "pidfile %s error (%s)", - cmd_args->pid_file, strerror (errno)); + gf_msg ("glusterfsd", GF_LOG_ERROR, errno, glusterfsd_msg_17, + cmd_args->pid_file); goto out; } @@ -1576,9 +1535,8 @@ glusterfs_pidfile_cleanup (glusterfs_ctx_t *ctx) if (!ctx->pidfp) return 0; - gf_log ("glusterfsd", GF_LOG_TRACE, - "pidfile %s cleanup", - cmd_args->pid_file); + gf_msg_trace ("glusterfsd", 0, "pidfile %s cleanup", + cmd_args->pid_file); if (ctx->cmd_args.pid_file) { unlink (ctx->cmd_args.pid_file); @@ -1607,39 +1565,34 @@ glusterfs_pidfile_update (glusterfs_ctx_t *ctx) ret = lockf (fileno (pidfp), F_TLOCK, 0); if (ret) { - gf_log ("glusterfsd", GF_LOG_ERROR, - "pidfile %s lock failed", + gf_msg ("glusterfsd", GF_LOG_ERROR, errno, glusterfsd_msg_18, cmd_args->pid_file); return ret; } ret = ftruncate (fileno (pidfp), 0); if (ret) { - gf_log ("glusterfsd", GF_LOG_ERROR, - "pidfile %s truncation failed", + gf_msg ("glusterfsd", GF_LOG_ERROR, errno, glusterfsd_msg_20, cmd_args->pid_file); return ret; } ret = fprintf (pidfp, "%d\n", getpid ()); if (ret <= 0) { - gf_log ("glusterfsd", GF_LOG_ERROR, - "pidfile %s write failed", + gf_msg ("glusterfsd", GF_LOG_ERROR, errno, glusterfsd_msg_21, cmd_args->pid_file); return ret; } ret = fflush (pidfp); if (ret) { - gf_log ("glusterfsd", GF_LOG_ERROR, - "pidfile %s write failed", + gf_msg ("glusterfsd", GF_LOG_ERROR, errno, glusterfsd_msg_21, cmd_args->pid_file); return ret; } - gf_log ("glusterfsd", GF_LOG_DEBUG, - "pidfile %s updated with pid %d", - cmd_args->pid_file, getpid ()); + gf_msg_debug ("glusterfsd", 0, "pidfile %s updated with pid %d", + cmd_args->pid_file, getpid ()); return 0; } @@ -1723,9 +1676,7 @@ glusterfs_signals_setup (glusterfs_ctx_t *ctx) ret = pthread_sigmask (SIG_BLOCK, &set, NULL); if (ret) { - gf_log ("glusterfsd", GF_LOG_WARNING, - "failed to execute pthread_signmask %s", - strerror (errno)); + gf_msg ("glusterfsd", GF_LOG_WARNING, errno, glusterfsd_msg_22); return ret; } @@ -1737,9 +1688,7 @@ glusterfs_signals_setup (glusterfs_ctx_t *ctx) fallback to signals getting handled by other threads. setup the signal handlers */ - gf_log ("glusterfsd", GF_LOG_WARNING, - "failed to create pthread %s", - strerror (errno)); + gf_msg ("glusterfsd", GF_LOG_WARNING, errno, glusterfsd_msg_23); return ret; } @@ -1784,8 +1733,7 @@ daemonize (glusterfs_ctx_t *ctx) close (ctx->daemon_pipe[1]); } - gf_log ("daemonize", GF_LOG_ERROR, - "Daemonization failed: %s", strerror(errno)); + gf_msg ("daemonize", GF_LOG_ERROR, errno, glusterfsd_msg_24); goto out; case 0: /* child */ @@ -1800,8 +1748,8 @@ daemonize (glusterfs_ctx_t *ctx) if (ctx->mnt_pid > 0) { ret = waitpid (ctx->mnt_pid, &cstatus, 0); if (!(ret == ctx->mnt_pid && cstatus == 0)) { - gf_log ("daemonize", GF_LOG_ERROR, - "mount failed"); + gf_msg ("daemonize", GF_LOG_ERROR, 0, + glusterfsd_msg_25); exit (1); } } @@ -1831,15 +1779,14 @@ glusterfs_process_volfp (glusterfs_ctx_t *ctx, FILE *fp) graph = glusterfs_graph_construct (fp); if (!graph) { - gf_log ("", GF_LOG_ERROR, "failed to construct the graph"); + gf_msg ("", GF_LOG_ERROR, 0, glusterfsd_msg_26); goto out; } for (trav = graph->first; trav; trav = trav->next) { if (strcmp (trav->type, "mount/fuse") == 0) { - gf_log ("glusterfsd", GF_LOG_ERROR, - "fuse xlator cannot be specified " - "in volume file"); + gf_msg ("glusterfsd", GF_LOG_ERROR, 0, + glusterfsd_msg_27); goto out; } } @@ -1897,8 +1844,7 @@ glusterfs_volumes_init (glusterfs_ctx_t *ctx) fp = get_volfp (ctx); if (!fp) { - gf_log ("glusterfsd", GF_LOG_ERROR, - "Cannot reach volume specification file"); + gf_msg ("glusterfsd", GF_LOG_ERROR, 0, glusterfsd_msg_28); ret = -1; goto out; } @@ -1925,8 +1871,7 @@ main (int argc, char *argv[]) ctx = glusterfs_ctx_new (); if (!ctx) { - gf_log ("glusterfs", GF_LOG_CRITICAL, - "ERROR: glusterfs context not initialized"); + gf_msg ("glusterfs", GF_LOG_CRITICAL, 0, glusterfsd_msg_29); return ENOMEM; } glusterfsd_ctx = ctx; @@ -1965,8 +1910,7 @@ main (int argc, char *argv[]) strcat (cmdlinestr, " "); strcat (cmdlinestr, argv[i]); } - gf_log (argv[0], GF_LOG_INFO, - "Started running %s version %s (%s)", + gf_msg (argv[0], GF_LOG_INFO, 0, glusterfsd_msg_30, argv[0], PACKAGE_VERSION, cmdlinestr); } @@ -1982,8 +1926,7 @@ main (int argc, char *argv[]) ctx->env = syncenv_new (0, 0, 0); if (!ctx->env) { - gf_log ("", GF_LOG_ERROR, - "Could not create new sync-environment"); + gf_msg ("", GF_LOG_ERROR, 0, glusterfsd_msg_31); goto out; } |