mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 02:01:24 +01:00
xl: split out cdrom related code
Signed-off-by: Wei Liu <wei.liu2@citrix.com> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
This commit is contained in:
1 parent
1378a24cb1
commit
07a1a8c3c8
3 files changed
+115
-81
No files matched your search
+1
-1
@@ -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)
|
||||
|
||||
@@ -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:
|
||||
*/
|
||||
@@ -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;
|
||||
|
||||