]>
Commit | Line | Data |
---|---|---|
dcb9dbe3 AK |
1 | |
2 | /* | |
3 | * Virtio 9p backend | |
4 | * | |
5 | * Copyright IBM, Corp. 2011 | |
6 | * | |
7 | * Authors: | |
8 | * Aneesh Kumar K.V <[email protected]> | |
9 | * | |
10 | * This work is licensed under the terms of the GNU GPL, version 2. See | |
11 | * the COPYING file in the top-level directory. | |
12 | * | |
13 | */ | |
14 | ||
15 | #include "fsdev/qemu-fsdev.h" | |
16 | #include "qemu-thread.h" | |
17 | #include "qemu-coroutine.h" | |
18 | #include "virtio-9p-coth.h" | |
19 | ||
bccacf6c | 20 | int v9fs_co_readdir_r(V9fsPDU *pdu, V9fsFidState *fidp, struct dirent *dent, |
5f524c1e | 21 | struct dirent **result) |
dcb9dbe3 AK |
22 | { |
23 | int err; | |
bccacf6c | 24 | V9fsState *s = pdu->s; |
dcb9dbe3 | 25 | |
bccacf6c AK |
26 | if (v9fs_request_cancelled(pdu)) { |
27 | return -EINTR; | |
28 | } | |
dcb9dbe3 AK |
29 | v9fs_co_run_in_worker( |
30 | { | |
31 | errno = 0; | |
cc720ddb | 32 | err = s->ops->readdir_r(&s->ctx, &fidp->fs, dent, result); |
5f524c1e | 33 | if (!*result && errno) { |
dcb9dbe3 AK |
34 | err = -errno; |
35 | } else { | |
36 | err = 0; | |
37 | } | |
38 | }); | |
39 | return err; | |
40 | } | |
41 | ||
bccacf6c | 42 | off_t v9fs_co_telldir(V9fsPDU *pdu, V9fsFidState *fidp) |
dcb9dbe3 AK |
43 | { |
44 | off_t err; | |
bccacf6c | 45 | V9fsState *s = pdu->s; |
dcb9dbe3 | 46 | |
bccacf6c AK |
47 | if (v9fs_request_cancelled(pdu)) { |
48 | return -EINTR; | |
49 | } | |
dcb9dbe3 AK |
50 | v9fs_co_run_in_worker( |
51 | { | |
cc720ddb | 52 | err = s->ops->telldir(&s->ctx, &fidp->fs); |
dcb9dbe3 AK |
53 | if (err < 0) { |
54 | err = -errno; | |
55 | } | |
56 | }); | |
57 | return err; | |
58 | } | |
59 | ||
bccacf6c | 60 | void v9fs_co_seekdir(V9fsPDU *pdu, V9fsFidState *fidp, off_t offset) |
dcb9dbe3 | 61 | { |
bccacf6c AK |
62 | V9fsState *s = pdu->s; |
63 | if (v9fs_request_cancelled(pdu)) { | |
64 | return; | |
65 | } | |
dcb9dbe3 AK |
66 | v9fs_co_run_in_worker( |
67 | { | |
cc720ddb | 68 | s->ops->seekdir(&s->ctx, &fidp->fs, offset); |
dcb9dbe3 AK |
69 | }); |
70 | } | |
71 | ||
bccacf6c | 72 | void v9fs_co_rewinddir(V9fsPDU *pdu, V9fsFidState *fidp) |
dcb9dbe3 | 73 | { |
bccacf6c AK |
74 | V9fsState *s = pdu->s; |
75 | if (v9fs_request_cancelled(pdu)) { | |
76 | return; | |
77 | } | |
dcb9dbe3 AK |
78 | v9fs_co_run_in_worker( |
79 | { | |
cc720ddb | 80 | s->ops->rewinddir(&s->ctx, &fidp->fs); |
dcb9dbe3 AK |
81 | }); |
82 | } | |
d0884642 | 83 | |
bccacf6c | 84 | int v9fs_co_mkdir(V9fsPDU *pdu, V9fsFidState *fidp, V9fsString *name, |
02cb7f3a | 85 | mode_t mode, uid_t uid, gid_t gid, struct stat *stbuf) |
d0884642 VJ |
86 | { |
87 | int err; | |
88 | FsCred cred; | |
2289be19 | 89 | V9fsPath path; |
bccacf6c | 90 | V9fsState *s = pdu->s; |
d0884642 | 91 | |
bccacf6c | 92 | if (v9fs_request_cancelled(pdu)) { |
3a93113a | 93 | return -EINTR; |
bccacf6c | 94 | } |
d0884642 VJ |
95 | cred_init(&cred); |
96 | cred.fc_mode = mode; | |
97 | cred.fc_uid = uid; | |
98 | cred.fc_gid = gid; | |
532decb7 | 99 | v9fs_path_read_lock(s); |
d0884642 VJ |
100 | v9fs_co_run_in_worker( |
101 | { | |
2289be19 | 102 | err = s->ops->mkdir(&s->ctx, &fidp->path, name->data, &cred); |
d0884642 VJ |
103 | if (err < 0) { |
104 | err = -errno; | |
02cb7f3a | 105 | } else { |
2289be19 AK |
106 | v9fs_path_init(&path); |
107 | err = v9fs_name_to_path(s, &fidp->path, name->data, &path); | |
108 | if (!err) { | |
109 | err = s->ops->lstat(&s->ctx, &path, stbuf); | |
110 | if (err < 0) { | |
111 | err = -errno; | |
112 | } | |
02cb7f3a | 113 | } |
2289be19 | 114 | v9fs_path_free(&path); |
d0884642 VJ |
115 | } |
116 | }); | |
532decb7 | 117 | v9fs_path_unlock(s); |
d0884642 VJ |
118 | return err; |
119 | } | |
f6b7f0ab | 120 | |
bccacf6c | 121 | int v9fs_co_opendir(V9fsPDU *pdu, V9fsFidState *fidp) |
f6b7f0ab AK |
122 | { |
123 | int err; | |
bccacf6c | 124 | V9fsState *s = pdu->s; |
f6b7f0ab | 125 | |
bccacf6c | 126 | if (v9fs_request_cancelled(pdu)) { |
3a93113a | 127 | return -EINTR; |
bccacf6c | 128 | } |
532decb7 | 129 | v9fs_path_read_lock(s); |
f6b7f0ab AK |
130 | v9fs_co_run_in_worker( |
131 | { | |
cc720ddb AK |
132 | err = s->ops->opendir(&s->ctx, &fidp->path, &fidp->fs); |
133 | if (err < 0) { | |
f6b7f0ab AK |
134 | err = -errno; |
135 | } else { | |
136 | err = 0; | |
137 | } | |
138 | }); | |
532decb7 | 139 | v9fs_path_unlock(s); |
95f65511 AK |
140 | if (!err) { |
141 | total_open_fd++; | |
142 | if (total_open_fd > open_fd_hw) { | |
bccacf6c | 143 | v9fs_reclaim_fd(pdu); |
95f65511 AK |
144 | } |
145 | } | |
f6b7f0ab AK |
146 | return err; |
147 | } | |
bed4352c | 148 | |
cc720ddb | 149 | int v9fs_co_closedir(V9fsPDU *pdu, V9fsFidOpenState *fs) |
bed4352c AK |
150 | { |
151 | int err; | |
bccacf6c | 152 | V9fsState *s = pdu->s; |
bed4352c | 153 | |
bccacf6c | 154 | if (v9fs_request_cancelled(pdu)) { |
3a93113a | 155 | return -EINTR; |
bccacf6c | 156 | } |
bed4352c AK |
157 | v9fs_co_run_in_worker( |
158 | { | |
cc720ddb | 159 | err = s->ops->closedir(&s->ctx, fs); |
bed4352c AK |
160 | if (err < 0) { |
161 | err = -errno; | |
162 | } | |
163 | }); | |
95f65511 AK |
164 | if (!err) { |
165 | total_open_fd--; | |
166 | } | |
bed4352c AK |
167 | return err; |
168 | } |