4 * Copyright IBM, Corp. 2011
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"
20 static ssize_t __readlink(V9fsState *s, V9fsPath *path, V9fsString *buf)
22 ssize_t len, maxlen = PATH_MAX;
24 buf->data = g_malloc(PATH_MAX);
26 len = s->ops->readlink(&s->ctx, path, buf->data, maxlen);
32 } else if (len == maxlen) {
34 * We dodn't have space to put the NULL or we have more
35 * to read. Increase the size and try again
39 buf->data = g_malloc(maxlen);
43 * Null terminate the readlink output
45 buf->data[len] = '\0';
52 int coroutine_fn v9fs_co_readlink(V9fsPDU *pdu, V9fsPath *path, V9fsString *buf)
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 = __readlink(s, path, buf);
72 int coroutine_fn v9fs_co_statfs(V9fsPDU *pdu, V9fsPath *path,
76 V9fsState *s = pdu->s;
78 if (v9fs_request_cancelled(pdu)) {
81 v9fs_path_read_lock(s);
82 v9fs_co_run_in_worker(
84 err = s->ops->statfs(&s->ctx, path, stbuf);
93 int coroutine_fn v9fs_co_chmod(V9fsPDU *pdu, V9fsPath *path, mode_t mode)
97 V9fsState *s = pdu->s;
99 if (v9fs_request_cancelled(pdu)) {
104 v9fs_path_read_lock(s);
105 v9fs_co_run_in_worker(
107 err = s->ops->chmod(&s->ctx, path, &cred);
116 int coroutine_fn v9fs_co_utimensat(V9fsPDU *pdu, V9fsPath *path,
117 struct timespec times[2])
120 V9fsState *s = pdu->s;
122 if (v9fs_request_cancelled(pdu)) {
125 v9fs_path_read_lock(s);
126 v9fs_co_run_in_worker(
128 err = s->ops->utimensat(&s->ctx, path, times);
137 int coroutine_fn v9fs_co_chown(V9fsPDU *pdu, V9fsPath *path, uid_t uid,
142 V9fsState *s = pdu->s;
144 if (v9fs_request_cancelled(pdu)) {
150 v9fs_path_read_lock(s);
151 v9fs_co_run_in_worker(
153 err = s->ops->chown(&s->ctx, path, &cred);
162 int coroutine_fn v9fs_co_truncate(V9fsPDU *pdu, V9fsPath *path, off_t size)
165 V9fsState *s = pdu->s;
167 if (v9fs_request_cancelled(pdu)) {
170 v9fs_path_read_lock(s);
171 v9fs_co_run_in_worker(
173 err = s->ops->truncate(&s->ctx, path, size);
182 int coroutine_fn v9fs_co_mknod(V9fsPDU *pdu, V9fsFidState *fidp,
183 V9fsString *name, uid_t uid, gid_t gid,
184 dev_t dev, mode_t mode, struct stat *stbuf)
189 V9fsState *s = pdu->s;
191 if (v9fs_request_cancelled(pdu)) {
199 v9fs_path_read_lock(s);
200 v9fs_co_run_in_worker(
202 err = s->ops->mknod(&s->ctx, &fidp->path, name->data, &cred);
206 v9fs_path_init(&path);
207 err = v9fs_name_to_path(s, &fidp->path, name->data, &path);
209 err = s->ops->lstat(&s->ctx, &path, stbuf);
214 v9fs_path_free(&path);
221 /* Only works with path name based fid */
222 int coroutine_fn v9fs_co_remove(V9fsPDU *pdu, V9fsPath *path)
225 V9fsState *s = pdu->s;
227 if (v9fs_request_cancelled(pdu)) {
230 v9fs_path_read_lock(s);
231 v9fs_co_run_in_worker(
233 err = s->ops->remove(&s->ctx, path->data);
242 int coroutine_fn v9fs_co_unlinkat(V9fsPDU *pdu, V9fsPath *path,
243 V9fsString *name, int flags)
246 V9fsState *s = pdu->s;
248 if (v9fs_request_cancelled(pdu)) {
251 v9fs_path_read_lock(s);
252 v9fs_co_run_in_worker(
254 err = s->ops->unlinkat(&s->ctx, path, name->data, flags);
263 /* Only work with path name based fid */
264 int coroutine_fn v9fs_co_rename(V9fsPDU *pdu, V9fsPath *oldpath,
268 V9fsState *s = pdu->s;
270 if (v9fs_request_cancelled(pdu)) {
273 v9fs_co_run_in_worker(
275 err = s->ops->rename(&s->ctx, oldpath->data, newpath->data);
283 int coroutine_fn v9fs_co_renameat(V9fsPDU *pdu, V9fsPath *olddirpath,
284 V9fsString *oldname, V9fsPath *newdirpath,
288 V9fsState *s = pdu->s;
290 if (v9fs_request_cancelled(pdu)) {
293 v9fs_co_run_in_worker(
295 err = s->ops->renameat(&s->ctx, olddirpath, oldname->data,
296 newdirpath, newname->data);
304 int coroutine_fn v9fs_co_symlink(V9fsPDU *pdu, V9fsFidState *dfidp,
305 V9fsString *name, const char *oldpath,
306 gid_t gid, struct stat *stbuf)
311 V9fsState *s = pdu->s;
313 if (v9fs_request_cancelled(pdu)) {
317 cred.fc_uid = dfidp->uid;
320 v9fs_path_read_lock(s);
321 v9fs_co_run_in_worker(
323 err = s->ops->symlink(&s->ctx, oldpath, &dfidp->path,
328 v9fs_path_init(&path);
329 err = v9fs_name_to_path(s, &dfidp->path, name->data, &path);
331 err = s->ops->lstat(&s->ctx, &path, stbuf);
336 v9fs_path_free(&path);
344 * For path name based fid we don't block. So we can
345 * directly call the fs driver ops.
347 int coroutine_fn v9fs_co_name_to_path(V9fsPDU *pdu, V9fsPath *dirpath,
348 const char *name, V9fsPath *path)
351 V9fsState *s = pdu->s;
353 if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) {
354 err = s->ops->name_to_path(&s->ctx, dirpath, name, path);
359 if (v9fs_request_cancelled(pdu)) {
362 v9fs_co_run_in_worker(
364 err = s->ops->name_to_path(&s->ctx, dirpath, name, path);