Skip to content

Commit

Permalink
switch generic_file_splice_read() to use of ->read_iter()
Browse files Browse the repository at this point in the history
... and kill the ->splice_read() instances that can be switched to it

Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
Al Viro committed Oct 5, 2016
1 parent 241699c commit 82c156f
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 605 deletions.
70 changes: 15 additions & 55 deletions drivers/staging/lustre/lustre/llite/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1153,36 +1153,21 @@ ll_file_io_generic(const struct lu_env *env, struct vvp_io_args *args,
int write_mutex_locked = 0;

vio->vui_fd = LUSTRE_FPRIVATE(file);
vio->vui_io_subtype = args->via_io_subtype;

switch (vio->vui_io_subtype) {
case IO_NORMAL:
vio->vui_iter = args->u.normal.via_iter;
vio->vui_iocb = args->u.normal.via_iocb;
if ((iot == CIT_WRITE) &&
!(vio->vui_fd->fd_flags & LL_FILE_GROUP_LOCKED)) {
if (mutex_lock_interruptible(&lli->
lli_write_mutex)) {
result = -ERESTARTSYS;
goto out;
}
write_mutex_locked = 1;
vio->vui_iter = args->u.normal.via_iter;
vio->vui_iocb = args->u.normal.via_iocb;
if ((iot == CIT_WRITE) &&
!(vio->vui_fd->fd_flags & LL_FILE_GROUP_LOCKED)) {
if (mutex_lock_interruptible(&lli->lli_write_mutex)) {
result = -ERESTARTSYS;
goto out;
}
down_read(&lli->lli_trunc_sem);
break;
case IO_SPLICE:
vio->u.splice.vui_pipe = args->u.splice.via_pipe;
vio->u.splice.vui_flags = args->u.splice.via_flags;
break;
default:
CERROR("Unknown IO type - %u\n", vio->vui_io_subtype);
LBUG();
write_mutex_locked = 1;
}
down_read(&lli->lli_trunc_sem);
ll_cl_add(file, env, io);
result = cl_io_loop(env, io);
ll_cl_remove(file, env);
if (args->via_io_subtype == IO_NORMAL)
up_read(&lli->lli_trunc_sem);
up_read(&lli->lli_trunc_sem);
if (write_mutex_locked)
mutex_unlock(&lli->lli_write_mutex);
} else {
Expand Down Expand Up @@ -1237,7 +1222,7 @@ static ssize_t ll_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
if (IS_ERR(env))
return PTR_ERR(env);

args = ll_env_args(env, IO_NORMAL);
args = ll_env_args(env);
args->u.normal.via_iter = to;
args->u.normal.via_iocb = iocb;

Expand All @@ -1261,7 +1246,7 @@ static ssize_t ll_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
if (IS_ERR(env))
return PTR_ERR(env);

args = ll_env_args(env, IO_NORMAL);
args = ll_env_args(env);
args->u.normal.via_iter = from;
args->u.normal.via_iocb = iocb;

Expand All @@ -1271,31 +1256,6 @@ static ssize_t ll_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
return result;
}

/*
* Send file content (through pagecache) somewhere with helper
*/
static ssize_t ll_file_splice_read(struct file *in_file, loff_t *ppos,
struct pipe_inode_info *pipe, size_t count,
unsigned int flags)
{
struct lu_env *env;
struct vvp_io_args *args;
ssize_t result;
int refcheck;

env = cl_env_get(&refcheck);
if (IS_ERR(env))
return PTR_ERR(env);

args = ll_env_args(env, IO_SPLICE);
args->u.splice.via_pipe = pipe;
args->u.splice.via_flags = flags;

result = ll_file_io_generic(env, args, in_file, CIT_READ, ppos, count);
cl_env_put(env, &refcheck);
return result;
}

static int ll_lov_recreate(struct inode *inode, struct ost_id *oi, u32 ost_idx)
{
struct obd_export *exp = ll_i2dtexp(inode);
Expand Down Expand Up @@ -3173,7 +3133,7 @@ struct file_operations ll_file_operations = {
.release = ll_file_release,
.mmap = ll_file_mmap,
.llseek = ll_file_seek,
.splice_read = ll_file_splice_read,
.splice_read = generic_file_splice_read,
.fsync = ll_fsync,
.flush = ll_flush
};
Expand All @@ -3186,7 +3146,7 @@ struct file_operations ll_file_operations_flock = {
.release = ll_file_release,
.mmap = ll_file_mmap,
.llseek = ll_file_seek,
.splice_read = ll_file_splice_read,
.splice_read = generic_file_splice_read,
.fsync = ll_fsync,
.flush = ll_flush,
.flock = ll_file_flock,
Expand All @@ -3202,7 +3162,7 @@ struct file_operations ll_file_operations_noflock = {
.release = ll_file_release,
.mmap = ll_file_mmap,
.llseek = ll_file_seek,
.splice_read = ll_file_splice_read,
.splice_read = generic_file_splice_read,
.fsync = ll_fsync,
.flush = ll_flush,
.flock = ll_file_noflock,
Expand Down
15 changes: 2 additions & 13 deletions drivers/staging/lustre/lustre/llite/llite_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -800,17 +800,11 @@ void vvp_write_complete(struct vvp_object *club, struct vvp_page *page);
*/
struct vvp_io_args {
/** normal/splice */
enum vvp_io_subtype via_io_subtype;

union {
struct {
struct kiocb *via_iocb;
struct iov_iter *via_iter;
} normal;
struct {
struct pipe_inode_info *via_pipe;
unsigned int via_flags;
} splice;
} u;
};

Expand Down Expand Up @@ -838,14 +832,9 @@ static inline struct ll_thread_info *ll_env_info(const struct lu_env *env)
return lti;
}

static inline struct vvp_io_args *ll_env_args(const struct lu_env *env,
enum vvp_io_subtype type)
static inline struct vvp_io_args *ll_env_args(const struct lu_env *env)
{
struct vvp_io_args *via = &ll_env_info(env)->lti_args;

via->via_io_subtype = type;

return via;
return &ll_env_info(env)->lti_args;
}

void ll_queue_done_writing(struct inode *inode, unsigned long flags);
Expand Down
14 changes: 0 additions & 14 deletions drivers/staging/lustre/lustre/llite/vvp_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,6 @@ struct obd_device;
struct obd_export;
struct page;

/* specific architecture can implement only part of this list */
enum vvp_io_subtype {
/** normal IO */
IO_NORMAL,
/** io started from splice_{read|write} */
IO_SPLICE
};

/**
* IO state private to IO state private to VVP layer.
*/
Expand Down Expand Up @@ -98,10 +90,6 @@ struct vvp_io {
*/
bool ft_flags_valid;
} fault;
struct {
struct pipe_inode_info *vui_pipe;
unsigned int vui_flags;
} splice;
struct {
struct cl_page_list vui_queue;
unsigned long vui_written;
Expand All @@ -110,8 +98,6 @@ struct vvp_io {
} write;
} u;

enum vvp_io_subtype vui_io_subtype;

/**
* Layout version when this IO is initialized
*/
Expand Down
45 changes: 4 additions & 41 deletions drivers/staging/lustre/lustre/llite/vvp_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,6 @@ static struct vvp_io *cl2vvp_io(const struct lu_env *env,
return vio;
}

/**
* True, if \a io is a normal io, False for splice_{read,write}
*/
static int cl_is_normalio(const struct lu_env *env, const struct cl_io *io)
{
struct vvp_io *vio = vvp_env_io(env);

LASSERT(io->ci_type == CIT_READ || io->ci_type == CIT_WRITE);

return vio->vui_io_subtype == IO_NORMAL;
}

/**
* For swapping layout. The file's layout may have changed.
* To avoid populating pages to a wrong stripe, we have to verify the
Expand Down Expand Up @@ -391,9 +379,6 @@ static int vvp_mmap_locks(const struct lu_env *env,

LASSERT(io->ci_type == CIT_READ || io->ci_type == CIT_WRITE);

if (!cl_is_normalio(env, io))
return 0;

if (!vio->vui_iter) /* nfs or loop back device write */
return 0;

Expand Down Expand Up @@ -462,15 +447,10 @@ static void vvp_io_advance(const struct lu_env *env,
const struct cl_io_slice *ios,
size_t nob)
{
struct vvp_io *vio = cl2vvp_io(env, ios);
struct cl_io *io = ios->cis_io;
struct cl_object *obj = ios->cis_io->ci_obj;

struct vvp_io *vio = cl2vvp_io(env, ios);
CLOBINVRNT(env, obj, vvp_object_invariant(obj));

if (!cl_is_normalio(env, io))
return;

iov_iter_reexpand(vio->vui_iter, vio->vui_tot_count -= nob);
}

Expand All @@ -479,7 +459,7 @@ static void vvp_io_update_iov(const struct lu_env *env,
{
size_t size = io->u.ci_rw.crw_count;

if (!cl_is_normalio(env, io) || !vio->vui_iter)
if (!vio->vui_iter)
return;

iov_iter_truncate(vio->vui_iter, size);
Expand Down Expand Up @@ -716,25 +696,8 @@ static int vvp_io_read_start(const struct lu_env *env,

/* BUG: 5972 */
file_accessed(file);
switch (vio->vui_io_subtype) {
case IO_NORMAL:
LASSERT(vio->vui_iocb->ki_pos == pos);
result = generic_file_read_iter(vio->vui_iocb, vio->vui_iter);
break;
case IO_SPLICE:
result = generic_file_splice_read(file, &pos,
vio->u.splice.vui_pipe, cnt,
vio->u.splice.vui_flags);
/* LU-1109: do splice read stripe by stripe otherwise if it
* may make nfsd stuck if this read occupied all internal pipe
* buffers.
*/
io->ci_continue = 0;
break;
default:
CERROR("Wrong IO type %u\n", vio->vui_io_subtype);
LBUG();
}
LASSERT(vio->vui_iocb->ki_pos == pos);
result = generic_file_read_iter(vio->vui_iocb, vio->vui_iter);

out:
if (result >= 0) {
Expand Down
23 changes: 1 addition & 22 deletions fs/coda/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,6 @@ coda_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
return vfs_iter_read(cfi->cfi_container, to, &iocb->ki_pos);
}

static ssize_t
coda_file_splice_read(struct file *coda_file, loff_t *ppos,
struct pipe_inode_info *pipe, size_t count,
unsigned int flags)
{
ssize_t (*splice_read)(struct file *, loff_t *,
struct pipe_inode_info *, size_t, unsigned int);
struct coda_file_info *cfi;
struct file *host_file;

cfi = CODA_FTOC(coda_file);
BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC);
host_file = cfi->cfi_container;

splice_read = host_file->f_op->splice_read;
if (!splice_read)
splice_read = default_file_splice_read;

return splice_read(host_file, ppos, pipe, count, flags);
}

static ssize_t
coda_file_write_iter(struct kiocb *iocb, struct iov_iter *to)
{
Expand Down Expand Up @@ -225,6 +204,6 @@ const struct file_operations coda_file_operations = {
.open = coda_open,
.release = coda_release,
.fsync = coda_fsync,
.splice_read = coda_file_splice_read,
.splice_read = generic_file_splice_read,
};

28 changes: 2 additions & 26 deletions fs/gfs2/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -954,30 +954,6 @@ static long gfs2_fallocate(struct file *file, int mode, loff_t offset, loff_t le
return ret;
}

static ssize_t gfs2_file_splice_read(struct file *in, loff_t *ppos,
struct pipe_inode_info *pipe, size_t len,
unsigned int flags)
{
struct inode *inode = in->f_mapping->host;
struct gfs2_inode *ip = GFS2_I(inode);
struct gfs2_holder gh;
int ret;

inode_lock(inode);

ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &gh);
if (ret) {
inode_unlock(inode);
return ret;
}

gfs2_glock_dq_uninit(&gh);
inode_unlock(inode);

return generic_file_splice_read(in, ppos, pipe, len, flags);
}


static ssize_t gfs2_file_splice_write(struct pipe_inode_info *pipe,
struct file *out, loff_t *ppos,
size_t len, unsigned int flags)
Expand Down Expand Up @@ -1140,7 +1116,7 @@ const struct file_operations gfs2_file_fops = {
.fsync = gfs2_fsync,
.lock = gfs2_lock,
.flock = gfs2_flock,
.splice_read = gfs2_file_splice_read,
.splice_read = generic_file_splice_read,
.splice_write = gfs2_file_splice_write,
.setlease = simple_nosetlease,
.fallocate = gfs2_fallocate,
Expand Down Expand Up @@ -1168,7 +1144,7 @@ const struct file_operations gfs2_file_fops_nolock = {
.open = gfs2_open,
.release = gfs2_release,
.fsync = gfs2_fsync,
.splice_read = gfs2_file_splice_read,
.splice_read = generic_file_splice_read,
.splice_write = gfs2_file_splice_write,
.setlease = generic_setlease,
.fallocate = gfs2_fallocate,
Expand Down
Loading

0 comments on commit 82c156f

Please sign in to comment.