On Mon, Nov 27, 2023 at 04:55:21PM +0800, Zhenzhong Duan wrote:
After hard reboot, domid is increased by 1 as a new domain.
Hard reboot simulate TD-guest reboot by calling qemuProcessStop
and qemuProcessStart which will release and recreate domain
resource including domid.
This is risky.
We use 'domid' as a mechanism to *guarantee* certain paths
are unique when re-spawning QEMU, so re-using domid for
a new QEMU is liable to cause bugs.
The domain ID is not guest visible, so we don't need to
preserve it from that POV.
I think we should just document domid is going to change
for confidential guests when the reboot is faked.
Most mgmt apps focus on UUID for most of their work
anyway, with domain ID largely irrelevant beyond it
being presented in users in a few places.
Define origin_id to save domid and restore it when recreate
domain. For persistent domain also need to save domid in newDef.
Also add logic to keep same domid when libvirt restart.
Signed-off-by: Zhenzhong Duan <zhenzhong.duan(a)intel.com>
---
src/conf/domain_conf.c | 4 ++++
src/conf/domain_conf.h | 1 +
src/qemu/qemu_process.c | 11 +++++++++--
3 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 08e82c5380..8c33b335bd 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -4159,6 +4159,7 @@ void virDomainObjAssignDef(virDomainObj *domain,
else
virDomainDefFree(domain->newDef);
domain->newDef = g_steal_pointer(def);
+ domain->newDef->origin_id = domain->def->id;
return;
}
@@ -17874,6 +17875,9 @@ virDomainDefParseIDs(virDomainDef *def,
return -1;
}
+ /* Restore origin_id to support hard reboot */
+ def->origin_id = def->id;
+
/* Extract domain name */
if (!(def->name = virXPathString("string(./name[1])", ctxt))) {
virReportError(VIR_ERR_NO_NAME, NULL);
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 3b01850eb4..afd54a07eb 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2957,6 +2957,7 @@ struct _virDomainVirtioOptions {
struct _virDomainDef {
int virtType; /* enum virDomainVirtType */
int id;
+ int origin_id;
unsigned char uuid[VIR_UUID_BUFLEN];
unsigned char genid[VIR_UUID_BUFLEN];
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index a9bba19852..6ec649a261 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -5757,8 +5757,15 @@ qemuProcessInit(virQEMUDriver *driver,
goto cleanup;
}
} else {
- vm->def->id = qemuDriverAllocateID(driver);
- qemuDomainSetFakeReboot(vm, false);
+ if (vm->def->origin_id > 0 && priv->hardReboot)
+ vm->def->id = vm->def->origin_id;
+ else
+ vm->def->id = qemuDriverAllocateID(driver);
+ vm->def->origin_id = vm->def->id;
+ if (vm->newDef)
+ vm->newDef->origin_id = vm->def->id;
+
+ qemuDomainSetHardReboot(vm, false);
qemuDomainSetFakeReboot(vm, false);
virDomainObjSetState(vm, VIR_DOMAIN_PAUSED, VIR_DOMAIN_PAUSED_STARTING_UP);
--
2.34.1
With regards,
Daniel
--
|:
https://berrange.com -o-
https://www.flickr.com/photos/dberrange :|
|:
https://libvirt.org -o-
https://fstop138.berrange.com :|
|:
https://entangle-photo.org -o-
https://www.instagram.com/dberrange :|