All of lore.kernel.org
 help / color / mirror / Atom feed
From: Benny Halevy <bhalevy@panasas.com>
To: Trond Myklebust <Trond.Myklebust@netapp.com>
Cc: linux-nfs@vger.kernel.org, Boaz Harrosh <bharrosh@panasas.com>
Subject: [PATCH v6 04/26] NFSv4.1: purge deviceid cache on nfs_free_client
Date: Mon, 23 May 2011 19:34:55 +0300	[thread overview]
Message-ID: <1306168495-11079-1-git-send-email-bhalevy@panasas.com> (raw)
In-Reply-To: <4DDA8C3D.5080706@panasas.com>

Use the pnfs_layoutdriver_type both as a qualifier for the deviceid,
distinguishing deviceid from different layout types on the server,
and for freeing the layout-driver allocated structure containing the
nfs4_deviceid_node.

Signed-off-by: Benny Halevy <bhalevy@panasas.com>
---
 fs/nfs/client.c            |    2 +
 fs/nfs/nfs4filelayout.c    |    7 +++++
 fs/nfs/nfs4filelayout.h    |    1 +
 fs/nfs/nfs4filelayoutdev.c |    9 ++++---
 fs/nfs/pnfs.h              |   11 +++++++++
 fs/nfs/pnfs_dev.c          |   53 +++++++++++++++++++++++++++++++++++++++++--
 6 files changed, 76 insertions(+), 7 deletions(-)

diff --git a/fs/nfs/client.c b/fs/nfs/client.c
index 139be96..b3dc2b8 100644
--- a/fs/nfs/client.c
+++ b/fs/nfs/client.c
@@ -290,6 +290,8 @@ static void nfs_free_client(struct nfs_client *clp)
 	if (clp->cl_machine_cred != NULL)
 		put_rpccred(clp->cl_machine_cred);
 
+	nfs4_deviceid_purge_client(clp);
+
 	kfree(clp->cl_hostname);
 	kfree(clp);
 
diff --git a/fs/nfs/nfs4filelayout.c b/fs/nfs/nfs4filelayout.c
index c8e7afe..c181a8b 100644
--- a/fs/nfs/nfs4filelayout.c
+++ b/fs/nfs/nfs4filelayout.c
@@ -862,6 +862,12 @@ filelayout_commit_pagelist(struct inode *inode, struct list_head *mds_pages,
 	return -ENOMEM;
 }
 
+static void
+filelayout_free_deveiceid_node(struct nfs4_deviceid_node *d)
+{
+	nfs4_fl_free_deviceid(container_of(d, struct nfs4_file_layout_dsaddr, id_node));
+}
+
 static struct pnfs_layoutdriver_type filelayout_type = {
 	.id			= LAYOUT_NFSV4_1_FILES,
 	.name			= "LAYOUT_NFSV4_1_FILES",
@@ -874,6 +880,7 @@ static struct pnfs_layoutdriver_type filelayout_type = {
 	.commit_pagelist	= filelayout_commit_pagelist,
 	.read_pagelist		= filelayout_read_pagelist,
 	.write_pagelist		= filelayout_write_pagelist,
+	.free_deviceid_node	= filelayout_free_deveiceid_node,
 };
 
 static int __init nfs4filelayout_init(void)
diff --git a/fs/nfs/nfs4filelayout.h b/fs/nfs/nfs4filelayout.h
index 0ace0a2..cebe01e 100644
--- a/fs/nfs/nfs4filelayout.h
+++ b/fs/nfs/nfs4filelayout.h
@@ -98,6 +98,7 @@ u32 nfs4_fl_calc_ds_index(struct pnfs_layout_segment *lseg, u32 j);
 struct nfs4_pnfs_ds *nfs4_fl_prepare_ds(struct pnfs_layout_segment *lseg,
 					u32 ds_idx);
 extern void nfs4_fl_put_deviceid(struct nfs4_file_layout_dsaddr *dsaddr);
+extern void nfs4_fl_free_deviceid(struct nfs4_file_layout_dsaddr *dsaddr);
 struct nfs4_file_layout_dsaddr *
 get_device_info(struct inode *inode, struct nfs4_deviceid *dev_id, gfp_t gfp_flags);
 
diff --git a/fs/nfs/nfs4filelayoutdev.c b/fs/nfs/nfs4filelayoutdev.c
index eda4527..5914659 100644
--- a/fs/nfs/nfs4filelayoutdev.c
+++ b/fs/nfs/nfs4filelayoutdev.c
@@ -156,7 +156,7 @@ destroy_ds(struct nfs4_pnfs_ds *ds)
 	kfree(ds);
 }
 
