Patchwork [RFC,V4,6/6] virtio-blk : Refactoring virtio-blk.

login
register
mail settings
Submitter fred.konrad@greensocs.com
Date Nov. 30, 2012, 5:12 p.m.
Message ID <1354295530-18644-7-git-send-email-fred.konrad@greensocs.com>
Download mbox | patch
Permalink /patch/203003/
State New
Headers show

Comments

fred.konrad@greensocs.com - Nov. 30, 2012, 5:12 p.m.
From: KONRAD Frederic <fred.konrad@greensocs.com>

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-blk.c |   61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/virtio-blk.h |   16 ++++++++++++++
 2 files changed, 77 insertions(+), 0 deletions(-)
Peter Maydell - Nov. 30, 2012, 6:42 p.m.
On 30 November 2012 17:12,  <fred.konrad@greensocs.com> wrote:
> From: KONRAD Frederic <fred.konrad@greensocs.com>

This is a dreadful commit message.

>
> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
> ---
>  hw/virtio-blk.c |   61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  hw/virtio-blk.h |   16 ++++++++++++++
>  2 files changed, 77 insertions(+), 0 deletions(-)
>
> diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
> index e25cc96..3547882 100644
> --- a/hw/virtio-blk.c
> +++ b/hw/virtio-blk.c
> @@ -656,3 +656,64 @@ void virtio_blk_exit(VirtIODevice *vdev)
>      blockdev_mark_auto_del(s->bs);
>      virtio_cleanup(vdev);
>  }
> +
> +/*
> + * Refactored virtio-blk.

...and a not very useful comment.

> + */

-- PMM

Patch

diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index e25cc96..3547882 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -656,3 +656,64 @@  void virtio_blk_exit(VirtIODevice *vdev)
     blockdev_mark_auto_del(s->bs);
     virtio_cleanup(vdev);
 }
+
+/*
+ * Refactored virtio-blk.
+ */
+
+static int virtio_device_init(DeviceState *qdev)
+{
+    VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
+    /*
+     * TODO: device initialization.
+     */
+    return 0;
+}
+
+static void virtio_device_exit(DeviceState *dev)
+{
+    /*
+     * TODO: destroy device.
+     */
+}
+
+static Property virtio_blk_properties[] = {
+    DEFINE_BLOCK_PROPERTIES(VirtioBlkState, blk.conf),
+    DEFINE_BLOCK_CHS_PROPERTIES(VirtioBlkState, blk.conf),
+    DEFINE_PROP_STRING("serial", VirtioBlkState, blk.serial),
+#ifdef __linux__
+    DEFINE_PROP_BIT("scsi", VirtioBlkState, blk.scsi, 0, true),
+#endif
+    DEFINE_PROP_BIT("config-wce", VirtioBlkState, blk.config_wce, 0, true),
+    DEFINE_VIRTIO_BLK_FEATURES(VirtioBlkState, host_features),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_blk_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
+    dc->init = virtio_device_init;
+    dc->exit = virtio_device_exit;
+    dc->props = virtio_blk_properties;
+    /* VirtioDeviceClass */
+    vdc->get_config = virtio_blk_update_config;
+    vdc->set_config = virtio_blk_set_config;
+    vdc->get_features = virtio_blk_get_features;
+    vdc->set_status = virtio_blk_set_status;
+    vdc->reset = virtio_blk_reset;
+}
+
+static const TypeInfo virtio_device_info = {
+    .name = TYPE_VIRTIO_BLK,
+    .parent = TYPE_VIRTIO_DEVICE,
+    .instance_size = sizeof(VirtioBlkState),
+    .class_init = virtio_blk_class_init,
+};
+
+static void virtio_register_types(void)
+{
+    type_register_static(&virtio_device_info);
+}
+
+type_init(virtio_register_types)
diff --git a/hw/virtio-blk.h b/hw/virtio-blk.h
index f0740d0..13876e7 100644
--- a/hw/virtio-blk.h
+++ b/hw/virtio-blk.h
@@ -111,4 +111,20 @@  struct VirtIOBlkConf
         DEFINE_VIRTIO_COMMON_FEATURES(_state, _field), \
         DEFINE_PROP_BIT("config-wce", _state, _field, VIRTIO_BLK_F_CONFIG_WCE, true)
 
+/*
+ * Refactored virtio-blk.
+ */
+
+#define TYPE_VIRTIO_BLK "virtio-blk"
+#define VIRTIO_BLK(obj) \
+        OBJECT_CHECK(VirtioBlkState, (obj), TYPE_VIRTIO_BLK)
+
+typedef struct {
+    DeviceState parent_obj;
+
+    /* virtio-blk specific */
+    VirtIOBlkConf blk;
+    uint32_t host_features;
+} VirtioBlkState;
+
 #endif