hw/9pfs: Update v9fs_readlink to use coroutine

Signed-off-by: Venkateswararao Jujjuri <jvrao@linux.vnet.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
This commit is contained in:
Venkateswararao Jujjuri 2011-08-08 23:36:41 +05:30 committed by Aneesh Kumar K.V
parent 86e42d7482
commit 7a5ca31eb4
2 changed files with 17 additions and 60 deletions

View File

@ -82,21 +82,6 @@ static int v9fs_do_lstat(V9fsState *s, V9fsString *path, struct stat *stbuf)
return s->ops->lstat(&s->ctx, path->data, stbuf); return s->ops->lstat(&s->ctx, path->data, stbuf);
} }
static ssize_t v9fs_do_readlink(V9fsState *s, V9fsString *path, V9fsString *buf)
{
ssize_t len;
buf->data = qemu_malloc(1024);
len = s->ops->readlink(&s->ctx, path->data, buf->data, 1024 - 1);
if (len > -1) {
buf->size = len;
buf->data[len] = 0;
}
return len;
}
static int v9fs_do_close(V9fsState *s, int fd) static int v9fs_do_close(V9fsState *s, int fd)
{ {
return s->ops->close(&s->ctx, fd); return s->ops->close(&s->ctx, fd);
@ -1054,13 +1039,10 @@ static int stat_to_v9stat(V9fsState *s, V9fsString *name,
v9fs_string_null(&v9stat->extension); v9fs_string_null(&v9stat->extension);
if (v9stat->mode & P9_STAT_MODE_SYMLINK) { if (v9stat->mode & P9_STAT_MODE_SYMLINK) {
err = v9fs_do_readlink(s, name, &v9stat->extension); err = v9fs_co_readlink(s, name, &v9stat->extension);
if (err == -1) { if (err < 0) {
err = -errno;
return err; return err;
} }
v9stat->extension.data[err] = 0;
v9stat->extension.size = err;
} else if (v9stat->mode & P9_STAT_MODE_DEVICE) { } else if (v9stat->mode & P9_STAT_MODE_DEVICE) {
v9fs_string_sprintf(&v9stat->extension, "%c %u %u", v9fs_string_sprintf(&v9stat->extension, "%c %u %u",
S_ISCHR(stbuf->st_mode) ? 'c' : 'b', S_ISCHR(stbuf->st_mode) ? 'c' : 'b',
@ -1949,13 +1931,13 @@ static void v9fs_read_post_seekdir(V9fsState *s, V9fsReadState *vs, ssize_t err)
if (err) { if (err) {
goto out; goto out;
} }
v9fs_stat_free(&vs->v9stat);
v9fs_string_free(&vs->name);
vs->offset += pdu_marshal(vs->pdu, vs->offset, "d", vs->count); vs->offset += pdu_marshal(vs->pdu, vs->offset, "d", vs->count);
vs->offset += vs->count; vs->offset += vs->count;
err = vs->offset; err = vs->offset;
out: out:
complete_pdu(s, vs->pdu, err); complete_pdu(s, vs->pdu, err);
v9fs_stat_free(&vs->v9stat);
v9fs_string_free(&vs->name);
qemu_free(vs); qemu_free(vs);
return; return;
} }
@ -3582,49 +3564,32 @@ out:
qemu_free(vs); qemu_free(vs);
} }
static void v9fs_readlink_post_readlink(V9fsState *s, V9fsReadLinkState *vs,
int err)
{
if (err < 0) {
err = -errno;
goto out;
}
vs->offset += pdu_marshal(vs->pdu, vs->offset, "s", &vs->target);
err = vs->offset;
out:
complete_pdu(s, vs->pdu, err);
v9fs_string_free(&vs->target);
qemu_free(vs);
}
static void v9fs_readlink(void *opaque) static void v9fs_readlink(void *opaque)
{ {
V9fsPDU *pdu = opaque; V9fsPDU *pdu = opaque;
V9fsState *s = pdu->s; size_t offset = 7;
V9fsString target;
int32_t fid; int32_t fid;
V9fsReadLinkState *vs;
int err = 0; int err = 0;
V9fsFidState *fidp; V9fsFidState *fidp;
vs = qemu_malloc(sizeof(*vs)); pdu_unmarshal(pdu, offset, "d", &fid);
vs->pdu = pdu; fidp = lookup_fid(pdu->s, fid);
vs->offset = 7;
pdu_unmarshal(vs->pdu, vs->offset, "d", &fid);
fidp = lookup_fid(s, fid);
if (fidp == NULL) { if (fidp == NULL) {
err = -ENOENT; err = -ENOENT;
goto out; goto out;
} }
v9fs_string_init(&vs->target); v9fs_string_init(&target);
err = v9fs_do_readlink(s, &fidp->path, &vs->target); err = v9fs_co_readlink(pdu->s, &fidp->path, &target);
v9fs_readlink_post_readlink(s, vs, err); if (err < 0) {
return; goto out;
}
offset += pdu_marshal(pdu, offset, "s", &target);
err = offset;
v9fs_string_free(&target);
out: out:
complete_pdu(s, vs->pdu, err); complete_pdu(pdu->s, pdu, err);
qemu_free(vs);
} }
static CoroutineEntry *pdu_co_handlers[] = { static CoroutineEntry *pdu_co_handlers[] = {

View File

@ -495,13 +495,6 @@ typedef struct V9fsGetlockState
V9fsGetlock *glock; V9fsGetlock *glock;
} V9fsGetlockState; } V9fsGetlockState;
typedef struct V9fsReadLinkState
{
V9fsPDU *pdu;
size_t offset;
V9fsString target;
} V9fsReadLinkState;
size_t pdu_packunpack(void *addr, struct iovec *sg, int sg_count, size_t pdu_packunpack(void *addr, struct iovec *sg, int sg_count,
size_t offset, size_t size, int pack); size_t offset, size_t size, int pack);
@ -512,5 +505,4 @@ static inline size_t do_pdu_unpack(void *dst, struct iovec *sg, int sg_count,
} }
extern void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq); extern void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq);
#endif #endif