Skip to contentSkip to conversation

nfsdcltrack: create a new usermodehelper upcall program for tracking clients

PATCH Superseded Jeff Layton 2 participants 13 messages Oct 1, 2012 – Oct 3, 2012

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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

This is a companion patchset to the kernel set posted earlier. It adds a new callout program for the kernel that handles client ID tracking.

The nfsdcld directory is first renamed to something more generic and then a new program is added to handle the callout. The storage backend for the program is identical to the one used by nfsdcld. This program is really just a new frontend for that.

We could even (in principle) have them use the same db directory, but for now I've made this program use a separate one.

Comments and suggestions welcome...

Jeff Layton (6):
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 manpage for nfsdcltrack
nfsdcltrack: update the README about server startup order

 README                                     |  12 +-
 configure.ac                               |  20 +-
 utils/Makefile.am                          |   4 +-
 utils/{nfsdcld => nfsdcltrack}/Makefile.am |   8 +-
 utils/{nfsdcld => nfsdcltrack}/nfsdcld.c   |   0
 utils/{nfsdcld => nfsdcltrack}/nfsdcld.man |   0
 utils/nfsdcltrack/nfsdcltrack.c            | 435 +++++++++++++++++++++++++++++
 utils/nfsdcltrack/nfsdcltrack.man          | 194 +++++++++++++
 utils/{nfsdcld => nfsdcltrack}/sqlite.c    |  58 ++--
 utils/{nfsdcld => nfsdcltrack}/sqlite.h    |   3 +-
 10 files changed, 693 insertions(+), 41 deletions(-)
 rename utils/{nfsdcld => nfsdcltrack}/Makefile.am (59%)
 rename utils/{nfsdcld => nfsdcltrack}/nfsdcld.c (100%)
 rename utils/{nfsdcld => nfsdcltrack}/nfsdcld.man (100%)
 create mode 100644 utils/nfsdcltrack/nfsdcltrack.c
 create mode 100644 utils/nfsdcltrack/nfsdcltrack.man
 rename utils/{nfsdcld => nfsdcltrack}/sqlite.c (94%)
 rename utils/{nfsdcld => nfsdcltrack}/sqlite.h (92%)
Signature · 1 line
1.7.11.4
#1 lore raw

PATCH 1/6 nfsdcltrack: rename the nfsdcld directory and options to nfsdcltrack

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.

---
 configure.ac                               | 20 ++++++++++----------
 utils/Makefile.am                          |  4 ++--
 utils/{nfsdcld => nfsdcltrack}/Makefile.am |  0
 utils/{nfsdcld => nfsdcltrack}/nfsdcld.c   |  0
 utils/{nfsdcld => nfsdcltrack}/nfsdcld.man |  0
 utils/{nfsdcld => nfsdcltrack}/sqlite.c    |  0
 utils/{nfsdcld => nfsdcltrack}/sqlite.h    |  0
 7 files changed, 12 insertions(+), 12 deletions(-)
 rename utils/{nfsdcld => nfsdcltrack}/Makefile.am (100%)
 rename utils/{nfsdcld => nfsdcltrack}/nfsdcld.c (100%)
 rename utils/{nfsdcld => nfsdcltrack}/nfsdcld.man (100%)
 rename utils/{nfsdcld => nfsdcltrack}/sqlite.c (100%)
 rename utils/{nfsdcld => nfsdcltrack}/sqlite.h (100%)
configure.ac +10 -10
index a174bf4..65d1bea 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=no@:>@])],
+	enable_nfsdctrack=$enableval,
+	enable_nfsdcltrack="no")
 
 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/nfsdcltrack/Makefile.am renamed from utils/nfsdcld/Makefile.am +0 -0
