hw/9pfs: Add yeild support for clunk related coroutine
[qemu/kevin.git] / hw / 9pfs / cofile.c
blobe5529996660ae59e7df2e873c8093c2d3766bea7
2 /*
3 * Virtio 9p backend
5 * Copyright IBM, Corp. 2011
7 * Authors:
8 * Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
10 * This work is licensed under the terms of the GNU GPL, version 2. See
11 * the COPYING file in the top-level directory.
15 #include "fsdev/qemu-fsdev.h"
16 #include "qemu-thread.h"
17 #include "qemu-coroutine.h"
18 #include "virtio-9p-coth.h"
20 int v9fs_co_lstat(V9fsState *s, V9fsString *path, struct stat *stbuf)
22 int err;
24 v9fs_co_run_in_worker(
26 err = s->ops->lstat(&s->ctx, path->data, stbuf);
27 if (err < 0) {
28 err = -errno;
30 });
31 return err;
34 int v9fs_co_fstat(V9fsState *s, int fd, struct stat *stbuf)
36 int err;
38 v9fs_co_run_in_worker(
40 err = s->ops->fstat(&s->ctx, fd, stbuf);
41 if (err < 0) {
42 err = -errno;
44 });
45 return err;
48 int v9fs_co_open(V9fsState *s, V9fsFidState *fidp, int flags)
50 int err;
52 v9fs_co_run_in_worker(
54 fidp->fs.fd = s->ops->open(&s->ctx, fidp->path.data, flags);
55 if (fidp->fs.fd == -1) {
56 err = -errno;
57 } else {
58 err = 0;
60 });
61 return err;
64 int v9fs_co_open2(V9fsState *s, V9fsFidState *fidp, char *fullname, gid_t gid,
65 int flags, int mode)
67 int err;
68 FsCred cred;
70 cred_init(&cred);
71 cred.fc_mode = mode & 07777;
72 cred.fc_uid = fidp->uid;
73 cred.fc_gid = gid;
74 v9fs_co_run_in_worker(
76 fidp->fs.fd = s->ops->open2(&s->ctx, fullname, flags, &cred);
77 err = 0;
78 if (fidp->fs.fd == -1) {
79 err = -errno;
81 });
82 return err;
85 int v9fs_co_close(V9fsState *s, V9fsFidState *fidp)
87 int fd;
88 int err;
90 fd = fidp->fs.fd;
91 v9fs_co_run_in_worker(
93 err = s->ops->close(&s->ctx, fd);
94 if (err < 0) {
95 err = -errno;
97 });
98 return err;