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 @@ ...@@ -36,6 +36,7 @@
#include <linux/utsname.h> #include <linux/utsname.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <linux/idr.h> #include <linux/idr.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>
...@@ -457,24 +458,20 @@ v9fs_file_write_internal(struct inode *inode, struct p9_fid *fid, ...@@ -457,24 +458,20 @@ v9fs_file_write_internal(struct inode *inode, struct p9_fid *fid,
const char __user *data, size_t count, const char __user *data, size_t count,
loff_t *offset, int invalidate) loff_t *offset, int invalidate)
{ {
int n;
loff_t i_size;
size_t total = 0;
loff_t origin = *offset; 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", p9_debug(P9_DEBUG_VFS, "data %p count %d offset %x\n",
data, (int)count, (int)*offset); data, (int)count, (int)*offset);
do { iov_iter_init(&from, WRITE, &iov, 1, count);
n = p9_client_write(fid, NULL, data+total, origin+total, count);
if (n <= 0)
break;
count -= n;
total += n;
} while (count > 0);
total = p9_client_write(fid, origin, &from, &err);
if (invalidate && (total > 0)) { if (invalidate && (total > 0)) {
loff_t i_size;
unsigned long pg_start, pg_end;
pg_start = origin >> PAGE_CACHE_SHIFT; pg_start = origin >> PAGE_CACHE_SHIFT;
pg_end = (origin + total - 1) >> PAGE_CACHE_SHIFT; pg_end = (origin + total - 1) >> PAGE_CACHE_SHIFT;
if (inode->i_mapping && inode->i_mapping->nrpages) if (inode->i_mapping && inode->i_mapping->nrpages)
...@@ -487,10 +484,7 @@ v9fs_file_write_internal(struct inode *inode, struct p9_fid *fid, ...@@ -487,10 +484,7 @@ v9fs_file_write_internal(struct inode *inode, struct p9_fid *fid,
i_size_write(inode, *offset); i_size_write(inode, *offset);
} }
} }
if (n < 0) return total ? total : err;
return n;
return total;
} }
/** /**
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/sched.h> #include <linux/sched.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>
...@@ -120,8 +121,11 @@ int v9fs_xattr_set(struct dentry *dentry, const char *name, ...@@ -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, int v9fs_fid_xattr_set(struct p9_fid *fid, const char *name,
const void *value, size_t value_len, int flags) const void *value, size_t value_len, int flags)
{ {
u64 offset = 0; struct kvec kvec = {.iov_base = (void *)value, .iov_len = value_len};
int retval, msize, write_count; 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", p9_debug(P9_DEBUG_VFS, "name = %s value_len = %zu flags = %d\n",
name, value_len, flags); name, value_len, flags);
...@@ -135,29 +139,11 @@ int v9fs_fid_xattr_set(struct p9_fid *fid, const char *name, ...@@ -135,29 +139,11 @@ int v9fs_fid_xattr_set(struct p9_fid *fid, const char *name,
* On success fid points to xattr * On success fid points to xattr
*/ */
retval = p9_client_xattrcreate(fid, name, value_len, flags); 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", p9_debug(P9_DEBUG_VFS, "p9_client_xattrcreate failed %d\n",
retval); retval);
goto err;
}
msize = fid->clnt->msize;
while (value_len) {
if (value_len > (msize - P9_IOHDRSZ))
write_count = msize - P9_IOHDRSZ;
else else
write_count = value_len; p9_client_write(fid, 0, &from, &retval);
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:
p9_client_clunk(fid); p9_client_clunk(fid);
return retval; return retval;
} }
......
...@@ -211,6 +211,8 @@ struct p9_dirent { ...@@ -211,6 +211,8 @@ struct p9_dirent {
char d_name[256]; char d_name[256];
}; };
struct iov_iter;
int p9_client_statfs(struct p9_fid *fid, struct p9_rstatfs *sb); int p9_client_statfs(struct p9_fid *fid, struct p9_rstatfs *sb);
int p9_client_rename(struct p9_fid *fid, struct p9_fid *newdirfid, int p9_client_rename(struct p9_fid *fid, struct p9_fid *newdirfid,
const char *name); const char *name);
...@@ -238,8 +240,7 @@ int p9_client_remove(struct p9_fid *fid); ...@@ -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_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, char *data, char __user *udata,
u64 offset, u32 count); u64 offset, u32 count);
int p9_client_write(struct p9_fid *fid, char *data, const char __user *udata, int p9_client_write(struct p9_fid *fid, u64 offset, struct iov_iter *from, int *err);
u64 offset, u32 count);
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,
struct p9_dirent *dirent); struct p9_dirent *dirent);
......
...@@ -1611,34 +1611,19 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset, ...@@ -1611,34 +1611,19 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
EXPORT_SYMBOL(p9_client_read); EXPORT_SYMBOL(p9_client_read);
int int
p9_client_write(struct p9_fid *fid, char *data, const char __user *udata, p9_client_write(struct p9_fid *fid, u64 offset, struct iov_iter *from, int *err)
u64 offset, u32 count)
{ {
int err, rsize; struct p9_client *clnt = fid->clnt;
struct p9_client *clnt;
struct p9_req_t *req; struct p9_req_t *req;
struct iov_iter from; int total = 0;
union {
struct kvec kv;
struct iovec iov;
} v;
if (data) { p9_debug(P9_DEBUG_9P, ">>> TWRITE fid %d offset %llu count %zd\n",
v.kv.iov_base = data; fid->fid, (unsigned long long) offset,
v.kv.iov_len = count; iov_iter_count(from));
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; while (iov_iter_count(from)) {
int count = iov_iter_count(from);
int rsize = fid->iounit;
if (!rsize || rsize > clnt->msize-P9_IOHDRSZ) if (!rsize || rsize > clnt->msize-P9_IOHDRSZ)
rsize = clnt->msize - P9_IOHDRSZ; rsize = clnt->msize - P9_IOHDRSZ;
...@@ -1647,33 +1632,32 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata, ...@@ -1647,33 +1632,32 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
/* 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) {
req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, &from, 0, rsize, req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, from, 0,
P9_ZC_HDR_SZ, "dqd", rsize, P9_ZC_HDR_SZ, "dqd",
fid->fid, offset, rsize); fid->fid, offset, rsize);
} else { } else {
req = p9_client_rpc(clnt, P9_TWRITE, "dqV", fid->fid, req = p9_client_rpc(clnt, P9_TWRITE, "dqV", fid->fid,
offset, rsize, &from); offset, rsize, from);
} }
if (IS_ERR(req)) { if (IS_ERR(req)) {
err = PTR_ERR(req); *err = PTR_ERR(req);
goto error; break;
} }
err = p9pdu_readf(req->rc, clnt->proto_version, "d", &count); *err = p9pdu_readf(req->rc, clnt->proto_version, "d", &count);
if (err) { if (*err) {
trace_9p_protocol_dump(clnt, req->rc); trace_9p_protocol_dump(clnt, req->rc);
goto free_and_error; p9_free_req(clnt, req);
} }
p9_debug(P9_DEBUG_9P, "<<< RWRITE count %d\n", count); p9_debug(P9_DEBUG_9P, "<<< RWRITE count %d\n", count);
p9_free_req(clnt, req); p9_free_req(clnt, req);
return count; iov_iter_advance(from, count);
total += count;
free_and_error: offset += count;
p9_free_req(clnt, req); }
error: return total;
return err;
} }
EXPORT_SYMBOL(p9_client_write); 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