mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 07:59:00 +00:00
qemu: command: Add infrastructure for object specified disk sources
To allow richer definitions of disk sources add infrastructure that will allow to register functionst generating a JSON object based definition. This infrastructure will then convert the definition to the proper command line syntax and use it in cases where it's necessary. This will allow to keep legacy definitions for back-compat when possible and use the new definitions for the configurations requiring them.
This commit is contained in:
parent
74df83a9eb
commit
f444101729
@ -2207,6 +2207,7 @@ virQEMUBuildBufferEscapeComma;
|
|||||||
virQEMUBuildCommandLineJSON;
|
virQEMUBuildCommandLineJSON;
|
||||||
virQEMUBuildCommandLineJSONArrayBitmap;
|
virQEMUBuildCommandLineJSONArrayBitmap;
|
||||||
virQEMUBuildCommandLineJSONArrayNumbered;
|
virQEMUBuildCommandLineJSONArrayNumbered;
|
||||||
|
virQEMUBuildDriveCommandlineFromJSON;
|
||||||
virQEMUBuildLuksOpts;
|
virQEMUBuildLuksOpts;
|
||||||
virQEMUBuildObjectCommandlineFromJSON;
|
virQEMUBuildObjectCommandlineFromJSON;
|
||||||
|
|
||||||
|
@ -916,6 +916,34 @@ qemuBuildNetworkDriveStr(virStorageSourcePtr src,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
qemuGetDriveSourceProps(virStorageSourcePtr src,
|
||||||
|
virJSONValuePtr *props)
|
||||||
|
{
|
||||||
|
int actualType = virStorageSourceGetActualType(src);
|
||||||
|
virJSONValuePtr fileprops = NULL;
|
||||||
|
|
||||||
|
*props = NULL;
|
||||||
|
|
||||||
|
switch ((virStorageType) actualType) {
|
||||||
|
case VIR_STORAGE_TYPE_BLOCK:
|
||||||
|
case VIR_STORAGE_TYPE_FILE:
|
||||||
|
case VIR_STORAGE_TYPE_DIR:
|
||||||
|
case VIR_STORAGE_TYPE_VOLUME:
|
||||||
|
case VIR_STORAGE_TYPE_NONE:
|
||||||
|
case VIR_STORAGE_TYPE_LAST:
|
||||||
|
case VIR_STORAGE_TYPE_NETWORK:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fileprops &&
|
||||||
|
virJSONValueObjectCreate(props, "a:file", fileprops, NULL) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
qemuGetDriveSourceString(virStorageSourcePtr src,
|
qemuGetDriveSourceString(virStorageSourcePtr src,
|
||||||
qemuDomainSecretInfoPtr secinfo,
|
qemuDomainSecretInfoPtr secinfo,
|
||||||
@ -1101,14 +1129,19 @@ qemuBuildDriveSourceStr(virDomainDiskDefPtr disk,
|
|||||||
qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
|
qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
|
||||||
qemuDomainSecretInfoPtr secinfo = diskPriv->secinfo;
|
qemuDomainSecretInfoPtr secinfo = diskPriv->secinfo;
|
||||||
qemuDomainSecretInfoPtr encinfo = diskPriv->encinfo;
|
qemuDomainSecretInfoPtr encinfo = diskPriv->encinfo;
|
||||||
|
virJSONValuePtr srcprops = NULL;
|
||||||
char *source = NULL;
|
char *source = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (qemuGetDriveSourceString(disk->src, secinfo, &source) < 0)
|
if (qemuGetDriveSourceProps(disk->src, &srcprops) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (!srcprops &&
|
||||||
|
qemuGetDriveSourceString(disk->src, secinfo, &source) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
/* nothing to format if the drive is empty */
|
/* nothing to format if the drive is empty */
|
||||||
if (!source ||
|
if (!(source || srcprops) ||
|
||||||
((disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY ||
|
((disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY ||
|
||||||
disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM) &&
|
disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM) &&
|
||||||
disk->tray_status == VIR_DOMAIN_DISK_TRAY_OPEN)) {
|
disk->tray_status == VIR_DOMAIN_DISK_TRAY_OPEN)) {
|
||||||
@ -1125,31 +1158,38 @@ qemuBuildDriveSourceStr(virDomainDiskDefPtr disk,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
virBufferAddLit(buf, "file=");
|
if (source) {
|
||||||
|
virBufferAddLit(buf, "file=");
|
||||||
|
|
||||||
/* for now the DIR based storage is handled by the magic FAT format */
|
/* for now the DIR based storage is handled by the magic FAT format */
|
||||||
if (actualType == VIR_STORAGE_TYPE_DIR) {
|
if (actualType == VIR_STORAGE_TYPE_DIR) {
|
||||||
if (disk->src->format > 0 &&
|
if (disk->src->format > 0 &&
|
||||||
disk->src->format != VIR_STORAGE_FILE_FAT) {
|
disk->src->format != VIR_STORAGE_FILE_FAT) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("unsupported disk driver type for '%s'"),
|
_("unsupported disk driver type for '%s'"),
|
||||||
virStorageFileFormatTypeToString(disk->src->format));
|
virStorageFileFormatTypeToString(disk->src->format));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!disk->src->readonly) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
_("cannot create virtual FAT disks in read-write mode"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
virBufferAddLit(buf, "fat:");
|
||||||
|
|
||||||
|
if (disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY)
|
||||||
|
virBufferAddLit(buf, "floppy:");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!disk->src->readonly) {
|
virQEMUBuildBufferEscapeComma(buf, source);
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
} else {
|
||||||
_("cannot create virtual FAT disks in read-write mode"));
|
if (!(source = virQEMUBuildDriveCommandlineFromJSON(srcprops)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
virBufferAddLit(buf, "fat:");
|
virBufferAdd(buf, source, -1);
|
||||||
|
|
||||||
if (disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY)
|
|
||||||
virBufferAddLit(buf, "floppy:");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virQEMUBuildBufferEscapeComma(buf, source);
|
|
||||||
virBufferAddLit(buf, ",");
|
virBufferAddLit(buf, ",");
|
||||||
|
|
||||||
if (secinfo && secinfo->type == VIR_DOMAIN_SECRET_INFO_TYPE_AES) {
|
if (secinfo && secinfo->type == VIR_DOMAIN_SECRET_INFO_TYPE_AES) {
|
||||||
@ -1170,6 +1210,7 @@ qemuBuildDriveSourceStr(virDomainDiskDefPtr disk,
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(source);
|
VIR_FREE(source);
|
||||||
|
virJSONValueFree(srcprops);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,6 +264,27 @@ virQEMUBuildObjectCommandlineFromJSON(const char *type,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
char *
|
||||||
|
virQEMUBuildDriveCommandlineFromJSON(const virJSONValue *srcdef)
|
||||||
|
{
|
||||||
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||||
|
char *ret = NULL;
|
||||||
|
|
||||||
|
if (virQEMUBuildCommandLineJSON(srcdef, &buf,
|
||||||
|
virQEMUBuildCommandLineJSONArrayNumbered) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (virBufferCheckError(&buf) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
ret = virBufferContentAndReset(&buf);
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
virBufferFreeAndReset(&buf);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virQEMUBuildBufferEscapeComma:
|
* virQEMUBuildBufferEscapeComma:
|
||||||
* @buf: buffer to append the escaped string
|
* @buf: buffer to append the escaped string
|
||||||
|
@ -47,6 +47,8 @@ char *virQEMUBuildObjectCommandlineFromJSON(const char *type,
|
|||||||
const char *alias,
|
const char *alias,
|
||||||
virJSONValuePtr props);
|
virJSONValuePtr props);
|
||||||
|
|
||||||
|
char *virQEMUBuildDriveCommandlineFromJSON(const virJSONValue *src);
|
||||||
|
|
||||||
void virQEMUBuildBufferEscapeComma(virBufferPtr buf, const char *str);
|
void virQEMUBuildBufferEscapeComma(virBufferPtr buf, const char *str);
|
||||||
void virQEMUBuildLuksOpts(virBufferPtr buf,
|
void virQEMUBuildLuksOpts(virBufferPtr buf,
|
||||||
virStorageEncryptionInfoDefPtr enc,
|
virStorageEncryptionInfoDefPtr enc,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user