6 #include <sys/resource.h>
7 #include "fsdev/file-op-9p.h"
8 #include "fsdev/9p-iov-marshal.h"
9 #include "qemu/thread.h"
10 #include "qemu/coroutine.h"
97 enum p9_proto_version {
98 V9FS_PROTO_2000U = 0x01,
99 V9FS_PROTO_2000L = 0x02,
102 #define P9_NOTAG (u16)(~0)
103 #define P9_NOFID (u32)(~0)
104 #define P9_MAXWELEM 16
106 #define FID_REFERENCED 0x1
107 #define FID_NON_RECLAIMABLE 0x2
108 static inline char *rpath(FsContext *ctx, const char *path)
110 return g_strdup_printf("%s/%s", ctx->fs_root, path);
114 * ample room for Twrite/Rread header
115 * size[4] Tread/Twrite tag[2] fid[4] offset[8] count[4]
117 #define P9_IOHDRSZ 24
119 typedef struct V9fsPDU V9fsPDU;
130 QLIST_ENTRY(V9fsPDU) next;
136 * 1) change user needs to set groups and stuff
140 #define MAX_TAG_LEN 32
142 #define BUG_ON(cond) assert(!(cond))
144 typedef struct V9fsFidState V9fsFidState;
153 typedef struct V9fsConf
155 /* tag name for the device */
160 typedef struct V9fsXattr
170 typedef struct V9fsDir {
172 QemuMutex readdir_mutex;
175 static inline void v9fs_readdir_lock(V9fsDir *dir)
177 qemu_mutex_lock(&dir->readdir_mutex);
180 static inline void v9fs_readdir_unlock(V9fsDir *dir)
182 qemu_mutex_unlock(&dir->readdir_mutex);
185 static inline void v9fs_readdir_init(V9fsDir *dir)
187 qemu_mutex_init(&dir->readdir_mutex);
191 * Filled by fs driver on open and other
194 union V9fsFidOpenState {
199 * private pointer for fs drivers, that
200 * have its own internal representation of
212 V9fsFidOpenState fs_reclaim;
219 V9fsFidState *rclm_lst;
222 typedef struct V9fsState
224 QLIST_HEAD(, V9fsPDU) free_list;
225 QLIST_HEAD(, V9fsPDU) active_list;
226 V9fsFidState *fid_list;
230 enum p9_proto_version proto_version;
232 V9fsPDU pdus[MAX_REQ];
234 * lock ensuring atomic path update
237 CoRwlock rename_lock;
239 Error *migration_blocker;
244 /* 9p2000.L open flags */
245 #define P9_DOTL_RDONLY 00000000
246 #define P9_DOTL_WRONLY 00000001
247 #define P9_DOTL_RDWR 00000002
248 #define P9_DOTL_NOACCESS 00000003
249 #define P9_DOTL_CREATE 00000100
250 #define P9_DOTL_EXCL 00000200
251 #define P9_DOTL_NOCTTY 00000400
252 #define P9_DOTL_TRUNC 00001000
253 #define P9_DOTL_APPEND 00002000
254 #define P9_DOTL_NONBLOCK 00004000
255 #define P9_DOTL_DSYNC 00010000
256 #define P9_DOTL_FASYNC 00020000
257 #define P9_DOTL_DIRECT 00040000
258 #define P9_DOTL_LARGEFILE 00100000
259 #define P9_DOTL_DIRECTORY 00200000
260 #define P9_DOTL_NOFOLLOW 00400000
261 #define P9_DOTL_NOATIME 01000000
262 #define P9_DOTL_CLOEXEC 02000000
263 #define P9_DOTL_SYNC 04000000
265 /* 9p2000.L at flags */
266 #define P9_DOTL_AT_REMOVEDIR 0x200
268 /* 9P2000.L lock type */
269 #define P9_LOCK_TYPE_RDLCK 0
270 #define P9_LOCK_TYPE_WRLCK 1
271 #define P9_LOCK_TYPE_UNLCK 2
273 #define P9_LOCK_SUCCESS 0
274 #define P9_LOCK_BLOCKED 1
275 #define P9_LOCK_ERROR 2
276 #define P9_LOCK_GRACE 3
278 #define P9_LOCK_FLAGS_BLOCK 1
279 #define P9_LOCK_FLAGS_RECLAIM 2
281 typedef struct V9fsFlock
285 uint64_t start; /* absolute offset */
288 V9fsString client_id;
291 typedef struct V9fsGetlock
294 uint64_t start; /* absolute offset */
297 V9fsString client_id;
300 extern int open_fd_hw;
301 extern int total_open_fd;
303 static inline void v9fs_path_write_lock(V9fsState *s)
305 if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) {
306 qemu_co_rwlock_wrlock(&s->rename_lock);
310 static inline void v9fs_path_read_lock(V9fsState *s)
312 if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) {
313 qemu_co_rwlock_rdlock(&s->rename_lock);
317 static inline void v9fs_path_unlock(V9fsState *s)
319 if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) {
320 qemu_co_rwlock_unlock(&s->rename_lock);
324 static inline uint8_t v9fs_request_cancelled(V9fsPDU *pdu)
326 return pdu->cancelled;
329 void coroutine_fn v9fs_reclaim_fd(V9fsPDU *pdu);
330 void v9fs_path_init(V9fsPath *path);
331 void v9fs_path_free(V9fsPath *path);
332 void v9fs_path_sprintf(V9fsPath *path, const char *fmt, ...);
333 void v9fs_path_copy(V9fsPath *lhs, V9fsPath *rhs);
334 int v9fs_name_to_path(V9fsState *s, V9fsPath *dirpath,
335 const char *name, V9fsPath *path);
336 int v9fs_device_realize_common(V9fsState *s, Error **errp);
337 void v9fs_device_unrealize_common(V9fsState *s, Error **errp);
339 ssize_t pdu_marshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...);
340 ssize_t pdu_unmarshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...);
341 V9fsPDU *pdu_alloc(V9fsState *s);
342 void pdu_free(V9fsPDU *pdu);
343 void pdu_submit(V9fsPDU *pdu);
344 void v9fs_reset(V9fsState *s);