WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH 1 of 2] xen: hvm_save: infrastructure for backwards c

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 1 of 2] xen: hvm_save: infrastructure for backwards compatibility
From: George Dunlap <george.dunlap@xxxxxxxxxxxxx>
Date: Thu, 31 Mar 2011 15:21:40 +0100
Cc: george.dunlap@xxxxxxxxxxxxx
Delivery-date: Thu, 31 Mar 2011 07:18:35 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1301581299@elijah>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <patchbomb.1301581299@elijah>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mercurial-patchbomb/1.4.3
The hvm_save code is used to save and restore hypervisor-related
hvm state, either for classic save/restore, or for migration
(including remus).  This is meant to be backwards-compatible across
some hypervisor versions; but if it does change, there is no way to
handle the old format as well as the new.

This patch introduces the infrastructure to allow a single older
version ("compat") of any given "save type" to be defined, along with
a function to turn the "old" version into the "new" version.  If the
size check fails for the "normal" version, it will check the "compat"
version, and if it matches, will read the old entry and call the
conversion function.

This patch involves some preprocessor hackery, but I'm only extending the
hackery that's already there.

Signed-off-by: George Dunlap <george.dunlap@xxxxxxxxxxxxx>

diff -r 45eeeb6d0481 -r ba5c95ba74d3 xen/include/public/hvm/save.h
--- a/xen/include/public/hvm/save.h     Tue Mar 29 16:34:01 2011 +0100
+++ b/xen/include/public/hvm/save.h     Thu Mar 31 15:21:21 2011 +0100
@@ -61,13 +61,35 @@
  * ugliness.
  */
 
-#define DECLARE_HVM_SAVE_TYPE(_x, _code, _type)                   \
-  struct __HVM_SAVE_TYPE_##_x { _type t; char c[_code]; }
+#ifdef __XEN__
+# define DECLARE_HVM_SAVE_TYPE_COMPAT(_x, _code, _type, _ctype, _fix)     \
+    static inline int __HVM_SAVE_FIX_COMPAT_##_x(void *h) { return _fix(h); } \
+    struct __HVM_SAVE_TYPE_##_x { _type t; char c[_code]; char cpt[2];}; \
+    struct __HVM_SAVE_TYPE_COMPAT_##_x { _ctype t; }                   
+
+# define DECLARE_HVM_SAVE_TYPE(_x, _code, _type)                         \
+    static inline int __HVM_SAVE_FIX_COMPAT_##_x(void *h) { BUG(); return -1; 
} \
+    struct __HVM_SAVE_TYPE_##_x { _type t; char c[_code]; char cpt[1];}; \
+    struct __HVM_SAVE_TYPE_COMPAT_##_x { _type t; }                   
+#else
+# define DECLARE_HVM_SAVE_TYPE_COMPAT(_x, _code, _type, _ctype, _fix)     \
+    struct __HVM_SAVE_TYPE_##_x { _type t; char c[_code]; char cpt[2];} 
+
+# define DECLARE_HVM_SAVE_TYPE(_x, _code, _type)                         \
+    struct __HVM_SAVE_TYPE_##_x { _type t; char c[_code]; char cpt[1];} 
+#endif
 
 #define HVM_SAVE_TYPE(_x) typeof (((struct __HVM_SAVE_TYPE_##_x *)(0))->t)
 #define HVM_SAVE_LENGTH(_x) (sizeof (HVM_SAVE_TYPE(_x)))
 #define HVM_SAVE_CODE(_x) (sizeof (((struct __HVM_SAVE_TYPE_##_x *)(0))->c))
 
+#ifdef __XEN__
+# define HVM_SAVE_TYPE_COMPAT(_x) typeof (((struct __HVM_SAVE_TYPE_COMPAT_##_x 
*)(0))->t)
+# define HVM_SAVE_LENGTH_COMPAT(_x) (sizeof (HVM_SAVE_TYPE_COMPAT(_x)))
+
+# define HVM_SAVE_HAS_COMPAT(_x) (sizeof (((struct __HVM_SAVE_TYPE_##_x 
*)(0))->cpt)-1)
+# define HVM_SAVE_FIX_COMPAT(_x, _dst) __HVM_SAVE_FIX_COMPAT_##_x(_dst)
+#endif
 
 /* 
  * The series of save records is teminated by a zero-type, zero-length 
diff -r 45eeeb6d0481 -r ba5c95ba74d3 xen/include/xen/hvm/save.h
--- a/xen/include/xen/hvm/save.h        Tue Mar 29 16:34:01 2011 +0100
+++ b/xen/include/xen/hvm/save.h        Thu Mar 31 15:21:21 2011 +0100
@@ -58,13 +58,19 @@
  * Unmarshalling: check, then copy. Evaluates to zero on success. This load
  * function requires the save entry to be the same size as the dest structure.
  */
-#define _hvm_load_entry(_x, _h, _dst, _strict) ({               \
-    int r;                                                      \
-    r = _hvm_check_entry((_h), HVM_SAVE_CODE(_x),               \
-                         HVM_SAVE_LENGTH(_x), (_strict));       \
-    if ( r == 0 )                                               \
-        _hvm_read_entry((_h), (_dst), HVM_SAVE_LENGTH(_x));     \
+#define _hvm_load_entry(_x, _h, _dst, _strict) ({                       \
+    int r;                                                              \
+    if ( (r = _hvm_check_entry((_h), HVM_SAVE_CODE(_x),                 \
+               HVM_SAVE_LENGTH(_x), (_strict))) == 0 )                  \
+        _hvm_read_entry((_h), (_dst), HVM_SAVE_LENGTH(_x));             \
+    else if (HVM_SAVE_HAS_COMPAT(_x)                                    \
+             && (r = _hvm_check_entry((_h), HVM_SAVE_CODE(_x),          \
+                       HVM_SAVE_LENGTH_COMPAT(_x), (_strict))) == 0 ) { \
+        _hvm_read_entry((_h), (_dst), HVM_SAVE_LENGTH_COMPAT(_x));      \
+        r=HVM_SAVE_FIX_COMPAT(_x, (_dst));                              \
+    }                                                                   \
     r; })
+
 #define hvm_load_entry(_x, _h, _dst)            \
     _hvm_load_entry(_x, _h, _dst, 1)
 #define hvm_load_entry_zeroextend(_x, _h, _dst) \

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>