WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH 3 of 3] xl, check a PCI device is assignable before a

To: Xen Devel <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] [PATCH 3 of 3] xl, check a PCI device is assignable before adding it to a domU
From: Gianni Tedesco <gianni.tedesco@xxxxxxxxxx>
Date: Tue, 27 Jul 2010 17:24:33 +0100
Cc: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>, Stefano Stabellini <Stefano.Stabellini@xxxxxxxxxxxxx>
Delivery-date: Tue, 27 Jul 2010 09:27:16 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1280247870@xxxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <patchbomb.1280247870@xxxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mercurial-patchbomb/1.4.3
 tools/libxl/libxl_pci.c |  11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)


This prevents PCI devices from being added multiply to the same domain
or multiple different domains simultaneously.

diff -r 214733749470 -r dbfc4f30efe2 tools/libxl/libxl_pci.c
--- a/tools/libxl/libxl_pci.c   Tue Jul 27 17:17:31 2010 +0100
+++ b/tools/libxl/libxl_pci.c   Tue Jul 27 17:18:44 2010 +0100
@@ -334,8 +334,17 @@ int libxl_device_pci_add(struct libxl_ct
     char *state, *vdevfn;
     int rc, hvm;
     int stubdomid = 0;
+    libxl_device_pci *assigned;
+    int num_assigned;
 
-    /* TODO: check if the device can be assigned */
+    assigned = get_all_assigned_devices(ctx, &num_assigned);
+    if ( is_assigned(assigned, num_assigned, pcidev->domain,
+                     pcidev->bus, pcidev->dev, pcidev->func) ) {
+        XL_LOG(ctx, XL_LOG_ERROR, "PCI device already attached to a domain");
+        free(assigned);
+        return ERROR_FAIL;
+    }
+    free(assigned);
 
     libxl_device_pci_reset(ctx, pcidev->domain, pcidev->bus, pcidev->dev, 
pcidev->func);
 

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel