From: Neil Brown Date: Fri, 16 Mar 2007 00:24:15 +0000 (+1100) Subject: Automatically start statd when mounting an nfs filesystem. X-Git-Tag: nfs-utils-1-1-0-rc1~80 X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=commitdiff_plain;h=993ec3f888a28c60d49ae0f8f1aa725b6b618a81;hp=dad50c0e589b5651242de50e81200b036d995b73 Automatically start statd when mounting an nfs filesystem. If statd is not running (/var/run/rpc.statd.pid) when an nfs filesystem is mounted (v2 or v3, with remote locking enabled), and if /usr/sbin/start-statd (or other program specified at config time) is present, then run that program to start statd. This means that statd does not need to be running "just in case". It only needs to be started at boot time if the nfs server is started. --- diff --git a/configure.in b/configure.in index 258188a..1a1ce1a 100644 --- a/configure.in +++ b/configure.in @@ -38,6 +38,15 @@ AC_ARG_WITH(statduser, statduser=nobody fi) AC_SUBST(statduser) +AC_ARG_WITH(start-statd, + [AC_HELP_STRING([--with-start-statd=scriptname], + [When an nfs filesystems is mounted with locking, run this script] + )], + startstatd=$withval, + startstatd=/usr/sbin/start-statd + ) + AC_SUBST(startstatd) + AC_DEFINE_UNQUOTED(START_STATD, "$startstatd", [Define this to a script which can start statd on mount]) AC_ARG_ENABLE(nfsv3, [AC_HELP_STRING([--enable-nfsv3], [enable support for NFSv3 @<:@default=yes@:>@])], diff --git a/utils/mount/mount.c b/utils/mount/mount.c index 7d71e06..6717941 100644 --- a/utils/mount/mount.c +++ b/utils/mount/mount.c @@ -255,6 +255,26 @@ static void mount_error(char *node) } } +static void start_statd() +{ + /* If /var/run/rpc.statd.pid exists and is non-empty, + * assume statd already running. + * If START_STATD not defined, or defined to a non-existent file, + * don't bother, + * else run that file (typically a shell script) + */ + struct stat stb; + if (stat("/var/run/rpc.statd.pid", &stb) == 0 && + stb.st_size > 0) + return; +#ifdef START_STATD + if (stat(START_STATD, &stb) ==0 && + S_ISREG(stb.st_mode) && + (stb.st_mode & S_IXUSR)) + system(START_STATD); +#endif +} + int main(int argc, char *argv[]) { int c, flags = 0, nfs_mount_vers = 0, mnt_err = 1, fake = 0; @@ -358,11 +378,13 @@ int main(int argc, char *argv[]) nfs_mount_vers = 4; mnt_err = nfs4mount(spec, mount_point, &flags, &extra_opts, &mount_opts, 0); } - else { - if (!strcmp(progname, "mount.nfs")) { - mnt_err = nfsmount(spec, mount_point, &flags, - &extra_opts, &mount_opts, &nfs_mount_vers, 0); - } + else if (!strcmp(progname, "mount.nfs")) { + int need_statd = 0; + mnt_err = nfsmount(spec, mount_point, &flags, + &extra_opts, &mount_opts, &nfs_mount_vers, + 0, &need_statd); + if (!mnt_err && !fake && need_statd) + start_statd(); } if (!mnt_err && !fake) { diff --git a/utils/mount/nfs_mount.h b/utils/mount/nfs_mount.h index 1fd74c8..1acb633 100644 --- a/utils/mount/nfs_mount.h +++ b/utils/mount/nfs_mount.h @@ -78,7 +78,8 @@ struct nfs_mount_data { #define AUTH_GSS_SPKMP 390011 #endif -int nfsmount(const char *, const char *, int *, char **, char **, int *, int); +int nfsmount(const char *, const char *, int *, char **, char **, int *, + int, int *); void mount_errors(char *, int, int); #endif /* _NFS_MOUNT_H */ diff --git a/utils/mount/nfsmount.c b/utils/mount/nfsmount.c index 6226f6c..0188caa 100644 --- a/utils/mount/nfsmount.c +++ b/utils/mount/nfsmount.c @@ -818,7 +818,7 @@ nfsmnt_check_compat(const struct pmap *nfs_pmap, const struct pmap *mnt_pmap) int nfsmount(const char *spec, const char *node, int *flags, char **extra_opts, char **mount_opts, int *nfs_mount_vers, - int running_bg) + int running_bg, int *need_statd) { static char *prev_bg_host; char hostdir[1024]; @@ -1185,6 +1185,7 @@ noauth_flavors: strcat(new_opts, cbuf); *extra_opts = xstrdup(new_opts); + *need_statd = ! (data.flags & NFS_MOUNT_NONLM); return 0; /* abort */