Blame SOURCES/nfs-utils-1.3.0-statd-monlists.patch

851484
commit 76f8ce8ce02868490ddfc5686bd48562fa73eab1
851484
Author: Scott Mayhew <smayhew@redhat.com>
851484
Date:   Mon Nov 23 10:43:03 2015 -0500
851484
851484
    statd: Update existing record if we receive SM_MON with new cookie
851484
    
851484
    This prevents rpc.statd's in-memory (and on-disk) monitor lists from
851484
    winding up with  multiple records for the same peer with outdated
851484
    cookie values.  This happens in some HA-NFS configurations where
851484
    rpc.statd is always running.
851484
    
851484
    Signed-off-by: Scott Mayhew <smayhew@redhat.com>
851484
    Signed-off-by: Steve Dickson <steved@redhat.com>
851484
851484
diff --git a/utils/statd/monitor.c b/utils/statd/monitor.c
851484
index 286a5e2..368bd80 100644
851484
--- a/utils/statd/monitor.c
851484
+++ b/utils/statd/monitor.c
851484
@@ -72,6 +72,7 @@ sm_mon_1_svc(struct mon *argp, struct svc_req *rqstp)
851484
 		.sin_addr.s_addr	= htonl(INADDR_LOOPBACK),
851484
 	};
851484
 	char *dnsname = NULL;
851484
+	int existing = 0;
851484
 
851484
 	xlog(D_CALL, "Received SM_MON for %s from %s", mon_name, my_name);
851484
 
851484
@@ -148,17 +149,26 @@ sm_mon_1_svc(struct mon *argp, struct svc_req *rqstp)
851484
 		if (statd_matchhostname(NL_MY_NAME(clnt), my_name) &&
851484
 		    NL_MY_PROC(clnt) == id->my_proc &&
851484
 		    NL_MY_PROG(clnt) == id->my_prog &&
851484
-		    NL_MY_VERS(clnt) == id->my_vers &&
851484
-		    memcmp(NL_PRIV(clnt), argp->priv, SM_PRIV_SIZE) == 0) {
851484
-			/* Hey!  We already know you guys! */
851484
-			xlog(D_GENERAL,
851484
-				"Duplicate SM_MON request for %s "
851484
-				"from procedure on %s",
851484
-				mon_name, my_name);
851484
+		    NL_MY_VERS(clnt) == id->my_vers) {
851484
+			if (memcmp(NL_PRIV(clnt), argp->priv, SM_PRIV_SIZE)) {
851484
+				xlog(D_GENERAL,
851484
+					"Received SM_MON request with new "
851484
+					"cookie for %s from procedure on %s",
851484
+					mon_name, my_name);
851484
+
851484
+				existing = 1; 
851484
+				break;
851484
+			} else {
851484
+				/* Hey!  We already know you guys! */
851484
+				xlog(D_GENERAL,
851484
+					"Duplicate SM_MON request for %s "
851484
+					"from procedure on %s",
851484
+					mon_name, my_name);
851484
 
851484
-			/* But we'll let you pass anyway. */
851484
-			free(dnsname);
851484
-			goto success;
851484
+				/* But we'll let you pass anyway. */
851484
+				free(dnsname);
851484
+				goto success;
851484
+			}
851484
 		}
851484
 		clnt = NL_NEXT(clnt);
851484
 	}
851484
@@ -167,7 +177,7 @@ sm_mon_1_svc(struct mon *argp, struct svc_req *rqstp)
851484
 	 * We're committed...ignoring errors.  Let's hope that a malloc()
851484
 	 * doesn't fail.  (I should probably fix this assumption.)
851484
 	 */
851484
-	if (!(clnt = nlist_new(my_name, mon_name, 0))) {
851484
+	if (!existing && !(clnt = nlist_new(my_name, mon_name, 0))) {
851484
 		free(dnsname);
851484
 		xlog_warn("out of memory");
851484
 		goto failure;
851484
@@ -180,8 +190,11 @@ sm_mon_1_svc(struct mon *argp, struct svc_req *rqstp)
851484
 	clnt->dns_name = dnsname;
851484
 
851484
 	/*
851484
-	 * Now, Create file on stable storage for host.
851484
+	 * Now, Create file on stable storage for host, first deleting any
851484
+	 * existing records on file.
851484
 	 */
851484
+	nsm_delete_monitored_host(dnsname, mon_name, my_name);
851484
+
851484
 	if (!nsm_insert_monitored_host(dnsname,
851484
 				(struct sockaddr *)(char *)&my_addr, argp)) {
851484
 		nlist_free(NULL, clnt);
851484
@@ -190,7 +203,8 @@ sm_mon_1_svc(struct mon *argp, struct svc_req *rqstp)
851484
 
851484
 	/* PRC: do the HA callout: */
851484
 	ha_callout("add-client", mon_name, my_name, -1);
851484
-	nlist_insert(&rtnl, clnt);
851484
+	if (!existing)
851484
+		nlist_insert(&rtnl, clnt);
851484
 	xlog(D_GENERAL, "MONITORING %s for %s", mon_name, my_name);
851484
  success:
851484
 	result.res_stat = STAT_SUCC;