Skip to contentSkip to conversation

idmapd: rearm event handler after error in nfsdcb()

PATCH In review Jeff Layton 5 participants 7 messages Sep 10, 2009 – Sep 23, 2009 2 messages not in the archive

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

PATCH 1/1 idmapd: rearm event handler after error in nfsdcb()

A couple of years ago, Bruce committed a patch to make knfsd send unsigned uid's and gid's to idmapd, rather than signed values. Part of that earlier discussion is here:

http://linux-nfs.org/pipermail/nfsv4/2007-December/007321.html

While this fixed the immediate problem, it doesn't appear that anything was ever done to make idmapd continue working when it gets a bogus upcall.

idmapd uses libevent for its main event handling loop. When idmapd gets an upcall from knfsd it will service the request and then rearm the event by calling event_add on the event structure again.

When it hits an error though, it returns in most cases w/o rearming the event. That prevents idmapd from servicing any further requests from knfsd.

I've made another change too. If an error is encountered while reading the channel file, this patch has it close and reopen the file prior to rearming the event.

I've not been able to test this patch directly, but I have tested a backport of it to earlier idmapd code and verified that it did prevent idmapd from hanging when it got a badly formatted upcall from knfsd.

---
 utils/idmapd/idmapd.c |   18 ++++++++++--------
 1 files changed, 10 insertions(+), 8 deletions(-)
utils/idmapd/idmapd.c +10 -8
index 65a6a2a..573abaa 100644
@@ -139,6 +139,7 @@ static void nametoidres(struct idmap_msg *);
 
 static int nfsdopen(void);
 static int nfsdopenone(struct idmap_client *);
+static void nfsdreopen_one(struct idmap_client *);
 static void nfsdreopen(void);
 
 size_t  strlcat(char *, const char *, size_t);
@@ -502,7 +503,8 @@ nfsdcb(int fd, short which, void *data)
 		xlog_warn("nfsdcb: read(%s) failed: errno %d (%s)",
 			     ic->ic_path, len?errno:0, 
 			     len?strerror(errno):"End of File");
-		goto out;
+		nfsdreopen_one(ic);
+		return;
 	}
 
 	/* Get rid of newline and terminate buffer*/
@@ -514,11 +516,11 @@ nfsdcb(int fd, short which, void *data)
 	/* Authentication name -- ignored for now*/
 	if (getfield(&bp, authbuf, sizeof(authbuf)) == -1) {
 		xlog_warn("nfsdcb: bad authentication name in upcall\n");
-		return;
+		goto out;
 	}
 	if (getfield(&bp, typebuf, sizeof(typebuf)) == -1) {
 		xlog_warn("nfsdcb: bad type in upcall\n");
-		return;
+		goto out;
 	}
 	if (verbose > 0)
 		xlog_warn("nfsdcb: authbuf=%s authtype=%s",
@@ -532,26 +534,26 @@ nfsdcb(int fd, short which, void *data)
 		im.im_conv = IDMAP_CONV_NAMETOID;
 		if (getfield(&bp, im.im_name, sizeof(im.im_name)) == -1) {
 			xlog_warn("nfsdcb: bad name in upcall\n");
-			return;
+			goto out;
 		}
 		break;
 	case IC_IDNAME:
 		im.im_conv = IDMAP_CONV_IDTONAME;
 		if (getfield(&bp, buf1, sizeof(buf1)) == -1) {
 			xlog_warn("nfsdcb: bad id in upcall\n");
-			return;
+			goto out;
 		}
 		tmp = strtoul(buf1, (char **)NULL, 10);
 		im.im_id = (u_int32_t)tmp;
 		if ((tmp == ULONG_MAX && errno == ERANGE)
 				|| (unsigned long)im.im_id != tmp) {
 			xlog_warn("nfsdcb: id '%s' too big!\n", buf1);
-			return;
+			goto out;
 		}
 		break;
 	default:
 		xlog_warn("nfsdcb: Unknown which type %d", ic->ic_which);
-		return;
+		goto out;
 	}
 
 	imconv(ic, &im);
@@ -612,7 +614,7 @@ nfsdcb(int fd, short which, void *data)
 		break;
 	default:
 		xlog_warn("nfsdcb: Unknown which type %d", ic->ic_which);
-		return;
+		goto out;
 	}
 
 	bsiz = sizeof(buf) - bsiz;
Signature · 1 line
1.5.5.6
#1 lore raw
Quoted 9 lines · Jeff Layton

A couple of years ago, Bruce committed a patch to make knfsd send unsigned uid's and gid's to idmapd, rather than signed values. Part of that earlier discussion is here:

