]> Git Repo - qemu.git/blame - hw/9pfs/codir.c
Include qemu/queue.h slightly less
[qemu.git] / hw / 9pfs / codir.c
CommitLineData
dcb9dbe3 1/*
af8b38b0 2 * 9p backend
dcb9dbe3
AK
3 *
4 * Copyright IBM, Corp. 2011
5 *
6 * Authors:
7 * Aneesh Kumar K.V <[email protected]>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
11 *
12 */
13
fbc04127 14#include "qemu/osdep.h"
dcb9dbe3 15#include "fsdev/qemu-fsdev.h"
1de7afc9 16#include "qemu/thread.h"
10817bf0 17#include "qemu/coroutine.h"
fe52840c 18#include "coth.h"
dcb9dbe3 19
5bdade66
GK
20int coroutine_fn v9fs_co_readdir(V9fsPDU *pdu, V9fsFidState *fidp,
21 struct dirent **dent)
dcb9dbe3
AK
22{
23 int err;
bccacf6c 24 V9fsState *s = pdu->s;
dcb9dbe3 25
bccacf6c
AK
26 if (v9fs_request_cancelled(pdu)) {
27 return -EINTR;
28 }
dcb9dbe3
AK
29 v9fs_co_run_in_worker(
30 {
635324e8
GK
31 struct dirent *entry;
32
dcb9dbe3 33 errno = 0;
635324e8
GK
34 entry = s->ops->readdir(&s->ctx, &fidp->fs);
35 if (!entry && errno) {
dcb9dbe3
AK
36 err = -errno;
37 } else {
635324e8 38 *dent = entry;
dcb9dbe3
AK
39 err = 0;
40 }
41 });
42 return err;
43}
44
bccacf6c 45off_t v9fs_co_telldir(V9fsPDU *pdu, V9fsFidState *fidp)
dcb9dbe3
AK
46{
47 off_t err;
bccacf6c 48 V9fsState *s = pdu->s;
dcb9dbe3 49
bccacf6c
AK
50 if (v9fs_request_cancelled(pdu)) {
51 return -EINTR;
52 }
dcb9dbe3
AK
53 v9fs_co_run_in_worker(
54 {
cc720ddb 55 err = s->ops->telldir(&s->ctx, &fidp->fs);
dcb9dbe3
AK
56 if (err < 0) {
57 err = -errno;
58 }
59 });
60 return err;
61}
62
5bdade66
GK
63void coroutine_fn v9fs_co_seekdir(V9fsPDU *pdu, V9fsFidState *fidp,
64 off_t offset)
dcb9dbe3 65{
bccacf6c
AK
66 V9fsState *s = pdu->s;
67 if (v9fs_request_cancelled(pdu)) {
68 return;
69 }
dcb9dbe3
AK
70 v9fs_co_run_in_worker(
71 {
cc720ddb 72 s->ops->seekdir(&s->ctx, &fidp->fs, offset);
dcb9dbe3
AK
73 });
74}
75
5bdade66 76void coroutine_fn v9fs_co_rewinddir(V9fsPDU *pdu, V9fsFidState *fidp)
dcb9dbe3 77{
bccacf6c
AK
78 V9fsState *s = pdu->s;
79 if (v9fs_request_cancelled(pdu)) {
80 return;
81 }
dcb9dbe3
AK
82 v9fs_co_run_in_worker(
83 {
cc720ddb 84 s->ops->rewinddir(&s->ctx, &fidp->fs);
dcb9dbe3
AK
85 });
86}
d0884642 87
5bdade66
GK
88int coroutine_fn v9fs_co_mkdir(V9fsPDU *pdu, V9fsFidState *fidp,
89 V9fsString *name, mode_t mode, uid_t uid,
90 gid_t gid, struct stat *stbuf)
d0884642
VJ
91{
92 int err;
93 FsCred cred;
2289be19 94 V9fsPath path;
bccacf6c 95 V9fsState *s = pdu->s;
d0884642 96
bccacf6c 97 if (v9fs_request_cancelled(pdu)) {
3a93113a 98 return -EINTR;
bccacf6c 99 }
d0884642
VJ
100 cred_init(&cred);
101 cred.fc_mode = mode;
102 cred.fc_uid = uid;
103 cred.fc_gid = gid;
532decb7 104 v9fs_path_read_lock(s);
d0884642
VJ
105 v9fs_co_run_in_worker(
106 {
2289be19 107 err = s->ops->mkdir(&s->ctx, &fidp->path, name->data, &cred);
d0884642
VJ
108 if (err < 0) {
109 err = -errno;
02cb7f3a 110 } else {
2289be19
AK
111 v9fs_path_init(&path);
112 err = v9fs_name_to_path(s, &fidp->path, name->data, &path);
113 if (!err) {
114 err = s->ops->lstat(&s->ctx, &path, stbuf);
115 if (err < 0) {
116 err = -errno;
117 }
02cb7f3a 118 }
2289be19 119 v9fs_path_free(&path);
d0884642
VJ
120 }
121 });
532decb7 122 v9fs_path_unlock(s);
d0884642
VJ
123 return err;
124}
f6b7f0ab 125
5bdade66 126int coroutine_fn v9fs_co_opendir(V9fsPDU *pdu, V9fsFidState *fidp)
f6b7f0ab
AK
127{
128 int err;
bccacf6c 129 V9fsState *s = pdu->s;
f6b7f0ab 130
bccacf6c 131 if (v9fs_request_cancelled(pdu)) {
3a93113a 132 return -EINTR;
bccacf6c 133 }
532decb7 134 v9fs_path_read_lock(s);
f6b7f0ab
AK
135 v9fs_co_run_in_worker(
136 {
cc720ddb
AK
137 err = s->ops->opendir(&s->ctx, &fidp->path, &fidp->fs);
138 if (err < 0) {
f6b7f0ab
AK
139 err = -errno;
140 } else {
141 err = 0;
142 }
143 });
532decb7 144 v9fs_path_unlock(s);
95f65511
AK
145 if (!err) {
146 total_open_fd++;
147 if (total_open_fd > open_fd_hw) {
bccacf6c 148 v9fs_reclaim_fd(pdu);
95f65511
AK
149 }
150 }
f6b7f0ab
AK
151 return err;
152}
bed4352c 153
5bdade66 154int coroutine_fn v9fs_co_closedir(V9fsPDU *pdu, V9fsFidOpenState *fs)
bed4352c
AK
155{
156 int err;
bccacf6c 157 V9fsState *s = pdu->s;
bed4352c 158
bccacf6c 159 if (v9fs_request_cancelled(pdu)) {
3a93113a 160 return -EINTR;
bccacf6c 161 }
bed4352c
AK
162 v9fs_co_run_in_worker(
163 {
cc720ddb 164 err = s->ops->closedir(&s->ctx, fs);
bed4352c
AK
165 if (err < 0) {
166 err = -errno;
167 }
168 });
95f65511
AK
169 if (!err) {
170 total_open_fd--;
171 }
bed4352c
AK
172 return err;
173}
This page took 0.435435 seconds and 4 git commands to generate.