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"
18 #include "qemu/main-loop.h"
21 int coroutine_fn
v9fs_co_st_gen(V9fsPDU
*pdu
, V9fsPath
*path
, mode_t st_mode
,
25 V9fsState
*s
= pdu
->s
;
27 if (v9fs_request_cancelled(pdu
)) {
30 if (s
->ctx
.exops
.get_st_gen
) {
31 v9fs_path_read_lock(s
);
32 v9fs_co_run_in_worker(
34 err
= s
->ctx
.exops
.get_st_gen(&s
->ctx
, path
, st_mode
,
45 int coroutine_fn
v9fs_co_lstat(V9fsPDU
*pdu
, V9fsPath
*path
, struct stat
*stbuf
)
48 V9fsState
*s
= pdu
->s
;
50 if (v9fs_request_cancelled(pdu
)) {
53 v9fs_path_read_lock(s
);
54 v9fs_co_run_in_worker(
56 err
= s
->ops
->lstat(&s
->ctx
, path
, stbuf
);
65 int coroutine_fn
v9fs_co_fstat(V9fsPDU
*pdu
, V9fsFidState
*fidp
,
69 V9fsState
*s
= pdu
->s
;
71 if (v9fs_request_cancelled(pdu
)) {
74 v9fs_co_run_in_worker(
76 err
= s
->ops
->fstat(&s
->ctx
, fidp
->fid_type
, &fidp
->fs
, stbuf
);
82 * Some FS driver (local:mapped-file) can't support fetching attributes
83 * using file descriptor. Use Path name in that case.
85 if (err
== -EOPNOTSUPP
) {
86 err
= v9fs_co_lstat(pdu
, &fidp
->path
, stbuf
);
89 * fstat on an unlinked file. Work with partial results
90 * returned from s->ops->fstat
98 int coroutine_fn
v9fs_co_open(V9fsPDU
*pdu
, V9fsFidState
*fidp
, int flags
)
101 V9fsState
*s
= pdu
->s
;
103 if (v9fs_request_cancelled(pdu
)) {
106 v9fs_path_read_lock(s
);
107 v9fs_co_run_in_worker(
109 err
= s
->ops
->open(&s
->ctx
, &fidp
->path
, flags
, &fidp
->fs
);
119 if (total_open_fd
> open_fd_hw
) {
120 v9fs_reclaim_fd(pdu
);
126 int coroutine_fn
v9fs_co_open2(V9fsPDU
*pdu
, V9fsFidState
*fidp
,
127 V9fsString
*name
, gid_t gid
, int flags
, int mode
,
133 V9fsState
*s
= pdu
->s
;
135 if (v9fs_request_cancelled(pdu
)) {
139 cred
.fc_mode
= mode
& 07777;
140 cred
.fc_uid
= fidp
->uid
;
143 * Hold the directory fid lock so that directory path name
144 * don't change. Take the write lock to be sure this fid
145 * cannot be used by another operation.
147 v9fs_path_write_lock(s
);
148 v9fs_co_run_in_worker(
150 err
= s
->ops
->open2(&s
->ctx
, &fidp
->path
,
151 name
->data
, flags
, &cred
, &fidp
->fs
);
155 v9fs_path_init(&path
);
156 err
= v9fs_name_to_path(s
, &fidp
->path
, name
->data
, &path
);
158 err
= s
->ops
->lstat(&s
->ctx
, &path
, stbuf
);
161 s
->ops
->close(&s
->ctx
, &fidp
->fs
);
163 v9fs_path_copy(&fidp
->path
, &path
);
166 s
->ops
->close(&s
->ctx
, &fidp
->fs
);
168 v9fs_path_free(&path
);
174 if (total_open_fd
> open_fd_hw
) {
175 v9fs_reclaim_fd(pdu
);
181 int coroutine_fn
v9fs_co_close(V9fsPDU
*pdu
, V9fsFidOpenState
*fs
)
184 V9fsState
*s
= pdu
->s
;
186 if (v9fs_request_cancelled(pdu
)) {
189 v9fs_co_run_in_worker(
191 err
= s
->ops
->close(&s
->ctx
, fs
);
202 int coroutine_fn
v9fs_co_fsync(V9fsPDU
*pdu
, V9fsFidState
*fidp
, int datasync
)
205 V9fsState
*s
= pdu
->s
;
207 if (v9fs_request_cancelled(pdu
)) {
210 v9fs_co_run_in_worker(
212 err
= s
->ops
->fsync(&s
->ctx
, fidp
->fid_type
, &fidp
->fs
, datasync
);
220 int coroutine_fn
v9fs_co_link(V9fsPDU
*pdu
, V9fsFidState
*oldfid
,
221 V9fsFidState
*newdirfid
, V9fsString
*name
)
224 V9fsState
*s
= pdu
->s
;
226 if (v9fs_request_cancelled(pdu
)) {
229 v9fs_path_read_lock(s
);
230 v9fs_co_run_in_worker(
232 err
= s
->ops
->link(&s
->ctx
, &oldfid
->path
,
233 &newdirfid
->path
, name
->data
);
242 int coroutine_fn
v9fs_co_pwritev(V9fsPDU
*pdu
, V9fsFidState
*fidp
,
243 struct iovec
*iov
, int iovcnt
, int64_t offset
)
246 V9fsState
*s
= pdu
->s
;
248 if (v9fs_request_cancelled(pdu
)) {
251 fsdev_co_throttle_request(s
->ctx
.fst
, true, iov
, iovcnt
);
252 v9fs_co_run_in_worker(
254 err
= s
->ops
->pwritev(&s
->ctx
, &fidp
->fs
, iov
, iovcnt
, offset
);
262 int coroutine_fn
v9fs_co_preadv(V9fsPDU
*pdu
, V9fsFidState
*fidp
,
263 struct iovec
*iov
, int iovcnt
, int64_t offset
)
266 V9fsState
*s
= pdu
->s
;
268 if (v9fs_request_cancelled(pdu
)) {
271 fsdev_co_throttle_request(s
->ctx
.fst
, false, iov
, iovcnt
);
272 v9fs_co_run_in_worker(
274 err
= s
->ops
->preadv(&s
->ctx
, &fidp
->fs
, iov
, iovcnt
, offset
);