[sheepdog] [PATCH] sheep: add an option for selecting the output directory of sheep.log

Teruaki Ishizaki ishizaki.teruaki at lab.ntt.co.jp
Mon Dec 9 12:49:45 CET 2013


Previously sheep.log was saved in the Sheepdog store directory,
and used size of Sheepdog store directory included log file size.
So, administrator couldn't do capacity planning simply.

This patch adds an option for setting the output directory of sheep.log.

Usage:
	$ sheep -L dir=<log_output_dir>

Example:
	$ sheep -L dir=/logdir /datastore

Signed-off-by: Teruaki Ishizaki <ishizaki.teruaki at lab.ntt.co.jp>
---
 sheep/sheep.c |   36 ++++++++++++++++++++++++++++++++++--
 1 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/sheep/sheep.c b/sheep/sheep.c
index 9d9afa0..fc4982c 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -98,6 +98,12 @@ static const char cache_help[] =
 "This tries to use /my_ssd as the cache storage with 200G allocted to the\n"
 "cache in directio mode\n";
 
+static const char logdir_help[] =
+"Example:\n\t$ sheep -L dir=/var/log/ ...\n"
+"Available arguments:\n"
+"\tdir=: path to the location of sheep.log\n"
+"if not specified use datastore directory\n";
+
 static struct sd_option sheep_options[] = {
 	{'b', "bindaddr", true, "specify IP address of interface to listen on",
 	 bind_help},
@@ -116,6 +122,7 @@ static struct sd_option sheep_options[] = {
 	 "operations. (default: disabled)", journal_help},
 	{'l', "loglevel", true, "specify the level of logging detail "
 	 "(default: 6 [SDOG_INFO])", loglevel_help},
+	{'L', "logdir", true, "output directory of sheep.log", logdir_help},
 	{'n', "nosync", false, "drop O_SYNC for write of backend"},
 	{'o', "stdout", false, "log to stdout instead of shared logger"},
 	{'p', "port", true, "specify the TCP port on which to listen "
@@ -302,6 +309,20 @@ static struct option_parser cache_parsers[] = {
 	{ NULL, NULL },
 };
 
+static char ologpath[PATH_MAX];
+
+static int log_dir_parser(const char *s)
+{
+	snprintf(ologpath, sizeof(ologpath), "%s", s);
+	return 0;
+}
+
+static struct option_parser log_parsers[] = {
+	{ "dir=", log_dir_parser },
+	{ NULL, NULL },
+};
+
+
 static const char *io_addr, *io_pt;
 static int ionic_host_parser(const char *s)
 {
@@ -545,7 +566,7 @@ int main(int argc, char **argv)
 	int log_level = SDOG_INFO, nr_vnodes = SD_DEFAULT_VNODES;
 	const char *dirp = DEFAULT_OBJECT_DIR, *short_options;
 	char *dir, *p, *pid_file = NULL, *bindaddr = NULL, path[PATH_MAX],
-	     *argp = NULL;
+	     *argp = NULL, *logdir = NULL;
 	bool is_daemon = true, to_stdout = false, explicit_addr = false;
 	int64_t zone = -1;
 	struct cluster_driver *cdrv;
@@ -589,6 +610,15 @@ int main(int argc, char **argv)
 				exit(1);
 			}
 			break;
+		case 'L':
+			if (option_parse(optarg, ",", log_parsers) < 0)
+				exit(1);
+			logdir = realpath(ologpath, NULL);
+			if (!logdir) {
+				sd_err("%m");
+				exit(1);
+			}
+			break;
 		case 'n':
 			sys->nosync = true;
 			break;
@@ -723,7 +753,9 @@ int main(int argc, char **argv)
 		exit(1);
 	}
 
-	snprintf(path, sizeof(path), "%s/" LOG_FILE_NAME, dir);
+	snprintf(path, sizeof(path), "%s/" LOG_FILE_NAME, logdir ? logdir : dir);
+
+	free(logdir);
 
 	srandom(port);
 
-- 
1.7.2.5




More information about the sheepdog mailing list