From: Mikhail Feoktistov <mfeoktistov(a)virtuozzo.com>
Now we check disk parameters correctness in DomainPostParse.
Signed-off-by: Maxim Nestratov <mnestratov(a)virtuozzo.com>
---
src/vz/vz_driver.c | 6 +++++-
src/vz/vz_sdk.c | 24 ++----------------------
src/vz/vz_utils.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/vz/vz_utils.h | 3 +++
4 files changed, 60 insertions(+), 23 deletions(-)
diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index 5d48d7e..4f52bc7 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -175,8 +175,11 @@ static int
vzDomainDefPostParse(virDomainDefPtr def ATTRIBUTE_UNUSED,
virCapsPtr caps ATTRIBUTE_UNUSED,
unsigned int parseFlags ATTRIBUTE_UNUSED,
- void *opaque ATTRIBUTE_UNUSED)
+ void *opaque)
{
+ if (vzCheckUnsupportedDisks(def, opaque) < 0)
+ return -1;
+
return 0;
}
@@ -239,6 +242,7 @@ vzOpenDefault(virConnectPtr conn)
if (!(privconn->caps = vzBuildCapabilities()))
goto error;
+ vzDomainDefParserConfig.priv = &privconn->vzCaps;
if (!(privconn->xmlopt = virDomainXMLOptionNew(&vzDomainDefParserConfig,
NULL, NULL)))
goto error;
diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index f7d769b..bac8feb 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -3137,30 +3137,10 @@ static int prlsdkAddDisk(PRL_HANDLE sdkdom,
pret = PrlVmDev_SetConnected(sdkdisk, 1);
prlsdkCheckRetGoto(pret, cleanup);
- if (disk->src->type == VIR_STORAGE_TYPE_FILE) {
- if (disk->device == VIR_DOMAIN_DISK_DEVICE_DISK &&
- virDomainDiskGetFormat(disk) != VIR_STORAGE_FILE_PLOOP) {
-
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Invalid format of "
- "disk %s, vz driver
supports only "
- "images in ploop
format."), disk->src->path);
- goto cleanup;
- }
-
+ if (disk->src->type == VIR_STORAGE_TYPE_FILE)
emutype = PDT_USE_IMAGE_FILE;
- } else {
- if (disk->device == VIR_DOMAIN_DISK_DEVICE_DISK &&
- (virDomainDiskGetFormat(disk) != VIR_STORAGE_FILE_RAW &&
- virDomainDiskGetFormat(disk) != VIR_STORAGE_FILE_NONE &&
- virDomainDiskGetFormat(disk) != VIR_STORAGE_FILE_AUTO)) {
-
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Invalid format "
- "of disk %s, it should be
either not set, or set "
- "to raw or auto."),
disk->src->path);
- goto cleanup;
- }
+ else
emutype = PDT_USE_REAL_DEVICE;
- }
pret = PrlVmDev_SetEmulatedType(sdkdisk, emutype);
prlsdkCheckRetGoto(pret, cleanup);
diff --git a/src/vz/vz_utils.c b/src/vz/vz_utils.c
index d8a95ac..f949887 100644
--- a/src/vz/vz_utils.c
+++ b/src/vz/vz_utils.c
@@ -249,3 +249,53 @@ vzInitVersion(vzConnPtr privconn)
VIR_FREE(output);
return ret;
}
+
+int
+vzCheckUnsupportedDisks(virDomainDefPtr def, vzCapabilitiesPtr vzCaps)
+{
+ size_t i, j;
+ virDomainDiskDefPtr disk;
+ virStorageFileFormat diskFormat;
+ bool supported;
+
+ for (i = 0; i < def->ndisks; i++) {
+ disk = def->disks[i];
+ diskFormat = virDomainDiskGetFormat(disk);
+ supported = true;
+ if (disk->src->type == VIR_STORAGE_TYPE_FILE) {
+ if (disk->device == VIR_DOMAIN_DISK_DEVICE_DISK &&
+ diskFormat != VIR_STORAGE_FILE_NONE) {
+
+ if (IS_CT(def))
+ supported = vzCaps->ctDiskFormat == diskFormat;
+ else
+ supported = vzCaps->vmDiskFormat == diskFormat;
+ }
+ } else {
+ if (disk->device == VIR_DOMAIN_DISK_DEVICE_DISK) {
+ supported = diskFormat == VIR_STORAGE_FILE_RAW ||
+ diskFormat == VIR_STORAGE_FILE_NONE ||
+ diskFormat == VIR_STORAGE_FILE_AUTO;
+ }
+ }
+
+ if (!supported) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Unsupported format of disk %s"),
+ disk->src->path);
+ return -1;
+ }
+ for (j = 0; vzCaps->diskBuses[j] != VIR_DOMAIN_DISK_BUS_LAST; j++) {
+ if (disk->bus == vzCaps->diskBuses[j])
+ break;
+ }
+
+ if (vzCaps->diskBuses[j] == VIR_DOMAIN_DISK_BUS_LAST) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("Unsupported disk bus type %s"),
+ virDomainDiskBusTypeToString(disk->bus));
+ return -1;
+ }
+ }
+ return 0;
+}
diff --git a/src/vz/vz_utils.h b/src/vz/vz_utils.h
index e0b0105..851322f 100644
--- a/src/vz/vz_utils.h
+++ b/src/vz/vz_utils.h
@@ -110,6 +110,9 @@ vzNewDomain(vzConnPtr privconn,
const unsigned char *uuid);
int
vzInitVersion(vzConnPtr privconn);
+int
+vzCheckUnsupportedDisks(virDomainDefPtr def,
+ vzCapabilitiesPtr vzCaps);
# define PARALLELS_BLOCK_STATS_FOREACH(OP) \
OP(rd_req, VIR_DOMAIN_BLOCK_STATS_READ_REQ, "read_requests") \
--
2.4.3