Aneesh Kumar K.V | dcb9dbe | 2011-05-18 15:42:42 -0700 | [diff] [blame] | 1 | /* |
Greg Kurz | af8b38b | 2016-06-06 11:52:34 +0200 | [diff] [blame] | 2 | * 9p backend |
Aneesh Kumar K.V | dcb9dbe | 2011-05-18 15:42:42 -0700 | [diff] [blame] | 3 | * |
| 4 | * Copyright IBM, Corp. 2011 |
| 5 | * |
| 6 | * Authors: |
| 7 | * Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> |
| 8 | * |
| 9 | * This work is licensed under the terms of the GNU GPL, version 2. See |
| 10 | * the COPYING file in the top-level directory. |
| 11 | * |
| 12 | */ |
| 13 | |
Christian Schoenebeck | 6f56908 | 2021-05-06 15:12:23 +0200 | [diff] [blame] | 14 | /* |
| 15 | * Not so fast! You might want to read the 9p developer docs first: |
| 16 | * https://wiki.qemu.org/Documentation/9p |
| 17 | */ |
| 18 | |
Peter Maydell | fbc0412 | 2016-01-26 18:17:10 +0000 | [diff] [blame] | 19 | #include "qemu/osdep.h" |
Aneesh Kumar K.V | dcb9dbe | 2011-05-18 15:42:42 -0700 | [diff] [blame] | 20 | #include "fsdev/qemu-fsdev.h" |
Paolo Bonzini | 1de7afc | 2012-12-17 18:20:00 +0100 | [diff] [blame] | 21 | #include "qemu/thread.h" |
Markus Armbruster | db72581 | 2019-08-12 07:23:50 +0200 | [diff] [blame] | 22 | #include "qemu/main-loop.h" |
Wei Liu | fe52840 | 2015-11-18 17:57:30 +0000 | [diff] [blame] | 23 | #include "coth.h" |
Keno Fischer | 6b3b279 | 2022-02-27 17:35:15 -0500 | [diff] [blame] | 24 | #include "9p-xattr.h" |
| 25 | #include "9p-util.h" |
Aneesh Kumar K.V | dcb9dbe | 2011-05-18 15:42:42 -0700 | [diff] [blame] | 26 | |
Christian Schoenebeck | dd8151f | 2020-07-29 10:11:54 +0200 | [diff] [blame] | 27 | /* |
| 28 | * Intended to be called from bottom-half (e.g. background I/O thread) |
| 29 | * context. |
| 30 | */ |
| 31 | static int do_readdir(V9fsPDU *pdu, V9fsFidState *fidp, struct dirent **dent) |
| 32 | { |
| 33 | int err = 0; |
| 34 | V9fsState *s = pdu->s; |
| 35 | struct dirent *entry; |
| 36 | |
| 37 | errno = 0; |
| 38 | entry = s->ops->readdir(&s->ctx, &fidp->fs); |
| 39 | if (!entry && errno) { |
| 40 | *dent = NULL; |
| 41 | err = -errno; |
| 42 | } else { |
| 43 | *dent = entry; |
| 44 | } |
| 45 | return err; |
| 46 | } |
| 47 | |
Christian Schoenebeck | 2149675 | 2020-07-29 10:12:33 +0200 | [diff] [blame] | 48 | /* |
| 49 | * TODO: This will be removed for performance reasons. |
| 50 | * Use v9fs_co_readdir_many() instead. |
| 51 | */ |
Greg Kurz | 5bdade6 | 2016-10-17 14:13:58 +0200 | [diff] [blame] | 52 | int coroutine_fn v9fs_co_readdir(V9fsPDU *pdu, V9fsFidState *fidp, |
| 53 | struct dirent **dent) |
Aneesh Kumar K.V | dcb9dbe | 2011-05-18 15:42:42 -0700 | [diff] [blame] | 54 | { |
| 55 | int err; |
| 56 | |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 57 | if (v9fs_request_cancelled(pdu)) { |
| 58 | return -EINTR; |
| 59 | } |
Christian Schoenebeck | dd8151f | 2020-07-29 10:11:54 +0200 | [diff] [blame] | 60 | v9fs_co_run_in_worker({ |
| 61 | err = do_readdir(pdu, fidp, dent); |
| 62 | }); |
Aneesh Kumar K.V | dcb9dbe | 2011-05-18 15:42:42 -0700 | [diff] [blame] | 63 | return err; |
| 64 | } |
| 65 | |
Christian Schoenebeck | 2149675 | 2020-07-29 10:12:33 +0200 | [diff] [blame] | 66 | /* |
| 67 | * This is solely executed on a background IO thread. |
| 68 | * |
| 69 | * See v9fs_co_readdir_many() (as its only user) below for details. |
| 70 | */ |
Paolo Bonzini | c3b21fb | 2023-03-09 09:44:52 +0100 | [diff] [blame] | 71 | static int coroutine_fn |
| 72 | do_readdir_many(V9fsPDU *pdu, V9fsFidState *fidp, struct V9fsDirEnt **entries, |
| 73 | off_t offset, int32_t maxsize, bool dostat) |
Christian Schoenebeck | 2149675 | 2020-07-29 10:12:33 +0200 | [diff] [blame] | 74 | { |
| 75 | V9fsState *s = pdu->s; |
| 76 | V9fsString name; |
| 77 | int len, err = 0; |
| 78 | int32_t size = 0; |
| 79 | off_t saved_dir_pos; |
| 80 | struct dirent *dent; |
| 81 | struct V9fsDirEnt *e = NULL; |
| 82 | V9fsPath path; |
| 83 | struct stat stbuf; |
| 84 | |
| 85 | *entries = NULL; |
| 86 | v9fs_path_init(&path); |
| 87 | |
| 88 | /* |
| 89 | * TODO: Here should be a warn_report_once() if lock failed. |
| 90 | * |
| 91 | * With a good 9p client we should not get into concurrency here, |
| 92 | * because a good client would not use the same fid for concurrent |
| 93 | * requests. We do the lock here for safety reasons though. However |
| 94 | * the client would then suffer performance issues, so better log that |
| 95 | * issue here. |
| 96 | */ |
| 97 | v9fs_readdir_lock(&fidp->fs.dir); |
| 98 | |
| 99 | /* seek directory to requested initial position */ |
| 100 | if (offset == 0) { |
| 101 | s->ops->rewinddir(&s->ctx, &fidp->fs); |
| 102 | } else { |
| 103 | s->ops->seekdir(&s->ctx, &fidp->fs, offset); |
| 104 | } |
| 105 | |
| 106 | /* save the directory position */ |
| 107 | saved_dir_pos = s->ops->telldir(&s->ctx, &fidp->fs); |
| 108 | if (saved_dir_pos < 0) { |
| 109 | err = saved_dir_pos; |
| 110 | goto out; |
| 111 | } |
| 112 | |
| 113 | while (true) { |
| 114 | /* interrupt loop if request was cancelled by a Tflush request */ |
| 115 | if (v9fs_request_cancelled(pdu)) { |
| 116 | err = -EINTR; |
| 117 | break; |
| 118 | } |
| 119 | |
| 120 | /* get directory entry from fs driver */ |
| 121 | err = do_readdir(pdu, fidp, &dent); |
| 122 | if (err || !dent) { |
| 123 | break; |
| 124 | } |
| 125 | |
| 126 | /* |
| 127 | * stop this loop as soon as it would exceed the allowed maximum |
| 128 | * response message size for the directory entries collected so far, |
| 129 | * because anything beyond that size would need to be discarded by |
| 130 | * 9p controller (main thread / top half) anyway |
| 131 | */ |
| 132 | v9fs_string_init(&name); |
| 133 | v9fs_string_sprintf(&name, "%s", dent->d_name); |
| 134 | len = v9fs_readdir_response_size(&name); |
| 135 | v9fs_string_free(&name); |
| 136 | if (size + len > maxsize) { |
| 137 | /* this is not an error case actually */ |
| 138 | break; |
| 139 | } |
| 140 | |
| 141 | /* append next node to result chain */ |
| 142 | if (!e) { |
Markus Armbruster | 1366244 | 2022-03-15 15:41:55 +0100 | [diff] [blame] | 143 | *entries = e = g_new0(V9fsDirEnt, 1); |
Christian Schoenebeck | 2149675 | 2020-07-29 10:12:33 +0200 | [diff] [blame] | 144 | } else { |
Markus Armbruster | 1366244 | 2022-03-15 15:41:55 +0100 | [diff] [blame] | 145 | e = e->next = g_new0(V9fsDirEnt, 1); |
Christian Schoenebeck | 2149675 | 2020-07-29 10:12:33 +0200 | [diff] [blame] | 146 | } |
Vitaly Chikunov | e64e27d | 2022-02-16 21:18:21 +0300 | [diff] [blame] | 147 | e->dent = qemu_dirent_dup(dent); |
Christian Schoenebeck | 2149675 | 2020-07-29 10:12:33 +0200 | [diff] [blame] | 148 | |
| 149 | /* perform a full stat() for directory entry if requested by caller */ |
| 150 | if (dostat) { |
| 151 | err = s->ops->name_to_path( |
| 152 | &s->ctx, &fidp->path, dent->d_name, &path |
| 153 | ); |
| 154 | if (err < 0) { |
| 155 | err = -errno; |
| 156 | break; |
| 157 | } |
| 158 | |
| 159 | err = s->ops->lstat(&s->ctx, &path, &stbuf); |
| 160 | if (err < 0) { |
| 161 | err = -errno; |
| 162 | break; |
| 163 | } |
| 164 | |
Markus Armbruster | 1366244 | 2022-03-15 15:41:55 +0100 | [diff] [blame] | 165 | e->st = g_new0(struct stat, 1); |
Christian Schoenebeck | 2149675 | 2020-07-29 10:12:33 +0200 | [diff] [blame] | 166 | memcpy(e->st, &stbuf, sizeof(struct stat)); |
| 167 | } |
| 168 | |
| 169 | size += len; |
Keno Fischer | 6b3b279 | 2022-02-27 17:35:15 -0500 | [diff] [blame] | 170 | saved_dir_pos = qemu_dirent_off(dent); |
Christian Schoenebeck | 2149675 | 2020-07-29 10:12:33 +0200 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | /* restore (last) saved position */ |
| 174 | s->ops->seekdir(&s->ctx, &fidp->fs, saved_dir_pos); |
| 175 | |
| 176 | out: |
| 177 | v9fs_readdir_unlock(&fidp->fs.dir); |
| 178 | v9fs_path_free(&path); |
| 179 | if (err < 0) { |
| 180 | return err; |
| 181 | } |
| 182 | return size; |
| 183 | } |
| 184 | |
| 185 | /** |
Christian Schoenebeck | 1a7f240 | 2022-03-03 13:52:14 +0100 | [diff] [blame] | 186 | * v9fs_co_readdir_many() - Reads multiple directory entries in one rush. |
| 187 | * |
| 188 | * @pdu: the causing 9p (T_readdir) client request |
| 189 | * @fidp: already opened directory where readdir shall be performed on |
| 190 | * @entries: output for directory entries (must not be NULL) |
| 191 | * @offset: initial position inside the directory the function shall |
| 192 | * seek to before retrieving the directory entries |
| 193 | * @maxsize: maximum result message body size (in bytes) |
| 194 | * @dostat: whether a stat() should be performed and returned for |
| 195 | * each directory entry |
| 196 | * Return: resulting response message body size (in bytes) on success, |
| 197 | * negative error code otherwise |
Christian Schoenebeck | 2149675 | 2020-07-29 10:12:33 +0200 | [diff] [blame] | 198 | * |
| 199 | * Retrieves the requested (max. amount of) directory entries from the fs |
| 200 | * driver. This function must only be called by the main IO thread (top half). |
| 201 | * Internally this function call will be dispatched to a background IO thread |
| 202 | * (bottom half) where it is eventually executed by the fs driver. |
| 203 | * |
Christian Schoenebeck | 1a7f240 | 2022-03-03 13:52:14 +0100 | [diff] [blame] | 204 | * Acquiring multiple directory entries in one rush from the fs |
Christian Schoenebeck | 2149675 | 2020-07-29 10:12:33 +0200 | [diff] [blame] | 205 | * driver, instead of retrieving each directory entry individually, is very |
| 206 | * beneficial from performance point of view. Because for every fs driver |
| 207 | * request latency is added, which in practice could lead to overall |
| 208 | * latencies of several hundred ms for reading all entries (of just a single |
| 209 | * directory) if every directory entry was individually requested from fs |
| 210 | * driver. |
| 211 | * |
Christian Schoenebeck | 1a7f240 | 2022-03-03 13:52:14 +0100 | [diff] [blame] | 212 | * NOTE: You must ALWAYS call v9fs_free_dirents(entries) after calling |
Christian Schoenebeck | 2149675 | 2020-07-29 10:12:33 +0200 | [diff] [blame] | 213 | * v9fs_co_readdir_many(), both on success and on error cases of this |
Christian Schoenebeck | 1a7f240 | 2022-03-03 13:52:14 +0100 | [diff] [blame] | 214 | * function, to avoid memory leaks once @entries are no longer needed. |
Christian Schoenebeck | 2149675 | 2020-07-29 10:12:33 +0200 | [diff] [blame] | 215 | */ |
| 216 | int coroutine_fn v9fs_co_readdir_many(V9fsPDU *pdu, V9fsFidState *fidp, |
| 217 | struct V9fsDirEnt **entries, |
| 218 | off_t offset, int32_t maxsize, |
| 219 | bool dostat) |
| 220 | { |
| 221 | int err = 0; |
| 222 | |
| 223 | if (v9fs_request_cancelled(pdu)) { |
| 224 | return -EINTR; |
| 225 | } |
| 226 | v9fs_co_run_in_worker({ |
| 227 | err = do_readdir_many(pdu, fidp, entries, offset, maxsize, dostat); |
| 228 | }); |
| 229 | return err; |
| 230 | } |
| 231 | |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 232 | off_t v9fs_co_telldir(V9fsPDU *pdu, V9fsFidState *fidp) |
Aneesh Kumar K.V | dcb9dbe | 2011-05-18 15:42:42 -0700 | [diff] [blame] | 233 | { |
| 234 | off_t err; |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 235 | V9fsState *s = pdu->s; |
Aneesh Kumar K.V | dcb9dbe | 2011-05-18 15:42:42 -0700 | [diff] [blame] | 236 | |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 237 | if (v9fs_request_cancelled(pdu)) { |
| 238 | return -EINTR; |
| 239 | } |
Aneesh Kumar K.V | dcb9dbe | 2011-05-18 15:42:42 -0700 | [diff] [blame] | 240 | v9fs_co_run_in_worker( |
| 241 | { |
Aneesh Kumar K.V | cc720dd | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 242 | err = s->ops->telldir(&s->ctx, &fidp->fs); |
Aneesh Kumar K.V | dcb9dbe | 2011-05-18 15:42:42 -0700 | [diff] [blame] | 243 | if (err < 0) { |
| 244 | err = -errno; |
| 245 | } |
| 246 | }); |
| 247 | return err; |
| 248 | } |
| 249 | |
Greg Kurz | 5bdade6 | 2016-10-17 14:13:58 +0200 | [diff] [blame] | 250 | void coroutine_fn v9fs_co_seekdir(V9fsPDU *pdu, V9fsFidState *fidp, |
| 251 | off_t offset) |
Aneesh Kumar K.V | dcb9dbe | 2011-05-18 15:42:42 -0700 | [diff] [blame] | 252 | { |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 253 | V9fsState *s = pdu->s; |
| 254 | if (v9fs_request_cancelled(pdu)) { |
| 255 | return; |
| 256 | } |
Aneesh Kumar K.V | dcb9dbe | 2011-05-18 15:42:42 -0700 | [diff] [blame] | 257 | v9fs_co_run_in_worker( |
| 258 | { |
Aneesh Kumar K.V | cc720dd | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 259 | s->ops->seekdir(&s->ctx, &fidp->fs, offset); |
Aneesh Kumar K.V | dcb9dbe | 2011-05-18 15:42:42 -0700 | [diff] [blame] | 260 | }); |
| 261 | } |
| 262 | |
Greg Kurz | 5bdade6 | 2016-10-17 14:13:58 +0200 | [diff] [blame] | 263 | void coroutine_fn v9fs_co_rewinddir(V9fsPDU *pdu, V9fsFidState *fidp) |
Aneesh Kumar K.V | dcb9dbe | 2011-05-18 15:42:42 -0700 | [diff] [blame] | 264 | { |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 265 | V9fsState *s = pdu->s; |
| 266 | if (v9fs_request_cancelled(pdu)) { |
| 267 | return; |
| 268 | } |
Aneesh Kumar K.V | dcb9dbe | 2011-05-18 15:42:42 -0700 | [diff] [blame] | 269 | v9fs_co_run_in_worker( |
| 270 | { |
Aneesh Kumar K.V | cc720dd | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 271 | s->ops->rewinddir(&s->ctx, &fidp->fs); |
Aneesh Kumar K.V | dcb9dbe | 2011-05-18 15:42:42 -0700 | [diff] [blame] | 272 | }); |
| 273 | } |
Venkateswararao Jujjuri | d088464 | 2011-08-08 23:44:24 +0530 | [diff] [blame] | 274 | |
Greg Kurz | 5bdade6 | 2016-10-17 14:13:58 +0200 | [diff] [blame] | 275 | int coroutine_fn v9fs_co_mkdir(V9fsPDU *pdu, V9fsFidState *fidp, |
| 276 | V9fsString *name, mode_t mode, uid_t uid, |
| 277 | gid_t gid, struct stat *stbuf) |
Venkateswararao Jujjuri | d088464 | 2011-08-08 23:44:24 +0530 | [diff] [blame] | 278 | { |
| 279 | int err; |
| 280 | FsCred cred; |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 281 | V9fsPath path; |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 282 | V9fsState *s = pdu->s; |
Venkateswararao Jujjuri | d088464 | 2011-08-08 23:44:24 +0530 | [diff] [blame] | 283 | |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 284 | if (v9fs_request_cancelled(pdu)) { |
Dong Xu Wang | 3a93113 | 2011-11-29 16:52:38 +0800 | [diff] [blame] | 285 | return -EINTR; |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 286 | } |
Venkateswararao Jujjuri | d088464 | 2011-08-08 23:44:24 +0530 | [diff] [blame] | 287 | cred_init(&cred); |
| 288 | cred.fc_mode = mode; |
| 289 | cred.fc_uid = uid; |
| 290 | cred.fc_gid = gid; |
Aneesh Kumar K.V | 532decb | 2011-08-02 11:35:54 +0530 | [diff] [blame] | 291 | v9fs_path_read_lock(s); |
Venkateswararao Jujjuri | d088464 | 2011-08-08 23:44:24 +0530 | [diff] [blame] | 292 | v9fs_co_run_in_worker( |
| 293 | { |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 294 | err = s->ops->mkdir(&s->ctx, &fidp->path, name->data, &cred); |
Venkateswararao Jujjuri | d088464 | 2011-08-08 23:44:24 +0530 | [diff] [blame] | 295 | if (err < 0) { |
| 296 | err = -errno; |
Aneesh Kumar K.V | 02cb7f3 | 2011-05-24 15:10:56 +0530 | [diff] [blame] | 297 | } else { |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 298 | v9fs_path_init(&path); |
| 299 | err = v9fs_name_to_path(s, &fidp->path, name->data, &path); |
| 300 | if (!err) { |
| 301 | err = s->ops->lstat(&s->ctx, &path, stbuf); |
| 302 | if (err < 0) { |
| 303 | err = -errno; |
| 304 | } |
Aneesh Kumar K.V | 02cb7f3 | 2011-05-24 15:10:56 +0530 | [diff] [blame] | 305 | } |
Aneesh Kumar K.V | 2289be1 | 2011-09-09 15:14:18 +0530 | [diff] [blame] | 306 | v9fs_path_free(&path); |
Venkateswararao Jujjuri | d088464 | 2011-08-08 23:44:24 +0530 | [diff] [blame] | 307 | } |
| 308 | }); |
Aneesh Kumar K.V | 532decb | 2011-08-02 11:35:54 +0530 | [diff] [blame] | 309 | v9fs_path_unlock(s); |
Venkateswararao Jujjuri | d088464 | 2011-08-08 23:44:24 +0530 | [diff] [blame] | 310 | return err; |
| 311 | } |
Aneesh Kumar K.V | f6b7f0a | 2011-05-07 18:12:42 +0530 | [diff] [blame] | 312 | |
Greg Kurz | 5bdade6 | 2016-10-17 14:13:58 +0200 | [diff] [blame] | 313 | int coroutine_fn v9fs_co_opendir(V9fsPDU *pdu, V9fsFidState *fidp) |
Aneesh Kumar K.V | f6b7f0a | 2011-05-07 18:12:42 +0530 | [diff] [blame] | 314 | { |
| 315 | int err; |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 316 | V9fsState *s = pdu->s; |
Aneesh Kumar K.V | f6b7f0a | 2011-05-07 18:12:42 +0530 | [diff] [blame] | 317 | |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 318 | if (v9fs_request_cancelled(pdu)) { |
Dong Xu Wang | 3a93113 | 2011-11-29 16:52:38 +0800 | [diff] [blame] | 319 | return -EINTR; |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 320 | } |
Aneesh Kumar K.V | 532decb | 2011-08-02 11:35:54 +0530 | [diff] [blame] | 321 | v9fs_path_read_lock(s); |
Aneesh Kumar K.V | f6b7f0a | 2011-05-07 18:12:42 +0530 | [diff] [blame] | 322 | v9fs_co_run_in_worker( |
| 323 | { |
Aneesh Kumar K.V | cc720dd | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 324 | err = s->ops->opendir(&s->ctx, &fidp->path, &fidp->fs); |
| 325 | if (err < 0) { |
Aneesh Kumar K.V | f6b7f0a | 2011-05-07 18:12:42 +0530 | [diff] [blame] | 326 | err = -errno; |
| 327 | } else { |
| 328 | err = 0; |
| 329 | } |
| 330 | }); |
Aneesh Kumar K.V | 532decb | 2011-08-02 11:35:54 +0530 | [diff] [blame] | 331 | v9fs_path_unlock(s); |
Aneesh Kumar K.V | 95f6551 | 2011-05-18 17:08:34 +0530 | [diff] [blame] | 332 | if (!err) { |
| 333 | total_open_fd++; |
| 334 | if (total_open_fd > open_fd_hw) { |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 335 | v9fs_reclaim_fd(pdu); |
Aneesh Kumar K.V | 95f6551 | 2011-05-18 17:08:34 +0530 | [diff] [blame] | 336 | } |
| 337 | } |
Aneesh Kumar K.V | f6b7f0a | 2011-05-07 18:12:42 +0530 | [diff] [blame] | 338 | return err; |
| 339 | } |
Aneesh Kumar K.V | bed4352 | 2011-05-07 21:09:24 +0530 | [diff] [blame] | 340 | |
Greg Kurz | 5bdade6 | 2016-10-17 14:13:58 +0200 | [diff] [blame] | 341 | int coroutine_fn v9fs_co_closedir(V9fsPDU *pdu, V9fsFidOpenState *fs) |
Aneesh Kumar K.V | bed4352 | 2011-05-07 21:09:24 +0530 | [diff] [blame] | 342 | { |
| 343 | int err; |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 344 | V9fsState *s = pdu->s; |
Aneesh Kumar K.V | bed4352 | 2011-05-07 21:09:24 +0530 | [diff] [blame] | 345 | |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 346 | if (v9fs_request_cancelled(pdu)) { |
Dong Xu Wang | 3a93113 | 2011-11-29 16:52:38 +0800 | [diff] [blame] | 347 | return -EINTR; |
Aneesh Kumar K.V | bccacf6 | 2011-08-02 11:36:17 +0530 | [diff] [blame] | 348 | } |
Aneesh Kumar K.V | bed4352 | 2011-05-07 21:09:24 +0530 | [diff] [blame] | 349 | v9fs_co_run_in_worker( |
| 350 | { |
Aneesh Kumar K.V | cc720dd | 2011-10-25 12:10:40 +0530 | [diff] [blame] | 351 | err = s->ops->closedir(&s->ctx, fs); |
Aneesh Kumar K.V | bed4352 | 2011-05-07 21:09:24 +0530 | [diff] [blame] | 352 | if (err < 0) { |
| 353 | err = -errno; |
| 354 | } |
| 355 | }); |
Aneesh Kumar K.V | 95f6551 | 2011-05-18 17:08:34 +0530 | [diff] [blame] | 356 | if (!err) { |
| 357 | total_open_fd--; |
| 358 | } |
Aneesh Kumar K.V | bed4352 | 2011-05-07 21:09:24 +0530 | [diff] [blame] | 359 | return err; |
| 360 | } |