Skip to content

Commit 070b365

Browse files
author
Al Viro
committed
9p: switch p9_client_write() to passing it struct iov_iter *
... and make it loop until it's done Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 4f3b35c commit 070b365

File tree

4 files changed

+62
-97
lines changed

4 files changed

+62
-97
lines changed

fs/9p/vfs_file.c

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <linux/utsname.h>
3737
#include <asm/uaccess.h>
3838
#include <linux/idr.h>
39+
#include <linux/uio.h>
3940
#include <net/9p/9p.h>
4041
#include <net/9p/client.h>
4142

@@ -457,24 +458,20 @@ v9fs_file_write_internal(struct inode *inode, struct p9_fid *fid,
457458
const char __user *data, size_t count,
458459
loff_t *offset, int invalidate)
459460
{
460-
int n;
461-
loff_t i_size;
462-
size_t total = 0;
463461
loff_t origin = *offset;
464-
unsigned long pg_start, pg_end;
462+
struct iovec iov = {.iov_base = (void __user *)data, .iov_len = count};
463+
struct iov_iter from;
464+
int total, err = 0;
465465

466466
p9_debug(P9_DEBUG_VFS, "data %p count %d offset %x\n",
467467
data, (int)count, (int)*offset);
468468

469-
do {
470-
n = p9_client_write(fid, NULL, data+total, origin+total, count);
471-
if (n <= 0)
472-
break;
473-
count -= n;
474-
total += n;
475-
} while (count > 0);
469+
iov_iter_init(&from, WRITE, &iov, 1, count);
476470

471+
total = p9_client_write(fid, origin, &from, &err);
477472
if (invalidate && (total > 0)) {
473+
loff_t i_size;
474+
unsigned long pg_start, pg_end;
478475
pg_start = origin >> PAGE_CACHE_SHIFT;
479476
pg_end = (origin + total - 1) >> PAGE_CACHE_SHIFT;
480477
if (inode->i_mapping && inode->i_mapping->nrpages)
@@ -487,10 +484,7 @@ v9fs_file_write_internal(struct inode *inode, struct p9_fid *fid,
487484
i_size_write(inode, *offset);
488485
}
489486
}
490-
if (n < 0)
491-
return n;
492-
493-
return total;
487+
return total ? total : err;
494488
}
495489

496490
/**

fs/9p/xattr.c

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/module.h>
1616
#include <linux/fs.h>
1717
#include <linux/sched.h>
18+
#include <linux/uio.h>
1819
#include <net/9p/9p.h>
1920
#include <net/9p/client.h>
2021

@@ -120,8 +121,11 @@ int v9fs_xattr_set(struct dentry *dentry, const char *name,
120121
int v9fs_fid_xattr_set(struct p9_fid *fid, const char *name,
121122
const void *value, size_t value_len, int flags)
122123
{
123-
u64 offset = 0;
124-
int retval, msize, write_count;
124+
struct kvec kvec = {.iov_base = (void *)value, .iov_len = value_len};
125+
struct iov_iter from;
126+
int retval;
127+
128+
iov_iter_kvec(&from, WRITE | ITER_KVEC, &kvec, 1, value_len);
125129

126130
p9_debug(P9_DEBUG_VFS, "name = %s value_len = %zu flags = %d\n",
127131
name, value_len, flags);
@@ -135,29 +139,11 @@ int v9fs_fid_xattr_set(struct p9_fid *fid, const char *name,
135139
* On success fid points to xattr
136140
*/
137141
retval = p9_client_xattrcreate(fid, name, value_len, flags);
138-
if (retval < 0) {
142+
if (retval < 0)
139143
p9_debug(P9_DEBUG_VFS, "p9_client_xattrcreate failed %d\n",
140144
retval);
141-
goto err;
142-
}
143-
msize = fid->clnt->msize;
144-
while (value_len) {
145-
if (value_len > (msize - P9_IOHDRSZ))
146-
write_count = msize - P9_IOHDRSZ;
147-
else
148-
write_count = value_len;
149-
write_count = p9_client_write(fid, ((char *)value)+offset,
150-
NULL, offset, write_count);
151-
if (write_count < 0) {
152-
/* error in xattr write */
153-
retval = write_count;
154-
goto err;
155-
}
156-
offset += write_count;
157-
value_len -= write_count;
158-
}
159-
retval = 0;
160-
err:
145+
else
146+
p9_client_write(fid, 0, &from, &retval);
161147
p9_client_clunk(fid);
162148
return retval;
163149
}

include/net/9p/client.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ struct p9_dirent {
211211
char d_name[256];
212212
};
213213

214+
struct iov_iter;
215+
214216
int p9_client_statfs(struct p9_fid *fid, struct p9_rstatfs *sb);
215217
int p9_client_rename(struct p9_fid *fid, struct p9_fid *newdirfid,
216218
const char *name);
@@ -238,8 +240,7 @@ int p9_client_remove(struct p9_fid *fid);
238240
int p9_client_unlinkat(struct p9_fid *dfid, const char *name, int flags);
239241
int p9_client_read(struct p9_fid *fid, char *data, char __user *udata,
240242
u64 offset, u32 count);
241-
int p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
242-
u64 offset, u32 count);
243+
int p9_client_write(struct p9_fid *fid, u64 offset, struct iov_iter *from, int *err);
243244
int p9_client_readdir(struct p9_fid *fid, char *data, u32 count, u64 offset);
244245
int p9dirent_read(struct p9_client *clnt, char *buf, int len,
245246
struct p9_dirent *dirent);

