5 * Copyright IBM, Corp. 2011
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 "block/coroutine.h"
18 #include "virtio-9p-coth.h"
20 int v9fs_co_readlink(V9fsPDU *pdu, V9fsPath *path, V9fsString *buf)
24 V9fsState *s = pdu->s;
26 if (v9fs_request_cancelled(pdu)) {
29 buf->data = g_malloc(PATH_MAX);
30 v9fs_path_read_lock(s);
31 v9fs_co_run_in_worker(
33 len = s->ops->readlink(&s->ctx, path,
34 buf->data, PATH_MAX - 1);
52 int v9fs_co_statfs(V9fsPDU *pdu, V9fsPath *path, struct statfs *stbuf)
55 V9fsState *s = pdu->s;
57 if (v9fs_request_cancelled(pdu)) {
60 v9fs_path_read_lock(s);
61 v9fs_co_run_in_worker(
63 err = s->ops->statfs(&s->ctx, path, stbuf);
72 int v9fs_co_chmod(V9fsPDU *pdu, V9fsPath *path, mode_t mode)
76 V9fsState *s = pdu->s;
78 if (v9fs_request_cancelled(pdu)) {
83 v9fs_path_read_lock(s);
84 v9fs_co_run_in_worker(
86 err = s->ops->chmod(&s->ctx, path, &cred);
95 int v9fs_co_utimensat(V9fsPDU *pdu, V9fsPath *path,
96 struct timespec times[2])
99 V9fsState *s = pdu->s;
101 if (v9fs_request_cancelled(pdu)) {
104 v9fs_path_read_lock(s);
105 v9fs_co_run_in_worker(
107 err = s->ops->utimensat(&s->ctx, path, times);
116 int v9fs_co_chown(V9fsPDU *pdu, V9fsPath *path, uid_t uid, gid_t gid)
120 V9fsState *s = pdu->s;
122 if (v9fs_request_cancelled(pdu)) {
128 v9fs_path_read_lock(s);
129 v9fs_co_run_in_worker(
131 err = s->ops->chown(&s->ctx, path, &cred);
140 int v9fs_co_truncate(V9fsPDU *pdu, V9fsPath *path, off_t size)
143 V9fsState *s = pdu->s;
145 if (v9fs_request_cancelled(pdu)) {
148 v9fs_path_read_lock(s);
149 v9fs_co_run_in_worker(
151 err = s->ops->truncate(&s->ctx, path, size);
160 int v9fs_co_mknod(V9fsPDU *pdu, V9fsFidState *fidp, V9fsString *name, uid_t uid,
161 gid_t gid, dev_t dev, mode_t mode, struct stat *stbuf)
166 V9fsState *s = pdu->s;
168 if (v9fs_request_cancelled(pdu)) {
176 v9fs_path_read_lock(s);
177 v9fs_co_run_in_worker(
179 err = s->ops->mknod(&s->ctx, &fidp->path, name->data, &cred);
183 v9fs_path_init(&path);
184 err = v9fs_name_to_path(s, &fidp->path, name->data, &path);
186 err = s->ops->lstat(&s->ctx, &path, stbuf);
191 v9fs_path_free(&path);
198 /* Only works with path name based fid */
199 int v9fs_co_remove(V9fsPDU *pdu, V9fsPath *path)
202 V9fsState *s = pdu->s;
204 if (v9fs_request_cancelled(pdu)) {
207 v9fs_path_read_lock(s);
208 v9fs_co_run_in_worker(
210 err = s->ops->remove(&s->ctx, path->data);
219 int v9fs_co_unlinkat(V9fsPDU *pdu, V9fsPath *path, V9fsString *name, int flags)
222 V9fsState *s = pdu->s;
224 if (v9fs_request_cancelled(pdu)) {
227 v9fs_path_read_lock(s);
228 v9fs_co_run_in_worker(
230 err = s->ops->unlinkat(&s->ctx, path, name->data, flags);
239 /* Only work with path name based fid */
240 int v9fs_co_rename(V9fsPDU *pdu, V9fsPath *oldpath, V9fsPath *newpath)
243 V9fsState *s = pdu->s;
245 if (v9fs_request_cancelled(pdu)) {
248 v9fs_co_run_in_worker(
250 err = s->ops->rename(&s->ctx, oldpath->data, newpath->data);
258 int v9fs_co_renameat(V9fsPDU *pdu, V9fsPath *olddirpath, V9fsString *oldname,
259 V9fsPath *newdirpath, V9fsString *newname)
262 V9fsState *s = pdu->s;
264 if (v9fs_request_cancelled(pdu)) {
267 v9fs_co_run_in_worker(
269 err = s->ops->renameat(&s->ctx, olddirpath, oldname->data,
270 newdirpath, newname->data);
278 int v9fs_co_symlink(V9fsPDU *pdu, V9fsFidState *dfidp, V9fsString *name,
279 const char *oldpath, gid_t gid, struct stat *stbuf)
284 V9fsState *s = pdu->s;
286 if (v9fs_request_cancelled(pdu)) {
290 cred.fc_uid = dfidp->uid;
293 v9fs_path_read_lock(s);
294 v9fs_co_run_in_worker(
296 err = s->ops->symlink(&s->ctx, oldpath, &dfidp->path,
301 v9fs_path_init(&path);
302 err = v9fs_name_to_path(s, &dfidp->path, name->data, &path);
304 err = s->ops->lstat(&s->ctx, &path, stbuf);
309 v9fs_path_free(&path);
317 * For path name based fid we don't block. So we can
318 * directly call the fs driver ops.
320 int v9fs_co_name_to_path(V9fsPDU *pdu, V9fsPath *dirpath,
321 const char *name, V9fsPath *path)
324 V9fsState *s = pdu->s;
326 if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) {
327 err = s->ops->name_to_path(&s->ctx, dirpath, name, path);
332 if (v9fs_request_cancelled(pdu)) {
335 v9fs_co_run_in_worker(
337 err = s->ops->name_to_path(&s->ctx, dirpath, name, path);