All of lore.kernel.org
 help / color / mirror / Atom feed
* [Patch 1/3] CLD: Whole hog on applog
@ 2009-08-12 20:55 Pete Zaitcev
  2009-08-12 21:22 ` Jeff Garzik
  0 siblings, 1 reply; 2+ messages in thread
From: Pete Zaitcev @ 2009-08-12 20:55 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: Project Hail List

We abandon the wasteful strategy of gradual changes and simply change
to applog-style API wholesale, to put the whole issue behind.
Applications need to be rebuilt after new cld-devel is installed.

Signed-off-by: Pete Zaitcev <zaitcev@redhat.com>

diff --git a/include/cldc.h b/include/cldc.h
index 712e7c7..8c2bde5 100644
--- a/include/cldc.h
+++ b/include/cldc.h
@@ -78,7 +78,6 @@ struct cldc_ops {
 				const void *buf, size_t buflen);
 	void		(*event)(void *private, struct cldc_session *,
 				 struct cldc_fh *, uint32_t);
-	void		(*printf)(const char *fmt, ...);
 	void		(*errlog)(int prio, const char *fmt, ...);
 };
 
@@ -89,8 +88,7 @@ struct cldc_session {
 	bool		verbose;
 
 	const struct cldc_ops *ops;
-	void		(*act_log)(struct cldc_session *,
-				   int prio, const char *fmt, ...);
+	void		(*act_log)(int prio, const char *fmt, ...);
 	void		*private;
 
 	uint8_t		addr[64];		/* server address */
@@ -211,13 +209,13 @@ extern bool cldc_levent_timer(void *private, bool add,
 
 /* cldc-dns */
 extern int cldc_getaddr(GList **host_list, const char *thishost, bool verbose,
-		 void (*act_log)(const char *fmt, ...));
+		 void (*act_log)(int prio, const char *fmt, ...));
 extern int cldc_saveaddr(struct cldc_host *hp,
 			 unsigned int priority,
 			 unsigned int weight, unsigned int port,
 			 unsigned int nlen, const char *name,
 			 bool verbose,
-			 void (*act_log)(const char *fmt, ...));
+			 void (*act_log)(int prio, const char *fmt, ...));
 
 static inline bool seqid_after_eq(uint64_t a_, uint64_t b_)
 {
diff --git a/lib/cldc-dns.c b/lib/cldc-dns.c
index 8f8984b..bc915e6 100644
--- a/lib/cldc-dns.c
+++ b/lib/cldc-dns.c
@@ -8,6 +8,7 @@
 #include <arpa/nameser.h>
 #include <netdb.h>
 #include <resolv.h>
+#include <syslog.h>
 #include "cldc.h"
 
 #define ADDRSIZE	24	/* Enough for IPv6, including port. */
@@ -21,7 +22,7 @@ int cldc_saveaddr(struct cldc_host *hp,
 			 unsigned int weight, unsigned int port,
 			 unsigned int nlen, const char *name,
 			 bool verbose,
-			 void (*act_log)(const char *fmt, ...))
+			 void (*act_log)(int prio, const char *fmt, ...))
 {
 	char portstr[11];
 	char *hostname;
@@ -46,7 +47,7 @@ int cldc_saveaddr(struct cldc_host *hp,
 
 	rc = getaddrinfo(hostname, portstr, &hints, &res0);
 	if (rc) {
-		act_log("getaddrinfo(%s,%s) failed: %s",
+		act_log(LOG_INFO, "getaddrinfo(%s,%s) failed: %s",
 		       hostname, portstr, gai_strerror(rc));
 		rc = -EINVAL;
 		goto err_addr;
@@ -65,7 +66,7 @@ int cldc_saveaddr(struct cldc_host *hp,
 	}
 
 	if (!something_suitable) {
-		act_log("Host %s port %u has no addresses",
+		act_log(LOG_INFO, "Host %s port %u has no addresses",
 		       hostname, port);
 		rc = -EINVAL;
 		goto err_suitable;
@@ -77,7 +78,7 @@ int cldc_saveaddr(struct cldc_host *hp,
 	hp->weight = weight;
 
 	if (verbose) {
-		act_log(
+		act_log(LOG_DEBUG,
 		       "Found CLD host %s prio %d weight %d",
 		       hostname, priority, weight);
 	}
@@ -100,7 +101,7 @@ err_name:
  */
 static int cldc_make_fqdn(char *buf, int size, const char *srvname,
 			  const char *thishost,
-		 	  void (*act_log)(const char *fmt, ...))
+		 	  void (*act_log)(int prio, const char *fmt, ...))
 {
 	char *s;
 	int nlen;
@@ -108,18 +109,19 @@ static int cldc_make_fqdn(char *buf, int size, const char *srvname,
 
 	nlen = strlen(srvname);
 	if (nlen >= size-20) {
-		act_log(
+		act_log(LOG_INFO,
 		       "cldc_getaddr: internal error (nlen %d size %d)",
 		       nlen, size);
 		return -1;
 	}
 
 	if (thishost == NULL) {
-		act_log("cldc_getaddr: internal error (null hostname)");
+		act_log(LOG_INFO,
+			"cldc_getaddr: internal error (null hostname)");
 		return -1;
 	}
 	if ((s = strchr(thishost, '.')) == NULL) {
-		act_log(
+		act_log(LOG_INFO,
 		       "cldc_getaddr: hostname is not FQDN: \"%s\"",
 		       thishost);
 		return -1;
@@ -128,7 +130,7 @@ static int cldc_make_fqdn(char *buf, int size, const char *srvname,
 
 	dlen = strlen(s);
 	if (nlen + 1 + dlen + 1 > size) {
-		act_log(
+		act_log(LOG_INFO,
 		       "cldc_getaddr: domain is too long: \"%s\"", s);
 		return -1;
 	}
@@ -160,7 +162,7 @@ static void push_host(GList **host_list, struct cldc_host *hp_in)
  * are started.
  */
 int cldc_getaddr(GList **host_list, const char *thishost, bool verbose,
-		 void (*act_log)(const char *fmt, ...))
+		 void (*act_log)(int prio, const char *fmt, ...))
 {
 	enum { hostsz = 64 };
 	char cldb[hostsz];
@@ -189,10 +191,12 @@ do_try_again:
 	if (rc < 0) {
 		switch (h_errno) {
 		case HOST_NOT_FOUND:
-			act_log("No _cld._udp SRV record");
+			act_log(LOG_INFO,
+				"cldc_getaddr: No _cld._udp SRV record");
 			return -1;
 		case NO_DATA:
-			act_log("Cannot find _cld._udp SRV record");
+			act_log(LOG_INFO,
+				"cldc_getaddr: Cannot find _cld._udp SRV record");
 			return -1;
 		case TRY_AGAIN:
 			if (search_retries-- > 0)
@@ -200,23 +204,22 @@ do_try_again:
 			/* fall through */
 		case NO_RECOVERY:
 		default:
-			act_log(
-			       "cldc_getaddr: res_search error (%d): %s",
-			       h_errno, hstrerror(h_errno));
+			act_log(LOG_INFO,
+				"cldc_getaddr: res_search error (%d): %s",
+				h_errno, hstrerror(h_errno));
 			return -1;
 		}
 	}
 	rlen = rc;
 
 	if (rlen == 0) {
-		act_log(
-		       "cldc_getaddr: res_search returned empty reply");
+		act_log(LOG_INFO,
+			"cldc_getaddr: res_search returned empty reply");
 		return -1;
 	}
 
 	if (ns_initparse(resp, rlen, &nsb) < 0) {
-		act_log(
-		       "cldc_getaddr: ns_initparse error");
+		act_log(LOG_INFO, "cldc_getaddr: ns_initparse error");
 		return -1;
 	}
 
@@ -235,9 +238,9 @@ do_try_again:
 			rrlen = ns_rr_rdlen(rrb);
 			if (rrlen < 8) {	/* 2+2+2 and 2 for host */
 				if (verbose) {
-					act_log(
-					       "cldc_getaddr: SRV len %d",
-					       rrlen);
+					act_log(LOG_DEBUG,
+						"cldc_getaddr: SRV len %d", 
+						rrlen);
 				}
 				break;
 			}
@@ -245,14 +248,14 @@ do_try_again:
 			rc = dn_expand(resp, resp+rlen, p+6, hostb, hostsz);
 			if (rc < 0) {
 				if (verbose) {
-					act_log("cldc_getaddr: "
+					act_log(LOG_DEBUG, "cldc_getaddr: "
 					       "dn_expand error %d", rc);
 				}
 				break;
 			}
 			if (rc < 2) {
 				if (verbose) {
-					act_log("cldc_getaddr: "
+					act_log(LOG_DEBUG, "cldc_getaddr: "
 					       "dn_expand short %d", rc);
 				}
 				break;
@@ -267,8 +270,8 @@ do_try_again:
 			break;
 		case ns_t_cname:	/* impossible, but */
 			if (verbose) {
-				act_log(
-				       "CNAME in SRV request, ignored");
+				act_log(LOG_DEBUG,
+					"CNAME in SRV request, ignored");
 			}
 			break;
 		default:
diff --git a/lib/cldc.c b/lib/cldc.c
index 90139cf..7ac6442 100644
--- a/lib/cldc.c
+++ b/lib/cldc.c
@@ -83,7 +83,7 @@ static size_t strnlen(const char *s, size_t maxlen)
 #define EBADE 52
 #endif
 
-static void cldc_stdlog(struct cldc_session *sess, int prio, const char *fmt, ...)
+static void cldc_errlog(int prio, const char *fmt, ...)
 {
 	char buf[200];
 	va_list ap;
@@ -94,30 +94,6 @@ static void cldc_stdlog(struct cldc_session *sess, int prio, const char *fmt, ..
 	va_end(ap);
 }
 
-static void cldc_oldlog(struct cldc_session *sess,
-			int prio, const char *fmt, ...)
-{
-	char buf[200];
-	va_list ap;
-
-	va_start(ap, fmt);
-	vsnprintf(buf, 200, fmt, ap);
-	sess->ops->printf("%s\n", buf);
-	va_end(ap);
-}
-
-static void cldc_applog(struct cldc_session *sess,
-			int prio, const char *fmt, ...)
-{
-	char buf[200];
-	va_list ap;
-
-	va_start(ap, fmt);
-	vsnprintf(buf, 200, fmt, ap);
-	sess->ops->errlog(prio, "%s", buf);
-	va_end(ap);
-}
-
 static int ack_seqid(struct cldc_session *sess, uint64_t seqid_le)
 {
 	struct cld_packet *pkt;
@@ -138,7 +114,7 @@ static int ack_seqid(struct cldc_session *sess, uint64_t seqid_le)
 	memcpy(resp, &def_msg_ack, sizeof(*resp));
 
 	if (!authsign(sess, pkt, pkt_len)) {
-		sess->act_log(sess, LOG_INFO, "authsign failed 2");
+		sess->act_log(LOG_INFO, "authsign failed 2");
 		return -1;
 	}
 
@@ -163,11 +139,11 @@ static int cldc_rx_generic(struct cldc_session *sess,
 		req = tmp->data;
 
 		if (sess->verbose)
-			sess->act_log(sess, LOG_DEBUG, "rx_gen: comparing req->xid (%llu) with resp->xid_in (%llu)",
-			        (unsigned long long)
-					le64_to_cpu(req->xid),
-			        (unsigned long long)
-					le64_to_cpu(resp->xid_in));
+			sess->act_log(LOG_DEBUG,
+				      "rx_gen: comparing req->xid (%llu) "
+				      "with resp->xid_in (%llu)",
+				(unsigned long long) le64_to_cpu(req->xid),
+			        (unsigned long long) le64_to_cpu(resp->xid_in));
 
 		if (req->xid == resp->xid_in)
 			break;
@@ -178,10 +154,11 @@ static int cldc_rx_generic(struct cldc_session *sess,
 
 	if (req->done) {
 		if (sess->verbose)
-			sess->act_log(sess, LOG_DEBUG, "rx_gen: re-acking");
+			sess->act_log(LOG_DEBUG, "rx_gen: re-acking");
 	} else {
 		if (sess->verbose)
-			sess->act_log(sess, LOG_DEBUG, "rx_gen: issuing completion, acking");
+			sess->act_log(LOG_DEBUG,
+				      "rx_gen: issuing completion, acking");
 
 		req->done = true;
 
@@ -208,7 +185,7 @@ static int cldc_rx_ack_frag(struct cldc_session *sess,
 		return -1008;
 
 	if (sess->verbose)
-		sess->act_log(sess, LOG_DEBUG, "ack-frag: seqid %llu, want to ack",
+		sess->act_log(LOG_DEBUG, "ack-frag: seqid %llu, want to ack",
 			      ack_msg->seqid);
 
 	tmp = sess->out_msg;
@@ -228,7 +205,7 @@ static int cldc_rx_ack_frag(struct cldc_session *sess,
 				continue;
 
 			if (sess->verbose)
-				sess->act_log(sess, LOG_DEBUG,
+				sess->act_log(LOG_DEBUG,
 					      "ack-frag: seqid %llu, expiring",
 					      ack_msg->seqid);
 
@@ -274,7 +251,7 @@ static int cldc_rx_not_master(struct cldc_session *sess,
 			      const void *msgbuf,
 			      size_t buflen)
 {
-	sess->act_log(sess, LOG_INFO, "FIXME: not-master message received");
+	sess->act_log(LOG_INFO, "FIXME: not-master message received");
 	return -1055;	/* FIXME */
 }
 
@@ -341,7 +318,7 @@ static bool authcheck(struct cldc_session *sess, const struct cld_packet *pkt,
 	     md, &md_len);
 
 	if (md_len != SHA_DIGEST_LENGTH)
-		sess->act_log(sess, LOG_INFO,
+		sess->act_log(LOG_INFO,
 			      "authsign BUG: md_len != SHA_DIGEST_LENGTH");
 
 	if (memcmp(buf + buflen - SHA_DIGEST_LENGTH, md, SHA_DIGEST_LENGTH))
@@ -366,7 +343,7 @@ static bool authsign(struct cldc_session *sess, struct cld_packet *pkt,
 	     md, &md_len);
 
 	if (md_len != SHA_DIGEST_LENGTH)
-		sess->act_log(sess, LOG_INFO,
+		sess->act_log(LOG_INFO,
 			      "authsign BUG: md_len != SHA_DIGEST_LENGTH");
 
 	memcpy(buf + (buflen - SHA_DIGEST_LENGTH), md, SHA_DIGEST_LENGTH);
@@ -452,7 +429,7 @@ int cldc_receive_pkt(struct cldc_session *sess,
 
 	if (pkt_len < (sizeof(*pkt) + SHA_DIGEST_LENGTH)) {
 		if (sess->verbose)
-			sess->act_log(sess, LOG_DEBUG, "receive_pkt: msg too short");
+			sess->act_log(LOG_DEBUG, "receive_pkt: msg too short");
 		return -EPROTO;
 	}
 
@@ -462,8 +439,8 @@ int cldc_receive_pkt(struct cldc_session *sess,
 		if (msg->op == cmo_get) {
 			struct cld_msg_get_resp *dp;
 			dp = (struct cld_msg_get_resp *) msg;
-			sess->act_log(sess, LOG_DEBUG, "receive pkt: len %u, op %s"
-				", seqid %llu, user %s, size %u",
+			sess->act_log(LOG_DEBUG, "receive pkt: len %u, op %s"
+				      ", seqid %llu, user %s, size %u",
 				(unsigned int) pkt_len,
 				opstr(msg->op),
 				(unsigned long long) le64_to_cpu(pkt->seqid),
@@ -472,16 +449,16 @@ int cldc_receive_pkt(struct cldc_session *sess,
 		} else if (msg->op == cmo_new_sess) {
 			struct cld_msg_resp *dp;
 			dp = (struct cld_msg_resp *) msg;
-			sess->act_log(sess, LOG_DEBUG, "receive pkt: len %u, op %s"
-				", seqid %llu, user %s, xid_in %llu",
+			sess->act_log(LOG_DEBUG, "receive pkt: len %u, op %s"
+				      ", seqid %llu, user %s, xid_in %llu",
 				(unsigned int) pkt_len,
 				opstr(msg->op),
 				(unsigned long long) le64_to_cpu(pkt->seqid),
 				pkt->user,
 				(unsigned long long) le64_to_cpu(dp->xid_in));
 		} else {
-			sess->act_log(sess, LOG_DEBUG, "receive pkt: len %u, op %s"
-				", seqid %llu, user %s",
+			sess->act_log(LOG_DEBUG, "receive pkt: len %u, op %s"
+				      ", seqid %llu, user %s",
 				(unsigned int) pkt_len,
 				opstr(msg->op),
 				(unsigned long long) le64_to_cpu(pkt->seqid),
@@ -491,14 +468,14 @@ int cldc_receive_pkt(struct cldc_session *sess,
 
 	if (memcmp(pkt->magic, CLD_PKT_MAGIC, sizeof(pkt->magic))) {
 		if (sess->verbose)
-			sess->act_log(sess, LOG_DEBUG, "receive_pkt: bad pkt magic");
+			sess->act_log(LOG_DEBUG, "receive_pkt: bad pkt magic");
 		return -EPROTO;
 	}
 
 	/* check HMAC signature */
 	if (!authcheck(sess, pkt, pkt_len)) {
 		if (sess->verbose)
-			sess->act_log(sess, LOG_DEBUG, "receive_pkt: invalid auth");
+			sess->act_log(LOG_DEBUG, "receive_pkt: invalid auth");
 		return -EACCES;
 	}
 
@@ -506,7 +483,7 @@ int cldc_receive_pkt(struct cldc_session *sess,
 	if (((sess->addr_len != net_addrlen) ||
 	    memcmp(sess->addr, net_addr, net_addrlen))) {
 		if (sess->verbose)
-			sess->act_log(sess, LOG_DEBUG,
+			sess->act_log(LOG_DEBUG,
 				      "receive_pkt: server address mismatch");
 		return -EBADE;
 	}
@@ -527,7 +504,7 @@ int cldc_receive_pkt(struct cldc_session *sess,
 
 	if ((sess->msg_buf_len + msglen) > CLD_MAX_MSG_SZ) {
 		if (sess->verbose)
-			sess->act_log(sess, LOG_DEBUG, "receive_pkt: bad pkt length");
+			sess->act_log(LOG_DEBUG, "receive_pkt: bad pkt length");
 		return -EPROTO;
 	}
 
@@ -536,7 +513,7 @@ int cldc_receive_pkt(struct cldc_session *sess,
 
 	if (memcmp(msg->magic, CLD_MSG_MAGIC, sizeof(msg->magic))) {
 		if (sess->verbose)
-			sess->act_log(sess, LOG_DEBUG, "receive_pkt: bad msg magic");
+			sess->act_log(LOG_DEBUG, "receive_pkt: bad msg magic");
 		return -EPROTO;
 	}
 
@@ -548,9 +525,9 @@ int cldc_receive_pkt(struct cldc_session *sess,
 			sess->next_seqid_in - CLDC_MSG_REMEMBER;
 
 		if (sess->verbose)
-			sess->act_log(sess, LOG_DEBUG, "receive_pkt: "
-					 "setting next_seqid_in to %llu",
-					 (unsigned long long) seqid);
+			sess->act_log(LOG_DEBUG, "receive_pkt: "
+				      "setting next_seqid_in to %llu",
+				      (unsigned long long) seqid);
 	} else if (!no_seqid) {
 		if (seqid != sess->next_seqid_in) {
 			if (seqid_in_range(seqid,
@@ -559,7 +536,7 @@ int cldc_receive_pkt(struct cldc_session *sess,
 				return ack_seqid(sess, pkt->seqid);
 
 			if (sess->verbose)
-				sess->act_log(sess, LOG_DEBUG,
+				sess->act_log(LOG_DEBUG,
 					      "receive_pkt: bad seqid %llu",
 					      (unsigned long long) seqid);
 			return -EBADSLT;
@@ -901,13 +878,7 @@ int cldc_new_sess(const struct cldc_ops *ops,
 
 	sess->private = private;
 	sess->ops = ops;
-	if (ops->printf) {	/* obsolete API in use XXX */
-		sess->act_log = cldc_oldlog;
-	} else if (ops->errlog) {
-		sess->act_log = cldc_applog;
-	} else {
-		sess->act_log = cldc_stdlog;
-	}
+	sess->act_log = ops->errlog ? ops->errlog : cldc_errlog;
 	sess->fh = g_array_sized_new(FALSE, TRUE, sizeof(struct cldc_fh), 16);
 	strcpy(sess->user, user);
 	strcpy(sess->secret_key, secret_key);
diff --git a/tools/cldcli.c b/tools/cldcli.c
index b2a0c02..2375ef4 100644
--- a/tools/cldcli.c
+++ b/tools/cldcli.c
@@ -144,12 +144,14 @@ static void errc_msg(struct cresp *cresp, enum cle_err_codes errc)
 	strcpy(cresp->msg, names_cle_err[errc]);
 }
 
-static void app_log(const char *fmt, ...)
+static void applog(int prio, const char *fmt, ...)
 {
+	char buf[200];
 	va_list ap;
 
 	va_start(ap, fmt);
-	vfprintf(stderr, fmt, ap);
+	vsnprintf(buf, 200, fmt, ap);
+	fprintf(stderr, "%s\n", buf);
 	va_end(ap);
 }
 
@@ -780,20 +782,11 @@ static void cld_p_event(void *private, struct cldc_session *sess,
 	fprintf(stderr, "FIXME: event\n");
 }
 
-static void cld_p_log(const char *fmt, ...)
-{
-	va_list ap;
-
-	va_start(ap, fmt);
-	vfprintf(stderr, fmt, ap);
-	va_end(ap);
-}
-
 static struct cldc_ops cld_ops = {
 	.timer_ctl	= cld_p_timer_ctl,
 	.pkt_send	= cld_p_pkt_send,
 	.event		= cld_p_event,
-	.printf		= cld_p_log,
+	.errlog		= applog,
 };
 
 static gpointer cld_thread(gpointer dummy)
@@ -1307,7 +1300,7 @@ int main (int argc, char *argv[])
 			return 1;
 		}
 		hostb[hostsz-1] = 0;
-		if (cldc_getaddr(&host_list, hostb, debugging, app_log)) {
+		if (cldc_getaddr(&host_list, hostb, debugging, applog)) {
 			fprintf(stderr, "Unable to find a CLD host\n");
 			return 1;
 		}

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Patch 1/3] CLD: Whole hog on applog
  2009-08-12 20:55 [Patch 1/3] CLD: Whole hog on applog Pete Zaitcev
@ 2009-08-12 21:22 ` Jeff Garzik
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Garzik @ 2009-08-12 21:22 UTC (permalink / raw)
  To: Pete Zaitcev; +Cc: Project Hail List

Pete Zaitcev wrote:
> We abandon the wasteful strategy of gradual changes and simply change
> to applog-style API wholesale, to put the whole issue behind.
> Applications need to be rebuilt after new cld-devel is installed.
> 
> Signed-off-by: Pete Zaitcev <zaitcev@redhat.com>

applied



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-08-12 21:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-12 20:55 [Patch 1/3] CLD: Whole hog on applog Pete Zaitcev
2009-08-12 21:22 ` Jeff Garzik

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.