From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH v3 2/5] add support for drive ids.
Date: Thu, 16 Jul 2009 16:57:01 +0200 [thread overview]
Message-ID: <1247756224-19219-3-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1247756224-19219-1-git-send-email-kraxel@redhat.com>
-drive accepts the new id= now, allowing to explicitely name your
drives. They will show up with that name in "info block" if specified,
otherwise the existing namimg scheme is used to autogenerate one.
There is also a new function to lookup drives by name. Not used yet.
The plan is to link disk drivers and drives using the drive id instead
of passing around pointers to BlockDriveState.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
sysemu.h | 2 ++
vl.c | 50 ++++++++++++++++++++++++++++++++------------------
2 files changed, 34 insertions(+), 18 deletions(-)
diff --git a/sysemu.h b/sysemu.h
index 36d6aaa..1f7532a 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -160,6 +160,7 @@ typedef enum {
typedef struct DriveInfo {
BlockDriverState *bdrv;
+ char *id;
const char *devaddr;
BlockInterfaceType type;
int bus;
@@ -177,6 +178,7 @@ typedef struct DriveInfo {
extern TAILQ_HEAD(drivelist, DriveInfo) drives;
extern DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit);
+extern DriveInfo *drive_get_by_id(char *id);
extern int drive_get_max_bus(BlockInterfaceType type);
extern void drive_uninit(BlockDriverState *bdrv);
extern void drive_remove(int index);
diff --git a/vl.c b/vl.c
index 4dae7ad..fd19219 100644
--- a/vl.c
+++ b/vl.c
@@ -1919,6 +1919,18 @@ DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit)
return NULL;
}
+DriveInfo *drive_get_by_id(char *id)
+{
+ DriveInfo *dinfo;
+
+ TAILQ_FOREACH(dinfo, &drives, next) {
+ if (strcmp(id, dinfo->id))
+ continue;
+ return dinfo;
+ }
+ return NULL;
+}
+
int drive_get_max_bus(BlockInterfaceType type)
{
int max_bus;
@@ -1988,7 +2000,6 @@ DriveInfo *drive_init(struct drive_opt *arg, int snapshot, void *opaque,
enum { MEDIA_DISK, MEDIA_CDROM } media;
int bus_id, unit_id;
int cyls, heads, secs, translation;
- BlockDriverState *bdrv;
BlockDriver *drv = NULL;
QEMUMachine *machine = opaque;
int max_devs;
@@ -2002,7 +2013,7 @@ DriveInfo *drive_init(struct drive_opt *arg, int snapshot, void *opaque,
"cyls", "heads", "secs", "trans",
"media", "snapshot", "file",
"cache", "format", "serial",
- "werror", "addr",
+ "werror", "addr", "id",
NULL };
*fatal_error = 1;
@@ -2278,17 +2289,20 @@ DriveInfo *drive_init(struct drive_opt *arg, int snapshot, void *opaque,
/* init */
- if (type == IF_IDE || type == IF_SCSI)
- mediastr = (media == MEDIA_CDROM) ? "-cd" : "-hd";
- if (max_devs)
- snprintf(buf, sizeof(buf), "%s%i%s%i",
- devname, bus_id, mediastr, unit_id);
- else
- snprintf(buf, sizeof(buf), "%s%s%i",
- devname, mediastr, unit_id);
- bdrv = bdrv_new(buf);
dinfo = qemu_mallocz(sizeof(*dinfo));
- dinfo->bdrv = bdrv;
+ if (!get_param_value(buf, sizeof(buf), "id", str)) {
+ /* no id supplied -> create one */
+ if (type == IF_IDE || type == IF_SCSI)
+ mediastr = (media == MEDIA_CDROM) ? "-cd" : "-hd";
+ if (max_devs)
+ snprintf(buf, sizeof(buf), "%s%i%s%i",
+ devname, bus_id, mediastr, unit_id);
+ else
+ snprintf(buf, sizeof(buf), "%s%s%i",
+ devname, mediastr, unit_id);
+ }
+ dinfo->id = qemu_strdup(buf);
+ dinfo->bdrv = bdrv_new(dinfo->id);
dinfo->devaddr = devaddr;
dinfo->type = type;
dinfo->bus = bus_id;
@@ -2305,12 +2319,12 @@ DriveInfo *drive_init(struct drive_opt *arg, int snapshot, void *opaque,
switch(media) {
case MEDIA_DISK:
if (cyls != 0) {
- bdrv_set_geometry_hint(bdrv, cyls, heads, secs);
- bdrv_set_translation_hint(bdrv, translation);
+ bdrv_set_geometry_hint(dinfo->bdrv, cyls, heads, secs);
+ bdrv_set_translation_hint(dinfo->bdrv, translation);
}
break;
case MEDIA_CDROM:
- bdrv_set_type_hint(bdrv, BDRV_TYPE_CDROM);
+ bdrv_set_type_hint(dinfo->bdrv, BDRV_TYPE_CDROM);
break;
}
break;
@@ -2318,7 +2332,7 @@ DriveInfo *drive_init(struct drive_opt *arg, int snapshot, void *opaque,
/* FIXME: This isn't really a floppy, but it's a reasonable
approximation. */
case IF_FLOPPY:
- bdrv_set_type_hint(bdrv, BDRV_TYPE_FLOPPY);
+ bdrv_set_type_hint(dinfo->bdrv, BDRV_TYPE_FLOPPY);
break;
case IF_PFLASH:
case IF_MTD:
@@ -2340,12 +2354,12 @@ DriveInfo *drive_init(struct drive_opt *arg, int snapshot, void *opaque,
bdrv_flags |= BDRV_O_NOCACHE;
else if (cache == 2) /* write-back */
bdrv_flags |= BDRV_O_CACHE_WB;
- if (bdrv_open2(bdrv, file, bdrv_flags, drv) < 0) {
+ if (bdrv_open2(dinfo->bdrv, file, bdrv_flags, drv) < 0) {
fprintf(stderr, "qemu: could not open disk image %s\n",
file);
return NULL;
}
- if (bdrv_key_required(bdrv))
+ if (bdrv_key_required(dinfo->bdrv))
autostart = 0;
*fatal_error = 0;
return dinfo;
--
1.6.2.5
next prev parent reply other threads:[~2009-07-16 14:57 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-16 14:56 [Qemu-devel] [PATCH v3 0/5] cleanup drive handling Gerd Hoffmann
2009-07-16 14:57 ` [Qemu-devel] [PATCH v3 1/5] kill drives_table Gerd Hoffmann
2009-07-16 14:57 ` Gerd Hoffmann [this message]
2009-07-16 14:57 ` [Qemu-devel] [PATCH v3 3/5] kill drives_opt Gerd Hoffmann
2009-07-16 14:57 ` [Qemu-devel] [PATCH v3 4/5] QemuOpts: framework for storing and parsing options Gerd Hoffmann
2009-07-16 16:35 ` [Qemu-devel] " Jan Kiszka
2009-07-16 18:50 ` Gerd Hoffmann
2009-07-17 7:03 ` [Qemu-devel] " Kevin Wolf
2009-07-21 7:25 ` Gerd Hoffmann
2009-07-21 7:42 ` Kevin Wolf
2009-07-21 13:59 ` Gerd Hoffmann
2009-07-21 15:58 ` Kevin Wolf
2009-07-22 6:58 ` Gerd Hoffmann
2009-07-22 7:31 ` Kevin Wolf
2009-07-22 7:55 ` Gerd Hoffmann
2009-07-16 14:57 ` [Qemu-devel] [PATCH v3 5/5] switch -drive to QemuOpts Gerd Hoffmann
2009-07-16 16:07 ` Anthony Liguori
2009-07-16 18:55 ` Gerd Hoffmann
2009-07-16 19:03 ` Anthony Liguori
2009-07-16 19:32 ` Gerd Hoffmann
2009-07-16 20:08 ` Anthony Liguori
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=1247756224-19219-3-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).