5 * Copyright IBM, Corp. 2011
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_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 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 v9fs_co_fstat(V9fsPDU
*pdu
, V9fsFidState
*fidp
, struct stat
*stbuf
)
67 V9fsState
*s
= pdu
->s
;
69 if (v9fs_request_cancelled(pdu
)) {
72 v9fs_co_run_in_worker(
74 err
= s
->ops
->fstat(&s
->ctx
, fidp
->fid_type
, &fidp
->fs
, stbuf
);
80 * Some FS driver (local:mapped-file) can't support fetching attributes
81 * using file descriptor. Use Path name in that case.
83 if (err
== -EOPNOTSUPP
) {
84 err
= v9fs_co_lstat(pdu
, &fidp
->path
, stbuf
);
87 * fstat on an unlinked file. Work with partial results
88 * returned from s->ops->fstat
96 int v9fs_co_open(V9fsPDU
*pdu
, V9fsFidState
*fidp
, int flags
)
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
->open(&s
->ctx
, &fidp
->path
, flags
, &fidp
->fs
);
117 if (total_open_fd
> open_fd_hw
) {
118 v9fs_reclaim_fd(pdu
);
124 int v9fs_co_open2(V9fsPDU
*pdu
, V9fsFidState
*fidp
, V9fsString
*name
, gid_t gid
,
125 int flags
, int mode
, struct stat
*stbuf
)
130 V9fsState
*s
= pdu
->s
;
132 if (v9fs_request_cancelled(pdu
)) {
136 cred
.fc_mode
= mode
& 07777;
137 cred
.fc_uid
= fidp
->uid
;
140 * Hold the directory fid lock so that directory path name
141 * don't change. Read lock is fine because this fid cannot
142 * be used by any other operation.
144 v9fs_path_read_lock(s
);
145 v9fs_co_run_in_worker(
147 err
= s
->ops
->open2(&s
->ctx
, &fidp
->path
,
148 name
->data
, flags
, &cred
, &fidp
->fs
);
152 v9fs_path_init(&path
);
153 err
= v9fs_name_to_path(s
, &fidp
->path
, name
->data
, &path
);
155 err
= s
->ops
->lstat(&s
->ctx
, &path
, stbuf
);
158 s
->ops
->close(&s
->ctx
, &fidp
->fs
);
160 v9fs_path_copy(&fidp
->path
, &path
);
163 s
->ops
->close(&s
->ctx
, &fidp
->fs
);
165 v9fs_path_free(&path
);
171 if (total_open_fd
> open_fd_hw
) {
172 v9fs_reclaim_fd(pdu
);
178 int v9fs_co_close(V9fsPDU
*pdu
, V9fsFidOpenState
*fs
)
181 V9fsState
*s
= pdu
->s
;
183 if (v9fs_request_cancelled(pdu
)) {
186 v9fs_co_run_in_worker(
188 err
= s
->ops
->close(&s
->ctx
, fs
);
199 int v9fs_co_fsync(V9fsPDU
*pdu
, V9fsFidState
*fidp
, int datasync
)
202 V9fsState
*s
= pdu
->s
;
204 if (v9fs_request_cancelled(pdu
)) {
207 v9fs_co_run_in_worker(
209 err
= s
->ops
->fsync(&s
->ctx
, fidp
->fid_type
, &fidp
->fs
, datasync
);
217 int v9fs_co_link(V9fsPDU
*pdu
, V9fsFidState
*oldfid
,
218 V9fsFidState
*newdirfid
, V9fsString
*name
)
221 V9fsState
*s
= pdu
->s
;
223 if (v9fs_request_cancelled(pdu
)) {
226 v9fs_path_read_lock(s
);
227 v9fs_co_run_in_worker(
229 err
= s
->ops
->link(&s
->ctx
, &oldfid
->path
,
230 &newdirfid
->path
, name
->data
);
239 int v9fs_co_pwritev(V9fsPDU
*pdu
, V9fsFidState
*fidp
,
240 struct iovec
*iov
, int iovcnt
, int64_t offset
)
243 V9fsState
*s
= pdu
->s
;
245 if (v9fs_request_cancelled(pdu
)) {
248 v9fs_co_run_in_worker(
250 err
= s
->ops
->pwritev(&s
->ctx
, &fidp
->fs
, iov
, iovcnt
, offset
);
258 int v9fs_co_preadv(V9fsPDU
*pdu
, V9fsFidState
*fidp
,
259 struct iovec
*iov
, int iovcnt
, int64_t offset
)
262 V9fsState
*s
= pdu
->s
;
264 if (v9fs_request_cancelled(pdu
)) {
267 v9fs_co_run_in_worker(
269 err
= s
->ops
->preadv(&s
->ctx
, &fidp
->fs
, iov
, iovcnt
, offset
);