All of lore.kernel.org
 help / color / mirror / Atom feed
From: shaobingqing <shaobingqing@bwstor.com.cn>
To: trond.myklebust@primarydata.com
Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	shaobingqing <shaobingqing@bwstor.com.cn>
Subject: [PATCH v2] NFSv4.1: new layout stateid can not be overwrite by one out of date
Date: Wed, 12 Feb 2014 18:06:20 +0800	[thread overview]
Message-ID: <1392199580-14249-1-git-send-email-shaobingqing@bwstor.com.cn> (raw)
In-Reply-To: <N>

If initiate_file_draining returned NFS4ERR_DELAY, all the lsegs of
a file might be released before the retrying cb_layout request arriving
at the client. In this situation, layoutget request of the file will
use open stateid to obtain a new layout stateid. And if the retrying
cb_layout request arrived at the client after the layoutget reply,
new layout stateid would be overwrite by one out of date.

Signed-off-by: shaobingqing <shaobingqing@bwstor.com.cn>
---
 fs/nfs/callback.h      |    5 +++++
 fs/nfs/callback_proc.c |   24 ++++++++++++++++++++++++
 fs/nfs/inode.c         |    1 +
 include/linux/nfs_fs.h |    1 +
 4 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/fs/nfs/callback.h b/fs/nfs/callback.h
index 84326e9..213ded9 100644
--- a/fs/nfs/callback.h
+++ b/fs/nfs/callback.h
@@ -166,6 +166,11 @@ struct cb_layoutrecallargs {
 	};
 };
 
+struct cb_stalestatenode {
+	nfs4_stateid cbs_stateid;
+	struct list_head cb_stale_state;
+};
+
 extern __be32 nfs4_callback_layoutrecall(
 	struct cb_layoutrecallargs *args,
 	void *dummy, struct cb_process_state *cps);
