qom: Use returned bool to check for failure, Coccinelle part
[qemu/ar7.git] / hw / 9pfs / codir.c
blob73f9a751e178341745143bc9d2f697f4102d87a3
1 /*
2 * 9p backend
4 * Copyright IBM, Corp. 2011
6 * Authors:
7 * Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
14 #include "qemu/osdep.h"
15 #include "fsdev/qemu-fsdev.h"
16 #include "qemu/thread.h"
17 #include "qemu/coroutine.h"
18 #include "qemu/main-loop.h"
19 #include "coth.h"
21 int coroutine_fn v9fs_co_readdir(V9fsPDU *pdu, V9fsFidState *fidp,
22 struct dirent **dent)
24 int err;
25 V9fsState *s = pdu->s;
27 if (v9fs_request_cancelled(pdu)) {
28 return -EINTR;
30 v9fs_co_run_in_worker(
32 struct dirent *entry;
34 errno = 0;
35 entry = s->ops->readdir(&s->ctx, &fidp->fs);
36 if (!entry && errno) {
37 err = -errno;
38 } else {
39 *dent = entry;
40 err = 0;
42 });
43 return err;
46 off_t v9fs_co_telldir(V9fsPDU *pdu, V9fsFidState *fidp)
48 off_t err;
49 V9fsState *s = pdu->s;
51 if (v9fs_request_cancelled(pdu)) {
52 return -EINTR;
54 v9fs_co_run_in_worker(
56 err = s->ops->telldir(&s->ctx, &fidp->fs);
57 if (err < 0) {
58 err = -errno;
60 });
61 return err;
64 void coroutine_fn v9fs_co_seekdir(V9fsPDU *pdu, V9fsFidState *fidp,
65 off_t offset)
67 V9fsState *s = pdu->s;
68 if (v9fs_request_cancelled(pdu)) {
69 return;
71 v9fs_co_run_in_worker(
73 s->ops->seekdir(&s->ctx, &fidp->fs, offset);
74 });
77 void coroutine_fn v9fs_co_rewinddir(V9fsPDU *pdu, V9fsFidState *fidp)
79 V9fsState *s = pdu->s;
80 if (v9fs_request_cancelled(pdu)) {
81 return;
83 v9fs_co_run_in_worker(
85 s->ops->rewinddir(&s->ctx, &fidp->fs);
86 });
89 int coroutine_fn v9fs_co_mkdir(V9fsPDU *pdu, V9fsFidState *fidp,
90 V9fsString *name, mode_t mode, uid_t uid,
91 gid_t gid, struct stat *stbuf)
93 int err;
94 FsCred cred;
95 V9fsPath path;
96 V9fsState *s = pdu->s;
98 if (v9fs_request_cancelled(pdu)) {
99 return -EINTR;
101 cred_init(&cred);
102 cred.fc_mode = mode;
103 cred.fc_uid = uid;
104 cred.fc_gid = gid;
105 v9fs_path_read_lock(s);
106 v9fs_co_run_in_worker(
108 err = s->ops->mkdir(&s->ctx, &fidp->path, name->data, &cred);
109 if (err < 0) {
110 err = -errno;
111 } else {
112 v9fs_path_init(&path);
113 err = v9fs_name_to_path(s, &fidp->path, name->data, &path);
114 if (!err) {
115 err = s->ops->lstat(&s->ctx, &path, stbuf);
116 if (err < 0) {
117 err = -errno;
120 v9fs_path_free(&path);
123 v9fs_path_unlock(s);
124 return err;
127 int coroutine_fn v9fs_co_opendir(V9fsPDU *pdu, V9fsFidState *fidp)
129 int err;
130 V9fsState *s = pdu->s;
132 if (v9fs_request_cancelled(pdu)) {
133 return -EINTR;
135 v9fs_path_read_lock(s);
136 v9fs_co_run_in_worker(
138 err = s->ops->opendir(&s->ctx, &fidp->path, &fidp->fs);
139 if (err < 0) {
140 err = -errno;
141 } else {
142 err = 0;
145 v9fs_path_unlock(s);
146 if (!err) {
147 total_open_fd++;
148 if (total_open_fd > open_fd_hw) {
149 v9fs_reclaim_fd(pdu);
152 return err;
155 int coroutine_fn v9fs_co_closedir(V9fsPDU *pdu, V9fsFidOpenState *fs)
157 int err;
158 V9fsState *s = pdu->s;
160 if (v9fs_request_cancelled(pdu)) {
161 return -EINTR;
163 v9fs_co_run_in_worker(
165 err = s->ops->closedir(&s->ctx, fs);
166 if (err < 0) {
167 err = -errno;
170 if (!err) {
171 total_open_fd--;
173 return err;