svn commit: r279225 - head/usr.sbin/bhyve

Neel Natu neel at FreeBSD.org
Tue Feb 24 02:04:18 UTC 2015


Author: neel
Date: Tue Feb 24 02:04:16 2015
New Revision: 279225
URL: https://svnweb.freebsd.org/changeset/base/279225

Log:
  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 at tubnor.net)
  MFC after:	2 weeks

Modified:
  head/usr.sbin/bhyve/bhyve.8
  head/usr.sbin/bhyve/bhyverun.c
  head/usr.sbin/bhyve/rtc.c
  head/usr.sbin/bhyve/rtc.h

Modified: head/usr.sbin/bhyve/bhyve.8
==============================================================================
--- head/usr.sbin/bhyve/bhyve.8	Tue Feb 24 01:46:43 2015	(r279224)
+++ head/usr.sbin/bhyve/bhyve.8	Tue Feb 24 02:04:16 2015	(r279225)
@@ -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 
 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

Modified: head/usr.sbin/bhyve/bhyverun.c
==============================================================================
--- head/usr.sbin/bhyve/bhyverun.c	Tue Feb 24 01:46:43 2015	(r279224)
+++ head/usr.sbin/bhyve/bhyverun.c	Tue Feb 24 02:04:16 2015	(r279225)
@@ -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);
 
 	/*

Modified: head/usr.sbin/bhyve/rtc.c
==============================================================================
--- head/usr.sbin/bhyve/rtc.c	Tue Feb 24 01:46:43 2015	(r279224)
+++ head/usr.sbin/bhyve/rtc.c	Tue Feb 24 02:04:16 2015	(r279225)
@@ -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);
 }
 

Modified: head/usr.sbin/bhyve/rtc.h
==============================================================================
--- head/usr.sbin/bhyve/rtc.h	Tue Feb 24 01:46:43 2015	(r279224)
+++ head/usr.sbin/bhyve/rtc.h	Tue Feb 24 02:04:16 2015	(r279225)
@@ -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_ */


More information about the svn-src-head mailing list