[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v8 1/8] 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> --- tools/libxl/libxl.c | 3 +-- tools/libxl/libxl_internal.c | 6 ++++++ tools/libxl/libxl_internal.h | 27 +++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 62e251a..1d8e046 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_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 a0d4f24..2a8f552 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1551,6 +1551,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 @@ void libxl__numa_candidate_put_nodemap(libxl__gc *gc, #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". @@ -3180,6 +3186,27 @@ int libxl__uint64_parse_json(libxl__gc *gc, const libxl__json_object *o, int libxl__string_parse_json(libxl__gc *gc, const libxl__json_object *o, char **p); +/* 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); +} + +static inline int libxl__cpuid_policy_is_empty(libxl_cpuid_policy_list *pl) +{ + return !libxl_cpuid_policy_list_length(pl); +} + #endif /* -- 1.7.10.4 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |