From patchwork Tue Oct 8 12:16:22 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 281428 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 384222C009A for ; Tue, 8 Oct 2013 23:17:32 +1100 (EST) Received: from localhost ([::1]:36387 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VTWED-0004Cz-U3 for incoming@patchwork.ozlabs.org; Tue, 08 Oct 2013 08:17:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59451) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VTWDW-0003zl-P2 for qemu-devel@nongnu.org; Tue, 08 Oct 2013 08:16:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VTWDQ-0002c6-D9 for qemu-devel@nongnu.org; Tue, 08 Oct 2013 08:16:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:2221) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VTWDQ-0002br-5x for qemu-devel@nongnu.org; Tue, 08 Oct 2013 08:16:40 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r98CGa3q003840 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 8 Oct 2013 08:16:36 -0400 Received: from dhcp-200-207.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r98CGOvr007904; Tue, 8 Oct 2013 08:16:35 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Tue, 8 Oct 2013 14:16:22 +0200 Message-Id: <1381234594-13968-6-git-send-email-kwolf@redhat.com> In-Reply-To: <1381234594-13968-1-git-send-email-kwolf@redhat.com> References: <1381234594-13968-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, benoit.canet@irqsave.net, armbru@redhat.com, mreitz@redhat.com, stefanha@redhat.com, xiawenc@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH v3 05/17] blockdev: Separate ID generation from DriveInfo creation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org blockdev-add shouldn't automatically generate IDs, but will keep most of the DriveInfo creation code. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz Reviewed-by: Wenchao Xia Reviewed-by: Eric Blake --- blockdev.c | 32 +++++++++++++++++--------------- include/qemu/option.h | 1 + util/qemu-option.c | 6 ++++++ 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/blockdev.c b/blockdev.c index 157c076..e7e6bdd 100644 --- a/blockdev.c +++ b/blockdev.c @@ -604,23 +604,25 @@ static DriveInfo *blockdev_init(QemuOpts *all_opts, return NULL; } - /* init */ - - dinfo = g_malloc0(sizeof(*dinfo)); - if ((buf = qemu_opts_id(opts)) != NULL) { - dinfo->id = g_strdup(buf); - } else { - /* no id supplied -> create one */ - dinfo->id = g_malloc0(32); - if (type == IF_IDE || type == IF_SCSI) + /* no id supplied -> create one */ + if (qemu_opts_id(opts) == NULL) { + char *new_id; + if (type == IF_IDE || type == IF_SCSI) { mediastr = (media == MEDIA_CDROM) ? "-cd" : "-hd"; - if (max_devs) - snprintf(dinfo->id, 32, "%s%i%s%i", - if_name[type], bus_id, mediastr, unit_id); - else - snprintf(dinfo->id, 32, "%s%s%i", - if_name[type], mediastr, unit_id); + } + if (max_devs) { + new_id = g_strdup_printf("%s%i%s%i", if_name[type], bus_id, + mediastr, unit_id); + } else { + 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->open_flags = snapshot ? BDRV_O_SNAPSHOT : 0; dinfo->bdrv->read_only = ro; diff --git a/include/qemu/option.h b/include/qemu/option.h index 63db4cc..5c0c6dd 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -142,6 +142,7 @@ void qemu_opts_loc_restore(QemuOpts *opts); int qemu_opts_set(QemuOptsList *list, const char *id, const char *name, const char *value); 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_validate(QemuOpts *opts, const QemuOptDesc *desc, Error **errp); int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname); diff --git a/util/qemu-option.c b/util/qemu-option.c index e0844a9..efcb5dc 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -834,6 +834,12 @@ const char *qemu_opts_id(QemuOpts *opts) 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) { QemuOpt *opt;