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. --- src/bhyve/bhyve_capabilities.c | 31 ++++++++++++++++++++++ src/bhyve/bhyve_capabilities.h | 5 ++++ src/bhyve/bhyve_command.c | 21 +++++++++++++++ src/bhyve/bhyve_driver.c | 13 +++++++++ src/bhyve/bhyve_driver.h | 2 ++ src/bhyve/bhyve_utils.h | 1 + .../bhyvexml2argvdata/bhyvexml2argv-acpiapic.args | 2 +- tests/bhyvexml2argvdata/bhyvexml2argv-base.args | 2 +- .../bhyvexml2argv-bhyveload-explicitargs.args | 2 +- tests/bhyvexml2argvdata/bhyvexml2argv-console.args | 2 +- .../bhyvexml2argv-custom-loader.args | 2 +- .../bhyvexml2argv-disk-cdrom-grub.args | 2 +- .../bhyvexml2argv-disk-cdrom.args | 2 +- .../bhyvexml2argv-disk-virtio.args | 2 +- .../bhyvexml2argv-grub-bootorder.args | 2 +- .../bhyvexml2argv-grub-bootorder2.args | 2 +- .../bhyvexml2argv-grub-defaults.args | 2 +- .../bhyvexml2argvdata/bhyvexml2argv-localtime.args | 3 +++ .../bhyvexml2argv-localtime.ldargs | 1 + .../bhyvexml2argvdata/bhyvexml2argv-localtime.xml | 23 ++++++++++++++++ tests/bhyvexml2argvdata/bhyvexml2argv-macaddr.args | 2 +- .../bhyvexml2argv-serial-grub-nocons.args | 2 +- .../bhyvexml2argv-serial-grub.args | 2 +- tests/bhyvexml2argvdata/bhyvexml2argv-serial.args | 2 +- tests/bhyvexml2argvtest.c | 2 ++ 25 files changed, 117 insertions(+), 15 deletions(-) create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-localtime.args create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-localtime.ldargs create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-localtime.xml diff --git a/src/bhyve/bhyve_capabilities.c b/src/bhyve/bhyve_capabilities.c index 3a55879..9b21649 100644 --- a/src/bhyve/bhyve_capabilities.c +++ b/src/bhyve/bhyve_capabilities.c @@ -141,3 +141,34 @@ virBhyveProbeGrubCaps(virBhyveGrubCapsFlags *caps) VIR_FREE(binary); return ret; } + +int +virBhyveProbeCaps(virBhyveCapsFlags *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; +} diff --git a/src/bhyve/bhyve_capabilities.h b/src/bhyve/bhyve_capabilities.h index ccd8eb6..df7218f 100644 --- a/src/bhyve/bhyve_capabilities.h +++ b/src/bhyve/bhyve_capabilities.h @@ -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(virBhyveCapsFlags *caps); #endif diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c index 5e31ca6..6576029 100644 --- a/src/bhyve/bhyve_command.c +++ b/src/bhyve/bhyve_command.c @@ -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. diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 85b7c8f..7f365b1 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -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; @@ -1240,6 +1243,16 @@ bhyveStateInitialize(bool privileged, } unsigned +bhyveDriverGetCaps(virConnectPtr conn) +{ + bhyveConnPtr driver = conn->privateData; + + if (driver != NULL) + return driver->bhyvecaps; + return 0; +} + +unsigned bhyveDriverGetGrubCaps(virConnectPtr conn) { bhyveConnPtr driver = conn->privateData; diff --git a/src/bhyve/bhyve_driver.h b/src/bhyve/bhyve_driver.h index af2424a..221d5a0 100644 --- a/src/bhyve/bhyve_driver.h +++ b/src/bhyve/bhyve_driver.h @@ -25,6 +25,8 @@ int bhyveRegister(void); +unsigned bhyveDriverGetCaps(virConnectPtr conn); + unsigned bhyveDriverGetGrubCaps(virConnectPtr conn); #endif /* __BHYVE_DRIVER_H__ */ diff --git a/src/bhyve/bhyve_utils.h b/src/bhyve/bhyve_utils.h index bbaa3a3..4bccdcc 100644 --- a/src/bhyve/bhyve_utils.h +++ b/src/bhyve/bhyve_utils.h @@ -46,6 +46,7 @@ struct _bhyveConn { virCloseCallbacksPtr closeCallbacks; + unsigned bhyvecaps; unsigned grubcaps; }; diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-acpiapic.args b/tests/bhyvexml2argvdata/bhyvexml2argv-acpiapic.args index 79f8e88..6b26964 100644 --- a/tests/bhyvexml2argvdata/bhyvexml2argv-acpiapic.args +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-acpiapic.args @@ -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 diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-base.args b/tests/bhyvexml2argvdata/bhyvexml2argv-base.args index 4122e62..118735e 100644 --- a/tests/bhyvexml2argvdata/bhyvexml2argv-base.args +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-base.args @@ -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 diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-bhyveload-explicitargs.args b/tests/bhyvexml2argvdata/bhyvexml2argv-bhyveload-explicitargs.args index 4122e62..118735e 100644 --- a/tests/bhyvexml2argvdata/bhyvexml2argv-bhyveload-explicitargs.args +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-bhyveload-explicitargs.args @@ -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 diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-console.args b/tests/bhyvexml2argvdata/bhyvexml2argv-console.args index df50290..3119777 100644 --- a/tests/bhyvexml2argvdata/bhyvexml2argv-console.args +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-console.args @@ -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 diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-custom-loader.args b/tests/bhyvexml2argvdata/bhyvexml2argv-custom-loader.args index 4122e62..118735e 100644 --- a/tests/bhyvexml2argvdata/bhyvexml2argv-custom-loader.args +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-custom-loader.args @@ -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 diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-disk-cdrom-grub.args b/tests/bhyvexml2argvdata/bhyvexml2argv-disk-cdrom-grub.args index eb38969..2b1281f 100644 --- a/tests/bhyvexml2argvdata/bhyvexml2argv-disk-cdrom-grub.args +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-disk-cdrom-grub.args @@ -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 diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-disk-cdrom.args b/tests/bhyvexml2argvdata/bhyvexml2argv-disk-cdrom.args index eb38969..2b1281f 100644 --- a/tests/bhyvexml2argvdata/bhyvexml2argv-disk-cdrom.args +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-disk-cdrom.args @@ -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 diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-disk-virtio.args b/tests/bhyvexml2argvdata/bhyvexml2argv-disk-virtio.args index 1638d54..da0577c 100644 --- a/tests/bhyvexml2argvdata/bhyvexml2argv-disk-virtio.args +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-disk-virtio.args @@ -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 diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder.args b/tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder.args index eaba370..fc0522d 100644 --- a/tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder.args +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder.args @@ -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 \ diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder2.args b/tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder2.args index eaba370..fc0522d 100644 --- a/tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder2.args +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder2.args @@ -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 \ diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-grub-defaults.args b/tests/bhyvexml2argvdata/bhyvexml2argv-grub-defaults.args index 4122e62..118735e 100644 --- a/tests/bhyvexml2argvdata/bhyvexml2argv-grub-defaults.args +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-grub-defaults.args @@ -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 diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-localtime.args b/tests/bhyvexml2argvdata/bhyvexml2argv-localtime.args new file mode 100644 index 0000000..4122e62 --- /dev/null +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-localtime.args @@ -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 diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-localtime.ldargs b/tests/bhyvexml2argvdata/bhyvexml2argv-localtime.ldargs new file mode 100644 index 0000000..215d65f --- /dev/null +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-localtime.ldargs @@ -0,0 +1 @@ +/usr/sbin/bhyveload -m 214 -d /tmp/freebsd.img bhyve diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-localtime.xml b/tests/bhyvexml2argvdata/bhyvexml2argv-localtime.xml new file mode 100644 index 0000000..f62c626 --- /dev/null +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-localtime.xml @@ -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> diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-macaddr.args b/tests/bhyvexml2argvdata/bhyvexml2argv-macaddr.args index f914865..77c3a17 100644 --- a/tests/bhyvexml2argvdata/bhyvexml2argv-macaddr.args +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-macaddr.args @@ -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 diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-serial-grub-nocons.args b/tests/bhyvexml2argvdata/bhyvexml2argv-serial-grub-nocons.args index df50290..3119777 100644 --- a/tests/bhyvexml2argvdata/bhyvexml2argv-serial-grub-nocons.args +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-serial-grub-nocons.args @@ -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 diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-serial-grub.args b/tests/bhyvexml2argvdata/bhyvexml2argv-serial-grub.args index df50290..3119777 100644 --- a/tests/bhyvexml2argvdata/bhyvexml2argv-serial-grub.args +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-serial-grub.args @@ -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 diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-serial.args b/tests/bhyvexml2argvdata/bhyvexml2argv-serial.args index df50290..3119777 100644 --- a/tests/bhyvexml2argvdata/bhyvexml2argv-serial.args +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-serial.args @@ -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 diff --git a/tests/bhyvexml2argvtest.c b/tests/bhyvexml2argvtest.c index fa6f87f..3e57a78 100644 --- a/tests/bhyvexml2argvtest.c +++ b/tests/bhyvexml2argvtest.c @@ -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; -- 2.3.7 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list