similarity index 100%
rename from utils/nfsdcld/Makefile.am
rename to utils/nfsdcltrack/Makefile.am
utils/nfsdcltrack/nfsdcld.c renamed from utils/nfsdcld/nfsdcld.c +0 -0
similarity index 100%
rename from utils/nfsdcld/nfsdcld.c
rename to utils/nfsdcltrack/nfsdcld.c
utils/nfsdcltrack/nfsdcld.man renamed from utils/nfsdcld/nfsdcld.man +0 -0
similarity index 100%
rename from utils/nfsdcld/nfsdcld.man
rename to utils/nfsdcltrack/nfsdcld.man
utils/nfsdcltrack/sqlite.c renamed from utils/nfsdcld/sqlite.c +0 -0
similarity index 100%
rename from utils/nfsdcld/sqlite.c
rename to utils/nfsdcltrack/sqlite.c
utils/nfsdcltrack/sqlite.h renamed from utils/nfsdcld/sqlite.h +0 -0
similarity index 100%
rename from utils/nfsdcld/sqlite.h
rename to utils/nfsdcltrack/sqlite.h
Signature · 1 line
1.7.11.4
#2 lore raw

PATCH 2/6 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.4
#3 lore raw

PATCH 3/6 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.4
#4 lore raw

PATCH 4/6 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 to set up an upcall. 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. Eventually we may want to put these under separate configure options or just deprecate nfsdcld if there's no interest in maintaining it long-term.

---
 utils/nfsdcltrack/Makefile.am   |   6 +-
 utils/nfsdcltrack/nfsdcltrack.c | 435 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 439 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 +435 -0

435 lines not on this page · raw message

Signature · 1 line
1.7.11.4
#5 lore raw

PATCH 5/6 nfsdcltrack: add a manpage for nfsdcltrack

In reply to Jeff Layton
---
 utils/nfsdcltrack/Makefile.am     |   2 +-
 utils/nfsdcltrack/nfsdcltrack.man | 194 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 195 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 +194 -0

194 lines not on this page · raw message

Signature · 1 line
1.7.11.4
#6 lore raw

PATCH 6/6 nfsdcltrack: update the README about server startup order

In reply to Jeff Layton

If we eventually deprecate nfsdcld, then we can just remove this section I think.

---
 README | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
README +9 -3
index e55b2dd..f997783 100644
@@ -110,8 +110,9 @@ scripts can be written to work correctly.
 
    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.
+       upcall, and only if the legacy client ID tracking and nfsdcltrack
+       aren'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:
 
@@ -124,7 +125,12 @@ scripts can be written to work correctly.
            # 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
+       outputs is not present, then check this:
+
+	   # modinfo nfsd | grep cltrack_prog
+
+       to see whether the kernel supports the nfsdcltrack upcall. If
+       none of those are configured then this daemon is required in order to
        support lock recovery by the clients when the server reboots.
 
    F/ rpc.nfsd
Signature · 1 line
1.7.11.4
#7 lore raw

[PATCH 7/6] 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. Trying to do that automatically would be a mess though...

---
 utils/nfsdcltrack/nfsdcltrack.c | 87 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 87 insertions(+)
utils/nfsdcltrack/nfsdcltrack.c +87 -0
index db7e534..7c2625a 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,50 @@ cltrack_remove(const char *id)
 }
 
 static int
+cltrack_check_legacy(const unsigned char *blob, const ssize_t len)
+{
+	int ret;
+	char *recdir;
+	struct stat st;
+
+	/* see if the legacy recdir exists */
+	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 +357,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)
+{
+	char *dirname = getenv("NFSDCLTRACK_LEGACY_TOPDIR");
+	DIR *v4recovery;
+	struct dirent *entry;
+
+	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 +428,8 @@ cltrack_gracedone(const char *timestr)
 
 	ret = sqlite_remove_unreclaimed(gracetime);
 
+	cltrack_legacy_gracedone();
+
 	return ret ? -EREMOTEIO : ret;
 }
 
Signature · 1 line
1.7.11.4
#8 lore raw

Re: [PATCH 7/6] nfsdcltrack: add a legacy transition mechanism

On Wed, Oct 3, 2012 at 8:42 AM, Jeff Layton <[email protected]> wrote:
[snip]

utils/nfsdcltrack/nfsdcltrack.c cltrack_check(const char *id) · line 393

