Skip to content

Commit a0d93e3

Browse files
ukernelidryomov
authored andcommitted
ceph: remove delay check logic from ceph_check_caps()
__ceph_caps_file_wanted() already checks 'caps_wanted_delay_min' and 'caps_wanted_delay_max'. There is no need to duplicate the logic in ceph_check_caps() and __send_cap() Signed-off-by: "Yan, Zheng" <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Ilya Dryomov <[email protected]>
1 parent 719a251 commit a0d93e3

File tree

4 files changed

+44
-126
lines changed

4 files changed

+44
-126
lines changed

fs/ceph/caps.c

Lines changed: 37 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -490,13 +490,10 @@ static void __cap_set_timeouts(struct ceph_mds_client *mdsc,
490490
struct ceph_inode_info *ci)
491491
{
492492
struct ceph_mount_options *opt = mdsc->fsc->mount_options;
493-
494-
ci->i_hold_caps_min = round_jiffies(jiffies +
495-
opt->caps_wanted_delay_min * HZ);
496493
ci->i_hold_caps_max = round_jiffies(jiffies +
497494
opt->caps_wanted_delay_max * HZ);
498-
dout("__cap_set_timeouts %p min %lu max %lu\n", &ci->vfs_inode,
499-
ci->i_hold_caps_min - jiffies, ci->i_hold_caps_max - jiffies);
495+
dout("__cap_set_timeouts %p %lu\n", &ci->vfs_inode,
496+
ci->i_hold_caps_max - jiffies);
500497
}
501498

502499
/*
@@ -508,8 +505,7 @@ static void __cap_set_timeouts(struct ceph_mds_client *mdsc,
508505
* -> we take mdsc->cap_delay_lock
509506
*/
510507
static void __cap_delay_requeue(struct ceph_mds_client *mdsc,
511-
struct ceph_inode_info *ci,
512-
bool set_timeout)
508+
struct ceph_inode_info *ci)
513509
{
514510
dout("__cap_delay_requeue %p flags 0x%lx at %lu\n", &ci->vfs_inode,
515511
ci->i_ceph_flags, ci->i_hold_caps_max);
@@ -520,8 +516,7 @@ static void __cap_delay_requeue(struct ceph_mds_client *mdsc,
520516
goto no_change;
521517
list_del_init(&ci->i_cap_delay_list);
522518
}
523-
if (set_timeout)
524-
__cap_set_timeouts(mdsc, ci);
519+
__cap_set_timeouts(mdsc, ci);
525520
list_add_tail(&ci->i_cap_delay_list, &mdsc->cap_delay_list);
526521
no_change:
527522
spin_unlock(&mdsc->cap_delay_lock);
@@ -733,7 +728,7 @@ void ceph_add_cap(struct inode *inode,
733728
dout(" issued %s, mds wanted %s, actual %s, queueing\n",
734729
ceph_cap_string(issued), ceph_cap_string(wanted),
735730
ceph_cap_string(actual_wanted));
736-
__cap_delay_requeue(mdsc, ci, true);
731+
__cap_delay_requeue(mdsc, ci);
737732
}
738733

739734
if (flags & CEPH_CAP_FLAG_AUTH) {
@@ -1342,7 +1337,6 @@ static int __send_cap(struct ceph_mds_client *mdsc, struct ceph_cap *cap,
13421337
struct cap_msg_args arg;
13431338
int held, revoking;
13441339
int wake = 0;
1345-
int delayed = 0;
13461340
int ret;
13471341

13481342
/* Don't send anything if it's still being created. Return delayed */
@@ -1362,28 +1356,7 @@ static int __send_cap(struct ceph_mds_client *mdsc, struct ceph_cap *cap,
13621356
ceph_cap_string(revoking));
13631357
BUG_ON((retain & CEPH_CAP_PIN) == 0);
13641358

1365-
arg.session = cap->session;
1366-
1367-
/* don't release wanted unless we've waited a bit. */
1368-
if ((ci->i_ceph_flags & CEPH_I_NODELAY) == 0 &&
1369-
time_before(jiffies, ci->i_hold_caps_min)) {
1370-
dout(" delaying issued %s -> %s, wanted %s -> %s on send\n",
1371-
ceph_cap_string(cap->issued),
1372-
ceph_cap_string(cap->issued & retain),
1373-
ceph_cap_string(cap->mds_wanted),
1374-
ceph_cap_string(want));
1375-
want |= cap->mds_wanted;
1376-
retain |= cap->issued;
1377-
delayed = 1;
1378-
}
1379-
ci->i_ceph_flags &= ~(CEPH_I_NODELAY | CEPH_I_FLUSH);
1380-
if (want & ~cap->mds_wanted) {
1381-
/* user space may open/close single file frequently.
1382-
* This avoids droping mds_wanted immediately after
1383-
* requesting new mds_wanted.
1384-
*/
1385-
__cap_set_timeouts(mdsc, ci);
1386-
}
1359+
ci->i_ceph_flags &= ~CEPH_I_FLUSH;
13871360

13881361
cap->issued &= retain; /* drop bits we don't want */
13891362
if (cap->implemented & ~cap->issued) {
@@ -1398,6 +1371,7 @@ static int __send_cap(struct ceph_mds_client *mdsc, struct ceph_cap *cap,
13981371
cap->implemented &= cap->issued | used;
13991372
cap->mds_wanted = want;
14001373

1374+
arg.session = cap->session;
14011375
arg.ino = ceph_vino(inode).ino;
14021376
arg.cid = cap->cap_id;
14031377
arg.follows = flushing ? ci->i_head_snapc->seq : 0;
@@ -1458,14 +1432,19 @@ static int __send_cap(struct ceph_mds_client *mdsc, struct ceph_cap *cap,
14581432

14591433
ret = send_cap_msg(&arg);
14601434
if (ret < 0) {
1461-
dout("error sending cap msg, must requeue %p\n", inode);
1462-
delayed = 1;
1435+
pr_err("error sending cap msg, ino (%llx.%llx) "
1436+
"flushing %s tid %llu, requeue\n",
1437+
ceph_vinop(inode), ceph_cap_string(flushing),
1438+
flush_tid);
1439+
spin_lock(&ci->i_ceph_lock);
1440+
__cap_delay_requeue(mdsc, ci);
1441+
spin_unlock(&ci->i_ceph_lock);
14631442
}
14641443

14651444
if (wake)
14661445
wake_up_all(&ci->i_cap_wq);
14671446

1468-
return delayed;
1447+
return ret;
14691448
}
14701449

14711450
static inline int __send_flush_snap(struct inode *inode,
@@ -1731,7 +1710,7 @@ int __ceph_mark_dirty_caps(struct ceph_inode_info *ci, int mask,
17311710
if (((was | ci->i_flushing_caps) & CEPH_CAP_FILE_BUFFER) &&
17321711
(mask & CEPH_CAP_FILE_BUFFER))
17331712
dirty |= I_DIRTY_DATASYNC;
1734-
__cap_delay_requeue(mdsc, ci, true);
1713+
__cap_delay_requeue(mdsc, ci);
17351714
return dirty;
17361715
}
17371716

@@ -1883,8 +1862,6 @@ bool __ceph_should_report_size(struct ceph_inode_info *ci)
18831862
* versus held caps. Release, flush, ack revoked caps to mds as
18841863
* appropriate.
18851864
*
1886-
* CHECK_CAPS_NODELAY - caller is delayed work and we should not delay
1887-
* cap release further.
18881865
* CHECK_CAPS_AUTHONLY - we should only check the auth cap
18891866
* CHECK_CAPS_FLUSH - we should flush any dirty caps immediately, without
18901867
* further delay.
@@ -1903,17 +1880,10 @@ void ceph_check_caps(struct ceph_inode_info *ci, int flags,
19031880
int mds = -1; /* keep track of how far we've gone through i_caps list
19041881
to avoid an infinite loop on retry */
19051882
struct rb_node *p;
1906-
int delayed = 0, sent = 0;
1907-
bool no_delay = flags & CHECK_CAPS_NODELAY;
19081883
bool queue_invalidate = false;
19091884
bool tried_invalidate = false;
19101885

1911-
/* if we are unmounting, flush any unused caps immediately. */
1912-
if (mdsc->stopping)
1913-
no_delay = true;
1914-
19151886
spin_lock(&ci->i_ceph_lock);
1916-
19171887
if (ci->i_ceph_flags & CEPH_I_FLUSH)
19181888
flags |= CHECK_CAPS_FLUSH;
19191889

@@ -1960,22 +1930,21 @@ void ceph_check_caps(struct ceph_inode_info *ci, int flags,
19601930
}
19611931

19621932
dout("check_caps %p file_want %s used %s dirty %s flushing %s"
1963-
" issued %s revoking %s retain %s %s%s%s\n", inode,
1933+
" issued %s revoking %s retain %s %s%s\n", inode,
19641934
ceph_cap_string(file_wanted),
19651935
ceph_cap_string(used), ceph_cap_string(ci->i_dirty_caps),
19661936
ceph_cap_string(ci->i_flushing_caps),
19671937
ceph_cap_string(issued), ceph_cap_string(revoking),
19681938
ceph_cap_string(retain),
19691939
(flags & CHECK_CAPS_AUTHONLY) ? " AUTHONLY" : "",
1970-
(flags & CHECK_CAPS_NODELAY) ? " NODELAY" : "",
19711940
(flags & CHECK_CAPS_FLUSH) ? " FLUSH" : "");
19721941

19731942
/*
19741943
* If we no longer need to hold onto old our caps, and we may
19751944
* have cached pages, but don't want them, then try to invalidate.
19761945
* If we fail, it's because pages are locked.... try again later.
19771946
*/
1978-
if ((!no_delay || mdsc->stopping) &&
1947+
if ((!(flags & CHECK_CAPS_NOINVAL) || mdsc->stopping) &&
19791948
S_ISREG(inode->i_mode) &&
19801949
!(ci->i_wb_ref || ci->i_wrbuffer_ref) && /* no dirty pages... */
19811950
inode->i_data.nrpages && /* have cached pages */
@@ -2055,21 +2024,6 @@ void ceph_check_caps(struct ceph_inode_info *ci, int flags,
20552024
if ((cap->issued & ~retain) == 0)
20562025
continue; /* nope, all good */
20572026

2058-
if (no_delay)
2059-
goto ack;
2060-
2061-
/* delay? */
2062-
if ((ci->i_ceph_flags & CEPH_I_NODELAY) == 0 &&
2063-
time_before(jiffies, ci->i_hold_caps_max)) {
2064-
dout(" delaying issued %s -> %s, wanted %s -> %s\n",
2065-
ceph_cap_string(cap->issued),
2066-
ceph_cap_string(cap->issued & retain),
2067-
ceph_cap_string(cap->mds_wanted),
2068-
ceph_cap_string(want));
2069-
delayed++;
2070-
continue;
2071-
}
2072-
20732027
ack:
20742028
if (session && session != cap->session) {
20752029
dout("oops, wrong session %p mutex\n", session);
@@ -2130,25 +2084,19 @@ void ceph_check_caps(struct ceph_inode_info *ci, int flags,
21302084
}
21312085

21322086
mds = cap->mds; /* remember mds, so we don't repeat */
2133-
sent++;
21342087

21352088
/* __send_cap drops i_ceph_lock */
2136-
delayed += __send_cap(mdsc, cap, CEPH_CAP_OP_UPDATE, 0,
2137-
cap_used, want, retain, flushing,
2138-
flush_tid, oldest_flush_tid);
2089+
__send_cap(mdsc, cap, CEPH_CAP_OP_UPDATE, 0, cap_used, want,
2090+
retain, flushing, flush_tid, oldest_flush_tid);
21392091
goto retry; /* retake i_ceph_lock and restart our cap scan. */
21402092
}
21412093

2142-
if (list_empty(&ci->i_cap_delay_list)) {
2143-
if (delayed) {
2144-
/* Reschedule delayed caps release if we delayed anything */
2145-
__cap_delay_requeue(mdsc, ci, false);
2146-
} else if (__ceph_is_any_real_caps(ci) &&
2147-
(file_wanted & ~CEPH_CAP_PIN) &&
2148-
!(used & (CEPH_CAP_FILE_RD | CEPH_CAP_ANY_FILE_WR))) {
2149-
/* periodically re-calculate caps wanted by open files */
2150-
__cap_delay_requeue(mdsc, ci, true);
2151-
}
2094+
/* periodically re-calculate caps wanted by open files */
2095+
if (__ceph_is_any_real_caps(ci) &&
2096+
list_empty(&ci->i_cap_delay_list) &&
2097+
(file_wanted & ~CEPH_CAP_PIN) &&
2098+
!(used & (CEPH_CAP_FILE_RD | CEPH_CAP_ANY_FILE_WR))) {
2099+
__cap_delay_requeue(mdsc, ci);
21522100
}
21532101

21542102
spin_unlock(&ci->i_ceph_lock);
@@ -2178,7 +2126,6 @@ static int try_flush_caps(struct inode *inode, u64 *ptid)
21782126
retry_locked:
21792127
if (ci->i_dirty_caps && ci->i_auth_cap) {
21802128
struct ceph_cap *cap = ci->i_auth_cap;
2181-
int delayed;
21822129

21832130
if (session != cap->session) {
21842131
spin_unlock(&ci->i_ceph_lock);
@@ -2207,18 +2154,10 @@ static int try_flush_caps(struct inode *inode, u64 *ptid)
22072154
&oldest_flush_tid);
22082155

22092156
/* __send_cap drops i_ceph_lock */
2210-
delayed = __send_cap(mdsc, cap, CEPH_CAP_OP_FLUSH,
2211-
CEPH_CLIENT_CAPS_SYNC,
2212-
__ceph_caps_used(ci),
2213-
__ceph_caps_wanted(ci),
2214-
(cap->issued | cap->implemented),
2215-
flushing, flush_tid, oldest_flush_tid);
2216-
2217-
if (delayed) {
2218-
spin_lock(&ci->i_ceph_lock);
2219-
__cap_delay_requeue(mdsc, ci, true);
2220-
spin_unlock(&ci->i_ceph_lock);
2221-
}
2157+
__send_cap(mdsc, cap, CEPH_CAP_OP_FLUSH, CEPH_CLIENT_CAPS_SYNC,
2158+
__ceph_caps_used(ci), __ceph_caps_wanted(ci),
2159+
(cap->issued | cap->implemented),
2160+
flushing, flush_tid, oldest_flush_tid);
22222161
} else {
22232162
if (!list_empty(&ci->i_cap_flush_list)) {
22242163
struct ceph_cap_flush *cf =
@@ -2422,22 +2361,13 @@ static void __kick_flushing_caps(struct ceph_mds_client *mdsc,
24222361
if (cf->caps) {
24232362
dout("kick_flushing_caps %p cap %p tid %llu %s\n",
24242363
inode, cap, cf->tid, ceph_cap_string(cf->caps));
2425-
ci->i_ceph_flags |= CEPH_I_NODELAY;
2426-
2427-
ret = __send_cap(mdsc, cap, CEPH_CAP_OP_FLUSH,
2364+
__send_cap(mdsc, cap, CEPH_CAP_OP_FLUSH,
24282365
(cf->tid < last_snap_flush ?
24292366
CEPH_CLIENT_CAPS_PENDING_CAPSNAP : 0),
24302367
__ceph_caps_used(ci),
24312368
__ceph_caps_wanted(ci),
24322369
(cap->issued | cap->implemented),
24332370
cf->caps, cf->tid, oldest_flush_tid);
2434-
if (ret) {
2435-
pr_err("kick_flushing_caps: error sending "
2436-
"cap flush, ino (%llx.%llx) "
2437-
"tid %llu flushing %s\n",
2438-
ceph_vinop(inode), cf->tid,
2439-
ceph_cap_string(cf->caps));
2440-
}
24412371
} else {
24422372
struct ceph_cap_snap *capsnap =
24432373
container_of(cf, struct ceph_cap_snap,
@@ -3059,7 +2989,7 @@ void ceph_put_cap_refs(struct ceph_inode_info *ci, int had)
30592989
dout("put_cap_refs %p had %s%s%s\n", inode, ceph_cap_string(had),
30602990
last ? " last" : "", put ? " put" : "");
30612991

3062-
if (last && !flushsnaps)
2992+
if (last)
30632993
ceph_check_caps(ci, 0, NULL);
30642994
else if (flushsnaps)
30652995
ceph_flush_snaps(ci, NULL);
@@ -3478,10 +3408,10 @@ static void handle_cap_grant(struct inode *inode,
34783408
wake_up_all(&ci->i_cap_wq);
34793409

34803410
if (check_caps == 1)
3481-
ceph_check_caps(ci, CHECK_CAPS_NODELAY|CHECK_CAPS_AUTHONLY,
3411+
ceph_check_caps(ci, CHECK_CAPS_AUTHONLY | CHECK_CAPS_NOINVAL,
34823412
session);
34833413
else if (check_caps == 2)
3484-
ceph_check_caps(ci, CHECK_CAPS_NODELAY, session);
3414+
ceph_check_caps(ci, CHECK_CAPS_NOINVAL, session);
34853415
else
34863416
mutex_unlock(&session->s_mutex);
34873417
}
@@ -4156,7 +4086,6 @@ void ceph_check_delayed_caps(struct ceph_mds_client *mdsc)
41564086
{
41574087
struct inode *inode;
41584088
struct ceph_inode_info *ci;
4159-
int flags = CHECK_CAPS_NODELAY;
41604089

41614090
dout("check_delayed_caps\n");
41624091
while (1) {
@@ -4176,7 +4105,7 @@ void ceph_check_delayed_caps(struct ceph_mds_client *mdsc)
41764105

41774106
if (inode) {
41784107
dout("check_delayed_caps on %p\n", inode);
4179-
ceph_check_caps(ci, flags, NULL);
4108+
ceph_check_caps(ci, 0, NULL);
41804109
/* avoid calling iput_final() in tick thread */
41814110
ceph_async_iput(inode);
41824111
}
@@ -4201,7 +4130,7 @@ void ceph_flush_dirty_caps(struct ceph_mds_client *mdsc)
42014130
ihold(inode);
42024131
dout("flush_dirty_caps %p\n", inode);
42034132
spin_unlock(&mdsc->cap_dirty_lock);
4204-
ceph_check_caps(ci, CHECK_CAPS_NODELAY|CHECK_CAPS_FLUSH, NULL);
4133+
ceph_check_caps(ci, CHECK_CAPS_FLUSH, NULL);
42054134
iput(inode);
42064135
spin_lock(&mdsc->cap_dirty_lock);
42074136
}
@@ -4221,7 +4150,7 @@ void __ceph_touch_fmode(struct ceph_inode_info *ci,
42214150
if (fmode &&
42224151
__ceph_is_any_real_caps(ci) &&
42234152
list_empty(&ci->i_cap_delay_list))
4224-
__cap_delay_requeue(mdsc, ci, true);
4153+
__cap_delay_requeue(mdsc, ci);
42254154
}
42264155

42274156
void ceph_get_fmode(struct ceph_inode_info *ci, int fmode, int count)
@@ -4280,7 +4209,6 @@ int ceph_drop_caps_for_unlink(struct inode *inode)
42804209
if (inode->i_nlink == 1) {
42814210
drop |= ~(__ceph_caps_wanted(ci) | CEPH_CAP_PIN);
42824211

4283-
ci->i_ceph_flags |= CEPH_I_NODELAY;
42844212
if (__ceph_caps_dirty(ci)) {
42854213
struct ceph_mds_client *mdsc =
42864214
ceph_inode_to_client(inode)->mdsc;
@@ -4336,8 +4264,6 @@ int ceph_encode_inode_release(void **p, struct inode *inode,
43364264
if (force || (cap->issued & drop)) {
43374265
if (cap->issued & drop) {
43384266
int wanted = __ceph_caps_wanted(ci);
4339-
if ((ci->i_ceph_flags & CEPH_I_NODELAY) == 0)
4340-
wanted |= cap->mds_wanted;
43414267
dout("encode_inode_release %p cap %p "
43424268
"%s -> %s, wanted %s -> %s\n", inode, cap,
43434269
ceph_cap_string(cap->issued),

fs/ceph/file.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,7 +1826,7 @@ static ssize_t ceph_write_iter(struct kiocb *iocb, struct iov_iter *from)
18261826
if (dirty)
18271827
__mark_inode_dirty(inode, dirty);
18281828
if (ceph_quota_is_max_bytes_approaching(inode, iocb->ki_pos))
1829-
ceph_check_caps(ci, CHECK_CAPS_NODELAY, NULL);
1829+
ceph_check_caps(ci, 0, NULL);
18301830
}
18311831

18321832
dout("aio_write %p %llx.%llx %llu~%u dropping cap refs on %s\n",
@@ -2427,15 +2427,10 @@ static ssize_t __ceph_copy_file_range(struct file *src_file, loff_t src_off,
24272427
inode_inc_iversion_raw(dst_inode);
24282428

24292429
if (dst_off > size) {
2430-
int caps_flags = 0;
2431-
24322430
/* Let the MDS know about dst file size change */
2433-
if (ceph_quota_is_max_bytes_approaching(dst_inode, dst_off))
2434-
caps_flags |= CHECK_CAPS_NODELAY;
2435-
if (ceph_inode_set_size(dst_inode, dst_off))
2436-
caps_flags |= CHECK_CAPS_AUTHONLY;
2437-
if (caps_flags)
2438-
ceph_check_caps(dst_ci, caps_flags, NULL);
2431+
if (ceph_inode_set_size(dst_inode, dst_off) ||
2432+
ceph_quota_is_max_bytes_approaching(dst_inode, dst_off))
2433+
ceph_check_caps(dst_ci, CHECK_CAPS_AUTHONLY, NULL);
24392434
}
24402435
/* Mark Fw dirty */
24412436
spin_lock(&dst_ci->i_ceph_lock);

fs/ceph/inode.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,6 @@ struct inode *ceph_alloc_inode(struct super_block *sb)
472472
ci->i_prealloc_cap_flush = NULL;
473473
INIT_LIST_HEAD(&ci->i_cap_flush_list);
474474
init_waitqueue_head(&ci->i_cap_wq);
475-
ci->i_hold_caps_min = 0;
476475
ci->i_hold_caps_max = 0;
477476
INIT_LIST_HEAD(&ci->i_cap_delay_list);
478477
INIT_LIST_HEAD(&ci->i_cap_snaps);

0 commit comments

Comments
 (0)