From mboxrd@z Thu Jan 1 00:00:00 1970 From: Philipp Hahn Subject: [libvirt] [BUG, PATCH-RFC] libvirt localtime and rtc_timeoffset handling in xen-sexpr/sxpr/sxp Date: Wed, 11 Jan 2012 11:20:18 +0100 Message-ID: <201201111121.22236.hahn@univention.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============3066580839774506476==" Return-path: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com To: libvir-list@redhat.com Cc: xen-devel@lists.xensource.com, John Levon List-Id: xen-devel@lists.xenproject.org --===============3066580839774506476== Content-Type: multipart/signed; boundary="nextPart1364855.lg51dqPocx"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit --nextPart1364855.lg51dqPocx Content-Type: multipart/mixed; boundary="Boundary-01=_iJWDPu42lbAemiP" Content-Transfer-Encoding: 7bit Content-Disposition: inline --Boundary-01=_iJWDPu42lbAemiP Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hello, I'm currently tracking a problem in libvirt regarding Xens handling of=20 localtime and rtc_timeoffset. My current understanding (Xen-3.4.3 and=20 Xen-4.1.2 under Linux) of Xend (the depcrecated Python one still used by=20 libvirt) is as this: =2D for HV domains, the RTC gets setup to either UTC or localtime depending= =20 on "/domain/image/hvm/localtime" =C2=B1 "/domain/image/hvm/rtc_offset". =2D if the OS of a domU changes its RTC, the rtc_offset gets adjusted and i= s=20 saved in XenStore as "/vm/$UUID/rtc/timeoffset". =2D if the dom0 accesses its RTC, is accesses the real HW-RTC. =2D the Xen-Hypervisor initially read the HW-RTC to setup its Wallclock onc= e,=20 which is than used to simulate the domU RTCs. (The HW-RTC is otherwise only= =20 accessed on (ACPI-)Suspend and Resume, and with NTP-drift-correction from=20 dom0). =2D on shut-down the rtc_offset is stored by Xend in=20 the "/var/lib/xend/domains/$uuid/config.sxp" file=20 in "/domain/image/hvm/rtc_timeoffset", from where it is loaded again on nex= t=20 start. =2D since PV domains don't have a RTC, they somehow(?) get either initializ= ed to=20 the localtime or UTC time depending on "/domain/image/linux/localtime". @xen: Did I figure out that correct? @xen: Is there some documentation on the Xen-sxp domain configuration? For the=20 Python based xen-xm format, I found (and updated)=20 , but for Xen-sxp I s= o=20 far found no documentation, especially on what changed between xen-1, xen-2= ,=20 xen-3.x, xen-4.x. @libvirt: Comparing Xend handling to =20 the current translation done by libvirt looks wrong; I think is mandates ba= ck=20 to the time when Xen supported only PV-domUs: libvirt translates the Xen configuration to "localtime" and "utc" ignoring= =20 the "rtc_offset", which exists for HV domains. For localtime=3D0 this=20 translates to libvirts offset=3D"variable"-case, but for localtime=3D1 ther= e is=20 no matching mapping in libvirt. Since for PV domains no rtc_timeoffset is tracked, there the mapping to "ut= c"=20 and "localtime" looks right. =46or libvirt there was a patch=20 whi= ch=20 added some special handling for "localtime" to be either placed=20 in "/domain/localtime" or "/domain/image/{hvm,linux}/localtime". Xend from= =20 3.4.3 und 4.1.2 seems to accept either one, but /domain/image/hvm/localtime= =20 is preferred and overwrites the first one. When reading back the=20 configuration the setting is always returned=20 as /domain/image/{hvm,linux}/localtime. @John: Is there a case, where /domain/localtime is returned or is that key=20 always translated to /domain/linux/{hvm,linux}/localtime? As you had a=20 sun.com email address, was this some special case when using Xen with=20 Solaris? @libvirt: The attached patch (for 0.8.7) would change the implementation to match the= =20 following: 1. For Xen-PV-domUs, use clock/@offset=3D'utc' and clock/@offset=3D'localti= me'. 2. For Xen-HV-domUs, use clock/@offset=3D'variable'. 3. For backward compatibility with old libvirt-XML-files convert=20 clock/@offset=3D'utc' =E2=86=92 (localtime 0)(rtc_timeoffset 0) and=20 clock/@offset=3D'localtime' =E2=86=92 (localtime 1)(rtc_timeosset 0). On re= adback that=20 will be returned as clock/@offset=3D'variable'! 4. For Xen-HV-domUs with (localtime=3D1)(rtc_timeoffset=E2=89=A00) print a = warning that=20 there is no mapping to libvirts XML. 5. Always put the (localtime)(rtc_offset)-SEXPRs in "(image ({linux,hvm})",= =20 since this is where Xend-3.4 and Xend-4.1 return them. I also checked Xen-3.2, where this is okay, but the I don't have any older= =20 versions of Xen available (and running), the I can't verify that it still=20 works there. Which leads me to a another question: Which versions of Xen are still=20 supported by libvirt (and must be checked for regressions)? I don't want so= =20 actively remove the code for old Xen versions, but it gets harder and harde= r=20 to maintain all those versions. So a statement like "Xen-3.x and Xen-4.y ar= e=20 actively supported by libvirt-0.a.b; older versions might still work (by=20 accident ;-)" Before I forward-port that change to 0.9.10 I'd like to get some comments.= =20 Thanks in advance. Sincerely Philipp Hahn =2D-=20 Philipp Hahn Open Source Software Engineer hahn@univention.de Univention GmbH Linux for Your Business fon: +49 421 22 232- 0 Mary-Somerville-Str.1 D-28359 Bremen fax: +49 421 22 232-99 http://www.univention.de/ --Boundary-01=_iJWDPu42lbAemiP Content-Type: text/x-diff; charset="iso-8859-15"; name="localtime.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="localtime.diff" diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c index 835c230..e112aa3 100644 =2D-- a/src/xen/xend_internal.c +++ b/src/xen/xend_internal.c @@ -903,7 +903,6 @@ xenDaemonListDomainsOld(virConnectPtr xend) * * Returns 0 for success, -1 (with errno) on error */ =2D int xenDaemonDomainCreateXML(virConnectPtr xend, const char *sexpr) { @@ -2148,7 +2147,6 @@ xenDaemonParseSxpr(virConnectPtr conn, } else def->onCrash =3D VIR_DOMAIN_LIFECYCLE_DESTROY; =20 =2D def->clock.offset =3D VIR_DOMAIN_CLOCK_OFFSET_UTC; if (hvm) { if (sexpr_int(root, "domain/image/hvm/acpi")) def->features |=3D (1 << VIR_DOMAIN_FEATURE_ACPI); @@ -2157,15 +2155,18 @@ xenDaemonParseSxpr(virConnectPtr conn, if (sexpr_int(root, "domain/image/hvm/pae")) def->features |=3D (1 << VIR_DOMAIN_FEATURE_PAE); =20 =2D /* Old XenD only allows localtime here for HVM */ =2D if (sexpr_int(root, "domain/image/hvm/localtime")) + def->clock.offset =3D VIR_DOMAIN_CLOCK_OFFSET_VARIABLE; + def->clock.data.adjustment =3D sexpr_int(root, "domain/image/hvm/r= tc_timeoffset"); + if (def->clock.data.adjustment && sexpr_int(root, "domain/image/hv= m/localtime")) { + virXendError(VIR_ERR_INTERNAL_ERROR, _("Ignoring localtime=3D1= while rtc_timeoffset!=3D0")); + } + } else { /* !hvm */ + if (sexpr_int(root, "domain/image/linux/localtime")) def->clock.offset =3D VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME; + else + def->clock.offset =3D VIR_DOMAIN_CLOCK_OFFSET_UTC; } =20 =2D /* Current XenD allows localtime here, for PV and HVM */ =2D if (sexpr_int(root, "domain/localtime")) =2D def->clock.offset =3D VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME; =2D if (sexpr_node_copy(root, hvm ? "domain/image/hvm/device_model" : "domain/image/linux/device_model", @@ -5759,31 +5760,15 @@ xenDaemonFormatSxpr(virConnectPtr conn, } virBufferVSprintf(&buf, "(on_crash '%s')", tmp); =20 =2D /* Set localtime here for current XenD (both PV & HVM) */ =2D if (def->clock.offset =3D=3D VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME) { =2D if (def->clock.data.timezone) { =2D virXendError(VIR_ERR_CONFIG_UNSUPPORTED, =2D "%s", _("configurable timezones are not support= ed")); =2D goto error; =2D } + if (STREQ(def->os.type, "hvm")) + hvm =3D 1; =20 =2D virBufferAddLit(&buf, "(localtime 1)"); =2D } else if (def->clock.offset !=3D VIR_DOMAIN_CLOCK_OFFSET_UTC) { =2D virXendError(VIR_ERR_CONFIG_UNSUPPORTED, =2D _("unsupported clock offset '%s'"), =2D virDomainClockOffsetTypeToString(def->clock.offset)= ); =2D goto error; =2D } + if (hvm) + virBufferAddLit(&buf, "(image (hvm "); + else + virBufferAddLit(&buf, "(image (linux "); =20 if (!def->os.bootloader) { =2D if (STREQ(def->os.type, "hvm")) =2D hvm =3D 1; =2D =2D if (hvm) =2D virBufferAddLit(&buf, "(image (hvm "); =2D else =2D virBufferAddLit(&buf, "(image (linux "); =2D if (hvm && def->os.loader =3D=3D NULL) { virXendError(VIR_ERR_INTERNAL_ERROR, @@ -5893,17 +5878,13 @@ xenDaemonFormatSxpr(virConnectPtr conn, virBufferAddLit(&buf, "(serial none)"); } =20 =2D /* Set localtime here to keep old XenD happy for HVM */ =2D if (def->clock.offset =3D=3D VIR_DOMAIN_CLOCK_OFFSET_LOCALTI= ME) =2D virBufferAddLit(&buf, "(localtime 1)"); =2D if (def->sounds) { virBufferAddLit(&buf, "(soundhw '"); if (xenDaemonFormatSxprSound(def, &buf) < 0) goto error; virBufferAddLit(&buf, "')"); } =2D } + } /* hvm */ =20 /* get the device emulation model */ if (def->emulator && (hvm || xendConfigVersion >=3D 3)) @@ -5918,10 +5899,37 @@ xenDaemonFormatSxpr(virConnectPtr conn, &buf, xendConfigVersion) < = 0) goto error; } + } /* os.bootloader */ + + if (hvm) { + /* Set localtime here to keep old XenD happy for HVM */ + if (def->clock.offset =3D=3D VIR_DOMAIN_CLOCK_OFFSET_VARIABLE) { + virBufferVSprintf(&buf, "(localtime 0)(rtc_timeoffset %d)", de= f->clock.data.adjustment); + } else if (def->clock.offset =3D=3D VIR_DOMAIN_CLOCK_OFFSET_LOCALT= IME) { + if (def->clock.data.timezone) { + virXendError(VIR_ERR_CONFIG_UNSUPPORTED, + "%s", _("configurable timezones are not suppo= rted")); + goto error; + } =20 =2D virBufferAddLit(&buf, "))"); + virBufferAddLit(&buf, "(localtime 1)(rtc_timeoffset 0)"); + } else if (def->clock.offset =3D=3D VIR_DOMAIN_CLOCK_OFFSET_UTC) { + virBufferAddLit(&buf, "(localtime 0)(rtc_timeoffset 0)"); + } else { + virXendError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unsupported clock offset '%s'"), + virDomainClockOffsetTypeToString(def->clock.offse= t)); + goto error; + } + } else { /* !hvm */ + if (def->clock.offset =3D=3D VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME) + virBufferAddLit(&buf, "(localtime 1)"); + else if (def->clock.offset =3D=3D VIR_DOMAIN_CLOCK_OFFSET_UTC) + virBufferAddLit(&buf, "(localtime 0)"); } =20 + virBufferAddLit(&buf, "))"); /* image/{kvm,linux}/ */ + for (i =3D 0 ; i < def->ndisks ; i++) if (xenDaemonFormatSxprDisk(conn, def->disks[i], &buf, hvm, xendConfigVersion, 0) < 0) --Boundary-01=_iJWDPu42lbAemiP-- --nextPart1364855.lg51dqPocx Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEABECAAYFAk8NYmIACgkQYPlgoZpUDjkxCACgoeZ/J6dEOk6bt8H13Zf6uz2l Bt0An2dy19TrrvtDu0IGZa3F3yCKCbVs =dp1P -----END PGP SIGNATURE----- --nextPart1364855.lg51dqPocx-- --===============3066580839774506476== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline --===============3066580839774506476==--