debuggers.hg

changeset 21937:1a92c8881770

libxl: Move libxl_device_pci_reset to libxl_pci.c

Signed-off-by: Gianni Tedesco <gianni.tedesco@citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
author Gianni Tedesco <gianni.tedesco@citrix.com>
date Thu Jul 29 18:49:47 2010 +0100 (2010-07-29)
parents 3263d0ff9476
children 9ced33b68bd8
files tools/libxl/libxl_device.c tools/libxl/libxl_pci.c
line diff
     1.1 --- a/tools/libxl/libxl_device.c	Thu Jul 29 16:53:40 2010 +0100
     1.2 +++ b/tools/libxl/libxl_device.c	Thu Jul 29 18:49:47 2010 +0100
     1.3 @@ -377,40 +377,6 @@ int libxl_device_del(libxl_ctx *ctx, lib
     1.4      return 0;
     1.5  }
     1.6  
     1.7 -int libxl_device_pci_reset(libxl_ctx *ctx, unsigned int domain, unsigned int bus,
     1.8 -                         unsigned int dev, unsigned int func)
     1.9 -{
    1.10 -    char *reset = "/sys/bus/pci/drivers/pciback/do_flr";
    1.11 -    int fd, rc;
    1.12 -
    1.13 -    fd = open(reset, O_WRONLY);
    1.14 -    if (fd > 0) {
    1.15 -        char *buf = libxl_sprintf(ctx, PCI_BDF, domain, bus, dev, func);
    1.16 -        rc = write(fd, buf, strlen(buf));
    1.17 -        if (rc < 0)
    1.18 -            XL_LOG(ctx, XL_LOG_ERROR, "write to %s returned %d", reset, rc);
    1.19 -        close(fd);
    1.20 -        return rc < 0 ? rc : 0;
    1.21 -    }
    1.22 -    if (errno != ENOENT)
    1.23 -        XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "Failed to access pciback path %s", reset);
    1.24 -    reset = libxl_sprintf(ctx, "/sys/bus/pci/devices/"PCI_BDF"/reset", domain, bus, dev, func);
    1.25 -    fd = open(reset, O_WRONLY);
    1.26 -    if (fd > 0) {
    1.27 -        rc = write(fd, "1", 1);
    1.28 -        if (rc < 0)
    1.29 -            XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "write to %s returned %d", reset, rc);
    1.30 -        close(fd);
    1.31 -        return rc < 0 ? rc : 0;
    1.32 -    }
    1.33 -    if (errno == ENOENT) {
    1.34 -        XL_LOG(ctx, XL_LOG_ERROR, "The kernel doesn't support PCI device reset from sysfs");
    1.35 -    } else {
    1.36 -        XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "Failed to access reset path %s", reset);
    1.37 -    }
    1.38 -    return -1;
    1.39 -}
    1.40 -
    1.41  int libxl_wait_for_device_model(libxl_ctx *ctx,
    1.42                                  uint32_t domid, char *state,
    1.43                                  int (*check_callback)(libxl_ctx *ctx,
     2.1 --- a/tools/libxl/libxl_pci.c	Thu Jul 29 16:53:40 2010 +0100
     2.2 +++ b/tools/libxl/libxl_pci.c	Thu Jul 29 18:49:47 2010 +0100
     2.3 @@ -536,3 +536,36 @@ int libxl_device_pci_init(libxl_device_p
     2.4      return 0;
     2.5  }
     2.6  
     2.7 +int libxl_device_pci_reset(libxl_ctx *ctx, unsigned int domain, unsigned int bus,
     2.8 +                         unsigned int dev, unsigned int func)
     2.9 +{
    2.10 +    char *reset = "/sys/bus/pci/drivers/pciback/do_flr";
    2.11 +    int fd, rc;
    2.12 +
    2.13 +    fd = open(reset, O_WRONLY);
    2.14 +    if (fd > 0) {
    2.15 +        char *buf = libxl_sprintf(ctx, PCI_BDF, domain, bus, dev, func);
    2.16 +        rc = write(fd, buf, strlen(buf));
    2.17 +        if (rc < 0)
    2.18 +            XL_LOG(ctx, XL_LOG_ERROR, "write to %s returned %d", reset, rc);
    2.19 +        close(fd);
    2.20 +        return rc < 0 ? rc : 0;
    2.21 +    }
    2.22 +    if (errno != ENOENT)
    2.23 +        XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "Failed to access pciback path %s", reset);
    2.24 +    reset = libxl_sprintf(ctx, "/sys/bus/pci/devices/"PCI_BDF"/reset", domain, bus, dev, func);
    2.25 +    fd = open(reset, O_WRONLY);
    2.26 +    if (fd > 0) {
    2.27 +        rc = write(fd, "1", 1);
    2.28 +        if (rc < 0)
    2.29 +            XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "write to %s returned %d", reset, rc);
    2.30 +        close(fd);
    2.31 +        return rc < 0 ? rc : 0;
    2.32 +    }
    2.33 +    if (errno == ENOENT) {
    2.34 +        XL_LOG(ctx, XL_LOG_ERROR, "The kernel doesn't support PCI device reset from sysfs");
    2.35 +    } else {
    2.36 +        XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "Failed to access reset path %s", reset);
    2.37 +    }
    2.38 +    return -1;
    2.39 +}