All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 00/15] xenstore: make it easier to run xenstore in a domain
@ 2016-01-08 13:08 Juergen Gross
  2016-01-08 13:08 ` [PATCH v3 01/15] xen: add xenstore domain flag to hypervisor Juergen Gross
                   ` (15 more replies)
  0 siblings, 16 replies; 35+ messages in thread
From: Juergen Gross @ 2016-01-08 13:08 UTC (permalink / raw)
  To: xen-devel, Ian.Campbell, ian.jackson, stefano.stabellini,
	wei.liu2, dgdegra
  Cc: Juergen Gross

Xen supports to run xenstore in a dedicated domain. It is, however, a
setup which isn't easy to configure. Today flask is required for full
functionality and the resulting xenstore domain is not configurable in
the same way as the xenstore daemon.

This patch series enables running a xenstore domain without flask. The
tool needed to start that domain is added to the installed binaries
and it is modified to pass arbitrary options to the xenstore domain.

I didn't include a configuration option for starting xenstore as an
own domain instead of the daemon, as this will require some major
tweaking of especially the systemd configuration files. Support for
this will be added later. The main issue is that running xenstore in
a domain requires the xenstore sockets not to be created. I don't
think this is possible with the current scheme of letting systemd
create those sockets.

Changes in V3:
- patch 1: changed comment as requested by Ian Campbell
- patch 2: changed name of flag from "xs_domain" to "xenstore" as requested
           by Ian Campbell
- patch 3: flag in dominfo instead function to get xenstore domid as requested
           by Ian Campbell
- patch 4: don't adapt coding style as requested by Ian Campbell
           adjust .gitignore
- new patch 5: adapt coding style of init-xenstore-domain.c
- patch 6 (was 5): adjust .gitignore as requested by Ian Campbell
           use libxentoollog instead of libxc as requested by Ian Campbell
- patch 10 (was 9): 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
- patch 14 (was 13): xl shutdown modified to query the "never_stop" flag
           instead of the xenstore domain id as requested by Ian Campbell
           drop usage of xenstore-exists as requested by Ian Campbell
- new patch 15: add xenstore domain xenstroe paths to docs as requested by
           Ian Campbell

Changes in V2:
- add new patch 3 to get the xenstore domain id via libxl
- move init-xenstore-domain to new directory tools/helpers in patch 4
  (former patch 3) and modify it to use the standard tools coding style
- add new patch 5 moving xen-init-dom0 to tools/helpers
- split patch 6 (former patch 4) into 2 patches as requested by Ian Campbell
- correct parameter parsing in patch 8 (former patch 5)
- modified commit message of patch 9 (former patch 6) as requested by
  Ian Campbell
- add new patch 11 to split up xen-init-dom0
- modify patch 12 (former patch 8) to create json object and more xenstore
  entries, add error messages as requested by Ian Campbell
- drop former patch 9
- add new patch 13 to avoid stopping xenstore domain on dom0 shutdown

Juergen Gross (15):
  xen: add xenstore domain flag to hypervisor
  libxc: support new xenstore domain flag in libxc
  libxl: provide a flag in dominfo to avoid stopping it
  xenstore: move init-xenstore-domain to tools/helpers
  xenstore: adjust coding style of init-xenstore-domain.c
  libxl: move xen-init-dom0 to tools/helpers
  xenstore: destroy xenstore domain in case of error after creating it
  xenstore: add error messages to init-xenstore-domain
  xenstore: modify init-xenstore-domain parameter syntax
  xenstore: make use of the "xenstore domain" flag
  xenstore: add init-xenstore-domain parameter to specify cmdline
  tools: split up xen-init-dom0.c
  xenstore: write xenstore domain data to xenstore
  tools: don't stop xenstore domain when stopping dom0
  docs: document xenstore domain xenstore paths

 .gitignore                            |   4 +-
 docs/misc/xenstore-paths.markdown     |  10 +
 tools/Makefile                        |   1 +
 tools/helpers/Makefile                |  46 +++++
 tools/helpers/init-dom-json.c         |  59 ++++++
 tools/helpers/init-dom-json.h         |  18 ++
 tools/helpers/init-xenstore-domain.c  | 343 ++++++++++++++++++++++++++++++++++
 tools/helpers/xen-init-dom0.c         |  67 +++++++
 tools/hotplug/Linux/xendomains.in     |  15 ++
 tools/libxc/include/xenctrl.h         |   2 +-
 tools/libxc/xc_domain.c               |   1 +
 tools/libxl/Makefile                  |  14 +-
 tools/libxl/libxl.c                   |  11 +-
 tools/libxl/libxl.h                   |   9 +
 tools/libxl/libxl_types.idl           |   1 +
 tools/libxl/xen-init-dom0.c           | 120 ------------
 tools/libxl/xl_cmdimpl.c              |   8 +-
 tools/xenstore/Makefile               |   9 -
 tools/xenstore/init-xenstore-domain.c | 119 ------------
 xen/common/domain.c                   |   6 +
 xen/common/domctl.c                   |  14 +-
 xen/include/public/domctl.h           |   6 +
 xen/include/xen/sched.h               |   5 +
 xen/include/xsm/dummy.h               |   6 +
 xen/include/xsm/xsm.h                 |   1 +
 25 files changed, 620 insertions(+), 275 deletions(-)
 create mode 100644 tools/helpers/Makefile
 create mode 100644 tools/helpers/init-dom-json.c
 create mode 100644 tools/helpers/init-dom-json.h
 create mode 100644 tools/helpers/init-xenstore-domain.c
 create mode 100644 tools/helpers/xen-init-dom0.c
 delete mode 100644 tools/libxl/xen-init-dom0.c
 delete mode 100644 tools/xenstore/init-xenstore-domain.c

-- 
2.6.2

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [PATCH v3 01/15] xen: add xenstore domain flag to hypervisor
  2016-01-08 13:08 [PATCH v3 00/15] xenstore: make it easier to run xenstore in a domain Juergen Gross
@ 2016-01-08 13:08 ` Juergen Gross
  2016-01-08 14:07   ` Jan Beulich
                     ` (2 more replies)
  2016-01-08 13:08 ` [PATCH v3 02/15] libxc: support new xenstore domain flag in libxc Juergen Gross
                   ` (14 subsequent siblings)
  15 siblings, 3 replies; 35+ messages in thread
From: Juergen Gross @ 2016-01-08 13:08 UTC (permalink / raw)
  To: xen-devel, Ian.Campbell, ian.jackson, stefano.stabellini,
	wei.liu2, dgdegra
  Cc: Juergen Gross, Keir Fraser, Andrew Cooper, Tim Deegan,
	David Vrabel, Jan Beulich

In order to be able to have full support of a xenstore domain in Xen
add a "Xenstore-domain" flag to the hypervisor. This flag must be
specified at domain creation time and is returned by
XEN_DOMCTL_getdomaininfo.

It will allow the domain to retrieve domain information by issuing the
XEN_DOMCTL_getdomaininfo itself in order to be able to check for
domains having been destroyed. At the same time this flag will inhibit
the domain to be migrated, as this wouldn't be a very wise thing to do.

In case of a later support of a rebootable Dom0 this flag will allow to
recognize a xenstore domain already being present to connect to.

Cc: Jan Beulich <jbeulich@suse.com>
Cc: Keir Fraser <keir@xen.org>
Cc: Tim Deegan <tim@xen.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: David Vrabel <david.vrabel@citrix.com>

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
Reviewed-by: Andrew Cooper <andrew.cooper3@citirx.com>
---
V3: changed comment as requested by Ian Campbell
---
 xen/common/domain.c         |  6 ++++++
 xen/common/domctl.c         | 14 +++++++++-----
 xen/include/public/domctl.h |  6 ++++++
 xen/include/xen/sched.h     |  5 +++++
 xen/include/xsm/dummy.h     |  6 ++++++
 xen/include/xsm/xsm.h       |  1 +
 6 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/xen/common/domain.c b/xen/common/domain.c
index 1017efb..2979c1b 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -318,6 +318,12 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
         hardware_domain = d;
     }
 
+    if ( domcr_flags & DOMCRF_xs_domain )
+    {
+        d->is_xenstore = 1;
+        d->disable_migrate = 1;
+    }
+
     rangeset_domain_initialise(d);
     init_status |= INIT_rangeset;
 
diff --git a/xen/common/domctl.c b/xen/common/domctl.c
index 1fab587..dc1ea06 100644
--- a/xen/common/domctl.c
+++ b/xen/common/domctl.c
@@ -183,10 +183,11 @@ void getdomaininfo(struct domain *d, struct xen_domctl_getdomaininfo *info)
     info->cpu_time = cpu_time;
 
     info->flags = (info->nr_online_vcpus ? flags : 0) |
-        ((d->is_dying == DOMDYING_dead) ? XEN_DOMINF_dying    : 0) |
-        (d->is_shut_down                ? XEN_DOMINF_shutdown : 0) |
-        (d->controller_pause_count > 0  ? XEN_DOMINF_paused   : 0) |
-        (d->debugger_attached           ? XEN_DOMINF_debugged : 0) |
+        ((d->is_dying == DOMDYING_dead) ? XEN_DOMINF_dying     : 0) |
+        (d->is_shut_down                ? XEN_DOMINF_shutdown  : 0) |
+        (d->controller_pause_count > 0  ? XEN_DOMINF_paused    : 0) |
+        (d->debugger_attached           ? XEN_DOMINF_debugged  : 0) |
+        (d->is_xenstore                 ? XEN_DOMINF_xs_domain : 0) |
         d->shutdown_code << XEN_DOMINF_shutdownshift;
 
     switch ( d->guest_type )
@@ -551,7 +552,8 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
                | XEN_DOMCTL_CDF_pvh_guest
                | XEN_DOMCTL_CDF_hap
                | XEN_DOMCTL_CDF_s3_integrity
-               | XEN_DOMCTL_CDF_oos_off)) )
+               | XEN_DOMCTL_CDF_oos_off
+               | XEN_DOMCTL_CDF_xs_domain)) )
             break;
 
         dom = op->domain;
@@ -593,6 +595,8 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
             domcr_flags |= DOMCRF_s3_integrity;
         if ( op->u.createdomain.flags & XEN_DOMCTL_CDF_oos_off )
             domcr_flags |= DOMCRF_oos_off;
+        if ( op->u.createdomain.flags & XEN_DOMCTL_CDF_xs_domain )
+            domcr_flags |= DOMCRF_xs_domain;
 
         d = domain_create(dom, domcr_flags, op->u.createdomain.ssidref,
                           &op->u.createdomain.config);
diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h
index 7a56b3f..2d8076c 100644
--- a/xen/include/public/domctl.h
+++ b/xen/include/public/domctl.h
@@ -63,6 +63,9 @@ struct xen_domctl_createdomain {
  /* Is this a PVH guest (as opposed to an HVM or PV guest)? */
 #define _XEN_DOMCTL_CDF_pvh_guest     4
 #define XEN_DOMCTL_CDF_pvh_guest      (1U<<_XEN_DOMCTL_CDF_pvh_guest)
+ /* Is this a xenstore domain? */
+#define _XEN_DOMCTL_CDF_xs_domain     5
+#define XEN_DOMCTL_CDF_xs_domain      (1U<<_XEN_DOMCTL_CDF_xs_domain)
     uint32_t flags;
     struct xen_arch_domainconfig config;
 };
@@ -97,6 +100,9 @@ struct xen_domctl_getdomaininfo {
 /* domain is PVH */
 #define _XEN_DOMINF_pvh_guest 7
 #define XEN_DOMINF_pvh_guest  (1U<<_XEN_DOMINF_pvh_guest)
+/* domain is a xenstore domain */
+#define _XEN_DOMINF_xs_domain 8
+#define XEN_DOMINF_xs_domain  (1U<<_XEN_DOMINF_xs_domain)
  /* XEN_DOMINF_shutdown guest-supplied code.  */
 #define XEN_DOMINF_shutdownmask 255
 #define XEN_DOMINF_shutdownshift 16
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index e1428f7..82b6dd1 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -374,6 +374,8 @@ struct domain
     bool_t           auto_node_affinity;
     /* Is this guest fully privileged (aka dom0)? */
     bool_t           is_privileged;
+    /* Is this a xenstore domain (not dom0)? */
+    bool_t           is_xenstore;
     /* Domain's VCPUs are pinned 1:1 to physical CPUs? */
     bool_t           is_pinned;
     /* Non-migratable and non-restoreable? */
@@ -533,6 +535,9 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
  /* DOMCRF_pvh: Create PV domain in HVM container. */
 #define _DOMCRF_pvh             5
 #define DOMCRF_pvh              (1U<<_DOMCRF_pvh)
+ /* DOMCRF_xs_domain: xenstore domain */
+#define _DOMCRF_xs_domain       6
+#define DOMCRF_xs_domain        (1U<<_DOMCRF_xs_domain)
 
 /*
  * rcu_lock_domain_by_id() is more efficient than get_domain_by_id().
diff --git a/xen/include/xsm/dummy.h b/xen/include/xsm/dummy.h
index 55b84f0..1d13826 100644
--- a/xen/include/xsm/dummy.h
+++ b/xen/include/xsm/dummy.h
@@ -71,6 +71,10 @@ static always_inline int xsm_default_action(
         if ( src->is_privileged )
             return 0;
         return -EPERM;
+    case XSM_XS_PRIV:
+        if ( src->is_xenstore || src->is_privileged )
+            return 0;
+        return -EPERM;
     default:
         LINKER_BUG_ON(1);
         return -EPERM;
@@ -123,6 +127,8 @@ static XSM_INLINE int xsm_domctl(XSM_DEFAULT_ARG struct domain *d, int cmd)
     case XEN_DOMCTL_bind_pt_irq:
     case XEN_DOMCTL_unbind_pt_irq:
         return xsm_default_action(XSM_DM_PRIV, current->domain, d);
+    case XEN_DOMCTL_getdomaininfo:
+        return xsm_default_action(XSM_XS_PRIV, current->domain, d);
     default:
         return xsm_default_action(XSM_PRIV, current->domain, d);
     }
diff --git a/xen/include/xsm/xsm.h b/xen/include/xsm/xsm.h
index 2c365cd..3afed70 100644
--- a/xen/include/xsm/xsm.h
+++ b/xen/include/xsm/xsm.h
@@ -35,6 +35,7 @@ enum xsm_default {
     XSM_DM_PRIV,  /* Device model can perform on its target domain */
     XSM_TARGET,   /* Can perform on self or your target domain */
     XSM_PRIV,     /* Privileged - normally restricted to dom0 */
+    XSM_XS_PRIV,  /* Xenstore domain - can do some privileged operations */
     XSM_OTHER     /* Something more complex */
 };
 typedef enum xsm_default xsm_default_t;
-- 
2.6.2

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v3 02/15] libxc: support new xenstore domain flag in libxc
  2016-01-08 13:08 [PATCH v3 00/15] xenstore: make it easier to run xenstore in a domain Juergen Gross
  2016-01-08 13:08 ` [PATCH v3 01/15] xen: add xenstore domain flag to hypervisor Juergen Gross
@ 2016-01-08 13:08 ` Juergen Gross
  2016-01-08 13:08 ` [PATCH v3 03/15] libxl: provide a flag in dominfo to avoid stopping it Juergen Gross
                   ` (13 subsequent siblings)
  15 siblings, 0 replies; 35+ messages in thread
From: Juergen Gross @ 2016-01-08 13:08 UTC (permalink / raw)
  To: xen-devel, Ian.Campbell, ian.jackson, stefano.stabellini,
	wei.liu2, dgdegra
  Cc: Juergen Gross

Support the xenstore domain flag for obtaining domain info.

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
---
V3: changed name of flag from "xs_domain" to "xenstore" as requested
    by Ian Campbell
---
 tools/libxc/include/xenctrl.h | 2 +-
 tools/libxc/xc_domain.c       | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h
index 01a6dda..079cad0 100644
--- a/tools/libxc/include/xenctrl.h
+++ b/tools/libxc/include/xenctrl.h
@@ -456,7 +456,7 @@ typedef struct xc_dominfo {
     uint32_t      ssidref;
     unsigned int  dying:1, crashed:1, shutdown:1,
                   paused:1, blocked:1, running:1,
-                  hvm:1, debugged:1, pvh:1;
+                  hvm:1, debugged:1, pvh:1, xenstore:1;
     unsigned int  shutdown_reason; /* only meaningful if shutdown==1 */
     unsigned long nr_pages; /* current number, not maximum */
     unsigned long nr_outstanding_pages;
diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c
index 96506d5..99e0d48 100644
--- a/tools/libxc/xc_domain.c
+++ b/tools/libxc/xc_domain.c
@@ -374,6 +374,7 @@ int xc_domain_getinfo(xc_interface *xch,
         info->hvm      = !!(domctl.u.getdomaininfo.flags&XEN_DOMINF_hvm_guest);
         info->debugged = !!(domctl.u.getdomaininfo.flags&XEN_DOMINF_debugged);
         info->pvh      = !!(domctl.u.getdomaininfo.flags&XEN_DOMINF_pvh_guest);
+        info->xenstore = !!(domctl.u.getdomaininfo.flags&XEN_DOMINF_xs_domain);
 
         info->shutdown_reason =
             (domctl.u.getdomaininfo.flags>>XEN_DOMINF_shutdownshift) &
-- 
2.6.2

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v3 03/15] libxl: provide a flag in dominfo to avoid stopping it
  2016-01-08 13:08 [PATCH v3 00/15] xenstore: make it easier to run xenstore in a domain Juergen Gross
  2016-01-08 13:08 ` [PATCH v3 01/15] xen: add xenstore domain flag to hypervisor Juergen Gross
  2016-01-08 13:08 ` [PATCH v3 02/15] libxc: support new xenstore domain flag in libxc Juergen Gross
@ 2016-01-08 13:08 ` Juergen Gross
  2016-01-15 15:51   ` Ian Campbell
  2016-01-08 13:08 ` [PATCH v3 04/15] xenstore: move init-xenstore-domain to tools/helpers Juergen Gross
                   ` (12 subsequent siblings)
  15 siblings, 1 reply; 35+ messages in thread
From: Juergen Gross @ 2016-01-08 13:08 UTC (permalink / raw)
  To: xen-devel, Ian.Campbell, ian.jackson, stefano.stabellini,
	wei.liu2, dgdegra
  Cc: Juergen Gross

Add a "never_stop" flag to dominfo as indicator for the toolstack that
this domain is to be kept running. For now it is being set for xenstore
domain, but there might be other domains in the future.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
V3: flag in dominfo instead function to get xenstore domid as requested
    by Ian Campbell
---
 tools/libxl/libxl.c         | 11 ++++++-----
 tools/libxl/libxl.h         |  9 +++++++++
 tools/libxl/libxl_types.idl |  1 +
 3 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 9207621..d2d03e4 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -623,11 +623,12 @@ static void xcinfo2xlinfo(libxl_ctx *ctx,
                                    &xlinfo->ssid_label, &size) < 0)
         xlinfo->ssid_label = NULL;
 
-    xlinfo->dying    = !!(xcinfo->flags&XEN_DOMINF_dying);
-    xlinfo->shutdown = !!(xcinfo->flags&XEN_DOMINF_shutdown);
-    xlinfo->paused   = !!(xcinfo->flags&XEN_DOMINF_paused);
-    xlinfo->blocked  = !!(xcinfo->flags&XEN_DOMINF_blocked);
-    xlinfo->running  = !!(xcinfo->flags&XEN_DOMINF_running);
+    xlinfo->dying      = !!(xcinfo->flags&XEN_DOMINF_dying);
+    xlinfo->shutdown   = !!(xcinfo->flags&XEN_DOMINF_shutdown);
+    xlinfo->paused     = !!(xcinfo->flags&XEN_DOMINF_paused);
+    xlinfo->blocked    = !!(xcinfo->flags&XEN_DOMINF_blocked);
+    xlinfo->running    = !!(xcinfo->flags&XEN_DOMINF_running);
+    xlinfo->never_stop = !!(xcinfo->flags&XEN_DOMINF_xs_domain);
 
     if (xlinfo->shutdown)
         xlinfo->shutdown_reason = (xcinfo->flags>>XEN_DOMINF_shutdownshift) & XEN_DOMINF_shutdownmask;
diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
index 05606a7..7114491 100644
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -560,6 +560,15 @@ typedef struct libxl__ctx libxl_ctx;
 #define LIBXL_HAVE_DOMINFO_OUTSTANDING_MEMKB 1
 
 /*
+ * LIBXL_HAVE_DOMINFO_NEVER_STOP
+ *
+ * If this is defined, libxl_dominfo will contain a flag called never_stop
+ * indicating that the specific domain should never be stopped by the
+ * toolstack.
+ */
+#define LIBXL_HAVE_DOMINFO_NEVER_STOP 1
+
+/*
  * LIBXL_HAVE_QXL
  *
  * If defined, then the libxl_vga_interface_type will contain another value:
diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
index 9658356..9ad7eba 100644
--- a/tools/libxl/libxl_types.idl
+++ b/tools/libxl/libxl_types.idl
@@ -295,6 +295,7 @@ libxl_dominfo = Struct("dominfo",[
     ("paused",      bool),
     ("shutdown",    bool),
     ("dying",       bool),
+    ("never_stop",  bool),
 
     # Valid iff ->shutdown is true.
     #
-- 
2.6.2

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v3 04/15] xenstore: move init-xenstore-domain to tools/helpers
  2016-01-08 13:08 [PATCH v3 00/15] xenstore: make it easier to run xenstore in a domain Juergen Gross
                   ` (2 preceding siblings ...)
  2016-01-08 13:08 ` [PATCH v3 03/15] libxl: provide a flag in dominfo to avoid stopping it Juergen Gross
@ 2016-01-08 13:08 ` Juergen Gross
  2016-01-15 15:51   ` Ian Campbell
  2016-01-08 13:08 ` [PATCH v3 05/15] xenstore: adjust coding style of init-xenstore-domain.c Juergen Gross
                   ` (11 subsequent siblings)
  15 siblings, 1 reply; 35+ messages in thread
From: Juergen Gross @ 2016-01-08 13:08 UTC (permalink / raw)
  To: xen-devel, Ian.Campbell, ian.jackson, stefano.stabellini,
	wei.liu2, dgdegra
  Cc: Juergen Gross

The program init-xenstore-domain to start a xenstore domain instead
of the xenstored daemon is built, but not installed. Change that.

Move the program to a new tools subdirectory "helpers" to be able to
use libxl in a later patch. Otherwise a dependency loop will be
created.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
V3: don't adapt coding style as requested by Ian Campbell
    adjust .gitignore
---
 .gitignore                                         |  2 +-
 tools/Makefile                                     |  1 +
 tools/helpers/Makefile                             | 34 ++++++++++++++++++++++
 tools/{xenstore => helpers}/init-xenstore-domain.c |  0
 tools/xenstore/Makefile                            |  9 ------
 5 files changed, 36 insertions(+), 10 deletions(-)
 create mode 100644 tools/helpers/Makefile
 rename tools/{xenstore => helpers}/init-xenstore-domain.c (100%)

diff --git a/.gitignore b/.gitignore
index e0df903..ec1cde3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -132,6 +132,7 @@ tools/flask/utils/flask-loadpolicy
 tools/flask/utils/flask-setenforce
 tools/flask/utils/flask-set-bool
 tools/flask/utils/flask-label-pci
+tools/helpers/init-xenstore-domain
 tools/hotplug/common/hotplugpath.sh
 tools/hotplug/FreeBSD/rc.d/xencommons
 tools/hotplug/FreeBSD/rc.d/xendriverdomain
@@ -200,7 +201,6 @@ tools/xenmon/xenbaked
 tools/xenpaging/xenpaging
 tools/xenpmd/xenpmd
 tools/xenstat/xentop/xentop
-tools/xenstore/init-xenstore-domain
 tools/xenstore/xenstore
 tools/xenstore/xenstore-chmod
 tools/xenstore/xenstore-exists
diff --git a/tools/Makefile b/tools/Makefile
index 9f74ac7..124919b 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -30,6 +30,7 @@ endif
 
 SUBDIRS-y += xenpmd
 SUBDIRS-y += libxl
+SUBDIRS-y += helpers
 SUBDIRS-$(CONFIG_X86) += xenpaging
 SUBDIRS-$(CONFIG_X86) += debugger/gdbsx
 SUBDIRS-$(CONFIG_X86) += debugger/kdd
diff --git a/tools/helpers/Makefile b/tools/helpers/Makefile
new file mode 100644
index 0000000..52347fd
--- /dev/null
+++ b/tools/helpers/Makefile
@@ -0,0 +1,34 @@
+#
+# tools/helpers/Makefile
+#
+
+XEN_ROOT = $(CURDIR)/../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+ifeq ($(CONFIG_Linux),y)
+PROGS += init-xenstore-domain
+endif
+
+INIT_XENSTORE_DOMAIN_OBJS = init-xenstore-domain.o
+$(INIT_XENSTORE_DOMAIN_OBJS): CFLAGS += $(CFLAGS_libxenguest)
+$(INIT_XENSTORE_DOMAIN_OBJS): CFLAGS += $(CFLAGS_libxenctrl)
+$(INIT_XENSTORE_DOMAIN_OBJS): CFLAGS += $(CFLAGS_libxenstore)
+
+.PHONY: all
+all: $(PROGS)
+
+init-xenstore-domain: $(INIT_XENSTORE_DOMAIN_OBJS)
+	$(CC) $(LDFLAGS) -o $@ $(INIT_XENSTORE_DOMAIN_OBJS) $(LDLIBS_libxenstore) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(APPEND_LDFLAGS)
+
+.PHONY: install
+install: all
+	$(INSTALL_DIR) $(DESTDIR)$(LIBEXEC_BIN)
+ifeq ($(CONFIG_Linux),y)
+	$(INSTALL_PROG) init-xenstore-domain $(DESTDIR)$(LIBEXEC_BIN)
+endif
+
+.PHONY: clean
+clean:
+	$(RM) -f *.o $(PROGS) $(DEPS)
+
+distclean: clean
diff --git a/tools/xenstore/init-xenstore-domain.c b/tools/helpers/init-xenstore-domain.c
similarity index 100%
rename from tools/xenstore/init-xenstore-domain.c
rename to tools/helpers/init-xenstore-domain.c
diff --git a/tools/xenstore/Makefile b/tools/xenstore/Makefile
index 1b4a494..404d4cb 100644
--- a/tools/xenstore/Makefile
+++ b/tools/xenstore/Makefile
@@ -46,10 +46,6 @@ ifeq ($(XENSTORE_XENSTORED),y)
 ALL_TARGETS += xs_tdb_dump xenstored
 endif
 
-ifeq ($(CONFIG_Linux),y)
-ALL_TARGETS += init-xenstore-domain
-endif
-
 ifdef CONFIG_STUBDOM
 CFLAGS += -DNO_SOCKETS=1
 endif
@@ -72,11 +68,6 @@ xenstored_probes.o: xenstored_solaris.o
 CFLAGS += -DHAVE_DTRACE=1
 endif
 
-init-xenstore-domain.o: CFLAGS += $(CFLAGS_libxenguest)
-
-init-xenstore-domain: init-xenstore-domain.o $(LIBXENSTORE)
-	$(CC) $^ $(LDFLAGS) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) -o $@ $(APPEND_LDFLAGS)
-
 xenstored: $(XENSTORED_OBJS)
 	$(CC) $^ $(LDFLAGS) $(LDLIBS_libxenctrl) $(SOCKET_LIBS) -o $@ $(APPEND_LDFLAGS)
 
-- 
2.6.2

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v3 05/15] xenstore: adjust coding style of init-xenstore-domain.c
  2016-01-08 13:08 [PATCH v3 00/15] xenstore: make it easier to run xenstore in a domain Juergen Gross
                   ` (3 preceding siblings ...)
  2016-01-08 13:08 ` [PATCH v3 04/15] xenstore: move init-xenstore-domain to tools/helpers Juergen Gross
@ 2016-01-08 13:08 ` Juergen Gross
  2016-01-15 15:54   ` Ian Campbell
  2016-01-08 13:08 ` [PATCH v3 06/15] libxl: move xen-init-dom0 to tools/helpers Juergen Gross
                   ` (10 subsequent siblings)
  15 siblings, 1 reply; 35+ messages in thread
From: Juergen Gross @ 2016-01-08 13:08 UTC (permalink / raw)
  To: xen-devel, Ian.Campbell, ian.jackson, stefano.stabellini,
	wei.liu2, dgdegra
  Cc: Juergen Gross

Adjust the coding style of init-xenstore-domain.c to the general Xen
coding style.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 tools/helpers/init-xenstore-domain.c | 221 ++++++++++++++++++++---------------
 1 file changed, 126 insertions(+), 95 deletions(-)

diff --git a/tools/helpers/init-xenstore-domain.c b/tools/helpers/init-xenstore-domain.c
index 297afe5..9c47af1 100644
--- a/tools/helpers/init-xenstore-domain.c
+++ b/tools/helpers/init-xenstore-domain.c
@@ -15,105 +15,136 @@ static uint32_t domid = -1;
 
 static int build(xc_interface *xch, int argc, char** argv)
 {
-	char cmdline[512];
-	uint32_t ssid;
-	xen_domain_handle_t handle = { 0 };
-	int rv, xs_fd;
-	struct xc_dom_image *dom = NULL;
-	int maxmem = atoi(argv[2]);
-	int limit_kb = (maxmem + 1)*1024;
-
-	xs_fd = open("/dev/xen/xenbus_backend", O_RDWR);
-	if (xs_fd == -1) return -1;
-
-	rv = xc_flask_context_to_sid(xch, argv[3], strlen(argv[3]), &ssid);
-	if (rv) goto err;
-	rv = xc_domain_create(xch, ssid, handle, 0, &domid, NULL);
-	if (rv) goto err;
-	rv = xc_domain_max_vcpus(xch, domid, 1);
-	if (rv) goto err;
-	rv = xc_domain_setmaxmem(xch, domid, limit_kb);
-	if (rv) goto err;
-	rv = xc_domain_set_memmap_limit(xch, domid, limit_kb);
-	if (rv) goto err;
-
-	rv = ioctl(xs_fd, IOCTL_XENBUS_BACKEND_SETUP, domid);
-	if (rv < 0) goto err;
-	snprintf(cmdline, 512, "--event %d --internal-db", rv);
-
-	dom = xc_dom_allocate(xch, cmdline, NULL);
-	rv = xc_dom_kernel_file(dom, argv[1]);
-	if (rv) goto err;
-
-	if (argc > 4) {
-		rv = xc_dom_ramdisk_file(dom, argv[4]);
-		if (rv) goto err;
-	}
-
-	rv = xc_dom_boot_xen_init(dom, xch, domid);
-	if (rv) goto err;
-	rv = xc_dom_parse_image(dom);
-	if (rv) goto err;
-	rv = xc_dom_mem_init(dom, maxmem);
-	if (rv) goto err;
-	rv = xc_dom_boot_mem_init(dom);
-	if (rv) goto err;
-	rv = xc_dom_build_image(dom);
-	if (rv) goto err;
-	rv = xc_dom_boot_image(dom);
-	if (rv) goto err;
-
-	xc_dom_release(dom);
-	dom = NULL;
-
-	rv = xc_domain_set_virq_handler(xch, domid, VIRQ_DOM_EXC);
-	if (rv) goto err;
-	rv = xc_domain_unpause(xch, domid);
-	if (rv) goto err;
-
-	return 0;
+    char cmdline[512];
+    uint32_t ssid;
+    xen_domain_handle_t handle = { 0 };
+    int rv, xs_fd;
+    struct xc_dom_image *dom = NULL;
+    int maxmem = atoi(argv[2]);
+    int limit_kb = (maxmem + 1) * 1024;
+
+    xs_fd = open("/dev/xen/xenbus_backend", O_RDWR);
+    if ( xs_fd == -1 )
+        return -1;
+
+    rv = xc_flask_context_to_sid(xch, argv[3], strlen(argv[3]), &ssid);
+    if ( rv )
+        goto err;
+    rv = xc_domain_create(xch, ssid, handle, 0, &domid, NULL);
+    if ( rv )
+        goto err;
+    rv = xc_domain_max_vcpus(xch, domid, 1);
+    if ( rv )
+        goto err;
+    rv = xc_domain_setmaxmem(xch, domid, limit_kb);
+    if ( rv )
+        goto err;
+    rv = xc_domain_set_memmap_limit(xch, domid, limit_kb);
+    if ( rv )
+        goto err;
+
+    rv = ioctl(xs_fd, IOCTL_XENBUS_BACKEND_SETUP, domid);
+    if ( rv < 0 )
+        goto err;
+    snprintf(cmdline, 512, "--event %d --internal-db", rv);
+
+    dom = xc_dom_allocate(xch, cmdline, NULL);
+    rv = xc_dom_kernel_file(dom, argv[1]);
+    if ( rv )
+        goto err;
+
+    if ( argc > 4 )
+    {
+        rv = xc_dom_ramdisk_file(dom, argv[4]);
+        if ( rv )
+            goto err;
+    }
+
+    rv = xc_dom_boot_xen_init(dom, xch, domid);
+    if ( rv )
+        goto err;
+    rv = xc_dom_parse_image(dom);
+    if ( rv )
+        goto err;
+    rv = xc_dom_mem_init(dom, maxmem);
+    if ( rv )
+        goto err;
+    rv = xc_dom_boot_mem_init(dom);
+    if ( rv )
+        goto err;
+    rv = xc_dom_build_image(dom);
+    if ( rv )
+        goto err;
+    rv = xc_dom_boot_image(dom);
+    if ( rv )
+        goto err;
+
+    xc_dom_release(dom);
+    dom = NULL;
+
+    rv = xc_domain_set_virq_handler(xch, domid, VIRQ_DOM_EXC);
+    if ( rv )
+        goto err;
+    rv = xc_domain_unpause(xch, domid);
+    if ( rv )
+        goto err;
+
+    return 0;
 
 err:
-	if (dom)
-		xc_dom_release(dom);
-	close(xs_fd);
-	return rv;
+    if ( dom )
+        xc_dom_release(dom);
+    close(xs_fd);
+    return rv;
 }
 
 int main(int argc, char** argv)
 {
-	xc_interface *xch;
-	struct xs_handle *xsh;
-	char buf[16];
-	int rv, fd;
-
-	if (argc < 4 || argc > 5) {
-		printf("Use: %s <xenstore-kernel> <memory_mb> <flask-label> [<ramdisk-file>]\n", argv[0]);
-		return 2;
-	}
-
-	xch = xc_interface_open(NULL, NULL, 0);
-	if (!xch) return 1;
-
-	rv = build(xch, argc, argv);
-
-	xc_interface_close(xch);
-
-	if (rv) return 1;
-
-	xsh = xs_open(0);
-	rv = snprintf(buf, 16, "%d", domid);
-	xs_write(xsh, XBT_NULL, "/tool/xenstored/domid", buf, rv);
-	xs_daemon_close(xsh);
-
-	fd = creat("/var/run/xenstored.pid", 0666);
-	if (fd < 0)
-		return 3;
-	rv = snprintf(buf, 16, "domid:%d\n", domid);
-	rv = write(fd, buf, rv);
-	close(fd);
-	if (rv < 0)
-		return 3;
-
-	return 0;
+    xc_interface *xch;
+    struct xs_handle *xsh;
+    char buf[16];
+    int rv, fd;
+
+    if ( argc < 4 || argc > 5 )
+    {
+        printf("Use: %s <xenstore-kernel> <memory_mb> <flask-label> [<ramdisk-file>]\n",
+               argv[0]);
+        return 2;
+    }
+
+    xch = xc_interface_open(NULL, NULL, 0);
+    if ( !xch )
+        return 1;
+
+    rv = build(xch, argc, argv);
+
+    xc_interface_close(xch);
+
+    if ( rv )
+        return 1;
+
+    xsh = xs_open(0);
+    rv = snprintf(buf, 16, "%d", domid);
+    xs_write(xsh, XBT_NULL, "/tool/xenstored/domid", buf, rv);
+    xs_daemon_close(xsh);
+
+    fd = creat("/var/run/xenstored.pid", 0666);
+    if ( fd < 0 )
+        return 3;
+    rv = snprintf(buf, 16, "domid:%d\n", domid);
+    rv = write(fd, buf, rv);
+    close(fd);
+    if ( rv < 0 )
+        return 3;
+
+    return 0;
 }
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
-- 
2.6.2

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v3 06/15] libxl: move xen-init-dom0 to tools/helpers
  2016-01-08 13:08 [PATCH v3 00/15] xenstore: make it easier to run xenstore in a domain Juergen Gross
                   ` (4 preceding siblings ...)
  2016-01-08 13:08 ` [PATCH v3 05/15] xenstore: adjust coding style of init-xenstore-domain.c Juergen Gross
@ 2016-01-08 13:08 ` Juergen Gross
  2016-01-15 15:55   ` Ian Campbell
  2016-01-08 13:08 ` [PATCH v3 07/15] xenstore: destroy xenstore domain in case of error after creating it Juergen Gross
                   ` (9 subsequent siblings)
  15 siblings, 1 reply; 35+ messages in thread
From: Juergen Gross @ 2016-01-08 13:08 UTC (permalink / raw)
  To: xen-devel, Ian.Campbell, ian.jackson, stefano.stabellini,
	wei.liu2, dgdegra
  Cc: Juergen Gross

Move xen-init-dom0 from tools/libxl to tools/helpers, as it is just a
helper program.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
V3: adjust .gitignore as requested by Ian Campbell
    use libxentoollog instead of libxc as requested by Ian Campbell
---
 .gitignore                               |  2 +-
 tools/helpers/Makefile                   | 10 ++++++++++
 tools/{libxl => helpers}/xen-init-dom0.c |  2 +-
 tools/libxl/Makefile                     | 14 +++-----------
 4 files changed, 15 insertions(+), 13 deletions(-)
 rename tools/{libxl => helpers}/xen-init-dom0.c (99%)

diff --git a/.gitignore b/.gitignore
index ec1cde3..f70d88f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -133,6 +133,7 @@ tools/flask/utils/flask-setenforce
 tools/flask/utils/flask-set-bool
 tools/flask/utils/flask-label-pci
 tools/helpers/init-xenstore-domain
+tools/helpers/xen-init-dom0
 tools/hotplug/common/hotplugpath.sh
 tools/hotplug/FreeBSD/rc.d/xencommons
 tools/hotplug/FreeBSD/rc.d/xendriverdomain
@@ -300,7 +301,6 @@ tools/libxl/*.pyc
 tools/libxl/libxl-save-helper
 tools/libxl/test_timedereg
 tools/libxl/test_fdderegrace
-tools/libxl/xen-init-dom0
 tools/blktap2/control/tap-ctl
 tools/firmware/etherboot/eb-roms.h
 tools/firmware/etherboot/gpxe-git-snapshot.tar.gz
diff --git a/tools/helpers/Makefile b/tools/helpers/Makefile
index 52347fd..826e0ed 100644
--- a/tools/helpers/Makefile
+++ b/tools/helpers/Makefile
@@ -5,10 +5,16 @@
 XEN_ROOT = $(CURDIR)/../..
 include $(XEN_ROOT)/tools/Rules.mk
 
+PROGS += xen-init-dom0
 ifeq ($(CONFIG_Linux),y)
 PROGS += init-xenstore-domain
 endif
 
+XEN_INIT_DOM0_OBJS = xen-init-dom0.o
+$(XEN_INIT_DOM0_OBJS): CFLAGS += $(CFLAGS_libxentoollog)
+$(XEN_INIT_DOM0_OBJS): CFLAGS += $(CFLAGS_libxenstore)
+$(XEN_INIT_DOM0_OBJS): CFLAGS += $(CFLAGS_libxenlight)
+
 INIT_XENSTORE_DOMAIN_OBJS = init-xenstore-domain.o
 $(INIT_XENSTORE_DOMAIN_OBJS): CFLAGS += $(CFLAGS_libxenguest)
 $(INIT_XENSTORE_DOMAIN_OBJS): CFLAGS += $(CFLAGS_libxenctrl)
@@ -17,12 +23,16 @@ $(INIT_XENSTORE_DOMAIN_OBJS): CFLAGS += $(CFLAGS_libxenstore)
 .PHONY: all
 all: $(PROGS)
 
+xen-init-dom0: $(XEN_INIT_DOM0_OBJS)
+	$(CC) $(LDFLAGS) -o $@ $(XEN_INIT_DOM0_OBJS) $(LDLIBS_libxentoollog) $(LDLIBS_libxenstore) $(LDLIBS_libxenlight) $(APPEND_LDFLAGS)
+
 init-xenstore-domain: $(INIT_XENSTORE_DOMAIN_OBJS)
 	$(CC) $(LDFLAGS) -o $@ $(INIT_XENSTORE_DOMAIN_OBJS) $(LDLIBS_libxenstore) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(APPEND_LDFLAGS)
 
 .PHONY: install
 install: all
 	$(INSTALL_DIR) $(DESTDIR)$(LIBEXEC_BIN)
+	$(INSTALL_PROG) xen-init-dom0 $(DESTDIR)$(LIBEXEC_BIN)
 ifeq ($(CONFIG_Linux),y)
 	$(INSTALL_PROG) init-xenstore-domain $(DESTDIR)$(LIBEXEC_BIN)
 endif
diff --git a/tools/libxl/xen-init-dom0.c b/tools/helpers/xen-init-dom0.c
similarity index 99%
rename from tools/libxl/xen-init-dom0.c
rename to tools/helpers/xen-init-dom0.c
index 7925d64..2f7aa7c 100644
--- a/tools/libxl/xen-init-dom0.c
+++ b/tools/helpers/xen-init-dom0.c
@@ -4,7 +4,7 @@
 #include <string.h>
 #include <stdio.h>
 
-#include <xenctrl.h>
+#include <xentoollog.h>
 #include <xenstore.h>
 #include <libxl.h>
 
diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile
index 2abae0c..b0cb9e4 100644
--- a/tools/libxl/Makefile
+++ b/tools/libxl/Makefile
@@ -143,7 +143,7 @@ LIBXLU_OBJS = libxlu_cfg_y.o libxlu_cfg_l.o libxlu_cfg.o \
 	libxlu_disk_l.o libxlu_disk.o libxlu_vif.o libxlu_pci.o
 $(LIBXLU_OBJS): CFLAGS += $(CFLAGS_libxenctrl) # For xentoollog.h
 
-CLIENTS = xl testidl libxl-save-helper xen-init-dom0
+CLIENTS = xl testidl libxl-save-helper
 
 CFLAGS_XL += $(CFLAGS_libxenlight)
 CFLAGS_XL += -Wshadow
@@ -154,10 +154,6 @@ $(XL_OBJS) $(TEST_PROG_OBJS) _libxl.api-for-check: \
 $(XL_OBJS): CFLAGS += $(CFLAGS_XL)
 $(XL_OBJS): CFLAGS += -include $(XEN_ROOT)/tools/config.h # libxl_json.h needs it.
 
-XEN_INIT_DOM0_OBJS = xen-init-dom0.o
-$(XEN_INIT_DOM0_OBJS): CFLAGS += $(CFLAGS_libxenctrl)
-$(XEN_INIT_DOM0_OBJS): CFLAGS += $(CFLAGS_libxenstore)
-
 SAVE_HELPER_OBJS = libxl_save_helper.o _libxl_save_msgs_helper.o
 $(SAVE_HELPER_OBJS): CFLAGS += $(CFLAGS_libxenctrl)
 
@@ -174,7 +170,7 @@ all: $(CLIENTS) $(TEST_PROGS) $(PKG_CONFIG) \
 	$(AUTOSRCS) $(AUTOINCS)
 
 $(LIBXL_OBJS) $(LIBXLU_OBJS) $(XL_OBJS) $(SAVE_HELPER_OBJS) \
-		$(LIBXL_TEST_OBJS) $(TEST_PROG_OBJS) $(XEN_INIT_DOM0_OBJS): \
+		$(LIBXL_TEST_OBJS) $(TEST_PROG_OBJS): \
 	$(AUTOINCS) libxl.api-ok
 
 %.c %.h:: %.y
@@ -215,7 +211,7 @@ libxl_internal_json.h: _libxl_types_internal_json.h
 xl.h: _paths.h
 
 $(LIBXL_OBJS) $(LIBXL_TEST_OBJS) $(LIBXLU_OBJS) \
-	$(XL_OBJS) $(TEST_PROG_OBJS) $(SAVE_HELPER_OBJS) $(XEN_INIT_DOM0_OBJS): libxl.h
+	$(XL_OBJS) $(TEST_PROG_OBJS) $(SAVE_HELPER_OBJS): libxl.h
 $(LIBXL_OBJS) $(LIBXL_TEST_OBJS): libxl_internal.h
 
 _libxl_type%.h _libxl_type%_json.h _libxl_type%_private.h _libxl_type%.c: libxl_type%.idl gentypes.py idl.py
@@ -256,9 +252,6 @@ libxlutil.a: $(LIBXLU_OBJS)
 xl: $(XL_OBJS) libxlutil.so libxenlight.so
 	$(CC) $(LDFLAGS) -o $@ $(XL_OBJS) libxlutil.so $(LDLIBS_libxenlight) $(LDLIBS_libxentoollog) -lyajl $(APPEND_LDFLAGS)
 
-xen-init-dom0: $(XEN_INIT_DOM0_OBJS) libxenlight.so
-	$(CC) $(LDFLAGS) -o $@ $(XEN_INIT_DOM0_OBJS) $(LDLIBS_libxenstore) $(LDLIBS_libxenlight) $(LDLIBS_libxentoollog) $(APPEND_LDFLAGS)
-
 test_%: test_%.o test_common.o libxlutil.so libxenlight_test.so
 	$(CC) $(LDFLAGS) -o $@ $^ $(filter-out %libxenlight.so, $(LDLIBS_libxenlight)) $(LDLIBS_libxentoollog) -lyajl $(APPEND_LDFLAGS)
 
@@ -281,7 +274,6 @@ install: all
 	$(INSTALL_DIR) $(DESTDIR)$(LIBEXEC_BIN)
 	$(INSTALL_DIR) $(DESTDIR)$(SHAREDIR)/pkgconfig
 	$(INSTALL_PROG) xl $(DESTDIR)$(sbindir)
-	$(INSTALL_PROG) xen-init-dom0 $(DESTDIR)$(LIBEXEC_BIN)
 	$(INSTALL_PROG) libxl-save-helper $(DESTDIR)$(LIBEXEC_BIN)
 	$(INSTALL_SHLIB) libxenlight.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)
 	$(SYMLINK_SHLIB) libxenlight.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)/libxenlight.so.$(MAJOR)
-- 
2.6.2

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v3 07/15] xenstore: destroy xenstore domain in case of error after creating it
  2016-01-08 13:08 [PATCH v3 00/15] xenstore: make it easier to run xenstore in a domain Juergen Gross
                   ` (5 preceding siblings ...)
  2016-01-08 13:08 ` [PATCH v3 06/15] libxl: move xen-init-dom0 to tools/helpers Juergen Gross
@ 2016-01-08 13:08 ` Juergen Gross
  2016-01-15 16:02   ` Ian Campbell
  2016-01-08 13:08 ` [PATCH v3 08/15] xenstore: add error messages to init-xenstore-domain Juergen Gross
                   ` (8 subsequent siblings)
  15 siblings, 1 reply; 35+ messages in thread
From: Juergen Gross @ 2016-01-08 13:08 UTC (permalink / raw)
  To: xen-devel, Ian.Campbell, ian.jackson, stefano.stabellini,
	wei.liu2, dgdegra
  Cc: Juergen Gross

When creating a xenstore domain via init-xenstore-domain destroy it
in case of an error occurred after calling xc_domain_create().

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
---
 tools/helpers/init-xenstore-domain.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/helpers/init-xenstore-domain.c b/tools/helpers/init-xenstore-domain.c
index 9c47af1..a9c5821 100644
--- a/tools/helpers/init-xenstore-domain.c
+++ b/tools/helpers/init-xenstore-domain.c
@@ -11,7 +11,7 @@
 #include <xenstore.h>
 #include <xen/sys/xenbus_dev.h>
 
-static uint32_t domid = -1;
+static uint32_t domid = ~0;
 
 static int build(xc_interface *xch, int argc, char** argv)
 {
@@ -94,6 +94,8 @@ static int build(xc_interface *xch, int argc, char** argv)
 err:
     if ( dom )
         xc_dom_release(dom);
+    if ( domid != ~0 )
+        xc_domain_destroy(xch, domid);
     close(xs_fd);
     return rv;
 }
-- 
2.6.2

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v3 08/15] xenstore: add error messages to init-xenstore-domain
  2016-01-08 13:08 [PATCH v3 00/15] xenstore: make it easier to run xenstore in a domain Juergen Gross
                   ` (6 preceding siblings ...)
  2016-01-08 13:08 ` [PATCH v3 07/15] xenstore: destroy xenstore domain in case of error after creating it Juergen Gross
@ 2016-01-08 13:08 ` Juergen Gross
  2016-01-08 13:08 ` [PATCH v3 09/15] xenstore: modify init-xenstore-domain parameter syntax Juergen Gross
                   ` (7 subsequent siblings)
  15 siblings, 0 replies; 35+ messages in thread
