19f107513SAnthony Liguori #ifndef _QEMU_VIRTIO_9P_H 29f107513SAnthony Liguori #define _QEMU_VIRTIO_9P_H 39f107513SAnthony Liguori 49f107513SAnthony Liguori #include <sys/types.h> 59f107513SAnthony Liguori #include <dirent.h> 69f107513SAnthony Liguori #include <sys/time.h> 79f107513SAnthony Liguori #include <utime.h> 87a462745SAneesh Kumar K.V #include <sys/resource.h> 9ff06030fSVenkateswararao Jujjuri (JV) #include "hw/virtio.h" 10353ac78dSAneesh Kumar K.V #include "fsdev/file-op-9p.h" 1102cb7f3aSAneesh Kumar K.V #include "qemu-thread.h" 1202cb7f3aSAneesh Kumar K.V #include "qemu-coroutine.h" 139f107513SAnthony Liguori 149f107513SAnthony Liguori /* The feature bitmap for virtio 9P */ 159f107513SAnthony Liguori /* The mount point is specified in a config variable */ 169f107513SAnthony Liguori #define VIRTIO_9P_MOUNT_TAG 0 179f107513SAnthony Liguori 189f107513SAnthony Liguori enum { 198f4d1ca5SArun R Bharadwaj P9_TLERROR = 6, 208f4d1ca5SArun R Bharadwaj P9_RLERROR, 21be940c87SM. Mohan Kumar P9_TSTATFS = 8, 22be940c87SM. Mohan Kumar P9_RSTATFS, 23771e9d4cSM. Mohan Kumar P9_TLOPEN = 12, 24771e9d4cSM. Mohan Kumar P9_RLOPEN, 25c1568af5SVenkateswararao Jujjuri (JV) P9_TLCREATE = 14, 26c1568af5SVenkateswararao Jujjuri (JV) P9_RLCREATE, 2708c60fc9SVenkateswararao Jujjuri (JV) P9_TSYMLINK = 16, 2808c60fc9SVenkateswararao Jujjuri (JV) P9_RSYMLINK, 295268ceccSM. Mohan Kumar P9_TMKNOD = 18, 305268ceccSM. Mohan Kumar P9_RMKNOD, 31c7b4b0b3SM. Mohan Kumar P9_TRENAME = 20, 32c7b4b0b3SM. Mohan Kumar P9_RRENAME, 33df0973a4SM. Mohan Kumar P9_TREADLINK = 22, 34df0973a4SM. Mohan Kumar P9_RREADLINK, 3500ede4c2SSripathi Kodi P9_TGETATTR = 24, 3600ede4c2SSripathi Kodi P9_RGETATTR, 37c79ce737SSripathi Kodi P9_TSETATTR = 26, 38c79ce737SSripathi Kodi P9_RSETATTR, 39fa32ef88SAneesh Kumar K.V P9_TXATTRWALK = 30, 40fa32ef88SAneesh Kumar K.V P9_RXATTRWALK, 4110b468bdSAneesh Kumar K.V P9_TXATTRCREATE = 32, 4210b468bdSAneesh Kumar K.V P9_RXATTRCREATE, 43c18e2f94SSripathi Kodi P9_TREADDIR = 40, 44c18e2f94SSripathi Kodi P9_RREADDIR, 45b41e95d3SVenkateswararao Jujjuri (JV) P9_TFSYNC = 50, 46b41e95d3SVenkateswararao Jujjuri (JV) P9_RFSYNC, 4782cc3ee8SM. Mohan Kumar P9_TLOCK = 52, 4882cc3ee8SM. Mohan Kumar P9_RLOCK, 498f354003SM. Mohan Kumar P9_TGETLOCK = 54, 508f354003SM. Mohan Kumar P9_RGETLOCK, 51b2c224beSVenkateswararao Jujjuri (JV) P9_TLINK = 70, 52b2c224beSVenkateswararao Jujjuri (JV) P9_RLINK, 53b67592eaSM. Mohan Kumar P9_TMKDIR = 72, 54b67592eaSM. Mohan Kumar P9_RMKDIR, 5589bf6593SAneesh Kumar K.V P9_TRENAMEAT = 74, 5689bf6593SAneesh Kumar K.V P9_RRENAMEAT, 577834cf77SAneesh Kumar K.V P9_TUNLINKAT = 76, 587834cf77SAneesh Kumar K.V P9_RUNLINKAT, 599f107513SAnthony Liguori P9_TVERSION = 100, 609f107513SAnthony Liguori P9_RVERSION, 619f107513SAnthony Liguori P9_TAUTH = 102, 629f107513SAnthony Liguori P9_RAUTH, 639f107513SAnthony Liguori P9_TATTACH = 104, 649f107513SAnthony Liguori P9_RATTACH, 659f107513SAnthony Liguori P9_TERROR = 106, 669f107513SAnthony Liguori P9_RERROR, 679f107513SAnthony Liguori P9_TFLUSH = 108, 689f107513SAnthony Liguori P9_RFLUSH, 699f107513SAnthony Liguori P9_TWALK = 110, 709f107513SAnthony Liguori P9_RWALK, 719f107513SAnthony Liguori P9_TOPEN = 112, 729f107513SAnthony Liguori P9_ROPEN, 739f107513SAnthony Liguori P9_TCREATE = 114, 749f107513SAnthony Liguori P9_RCREATE, 759f107513SAnthony Liguori P9_TREAD = 116, 769f107513SAnthony Liguori P9_RREAD, 779f107513SAnthony Liguori P9_TWRITE = 118, 789f107513SAnthony Liguori P9_RWRITE, 799f107513SAnthony Liguori P9_TCLUNK = 120, 809f107513SAnthony Liguori P9_RCLUNK, 819f107513SAnthony Liguori P9_TREMOVE = 122, 829f107513SAnthony Liguori P9_RREMOVE, 839f107513SAnthony Liguori P9_TSTAT = 124, 849f107513SAnthony Liguori P9_RSTAT, 859f107513SAnthony Liguori P9_TWSTAT = 126, 869f107513SAnthony Liguori P9_RWSTAT, 879f107513SAnthony Liguori }; 889f107513SAnthony Liguori 899f107513SAnthony Liguori 909f107513SAnthony Liguori /* qid.types */ 919f107513SAnthony Liguori enum { 929f107513SAnthony Liguori P9_QTDIR = 0x80, 939f107513SAnthony Liguori P9_QTAPPEND = 0x40, 949f107513SAnthony Liguori P9_QTEXCL = 0x20, 959f107513SAnthony Liguori P9_QTMOUNT = 0x10, 969f107513SAnthony Liguori P9_QTAUTH = 0x08, 979f107513SAnthony Liguori P9_QTTMP = 0x04, 989f107513SAnthony Liguori P9_QTSYMLINK = 0x02, 999f107513SAnthony Liguori P9_QTLINK = 0x01, 1009f107513SAnthony Liguori P9_QTFILE = 0x00, 1019f107513SAnthony Liguori }; 1029f107513SAnthony Liguori 10384151514SM. Mohan Kumar enum p9_proto_version { 10484151514SM. Mohan Kumar V9FS_PROTO_2000U = 0x01, 10584151514SM. Mohan Kumar V9FS_PROTO_2000L = 0x02, 10684151514SM. Mohan Kumar }; 10784151514SM. Mohan Kumar 1089f107513SAnthony Liguori #define P9_NOTAG (u16)(~0) 1099f107513SAnthony Liguori #define P9_NOFID (u32)(~0) 1109f107513SAnthony Liguori #define P9_MAXWELEM 16 1117a462745SAneesh Kumar K.V 1127a462745SAneesh Kumar K.V #define FID_REFERENCED 0x1 1137a462745SAneesh Kumar K.V #define FID_NON_RECLAIMABLE 0x2 114faa44e3dSVenkateswararao Jujjuri (JV) static inline const char *rpath(FsContext *ctx, const char *path, char *buffer) 115faa44e3dSVenkateswararao Jujjuri (JV) { 116faa44e3dSVenkateswararao Jujjuri (JV) snprintf(buffer, PATH_MAX, "%s/%s", ctx->fs_root, path); 117faa44e3dSVenkateswararao Jujjuri (JV) return buffer; 118faa44e3dSVenkateswararao Jujjuri (JV) } 1199f107513SAnthony Liguori 1205e94c103SM. Mohan Kumar /* 1215e94c103SM. Mohan Kumar * ample room for Twrite/Rread header 1225e94c103SM. Mohan Kumar * size[4] Tread/Twrite tag[2] fid[4] offset[8] count[4] 1235e94c103SM. Mohan Kumar */ 1245e94c103SM. Mohan Kumar #define P9_IOHDRSZ 24 1255e94c103SM. Mohan Kumar 1269f107513SAnthony Liguori typedef struct V9fsPDU V9fsPDU; 127ff06030fSVenkateswararao Jujjuri (JV) struct V9fsState; 1289f107513SAnthony Liguori 1299f107513SAnthony Liguori struct V9fsPDU 1309f107513SAnthony Liguori { 1319f107513SAnthony Liguori uint32_t size; 1329f107513SAnthony Liguori uint16_t tag; 1339f107513SAnthony Liguori uint8_t id; 134bccacf6cSAneesh Kumar K.V uint8_t cancelled; 135bccacf6cSAneesh Kumar K.V CoQueue complete; 1369f107513SAnthony Liguori VirtQueueElement elem; 137ff06030fSVenkateswararao Jujjuri (JV) struct V9fsState *s; 1389f107513SAnthony Liguori QLIST_ENTRY(V9fsPDU) next; 1399f107513SAnthony Liguori }; 1409f107513SAnthony Liguori 1419f107513SAnthony Liguori 1429f107513SAnthony Liguori /* FIXME 1439f107513SAnthony Liguori * 1) change user needs to set groups and stuff 1449f107513SAnthony Liguori */ 1459f107513SAnthony Liguori 1469f107513SAnthony Liguori /* from Linux's linux/virtio_9p.h */ 1479f107513SAnthony Liguori 1489f107513SAnthony Liguori /* The ID for virtio console */ 1499f107513SAnthony Liguori #define VIRTIO_ID_9P 9 1509f107513SAnthony Liguori #define MAX_REQ 128 1519f107513SAnthony Liguori #define MAX_TAG_LEN 32 1529f107513SAnthony Liguori 1539f107513SAnthony Liguori #define BUG_ON(cond) assert(!(cond)) 1549f107513SAnthony Liguori 1559f107513SAnthony Liguori typedef struct V9fsFidState V9fsFidState; 1569f107513SAnthony Liguori 1579f107513SAnthony Liguori typedef struct V9fsString 1589f107513SAnthony Liguori { 1599f107513SAnthony Liguori int16_t size; 1609f107513SAnthony Liguori char *data; 1619f107513SAnthony Liguori } V9fsString; 1629f107513SAnthony Liguori 1639f107513SAnthony Liguori typedef struct V9fsQID 1649f107513SAnthony Liguori { 1659f107513SAnthony Liguori int8_t type; 1669f107513SAnthony Liguori int32_t version; 1679f107513SAnthony Liguori int64_t path; 1689f107513SAnthony Liguori } V9fsQID; 1699f107513SAnthony Liguori 1709f107513SAnthony Liguori typedef struct V9fsStat 1719f107513SAnthony Liguori { 1729f107513SAnthony Liguori int16_t size; 1739f107513SAnthony Liguori int16_t type; 1749f107513SAnthony Liguori int32_t dev; 1759f107513SAnthony Liguori V9fsQID qid; 1769f107513SAnthony Liguori int32_t mode; 1779f107513SAnthony Liguori int32_t atime; 1789f107513SAnthony Liguori int32_t mtime; 1799f107513SAnthony Liguori int64_t length; 1809f107513SAnthony Liguori V9fsString name; 1819f107513SAnthony Liguori V9fsString uid; 1829f107513SAnthony Liguori V9fsString gid; 1839f107513SAnthony Liguori V9fsString muid; 1849f107513SAnthony Liguori /* 9p2000.u */ 1859f107513SAnthony Liguori V9fsString extension; 1869f107513SAnthony Liguori int32_t n_uid; 1879f107513SAnthony Liguori int32_t n_gid; 1889f107513SAnthony Liguori int32_t n_muid; 1899f107513SAnthony Liguori } V9fsStat; 1909f107513SAnthony Liguori 191d62dbb51SAneesh Kumar K.V enum { 192d62dbb51SAneesh Kumar K.V P9_FID_NONE = 0, 193d62dbb51SAneesh Kumar K.V P9_FID_FILE, 194d62dbb51SAneesh Kumar K.V P9_FID_DIR, 195d62dbb51SAneesh Kumar K.V P9_FID_XATTR, 196d62dbb51SAneesh Kumar K.V }; 197d62dbb51SAneesh Kumar K.V 198d62dbb51SAneesh Kumar K.V typedef struct V9fsXattr 199d62dbb51SAneesh Kumar K.V { 200d62dbb51SAneesh Kumar K.V int64_t copied_len; 201d62dbb51SAneesh Kumar K.V int64_t len; 202d62dbb51SAneesh Kumar K.V void *value; 203d62dbb51SAneesh Kumar K.V V9fsString name; 204d62dbb51SAneesh Kumar K.V int flags; 205d62dbb51SAneesh Kumar K.V } V9fsXattr; 206d62dbb51SAneesh Kumar K.V 207cc720ddbSAneesh Kumar K.V /* 208cc720ddbSAneesh Kumar K.V * Filled by fs driver on open and other 209cc720ddbSAneesh Kumar K.V * calls. 210cc720ddbSAneesh Kumar K.V */ 211cc720ddbSAneesh Kumar K.V union V9fsFidOpenState { 212cc720ddbSAneesh Kumar K.V int fd; 213cc720ddbSAneesh Kumar K.V DIR *dir; 214cc720ddbSAneesh Kumar K.V V9fsXattr xattr; 2159db221aeSAneesh Kumar K.V /* 2169db221aeSAneesh Kumar K.V * private pointer for fs drivers, that 2179db221aeSAneesh Kumar K.V * have its own internal representation of 2189db221aeSAneesh Kumar K.V * open files. 2199db221aeSAneesh Kumar K.V */ 2209db221aeSAneesh Kumar K.V void *private; 221cc720ddbSAneesh Kumar K.V }; 222cc720ddbSAneesh Kumar K.V 2239f107513SAnthony Liguori struct V9fsFidState 2249f107513SAnthony Liguori { 225d62dbb51SAneesh Kumar K.V int fid_type; 2269f107513SAnthony Liguori int32_t fid; 2272289be19SAneesh Kumar K.V V9fsPath path; 228cc720ddbSAneesh Kumar K.V V9fsFidOpenState fs; 229cc720ddbSAneesh Kumar K.V V9fsFidOpenState fs_reclaim; 2307a462745SAneesh Kumar K.V int flags; 2317a462745SAneesh Kumar K.V int open_flags; 2329f107513SAnthony Liguori uid_t uid; 23384dfb926SAneesh Kumar K.V int ref; 23484dfb926SAneesh Kumar K.V int clunked; 2359f107513SAnthony Liguori V9fsFidState *next; 2367a462745SAneesh Kumar K.V V9fsFidState *rclm_lst; 2379f107513SAnthony Liguori }; 2389f107513SAnthony Liguori 2399f107513SAnthony Liguori typedef struct V9fsState 2409f107513SAnthony Liguori { 2419f107513SAnthony Liguori VirtIODevice vdev; 2429f107513SAnthony Liguori VirtQueue *vq; 2439f107513SAnthony Liguori V9fsPDU pdus[MAX_REQ]; 2449f107513SAnthony Liguori QLIST_HEAD(, V9fsPDU) free_list; 245bccacf6cSAneesh Kumar K.V QLIST_HEAD(, V9fsPDU) active_list; 2469f107513SAnthony Liguori V9fsFidState *fid_list; 2479f107513SAnthony Liguori FileOperations *ops; 2489f107513SAnthony Liguori FsContext ctx; 249*e9a0152bSAneesh Kumar K.V char *tag; 2509f107513SAnthony Liguori size_t config_size; 25184151514SM. Mohan Kumar enum p9_proto_version proto_version; 2525e94c103SM. Mohan Kumar int32_t msize; 25302cb7f3aSAneesh Kumar K.V /* 25402cb7f3aSAneesh Kumar K.V * lock ensuring atomic path update 25502cb7f3aSAneesh Kumar K.V * on rename. 25602cb7f3aSAneesh Kumar K.V */ 25702cb7f3aSAneesh Kumar K.V CoRwlock rename_lock; 258*e9a0152bSAneesh Kumar K.V int32_t root_fid; 259*e9a0152bSAneesh Kumar K.V Error *migration_blocker; 2609f107513SAnthony Liguori } V9fsState; 2619f107513SAnthony Liguori 262fac4f111SVenkateswararao Jujjuri (JV) typedef struct V9fsStatState { 263fac4f111SVenkateswararao Jujjuri (JV) V9fsPDU *pdu; 264fac4f111SVenkateswararao Jujjuri (JV) size_t offset; 265fac4f111SVenkateswararao Jujjuri (JV) V9fsStat v9stat; 266fac4f111SVenkateswararao Jujjuri (JV) V9fsFidState *fidp; 267fac4f111SVenkateswararao Jujjuri (JV) struct stat stbuf; 268fac4f111SVenkateswararao Jujjuri (JV) } V9fsStatState; 269fac4f111SVenkateswararao Jujjuri (JV) 27000ede4c2SSripathi Kodi typedef struct V9fsStatDotl { 27100ede4c2SSripathi Kodi uint64_t st_result_mask; 27200ede4c2SSripathi Kodi V9fsQID qid; 27300ede4c2SSripathi Kodi uint32_t st_mode; 27400ede4c2SSripathi Kodi uint32_t st_uid; 27500ede4c2SSripathi Kodi uint32_t st_gid; 27600ede4c2SSripathi Kodi uint64_t st_nlink; 27700ede4c2SSripathi Kodi uint64_t st_rdev; 27800ede4c2SSripathi Kodi uint64_t st_size; 27900ede4c2SSripathi Kodi uint64_t st_blksize; 28000ede4c2SSripathi Kodi uint64_t st_blocks; 28100ede4c2SSripathi Kodi uint64_t st_atime_sec; 28200ede4c2SSripathi Kodi uint64_t st_atime_nsec; 28300ede4c2SSripathi Kodi uint64_t st_mtime_sec; 28400ede4c2SSripathi Kodi uint64_t st_mtime_nsec; 28500ede4c2SSripathi Kodi uint64_t st_ctime_sec; 28600ede4c2SSripathi Kodi uint64_t st_ctime_nsec; 28700ede4c2SSripathi Kodi uint64_t st_btime_sec; 28800ede4c2SSripathi Kodi uint64_t st_btime_nsec; 28900ede4c2SSripathi Kodi uint64_t st_gen; 29000ede4c2SSripathi Kodi uint64_t st_data_version; 29100ede4c2SSripathi Kodi } V9fsStatDotl; 29200ede4c2SSripathi Kodi 293fac4f111SVenkateswararao Jujjuri (JV) typedef struct V9fsOpenState { 294fac4f111SVenkateswararao Jujjuri (JV) V9fsPDU *pdu; 295fac4f111SVenkateswararao Jujjuri (JV) size_t offset; 296771e9d4cSM. Mohan Kumar int32_t mode; 297fac4f111SVenkateswararao Jujjuri (JV) V9fsFidState *fidp; 298fac4f111SVenkateswararao Jujjuri (JV) V9fsQID qid; 299fac4f111SVenkateswararao Jujjuri (JV) struct stat stbuf; 3005e94c103SM. Mohan Kumar int iounit; 301fac4f111SVenkateswararao Jujjuri (JV) } V9fsOpenState; 302fac4f111SVenkateswararao Jujjuri (JV) 303fac4f111SVenkateswararao Jujjuri (JV) typedef struct V9fsReadState { 304fac4f111SVenkateswararao Jujjuri (JV) V9fsPDU *pdu; 305fac4f111SVenkateswararao Jujjuri (JV) size_t offset; 306fac4f111SVenkateswararao Jujjuri (JV) int32_t count; 307fac4f111SVenkateswararao Jujjuri (JV) int32_t total; 308fac4f111SVenkateswararao Jujjuri (JV) int64_t off; 309fac4f111SVenkateswararao Jujjuri (JV) V9fsFidState *fidp; 310fac4f111SVenkateswararao Jujjuri (JV) struct iovec iov[128]; /* FIXME: bad, bad, bad */ 311fac4f111SVenkateswararao Jujjuri (JV) struct iovec *sg; 312fac4f111SVenkateswararao Jujjuri (JV) off_t dir_pos; 313fac4f111SVenkateswararao Jujjuri (JV) struct dirent *dent; 314fac4f111SVenkateswararao Jujjuri (JV) struct stat stbuf; 315fac4f111SVenkateswararao Jujjuri (JV) V9fsString name; 316fac4f111SVenkateswararao Jujjuri (JV) V9fsStat v9stat; 317fac4f111SVenkateswararao Jujjuri (JV) int32_t len; 318fac4f111SVenkateswararao Jujjuri (JV) int32_t cnt; 319fac4f111SVenkateswararao Jujjuri (JV) int32_t max_count; 320fac4f111SVenkateswararao Jujjuri (JV) } V9fsReadState; 321fac4f111SVenkateswararao Jujjuri (JV) 322fac4f111SVenkateswararao Jujjuri (JV) typedef struct V9fsWriteState { 323fac4f111SVenkateswararao Jujjuri (JV) V9fsPDU *pdu; 324fac4f111SVenkateswararao Jujjuri (JV) size_t offset; 325fac4f111SVenkateswararao Jujjuri (JV) int32_t len; 326fac4f111SVenkateswararao Jujjuri (JV) int32_t count; 327fac4f111SVenkateswararao Jujjuri (JV) int32_t total; 328fac4f111SVenkateswararao Jujjuri (JV) int64_t off; 329fac4f111SVenkateswararao Jujjuri (JV) V9fsFidState *fidp; 330fac4f111SVenkateswararao Jujjuri (JV) struct iovec iov[128]; /* FIXME: bad, bad, bad */ 331fac4f111SVenkateswararao Jujjuri (JV) struct iovec *sg; 332fac4f111SVenkateswararao Jujjuri (JV) int cnt; 333fac4f111SVenkateswararao Jujjuri (JV) } V9fsWriteState; 334fac4f111SVenkateswararao Jujjuri (JV) 335c79ce737SSripathi Kodi typedef struct V9fsIattr 336c79ce737SSripathi Kodi { 337c79ce737SSripathi Kodi int32_t valid; 338c79ce737SSripathi Kodi int32_t mode; 339c79ce737SSripathi Kodi int32_t uid; 340c79ce737SSripathi Kodi int32_t gid; 341c79ce737SSripathi Kodi int64_t size; 342c79ce737SSripathi Kodi int64_t atime_sec; 343c79ce737SSripathi Kodi int64_t atime_nsec; 344c79ce737SSripathi Kodi int64_t mtime_sec; 345c79ce737SSripathi Kodi int64_t mtime_nsec; 346c79ce737SSripathi Kodi } V9fsIattr; 347c79ce737SSripathi Kodi 3489f107513SAnthony Liguori struct virtio_9p_config 3499f107513SAnthony Liguori { 3509f107513SAnthony Liguori /* number of characters in tag */ 3519f107513SAnthony Liguori uint16_t tag_len; 3529f107513SAnthony Liguori /* Variable size tag name */ 3539f107513SAnthony Liguori uint8_t tag[0]; 354541dc0d4SStefan Weil } QEMU_PACKED; 3559f107513SAnthony Liguori 3565268ceccSM. Mohan Kumar typedef struct V9fsMkState { 3575268ceccSM. Mohan Kumar V9fsPDU *pdu; 3585268ceccSM. Mohan Kumar size_t offset; 3595268ceccSM. Mohan Kumar V9fsQID qid; 3605268ceccSM. Mohan Kumar struct stat stbuf; 3615268ceccSM. Mohan Kumar V9fsString name; 3625268ceccSM. Mohan Kumar V9fsString fullname; 3635268ceccSM. Mohan Kumar } V9fsMkState; 3645268ceccSM. Mohan Kumar 3659844081bSM. Mohan Kumar /* 9p2000.L open flags */ 3669844081bSM. Mohan Kumar #define P9_DOTL_RDONLY 00000000 3679844081bSM. Mohan Kumar #define P9_DOTL_WRONLY 00000001 3689844081bSM. Mohan Kumar #define P9_DOTL_RDWR 00000002 3699844081bSM. Mohan Kumar #define P9_DOTL_NOACCESS 00000003 3709844081bSM. Mohan Kumar #define P9_DOTL_CREATE 00000100 3719844081bSM. Mohan Kumar #define P9_DOTL_EXCL 00000200 3729844081bSM. Mohan Kumar #define P9_DOTL_NOCTTY 00000400 3739844081bSM. Mohan Kumar #define P9_DOTL_TRUNC 00001000 3749844081bSM. Mohan Kumar #define P9_DOTL_APPEND 00002000 3759844081bSM. Mohan Kumar #define P9_DOTL_NONBLOCK 00004000 3769844081bSM. Mohan Kumar #define P9_DOTL_DSYNC 00010000 3779844081bSM. Mohan Kumar #define P9_DOTL_FASYNC 00020000 3789844081bSM. Mohan Kumar #define P9_DOTL_DIRECT 00040000 3799844081bSM. Mohan Kumar #define P9_DOTL_LARGEFILE 00100000 3809844081bSM. Mohan Kumar #define P9_DOTL_DIRECTORY 00200000 3819844081bSM. Mohan Kumar #define P9_DOTL_NOFOLLOW 00400000 3829844081bSM. Mohan Kumar #define P9_DOTL_NOATIME 01000000 3839844081bSM. Mohan Kumar #define P9_DOTL_CLOEXEC 02000000 3849844081bSM. Mohan Kumar #define P9_DOTL_SYNC 04000000 3859844081bSM. Mohan Kumar 3869844081bSM. Mohan Kumar /* 9p2000.L at flags */ 3879844081bSM. Mohan Kumar #define P9_DOTL_AT_REMOVEDIR 0x200 3889844081bSM. Mohan Kumar 389ea60f315SM. Mohan Kumar /* 9P2000.L lock type */ 390ea60f315SM. Mohan Kumar #define P9_LOCK_TYPE_RDLCK 0 391ea60f315SM. Mohan Kumar #define P9_LOCK_TYPE_WRLCK 1 392ea60f315SM. Mohan Kumar #define P9_LOCK_TYPE_UNLCK 2 393ea60f315SM. Mohan Kumar 39482cc3ee8SM. Mohan Kumar #define P9_LOCK_SUCCESS 0 39582cc3ee8SM. Mohan Kumar #define P9_LOCK_BLOCKED 1 39682cc3ee8SM. Mohan Kumar #define P9_LOCK_ERROR 2 39782cc3ee8SM. Mohan Kumar #define P9_LOCK_GRACE 3 39882cc3ee8SM. Mohan Kumar 39982cc3ee8SM. Mohan Kumar #define P9_LOCK_FLAGS_BLOCK 1 40082cc3ee8SM. Mohan Kumar #define P9_LOCK_FLAGS_RECLAIM 2 40182cc3ee8SM. Mohan Kumar 40282cc3ee8SM. Mohan Kumar typedef struct V9fsFlock 40382cc3ee8SM. Mohan Kumar { 40482cc3ee8SM. Mohan Kumar uint8_t type; 40582cc3ee8SM. Mohan Kumar uint32_t flags; 40682cc3ee8SM. Mohan Kumar uint64_t start; /* absolute offset */ 40782cc3ee8SM. Mohan Kumar uint64_t length; 40882cc3ee8SM. Mohan Kumar uint32_t proc_id; 40982cc3ee8SM. Mohan Kumar V9fsString client_id; 41082cc3ee8SM. Mohan Kumar } V9fsFlock; 41182cc3ee8SM. Mohan Kumar 4128f354003SM. Mohan Kumar typedef struct V9fsGetlock 4138f354003SM. Mohan Kumar { 4148f354003SM. Mohan Kumar uint8_t type; 4158f354003SM. Mohan Kumar uint64_t start; /* absolute offset */ 4168f354003SM. Mohan Kumar uint64_t length; 4178f354003SM. Mohan Kumar uint32_t proc_id; 4188f354003SM. Mohan Kumar V9fsString client_id; 4198f354003SM. Mohan Kumar } V9fsGetlock; 4208f354003SM. Mohan Kumar 4217a462745SAneesh Kumar K.V extern int open_fd_hw; 4227a462745SAneesh Kumar K.V extern int total_open_fd; 4237a462745SAneesh Kumar K.V 42464b85a8fSBlue Swirl size_t pdu_packunpack(void *addr, struct iovec *sg, int sg_count, 4259f107513SAnthony Liguori size_t offset, size_t size, int pack); 4269f107513SAnthony Liguori 4279f107513SAnthony Liguori static inline size_t do_pdu_unpack(void *dst, struct iovec *sg, int sg_count, 4289f107513SAnthony Liguori size_t offset, size_t size) 4299f107513SAnthony Liguori { 4309f107513SAnthony Liguori return pdu_packunpack(dst, sg, sg_count, offset, size, 0); 4319f107513SAnthony Liguori } 4329f107513SAnthony Liguori 433532decb7SAneesh Kumar K.V static inline void v9fs_path_write_lock(V9fsState *s) 434532decb7SAneesh Kumar K.V { 435c98f1d4aSAneesh Kumar K.V if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) { 436532decb7SAneesh Kumar K.V qemu_co_rwlock_wrlock(&s->rename_lock); 437532decb7SAneesh Kumar K.V } 438532decb7SAneesh Kumar K.V } 439532decb7SAneesh Kumar K.V 440532decb7SAneesh Kumar K.V static inline void v9fs_path_read_lock(V9fsState *s) 441532decb7SAneesh Kumar K.V { 442c98f1d4aSAneesh Kumar K.V if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) { 443532decb7SAneesh Kumar K.V qemu_co_rwlock_rdlock(&s->rename_lock); 444532decb7SAneesh Kumar K.V } 445532decb7SAneesh Kumar K.V } 446532decb7SAneesh Kumar K.V 447532decb7SAneesh Kumar K.V static inline void v9fs_path_unlock(V9fsState *s) 448532decb7SAneesh Kumar K.V { 449c98f1d4aSAneesh Kumar K.V if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) { 450532decb7SAneesh Kumar K.V qemu_co_rwlock_unlock(&s->rename_lock); 451532decb7SAneesh Kumar K.V } 452532decb7SAneesh Kumar K.V } 453532decb7SAneesh Kumar K.V 454bccacf6cSAneesh Kumar K.V static inline uint8_t v9fs_request_cancelled(V9fsPDU *pdu) 455bccacf6cSAneesh Kumar K.V { 456bccacf6cSAneesh Kumar K.V return pdu->cancelled; 457bccacf6cSAneesh Kumar K.V } 458bccacf6cSAneesh Kumar K.V 459f4f61d27SAneesh Kumar K.V extern void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq); 4607a462745SAneesh Kumar K.V extern void virtio_9p_set_fd_limit(void); 461bccacf6cSAneesh Kumar K.V extern void v9fs_reclaim_fd(V9fsPDU *pdu); 46270c18fc0SAneesh Kumar K.V extern void v9fs_string_init(V9fsString *str); 46370c18fc0SAneesh Kumar K.V extern void v9fs_string_free(V9fsString *str); 46470c18fc0SAneesh Kumar K.V extern void v9fs_string_null(V9fsString *str); 46570c18fc0SAneesh Kumar K.V extern void v9fs_string_sprintf(V9fsString *str, const char *fmt, ...); 46670c18fc0SAneesh Kumar K.V extern void v9fs_string_copy(V9fsString *lhs, V9fsString *rhs); 4672289be19SAneesh Kumar K.V extern void v9fs_path_init(V9fsPath *path); 4682289be19SAneesh Kumar K.V extern void v9fs_path_free(V9fsPath *path); 4692289be19SAneesh Kumar K.V extern void v9fs_path_copy(V9fsPath *lhs, V9fsPath *rhs); 4702289be19SAneesh Kumar K.V extern int v9fs_name_to_path(V9fsState *s, V9fsPath *dirpath, 4712289be19SAneesh Kumar K.V const char *name, V9fsPath *path); 4729f107513SAnthony Liguori #endif 473