xref: /openbmc/qemu/hw/9pfs/coth.h (revision 68ba85ce)
1fe52840cSWei Liu /*
2fe52840cSWei Liu  * 9p backend
3fe52840cSWei Liu  *
4fe52840cSWei Liu  * Copyright IBM, Corp. 2010
5fe52840cSWei Liu  *
6fe52840cSWei Liu  * Authors:
7fe52840cSWei Liu  *  Harsh Prateek Bora <harsh@linux.vnet.ibm.com>
8fe52840cSWei Liu  *  Venkateswararao Jujjuri(JV) <jvrao@linux.vnet.ibm.com>
9fe52840cSWei Liu  *
10fe52840cSWei Liu  * This work is licensed under the terms of the GNU GPL, version 2.  See
11fe52840cSWei Liu  * the COPYING file in the top-level directory.
12fe52840cSWei Liu  *
13fe52840cSWei Liu  */
14fe52840cSWei Liu 
152a6a4076SMarkus Armbruster #ifndef QEMU_9P_COTH_H
162a6a4076SMarkus Armbruster #define QEMU_9P_COTH_H
17fe52840cSWei Liu 
18fe52840cSWei Liu #include "qemu/thread.h"
19*68ba85ceSMarkus Armbruster #include "qemu/coroutine-core.h"
20af8b38b0SGreg Kurz #include "9p.h"
21fe52840cSWei Liu 
2209d19d58SChristian Schoenebeck /*
23fe52840cSWei Liu  * we want to use bottom half because we want to make sure the below
24fe52840cSWei Liu  * sequence of events.
25fe52840cSWei Liu  *
26fe52840cSWei Liu  *   1. Yield the coroutine in the QEMU thread.
27fe52840cSWei Liu  *   2. Submit the coroutine to a worker thread.
28fe52840cSWei Liu  *   3. Enter the coroutine in the worker thread.
29fe52840cSWei Liu  * we cannot swap step 1 and 2, because that would imply worker thread
30fe52840cSWei Liu  * can enter coroutine while step1 is still running
31da9f2edaSChristian Schoenebeck  *
3209d19d58SChristian Schoenebeck  * PERFORMANCE CONSIDERATIONS: As a rule of thumb, keep in mind
33da9f2edaSChristian Schoenebeck  * that hopping between threads adds @b latency! So when handling a
34da9f2edaSChristian Schoenebeck  * 9pfs request, avoid calling v9fs_co_run_in_worker() too often, because
35da9f2edaSChristian Schoenebeck  * this might otherwise sum up to a significant, huge overall latency for
36da9f2edaSChristian Schoenebeck  * providing the response for just a single request. For that reason it
37da9f2edaSChristian Schoenebeck  * is highly recommended to fetch all data from fs driver with a single
38da9f2edaSChristian Schoenebeck  * fs driver request on a background I/O thread (bottom half) in one rush
39da9f2edaSChristian Schoenebeck  * first and then eventually assembling the final response from that data
40da9f2edaSChristian Schoenebeck  * on main I/O thread (top half).
41fe52840cSWei Liu  */
42fe52840cSWei Liu #define v9fs_co_run_in_worker(code_block)                               \
43fe52840cSWei Liu     do {                                                                \
44fe52840cSWei Liu         QEMUBH *co_bh;                                                  \
45fe52840cSWei Liu         co_bh = qemu_bh_new(co_run_in_worker_bh,                        \
46fe52840cSWei Liu                             qemu_coroutine_self());                     \
47fe52840cSWei Liu         qemu_bh_schedule(co_bh);                                        \
48fe52840cSWei Liu         /*                                                              \
49fe52840cSWei Liu          * yield in qemu thread and re-enter back                       \
50fe52840cSWei Liu          * in worker thread                                             \
51fe52840cSWei Liu          */                                                             \
52fe52840cSWei Liu         qemu_coroutine_yield();                                         \
53fe52840cSWei Liu         qemu_bh_delete(co_bh);                                          \
54f83df009SChristian Schoenebeck         do {                                                            \
55fe52840cSWei Liu             code_block;                                                 \
56f83df009SChristian Schoenebeck         } while (0);                                                    \
57fe52840cSWei Liu         /* re-enter back to qemu thread */                              \
58fe52840cSWei Liu         qemu_coroutine_yield();                                         \
59fe52840cSWei Liu     } while (0)
60fe52840cSWei Liu 
61bc70a592SGreg Kurz void co_run_in_worker_bh(void *);
625bdade66SGreg Kurz int coroutine_fn v9fs_co_readlink(V9fsPDU *, V9fsPath *, V9fsString *);
635bdade66SGreg Kurz int coroutine_fn v9fs_co_readdir(V9fsPDU *, V9fsFidState *, struct dirent **);
642149675bSChristian Schoenebeck int coroutine_fn v9fs_co_readdir_many(V9fsPDU *, V9fsFidState *,
652149675bSChristian Schoenebeck                                       struct V9fsDirEnt **, off_t, int32_t,
662149675bSChristian Schoenebeck                                       bool);
675bdade66SGreg Kurz off_t coroutine_fn v9fs_co_telldir(V9fsPDU *, V9fsFidState *);
685bdade66SGreg Kurz void coroutine_fn v9fs_co_seekdir(V9fsPDU *, V9fsFidState *, off_t);
695bdade66SGreg Kurz void coroutine_fn v9fs_co_rewinddir(V9fsPDU *, V9fsFidState *);
705bdade66SGreg Kurz int coroutine_fn v9fs_co_statfs(V9fsPDU *, V9fsPath *, struct statfs *);
715bdade66SGreg Kurz int coroutine_fn v9fs_co_lstat(V9fsPDU *, V9fsPath *, struct stat *);
725bdade66SGreg Kurz int coroutine_fn v9fs_co_chmod(V9fsPDU *, V9fsPath *, mode_t);
735bdade66SGreg Kurz int coroutine_fn v9fs_co_utimensat(V9fsPDU *, V9fsPath *, struct timespec [2]);
745bdade66SGreg Kurz int coroutine_fn v9fs_co_chown(V9fsPDU *, V9fsPath *, uid_t, gid_t);
755bdade66SGreg Kurz int coroutine_fn v9fs_co_truncate(V9fsPDU *, V9fsPath *, off_t);
765bdade66SGreg Kurz int coroutine_fn v9fs_co_llistxattr(V9fsPDU *, V9fsPath *, void *, size_t);
775bdade66SGreg Kurz int coroutine_fn v9fs_co_lgetxattr(V9fsPDU *, V9fsPath *,
78fe52840cSWei Liu                                    V9fsString *, void *, size_t);
795bdade66SGreg Kurz int coroutine_fn v9fs_co_mknod(V9fsPDU *, V9fsFidState *, V9fsString *, uid_t,
80fe52840cSWei Liu                                gid_t, dev_t, mode_t, struct stat *);
815bdade66SGreg Kurz int coroutine_fn v9fs_co_mkdir(V9fsPDU *, V9fsFidState *, V9fsString *,
82fe52840cSWei Liu                                mode_t, uid_t, gid_t, struct stat *);
835bdade66SGreg Kurz int coroutine_fn v9fs_co_remove(V9fsPDU *, V9fsPath *);
845bdade66SGreg Kurz int coroutine_fn v9fs_co_rename(V9fsPDU *, V9fsPath *, V9fsPath *);
855bdade66SGreg Kurz int coroutine_fn v9fs_co_unlinkat(V9fsPDU *, V9fsPath *, V9fsString *,
865bdade66SGreg Kurz                                   int flags);
875bdade66SGreg Kurz int coroutine_fn v9fs_co_renameat(V9fsPDU *, V9fsPath *, V9fsString *,
88fe52840cSWei Liu                                   V9fsPath *, V9fsString *);
895bdade66SGreg Kurz int coroutine_fn v9fs_co_fstat(V9fsPDU *, V9fsFidState *, struct stat *);
905bdade66SGreg Kurz int coroutine_fn v9fs_co_opendir(V9fsPDU *, V9fsFidState *);
915bdade66SGreg Kurz int coroutine_fn v9fs_co_open(V9fsPDU *, V9fsFidState *, int);
925bdade66SGreg Kurz int coroutine_fn v9fs_co_open2(V9fsPDU *, V9fsFidState *, V9fsString *,
93fe52840cSWei Liu                                gid_t, int, int, struct stat *);
945bdade66SGreg Kurz int coroutine_fn v9fs_co_lsetxattr(V9fsPDU *, V9fsPath *, V9fsString *,
95fe52840cSWei Liu                                    void *, size_t, int);
965bdade66SGreg Kurz int coroutine_fn v9fs_co_lremovexattr(V9fsPDU *, V9fsPath *, V9fsString *);
975bdade66SGreg Kurz int coroutine_fn v9fs_co_closedir(V9fsPDU *, V9fsFidOpenState *);
985bdade66SGreg Kurz int coroutine_fn v9fs_co_close(V9fsPDU *, V9fsFidOpenState *);
995bdade66SGreg Kurz int coroutine_fn v9fs_co_fsync(V9fsPDU *, V9fsFidState *, int);
1005bdade66SGreg Kurz int coroutine_fn v9fs_co_symlink(V9fsPDU *, V9fsFidState *, V9fsString *,
101fe52840cSWei Liu                                  const char *, gid_t, struct stat *);
1025bdade66SGreg Kurz int coroutine_fn v9fs_co_link(V9fsPDU *, V9fsFidState *,
103fe52840cSWei Liu                               V9fsFidState *, V9fsString *);
1045bdade66SGreg Kurz int coroutine_fn v9fs_co_pwritev(V9fsPDU *, V9fsFidState *,
105fe52840cSWei Liu                                  struct iovec *, int, int64_t);
1065bdade66SGreg Kurz int coroutine_fn v9fs_co_preadv(V9fsPDU *, V9fsFidState *,
107fe52840cSWei Liu                                 struct iovec *, int, int64_t);
1085bdade66SGreg Kurz int coroutine_fn v9fs_co_name_to_path(V9fsPDU *, V9fsPath *,
109fe52840cSWei Liu                                       const char *, V9fsPath *);
1105bdade66SGreg Kurz int coroutine_fn v9fs_co_st_gen(V9fsPDU *pdu, V9fsPath *path, mode_t,
111fe52840cSWei Liu                                 V9fsStatDotl *v9stat);
112fe52840cSWei Liu 
113fe52840cSWei Liu #endif
114