blockdev: Separate ID generation from DriveInfo creation
blockdev-add shouldn't automatically generate IDs, but will keep most of the DriveInfo creation code. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com> Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
d26c9a1573
commit
326642bc7f
32
blockdev.c
32
blockdev.c
|
@ -600,23 +600,25 @@ static DriveInfo *blockdev_init(QemuOpts *all_opts,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* init */
|
/* no id supplied -> create one */
|
||||||
|
if (qemu_opts_id(opts) == NULL) {
|
||||||
dinfo = g_malloc0(sizeof(*dinfo));
|
char *new_id;
|
||||||
if ((buf = qemu_opts_id(opts)) != NULL) {
|
if (type == IF_IDE || type == IF_SCSI) {
|
||||||
dinfo->id = g_strdup(buf);
|
|
||||||
} else {
|
|
||||||
/* no id supplied -> create one */
|
|
||||||
dinfo->id = g_malloc0(32);
|
|
||||||
if (type == IF_IDE || type == IF_SCSI)
|
|
||||||
mediastr = (media == MEDIA_CDROM) ? "-cd" : "-hd";
|
mediastr = (media == MEDIA_CDROM) ? "-cd" : "-hd";
|
||||||
if (max_devs)
|
}
|
||||||
snprintf(dinfo->id, 32, "%s%i%s%i",
|
if (max_devs) {
|
||||||
if_name[type], bus_id, mediastr, unit_id);
|
new_id = g_strdup_printf("%s%i%s%i", if_name[type], bus_id,
|
||||||
else
|
mediastr, unit_id);
|
||||||
snprintf(dinfo->id, 32, "%s%s%i",
|
} else {
|
||||||
if_name[type], mediastr, unit_id);
|
new_id = g_strdup_printf("%s%s%i", if_name[type],
|
||||||
|
mediastr, unit_id);
|
||||||
|
}
|
||||||
|
qemu_opts_set_id(opts, new_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* init */
|
||||||
|
dinfo = g_malloc0(sizeof(*dinfo));
|
||||||
|
dinfo->id = g_strdup(qemu_opts_id(opts));
|
||||||
dinfo->bdrv = bdrv_new(dinfo->id);
|
dinfo->bdrv = bdrv_new(dinfo->id);
|
||||||
dinfo->bdrv->open_flags = snapshot ? BDRV_O_SNAPSHOT : 0;
|
dinfo->bdrv->open_flags = snapshot ? BDRV_O_SNAPSHOT : 0;
|
||||||
dinfo->bdrv->read_only = ro;
|
dinfo->bdrv->read_only = ro;
|
||||||
|
|
|
@ -142,6 +142,7 @@ void qemu_opts_loc_restore(QemuOpts *opts);
|
||||||
int qemu_opts_set(QemuOptsList *list, const char *id,
|
int qemu_opts_set(QemuOptsList *list, const char *id,
|
||||||
const char *name, const char *value);
|
const char *name, const char *value);
|
||||||
const char *qemu_opts_id(QemuOpts *opts);
|
const char *qemu_opts_id(QemuOpts *opts);
|
||||||
|
void qemu_opts_set_id(QemuOpts *opts, char *id);
|
||||||
void qemu_opts_del(QemuOpts *opts);
|
void qemu_opts_del(QemuOpts *opts);
|
||||||
void qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc, Error **errp);
|
void qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc, Error **errp);
|
||||||
int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname);
|
int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname);
|
||||||
|
|
|
@ -834,6 +834,12 @@ const char *qemu_opts_id(QemuOpts *opts)
|
||||||
return opts->id;
|
return opts->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* The id string will be g_free()d by qemu_opts_del */
|
||||||
|
void qemu_opts_set_id(QemuOpts *opts, char *id)
|
||||||
|
{
|
||||||
|
opts->id = id;
|
||||||
|
}
|
||||||
|
|
||||||
void qemu_opts_del(QemuOpts *opts)
|
void qemu_opts_del(QemuOpts *opts)
|
||||||
{
|
{
|
||||||
QemuOpt *opt;
|
QemuOpt *opt;
|
||||||
|
|
Loading…
Reference in New Issue