From: Juergen Gross @ 2016-01-08 13:08 UTC (permalink / raw)
  To: xen-devel, Ian.Campbell, ian.jackson, stefano.stabellini,
	wei.liu2, dgdegra
  Cc: Juergen Gross

Additional add some diagnostic messages to the program to have an idea
why it failed.

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
---
 tools/helpers/init-xenstore-domain.c | 66 ++++++++++++++++++++++++++++++++++--
 1 file changed, 64 insertions(+), 2 deletions(-)

diff --git a/tools/helpers/init-xenstore-domain.c b/tools/helpers/init-xenstore-domain.c
index a9c5821..124f29c 100644
--- a/tools/helpers/init-xenstore-domain.c
+++ b/tools/helpers/init-xenstore-domain.c
@@ -10,6 +10,7 @@
 #include <xc_dom.h>
 #include <xenstore.h>
 #include <xen/sys/xenbus_dev.h>
+#include <xen-xsm/flask/flask.h>
 
 static uint32_t domid = ~0;
 
@@ -25,69 +26,120 @@ static int build(xc_interface *xch, int argc, char** argv)
 
     xs_fd = open("/dev/xen/xenbus_backend", O_RDWR);
     if ( xs_fd == -1 )
+    {
+        fprintf(stderr, "Could not open /dev/xen/xenbus_backend\n");
         return -1;
+    }
 
     rv = xc_flask_context_to_sid(xch, argv[3], strlen(argv[3]), &ssid);
     if ( rv )
+    {
+        fprintf(stderr, "xc_flask_context_to_sid failed\n");
         goto err;
+    }
     rv = xc_domain_create(xch, ssid, handle, 0, &domid, NULL);
     if ( rv )
+    {
+        fprintf(stderr, "xc_domain_create failed\n");
         goto err;
+    }
     rv = xc_domain_max_vcpus(xch, domid, 1);
     if ( rv )
+    {
+        fprintf(stderr, "xc_domain_max_vcpus failed\n");
         goto err;
+    }
     rv = xc_domain_setmaxmem(xch, domid, limit_kb);
     if ( rv )
+    {
+        fprintf(stderr, "xc_domain_setmaxmem failed\n");
         goto err;
+    }
     rv = xc_domain_set_memmap_limit(xch, domid, limit_kb);
     if ( rv )
+    {
+        fprintf(stderr, "xc_domain_set_memmap_limit failed\n");
         goto err;
+    }
 
     rv = ioctl(xs_fd, IOCTL_XENBUS_BACKEND_SETUP, domid);
     if ( rv < 0 )
+    {
+        fprintf(stderr, "Xenbus setup ioctl failed\n");
         goto err;
+    }
     snprintf(cmdline, 512, "--event %d --internal-db", rv);
 
     dom = xc_dom_allocate(xch, cmdline, NULL);
     rv = xc_dom_kernel_file(dom, argv[1]);
     if ( rv )
+    {
+        fprintf(stderr, "xc_dom_kernel_file failed\n");
         goto err;
+    }
 
     if ( argc > 4 )
     {
         rv = xc_dom_ramdisk_file(dom, argv[4]);
         if ( rv )
+        {
+            fprintf(stderr, "xc_dom_ramdisk_file failed\n");
             goto err;
+        }
     }
 
     rv = xc_dom_boot_xen_init(dom, xch, domid);
     if ( rv )
+    {
+        fprintf(stderr, "xc_dom_boot_xen_init failed\n");
         goto err;
+    }
     rv = xc_dom_parse_image(dom);
     if ( rv )
+    {
+        fprintf(stderr, "xc_dom_parse_image failed\n");
         goto err;
+    }
     rv = xc_dom_mem_init(dom, maxmem);
     if ( rv )
+    {
+        fprintf(stderr, "xc_dom_mem_init failed\n");
         goto err;
+    }
     rv = xc_dom_boot_mem_init(dom);
     if ( rv )
+    {
+        fprintf(stderr, "xc_dom_boot_mem_init failed\n");
         goto err;
+    }
     rv = xc_dom_build_image(dom);
     if ( rv )
+    {
+        fprintf(stderr, "xc_dom_build_image failed\n");
         goto err;
+    }
     rv = xc_dom_boot_image(dom);
     if ( rv )
+    {
+        fprintf(stderr, "xc_dom_boot_image failed\n");
         goto err;
+    }
 
     xc_dom_release(dom);
     dom = NULL;
 
     rv = xc_domain_set_virq_handler(xch, domid, VIRQ_DOM_EXC);
     if ( rv )
+    {
+        fprintf(stderr, "xc_domain_set_virq_handler failed\n");
         goto err;
+    }
     rv = xc_domain_unpause(xch, domid);
     if ( rv )
+    {
+        fprintf(stderr, "xc_domain_unpause failed\n");
         goto err;
+    }
 
     return 0;
 
@@ -109,14 +161,18 @@ int main(int argc, char** argv)
 
     if ( argc < 4 || argc > 5 )
     {
-        printf("Use: %s <xenstore-kernel> <memory_mb> <flask-label> [<ramdisk-file>]\n",
-               argv[0]);
+        fprintf(stderr,
+                "Use: %s <xenstore-kernel> <memory_mb> <flask-label> [<ramdisk-file>]\n",
+            argv[0]);
         return 2;
     }
 
     xch = xc_interface_open(NULL, NULL, 0);
     if ( !xch )
+    {
+        fprintf(stderr, "xc_interface_open() failed\n");
         return 1;
+    }
 
     rv = build(xch, argc, argv);
 
@@ -132,12 +188,18 @@ int main(int argc, char** argv)
 
     fd = creat("/var/run/xenstored.pid", 0666);
     if ( fd < 0 )
+    {
+        fprintf(stderr, "Creating /var/run/xenstored.pid failed\n");
         return 3;
+    }
     rv = snprintf(buf, 16, "domid:%d\n", domid);
     rv = write(fd, buf, rv);
     close(fd);
     if ( rv < 0 )
+    {
+        fprintf(stderr, "Writing domid to /var/run/xenstored.pid failed\n");
         return 3;
+    }
 
     return 0;
 }
-- 
2.6.2

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v3 09/15] xenstore: modify init-xenstore-domain parameter syntax
  2016-01-08 13:08 [PATCH v3 00/15] xenstore: make it easier to run xenstore in a domain Juergen Gross
                   ` (7 preceding siblings ...)
  2016-01-08 13:08 ` [PATCH v3 08/15] xenstore: add error messages to init-xenstore-domain Juergen Gross
@ 2016-01-08 13:08 ` Juergen Gross
  2016-01-08 13:08 ` [PATCH v3 10/15] xenstore: make use of the "xenstore domain" flag Juergen Gross
                   ` (6 subsequent siblings)
  15 siblings, 0 replies; 35+ messages in thread
From: Juergen Gross @ 2016-01-08 13:08 UTC (permalink / raw)
  To: xen-devel, Ian.Campbell, ian.jackson, stefano.stabellini,
	wei.liu2, dgdegra
  Cc: Juergen Gross

init-xenstore-domain takes only positional parameters today. Change
this to a more flexible parameter syntax allowing to specify additional
options or to omit some.

Today the supported usage is:

init-xenstore-domain <xenstore-kernel> <memory_mb> <flask-label>
                     [<ramdisk-file>]

Modify this to:

init-xenstore-domain --kernel <xenstore-kernel>
                     --memory <memory_mb>
                     [--flask <flask-label>]
                     [--ramdisk <ramdisk-file>]

The flask label is made optional in order to support xenstore domains
without the need of a flask enabled hypervisor.

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
---
 tools/helpers/init-xenstore-domain.c | 87 +++++++++++++++++++++++++++++-------
 1 file changed, 71 insertions(+), 16 deletions(-)

diff --git a/tools/helpers/init-xenstore-domain.c b/tools/helpers/init-xenstore-domain.c
index 124f29c..ff9968f 100644
--- a/tools/helpers/init-xenstore-domain.c
+++ b/tools/helpers/init-xenstore-domain.c
@@ -4,6 +4,7 @@
 #include <string.h>
 #include <stdint.h>
 #include <stdlib.h>
+#include <getopt.h>
 #include <sys/ioctl.h>
 #include <sys/mman.h>
 #include <xenctrl.h>
@@ -13,16 +14,42 @@
 #include <xen-xsm/flask/flask.h>
 
 static uint32_t domid = ~0;
+static char *kernel;
+static char *ramdisk;
+static char *flask;
+static int memory;
 
-static int build(xc_interface *xch, int argc, char** argv)
+static struct option options[] = {
+    { "kernel", 1, NULL, 'k' },
+    { "memory", 1, NULL, 'm' },
+    { "flask", 1, NULL, 'f' },
+    { "ramdisk", 1, NULL, 'r' },
+    { NULL, 0, NULL, 0 }
+};
+
+static void usage(void)
+{
+    fprintf(stderr,
+"Usage:\n"
+"\n"
+"init-xenstore-domain <options>\n"
+"\n"
+"where options may include:\n"
+"\n"
+"  --kernel <xenstore-kernel> kernel file of the xenstore domain, mandatory\n"
+"  --memory <memory size>     size of the domain in MB, mandatory\n"
+"  --flask <flask-label>      optional flask label of the domain\n"
+"  --ramdisk <ramdisk-file>   optional ramdisk file for the domain\n");
+}
+
+static int build(xc_interface *xch)
 {
     char cmdline[512];
     uint32_t ssid;
     xen_domain_handle_t handle = { 0 };
     int rv, xs_fd;
     struct xc_dom_image *dom = NULL;
-    int maxmem = atoi(argv[2]);
-    int limit_kb = (maxmem + 1) * 1024;
+    int limit_kb = (memory + 1) * 1024;
 
     xs_fd = open("/dev/xen/xenbus_backend", O_RDWR);
     if ( xs_fd == -1 )
@@ -31,11 +58,18 @@ static int build(xc_interface *xch, int argc, char** argv)
         return -1;
     }
 
-    rv = xc_flask_context_to_sid(xch, argv[3], strlen(argv[3]), &ssid);
-    if ( rv )
+    if ( flask )
     {
-        fprintf(stderr, "xc_flask_context_to_sid failed\n");
-        goto err;
+        rv = xc_flask_context_to_sid(xch, flask, strlen(flask), &ssid);
+        if ( rv )
+        {
+            fprintf(stderr, "xc_flask_context_to_sid failed\n");
+            goto err;
+        }
+    }
+    else
+    {
+        ssid = SECINITSID_DOMU;
     }
     rv = xc_domain_create(xch, ssid, handle, 0, &domid, NULL);
     if ( rv )
@@ -71,16 +105,16 @@ static int build(xc_interface *xch, int argc, char** argv)
     snprintf(cmdline, 512, "--event %d --internal-db", rv);
 
     dom = xc_dom_allocate(xch, cmdline, NULL);
-    rv = xc_dom_kernel_file(dom, argv[1]);
+    rv = xc_dom_kernel_file(dom, kernel);
     if ( rv )
     {
         fprintf(stderr, "xc_dom_kernel_file failed\n");
         goto err;
     }
 
-    if ( argc > 4 )
+    if ( ramdisk )
     {
-        rv = xc_dom_ramdisk_file(dom, argv[4]);
+        rv = xc_dom_ramdisk_file(dom, ramdisk);
         if ( rv )
         {
             fprintf(stderr, "xc_dom_ramdisk_file failed\n");
@@ -100,7 +134,7 @@ static int build(xc_interface *xch, int argc, char** argv)
         fprintf(stderr, "xc_dom_parse_image failed\n");
         goto err;
     }
-    rv = xc_dom_mem_init(dom, maxmem);
+    rv = xc_dom_mem_init(dom, memory);
     if ( rv )
     {
         fprintf(stderr, "xc_dom_mem_init failed\n");
@@ -154,16 +188,37 @@ err:
 
 int main(int argc, char** argv)
 {
+    int opt;
     xc_interface *xch;
     struct xs_handle *xsh;
     char buf[16];
     int rv, fd;
 
-    if ( argc < 4 || argc > 5 )
+    while ( (opt = getopt_long(argc, argv, "", options, NULL)) != -1 )
+    {
+        switch ( opt )
+        {
+        case 'k':
+            kernel = optarg;
+            break;
+        case 'm':
+            memory = strtol(optarg, NULL, 10);
+            break;
+        case 'f':
+            flask = optarg;
+            break;
+        case 'r':
+            ramdisk = optarg;
+            break;
+        default:
+            usage();
+            return 2;
+        }
+    }
+
+    if ( optind != argc || !kernel || !memory )
     {
-        fprintf(stderr,
-                "Use: %s <xenstore-kernel> <memory_mb> <flask-label> [<ramdisk-file>]\n",
-            argv[0]);
+        usage();
         return 2;
     }
 
@@ -174,7 +229,7 @@ int main(int argc, char** argv)
         return 1;
     }
 
-    rv = build(xch, argc, argv);
+    rv = build(xch);
 
     xc_interface_close(xch);
 
-- 
2.6.2

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v3 10/15] xenstore: make use of the "xenstore domain" flag
  2016-01-08 13:08 [PATCH v3 00/15] xenstore: make it easier to run xenstore in a domain Juergen Gross
                   ` (8 preceding siblings ...)
  2016-01-08 13:08 ` [PATCH v3 09/15] xenstore: modify init-xenstore-domain parameter syntax Juergen Gross
@ 2016-01-08 13:08 ` Juergen Gross
  2016-01-15 16:03   ` Ian Campbell
  2016-01-08 13:08 ` [PATCH v3 11/15] xenstore: add init-xenstore-domain parameter to specify cmdline Juergen Gross
                   ` (5 subsequent siblings)
  15 siblings, 1 reply; 35+ messages in thread
From: Juergen Gross @ 2016-01-08 13:08 UTC (permalink / raw)
  To: xen-devel, Ian.Campbell, ian.jackson, stefano.stabellini,
	wei.liu2, dgdegra
  Cc: Juergen Gross

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 <jgross@suse.com>
---
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

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v3 11/15] xenstore: add init-xenstore-domain parameter to specify cmdline
  2016-01-08 13:08 [PATCH v3 00/15] xenstore: make it easier to run xenstore in a domain Juergen Gross
                   ` (9 preceding siblings ...)
  2016-01-08 13:08 ` [PATCH v3 10/15] xenstore: make use of the "xenstore domain" flag Juergen Gross
@ 2016-01-08 13:08 ` Juergen Gross
  2016-01-08 13:08 ` [PATCH v3 12/15] tools: split up xen-init-dom0.c Juergen Gross
                   ` (4 subsequent siblings)
  15 siblings, 0 replies; 35+ messages in thread
From: Juergen Gross @ 2016-01-08 13:08 UTC (permalink / raw)
  To: xen-devel, Ian.Campbell, ian.jackson, stefano.stabellini,
	wei.liu2, dgdegra
  Cc: Juergen Gross

Add a parameter to init-xenstore-domain for support of arbitrary
parameters for the xenstore domain.

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
---
 tools/helpers/init-xenstore-domain.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/tools/helpers/init-xenstore-domain.c b/tools/helpers/init-xenstore-domain.c
index ecced04..238007b 100644
--- a/tools/helpers/init-xenstore-domain.c
+++ b/tools/helpers/init-xenstore-domain.c
@@ -17,6 +17,7 @@ static uint32_t domid = ~0;
 static char *kernel;
 static char *ramdisk;
 static char *flask;
+static char *param;
 static int memory;
 
 static struct option options[] = {
@@ -24,6 +25,7 @@ static struct option options[] = {
     { "memory", 1, NULL, 'm' },
     { "flask", 1, NULL, 'f' },
     { "ramdisk", 1, NULL, 'r' },
+    { "param", 1, NULL, 'p' },
     { NULL, 0, NULL, 0 }
 };
 
@@ -39,7 +41,8 @@ static void usage(void)
 "  --kernel <xenstore-kernel> kernel file of the xenstore domain, mandatory\n"
 "  --memory <memory size>     size of the domain in MB, mandatory\n"
 "  --flask <flask-label>      optional flask label of the domain\n"
-"  --ramdisk <ramdisk-file>   optional ramdisk file for the domain\n");
+"  --ramdisk <ramdisk-file>   optional ramdisk file for the domain\n"
+"  --param <cmdline>          optional additional parameters for the domain\n");
 }
 
 static int build(xc_interface *xch)
@@ -103,7 +106,11 @@ static int build(xc_interface *xch)
         fprintf(stderr, "Xenbus setup ioctl failed\n");
         goto err;
     }
-    snprintf(cmdline, 512, "--event %d --internal-db", rv);
+
+    if ( param )
+        snprintf(cmdline, 512, "--event %d --internal-db %s", rv, param);
+    else
+        snprintf(cmdline, 512, "--event %d --internal-db", rv);
 
     dom = xc_dom_allocate(xch, cmdline, NULL);
     rv = xc_dom_kernel_file(dom, kernel);
@@ -233,6 +240,9 @@ int main(int argc, char** argv)
         case 'r':
             ramdisk = optarg;
             break;
+        case 'p':
+            param = optarg;
+            break;
         default:
             usage();
             return 2;
-- 
2.6.2

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v3 12/15] tools: split up xen-init-dom0.c
  2016-01-08 13:08 [PATCH v3 00/15] xenstore: make it easier to run xenstore in a domain Juergen Gross
                   ` (10 preceding siblings ...)
  2016-01-08 13:08 ` [PATCH v3 11/15] xenstore: add init-xenstore-domain parameter to specify cmdline Juergen Gross
@ 2016-01-08 13:08 ` Juergen Gross
  2016-01-08 13:08 ` [PATCH v3 13/15] xenstore: write xenstore domain data to xenstore Juergen Gross
                   ` (3 subsequent siblings)
  15 siblings, 0 replies; 35+ messages in thread
From: Juergen Gross @ 2016-01-08 13:08 UTC (permalink / raw)
  To: xen-devel, Ian.Campbell, ian.jackson, stefano.stabellini,
	wei.liu2, dgdegra
  Cc: Juergen Gross

Split up tools/helpers/xen-init-dom0.c in order to prepare reusing
generation of the json configuration by init-xenstore-domain.c.

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
---
 tools/helpers/Makefile        |  2 +-
 tools/helpers/init-dom-json.c | 59 ++++++++++++++++++++++++++++++++++
 tools/helpers/init-dom-json.h | 18 +++++++++++
 tools/helpers/xen-init-dom0.c | 73 ++++++-------------------------------------
 4 files changed, 88 insertions(+), 64 deletions(-)
 create mode 100644 tools/helpers/init-dom-json.c
 create mode 100644 tools/helpers/init-dom-json.h

diff --git a/tools/helpers/Makefile b/tools/helpers/Makefile
index 826e0ed..0325ba2 100644
--- a/tools/helpers/Makefile
+++ b/tools/helpers/Makefile
@@ -10,7 +10,7 @@ ifeq ($(CONFIG_Linux),y)
 PROGS += init-xenstore-domain
 endif
 
-XEN_INIT_DOM0_OBJS = xen-init-dom0.o
+XEN_INIT_DOM0_OBJS = xen-init-dom0.o init-dom-json.o
 $(XEN_INIT_DOM0_OBJS): CFLAGS += $(CFLAGS_libxentoollog)
 $(XEN_INIT_DOM0_OBJS): CFLAGS += $(CFLAGS_libxenstore)
 $(XEN_INIT_DOM0_OBJS): CFLAGS += $(CFLAGS_libxenlight)
diff --git a/tools/helpers/init-dom-json.c b/tools/helpers/init-dom-json.c
new file mode 100644
index 0000000..91b1fdf
--- /dev/null
+++ b/tools/helpers/init-dom-json.c
@@ -0,0 +1,59 @@
+#include <err.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <xenctrl.h>
+#include <libxl.h>
+
+int gen_stub_json_config(uint32_t domid)
+{
+    int rc = 1;
+    xentoollog_logger_stdiostream *logger;
+    libxl_ctx *ctx;
+    libxl_domain_config dom_config;
+    char *json = NULL;
+
+    logger = xtl_createlogger_stdiostream(stderr, XTL_ERROR, 0);
+    if (!logger)
+        return 1;
+
+    if (libxl_ctx_alloc(&ctx, LIBXL_VERSION, 0,
+                        (xentoollog_logger *)logger)) {
+        fprintf(stderr, "cannot init libxl context\n");
+        goto outlog;
+    }
+
+    libxl_domain_config_init(&dom_config);
+
+    /* Generate stub JSON config. */
+    dom_config.c_info.type = LIBXL_DOMAIN_TYPE_PV;
+    libxl_domain_build_info_init_type(&dom_config.b_info,
+                                      LIBXL_DOMAIN_TYPE_PV);
+
+    json = libxl_domain_config_to_json(ctx, &dom_config);
+    /* libxl-json format requires the string ends with '\0'. Code
+     * snippet taken from libxl.
+     */
+    rc = libxl_userdata_store(ctx, domid, "libxl-json",
+                              (const uint8_t *)json,
+                              strlen(json) + 1 /* include '\0' */);
+    if (rc)
+        fprintf(stderr, "cannot store stub json config for domain %u\n", domid);
+
+    libxl_domain_config_dispose(&dom_config);
+    free(json);
+    libxl_ctx_free(ctx);
+outlog:
+    xtl_logger_destroy((xentoollog_logger *)logger);
+    return rc;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/tools/helpers/init-dom-json.h b/tools/helpers/init-dom-json.h
new file mode 100644
index 0000000..58c85df
--- /dev/null
+++ b/tools/helpers/init-dom-json.h
@@ -0,0 +1,18 @@
+#ifndef __INIT_DOM_JSON_H
+#define __INIT_DOM_JSON_H
+
+/*
+ * Generate a stub JSON config for a domain with the given domid.
+ */
+int gen_stub_json_config(uint32_t domid);
+
+#endif
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/tools/helpers/xen-init-dom0.c b/tools/helpers/xen-init-dom0.c
index 2f7aa7c..9ab8468 100644
--- a/tools/helpers/xen-init-dom0.c
+++ b/tools/helpers/xen-init-dom0.c
@@ -1,65 +1,26 @@
-#include <err.h>
 #include <stdlib.h>
 #include <stdint.h>
 #include <string.h>
 #include <stdio.h>
 
-#include <xentoollog.h>
 #include <xenstore.h>
-#include <libxl.h>
+
+#include "init-dom-json.h"
 
 #define DOMNAME_PATH   "/local/domain/0/name"
 #define DOMID_PATH     "/local/domain/0/domid"
 
-static libxl_ctx *ctx;
-static xentoollog_logger_stdiostream *logger;
-static struct xs_handle *xsh;
-
-static void ctx_alloc(void)
+int main(int argc, char **argv)
 {
-    if (libxl_ctx_alloc(&ctx, LIBXL_VERSION, 0,
-                        (xentoollog_logger *)logger)) {
-        fprintf(stderr, "cannot init libxl context\n");
-        exit(1);
-    }
+    int rc;
+    struct xs_handle *xsh;
+    char *domname_string = NULL, *domid_string = NULL;
+
     xsh = xs_open(0);
     if (!xsh) {
         fprintf(stderr, "cannot open xenstore connection\n");
         exit(1);
     }
-}
-
-static void ctx_free(void)
-{
-    if (ctx) {
-        libxl_ctx_free(ctx);
-        ctx = NULL;
-    }
-    if (logger) {
-        xtl_logger_destroy((xentoollog_logger *)logger);
-        logger = NULL;
-    }
-    if (xsh) {
-        xs_close(xsh);
-        xsh = NULL;
-    }
-}
-
-int main(int argc, char **argv)
-{
-    int rc;
-    libxl_domain_config dom0_config;
-    char *domname_string = NULL, *domid_string = NULL;
-    char *json = NULL;;
-
-    logger = xtl_createlogger_stdiostream(stderr, XTL_ERROR, 0);
-    if (!logger) exit(1);
-
-    atexit(ctx_free);
-
-    ctx_alloc();
-
-    libxl_domain_config_init(&dom0_config);
 
     /* Sanity check: this program can only be run once. */
     domid_string = xs_read(xsh, XBT_NULL, DOMID_PATH, NULL);
@@ -70,22 +31,9 @@ int main(int argc, char **argv)
         goto out;
     }
 
-    /* Generate stub JSON config. */
-    dom0_config.c_info.type = LIBXL_DOMAIN_TYPE_PV;
-    libxl_domain_build_info_init_type(&dom0_config.b_info,
-                                      LIBXL_DOMAIN_TYPE_PV);
-
-    json = libxl_domain_config_to_json(ctx, &dom0_config);
-    /* libxl-json format requires the string ends with '\0'. Code
-     * snippet taken from libxl.
-     */
-    rc = libxl_userdata_store(ctx, 0, "libxl-json",
-                              (const uint8_t *)json,
-                              strlen(json) + 1 /* include '\0' */);
-    if (rc) {
-        fprintf(stderr, "cannot store stub json config for Dom0\n");
+    rc = gen_stub_json_config(0);
+    if (rc)
         goto out;
-    }
 
     /* Write xenstore entries. */
     if (!xs_write(xsh, XBT_NULL, DOMID_PATH, "0", strlen("0"))) {
@@ -104,10 +52,9 @@ int main(int argc, char **argv)
     printf("Done setting up Dom0\n");
 
 out:
-    libxl_domain_config_dispose(&dom0_config);
     free(domid_string);
     free(domname_string);
-    free(json);
+    xs_close(xsh);
     return rc;
 }
 
-- 
2.6.2

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v3 13/15] xenstore: write xenstore domain data to xenstore
  2016-01-08 13:08 [PATCH v3 00/15] xenstore: make it easier to run xenstore in a domain Juergen Gross
                   ` (11 preceding siblings ...)
  2016-01-08 13:08 ` [PATCH v3 12/15] tools: split up xen-init-dom0.c Juergen Gross
@ 2016-01-08 13:08 ` Juergen Gross
  2016-01-08 13:08 ` [PATCH v3 14/15] tools: don't stop xenstore domain when stopping dom0 Juergen Gross
                   ` (2 subsequent siblings)
  15 siblings, 0 replies; 35+ messages in thread
From: Juergen Gross @ 2016-01-08 13:08 UTC (permalink / raw)
  To: xen-devel, Ian.Campbell, ian.jackson, stefano.stabellini,
	wei.liu2, dgdegra
  Cc: Juergen Gross

After starting the xenstore domain write the basic data (domid, name
and memory values) to the xenstore. This makes the domain appear
correctly in xl list. Create a stub json object in order to make e.g.
xl list -l happy.

Add a new option to init-xenstore-domain to be able to specify the
domain's name.

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
---
 tools/helpers/Makefile               |  6 +++--
 tools/helpers/init-xenstore-domain.c | 44 ++++++++++++++++++++++++++++++++----
 2 files changed, 44 insertions(+), 6 deletions(-)

diff --git a/tools/helpers/Makefile b/tools/helpers/Makefile
index 0325ba2..a05a368 100644
--- a/tools/helpers/Makefile
+++ b/tools/helpers/Makefile
@@ -15,10 +15,12 @@ $(XEN_INIT_DOM0_OBJS): CFLAGS += $(CFLAGS_libxentoollog)
 $(XEN_INIT_DOM0_OBJS): CFLAGS += $(CFLAGS_libxenstore)
 $(XEN_INIT_DOM0_OBJS): CFLAGS += $(CFLAGS_libxenlight)
 
-INIT_XENSTORE_DOMAIN_OBJS = init-xenstore-domain.o
+INIT_XENSTORE_DOMAIN_OBJS = init-xenstore-domain.o init-dom-json.o
+$(INIT_XENSTORE_DOMAIN_OBJS): CFLAGS += $(CFLAGS_libxentoollog)
 $(INIT_XENSTORE_DOMAIN_OBJS): CFLAGS += $(CFLAGS_libxenguest)
 $(INIT_XENSTORE_DOMAIN_OBJS): CFLAGS += $(CFLAGS_libxenctrl)
 $(INIT_XENSTORE_DOMAIN_OBJS): CFLAGS += $(CFLAGS_libxenstore)
+$(INIT_XENSTORE_DOMAIN_OBJS): CFLAGS += $(CFLAGS_libxenlight)
 
 .PHONY: all
 all: $(PROGS)
@@ -27,7 +29,7 @@ xen-init-dom0: $(XEN_INIT_DOM0_OBJS)
 	$(CC) $(LDFLAGS) -o $@ $(XEN_INIT_DOM0_OBJS) $(LDLIBS_libxentoollog) $(LDLIBS_libxenstore) $(LDLIBS_libxenlight) $(APPEND_LDFLAGS)
 
 init-xenstore-domain: $(INIT_XENSTORE_DOMAIN_OBJS)
