summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorneel <neel@FreeBSD.org>2015-02-24 02:04:16 +0000
committerneel <neel@FreeBSD.org>2015-02-24 02:04:16 +0000
commitb341fa888c7a3b71ef8fb36ed40f08b7ceb8c486 (patch)
treeb53b5a410574d495c9fbeeaead7a49f4b3ecf90d
parent11397750d9f6c941f9d39544909634817c8fae42 (diff)
downloadFreeBSD-src-b341fa888c7a3b71ef8fb36ed40f08b7ceb8c486.zip
FreeBSD-src-b341fa888c7a3b71ef8fb36ed40f08b7ceb8c486.tar.gz
Add "-u" option to bhyve(8) to indicate that the RTC should maintain UTC time.
The default remains localtime for compatibility with the original device model in bhyve(8). This is required for OpenBSD guests which assume that the RTC keeps UTC time. Reviewed by: grehan Pointed out by: Jason Tubnor (jason@tubnor.net) MFC after: 2 weeks
-rw-r--r--usr.sbin/bhyve/bhyve.84
-rw-r--r--usr.sbin/bhyve/bhyverun.c12
-rw-r--r--usr.sbin/bhyve/rtc.c16
-rw-r--r--usr.sbin/bhyve/rtc.h2
4 files changed, 21 insertions, 13 deletions
diff --git a/usr.sbin/bhyve/bhyve.8 b/usr.sbin/bhyve/bhyve.8
index a537c48..e3cf36b 100644
--- a/usr.sbin/bhyve/bhyve.8
+++ b/usr.sbin/bhyve/bhyve.8
@@ -32,7 +32,7 @@
.Nd "run a guest operating system inside a virtual machine"
.Sh SYNOPSIS
.Nm
-.Op Fl abehwxACHPWY
+.Op Fl abehuwxACHPWY
.Op Fl c Ar numcpus
.Op Fl g Ar gdbport
.Op Fl l Ar lpcdev Ns Op , Ns Ar conf
@@ -239,6 +239,8 @@ The host device must have been reserved at boot-time using the
loader variable as described in
.Xr vmm 4 .
.El
+.It Fl u
+RTC keeps UTC time.
.It Fl U Ar uuid
Set the universally unique identifier
.Pq UUID
diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c
index 347e436..97ed046 100644
--- a/usr.sbin/bhyve/bhyverun.c
+++ b/usr.sbin/bhyve/bhyverun.c
@@ -122,7 +122,7 @@ usage(int code)
{
fprintf(stderr,
- "Usage: %s [-abehwxACHPWY] [-c vcpus] [-g <gdb port>] [-l <lpc>]\n"
+ "Usage: %s [-abehuwxACHPWY] [-c vcpus] [-g <gdb port>] [-l <lpc>]\n"
" %*s [-m mem] [-p vcpu:hostcpu] [-s <pci>] [-U uuid] <vm>\n"
" -a: local apic is in xAPIC mode (deprecated)\n"
" -A: create ACPI tables\n"
@@ -137,6 +137,7 @@ usage(int code)
" -p: pin 'vcpu' to 'hostcpu'\n"
" -P: vmexit from the guest on pause\n"
" -s: <slot,driver,configinfo> PCI slot config\n"
+ " -u: RTC keeps UTC time\n"
" -U: uuid\n"
" -w: ignore unimplemented MSRs\n"
" -W: force virtio to use single-vector MSI\n"
@@ -685,6 +686,7 @@ main(int argc, char *argv[])
{
int c, error, gdb_port, err, bvmcons;
int dump_guest_memory, max_vcpus, mptgen;
+ int rtc_localtime;
struct vmctx *ctx;
uint64_t rip;
size_t memsize;
@@ -696,8 +698,9 @@ main(int argc, char *argv[])
guest_ncpus = 1;
memsize = 256 * MB;
mptgen = 1;
+ rtc_localtime = 1;
- while ((c = getopt(argc, argv, "abehwxACHIPWYp:g:c:s:m:l:U:")) != -1) {
+ while ((c = getopt(argc, argv, "abehuwxACHIPWYp:g:c:s:m:l:U:")) != -1) {
switch (c) {
case 'a':
x2apic_mode = 0;
@@ -757,6 +760,9 @@ main(int argc, char *argv[])
case 'e':
strictio = 1;
break;
+ case 'u':
+ rtc_localtime = 0;
+ break;
case 'U':
guest_uuid_str = optarg;
break;
@@ -820,7 +826,7 @@ main(int argc, char *argv[])
pci_irq_init(ctx);
ioapic_init(ctx);
- rtc_init(ctx);
+ rtc_init(ctx, rtc_localtime);
sci_init(ctx);
/*
diff --git a/usr.sbin/bhyve/rtc.c b/usr.sbin/bhyve/rtc.c
index 055af50..5c70154 100644
--- a/usr.sbin/bhyve/rtc.c
+++ b/usr.sbin/bhyve/rtc.c
@@ -55,23 +55,23 @@ __FBSDID("$FreeBSD$");
/*
* Returns the current RTC time as number of seconds since 00:00:00 Jan 1, 1970
- *
- * XXX this always returns localtime to maintain compatibility with the
- * original device model.
*/
static time_t
-rtc_time(struct vmctx *ctx)
+rtc_time(struct vmctx *ctx, int use_localtime)
{
struct tm tm;
time_t t;
time(&t);
- localtime_r(&t, &tm);
- return (timegm(&tm));
+ if (use_localtime) {
+ localtime_r(&t, &tm);
+ t = timegm(&tm);
+ }
+ return (t);
}
void
-rtc_init(struct vmctx *ctx)
+rtc_init(struct vmctx *ctx, int use_localtime)
{
size_t himem;
size_t lomem;
@@ -99,7 +99,7 @@ rtc_init(struct vmctx *ctx)
err = vm_rtc_write(ctx, RTC_HMEM_MSB, himem >> 16);
assert(err == 0);
- err = vm_rtc_settime(ctx, rtc_time(ctx));
+ err = vm_rtc_settime(ctx, rtc_time(ctx, use_localtime));
assert(err == 0);
}
diff --git a/usr.sbin/bhyve/rtc.h b/usr.sbin/bhyve/rtc.h
index 72cffb3..5b08ca3 100644
--- a/usr.sbin/bhyve/rtc.h
+++ b/usr.sbin/bhyve/rtc.h
@@ -29,6 +29,6 @@
#ifndef _RTC_H_
#define _RTC_H_
-void rtc_init(struct vmctx *ctx);
+void rtc_init(struct vmctx *ctx, int use_localtime);
#endif /* _RTC_H_ */
OpenPOWER on IntegriCloud