From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mark McLoughlin Subject: [PATCH 02/12] kvm: qemu: device-assignment: introduce add_assigned_devices() Date: Fri, 28 Nov 2008 17:10:40 +0000 Message-ID: <1227892250-14386-2-git-send-email-markmc@redhat.com> References: <> <1227892250-14386-1-git-send-email-markmc@redhat.com> Cc: kvm@vger.kernel.org, Mark McLoughlin To: Avi Kivity Return-path: Received: from mail26.svc.cra.dublin.eircom.net ([159.134.118.55]:30973 "HELO mail26.svc.cra.dublin.eircom.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1752220AbYK1RMJ (ORCPT ); Fri, 28 Nov 2008 12:12:09 -0500 In-Reply-To: <1227892250-14386-1-git-send-email-markmc@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Merge two copies of the same code and cleanup with no functional changes. Signed-off-by: Mark McLoughlin fix error messages Signed-off-by: Mark McLoughlin --- qemu/hw/device-assignment.c | 32 +++++++++++++++++++++----------- qemu/hw/device-assignment.h | 2 +- qemu/hw/ipf.c | 16 ++-------------- qemu/hw/pc.c | 16 ++-------------- 4 files changed, 26 insertions(+), 40 deletions(-) diff --git a/qemu/hw/device-assignment.c b/qemu/hw/device-assignment.c index 9a790c6..eb2a73a 100644 --- a/qemu/hw/device-assignment.c +++ b/qemu/hw/device-assignment.c @@ -554,17 +554,6 @@ struct PCIDevice *init_assigned_device(AssignedDevInfo *adev, PCIBus *bus) return &dev->dev; } -int init_all_assigned_devices(PCIBus *bus) -{ - struct AssignedDevInfo *adev; - - LIST_FOREACH(adev, &adev_head, next) - if (init_assigned_device(adev, bus) == NULL) - return -1; - - return 0; -} - /* * Syntax to assign device: * @@ -619,3 +608,24 @@ bad: qemu_free(adev); return NULL; } + +void add_assigned_devices(PCIBus *bus, const char **devices, int n_devices) +{ + int i; + + for (i = 0; i < n_devices; i++) { + struct AssignedDevInfo *adev; + + adev = add_assigned_device(devices[i]); + if (!adev) { + fprintf(stderr, "Could not add assigned device %s\n", devices[i]); + continue; + } + + if (!init_assigned_device(adev, bus)) { + fprintf(stderr, "Failed to initialize assigned device %s\n", + devices[i]); + exit(1); + } + } +} diff --git a/qemu/hw/device-assignment.h b/qemu/hw/device-assignment.h index d6caa67..5a01d98 100644 --- a/qemu/hw/device-assignment.h +++ b/qemu/hw/device-assignment.h @@ -96,7 +96,7 @@ struct AssignedDevInfo { PCIDevice *init_assigned_device(AssignedDevInfo *adev, PCIBus *bus); AssignedDevInfo *add_assigned_device(const char *arg); -int init_all_assigned_devices(PCIBus *bus); +void add_assigned_devices(PCIBus *bus, const char **devices, int n_devices); #define MAX_DEV_ASSIGN_CMDLINE 8 diff --git a/qemu/hw/ipf.c b/qemu/hw/ipf.c index c0ac9eb..3e24c98 100644 --- a/qemu/hw/ipf.c +++ b/qemu/hw/ipf.c @@ -647,20 +647,8 @@ static void ipf_init1(ram_addr_t ram_size, int vga_ram_size, } #ifdef USE_KVM_DEVICE_ASSIGNMENT - if (kvm_enabled()) { - int i; - for (i = 0; i < assigned_devices_index; i++) { - if (!add_assigned_device(assigned_devices[i])) { - fprintf(stderr, "Warning: could not add assigned device %s\n", - assigned_devices[i]); - } - } - - if (init_all_assigned_devices(pci_bus)) { - fprintf(stderr, "Failed to initialize assigned devices\n"); - exit (1); - } - } + if (kvm_enabled()) + add_assigned_devices(pci_bus, assigned_devices, assigned_devices_index); #endif /* USE_KVM_DEVICE_ASSIGNMENT */ } diff --git a/qemu/hw/pc.c b/qemu/hw/pc.c index 6f3339f..6de460c 100644 --- a/qemu/hw/pc.c +++ b/qemu/hw/pc.c @@ -1184,20 +1184,8 @@ static void pc_init1(ram_addr_t ram_size, int vga_ram_size, virtio_balloon_init(pci_bus); #ifdef USE_KVM_DEVICE_ASSIGNMENT - if (kvm_enabled()) { - int i; - for (i = 0; i < assigned_devices_index; i++) { - if (!add_assigned_device(assigned_devices[i])) { - fprintf(stderr, "Warning: could not add assigned device %s\n", - assigned_devices[i]); - } - } - - if (init_all_assigned_devices(pci_bus)) { - fprintf(stderr, "Failed to initialize assigned devices\n"); - exit (1); - } - } + if (kvm_enabled()) + add_assigned_devices(pci_bus, assigned_devices, assigned_devices_index); #endif /* USE_KVM_DEVICE_ASSIGNMENT */ } -- 1.5.4.3