From 67c346b1029cbbd39425fcd707b0bef181a1a7bc Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Mon, 16 Jul 2007 21:30:30 +0000 Subject: [PATCH] Added new element in XML for choosing utc/localtime --- ChangeLog | 13 ++++ docs/format.html | 8 +++ docs/libvir.html | 8 +++ src/qemu_conf.c | 22 +++++++ src/qemu_conf.h | 1 + src/xend_internal.c | 5 ++ src/xm_internal.c | 15 +++++ src/xml.c | 5 ++ .../sexpr2xml-fv-localtime.sexpr | 1 + .../sexpr2xmldata/sexpr2xml-fv-localtime.xml | 38 +++++++++++ tests/sexpr2xmldata/sexpr2xml-fv-utc.sexpr | 1 + tests/sexpr2xmldata/sexpr2xml-fv-utc.xml | 38 +++++++++++ tests/sexpr2xmldata/sexpr2xml-fv-v2.xml | 1 + tests/sexpr2xmldata/sexpr2xml-fv.xml | 1 + .../sexpr2xml-no-source-cdrom.xml | 1 + tests/sexpr2xmltest.c | 32 +++++++-- .../xmconfigdata/test-fullvirt-localtime.cfg | 23 +++++++ .../xmconfigdata/test-fullvirt-localtime.xml | 40 +++++++++++ .../xmconfigdata/test-fullvirt-new-cdrom.cfg | 1 + .../xmconfigdata/test-fullvirt-new-cdrom.xml | 1 + .../xmconfigdata/test-fullvirt-old-cdrom.cfg | 1 + .../xmconfigdata/test-fullvirt-old-cdrom.xml | 1 + tests/xmconfigdata/test-fullvirt-utc.cfg | 23 +++++++ tests/xmconfigdata/test-fullvirt-utc.xml | 40 +++++++++++ tests/xmconfigtest.c | 66 ++++++++++++++----- .../xml2sexpr-fv-localtime.sexpr | 1 + .../xml2sexprdata/xml2sexpr-fv-localtime.xml | 37 +++++++++++ tests/xml2sexprdata/xml2sexpr-fv-utc.sexpr | 1 + tests/xml2sexprdata/xml2sexpr-fv-utc.xml | 37 +++++++++++ tests/xml2sexprtest.c | 22 +++++++ 30 files changed, 464 insertions(+), 20 deletions(-) create mode 100644 tests/sexpr2xmldata/sexpr2xml-fv-localtime.sexpr create mode 100644 tests/sexpr2xmldata/sexpr2xml-fv-localtime.xml create mode 100644 tests/sexpr2xmldata/sexpr2xml-fv-utc.sexpr create mode 100644 tests/sexpr2xmldata/sexpr2xml-fv-utc.xml create mode 100755 tests/xmconfigdata/test-fullvirt-localtime.cfg create mode 100644 tests/xmconfigdata/test-fullvirt-localtime.xml create mode 100755 tests/xmconfigdata/test-fullvirt-utc.cfg create mode 100644 tests/xmconfigdata/test-fullvirt-utc.xml create mode 100644 tests/xml2sexprdata/xml2sexpr-fv-localtime.sexpr create mode 100644 tests/xml2sexprdata/xml2sexpr-fv-localtime.xml create mode 100644 tests/xml2sexprdata/xml2sexpr-fv-utc.sexpr create mode 100644 tests/xml2sexprdata/xml2sexpr-fv-utc.xml diff --git a/ChangeLog b/ChangeLog index 8436b086aa..ce32e2b848 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +Mon Jul 16 16:59:24 EST 2007 Daniel P. Berrange + + * src/qemu_conf.c, src/qemu_conf.h, src/xend_internal.c, + src/xm_internal.c, src/xml.c: Added support for the + element to switch between UTC and localtime in guests + * tests/sexpr2xmltest.c, tests/xmconfigtest.c, + tests/xml2sexprtest.c, tests/sexpr2xmldata/*, + tests/xml2sexprdata/*, tests/xmconfigdata/*: Added test + cases for new element, and adapted existing expected + data files where needed. + * docs/libvir.html, docs/format.html: Added docs about the + new element + Fri Jul 13 14:25:16 CEST 2007 Daniel Veillard * src/xml.c: applied modified patch from Masayuki Sunou for diff --git a/docs/format.html b/docs/format.html index e2f0446b25..059ec7e820 100644 --- a/docs/format.html +++ b/docs/format.html @@ -117,6 +117,7 @@ systems:

<domain type='xen' id='3'>
      <acpi/>
      <apic/>
   </features>
+  <clock sync="localtime"/>
   <devices>
     <emulator>/usr/lib/xen/bin/qemu-dm</emulator>
     <interface type='bridge'>
@@ -146,6 +147,11 @@ systems:

<domain type='xen' id='3'>
       
  • apic - enable IO APIC
  • acpi - enable ACPI bios
  • +
  • the optional <clock> element is used to specify + whether the emulated BIOS clock in the guest is synced to either + localtime or utc. In general Windows will + want localtime while all other operating systems will + want utc. The default is thus utc
  • the <os> block description is very different, first it indicates that the type is 'hvm' for hardware virtualization, then instead of a kernel, boot and command line arguments, it points to an os @@ -194,6 +200,7 @@ XML description is quite similar, here is a simple example:

    <domain <
       <os>
         <type>hvm</type>
       </os>
    +  <clock sync="localtime"/>
       <devices>
         <emulator>/home/user/usr/kvm-devel/bin/qemu-system-x86_64</emulator>
         <disk type='file' device='disk'>
    @@ -206,6 +213,7 @@ XML description is quite similar, here is a simple example:

    <domain <
         <graphics type='vnc' port='-1'/>
       </devices>
     </domain>

    The specific points to note if using KVM are:

    • the top level domain element carries a type of 'kvm'
    • +
    • the <clock> optional is supported as with Xen HVM
    • the <devices> emulator points to the special qemu binary required for KVM
    • networking interface definitions definitions are somewhat different due diff --git a/docs/libvir.html b/docs/libvir.html index 0a64973aa4..11b7132edd 100644 --- a/docs/libvir.html +++ b/docs/libvir.html @@ -738,6 +738,7 @@ systems:

      <acpi/> <apic/> </features> + <clock sync="localtime"/> <devices> <emulator>/usr/lib/xen/bin/qemu-dm</emulator> <interface type='bridge'> @@ -773,6 +774,11 @@ systems:

    • acpi - enable ACPI bios
  • +
  • the optional <clock> element is used to specify + whether the emulated BIOS clock in the guest is synced to either + localtime or utc. In general Windows will + want localtime while all other operating systems will + want utc. The default is thus utc
  • the <os> block description is very different, first it indicates that the type is 'hvm' for hardware virtualization, then instead of a kernel, boot and command line arguments, it points to an os @@ -832,6 +838,7 @@ XML description is quite similar, here is a simple example:

    <os> <type>hvm</type> </os> + <clock sync="localtime"/> <devices> <emulator>/home/user/usr/kvm-devel/bin/qemu-system-x86_64</emulator> <disk type='file' device='disk'> @@ -848,6 +855,7 @@ XML description is quite similar, here is a simple example:

    The specific points to note if using KVM are:

    • the top level domain element carries a type of 'kvm'
    • +
    • the <clock> optional is supported as with Xen HVM
    • the <devices> emulator points to the special qemu binary required for KVM
    • networking interface definitions definitions are somewhat different due diff --git a/src/qemu_conf.c b/src/qemu_conf.c index 6481a4568f..666c3aeaac 100644 --- a/src/qemu_conf.c +++ b/src/qemu_conf.c @@ -967,6 +967,20 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn, if (obj) xmlXPathFreeObject(obj); + /* See if we set clock to localtime */ + obj = xmlXPathEval(BAD_CAST "string(/domain/clock/@offset)", ctxt); + if ((obj == NULL) || (obj->type != XPATH_STRING) || + (obj->stringval == NULL) || (obj->stringval[0] == 0)) { + def->localtime = 0; + } else { + if (!strcmp((char*)obj->stringval, "localtime")) + def->localtime = 1; + else + def->localtime = 0; + } + if (obj) + xmlXPathFreeObject(obj); + /* Extract OS type info */ obj = xmlXPathEval(BAD_CAST "string(/domain/os/type[1])", ctxt); @@ -1338,6 +1352,7 @@ int qemudBuildCommandLine(virConnectPtr conn, 2 + /* cpus */ 2 + /* boot device */ 2 + /* monitor */ + (vm->def->localtime ? 1 : 0) + /* localtime */ (driver->qemuCmdFlags & QEMUD_CMD_FLAG_NO_REBOOT && vm->def->noReboot ? 1 : 0) + /* no-reboot */ (vm->def->features & QEMUD_FEATURE_ACPI ? 0 : 1) + /* acpi */ @@ -1376,6 +1391,11 @@ int qemudBuildCommandLine(virConnectPtr conn, if (!((*argv)[++n] = strdup("pty"))) goto no_memory; + if (vm->def->localtime) { + if (!((*argv)[++n] = strdup("-localtime"))) + goto no_memory; + } + if (driver->qemuCmdFlags & QEMUD_CMD_FLAG_NO_REBOOT && vm->def->noReboot) { if (!((*argv)[++n] = strdup("-no-reboot"))) @@ -2623,6 +2643,8 @@ char *qemudGenerateXML(virConnectPtr conn, goto no_memory; } + virBufferVSprintf(buf, " \n", def->localtime ? "localtime" : "utc"); + if (virBufferAdd(buf, " destroy\n", -1) < 0) goto no_memory; if (def->noReboot) { diff --git a/src/qemu_conf.h b/src/qemu_conf.h index 969a2f0525..ed5df987be 100644 --- a/src/qemu_conf.h +++ b/src/qemu_conf.h @@ -164,6 +164,7 @@ struct qemud_vm_def { struct qemud_vm_os_def os; + int localtime; int features; int graphicsType; int vncPort; diff --git a/src/xend_internal.c b/src/xend_internal.c index 14c6f58627..bf9ac208d5 100644 --- a/src/xend_internal.c +++ b/src/xend_internal.c @@ -1442,6 +1442,8 @@ xend_parse_sexp_desc(virConnectPtr conn, struct sexpr *root, int xendConfigVersi virBufferVSprintf(&buf, " %s\n", tmp); if (hvm) { + int clockLocal; + virBufferAdd(&buf, " \n", 13); if (sexpr_int(root, "domain/image/hvm/acpi")) virBufferAdd(&buf, " \n", 12); @@ -1450,6 +1452,9 @@ xend_parse_sexp_desc(virConnectPtr conn, struct sexpr *root, int xendConfigVersi if (sexpr_int(root, "domain/image/hvm/pae")) virBufferAdd(&buf, " \n", 11); virBufferAdd(&buf, " \n", 14); + + clockLocal = sexpr_int(root, "domain/image/hvm/localtime"); + virBufferVSprintf(&buf, " \n", clockLocal ? "localtime" : "utc"); } virBufferAdd(&buf, " \n", 12); diff --git a/src/xm_internal.c b/src/xm_internal.c index 803d5f893e..c8fc1e35e1 100644 --- a/src/xm_internal.c +++ b/src/xm_internal.c @@ -708,6 +708,10 @@ char *xenXMDomainFormatXML(virConnectPtr conn, virConfPtr conf) { val) virBufferAdd(buf, " \n", -1); virBufferAdd(buf, " \n", -1); + + if (xenXMConfigGetInt(conf, "localtime", &val) < 0) + val = 0; + virBufferVSprintf(buf, " \n", val ? "localtime" : "utc"); } virBufferAdd(buf, " \n", -1); @@ -1812,6 +1816,7 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml) { if (hvm) { const char *boot = "c"; + int clockLocal = 0; if (xenXMConfigSetString(conf, "builder", "hvm") < 0) goto error; @@ -1845,6 +1850,16 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml) { "cannot set the apic parameter") < 0) goto error; + obj = xmlXPathEval(BAD_CAST "string(/domain/clock/@offset)", ctxt); + if ((obj != NULL) && (obj->type == XPATH_STRING) && + (obj->stringval != NULL)) { + if (!strcmp((const char*)obj->stringval, "localtime")) + clockLocal = 1; + } + xmlXPathFreeObject(obj); + if (xenXMConfigSetInt(conf, "localtime", clockLocal) < 0) + goto error; + if (priv->xendConfigVersion == 1) { if (xenXMConfigSetStringFromXPath(conn, conf, ctxt, "cdrom", "string(/domain/devices/disk[@device='cdrom']/source/@file)", 1, "cannot set the cdrom parameter") < 0) diff --git a/src/xml.c b/src/xml.c index 5337598dcb..ae3c0cb359 100644 --- a/src/xml.c +++ b/src/xml.c @@ -562,6 +562,11 @@ virDomainParseXMLOSDescHVM(virConnectPtr conn, xmlNodePtr node, virBufferPtr buf } } + str = virXPathString("string(/domain/clock/@offset)", ctxt); + if (str != NULL && !strcmp(str, "localtime")) { + virBufferAdd(buf, "(localtime 1)", 13); + } + virBufferAdd(buf, "))", 2); return (0); diff --git a/tests/sexpr2xmldata/sexpr2xml-fv-localtime.sexpr b/tests/sexpr2xmldata/sexpr2xml-fv-localtime.sexpr new file mode 100644 index 0000000000..1668e15b31 --- /dev/null +++ b/tests/sexpr2xmldata/sexpr2xml-fv-localtime.sexpr @@ -0,0 +1 @@ +(domain (domid 3)(name 'fvtest')(memory 400)(maxmem 400)(vcpus 1)(uuid 'b5d70dd275cdaca517769660b059d8bc')(on_poweroff 'destroy')(on_reboot 'restart')(on_crash 'restart')(image (hvm (kernel '/usr/lib/xen/boot/hvmloader')(device_model '/usr/lib64/xen/bin/qemu-dm')(boot c)(cdrom '/root/boot.iso')(acpi 1)(vnc 1)(keymap ja)(localtime 1)))(device (vbd (dev 'ioemu:hda')(uname 'file:/root/foo.img')(mode 'w')))(device (vif (mac '00:16:3e:1b:b1:47')(bridge 'xenbr0')(script 'vif-bridge')(type ioemu)))) diff --git a/tests/sexpr2xmldata/sexpr2xml-fv-localtime.xml b/tests/sexpr2xmldata/sexpr2xml-fv-localtime.xml new file mode 100644 index 0000000000..512580eb6a --- /dev/null +++ b/tests/sexpr2xmldata/sexpr2xml-fv-localtime.xml @@ -0,0 +1,38 @@ + + fvtest + b5d70dd275cdaca517769660b059d8bc + + hvm + /usr/lib/xen/boot/hvmloader + + + 409600 + 1 + destroy + restart + restart + + + + + + /usr/lib64/xen/bin/qemu-dm + + + + + + + + +