nfsdcltrack: create a new usermodehelper upcall program for tracking clients
Subsystems (2)
v2 cover nfsdcltrack: create a new usermodehelper upcall program for tracking clients
This is a respin of the set that I sent on Oct 1st. The main differences from that set are:
- a new legacy transition mechanism has been added and the manpage has been updated to document it
- the nfsdcld daemon is being removed wholesale. Steve D. requested that we just go ahead and pull the plug on it, and I didn't see any reason to object
- the default is now to build nfsdcltrack if all of the dependencies for it are in place
It's a fairly simple program and I've tested it as best I can. At this point, I'd like to see this patchset go into the next nfs-utils release.
Jeff Layton (10):
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
nfsdcltrack: flip the default in autoconf to "yes" for it
README | 23 +- configure.ac | 34 ++- 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 | 526 +++++++++++++++++++++++++++++++++ utils/nfsdcltrack/nfsdcltrack.man | 211 +++++++++++++ utils/nfsdcltrack/sqlite.c | 400 +++++++++++++++++++++++++ utils/nfsdcltrack/sqlite.h | 30 ++ 13 files changed, 1206 insertions(+), 1256 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
PATCH v2 1/10 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
@@ -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
PATCH v2 2/10 nfsdcltrack: rename the nfsdcld directory and options to nfsdcltrack
In reply to Jeff LaytonWe'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/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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v2 3/10 nfsdcltrack: remove pointless sqlite_topdir variable
In reply to Jeff LaytonThis 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
@@ -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
@@ -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
PATCH v2 4/10 nfsdcltrack: break out a function to open the database handle
In reply to Jeff LaytonWhen 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
@@ -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
@@ -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
PATCH v2 5/10 nfsdcltrack: add a new "one-shot" program for manipulating the client tracking db
In reply to Jeff LaytonUsermode 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 | 441 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 445 insertions(+), 2 deletions(-) create mode 100644 utils/nfsdcltrack/nfsdcltrack.c
utils/nfsdcltrack/Makefile.am +4 -2
@@ -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 +441 -0
441 lines not on this page · raw message
Signature · 1 line
1.7.11.7
Re: [PATCH v2 05/10] nfsdcltrack: add a new "one-shot" program for manipulating the client tracking db
Over all it I think it look very good... but a couple small nits at the bottom...
Quoted 412 lines · 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.
Signed-off-by Jeff Layton <[email protected]>--- utils/nfsdcltrack/Makefile.am | 6 +- utils/nfsdcltrack/nfsdcltrack.c | 441 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 445 insertions(+), 2 deletions(-) create mode 100644 utils/nfsdcltrack/nfsdcltrack.cutils/nfsdcltrack/Makefile.am +4
-2@@ -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.inutils/nfsdcltrack/nfsdcltrack.c new file +367
-0@@ -0,0 +1,441 @@ +/* +* nfsdcltrack.c -- NFSv4 client name tracking program +* +* Copyright (C) 2012 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. +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include <stdio.h> +#include <stdlib.h> +#include <ctype.h> +#include <errno.h> +#include <stdbool.h> +#include <getopt.h> +#include <string.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <fcntl.h> +#include <unistd.h> +#include <libgen.h> +#include <sys/inotify.h> +#ifdef HAVE_SYS_CAPABILITY_H +#include <sys/prctl.h> +#include <sys/capability.h> +#endif + +#include "xlog.h" +#include "sqlite.h" + +#ifndef CLD_DEFAULT_STORAGEDIR +#define CLD_DEFAULT_STORAGEDIR NFS_STATEDIR "/nfsdcltrack" +#endif + +/* defined by RFC 3530 */ +#define NFS4_OPAQUE_LIMIT 1024 + +/* private data structures */ +struct cltrack_cmd { +char *name; +bool needs_arg; +int (*func)(const char *arg); +}; + +/* forward declarations */ +static int cltrack_init (const char *unused); +static int cltrack_create (const char *id); +static int cltrack_remove (const char *id); +static int cltrack_check (const char *id); +static int cltrack_gracedone (const char *gracetime); + +/* global variables */ +static struct option longopts[] = +{ + {"help" ,0 ,NULL ,'h' }, + {"debug" ,0 ,NULL ,'d' }, + {"foreground" ,0 ,NULL ,'f' }, + {"storagedir" ,1 ,NULL ,'s' }, + {NULL ,0 ,0 ,0 }, +}; + +static struct cltrack_cmd commands[] = +{ + {"init" , false, cltrack_init }, + {"create" , true, cltrack_create }, + {"remove" , true, cltrack_remove }, + {"check" , true, cltrack_check }, + {"gracedone" , true, cltrack_gracedone }, + {NULL , false,NULL }, +}; + +static char *storagedir =CLD_DEFAULT_STORAGEDIR ; + +/* common buffer for holding id4 blobs */ +static unsigned char blob[NFS4_OPAQUE_LIMIT ]; + +static void +usage (char *progname) +{ +printf ("%s [ -hfd ] [ -s dir ] < cmd > < arg >\n" , progname); +printf ("Where < cmd > is one of the following and takes the following < arg >:\n" ); +printf (" init\n" ); +printf (" create <nfs_client_id4>\n" ); +printf (" remove <nfs_client_id4>\n" ); +printf (" check <nfs_client_id4>\n" ); +printf (" gracedone <epoch time>\n" ); +} + + +/** +* hex_to_bin - convert a hex digit to its real value +* @ch: ascii character represents hex digit +* +* hex_to_bin() converts one hex digit to its actual value or -1 in case of bad +* input. +* +* Note: borrowed from lib/hexdump.c in the Linux kernel sources. +*/ +static int +hex_to_bin (char ch) +{ +if ((ch >='0' ) && (ch <='9' )) +return ch -'0' ; + ch =tolower (ch); +if ((ch >='a' ) && (ch <='f' )) +return ch -'a' +10 ; +return -1 ; +} + +/** +* hex_str_to_bin - convert a hexidecimal string into a binary blob +* +* @src: string of hex digit pairs +* @dst: destination buffer to hold binary data +* @dstsize: size of the destination buffer +* +* Walk a string of hex digit pairs and convert them into binary data. Returns +* the resulting length of the binary data or a negative error code. If the +* data will not fit in the buffer, it returns -ENOBUFS (but will likely have +* clobbered the dst buffer in the process of determining that). If there are +* non-hexidecimal characters in the src, or an odd number of them then it +* returns -EINVAL. +*/ +static ssize_t +hex_str_to_bin (const char *src,unsigned char *dst,ssize_t dstsize) +{ +unsigned char *tmpdst = dst; + +while (*src) { +int hi, lo; + +/* make sure we don't overrun the dst buffer */ +if ((tmpdst - dst) >= dstsize) +return -ENOBUFS ; + + hi =hex_to_bin (*src++); + +/* did we get an odd number of characters? */ +if (!*src) +return -EINVAL ; + lo =hex_to_bin (*src++); + +/* one of the characters isn't a hex digit */ +if (hi <0 || lo <0 ) +return -EINVAL ; + +/* now place it in the dst buffer */ + *tmpdst++ = (hi <<4 ) | lo; + } + +return (ssize_t )(tmpdst - dst); +} + +/* +* This program will almost always be run with root privileges since the +* kernel will call out to run it. Drop all capabilities prior to doing +* anything important to limit the exposure to potential compromise. +* +* FIXME: should we setuid to a different user early on instead? +*/ +static int +cltrack_set_caps (void ) +{ +int ret =0 ; +#ifdef HAVE_SYS_CAPABILITY_H +unsigned long i; +cap_t caps; + +/* prune the bounding set to nothing */ +for (i =0 ;prctl (PR_CAPBSET_READ , i,0 ,0 ,0 ) >=0 ; ++i) { + ret =prctl (PR_CAPBSET_DROP , i,0 ,0 ,0 ); +if (ret) { +xlog (L_ERROR ,"Unable to prune capability %lu from " +"bounding set: %m" , i); +return -errno; + } + } + +/* get a blank capset */ + caps =cap_init (); +if (caps ==NULL ) { +xlog (L_ERROR ,"Unable to get blank capability set: %m" ); +return -errno; + } + +/* reset the process capabilities */ +if (cap_set_proc (caps) !=0 ) { +xlog (L_ERROR ,"Unable to set process capabilities: %m" ); + ret = -errno; + } +cap_free (caps); +#endif +return ret; +} + +static int +cltrack_init (const char __attribute__((unused)) *unused) +{ +int ret; + +/* +* see if the storagedir is writable by root w/o CAP_DAC_OVERRIDE. +* If it isn't then give the user a warning but proceed as if +* everything is OK. If the DB has already been created, then +* everything might still work. If it doesn't exist at all, then +* assume that the maindb init will be able to create it. Fail on +* anything else. +*/ +if (access (storagedir,W_OK ) ==-1 ) { +switch (errno) { +case EACCES : +xlog (L_WARNING ,"Storage directory %s is not writable. " +"Should be owned by root and writable " +"by owner!" , storagedir); +break ; +case ENOENT : +/* ignore and assume that we can create dir as root */ +break ; +default : +xlog (L_ERROR ,"Unexpected error when checking access " +"on %s: %m" , storagedir); +return -errno; + } + } + +/* set up storage db */ + ret =sqlite_maindb_init (storagedir); +if (ret) { +xlog (L_ERROR ,"Failed to init database: %d" , ret); +/* +* Convert any error here into -EACCES. It's not truly +* accurate in all cases, but it should cause the kernel to +* stop upcalling until the problem is resolved. +*/ + ret = -EACCES ; + } +return ret; +} + +static int +cltrack_create (const char *id) +{ +int ret; +ssize_t len; + +xlog (D_GENERAL ,"%s: create client record." , __func__); + + ret =sqlite_prepare_dbh (storagedir); +if (ret) +return ret; + + len =hex_str_to_bin (id, blob,sizeof (blob)); +if (len <0 ) +return (int )len; + + ret =sqlite_insert_client (blob, len); + +return ret ? -EREMOTEIO : ret; +} + +static int +cltrack_remove (const char *id) +{ +int ret; +ssize_t len; + +xlog (D_GENERAL ,"%s: remove client record." , __func__); + + ret =sqlite_prepare_dbh (storagedir); +if (ret) +return ret; + + len =hex_str_to_bin (id, blob,sizeof (blob)); +if (len <0 ) +return (int )len; + + ret =sqlite_remove_client (blob, len); + +return ret ? -EREMOTEIO : ret; +} + +static int +cltrack_check (const char *id) +{ +int ret; +ssize_t len; + +xlog (D_GENERAL ,"%s: check client record" , __func__); + + ret =sqlite_prepare_dbh (storagedir); +if (ret) +return ret; + + len =hex_str_to_bin (id, blob,sizeof (blob)); +if (len <0 ) +return (int )len; + + ret =sqlite_check_client (blob, len); + +return ret ? -EPERM : ret; +} + +static int +cltrack_gracedone (const char *timestr) +{ +int ret; +char *tail; +time_t gracetime; + + + ret =sqlite_prepare_dbh (storagedir); +if (ret) +return ret; + + errno =0 ; + gracetime =strtol (timestr, &tail,0 ); + +/* did the resulting value overflow? (Probably -ERANGE here) */ +if (errno) +return -errno; + +/* string wasn't fully converted */ +if (*tail) +return -EINVAL ; + +xlog (D_GENERAL ,"%s: grace done. gracetime=%ld" , __func__, gracetime); + + ret =sqlite_remove_unreclaimed (gracetime); + +return ret ? -EREMOTEIO : ret; +} + +static struct cltrack_cmd * +find_cmd (char *cmdname) +{ +struct cltrack_cmd *current = &commands[0 ]; + +while (current->name) { +if (!strcmp (cmdname, current->name)) +return current; + ++current; + } + +xlog (L_ERROR ,"%s: '%s' doesn't match any known command" , + __func__, cmdname); +return NULL ; +} + +int +main (int argc,char **argv) +{
utils/nfsdcltrack/nfsdcltrack.c line 377
Quoted 10 lines
utils/nfsdcltrack/nfsdcltrack.c new file +10
-0+char arg; +int rc =0 ; +char *progname, *cmdarg =NULL ; +struct cltrack_cmd *cmd; + + progname =strdup (basename (argv[0 ])); +if (!progname) { +fprintf (stderr,"%s: unable to allocate memory.\n" , argv[0 ]); +return 1 ; + }
Small nit: Do we really want to fail because we cannot get memory for the program name? Why not just use the string returned from basename()?
Quoted 49 lines
utils/nfsdcltrack/nfsdcltrack.c new file +49
-0+ +xlog_syslog (1 ); +xlog_stderr (0 ); + +/* process command-line options */ +while ((arg =getopt_long (argc, argv,"hdfs:" , longopts, +NULL )) !=EOF ) { +switch (arg) { +case 'd' : +xlog_config (D_ALL ,1 ); +case 'f' : +xlog_syslog (0 ); +xlog_stderr (1 ); +break ; +case 's' : + storagedir = optarg; +break ; +default : +usage (progname); +return 0 ; + } + } + +xlog_open (progname); + +/* we expect a command, at least */ +if (optind >= argc) { +xlog (L_ERROR ,"Missing command name\n" ); + rc = -EINVAL ; + goto out; + } + +/* drop all capabilities */ + rc =cltrack_set_caps (); +if (rc) + goto out; + + cmd =find_cmd (argv[optind]); +if (!cmd) { +/* +* In the event that we get a command that we don't understand +* then return a distinct error. The kernel can use this to +* determine a new kernel/old userspace situation and cope +* with it. +*/ + rc = -ENOSYS ; + goto out; + } +
utils/nfsdcltrack/nfsdcltrack.c line 436
Quoted 10 lines
utils/nfsdcltrack/nfsdcltrack.c new file +10
-0+/* populate arg var if command needs it */ +if (cmd->needs_arg) { +if (optind +1 >= argc) { +xlog (L_ERROR ,"Command %s requires an argument\n" , + cmd->name); + rc = -EINVAL ; + goto out; + } + cmdarg = argv[optind +1 ]; + }
Is needs_arg really necessary? Once the function is found, just pass it the rest of argv and let the function decide if there should be an argument or not... but again.. just a nit...
steved.
Quoted 6 lines
utils/nfsdcltrack/nfsdcltrack.c new file +5
-0+ rc = cmd->func (cmdarg); +out: +free (progname); +return rc; +}
Re: [PATCH v2 05/10] nfsdcltrack: add a new "one-shot" program for manipulating the client tracking db
Quoted 491 lines · On Thu, 25 Oct 2012 08:56:58 -0400 Steve Dickson <[email protected]> wrote:
Over all it I think it look very good... but a couple small nits at the bottom...
Quoted 412 lines · 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.
Signed-off-by Jeff Layton <[email protected]>--- utils/nfsdcltrack/Makefile.am | 6 +- utils/nfsdcltrack/nfsdcltrack.c | 441 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 445 insertions(+), 2 deletions(-) create mode 100644 utils/nfsdcltrack/nfsdcltrack.cutils/nfsdcltrack/Makefile.am +4
-2@@ -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.inutils/nfsdcltrack/nfsdcltrack.c new file +367
-0@@ -0,0 +1,441 @@ +/* +* nfsdcltrack.c -- NFSv4 client name tracking program +* +* Copyright (C) 2012 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. +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include <stdio.h> +#include <stdlib.h> +#include <ctype.h> +#include <errno.h> +#include <stdbool.h> +#include <getopt.h> +#include <string.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <fcntl.h> +#include <unistd.h> +#include <libgen.h> +#include <sys/inotify.h> +#ifdef HAVE_SYS_CAPABILITY_H +#include <sys/prctl.h> +#include <sys/capability.h> +#endif + +#include "xlog.h" +#include "sqlite.h" + +#ifndef CLD_DEFAULT_STORAGEDIR +#define CLD_DEFAULT_STORAGEDIR NFS_STATEDIR "/nfsdcltrack" +#endif + +/* defined by RFC 3530 */ +#define NFS4_OPAQUE_LIMIT 1024 + +/* private data structures */ +struct cltrack_cmd { +char *name; +bool needs_arg; +int (*func)(const char *arg); +}; + +/* forward declarations */ +static int cltrack_init (const char *unused); +static int cltrack_create (const char *id); +static int cltrack_remove (const char *id); +static int cltrack_check (const char *id); +static int cltrack_gracedone (const char *gracetime); + +/* global variables */ +static struct option longopts[] = +{ + {"help" ,0 ,NULL ,'h' }, + {"debug" ,0 ,NULL ,'d' }, + {"foreground" ,0 ,NULL ,'f' }, + {"storagedir" ,1 ,NULL ,'s' }, + {NULL ,0 ,0 ,0 }, +}; + +static struct cltrack_cmd commands[] = +{ + {"init" , false, cltrack_init }, + {"create" , true, cltrack_create }, + {"remove" , true, cltrack_remove }, + {"check" , true, cltrack_check }, + {"gracedone" , true, cltrack_gracedone }, + {NULL , false,NULL }, +}; + +static char *storagedir =CLD_DEFAULT_STORAGEDIR ; + +/* common buffer for holding id4 blobs */ +static unsigned char blob[NFS4_OPAQUE_LIMIT ]; + +static void +usage (char *progname) +{ +printf ("%s [ -hfd ] [ -s dir ] < cmd > < arg >\n" , progname); +printf ("Where < cmd > is one of the following and takes the following < arg >:\n" ); +printf (" init\n" ); +printf (" create <nfs_client_id4>\n" ); +printf (" remove <nfs_client_id4>\n" ); +printf (" check <nfs_client_id4>\n" ); +printf (" gracedone <epoch time>\n" ); +} + + +/** +* hex_to_bin - convert a hex digit to its real value +* @ch: ascii character represents hex digit +* +* hex_to_bin() converts one hex digit to its actual value or -1 in case of bad +* input. +* +* Note: borrowed from lib/hexdump.c in the Linux kernel sources. +*/ +static int +hex_to_bin (char ch) +{ +if ((ch >='0' ) && (ch <='9' )) +return ch -'0' ; + ch =tolower (ch); +if ((ch >='a' ) && (ch <='f' )) +return ch -'a' +10 ; +return -1 ; +} + +/** +* hex_str_to_bin - convert a hexidecimal string into a binary blob +* +* @src: string of hex digit pairs +* @dst: destination buffer to hold binary data +* @dstsize: size of the destination buffer +* +* Walk a string of hex digit pairs and convert them into binary data. Returns +* the resulting length of the binary data or a negative error code. If the +* data will not fit in the buffer, it returns -ENOBUFS (but will likely have +* clobbered the dst buffer in the process of determining that). If there are +* non-hexidecimal characters in the src, or an odd number of them then it +* returns -EINVAL. +*/ +static ssize_t +hex_str_to_bin (const char *src,unsigned char *dst,ssize_t dstsize) +{ +unsigned char *tmpdst = dst; + +while (*src) { +int hi, lo; + +/* make sure we don't overrun the dst buffer */ +if ((tmpdst - dst) >= dstsize) +return -ENOBUFS ; + + hi =hex_to_bin (*src++); + +/* did we get an odd number of characters? */ +if (!*src) +return -EINVAL ; + lo =hex_to_bin (*src++); + +/* one of the characters isn't a hex digit */ +if (hi <0 || lo <0 ) +return -EINVAL ; + +/* now place it in the dst buffer */ + *tmpdst++ = (hi <<4 ) | lo; + } + +return (ssize_t )(tmpdst - dst); +} + +/* +* This program will almost always be run with root privileges since the +* kernel will call out to run it. Drop all capabilities prior to doing +* anything important to limit the exposure to potential compromise. +* +* FIXME: should we setuid to a different user early on instead? +*/ +static int +cltrack_set_caps (void ) +{ +int ret =0 ; +#ifdef HAVE_SYS_CAPABILITY_H +unsigned long i; +cap_t caps; + +/* prune the bounding set to nothing */ +for (i =0 ;prctl (PR_CAPBSET_READ , i,0 ,0 ,0 ) >=0 ; ++i) { + ret =prctl (PR_CAPBSET_DROP , i,0 ,0 ,0 ); +if (ret) { +xlog (L_ERROR ,"Unable to prune capability %lu from " +"bounding set: %m" , i); +return -errno; + } + } + +/* get a blank capset */ + caps =cap_init (); +if (caps ==NULL ) { +xlog (L_ERROR ,"Unable to get blank capability set: %m" ); +return -errno; + } + +/* reset the process capabilities */ +if (cap_set_proc (caps) !=0 ) { +xlog (L_ERROR ,"Unable to set process capabilities: %m" ); + ret = -errno; + } +cap_free (caps); +#endif +return ret; +} + +static int +cltrack_init (const char __attribute__((unused)) *unused) +{ +int ret; + +/* +* see if the storagedir is writable by root w/o CAP_DAC_OVERRIDE. +* If it isn't then give the user a warning but proceed as if +* everything is OK. If the DB has already been created, then +* everything might still work. If it doesn't exist at all, then +* assume that the maindb init will be able to create it. Fail on +* anything else. +*/ +if (access (storagedir,W_OK ) ==-1 ) { +switch (errno) { +case EACCES : +xlog (L_WARNING ,"Storage directory %s is not writable. " +"Should be owned by root and writable " +"by owner!" , storagedir); +break ; +case ENOENT : +/* ignore and assume that we can create dir as root */ +break ; +default : +xlog (L_ERROR ,"Unexpected error when checking access " +"on %s: %m" , storagedir); +return -errno; + } + } + +/* set up storage db */ + ret =sqlite_maindb_init (storagedir); +if (ret) { +xlog (L_ERROR ,"Failed to init database: %d" , ret); +/* +* Convert any error here into -EACCES. It's not truly +* accurate in all cases, but it should cause the kernel to +* stop upcalling until the problem is resolved. +*/ + ret = -EACCES ; + } +return ret; +} + +static int +cltrack_create (const char *id) +{ +int ret; +ssize_t len; + +xlog (D_GENERAL ,"%s: create client record." , __func__); + + ret =sqlite_prepare_dbh (storagedir); +if (ret) +return ret; + + len =hex_str_to_bin (id, blob,sizeof (blob)); +if (len <0 ) +return (int )len; + + ret =sqlite_insert_client (blob, len); + +return ret ? -EREMOTEIO : ret; +} + +static int +cltrack_remove (const char *id) +{ +int ret; +ssize_t len; + +xlog (D_GENERAL ,"%s: remove client record." , __func__); + + ret =sqlite_prepare_dbh (storagedir); +if (ret) +return ret; + + len =hex_str_to_bin (id, blob,sizeof (blob)); +if (len <0 ) +return (int )len; + + ret =sqlite_remove_client (blob, len); + +return ret ? -EREMOTEIO : ret; +} + +static int +cltrack_check (const char *id) +{ +int ret; +ssize_t len; + +xlog (D_GENERAL ,"%s: check client record" , __func__); + + ret =sqlite_prepare_dbh (storagedir); +if (ret) +return ret; + + len =hex_str_to_bin (id, blob,sizeof (blob)); +if (len <0 ) +return (int )len; + + ret =sqlite_check_client (blob, len); + +return ret ? -EPERM : ret; +} + +static int +cltrack_gracedone (const char *timestr) +{ +int ret; +char *tail; +time_t gracetime; + + + ret =sqlite_prepare_dbh (storagedir); +if (ret) +return ret; + + errno =0 ; + gracetime =strtol (timestr, &tail,0 ); + +/* did the resulting value overflow? (Probably -ERANGE here) */ +if (errno) +return -errno; + +/* string wasn't fully converted */ +if (*tail) +return -EINVAL ; + +xlog (D_GENERAL ,"%s: grace done. gracetime=%ld" , __func__, gracetime); + + ret =sqlite_remove_unreclaimed (gracetime); + +return ret ? -EREMOTEIO : ret; +} + +static struct cltrack_cmd * +find_cmd (char *cmdname) +{ +struct cltrack_cmd *current = &commands[0 ]; + +while (current->name) { +if (!strcmp (cmdname, current->name)) +return current; + ++current; + } + +xlog (L_ERROR ,"%s: '%s' doesn't match any known command" , + __func__, cmdname); +return NULL ; +} + +int +main (int argc,char **argv) +{utils/nfsdcltrack/nfsdcltrack.c line 377
Quoted 10 lines
utils/nfsdcltrack/nfsdcltrack.c new file +10
-0+char arg; +int rc =0 ; +char *progname, *cmdarg =NULL ; +struct cltrack_cmd *cmd; + + progname =strdup (basename (argv[0 ])); +if (!progname) { +fprintf (stderr,"%s: unable to allocate memory.\n" , argv[0 ]); +return 1 ; + }Small nit: Do we really want to fail because we cannot get memory for the program name? Why not just use the string returned from
basename()?Quoted 49 lines
utils/nfsdcltrack/nfsdcltrack.c new file +49
-0+ +xlog_syslog (1 ); +xlog_stderr (0 ); + +/* process command-line options */ +while ((arg =getopt_long (argc, argv,"hdfs:" , longopts, +NULL )) !=EOF ) { +switch (arg) { +case 'd' : +xlog_config (D_ALL ,1 ); +case 'f' : +xlog_syslog (0 ); +xlog_stderr (1 ); +break ; +case 's' : + storagedir = optarg; +break ; +default : +usage (progname); +return 0 ; + } + } + +xlog_open (progname); + +/* we expect a command, at least */ +if (optind >= argc) { +xlog (L_ERROR ,"Missing command name\n" ); + rc = -EINVAL ; + goto out; + } + +/* drop all capabilities */ + rc =cltrack_set_caps (); +if (rc) + goto out; + + cmd =find_cmd (argv[optind]); +if (!cmd) { +/* +* In the event that we get a command that we don't understand +* then return a distinct error. The kernel can use this to +* determine a new kernel/old userspace situation and cope +* with it. +*/ + rc = -ENOSYS ; + goto out; + } +utils/nfsdcltrack/nfsdcltrack.c line 436
Quoted 10 lines
utils/nfsdcltrack/nfsdcltrack.c new file +10
-0+/* populate arg var if command needs it */ +if (cmd->needs_arg) { +if (optind +1 >= argc) { +xlog (L_ERROR ,"Command %s requires an argument\n" , + cmd->name); + rc = -EINVAL ; + goto out; + } + cmdarg = argv[optind +1 ]; + }Is
needs_argreally necessary? Once the function is found, just pass it the rest of argv and let the function decide if there should be an argument or not... but again.. just a nit...
Quoted 1 line
steved.
No, it's not strictly necessary. The alternative though is to make the command functions do argv processing, which seemed more ugly to me. I tend to prefer to keep argv processing in a single place since it can get sort of hairy to work through the bounds checks after getopt and such.
If you feel strongly about it, I can try to change it, but I don't think the result will be cleaner.
Quoted 6 lines
Quoted 6 lines
utils/nfsdcltrack/nfsdcltrack.c new file +5
-0+ rc = cmd->func (cmdarg); +out: +free (progname); +return rc; +}
Signature · 1 line
Jeff Layton <[email protected]>
Re: [PATCH v2 05/10] nfsdcltrack: add a new "one-shot" program for manipulating the client tracking db
Quoted 5 lines · Jeff Layton
Quoted 5 lines
Is
needs_argreally necessary? Once the function is found, just passQuoted 4 lines
it the rest of argv and let the function decide if there should be an argument or not... but again.. just a nit...
steved.
Quoted 9 lines
No, it's not strictly necessary. The alternative though is to make the command functions do argv processing, which seemed more ugly to me. I tend to prefer to keep argv processing in a single place since it can get sort of hairy to work through the bounds checks after getopt and such.
If you feel strongly about it, I can try to change it, but I don't think the result will be cleaner.
Like I said its a nit... Just a different way to look at it... no issues here keeping it as is...
steved.
PATCH v2 6/10 nfsdcltrack: add a legacy transition mechanism
In reply to Jeff LaytonIf 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
@@ -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
PATCH v2 7/10 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
@@ -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
PATCH v2 8/10 nfsdcltrack: remove the nfsdcld daemon
In reply to Jeff LaytonSince 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
@@ -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
PATCH v2 9/10 nfsdcltrack: update the README about server startup order
In reply to Jeff LaytonNow that nfsdcld is gone, remove the section about starting it up.
--- README | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-)
README +2 -21
@@ -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
PATCH v2 10/10 nfsdcltrack: flip the default in autoconf to "yes" for it
In reply to Jeff LaytonAllow nfsdcltrack to be built by default if all of the requirements for it are in place. Set the initial state of $enable_nfsdcltrack to "maybe", and fix the appropriate tests to just disable building the binary unless someone explicitly requests it.
--- configure.ac | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)
configure.ac +17 -7
@@ -187,9 +187,9 @@ fi AC_ARG_ENABLE(nfsdcltrack, [AC_HELP_STRING([--enable-nfsdcltrack], - [enable NFSv4 clientid tracking programs @<:@default=no@:>@])], + [enable NFSv4 clientid tracking programs @<:@default=yes@:>@])], enable_nfsdctrack=$enableval, - enable_nfsdcltrack="no") + enable_nfsdcltrack="maybe") dnl Check for TI-RPC library and headers AC_LIBTIRPC
@@ -269,12 +269,22 @@ if test "$enable_nfsv4" = yes; then dnl Check for sqlite3 AC_SQLITE3_VERS - if test "$enable_nfsdcltrack" = "yes"; then + if test "$enable_nfsdcltrack" != "no"; then AC_CHECK_HEADERS([libgen.h sys/inotify.h], , - AC_MSG_ERROR([Cannot find header needed for nfsdcltrack])) - - if test "$libsqlite3_cv_is_recent" != "yes" ; then + if test "$enable_nfsdcltrack" = "yes"; then + AC_MSG_ERROR([Cannot find header needed for nfsdcltrack]) + else + AC_MSG_WARN([Cannot find header needed for nfsdcltrack. Disabling it.]) + enable_nfsdcltrack="no" + fi + ) + fi + if test "$libsqlite3_cv_is_recent" != "yes" ; then + if test "$enable_nfsdcltrack" = "yes"; then AC_MSG_ERROR([nfsdcltrack requires sqlite3]) + elif test "$enable_nfsdcltrack" != "no"; then + AC_MSG_WARN([nfsdcltrack requires sqlite3. Disabling it.]) + enable_nfsdcltrack="no" fi fi
@@ -292,7 +302,7 @@ if test "$enable_nfsv41" = yes; then fi dnl enable nfsidmap when its support by libnfsidmap -AM_CONDITIONAL(CONFIG_NFSDCLTRACK, [test "$enable_nfsdcltrack" = "yes" ]) +AM_CONDITIONAL(CONFIG_NFSDCLTRACK, [test "$enable_nfsdcltrack" != "no" ]) AM_CONDITIONAL(CONFIG_NFSIDMAP, [test "$ac_cv_header_keyutils_h$ac_cv_lib_nfsidmap_nfs4_owner_to_uid" = "yesyes"])
Signature · 1 line
1.7.11.7
Re: [PATCH v2 10/10] nfsdcltrack: flip the default in autoconf to "yes" for it
Quoted 4 lines · Jeff Layton
Allow nfsdcltrack to be built by default if all of the requirements for it are in place. Set the initial state of $enable_nfsdcltrack to "maybe", and fix the appropriate tests to just disable building the binary unless someone explicitly requests it.
Hmm... I'm not sure I too keen on this "maybe" state...
So if no flags are given to ./configuration, and not
all the requirements to build nfsdcltrack exists, the configuration will succeed, but the command will not be build. Correct?
But if the --enable_nfsdcltrack flag is given and not all the requirements to build nfsdcltrack exist the configuration will fail.
I'm thinking we might want to make it a bit more binary. Either on or off. Like it is with the other conditionally built commands...
steved.
Quoted 59 lines
Signed-off-by Jeff Layton <[email protected]>--- configure.ac | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)configure.ac +17
-7@@ -187,9 +187,9 @@ fi AC_ARG_ENABLE(nfsdcltrack, [AC_HELP_STRING([--enable-nfsdcltrack], - [enable NFSv4 clientid tracking programs @<:@default=no@:>@])], + [enable NFSv4 clientid tracking programs @<:@default=yes@:>@])], enable_nfsdctrack=$enableval, - enable_nfsdcltrack="no") + enable_nfsdcltrack="maybe") dnl Check for TI-RPC library and headers AC_LIBTIRPC@@ -269,12 +269,22 @@ if test "$enable_nfsv4" = yes; then dnl Check for sqlite3 AC_SQLITE3_VERS - if test "$enable_nfsdcltrack" = "yes"; then + if test "$enable_nfsdcltrack" != "no"; then AC_CHECK_HEADERS([libgen.h sys/inotify.h], , - AC_MSG_ERROR([Cannot find header needed for nfsdcltrack])) - - if test "$libsqlite3_cv_is_recent" != "yes" ; then + if test "$enable_nfsdcltrack" = "yes"; then + AC_MSG_ERROR([Cannot find header needed for nfsdcltrack]) + else + AC_MSG_WARN([Cannot find header needed for nfsdcltrack. Disabling it.]) + enable_nfsdcltrack="no" + fi + ) + fi + if test "$libsqlite3_cv_is_recent" != "yes" ; then + if test "$enable_nfsdcltrack" = "yes"; then AC_MSG_ERROR([nfsdcltrack requires sqlite3]) + elif test "$enable_nfsdcltrack" != "no"; then + AC_MSG_WARN([nfsdcltrack requires sqlite3. Disabling it.]) + enable_nfsdcltrack="no" fi fi@@ -292,7 +302,7 @@ if test "$enable_nfsv41" = yes; then fi dnl enable nfsidmap when its support by libnfsidmap -AM_CONDITIONAL(CONFIG_NFSDCLTRACK, [test "$enable_nfsdcltrack" = "yes" ]) +AM_CONDITIONAL(CONFIG_NFSDCLTRACK, [test "$enable_nfsdcltrack" != "no" ]) AM_CONDITIONAL(CONFIG_NFSIDMAP, [test "$ac_cv_header_keyutils_h$ac_cv_lib_nfsidmap_nfs4_owner_to_uid" = "yesyes"])
Re: [PATCH v2 10/10] nfsdcltrack: flip the default in autoconf to "yes" for it
Quoted 9 lines · On Thu, 25 Oct 2012 08:57:17 -0400 Steve Dickson <[email protected]> wrote:
Quoted 4 lines · Jeff Layton
Allow nfsdcltrack to be built by default if all of the requirements for it are in place. Set the initial state of $enable_nfsdcltrack to "maybe", and fix the appropriate tests to just disable building the binary unless someone explicitly requests it.
Hmm... I'm not sure I too keen on this "maybe" state...
Would it help if we renamed it to
"yes_but_only_if_requirements_are_met" ? :)
Quoted 4 lines
So if no flags are given to ./configuration, and not
all the requirements to build nfsdcltrack exists, the configuration will succeed, but the command will not be build. Correct?
Correct.
Quoted 4 lines
But if the --enable_nfsdcltrack flag is given and not all the requirements to build nfsdcltrack exist the configuration will fail.
Correct.
Quoted 4 lines
I'm thinking we might want to make it a bit more binary. Either on or off. Like it is with the other conditionally built commands...
So you want to fail the configure stage if all of the requirements for nfsdcltrack aren't present? That doesn't sound good to me. Note that we do have "tristate" handling already for stuff like the --disable-uuid option...
Quoted 61 lines
steved.
Quoted 59 lines
Signed-off-by Jeff Layton <[email protected]>--- configure.ac | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)configure.ac +17
-7@@ -187,9 +187,9 @@ fi AC_ARG_ENABLE(nfsdcltrack, [AC_HELP_STRING([--enable-nfsdcltrack], - [enable NFSv4 clientid tracking programs @<:@default=no@:>@])], + [enable NFSv4 clientid tracking programs @<:@default=yes@:>@])], enable_nfsdctrack=$enableval, - enable_nfsdcltrack="no") + enable_nfsdcltrack="maybe") dnl Check for TI-RPC library and headers AC_LIBTIRPC@@ -269,12 +269,22 @@ if test "$enable_nfsv4" = yes; then dnl Check for sqlite3 AC_SQLITE3_VERS - if test "$enable_nfsdcltrack" = "yes"; then + if test "$enable_nfsdcltrack" != "no"; then AC_CHECK_HEADERS([libgen.h sys/inotify.h], , - AC_MSG_ERROR([Cannot find header needed for nfsdcltrack])) - - if test "$libsqlite3_cv_is_recent" != "yes" ; then + if test "$enable_nfsdcltrack" = "yes"; then + AC_MSG_ERROR([Cannot find header needed for nfsdcltrack]) + else + AC_MSG_WARN([Cannot find header needed for nfsdcltrack. Disabling it.]) + enable_nfsdcltrack="no" + fi + ) + fi + if test "$libsqlite3_cv_is_recent" != "yes" ; then + if test "$enable_nfsdcltrack" = "yes"; then AC_MSG_ERROR([nfsdcltrack requires sqlite3]) + elif test "$enable_nfsdcltrack" != "no"; then + AC_MSG_WARN([nfsdcltrack requires sqlite3. Disabling it.]) + enable_nfsdcltrack="no" fi fi@@ -292,7 +302,7 @@ if test "$enable_nfsv41" = yes; then fi dnl enable nfsidmap when its support by libnfsidmap -AM_CONDITIONAL(CONFIG_NFSDCLTRACK, [test "$enable_nfsdcltrack" = "yes" ]) +AM_CONDITIONAL(CONFIG_NFSDCLTRACK, [test "$enable_nfsdcltrack" != "no" ]) AM_CONDITIONAL(CONFIG_NFSIDMAP, [test "$ac_cv_header_keyutils_h$ac_cv_lib_nfsidmap_nfs4_owner_to_uid" = "yesyes"])
Signature · 1 line
Jeff Layton <[email protected]>
Re: [PATCH v2 10/10] nfsdcltrack: flip the default in autoconf to "yes" for it
Quoted 10 lines · Jeff Layton
Quoted 7 lines · On Thu, 25 Oct 2012 08:57:17 -0400 Steve Dickson <[email protected]> wrote:
Quoted 4 lines · Jeff Layton
Allow nfsdcltrack to be built by default if all of the requirements for it are in place. Set the initial state of $enable_nfsdcltrack to "maybe", and fix the appropriate tests to just disable building the binary unless someone explicitly requests it.
Quoted 5 lines
Quoted 2 lines
Hmm... I'm not sure I too keen on this "maybe" state...
Would it help if we renamed it to
"yes_but_only_if_requirements_are_met" ? :)
:-)
Quoted 20 lines
Quoted 5 lines
So if no flags are given to ./configuration, and not
all the requirements to build nfsdcltrack exists, the configuration will succeed, but the command will not be build. Correct?Correct.
Quoted 4 lines
But if the --enable_nfsdcltrack flag is given and not all the requirements to build nfsdcltrack exist the configuration will fail.
Correct.
Quoted 4 lines
I'm thinking we might want to make it a bit more binary. Either on or off. Like it is with the other conditionally built commands...
Quoted 4 lines
So you want to fail the configure stage if all of the requirements for nfsdcltrack aren't present? That doesn't sound good to me. Note that we do have "tristate" handling already for stuff like the --disable-uuid option...
I'm thinking there it might cause confusion to silently not build a binary, when the expectation is this should be there. I'm thinking a failure of the config script would remove that confusion... And as long as there a way to mask that failure out (aka --enable_nfsdcltrack=no or --disable_nfsdcltrack) it will make it more explicit to what is or is not happening...
steved.
Quoted 64 lines
Quoted 62 lines
steved.
Quoted 59 lines
Signed-off-by Jeff Layton <[email protected]>--- configure.ac | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)configure.ac +17
-7@@ -187,9 +187,9 @@ fi AC_ARG_ENABLE(nfsdcltrack, [AC_HELP_STRING([--enable-nfsdcltrack], - [enable NFSv4 clientid tracking programs @<:@default=no@:>@])], + [enable NFSv4 clientid tracking programs @<:@default=yes@:>@])], enable_nfsdctrack=$enableval, - enable_nfsdcltrack="no") + enable_nfsdcltrack="maybe") dnl Check for TI-RPC library and headers AC_LIBTIRPC@@ -269,12 +269,22 @@ if test "$enable_nfsv4" = yes; then dnl Check for sqlite3 AC_SQLITE3_VERS - if test "$enable_nfsdcltrack" = "yes"; then + if test "$enable_nfsdcltrack" != "no"; then AC_CHECK_HEADERS([libgen.h sys/inotify.h], , - AC_MSG_ERROR([Cannot find header needed for nfsdcltrack])) - - if test "$libsqlite3_cv_is_recent" != "yes" ; then + if test "$enable_nfsdcltrack" = "yes"; then + AC_MSG_ERROR([Cannot find header needed for nfsdcltrack]) + else + AC_MSG_WARN([Cannot find header needed for nfsdcltrack. Disabling it.]) + enable_nfsdcltrack="no" + fi + ) + fi + if test "$libsqlite3_cv_is_recent" != "yes" ; then + if test "$enable_nfsdcltrack" = "yes"; then AC_MSG_ERROR([nfsdcltrack requires sqlite3]) + elif test "$enable_nfsdcltrack" != "no"; then + AC_MSG_WARN([nfsdcltrack requires sqlite3. Disabling it.]) + enable_nfsdcltrack="no" fi fi@@ -292,7 +302,7 @@ if test "$enable_nfsv41" = yes; then fi dnl enable nfsidmap when its support by libnfsidmap -AM_CONDITIONAL(CONFIG_NFSDCLTRACK, [test "$enable_nfsdcltrack" = "yes" ]) +AM_CONDITIONAL(CONFIG_NFSDCLTRACK, [test "$enable_nfsdcltrack" != "no" ]) AM_CONDITIONAL(CONFIG_NFSIDMAP, [test "$ac_cv_header_keyutils_h$ac_cv_lib_nfsidmap_nfs4_owner_to_uid" = "yesyes"])
Re: [PATCH v2 10/10] nfsdcltrack: flip the default in autoconf to "yes" for it
Quoted 44 lines · On Thu, 25 Oct 2012 10:28:24 -0400 Steve Dickson <[email protected]> wrote:
Quoted 10 lines · Jeff Layton
Quoted 7 lines · On Thu, 25 Oct 2012 08:57:17 -0400 Steve Dickson <[email protected]> wrote:
Quoted 4 lines · Jeff Layton
Allow nfsdcltrack to be built by default if all of the requirements for it are in place. Set the initial state of $enable_nfsdcltrack to "maybe", and fix the appropriate tests to just disable building the binary unless someone explicitly requests it.
Quoted 5 lines
Quoted 2 lines
Hmm... I'm not sure I too keen on this "maybe" state...
Would it help if we renamed it to
"yes_but_only_if_requirements_are_met" ? :):-)
Quoted 20 lines
Quoted 5 lines
So if no flags are given to ./configuration, and not
all the requirements to build nfsdcltrack exists, the configuration will succeed, but the command will not be build. Correct?Correct.
Quoted 4 lines
But if the --enable_nfsdcltrack flag is given and not all the requirements to build nfsdcltrack exist the configuration will fail.
Correct.
Quoted 4 lines
I'm thinking we might want to make it a bit more binary. Either on or off. Like it is with the other conditionally built commands...
Quoted 4 lines
So you want to fail the configure stage if all of the requirements for nfsdcltrack aren't present? That doesn't sound good to me. Note that we do have "tristate" handling already for stuff like the --disable-uuid option...
Quoted 8 lines
I'm thinking there it might cause confusion to silently not build a binary, when the expectation is this should be there. I'm thinking a failure of the config script would remove that confusion... And as long as there a way to mask that failure out (aka --enable_nfsdcltrack=no or --disable_nfsdcltrack) it will make it more explicit to what is or is not happening...
It's not silent. It does throw a warning in this case, but that is likely to get lost in the noise. It's your call -- if you want to fail the build by default if the requirements aren't present, then I'm ok with that.
Signature · 1 line
Jeff Layton <[email protected]>