From: "Andreas Färber" <afaerber@suse.de>
To: qemu-devel@nongnu.org
Cc: "Kevin Wolf" <kwolf@redhat.com>,
"Blue Swirl" <blauwirbel@gmail.com>,
"Anthony Liguori" <aliguori@us.ibm.com>,
"Juan Quintela" <quintela@redhat.com>,
qemu-trivial@nongnu.org, "Jan Kiszka" <jan.kiszka@siemens.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Vasilis Liaskovitis" <vasilis.liaskovitis@profitbricks.com>,
"Andreas Färber" <andreas.faerber@web.de>,
"Amit Shah" <amit.shah@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>
Subject: [Qemu-devel] [PATCH v6] qdev: Add support for property type bool
Date: Tue, 24 Jan 2012 18:17:36 +0100 [thread overview]
Message-ID: <1327425457-31313-1-git-send-email-afaerber@suse.de> (raw)
From: Andreas Färber <andreas.faerber@web.de>
VMState supports the type bool but qdev instead supports bit, backed by
uint32_t. Therefore let's add DEFINE_PROP_BOOL() and qdev_prop_set_bool().
bool by definition is either true or false. Should the need arise to
parse yes/no, on/off, 1/0 or whatever as well, we can still add that at
a later point in time.
Signed-off-by: Andreas Färber <andreas.faerber@web.de>
Cc: Juan Quintela <quintela@redhat.com>
Cc: Markus Armbruster <armbru@redhat.com>
Cc: Jan Kiszka <jan.kiszka@siemens.com>
Cc: Vasilis Liaskovitis <vasilis.liaskovitis@profitbricks.com>
---
v5 -> v6:
* Rebased onto QOM properties.
* Parse and print true/false for bool, leave bit untouched.
Please review, v6 untested.
v4 -> v5 (40P):
* Parse on/off in addition to yes/no for both bit and bool, print yes/no for bool.
v4 (ISA):
* Introduced.
hw/qdev-properties.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++
hw/qdev.h | 4 +++
2 files changed, 66 insertions(+), 0 deletions(-)
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 02f0dae..612f2ea 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -96,6 +96,68 @@ PropertyInfo qdev_prop_bit = {
.set = set_bit,
};
+/* --- bool --- */
+
+static int parse_bool(DeviceState *dev, Property *prop, const char *str)
+{
+ bool *ptr = qdev_get_prop_ptr(dev, prop);
+ if (strcmp(str, "true") == 0) {
+ *ptr = true;
+ } else if (strcmp(str, "false") == 0) {
+ *ptr = false;
+ } else {
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+static int print_bool(DeviceState *dev, Property *prop, char *dest, size_t len)
+{
+ bool *ptr = qdev_get_prop_ptr(dev, prop);
+ return snprintf(dest, len, *ptr ? "true" : "false");
+}
+
+static void get_bool(DeviceState *dev, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ Property *prop = opaque;
+ bool *ptr = qdev_get_prop_ptr(dev, prop);
+
+ visit_type_bool(v, ptr, name, errp);
+}
+
+static void set_bool(DeviceState *dev, Visitor *v, void *opaque,
+ const char *name, Error **errp)
+{
+ Property *prop = opaque;
+ bool *ptr = qdev_get_prop_ptr(dev, prop);
+ Error *local_err = NULL;
+ bool value;
+
+ if (dev->state != DEV_STATE_CREATED) {
+ error_set(errp, QERR_PERMISSION_DENIED);
+ return;
+ }
+
+ visit_type_bool(v, &value, name, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return;
+ }
+ *ptr = value;
+}
+
+PropertyInfo qdev_prop_bool = {
+ .name = "bool",
+ .type = PROP_TYPE_BOOL,
+ .size = sizeof(bool),
+ .parse = parse_bool,
+ .print = print_bool,
+ .get = get_bool,
+ .set = set_bool,
+};
+
/* --- 8bit integer --- */
static int parse_uint8(DeviceState *dev, Property *prop, const char *str)
diff --git a/hw/qdev.h b/hw/qdev.h
index 6b58dd8..5e34d90 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -152,6 +152,7 @@ enum PropertyType {
PROP_TYPE_VLAN,
PROP_TYPE_PTR,
PROP_TYPE_BIT,
+ PROP_TYPE_BOOL,
};
struct PropertyInfo {
@@ -276,6 +277,7 @@ int do_device_del(Monitor *mon, const QDict *qdict, QObject **ret_data);
/*** qdev-properties.c ***/
extern PropertyInfo qdev_prop_bit;
+extern PropertyInfo qdev_prop_bool;
extern PropertyInfo qdev_prop_uint8;
extern PropertyInfo qdev_prop_uint16;
extern PropertyInfo qdev_prop_uint32;
@@ -315,6 +317,8 @@ extern PropertyInfo qdev_prop_pci_devfn;
.defval = (bool[]) { (_defval) }, \
}
+#define DEFINE_PROP_BOOL(_n, _s, _f, _d) \
+ DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_bool, bool)
#define DEFINE_PROP_UINT8(_n, _s, _f, _d) \
DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
#define DEFINE_PROP_UINT16(_n, _s, _f, _d) \
--
1.7.7
next reply other threads:[~2012-01-24 17:19 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-24 17:17 Andreas Färber [this message]
2012-01-24 17:29 ` [Qemu-devel] [PATCH v6] qdev: Add support for property type bool Jan Kiszka
2012-01-24 17:38 ` Andreas Färber
2012-01-24 17:59 ` Anthony Liguori
2012-01-24 17:59 ` Jan Kiszka
2012-01-26 15:02 ` Andreas Färber
2012-01-27 6:23 ` Stefan Hajnoczi
2012-01-27 9:38 ` Andreas Färber
2012-01-27 12:41 ` Anthony Liguori
2012-01-27 13:22 ` Andreas Färber
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=1327425457-31313-1-git-send-email-afaerber@suse.de \
--to=afaerber@suse.de \
--cc=aliguori@us.ibm.com \
--cc=amit.shah@redhat.com \
--cc=andreas.faerber@web.de \
--cc=armbru@redhat.com \
--cc=blauwirbel@gmail.com \
--cc=jan.kiszka@siemens.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
--cc=quintela@redhat.com \
--cc=vasilis.liaskovitis@profitbricks.com \
/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).