Skip to content

Commit 23ee27d

Browse files
lxbszidryomov
authored andcommitted
ceph: add a dedicated private data for netfs rreq
We need to save the 'f_ra.ra_pages' to expand the readahead window later. Cc: [email protected] Fixes: 4987005 ("ceph: convert ceph_readpages to ceph_readahead") Link: https://lore.kernel.org/ceph-devel/[email protected] Link: https://www.spinics.net/lists/ceph-users/msg76183.html Signed-off-by: Xiubo Li <[email protected]> Reviewed-and-tested-by: Hu Weiwen <[email protected]> Reviewed-by: Milind Changire <[email protected]> Signed-off-by: Ilya Dryomov <[email protected]>
1 parent d9d00f7 commit 23ee27d

File tree

2 files changed

+47
-11
lines changed

2 files changed

+47
-11
lines changed

fs/ceph/addr.c

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -362,18 +362,28 @@ static int ceph_init_request(struct netfs_io_request *rreq, struct file *file)
362362
{
363363
struct inode *inode = rreq->inode;
364364
int got = 0, want = CEPH_CAP_FILE_CACHE;
365+
struct ceph_netfs_request_data *priv;
365366
int ret = 0;
366367

367368
if (rreq->origin != NETFS_READAHEAD)
368369
return 0;
369370

371+
priv = kzalloc(sizeof(*priv), GFP_NOFS);
372+
if (!priv)
373+
return -ENOMEM;
374+
370375
if (file) {
371376
struct ceph_rw_context *rw_ctx;
372377
struct ceph_file_info *fi = file->private_data;
373378

379+
priv->file_ra_pages = file->f_ra.ra_pages;
380+
priv->file_ra_disabled = file->f_mode & FMODE_RANDOM;
381+
374382
rw_ctx = ceph_find_rw_context(fi);
375-
if (rw_ctx)
383+
if (rw_ctx) {
384+
rreq->netfs_priv = priv;
376385
return 0;
386+
}
377387
}
378388

379389
/*
@@ -383,27 +393,40 @@ static int ceph_init_request(struct netfs_io_request *rreq, struct file *file)
383393
ret = ceph_try_get_caps(inode, CEPH_CAP_FILE_RD, want, true, &got);
384394
if (ret < 0) {
385395
dout("start_read %p, error getting cap\n", inode);
386-
return ret;
396+
goto out;
387397
}
388398

389399
if (!(got & want)) {
390400
dout("start_read %p, no cache cap\n", inode);
391-
return -EACCES;
401+
ret = -EACCES;
402+
goto out;
403+
}
404+
if (ret == 0) {
405+
ret = -EACCES;
406+
goto out;
392407
}
393-
if (ret == 0)
394-
return -EACCES;
395408

396-
rreq->netfs_priv = (void *)(uintptr_t)got;
397-
return 0;
409+
priv->caps = got;
410+
rreq->netfs_priv = priv;
411+
412+
out:
413+
if (ret < 0)
414+
kfree(priv);
415+
416+
return ret;
398417
}
399418

400419
static void ceph_netfs_free_request(struct netfs_io_request *rreq)
401420
{
402-
struct ceph_inode_info *ci = ceph_inode(rreq->inode);
403-
int got = (uintptr_t)rreq->netfs_priv;
421+
struct ceph_netfs_request_data *priv = rreq->netfs_priv;
422+
423+
if (!priv)
424+
return;
404425

405-
if (got)
406-
ceph_put_cap_refs(ci, got);
426+
if (priv->caps)
427+
ceph_put_cap_refs(ceph_inode(rreq->inode), priv->caps);
428+
kfree(priv);
429+
rreq->netfs_priv = NULL;
407430
}
408431

409432
const struct netfs_request_ops ceph_netfs_ops = {

fs/ceph/super.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,19 @@ struct ceph_inode_info {
451451
unsigned long i_work_mask;
452452
};
453453

454+
struct ceph_netfs_request_data {
455+
int caps;
456+
457+
/*
458+
* Maximum size of a file readahead request.
459+
* The fadvise could update the bdi's default ra_pages.
460+
*/
461+
unsigned int file_ra_pages;
462+
463+
/* Set it if fadvise disables file readahead entirely */
464+
bool file_ra_disabled;
465+
};
466+
454467
static inline struct ceph_inode_info *
455468
ceph_inode(const struct inode *inode)
456469
{

0 commit comments

Comments
 (0)