From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: [patch 11/24] QEMU/KVM: net/drive add/remove tweaks Date: Tue, 11 Mar 2008 17:12:02 -0300 Message-ID: <20080311201418.084167171@localhost.localdomain> References: <20080311201151.959635433@localhost.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: Marcelo Tosatti To: qemu-devel@nongnu.org, kvm-devel@lists.sourceforge.net Return-path: Content-Disposition: inline; filename=drive_init_ret List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: kvm-devel-bounces@lists.sourceforge.net Errors-To: kvm-devel-bounces@lists.sourceforge.net List-Id: kvm.vger.kernel.org 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: kvm-userspace.hotplug2/qemu/vl.c =================================================================== --- kvm-userspace.hotplug2.orig/qemu/vl.c +++ kvm-userspace.hotplug2/qemu/vl.c @@ -4797,7 +4797,7 @@ static int nic_get_free_idx(void) return -1; } -static int net_client_init(const char *str) +int net_client_init(const char *str) { const char *p; char *q; @@ -4856,7 +4856,7 @@ static int net_client_init(const char *s nd->used = 1; 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 @@ -4986,14 +4986,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; @@ -5056,9 +5056,10 @@ 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) { + QEMUMachine *machine = opaque; char buf[128]; char file[1024]; char devname[128]; @@ -5311,7 +5312,7 @@ static int drive_init(struct drive_opt * */ if (drive_get_index(type, bus_id, unit_id) != -1) - return 0; + return -2; /* init */ @@ -5359,7 +5360,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; @@ -5370,7 +5371,7 @@ static int drive_init(struct drive_opt * file); return -1; } - return 0; + return drives_table_idx; } /***********************************************************/ Index: kvm-userspace.hotplug2/qemu/net.h =================================================================== --- kvm-userspace.hotplug2.orig/qemu/net.h +++ kvm-userspace.hotplug2/qemu/net.h @@ -37,6 +37,8 @@ void do_info_network(void); /* virtio hack for zero copy receive */ int hack_around_tap(void *opaque); +int net_client_init(const char *str); + /* NIC info */ #define MAX_NICS 8 Index: kvm-userspace.hotplug2/qemu/sysemu.h =================================================================== --- kvm-userspace.hotplug2.orig/qemu/sysemu.h +++ kvm-userspace.hotplug2/qemu/sysemu.h @@ -166,6 +166,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); + /* acpi */ void qemu_system_cpu_hot_add(int cpu, int state); void qemu_system_hot_add_init(char *cpu_model); -- ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JZAto-0007gx-UI for qemu-devel@nongnu.org; Tue, 11 Mar 2008 16:16:36 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JZAto-0007gM-BZ for qemu-devel@nongnu.org; Tue, 11 Mar 2008 16:16:36 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JZAto-0007gE-4B for qemu-devel@nongnu.org; Tue, 11 Mar 2008 16:16:36 -0400 Received: from mx20.gnu.org ([199.232.41.8]) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1JZAtn-00047x-Qp for qemu-devel@nongnu.org; Tue, 11 Mar 2008 16:16:35 -0400 Received: from mx1.redhat.com ([66.187.233.31]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JZAtm-0007Fq-Lk for qemu-devel@nongnu.org; Tue, 11 Mar 2008 16:16:34 -0400 Message-Id: <20080311201418.084167171@localhost.localdomain> References: <20080311201151.959635433@localhost.localdomain> Date: Tue, 11 Mar 2008 17:12:02 -0300 From: Marcelo Tosatti Content-Disposition: inline; filename=drive_init_ret Subject: [Qemu-devel] [patch 11/24] QEMU/KVM: 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, kvm-devel@lists.sourceforge.net Cc: aliguori@us.ibm.com, 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: kvm-userspace.hotplug2/qemu/vl.c =================================================================== --- kvm-userspace.hotplug2.orig/qemu/vl.c +++ kvm-userspace.hotplug2/qemu/vl.c @@ -4797,7 +4797,7 @@ static int nic_get_free_idx(void) return -1; } -static int net_client_init(const char *str) +int net_client_init(const char *str) { const char *p; char *q; @@ -4856,7 +4856,7 @@ static int net_client_init(const char *s nd->used = 1; 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 @@ -4986,14 +4986,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; @@ -5056,9 +5056,10 @@ 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) { + QEMUMachine *machine = opaque; char buf[128]; char file[1024]; char devname[128]; @@ -5311,7 +5312,7 @@ static int drive_init(struct drive_opt * */ if (drive_get_index(type, bus_id, unit_id) != -1) - return 0; + return -2; /* init */ @@ -5359,7 +5360,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; @@ -5370,7 +5371,7 @@ static int drive_init(struct drive_opt * file); return -1; } - return 0; + return drives_table_idx; } /***********************************************************/ Index: kvm-userspace.hotplug2/qemu/net.h =================================================================== --- kvm-userspace.hotplug2.orig/qemu/net.h +++ kvm-userspace.hotplug2/qemu/net.h @@ -37,6 +37,8 @@ void do_info_network(void); /* virtio hack for zero copy receive */ int hack_around_tap(void *opaque); +int net_client_init(const char *str); + /* NIC info */ #define MAX_NICS 8 Index: kvm-userspace.hotplug2/qemu/sysemu.h =================================================================== --- kvm-userspace.hotplug2.orig/qemu/sysemu.h +++ kvm-userspace.hotplug2/qemu/sysemu.h @@ -166,6 +166,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); + /* acpi */ void qemu_system_cpu_hot_add(int cpu, int state); void qemu_system_hot_add_init(char *cpu_model); --