nfsdcld: add a daemon to track NFSv4 client names on stable storage
Subsystems (2)
v5 cover nfsdcld: add a daemon to track NFSv4 client names on stable storage
This patchset is the userspace portion of the knfsd client name tracking overhaul. See this patch series for an explanation:
nfsd: overhaul the client name tracking code
This version scales back some of the changes in the last set. Since then, it's become clear that I'm not entirely certain what changes we'll need in order to handle this in a clustered configuration. Instead of trying to anticipate those changes, I've decided just to focus on the single-server case and leave any other changes for later once it becomes more clear what (if anything) is needed.
The main changes from the last set are:
- the "remove" upcall has been readded
- the "init" upcall has been removed
- the "check" and "update" upcalls no longer return a client index to the kernel
- the pipe open and reopen code has been overhauled and consolidated. Instead of looping indefinitely when trying to reopen the file, it will abort the daemon if the open fails with anything besides ENOENT. If the pipe isn't present when the daemon starts, it now uses the inotify event callback to handle the opening.
Jeff Layton (9):
nfsdcld: add client tracking daemon stub
nfsdcld: add autoconf goop for sqlite
nfsdcld: add routines for a sqlite backend database
nfsdcld: add remove functionality
nfsdcld: add check/update functionality
nfsdcld: add function to remove unreclaimed client records
nfsdcld: make it watch for inotify events in the containing directory
nfsdcld: add a manpage for nfsdcld
nfsdcld: update the README
README | 25 ++- aclocal/libsqlite3.m4 | 33 +++ configure.ac | 21 ++ utils/Makefile.am | 4 + utils/nfsdcld/Makefile.am | 14 ++ utils/nfsdcld/nfsdcld.c | 528 +++++++++++++++++++++++++++++++++++++++++++++ utils/nfsdcld/nfsdcld.man | 180 +++++++++++++++ utils/nfsdcld/nfsdcld.pod | 67 ++++++ utils/nfsdcld/sqlite.c | 390 +++++++++++++++++++++++++++++++++ utils/nfsdcld/sqlite.h | 29 +++ 10 files changed, 1289 insertions(+), 2 deletions(-) create mode 100644 aclocal/libsqlite3.m4 create mode 100644 utils/nfsdcld/Makefile.am create mode 100644 utils/nfsdcld/nfsdcld.c create mode 100644 utils/nfsdcld/nfsdcld.man create mode 100644 utils/nfsdcld/nfsdcld.pod create mode 100644 utils/nfsdcld/sqlite.c create mode 100644 utils/nfsdcld/sqlite.h
Signature · 1 line
1.7.7.6
PATCH v5 1/9 nfsdcld: add client tracking daemon stub
This program opens and "listens" on the new nfsd/cld rpc_pipefs pipe. The code here doesn't actually do anything on stable storage yet. That will be added in a later patch.
The patch also adds a autoconf enable switch for the new daemon that defaults to "no", and a test for the upcall description header file.
--- configure.ac | 14 +++ utils/Makefile.am | 4 + utils/nfsdcld/Makefile.am | 14 +++ utils/nfsdcld/nfsdcld.c | 275 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 307 insertions(+), 0 deletions(-) create mode 100644 utils/nfsdcld/Makefile.am create mode 100644 utils/nfsdcld/nfsdcld.c
configure.ac +14 -0
@@ -185,6 +185,12 @@ 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") + dnl Check for TI-RPC library and headers AC_LIBTIRPC
@@ -260,6 +266,13 @@ if test "$enable_nfsv4" = yes; then dnl check for the keyutils libraries and headers AC_KEYUTILS + if test "$enable_nfsdcld" = "yes"; then + AC_CHECK_HEADERS([linux/nfsd/cld.h], , + AC_MSG_ERROR([Cannot find header needed for nfsdcld])) + fi + + AM_CONDITIONAL(CONFIG_NFSDCLD, [test "$enable_nfsdcld" = "yes" ]) + dnl librpcsecgss already has a dependency on libgssapi, dnl but we need to make sure we get the right version if test "$enable_gss" = yes; then
@@ -460,6 +473,7 @@ AC_CONFIG_FILES([ tools/nfs-iostat/Makefile utils/Makefile utils/blkmapd/Makefile + utils/nfsdcld/Makefile utils/exportfs/Makefile utils/gssd/Makefile utils/idmapd/Makefile
utils/Makefile.am +4 -0
@@ -21,6 +21,10 @@ if CONFIG_MOUNT OPTDIRS += mount endif +if CONFIG_NFSDCLD +OPTDIRS += nfsdcld +endif + SUBDIRS = \ exportfs \ mountd \
utils/nfsdcld/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 + +nfsdcld_LDADD = ../../support/nfs/libnfs.a $(LIBEVENT) + +MAINTAINERCLEANFILES = Makefile.in +
utils/nfsdcld/nfsdcld.c new file +275 -0
275 lines not on this page · raw message
Signature · 1 line
1.7.7.6
PATCH v5 2/9 nfsdcld: add autoconf goop for sqlite
In reply to Jeff LaytonMostly cribbed from Chuck Lever's new-statd rewrite a few years ago...
This adds an autoconf test for the sqlite3 library and includes. If they're not working properly and nfsdcld was enabled, then configure will error out.
--- aclocal/libsqlite3.m4 | 33 +++++++++++++++++++++++++++++++++ configure.ac | 7 +++++++ 2 files changed, 40 insertions(+), 0 deletions(-) create mode 100644 aclocal/libsqlite3.m4
aclocal/libsqlite3.m4 new file +33 -0
@@ -0,0 +1,33 @@ +dnl Checks for matching sqlite3 header and library, and +dnl sufficient sqlite3 version. +dnl +AC_DEFUN([AC_SQLITE3_VERS], [ + AC_CHECK_HEADERS([sqlite3.h], ,) + + dnl look for the library; do not add to LIBS if found + AC_CHECK_LIB([sqlite3], [sqlite3_libversion_number], [LIBSQLITE=-lsqlite3], ,) + AC_SUBST(LIBSQLITE) + + AC_MSG_CHECKING(for suitable sqlite3 version) + + AC_CACHE_VAL([libsqlite3_cv_is_recent], + [ + saved_LIBS="$LIBS" + LIBS=-lsqlite3 + AC_TRY_RUN([ + #include <stdio.h> + #include <sqlite3.h> + int main() + { + int vers = sqlite3_libversion_number(); + + return vers != SQLITE_VERSION_NUMBER || + vers < 3003000; + } + ], [libsqlite3_cv_is_recent=yes], [libsqlite3_cv_is_recent=no], + [libsqlite3_cv_is_recent=unknown]) + LIBS="$saved_LIBS"]) + + AC_MSG_RESULT($libsqlite3_cv_is_recent) + AM_CONDITIONAL(CONFIG_SQLITE3, [test "$libsqlite3_cv_is_recent" = "yes"]) +])dnl
configure.ac +7 -0
@@ -266,9 +266,16 @@ if test "$enable_nfsv4" = yes; then dnl check for the keyutils libraries and headers AC_KEYUTILS + dnl Check for sqlite3 + AC_SQLITE3_VERS + if test "$enable_nfsdcld" = "yes"; then AC_CHECK_HEADERS([linux/nfsd/cld.h], , AC_MSG_ERROR([Cannot find header needed for nfsdcld])) + + if test "$libsqlite3_cv_is_recent" != "yes" ; then + AC_MSG_ERROR([nfsdcld requires sqlite3]) + fi fi AM_CONDITIONAL(CONFIG_NFSDCLD, [test "$enable_nfsdcld" = "yes" ])
Signature · 1 line
1.7.7.6
PATCH v5 3/9 nfsdcld: add routines for a sqlite backend database
In reply to Jeff LaytonRather than roll our own "storage engine", use sqlite instead. It fits the bill nicely as it does:
- durable on-disk storage
- the ability to constrain record uniqueness
- a facility for collating and searching the host records
...it does add a build dependency to nfs-utils, but almost all modern distros provide those packages.
The current incarnation of this code dynamically links against a provided sqlite library, but we could also consider including their single-file "amalgamation" to reduce dependencies (though with all the caveats that that entails).
--- utils/nfsdcld/Makefile.am | 4 +- utils/nfsdcld/nfsdcld.c | 24 +++- utils/nfsdcld/sqlite.c | 253 +++++++++++++++++++++++++++++++++++++++++++++ utils/nfsdcld/sqlite.h | 26 +++++ 4 files changed, 299 insertions(+), 8 deletions(-) create mode 100644 utils/nfsdcld/sqlite.c create mode 100644 utils/nfsdcld/sqlite.h
utils/nfsdcld/Makefile.am +2 -2
@@ -6,9 +6,9 @@ AM_CFLAGS += -D_LARGEFILE64_SOURCE sbin_PROGRAMS = nfsdcld -nfsdcld_SOURCES = nfsdcld.c +nfsdcld_SOURCES = nfsdcld.c sqlite.c -nfsdcld_LDADD = ../../support/nfs/libnfs.a $(LIBEVENT) +nfsdcld_LDADD = ../../support/nfs/libnfs.a $(LIBEVENT) $(LIBSQLITE) MAINTAINERCLEANFILES = Makefile.in
utils/nfsdcld/nfsdcld.c +18 -6
@@ -36,6 +36,7 @@#include "xlog.h" #include "nfslib.h" +#include "sqlite.h" #ifndef PIPEFS_DIR #define PIPEFS_DIR NFS_STATEDIR "/rpc_pipefs"
@@ -61,6 +62,7 @@ static struct option longopts[] = { "foreground", 0, NULL, 'F' }, { "debug", 0, NULL, 'd' }, { "pipe", 1, NULL, 'p' }, + { "storagedir", 1, NULL, 's' }, { NULL, 0, 0, 0 }, };
@@ -71,7 +73,7 @@ static void usage(char *progname) {printf ("Usage:\n" ); -printf ("%s [ -hFd ] [ -p pipe ]\n" , progname); +printf ("%s [ -hFd ] [ -p pipe ] [ -s dir ]\n" , progname); } static int
@@ -145,15 +147,16 @@ cld_create(struct cld_client *clnt)ssize_t bsize, wsize;struct cld_msg *cmsg = &clnt->cl_msg; -xlog (D_GENERAL ,"%s: create client record" , __func__); +xlog (D_GENERAL ,"%s: create client record." , __func__); -/* FIXME: create client record on storage here */ + ret =sqlite_insert_client (cmsg->cm_u.cm_name.cn_id, + cmsg->cm_u.cm_name.cn_len); -/* set up reply */ - cmsg->cm_status =0 ; + cmsg->cm_status = ret ? -EREMOTEIO : ret; bsize =sizeof (*cmsg); +xlog (D_GENERAL ,"Doing downcall with status %d" , cmsg->cm_status); wsize =atomicio ((void *)write, clnt->cl_fd, cmsg, bsize);if (wsize != bsize) { xlog(L_ERROR, "%s: problem writing to cld pipe (%ld): %m",
@@ -211,6 +214,7 @@ main(int argc, char **argv)int rc =0 ;bool foreground = false;char *progname; +char *storagedir =NULL ;struct cld_client clnt;memset (&clnt,0 ,sizeof (clnt));
@@ -226,7 +230,7 @@ main(int argc, char **argv)xlog_stderr (1 );/* process command-line options */ -while ((arg =getopt_long (argc, argv,"hdFp:" , longopts, +while ((arg =getopt_long (argc, argv,"hdFp:s:" , longopts,NULL )) !=EOF ) {switch (arg) {case 'd' :
@@ -238,6 +242,9 @@ main(int argc, char **argv)case 'p' : pipepath = optarg;break ; +case 's' : + storagedir = optarg; +break ;default :usage (progname);return 0 ;
@@ -257,6 +264,11 @@ main(int argc, char **argv) }/* set up storage db */ + rc =sqlite_maindb_init (storagedir); +if (rc) { +xlog (L_ERROR ,"Failed to open main database: %d" , rc); + goto out; + }/* set up event handler */ rc =cld_pipe_init (&clnt);
utils/nfsdcld/sqlite.c new file +253 -0
253 lines not on this page · raw message
utils/nfsdcld/sqlite.h new file +26 -0
@@ -0,0 +1,26 @@ +/* +* 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); + +#endif /* _SQLITE_H */
Signature · 1 line
1.7.7.6
PATCH v5 4/9 nfsdcld: add remove functionality
In reply to Jeff LaytonAllow the kernel to ask for removal of a client record.
--- utils/nfsdcld/nfsdcld.c | 34 ++++++++++++++++++++++++++++++++++ utils/nfsdcld/sqlite.c | 36 ++++++++++++++++++++++++++++++++++++ utils/nfsdcld/sqlite.h | 1 + 3 files changed, 71 insertions(+), 0 deletions(-)
utils/nfsdcld/nfsdcld.c +34 -0
@@ -171,6 +171,37 @@ cld_create(struct cld_client *clnt) }static void +cld_remove (struct cld_client *clnt) +{ +int ret; +ssize_t bsize, wsize; +struct cld_msg *cmsg = &clnt->cl_msg; + +xlog (D_GENERAL ,"%s: remove client record." , __func__); + + ret =sqlite_remove_client (cmsg->cm_u.cm_name.cn_id, + cmsg->cm_u.cm_name.cn_len); + + cmsg->cm_status = ret ? -EREMOTEIO : ret; + + bsize =sizeof (*cmsg); + +xlog (D_GENERAL ,"%s: downcall with status %d" , __func__, + cmsg->cm_status); + wsize =atomicio ((void *)write, clnt->cl_fd, cmsg, bsize); +if (wsize != bsize) { +xlog (L_ERROR ,"%s: problem writing to cld pipe (%ld): %m" , + __func__, wsize); + ret =cld_pipe_open (clnt); +if (ret) { +xlog (L_FATAL ,"%s: unable to reopen pipe: %d" , + __func__, ret); +exit (ret); + } + } +} + +static void cldcb (int UNUSED (fd ),short which,void *data) {ssize_t len;
@@ -198,6 +229,9 @@ cldcb(int UNUSED(fd), short which, void *data)case Cld_Create:cld_create (clnt);break ; +case Cld_Remove: +cld_remove (clnt); +break ;default :xlog (L_WARNING ,"%s: command %u is not yet implemented" , __func__, cmsg->cm_cmd);
utils/nfsdcld/sqlite.c +36 -0
@@ -251,3 +251,39 @@ out_err:sqlite3_finalize (stmt);return ret; } + +/* Remove a client record */ +int +sqlite_remove_client (const unsigned char *clname,const size_t namelen) +{ +int ret; +sqlite3_stmt *stmt =NULL ; + + ret =sqlite3_prepare_v2 (dbh,"DELETE FROM clients WHERE id==?" ,-1 , + &stmt,NULL ); +if (ret !=SQLITE_OK ) { +xlog (L_ERROR ,"%s: statement prepare failed: %s" , + __func__,sqlite3_errmsg (dbh)); + goto out_err; + } + + ret =sqlite3_bind_blob (stmt,1 , (const void *)clname, namelen, +SQLITE_STATIC ); +if (ret !=SQLITE_OK ) { +xlog (L_ERROR ,"%s: bind blob failed: %s" , __func__, +sqlite3_errmsg (dbh)); + goto out_err; + } + + ret =sqlite3_step (stmt); +if (ret ==SQLITE_DONE ) + ret =SQLITE_OK ; +else +xlog (L_ERROR ,"%s: unexpected return code from delete: %d" , + __func__, ret); + +out_err: +xlog (D_GENERAL ,"%s: returning %d" , __func__, ret); +sqlite3_finalize (stmt); +return ret; +}
utils/nfsdcld/sqlite.h +1 -0
@@ -22,5 +22,6 @@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);#endif /* _SQLITE_H */
Signature · 1 line
1.7.7.6
PATCH v5 5/9 nfsdcld: add check/update functionality
In reply to Jeff LaytonAdd functions to check whether a client is allowed to reclaim, and update its timestamp in the DB if so. If either the query or update fails, then the host is not allowed to reclaim state.
--- utils/nfsdcld/nfsdcld.c | 35 ++++++++++++++++++++++ utils/nfsdcld/sqlite.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++ utils/nfsdcld/sqlite.h | 1 + 3 files changed, 109 insertions(+), 0 deletions(-)
utils/nfsdcld/nfsdcld.c +35 -0
@@ -202,6 +202,38 @@ cld_remove(struct cld_client *clnt) }static void +cld_check (struct cld_client *clnt) +{ +int ret; +ssize_t bsize, wsize; +struct cld_msg *cmsg = &clnt->cl_msg; + +xlog (D_GENERAL ,"%s: check client record" , __func__); + + ret =sqlite_check_client (cmsg->cm_u.cm_name.cn_id, + cmsg->cm_u.cm_name.cn_len); + +/* set up reply */ + cmsg->cm_status = ret ? -EACCES : ret; + + bsize =sizeof (*cmsg); + +xlog (D_GENERAL ,"%s: downcall with status %d" , __func__, + cmsg->cm_status); + wsize =atomicio ((void *)write, clnt->cl_fd, cmsg, bsize); +if (wsize != bsize) { +xlog (L_ERROR ,"%s: problem writing to cld pipe (%ld): %m" , + __func__, wsize); + ret =cld_pipe_open (clnt); +if (ret) { +xlog (L_FATAL ,"%s: unable to reopen pipe: %d" , + __func__, ret); +exit (ret); + } + } +} + +static void cldcb (int UNUSED (fd ),short which,void *data) {ssize_t len;
@@ -232,6 +264,9 @@ cldcb(int UNUSED(fd), short which, void *data)case Cld_Remove:cld_remove (clnt);break ; +case Cld_Check: +cld_check (clnt); +break ;default :xlog (L_WARNING ,"%s: command %u is not yet implemented" , __func__, cmsg->cm_cmd);
utils/nfsdcld/sqlite.c +73 -0
76 lines not on this page · raw message
utils/nfsdcld/sqlite.h +1 -0
@@ -23,5 +23,6 @@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);#endif /* _SQLITE_H */
Signature · 1 line
1.7.7.6
PATCH v5 6/9 nfsdcld: add function to remove unreclaimed client records
In reply to Jeff LaytonThis should remove any client record that has a timestamp prior to the given time.
Eventually, this call will need to be made cluster aware when this is run in a clustered configuration. For now, this is only suitable for single-host configurations.
--- utils/nfsdcld/nfsdcld.c | 34 ++++++++++++++++++++++++++++++++++ utils/nfsdcld/sqlite.c | 28 ++++++++++++++++++++++++++++ utils/nfsdcld/sqlite.h | 1 + 3 files changed, 63 insertions(+), 0 deletions(-)
utils/nfsdcld/nfsdcld.c +34 -0
@@ -234,6 +234,37 @@ cld_check(struct cld_client *clnt) }static void +cld_gracedone (struct cld_client *clnt) +{ +int ret; +ssize_t bsize, wsize; +struct cld_msg *cmsg = &clnt->cl_msg; + +xlog (D_GENERAL ,"%s: grace done. cm_gracetime=%ld" , __func__, + cmsg->cm_u.cm_gracetime); + + ret =sqlite_remove_unreclaimed (cmsg->cm_u.cm_gracetime); + +/* set up reply: downcall with 0 status */ + cmsg->cm_status = ret ? -EREMOTEIO : ret; + + bsize =sizeof (*cmsg); + +xlog (D_GENERAL ,"Doing downcall with status %d" , cmsg->cm_status); + wsize =atomicio ((void *)write, clnt->cl_fd, cmsg, bsize); +if (wsize != bsize) { +xlog (L_ERROR ,"%s: problem writing to cld pipe (%ld): %m" , + __func__, wsize); + ret =cld_pipe_open (clnt); +if (ret) { +xlog (L_FATAL ,"%s: unable to reopen pipe: %d" , + __func__, ret); +exit (ret); + } + } +} + +static void cldcb (int UNUSED (fd ),short which,void *data) {ssize_t len;
@@ -267,6 +298,9 @@ cldcb(int UNUSED(fd), short which, void *data)case Cld_Check:cld_check (clnt);break ; +case Cld_GraceDone: +cld_gracedone (clnt); +break ;default :xlog (L_WARNING ,"%s: command %u is not yet implemented" , __func__, cmsg->cm_cmd);
utils/nfsdcld/sqlite.c +28 -0
@@ -38,6 +38,7 @@#include "config.h" #endif /* HAVE_CONFIG_H */ +#include <dirent.h> #include <errno.h> #include <event.h> #include <stdbool.h>
@@ -360,3 +361,30 @@ out_err:sqlite3_finalize (stmt);return ret; } + +/* +* remove any client records that were not reclaimed since grace_start. +*/ +int +sqlite_remove_unreclaimed (time_t grace_start) +{ +int ret; +char *err =NULL ; + + ret =snprintf (buf,sizeof (buf),"DELETE FROM clients WHERE time < %ld" , + grace_start); +if (ret <0 ) { +return ret; + }else if ((size_t )ret >=sizeof (buf)) { + ret = -EINVAL ; +return ret; + } + + ret =sqlite3_exec (dbh, buf,NULL ,NULL , &err); +if (ret !=SQLITE_OK ) +xlog (L_ERROR ,"%s: delete failed: %s" , __func__, err); + +xlog (D_GENERAL ,"%s: returning %d" , __func__, ret); +sqlite3_free (err); +return ret; +}
utils/nfsdcld/sqlite.h +1 -0
@@ -24,5 +24,6 @@ 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.7.6
PATCH v5 7/9 nfsdcld: make it watch for inotify events in the containing directory
In reply to Jeff LaytonBefore opening the pipe, set an inotify watch on the containing dir and then try to open the pipe. If it succeeds, then set up pipe and inotify events and return success. If it fails with -ENOENT, then just set up the inotify event and return success. If it fails with any other error then return the error and the caller can then abort the program.
--- configure.ac | 2 +- utils/nfsdcld/nfsdcld.c | 146 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 143 insertions(+), 5 deletions(-)
configure.ac +1 -1
@@ -270,7 +270,7 @@ if test "$enable_nfsv4" = yes; then AC_SQLITE3_VERS if test "$enable_nfsdcld" = "yes"; then - AC_CHECK_HEADERS([linux/nfsd/cld.h], , + AC_CHECK_HEADERS([linux/nfsd/cld.h libgen.h sys/inotify.h], , AC_MSG_ERROR([Cannot find header needed for nfsdcld])) if test "$libsqlite3_cv_is_recent" != "yes" ; then
utils/nfsdcld/nfsdcld.c +142 -4
184 lines not on this page · raw message
Signature · 1 line
1.7.7.6
PATCH v5 8/9 nfsdcld: add a manpage for nfsdcld
In reply to Jeff Layton...for now I'm including the POD source for the manpage. We can drop from the repo if desired though.
--- utils/nfsdcld/Makefile.am | 4 +- utils/nfsdcld/nfsdcld.man | 180 +++++++++++++++++++++++++++++++++++++++++++++ utils/nfsdcld/nfsdcld.pod | 67 +++++++++++++++++ 3 files changed, 249 insertions(+), 2 deletions(-) create mode 100644 utils/nfsdcld/nfsdcld.man create mode 100644 utils/nfsdcld/nfsdcld.pod
utils/nfsdcld/Makefile.am +2 -2
@@ -1,7 +1,7 @@ ## Process this file with automake to produce Makefile.in -#man8_MANS = nfsdcld.man -#EXTRA_DIST = $(man8_MANS) +man8_MANS = nfsdcld.man +EXTRA_DIST = $(man8_MANS) AM_CFLAGS += -D_LARGEFILE64_SOURCE sbin_PROGRAMS = nfsdcld
utils/nfsdcld/nfsdcld.man new file +180 -0
180 lines not on this page · raw message
utils/nfsdcld/nfsdcld.pod new file +67 -0
67 lines not on this page · raw message
Signature · 1 line
1.7.7.6
PATCH v5 9/9 nfsdcld: update the README
In reply to Jeff LaytonAdd info to the README about when this daemon should be started, and its build and runtime requirements.
--- README | 25 +++++++++++++++++++++++-- 1 files changed, 23 insertions(+), 2 deletions(-)
README +23 -2
@@ -15,6 +15,8 @@ libraries. They are available from http://www.citi.umich.edu/projects/nfsv4/linux/libnfsidmap/ Otherwise use --disable-nfsv4 +To use the nfsdcld tracking daemon, nfsv4 support must be enabled, +and the libsqlite3 development libraries must be installed. 1. COMPILING
@@ -106,12 +108,31 @@ scripts can be written to work correctly. the lock. rpc.statd is only needed for NFSv2 and NFSv3 support. - E/ rpc.nfsd + 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 Starting nfsd will automatically start lockd. The nfs server will now be fully active and respond to any requests from clients. - F/ sm-notify + G/ 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.7.6
Re: [PATCH v5 1/9] nfsdcld: add client tracking daemon stub
In reply to Jeff LaytonQuoted 35 lines · Jeff Layton
This program opens and "listens" on the new nfsd/cld
rpc_pipefspipe. The code here doesn't actually do anything on stable storage yet. That will be added in a later patch.The patch also adds a autoconf enable switch for the new daemon that defaults to "no", and a test for the upcall description header file.
Signed-off-by Jeff Layton <[email protected]>--- configure.ac | 14 +++ utils/Makefile.am | 4 + utils/nfsdcld/Makefile.am | 14 +++ utils/nfsdcld/nfsdcld.c | 275 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 307 insertions(+), 0 deletions(-) create mode 100644 utils/nfsdcld/Makefile.am create mode 100644 utils/nfsdcld/nfsdcld.cconfigure.ac +6
-0@@ -185,6 +185,12 @@ 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") + dnl Check for TI-RPC library and headers AC_LIBTIRPC
configure.ac if test "$enable_nfsv4" = yes; then · line 272
Quoted 7 lines
configure.ac +4
-0@@ -260,6 +266,13 @@ if test "$enable_nfsv4" = yes; then dnl check for the keyutils libraries and headers AC_KEYUTILS + if test "$enable_nfsdcld" = "yes"; then + AC_CHECK_HEADERS([linux/nfsd/cld.h], , + AC_MSG_ERROR([Cannot find header needed for nfsdcld])) + fi
This adds a dependency on the kernel headers being present which is unprecedented for nfs-utils or any other package I'm aware of and I just don't think its a good idea...
So I'm wondering if there is someway around creating this dependency...
steved.
Quoted 330 lines
configure.ac +4
-0+ + AM_CONDITIONAL(CONFIG_NFSDCLD, [test "$enable_nfsdcld" = "yes" ]) + dnl librpcsecgss already has a dependency on libgssapi, dnl but we need to make sure we get the right version if test "$enable_gss" = yes; then@@ -460,6 +473,7 @@ AC_CONFIG_FILES([ tools/nfs-iostat/Makefile utils/Makefile utils/blkmapd/Makefile + utils/nfsdcld/Makefile utils/exportfs/Makefile utils/gssd/Makefile utils/idmapd/Makefileutils/Makefile.am +4
-0@@ -21,6 +21,10 @@ if CONFIG_MOUNT OPTDIRS += mount endif +if CONFIG_NFSDCLD +OPTDIRS += nfsdcld +endif + SUBDIRS = \ exportfs \ mountd \utils/nfsdcld/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 + +nfsdcld_LDADD = ../../support/nfs/libnfs.a $(LIBEVENT) + +MAINTAINERCLEANFILES = Makefile.in +utils/nfsdcld/nfsdcld.c new file +275
-0@@ -0,0 +1,275 @@ +/* +* nfsdcld.c -- NFSv4 client name tracking daemon +* +* 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. +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include <errno.h> +#include <event.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 <linux/nfsd/cld.h> + +#include "xlog.h" +#include "nfslib.h" + +#ifndef PIPEFS_DIR +#define PIPEFS_DIR NFS_STATEDIR "/rpc_pipefs" +#endif + +#define DEFAULT_CLD_PATH PIPEFS_DIR "/nfsd/cld" + +#define UPCALL_VERSION 1 + +/* private data structures */ +struct cld_client { +int cl_fd; +struct event cl_event; +struct cld_msg cl_msg; +}; + +/* global variables */ +static char *pipepath =DEFAULT_CLD_PATH ; + +static struct option longopts[] = +{ + {"help" ,0 ,NULL ,'h' }, + {"foreground" ,0 ,NULL ,'F' }, + {"debug" ,0 ,NULL ,'d' }, + {"pipe" ,1 ,NULL ,'p' }, + {NULL ,0 ,0 ,0 }, +}; + +/* forward declarations */ +static void cldcb (int UNUSED (fd ),short which,void *data); + +static void +usage (char *progname) +{ +printf ("Usage:\n" ); +printf ("%s [ -hFd ] [ -p pipe ]\n" , progname); +} + +static int +cld_pipe_open (struct cld_client *clnt) +{ +int fd; + +xlog (D_GENERAL ,"%s: opening upcall pipe %s" , __func__, pipepath); + fd =open (pipepath,O_RDWR ,0 ); +if (fd <0 ) { +xlog (L_ERROR ,"%s: open of %s failed: %m" , __func__, pipepath); +return -errno; + } + +if (clnt->cl_event.ev_flags &EVLIST_INIT ) +event_del (&clnt->cl_event); +if (clnt->cl_fd >=0 ) +close (clnt->cl_fd); + + clnt->cl_fd = fd; +event_set (&clnt->cl_event, clnt->cl_fd,EV_READ , cldcb, clnt); +/* event_add is done by the caller */ +return 0 ; +} + +static int +cld_pipe_init (struct cld_client *clnt) +{ +int ret; + + clnt->cl_fd =-1 ; + ret =cld_pipe_open (clnt); +if (ret) +return ret; + +event_add (&clnt->cl_event,NULL ); +return 0 ; +} + +static void +cld_not_implemented (struct cld_client *clnt) +{ +int ret; +ssize_t bsize, wsize; +struct cld_msg *cmsg = &clnt->cl_msg; + +xlog (D_GENERAL ,"%s: downcalling with not implemented error" , __func__); + +/* set up reply */ + cmsg->cm_status = -EOPNOTSUPP ; + + bsize =sizeof (*cmsg); + + wsize =atomicio ((void *)write, clnt->cl_fd, cmsg, bsize); +if (wsize != bsize) +xlog (L_ERROR ,"%s: problem writing to cld pipe (%ld): %m" , + __func__, wsize); + +/* reopen pipe, just to be sure */ + ret =cld_pipe_open (clnt); +if (ret) { +xlog (L_FATAL ,"%s: unable to reopen pipe: %d" , __func__, ret); +exit (ret); + } +} + +static void +cld_create (struct cld_client *clnt) +{ +int ret; +ssize_t bsize, wsize; +struct cld_msg *cmsg = &clnt->cl_msg; + +xlog (D_GENERAL ,"%s: create client record" , __func__); + +/* FIXME: create client record on storage here */ + +/* set up reply */ + cmsg->cm_status =0 ; + + bsize =sizeof (*cmsg); + + wsize =atomicio ((void *)write, clnt->cl_fd, cmsg, bsize); +if (wsize != bsize) { +xlog (L_ERROR ,"%s: problem writing to cld pipe (%ld): %m" , + __func__, wsize); + ret =cld_pipe_open (clnt); +if (ret) { +xlog (L_FATAL ,"%s: unable to reopen pipe: %d" , + __func__, ret); +exit (ret); + } + } +} + +static void +cldcb (int UNUSED (fd ),short which,void *data) +{ +ssize_t len; +struct cld_client *clnt = data; +struct cld_msg *cmsg = &clnt->cl_msg; + +if (which !=EV_READ ) + goto out; + + len =atomicio (read, clnt->cl_fd, cmsg,sizeof (*cmsg)); +if (len <=0 ) { +xlog (L_ERROR ,"%s: pipe read failed: %m" , __func__); +cld_pipe_open (clnt); + goto out; + } + +if (cmsg->cm_vers !=UPCALL_VERSION ) { +xlog (L_ERROR ,"%s: unsupported upcall version: %hu" , + cmsg->cm_vers); +cld_pipe_open (clnt); + goto out; + } + +switch (cmsg->cm_cmd) { +case Cld_Create: +cld_create (clnt); +break ; +default : +xlog (L_WARNING ,"%s: command %u is not yet implemented" , + __func__, cmsg->cm_cmd); +cld_not_implemented (clnt); + } +out: +event_add (&clnt->cl_event,NULL ); +} + +int +main (int argc,char **argv) +{ +char arg; +int rc =0 ; +bool foreground = false; +char *progname; +struct cld_client clnt; + +memset (&clnt,0 ,sizeof (clnt)); + + progname =strdup (basename (argv[0 ])); +if (!progname) { +fprintf (stderr,"%s: unable to allocate memory.\n" , argv[0 ]); +return 1 ; + } + +event_init (); +xlog_syslog (0 ); +xlog_stderr (1 ); + +/* process command-line options */ +while ((arg =getopt_long (argc, argv,"hdFp:" , longopts, +NULL )) !=EOF ) { +switch (arg) { +case 'd' : +xlog_config (D_ALL ,1 ); +break ; +case 'F' : + foreground = true; +break ; +case 'p' : + pipepath = optarg; +break ; +default : +usage (progname); +return 0 ; + } + } + + +xlog_open (progname); +if (!foreground) { +xlog_syslog (1 ); +xlog_stderr (0 ); + rc =daemon (0 ,0 ); +if (rc) { +xlog (L_ERROR ,"Unable to daemonize: %m" ); + goto out; + } + } + +/* set up storage db */ + +/* set up event handler */ + rc =cld_pipe_init (&clnt); +if (rc) + goto out; + +xlog (D_GENERAL ,"%s: Starting event dispatch handler." , __func__); + rc =event_dispatch (); +if (rc <0 ) +xlog (L_ERROR ,"%s: event_dispatch failed: %m" , __func__); + +close (clnt.cl_fd); +out: +free (progname); +return rc; +}
Re: [PATCH v5 1/9] nfsdcld: add client tracking daemon stub
Quoted 49 lines · On Mon, 16 Apr 2012 10:06:55 -0400 Steve Dickson <[email protected]> wrote:
Quoted 35 lines · Jeff Layton
This program opens and "listens" on the new nfsd/cld
rpc_pipefspipe. The code here doesn't actually do anything on stable storage yet. That will be added in a later patch.The patch also adds a autoconf enable switch for the new daemon that defaults to "no", and a test for the upcall description header file.
Signed-off-by Jeff Layton <[email protected]>--- configure.ac | 14 +++ utils/Makefile.am | 4 + utils/nfsdcld/Makefile.am | 14 +++ utils/nfsdcld/nfsdcld.c | 275 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 307 insertions(+), 0 deletions(-) create mode 100644 utils/nfsdcld/Makefile.am create mode 100644 utils/nfsdcld/nfsdcld.cconfigure.ac +6
-0@@ -185,6 +185,12 @@ 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") + dnl Check for TI-RPC library and headers AC_LIBTIRPCconfigure.ac if test "$enable_nfsv4" = yes; then · line 272
Quoted 7 lines
configure.ac +4
-0@@ -260,6 +266,13 @@ if test "$enable_nfsv4" = yes; then dnl check for the keyutils libraries and headers AC_KEYUTILS + if test "$enable_nfsdcld" = "yes"; then + AC_CHECK_HEADERS([linux/nfsd/cld.h], , + AC_MSG_ERROR([Cannot find header needed for nfsdcld])) + fiThis adds a dependency on the kernel headers being present which is unprecedented for nfs-utils or any other package I'm aware of and I just don't think its a good idea...
Quoted 3 lines
So I'm wondering if there is someway around creating this dependency...
The idea with that header was to have a common userspace/kernel header that describes the upcall/downcall format. The proper place for those is generally the kernel-headers package (at least on Fedora). Other distros have a similar package.
One possibility is to include a copy of this header with nfs-utils, and only use it if /usr/include/linux/nfsd/cld.h isn't present. It's not ideal, but I suppose we could live with it if adding a dependency on kernel headers is anathema. It would take some rework of the code and autoconf/automake stuff however.
Signature · 1 line
Jeff Layton <[email protected]>
Re: [PATCH v5 1/9] nfsdcld: add client tracking daemon stub
Quoted 61 lines · Jeff Layton
Quoted 49 lines · On Mon, 16 Apr 2012 10:06:55 -0400 Steve Dickson <[email protected]> wrote:
Quoted 35 lines · Jeff Layton
This program opens and "listens" on the new nfsd/cld
rpc_pipefspipe. The code here doesn't actually do anything on stable storage yet. That will be added in a later patch.The patch also adds a autoconf enable switch for the new daemon that defaults to "no", and a test for the upcall description header file.
Signed-off-by Jeff Layton <[email protected]>--- configure.ac | 14 +++ utils/Makefile.am | 4 + utils/nfsdcld/Makefile.am | 14 +++ utils/nfsdcld/nfsdcld.c | 275 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 307 insertions(+), 0 deletions(-) create mode 100644 utils/nfsdcld/Makefile.am create mode 100644 utils/nfsdcld/nfsdcld.cconfigure.ac +6
-0@@ -185,6 +185,12 @@ 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") + dnl Check for TI-RPC library and headers AC_LIBTIRPCconfigure.ac if test "$enable_nfsv4" = yes; then · line 272
Quoted 7 lines
configure.ac +4
-0@@ -260,6 +266,13 @@ if test "$enable_nfsv4" = yes; then dnl check for the keyutils libraries and headers AC_KEYUTILS + if test "$enable_nfsdcld" = "yes"; then + AC_CHECK_HEADERS([linux/nfsd/cld.h], , + AC_MSG_ERROR([Cannot find header needed for nfsdcld])) + fiThis adds a dependency on the kernel headers being present which is unprecedented for nfs-utils or any other package I'm aware of and I just don't think its a good idea...
Quoted 3 lines
So I'm wondering if there is someway around creating this dependency...
The idea with that header was to have a common userspace/kernel header that describes the upcall/downcall format. The proper place for those is generally the kernel-headers package (at least on Fedora). Other distros have a similar package.
Quoted 6 lines
One possibility is to include a copy of this header with nfs-utils, and only use it if
/usr/include/linux/nfsd/cld.hisn't present. It's not ideal, but I suppose we could live with it if adding a dependency on kernel headers is anathema. It would take some rework of the code and autoconf/automake stuff however.
I believe this is how it was done in the past, keeping separate header files... Since I'm causing the pain, I would be more than willing to do the autoconf/automake updates...
steved.
Re: [PATCH v5 1/9] nfsdcld: add client tracking daemon stub
Quoted 70 lines · On Mon, 16 Apr 2012 11:14:34 -0400 Steve Dickson <[email protected]> wrote:
Quoted 61 lines · Jeff Layton
Quoted 49 lines · On Mon, 16 Apr 2012 10:06:55 -0400 Steve Dickson <[email protected]> wrote:
Quoted 35 lines · Jeff Layton
This program opens and "listens" on the new nfsd/cld
rpc_pipefspipe. The code here doesn't actually do anything on stable storage yet. That will be added in a later patch.The patch also adds a autoconf enable switch for the new daemon that defaults to "no", and a test for the upcall description header file.
Signed-off-by Jeff Layton <[email protected]>--- configure.ac | 14 +++ utils/Makefile.am | 4 + utils/nfsdcld/Makefile.am | 14 +++ utils/nfsdcld/nfsdcld.c | 275 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 307 insertions(+), 0 deletions(-) create mode 100644 utils/nfsdcld/Makefile.am create mode 100644 utils/nfsdcld/nfsdcld.cconfigure.ac +6
-0@@ -185,6 +185,12 @@ 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") + dnl Check for TI-RPC library and headers AC_LIBTIRPCconfigure.ac if test "$enable_nfsv4" = yes; then · line 272
Quoted 7 lines
configure.ac +4
-0@@ -260,6 +266,13 @@ if test "$enable_nfsv4" = yes; then dnl check for the keyutils libraries and headers AC_KEYUTILS + if test "$enable_nfsdcld" = "yes"; then + AC_CHECK_HEADERS([linux/nfsd/cld.h], , + AC_MSG_ERROR([Cannot find header needed for nfsdcld])) + fiThis adds a dependency on the kernel headers being present which is unprecedented for nfs-utils or any other package I'm aware of and I just don't think its a good idea...
Quoted 3 lines
So I'm wondering if there is someway around creating this dependency...
The idea with that header was to have a common userspace/kernel header that describes the upcall/downcall format. The proper place for those is generally the kernel-headers package (at least on Fedora). Other distros have a similar package.
Quoted 6 lines
One possibility is to include a copy of this header with nfs-utils, and only use it if
/usr/include/linux/nfsd/cld.hisn't present. It's not ideal, but I suppose we could live with it if adding a dependency on kernel headers is anathema. It would take some rework of the code and autoconf/automake stuff however.
Quoted 4 lines
I believe this is how it was done in the past, keeping separate header files... Since I'm causing the pain, I would be more than willing to do the autoconf/automake updates...
Ok. If we ever have to rev the upcall format, then we'll also need to fix the daemon to deal with legacy formats as well. Using a header bundled with nfs-utils might actually make that easier.
I'm rather swamped at the moment, so I'll take you up on the offer to fix up the autoconf/automake stuff :).
Signature · 1 line
Jeff Layton <[email protected]>
Re: [PATCH v5 1/9] nfsdcld: add client tracking daemon stub
Quoted 4 lines · Jeff Layton
On Mon, 16 Apr 2012 11:14:34 -0400
I'm rather swamped at the moment, so I'll take you up on the offer to fix up the autoconf/automake stuff :).
Of course you will!! 8-)
Thanks!
steved.
Quoted 27 lines · Jeff Layton
This patchset is the userspace portion of the knfsd client name tracking overhaul. See this patch series for an explanation:
nfsd: overhaul the client name tracking code
This version scales back some of the changes in the last set. Since then, it's become clear that I'm not entirely certain what changes we'll need in order to handle this in a clustered configuration. Instead of trying to anticipate those changes, I've decided just to focus on the single-server case and leave any other changes for later once it becomes more clear what (if anything) is needed.
The main changes from the last set are:
- the "remove" upcall has been readded
- the "init" upcall has been removed
- the "check" and "update" upcalls no longer return a client index to the kernel
- the pipe open and reopen code has been overhauled and consolidated. Instead of looping indefinitely when trying to reopen the file, it will abort the daemon if the open fails with anything besides ENOENT. If the pipe isn't present when the daemon starts, it now uses the inotify event callback to handle the opening.
Quoted 10 lines
Jeff Layton (9):
nfsdcld: add client tracking daemon stub
nfsdcld: add autoconf goop for sqlite
nfsdcld: add routines for a sqlite backend database
nfsdcld: add remove functionality
nfsdcld: add check/update functionality
nfsdcld: add function to remove unreclaimed client records
nfsdcld: make it watch for inotify events in the containing directory
nfsdcld: add a manpage for nfsdcld
nfsdcld: update the README
Committed.... My apologies for taking so long...
steved.