-	$(CC) $(LDFLAGS) -o $@ $(INIT_XENSTORE_DOMAIN_OBJS) $(LDLIBS_libxenstore) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(APPEND_LDFLAGS)
+	$(CC) $(LDFLAGS) -o $@ $(INIT_XENSTORE_DOMAIN_OBJS) $(LDLIBS_libxentoollog) $(LDLIBS_libxenstore) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenlight) $(APPEND_LDFLAGS)
 
 .PHONY: install
 install: all
diff --git a/tools/helpers/init-xenstore-domain.c b/tools/helpers/init-xenstore-domain.c
index 238007b..5c5af2d 100644
--- a/tools/helpers/init-xenstore-domain.c
+++ b/tools/helpers/init-xenstore-domain.c
@@ -13,11 +13,14 @@
 #include <xen/sys/xenbus_dev.h>
 #include <xen-xsm/flask/flask.h>
 
+#include "init-dom-json.h"
+
 static uint32_t domid = ~0;
 static char *kernel;
 static char *ramdisk;
 static char *flask;
 static char *param;
+static char *name = "Xenstore";
 static int memory;
 
 static struct option options[] = {
@@ -26,6 +29,7 @@ static struct option options[] = {
     { "flask", 1, NULL, 'f' },
     { "ramdisk", 1, NULL, 'r' },
     { "param", 1, NULL, 'p' },
+    { "name", 1, NULL, 'n' },
     { NULL, 0, NULL, 0 }
 };
 
@@ -42,7 +46,8 @@ static void usage(void)
 "  --memory <memory size>     size of the domain in MB, mandatory\n"
 "  --flask <flask-label>      optional flask label of the domain\n"
 "  --ramdisk <ramdisk-file>   optional ramdisk file for the domain\n"
-"  --param <cmdline>          optional additional parameters for the domain\n");
+"  --param <cmdline>          optional additional parameters for the domain\n"
+"  --name <name>              name of the domain (default: Xenstore)\n");
 }
 
 static int build(xc_interface *xch)
@@ -216,6 +221,20 @@ static int check_domain(xc_interface *xch)
     return 0;
 }
 
+static void do_xs_write(struct xs_handle *xsh, char *path, char *val)
+{
+    if ( !xs_write(xsh, XBT_NULL, path, val, strlen(val)) )
+        fprintf(stderr, "writing %s to xenstore failed.\n", path);
+}
+
+static void do_xs_write_dom(struct xs_handle *xsh, char *path, char *val)
+{
+    char full_path[64];
+
+    snprintf(full_path, 64, "/local/domain/%d/%s", domid, path);
+    do_xs_write(xsh, full_path, val);
+}
+
 int main(int argc, char** argv)
 {
     int opt;
@@ -243,6 +262,9 @@ int main(int argc, char** argv)
         case 'p':
             param = optarg;
             break;
+        case 'n':
+            name = optarg;
+            break;
         default:
             usage();
             return 2;
@@ -274,10 +296,24 @@ int main(int argc, char** argv)
     if ( rv )
         return 1;
 
+    rv = gen_stub_json_config(domid);
+    if ( rv )
+        return 3;
+
     xsh = xs_open(0);
-    rv = snprintf(buf, 16, "%d", domid);
-    xs_write(xsh, XBT_NULL, "/tool/xenstored/domid", buf, rv);
-    xs_daemon_close(xsh);
+    if ( !xsh )
+    {
+        fprintf(stderr, "xs_open() failed.\n");
+        return 3;
+    }
+    snprintf(buf, 16, "%d", domid);
+    do_xs_write(xsh, "/tool/xenstored/domid", buf);
+    do_xs_write_dom(xsh, "domid", buf);
+    do_xs_write_dom(xsh, "name", name);
+    snprintf(buf, 16, "%d", memory * 1024);
+    do_xs_write_dom(xsh, "memory/target", buf);
+    do_xs_write_dom(xsh, "memory/static-max", buf);
+    xs_close(xsh);
 
     fd = creat("/var/run/xenstored.pid", 0666);
     if ( fd < 0 )
-- 
2.6.2

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v3 14/15] tools: don't stop xenstore domain when stopping dom0
  2016-01-08 13:08 [PATCH v3 00/15] xenstore: make it easier to run xenstore in a domain Juergen Gross
                   ` (12 preceding siblings ...)
  2016-01-08 13:08 ` [PATCH v3 13/15] xenstore: write xenstore domain data to xenstore Juergen Gross
@ 2016-01-08 13:08 ` Juergen Gross
  2016-01-15 16:12   ` Ian Campbell
  2016-01-08 13:08 ` [PATCH v3 15/15] docs: document xenstore domain xenstore paths Juergen Gross
  2016-01-15 15:04 ` [PATCH v3 00/15] xenstore: make it easier to run xenstore in a domain Juergen Gross
  15 siblings, 1 reply; 35+ messages in thread
From: Juergen Gross @ 2016-01-08 13:08 UTC (permalink / raw)
  To: xen-devel, Ian.Campbell, ian.jackson, stefano.stabellini,
	wei.liu2, dgdegra
  Cc: Juergen Gross

When restarting or shutting down dom0 the xendomains script tries to
stop all other domains. Don't do this for the xenstore domain, as it
might survive a dom0 reboot in the future.

The same applies to xl shutdown --all. Here the xenstore domain is
flagged as "never stop".

Signed-off-by: Juergen Gross <jgross@suse.com>
---
V3: xl shutdown modified to query the "never_stop" flag instead of
    the xenstore domain id as requested by Ian Campbell
    drop usage of xenstore-exists as requested by Ian Campbell
---
 tools/hotplug/Linux/xendomains.in | 15 +++++++++++++++
 tools/libxl/xl_cmdimpl.c          |  8 +++++---
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/tools/hotplug/Linux/xendomains.in b/tools/hotplug/Linux/xendomains.in
index dfe0b33..9f88649 100644
--- a/tools/hotplug/Linux/xendomains.in
+++ b/tools/hotplug/Linux/xendomains.in
@@ -196,6 +196,15 @@ rdnames()
     done
 }
 
+# get xenstore domain id (or 0 if no xenstore domain)
+get_xsdomid()
+{
+    XS_DOMID=`${bindir}/xenstore-read /tool/xenstored/domid 2>/dev/null`
+    if test $? -ne 0; then
+        XS_DOMID=0
+    fi
+}
+
 LIST_GREP='(domain\|(domid\|(name\|^    {$\|"name":\|"domid":'
 parseln()
 {
@@ -216,12 +225,14 @@ parseln()
 
 is_running()
 {
+    get_xsdomid
     rdname $1
     RC=1
     name=;id=
     while read LN; do
 	parseln "$LN" || continue
 	if test $id = 0; then continue; fi
+	if test $id = $XS_DOMID; then continue; fi
 	case $name in
 	    ($NM)
 		RC=0
@@ -302,10 +313,12 @@ start()
 
 all_zombies()
 {
+    get_xsdomid
     name=;id=
     while read LN; do
 	parseln "$LN" || continue
 	if test $id = 0; then continue; fi
+	if test $id = $XS_DOMID; then continue; fi
 	if test "$state" != "-b---d" -a "$state" != "-----d"; then
 	    return 1;
 	fi
@@ -351,11 +364,13 @@ stop()
     if test "$XENDOMAINS_AUTO_ONLY" = "true"; then
 	rdnames
     fi
+    get_xsdomid
     echo -n "Shutting down Xen domains:"
     name=;id=
     while read LN; do
 	parseln "$LN" || continue
 	if test $id = 0; then continue; fi
+	if test $id = $XS_DOMID; then continue; fi
 	echo -n " $name"
 	if test "$XENDOMAINS_AUTO_ONLY" = "true"; then
 	    eval "
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index f9933cb..29f9d19 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -4856,15 +4856,17 @@ static int main_shutdown_or_reboot(int do_reboot, int argc, char **argv)
         if (wait_for_it)
             deathws = calloc(nb_domain, sizeof(*deathws));
 
+        wait_for_it = 0;
         for (i = 0; i<nb_domain; i++) {
-            if (dominfo[i].domid == 0)
+            if (dominfo[i].domid == 0 || dominfo[i].never_stop)
                 continue;
             fn(dominfo[i].domid, deathws ? &deathws[i] : NULL, i,
                fallback_trigger);
+            wait_for_it++;
         }
 
-        if (wait_for_it) {
-            wait_for_domain_deaths(deathws, nb_domain - 1 /* not dom 0 */);
+        if (deathws) {
+            wait_for_domain_deaths(deathws, wait_for_it);
             free(deathws);
         }
 
-- 
2.6.2

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [PATCH v3 15/15] docs: document xenstore domain xenstore paths
  2016-01-08 13:08 [PATCH v3 00/15] xenstore: make it easier to run xenstore in a domain Juergen Gross
                   ` (13 preceding siblings ...)
  2016-01-08 13:08 ` [PATCH v3 14/15] tools: don't stop xenstore domain when stopping dom0 Juergen Gross
@ 2016-01-08 13:08 ` Juergen Gross
  2016-01-15 16:14   ` Ian Campbell
  2016-01-15 15:04 ` [PATCH v3 00/15] xenstore: make it easier to run xenstore in a domain Juergen Gross
  15 siblings, 1 reply; 35+ messages in thread
From: Juergen Gross @ 2016-01-08 13:08 UTC (permalink / raw)
  To: xen-devel, Ian.Campbell, ian.jackson, stefano.stabellini,
	wei.liu2, dgdegra
  Cc: Juergen Gross

Add the xenstore domain specific xenstore paths to
docs/misc/xenstore-paths.markdown

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 docs/misc/xenstore-paths.markdown | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/docs/misc/xenstore-paths.markdown b/docs/misc/xenstore-paths.markdown
index 197bb0f..4712e3a 100644
--- a/docs/misc/xenstore-paths.markdown
+++ b/docs/misc/xenstore-paths.markdown
@@ -509,6 +509,16 @@ The device model version for a domain.
 
 ifb device used by Remus to buffer network output from the associated vif.
 
+### xenstored specific paths
+
+The /tool/xenstored namespace is created by the xenstore daemon or domain
+for the toolstack to obtain e.g. the domain id of a xenstore domain.
+
+#### /tool/xenstored/domid = INTEGER [n,INTERNAL]
+
+Domain Id of the xenstroe domain in case xenstore is provided via a
+domain instead of a daemon in dom0.
+
 [BLKIF]: http://xenbits.xen.org/docs/unstable/hypercall/include,public,io,blkif.h.html
 [FBIF]: http://xenbits.xen.org/docs/unstable/hypercall/include,public,io,fbif.h.html
 [HVMPARAMS]: http://xenbits.xen.org/docs/unstable/hypercall/include,public,hvm,params.h.html
-- 
2.6.2

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* Re: [PATCH v3 01/15] xen: add xenstore domain flag to hypervisor
  2016-01-08 13:08 ` [PATCH v3 01/15] xen: add xenstore domain flag to hypervisor Juergen Gross
@ 2016-01-08 14:07   ` Jan Beulich
  2016-01-08 16:13     ` David Vrabel
       [not found]   ` <568FD0B902000078000C4E8F@suse.com>
  2016-01-15 15:50   ` Ian Campbell
  2 siblings, 1 reply; 35+ messages in thread
From: Jan Beulich @ 2016-01-08 14:07 UTC (permalink / raw)
  To: Juergen Gross
  Cc: Tim Deegan, wei.liu2, Ian.Campbell, stefano.stabellini,
	Andrew Cooper, ian.jackson, xen-devel, David Vrabel, Keir Fraser,
	dgdegra

>>> On 08.01.16 at 14:08, <JGross@suse.com> wrote:
> --- a/xen/common/domain.c
> +++ b/xen/common/domain.c
> @@ -318,6 +318,12 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
>          hardware_domain = d;
>      }
>  
> +    if ( domcr_flags & DOMCRF_xs_domain )
> +    {
> +        d->is_xenstore = 1;
> +        d->disable_migrate = 1;
> +    }

It only occurred to me now: Wouldn't it be worth denying the domain
creation request if there already is a xenstore domain?

Jan

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH v3 01/15] xen: add xenstore domain flag to hypervisor
       [not found]   ` <568FD0B902000078000C4E8F@suse.com>
@ 2016-01-08 14:22     ` Juergen Gross
  2016-01-08 14:25       ` Andrew Cooper
                         ` (2 more replies)
  0 siblings, 3 replies; 35+ messages in thread
From: Juergen Gross @ 2016-01-08 14:22 UTC (permalink / raw)
  To: Jan Beulich
  Cc: Tim Deegan, wei.liu2, Ian.Campbell, stefano.stabellini,
	Andrew Cooper, ian.jackson, xen-devel, David Vrabel, Keir Fraser,
	dgdegra

On 08/01/16 15:07, Jan Beulich wrote:
>>>> On 08.01.16 at 14:08, <JGross@suse.com> wrote:
>> --- a/xen/common/domain.c
>> +++ b/xen/common/domain.c
>> @@ -318,6 +318,12 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
>>          hardware_domain = d;
>>      }
>>  
>> +    if ( domcr_flags & DOMCRF_xs_domain )
>> +    {
>> +        d->is_xenstore = 1;
>> +        d->disable_migrate = 1;
>> +    }
> 
> It only occurred to me now: Wouldn't it be worth denying the domain
> creation request if there already is a xenstore domain?

Hmm, the only cases where this would make sense would be:

- some bug in dom0 resulting in parallel calls of init-xenstore-domain
- an out-of-tree tool in dom0 (or another domain capable of creating
  domains) creating a domain with the xenstore flag set

I'm really not sure what would be best here. Should the hypervisor
really be responsible for this decision?

In case it is desired, I can modify the patch accordingly (the
modification would be trivial).


Juergen

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH v3 01/15] xen: add xenstore domain flag to hypervisor
  2016-01-08 14:22     ` Juergen Gross
@ 2016-01-08 14:25       ` Andrew Cooper
  2016-01-08 16:03       ` Jan Beulich
       [not found]       ` <568FEBE402000078000C500D@suse.com>
  2 siblings, 0 replies; 35+ messages in thread
From: Andrew Cooper @ 2016-01-08 14:25 UTC (permalink / raw)
  To: Juergen Gross, Jan Beulich
  Cc: wei.liu2, Ian.Campbell, stefano.stabellini, Tim Deegan,
	ian.jackson, xen-devel, David Vrabel, Keir Fraser, dgdegra

On 08/01/16 14:22, Juergen Gross wrote:
> On 08/01/16 15:07, Jan Beulich wrote:
>>>>> On 08.01.16 at 14:08, <JGross@suse.com> wrote:
>>> --- a/xen/common/domain.c
>>> +++ b/xen/common/domain.c
>>> @@ -318,6 +318,12 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
>>>          hardware_domain = d;
>>>      }
>>>  
>>> +    if ( domcr_flags & DOMCRF_xs_domain )
>>> +    {
>>> +        d->is_xenstore = 1;
>>> +        d->disable_migrate = 1;
>>> +    }
>> It only occurred to me now: Wouldn't it be worth denying the domain
>> creation request if there already is a xenstore domain?
> Hmm, the only cases where this would make sense would be:
>
> - some bug in dom0 resulting in parallel calls of init-xenstore-domain
> - an out-of-tree tool in dom0 (or another domain capable of creating
>   domains) creating a domain with the xenstore flag set
>
> I'm really not sure what would be best here. Should the hypervisor
> really be responsible for this decision?
>
> In case it is desired, I can modify the patch accordingly (the
> modification would be trivial).

For now, it might be better to knobble it in Xen to weed out bugs.

However, given future plans for restartable or multiple xenstores, I
could easily see it becoming a valid option.

