Skip to contentSkip to conversation

nfsdcltrack: create a new usermodehelper upcall program for tracking clients

PATCH New Jeff Layton 1 participant 10 messages Oct 25, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v3 cover nfsdcltrack: create a new usermodehelper upcall program for tracking clients

This is a respin of the set that I sent yesterday. The main differences are fairly minor...

- the program no longer strdup()s the basename of the binary

- the autoconf option is still built by default, but if the requirements aren't met, configure will error out. Steve felt this was better than disabling it and moving on.

Everything else is pretty much the same. If it's easier, these patches are also in the "nfsdcltrack" branch of my git tree here:

git://git.linux-nfs.org/projects/jlayton/nfs-utils.git

Thanks for the review so far!

Jeff Layton (9):
nfsdcltrack: fix segfault in sqlite debug logging
nfsdcltrack: rename the nfsdcld directory and options to nfsdcltrack
nfsdcltrack: remove pointless sqlite_topdir variable
nfsdcltrack: break out a function to open the database handle
nfsdcltrack: add a new "one-shot" program for manipulating the client
tracking db
nfsdcltrack: add a legacy transition mechanism
nfsdcltrack: add a manpage for nfsdcltrack
nfsdcltrack: remove the nfsdcld daemon
nfsdcltrack: update the README about server startup order

 README                            |  23 +-
 configure.ac                      |  20 +-
 utils/Makefile.am                 |   4 +-
 utils/nfsdcld/Makefile.am         |  14 -
 utils/nfsdcld/nfsdcld.c           | 607 --------------------------------------
 utils/nfsdcld/nfsdcld.man         | 185 ------------
 utils/nfsdcld/sqlite.c            | 386 ------------------------
 utils/nfsdcld/sqlite.h            |  29 --
 utils/nfsdcltrack/Makefile.am     |  13 +
 utils/nfsdcltrack/nfsdcltrack.c   | 521 ++++++++++++++++++++++++++++++++
 utils/nfsdcltrack/nfsdcltrack.man | 211 +++++++++++++
 utils/nfsdcltrack/sqlite.c        | 400 +++++++++++++++++++++++++
 utils/nfsdcltrack/sqlite.h        |  30 ++
 13 files changed, 1189 insertions(+), 1254 deletions(-)
 delete mode 100644 utils/nfsdcld/Makefile.am
 delete mode 100644 utils/nfsdcld/nfsdcld.c
 delete mode 100644 utils/nfsdcld/nfsdcld.man
 delete mode 100644 utils/nfsdcld/sqlite.c
 delete mode 100644 utils/nfsdcld/sqlite.h
 create mode 100644 utils/nfsdcltrack/Makefile.am
 create mode 100644 utils/nfsdcltrack/nfsdcltrack.c
 create mode 100644 utils/nfsdcltrack/nfsdcltrack.man
 create mode 100644 utils/nfsdcltrack/sqlite.c
 create mode 100644 utils/nfsdcltrack/sqlite.h
Signature · 1 line
1.7.11.7
#1 lore raw

PATCH v3 1/9 nfsdcltrack: fix segfault in sqlite debug logging

One too few arguments...

---
 utils/nfsdcld/sqlite.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
utils/nfsdcld/sqlite.c +1 -1
index bb2519d..fc882c6 100644
@@ -320,7 +320,7 @@ sqlite_check_client(const unsigned char *clname, const size_t namelen)
 	}
 
 	ret = sqlite3_column_int(stmt, 0);
-	xlog(D_GENERAL, "%s: select returned %d rows", ret);
+	xlog(D_GENERAL, "%s: select returned %d rows", __func__, ret);
 	if (ret != 1) {
 		ret = -EACCES;
 		goto out_err;
Signature · 1 line
1.7.11.7
#2 lore raw

PATCH v3 2/9 nfsdcltrack: rename the nfsdcld directory and options to nfsdcltrack

In reply to Jeff Layton

We'll soon be adding a new nfsdcltrack program, at which point it won't make much sense to call this directory and the config option "nfsdcld". Rename it to be a bit more generic.

While we're at it, change the default for --enable-cltrack to "yes". When we introduce the one-shot program, we're going to want to build it by default anyway.

---
 configure.ac                  |  20 +-
 utils/Makefile.am             |   4 +-
 utils/nfsdcld/Makefile.am     |  14 -
 utils/nfsdcld/nfsdcld.c       | 607 ------------------------------------------
 utils/nfsdcld/nfsdcld.man     | 185 -------------
 utils/nfsdcld/sqlite.c        | 386 ---------------------------
 utils/nfsdcld/sqlite.h        |  29 --
 utils/nfsdcltrack/Makefile.am |  14 +
 utils/nfsdcltrack/nfsdcld.c   | 607 ++++++++++++++++++++++++++++++++++++++++++
 utils/nfsdcltrack/nfsdcld.man | 185 +++++++++++++
 utils/nfsdcltrack/sqlite.c    | 386 +++++++++++++++++++++++++++
 utils/nfsdcltrack/sqlite.h    |  29 ++
 12 files changed, 1233 insertions(+), 1233 deletions(-)
 delete mode 100644 utils/nfsdcld/Makefile.am
 delete mode 100644 utils/nfsdcld/nfsdcld.c
 delete mode 100644 utils/nfsdcld/nfsdcld.man
 delete mode 100644 utils/nfsdcld/sqlite.c
 delete mode 100644 utils/nfsdcld/sqlite.h
 create mode 100644 utils/nfsdcltrack/Makefile.am
 create mode 100644 utils/nfsdcltrack/nfsdcld.c
 create mode 100644 utils/nfsdcltrack/nfsdcld.man
 create mode 100644 utils/nfsdcltrack/sqlite.c
 create mode 100644 utils/nfsdcltrack/sqlite.h
configure.ac +10 -10
index a174bf4..f11ca80 100644
@@ -185,11 +185,11 @@ else
 	AM_CONDITIONAL(MOUNT_CONFIG, [test "$enable_mount" = "yes"])
 fi
 
-AC_ARG_ENABLE(nfsdcld,
-	[AC_HELP_STRING([--enable-nfsdcld],
-			[Create nfsdcld NFSv4 clientid tracking daemon. @<:@default=no@:>@])],
-	enable_nfsdcld=$enableval,
-	enable_nfsdcld="no")
+AC_ARG_ENABLE(nfsdcltrack,
+	[AC_HELP_STRING([--enable-nfsdcltrack],
+			[enable NFSv4 clientid tracking programs @<:@default=yes@:>@])],
+	enable_nfsdctrack=$enableval,
+	enable_nfsdcltrack="yes")
 
 dnl Check for TI-RPC library and headers
 AC_LIBTIRPC
@@ -269,12 +269,12 @@ if test "$enable_nfsv4" = yes; then
   dnl Check for sqlite3
   AC_SQLITE3_VERS
 
-  if test "$enable_nfsdcld" = "yes"; then
+  if test "$enable_nfsdcltrack" = "yes"; then
 	AC_CHECK_HEADERS([libgen.h sys/inotify.h], ,
-		AC_MSG_ERROR([Cannot find header needed for nfsdcld]))
+		AC_MSG_ERROR([Cannot find header needed for nfsdcltrack]))
 
   	if test "$libsqlite3_cv_is_recent" != "yes" ; then
-		AC_MSG_ERROR([nfsdcld requires sqlite3])
+		AC_MSG_ERROR([nfsdcltrack requires sqlite3])
 	fi
   fi
 
@@ -292,7 +292,7 @@ if test "$enable_nfsv41" = yes; then
 fi
 
 dnl enable nfsidmap when its support by libnfsidmap
-AM_CONDITIONAL(CONFIG_NFSDCLD, [test "$enable_nfsdcld" = "yes" ])
+AM_CONDITIONAL(CONFIG_NFSDCLTRACK, [test "$enable_nfsdcltrack" = "yes" ])
 AM_CONDITIONAL(CONFIG_NFSIDMAP, [test "$ac_cv_header_keyutils_h$ac_cv_lib_nfsidmap_nfs4_owner_to_uid" = "yesyes"])
 
 
