linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/5] NFSv4.1/pnfs: Ensure we handle delegation errors in nfs4_proc_layoutget()
@ 2016-06-10 15:49 Trond Myklebust
  2016-06-10 15:49 ` [PATCH 2/5] NFSv4.1/pnfs: Layout stateids start out as being invalid Trond Myklebust
  2016-06-10 20:05 ` [PATCH 1/5] NFSv4.1/pnfs: Ensure we handle delegation errors in nfs4_proc_layoutget() Jeff Layton
  0 siblings, 2 replies; 6+ messages in thread
From: Trond Myklebust @ 2016-06-10 15:49 UTC (permalink / raw)
  To: linux-nfs

nfs4_handle_exception() relies on the caller setting the 'inode' field
in the struct nfs4_exception argument when the error applies to a
delegation.

Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
---
 fs/nfs/nfs4proc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index de97567795a5..27fe63b502d5 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -8036,7 +8036,10 @@ nfs4_proc_layoutget(struct nfs4_layoutget *lgp, long *timeout, gfp_t gfp_flags)
 		.flags = RPC_TASK_ASYNC,
 	};
 	struct pnfs_layout_segment *lseg = NULL;
-	struct nfs4_exception exception = { .timeout = *timeout };
+	struct nfs4_exception exception = {
+		.inode = inode,
+		.timeout = *timeout,
+	};
 	int status = 0;
 
 	dprintk("--> %s\n", __func__);
-- 
2.5.5


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/5] NFSv4.1/pnfs: Layout stateids start out as being invalid
  2016-06-10 15:49 [PATCH 1/5] NFSv4.1/pnfs: Ensure we handle delegation errors in nfs4_proc_layoutget() Trond Myklebust
@ 2016-06-10 15:49 ` Trond Myklebust
  2016-06-10 15:49   ` [PATCH 3/5] NFSv4.1/pnfs: Add sparse lock annotations for pnfs_find_alloc_layout Trond Myklebust
  2016-06-10 20:05 ` [PATCH 1/5] NFSv4.1/pnfs: Ensure we handle delegation errors in nfs4_proc_layoutget() Jeff Layton
  1 sibling, 1 reply; 6+ messages in thread
From: Trond Myklebust @ 2016-06-10 15:49 UTC (permalink / raw)
  To: linux-nfs

Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
---
 fs/nfs/pnfs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
index 0c7e0d45a4de..f619139621ec 100644
--- a/fs/nfs/pnfs.c
+++ b/fs/nfs/pnfs.c
@@ -1290,6 +1290,7 @@ alloc_init_layout_hdr(struct inode *ino,
 	INIT_LIST_HEAD(&lo->plh_bulk_destroy);
 	lo->plh_inode = ino;
 	lo->plh_lc_cred = get_rpccred(ctx->cred);
+	lo->plh_flags |= 1 << NFS_LAYOUT_INVALID_STID;
 	return lo;
 }
 
@@ -1565,8 +1566,7 @@ lookup_again:
 	 * stateid, or it has been invalidated, then we must use the open
 	 * stateid.
 	 */
-	if (lo->plh_stateid.seqid == 0 ||
-	    test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags)) {
+	if (test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags)) {
 
 		/*
 		 * The first layoutget for the file. Need to serialize per
-- 
2.5.5


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/5] NFSv4.1/pnfs: Add sparse lock annotations for pnfs_find_alloc_layout
  2016-06-10 15:49 ` [PATCH 2/5] NFSv4.1/pnfs: Layout stateids start out as being invalid Trond Myklebust
@ 2016-06-10 15:49   ` Trond Myklebust
  2016-06-10 15:49     ` [PATCH 4/5] NFS/pnfs: handle bad delegation stateids in nfs4_layoutget_handle_exception Trond Myklebust
  0 siblings, 1 reply; 6+ messages in thread
From: Trond Myklebust @ 2016-06-10 15:49 UTC (permalink / raw)
  To: linux-nfs

Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
---
 fs/nfs/pnfs.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
index f619139621ec..ca488b52cbfb 100644
--- a/fs/nfs/pnfs.c
+++ b/fs/nfs/pnfs.c
@@ -1298,6 +1298,8 @@ static struct pnfs_layout_hdr *
 pnfs_find_alloc_layout(struct inode *ino,
 		       struct nfs_open_context *ctx,
 		       gfp_t gfp_flags)