http://linux-nfs.org/pipermail/nfsv4/2007-December/007321.html

While this fixed the immediate problem, it doesn't appear that anything was ever done to make idmapd continue working when it gets a bogus upcall.

Thanks for following up on this!

Quoted 35 lines

idmapd uses libevent for its main event handling loop. When idmapd gets an upcall from knfsd it will service the request and then rearm the event by calling event_add on the event structure again.

When it hits an error though, it returns in most cases w/o rearming the event. That prevents idmapd from servicing any further requests from knfsd.

I've made another change too. If an error is encountered while reading the channel file, this patch has it close and reopen the file prior to rearming the event.

I've not been able to test this patch directly, but I have tested a backport of it to earlier idmapd code and verified that it did prevent idmapd from hanging when it got a badly formatted upcall from knfsd.

---
 utils/idmapd/idmapd.c |   18 ++++++++++--------
 1 files changed, 10 insertions(+), 8 deletions(-)
utils/idmapd/idmapd.c +1 -0
index 65a6a2a..573abaa 100644
@@ -139,6 +139,7 @@ static void nametoidres(struct idmap_msg *);
 
 static int nfsdopen(void);
 static int nfsdopenone(struct idmap_client *);
+static void nfsdreopen_one(struct idmap_client *);
 static void nfsdreopen(void);
 
 size_t  strlcat(char *, const char *, size_t);

utils/idmapd/idmapd.c nfsdcb(int fd, short which, void *data) · line 507

Quoted 6 lines
utils/idmapd/idmapd.c +2 -1
@@ -502,7 +503,8 @@ nfsdcb(int fd, short which, void *data)
 		xlog_warn("nfsdcb: read(%s) failed: errno %d (%s)",
 			     ic->ic_path, len?errno:0, 
 			     len?strerror(errno):"End of File");
-		goto out;
+		nfsdreopen_one(ic);
+		return;

Why the "return"? From your description above ("... close and reopen the file prior to rearming the event"), I would have thought you'd want the final event_add() that's done at "out".

--b.

Quoted 64 lines
utils/idmapd/idmapd.c +7 -7
 	}
 
 	/* Get rid of newline and terminate buffer*/
@@ -514,11 +516,11 @@ nfsdcb(int fd, short which, void *data)
 	/* Authentication name -- ignored for now*/
 	if (getfield(&bp, authbuf, sizeof(authbuf)) == -1) {
 		xlog_warn("nfsdcb: bad authentication name in upcall\n");
-		return;
+		goto out;
 	}
 	if (getfield(&bp, typebuf, sizeof(typebuf)) == -1) {
 		xlog_warn("nfsdcb: bad type in upcall\n");
-		return;
+		goto out;
 	}
 	if (verbose > 0)
 		xlog_warn("nfsdcb: authbuf=%s authtype=%s",
@@ -532,26 +534,26 @@ nfsdcb(int fd, short which, void *data)
 		im.im_conv = IDMAP_CONV_NAMETOID;
 		if (getfield(&bp, im.im_name, sizeof(im.im_name)) == -1) {
 			xlog_warn("nfsdcb: bad name in upcall\n");
-			return;
+			goto out;
 		}
 		break;
 	case IC_IDNAME:
 		im.im_conv = IDMAP_CONV_IDTONAME;
 		if (getfield(&bp, buf1, sizeof(buf1)) == -1) {
 			xlog_warn("nfsdcb: bad id in upcall\n");
-			return;
+			goto out;
 		}
 		tmp = strtoul(buf1, (char **)NULL, 10);
 		im.im_id = (u_int32_t)tmp;
 		if ((tmp == ULONG_MAX && errno == ERANGE)
 				|| (unsigned long)im.im_id != tmp) {
 			xlog_warn("nfsdcb: id '%s' too big!\n", buf1);
-			return;
+			goto out;
 		}
 		break;
 	default:
 		xlog_warn("nfsdcb: Unknown which type %d", ic->ic_which);
-		return;
+		goto out;
 	}
 
 	imconv(ic, &im);
@@ -612,7 +614,7 @@ nfsdcb(int fd, short which, void *data)
 		break;
 	default:
 		xlog_warn("nfsdcb: Unknown which type %d", ic->ic_which);
-		return;
+		goto out;
 	}
 
 	bsiz = sizeof(buf) - bsiz;
Signature · 6 lines
1.5.5.6

_______________________________________________
NFSv4 mailing list
[email protected]
http://linux-nfs.org/cgi-bin/mailman/listinfo/nfsv4
#2 lore raw
Quoted 59 lines · On Thu, 10 Sep 2009 16:28:25 -0400 "J. Bruce Fields" <[email protected]>…
Quoted 9 lines · Jeff Layton

A couple of years ago, Bruce committed a patch to make knfsd send unsigned uid's and gid's to idmapd, rather than signed values. Part of that earlier discussion is here:

http://linux-nfs.org/pipermail/nfsv4/2007-December/007321.html

While this fixed the immediate problem, it doesn't appear that anything was ever done to make idmapd continue working when it gets a bogus upcall.

Thanks for following up on this!

Quoted 35 lines

idmapd uses libevent for its main event handling loop. When idmapd gets an upcall from knfsd it will service the request and then rearm the event by calling event_add on the event structure again.

When it hits an error though, it returns in most cases w/o rearming the event. That prevents idmapd from servicing any further requests from knfsd.

I've made another change too. If an error is encountered while reading the channel file, this patch has it close and reopen the file prior to rearming the event.

I've not been able to test this patch directly, but I have tested a backport of it to earlier idmapd code and verified that it did prevent idmapd from hanging when it got a badly formatted upcall from knfsd.

---
 utils/idmapd/idmapd.c |   18 ++++++++++--------
 1 files changed, 10 insertions(+), 8 deletions(-)
utils/idmapd/idmapd.c +1 -0
index 65a6a2a..573abaa 100644
@@ -139,6 +139,7 @@ static void nametoidres(struct idmap_msg *);
 
 static int nfsdopen(void);
 static int nfsdopenone(struct idmap_client *);
+static void nfsdreopen_one(struct idmap_client *);
 static void nfsdreopen(void);
 
 size_t  strlcat(char *, const char *, size_t);

utils/idmapd/idmapd.c nfsdcb(int fd, short which, void *data) · line 507

Quoted 6 lines
utils/idmapd/idmapd.c +2 -1
@@ -502,7 +503,8 @@ nfsdcb(int fd, short which, void *data)
 		xlog_warn("nfsdcb: read(%s) failed: errno %d (%s)",
 			     ic->ic_path, len?errno:0, 
 			     len?strerror(errno):"End of File");
-		goto out;
+		nfsdreopen_one(ic);
+		return;

Why the "return"? From your description above ("... close and reopen the file prior to rearming the event"), I would have thought you'd want the final event_add() that's done at "out".

Quoted 2 lines

--b.

Ahh yeah...it's not very clear from the patch, but nfsdreopen_one() rearms the event after reopening the file. Doing a return there should be correct.

Quoted 64 lines
Quoted 64 lines
utils/idmapd/idmapd.c +7 -7
 	}
 
 	/* Get rid of newline and terminate buffer*/
@@ -514,11 +516,11 @@ nfsdcb(int fd, short which, void *data)
 	/* Authentication name -- ignored for now*/
 	if (getfield(&bp, authbuf, sizeof(authbuf)) == -1) {
 		xlog_warn("nfsdcb: bad authentication name in upcall\n");
-		return;
+		goto out;
 	}
 	if (getfield(&bp, typebuf, sizeof(typebuf)) == -1) {
 		xlog_warn("nfsdcb: bad type in upcall\n");
-		return;
+		goto out;
 	}
 	if (verbose > 0)
 		xlog_warn("nfsdcb: authbuf=%s authtype=%s",
@@ -532,26 +534,26 @@ nfsdcb(int fd, short which, void *data)
 		im.im_conv = IDMAP_CONV_NAMETOID;
 		if (getfield(&bp, im.im_name, sizeof(im.im_name)) == -1) {
 			xlog_warn("nfsdcb: bad name in upcall\n");
-			return;
+			goto out;
 		}
 		break;
 	case IC_IDNAME:
 		im.im_conv = IDMAP_CONV_IDTONAME;
 		if (getfield(&bp, buf1, sizeof(buf1)) == -1) {
 			xlog_warn("nfsdcb: bad id in upcall\n");
-			return;
+			goto out;
 		}
 		tmp = strtoul(buf1, (char **)NULL, 10);
 		im.im_id = (u_int32_t)tmp;
 		if ((tmp == ULONG_MAX && errno == ERANGE)
 				|| (unsigned long)im.im_id != tmp) {
 			xlog_warn("nfsdcb: id '%s' too big!\n", buf1);
-			return;
+			goto out;
 		}
 		break;
 	default:
 		xlog_warn("nfsdcb: Unknown which type %d", ic->ic_which);
-		return;
+		goto out;
 	}
 
 	imconv(ic, &im);