-static void
+void
 nfs4_fl_free_deviceid(struct nfs4_file_layout_dsaddr *dsaddr)
 {
 	struct nfs4_pnfs_ds *ds;
@@ -386,7 +386,9 @@ decode_device(struct inode *ino, struct pnfs_device *pdev, gfp_t gfp_flags)
 	dsaddr->stripe_indices = stripe_indices;
 	stripe_indices = NULL;
 	dsaddr->ds_num = num;
-	nfs4_init_deviceid_node(&dsaddr->id_node, NFS_SERVER(ino)->nfs_client,
+	nfs4_init_deviceid_node(&dsaddr->id_node,
+				NFS_SERVER(ino)->pnfs_curr_ld,
+				NFS_SERVER(ino)->nfs_client,
 				&pdev->dev_id);
 
 	for (i = 0; i < dsaddr->ds_num; i++) {
@@ -548,8 +550,7 @@ out_free:
 void
 nfs4_fl_put_deviceid(struct nfs4_file_layout_dsaddr *dsaddr)
 {
-	if (nfs4_put_deviceid_node(&dsaddr->id_node))
-		nfs4_fl_free_deviceid(dsaddr);
+	nfs4_put_deviceid_node(&dsaddr->id_node);
 }
 
 /*
diff --git a/fs/nfs/pnfs.h b/fs/nfs/pnfs.h
index 3831ad0..9667a62 100644
--- a/fs/nfs/pnfs.h
+++ b/fs/nfs/pnfs.h
@@ -65,6 +65,8 @@ enum {
 	NFS_LAYOUT_DESTROYED,		/* no new use of layout allowed */
 };
 
+struct nfs4_deviceid_node;
+
 /* Per-layout driver specific registration structure */
 struct pnfs_layoutdriver_type {
 	struct list_head pnfs_tblid;
@@ -90,6 +92,8 @@ struct pnfs_layoutdriver_type {
 	 */
 	enum pnfs_try_status (*read_pagelist) (struct nfs_read_data *nfs_data);
 	enum pnfs_try_status (*write_pagelist) (struct nfs_write_data *nfs_data, int how);
+
+	void (*free_deviceid_node) (struct nfs4_deviceid_node *);
 };
 
 struct pnfs_layout_hdr {
@@ -160,6 +164,7 @@ int pnfs_layoutcommit_inode(struct inode *inode, bool sync);
 /* pnfs_dev.c */
 struct nfs4_deviceid_node {
 	struct hlist_node		node;
+	const struct pnfs_layoutdriver_type *ld;
 	const struct nfs_client		*nfs_client;
 	struct nfs4_deviceid		deviceid;
 	atomic_t			ref;
@@ -169,10 +174,12 @@ void nfs4_print_deviceid(const struct nfs4_deviceid *dev_id);
 struct nfs4_deviceid_node *nfs4_find_get_deviceid(const struct nfs_client *, const struct nfs4_deviceid *);
 struct nfs4_deviceid_node *nfs4_unhash_put_deviceid(const struct nfs_client *, const struct nfs4_deviceid *);
 void nfs4_init_deviceid_node(struct nfs4_deviceid_node *,
+			     const struct pnfs_layoutdriver_type *,
 			     const struct nfs_client *,
 			     const struct nfs4_deviceid *);
 struct nfs4_deviceid_node *nfs4_insert_deviceid_node(struct nfs4_deviceid_node *);
 bool nfs4_put_deviceid_node(struct nfs4_deviceid_node *);
+void nfs4_deviceid_purge_client(const struct nfs_client *);
 
 static inline int lo_fail_bit(u32 iomode)
 {
@@ -349,6 +356,10 @@ static inline int pnfs_layoutcommit_inode(struct inode *inode, bool sync)
 {
 	return 0;
 }
+
+static inline void nfs4_deviceid_purge_client(struct nfs_client *)
+{
+}
 #endif /* CONFIG_NFS_V4_1 */
 
 #endif /* FS_NFS_PNFS_H */
diff --git a/fs/nfs/pnfs_dev.c b/fs/nfs/pnfs_dev.c
index bf05189..3cd7854 100644
--- a/fs/nfs/pnfs_dev.c
+++ b/fs/nfs/pnfs_dev.c
@@ -96,11 +96,15 @@ EXPORT_SYMBOL_GPL(nfs4_find_get_deviceid);
 
 void
 nfs4_init_deviceid_node(struct nfs4_deviceid_node *d,
+			const struct pnfs_layoutdriver_type *ld,
 			const struct nfs_client *nfs_client,
 			const struct nfs4_deviceid *id)
 {
+	INIT_HLIST_NODE(&d->node);
+	d->ld = ld;
 	d->nfs_client = nfs_client;
 	d->deviceid = *id;
+	atomic_set(&d->ref, 1);
 }
 EXPORT_SYMBOL_GPL(nfs4_init_deviceid_node);
 
@@ -108,7 +112,10 @@ EXPORT_SYMBOL_GPL(nfs4_init_deviceid_node);
  * Uniquely initialize and insert a deviceid node into cache
  *
  * @new new deviceid node
- *      Note that the caller must set up new->nfs_client and new->deviceid
+ *      Note that the caller must set up the following members:
+ *        new->ld
+ *        new->nfs_client
+ *        new->deviceid
  *
  * @ret the inserted node, if none found, otherwise, the found entry.
  */
@@ -125,8 +132,6 @@ nfs4_insert_deviceid_node(struct nfs4_deviceid_node *new)
 		return d;
 	}
 
-	INIT_HLIST_NODE(&new->node);
-	atomic_set(&new->ref, 1);
 	hash = nfs4_deviceid_hash(&new->deviceid);
 	hlist_add_head_rcu(&new->node, &nfs4_deviceid_cache[hash]);
 	spin_unlock(&nfs4_deviceid_lock);
@@ -151,6 +156,48 @@ nfs4_put_deviceid_node(struct nfs4_deviceid_node *d)
 	hlist_del_init_rcu(&d->node);
 	spin_unlock(&nfs4_deviceid_lock);
 	synchronize_rcu();
+	if (d->ld->free_deviceid_node)
+		d->ld->free_deviceid_node(d);
 	return true;
 }
 EXPORT_SYMBOL_GPL(nfs4_put_deviceid_node);
+
+static void
+_deviceid_purge_client(const struct nfs_client *clp, long hash)
+{
+	struct nfs4_deviceid_node *d;
+	struct hlist_node *n, *next;
+	HLIST_HEAD(tmp);
+
+	rcu_read_lock();
+	hlist_for_each_entry_rcu(d, n, &nfs4_deviceid_cache[hash], node)
+		if (d->nfs_client == clp && atomic_read(&d->ref)) {
+			hlist_del_init_rcu(&d->node);
+			hlist_add_head(&d->node, &tmp);
+		}
+	rcu_read_unlock();
+
+	if (hlist_empty(&tmp))
+		return;
+
+	synchronize_rcu();
+	hlist_for_each_entry_safe(d, n, next, &tmp, node)
+		if (!atomic_dec_and_test(&d->ref)) {
+			if (d->ld->free_deviceid_node)
+				d->ld->free_deviceid_node(d);
+			else
+				kfree(d);
+		}
+}
+
+void
+nfs4_deviceid_purge_client(const struct nfs_client *clp)
+{
+	long h;
+
+	spin_lock(&nfs4_deviceid_lock);
+	for (h = 0; h < NFS4_DEVICE_ID_HASH_SIZE; h++)
+		_deviceid_purge_client(clp, h);
+	spin_unlock(&nfs4_deviceid_lock);
+}
+EXPORT_SYMBOL_GPL(nfs4_deviceid_purge_client);
-- 
1.7.3.4


  parent reply	other threads:[~2011-05-23 16:35 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-23 16:33 [PATCHSET v6 0/26] pnfs for 2.6.40 Benny Halevy
2011-05-23 16:34 ` [PATCH v6 01/26] NFSv4.1: use struct nfs_client to qualify deviceid Benny Halevy
2011-05-23 17:33   ` Benny Halevy
2011-05-23 16:34 ` [PATCH v6 02/26] pnfs: resolve header dependency in pnfs.h Benny Halevy
2011-05-23 16:34 ` [PATCH v6 03/26] NFSv4.1: make deviceid cache global Benny Halevy
2011-05-23 16:34 ` Benny Halevy [this message]
2011-05-23 17:21   ` [PATCH v6 04/26] NFSv4.1: purge deviceid cache on nfs_free_client Benny Halevy
2011-05-23 16:35 ` [PATCH v6 05/26] pnfs: CB_NOTIFY_DEVICEID Benny Halevy
2011-05-23 16:35 ` [PATCH v6 06/26] SUNRPC: introduce xdr_init_decode_pages Benny Halevy
2011-05-23 16:35 ` [PATCH v6 07/26] pnfs: Use byte-range for layoutget Benny Halevy
2011-05-23 16:35 ` [PATCH v6 08/26] pnfs: align layoutget requests on page boundaries Benny Halevy
2011-05-23 16:35 ` [PATCH v6 09/26] pnfs: Use byte-range for cb_layoutrecall Benny Halevy
2011-05-23 16:36 ` [PATCH v6 10/26] pnfs: client stats Benny Halevy
2011-05-23 16:36 ` [PATCH v6 11/26] pnfs-obj: objlayoutdriver module skeleton Benny Halevy
2011-05-23 16:36 ` [PATCH v6 12/26] pnfs-obj: pnfs_osd XDR definitions Benny Halevy
2011-05-23 16:36 ` [PATCH v6 13/26] pnfs-obj: pnfs_osd XDR client implementation Benny Halevy
2011-05-23 19:46   ` [PATCH] SQUASHME: pnf-obj xdr_cli: Wrong type in comments Boaz Harrosh
2011-05-23 16:37 ` [PATCH v6 14/26] pnfs-obj: decode layout, alloc/free lseg Benny Halevy
2011-05-23 19:45   ` [PATCH] SQUASHME: objio read/write patch: Bugs fixes Boaz Harrosh
2011-05-24 13:10     ` Benny Halevy
2011-05-24 14:37       ` Boaz Harrosh
2011-05-24 15:57         ` Benny Halevy
2011-05-24 16:04           ` Boaz Harrosh
2011-05-23 16:37 ` [PATCH v6 15/26] pnfs-obj: objio_osd device information retrieval and caching Benny Halevy
2011-05-23 16:37 ` [PATCH v6 16/26] NFSv4.1: use layout driver in global device cache Benny Halevy
2011-05-23 16:37 ` [PATCH v6 17/26] pnfs: alloc and free layout_hdr layoutdriver methods Benny Halevy
2011-05-23 16:37 ` [PATCH v6 18/26] pnfs-obj: define per-inode private structure Benny Halevy
2011-05-23 16:38 ` [PATCH v6 19/26] pnfs: support for non-rpc layout drivers Benny Halevy
2011-05-23 18:10   ` Boaz Harrosh
2011-05-23 19:22     ` Benny Halevy
2011-05-23 19:43       ` [PATCH] SQUASHME: into pnfs: pnfs: support for non-rpc layout drivers: de-ref not needed Boaz Harrosh
2011-05-23 16:38 ` [PATCH v6 20/26] pnfs-obj: osd raid engine read/write implementation Benny Halevy
2011-05-25 13:39   ` Boaz Harrosh
2011-05-25 13:41     ` [PATCH] SQUASHME: pnfs-obj: pg_test check for max_io_size Boaz Harrosh
2011-05-25 16:57       ` Benny Halevy
2011-05-23 16:38 ` [PATCH v6 21/26] pnfs: layoutreturn Benny Halevy
2011-05-25 16:07   ` [PATCH] SQUASHME: pnfs: Fix NULL dereference in the -ENOMEM path Boaz Harrosh
2011-05-25 16:12     ` Boaz Harrosh
2011-05-25 16:19     ` [PATCH V2] SQUASHME: pnfs: Fix NULL dereference and leak " Boaz Harrosh
2011-05-25 16:37       ` Boaz Harrosh
2011-05-25 16:47         ` Benny Halevy
2011-05-25 16:40     ` [PATCH V3] " Boaz Harrosh
2011-05-25 16:55       ` Benny Halevy
2011-05-23 16:38 ` [PATCH v6 22/26] pnfs: layoutret_on_setattr Benny Halevy
2011-05-23 16:38 ` [PATCH v6 23/26] pnfs: encode_layoutreturn Benny Halevy
2011-05-23 16:39 ` [PATCH v6 24/26] pnfs-obj: report errors and .encode_layoutreturn Implementation Benny Halevy
2011-05-23 16:39 ` [PATCH v6 25/26] pnfs: encode_layoutcommit Benny Halevy
2011-05-23 16:39 ` [PATCH v6 26/26] pnfs-obj: objlayout_encode_layoutcommit implementation Benny Halevy
2011-05-23 18:20 ` [PATCHSET v6 0/26] pnfs for 2.6.40 Boaz Harrosh
2011-05-23 18:50 ` Boaz Harrosh
2011-05-24 15:16   ` Benny Halevy
     [not found]     ` <2E1EB2CF9ED1CB4AA966F0EB76EAB443080D6E54@SACMVEXC2-PRD.hq.netapp.com>
2011-05-24 15:49       ` Benny Halevy
2011-05-24 17:07         ` Fred Isaman
2011-05-24 15:56       ` Boaz Harrosh
2011-05-24 16:21         ` Trond Myklebust
2011-05-24 16:58           ` Boaz Harrosh
2011-05-24 17:05             ` Trond Myklebust
2011-05-24 17:07               ` Boaz Harrosh

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=1306168495-11079-1-git-send-email-bhalevy@panasas.com \
    --to=bhalevy@panasas.com \
    --cc=Trond.Myklebust@netapp.com \
    --cc=bharrosh@panasas.com \
    --cc=linux-nfs@vger.kernel.org \
    /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.