<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">From 38a80d23c1fa7e28394933a194984a9e3a53c35b Mon Sep 17 00:00:00 2001
Message-Id: &lt;38a80d23c1fa7e28394933a194984a9e3a53c35b.1357726992.git.minovotn@redhat.com&gt;
In-Reply-To: &lt;4f8efce613a639a3c1e3022c521d6c70b7154de8.1357726992.git.minovotn@redhat.com&gt;
References: &lt;4f8efce613a639a3c1e3022c521d6c70b7154de8.1357726992.git.minovotn@redhat.com&gt;
From: Stefan Hajnoczi &lt;stefanha@redhat.com&gt;
Date: Wed, 2 Jan 2013 15:02:35 +0100
Subject: [PATCH 12/16] virtio-blk: define VirtIOBlkConf

RH-Author: Stefan Hajnoczi &lt;stefanha@redhat.com&gt;
Message-id: &lt;1357138959-1918-13-git-send-email-stefanha@redhat.com&gt;
Patchwork-id: 45525
O-Subject: [RHEL6.4 qemu-kvm PATCH v5 12/16] virtio-blk: define VirtIOBlkConf
Bugzilla: 877836
RH-Acked-by: Laszlo Ersek &lt;lersek@redhat.com&gt;
RH-Acked-by: Michael S. Tsirkin &lt;mst@redhat.com&gt;
RH-Acked-by: Paolo Bonzini &lt;pbonzini@redhat.com&gt;

From: Paolo Bonzini &lt;pbonzini@redhat.com&gt;

We will have to add another field to the virtio-blk configuration in
the next patch.  Avoid a proliferation of arguments to virtio_blk_init.

Signed-off-by: Paolo Bonzini &lt;pbonzini@redhat.com&gt;
Signed-off-by: Anthony Liguori &lt;aliguori@us.ibm.com&gt;
(cherry picked from 12c5674b846dccf1f80fb43b64606721e6f78976)

Conflicts:
	hw/s390-virtio-bus.c
	hw/s390-virtio-bus.h
	hw/virtio-blk.c
	hw/virtio-pci.c
	hw/virtio-pci.h

The s390 and virtio-pci.c conflicts are mostly because RHEL qemu-kvm
doesn't have QEMU Object Model qdev changes.

Signed-off-by: Stefan Hajnoczi &lt;stefanha@redhat.com&gt;
---
 hw/s390-virtio-bus.c |  7 +++----
 hw/s390-virtio-bus.h |  5 +++--
 hw/virtio-blk.c      | 27 +++++++++++++--------------
 hw/virtio-blk.h      |  7 +++++++
 hw/virtio-pci.c      | 12 +++++-------
 hw/virtio.h          |  4 ++--
 6 files changed, 33 insertions(+), 29 deletions(-)

Signed-off-by: Michal Novotny &lt;minovotn@redhat.com&gt;
---
 hw/s390-virtio-bus.c |  7 +++----
 hw/s390-virtio-bus.h |  5 +++--
 hw/virtio-blk.c      | 27 +++++++++++++--------------
 hw/virtio-blk.h      |  7 +++++++
 hw/virtio-pci.c      | 12 +++++-------
 hw/virtio.h          |  4 ++--
 6 files changed, 33 insertions(+), 29 deletions(-)

