[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 20/29] xl: split out cd related code
Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx> --- tools/xl/Makefile | 2 +- tools/xl/xl_cd.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++ tools/xl/xl_cmdimpl.c | 80 ----------------------------------- 3 files changed, 115 insertions(+), 81 deletions(-) create mode 100644 tools/xl/xl_cd.c diff --git a/tools/xl/Makefile b/tools/xl/Makefile index e6e8cef710..89cf9069e0 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_pci.o xl_vcpu.o +XL_OBJS += xl_sched.o xl_pci.o xl_vcpu.o xl_cd.o $(XL_OBJS): CFLAGS += $(CFLAGS_libxentoollog) $(XL_OBJS): CFLAGS += $(CFLAGS_XL) diff --git a/tools/xl/xl_cd.c b/tools/xl/xl_cd.c new file mode 100644 index 0000000000..d99f461c6d --- /dev/null +++ b/tools/xl/xl_cd.c @@ -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 = xfind_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 = xfind_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: + */ diff --git a/tools/xl/xl_cmdimpl.c b/tools/xl/xl_cmdimpl.c index faeac675ad..e15baae861 100644 --- a/tools/xl/xl_cmdimpl.c +++ b/tools/xl/xl_cmdimpl.c @@ -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 = xfind_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 = xfind_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; -- 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx https://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |