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 146487729e9SXinhao Zhang struct V9fsPDU { 147ebe74f8bSWei Liu uint32_t size; 148ebe74f8bSWei Liu uint16_t tag; 149ebe74f8bSWei Liu uint8_t id; 150ebe74f8bSWei Liu uint8_t cancelled; 151ebe74f8bSWei Liu CoQueue complete; 15221cf9edfSGreg Kurz V9fsState *s; 153ebe74f8bSWei Liu QLIST_ENTRY(V9fsPDU) next; 15400588a0aSWei Liu uint32_t idx; 155ebe74f8bSWei Liu }; 156ebe74f8bSWei Liu 157ebe74f8bSWei Liu 158ebe74f8bSWei Liu /* FIXME 159ebe74f8bSWei Liu * 1) change user needs to set groups and stuff 160ebe74f8bSWei Liu */ 161ebe74f8bSWei Liu 162ebe74f8bSWei Liu #define MAX_REQ 128 163ebe74f8bSWei Liu #define MAX_TAG_LEN 32 164ebe74f8bSWei Liu 165ebe74f8bSWei Liu #define BUG_ON(cond) assert(!(cond)) 166ebe74f8bSWei Liu 167ebe74f8bSWei Liu typedef struct V9fsFidState V9fsFidState; 168ebe74f8bSWei Liu 169ebe74f8bSWei Liu enum { 170ebe74f8bSWei Liu P9_FID_NONE = 0, 171ebe74f8bSWei Liu P9_FID_FILE, 172ebe74f8bSWei Liu P9_FID_DIR, 173ebe74f8bSWei Liu P9_FID_XATTR, 174ebe74f8bSWei Liu }; 175ebe74f8bSWei Liu 176ebe74f8bSWei Liu typedef struct V9fsConf 177ebe74f8bSWei Liu { 178ebe74f8bSWei Liu /* tag name for the device */ 179ebe74f8bSWei Liu char *tag; 180ebe74f8bSWei Liu char *fsdev_id; 181ebe74f8bSWei Liu } V9fsConf; 182ebe74f8bSWei Liu 183aca6897fSKeno Fischer /* 9p2000.L xattr flags (matches Linux values) */ 184aca6897fSKeno Fischer #define P9_XATTR_CREATE 1 185aca6897fSKeno Fischer #define P9_XATTR_REPLACE 2 186aca6897fSKeno Fischer 187ebe74f8bSWei Liu typedef struct V9fsXattr 188ebe74f8bSWei Liu { 1898495f9adSLi Qiang uint64_t copied_len; 1908495f9adSLi Qiang uint64_t len; 191ebe74f8bSWei Liu void *value; 192ebe74f8bSWei Liu V9fsString name; 193ebe74f8bSWei Liu int flags; 194dd28fbbcSLi Qiang bool xattrwalk_fid; 195ebe74f8bSWei Liu } V9fsXattr; 196ebe74f8bSWei Liu 197f314ea4eSGreg Kurz typedef struct V9fsDir { 198f314ea4eSGreg Kurz DIR *stream; 199d2c5cf7cSChristian Schoenebeck P9ProtoVersion proto_version; 200d2c5cf7cSChristian Schoenebeck /* readdir mutex type used for 9P2000.u protocol variant */ 201d2c5cf7cSChristian Schoenebeck CoMutex readdir_mutex_u; 202d2c5cf7cSChristian Schoenebeck /* readdir mutex type used for 9P2000.L protocol variant */ 203d2c5cf7cSChristian Schoenebeck QemuMutex readdir_mutex_L; 204f314ea4eSGreg Kurz } V9fsDir; 205f314ea4eSGreg Kurz 2067cde47d4SGreg Kurz static inline void v9fs_readdir_lock(V9fsDir *dir) 2077cde47d4SGreg Kurz { 208d2c5cf7cSChristian Schoenebeck if (dir->proto_version == V9FS_PROTO_2000U) { 209d2c5cf7cSChristian Schoenebeck qemu_co_mutex_lock(&dir->readdir_mutex_u); 210d2c5cf7cSChristian Schoenebeck } else { 211d2c5cf7cSChristian Schoenebeck qemu_mutex_lock(&dir->readdir_mutex_L); 212d2c5cf7cSChristian Schoenebeck } 2137cde47d4SGreg Kurz } 2147cde47d4SGreg Kurz 2157cde47d4SGreg Kurz static inline void v9fs_readdir_unlock(V9fsDir *dir) 2167cde47d4SGreg Kurz { 217d2c5cf7cSChristian Schoenebeck if (dir->proto_version == V9FS_PROTO_2000U) { 218d2c5cf7cSChristian Schoenebeck qemu_co_mutex_unlock(&dir->readdir_mutex_u); 219d2c5cf7cSChristian Schoenebeck } else { 220d2c5cf7cSChristian Schoenebeck qemu_mutex_unlock(&dir->readdir_mutex_L); 221d2c5cf7cSChristian Schoenebeck } 2227cde47d4SGreg Kurz } 2237cde47d4SGreg Kurz 224d2c5cf7cSChristian Schoenebeck static inline void v9fs_readdir_init(P9ProtoVersion proto_version, V9fsDir *dir) 2257cde47d4SGreg Kurz { 226d2c5cf7cSChristian Schoenebeck dir->proto_version = proto_version; 227d2c5cf7cSChristian Schoenebeck if (proto_version == V9FS_PROTO_2000U) { 228d2c5cf7cSChristian Schoenebeck qemu_co_mutex_init(&dir->readdir_mutex_u); 229d2c5cf7cSChristian Schoenebeck } else { 230d2c5cf7cSChristian Schoenebeck qemu_mutex_init(&dir->readdir_mutex_L); 231d2c5cf7cSChristian Schoenebeck } 2327cde47d4SGreg Kurz } 2337cde47d4SGreg Kurz 2342149675bSChristian Schoenebeck /** 2352149675bSChristian Schoenebeck * Type for 9p fs drivers' (a.k.a. 9p backends) result of readdir requests, 2362149675bSChristian Schoenebeck * which is a chained list of directory entries. 2372149675bSChristian Schoenebeck */ 2382149675bSChristian Schoenebeck typedef struct V9fsDirEnt { 2392149675bSChristian Schoenebeck /* mandatory (must not be NULL) information for all readdir requests */ 2402149675bSChristian Schoenebeck struct dirent *dent; 2412149675bSChristian Schoenebeck /* 2422149675bSChristian Schoenebeck * optional (may be NULL): A full stat of each directory entry is just 2432149675bSChristian Schoenebeck * done if explicitly told to fs driver. 2442149675bSChristian Schoenebeck */ 2452149675bSChristian Schoenebeck struct stat *st; 2462149675bSChristian Schoenebeck /* 2472149675bSChristian Schoenebeck * instead of an array, directory entries are always returned as 2482149675bSChristian Schoenebeck * chained list, that's because the amount of entries retrieved by fs 2492149675bSChristian Schoenebeck * drivers is dependent on the individual entries' name (since response 2502149675bSChristian Schoenebeck * messages are size limited), so the final amount cannot be estimated 2512149675bSChristian Schoenebeck * before hand 2522149675bSChristian Schoenebeck */ 2532149675bSChristian Schoenebeck struct V9fsDirEnt *next; 2542149675bSChristian Schoenebeck } V9fsDirEnt; 2552149675bSChristian Schoenebeck 256ebe74f8bSWei Liu /* 257ebe74f8bSWei Liu * Filled by fs driver on open and other 258ebe74f8bSWei Liu * calls. 259ebe74f8bSWei Liu */ 260ebe74f8bSWei Liu union V9fsFidOpenState { 261ebe74f8bSWei Liu int fd; 262f314ea4eSGreg Kurz V9fsDir dir; 263ebe74f8bSWei Liu V9fsXattr xattr; 264ebe74f8bSWei Liu /* 265ebe74f8bSWei Liu * private pointer for fs drivers, that 266ebe74f8bSWei Liu * have its own internal representation of 267ebe74f8bSWei Liu * open files. 268ebe74f8bSWei Liu */ 269ebe74f8bSWei Liu void *private; 270ebe74f8bSWei Liu }; 271ebe74f8bSWei Liu 272487729e9SXinhao Zhang struct V9fsFidState { 273ebe74f8bSWei Liu int fid_type; 274ebe74f8bSWei Liu int32_t fid; 275ebe74f8bSWei Liu V9fsPath path; 276ebe74f8bSWei Liu V9fsFidOpenState fs; 277ebe74f8bSWei Liu V9fsFidOpenState fs_reclaim; 278ebe74f8bSWei Liu int flags; 279ebe74f8bSWei Liu int open_flags; 280ebe74f8bSWei Liu uid_t uid; 281ebe74f8bSWei Liu int ref; 2822e53160fSGreg Kurz bool clunked; 283feabd6cfSGreg Kurz QSIMPLEQ_ENTRY(V9fsFidState) next; 284*81f9766bSGreg Kurz QSLIST_ENTRY(V9fsFidState) reclaim_next; 285ebe74f8bSWei Liu }; 286ebe74f8bSWei Liu 2876b6aa828SChristian Schoenebeck typedef enum AffixType_t { 2886b6aa828SChristian Schoenebeck AffixType_Prefix, 2896b6aa828SChristian Schoenebeck AffixType_Suffix, /* A.k.a. postfix. */ 2906b6aa828SChristian Schoenebeck } AffixType_t; 2916b6aa828SChristian Schoenebeck 2926b6aa828SChristian Schoenebeck /** 2936b6aa828SChristian Schoenebeck * @brief Unique affix of variable length. 2946b6aa828SChristian Schoenebeck * 2956b6aa828SChristian Schoenebeck * An affix is (currently) either a suffix or a prefix, which is either 2966b6aa828SChristian Schoenebeck * going to be prepended (prefix) or appended (suffix) with some other 2976b6aa828SChristian Schoenebeck * number for the goal to generate unique numbers. Accordingly the 2986b6aa828SChristian Schoenebeck * suffixes (or prefixes) we generate @b must all have the mathematical 2996b6aa828SChristian Schoenebeck * property of being suffix-free (or prefix-free in case of prefixes) 3006b6aa828SChristian Schoenebeck * so that no matter what number we concatenate the affix with, that we 3016b6aa828SChristian Schoenebeck * always reliably get unique numbers as result after concatenation. 3026b6aa828SChristian Schoenebeck */ 3036b6aa828SChristian Schoenebeck typedef struct VariLenAffix { 3046b6aa828SChristian Schoenebeck AffixType_t type; /* Whether this affix is a suffix or a prefix. */ 3056b6aa828SChristian Schoenebeck uint64_t value; /* Actual numerical value of this affix. */ 3066b6aa828SChristian Schoenebeck /* 3076b6aa828SChristian Schoenebeck * Lenght of the affix, that is how many (of the lowest) bits of @c value 3086b6aa828SChristian Schoenebeck * must be used for appending/prepending this affix to its final resulting, 3096b6aa828SChristian Schoenebeck * unique number. 3106b6aa828SChristian Schoenebeck */ 3116b6aa828SChristian Schoenebeck int bits; 3126b6aa828SChristian Schoenebeck } VariLenAffix; 3136b6aa828SChristian Schoenebeck 3146b6aa828SChristian Schoenebeck /* See qid_inode_prefix_hash_bits(). */ 3156b6aa828SChristian Schoenebeck typedef struct { 3166b6aa828SChristian Schoenebeck dev_t dev; /* FS device on host. */ 3176b6aa828SChristian Schoenebeck /* 3186b6aa828SChristian Schoenebeck * How many (high) bits of the original inode number shall be used for 3196b6aa828SChristian Schoenebeck * hashing. 3206b6aa828SChristian Schoenebeck */ 3216b6aa828SChristian Schoenebeck int prefix_bits; 3226b6aa828SChristian Schoenebeck } QpdEntry; 3231a6ed33cSAntonios Motakis 3241a6ed33cSAntonios Motakis /* QID path prefix entry, see stat_to_qid */ 3251a6ed33cSAntonios Motakis typedef struct { 3261a6ed33cSAntonios Motakis dev_t dev; 3271a6ed33cSAntonios Motakis uint16_t ino_prefix; 3286b6aa828SChristian Schoenebeck uint32_t qp_affix_index; 3296b6aa828SChristian Schoenebeck VariLenAffix qp_affix; 3301a6ed33cSAntonios Motakis } QppEntry; 3311a6ed33cSAntonios Motakis 332f3fe4a2dSAntonios Motakis /* QID path full entry, as above */ 333f3fe4a2dSAntonios Motakis typedef struct { 334f3fe4a2dSAntonios Motakis dev_t dev; 335f3fe4a2dSAntonios Motakis ino_t ino; 336f3fe4a2dSAntonios Motakis uint64_t path; 337f3fe4a2dSAntonios Motakis } QpfEntry; 338f3fe4a2dSAntonios Motakis 339487729e9SXinhao Zhang struct V9fsState { 340ebe74f8bSWei Liu QLIST_HEAD(, V9fsPDU) free_list; 341ebe74f8bSWei Liu QLIST_HEAD(, V9fsPDU) active_list; 342feabd6cfSGreg Kurz QSIMPLEQ_HEAD(, V9fsFidState) fid_list; 343ebe74f8bSWei Liu FileOperations *ops; 344ebe74f8bSWei Liu FsContext ctx; 345ebe74f8bSWei Liu char *tag; 3468e71b96cSGreg Kurz P9ProtoVersion proto_version; 347ebe74f8bSWei Liu int32_t msize; 348583f21f8SStefano Stabellini V9fsPDU pdus[MAX_REQ]; 3498e71b96cSGreg Kurz const V9fsTransport *transport; 350ebe74f8bSWei Liu /* 351ebe74f8bSWei Liu * lock ensuring atomic path update 352ebe74f8bSWei Liu * on rename. 353ebe74f8bSWei Liu */ 354ebe74f8bSWei Liu CoRwlock rename_lock; 355ebe74f8bSWei Liu int32_t root_fid; 356ebe74f8bSWei Liu Error *migration_blocker; 357ebe74f8bSWei Liu V9fsConf fsconf; 35856f101ecSGreg Kurz V9fsQID root_qid; 3593b5ee9e8SAntonios Motakis dev_t dev_id; 3606b6aa828SChristian Schoenebeck struct qht qpd_table; 3611a6ed33cSAntonios Motakis struct qht qpp_table; 362f3fe4a2dSAntonios Motakis struct qht qpf_table; 3636b6aa828SChristian Schoenebeck uint64_t qp_ndevices; /* Amount of entries in qpd_table. */ 3646b6aa828SChristian Schoenebeck uint16_t qp_affix_next; 365f3fe4a2dSAntonios Motakis uint64_t qp_fullpath_next; 36621cf9edfSGreg Kurz }; 367ebe74f8bSWei Liu 368ebe74f8bSWei Liu /* 9p2000.L open flags */ 369ebe74f8bSWei Liu #define P9_DOTL_RDONLY 00000000 370ebe74f8bSWei Liu #define P9_DOTL_WRONLY 00000001 371ebe74f8bSWei Liu #define P9_DOTL_RDWR 00000002 372ebe74f8bSWei Liu #define P9_DOTL_NOACCESS 00000003 373ebe74f8bSWei Liu #define P9_DOTL_CREATE 00000100 374ebe74f8bSWei Liu #define P9_DOTL_EXCL 00000200 375ebe74f8bSWei Liu #define P9_DOTL_NOCTTY 00000400 376ebe74f8bSWei Liu #define P9_DOTL_TRUNC 00001000 377ebe74f8bSWei Liu #define P9_DOTL_APPEND 00002000 378ebe74f8bSWei Liu #define P9_DOTL_NONBLOCK 00004000 379ebe74f8bSWei Liu #define P9_DOTL_DSYNC 00010000 380ebe74f8bSWei Liu #define P9_DOTL_FASYNC 00020000 381ebe74f8bSWei Liu #define P9_DOTL_DIRECT 00040000 382ebe74f8bSWei Liu #define P9_DOTL_LARGEFILE 00100000 383ebe74f8bSWei Liu #define P9_DOTL_DIRECTORY 00200000 384ebe74f8bSWei Liu #define P9_DOTL_NOFOLLOW 00400000 385ebe74f8bSWei Liu #define P9_DOTL_NOATIME 01000000 386ebe74f8bSWei Liu #define P9_DOTL_CLOEXEC 02000000 387ebe74f8bSWei Liu #define P9_DOTL_SYNC 04000000 388ebe74f8bSWei Liu 389ebe74f8bSWei Liu /* 9p2000.L at flags */ 390ebe74f8bSWei Liu #define P9_DOTL_AT_REMOVEDIR 0x200 391ebe74f8bSWei Liu 392ebe74f8bSWei Liu /* 9P2000.L lock type */ 393ebe74f8bSWei Liu #define P9_LOCK_TYPE_RDLCK 0 394ebe74f8bSWei Liu #define P9_LOCK_TYPE_WRLCK 1 395ebe74f8bSWei Liu #define P9_LOCK_TYPE_UNLCK 2 396ebe74f8bSWei Liu 397ebe74f8bSWei Liu #define P9_LOCK_SUCCESS 0 398ebe74f8bSWei Liu #define P9_LOCK_BLOCKED 1 399ebe74f8bSWei Liu #define P9_LOCK_ERROR 2 400ebe74f8bSWei Liu #define P9_LOCK_GRACE 3 401ebe74f8bSWei Liu 402ebe74f8bSWei Liu #define P9_LOCK_FLAGS_BLOCK 1 403ebe74f8bSWei Liu #define P9_LOCK_FLAGS_RECLAIM 2 404ebe74f8bSWei Liu 405ebe74f8bSWei Liu typedef struct V9fsFlock 406ebe74f8bSWei Liu { 407ebe74f8bSWei Liu uint8_t type; 408ebe74f8bSWei Liu uint32_t flags; 409ebe74f8bSWei Liu uint64_t start; /* absolute offset */ 410ebe74f8bSWei Liu uint64_t length; 411ebe74f8bSWei Liu uint32_t proc_id; 412ebe74f8bSWei Liu V9fsString client_id; 413ebe74f8bSWei Liu } V9fsFlock; 414ebe74f8bSWei Liu 415ebe74f8bSWei Liu typedef struct V9fsGetlock 416ebe74f8bSWei Liu { 417ebe74f8bSWei Liu uint8_t type; 418ebe74f8bSWei Liu uint64_t start; /* absolute offset */ 419ebe74f8bSWei Liu uint64_t length; 420ebe74f8bSWei Liu uint32_t proc_id; 421ebe74f8bSWei Liu V9fsString client_id; 422ebe74f8bSWei Liu } V9fsGetlock; 423ebe74f8bSWei Liu 424ebe74f8bSWei Liu extern int open_fd_hw; 425ebe74f8bSWei Liu extern int total_open_fd; 426ebe74f8bSWei Liu 427ebe74f8bSWei Liu static inline void v9fs_path_write_lock(V9fsState *s) 428ebe74f8bSWei Liu { 429ebe74f8bSWei Liu if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) { 430ebe74f8bSWei Liu qemu_co_rwlock_wrlock(&s->rename_lock); 431ebe74f8bSWei Liu } 432ebe74f8bSWei Liu } 433ebe74f8bSWei Liu 434ebe74f8bSWei Liu static inline void v9fs_path_read_lock(V9fsState *s) 435ebe74f8bSWei Liu { 436ebe74f8bSWei Liu if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) { 437ebe74f8bSWei Liu qemu_co_rwlock_rdlock(&s->rename_lock); 438ebe74f8bSWei Liu } 439ebe74f8bSWei Liu } 440ebe74f8bSWei Liu 441ebe74f8bSWei Liu static inline void v9fs_path_unlock(V9fsState *s) 442ebe74f8bSWei Liu { 443ebe74f8bSWei Liu if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) { 444ebe74f8bSWei Liu qemu_co_rwlock_unlock(&s->rename_lock); 445ebe74f8bSWei Liu } 446ebe74f8bSWei Liu } 447ebe74f8bSWei Liu 448ebe74f8bSWei Liu static inline uint8_t v9fs_request_cancelled(V9fsPDU *pdu) 449ebe74f8bSWei Liu { 450ebe74f8bSWei Liu return pdu->cancelled; 451ebe74f8bSWei Liu } 452ebe74f8bSWei Liu 4538440e22eSGreg Kurz void coroutine_fn v9fs_reclaim_fd(V9fsPDU *pdu); 454bc70a592SGreg Kurz void v9fs_path_init(V9fsPath *path); 455bc70a592SGreg Kurz void v9fs_path_free(V9fsPath *path); 456bc70a592SGreg Kurz void v9fs_path_sprintf(V9fsPath *path, const char *fmt, ...); 457e446a1ebSMarc-André Lureau void v9fs_path_copy(V9fsPath *dst, const V9fsPath *src); 45829c9d2caSChristian Schoenebeck size_t v9fs_readdir_response_size(V9fsString *name); 459bc70a592SGreg Kurz int v9fs_name_to_path(V9fsState *s, V9fsPath *dirpath, 460ebe74f8bSWei Liu const char *name, V9fsPath *path); 461066eb006SGreg Kurz int v9fs_device_realize_common(V9fsState *s, const V9fsTransport *t, 462066eb006SGreg Kurz Error **errp); 463b69c3c21SMarkus Armbruster void v9fs_device_unrealize_common(V9fsState *s); 464ebe74f8bSWei Liu 4654b311c5fSWei Liu V9fsPDU *pdu_alloc(V9fsState *s); 4664b311c5fSWei Liu void pdu_free(V9fsPDU *pdu); 467506f3275SGreg Kurz void pdu_submit(V9fsPDU *pdu, P9MsgHeader *hdr); 4680e44a0fdSGreg Kurz void v9fs_reset(V9fsState *s); 469ebe74f8bSWei Liu 470ea83441cSStefano Stabellini struct V9fsTransport { 471ea83441cSStefano Stabellini ssize_t (*pdu_vmarshal)(V9fsPDU *pdu, size_t offset, const char *fmt, 472ea83441cSStefano Stabellini va_list ap); 473ea83441cSStefano Stabellini ssize_t (*pdu_vunmarshal)(V9fsPDU *pdu, size_t offset, const char *fmt, 474ea83441cSStefano Stabellini va_list ap); 47588da0b03SStefano Stabellini void (*init_in_iov_from_pdu)(V9fsPDU *pdu, struct iovec **piov, 476cf45183bSStefano Stabellini unsigned int *pniov, size_t size); 47788da0b03SStefano Stabellini void (*init_out_iov_from_pdu)(V9fsPDU *pdu, struct iovec **piov, 4788d37de41SGreg Kurz unsigned int *pniov, size_t size); 479ea83441cSStefano Stabellini void (*push_and_notify)(V9fsPDU *pdu); 480ea83441cSStefano Stabellini }; 481ea83441cSStefano Stabellini 482ebe74f8bSWei Liu #endif 483