diff --git a/hw/s390-virtio-bus.c b/hw/s390-virtio-bus.c
index d18f916..26aac5c 100644
--- a/hw/s390-virtio-bus.c
+++ b/hw/s390-virtio-bus.c
@@ -124,8 +124,7 @@ static int s390_virtio_blk_init(VirtIOS390Device *dev)
 {
     VirtIODevice *vdev;
 
-    vdev = virtio_blk_init((DeviceState *)dev, &amp;dev-&gt;block,
-                           &amp;dev-&gt;block_serial);
+    vdev = virtio_blk_init((DeviceState *)dev, &amp;dev-&gt;blk);
     if (!vdev) {
         return -1;
     }
@@ -344,8 +343,8 @@ static VirtIOS390DeviceInfo s390_virtio_blk = {
     .qdev.name = "virtio-blk-s390",
     .qdev.size = sizeof(VirtIOS390Device),
     .qdev.props = (Property[]) {
-        DEFINE_BLOCK_PROPERTIES(VirtIOS390Device, block),
-        DEFINE_PROP_STRING("serial", VirtIOS390Device, block_serial),
+        DEFINE_BLOCK_PROPERTIES(VirtIOS390Device, blk.conf),
+        DEFINE_PROP_STRING("serial", VirtIOS390Device, blk.serial),
         DEFINE_PROP_END_OF_LIST(),
     },
 };
diff --git a/hw/s390-virtio-bus.h b/hw/s390-virtio-bus.h
index bb0b9a7..470bd50 100644
--- a/hw/s390-virtio-bus.h
+++ b/hw/s390-virtio-bus.h
@@ -17,6 +17,8 @@
  * License along with this library; if not, see &lt;http://www.gnu.org/licenses/&gt;.
  */
 
+#include "virtio-blk.h"
+
 #define VIRTIO_DEV_OFFS_TYPE		0	/* 8 bits */
 #define VIRTIO_DEV_OFFS_NUM_VQ		1	/* 8 bits */
 #define VIRTIO_DEV_OFFS_FEATURE_LEN	2	/* 8 bits */
@@ -38,8 +40,7 @@ typedef struct VirtIOS390Device {
     ram_addr_t feat_offs;
     uint8_t feat_len;
     VirtIODevice *vdev;
-    BlockConf block;
-    char *block_serial;
+    VirtIOBlkConf blk;
     NICConf nic;
     uint32_t host_features;
     /* Max. number of ports we can have for a the virtio-serial device */
diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 8b3be64..d6e8423 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -28,7 +28,7 @@ typedef struct VirtIOBlock
     void *rq;
     QEMUBH *bh;
     BlockConf *conf;
-    char *serial;
+    VirtIOBlkConf *blk;
     unsigned short sector_mask;
     DeviceState *qdev;
 } VirtIOBlock;
@@ -397,7 +397,7 @@ static void virtio_blk_handle_request(VirtIOBlockReq *req,
          * terminated by '\0' only when shorter than buffer.
          */
         strncpy(req-&gt;elem.in_sg[0].iov_base,
-                s-&gt;serial ? s-&gt;serial : "",
+                s-&gt;blk-&gt;serial ? s-&gt;blk-&gt;serial : "",
                 MIN(req-&gt;elem.in_sg[0].iov_len, VIRTIO_BLK_ID_BYTES));
         virtio_blk_req_complete(req, VIRTIO_BLK_S_OK);
         qemu_free(req);
@@ -591,28 +591,27 @@ static const BlockDevOps virtio_block_ops = {
     .resize_cb = virtio_blk_resize,
 };
 
-VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf,
-                              char **serial)
+VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)
 {
     VirtIOBlock *s;
     int cylinders, heads, secs;
     static int virtio_blk_id;
     DriveInfo *dinfo;
 
-    if (!conf-&gt;bs) {
+    if (!blk-&gt;conf.bs) {
         error_report("drive property not set");
         return NULL;
     }
-    if (!bdrv_is_inserted(conf-&gt;bs)) {
+    if (!bdrv_is_inserted(blk-&gt;conf.bs)) {
         error_report("Device needs media, but drive is empty");
         return NULL;
     }
 
-    if (!*serial) {
+    if (!blk-&gt;serial) {
         /* try to fall back to value set with legacy -drive serial=... */
-        dinfo = drive_get_by_blockdev(conf-&gt;bs);
+        dinfo = drive_get_by_blockdev(blk-&gt;conf.bs);
         if (*dinfo-&gt;serial) {
-            *serial = strdup(dinfo-&gt;serial);
+            blk-&gt;serial = strdup(dinfo-&gt;serial);
         }
     }
 
@@ -623,9 +622,9 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf,
     s-&gt;vdev.get_config = virtio_blk_update_config;
     s-&gt;vdev.get_features = virtio_blk_get_features;
     s-&gt;vdev.reset = virtio_blk_reset;
-    s-&gt;bs = conf-&gt;bs;
-    s-&gt;conf = conf;
-    s-&gt;serial = *serial;
+    s-&gt;bs = blk-&gt;conf.bs;
+    s-&gt;conf = &amp;blk-&gt;conf;
+    s-&gt;blk = blk;
     s-&gt;rq = NULL;
     s-&gt;sector_mask = (s-&gt;conf-&gt;logical_block_size / 512) - 1;
     bdrv_guess_geometry(s-&gt;bs, &amp;cylinders, &amp;heads, &amp;secs);
@@ -638,10 +637,10 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf,
     register_savevm(dev, "virtio-blk", virtio_blk_id++, 2,
                     virtio_blk_save, virtio_blk_load, s);
     bdrv_set_dev_ops(s-&gt;bs, &amp;virtio_block_ops, s);
-    s-&gt;bs-&gt;buffer_alignment = conf-&gt;logical_block_size;
+    s-&gt;bs-&gt;buffer_alignment = s-&gt;conf-&gt;logical_block_size;
 
     bdrv_iostatus_enable(s-&gt;bs);
-    add_boot_device_path(conf-&gt;bootindex, dev, "/disk@0,0");
+    add_boot_device_path(s-&gt;conf-&gt;bootindex, dev, "/disk@0,0");
 
     return &amp;s-&gt;vdev;
 }
diff --git a/hw/virtio-blk.h b/hw/virtio-blk.h
index 5645d2b..5eea647 100644
--- a/hw/virtio-blk.h
+++ b/hw/virtio-blk.h
@@ -97,6 +97,12 @@ struct virtio_scsi_inhdr
     uint32_t residual;
 };
 
+struct VirtIOBlkConf
+{
+    BlockConf conf;
+    char *serial;
+};
+
 #ifdef __linux__
 #define DEFINE_VIRTIO_BLK_FEATURES(_state, _field) \
         DEFINE_VIRTIO_COMMON_FEATURES(_state, _field), \
@@ -105,4 +111,5 @@ struct virtio_scsi_inhdr
 #define DEFINE_VIRTIO_BLK_FEATURES(_state, _field) \
         DEFINE_VIRTIO_COMMON_FEATURES(_state, _field)
 #endif
+
 #endif
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 9e001d2..01a1e45 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -113,8 +113,7 @@ typedef struct {
     uint32_t addr;
     uint32_t class_code;
     uint32_t nvectors;
-    BlockConf block;
-    char *block_serial;
+    VirtIOBlkConf blk;
     NICConf nic;
     VirtIOSCSIConf scsi;
     uint32_t host_features;
@@ -827,8 +826,7 @@ static int virtio_blk_init_pci(PCIDevice *pci_dev)
         proxy-&gt;class_code != PCI_CLASS_STORAGE_OTHER)
         proxy-&gt;class_code = PCI_CLASS_STORAGE_SCSI;
 
-    vdev = virtio_blk_init(&amp;pci_dev-&gt;qdev, &amp;proxy-&gt;block,
-                           &amp;proxy-&gt;block_serial);
+    vdev = virtio_blk_init(&amp;pci_dev-&gt;qdev, &amp;proxy-&gt;blk);
     if (!vdev) {
         return -1;
     }
@@ -853,7 +851,7 @@ static int virtio_blk_exit_pci(PCIDevice *pci_dev)
 
     virtio_pci_stop_ioeventfd(proxy);
     virtio_blk_exit(proxy-&gt;vdev);
-    blockdev_mark_auto_del(proxy-&gt;block.bs);
+    blockdev_mark_auto_del(proxy-&gt;blk.conf.bs);
     return virtio_exit_pci(pci_dev);
 }
 
@@ -988,8 +986,8 @@ static PCIDeviceInfo virtio_info[] = {
         .exit      = virtio_blk_exit_pci,
         .qdev.props = (Property[]) {
             DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
-            DEFINE_BLOCK_PROPERTIES(VirtIOPCIProxy, block),
-            DEFINE_PROP_STRING("serial", VirtIOPCIProxy, block_serial),
+            DEFINE_BLOCK_PROPERTIES(VirtIOPCIProxy, blk.conf),
+            DEFINE_PROP_STRING("serial", VirtIOPCIProxy, blk.serial),
             DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
                             VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
             DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
diff --git a/hw/virtio.h b/hw/virtio.h
index dadf563..e6f96e7 100644
--- a/hw/virtio.h
+++ b/hw/virtio.h
@@ -196,8 +196,8 @@ void virtio_bind_device(VirtIODevice *vdev, const VirtIOBindings *binding,
                         void *opaque);
 
 /* Base devices.  */
-VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf,
-                              char **serial);
+typedef struct VirtIOBlkConf VirtIOBlkConf;
+VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk);
 struct virtio_net_conf;
 VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf,
                               struct virtio_net_conf *net);
-- 
1.7.11.7

</pre></body></html>