1 #ifndef KVM__VIRTIO_9P_H 2 #define KVM__VIRTIO_9P_H 3 #include "kvm/virtio.h" 4 #include "kvm/pci.h" 5 #include "kvm/threadpool.h" 6 #include "kvm/parse-options.h" 7 8 #include <dirent.h> 9 #include <linux/list.h> 10 #include <linux/rbtree.h> 11 12 #define NUM_VIRT_QUEUES 1 13 #define VIRTQUEUE_NUM 128 14 #define VIRTIO_9P_DEFAULT_TAG "kvm_9p" 15 #define VIRTIO_9P_HDR_LEN (sizeof(u32)+sizeof(u8)+sizeof(u16)) 16 #define VIRTIO_9P_VERSION_DOTL "9P2000.L" 17 #define MAX_TAG_LEN 32 18 19 struct p9_msg { 20 u32 size; 21 u8 cmd; 22 u16 tag; 23 u8 msg[0]; 24 } __attribute__((packed)); 25 26 struct p9_fid { 27 u32 fid; 28 u32 uid; 29 char abs_path[PATH_MAX]; 30 char *path; 31 DIR *dir; 32 int fd; 33 struct rb_node node; 34 }; 35 36 struct p9_dev_job { 37 struct virt_queue *vq; 38 struct p9_dev *p9dev; 39 struct thread_pool__job job_id; 40 }; 41 42 struct p9_dev { 43 struct list_head list; 44 struct virtio_device vdev; 45 struct rb_root fids; 46 47 size_t config_size; 48 struct virtio_9p_config *config; 49 u16 tag_len; 50 51 /* virtio queue */ 52 struct virt_queue vqs[NUM_VIRT_QUEUES]; 53 struct p9_dev_job jobs[NUM_VIRT_QUEUES]; 54 char root_dir[PATH_MAX]; 55 }; 56 57 struct p9_pdu { 58 u32 queue_head; 59 size_t read_offset; 60 size_t write_offset; 61 u16 out_iov_cnt; 62 u16 in_iov_cnt; 63 struct iovec in_iov[VIRTQUEUE_NUM]; 64 struct iovec out_iov[VIRTQUEUE_NUM]; 65 }; 66 67 struct kvm; 68 69 int virtio_9p_rootdir_parser(const struct option *opt, const char *arg, int unset); 70 int virtio_9p_img_name_parser(const struct option *opt, const char *arg, int unset); 71 int virtio_9p__register(struct kvm *kvm, const char *root, const char *tag_name); 72 int virtio_9p__init(struct kvm *kvm); 73 int virtio_9p__exit(struct kvm *kvm); 74 int virtio_p9_pdu_readf(struct p9_pdu *pdu, const char *fmt, ...); 75 int virtio_p9_pdu_writef(struct p9_pdu *pdu, const char *fmt, ...); 76 77 #endif 78