]> git.decadent.org.uk Git - nfs-utils.git/commitdiff
Tell NFS/lockd client what that local state number is.
authorNeil Brown <neilb@suse.de>
Mon, 2 Apr 2007 03:25:40 +0000 (13:25 +1000)
committerNeil Brown <neilb@suse.de>
Mon, 2 Apr 2007 03:25:40 +0000 (13:25 +1000)
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>
utils/statd/monitor.c
utils/statd/sm-notify.c
utils/statd/stat.c
utils/statd/statd.c

index b95b0ad51692e7b6708a2a94d289ad7484ccbbd1..bbc1dec67f423de605cfbfd228fe09cd8e8a7df6 100644 (file)
@@ -166,9 +166,7 @@ sm_mon_1_svc(struct mon *argp, struct svc_req *rqstp)
                                mon_name, my_name);
 
                        /* But we'll let you pass anyway. */
                                mon_name, my_name);
 
                        /* But we'll let you pass anyway. */
-                       result.res_stat = STAT_SUCC;
-                       result.state = MY_STATE;
-                       return (&result);
+                       goto success;
                }
                clnt = NL_NEXT(clnt);
        }
                }
                clnt = NL_NEXT(clnt);
        }
@@ -222,10 +220,20 @@ sm_mon_1_svc(struct mon *argp, struct svc_req *rqstp)
        ha_callout("add-client", mon_name, my_name, -1);
        nlist_insert(&rtnl, clnt);
        close(fd);
        ha_callout("add-client", mon_name, my_name, -1);
        nlist_insert(&rtnl, clnt);
        close(fd);
-
+       dprintf(N_DEBUG, "MONITORING %s for %s", mon_name, my_name);
+ success:
        result.res_stat = STAT_SUCC;
        result.res_stat = STAT_SUCC;
+       /* SUN's sm_inter.x says this should be "state number of local site".
+        * X/Open says '"state" will be contain the state of the remote NSM.'
+        * href=http://www.opengroup.org/onlinepubs/9629799/SM_MON.htm
+        * Linux lockd currently (2.6.21 and prior) ignores whatever is
+        * returned, and given the above contraction, it probably always will..
+        * So we just return what we always returned.  If possible, we
+        * have already told lockd about our state number via a sysctl.
+        * If lockd wants the remote state, it will need to
+        * use SM_STAT (and prayer).
+        */
        result.state = MY_STATE;
        result.state = MY_STATE;
-       dprintf(N_DEBUG, "MONITORING %s for %s", mon_name, my_name);
        return (&result);
 
 failure:
        return (&result);
 
 failure:
index a94876d1b160190c819d6b7ae82d9caf800a5805..bb6c2efa3f4e949191f4831757f7cf5e649eafa6 100644 (file)
@@ -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);
 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;
 
 
 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);
 
        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");
        if (!opt_debug) {
                if (!opt_quiet)
                        printf("Backgrounding to notify hosts...\n");
@@ -184,9 +189,6 @@ usage:              fprintf(stderr,
                close(2);
        }
 
                close(2);
        }
 
-       /* Get and update the NSM state. This will call sync() */
-       nsm_state = nsm_get_state(opt_update_state);
-
        notify();
 
        if (hosts) {
        notify();
 
        if (hosts) {
@@ -758,3 +760,16 @@ static void drop_privs(void)
                exit(1);
        }
 }
                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);
+       }
+}
index bcd3550f34d54e1dbcf5feaa24a46c507256195d..799239f1d956f668c0cf2c79c98175914740b0b4 100644 (file)
  * status."  My implementation is operative; it returns 'STAT_SUCC'
  * whenever it can resolve the hostname that it's being asked to
  * monitor, and returns 'STAT_FAIL' otherwise.
  * status."  My implementation is operative; it returns 'STAT_SUCC'
  * whenever it can resolve the hostname that it's being asked to
  * monitor, and returns 'STAT_FAIL' otherwise.
+ *
+ * sm_inter.x says the 'state' returned should be
+ *   "state number of site sm_name".  It is not clear how to get this.
+ * X/Open says:
+ *   STAT_SUCC
+ *      The NSM will monitor the given host. "sm_stat_res.state" contains
+ *      the state of the NSM.
+ * Which implies that 'state' is the state number of the *local* NSM.
+ * href=http://www.opengroup.org/onlinepubs/9629799/SM_STAT.htm
+ *
+ * We return the *local* state as
+ *   1/ We have easy access to it.
+ *   2/ It might be useful to a remote client who needs it and has no
+ *      other way to get it.
+ *   3/ That's what we always did in the past.
  */
 struct sm_stat_res * 
 sm_stat_1_svc (struct sm_name *argp, struct svc_req *rqstp)
  */
 struct sm_stat_res * 
 sm_stat_1_svc (struct sm_name *argp, struct svc_req *rqstp)
index 091ced9316e9220408fb7799004c297b8c0fd9ec..8337b64b993918fb8704daeb49cae711447779d3 100644 (file)
@@ -76,6 +76,7 @@ static struct option longopts[] =
 
 extern void sm_prog_1 (struct svc_req *, register SVCXPRT *);
 extern int statd_get_socket(void);
 
 extern void sm_prog_1 (struct svc_req *, register SVCXPRT *);
 extern int statd_get_socket(void);
+static void load_state_number(void);
 
 #ifdef SIMULATIONS
 extern void simulator (int, char **);
 
 #ifdef SIMULATIONS
 extern void simulator (int, char **);
@@ -483,7 +484,7 @@ int main (int argc, char **argv)
         * pass on any SM_NOTIFY that arrives
         */
        load_state();
         * pass on any SM_NOTIFY that arrives
         */
        load_state();
-
+       load_state_number();
        pmap_unset (SM_PROG, SM_VERS);
 
        /* this registers both UDP and TCP services */
        pmap_unset (SM_PROG, SM_VERS);
 
        /* this registers both UDP and TCP services */
@@ -526,3 +527,23 @@ int main (int argc, char **argv)
        }
        return 0;
 }
        }
        return 0;
 }
+
+static void
+load_state_number(void)
+{
+       int fd;
+
+       if ((fd = open(SM_STAT_PATH, O_RDONLY)) == -1)
+               return;
+
+       read(fd, &MY_STATE, sizeof(MY_STATE));
+       close(fd);
+       fd = open("/proc/sys/fs/nfs/nsm_local_state",O_WRONLY);
+       if (fd >= 0) {
+               char buf[20];
+               snprintf(buf, sizeof(buf), "%d", MY_STATE);
+               write(fd, buf, strlen(buf));
+               close(fd);
+       }
+
+}