hw/9pfs: Update v9fs_lock 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-08-22 09:14:04 +05:30
parent 03feb1e172
commit 0c27bf2a45
2 changed files with 20 additions and 34 deletions

View File

@ -3006,47 +3006,43 @@ out:
* do any thing in * qemu 9p server side lock code path. * do any thing in * qemu 9p server side lock code path.
* So when a TLOCK request comes, always return success * So when a TLOCK request comes, always return success
*/ */
static void v9fs_lock(void *opaque) static void v9fs_lock(void *opaque)
{ {
int8_t status;
V9fsFlock *flock;
size_t offset = 7;
struct stat stbuf;
V9fsFidState *fidp;
int32_t fid, err = 0;
V9fsPDU *pdu = opaque; V9fsPDU *pdu = opaque;
V9fsState *s = pdu->s; V9fsState *s = pdu->s;
int32_t fid, err = 0;
V9fsLockState *vs;
vs = g_malloc0(sizeof(*vs)); flock = g_malloc(sizeof(*flock));
vs->pdu = pdu; pdu_unmarshal(pdu, offset, "dbdqqds", &fid, &flock->type,
vs->offset = 7; &flock->flags, &flock->start, &flock->length,
&flock->proc_id, &flock->client_id);
vs->flock = g_malloc(sizeof(*vs->flock)); status = P9_LOCK_ERROR;
pdu_unmarshal(vs->pdu, vs->offset, "dbdqqds", &fid, &vs->flock->type,
&vs->flock->flags, &vs->flock->start, &vs->flock->length,
&vs->flock->proc_id, &vs->flock->client_id);
vs->status = P9_LOCK_ERROR;
/* We support only block flag now (that too ignored currently) */ /* We support only block flag now (that too ignored currently) */
if (vs->flock->flags & ~P9_LOCK_FLAGS_BLOCK) { if (flock->flags & ~P9_LOCK_FLAGS_BLOCK) {
err = -EINVAL; err = -EINVAL;
goto out; goto out;
} }
vs->fidp = lookup_fid(s, fid); fidp = lookup_fid(s, fid);
if (vs->fidp == NULL) { if (fidp == NULL) {
err = -ENOENT; err = -ENOENT;
goto out; goto out;
} }
err = v9fs_co_fstat(s, fidp->fs.fd, &stbuf);
err = v9fs_do_fstat(s, vs->fidp->fs.fd, &vs->stbuf);
if (err < 0) { if (err < 0) {
err = -errno;
goto out; goto out;
} }
vs->status = P9_LOCK_SUCCESS; status = P9_LOCK_SUCCESS;
out: out:
vs->offset += pdu_marshal(vs->pdu, vs->offset, "b", vs->status); err = offset;
complete_pdu(s, vs->pdu, err); err += pdu_marshal(pdu, offset, "b", status);
g_free(vs->flock); complete_pdu(s, pdu, err);
g_free(vs); g_free(flock);
} }
/* /*

View File

@ -403,16 +403,6 @@ typedef struct V9fsFlock
V9fsString client_id; V9fsString client_id;
} V9fsFlock; } V9fsFlock;
typedef struct V9fsLockState
{
V9fsPDU *pdu;
size_t offset;
int8_t status;
struct stat stbuf;
V9fsFidState *fidp;
V9fsFlock *flock;
} V9fsLockState;
typedef struct V9fsGetlock typedef struct V9fsGetlock
{ {
uint8_t type; uint8_t type;