From 31e34cfd72712c76c127509d14d50eb008743fd5 Mon Sep 17 00:00:00 2001 From: ShyamsundarR Date: Fri, 20 Dec 2013 13:19:00 +0530 Subject: 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 Reviewed-on: http://review.gluster.org/6547 Reviewed-by: Krutika Dhananjay Tested-by: Gluster Build System Reviewed-by: Raghavendra G Reviewed-by: Pranith Kumar Karampuri Reviewed-by: Vijay Bellur --- glusterfsd/src/Makefile.am | 2 +- glusterfsd/src/glusterfsd-messages.h | 111 ++++++++++++++ glusterfsd/src/glusterfsd.c | 275 ++++++++++++++--------------------- 3 files changed, 221 insertions(+), 167 deletions(-) create mode 100644 glusterfsd/src/glusterfsd-messages.h (limited to 'glusterfsd/src') diff --git a/glusterfsd/src/Makefile.am b/glusterfsd/src/Makefile.am index 05a10dee3..1797c32be 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 000000000..48a0b17f6 --- /dev/null +++ b/glusterfsd/src/glusterfsd-messages.h @@ -0,0 +1,111 @@ +/* + Copyright (c) 2013 Red Hat, Inc. + 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 6a4655fc6..449fadda6 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; } -- cgit From d586ecc0a501440436a918ed973fd75facafc455 Mon Sep 17 00:00:00 2001 From: Krutika Dhananjay Date: Sun, 30 Mar 2014 08:37:02 +0530 Subject: log: Add missing log message from glusterfsd.c to glusterfsd-messages.h ... by retaining GLFS_NUM_MESSAGES as 33 which is its correct value. Also replace all occurrences of gf_log with gf_msg/gf_msg_debug. Change-Id: Ibfbe1d645de521e8d59ca406f78b1a8eb08aa7e0 BUG: 1075611 Signed-off-by: Krutika Dhananjay Reviewed-on: http://review.gluster.org/7371 Tested-by: Gluster Build System Reviewed-by: Vijay Bellur --- glusterfsd/src/glusterfsd-messages.h | 3 +++ glusterfsd/src/glusterfsd.c | 12 ++++-------- 2 files changed, 7 insertions(+), 8 deletions(-) (limited to 'glusterfsd/src') diff --git a/glusterfsd/src/glusterfsd-messages.h b/glusterfsd/src/glusterfsd-messages.h index 48a0b17f6..3165c971f 100644 --- a/glusterfsd/src/glusterfsd-messages.h +++ b/glusterfsd/src/glusterfsd-messages.h @@ -104,6 +104,9 @@ " sync-environment" #define glusterfsd_msg_32 (GLFS_COMP_BASE + 32), "received signum (%d)," \ " shutting down" +#define glusterfsd_msg_33 (GLFS_COMP_BASE + 33), "obsolete option " \ + "'--volfile-max-fetch-attempts or fetch-attempts' " \ + "was provided" /*------------*/ #define glfs_msg_end_x GLFS_MSGID_END, "Invalid: End of messages" diff --git a/glusterfsd/src/glusterfsd.c b/glusterfsd/src/glusterfsd.c index 449fadda6..9c9fad96e 100644 --- a/glusterfsd/src/glusterfsd.c +++ b/glusterfsd/src/glusterfsd.c @@ -461,8 +461,7 @@ set_fuse_mount_options (glusterfs_ctx_t *ctx, dict_t *options) ret = dict_set_static_ptr (options, "no-root-squash", "enable"); if (ret < 0) { - gf_log ("glusterfsd", GF_LOG_ERROR, - "failed to set 'enable' for key " + gf_msg ("glusterfsd", GF_LOG_ERROR, 0, glusterfsd_msg_6, "no-root-squash"); goto err; } @@ -472,12 +471,11 @@ set_fuse_mount_options (glusterfs_ctx_t *ctx, dict_t *options) ret = dict_set_static_ptr (options, "no-root-squash", "disable"); if (ret < 0) { - gf_log ("glusterfsd", GF_LOG_ERROR, - "failed to set 'disable' for key " + gf_msg ("glusterfsd", GF_LOG_ERROR, 0, glusterfsd_msg_5, "no-root-squash"); goto err; } - gf_log ("", GF_LOG_DEBUG, "fuse no-root-squash mode %d", + gf_msg_debug ("glusterfsd", 0, "fuse no-root-squash mode %d", cmd_args->no_root_squash); break; } @@ -1481,9 +1479,7 @@ parse_cmdline (int argc, char *argv[], glusterfs_ctx_t *ctx) compatibility with third party applications */ if (cmd_args->max_connect_attempts) { - gf_log ("glusterfs", GF_LOG_WARNING, - "obsolete option '--volfile-max-fetch-attempts" - " or fetch-attempts' was provided"); + gf_msg ("glusterfs", GF_LOG_WARNING, 0, glusterfsd_msg_33); } #ifdef GF_DARWIN_HOST_OS -- cgit From 29bccc2ed18eedc40e83d2f0d35327037a322384 Mon Sep 17 00:00:00 2001 From: Avra Sengupta Date: Wed, 19 Feb 2014 16:30:11 +0530 Subject: gluster: GlusterFS Volume Snapshot Feature This is the initial patch for the Snapshot feature. Current patch includes following features: * Snapshot create * Snapshot delete * Snapshot restore * Snapshot list * Snapshot info * Snapshot status * Snapshot config Change-Id: I2f46920c0d61c515f6a60e0f8b46fff886d9f6a9 BUG: 1061685 Signed-off-by: shishir gowda Signed-off-by: Sachin Pandit Signed-off-by: Vijaikumar M Signed-off-by: Raghavendra Bhat Signed-off-by: Rajesh Joseph Signed-off-by: Joseph Fernandes Signed-off-by: Avra Sengupta Reviewed-on: http://review.gluster.org/7128 Tested-by: Gluster Build System Reviewed-by: Vijay Bellur --- glusterfsd/src/glusterfsd-mgmt.c | 78 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) (limited to 'glusterfsd/src') diff --git a/glusterfsd/src/glusterfsd-mgmt.c b/glusterfsd/src/glusterfsd-mgmt.c index d4201b38e..c42228a04 100644 --- a/glusterfsd/src/glusterfsd-mgmt.c +++ b/glusterfsd/src/glusterfsd-mgmt.c @@ -1128,6 +1128,83 @@ out: return ret; } +int +glusterfs_handle_volume_barrier_op (rpcsvc_request_t *req) +{ + int32_t ret = -1; + gd1_mgmt_brick_op_req xlator_req = {0,}; + dict_t *dict = NULL; + xlator_t *xlator = NULL; + xlator_t *any = NULL; + dict_t *output = NULL; + char msg[2048] = {0}; + glusterfs_ctx_t *ctx = NULL; + glusterfs_graph_t *active = NULL; + xlator_t *this = NULL; + + GF_ASSERT (req); + this = THIS; + GF_ASSERT (this); + + ctx = glusterfsd_ctx; + GF_ASSERT (ctx); + + active = ctx->active; + if (!active) { + req->rpc_err = GARBAGE_ARGS; + goto out; + } + + any = active->first; + ret = xdr_to_generic (req->msg[0], &xlator_req, + (xdrproc_t)xdr_gd1_mgmt_brick_op_req); + if (ret < 0) { + //failed to decode msg; + req->rpc_err = GARBAGE_ARGS; + goto out; + } + dict = dict_new (); + if (!dict) + goto out; + + ret = dict_unserialize (xlator_req.input.input_val, + xlator_req.input.input_len, + &dict); + if (ret < 0) { + gf_log (this->name, GF_LOG_ERROR, + "failed to " + "unserialize req-buffer to dictionary"); + goto out; + } + xlator = xlator_search_by_name (any, xlator_req.name); + if (!xlator) { + snprintf (msg, sizeof (msg), "xlator %s is not loaded", + xlator_req.name); + goto out; + } + + output = dict_new (); + if (!output) { + ret = -1; + goto out; + } + + ret = xlator->notify (xlator, GF_EVENT_VOLUME_BARRIER_OP, + dict, output); + + ret = glusterfs_translator_info_response_send (req, ret, + msg, output); +out: + if (dict) + dict_unref (dict); + free (xlator_req.input.input_val); // malloced by xdr + if (output) + dict_unref (output); + free (xlator_req.name); //malloced by xdr + + return ret; + +} int glusterfs_handle_rpc_msg (rpcsvc_request_t *req) { @@ -1192,6 +1269,7 @@ rpcsvc_actor_t glusterfs_actors[] = { [GLUSTERD_BRICK_XLATOR_DEFRAG] = {"TRANSLATOR DEFRAG", GLUSTERD_BRICK_XLATOR_DEFRAG, glusterfs_handle_defrag, NULL, 0, DRC_NA}, [GLUSTERD_NODE_PROFILE] = {"NFS PROFILE", GLUSTERD_NODE_PROFILE, glusterfs_handle_nfs_profile, NULL, 0, DRC_NA}, [GLUSTERD_NODE_STATUS] = {"NFS STATUS", GLUSTERD_NODE_STATUS, glusterfs_handle_node_status, NULL, 0, DRC_NA}, + [GLUSTERD_VOLUME_BARRIER_OP] = {"VOLUME BARRIER OP", GLUSTERD_VOLUME_BARRIER_OP, glusterfs_handle_volume_barrier_op, NULL, 0, DRC_NA}, }; struct rpcsvc_program glusterfs_mop_prog = { -- cgit From 712541cdefcc9614e5a79f628358f205ceda6e55 Mon Sep 17 00:00:00 2001 From: Krutika Dhananjay Date: Tue, 11 Mar 2014 15:05:44 +0530 Subject: logging: Make logger and log format configurable through cli Change-Id: Ic4b701a6621578848ff67ae4ecb5a10b5f32f93b BUG: 1075611 Signed-off-by: Krutika Dhananjay Reviewed-on: http://review.gluster.org/7372 Tested-by: Gluster Build System Reviewed-by: Krishnan Parthasarathi Reviewed-by: Vijay Bellur --- glusterfsd/src/glusterfsd.c | 32 ++++++++++++++++++++++++++++++++ glusterfsd/src/glusterfsd.h | 2 ++ 2 files changed, 34 insertions(+) (limited to 'glusterfsd/src') diff --git a/glusterfsd/src/glusterfsd.c b/glusterfsd/src/glusterfsd.c index 9c9fad96e..531932619 100644 --- a/glusterfsd/src/glusterfsd.c +++ b/glusterfsd/src/glusterfsd.c @@ -110,6 +110,11 @@ static struct argp_option gf_options[] = { {"log-file", ARGP_LOG_FILE_KEY, "LOGFILE", 0, "File to use for logging [default: " DEFAULT_LOG_FILE_DIRECTORY "/" PACKAGE_NAME ".log" "]"}, + {"logger", ARGP_LOGGER, "LOGGER", 0, "Set which logging sub-system to " + "log to, valid options are: gluster-log and syslog, " + "[default: \"gluster-log\"]"}, + {"log-format", ARGP_LOG_FORMAT, "LOG-FORMAT", 0, "Set log format, valid" + " options are: no-msg-id and with-msg-id, [default: \"with-msg-id\"]"}, {0, 0, 0, 0, "Advanced Options:"}, {"volfile-server-port", ARGP_VOLFILE_SERVER_PORT_KEY, "PORT", 0, @@ -1084,6 +1089,27 @@ parse_opts (int key, char *arg, struct argp_state *state) "unknown use-readdirp setting \"%s\"", arg); break; + case ARGP_LOGGER: + if (strcasecmp (arg, GF_LOGGER_GLUSTER_LOG) == 0) + cmd_args->logger = gf_logger_glusterlog; + else if (strcasecmp (arg, GF_LOGGER_SYSLOG) == 0) + cmd_args->logger = gf_logger_syslog; + else + argp_failure (state, -1, 0, "unknown logger %s", arg); + + break; + + case ARGP_LOG_FORMAT: + if (strcasecmp (arg, GF_LOG_FORMAT_NO_MSG_ID) == 0) + cmd_args->log_format = gf_logformat_traditional; + else if (strcasecmp (arg, GF_LOG_FORMAT_WITH_MSG_ID) == 0) + cmd_args->log_format = gf_logformat_withmsgid; + else + argp_failure (state, -1, 0, "unknown log format %s", + arg); + + break; + } return 0; @@ -1297,6 +1323,8 @@ glusterfs_ctx_defaults_init (glusterfs_ctx_t *ctx) /* parsing command line arguments */ cmd_args->log_level = DEFAULT_LOG_LEVEL; + cmd_args->logger = gf_logger_glusterlog; + cmd_args->log_format = gf_logformat_withmsgid; cmd_args->mac_compat = GF_OPTION_DISABLE; #ifdef GF_DARWIN_HOST_OS @@ -1365,6 +1393,10 @@ logging_init (glusterfs_ctx_t *ctx, const char *progpath) /* finish log set parameters before init */ gf_log_set_loglevel (cmd_args->log_level); + gf_log_set_logger (cmd_args->logger); + + gf_log_set_logformat (cmd_args->log_format); + 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); diff --git a/glusterfsd/src/glusterfsd.h b/glusterfsd/src/glusterfsd.h index ad4c3699b..24487b4d4 100644 --- a/glusterfsd/src/glusterfsd.h +++ b/glusterfsd/src/glusterfsd.h @@ -85,6 +85,8 @@ enum argp_option_keys { ARGP_FUSE_USE_READDIRP_KEY = 165, ARGP_AUX_GFID_MOUNT_KEY = 166, ARGP_FUSE_NO_ROOT_SQUASH_KEY = 167, + ARGP_LOGGER = 168, + ARGP_LOG_FORMAT = 169, }; struct _gfd_vol_top_priv_t { -- cgit