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_readdir(V9fsPDU
*pdu
, V9fsFidState
*fidp
,
25 V9fsState
*s
= pdu
->s
;
27 if (v9fs_request_cancelled(pdu
)) {
30 v9fs_co_run_in_worker(
35 entry
= s
->ops
->readdir(&s
->ctx
, &fidp
->fs
);
36 if (!entry
&& errno
) {
46 off_t
v9fs_co_telldir(V9fsPDU
*pdu
, V9fsFidState
*fidp
)
49 V9fsState
*s
= pdu
->s
;
51 if (v9fs_request_cancelled(pdu
)) {
54 v9fs_co_run_in_worker(
56 err
= s
->ops
->telldir(&s
->ctx
, &fidp
->fs
);
64 void coroutine_fn
v9fs_co_seekdir(V9fsPDU
*pdu
, V9fsFidState
*fidp
,
67 V9fsState
*s
= pdu
->s
;
68 if (v9fs_request_cancelled(pdu
)) {
71 v9fs_co_run_in_worker(
73 s
->ops
->seekdir(&s
->ctx
, &fidp
->fs
, offset
);
77 void coroutine_fn
v9fs_co_rewinddir(V9fsPDU
*pdu
, V9fsFidState
*fidp
)
79 V9fsState
*s
= pdu
->s
;
80 if (v9fs_request_cancelled(pdu
)) {
83 v9fs_co_run_in_worker(
85 s
->ops
->rewinddir(&s
->ctx
, &fidp
->fs
);
89 int coroutine_fn
v9fs_co_mkdir(V9fsPDU
*pdu
, V9fsFidState
*fidp
,
90 V9fsString
*name
, mode_t mode
, uid_t uid
,
91 gid_t gid
, struct stat
*stbuf
)
96 V9fsState
*s
= pdu
->s
;
98 if (v9fs_request_cancelled(pdu
)) {
105 v9fs_path_read_lock(s
);
106 v9fs_co_run_in_worker(
108 err
= s
->ops
->mkdir(&s
->ctx
, &fidp
->path
, name
->data
, &cred
);
112 v9fs_path_init(&path
);
113 err
= v9fs_name_to_path(s
, &fidp
->path
, name
->data
, &path
);
115 err
= s
->ops
->lstat(&s
->ctx
, &path
, stbuf
);
120 v9fs_path_free(&path
);
127 int coroutine_fn
v9fs_co_opendir(V9fsPDU
*pdu
, V9fsFidState
*fidp
)
130 V9fsState
*s
= pdu
->s
;
132 if (v9fs_request_cancelled(pdu
)) {
135 v9fs_path_read_lock(s
);
136 v9fs_co_run_in_worker(
138 err
= s
->ops
->opendir(&s
->ctx
, &fidp
->path
, &fidp
->fs
);
148 if (total_open_fd
> open_fd_hw
) {
149 v9fs_reclaim_fd(pdu
);
155 int coroutine_fn
v9fs_co_closedir(V9fsPDU
*pdu
, V9fsFidOpenState
*fs
)
158 V9fsState
*s
= pdu
->s
;
160 if (v9fs_request_cancelled(pdu
)) {
163 v9fs_co_run_in_worker(
165 err
= s
->ops
->closedir(&s
->ctx
, fs
);