mirror of https://gitee.com/openkylin/libvirt.git
bhyve: add UTC clock support
Bhyve as of r279225 (FreeBSD -CURRENT) or r284894 (FreeBSD 10-STABLE) supports using UTC time offset via the '-u' argument to bhyve(8). By default it's still using localtime. Make the bhyve driver use UTC clock if it's requested by specifying <clock offset='utc'> in domain XML and if the bhyve(8) binary supports the '-u' flag.
This commit is contained in:
parent
830344d6e7
commit
6cb9ef1bab
|
@ -141,3 +141,34 @@ virBhyveProbeGrubCaps(virBhyveGrubCapsFlags *caps)
|
|||
VIR_FREE(binary);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
virBhyveProbeCaps(unsigned int *caps)
|
||||
{
|
||||
char *binary, *help;
|
||||
virCommandPtr cmd = NULL;
|
||||
int ret = 0, exit;
|
||||
|
||||
binary = virFindFileInPath("bhyve");
|
||||
if (binary == NULL)
|
||||
goto out;
|
||||
if (!virFileIsExecutable(binary))
|
||||
goto out;
|
||||
|
||||
cmd = virCommandNew(binary);
|
||||
virCommandAddArg(cmd, "-h");
|
||||
virCommandSetErrorBuffer(cmd, &help);
|
||||
if (virCommandRun(cmd, &exit) < 0) {
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (strstr(help, "-u:") != NULL)
|
||||
*caps |= BHYVE_CAP_RTC_UTC;
|
||||
|
||||
out:
|
||||
VIR_FREE(help);
|
||||
virCommandFree(cmd);
|
||||
VIR_FREE(binary);
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,11 @@ typedef enum {
|
|||
BHYVE_GRUB_CAP_CONSDEV = 1,
|
||||
} virBhyveGrubCapsFlags;
|
||||
|
||||
typedef enum {
|
||||
BHYVE_CAP_RTC_UTC = 1,
|
||||
} virBhyveCapsFlags;
|
||||
|
||||
int virBhyveProbeGrubCaps(virBhyveGrubCapsFlags *caps);
|
||||
int virBhyveProbeCaps(unsigned int *caps);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -245,6 +245,27 @@ virBhyveProcessBuildBhyveCmd(virConnectPtr conn,
|
|||
if (def->features[VIR_DOMAIN_FEATURE_APIC] == VIR_TRISTATE_SWITCH_ON)
|
||||
virCommandAddArg(cmd, "-I"); /* Present ioapic to the guest */
|
||||
|
||||
switch (def->clock.offset) {
|
||||
case VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME:
|
||||
/* used by default in bhyve */
|
||||
break;
|
||||
case VIR_DOMAIN_CLOCK_OFFSET_UTC:
|
||||
if ((bhyveDriverGetCaps(conn) & BHYVE_CAP_RTC_UTC) != 0) {
|
||||
virCommandAddArg(cmd, "-u");
|
||||
} else {
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||
_("Installed bhyve binary does not support "
|
||||
"UTC clock"));
|
||||
goto error;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("unsupported clock offset '%s'"),
|
||||
virDomainClockOffsetTypeToString(def->clock.offset));
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Clarification about -H and -P flags from Peter Grehan:
|
||||
* -H and -P flags force the guest to exit when it executes IA32 HLT and PAUSE
|
||||
* instructions respectively.
|
||||
|
|
|
@ -1181,6 +1181,9 @@ bhyveStateInitialize(bool privileged,
|
|||
if (!(bhyve_driver->caps = virBhyveCapsBuild()))
|
||||
goto cleanup;
|
||||
|
||||
if (virBhyveProbeCaps(&bhyve_driver->bhyvecaps) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virBhyveProbeGrubCaps(&bhyve_driver->grubcaps) < 0)
|
||||
goto cleanup;
|
||||
|
||||
|
@ -1239,6 +1242,16 @@ bhyveStateInitialize(bool privileged,
|
|||
return -1;
|
||||
}
|
||||
|
||||
unsigned
|
||||
bhyveDriverGetCaps(virConnectPtr conn)
|
||||
{
|
||||
bhyveConnPtr driver = conn->privateData;
|
||||
|
||||
if (driver != NULL)
|
||||
return driver->bhyvecaps;
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned
|
||||
bhyveDriverGetGrubCaps(virConnectPtr conn)
|
||||
{
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
|
||||
int bhyveRegister(void);
|
||||
|
||||
unsigned bhyveDriverGetCaps(virConnectPtr conn);
|
||||
|
||||
unsigned bhyveDriverGetGrubCaps(virConnectPtr conn);
|
||||
|
||||
#endif /* __BHYVE_DRIVER_H__ */
|
||||
|
|
|
@ -46,6 +46,7 @@ struct _bhyveConn {
|
|||
|
||||
virCloseCallbacksPtr closeCallbacks;
|
||||
|
||||
unsigned bhyvecaps;
|
||||
unsigned grubcaps;
|
||||
};
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
/usr/sbin/bhyve -c 1 -m 214 -A -I -H -P -s 0:0,hostbridge \
|
||||
/usr/sbin/bhyve -c 1 -m 214 -A -I -u -H -P -s 0:0,hostbridge \
|
||||
-s 3:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \
|
||||
-s 2:0,ahci-hd,/tmp/freebsd.img bhyve
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
/usr/sbin/bhyve -c 1 -m 214 -H -P -s 0:0,hostbridge \
|
||||
/usr/sbin/bhyve -c 1 -m 214 -u -H -P -s 0:0,hostbridge \
|
||||
-s 3:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \
|
||||
-s 2:0,ahci-hd,/tmp/freebsd.img bhyve
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
/usr/sbin/bhyve -c 1 -m 214 -H -P -s 0:0,hostbridge \
|
||||
/usr/sbin/bhyve -c 1 -m 214 -u -H -P -s 0:0,hostbridge \
|
||||
-s 3:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \
|
||||
-s 2:0,ahci-hd,/tmp/freebsd.img bhyve
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/usr/sbin/bhyve -c 1 -m 214 -H -P -s 0:0,hostbridge \
|
||||
/usr/sbin/bhyve -c 1 -m 214 -u -H -P -s 0:0,hostbridge \
|
||||
-s 3:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \
|
||||
-s 2:0,ahci-hd,/tmp/freebsd.img \
|
||||
-s 1,lpc -l com1,/dev/nmdm0A bhyve
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
/usr/sbin/bhyve -c 1 -m 214 -H -P -s 0:0,hostbridge \
|
||||
/usr/sbin/bhyve -c 1 -m 214 -u -H -P -s 0:0,hostbridge \
|
||||
-s 3:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \
|
||||
-s 2:0,ahci-hd,/tmp/freebsd.img bhyve
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
/usr/sbin/bhyve -c 1 -m 214 -H -P -s 0:0,hostbridge \
|
||||
/usr/sbin/bhyve -c 1 -m 214 -u -H -P -s 0:0,hostbridge \
|
||||
-s 3:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \
|
||||
-s 2:0,ahci-cd,/tmp/cdrom.iso bhyve
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
/usr/sbin/bhyve -c 1 -m 214 -H -P -s 0:0,hostbridge \
|
||||
/usr/sbin/bhyve -c 1 -m 214 -u -H -P -s 0:0,hostbridge \
|
||||
-s 3:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \
|
||||
-s 2:0,ahci-cd,/tmp/cdrom.iso bhyve
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
/usr/sbin/bhyve -c 1 -m 214 -H -P -s 0:0,hostbridge \
|
||||
/usr/sbin/bhyve -c 1 -m 214 -u -H -P -s 0:0,hostbridge \
|
||||
-s 3:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \
|
||||
-s 2:0,virtio-blk,/tmp/freebsd.img bhyve
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/usr/sbin/bhyve -c 1 -m 214 -H -P -s 0:0,hostbridge \
|
||||
/usr/sbin/bhyve -c 1 -m 214 -u -H -P -s 0:0,hostbridge \
|
||||
-s 3:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \
|
||||
-s 2:0,ahci-hd,/tmp/freebsd1.img \
|
||||
-s 2:0,ahci-hd,/tmp/freebsd2.img \
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/usr/sbin/bhyve -c 1 -m 214 -H -P -s 0:0,hostbridge \
|
||||
/usr/sbin/bhyve -c 1 -m 214 -u -H -P -s 0:0,hostbridge \
|
||||
-s 3:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \
|
||||
-s 2:0,ahci-hd,/tmp/freebsd1.img \
|
||||
-s 2:0,ahci-hd,/tmp/freebsd2.img \
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
/usr/sbin/bhyve -c 1 -m 214 -H -P -s 0:0,hostbridge \
|
||||
/usr/sbin/bhyve -c 1 -m 214 -u -H -P -s 0:0,hostbridge \
|
||||
-s 3:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \
|
||||
-s 2:0,ahci-hd,/tmp/freebsd.img bhyve
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
/usr/sbin/bhyve -c 1 -m 214 -H -P -s 0:0,hostbridge \
|
||||
-s 3:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \
|
||||
-s 2:0,ahci-hd,/tmp/freebsd.img bhyve
|
|
@ -0,0 +1 @@
|
|||
/usr/sbin/bhyveload -m 214 -d /tmp/freebsd.img bhyve
|
|
@ -0,0 +1,23 @@
|
|||
<domain type='bhyve'>
|
||||
<name>bhyve</name>
|
||||
<uuid>df3be7e7-a104-11e3-aeb0-50e5492bd3dc</uuid>
|
||||
<memory>219136</memory>
|
||||
<vcpu>1</vcpu>
|
||||
<os>
|
||||
<type>hvm</type>
|
||||
</os>
|
||||
<clock offset='localtime'/>
|
||||
<devices>
|
||||
<disk type='file'>
|
||||
<driver name='file' type='raw'/>
|
||||
<source file='/tmp/freebsd.img'/>
|
||||
<target dev='hda' bus='sata'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
|
||||
</disk>
|
||||
<interface type='bridge'>
|
||||
<model type='virtio'/>
|
||||
<source bridge="virbr0"/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
|
||||
</interface>
|
||||
</devices>
|
||||
</domain>
|
|
@ -1,3 +1,3 @@
|
|||
/usr/sbin/bhyve -c 1 -m 214 -H -P -s 0:0,hostbridge \
|
||||
/usr/sbin/bhyve -c 1 -m 214 -u -H -P -s 0:0,hostbridge \
|
||||
-s 3:0,virtio-net,faketapdev,mac=52:54:00:22:ee:11 \
|
||||
-s 2:0,ahci-hd,/tmp/freebsd.img bhyve
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/usr/sbin/bhyve -c 1 -m 214 -H -P -s 0:0,hostbridge \
|
||||
/usr/sbin/bhyve -c 1 -m 214 -u -H -P -s 0:0,hostbridge \
|
||||
-s 3:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \
|
||||
-s 2:0,ahci-hd,/tmp/freebsd.img \
|
||||
-s 1,lpc -l com1,/dev/nmdm0A bhyve
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/usr/sbin/bhyve -c 1 -m 214 -H -P -s 0:0,hostbridge \
|
||||
/usr/sbin/bhyve -c 1 -m 214 -u -H -P -s 0:0,hostbridge \
|
||||
-s 3:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \
|
||||
-s 2:0,ahci-hd,/tmp/freebsd.img \
|
||||
-s 1,lpc -l com1,/dev/nmdm0A bhyve
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/usr/sbin/bhyve -c 1 -m 214 -H -P -s 0:0,hostbridge \
|
||||
/usr/sbin/bhyve -c 1 -m 214 -u -H -P -s 0:0,hostbridge \
|
||||
-s 3:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \
|
||||
-s 2:0,ahci-hd,/tmp/freebsd.img \
|
||||
-s 1,lpc -l com1,/dev/nmdm0A bhyve
|
||||
|
|
|
@ -118,6 +118,7 @@ mymain(void)
|
|||
} while (0)
|
||||
|
||||
driver.grubcaps = BHYVE_GRUB_CAP_CONSDEV;
|
||||
driver.bhyvecaps = BHYVE_CAP_RTC_UTC;
|
||||
|
||||
DO_TEST("base");
|
||||
DO_TEST("acpiapic");
|
||||
|
@ -133,6 +134,7 @@ mymain(void)
|
|||
DO_TEST("custom-loader");
|
||||
DO_TEST("disk-cdrom-grub");
|
||||
DO_TEST("serial-grub");
|
||||
DO_TEST("localtime");
|
||||
|
||||
driver.grubcaps = 0;
|
||||
|
||||
|
|
Loading…
Reference in New Issue