From patchwork Fri Apr 8 14:00:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 8783741 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 081DBC0553 for ; Fri, 8 Apr 2016 14:03:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0B036202E9 for ; Fri, 8 Apr 2016 14:03:18 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2C312202BE for ; Fri, 8 Apr 2016 14:03:16 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1aoWyF-0006ih-K8; Fri, 08 Apr 2016 14:01:11 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1aoWyD-0006iU-O9 for xen-devel@lists.xenproject.org; Fri, 08 Apr 2016 14:01:09 +0000 Received: from [85.158.137.68] by server-13.bemta-3.messagelabs.com id 80/85-03443-4A9B7075; Fri, 08 Apr 2016 14:01:08 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupnkeJIrShJLcpLzFFi42JxWrohUnfJTvZ wg5uTxSy+b5nM5MDocfjDFZYAxijWzLyk/IoE1ozlfXNYCrbqVxyZXtrAuFm9i5GTQ0LAX2Lq 1E4mEJtNQEfi4tydbF2MHBwiAioSt/cagISZBYolVv3tYQWxhQU8JH73PwIrZwEqOT9xNxuIz SvgIvF94l02iJG6Eid3b2KHiAtKnJz5hAVijqZE6/bf7BC2vETz1tnMILaQgKJE/7wHUL3cEr dPT2WewMg7C0n7LCTts5C0L2BkXsWoUZxaVJZapGtooZdUlJmeUZKbmJmja2hgrJebWlycmJ6 ak5hUrJecn7uJERhQ9QwMjDsYf5/2PMQoycGkJMrL0MseLsSXlJ9SmZFYnBFfVJqTWnyIUYaD Q0mCd9MOoJxgUWp6akVaZg4wtGHSEhw8SiK8JiBp3uKCxNzizHSI1ClGRSlxXnaQhABIIqM0D 64NFk+XGGWlhHkZGRgYhHgKUotyM0tQ5V8xinMwKgnzSoFM4cnMK4Gb/gpoMRPQ4gv8bCCLSx IRUlINjArBy12FHSdGH9ro/fl47JIDp/P4l/LI2ukFsJpsSxZVD3kb51rc6fA3z36277GTFVP YMl9uculc37q19veHZanN5StZ7wqsaMlSrXi4bVn+BcYHn3IE9lqUhwY8XxylbPt+Ol9j3ft1 yewNN1bv5J3b/LZ+ZjPPstkpk/qfBoixPrKuqbqpqsRSnJFoqMVcVJwIAEg1WY+iAgAA X-Env-Sender: prvs=89920a859=roger.pau@citrix.com X-Msg-Ref: server-3.tower-31.messagelabs.com!1460124066!33711894!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 8.28; banners=-,-,- X-VirusChecked: Checked Received: (qmail 55080 invoked from network); 8 Apr 2016 14:01:08 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-3.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 8 Apr 2016 14:01:08 -0000 X-IronPort-AV: E=Sophos;i="5.24,449,1454976000"; d="scan'208";a="345797438" From: Roger Pau Monne To: Date: Fri, 8 Apr 2016 16:00:16 +0200 Message-ID: <1460124016-22640-1-git-send-email-roger.pau@citrix.com> X-Mailer: git-send-email 2.6.4 (Apple Git-63) MIME-Version: 1.0 X-DLP: MIA2 Cc: Wei Liu , Ian Jackson , Roger Pau Monne Subject: [Xen-devel] [PATCH v3] libxl: replace the usage of uuid_t with a char array X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The internals of the uuid_t struct don't match a big endian octet stream on *BSD systems, which means that it cannot be directly casted to a uint8_t[16]. In order to solve that change the type to be an unsigned char[16], which doesn't imply any other change on Linux. On *BSDs change the helpers so that the uuid is always stored as a big endian byte stream. NB: tested on FreeBSD and Linux only. Signed-off-by: Roger Pau Monné Reviewed-by: Wei Liu Discussed-with: Ian Jackson Discussed-with: Wei Liu --- Cc: Ian Jackson Cc: Wei Liu --- NB2: AFAICT the NetBSD version of libxl_uuid_from_string *could* be switched to the FreeBSD one (because NetBSD also has uuid_from_string), but I don't have a NetBSD box in order to test it. --- Changes since v2: - Add LIBXL_HAVE_BYTEARRAY_UUID define. Changes since v1: - Readd a line that was deleted by error. --- tools/libxl/libxl.h | 9 +++++++++ tools/libxl/libxl_osdeps.h | 3 +++ tools/libxl/libxl_uuid.c | 28 ++++++++++++++++++++-------- tools/libxl/libxl_uuid.h | 21 ++++++++------------- 4 files changed, 40 insertions(+), 21 deletions(-) diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 677e060..8935a8f 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -932,6 +932,15 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, libxl_mac *src); */ #define LIBXL_HAVE_VGA_INTERFACE_TYPE_UNKNOWN 1 +/* + * LIBXL_HAVE_BYTEARRAY_UUID + * + * If this is defined, the internal member of libxl_uuid is defined + * as a 16 byte array that contains the UUID in big endian format. + * Also, the same structure layout is used across all OSes. + */ +#define LIBXL_HAVE_BYTEARRAY_UUID 1 + typedef char **libxl_string_list; void libxl_string_list_dispose(libxl_string_list *sl); int libxl_string_list_length(const libxl_string_list *sl); diff --git a/tools/libxl/libxl_osdeps.h b/tools/libxl/libxl_osdeps.h index 802c762..10ce703 100644 --- a/tools/libxl/libxl_osdeps.h +++ b/tools/libxl/libxl_osdeps.h @@ -30,6 +30,7 @@ #define SYSFS_PCIBACK_DRIVER "/kern/xen/pci" #define NETBACK_NIC_NAME "xvif%ui%d" #include +#include #elif defined(__OpenBSD__) #include #elif defined(__linux__) @@ -39,6 +40,7 @@ #define SYSFS_PCIBACK_DRIVER "/sys/bus/pci/drivers/pciback" #define NETBACK_NIC_NAME "vif%u.%d" #include +#include #elif defined(__sun__) #include #elif defined(__FreeBSD__) @@ -49,6 +51,7 @@ #define NETBACK_NIC_NAME "xnb%u.%d" #include #include +#include #endif #ifndef SYSFS_USBBACK_DRIVER diff --git a/tools/libxl/libxl_uuid.c b/tools/libxl/libxl_uuid.c index 7d4a032..dadb79b 100644 --- a/tools/libxl/libxl_uuid.c +++ b/tools/libxl/libxl_uuid.c @@ -64,27 +64,35 @@ uint8_t *libxl_uuid_bytearray(libxl_uuid *uuid) int libxl_uuid_is_nil(const libxl_uuid *uuid) { uint32_t status; + uuid_t nat_uuid; - return uuid_is_nil(&uuid->uuid, &status); + uuid_dec_be(uuid->uuid, &nat_uuid); + + return uuid_is_nil(&nat_uuid, &status); } void libxl_uuid_generate(libxl_uuid *uuid) { uint32_t status; + uuid_t nat_uuid; - BUILD_BUG_ON(sizeof(libxl_uuid) != sizeof(uuid_t)); - uuid_create(&uuid->uuid, &status); + uuid_create(&nat_uuid, &status); assert(status == uuid_s_ok); + + uuid_enc_be(uuid->uuid, &nat_uuid); } #ifdef __FreeBSD__ int libxl_uuid_from_string(libxl_uuid *uuid, const char *in) { uint32_t status; + uuid_t nat_uuid; - uuid_from_string(in, &uuid->uuid, &status); + uuid_from_string(in, &nat_uuid, &status); if (status != uuid_s_ok) - return -1; + return ERROR_FAIL; + uuid_enc_be(uuid->uuid, &nat_uuid); + return 0; } #else @@ -115,8 +123,12 @@ void libxl_uuid_clear(libxl_uuid *uuid) #ifdef __FreeBSD__ int libxl_uuid_compare(const libxl_uuid *uuid1, const libxl_uuid *uuid2) { + uuid_t nat_uuid1, nat_uuid2; - return uuid_compare(&uuid1->uuid, &uuid2->uuid, NULL); + uuid_dec_be(uuid1->uuid, &nat_uuid1); + uuid_dec_be(uuid2->uuid, &nat_uuid2); + + return uuid_compare(&nat_uuid1, &nat_uuid2, NULL); } #else int libxl_uuid_compare(const libxl_uuid *uuid1, const libxl_uuid *uuid2) @@ -128,13 +140,13 @@ int libxl_uuid_compare(const libxl_uuid *uuid1, const libxl_uuid *uuid2) const uint8_t *libxl_uuid_bytearray_const(const libxl_uuid *uuid) { - return uuid->uuid_raw; + return uuid->uuid; } uint8_t *libxl_uuid_bytearray(libxl_uuid *uuid) { - return uuid->uuid_raw; + return uuid->uuid; } #else diff --git a/tools/libxl/libxl_uuid.h b/tools/libxl/libxl_uuid.h index c5041c7..994320d 100644 --- a/tools/libxl/libxl_uuid.h +++ b/tools/libxl/libxl_uuid.h @@ -21,18 +21,19 @@ uuid[4], uuid[5], uuid[6], uuid[7], \ uuid[8], uuid[9], uuid[10], uuid[11], \ uuid[12], uuid[13], uuid[14], uuid[15] +#define LIBXL_UUID_BYTES(arg) LIBXL__UUID_BYTES((arg).uuid) +typedef struct { + /* UUID as an octet stream in big-endian byte-order. */ + unsigned char uuid[16]; +} libxl_uuid; + +#if defined(LIBXL_API_VERSION) && LIBXL_API_VERSION < 0x040700 #if defined(__linux__) #include #include -typedef struct { - uuid_t uuid; -} libxl_uuid; - -#define LIBXL_UUID_BYTES(arg) LIBXL__UUID_BYTES(((uint8_t *)arg.uuid)) - #elif defined(__FreeBSD__) || defined(__NetBSD__) #include @@ -42,18 +43,12 @@ typedef struct { #include #include -typedef union { - uuid_t uuid; - uint8_t uuid_raw[16]; -} libxl_uuid; - -#define LIBXL_UUID_BYTES(arg) LIBXL__UUID_BYTES(arg.uuid_raw) - #else #error "Please update libxl_uuid.h for your OS" #endif +#endif int libxl_uuid_is_nil(const libxl_uuid *uuid); void libxl_uuid_generate(libxl_uuid *uuid);