@@ -612,7 +614,7 @@ nfsdcb(int fd, short which, void *data)
 		break;
 	default:
 		xlog_warn("nfsdcb: Unknown which type %d", ic->ic_which);
-		return;
+		goto out;
 	}
 
 	bsiz = sizeof(buf) - bsiz;
Signature · 6 lines
1.5.5.6

_______________________________________________
NFSv4 mailing list
[email protected]
http://linux-nfs.org/cgi-bin/mailman/listinfo/nfsv4
Signature · 1 line
Jeff Layton <[email protected]>

A message that is not in the archive (sent off-list or not yet received): 20090910170024.2853a48e-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org

#4 lore raw
Quoted 62 lines · Jeff Layton
Quoted 59 lines · On Thu, 10 Sep 2009 16:28:25 -0400 "J. Bruce Fields" <[email protected]>…
Quoted 9 lines · Jeff Layton

A couple of years ago, Bruce committed a patch to make knfsd send unsigned uid's and gid's to idmapd, rather than signed values. Part of that earlier discussion is here:

http://linux-nfs.org/pipermail/nfsv4/2007-December/007321.html

While this fixed the immediate problem, it doesn't appear that anything was ever done to make idmapd continue working when it gets a bogus upcall.

Thanks for following up on this!

Quoted 35 lines

idmapd uses libevent for its main event handling loop. When idmapd gets an upcall from knfsd it will service the request and then rearm the event by calling event_add on the event structure again.

When it hits an error though, it returns in most cases w/o rearming the event. That prevents idmapd from servicing any further requests from knfsd.

I've made another change too. If an error is encountered while reading the channel file, this patch has it close and reopen the file prior to rearming the event.

I've not been able to test this patch directly, but I have tested a backport of it to earlier idmapd code and verified that it did prevent idmapd from hanging when it got a badly formatted upcall from knfsd.

---
 utils/idmapd/idmapd.c |   18 ++++++++++--------
 1 files changed, 10 insertions(+), 8 deletions(-)
utils/idmapd/idmapd.c +1 -0
index 65a6a2a..573abaa 100644
@@ -139,6 +139,7 @@ static void nametoidres(struct idmap_msg *);
 
 static int nfsdopen(void);
 static int nfsdopenone(struct idmap_client *);
+static void nfsdreopen_one(struct idmap_client *);
 static void nfsdreopen(void);
 
 size_t  strlcat(char *, const char *, size_t);

utils/idmapd/idmapd.c nfsdcb(int fd, short which, void *data) · line 507

Quoted 6 lines
utils/idmapd/idmapd.c +2 -1
@@ -502,7 +503,8 @@ nfsdcb(int fd, short which, void *data)
 		xlog_warn("nfsdcb: read(%s) failed: errno %d (%s)",
 			     ic->ic_path, len?errno:0, 
 			     len?strerror(errno):"End of File");
-		goto out;
+		nfsdreopen_one(ic);
+		return;

Why the "return"? From your description above ("... close and reopen the file prior to rearming the event"), I would have thought you'd want the final event_add() that's done at "out".

Quoted 6 lines
Quoted 2 lines

--b.

Ahh yeah...it's not very clear from the patch, but nfsdreopen_one() rearms the event after reopening the file. Doing a return there should be correct.

OK, got it! Patch looks good to me.

--b.

Quoted 69 lines
Quoted 65 lines
Quoted 65 lines
utils/idmapd/idmapd.c +7 -7
 	}
 
 	/* Get rid of newline and terminate buffer*/
@@ -514,11 +516,11 @@ nfsdcb(int fd, short which, void *data)
 	/* Authentication name -- ignored for now*/
 	if (getfield(&bp, authbuf, sizeof(authbuf)) == -1) {
 		xlog_warn("nfsdcb: bad authentication name in upcall\n");
-		return;
+		goto out;
 	}
 	if (getfield(&bp, typebuf, sizeof(typebuf)) == -1) {
 		xlog_warn("nfsdcb: bad type in upcall\n");
-		return;
+		goto out;
 	}
 	if (verbose > 0)
 		xlog_warn("nfsdcb: authbuf=%s authtype=%s",
@@ -532,26 +534,26 @@ nfsdcb(int fd, short which, void *data)
 		im.im_conv = IDMAP_CONV_NAMETOID;
 		if (getfield(&bp, im.im_name, sizeof(im.im_name)) == -1) {
 			xlog_warn("nfsdcb: bad name in upcall\n");
-			return;
+			goto out;
 		}
 		break;
 	case IC_IDNAME:
 		im.im_conv = IDMAP_CONV_IDTONAME;
 		if (getfield(&bp, buf1, sizeof(buf1)) == -1) {
 			xlog_warn("nfsdcb: bad id in upcall\n");
-			return;
+			goto out;
 		}
 		tmp = strtoul(buf1, (char **)NULL, 10);
 		im.im_id = (u_int32_t)tmp;
 		if ((tmp == ULONG_MAX && errno == ERANGE)
 				|| (unsigned long)im.im_id != tmp) {
 			xlog_warn("nfsdcb: id '%s' too big!\n", buf1);
-			return;
+			goto out;
 		}
 		break;
 	default:
 		xlog_warn("nfsdcb: Unknown which type %d", ic->ic_which);
-		return;
+		goto out;
 	}
 
 	imconv(ic, &im);
@@ -612,7 +614,7 @@ nfsdcb(int fd, short which, void *data)
 		break;
 	default:
 		xlog_warn("nfsdcb: Unknown which type %d", ic->ic_which);
-		return;
+		goto out;
 	}
 
 	bsiz = sizeof(buf) - bsiz;
Signature · 6 lines
1.5.5.6

_______________________________________________
NFSv4 mailing list
[email protected]
http://linux-nfs.org/cgi-bin/mailman/listinfo/nfsv4
Signature · 1 line
Jeff Layton <[email protected]>
#5 lore raw

a question abount idmapd‏

hello,

I have a question about idmap. Should I send the mail to [email protected]? The question is as follows:

In Linux Kernel fs/nfs/idmap.c,
The
process will call rpc_queue_upcall in the nfs_idmap_id function, then it will wait on the waitqueue util the userspace write msg into the idmap rpc_pipe.

In userspace idmapd.c file,
the nfscb will read the rpc_pipe by aiomicio(read, ...), write the rpc_pipe by atomicio(write,...) in the end. my
question is : if the rpc.idmapd deamon is killed in the duration time
that between atomicio(read,.. ) and atomic(write,...), will the kernel
thread will always sleep on the wait_queue? That is to say, will the
rpc_queue_upcall be never return ?

thanks,
Best Regards,

_________________________________________________________________
Invite your mail contacts to join your friends list with Windows Live Spaces. It's easy!
http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.aspx&mkt=en-us

_______________________________________________
NFSv4 mailing list
[email protected]
http://linux-nfs.org/cgi-bin/mailman/listinfo/nfsv4

A message that is not in the archive (sent off-list or not yet received): [email protected]

#7 lore raw

Re: a question abount idmapd‏

Quoted 5 lines · hongpo gao

hello,

I have a question about idmap. Should I send the mail to [email protected]?

The linux-nfs mailing list is preferred over [email protected], if that's what you mean.

Quoted 7 lines

The question is as follows:

In Linux Kernel fs/nfs/idmap.c,
The process will call rpc_queue_upcall in the nfs_idmap_id function, then it will wait on the waitqueue util the userspace write msg into the idmap rpc_pipe.

Quoted 7 lines

In userspace idmapd.c file,
the nfscb will read the rpc_pipe by aiomicio(read, ...), write the rpc_pipe by atomicio(write,...) in the end.
my question is : if the rpc.idmapd deamon is killed in the duration time that between atomicio(read,.. ) and atomic(write,...), will the kernel thread will always sleep on the wait_queue? That is to say, will the rpc_queue_upcall be never return ?

No. The kernel tracks whether or not a daemon is listening on the other end of the rpc_pipe, and will therefore return an error should the above scenario happen.

Cheers
Trond

#8 lore raw
In reply to Jeff Layton
Quoted 22 lines · Jeff Layton

A couple of years ago, Bruce committed a patch to make knfsd send unsigned uid's and gid's to idmapd, rather than signed values. Part of that earlier discussion is here:

http://linux-nfs.org/pipermail/nfsv4/2007-December/007321.html

While this fixed the immediate problem, it doesn't appear that anything was ever done to make idmapd continue working when it gets a bogus upcall.

idmapd uses libevent for its main event handling loop. When idmapd gets an upcall from knfsd it will service the request and then rearm the event by calling event_add on the event structure again.

When it hits an error though, it returns in most cases w/o rearming the event. That prevents idmapd from servicing any further requests from knfsd.

I've made another change too. If an error is encountered while reading the channel file, this patch has it close and reopen the file prior to rearming the event.

Quoted 5 lines

I've not been able to test this patch directly, but I have tested a backport of it to earlier idmapd code and verified that it did prevent idmapd from hanging when it got a badly formatted upcall from knfsd.

Committed...

steved.