conf: Introduce 'absolute' clock offset

The 'absolute' clock offset type has a 'start' attribute which is an
unix epoch timestamp to which the hardware clock is always set at start
of the VM.

This is useful if some VM needs to be kept set to an arbitrary time for
e.g. testing or working around broken software.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa 2022-04-26 17:00:36 +02:00
parent 9cd2c5257a
commit d53e75aad0
8 changed files with 100 additions and 0 deletions

View File

@ -2170,6 +2170,11 @@ Windows, however, expects it to be in so called 'localtime'.
the RTC adjustments are lost at each reboot. :since:`Since 0.7.7` the RTC adjustments are lost at each reboot. :since:`Since 0.7.7`
:since:`Since 0.9.11` the ``basis`` attribute can be either 'utc' :since:`Since 0.9.11` the ``basis`` attribute can be either 'utc'
(default) or 'localtime'. (default) or 'localtime'.
``absolute``
The guest clock will be always set to the value of the ``start``
attribute at startup of the domain. The ``start`` attribute takes an
epoch timestamp.
:since:`Since 8.4.0`.
A ``clock`` may have zero or more ``timer`` sub-elements. :since:`Since A ``clock`` may have zero or more ``timer`` sub-elements. :since:`Since
0.8.0` 0.8.0`

View File

@ -1172,6 +1172,7 @@ VIR_ENUM_IMPL(virDomainClockOffset,
"localtime", "localtime",
"variable", "variable",
"timezone", "timezone",
"absolute",
); );
VIR_ENUM_IMPL(virDomainClockBasis, VIR_ENUM_IMPL(virDomainClockBasis,
@ -19459,6 +19460,15 @@ virDomainDefClockParse(virDomainDef *def,
return -1; return -1;
} }
break; break;
case VIR_DOMAIN_CLOCK_OFFSET_ABSOLUTE:
if (virXPathULongLong("number(./clock/@start)", ctxt,
&def->clock.data.starttime) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("missing 'start' attribute for clock with offset='absolute'"));
return -1;
}
break;
} }
if ((n = virXPathNodeSet("./clock/timer", ctxt, &nodes)) < 0) if ((n = virXPathNodeSet("./clock/timer", ctxt, &nodes)) < 0)
@ -26263,6 +26273,9 @@ virDomainClockDefFormat(virBuffer *buf,
case VIR_DOMAIN_CLOCK_OFFSET_TIMEZONE: case VIR_DOMAIN_CLOCK_OFFSET_TIMEZONE:
virBufferEscapeString(&clockAttr, " timezone='%s'", def->data.timezone); virBufferEscapeString(&clockAttr, " timezone='%s'", def->data.timezone);
break; break;
case VIR_DOMAIN_CLOCK_OFFSET_ABSOLUTE:
virBufferAsprintf(&clockAttr, " start='%llu'", def->data.starttime);
break;
} }
for (n = 0; n < def->ntimers; n++) { for (n = 0; n < def->ntimers; n++) {

View File

@ -2453,6 +2453,7 @@ typedef enum {
VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME = 1, VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME = 1,
VIR_DOMAIN_CLOCK_OFFSET_VARIABLE = 2, VIR_DOMAIN_CLOCK_OFFSET_VARIABLE = 2,
VIR_DOMAIN_CLOCK_OFFSET_TIMEZONE = 3, VIR_DOMAIN_CLOCK_OFFSET_TIMEZONE = 3,
VIR_DOMAIN_CLOCK_OFFSET_ABSOLUTE = 4,
VIR_DOMAIN_CLOCK_OFFSET_LAST VIR_DOMAIN_CLOCK_OFFSET_LAST
} virDomainClockOffsetType; } virDomainClockOffsetType;
@ -2487,6 +2488,9 @@ struct _virDomainClockDef {
/* Timezone name, when /* Timezone name, when
* offset == VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME */ * offset == VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME */
char *timezone; char *timezone;
/* absolute clock start time for VIR_DOMAIN_CLOCK_OFFSET_ABSOLUTE */
unsigned long long starttime;
} data; } data;
size_t ntimers; size_t ntimers;

View File

@ -1252,6 +1252,14 @@
</attribute> </attribute>
</optional> </optional>
</group> </group>
<group>
<attribute name="offset">
<value>absolute</value>
</attribute>
<attribute name="start">
<ref name="unsignedInt"/>
</attribute>
</group>
</choice> </choice>
<zeroOrMore> <zeroOrMore>
<ref name="timer"/> <ref name="timer"/>

View File

@ -391,6 +391,7 @@ libxlMakeDomBuildInfo(virDomainDef *def,
virDomainClockOffsetTypeToString(clock.offset)); virDomainClockOffsetTypeToString(clock.offset));
return -1; return -1;
case VIR_DOMAIN_CLOCK_OFFSET_ABSOLUTE:
case VIR_DOMAIN_CLOCK_OFFSET_LAST: case VIR_DOMAIN_CLOCK_OFFSET_LAST:
default: default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,

View File

@ -0,0 +1,30 @@
<domain type='qemu'>
<name>QEMUGuest1</name>
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
<memory unit='KiB'>219100</memory>
<currentMemory unit='KiB'>219100</currentMemory>
<vcpu placement='static'>1</vcpu>
<os>
<type arch='x86_64' machine='pc'>hvm</type>
<boot dev='hd'/>
</os>
<clock offset='absolute' start='1234'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu-system-x86_64</emulator>
<disk type='block' device='disk'>
<driver name='qemu' type='raw'/>
<source dev='/dev/HostVG/QEMUGuest1'/>
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<controller type='usb' index='0'/>
<controller type='ide' index='0'/>
<controller type='pci' index='0' model='pci-root'/>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<memballoon model='none'/>
</devices>
</domain>

View File

@ -0,0 +1,38 @@
<domain type='qemu'>
<name>QEMUGuest1</name>
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
<memory unit='KiB'>219100</memory>
<currentMemory unit='KiB'>219100</currentMemory>
<vcpu placement='static'>1</vcpu>
<os>
<type arch='x86_64' machine='pc'>hvm</type>
<boot dev='hd'/>
</os>
<cpu mode='custom' match='exact' check='none'>
<model fallback='forbid'>qemu64</model>
</cpu>
<clock offset='absolute' start='1234'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu-system-x86_64</emulator>
<disk type='block' device='disk'>
<driver name='qemu' type='raw'/>
<source dev='/dev/HostVG/QEMUGuest1'/>
<target dev='hda' bus='ide'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<controller type='usb' index='0' model='piix3-uhci'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
</controller>
<controller type='ide' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
</controller>
<controller type='pci' index='0' model='pci-root'/>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<audio id='1' type='none'/>
<memballoon model='none'/>
</devices>
</domain>

View File

@ -276,6 +276,7 @@ mymain(void)
DO_TEST_NOCAPS("clock-timer-hyperv-rtc"); DO_TEST_NOCAPS("clock-timer-hyperv-rtc");
DO_TEST_CAPS_ARCH_LATEST("clock-timer-armvtimer", "aarch64"); DO_TEST_CAPS_ARCH_LATEST("clock-timer-armvtimer", "aarch64");
DO_TEST_NOCAPS("clock-realtime"); DO_TEST_NOCAPS("clock-realtime");
DO_TEST_CAPS_LATEST("clock-absolute");
DO_TEST_NOCAPS("cpu-eoi-disabled"); DO_TEST_NOCAPS("cpu-eoi-disabled");
DO_TEST_NOCAPS("cpu-eoi-enabled"); DO_TEST_NOCAPS("cpu-eoi-enabled");