ceph: update the auth cap when the async create req is forwarded
cover ceph: update the auth cap when the async create req is forwarded
Xiubo Li (2):
ceph: make change_auth_cap_ses a global symbol
ceph: update the auth cap when the async create req is forwarded
fs/ceph/caps.c | 4 +-- fs/ceph/file.c | 12 +++++++++ fs/ceph/mds_client.c | 58 ++++++++++++++++++++++++++++++++++++++++++++ fs/ceph/super.h | 4 +++ 4 files changed, 76 insertions(+), 2 deletions(-)
Signature · 1 line
2.36.0.rc1
PATCH 1/2 ceph: make change_auth_cap_ses a global symbol
--- fs/ceph/caps.c | 4 ++-- fs/ceph/super.h | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-)
fs/ceph/caps.c +2 -2
@@ -602,8 +602,8 @@ static void __check_cap_issue(struct ceph_inode_info *ci, struct ceph_cap *cap,* @ci: inode to be moved * @session: new auth caps session */ -static void change_auth_cap_ses (struct ceph_inode_info *ci, -struct ceph_mds_session *session) +void change_auth_cap_ses (struct ceph_inode_info *ci, +struct ceph_mds_session *session) {lockdep_assert_held (&ci->i_ceph_lock);
fs/ceph/super.h +2 -0
@@ -774,6 +774,8 @@ extern void ceph_unreserve_caps(struct ceph_mds_client *mdsc,extern void ceph_reservation_status (struct ceph_fs_client *client,int *total,int *avail,int *used,int *reserved,int *min); +extern void change_auth_cap_ses (struct ceph_inode_info *ci, +struct ceph_mds_session *session);
Signature · 1 line
2.36.0.rc1
PATCH 2/2 ceph: update the auth cap when the async create req is forwarded
In reply to Xiubo LiFor async create we will always try to choose the auth MDS of frag the dentry belonged to of the parent directory to send the request and ususally this works fine, but if the MDS migrated the directory to another MDS before it could be handled the request will be forwarded. And then the auth cap will be changed.
We need to update the auth cap in this case before the request is forwarded.
URL: https://tracker.ceph.com/issues/55857
--- fs/ceph/file.c | 12 +++++++++ fs/ceph/mds_client.c | 58 ++++++++++++++++++++++++++++++++++++++++++++ fs/ceph/super.h | 2 ++ 3 files changed, 72 insertions(+)
fs/ceph/file.c +12 -0
@@ -613,6 +613,7 @@ static int ceph_finish_async_create(struct inode *dir, struct inode *inode,struct ceph_mds_reply_inode in = { };struct ceph_mds_reply_info_in iinfo = { .in = &in };struct ceph_inode_info *ci =ceph_inode (dir); +struct ceph_dentry_info *di =ceph_dentry (dentry);struct timespec64 now;struct ceph_string *pool_ns;struct ceph_mds_client *mdsc =ceph_sb_to_mdsc (dir->i_sb);
@@ -709,6 +710,12 @@ static int ceph_finish_async_create(struct inode *dir, struct inode *inode, file->f_mode |=FMODE_CREATED ; ret =finish_open (file, dentry, ceph_open); } + +spin_lock (&dentry->d_lock); + di->flags &= ~CEPH_DENTRY_ASYNC_CREATE ; +wake_up_bit (&di->flags,CEPH_DENTRY_ASYNC_CREATE_BIT ); +spin_unlock (&dentry->d_lock); +return ret; }
@@ -786,6 +793,7 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry, try_prep_async_create(dir, dentry, &lo, &req->r_deleg_ino))) {struct ceph_vino vino = { .ino = req->r_deleg_ino, .snap =CEPH_NOSNAP }; +struct ceph_dentry_info *di =ceph_dentry (dentry);set_bit (CEPH_MDS_R_ASYNC , &req->r_req_flags); req->r_args.open.flags |=cpu_to_le32 (CEPH_O_EXCL );
@@ -800,6 +808,10 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry, }WARN_ON_ONCE (!(new_inode->i_state &I_NEW )); +spin_lock (&dentry->d_lock); + di->flags |=CEPH_DENTRY_ASYNC_CREATE ; +spin_unlock (&dentry->d_lock); + err =ceph_mdsc_submit_request (mdsc, dir, req);if (!err) { err = ceph_finish_async_create(dir, new_inode, dentry,
fs/ceph/mds_client.c +58 -0
64 lines not on this page · raw message
fs/ceph/super.h +2 -0
@@ -304,6 +304,8 @@ struct ceph_dentry_info {#define CEPH_DENTRY_PRIMARY_LINK (1 << 3)#define CEPH_DENTRY_ASYNC_UNLINK_BIT (4)#define CEPH_DENTRY_ASYNC_UNLINK (1 << CEPH_DENTRY_ASYNC_UNLINK_BIT) +#define CEPH_DENTRY_ASYNC_CREATE_BIT (5) +#define CEPH_DENTRY_ASYNC_CREATE (1 << CEPH_DENTRY_ASYNC_CREATE_BIT)struct ceph_inode_xattrs_info {/*
Signature · 1 line
2.36.0.rc1
Quoted 30 lines · Xiubo Li
For async create we will always try to choose the auth MDS of frag the dentry belonged to of the parent directory to send the request and ususally this works fine, but if the MDS migrated the directory to another MDS before it could be handled the request will be forwarded. And then the auth cap will be changed.
We need to update the auth cap in this case before the request is forwarded.
URL: https://tracker.ceph.com/issues/55857
Signed-off-by Xiubo Li <[email protected]>--- fs/ceph/file.c | 12 +++++++++ fs/ceph/mds_client.c | 58 ++++++++++++++++++++++++++++++++++++++++++++ fs/ceph/super.h | 2 ++ 3 files changed, 72 insertions(+)fs/ceph/file.c +1
-0@@ -613,6 +613,7 @@ static int ceph_finish_async_create(struct inode *dir, struct inode *inode,struct ceph_mds_reply_inode in = { };struct ceph_mds_reply_info_in iinfo = { .in = &in };struct ceph_inode_info *ci =ceph_inode (dir); +struct ceph_dentry_info *di =ceph_dentry (dentry);struct timespec64 now;struct ceph_string *pool_ns;struct ceph_mds_client *mdsc =ceph_sb_to_mdsc (dir->i_sb);
fs/ceph/file.c static int ceph_finish_async_create(struct inode *dir, struct inode *inode, · line 717
Quoted 8 lines
fs/ceph/file.c +5
-0@@ -709,6 +710,12 @@ static int ceph_finish_async_create(struct inode *dir, struct inode *inode, file->f_mode |=FMODE_CREATED ; ret =finish_open (file, dentry, ceph_open); } + +spin_lock (&dentry->d_lock); + di->flags &= ~CEPH_DENTRY_ASYNC_CREATE ; +wake_up_bit (&di->flags,CEPH_DENTRY_ASYNC_CREATE_BIT ); +spin_unlock (&dentry->d_lock);
Question: shouldn't we initialise 'di' *after* grabbing ->d_lock? Ceph code doesn't seem to be consistent with this regard, but my understanding is that doing it this way is racy. And if so, some other places may need fixing.
Cheers,
Signature · 1 line
Luís
Quoted 109 lines
fs/ceph/file.c +6
-0+return ret; }@@ -786,6 +793,7 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry, try_prep_async_create(dir, dentry, &lo, &req->r_deleg_ino))) {struct ceph_vino vino = { .ino = req->r_deleg_ino, .snap =CEPH_NOSNAP }; +struct ceph_dentry_info *di =ceph_dentry (dentry);set_bit (CEPH_MDS_R_ASYNC , &req->r_req_flags); req->r_args.open.flags |=cpu_to_le32 (CEPH_O_EXCL );@@ -800,6 +808,10 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry, }WARN_ON_ONCE (!(new_inode->i_state &I_NEW )); +spin_lock (&dentry->d_lock); + di->flags |=CEPH_DENTRY_ASYNC_CREATE ; +spin_unlock (&dentry->d_lock); + err =ceph_mdsc_submit_request (mdsc, dir, req);if (!err) { err = ceph_finish_async_create(dir, new_inode, dentry,fs/ceph/mds_client.c +58
-0@@ -2993,6 +2993,64 @@ static void __do_request(struct ceph_mds_client *mdsc,if (req->r_request_started ==0 )/* note request start time */ req->r_request_started = jiffies; +/* +* For async create we will choose the auth MDS of frag in parent +* directory to send the request and ususally this works fine, but +* if the migrated the dirtory to another MDS before it could handle +* it the request will be forwarded. +* +* And then the auth cap will be changed. +*/ +if (test_bit (CEPH_MDS_R_ASYNC , &req->r_req_flags) && req->r_num_fwd) { +struct ceph_dentry_info *di =ceph_dentry (req->r_dentry); +struct ceph_inode_info *ci; +struct ceph_cap *cap; + +/* +* The request maybe handled very fast and the new inode +* hasn't been linked to the dentry yet. We need to wait +* for the ceph_finish_async_create(), which shouldn't be +* stuck too long or fail in thoery, to finish when forwarding +* the request. +*/ +if (!d_inode (req->r_dentry)) { + err =wait_on_bit (&di->flags,CEPH_DENTRY_ASYNC_CREATE_BIT , +TASK_KILLABLE ); +if (err) { +mutex_lock (&req->r_fill_mutex); +set_bit (CEPH_MDS_R_ABORTED , &req->r_req_flags); +mutex_unlock (&req->r_fill_mutex); + goto out_session; + } + } + + ci =ceph_inode (d_inode (req->r_dentry)); + +spin_lock (&ci->i_ceph_lock); + cap = ci->i_auth_cap; +if (ci->i_ceph_flags &CEPH_I_ASYNC_CREATE && mds != cap->mds) { +dout ("do_request session changed for auth cap %d -> %d\n" , + cap->session->s_mds, session->s_mds); + +/* Remove the auth cap from old session */ +spin_lock (&cap->session->s_cap_lock); + cap->session->s_nr_caps--; +list_del_init (&cap->session_caps); +spin_unlock (&cap->session->s_cap_lock); + +/* Add the auth cap to the new session */ + cap->mds = mds; + cap->session = session; +spin_lock (&session->s_cap_lock); + session->s_nr_caps++; +list_add_tail (&cap->session_caps, &session->s_caps); +spin_unlock (&session->s_cap_lock); + +change_auth_cap_ses (ci, session); + } +spin_unlock (&ci->i_ceph_lock); + } + err =__send_request (session, req, false); out_session:fs/ceph/super.h +2
-0@@ -304,6 +304,8 @@ struct ceph_dentry_info {#define CEPH_DENTRY_PRIMARY_LINK (1 << 3)#define CEPH_DENTRY_ASYNC_UNLINK_BIT (4)#define CEPH_DENTRY_ASYNC_UNLINK (1 << CEPH_DENTRY_ASYNC_UNLINK_BIT) +#define CEPH_DENTRY_ASYNC_CREATE_BIT (5) +#define CEPH_DENTRY_ASYNC_CREATE (1 << CEPH_DENTRY_ASYNC_CREATE_BIT)struct ceph_inode_xattrs_info {/* Signature · 1 line
2.36.0.rc1
Quoted 36 lines · Luís Henriques
Quoted 34 lines · Xiubo Li
For async create we will always try to choose the auth MDS of frag the dentry belonged to of the parent directory to send the request and ususally this works fine, but if the MDS migrated the directory to another MDS before it could be handled the request will be forwarded. And then the auth cap will be changed.
We need to update the auth cap in this case before the request is forwarded.
URL: https://tracker.ceph.com/issues/55857
Signed-off-by Xiubo Li <[email protected]>--- fs/ceph/file.c | 12 +++++++++ fs/ceph/mds_client.c | 58 ++++++++++++++++++++++++++++++++++++++++++++ fs/ceph/super.h | 2 ++ 3 files changed, 72 insertions(+)fs/ceph/file.c +2
-0@@ -613,6 +613,7 @@ static int ceph_finish_async_create(struct inode *dir, struct inode *inode,struct ceph_mds_reply_inode in = { };struct ceph_mds_reply_info_in iinfo = { .in = &in };struct ceph_inode_info *ci =ceph_inode (dir); +struct ceph_dentry_info *di =ceph_dentry (dentry);struct timespec64 now;struct ceph_string *pool_ns;struct ceph_mds_client *mdsc =ceph_sb_to_mdsc (dir->i_sb);@@ -709,6 +710,12 @@ static int ceph_finish_async_create(struct inode *dir, struct inode *inode, file->f_mode |=FMODE_CREATED ; ret =finish_open (file, dentry, ceph_open); } +
Quoted 8 lines
fs/ceph/file.c static int ceph_finish_async_create(struct inode *dir, struct inode *inode, · line 717
Quoted 4 lines
fs/ceph/file.c +4
-0+spin_lock (&dentry->d_lock); + di->flags &= ~CEPH_DENTRY_ASYNC_CREATE ; +wake_up_bit (&di->flags,CEPH_DENTRY_ASYNC_CREATE_BIT ); +spin_unlock (&dentry->d_lock);Question: shouldn't we initialise 'di' *after* grabbing ->d_lock? Ceph code doesn't seem to be consistent with this regard, but my understanding is that doing it this way is racy. And if so, some other places may need fixing.
Yeah, it should be.
BTW, do you mean some where like this:
if (!test_bit(CEPH_DENTRY_ASYNC_UNLINK_BIT, &di->flags))
?
If so, it's okay and no issue here.
-- Xiubo
Quoted 1 line
Cheers,
Quoted 48 lines · Xiubo Li
Quoted 36 lines · Luís Henriques
Quoted 34 lines · Xiubo Li
For async create we will always try to choose the auth MDS of frag the dentry belonged to of the parent directory to send the request and ususally this works fine, but if the MDS migrated the directory to another MDS before it could be handled the request will be forwarded. And then the auth cap will be changed.
We need to update the auth cap in this case before the request is forwarded.
URL: https://tracker.ceph.com/issues/55857
Signed-off-by Xiubo Li <[email protected]>--- fs/ceph/file.c | 12 +++++++++ fs/ceph/mds_client.c | 58 ++++++++++++++++++++++++++++++++++++++++++++ fs/ceph/super.h | 2 ++ 3 files changed, 72 insertions(+)fs/ceph/file.c +2
-0@@ -613,6 +613,7 @@ static int ceph_finish_async_create(struct inode *dir, struct inode *inode,struct ceph_mds_reply_inode in = { };struct ceph_mds_reply_info_in iinfo = { .in = &in };struct ceph_inode_info *ci =ceph_inode (dir); +struct ceph_dentry_info *di =ceph_dentry (dentry);struct timespec64 now;struct ceph_string *pool_ns;struct ceph_mds_client *mdsc =ceph_sb_to_mdsc (dir->i_sb);@@ -709,6 +710,12 @@ static int ceph_finish_async_create(struct inode *dir, struct inode *inode, file->f_mode |=FMODE_CREATED ; ret =finish_open (file, dentry, ceph_open); } +Quoted 8 lines
fs/ceph/file.c static int ceph_finish_async_create(struct inode *dir, struct inode *inode, · line 717
Quoted 4 lines
fs/ceph/file.c +4
-0+spin_lock (&dentry->d_lock); + di->flags &= ~CEPH_DENTRY_ASYNC_CREATE ; +wake_up_bit (&di->flags,CEPH_DENTRY_ASYNC_CREATE_BIT ); +spin_unlock (&dentry->d_lock);Question: shouldn't we initialise 'di' *after* grabbing ->d_lock? Ceph code doesn't seem to be consistent with this regard, but my understanding is that doing it this way is racy. And if so, some other places may need fixing.
Yeah, it should be.
Quoted 7 lines
BTW, do you mean some where like this:
if (!test_bit(CEPH_DENTRY_ASYNC_UNLINK_BIT,
&di->flags))?
If so, it's okay and no issue here.
No, I meant patterns like the one above, where you initialize a pointer to a struct ceph_dentry_info (from ->d_fsdata) and then grab ->d_lock. For example, in splice_dentry(). I think there are a few other places where this pattern can be seen, even in other filesystems. So maybe it's not really an issue, and that's why I asked: does this lock really protects accesses to ->d_fsdata?
Cheers,
Signature · 1 line
Luís
Quoted 55 lines · Luís Henriques
Quoted 53 lines · Xiubo Li
Quoted 36 lines · Luís Henriques
Quoted 34 lines · Xiubo Li
For async create we will always try to choose the auth MDS of frag the dentry belonged to of the parent directory to send the request and ususally this works fine, but if the MDS migrated the directory to another MDS before it could be handled the request will be forwarded. And then the auth cap will be changed.
We need to update the auth cap in this case before the request is forwarded.
URL: https://tracker.ceph.com/issues/55857
Signed-off-by Xiubo Li <[email protected]>--- fs/ceph/file.c | 12 +++++++++ fs/ceph/mds_client.c | 58 ++++++++++++++++++++++++++++++++++++++++++++ fs/ceph/super.h | 2 ++ 3 files changed, 72 insertions(+)fs/ceph/file.c +2
-0@@ -613,6 +613,7 @@ static int ceph_finish_async_create(struct inode *dir, struct inode *inode,struct ceph_mds_reply_inode in = { };struct ceph_mds_reply_info_in iinfo = { .in = &in };struct ceph_inode_info *ci =ceph_inode (dir); +struct ceph_dentry_info *di =ceph_dentry (dentry);struct timespec64 now;struct ceph_string *pool_ns;struct ceph_mds_client *mdsc =ceph_sb_to_mdsc (dir->i_sb);@@ -709,6 +710,12 @@ static int ceph_finish_async_create(struct inode *dir, struct inode *inode, file->f_mode |=FMODE_CREATED ; ret =finish_open (file, dentry, ceph_open); } +Quoted 8 lines
fs/ceph/file.c static int ceph_finish_async_create(struct inode *dir, struct inode *inode, · line 717
Quoted 4 lines
fs/ceph/file.c +4
-0+spin_lock (&dentry->d_lock); + di->flags &= ~CEPH_DENTRY_ASYNC_CREATE ; +wake_up_bit (&di->flags,CEPH_DENTRY_ASYNC_CREATE_BIT ); +spin_unlock (&dentry->d_lock);Question: shouldn't we initialise 'di' *after* grabbing ->d_lock? Ceph code doesn't seem to be consistent with this regard, but my understanding is that doing it this way is racy. And if so, some other places may need fixing.
Yeah, it should be.
BTW, do you mean some where like this:
if (!test_bit(CEPH_DENTRY_ASYNC_UNLINK_BIT,
&di->flags))?
Quoted 7 lines
Quoted 1 line
If so, it's okay and no issue here.
No, I meant patterns like the one above, where you initialize a pointer to a struct
ceph_dentry_info(from ->d_fsdata) and then grab ->d_lock. For example, insplice_dentry(). I think there are a few other places where this pattern can be seen, even in other filesystems. So maybe it's not really an issue, and that's why I asked: does this lock really protects accesses to ->d_fsdata?
Okay, get it.
I think it should be okay, the dentry reference has been increased during these. In theory the ->d_fsdata shouldn't be released while we are accessing it if I didn't miss something important.
-- Xiubo
Quoted 2 lines
Cheers,
Quoted 36 lines · Luís Henriques
Quoted 34 lines · Xiubo Li
For async create we will always try to choose the auth MDS of frag the dentry belonged to of the parent directory to send the request and ususally this works fine, but if the MDS migrated the directory to another MDS before it could be handled the request will be forwarded. And then the auth cap will be changed.
We need to update the auth cap in this case before the request is forwarded.
URL: https://tracker.ceph.com/issues/55857
Signed-off-by Xiubo Li <[email protected]>--- fs/ceph/file.c | 12 +++++++++ fs/ceph/mds_client.c | 58 ++++++++++++++++++++++++++++++++++++++++++++ fs/ceph/super.h | 2 ++ 3 files changed, 72 insertions(+)fs/ceph/file.c +2
-0@@ -613,6 +613,7 @@ static int ceph_finish_async_create(struct inode *dir, struct inode *inode,struct ceph_mds_reply_inode in = { };struct ceph_mds_reply_info_in iinfo = { .in = &in };struct ceph_inode_info *ci =ceph_inode (dir); +struct ceph_dentry_info *di =ceph_dentry (dentry);struct timespec64 now;struct ceph_string *pool_ns;struct ceph_mds_client *mdsc =ceph_sb_to_mdsc (dir->i_sb);@@ -709,6 +710,12 @@ static int ceph_finish_async_create(struct inode *dir, struct inode *inode, file->f_mode |=FMODE_CREATED ; ret =finish_open (file, dentry, ceph_open); } +
Quoted 8 lines
fs/ceph/file.c static int ceph_finish_async_create(struct inode *dir, struct inode *inode, · line 717
Quoted 4 lines
fs/ceph/file.c +4
-0+spin_lock (&dentry->d_lock); + di->flags &= ~CEPH_DENTRY_ASYNC_CREATE ; +wake_up_bit (&di->flags,CEPH_DENTRY_ASYNC_CREATE_BIT ); +spin_unlock (&dentry->d_lock);Question: shouldn't we initialise 'di' *after* grabbing ->d_lock? Ceph code doesn't seem to be consistent with this regard, but my understanding is that doing it this way is racy. And if so, some other places may need fixing.
BTW, do you mean some where like:
'if (!test_bit(CEPH_DENTRY_ASYNC_UNLINK_BIT, &di->flags))' and 'di->hnode' ?
If so, it's okay and no issue here.
-- Xiubo
Quoted 1 line
Cheers,