]> git.decadent.org.uk Git - nfs-utils.git/commitdiff
sm-notify: Refactor insert_host() and recv_rpcbind_reply()
authorChuck Lever <chuck.lever@oracle.com>
Mon, 19 Sep 2011 18:17:02 +0000 (14:17 -0400)
committerSteve Dickson <steved@redhat.com>
Tue, 20 Sep 2011 11:33:03 +0000 (07:33 -0400)
Clean up: refactor the logic in recv_rpcbind_reply() that re-schedules
an nsm_host into a separate helper function

Adjust debugging messages so it's always apparent when an nsm_host is
rescheduled.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
utils/statd/sm-notify.c

index 2421f8bb4f043ed73ea0e58f2b37f6030f49eecb..46447e8110284b0e960c67d81da6dae45c5deca1 100644 (file)
@@ -252,7 +252,6 @@ smn_get_host(const char *hostname,
                return 0;
 
        insert_host(host);
-       xlog(D_GENERAL, "Added host %s to notify list", hostname);
        return 1;
 }
 
@@ -688,6 +687,25 @@ notify_host(int sock, struct nsm_host *host)
        return 0;
 }
 
+static void
+smn_defer(struct nsm_host *host)
+{
+       host->xid = 0;
+       host->send_next = time(NULL) + NSM_MAX_TIMEOUT;
+       host->timeout = NSM_MAX_TIMEOUT;
+       insert_host(host);
+}
+
+static void
+smn_schedule(struct nsm_host *host)
+{
+       host->xid = 0;
+       host->send_next = time(NULL);
+       if (host->timeout >= NSM_MAX_TIMEOUT / 4)
+               host->timeout = NSM_MAX_TIMEOUT / 4;
+       insert_host(host);
+}
+
 /*
  * Extract the returned port number and set up the SM_NOTIFY call.
  */
@@ -696,21 +714,16 @@ recv_rpcbind_reply(struct sockaddr *sap, struct nsm_host *host, XDR *xdr)
 {
        uint16_t port = nsm_recv_rpcbind(sap->sa_family, xdr);
 
-       host->send_next = time(NULL);
-       host->xid = 0;
-
        if (port == 0) {
                /* No binding for statd... */
                xlog(D_GENERAL, "No statd on host %s", host->name);
-               host->timeout = NSM_MAX_TIMEOUT;
-               host->send_next += NSM_MAX_TIMEOUT;
+               smn_defer(host);
        } else {
+               xlog(D_GENERAL, "Processing rpcbind reply for %s (port %u)",
+                       host->name, port);
                nfs_set_port(sap, port);
-               if (host->timeout >= NSM_MAX_TIMEOUT / 4)
-                       host->timeout = NSM_MAX_TIMEOUT / 4;
+               smn_schedule(host);
        }
-
-       insert_host(host);
 }
 
 /*
@@ -727,11 +740,7 @@ recv_notify_reply(struct nsm_host *host)
 
        if (dot != NULL) {
                *dot = '\0';
-               host->send_next = time(NULL);
-               host->xid = 0;
-               if (host->timeout >= NSM_MAX_TIMEOUT / 4)
-                       host->timeout = NSM_MAX_TIMEOUT / 4;
-               insert_host(host);
+               smn_schedule(host);
        } else {
                xlog(D_GENERAL, "Host %s notified successfully", host->name);
                smn_forget_host(host);
@@ -780,7 +789,7 @@ out:
 }
 
 /*
- * Insert host into sorted list
+ * Insert host into notification list, sorted by next send time
  */
 static void
 insert_host(struct nsm_host *host)
@@ -805,6 +814,7 @@ insert_host(struct nsm_host *host)
 
        host->next = *where;
        *where = host;
+       xlog(D_GENERAL, "Added host %s to notify list", host->name);
 }
 
 /*