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

[Xen-devel] [PATCH 13/29] xl: split out vtpm related code



Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx>
---
 tools/xl/Makefile     |   1 +
 tools/xl/xl_cmdimpl.c | 122 ----------------------------------------
 tools/xl/xl_vtpm.c    | 153 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 154 insertions(+), 122 deletions(-)
 create mode 100644 tools/xl/xl_vtpm.c

diff --git a/tools/xl/Makefile b/tools/xl/Makefile
index df0b5dd5cf..b31ec052c1 100644
--- a/tools/xl/Makefile
+++ b/tools/xl/Makefile
@@ -17,6 +17,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_OBJS): CFLAGS += $(CFLAGS_libxentoollog)
 $(XL_OBJS): CFLAGS += $(CFLAGS_XL)
diff --git a/tools/xl/xl_cmdimpl.c b/tools/xl/xl_cmdimpl.c
index eb87cb975a..aeb4fb362f 100644
--- a/tools/xl/xl_cmdimpl.c
+++ b/tools/xl/xl_cmdimpl.c
@@ -5274,128 +5274,6 @@ int main_blockdetach(int argc, char **argv)
     return rc;
 }
 
-int main_vtpmattach(int argc, char **argv)
-{
-    int opt;
-    libxl_device_vtpm vtpm;
-    char *oparg;
-    uint32_t domid;
-
-    SWITCH_FOREACH_OPT(opt, "", NULL, "vtpm-attach", 1) {
-        /* No options */
-    }
-
-    if (libxl_domain_qualifier_to_domid(ctx, argv[optind], &domid) < 0) {
-        fprintf(stderr, "%s is an invalid domain identifier\n", argv[optind]);
-        return 1;
-    }
-    ++optind;
-
-    libxl_device_vtpm_init(&vtpm);
-    for (argv += optind, argc -= optind; argc > 0; ++argv, --argc) {
-        if (MATCH_OPTION("uuid", *argv, oparg)) {
-            if(libxl_uuid_from_string(&(vtpm.uuid), oparg)) {
-                fprintf(stderr, "Invalid uuid specified (%s)\n", oparg);
-                return 1;
-            }
-        } else if (MATCH_OPTION("backend", *argv, oparg)) {
-            replace_string(&vtpm.backend_domname, oparg);
-        } else {
-            fprintf(stderr, "unrecognized argument `%s'\n", *argv);
-            return 1;
-        }
-    }
-
-    if(dryrun_only) {
-       char* json = libxl_device_vtpm_to_json(ctx, &vtpm);
-       printf("vtpm: %s\n", json);
-       free(json);
-       libxl_device_vtpm_dispose(&vtpm);
-       if (ferror(stdout) || fflush(stdout)) { perror("stdout"); exit(-1); }
-       return 0;
-    }
-
-    if (libxl_device_vtpm_add(ctx, domid, &vtpm, 0)) {
-        fprintf(stderr, "libxl_device_vtpm_add failed.\n");
-        return 1;
-    }
-    libxl_device_vtpm_dispose(&vtpm);
-    return 0;
-}
-
-int main_vtpmlist(int argc, char **argv)
-{
-    int opt;
-    libxl_device_vtpm *vtpms;
-    libxl_vtpminfo vtpminfo;
-    int nb, i;
-
-    SWITCH_FOREACH_OPT(opt, "", NULL, "vtpm-list", 1) {
-        /* No options */
-    }
-
-    /*      Idx  BE   UUID   Hdl  Sta  evch rref  BE-path */
-    printf("%-3s %-2s %-36s %-6s %-5s %-6s %-5s %-10s\n",
-           "Idx", "BE", "Uuid", "handle", "state", "evt-ch", "ring-ref", 
"BE-path");
-    for (argv += optind, argc -= optind; argc > 0; --argc, ++argv) {
-        uint32_t domid;
-        if (libxl_domain_qualifier_to_domid(ctx, *argv, &domid) < 0) {
-            fprintf(stderr, "%s is an invalid domain identifier\n", *argv);
-            continue;
-        }
-        if (!(vtpms = libxl_device_vtpm_list(ctx, domid, &nb))) {
-            continue;
-        }
-        for (i = 0; i < nb; ++i) {
-           if(!libxl_device_vtpm_getinfo(ctx, domid, &vtpms[i], &vtpminfo)) {
-              /*      Idx  BE     UUID             Hdl Sta evch rref BE-path*/
-              printf("%-3d %-2d " LIBXL_UUID_FMT " %6d %5d %6d %8d %-30s\n",
-                    vtpminfo.devid, vtpminfo.backend_id,
-                    LIBXL_UUID_BYTES(vtpminfo.uuid),
-                    vtpminfo.devid, vtpminfo.state, vtpminfo.evtch,
-                    vtpminfo.rref, vtpminfo.backend);
-
-              libxl_vtpminfo_dispose(&vtpminfo);
-           }
-           libxl_device_vtpm_dispose(&vtpms[i]);
-        }
-        free(vtpms);
-    }
-    return 0;
-}
-
-int main_vtpmdetach(int argc, char **argv)
-{
-    uint32_t domid;
-    int opt, rc=0;
-    libxl_device_vtpm vtpm;
-    libxl_uuid uuid;
-
-    SWITCH_FOREACH_OPT(opt, "", NULL, "vtpm-detach", 2) {
-        /* No options */
-    }
-
-    domid = xfind_domain(argv[optind]);
-
-    if ( libxl_uuid_from_string(&uuid, argv[optind+1])) {
-        if (libxl_devid_to_device_vtpm(ctx, domid, atoi(argv[optind+1]), 
&vtpm)) {
-            fprintf(stderr, "Unknown device %s.\n", argv[optind+1]);
-            return 1;
-        }
-    } else {
-        if (libxl_uuid_to_device_vtpm(ctx, domid, &uuid, &vtpm)) {
-            fprintf(stderr, "Unknown device %s.\n", argv[optind+1]);
-            return 1;
-        }
-    }
-    rc = libxl_device_vtpm_remove(ctx, domid, &vtpm, 0);
-    if (rc) {
-        fprintf(stderr, "libxl_device_vtpm_remove failed.\n");
-    }
-    libxl_device_vtpm_dispose(&vtpm);
-    return rc;
-}
-
 
 static char *uptime_to_string(unsigned long uptime, int short_mode)
 {
diff --git a/tools/xl/xl_vtpm.c b/tools/xl/xl_vtpm.c
new file mode 100644
index 0000000000..a69cc04eff
--- /dev/null
+++ b/tools/xl/xl_vtpm.c
@@ -0,0 +1,153 @@
+/*
+ * 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"
+
+int main_vtpmattach(int argc, char **argv)
+{
+    int opt;
+    libxl_device_vtpm vtpm;
+    char *oparg;
+    uint32_t domid;
+
+    SWITCH_FOREACH_OPT(opt, "", NULL, "vtpm-attach", 1) {
+        /* No options */
+    }
+
+    if (libxl_domain_qualifier_to_domid(ctx, argv[optind], &domid) < 0) {
+        fprintf(stderr, "%s is an invalid domain identifier\n", argv[optind]);
+        return 1;
+    }
+    ++optind;
+
+    libxl_device_vtpm_init(&vtpm);
+    for (argv += optind, argc -= optind; argc > 0; ++argv, --argc) {
+        if (MATCH_OPTION("uuid", *argv, oparg)) {
+            if(libxl_uuid_from_string(&(vtpm.uuid), oparg)) {
+                fprintf(stderr, "Invalid uuid specified (%s)\n", oparg);
+                return 1;
+            }
+        } else if (MATCH_OPTION("backend", *argv, oparg)) {
+            replace_string(&vtpm.backend_domname, oparg);
+        } else {
+            fprintf(stderr, "unrecognized argument `%s'\n", *argv);
+            return 1;
+        }
+    }
+
+    if(dryrun_only) {
+       char* json = libxl_device_vtpm_to_json(ctx, &vtpm);
+       printf("vtpm: %s\n", json);
+       free(json);
+       libxl_device_vtpm_dispose(&vtpm);
+       if (ferror(stdout) || fflush(stdout)) { perror("stdout"); exit(-1); }
+       return 0;
+    }
+
+    if (libxl_device_vtpm_add(ctx, domid, &vtpm, 0)) {
+        fprintf(stderr, "libxl_device_vtpm_add failed.\n");
+        return 1;
+    }
+    libxl_device_vtpm_dispose(&vtpm);
+    return 0;
+}
+
+int main_vtpmlist(int argc, char **argv)
+{
+    int opt;
+    libxl_device_vtpm *vtpms;
+    libxl_vtpminfo vtpminfo;
+    int nb, i;
+
+    SWITCH_FOREACH_OPT(opt, "", NULL, "vtpm-list", 1) {
+        /* No options */
+    }
+
+    /*      Idx  BE   UUID   Hdl  Sta  evch rref  BE-path */
+    printf("%-3s %-2s %-36s %-6s %-5s %-6s %-5s %-10s\n",
+           "Idx", "BE", "Uuid", "handle", "state", "evt-ch", "ring-ref", 
"BE-path");
+    for (argv += optind, argc -= optind; argc > 0; --argc, ++argv) {
+        uint32_t domid;
+        if (libxl_domain_qualifier_to_domid(ctx, *argv, &domid) < 0) {
+            fprintf(stderr, "%s is an invalid domain identifier\n", *argv);
+            continue;
+        }
+        if (!(vtpms = libxl_device_vtpm_list(ctx, domid, &nb))) {
+            continue;
+        }
+        for (i = 0; i < nb; ++i) {
+           if(!libxl_device_vtpm_getinfo(ctx, domid, &vtpms[i], &vtpminfo)) {
+              /*      Idx  BE     UUID             Hdl Sta evch rref BE-path*/
+              printf("%-3d %-2d " LIBXL_UUID_FMT " %6d %5d %6d %8d %-30s\n",
+                    vtpminfo.devid, vtpminfo.backend_id,
+                    LIBXL_UUID_BYTES(vtpminfo.uuid),
+                    vtpminfo.devid, vtpminfo.state, vtpminfo.evtch,
+                    vtpminfo.rref, vtpminfo.backend);
+
+              libxl_vtpminfo_dispose(&vtpminfo);
+           }
+           libxl_device_vtpm_dispose(&vtpms[i]);
+        }
+        free(vtpms);
+    }
+    return 0;
+}
+
+int main_vtpmdetach(int argc, char **argv)
+{
+    uint32_t domid;
+    int opt, rc=0;
+    libxl_device_vtpm vtpm;
+    libxl_uuid uuid;
+
+    SWITCH_FOREACH_OPT(opt, "", NULL, "vtpm-detach", 2) {
+        /* No options */
+    }
+
+    domid = xfind_domain(argv[optind]);
+
+    if ( libxl_uuid_from_string(&uuid, argv[optind+1])) {
+        if (libxl_devid_to_device_vtpm(ctx, domid, atoi(argv[optind+1]), 
&vtpm)) {
+            fprintf(stderr, "Unknown device %s.\n", argv[optind+1]);
+            return 1;
+        }
+    } else {
+        if (libxl_uuid_to_device_vtpm(ctx, domid, &uuid, &vtpm)) {
+            fprintf(stderr, "Unknown device %s.\n", argv[optind+1]);
+            return 1;
+        }
+    }
+    rc = libxl_device_vtpm_remove(ctx, domid, &vtpm, 0);
+    if (rc) {
+        fprintf(stderr, "libxl_device_vtpm_remove failed.\n");
+    }
+    libxl_device_vtpm_dispose(&vtpm);
+    return rc;
+}
+
+/*
+ * 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®.