summaryrefslogtreecommitdiffstats
path: root/utils/statd/sm-notify.c
diff options
context:
space:
mode:
authorNeil Brown <neilb@suse.de>2007-04-02 13:25:40 +1000
committerNeil Brown <neilb@suse.de>2007-04-02 13:25:40 +1000
commitdda3455d8b96a7b078bc00c113e1af15ed421d5b (patch)
tree50d1c08a904ff99714f69d1cea1422cd8d196143 /utils/statd/sm-notify.c
parentca5f2d1e16a6451c1df203bccfd8944ee84c728f (diff)
downloadnfs-utils-dda3455d8b96a7b078bc00c113e1af15ed421d5b.tar.gz
nfs-utils-dda3455d8b96a7b078bc00c113e1af15ed421d5b.tar.xz
nfs-utils-dda3455d8b96a7b078bc00c113e1af15ed421d5b.zip
Tell NFS/lockd client what that local state number is.
Both SM_STAT and SM_MON can return the state of an NSM, but it is unclear which NSM they return the state of, so the value cannot be used, and lockd doesn't use it. Document this confusion, and give the current state to the kernel via a sysctl if that sysctl is available (since about 2.6.19). This should make is possible for the NFS server to detect a small class of bad SM_NOTIFY packets and not flush locks in that case. Signed-off-by: Neil Brown <neilb@suse.de>
Diffstat (limited to 'utils/statd/sm-notify.c')
-rw-r--r--utils/statd/sm-notify.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/utils/statd/sm-notify.c b/utils/statd/sm-notify.c
index a94876d..bb6c2ef 100644
--- a/utils/statd/sm-notify.c
+++ b/utils/statd/sm-notify.c
@@ -88,6 +88,7 @@ static struct addrinfo *host_lookup(int, const char *);
void nsm_log(int fac, const char *fmt, ...);
static int record_pid();
static void drop_privs(void);
+static void set_kernel_nsm_state(int state);
static struct nsm_host * hosts = NULL;
@@ -166,6 +167,10 @@ usage: fprintf(stderr,
backup_hosts(_SM_DIR_PATH, _SM_BAK_PATH);
get_hosts(_SM_BAK_PATH);
+ /* Get and update the NSM state. This will call sync() */
+ nsm_state = nsm_get_state(opt_update_state);
+ set_kernel_nsm_state(nsm_state);
+
if (!opt_debug) {
if (!opt_quiet)
printf("Backgrounding to notify hosts...\n");
@@ -184,9 +189,6 @@ usage: fprintf(stderr,
close(2);
}
- /* Get and update the NSM state. This will call sync() */
- nsm_state = nsm_get_state(opt_update_state);
-
notify();
if (hosts) {
@@ -758,3 +760,16 @@ static void drop_privs(void)
exit(1);
}
}
+
+static void set_kernel_nsm_state(int state)
+{
+ int fd;
+
+ fd = open("/proc/sys/fs/nfs/nsm_local_state",O_WRONLY);
+ if (fd >= 0) {
+ char buf[20];
+ snprintf(buf, sizeof(buf), "%d", state);
+ write(fd, buf, strlen(buf));
+ close(fd);
+ }
+}