[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH v9 1/8] libxl_internal: functions to check default values for builtin types



On Thu, Jul 10, 2014 at 11:19:44AM +0100, Ian Campbell wrote:
> On Wed, 2014-07-09 at 10:45 +0100, Wei Liu wrote:
> > +static inline int libxl__cpuid_policy_is_empty(libxl_cpuid_policy_list *pl)
> > +{
> > +    return !libxl_cpuid_policy_list_length(pl);
> > +}
> 
> Unfortunately on ARM I get
> libxenlight_test.so: undefined reference to `libxl_cpuid_policy_list_length'
> /local/scratch/ianc/devel/committer-arm32.git/tools/libxl/../../tools/libxl/libxenlight.so:
>  undefined reference to `libxl_cpuid_policy_list_length'
> 
> So I think you need to move this one out of line into libxl_cpuid.c and
> put a dummy version in libxl_nocpuid.c.
> 
> I can build test ARM the arm side for you, since I expect you don't have
> the environment.
> 

OIC, ARM doesn't have CPUID thing (yet) so it's compiled with
libxl_nocpuid.c. Sorry for the trouble.

The following patch, which has libxl__cpuid_policy_is_empty moved to
libxl_cpuid.c and libxl_nocpuid.c, assumes that when libxl_nocpuid.c is
compiled, the given cpuid policy is always empty, so that the JSON
output won't have cpuid policy.

Please try the following patch.

---8<---
From 098f9b3182323d4c76c1412b9a44ba2a70054319 Mon Sep 17 00:00:00 2001
From: Wei Liu <wei.liu2@xxxxxxxxxx>
Date: Wed, 11 Jun 2014 17:35:07 +0100
Subject: [PATCH] libxl_internal: functions to check default values for
 builtin types

They will be used in later patch to determine whether we should generate
JSON output for a type. If that type has default value we just skip
generating JSON output.

Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx>
Acked-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
---
 tools/libxl/libxl.c          |    3 +--
 tools/libxl/libxl_cpuid.c    |    5 +++++
 tools/libxl/libxl_internal.c |    6 ++++++
 tools/libxl/libxl_internal.h |   24 ++++++++++++++++++++++++
 tools/libxl/libxl_nocpuid.c  |    5 +++++
 5 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 39f1c28..c272b8d 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -2860,8 +2860,7 @@ int libxl__device_nic_setdefault(libxl__gc *gc, 
libxl_device_nic *nic,
         nic->model = strdup("rtl8139");
         if (!nic->model) return ERROR_NOMEM;
     }
-    if (!nic->mac[0] && !nic->mac[1] && !nic->mac[2] &&
-        !nic->mac[3] && !nic->mac[4] && !nic->mac[5]) {
+    if (libxl__mac_is_default(&nic->mac)) {
         const uint8_t *r;
         libxl_uuid uuid;
 
diff --git a/tools/libxl/libxl_cpuid.c b/tools/libxl/libxl_cpuid.c
index 1f2bcd5..1706357 100644
--- a/tools/libxl/libxl_cpuid.c
+++ b/tools/libxl/libxl_cpuid.c
@@ -14,6 +14,11 @@
 
 #include "libxl_internal.h"
 
+int libxl__cpuid_policy_is_empty(libxl_cpuid_policy_list *pl)
+{
+    return !libxl_cpuid_policy_list_length(pl);
+}
+
 void libxl_cpuid_dispose(libxl_cpuid_policy_list *p_cpuid_list)
 {
     int i, j;
diff --git a/tools/libxl/libxl_internal.c b/tools/libxl/libxl_internal.c
index 6c94d3e..81f8985 100644
--- a/tools/libxl/libxl_internal.c
+++ b/tools/libxl/libxl_internal.c
@@ -307,6 +307,12 @@ _hidden int libxl__compare_macs(libxl_mac *a, libxl_mac *b)
     return 0;
 }
 
+_hidden int libxl__mac_is_default(libxl_mac *mac)
+{
+    return (!(*mac)[0] && !(*mac)[1] && !(*mac)[2] &&
+            !(*mac)[3] && !(*mac)[4] && !(*mac)[5]);
+}
+
 _hidden int libxl__init_recursive_mutex(libxl_ctx *ctx, pthread_mutex_t *lock)
 {
     pthread_mutexattr_t attr;
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index e8f2abb..7750dc5 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -1549,6 +1549,8 @@ struct libxl__xen_console_reader {
 _hidden int libxl__parse_mac(const char *s, libxl_mac mac);
 /* compare mac address @a and @b. 0 if the same, -ve if a<b and +ve if a>b */
 _hidden int libxl__compare_macs(libxl_mac *a, libxl_mac *b);
+/* return true if mac address is all zero (the default value) */
+_hidden int libxl__mac_is_default(libxl_mac *mac);
 /* init a recursive mutex */
 _hidden int libxl__init_recursive_mutex(libxl_ctx *ctx, pthread_mutex_t *lock);
 
@@ -3097,6 +3099,10 @@ _hidden int libxl__ms_vm_genid_set(libxl__gc *gc, 
uint32_t domid,
 #define LIBXL__DEFBOOL_STR_DEFAULT "<default>"
 #define LIBXL__DEFBOOL_STR_FALSE   "False"
 #define LIBXL__DEFBOOL_STR_TRUE    "True"
+static inline int libxl__defbool_is_default(libxl_defbool *db)
+{
+    return !db->val;
+}
 
 /*
  * Inserts "elm_new" into the sorted list "head".
@@ -3193,6 +3199,24 @@ int libxl__random_bytes(libxl__gc *gc, uint8_t *buf, 
size_t len);
 #define BUILD_BUG_ON(p) ((void)sizeof(char[1 - 2 * !!(p)]))
 #endif
 
+/* This always return false, there's no "default value" for hw cap */
+static inline int libxl__hwcap_is_default(libxl_hwcap *hwcap)
+{
+    return 0;
+}
+
+static inline int libxl__string_list_is_empty(libxl_string_list *psl)
+{
+    return !libxl_string_list_length(psl);
+}
+
+static inline int libxl__key_value_list_is_empty(libxl_key_value_list *pkvl)
+{
+    return !libxl_key_value_list_length(pkvl);
+}
+
+int libxl__cpuid_policy_is_empty(libxl_cpuid_policy_list *pl);
+
 #endif
 
 /*
diff --git a/tools/libxl/libxl_nocpuid.c b/tools/libxl/libxl_nocpuid.c
index eb525fc..96e6e2e 100644
--- a/tools/libxl/libxl_nocpuid.c
+++ b/tools/libxl/libxl_nocpuid.c
@@ -14,6 +14,11 @@
 
 #include "libxl_internal.h"
 
+int libxl__cpuid_policy_is_empty(libxl_cpuid_policy_list *pl)
+{
+    return 1;
+}
+
 void libxl_cpuid_dispose(libxl_cpuid_policy_list *p_cpuid_list)
 {
 }
-- 
1.7.10.4



> Ian.

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.