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/9p-iov-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
;
135 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 QLIST_HEAD(, V9fsPDU
) free_list
;
209 QLIST_HEAD(, V9fsPDU
) active_list
;
210 V9fsFidState
*fid_list
;
214 enum p9_proto_version proto_version
;
217 * lock ensuring atomic path update
220 CoRwlock rename_lock
;
222 Error
*migration_blocker
;
226 /* 9p2000.L open flags */
227 #define P9_DOTL_RDONLY 00000000
228 #define P9_DOTL_WRONLY 00000001
229 #define P9_DOTL_RDWR 00000002
230 #define P9_DOTL_NOACCESS 00000003
231 #define P9_DOTL_CREATE 00000100
232 #define P9_DOTL_EXCL 00000200
233 #define P9_DOTL_NOCTTY 00000400
234 #define P9_DOTL_TRUNC 00001000
235 #define P9_DOTL_APPEND 00002000
236 #define P9_DOTL_NONBLOCK 00004000
237 #define P9_DOTL_DSYNC 00010000
238 #define P9_DOTL_FASYNC 00020000
239 #define P9_DOTL_DIRECT 00040000
240 #define P9_DOTL_LARGEFILE 00100000
241 #define P9_DOTL_DIRECTORY 00200000
242 #define P9_DOTL_NOFOLLOW 00400000
243 #define P9_DOTL_NOATIME 01000000
244 #define P9_DOTL_CLOEXEC 02000000
245 #define P9_DOTL_SYNC 04000000
247 /* 9p2000.L at flags */
248 #define P9_DOTL_AT_REMOVEDIR 0x200
250 /* 9P2000.L lock type */
251 #define P9_LOCK_TYPE_RDLCK 0
252 #define P9_LOCK_TYPE_WRLCK 1
253 #define P9_LOCK_TYPE_UNLCK 2
255 #define P9_LOCK_SUCCESS 0
256 #define P9_LOCK_BLOCKED 1
257 #define P9_LOCK_ERROR 2
258 #define P9_LOCK_GRACE 3
260 #define P9_LOCK_FLAGS_BLOCK 1
261 #define P9_LOCK_FLAGS_RECLAIM 2
263 typedef struct V9fsFlock
267 uint64_t start
; /* absolute offset */
270 V9fsString client_id
;
273 typedef struct V9fsGetlock
276 uint64_t start
; /* absolute offset */
279 V9fsString client_id
;
282 extern int open_fd_hw
;
283 extern int total_open_fd
;
285 static inline void v9fs_path_write_lock(V9fsState
*s
)
287 if (s
->ctx
.export_flags
& V9FS_PATHNAME_FSCONTEXT
) {
288 qemu_co_rwlock_wrlock(&s
->rename_lock
);
292 static inline void v9fs_path_read_lock(V9fsState
*s
)
294 if (s
->ctx
.export_flags
& V9FS_PATHNAME_FSCONTEXT
) {
295 qemu_co_rwlock_rdlock(&s
->rename_lock
);
299 static inline void v9fs_path_unlock(V9fsState
*s
)
301 if (s
->ctx
.export_flags
& V9FS_PATHNAME_FSCONTEXT
) {
302 qemu_co_rwlock_unlock(&s
->rename_lock
);
306 static inline uint8_t v9fs_request_cancelled(V9fsPDU
*pdu
)
308 return pdu
->cancelled
;
311 extern void v9fs_reclaim_fd(V9fsPDU
*pdu
);
312 extern void v9fs_path_init(V9fsPath
*path
);
313 extern void v9fs_path_free(V9fsPath
*path
);
314 extern void v9fs_path_copy(V9fsPath
*lhs
, V9fsPath
*rhs
);
315 extern int v9fs_name_to_path(V9fsState
*s
, V9fsPath
*dirpath
,
316 const char *name
, V9fsPath
*path
);
317 extern int v9fs_device_realize_common(V9fsState
*s
, Error
**errp
);
318 extern void v9fs_device_unrealize_common(V9fsState
*s
, Error
**errp
);
320 ssize_t
pdu_marshal(V9fsPDU
*pdu
, size_t offset
, const char *fmt
, ...);
321 ssize_t
pdu_unmarshal(V9fsPDU
*pdu
, size_t offset
, const char *fmt
, ...);
322 V9fsPDU
*pdu_alloc(V9fsState
*s
);
323 void pdu_free(V9fsPDU
*pdu
);
324 void pdu_submit(V9fsPDU
*pdu
);