Re: [libvirt] [PATCH 2/6] Add new clock mode allowing variable adjustments

2010-03-01 Thread Jim Meyering
Daniel P. Berrange wrote:
>> Here's the change to the syntax-check rule,
>> followed by the change to the code to make those files comply.
>> If everyone agrees, I'll reverse the order before pushing,
>> so that make syntax-check passes after each commit.
>
> ACK, this makes sense - since we clearly keep re-introducing tabs
> in these files.

Thanks for the quick ACK.
Pushed.

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 2/6] Add new clock mode allowing variable adjustments

2010-03-01 Thread Daniel P. Berrange
On Mon, Mar 01, 2010 at 08:12:23PM +0100, Jim Meyering wrote:
> Daniel P. Berrange wrote:
> ...
> >> > diff --git a/docs/schemas/domain.rng b/docs/schemas/domain.rng
> >> > index 1ff0944..d295bfe 100644
> >> > --- a/docs/schemas/domain.rng
> >> > +++ b/docs/schemas/domain.rng
> >> > @@ -297,12 +297,24 @@
> >> >
> >> >  
> >> >
> >> > -
> >> > -  
> >> > +
> >> > +  
> >>
> >>   hum isn't that inserting tabs in the XML that we remove from time to
> >>   time :-) ?
> >
> > Hmm, our syntax-check only seems to validate no-TABS for source
> > code files, not schemas/docs
> 
> Here's the change to the syntax-check rule,
> followed by the change to the code to make those files comply.
> If everyone agrees, I'll reverse the order before pushing,
> so that make syntax-check passes after each commit.

ACK, this makes sense - since we clearly keep re-introducing tabs
in these files.

Daniel
-- 
|: Red Hat, Engineering, London-o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :|
|: http://autobuild.org-o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 2/6] Add new clock mode allowing variable adjustments

2010-03-01 Thread Jim Meyering
Daniel P. Berrange wrote:
...
>> > diff --git a/docs/schemas/domain.rng b/docs/schemas/domain.rng
>> > index 1ff0944..d295bfe 100644
>> > --- a/docs/schemas/domain.rng
>> > +++ b/docs/schemas/domain.rng
>> > @@ -297,12 +297,24 @@
>> >
>> >  
>> >
>> > -
>> > -  
>> > +  
>> > +  
>>
>>   hum isn't that inserting tabs in the XML that we remove from time to
>>   time :-) ?
>
> Hmm, our syntax-check only seems to validate no-TABS for source
> code files, not schemas/docs

Here's the change to the syntax-check rule,
followed by the change to the code to make those files comply.
If everyone agrees, I'll reverse the order before pushing,
so that make syntax-check passes after each commit.

>From a5a73e3ec03deed1e411b05e3e32ef4194acbf16 Mon Sep 17 00:00:00 2001
From: Jim Meyering 
Date: Mon, 1 Mar 2010 20:05:06 +0100
Subject: [PATCH 1/2] maint: disallow TAB-in-indentation also in *.rng files

* cfg.mk (sc_TAB_in_indentation): Also check .rng files.
---
 cfg.mk |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/cfg.mk b/cfg.mk
index 8317ae2..680c312 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -132,7 +132,7 @@ sc_prohibit_ctype_h:
 sc_TAB_in_indentation:
@grep -lE '^ *  ' /dev/null \
 $$($(VC_LIST_EXCEPT)   \
-   | grep -E '\.[ch](\.in)?$$' \
+   | grep -E '\.(rng|[ch](\.in)?)$$'   \
| grep -v '^gnulib/') &&\
  { echo '$(ME): found TAB(s) used for indentation in C sources;'\
  'use spaces' 1>&2; exit 1; } || :
--
1.7.0.1.414.g89213d


>From 87e8002f2f18a0295f2c2dd7c39c5e937585ffea Mon Sep 17 00:00:00 2001
From: Jim Meyering 
Date: Mon, 1 Mar 2010 20:09:26 +0100
Subject: [PATCH 2/2] maint: convert leading TABs in *.rng files to equivalent 
spaces

