aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYan, Zheng <zyan@redhat.com>2019-04-17 23:24:57 -0400
committerIlya Dryomov <idryomov@gmail.com>2019-04-23 15:37:54 -0400
commit37659182bff1eeaaeadcfc8f853c6d2b6dbc3f47 (patch)
tree131b20cb2308f0fbd8b411fdeaf49d97b9ff7aa1
parent4b8222870032715f9d995f3eb7c7acd8379a275d (diff)
ceph: fix ci->i_head_snapc leak
We missed two places that i_wrbuffer_ref_head, i_wr_ref, i_dirty_caps and i_flushing_caps may change. When they are all zeros, we should free i_head_snapc. Cc: stable@vger.kernel.org Link: https://tracker.ceph.com/issues/38224 Reported-and-tested-by: Luis Henriques <lhenriques@suse.com> Signed-off-by: "Yan, Zheng" <zyan@redhat.com> Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
-rw-r--r--fs/ceph/mds_client.c9
-rw-r--r--fs/ceph/snap.c7
2 files changed, 15 insertions, 1 deletions
diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index bc5d70d6bfe6..9049c2a3e972 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -1414,6 +1414,15 @@ static int remove_session_caps_cb(struct inode *inode, struct ceph_cap *cap,
1414 list_add(&ci->i_prealloc_cap_flush->i_list, &to_remove); 1414 list_add(&ci->i_prealloc_cap_flush->i_list, &to_remove);
1415 ci->i_prealloc_cap_flush = NULL; 1415 ci->i_prealloc_cap_flush = NULL;
1416 } 1416 }
1417
1418 if (drop &&
1419 ci->i_wrbuffer_ref_head == 0 &&
1420 ci->i_wr_ref == 0 &&
1421 ci->i_dirty_caps == 0 &&
1422 ci->i_flushing_caps == 0) {
1423 ceph_put_snap_context(ci->i_head_snapc);
1424 ci->i_head_snapc = NULL;
1425 }
1417 } 1426 }
1418 spin_unlock(&ci->i_ceph_lock); 1427 spin_unlock(&ci->i_ceph_lock);
1419 while (!list_empty(&to_remove)) { 1428 while (!list_empty(&to_remove)) {
diff --git a/fs/ceph/snap.c b/fs/ceph/snap.c
index 89aa37fa0f84..b26e12cd8ec3 100644
--- a/fs/ceph/snap.c
+++ b/fs/ceph/snap.c
@@ -572,7 +572,12 @@ void ceph_queue_cap_snap(struct ceph_inode_info *ci)
572 old_snapc = NULL; 572 old_snapc = NULL;
573 573
574update_snapc: 574update_snapc:
575 if (ci->i_head_snapc) { 575 if (ci->i_wrbuffer_ref_head == 0 &&
576 ci->i_wr_ref == 0 &&
577 ci->i_dirty_caps == 0 &&
578 ci->i_flushing_caps == 0) {
579 ci->i_head_snapc = NULL;
580 } else {
576 ci->i_head_snapc = ceph_get_snap_context(new_snapc); 581 ci->i_head_snapc = ceph_get_snap_context(new_snapc);
577 dout(" new snapc is %p\n", new_snapc); 582 dout(" new snapc is %p\n", new_snapc);
578 } 583 }