Re: [PATCH 2/3] nfs-utils: add statdb_dump utility

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Jan 5, 2010, at 10:40 AM, Jeff Layton wrote:

To dump contents of statd's monitor DB.

Signed-off-by: Jeff Layton <jlayton@xxxxxxxxxx>
---
tests/Makefile.am   |    6 ++++
tests/statdb_dump.c | 75 ++++++++++++++++++++++++++++++++++++++++++ +++++++++
2 files changed, 81 insertions(+), 0 deletions(-)
create mode 100644 tests/statdb_dump.c

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 375af80..a20b42b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,5 +1,11 @@
## Process this file with automake to produce Makefile.in

+check_PROGRAMS = statdb_dump
+statdb_dump_SOURCES = statdb_dump.c
+
+statdb_dump_LDADD = ../support/nfs/libnfs.a \
+		    ../support/nsm/libnsm.a $(LIBCAP)
+
SUBDIRS = nsm_client

MAINTAINERCLEANFILES = Makefile.in
diff --git a/tests/statdb_dump.c b/tests/statdb_dump.c
new file mode 100644
index 0000000..655213a
--- /dev/null
+++ b/tests/statdb_dump.c
@@ -0,0 +1,75 @@
+/*
+ * statdb_dump.c -- dump contents of statd's monitor DB
+ *
+ * Copyright (C) 2010  Red Hat, Jeff Layton <jlayton@xxxxxxxxxx>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * Output format is:
+ *
+ * <hostname> <cookie> <mon_name>

my_name might also be interesting when we get local multi-homed support going. Perhaps some command line switches could control what is displayed.

+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+
+#include "nsm.h"
+#include "xlog.h"
+
+static char cookiebuf[(SM_PRIV_SIZE * 2) + 1];
+
+static _Bool
+error_check(const int len, const size_t buflen)
+{
+        return (len < 0) || ((size_t)len >= buflen);
+}
+
+static unsigned int
+dump_host(const char *hostname, const struct sockaddr *sa, const struct mon *m,
+	  const time_t timestamp)
+{
+	int i, len;
+	char *buf = cookiebuf;
+	size_t remaining = sizeof(cookiebuf);
+
+	/* convert cookie to text string */
+	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;
+	}

I wonder if having a shared helper in support/nsm/file.c for converting a priv cookie to a string would be generally useful.

+
+	printf("%s %s %s\n", hostname, cookiebuf, m->mon_id.mon_name);
+	return 1;
+}
+
+int
+main(int argc, char **argv)
+{
+	xlog_syslog(0);
+	xlog_stderr(1);
+	xlog_open(argv[0]);
+	
+	nsm_load_monitor_list(dump_host);
+	return 0;
+}
--
1.6.5.2


--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com




--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Filesystem Development]     [Linux USB Development]     [Linux Media Development]     [Video for Linux]     [Linux NILFS]     [Linux Audio Users]     [Yosemite Info]     [Linux SCSI]

  Powered by Linux