]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - utils/statd/sm-notify.c
Imported upstream 1.2.8
[nfs-utils.git] / utils / statd / sm-notify.c
index 2421f8bb4f043ed73ea0e58f2b37f6030f49eecb..9dbe5d9083361f2422716b004d029ff19e222779 100644 (file)
@@ -45,8 +45,9 @@
 struct nsm_host {
        struct nsm_host *       next;
        char *                  name;
-       char *                  mon_name;
-       char *                  my_name;
+       const char *            mon_name;
+       const char *            my_name;
+       char *                  notify_arg;
        struct addrinfo         *ai;
        time_t                  last_used;
        time_t                  send_next;
@@ -199,14 +200,23 @@ smn_alloc_host(const char *hostname, const char *mon_name,
        if (host == NULL)
                goto out_nomem;
 
+       /*
+        * mon_name and my_name are preserved so sm-notify can
+        * find the right monitor record to remove when it is
+        * done processing this host.
+        */
        host->name = strdup(hostname);
-       host->mon_name = strdup(mon_name);
-       host->my_name = strdup(my_name);
+       host->mon_name = (const char *)strdup(mon_name);
+       host->my_name = (const char *)strdup(my_name);
+       host->notify_arg = strdup(opt_srcaddr != NULL ?
+                                       nsm_hostname : my_name);
        if (host->name == NULL ||
            host->mon_name == NULL ||
-           host->my_name == NULL) {
-               free(host->my_name);
-               free(host->mon_name);
+           host->my_name == NULL ||
+           host->notify_arg == NULL) {
+               free(host->notify_arg);
+               free((void *)host->my_name);
+               free((void *)host->mon_name);
                free(host->name);
                free(host);
                goto out_nomem;
@@ -230,8 +240,9 @@ static void smn_forget_host(struct nsm_host *host)
 
        nsm_delete_notified_host(host->name, host->mon_name, host->my_name);
 
-       free(host->my_name);
-       free(host->mon_name);
+       free(host->notify_arg);
+       free((void *)host->my_name);
+       free((void *)host->mon_name);
        free(host->name);
        if (host->ai)
                freeaddrinfo(host->ai);
@@ -252,7 +263,6 @@ smn_get_host(const char *hostname,
                return 0;
 
        insert_host(host);
-       xlog(D_GENERAL, "Added host %s to notify list", hostname);
        return 1;
 }
 
@@ -339,7 +349,7 @@ smn_bind_address(const char *srcaddr, const char *srcport)
 {
        struct addrinfo *ai = NULL;
        struct addrinfo hint = {
-               .ai_flags       = AI_NUMERICSERV,
+               .ai_flags       = AI_NUMERICSERV | AI_V4MAPPED,
                .ai_family      = nsm_family,
                .ai_protocol    = (int)IPPROTO_UDP,
        };
@@ -636,8 +646,6 @@ notify(const int sock)
 static int
 notify_host(int sock, struct nsm_host *host)
 {
-       const char *my_name = (opt_srcaddr != NULL ?
-                                       nsm_hostname : host->my_name);
        struct sockaddr *sap;
        socklen_t salen;
 
@@ -683,11 +691,30 @@ notify_host(int sock, struct nsm_host *host)
                host->xid = nsm_xmit_rpcbind(sock, sap, SM_PROG, SM_VERS);
        else
                host->xid = nsm_xmit_notify(sock, sap, salen,
-                                       SM_PROG, my_name, nsm_state);
+                                       SM_PROG, host->notify_arg, nsm_state);
 
        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->retries = 0;
+       host->xid = 0;
+       host->send_next = time(NULL);
+       host->timeout = NSM_TIMEOUT;
+       insert_host(host);
+}
+
 /*
  * Extract the returned port number and set up the SM_NOTIFY call.
  */
@@ -696,21 +723,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);
 }
 
 /*
@@ -723,15 +745,11 @@ recv_rpcbind_reply(struct sockaddr *sap, struct nsm_host *host, XDR *xdr)
 static void
 recv_notify_reply(struct nsm_host *host)
 {
-       char *dot = strchr(host->my_name, '.');
+       char *dot = strchr(host->notify_arg, '.');
 
        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 +798,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 +823,7 @@ insert_host(struct nsm_host *host)
 
        host->next = *where;
        *where = host;
+       xlog(D_GENERAL, "Added host %s to notify list", host->name);
 }
 
 /*