[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 18/29] xl: split out pci related code



Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx>
---
 tools/xl/Makefile     |   2 +-
 tools/xl/xl_cmdimpl.c | 247 --------------------------------------------
 tools/xl/xl_pci.c     | 278 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 279 insertions(+), 248 deletions(-)
 create mode 100644 tools/xl/xl_pci.c

diff --git a/tools/xl/Makefile b/tools/xl/Makefile
index 8aa294d5a0..0af1e92b65 100644
--- a/tools/xl/Makefile
+++ b/tools/xl/Makefile
@@ -18,7 +18,7 @@ CFLAGS_XL += -Wshadow
 XL_OBJS = xl.o xl_cmdimpl.o xl_cmdtable.o xl_sxp.o xl_utils.o
 XL_OBJS += xl_tmem.o xl_parse.o xl_cpupool.o xl_flask.o
 XL_OBJS += xl_vtpm.o xl_block.o xl_nic.o xl_usb.o
-XL_OBJS += xl_sched.o
+XL_OBJS += xl_sched.o xl_pci.o
 
 $(XL_OBJS): CFLAGS += $(CFLAGS_libxentoollog)
 $(XL_OBJS): CFLAGS += $(CFLAGS_XL)
diff --git a/tools/xl/xl_cmdimpl.c b/tools/xl/xl_cmdimpl.c
index 7d6de3957e..b32233e95e 100644
--- a/tools/xl/xl_cmdimpl.c
+++ b/tools/xl/xl_cmdimpl.c
@@ -1347,253 +1347,6 @@ int main_vncviewer(int argc, char **argv)
     return EXIT_SUCCESS;
 }
 