~Andrew

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH v3 01/15] xen: add xenstore domain flag to hypervisor
  2016-01-08 14:22     ` Juergen Gross
  2016-01-08 14:25       ` Andrew Cooper
@ 2016-01-08 16:03       ` Jan Beulich
       [not found]       ` <568FEBE402000078000C500D@suse.com>
  2 siblings, 0 replies; 35+ messages in thread
From: Jan Beulich @ 2016-01-08 16:03 UTC (permalink / raw)
  To: Juergen Gross
  Cc: Tim Deegan, wei.liu2, Ian.Campbell, stefano.stabellini,
	Andrew Cooper, ian.jackson, xen-devel, David Vrabel, Keir Fraser,
	dgdegra

>>> On 08.01.16 at 15:22, <JGross@suse.com> wrote:
> On 08/01/16 15:07, Jan Beulich wrote:
>>>>> On 08.01.16 at 14:08, <JGross@suse.com> wrote:
>>> --- a/xen/common/domain.c
>>> +++ b/xen/common/domain.c
>>> @@ -318,6 +318,12 @@ struct domain *domain_create(domid_t domid, unsigned 
> int domcr_flags,
>>>          hardware_domain = d;
>>>      }
>>>  
>>> +    if ( domcr_flags & DOMCRF_xs_domain )
>>> +    {
>>> +        d->is_xenstore = 1;
>>> +        d->disable_migrate = 1;
>>> +    }
>> 
>> It only occurred to me now: Wouldn't it be worth denying the domain
>> creation request if there already is a xenstore domain?
> 
> Hmm, the only cases where this would make sense would be:
> 
> - some bug in dom0 resulting in parallel calls of init-xenstore-domain

Or human (admin) error?

Jan

> - an out-of-tree tool in dom0 (or another domain capable of creating
>   domains) creating a domain with the xenstore flag set
> 
> I'm really not sure what would be best here. Should the hypervisor
> really be responsible for this decision?
> 
> In case it is desired, I can modify the patch accordingly (the
> modification would be trivial).
> 
> 
> Juergen

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH v3 01/15] xen: add xenstore domain flag to hypervisor
       [not found]       ` <568FEBE402000078000C500D@suse.com>
@ 2016-01-08 16:10         ` Juergen Gross
  0 siblings, 0 replies; 35+ messages in thread
From: Juergen Gross @ 2016-01-08 16:10 UTC (permalink / raw)
  To: Jan Beulich
  Cc: Tim Deegan, wei.liu2, Ian.Campbell, stefano.stabellini,
	Andrew Cooper, ian.jackson, xen-devel, David Vrabel, Keir Fraser,
	dgdegra

On 08/01/16 17:03, Jan Beulich wrote:
>>>> On 08.01.16 at 15:22, <JGross@suse.com> wrote:
>> On 08/01/16 15:07, Jan Beulich wrote:
>>>>>> On 08.01.16 at 14:08, <JGross@suse.com> wrote:
>>>> --- a/xen/common/domain.c
>>>> +++ b/xen/common/domain.c
>>>> @@ -318,6 +318,12 @@ struct domain *domain_create(domid_t domid, unsigned 
>> int domcr_flags,
>>>>          hardware_domain = d;
>>>>      }
>>>>  
>>>> +    if ( domcr_flags & DOMCRF_xs_domain )
>>>> +    {
>>>> +        d->is_xenstore = 1;
>>>> +        d->disable_migrate = 1;
>>>> +    }
>>>
>>> It only occurred to me now: Wouldn't it be worth denying the domain
>>> creation request if there already is a xenstore domain?
>>
>> Hmm, the only cases where this would make sense would be:
>>
>> - some bug in dom0 resulting in parallel calls of init-xenstore-domain
> 
> Or human (admin) error?

I don't think so. init-xenstore-domain checks whether xenstored or
another xenstore domain is already running and will fail in this case.
Multiple xenstore domains are possible only if init-xenstore-domain
is running multiple times in parallel and at least two instances
succeed in passing the check for another xenstored domain before
one instance did create the domain.

The only way to achieve this via admin error would be to duplicate
the start script/service and configure both to run in parallel.
I think this scenario is plausible only for an action done on
purpose.


Juergen

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH v3 01/15] xen: add xenstore domain flag to hypervisor
  2016-01-08 14:07   ` Jan Beulich
@ 2016-01-08 16:13     ` David Vrabel
  0 siblings, 0 replies; 35+ messages in thread
From: David Vrabel @ 2016-01-08 16:13 UTC (permalink / raw)
  To: Jan Beulich, Juergen Gross
  Cc: Tim Deegan, wei.liu2, Ian.Campbell, stefano.stabellini,
	Andrew Cooper, ian.jackson, xen-devel, Keir Fraser, dgdegra

On 08/01/16 14:07, Jan Beulich wrote:
>>>> On 08.01.16 at 14:08, <JGross@suse.com> wrote:
>> --- a/xen/common/domain.c
>> +++ b/xen/common/domain.c
>> @@ -318,6 +318,12 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
>>          hardware_domain = d;
>>      }
>>  
>> +    if ( domcr_flags & DOMCRF_xs_domain )
>> +    {
>> +        d->is_xenstore = 1;
>> +        d->disable_migrate = 1;
>> +    }
> 
> It only occurred to me now: Wouldn't it be worth denying the domain
> creation request if there already is a xenstore domain?

Running multiple xenstore domains, one for each isolated set of domains
managed by their own toolstack domain with their own backends seems like
a valid (future) use case.

David

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH v3 00/15] xenstore: make it easier to run xenstore in a domain
  2016-01-08 13:08 [PATCH v3 00/15] xenstore: make it easier to run xenstore in a domain Juergen Gross
                   ` (14 preceding siblings ...)
  2016-01-08 13:08 ` [PATCH v3 15/15] docs: document xenstore domain xenstore paths Juergen Gross
@ 2016-01-15 15:04 ` Juergen Gross
  15 siblings, 0 replies; 35+ messages in thread
From: Juergen Gross @ 2016-01-15 15:04 UTC (permalink / raw)
  To: xen-devel, Ian.Campbell, ian.jackson, stefano.stabellini,
	wei.liu2, dgdegra

On 08/01/16 14:08, Juergen Gross wrote:
> Xen supports to run xenstore in a dedicated domain. It is, however, a
> setup which isn't easy to configure. Today flask is required for full
> functionality and the resulting xenstore domain is not configurable in
> the same way as the xenstore daemon.
> 
> This patch series enables running a xenstore domain without flask. The
> tool needed to start that domain is added to the installed binaries
> and it is modified to pass arbitrary options to the xenstore domain.
> 
> I didn't include a configuration option for starting xenstore as an
> own domain instead of the daemon, as this will require some major
> tweaking of especially the systemd configuration files. Support for
> this will be added later. The main issue is that running xenstore in
> a domain requires the xenstore sockets not to be created. I don't
> think this is possible with the current scheme of letting systemd
> create those sockets.
> 
> Changes in V3:
> - patch 1: changed comment as requested by Ian Campbell
> - patch 2: changed name of flag from "xs_domain" to "xenstore" as requested
>            by Ian Campbell
> - patch 3: flag in dominfo instead function to get xenstore domid as requested
>            by Ian Campbell
> - patch 4: don't adapt coding style as requested by Ian Campbell
>            adjust .gitignore
> - new patch 5: adapt coding style of init-xenstore-domain.c
> - patch 6 (was 5): adjust .gitignore as requested by Ian Campbell
>            use libxentoollog instead of libxc as requested by Ian Campbell
> - patch 10 (was 9): 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
> - patch 14 (was 13): xl shutdown modified to query the "never_stop" flag
>            instead of the xenstore domain id as requested by Ian Campbell
>            drop usage of xenstore-exists as requested by Ian Campbell
> - new patch 15: add xenstore domain xenstroe paths to docs as requested by
>            Ian Campbell
> 
> Changes in V2:
> - add new patch 3 to get the xenstore domain id via libxl
> - move init-xenstore-domain to new directory tools/helpers in patch 4
>   (former patch 3) and modify it to use the standard tools coding style
> - add new patch 5 moving xen-init-dom0 to tools/helpers
> - split patch 6 (former patch 4) into 2 patches as requested by Ian Campbell
> - correct parameter parsing in patch 8 (former patch 5)
> - modified commit message of patch 9 (former patch 6) as requested by
>   Ian Campbell
> - add new patch 11 to split up xen-init-dom0
> - modify patch 12 (former patch 8) to create json object and more xenstore
>   entries, add error messages as requested by Ian Campbell
> - drop former patch 9
> - add new patch 13 to avoid stopping xenstore domain on dom0 shutdown
> 
> Juergen Gross (15):
>   xen: add xenstore domain flag to hypervisor
>   libxc: support new xenstore domain flag in libxc
>   libxl: provide a flag in dominfo to avoid stopping it
>   xenstore: move init-xenstore-domain to tools/helpers
>   xenstore: adjust coding style of init-xenstore-domain.c
>   libxl: move xen-init-dom0 to tools/helpers
>   xenstore: destroy xenstore domain in case of error after creating it
>   xenstore: add error messages to init-xenstore-domain
>   xenstore: modify init-xenstore-domain parameter syntax
>   xenstore: make use of the "xenstore domain" flag
>   xenstore: add init-xenstore-domain parameter to specify cmdline
>   tools: split up xen-init-dom0.c
>   xenstore: write xenstore domain data to xenstore
>   tools: don't stop xenstore domain when stopping dom0
>   docs: document xenstore domain xenstore paths
> 
>  .gitignore                            |   4 +-
>  docs/misc/xenstore-paths.markdown     |  10 +
>  tools/Makefile                        |   1 +
>  tools/helpers/Makefile                |  46 +++++
>  tools/helpers/init-dom-json.c         |  59 ++++++
>  tools/helpers/init-dom-json.h         |  18 ++
>  tools/helpers/init-xenstore-domain.c  | 343 ++++++++++++++++++++++++++++++++++
>  tools/helpers/xen-init-dom0.c         |  67 +++++++
>  tools/hotplug/Linux/xendomains.in     |  15 ++
>  tools/libxc/include/xenctrl.h         |   2 +-
>  tools/libxc/xc_domain.c               |   1 +
>  tools/libxl/Makefile                  |  14 +-
>  tools/libxl/libxl.c                   |  11 +-
>  tools/libxl/libxl.h                   |   9 +
>  tools/libxl/libxl_types.idl           |   1 +
>  tools/libxl/xen-init-dom0.c           | 120 ------------
>  tools/libxl/xl_cmdimpl.c              |   8 +-
>  tools/xenstore/Makefile               |   9 -
>  tools/xenstore/init-xenstore-domain.c | 119 ------------
>  xen/common/domain.c                   |   6 +
>  xen/common/domctl.c                   |  14 +-
>  xen/include/public/domctl.h           |   6 +
>  xen/include/xen/sched.h               |   5 +
>  xen/include/xsm/dummy.h               |   6 +
>  xen/include/xsm/xsm.h                 |   1 +
>  25 files changed, 620 insertions(+), 275 deletions(-)
>  create mode 100644 tools/helpers/Makefile
>  create mode 100644 tools/helpers/init-dom-json.c
>  create mode 100644 tools/helpers/init-dom-json.h
>  create mode 100644 tools/helpers/init-xenstore-domain.c
>  create mode 100644 tools/helpers/xen-init-dom0.c
>  delete mode 100644 tools/libxl/xen-init-dom0.c
>  delete mode 100644 tools/xenstore/init-xenstore-domain.c

I'd appreciate some more comments/Acks.


Juergen

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH v3 01/15] xen: add xenstore domain flag to hypervisor
  2016-01-08 13:08 ` [PATCH v3 01/15] xen: add xenstore domain flag to hypervisor Juergen Gross
  2016-01-08 14:07   ` Jan Beulich
       [not found]   ` <568FD0B902000078000C4E8F@suse.com>
@ 2016-01-15 15:50   ` Ian Campbell
  2 siblings, 0 replies; 35+ messages in thread
From: Ian Campbell @ 2016-01-15 15:50 UTC (permalink / raw)
  To: Juergen Gross, xen-devel, ian.jackson, stefano.stabellini,
	wei.liu2, dgdegra
  Cc: Tim Deegan, Keir Fraser, David Vrabel, Jan Beulich, Andrew Cooper

On Fri, 2016-01-08 at 14:08 +0100, Juergen Gross wrote:
> In order to be able to have full support of a xenstore domain in Xen
> add a "Xenstore-domain" flag to the hypervisor. This flag must be
> specified at domain creation time and is returned by
> XEN_DOMCTL_getdomaininfo.
> 
> It will allow the domain to retrieve domain information by issuing the
> XEN_DOMCTL_getdomaininfo itself in order to be able to check for
> domains having been destroyed. At the same time this flag will inhibit
> the domain to be migrated, as this wouldn't be a very wise thing to do.
> 
> In case of a later support of a rebootable Dom0 this flag will allow to
> recognize a xenstore domain already being present to connect to.
> 
> Cc: Jan Beulich <jbeulich@suse.com>
> Cc: Keir Fraser <keir@xen.org>
> Cc: Tim Deegan <tim@xen.org>
> Cc: Andrew Cooper <andrew.cooper3@citrix.com>
> Cc: David Vrabel <david.vrabel@citrix.com>
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>
> Acked-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
> Reviewed-by: Andrew Cooper <andrew.cooper3@citirx.com>

Acked-by: Ian Campbell <ian.campbell@citrix.com>

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH v3 03/15] libxl: provide a flag in dominfo to avoid stopping it
  2016-01-08 13:08 ` [PATCH v3 03/15] libxl: provide a flag in dominfo to avoid stopping it Juergen Gross
@ 2016-01-15 15:51   ` Ian Campbell
  0 siblings, 0 replies; 35+ messages in thread
From: Ian Campbell @ 2016-01-15 15:51 UTC (permalink / raw)
  To: Juergen Gross, xen-devel, ian.jackson, stefano.stabellini,
	wei.liu2, dgdegra

On Fri, 2016-01-08 at 14:08 +0100, Juergen Gross wrote:
> Add a "never_stop" flag to dominfo as indicator for the toolstack that
> this domain is to be kept running. For now it is being set for xenstore
> domain, but there might be other domains in the future.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Acked-by: Ian Campbell <ian.campbell@citrix.com>

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH v3 04/15] xenstore: move init-xenstore-domain to tools/helpers
  2016-01-08 13:08 ` [PATCH v3 04/15] xenstore: move init-xenstore-domain to tools/helpers Juergen Gross
@ 2016-01-15 15:51   ` Ian Campbell
  0 siblings, 0 replies; 35+ messages in thread
From: Ian Campbell @ 2016-01-15 15:51 UTC (permalink / raw)
  To: Juergen Gross, xen-devel, ian.jackson, stefano.stabellini,
	wei.liu2, dgdegra

On Fri, 2016-01-08 at 14:08 +0100, Juergen Gross wrote:
> The program init-xenstore-domain to start a xenstore domain instead
> of the xenstored daemon is built, but not installed. Change that.
> 
> Move the program to a new tools subdirectory "helpers" to be able to
> use libxl in a later patch. Otherwise a dependency loop will be
> created.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Acked-by: Ian Campbell <ian.campbell@citrix.com>

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH v3 05/15] xenstore: adjust coding style of init-xenstore-domain.c
  2016-01-08 13:08 ` [PATCH v3 05/15] xenstore: adjust coding style of init-xenstore-domain.c Juergen Gross
