From 1073c04ca0f4edfbef3fe68e42933a988228f8de Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 3 Sep 2009 13:19:44 -0700 Subject: [PATCH] kclient: take inode ref on first WRBUFFER cap ref in set_page_dirty This only came up if the first dirty data on the inode was from an mmap write; the aio_write would grab a ref via the __take_cap_ref path first and grab the reference. Fix the put_cap_refs() too for consistency, even though that path isn't normally used (but theoretically could be?). --- src/kernel/addr.c | 2 ++ src/kernel/caps.c | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/kernel/addr.c b/src/kernel/addr.c index 89273c93aa9..a5dd43abc37 100644 --- a/src/kernel/addr.c +++ b/src/kernel/addr.c @@ -84,6 +84,8 @@ static int ceph_set_page_dirty(struct page *page) if (ci->i_wrbuffer_ref_head == 0) ci->i_head_snapc = ceph_get_snap_context(snapc); ++ci->i_wrbuffer_ref_head; + if (ci->i_wrbuffer_ref == 0) + igrab(inode); ++ci->i_wrbuffer_ref; dout("%p set_page_dirty %p idx %lu head %d/%d -> %d/%d " "snapc %p seq %lld (%d snaps)\n", diff --git a/src/kernel/caps.c b/src/kernel/caps.c index 2ce693430bb..b883e83679f 100644 --- a/src/kernel/caps.c +++ b/src/kernel/caps.c @@ -1950,7 +1950,7 @@ void ceph_get_cap_refs(struct ceph_inode_info *ci, int caps) void ceph_put_cap_refs(struct ceph_inode_info *ci, int had) { struct inode *inode = &ci->vfs_inode; - int last = 0, flushsnaps = 0, wake = 0; + int last = 0, put = 0, flushsnaps = 0, wake = 0; struct ceph_cap_snap *capsnap; spin_lock(&inode->i_lock); @@ -1963,8 +1963,10 @@ void ceph_put_cap_refs(struct ceph_inode_info *ci, int had) if (--ci->i_rdcache_ref == 0) last++; if (had & CEPH_CAP_FILE_BUFFER) { - if (--ci->i_wrbuffer_ref == 0) + if (--ci->i_wrbuffer_ref == 0) { last++; + put++; + } dout("put_cap_refs %p wrbuffer %d -> %d (?)\n", inode, ci->i_wrbuffer_ref+1, ci->i_wrbuffer_ref); } @@ -1995,6 +1997,8 @@ void ceph_put_cap_refs(struct ceph_inode_info *ci, int had) ceph_flush_snaps(ci); if (wake) wake_up(&ci->i_cap_wq); + if (put) + iput(inode); } /* -- 2.47.3