mirror of
https://git.proxmox.com/git/qemu
synced 2025-08-09 02:56:42 +00:00
hw/9pfs: Update v9fs_write to use coroutines
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
This commit is contained in:
parent
f6b3c976c6
commit
d7a9049119
@ -103,12 +103,6 @@ static int v9fs_do_preadv(V9fsState *s, int fd, const struct iovec *iov,
|
|||||||
return s->ops->preadv(&s->ctx, fd, iov, iovcnt, offset);
|
return s->ops->preadv(&s->ctx, fd, iov, iovcnt, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int v9fs_do_pwritev(V9fsState *s, int fd, const struct iovec *iov,
|
|
||||||
int iovcnt, int64_t offset)
|
|
||||||
{
|
|
||||||
return s->ops->pwritev(&s->ctx, fd, iov, iovcnt, offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int v9fs_do_chmod(V9fsState *s, V9fsString *path, mode_t mode)
|
static int v9fs_do_chmod(V9fsState *s, V9fsString *path, mode_t mode)
|
||||||
{
|
{
|
||||||
FsCred cred;
|
FsCred cred;
|
||||||
@ -1834,51 +1828,21 @@ out:
|
|||||||
complete_pdu(s, pdu, retval);
|
complete_pdu(s, pdu, retval);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void v9fs_write_post_pwritev(V9fsState *s, V9fsWriteState *vs,
|
static int v9fs_xattr_write(V9fsState *s, V9fsPDU *pdu, V9fsFidState *fidp,
|
||||||
ssize_t err)
|
int64_t off, int32_t count,
|
||||||
{
|
struct iovec *sg, int cnt)
|
||||||
if (err < 0) {
|
|
||||||
/* IO error return the error */
|
|
||||||
err = -errno;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
vs->total += vs->len;
|
|
||||||
vs->sg = adjust_sg(vs->sg, vs->len, &vs->cnt);
|
|
||||||
if (vs->total < vs->count && vs->len > 0) {
|
|
||||||
do {
|
|
||||||
if (0) {
|
|
||||||
print_sg(vs->sg, vs->cnt);
|
|
||||||
}
|
|
||||||
vs->len = v9fs_do_pwritev(s, vs->fidp->fs.fd, vs->sg, vs->cnt,
|
|
||||||
vs->off);
|
|
||||||
if (vs->len > 0) {
|
|
||||||
vs->off += vs->len;
|
|
||||||
}
|
|
||||||
} while (vs->len == -1 && errno == EINTR);
|
|
||||||
if (vs->len == -1) {
|
|
||||||
err = -errno;
|
|
||||||
}
|
|
||||||
v9fs_write_post_pwritev(s, vs, err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
vs->offset += pdu_marshal(vs->pdu, vs->offset, "d", vs->total);
|
|
||||||
err = vs->offset;
|
|
||||||
out:
|
|
||||||
complete_pdu(s, vs->pdu, err);
|
|
||||||
g_free(vs);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void v9fs_xattr_write(V9fsState *s, V9fsWriteState *vs)
|
|
||||||
{
|
{
|
||||||
int i, to_copy;
|
int i, to_copy;
|
||||||
ssize_t err = 0;
|
ssize_t err = 0;
|
||||||
int write_count;
|
int write_count;
|
||||||
int64_t xattr_len;
|
int64_t xattr_len;
|
||||||
|
size_t offset = 7;
|
||||||
|
|
||||||
xattr_len = vs->fidp->fs.xattr.len;
|
|
||||||
write_count = xattr_len - vs->off;
|
xattr_len = fidp->fs.xattr.len;
|
||||||
if (write_count > vs->count) {
|
write_count = xattr_len - off;
|
||||||
write_count = vs->count;
|
if (write_count > count) {
|
||||||
|
write_count = count;
|
||||||
} else if (write_count < 0) {
|
} else if (write_count < 0) {
|
||||||
/*
|
/*
|
||||||
* write beyond XATTR value len specified in
|
* write beyond XATTR value len specified in
|
||||||
@ -1887,82 +1851,88 @@ static void v9fs_xattr_write(V9fsState *s, V9fsWriteState *vs)
|
|||||||
err = -ENOSPC;
|
err = -ENOSPC;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
vs->offset += pdu_marshal(vs->pdu, vs->offset, "d", write_count);
|
offset += pdu_marshal(pdu, offset, "d", write_count);
|
||||||
err = vs->offset;
|
err = offset;
|
||||||
vs->fidp->fs.xattr.copied_len += write_count;
|
fidp->fs.xattr.copied_len += write_count;
|
||||||
/*
|
/*
|
||||||
* Now copy the content from sg list
|
* Now copy the content from sg list
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < vs->cnt; i++) {
|
for (i = 0; i < cnt; i++) {
|
||||||
if (write_count > vs->sg[i].iov_len) {
|
if (write_count > sg[i].iov_len) {
|
||||||
to_copy = vs->sg[i].iov_len;
|
to_copy = sg[i].iov_len;
|
||||||
} else {
|
} else {
|
||||||
to_copy = write_count;
|
to_copy = write_count;
|
||||||
}
|
}
|
||||||
memcpy((char *)vs->fidp->fs.xattr.value + vs->off,
|
memcpy((char *)fidp->fs.xattr.value + off, sg[i].iov_base, to_copy);
|
||||||
vs->sg[i].iov_base, to_copy);
|
|
||||||
/* updating vs->off since we are not using below */
|
/* updating vs->off since we are not using below */
|
||||||
vs->off += to_copy;
|
off += to_copy;
|
||||||
write_count -= to_copy;
|
write_count -= to_copy;
|
||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
complete_pdu(s, vs->pdu, err);
|
return err;
|
||||||
g_free(vs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void v9fs_write(void *opaque)
|
static void v9fs_write(void *opaque)
|
||||||
{
|
{
|
||||||
|
int cnt;
|
||||||
|
ssize_t err;
|
||||||
|
int32_t fid;
|
||||||
|
int64_t off;
|
||||||
|
int32_t count;
|
||||||
|
int32_t len = 0;
|
||||||
|
int32_t total = 0;
|
||||||
|
size_t offset = 7;
|
||||||
|
V9fsFidState *fidp;
|
||||||
|
struct iovec iov[128]; /* FIXME: bad, bad, bad */
|
||||||
|
struct iovec *sg = iov;
|
||||||
V9fsPDU *pdu = opaque;
|
V9fsPDU *pdu = opaque;
|
||||||
V9fsState *s = pdu->s;
|
V9fsState *s = pdu->s;
|
||||||
int32_t fid;
|
|
||||||
V9fsWriteState *vs;
|
|
||||||
ssize_t err;
|
|
||||||
|
|
||||||
vs = g_malloc(sizeof(*vs));
|
pdu_unmarshal(pdu, offset, "dqdv", &fid, &off, &count, sg, &cnt);
|
||||||
|
fidp = lookup_fid(s, fid);
|
||||||
vs->pdu = pdu;
|
if (fidp == NULL) {
|
||||||
vs->offset = 7;
|
|
||||||
vs->sg = vs->iov;
|
|
||||||
vs->total = 0;
|
|
||||||
vs->len = 0;
|
|
||||||
|
|
||||||
pdu_unmarshal(vs->pdu, vs->offset, "dqdv", &fid, &vs->off, &vs->count,
|
|
||||||
vs->sg, &vs->cnt);
|
|
||||||
|
|
||||||
vs->fidp = lookup_fid(s, fid);
|
|
||||||
if (vs->fidp == NULL) {
|
|
||||||
err = -EINVAL;
|
err = -EINVAL;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
if (fidp->fid_type == P9_FID_FILE) {
|
||||||
if (vs->fidp->fid_type == P9_FID_FILE) {
|
if (fidp->fs.fd == -1) {
|
||||||
if (vs->fidp->fs.fd == -1) {
|
|
||||||
err = -EINVAL;
|
err = -EINVAL;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
} else if (vs->fidp->fid_type == P9_FID_XATTR) {
|
} else if (fidp->fid_type == P9_FID_XATTR) {
|
||||||
/*
|
/*
|
||||||
* setxattr operation
|
* setxattr operation
|
||||||
*/
|
*/
|
||||||
v9fs_xattr_write(s, vs);
|
err = v9fs_xattr_write(s, pdu, fidp, off, count, sg, cnt);
|
||||||
return;
|
goto out;
|
||||||
} else {
|
} else {
|
||||||
err = -EINVAL;
|
err = -EINVAL;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
vs->sg = cap_sg(vs->sg, vs->count, &vs->cnt);
|
sg = cap_sg(sg, count, &cnt);
|
||||||
if (vs->total <= vs->count) {
|
do {
|
||||||
vs->len = v9fs_do_pwritev(s, vs->fidp->fs.fd, vs->sg, vs->cnt, vs->off);
|
if (0) {
|
||||||
if (vs->len > 0) {
|
print_sg(sg, cnt);
|
||||||
vs->off += vs->len;
|
|
||||||
}
|
}
|
||||||
err = vs->len;
|
/* Loop in case of EINTR */
|
||||||
v9fs_write_post_pwritev(s, vs, err);
|
do {
|
||||||
|
len = v9fs_co_pwritev(s, fidp, sg, cnt, off);
|
||||||
|
if (len >= 0) {
|
||||||
|
off += len;
|
||||||
|
total += len;
|
||||||
}
|
}
|
||||||
return;
|
} while (len == -EINTR);
|
||||||
|
if (len < 0) {
|
||||||
|
/* IO error return the error */
|
||||||
|
err = len;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
sg = adjust_sg(sg, len, &cnt);
|
||||||
|
} while (total < count && len > 0);
|
||||||
|
offset += pdu_marshal(pdu, offset, "d", total);
|
||||||
|
err = offset;
|
||||||
out:
|
out:
|
||||||
complete_pdu(s, vs->pdu, err);
|
complete_pdu(s, pdu, err);
|
||||||
g_free(vs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void v9fs_create(void *opaque)
|
static void v9fs_create(void *opaque)
|
||||||
|
Loading…
Reference in New Issue
Block a user