net/9p/client.c

Lines changed: 41 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,69 +1611,53 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
16111611
EXPORT_SYMBOL(p9_client_read);
16121612

16131613
int
1614-
p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
1615-
u64 offset, u32 count)
1614+
p9_client_write(struct p9_fid *fid, u64 offset, struct iov_iter *from, int *err)
16161615
{
1617-
int err, rsize;
1618-
struct p9_client *clnt;
1616+
struct p9_client *clnt = fid->clnt;
16191617
struct p9_req_t *req;
1620-
struct iov_iter from;
1621-
union {
1622-
struct kvec kv;
1623-
struct iovec iov;
1624-
} v;
1625-
1626-
if (data) {
1627-
v.kv.iov_base = data;
1628-
v.kv.iov_len = count;
1629-
iov_iter_kvec(&from, ITER_KVEC | WRITE, &v.kv, 1, count);
1630-
} else {
1631-
v.iov.iov_base = udata;
1632-
v.iov.iov_len = count;
1633-
iov_iter_init(&from, WRITE, &v.iov, 1, count);
1634-
}
1635-
1636-
p9_debug(P9_DEBUG_9P, ">>> TWRITE fid %d offset %llu count %d\n",
1637-
fid->fid, (unsigned long long) offset, count);
1638-
err = 0;
1639-
clnt = fid->clnt;
1640-
1641-
rsize = fid->iounit;
1642-
if (!rsize || rsize > clnt->msize-P9_IOHDRSZ)
1643-
rsize = clnt->msize - P9_IOHDRSZ;
1618+
int total = 0;
1619+
1620+
p9_debug(P9_DEBUG_9P, ">>> TWRITE fid %d offset %llu count %zd\n",
1621+
fid->fid, (unsigned long long) offset,
1622+
iov_iter_count(from));
1623+
1624+
while (iov_iter_count(from)) {
1625+
int count = iov_iter_count(from);
1626+
int rsize = fid->iounit;
1627+
if (!rsize || rsize > clnt->msize-P9_IOHDRSZ)
1628+
rsize = clnt->msize - P9_IOHDRSZ;
1629+
1630+
if (count < rsize)
1631+
rsize = count;
1632+
1633+
/* Don't bother zerocopy for small IO (< 1024) */
1634+
if (clnt->trans_mod->zc_request && rsize > 1024) {
1635+
req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, from, 0,
1636+
rsize, P9_ZC_HDR_SZ, "dqd",
1637+
fid->fid, offset, rsize);
1638+
} else {
1639+
req = p9_client_rpc(clnt, P9_TWRITE, "dqV", fid->fid,
1640+
offset, rsize, from);
1641+
}
1642+
if (IS_ERR(req)) {
1643+
*err = PTR_ERR(req);
1644+
break;
1645+
}
16441646

1645-
if (count < rsize)
1646-
rsize = count;
1647+
*err = p9pdu_readf(req->rc, clnt->proto_version, "d", &count);
1648+
if (*err) {
1649+
trace_9p_protocol_dump(clnt, req->rc);
1650+
p9_free_req(clnt, req);
1651+
}
16471652

1648-
/* Don't bother zerocopy for small IO (< 1024) */
1649-
if (clnt->trans_mod->zc_request && rsize > 1024) {
1650-
req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, &from, 0, rsize,
1651-
P9_ZC_HDR_SZ, "dqd",
1652-
fid->fid, offset, rsize);
1653-
} else {
1654-
req = p9_client_rpc(clnt, P9_TWRITE, "dqV", fid->fid,
1655-
offset, rsize, &from);
1656-
}
1657-
if (IS_ERR(req)) {
1658-
err = PTR_ERR(req);
1659-
goto error;
1660-
}
1653+
p9_debug(P9_DEBUG_9P, "<<< RWRITE count %d\n", count);
16611654

1662-
err = p9pdu_readf(req->rc, clnt->proto_version, "d", &count);
1663-
if (err) {
1664-
trace_9p_protocol_dump(clnt, req->rc);
1665-
goto free_and_error;
1655+
p9_free_req(clnt, req);
1656+
iov_iter_advance(from, count);
1657+
total += count;
1658+
offset += count;
16661659
}
1667-
1668-
p9_debug(P9_DEBUG_9P, "<<< RWRITE count %d\n", count);
1669-
1670-
p9_free_req(clnt, req);
1671-
return count;
1672-
1673-
free_and_error:
1674-
p9_free_req(clnt, req);
1675-
error:
1676-
return err;
1660+
return total;
16771661
}
16781662
EXPORT_SYMBOL(p9_client_write);
16791663

0 commit comments

Comments
 (0)