debuggers.hg

changeset 21963:b92dfdc284dd

xl: prevent attempts to remove non-attached pci pass-through devices

Signed-off-by: Gianni Tedesco <gianni.tedesco@citrix.com>
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
author Gianni Tedesco <gianni.tedesco@citrix.com>
date Wed Aug 04 14:24:43 2010 +0100 (2010-08-04)
parents 3eec4c068649
children 9c720d64160b
files tools/libxl/libxl_pci.c
line diff
     1.1 --- a/tools/libxl/libxl_pci.c	Wed Aug 04 14:24:19 2010 +0100
     1.2 +++ b/tools/libxl/libxl_pci.c	Wed Aug 04 14:24:43 2010 +0100
     1.3 @@ -564,12 +564,20 @@ int libxl_device_pci_add(libxl_ctx *ctx,
     1.4  
     1.5  int libxl_device_pci_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcidev)
     1.6  {
     1.7 +    libxl_device_pci *assigned;
     1.8      char *path;
     1.9      char *state;
    1.10 -    int hvm, rc;
    1.11 +    int hvm, rc, num;
    1.12      int stubdomid = 0;
    1.13  
    1.14 -    /* TODO: check if the device can be detached */
    1.15 +    if ( !libxl_device_pci_list_assigned(ctx, &assigned, domid, &num) ) {
    1.16 +        if ( !is_assigned(assigned, num, pcidev->domain,
    1.17 +                         pcidev->bus, pcidev->dev, pcidev->func) ) {
    1.18 +            XL_LOG(ctx, XL_LOG_ERROR, "PCI device not attached to this domain");
    1.19 +            return ERROR_INVAL;
    1.20 +        }
    1.21 +    }
    1.22 +
    1.23      libxl_device_pci_remove_xenstore(ctx, domid, pcidev);
    1.24  
    1.25      hvm = is_hvm(ctx, domid);