Skip to contentSkip to conversation

virtio-9p: paravirtual filesystem passthrough

RFC PATCH In review Anthony Liguori 6 participants 28 messages Mar 3, 2010 – Mar 11, 2010 Kbuild

lore
Share & tools
lore
#0 lore raw

cover virtio-9p: paravirtual filesystem passthrough

This patch series adds a paravirtual file system passthrough mechanism to QEMU based on the 9P protocol. This an RFC series with a few known issues. Right now, all I/O is implemented in the VCPU thread. We've modified the protocol handlers so that we can support dispatch I/O in a thread pool but we wanted to send out the series for initial review before completing that work.

We also do not have a very good mechanism for specifying the share path. Suggestions would be welcome here.

This patch set should work with any recent Linux kernel as virtio-9p has been supported for a few kernel releases now.

#1 lore raw

PATCH 1/17 vitio-9p: Add a virtio 9p device to qemu

This patch doesn't implement the 9p protocol handling code. It add a simple device which dump the protocl data

---
 Makefile.target      |    1 +
 hw/virtio-9p-debug.c |  442 ++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/virtio-9p.c       |  275 +++++++++++++++++++++++++++++++
 hw/virtio-9p.h       |   70 ++++++++
 hw/virtio-pci.c      |   25 +++
 hw/virtio.h          |    1 +
 6 files changed, 814 insertions(+), 0 deletions(-)
 create mode 100644 hw/virtio-9p-debug.c
 create mode 100644 hw/virtio-9p.c
 create mode 100644 hw/virtio-9p.h
Makefile.target +1 -0
index 4c4d397..8f240ea 100644
@@ -173,6 +173,7 @@ obj-y = vl.o async.o monitor.o pci.o pci_host.o pcie_host.o machine.o gdbstub.o
 # virtio has to be here due to weird dependency between PCI and virtio-net.
 # need to fix this properly
 obj-y += virtio-blk.o virtio-balloon.o virtio-net.o virtio-pci.o virtio-serial-bus.o
+obj-y += virtio-9p.o virtio-9p-debug.o
 obj-y += rwhandler.o
 obj-$(CONFIG_KVM) += kvm.o kvm-all.o
 obj-$(CONFIG_ISA_MMIO) += isa_mmio.o
hw/virtio-9p-debug.c new file +442 -0

442 lines not on this page · raw message

hw/virtio-9p.c new file +275 -0

275 lines not on this page · raw message

hw/virtio-9p.h new file +70 -0

70 lines not on this page · raw message

hw/virtio-pci.c +25 -0
index bcd40f7..f837376 100644
@@ -96,6 +96,7 @@ typedef struct {
     BlockConf block;
     NICConf nic;
     uint32_t host_features;
+    char *share_path;
     /* Max. number of ports we can have for a the virtio-serial device */
     uint32_t max_virtserial_ports;
 } VirtIOPCIProxy;
@@ -551,6 +552,21 @@ static int virtio_balloon_init_pci(PCIDevice *pci_dev)
     return 0;
 }
 
+static int virtio_9p_init_pci(PCIDevice *pci_dev)
+{
+    VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
+    VirtIODevice *vdev;
+
+    vdev = virtio_9p_init(&pci_dev->qdev, proxy->share_path);
+    virtio_init_pci(proxy, vdev,
+		    PCI_VENDOR_ID_REDHAT_QUMRANET,
+		    0x1009,
+		    0x2,
+		    0x00);
+
+    return 0;
+}
+
 static PCIDeviceInfo virtio_info[] = {
     {
         .qdev.name = "virtio-blk-pci",
@@ -604,6 +620,15 @@ static PCIDeviceInfo virtio_info[] = {
         },
         .qdev.reset = virtio_pci_reset,
     },{
+        .qdev.name = "virtio-9p-pci",
+        .qdev.size = sizeof(VirtIOPCIProxy),
+        .init      = virtio_9p_init_pci,
+        .qdev.props = (Property[]) {
+            DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
+            DEFINE_PROP_STRING("share_path", VirtIOPCIProxy, share_path),
+            DEFINE_PROP_END_OF_LIST(),
+        },
+    },{
         /* end of list */
     }
 };
hw/virtio.h +1 -0
index 3baa2a3..4032a96 100644
@@ -174,6 +174,7 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf);
 VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf);
 VirtIODevice *virtio_serial_init(DeviceState *dev, uint32_t max_nr_ports);
 VirtIODevice *virtio_balloon_init(DeviceState *dev);
+VirtIODevice *virtio_9p_init(DeviceState *dev, const char *path);
 
 void virtio_net_exit(VirtIODevice *vdev);
 
Signature · 1 line
1.6.5.2
#2 lore raw

PATCH 2/17 vrtio-9p: Implement P9_TVERSION for 9P

In reply to Anthony Liguori

[[email protected]: malloc to qemu_malloc coversion]

---
 hw/virtio-9p.c |  263 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 262 insertions(+), 1 deletions(-)
hw/virtio-9p.c +262 -1
index 93402c5..a057fbb 100644
@@ -111,10 +111,271 @@ static void free_pdu(V9fsState *s, V9fsPDU *pdu)
     }
 }
 
