From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44552) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XWPFF-0005RN-OB for qemu-devel@nongnu.org; Tue, 23 Sep 2014 08:31:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XWPF9-000768-Jx for qemu-devel@nongnu.org; Tue, 23 Sep 2014 08:31:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37087) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XWPF9-00075h-7x for qemu-devel@nongnu.org; Tue, 23 Sep 2014 08:30:55 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s8NCDjW4023037 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 23 Sep 2014 08:13:45 -0400 From: Gerd Hoffmann Date: Tue, 23 Sep 2014 14:13:12 +0200 Message-Id: <1411474417-9704-2-git-send-email-kraxel@redhat.com> In-Reply-To: <1411474417-9704-1-git-send-email-kraxel@redhat.com> References: <1411474417-9704-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PULL 01/26] usb-storage: Fix how legacy init handles option ID clash List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Markus Armbruster , Gerd Hoffmann From: Markus Armbruster usb_msd_init() calls qemu_opts_create() with a made-up ID and false fail_if_exists. If the ID already exists, it happily messes up those options, then fails drive_new(), because the BlockDriverState with that ID already exists, too. Reproducer: -drive if=none,id=usb0,format=raw -usbdevice disk:tmp.qcow2 Pass true fail_if_exists to qemu_opts_create(), and if it fails, try the next made-up ID. The reproducer now succeeds, and creates an usb-storage device with ID usb1. Signed-off-by: Markus Armbruster Signed-off-by: Gerd Hoffmann --- hw/usb/dev-storage.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c index ae4efcb..eb75f6a 100644 --- a/hw/usb/dev-storage.c +++ b/hw/usb/dev-storage.c @@ -666,8 +666,10 @@ static USBDevice *usb_msd_init(USBBus *bus, const char *filename) char fmt[32]; /* parse -usbdevice disk: syntax into drive opts */ - snprintf(id, sizeof(id), "usb%d", nr++); - opts = qemu_opts_create(qemu_find_opts("drive"), id, 0, NULL); + do { + snprintf(id, sizeof(id), "usb%d", nr++); + opts = qemu_opts_create(qemu_find_opts("drive"), id, 1, NULL); + } while (!opts); p1 = strchr(filename, ':'); if (p1++) { -- 1.8.3.1