-static void pcilist(uint32_t domid)
-{
-    libxl_device_pci *pcidevs;
-    int num, i;
-
-    pcidevs = libxl_device_pci_list(ctx, domid, &num);
-    if (pcidevs == NULL)
-        return;
-    printf("Vdev Device\n");
-    for (i = 0; i < num; i++) {
-        printf("%02x.%01x %04x:%02x:%02x.%01x\n",
-               (pcidevs[i].vdevfn >> 3) & 0x1f, pcidevs[i].vdevfn & 0x7,
-               pcidevs[i].domain, pcidevs[i].bus, pcidevs[i].dev, 
pcidevs[i].func);
-        libxl_device_pci_dispose(&pcidevs[i]);
-    }
-    free(pcidevs);
-}
-
-int main_pcilist(int argc, char **argv)
-{
-    uint32_t domid;
-    int opt;
-
-    SWITCH_FOREACH_OPT(opt, "", NULL, "pci-list", 1) {
-        /* No options */
-    }
-
-    domid = xfind_domain(argv[optind]);
-
-    pcilist(domid);
-    return 0;
-}
-
-static int pcidetach(uint32_t domid, const char *bdf, int force)
-{
-    libxl_device_pci pcidev;
-    XLU_Config *config;
-    int r = 0;
-
-    libxl_device_pci_init(&pcidev);
-
-    config = xlu_cfg_init(stderr, "command line");
-    if (!config) { perror("xlu_cfg_inig"); exit(-1); }
-
-    if (xlu_pci_parse_bdf(config, &pcidev, bdf)) {
-        fprintf(stderr, "pci-detach: malformed BDF specification \"%s\"\n", 
bdf);
-        exit(2);
-    }
-    if (force) {
-        if (libxl_device_pci_destroy(ctx, domid, &pcidev, 0))
-            r = 1;
-    } else {
-        if (libxl_device_pci_remove(ctx, domid, &pcidev, 0))
-            r = 1;
-    }
-
-    libxl_device_pci_dispose(&pcidev);
-    xlu_cfg_destroy(config);
-
-    return r;
-}
-
-int main_pcidetach(int argc, char **argv)
-{
-    uint32_t domid;
-    int opt;
-    int force = 0;
-    const char *bdf = NULL;
-
-    SWITCH_FOREACH_OPT(opt, "f", NULL, "pci-detach", 2) {
-    case 'f':
-        force = 1;
-        break;
-    }
-
-    domid = xfind_domain(argv[optind]);
-    bdf = argv[optind + 1];
-
-    if (pcidetach(domid, bdf, force))
-        return EXIT_FAILURE;
-
-    return EXIT_SUCCESS;
-}
-
-static int pciattach(uint32_t domid, const char *bdf, const char *vs)
-{
-    libxl_device_pci pcidev;
-    XLU_Config *config;
-    int r = 0;
-
-    libxl_device_pci_init(&pcidev);
-
-    config = xlu_cfg_init(stderr, "command line");
-    if (!config) { perror("xlu_cfg_inig"); exit(-1); }
-
-    if (xlu_pci_parse_bdf(config, &pcidev, bdf)) {
-        fprintf(stderr, "pci-attach: malformed BDF specification \"%s\"\n", 
bdf);
-        exit(2);
-    }
-
-    if (libxl_device_pci_add(ctx, domid, &pcidev, 0))
-        r = 1;
-
-    libxl_device_pci_dispose(&pcidev);
-    xlu_cfg_destroy(config);
-
-    return r;
-}
-
-int main_pciattach(int argc, char **argv)
-{
-    uint32_t domid;
-    int opt;
-    const char *bdf = NULL, *vs = NULL;
-
-    SWITCH_FOREACH_OPT(opt, "", NULL, "pci-attach", 2) {
-        /* No options */
-    }
-
-    domid = xfind_domain(argv[optind]);
-    bdf = argv[optind + 1];
-
-    if (optind + 1 < argc)
-        vs = argv[optind + 2];
-
-    if (pciattach(domid, bdf, vs))
-        return EXIT_FAILURE;
-
-    return EXIT_SUCCESS;
-}
-
-static void pciassignable_list(void)
-{
-    libxl_device_pci *pcidevs;
-    int num, i;
-
-    pcidevs = libxl_device_pci_assignable_list(ctx, &num);
-
-    if ( pcidevs == NULL )
-        return;
-    for (i = 0; i < num; i++) {
-        printf("%04x:%02x:%02x.%01x\n",
-               pcidevs[i].domain, pcidevs[i].bus, pcidevs[i].dev, 
pcidevs[i].func);
-        libxl_device_pci_dispose(&pcidevs[i]);
-    }
-    free(pcidevs);
-}
-
-int main_pciassignable_list(int argc, char **argv)
-{
-    int opt;
-
-    SWITCH_FOREACH_OPT(opt, "", NULL, "pci-assignable-list", 0) {
-        /* No options */
-    }
-
-    pciassignable_list();
-    return 0;
-}
-
-static int pciassignable_add(const char *bdf, int rebind)
-{
-    libxl_device_pci pcidev;
-    XLU_Config *config;
-    int r = 0;
-
-    libxl_device_pci_init(&pcidev);
-
-    config = xlu_cfg_init(stderr, "command line");
-    if (!config) { perror("xlu_cfg_init"); exit(-1); }
-
-    if (xlu_pci_parse_bdf(config, &pcidev, bdf)) {
-        fprintf(stderr, "pci-assignable-add: malformed BDF specification 
\"%s\"\n", bdf);
-        exit(2);
-    }
-
-    if (libxl_device_pci_assignable_add(ctx, &pcidev, rebind))
-        r = 1;
-
-    libxl_device_pci_dispose(&pcidev);
-    xlu_cfg_destroy(config);
-
-    return r;
-}
-
-int main_pciassignable_add(int argc, char **argv)
-{
-    int opt;
-    const char *bdf = NULL;
-
-    SWITCH_FOREACH_OPT(opt, "", NULL, "pci-assignable-add", 1) {
-        /* No options */
-    }
-
-    bdf = argv[optind];
-
-    if (pciassignable_add(bdf, 1))
-        return EXIT_FAILURE;
-
-    return EXIT_SUCCESS;
-}
-
-static int pciassignable_remove(const char *bdf, int rebind)
-{
-    libxl_device_pci pcidev;
-    XLU_Config *config;
-    int r = 0;
-
-    libxl_device_pci_init(&pcidev);
-
-    config = xlu_cfg_init(stderr, "command line");
-    if (!config) { perror("xlu_cfg_init"); exit(-1); }
-
-    if (xlu_pci_parse_bdf(config, &pcidev, bdf)) {
-        fprintf(stderr, "pci-assignable-remove: malformed BDF specification 
\"%s\"\n", bdf);
-        exit(2);
-    }
-
-    if (libxl_device_pci_assignable_remove(ctx, &pcidev, rebind))
-        r = 1;
-
-    libxl_device_pci_dispose(&pcidev);
-    xlu_cfg_destroy(config);
-
-    return r;
-}
-
-int main_pciassignable_remove(int argc, char **argv)
-{
-    int opt;
-    const char *bdf = NULL;
-    int rebind = 0;
-
-    SWITCH_FOREACH_OPT(opt, "r", NULL, "pci-assignable-remove", 1) {
-    case 'r':
-        rebind=1;
-        break;
-    }
-
-    bdf = argv[optind];
-
-    if (pciassignable_remove(bdf, rebind))
-        return EXIT_FAILURE;
-
-    return EXIT_SUCCESS;
-}
-
 static void pause_domain(uint32_t domid)
 {
     libxl_domain_pause(ctx, domid);
diff --git a/tools/xl/xl_pci.c b/tools/xl/xl_pci.c
new file mode 100644
index 0000000000..2e0f6fdda5
--- /dev/null
+++ b/tools/xl/xl_pci.c
@@ -0,0 +1,278 @@
+/*
+ * Copyright 2009-2017 Citrix Ltd and other contributors
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ */
+
+#include <stdlib.h>
+
+#include <libxl.h>
+#include <libxl_utils.h>
+#include <libxlutil.h>
+
+#include "xl.h"
+#include "xl_utils.h"
+#include "xl_parse.h"
+
+static void pcilist(uint32_t domid)
+{
+    libxl_device_pci *pcidevs;
+    int num, i;
+
+    pcidevs = libxl_device_pci_list(ctx, domid, &num);
+    if (pcidevs == NULL)
+        return;
+    printf("Vdev Device\n");
+    for (i = 0; i < num; i++) {
+        printf("%02x.%01x %04x:%02x:%02x.%01x\n",
+               (pcidevs[i].vdevfn >> 3) & 0x1f, pcidevs[i].vdevfn & 0x7,
+               pcidevs[i].domain, pcidevs[i].bus, pcidevs[i].dev, 
pcidevs[i].func);
+        libxl_device_pci_dispose(&pcidevs[i]);
+    }
+    free(pcidevs);
+}
+
+int main_pcilist(int argc, char **argv)
+{
+    uint32_t domid;
+    int opt;
+
+    SWITCH_FOREACH_OPT(opt, "", NULL, "pci-list", 1) {
+        /* No options */
+    }
+
+    domid = xfind_domain(argv[optind]);
+
+    pcilist(domid);
+    return 0;
+}
+
+static int pcidetach(uint32_t domid, const char *bdf, int force)
+{
+    libxl_device_pci pcidev;
+    XLU_Config *config;
+    int r = 0;
+
+    libxl_device_pci_init(&pcidev);
+
+    config = xlu_cfg_init(stderr, "command line");
+    if (!config) { perror("xlu_cfg_inig"); exit(-1); }
+
+    if (xlu_pci_parse_bdf(config, &pcidev, bdf)) {
+        fprintf(stderr, "pci-detach: malformed BDF specification \"%s\"\n", 
bdf);
+        exit(2);
+    }
+    if (force) {
+        if (libxl_device_pci_destroy(ctx, domid, &pcidev, 0))
+            r = 1;
+    } else {
+        if (libxl_device_pci_remove(ctx, domid, &pcidev, 0))
+            r = 1;
+    }
+
+    libxl_device_pci_dispose(&pcidev);
+    xlu_cfg_destroy(config);
+
+    return r;
+}
+
+int main_pcidetach(int argc, char **argv)
+{
+    uint32_t domid;
+    int opt;
+    int force = 0;
+    const char *bdf = NULL;
+
+    SWITCH_FOREACH_OPT(opt, "f", NULL, "pci-detach", 2) {
+    case 'f':
+        force = 1;
+        break;
+    }
+
+    domid = xfind_domain(argv[optind]);
+    bdf = argv[optind + 1];
+
+    if (pcidetach(domid, bdf, force))
+        return EXIT_FAILURE;
+
+    return EXIT_SUCCESS;
+}
+
+static int pciattach(uint32_t domid, const char *bdf, const char *vs)
+{
+    libxl_device_pci pcidev;
+    XLU_Config *config;
+    int r = 0;
+
+    libxl_device_pci_init(&pcidev);
+
+    config = xlu_cfg_init(stderr, "command line");
+    if (!config) { perror("xlu_cfg_inig"); exit(-1); }
+
+    if (xlu_pci_parse_bdf(config, &pcidev, bdf)) {
+        fprintf(stderr, "pci-attach: malformed BDF specification \"%s\"\n", 
bdf);
+        exit(2);
+    }
+
+    if (libxl_device_pci_add(ctx, domid, &pcidev, 0))
+        r = 1;
+
+    libxl_device_pci_dispose(&pcidev);
+    xlu_cfg_destroy(config);
+
+    return r;
+}
+
+int main_pciattach(int argc, char **argv)
+{
+    uint32_t domid;
+    int opt;
+    const char *bdf = NULL, *vs = NULL;
+
+    SWITCH_FOREACH_OPT(opt, "", NULL, "pci-attach", 2) {
+        /* No options */
+    }
+
+    domid = xfind_domain(argv[optind]);
+    bdf = argv[optind + 1];
+
+    if (optind + 1 < argc)
+        vs = argv[optind + 2];
+
+    if (pciattach(domid, bdf, vs))
+        return EXIT_FAILURE;
+
+    return EXIT_SUCCESS;
+}
+
+static void pciassignable_list(void)
+{
+    libxl_device_pci *pcidevs;
+    int num, i;
+
+    pcidevs = libxl_device_pci_assignable_list(ctx, &num);
+
+    if ( pcidevs == NULL )
+        return;
+    for (i = 0; i < num; i++) {
+        printf("%04x:%02x:%02x.%01x\n",
+               pcidevs[i].domain, pcidevs[i].bus, pcidevs[i].dev, 
pcidevs[i].func);
+        libxl_device_pci_dispose(&pcidevs[i]);
+    }
+    free(pcidevs);
+}
+
+int main_pciassignable_list(int argc, char **argv)
+{
+    int opt;
+
+    SWITCH_FOREACH_OPT(opt, "", NULL, "pci-assignable-list", 0) {
+        /* No options */
+    }
+
+    pciassignable_list();
+    return 0;
+}
+
+static int pciassignable_add(const char *bdf, int rebind)
+{
+    libxl_device_pci pcidev;
+    XLU_Config *config;
+    int r = 0;
+
+    libxl_device_pci_init(&pcidev);
+
+    config = xlu_cfg_init(stderr, "command line");
+    if (!config) { perror("xlu_cfg_init"); exit(-1); }
+
+    if (xlu_pci_parse_bdf(config, &pcidev, bdf)) {
+        fprintf(stderr, "pci-assignable-add: malformed BDF specification 
\"%s\"\n", bdf);
+        exit(2);
+    }
+
+    if (libxl_device_pci_assignable_add(ctx, &pcidev, rebind))
+        r = 1;
+
+    libxl_device_pci_dispose(&pcidev);
+    xlu_cfg_destroy(config);
+
+    return r;
+}
+
+int main_pciassignable_add(int argc, char **argv)
+{
+    int opt;
+    const char *bdf = NULL;
+
+    SWITCH_FOREACH_OPT(opt, "", NULL, "pci-assignable-add", 1) {
+        /* No options */
+    }
+
+    bdf = argv[optind];
+
+    if (pciassignable_add(bdf, 1))
+        return EXIT_FAILURE;
+
+    return EXIT_SUCCESS;
+}
+
+static int pciassignable_remove(const char *bdf, int rebind)
+{
+    libxl_device_pci pcidev;
+    XLU_Config *config;
+    int r = 0;
+
+    libxl_device_pci_init(&pcidev);
+
+    config = xlu_cfg_init(stderr, "command line");
+    if (!config) { perror("xlu_cfg_init"); exit(-1); }
+
+    if (xlu_pci_parse_bdf(config, &pcidev, bdf)) {
+        fprintf(stderr, "pci-assignable-remove: malformed BDF specification 
\"%s\"\n", bdf);
+        exit(2);
+    }
+
+    if (libxl_device_pci_assignable_remove(ctx, &pcidev, rebind))
+        r = 1;
+
+    libxl_device_pci_dispose(&pcidev);
+    xlu_cfg_destroy(config);
+
+    return r;
+}
+
+int main_pciassignable_remove(int argc, char **argv)
+{
+    int opt;
+    const char *bdf = NULL;
+    int rebind = 0;
+
+    SWITCH_FOREACH_OPT(opt, "r", NULL, "pci-assignable-remove", 1) {
+    case 'r':
+        rebind=1;
+        break;
+    }
+
+    bdf = argv[optind];
+
+    if (pciassignable_remove(bdf, rebind))
+        return EXIT_FAILURE;
+
+    return EXIT_SUCCESS;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
-- 
2.11.0


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.