-static void v9fs_version(V9fsState *s, V9fsPDU *pdu)
+static void v9fs_string_free(V9fsString *str)
+{
+    free(str->data);
+    str->data = NULL;
+    str->size = 0;
+}
+
+static size_t pdu_unpack(void *dst, V9fsPDU *pdu, size_t offset, size_t size)
+{
+    struct iovec *sg = pdu->elem.out_sg;
+    BUG_ON((offset + size) > sg[0].iov_len);
+    memcpy(dst, sg[0].iov_base + offset, size);
+    return size;
+}
+
+/* FIXME i can do this with less variables */
+static size_t pdu_pack(V9fsPDU *pdu, size_t offset, const void *src, size_t size)
+{
+    struct iovec *sg = pdu->elem.in_sg;
+    size_t off = 0;
+    size_t copied = 0;
+    int i = 0;
+
+    for (i = 0; size && i < pdu->elem.in_num; i++) {
+	size_t len;
+
+	if (offset >= off && offset < (off + sg[i].iov_len)) {
+	    len = MIN(sg[i].iov_len - (offset - off), size);
+	    memcpy(sg[i].iov_base + (offset - off), src, len);
+	    size -= len;
+	    offset += len;
+	    off = offset;
+	    copied += len;
+	    src += len;
+	} else
+	    off += sg[i].iov_len;
+    }
+
+    return copied;
+}
+
+static int pdu_copy_sg(V9fsPDU *pdu, size_t offset, int rx, struct iovec *sg)
+{
+    size_t pos = 0;
+    int i, j;
+    struct iovec *src_sg;
+    unsigned int num;
+
+    if (rx) {
+	    src_sg = pdu->elem.in_sg;
+	    num = pdu->elem.in_num;
+    } else {
+	    src_sg = pdu->elem.out_sg;
+	    num = pdu->elem.out_num;
+    }
+
+    j = 0;
+    for (i = 0; i < num; i++) {
+	if (offset <= pos) {
+	    sg[j].iov_base = src_sg[i].iov_base;
+	    sg[j].iov_len = src_sg[i].iov_len;
+	    j++;
+	} else if (offset < (src_sg[i].iov_len + pos)) {
+	    sg[j].iov_base = src_sg[i].iov_base;
+	    sg[j].iov_len = src_sg[i].iov_len;
+	    sg[j].iov_base += (offset - pos);
+	    sg[j].iov_len -= (offset - pos);
+	    j++;
+	}
+	pos += src_sg[i].iov_len;
+    }
+
+    return j;
+}
+
+static size_t pdu_unmarshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...)
+{
+    size_t old_offset = offset;
+    va_list ap;
+    int i;
+
+    va_start(ap, fmt);
+    for (i = 0; fmt[i]; i++) {
+	switch (fmt[i]) {
+	case 'b': {
+	    int8_t *valp = va_arg(ap, int8_t *);
+	    offset += pdu_unpack(valp, pdu, offset, sizeof(*valp));
+	    break;
+	}
+	case 'w': {
+	    int16_t *valp = va_arg(ap, int16_t *);
+	    offset += pdu_unpack(valp, pdu, offset, sizeof(*valp));
+	    break;
+	}
+	case 'd': {
+	    int32_t *valp = va_arg(ap, int32_t *);
+	    offset += pdu_unpack(valp, pdu, offset, sizeof(*valp));
+	    break;
+	}
+	case 'q': {
+	    int64_t *valp = va_arg(ap, int64_t *);
+	    offset += pdu_unpack(valp, pdu, offset, sizeof(*valp));
+	    break;
+	}
+	case 'v': {
+	    struct iovec *iov = va_arg(ap, struct iovec *);
+	    int *iovcnt = va_arg(ap, int *);
+	    *iovcnt = pdu_copy_sg(pdu, offset, 0, iov);
+	    break;
+	}
+	case 's': {
+	    V9fsString *str = va_arg(ap, V9fsString *);
+	    offset += pdu_unmarshal(pdu, offset, "w", &str->size);
+	    /* FIXME: sanity check str->size */
+	    str->data = qemu_malloc(str->size + 1);
+	    offset += pdu_unpack(str->data, pdu, offset, str->size);
+	    str->data[str->size] = 0;
+	    break;
+	}
+	case 'Q': {
+	    V9fsQID *qidp = va_arg(ap, V9fsQID *);
+	    offset += pdu_unmarshal(pdu, offset, "bdq",
+				    &qidp->type, &qidp->version, &qidp->path);
+	    break;
+	}
+	case 'S': {
+	    V9fsStat *statp = va_arg(ap, V9fsStat *);
+	    offset += pdu_unmarshal(pdu, offset, "wwdQdddqsssssddd",
+				    &statp->size, &statp->type, &statp->dev,
+				    &statp->qid, &statp->mode, &statp->atime,
+				    &statp->mtime, &statp->length,
+				    &statp->name, &statp->uid, &statp->gid,
+				    &statp->muid, &statp->extension,
+				    &statp->n_uid, &statp->n_gid,
+				    &statp->n_muid);
+	    break;
+	}
+	default:
+	    break;
+	}
+    }
+
+    va_end(ap);
+
+    return offset - old_offset;
+}
+
+static size_t pdu_marshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...)
 {
+    size_t old_offset = offset;
+    va_list ap;
+    int i;
+
+    va_start(ap, fmt);
+    for (i = 0; fmt[i]; i++) {
+	switch (fmt[i]) {
+	case 'b': {
+	    int8_t val = va_arg(ap, int);
+	    offset += pdu_pack(pdu, offset, &val, sizeof(val));
+	    break;
+	}
+	case 'w': {
+	    int16_t val = va_arg(ap, int);
+	    offset += pdu_pack(pdu, offset, &val, sizeof(val));
+	    break;
+	}
+	case 'd': {
+	    int32_t val = va_arg(ap, int);
+	    offset += pdu_pack(pdu, offset, &val, sizeof(val));
+	    break;
+	}
+	case 'q': {
+	    int64_t val = va_arg(ap, int64_t);
+	    offset += pdu_pack(pdu, offset, &val, sizeof(val));
+	    break;
+	}
+	case 'v': {
+	    struct iovec *iov = va_arg(ap, struct iovec *);
+	    int *iovcnt = va_arg(ap, int *);
+	    *iovcnt = pdu_copy_sg(pdu, offset, 1, iov);
+	    break;
+	}
+	case 's': {
+	    V9fsString *str = va_arg(ap, V9fsString *);
+	    offset += pdu_marshal(pdu, offset, "w", str->size);
+	    offset += pdu_pack(pdu, offset, str->data, str->size);
+	    break;
+	}
+	case 'Q': {
+	    V9fsQID *qidp = va_arg(ap, V9fsQID *);
+	    offset += pdu_marshal(pdu, offset, "bdq",
+				  qidp->type, qidp->version, qidp->path);
+	    break;
+	}
+	case 'S': {
+	    V9fsStat *statp = va_arg(ap, V9fsStat *);
+	    offset += pdu_marshal(pdu, offset, "wwdQdddqsssssddd",
+				  statp->size, statp->type, statp->dev,
+				  &statp->qid, statp->mode, statp->atime,
+				  statp->mtime, statp->length, &statp->name,
+				  &statp->uid, &statp->gid, &statp->muid,
+				  &statp->extension, statp->n_uid,
+				  statp->n_gid, statp->n_muid);
+	    break;
+	}
+	default:
+	    break;
+	}
+    }
+    va_end(ap);
+
+    return offset - old_offset;
+}
+
+static void complete_pdu(V9fsState *s, V9fsPDU *pdu, ssize_t len)
+{
+    int8_t id = pdu->id + 1; /* Response */
+
+    if (len < 0) {
+	V9fsString str;
+	int err = -len;
+
+	str.data = strerror(err);
+	str.size = strlen(str.data);
+
+	len = 7;
+	len += pdu_marshal(pdu, len, "s", &str);
+	if (dotu)
+	    len += pdu_marshal(pdu, len, "d", err);
+
+	id = P9_RERROR;
+    }
+
+    /* fill out the header */
+    pdu_marshal(pdu, 0, "dbw", (int32_t)len, id, pdu->tag);
+
+    /* keep these in sync */
+    pdu->size = len;
+    pdu->id = id;
+
     if (debug_9p_pdu)
 	pprint_pdu(pdu);
+
+    /* push onto queue and notify */
+    virtqueue_push(s->vq, &pdu->elem, len);
+
+    /* FIXME: we should batch these completions */
+    virtio_notify(&s->vdev, s->vq);
+
+    free_pdu(s, pdu);
+}
+
+static void v9fs_version(V9fsState *s, V9fsPDU *pdu)
+{
+    int32_t msize;
+    V9fsString version;
+    size_t offset = 7;
+
+    pdu_unmarshal(pdu, offset, "ds", &msize, &version);
+    BUG_ON(strcmp(version.data, "9P2000.u") != 0);
+
+    offset += pdu_marshal(pdu, offset, "ds", msize, &version);
+    complete_pdu(s, pdu, offset);
+
+    v9fs_string_free(&version);
 }
 
 static void v9fs_attach(V9fsState *s, V9fsPDU *pdu)
Signature · 1 line
1.6.5.2
#3 lore raw

[Qemu-devel] Re: [PATCH 02/17] vrtio-9p: Implement P9_TVERSION for 9P

Quoted 24 lines · Anthony Liguori

[[email protected]: malloc to qemu_malloc coversion]

---
 hw/virtio-9p.c |  263 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 262 insertions(+), 1 deletions(-)
hw/virtio-9p.c +7 -1
index 93402c5..a057fbb 100644
@@ -111,10 +111,271 @@ static void free_pdu(V9fsState *s, V9fsPDU *pdu)
     }
 }
 
-static void v9fs_version(V9fsState *s, V9fsPDU *pdu)
+static void v9fs_string_free(V9fsString *str)
+{
+    free(str->data);
+    str->data = NULL;
+    str->size = 0;
+}
+

hw/virtio-9p.c static void free_pdu(V9fsState *s, V9fsPDU *pdu) · line 130

Quoted 10 lines
hw/virtio-9p.c +10 -0
+static size_t pdu_unpack(void *dst, V9fsPDU *pdu, size_t offset, size_t size)
+{
+    struct iovec *sg = pdu->elem.out_sg;
+    BUG_ON((offset + size) > sg[0].iov_len);
+    memcpy(dst, sg[0].iov_base + offset, size);
+    return size;
+}
+
+/* FIXME i can do this with less variables */
+static size_t pdu_pack(V9fsPDU *pdu, size_t offset, const void *src, size_t size)

Is the point of this functuion to copy size bytes starting at offset? Maybe generalize this to work on any iovec?

hw/virtio-9p.c static void free_pdu(V9fsState *s, V9fsPDU *pdu) · line 138

