Skip to contentSkip to conversation

libxl: fix rtc_timeoffset setting

PATCH In review Lin Ming 2 participants 3 messages Apr 13, 2012 – Apr 24, 2012

lore
Share & tools
lore

Lin Ming

author
#0 lore raw

PATCH 1/1 libxl: fix rtc_timeoffset setting

libxl__domain_build_info_setdefault may be called several times, so rtc_timeoffset can't be setted in it.

Move rtc_timeoffset setting logic to libxl__build_pre.

---
 tools/libxl/libxl_create.c |    9 ---------
 tools/libxl/libxl_dom.c    |   17 +++++++++++++++--
 2 files changed, 15 insertions(+), 11 deletions(-)
tools/libxl/libxl_create.c +0 -9
index e63c7bd..e706124 100644
@@ -127,15 +127,6 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
         b_info->target_memkb = b_info->max_memkb;
 
     libxl_defbool_setdefault(&b_info->localtime, false);
-    if (libxl_defbool_val(b_info->localtime)) {
-        time_t t;
-        struct tm *tm;
-
-        t = time(NULL);
-        tm = localtime(&t);
-
-        b_info->rtc_timeoffset += tm->tm_gmtoff;
-    }
 
     libxl_defbool_setdefault(&b_info->disable_migrate, false);
 
tools/libxl/libxl_dom.c +15 -2
index 0bdd654..91c4bd8 100644
@@ -65,6 +65,8 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid,
     libxl_ctx *ctx = libxl__gc_owner(gc);
     int tsc_mode;
     char *xs_domid, *con_domid;
+    uint32_t rtc_timeoffset;
+
     xc_domain_max_vcpus(ctx->xch, domid, info->max_vcpus);
     libxl_set_vcpuaffinity_all(ctx, domid, info->max_vcpus, &info->cpumap);
     xc_domain_setmaxmem(ctx->xch, domid, info->target_memkb + LIBXL_MAXMEM_CONSTANT);
@@ -91,8 +93,19 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid,
     if (libxl_defbool_val(info->disable_migrate))
         xc_domain_disable_migrate(ctx->xch, domid);
 
-    if (info->rtc_timeoffset)
-        xc_domain_set_time_offset(ctx->xch, domid, info->rtc_timeoffset);
+    rtc_timeoffset = info->rtc_timeoffset;
+    if (libxl_defbool_val(info->localtime)) {
+        time_t t;
+        struct tm *tm;
+
+        t = time(NULL);
+        tm = localtime(&t);
+
+        rtc_timeoffset += tm->tm_gmtoff;
+    }
+
+    if (rtc_timeoffset)
+        xc_domain_set_time_offset(ctx->xch, domid, rtc_timeoffset);
 
     if (info->type == LIBXL_DOMAIN_TYPE_HVM) {
         unsigned long shadow;
Signature · 1 line
1.7.2.5
author
#1 lore raw
Quoted 8 lines · Lin Ming

libxl__domain_build_info_setdefault may be called several times, so rtc_timeoffset can't be setted in it.

Move rtc_timeoffset setting logic to libxl__build_pre.

Hi IanJ,

Would you take this one?

Thanks,
Lin Ming

Quoted 70 lines

---
 tools/libxl/libxl_create.c |    9 --------- tools/libxl/libxl_dom.c    |   17 +++++++++++++++--

 2 files changed, 15 insertions(+), 11 deletions(-)
tools/libxl/libxl_create.c +0 -9
index e63c7bd..e706124 100644
@@ -127,15 +127,6 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
         b_info->target_memkb = b_info->max_memkb;
 
     libxl_defbool_setdefault(&b_info->localtime, false);
-    if (libxl_defbool_val(b_info->localtime)) {
-        time_t t;
-        struct tm *tm;
-
-        t = time(NULL);
-        tm = localtime(&t);
-
-        b_info->rtc_timeoffset += tm->tm_gmtoff;
-    }
 
     libxl_defbool_setdefault(&b_info->disable_migrate, false);
 
tools/libxl/libxl_dom.c +15 -3
index 0bdd654..91c4bd8 100644
@@ -65,6 +65,8 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid,
     libxl_ctx *ctx = libxl__gc_owner(gc);
     int tsc_mode;
     char *xs_domid, *con_domid;
+    uint32_t rtc_timeoffset;
+
     xc_domain_max_vcpus(ctx->xch, domid, info->max_vcpus);
     libxl_set_vcpuaffinity_all(ctx, domid, info->max_vcpus, &info->cpumap);
     xc_domain_setmaxmem(ctx->xch, domid, info->target_memkb + LIBXL_MAXMEM_CONSTANT);
@@ -91,8 +93,19 @@ int libxl__build_pre(libxl__gc *gc, uint32_t domid,
     if (libxl_defbool_val(info->disable_migrate))
         xc_domain_disable_migrate(ctx->xch, domid);
 
-    if (info->rtc_timeoffset)
-        xc_domain_set_time_offset(ctx->xch, domid, info->rtc_timeoffset);
+    rtc_timeoffset = info->rtc_timeoffset;
+    if (libxl_defbool_val(info->localtime)) {
+        time_t t;
+        struct tm *tm;
+
+        t = time(NULL);
+        tm = localtime(&t);
+
+        rtc_timeoffset += tm->tm_gmtoff;
+    }
+
+    if (rtc_timeoffset)
+        xc_domain_set_time_offset(ctx->xch, domid, rtc_timeoffset);
 
     if (info->type == LIBXL_DOMAIN_TYPE_HVM) {
         unsigned long shadow;
--

1.7.2.5

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel