From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53200) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XSWSa-0006UI-Ex for qemu-devel@nongnu.org; Fri, 12 Sep 2014 15:24:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XSWSU-0002ce-Ao for qemu-devel@nongnu.org; Fri, 12 Sep 2014 15:24:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:1488) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XSWSU-0002cZ-3P for qemu-devel@nongnu.org; Fri, 12 Sep 2014 15:24:38 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s8CJObk3024193 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Fri, 12 Sep 2014 15:24:37 -0400 From: Markus Armbruster Date: Fri, 12 Sep 2014 21:24:34 +0200 Message-Id: <1410549874-15980-1-git-send-email-armbru@redhat.com> Subject: [Qemu-devel] [PATCH] 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: kwolf@redhat.com, kraxel@redhat.com 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 --- 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.9.3