Quoted 8 lines
hw/virtio-9p.c +8 -0
+{
+    struct iovec *sg = pdu->elem.in_sg;
+    size_t off = 0;
+    size_t copied = 0;
+    int i = 0;
+
+    for (i = 0; size && i < pdu->elem.in_num; i++) {
+	size_t len;

indentation by tabs.

hw/virtio-9p.c static void free_pdu(V9fsState *s, V9fsPDU *pdu) · line 140

Quoted 2 lines
hw/virtio-9p.c +2 -0
+
+	if (offset >= off && offset < (off + sg[i].iov_len)) {

The above math might overflow. Not sure what the result will be.

hw/virtio-9p.c static void free_pdu(V9fsState *s, V9fsPDU *pdu) · line 149

Quoted 9 lines
hw/virtio-9p.c +9 -0
+	    len = MIN(sg[i].iov_len - (offset - off), size);
+	    memcpy(sg[i].iov_base + (offset - off), src, len);
+	    size -= len;
+	    offset += len;
+	    off = offset;
+	    copied += len;
+	    src += len;
+	} else
+	    off += sg[i].iov_len;

{}

hw/virtio-9p.c static void free_pdu(V9fsState *s, V9fsPDU *pdu) · line 156

Quoted 7 lines
hw/virtio-9p.c +7 -0
+    }
+
+    return copied;
+}
+
+static int pdu_copy_sg(V9fsPDU *pdu, size_t offset, int rx, struct iovec *sg)
+{

Maybe generalize this to work on any iovec?

Quoted 229 lines
hw/virtio-9p.c +219 -0
+    size_t pos = 0;
+    int i, j;
+    struct iovec *src_sg;
+    unsigned int num;
+
+    if (rx) {
+	    src_sg = pdu->elem.in_sg;
+	    num = pdu->elem.in_num;
+    } else {
+	    src_sg = pdu->elem.out_sg;
+	    num = pdu->elem.out_num;
+    }
+
+    j = 0;
+    for (i = 0; i < num; i++) {
+	if (offset <= pos) {
+	    sg[j].iov_base = src_sg[i].iov_base;
+	    sg[j].iov_len = src_sg[i].iov_len;
+	    j++;
+	} else if (offset < (src_sg[i].iov_len + pos)) {
+	    sg[j].iov_base = src_sg[i].iov_base;
+	    sg[j].iov_len = src_sg[i].iov_len;
+	    sg[j].iov_base += (offset - pos);
+	    sg[j].iov_len -= (offset - pos);
+	    j++;
+	}
+	pos += src_sg[i].iov_len;
+    }
+
+    return j;
+}
+
+static size_t pdu_unmarshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...)
+{
+    size_t old_offset = offset;
+    va_list ap;
+    int i;
+
+    va_start(ap, fmt);
+    for (i = 0; fmt[i]; i++) {
+	switch (fmt[i]) {
+	case 'b': {
+	    int8_t *valp = va_arg(ap, int8_t *);
+	    offset += pdu_unpack(valp, pdu, offset, sizeof(*valp));
+	    break;
+	}
+	case 'w': {
+	    int16_t *valp = va_arg(ap, int16_t *);
+	    offset += pdu_unpack(valp, pdu, offset, sizeof(*valp));
+	    break;
+	}
+	case 'd': {
+	    int32_t *valp = va_arg(ap, int32_t *);
+	    offset += pdu_unpack(valp, pdu, offset, sizeof(*valp));
+	    break;
+	}
+	case 'q': {
+	    int64_t *valp = va_arg(ap, int64_t *);
+	    offset += pdu_unpack(valp, pdu, offset, sizeof(*valp));
+	    break;
+	}
+	case 'v': {
+	    struct iovec *iov = va_arg(ap, struct iovec *);
+	    int *iovcnt = va_arg(ap, int *);
+	    *iovcnt = pdu_copy_sg(pdu, offset, 0, iov);
+	    break;
+	}
+	case 's': {
+	    V9fsString *str = va_arg(ap, V9fsString *);
+	    offset += pdu_unmarshal(pdu, offset, "w", &str->size);
+	    /* FIXME: sanity check str->size */
+	    str->data = qemu_malloc(str->size + 1);
+	    offset += pdu_unpack(str->data, pdu, offset, str->size);
+	    str->data[str->size] = 0;
+	    break;
+	}
+	case 'Q': {
+	    V9fsQID *qidp = va_arg(ap, V9fsQID *);
+	    offset += pdu_unmarshal(pdu, offset, "bdq",
+				    &qidp->type, &qidp->version, &qidp->path);
+	    break;
+	}
+	case 'S': {
+	    V9fsStat *statp = va_arg(ap, V9fsStat *);
+	    offset += pdu_unmarshal(pdu, offset, "wwdQdddqsssssddd",
+				    &statp->size, &statp->type, &statp->dev,
+				    &statp->qid, &statp->mode, &statp->atime,
+				    &statp->mtime, &statp->length,
+				    &statp->name, &statp->uid, &statp->gid,
+				    &statp->muid, &statp->extension,
+				    &statp->n_uid, &statp->n_gid,
+				    &statp->n_muid);
+	    break;
+	}
+	default:
+	    break;
+	}
+    }
+
+    va_end(ap);
+
+    return offset - old_offset;
+}
+
+static size_t pdu_marshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...)
 {
+    size_t old_offset = offset;
+    va_list ap;
+    int i;
+
+    va_start(ap, fmt);
+    for (i = 0; fmt[i]; i++) {
+	switch (fmt[i]) {
+	case 'b': {
+	    int8_t val = va_arg(ap, int);
+	    offset += pdu_pack(pdu, offset, &val, sizeof(val));
+	    break;
+	}
+	case 'w': {
+	    int16_t val = va_arg(ap, int);
+	    offset += pdu_pack(pdu, offset, &val, sizeof(val));
+	    break;
+	}
+	case 'd': {
+	    int32_t val = va_arg(ap, int);
+	    offset += pdu_pack(pdu, offset, &val, sizeof(val));
+	    break;
+	}
+	case 'q': {
+	    int64_t val = va_arg(ap, int64_t);
+	    offset += pdu_pack(pdu, offset, &val, sizeof(val));
+	    break;
+	}
+	case 'v': {
+	    struct iovec *iov = va_arg(ap, struct iovec *);
+	    int *iovcnt = va_arg(ap, int *);
+	    *iovcnt = pdu_copy_sg(pdu, offset, 1, iov);
+	    break;
+	}
+	case 's': {
+	    V9fsString *str = va_arg(ap, V9fsString *);
+	    offset += pdu_marshal(pdu, offset, "w", str->size);
+	    offset += pdu_pack(pdu, offset, str->data, str->size);
+	    break;
+	}
+	case 'Q': {
+	    V9fsQID *qidp = va_arg(ap, V9fsQID *);
+	    offset += pdu_marshal(pdu, offset, "bdq",
+				  qidp->type, qidp->version, qidp->path);
+	    break;
+	}
+	case 'S': {
+	    V9fsStat *statp = va_arg(ap, V9fsStat *);
+	    offset += pdu_marshal(pdu, offset, "wwdQdddqsssssddd",
+				  statp->size, statp->type, statp->dev,
+				  &statp->qid, statp->mode, statp->atime,
+				  statp->mtime, statp->length, &statp->name,
+				  &statp->uid, &statp->gid, &statp->muid,
+				  &statp->extension, statp->n_uid,
+				  statp->n_gid, statp->n_muid);
+	    break;
+	}
+	default:
+	    break;
+	}
+    }
+    va_end(ap);
+
+    return offset - old_offset;
+}
+
+static void complete_pdu(V9fsState *s, V9fsPDU *pdu, ssize_t len)
+{
+    int8_t id = pdu->id + 1; /* Response */
+
+    if (len < 0) {
+	V9fsString str;
+	int err = -len;
+
+	str.data = strerror(err);
+	str.size = strlen(str.data);
+
+	len = 7;
+	len += pdu_marshal(pdu, len, "s", &str);
+	if (dotu)
+	    len += pdu_marshal(pdu, len, "d", err);
+
+	id = P9_RERROR;
+    }
+
+    /* fill out the header */
+    pdu_marshal(pdu, 0, "dbw", (int32_t)len, id, pdu->tag);
+
+    /* keep these in sync */
+    pdu->size = len;
+    pdu->id = id;
+
     if (debug_9p_pdu)
 	pprint_pdu(pdu);
+
+    /* push onto queue and notify */
+    virtqueue_push(s->vq, &pdu->elem, len);
+
+    /* FIXME: we should batch these completions */
+    virtio_notify(&s->vdev, s->vq);
+
+    free_pdu(s, pdu);
+}
+
+static void v9fs_version(V9fsState *s, V9fsPDU *pdu)
+{
+    int32_t msize;
+    V9fsString version;
+    size_t offset = 7;
+
+    pdu_unmarshal(pdu, offset, "ds", &msize, &version);
+    BUG_ON(strcmp(version.data, "9P2000.u") != 0);
+
+    offset += pdu_marshal(pdu, offset, "ds", msize, &version);
+    complete_pdu(s, pdu, offset);
+
+    v9fs_string_free(&version);
 }
 
 static void v9fs_attach(V9fsState *s, V9fsPDU *pdu)
Signature · 1 line
1.6.5.2
#4 lore raw

[Qemu-devel] Re: [PATCH 02/17] vrtio-9p: Implement P9_TVERSION for 9P

Quoted 30 lines · Michael S. Tsirkin
Quoted 29 lines · Anthony Liguori

[[email protected]: malloc to qemu_malloc coversion]

---
 hw/virtio-9p.c |  263 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 262 insertions(+), 1 deletions(-)
hw/virtio-9p.c +12 -1
index 93402c5..a057fbb 100644
@@ -111,10 +111,271 @@ static void free_pdu(V9fsState *s, V9fsPDU *pdu)
     }
 }
 
-static void v9fs_version(V9fsState *s, V9fsPDU *pdu)
+static void v9fs_string_free(V9fsString *str)
+{
+    free(str->data);
+    str->data = NULL;
+    str->size = 0;
+}
+
+static size_t pdu_unpack(void *dst, V9fsPDU *pdu, size_t offset, size_t size)
+{
+    struct iovec *sg = pdu->elem.out_sg;
+    BUG_ON((offset + size) > sg[0].iov_len);
+    memcpy(dst, sg[0].iov_base + offset, size);
Quoted 8 lines

hw/virtio-9p.c static void free_pdu(V9fsState *s, V9fsPDU *pdu) · line 130

Quoted 5 lines
hw/virtio-9p.c +5 -0
+    return size;
+}
+
+/* FIXME i can do this with less variables */
+static size_t pdu_pack(V9fsPDU *pdu, size_t offset, const void *src, size_t size)

Is the point of this functuion to copy size bytes starting at offset? Maybe generalize this to work on any iovec?

The 9p debug code also need a similar function. I have a bug fix patch that make sure we use all the elem.out_num elements in elem.out_sg array. That patch already does abstract this out for any iovec. But still keep the function in virtio-9p.c.

Quoted 11 lines

hw/virtio-9p.c static void free_pdu(V9fsState *s, V9fsPDU *pdu) · line 138

Quoted 9 lines
hw/virtio-9p.c +8 -0
+{
+    struct iovec *sg = pdu->elem.in_sg;
+    size_t off = 0;
+    size_t copied = 0;
+    int i = 0;
+
+    for (i = 0; size && i < pdu->elem.in_num; i++) {
+	size_t len;

indentation by tabs.

Fixed

Quoted 6 lines

hw/virtio-9p.c static void free_pdu(V9fsState *s, V9fsPDU *pdu) · line 140

Quoted 3 lines
hw/virtio-9p.c +2 -0
+
+	if (offset >= off && offset < (off + sg[i].iov_len)) {

The above math might overflow. Not sure what the result will be.

Quoted 11 lines

hw/virtio-9p.c static void free_pdu(V9fsState *s, V9fsPDU *pdu) · line 149

Quoted 9 lines
hw/virtio-9p.c +9 -0
+	    len = MIN(sg[i].iov_len - (offset - off), size);
+	    memcpy(sg[i].iov_base + (offset - off), src, len);
+	    size -= len;
+	    offset += len;
+	    off = offset;
+	    copied += len;
+	    src += len;
+	} else
+	    off += sg[i].iov_len;

{}

Fixed

Quoted 25 lines

hw/virtio-9p.c static void free_pdu(V9fsState *s, V9fsPDU *pdu) · line 156

Quoted 8 lines
hw/virtio-9p.c +7 -0
+    }
+
+    return copied;
+}
+
+static int pdu_copy_sg(V9fsPDU *pdu, size_t offset, int rx, struct iovec *sg)
+{

Maybe generalize this to work on any iovec?

Quoted 14 lines
hw/virtio-9p.c +14 -0
+    size_t pos = 0;
+    int i, j;
+    struct iovec *src_sg;
+    unsigned int num;
+
+    if (rx) {
+	    src_sg = pdu->elem.in_sg;
+	    num = pdu->elem.in_num;
+    } else {
+	    src_sg = pdu->elem.out_sg;
+	    num = pdu->elem.out_num;
+    }
+
+    j = 0;
#5 lore raw

PATCH 3/17 virtio-9p: Implement P9_TATTACH

In reply to Anthony Liguori
---
 Makefile.target      |    2 +-
 hw/virtio-9p-local.c |   84 +++++++++++++++++++++++++++
 hw/virtio-9p.c       |  155 +++++++++++++++++++++++++++++++++++++++++++++++---
 hw/virtio-9p.h       |   33 +++++++++++
 4 files changed, 264 insertions(+), 10 deletions(-)
 create mode 100644 hw/virtio-9p-local.c
Makefile.target +1 -1
index 8f240ea..ff5fc4b 100644
@@ -173,7 +173,7 @@ obj-y = vl.o async.o monitor.o pci.o pci_host.o pcie_host.o machine.o gdbstub.o
 # virtio has to be here due to weird dependency between PCI and virtio-net.
 # need to fix this properly
 obj-y += virtio-blk.o virtio-balloon.o virtio-net.o virtio-pci.o virtio-serial-bus.o
-obj-y += virtio-9p.o virtio-9p-debug.o
+obj-y += virtio-9p.o virtio-9p-debug.o virtio-9p-local.o
 obj-y += rwhandler.o
 obj-$(CONFIG_KVM) += kvm.o kvm-all.o
 obj-$(CONFIG_ISA_MMIO) += isa_mmio.o
hw/virtio-9p-local.c new file +84 -0

84 lines not on this page · raw message

hw/virtio-9p.c +146 -9

185 lines not on this page · raw message

hw/virtio-9p.h +33 -0
index 3945f81..10a084a 100644
@@ -66,5 +66,38 @@ struct V9fsPDU
     V9fsPDU *next;
 };
 
+typedef struct V9fsPosixFileOpertions
+{
+    int (*lstat)(void *, const char *, struct stat *);
+    ssize_t (*readlink)(void *, const char *, char *, size_t);
+    int (*chmod)(void *, const char *, mode_t);
+    int (*chown)(void *, const char *, uid_t, gid_t);
+    int (*mknod)(void *, const char *, mode_t, dev_t);
+    int (*mksock)(void *, const char *);
+    int (*utime)(void *, const char *, const struct utimbuf *);
+    int (*remove)(void *, const char *);
+    int (*symlink)(void *, const char *, const char *);
+    int (*link)(void *, const char *, const char *);
+    int (*setuid)(void *, uid_t);
+    int (*close)(void *, int);
+    int (*closedir)(void *, DIR *);
+    DIR *(*opendir)(void *, const char *);
+    int (*open)(void *, const char *, int);
+    int (*open2)(void *, const char *, int, mode_t);
+    void (*rewinddir)(void *, DIR *);
+    off_t (*telldir)(void *, DIR *);
+    struct dirent *(*readdir)(void *, DIR *);
+    void (*seekdir)(void *, DIR *, off_t);
+    ssize_t (*readv)(void *, int, const struct iovec *, int);
+    ssize_t (*writev)(void *, int, const struct iovec *, int);
+    off_t (*lseek)(void *, int, off_t, int);
+    int (*mkdir)(void *, const char *, mode_t);
+    int (*fstat)(void *, int, struct stat *);
+    int (*rename)(void *, const char *, const char *);
+    int (*truncate)(void *, const char *, off_t);
+    void *opaque;
+} V9fsPosixFileOperations;
+
+V9fsPosixFileOperations *virtio_9p_init_local(const char *path);
 
 #endif
Signature · 1 line
1.6.5.2
#6 lore raw

PATCH 4/17 virtio-9p: Implement P9_TSTAT

In reply to Anthony Liguori

This get the mount to work on the guest

[[email protected]: malloc to qemu_malloc conversion]

---
 hw/virtio-9p-local.c |    7 ++
 hw/virtio-9p.c       |  169 +++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 174 insertions(+), 2 deletions(-)
hw/virtio-9p-local.c +7 -0
index 204437c..9752f76 100644
@@ -72,9 +72,16 @@ static int local_setuid(void *opaque, uid_t uid)
     return 0;
 }
 
+static ssize_t local_readlink(void *opaque, const char *path,
+			      char *buf, size_t bufsz)
+{
+    return readlink(rpath(path), buf, bufsz);
+}
+
 static V9fsPosixFileOperations ops = {
     .lstat = local_lstat,
     .setuid = local_setuid,
+    .readlink = local_readlink,
 };
 
 V9fsPosixFileOperations *virtio_9p_init_local(const char *path)
hw/virtio-9p.c +167 -2

207 lines not on this page · raw message

Signature · 1 line
1.6.5.2
#7 lore raw

Re: [Qemu-devel] [PATCH 04/17] virtio-9p: Implement P9_TSTAT

Quoted 49 lines · Anthony Liguori

This get the mount to work on the guest

[[email protected]: malloc to qemu_malloc conversion]

---
 hw/virtio-9p-local.c |    7 ++
 hw/virtio-9p.c       |  169 +++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 174 insertions(+), 2 deletions(-)
hw/virtio-9p-local.c +7 -0
index 204437c..9752f76 100644
@@ -72,9 +72,16 @@ static int local_setuid(void *opaque, uid_t uid)
     return 0;
 }
 
+static ssize_t local_readlink(void *opaque, const char *path,
+			      char *buf, size_t bufsz)
+{
+    return readlink(rpath(path), buf, bufsz);
+}
+
 static V9fsPosixFileOperations ops = {
     .lstat = local_lstat,
     .setuid = local_setuid,
+    .readlink = local_readlink,
 };
 
 V9fsPosixFileOperations *virtio_9p_init_local(const char *path)
hw/virtio-9p.c +8 -0
index c63ac80..10bcd89 100644
@@ -102,6 +102,21 @@ static int posix_setuid(V9fsState *s, uid_t uid)
     return s->ops->setuid(s->ops->opaque, uid);
 }
 
