[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 33/43] qdev-properties: add size32 property type
From: |
Kevin Wolf |
Subject: |
[PULL 33/43] qdev-properties: add size32 property type |
Date: |
Wed, 17 Jun 2020 16:48:59 +0200 |
From: Roman Kagan <rvkagan@yandex-team.ru>
Introduce size32 property type which handles size suffixes (k, m, g)
just like size property, but is uint32_t rather than uint64_t. It's
going to be useful for properties that are byte sizes but are inherently
32bit, like BlkConf.opt_io_size or .discard_granularity (they are
switched to this new property type in a followup commit).
The getter for size32 is left out for a separate patch as its benefit is
less obvious, and it affects test output; for now the regular uint32
getter is used.
Signed-off-by: Roman Kagan <rvkagan@yandex-team.ru>
Message-Id: <20200528225516.1676602-5-rvkagan@yandex-team.ru>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
include/hw/qdev-properties.h | 3 +++
hw/core/qdev-properties.c | 40 ++++++++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+)
diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
index f161604fb6..c03eadfad6 100644
--- a/include/hw/qdev-properties.h
+++ b/include/hw/qdev-properties.h
@@ -29,6 +29,7 @@ extern const PropertyInfo qdev_prop_drive;
extern const PropertyInfo qdev_prop_drive_iothread;
extern const PropertyInfo qdev_prop_netdev;
extern const PropertyInfo qdev_prop_pci_devfn;
+extern const PropertyInfo qdev_prop_size32;
extern const PropertyInfo qdev_prop_blocksize;
extern const PropertyInfo qdev_prop_pci_host_devaddr;
extern const PropertyInfo qdev_prop_uuid;
@@ -196,6 +197,8 @@ extern const PropertyInfo qdev_prop_pcie_link_width;
BlockdevOnError)
#define DEFINE_PROP_BIOS_CHS_TRANS(_n, _s, _f, _d) \
DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_bios_chs_trans, int)
+#define DEFINE_PROP_SIZE32(_n, _s, _f, _d) \
+ DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_size32, uint32_t)
#define DEFINE_PROP_BLOCKSIZE(_n, _s, _f) \
DEFINE_PROP_UNSIGNED(_n, _s, _f, 0, qdev_prop_blocksize, uint16_t)
#define DEFINE_PROP_PCI_HOST_DEVADDR(_n, _s, _f) \
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 249dc69bd8..40c13f6ebe 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -727,6 +727,46 @@ const PropertyInfo qdev_prop_pci_devfn = {
.set_default_value = set_default_value_int,
};
+/* --- 32bit unsigned int 'size' type --- */
+
+static void set_size32(Object *obj, Visitor *v, const char *name, void *opaque,
+ Error **errp)
+{
+ DeviceState *dev = DEVICE(obj);
+ Property *prop = opaque;
+ uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
+ uint64_t value;
+ Error *local_err = NULL;
+
+ if (dev->realized) {
+ qdev_prop_set_after_realize(dev, name, errp);
+ return;
+ }
+
+ visit_type_size(v, name, &value, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
+
+ if (value > UINT32_MAX) {
+ error_setg(errp,
+ "Property %s.%s doesn't take value %" PRIu64
+ " (maximum: %u)",
+ dev->id ? : "", name, value, UINT32_MAX);
+ return;
+ }
+
+ *ptr = value;
+}
+
+const PropertyInfo qdev_prop_size32 = {
+ .name = "size",
+ .get = get_uint32,
+ .set = set_size32,
+ .set_default_value = set_default_value_uint,
+};
+
/* --- blocksize --- */
/* lower limit is sector size */
--
2.25.4
- [PULL 23/43] hw/block/nvme: factor out pmr setup, (continued)
- [PULL 23/43] hw/block/nvme: factor out pmr setup, Kevin Wolf, 2020/06/17
- [PULL 24/43] hw/block/nvme: do cmb/pmr init as part of pci init, Kevin Wolf, 2020/06/17
- [PULL 26/43] hw/block/nvme: Verify msix_vector_use() returned value, Kevin Wolf, 2020/06/17
- [PULL 28/43] hw/block/nvme: verify msix_init_exclusive_bar() return value, Kevin Wolf, 2020/06/17
- [PULL 30/43] virtio-blk: store opt_io_size with correct size, Kevin Wolf, 2020/06/17
- [PULL 32/43] qdev-properties: blocksize: use same limits in code and description, Kevin Wolf, 2020/06/17
- [PULL 27/43] hw/block/nvme: add msix_qsize parameter, Kevin Wolf, 2020/06/17
- [PULL 31/43] block: consolidate blocksize properties consistency checks, Kevin Wolf, 2020/06/17
- [PULL 29/43] .gitignore: Ignore storage-daemon files, Kevin Wolf, 2020/06/17
- [PULL 34/43] qdev-properties: make blocksize accept size suffixes, Kevin Wolf, 2020/06/17
- [PULL 33/43] qdev-properties: add size32 property type,
Kevin Wolf <=
- [PULL 35/43] block: make BlockConf size props 32bit and accept size suffixes, Kevin Wolf, 2020/06/17
- [PULL 36/43] qdev-properties: add getter for size32 and blocksize, Kevin Wolf, 2020/06/17
- [PULL 38/43] iotests.py: Add skip_for_formats() decorator, Kevin Wolf, 2020/06/17
- [PULL 40/43] iotests/292: data_file is unsupported, Kevin Wolf, 2020/06/17
- [PULL 37/43] block: lift blocksize property limit to 2 MiB, Kevin Wolf, 2020/06/17
- [PULL 41/43] iotests/229: data_file is unsupported, Kevin Wolf, 2020/06/17
- [PULL 42/43] iotests/{190,291}: compat=0.10 is unsupported, Kevin Wolf, 2020/06/17
- [PULL 39/43] iotests/041: Skip test_small_target for qed, Kevin Wolf, 2020/06/17
- [PULL 43/43] iotests: Add copyright line in qcow2.py, Kevin Wolf, 2020/06/17
- Re: [PULL 00/43] Block layer patches, no-reply, 2020/06/17