mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
storage: use enum for disk driver type
Actually use the enum in the domain conf structure. * src/conf/domain_conf.h (_virDomainDiskDef): Store enum rather than string for disk type. * src/conf/domain_conf.c (virDomainDiskDefFree) (virDomainDiskDefParseXML, virDomainDiskDefFormat) (virDomainDiskDefForeachPath): Adjust users. * src/xenxs/xen_sxpr.c (xenParseSxprDisks, xenFormatSxprDisk): Likewise. * src/xenxs/xen_xm.c (xenParseXM, xenFormatXMDisk): Likewise. * src/vbox/vbox_tmpl.c (vboxAttachDrives): Likewise. * src/libxl/libxl_conf.c (libxlMakeDisk): Likewise.
This commit is contained in:
parent
09e7fb5e1f
commit
e5e8d5d082
@ -975,9 +975,7 @@ void virDomainDiskDefFree(virDomainDiskDefPtr def)
|
|||||||
VIR_FREE(def->src);
|
VIR_FREE(def->src);
|
||||||
VIR_FREE(def->dst);
|
VIR_FREE(def->dst);
|
||||||
VIR_FREE(def->driverName);
|
VIR_FREE(def->driverName);
|
||||||
VIR_FREE(def->driverType);
|
|
||||||
VIR_FREE(def->mirror);
|
VIR_FREE(def->mirror);
|
||||||
VIR_FREE(def->mirrorFormat);
|
|
||||||
VIR_FREE(def->auth.username);
|
VIR_FREE(def->auth.username);
|
||||||
VIR_FREE(def->wwn);
|
VIR_FREE(def->wwn);
|
||||||
if (def->auth.secretType == VIR_DOMAIN_DISK_SECRET_TYPE_USAGE)
|
if (def->auth.secretType == VIR_DOMAIN_DISK_SECRET_TYPE_USAGE)
|
||||||
@ -4176,12 +4174,8 @@ virDomainDiskDefParseXML(virCapsPtr caps,
|
|||||||
authUsername = NULL;
|
authUsername = NULL;
|
||||||
def->driverName = driverName;
|
def->driverName = driverName;
|
||||||
driverName = NULL;
|
driverName = NULL;
|
||||||
def->driverType = driverType;
|
|
||||||
driverType = NULL;
|
|
||||||
def->mirror = mirror;
|
def->mirror = mirror;
|
||||||
mirror = NULL;
|
mirror = NULL;
|
||||||
def->mirrorFormat = mirrorFormat;
|
|
||||||
mirrorFormat = NULL;
|
|
||||||
def->mirroring = mirroring;
|
def->mirroring = mirroring;
|
||||||
def->encryption = encryption;
|
def->encryption = encryption;
|
||||||
encryption = NULL;
|
encryption = NULL;
|
||||||
@ -4190,23 +4184,35 @@ virDomainDiskDefParseXML(virCapsPtr caps,
|
|||||||
def->wwn = wwn;
|
def->wwn = wwn;
|
||||||
wwn = NULL;
|
wwn = NULL;
|
||||||
|
|
||||||
if (!def->driverType &&
|
if (driverType) {
|
||||||
caps->defaultDiskDriverType &&
|
def->format = virStorageFileFormatTypeFromString(driverType);
|
||||||
!(def->driverType = strdup(virStorageFileFormatTypeToString(
|
if (def->format <= 0) {
|
||||||
caps->defaultDiskDriverType))))
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
goto no_memory;
|
_("unknown driver format value '%s'"),
|
||||||
|
driverType);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
} else if (def->type == VIR_DOMAIN_DISK_TYPE_FILE ||
|
||||||
|
def->type == VIR_DOMAIN_DISK_TYPE_BLOCK) {
|
||||||
|
def->format = caps->defaultDiskDriverType;
|
||||||
|
}
|
||||||
|
|
||||||
if (!def->driverName &&
|
if (!def->driverName &&
|
||||||
caps->defaultDiskDriverName &&
|
caps->defaultDiskDriverName &&
|
||||||
!(def->driverName = strdup(caps->defaultDiskDriverName)))
|
!(def->driverName = strdup(caps->defaultDiskDriverName)))
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
|
|
||||||
|
if (mirrorFormat) {
|
||||||
if (def->mirror && !def->mirrorFormat &&
|
def->mirrorFormat = virStorageFileFormatTypeFromString(mirrorFormat);
|
||||||
caps->defaultDiskDriverType &&
|
if (def->mirrorFormat <= 0) {
|
||||||
!(def->mirrorFormat = strdup(virStorageFileFormatTypeToString(
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
caps->defaultDiskDriverType))))
|
_("unknown mirror format value '%s'"),
|
||||||
goto no_memory;
|
driverType);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
} else if (def->mirror) {
|
||||||
|
def->mirrorFormat = caps->defaultDiskDriverType;
|
||||||
|
}
|
||||||
|
|
||||||
if (def->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE
|
if (def->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE
|
||||||
&& virDomainDiskDefAssignAddress(caps, def) < 0)
|
&& virDomainDiskDefAssignAddress(caps, def) < 0)
|
||||||
@ -11865,13 +11871,14 @@ virDomainDiskDefFormat(virBufferPtr buf,
|
|||||||
virDomainSnapshotLocationTypeToString(def->snapshot));
|
virDomainSnapshotLocationTypeToString(def->snapshot));
|
||||||
virBufferAddLit(buf, ">\n");
|
virBufferAddLit(buf, ">\n");
|
||||||
|
|
||||||
if (def->driverName || def->driverType || def->cachemode ||
|
if (def->driverName || def->format > 0 || def->cachemode ||
|
||||||
def->ioeventfd || def->event_idx || def->copy_on_read) {
|
def->ioeventfd || def->event_idx || def->copy_on_read) {
|
||||||
virBufferAddLit(buf, " <driver");
|
virBufferAddLit(buf, " <driver");
|
||||||
if (def->driverName)
|
if (def->driverName)
|
||||||
virBufferAsprintf(buf, " name='%s'", def->driverName);
|
virBufferAsprintf(buf, " name='%s'", def->driverName);
|
||||||
if (def->driverType)
|
if (def->format > 0)
|
||||||
virBufferAsprintf(buf, " type='%s'", def->driverType);
|
virBufferAsprintf(buf, " type='%s'",
|
||||||
|
virStorageFileFormatTypeToString(def->format));
|
||||||
if (def->cachemode)
|
if (def->cachemode)
|
||||||
virBufferAsprintf(buf, " cache='%s'", cachemode);
|
virBufferAsprintf(buf, " cache='%s'", cachemode);
|
||||||
if (def->error_policy)
|
if (def->error_policy)
|
||||||
@ -11983,7 +11990,8 @@ virDomainDiskDefFormat(virBufferPtr buf,
|
|||||||
if (def->mirror && !(flags & VIR_DOMAIN_XML_INACTIVE)) {
|
if (def->mirror && !(flags & VIR_DOMAIN_XML_INACTIVE)) {
|
||||||
virBufferEscapeString(buf, " <mirror file='%s'", def->mirror);
|
virBufferEscapeString(buf, " <mirror file='%s'", def->mirror);
|
||||||
if (def->mirrorFormat)
|
if (def->mirrorFormat)
|
||||||
virBufferAsprintf(buf, " format='%s'", def->mirrorFormat);
|
virBufferAsprintf(buf, " format='%s'",
|
||||||
|
virStorageFileFormatTypeToString(def->mirrorFormat));
|
||||||
if (def->mirroring)
|
if (def->mirroring)
|
||||||
virBufferAddLit(buf, " ready='yes'");
|
virBufferAddLit(buf, " ready='yes'");
|
||||||
virBufferAddLit(buf, "/>\n");
|
virBufferAddLit(buf, "/>\n");
|
||||||
@ -14850,15 +14858,8 @@ int virDomainDiskDefForeachPath(virDomainDiskDefPtr disk,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (disk->driverType) {
|
if (disk->format > 0) {
|
||||||
const char *formatStr = disk->driverType;
|
format = disk->format;
|
||||||
|
|
||||||
if ((format = virStorageFileFormatTypeFromString(formatStr)) <= 0) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("unknown disk format '%s' for %s"),
|
|
||||||
disk->driverType, disk->src);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (allowProbing) {
|
if (allowProbing) {
|
||||||
format = VIR_STORAGE_FILE_AUTO;
|
format = VIR_STORAGE_FILE_AUTO;
|
||||||
|
@ -567,10 +567,10 @@ struct _virDomainDiskDef {
|
|||||||
} secret;
|
} secret;
|
||||||
} auth;
|
} auth;
|
||||||
char *driverName;
|
char *driverName;
|
||||||
char *driverType;
|
int format; /* enum virStorageFileFormat */
|
||||||
|
|
||||||
char *mirror;
|
char *mirror;
|
||||||
char *mirrorFormat;
|
int mirrorFormat; /* enum virStorageFileFormat */
|
||||||
bool mirroring;
|
bool mirroring;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
#include "capabilities.h"
|
#include "capabilities.h"
|
||||||
#include "libxl_driver.h"
|
#include "libxl_driver.h"
|
||||||
#include "libxl_conf.h"
|
#include "libxl_conf.h"
|
||||||
|
#include "storage_file.h"
|
||||||
|
|
||||||
|
|
||||||
#define VIR_FROM_THIS VIR_FROM_LIBXL
|
#define VIR_FROM_THIS VIR_FROM_LIBXL
|
||||||
@ -505,25 +506,30 @@ libxlMakeDisk(virDomainDefPtr def, virDomainDiskDefPtr l_disk,
|
|||||||
if (l_disk->driverName) {
|
if (l_disk->driverName) {
|
||||||
if (STREQ(l_disk->driverName, "tap") ||
|
if (STREQ(l_disk->driverName, "tap") ||
|
||||||
STREQ(l_disk->driverName, "tap2")) {
|
STREQ(l_disk->driverName, "tap2")) {
|
||||||
if (l_disk->driverType) {
|
switch (l_disk->format) {
|
||||||
if (STREQ(l_disk->driverType, "qcow")) {
|
case VIR_STORAGE_FILE_QCOW:
|
||||||
x_disk->format = DISK_FORMAT_QCOW;
|
x_disk->format = DISK_FORMAT_QCOW;
|
||||||
x_disk->backend = DISK_BACKEND_QDISK;
|
x_disk->backend = DISK_BACKEND_QDISK;
|
||||||
} else if (STREQ(l_disk->driverType, "qcow2")) {
|
break;
|
||||||
|
case VIR_STORAGE_FILE_QCOW2:
|
||||||
x_disk->format = DISK_FORMAT_QCOW2;
|
x_disk->format = DISK_FORMAT_QCOW2;
|
||||||
x_disk->backend = DISK_BACKEND_QDISK;
|
x_disk->backend = DISK_BACKEND_QDISK;
|
||||||
} else if (STREQ(l_disk->driverType, "vhd")) {
|
break;
|
||||||
|
case VIR_STORAGE_FILE_VHD:
|
||||||
x_disk->format = DISK_FORMAT_VHD;
|
x_disk->format = DISK_FORMAT_VHD;
|
||||||
x_disk->backend = DISK_BACKEND_TAP;
|
x_disk->backend = DISK_BACKEND_TAP;
|
||||||
} else if (STREQ(l_disk->driverType, "aio") ||
|
break;
|
||||||
STREQ(l_disk->driverType, "raw")) {
|
case VIR_STORAGE_FILE_NONE:
|
||||||
x_disk->format = DISK_FORMAT_RAW;
|
|
||||||
x_disk->backend = DISK_BACKEND_TAP;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* No subtype specified, default to raw/tap */
|
/* No subtype specified, default to raw/tap */
|
||||||
|
case VIR_STORAGE_FILE_RAW:
|
||||||
x_disk->format = DISK_FORMAT_RAW;
|
x_disk->format = DISK_FORMAT_RAW;
|
||||||
x_disk->backend = DISK_BACKEND_TAP;
|
x_disk->backend = DISK_BACKEND_TAP;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("libxenlight does not support disk driver %s"),
|
||||||
|
virStorageFileFormatTypeToString(l_disk->format));
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
} else if (STREQ(l_disk->driverName, "file")) {
|
} else if (STREQ(l_disk->driverName, "file")) {
|
||||||
x_disk->format = DISK_FORMAT_RAW;
|
x_disk->format = DISK_FORMAT_RAW;
|
||||||
|
@ -3202,11 +3202,7 @@ libxlDomainUpdateDeviceConfig(virDomainDefPtr vmdef, virDomainDeviceDefPtr dev)
|
|||||||
orig->driverName = disk->driverName;
|
orig->driverName = disk->driverName;
|
||||||
disk->driverName = NULL;
|
disk->driverName = NULL;
|
||||||
}
|
}
|
||||||
if (disk->driverType) {
|
orig->format = disk->format;
|
||||||
VIR_FREE(orig->driverType);
|
|
||||||
orig->driverType = disk->driverType;
|
|
||||||
disk->driverType = NULL;
|
|
||||||
}
|
|
||||||
disk->src = NULL;
|
disk->src = NULL;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -43,6 +43,7 @@
|
|||||||
#include "virnetdevtap.h"
|
#include "virnetdevtap.h"
|
||||||
#include "base64.h"
|
#include "base64.h"
|
||||||
#include "device_conf.h"
|
#include "device_conf.h"
|
||||||
|
#include "storage_file.h"
|
||||||
|
|
||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@ -2142,11 +2143,10 @@ qemuBuildDriveStr(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
disk->tray_status == VIR_DOMAIN_DISK_TRAY_OPEN)) {
|
disk->tray_status == VIR_DOMAIN_DISK_TRAY_OPEN)) {
|
||||||
if (disk->type == VIR_DOMAIN_DISK_TYPE_DIR) {
|
if (disk->type == VIR_DOMAIN_DISK_TYPE_DIR) {
|
||||||
/* QEMU only supports magic FAT format for now */
|
/* QEMU only supports magic FAT format for now */
|
||||||
if (disk->driverType &&
|
if (disk->format > 0 && disk->format != VIR_STORAGE_FILE_FAT) {
|
||||||
STRNEQ(disk->driverType, "fat")) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("unsupported disk driver type for '%s'"),
|
_("unsupported disk driver type for '%s'"),
|
||||||
disk->driverType);
|
virStorageFileFormatTypeToString(disk->format));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (!disk->readonly) {
|
if (!disk->readonly) {
|
||||||
@ -2243,10 +2243,11 @@ qemuBuildDriveStr(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
_("transient disks not supported yet"));
|
_("transient disks not supported yet"));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (disk->driverType && *disk->driverType != '\0' &&
|
if (disk->format > 0 &&
|
||||||
disk->type != VIR_DOMAIN_DISK_TYPE_DIR &&
|
disk->type != VIR_DOMAIN_DISK_TYPE_DIR &&
|
||||||
qemuCapsGet(caps, QEMU_CAPS_DRIVE_FORMAT))
|
qemuCapsGet(caps, QEMU_CAPS_DRIVE_FORMAT))
|
||||||
virBufferAsprintf(&opt, ",format=%s", disk->driverType);
|
virBufferAsprintf(&opt, ",format=%s",
|
||||||
|
virStorageFileFormatTypeToString(disk->format));
|
||||||
|
|
||||||
/* generate geometry command string */
|
/* generate geometry command string */
|
||||||
if (disk->geometry.cylinders > 0 &&
|
if (disk->geometry.cylinders > 0 &&
|
||||||
@ -5244,11 +5245,10 @@ qemuBuildCommandLine(virConnectPtr conn,
|
|||||||
|
|
||||||
if (disk->type == VIR_DOMAIN_DISK_TYPE_DIR) {
|
if (disk->type == VIR_DOMAIN_DISK_TYPE_DIR) {
|
||||||
/* QEMU only supports magic FAT format for now */
|
/* QEMU only supports magic FAT format for now */
|
||||||
if (disk->driverType &&
|
if (disk->format > 0 && disk->format != VIR_STORAGE_FILE_FAT) {
|
||||||
STRNEQ(disk->driverType, "fat")) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("unsupported disk driver type for '%s'"),
|
_("unsupported disk driver type for '%s'"),
|
||||||
disk->driverType);
|
virStorageFileFormatTypeToString(disk->format));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (!disk->readonly) {
|
if (!disk->readonly) {
|
||||||
@ -7055,7 +7055,7 @@ qemuParseCommandLineDisk(virCapsPtr caps,
|
|||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
def->driverType = values[i];
|
def->format = virStorageFileFormatTypeFromString(values[i]);
|
||||||
values[i] = NULL;
|
values[i] = NULL;
|
||||||
} else if (STREQ(keywords[i], "cache")) {
|
} else if (STREQ(keywords[i], "cache")) {
|
||||||
if (STREQ(values[i], "off") ||
|
if (STREQ(values[i], "off") ||
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#include "virfile.h"
|
#include "virfile.h"
|
||||||
#include "domain_event.h"
|
#include "domain_event.h"
|
||||||
#include "virtime.h"
|
#include "virtime.h"
|
||||||
|
#include "storage_file.h"
|
||||||
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@ -1410,7 +1411,7 @@ void qemuDomainObjCheckDiskTaint(struct qemud_driver *driver,
|
|||||||
virDomainDiskDefPtr disk,
|
virDomainDiskDefPtr disk,
|
||||||
int logFD)
|
int logFD)
|
||||||
{
|
{
|
||||||
if (!disk->driverType &&
|
if ((!disk->format || disk->format == VIR_STORAGE_FILE_AUTO) &&
|
||||||
driver->allowDiskFormatProbing)
|
driver->allowDiskFormatProbing)
|
||||||
qemuDomainObjTaint(driver, obj, VIR_DOMAIN_TAINT_DISK_PROBING, logFD);
|
qemuDomainObjTaint(driver, obj, VIR_DOMAIN_TAINT_DISK_PROBING, logFD);
|
||||||
|
|
||||||
@ -1662,8 +1663,8 @@ qemuDomainSnapshotForEachQcow2Raw(struct qemud_driver *driver,
|
|||||||
for (i = 0; i < ndisks; i++) {
|
for (i = 0; i < ndisks; i++) {
|
||||||
/* FIXME: we also need to handle LVM here */
|
/* FIXME: we also need to handle LVM here */
|
||||||
if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_DISK) {
|
if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_DISK) {
|
||||||
if (!def->disks[i]->driverType ||
|
if (def->disks[i]->format > 0 &&
|
||||||
STRNEQ(def->disks[i]->driverType, "qcow2")) {
|
def->disks[i]->format != VIR_STORAGE_FILE_QCOW2) {
|
||||||
if (try_all) {
|
if (try_all) {
|
||||||
/* Continue on even in the face of error, since other
|
/* Continue on even in the face of error, since other
|
||||||
* disks in this VM may have the same snapshot name.
|
* disks in this VM may have the same snapshot name.
|
||||||
|
@ -6335,11 +6335,8 @@ qemuDomainUpdateDeviceConfig(qemuCapsPtr caps,
|
|||||||
orig->driverName = disk->driverName;
|
orig->driverName = disk->driverName;
|
||||||
disk->driverName = NULL;
|
disk->driverName = NULL;
|
||||||
}
|
}
|
||||||
if (disk->driverType) {
|
if (disk->format)
|
||||||
VIR_FREE(orig->driverType);
|
orig->format = disk->format;
|
||||||
orig->driverType = disk->driverType;
|
|
||||||
disk->driverType = NULL;
|
|
||||||
}
|
|
||||||
disk->src = NULL;
|
disk->src = NULL;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -9302,13 +9299,8 @@ static int qemuDomainGetBlockInfo(virDomainPtr dom,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Probe for magic formats */
|
/* Probe for magic formats */
|
||||||
if (disk->driverType) {
|
if (disk->format) {
|
||||||
if ((format = virStorageFileFormatTypeFromString(disk->driverType)) <= 0) {
|
format = disk->format;
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("unknown disk format %s for %s"),
|
|
||||||
disk->driverType, disk->src);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (driver->allowDiskFormatProbing) {
|
if (driver->allowDiskFormatProbing) {
|
||||||
if ((format = virStorageFileProbeFormat(disk->src)) < 0)
|
if ((format = virStorageFileProbeFormat(disk->src)) < 0)
|
||||||
@ -10481,7 +10473,7 @@ qemuDomainSnapshotIsAllowed(virDomainObjPtr vm)
|
|||||||
|
|
||||||
if ((disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) ||
|
if ((disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) ||
|
||||||
(disk->device == VIR_DOMAIN_DISK_DEVICE_DISK &&
|
(disk->device == VIR_DOMAIN_DISK_DEVICE_DISK &&
|
||||||
STRNEQ_NULLABLE(disk->driverType, "qcow2"))) {
|
disk->format > 0 && disk->format != VIR_STORAGE_FILE_QCOW2)) {
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID,
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
||||||
_("Disk '%s' does not support snapshotting"),
|
_("Disk '%s' does not support snapshotting"),
|
||||||
disk->src);
|
disk->src);
|
||||||
@ -10675,13 +10667,14 @@ qemuDomainSnapshotDiskPrepare(virDomainObjPtr vm, virDomainSnapshotDefPtr def,
|
|||||||
disk->name);
|
disk->name);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (!vm->def->disks[i]->driverType ||
|
if (vm->def->disks[i]->format > 0 &&
|
||||||
STRNEQ(vm->def->disks[i]->driverType, "qcow2")) {
|
vm->def->disks[i]->format != VIR_STORAGE_FILE_QCOW2) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
_("internal snapshot for disk %s unsupported "
|
_("internal snapshot for disk %s unsupported "
|
||||||
"for storage type %s"),
|
"for storage type %s"),
|
||||||
disk->name,
|
disk->name,
|
||||||
NULLSTR(vm->def->disks[i]->driverType));
|
virStorageFileFormatTypeToString(
|
||||||
|
vm->def->disks[i]->format));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
found = true;
|
found = true;
|
||||||
@ -10768,13 +10761,12 @@ qemuDomainSnapshotCreateSingleDiskActive(struct qemud_driver *driver,
|
|||||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||||
char *device = NULL;
|
char *device = NULL;
|
||||||
char *source = NULL;
|
char *source = NULL;
|
||||||
char *driverType = NULL;
|
int format = VIR_STORAGE_FILE_NONE;
|
||||||
char *persistSource = NULL;
|
char *persistSource = NULL;
|
||||||
char *persistDriverType = NULL;
|
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
char *origsrc = NULL;
|
char *origsrc = NULL;
|
||||||
char *origdriver = NULL;
|
int origdriver;
|
||||||
bool need_unlink = false;
|
bool need_unlink = false;
|
||||||
|
|
||||||
if (snap->snapshot != VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) {
|
if (snap->snapshot != VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) {
|
||||||
@ -10783,14 +10775,19 @@ qemuDomainSnapshotCreateSingleDiskActive(struct qemud_driver *driver,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (snap->driverType) {
|
||||||
|
format = virStorageFileFormatTypeFromString(snap->driverType);
|
||||||
|
if (format <= 0) {
|
||||||
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
|
_("unknown driver type %s"), snap->driverType);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (virAsprintf(&device, "drive-%s", disk->info.alias) < 0 ||
|
if (virAsprintf(&device, "drive-%s", disk->info.alias) < 0 ||
|
||||||
!(source = strdup(snap->file)) ||
|
!(source = strdup(snap->file)) ||
|
||||||
(STRNEQ_NULLABLE(disk->driverType, snap->driverType) &&
|
|
||||||
!(driverType = strdup(snap->driverType))) ||
|
|
||||||
(persistDisk &&
|
(persistDisk &&
|
||||||
(!(persistSource = strdup(source)) ||
|
!(persistSource = strdup(source)))) {
|
||||||
(STRNEQ_NULLABLE(persistDisk->driverType, snap->driverType) &&
|
|
||||||
!(persistDriverType = strdup(snap->driverType)))))) {
|
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -10807,8 +10804,8 @@ qemuDomainSnapshotCreateSingleDiskActive(struct qemud_driver *driver,
|
|||||||
|
|
||||||
origsrc = disk->src;
|
origsrc = disk->src;
|
||||||
disk->src = source;
|
disk->src = source;
|
||||||
origdriver = disk->driverType;
|
origdriver = disk->format;
|
||||||
disk->driverType = (char *) "raw"; /* Don't want to probe backing files */
|
disk->format = VIR_STORAGE_FILE_RAW; /* Don't want to probe backing files */
|
||||||
|
|
||||||
if (virDomainLockDiskAttach(driver->lockManager, driver->uri,
|
if (virDomainLockDiskAttach(driver->lockManager, driver->uri,
|
||||||
vm, disk) < 0)
|
vm, disk) < 0)
|
||||||
@ -10829,8 +10826,7 @@ qemuDomainSnapshotCreateSingleDiskActive(struct qemud_driver *driver,
|
|||||||
|
|
||||||
disk->src = origsrc;
|
disk->src = origsrc;
|
||||||
origsrc = NULL;
|
origsrc = NULL;
|
||||||
disk->driverType = origdriver;
|
disk->format = origdriver;
|
||||||
origdriver = NULL;
|
|
||||||
|
|
||||||
/* create the actual snapshot */
|
/* create the actual snapshot */
|
||||||
ret = qemuMonitorDiskSnapshot(priv->mon, actions, device, source,
|
ret = qemuMonitorDiskSnapshot(priv->mon, actions, device, source,
|
||||||
@ -10844,34 +10840,24 @@ qemuDomainSnapshotCreateSingleDiskActive(struct qemud_driver *driver,
|
|||||||
VIR_FREE(disk->src);
|
VIR_FREE(disk->src);
|
||||||
disk->src = source;
|
disk->src = source;
|
||||||
source = NULL;
|
source = NULL;
|
||||||
if (driverType) {
|
disk->format = format;
|
||||||
VIR_FREE(disk->driverType);
|
|
||||||
disk->driverType = driverType;
|
|
||||||
driverType = NULL;
|
|
||||||
}
|
|
||||||
if (persistDisk) {
|
if (persistDisk) {
|
||||||
VIR_FREE(persistDisk->src);
|
VIR_FREE(persistDisk->src);
|
||||||
persistDisk->src = persistSource;
|
persistDisk->src = persistSource;
|
||||||
persistSource = NULL;
|
persistSource = NULL;
|
||||||
if (persistDriverType) {
|
persistDisk->format = format;
|
||||||
VIR_FREE(persistDisk->driverType);
|
|
||||||
persistDisk->driverType = persistDriverType;
|
|
||||||
persistDriverType = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (origsrc) {
|
if (origsrc) {
|
||||||
disk->src = origsrc;
|
disk->src = origsrc;
|
||||||
disk->driverType = origdriver;
|
disk->format = origdriver;
|
||||||
}
|
}
|
||||||
if (need_unlink && unlink(source))
|
if (need_unlink && unlink(source))
|
||||||
VIR_WARN("unable to unlink just-created %s", source);
|
VIR_WARN("unable to unlink just-created %s", source);
|
||||||
VIR_FREE(device);
|
VIR_FREE(device);
|
||||||
VIR_FREE(source);
|
VIR_FREE(source);
|
||||||
VIR_FREE(driverType);
|
|
||||||
VIR_FREE(persistSource);
|
VIR_FREE(persistSource);
|
||||||
VIR_FREE(persistDriverType);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -10888,17 +10874,12 @@ qemuDomainSnapshotUndoSingleDiskActive(struct qemud_driver *driver,
|
|||||||
bool need_unlink)
|
bool need_unlink)
|
||||||
{
|
{
|
||||||
char *source = NULL;
|
char *source = NULL;
|
||||||
char *driverType = NULL;
|
|
||||||
char *persistSource = NULL;
|
char *persistSource = NULL;
|
||||||
char *persistDriverType = NULL;
|
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
if (!(source = strdup(origdisk->src)) ||
|
if (!(source = strdup(origdisk->src)) ||
|
||||||
(origdisk->driverType &&
|
|
||||||
!(driverType = strdup(origdisk->driverType))) ||
|
|
||||||
(persistDisk &&
|
(persistDisk &&
|
||||||
(!(persistSource = strdup(source)) ||
|
!(persistSource = strdup(source)))) {
|
||||||
(driverType && !(persistDriverType = strdup(driverType)))))) {
|
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -10918,27 +10899,17 @@ qemuDomainSnapshotUndoSingleDiskActive(struct qemud_driver *driver,
|
|||||||
VIR_FREE(disk->src);
|
VIR_FREE(disk->src);
|
||||||
disk->src = source;
|
disk->src = source;
|
||||||
source = NULL;
|
source = NULL;
|
||||||
VIR_FREE(disk->driverType);
|
disk->format = origdisk->format;
|
||||||
if (driverType) {
|
|
||||||
disk->driverType = driverType;
|
|
||||||
driverType = NULL;
|
|
||||||
}
|
|
||||||
if (persistDisk) {
|
if (persistDisk) {
|
||||||
VIR_FREE(persistDisk->src);
|
VIR_FREE(persistDisk->src);
|
||||||
persistDisk->src = persistSource;
|
persistDisk->src = persistSource;
|
||||||
persistSource = NULL;
|
persistSource = NULL;
|
||||||
VIR_FREE(persistDisk->driverType);
|
persistDisk->format = origdisk->format;
|
||||||
if (persistDriverType) {
|
|
||||||
persistDisk->driverType = persistDriverType;
|
|
||||||
persistDriverType = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(source);
|
VIR_FREE(source);
|
||||||
VIR_FREE(driverType);
|
|
||||||
VIR_FREE(persistSource);
|
VIR_FREE(persistSource);
|
||||||
VIR_FREE(persistDriverType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The domain is expected to be locked and active. */
|
/* The domain is expected to be locked and active. */
|
||||||
|
@ -45,6 +45,7 @@
|
|||||||
#include "virnetdevbridge.h"
|
#include "virnetdevbridge.h"
|
||||||
#include "virnetdevtap.h"
|
#include "virnetdevtap.h"
|
||||||
#include "device_conf.h"
|
#include "device_conf.h"
|
||||||
|
#include "storage_file.h"
|
||||||
|
|
||||||
#define VIR_FROM_THIS VIR_FROM_QEMU
|
#define VIR_FROM_THIS VIR_FROM_QEMU
|
||||||
|
|
||||||
@ -107,10 +108,10 @@ int qemuDomainChangeEjectableMedia(struct qemud_driver *driver,
|
|||||||
if (disk->src) {
|
if (disk->src) {
|
||||||
const char *format = NULL;
|
const char *format = NULL;
|
||||||
if (disk->type != VIR_DOMAIN_DISK_TYPE_DIR) {
|
if (disk->type != VIR_DOMAIN_DISK_TYPE_DIR) {
|
||||||
if (disk->driverType)
|
if (disk->format > 0)
|
||||||
format = disk->driverType;
|
format = virStorageFileFormatTypeToString(disk->format);
|
||||||
else if (origdisk->driverType)
|
else if (origdisk->format > 0)
|
||||||
format = origdisk->driverType;
|
format = virStorageFileFormatTypeToString(origdisk->format);
|
||||||
}
|
}
|
||||||
ret = qemuMonitorChangeMedia(priv->mon,
|
ret = qemuMonitorChangeMedia(priv->mon,
|
||||||
driveAlias,
|
driveAlias,
|
||||||
|
@ -3846,7 +3846,8 @@ vboxAttachDrives(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
|
|||||||
VIR_DEBUG("disk(%d) src: %s", i, def->disks[i]->src);
|
VIR_DEBUG("disk(%d) src: %s", i, def->disks[i]->src);
|
||||||
VIR_DEBUG("disk(%d) dst: %s", i, def->disks[i]->dst);
|
VIR_DEBUG("disk(%d) dst: %s", i, def->disks[i]->dst);
|
||||||
VIR_DEBUG("disk(%d) driverName: %s", i, def->disks[i]->driverName);
|
VIR_DEBUG("disk(%d) driverName: %s", i, def->disks[i]->driverName);
|
||||||
VIR_DEBUG("disk(%d) driverType: %s", i, def->disks[i]->driverType);
|
VIR_DEBUG("disk(%d) driverType: %s", i,
|
||||||
|
virStorageFileFormatTypeToString(def->disks[i]->format));
|
||||||
VIR_DEBUG("disk(%d) cachemode: %d", i, def->disks[i]->cachemode);
|
VIR_DEBUG("disk(%d) cachemode: %d", i, def->disks[i]->cachemode);
|
||||||
VIR_DEBUG("disk(%d) readonly: %s", i, (def->disks[i]->readonly
|
VIR_DEBUG("disk(%d) readonly: %s", i, (def->disks[i]->readonly
|
||||||
? "True" : "False"));
|
? "True" : "False"));
|
||||||
@ -4125,7 +4126,8 @@ vboxAttachDrives(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
|
|||||||
VIR_DEBUG("disk(%d) src: %s", i, def->disks[i]->src);
|
VIR_DEBUG("disk(%d) src: %s", i, def->disks[i]->src);
|
||||||
VIR_DEBUG("disk(%d) dst: %s", i, def->disks[i]->dst);
|
VIR_DEBUG("disk(%d) dst: %s", i, def->disks[i]->dst);
|
||||||
VIR_DEBUG("disk(%d) driverName: %s", i, def->disks[i]->driverName);
|
VIR_DEBUG("disk(%d) driverName: %s", i, def->disks[i]->driverName);
|
||||||
VIR_DEBUG("disk(%d) driverType: %s", i, def->disks[i]->driverType);
|
VIR_DEBUG("disk(%d) driverType: %s", i,
|
||||||
|
virStorageFileFormatTypeToString(def->disks[i]->format));
|
||||||
VIR_DEBUG("disk(%d) cachemode: %d", i, def->disks[i]->cachemode);
|
VIR_DEBUG("disk(%d) cachemode: %d", i, def->disks[i]->cachemode);
|
||||||
VIR_DEBUG("disk(%d) readonly: %s", i, (def->disks[i]->readonly
|
VIR_DEBUG("disk(%d) readonly: %s", i, (def->disks[i]->readonly
|
||||||
? "True" : "False"));
|
? "True" : "False"));
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#include "count-one-bits.h"
|
#include "count-one-bits.h"
|
||||||
#include "xenxs_private.h"
|
#include "xenxs_private.h"
|
||||||
#include "xen_sxpr.h"
|
#include "xen_sxpr.h"
|
||||||
|
#include "storage_file.h"
|
||||||
|
|
||||||
/* Get a domain id from a S-expression string */
|
/* Get a domain id from a S-expression string */
|
||||||
int xenGetDomIdFromSxprString(const char *sexpr, int xendConfigVersion)
|
int xenGetDomIdFromSxprString(const char *sexpr, int xendConfigVersion)
|
||||||
@ -427,6 +428,8 @@ xenParseSxprDisks(virDomainDefPtr def,
|
|||||||
|
|
||||||
if (STREQ (disk->driverName, "tap") ||
|
if (STREQ (disk->driverName, "tap") ||
|
||||||
STREQ (disk->driverName, "tap2")) {
|
STREQ (disk->driverName, "tap2")) {
|
||||||
|
char *driverType = NULL;
|
||||||
|
|
||||||
offset = strchr(src, ':');
|
offset = strchr(src, ':');
|
||||||
if (!offset) {
|
if (!offset) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
@ -434,21 +437,19 @@ xenParseSxprDisks(virDomainDefPtr def,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC_N(disk->driverType, (offset-src)+1)< 0)
|
if (!(driverType = strndup(src, offset - src)))
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
if (virStrncpy(disk->driverType, src, offset-src,
|
if (STREQ(driverType, "aio"))
|
||||||
(offset-src)+1) == NULL) {
|
disk->format = VIR_STORAGE_FILE_RAW;
|
||||||
|
else
|
||||||
|
disk->format =
|
||||||
|
virStorageFileFormatTypeFromString(driverType);
|
||||||
|
VIR_FREE(driverType);
|
||||||
|
if (disk->format <= 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Driver type %s too big for destination"),
|
_("Unknown driver type %s"), src);
|
||||||
src);
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (STREQ(disk->driverType, "aio")) {
|
|
||||||
/* In-place conversion to "raw" */
|
|
||||||
disk->driverType[0] = 'r';
|
|
||||||
disk->driverType[1] = 'a';
|
|
||||||
disk->driverType[2] = 'w';
|
|
||||||
}
|
|
||||||
|
|
||||||
src = offset + 1;
|
src = offset + 1;
|
||||||
/* Its possible to use blktap driver for block devs
|
/* Its possible to use blktap driver for block devs
|
||||||
@ -1837,9 +1838,12 @@ xenFormatSxprDisk(virDomainDiskDefPtr def,
|
|||||||
if (def->driverName) {
|
if (def->driverName) {
|
||||||
if (STREQ(def->driverName, "tap") ||
|
if (STREQ(def->driverName, "tap") ||
|
||||||
STREQ(def->driverName, "tap2")) {
|
STREQ(def->driverName, "tap2")) {
|
||||||
const char *type = def->driverType ? def->driverType : "aio";
|
const char *type;
|
||||||
if (STREQ(type, "raw"))
|
|
||||||
|
if (!def->format || def->format == VIR_STORAGE_FILE_RAW)
|
||||||
type = "aio";
|
type = "aio";
|
||||||
|
else
|
||||||
|
type = virStorageFileFormatTypeToString(def->format);
|
||||||
virBufferEscapeSexpr(buf, "(uname '%s:", def->driverName);
|
virBufferEscapeSexpr(buf, "(uname '%s:", def->driverName);
|
||||||
virBufferEscapeSexpr(buf, "%s:", type);
|
virBufferEscapeSexpr(buf, "%s:", type);
|
||||||
virBufferEscapeSexpr(buf, "%s')", def->src);
|
virBufferEscapeSexpr(buf, "%s')", def->src);
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
#include "xen_xm.h"
|
#include "xen_xm.h"
|
||||||
#include "xen_sxpr.h"
|
#include "xen_sxpr.h"
|
||||||
#include "domain_conf.h"
|
#include "domain_conf.h"
|
||||||
|
#include "storage_file.h"
|
||||||
|
|
||||||
/* Convenience method to grab a long int from the config file object */
|
/* Convenience method to grab a long int from the config file object */
|
||||||
static int xenXMConfigGetBool(virConfPtr conf,
|
static int xenXMConfigGetBool(virConfPtr conf,
|
||||||
@ -554,24 +555,25 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
|
|||||||
/* And the sub-type for tap:XXX: type */
|
/* And the sub-type for tap:XXX: type */
|
||||||
if (disk->driverName &&
|
if (disk->driverName &&
|
||||||
STREQ(disk->driverName, "tap")) {
|
STREQ(disk->driverName, "tap")) {
|
||||||
|
char *driverType;
|
||||||
|
|
||||||
if (!(tmp = strchr(disk->src, ':')))
|
if (!(tmp = strchr(disk->src, ':')))
|
||||||
goto skipdisk;
|
goto skipdisk;
|
||||||
if (VIR_ALLOC_N(disk->driverType, (tmp - disk->src) + 1) < 0)
|
|
||||||
|
if (!(driverType = strndup(disk->src, tmp - disk->src)))
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
if (virStrncpy(disk->driverType, disk->src,
|
if (STREQ(driverType, "aio"))
|
||||||
(tmp - disk->src),
|
disk->format = VIR_STORAGE_FILE_RAW;
|
||||||
(tmp - disk->src) + 1) == NULL) {
|
else
|
||||||
|
disk->format =
|
||||||
|
virStorageFileFormatTypeFromString(driverType);
|
||||||
|
VIR_FREE(driverType);
|
||||||
|
if (disk->format <= 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Driver type %s too big for destination"),
|
_("Unknown driver type %s"),
|
||||||
disk->src);
|
disk->src);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (STREQ(disk->driverType, "aio")) {
|
|
||||||
/* In-place conversion to "raw" */
|
|
||||||
disk->driverType[0] = 'r';
|
|
||||||
disk->driverType[1] = 'a';
|
|
||||||
disk->driverType[2] = 'w';
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Strip the prefix we found off the source file name */
|
/* Strip the prefix we found off the source file name */
|
||||||
memmove(disk->src, disk->src+(tmp-disk->src)+1,
|
memmove(disk->src, disk->src+(tmp-disk->src)+1,
|
||||||
@ -1208,10 +1210,13 @@ static int xenFormatXMDisk(virConfValuePtr list,
|
|||||||
virConfValuePtr val, tmp;
|
virConfValuePtr val, tmp;
|
||||||
|
|
||||||
if(disk->src) {
|
if(disk->src) {
|
||||||
if (disk->driverName) {
|
if (disk->format) {
|
||||||
const char *type = disk->driverType ? disk->driverType : "aio";
|
const char *type;
|
||||||
if (STREQ(type, "raw"))
|
|
||||||
|
if (disk->format == VIR_STORAGE_FILE_RAW)
|
||||||
type = "aio";
|
type = "aio";
|
||||||
|
else
|
||||||
|
type = virStorageFileFormatTypeToString(disk->format);
|
||||||
virBufferAsprintf(&buf, "%s:", disk->driverName);
|
virBufferAsprintf(&buf, "%s:", disk->driverName);
|
||||||
if (STREQ(disk->driverName, "tap"))
|
if (STREQ(disk->driverName, "tap"))
|
||||||
virBufferAsprintf(&buf, "%s:", type);
|
virBufferAsprintf(&buf, "%s:", type);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user