+	__releases(&ino->i_lock)
+	__acquires(&ino->i_lock)
 {
 	struct nfs_inode *nfsi = NFS_I(ino);
 	struct pnfs_layout_hdr *new = NULL;
-- 
2.5.5


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/5] NFS/pnfs: handle bad delegation stateids in nfs4_layoutget_handle_exception
  2016-06-10 15:49   ` [PATCH 3/5] NFSv4.1/pnfs: Add sparse lock annotations for pnfs_find_alloc_layout Trond Myklebust
@ 2016-06-10 15:49     ` Trond Myklebust
  2016-06-10 15:49       ` [PATCH 5/5] NFS: Fix up O_DIRECT results Trond Myklebust
  0 siblings, 1 reply; 6+ messages in thread
From: Trond Myklebust @ 2016-06-10 15:49 UTC (permalink / raw)
  To: linux-nfs

We must call nfs4_handle_exception() on BAD_STATEID errors. The only
exception is if the stateid argument turns out to be a layout stateid
that is declared invalid.

Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
---
 fs/nfs/nfs4proc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 27fe63b502d5..406dd3eb68e2 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -7924,8 +7924,8 @@ nfs4_layoutget_handle_exception(struct rpc_task *task,
 			break;
 		}
 		lo = NFS_I(inode)->layout;
-		if (lo && nfs4_stateid_match(&lgp->args.stateid,
-					&lo->plh_stateid)) {
+		if (lo && !test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) &&
+		    nfs4_stateid_match_other(&lgp->args.stateid, &lo->plh_stateid)) {
 			LIST_HEAD(head);
 
 			/*
@@ -7936,10 +7936,10 @@ nfs4_layoutget_handle_exception(struct rpc_task *task,
 			pnfs_mark_matching_lsegs_invalid(lo, &head, NULL, 0);
 			spin_unlock(&inode->i_lock);
 			pnfs_free_lseg_list(&head);
+			status = -EAGAIN;
+			goto out;
 		} else
 			spin_unlock(&inode->i_lock);
-		status = -EAGAIN;
-		goto out;
 	}
 
 	status = nfs4_handle_exception(server, status, exception);
-- 
2.5.5


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 5/5] NFS: Fix up O_DIRECT results
  2016-06-10 15:49     ` [PATCH 4/5] NFS/pnfs: handle bad delegation stateids in nfs4_layoutget_handle_exception Trond Myklebust
@ 2016-06-10 15:49       ` Trond Myklebust
  0 siblings, 0 replies; 6+ messages in thread
From: Trond Myklebust @ 2016-06-10 15:49 UTC (permalink / raw)
  To: linux-nfs

if we read or wrote something, we must report it

Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
---
 fs/nfs/direct.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c
index 979b3c4dee6a..c7326c2af2c3 100644
--- a/fs/nfs/direct.c
+++ b/fs/nfs/direct.c
@@ -353,10 +353,12 @@ static ssize_t nfs_direct_wait(struct nfs_direct_req *dreq)
 
 	result = wait_for_completion_killable(&dreq->completion);
 
+	if (!result) {
+		result = dreq->count;
+		WARN_ON_ONCE(dreq->count < 0);
+	}
 	if (!result)
 		result = dreq->error;
-	if (!result)
-		result = dreq->count;
 
 out:
 	return (ssize_t) result;
@@ -386,8 +388,10 @@ static void nfs_direct_complete(struct nfs_direct_req *dreq, bool write)
 
 	if (dreq->iocb) {
 		long res = (long) dreq->error;
-		if (!res)
+		if (dreq->count != 0) {
 			res = (long) dreq->count;
+			WARN_ON_ONCE(dreq->count < 0);
+		}
 		dreq->iocb->ki_complete(dreq->iocb, res, 0);
 	}
 
-- 
2.5.5


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/5] NFSv4.1/pnfs: Ensure we handle delegation errors in nfs4_proc_layoutget()
  2016-06-10 15:49 [PATCH 1/5] NFSv4.1/pnfs: Ensure we handle delegation errors in nfs4_proc_layoutget() Trond Myklebust
  2016-06-10 15:49 ` [PATCH 2/5] NFSv4.1/pnfs: Layout stateids start out as being invalid Trond Myklebust
@ 2016-06-10 20:05 ` Jeff Layton
  1 sibling, 0 replies; 6+ messages in thread
From: Jeff Layton @ 2016-06-10 20:05 UTC (permalink / raw)
  To: Trond Myklebust, linux-nfs

On Fri, 2016-06-10 at 11:49 -0400, Trond Myklebust wrote:
> nfs4_handle_exception() relies on the caller setting the 'inode' field
> in the struct nfs4_exception argument when the error applies to a
> delegation.
> 
> Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
> ---
>  fs/nfs/nfs4proc.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
> index de97567795a5..27fe63b502d5 100644
> --- a/fs/nfs/nfs4proc.c
> +++ b/fs/nfs/nfs4proc.c
> @@ -8036,7 +8036,10 @@ nfs4_proc_layoutget(struct nfs4_layoutget *lgp, long *timeout, gfp_t gfp_flags)
>  		.flags = RPC_TASK_ASYNC,
>  	};
>  	struct pnfs_layout_segment *lseg = NULL;
> -	struct nfs4_exception exception = { .timeout = *timeout };
> +	struct nfs4_exception exception = {
> +		.inode = inode,
> +		.timeout = *timeout,
> +	};
>  	int status = 0;
>  
>  	dprintk("--> %s\n", __func__);

The whole set looks good to me. You can add this to all of them:

Reviewed-by: Jeff Layton <jlayton@poochiereds.net>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-06-10 20:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-10 15:49 [PATCH 1/5] NFSv4.1/pnfs: Ensure we handle delegation errors in nfs4_proc_layoutget() Trond Myklebust
2016-06-10 15:49 ` [PATCH 2/5] NFSv4.1/pnfs: Layout stateids start out as being invalid Trond Myklebust
2016-06-10 15:49   ` [PATCH 3/5] NFSv4.1/pnfs: Add sparse lock annotations for pnfs_find_alloc_layout Trond Myklebust
2016-06-10 15:49     ` [PATCH 4/5] NFS/pnfs: handle bad delegation stateids in nfs4_layoutget_handle_exception Trond Myklebust
2016-06-10 15:49       ` [PATCH 5/5] NFS: Fix up O_DIRECT results Trond Myklebust
2016-06-10 20:05 ` [PATCH 1/5] NFSv4.1/pnfs: Ensure we handle delegation errors in nfs4_proc_layoutget() Jeff Layton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).