[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 21/55] virtio-blk: move config size params to virtio-blk-common
From: |
Michael S. Tsirkin |
Subject: |
[PULL 21/55] virtio-blk: move config size params to virtio-blk-common |
Date: |
Mon, 10 Oct 2022 13:30:09 -0400 |
From: Daniil Tatianin <d-tatianin@yandex-team.ru>
This way we can reuse it for other virtio-blk devices, e.g
vhost-user-blk, which currently does not control its config space size
dynamically.
Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru>
Reviewed-by: Raphael Norwitz <raphael.norwitz@nutanix.com>
Message-Id: <20220906073111.353245-3-d-tatianin@yandex-team.ru>
Reviewed-by: Raphael Norwitz <raphael.norwitz@nutanix.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
include/hw/virtio/virtio-blk-common.h | 20 ++++++++++++++
hw/block/virtio-blk-common.c | 39 +++++++++++++++++++++++++++
hw/block/virtio-blk.c | 24 ++---------------
MAINTAINERS | 2 ++
hw/block/meson.build | 2 +-
5 files changed, 64 insertions(+), 23 deletions(-)
create mode 100644 include/hw/virtio/virtio-blk-common.h
create mode 100644 hw/block/virtio-blk-common.c
diff --git a/include/hw/virtio/virtio-blk-common.h
b/include/hw/virtio/virtio-blk-common.h
new file mode 100644
index 0000000000..31daada3e3
--- /dev/null
+++ b/include/hw/virtio/virtio-blk-common.h
@@ -0,0 +1,20 @@
+/*
+ * Virtio Block Device common helpers
+ *
+ * Copyright IBM, Corp. 2007
+ *
+ * Authors:
+ * Anthony Liguori <aliguori@us.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ */
+
+#ifndef VIRTIO_BLK_COMMON_H
+#define VIRTIO_BLK_COMMON_H
+
+#include "hw/virtio/virtio.h"
+
+extern const VirtIOConfigSizeParams virtio_blk_cfg_size_params;
+
+#endif
diff --git a/hw/block/virtio-blk-common.c b/hw/block/virtio-blk-common.c
new file mode 100644
index 0000000000..ac52d7c176
--- /dev/null
+++ b/hw/block/virtio-blk-common.c
@@ -0,0 +1,39 @@
+/*
+ * Virtio Block Device common helpers
+ *
+ * Copyright IBM, Corp. 2007
+ *
+ * Authors:
+ * Anthony Liguori <aliguori@us.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2. See
+ * the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+
+#include "standard-headers/linux/virtio_blk.h"
+#include "hw/virtio/virtio.h"
+#include "hw/virtio/virtio-blk-common.h"
+
+/* Config size before the discard support (hide associated config fields) */
+#define VIRTIO_BLK_CFG_SIZE offsetof(struct virtio_blk_config, \
+ max_discard_sectors)
+
+/*
+ * Starting from the discard feature, we can use this array to properly
+ * set the config size depending on the features enabled.
+ */
+static const VirtIOFeature feature_sizes[] = {
+ {.flags = 1ULL << VIRTIO_BLK_F_DISCARD,
+ .end = endof(struct virtio_blk_config, discard_sector_alignment)},
+ {.flags = 1ULL << VIRTIO_BLK_F_WRITE_ZEROES,
+ .end = endof(struct virtio_blk_config, write_zeroes_may_unmap)},
+ {}
+};
+
+const VirtIOConfigSizeParams virtio_blk_cfg_size_params = {
+ .min_size = VIRTIO_BLK_CFG_SIZE,
+ .max_size = sizeof(struct virtio_blk_config),
+ .feature_sizes = feature_sizes
+};
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index 10c47c2934..8131ec2dbc 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -32,29 +32,9 @@
#include "hw/virtio/virtio-bus.h"
#include "migration/qemu-file-types.h"
#include "hw/virtio/virtio-access.h"
+#include "hw/virtio/virtio-blk-common.h"
#include "qemu/coroutine.h"
-/* Config size before the discard support (hide associated config fields) */
-#define VIRTIO_BLK_CFG_SIZE offsetof(struct virtio_blk_config, \
- max_discard_sectors)
-/*
- * Starting from the discard feature, we can use this array to properly
- * set the config size depending on the features enabled.
- */
-static const VirtIOFeature feature_sizes[] = {
- {.flags = 1ULL << VIRTIO_BLK_F_DISCARD,
- .end = endof(struct virtio_blk_config, discard_sector_alignment)},
- {.flags = 1ULL << VIRTIO_BLK_F_WRITE_ZEROES,
- .end = endof(struct virtio_blk_config, write_zeroes_may_unmap)},
- {}
-};
-
-static const VirtIOConfigSizeParams cfg_size_params = {
- .min_size = VIRTIO_BLK_CFG_SIZE,
- .max_size = sizeof(struct virtio_blk_config),
- .feature_sizes = feature_sizes
-};
-
static void virtio_blk_init_request(VirtIOBlock *s, VirtQueue *vq,
VirtIOBlockReq *req)
{
@@ -1202,7 +1182,7 @@ static void virtio_blk_device_realize(DeviceState *dev,
Error **errp)
return;
}
- s->config_size = virtio_get_config_size(&cfg_size_params,
+ s->config_size = virtio_get_config_size(&virtio_blk_cfg_size_params,
s->host_features);
virtio_init(vdev, VIRTIO_ID_BLOCK, s->config_size);
diff --git a/MAINTAINERS b/MAINTAINERS
index d0c0c8a55b..05b75805eb 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2030,8 +2030,10 @@ virtio-blk
M: Stefan Hajnoczi <stefanha@redhat.com>
L: qemu-block@nongnu.org
S: Supported
+F: hw/block/virtio-blk-common.c
F: hw/block/virtio-blk.c
F: hw/block/dataplane/*
+F: include/hw/virtio/virtio-blk-common.h
F: tests/qtest/virtio-blk-test.c
T: git https://github.com/stefanha/qemu.git block
diff --git a/hw/block/meson.build b/hw/block/meson.build
index 2389326112..8ee1f1f850 100644
--- a/hw/block/meson.build
+++ b/hw/block/meson.build
@@ -16,7 +16,7 @@ softmmu_ss.add(when: 'CONFIG_SWIM', if_true: files('swim.c'))
softmmu_ss.add(when: 'CONFIG_XEN', if_true: files('xen-block.c'))
softmmu_ss.add(when: 'CONFIG_TC58128', if_true: files('tc58128.c'))
-specific_ss.add(when: 'CONFIG_VIRTIO_BLK', if_true: files('virtio-blk.c'))
+specific_ss.add(when: 'CONFIG_VIRTIO_BLK', if_true: files('virtio-blk.c',
'virtio-blk-common.c'))
specific_ss.add(when: 'CONFIG_VHOST_USER_BLK', if_true:
files('vhost-user-blk.c'))
subdir('dataplane')
--
MST
- [PULL 11/55] tests/qtest: pass stdout/stderr down to subtests, (continued)
- [PULL 11/55] tests/qtest: pass stdout/stderr down to subtests, Michael S. Tsirkin, 2022/10/10
- [PULL 12/55] tests/qtest: add a timeout for subprocess_run_one_test, Michael S. Tsirkin, 2022/10/10
- [PULL 13/55] tests/qtest: use qos_printf instead of g_test_message, Michael S. Tsirkin, 2022/10/10
- [PULL 14/55] tests/qtest: catch unhandled vhost-user messages, Michael S. Tsirkin, 2022/10/10
- [PULL 15/55] tests/qtest: plain g_assert for VHOST_USER_F_PROTOCOL_FEATURES, Michael S. Tsirkin, 2022/10/10
- [PULL 16/55] tests/qtest: add assert to catch bad features, Michael S. Tsirkin, 2022/10/10
- [PULL 17/55] tests/qtest: implement stub for VHOST_USER_GET_CONFIG, Michael S. Tsirkin, 2022/10/10
- [PULL 18/55] tests/qtest: add a get_features op to vhost-user-test, Michael S. Tsirkin, 2022/10/10
- [PULL 19/55] tests/qtest: enable tests for virtio-gpio, Michael S. Tsirkin, 2022/10/10
- [PULL 20/55] virtio: introduce VirtIOConfigSizeParams & virtio_get_config_size, Michael S. Tsirkin, 2022/10/10
- [PULL 21/55] virtio-blk: move config size params to virtio-blk-common,
Michael S. Tsirkin <=
- [PULL 22/55] vhost-user-blk: make it possible to disable write-zeroes/discard, Michael S. Tsirkin, 2022/10/10
- [PULL 23/55] vhost-user-blk: make 'config_wce' part of 'host_features', Michael S. Tsirkin, 2022/10/10
- [PULL 24/55] vhost-user-blk: dynamically resize config space based on features, Michael S. Tsirkin, 2022/10/10
- [PULL 25/55] tests/acpi: virt: allow acpi GTDT changes, Michael S. Tsirkin, 2022/10/10
- [PULL 26/55] acpi: arm/virt: build_gtdt: fix invalid 64-bit physical addresses, Michael S. Tsirkin, 2022/10/10
- [PULL 27/55] tests/acpi: virt: update ACPI GTDT binaries, Michael S. Tsirkin, 2022/10/10
- [PULL 28/55] mem/cxl-type3: Add sn option to provide serial number for PCI ecap, Michael S. Tsirkin, 2022/10/10
- [PULL 29/55] Revert "intel_iommu: Fix irqchip / X2APIC configuration checks", Michael S. Tsirkin, 2022/10/10