1 #ifndef _QEMU_VIRTIO_9P_H
2 #define _QEMU_VIRTIO_9P_H
8 #include <sys/resource.h>
10 #include "fsdev/file-op-9p.h"
11 #include "fsdev/virtio-9p-marshal.h"
12 #include "qemu/thread.h"
13 #include "block/coroutine.h"
16 /* The feature bitmap for virtio 9P */
17 /* The mount point is specified in a config variable */
18 #define VIRTIO_9P_MOUNT_TAG 0
105 enum p9_proto_version
{
106 V9FS_PROTO_2000U
= 0x01,
107 V9FS_PROTO_2000L
= 0x02,
110 #define P9_NOTAG (u16)(~0)
111 #define P9_NOFID (u32)(~0)
112 #define P9_MAXWELEM 16
114 #define FID_REFERENCED 0x1
115 #define FID_NON_RECLAIMABLE 0x2
116 static inline const char *rpath(FsContext
*ctx
, const char *path
, char *buffer
)
118 snprintf(buffer
, PATH_MAX
, "%s/%s", ctx
->fs_root
, path
);
123 * ample room for Twrite/Rread header
124 * size[4] Tread/Twrite tag[2] fid[4] offset[8] count[4]
126 #define P9_IOHDRSZ 24
128 typedef struct V9fsPDU V9fsPDU
;
138 VirtQueueElement elem
;
140 QLIST_ENTRY(V9fsPDU
) next
;
145 * 1) change user needs to set groups and stuff
148 /* from Linux's linux/virtio_9p.h */
150 /* The ID for virtio console */
151 #define VIRTIO_ID_9P 9
153 #define MAX_TAG_LEN 32
155 #define BUG_ON(cond) assert(!(cond))
157 typedef struct V9fsFidState V9fsFidState
;
166 typedef struct V9fsXattr
176 * Filled by fs driver on open and other
179 union V9fsFidOpenState
{
184 * private pointer for fs drivers, that
185 * have its own internal representation of
197 V9fsFidOpenState fs_reclaim
;
204 V9fsFidState
*rclm_lst
;
207 typedef struct V9fsState
211 V9fsPDU pdus
[MAX_REQ
];
212 QLIST_HEAD(, V9fsPDU
) free_list
;
213 QLIST_HEAD(, V9fsPDU
) active_list
;
214 V9fsFidState
*fid_list
;
219 enum p9_proto_version proto_version
;
222 * lock ensuring atomic path update
225 CoRwlock rename_lock
;
227 Error
*migration_blocker
;
230 typedef struct V9fsStatState
{
238 typedef struct V9fsOpenState
{
248 typedef struct V9fsReadState
{
255 struct iovec iov
[128]; /* FIXME: bad, bad, bad */
267 typedef struct V9fsWriteState
{
275 struct iovec iov
[128]; /* FIXME: bad, bad, bad */
280 struct virtio_9p_config
282 /* number of characters in tag */
284 /* Variable size tag name */
288 typedef struct V9fsMkState
{
297 /* 9p2000.L open flags */
298 #define P9_DOTL_RDONLY 00000000
299 #define P9_DOTL_WRONLY 00000001
300 #define P9_DOTL_RDWR 00000002
301 #define P9_DOTL_NOACCESS 00000003
302 #define P9_DOTL_CREATE 00000100
303 #define P9_DOTL_EXCL 00000200
304 #define P9_DOTL_NOCTTY 00000400
305 #define P9_DOTL_TRUNC 00001000
306 #define P9_DOTL_APPEND 00002000
307 #define P9_DOTL_NONBLOCK 00004000
308 #define P9_DOTL_DSYNC 00010000
309 #define P9_DOTL_FASYNC 00020000
310 #define P9_DOTL_DIRECT 00040000
311 #define P9_DOTL_LARGEFILE 00100000
312 #define P9_DOTL_DIRECTORY 00200000
313 #define P9_DOTL_NOFOLLOW 00400000
314 #define P9_DOTL_NOATIME 01000000
315 #define P9_DOTL_CLOEXEC 02000000
316 #define P9_DOTL_SYNC 04000000
318 /* 9p2000.L at flags */
319 #define P9_DOTL_AT_REMOVEDIR 0x200
321 /* 9P2000.L lock type */
322 #define P9_LOCK_TYPE_RDLCK 0
323 #define P9_LOCK_TYPE_WRLCK 1
324 #define P9_LOCK_TYPE_UNLCK 2
326 #define P9_LOCK_SUCCESS 0
327 #define P9_LOCK_BLOCKED 1
328 #define P9_LOCK_ERROR 2
329 #define P9_LOCK_GRACE 3
331 #define P9_LOCK_FLAGS_BLOCK 1
332 #define P9_LOCK_FLAGS_RECLAIM 2
334 typedef struct V9fsFlock
338 uint64_t start
; /* absolute offset */
341 V9fsString client_id
;
344 typedef struct V9fsGetlock
347 uint64_t start
; /* absolute offset */
350 V9fsString client_id
;
353 extern int open_fd_hw
;
354 extern int total_open_fd
;
356 size_t pdu_packunpack(void *addr
, struct iovec
*sg
, int sg_count
,
357 size_t offset
, size_t size
, int pack
);
359 static inline size_t do_pdu_unpack(void *dst
, struct iovec
*sg
, int sg_count
,
360 size_t offset
, size_t size
)
362 return pdu_packunpack(dst
, sg
, sg_count
, offset
, size
, 0);
365 static inline void v9fs_path_write_lock(V9fsState
*s
)
367 if (s
->ctx
.export_flags
& V9FS_PATHNAME_FSCONTEXT
) {
368 qemu_co_rwlock_wrlock(&s
->rename_lock
);
372 static inline void v9fs_path_read_lock(V9fsState
*s
)
374 if (s
->ctx
.export_flags
& V9FS_PATHNAME_FSCONTEXT
) {
375 qemu_co_rwlock_rdlock(&s
->rename_lock
);
379 static inline void v9fs_path_unlock(V9fsState
*s
)
381 if (s
->ctx
.export_flags
& V9FS_PATHNAME_FSCONTEXT
) {
382 qemu_co_rwlock_unlock(&s
->rename_lock
);
386 static inline uint8_t v9fs_request_cancelled(V9fsPDU
*pdu
)
388 return pdu
->cancelled
;
391 extern void handle_9p_output(VirtIODevice
*vdev
, VirtQueue
*vq
);
392 extern void virtio_9p_set_fd_limit(void);
393 extern void v9fs_reclaim_fd(V9fsPDU
*pdu
);
394 extern void v9fs_path_init(V9fsPath
*path
);
395 extern void v9fs_path_free(V9fsPath
*path
);
396 extern void v9fs_path_copy(V9fsPath
*lhs
, V9fsPath
*rhs
);
397 extern int v9fs_name_to_path(V9fsState
*s
, V9fsPath
*dirpath
,
398 const char *name
, V9fsPath
*path
);
400 #define pdu_marshal(pdu, offset, fmt, args...) \
401 v9fs_marshal(pdu->elem.in_sg, pdu->elem.in_num, offset, 1, fmt, ##args)
402 #define pdu_unmarshal(pdu, offset, fmt, args...) \
403 v9fs_unmarshal(pdu->elem.out_sg, pdu->elem.out_num, offset, 1, fmt, ##args)