@ 2016-01-15 15:54   ` Ian Campbell
  0 siblings, 0 replies; 35+ messages in thread
From: Ian Campbell @ 2016-01-15 15:54 UTC (permalink / raw)
  To: Juergen Gross, xen-devel, ian.jackson, stefano.stabellini,
	wei.liu2, dgdegra

On Fri, 2016-01-08 at 14:08 +0100, Juergen Gross wrote:
> Adjust the coding style of init-xenstore-domain.c to the general Xen
> coding style.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Acked-by: Ian Campbell <ian.campbell@citrix.com>

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH v3 06/15] libxl: move xen-init-dom0 to tools/helpers
  2016-01-08 13:08 ` [PATCH v3 06/15] libxl: move xen-init-dom0 to tools/helpers Juergen Gross
@ 2016-01-15 15:55   ` Ian Campbell
  0 siblings, 0 replies; 35+ messages in thread
From: Ian Campbell @ 2016-01-15 15:55 UTC (permalink / raw)
  To: Juergen Gross, xen-devel, ian.jackson, stefano.stabellini,
	wei.liu2, dgdegra

On Fri, 2016-01-08 at 14:08 +0100, Juergen Gross wrote:
> Move xen-init-dom0 from tools/libxl to tools/helpers, as it is just a
> helper program.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Acked-by: Ian Campbell <ian.campbell@citrix.com>

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH v3 07/15] xenstore: destroy xenstore domain in case of error after creating it
  2016-01-08 13:08 ` [PATCH v3 07/15] xenstore: destroy xenstore domain in case of error after creating it Juergen Gross
@ 2016-01-15 16:02   ` Ian Campbell
  0 siblings, 0 replies; 35+ messages in thread
From: Ian Campbell @ 2016-01-15 16:02 UTC (permalink / raw)
  To: Juergen Gross, xen-devel, ian.jackson, stefano.stabellini,
	wei.liu2, dgdegra

On Fri, 2016-01-08 at 14:08 +0100, Juergen Gross wrote:
> When creating a xenstore domain via init-xenstore-domain destroy it
> in case of an error occurred after calling xc_domain_create().
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>
> Acked-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>

Acked-by: Ian Campbell <ian.campbell@citrix.com>

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH v3 10/15] xenstore: make use of the "xenstore domain" flag
  2016-01-08 13:08 ` [PATCH v3 10/15] xenstore: make use of the "xenstore domain" flag Juergen Gross
@ 2016-01-15 16:03   ` Ian Campbell
  0 siblings, 0 replies; 35+ messages in thread
From: Ian Campbell @ 2016-01-15 16:03 UTC (permalink / raw)
  To: Juergen Gross, xen-devel, ian.jackson, stefano.stabellini,
	wei.liu2, dgdegra

On Fri, 2016-01-08 at 14:08 +0100, Juergen Gross wrote:
> 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 <jgross@suse.com>

Acked-by: Ian Campbell <ian.campbell@citrix.com>

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH v3 14/15] tools: don't stop xenstore domain when stopping dom0
  2016-01-08 13:08 ` [PATCH v3 14/15] tools: don't stop xenstore domain when stopping dom0 Juergen Gross
@ 2016-01-15 16:12   ` Ian Campbell
  2016-01-15 16:24     ` Juergen Gross
  0 siblings, 1 reply; 35+ messages in thread
From: Ian Campbell @ 2016-01-15 16:12 UTC (permalink / raw)
  To: Juergen Gross, xen-devel, ian.jackson, stefano.stabellini,
	wei.liu2, dgdegra

On Fri, 2016-01-08 at 14:08 +0100, Juergen Gross wrote:
> +# get xenstore domain id (or 0 if no xenstore domain)
> +get_xsdomid()
> +{
> +    XS_DOMID=`${bindir}/xenstore-read /tool/xenstored/domid 2>/dev/null`
> +    if test $? -ne 0; then
> +        XS_DOMID=0
> +    fi

In principal this could be:
+    XS_DOMID=`${bindir}/xenstore-read /tool/xenstored/domid 2>/dev/null || echo 0`

But I'm far from convinced that is an improvement.

> diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
> index f9933cb..29f9d19 100644
> --- a/tools/libxl/xl_cmdimpl.c
> +++ b/tools/libxl/xl_cmdimpl.c
> @@ -4856,15 +4856,17 @@ static int main_shutdown_or_reboot(int do_reboot,
> int argc, char **argv)
>          if (wait_for_it)
>              deathws = calloc(nb_domain, sizeof(*deathws));
>  
> +        wait_for_it = 0;

Please can we avoid reusing the boolean flag used for argument handling as
a counter.

I think you will need to introduce a new nrdeathws.

I was thinking if you could invert the loop to count downwards such that
you can decrement nb_domain for uninteresting domains, but then the uses of
deathws[i] don't work, the solving of which would no doubt require another
variable anyway.


>          for (i = 0; i<nb_domain; i++) {
> -            if (dominfo[i].domid == 0)
> +            if (dominfo[i].domid == 0 || dominfo[i].never_stop)
>                  continue;
>              fn(dominfo[i].domid, deathws ? &deathws[i] : NULL, i,
>                 fallback_trigger);
> +            wait_for_it++;
>          }
>  
> -        if (wait_for_it) {
> -            wait_for_domain_deaths(deathws, nb_domain - 1 /* not dom 0
> */);
> +        if (deathws) {
> +            wait_for_domain_deaths(deathws, wait_for_it);
>              free(deathws);
>          }
>  
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH v3 15/15] docs: document xenstore domain xenstore paths
  2016-01-08 13:08 ` [PATCH v3 15/15] docs: document xenstore domain xenstore paths Juergen Gross
@ 2016-01-15 16:14   ` Ian Campbell
  2016-01-15 16:22     ` Juergen Gross
  0 siblings, 1 reply; 35+ messages in thread
From: Ian Campbell @ 2016-01-15 16:14 UTC (permalink / raw)
  To: Juergen Gross, xen-devel, ian.jackson, stefano.stabellini,
	wei.liu2, dgdegra

On Fri, 2016-01-08 at 14:08 +0100, Juergen Gross wrote:
> Add the xenstore domain specific xenstore paths to
> docs/misc/xenstore-paths.markdown
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

One typo below, otherwise:

Acked-by: Ian Campbell <ian.campbell@citrix.com>

You could fold this into some earlier patch which first uses these paths,
if such a patch exists (and you can be bothered).

> ---
>  docs/misc/xenstore-paths.markdown | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/docs/misc/xenstore-paths.markdown b/docs/misc/xenstore-
> paths.markdown
> index 197bb0f..4712e3a 100644
> --- a/docs/misc/xenstore-paths.markdown
> +++ b/docs/misc/xenstore-paths.markdown
> @@ -509,6 +509,16 @@ The device model version for a domain.
>  
>  ifb device used by Remus to buffer network output from the associated
> vif.
>  
> +### xenstored specific paths
> +
> +The /tool/xenstored namespace is created by the xenstore daemon or
> domain
> +for the toolstack to obtain e.g. the domain id of a xenstore domain.
> +
> +#### /tool/xenstored/domid = INTEGER [n,INTERNAL]
> +
> +Domain Id of the xenstroe domain in case xenstore is provided via a

"xenstore"


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH v3 15/15] docs: document xenstore domain xenstore paths
  2016-01-15 16:14   ` Ian Campbell
@ 2016-01-15 16:22     ` Juergen Gross
  2016-01-15 16:27       ` Ian Campbell
  0 siblings, 1 reply; 35+ messages in thread
From: Juergen Gross @ 2016-01-15 16:22 UTC (permalink / raw)
  To: Ian Campbell, xen-devel, ian.jackson, stefano.stabellini,
	wei.liu2, dgdegra

On 15/01/16 17:14, Ian Campbell wrote:
> On Fri, 2016-01-08 at 14:08 +0100, Juergen Gross wrote:
>> Add the xenstore domain specific xenstore paths to
>> docs/misc/xenstore-paths.markdown
>>
>> Signed-off-by: Juergen Gross <jgross@suse.com>
> 
> One typo below, otherwise:
> 
> Acked-by: Ian Campbell <ian.campbell@citrix.com>
> 
> You could fold this into some earlier patch which first uses these paths,
> if such a patch exists (and you can be bothered).

As the /tool/xenstored/ path isn't introduced by any of my patches in
this series I don't think this would be appropriate. And just due to
consuming it in patch 14 I don't think these two patches should be
merged.

> 
>> ---
>>  docs/misc/xenstore-paths.markdown | 10 ++++++++++
>>  1 file changed, 10 insertions(+)
>>
>> diff --git a/docs/misc/xenstore-paths.markdown b/docs/misc/xenstore-
>> paths.markdown
>> index 197bb0f..4712e3a 100644
>> --- a/docs/misc/xenstore-paths.markdown
>> +++ b/docs/misc/xenstore-paths.markdown
>> @@ -509,6 +509,16 @@ The device model version for a domain.
>>  
>>  ifb device used by Remus to buffer network output from the associated
>> vif.
>>  
>> +### xenstored specific paths
>> +
>> +The /tool/xenstored namespace is created by the xenstore daemon or
>> domain
>> +for the toolstack to obtain e.g. the domain id of a xenstore domain.
>> +
>> +#### /tool/xenstored/domid = INTEGER [n,INTERNAL]
>> +
>> +Domain Id of the xenstroe domain in case xenstore is provided via a
> 
> "xenstore"

Uuh, yes. I'll correct it.


Thanks,

Juergen

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH v3 14/15] tools: don't stop xenstore domain when stopping dom0
  2016-01-15 16:12   ` Ian Campbell
@ 2016-01-15 16:24     ` Juergen Gross
  0 siblings, 0 replies; 35+ messages in thread
From: Juergen Gross @ 2016-01-15 16:24 UTC (permalink / raw)
  To: Ian Campbell, xen-devel, ian.jackson, stefano.stabellini,
	wei.liu2, dgdegra

On 15/01/16 17:12, Ian Campbell wrote:
> On Fri, 2016-01-08 at 14:08 +0100, Juergen Gross wrote:
>> +# get xenstore domain id (or 0 if no xenstore domain)
>> +get_xsdomid()
>> +{
>> +    XS_DOMID=`${bindir}/xenstore-read /tool/xenstored/domid 2>/dev/null`
>> +    if test $? -ne 0; then
>> +        XS_DOMID=0
>> +    fi
> 
> In principal this could be:
> +    XS_DOMID=`${bindir}/xenstore-read /tool/xenstored/domid 2>/dev/null || echo 0`
> 
> But I'm far from convinced that is an improvement.

I think I'll leave it as before.

> 
>> diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
>> index f9933cb..29f9d19 100644
>> --- a/tools/libxl/xl_cmdimpl.c
>> +++ b/tools/libxl/xl_cmdimpl.c
>> @@ -4856,15 +4856,17 @@ static int main_shutdown_or_reboot(int do_reboot,
>> int argc, char **argv)
>>          if (wait_for_it)
>>              deathws = calloc(nb_domain, sizeof(*deathws));
>>  
>> +        wait_for_it = 0;
> 
> Please can we avoid reusing the boolean flag used for argument handling as
> a counter.
> 
> I think you will need to introduce a new nrdeathws.

Okay, will do.


Thanks,

Juergen

^ permalink raw reply	[flat|nested] 35+ messages in thread

* Re: [PATCH v3 15/15] docs: document xenstore domain xenstore paths
  2016-01-15 16:22     ` Juergen Gross
@ 2016-01-15 16:27       ` Ian Campbell
  0 siblings, 0 replies; 35+ messages in thread
From: Ian Campbell @ 2016-01-15 16:27 UTC (permalink / raw)
  To: Juergen Gross, xen-devel, ian.jackson, stefano.stabellini,
	wei.liu2, dgdegra

On Fri, 2016-01-15 at 17:22 +0100, Juergen Gross wrote:
> On 15/01/16 17:14, Ian Campbell wrote:
> > On Fri, 2016-01-08 at 14:08 +0100, Juergen Gross wrote:
> > > Add the xenstore domain specific xenstore paths to
> > > docs/misc/xenstore-paths.markdown
> > > 
> > > Signed-off-by: Juergen Gross <jgross@suse.com>
> > 
> > One typo below, otherwise:
> > 
> > Acked-by: Ian Campbell <ian.campbell@citrix.com>
> > 
> > You could fold this into some earlier patch which first uses these
> > paths,
> > if such a patch exists (and you can be bothered).
> 
> As the /tool/xenstored/ path isn't introduced by any of my patches in
> this series I don't think this would be appropriate. And just due to
> consuming it in patch 14 I don't think these two patches should be
> merged.

Ah, fair enough.

^ permalink raw reply	[flat|nested] 35+ messages in thread

end of thread, other threads:[~2016-01-15 16:27 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-08 13:08 [PATCH v3 00/15] xenstore: make it easier to run xenstore in a domain Juergen Gross
2016-01-08 13:08 ` [PATCH v3 01/15] xen: add xenstore domain flag to hypervisor Juergen Gross
2016-01-08 14:07   ` Jan Beulich
2016-01-08 16:13     ` David Vrabel
     [not found]   ` <568FD0B902000078000C4E8F@suse.com>
2016-01-08 14:22     ` Juergen Gross
2016-01-08 14:25       ` Andrew Cooper
2016-01-08 16:03       ` Jan Beulich
     [not found]       ` <568FEBE402000078000C500D@suse.com>
2016-01-08 16:10         ` Juergen Gross
2016-01-15 15:50   ` Ian Campbell
2016-01-08 13:08 ` [PATCH v3 02/15] libxc: support new xenstore domain flag in libxc Juergen Gross
2016-01-08 13:08 ` [PATCH v3 03/15] libxl: provide a flag in dominfo to avoid stopping it Juergen Gross
2016-01-15 15:51   ` Ian Campbell
2016-01-08 13:08 ` [PATCH v3 04/15] xenstore: move init-xenstore-domain to tools/helpers Juergen Gross
2016-01-15 15:51   ` Ian Campbell
2016-01-08 13:08 ` [PATCH v3 05/15] xenstore: adjust coding style of init-xenstore-domain.c Juergen Gross
2016-01-15 15:54   ` Ian Campbell
2016-01-08 13:08 ` [PATCH v3 06/15] libxl: move xen-init-dom0 to tools/helpers Juergen Gross
2016-01-15 15:55   ` Ian Campbell
2016-01-08 13:08 ` [PATCH v3 07/15] xenstore: destroy xenstore domain in case of error after creating it Juergen Gross
2016-01-15 16:02   ` Ian Campbell
2016-01-08 13:08 ` [PATCH v3 08/15] xenstore: add error messages to init-xenstore-domain Juergen Gross
2016-01-08 13:08 ` [PATCH v3 09/15] xenstore: modify init-xenstore-domain parameter syntax Juergen Gross
2016-01-08 13:08 ` [PATCH v3 10/15] xenstore: make use of the "xenstore domain" flag Juergen Gross
2016-01-15 16:03   ` Ian Campbell
2016-01-08 13:08 ` [PATCH v3 11/15] xenstore: add init-xenstore-domain parameter to specify cmdline Juergen Gross
2016-01-08 13:08 ` [PATCH v3 12/15] tools: split up xen-init-dom0.c Juergen Gross
2016-01-08 13:08 ` [PATCH v3 13/15] xenstore: write xenstore domain data to xenstore Juergen Gross
2016-01-08 13:08 ` [PATCH v3 14/15] tools: don't stop xenstore domain when stopping dom0 Juergen Gross
2016-01-15 16:12   ` Ian Campbell
2016-01-15 16:24     ` Juergen Gross
2016-01-08 13:08 ` [PATCH v3 15/15] docs: document xenstore domain xenstore paths Juergen Gross
2016-01-15 16:14   ` Ian Campbell
2016-01-15 16:22     ` Juergen Gross
2016-01-15 16:27       ` Ian Campbell
2016-01-15 15:04 ` [PATCH v3 00/15] xenstore: make it easier to run xenstore in a domain Juergen Gross

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.