Skip to contentSkip to conversation

nfsdcld: stop polling a dead cld pipe after nfsd shuts down

PATCH New Benjamin Coddington 1 participant 1 message Nov 19

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nfsdcld: stop polling a dead cld pipe after nfsd shuts down

When nfsd shuts down, the kernel removes rpc_pipefs/nfsd/cld. The next read on the open pipe fails, and cld_pipe_read_msg() tries to reopen it. That open fails with ENOENT, cld_pipe_open() leaves the old fd and event in place, and cldcb() re-adds the event on the dead fd. The fd always reports HUP, so nfsdcld spins at full CPU and floods syslog with "pipe read failed: Broken pipe" until nfsd comes back.

If the reopen fails, close the dead pipe and drop its event. The inotify watch on the pipefs directory reopens the pipe when nfsd recreates it.

---
 utils/nfsdcld/nfsdcld.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)
utils/nfsdcld/nfsdcld.c +24 -2
index 772cf3147e88..3ffecb5a28f7 100644
@@ -186,6 +186,19 @@ cld_pipe_open(struct cld_client *clnt)
 	return 0;
 }
 
+static void
+cld_pipe_close(struct cld_client *clnt)
+{
+	if (clnt->cl_event) {
+		event_free(clnt->cl_event);
+		clnt->cl_event = NULL;
+	}
+	if (clnt->cl_fd >= 0) {
+		close(clnt->cl_fd);
+		clnt->cl_fd = -1;
+	}
+}
+
 static void
 cld_inotify_cb(int UNUSED(fd), short which, void *data)
 {
@@ -753,7 +766,15 @@ cld_pipe_read_msg(struct cld_client *clnt)
 	return 0;
 
 fail_read:
-	cld_pipe_open(clnt);
+	/*
+	 * If the pipe is gone, re-arming the dead fd would spin on HUP.
+	 * Drop it and let cld_inotify_cb reopen the pipe when it returns.
+	 */
+	if (cld_pipe_open(clnt) < 0) {
+		xlog(D_GENERAL, "%s: waiting for %s to reappear",
+			__func__, pipepath);
+		cld_pipe_close(clnt);
+	}
 	return -1;
 }
 
@@ -794,7 +815,8 @@ cldcb(int UNUSED(fd), short which, void *data)
 		cld_not_implemented(clnt);
 	}
 out:
-	event_add(clnt->cl_event, NULL);
+	if (clnt->cl_event)
+		event_add(clnt->cl_event, NULL);
 }
 
 int

base-commit: 79770ef91411cc2d3f97eb5efdd43a7d39b0070e

Signature · 1 line
2.53.0