Skip to contentSkip to conversation

NFS: don't let nfs_callback_svc exit on unexpected svc_recv errors (try #2)

PATCH New Jeff Layton 3 participants 5 messages Apr 8, 2008 – Apr 9, 2008

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

PATCH 1/1 NLM: don't let lockd exit on unexpected svc_recv errors (try #2)

In reply to Jeff Layton

When svc_recv returns an unexpected error, lockd will print a warning and exit. This problematic for several reasons. In particular, it will cause the reference counts for the thread to be wrong, and can lead to a potential BUG() call.

Rather than exiting on error from svc_recv, have the thread do a 1s sleep and then retry the loop. This is unlikely to cause any harm, and if the error turns out to be something temporary then it may be able to recover.

---
 fs/lockd/svc.c |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)
fs/lockd/svc.c +12 -6
index 66b5c98..cf977bb 100644
@@ -112,7 +112,7 @@ static inline void clear_grace_period(void)
 static int
 lockd(void *vrqstp)
 {
-	int		err = 0;
+	int		err = 0, preverr = 0;
 	struct svc_rqst *rqstp = vrqstp;
 	unsigned long grace_period_expire;
 
@@ -172,14 +172,20 @@ lockd(void *vrqstp)
 		 * recvfrom routine.
 		 */
 		err = svc_recv(rqstp, timeout);
-		if (err == -EAGAIN || err == -EINTR)
+		if (err == -EAGAIN || err == -EINTR) {
+			preverr = err;
 			continue;
+		}
 		if (err < 0) {
-			printk(KERN_WARNING
-			       "lockd: terminating on error %d\n",
-			       -err);
-			break;
+			if (err != preverr) {
+				printk(KERN_WARNING "%s: unexpected error "
+					"from svc_recv (%d)\n", __func__, err);
+				preverr = err;
+			}
+			schedule_timeout_interruptible(HZ);
+			continue;
 		}
+		preverr = err;
 
 		dprintk("lockd: request from %s\n",
 				svc_print_addr(rqstp, buf, sizeof(buf)));
Signature · 1 line
1.5.3.6
#0 lore raw

PATCH 1/1 NFS: don't let nfs_callback_svc exit on unexpected svc_recv errors (try #2)

When svc_recv returns an unexpected error, nfs_callback_svc will print a warning and exit. This problematic for several reasons. In particular, it will cause the reference counts for the thread to be wrong, and no new thread will be started until all nfs4 mounts are unmounted.

Rather than exiting on error from svc_recv, have the thread do a 1s sleep and then retry the loop. This is unlikely to cause any harm, and if the error turns out to be something temporary then it may be able to recover.

---
 fs/nfs/callback.c |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)
fs/nfs/callback.c +12 -6
index a9f1538..5606ae3 100644
@@ -59,7 +59,7 @@ module_param_call(callback_tcpport, param_set_port, param_get_int,
 static int
 nfs_callback_svc(void *vrqstp)
 {
-	int err;
+	int err, preverr = 0;
 	struct svc_rqst *rqstp = vrqstp;
 
 	set_freezable();
@@ -74,14 +74,20 @@ nfs_callback_svc(void *vrqstp)
 		 * Listen for a request on the socket
 		 */
 		err = svc_recv(rqstp, MAX_SCHEDULE_TIMEOUT);
-		if (err == -EAGAIN || err == -EINTR)
+		if (err == -EAGAIN || err == -EINTR) {
+			preverr = err;
 			continue;
+		}
 		if (err < 0) {
-			printk(KERN_WARNING
-					"%s: terminating on error %d\n",
-					__FUNCTION__, -err);
-			break;
+			if (err != preverr) {
+				printk(KERN_WARNING "%s: unexpected error "
+					"from svc_recv (%d)\n", __func__, err);
+				preverr = err;
+			}
+			schedule_timeout_uninterruptible(HZ);
+			continue;
 		}
+		preverr = err;
 		svc_process(rqstp);
 	}
 	unlock_kernel();
Signature · 1 line
1.5.3.6
#2 lore raw

Re: [PATCH] NLM: don't let lockd exit on unexpected svc_recv errors (try #2)

In reply to Jeff Layton
Quoted 38 lines · Jeff Layton

When svc_recv returns an unexpected error, lockd will print a warning and exit. This problematic for several reasons. In particular, it will cause the reference counts for the thread to be wrong, and can lead to a potential BUG() call.

Rather than exiting on error from svc_recv, have the thread do a 1s sleep and then retry the loop. This is unlikely to cause any harm, and if the error turns out to be something temporary then it may be able to recover.

---
 fs/lockd/svc.c |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)