+static ssize_t posix_readlink(V9fsState *s, V9fsString *path, V9fsString *buf)
+{
+    ssize_t len;
+
+    buf->data = qemu_malloc(1024);
+
+    len = s->ops->readlink(s->ops->opaque, path->data, buf->data, 1024 - 1);
+    if (len > -1) {

hw/virtio-9p.c static int posix_setuid(V9fsState *s, uid_t uid) · line 122

Quoted 10 lines
hw/virtio-9p.c +7 -0
+	buf->size = len;
+	buf->data[len] = 0;
+    }
+
+    return len;
+}
+
 static void v9fs_string_free(V9fsString *str)
 {
     free(str->data);

Should be qemu_free, no?

[..snip..]

Signature · 1 line
mailto:[email protected]
#8 lore raw

Re: [Qemu-devel] [PATCH 04/17] virtio-9p: Implement P9_TSTAT

Quoted 55 lines · malc
Quoted 53 lines · Anthony Liguori

This get the mount to work on the guest

[[email protected]: malloc to qemu_malloc conversion]

---
 hw/virtio-9p-local.c |    7 ++
 hw/virtio-9p.c       |  169 +++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 174 insertions(+), 2 deletions(-)
hw/virtio-9p-local.c +7 -0
index 204437c..9752f76 100644
@@ -72,9 +72,16 @@ static int local_setuid(void *opaque, uid_t uid)
     return 0;
 }
 
+static ssize_t local_readlink(void *opaque, const char *path,
+			      char *buf, size_t bufsz)
+{
+    return readlink(rpath(path), buf, bufsz);
+}
+
 static V9fsPosixFileOperations ops = {
     .lstat = local_lstat,
     .setuid = local_setuid,
+    .readlink = local_readlink,
 };
 
 V9fsPosixFileOperations *virtio_9p_init_local(const char *path)
hw/virtio-9p.c +12 -0
index c63ac80..10bcd89 100644
@@ -102,6 +102,21 @@ static int posix_setuid(V9fsState *s, uid_t uid)
     return s->ops->setuid(s->ops->opaque, uid);
 }
 
+static ssize_t posix_readlink(V9fsState *s, V9fsString *path, V9fsString *buf)
+{
+    ssize_t len;
+
+    buf->data = qemu_malloc(1024);
+
+    len = s->ops->readlink(s->ops->opaque, path->data, buf->data, 1024 - 1);
+    if (len > -1) {
+	buf->size = len;
+	buf->data[len] = 0;
+    }
+
Quoted 9 lines

hw/virtio-9p.c static int posix_setuid(V9fsState *s, uid_t uid) · line 122

Quoted 6 lines
hw/virtio-9p.c +3 -0
+    return len;
+}
+
 static void v9fs_string_free(V9fsString *str)
 {
     free(str->data);

Should be qemu_free, no?

Updated the patch

-aneesh

#9 lore raw

Re: [Qemu-devel] [PATCH 04/17] virtio-9p: Implement P9_TSTAT

Quoted 66 lines · Aneesh Kumar K. V
Quoted 54 lines · malc
Quoted 52 lines · Anthony Liguori

This get the mount to work on the guest

[[email protected]: malloc to qemu_malloc conversion]

---
 hw/virtio-9p-local.c |    7 ++
 hw/virtio-9p.c       |  169 +++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 174 insertions(+), 2 deletions(-)
hw/virtio-9p-local.c +7 -0
index 204437c..9752f76 100644
@@ -72,9 +72,16 @@ static int local_setuid(void *opaque, uid_t uid)
     return 0;
 }
 
+static ssize_t local_readlink(void *opaque, const char *path,
+			      char *buf, size_t bufsz)
+{
+    return readlink(rpath(path), buf, bufsz);
+}
+
 static V9fsPosixFileOperations ops = {
     .lstat = local_lstat,
     .setuid = local_setuid,
+    .readlink = local_readlink,
 };
 
 V9fsPosixFileOperations *virtio_9p_init_local(const char *path)
hw/virtio-9p.c +11 -0
index c63ac80..10bcd89 100644
@@ -102,6 +102,21 @@ static int posix_setuid(V9fsState *s, uid_t uid)
     return s->ops->setuid(s->ops->opaque, uid);
 }
 
+static ssize_t posix_readlink(V9fsState *s, V9fsString *path, V9fsString *buf)
+{
+    ssize_t len;
+
+    buf->data = qemu_malloc(1024);
+
+    len = s->ops->readlink(s->ops->opaque, path->data, buf->data, 1024 - 1);
+    if (len > -1) {
+	buf->size = len;
+	buf->data[len] = 0;
+    }
Quoted 9 lines

hw/virtio-9p.c static int posix_setuid(V9fsState *s, uid_t uid) · line 122

Quoted 7 lines
hw/virtio-9p.c +4 -0
+
+    return len;
+}
+
 static void v9fs_string_free(V9fsString *str)
 {
     free(str->data);

Should be qemu_free, no?

Quoted 1 line

Updated the patch

Is there any reason (other than being coding style) in using qemu_free() instead of free()? As per qem-malloc.c qemu_free() is nothing but free().

The reason I am asking is.. tracking string allocs become tricky
if some of them were defined using qemu_alloc() and others are allocated through sprintf().

Thanks,
JV

Quoted 4 lines

-aneesh

#10 lore raw

Re: [Qemu-devel] [PATCH 04/17] virtio-9p: Implement P9_TSTAT

Quoted 2 lines

Is there any reason (other than being coding style) in using qemu_free() instead of free()? As per qem-malloc.c qemu_free() is nothing but free().

The whole point of qemu_{malloc,free} is to isolate code from the system implementation of malloc/free. It's entirely possible that future versions of qemu_malloc will use a different memory allocation strategy.

Quoted 3 lines

The reason I am asking is.. tracking string allocs become tricky if some of them were defined using qemu_alloc() and others are allocated
through sprintf().

sprintf does not allocate memory.
If you mean strdup, then you shouldn't be using that (use qemu_strdup).

Paul

#11 lore raw

Re: [Qemu-devel] [PATCH 04/17] virtio-9p: Implement P9_TSTAT

Quoted 7 lines · Paul Brook
Quoted 2 lines

Is there any reason (other than being coding style) in using qemu_free() instead of free()? As per qem-malloc.c qemu_free() is nothing but free().

The whole point of qemu_{malloc,free} is to isolate code from the system implementation of malloc/free. It's entirely possible that future versions of qemu_malloc will use a different memory allocation strategy.

Quoted 6 lines
Quoted 3 lines

The reason I am asking is.. tracking string allocs become tricky if some of them were defined using qemu_alloc() and others are allocated
through sprintf().

sprintf does not allocate memory.
If you mean strdup, then you shouldn't be using that (use qemu_strdup).

we have code that does

static void v9fs_string_sprintf(V9fsString *str, const char *fmt, ...)

{
    va_list ap;
    int err;

    v9fs_string_free(str);

    va_start(ap, fmt);
    err = vasprintf(&str->data, fmt, ap);
    BUG_ON(err == -1);
    va_end(ap);

    str->size = err;
}

I guess we should not be using vasprint. What alternatives are available today ?

-aneesh

#12 lore raw

Re: [Qemu-devel] [PATCH 04/17] virtio-9p: Implement P9_TSTAT

In reply to Paul Brook
Quoted 7 lines · Paul Brook
Quoted 2 lines

Is there any reason (other than being coding style) in using qemu_free() instead of free()? As per qem-malloc.c qemu_free() is nothing but free().

The whole point of qemu_{malloc,free} is to isolate code from the system implementation of malloc/free. It's entirely possible that future versions of qemu_malloc will use a different memory allocation strategy.

Quoted 6 lines
Quoted 3 lines

The reason I am asking is.. tracking string allocs become tricky if some of them were defined using qemu_alloc() and others are allocated
through sprintf().

sprintf does not allocate memory.
If you mean strdup, then you shouldn't be using that (use qemu_strdup).

Thanks for correcting Paul.. I was talking about vasprintf() .. not really the sprintf() In any case.. right way to do it may be adding a new qemu_vasprintf() for and use it along with qemu_free() Right?

Thanks,
JV

Quoted 2 lines

Paul

#13 lore raw

Re: [Qemu-devel] [PATCH 04/17] virtio-9p: Implement P9_TSTAT

Quoted 13 lines
Quoted 12 lines · Paul Brook
Quoted 3 lines

Is there any reason (other than being coding style) in using qemu_free() instead of free()? As per qem-malloc.c qemu_free() is nothing but free().

The whole point of qemu_{malloc,free} is to isolate code from the system implementation of malloc/free. It's entirely possible that future versions of qemu_malloc will use a different memory allocation strategy.

Quoted 3 lines

The reason I am asking is.. tracking string allocs become tricky if some of them were defined using qemu_alloc() and others are allocated
through sprintf().

Quoted 6 lines
Quoted 2 lines

sprintf does not allocate memory.
If you mean strdup, then you shouldn't be using that (use qemu_strdup).

Thanks for correcting Paul.. I was talking about vasprintf() .. not really
the sprintf() In any case.. right way to do it may be adding a new qemu_vasprintf() for and use it along with qemu_free() Right?

Something like that, yes. Any use of [v]asprintf is incorrect.

Paul

#14 lore raw

PATCH 5/17 virtio-9p: Implement P9_TWALK

In reply to Anthony Liguori
---
 hw/virtio-9p-local.c |   12 +++
 hw/virtio-9p.c       |  219 +++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 229 insertions(+), 2 deletions(-)
hw/virtio-9p-local.c +12 -0
index 9752f76..ac0dce5 100644
@@ -78,10 +78,22 @@ static ssize_t local_readlink(void *opaque, const char *path,
     return readlink(rpath(path), buf, bufsz);
 }
 
+static int local_close(void *opaque, int fd)
+{
+    return close(fd);
+}
+
+static int local_closedir(void *opaque, DIR *dir)
+{
+    return closedir(dir);
+}
+
 static V9fsPosixFileOperations ops = {
     .lstat = local_lstat,
     .setuid = local_setuid,
     .readlink = local_readlink,
+    .close = local_close,
+    .closedir = local_closedir,
 };
 
 V9fsPosixFileOperations *virtio_9p_init_local(const char *path)
hw/virtio-9p.c +217 -2

245 lines not on this page · raw message

Signature · 1 line
1.6.5.2
#15 lore raw

PATCH 6/17 virtio-9p: Implement P9_TOPEN

In reply to Anthony Liguori
---
 hw/virtio-9p-local.c |   12 ++++
 hw/virtio-9p.c       |  141 ++++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 149 insertions(+), 4 deletions(-)
hw/virtio-9p-local.c +12 -0
index ac0dce5..803b0ea 100644
@@ -88,12 +88,24 @@ static int local_closedir(void *opaque, DIR *dir)
     return closedir(dir);
 }
 
