6 #include <sys/resource.h>
8 #include "standard-headers/linux/virtio_9p.h"
9 #include "hw/virtio/virtio.h"
10 #include "fsdev/file-op-9p.h"
11 #include "fsdev/9p-iov-marshal.h"
12 #include "qemu/thread.h"
13 #include "qemu/coroutine.h"
100 enum p9_proto_version
{
101 V9FS_PROTO_2000U
= 0x01,
102 V9FS_PROTO_2000L
= 0x02,
105 #define P9_NOTAG (u16)(~0)
106 #define P9_NOFID (u32)(~0)
107 #define P9_MAXWELEM 16
109 #define FID_REFERENCED 0x1
110 #define FID_NON_RECLAIMABLE 0x2
111 static inline char *rpath(FsContext
*ctx
, const char *path
)
113 return g_strdup_printf("%s/%s", ctx
->fs_root
, path
);
117 * ample room for Twrite/Rread header
118 * size[4] Tread/Twrite tag[2] fid[4] offset[8] count[4]
120 #define P9_IOHDRSZ 24
122 typedef struct V9fsPDU V9fsPDU
;
133 QLIST_ENTRY(V9fsPDU
) next
;
139 * 1) change user needs to set groups and stuff
143 #define MAX_TAG_LEN 32
145 #define BUG_ON(cond) assert(!(cond))
147 typedef struct V9fsFidState V9fsFidState
;
156 typedef struct V9fsConf
158 /* tag name for the device */
163 typedef struct V9fsXattr
173 * Filled by fs driver on open and other
176 union V9fsFidOpenState
{
181 * private pointer for fs drivers, that
182 * have its own internal representation of
194 V9fsFidOpenState fs_reclaim
;
201 V9fsFidState
*rclm_lst
;
204 typedef struct V9fsState
206 QLIST_HEAD(, V9fsPDU
) free_list
;
207 QLIST_HEAD(, V9fsPDU
) active_list
;
208 V9fsFidState
*fid_list
;
212 enum p9_proto_version proto_version
;
215 * lock ensuring atomic path update
218 CoRwlock rename_lock
;
220 Error
*migration_blocker
;
224 /* 9p2000.L open flags */
225 #define P9_DOTL_RDONLY 00000000
226 #define P9_DOTL_WRONLY 00000001
227 #define P9_DOTL_RDWR 00000002
228 #define P9_DOTL_NOACCESS 00000003
229 #define P9_DOTL_CREATE 00000100
230 #define P9_DOTL_EXCL 00000200
231 #define P9_DOTL_NOCTTY 00000400
232 #define P9_DOTL_TRUNC 00001000
233 #define P9_DOTL_APPEND 00002000
234 #define P9_DOTL_NONBLOCK 00004000
235 #define P9_DOTL_DSYNC 00010000
236 #define P9_DOTL_FASYNC 00020000
237 #define P9_DOTL_DIRECT 00040000
238 #define P9_DOTL_LARGEFILE 00100000
239 #define P9_DOTL_DIRECTORY 00200000
240 #define P9_DOTL_NOFOLLOW 00400000
241 #define P9_DOTL_NOATIME 01000000
242 #define P9_DOTL_CLOEXEC 02000000
243 #define P9_DOTL_SYNC 04000000
245 /* 9p2000.L at flags */
246 #define P9_DOTL_AT_REMOVEDIR 0x200
248 /* 9P2000.L lock type */
249 #define P9_LOCK_TYPE_RDLCK 0
250 #define P9_LOCK_TYPE_WRLCK 1
251 #define P9_LOCK_TYPE_UNLCK 2
253 #define P9_LOCK_SUCCESS 0
254 #define P9_LOCK_BLOCKED 1
255 #define P9_LOCK_ERROR 2
256 #define P9_LOCK_GRACE 3
258 #define P9_LOCK_FLAGS_BLOCK 1
259 #define P9_LOCK_FLAGS_RECLAIM 2
261 typedef struct V9fsFlock
265 uint64_t start
; /* absolute offset */
268 V9fsString client_id
;
271 typedef struct V9fsGetlock
274 uint64_t start
; /* absolute offset */
277 V9fsString client_id
;
280 extern int open_fd_hw
;
281 extern int total_open_fd
;
283 static inline void v9fs_path_write_lock(V9fsState
*s
)
285 if (s
->ctx
.export_flags
& V9FS_PATHNAME_FSCONTEXT
) {
286 qemu_co_rwlock_wrlock(&s
->rename_lock
);
290 static inline void v9fs_path_read_lock(V9fsState
*s
)
292 if (s
->ctx
.export_flags
& V9FS_PATHNAME_FSCONTEXT
) {
293 qemu_co_rwlock_rdlock(&s
->rename_lock
);
297 static inline void v9fs_path_unlock(V9fsState
*s
)
299 if (s
->ctx
.export_flags
& V9FS_PATHNAME_FSCONTEXT
) {
300 qemu_co_rwlock_unlock(&s
->rename_lock
);
304 static inline uint8_t v9fs_request_cancelled(V9fsPDU
*pdu
)
306 return pdu
->cancelled
;
309 extern void v9fs_reclaim_fd(V9fsPDU
*pdu
);
310 extern void v9fs_path_init(V9fsPath
*path
);
311 extern void v9fs_path_free(V9fsPath
*path
);
312 extern void v9fs_path_copy(V9fsPath
*lhs
, V9fsPath
*rhs
);
313 extern int v9fs_name_to_path(V9fsState
*s
, V9fsPath
*dirpath
,
314 const char *name
, V9fsPath
*path
);
315 extern int v9fs_device_realize_common(V9fsState
*s
, Error
**errp
);
316 extern void v9fs_device_unrealize_common(V9fsState
*s
, Error
**errp
);
318 ssize_t
pdu_marshal(V9fsPDU
*pdu
, size_t offset
, const char *fmt
, ...);
319 ssize_t
pdu_unmarshal(V9fsPDU
*pdu
, size_t offset
, const char *fmt
, ...);
320 V9fsPDU
*pdu_alloc(V9fsState
*s
);
321 void pdu_free(V9fsPDU
*pdu
);
322 void pdu_submit(V9fsPDU
*pdu
);