Skip to content

Commit 5e3ded1

Browse files
ukernelidryomov
authored andcommitted
ceph: pass filp to ceph_get_caps()
Also change several other functions' arguments, no logical changes. This is preparetion for later patch that checks filp error. Signed-off-by: "Yan, Zheng" <zyan@redhat.com> Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
1 parent f4b9786 commit 5e3ded1

4 files changed

Lines changed: 46 additions & 42 deletions

File tree

‎fs/ceph/addr.c‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,8 @@ static int start_read(struct inode *inode, struct ceph_rw_context *rw_ctx,
323323
/* caller of readpages does not hold buffer and read caps
324324
* (fadvise, madvise and readahead cases) */
325325
int want = CEPH_CAP_FILE_CACHE;
326-
ret = ceph_try_get_caps(ci, CEPH_CAP_FILE_RD, want, true, &got);
326+
ret = ceph_try_get_caps(inode, CEPH_CAP_FILE_RD, want,
327+
true, &got);
327328
if (ret < 0) {
328329
dout("start_read %p, error getting cap\n", inode);
329330
} else if (!(got & want)) {
@@ -1452,7 +1453,8 @@ static vm_fault_t ceph_filemap_fault(struct vm_fault *vmf)
14521453
want = CEPH_CAP_FILE_CACHE;
14531454

14541455
got = 0;
1455-
err = ceph_get_caps(ci, CEPH_CAP_FILE_RD, want, -1, &got, &pinned_page);
1456+
err = ceph_get_caps(vma->vm_file, CEPH_CAP_FILE_RD, want, -1,
1457+
&got, &pinned_page);
14561458
if (err < 0)
14571459
goto out_restore;
14581460

@@ -1568,7 +1570,7 @@ static vm_fault_t ceph_page_mkwrite(struct vm_fault *vmf)
15681570
want = CEPH_CAP_FILE_BUFFER;
15691571

15701572
got = 0;
1571-
err = ceph_get_caps(ci, CEPH_CAP_FILE_WR, want, off + len,
1573+
err = ceph_get_caps(vma->vm_file, CEPH_CAP_FILE_WR, want, off + len,
15721574
&got, NULL);
15731575
if (err < 0)
15741576
goto out_free;
@@ -1989,10 +1991,11 @@ static int __ceph_pool_perm_get(struct ceph_inode_info *ci,
19891991
return err;
19901992
}
19911993

1992-
int ceph_pool_perm_check(struct ceph_inode_info *ci, int need)
1994+
int ceph_pool_perm_check(struct inode *inode, int need)
19931995
{
1994-
s64 pool;
1996+
struct ceph_inode_info *ci = ceph_inode(inode);
19951997
struct ceph_string *pool_ns;
1998+
s64 pool;
19961999
int ret, flags;
19972000

19982001
if (ci->i_vino.snap != CEPH_NOSNAP) {
@@ -2004,7 +2007,7 @@ int ceph_pool_perm_check(struct ceph_inode_info *ci, int need)
20042007
return 0;
20052008
}
20062009

2007-
if (ceph_test_mount_opt(ceph_inode_to_client(&ci->vfs_inode),
2010+
if (ceph_test_mount_opt(ceph_inode_to_client(inode),
20082011
NOPOOLPERM))
20092012
return 0;
20102013

‎fs/ceph/caps.c‎

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2570,10 +2570,10 @@ static void __take_cap_refs(struct ceph_inode_info *ci, int got,
25702570
*
25712571
* FIXME: how does a 0 return differ from -EAGAIN?
25722572
*/
2573-
static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want,
2573+
static int try_get_cap_refs(struct inode *inode, int need, int want,
25742574
loff_t endoff, bool nonblock, int *got)
25752575
{
2576-
struct inode *inode = &ci->vfs_inode;
2576+
struct ceph_inode_info *ci = ceph_inode(inode);
25772577
struct ceph_mds_client *mdsc = ceph_inode_to_client(inode)->mdsc;
25782578
int ret = 0;
25792579
int have, implemented;
@@ -2741,18 +2741,18 @@ static void check_max_size(struct inode *inode, loff_t endoff)
27412741
ceph_check_caps(ci, CHECK_CAPS_AUTHONLY, NULL);
27422742
}
27432743

2744-
int ceph_try_get_caps(struct ceph_inode_info *ci, int need, int want,
2744+
int ceph_try_get_caps(struct inode *inode, int need, int want,
27452745
bool nonblock, int *got)
27462746
{
27472747
int ret;
27482748

27492749
BUG_ON(need & ~CEPH_CAP_FILE_RD);
27502750
BUG_ON(want & ~(CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_LAZYIO|CEPH_CAP_FILE_SHARED));
2751-
ret = ceph_pool_perm_check(ci, need);
2751+
ret = ceph_pool_perm_check(inode, need);
27522752
if (ret < 0)
27532753
return ret;
27542754

2755-
ret = try_get_cap_refs(ci, need, want, 0, nonblock, got);
2755+
ret = try_get_cap_refs(inode, need, want, 0, nonblock, got);
27562756
return ret == -EAGAIN ? 0 : ret;
27572757
}
27582758

@@ -2761,30 +2761,32 @@ int ceph_try_get_caps(struct ceph_inode_info *ci, int need, int want,
27612761
* due to a small max_size, make sure we check_max_size (and possibly
27622762
* ask the mds) so we don't get hung up indefinitely.
27632763
*/
2764-
int ceph_get_caps(struct ceph_inode_info *ci, int need, int want,
2764+
int ceph_get_caps(struct file *filp, int need, int want,
27652765
loff_t endoff, int *got, struct page **pinned_page)
27662766
{
2767+
struct inode *inode = file_inode(filp);
2768+
struct ceph_inode_info *ci = ceph_inode(inode);
27672769
int _got, ret;
27682770

2769-
ret = ceph_pool_perm_check(ci, need);
2771+
ret = ceph_pool_perm_check(inode, need);
27702772
if (ret < 0)
27712773
return ret;
27722774

27732775
while (true) {
27742776
if (endoff > 0)
2775-
check_max_size(&ci->vfs_inode, endoff);
2777+
check_max_size(inode, endoff);
27762778

27772779
_got = 0;
2778-
ret = try_get_cap_refs(ci, need, want, endoff,
2780+
ret = try_get_cap_refs(inode, need, want, endoff,
27792781
false, &_got);
27802782
if (ret == -EAGAIN)
27812783
continue;
27822784
if (!ret) {
27832785
DEFINE_WAIT_FUNC(wait, woken_wake_function);
27842786
add_wait_queue(&ci->i_cap_wq, &wait);
27852787

2786-
while (!(ret = try_get_cap_refs(ci, need, want, endoff,
2787-
true, &_got))) {
2788+
while (!(ret = try_get_cap_refs(inode, need, want,
2789+
endoff, true, &_got))) {
27882790
if (signal_pending(current)) {
27892791
ret = -ERESTARTSYS;
27902792
break;
@@ -2799,7 +2801,7 @@ int ceph_get_caps(struct ceph_inode_info *ci, int need, int want,
27992801
if (ret < 0) {
28002802
if (ret == -ESTALE) {
28012803
/* session was killed, try renew caps */
2802-
ret = ceph_renew_caps(&ci->vfs_inode);
2804+
ret = ceph_renew_caps(inode);
28032805
if (ret == 0)
28042806
continue;
28052807
}
@@ -2808,9 +2810,9 @@ int ceph_get_caps(struct ceph_inode_info *ci, int need, int want,
28082810

28092811
if (ci->i_inline_version != CEPH_INLINE_NONE &&
28102812
(_got & (CEPH_CAP_FILE_CACHE|CEPH_CAP_FILE_LAZYIO)) &&
2811-
i_size_read(&ci->vfs_inode) > 0) {
2813+
i_size_read(inode) > 0) {
28122814
struct page *page =
2813-
find_get_page(ci->vfs_inode.i_mapping, 0);
2815+
find_get_page(inode->i_mapping, 0);
28142816
if (page) {
28152817
if (PageUptodate(page)) {
28162818
*pinned_page = page;
@@ -2829,7 +2831,7 @@ int ceph_get_caps(struct ceph_inode_info *ci, int need, int want,
28292831
* getattr request will bring inline data into
28302832
* page cache
28312833
*/
2832-
ret = __ceph_do_getattr(&ci->vfs_inode, NULL,
2834+
ret = __ceph_do_getattr(inode, NULL,
28332835
CEPH_STAT_CAP_INLINE_DATA,
28342836
true);
28352837
if (ret < 0)

‎fs/ceph/file.c‎

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,7 +1262,8 @@ static ssize_t ceph_read_iter(struct kiocb *iocb, struct iov_iter *to)
12621262
want = CEPH_CAP_FILE_CACHE | CEPH_CAP_FILE_LAZYIO;
12631263
else
12641264
want = CEPH_CAP_FILE_CACHE;
1265-
ret = ceph_get_caps(ci, CEPH_CAP_FILE_RD, want, -1, &got, &pinned_page);
1265+
ret = ceph_get_caps(filp, CEPH_CAP_FILE_RD, want, -1,
1266+
&got, &pinned_page);
12661267
if (ret < 0)
12671268
return ret;
12681269

@@ -1459,7 +1460,7 @@ static ssize_t ceph_write_iter(struct kiocb *iocb, struct iov_iter *from)
14591460
else
14601461
want = CEPH_CAP_FILE_BUFFER;
14611462
got = 0;
1462-
err = ceph_get_caps(ci, CEPH_CAP_FILE_WR, want, pos + count,
1463+
err = ceph_get_caps(file, CEPH_CAP_FILE_WR, want, pos + count,
14631464
&got, NULL);
14641465
if (err < 0)
14651466
goto out;
@@ -1783,7 +1784,7 @@ static long ceph_fallocate(struct file *file, int mode,
17831784
else
17841785
want = CEPH_CAP_FILE_BUFFER;
17851786

1786-
ret = ceph_get_caps(ci, CEPH_CAP_FILE_WR, want, endoff, &got, NULL);
1787+
ret = ceph_get_caps(file, CEPH_CAP_FILE_WR, want, endoff, &got, NULL);
17871788
if (ret < 0)
17881789
goto unlock;
17891790

@@ -1812,16 +1813,15 @@ static long ceph_fallocate(struct file *file, int mode,
18121813
* src_ci. Two attempts are made to obtain both caps, and an error is return if
18131814
* this fails; zero is returned on success.
18141815
*/
1815-
static int get_rd_wr_caps(struct ceph_inode_info *src_ci,
1816-
loff_t src_endoff, int *src_got,
1817-
struct ceph_inode_info *dst_ci,
1816+
static int get_rd_wr_caps(struct file *src_filp, int *src_got,
1817+
struct file *dst_filp,
18181818
loff_t dst_endoff, int *dst_got)
18191819
{
18201820
int ret = 0;
18211821
bool retrying = false;
18221822

18231823
retry_caps:
1824-
ret = ceph_get_caps(dst_ci, CEPH_CAP_FILE_WR, CEPH_CAP_FILE_BUFFER,
1824+
ret = ceph_get_caps(dst_filp, CEPH_CAP_FILE_WR, CEPH_CAP_FILE_BUFFER,
18251825
dst_endoff, dst_got, NULL);
18261826
if (ret < 0)
18271827
return ret;
@@ -1831,24 +1831,24 @@ static int get_rd_wr_caps(struct ceph_inode_info *src_ci,
18311831
* we would risk a deadlock by using ceph_get_caps. Thus, we'll do some
18321832
* retry dance instead to try to get both capabilities.
18331833
*/
1834-
ret = ceph_try_get_caps(src_ci, CEPH_CAP_FILE_RD, CEPH_CAP_FILE_SHARED,
1834+
ret = ceph_try_get_caps(file_inode(src_filp),
1835+
CEPH_CAP_FILE_RD, CEPH_CAP_FILE_SHARED,
18351836
false, src_got);
18361837
if (ret <= 0) {
18371838
/* Start by dropping dst_ci caps and getting src_ci caps */
1838-
ceph_put_cap_refs(dst_ci, *dst_got);
1839+
ceph_put_cap_refs(ceph_inode(file_inode(dst_filp)), *dst_got);
18391840
if (retrying) {
18401841
if (!ret)
18411842
/* ceph_try_get_caps masks EAGAIN */
18421843
ret = -EAGAIN;
18431844
return ret;
18441845
}
1845-
ret = ceph_get_caps(src_ci, CEPH_CAP_FILE_RD,
1846-
CEPH_CAP_FILE_SHARED, src_endoff,
1847-
src_got, NULL);
1846+
ret = ceph_get_caps(src_filp, CEPH_CAP_FILE_RD,
1847+
CEPH_CAP_FILE_SHARED, -1, src_got, NULL);
18481848
if (ret < 0)
18491849
return ret;
18501850
/*... drop src_ci caps too, and retry */
1851-
ceph_put_cap_refs(src_ci, *src_got);
1851+
ceph_put_cap_refs(ceph_inode(file_inode(src_filp)), *src_got);
18521852
retrying = true;
18531853
goto retry_caps;
18541854
}
@@ -1960,8 +1960,8 @@ static ssize_t __ceph_copy_file_range(struct file *src_file, loff_t src_off,
19601960
* clients may have dirty data in their caches. And OSDs know nothing
19611961
* about caps, so they can't safely do the remote object copies.
19621962
*/
1963-
err = get_rd_wr_caps(src_ci, (src_off + len), &src_got,
1964-
dst_ci, (dst_off + len), &dst_got);
1963+
err = get_rd_wr_caps(src_file, &src_got,
1964+
dst_file, (dst_off + len), &dst_got);
19651965
if (err < 0) {
19661966
dout("get_rd_wr_caps returned %d\n", err);
19671967
ret = -EOPNOTSUPP;
@@ -2018,9 +2018,8 @@ static ssize_t __ceph_copy_file_range(struct file *src_file, loff_t src_off,
20182018
goto out;
20192019
}
20202020
len -= ret;
2021-
err = get_rd_wr_caps(src_ci, (src_off + len),
2022-
&src_got, dst_ci,
2023-
(dst_off + len), &dst_got);
2021+
err = get_rd_wr_caps(src_file, &src_got,
2022+
dst_file, (dst_off + len), &dst_got);
20242023
if (err < 0)
20252024
goto out;
20262025
err = is_file_size_ok(src_inode, dst_inode,

‎fs/ceph/super.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,9 +1062,9 @@ extern int ceph_encode_dentry_release(void **p, struct dentry *dn,
10621062
struct inode *dir,
10631063
int mds, int drop, int unless);
10641064

1065-
extern int ceph_get_caps(struct ceph_inode_info *ci, int need, int want,
1065+
extern int ceph_get_caps(struct file *filp, int need, int want,
10661066
loff_t endoff, int *got, struct page **pinned_page);
1067-
extern int ceph_try_get_caps(struct ceph_inode_info *ci,
1067+
extern int ceph_try_get_caps(struct inode *inode,
10681068
int need, int want, bool nonblock, int *got);
10691069

10701070
/* for counting open files by mode */
@@ -1075,7 +1075,7 @@ extern void ceph_put_fmode(struct ceph_inode_info *ci, int mode);
10751075
extern const struct address_space_operations ceph_aops;
10761076
extern int ceph_mmap(struct file *file, struct vm_area_struct *vma);
10771077
extern int ceph_uninline_data(struct file *filp, struct page *locked_page);
1078-
extern int ceph_pool_perm_check(struct ceph_inode_info *ci, int need);
1078+
extern int ceph_pool_perm_check(struct inode *inode, int need);
10791079
extern void ceph_pool_perm_destroy(struct ceph_mds_client* mdsc);
10801080

10811081
/* file.c */

0 commit comments

Comments
 (0)