From nobody Thu May 2 13:17:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1589331382; cv=none; d=zohomail.com; s=zohoarc; b=kS/hAw5wTkhQvaiz7FIR6vflqdHj9kbo1QgOPQHmPvta8KlAnOVNVRrs3yAGYm02DC30cURtS8Q58ZLnMTZRwcwsAMBT5Iq+RMcnCrzaC/AnakWBT3Im/QxBPmsmP9+Vki5odu1Q9SZj/Q4B70N8U0+UdSAgtvnJK+6QLDCiazs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589331382; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=vucWzifnCHg1Y17H84jeYTA4ym+JO/tR6T+lTmzuxUM=; b=mN+VH/DER3FLGBFtaW/7r3ac/58cLNlnWf/nJppHvM9H/+s6Jt95C6qACNNPhrKuhoVs5gi9UTBgvDYCl/WPNGyIGsFDTjObGburbaSA7WXHdPx8N/tFBKkDZxSrhZClwIQzkL9YQy+QH0l+Kg8FzLUTq0Msl2XNNB1yLE8I9qI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1589331382713226.94929417178264; Tue, 12 May 2020 17:56:22 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jYfgn-00064F-Fp; Wed, 13 May 2020 00:56:01 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jYfgm-000646-9y for xen-devel@lists.xenproject.org; Wed, 13 May 2020 00:56:00 +0000 Received: from mail-qt1-x841.google.com (unknown [2607:f8b0:4864:20::841]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 8090bc20-94b4-11ea-ae69-bc764e2007e4; Wed, 13 May 2020 00:55:56 +0000 (UTC) Received: by mail-qt1-x841.google.com with SMTP id i68so12867109qtb.5 for ; Tue, 12 May 2020 17:55:56 -0700 (PDT) Received: from six.lan (cpe-67-241-56-252.twcny.res.rr.com. [67.241.56.252]) by smtp.gmail.com with ESMTPSA id y28sm8388602qtc.62.2020.05.12.17.55.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2020 17:55:54 -0700 (PDT) X-Inumbo-ID: 8090bc20-94b4-11ea-ae69-bc764e2007e4 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 :in-reply-to:references; bh=vucWzifnCHg1Y17H84jeYTA4ym+JO/tR6T+lTmzuxUM=; b=nFwHOxIyQmzykfR4t6Lqr1JLUBfjw6TpV3GM0+nB9D79zh+TotaGfgG11UemFt7Adj QpiNhIOWB1LW5E3UhqOSmz5I0YcY8ifsuCpN8upCe3YgVAqskiiF0psYKUttBMeZK3Rb rfMlbiYg7Y6obDCP1hruvkfFp7Ek2ZldAIyB2TL3NZg/UIy0h2lqOLk2knz/ILX/m1u1 N2DiP/j2LrNnLncOe2BGliPHdlrVS59He/s64RMwA18xLXnKR/MrTR0Z75zutnHFKTcb 7JhNisfQLDqmczUGs8Ph/yb6BrpNuSL5VSG//nDoAHKxY6ccJ+2M094snSOs/EwO3aiI sIew== 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:in-reply-to:references; bh=vucWzifnCHg1Y17H84jeYTA4ym+JO/tR6T+lTmzuxUM=; b=DNvfWDQUoJ09ucxLK8wSuuaIZ6e11/QGyFZFJoajDsauXvT7vyz36iT6mUd32mQaxo H5Ait62QBFK+ZdA8efr5N6WGwAL71b1soA8brj5lZ0L0UdvFzdUqhlN5jyJPL0HV/Pbj JcWJ8rbCRrwwNd7N8hEWF00HLY9+Ln5P+lpAfJXCoeI5lhljVEeQW4vzDaDSePoklsLZ wS4tl2v0scIaUOeNenBphFs8OQ1nH0FktHbHOOhognDLtxMj2NANGsqGCCvKvqrL/fUG i6TjxO5yZe4KKx5B17XkjLrOTqXOohZwYKpLWGjhNCy7t9nQLj0sET/RWUCTalXMxcP0 3R0g== X-Gm-Message-State: AGi0PubWI9EPYVg67scmqAfz6uMAfDhWwXexhLY5v1sU4+prKasvd/np tGdyOoRN5j2sKRdQZSS1LlgE/SjNS/4= X-Google-Smtp-Source: APiQypL+6WJmum4S4Lp8c1UA4uB8kZY4IOWco9PVZueHJf77++cWuk8UFJRu+Z2ujqjmdlZiGd4JhQ== X-Received: by 2002:aed:3788:: with SMTP id j8mr24430376qtb.113.1589331355391; Tue, 12 May 2020 17:55:55 -0700 (PDT) From: Nick Rosbrook X-Google-Original-From: Nick Rosbrook To: xen-devel@lists.xenproject.org Subject: [PATCH v3 1/1] golang/xenlight: add NameToDomid and DomidToName util functions Date: Tue, 12 May 2020 20:55:50 -0400 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Nick Rosbrook , Ian Jackson , George Dunlap , Wei Liu Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Many exported functions in xenlight require a domid as an argument. Make it easier for package users to use these functions by adding wrappers for the libxl utility functions libxl_name_to_domid and libxl_domid_to_name. Signed-off-by: Nick Rosbrook Reviewed-by: George Dunlap --- tools/golang/xenlight/xenlight.go | 40 ++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenl= ight.go index 6b4f492550..742e5e11f1 100644 --- a/tools/golang/xenlight/xenlight.go +++ b/tools/golang/xenlight/xenlight.go @@ -21,13 +21,15 @@ package xenlight #cgo LDFLAGS: -lxenlight -lyajl -lxentoollog #include #include +#include + +#define INVALID_DOMID_TYPED ((uint32_t) INVALID_DOMID) =20 static const libxl_childproc_hooks childproc_hooks =3D { .chldowner =3D li= bxl_sigchld_owner_mainloop }; =20 void xenlight_set_chldproc(libxl_ctx *ctx) { libxl_childproc_setmode(ctx, &childproc_hooks, NULL); } - */ import "C" =20 @@ -75,6 +77,10 @@ var libxlErrors =3D map[Error]string{ ErrorFeatureRemoved: "Feature removed", } =20 +const ( + DomidInvalid Domid =3D Domid(C.INVALID_DOMID_TYPED) +) + func (e Error) Error() string { if s, ok :=3D libxlErrors[e]; ok { return s @@ -190,6 +196,38 @@ func (ctx *Context) Close() error { =20 type Domid uint32 =20 +// NameToDomid returns the Domid for a domain, given its name, if it exist= s. +// +// NameToDomid does not guarantee that the domid associated with name at +// the time NameToDomid is called is the same as the domid associated with +// name at the time NameToDomid returns. +func (Ctx *Context) NameToDomid(name string) (Domid, error) { + var domid C.uint32_t + + cname :=3D C.CString(name) + defer C.free(unsafe.Pointer(cname)) + + if ret :=3D C.libxl_name_to_domid(Ctx.ctx, cname, &domid); ret !=3D 0 { + return DomidInvalid, Error(ret) + } + + return Domid(domid), nil +} + +// DomidToName returns the name for a domain, given its domid. If there +// is no domain with the given domid, DomidToName will return the empty +// string. +// +// DomidToName does not guarantee that the name (if any) associated with d= omid +// at the time DomidToName is called is the same as the name (if any) asso= ciated +// with domid at the time DomidToName returns. +func (Ctx *Context) DomidToName(domid Domid) string { + cname :=3D C.libxl_domid_to_name(Ctx.ctx, C.uint32_t(domid)) + defer C.free(unsafe.Pointer(cname)) + + return C.GoString(cname) +} + // Devid is a device ID. type Devid int =20 --=20 2.17.1