[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 53/61] virtio-9p : add the virtio-9p device.
From: |
fred . konrad |
Subject: |
[Qemu-devel] [PATCH 53/61] virtio-9p : add the virtio-9p device. |
Date: |
Mon, 7 Jan 2013 19:41:06 +0100 |
From: KONRAD Frederic <address@hidden>
Create virtio-9p which extends virtio-device, so it can be connected on
virtio-bus.
Signed-off-by: KONRAD Frederic <address@hidden>
---
hw/9pfs/virtio-9p-device.c | 84 +++++++++++++++++++++++++++++++++++++++-------
hw/9pfs/virtio-9p.h | 11 ++++++
hw/virtio-pci.c | 5 +++
3 files changed, 87 insertions(+), 13 deletions(-)
diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
index 6761bce..8a88739 100644
--- a/hw/9pfs/virtio-9p-device.c
+++ b/hw/9pfs/virtio-9p-device.c
@@ -46,19 +46,36 @@ static void virtio_9p_get_config(VirtIODevice *vdev,
uint8_t *config)
g_free(cfg);
}
-VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf)
+void virtio_9p_set_conf(DeviceState *dev, V9fsConf *conf)
{
- V9fsState *s;
+ V9fsState *s = VIRTIO_9P(dev);
+ memcpy(&(s->fsconf), conf, sizeof(V9fsConf));
+}
+
+static VirtIODevice *virtio_9p_common_init(DeviceState *dev, V9fsConf *conf,
+ V9fsState **ps)
+{
+ V9fsState *s = *ps;
int i, len;
struct stat stat;
FsDriverEntry *fse;
V9fsPath path;
- s = (V9fsState *)virtio_common_init("virtio-9p",
- VIRTIO_ID_9P,
- sizeof(struct virtio_9p_config)+
- MAX_TAG_LEN,
- sizeof(V9fsState));
+ /*
+ * We have two cases here : the old virtio-9p-pci device, and the
+ * refactored virtio-9p.
+ */
+
+ if (s == NULL) {
+ s = (V9fsState *)virtio_common_init("virtio-9p",
+ VIRTIO_ID_9P,
+ sizeof(struct virtio_9p_config)+
+ MAX_TAG_LEN,
+ sizeof(V9fsState));
+ } else {
+ virtio_init(VIRTIO_DEVICE(s), "virtio-9p", VIRTIO_ID_9P,
+ sizeof(struct virtio_9p_config) + MAX_TAG_LEN);
+ }
/* initialize pdu allocator */
QLIST_INIT(&s->free_list);
QLIST_INIT(&s->active_list);
@@ -141,6 +158,12 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf
*conf)
return &s->vdev;
}
+VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf)
+{
+ V9fsState *s = NULL;
+ return virtio_9p_common_init(dev, conf, &s);
+}
+
static int virtio_9p_init_pci(PCIDevice *pci_dev)
{
VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
@@ -154,16 +177,15 @@ static int virtio_9p_init_pci(PCIDevice *pci_dev)
return 0;
}
-static Property virtio_9p_properties[] = {
+static Property virtio_9p_pci_properties[] = {
DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
- DEFINE_PROP_STRING("mount_tag", VirtIOPCIProxy, fsconf.tag),
- DEFINE_PROP_STRING("fsdev", VirtIOPCIProxy, fsconf.fsdev_id),
+ DEFINE_VIRTIO_9P_PROPERTIES(VirtIOPCIProxy, fsconf),
DEFINE_PROP_END_OF_LIST(),
};
-static void virtio_9p_class_init(ObjectClass *klass, void *data)
+static void virtio_9p_pci_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
@@ -173,7 +195,7 @@ static void virtio_9p_class_init(ObjectClass *klass, void
*data)
k->device_id = 0x1009;
k->revision = VIRTIO_PCI_ABI_VERSION;
k->class_id = 0x2;
- dc->props = virtio_9p_properties;
+ dc->props = virtio_9p_pci_properties;
dc->reset = virtio_pci_reset;
}
@@ -181,11 +203,47 @@ static TypeInfo virtio_9p_info = {
.name = "virtio-9p-pci",
.parent = TYPE_PCI_DEVICE,
.instance_size = sizeof(VirtIOPCIProxy),
- .class_init = virtio_9p_class_init,
+ .class_init = virtio_9p_pci_class_init,
+};
+
+/* virtio-9p device */
+
+static int virtio_9p_device_init(VirtIODevice *vdev)
+{
+ DeviceState *qdev = DEVICE(vdev);
+ V9fsState *s = VIRTIO_9P(vdev);
+ V9fsConf *fsconf = &(s->fsconf);
+ if (virtio_9p_common_init(qdev, fsconf, &s) == NULL) {
+ return -1;
+ }
+ return 0;
+}
+
+static Property virtio_9p_properties[] = {
+ DEFINE_VIRTIO_9P_PROPERTIES(V9fsState, fsconf),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_9p_class_init(ObjectClass *klass, void *data)
+{
+ DeviceClass *dc = DEVICE_CLASS(klass);
+ VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
+ dc->props = virtio_9p_properties;
+ vdc->init = virtio_9p_device_init;
+ vdc->get_features = virtio_9p_get_features;
+ vdc->get_config = virtio_9p_get_config;
+}
+
+static const TypeInfo virtio_device_info = {
+ .name = TYPE_VIRTIO_9P,
+ .parent = TYPE_VIRTIO_DEVICE,
+ .instance_size = sizeof(V9fsState),
+ .class_init = virtio_9p_class_init,
};
static void virtio_9p_register_types(void)
{
+ type_register_static(&virtio_device_info);
type_register_static(&virtio_9p_info);
virtio_9p_set_fd_limit();
}
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index 406fe52..3be634f 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -225,6 +225,7 @@ typedef struct V9fsState
CoRwlock rename_lock;
int32_t root_fid;
Error *migration_blocker;
+ V9fsConf fsconf;
} V9fsState;
typedef struct V9fsStatState {
@@ -402,4 +403,14 @@ extern int v9fs_name_to_path(V9fsState *s, V9fsPath
*dirpath,
#define pdu_unmarshal(pdu, offset, fmt, args...) \
v9fs_unmarshal(pdu->elem.out_sg, pdu->elem.out_num, offset, 1, fmt, ##args)
+#define TYPE_VIRTIO_9P "virtio-9p"
+#define VIRTIO_9P(obj) \
+ OBJECT_CHECK(V9fsState, (obj), TYPE_VIRTIO_9P)
+
+#define DEFINE_VIRTIO_9P_PROPERTIES(_state, _field) \
+ DEFINE_PROP_STRING("mount_tag", _state, _field.tag), \
+ DEFINE_PROP_STRING("fsdev", _state, _field.fsdev_id)
+
+void virtio_9p_set_conf(DeviceState *dev, V9fsConf *conf);
+
#endif
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 7d66c51..0e45b1a 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -23,6 +23,7 @@
#include "virtio-serial.h"
#include "virtio-scsi.h"
#include "virtio-balloon.h"
+#include "9pfs/virtio-9p.h"
#include "pci/pci.h"
#include "qemu/error-report.h"
#include "pci/msi.h"
@@ -829,6 +830,10 @@ static void virtio_pci_device_plugged(DeviceState *d)
pci_config_set_class(proxy->pci_dev.config,
PCI_CLASS_COMMUNICATION_OTHER);
break;
+ case VIRTIO_ID_9P:
+ pci_config_set_device_id(proxy->pci_dev.config, 0x1009);
+ pci_config_set_class(proxy->pci_dev.config, 0x0002);
+ break;
default:
error_report("unknown device id\n");
break;
--
1.7.11.7
- [Qemu-devel] [PATCH 50/61] virtio-serial : cleanup : init and exit functions., (continued)
- [Qemu-devel] [PATCH 50/61] virtio-serial : cleanup : init and exit functions., fred . konrad, 2013/01/07
- [Qemu-devel] [PATCH 42/61] virtio-rng-pci : switch to the new API., fred . konrad, 2013/01/07
- [Qemu-devel] [PATCH 47/61] virtio-serial : add the virtio-serial device., fred . konrad, 2013/01/07
- [Qemu-devel] [PATCH 61/61] virtio : cleanup : init and exit function., fred . konrad, 2013/01/07
- [Qemu-devel] [PATCH 51/61] virtio-serial : cleanup : use QOM casts., fred . konrad, 2013/01/07
- [Qemu-devel] [PATCH 56/61] virtio-9p : cleanup : QOM casts., fred . konrad, 2013/01/07
- [Qemu-devel] [PATCH 59/61] s390-virtio-bus : cleanup, fred . konrad, 2013/01/07
- [Qemu-devel] [PATCH 57/61] virtio : remove the function pointer., fred . konrad, 2013/01/07
- [Qemu-devel] [PATCH 22/61] virtio-scsi : show the VirtIOSCSI structure., fred . konrad, 2013/01/07
- [Qemu-devel] [PATCH 58/61] virtio-pci : cleanup : init, exit and reset functions., fred . konrad, 2013/01/07
- [Qemu-devel] [PATCH 53/61] virtio-9p : add the virtio-9p device.,
fred . konrad <=
- [Qemu-devel] [PATCH 25/61] virtio-scsi : moving host_features from properties to transport properties., fred . konrad, 2013/01/07
- [Qemu-devel] [PATCH 55/61] virtio-9p : cleanup : init function., fred . konrad, 2013/01/07
- [Qemu-devel] [PATCH 54/61] virtio-9p-pci : switch to the new API., fred . konrad, 2013/01/07
- [Qemu-devel] [PATCH 60/61] virtio : remove virtiobindings., fred . konrad, 2013/01/07
- Re: [Qemu-devel] [PATCH 00/61] Virtio refactoring., Anthony Liguori, 2013/01/07
- [Qemu-devel] [PATCH 44/61] virtio-rng.c : cleanup : remove qdev field., fred . konrad, 2013/01/07