diff options
Diffstat (limited to 'hw/9pfs/virtio-9p.h')
-rw-r--r-- | hw/9pfs/virtio-9p.h | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h index 17d44b41ca..60b8a56e57 100644 --- a/hw/9pfs/virtio-9p.h +++ b/hw/9pfs/virtio-9p.h @@ -8,6 +8,8 @@ #include <sys/resource.h> #include "hw/virtio.h" #include "fsdev/file-op-9p.h" +#include "qemu-thread.h" +#include "qemu-coroutine.h" /* The feature bitmap for virtio 9P */ /* The mount point is specified in a config variable */ @@ -129,6 +131,8 @@ struct V9fsPDU uint32_t size; uint16_t tag; uint8_t id; + uint8_t cancelled; + CoQueue complete; VirtQueueElement elem; struct V9fsState *s; QLIST_ENTRY(V9fsPDU) next; @@ -204,7 +208,7 @@ struct V9fsFidState { int fid_type; int32_t fid; - V9fsString path; + V9fsPath path; union { int fd; DIR *dir; @@ -229,6 +233,7 @@ typedef struct V9fsState VirtQueue *vq; V9fsPDU pdus[MAX_REQ]; QLIST_HEAD(, V9fsPDU) free_list; + QLIST_HEAD(, V9fsPDU) active_list; V9fsFidState *fid_list; FileOperations *ops; FsContext ctx; @@ -237,6 +242,11 @@ typedef struct V9fsState size_t config_size; enum p9_proto_version proto_version; int32_t msize; + /* + * lock ensuring atomic path update + * on rename. + */ + CoRwlock rename_lock; } V9fsState; typedef struct V9fsStatState { @@ -381,7 +391,43 @@ static inline size_t do_pdu_unpack(void *dst, struct iovec *sg, int sg_count, return pdu_packunpack(dst, sg, sg_count, offset, size, 0); } +static inline void v9fs_path_write_lock(V9fsState *s) +{ + if (s->ctx.flags & PATHNAME_FSCONTEXT) { + qemu_co_rwlock_wrlock(&s->rename_lock); + } +} + +static inline void v9fs_path_read_lock(V9fsState *s) +{ + if (s->ctx.flags & PATHNAME_FSCONTEXT) { + qemu_co_rwlock_rdlock(&s->rename_lock); + } +} + +static inline void v9fs_path_unlock(V9fsState *s) +{ + if (s->ctx.flags & PATHNAME_FSCONTEXT) { + qemu_co_rwlock_unlock(&s->rename_lock); + } +} + +static inline uint8_t v9fs_request_cancelled(V9fsPDU *pdu) +{ + return pdu->cancelled; +} + extern void handle_9p_output(VirtIODevice *vdev, VirtQueue *vq); extern void virtio_9p_set_fd_limit(void); -extern void v9fs_reclaim_fd(V9fsState *s); +extern void v9fs_reclaim_fd(V9fsPDU *pdu); +extern void v9fs_string_init(V9fsString *str); +extern void v9fs_string_free(V9fsString *str); +extern void v9fs_string_null(V9fsString *str); +extern void v9fs_string_sprintf(V9fsString *str, const char *fmt, ...); +extern void v9fs_string_copy(V9fsString *lhs, V9fsString *rhs); +extern void v9fs_path_init(V9fsPath *path); +extern void v9fs_path_free(V9fsPath *path); +extern void v9fs_path_copy(V9fsPath *lhs, V9fsPath *rhs); +extern int v9fs_name_to_path(V9fsState *s, V9fsPath *dirpath, + const char *name, V9fsPath *path); #endif |