From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LUi53-0002sG-MN for qemu-devel@nongnu.org; Wed, 04 Feb 2009 08:46:17 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LUi52-0002rB-Jy for qemu-devel@nongnu.org; Wed, 04 Feb 2009 08:46:16 -0500 Received: from [199.232.76.173] (port=37320 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LUi52-0002qw-C0 for qemu-devel@nongnu.org; Wed, 04 Feb 2009 08:46:16 -0500 Received: from mx2.redhat.com ([66.187.237.31]:34142) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LUi51-0000g3-Pt for qemu-devel@nongnu.org; Wed, 04 Feb 2009 08:46:16 -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 n14DkFC6010737 for ; Wed, 4 Feb 2009 08:46:15 -0500 Message-Id: <20090204133923.905967066@localhost.localdomain> References: <20090204133303.113145633@localhost.localdomain> Date: Wed, 04 Feb 2009 11:33:11 -0200 From: Marcelo Tosatti Content-Disposition: inline; filename=net-drive-add-remove-tweaks Subject: [Qemu-devel] [patch 08/18] qemu: net/drive add/remove tweaks 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 Export net/drive add/remove functions for device hotplug usage. Return the table index on add. Return failure instead of exiting if limit has been reached on drive_add. Signed-off-by: Marcelo Tosatti Index: trunk/net.c =================================================================== --- trunk.orig/net.c +++ trunk/net.c @@ -1611,7 +1611,7 @@ int net_client_init(const char *device, name = NULL; nb_nics++; vlan->nb_guest_devs++; - ret = 0; + ret = idx; } else if (!strcmp(device, "none")) { /* does nothing. It is needed to signal that no network cards Index: trunk/sysemu.h =================================================================== --- trunk.orig/sysemu.h +++ trunk/sysemu.h @@ -163,6 +163,9 @@ struct drive_opt { extern struct drive_opt drives_opt[MAX_DRIVES]; extern int nb_drives_opt; +extern int drive_add(const char *file, const char *fmt, ...); +extern int drive_init(struct drive_opt *arg, int snapshot, void *machine); + /* serial ports */ #define MAX_SERIAL_PORTS 4 Index: trunk/vl.c =================================================================== --- trunk.orig/vl.c +++ trunk/vl.c @@ -2162,14 +2162,14 @@ static int drive_get_free_idx(void) return -1; } -static int drive_add(const char *file, const char *fmt, ...) +int drive_add(const char *file, const char *fmt, ...) { va_list ap; int index = drive_opt_get_free_idx(); if (nb_drives_opt >= MAX_DRIVES || index == -1) { fprintf(stderr, "qemu: too many drives\n"); - exit(1); + return -1; } drives_opt[index].file = file; @@ -2259,8 +2259,7 @@ void drive_uninit(BlockDriverState *bdrv } } -static int drive_init(struct drive_opt *arg, int snapshot, - QEMUMachine *machine) +int drive_init(struct drive_opt *arg, int snapshot, void *opaque) { char buf[128]; char file[1024]; @@ -2273,6 +2272,7 @@ static int drive_init(struct drive_opt * int cyls, heads, secs, translation; BlockDriverState *bdrv; BlockDriver *drv = NULL; + QEMUMachine *machine = opaque; int max_devs; int index; int cache; @@ -2539,7 +2539,7 @@ static int drive_init(struct drive_opt * */ if (drive_get_index(type, bus_id, unit_id) != -1) - return 0; + return -2; /* init */ @@ -2589,7 +2589,7 @@ static int drive_init(struct drive_opt * break; } if (!file[0]) - return 0; + return -2; bdrv_flags = 0; if (snapshot) { bdrv_flags |= BDRV_O_SNAPSHOT; @@ -2606,7 +2606,7 @@ static int drive_init(struct drive_opt * file); return -1; } - return 0; + return drives_table_idx; } /***********************************************************/ --