Bug 859868 - Guest timezone is not the same as what set
Guest timezone is not the same as what set
Status: CLOSED NOTABUG
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: libvirt (Show other bugs)
6.4
Unspecified Unspecified
medium Severity medium
: rc
: ---
Assigned To: Osier Yang
Virtualization Bugs
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2012-09-24 04:54 EDT by hongming
Modified: 2014-03-26 21:03 EDT (History)
10 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2012-09-29 03:22:44 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description hongming 2012-09-24 04:54:51 EDT
Description of problem:
libvirt can't pass timezone parameter from domain's xml to qemu-kvm

Version-Release number of selected component (if applicable):
libvirt-0.10.2-0rc1.el6.x86_64
qemu-kvm-0.12.1.2-2.307.el6.x86_64

How reproducible:
100% 

Steps to Reproduce:
1.# virsh start newrhel6
Domain newrhel6 started
 
2. # virsh dumpxml newrhel6
<domain type='kvm' id='3'>
 .....
  <clock offset='localtime'/>
 .....
</domain>

3. Check the host's timezone
# date -R
Mon, 24 Sep 2012 11:30:41 +0800

4.Login guest ,check its timezone
# date -R
Mon, 24 Sep 2012 07:31:19 -0400

5.Check qemu-kvm ,it is "-rtc base=localtime" 

# ps -ef|grep qemu-kvm
qemu      2095     1  6 16:55 ?        00:00:00 /usr/libexec/qemu-kvm -name newrhel6 -S -M rhel6.3.0 -enable-kvm -m 1024 -smp 1,maxcpus=10,sockets=10,cores=1,threads=1 -uuid 8242f7c4-b8e4-1f9c-09ea-17ce0bfebc3b -nodefconfig -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/newrhel6.monitor,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=localtime -no-shutdown -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 -drive file=/var/lib/libvirt/images/kvm-rhel6.3-x86_64.img,if=none,id=drive-ide0-0-0,format=raw,cache=none -device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 -netdev tap,fd=26,id=hostnet0 -device rtl8139,netdev=hostnet0,id=net0,mac=52:54:00:28:65:0f,bus=pci.0,addr=0x3 -chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 -vnc 127.0.0.1:0 -vga cirrus -device intel-hda,id=sound0,bus=pci.0,addr=0x4 -device hda-duplex,id=sound0-codec0,bus=sound0.0,cad=0 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5

6. Edit timezone as Europe/Paris.
# virsh edit newrhel6
......
 <clock offset='timezone' timezone='Europe/Paris'/>  (Its offset is +0200)
......
Domain newrhel6 XML configuration edited.

7. # virsh destroy newrhel6
Domain newrhel6 destroyed

8. # virsh start newrhel6
Domain newrhel6 started

9. Login guest ,check its timezone
# date -R
Mon, 24 Sep 2012 07:31:19 -0400

10. Check qemu-kvm ,it is "-rtc base=localtime" 

# ps -ef|grep qemu-kvm
root       954  3428  0 16:41 pts/0    00:00:00 grep qemu-kvm
qemu     11541     1  0 11:33 ?        00:00:36 /usr/libexec/qemu-kvm -name newrhel6 -S -M rhel6.3.0 -enable-kvm -m 1024 -smp 1,maxcpus=10,sockets=10,cores=1,threads=1 -uuid 8242f7c4-b8e4-1f9c-09ea-17ce0bfebc3b -nodefconfig -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/newrhel6.monitor,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=localtime -no-shutdown -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 -drive file=/var/lib/libvirt/images/kvm-rhel6.3-x86_64.img,if=none,id=drive-ide0-0-0,format=raw,cache=none -device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 -netdev tap,fd=26,id=hostnet0 -device rtl8139,netdev=hostnet0,id=net0,mac=52:54:00:28:65:0f,bus=pci.0,addr=0x3 -chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 -vnc 127.0.0.1:0 -vga cirrus -device intel-hda,id=sound0,bus=pci.0,addr=0x4 -device hda-duplex,id=sound0-codec0,bus=sound0.0,cad=0 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5

  
Actual results:
libvirt can't pass timezone parameter from domain's xml to qemu-kvm

