From: Alexandros Batsakis <batsakis@netapp.com>
To: linux-nfs@vger.kernel.org
Cc: bhalevy@panasas.com, Alexandros Batsakis <batsakis@netapp.com>,
Fred Isaman <iisaman@netapp.com>
Subject: [PATCH 2/8] pnfs-submit: clean locking infrastructure
Date: Mon, 7 Jun 2010 14:11:47 -0700 [thread overview]
Message-ID: <1275945113-3436-3-git-send-email-batsakis@netapp.com> (raw)
In-Reply-To: <1275945113-3436-2-git-send-email-batsakis@netapp.com>
(also minor cleanup of pnfs_free_layout())
Signed-off-by: Alexandros Batsakis <batsakis@netapp.com>
Signed-off-by: Fred Isaman <iisaman@netapp.com>
---
fs/nfs/pnfs.c | 73 ++++++++++++++++++++++++++++++++++++--------------------
1 files changed, 47 insertions(+), 26 deletions(-)
diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
index 8620f68..b0a4bca 100644
--- a/fs/nfs/pnfs.c
+++ b/fs/nfs/pnfs.c
@@ -60,6 +60,8 @@ static int pnfs_initialized;
static void pnfs_free_layout(struct pnfs_layout_type *lo,
struct nfs4_pnfs_layout_segment *range);
static enum pnfs_try_status pnfs_commit(struct nfs_write_data *data, int sync);
+static inline void lock_current_layout(struct nfs_inode *nfsi);
+static inline void unlock_current_layout(struct nfs_inode *nfsi);
/* Locking:
*
@@ -152,15 +154,15 @@ void
pnfs_need_layoutcommit(struct nfs_inode *nfsi, struct nfs_open_context *ctx)
{
dprintk("%s: has_layout=%d ctx=%p\n", __func__, has_layout(nfsi), ctx);
- spin_lock(&nfsi->lo_lock);
+ lock_current_layout(nfsi);
if (has_layout(nfsi) && !layoutcommit_needed(nfsi)) {
nfsi->layout.lo_cred = get_rpccred(ctx->state->owner->so_cred);
nfsi->change_attr++;
- spin_unlock(&nfsi->lo_lock);
+ unlock_current_layout(nfsi);
dprintk("%s: Set layoutcommit\n", __func__);
return;
}
- spin_unlock(&nfsi->lo_lock);
+ unlock_current_layout(nfsi);
}
/* Update last_write_offset for layoutcommit.
@@ -173,7 +175,7 @@ pnfs_update_last_write(struct nfs_inode *nfsi, loff_t offset, size_t extent)
{
loff_t end_pos;
- spin_lock(&nfsi->lo_lock);
+ lock_current_layout(nfsi);
if (offset < nfsi->layout.pnfs_write_begin_pos)
nfsi->layout.pnfs_write_begin_pos = offset;
end_pos = offset + extent - 1; /* I'm being inclusive */
@@ -185,7 +187,7 @@ pnfs_update_last_write(struct nfs_inode *nfsi, loff_t offset, size_t extent)
(unsigned long) offset ,
(unsigned long) nfsi->layout.pnfs_write_begin_pos,
(unsigned long) nfsi->layout.pnfs_write_end_pos);
- spin_unlock(&nfsi->lo_lock);
+ unlock_current_layout(nfsi);
}
/* Unitialize a mountpoint in a layout driver */
@@ -312,6 +314,17 @@ pnfs_unregister_layoutdriver(struct pnfs_layoutdriver_type *ld_type)
#define BUG_ON_UNLOCKED_LO(lo) do {} while (0)
#endif /* CONFIG_SMP */
+static inline void lock_current_layout(struct nfs_inode *nfsi)
+{
+ spin_lock(&nfsi->lo_lock);
+}
+
+static inline void unlock_current_layout(struct nfs_inode *nfsi)
+{
+ BUG_ON_UNLOCKED_LO((&nfsi->layout));
+ spin_unlock(&nfsi->lo_lock);
+}
+
/*
* get and lock nfsi->layout
*/
@@ -320,10 +333,10 @@ get_lock_current_layout(struct nfs_inode *nfsi)
{
struct pnfs_layout_type *lo;
+ lock_current_layout(nfsi);
lo = &nfsi->layout;
- spin_lock(&nfsi->lo_lock);
if (!lo->ld_data) {
- spin_unlock(&nfsi->lo_lock);
+ unlock_current_layout(nfsi);
return NULL;
}
@@ -343,7 +356,12 @@ put_unlock_current_layout(struct pnfs_layout_type *lo)
BUG_ON_UNLOCKED_LO(lo);
BUG_ON(lo->refcount <= 0);
- if (--lo->refcount == 0 && list_empty(&lo->segs)) {
+ lo->refcount--;
+
+ if (lo->refcount > 0)
+ goto out;
+
+ if (list_empty(&lo->segs)) {
struct layoutdriver_io_operations *io_ops =
PNFS_LD_IO_OPS(lo);
@@ -357,7 +375,8 @@ put_unlock_current_layout(struct pnfs_layout_type *lo)
list_del_init(&nfsi->lo_inodes);
spin_unlock(&clp->cl_lock);
}
- spin_unlock(&nfsi->lo_lock);
+out:
+ unlock_current_layout(nfsi);
}
void
@@ -366,7 +385,7 @@ pnfs_layout_release(struct pnfs_layout_type *lo, atomic_t *count,
{
struct nfs_inode *nfsi = PNFS_NFS_INODE(lo);
- spin_lock(&nfsi->lo_lock);
+ lock_current_layout(nfsi);
if (range)
pnfs_free_layout(lo, range);
atomic_dec(count);
@@ -385,6 +404,8 @@ pnfs_destroy_layout(struct nfs_inode *nfsi)
};
lo = get_lock_current_layout(nfsi);
+ if (!lo)
+ return;
pnfs_free_layout(lo, &range);
put_unlock_current_layout(lo);
}
@@ -662,7 +683,7 @@ pnfs_return_layout_barrier(struct nfs_inode *nfsi,
struct pnfs_layout_segment *lseg;
bool ret = false;
- spin_lock(&nfsi->lo_lock);
+ lock_current_layout(nfsi);
list_for_each_entry (lseg, &nfsi->layout.segs, fi_list) {
if (!should_free_lseg(lseg, range))
continue;
@@ -676,7 +697,7 @@ pnfs_return_layout_barrier(struct nfs_inode *nfsi,
}
if (atomic_read(&nfsi->layout.lgetcount))
ret = true;
- spin_unlock(&nfsi->lo_lock);
+ unlock_current_layout(nfsi);
dprintk("%s:Return %d\n", __func__, ret);
return ret;
@@ -758,7 +779,7 @@ _pnfs_return_layout(struct inode *ino, struct nfs4_pnfs_layout_segment *range,
/* unlock w/o put rebalanced by eventual call to
* pnfs_layout_release
*/
- spin_unlock(&nfsi->lo_lock);
+ unlock_current_layout(nfsi);
if (pnfs_return_layout_barrier(nfsi, &arg)) {
dprintk("%s: waiting\n", __func__);
@@ -899,7 +920,7 @@ static int pnfs_wait_schedule(void *word)
*
* Note: If successful, nfsi->lo_lock is taken and the caller
* must put and unlock current_layout by using put_unlock_current_layout()
- * when the returned layout is released.
+ * directly or pnfs_layout_release() when the returned layout is released.
*/
static struct pnfs_layout_type *
get_lock_alloc_layout(struct inode *ino)
@@ -934,7 +955,7 @@ get_lock_alloc_layout(struct inode *ino)
struct nfs_client *clp = NFS_SERVER(ino)->nfs_client;
/* must grab the layout lock before the client lock */
- spin_lock(&nfsi->lo_lock);
+ lock_current_layout(nfsi);
spin_lock(&clp->cl_lock);
if (list_empty(&nfsi->lo_inodes))
@@ -1026,10 +1047,10 @@ void drain_layoutreturns(struct pnfs_layout_type *lo)
while (atomic_read(&lo->lretcount)) {
struct nfs_inode *nfsi = PNFS_NFS_INODE(lo);
- spin_unlock(&nfsi->lo_lock);
+ unlock_current_layout(nfsi);
dprintk("%s: waiting\n", __func__);
wait_event(nfsi->lo_waitq, (atomic_read(&lo->lretcount) == 0));
- spin_lock(&nfsi->lo_lock);
+ lock_current_layout(nfsi);
}
}
@@ -1068,13 +1089,13 @@ pnfs_update_layout(struct inode *ino,
/* Check to see if the layout for the given range already exists */
lseg = pnfs_has_layout(lo, &arg, take_ref, !take_ref);
if (lseg && !lseg->valid) {
- spin_unlock(&nfsi->lo_lock);
+ unlock_current_layout(nfsi);
if (take_ref)
put_lseg(lseg);
for (;;) {
prepare_to_wait(&nfsi->lo_waitq, &__wait,
TASK_KILLABLE);
- spin_lock(&nfsi->lo_lock);
+ lock_current_layout(nfsi);
lseg = pnfs_has_layout(lo, &arg, take_ref, !take_ref);
if (!lseg || lseg->valid)
break;
@@ -1087,7 +1108,7 @@ pnfs_update_layout(struct inode *ino,
result = -ERESTARTSYS;
break;
}
- spin_unlock(&nfsi->lo_lock);
+ unlock_current_layout(nfsi);
schedule();
}
finish_wait(&nfsi->lo_waitq, &__wait);
@@ -1124,7 +1145,7 @@ pnfs_update_layout(struct inode *ino,
/* Matching dec is done in .rpc_release (on non-error paths) */
atomic_inc(&lo->lgetcount);
/* Lose lock, but not reference, match this with pnfs_layout_release */
- spin_unlock(&nfsi->lo_lock);
+ unlock_current_layout(nfsi);
result = get_layout(ino, ctx, &arg, lsegpp, lo);
out:
@@ -1274,7 +1295,7 @@ pnfs_layout_process(struct nfs4_pnfs_layoutget *lgp)
*lgp->lsegpp = lseg;
}
- spin_lock(&nfsi->lo_lock);
+ lock_current_layout(nfsi);
pnfs_insert_layout(lo, lseg);
if (res->return_on_close) {
@@ -1285,7 +1306,7 @@ pnfs_layout_process(struct nfs4_pnfs_layoutget *lgp)
/* Done processing layoutget. Set the layout stateid */
pnfs_set_layout_stateid(lo, &res->stateid);
- spin_unlock(&nfsi->lo_lock);
+ unlock_current_layout(nfsi);
out:
return status;
}
@@ -2005,9 +2026,9 @@ pnfs_layoutcommit_inode(struct inode *inode, int sync)
if (!data)
return -ENOMEM;
- spin_lock(&nfsi->lo_lock);
+ lock_current_layout(nfsi);
if (!layoutcommit_needed(nfsi)) {
- spin_unlock(&nfsi->lo_lock);
+ unlock_current_layout(nfsi);
goto out_free;
}
@@ -2022,7 +2043,7 @@ pnfs_layoutcommit_inode(struct inode *inode, int sync)
nfsi->layout.lo_cred = NULL;
pnfs_get_layout_stateid(&data->args.stateid, &nfsi->layout);
- spin_unlock(&nfsi->lo_lock);
+ unlock_current_layout(nfsi);
/* Set up layout commit args */
status = pnfs_layoutcommit_setup(inode, data, write_begin_pos,
--
1.6.2.5
next prev parent reply other threads:[~2010-06-07 21:11 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-07 21:11 [PATCH 0/8] forgetful client v2 Alexandros Batsakis
2010-06-07 21:11 ` [PATCH 1/8] pnfs-submit: clean struct nfs_inode Alexandros Batsakis
2010-06-07 21:11 ` Alexandros Batsakis [this message]
2010-06-07 21:11 ` [PATCH 3/8] pnfs-submit: remove lgetcount, lretcount Alexandros Batsakis
2010-06-07 21:11 ` [PATCH 4/8] pnfs-submit: change stateid to be a union Alexandros Batsakis
2010-06-07 21:11 ` [PATCH 5/8] pnfs-submit: request whole-file layouts only Alexandros Batsakis
2010-06-07 21:11 ` [PATCH 6/8] pnfs-submit: change layout list to be similar to other state lists Alexandros Batsakis
2010-06-07 21:11 ` [PATCH 7/8] pnfs-submit: forgetful client (layouts) Alexandros Batsakis
2010-06-07 21:11 ` [PATCH 8/8] pnfs-submit: support for CB_RECALL_ANY (layouts) Alexandros Batsakis
2010-06-08 7:23 ` [PATCH 7/8] pnfs-submit: forgetful client (layouts) Benny Halevy
2010-06-08 7:51 ` Alexandros Batsakis
2010-06-08 9:15 ` Benny Halevy
2010-06-08 7:14 ` [PATCH 5/8] pnfs-submit: request whole-file layouts only Benny Halevy
2010-06-08 7:33 ` Alexandros Batsakis
2010-06-08 7:30 ` [PATCH 2/8] pnfs-submit: clean locking infrastructure Christoph Hellwig
2010-06-08 7:34 ` Benny Halevy
-- strict thread matches above, loose matches on Subject: below --
2010-05-17 17:56 [PATCH 0/8] pnfs-submit: Forgetful cleint and some layout cleanups Alexandros Batsakis
2010-05-17 17:56 ` [PATCH 1/8] pnfs-submit: clean struct nfs_inode Alexandros Batsakis
2010-05-17 17:56 ` [PATCH 2/8] pnfs-submit: clean locking infrastructure Alexandros Batsakis
2010-05-26 8:28 ` Benny Halevy
2010-05-28 17:27 ` Fred Isaman
[not found] ` <AANLkTinsHI0fHYdpUlq-MsMX0BmsLGvdAbrKx7M5ydjw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-05-28 18:27 ` Alexandros Batsakis
2010-05-05 17:00 [PATCH 0/8] pnfs-submit: forgetful client v2 Alexandros Batsakis
2010-05-05 17:00 ` [PATCH 1/8] pnfs-submit: clean struct nfs_inode Alexandros Batsakis
2010-05-05 17:00 ` [PATCH 2/8] pnfs-submit: clean locking infrastructure Alexandros Batsakis
2010-06-07 14:34 ` Fred Isaman
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=1275945113-3436-3-git-send-email-batsakis@netapp.com \
--to=batsakis@netapp.com \
--cc=bhalevy@panasas.com \
--cc=iisaman@netapp.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 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).