From 6cb9ef1bab8030e5b9a9f0bb26e00e103af8db57 Mon Sep 17 00:00:00 2001 From: Roman Bogorodskiy Date: Sun, 19 Jul 2015 11:20:35 +0300 Subject: [PATCH] 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 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 + .../bhyvexml2argv-acpiapic.args | 2 +- .../bhyvexml2argvdata/bhyvexml2argv-base.args | 2 +- .../bhyvexml2argv-bhyveload-explicitargs.args | 2 +- .../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 +- .../bhyvexml2argv-localtime.args | 3 ++ .../bhyvexml2argv-localtime.ldargs | 1 + .../bhyvexml2argv-localtime.xml | 23 ++++++++++++++ .../bhyvexml2argv-macaddr.args | 2 +- .../bhyvexml2argv-serial-grub-nocons.args | 2 +- .../bhyvexml2argv-serial-grub.args | 2 +- .../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 3a558793db..d2970a2315 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(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; +} diff --git a/src/bhyve/bhyve_capabilities.h b/src/bhyve/bhyve_capabilities.h index ccd8eb6cf2..0eb22a40de 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(unsigned int *caps); #endif diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c index 5e31ca6434..6576029928 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 85b7c8f537..7f365b1f24 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; @@ -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) { diff --git a/src/bhyve/bhyve_driver.h b/src/bhyve/bhyve_driver.h index af2424ad3d..221d5a0566 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 bbaa3a35fa..4bccdccd97 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 79f8e88613..6b26964812 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 4122e627b0..118735e1f4 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 4122e627b0..118735e1f4 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 df50290214..311977705b 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 4122e627b0..118735e1f4 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 eb38969e12..2b1281f06f 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 eb38969e12..2b1281f06f 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 1638d540b4..da0577c186 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 eaba3708a1..fc0522de18 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 eaba3708a1..fc0522de18 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 4122e627b0..118735e1f4 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 0000000000..4122e627b0 --- /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 0000000000..215d65fb25 --- /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 0000000000..f62c6261c9 --- /dev/null +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-localtime.xml @@ -0,0 +1,23 @@ + + bhyve + df3be7e7-a104-11e3-aeb0-50e5492bd3dc + 219136 + 1 + + hvm + + + + + + + +
+ + + + +
+ + + diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-macaddr.args b/tests/bhyvexml2argvdata/bhyvexml2argv-macaddr.args index f91486502e..77c3a17ba2 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 df50290214..311977705b 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 df50290214..311977705b 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 df50290214..311977705b 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 fa6f87f8c6..3e57a78e10 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; -- GitLab