* [PATCH] Don't mark_inode_dirty_sync() while holding lock
@ 2011-04-12 21:17 Weston Andros Adamson
2011-04-12 22:23 ` Trond Myklebust
0 siblings, 1 reply; 3+ messages in thread
From: Weston Andros Adamson @ 2011-04-12 21:17 UTC (permalink / raw)
To: andros, trond; +Cc: linux-nfs, Weston Andros Adamson
mark_inode_dirty_sync() grabs the same inode lock!
race conditions between holding the lock in pnfs_set_layoutcommit() and in
mark_inode_dirty_sync() can result in a second call to pnfs_layoutcommit_inode(), but
this will be a noop as NFS_INO_LAYOUTCOMMIT won't be set in the second call
---
fs/nfs/pnfs.c | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
index d9ab972..d71997e 100644
--- a/fs/nfs/pnfs.c
+++ b/fs/nfs/pnfs.c
@@ -1004,6 +1004,7 @@ pnfs_set_layoutcommit(struct nfs_write_data *wdata)
{
struct nfs_inode *nfsi = NFS_I(wdata->inode);
loff_t end_pos = wdata->args.offset + wdata->res.count;
+ int mark_as_dirty = false;
spin_lock(&nfsi->vfs_inode.i_lock);
if (!test_and_set_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags)) {
@@ -1011,13 +1012,18 @@ pnfs_set_layoutcommit(struct nfs_write_data *wdata)
get_lseg(wdata->lseg);
wdata->lseg->pls_lc_cred =
get_rpccred(wdata->args.context->state->owner->so_cred);
- mark_inode_dirty_sync(wdata->inode);
+ mark_as_dirty = true;
dprintk("%s: Set layoutcommit for inode %lu ",
__func__, wdata->inode->i_ino);
}
if (end_pos > wdata->lseg->pls_end_pos)
wdata->lseg->pls_end_pos = end_pos;
spin_unlock(&nfsi->vfs_inode.i_lock);
+
+ /* if pnfs_layoutcommit_inode() runs between inode locks, the next one
+ * will be a noop because NFS_INO_LAYOUTCOMMIT will not be set */
+ if (mark_as_dirty)
+ mark_inode_dirty_sync(wdata->inode);
}
EXPORT_SYMBOL_GPL(pnfs_set_layoutcommit);
--
1.7.4.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Don't mark_inode_dirty_sync() while holding lock
2011-04-12 21:17 [PATCH] Don't mark_inode_dirty_sync() while holding lock Weston Andros Adamson
@ 2011-04-12 22:23 ` Trond Myklebust
0 siblings, 0 replies; 3+ messages in thread
From: Trond Myklebust @ 2011-04-12 22:23 UTC (permalink / raw)
To: Weston Andros Adamson; +Cc: andros, trond, linux-nfs
On Tue, 2011-04-12 at 17:17 -0400, Weston Andros Adamson wrote:
> mark_inode_dirty_sync() grabs the same inode lock!
>
> race conditions between holding the lock in pnfs_set_layoutcommit() and in
> mark_inode_dirty_sync() can result in a second call to pnfs_layoutcommit_inode(), but
> this will be a noop as NFS_INO_LAYOUTCOMMIT won't be set in the second call
I'm missing a "Signed-off-by:" here.
> ---
> fs/nfs/pnfs.c | 8 +++++++-
> 1 files changed, 7 insertions(+), 1 deletions(-)
>
> diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
> index d9ab972..d71997e 100644
> --- a/fs/nfs/pnfs.c
> +++ b/fs/nfs/pnfs.c
> @@ -1004,6 +1004,7 @@ pnfs_set_layoutcommit(struct nfs_write_data *wdata)
> {
> struct nfs_inode *nfsi = NFS_I(wdata->inode);
> loff_t end_pos = wdata->args.offset + wdata->res.count;
> + int mark_as_dirty = false;
Strictly speaking, an 'int' does not take values in the set 'true' and
'false'.
> spin_lock(&nfsi->vfs_inode.i_lock);
> if (!test_and_set_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags)) {
> @@ -1011,13 +1012,18 @@ pnfs_set_layoutcommit(struct nfs_write_data *wdata)
> get_lseg(wdata->lseg);
> wdata->lseg->pls_lc_cred =
> get_rpccred(wdata->args.context->state->owner->so_cred);
> - mark_inode_dirty_sync(wdata->inode);
> + mark_as_dirty = true;
> dprintk("%s: Set layoutcommit for inode %lu ",
> __func__, wdata->inode->i_ino);
> }
> if (end_pos > wdata->lseg->pls_end_pos)
> wdata->lseg->pls_end_pos = end_pos;
> spin_unlock(&nfsi->vfs_inode.i_lock);
> +
> + /* if pnfs_layoutcommit_inode() runs between inode locks, the next one
> + * will be a noop because NFS_INO_LAYOUTCOMMIT will not be set */
> + if (mark_as_dirty)
> + mark_inode_dirty_sync(wdata->inode);
> }
> EXPORT_SYMBOL_GPL(pnfs_set_layoutcommit);
Otherwise this looks fine. Please correct and resend.
--
Trond Myklebust
Linux NFS client maintainer
NetApp
Trond.Myklebust@netapp.com
www.netapp.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] Don't mark_inode_dirty_sync() while holding lock
@ 2011-04-13 14:53 Weston Andros Adamson
0 siblings, 0 replies; 3+ messages in thread
From: Weston Andros Adamson @ 2011-04-13 14:53 UTC (permalink / raw)
To: trond, andros; +Cc: linux-nfs, Weston Andros Adamson
mark_inode_dirty_sync() grabs the same inode lock!
race conditions between holding the lock in pnfs_set_layoutcommit() and in
mark_inode_dirty_sync() can result in a second call to pnfs_layoutcommit_inode(), but
this will be a noop as NFS_INO_LAYOUTCOMMIT won't be set in the second call
Signed-off-by: Weston Andros Adamson <dros@netapp.com>
---
fs/nfs/pnfs.c | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
index d9ab972..ff681ab 100644
--- a/fs/nfs/pnfs.c
+++ b/fs/nfs/pnfs.c
@@ -1004,6 +1004,7 @@ pnfs_set_layoutcommit(struct nfs_write_data *wdata)
{
struct nfs_inode *nfsi = NFS_I(wdata->inode);
loff_t end_pos = wdata->args.offset + wdata->res.count;
+ bool mark_as_dirty = false;
spin_lock(&nfsi->vfs_inode.i_lock);
if (!test_and_set_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags)) {
@@ -1011,13 +1012,18 @@ pnfs_set_layoutcommit(struct nfs_write_data *wdata)
get_lseg(wdata->lseg);
wdata->lseg->pls_lc_cred =
get_rpccred(wdata->args.context->state->owner->so_cred);
- mark_inode_dirty_sync(wdata->inode);
+ mark_as_dirty = true;
dprintk("%s: Set layoutcommit for inode %lu ",
__func__, wdata->inode->i_ino);
}
if (end_pos > wdata->lseg->pls_end_pos)
wdata->lseg->pls_end_pos = end_pos;
spin_unlock(&nfsi->vfs_inode.i_lock);
+
+ /* if pnfs_layoutcommit_inode() runs between inode locks, the next one
+ * will be a noop because NFS_INO_LAYOUTCOMMIT will not be set */
+ if (mark_as_dirty)
+ mark_inode_dirty_sync(wdata->inode);
}
EXPORT_SYMBOL_GPL(pnfs_set_layoutcommit);
--
1.7.4.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-04-13 14:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-12 21:17 [PATCH] Don't mark_inode_dirty_sync() while holding lock Weston Andros Adamson
2011-04-12 22:23 ` Trond Myklebust
-- strict thread matches above, loose matches on Subject: below --
2011-04-13 14:53 Weston Andros Adamson
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).