]> xenbits.xensource.com Git - xen.git/commitdiff
xl: split out cdrom related code
authorWei Liu <wei.liu2@citrix.com>
Fri, 24 Feb 2017 14:08:53 +0000 (14:08 +0000)
committerWei Liu <wei.liu2@citrix.com>
Tue, 28 Feb 2017 10:40:07 +0000 (10:40 +0000)
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/xl/Makefile
tools/xl/xl_cdrom.c [new file with mode: 0644]
tools/xl/xl_cmdimpl.c

index e6e8cef7103b8a9c626b8ec2878d06838beee997..24beb6a90ded1cbe261b0240eeccb10b4538a494 100644 (file)
@@ -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_pci.o xl_vcpu.o
+XL_OBJS += xl_sched.o xl_pci.o xl_vcpu.o xl_cdrom.o
 
 $(XL_OBJS): CFLAGS += $(CFLAGS_libxentoollog)
 $(XL_OBJS): CFLAGS += $(CFLAGS_XL)
diff --git a/tools/xl/xl_cdrom.c b/tools/xl/xl_cdrom.c
new file mode 100644 (file)
index 0000000..df987dd
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+ * 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 <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include <libxl.h>
+#include <libxl_utils.h>
+#include <libxlutil.h>
+
+#include "xl.h"
+#include "xl_utils.h"
+#include "xl_parse.h"
+
+static int cd_insert(uint32_t domid, const char *virtdev, char *phys)
+{
+    libxl_device_disk disk;
+    char *buf = NULL;
+    XLU_Config *config = 0;
+    struct stat b;
+    int r;
+
+    xasprintf(&buf, "vdev=%s,access=r,devtype=cdrom,target=%s",
+              virtdev, phys ? phys : "");
+
+    parse_disk_config(&config, buf, &disk);
+
+    /* ATM the existence of the backing file is not checked for qdisk
+     * in libxl_cdrom_insert() because RAW is used for remote
+     * protocols as well as plain files.  This will ideally be changed
+     * for 4.4, but this work-around fixes the problem of "cd-insert"
+     * returning success for non-existent files. */
+    if (disk.format != LIBXL_DISK_FORMAT_EMPTY
+        && stat(disk.pdev_path, &b)) {
+        fprintf(stderr, "Cannot stat file: %s\n",
+                disk.pdev_path);
+        r = 1;
+        goto out;
+    }
+
+    if (libxl_cdrom_insert(ctx, domid, &disk, NULL)) {
+        r = 1;
+        goto out;
+    }
+
+    r = 0;
+
+out:
+    libxl_device_disk_dispose(&disk);
+    free(buf);
+
+    return r;
+}
+
+int main_cd_eject(int argc, char **argv)
+{
+    uint32_t domid;
+    int opt = 0;
+    const char *virtdev;
+
+    SWITCH_FOREACH_OPT(opt, "", NULL, "cd-eject", 2) {
+        /* No options */
+    }
+
+    domid = find_domain(argv[optind]);
+    virtdev = argv[optind + 1];
+
+    if (cd_insert(domid, virtdev, NULL))
+        return EXIT_FAILURE;
+
+    return EXIT_SUCCESS;
+}
+
+int main_cd_insert(int argc, char **argv)
+{
+    uint32_t domid;
+    int opt = 0;
+    const char *virtdev;
+    char *file = NULL; /* modified by cd_insert tokenising it */
+
+    SWITCH_FOREACH_OPT(opt, "", NULL, "cd-insert", 3) {
+        /* No options */
+    }
+
+    domid = find_domain(argv[optind]);
+    virtdev = argv[optind + 1];
+    file = argv[optind + 2];
+
+    if (cd_insert(domid, virtdev, file))
+        return EXIT_FAILURE;
+
+    return EXIT_SUCCESS;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
index 1acdf549a73081bfce7984989d738486181ee4f9..cd3a3ba9b9737e4142e18ef9e5ea09b0b66c4022 100644 (file)
@@ -1213,86 +1213,6 @@ int main_memset(int argc, char **argv)
     return set_memory_target(domid, mem);
 }
 
-static int cd_insert(uint32_t domid, const char *virtdev, char *phys)
-{
-    libxl_device_disk disk;
-    char *buf = NULL;
-    XLU_Config *config = 0;
-    struct stat b;
-    int r;
-
-    xasprintf(&buf, "vdev=%s,access=r,devtype=cdrom,target=%s",
-              virtdev, phys ? phys : "");
-
-    parse_disk_config(&config, buf, &disk);
-
-    /* ATM the existence of the backing file is not checked for qdisk
-     * in libxl_cdrom_insert() because RAW is used for remote
-     * protocols as well as plain files.  This will ideally be changed
-     * for 4.4, but this work-around fixes the problem of "cd-insert"
-     * returning success for non-existent files. */
-    if (disk.format != LIBXL_DISK_FORMAT_EMPTY
-        && stat(disk.pdev_path, &b)) {
-        fprintf(stderr, "Cannot stat file: %s\n",
-                disk.pdev_path);
-        r = 1;
-        goto out;
-    }
-
-    if (libxl_cdrom_insert(ctx, domid, &disk, NULL)) {
-        r = 1;
-        goto out;
-    }
-
-    r = 0;
-
-out:
-    libxl_device_disk_dispose(&disk);
-    free(buf);
-
-    return r;
-}
-
-int main_cd_eject(int argc, char **argv)
-{
-    uint32_t domid;
-    int opt = 0;
-    const char *virtdev;
-
-    SWITCH_FOREACH_OPT(opt, "", NULL, "cd-eject", 2) {
-        /* No options */
-    }
-
-    domid = find_domain(argv[optind]);
-    virtdev = argv[optind + 1];
-
-    if (cd_insert(domid, virtdev, NULL))
-        return EXIT_FAILURE;
-
-    return EXIT_SUCCESS;
-}
-
-int main_cd_insert(int argc, char **argv)
-{
-    uint32_t domid;
-    int opt = 0;
-    const char *virtdev;
-    char *file = NULL; /* modified by cd_insert tokenising it */
-
-    SWITCH_FOREACH_OPT(opt, "", NULL, "cd-insert", 3) {
-        /* No options */
-    }
-
-    domid = find_domain(argv[optind]);
-    virtdev = argv[optind + 1];
-    file = argv[optind + 2];
-
-    if (cd_insert(domid, virtdev, file))
-        return EXIT_FAILURE;
-
-    return EXIT_SUCCESS;
-}
-
 int main_console(int argc, char **argv)
 {
     uint32_t domid;