Skip to contentSkip to conversation

Fixed Regression in NFS Direct I/O path

PATCH Applied Steve Dickson 5 participants 8 messages Oct 28, 2010

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

PATCH 1/1 Fixed Regression in NFS Direct I/O path

A typo, introduced by commit f11ac8db, in the nfs_direct_write() routine causes writes with O_DIRECT set to fail with a ENOMEM error.

---
 fs/nfs/direct.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/nfs/direct.c +1 -1
index 064a809..84d3c8b 100644
@@ -873,7 +873,7 @@ static ssize_t nfs_direct_write(struct kiocb *iocb, const struct iovec *iov,
 	dreq->inode = inode;
 	dreq->ctx = get_nfs_open_context(nfs_file_open_context(iocb->ki_filp));
 	dreq->l_ctx = nfs_get_lock_context(dreq->ctx);
-	if (dreq->l_ctx != NULL)
+	if (dreq->l_ctx == NULL)
 		goto out_release;
 	if (!is_sync_kiocb(iocb))
 		dreq->iocb = iocb;
Signature · 1 line
1.7.2.3
#1 lore raw
Quoted 14 lines · On Thu, 28 Oct 2010 08:17:54 -0400 Steve Dickson <[email protected]> wrote:

A typo, introduced by commit f11ac8db, in the nfs_direct_write() routine causes writes with O_DIRECT set to fail with a ENOMEM error.

---
 fs/nfs/direct.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/nfs/direct.c +0 -0
index 064a809..84d3c8b 100644

fs/nfs/direct.c static ssize_t nfs_direct_write(struct kiocb *iocb, const struct iovec *iov, · line 879

Quoted 8 lines
fs/nfs/direct.c +1 -1
@@ -873,7 +873,7 @@ static ssize_t nfs_direct_write(struct kiocb *iocb, const struct iovec *iov,
 	dreq->inode = inode;
 	dreq->ctx = get_nfs_open_context(nfs_file_open_context(iocb->ki_filp));
 	dreq->l_ctx = nfs_get_lock_context(dreq->ctx);
-	if (dreq->l_ctx != NULL)
+	if (dreq->l_ctx == NULL)
 		goto out_release;
 	if (!is_sync_kiocb(iocb))
 		dreq->iocb = iocb;

Also, since get_lock_context holds references, this prevents the fs from being unmounted. It looks like this bug is in 2.6.36 too, so this may be suitable for stable series as well.

Signature · 1 line
Jeff Layton <[email protected]>
#2 lore raw
Quoted 21 lines · On Thu, 28 Oct 2010 08:34:35 -0400 Jeff Layton <[email protected]> wrote:
Quoted 18 lines · On Thu, 28 Oct 2010 08:17:54 -0400 Steve Dickson <[email protected]> wrote:

A typo, introduced by commit f11ac8db, in the nfs_direct_write() routine causes writes with O_DIRECT set to fail with a ENOMEM error.

---
 fs/nfs/direct.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/nfs/direct.c +0 -1
index 064a809..84d3c8b 100644
@@ -873,7 +873,7 @@ static ssize_t nfs_direct_write(struct kiocb *iocb, const struct iovec *iov,
 	dreq->inode = inode;
 	dreq->ctx = get_nfs_open_context(nfs_file_open_context(iocb->ki_filp));
 	dreq->l_ctx = nfs_get_lock_context(dreq->ctx);
-	if (dreq->l_ctx != NULL)
Quoted 9 lines

fs/nfs/direct.c static ssize_t nfs_direct_write(struct kiocb *iocb, const struct iovec *iov, · line 879

Quoted 4 lines
fs/nfs/direct.c +1 -0
+	if (dreq->l_ctx == NULL)
 		goto out_release;
 	if (!is_sync_kiocb(iocb))
 		dreq->iocb = iocb;

Also, since get_lock_context holds references, this prevents the fs from being unmounted. It looks like this bug is in 2.6.36 too, so this may be suitable for stable series as well.

Oh...and another thing I noticed too...

nfs_create_request doesn't check for a NULL return from nfs_get_lock_context. If it ever does, it looks like that will likely trickle down to an oops in encode_stateid.

It might be good to fix that as well. Maybe something like this compile-tested-only patch?

--------------------[snip]---------------------

nfs: handle lock context allocation failures in nfs_create_request

nfs_get_lock_context can return NULL on an allocation failure.

---
 fs/nfs/pagelist.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
fs/nfs/pagelist.c +7 -1
index 9194902..137b549 100644
@@ -65,6 +65,13 @@ nfs_create_request(struct nfs_open_context *ctx, struct inode *inode,
 	if (req == NULL)
 		return ERR_PTR(-ENOMEM);
 
+	/* get lock context early so we can deal with alloc failures */
+	req->wb_lock_context = nfs_get_lock_context(ctx);
+	if (req->wb_lock_context == NULL) {
+		nfs_page_free(req);
+		return ERR_PTR(-ENOMEM);
+	}
+
 	/* Initialize the request struct. Initially, we assume a
 	 * long write-back delay. This will be adjusted in
 	 * update_nfs_request below if the region is not locked. */
@@ -79,7 +86,6 @@ nfs_create_request(struct nfs_open_context *ctx, struct inode *inode,
 	req->wb_pgbase	= offset;
 	req->wb_bytes   = count;
 	req->wb_context = get_nfs_open_context(ctx);
-	req->wb_lock_context = nfs_get_lock_context(ctx);
 	kref_init(&req->wb_kref);
 	return req;
 }
Signature · 1 line
1.7.2.3
#3 lore raw
Quoted 73 lines · Jeff Layton
Quoted 21 lines · On Thu, 28 Oct 2010 08:34:35 -0400 Jeff Layton <[email protected]> wrote:
Quoted 18 lines · On Thu, 28 Oct 2010 08:17:54 -0400 Steve Dickson <[email protected]> wrote:

A typo, introduced by commit f11ac8db, in the nfs_direct_write() routine causes writes with O_DIRECT set to fail with a ENOMEM error.

---
 fs/nfs/direct.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/nfs/direct.c +0 -1
index 064a809..84d3c8b 100644
@@ -873,7 +873,7 @@ static ssize_t nfs_direct_write(struct kiocb *iocb, const struct iovec *iov,
 	dreq->inode = inode;
 	dreq->ctx = get_nfs_open_context(nfs_file_open_context(iocb->ki_filp));
 	dreq->l_ctx = nfs_get_lock_context(dreq->ctx);
-	if (dreq->l_ctx != NULL)
Quoted 9 lines

fs/nfs/direct.c static ssize_t nfs_direct_write(struct kiocb *iocb, const struct iovec *iov, · line 879

Quoted 4 lines
fs/nfs/direct.c +1 -0
+	if (dreq->l_ctx == NULL)
 		goto out_release;
 	if (!is_sync_kiocb(iocb))
 		dreq->iocb = iocb;

Also, since get_lock_context holds references, this prevents the fs from being unmounted. It looks like this bug is in 2.6.36 too, so this may be suitable for stable series as well.

Oh...and another thing I noticed too...

nfs_create_request doesn't check for a NULL return from nfs_get_lock_context. If it ever does, it looks like that will likely trickle down to an oops in encode_stateid.

It might be good to fix that as well. Maybe something like this compile-tested-only patch?

--------------------[snip]---------------------

nfs: handle lock context allocation failures in nfs_create_request

nfs_get_lock_context can return NULL on an allocation failure.

---
 fs/nfs/pagelist.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
fs/nfs/pagelist.c +7 -0
index 9194902..137b549 100644
@@ -65,6 +65,13 @@ nfs_create_request(struct nfs_open_context *ctx, struct inode *inode,
 	if (req == NULL)
 		return ERR_PTR(-ENOMEM);
 
+	/* get lock context early so we can deal with alloc failures */
+	req->wb_lock_context = nfs_get_lock_context(ctx);
+	if (req->wb_lock_context == NULL) {
+		nfs_page_free(req);
+		return ERR_PTR(-ENOMEM);
+	}
+
 	/* Initialize the request struct. Initially, we assume a
 	 * long write-back delay. This will be adjusted in
 	 * update_nfs_request below if the region is not locked. */

fs/nfs/pagelist.c nfs_create_request(struct nfs_open_context *ctx, struct inode *inode, · line 91

Quoted 7 lines
fs/nfs/pagelist.c +0 -1
@@ -79,7 +86,6 @@ nfs_create_request(struct nfs_open_context *ctx, struct inode *inode,
 	req->wb_pgbase	= offset;
 	req->wb_bytes   = count;
 	req->wb_context = get_nfs_open_context(ctx);
-	req->wb_lock_context = nfs_get_lock_context(ctx);
 	kref_init(&req->wb_kref);
 	return req;
 }

Yup. That looks as if it should be required...

Trond

#4 lore raw
Quoted 75 lines · On Thu, 28 Oct 2010 10:03:23 -0400 Trond Myklebust…
Quoted 74 lines · Jeff Layton
Quoted 21 lines · On Thu, 28 Oct 2010 08:34:35 -0400 Jeff Layton <[email protected]> wrote:
Quoted 18 lines · On Thu, 28 Oct 2010 08:17:54 -0400 Steve Dickson <[email protected]> wrote:

A typo, introduced by commit f11ac8db, in the nfs_direct_write() routine causes writes with O_DIRECT set to fail with a ENOMEM error.

---
 fs/nfs/direct.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/nfs/direct.c +0 -1
index 064a809..84d3c8b 100644
@@ -873,7 +873,7 @@ static ssize_t nfs_direct_write(struct kiocb *iocb, const struct iovec *iov,
 	dreq->inode = inode;
 	dreq->ctx = get_nfs_open_context(nfs_file_open_context(iocb->ki_filp));
 	dreq->l_ctx = nfs_get_lock_context(dreq->ctx);
-	if (dreq->l_ctx != NULL)
Quoted 9 lines

fs/nfs/direct.c static ssize_t nfs_direct_write(struct kiocb *iocb, const struct iovec *iov, · line 879

Quoted 4 lines
fs/nfs/direct.c +1 -0
+	if (dreq->l_ctx == NULL)
 		goto out_release;
 	if (!is_sync_kiocb(iocb))
 		dreq->iocb = iocb;

Also, since get_lock_context holds references, this prevents the fs from being unmounted. It looks like this bug is in 2.6.36 too, so this may be suitable for stable series as well.

Oh...and another thing I noticed too...

nfs_create_request doesn't check for a NULL return from nfs_get_lock_context. If it ever does, it looks like that will likely trickle down to an oops in encode_stateid.

It might be good to fix that as well. Maybe something like this compile-tested-only patch?

--------------------[snip]---------------------

nfs: handle lock context allocation failures in nfs_create_request

nfs_get_lock_context can return NULL on an allocation failure.

---
 fs/nfs/pagelist.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
fs/nfs/pagelist.c +7 -0
index 9194902..137b549 100644
@@ -65,6 +65,13 @@ nfs_create_request(struct nfs_open_context *ctx, struct inode *inode,
 	if (req == NULL)
 		return ERR_PTR(-ENOMEM);
 
+	/* get lock context early so we can deal with alloc failures */
+	req->wb_lock_context = nfs_get_lock_context(ctx);
+	if (req->wb_lock_context == NULL) {
+		nfs_page_free(req);
+		return ERR_PTR(-ENOMEM);
+	}
+
 	/* Initialize the request struct. Initially, we assume a
 	 * long write-back delay. This will be adjusted in
 	 * update_nfs_request below if the region is not locked. */
@@ -79,7 +86,6 @@ nfs_create_request(struct nfs_open_context *ctx, struct inode *inode,
 	req->wb_pgbase	= offset;
Quoted 9 lines

fs/nfs/pagelist.c nfs_create_request(struct nfs_open_context *ctx, struct inode *inode, · line 91

Quoted 6 lines
fs/nfs/pagelist.c +0 -1
 	req->wb_bytes   = count;
 	req->wb_context = get_nfs_open_context(ctx);
-	req->wb_lock_context = nfs_get_lock_context(ctx);
 	kref_init(&req->wb_kref);
 	return req;
 }

Yup. That looks as if it should be required...

Actually...Steve noticed this yesterday. I'll resend as an "official" patch separate from this thread...

Signature · 1 line
Jeff Layton <[email protected]>
#5 lore raw
In reply to Steve Dickson
Quoted 2 lines · Steve Dickson

A typo, introduced by commit f11ac8db, in the nfs_direct_write() routine causes writes with O_DIRECT set to fail with a ENOMEM error.

I guess someone should run xfstests on nfs more regularly :)

#6 lore raw
Quoted 5 lines · Christoph Hellwig
Quoted 2 lines · Steve Dickson

A typo, introduced by commit f11ac8db, in the nfs_direct_write() routine causes writes with O_DIRECT set to fail with a ENOMEM error.

I guess someone should run xfstests on nfs more regularly :)

Sigh, yes... I should set up a VM to run all the test suites on a regular basis...

Trond

#7 lore raw
In reply to Steve Dickson
Quoted 14 lines · Steve Dickson

A typo, introduced by commit f11ac8db, in the nfs_direct_write() routine causes writes with O_DIRECT set to fail with a ENOMEM error.

---
 fs/nfs/direct.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/nfs/direct.c +0 -0
index 064a809..84d3c8b 100644

fs/nfs/direct.c static ssize_t nfs_direct_write(struct kiocb *iocb, const struct iovec *iov, · line 879

Quoted 8 lines
fs/nfs/direct.c +1 -1
@@ -873,7 +873,7 @@ static ssize_t nfs_direct_write(struct kiocb *iocb, const struct iovec *iov,
 	dreq->inode = inode;
 	dreq->ctx = get_nfs_open_context(nfs_file_open_context(iocb->ki_filp));
 	dreq->l_ctx = nfs_get_lock_context(dreq->ctx);
-	if (dreq->l_ctx != NULL)
+	if (dreq->l_ctx == NULL)
 		goto out_release;
 	if (!is_sync_kiocb(iocb))
 		dreq->iocb = iocb;

Applied! Thanks!

Trond