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