diff mbox

[v2,09/13] xenstore: make use of the "xenstore domain" flag

Message ID 1450444471-6454-10-git-send-email-jgross@suse.com (mailing list archive)
State New, archived
Headers show

Commit Message

Juergen Gross Dec. 18, 2015, 1:14 p.m. UTC
Create the xenstore domain with the xs_domain 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 <jgross@suse.com>
---
 tools/helpers/init-xenstore-domain.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

Comments

Ian Campbell Jan. 6, 2016, 4:23 p.m. UTC | #1
On Fri, 2015-12-18 at 14:14 +0100, Juergen Gross wrote:
> Create the xenstore domain with the xs_domain 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 <jgross@suse.com>
> ---
>  tools/helpers/init-xenstore-domain.c | 25 +++++++++++++++++++++++--
>  1 file changed, 23 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/helpers/init-xenstore-domain.c b/tools/helpers/init-
> xenstore-domain.c
> index 17f0151..4cd9e0f 100644
> --- a/tools/helpers/init-xenstore-domain.c
> +++ b/tools/helpers/init-xenstore-domain.c
> @@ -66,7 +66,8 @@ static int build(xc_interface *xch)
>      } else {
>          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");
>          goto err;
> @@ -165,6 +166,21 @@ err:
>      return rv;
>  }
>  
> +static int check_domain(xc_interface *xch)
> +{
> +    xc_dominfo_t info;
> +    uint32_t dom;
> +
> +    dom = 0;

You can pretty safely skip dom0 I think?

> +    while (xc_domain_getinfo(xch, dom, 1, &info) == 1) {

Logging errors (i.e. on return < 0) would be nice I think.

> +        if (info.xs_domain)
> +            return 1;
> +        dom = info.domid + 1;
> +    }
> +
> +    return 0;
> +}
> +
>  int main(int argc, char** argv)
>  {
>      int opt;
> @@ -204,7 +220,12 @@ int main(int argc, char** argv)
>          return 1;
>      }
>  
> -    rv = build(xch);
> +    rv = check_domain(xch);
> +
> +    if (!rv)
> +        rv = build(xch);
> +    else
> +        fprintf(stderr, "xenstore domain already present.\n");
>  
>      xc_interface_close(xch);
>
Juergen Gross Jan. 7, 2016, 6:36 a.m. UTC | #2
On 06/01/16 17:23, Ian Campbell wrote:
> On Fri, 2015-12-18 at 14:14 +0100, Juergen Gross wrote:
>> Create the xenstore domain with the xs_domain 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 <jgross@suse.com>
>> ---
>>  tools/helpers/init-xenstore-domain.c | 25 +++++++++++++++++++++++--
>>  1 file changed, 23 insertions(+), 2 deletions(-)
>>
>> diff --git a/tools/helpers/init-xenstore-domain.c b/tools/helpers/init-
>> xenstore-domain.c
>> index 17f0151..4cd9e0f 100644
>> --- a/tools/helpers/init-xenstore-domain.c
>> +++ b/tools/helpers/init-xenstore-domain.c
>> @@ -66,7 +66,8 @@ static int build(xc_interface *xch)
>>      } else {
>>          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");
>>          goto err;
>> @@ -165,6 +166,21 @@ err:
>>      return rv;
>>  }
>>  
>> +static int check_domain(xc_interface *xch)
>> +{
>> +    xc_dominfo_t info;
>> +    uint32_t dom;
>> +
>> +    dom = 0;
> 
> You can pretty safely skip dom0 I think?

Hmm, yes.

> 
>> +    while (xc_domain_getinfo(xch, dom, 1, &info) == 1) {
> 
> Logging errors (i.e. on return < 0) would be nice I think.

Okay.


Juergen
diff mbox

Patch

diff --git a/tools/helpers/init-xenstore-domain.c b/tools/helpers/init-xenstore-domain.c
index 17f0151..4cd9e0f 100644
--- a/tools/helpers/init-xenstore-domain.c
+++ b/tools/helpers/init-xenstore-domain.c
@@ -66,7 +66,8 @@  static int build(xc_interface *xch)
     } else {
         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");
         goto err;
@@ -165,6 +166,21 @@  err:
     return rv;
 }
 
+static int check_domain(xc_interface *xch)
+{
+    xc_dominfo_t info;
+    uint32_t dom;
+
+    dom = 0;
+    while (xc_domain_getinfo(xch, dom, 1, &info) == 1) {
+        if (info.xs_domain)
+            return 1;
+        dom = info.domid + 1;
+    }
+
+    return 0;
+}
+
 int main(int argc, char** argv)
 {
     int opt;
@@ -204,7 +220,12 @@  int main(int argc, char** argv)
         return 1;
     }
 
-    rv = build(xch);
+    rv = check_domain(xch);
+
+    if (!rv)
+        rv = build(xch);
+    else
+        fprintf(stderr, "xenstore domain already present.\n");
 
     xc_interface_close(xch);