From mboxrd@z Thu Jan 1 00:00:00 1970 From: Juergen Gross Subject: [PATCH v3 10/15] xenstore: make use of the "xenstore domain" flag Date: Fri, 8 Jan 2016 14:08:41 +0100 Message-ID: <1452258526-4797-11-git-send-email-jgross@suse.com> References: <1452258526-4797-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: <1452258526-4797-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 Create the xenstore domain with the xenstore flag specified. This enables us to test whether such a domain is already running before we create it. As there ought to be only one xenstore in the system we don't need to start another one. Signed-off-by: Juergen Gross --- V3: omit dom0 when checking for xenstore domain as suggested by Ian Campbell log an error in case of an error when obtaining domain info as requested by Ian Campbell --- tools/helpers/init-xenstore-domain.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/tools/helpers/init-xenstore-domain.c b/tools/helpers/init-xenstore-domain.c index ff9968f..ecced04 100644 --- a/tools/helpers/init-xenstore-domain.c +++ b/tools/helpers/init-xenstore-domain.c @@ -71,7 +71,8 @@ static int build(xc_interface *xch) { ssid = SECINITSID_DOMU; } - rv = xc_domain_create(xch, ssid, handle, 0, &domid, NULL); + rv = xc_domain_create(xch, ssid, handle, XEN_DOMCTL_CDF_xs_domain, + &domid, NULL); if ( rv ) { fprintf(stderr, "xc_domain_create failed\n"); @@ -186,6 +187,28 @@ err: return rv; } +static int check_domain(xc_interface *xch) +{ + xc_dominfo_t info; + uint32_t dom; + int ret; + + dom = 1; + while ( (ret = xc_domain_getinfo(xch, dom, 1, &info)) == 1 ) + { + if ( info.xenstore ) + return 1; + dom = info.domid + 1; + } + if ( ret < 0 && errno != ESRCH ) + { + fprintf(stderr, "xc_domain_getinfo failed\n"); + return ret; + } + + return 0; +} + int main(int argc, char** argv) { int opt; @@ -229,7 +252,12 @@ int main(int argc, char** argv) return 1; } - rv = build(xch); + rv = check_domain(xch); + + if ( !rv ) + rv = build(xch); + else if ( rv > 0 ) + fprintf(stderr, "xenstore domain already present.\n"); xc_interface_close(xch); -- 2.6.2