From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LUi4o-0002kc-FG for qemu-devel@nongnu.org; Wed, 04 Feb 2009 08:46:02 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LUi4n-0002k8-Kz for qemu-devel@nongnu.org; Wed, 04 Feb 2009 08:46:02 -0500 Received: from [199.232.76.173] (port=37309 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LUi4n-0002jz-DA for qemu-devel@nongnu.org; Wed, 04 Feb 2009 08:46:01 -0500 Received: from mx2.redhat.com ([66.187.237.31]:34125) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LUi4m-0000dA-SK for qemu-devel@nongnu.org; Wed, 04 Feb 2009 08:46:01 -0500 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 n14Dk0fm010625 for ; Wed, 4 Feb 2009 08:46:00 -0500 Message-Id: <20090204133923.593575773@localhost.localdomain> References: <20090204133303.113145633@localhost.localdomain> Date: Wed, 04 Feb 2009 11:33:08 -0200 From: Marcelo Tosatti Content-Disposition: inline; filename=drive-remove Subject: [Qemu-devel] [patch 05/18] qemu: drive removal support Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Marcelo Tosatti To be used by hot-remove. Signed-off-by: Marcelo Tosatti Index: trunk/sysemu.h =================================================================== --- trunk.orig/sysemu.h +++ trunk/sysemu.h @@ -135,6 +135,7 @@ typedef struct DriveInfo { int bus; int unit; int used; + int drive_opt_idx; BlockInterfaceErrorAction onerror; char serial[21]; } DriveInfo; @@ -148,6 +149,8 @@ extern DriveInfo drives_table[MAX_DRIVES extern int drive_get_index(BlockInterfaceType type, int bus, int unit); extern int drive_get_max_bus(BlockInterfaceType type); +extern void drive_uninit(BlockDriverState *bdrv); +extern void drive_remove(int index); extern const char *drive_get_serial(BlockDriverState *bdrv); extern BlockInterfaceErrorAction drive_get_onerror(BlockDriverState *bdrv); Index: trunk/vl.c =================================================================== --- trunk.orig/vl.c +++ trunk/vl.c @@ -2186,6 +2186,12 @@ static int drive_add(const char *file, c return index; } +void drive_remove(int index) +{ + drives_opt[index].used = 0; + nb_drives_opt--; +} + int drive_get_index(BlockInterfaceType type, int bus, int unit) { int index; @@ -2243,6 +2249,20 @@ static void bdrv_format_print(void *opaq fprintf(stderr, " %s", name); } +void drive_uninit(BlockDriverState *bdrv) +{ + int i; + + for (i = 0; i < MAX_DRIVES; i++) + if (drives_table[i].bdrv == bdrv) { + drives_table[i].bdrv = NULL; + drives_table[i].used = 0; + drive_remove(drives_table[i].drive_opt_idx); + nb_drives--; + break; + } +} + static int drive_init(struct drive_opt *arg, int snapshot, QEMUMachine *machine) { @@ -2542,6 +2562,7 @@ static int drive_init(struct drive_opt * drives_table[drives_table_idx].bus = bus_id; drives_table[drives_table_idx].unit = unit_id; drives_table[drives_table_idx].onerror = onerror; + drives_table[drives_table_idx].drive_opt_idx = arg - drives_opt; strncpy(drives_table[nb_drives].serial, serial, sizeof(serial)); nb_drives++; --