4 * Copyright IBM, Corp. 2011
7 * Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
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 int coroutine_fn v9fs_co_st_gen(V9fsPDU *pdu, V9fsPath *path, mode_t st_mode,
24 V9fsState *s = pdu->s;
26 if (v9fs_request_cancelled(pdu)) {
29 if (s->ctx.exops.get_st_gen) {
30 v9fs_path_read_lock(s);
31 v9fs_co_run_in_worker(
33 err = s->ctx.exops.get_st_gen(&s->ctx, path, st_mode,
44 int coroutine_fn v9fs_co_lstat(V9fsPDU *pdu, V9fsPath *path, struct stat *stbuf)
47 V9fsState *s = pdu->s;
49 if (v9fs_request_cancelled(pdu)) {
52 v9fs_path_read_lock(s);
53 v9fs_co_run_in_worker(
55 err = s->ops->lstat(&s->ctx, path, stbuf);
64 int coroutine_fn v9fs_co_fstat(V9fsPDU *pdu, V9fsFidState *fidp,
68 V9fsState *s = pdu->s;
70 if (v9fs_request_cancelled(pdu)) {
73 v9fs_co_run_in_worker(
75 err = s->ops->fstat(&s->ctx, fidp->fid_type, &fidp->fs, stbuf);
81 * Some FS driver (local:mapped-file) can't support fetching attributes
82 * using file descriptor. Use Path name in that case.
84 if (err == -EOPNOTSUPP) {
85 err = v9fs_co_lstat(pdu, &fidp->path, stbuf);
88 * fstat on an unlinked file. Work with partial results
89 * returned from s->ops->fstat
97 int coroutine_fn v9fs_co_open(V9fsPDU *pdu, V9fsFidState *fidp, int flags)
100 V9fsState *s = pdu->s;
102 if (v9fs_request_cancelled(pdu)) {
105 v9fs_path_read_lock(s);
106 v9fs_co_run_in_worker(
108 err = s->ops->open(&s->ctx, &fidp->path, flags, &fidp->fs);
118 if (total_open_fd > open_fd_hw) {
119 v9fs_reclaim_fd(pdu);
125 int coroutine_fn v9fs_co_open2(V9fsPDU *pdu, V9fsFidState *fidp,
126 V9fsString *name, gid_t gid, int flags, int mode,
132 V9fsState *s = pdu->s;
134 if (v9fs_request_cancelled(pdu)) {
138 cred.fc_mode = mode & 07777;
139 cred.fc_uid = fidp->uid;
142 * Hold the directory fid lock so that directory path name
143 * don't change. Take the write lock to be sure this fid
144 * cannot be used by another operation.
146 v9fs_path_write_lock(s);
147 v9fs_co_run_in_worker(
149 err = s->ops->open2(&s->ctx, &fidp->path,
150 name->data, flags, &cred, &fidp->fs);
154 v9fs_path_init(&path);
155 err = v9fs_name_to_path(s, &fidp->path, name->data, &path);
157 err = s->ops->lstat(&s->ctx, &path, stbuf);
160 s->ops->close(&s->ctx, &fidp->fs);
162 v9fs_path_copy(&fidp->path, &path);
165 s->ops->close(&s->ctx, &fidp->fs);
167 v9fs_path_free(&path);
173 if (total_open_fd > open_fd_hw) {
174 v9fs_reclaim_fd(pdu);
180 int coroutine_fn v9fs_co_close(V9fsPDU *pdu, V9fsFidOpenState *fs)
183 V9fsState *s = pdu->s;
185 if (v9fs_request_cancelled(pdu)) {
188 v9fs_co_run_in_worker(
190 err = s->ops->close(&s->ctx, fs);
201 int coroutine_fn v9fs_co_fsync(V9fsPDU *pdu, V9fsFidState *fidp, int datasync)
204 V9fsState *s = pdu->s;
206 if (v9fs_request_cancelled(pdu)) {
209 v9fs_co_run_in_worker(
211 err = s->ops->fsync(&s->ctx, fidp->fid_type, &fidp->fs, datasync);
219 int coroutine_fn v9fs_co_link(V9fsPDU *pdu, V9fsFidState *oldfid,
220 V9fsFidState *newdirfid, V9fsString *name)
223 V9fsState *s = pdu->s;
225 if (v9fs_request_cancelled(pdu)) {
228 v9fs_path_read_lock(s);
229 v9fs_co_run_in_worker(
231 err = s->ops->link(&s->ctx, &oldfid->path,
232 &newdirfid->path, name->data);
241 int coroutine_fn v9fs_co_pwritev(V9fsPDU *pdu, V9fsFidState *fidp,
242 struct iovec *iov, int iovcnt, int64_t offset)
245 V9fsState *s = pdu->s;
247 if (v9fs_request_cancelled(pdu)) {
250 fsdev_co_throttle_request(s->ctx.fst, true, iov, iovcnt);
251 v9fs_co_run_in_worker(
253 err = s->ops->pwritev(&s->ctx, &fidp->fs, iov, iovcnt, offset);
261 int coroutine_fn v9fs_co_preadv(V9fsPDU *pdu, V9fsFidState *fidp,
262 struct iovec *iov, int iovcnt, int64_t offset)
265 V9fsState *s = pdu->s;
267 if (v9fs_request_cancelled(pdu)) {
270 fsdev_co_throttle_request(s->ctx.fst, false, iov, iovcnt);
271 v9fs_co_run_in_worker(
273 err = s->ops->preadv(&s->ctx, &fidp->fs, iov, iovcnt, offset);