From: Roman Kagan <rvkagan@yandex-team.ru>
To: qemu-devel@nongnu.org
Cc: "Fam Zheng" <fam@euphon.net>, "Kevin Wolf" <kwolf@redhat.com>,
"Stefano Stabellini" <sstabellini@kernel.org>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Eduardo Habkost" <ehabkost@redhat.com>,
qemu-block@nongnu.org, "Paul Durrant" <paul@xen.org>,
"John Snow" <jsnow@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Laurent Vivier" <laurent@vivier.eu>,
"Eric Blake" <eblake@redhat.com>, "Max Reitz" <mreitz@redhat.com>,
"Keith Busch" <kbusch@kernel.org>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Anthony Perard" <anthony.perard@citrix.com>,
xen-devel@lists.xenproject.org,
"Philippe Mathieu-Daudé" <philmd@redhat.com>
Subject: [PATCH v8 4/8] qdev-properties: add size32 property type
Date: Fri, 29 May 2020 01:55:12 +0300 [thread overview]
Message-ID: <20200528225516.1676602-5-rvkagan@yandex-team.ru> (raw)
In-Reply-To: <20200528225516.1676602-1-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>
---
v7 -> v8:
- replace stringify with %u in the error message [Eric]
- fix wording in the log [Eric]
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.26.2
next prev parent reply other threads:[~2020-05-28 22:56 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-28 22:55 [PATCH v8 0/8] block: enhance handling of size-related BlockConf properties Roman Kagan
2020-05-28 22:55 ` [PATCH v8 1/8] virtio-blk: store opt_io_size with correct size Roman Kagan
2020-05-28 22:55 ` [PATCH v8 2/8] block: consolidate blocksize properties consistency checks Roman Kagan
2020-05-29 9:53 ` Markus Armbruster
2020-05-29 10:56 ` Roman Kagan
2020-06-02 11:42 ` Kevin Wolf
2020-05-28 22:55 ` [PATCH v8 3/8] qdev-properties: blocksize: use same limits in code and description Roman Kagan
2020-05-28 22:55 ` Roman Kagan [this message]
2020-05-28 22:55 ` [PATCH v8 5/8] qdev-properties: make blocksize accept size suffixes Roman Kagan
2020-06-02 12:06 ` Philippe Mathieu-Daudé
2020-05-28 22:55 ` [PATCH v8 6/8] block: make BlockConf size props 32bit and " Roman Kagan
2020-05-28 22:55 ` [PATCH v8 7/8] qdev-properties: add getter for size32 and blocksize Roman Kagan
2020-05-28 22:55 ` [PATCH v8 8/8] block: lift blocksize property limit to 2 MiB Roman Kagan
2020-06-15 18:05 ` [PATCH v8 0/8] block: enhance handling of size-related BlockConf properties Roman Kagan
2020-06-16 16:09 ` Kevin Wolf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200528225516.1676602-5-rvkagan@yandex-team.ru \
--to=rvkagan@yandex-team.ru \
--cc=anthony.perard@citrix.com \
--cc=berrange@redhat.com \
--cc=eblake@redhat.com \
--cc=ehabkost@redhat.com \
--cc=fam@euphon.net \
--cc=jsnow@redhat.com \
--cc=kbusch@kernel.org \
--cc=kraxel@redhat.com \
--cc=kwolf@redhat.com \
--cc=laurent@vivier.eu \
--cc=mreitz@redhat.com \
--cc=mst@redhat.com \
--cc=paul@xen.org \
--cc=pbonzini@redhat.com \
--cc=philmd@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=sstabellini@kernel.org \
--cc=stefanha@redhat.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).