This patch adds configuration support for the cpu device.
Signed-off-by: Zhu Guihua <zhugh.fnst(a)cn.fujitsu.com>
---
src/conf/domain_conf.c | 34 +++++++++++++++++++++++++++++++++-
src/conf/domain_conf.h | 16 ++++++++++++++++
src/qemu/qemu_driver.c | 6 ++++++
src/qemu/qemu_hotplug.c | 1 +
4 files changed, 56 insertions(+), 1 deletion(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 10dbabd..0f4baaf 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -236,7 +236,8 @@ VIR_ENUM_IMPL(virDomainDevice, VIR_DOMAIN_DEVICE_LAST,
"rng",
"shmem",
"tpm",
- "panic")
+ "panic",
+ "cpu")
VIR_ENUM_IMPL(virDomainDeviceAddress, VIR_DOMAIN_DEVICE_ADDRESS_TYPE_LAST,
"none",
@@ -1981,6 +1982,7 @@ void virDomainDeviceDefFree(virDomainDeviceDefPtr def)
case VIR_DOMAIN_DEVICE_PANIC:
virDomainPanicDefFree(def->data.panic);
break;
+ case VIR_DOMAIN_DEVICE_CPU:
case VIR_DOMAIN_DEVICE_LAST:
case VIR_DOMAIN_DEVICE_NONE:
break;
@@ -2687,6 +2689,8 @@ virDomainDeviceGetInfo(virDomainDeviceDefPtr device)
return &device->data.tpm->info;
case VIR_DOMAIN_DEVICE_PANIC:
return &device->data.panic->info;
+ case VIR_DOMAIN_DEVICE_CPU:
+ return &device->data.cpu->info;
/* The following devices do not contain virDomainDeviceInfo */
case VIR_DOMAIN_DEVICE_LEASE:
@@ -2917,6 +2921,12 @@ virDomainDeviceInfoIterateInternal(virDomainDefPtr def,
if (cb(def, &device, &def->panic->info, opaque) < 0)
return -1;
}
+ device.type = VIR_DOMAIN_DEVICE_CPU;
+ for (i = 0; i < def->ncpus; i++) {
+ device.data.cpu = def->cpus[i];
+ if (cb(def, &device, &def->cpus[i]->info, opaque) < 0)
+ return -1;
+ }
/* Coverity is not very happy with this - all dead_error_condition */
#if !STATIC_ANALYSIS
@@ -2950,6 +2960,7 @@ virDomainDeviceInfoIterateInternal(virDomainDefPtr def,
case VIR_DOMAIN_DEVICE_PANIC:
case VIR_DOMAIN_DEVICE_LAST:
case VIR_DOMAIN_DEVICE_RNG:
+ case VIR_DOMAIN_DEVICE_CPU:
break;
}
#endif
@@ -11175,6 +11186,7 @@ virDomainDeviceDefParse(const char *xmlStr,
if (!(dev->data.panic = virDomainPanicDefParseXML(node)))
goto error;
break;
+ case VIR_DOMAIN_DEVICE_CPU:
case VIR_DOMAIN_DEVICE_NONE:
case VIR_DOMAIN_DEVICE_LAST:
break;
@@ -15552,6 +15564,19 @@ virDomainPanicDefCheckABIStability(virDomainPanicDefPtr src,
return virDomainDeviceInfoCheckABIStability(&src->info, &dst->info);
}
+static bool
+virDomainCPUDefCheckABIStability(virDomainCPUDefPtr src,
+ virDomainCPUDefPtr dst)
+{
+ if (src->virCPU->model != dst->virCPU->model) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("Target CPU device model doesn't match source"));
+ return false;
+ }
+
+ return virDomainDeviceInfoCheckABIStability(&src->info, &dst->info);
+}
+
/* This compares two configurations and looks for any differences
* which will affect the guest ABI. This is primarily to allow
* validation of custom XML config passed in during migration
@@ -15985,6 +16010,11 @@ virDomainDefCheckABIStability(virDomainDefPtr src,
goto error;
}
+ for (i = 0; i < src->ncpus; i++) {
+ if (!virDomainCPUDefCheckABIStability(src->cpus[i], dst->cpus[i]))
+ goto error;
+ }
+
/* Coverity is not very happy with this - all dead_error_condition */
#if !STATIC_ANALYSIS
/* This switch statement is here to trigger compiler warning when adding
@@ -16016,6 +16046,7 @@ virDomainDefCheckABIStability(virDomainDefPtr src,
case VIR_DOMAIN_DEVICE_TPM:
case VIR_DOMAIN_DEVICE_PANIC:
case VIR_DOMAIN_DEVICE_SHMEM:
+ case VIR_DOMAIN_DEVICE_CPU:
break;
}
#endif
@@ -21448,6 +21479,7 @@ virDomainDeviceDefCopy(virDomainDeviceDefPtr src,
case VIR_DOMAIN_DEVICE_PANIC:
rc = virDomainPanicDefFormat(&buf, src->data.panic);
break;
+ case VIR_DOMAIN_DEVICE_CPU:
case VIR_DOMAIN_DEVICE_NONE:
case VIR_DOMAIN_DEVICE_SMARTCARD:
case VIR_DOMAIN_DEVICE_MEMBALLOON:
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 563c18b..b9d4e7c 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -144,6 +144,9 @@ typedef virDomainShmemDef *virDomainShmemDefPtr;
typedef struct _virDomainTPMDef virDomainTPMDef;
typedef virDomainTPMDef *virDomainTPMDefPtr;
+typedef struct _virDomainCPUDef virDomainCPUDef;
+typedef virDomainCPUDef *virDomainCPUDefPtr;
+
/* Flags for the 'type' field in virDomainDeviceDef */
typedef enum {
VIR_DOMAIN_DEVICE_NONE = 0,
@@ -168,6 +171,7 @@ typedef enum {
VIR_DOMAIN_DEVICE_SHMEM,
VIR_DOMAIN_DEVICE_TPM,
VIR_DOMAIN_DEVICE_PANIC,
+ VIR_DOMAIN_DEVICE_CPU,
VIR_DOMAIN_DEVICE_LAST
} virDomainDeviceType;
@@ -192,6 +196,7 @@ struct _virDomainDeviceDef {
virDomainRedirdevDefPtr redirdev;
virDomainSmartcardDefPtr smartcard;
virDomainChrDefPtr chr;
+ virDomainCPUDefPtr cpu;
virDomainMemballoonDefPtr memballoon;
virDomainNVRAMDefPtr nvram;
virDomainRNGDefPtr rng;
@@ -1158,6 +1163,13 @@ struct _virDomainChrDef {
virSecurityDeviceLabelDefPtr *seclabels;
};
+struct _virDomainCPUDef {
+ virCPUDefPtr virCPU;
+ int apic_id;
+
+ virDomainDeviceInfo info;
+};
+
typedef enum {
VIR_DOMAIN_SMARTCARD_TYPE_HOST,
VIR_DOMAIN_SMARTCARD_TYPE_HOST_CERTIFICATES,
@@ -2156,6 +2168,9 @@ struct _virDomainDef {
size_t nshmems;
virDomainShmemDefPtr *shmems;
+ size_t ncpus;
+ virDomainCPUDefPtr *cpus;
+
/* Only 1 */
virDomainWatchdogDefPtr watchdog;
virDomainMemballoonDefPtr memballoon;
@@ -2841,6 +2856,7 @@ VIR_ENUM_DECL(virDomainRNGModel)
VIR_ENUM_DECL(virDomainRNGBackend)
VIR_ENUM_DECL(virDomainTPMModel)
VIR_ENUM_DECL(virDomainTPMBackend)
+VIR_ENUM_DECL(virDomainCPU)
/* from libvirt.h */
VIR_ENUM_DECL(virDomainState)
VIR_ENUM_DECL(virDomainNostateReason)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index bc0a48c..31c7655 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7004,6 +7004,7 @@ qemuDomainAttachDeviceLive(virDomainObjPtr vm,
dev->data.chr = NULL;
break;
+ case VIR_DOMAIN_DEVICE_CPU:
case VIR_DOMAIN_DEVICE_NONE:
case VIR_DOMAIN_DEVICE_FS:
case VIR_DOMAIN_DEVICE_INPUT:
@@ -7079,6 +7080,7 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm,
case VIR_DOMAIN_DEVICE_CHR:
ret = qemuDomainDetachChrDevice(driver, vm, dev->data.chr);
break;
+ case VIR_DOMAIN_DEVICE_CPU:
case VIR_DOMAIN_DEVICE_FS:
case VIR_DOMAIN_DEVICE_INPUT:
case VIR_DOMAIN_DEVICE_SOUND:
@@ -7198,6 +7200,7 @@ qemuDomainUpdateDeviceLive(virConnectPtr conn,
case VIR_DOMAIN_DEVICE_CONTROLLER:
case VIR_DOMAIN_DEVICE_REDIRDEV:
case VIR_DOMAIN_DEVICE_CHR:
+ case VIR_DOMAIN_DEVICE_CPU:
case VIR_DOMAIN_DEVICE_NONE:
case VIR_DOMAIN_DEVICE_TPM:
case VIR_DOMAIN_DEVICE_PANIC:
@@ -7322,6 +7325,7 @@ qemuDomainAttachDeviceConfig(virQEMUCapsPtr qemuCaps,
dev->data.fs = NULL;
break;
+ case VIR_DOMAIN_DEVICE_CPU:
case VIR_DOMAIN_DEVICE_INPUT:
case VIR_DOMAIN_DEVICE_SOUND:
case VIR_DOMAIN_DEVICE_VIDEO:
@@ -7438,6 +7442,7 @@ qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef,
virDomainFSDefFree(fs);
break;
+ case VIR_DOMAIN_DEVICE_CPU:
case VIR_DOMAIN_DEVICE_INPUT:
case VIR_DOMAIN_DEVICE_SOUND:
case VIR_DOMAIN_DEVICE_VIDEO:
@@ -7553,6 +7558,7 @@ qemuDomainUpdateDeviceConfig(virQEMUCapsPtr qemuCaps,
case VIR_DOMAIN_DEVICE_CONTROLLER:
case VIR_DOMAIN_DEVICE_REDIRDEV:
case VIR_DOMAIN_DEVICE_CHR:
+ case VIR_DOMAIN_DEVICE_CPU:
case VIR_DOMAIN_DEVICE_NONE:
case VIR_DOMAIN_DEVICE_TPM:
case VIR_DOMAIN_DEVICE_PANIC:
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 1dbcc5d..cf8362c 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -2885,6 +2885,7 @@ qemuDomainRemoveDevice(virQEMUDriverPtr driver,
ret = qemuDomainRemoveChrDevice(driver, vm, dev->data.chr);
break;
+ case VIR_DOMAIN_DEVICE_CPU:
case VIR_DOMAIN_DEVICE_NONE:
case VIR_DOMAIN_DEVICE_LEASE:
case VIR_DOMAIN_DEVICE_FS:
--
1.9.3