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.
15 * Not so fast! You might want to read the 9p developer docs first:
16 * https://wiki.qemu.org/Documentation/9p
19 #include "qemu/osdep.h"
20 #include "fsdev/qemu-fsdev.h"
21 #include "qemu/thread.h"
22 #include "qemu/main-loop.h"
25 int coroutine_fn
v9fs_co_st_gen(V9fsPDU
*pdu
, V9fsPath
*path
, mode_t st_mode
,
29 V9fsState
*s
= pdu
->s
;
31 if (v9fs_request_cancelled(pdu
)) {
34 if (s
->ctx
.exops
.get_st_gen
) {
35 v9fs_path_read_lock(s
);
36 v9fs_co_run_in_worker(
38 err
= s
->ctx
.exops
.get_st_gen(&s
->ctx
, path
, st_mode
,
49 int coroutine_fn
v9fs_co_lstat(V9fsPDU
*pdu
, V9fsPath
*path
, struct stat
*stbuf
)
52 V9fsState
*s
= pdu
->s
;
54 if (v9fs_request_cancelled(pdu
)) {
57 v9fs_path_read_lock(s
);
58 v9fs_co_run_in_worker(
60 err
= s
->ops
->lstat(&s
->ctx
, path
, stbuf
);
69 int coroutine_fn
v9fs_co_fstat(V9fsPDU
*pdu
, V9fsFidState
*fidp
,
73 V9fsState
*s
= pdu
->s
;
75 if (v9fs_request_cancelled(pdu
)) {
78 v9fs_co_run_in_worker(
80 err
= s
->ops
->fstat(&s
->ctx
, fidp
->fid_type
, &fidp
->fs
, stbuf
);
86 * Some FS driver (local:mapped-file) can't support fetching attributes
87 * using file descriptor. Use Path name in that case.
89 if (err
== -EOPNOTSUPP
) {
90 err
= v9fs_co_lstat(pdu
, &fidp
->path
, stbuf
);
93 * fstat on an unlinked file. Work with partial results
94 * returned from s->ops->fstat
102 int coroutine_fn
v9fs_co_open(V9fsPDU
*pdu
, V9fsFidState
*fidp
, int flags
)
105 V9fsState
*s
= pdu
->s
;
107 if (v9fs_request_cancelled(pdu
)) {
110 v9fs_path_read_lock(s
);
111 v9fs_co_run_in_worker(
113 err
= s
->ops
->open(&s
->ctx
, &fidp
->path
, flags
, &fidp
->fs
);
123 if (total_open_fd
> open_fd_hw
) {
124 v9fs_reclaim_fd(pdu
);
130 int coroutine_fn
v9fs_co_open2(V9fsPDU
*pdu
, V9fsFidState
*fidp
,
131 V9fsString
*name
, gid_t gid
, int flags
, int mode
,
137 V9fsState
*s
= pdu
->s
;
139 if (v9fs_request_cancelled(pdu
)) {
143 cred
.fc_mode
= mode
& 07777;
144 cred
.fc_uid
= fidp
->uid
;
147 * Hold the directory fid lock so that directory path name
148 * don't change. Take the write lock to be sure this fid
149 * cannot be used by another operation.
151 v9fs_path_write_lock(s
);
152 v9fs_co_run_in_worker(
154 err
= s
->ops
->open2(&s
->ctx
, &fidp
->path
,
155 name
->data
, flags
, &cred
, &fidp
->fs
);
159 v9fs_path_init(&path
);
160 err
= v9fs_name_to_path(s
, &fidp
->path
, name
->data
, &path
);
162 err
= s
->ops
->lstat(&s
->ctx
, &path
, stbuf
);
165 s
->ops
->close(&s
->ctx
, &fidp
->fs
);
167 v9fs_path_copy(&fidp
->path
, &path
);
170 s
->ops
->close(&s
->ctx
, &fidp
->fs
);
172 v9fs_path_free(&path
);
178 if (total_open_fd
> open_fd_hw
) {
179 v9fs_reclaim_fd(pdu
);
185 int coroutine_fn
v9fs_co_close(V9fsPDU
*pdu
, V9fsFidOpenState
*fs
)
188 V9fsState
*s
= pdu
->s
;
190 if (v9fs_request_cancelled(pdu
)) {
193 v9fs_co_run_in_worker(
195 err
= s
->ops
->close(&s
->ctx
, fs
);
206 int coroutine_fn
v9fs_co_fsync(V9fsPDU
*pdu
, V9fsFidState
*fidp
, int datasync
)
209 V9fsState
*s
= pdu
->s
;
211 if (v9fs_request_cancelled(pdu
)) {
214 v9fs_co_run_in_worker(
216 err
= s
->ops
->fsync(&s
->ctx
, fidp
->fid_type
, &fidp
->fs
, datasync
);
224 int coroutine_fn
v9fs_co_link(V9fsPDU
*pdu
, V9fsFidState
*oldfid
,
225 V9fsFidState
*newdirfid
, V9fsString
*name
)
228 V9fsState
*s
= pdu
->s
;
230 if (v9fs_request_cancelled(pdu
)) {
233 v9fs_path_read_lock(s
);
234 v9fs_co_run_in_worker(
236 err
= s
->ops
->link(&s
->ctx
, &oldfid
->path
,
237 &newdirfid
->path
, name
->data
);
246 int coroutine_fn
v9fs_co_pwritev(V9fsPDU
*pdu
, V9fsFidState
*fidp
,
247 struct iovec
*iov
, int iovcnt
, int64_t offset
)
250 V9fsState
*s
= pdu
->s
;
252 if (v9fs_request_cancelled(pdu
)) {
255 fsdev_co_throttle_request(s
->ctx
.fst
, THROTTLE_WRITE
, iov
, iovcnt
);
256 v9fs_co_run_in_worker(
258 err
= s
->ops
->pwritev(&s
->ctx
, &fidp
->fs
, iov
, iovcnt
, offset
);
266 int coroutine_fn
v9fs_co_preadv(V9fsPDU
*pdu
, V9fsFidState
*fidp
,
267 struct iovec
*iov
, int iovcnt
, int64_t offset
)
270 V9fsState
*s
= pdu
->s
;
272 if (v9fs_request_cancelled(pdu
)) {
275 fsdev_co_throttle_request(s
->ctx
.fst
, THROTTLE_READ
, iov
, iovcnt
);
276 v9fs_co_run_in_worker(
278 err
= s
->ops
->preadv(&s
->ctx
, &fidp
->fs
, iov
, iovcnt
, offset
);