+static int local_open(void *opaque, const char *path, int flags)
+{
+    return open(rpath(path), flags);
+}
+
+static DIR *local_opendir(void *opaque, const char *path)
+{
+    return opendir(rpath(path));
+}
+
 static V9fsPosixFileOperations ops = {
     .lstat = local_lstat,
     .setuid = local_setuid,
     .readlink = local_readlink,
     .close = local_close,
     .closedir = local_closedir,
+    .open = local_open,
+    .opendir = local_opendir,
 };
 
 V9fsPosixFileOperations *virtio_9p_init_local(const char *path)
hw/virtio-9p.c +137 -4

157 lines not on this page · raw message

Signature · 1 line
1.6.5.2
#16 lore raw

PATCH 7/17 virtio-9p: Implement P9_TREAD

In reply to Anthony Liguori
---
 hw/virtio-9p-local.c |   37 ++++++++
 hw/virtio-9p.c       |  253 +++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 287 insertions(+), 3 deletions(-)
hw/virtio-9p-local.c +37 -0
index 803b0ea..90664a0 100644
@@ -98,6 +98,37 @@ static DIR *local_opendir(void *opaque, const char *path)
     return opendir(rpath(path));
 }
 
+static void local_rewinddir(void *opaque, DIR *dir)
+{
+    return rewinddir(dir);
+}
+
+static off_t local_telldir(void *opaque, DIR *dir)
+{
+    return telldir(dir);
+}
+
+static struct dirent *local_readdir(void *opaque, DIR *dir)
+{
+    return readdir(dir);
+}
+
+static void local_seekdir(void *opaque, DIR *dir, off_t off)
+{
+    return seekdir(dir, off);
+}
+
+static ssize_t local_readv(void *opaque, int fd, const struct iovec *iov,
+			   int iovcnt)
+{
+    return readv(fd, iov, iovcnt);
+}
+
+static off_t local_lseek(void *opaque, int fd, off_t offset, int whence)
+{
+    return lseek(fd, offset, whence);
+}
+
 static V9fsPosixFileOperations ops = {
     .lstat = local_lstat,
     .setuid = local_setuid,
@@ -106,6 +137,12 @@ static V9fsPosixFileOperations ops = {
     .closedir = local_closedir,
     .open = local_open,
     .opendir = local_opendir,
+    .rewinddir = local_rewinddir,
+    .telldir = local_telldir,
+    .readdir = local_readdir,
+    .seekdir = local_seekdir,
+    .readv = local_readv,
+    .lseek = local_lseek,
 };
 
 V9fsPosixFileOperations *virtio_9p_init_local(const char *path)
hw/virtio-9p.c +250 -3

270 lines not on this page · raw message

Signature · 1 line
1.6.5.2
#17 lore raw

PATCH 8/17 virtio-9p: Implement P9_TCLUNK

In reply to Anthony Liguori

This patch gets ls -al to work

---
 hw/virtio-9p.c |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)
hw/virtio-9p.c +14 -2
index b30933a..7822a00 100644
@@ -1305,8 +1305,20 @@ out:
 
 static void v9fs_clunk(V9fsState *s, V9fsPDU *pdu)
 {
-    if (debug_9p_pdu)
-	pprint_pdu(pdu);
+    int32_t fid;
+    size_t offset = 7;
+    int err;
+
+    pdu_unmarshal(pdu, offset, "d", &fid);
+
+    err = free_fid(s, fid);
+    if (err < 0)
+	goto out;
+
+    offset = 7;
+    err = offset;
+out:
+    complete_pdu(s, pdu, err);
 }
 
 static void v9fs_write(V9fsState *s, V9fsPDU *pdu)
Signature · 1 line
1.6.5.2
#18 lore raw

PATCH 9/17 virtio-9p: Implement P9_TWRITE

In reply to Anthony Liguori

This gets write to file to work

---
 hw/virtio-9p-local.c |    7 ++++
 hw/virtio-9p.c       |   97 ++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 102 insertions(+), 2 deletions(-)
hw/virtio-9p-local.c +7 -0
index 90664a0..441d22d 100644
@@ -129,6 +129,12 @@ static off_t local_lseek(void *opaque, int fd, off_t offset, int whence)
     return lseek(fd, offset, whence);
 }
 
