debuggers.hg

changeset 22766:5b8034ce8b8c

libxl: refactor code which adds per-PCI device backend nodes in xenstore

libxl_create_pci_backend and libxl_device_pci_add_xenstore contains
identical code to setup the per device xenstore nodes in the backend.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
author Ian Campbell <ian.campbell@citrix.com>
date Tue Jan 11 18:16:45 2011 +0000 (2011-01-11)
parents fd6239cbac00
children ca75ceb02221
files tools/libxl/libxl_pci.c
line diff
     1.1 --- a/tools/libxl/libxl_pci.c	Tue Jan 11 18:16:26 2011 +0000
     1.2 +++ b/tools/libxl/libxl_pci.c	Tue Jan 11 18:16:45 2011 +0000
     1.3 @@ -221,6 +221,19 @@ parse_error:
     1.4      return ERROR_INVAL;
     1.5  }
     1.6  
     1.7 +static void libxl_create_pci_backend_device(libxl__gc *gc, flexarray_t *back, int num, libxl_device_pci *pcidev)
     1.8 +{
     1.9 +    flexarray_append(back, libxl__sprintf(gc, "key-%d", num));
    1.10 +    flexarray_append(back, libxl__sprintf(gc, PCI_BDF, pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func));
    1.11 +    flexarray_append(back, libxl__sprintf(gc, "dev-%d", num));
    1.12 +    flexarray_append(back, libxl__sprintf(gc, PCI_BDF, pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func));
    1.13 +    if (pcidev->vdevfn)
    1.14 +        flexarray_vappend(back, libxl__sprintf(gc, "vdevfn-%d", num), libxl__sprintf(gc, "%x", pcidev->vdevfn), NULL);
    1.15 +    flexarray_append(back, libxl__sprintf(gc, "opts-%d", num));
    1.16 +    flexarray_append(back, libxl__sprintf(gc, "msitranslate=%d,power_mgmt=%d", pcidev->msitranslate, pcidev->power_mgmt));
    1.17 +    flexarray_vappend(back, libxl__sprintf(gc, "state-%d", num), libxl__sprintf(gc, "%d", 1), NULL);
    1.18 +}
    1.19 +
    1.20  static int libxl_create_pci_backend(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev, int num)
    1.21  {
    1.22      libxl_ctx *ctx = libxl__gc_owner(gc);
    1.23 @@ -249,20 +262,12 @@ static int libxl_create_pci_backend(libx
    1.24      device.kind = DEVICE_PCI;
    1.25  
    1.26      flexarray_vappend(back, "frontend-id", libxl__sprintf(gc, "%d", domid),
    1.27 -                     "online", "1", "state", libxl__sprintf(gc, "%d", 1),
    1.28 -                    "domain", libxl__domid_to_name(gc, domid), NULL);
    1.29 -    for (i = 0; i < num; i++) {
    1.30 -        flexarray_append(back, libxl__sprintf(gc, "key-%d", i));
    1.31 -        flexarray_append(back, libxl__sprintf(gc, PCI_BDF, pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func));
    1.32 -        flexarray_append(back, libxl__sprintf(gc, "dev-%d", i));
    1.33 -        flexarray_append(back, libxl__sprintf(gc, PCI_BDF, pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func));
    1.34 -        if (pcidev->vdevfn) {
    1.35 -            flexarray_vappend(back, libxl__sprintf(gc, "vdevfn-%d", i), libxl__sprintf(gc, "%x", pcidev->vdevfn), NULL);
    1.36 -        }
    1.37 -        flexarray_append(back, libxl__sprintf(gc, "opts-%d", i));
    1.38 -        flexarray_append(back, libxl__sprintf(gc, "msitranslate=%d,power_mgmt=%d", pcidev->msitranslate, pcidev->power_mgmt));
    1.39 -        flexarray_vappend(back, libxl__sprintf(gc, "state-%d", i), libxl__sprintf(gc, "%d", 1), NULL);
    1.40 -    }
    1.41 +                      "online", "1", "state", libxl__sprintf(gc, "%d", 1),
    1.42 +                      "domain", libxl__domid_to_name(gc, domid), NULL);
    1.43 +
    1.44 +    for (i = 0; i < num; i++, pcidev++)
    1.45 +        libxl_create_pci_backend_device(gc, back, i, pcidev);
    1.46 +
    1.47      flexarray_vappend(back, "num_devs", libxl__sprintf(gc, "%d", num));
    1.48  
    1.49      flexarray_vappend(front,
    1.50 @@ -305,17 +310,7 @@ static int libxl_device_pci_add_xenstore
    1.51  
    1.52      LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Adding new pci device to xenstore");
    1.53      num = atoi(num_devs);
    1.54 -    flexarray_append(back, libxl__sprintf(gc, "key-%d", num));
    1.55 -    flexarray_append(back, libxl__sprintf(gc, PCI_BDF, pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func));
    1.56 -    flexarray_append(back, libxl__sprintf(gc, "dev-%d", num));
    1.57 -    flexarray_append(back, libxl__sprintf(gc, PCI_BDF, pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func));
    1.58 -    if (pcidev->vdevfn) {
    1.59 -        flexarray_append(back, libxl__sprintf(gc, "vdevfn-%d", num));
    1.60 -        flexarray_append(back, libxl__sprintf(gc, "%x", pcidev->vdevfn));
    1.61 -    }
    1.62 -    flexarray_append(back, libxl__sprintf(gc, "opts-%d", num));
    1.63 -    flexarray_append(back, libxl__sprintf(gc, "msitranslate=%d,power_mgmt=%d", pcidev->msitranslate, pcidev->power_mgmt));
    1.64 -    flexarray_vappend(back, libxl__sprintf(gc, "state-%d", num), libxl__sprintf(gc, "%d", 1), NULL);
    1.65 +    libxl_create_pci_backend_device(gc, back, num, pcidev);
    1.66      flexarray_vappend(back, "num_devs", libxl__sprintf(gc, "%d", num + 1), NULL);
    1.67      flexarray_vappend(back, "state", libxl__sprintf(gc, "%d", 7), NULL);
    1.68