All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@redhat.com>
To: steved@redhat.com
Cc: chuck.lever@oracle.com, bfields@fieldses.org, linux-nfs@vger.kernel.org
Subject: [PATCH 1/4] nfs-utils: make private cookie to hex conversion a library routine
Date: Fri,  8 Jan 2010 09:56:00 -0500	[thread overview]
Message-ID: <1262962563-5554-2-git-send-email-jlayton@redhat.com> (raw)
In-Reply-To: <1262962563-5554-1-git-send-email-jlayton@redhat.com>

Signed-off-by: Jeff Layton <jlayton@redhat.com>
---
 support/include/nsm.h |    2 ++
 support/nsm/file.c    |   44 ++++++++++++++++++++++++++++++++++----------
 2 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/support/include/nsm.h b/support/include/nsm.h
index 850c191..db53eb2 100644
--- a/support/include/nsm.h
+++ b/support/include/nsm.h
@@ -71,6 +71,8 @@ extern void	nsm_delete_monitored_host(const char *hostname,
 			const char *mon_name, const char *my_name);
 extern void	nsm_delete_notified_host(const char *hostname,
 			const char *mon_name, const char *my_name);
+extern size_t	nsm_priv_to_hex(const char *priv, char *buf,
+				const size_t buflen);
 
 /* rpc.c */
 
diff --git a/support/nsm/file.c b/support/nsm/file.c
index 635fb4e..7e923ef 100644
--- a/support/nsm/file.c
+++ b/support/nsm/file.c
@@ -677,6 +677,33 @@ nsm_retire_monitored_hosts(void)
 }
 
 /*
+ * nsm_priv_to_hex - convert a NSM private cookie to a hex string.
+ *
+ * @priv: buffer holding the binary NSM private cookie
+ * @buf: output buffer for NULL terminated hex string
+ * @buflen: size of output buffer
+ *
+ * Returns the length of the resulting string or 0 on error
+ */
+size_t
+nsm_priv_to_hex(const char *priv, char *buf, const size_t buflen)
+{
+	int i, len;
+	size_t remaining = buflen;
+
+	for (i = 0; i < SM_PRIV_SIZE; i++) {
+		len = snprintf(buf, remaining, "%02x",
+				(unsigned int)(0xff & priv[i]));
+		if (error_check(len, remaining))
+			return 0;
+		buf += len;
+		remaining -= (size_t)len;
+	}
+
+	return buflen - remaining;
+}
+
+/*
  * Returns the length in bytes of the created record.
  */
 __attribute_noinline__
@@ -685,8 +712,8 @@ nsm_create_monitor_record(char *buf, const size_t buflen,
 		const struct sockaddr *sap, const struct mon *m)
 {
 	const struct sockaddr_in *sin = (const struct sockaddr_in *)sap;
-	size_t remaining = buflen;
-	int i, len;
+	size_t hexlen, remaining = buflen;
+	int len;
 
 	len = snprintf(buf, remaining, "%08x %08x %08x %08x ",
 			(unsigned int)sin->sin_addr.s_addr,
@@ -698,14 +725,11 @@ nsm_create_monitor_record(char *buf, const size_t buflen,
 	buf += len;
 	remaining -= (size_t)len;
 
-	for (i = 0; i < SM_PRIV_SIZE; i++) {
-		len = snprintf(buf, remaining, "%02x",
-				(unsigned int)(0xff & m->priv[i]));
-		if (error_check(len, remaining))
-			return 0;
-		buf += len;
-		remaining -= (size_t)len;
-	}
+	hexlen = nsm_priv_to_hex(m->priv, buf, remaining);
+	if (hexlen == 0)
+		return 0;
+	buf += hexlen;
+	remaining -= hexlen;
 
 	len = snprintf(buf, remaining, " %s %s\n",
 			m->mon_id.mon_name, m->mon_id.my_id.my_name);
-- 
1.6.5.2


  reply	other threads:[~2010-01-08 14:56 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-08 14:55 [PATCH 0/4] nfs-utils: add testing infrastructure to nfs-utils (try #6) Jeff Layton
2010-01-08 14:56 ` Jeff Layton [this message]
2010-01-08 14:56 ` [PATCH 2/4] nfs-utils: introduce new statd testing simulator Jeff Layton
2010-01-08 14:56 ` [PATCH 3/4] nfs-utils: add statdb_dump utility Jeff Layton
2010-01-08 14:56 ` [PATCH 4/4] nfs-utils: add initial tests for statd that run via "make check" Jeff Layton
2010-01-08 16:49   ` Chuck Lever
2010-01-08 16:56     ` Jeff Layton
     [not found]       ` <20100108115651.7a84a3c5-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>
2010-01-08 18:21         ` Chuck Lever
2010-01-08 16:59     ` J. Bruce Fields
2010-01-12 12:25 ` [PATCH 0/4] nfs-utils: add testing infrastructure to nfs-utils (try #6) Steve Dickson
  -- strict thread matches above, loose matches on Subject: below --
2010-01-06 15:20 [PATCH 0/4] nfs-utils: add testing infrastructure to nfs-utils (try #5) Jeff Layton
2010-01-06 15:20 ` [PATCH 1/4] nfs-utils: make private cookie to hex conversion a library routine Jeff Layton
2010-01-06 15:37   ` Chuck Lever
2010-01-06 12:53 [PATCH 0/4] nfs-utils: add testing infrastructure to nfs-utils (try #4) Jeff Layton
2010-01-06 12:53 ` [PATCH 1/4] nfs-utils: make private cookie to hex conversion a library routine Jeff Layton
2010-01-06 13:08   ` Chuck Lever

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1262962563-5554-2-git-send-email-jlayton@redhat.com \
    --to=jlayton@redhat.com \
    --cc=bfields@fieldses.org \
    --cc=chuck.lever@oracle.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=steved@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.