qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 09/10] qdev/prop: add drive property.
Date: Fri, 31 Jul 2009 12:25:40 +0200	[thread overview]
Message-ID: <1249035941-4562-10-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1249035941-4562-1-git-send-email-kraxel@redhat.com>

Adds a (host) drive property, intended to be used by virtual disk
backend drivers.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/qdev-properties.c |   32 ++++++++++++++++++++++++++++++++
 hw/qdev.h            |    4 ++++
 2 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 0e4878e..5a3d10d 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);
diff --git a/hw/qdev.h b/hw/qdev.h
index 0f0acb1..91d9f5f 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -2,6 +2,7 @@
 #define QDEV_H
 
 #include "hw.h"
+#include "sysemu.h"
 #include "sys-queue.h"
 #include "qemu-option.h"
 
@@ -63,6 +64,7 @@ enum PropertyType {
     PROP_TYPE_UINT64,
     PROP_TYPE_TADDR,
     PROP_TYPE_MACADDR,
+    PROP_TYPE_DRIVE,
     PROP_TYPE_PTR,
 };
 
@@ -155,6 +157,7 @@ extern PropertyInfo qdev_prop_hex32;
 extern PropertyInfo qdev_prop_hex64;
 extern PropertyInfo qdev_prop_ptr;
 extern PropertyInfo qdev_prop_macaddr;
+extern PropertyInfo qdev_prop_drive;
 extern PropertyInfo qdev_prop_pci_devfn;
 
 /* Set properties between creation and init.  */
@@ -164,6 +167,7 @@ void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyT
 void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value);
 void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value);
 void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value);
+void qdev_prop_set_drive(DeviceState *dev, const char *name, DriveInfo *value);
 /* FIXME: Remove opaque pointer properties.  */
 void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
 void qdev_prop_set_defaults(DeviceState *dev, Property *props);
-- 
1.6.2.5

  parent reply	other threads:[~2009-07-31 10:25 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-31 10:25 [Qemu-devel] [PATCH 0/10] QemuOpts+qdev patches Gerd Hoffmann
2009-07-31 10:25 ` [Qemu-devel] [PATCH 01/10] QemuOpts: add some functions Gerd Hoffmann
2009-07-31 14:54   ` Luiz Capitulino
2009-07-31 10:25 ` [Qemu-devel] [PATCH 02/10] QemuOpts: qemu_opts_parse: fix id= parsing Gerd Hoffmann
2009-07-31 10:25 ` [Qemu-devel] [PATCH 03/10] QemuOpts: make the drive id actually show up in "info block" Gerd Hoffmann
2009-07-31 10:25 ` [Qemu-devel] [PATCH 04/10] QemuOpts: create qemu-config.h Gerd Hoffmann
2009-07-31 10:25 ` [Qemu-devel] [PATCH 05/10] QemuOpts: add -set option Gerd Hoffmann
2009-07-31 17:01   ` Anthony Liguori
2009-08-03  8:44     ` Gerd Hoffmann
2009-07-31 10:25 ` [Qemu-devel] [PATCH 06/10] QemuOpts: switch over -device Gerd Hoffmann
2009-07-31 10:25 ` [Qemu-devel] [PATCH 07/10] constify drive_get_by_id arg Gerd Hoffmann
2009-07-31 10:25 ` [Qemu-devel] [PATCH 08/10] add -drive if=none Gerd Hoffmann
2009-07-31 10:25 ` Gerd Hoffmann [this message]
2009-07-31 10:25 ` [Qemu-devel] [PATCH 10/10] qdev-ify virtio-blk Gerd Hoffmann

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=1249035941-4562-10-git-send-email-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.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).