@@ -477,7 +477,7 @@ AC_CONFIG_FILES([
 	tools/nfs-iostat/Makefile
 	utils/Makefile
 	utils/blkmapd/Makefile
-	utils/nfsdcld/Makefile
+	utils/nfsdcltrack/Makefile
 	utils/exportfs/Makefile
 	utils/gssd/Makefile
 	utils/idmapd/Makefile
utils/Makefile.am +2 -2
index 09045dd..b892dc8 100644
@@ -21,8 +21,8 @@ if CONFIG_MOUNT
 OPTDIRS += mount
 endif
 
-if CONFIG_NFSDCLD
-OPTDIRS += nfsdcld
+if CONFIG_NFSDCLTRACK
+OPTDIRS += nfsdcltrack
 endif
 
 SUBDIRS = \
utils/nfsdcld/Makefile.am deleted +0 -14
deleted file mode 100644
index 073a71b..0000000
@@ -1,14 +0,0 @@
-## Process this file with automake to produce Makefile.in
-
-man8_MANS	= nfsdcld.man
-EXTRA_DIST	= $(man8_MANS)
-
-AM_CFLAGS	+= -D_LARGEFILE64_SOURCE
-sbin_PROGRAMS	= nfsdcld
-
-nfsdcld_SOURCES = nfsdcld.c sqlite.c
-
-nfsdcld_LDADD = ../../support/nfs/libnfs.a $(LIBEVENT) $(LIBSQLITE) $(LIBCAP)
-
-MAINTAINERCLEANFILES = Makefile.in
-
utils/nfsdcld/nfsdcld.c deleted +0 -607

607 lines not on this page · raw message

utils/nfsdcld/nfsdcld.man deleted +0 -185

185 lines not on this page · raw message

utils/nfsdcld/sqlite.c deleted +0 -386

386 lines not on this page · raw message

utils/nfsdcld/sqlite.h deleted +0 -29
deleted file mode 100644
index c85e7d6..0000000
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2011  Red Hat, Jeff Layton <[email protected]>
- *
- * 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.
- */
-
-#ifndef _SQLITE_H_
-#define _SQLITE_H_
-
-int sqlite_maindb_init(char *topdir);
-int sqlite_insert_client(const unsigned char *clname, const size_t namelen);
-int sqlite_remove_client(const unsigned char *clname, const size_t namelen);
-int sqlite_check_client(const unsigned char *clname, const size_t namelen);
-int sqlite_remove_unreclaimed(const time_t grace_start);
-
-#endif /* _SQLITE_H */
utils/nfsdcltrack/Makefile.am new file +14 -0
new file mode 100644
index 0000000..073a71b
@@ -0,0 +1,14 @@
+## Process this file with automake to produce Makefile.in
+
+man8_MANS	= nfsdcld.man
+EXTRA_DIST	= $(man8_MANS)
+
+AM_CFLAGS	+= -D_LARGEFILE64_SOURCE
+sbin_PROGRAMS	= nfsdcld
+
+nfsdcld_SOURCES = nfsdcld.c sqlite.c
+
+nfsdcld_LDADD = ../../support/nfs/libnfs.a $(LIBEVENT) $(LIBSQLITE) $(LIBCAP)
+
+MAINTAINERCLEANFILES = Makefile.in
+
utils/nfsdcltrack/nfsdcld.c new file +607 -0

607 lines not on this page · raw message

utils/nfsdcltrack/nfsdcld.man new file +185 -0

185 lines not on this page · raw message

utils/nfsdcltrack/sqlite.c new file +386 -0

386 lines not on this page · raw message

utils/nfsdcltrack/sqlite.h new file +29 -0
new file mode 100644
index 0000000..c85e7d6
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2011  Red Hat, Jeff Layton <[email protected]>
+ *
+ * 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.
+ */
+
+#ifndef _SQLITE_H_
+#define _SQLITE_H_
+
+int sqlite_maindb_init(char *topdir);
+int sqlite_insert_client(const unsigned char *clname, const size_t namelen);
+int sqlite_remove_client(const unsigned char *clname, const size_t namelen);
+int sqlite_check_client(const unsigned char *clname, const size_t namelen);
+int sqlite_remove_unreclaimed(const time_t grace_start);
+
+#endif /* _SQLITE_H */
Signature · 1 line
1.7.11.7
#3 lore raw

PATCH v3 3/9 nfsdcltrack: remove pointless sqlite_topdir variable

In reply to Jeff Layton

This is holdover from an earlier version of the code and doesn't really provide any benefit. Also, mark the topdir and dirname arguments const since they should never be changed.

---
 utils/nfsdcltrack/sqlite.c | 13 ++++---------
 utils/nfsdcltrack/sqlite.h |  2 +-
 2 files changed, 5 insertions(+), 10 deletions(-)
utils/nfsdcltrack/sqlite.c +4 -9
index fc882c6..c19af7e 100644
@@ -61,9 +61,6 @@
 
 /* global variables */
 
-/* top level DB directory */
-static char *sqlite_topdir;
-
 /* reusable pathname and sql command buffer */
 static char buf[PATH_MAX];
 
@@ -74,7 +71,7 @@ static sqlite3 *dbh;
 
 /* make a directory, ignoring EEXIST errors unless it's not a directory */
 static int
-mkdir_if_not_exist(char *dirname)
+mkdir_if_not_exist(const char *dirname)
 {
 	int ret;
 	struct stat statbuf;
@@ -102,19 +99,17 @@ mkdir_if_not_exist(char *dirname)
  * the "clients" table.
  */
 int
-sqlite_maindb_init(char *topdir)
+sqlite_maindb_init(const char *topdir)
 {
 	int ret;
 	char *err = NULL;
 	sqlite3_stmt *stmt = NULL;
 
-	sqlite_topdir = topdir;
-
-	ret = mkdir_if_not_exist(sqlite_topdir);
+	ret = mkdir_if_not_exist(topdir);
 	if (ret)
 		return ret;
 
-	ret = snprintf(buf, PATH_MAX - 1, "%s/main.sqlite", sqlite_topdir);
+	ret = snprintf(buf, PATH_MAX - 1, "%s/main.sqlite", topdir);
 	if (ret < 0)
 		return ret;
 
utils/nfsdcltrack/sqlite.h +1 -1
index c85e7d6..8748948 100644
@@ -20,7 +20,7 @@
 #ifndef _SQLITE_H_
 #define _SQLITE_H_
 
-int sqlite_maindb_init(char *topdir);
+int sqlite_maindb_init(const char *topdir);
 int sqlite_insert_client(const unsigned char *clname, const size_t namelen);
 int sqlite_remove_client(const unsigned char *clname, const size_t namelen);
 int sqlite_check_client(const unsigned char *clname, const size_t namelen);
Signature · 1 line
1.7.11.7
#4 lore raw

PATCH v3 4/9 nfsdcltrack: break out a function to open the database handle

In reply to Jeff Layton

When we add a new usermodehelper upcall program to do the database access, the existing "init" function will be overkill every time we start up the program.

Break out the database handle establishment routine into a separate function that we can call from each upcall command in the one-shot program.

---
 utils/nfsdcltrack/sqlite.c | 49 ++++++++++++++++++++++++++++++++--------------
 utils/nfsdcltrack/sqlite.h |  1 +
 2 files changed, 35 insertions(+), 15 deletions(-)
utils/nfsdcltrack/sqlite.c +34 -15
index c19af7e..bac6789 100644
@@ -90,24 +90,15 @@ mkdir_if_not_exist(const char *dirname)
 	return ret;
 }
 
-/*
- * Open the "main" database, and attempt to initialize it by creating the
- * parameters table and inserting the schema version into it. Ignore any errors
- * from that, and then attempt to select the version out of it again. If the
- * version appears wrong, then assume that the DB is corrupt or has been
- * upgraded, and return an error. If all of that works, then attempt to create
- * the "clients" table.
- */
+/* Open the database and set up the database handle for it */
 int
-sqlite_maindb_init(const char *topdir)
+sqlite_prepare_dbh(const char *topdir)
 {
 	int ret;
-	char *err = NULL;
-	sqlite3_stmt *stmt = NULL;
 
-	ret = mkdir_if_not_exist(topdir);
-	if (ret)
-		return ret;
+	/* Do nothing if the database handle is already set up */
+	if (dbh)
+		return 0;
 
 	ret = snprintf(buf, PATH_MAX - 1, "%s/main.sqlite", topdir);
 	if (ret < 0)
@@ -118,15 +109,43 @@ sqlite_maindb_init(const char *topdir)
 	ret = sqlite3_open(buf, &dbh);
 	if (ret != SQLITE_OK) {
 		xlog(L_ERROR, "Unable to open main database: %d", ret);
+		dbh = NULL;
 		return ret;
 	}
 
 	ret = sqlite3_busy_timeout(dbh, CLD_SQLITE_BUSY_TIMEOUT);
 	if (ret != SQLITE_OK) {
 		xlog(L_ERROR, "Unable to set sqlite busy timeout: %d", ret);
-		goto out_err;
+		sqlite3_close(dbh);
+		dbh = NULL;
 	}
 
+	return ret;
+}
+
+/*
+ * Open the "main" database, and attempt to initialize it by creating the
+ * parameters table and inserting the schema version into it. Ignore any errors
+ * from that, and then attempt to select the version out of it again. If the
+ * version appears wrong, then assume that the DB is corrupt or has been
+ * upgraded, and return an error. If all of that works, then attempt to create
+ * the "clients" table.
+ */
+int
+sqlite_maindb_init(const char *topdir)
+{
+	int ret;
+	char *err = NULL;
+	sqlite3_stmt *stmt = NULL;
+
+	ret = mkdir_if_not_exist(topdir);
+	if (ret)
+		return ret;
+
+	ret = sqlite_prepare_dbh(topdir);
+	if (ret)
+		return ret;
+
 	/* Try to create table */
 	ret = sqlite3_exec(dbh, "CREATE TABLE IF NOT EXISTS parameters "
 				"(key TEXT PRIMARY KEY, value TEXT);",
utils/nfsdcltrack/sqlite.h +1 -0
index 8748948..ebf04c3 100644
@@ -20,6 +20,7 @@
 #ifndef _SQLITE_H_
 #define _SQLITE_H_
 
+int sqlite_prepare_dbh(const char *topdir);
 int sqlite_maindb_init(const char *topdir);
 int sqlite_insert_client(const unsigned char *clname, const size_t namelen);
 int sqlite_remove_client(const unsigned char *clname, const size_t namelen);
Signature · 1 line
1.7.11.7
#5 lore raw

PATCH v3 5/9 nfsdcltrack: add a new "one-shot" program for manipulating the client tracking db

In reply to Jeff Layton

Usermode helper upcalls are all the rage these days for infrequent upcalls, since they make it rather idiot-proof. No running daemon is required, so there's really no setup beyond ensuring that the callout exists and is runnable.

This program adds a callout program to nfs-utils for that purpose. The storage engine on the backend is identical to the one used by nfsdcld. This just adds a new frontend for it.

For now, building with --enable-nfsdcltrack gives you both nfsdcld and nfsdcltrack programs. A later patch will remove nfsdcld altogether.

---
 utils/nfsdcltrack/Makefile.am   |   6 +-
 utils/nfsdcltrack/nfsdcltrack.c | 436 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 440 insertions(+), 2 deletions(-)
 create mode 100644 utils/nfsdcltrack/nfsdcltrack.c
utils/nfsdcltrack/Makefile.am +4 -2
index 073a71b..afae455 100644
@@ -4,11 +4,13 @@ man8_MANS	= nfsdcld.man
 EXTRA_DIST	= $(man8_MANS)
 
 AM_CFLAGS	+= -D_LARGEFILE64_SOURCE
-sbin_PROGRAMS	= nfsdcld
+sbin_PROGRAMS	= nfsdcld nfsdcltrack
 
 nfsdcld_SOURCES = nfsdcld.c sqlite.c
-
 nfsdcld_LDADD = ../../support/nfs/libnfs.a $(LIBEVENT) $(LIBSQLITE) $(LIBCAP)
 
+nfsdcltrack_SOURCES = nfsdcltrack.c sqlite.c
+nfsdcltrack_LDADD = ../../support/nfs/libnfs.a $(LIBSQLITE) $(LIBCAP)
+
 MAINTAINERCLEANFILES = Makefile.in
 
utils/nfsdcltrack/nfsdcltrack.c new file +436 -0

436 lines not on this page · raw message

Signature · 1 line
1.7.11.7
#6 lore raw

PATCH v3 6/9 nfsdcltrack: add a legacy transition mechanism

In reply to Jeff Layton

If the kernel passes the legacy recdir path in the environment, then we can use that to transition from the old legacy tracker to the new one.

On a "check" operation, if there is no record of the client in the database, check to see if there is a matching recoverydir. If there isn't then just refuse the reclaim. If there is, then insert a new record for this client into the db, and remove the legacy recoverydir. If either of those operations fail, then refuse the reclaim.

On a "gracedone" operation, clean out the entire legacy recoverydir after purging any unreclaimed records from the db. There's not much we can do if this fails, so just log a warning if it does.

Note that this is a one-way conversion. If the user later boots back into an older kernel, it will have no knowledge of the new database.

In principle, we could create a tool that would walk the clients table, md5 hash the clientids and create directories in the v4recovery dir. Doing that automatically would be pretty difficult however.

---
 utils/nfsdcltrack/nfsdcltrack.c | 85 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 85 insertions(+)
utils/nfsdcltrack/nfsdcltrack.c +85 -0
index 1d262a2..9801b9c 100644
@@ -36,6 +36,7 @@
 #include <unistd.h>
 #include <libgen.h>
 #include <sys/inotify.h>
+#include <dirent.h>
 #ifdef HAVE_SYS_CAPABILITY_H
 #include <sys/prctl.h>
 #include <sys/capability.h>
@@ -296,6 +297,48 @@ cltrack_remove(const char *id)
 }
 
 static int
+cltrack_check_legacy(const unsigned char *blob, const ssize_t len)
+{
+	int ret;
+	struct stat st;
+	char *recdir = getenv("NFSDCLTRACK_LEGACY_RECDIR");
+
+	if (!recdir) {
+		xlog(D_GENERAL, "No NFSDCLTRACK_LEGACY_RECDIR env var");
+		return -EOPNOTSUPP;
+	}
+
+	/* fail recovery on any stat failure */
+	ret = stat(recdir, &st);
+	if (ret) {
+		xlog(D_GENERAL, "Unable to stat %s: %d", recdir, errno);
+		return -errno;
+	}
+
+	/* fail if it isn't a directory */
+	if (!S_ISDIR(st.st_mode)) {
+		xlog(D_GENERAL, "%s is not a directory: mode=0%o", recdir
+				, st.st_mode);
+		return -ENOTDIR;
+	}
+
+	/* Dir exists, try to insert record into db */
+	ret = sqlite_insert_client(blob, len);
+	if (ret) {
+		xlog(D_GENERAL, "Failed to insert client: %d", ret);
+		return -EREMOTEIO;
+	}
+
+	/* remove the legacy recoverydir */
+	ret = rmdir(recdir);
+	if (ret) {
+		xlog(D_GENERAL, "Failed to rmdir %s: %d", recdir, errno);
+		return -errno;
+	}
+	return 0;
+}
+
+static int
 cltrack_check(const char *id)
 {
 	int ret;
@@ -312,10 +355,50 @@ cltrack_check(const char *id)
 		return (int)len;
 
 	ret = sqlite_check_client(blob, len);
+	if (ret)
+		ret = cltrack_check_legacy(blob, len);
 
 	return ret ? -EPERM : ret;
 }
 
+/* Clean out the v4recoverydir -- best effort here */
+static void
+cltrack_legacy_gracedone(void)
+{
+	DIR *v4recovery;
+	struct dirent *entry;
+	char *dirname = getenv("NFSDCLTRACK_LEGACY_TOPDIR");
+
+	if (!dirname)
+		return;
+
+	v4recovery = opendir(dirname);
+	if (!v4recovery)
+		return;
+
+	while ((entry = readdir(v4recovery))) {
+		int len;
+
+		/* borrow the clientid blob for this */
+		len = snprintf((char *)blob, sizeof(blob), "%s/%s", dirname,
+				entry->d_name);
+
+		/* if there's a problem, then skip this entry */
+		if (len < 0 || (size_t)len >= sizeof(blob)) {
+			xlog(L_WARNING, "%s: unable to build filename for %s!",
+				__func__, entry->d_name);
+			continue;
+		}
+
+		len = rmdir((char *)blob);
+		if (len)
+			xlog(L_WARNING, "%s: unable to rmdir %s: %d", __func__,
+				(char *)blob, len);
+	}
+
+	closedir(v4recovery);
+}
+
 static int
 cltrack_gracedone(const char *timestr)
 {
@@ -343,6 +426,8 @@ cltrack_gracedone(const char *timestr)
 
 	ret = sqlite_remove_unreclaimed(gracetime);
 
+	cltrack_legacy_gracedone();
+
 	return ret ? -EREMOTEIO : ret;
 }
 
Signature · 1 line
1.7.11.7
#7 lore raw

PATCH v3 7/9 nfsdcltrack: add a manpage for nfsdcltrack

In reply to Jeff Layton
---
 utils/nfsdcltrack/Makefile.am     |   2 +-
 utils/nfsdcltrack/nfsdcltrack.man | 211 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 212 insertions(+), 1 deletion(-)
 create mode 100644 utils/nfsdcltrack/nfsdcltrack.man
utils/nfsdcltrack/Makefile.am +1 -1
index afae455..1746a25 100644
@@ -1,6 +1,6 @@
 ## Process this file with automake to produce Makefile.in
 
-man8_MANS	= nfsdcld.man
+man8_MANS	= nfsdcld.man nfsdcltrack.man
 EXTRA_DIST	= $(man8_MANS)
 
 AM_CFLAGS	+= -D_LARGEFILE64_SOURCE
utils/nfsdcltrack/nfsdcltrack.man new file +211 -0

211 lines not on this page · raw message

Signature · 1 line
1.7.11.7
#8 lore raw

PATCH v3 8/9 nfsdcltrack: remove the nfsdcld daemon

In reply to Jeff Layton

Since we want to move to using the usermodehelper upcall unconditionally, just remove nfsdcld. The kernel code to handle this will be formally deprecated in 3.10 as well.

---
 utils/nfsdcltrack/Makefile.am |   7 +-
 utils/nfsdcltrack/nfsdcld.c   | 607 ------------------------------------------
 utils/nfsdcltrack/nfsdcld.man | 185 -------------
 3 files changed, 2 insertions(+), 797 deletions(-)
 delete mode 100644 utils/nfsdcltrack/nfsdcld.c
 delete mode 100644 utils/nfsdcltrack/nfsdcld.man
utils/nfsdcltrack/Makefile.am +2 -5
index 1746a25..a860ffb 100644
@@ -1,13 +1,10 @@
 ## Process this file with automake to produce Makefile.in
 
-man8_MANS	= nfsdcld.man nfsdcltrack.man
+man8_MANS	= nfsdcltrack.man
 EXTRA_DIST	= $(man8_MANS)
 
 AM_CFLAGS	+= -D_LARGEFILE64_SOURCE
-sbin_PROGRAMS	= nfsdcld nfsdcltrack
-
-nfsdcld_SOURCES = nfsdcld.c sqlite.c
-nfsdcld_LDADD = ../../support/nfs/libnfs.a $(LIBEVENT) $(LIBSQLITE) $(LIBCAP)
+sbin_PROGRAMS	= nfsdcltrack
 
 nfsdcltrack_SOURCES = nfsdcltrack.c sqlite.c
 nfsdcltrack_LDADD = ../../support/nfs/libnfs.a $(LIBSQLITE) $(LIBCAP)
utils/nfsdcltrack/nfsdcld.c deleted +0 -607

607 lines not on this page · raw message

utils/nfsdcltrack/nfsdcld.man deleted +0 -185

185 lines not on this page · raw message

Signature · 1 line
1.7.11.7
#9 lore raw

PATCH v3 9/9 nfsdcltrack: update the README about server startup order

In reply to Jeff Layton

Now that nfsdcld is gone, remove the section about starting it up.

---
 README | 23 ++---------------------
 1 file changed, 2 insertions(+), 21 deletions(-)
README +2 -21
index e55b2dd..61702f7 100644
@@ -108,31 +108,12 @@ scripts can be written to work correctly.
        the lock.
        rpc.statd is only needed for NFSv2 and NFSv3 support.
 
-   E/ nfsdcld
-       This daemon is only needed on kernels that support the nfsdcld
-       upcall, and only if the legacy client ID tracking isn't used. It
-       is also not needed if the server does not support NFSv4.
-
-       To determine whether you need this or not, do the following:
-
-           # cat /proc/fs/nfsd/versions
-
-       That should yield a list of NFS versions that this kernel supports,
-       if "4" or later is not in that list, or they are prefixed with a "-"
-       then you don't need to run this daemon. Next:
-
-           # cat /proc/fs/nfsd/nfsv4recoverydir
-
-       If that file is not present, or the directory that the above command
-       outputs is not present, then this daemon is required in order to
-       support lock recovery by the clients when the server reboots.
-
-   F/ rpc.nfsd
+   E/ rpc.nfsd
        Starting nfsd will automatically start lockd.  The nfs server
        will now be fully active and respond to any requests from
        clients.
        
-   G/ sm-notify
+   F/ sm-notify
        This will notify any client which might have locks from before
        a reboot to try to reclaim their locks.  This should start
        immediately after rpc.nfsd is started so that clients have a
Signature · 1 line
1.7.11.7