From mboxrd@z Thu Jan 1 00:00:00 1970 From: Juergen Gross Subject: [PATCH v2 03/13] libxl: provide a function to retrieve the xenstore domain id Date: Fri, 18 Dec 2015 14:14:21 +0100 Message-ID: <1450444471-6454-4-git-send-email-jgross@suse.com> References: <1450444471-6454-1-git-send-email-jgross@suse.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1450444471-6454-1-git-send-email-jgross@suse.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org, Ian.Campbell@citrix.com, ian.jackson@eu.citrix.com, stefano.stabellini@eu.citrix.com, wei.liu2@citrix.com, dgdegra@tycho.nsa.gov Cc: Juergen Gross List-Id: xen-devel@lists.xenproject.org Add libxl_xenstore_domid() to obtain the domain id of the xenstore domain. Signed-off-by: Juergen Gross --- tools/libxl/libxl.c | 24 ++++++++++++++++++++++++ tools/libxl/libxl.h | 11 +++++++++++ 2 files changed, 35 insertions(+) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 9207621..3bcff59 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -701,6 +701,30 @@ int libxl_domain_info(libxl_ctx *ctx, libxl_dominfo *info_r, return 0; } +int libxl_xenstore_domid(libxl_ctx *ctx, uint32_t *domid) +{ + xc_dominfo_t info; + uint32_t last_domid; + int ret; + GC_INIT(ctx); + + for (last_domid = 0; + (ret = xc_domain_getinfo(ctx->xch, last_domid, 1, &info)) == 1; + last_domid = info.domid + 1) + { + if (info.xs_domain) + { + *domid = info.domid; + ret = 0; + goto out; + } + } + ret = (ret == 0) ? ERROR_DOMAIN_NOTFOUND : ERROR_FAIL; +out: + GC_FREE; + return ret; +} + /* Returns: * 0 - success * ERROR_FAIL + errno == ENOENT - no entry found diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 05606a7..41e9d88 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -867,6 +867,13 @@ void libxl_mac_copy(libxl_ctx *ctx, libxl_mac *dst, libxl_mac *src); */ #define LIBXL_HAVE_DEVICE_MODEL_VERSION_NONE 1 +/* + * LIBXL_HAVE_XENSTORE_DOMID + * + * If this is defined, then libxl_xenstore_domid is available. + */ +#define LIBXL_HAVE_XENSTORE_DOMID + typedef char **libxl_string_list; void libxl_string_list_dispose(libxl_string_list *sl); int libxl_string_list_length(const libxl_string_list *sl); @@ -1306,6 +1313,10 @@ int libxl_console_get_tty(libxl_ctx *ctx, uint32_t domid, int cons_num, */ int libxl_primary_console_get_tty(libxl_ctx *ctx, uint32_t domid_vm, char **path); +/* Save domid of a possible Xenstore domain. If no Xenstore domain exists, + * ERROR_DOMAIN_NOTFOUND is returned. */ +int libxl_xenstore_domid(libxl_ctx *ctx, uint32_t *domid); + /* May be called with info_r == NULL to check for domain's existence. * Returns ERROR_DOMAIN_NOTFOUND if domain does not exist (used to return * ERROR_INVAL for this scenario). */ -- 2.6.2