hw/9pfs: Add yeild support for clunk related coroutine
[qemu/kevin.git] / hw / 9pfs / codir.c
blob0c31db3cbc04306f062fae6e63b24aed9e50e4bb
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_readdir(V9fsState *s, V9fsFidState *fidp, struct dirent **dent)
22 int err;
24 v9fs_co_run_in_worker(
26 errno = 0;
27 /*FIXME!! need to switch to readdir_r */
28 *dent = s->ops->readdir(&s->ctx, fidp->fs.dir);
29 if (!*dent && errno) {
30 err = -errno;
31 } else {
32 err = 0;
34 });
35 return err;
38 off_t v9fs_co_telldir(V9fsState *s, V9fsFidState *fidp)
40 off_t err;
42 v9fs_co_run_in_worker(
44 err = s->ops->telldir(&s->ctx, fidp->fs.dir);
45 if (err < 0) {
46 err = -errno;
48 });
49 return err;
52 void v9fs_co_seekdir(V9fsState *s, V9fsFidState *fidp, off_t offset)
54 v9fs_co_run_in_worker(
56 s->ops->seekdir(&s->ctx, fidp->fs.dir, offset);
57 });
60 void v9fs_co_rewinddir(V9fsState *s, V9fsFidState *fidp)
62 v9fs_co_run_in_worker(
64 s->ops->rewinddir(&s->ctx, fidp->fs.dir);
65 });
68 int v9fs_co_mkdir(V9fsState *s, char *name, mode_t mode, uid_t uid, gid_t gid)
70 int err;
71 FsCred cred;
73 cred_init(&cred);
74 cred.fc_mode = mode;
75 cred.fc_uid = uid;
76 cred.fc_gid = gid;
77 v9fs_co_run_in_worker(
79 err = s->ops->mkdir(&s->ctx, name, &cred);
80 if (err < 0) {
81 err = -errno;
83 });
84 return err;
87 int v9fs_co_opendir(V9fsState *s, V9fsFidState *fidp)
89 int err;
91 v9fs_co_run_in_worker(
93 fidp->fs.dir = s->ops->opendir(&s->ctx, fidp->path.data);
94 if (!fidp->fs.dir) {
95 err = -errno;
96 } else {
97 err = 0;
99 });
100 return err;
103 int v9fs_co_closedir(V9fsState *s, V9fsFidState *fidp)
105 int err;
106 DIR *dir;
108 dir = fidp->fs.dir;
109 v9fs_co_run_in_worker(
111 err = s->ops->closedir(&s->ctx, dir);
112 if (err < 0) {
113 err = -errno;
116 return err;