9p: switch p9_client_read() to passing struct iov_iter *
... and make it loop Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
9565a54452
commit
e1200fe68f
@ -68,8 +68,6 @@ int v9fs_file_open(struct inode *inode, struct file *file);
|
|||||||
void v9fs_inode2stat(struct inode *inode, struct p9_wstat *stat);
|
void v9fs_inode2stat(struct inode *inode, struct p9_wstat *stat);
|
||||||
int v9fs_uflags2omode(int uflags, int extended);
|
int v9fs_uflags2omode(int uflags, int extended);
|
||||||
|
|
||||||
ssize_t v9fs_file_readn(struct file *, char *, char __user *, u32, u64);
|
|
||||||
ssize_t v9fs_fid_readn(struct p9_fid *, char *, char __user *, u32, u64);
|
|
||||||
void v9fs_blank_wstat(struct p9_wstat *wstat);
|
void v9fs_blank_wstat(struct p9_wstat *wstat);
|
||||||
int v9fs_vfs_setattr_dotl(struct dentry *, struct iattr *);
|
int v9fs_vfs_setattr_dotl(struct dentry *, struct iattr *);
|
||||||
int v9fs_file_fsync_dotl(struct file *filp, loff_t start, loff_t end,
|
int v9fs_file_fsync_dotl(struct file *filp, loff_t start, loff_t end,
|
||||||
|
@ -51,12 +51,11 @@
|
|||||||
*/
|
*/
|
||||||
static int v9fs_fid_readpage(struct p9_fid *fid, struct page *page)
|
static int v9fs_fid_readpage(struct p9_fid *fid, struct page *page)
|
||||||
{
|
{
|
||||||
int retval;
|
struct inode *inode = page->mapping->host;
|
||||||
loff_t offset;
|
struct bio_vec bvec = {.bv_page = page, .bv_len = PAGE_SIZE};
|
||||||
char *buffer;
|
struct iov_iter to;
|
||||||
struct inode *inode;
|
int retval, err;
|
||||||
|
|
||||||
inode = page->mapping->host;
|
|
||||||
p9_debug(P9_DEBUG_VFS, "\n");
|
p9_debug(P9_DEBUG_VFS, "\n");
|
||||||
|
|
||||||
BUG_ON(!PageLocked(page));
|
BUG_ON(!PageLocked(page));
|
||||||
@ -65,16 +64,16 @@ static int v9fs_fid_readpage(struct p9_fid *fid, struct page *page)
|
|||||||
if (retval == 0)
|
if (retval == 0)
|
||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
buffer = kmap(page);
|
iov_iter_bvec(&to, ITER_BVEC | READ, &bvec, 1, PAGE_SIZE);
|
||||||
offset = page_offset(page);
|
|
||||||
|
|
||||||
retval = v9fs_fid_readn(fid, buffer, NULL, PAGE_CACHE_SIZE, offset);
|
retval = p9_client_read(fid, page_offset(page), &to, &err);
|
||||||
if (retval < 0) {
|
if (err) {
|
||||||
v9fs_uncache_page(inode, page);
|
v9fs_uncache_page(inode, page);
|
||||||
|
retval = err;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(buffer + retval, 0, PAGE_CACHE_SIZE - retval);
|
zero_user(page, retval, PAGE_SIZE - retval);
|
||||||
flush_dcache_page(page);
|
flush_dcache_page(page);
|
||||||
SetPageUptodate(page);
|
SetPageUptodate(page);
|
||||||
|
|
||||||
@ -82,7 +81,6 @@ static int v9fs_fid_readpage(struct p9_fid *fid, struct page *page)
|
|||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
||||||
done:
|
done:
|
||||||
kunmap(page);
|
|
||||||
unlock_page(page);
|
unlock_page(page);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
#include <linux/inet.h>
|
#include <linux/inet.h>
|
||||||
#include <linux/idr.h>
|
#include <linux/idr.h>
|
||||||
#include <linux/slab.h>
|
#include <linux/slab.h>
|
||||||
|
#include <linux/uio.h>
|
||||||
#include <net/9p/9p.h>
|
#include <net/9p/9p.h>
|
||||||
#include <net/9p/client.h>
|
#include <net/9p/client.h>
|
||||||
|
|
||||||
@ -115,6 +116,7 @@ static int v9fs_dir_readdir(struct file *file, struct dir_context *ctx)
|
|||||||
int buflen;
|
int buflen;
|
||||||
int reclen = 0;
|
int reclen = 0;
|
||||||
struct p9_rdir *rdir;
|
struct p9_rdir *rdir;
|
||||||
|
struct kvec kvec;
|
||||||
|
|
||||||
p9_debug(P9_DEBUG_VFS, "name %pD\n", file);
|
p9_debug(P9_DEBUG_VFS, "name %pD\n", file);
|
||||||
fid = file->private_data;
|
fid = file->private_data;
|
||||||
@ -124,16 +126,21 @@ static int v9fs_dir_readdir(struct file *file, struct dir_context *ctx)
|
|||||||
rdir = v9fs_alloc_rdir_buf(file, buflen);
|
rdir = v9fs_alloc_rdir_buf(file, buflen);
|
||||||
if (!rdir)
|
if (!rdir)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
kvec.iov_base = rdir->buf;
|
||||||
|
kvec.iov_len = buflen;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (rdir->tail == rdir->head) {
|
if (rdir->tail == rdir->head) {
|
||||||
err = v9fs_file_readn(file, rdir->buf, NULL,
|
struct iov_iter to;
|
||||||
buflen, ctx->pos);
|
int n;
|
||||||
if (err <= 0)
|
iov_iter_kvec(&to, READ | ITER_KVEC, &kvec, 1, buflen);
|
||||||
|
n = p9_client_read(file->private_data, ctx->pos, &to,
|
||||||
|
&err);
|
||||||
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
rdir->head = 0;
|
rdir->head = 0;
|
||||||
rdir->tail = err;
|
rdir->tail = n;
|
||||||
}
|
}
|
||||||
while (rdir->head < rdir->tail) {
|
while (rdir->head < rdir->tail) {
|
||||||
p9stat_init(&st);
|
p9stat_init(&st);
|
||||||
|
@ -364,63 +364,6 @@ out_err:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* v9fs_fid_readn - read from a fid
|
|
||||||
* @fid: fid to read
|
|
||||||
* @data: data buffer to read data into
|
|
||||||
* @udata: user data buffer to read data into
|
|
||||||
* @count: size of buffer
|
|
||||||
* @offset: offset at which to read data
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
ssize_t
|
|
||||||
v9fs_fid_readn(struct p9_fid *fid, char *data, char __user *udata, u32 count,
|
|
||||||
u64 offset)
|
|
||||||
{
|
|
||||||
int n, total, size;
|
|
||||||
|
|
||||||
p9_debug(P9_DEBUG_VFS, "fid %d offset %llu count %d\n",
|
|
||||||
fid->fid, (long long unsigned)offset, count);
|
|
||||||
n = 0;
|
|
||||||
total = 0;
|
|
||||||
size = fid->iounit ? fid->iounit : fid->clnt->msize - P9_IOHDRSZ;
|
|
||||||
do {
|
|
||||||
n = p9_client_read(fid, data, udata, offset, count);
|
|
||||||
if (n <= 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (data)
|
|
||||||
data += n;
|
|
||||||
if (udata)
|
|
||||||
udata += n;
|
|
||||||
|
|
||||||
offset += n;
|
|
||||||
count -= n;
|
|
||||||
total += n;
|
|
||||||
} while (count > 0 && n == size);
|
|
||||||
|
|
||||||
if (n < 0)
|
|
||||||
total = n;
|
|
||||||
|
|
||||||
return total;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* v9fs_file_readn - read from a file
|
|
||||||
* @filp: file pointer to read
|
|
||||||
* @data: data buffer to read data into
|
|
||||||
* @udata: user data buffer to read data into
|
|
||||||
* @count: size of buffer
|
|
||||||
* @offset: offset at which to read data
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
ssize_t
|
|
||||||
v9fs_file_readn(struct file *filp, char *data, char __user *udata, u32 count,
|
|
||||||
u64 offset)
|
|
||||||
{
|
|
||||||
return v9fs_fid_readn(filp->private_data, data, udata, count, offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* v9fs_file_read - read from a file
|
* v9fs_file_read - read from a file
|
||||||
* @filp: file pointer to read
|
* @filp: file pointer to read
|
||||||
@ -434,22 +377,20 @@ static ssize_t
|
|||||||
v9fs_file_read(struct file *filp, char __user *udata, size_t count,
|
v9fs_file_read(struct file *filp, char __user *udata, size_t count,
|
||||||
loff_t * offset)
|
loff_t * offset)
|
||||||
{
|
{
|
||||||
int ret;
|
struct p9_fid *fid = filp->private_data;
|
||||||
struct p9_fid *fid;
|
struct iovec iov = {.iov_base = udata, .iov_len = count};
|
||||||
size_t size;
|
struct iov_iter to;
|
||||||
|
int ret, err;
|
||||||
|
|
||||||
|
iov_iter_init(&to, READ, &iov, 1, count);
|
||||||
|
|
||||||
p9_debug(P9_DEBUG_VFS, "count %zu offset %lld\n", count, *offset);
|
p9_debug(P9_DEBUG_VFS, "count %zu offset %lld\n", count, *offset);
|
||||||
fid = filp->private_data;
|
|
||||||
|
|
||||||
size = fid->iounit ? fid->iounit : fid->clnt->msize - P9_IOHDRSZ;
|
ret = p9_client_read(fid, *offset, &to, &err);
|
||||||
if (count > size)
|
if (!ret)
|
||||||
ret = v9fs_file_readn(filp, NULL, udata, count, *offset);
|
return err;
|
||||||
else
|
|
||||||
ret = p9_client_read(fid, NULL, udata, *offset, count);
|
|
||||||
|
|
||||||
if (ret > 0)
|
|
||||||
*offset += ret;
|
|
||||||
|
|
||||||
|
*offset += ret;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,50 +26,34 @@ ssize_t v9fs_fid_xattr_get(struct p9_fid *fid, const char *name,
|
|||||||
void *buffer, size_t buffer_size)
|
void *buffer, size_t buffer_size)
|
||||||
{
|
{
|
||||||
ssize_t retval;
|
ssize_t retval;
|
||||||
int msize, read_count;
|
u64 attr_size;
|
||||||
u64 offset = 0, attr_size;
|
|
||||||
struct p9_fid *attr_fid;
|
struct p9_fid *attr_fid;
|
||||||
|
struct kvec kvec = {.iov_base = buffer, .iov_len = buffer_size};
|
||||||
|
struct iov_iter to;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
iov_iter_kvec(&to, READ | ITER_KVEC, &kvec, 1, buffer_size);
|
||||||
|
|
||||||
attr_fid = p9_client_xattrwalk(fid, name, &attr_size);
|
attr_fid = p9_client_xattrwalk(fid, name, &attr_size);
|
||||||
if (IS_ERR(attr_fid)) {
|
if (IS_ERR(attr_fid)) {
|
||||||
retval = PTR_ERR(attr_fid);
|
retval = PTR_ERR(attr_fid);
|
||||||
p9_debug(P9_DEBUG_VFS, "p9_client_attrwalk failed %zd\n",
|
p9_debug(P9_DEBUG_VFS, "p9_client_attrwalk failed %zd\n",
|
||||||
retval);
|
retval);
|
||||||
attr_fid = NULL;
|
return retval;
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
if (!buffer_size) {
|
|
||||||
/* request to get the attr_size */
|
|
||||||
retval = attr_size;
|
|
||||||
goto error;
|
|
||||||
}
|
}
|
||||||
if (attr_size > buffer_size) {
|
if (attr_size > buffer_size) {
|
||||||
retval = -ERANGE;
|
if (!buffer_size) /* request to get the attr_size */
|
||||||
goto error;
|
retval = attr_size;
|
||||||
}
|
|
||||||
msize = attr_fid->clnt->msize;
|
|
||||||
while (attr_size) {
|
|
||||||
if (attr_size > (msize - P9_IOHDRSZ))
|
|
||||||
read_count = msize - P9_IOHDRSZ;
|
|
||||||
else
|
else
|
||||||
read_count = attr_size;
|
retval = -ERANGE;
|
||||||
read_count = p9_client_read(attr_fid, ((char *)buffer)+offset,
|
} else {
|
||||||
NULL, offset, read_count);
|
iov_iter_truncate(&to, attr_size);
|
||||||
if (read_count < 0) {
|
retval = p9_client_read(attr_fid, 0, &to, &err);
|
||||||
/* error in xattr read */
|
if (err)
|
||||||
retval = read_count;
|
retval = err;
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
offset += read_count;
|
|
||||||
attr_size -= read_count;
|
|
||||||
}
|
}
|
||||||
/* Total read xattr bytes */
|
p9_client_clunk(attr_fid);
|
||||||
retval = offset;
|
|
||||||
error:
|
|
||||||
if (attr_fid)
|
|
||||||
p9_client_clunk(attr_fid);
|
|
||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -238,8 +238,7 @@ int p9_client_clunk(struct p9_fid *fid);
|
|||||||
int p9_client_fsync(struct p9_fid *fid, int datasync);
|
int p9_client_fsync(struct p9_fid *fid, int datasync);
|
||||||
int p9_client_remove(struct p9_fid *fid);
|
int p9_client_remove(struct p9_fid *fid);
|
||||||
int p9_client_unlinkat(struct p9_fid *dfid, const char *name, int flags);
|
int p9_client_unlinkat(struct p9_fid *dfid, const char *name, int flags);
|
||||||
int p9_client_read(struct p9_fid *fid, char *data, char __user *udata,
|
int p9_client_read(struct p9_fid *fid, u64 offset, struct iov_iter *to, int *err);
|
||||||
u64 offset, u32 count);
|
|
||||||
int p9_client_write(struct p9_fid *fid, u64 offset, struct iov_iter *from, int *err);
|
int p9_client_write(struct p9_fid *fid, u64 offset, struct iov_iter *from, int *err);
|
||||||
int p9_client_readdir(struct p9_fid *fid, char *data, u32 count, u64 offset);
|
int p9_client_readdir(struct p9_fid *fid, char *data, u32 count, u64 offset);
|
||||||
int p9dirent_read(struct p9_client *clnt, char *buf, int len,
|
int p9dirent_read(struct p9_client *clnt, char *buf, int len,
|
||||||
|
128
net/9p/client.c
128
net/9p/client.c
@ -1534,79 +1534,77 @@ error:
|
|||||||
EXPORT_SYMBOL(p9_client_unlinkat);
|
EXPORT_SYMBOL(p9_client_unlinkat);
|
||||||
|
|
||||||
int
|
int
|
||||||
p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
|
p9_client_read(struct p9_fid *fid, u64 offset, struct iov_iter *to, int *err)
|
||||||
u32 count)
|
|
||||||
{
|
{
|
||||||
char *dataptr;
|
struct p9_client *clnt = fid->clnt;
|
||||||
struct p9_req_t *req;
|
struct p9_req_t *req;
|
||||||
struct p9_client *clnt;
|
int total = 0;
|
||||||
int err, rsize, non_zc = 0;
|
|
||||||
struct iov_iter to;
|
|
||||||
union {
|
|
||||||
struct kvec kv;
|
|
||||||
struct iovec iov;
|
|
||||||
} v;
|
|
||||||
|
|
||||||
if (data) {
|
|
||||||
v.kv.iov_base = data;
|
|
||||||
v.kv.iov_len = count;
|
|
||||||
iov_iter_kvec(&to, ITER_KVEC | READ, &v.kv, 1, count);
|
|
||||||
} else {
|
|
||||||
v.iov.iov_base = udata;
|
|
||||||
v.iov.iov_len = count;
|
|
||||||
iov_iter_init(&to, READ, &v.iov, 1, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
p9_debug(P9_DEBUG_9P, ">>> TREAD fid %d offset %llu %d\n",
|
p9_debug(P9_DEBUG_9P, ">>> TREAD fid %d offset %llu %d\n",
|
||||||
fid->fid, (unsigned long long) offset, count);
|
fid->fid, (unsigned long long) offset, (int)iov_iter_count(to));
|
||||||
err = 0;
|
|
||||||
clnt = fid->clnt;
|
|
||||||
|
|
||||||
rsize = fid->iounit;
|
while (iov_iter_count(to)) {
|
||||||
if (!rsize || rsize > clnt->msize-P9_IOHDRSZ)
|
int count = iov_iter_count(to);
|
||||||
rsize = clnt->msize - P9_IOHDRSZ;
|
int rsize, non_zc = 0;
|
||||||
|
char *dataptr;
|
||||||
|
|
||||||
|
rsize = fid->iounit;
|
||||||
|
if (!rsize || rsize > clnt->msize-P9_IOHDRSZ)
|
||||||
|
rsize = clnt->msize - P9_IOHDRSZ;
|
||||||
|
|
||||||
if (count < rsize)
|
if (count < rsize)
|
||||||
rsize = count;
|
rsize = count;
|
||||||
|
|
||||||
/* Don't bother zerocopy for small IO (< 1024) */
|
/* Don't bother zerocopy for small IO (< 1024) */
|
||||||
if (clnt->trans_mod->zc_request && rsize > 1024) {
|
if (clnt->trans_mod->zc_request && rsize > 1024) {
|
||||||
/*
|
/*
|
||||||
* response header len is 11
|
* response header len is 11
|
||||||
* PDU Header(7) + IO Size (4)
|
* PDU Header(7) + IO Size (4)
|
||||||
*/
|
*/
|
||||||
req = p9_client_zc_rpc(clnt, P9_TREAD, &to, NULL, rsize, 0,
|
req = p9_client_zc_rpc(clnt, P9_TREAD, to, NULL, rsize,
|
||||||
11, "dqd", fid->fid,
|
0, 11, "dqd", fid->fid,
|
||||||
offset, rsize);
|
offset, rsize);
|
||||||
} else {
|
} else {
|
||||||
non_zc = 1;
|
non_zc = 1;
|
||||||
req = p9_client_rpc(clnt, P9_TREAD, "dqd", fid->fid, offset,
|
req = p9_client_rpc(clnt, P9_TREAD, "dqd", fid->fid, offset,
|
||||||
rsize);
|
rsize);
|
||||||
|
}
|
||||||
|
if (IS_ERR(req)) {
|
||||||
|
*err = PTR_ERR(req);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
*err = p9pdu_readf(req->rc, clnt->proto_version,
|
||||||
|
"D", &count, &dataptr);
|
||||||
|
if (*err) {
|
||||||
|
trace_9p_protocol_dump(clnt, req->rc);
|
||||||
|
p9_free_req(clnt, req);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
p9_debug(P9_DEBUG_9P, "<<< RREAD count %d\n", count);
|
||||||
|
if (!count) {
|
||||||
|
p9_free_req(clnt, req);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (non_zc) {
|
||||||
|
int n = copy_to_iter(dataptr, count, to);
|
||||||
|
total += n;
|
||||||
|
offset += n;
|
||||||
|
if (n != count) {
|
||||||
|
*err = -EFAULT;
|
||||||
|
p9_free_req(clnt, req);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
iov_iter_advance(to, count);
|
||||||
|
total += count;
|
||||||
|
offset += count;
|
||||||
|
}
|
||||||
|
p9_free_req(clnt, req);
|
||||||
}
|
}
|
||||||
if (IS_ERR(req)) {
|
return total;
|
||||||
err = PTR_ERR(req);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = p9pdu_readf(req->rc, clnt->proto_version, "D", &count, &dataptr);
|
|
||||||
if (err) {
|
|
||||||
trace_9p_protocol_dump(clnt, req->rc);
|
|
||||||
goto free_and_error;
|
|
||||||
}
|
|
||||||
|
|
||||||
p9_debug(P9_DEBUG_9P, "<<< RREAD count %d\n", count);
|
|
||||||
|
|
||||||
if (non_zc && copy_to_iter(dataptr, count, &to) != count) {
|
|
||||||
err = -EFAULT;
|
|
||||||
goto free_and_error;
|
|
||||||
}
|
|
||||||
p9_free_req(clnt, req);
|
|
||||||
return count;
|
|
||||||
|
|
||||||
free_and_error:
|
|
||||||
p9_free_req(clnt, req);
|
|
||||||
error:
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(p9_client_read);
|
EXPORT_SYMBOL(p9_client_read);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user