fix ceph_get_caps() bugs
cover fix ceph_get_caps() bugs
Yan, Zheng (4):
ceph: cleanup return error of try_get_cap_refs()
ceph: request new max size only when there is auth cap
ceph: don't skip updating wanted caps when cap is stale
ceph: wait for async creating inode before requesting new max size
fs/ceph/caps.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-)
Signature · 1 line
2.21.1
PATCH 1/4 ceph: cleanup return error of try_get_cap_refs()
Returns 0 if caps were not able to be acquired (yet), 1 if succeed, or a negative error code. There are 3 speical error codes:
-EAGAIN: need to sleep but non-blocking is specified -EFBIG: ask caller to call check_max_size() and try again. -ESTALE: ask caller to call ceph_renew_caps() and try again.
--- fs/ceph/caps.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)
fs/ceph/caps.c +14 -11
@@ -2530,10 +2530,11 @@ void ceph_take_cap_refs(struct ceph_inode_info *ci, int got,* Note that caller is responsible for ensuring max_size increases are * requested from the MDS. * -* Returns 0 if caps were not able to be acquired (yet), a 1 if they were, -* or a negative error code. -* -* FIXME: how does a 0 return differ from -EAGAIN? +* Returns 0 if caps were not able to be acquired (yet), 1 if succeed, +* or a negative error code. There are 3 speical error codes: +* -EAGAIN: need to sleep but non-blocking is specified +* -EFBIG: ask caller to call check_max_size() and try again. +* -ESTALE: ask caller to call ceph_renew_caps() and try again. */ enum {/* first 8 bits are reserved for CEPH_FILE_MODE_FOO */
@@ -2581,7 +2582,7 @@ static int try_get_cap_refs(struct inode *inode, int need, int want,dout ("get_cap_refs %p endoff %llu > maxsize %llu\n" , inode, endoff, ci->i_max_size);if (endoff > ci->i_requested_max_size) - ret = -EAGAIN ; + ret = -EFBIG ; goto out_unlock; }/*
@@ -2743,7 +2744,10 @@ int ceph_try_get_caps(struct inode *inode, int need, int want, flags |=NON_BLOCKING ; ret =try_get_cap_refs (inode, need, want,0 , flags, got); -return ret == -EAGAIN ?0 : ret; +/* three special error codes */ +if (ret == -EAGAIN || ret == -EFBIG || ret == -EAGAIN ) + ret =0 ; +return ret; }/*
@@ -2771,17 +2775,12 @@ int ceph_get_caps(struct file *filp, int need, int want, flags =get_used_fmode (need | want);while (true) { -if (endoff >0 ) -check_max_size (inode, endoff); - flags &=CEPH_FILE_MODE_MASK ;if (atomic_read (&fi->num_locks)) flags |=CHECK_FILELOCK ; _got =0 ; ret =try_get_cap_refs (inode, need, want, endoff, flags, &_got); -if (ret == -EAGAIN ) -continue ;if (!ret) {struct ceph_mds_client *mdsc = fsc->mdsc;struct cap_wait cw;
@@ -2829,6 +2828,10 @@ int ceph_get_caps(struct file *filp, int need, int want, }if (ret <0 ) { +if (ret == -EFBIG ) { +check_max_size (inode, endoff); +continue ; + }if (ret == -ESTALE ) {/* session was killed, try renew caps */ ret =ceph_renew_caps (inode, flags);
Signature · 1 line
2.21.1
Re: [PATCH 1/4] ceph: cleanup return error of try_get_cap_refs()
Quoted 58 lines · Zheng
Returns 0 if caps were not able to be acquired (yet), 1 if succeed, or a negative error code. There are 3 speical error codes:
(quoted diff) +0
-3-EAGAIN: need to sleep but non-blocking is specified -EFBIG: ask caller to call check_max_size() and try again. -ESTALE: ask caller to call ceph_renew_caps() and try again.Signed-off-by "Yan, Zheng" <[email protected]>--- fs/ceph/caps.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)fs/ceph/caps.c +10
-7@@ -2530,10 +2530,11 @@ void ceph_take_cap_refs(struct ceph_inode_info *ci, int got,* Note that caller is responsible for ensuring max_size increases are * requested from the MDS. * -* Returns 0 if caps were not able to be acquired (yet), a 1 if they were, -* or a negative error code. -* -* FIXME: how does a 0 return differ from -EAGAIN? +* Returns 0 if caps were not able to be acquired (yet), 1 if succeed, +* or a negative error code. There are 3 speical error codes: +* -EAGAIN: need to sleep but non-blocking is specified +* -EFBIG: ask caller to call check_max_size() and try again. +* -ESTALE: ask caller to call ceph_renew_caps() and try again. */ enum {/* first 8 bits are reserved for CEPH_FILE_MODE_FOO */ @@ -2581,7 +2582,7 @@ static int try_get_cap_refs(struct inode *inode, int need, int want,dout ("get_cap_refs %p endoff %llu > maxsize %llu\n" , inode, endoff, ci->i_max_size);if (endoff > ci->i_requested_max_size) - ret = -EAGAIN ; + ret = -EFBIG ; goto out_unlock; }/* @@ -2743,7 +2744,10 @@ int ceph_try_get_caps(struct inode *inode, int need, int want, flags |=NON_BLOCKING ; ret =try_get_cap_refs (inode, need, want,0 , flags, got); -return ret == -EAGAIN ?0 : ret; +/* three special error codes */ +if (ret == -EAGAIN || ret == -EFBIG || ret == -EAGAIN ) + ret =0 ; +return ret; }/* @@ -2771,17 +2775,12 @@ int ceph_get_caps(struct file *filp, int need, int want, flags =get_used_fmode (need | want);while (true) { -if (endoff >0 )
fs/ceph/caps.c int ceph_get_caps(struct file *filp, int need, int want, · line 2784
Quoted 10 lines
fs/ceph/caps.c +0
-4-check_max_size (inode, endoff); - flags &=CEPH_FILE_MODE_MASK ;if (atomic_read (&fi->num_locks)) flags |=CHECK_FILELOCK ; _got =0 ; ret =try_get_cap_refs (inode, need, want, endoff, flags, &_got); -if (ret == -EAGAIN ) -continue ;
Ok, so I guess we don't expect to see this error here since we didn't set NON_BLOCKING. The error returns from try_get_cap_refs are pretty complex, and I worry a little about future changes subtly breaking some of these assumptions.
Maybe a WARN_ON_ONCE(ret == -EAGAIN) here would be good?
Quoted 14 lines
fs/ceph/caps.c +4
-0if (!ret) {struct ceph_mds_client *mdsc = fsc->mdsc;struct cap_wait cw;@@ -2829,6 +2828,10 @@ int ceph_get_caps(struct file *filp, int need, int want, }if (ret <0 ) { +if (ret == -EFBIG ) { +check_max_size (inode, endoff); +continue ; + }if (ret == -ESTALE ) {/* session was killed, try renew caps */ ret =ceph_renew_caps (inode, flags);
Signature · 1 line
Jeff Layton <[email protected]>
Re: [PATCH 1/4] ceph: cleanup return error of try_get_cap_refs()
Quoted 76 lines · Jeff Layton
Quoted 58 lines · Zheng
Returns 0 if caps were not able to be acquired (yet), 1 if succeed, or a negative error code. There are 3 speical error codes:
(quoted diff) +0
-3-EAGAIN: need to sleep but non-blocking is specified -EFBIG: ask caller to call check_max_size() and try again. -ESTALE: ask caller to call ceph_renew_caps() and try again.Signed-off-by "Yan, Zheng" <[email protected]>--- fs/ceph/caps.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)fs/ceph/caps.c +10
-7@@ -2530,10 +2530,11 @@ void ceph_take_cap_refs(struct ceph_inode_info *ci, int got,* Note that caller is responsible for ensuring max_size increases are * requested from the MDS. * -* Returns 0 if caps were not able to be acquired (yet), a 1 if they were, -* or a negative error code. -* -* FIXME: how does a 0 return differ from -EAGAIN? +* Returns 0 if caps were not able to be acquired (yet), 1 if succeed, +* or a negative error code. There are 3 speical error codes: +* -EAGAIN: need to sleep but non-blocking is specified +* -EFBIG: ask caller to call check_max_size() and try again. +* -ESTALE: ask caller to call ceph_renew_caps() and try again. */ enum {/* first 8 bits are reserved for CEPH_FILE_MODE_FOO */ @@ -2581,7 +2582,7 @@ static int try_get_cap_refs(struct inode *inode, int need, int want,dout ("get_cap_refs %p endoff %llu > maxsize %llu\n" , inode, endoff, ci->i_max_size);if (endoff > ci->i_requested_max_size) - ret = -EAGAIN ; + ret = -EFBIG ; goto out_unlock; }/* @@ -2743,7 +2744,10 @@ int ceph_try_get_caps(struct inode *inode, int need, int want, flags |=NON_BLOCKING ; ret =try_get_cap_refs (inode, need, want,0 , flags, got); -return ret == -EAGAIN ?0 : ret; +/* three special error codes */ +if (ret == -EAGAIN || ret == -EFBIG || ret == -EAGAIN ) + ret =0 ; +return ret; }/* @@ -2771,17 +2775,12 @@ int ceph_get_caps(struct file *filp, int need, int want, flags =get_used_fmode (need | want);while (true) { -if (endoff >0 )fs/ceph/caps.c int ceph_get_caps(struct file *filp, int need, int want, · line 2784
Quoted 10 lines
fs/ceph/caps.c +0
-4-check_max_size (inode, endoff); - flags &=CEPH_FILE_MODE_MASK ;if (atomic_read (&fi->num_locks)) flags |=CHECK_FILELOCK ; _got =0 ; ret =try_get_cap_refs (inode, need, want, endoff, flags, &_got); -if (ret == -EAGAIN ) -continue ;Ok, so I guess we don't expect to see this error here since we didn't set
NON_BLOCKING. The error returns fromtry_get_cap_refsare pretty complex, and I worry a little about future changes subtly breaking some of these assumptions.
Quoted 2 lines
Maybe a
WARN_ON_ONCE(ret == -EAGAIN)here would be good?
make sense. Please edit the patch if you don't have other comments.
Regards
Yan, Zheng
Quoted 18 lines
Quoted 4 lines
fs/ceph/caps.c +0
-0if (!ret) {struct ceph_mds_client *mdsc = fsc->mdsc;struct cap_wait cw;fs/ceph/caps.c int ceph_get_caps(struct file *filp, int need, int want, · line 2837
Quoted 10 lines
fs/ceph/caps.c +4
-0@@ -2829,6 +2828,10 @@ int ceph_get_caps(struct file *filp, int need, int want, }if (ret <0 ) { +if (ret == -EFBIG ) { +check_max_size (inode, endoff); +continue ; + }if (ret == -ESTALE ) {/* session was killed, try renew caps */ ret =ceph_renew_caps (inode, flags);--
Jeff Layton <[email protected]>
PATCH 2/4 ceph: request new max size only when there is auth cap
In reply to Yan, ZhengWhen there is no auth cap, check_max_size() can't do anything, may cause infinite loop inside ceph_get_caps().
--- fs/ceph/caps.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ceph/caps.c +1 -1
@@ -2582,7 +2582,7 @@ static int try_get_cap_refs(struct inode *inode, int need, int want,dout ("get_cap_refs %p endoff %llu > maxsize %llu\n" , inode, endoff, ci->i_max_size);if (endoff > ci->i_requested_max_size) - ret = -EFBIG ; + ret = ci->i_auth_cap ? -EFBIG : -ESTALE ; goto out_unlock; }/*
Signature · 1 line
2.21.1
PATCH 3/4 ceph: don't skip updating wanted caps when cap is stale
In reply to Yan, Zheng1. try_get_cap_refs() fails to get caps and finds that mds_wanted does not include what it wants. It return -ESTALE.
2. ceph_get_caps() calls ceph_renew_caps(). ceph_renew_caps() finds that inode has cap, so it calls ceph_check_caps().
3. ceph_check_caps() finds that issued caps (without checking if it's stale) already includes caps wanted by open file, so it skips updating wanted caps.
Above events can cause infinite loop inside ceph_get_caps()
--- fs/ceph/caps.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
fs/ceph/caps.c +6 -2
@@ -2008,8 +2008,12 @@ void ceph_check_caps(struct ceph_inode_info *ci, int flags, }/* want more caps from mds? */ -if (want & ~(cap->mds_wanted | cap->issued)) - goto ack; +if (want & ~cap->mds_wanted) { +if (want & ~(cap->mds_wanted | cap->issued)) + goto ack; +if (!__cap_is_valid (cap)) + goto ack; + }/* things we might delay */ if ((cap->issued & ~retain) ==0 )
Signature · 1 line
2.21.1
PATCH 4/4 ceph: wait for async creating inode before requesting new max size
In reply to Yan, Zhengceph_check_caps() can't request new max size for async creating inode. This may make ceph_get_caps() loop busily until getting reply of the async create.
This patch also waits for async creating inode before calling ceph_renew_caps()
--- fs/ceph/caps.c | 5 +++++ 1 file changed, 5 insertions(+)
fs/ceph/caps.c +5 -0
@@ -2832,6 +2832,11 @@ int ceph_get_caps(struct file *filp, int need, int want, }if (ret <0 ) { +if (ret == -EFBIG || ret == -ESTALE ) { +int ret2 =ceph_wait_on_async_create (inode); +if (ret2 <0 ) +return ret2; + }if (ret == -EFBIG ) {check_max_size (inode, endoff);continue ;
Signature · 1 line
2.21.1