+static ssize_t local_writev(void *opaque, int fd, const struct iovec *iov,
+			    int iovcnt)
+{
+    return writev(fd, iov, iovcnt);
+}
+
 static V9fsPosixFileOperations ops = {
     .lstat = local_lstat,
     .setuid = local_setuid,
@@ -143,6 +149,7 @@ static V9fsPosixFileOperations ops = {
     .seekdir = local_seekdir,
     .readv = local_readv,
     .lseek = local_lseek,
+    .writev = local_writev,
 };
 
 V9fsPosixFileOperations *virtio_9p_init_local(const char *path)
hw/virtio-9p.c +95 -2

111 lines not on this page · raw message

Signature · 1 line
1.6.5.2
#19 lore raw

PATCH 10/17 virtio-9p: Implement P9_TCREATE

In reply to Anthony Liguori
---
 hw/virtio-9p-local.c |   80 +++++++++++++++
 hw/virtio-9p.c       |  267 +++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 345 insertions(+), 2 deletions(-)
hw/virtio-9p-local.c +80 -0
index 441d22d..606f5be 100644
@@ -135,6 +135,78 @@ static ssize_t local_writev(void *opaque, int fd, const struct iovec *iov,
     return writev(fd, iov, iovcnt);
 }
 
+static int local_chmod(void *opaque, const char *path, mode_t mode)
+{
+    return chmod(rpath(path), mode);
+}
+
+static int local_mknod(void *opaque, const char *path, mode_t mode, dev_t dev)
+{
+    return mknod(rpath(path), mode, dev);
+}
+
+static int local_mksock(void *opaque, const char *path)
+{
+    struct sockaddr_un addr;
+    int s;
+
+    addr.sun_family = AF_UNIX;
+    snprintf(addr.sun_path, 108, "%s", rpath(path));
+
+    s = socket(PF_UNIX, SOCK_STREAM, 0);
+    if (s == -1)
+	return -1;
+
+    if (bind(s, (struct sockaddr *)&addr, sizeof(addr))) {
+	close(s);
+	return -1;
+    }
+
+    close(s);
+    return 0;
+}
+
+static int local_mkdir(void *opaque, const char *path, mode_t mode)
+{
+    return mkdir(rpath(path), mode);
+}
+
+static int local_fstat(void *opaque, int fd, struct stat *stbuf)
+{
+    return fstat(fd, stbuf);
+}
+
+static int local_open2(void *opaque, const char *path, int flags, mode_t mode)
+{
+    return open(rpath(path), flags, mode);
+}
+
+static int local_symlink(void *opaque, const char *oldpath,
+			 const char *newpath)
+{
+    return symlink(oldpath, rpath(newpath));
+}
+
+static int local_link(void *opaque, const char *oldpath, const char *newpath)
+{
+    char *tmp = strdup(rpath(oldpath));
+    int err, serrno = 0;
+
+    if (tmp == NULL)
+	return -ENOMEM;
+
+    err = link(tmp, rpath(newpath));
+    if (err == -1)
+	serrno = errno;
+
+    free(tmp);
+
+    if (err == -1)
+	errno = serrno;
+
+    return err;
+}
+
 static V9fsPosixFileOperations ops = {
     .lstat = local_lstat,
     .setuid = local_setuid,
@@ -150,6 +222,14 @@ static V9fsPosixFileOperations ops = {
     .readv = local_readv,
     .lseek = local_lseek,
     .writev = local_writev,
+    .chmod = local_chmod,
+    .mknod = local_mknod,
+    .mksock = local_mksock,
+    .mkdir = local_mkdir,
+    .fstat = local_fstat,
+    .open2 = local_open2,
+    .symlink = local_symlink,
+    .link = local_link,
 };
 
 V9fsPosixFileOperations *virtio_9p_init_local(const char *path)
hw/virtio-9p.c +265 -2

281 lines not on this page · raw message

Signature · 1 line
1.6.5.2
#20 lore raw

PATCH 11/17 virtio-9p: Implement P9_TWSTAT

In reply to Anthony Liguori

This gets file and directory creation to work

---
 hw/virtio-9p-local.c |   42 +++++++++
 hw/virtio-9p.c       |  236 +++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 274 insertions(+), 4 deletions(-)
hw/virtio-9p-local.c +42 -0
index 606f5be..0a9f111 100644
@@ -207,6 +207,44 @@ static int local_link(void *opaque, const char *oldpath, const char *newpath)
     return err;
 }
 
+static int local_truncate(void *opaque, const char *path, off_t size)
+{
+    return truncate(rpath(path), size);
+}
+
+static int local_rename(void *opaque, const char *oldpath,
+			const char *newpath)
+{
+    char *tmp;
+    int err;
+
+    tmp = strdup(rpath(oldpath));
+    if (tmp == NULL)
+	return -1;
+
+    err = rename(tmp, rpath(newpath));
+    if (err == -1) {
+	int serrno = errno;
+	free(tmp);
+	errno = serrno;
+    } else
+	free(tmp);
+
+    return err;
+
+}
+
+static int local_chown(void *opaque, const char *path, uid_t uid, gid_t gid)
+{
+    return chown(rpath(path), uid, gid);
+}
+
+static int local_utime(void *opaque, const char *path,
+		       const struct utimbuf *buf)
+{
+    return utime(rpath(path), buf);
+}
+
 static V9fsPosixFileOperations ops = {
     .lstat = local_lstat,
     .setuid = local_setuid,
@@ -230,6 +268,10 @@ static V9fsPosixFileOperations ops = {
     .open2 = local_open2,
     .symlink = local_symlink,
     .link = local_link,
+    .truncate = local_truncate,
+    .rename = local_rename,
+    .chown = local_chown,
+    .utime = local_utime,
 };
 
 V9fsPosixFileOperations *virtio_9p_init_local(const char *path)
hw/virtio-9p.c +232 -4

262 lines not on this page · raw message

Signature · 1 line
1.6.5.2
#21 lore raw

PATCH 12/17 virtio-9p: Implement P9_TREMOVE

In reply to Anthony Liguori

This gets file deletion to work

[[email protected]: Fix truncate to use the relative path]

---
 hw/virtio-9p-local.c |    7 ++++++
 hw/virtio-9p.c       |   54 ++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 59 insertions(+), 2 deletions(-)
hw/virtio-9p-local.c +7 -0
index 0a9f111..43867be 100644
@@ -245,6 +245,12 @@ static int local_utime(void *opaque, const char *path,
     return utime(rpath(path), buf);
 }
 
+static int local_remove(void *opaque, const char *path)
+{
+    return remove(rpath(path));
+}
+
+
 static V9fsPosixFileOperations ops = {
     .lstat = local_lstat,
     .setuid = local_setuid,
@@ -272,6 +278,7 @@ static V9fsPosixFileOperations ops = {
     .rename = local_rename,
     .chown = local_chown,
     .utime = local_utime,
+    .remove = local_remove,
 };
 
 V9fsPosixFileOperations *virtio_9p_init_local(const char *path)
hw/virtio-9p.c +52 -2

68 lines not on this page · raw message

Signature · 1 line
1.6.5.2
#22 lore raw

PATCH 13/17 virtio-9p: Implement P9_TFLUSH

In reply to Anthony Liguori

Don't do anything special for flush

---
 hw/virtio-9p.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
hw/virtio-9p.c +3 -2
index 50ee82a..72e0339 100644
@@ -1720,10 +1720,11 @@ out:
 
 static void v9fs_flush(V9fsState *s, V9fsPDU *pdu)
 {
-    if (debug_9p_pdu)
-	pprint_pdu(pdu);
+    /* A nop call with no return */
+    complete_pdu(s, pdu, 7);
 }
 
+
 typedef struct V9fsRemoveState {
     V9fsPDU *pdu;
     size_t offset;
Signature · 1 line
1.6.5.2
#24 lore raw

PATCH 14/17 virtio-9p: Add multiple mount point support

In reply to Anthony Liguori

From: Aneesh Kumar K.V <[email protected]>

This patch add a mount tag name in 9p config space. This tag should uniquely identify the mount point and should be used in the mount command as the device name

Qemu command line for specifying 9p share directory now becomes -device virtio-9p-pci,share_path=/mnt/,mount_tag=v_mnt -device virtio-9p-pci,share_path=/tmp/,mount_tag=v_tmp

NOTE: We now limit tag name to 32 characters because of virtio config space limitation.

---
 hw/9p.h              |   26 +++++++
 hw/virtio-9p-local.c |   97 ++++++++++++------------
 hw/virtio-9p.c       |  204 ++++++++++++++++++++++++-------------------------
 hw/virtio-9p.h       |  141 ++++++++++++++++++++++++++++-------
 hw/virtio-pci.c      |    8 +-
 hw/virtio.h          |    3 +-
 6 files changed, 293 insertions(+), 186 deletions(-)
 create mode 100644 hw/9p.h
hw/9p.h new file +26 -0
new file mode 100644
index 0000000..f0ff45b
@@ -0,0 +1,26 @@
+/*
+ * Virtio 9p
+ *
+ * Copyright IBM, Corp. 2010
+ *
+ * Authors:
+ *  Aneesh Kumar K.V <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef QEMU_9P_H
+#define QEMU_9P_H
+
+#include <stdbool.h>
+
+typedef struct V9fsConf
+{
+    char *share_path;
+    /* tag name for the device */
+    char *tag;
+} V9fsConf;
+
+#endif
hw/virtio-9p-local.c +47 -50

239 lines not on this page · raw message

hw/virtio-9p.c +100 -104

360 lines not on this page · raw message

hw/virtio-9p.h +114 -27

155 lines not on this page · raw message

hw/virtio-pci.c +4 -4
index f837376..e48a49d 100644
@@ -86,7 +86,6 @@
 #define wmb() do { } while (0)
 
 /* PCI bindings.  */
-
 typedef struct {
     PCIDevice pci_dev;
     VirtIODevice *vdev;
@@ -96,7 +95,7 @@ typedef struct {
     BlockConf block;
     NICConf nic;
     uint32_t host_features;
-    char *share_path;
+    V9fsConf fsconf;
     /* Max. number of ports we can have for a the virtio-serial device */
     uint32_t max_virtserial_ports;
 } VirtIOPCIProxy;
@@ -557,7 +556,7 @@ static int virtio_9p_init_pci(PCIDevice *pci_dev)
     VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
     VirtIODevice *vdev;
 
-    vdev = virtio_9p_init(&pci_dev->qdev, proxy->share_path);
+    vdev = virtio_9p_init(&pci_dev->qdev, &proxy->fsconf);
     virtio_init_pci(proxy, vdev,
 		    PCI_VENDOR_ID_REDHAT_QUMRANET,
 		    0x1009,
@@ -625,7 +624,8 @@ static PCIDeviceInfo virtio_info[] = {
         .init      = virtio_9p_init_pci,
         .qdev.props = (Property[]) {
             DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
-            DEFINE_PROP_STRING("share_path", VirtIOPCIProxy, share_path),
+            DEFINE_PROP_STRING("share_path", VirtIOPCIProxy, fsconf.share_path),
+            DEFINE_PROP_STRING("mount_tag", VirtIOPCIProxy, fsconf.tag),
             DEFINE_PROP_END_OF_LIST(),
         },
     },{
hw/virtio.h +2 -1
index 4032a96..c11a380 100644
@@ -19,6 +19,7 @@
 #include "qdev.h"
 #include "sysemu.h"
 #include "block_int.h"
+#include "9p.h"
 
 /* from Linux's linux/virtio_config.h */
 
@@ -174,7 +175,7 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf);
 VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf);
 VirtIODevice *virtio_serial_init(DeviceState *dev, uint32_t max_nr_ports);
 VirtIODevice *virtio_balloon_init(DeviceState *dev);
-VirtIODevice *virtio_9p_init(DeviceState *dev, const char *path);
+VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf);
 
 void virtio_net_exit(VirtIODevice *vdev);
 
Signature · 1 line
1.6.5.2
#25 lore raw

PATCH 15/17 virtio-9p: Use little endian format on virtio

In reply to Anthony Liguori

From: Aneesh Kumar K.V <[email protected]>

We need to use platform independent data format as part of protocol data. 9P uses little endian format on wire

---
 hw/virtio-9p.c |   34 +++++++++++++++++++++++-----------
 1 files changed, 23 insertions(+), 11 deletions(-)
hw/virtio-9p.c +23 -11
index 97fcb8a..65f5827 100644
@@ -425,23 +425,32 @@ static size_t pdu_unmarshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...)
     for (i = 0; fmt[i]; i++) {
 	switch (fmt[i]) {
 	case 'b': {
-	    int8_t *valp = va_arg(ap, int8_t *);
+	    uint8_t *valp = va_arg(ap, uint8_t *);
 	    offset += pdu_unpack(valp, pdu, offset, sizeof(*valp));
 	    break;
 	}
 	case 'w': {
-	    int16_t *valp = va_arg(ap, int16_t *);
-	    offset += pdu_unpack(valp, pdu, offset, sizeof(*valp));
+	    uint16_t val, *valp;
+	    valp = va_arg(ap, uint16_t *);
+	    val = le16_to_cpupu(valp);
+	    offset += pdu_unpack(&val, pdu, offset, sizeof(val));
+	    *valp = val;
 	    break;
 	}
 	case 'd': {
-	    int32_t *valp = va_arg(ap, int32_t *);
-	    offset += pdu_unpack(valp, pdu, offset, sizeof(*valp));
+	    uint32_t val, *valp;
+	    valp = va_arg(ap, uint32_t *);
+	    val = le32_to_cpupu(valp);
+	    offset += pdu_unpack(&val, pdu, offset, sizeof(val));
+	    *valp = val;
 	    break;
 	}
 	case 'q': {
-	    int64_t *valp = va_arg(ap, int64_t *);
-	    offset += pdu_unpack(valp, pdu, offset, sizeof(*valp));
+	    uint64_t val, *valp;
+	    valp = va_arg(ap, uint64_t *);
+	    val = le64_to_cpup(valp);
+	    offset += pdu_unpack(&val, pdu, offset, sizeof(val));
+	    *valp = val;
 	    break;
 	}
 	case 'v': {
@@ -497,22 +506,25 @@ static size_t pdu_marshal(V9fsPDU *pdu, size_t offset, const char *fmt, ...)
     for (i = 0; fmt[i]; i++) {
 	switch (fmt[i]) {
 	case 'b': {
-	    int8_t val = va_arg(ap, int);
+	    uint8_t val = va_arg(ap, int);
 	    offset += pdu_pack(pdu, offset, &val, sizeof(val));
 	    break;
 	}
 	case 'w': {
-	    int16_t val = va_arg(ap, int);
+	    uint16_t val;
+	    cpu_to_le16w(&val, va_arg(ap, int));
 	    offset += pdu_pack(pdu, offset, &val, sizeof(val));
 	    break;
 	}
 	case 'd': {
-	    int32_t val = va_arg(ap, int);
+	    uint32_t val;
+	    cpu_to_le32w(&val, va_arg(ap, uint32_t));
 	    offset += pdu_pack(pdu, offset, &val, sizeof(val));
 	    break;
 	}
 	case 'q': {
-	    int64_t val = va_arg(ap, int64_t);
+	    uint64_t val;
+	    cpu_to_le64w(&val, va_arg(ap, uint64_t));
 	    offset += pdu_pack(pdu, offset, &val, sizeof(val));
 	    break;
 	}
Signature · 1 line
1.6.5.2
#26 lore raw

PATCH 16/17 virtio-9p: Add support for hardlink

In reply to Anthony Liguori

From: Aneesh Kumar K.V <[email protected]>

link count for files and directories are encoded as a tagged string in the extension field for a .u protocol extension.

---
 hw/virtio-9p.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
hw/virtio-9p.c +3 -0
index 65f5827..8a96645 100644
@@ -676,6 +676,9 @@ static void stat_to_v9stat(V9fsState *s, V9fsString *name,
 	    v9fs_string_sprintf(&v9stat->extension, "%c %u %u",
 				S_ISCHR(stbuf->st_mode) ? 'c' : 'b',
 				major(stbuf->st_rdev), minor(stbuf->st_rdev));
+	} else if (S_ISDIR(stbuf->st_mode) || S_ISREG(stbuf->st_mode)) {
+		v9fs_string_sprintf(&v9stat->extension, "%s %u",
+				"HARDLINKCOUNT", stbuf->st_nlink);
 	}
     }
 
Signature · 1 line
1.6.5.2
#27 lore raw

PATCH 17/17 Implement sync support in 9p server

In reply to Anthony Liguori

From: M. Mohan Kumar <[email protected]>

When wstat is called with stat field values set to 'don't touch' pattern, 9p Server interprets it as a request to guarantee that the contents of the associated file are committed to stable storage before the Rwstat message is returned. Implement this feature in the server side.

---
 hw/virtio-9p-local.c |    6 ++++++
 hw/virtio-9p.c       |   34 ++++++++++++++++++++++++++++++++++
 hw/virtio-9p.h       |    1 +
 3 files changed, 41 insertions(+), 0 deletions(-)
hw/virtio-9p-local.c +6 -0
index d89a735..4317ea3 100644
@@ -249,6 +249,11 @@ static int local_remove(V9fsState *s, const char *path)
 }
 
 
+static int local_fsync(V9fsState *s, int fd)
+{
+    return fsync(fd);
+}
+
 static V9fsPosixFileOperations ops = {
     .lstat = local_lstat,
     .setuid = local_setuid,
@@ -277,6 +282,7 @@ static V9fsPosixFileOperations ops = {
     .chown = local_chown,
     .utime = local_utime,
     .remove = local_remove,
+    .fsync = local_fsync,
 };
 
 V9fsPosixFileOperations *virtio_9p_init_local(const char *path)
hw/virtio-9p.c +34 -0
index 8a96645..94c9c58 100644
@@ -172,6 +172,11 @@ static int posix_remove(V9fsState *s, V9fsString *path)
     return s->ops->remove(s, path->data);
 }
 
+static int posix_fsync(V9fsState *s, int fd)
+{
+    return s->ops->fsync(s, fd);
+}
+
 static void v9fs_string_init(V9fsString *str)
 {
     str->data = NULL;
@@ -1892,6 +1897,29 @@ out:
     qemu_free(vs);
 }
 
+static int donttouch_stat(V9fsStat *stat)
+{
+    if (stat->type == -1 &&
+	stat->dev == -1 &&
+	stat->qid.type == -1 &&
+	stat->qid.version == -1 &&
+	stat->qid.path == -1 &&
+	stat->mode == -1 &&
+	stat->atime == -1 &&
+	stat->mtime == -1 &&
+	stat->length == -1 &&
+	!stat->name.size &&
+	!stat->uid.size &&
+	!stat->gid.size &&
+	!stat->muid.size &&
+	stat->n_uid == -1 &&
+	stat->n_gid == -1 &&
+	stat->n_muid == -1)
+		return 1;
+	else
+		return 0;
+}
+
 static void v9fs_wstat(V9fsState *s, V9fsPDU *pdu)
 {
     V9fsWstatState *vs;
@@ -1909,6 +1937,12 @@ static void v9fs_wstat(V9fsState *s, V9fsPDU *pdu)
 	goto out;
     }
 
+    /* do we need to sync the file? */
+    if (donttouch_stat(&vs->v9stat)) {
+        posix_fsync(s, vs->fidp->fd);
+        goto out;
+    }
+
     if (vs->v9stat.mode != -1) {
 	if (vs->v9stat.mode & P9_STAT_MODE_DIR && vs->fidp->dir == NULL) {
 	    err = -EIO;
hw/virtio-9p.h +1 -0
index 42ca887..113b0d5 100644
@@ -182,6 +182,7 @@ typedef struct V9fsPosixFileOpertions
     int (*fstat)(V9fsState *, int, struct stat *);
     int (*rename)(V9fsState *, const char *, const char *);
     int (*truncate)(V9fsState *, const char *, off_t);
+    int (*fsync)(V9fsState *, int);
     void *opaque;
 } V9fsPosixFileOperations;
 
Signature · 1 line
1.6.5.2