summaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorZhi Zhang <zhang.david2011@gmail.com>2018-01-24 08:24:33 -0500
committerIlya Dryomov <idryomov@gmail.com>2018-02-26 10:19:16 -0500
commit6ef0bc6ddee1f62310877a1d53b1ea1d0d8e51a2 (patch)
treea4657907e7179ff8d0ffe81c26cae5911790bc41 /fs
parent4a3928c6f8a53fa1aed28ccba227742486e8ddcb (diff)
ceph: flush dirty caps of unlinked inode ASAP
Client should release unlinked inode from its cache ASAP. But client can't release inode with dirty caps. Link: http://tracker.ceph.com/issues/22886 Signed-off-by: Zhi Zhang <zhang.david2011@gmail.com> Reviewed-by: "Yan, Zheng" <zyan@redhat.com> Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/ceph/caps.c26
-rw-r--r--fs/ceph/dir.c28
-rw-r--r--fs/ceph/super.h2
3 files changed, 32 insertions, 24 deletions
diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c
index 6582c4507e6c..0e5bd3e3344e 100644
--- a/fs/ceph/caps.c
+++ b/fs/ceph/caps.c
@@ -3965,6 +3965,32 @@ void ceph_put_fmode(struct ceph_inode_info *ci, int fmode)
3965} 3965}
3966 3966
3967/* 3967/*
3968 * For a soon-to-be unlinked file, drop the AUTH_RDCACHE caps. If it
3969 * looks like the link count will hit 0, drop any other caps (other
3970 * than PIN) we don't specifically want (due to the file still being
3971 * open).
3972 */
3973int ceph_drop_caps_for_unlink(struct inode *inode)
3974{
3975 struct ceph_inode_info *ci = ceph_inode(inode);
3976 int drop = CEPH_CAP_LINK_SHARED | CEPH_CAP_LINK_EXCL;
3977
3978 spin_lock(&ci->i_ceph_lock);
3979 if (inode->i_nlink == 1) {
3980 drop |= ~(__ceph_caps_wanted(ci) | CEPH_CAP_PIN);
3981
3982 ci->i_ceph_flags |= CEPH_I_NODELAY;
3983 if (__ceph_caps_dirty(ci)) {
3984 struct ceph_mds_client *mdsc =
3985 ceph_inode_to_client(inode)->mdsc;
3986 __cap_delay_requeue_front(mdsc, ci);
3987 }
3988 }
3989 spin_unlock(&ci->i_ceph_lock);
3990 return drop;
3991}
3992
3993/*
3968 * Helpers for embedding cap and dentry lease releases into mds 3994 * Helpers for embedding cap and dentry lease releases into mds
3969 * requests. 3995 * requests.
3970 * 3996 *
diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
index 0c4346806e17..f1d9c6cc0491 100644
--- a/fs/ceph/dir.c
+++ b/fs/ceph/dir.c
@@ -1003,26 +1003,6 @@ static int ceph_link(struct dentry *old_dentry, struct inode *dir,
1003} 1003}
1004 1004
1005/* 1005/*
1006 * For a soon-to-be unlinked file, drop the AUTH_RDCACHE caps. If it
1007 * looks like the link count will hit 0, drop any other caps (other
1008 * than PIN) we don't specifically want (due to the file still being
1009 * open).
1010 */
1011static int drop_caps_for_unlink(struct inode *inode)
1012{
1013 struct ceph_inode_info *ci = ceph_inode(inode);
1014 int drop = CEPH_CAP_LINK_SHARED | CEPH_CAP_LINK_EXCL;
1015
1016 spin_lock(&ci->i_ceph_lock);
1017 if (inode->i_nlink == 1) {
1018 drop |= ~(__ceph_caps_wanted(ci) | CEPH_CAP_PIN);
1019 ci->i_ceph_flags |= CEPH_I_NODELAY;
1020 }
1021 spin_unlock(&ci->i_ceph_lock);
1022 return drop;
1023}
1024
1025/*
1026 * rmdir and unlink are differ only by the metadata op code 1006 * rmdir and unlink are differ only by the metadata op code
1027 */ 1007 */
1028static int ceph_unlink(struct inode *dir, struct dentry *dentry) 1008static int ceph_unlink(struct inode *dir, struct dentry *dentry)
@@ -1056,7 +1036,7 @@ static int ceph_unlink(struct inode *dir, struct dentry *dentry)
1056 set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags); 1036 set_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags);
1057 req->r_dentry_drop = CEPH_CAP_FILE_SHARED; 1037 req->r_dentry_drop = CEPH_CAP_FILE_SHARED;
1058 req->r_dentry_unless = CEPH_CAP_FILE_EXCL; 1038 req->r_dentry_unless = CEPH_CAP_FILE_EXCL;
1059 req->r_inode_drop = drop_caps_for_unlink(inode); 1039 req->r_inode_drop = ceph_drop_caps_for_unlink(inode);
1060 err = ceph_mdsc_do_request(mdsc, dir, req); 1040 err = ceph_mdsc_do_request(mdsc, dir, req);
1061 if (!err && !req->r_reply_info.head->is_dentry) 1041 if (!err && !req->r_reply_info.head->is_dentry)
1062 d_delete(dentry); 1042 d_delete(dentry);
@@ -1104,8 +1084,10 @@ static int ceph_rename(struct inode *old_dir, struct dentry *old_dentry,
1104 req->r_dentry_unless = CEPH_CAP_FILE_EXCL; 1084 req->r_dentry_unless = CEPH_CAP_FILE_EXCL;
1105 /* release LINK_RDCACHE on source inode (mds will lock it) */ 1085 /* release LINK_RDCACHE on source inode (mds will lock it) */
1106 req->r_old_inode_drop = CEPH_CAP_LINK_SHARED | CEPH_CAP_LINK_EXCL; 1086 req->r_old_inode_drop = CEPH_CAP_LINK_SHARED | CEPH_CAP_LINK_EXCL;
1107 if (d_really_is_positive(new_dentry)) 1087 if (d_really_is_positive(new_dentry)) {
1108 req->r_inode_drop = drop_caps_for_unlink(d_inode(new_dentry)); 1088 req->r_inode_drop =
1089 ceph_drop_caps_for_unlink(d_inode(new_dentry));
1090 }
1109 err = ceph_mdsc_do_request(mdsc, old_dir, req); 1091 err = ceph_mdsc_do_request(mdsc, old_dir, req);
1110 if (!err && !req->r_reply_info.head->is_dentry) { 1092 if (!err && !req->r_reply_info.head->is_dentry) {
1111 /* 1093 /*
diff --git a/fs/ceph/super.h b/fs/ceph/super.h
index 21b2e5b004eb..1c2086e0fec2 100644
--- a/fs/ceph/super.h
+++ b/fs/ceph/super.h
@@ -987,7 +987,7 @@ extern void ceph_check_caps(struct ceph_inode_info *ci, int flags,
987 struct ceph_mds_session *session); 987 struct ceph_mds_session *session);
988extern void ceph_check_delayed_caps(struct ceph_mds_client *mdsc); 988extern void ceph_check_delayed_caps(struct ceph_mds_client *mdsc);
989extern void ceph_flush_dirty_caps(struct ceph_mds_client *mdsc); 989extern void ceph_flush_dirty_caps(struct ceph_mds_client *mdsc);
990 990extern int ceph_drop_caps_for_unlink(struct inode *inode);
991extern int ceph_encode_inode_release(void **p, struct inode *inode, 991extern int ceph_encode_inode_release(void **p, struct inode *inode,
992 int mds, int drop, int unless, int force); 992 int mds, int drop, int unless, int force);
993extern int ceph_encode_dentry_release(void **p, struct dentry *dn, 993extern int ceph_encode_dentry_release(void **p, struct dentry *dn,