From patchwork Tue Dec 10 15:47:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Rosbrook X-Patchwork-Id: 11282883 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 005E914BD for ; Tue, 10 Dec 2019 15:49:38 +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 D113B206D5 for ; Tue, 10 Dec 2019 15:49:37 +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="bGd4ymgk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D113B206D5 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 1iehkl-0003Ki-O3; Tue, 10 Dec 2019 15:48:47 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iehkj-0003J1-S3 for xen-devel@lists.xenproject.org; Tue, 10 Dec 2019 15:48:45 +0000 X-Inumbo-ID: 73741506-1b64-11ea-a1e1-bc764e2007e4 Received: from mail-qt1-x844.google.com (unknown [2607:f8b0:4864:20::844]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 73741506-1b64-11ea-a1e1-bc764e2007e4; Tue, 10 Dec 2019 15:48:03 +0000 (UTC) Received: by mail-qt1-x844.google.com with SMTP id 38so3130825qtb.13 for ; Tue, 10 Dec 2019 07:48:03 -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=c8eG9nY6uSAld50WZyo55/GW778waof2L41HLOEHCKQ=; b=bGd4ymgkVlVL1phXwcmu5aPmfqdTvLi6u5ExaiW9g829fXig+NFceUzr6jTqtV5gwf eYIuiTYlaXmrTnukn6XCoLjlQlBFSHZTtzP2RcN0w8sV70fqZ0jEnbs4a0e4Dp0UIcFD lT2eE3O1i09NHJ9ORk4nd6QBgdQjXc5o2CJXyQcytZmqOcmnbIfYiuOv7QV5MGCLUd/4 CPWXCR+OdVwWhMtt/+sg+/5+HR1aIikUC+p4Twuo+tFE/QFWus64gOEPlRqi2PhMVwI2 0ikez2OYCUS/T9Z7g96/PKv2GEyDwgFYeVC40PSXp0GCe/49mdokT8SwMlSs/JwDOkyc idzg== 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=c8eG9nY6uSAld50WZyo55/GW778waof2L41HLOEHCKQ=; b=ai1fpvJmD0rhGP46/6x1a3x7wbIuiiKADNJbXpgwAqOvXK7a6wDMa0VS3gZx7PULXm qvX0/14f8Fa4AtFfaba2t7SDWVqBEAv8yMKWmGHctCiIOFoGg4G5Z5oXzdQO0iL2nCy1 DqJa8nzaVeZP8CKbDYFk+S5mKVxh7myG6rsoj21RpzQDCXS+tHEqAQjAp188v+JejWsO lT/pH8o3UtQ2xrGsQsATKHMeTTp7+qP9HMFTzO7O1oqMxXkh4LEes4DYbJ95+j+uRAl9 4fWeX3LGkv8Cv9fOWroWHVK0F7YfS7tgZCiawEkztSa6Juvw9tJDwTEEx3R9nV5CyuSw DAqQ== X-Gm-Message-State: APjAAAUT5iik6+NFWhxJ+rRvurHkMVbyqehXgUE22qSJWXRE/9NoMQJo 6LTOo4b8XCYYt0eQChCbTJbjZbG8 X-Google-Smtp-Source: APXvYqz8TJn17TN6D32LLH5uf7D2c0reXOGZrLTbJ9v2fyFuFDZQHnaIsX4Y0WMjgqTi4SuVUxxP4g== X-Received: by 2002:ac8:5159:: with SMTP id h25mr31205583qtn.101.1575992882974; Tue, 10 Dec 2019 07:48:02 -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 m29sm1247848qtf.1.2019.12.10.07.48.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 07:48:02 -0800 (PST) From: Nick Rosbrook To: xen-devel@lists.xenproject.org Date: Tue, 10 Dec 2019 10:47:26 -0500 Message-Id: <0003ff86099be24d6b5a2131393189da6bf5bab7.1575990937.git.rosbrookn@ainfosec.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v3 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 Reviewed-by: George Dunlap --- Changes in v3: - In fromC, iterate over the indirect of u instead of creating a slice from the C type. --- tools/golang/xenlight/xenlight.go | 35 +++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go index 6b87bf857d..f9c2f84c81 100644 --- a/tools/golang/xenlight/xenlight.go +++ b/tools/golang/xenlight/xenlight.go @@ -86,7 +86,38 @@ 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 { + for i := range *u { + u[i] = byte(c.uuid[i]) + } + + 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 @@ -495,7 +526,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)