* docs/schemas/capability.rng: Likewise.
* docs/schemas/network.rng: Likewise.
* docs/schemas/nodedev.rng: Likewise.
* docs/schemas/storagepool.rng: Likewise.
* docs/schemas/storagevol.rng: Likewise.
Use these commands:
t=$'\t'
git ls-files | grep '\.rng$' | xargs grep -lE "^ *$t" \
  | xargs perl -MText::Tabs -ni -le \
'$m=/^( *\t[ \t]*)(.*)/; print $m ? expand($1) . $2 : $_'
---
 docs/schemas/capability.rng  |  188 +-
 docs/schemas/network.rng |   16 ++--
 docs/schemas/nodedev.rng |   94 +++---
 docs/schemas/storagepool.rng |  172 +++---
 docs/schemas/storagevol.rng  |   88 ++--
 5 files changed, 279 insertions(+), 279 deletions(-)

diff --git a/docs/schemas/capability.rng b/docs/schemas/capability.rng
index 378652e..eb3c50a 100644
--- a/docs/schemas/capability.rng
+++ b/docs/schemas/capability.rng
@@ -11,7 +11,7 @@
   

   
-   
+
   
 
   
@@ -19,24 +19,24 @@
   
 
   
-   
- 
-   
-   
- 
-   
-   
- 
-   
+
+  
+
+
+  
+
+
+  
+
   
   
-   
+
   
   
-   
+
   
   
-   
+
   
 
   
@@ -56,16 +56,16 @@
   
 
   
-   
+
   
   
-   
+
   
   
-   
+
   
   
-   
+
   
 
   
@@ -98,22 +98,22 @@
   
 
   
-   
- 
-   
+
+  
+
   
   
-   
- 
-   
- 
-   esx
-   tcp
-   xenmigr
- 
-   
- 
-   
+
+  
+
+  
+esx
+tcp
+xenmigr
+  
+
+  
+
   
 
   
@@ -121,12 +121,12 @@
   
 
   
-   
- 
-   
-   
- 
-   
+
+  
+
+
+  
+
   
 
   
@@ -134,18 +134,18 @@
   
 
   
-   
+
   

   
-   
- 
-   
- 
- 
-   
- 
-   
+
+  
+
+  
+  
+
+  
+
   
 
   
@@ -153,7 +153,7 @@
   
 
   
-   
+
   
 
   
@@ -163,7 +163,7 @@
   
   
   
-   
+
   
 
   
@@ -171,11 +171,11 @@
   
 
   
-   xen 
-   linux 
-   hvm 
-   exe 
-   uml 
+xen 
+linux 
+hvm 
+exe 
+uml 
   
 
   
@@ -183,20 +183,20 @@
   
 
   
-   
+
   
   
   
-   
+
   
   
-   
+
   
   
-   
+
   
   
-   
+
   
 
   
@@ -216,9 +216,9 @@
  

Re: [libvirt] [PATCH 2/6] Add new clock mode allowing variable adjustments

2010-03-01 Thread Daniel P. Berrange
On Mon, Mar 01, 2010 at 03:02:06PM +0100, Daniel Veillard wrote:
> On Thu, Feb 18, 2010 at 05:54:28PM +, Daniel P. Berrange wrote:
> > This introduces a third option for clock offset synchronization,
> > that allows an arbitrary / variable adjustment to be set. In
> > essence the XML contains the time delta in seconds, relative to
> > UTC.
> > 
> >   
> > 
> > The difference from 'utc' mode, is that management apps should
> > track adjustments and preserve them at next reboot.
> 
>   hum ... if the management layer start to track time of delta w.r.t.
> UTC as defined by node clock, I also assume they manage the variations
> in clock when migrating too (or that the nodes clocks are actually
> properly sync'ed).

libvirt would be responsible for doing the right thing during
migration - its only the persistent config on disk that apps
are responsible for.

> 
> > * docs/schemas/domain.rng: Schema for new clock mode
> > * src/conf/domain_conf.c, src/conf/domain_conf.h: Parse
> >   new clock time delta
> > * src/libvirt_private.syms, src/util/xml.c, src/util/xml.h: Add
> >   virXPathLongLong() method
> > ---
> >  docs/schemas/domain.rng  |   25 +---
> >  src/conf/domain_conf.c   |   18 +-
> >  src/conf/domain_conf.h   |5 
> >  src/libvirt_private.syms |1 +
> >  src/util/xml.c   |   54 
> > ++
> >  src/util/xml.h   |5 +++-
> >  6 files changed, 101 insertions(+), 7 deletions(-)
> > 
> > diff --git a/docs/schemas/domain.rng b/docs/schemas/domain.rng
> > index 1ff0944..d295bfe 100644
> > --- a/docs/schemas/domain.rng
> > +++ b/docs/schemas/domain.rng
> > @@ -297,12 +297,24 @@
> >
> >  
> >
> > -
> > -  
> > +   
> > +  
> 
>   hum isn't that inserting tabs in the XML that we remove from time to
>   time :-) ?

