]> xenbits.xensource.com Git - libvirt.git/commitdiff
bhyve: add UTC clock support
authorRoman Bogorodskiy <bogorodskiy@gmail.com>
Sun, 19 Jul 2015 08:20:35 +0000 (11:20 +0300)
committerRoman Bogorodskiy <bogorodskiy@gmail.com>
Wed, 22 Jul 2015 16:05:09 +0000 (19:05 +0300)
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.

25 files changed:
src/bhyve/bhyve_capabilities.c
src/bhyve/bhyve_capabilities.h
src/bhyve/bhyve_command.c
src/bhyve/bhyve_driver.c
src/bhyve/bhyve_driver.h
src/bhyve/bhyve_utils.h
tests/bhyvexml2argvdata/bhyvexml2argv-acpiapic.args
tests/bhyvexml2argvdata/bhyvexml2argv-base.args
tests/bhyvexml2argvdata/bhyvexml2argv-bhyveload-explicitargs.args
tests/bhyvexml2argvdata/bhyvexml2argv-console.args
tests/bhyvexml2argvdata/bhyvexml2argv-custom-loader.args
tests/bhyvexml2argvdata/bhyvexml2argv-disk-cdrom-grub.args
tests/bhyvexml2argvdata/bhyvexml2argv-disk-cdrom.args
tests/bhyvexml2argvdata/bhyvexml2argv-disk-virtio.args
tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder.args
tests/bhyvexml2argvdata/bhyvexml2argv-grub-bootorder2.args
tests/bhyvexml2argvdata/bhyvexml2argv-grub-defaults.args
tests/bhyvexml2argvdata/bhyvexml2argv-localtime.args [new file with mode: 0644]
tests/bhyvexml2argvdata/bhyvexml2argv-localtime.ldargs [new file with mode: 0644]
tests/bhyvexml2argvdata/bhyvexml2argv-localtime.xml [new file with mode: 0644]
tests/bhyvexml2argvdata/bhyvexml2argv-macaddr.args
tests/bhyvexml2argvdata/bhyvexml2argv-serial-grub-nocons.args
tests/bhyvexml2argvdata/bhyvexml2argv-serial-grub.args
tests/bhyvexml2argvdata/bhyvexml2argv-serial.args
tests/bhyvexml2argvtest.c

index 3a558793db0538b32fd69ff01be9713fcd1998c7..d2970a2315feecefd195bc1fe6967fbd250f54b1 100644 (file)
@@ -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;
+}
index ccd8eb6cf23c3d946928afe60af04a13725d3e31..0eb22a40de7e09905108c8d176dde4894e545a33 100644 (file)
@@ -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
index 5e31ca6434b8117348d582ee3ebe1d9cc2013121..65760299288b08d71c83a0312d4607ec986aa93e 100644 (file)
@@ -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.
index 85b7c8f537def78283a27475ed2ae61497f45d8d..7f365b1f24467893ce7db7d2d14a51488384fb74 100644 (file)
@@ -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)
 {
index af2424ad3d1c760b4775bf0851c3fb87e0e40726..221d5a0566ac342863c18b2fbb60da57a1d04640 100644 (file)
@@ -25,6 +25,8 @@
 
 int bhyveRegister(void);
 
+unsigned bhyveDriverGetCaps(virConnectPtr conn);
+
 unsigned bhyveDriverGetGrubCaps(virConnectPtr conn);
 
 #endif /* __BHYVE_DRIVER_H__ */
index bbaa3a35fa578d9a428e73efdd76733fa8f8dbd1..4bccdccd970528fcebfb80bf28b58f83b2453e06 100644 (file)
@@ -46,6 +46,7 @@ struct _bhyveConn {
 
     virCloseCallbacksPtr closeCallbacks;
 
+    unsigned bhyvecaps;
     unsigned grubcaps;
 };
 
index 79f8e88613df4a31bcc88a86d1cefbd14525eb39..6b269648129f1f0c324f74c19fe0d45d23c36590 100644 (file)
@@ -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
index 4122e627b0abc8223052985969bf688e4058fb80..118735e1f44ebd631ccb59b46753a5821e7cabcc 100644 (file)
@@ -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
index 4122e627b0abc8223052985969bf688e4058fb80..118735e1f44ebd631ccb59b46753a5821e7cabcc 100644 (file)
@@ -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
index df502902142b64c5d7a8afea5cd9ea7b3634a215..311977705b1140bde2c1038676ed2a287462cf20 100644 (file)
@@ -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
index 4122e627b0abc8223052985969bf688e4058fb80..118735e1f44ebd631ccb59b46753a5821e7cabcc 100644 (file)
@@ -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
index eb38969e12d2e5251dabec80e7e3560d306ce5f6..2b1281f06f2e704661c0419ac4c457a644b7ef44 100644 (file)
@@ -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
index eb38969e12d2e5251dabec80e7e3560d306ce5f6..2b1281f06f2e704661c0419ac4c457a644b7ef44 100644 (file)
@@ -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
index 1638d540b42b21cc2a72abe1fe6d1a9cc1b1daa9..da0577c186ad97539d4519d166c494de02d6d692 100644 (file)
@@ -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
index eaba3708a1a586d8281bdf90541ee5684e29d7e6..fc0522de18c553c942a47340298bf09c26dab9fb 100644 (file)
@@ -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 \
index eaba3708a1a586d8281bdf90541ee5684e29d7e6..fc0522de18c553c942a47340298bf09c26dab9fb 100644 (file)
@@ -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 \
index 4122e627b0abc8223052985969bf688e4058fb80..118735e1f44ebd631ccb59b46753a5821e7cabcc 100644 (file)
@@ -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 (file)
index 0000000..4122e62
--- /dev/null
@@ -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 (file)
index 0000000..215d65f
--- /dev/null
@@ -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 (file)
index 0000000..f62c626
--- /dev/null
@@ -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>
index f91486502e4a0bfb8e17bfcfad8654ca874af530..77c3a17ba26697a82c3d17cb9981a52737d3cc4c 100644 (file)
@@ -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
index df502902142b64c5d7a8afea5cd9ea7b3634a215..311977705b1140bde2c1038676ed2a287462cf20 100644 (file)
@@ -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
index df502902142b64c5d7a8afea5cd9ea7b3634a215..311977705b1140bde2c1038676ed2a287462cf20 100644 (file)
@@ -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
index df502902142b64c5d7a8afea5cd9ea7b3634a215..311977705b1140bde2c1038676ed2a287462cf20 100644 (file)
@@ -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
index fa6f87f8c68c675e07d1e49313baf96ba5098c48..3e57a78e101bc5da5ad3c1d725c5485c31cd1798 100644 (file)
@@ -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;