hw/9pfs: Update v9fs_statfs to use coroutines

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
This commit is contained in:
Aneesh Kumar K.V 2011-05-18 16:04:01 -07:00
parent 94840ff9f3
commit 88a4763e88
2 changed files with 43 additions and 69 deletions

View File

@ -3036,79 +3036,75 @@ out:
qemu_free(vs); qemu_free(vs);
} }
static void v9fs_statfs_post_statfs(V9fsState *s, V9fsStatfsState *vs, int err) static int v9fs_fill_statfs(V9fsState *s, V9fsPDU *pdu, struct statfs *stbuf)
{ {
uint32_t f_type;
uint32_t f_bsize;
uint64_t f_blocks;
uint64_t f_bfree;
uint64_t f_bavail;
uint64_t f_files;
uint64_t f_ffree;
uint64_t fsid_val;
uint32_t f_namelen;
size_t offset = 7;
int32_t bsize_factor; int32_t bsize_factor;
if (err) {
err = -errno;
goto out;
}
/* /*
* compute bsize factor based on host file system block size * compute bsize factor based on host file system block size
* and client msize * and client msize
*/ */
bsize_factor = (s->msize - P9_IOHDRSZ)/vs->stbuf.f_bsize; bsize_factor = (s->msize - P9_IOHDRSZ)/stbuf->f_bsize;
if (!bsize_factor) { if (!bsize_factor) {
bsize_factor = 1; bsize_factor = 1;
} }
vs->v9statfs.f_type = vs->stbuf.f_type; f_type = stbuf->f_type;
vs->v9statfs.f_bsize = vs->stbuf.f_bsize; f_bsize = stbuf->f_bsize;
vs->v9statfs.f_bsize *= bsize_factor; f_bsize *= bsize_factor;
/* /*
* f_bsize is adjusted(multiplied) by bsize factor, so we need to * f_bsize is adjusted(multiplied) by bsize factor, so we need to
* adjust(divide) the number of blocks, free blocks and available * adjust(divide) the number of blocks, free blocks and available
* blocks by bsize factor * blocks by bsize factor
*/ */
vs->v9statfs.f_blocks = vs->stbuf.f_blocks/bsize_factor; f_blocks = stbuf->f_blocks/bsize_factor;
vs->v9statfs.f_bfree = vs->stbuf.f_bfree/bsize_factor; f_bfree = stbuf->f_bfree/bsize_factor;
vs->v9statfs.f_bavail = vs->stbuf.f_bavail/bsize_factor; f_bavail = stbuf->f_bavail/bsize_factor;
vs->v9statfs.f_files = vs->stbuf.f_files; f_files = stbuf->f_files;
vs->v9statfs.f_ffree = vs->stbuf.f_ffree; f_ffree = stbuf->f_ffree;
vs->v9statfs.fsid_val = (unsigned int) vs->stbuf.f_fsid.__val[0] | fsid_val = (unsigned int) stbuf->f_fsid.__val[0] |
(unsigned long long)vs->stbuf.f_fsid.__val[1] << 32; (unsigned long long)stbuf->f_fsid.__val[1] << 32;
vs->v9statfs.f_namelen = vs->stbuf.f_namelen; f_namelen = stbuf->f_namelen;
vs->offset += pdu_marshal(vs->pdu, vs->offset, "ddqqqqqqd", return pdu_marshal(pdu, offset, "ddqqqqqqd",
vs->v9statfs.f_type, vs->v9statfs.f_bsize, vs->v9statfs.f_blocks, f_type, f_bsize, f_blocks, f_bfree,
vs->v9statfs.f_bfree, vs->v9statfs.f_bavail, vs->v9statfs.f_files, f_bavail, f_files, f_ffree,
vs->v9statfs.f_ffree, vs->v9statfs.fsid_val, fsid_val, f_namelen);
vs->v9statfs.f_namelen);
out:
complete_pdu(s, vs->pdu, vs->offset);
qemu_free(vs);
} }
static void v9fs_statfs(void *opaque) static void v9fs_statfs(void *opaque)
{ {
int32_t fid;
ssize_t retval = 0;
size_t offset = 7;
V9fsFidState *fidp;
struct statfs stbuf;
V9fsPDU *pdu = opaque; V9fsPDU *pdu = opaque;
V9fsState *s = pdu->s; V9fsState *s = pdu->s;
V9fsStatfsState *vs;
ssize_t err = 0;
vs = qemu_malloc(sizeof(*vs)); pdu_unmarshal(pdu, offset, "d", &fid);
vs->pdu = pdu; fidp = lookup_fid(s, fid);
vs->offset = 7; if (fidp == NULL) {
retval = -ENOENT;
memset(&vs->v9statfs, 0, sizeof(vs->v9statfs));
pdu_unmarshal(vs->pdu, vs->offset, "d", &vs->fid);
vs->fidp = lookup_fid(s, vs->fid);
if (vs->fidp == NULL) {
err = -ENOENT;
goto out; goto out;
} }
retval = v9fs_co_statfs(s, &fidp->path, &stbuf);
err = v9fs_do_statfs(s, &vs->fidp->path, &vs->stbuf); if (retval < 0) {
v9fs_statfs_post_statfs(s, vs, err); goto out;
return; }
retval = offset;
retval += v9fs_fill_statfs(s, pdu, &stbuf);
out: out:
complete_pdu(s, vs->pdu, err); complete_pdu(s, pdu, retval);
qemu_free(vs);
return; return;
} }

View File

@ -398,28 +398,6 @@ struct virtio_9p_config
uint8_t tag[0]; uint8_t tag[0];
} __attribute__((packed)); } __attribute__((packed));
typedef struct V9fsStatfs
{
uint32_t f_type;
uint32_t f_bsize;
uint64_t f_blocks;
uint64_t f_bfree;
uint64_t f_bavail;
uint64_t f_files;
uint64_t f_ffree;
uint64_t fsid_val;
uint32_t f_namelen;
} V9fsStatfs;
typedef struct V9fsStatfsState {
V9fsPDU *pdu;
size_t offset;
int32_t fid;
V9fsStatfs v9statfs;
V9fsFidState *fidp;
struct statfs stbuf;
} V9fsStatfsState;
typedef struct V9fsMkState { typedef struct V9fsMkState {
V9fsPDU *pdu; V9fsPDU *pdu;
size_t offset; size_t offset;