virtio-gpu: check max_outputs only
[qemu/ar7.git] / hw / 9pfs / codir.c
blob91df7f7a7b8d1f6b7a0eea576a0f4f4b0c0b7420
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 "qemu/osdep.h"
16 #include "fsdev/qemu-fsdev.h"
17 #include "qemu/thread.h"
18 #include "qemu/coroutine.h"
19 #include "coth.h"
21 int v9fs_co_readdir_r(V9fsPDU *pdu, V9fsFidState *fidp, struct dirent *dent,
22 struct dirent **result)
24 int err;
25 V9fsState *s = pdu->s;
27 if (v9fs_request_cancelled(pdu)) {
28 return -EINTR;
30 v9fs_co_run_in_worker(
32 errno = 0;
33 err = s->ops->readdir_r(&s->ctx, &fidp->fs, dent, result);
34 if (!*result && errno) {
35 err = -errno;
36 } else {
37 err = 0;
39 });
40 return err;
43 off_t v9fs_co_telldir(V9fsPDU *pdu, V9fsFidState *fidp)
45 off_t err;
46 V9fsState *s = pdu->s;
48 if (v9fs_request_cancelled(pdu)) {
49 return -EINTR;
51 v9fs_co_run_in_worker(
53 err = s->ops->telldir(&s->ctx, &fidp->fs);
54 if (err < 0) {
55 err = -errno;
57 });
58 return err;
61 void v9fs_co_seekdir(V9fsPDU *pdu, V9fsFidState *fidp, off_t offset)
63 V9fsState *s = pdu->s;
64 if (v9fs_request_cancelled(pdu)) {
65 return;
67 v9fs_co_run_in_worker(
69 s->ops->seekdir(&s->ctx, &fidp->fs, offset);
70 });
73 void v9fs_co_rewinddir(V9fsPDU *pdu, V9fsFidState *fidp)
75 V9fsState *s = pdu->s;
76 if (v9fs_request_cancelled(pdu)) {
77 return;
79 v9fs_co_run_in_worker(
81 s->ops->rewinddir(&s->ctx, &fidp->fs);
82 });
85 int v9fs_co_mkdir(V9fsPDU *pdu, V9fsFidState *fidp, V9fsString *name,
86 mode_t mode, uid_t uid, gid_t gid, struct stat *stbuf)
88 int err;
89 FsCred cred;
90 V9fsPath path;
91 V9fsState *s = pdu->s;
93 if (v9fs_request_cancelled(pdu)) {
94 return -EINTR;
96 cred_init(&cred);
97 cred.fc_mode = mode;
98 cred.fc_uid = uid;
99 cred.fc_gid = gid;
100 v9fs_path_read_lock(s);
101 v9fs_co_run_in_worker(
103 err = s->ops->mkdir(&s->ctx, &fidp->path, name->data, &cred);
104 if (err < 0) {
105 err = -errno;
106 } else {
107 v9fs_path_init(&path);
108 err = v9fs_name_to_path(s, &fidp->path, name->data, &path);
109 if (!err) {
110 err = s->ops->lstat(&s->ctx, &path, stbuf);
111 if (err < 0) {
112 err = -errno;
115 v9fs_path_free(&path);
118 v9fs_path_unlock(s);
119 return err;
122 int v9fs_co_opendir(V9fsPDU *pdu, V9fsFidState *fidp)
124 int err;
125 V9fsState *s = pdu->s;
127 if (v9fs_request_cancelled(pdu)) {
128 return -EINTR;
130 v9fs_path_read_lock(s);
131 v9fs_co_run_in_worker(
133 err = s->ops->opendir(&s->ctx, &fidp->path, &fidp->fs);
134 if (err < 0) {
135 err = -errno;
136 } else {
137 err = 0;
140 v9fs_path_unlock(s);
141 if (!err) {
142 total_open_fd++;
143 if (total_open_fd > open_fd_hw) {
144 v9fs_reclaim_fd(pdu);
147 return err;
150 int v9fs_co_closedir(V9fsPDU *pdu, V9fsFidOpenState *fs)
152 int err;
153 V9fsState *s = pdu->s;
155 if (v9fs_request_cancelled(pdu)) {
156 return -EINTR;
158 v9fs_co_run_in_worker(
160 err = s->ops->closedir(&s->ctx, fs);
161 if (err < 0) {
162 err = -errno;
165 if (!err) {
166 total_open_fd--;
168 return err;