From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MMStK-0005UM-Sm for qemu-devel@nongnu.org; Thu, 02 Jul 2009 16:28:22 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MMStG-0005RF-6U for qemu-devel@nongnu.org; Thu, 02 Jul 2009 16:28:22 -0400 Received: from [199.232.76.173] (port=52793 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MMStG-0005R4-2D for qemu-devel@nongnu.org; Thu, 02 Jul 2009 16:28:18 -0400 Received: from mx2.redhat.com ([66.187.237.31]:45341) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MMStF-0007E5-Hp for qemu-devel@nongnu.org; Thu, 02 Jul 2009 16:28:17 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n62KSGN9009482 for ; Thu, 2 Jul 2009 16:28:16 -0400 From: Gerd Hoffmann Date: Thu, 2 Jul 2009 22:28:10 +0200 Message-Id: <1246566490-15093-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PATCH] add support for drive names. List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Gerd Hoffmann -drive accepts the new name= 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 name instead of passing around pointers to BlockDriveState. The patch depends on the "kill drives_table" sent earlier today. Signed-off-by: Gerd Hoffmann --- sysemu.h | 2 ++ vl.c | 49 +++++++++++++++++++++++++++++++------------------ 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/sysemu.h b/sysemu.h index 36d6aaa..f8c2729 100644 --- a/sysemu.h +++ b/sysemu.h @@ -160,6 +160,7 @@ typedef enum { typedef struct DriveInfo { BlockDriverState *bdrv; + char name[32]; 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_byname(char *name); 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 3dd1010..534af0f 100644 --- a/vl.c +++ b/vl.c @@ -2130,6 +2130,18 @@ DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit) return NULL; } +DriveInfo *drive_get_byname(char *name) +{ + DriveInfo *dinfo; + + TAILQ_FOREACH(dinfo, &drives, next) { + if (strcmp(name, dinfo->name)) + continue; + return dinfo; + } + return NULL; +} + int drive_get_max_bus(BlockInterfaceType type) { int max_bus; @@ -2199,7 +2211,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; @@ -2213,7 +2224,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", "name", NULL }; *fatal_error = 1; @@ -2489,17 +2500,19 @@ 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(dinfo->name, sizeof(dinfo->name), "name", str)) { + /* no name supplied -> create one */ + if (type == IF_IDE || type == IF_SCSI) + mediastr = (media == MEDIA_CDROM) ? "-cd" : "-hd"; + if (max_devs) + snprintf(dinfo->name, sizeof(dinfo->name), "%s%i%s%i", + devname, bus_id, mediastr, unit_id); + else + snprintf(dinfo->name, sizeof(dinfo->name), "%s%s%i", + devname, mediastr, unit_id); + } + dinfo->bdrv = bdrv_new(dinfo->name); dinfo->devaddr = devaddr; dinfo->type = type; dinfo->bus = bus_id; @@ -2516,12 +2529,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; @@ -2529,7 +2542,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: @@ -2553,12 +2566,12 @@ DriveInfo *drive_init(struct drive_opt *arg, int snapshot, void *opaque, bdrv_flags |= BDRV_O_CACHE_WB; else if (cache == 3) /* not specified */ bdrv_flags |= BDRV_O_CACHE_DEF; - 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