]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
ceph: hold i_ceph_lock when removing caps for freeing inode
authorYan, Zheng <zyan@redhat.com>
Thu, 23 May 2019 03:01:37 +0000 (11:01 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 4 Aug 2019 07:29:40 +0000 (09:29 +0200)
commit d6e47819721ae2d9d090058ad5570a66f3c42e39 upstream.

ceph_d_revalidate(, LOOKUP_RCU) may call __ceph_caps_issued_mask()
on a freeing inode.

Signed-off-by: "Yan, Zheng" <zyan@redhat.com>
Reviewed-by: Jeff Layton <jlayton@redhat.com>
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/ceph/caps.c
fs/ceph/inode.c
fs/ceph/super.h

index 0176241eaea7ef5f4ce4a1b01a19c91c5815dafe..7754d767912280472542191e8b38c47d497afc0f 100644 (file)
@@ -1263,20 +1263,22 @@ static int send_cap_msg(struct cap_msg_args *arg)
 }
 
 /*
- * Queue cap releases when an inode is dropped from our cache.  Since
- * inode is about to be destroyed, there is no need for i_ceph_lock.
+ * Queue cap releases when an inode is dropped from our cache.
  */
-void __ceph_remove_caps(struct inode *inode)
+void __ceph_remove_caps(struct ceph_inode_info *ci)
 {
-       struct ceph_inode_info *ci = ceph_inode(inode);
        struct rb_node *p;
 
+       /* lock i_ceph_lock, because ceph_d_revalidate(..., LOOKUP_RCU)
+        * may call __ceph_caps_issued_mask() on a freeing inode. */
+       spin_lock(&ci->i_ceph_lock);
        p = rb_first(&ci->i_caps);
        while (p) {
                struct ceph_cap *cap = rb_entry(p, struct ceph_cap, ci_node);
                p = rb_next(p);
                __ceph_remove_cap(cap, true);
        }
+       spin_unlock(&ci->i_ceph_lock);
 }
 
 /*
index 5b7d4881a4f88fcba53bda05d0cbad403d092305..3c7a32779574be8d69028701163275be448d54fd 100644 (file)
@@ -536,7 +536,7 @@ void ceph_evict_inode(struct inode *inode)
 
        ceph_fscache_unregister_inode_cookie(ci);
 
-       __ceph_remove_caps(inode);
+       __ceph_remove_caps(ci);
 
        if (__ceph_has_any_quota(ci))
                ceph_adjust_quota_realms_count(inode, false);
index 048409fba1a84b918a38aadebd17374a76648c15..edec39aa5ce209ce4bdc5b501c033c8ee3c083cc 100644 (file)
@@ -1000,7 +1000,7 @@ extern void ceph_add_cap(struct inode *inode,
                         unsigned cap, unsigned seq, u64 realmino, int flags,
                         struct ceph_cap **new_cap);
 extern void __ceph_remove_cap(struct ceph_cap *cap, bool queue_release);
-extern void __ceph_remove_caps(struct inode* inode);
+extern void __ceph_remove_caps(struct ceph_inode_info *ci);
 extern void ceph_put_cap(struct ceph_mds_client *mdsc,
                         struct ceph_cap *cap);
 extern int ceph_is_any_caps(struct inode *inode);