fs/lockd/svc.c +4 -2
index 66b5c98..cf977bb 100644
@@ -112,7 +112,7 @@ static inline void clear_grace_period(void)
 static int
 lockd(void *vrqstp)
 {
-	int		err = 0;
+	int		err = 0, preverr = 0;
 	struct svc_rqst *rqstp = vrqstp;
 	unsigned long grace_period_expire;
 
@@ -172,14 +172,20 @@ lockd(void *vrqstp)
 		 * recvfrom routine.
 		 */
 		err = svc_recv(rqstp, timeout);
-		if (err == -EAGAIN || err == -EINTR)
+		if (err == -EAGAIN || err == -EINTR) {
+			preverr = err;
 			continue;
+		}
 		if (err < 0) {

fs/lockd/svc.c lockd(void *vrqstp) · line 185

Quoted 10 lines
fs/lockd/svc.c +6 -4
-			printk(KERN_WARNING
-			       "lockd: terminating on error %d\n",
-			       -err);
-			break;
+			if (err != preverr) {
+				printk(KERN_WARNING "%s: unexpected error "
+					"from svc_recv (%d)\n", __func__, err);
+				preverr = err;
+			}
+			schedule_timeout_interruptible(HZ);

Why not use an uninterruptible sleep?

Trond

#3 lore raw

Re: [PATCH] NLM: don't let lockd exit on unexpected svc_recv errors (try #2)

Quoted 53 lines · On Tue, 08 Apr 2008 16:15:58 -0400 Trond Myklebust…
Quoted 38 lines · Jeff Layton

When svc_recv returns an unexpected error, lockd will print a warning and exit. This problematic for several reasons. In particular, it will cause the reference counts for the thread to be wrong, and can lead to a potential BUG() call.

Rather than exiting on error from svc_recv, have the thread do a 1s sleep and then retry the loop. This is unlikely to cause any harm, and if the error turns out to be something temporary then it may be able to recover.

---
 fs/lockd/svc.c |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)
fs/lockd/svc.c +4 -2
index 66b5c98..cf977bb 100644
@@ -112,7 +112,7 @@ static inline void clear_grace_period(void)
 static int
 lockd(void *vrqstp)
 {
-	int		err = 0;
+	int		err = 0, preverr = 0;
 	struct svc_rqst *rqstp = vrqstp;
 	unsigned long grace_period_expire;
 
@@ -172,14 +172,20 @@ lockd(void *vrqstp)
 		 * recvfrom routine.
 		 */
 		err = svc_recv(rqstp, timeout);
-		if (err == -EAGAIN || err == -EINTR)
+		if (err == -EAGAIN || err == -EINTR) {
+			preverr = err;
 			continue;
+		}
 		if (err < 0) {

fs/lockd/svc.c lockd(void *vrqstp) · line 185

Quoted 10 lines
fs/lockd/svc.c +6 -4
-			printk(KERN_WARNING
-			       "lockd: terminating on error %d\n",
-			       -err);
-			break;
+			if (err != preverr) {
+				printk(KERN_WARNING "%s: unexpected error "
+					"from svc_recv (%d)\n", __func__, err);
+				preverr = err;
+			}
+			schedule_timeout_interruptible(HZ);

Why not use an uninterruptible sleep?

Quoted 2 lines

Trond

lockd can receive a SIGKILL to tell it to drop all locks, so I figured it was reasonable to allow the sleep to be interrupted if that happens. It probably doesn't matter much either way though...

Signature · 1 line
Jeff Layton <[email protected]>
#4 lore raw

Re: [PATCH] NLM: don't let lockd exit on unexpected svc_recv errors (try #2)

In reply to Jeff Layton
Quoted 9 lines · Jeff Layton

When svc_recv returns an unexpected error, lockd will print a warning and exit. This problematic for several reasons. In particular, it will cause the reference counts for the thread to be wrong, and can lead to a potential BUG() call.

Rather than exiting on error from svc_recv, have the thread do a 1s sleep and then retry the loop. This is unlikely to cause any harm, and if the error turns out to be something temporary then it may be able to recover.

Both applied; thanks!--b.

Quoted 48 lines
---
 fs/lockd/svc.c |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)
fs/lockd/svc.c +12 -6
index 66b5c98..cf977bb 100644
@@ -112,7 +112,7 @@ static inline void clear_grace_period(void)
 static int
 lockd(void *vrqstp)
 {
-	int		err = 0;
+	int		err = 0, preverr = 0;
 	struct svc_rqst *rqstp = vrqstp;
 	unsigned long grace_period_expire;
 
@@ -172,14 +172,20 @@ lockd(void *vrqstp)
 		 * recvfrom routine.
 		 */
 		err = svc_recv(rqstp, timeout);
-		if (err == -EAGAIN || err == -EINTR)
+		if (err == -EAGAIN || err == -EINTR) {
+			preverr = err;
 			continue;
+		}
 		if (err < 0) {
-			printk(KERN_WARNING
-			       "lockd: terminating on error %d\n",
-			       -err);
-			break;
+			if (err != preverr) {
+				printk(KERN_WARNING "%s: unexpected error "
+					"from svc_recv (%d)\n", __func__, err);
+				preverr = err;
+			}
+			schedule_timeout_interruptible(HZ);
+			continue;
 		}
+		preverr = err;
 
 		dprintk("lockd: request from %s\n",
 				svc_print_addr(rqstp, buf, sizeof(buf)));
Signature · 1 line
1.5.3.6