From patchwork Tue Jan 12 13:14:27 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: 8017051 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6E47E9F3F6 for ; Tue, 12 Jan 2016 13:17:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 812D6203DA for ; Tue, 12 Jan 2016 13:17:35 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 71679203C3 for ; Tue, 12 Jan 2016 13:17:34 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aIymU-0005iG-OS; Tue, 12 Jan 2016 13:14:38 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aIymS-0005hs-Lj for xen-devel@lists.xenproject.org; Tue, 12 Jan 2016 13:14:36 +0000 Received: from [85.158.137.68] by server-6.bemta-3.messagelabs.com id D6/40-29649-B3CF4965; Tue, 12 Jan 2016 13:14:35 +0000 X-Env-Sender: prvs=812c9b64b=roger.pau@citrix.com X-Msg-Ref: server-7.tower-31.messagelabs.com!1452604474!7858880!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 29907 invoked from network); 12 Jan 2016 13:14:35 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-7.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 12 Jan 2016 13:14:35 -0000 X-IronPort-AV: E=Sophos;i="5.20,557,1444694400"; d="scan'208";a="330623544" From: Roger Pau Monne To: Date: Tue, 12 Jan 2016 14:14:27 +0100 Message-ID: <1452604467-65746-3-git-send-email-roger.pau@citrix.com> X-Mailer: git-send-email 1.9.5 (Apple Git-50.3) In-Reply-To: <1452604467-65746-1-git-send-email-roger.pau@citrix.com> References: <1452604467-65746-1-git-send-email-roger.pau@citrix.com> MIME-Version: 1.0 X-DLP: MIA2 Cc: Roger Pau Monne Subject: [Xen-devel] [PATCH 2/2] libxl: fix UUID usage on FreeBSD X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org 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 libxl makes the assumtion that libxl_uuid == uuid_t, and that uuid_t can be freely used as a byte array. This is not true on FreeBSD (and NetBSD too, not sure about other BSD UUID implementations), where the internals of uuid don't match what libxl expects as a byte array because of endianness issues. Fix this by converting the libxl_uuid type to a struct with an internal uuid_t field and a byte-array. Also introduce a new function that should be used in order to load a byte array into a uuid_t struct. Signed-off-by: Roger Pau Monné --- tools/libxl/libxl.c | 2 +- tools/libxl/libxl.h | 9 +++++++++ tools/libxl/libxl_uuid.c | 22 +++++++++++++++++++--- tools/libxl/libxl_uuid.h | 3 ++- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 9207621..ae08b2f 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -616,7 +616,7 @@ static void xcinfo2xlinfo(libxl_ctx *ctx, { size_t size; - memcpy(&(xlinfo->uuid), xcinfo->handle, sizeof(xen_domain_handle_t)); + libxl_uuid_from_bytearray(&xlinfo->uuid, xcinfo->handle); xlinfo->domid = xcinfo->domain; xlinfo->ssidref = xcinfo->ssidref; if (libxl_flask_sid_to_context(ctx, xlinfo->ssidref, diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 05606a7..876fca8 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -867,6 +867,15 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, libxl_mac *src); */ #define LIBXL_HAVE_DEVICE_MODEL_VERSION_NONE 1 +/* + * LIBXL_HAVE_UUID_FROM_BYTEARRAY + * + * In the case that LIBXL_HAVE_UUID_FROM_BYTEARRAY is set libxl + * provides a function (libxl_uuid_from_bytearray) to convert an + * octet stream into a UUID. + */ +#define LIBXL_HAVE_UUID_FROM_BYTEARRAY 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_uuid.c b/tools/libxl/libxl_uuid.c index 7d4a032..f566f50 100644 --- a/tools/libxl/libxl_uuid.c +++ b/tools/libxl/libxl_uuid.c @@ -33,6 +33,12 @@ int libxl_uuid_from_string(libxl_uuid *uuid, const char *in) return uuid_parse(in, uuid->uuid); } +int libxl_uuid_from_bytearray(libxl_uuid *uuid, const uint8_t *raw) +{ + memcpy(uuid, raw, sizeof(*uuid)); + return 0; +} + void libxl_uuid_copy(libxl_ctx *ctx_opt, libxl_uuid *dst, const libxl_uuid *src) { @@ -72,9 +78,9 @@ void libxl_uuid_generate(libxl_uuid *uuid) { uint32_t status; - BUILD_BUG_ON(sizeof(libxl_uuid) != sizeof(uuid_t)); uuid_create(&uuid->uuid, &status); assert(status == uuid_s_ok); + uuid_enc_be(uuid->uuid_raw, &uuid->uuid); } #ifdef __FreeBSD__ @@ -85,6 +91,8 @@ int libxl_uuid_from_string(libxl_uuid *uuid, const char *in) uuid_from_string(in, &uuid->uuid, &status); if (status != uuid_s_ok) return -1; + uuid_enc_be(uuid->uuid_raw, &uuid->uuid); + return 0; } #else @@ -101,15 +109,23 @@ int libxl_uuid_from_string(libxl_uuid *uuid, const char *in) #undef LIBXL__UUID_PTRS #endif +int libxl_uuid_from_bytearray(libxl_uuid *uuid, const uint8_t *raw) +{ + uuid_dec_le(raw, &uuid->uuid); + uuid_enc_be(uuid->uuid_raw, &uuid->uuid); + + return 0; +} + void libxl_uuid_copy(libxl_ctx *ctx_opt, libxl_uuid *dst, const libxl_uuid *src) { - memcpy(&dst->uuid, &src->uuid, sizeof(dst->uuid)); + memcpy(dst, src, sizeof(*dst)); } void libxl_uuid_clear(libxl_uuid *uuid) { - memset(&uuid->uuid, 0, sizeof(uuid->uuid)); + memset(uuid, 0, sizeof(*uuid)); } #ifdef __FreeBSD__ diff --git a/tools/libxl/libxl_uuid.h b/tools/libxl/libxl_uuid.h index c5041c7..d84e3d1 100644 --- a/tools/libxl/libxl_uuid.h +++ b/tools/libxl/libxl_uuid.h @@ -42,7 +42,7 @@ typedef struct { #include #include -typedef union { +typedef struct { uuid_t uuid; uint8_t uuid_raw[16]; } libxl_uuid; @@ -73,6 +73,7 @@ void libxl_uuid_clear(libxl_uuid *uuid); int libxl_uuid_compare(const libxl_uuid *uuid1, const libxl_uuid *uuid2); const uint8_t *libxl_uuid_bytearray_const(const libxl_uuid *uuid); uint8_t *libxl_uuid_bytearray(libxl_uuid *uuid); +int libxl_uuid_from_bytearray(libxl_uuid *uuid, const uint8_t *raw); #endif /* __LIBXL_UUID_H__ */