aboutsummaryrefslogtreecommitdiff
path: root/hw/qdev-properties.c
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2009-07-31 12:25:40 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2009-08-10 13:05:27 -0500
commit14b41872fd4ccdb750d539f1f317ae0e070f73a4 (patch)
tree53fc8c557be4d1897bd94238a1d731b2cfc1c85f /hw/qdev-properties.c
parenta8659e90e9cb08816435f737bb90ca5a43ca48ec (diff)
qdev/prop: add drive property.
Adds a (host) drive property, intended to be used by virtual disk backend drivers. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> Message-Id:
Diffstat (limited to 'hw/qdev-properties.c')
-rw-r--r--hw/qdev-properties.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 0e4878ee8f..5a3d10d6f0 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -1,3 +1,4 @@
+#include "sysemu.h"
#include "qdev.h"
void *qdev_get_prop_ptr(DeviceState *dev, Property *prop)
@@ -141,6 +142,32 @@ PropertyInfo qdev_prop_hex64 = {
.print = print_hex64,
};
+/* --- drive --- */
+
+static int parse_drive(DeviceState *dev, Property *prop, const char *str)
+{
+ DriveInfo **ptr = qdev_get_prop_ptr(dev, prop);
+
+ *ptr = drive_get_by_id(str);
+ if (*ptr == NULL)
+ return -1;
+ return 0;
+}
+
+static int print_drive(DeviceState *dev, Property *prop, char *dest, size_t len)
+{
+ DriveInfo **ptr = qdev_get_prop_ptr(dev, prop);
+ return snprintf(dest, len, "%s", (*ptr)->id);
+}
+
+PropertyInfo qdev_prop_drive = {
+ .name = "drive",
+ .type = PROP_TYPE_DRIVE,
+ .size = sizeof(DriveInfo*),
+ .parse = parse_drive,
+ .print = print_drive,
+};
+
/* --- pointer --- */
static int print_ptr(DeviceState *dev, Property *prop, char *dest, size_t len)
@@ -325,6 +352,11 @@ void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value)
qdev_prop_set(dev, name, &value, PROP_TYPE_UINT64);
}
+void qdev_prop_set_drive(DeviceState *dev, const char *name, DriveInfo *value)
+{
+ qdev_prop_set(dev, name, &value, PROP_TYPE_DRIVE);
+}
+
void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value)
{
qdev_prop_set(dev, name, &value, PROP_TYPE_PTR);