Quoted 6 lines
utils/nfsdcltrack/nfsdcltrack.c +6 -0
+               /* 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;
+               }

Is a len == 0 not a problem?

Signature · 2 lines
Peace and Blessings,
-Scott.
#9 lore raw

Re: [PATCH 7/6] nfsdcltrack: add a legacy transition mechanism

Quoted 11 lines · On Wed, 3 Oct 2012 09:34:36 -0400 Scott Lovenberg <[email protected]>…

On Wed, Oct 3, 2012 at 8:42 AM, Jeff Layton <[email protected]> wrote:
[snip]

utils/nfsdcltrack/nfsdcltrack.c cltrack_check(const char *id) · line 393

Quoted 6 lines
utils/nfsdcltrack/nfsdcltrack.c +6 -0
+               /* 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;
+               }

Is a len == 0 not a problem?

I'm not sure -- under what circumstances would it return 0?

Signature · 1 line
Jeff Layton <[email protected]>
#10 lore raw

Re: [PATCH 7/6] nfsdcltrack: add a legacy transition mechanism

Quoted 12 lines · Jeff Layton
Quoted 9 lines · On Wed, 3 Oct 2012 09:34:36 -0400 Scott Lovenberg <[email protected]>…

On Wed, Oct 3, 2012 at 8:42 AM, Jeff Layton <[email protected]> wrote:
[snip]

Quoted 6 lines
utils/nfsdcltrack/nfsdcltrack.c +6 -0
+               /* 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;
+               }
Quoted 7 lines
Quoted 2 lines

Is a len == 0 not a problem?

I'm not sure -- under what circumstances would it return 0?

--
Jeff Layton <[email protected]>

I guess the only case would be if sizeof(blob) was 0, then snprintf would return a value < 1 according to the SUSv2. Apparently C99 says the return value will be > 0. I guess this is a non-issue?

Signature · 2 lines
Peace and Blessings,
-Scott.
#11 lore raw

Re: [PATCH 7/6] nfsdcltrack: add a legacy transition mechanism

Quoted 16 lines · On Wed, 3 Oct 2012 09:52:02 -0400 Scott Lovenberg <[email protected]>…
Quoted 15 lines · Jeff Layton
Quoted 11 lines · On Wed, 3 Oct 2012 09:34:36 -0400 Scott Lovenberg <[email protected]>…

On Wed, Oct 3, 2012 at 8:42 AM, Jeff Layton <[email protected]> wrote:
[snip]

utils/nfsdcltrack/nfsdcltrack.c cltrack_check(const char *id) · line 393

Quoted 6 lines
utils/nfsdcltrack/nfsdcltrack.c +6 -0
+               /* 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;
+               }

Is a len == 0 not a problem?

Quoted 9 lines
Quoted 4 lines

I'm not sure -- under what circumstances would it return 0?

--
Jeff Layton <[email protected]>

I guess the only case would be if sizeof(blob) was 0, then snprintf would return a value < 1 according to the SUSv2. Apparently C99 says the return value will be > 0. I guess this is a non-issue?

I think so, yes. The main worry here is overrunning the buffer and I think the error checking I'm doing has that covered.

Signature · 1 line
Jeff Layton <[email protected]>
#12 lore raw

Re: [PATCH 7/6] nfsdcltrack: add a legacy transition mechanism

Quoted 29 lines · Jeff Layton
Quoted 16 lines · On Wed, 3 Oct 2012 09:52:02 -0400 Scott Lovenberg <[email protected]>…
Quoted 15 lines · Jeff Layton
Quoted 11 lines · On Wed, 3 Oct 2012 09:34:36 -0400 Scott Lovenberg <[email protected]>…

On Wed, Oct 3, 2012 at 8:42 AM, Jeff Layton <[email protected]> wrote:
[snip]

utils/nfsdcltrack/nfsdcltrack.c cltrack_check(const char *id) · line 393

Quoted 6 lines
utils/nfsdcltrack/nfsdcltrack.c +6 -0
+               /* 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;
+               }

Is a len == 0 not a problem?

Quoted 9 lines
Quoted 4 lines

I'm not sure -- under what circumstances would it return 0?

--
Jeff Layton <[email protected]>

I guess the only case would be if sizeof(blob) was 0, then snprintf would return a value < 1 according to the SUSv2. Apparently C99 says the return value will be > 0. I guess this is a non-issue?

Quoted 5 lines

I think so, yes. The main worry here is overrunning the buffer and I think the error checking I'm doing has that covered.

--
Jeff Layton <[email protected]>

Agreed. Sorry for the noise. :)

Signature · 2 lines
Peace and Blessings,
-Scott.