Skip to content

Commit 546d402

Browse files
ukernelidryomov
authored andcommitted
ceph: cleanup return error of try_get_cap_refs()
Returns 0 if caps were not able to be acquired (yet), 1 if cap acquisition succeeded, or a negative error code. There are 3 special 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. [ jlayton: add WARN_ON_ONCE check for -EAGAIN ] Signed-off-by: "Yan, Zheng" <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Ilya Dryomov <[email protected]>
1 parent c6d5029 commit 546d402

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

fs/ceph/caps.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2530,10 +2530,11 @@ void ceph_take_cap_refs(struct ceph_inode_info *ci, int got,
25302530
* Note that caller is responsible for ensuring max_size increases are
25312531
* requested from the MDS.
25322532
*
2533-
* Returns 0 if caps were not able to be acquired (yet), a 1 if they were,
2534-
* or a negative error code.
2535-
*
2536-
* FIXME: how does a 0 return differ from -EAGAIN?
2533+
* Returns 0 if caps were not able to be acquired (yet), 1 if succeed,
2534+
* or a negative error code. There are 3 speical error codes:
2535+
* -EAGAIN: need to sleep but non-blocking is specified
2536+
* -EFBIG: ask caller to call check_max_size() and try again.
2537+
* -ESTALE: ask caller to call ceph_renew_caps() and try again.
25372538
*/
25382539
enum {
25392540
/* 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,
25812582
dout("get_cap_refs %p endoff %llu > maxsize %llu\n",
25822583
inode, endoff, ci->i_max_size);
25832584
if (endoff > ci->i_requested_max_size)
2584-
ret = -EAGAIN;
2585+
ret = -EFBIG;
25852586
goto out_unlock;
25862587
}
25872588
/*
@@ -2743,7 +2744,10 @@ int ceph_try_get_caps(struct inode *inode, int need, int want,
27432744
flags |= NON_BLOCKING;
27442745

27452746
ret = try_get_cap_refs(inode, need, want, 0, flags, got);
2746-
return ret == -EAGAIN ? 0 : ret;
2747+
/* three special error codes */
2748+
if (ret == -EAGAIN || ret == -EFBIG || ret == -EAGAIN)
2749+
ret = 0;
2750+
return ret;
27472751
}
27482752

27492753
/*
@@ -2771,17 +2775,13 @@ int ceph_get_caps(struct file *filp, int need, int want,
27712775
flags = get_used_fmode(need | want);
27722776

27732777
while (true) {
2774-
if (endoff > 0)
2775-
check_max_size(inode, endoff);
2776-
27772778
flags &= CEPH_FILE_MODE_MASK;
27782779
if (atomic_read(&fi->num_locks))
27792780
flags |= CHECK_FILELOCK;
27802781
_got = 0;
27812782
ret = try_get_cap_refs(inode, need, want, endoff,
27822783
flags, &_got);
2783-
if (ret == -EAGAIN)
2784-
continue;
2784+
WARN_ON_ONCE(ret == -EAGAIN);
27852785
if (!ret) {
27862786
struct ceph_mds_client *mdsc = fsc->mdsc;
27872787
struct cap_wait cw;
@@ -2829,6 +2829,10 @@ int ceph_get_caps(struct file *filp, int need, int want,
28292829
}
28302830

28312831
if (ret < 0) {
2832+
if (ret == -EFBIG) {
2833+
check_max_size(inode, endoff);
2834+
continue;
2835+
}
28322836
if (ret == -ESTALE) {
28332837
/* session was killed, try renew caps */
28342838
ret = ceph_renew_caps(inode, flags);

0 commit comments

Comments
 (0)