storage: use enum for snapshot driver type
This is the last use of raw strings for disk formats throughout the src/conf directory. * src/conf/snapshot_conf.h (_virDomainSnapshotDiskDef): Store enum rather than string for disk type. * src/conf/snapshot_conf.c (virDomainSnapshotDiskDefClear) (virDomainSnapshotDiskDefParseXML, virDomainSnapshotDefFormat): Adjust users. * src/qemu/qemu_driver.c (qemuDomainSnapshotDiskPrepare) (qemuDomainSnapshotCreateSingleDiskActive): Likewise.
This commit is contained in:
parent
e5e8d5d082
commit
1246640b3d
@ -82,7 +82,6 @@ virDomainSnapshotDiskDefClear(virDomainSnapshotDiskDefPtr disk)
|
|||||||
{
|
{
|
||||||
VIR_FREE(disk->name);
|
VIR_FREE(disk->name);
|
||||||
VIR_FREE(disk->file);
|
VIR_FREE(disk->file);
|
||||||
VIR_FREE(disk->driverType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void virDomainSnapshotDefFree(virDomainSnapshotDefPtr def)
|
void virDomainSnapshotDefFree(virDomainSnapshotDefPtr def)
|
||||||
@ -134,15 +133,24 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node,
|
|||||||
if (!def->file &&
|
if (!def->file &&
|
||||||
xmlStrEqual(cur->name, BAD_CAST "source")) {
|
xmlStrEqual(cur->name, BAD_CAST "source")) {
|
||||||
def->file = virXMLPropString(cur, "file");
|
def->file = virXMLPropString(cur, "file");
|
||||||
} else if (!def->driverType &&
|
} else if (!def->format &&
|
||||||
xmlStrEqual(cur->name, BAD_CAST "driver")) {
|
xmlStrEqual(cur->name, BAD_CAST "driver")) {
|
||||||
def->driverType = virXMLPropString(cur, "type");
|
char *driver = virXMLPropString(cur, "type");
|
||||||
|
def->format = virStorageFileFormatTypeFromString(driver);
|
||||||
|
if (def->format <= 0) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("unknown disk snapshot driver '%s'"),
|
||||||
|
driver);
|
||||||
|
VIR_FREE(driver);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
VIR_FREE(driver);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cur = cur->next;
|
cur = cur->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!def->snapshot && (def->file || def->driverType))
|
if (!def->snapshot && (def->file || def->format))
|
||||||
def->snapshot = VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL;
|
def->snapshot = VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
@ -536,11 +544,12 @@ char *virDomainSnapshotDefFormat(const char *domain_uuid,
|
|||||||
if (disk->snapshot)
|
if (disk->snapshot)
|
||||||
virBufferAsprintf(&buf, " snapshot='%s'",
|
virBufferAsprintf(&buf, " snapshot='%s'",
|
||||||
virDomainSnapshotLocationTypeToString(disk->snapshot));
|
virDomainSnapshotLocationTypeToString(disk->snapshot));
|
||||||
if (disk->file || disk->driverType) {
|
if (disk->file || disk->format > 0) {
|
||||||
virBufferAddLit(&buf, ">\n");
|
virBufferAddLit(&buf, ">\n");
|
||||||
if (disk->driverType)
|
if (disk->format > 0)
|
||||||
virBufferEscapeString(&buf, " <driver type='%s'/>\n",
|
virBufferEscapeString(&buf, " <driver type='%s'/>\n",
|
||||||
disk->driverType);
|
virStorageFileFormatTypeToString(
|
||||||
|
disk->format));
|
||||||
if (disk->file)
|
if (disk->file)
|
||||||
virBufferEscapeString(&buf, " <source file='%s'/>\n",
|
virBufferEscapeString(&buf, " <source file='%s'/>\n",
|
||||||
disk->file);
|
disk->file);
|
||||||
|
@ -52,7 +52,7 @@ struct _virDomainSnapshotDiskDef {
|
|||||||
int index; /* index within snapshot->dom->disks that matches name */
|
int index; /* index within snapshot->dom->disks that matches name */
|
||||||
int snapshot; /* enum virDomainSnapshotLocation */
|
int snapshot; /* enum virDomainSnapshotLocation */
|
||||||
char *file; /* new source file when snapshot is external */
|
char *file; /* new source file when snapshot is external */
|
||||||
char *driverType; /* file format type of new file */
|
int format; /* enum virStorageFileFormat */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Stores the complete snapshot metadata */
|
/* Stores the complete snapshot metadata */
|
||||||
|
@ -10681,17 +10681,15 @@ qemuDomainSnapshotDiskPrepare(virDomainObjPtr vm, virDomainSnapshotDefPtr def,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL:
|
case VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL:
|
||||||
if (!disk->driverType) {
|
if (!disk->format) {
|
||||||
if (!(disk->driverType = strdup("qcow2"))) {
|
disk->format = VIR_STORAGE_FILE_QCOW2;
|
||||||
virReportOOMError();
|
} else if (disk->format != VIR_STORAGE_FILE_QCOW2 &&
|
||||||
goto cleanup;
|
disk->format != VIR_STORAGE_FILE_QED) {
|
||||||
}
|
|
||||||
} else if (STRNEQ(disk->driverType, "qcow2") &&
|
|
||||||
STRNEQ(disk->driverType, "qed")) {
|
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
_("external snapshot format for disk %s "
|
_("external snapshot format for disk %s "
|
||||||
"is unsupported: %s"),
|
"is unsupported: %s"),
|
||||||
disk->name, disk->driverType);
|
disk->name,
|
||||||
|
virStorageFileFormatTypeToString(disk->format));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (stat(disk->file, &st) < 0) {
|
if (stat(disk->file, &st) < 0) {
|
||||||
@ -10761,7 +10759,8 @@ 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;
|
||||||
int format = VIR_STORAGE_FILE_NONE;
|
int format = snap->format;
|
||||||
|
const char *formatStr = NULL;
|
||||||
char *persistSource = NULL;
|
char *persistSource = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
@ -10775,15 +10774,6 @@ 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)) ||
|
||||||
(persistDisk &&
|
(persistDisk &&
|
||||||
@ -10829,8 +10819,10 @@ qemuDomainSnapshotCreateSingleDiskActive(struct qemud_driver *driver,
|
|||||||
disk->format = origdriver;
|
disk->format = origdriver;
|
||||||
|
|
||||||
/* create the actual snapshot */
|
/* create the actual snapshot */
|
||||||
|
if (snap->format)
|
||||||
|
formatStr = virStorageFileFormatTypeToString(snap->format);
|
||||||
ret = qemuMonitorDiskSnapshot(priv->mon, actions, device, source,
|
ret = qemuMonitorDiskSnapshot(priv->mon, actions, device, source,
|
||||||
snap->driverType, reuse);
|
formatStr, reuse);
|
||||||
virDomainAuditDisk(vm, disk->src, source, "snapshot", ret >= 0);
|
virDomainAuditDisk(vm, disk->src, source, "snapshot", ret >= 0);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user