Skip to contentSkip to conversation

libcldc: propagate verbosity

PATCH New Pete Zaitcev 1 participant 1 message Feb 9, 2010 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libcldc: propagate verbosity

It has been observed that it's not possible to enable the session-level verbose dump with -v switch of cldcli anymore (post XDR and ncld).

The main issue is that it is impossible to set the session verbosity by an application control. Secondary issue is that if application attempts to change the verbosity level, it cannot do so for newly-created sessions, because the session structure is allocated when session is created.

Contributing to the confusion is the desire not to enable excessive verbosity in the CLD sessions whenever debugging is requested.

To fix these issues, the patch does the following:

- Drops all commented-out inserts that assign additional verbosity from libraries. Permits top-level applications to specify verbosity (what cldcli -v was intended to do).

- Splits per-packet verbosity away from debugging messages.

- Changes the command line option -D of both cld and cldcli to mean the same thing.

Coincidentially this fixes the crash whenever there's a resolution failure for an SRV record.

---
 include/cldc.h       |    1 
 include/hail_log.h   |   24 +++++----
 include/ncld.h       |    2 
 lib/cldc.c           |  103 +++++++++++++++++++++++------------------
 server/server.c      |   22 +++++---
 test/basic-io.c      |    4 -
 test/basic-session.c |    2 
 test/lock-file.c     |    2 
 tools/cldcli.c       |   24 +++++----
 9 files changed, 108 insertions(+), 76 deletions(-)

commit 2b74fc8e0aecd79e466cf0ac7e966af65554307e

Author: Master <[email protected]>
Date:   Tue Feb 9 15:03:18 2010 -0700

Verbosity.

include/cldc.h +0 -1
index 858fbd3..3b75376 100644
@@ -88,7 +88,6 @@ struct cldc_ops {
 				const void *buf, size_t buflen);
 	void		(*event)(void *private, struct cldc_session *,
 				 struct cldc_fh *, uint32_t);
-	void		(*errlog)(int prio, const char *fmt, ...);
 };
 
 /** a single CLD client session */
include/hail_log.h +15 -9
index 88074a3..53a6780 100644
@@ -10,31 +10,37 @@
 #endif
 
 struct hail_log {
-	void (*func)(int prio, const char *fmt, ...)
-		ATTR_PRINTF(2,3);
-	bool verbose;
+	void (*func)(int prio, const char *fmt, ...) ATTR_PRINTF(2,3);
+	bool debug;		/* unmutes HAIL_DEBUG */
+	bool verbose;		/* enables CLD session verbosity */
 };
 
-/** Print out a debug message if 'verbose' is enabled */
-#define HAIL_DEBUG(log, ...) \
+/** Print out a CLD session debug message if enabled */
+#define HAIL_VERBOSE(log, ...) \
 	if ((log)->verbose) { \
 		(log)->func(LOG_DEBUG, __VA_ARGS__); \
 	}
 
+/** Print out an application debug message if enabled */
+#define HAIL_DEBUG(log, ...) \
+	if ((log)->debug) { \
+		(log)->func(LOG_DEBUG, __VA_ARGS__); \
+	}
+
 /** Print out an informational log message */
 #define HAIL_INFO(log, ...) \
-	(log)->func(LOG_INFO, __VA_ARGS__);
+	(log)->func(LOG_INFO, __VA_ARGS__)
 
 /** Print out a warning message */
 #define HAIL_WARN(log, ...) \
-	(log)->func(LOG_WARNING, __VA_ARGS__);
+	(log)->func(LOG_WARNING, __VA_ARGS__)
 
 /** Print out an error message */
 #define HAIL_ERR(log, ...) \
-	(log)->func(LOG_ERR, __VA_ARGS__);
+	(log)->func(LOG_ERR, __VA_ARGS__)
 
 /** Print out a critical warning message */
 #define HAIL_CRIT(log, ...) \
-	(log)->func(LOG_CRIT, __VA_ARGS__);
+	(log)->func(LOG_CRIT, __VA_ARGS__)
 
 #endif /* __HAIL_LOG_H__ */
include/ncld.h +1 -1
index 690c64b..bcdb721 100644
@@ -70,7 +70,7 @@ struct ncld_read {
 
 extern struct ncld_sess *ncld_sess_open(const char *host, int port,
 	int *error, void (*event)(void *, unsigned int), void *ev_arg,
-	const char *cld_user, const char *cld_key);
+	const char *cld_user, const char *cld_key, struct hail_log *log);
 extern struct ncld_fh *ncld_open(struct ncld_sess *s, const char *fname,
 	unsigned int mode, int *error, unsigned int events,
 	void (*event)(void *, unsigned int), void *ev_arg);
lib/cldc.c +60 -43

214 lines not on this page · raw message

server/server.c +15 -7
index 3208e0f..7c1d6a6 100644
@@ -117,7 +117,6 @@ static void applog(int prio, const char *fmt, ...)
 
 struct hail_log srv_log = {
 	.func = applog,
-	.verbose = 0,
 };
 
 int udp_tx(int sock_fd, struct sockaddr *addr, socklen_t addr_len,
@@ -918,9 +917,17 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state)
 		cld_srv.data_dir = arg;
 		break;
 	case 'D':
-		if (atoi(arg) >= 0 && atoi(arg) <= 2)
-			srv_log.verbose = atoi(arg);
-		else {
+		switch (atoi(arg)) {
+		case 0:
+			break;
+		case 1:
+			srv_log.debug = true;
+			break;
+		case 2:
+			srv_log.debug = true;
+			srv_log.verbose = true;
+			break;
+		default:
 			fprintf(stderr, "invalid debug level: '%s'\n", arg);
 			argp_usage(state);
 		}
@@ -1120,9 +1127,10 @@ int main (int argc, char *argv[])
 	if (rc)
 		goto err_out_pid;
 
-	HAIL_INFO(&srv_log, "initialized: verbose %u%s",
-	       srv_log.verbose,
-	       strict_free ? ", strict-free" : "");
+	HAIL_INFO(&srv_log, "initialized: %s%s",
+		  srv_log.verbose ? "verbose" :
+		  (srv_log.debug ? "debug" : "quiet"),
+		  strict_free ? ", strict-free" : "");
 
 	/*
 	 * execute main loop
test/basic-io.c +2 -2
index 2565280..bd41187 100644
@@ -40,7 +40,7 @@ static int test_write(int port)
 	int error;
 
 	nsp = ncld_sess_open(TEST_HOST, port, &error, NULL, NULL,
-			     TEST_USER, TEST_USER_KEY);
+			     TEST_USER, TEST_USER_KEY, NULL);
 	if (!nsp) {
 		fprintf(stderr, "ncld_sess_open(host %s port %u) failed: %d\n",
 			TEST_HOST, port, error);
@@ -74,7 +74,7 @@ static int test_read(int port)
 	int error;
 
 	nsp = ncld_sess_open(TEST_HOST, port, &error, NULL, NULL,
-			     TEST_USER, TEST_USER_KEY);
+			     TEST_USER, TEST_USER_KEY, NULL);
 	if (!nsp) {
 		fprintf(stderr, "ncld_sess_open(host %s port %u) failed: %d\n",
 			TEST_HOST, port, error);
test/basic-session.c +1 -1
index d8f9ec1..61efd71 100644
@@ -45,7 +45,7 @@ int main (int argc, char *argv[])
 		return -1;
 
 	nsp = ncld_sess_open(TEST_HOST, port, &error, NULL, NULL,
-			     TEST_USER, TEST_USER_KEY);
+			     TEST_USER, TEST_USER_KEY, NULL);
 	if (!nsp) {
 		fprintf(stderr, "ncld_sess_open(host %s port %u) failed: %d\n",
 			TEST_HOST, port, error);
test/lock-file.c +1 -1
index 64e6020..8b154e3 100644
@@ -50,7 +50,7 @@ int main (int argc, char *argv[])
 		return -1;
 
 	nsp = ncld_sess_open(TEST_HOST, port, &error, NULL, NULL,
-			     TEST_USER, TEST_USER_KEY);
+			     TEST_USER, TEST_USER_KEY, NULL);
 	if (!nsp) {
 		fprintf(stderr, "ncld_sess_open(host %s port %u) failed: %d\n",
 			TEST_HOST, port, error);
tools/cldcli.c +13 -11
index 85a7ef8..8a4868c 100644
@@ -44,8 +44,6 @@ static struct argp_option options[] = {
 	  "Connect to remote CLD at specified HOST:PORT" },
 	{ "user", 'u', "USER", 0,
 	  "Set username to USER" },
-	{ "verbose", 'v', NULL, 0,
-	  "Enable verbose libcldc output" },
 	{ }
 };
 
@@ -98,7 +96,6 @@ static void applog(int prio, const char *fmt, ...)
 
 static struct hail_log cli_log = {
 	.func = applog,
-	.verbose = 0,
 };
 
 static void sess_event(void *private, uint32_t what)
@@ -630,11 +627,19 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state)
 {
 	switch(key) {
 	case 'D':
-		if (atoi(arg) >= 0 && atoi(arg) <= 2)
-			cli_log.verbose = atoi(arg);
-		else {
+		switch (atoi(arg)) {
+		case 0:
+			break;
+		case 1:
+			cli_log.debug = true;
+			break;
+		case 2:
+			cli_log.debug = true;
+			cli_log.verbose = true;
+			break;
+		default:
 			fprintf(stderr, TAG ": invalid debug level: '%s'\n",
-				arg);
+       				arg);
 			argp_usage(state);
 		}
 		break;
@@ -649,9 +654,6 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state)
 		} else
 			strcpy(our_user, arg);
 		break;
-	case 'v':
-		cli_log.verbose = true;
-		break;
 	case ARGP_KEY_ARG:
 		argp_usage(state);	/* too many args */
 		break;
@@ -711,7 +713,7 @@ int main (int argc, char *argv[])
 	dr = host_list->data;
 
 	nsp = ncld_sess_open(dr->host, dr->port, &error, sess_event, NULL,
-			     "cldcli", "cldcli");
+			     "cldcli", "cldcli", &cli_log);
 	if (!nsp) {
 		if (error < 1000) {
 			fprintf(stderr, TAG ": cannot open CLD session: %s\n",