2011-02-21 13:40:10 +00:00
|
|
|
/*
|
|
|
|
* xen_xm.c: Xen XM parsing functions
|
|
|
|
*
|
2014-03-24 18:14:48 +00:00
|
|
|
* Copyright (C) 2006-2007, 2009-2014 Red Hat, Inc.
|
2011-02-21 13:40:10 +00:00
|
|
|
* Copyright (C) 2011 Univention GmbH
|
|
|
|
* Copyright (C) 2006 Daniel P. Berrange
|
|
|
|
*
|
|
|
|
* This library 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; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2011-02-21 13:40:10 +00:00
|
|
|
*
|
|
|
|
* Author: Daniel P. Berrange <berrange@redhat.com>
|
|
|
|
* Author: Markus Groß <gross@univention.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "internal.h"
|
2012-12-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2012-12-12 16:35:35 +00:00
|
|
|
#include "virconf.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2011-02-21 13:40:10 +00:00
|
|
|
#include "verify.h"
|
|
|
|
#include "xenxs_private.h"
|
|
|
|
#include "xen_xm.h"
|
2011-04-14 16:05:14 +00:00
|
|
|
#include "domain_conf.h"
|
2013-04-03 10:36:23 +00:00
|
|
|
#include "virstring.h"
|
2014-08-16 02:52:15 +00:00
|
|
|
#include "xen_common.h"
|
2014-08-07 18:32:54 +00:00
|
|
|
|
|
|
|
|
2014-08-07 18:32:55 +00:00
|
|
|
static int
|
|
|
|
xenParseXMDisk(virConfPtr conf, virDomainDefPtr def, int xendConfigVersion)
|
2014-03-18 08:14:16 +00:00
|
|
|
{
|
2014-08-07 18:32:55 +00:00
|
|
|
const char *str = NULL;
|
2011-02-21 13:40:10 +00:00
|
|
|
virDomainDiskDefPtr disk = NULL;
|
2014-08-07 18:32:55 +00:00
|
|
|
int hvm = STREQ(def->os.type, "hvm");
|
|
|
|
virConfValuePtr list = virConfGetValue(conf, "disk");
|
2011-02-21 13:40:10 +00:00
|
|
|
|
|
|
|
if (list && list->type == VIR_CONF_LIST) {
|
|
|
|
list = list->list;
|
|
|
|
while (list) {
|
|
|
|
char *head;
|
|
|
|
char *offset;
|
|
|
|
char *tmp;
|
2014-03-24 18:14:48 +00:00
|
|
|
const char *src;
|
2011-02-21 13:40:10 +00:00
|
|
|
|
|
|
|
if ((list->type != VIR_CONF_STRING) || (list->str == NULL))
|
|
|
|
goto skipdisk;
|
|
|
|
|
2014-08-07 18:32:55 +00:00
|
|
|
head = list->str;
|
2014-05-21 22:50:41 +00:00
|
|
|
if (!(disk = virDomainDiskDefNew()))
|
2014-08-07 18:32:55 +00:00
|
|
|
return -1;
|
2011-02-21 13:40:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Disks have 3 components, SOURCE,DEST-DEVICE,MODE
|
|
|
|
* eg, phy:/dev/HostVG/XenGuest1,xvda,w
|
|
|
|
* The SOURCE is usually prefixed with a driver type,
|
|
|
|
* and optionally driver sub-type
|
|
|
|
* The DEST-DEVICE is optionally post-fixed with disk type
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Extract the source file path*/
|
|
|
|
if (!(offset = strchr(head, ',')))
|
|
|
|
goto skipdisk;
|
|
|
|
|
|
|
|
if (offset == head) {
|
2014-03-24 18:14:48 +00:00
|
|
|
/* No source file given, eg CDROM with no media */
|
|
|
|
ignore_value(virDomainDiskSetSource(disk, NULL));
|
2011-02-21 13:40:10 +00:00
|
|
|
} else {
|
2014-03-24 18:14:48 +00:00
|
|
|
if (VIR_STRNDUP(tmp, head, offset - head) < 0)
|
2013-07-04 10:19:27 +00:00
|
|
|
goto cleanup;
|
2014-08-07 18:32:55 +00:00
|
|
|
|
2014-03-24 18:14:48 +00:00
|
|
|
if (virDomainDiskSetSource(disk, tmp) < 0) {
|
|
|
|
VIR_FREE(tmp);
|
2011-02-21 13:40:10 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2014-03-24 18:14:48 +00:00
|
|
|
VIR_FREE(tmp);
|
2011-02-21 13:40:10 +00:00
|
|
|
}
|
|
|
|
|
2014-08-07 18:32:55 +00:00
|
|
|
head = offset + 1;
|
2011-02-21 13:40:10 +00:00
|
|
|
/* Remove legacy ioemu: junk */
|
|
|
|
if (STRPREFIX(head, "ioemu:"))
|
|
|
|
head = head + 6;
|
|
|
|
|
|
|
|
/* Extract the dest device name */
|
|
|
|
if (!(offset = strchr(head, ',')))
|
|
|
|
goto skipdisk;
|
2014-08-07 18:32:55 +00:00
|
|
|
|
2011-02-21 13:40:10 +00:00
|
|
|
if (VIR_ALLOC_N(disk->dst, (offset - head) + 1) < 0)
|
2013-07-04 10:19:27 +00:00
|
|
|
goto cleanup;
|
2014-08-07 18:32:55 +00:00
|
|
|
|
2011-02-21 13:40:10 +00:00
|
|
|
if (virStrncpy(disk->dst, head, offset - head,
|
|
|
|
(offset - head) + 1) == NULL) {
|
2012-07-18 13:17:20 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Dest file %s too big for destination"), head);
|
2011-02-21 13:40:10 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-08-07 18:32:55 +00:00
|
|
|
head = offset + 1;
|
2011-02-21 13:40:10 +00:00
|
|
|
/* Extract source driver type */
|
2014-03-24 18:14:48 +00:00
|
|
|
src = virDomainDiskGetSource(disk);
|
|
|
|
if (src) {
|
|
|
|
size_t len;
|
2011-02-21 13:40:10 +00:00
|
|
|
/* The main type phy:, file:, tap: ... */
|
2014-03-24 18:14:48 +00:00
|
|
|
if ((tmp = strchr(src, ':')) != NULL) {
|
|
|
|
len = tmp - src;
|
|
|
|
if (VIR_STRNDUP(tmp, src, len) < 0)
|
2013-07-04 10:19:27 +00:00
|
|
|
goto cleanup;
|
2014-08-07 18:32:55 +00:00
|
|
|
|
2014-03-24 18:14:48 +00:00
|
|
|
if (virDomainDiskSetDriver(disk, tmp) < 0) {
|
|
|
|
VIR_FREE(tmp);
|
2011-02-21 13:40:10 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2014-03-24 18:14:48 +00:00
|
|
|
VIR_FREE(tmp);
|
2011-02-21 13:40:10 +00:00
|
|
|
|
|
|
|
/* Strip the prefix we found off the source file name */
|
2014-03-24 18:14:48 +00:00
|
|
|
if (virDomainDiskSetSource(disk, src + len + 1) < 0)
|
|
|
|
goto cleanup;
|
2014-08-07 18:32:55 +00:00
|
|
|
|
2014-03-24 18:14:48 +00:00
|
|
|
src = virDomainDiskGetSource(disk);
|
2011-02-21 13:40:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* And the sub-type for tap:XXX: type */
|
2014-03-24 18:14:48 +00:00
|
|
|
if (STREQ_NULLABLE(virDomainDiskGetDriver(disk), "tap")) {
|
2012-10-15 21:47:42 +00:00
|
|
|
char *driverType;
|
|
|
|
|
2014-03-24 18:14:48 +00:00
|
|
|
if (!(tmp = strchr(src, ':')))
|
2011-02-21 13:40:10 +00:00
|
|
|
goto skipdisk;
|
2014-03-24 18:14:48 +00:00
|
|
|
len = tmp - src;
|
2012-10-15 21:47:42 +00:00
|
|
|
|
2014-03-24 18:14:48 +00:00
|
|
|
if (VIR_STRNDUP(driverType, src, len) < 0)
|
2013-05-03 12:51:56 +00:00
|
|
|
goto cleanup;
|
2014-08-07 18:32:55 +00:00
|
|
|
|
2012-10-15 21:47:42 +00:00
|
|
|
if (STREQ(driverType, "aio"))
|
2014-03-24 18:14:48 +00:00
|
|
|
virDomainDiskSetFormat(disk, VIR_STORAGE_FILE_RAW);
|
2012-10-15 21:47:42 +00:00
|
|
|
else
|
2014-03-24 18:14:48 +00:00
|
|
|
virDomainDiskSetFormat(disk,
|
|
|
|
virStorageFileFormatTypeFromString(driverType));
|
2012-10-15 21:47:42 +00:00
|
|
|
VIR_FREE(driverType);
|
2014-03-24 18:14:48 +00:00
|
|
|
if (virDomainDiskGetFormat(disk) <= 0) {
|
2012-07-18 13:17:20 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
2012-10-15 21:47:42 +00:00
|
|
|
_("Unknown driver type %s"),
|
2014-03-24 18:14:48 +00:00
|
|
|
src);
|
2011-02-21 13:40:10 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Strip the prefix we found off the source file name */
|
2014-03-24 18:14:48 +00:00
|
|
|
if (virDomainDiskSetSource(disk, src + len + 1) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
src = virDomainDiskGetSource(disk);
|
2011-02-21 13:40:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No source, or driver name, so fix to phy: */
|
2014-03-24 18:14:48 +00:00
|
|
|
if (!virDomainDiskGetDriver(disk) &&
|
|
|
|
virDomainDiskSetDriver(disk, "phy") < 0)
|
2013-05-03 12:51:56 +00:00
|
|
|
goto cleanup;
|
2011-02-21 13:40:10 +00:00
|
|
|
|
|
|
|
/* phy: type indicates a block device */
|
2014-03-24 18:14:48 +00:00
|
|
|
virDomainDiskSetType(disk,
|
|
|
|
STREQ(virDomainDiskGetDriver(disk), "phy") ?
|
conf: move host disk type to util/
A continuation of the migration of disk details to virstoragefile.
This patch moves a single enum, but converting the name has quite
a bit of fallout.
* src/conf/domain_conf.h (virDomainDiskType): Move...
* src/util/virstoragefile.h (virStorageType): ...and rename.
* src/bhyve/bhyve_command.c (bhyveBuildDiskArgStr)
(virBhyveProcessBuildLoadCmd): Update clients.
* src/conf/domain_conf.c (virDomainDiskSourceDefParse)
(virDomainDiskDefParseXML, virDomainDiskSourceDefFormatInternal)
(virDomainDiskDefFormat, virDomainDiskGetActualType)
(virDomainDiskDefForeachPath, virDomainDiskSourceIsBlockType):
Likewise.
* src/conf/snapshot_conf.h (_virDomainSnapshotDiskDef): Likewise.
* src/conf/snapshot_conf.c (virDomainSnapshotDiskDefParseXML)
(virDomainSnapshotAlignDisks, virDomainSnapshotDiskDefFormat):
Likewise.
* src/esx/esx_driver.c (esxAutodetectSCSIControllerModel)
(esxDomainDefineXML): Likewise.
* src/locking/domain_lock.c (virDomainLockManagerAddDisk):
Likewise.
* src/lxc/lxc_controller.c
(virLXCControllerSetupLoopDeviceDisk)
(virLXCControllerSetupNBDDeviceDisk)
(virLXCControllerSetupLoopDevices, virLXCControllerSetupDisk):
Likewise.
* src/parallels/parallels_driver.c (parallelsGetHddInfo):
Likewise.
* src/phyp/phyp_driver.c (phypDiskType): Likewise.
* src/qemu/qemu_command.c (qemuGetDriveSourceString)
(qemuDomainDiskGetSourceString, qemuBuildDriveStr)
(qemuBuildCommandLine, qemuParseCommandLineDisk)
(qemuParseCommandLine): Likewise.
* src/qemu/qemu_conf.c (qemuCheckSharedDevice)
(qemuTranslateDiskSourcePool)
(qemuTranslateSnapshotDiskSourcePool): Likewise.
* src/qemu/qemu_domain.c (qemuDomainDeviceDefPostParse)
(qemuDomainDetermineDiskChain): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetBlockInfo)
(qemuDomainSnapshotPrepareDiskExternalBackingInactive)
(qemuDomainSnapshotPrepareDiskExternalBackingActive)
(qemuDomainSnapshotPrepareDiskExternalOverlayActive)
(qemuDomainSnapshotPrepareDiskExternalOverlayInactive)
(qemuDomainSnapshotPrepareDiskInternal)
(qemuDomainSnapshotPrepare)
(qemuDomainSnapshotCreateSingleDiskActive): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainChangeEjectableMedia):
Likewise.
* src/qemu/qemu_migration.c (qemuMigrationIsSafe): Likewise.
* src/security/security_apparmor.c
(AppArmorRestoreSecurityImageLabel)
(AppArmorSetSecurityImageLabel): Likewise.
* src/security/security_dac.c (virSecurityDACSetSecurityImageLabel)
(virSecurityDACRestoreSecurityImageLabelInt)
(virSecurityDACSetSecurityAllLabel): Likewise.
* src/security/security_selinux.c
(virSecuritySELinuxRestoreSecurityImageLabelInt)
(virSecuritySELinuxSetSecurityImageLabel)
(virSecuritySELinuxSetSecurityAllLabel): Likewise.
* src/storage/storage_backend.c (virStorageFileBackendForType):
Likewise.
* src/storage/storage_backend_fs.c (virStorageFileBackendFile)
(virStorageFileBackendBlock): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageFileBackendGluster): Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainGetXMLDesc, vboxAttachDrives)
(vboxDomainAttachDeviceImpl, vboxDomainDetachDevice): Likewise.
* src/vmware/vmware_conf.c (vmwareVmxPath): Likewise.
* src/vmx/vmx.c (virVMXParseDisk, virVMXFormatDisk)
(virVMXFormatFloppy): Likewise.
* src/xenxs/xen_sxpr.c (xenParseSxprDisks, xenParseSxpr)
(xenFormatSxprDisk): Likewise.
* src/xenxs/xen_xm.c (xenParseXM, xenFormatXMDisk): Likewise.
* tests/securityselinuxlabeltest.c (testSELinuxLoadDef):
Likewise.
* src/libvirt_private.syms (domain_conf.h): Move symbols...
(virstoragefile.h): ...as appropriate.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-27 21:57:49 +00:00
|
|
|
VIR_STORAGE_TYPE_BLOCK :
|
|
|
|
VIR_STORAGE_TYPE_FILE);
|
2011-02-21 13:40:10 +00:00
|
|
|
|
|
|
|
/* Check for a :cdrom/:disk postfix */
|
|
|
|
disk->device = VIR_DOMAIN_DISK_DEVICE_DISK;
|
|
|
|
if ((tmp = strchr(disk->dst, ':')) != NULL) {
|
|
|
|
if (STREQ(tmp, ":cdrom"))
|
|
|
|
disk->device = VIR_DOMAIN_DISK_DEVICE_CDROM;
|
|
|
|
tmp[0] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (STRPREFIX(disk->dst, "xvd") || !hvm) {
|
|
|
|
disk->bus = VIR_DOMAIN_DISK_BUS_XEN;
|
|
|
|
} else if (STRPREFIX(disk->dst, "sd")) {
|
|
|
|
disk->bus = VIR_DOMAIN_DISK_BUS_SCSI;
|
|
|
|
} else {
|
|
|
|
disk->bus = VIR_DOMAIN_DISK_BUS_IDE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (STREQ(head, "r") ||
|
|
|
|
STREQ(head, "ro"))
|
2014-06-24 13:15:55 +00:00
|
|
|
disk->src->readonly = true;
|
2011-02-21 13:40:10 +00:00
|
|
|
else if ((STREQ(head, "w!")) ||
|
|
|
|
(STREQ(head, "!")))
|
2014-06-24 13:15:55 +00:00
|
|
|
disk->src->shared = true;
|
2011-02-21 13:40:10 +00:00
|
|
|
|
|
|
|
/* Maintain list in sorted order according to target device name */
|
2014-03-07 08:33:31 +00:00
|
|
|
if (VIR_APPEND_ELEMENT(def->disks, def->ndisks, disk) < 0)
|
2013-07-04 10:19:27 +00:00
|
|
|
goto cleanup;
|
2011-02-21 13:40:10 +00:00
|
|
|
|
|
|
|
skipdisk:
|
|
|
|
list = list->next;
|
|
|
|
virDomainDiskDefFree(disk);
|
2014-08-27 11:48:37 +00:00
|
|
|
disk = NULL;
|
2011-02-21 13:40:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-31 17:08:09 +00:00
|
|
|
if (hvm && xendConfigVersion == XEND_CONFIG_VERSION_3_0_2) {
|
2014-08-16 02:52:15 +00:00
|
|
|
if (xenConfigGetString(conf, "cdrom", &str, NULL) < 0)
|
2011-02-21 13:40:10 +00:00
|
|
|
goto cleanup;
|
|
|
|
if (str) {
|
2014-05-21 22:50:41 +00:00
|
|
|
if (!(disk = virDomainDiskDefNew()))
|
2013-07-04 10:19:27 +00:00
|
|
|
goto cleanup;
|
2011-02-21 13:40:10 +00:00
|
|
|
|
conf: move host disk type to util/
A continuation of the migration of disk details to virstoragefile.
This patch moves a single enum, but converting the name has quite
a bit of fallout.
* src/conf/domain_conf.h (virDomainDiskType): Move...
* src/util/virstoragefile.h (virStorageType): ...and rename.
* src/bhyve/bhyve_command.c (bhyveBuildDiskArgStr)
(virBhyveProcessBuildLoadCmd): Update clients.
* src/conf/domain_conf.c (virDomainDiskSourceDefParse)
(virDomainDiskDefParseXML, virDomainDiskSourceDefFormatInternal)
(virDomainDiskDefFormat, virDomainDiskGetActualType)
(virDomainDiskDefForeachPath, virDomainDiskSourceIsBlockType):
Likewise.
* src/conf/snapshot_conf.h (_virDomainSnapshotDiskDef): Likewise.
* src/conf/snapshot_conf.c (virDomainSnapshotDiskDefParseXML)
(virDomainSnapshotAlignDisks, virDomainSnapshotDiskDefFormat):
Likewise.
* src/esx/esx_driver.c (esxAutodetectSCSIControllerModel)
(esxDomainDefineXML): Likewise.
* src/locking/domain_lock.c (virDomainLockManagerAddDisk):
Likewise.
* src/lxc/lxc_controller.c
(virLXCControllerSetupLoopDeviceDisk)
(virLXCControllerSetupNBDDeviceDisk)
(virLXCControllerSetupLoopDevices, virLXCControllerSetupDisk):
Likewise.
* src/parallels/parallels_driver.c (parallelsGetHddInfo):
Likewise.
* src/phyp/phyp_driver.c (phypDiskType): Likewise.
* src/qemu/qemu_command.c (qemuGetDriveSourceString)
(qemuDomainDiskGetSourceString, qemuBuildDriveStr)
(qemuBuildCommandLine, qemuParseCommandLineDisk)
(qemuParseCommandLine): Likewise.
* src/qemu/qemu_conf.c (qemuCheckSharedDevice)
(qemuTranslateDiskSourcePool)
(qemuTranslateSnapshotDiskSourcePool): Likewise.
* src/qemu/qemu_domain.c (qemuDomainDeviceDefPostParse)
(qemuDomainDetermineDiskChain): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetBlockInfo)
(qemuDomainSnapshotPrepareDiskExternalBackingInactive)
(qemuDomainSnapshotPrepareDiskExternalBackingActive)
(qemuDomainSnapshotPrepareDiskExternalOverlayActive)
(qemuDomainSnapshotPrepareDiskExternalOverlayInactive)
(qemuDomainSnapshotPrepareDiskInternal)
(qemuDomainSnapshotPrepare)
(qemuDomainSnapshotCreateSingleDiskActive): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainChangeEjectableMedia):
Likewise.
* src/qemu/qemu_migration.c (qemuMigrationIsSafe): Likewise.
* src/security/security_apparmor.c
(AppArmorRestoreSecurityImageLabel)
(AppArmorSetSecurityImageLabel): Likewise.
* src/security/security_dac.c (virSecurityDACSetSecurityImageLabel)
(virSecurityDACRestoreSecurityImageLabelInt)
(virSecurityDACSetSecurityAllLabel): Likewise.
* src/security/security_selinux.c
(virSecuritySELinuxRestoreSecurityImageLabelInt)
(virSecuritySELinuxSetSecurityImageLabel)
(virSecuritySELinuxSetSecurityAllLabel): Likewise.
* src/storage/storage_backend.c (virStorageFileBackendForType):
Likewise.
* src/storage/storage_backend_fs.c (virStorageFileBackendFile)
(virStorageFileBackendBlock): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageFileBackendGluster): Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainGetXMLDesc, vboxAttachDrives)
(vboxDomainAttachDeviceImpl, vboxDomainDetachDevice): Likewise.
* src/vmware/vmware_conf.c (vmwareVmxPath): Likewise.
* src/vmx/vmx.c (virVMXParseDisk, virVMXFormatDisk)
(virVMXFormatFloppy): Likewise.
* src/xenxs/xen_sxpr.c (xenParseSxprDisks, xenParseSxpr)
(xenFormatSxprDisk): Likewise.
* src/xenxs/xen_xm.c (xenParseXM, xenFormatXMDisk): Likewise.
* tests/securityselinuxlabeltest.c (testSELinuxLoadDef):
Likewise.
* src/libvirt_private.syms (domain_conf.h): Move symbols...
(virstoragefile.h): ...as appropriate.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-27 21:57:49 +00:00
|
|
|
virDomainDiskSetType(disk, VIR_STORAGE_TYPE_FILE);
|
2011-02-21 13:40:10 +00:00
|
|
|
disk->device = VIR_DOMAIN_DISK_DEVICE_CDROM;
|
2014-03-24 18:14:48 +00:00
|
|
|
if (virDomainDiskSetDriver(disk, "file") < 0)
|
2013-05-03 12:51:56 +00:00
|
|
|
goto cleanup;
|
2014-03-24 18:14:48 +00:00
|
|
|
if (virDomainDiskSetSource(disk, str) < 0)
|
2013-05-03 12:51:56 +00:00
|
|
|
goto cleanup;
|
|
|
|
if (VIR_STRDUP(disk->dst, "hdc") < 0)
|
|
|
|
goto cleanup;
|
2011-02-21 13:40:10 +00:00
|
|
|
disk->bus = VIR_DOMAIN_DISK_BUS_IDE;
|
2014-06-24 13:15:55 +00:00
|
|
|
disk->src->readonly = true;
|
2011-02-21 13:40:10 +00:00
|
|
|
|
2014-03-07 08:33:31 +00:00
|
|
|
if (VIR_APPEND_ELEMENT(def->disks, def->ndisks, disk) < 0)
|
2013-07-04 10:19:27 +00:00
|
|
|
goto cleanup;
|
2011-02-21 13:40:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-07 18:32:55 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virDomainDiskDefFree(disk);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-07 18:32:56 +00:00
|
|
|
static int
|
2014-08-16 02:52:15 +00:00
|
|
|
xenFormatXMDisk(virConfValuePtr list,
|
|
|
|
virDomainDiskDefPtr disk,
|
|
|
|
int hvm,
|
|
|
|
int xendConfigVersion)
|
2014-08-07 18:32:56 +00:00
|
|
|
{
|
2014-08-16 02:52:15 +00:00
|
|
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
|
|
|
virConfValuePtr val, tmp;
|
|
|
|
const char *src = virDomainDiskGetSource(disk);
|
|
|
|
int format = virDomainDiskGetFormat(disk);
|
|
|
|
const char *driver = virDomainDiskGetDriver(disk);
|
2014-08-07 18:32:56 +00:00
|
|
|
|
2014-08-16 02:52:15 +00:00
|
|
|
if (src) {
|
|
|
|
if (format) {
|
|
|
|
const char *type;
|
2014-08-07 18:32:56 +00:00
|
|
|
|
2014-08-16 02:52:15 +00:00
|
|
|
if (format == VIR_STORAGE_FILE_RAW)
|
|
|
|
type = "aio";
|
|
|
|
else
|
|
|
|
type = virStorageFileFormatTypeToString(format);
|
|
|
|
virBufferAsprintf(&buf, "%s:", driver);
|
|
|
|
if (STREQ(driver, "tap"))
|
|
|
|
virBufferAsprintf(&buf, "%s:", type);
|
2014-08-07 18:32:56 +00:00
|
|
|
} else {
|
2014-08-16 02:52:15 +00:00
|
|
|
switch (virDomainDiskGetType(disk)) {
|
|
|
|
case VIR_STORAGE_TYPE_FILE:
|
|
|
|
virBufferAddLit(&buf, "file:");
|
|
|
|
break;
|
|
|
|
case VIR_STORAGE_TYPE_BLOCK:
|
|
|
|
virBufferAddLit(&buf, "phy:");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("unsupported disk type %s"),
|
|
|
|
virStorageTypeToString(virDomainDiskGetType(disk)));
|
2014-08-07 18:32:56 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
2014-08-16 02:52:15 +00:00
|
|
|
virBufferAdd(&buf, src, -1);
|
2014-08-07 18:32:56 +00:00
|
|
|
}
|
2014-08-16 02:52:15 +00:00
|
|
|
virBufferAddLit(&buf, ",");
|
|
|
|
if (hvm && xendConfigVersion == XEND_CONFIG_VERSION_3_0_2)
|
|
|
|
virBufferAddLit(&buf, "ioemu:");
|
2014-08-07 18:32:56 +00:00
|
|
|
|
2014-08-16 02:52:15 +00:00
|
|
|
virBufferAdd(&buf, disk->dst, -1);
|
|
|
|
if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM)
|
|
|
|
virBufferAddLit(&buf, ":cdrom");
|
2014-08-07 18:32:56 +00:00
|
|
|
|
2014-08-16 02:52:15 +00:00
|
|
|
if (disk->src->readonly)
|
|
|
|
virBufferAddLit(&buf, ",r");
|
|
|
|
else if (disk->src->shared)
|
|
|
|
virBufferAddLit(&buf, ",!");
|
|
|
|
else
|
|
|
|
virBufferAddLit(&buf, ",w");
|
|
|
|
if (disk->transient) {
|
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("transient disks not supported yet"));
|
2014-08-11 21:21:28 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-08-16 02:52:15 +00:00
|
|
|
if (virBufferCheckError(&buf) < 0)
|
|
|
|
goto cleanup;
|
2014-08-11 21:21:28 +00:00
|
|
|
|
2014-08-16 02:52:15 +00:00
|
|
|
if (VIR_ALLOC(val) < 0)
|
|
|
|
goto cleanup;
|
2014-08-11 21:21:28 +00:00
|
|
|
|
2014-08-16 02:52:15 +00:00
|
|
|
val->type = VIR_CONF_STRING;
|
|
|
|
val->str = virBufferContentAndReset(&buf);
|
|
|
|
tmp = list->list;
|
|
|
|
while (tmp && tmp->next)
|
|
|
|
tmp = tmp->next;
|
|
|
|
if (tmp)
|
|
|
|
tmp->next = val;
|
|
|
|
else
|
|
|
|
list->list = val;
|
2014-08-11 21:21:28 +00:00
|
|
|
|
|
|
|
return 0;
|
2014-08-11 21:21:29 +00:00
|
|
|
|
2014-08-16 02:52:15 +00:00
|
|
|
cleanup:
|
|
|
|
virBufferFreeAndReset(&buf);
|
|
|
|
return -1;
|
2014-08-11 21:21:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-11 21:21:30 +00:00
|
|
|
static int
|
|
|
|
xenFormatXMDisks(virConfPtr conf, virDomainDefPtr def, int xendConfigVersion)
|
|
|
|
{
|
|
|
|
virConfValuePtr diskVal = NULL;
|
|
|
|
size_t i = 0;
|
|
|
|
int hvm = STREQ(def->os.type, "hvm");
|
|
|
|
|
|
|
|
if (VIR_ALLOC(diskVal) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
diskVal->type = VIR_CONF_LIST;
|
|
|
|
diskVal->list = NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < def->ndisks; i++) {
|
|
|
|
if (xendConfigVersion == XEND_CONFIG_VERSION_3_0_2 &&
|
|
|
|
def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_CDROM &&
|
|
|
|
def->disks[i]->dst &&
|
|
|
|
STREQ(def->disks[i]->dst, "hdc")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (xenFormatXMDisk(diskVal, def->disks[i],
|
|
|
|
hvm, xendConfigVersion) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (diskVal->list != NULL) {
|
|
|
|
int ret = virConfSetValue(conf, "disk", diskVal);
|
|
|
|
diskVal = NULL;
|
|
|
|
if (ret < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
VIR_FREE(diskVal);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virConfFreeValue(diskVal);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-16 02:52:15 +00:00
|
|
|
/*
|
|
|
|
* Convert an XM config record into a virDomainDef object.
|
|
|
|
*/
|
|
|
|
virDomainDefPtr
|
|
|
|
xenParseXM(virConfPtr conf,
|
|
|
|
int xendConfigVersion,
|
|
|
|
virCapsPtr caps)
|
2014-08-11 21:21:34 +00:00
|
|
|
{
|
2014-08-16 02:52:15 +00:00
|
|
|
virDomainDefPtr def = NULL;
|
2014-08-11 21:21:34 +00:00
|
|
|
|
2014-08-16 02:52:15 +00:00
|
|
|
if (VIR_ALLOC(def) < 0)
|
|
|
|
return NULL;
|
2014-08-11 21:21:34 +00:00
|
|
|
|
2014-08-16 02:52:15 +00:00
|
|
|
def->virtType = VIR_DOMAIN_VIRT_XEN;
|
|
|
|
def->id = -1;
|
2014-08-13 20:46:16 +00:00
|
|
|
|
2014-08-16 02:52:15 +00:00
|
|
|
if (xenParseConfigCommon(conf, def, caps, xendConfigVersion) < 0)
|
2014-08-13 20:46:16 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2014-08-16 02:52:15 +00:00
|
|
|
if (xenParseXMDisk(conf, def, xendConfigVersion) < 0)
|
|
|
|
goto cleanup;
|
2014-08-13 20:46:16 +00:00
|
|
|
|
2014-08-16 02:52:15 +00:00
|
|
|
return def;
|
2014-08-13 20:46:16 +00:00
|
|
|
|
|
|
|
cleanup:
|
2014-08-16 02:52:15 +00:00
|
|
|
virDomainDefFree(def);
|
|
|
|
return NULL;
|
2014-08-11 21:21:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is
|
|
|
|
either 32, or 64 on a platform where long is big enough. */
|
|
|
|
verify(MAX_VIRT_CPUS <= sizeof(1UL) * CHAR_BIT);
|
|
|
|
|
2014-08-16 02:52:15 +00:00
|
|
|
/*
|
|
|
|
* Convert a virDomainDef object inot an XM config record.
|
|
|
|
*/
|
2014-08-11 21:21:35 +00:00
|
|
|
virConfPtr
|
|
|
|
xenFormatXM(virConnectPtr conn,
|
|
|
|
virDomainDefPtr def,
|
|
|
|
int xendConfigVersion)
|
|
|
|
{
|
|
|
|
virConfPtr conf = NULL;
|
|
|
|
|
|
|
|
if (!(conf = virConfNew()))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (xenFormatConfigCommon(conf, def, conn, xendConfigVersion) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (xenFormatXMDisks(conf, def, xendConfigVersion) < 0)
|
2014-08-11 21:21:34 +00:00
|
|
|
goto cleanup;
|
2011-02-21 13:40:11 +00:00
|
|
|
|
|
|
|
return conf;
|
|
|
|
|
2014-03-25 06:57:22 +00:00
|
|
|
cleanup:
|
2011-02-21 13:40:11 +00:00
|
|
|
if (conf)
|
|
|
|
virConfFree(conf);
|
2012-03-22 11:33:35 +00:00
|
|
|
return NULL;
|
2011-02-25 14:41:12 +00:00
|
|
|
}
|