From patchwork Mon Oct 7 15:12:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Rosbrook X-Patchwork-Id: 11177793 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 02E3013BD for ; Mon, 7 Oct 2019 15:15:26 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D2B412070B for ; Mon, 7 Oct 2019 15:15:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eaQXZAFj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D2B412070B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iHUiI-00078o-NG; Mon, 07 Oct 2019 15:14:18 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iHUiG-00077R-OK for xen-devel@lists.xenproject.org; Mon, 07 Oct 2019 15:14:16 +0000 X-Inumbo-ID: 05370412-e915-11e9-80e3-bc764e2007e4 Received: from mail-qt1-x842.google.com (unknown [2607:f8b0:4864:20::842]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 05370412-e915-11e9-80e3-bc764e2007e4; Mon, 07 Oct 2019 15:13:30 +0000 (UTC) Received: by mail-qt1-x842.google.com with SMTP id 3so19678434qta.1 for ; Mon, 07 Oct 2019 08:13:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4SAiZoZ3TDuKHeorxNwWTkai7aNXrNdRhe1wN1UxU/4=; b=eaQXZAFjIZIDM3XO2x2Y4+glwNvk8TwoZEKBTSqBO9hIZ/+6gII+IL5rnI6kAkTiSI hSY0Kc9NAp/01CzQ/NDDrn4pqZvcJvgNwet7Y5BwjPbmteL0usWmetDlkG9shXmMUTSR EhWwu8btnvUalJ565CDT8kWsQzl+/q2tEFAq5qkhf7RQiBvd/3d7YrCwPfymr7cbUR5F 4mhsm4CikZx/NljVbvKQ3MzypxYD6M4w/VhfPcf0Tjzw9GdKV049NlC1lriAcpzbPeFr qXWRzLBuHKVQEro0g/4dJ1QALQ6XOWdf5Awbp2uKv5xbBzRBHQbBzn6L9vhyM1h6gWvF KlWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4SAiZoZ3TDuKHeorxNwWTkai7aNXrNdRhe1wN1UxU/4=; b=crM5cebQk/obiJlx40troY6bHGp4Ca+E3j5yzecczewZ5SONA3bukYE0Y3CGUE6XTc mh19nbjLKzBUGR/ysd8pvVtHrurGbopZFSLvXCG+ocADy9fmwxI2tkBrWILXtasEfhci aYS6Xq7Hi54GAjZ0wbHnUajIlXC91G14XMD8ryBuQ/LVp+89EDFUVoevUFR2uyIpSGEh 4b2VVSmbqc7+l12VekGA7Xk+1OJT2spueFGwp2wW370TM/7/qi4kbc4o9afVCpj/BWBa N6GGDb2EFqKA5voJW8yex7AZUGhnVG/H6L4BYcky14z0AHqsgg53GZck01qSgFjI0FA7 rg6A== X-Gm-Message-State: APjAAAUU/mQRyQGDUR8+qBsvY0tPxUKb44WzmReVSYA5Kih8sIMoNz5K H+6I8UAU/e8/yOcKRKDnT7FIm2Bg X-Google-Smtp-Source: APXvYqyn0FSlaoAW3TtcuIzFioCAv4ncqlFrmwu4axCIKbTNLhXsIIbiyX8VSMePyzLHH5p3VQbZrA== X-Received: by 2002:aed:3fe9:: with SMTP id w38mr30506897qth.180.1570461209709; Mon, 07 Oct 2019 08:13:29 -0700 (PDT) Received: from five.crux.rad.ainfosec.com (209-217-208-226.northland.net. [209.217.208.226]) by smtp.googlemail.com with ESMTPSA id c185sm8354313qkg.74.2019.10.07.08.13.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Oct 2019 08:13:29 -0700 (PDT) From: Nick Rosbrook To: xen-devel@lists.xenproject.org Date: Mon, 7 Oct 2019 11:12:59 -0400 Message-Id: <03324a8aca83d6006977e8d6752e0a5f5250f081.1570456846.git.rosbrookn@ainfosec.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 12/24] golang/xenlight: re-factor Uuid type implementation X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Nick Rosbrook , Ian Jackson , kerriganb@ainfosec.com, George Dunlap , Wei Liu Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Nick Rosbrook Re-define Uuid as [16]byte and implement fromC, toC, and String functions. Signed-off-by: Nick Rosbrook --- Cc: George Dunlap Cc: Ian Jackson Cc: Wei Liu tools/golang/xenlight/xenlight.go | 37 +++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go index 9c384485e1..3e3753f92e 100644 --- a/tools/golang/xenlight/xenlight.go +++ b/tools/golang/xenlight/xenlight.go @@ -86,7 +86,40 @@ type Devid int type MemKB uint64 -type Uuid C.libxl_uuid +// Uuid is a domain UUID. +type Uuid [16]byte + +// String formats a Uuid in the form "xxxx-xx-xx-xx-xxxxxx". +func (u Uuid) String() string { + s := "%x%x%x%x-%x%x-%x%x-%x%x-%x%x%x%x%x%x" + opts := make([]interface{}, 16) + + for i, v := range u { + opts[i] = v + } + + return fmt.Sprintf(s, opts...) +} + +func (u *Uuid) fromC(c *C.libxl_uuid) error { + b := (*[16]C.uint8_t)(unsafe.Pointer(&c.uuid[0])) + + for i, v := range b { + u[i] = byte(v) + } + + return nil +} + +func (u *Uuid) toC() (C.libxl_uuid, error) { + var c C.libxl_uuid + + for i, v := range u { + c.uuid[i] = C.uint8_t(v) + } + + return c, nil +} // defboolVal represents a defbool value. type defboolVal int @@ -516,7 +549,7 @@ type Dominfo struct { func (cdi *C.libxl_dominfo) toGo() (di *Dominfo) { di = &Dominfo{} - di.Uuid = Uuid(cdi.uuid) + di.Uuid.fromC(&cdi.uuid) di.Domid = Domid(cdi.domid) di.Ssidref = uint32(cdi.ssidref) di.SsidLabel = C.GoString(cdi.ssid_label)