Expected results:
libvirt pass timezone parameter from domain's xml to qemu-kvm

Additional info:
Comment 2 Daniel Berrange 2012-09-24 07:47:37 EDT
Looking at the command line arguments of QEMU won't tell you the timezone. You need to look at the environment variables instead.
Comment 3 Osier Yang 2012-09-27 02:54:29 EDT
(In reply to comment #2)
> Looking at the command line arguments of QEMU won't tell you the timezone.
> You need to look at the environment variables instead.

Right, you should check if the env variable "TZ" is set correctly for "timezone".
Comment 4 hongming 2012-09-27 03:41:21 EDT
Add the following info and steps

Guest kernel - 2.6.32-279.el6.x86_64


1. Check host timezone
# cat /etc/sysconfig/clock 
ZONE="Asia/Shanghai"


2.Guest timezone is set as follows
# virsh dumpxml newrhel6 |grep timezone
  <clock offset='timezone' timezone='Europe/Paris'>


3.Login guest and check guest timezone
# cat /etc/sysconfig/clock 
ZONE="America/New_York"


# hwclock -s


# cat /etc/sysconfig/clock 
ZONE="America/New_York"


# hwclock -w


# cat /etc/sysconfig/clock 
ZONE="America/New_York"
Comment 5 hongming 2012-09-27 03:43:37 EDT
After confirmed with dev .change the subject.
Comment 6 Osier Yang 2012-09-27 09:43:20 EDT
(In reply to comment #4)
> Add the following info and steps
> 
> Guest kernel - 2.6.32-279.el6.x86_64
> 
> 
> 1. Check host timezone
> # cat /etc/sysconfig/clock 
> ZONE="Asia/Shanghai"
> 
> 
> 2.Guest timezone is set as follows
> # virsh dumpxml newrhel6 |grep timezone
>   <clock offset='timezone' timezone='Europe/Paris'>
> 
> 
> 3.Login guest and check guest timezone
> # cat /etc/sysconfig/clock 
> ZONE="America/New_York"
> 
> 
> # hwclock -s
> 
> 
> # cat /etc/sysconfig/clock 
> ZONE="America/New_York"
> 
> 
> # hwclock -w
> 
> 
> # cat /etc/sysconfig/clock 
> ZONE="America/New_York"

What's the hardware clock on host? (I.e. output of "hwclock"). I
Comment 7 hongming 2012-09-27 20:43:10 EDT
(In reply to comment #6)
> (In reply to comment #4)
> > Add the following info and steps
> > 
> > Guest kernel - 2.6.32-279.el6.x86_64
> > 
> > 
> > 1. Check host timezone
> > # cat /etc/sysconfig/clock 
> > ZONE="Asia/Shanghai"
> > 
> > 
> > 2.Guest timezone is set as follows
> > # virsh dumpxml newrhel6 |grep timezone
> >   <clock offset='timezone' timezone='Europe/Paris'>
> > 
> > 
> > 3.Login guest and check guest timezone
> > # cat /etc/sysconfig/clock 
> > ZONE="America/New_York"
> > 
> > 
> > # hwclock -s
> > 
> > 
> > # cat /etc/sysconfig/clock 
> > ZONE="America/New_York"
> > 
> > 
> > # hwclock -w
> > 
> > 
> > # cat /etc/sysconfig/clock 
> > ZONE="America/New_York"
> 
> What's the hardware clock on host? (I.e. output of "hwclock"). I

[root@localhost qemu]# hwclock
Fri 28 Sep 2012 08:38:24 AM CST  -0.809430 seconds
Comment 8 Osier Yang 2012-09-28 06:35:41 EDT
More debug datas:

LC_ALL=C PATH=/sbin:/usr/sbin:/bin:/usr/bin TZ=Europe/Paris QEMU_AUDIO_DRV=none /usr/libexec/qemu-kvm -name newrhel6 -S -M rhel6.3.0 -enable-kvm -m 1024 -smp 2,maxcpus=10,sockets=10,cores=1,threads=1 -uuid 8242f7c4-b8e4-1f9c-09ea-17ce0bfebc3b -nodefconfig -nodefaults -chardev socket,id=charmonitor,path=/var/lib/libvirt/qemu/newrhel6.monitor,server,nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=localtime -no-shutdown -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 -drive file=/var/lib/libvirt/images/kvm-rhel6.3-x86_64.img,if=none,id=drive-ide0-0-0,format=raw,cache=none -device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 -netdev tap,fd=23,id=hostnet0 -device rtl8139,netdev=hostnet0,id=net0,mac=52:54:00:28:65:0f,bus=pci.0,addr=0x3 -chardev pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 -vnc 127.0.0.1:0 -vga cirrus -device intel-hda,id=sound0,bus=pci.0,addr=0x4 -device hda-duplex,id=sound0-codec0,bus=sound0.0,cad=0 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5

guest# date
Fri Sep 28 06:48:53 EDT 2012

guest# hwclock
Fri 28 Sep 2012 06:49:45 AM EDT  -0.209066 seconds

host# hwclock
Fri 28 Sep 2012 04:50:04 PM CST  -0.754828 seconds

host# date
Fri Sep 28 16:50:16 CST 2012
Comment 9 Osier Yang 2012-09-28 06:55:53 EDT
(In reply to comment #8)
> More debug datas:
> 
> LC_ALL=C PATH=/sbin:/usr/sbin:/bin:/usr/bin TZ=Europe/Paris
> QEMU_AUDIO_DRV=none /usr/libexec/qemu-kvm -name newrhel6 -S -M rhel6.3.0
> -enable-kvm -m 1024 -smp 2,maxcpus=10,sockets=10,cores=1,threads=1 -uuid
> 8242f7c4-b8e4-1f9c-09ea-17ce0bfebc3b -nodefconfig -nodefaults -chardev
> socket,id=charmonitor,path=/var/lib/libvirt/qemu/newrhel6.monitor,server,
> nowait -mon chardev=charmonitor,id=monitor,mode=control -rtc base=localtime
> -no-shutdown -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 -drive
> file=/var/lib/libvirt/images/kvm-rhel6.3-x86_64.img,if=none,id=drive-ide0-0-
> 0,format=raw,cache=none -device
> ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1
> -netdev tap,fd=23,id=hostnet0 -device
> rtl8139,netdev=hostnet0,id=net0,mac=52:54:00:28:65:0f,bus=pci.0,addr=0x3
> -chardev pty,id=charserial0 -device
> isa-serial,chardev=charserial0,id=serial0 -vnc 127.0.0.1:0 -vga cirrus
> -device intel-hda,id=sound0,bus=pci.0,addr=0x4 -device
> hda-duplex,id=sound0-codec0,bus=sound0.0,cad=0 -device
> virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5
> 
> guest# date
> Fri Sep 28 06:48:53 EDT 2012
> 
> guest# hwclock
> Fri 28 Sep 2012 06:49:45 AM EDT  -0.209066 seconds
> 
> host# hwclock
> Fri 28 Sep 2012 04:50:04 PM CST  -0.754828 seconds
> 
> host# date
> Fri Sep 28 16:50:16 CST 2012

Hi, Paolo, It's said that you knowns qemu timer well, do you known why it's
such different?

IIUC, -rtc base=localtime should start the guest clock with current host time.
And "ret = localtime(&ti);" will also honor the env variable TZ. So it's
strange for me why they are different (ntp service in guest is disabled).
Comment 10 Daniel Berrange 2012-09-28 07:11:12 EDT
Your test scenarios are flawed.

The <clock> config in libvirt XML *only* controls what time is stored in the BIOS virtual clock. It has no effect on the actuall OS configuration. So if you set a custom timezone in the XML, you need to manually configure the guest with the matching time, and also tell the guest that its hardware cllock is set to localtime, not UTC

To test this you need todo:

 - On the host

  # TZ=Europe/Paris date

 - In the guest

  # TZ=Europe/Paris hwclock --localtime

and they should match - and do match in my testing.
Comment 11 Paolo Bonzini 2012-09-28 07:42:41 EDT
So, there are three timezones involved:
- EDT (America/New_York), which is 4 hours before UTC (Greenwhich).
- CST (Asia/Shanghai), which is 8 hours after UTC.
- CEST (Europe/Paris) is (at this time of year) 2 hours after UTC.

The time when the guest was started is 16:50 CST = 08:50 UTC.

Inside QEMU, localtime returns CEST.  So the RTC was initialized with 10:50.

Your guest is probably configured for "-rtc base=utc".  It interprets 10:50 as UTC and prints a result that is 4 hours less than what is answered.

The reason of the confusion is that the <clock> element should match your guest's configuration.  Setting the timezone to Europe/Paris while the guest believes to be in America/New_York is invalid.

However, I won't close it immediately as NOTABUG.  Please do the following tests.

- ensure the timezone in the guest to America/New_York.  Start the VM with <clock offset="utc">.    The following two pairs of commands should give the same output on the guest and the host:

          guest                      host
     ------------------------------------------------------------
          date                       TZ=America/New_York date
          TZ=Asia/Shanghai date      date

In other words, "date" output in the guest should be 12 hours before the "date" output in the host.  This is correct, because that's the time a hypothetical user from New York would see on his watch.

- open system-config-date and turn off the "System clock uses UTC" checkbox in the Timezone tab.  Turn off the VM.  Start it again, this time with <clock offset="timezone" timezone="America/New_York">.  Repeat the same tests as step 1.  They should have the same results.

- open system-config-date and set the timezone to Asia/Shanghai.  Leave the checkbox off.  Turn off the VM.  Start it again, this time with <clock offset="localtime">.  The following two pairs of commands should give the same output on the guest and the host:

          guest                      host
     ------------------------------------------------------------
          date                       date
          TZ=America/New_York date   TZ=America/New_York date

- open system-config-date and put the checkbox on again.  Turn off the VM.  Start it again, this time with <clock offset="utc">.  Repeat the same test as step 3.  They should have the same results.


Perhaps this can be added to the test plan?
Comment 12 Osier Yang 2012-09-28 11:29:41 EDT
(In reply to comment #11)
> So, there are three timezones involved:
> - EDT (America/New_York), which is 4 hours before UTC (Greenwhich).
> - CST (Asia/Shanghai), which is 8 hours after UTC.
> - CEST (Europe/Paris) is (at this time of year) 2 hours after UTC.
> 
> The time when the guest was started is 16:50 CST = 08:50 UTC.
> 
> Inside QEMU, localtime returns CEST.  So the RTC was initialized with 10:50.
> 
> Your guest is probably configured for "-rtc base=utc".  It interprets 10:50
> as UTC and prints a result that is 4 hours less than what is answered.
> 
> The reason of the confusion is that the <clock> element should match your
> guest's configuration.  Setting the timezone to Europe/Paris while the guest
> believes to be in America/New_York is invalid.
> 
> However, I won't close it immediately as NOTABUG.  Please do the following
> tests.
> 
> - ensure the timezone in the guest to America/New_York.  Start the VM with
> <clock offset="utc">.    The following two pairs of commands should give the
> same output on the guest and the host:
> 
>           guest                      host
>      ------------------------------------------------------------
>           date                       TZ=America/New_York date
>           TZ=Asia/Shanghai date      date
> 
> In other words, "date" output in the guest should be 12 hours before the
> "date" output in the host.  This is correct, because that's the time a
> hypothetical user from New York would see on his watch.
> 
> - open system-config-date and turn off the "System clock uses UTC" checkbox
> in the Timezone tab.  Turn off the VM.  Start it again, this time with
> <clock offset="timezone" timezone="America/New_York">.  Repeat the same
> tests as step 1.  They should have the same results.
> 
> - open system-config-date and set the timezone to Asia/Shanghai.  Leave the
> checkbox off.  Turn off the VM.  Start it again, this time with <clock
> offset="localtime">.  The following two pairs of commands should give the
> same output on the guest and the host:
> 
>           guest                      host
>      ------------------------------------------------------------
>           date                       date
>           TZ=America/New_York date   TZ=America/New_York date
> 
> - open system-config-date and put the checkbox on again.  Turn off the VM. 
> Start it again, this time with <clock offset="utc">.  Repeat the same test
> as step 3.  They should have the same results.
> 
> 
> Perhaps this can be added to the test plan?

Thanks, paolo, with explaination from you and Daniel, finally I'm clear. 

@Hongming, could you do the testing, and add it to the testplan?
Comment 13 hongming 2012-09-28 23:41:59 EDT
Do the following test. The results are expected. Have add it to test plan.

================================================================================
The timezone of guest is America/New_York.

# virsh start rhel6.3
Domain rhel6.3 started


# virsh dumpxml rhel6.3 |grep clock
  <clock offset='utc'/>


guest                                | host
----------------------------------------------------------------------------
# date                               |# TZ=America/New_York date
Fri Sep 28 22:20:18 EDT 2012         |Fri Sep 28 22:20:29 EDT 2012 
----------------------------------------------------------------------------
# TZ=Asia/Shanghai date              |# date  
Sat Sep 29 10:21:49 CST 2012         |Sat Sep 29 10:22:11 CST 2012
----------------------------------------------------------------------------
 
================================================================================
Open system-config-date and turn off the "System clock uses UTC" checkbox in the Timezone tab


# virsh destroy rhel6.3
Domain rhel6.3 destroyed


# virsh edit rhel6.3 ( <clock offset="timezone" timezone="America/New_York"> )
Domain rhel6.3 XML configuration edited.


# virsh start rhel6.3
Domain rhel6.3 started

# virsh dumpxml rhel6.3 |grep clock
  <clock offset='timezone' timezone='America/New_York'/>


guest                                | host
----------------------------------------------------------------------------
# date                               |# TZ=America/New_York date
Fri Sep 28 22:44:06 EDT 2012         |Fri Sep 28 22:44:49 EDT 2012
----------------------------------------------------------------------------
# TZ=Asia/Shanghai date              |# date  
Sat Sep 29 10:45:16 CST 2012         |Sat Sep 29 10:45:32 CST 2012
----------------------------------------------------------------------------

===============================================================================
Open system-config-date and set the timezone to Asia/Shanghai.Leave the "System clock uses UTC" off.

# virsh edit rhel6.3 (<clock offset='localtime'/>)
Domain rhel6.3 XML configuration edited.


# virsh destroy rhel6.3
Domain rhel6.3 destroyed


# virsh start rhel6.3
Domain rhel6.3 started


# virsh dumpxml rhel6.3 |grep clock
  <clock offset='localtime'/>

guest                                | host
----------------------------------------------------------------------------
# date                               |# date
Sat Sep 29 11:09:20 CST 2012         |Sat Sep 29 11:09:41 CST 2012
----------------------------------------------------------------------------
# TZ=America/New_York date           |# TZ=America/New_York date
Fri Sep 28 23:10:46 EDT 2012         |Fri Sep 28 23:10:10 EDT 2012
----------------------------------------------------------------------------

==============================================================================
Open system-config-date and put the checkbox on

# virsh edit rhel6.3 (<clock offset='utc'/>)
Domain rhel6.3 XML configuration edited.


# virsh destroy rhel6.3
Domain rhel6.3 destroyed


# virsh start rhel6.3
Domain rhel6.3 started


# virsh dumpxml rhel6.3 |grep clock
  <clock offset='utc'/>

guest                                | host
----------------------------------------------------------------------------
# date                               |# date
Sat Sep 29 11:25:55 CST 2012         |Sat Sep 29 11:25:00 CST 2012
----------------------------------------------------------------------------
# TZ=America/New_York date           |# TZ=America/New_York date
Fri Sep 28 23:26:53 EDT 2012         |Fri Sep 28 23:27:27 EDT 2012
----------------------------------------------------------------------------
Comment 14 Osier Yang 2012-09-29 03:22:44 EDT
(In reply to comment #13)
> Do the following test. The results are expected. Have add it to test plan.
> 

Close the bug as NOTABUG then.

Note You need to log in before you can comment on or make changes to this bug.