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 v9fs_co_readdir(V9fsPDU
*pdu
, V9fsFidState
*fidp
, struct dirent
**dent
)
23 V9fsState
*s
= pdu
->s
;
25 if (v9fs_request_cancelled(pdu
)) {
28 v9fs_co_run_in_worker(
33 entry
= s
->ops
->readdir(&s
->ctx
, &fidp
->fs
);
34 if (!entry
&& errno
) {
44 off_t
v9fs_co_telldir(V9fsPDU
*pdu
, V9fsFidState
*fidp
)
47 V9fsState
*s
= pdu
->s
;
49 if (v9fs_request_cancelled(pdu
)) {
52 v9fs_co_run_in_worker(
54 err
= s
->ops
->telldir(&s
->ctx
, &fidp
->fs
);
62 void v9fs_co_seekdir(V9fsPDU
*pdu
, V9fsFidState
*fidp
, off_t offset
)
64 V9fsState
*s
= pdu
->s
;
65 if (v9fs_request_cancelled(pdu
)) {
68 v9fs_co_run_in_worker(
70 s
->ops
->seekdir(&s
->ctx
, &fidp
->fs
, offset
);
74 void v9fs_co_rewinddir(V9fsPDU
*pdu
, V9fsFidState
*fidp
)
76 V9fsState
*s
= pdu
->s
;
77 if (v9fs_request_cancelled(pdu
)) {
80 v9fs_co_run_in_worker(
82 s
->ops
->rewinddir(&s
->ctx
, &fidp
->fs
);
86 int v9fs_co_mkdir(V9fsPDU
*pdu
, V9fsFidState
*fidp
, V9fsString
*name
,
87 mode_t mode
, uid_t uid
, gid_t gid
, struct stat
*stbuf
)
92 V9fsState
*s
= pdu
->s
;
94 if (v9fs_request_cancelled(pdu
)) {
101 v9fs_path_read_lock(s
);
102 v9fs_co_run_in_worker(
104 err
= s
->ops
->mkdir(&s
->ctx
, &fidp
->path
, name
->data
, &cred
);
108 v9fs_path_init(&path
);
109 err
= v9fs_name_to_path(s
, &fidp
->path
, name
->data
, &path
);
111 err
= s
->ops
->lstat(&s
->ctx
, &path
, stbuf
);
116 v9fs_path_free(&path
);
123 int v9fs_co_opendir(V9fsPDU
*pdu
, V9fsFidState
*fidp
)
126 V9fsState
*s
= pdu
->s
;
128 if (v9fs_request_cancelled(pdu
)) {
131 v9fs_path_read_lock(s
);
132 v9fs_co_run_in_worker(
134 err
= s
->ops
->opendir(&s
->ctx
, &fidp
->path
, &fidp
->fs
);
144 if (total_open_fd
> open_fd_hw
) {
145 v9fs_reclaim_fd(pdu
);
151 int v9fs_co_closedir(V9fsPDU
*pdu
, V9fsFidOpenState
*fs
)
154 V9fsState
*s
= pdu
->s
;
156 if (v9fs_request_cancelled(pdu
)) {
159 v9fs_co_run_in_worker(
161 err
= s
->ops
->closedir(&s
->ctx
, fs
);