diff --git a/fs/nfs/callback_proc.c b/fs/nfs/callback_proc.c
index ae2e87b..80bafbe 100644
--- a/fs/nfs/callback_proc.c
+++ b/fs/nfs/callback_proc.c
@@ -159,9 +159,16 @@ static u32 initiate_file_draining(struct nfs_client *clp,
 {
 	struct inode *ino;
 	struct pnfs_layout_hdr *lo;
+	struct cb_stalestatenode  *state_entry, *state_node;
+	struct cb_stalestatenode *tmp;
+	bool res;
 	u32 rv = NFS4ERR_NOMATCHING_LAYOUT;
 	LIST_HEAD(free_me_list);
 
+	state_node = kmalloc(sizeof(cb_stalestatenode), GFP_KERNEL);
+	if (!state_node)
+		return NFS4ERR_DELAY;
+
 	lo = get_layout_by_fh(clp, &args->cbl_fh);
 	if (!lo)
 		return NFS4ERR_NOMATCHING_LAYOUT;
@@ -174,7 +181,24 @@ static u32 initiate_file_draining(struct nfs_client *clp,
 		rv = NFS4ERR_DELAY;
 	else
 		rv = NFS4ERR_NOMATCHING_LAYOUT;
+	list_for_each_entry_safe(state_entry, tmp,
+			&NFS_I(ino)->cb_stale_state_list, cb_stale_state) {
+		if (memcmp(&args->cbl_stateid, &state_entry->cbs_stateid,
+				NFS4_STATEID_OTHER_SIZE) != 0)
+			continue;
+		if (rv == NFS4ERR_NOMATCHING_LAYOUT)
+			list_del(&state_entry->cb_stale_state);
+		goto unlock;
+	}
+	if (rv == NFS4ERR_DELAY) {
+		nfs4_stateid_copy(&state_node->cbs_stateid, &args->cbl_stateid);
+		list_add(&state_node->cb_stale_state,
+				&NFS_I(ino)->cb_stale_state_list);
+	} else {
+		kfree(state_node);
+	}
 	pnfs_set_layout_stateid(lo, &args->cbl_stateid, true);
+unlock:
 	spin_unlock(&ino->i_lock);
 	pnfs_free_lseg_list(&free_me_list);
 	pnfs_put_layout_hdr(lo);
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index eda8879..e2c881a 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -1643,6 +1643,7 @@ struct inode *nfs_alloc_inode(struct super_block *sb)
 		return NULL;
 	nfsi->flags = 0UL;
 	nfsi->cache_validity = 0UL;
+	INIT_LIST_HEAD(&nfsi->cb_stale_state_list);
 #ifdef CONFIG_NFS_V3_ACL
 	nfsi->acl_access = ERR_PTR(-EAGAIN);
 	nfsi->acl_default = ERR_PTR(-EAGAIN);
diff --git a/include/linux/nfs_fs.h b/include/linux/nfs_fs.h
index 3ea4cde..ba47870 100644
--- a/include/linux/nfs_fs.h
+++ b/include/linux/nfs_fs.h
@@ -181,6 +181,7 @@ struct nfs_inode {
 	struct nfs4_cached_acl	*nfs4_acl;
         /* NFSv4 state */
 	struct list_head	open_states;
+	struct list_head	cb_stale_state_list;
 	struct nfs_delegation __rcu *delegation;
 	fmode_t			 delegation_state;
 	struct rw_semaphore	rwsem;
-- 
1.7.4.2


  parent reply	other threads:[~2014-02-12 10:07 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <N>
2012-11-22 11:54 ` [PATCH 1/2] fs/buffer.c: do not inline exported function Yan Hong
2012-11-22 11:54   ` [PATCH 2/2] fs/buffer.c: remove redundant initialization in alloc_page_buffers() Yan Hong
2014-02-12 10:06 ` shaobingqing [this message]
2014-02-12 12:34   ` [PATCH v2] NFSv4.1: new layout stateid can not be overwrite by one out of date Trond Myklebust
2014-02-17  7:08 ` [PATCH v3] " shaobingqing
2014-02-17 16:46   ` Trond Myklebust
2014-07-11 10:35 ` [PATCH 1/2] f2fs: cleanup the needless return of f2fs_create_root_stats Gu Zheng
2014-07-11 10:35   ` [PATCH 2/2] f2fs: remove the unused stat_lock Gu Zheng
2014-10-22  4:16 ` [PATCH net-next 0/6] cleanup on resource check Varka Bhadram
2014-10-22  4:16   ` [PATCH net-next 1/6] ethernet: wiznet: remove unnecessary check Varka Bhadram
2014-10-22 11:43     ` Sergei Shtylyov
2014-10-22 12:23       ` Varka Bhadram
2014-10-22  4:16   ` [PATCH net-next 2/6] " Varka Bhadram
2014-10-22 11:44     ` Sergei Shtylyov
2014-10-22 12:24       ` Varka Bhadram
2014-10-22  4:16   ` [PATCH net-next 3/6] ethernet: apm: xgene: " Varka Bhadram
2014-10-22  4:16   ` [PATCH net-next 4/6] ethernet: marvell: " Varka Bhadram
2014-10-22  4:16   ` [PATCH net-next 5/6] ethernet: renesas: " Varka Bhadram
2014-10-22 11:47     ` Sergei Shtylyov
2014-10-22 12:22       ` Varka Bhadram
2014-10-22  4:16   ` [PATCH net-next 6/6] ethernet: samsung: sxgbe: " Varka Bhadram
2014-11-04  1:47 ` [PATCH usb v4 0/2] fixes on resource check varkabhadram
2014-11-04  1:47   ` [PATCH usb v4 1/2] host: uhci-platform: fix NULL pointer dereference on resource varkabhadram
2014-11-04  1:47   ` [PATCH usb v4 2/2] host: ehci-sead3: " varkabhadram
2020-08-18 15:20 ` [RFC PATCH 00/30] ima: Introduce IMA namespace krzysztof.struczynski
2020-08-18 15:20   ` [RFC PATCH 01/30] ima: Introduce ima namespace krzysztof.struczynski
2020-08-18 15:20   ` [RFC PATCH 02/30] ima: Add a list of the installed ima namespaces krzysztof.struczynski
2020-08-18 15:20   ` [RFC PATCH 03/30] ima: Bind ima namespace to the file descriptor krzysztof.struczynski
2020-08-18 15:20   ` [RFC PATCH 04/30] ima: Add ima policy related data to the ima namespace krzysztof.struczynski
2020-08-18 15:20   ` [RFC PATCH 05/30] ima: Add methods for parsing ima policy configuration string krzysztof.struczynski
2020-08-18 15:20   ` [RFC PATCH 06/30] ima: Add ima namespace to the ima subsystem APIs krzysztof.struczynski
2020-08-18 15:20   ` [RFC PATCH 07/30] ima: Extend the APIs in the integrity subsystem krzysztof.struczynski
2020-08-18 15:20   ` [RFC PATCH 08/30] ima: Add integrity inode related data to the ima namespace krzysztof.struczynski
2020-08-18 15:20   ` [RFC PATCH 09/30] ima: Enable per ima namespace policy settings krzysztof.struczynski
2020-08-18 15:53   ` [RFC PATCH 00/30] ima: Introduce IMA namespace Christian Brauner
2020-08-21 15:18     ` Krzysztof Struczynski
2020-08-18 16:19   ` James Bottomley
2020-08-21 15:13     ` Krzysztof Struczynski
2020-09-02 18:53       ` Mimi Zohar
2020-09-02 18:53         ` Mimi Zohar
2020-09-04 14:06         ` Dr. Greg
2020-09-04 14:06           ` Dr. Greg
2020-09-14 12:05         ` Krzysztof Struczynski
2020-09-14 12:05           ` Krzysztof Struczynski
2020-08-18 16:49   ` Christian Brauner
2020-08-21 15:37     ` Krzysztof Struczynski
2020-09-02 19:54     ` Mimi Zohar
2020-09-02 19:54       ` Mimi Zohar
2020-09-06 17:14       ` Dr. Greg
2020-09-06 17:14         ` Dr. Greg
2020-09-07 11:50         ` Luke Hinds
2020-09-08 14:03           ` Mimi Zohar
2020-09-08 14:03             ` Mimi Zohar
2020-09-14 12:07             ` Krzysztof Struczynski
2020-09-14 12:07               ` Krzysztof Struczynski
2020-10-19  9:30             ` Krzysztof Struczynski
2020-10-19  9:30               ` Krzysztof Struczynski
2020-10-25 15:00               ` Dr. Greg
2020-10-25 15:00                 ` Dr. Greg
2020-09-09 10:11           ` Dr. Greg
2020-09-09 10:11             ` Dr. Greg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1392199580-14249-1-git-send-email-shaobingqing@bwstor.com.cn \
    --to=shaobingqing@bwstor.com.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=trond.myklebust@primarydata.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.