xref: /openbmc/qemu/hw/9pfs/9p.h (revision cf45183b718f02b1369e18c795dc51bc1821245d)
12a6a4076SMarkus Armbruster #ifndef QEMU_9P_H
22a6a4076SMarkus Armbruster #define QEMU_9P_H
3ebe74f8bSWei Liu 
4ebe74f8bSWei Liu #include <dirent.h>
5ebe74f8bSWei Liu #include <utime.h>
6ebe74f8bSWei Liu #include <sys/resource.h>
7ebe74f8bSWei Liu #include "fsdev/file-op-9p.h"
8ebe74f8bSWei Liu #include "fsdev/9p-iov-marshal.h"
9ebe74f8bSWei Liu #include "qemu/thread.h"
10ebe74f8bSWei Liu #include "qemu/coroutine.h"
111a6ed33cSAntonios Motakis #include "qemu/qht.h"
12ebe74f8bSWei Liu 
13ebe74f8bSWei Liu enum {
14ebe74f8bSWei Liu     P9_TLERROR = 6,
15ebe74f8bSWei Liu     P9_RLERROR,
16ebe74f8bSWei Liu     P9_TSTATFS = 8,
17ebe74f8bSWei Liu     P9_RSTATFS,
18ebe74f8bSWei Liu     P9_TLOPEN = 12,
19ebe74f8bSWei Liu     P9_RLOPEN,
20ebe74f8bSWei Liu     P9_TLCREATE = 14,
21ebe74f8bSWei Liu     P9_RLCREATE,
22ebe74f8bSWei Liu     P9_TSYMLINK = 16,
23ebe74f8bSWei Liu     P9_RSYMLINK,
24ebe74f8bSWei Liu     P9_TMKNOD = 18,
25ebe74f8bSWei Liu     P9_RMKNOD,
26ebe74f8bSWei Liu     P9_TRENAME = 20,
27ebe74f8bSWei Liu     P9_RRENAME,
28ebe74f8bSWei Liu     P9_TREADLINK = 22,
29ebe74f8bSWei Liu     P9_RREADLINK,
30ebe74f8bSWei Liu     P9_TGETATTR = 24,
31ebe74f8bSWei Liu     P9_RGETATTR,
32ebe74f8bSWei Liu     P9_TSETATTR = 26,
33ebe74f8bSWei Liu     P9_RSETATTR,
34ebe74f8bSWei Liu     P9_TXATTRWALK = 30,
35ebe74f8bSWei Liu     P9_RXATTRWALK,
36ebe74f8bSWei Liu     P9_TXATTRCREATE = 32,
37ebe74f8bSWei Liu     P9_RXATTRCREATE,
38ebe74f8bSWei Liu     P9_TREADDIR = 40,
39ebe74f8bSWei Liu     P9_RREADDIR,
40ebe74f8bSWei Liu     P9_TFSYNC = 50,
41ebe74f8bSWei Liu     P9_RFSYNC,
42ebe74f8bSWei Liu     P9_TLOCK = 52,
43ebe74f8bSWei Liu     P9_RLOCK,
44ebe74f8bSWei Liu     P9_TGETLOCK = 54,
45ebe74f8bSWei Liu     P9_RGETLOCK,
46ebe74f8bSWei Liu     P9_TLINK = 70,
47ebe74f8bSWei Liu     P9_RLINK,
48ebe74f8bSWei Liu     P9_TMKDIR = 72,
49ebe74f8bSWei Liu     P9_RMKDIR,
50ebe74f8bSWei Liu     P9_TRENAMEAT = 74,
51ebe74f8bSWei Liu     P9_RRENAMEAT,
52ebe74f8bSWei Liu     P9_TUNLINKAT = 76,
53ebe74f8bSWei Liu     P9_RUNLINKAT,
54ebe74f8bSWei Liu     P9_TVERSION = 100,
55ebe74f8bSWei Liu     P9_RVERSION,
56ebe74f8bSWei Liu     P9_TAUTH = 102,
57ebe74f8bSWei Liu     P9_RAUTH,
58ebe74f8bSWei Liu     P9_TATTACH = 104,
59ebe74f8bSWei Liu     P9_RATTACH,
60ebe74f8bSWei Liu     P9_TERROR = 106,
61ebe74f8bSWei Liu     P9_RERROR,
62ebe74f8bSWei Liu     P9_TFLUSH = 108,
63ebe74f8bSWei Liu     P9_RFLUSH,
64ebe74f8bSWei Liu     P9_TWALK = 110,
65ebe74f8bSWei Liu     P9_RWALK,
66ebe74f8bSWei Liu     P9_TOPEN = 112,
67ebe74f8bSWei Liu     P9_ROPEN,
68ebe74f8bSWei Liu     P9_TCREATE = 114,
69ebe74f8bSWei Liu     P9_RCREATE,
70ebe74f8bSWei Liu     P9_TREAD = 116,
71ebe74f8bSWei Liu     P9_RREAD,
72ebe74f8bSWei Liu     P9_TWRITE = 118,
73ebe74f8bSWei Liu     P9_RWRITE,
74ebe74f8bSWei Liu     P9_TCLUNK = 120,
75ebe74f8bSWei Liu     P9_RCLUNK,
76ebe74f8bSWei Liu     P9_TREMOVE = 122,
77ebe74f8bSWei Liu     P9_RREMOVE,
78ebe74f8bSWei Liu     P9_TSTAT = 124,
79ebe74f8bSWei Liu     P9_RSTAT,
80ebe74f8bSWei Liu     P9_TWSTAT = 126,
81ebe74f8bSWei Liu     P9_RWSTAT,
82ebe74f8bSWei Liu };
83ebe74f8bSWei Liu 
84ebe74f8bSWei Liu 
85ebe74f8bSWei Liu /* qid.types */
86ebe74f8bSWei Liu enum {
87ebe74f8bSWei Liu     P9_QTDIR = 0x80,
88ebe74f8bSWei Liu     P9_QTAPPEND = 0x40,
89ebe74f8bSWei Liu     P9_QTEXCL = 0x20,
90ebe74f8bSWei Liu     P9_QTMOUNT = 0x10,
91ebe74f8bSWei Liu     P9_QTAUTH = 0x08,
92ebe74f8bSWei Liu     P9_QTTMP = 0x04,
93ebe74f8bSWei Liu     P9_QTSYMLINK = 0x02,
94ebe74f8bSWei Liu     P9_QTLINK = 0x01,
95ebe74f8bSWei Liu     P9_QTFILE = 0x00,
96ebe74f8bSWei Liu };
97ebe74f8bSWei Liu 
988e71b96cSGreg Kurz typedef enum P9ProtoVersion {
99ebe74f8bSWei Liu     V9FS_PROTO_2000U = 0x01,
100ebe74f8bSWei Liu     V9FS_PROTO_2000L = 0x02,
1018e71b96cSGreg Kurz } P9ProtoVersion;
102ebe74f8bSWei Liu 
103e16453a3SChristian Schoenebeck /**
104e16453a3SChristian Schoenebeck  * @brief Minimum message size supported by this 9pfs server.
105e16453a3SChristian Schoenebeck  *
106e16453a3SChristian Schoenebeck  * A client establishes a session by sending a Tversion request along with a
107e16453a3SChristian Schoenebeck  * 'msize' parameter which suggests the server a maximum message size ever to be
108e16453a3SChristian Schoenebeck  * used for communication (for both requests and replies) between client and
109e16453a3SChristian Schoenebeck  * server during that session. If client suggests a 'msize' smaller than this
110e16453a3SChristian Schoenebeck  * value then session is denied by server with an error response.
111e16453a3SChristian Schoenebeck  */
112e16453a3SChristian Schoenebeck #define P9_MIN_MSIZE    4096
113e16453a3SChristian Schoenebeck 
114baecbde6SGreg Kurz #define P9_NOTAG    UINT16_MAX
115baecbde6SGreg Kurz #define P9_NOFID    UINT32_MAX
116ebe74f8bSWei Liu #define P9_MAXWELEM 16
117ebe74f8bSWei Liu 
118ebe74f8bSWei Liu #define FID_REFERENCED          0x1
119ebe74f8bSWei Liu #define FID_NON_RECLAIMABLE     0x2
120ebe74f8bSWei Liu static inline char *rpath(FsContext *ctx, const char *path)
121ebe74f8bSWei Liu {
122ebe74f8bSWei Liu     return g_strdup_printf("%s/%s", ctx->fs_root, path);
123ebe74f8bSWei Liu }
124ebe74f8bSWei Liu 
125ebe74f8bSWei Liu /*
126ebe74f8bSWei Liu  * ample room for Twrite/Rread header
127ebe74f8bSWei Liu  * size[4] Tread/Twrite tag[2] fid[4] offset[8] count[4]
128ebe74f8bSWei Liu  */
129ebe74f8bSWei Liu #define P9_IOHDRSZ 24
130ebe74f8bSWei Liu 
131ebe74f8bSWei Liu typedef struct V9fsPDU V9fsPDU;
13221cf9edfSGreg Kurz typedef struct V9fsState V9fsState;
1338e71b96cSGreg Kurz typedef struct V9fsTransport V9fsTransport;
134ebe74f8bSWei Liu 
135c9fb47e7SStefano Stabellini typedef struct {
136c9fb47e7SStefano Stabellini     uint32_t size_le;
137c9fb47e7SStefano Stabellini     uint8_t id;
138c9fb47e7SStefano Stabellini     uint16_t tag_le;
139c9fb47e7SStefano Stabellini } QEMU_PACKED P9MsgHeader;
140a4d99854SGreg Kurz /* According to the specification, 9p messages start with a 7-byte header.
141a4d99854SGreg Kurz  * Since most of the code uses this header size in literal form, we must be
142a4d99854SGreg Kurz  * sure this is indeed the case.
143a4d99854SGreg Kurz  */
144a4d99854SGreg Kurz QEMU_BUILD_BUG_ON(sizeof(P9MsgHeader) != 7);
145c9fb47e7SStefano Stabellini 
146ebe74f8bSWei Liu struct V9fsPDU
147ebe74f8bSWei Liu {
148ebe74f8bSWei Liu     uint32_t size;
149ebe74f8bSWei Liu     uint16_t tag;
150ebe74f8bSWei Liu     uint8_t id;
151ebe74f8bSWei Liu     uint8_t cancelled;
152ebe74f8bSWei Liu     CoQueue complete;
15321cf9edfSGreg Kurz     V9fsState *s;
154ebe74f8bSWei Liu     QLIST_ENTRY(V9fsPDU) next;
15500588a0aSWei Liu     uint32_t idx;
156ebe74f8bSWei Liu };
157ebe74f8bSWei Liu 
158ebe74f8bSWei Liu 
159ebe74f8bSWei Liu /* FIXME
160ebe74f8bSWei Liu  * 1) change user needs to set groups and stuff
161ebe74f8bSWei Liu  */
162ebe74f8bSWei Liu 
163ebe74f8bSWei Liu #define MAX_REQ         128
164ebe74f8bSWei Liu #define MAX_TAG_LEN     32
165ebe74f8bSWei Liu 
166ebe74f8bSWei Liu #define BUG_ON(cond) assert(!(cond))
167ebe74f8bSWei Liu 
168ebe74f8bSWei Liu typedef struct V9fsFidState V9fsFidState;
169ebe74f8bSWei Liu 
170ebe74f8bSWei Liu enum {
171ebe74f8bSWei Liu     P9_FID_NONE = 0,
172ebe74f8bSWei Liu     P9_FID_FILE,
173ebe74f8bSWei Liu     P9_FID_DIR,
174ebe74f8bSWei Liu     P9_FID_XATTR,
175ebe74f8bSWei Liu };
176ebe74f8bSWei Liu 
177ebe74f8bSWei Liu typedef struct V9fsConf
178ebe74f8bSWei Liu {
179ebe74f8bSWei Liu     /* tag name for the device */
180ebe74f8bSWei Liu     char *tag;
181ebe74f8bSWei Liu     char *fsdev_id;
182ebe74f8bSWei Liu } V9fsConf;
183ebe74f8bSWei Liu 
184aca6897fSKeno Fischer /* 9p2000.L xattr flags (matches Linux values) */
185aca6897fSKeno Fischer #define P9_XATTR_CREATE 1
186aca6897fSKeno Fischer #define P9_XATTR_REPLACE 2
187aca6897fSKeno Fischer 
188ebe74f8bSWei Liu typedef struct V9fsXattr
189ebe74f8bSWei Liu {
1908495f9adSLi Qiang     uint64_t copied_len;
1918495f9adSLi Qiang     uint64_t len;
192ebe74f8bSWei Liu     void *value;
193ebe74f8bSWei Liu     V9fsString name;
194ebe74f8bSWei Liu     int flags;
195dd28fbbcSLi Qiang     bool xattrwalk_fid;
196ebe74f8bSWei Liu } V9fsXattr;
197ebe74f8bSWei Liu 
198f314ea4eSGreg Kurz typedef struct V9fsDir {
199f314ea4eSGreg Kurz     DIR *stream;
200ed463454SGreg Kurz     CoMutex readdir_mutex;
201f314ea4eSGreg Kurz } V9fsDir;
202f314ea4eSGreg Kurz 
2037cde47d4SGreg Kurz static inline void v9fs_readdir_lock(V9fsDir *dir)
2047cde47d4SGreg Kurz {
205ed463454SGreg Kurz     qemu_co_mutex_lock(&dir->readdir_mutex);
2067cde47d4SGreg Kurz }
2077cde47d4SGreg Kurz 
2087cde47d4SGreg Kurz static inline void v9fs_readdir_unlock(V9fsDir *dir)
2097cde47d4SGreg Kurz {
210ed463454SGreg Kurz     qemu_co_mutex_unlock(&dir->readdir_mutex);
2117cde47d4SGreg Kurz }
2127cde47d4SGreg Kurz 
2137cde47d4SGreg Kurz static inline void v9fs_readdir_init(V9fsDir *dir)
2147cde47d4SGreg Kurz {
215ed463454SGreg Kurz     qemu_co_mutex_init(&dir->readdir_mutex);
2167cde47d4SGreg Kurz }
2177cde47d4SGreg Kurz 
218ebe74f8bSWei Liu /*
219ebe74f8bSWei Liu  * Filled by fs driver on open and other
220ebe74f8bSWei Liu  * calls.
221ebe74f8bSWei Liu  */
222ebe74f8bSWei Liu union V9fsFidOpenState {
223ebe74f8bSWei Liu     int fd;
224f314ea4eSGreg Kurz     V9fsDir dir;
225ebe74f8bSWei Liu     V9fsXattr xattr;
226ebe74f8bSWei Liu     /*
227ebe74f8bSWei Liu      * private pointer for fs drivers, that
228ebe74f8bSWei Liu      * have its own internal representation of
229ebe74f8bSWei Liu      * open files.
230ebe74f8bSWei Liu      */
231ebe74f8bSWei Liu     void *private;
232ebe74f8bSWei Liu };
233ebe74f8bSWei Liu 
234ebe74f8bSWei Liu struct V9fsFidState
235ebe74f8bSWei Liu {
236ebe74f8bSWei Liu     int fid_type;
237ebe74f8bSWei Liu     int32_t fid;
238ebe74f8bSWei Liu     V9fsPath path;
239ebe74f8bSWei Liu     V9fsFidOpenState fs;
240ebe74f8bSWei Liu     V9fsFidOpenState fs_reclaim;
241ebe74f8bSWei Liu     int flags;
242ebe74f8bSWei Liu     int open_flags;
243ebe74f8bSWei Liu     uid_t uid;
244ebe74f8bSWei Liu     int ref;
245ebe74f8bSWei Liu     int clunked;
246ebe74f8bSWei Liu     V9fsFidState *next;
247ebe74f8bSWei Liu     V9fsFidState *rclm_lst;
248ebe74f8bSWei Liu };
249ebe74f8bSWei Liu 
2506b6aa828SChristian Schoenebeck typedef enum AffixType_t {
2516b6aa828SChristian Schoenebeck     AffixType_Prefix,
2526b6aa828SChristian Schoenebeck     AffixType_Suffix, /* A.k.a. postfix. */
2536b6aa828SChristian Schoenebeck } AffixType_t;
2546b6aa828SChristian Schoenebeck 
2556b6aa828SChristian Schoenebeck /**
2566b6aa828SChristian Schoenebeck  * @brief Unique affix of variable length.
2576b6aa828SChristian Schoenebeck  *
2586b6aa828SChristian Schoenebeck  * An affix is (currently) either a suffix or a prefix, which is either
2596b6aa828SChristian Schoenebeck  * going to be prepended (prefix) or appended (suffix) with some other
2606b6aa828SChristian Schoenebeck  * number for the goal to generate unique numbers. Accordingly the
2616b6aa828SChristian Schoenebeck  * suffixes (or prefixes) we generate @b must all have the mathematical
2626b6aa828SChristian Schoenebeck  * property of being suffix-free (or prefix-free in case of prefixes)
2636b6aa828SChristian Schoenebeck  * so that no matter what number we concatenate the affix with, that we
2646b6aa828SChristian Schoenebeck  * always reliably get unique numbers as result after concatenation.
2656b6aa828SChristian Schoenebeck  */
2666b6aa828SChristian Schoenebeck typedef struct VariLenAffix {
2676b6aa828SChristian Schoenebeck     AffixType_t type; /* Whether this affix is a suffix or a prefix. */
2686b6aa828SChristian Schoenebeck     uint64_t value; /* Actual numerical value of this affix. */
2696b6aa828SChristian Schoenebeck     /*
2706b6aa828SChristian Schoenebeck      * Lenght of the affix, that is how many (of the lowest) bits of @c value
2716b6aa828SChristian Schoenebeck      * must be used for appending/prepending this affix to its final resulting,
2726b6aa828SChristian Schoenebeck      * unique number.
2736b6aa828SChristian Schoenebeck      */
2746b6aa828SChristian Schoenebeck     int bits;
2756b6aa828SChristian Schoenebeck } VariLenAffix;
2766b6aa828SChristian Schoenebeck 
2776b6aa828SChristian Schoenebeck /* See qid_inode_prefix_hash_bits(). */
2786b6aa828SChristian Schoenebeck typedef struct {
2796b6aa828SChristian Schoenebeck     dev_t dev; /* FS device on host. */
2806b6aa828SChristian Schoenebeck     /*
2816b6aa828SChristian Schoenebeck      * How many (high) bits of the original inode number shall be used for
2826b6aa828SChristian Schoenebeck      * hashing.
2836b6aa828SChristian Schoenebeck      */
2846b6aa828SChristian Schoenebeck     int prefix_bits;
2856b6aa828SChristian Schoenebeck } QpdEntry;
2861a6ed33cSAntonios Motakis 
2871a6ed33cSAntonios Motakis /* QID path prefix entry, see stat_to_qid */
2881a6ed33cSAntonios Motakis typedef struct {
2891a6ed33cSAntonios Motakis     dev_t dev;
2901a6ed33cSAntonios Motakis     uint16_t ino_prefix;
2916b6aa828SChristian Schoenebeck     uint32_t qp_affix_index;
2926b6aa828SChristian Schoenebeck     VariLenAffix qp_affix;
2931a6ed33cSAntonios Motakis } QppEntry;
2941a6ed33cSAntonios Motakis 
295f3fe4a2dSAntonios Motakis /* QID path full entry, as above */
296f3fe4a2dSAntonios Motakis typedef struct {
297f3fe4a2dSAntonios Motakis     dev_t dev;
298f3fe4a2dSAntonios Motakis     ino_t ino;
299f3fe4a2dSAntonios Motakis     uint64_t path;
300f3fe4a2dSAntonios Motakis } QpfEntry;
301f3fe4a2dSAntonios Motakis 
30221cf9edfSGreg Kurz struct V9fsState
303ebe74f8bSWei Liu {
304ebe74f8bSWei Liu     QLIST_HEAD(, V9fsPDU) free_list;
305ebe74f8bSWei Liu     QLIST_HEAD(, V9fsPDU) active_list;
306ebe74f8bSWei Liu     V9fsFidState *fid_list;
307ebe74f8bSWei Liu     FileOperations *ops;
308ebe74f8bSWei Liu     FsContext ctx;
309ebe74f8bSWei Liu     char *tag;
3108e71b96cSGreg Kurz     P9ProtoVersion proto_version;
311ebe74f8bSWei Liu     int32_t msize;
312583f21f8SStefano Stabellini     V9fsPDU pdus[MAX_REQ];
3138e71b96cSGreg Kurz     const V9fsTransport *transport;
314ebe74f8bSWei Liu     /*
315ebe74f8bSWei Liu      * lock ensuring atomic path update
316ebe74f8bSWei Liu      * on rename.
317ebe74f8bSWei Liu      */
318ebe74f8bSWei Liu     CoRwlock rename_lock;
319ebe74f8bSWei Liu     int32_t root_fid;
320ebe74f8bSWei Liu     Error *migration_blocker;
321ebe74f8bSWei Liu     V9fsConf fsconf;
32256f101ecSGreg Kurz     V9fsQID root_qid;
3233b5ee9e8SAntonios Motakis     dev_t dev_id;
3246b6aa828SChristian Schoenebeck     struct qht qpd_table;
3251a6ed33cSAntonios Motakis     struct qht qpp_table;
326f3fe4a2dSAntonios Motakis     struct qht qpf_table;
3276b6aa828SChristian Schoenebeck     uint64_t qp_ndevices; /* Amount of entries in qpd_table. */
3286b6aa828SChristian Schoenebeck     uint16_t qp_affix_next;
329f3fe4a2dSAntonios Motakis     uint64_t qp_fullpath_next;
33021cf9edfSGreg Kurz };
331ebe74f8bSWei Liu 
332ebe74f8bSWei Liu /* 9p2000.L open flags */
333ebe74f8bSWei Liu #define P9_DOTL_RDONLY        00000000
334ebe74f8bSWei Liu #define P9_DOTL_WRONLY        00000001
335ebe74f8bSWei Liu #define P9_DOTL_RDWR          00000002
336ebe74f8bSWei Liu #define P9_DOTL_NOACCESS      00000003
337ebe74f8bSWei Liu #define P9_DOTL_CREATE        00000100
338ebe74f8bSWei Liu #define P9_DOTL_EXCL          00000200
339ebe74f8bSWei Liu #define P9_DOTL_NOCTTY        00000400
340ebe74f8bSWei Liu #define P9_DOTL_TRUNC         00001000
341ebe74f8bSWei Liu #define P9_DOTL_APPEND        00002000
342ebe74f8bSWei Liu #define P9_DOTL_NONBLOCK      00004000
343ebe74f8bSWei Liu #define P9_DOTL_DSYNC         00010000
344ebe74f8bSWei Liu #define P9_DOTL_FASYNC        00020000
345ebe74f8bSWei Liu #define P9_DOTL_DIRECT        00040000
346ebe74f8bSWei Liu #define P9_DOTL_LARGEFILE     00100000
347ebe74f8bSWei Liu #define P9_DOTL_DIRECTORY     00200000
348ebe74f8bSWei Liu #define P9_DOTL_NOFOLLOW      00400000
349ebe74f8bSWei Liu #define P9_DOTL_NOATIME       01000000
350ebe74f8bSWei Liu #define P9_DOTL_CLOEXEC       02000000
351ebe74f8bSWei Liu #define P9_DOTL_SYNC          04000000
352ebe74f8bSWei Liu 
353ebe74f8bSWei Liu /* 9p2000.L at flags */
354ebe74f8bSWei Liu #define P9_DOTL_AT_REMOVEDIR         0x200
355ebe74f8bSWei Liu 
356ebe74f8bSWei Liu /* 9P2000.L lock type */
357ebe74f8bSWei Liu #define P9_LOCK_TYPE_RDLCK 0
358ebe74f8bSWei Liu #define P9_LOCK_TYPE_WRLCK 1
359ebe74f8bSWei Liu #define P9_LOCK_TYPE_UNLCK 2
360ebe74f8bSWei Liu 
361ebe74f8bSWei Liu #define P9_LOCK_SUCCESS 0
362ebe74f8bSWei Liu #define P9_LOCK_BLOCKED 1
363ebe74f8bSWei Liu #define P9_LOCK_ERROR 2
364ebe74f8bSWei Liu #define P9_LOCK_GRACE 3
365ebe74f8bSWei Liu 
366ebe74f8bSWei Liu #define P9_LOCK_FLAGS_BLOCK 1
367ebe74f8bSWei Liu #define P9_LOCK_FLAGS_RECLAIM 2
368ebe74f8bSWei Liu 
369ebe74f8bSWei Liu typedef struct V9fsFlock
370ebe74f8bSWei Liu {
371ebe74f8bSWei Liu     uint8_t type;
372ebe74f8bSWei Liu     uint32_t flags;
373ebe74f8bSWei Liu     uint64_t start; /* absolute offset */
374ebe74f8bSWei Liu     uint64_t length;
375ebe74f8bSWei Liu     uint32_t proc_id;
376ebe74f8bSWei Liu     V9fsString client_id;
377ebe74f8bSWei Liu } V9fsFlock;
378ebe74f8bSWei Liu 
379ebe74f8bSWei Liu typedef struct V9fsGetlock
380ebe74f8bSWei Liu {
381ebe74f8bSWei Liu     uint8_t type;
382ebe74f8bSWei Liu     uint64_t start; /* absolute offset */
383ebe74f8bSWei Liu     uint64_t length;
384ebe74f8bSWei Liu     uint32_t proc_id;
385ebe74f8bSWei Liu     V9fsString client_id;
386ebe74f8bSWei Liu } V9fsGetlock;
387ebe74f8bSWei Liu 
388ebe74f8bSWei Liu extern int open_fd_hw;
389ebe74f8bSWei Liu extern int total_open_fd;
390ebe74f8bSWei Liu 
391ebe74f8bSWei Liu static inline void v9fs_path_write_lock(V9fsState *s)
392ebe74f8bSWei Liu {
393ebe74f8bSWei Liu     if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) {
394ebe74f8bSWei Liu         qemu_co_rwlock_wrlock(&s->rename_lock);
395ebe74f8bSWei Liu     }
396ebe74f8bSWei Liu }
397ebe74f8bSWei Liu 
398ebe74f8bSWei Liu static inline void v9fs_path_read_lock(V9fsState *s)
399ebe74f8bSWei Liu {
400ebe74f8bSWei Liu     if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) {
401ebe74f8bSWei Liu         qemu_co_rwlock_rdlock(&s->rename_lock);
402ebe74f8bSWei Liu     }
403ebe74f8bSWei Liu }
404ebe74f8bSWei Liu 
405ebe74f8bSWei Liu static inline void v9fs_path_unlock(V9fsState *s)
406ebe74f8bSWei Liu {
407ebe74f8bSWei Liu     if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) {
408ebe74f8bSWei Liu         qemu_co_rwlock_unlock(&s->rename_lock);
409ebe74f8bSWei Liu     }
410ebe74f8bSWei Liu }
411ebe74f8bSWei Liu 
412ebe74f8bSWei Liu static inline uint8_t v9fs_request_cancelled(V9fsPDU *pdu)
413ebe74f8bSWei Liu {
414ebe74f8bSWei Liu     return pdu->cancelled;
415ebe74f8bSWei Liu }
416ebe74f8bSWei Liu 
4178440e22eSGreg Kurz void coroutine_fn v9fs_reclaim_fd(V9fsPDU *pdu);
418bc70a592SGreg Kurz void v9fs_path_init(V9fsPath *path);
419bc70a592SGreg Kurz void v9fs_path_free(V9fsPath *path);
420bc70a592SGreg Kurz void v9fs_path_sprintf(V9fsPath *path, const char *fmt, ...);
421e446a1ebSMarc-André Lureau void v9fs_path_copy(V9fsPath *dst, const V9fsPath *src);
422bc70a592SGreg Kurz int v9fs_name_to_path(V9fsState *s, V9fsPath *dirpath,
423ebe74f8bSWei Liu                       const char *name, V9fsPath *path);
424066eb006SGreg Kurz int v9fs_device_realize_common(V9fsState *s, const V9fsTransport *t,
425066eb006SGreg Kurz                                Error **errp);
426b69c3c21SMarkus Armbruster void v9fs_device_unrealize_common(V9fsState *s);
427ebe74f8bSWei Liu 
4284b311c5fSWei Liu V9fsPDU *pdu_alloc(V9fsState *s);
4294b311c5fSWei Liu void pdu_free(V9fsPDU *pdu);
430506f3275SGreg Kurz void pdu_submit(V9fsPDU *pdu, P9MsgHeader *hdr);
4310e44a0fdSGreg Kurz void v9fs_reset(V9fsState *s);
432ebe74f8bSWei Liu 
433ea83441cSStefano Stabellini struct V9fsTransport {
434ea83441cSStefano Stabellini     ssize_t     (*pdu_vmarshal)(V9fsPDU *pdu, size_t offset, const char *fmt,
435ea83441cSStefano Stabellini                                 va_list ap);
436ea83441cSStefano Stabellini     ssize_t     (*pdu_vunmarshal)(V9fsPDU *pdu, size_t offset, const char *fmt,
437ea83441cSStefano Stabellini                                   va_list ap);
43888da0b03SStefano Stabellini     void        (*init_in_iov_from_pdu)(V9fsPDU *pdu, struct iovec **piov,
439*cf45183bSStefano Stabellini                                         unsigned int *pniov, size_t size);
44088da0b03SStefano Stabellini     void        (*init_out_iov_from_pdu)(V9fsPDU *pdu, struct iovec **piov,
4418d37de41SGreg Kurz                                          unsigned int *pniov, size_t size);
442ea83441cSStefano Stabellini     void        (*push_and_notify)(V9fsPDU *pdu);
443ea83441cSStefano Stabellini };
444ea83441cSStefano Stabellini 
445ebe74f8bSWei Liu #endif
446