1 #ifndef _QEMU_VIRTIO_9P_H
2 #define _QEMU_VIRTIO_9P_H
8 #include <sys/resource.h>
10 #include "standard-headers/linux/virtio_9p.h"
11 #include "hw/virtio/virtio.h"
12 #include "fsdev/file-op-9p.h"
13 #include "fsdev/virtio-9p-marshal.h"
14 #include "qemu/thread.h"
15 #include "qemu/coroutine.h"
102 enum p9_proto_version
{
103 V9FS_PROTO_2000U
= 0x01,
104 V9FS_PROTO_2000L
= 0x02,
107 #define P9_NOTAG (u16)(~0)
108 #define P9_NOFID (u32)(~0)
109 #define P9_MAXWELEM 16
111 #define FID_REFERENCED 0x1
112 #define FID_NON_RECLAIMABLE 0x2
113 static inline char *rpath(FsContext
*ctx
, const char *path
)
115 return g_strdup_printf("%s/%s", ctx
->fs_root
, path
);
119 * ample room for Twrite/Rread header
120 * size[4] Tread/Twrite tag[2] fid[4] offset[8] count[4]
122 #define P9_IOHDRSZ 24
124 typedef struct V9fsPDU V9fsPDU
;
134 VirtQueueElement elem
;
136 QLIST_ENTRY(V9fsPDU
) next
;
141 * 1) change user needs to set groups and stuff
145 #define MAX_TAG_LEN 32
147 #define BUG_ON(cond) assert(!(cond))
149 typedef struct V9fsFidState V9fsFidState
;
158 typedef struct V9fsConf
160 /* tag name for the device */
165 typedef struct V9fsXattr
175 * Filled by fs driver on open and other
178 union V9fsFidOpenState
{
183 * private pointer for fs drivers, that
184 * have its own internal representation of
196 V9fsFidOpenState fs_reclaim
;
203 V9fsFidState
*rclm_lst
;
206 typedef struct V9fsState
208 VirtIODevice parent_obj
;
210 V9fsPDU pdus
[MAX_REQ
];
211 QLIST_HEAD(, V9fsPDU
) free_list
;
212 QLIST_HEAD(, V9fsPDU
) active_list
;
213 V9fsFidState
*fid_list
;
218 enum p9_proto_version proto_version
;
221 * lock ensuring atomic path update
224 CoRwlock rename_lock
;
226 Error
*migration_blocker
;
230 /* 9p2000.L open flags */
231 #define P9_DOTL_RDONLY 00000000
232 #define P9_DOTL_WRONLY 00000001
233 #define P9_DOTL_RDWR 00000002
234 #define P9_DOTL_NOACCESS 00000003
235 #define P9_DOTL_CREATE 00000100
236 #define P9_DOTL_EXCL 00000200
237 #define P9_DOTL_NOCTTY 00000400
238 #define P9_DOTL_TRUNC 00001000
239 #define P9_DOTL_APPEND 00002000
240 #define P9_DOTL_NONBLOCK 00004000
241 #define P9_DOTL_DSYNC 00010000
242 #define P9_DOTL_FASYNC 00020000
243 #define P9_DOTL_DIRECT 00040000
244 #define P9_DOTL_LARGEFILE 00100000
245 #define P9_DOTL_DIRECTORY 00200000
246 #define P9_DOTL_NOFOLLOW 00400000
247 #define P9_DOTL_NOATIME 01000000
248 #define P9_DOTL_CLOEXEC 02000000
249 #define P9_DOTL_SYNC 04000000
251 /* 9p2000.L at flags */
252 #define P9_DOTL_AT_REMOVEDIR 0x200
254 /* 9P2000.L lock type */
255 #define P9_LOCK_TYPE_RDLCK 0
256 #define P9_LOCK_TYPE_WRLCK 1
257 #define P9_LOCK_TYPE_UNLCK 2
259 #define P9_LOCK_SUCCESS 0
260 #define P9_LOCK_BLOCKED 1
261 #define P9_LOCK_ERROR 2
262 #define P9_LOCK_GRACE 3
264 #define P9_LOCK_FLAGS_BLOCK 1
265 #define P9_LOCK_FLAGS_RECLAIM 2
267 typedef struct V9fsFlock
271 uint64_t start
; /* absolute offset */
274 V9fsString client_id
;
277 typedef struct V9fsGetlock
280 uint64_t start
; /* absolute offset */
283 V9fsString client_id
;
286 extern int open_fd_hw
;
287 extern int total_open_fd
;
289 static inline void v9fs_path_write_lock(V9fsState
*s
)
291 if (s
->ctx
.export_flags
& V9FS_PATHNAME_FSCONTEXT
) {
292 qemu_co_rwlock_wrlock(&s
->rename_lock
);
296 static inline void v9fs_path_read_lock(V9fsState
*s
)
298 if (s
->ctx
.export_flags
& V9FS_PATHNAME_FSCONTEXT
) {
299 qemu_co_rwlock_rdlock(&s
->rename_lock
);
303 static inline void v9fs_path_unlock(V9fsState
*s
)
305 if (s
->ctx
.export_flags
& V9FS_PATHNAME_FSCONTEXT
) {
306 qemu_co_rwlock_unlock(&s
->rename_lock
);
310 static inline uint8_t v9fs_request_cancelled(V9fsPDU
*pdu
)
312 return pdu
->cancelled
;
315 extern void handle_9p_output(VirtIODevice
*vdev
, VirtQueue
*vq
);
316 extern void v9fs_reclaim_fd(V9fsPDU
*pdu
);
317 extern void v9fs_path_init(V9fsPath
*path
);
318 extern void v9fs_path_free(V9fsPath
*path
);
319 extern void v9fs_path_copy(V9fsPath
*lhs
, V9fsPath
*rhs
);
320 extern int v9fs_name_to_path(V9fsState
*s
, V9fsPath
*dirpath
,
321 const char *name
, V9fsPath
*path
);
323 #define pdu_marshal(pdu, offset, fmt, args...) \
324 v9fs_marshal(pdu->elem.in_sg, pdu->elem.in_num, offset, 1, fmt, ##args)
325 #define pdu_unmarshal(pdu, offset, fmt, args...) \
326 v9fs_unmarshal(pdu->elem.out_sg, pdu->elem.out_num, offset, 1, fmt, ##args)
328 #define TYPE_VIRTIO_9P "virtio-9p-device"
329 #define VIRTIO_9P(obj) \
330 OBJECT_CHECK(V9fsState, (obj), TYPE_VIRTIO_9P)