xen/Makefile.objs: simplify
[qemu/ar7.git] / hw / 9pfs / codir.c
blobec9cc7fb274a80849e86b2e7791ca9c1ec8bc8ac
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_r(V9fsPDU *pdu, V9fsFidState *fidp, struct dirent *dent,
21 struct dirent **result)
23 int err;
24 V9fsState *s = pdu->s;
26 if (v9fs_request_cancelled(pdu)) {
27 return -EINTR;
29 v9fs_co_run_in_worker(
31 errno = 0;
32 err = s->ops->readdir_r(&s->ctx, &fidp->fs, dent, result);
33 if (!*result && errno) {
34 err = -errno;
35 } else {
36 err = 0;
38 });
39 return err;
42 off_t v9fs_co_telldir(V9fsPDU *pdu, V9fsFidState *fidp)
44 off_t err;
45 V9fsState *s = pdu->s;
47 if (v9fs_request_cancelled(pdu)) {
48 return -EINTR;
50 v9fs_co_run_in_worker(
52 err = s->ops->telldir(&s->ctx, &fidp->fs);
53 if (err < 0) {
54 err = -errno;
56 });
57 return err;
60 void v9fs_co_seekdir(V9fsPDU *pdu, V9fsFidState *fidp, off_t offset)
62 V9fsState *s = pdu->s;
63 if (v9fs_request_cancelled(pdu)) {
64 return;
66 v9fs_co_run_in_worker(
68 s->ops->seekdir(&s->ctx, &fidp->fs, offset);
69 });
72 void v9fs_co_rewinddir(V9fsPDU *pdu, V9fsFidState *fidp)
74 V9fsState *s = pdu->s;
75 if (v9fs_request_cancelled(pdu)) {
76 return;
78 v9fs_co_run_in_worker(
80 s->ops->rewinddir(&s->ctx, &fidp->fs);
81 });
84 int v9fs_co_mkdir(V9fsPDU *pdu, V9fsFidState *fidp, V9fsString *name,
85 mode_t mode, uid_t uid, gid_t gid, struct stat *stbuf)
87 int err;
88 FsCred cred;
89 V9fsPath path;
90 V9fsState *s = pdu->s;
92 if (v9fs_request_cancelled(pdu)) {
93 return -EINTR;
95 cred_init(&cred);
96 cred.fc_mode = mode;
97 cred.fc_uid = uid;
98 cred.fc_gid = gid;
99 v9fs_path_read_lock(s);
100 v9fs_co_run_in_worker(
102 err = s->ops->mkdir(&s->ctx, &fidp->path, name->data, &cred);
103 if (err < 0) {
104 err = -errno;
105 } else {
106 v9fs_path_init(&path);
107 err = v9fs_name_to_path(s, &fidp->path, name->data, &path);
108 if (!err) {
109 err = s->ops->lstat(&s->ctx, &path, stbuf);
110 if (err < 0) {
111 err = -errno;
114 v9fs_path_free(&path);
117 v9fs_path_unlock(s);
118 return err;
121 int v9fs_co_opendir(V9fsPDU *pdu, V9fsFidState *fidp)
123 int err;
124 V9fsState *s = pdu->s;
126 if (v9fs_request_cancelled(pdu)) {
127 return -EINTR;
129 v9fs_path_read_lock(s);
130 v9fs_co_run_in_worker(
132 err = s->ops->opendir(&s->ctx, &fidp->path, &fidp->fs);
133 if (err < 0) {
134 err = -errno;
135 } else {
136 err = 0;
139 v9fs_path_unlock(s);
140 if (!err) {
141 total_open_fd++;
142 if (total_open_fd > open_fd_hw) {
143 v9fs_reclaim_fd(pdu);
146 return err;
149 int v9fs_co_closedir(V9fsPDU *pdu, V9fsFidOpenState *fs)
151 int err;
152 V9fsState *s = pdu->s;
154 if (v9fs_request_cancelled(pdu)) {
155 return -EINTR;
157 v9fs_co_run_in_worker(
159 err = s->ops->closedir(&s->ctx, fs);
160 if (err < 0) {
161 err = -errno;
164 if (!err) {
165 total_open_fd--;
167 return err;