From patchwork Fri Nov 15 19:44:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Rosbrook X-Patchwork-Id: 11247037 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 257FA1393 for ; Fri, 15 Nov 2019 19:47:01 +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 0236C2073B for ; Fri, 15 Nov 2019 19:47:01 +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="luBZLGUv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0236C2073B 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 1iVhXX-0001je-E1; Fri, 15 Nov 2019 19:45:55 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iVhXW-0001j7-HQ for xen-devel@lists.xenproject.org; Fri, 15 Nov 2019 19:45:54 +0000 X-Inumbo-ID: 7029a7b8-07e0-11ea-adbe-bc764e2007e4 Received: from mail-qk1-x743.google.com (unknown [2607:f8b0:4864:20::743]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 7029a7b8-07e0-11ea-adbe-bc764e2007e4; Fri, 15 Nov 2019 19:45:12 +0000 (UTC) Received: by mail-qk1-x743.google.com with SMTP id m16so9026829qki.11 for ; Fri, 15 Nov 2019 11:45:12 -0800 (PST) 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=U0uRdbQ97Jci5S6T709cmAdpGm4vb5NqX8cD6aIJD1I=; b=luBZLGUvSEjVB1Dn+nW3uUIzXLfFmaNdimw+p46lqUV9gsVhkzBnhyzGVs2hnXH6Io w9XPqa2vcxxppNP0XCVQq6EfYPK3Edj6HKRK4yvjzWovG5pH52E+YbdjELB3SV7vdS5a 9GLWz4cfJmlxp7jjJFXq+I6N4pKHlpK0EPkyEh8DXZnC7Kk6PoKD6P5Dfi+TrlvIjKk1 MWMF6OoCgnGMos7zxssXpobtt/lI33JfObZLo9wE06/8T5NUYCScH+IfjyodHHdH1Xaa TNgjBj1oGH2b8AvE4Fh8hTl3eHVuHo3pJbuW0dZS+YoayUy3EuHGEsEf9Q8d4heY0wOv uqpQ== 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=U0uRdbQ97Jci5S6T709cmAdpGm4vb5NqX8cD6aIJD1I=; b=r2Fm22xk+QPxdylFCjOc40hHW7BuOUoT4BKq/dx3F1qBMqoiFRDYGD0ddP6bXtG1fk Gn+dAGOTY6a1jxc4WfkPkNQyXA509eaoe962835zA8XkDOYXXfd6m4cVVVIKJMdi27pd KiEc4J+UyG/v6NVgC4IAKILKNJ4gJsRZihqMdyaFUsh7mR9RfgRuTyi/682Yofx/C6t2 DTqylrDJ2dOrkFcNEU82DCYZKrYCbBRWz9v2Ev1ZQTcyJl4NQGQU51Gnh1+GDUgcD5SH svH/JYVpzhPfzuT8NVZa5pGmYiXA1V4oHvrAI6Xxgq0R48Q+2s0yC0w8AWLibiMv+Roa xPkA== X-Gm-Message-State: APjAAAXJnV2h4MccRFHNFUdA3u34o05zMJjApEedQ7t2ZzAzT3gWDKxN sSd/VQKLH4QvWq6I24YvKhASueGf X-Google-Smtp-Source: APXvYqzDq5dlGuJKHmXdakxlK4QrBz+F0mQ1TvzF2eKtnT56y16IYWscqQKBkr/yY25kPL1hmGHaSA== X-Received: by 2002:a37:9c52:: with SMTP id f79mr867952qke.163.1573847111708; Fri, 15 Nov 2019 11:45:11 -0800 (PST) Received: from five.crux.rad.ainfosec.com (209-217-208-226.northland.net. [209.217.208.226]) by smtp.googlemail.com with ESMTPSA id y10sm4649679qkb.55.2019.11.15.11.45.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2019 11:45:10 -0800 (PST) From: Nick Rosbrook To: xen-devel@lists.xenproject.org Date: Fri, 15 Nov 2019 14:44:18 -0500 Message-Id: <1869a722c33ba47ab86c1acec399de3c2f3e58e3.1573840474.git.rosbrookn@ainfosec.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 11/22] 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 --- 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 6f0a9278ad..67c1bb1225 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 @@ -499,7 +532,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)