* \retval - number of bytes have been read, or error code if error occurred.
*/
static ssize_t
-ll_do_fast_read(const struct lu_env *env, struct kiocb *iocb,
- struct iov_iter *iter)
+ll_do_fast_read(struct kiocb *iocb, struct iov_iter *iter)
{
ssize_t result;
if (iocb->ki_filp->f_flags & O_DIRECT)
return 0;
- ll_cl_add(iocb->ki_filp, env, NULL, LCC_RW);
result = generic_file_read_iter(iocb, iter);
- ll_cl_remove(iocb->ki_filp, env);
/* If the first page is not in cache, generic_file_aio_read() will be
* returned with -ENODATA.
ssize_t rc2;
__u16 refcheck;
+ result = ll_do_fast_read(iocb, to);
+ if (result < 0 || iov_iter_count(to) == 0)
+ GOTO(out, result);
+
env = cl_env_get(&refcheck);
if (IS_ERR(env))
return PTR_ERR(env);
- result = ll_do_fast_read(env, iocb, to);
- if (result < 0 || iov_iter_count(to) == 0)
- GOTO(out, result);
-
args = ll_env_args(env, IO_NORMAL);
args->u.normal.via_iter = to;
args->u.normal.via_iocb = iocb;
else if (result == 0)
result = rc2;
-out:
cl_env_put(env, &refcheck);
+out:
return result;
}
static ssize_t ll_file_read(struct file *file, char __user *buf, size_t count,
loff_t *ppos)
{
- struct lu_env *env;
struct iovec iov = { .iov_base = buf, .iov_len = count };
- struct kiocb *kiocb;
+ struct kiocb kiocb;
ssize_t result;
- __u16 refcheck;
ENTRY;
- env = cl_env_get(&refcheck);
- if (IS_ERR(env))
- RETURN(PTR_ERR(env));
-
- kiocb = &ll_env_info(env)->lti_kiocb;
- init_sync_kiocb(kiocb, file);
- kiocb->ki_pos = *ppos;
+ init_sync_kiocb(&kiocb, file);
+ kiocb.ki_pos = *ppos;
#ifdef HAVE_KIOCB_KI_LEFT
- kiocb->ki_left = count;
+ kiocb.ki_left = count;
#elif defined(HAVE_KI_NBYTES)
- kiocb->ki_nbytes = count;
+ kiocb.i_nbytes = count;
#endif
- result = ll_file_aio_read(kiocb, &iov, 1, kiocb->ki_pos);
- *ppos = kiocb->ki_pos;
+ result = ll_file_aio_read(&kiocb, &iov, 1, kiocb.ki_pos);
+ *ppos = kiocb.ki_pos;
- cl_env_put(env, &refcheck);
RETURN(result);
}
struct inode *inode = file_inode(file);
struct cl_object *clob = ll_i2info(inode)->lli_clob;
struct ll_cl_context *lcc;
- const struct lu_env *env;
- struct cl_io *io;
+ const struct lu_env *env = NULL;
+ struct cl_io *io = NULL;
struct cl_page *page;
int result;
ENTRY;
lcc = ll_cl_find(file);
- if (lcc == NULL) {
- unlock_page(vmpage);
- RETURN(-EIO);
+ if (lcc != NULL) {
+ env = lcc->lcc_env;
+ io = lcc->lcc_io;
}
- env = lcc->lcc_env;
- io = lcc->lcc_io;
if (io == NULL) { /* fast read */
struct inode *inode = file_inode(file);
struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
struct ll_readahead_state *ras = &fd->fd_ras;
+ struct lu_env *local_env = NULL;
struct vvp_page *vpg;
result = -ENODATA;
RETURN(result);
}
+ if (!env) {
+ local_env = cl_env_percpu_get();
+ env = local_env;
+ }
+
vpg = cl2vvp_page(cl_object_page_slice(page->cp_obj, page));
if (vpg->vpg_defer_uptodate) {
enum ras_update_flags flags = LL_RAS_HIT;
- if (lcc->lcc_type == LCC_MMAP)
+ if (lcc && lcc->lcc_type == LCC_MMAP)
flags |= LL_RAS_MMAP;
/* For fast read, it updates read ahead state only
}
}
- unlock_page(vmpage);
+ /* release page refcount before unlocking the page to ensure
+ * the object won't be destroyed in the calling path of
+ * cl_page_put(). Please see comment in ll_releasepage(). */
cl_page_put(env, page);
+ unlock_page(vmpage);
+ if (local_env)
+ cl_env_percpu_put(local_env);
+
RETURN(result);
}