Skip to content

Commit 135e671

Browse files
ukernelidryomov
authored andcommitted
ceph: simplify calling of ceph_get_fmode()
Originally, calling ceph_get_fmode() for open files is by thread that handles request reply. There is a small window between updating caps and and waking the request initiator. We need to prevent ceph_check_caps() from releasing wanted caps in the window. Previous patches made fill_inode() call __ceph_touch_fmode() for open file requests. This prevented ceph_check_caps() from releasing wanted caps for 'caps_wanted_delay_min' seconds, enough for request initiator to get woken up and call ceph_get_fmode(). This allows us to now call ceph_get_fmode() in ceph_open() instead. Signed-off-by: "Yan, Zheng" <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Ilya Dryomov <[email protected]>
1 parent a0d93e3 commit 135e671

File tree

4 files changed

+10
-48
lines changed

4 files changed

+10
-48
lines changed

fs/ceph/caps.c

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ static void __check_cap_issue(struct ceph_inode_info *ci, struct ceph_cap *cap,
608608
*/
609609
void ceph_add_cap(struct inode *inode,
610610
struct ceph_mds_session *session, u64 cap_id,
611-
int fmode, unsigned issued, unsigned wanted,
611+
unsigned issued, unsigned wanted,
612612
unsigned seq, unsigned mseq, u64 realmino, int flags,
613613
struct ceph_cap **new_cap)
614614
{
@@ -624,13 +624,6 @@ void ceph_add_cap(struct inode *inode,
624624
dout("add_cap %p mds%d cap %llx %s seq %d\n", inode,
625625
session->s_mds, cap_id, ceph_cap_string(issued), seq);
626626

627-
/*
628-
* If we are opening the file, include file mode wanted bits
629-
* in wanted.
630-
*/
631-
if (fmode >= 0)
632-
wanted |= ceph_caps_for_mode(fmode);
633-
634627
spin_lock(&session->s_gen_ttl_lock);
635628
gen = session->s_cap_gen;
636629
spin_unlock(&session->s_gen_ttl_lock);
@@ -755,9 +748,6 @@ void ceph_add_cap(struct inode *inode,
755748
cap->issue_seq = seq;
756749
cap->mseq = mseq;
757750
cap->cap_gen = gen;
758-
759-
if (fmode >= 0)
760-
__ceph_get_fmode(ci, fmode);
761751
}
762752

763753
/*
@@ -3707,7 +3697,7 @@ static void handle_cap_export(struct inode *inode, struct ceph_mds_caps *ex,
37073697
/* add placeholder for the export tagert */
37083698
int flag = (cap == ci->i_auth_cap) ? CEPH_CAP_FLAG_AUTH : 0;
37093699
tcap = new_cap;
3710-
ceph_add_cap(inode, tsession, t_cap_id, -1, issued, 0,
3700+
ceph_add_cap(inode, tsession, t_cap_id, issued, 0,
37113701
t_seq - 1, t_mseq, (u64)-1, flag, &new_cap);
37123702

37133703
if (!list_empty(&ci->i_cap_flush_list) &&
@@ -3812,7 +3802,7 @@ static void handle_cap_import(struct ceph_mds_client *mdsc,
38123802
__ceph_caps_issued(ci, &issued);
38133803
issued |= __ceph_caps_dirty(ci);
38143804

3815-
ceph_add_cap(inode, session, cap_id, -1, caps, wanted, seq, mseq,
3805+
ceph_add_cap(inode, session, cap_id, caps, wanted, seq, mseq,
38163806
realmino, CEPH_CAP_FLAG_AUTH, &new_cap);
38173807

38183808
ocap = peer >= 0 ? __get_cap_for_mds(ci, peer) : NULL;
@@ -4165,16 +4155,6 @@ void ceph_get_fmode(struct ceph_inode_info *ci, int fmode, int count)
41654155
spin_unlock(&ci->i_ceph_lock);
41664156
}
41674157

4168-
void __ceph_get_fmode(struct ceph_inode_info *ci, int fmode)
4169-
{
4170-
int i;
4171-
int bits = (fmode << 1) | 1;
4172-
for (i = 0; i < CEPH_FILE_MODE_BITS; i++) {
4173-
if (bits & (1 << i))
4174-
ci->i_nr_by_mode[i]++;
4175-
}
4176-
}
4177-
41784158
/*
41794159
* Drop open file reference. If we were the last open file,
41804160
* we may need to release capabilities to the MDS (or schedule

fs/ceph/file.c

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -212,26 +212,24 @@ static int ceph_init_file_info(struct inode *inode, struct file *file,
212212
if (isdir) {
213213
struct ceph_dir_file_info *dfi =
214214
kmem_cache_zalloc(ceph_dir_file_cachep, GFP_KERNEL);
215-
if (!dfi) {
216-
ceph_put_fmode(ci, fmode, 1); /* clean up */
215+
if (!dfi)
217216
return -ENOMEM;
218-
}
219217

220218
file->private_data = dfi;
221219
fi = &dfi->file_info;
222220
dfi->next_offset = 2;
223221
dfi->readdir_cache_idx = -1;
224222
} else {
225223
fi = kmem_cache_zalloc(ceph_file_cachep, GFP_KERNEL);
226-
if (!fi) {
227-
ceph_put_fmode(ci, fmode, 1); /* clean up */
224+
if (!fi)
228225
return -ENOMEM;
229-
}
230226

231227
file->private_data = fi;
232228
}
233229

230+
ceph_get_fmode(ci, fmode, 1);
234231
fi->fmode = fmode;
232+
235233
spin_lock_init(&fi->rw_contexts_lock);
236234
INIT_LIST_HEAD(&fi->rw_contexts);
237235
fi->meta_err = errseq_sample(&ci->i_meta_err);
@@ -263,7 +261,6 @@ static int ceph_init_file(struct inode *inode, struct file *file, int fmode)
263261
case S_IFLNK:
264262
dout("init_file %p %p 0%o (symlink)\n", inode, file,
265263
inode->i_mode);
266-
ceph_put_fmode(ceph_inode(inode), fmode, 1); /* clean up */
267264
break;
268265

269266
default:
@@ -273,7 +270,6 @@ static int ceph_init_file(struct inode *inode, struct file *file, int fmode)
273270
* we need to drop the open ref now, since we don't
274271
* have .release set to ceph_release.
275272
*/
276-
ceph_put_fmode(ceph_inode(inode), fmode, 1); /* clean up */
277273
BUG_ON(inode->i_fop->release == ceph_release);
278274

279275
/* call the proper open fop */
@@ -327,7 +323,6 @@ int ceph_renew_caps(struct inode *inode, int fmode)
327323
req->r_inode = inode;
328324
ihold(inode);
329325
req->r_num_caps = 1;
330-
req->r_fmode = -1;
331326

332327
err = ceph_mdsc_do_request(mdsc, NULL, req);
333328
ceph_mdsc_put_request(req);
@@ -373,9 +368,6 @@ int ceph_open(struct inode *inode, struct file *file)
373368

374369
/* trivially open snapdir */
375370
if (ceph_snap(inode) == CEPH_SNAPDIR) {
376-
spin_lock(&ci->i_ceph_lock);
377-
__ceph_get_fmode(ci, fmode);
378-
spin_unlock(&ci->i_ceph_lock);
379371
return ceph_init_file(inode, file, fmode);
380372
}
381373

@@ -393,7 +385,7 @@ int ceph_open(struct inode *inode, struct file *file)
393385
dout("open %p fmode %d want %s issued %s using existing\n",
394386
inode, fmode, ceph_cap_string(wanted),
395387
ceph_cap_string(issued));
396-
__ceph_get_fmode(ci, fmode);
388+
__ceph_touch_fmode(ci, mdsc, fmode);
397389
spin_unlock(&ci->i_ceph_lock);
398390

399391
/* adjust wanted? */
@@ -405,7 +397,6 @@ int ceph_open(struct inode *inode, struct file *file)
405397
return ceph_init_file(inode, file, fmode);
406398
} else if (ceph_snap(inode) != CEPH_NOSNAP &&
407399
(ci->i_snap_caps & wanted) == wanted) {
408-
__ceph_get_fmode(ci, fmode);
409400
__ceph_touch_fmode(ci, mdsc, fmode);
410401
spin_unlock(&ci->i_ceph_lock);
411402
return ceph_init_file(inode, file, fmode);
@@ -782,8 +773,6 @@ int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
782773
err = finish_open(file, dentry, ceph_open);
783774
}
784775
out_req:
785-
if (!req->r_err && req->r_target_inode)
786-
ceph_put_fmode(ceph_inode(req->r_target_inode), req->r_fmode, 1);
787776
ceph_mdsc_put_request(req);
788777
out_ctx:
789778
ceph_release_acl_sec_ctx(&as_ctx);

fs/ceph/inode.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ int ceph_fill_inode(struct inode *inode, struct page *locked_page,
970970
if (ceph_snap(inode) == CEPH_NOSNAP) {
971971
ceph_add_cap(inode, session,
972972
le64_to_cpu(info->cap.cap_id),
973-
cap_fmode, info_caps,
973+
info_caps,
974974
le32_to_cpu(info->cap.wanted),
975975
le32_to_cpu(info->cap.seq),
976976
le32_to_cpu(info->cap.mseq),
@@ -995,13 +995,7 @@ int ceph_fill_inode(struct inode *inode, struct page *locked_page,
995995
dout(" %p got snap_caps %s\n", inode,
996996
ceph_cap_string(info_caps));
997997
ci->i_snap_caps |= info_caps;
998-
if (cap_fmode >= 0)
999-
__ceph_get_fmode(ci, cap_fmode);
1000998
}
1001-
} else if (cap_fmode >= 0) {
1002-
pr_warn("mds issued no caps on %llx.%llx\n",
1003-
ceph_vinop(inode));
1004-
__ceph_get_fmode(ci, cap_fmode);
1005999
}
10061000

10071001
if (iinfo->inline_version > 0 &&

fs/ceph/super.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ extern struct ceph_cap *ceph_get_cap(struct ceph_mds_client *mdsc,
10501050
struct ceph_cap_reservation *ctx);
10511051
extern void ceph_add_cap(struct inode *inode,
10521052
struct ceph_mds_session *session, u64 cap_id,
1053-
int fmode, unsigned issued, unsigned wanted,
1053+
unsigned issued, unsigned wanted,
10541054
unsigned cap, unsigned seq, u64 realmino, int flags,
10551055
struct ceph_cap **new_cap);
10561056
extern void __ceph_remove_cap(struct ceph_cap *cap, bool queue_release);
@@ -1096,7 +1096,6 @@ extern int ceph_try_get_caps(struct inode *inode,
10961096
int need, int want, bool nonblock, int *got);
10971097

10981098
/* for counting open files by mode */
1099-
extern void __ceph_get_fmode(struct ceph_inode_info *ci, int mode);
11001099
extern void ceph_get_fmode(struct ceph_inode_info *ci, int mode, int count);
11011100
extern void ceph_put_fmode(struct ceph_inode_info *ci, int mode, int count);
11021101
extern void __ceph_touch_fmode(struct ceph_inode_info *ci,

0 commit comments

Comments
 (0)