Commit 070b3656 authored by Al Viro's avatar Al Viro

9p: switch p9_client_write() to passing it struct iov_iter *

... and make it loop until it's done
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 4f3b35c1
......@@ -36,6 +36,7 @@
#include <linux/utsname.h>
#include <asm/uaccess.h>
#include <linux/idr.h>
#include <linux/uio.h>
#include <net/9p/9p.h>
#include <net/9p/client.h>
......@@ -457,24 +458,20 @@ v9fs_file_write_internal(struct inode *inode, struct p9_fid *fid,
const char __user *data, size_t count,
loff_t *offset, int invalidate)
{
int n;
loff_t i_size;
size_t total = 0;
loff_t origin = *offset;
unsigned long pg_start, pg_end;
struct iovec iov = {.iov_base = (void __user *)data, .iov_len = count};
struct iov_iter from;
int total, err = 0;
p9_debug(P9_DEBUG_VFS, "data %p count %d offset %x\n",
data, (int)count, (int)*offset);
do {
n = p9_client_write(fid, NULL, data+total, origin+total, count);
if (n <= 0)
break;
count -= n;
total += n;
} while (count > 0);
iov_iter_init(&from, WRITE, &iov, 1, count);
total = p9_client_write(fid, origin, &from, &err);
if (invalidate && (total > 0)) {
loff_t i_size;
unsigned long pg_start, pg_end;
pg_start = origin >> PAGE_CACHE_SHIFT;
pg_end = (origin + total - 1) >> PAGE_CACHE_SHIFT;
if (inode->i_mapping && inode->i_mapping->nrpages)
......@@ -487,10 +484,7 @@ v9fs_file_write_internal(struct inode *inode, struct p9_fid *fid,
i_size_write(inode, *offset);
}
}
if (n < 0)
return n;
return total;
return total ? total : err;
}
/**
......
......@@ -15,6 +15,7 @@
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/sched.h>
#include <linux/uio.h>
#include <net/9p/9p.h>
#include <net/9p/client.h>
......@@ -120,8 +121,11 @@ int v9fs_xattr_set(struct dentry *dentry, const char *name,
int v9fs_fid_xattr_set(struct p9_fid *fid, const char *name,
const void *value, size_t value_len, int flags)
{
u64 offset = 0;
int retval, msize, write_count;
struct kvec kvec = {.iov_base = (void *)value, .iov_len = value_len};
struct iov_iter from;
int retval;
iov_iter_kvec(&from, WRITE | ITER_KVEC, &kvec, 1, value_len);
p9_debug(P9_DEBUG_VFS, "name = %s value_len = %zu flags = %d\n",
name, value_len, flags);
......@@ -135,29 +139,11 @@ int v9fs_fid_xattr_set(struct p9_fid *fid, const char *name,
* On success fid points to xattr
*/
retval = p9_client_xattrcreate(fid, name, value_len, flags);
if (retval < 0) {
if (retval < 0)
p9_debug(P9_DEBUG_VFS, "p9_client_xattrcreate failed %d\n",
retval);
goto err;
}
msize = fid->clnt->msize;
while (value_len) {
if (value_len > (msize - P9_IOHDRSZ))
write_count = msize - P9_IOHDRSZ;
else
write_count = value_len;
write_count = p9_client_write(fid, ((char *)value)+offset,
NULL, offset, write_count);
if (write_count < 0) {
/* error in xattr write */
retval = write_count;
goto err;
}
offset += write_count;
value_len -= write_count;
}
retval = 0;
err:
else
p9_client_write(fid, 0, &from, &retval);
p9_client_clunk(fid);
return retval;
}
......
......@@ -211,6 +211,8 @@ struct p9_dirent {
char d_name[256];
};
struct iov_iter;
int p9_client_statfs(struct p9_fid *fid, struct p9_rstatfs *sb);
int p9_client_rename(struct p9_fid *fid, struct p9_fid *newdirfid,
const char *name);
......@@ -238,8 +240,7 @@ int p9_client_remove(struct p9_fid *fid);
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,
u64 offset, u32 count);
int p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
u64 offset, u32 count);
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 p9dirent_read(struct p9_client *clnt, char *buf, int len,
struct p9_dirent *dirent);
......
......@@ -1611,69 +1611,53 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
EXPORT_SYMBOL(p9_client_read);
int
p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
u64 offset, u32 count)
p9_client_write(struct p9_fid *fid, u64 offset, struct iov_iter *from, int *err)
{
int err, rsize;
struct p9_client *clnt;
struct p9_client *clnt = fid->clnt;
struct p9_req_t *req;
struct iov_iter from;
union {
struct kvec kv;
struct iovec iov;
} v;
if (data) {
v.kv.iov_base = data;
v.kv.iov_len = count;
iov_iter_kvec(&from, ITER_KVEC | WRITE, &v.kv, 1, count);
} else {
v.iov.iov_base = udata;
v.iov.iov_len = count;
iov_iter_init(&from, WRITE, &v.iov, 1, count);
}
p9_debug(P9_DEBUG_9P, ">>> TWRITE fid %d offset %llu count %d\n",
fid->fid, (unsigned long long) offset, count);
err = 0;
clnt = fid->clnt;
rsize = fid->iounit;
if (!rsize || rsize > clnt->msize-P9_IOHDRSZ)
rsize = clnt->msize - P9_IOHDRSZ;
int total = 0;
p9_debug(P9_DEBUG_9P, ">>> TWRITE fid %d offset %llu count %zd\n",
fid->fid, (unsigned long long) offset,
iov_iter_count(from));
while (iov_iter_count(from)) {
int count = iov_iter_count(from);
int rsize = fid->iounit;
if (!rsize || rsize > clnt->msize-P9_IOHDRSZ)
rsize = clnt->msize - P9_IOHDRSZ;
if (count < rsize)
rsize = count;
/* Don't bother zerocopy for small IO (< 1024) */
if (clnt->trans_mod->zc_request && rsize > 1024) {
req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, from, 0,
rsize, P9_ZC_HDR_SZ, "dqd",
fid->fid, offset, rsize);
} else {
req = p9_client_rpc(clnt, P9_TWRITE, "dqV", fid->fid,
offset, rsize, from);
}
if (IS_ERR(req)) {
*err = PTR_ERR(req);
break;
}
if (count < rsize)
rsize = count;
*err = p9pdu_readf(req->rc, clnt->proto_version, "d", &count);
if (*err) {
trace_9p_protocol_dump(clnt, req->rc);
p9_free_req(clnt, req);
}
/* Don't bother zerocopy for small IO (< 1024) */
if (clnt->trans_mod->zc_request && rsize > 1024) {
req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, &from, 0, rsize,
P9_ZC_HDR_SZ, "dqd",
fid->fid, offset, rsize);
} else {
req = p9_client_rpc(clnt, P9_TWRITE, "dqV", fid->fid,
offset, rsize, &from);
}
if (IS_ERR(req)) {
err = PTR_ERR(req);
goto error;
}
p9_debug(P9_DEBUG_9P, "<<< RWRITE count %d\n", count);
err = p9pdu_readf(req->rc, clnt->proto_version, "d", &count);
if (err) {
trace_9p_protocol_dump(clnt, req->rc);
goto free_and_error;
p9_free_req(clnt, req);
iov_iter_advance(from, count);
total += count;
offset += count;
}
p9_debug(P9_DEBUG_9P, "<<< RWRITE count %d\n", count);
p9_free_req(clnt, req);
return count;
free_and_error:
p9_free_req(clnt, req);
error:
return err;
return total;
}
EXPORT_SYMBOL(p9_client_write);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment