Patchwork [1/2] Add drive_get_by_id

login
register
mail settings
Submitter Ryan Harper
Date Oct. 18, 2010, 10:17 p.m.
Message ID <1287440237-14675-2-git-send-email-ryanh@us.ibm.com>
Download mbox | patch
Permalink /patch/68244/
State New
Headers show

Comments

Ryan Harper - Oct. 18, 2010, 10:17 p.m.
Add a function to find a drive by id string.

Signed-off-by: Ryan Harper <ryanh@us.ibm.com>
---
 blockdev.c |   12 ++++++++++++
 blockdev.h |    1 +
 2 files changed, 13 insertions(+), 0 deletions(-)
Stefan Hajnoczi - Oct. 19, 2010, 10:29 a.m.
On Mon, Oct 18, 2010 at 11:17 PM, Ryan Harper <ryanh@us.ibm.com> wrote:
> Add a function to find a drive by id string.
>
> Signed-off-by: Ryan Harper <ryanh@us.ibm.com>
> ---
>  blockdev.c |   12 ++++++++++++
>  blockdev.h |    1 +
>  2 files changed, 13 insertions(+), 0 deletions(-)
>
> diff --git a/blockdev.c b/blockdev.c
> index ff7602b..a00b3fa 100644
> --- a/blockdev.c
> +++ b/blockdev.c
> @@ -75,6 +75,18 @@ DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit)
>     return NULL;
>  }
>
> +DriveInfo *drive_get_by_id(const char *id)
> +{
> +    DriveInfo *dinfo;
> +
> +    QTAILQ_FOREACH(dinfo, &drives, next) {
> +        if (strcmp(id, dinfo->id))
> +            continue;

QEMU coding style uses curly braces even for 1-line if statements:
if (strcmp(id, dinfo->id)) {
    continue;
}

Stefan

Patch

diff --git a/blockdev.c b/blockdev.c
index ff7602b..a00b3fa 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -75,6 +75,18 @@  DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit)
     return NULL;
 }
 
+DriveInfo *drive_get_by_id(const char *id)
+{
+    DriveInfo *dinfo;
+
+    QTAILQ_FOREACH(dinfo, &drives, next) {
+        if (strcmp(id, dinfo->id))
+            continue;
+        return dinfo;
+    }
+    return NULL;
+}
+
 int drive_get_max_bus(BlockInterfaceType type)
 {
     int max_bus;
diff --git a/blockdev.h b/blockdev.h
index 653affc..19c6915 100644
--- a/blockdev.h
+++ b/blockdev.h
@@ -38,6 +38,7 @@  DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit);
 int drive_get_max_bus(BlockInterfaceType type);
 void drive_uninit(DriveInfo *dinfo);
 DriveInfo *drive_get_by_blockdev(BlockDriverState *bs);
+DriveInfo *drive_get_by_id(const char *id);
 
 QemuOpts *drive_add(const char *file, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
 DriveInfo *drive_init(QemuOpts *arg, int default_to_scsi, int *fatal_error);