Hmm, our syntax-check only seems to validate no-TABS for source
code files, not schemas/docs

> 
> >  localtime
> > + 
> > +  
> >  utc
> > -  
> > -
> > + 
> > + 
> > +
> > +  variable
> > +   
> > +   
> > + 
> > +   
> > + 
> > +   
> > + 
> > +   
> >  
> >
> >  
> > @@ -1567,4 +1579,9 @@
> >[a-zA-Z0-9\-_]+
> >  
> >
> > +  
> > +
> 
>   actually we could use XSD integer there
> http://www.w3.org/TR/xmlschema-2/#integer
> but this won't change much
> 
> > +  (-|\+)?[0-9]+
> > +
> > +  
> >  
> > diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> > index f86b4eb..49d5d19 100644
> > --- a/src/conf/domain_conf.c
> > +++ b/src/conf/domain_conf.c
> > @@ -231,7 +231,8 @@ VIR_ENUM_IMPL(virDomainNetdevMacvtap, 
> > VIR_DOMAIN_NETDEV_MACVTAP_MODE_LAST,
> >  
> >  VIR_ENUM_IMPL(virDomainClockOffset, VIR_DOMAIN_CLOCK_OFFSET_LAST,
> >"utc",
> > -  "localtime");
> > +  "localtime",
> > +  "variable");
> >  
> >  #define virDomainReportError(code, fmt...)   \
> >  virReportErrorHelper(NULL, VIR_FROM_DOMAIN, code, __FILE__,  \
> > @@ -3492,6 +3493,13 @@ static virDomainDefPtr 
> > virDomainDefParseXML(virCapsPtr caps,
> >  } else {
> >  def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_UTC;
> >  }
> > +switch (def->clock.offset) {
> > +case VIR_DOMAIN_CLOCK_OFFSET_VARIABLE:
> > +if (virXPathLongLong("./clock/@adjustment", ctxt,
> > + &def->clock.adjustment) < 0)
> > +def->clock.adjustment = 0;
> 
>Hum, should probably give an error message here 
> 
> > +break;
> > +}
> >  
> >  def->os.bootloader = virXPathString("string(./bootloader)", ctxt);
> >  def->os.bootloaderArgs = virXPathString("string(./bootloader_args)", 
> > ctxt);
> > @@ -5399,8 +5407,14 @@ char *virDomainDefFormat(virDomainDefPtr def,
> >  if (virCPUDefFormatBuf(&buf, def->cpu, "  ", 0) < 0)
> >  goto cleanup;
> >  
> > -virBufferVSprintf(&buf, "  \n",
> > +virBufferVSprintf(&buf, "   >virDomainClockOffsetTypeToString(def->clock.offset));
> > +switch (def->clock.offset) {
> > +case VIR_DOMAIN_CLOCK_OFFSET_VARIABLE:
> > +virBufferVSprintf(&buf, " adjustment='%lld'", 
> > def->clock.adjustment);
> > +break;
> > +}
> > +virBufferAddLit(&buf, "/>\n");
> >  
> >  if (virDomainLifecycleDefFormat(&buf, def->onPoweroff,
> >  "on_poweroff") < 0)
> > diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
> > index fbbe683..f5fe016 100644
> > --- a/src/conf/domain_conf.h
> > +++ b/src/conf/domain_conf.h
> > @@ -612,6 +612,7 @@ struct _virSecurityLabelDef {
> >  enum virDomainClockOffsetType {
> >  VIR_DOMAIN_CLOCK_OFFSET_UTC = 0,
> >  VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME = 1,
> > +VIR_DOMAIN_CLOCK_OFFSET_VARIABLE = 2,
> >  
> >  VIR

Re: [libvirt] [PATCH 2/6] Add new clock mode allowing variable adjustments

2010-03-01 Thread Daniel Veillard
On Thu, Feb 18, 2010 at 05:54:28PM +, Daniel P. Berrange wrote:
> This introduces a third option for clock offset synchronization,
> that allows an arbitrary / variable adjustment to be set. In
> essence the XML contains the time delta in seconds, relative to
> UTC.
> 
>   
> 
> The difference from 'utc' mode, is that management apps should
> track adjustments and preserve them at next reboot.

  hum ... if the management layer start to track time of delta w.r.t.
UTC as defined by node clock, I also assume they manage the variations
in clock when migrating too (or that the nodes clocks are actually
properly sync'ed).

> * docs/schemas/domain.rng: Schema for new clock mode
> * src/conf/domain_conf.c, src/conf/domain_conf.h: Parse
>   new clock time delta
> * src/libvirt_private.syms, src/util/xml.c, src/util/xml.h: Add
>   virXPathLongLong() method
> ---
>  docs/schemas/domain.rng  |   25 +---
>  src/conf/domain_conf.c   |   18 +-
>  src/conf/domain_conf.h   |5 
>  src/libvirt_private.syms |1 +
>  src/util/xml.c   |   54 
> ++
>  src/util/xml.h   |5 +++-
>  6 files changed, 101 insertions(+), 7 deletions(-)
> 
> diff --git a/docs/schemas/domain.rng b/docs/schemas/domain.rng
> index 1ff0944..d295bfe 100644
> --- a/docs/schemas/domain.rng
> +++ b/docs/schemas/domain.rng
> @@ -297,12 +297,24 @@
>
>  
>
> -
> -  
> + 
> +  

  hum isn't that inserting tabs in the XML that we remove from time to
  time :-) ?

>  localtime
> +   
> +  
>  utc
> -  
> -
> +   
> +   
> +
> +  variable
> + 
> + 
> +   
> + 
> +   
> + 
> +   
> + 
>  
>
>  
> @@ -1567,4 +1579,9 @@
>[a-zA-Z0-9\-_]+
>  
>
> +  
> +

  actually we could use XSD integer there
http://www.w3.org/TR/xmlschema-2/#integer
but this won't change much

> +  (-|\+)?[0-9]+
> +
> +  
>  
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index f86b4eb..49d5d19 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -231,7 +231,8 @@ VIR_ENUM_IMPL(virDomainNetdevMacvtap, 
> VIR_DOMAIN_NETDEV_MACVTAP_MODE_LAST,
>  
>  VIR_ENUM_IMPL(virDomainClockOffset, VIR_DOMAIN_CLOCK_OFFSET_LAST,
>"utc",
> -  "localtime");
> +  "localtime",
> +  "variable");
>  
>  #define virDomainReportError(code, fmt...)   \
>  virReportErrorHelper(NULL, VIR_FROM_DOMAIN, code, __FILE__,  \
> @@ -3492,6 +3493,13 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr 
> caps,
>  } else {
>  def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_UTC;
>  }
> +switch (def->clock.offset) {
> +case VIR_DOMAIN_CLOCK_OFFSET_VARIABLE:
> +if (virXPathLongLong("./clock/@adjustment", ctxt,
> + &def->clock.adjustment) < 0)
> +def->clock.adjustment = 0;

   Hum, should probably give an error message here 

> +break;
> +}
>  
>  def->os.bootloader = virXPathString("string(./bootloader)", ctxt);
>  def->os.bootloaderArgs = virXPathString("string(./bootloader_args)", 
> ctxt);
> @@ -5399,8 +5407,14 @@ char *virDomainDefFormat(virDomainDefPtr def,
>  if (virCPUDefFormatBuf(&buf, def->cpu, "  ", 0) < 0)
>  goto cleanup;
>  
> -virBufferVSprintf(&buf, "  \n",
> +virBufferVSprintf(&buf, "  virDomainClockOffsetTypeToString(def->clock.offset));
> +switch (def->clock.offset) {
> +case VIR_DOMAIN_CLOCK_OFFSET_VARIABLE:
> +virBufferVSprintf(&buf, " adjustment='%lld'", def->clock.adjustment);
> +break;
> +}
> +virBufferAddLit(&buf, "/>\n");
>  
>  if (virDomainLifecycleDefFormat(&buf, def->onPoweroff,
>  "on_poweroff") < 0)
> diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
> index fbbe683..f5fe016 100644
> --- a/src/conf/domain_conf.h
> +++ b/src/conf/domain_conf.h
> @@ -612,6 +612,7 @@ struct _virSecurityLabelDef {
>  enum virDomainClockOffsetType {
>  VIR_DOMAIN_CLOCK_OFFSET_UTC = 0,
>  VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME = 1,
> +VIR_DOMAIN_CLOCK_OFFSET_VARIABLE = 2,
>  
>  VIR_DOMAIN_CLOCK_OFFSET_LAST,
>  };
> @@ -620,6 +621,10 @@ typedef struct _virDomainClockDef virDomainClockDef;
>  typedef virDomainClockDef *virDomainClockDefPtr;
>  struct _virDomainClockDef {
>  int offset;
> +
> +/* Adjustment in seconds, relative to UTC, when
> + * offset == VIR_DOMAIN_CLOCK_OFFSET_VARIABLE */
> +long long adjustment;
>  };
>  
>  #define VIR_DOMAIN_CPUMASK_LEN 1024
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index 1af34bd..41bde8e 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -

[libvirt] [PATCH 2/6] Add new clock mode allowing variable adjustments

2010-02-18 Thread Daniel P. Berrange
This introduces a third option for clock offset synchronization,
that allows an arbitrary / variable adjustment to be set. In
essence the XML contains the time delta in seconds, relative to
UTC.

  

The difference from 'utc' mode, is that management apps should
track adjustments and preserve them at next reboot.

* docs/schemas/domain.rng: Schema for new clock mode
* src/conf/domain_conf.c, src/conf/domain_conf.h: Parse
  new clock time delta
* src/libvirt_private.syms, src/util/xml.c, src/util/xml.h: Add
  virXPathLongLong() method
---
 docs/schemas/domain.rng  |   25 +---
 src/conf/domain_conf.c   |   18 +-
 src/conf/domain_conf.h   |5 
 src/libvirt_private.syms |1 +
 src/util/xml.c   |   54 ++
 src/util/xml.h   |5 +++-
 6 files changed, 101 insertions(+), 7 deletions(-)

diff --git a/docs/schemas/domain.rng b/docs/schemas/domain.rng
index 1ff0944..d295bfe 100644
--- a/docs/schemas/domain.rng
+++ b/docs/schemas/domain.rng
@@ -297,12 +297,24 @@
   
 
   
-
-  
+   
+  
 localtime
+ 
+  
 utc
-  
-
+ 
+ 
+
+  variable
+   
+   
+ 
+   
+ 
+   
+ 
+   
 
   
 
@@ -1567,4 +1579,9 @@
   [a-zA-Z0-9\-_]+
 
   
+  
+
+  (-|\+)?[0-9]+
+
+  
 
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index f86b4eb..49d5d19 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -231,7 +231,8 @@ VIR_ENUM_IMPL(virDomainNetdevMacvtap, 
VIR_DOMAIN_NETDEV_MACVTAP_MODE_LAST,
 
 VIR_ENUM_IMPL(virDomainClockOffset, VIR_DOMAIN_CLOCK_OFFSET_LAST,
   "utc",
-  "localtime");
+  "localtime",
+  "variable");
 
 #define virDomainReportError(code, fmt...)   \
 virReportErrorHelper(NULL, VIR_FROM_DOMAIN, code, __FILE__,  \
@@ -3492,6 +3493,13 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr 
caps,
 } else {
 def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_UTC;
 }
+switch (def->clock.offset) {
+case VIR_DOMAIN_CLOCK_OFFSET_VARIABLE:
+if (virXPathLongLong("./clock/@adjustment", ctxt,
+ &def->clock.adjustment) < 0)
+def->clock.adjustment = 0;
+break;
+}
 
 def->os.bootloader = virXPathString("string(./bootloader)", ctxt);
 def->os.bootloaderArgs = virXPathString("string(./bootloader_args)", ctxt);
@@ -5399,8 +5407,14 @@ char *virDomainDefFormat(virDomainDefPtr def,
 if (virCPUDefFormatBuf(&buf, def->cpu, "  ", 0) < 0)
 goto cleanup;
 
-virBufferVSprintf(&buf, "  \n",
+virBufferVSprintf(&buf, "  clock.offset));
+switch (def->clock.offset) {
+case VIR_DOMAIN_CLOCK_OFFSET_VARIABLE:
+virBufferVSprintf(&buf, " adjustment='%lld'", def->clock.adjustment);
+break;
+}
+virBufferAddLit(&buf, "/>\n");
 
 if (virDomainLifecycleDefFormat(&buf, def->onPoweroff,
 "on_poweroff") < 0)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index fbbe683..f5fe016 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -612,6 +612,7 @@ struct _virSecurityLabelDef {
 enum virDomainClockOffsetType {
 VIR_DOMAIN_CLOCK_OFFSET_UTC = 0,
 VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME = 1,
+VIR_DOMAIN_CLOCK_OFFSET_VARIABLE = 2,
 
 VIR_DOMAIN_CLOCK_OFFSET_LAST,
 };
@@ -620,6 +621,10 @@ typedef struct _virDomainClockDef virDomainClockDef;
 typedef virDomainClockDef *virDomainClockDefPtr;
 struct _virDomainClockDef {
 int offset;
+
+/* Adjustment in seconds, relative to UTC, when
+ * offset == VIR_DOMAIN_CLOCK_OFFSET_VARIABLE */
+long long adjustment;
 };
 
 #define VIR_DOMAIN_CPUMASK_LEN 1024
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 1af34bd..41bde8e 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -629,6 +629,7 @@ virXPathStringLimit;
 virXPathBoolean;
 virXPathNumber;
 virXPathULong;
+virXPathLongLong;
 virXPathULongLong;
 virXPathLongHex;
 virXPathULongHex;
diff --git a/src/util/xml.c b/src/util/xml.c
index 46ea9aa..14c8345 100644
--- a/src/util/xml.c
+++ b/src/util/xml.c
@@ -364,6 +364,60 @@ virXPathULongLong(const char *xpath,
 return (ret);
 }
 
+/**
+ * virXPathULongLong:
+ * @xpath: the XPath string to evaluate
+ * @ctxt: an XPath context
+ * @value: the returned long long value
+ *
+ * Convenience function to evaluate an XPath number
+ *
+ * Returns 0 in case of success in which case @value is set,
+ * or -1 if the XPath evaluation failed or -2 if the
+ * value doesn't have a long format.
+ */
+int
+virXPathLongLong(const char *xpath,
+ xmlXPathContextPtr ctxt,
+ long long *value)
+{
+xmlXPathO

[libvirt] [PATCH 2/6] Add new clock mode allowing variable adjustments

2010-02-02 Thread Daniel P. Berrange
This introduces a third option for clock offset synchronization,
that allows an arbitrary / variable adjustment to be set. In
essence the XML contains the time delta in seconds, relative to
UTC.

  

The difference from 'utc' mode, is that management apps should
track adjustments and preserve them at next reboot.

* docs/schemas/domain.rng: Schema for new clock mode
* src/conf/domain_conf.c, src/conf/domain_conf.h: Parse
  new clock time delta
* src/libvirt_private.syms, src/util/xml.c, src/util/xml.h: Add
  virXPathLongLong() method
---
 docs/schemas/domain.rng  |   25 +---
 src/conf/domain_conf.c   |   14 ++-
 src/conf/domain_conf.h   |5 
 src/libvirt_private.syms |1 +
 src/util/xml.c   |   55 ++
 src/util/xml.h   |4 +++
 6 files changed, 98 insertions(+), 6 deletions(-)

diff --git a/docs/schemas/domain.rng b/docs/schemas/domain.rng
index bb6d00d..5c48a8b 100644
--- a/docs/schemas/domain.rng
+++ b/docs/schemas/domain.rng
@@ -297,12 +297,24 @@
   
 
   
-
-  
+   
+  
 localtime
+ 
+  
 utc
-  
-
+ 
+ 
+
+  variable
+   
+   
+ 
+   
+ 
+   
+ 
+   
 
   
 
@@ -1526,4 +1538,9 @@
   [a-zA-Z0-9\-_]+
 
   
+  
+
+  (-|\+)?[0-9]+
+
+  
 
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 1daf6f4..0c502b9 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -224,7 +224,8 @@ VIR_ENUM_IMPL(virDomainSeclabel, VIR_DOMAIN_SECLABEL_LAST,
 
 VIR_ENUM_IMPL(virDomainClockOffset, VIR_DOMAIN_CLOCK_OFFSET_LAST,
   "utc",
-  "localtime");
+  "localtime",
+  "variable");
 
 
 #define virDomainReportError(conn, code, fmt...)   \
@@ -3479,6 +3480,11 @@ static virDomainDefPtr 
virDomainDefParseXML(virConnectPtr conn,
 } else {
 def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_UTC;
 }
+if (def->clock.offset == VIR_DOMAIN_CLOCK_OFFSET_VARIABLE) {
+if (virXPathLongLong(conn, "./clock/@adjustment", ctxt,
+ &def->clock.adjustment) < 0)
+def->clock.adjustment = 0;
+}
 
 def->os.bootloader = virXPathString(conn, "string(./bootloader)", ctxt);
 def->os.bootloaderArgs = virXPathString(conn, "string(./bootloader_args)", 
ctxt);
@@ -5419,8 +5425,12 @@ char *virDomainDefFormat(virConnectPtr conn,
 if (virCPUDefFormatBuf(conn, &buf, def->cpu, "  ", 0) < 0)
 goto cleanup;
 
-virBufferVSprintf(&buf, "  \n",
+virBufferVSprintf(&buf, "  clock.offset));
+if (def->clock.offset == VIR_DOMAIN_CLOCK_OFFSET_VARIABLE) {
+virBufferVSprintf(&buf, " adjustment='%lld'", def->clock.adjustment);
+}
+virBufferAddLit(&buf, "/>\n");
 
 if (virDomainLifecycleDefFormat(conn, &buf, def->onPoweroff,
 "on_poweroff") < 0)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 5653b18..4df28e5 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -597,6 +597,7 @@ struct _virSecurityLabelDef {
 enum virDomainClockOffsetType {
 VIR_DOMAIN_CLOCK_OFFSET_UTC = 0,
 VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME = 1,
+VIR_DOMAIN_CLOCK_OFFSET_VARIABLE = 2,
 
 VIR_DOMAIN_CLOCK_OFFSET_LAST,
 };
@@ -605,6 +606,10 @@ typedef struct _virDomainClockDef virDomainClockDef;
 typedef virDomainClockDef *virDomainClockDefPtr;
 struct _virDomainClockDef {
 int offset;
+
+/* Adjustment in seconds, relative to UTC, when
+ * offset == VIR_DOMAIN_CLOCK_OFFSET_VARIABLE */
+long long adjustment;
 };
 
 #define VIR_DOMAIN_CPUMASK_LEN 1024
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index e882ae4..39b7c45 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -625,6 +625,7 @@ virXPathStringLimit;
 virXPathBoolean;
 virXPathNumber;
 virXPathULong;
+virXPathLongLong;
 virXPathULongLong;
 virXPathLongHex;
 virXPathULongHex;
diff --git a/src/util/xml.c b/src/util/xml.c
index 4fa443d..52786d0 100644
--- a/src/util/xml.c
+++ b/src/util/xml.c
@@ -374,6 +374,61 @@ virXPathULongLong(virConnectPtr conn,
 return (ret);
 }
 
+/**
+ * virXPathULongLong:
+ * @xpath: the XPath string to evaluate
+ * @ctxt: an XPath context
+ * @value: the returned long long value
+ *
+ * Convenience function to evaluate an XPath number
+ *
+ * Returns 0 in case of success in which case @value is set,
+ * or -1 if the XPath evaluation failed or -2 if the
+ * value doesn't have a long format.
+ */
+int
+virXPathLongLong(virConnectPtr conn,
+ const char *xpath,
+ xmlXPathContextPtr ctxt,
+ long long *value)
+{
+xmlXPathObjectPtr obj;
+xmlNodePtr relnode;
+int ret = 0;
+
+if ((c