All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v6 00/13] xen: add systemd support
@ 2014-06-13  1:18 Luis R. Rodriguez
  2014-06-13  1:18 ` [PATCH v6 01/13] xenstored: enable usage of config.h on both xenstored and oxenstored Luis R. Rodriguez
                   ` (14 more replies)
  0 siblings, 15 replies; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-06-13  1:18 UTC (permalink / raw)
  To: xen-devel; +Cc: Luis R. Rodriguez

From: "Luis R. Rodriguez" <mcgrof@suse.com>

Here's my v6 series. It should address all the feedback I've gotten
fron the v5 series. I've compile tested and run time tested this
on both systemd (OpenSUSE 13.1) and non-systemd systems (Debian testing)
with cxenstored and oxenstored preferences.

The launcher thing is resolved now by using shell to do the explicit
launching for us. This all also goes rebased an testd against today's
git tree master branch.

Luis R. Rodriguez (13):
  xenstored: enable usage of config.h on both xenstored and oxenstored
  cxenstored: add support for systemd active sockets
  oxenstored: add support for systemd active sockets
  oxenstored: force FD_CLOEXEC with Unix.set_close_on_exec on LSB init
  tools/xendomains: make xl the default and remove xm usage
  tools/xendomains: do space cleanups
  tools/xendomains: move to libexec and use a smaller init helper
  autoconf: xen: force a refresh with autoconf
  autoconf: update m4/pkg.m4
  autoconf: xen: move standard path variables to config/Paths.mk.in
  xencommons: move module list into a generic place
  autoconf: xen: enable explicit preference option for xenstored
    preference
  systemd: add xen systemd service and module files

 .gitignore                                         |   6 +
 Makefile                                           |   6 +-
 README                                             |  77 +++
 autogen.sh                                         |   8 +-
 config/Paths.mk.in                                 |  37 ++
 config/Stubdom.mk.in                               |   1 +
 config/Tools.mk.in                                 |   6 +
 config/modules                                     |  16 +
 configure.ac                                       |   8 +-
 m4/README.source                                   |  38 ++
 m4/paths.m4                                        |  61 +++
 m4/pkg.m4                                          |  88 +++-
 m4/systemd.m4                                      | 123 +++++
 m4/xenstored.m4                                    |  60 +++
 stubdom/Makefile                                   |   1 +
 tools/Rules.mk                                     |   1 +
 tools/configure.ac                                 |  30 +-
 tools/hotplug/Linux/Makefile                       |  45 +-
 ...ysconfig.xencommons => sysconfig.xencommons.in} |  13 +-
 .../Linux/init.d/{xencommons => xencommons.in.in}  |  24 +-
 tools/hotplug/Linux/init.d/xendomains              | 567 +-------------------
 tools/hotplug/Linux/systemd/Makefile               |  67 +++
 tools/hotplug/Linux/systemd/proc-xen.mount.in      |   9 +
 .../Linux/systemd/var-lib-xenstored.mount.in       |  13 +
 .../systemd/xen-qemu-dom0-disk-backend.service.in  |  22 +
 .../hotplug/Linux/systemd/xen-watchdog.service.in  |  13 +
 tools/hotplug/Linux/systemd/xenconsoled.service.in |  20 +
 tools/hotplug/Linux/systemd/xendomains.service.in  |  16 +
 tools/hotplug/Linux/systemd/xenstored.service.in   |  27 +
 tools/hotplug/Linux/systemd/xenstored.socket.in    |  11 +
 tools/hotplug/Linux/systemd/xenstored_ro.socket.in |  11 +
 tools/hotplug/Linux/xendomains                     | 584 +++++++++++++++++++++
 tools/ocaml/xenstored/Makefile                     |  15 +-
 tools/ocaml/xenstored/systemd.ml                   |  17 +
 tools/ocaml/xenstored/systemd.mli                  |  24 +
 tools/ocaml/xenstored/systemd_stubs.c              | 158 ++++++
 tools/ocaml/xenstored/utils.ml                     |  21 +-
 tools/ocaml/xenstored/xenstored.ml                 |   2 +
 tools/xenstore/Makefile                            |   7 +
 tools/xenstore/xenstored_core.c                    | 110 +++-
 40 files changed, 1759 insertions(+), 604 deletions(-)
 create mode 100644 config/Paths.mk.in
 create mode 100644 config/modules
 create mode 100644 m4/README.source
 create mode 100644 m4/paths.m4
 create mode 100644 m4/systemd.m4
 create mode 100644 m4/xenstored.m4
 rename tools/hotplug/Linux/init.d/{sysconfig.xencommons => sysconfig.xencommons.in} (64%)
 rename tools/hotplug/Linux/init.d/{xencommons => xencommons.in.in} (82%)
 create mode 100644 tools/hotplug/Linux/systemd/Makefile
 create mode 100644 tools/hotplug/Linux/systemd/proc-xen.mount.in
 create mode 100644 tools/hotplug/Linux/systemd/var-lib-xenstored.mount.in
 create mode 100644 tools/hotplug/Linux/systemd/xen-qemu-dom0-disk-backend.service.in
 create mode 100644 tools/hotplug/Linux/systemd/xen-watchdog.service.in
 create mode 100644 tools/hotplug/Linux/systemd/xenconsoled.service.in
 create mode 100644 tools/hotplug/Linux/systemd/xendomains.service.in
 create mode 100644 tools/hotplug/Linux/systemd/xenstored.service.in
 create mode 100644 tools/hotplug/Linux/systemd/xenstored.socket.in
 create mode 100644 tools/hotplug/Linux/systemd/xenstored_ro.socket.in
 create mode 100644 tools/hotplug/Linux/xendomains
 create mode 100644 tools/ocaml/xenstored/systemd.ml
 create mode 100644 tools/ocaml/xenstored/systemd.mli
 create mode 100644 tools/ocaml/xenstored/systemd_stubs.c

-- 
2.0.0.rc3.18.g00a5b79

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

* [PATCH v6 01/13] xenstored: enable usage of config.h on both xenstored and oxenstored
  2014-06-13  1:18 [PATCH v6 00/13] xen: add systemd support Luis R. Rodriguez
@ 2014-06-13  1:18 ` Luis R. Rodriguez
  2014-06-13  1:18 ` [PATCH v6 02/13] cxenstored: add support for systemd active sockets Luis R. Rodriguez
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-06-13  1:18 UTC (permalink / raw)
  To: xen-devel; +Cc: Luis R. Rodriguez

From: "Luis R. Rodriguez" <mcgrof@suse.com>

This will be used later for dynamic configuration paths on C code.

Acked-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
---
 tools/ocaml/xenstored/Makefile | 2 ++
 tools/xenstore/Makefile        | 1 +
 2 files changed, 3 insertions(+)

diff --git a/tools/ocaml/xenstored/Makefile b/tools/ocaml/xenstored/Makefile
index b18f190..7fa8f53 100644
--- a/tools/ocaml/xenstored/Makefile
+++ b/tools/ocaml/xenstored/Makefile
@@ -2,6 +2,8 @@ XEN_ROOT = $(CURDIR)/../../..
 OCAML_TOPLEVEL = $(CURDIR)/..
 include $(OCAML_TOPLEVEL)/common.make
 
+CFLAGS += -I$(XEN_ROOT)/tools/
+
 OCAMLINCLUDE += \
 	-I $(OCAML_TOPLEVEL)/libs/xb \
 	-I $(OCAML_TOPLEVEL)/libs/mmap \
diff --git a/tools/xenstore/Makefile b/tools/xenstore/Makefile
index b626104..55ca7a3 100644
--- a/tools/xenstore/Makefile
+++ b/tools/xenstore/Makefile
@@ -6,6 +6,7 @@ MINOR = 3
 
 CFLAGS += -Werror
 CFLAGS += -I.
+CFLAGS += -I$(XEN_ROOT)/tools/
 CFLAGS += $(CFLAGS_libxenctrl)
 
 CLIENTS := xenstore-exists xenstore-list xenstore-read xenstore-rm xenstore-chmod
-- 
2.0.0.rc3.18.g00a5b79

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

* [PATCH v6 02/13] cxenstored: add support for systemd active sockets
  2014-06-13  1:18 [PATCH v6 00/13] xen: add systemd support Luis R. Rodriguez
  2014-06-13  1:18 ` [PATCH v6 01/13] xenstored: enable usage of config.h on both xenstored and oxenstored Luis R. Rodriguez
@ 2014-06-13  1:18 ` Luis R. Rodriguez
  2014-07-02 13:02   ` Ian Campbell
  2014-06-13  1:18 ` [PATCH v6 03/13] oxenstored: " Luis R. Rodriguez
                   ` (12 subsequent siblings)
  14 siblings, 1 reply; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-06-13  1:18 UTC (permalink / raw)
  To: xen-devel; +Cc: Luis R. Rodriguez

From: "Luis R. Rodriguez" <mcgrof@suse.com>

This adds systemd socket activation support for the C xenstored.
Active sockets enable xenstored to be loaded only if required by a system
onto which Xen is installed on. Socket activation is handled by
systemd, once a port for a service which claims a socket is used
systemd will start the required services for it, on demand. For more
details on socket activation refer to Lennart's socket-activation
post regarding this [0].

Right now this code adds a no-op for this functionality, leaving the
enablement to be done later once systemd is properly hooked into
the build system. The socket activation is ordered in aligment with
the socket activation order passed on to systemd.

[0] http://0pointer.de/blog/projects/socket-activation2.html

Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
---
 tools/xenstore/xenstored_core.c | 110 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 109 insertions(+), 1 deletion(-)

diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
index 47f0722..6270618 100644
--- a/tools/xenstore/xenstored_core.c
+++ b/tools/xenstore/xenstored_core.c
@@ -40,6 +40,7 @@
 #include <signal.h>
 #include <assert.h>
 #include <setjmp.h>
+#include <config.h>
 
 #include "utils.h"
 #include "list.h"
@@ -54,6 +55,16 @@
 
 #include "hashtable.h"
 
+#ifndef NO_SOCKETS
+#if defined(HAVE_SYSTEMD)
+#define XEN_SYSTEMD_ENABLED 1
+#endif
+#endif
+
+#if defined(XEN_SYSTEMD_ENABLED)
+#include <systemd/sd-daemon.h>
+#endif
+
 extern xc_evtchn *xce_handle; /* in xenstored_domain.c */
 static int xce_pollfd_idx = -1;
 static struct pollfd *fds;
@@ -1714,6 +1725,81 @@ static int destroy_fd(void *_fd)
 	return 0;
 }
 
+#if defined(XEN_SYSTEMD_ENABLED)
+/* Will work regardless of the order systemd gives them to us */
+int xs_get_sd_fd(const char *connect_to)
+{
+	int fd = SD_LISTEN_FDS_START;
+	int r;
+
+	while (fd <= SD_LISTEN_FDS_START + 1) {
+		r = sd_is_socket_unix(fd, SOCK_STREAM, 1, connect_to, 0);
+		if (r > 0)
+			return fd;
+		fd++;
+	}
+
+	return -EBADR;
+}
+
+int xs_validate_active_socket(const char *connect_to)
+{
+	char sock[30];
+
+	/* We have to null terminate the socket path */
+	memset(sock, '\0', sizeof(sock));
+	memcpy(sock, connect_to, strlen(connect_to));
+
+	if ((strncmp("/var/run/xenstored/socket_ro", sock, 28) != 0) &&
+	    (strncmp("/var/run/xenstored/socket", sock, 25) != 0)) {
+		sd_notifyf(0, "STATUS=unexpected socket: %s\n"
+			   "ERRNO=%i",
+			   connect_to,
+			   EBADR);
+		return -EBADR;
+	}
+
+	return xs_get_sd_fd(sock);
+}
+
+static void xen_claim_active_sockets(int **psock, int **pro_sock)
+{
+	int *sock, *ro_sock;
+	const char *soc_str = xs_daemon_socket();
+	const char *soc_str_ro = xs_daemon_socket_ro();
+	int n;
+
+	n = sd_listen_fds(0);
+	if (n <= 0) {
+		sd_notifyf(0, "STATUS=Failed to get any active sockets: %s\n"
+			   "ERRNO=%i",
+			   strerror(errno),
+			   errno);
+		barf_perror("sd_listen_fds() failed\n");
+	} else if (n > 2) {
+		fprintf(stderr, SD_ERR "Expected 2 fds but given %d\n", n);
+		sd_notifyf(0, "STATUS=Mismatch on number (2): %s\n"
+			   "ERRNO=%d",
+			   strerror(EBADR),
+			   EBADR);
+		barf_perror("sd_listen_fds() gave too many fds\n");
+	}
+
+	*psock = sock = talloc(talloc_autofree_context(), int);
+	*sock = xs_validate_active_socket(soc_str);
+	if (*sock <= 0)
+		barf_perror("%s", soc_str);
+
+	*pro_sock = ro_sock = talloc(talloc_autofree_context(), int);
+	*ro_sock = xs_validate_active_socket(soc_str_ro);
+	if (*ro_sock <= 0)
+		barf_perror("%s", soc_str_ro);
+
+	talloc_set_destructor(sock, destroy_fd);
+	talloc_set_destructor(ro_sock, destroy_fd);
+}
+#endif
+
 static void init_sockets(int **psock, int **pro_sock)
 {
 	struct sockaddr_un addr;
@@ -1884,6 +1970,15 @@ int main(int argc, char *argv[])
 	if (optind != argc)
 		barf("%s: No arguments desired", argv[0]);
 
+#if defined(XEN_SYSTEMD_ENABLED)
+	if (sd_booted()) {
+		dofork = false;
+		if (pidfile)
+			barf("%s: PID file not needed on systemd", argv[0]);
+		pidfile = NULL;
+	}
+#endif
+
 	reopen_log();
 
 	/* make sure xenstored directories exist */
@@ -1905,7 +2000,13 @@ int main(int argc, char *argv[])
 	/* Don't kill us with SIGPIPE. */
 	signal(SIGPIPE, SIG_IGN);
 
-	init_sockets(&sock, &ro_sock);
+#if defined(XEN_SYSTEMD_ENABLED)
+	if (sd_booted())
+		xen_claim_active_sockets(&sock, &ro_sock);
+	else
+#endif
+		init_sockets(&sock, &ro_sock);
+
 	init_pipe(reopen_log_pipe);
 
 	/* Setup the database */
@@ -1936,6 +2037,13 @@ int main(int argc, char *argv[])
 	/* Tell the kernel we're up and running. */
 	xenbus_notify_running();
 
+#if defined(XEN_SYSTEMD_ENABLED)
+	if (sd_booted()) {
+		sd_notify(1, "READY=1");
+		fprintf(stderr, SD_NOTICE "xenstored is ready\n");
+	}
+#endif
+
 	/* Main loop. */
 	for (;;) {
 		struct connection *conn, *next;
-- 
2.0.0.rc3.18.g00a5b79

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

* [PATCH v6 03/13] oxenstored: add support for systemd active sockets
  2014-06-13  1:18 [PATCH v6 00/13] xen: add systemd support Luis R. Rodriguez
  2014-06-13  1:18 ` [PATCH v6 01/13] xenstored: enable usage of config.h on both xenstored and oxenstored Luis R. Rodriguez
  2014-06-13  1:18 ` [PATCH v6 02/13] cxenstored: add support for systemd active sockets Luis R. Rodriguez
@ 2014-06-13  1:18 ` Luis R. Rodriguez
  2014-07-02 13:08   ` Ian Campbell
  2014-06-13  1:18 ` [PATCH v6 04/13] oxenstored: force FD_CLOEXEC with Unix.set_close_on_exec on LSB init Luis R. Rodriguez
                   ` (11 subsequent siblings)
  14 siblings, 1 reply; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-06-13  1:18 UTC (permalink / raw)
  To: xen-devel
  Cc: David Scott, Stefano Stabellini, Ian Jackson, Luis R. Rodriguez,
	Vincent Hanquez, Ian Campbell

From: "Luis R. Rodriguez" <mcgrof@suse.com>

This adds systemd socket activation support for the Ocaml xenstored.
Ocaml lacks systemd library support so we provide our own C helpers
as is done with other functionality lacking on Ocaml.

Active sockets enables oxenstored to be loaded only if required by a system
onto which Xen is installed on. Socket activation is handled by
systemd, once a port for a service which claims a socket is used
systemd will start the required services for it, on demand. For more
details on socket activation refer to Lennart's socket-activation
post regarding this [0].

An important difference with socket activation is that systemd will set
FD_CLOEXEC for us on the socket before giving it to us, we'll sprinkly
the Unix.set_close_on_exec for LSB init next as a separate commit.

Right now this code adds a no-op for this functionality, leaving the
enablement to be done later once systemd is properly hooked into
the build system. The socket activation is ordered in aligment with
the socket activation order passed on to systemd.

[0] http://0pointer.de/blog/projects/socket-activation2.html

Cc: David Scott <dave.scott@eu.citrix.com>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Vincent Hanquez <Vincent.Hanquez@eu.citrix.com>
Acked-by: Dave Scott <Dave.Scott@citrix.com>
Acked-by: Anil Madhavapeddy <anil@recoil.org>
Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
---
 tools/ocaml/xenstored/Makefile        |   8 +-
 tools/ocaml/xenstored/systemd.ml      |  17 ++++
 tools/ocaml/xenstored/systemd.mli     |  24 ++++++
 tools/ocaml/xenstored/systemd_stubs.c | 158 ++++++++++++++++++++++++++++++++++
 tools/ocaml/xenstored/utils.ml        |  20 +++--
 tools/ocaml/xenstored/xenstored.ml    |   2 +
 6 files changed, 221 insertions(+), 8 deletions(-)
 create mode 100644 tools/ocaml/xenstored/systemd.ml
 create mode 100644 tools/ocaml/xenstored/systemd.mli
 create mode 100644 tools/ocaml/xenstored/systemd_stubs.c

diff --git a/tools/ocaml/xenstored/Makefile b/tools/ocaml/xenstored/Makefile
index 7fa8f53..382a813 100644
--- a/tools/ocaml/xenstored/Makefile
+++ b/tools/ocaml/xenstored/Makefile
@@ -15,6 +15,11 @@ syslog_OBJS = syslog
 syslog_C_OBJS = syslog_stubs
 OCAML_LIBRARY = syslog
 
+LIBS += systemd.cma systemd.cmxa
+systemd_OBJS = systemd
+systemd_C_OBJS = systemd_stubs
+OCAML_LIBRARY += systemd
+
 OBJS = define \
 	stdext \
 	trie \
@@ -36,11 +41,12 @@ OBJS = define \
 	process \
 	xenstored
 
-INTF = symbol.cmi trie.cmi syslog.cmi
+INTF = symbol.cmi trie.cmi syslog.cmi systemd.cmi
 
 XENSTOREDLIBS = \
 	unix.cmxa \
 	-ccopt -L -ccopt . syslog.cmxa \
+	-ccopt -L -ccopt . systemd.cmxa \
 	-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/mmap $(OCAML_TOPLEVEL)/libs/mmap/xenmmap.cmxa \
 	-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/eventchn $(OCAML_TOPLEVEL)/libs/eventchn/xeneventchn.cmxa \
 	-ccopt -L -ccopt $(OCAML_TOPLEVEL)/libs/xc $(OCAML_TOPLEVEL)/libs/xc/xenctrl.cmxa \
diff --git a/tools/ocaml/xenstored/systemd.ml b/tools/ocaml/xenstored/systemd.ml
new file mode 100644
index 0000000..2aa39ea
--- /dev/null
+++ b/tools/ocaml/xenstored/systemd.ml
@@ -0,0 +1,17 @@
+(*
+ * Copyright (C) 2014 Luis R. Rodriguez <mcgrof@suse.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *)
+
+external sd_listen_fds: string -> Unix.file_descr = "ocaml_sd_listen_fds"
+external sd_booted: unit -> bool = "ocaml_sd_booted"
+external sd_notify_ready: unit -> unit = "ocaml_sd_notify_ready"
diff --git a/tools/ocaml/xenstored/systemd.mli b/tools/ocaml/xenstored/systemd.mli
new file mode 100644
index 0000000..85c9f2e
--- /dev/null
+++ b/tools/ocaml/xenstored/systemd.mli
@@ -0,0 +1,24 @@
+(*
+ * Copyright (C) 2014 Luis R. Rodriguez <mcgrof@suse.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *)
+
+(** Calls the C library sd_listen_fds() function for us. Although
+ *  the library doesn't accept argument we send one over to help
+ *  us do sanity checks on the expected sockets *)
+val sd_listen_fds: string -> Unix.file_descr
+
+(** Tells us whether or not systemd support was compiled in *)
+val sd_booted: unit -> bool
+
+(** Tells systemd we're ready *)
+external sd_notify_ready: unit -> unit = "ocaml_sd_notify_ready"
diff --git a/tools/ocaml/xenstored/systemd_stubs.c b/tools/ocaml/xenstored/systemd_stubs.c
new file mode 100644
index 0000000..b49a04b
--- /dev/null
+++ b/tools/ocaml/xenstored/systemd_stubs.c
@@ -0,0 +1,158 @@
+/*
+ * Copyright (C) 2014 Luis R. Rodriguez <mcgrof@suse.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ */
+
+#include <string.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <errno.h>
+#include <caml/mlvalues.h>
+#include <caml/memory.h>
+#include <caml/alloc.h>
+#include <caml/custom.h>
+#include <caml/signals.h>
+#include <caml/fail.h>
+#include <config.h>
+
+#if defined(HAVE_SYSTEMD)
+
+#include <sys/socket.h>
+#include <systemd/sd-daemon.h>
+
+/* Will work regardless of the order systemd gives them to us */
+int oxen_get_sd_fd(const char *connect_to)
+{
+	int fd = SD_LISTEN_FDS_START;
+	int r;
+
+	while (fd <= SD_LISTEN_FDS_START + 1) {
+		r = sd_is_socket_unix(fd, SOCK_STREAM, 1, connect_to, 0);
+		if (r > 0)
+			return fd;
+		fd++;
+	}
+
+	return -EBADR;
+}
+
+static int oxen_verify_socket_socket(const char *connect_to)
+{
+	char sock[30];
+
+	/* We have to null terminate the socket path */
+	memset(sock, '\0', sizeof(sock));
+	memcpy(sock, connect_to, strlen(connect_to));
+
+	if ((strncmp("/var/run/xenstored/socket_ro", sock, 28) != 0) &&
+	    (strncmp("/var/run/xenstored/socket", sock, 25) != 0)) {
+		sd_notifyf(0, "STATUS=unexpected socket: %s\n"
+			   "ERRNO=%i",
+			   connect_to,
+			   EBADR);
+		return -EBADR;
+	}
+
+	return oxen_get_sd_fd(sock);
+}
+
+CAMLprim value ocaml_sd_listen_fds(value connect_to)
+{
+	CAMLparam1(connect_to);
+	CAMLlocal1(sock_ret);
+	int sock = -EBADR, n;
+
+	n = sd_listen_fds(0);
+	if (n <= 0) {
+		sd_notifyf(0, "STATUS=Failed to get any active sockets: %s\n"
+			   "ERRNO=%i",
+			   strerror(errno),
+			   errno);
+		caml_failwith("ocaml_sd_listen_fds() failed to get any sockets");
+	} else if (n > 2) {
+		fprintf(stderr, SD_ERR "Expected 2 fds but given %d\n", n);
+		sd_notifyf(0, "STATUS=Mismatch on number (2): %s\n"
+			   "ERRNO=%d",
+			   strerror(EBADR),
+			   EBADR);
+		caml_failwith("ocaml_sd_listen_fds() mismatch");
+	}
+
+	sock = oxen_verify_socket_socket((const char *) String_val(connect_to));
+	if (sock <= 0) {
+		fprintf(stderr, "failed to verify sock %s\n",
+			(const char *) String_val(connect_to));
+		caml_failwith("ocaml_sd_listen_fds_init() invalid socket");
+	}
+
+	sock_ret = Val_int(sock);
+
+	CAMLreturn(sock_ret);
+}
+
+CAMLprim value ocaml_sd_booted(value ignore)
+{
+	CAMLparam1(ignore);
+	CAMLlocal1(ret);
+
+	ret = Val_false;
+
+	if (sd_booted())
+		ret = Val_true;
+
+	CAMLreturn(ret);
+}
+
+CAMLprim value ocaml_sd_notify_ready(value ignore)
+{
+	CAMLparam1(ignore);
+	CAMLlocal1(ret);
+
+	ret = Val_int(0);
+
+	sd_notify(1, "READY=1");
+
+	CAMLreturn(ret);
+}
+
+#else
+
+CAMLprim value ocaml_sd_listen_fds(value connect_to)
+{
+	CAMLparam1(connect_to);
+	CAMLlocal1(sock_ret);
+
+	sock_ret = Val_int(-1);
+
+	CAMLreturn(sock_ret);
+}
+
+CAMLprim value ocaml_sd_booted(value ignore)
+{
+	CAMLparam1(ignore);
+	CAMLlocal1(ret);
+
+	ret = Val_false;
+
+	CAMLreturn(ret);
+}
+
+CAMLprim value ocaml_sd_notify_ready(value ignore)
+{
+	CAMLparam1(ignore);
+	CAMLlocal1(ret);
+
+	ret = Val_int(-1);
+
+	CAMLreturn(ret);
+}
+#endif
diff --git a/tools/ocaml/xenstored/utils.ml b/tools/ocaml/xenstored/utils.ml
index 68b70c5..0cfeded 100644
--- a/tools/ocaml/xenstored/utils.ml
+++ b/tools/ocaml/xenstored/utils.ml
@@ -73,14 +73,20 @@ let trim_path path =
 let join_by_null ls = String.concat "\000" ls
 
 (* unix utils *)
+let create_regular_unix_socket name =
+        Unixext.unlink_safe name;
+        Unixext.mkdir_rec (Filename.dirname name) 0o700;
+        let sockaddr = Unix.ADDR_UNIX(name) in
+        let sock = Unix.socket Unix.PF_UNIX Unix.SOCK_STREAM 0 in
+        Unix.bind sock sockaddr;
+        Unix.listen sock 1;
+        sock
+
 let create_unix_socket name =
-	Unixext.unlink_safe name;
-	Unixext.mkdir_rec (Filename.dirname name) 0o700;
-	let sockaddr = Unix.ADDR_UNIX(name) in
-	let sock = Unix.socket Unix.PF_UNIX Unix.SOCK_STREAM 0 in
-	Unix.bind sock sockaddr;
-	Unix.listen sock 1;
-	sock
+        if Systemd.sd_booted() then
+                Systemd.sd_listen_fds name
+        else
+                create_regular_unix_socket name
 
 let read_file_single_integer filename =
 	let fd = Unix.openfile filename [ Unix.O_RDONLY ] 0o640 in
diff --git a/tools/ocaml/xenstored/xenstored.ml b/tools/ocaml/xenstored/xenstored.ml
index 438ecb9..1c02f2f 100644
--- a/tools/ocaml/xenstored/xenstored.ml
+++ b/tools/ocaml/xenstored/xenstored.ml
@@ -383,6 +383,8 @@ let _ =
 	while not !quit
 	do
 		try
+                        if Systemd.sd_booted() then
+                                Systemd.sd_notify_ready ();
 			main_loop ()
 		with exc ->
 			error "caught exception %s" (Printexc.to_string exc);
-- 
2.0.0.rc3.18.g00a5b79

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

* [PATCH v6 04/13] oxenstored: force FD_CLOEXEC with Unix.set_close_on_exec on LSB init
  2014-06-13  1:18 [PATCH v6 00/13] xen: add systemd support Luis R. Rodriguez
                   ` (2 preceding siblings ...)
  2014-06-13  1:18 ` [PATCH v6 03/13] oxenstored: " Luis R. Rodriguez
@ 2014-06-13  1:18 ` Luis R. Rodriguez
  2014-07-02 13:08   ` Ian Campbell
  2014-06-13  1:18 ` [PATCH v6 05/13] tools/xendomains: make xl the default and remove xm usage Luis R. Rodriguez
                   ` (10 subsequent siblings)
  14 siblings, 1 reply; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-06-13  1:18 UTC (permalink / raw)
  To: xen-devel
  Cc: David Scott, Stefano Stabellini, Vincent Hanquez,
	Luis R. Rodriguez, Anil Madhavapeddy, Ian Jackson, Ian Campbell

From: "Luis R. Rodriguez" <mcgrof@suse.com>

Lets match the systemd active socket activation implementation and
ensure that FD_CLOEXEC is set by usin Unix.set_close_on_exec. David
notes oxenstored likely does not exec but there is no harm in being
careful just in case things change in the future.

Cc: David Scott <dave.scott@eu.citrix.com>
Cc: Anil Madhavapeddy <anil@recoil.org>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Vincent Hanquez <Vincent.Hanquez@eu.citrix.com>
Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
---
 tools/ocaml/xenstored/utils.ml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/ocaml/xenstored/utils.ml b/tools/ocaml/xenstored/utils.ml
index 0cfeded..61321c6 100644
--- a/tools/ocaml/xenstored/utils.ml
+++ b/tools/ocaml/xenstored/utils.ml
@@ -78,6 +78,7 @@ let create_regular_unix_socket name =
         Unixext.mkdir_rec (Filename.dirname name) 0o700;
         let sockaddr = Unix.ADDR_UNIX(name) in
         let sock = Unix.socket Unix.PF_UNIX Unix.SOCK_STREAM 0 in
+        Unix.set_close_on_exec sock;
         Unix.bind sock sockaddr;
         Unix.listen sock 1;
         sock
-- 
2.0.0.rc3.18.g00a5b79

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

* [PATCH v6 05/13] tools/xendomains: make xl the default and remove xm usage
  2014-06-13  1:18 [PATCH v6 00/13] xen: add systemd support Luis R. Rodriguez
                   ` (3 preceding siblings ...)
  2014-06-13  1:18 ` [PATCH v6 04/13] oxenstored: force FD_CLOEXEC with Unix.set_close_on_exec on LSB init Luis R. Rodriguez
@ 2014-06-13  1:18 ` Luis R. Rodriguez
  2014-06-13  1:18 ` [PATCH v6 06/13] tools/xendomains: do space cleanups Luis R. Rodriguez
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-06-13  1:18 UTC (permalink / raw)
  To: xen-devel
  Cc: Ian Campbell, Stefano Stabellini, Luis R. Rodriguez,
	Jan Rękorajski, Ian Jackson, Jacek Konieczny, M A Young

From: "Luis R. Rodriguez" <mcgrof@suse.com>

xm is gone so make xl the default and remove xm stuff.

Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Jan Rękorajski <baggins@pld-linux.org>
Cc: M A Young <m.a.young@durham.ac.uk>
Cc: Jacek Konieczny <jajcus@jajcus.net>
Cc: xen-devel@lists.xenproject.org
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
---
 tools/hotplug/Linux/init.d/xendomains | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/tools/hotplug/Linux/init.d/xendomains b/tools/hotplug/Linux/init.d/xendomains
index 59f1e3d..f68fd2b 100644
--- a/tools/hotplug/Linux/init.d/xendomains
+++ b/tools/hotplug/Linux/init.d/xendomains
@@ -29,13 +29,12 @@
 
 . /etc/xen/scripts/hotplugpath.sh
 
-CMD=${SBINDIR}/xm
-HEADCOMP="LinuxGuestRecord"
+CMD=${SBINDIR}/xl
+HEADCOMP="Xen saved domain"
 $CMD list &> /dev/null
 if test $? -ne 0
 then
-	CMD=${SBINDIR}/xl
-	HEADCOMP="Xen saved domain"
+	exit $?
 fi
 
 $CMD list &> /dev/null
-- 
2.0.0.rc3.18.g00a5b79


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

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

* [PATCH v6 06/13] tools/xendomains: do space cleanups
  2014-06-13  1:18 [PATCH v6 00/13] xen: add systemd support Luis R. Rodriguez
                   ` (4 preceding siblings ...)
  2014-06-13  1:18 ` [PATCH v6 05/13] tools/xendomains: make xl the default and remove xm usage Luis R. Rodriguez
@ 2014-06-13  1:18 ` Luis R. Rodriguez
  2014-06-13  1:18 ` [PATCH v6 07/13] tools/xendomains: move to libexec and use a smaller init helper Luis R. Rodriguez
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-06-13  1:18 UTC (permalink / raw)
  To: xen-devel
  Cc: Ian Campbell, Stefano Stabellini, Luis R. Rodriguez,
	Jan Rękorajski, Ian Jackson, Jacek Konieczny, M A Young

From: "Luis R. Rodriguez" <mcgrof@suse.com>

This has no functional changes. This is just to prepare the file
to be moved, so you won't blind your eyes or get git am to complain.

Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Jan Rękorajski <baggins@pld-linux.org>
Cc: M A Young <m.a.young@durham.ac.uk>
Cc: Jacek Konieczny <jajcus@jajcus.net>
Cc: xen-devel@lists.xenproject.org
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
---
 tools/hotplug/Linux/init.d/xendomains | 62 +++++++++++++++++------------------
 1 file changed, 31 insertions(+), 31 deletions(-)

diff --git a/tools/hotplug/Linux/init.d/xendomains b/tools/hotplug/Linux/init.d/xendomains
index f68fd2b..cad92da 100644
--- a/tools/hotplug/Linux/init.d/xendomains
+++ b/tools/hotplug/Linux/init.d/xendomains
@@ -23,7 +23,7 @@
 # Default-Start:     2 3 5
 # Default-Stop:      0 1 6
 # Short-Description: Start/stop secondary xen domains
-# Description:       Start / stop domains automatically when domain 0 
+# Description:       Start / stop domains automatically when domain 0
 #                    boots / shuts down.
 ### END INIT INFO
 
@@ -43,7 +43,7 @@ then
 	exit 0;
 fi
 
-# Correct exit code would probably be 5, but it's enough 
+# Correct exit code would probably be 5, but it's enough
 # if xend complains if we're not running as privileged domain
 if ! [ -e /proc/xen/privcmd ]; then
 	exit 0
@@ -73,7 +73,7 @@ test -r $XENDOM_CONFIG || { echo "$XENDOM_CONFIG not existing";
 if test -e /etc/rc.status; then
     # SUSE rc script library
     . /etc/rc.status
-else    
+else
     _cmd=$1
     declare -a _SMSG
     if test "${_cmd}" = "status"; then
@@ -96,7 +96,7 @@ else
 	    fi
 	}
     elif test -e /lib/lsb/init-functions; then
-	# LSB    
+	# LSB
     	. /lib/lsb/init-functions
         if alias log_success_msg >/dev/null 2>/dev/null; then
 	  echo_rc()
@@ -113,7 +113,7 @@ else
 	    fi
 	  }
         fi
-    else    
+    else
 	# emulate it
 	echo_rc()
 	{
@@ -123,17 +123,17 @@ else
     rc_reset() { _RC_RV=0; }
     rc_failed()
     {
-	if test -z "$1"; then 
+	if test -z "$1"; then
 	    _RC_RV=1;
-	elif test "$1" != "0"; then 
-	    _RC_RV=$1; 
-    	fi
+	elif test "$1" != "0"; then
+	    _RC_RV=$1;
+	fi
 	return ${_RC_RV}
     }
     rc_check()
     {
 	return rc_failed $?
-    }	
+    }
     rc_status()
     {
 	rc_failed $?
@@ -145,7 +145,7 @@ else
 	return ${_RC_RV}
     }
     rc_exit() { exit ${_RC_RV}; }
-    rc_active() 
+    rc_active()
     {
 	if test -z "$RUNLEVEL"; then read RUNLEVEL REST < <(/sbin/runlevel); fi
 	if test -e /etc/init.d/S[0-9][0-9]${1}; then return 0; fi
@@ -192,13 +192,13 @@ rdnames()
 {
     NAMES=
     if ! contains_something "$XENDOMAINS_AUTO"
-    then 
+    then
 	return
     fi
     for dom in $XENDOMAINS_AUTO/*; do
 	rdname $dom
-	if test -z $NAMES; then 
-	    NAMES=$NM; 
+	if test -z $NAMES; then
+	    NAMES=$NM;
 	else
 	    NAMES="$NAMES|$NM"
 	fi
@@ -231,7 +231,7 @@ is_running()
     while read LN; do
 	parseln "$LN" || continue
 	if test $id = 0; then continue; fi
-	case $name in 
+	case $name in
 	    ($NM)
 		RC=0
 		;;
@@ -240,11 +240,11 @@ is_running()
     return $RC
 }
 
-start() 
+start()
 {
-    if [ -f $LOCKFILE ]; then 
+    if [ -f $LOCKFILE ]; then
 	echo -e "xendomains already running (lockfile exists)"
-	return; 
+	return;
     fi
 
     saved_domains=" "
@@ -284,10 +284,10 @@ start()
 	# XENDOMAINS_AUTO - they could just be symlinks to files elsewhere
 
 	# Create all domains with config files in XENDOMAINS_AUTO.
-	# TODO: We should record which domain name belongs 
+	# TODO: We should record which domain name belongs
 	# so we have the option to selectively shut down / migrate later
 	# If a domain statefile from $XENDOMAINS_SAVE matches a domain name
-	# in $XENDOMAINS_AUTO, do not try to start that domain; if it didn't 
+	# in $XENDOMAINS_AUTO, do not try to start that domain; if it didn't
 	# restore correctly it requires administrative attention.
 	for dom in $XENDOMAINS_AUTO/*; do
 	    echo -n " ${dom##*/}"
@@ -348,14 +348,14 @@ watchdog_xencmd()
     read PSF PSUID PSPID PSPPID < <(echo "$PSAX")
     # kill $CMD $1
     kill $PSPID >/dev/null 2>&1
-    
+
     echo -e .
 }
 
 stop()
 {
     exec 3>&2 2> /dev/null
-    
+
     # Collect list of domains to shut down
     if test "$XENDOMAINS_AUTO_ONLY" = "true"; then
 	rdnames
@@ -379,7 +379,7 @@ stop()
 	    esac
 	    "
 	fi
-	# XENDOMAINS_SYSRQ chould be something like just "s" 
+	# XENDOMAINS_SYSRQ chould be something like just "s"
 	# or "s e i u" or even "s e s i u o"
 	# for the latter, you should set XENDOMAINS_USLEEP to 1200000 or so
 	if test -n "$XENDOMAINS_SYSRQ"; then
@@ -412,7 +412,7 @@ stop()
 		kill $WDOG_PID >/dev/null 2>&1
 	    else
 		kill $WDOG_PID >/dev/null 2>&1
-		
+
 		echo -e .
 		usleep 1000
 		continue
@@ -471,7 +471,7 @@ stop()
 
     # Unconditionally delete lock file
     rm -f $LOCKFILE
-    
+
     exec 2>&3
 }
 
@@ -481,7 +481,7 @@ check_domain_up()
     while read LN; do
 	parseln "$LN" || continue
 	if test $id = 0; then continue; fi
-	case $name in 
+	case $name in
 	    ($1)
 		return 0
 		;;
@@ -500,9 +500,9 @@ check_all_auto_domains_up()
     for nm in $XENDOMAINS_AUTO/*; do
 	rdname $nm
 	found=0
-	if check_domain_up "$NM"; then 
+	if check_domain_up "$NM"; then
 	    echo -n " $name"
-	else 
+	else
 	    missing="$missing $NM"
 	fi
     done
@@ -515,7 +515,7 @@ check_all_auto_domains_up()
 
 check_all_saved_domains_up()
 {
-    if ! contains_something "$XENDOMAINS_SAVE" 
+    if ! contains_something "$XENDOMAINS_SAVE"
     then
       return 0
     fi
@@ -562,8 +562,8 @@ case "$1" in
 	;;
 
     status)
-	echo -n "Checking for xendomains:" 
-	if test ! -f $LOCKFILE; then 
+	echo -n "Checking for xendomains:"
+	if test ! -f $LOCKFILE; then
 	    rc_failed 3
 	else
 	    check_all_auto_domains_up
-- 
2.0.0.rc3.18.g00a5b79


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

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

* [PATCH v6 07/13] tools/xendomains: move to libexec and use a smaller init helper
  2014-06-13  1:18 [PATCH v6 00/13] xen: add systemd support Luis R. Rodriguez
                   ` (5 preceding siblings ...)
  2014-06-13  1:18 ` [PATCH v6 06/13] tools/xendomains: do space cleanups Luis R. Rodriguez
@ 2014-06-13  1:18 ` Luis R. Rodriguez
  2014-06-13  7:06   ` Jacek Konieczny
  2014-07-02 13:12   ` Ian Campbell
  2014-06-13  1:18 ` [PATCH v6 08/13] autoconf: xen: force a refresh with autoconf Luis R. Rodriguez
                   ` (7 subsequent siblings)
  14 siblings, 2 replies; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-06-13  1:18 UTC (permalink / raw)
  To: xen-devel
  Cc: Ian Campbell, Stefano Stabellini, Luis R. Rodriguez,
	Jan Rękorajski, Ian Jackson, Jacek Konieczny, M A Young

From: "Luis R. Rodriguez" <mcgrof@suse.com>

The xendomains script can be reused with systemd systems as it
does not control services or sockets per se, but does a one shot
scrape of domUs it needs start bring up, stop, reload so we're
going to reuse it. This moves the core of the script to libexec
and leaves only a helper on init.

Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Jan Rękorajski <baggins@pld-linux.org>
Cc: M A Young <m.a.young@durham.ac.uk>
Cc: Jacek Konieczny <jajcus@jajcus.net>
Cc: xen-devel@lists.xenproject.org
Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
---
 tools/hotplug/Linux/Makefile          |   3 +
 tools/hotplug/Linux/init.d/xendomains | 566 +-------------------------------
 tools/hotplug/Linux/xendomains        | 584 ++++++++++++++++++++++++++++++++++
 3 files changed, 603 insertions(+), 550 deletions(-)
 create mode 100644 tools/hotplug/Linux/xendomains

diff --git a/tools/hotplug/Linux/Makefile b/tools/hotplug/Linux/Makefile
index 4874ec5..d5de9e6 100644
--- a/tools/hotplug/Linux/Makefile
+++ b/tools/hotplug/Linux/Makefile
@@ -3,6 +3,7 @@ include $(XEN_ROOT)/tools/Rules.mk
 
 # Init scripts.
 XENDOMAINS_INITD = init.d/xendomains
+XENDOMAINS_LIBEXEC = xendomains
 XENDOMAINS_SYSCONFIG = init.d/sysconfig.xendomains
 
 XENCOMMONS_INITD = init.d/xencommons
@@ -45,6 +46,8 @@ install: all install-initd install-scripts install-udev
 install-initd:
 	[ -d $(DESTDIR)$(INITD_DIR) ] || $(INSTALL_DIR) $(DESTDIR)$(INITD_DIR)
 	[ -d $(DESTDIR)$(SYSCONFIG_DIR) ] || $(INSTALL_DIR) $(DESTDIR)$(SYSCONFIG_DIR)
+	[ -d $(DESTDIR)$(LIBEXEC) ] || $(INSTALL_DIR) $(DESTDIR)$(LIBEXEC)
+	$(INSTALL_PROG) $(XENDOMAINS_LIBEXEC) $(DESTDIR)$(LIBEXEC)
 	$(INSTALL_PROG) $(XENDOMAINS_INITD) $(DESTDIR)$(INITD_DIR)
 	$(INSTALL_DATA) $(XENDOMAINS_SYSCONFIG) $(DESTDIR)$(SYSCONFIG_DIR)/xendomains
 	$(INSTALL_PROG) $(XENCOMMONS_INITD) $(DESTDIR)$(INITD_DIR)
diff --git a/tools/hotplug/Linux/init.d/xendomains b/tools/hotplug/Linux/init.d/xendomains
index cad92da..d0122fc 100644
--- a/tools/hotplug/Linux/init.d/xendomains
+++ b/tools/hotplug/Linux/init.d/xendomains
@@ -1,18 +1,13 @@
 #!/bin/bash
 #
 # /etc/init.d/xendomains
-# Start / stop domains automatically when domain 0 boots / shuts down.
+# Wrapper to start / stop domains automatically when domain 0 boots / shuts down
 #
 # chkconfig: 345 99 00
-# description: Start / stop Xen domains.
+# description: Helper to start / stop Xen domains.
 #
-# This script offers fairly basic functionality.  It should work on Redhat
-# but also on LSB-compliant SuSE releases and on Debian with the LSB package
-# installed.  (LSB is the Linux Standard Base)
-#
-# Based on the example in the "Designing High Quality Integrated Linux
-# Applications HOWTO" by Avi Alkalay
-# <http://www.tldp.org/HOWTO/HighQuality-Apps-HOWTO/>
+# This script is a wrapper init helper for the real workload horse script.
+# It should work on LSB-compliant systems.
 #
 ### BEGIN INIT INFO
 # Provides:          xendomains
@@ -22,563 +17,34 @@
 # Should-Stop:       xend
 # Default-Start:     2 3 5
 # Default-Stop:      0 1 6
-# Short-Description: Start/stop secondary xen domains
-# Description:       Start / stop domains automatically when domain 0
-#                    boots / shuts down.
+# Short-Description: Wrapper to start/stop secondary xen domains
+# Description:       Wrapper for starting / stopping domains automatically
+#                    when domain 0 boots / shuts down on systems using init.
+#                    The $SBINDIR/xendomains helper is shared between init and
+#                    systemd systems.
 ### END INIT INFO
 
 . /etc/xen/scripts/hotplugpath.sh
 
-CMD=${SBINDIR}/xl
-HEADCOMP="Xen saved domain"
-$CMD list &> /dev/null
-if test $? -ne 0
-then
-	exit $?
-fi
-
-$CMD list &> /dev/null
-if test $? -ne 0
-then
-	exit 0;
-fi
-
-# Correct exit code would probably be 5, but it's enough
-# if xend complains if we're not running as privileged domain
-if ! [ -e /proc/xen/privcmd ]; then
-	exit 0
-fi
-
-# See docs/misc/distro_mapping.txt
-if [ -d /var/lock/subsys ]; then
-	LOCKFILE=/var/lock/subsys/xendomains
-else
-	LOCKFILE=/var/lock/xendomains
-fi
-
-if [ -d /etc/sysconfig ]; then
-	XENDOM_CONFIG=/etc/sysconfig/xendomains
-else
-	XENDOM_CONFIG=/etc/default/xendomains
-fi
-
-test -r $XENDOM_CONFIG || { echo "$XENDOM_CONFIG not existing";
-	if [ "$1" = "stop" ]; then exit 0;
-	else exit 6; fi; }
-
-. $XENDOM_CONFIG
-
-# Use the SUSE rc_ init script functions;
-# emulate them on LSB, RH and other systems
-if test -e /etc/rc.status; then
-    # SUSE rc script library
-    . /etc/rc.status
-else
-    _cmd=$1
-    declare -a _SMSG
-    if test "${_cmd}" = "status"; then
-	_SMSG=(running dead dead unused unknown)
-	_RC_UNUSED=3
-    else
-	_SMSG=(done failed failed missed failed skipped unused failed failed)
-	_RC_UNUSED=6
-    fi
-    if test -e /etc/init.d/functions; then
-	# REDHAT
-	. /etc/init.d/functions
-	echo_rc()
-	{
-	    #echo -n "  [${_SMSG[${_RC_RV}]}] "
-	    if test ${_RC_RV} = 0; then
-		success "  [${_SMSG[${_RC_RV}]}] "
-	    else
-		failure "  [${_SMSG[${_RC_RV}]}] "
-	    fi
-	}
-    elif test -e /lib/lsb/init-functions; then
-	# LSB
-    	. /lib/lsb/init-functions
-        if alias log_success_msg >/dev/null 2>/dev/null; then
-	  echo_rc()
-	  {
-	       echo "  [${_SMSG[${_RC_RV}]}] "
-	  }
-        else
-	  echo_rc()
-	  {
-	    if test ${_RC_RV} = 0; then
-		log_success_msg "  [${_SMSG[${_RC_RV}]}] "
-	    else
-		log_failure_msg "  [${_SMSG[${_RC_RV}]}] "
-	    fi
-	  }
-        fi
-    else
-	# emulate it
-	echo_rc()
-	{
-	    echo "  [${_SMSG[${_RC_RV}]}] "
-	}
-    fi
-    rc_reset() { _RC_RV=0; }
-    rc_failed()
-    {
-	if test -z "$1"; then
-	    _RC_RV=1;
-	elif test "$1" != "0"; then
-	    _RC_RV=$1;
-	fi
-	return ${_RC_RV}
-    }
-    rc_check()
-    {
-	return rc_failed $?
-    }
-    rc_status()
-    {
-	rc_failed $?
-	if test "$1" = "-r"; then _RC_RV=0; shift; fi
-	if test "$1" = "-s"; then rc_failed 5; echo_rc; rc_failed 3; shift; fi
-	if test "$1" = "-u"; then rc_failed ${_RC_UNUSED}; echo_rc; rc_failed 3; shift; fi
-	if test "$1" = "-v"; then echo_rc; shift; fi
-	if test "$1" = "-r"; then _RC_RV=0; shift; fi
-	return ${_RC_RV}
-    }
-    rc_exit() { exit ${_RC_RV}; }
-    rc_active()
-    {
-	if test -z "$RUNLEVEL"; then read RUNLEVEL REST < <(/sbin/runlevel); fi
-	if test -e /etc/init.d/S[0-9][0-9]${1}; then return 0; fi
-	return 1
-    }
-fi
-
-if ! which usleep >&/dev/null
-then
-  usleep()
-  {
-    if [ -n "$1" ]
-    then
-      sleep $(( $1 / 1000000 ))
-    fi
-  }
-fi
-
-# Reset status of this service
-rc_reset
-
-##
-# Returns 0 (success) if the given parameter names a directory, and that
-# directory is not empty.
-#
-contains_something()
-{
-  if [ -d "$1" ] && [ `/bin/ls $1 | wc -l` -gt 0 ]
-  then
-    return 0
-  else
-    return 1
-  fi
-}
-
-# read name from xen config file
-rdname()
-{
-    NM=$($CMD create --quiet --dryrun --defconfig "$1" |
-         sed -n 's/^.*(name \(.*\))$/\1/p;s/^.*"name": "\(.*\)",$/\1/p')
-}
-
-rdnames()
-{
-    NAMES=
-    if ! contains_something "$XENDOMAINS_AUTO"
-    then
-	return
-    fi
-    for dom in $XENDOMAINS_AUTO/*; do
-	rdname $dom
-	if test -z $NAMES; then
-	    NAMES=$NM;
-	else
-	    NAMES="$NAMES|$NM"
-	fi
-    done
-}
-
-LIST_GREP='(domain\|(domid\|(name\|^    {$\|"name":\|"domid":'
-parseln()
-{
-    if [[ "$1" =~ '(domain' ]] || [[ "$1" = "{" ]]; then
-        name=;id=
-    elif [[ "$1" =~ '(name' ]]; then
-        name=$(echo $1 | sed -e 's/^.*(name \(.*\))$/\1/')
-    elif [[ "$1" =~ '(domid' ]]; then
-        id=$(echo $1 | sed -e 's/^.*(domid \(.*\))$/\1/')
-    elif [[ "$1" =~ '"name":' ]]; then
-        name=$(echo $1 | sed -e 's/^.*"name": "\(.*\)",$/\1/')
-    elif [[ "$1" =~ '"domid":' ]]; then
-        id=$(echo $1 | sed -e 's/^.*"domid": \(.*\),$/\1/')
-    fi
-
-    [ -n "$name" -a -n "$id" ] && return 0 || return 1
-}
-
-is_running()
-{
-    rdname $1
-    RC=1
-    name=;id=
-    while read LN; do
-	parseln "$LN" || continue
-	if test $id = 0; then continue; fi
-	case $name in
-	    ($NM)
-		RC=0
-		;;
-	esac
-    done < <($CMD list -l | grep "$LIST_GREP")
-    return $RC
-}
-
-start()
-{
-    if [ -f $LOCKFILE ]; then
-	echo -e "xendomains already running (lockfile exists)"
-	return;
-    fi
-
-    saved_domains=" "
-    if [ "$XENDOMAINS_RESTORE" = "true" ] &&
-       contains_something "$XENDOMAINS_SAVE"
-    then
-	mkdir -p $(dirname "$LOCKFILE")
-	touch $LOCKFILE
-	echo -n "Restoring Xen domains:"
-	saved_domains=`ls $XENDOMAINS_SAVE`
-        for dom in $XENDOMAINS_SAVE/*; do
-            if [ -f $dom ] ; then
-                HEADER=`head -c 16 $dom | head -n 1 2> /dev/null`
-                if [ "$HEADER" = "$HEADCOMP" ]; then
-                    echo -n " ${dom##*/}"
-                    XMR=`$CMD restore $dom 2>&1 1>/dev/null`
-                    #$CMD restore $dom
-                    if [ $? -ne 0 ]; then
-                        echo -e "\nAn error occurred while restoring domain ${dom##*/}:\n$XMR"
-                        rc_failed $?
-                        echo -e '!'
-                    else
-                        # mv $dom ${dom%/*}/.${dom##*/}
-                        rm $dom
-                    fi
-                fi
-            fi
-        done
-	echo -e
-    fi
-
-    if contains_something "$XENDOMAINS_AUTO"
-    then
-	touch $LOCKFILE
-	echo -n "Starting auto Xen domains:"
-	# We expect config scripts for auto starting domains to be in
-	# XENDOMAINS_AUTO - they could just be symlinks to files elsewhere
-
-	# Create all domains with config files in XENDOMAINS_AUTO.
-	# TODO: We should record which domain name belongs
-	# so we have the option to selectively shut down / migrate later
-	# If a domain statefile from $XENDOMAINS_SAVE matches a domain name
-	# in $XENDOMAINS_AUTO, do not try to start that domain; if it didn't
-	# restore correctly it requires administrative attention.
-	for dom in $XENDOMAINS_AUTO/*; do
-	    echo -n " ${dom##*/}"
-	    shortdom=$(echo $dom | sed -n 's/^.*\/\(.*\)$/\1/p')
-	    echo $saved_domains | grep -w $shortdom > /dev/null
-	    if [ $? -eq 0 ] || is_running $dom; then
-		echo -n "(skip)"
-	    else
-		XMC=`$CMD create --quiet --defconfig $dom`
-		if [ $? -ne 0 ]; then
-		    echo -e "\nAn error occurred while creating domain ${dom##*/}: $XMC\n"
-		    rc_failed $?
-		    echo -e '!'
-		else
-		    usleep $XENDOMAINS_CREATE_USLEEP
-		fi
-	    fi
-	done
-    fi
-}
-
-all_zombies()
-{
-    name=;id=
-    while read LN; do
-	parseln "$LN" || continue
-	if test $id = 0; then continue; fi
-	if test "$state" != "-b---d" -a "$state" != "-----d"; then
-	    return 1;
-	fi
-    done < <($CMD list -l | grep "$LIST_GREP")
-    return 0
-}
-
-# Wait for max $XENDOMAINS_STOP_MAXWAIT for $CMD $1 to finish;
-# if it has not exited by that time kill it, so the init script will
-# succeed within a finite amount of time; if $2 is nonnull, it will
-# kill the command as well as soon as no domain (except for zombies)
-# are left (used for shutdown --all). Third parameter, if any, suppresses
-# output of dots per working state (formatting issues)
-watchdog_xencmd()
-{
-    if test -z "$XENDOMAINS_STOP_MAXWAIT" -o "$XENDOMAINS_STOP_MAXWAIT" = "0"; then
-	exit
-    fi
-
-    usleep 20000
-    for no in `seq 0 $XENDOMAINS_STOP_MAXWAIT`; do
-	# exit if $CMD save/migrate/shutdown is finished
-	PSAX=`ps axlw | grep "$CMD $1" | grep -v grep`
-	if test -z "$PSAX"; then exit; fi
-	if ! test -n "$3"; then echo -n '.'; fi
-	sleep 1
-	# go to kill immediately if there's only zombies left
-	if all_zombies && test -n "$2"; then break; fi
-    done
-    sleep 1
-    read PSF PSUID PSPID PSPPID < <(echo "$PSAX")
-    # kill $CMD $1
-    kill $PSPID >/dev/null 2>&1
-
-    echo -e .
-}
-
-stop()
-{
-    exec 3>&2 2> /dev/null
-
-    # Collect list of domains to shut down
-    if test "$XENDOMAINS_AUTO_ONLY" = "true"; then
-	rdnames
-    fi
-    echo -n "Shutting down Xen domains:"
-    name=;id=
-    while read LN; do
-	parseln "$LN" || continue
-	if test $id = 0; then continue; fi
-	echo -n " $name"
-	if test "$XENDOMAINS_AUTO_ONLY" = "true"; then
-	    eval "
-	    case \"\$name\" in
-		($NAMES)
-		    # nothing
-		    ;;
-		(*)
-		    echo -e '(skip)'
-		    continue
-		    ;;
-	    esac
-	    "
-	fi
-	# XENDOMAINS_SYSRQ chould be something like just "s"
-	# or "s e i u" or even "s e s i u o"
-	# for the latter, you should set XENDOMAINS_USLEEP to 1200000 or so
-	if test -n "$XENDOMAINS_SYSRQ"; then
-	    for sysrq in $XENDOMAINS_SYSRQ; do
-		echo -n "(SR-$sysrq)"
-		XMR=`$CMD sysrq $id $sysrq 2>&1 1>/dev/null`
-		if test $? -ne 0; then
-		    echo -e "\nAn error occurred while doing sysrq on domain:\n$XMR\n"
-		    rc_failed $?
-		    echo -n '!'
-		fi
-		# usleep just ignores empty arg
-		usleep $XENDOMAINS_USLEEP
-	    done
-	fi
-	if test "$state" = "-b---d" -o "$state" = "-----d"; then
-	    echo -n "(zomb)"
-	    continue
-	fi
-	if test -n "$XENDOMAINS_MIGRATE"; then
-	    echo -n "(migr)"
-	    watchdog_xencmd migrate &
-	    WDOG_PID=$!
-	    XMR=`$CMD migrate $id $XENDOMAINS_MIGRATE 2>&1 1>/dev/null`
-	    if test $? -ne 0; then
-		echo -e "\nAn error occurred while migrating domain:\n$XMR\n"
-		rc_failed $?
-		echo -e '!'
-
-		kill $WDOG_PID >/dev/null 2>&1
-	    else
-		kill $WDOG_PID >/dev/null 2>&1
-
-		echo -e .
-		usleep 1000
-		continue
-	    fi
-	fi
-	if test -n "$XENDOMAINS_SAVE"; then
-	    echo -n "(save)"
-	    watchdog_xencmd save &
-	    WDOG_PID=$!
-	    mkdir -p "$XENDOMAINS_SAVE"
-	    XMR=`$CMD save $id $XENDOMAINS_SAVE/$name 2>&1 1>/dev/null`
-	    if test $? -ne 0; then
-		echo -e "\nAn error occurred while saving domain:\n$XMR\n"
-		rc_failed $?
-		echo -e '!'
-		kill $WDOG_PID >/dev/null 2>&1
-	    else
-		kill $WDOG_PID >/dev/null 2>&1
-		echo -e .
-		usleep 1000
-		continue
-	    fi
-	fi
-	if test -n "$XENDOMAINS_SHUTDOWN"; then
-	    # XENDOMAINS_SHUTDOWN should be "--wait"
-	    echo -n "(shut)"
-	    watchdog_xencmd shutdown &
-	    WDOG_PID=$!
-	    XMR=`$CMD shutdown $XENDOMAINS_SHUTDOWN $id 2>&1 1>/dev/null`
-	    if test $? -ne 0; then
-		echo -e "\nAn error occurred while shutting down domain:\n$XMR\n"
-		rc_failed $?
-		echo -e '!'
-	    fi
-	    kill $WDOG_PID >/dev/null 2>&1
-	fi
-    done < <($CMD list -l | grep "$LIST_GREP")
-
-    # NB. this shuts down ALL Xen domains (politely), not just the ones in
-    # AUTODIR/*
-    # This is because it's easier to do ;-) but arguably if this script is run
-    # on system shutdown then it's also the right thing to do.
-    if ! all_zombies && test -n "$XENDOMAINS_SHUTDOWN_ALL"; then
-	# XENDOMAINS_SHUTDOWN_ALL should be "--all --wait"
-	echo -n " SHUTDOWN_ALL "
-	watchdog_xencmd shutdown 1 false &
-	WDOG_PID=$!
-	XMR=`$CMD shutdown $XENDOMAINS_SHUTDOWN_ALL 2>&1 1>/dev/null`
-	if test $? -ne 0; then
-	    echo -e "\nAn error occurred while shutting down all domains: $XMR\n"
-	    rc_failed $?
-	    echo -e '!'
-	fi
-	kill $WDOG_PID >/dev/null 2>&1
-    fi
-
-    # Unconditionally delete lock file
-    rm -f $LOCKFILE
-
-    exec 2>&3
-}
-
-check_domain_up()
-{
-    name=;id=
-    while read LN; do
-	parseln "$LN" || continue
-	if test $id = 0; then continue; fi
-	case $name in
-	    ($1)
-		return 0
-		;;
-	esac
-    done < <($CMD list -l | grep "$LIST_GREP")
-    return 1
-}
-
-check_all_auto_domains_up()
-{
-    if ! contains_something "$XENDOMAINS_AUTO"
-    then
-      return 0
-    fi
-    missing=
-    for nm in $XENDOMAINS_AUTO/*; do
-	rdname $nm
-	found=0
-	if check_domain_up "$NM"; then
-	    echo -n " $name"
-	else
-	    missing="$missing $NM"
-	fi
-    done
-    if test -n "$missing"; then
-	echo -n " MISS AUTO:$missing"
-	return 1
-    fi
-    return 0
-}
-
-check_all_saved_domains_up()
-{
-    if ! contains_something "$XENDOMAINS_SAVE"
-    then
-      return 0
-    fi
-    missing=`/bin/ls $XENDOMAINS_SAVE`
-    echo -n " MISS SAVED: " $missing
-    return 1
-}
-
-# This does NOT necessarily restart all running domains: instead it
-# stops all running domains and then boots all the domains specified in
-# AUTODIR.  If other domains have been started manually then they will
-# not get restarted.
-# Commented out to avoid confusion!
-
-restart()
-{
-    stop
-    start
-}
-
-reload()
-{
-    restart
-}
-
-
 case "$1" in
     start)
-	start
-	rc_status
-	if test -f $LOCKFILE; then rc_status -v; fi
+	$SBINDIR/xendomains start
 	;;
-
     stop)
-	stop
-	rc_status -v
+	$SBINDIR/xendomains stop
 	;;
-
     restart)
-	restart
+	$SBINDIR/xendomains restart
 	;;
     reload)
-	reload
+	$SBINDIR/xendomains reload
 	;;
-
     status)
-	echo -n "Checking for xendomains:"
-	if test ! -f $LOCKFILE; then
-	    rc_failed 3
-	else
-	    check_all_auto_domains_up
-	    rc_status
-	    check_all_saved_domains_up
-	    rc_status
-	fi
-	rc_status -v
+	$SBINDIR/xendomains status
 	;;
-
     *)
 	echo "Usage: $0 {start|stop|restart|reload|status}"
-	rc_failed 3
-	rc_status -v
+	exit 3
 	;;
 esac
-
-rc_exit
+exit $?
diff --git a/tools/hotplug/Linux/xendomains b/tools/hotplug/Linux/xendomains
new file mode 100644
index 0000000..cad92da
--- /dev/null
+++ b/tools/hotplug/Linux/xendomains
@@ -0,0 +1,584 @@
+#!/bin/bash
+#
+# /etc/init.d/xendomains
+# Start / stop domains automatically when domain 0 boots / shuts down.
+#
+# chkconfig: 345 99 00
+# description: Start / stop Xen domains.
+#
+# This script offers fairly basic functionality.  It should work on Redhat
+# but also on LSB-compliant SuSE releases and on Debian with the LSB package
+# installed.  (LSB is the Linux Standard Base)
+#
+# Based on the example in the "Designing High Quality Integrated Linux
+# Applications HOWTO" by Avi Alkalay
+# <http://www.tldp.org/HOWTO/HighQuality-Apps-HOWTO/>
+#
+### BEGIN INIT INFO
+# Provides:          xendomains
+# Required-Start:    $syslog $remote_fs xenstored xenconsoled
+# Should-Start:      xend
+# Required-Stop:     $syslog $remote_fs xenstored xenconsoled
+# Should-Stop:       xend
+# Default-Start:     2 3 5
+# Default-Stop:      0 1 6
+# Short-Description: Start/stop secondary xen domains
+# Description:       Start / stop domains automatically when domain 0
+#                    boots / shuts down.
+### END INIT INFO
+
+. /etc/xen/scripts/hotplugpath.sh
+
+CMD=${SBINDIR}/xl
+HEADCOMP="Xen saved domain"
+$CMD list &> /dev/null
+if test $? -ne 0
+then
+	exit $?
+fi
+
+$CMD list &> /dev/null
+if test $? -ne 0
+then
+	exit 0;
+fi
+
+# Correct exit code would probably be 5, but it's enough
+# if xend complains if we're not running as privileged domain
+if ! [ -e /proc/xen/privcmd ]; then
+	exit 0
+fi
+
+# See docs/misc/distro_mapping.txt
+if [ -d /var/lock/subsys ]; then
+	LOCKFILE=/var/lock/subsys/xendomains
+else
+	LOCKFILE=/var/lock/xendomains
+fi
+
+if [ -d /etc/sysconfig ]; then
+	XENDOM_CONFIG=/etc/sysconfig/xendomains
+else
+	XENDOM_CONFIG=/etc/default/xendomains
+fi
+
+test -r $XENDOM_CONFIG || { echo "$XENDOM_CONFIG not existing";
+	if [ "$1" = "stop" ]; then exit 0;
+	else exit 6; fi; }
+
+. $XENDOM_CONFIG
+
+# Use the SUSE rc_ init script functions;
+# emulate them on LSB, RH and other systems
+if test -e /etc/rc.status; then
+    # SUSE rc script library
+    . /etc/rc.status
+else
+    _cmd=$1
+    declare -a _SMSG
+    if test "${_cmd}" = "status"; then
+	_SMSG=(running dead dead unused unknown)
+	_RC_UNUSED=3
+    else
+	_SMSG=(done failed failed missed failed skipped unused failed failed)
+	_RC_UNUSED=6
+    fi
+    if test -e /etc/init.d/functions; then
+	# REDHAT
+	. /etc/init.d/functions
+	echo_rc()
+	{
+	    #echo -n "  [${_SMSG[${_RC_RV}]}] "
+	    if test ${_RC_RV} = 0; then
+		success "  [${_SMSG[${_RC_RV}]}] "
+	    else
+		failure "  [${_SMSG[${_RC_RV}]}] "
+	    fi
+	}
+    elif test -e /lib/lsb/init-functions; then
+	# LSB
+    	. /lib/lsb/init-functions
+        if alias log_success_msg >/dev/null 2>/dev/null; then
+	  echo_rc()
+	  {
+	       echo "  [${_SMSG[${_RC_RV}]}] "
+	  }
+        else
+	  echo_rc()
+	  {
+	    if test ${_RC_RV} = 0; then
+		log_success_msg "  [${_SMSG[${_RC_RV}]}] "
+	    else
+		log_failure_msg "  [${_SMSG[${_RC_RV}]}] "
+	    fi
+	  }
+        fi
+    else
+	# emulate it
+	echo_rc()
+	{
+	    echo "  [${_SMSG[${_RC_RV}]}] "
+	}
+    fi
+    rc_reset() { _RC_RV=0; }
+    rc_failed()
+    {
+	if test -z "$1"; then
+	    _RC_RV=1;
+	elif test "$1" != "0"; then
+	    _RC_RV=$1;
+	fi
+	return ${_RC_RV}
+    }
+    rc_check()
+    {
+	return rc_failed $?
+    }
+    rc_status()
+    {
+	rc_failed $?
+	if test "$1" = "-r"; then _RC_RV=0; shift; fi
+	if test "$1" = "-s"; then rc_failed 5; echo_rc; rc_failed 3; shift; fi
+	if test "$1" = "-u"; then rc_failed ${_RC_UNUSED}; echo_rc; rc_failed 3; shift; fi
+	if test "$1" = "-v"; then echo_rc; shift; fi
+	if test "$1" = "-r"; then _RC_RV=0; shift; fi
+	return ${_RC_RV}
+    }
+    rc_exit() { exit ${_RC_RV}; }
+    rc_active()
+    {
+	if test -z "$RUNLEVEL"; then read RUNLEVEL REST < <(/sbin/runlevel); fi
+	if test -e /etc/init.d/S[0-9][0-9]${1}; then return 0; fi
+	return 1
+    }
+fi
+
+if ! which usleep >&/dev/null
+then
+  usleep()
+  {
+    if [ -n "$1" ]
+    then
+      sleep $(( $1 / 1000000 ))
+    fi
+  }
+fi
+
+# Reset status of this service
+rc_reset
+
+##
+# Returns 0 (success) if the given parameter names a directory, and that
+# directory is not empty.
+#
+contains_something()
+{
+  if [ -d "$1" ] && [ `/bin/ls $1 | wc -l` -gt 0 ]
+  then
+    return 0
+  else
+    return 1
+  fi
+}
+
+# read name from xen config file
+rdname()
+{
+    NM=$($CMD create --quiet --dryrun --defconfig "$1" |
+         sed -n 's/^.*(name \(.*\))$/\1/p;s/^.*"name": "\(.*\)",$/\1/p')
+}
+
+rdnames()
+{
+    NAMES=
+    if ! contains_something "$XENDOMAINS_AUTO"
+    then
+	return
+    fi
+    for dom in $XENDOMAINS_AUTO/*; do
+	rdname $dom
+	if test -z $NAMES; then
+	    NAMES=$NM;
+	else
+	    NAMES="$NAMES|$NM"
+	fi
+    done
+}
+
+LIST_GREP='(domain\|(domid\|(name\|^    {$\|"name":\|"domid":'
+parseln()
+{
+    if [[ "$1" =~ '(domain' ]] || [[ "$1" = "{" ]]; then
+        name=;id=
+    elif [[ "$1" =~ '(name' ]]; then
+        name=$(echo $1 | sed -e 's/^.*(name \(.*\))$/\1/')
+    elif [[ "$1" =~ '(domid' ]]; then
+        id=$(echo $1 | sed -e 's/^.*(domid \(.*\))$/\1/')
+    elif [[ "$1" =~ '"name":' ]]; then
+        name=$(echo $1 | sed -e 's/^.*"name": "\(.*\)",$/\1/')
+    elif [[ "$1" =~ '"domid":' ]]; then
+        id=$(echo $1 | sed -e 's/^.*"domid": \(.*\),$/\1/')
+    fi
+
+    [ -n "$name" -a -n "$id" ] && return 0 || return 1
+}
+
+is_running()
+{
+    rdname $1
+    RC=1
+    name=;id=
+    while read LN; do
+	parseln "$LN" || continue
+	if test $id = 0; then continue; fi
+	case $name in
+	    ($NM)
+		RC=0
+		;;
+	esac
+    done < <($CMD list -l | grep "$LIST_GREP")
+    return $RC
+}
+
+start()
+{
+    if [ -f $LOCKFILE ]; then
+	echo -e "xendomains already running (lockfile exists)"
+	return;
+    fi
+
+    saved_domains=" "
+    if [ "$XENDOMAINS_RESTORE" = "true" ] &&
+       contains_something "$XENDOMAINS_SAVE"
+    then
+	mkdir -p $(dirname "$LOCKFILE")
+	touch $LOCKFILE
+	echo -n "Restoring Xen domains:"
+	saved_domains=`ls $XENDOMAINS_SAVE`
+        for dom in $XENDOMAINS_SAVE/*; do
+            if [ -f $dom ] ; then
+                HEADER=`head -c 16 $dom | head -n 1 2> /dev/null`
+                if [ "$HEADER" = "$HEADCOMP" ]; then
+                    echo -n " ${dom##*/}"
+                    XMR=`$CMD restore $dom 2>&1 1>/dev/null`
+                    #$CMD restore $dom
+                    if [ $? -ne 0 ]; then
+                        echo -e "\nAn error occurred while restoring domain ${dom##*/}:\n$XMR"
+                        rc_failed $?
+                        echo -e '!'
+                    else
+                        # mv $dom ${dom%/*}/.${dom##*/}
+                        rm $dom
+                    fi
+                fi
+            fi
+        done
+	echo -e
+    fi
+
+    if contains_something "$XENDOMAINS_AUTO"
+    then
+	touch $LOCKFILE
+	echo -n "Starting auto Xen domains:"
+	# We expect config scripts for auto starting domains to be in
+	# XENDOMAINS_AUTO - they could just be symlinks to files elsewhere
+
+	# Create all domains with config files in XENDOMAINS_AUTO.
+	# TODO: We should record which domain name belongs
+	# so we have the option to selectively shut down / migrate later
+	# If a domain statefile from $XENDOMAINS_SAVE matches a domain name
+	# in $XENDOMAINS_AUTO, do not try to start that domain; if it didn't
+	# restore correctly it requires administrative attention.
+	for dom in $XENDOMAINS_AUTO/*; do
+	    echo -n " ${dom##*/}"
+	    shortdom=$(echo $dom | sed -n 's/^.*\/\(.*\)$/\1/p')
+	    echo $saved_domains | grep -w $shortdom > /dev/null
+	    if [ $? -eq 0 ] || is_running $dom; then
+		echo -n "(skip)"
+	    else
+		XMC=`$CMD create --quiet --defconfig $dom`
+		if [ $? -ne 0 ]; then
+		    echo -e "\nAn error occurred while creating domain ${dom##*/}: $XMC\n"
+		    rc_failed $?
+		    echo -e '!'
+		else
+		    usleep $XENDOMAINS_CREATE_USLEEP
+		fi
+	    fi
+	done
+    fi
+}
+
+all_zombies()
+{
+    name=;id=
+    while read LN; do
+	parseln "$LN" || continue
+	if test $id = 0; then continue; fi
+	if test "$state" != "-b---d" -a "$state" != "-----d"; then
+	    return 1;
+	fi
+    done < <($CMD list -l | grep "$LIST_GREP")
+    return 0
+}
+
+# Wait for max $XENDOMAINS_STOP_MAXWAIT for $CMD $1 to finish;
+# if it has not exited by that time kill it, so the init script will
+# succeed within a finite amount of time; if $2 is nonnull, it will
+# kill the command as well as soon as no domain (except for zombies)
+# are left (used for shutdown --all). Third parameter, if any, suppresses
+# output of dots per working state (formatting issues)
+watchdog_xencmd()
+{
+    if test -z "$XENDOMAINS_STOP_MAXWAIT" -o "$XENDOMAINS_STOP_MAXWAIT" = "0"; then
+	exit
+    fi
+
+    usleep 20000
+    for no in `seq 0 $XENDOMAINS_STOP_MAXWAIT`; do
+	# exit if $CMD save/migrate/shutdown is finished
+	PSAX=`ps axlw | grep "$CMD $1" | grep -v grep`
+	if test -z "$PSAX"; then exit; fi
+	if ! test -n "$3"; then echo -n '.'; fi
+	sleep 1
+	# go to kill immediately if there's only zombies left
+	if all_zombies && test -n "$2"; then break; fi
+    done
+    sleep 1
+    read PSF PSUID PSPID PSPPID < <(echo "$PSAX")
+    # kill $CMD $1
+    kill $PSPID >/dev/null 2>&1
+
+    echo -e .
+}
+
+stop()
+{
+    exec 3>&2 2> /dev/null
+
+    # Collect list of domains to shut down
+    if test "$XENDOMAINS_AUTO_ONLY" = "true"; then
+	rdnames
+    fi
+    echo -n "Shutting down Xen domains:"
+    name=;id=
+    while read LN; do
+	parseln "$LN" || continue
+	if test $id = 0; then continue; fi
+	echo -n " $name"
+	if test "$XENDOMAINS_AUTO_ONLY" = "true"; then
+	    eval "
+	    case \"\$name\" in
+		($NAMES)
+		    # nothing
+		    ;;
+		(*)
+		    echo -e '(skip)'
+		    continue
+		    ;;
+	    esac
+	    "
+	fi
+	# XENDOMAINS_SYSRQ chould be something like just "s"
+	# or "s e i u" or even "s e s i u o"
+	# for the latter, you should set XENDOMAINS_USLEEP to 1200000 or so
+	if test -n "$XENDOMAINS_SYSRQ"; then
+	    for sysrq in $XENDOMAINS_SYSRQ; do
+		echo -n "(SR-$sysrq)"
+		XMR=`$CMD sysrq $id $sysrq 2>&1 1>/dev/null`
+		if test $? -ne 0; then
+		    echo -e "\nAn error occurred while doing sysrq on domain:\n$XMR\n"
+		    rc_failed $?
+		    echo -n '!'
+		fi
+		# usleep just ignores empty arg
+		usleep $XENDOMAINS_USLEEP
+	    done
+	fi
+	if test "$state" = "-b---d" -o "$state" = "-----d"; then
+	    echo -n "(zomb)"
+	    continue
+	fi
+	if test -n "$XENDOMAINS_MIGRATE"; then
+	    echo -n "(migr)"
+	    watchdog_xencmd migrate &
+	    WDOG_PID=$!
+	    XMR=`$CMD migrate $id $XENDOMAINS_MIGRATE 2>&1 1>/dev/null`
+	    if test $? -ne 0; then
+		echo -e "\nAn error occurred while migrating domain:\n$XMR\n"
+		rc_failed $?
+		echo -e '!'
+
+		kill $WDOG_PID >/dev/null 2>&1
+	    else
+		kill $WDOG_PID >/dev/null 2>&1
+
+		echo -e .
+		usleep 1000
+		continue
+	    fi
+	fi
+	if test -n "$XENDOMAINS_SAVE"; then
+	    echo -n "(save)"
+	    watchdog_xencmd save &
+	    WDOG_PID=$!
+	    mkdir -p "$XENDOMAINS_SAVE"
+	    XMR=`$CMD save $id $XENDOMAINS_SAVE/$name 2>&1 1>/dev/null`
+	    if test $? -ne 0; then
+		echo -e "\nAn error occurred while saving domain:\n$XMR\n"
+		rc_failed $?
+		echo -e '!'
+		kill $WDOG_PID >/dev/null 2>&1
+	    else
+		kill $WDOG_PID >/dev/null 2>&1
+		echo -e .
+		usleep 1000
+		continue
+	    fi
+	fi
+	if test -n "$XENDOMAINS_SHUTDOWN"; then
+	    # XENDOMAINS_SHUTDOWN should be "--wait"
+	    echo -n "(shut)"
+	    watchdog_xencmd shutdown &
+	    WDOG_PID=$!
+	    XMR=`$CMD shutdown $XENDOMAINS_SHUTDOWN $id 2>&1 1>/dev/null`
+	    if test $? -ne 0; then
+		echo -e "\nAn error occurred while shutting down domain:\n$XMR\n"
+		rc_failed $?
+		echo -e '!'
+	    fi
+	    kill $WDOG_PID >/dev/null 2>&1
+	fi
+    done < <($CMD list -l | grep "$LIST_GREP")
+
+    # NB. this shuts down ALL Xen domains (politely), not just the ones in
+    # AUTODIR/*
+    # This is because it's easier to do ;-) but arguably if this script is run
+    # on system shutdown then it's also the right thing to do.
+    if ! all_zombies && test -n "$XENDOMAINS_SHUTDOWN_ALL"; then
+	# XENDOMAINS_SHUTDOWN_ALL should be "--all --wait"
+	echo -n " SHUTDOWN_ALL "
+	watchdog_xencmd shutdown 1 false &
+	WDOG_PID=$!
+	XMR=`$CMD shutdown $XENDOMAINS_SHUTDOWN_ALL 2>&1 1>/dev/null`
+	if test $? -ne 0; then
+	    echo -e "\nAn error occurred while shutting down all domains: $XMR\n"
+	    rc_failed $?
+	    echo -e '!'
+	fi
+	kill $WDOG_PID >/dev/null 2>&1
+    fi
+
+    # Unconditionally delete lock file
+    rm -f $LOCKFILE
+
+    exec 2>&3
+}
+
+check_domain_up()
+{
+    name=;id=
+    while read LN; do
+	parseln "$LN" || continue
+	if test $id = 0; then continue; fi
+	case $name in
+	    ($1)
+		return 0
+		;;
+	esac
+    done < <($CMD list -l | grep "$LIST_GREP")
+    return 1
+}
+
+check_all_auto_domains_up()
+{
+    if ! contains_something "$XENDOMAINS_AUTO"
+    then
+      return 0
+    fi
+    missing=
+    for nm in $XENDOMAINS_AUTO/*; do
+	rdname $nm
+	found=0
+	if check_domain_up "$NM"; then
+	    echo -n " $name"
+	else
+	    missing="$missing $NM"
+	fi
+    done
+    if test -n "$missing"; then
+	echo -n " MISS AUTO:$missing"
+	return 1
+    fi
+    return 0
+}
+
+check_all_saved_domains_up()
+{
+    if ! contains_something "$XENDOMAINS_SAVE"
+    then
+      return 0
+    fi
+    missing=`/bin/ls $XENDOMAINS_SAVE`
+    echo -n " MISS SAVED: " $missing
+    return 1
+}
+
+# This does NOT necessarily restart all running domains: instead it
+# stops all running domains and then boots all the domains specified in
+# AUTODIR.  If other domains have been started manually then they will
+# not get restarted.
+# Commented out to avoid confusion!
+
+restart()
+{
+    stop
+    start
+}
+
+reload()
+{
+    restart
+}
+
+
+case "$1" in
+    start)
+	start
+	rc_status
+	if test -f $LOCKFILE; then rc_status -v; fi
+	;;
+
+    stop)
+	stop
+	rc_status -v
+	;;
+
+    restart)
+	restart
+	;;
+    reload)
+	reload
+	;;
+
+    status)
+	echo -n "Checking for xendomains:"
+	if test ! -f $LOCKFILE; then
+	    rc_failed 3
+	else
+	    check_all_auto_domains_up
+	    rc_status
+	    check_all_saved_domains_up
+	    rc_status
+	fi
+	rc_status -v
+	;;
+
+    *)
+	echo "Usage: $0 {start|stop|restart|reload|status}"
+	rc_failed 3
+	rc_status -v
+	;;
+esac
+
+rc_exit
-- 
2.0.0.rc3.18.g00a5b79


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

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

* [PATCH v6 08/13] autoconf: xen: force a refresh with autoconf
  2014-06-13  1:18 [PATCH v6 00/13] xen: add systemd support Luis R. Rodriguez
                   ` (6 preceding siblings ...)
  2014-06-13  1:18 ` [PATCH v6 07/13] tools/xendomains: move to libexec and use a smaller init helper Luis R. Rodriguez
@ 2014-06-13  1:18 ` Luis R. Rodriguez
  2014-06-13  1:18 ` [PATCH v6 09/13] autoconf: update m4/pkg.m4 Luis R. Rodriguez
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-06-13  1:18 UTC (permalink / raw)
  To: xen-devel
  Cc: Keir Fraser, Ian Campbell, Tim Deegan, Luis R. Rodriguez,
	Ian Jackson, Jan Beulich

From: "Luis R. Rodriguez" <mcgrof@suse.com>

With some new functionality introduced we can't keep around the old cache,
but more specifically at times autogen.sh can produce inconsistent
results without considering all files obsolete. The cost of considering
all files obsolete is small so just force it.

Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Keir Fraser <keir@xen.org>
Cc: Tim Deegan <tim@xen.org>
Acked-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
---

Please run autogen.sh, just in case after applying this.

 autogen.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/autogen.sh b/autogen.sh
index b5c9688..2be8360 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -1,12 +1,12 @@
 #!/bin/sh -e
-autoconf
+autoconf -f
 ( cd tools
-  autoconf
+  autoconf -f
   autoheader
 )
 ( cd stubdom
-  autoconf
+  autoconf -f
 )
 ( cd docs
-  autoconf
+  autoconf -f
 )
-- 
2.0.0.rc3.18.g00a5b79


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

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

* [PATCH v6 09/13] autoconf: update m4/pkg.m4
  2014-06-13  1:18 [PATCH v6 00/13] xen: add systemd support Luis R. Rodriguez
                   ` (7 preceding siblings ...)
  2014-06-13  1:18 ` [PATCH v6 08/13] autoconf: xen: force a refresh with autoconf Luis R. Rodriguez
@ 2014-06-13  1:18 ` Luis R. Rodriguez
  2014-07-02 13:13   ` Ian Campbell
  2014-06-13  1:18 ` [PATCH v6 10/13] autoconf: xen: move standard path variables to config/Paths.mk.in Luis R. Rodriguez
                   ` (5 subsequent siblings)
  14 siblings, 1 reply; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-06-13  1:18 UTC (permalink / raw)
  To: xen-devel
  Cc: Keir Fraser, Ian Campbell, Tim Deegan, Luis R. Rodriguez,
	Ian Jackson, Jan Beulich

From: "Luis R. Rodriguez" <mcgrof@suse.com>

The provenance of the m4 pkg.m4 macro library was not documented
and it was not clear how and if we can update this without breaking
things. Document where this comes from, update us to the latest
release from git and put a warning about avoiding private evolutions
so that instead things go upstream.

The pkg-config m4 macro library comes from the upstream pkg-config
git repository [0]. If you update the m4 library update this file
with provenance and last commit ID information. For documentation
on how to use this read the pkg-config(1) man page.

Tree: git://anongit.freedesktop.org/pkg-config

The last synch was from commit:

commit 4f0084d9d3b8726a797a373c7ec5e406000995d0
Author: Dan Nicholson <dbn.lists@gmail.com>
Date:   Mon Feb 3 15:59:18 2014 -0800

    glib: Fix Makefiles to suppress warnings from automake

    With the newly added glib.mk, some of the noinst_* variables need to use
    += in the evaluation to avoid multiple definition warnings from
    automake.

Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Keir Fraser <keir@xen.org>
Cc: Tim Deegan <tim@xen.org>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
---

please run autogen.sh after applying

 m4/README.source | 28 ++++++++++++++++++
 m4/pkg.m4        | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 110 insertions(+), 6 deletions(-)
 create mode 100644 m4/README.source

diff --git a/m4/README.source b/m4/README.source
new file mode 100644
index 0000000..76f7c5a
--- /dev/null
+++ b/m4/README.source
@@ -0,0 +1,28 @@
+About
+=====
+This documents the upstream sources for the different slew of different
+m4 sources we have picked up or developed.
+
+pkg.m4
+======
+The pkg-config m4 macro library comes from the upstream pkg-config
+git repository [0]. If you update the m4 library update this file
+with provenance and last commit ID information. For documentation
+on how to use this read the pkg-config(1) man page.
+
+Do not modify this file yourself, if you want to evolve it send
+patches upstream and then synch back here.
+
+Tree: git://anongit.freedesktop.org/pkg-config
+
+The last synch was from commit:
+
+commit 4f0084d9d3b8726a797a373c7ec5e406000995d0
+Author: Dan Nicholson <dbn.lists@gmail.com>
+Date:   Mon Feb 3 15:59:18 2014 -0800
+
+    glib: Fix Makefiles to suppress warnings from automake
+    
+    With the newly added glib.mk, some of the noinst_* variables need to use
+    += in the evaluation to avoid multiple definition warnings from
+    automake.
diff --git a/m4/pkg.m4 b/m4/pkg.m4
index 9bb3e06..62995f0 100644
--- a/m4/pkg.m4
+++ b/m4/pkg.m4
@@ -26,7 +26,8 @@
 # ----------------------------------
 AC_DEFUN([PKG_PROG_PKG_CONFIG],
 [m4_pattern_forbid([^_?PKG_[A-Z_]+$])
-m4_pattern_allow([^PKG_CONFIG(_PATH)?$])
+m4_pattern_allow([^PKG_CONFIG(_(PATH|LIBDIR|SYSROOT_DIR|ALLOW_SYSTEM_(CFLAGS|LIBS)))?$])
+m4_pattern_allow([^PKG_CONFIG_(DISABLE_UNINSTALLED|TOP_BUILD_DIR|DEBUG_SPEW)$])
 AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])
 AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path])
 AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path])
@@ -72,7 +73,8 @@ m4_define([_PKG_CONFIG],
     pkg_cv_[]$1="$$1"
  elif test -n "$PKG_CONFIG"; then
     PKG_CHECK_EXISTS([$3],
-                     [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`],
+                     [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`
+		      test "x$?" != "x0" && pkg_failed=yes ],
 		     [pkg_failed=yes])
  else
     pkg_failed=untried
@@ -120,9 +122,9 @@ if test $pkg_failed = yes; then
    	AC_MSG_RESULT([no])
         _PKG_SHORT_ERRORS_SUPPORTED
         if test $_pkg_short_errors_supported = yes; then
-	        $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "$2" 2>&1`
+	        $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "$2" 2>&1`
         else 
-	        $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors "$2" 2>&1`
+	        $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "$2" 2>&1`
         fi
 	# Put the nasty error message in config.log where it belongs
 	echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
@@ -135,7 +137,7 @@ $$1_PKG_ERRORS
 Consider adjusting the PKG_CONFIG_PATH environment variable if you
 installed software in a non-standard prefix.
 
-_PKG_TEXT])dnl
+_PKG_TEXT])[]dnl
         ])
 elif test $pkg_failed = untried; then
      	AC_MSG_RESULT([no])
@@ -146,7 +148,7 @@ path to pkg-config.
 
 _PKG_TEXT
 
-To get pkg-config, see <http://pkg-config.freedesktop.org/>.])dnl
+To get pkg-config, see <http://pkg-config.freedesktop.org/>.])[]dnl
         ])
 else
 	$1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
@@ -155,3 +157,77 @@ else
 	$3
 fi[]dnl
 ])# PKG_CHECK_MODULES
+
+
+# PKG_CHECK_MODULES_STATIC(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
+# [ACTION-IF-NOT-FOUND])
+# ---------------------------------------------------------------------
+# Checks for existence of MODULES and gathers its build flags with
+# static libraries enabled. Sets VARIABLE-PREFIX_CFLAGS from --cflags
+# and VARIABLE-PREFIX_LIBS from --libs.
+#
+# Note that if there is a possibility the first call to
+# PKG_CHECK_MODULES_STATIC might not happen, you should be sure to include
+# an explicit call to PKG_PROG_PKG_CONFIG in your configure.ac.
+AC_DEFUN([PKG_CHECK_MODULES_STATIC],
+[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
+_save_PKG_CONFIG=$PKG_CONFIG
+PKG_CONFIG="$PKG_CONFIG --static"
+PKG_CHECK_MODULES($@)
+PKG_CONFIG=$_save_PKG_CONFIG[]dnl
+])
+
+
+# PKG_INSTALLDIR(DIRECTORY)
+# -------------------------
+# Substitutes the variable pkgconfigdir as the location where a module
+# should install pkg-config .pc files. By default the directory is
+# $libdir/pkgconfig, but the default can be changed by passing
+# DIRECTORY. The user can override through the --with-pkgconfigdir
+# parameter.
+AC_DEFUN([PKG_INSTALLDIR],
+[m4_pushdef([pkg_default], [m4_default([$1], ['${libdir}/pkgconfig'])])
+m4_pushdef([pkg_description],
+    [pkg-config installation directory @<:@]pkg_default[@:>@])
+AC_ARG_WITH([pkgconfigdir],
+    [AS_HELP_STRING([--with-pkgconfigdir], pkg_description)],,
+    [with_pkgconfigdir=]pkg_default)
+AC_SUBST([pkgconfigdir], [$with_pkgconfigdir])
+m4_popdef([pkg_default])
+m4_popdef([pkg_description])
+]) dnl PKG_INSTALLDIR
+
+
+# PKG_NOARCH_INSTALLDIR(DIRECTORY)
+# -------------------------
+# Substitutes the variable noarch_pkgconfigdir as the location where a
+# module should install arch-independent pkg-config .pc files. By
+# default the directory is $datadir/pkgconfig, but the default can be
+# changed by passing DIRECTORY. The user can override through the
+# --with-noarch-pkgconfigdir parameter.
+AC_DEFUN([PKG_NOARCH_INSTALLDIR],
+[m4_pushdef([pkg_default], [m4_default([$1], ['${datadir}/pkgconfig'])])
+m4_pushdef([pkg_description],
+    [pkg-config arch-independent installation directory @<:@]pkg_default[@:>@])
+AC_ARG_WITH([noarch-pkgconfigdir],
+    [AS_HELP_STRING([--with-noarch-pkgconfigdir], pkg_description)],,
+    [with_noarch_pkgconfigdir=]pkg_default)
+AC_SUBST([noarch_pkgconfigdir], [$with_noarch_pkgconfigdir])
+m4_popdef([pkg_default])
+m4_popdef([pkg_description])
+]) dnl PKG_NOARCH_INSTALLDIR
+
+
+# PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE,
+# [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
+# -------------------------------------------
+# Retrieves the value of the pkg-config variable for the given module.
+AC_DEFUN([PKG_CHECK_VAR],
+[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
+AC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl
+
+_PKG_CONFIG([$1], [variable="][$3]["], [$2])
+AS_VAR_COPY([$1], [pkg_cv_][$1])
+
+AS_VAR_IF([$1], [""], [$5], [$4])dnl
+])# PKG_CHECK_VAR
-- 
2.0.0.rc3.18.g00a5b79

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

* [PATCH v6 10/13] autoconf: xen: move standard path variables to config/Paths.mk.in
  2014-06-13  1:18 [PATCH v6 00/13] xen: add systemd support Luis R. Rodriguez
                   ` (8 preceding siblings ...)
  2014-06-13  1:18 ` [PATCH v6 09/13] autoconf: update m4/pkg.m4 Luis R. Rodriguez
@ 2014-06-13  1:18 ` Luis R. Rodriguez
  2014-07-02 13:34   ` Ian Campbell
  2014-06-13  1:18 ` [PATCH v6 11/13] xencommons: move module list into a generic place Luis R. Rodriguez
                   ` (4 subsequent siblings)
  14 siblings, 1 reply; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-06-13  1:18 UTC (permalink / raw)
  To: xen-devel
  Cc: Keir Fraser, Ian Campbell, Tim Deegan, Luis R. Rodriguez,
	Ian Jackson, Jan Beulich, Samuel Thibault

From: "Luis R. Rodriguez" <mcgrof@suse.com>

This moves all generic path variables to a new the config/Paths.mk.in
input source file to be processed at configure time, tons of files use
these so this just share them. This also paves the way to let us
easily dynamically configure these with autoconf, for now we leave the
same presets as was present before.

This work was prompted by looking for an autoconf way to do
replacements for the hotplug global file, while at it I realized
that a few other files use the same variables and have in places
around the tree the same constructs for generating their own
files. This makes use of the old buildmakevars2file() but generalizes
the definition of the paths at configure time and spreads the
new definitions out throughout the build system.

This has no impact on building the hypervisor and extras/mini-os,
you do not need to, and are not expected to, run configure to build
those targets.

While at it lets add some documentation on the for the two files on
the source file, we can expand further details on the wiki [0].

[0] http://wiki.xen.org/wiki/Category:Host_Configuration#System_wide_xen_configuration

Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Samuel Thibault <samuel.thibault@ens-lyon.org>
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Keir Fraser <keir@xen.org>
Cc: Tim Deegan <tim@xen.org>
Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
---

Please run autogen.sh after applying.

 .gitignore           |  1 +
 config/Paths.mk.in   | 37 +++++++++++++++++++++++++++++++
 config/Stubdom.mk.in |  1 +
 configure.ac         |  8 ++++++-
 m4/paths.m4          | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 stubdom/Makefile     |  1 +
 tools/Rules.mk       |  1 +
 7 files changed, 109 insertions(+), 1 deletion(-)
 create mode 100644 config/Paths.mk.in
 create mode 100644 m4/paths.m4

diff --git a/.gitignore b/.gitignore
index 562c262..588a76d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -36,6 +36,7 @@ config.log
 config.status
 config.cache
 config/Toplevel.mk
+config/Paths.mk
 
 build-*
 dist/*
diff --git a/config/Paths.mk.in b/config/Paths.mk.in
new file mode 100644
index 0000000..507b6d1
--- /dev/null
+++ b/config/Paths.mk.in
@@ -0,0 +1,37 @@
+# Xen system configuration
+# ========================
+#
+# Xen uses a set of variables for system configuration and at build time,
+# because of this these variables are defined on one master input source file
+# and is generated after running ./configure. The master source is located
+# on the xen source tree at under config/Paths.mk.in and it is used to
+# generate shell or header files by the build system upon demand through the
+# use of the helper makefile helper buildmakevars2file().
+#
+# For more documentation you can refer to the wiki:
+#
+# http://wiki.xen.org/wiki/Category:Host_Configuration#System_wide_xen_configuration
+
+SBINDIR                  := @SBINDIR@
+BINDIR                   := @BINDIR@
+LIBEXEC                  := @LIBEXEC@
+
+SHAREDIR                 := @SHAREDIR@
+LIBDIR                   := @LIBDIR@
+
+XEN_RUN_DIR              := @XEN_RUN_DIR@
+XEN_LOG_DIR              := @XEN_LOG_DIR@
+XEN_LIB_STORED           := @XEN_LIB_STORED@
+
+CONFIG_DIR               := @CONFIG_DIR@
+XEN_LOCK_DIR             := @XEN_LOCK_DIR@
+XEN_PAGING_DIR           := @XEN_PAGING_DIR@
+
+PRIVATE_PREFIX           := @PRIVATE_PREFIX@
+PRIVATE_PREFIX           := @PKG_XEN_PREFIX@
+PRIVATE_BINDIR           := @PRIVATE_BINDIR@
+
+XENFIRMWAREDIR           := @XENFIRMWAREDIR@
+
+XEN_CONFIG_DIR           := @XEN_CONFIG_DIR@
+XEN_SCRIPT_DIR           := @XEN_SCRIPT_DIR@
diff --git a/config/Stubdom.mk.in b/config/Stubdom.mk.in
index 302842e..6bce206 100644
--- a/config/Stubdom.mk.in
+++ b/config/Stubdom.mk.in
@@ -1,4 +1,5 @@
 # Prefix and install folder
+include $(XEN_ROOT)/config/Paths.mk
 prefix              := @prefix@
 PREFIX              := $(prefix)
 exec_prefix         := @exec_prefix@
diff --git a/configure.ac b/configure.ac
index 6c14524..f32f9af 100644
--- a/configure.ac
+++ b/configure.ac
@@ -5,12 +5,18 @@ AC_PREREQ([2.67])
 AC_INIT([Xen Hypervisor], m4_esyscmd([./version.sh ./xen/Makefile]),
     [xen-devel@lists.xen.org], [xen], [http://www.xen.org/])
 AC_CONFIG_SRCDIR([./xen/common/kernel.c])
-AC_CONFIG_FILES([./config/Toplevel.mk])
+AC_CONFIG_FILES([
+	config/Toplevel.mk
+	config/Paths.mk
+])
 
 AC_CANONICAL_HOST
 
 m4_include([m4/features.m4])
 m4_include([m4/subsystem.m4])
+m4_include([m4/paths.m4])
+
+AX_XEN_EXPAND_CONFIG()
 
 dnl mini-os is only ported to certain platforms
 case "$host_cpu" in
diff --git a/m4/paths.m4 b/m4/paths.m4
new file mode 100644
index 0000000..717fcd1
--- /dev/null
+++ b/m4/paths.m4
@@ -0,0 +1,61 @@
+AC_DEFUN([AX_XEN_EXPAND_CONFIG], [
+dnl expand these early so we can use this for substitutions
+test "x$prefix" = "xNONE" && prefix=$ac_default_prefix
+test "x$exec_prefix" = "xNONE" && exec_prefix=$ac_default_prefix
+
+BINDIR=$prefix/bin
+AC_SUBST(BINDIR)
+
+SBINDIR=$prefix/sbin
+AC_SUBST(SBINDIR)
+
+dnl XXX: this should be changed to use the passed $libexec
+dnl but can be done as a second step
+LIBEXEC=$prefix/lib/xen/bin
+AC_SUBST(LIBEXEC)
+
+LIBDIR=`eval echo $libdir`
+AC_SUBST(LIBDIR)
+
+XEN_RUN_DIR=/var/run/xen
+AC_SUBST(XEN_RUN_DIR)
+
+XEN_LOG_DIR=/var/log/xen
+AC_SUBST(XEN_LOG_DIR)
+
+XEN_LIB_STORED=/var/lib/xenstored
+AC_SUBST(XEN_LIB_STORED)
+
+SHAREDIR=$prefix/share
+AC_SUBST(SHAREDIR)
+
+PRIVATE_PREFIX=$LIBDIR/xen
+AC_SUBST(PRIVATE_PREFIX)
+
+PKG_XEN_PREFIX=$LIBDIR/xen
+AC_SUBST(PKG_XEN_PREFIX)
+
+PRIVATE_BINDIR=$PRIVATE_PREFIX/bin
+AC_SUBST(PRIVATE_BINDIR)
+
+XENFIRMWAREDIR=$prefix/lib/xen/boot
+AC_SUBST(XENFIRMWAREDIR)
+
+CONFIG_DIR=/etc
+AC_SUBST(CONFIG_DIR)
+
+XEN_CONFIG_DIR=$CONFIG_DIR/xen
+AC_SUBST(XEN_CONFIG_DIR)
+
+XEN_SCRIPT_DIR=$XEN_CONFIG_DIR/scripts
+AC_SUBST(XEN_SCRIPT_DIR)
+
+XEN_LOCK_DIR=/var/lock
+AC_SUBST(XEN_LOCK_DIR)
+
+XEN_RUN_DIR=/var/run/xen
+AC_SUBST(XEN_RUN_DIR)
+
+XEN_PAGING_DIR=/var/lib/xen/xenpaging
+AC_SUBST(XEN_PAGING_DIR)
+])
diff --git a/stubdom/Makefile b/stubdom/Makefile
index c41de27..ef99e3e 100644
--- a/stubdom/Makefile
+++ b/stubdom/Makefile
@@ -7,6 +7,7 @@ export stubdom=y
 export debug=y
 include $(XEN_ROOT)/Config.mk
 -include $(XEN_ROOT)/config/Stubdom.mk
+include $(XEN_ROOT)/config/Paths.mk
 
 GNU_TARGET_ARCH:=$(XEN_TARGET_ARCH)
 ifeq ($(XEN_TARGET_ARCH),x86_32)
diff --git a/tools/Rules.mk b/tools/Rules.mk
index 13d8fc1..423f2b1 100644
--- a/tools/Rules.mk
+++ b/tools/Rules.mk
@@ -5,6 +5,7 @@ all:
 
 -include $(XEN_ROOT)/config/Tools.mk
 include $(XEN_ROOT)/Config.mk
+include $(XEN_ROOT)/config/Paths.mk
 
 export _INSTALL := $(INSTALL)
 INSTALL = $(XEN_ROOT)/tools/cross-install
-- 
2.0.0.rc3.18.g00a5b79

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

* [PATCH v6 11/13] xencommons: move module list into a generic place
  2014-06-13  1:18 [PATCH v6 00/13] xen: add systemd support Luis R. Rodriguez
                   ` (9 preceding siblings ...)
  2014-06-13  1:18 ` [PATCH v6 10/13] autoconf: xen: move standard path variables to config/Paths.mk.in Luis R. Rodriguez
@ 2014-06-13  1:18 ` Luis R. Rodriguez
  2014-07-02 13:44   ` Ian Campbell
  2014-06-13  1:18 ` [PATCH v6 12/13] autoconf: xen: enable explicit preference option for xenstored preference Luis R. Rodriguez
                   ` (3 subsequent siblings)
  14 siblings, 1 reply; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-06-13  1:18 UTC (permalink / raw)
  To: xen-devel; +Cc: Luis R. Rodriguez

From: "Luis R. Rodriguez" <mcgrof@suse.com>

This will allows us to share the same module list with
sysemd, and lets us upkeep it in one place. Document this
while at it on the top level README and expand on the wiki:

http://wiki.xen.org/wiki/Category:Host_Configuration#Linux_kernel_modules

In order to upkeep parallelism builds be explicit about the
requirement to complete all actions before any installation
targets.

Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
---
 README                                             | 18 +++++++++++
 config/modules                                     | 16 ++++++++++
 tools/hotplug/Linux/Makefile                       | 36 +++++++++++++++++++---
 .../Linux/init.d/{xencommons => xencommons.in}     | 16 +---------
 4 files changed, 67 insertions(+), 19 deletions(-)
 create mode 100644 config/modules
 rename tools/hotplug/Linux/init.d/{xencommons => xencommons.in} (89%)

diff --git a/README b/README
index 9bbe734..34d7c0b 100644
--- a/README
+++ b/README
@@ -129,6 +129,24 @@ performed with root privileges.]
    versions of those scripts, so that you can copy the dist directory
    to another machine and install from that distribution.
 
+Required Linux modules
+======================
+
+Xen has a set of Linux modules which the init scripts ensure to load before
+enablement of xen guests. The list of modules are upkept in one place:
+
+  * config/modules
+
+The file supports a simple language, comments are ignored, and if you there
+are module replacements this can be listed by using a pipe to show preference
+for the first module, followed by the older module.
+
+We should strive to not require statically loading modules but it seems some
+systems have had issues with automatically loading some Linux kernel modules.
+For more details refer to:
+
+http://wiki.xen.org/wiki/Category:Host_Configuration#Linux_kernel_modules
+
 Python Runtime Libraries
 ========================
 
diff --git a/config/modules b/config/modules
new file mode 100644
index 0000000..525c60e
--- /dev/null
+++ b/config/modules
@@ -0,0 +1,16 @@
+xen-evtchn
+xen-gntdev
+xen-gntalloc
+xen-blkback
+xen-netback
+xen-pciback
+evtchn
+gntdev
+netbk
+blkbk
+xen-scsibk
+usbbk
+pciback
+xen-acpi-processor
+# Prefer to load blktap2 if found, otherwise load blktap
+blktap2|blktap
diff --git a/tools/hotplug/Linux/Makefile b/tools/hotplug/Linux/Makefile
index d5de9e6..90b0b0c 100644
--- a/tools/hotplug/Linux/Makefile
+++ b/tools/hotplug/Linux/Makefile
@@ -33,17 +33,45 @@ UDEV_RULES_DIR = $(CONFIG_DIR)/udev
 UDEV_RULES = xen-backend.rules $(UDEV_RULES-y)
 
 .PHONY: all
-all:
+all: $(XENCOMMONS_INITD)
+
+$(XENCOMMONS_INITD): $(XEN_ROOT)/config/modules $(XENCOMMONS_INITD).in
+	@set -e ;							\
+	IFS=''								;\
+	cat  $(XEN_ROOT)/config/modules	| (				\
+		while read l ; do					\
+			if echo $${l} | egrep -q "^#" ; then		\
+				continue				;\
+			fi						;\
+			if echo "$${l}" | egrep -q "\|" ; then		\
+				m1=$${l%%|*}				;\
+				m2=$${l#*|} 				;\
+				echo "        modprobe $$m1 2>/dev/null || modprobe $$m2 2>/dev/null" ;\
+			else						\
+				echo "        modprobe $$l 2>/dev/null"		;\
+			fi						;\
+		done							\
+	) > $(XENCOMMONS_INITD).modules					;\
+	cat  $(XENCOMMONS_INITD).in	| (				\
+		while read l ; do					\
+			if echo "$${l}" | egrep -q "@LOAD_MODULES@" ; then \
+				cat $(XENCOMMONS_INITD).modules 	;\
+			else						\
+				echo $$l				;\
+			fi						;\
+		done							\
+	) > $@
+	@rm -f $(XENCOMMONS_INITD).modules
 
 .PHONY: build
-build:
+build: all
 
 .PHONY: install
 install: all install-initd install-scripts install-udev
 
 # See docs/misc/distro_mapping.txt for INITD_DIR location
 .PHONY: install-initd
-install-initd:
+install-initd: all
 	[ -d $(DESTDIR)$(INITD_DIR) ] || $(INSTALL_DIR) $(DESTDIR)$(INITD_DIR)
 	[ -d $(DESTDIR)$(SYSCONFIG_DIR) ] || $(INSTALL_DIR) $(DESTDIR)$(SYSCONFIG_DIR)
 	[ -d $(DESTDIR)$(LIBEXEC) ] || $(INSTALL_DIR) $(DESTDIR)$(LIBEXEC)
@@ -55,7 +83,7 @@ install-initd:
 	$(INSTALL_PROG) init.d/xen-watchdog $(DESTDIR)$(INITD_DIR)
 
 .PHONY: install-scripts
-install-scripts:
+install-scripts: all
 	[ -d $(DESTDIR)$(XEN_SCRIPT_DIR) ] || \
 		$(INSTALL_DIR) $(DESTDIR)$(XEN_SCRIPT_DIR)
 	set -e; for i in $(XEN_SCRIPTS); \
diff --git a/tools/hotplug/Linux/init.d/xencommons b/tools/hotplug/Linux/init.d/xencommons.in
similarity index 89%
rename from tools/hotplug/Linux/init.d/xencommons
rename to tools/hotplug/Linux/init.d/xencommons.in
index 4ebd636..3939bcc 100644
--- a/tools/hotplug/Linux/init.d/xencommons
+++ b/tools/hotplug/Linux/init.d/xencommons.in
@@ -57,21 +57,7 @@ do_start () {
         local time=0
 	local timeout=30
 
-	modprobe xen-evtchn 2>/dev/null
-	modprobe xen-gntdev 2>/dev/null
-	modprobe xen-gntalloc 2>/dev/null
-	modprobe xen-blkback 2>/dev/null
-	modprobe xen-netback 2>/dev/null
-	modprobe xen-pciback 2>/dev/null
-	modprobe evtchn 2>/dev/null
-	modprobe gntdev 2>/dev/null
-	modprobe netbk 2>/dev/null
-	modprobe blkbk 2>/dev/null
-	modprobe xen-scsibk 2>/dev/null
-	modprobe usbbk 2>/dev/null
-	modprobe pciback 2>/dev/null
-	modprobe xen-acpi-processor 2>/dev/null
-	modprobe blktap2 2>/dev/null || modprobe blktap 2>/dev/null
+	@LOAD_MODULES@
 	mkdir -p /var/run/xen
 
 	if ! `${BINDIR}/xenstore-read -s / >/dev/null 2>&1`
-- 
2.0.0.rc3.18.g00a5b79

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

* [PATCH v6 12/13] autoconf: xen: enable explicit preference option for xenstored preference
  2014-06-13  1:18 [PATCH v6 00/13] xen: add systemd support Luis R. Rodriguez
                   ` (10 preceding siblings ...)
  2014-06-13  1:18 ` [PATCH v6 11/13] xencommons: move module list into a generic place Luis R. Rodriguez
@ 2014-06-13  1:18 ` Luis R. Rodriguez
  2014-07-02 13:54   ` Ian Campbell
  2014-06-13  1:18 ` [PATCH v6 13/13] systemd: add xen systemd service and module files Luis R. Rodriguez
                   ` (2 subsequent siblings)
  14 siblings, 1 reply; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-06-13  1:18 UTC (permalink / raw)
  To: xen-devel
  Cc: Keir Fraser, Ian Campbell, Tim Deegan, Luis R. Rodriguez,
	Ian Jackson, Jan Beulich

From: "Luis R. Rodriguez" <mcgrof@suse.com>

As it stands oxenstored will be used by default if ocaml tools are
found, the init system will also try to use oxenstored first if its
found otherwise the cxenstored will be used. Lets simplify the init
script and let users be explicit about the preference through configure.

This adds support to let you be explicit about the xenstored preference,
you can only use one of these two options:

./configure --with-xenstored=xenstored
./configure --with-xenstored=oxenstored

We continue with the old behaviour and default oxenstored will be used
but only if you have ocaml dependencies. Since the xenstored preference
is explicit now and since we require configure substitutions for it we
make use of the AX_XEN_EXPAND_CONFIG() helpers as otherwise substitution
for SBINDIR is not propagated from the top level configuration.

All this allows us to simplify the init script to use the configured
xenstore from the start. We update the sysconfig/default xencommons file
with the paths for the different options though, this can be used by
users to override the default xenstored, this follows the old behaviour
but we now just explicitly provide the full configured paths for users.

As before, changing the xenstore requires a reboot.

In order to help with documentation we update the README with some
details on configure usage refer to the wiki [0] [1] [2] for more elaborate
details.

Since we are now parsing an entry within Paths.mk.in on tools we let
the move the parsing of the file to be the tool's configure.

[0] http://wiki.xen.org/wiki/Xenstored
[1] http://wiki.xen.org/wiki/XenStore
[2] http://wiki.xen.org/wiki/XenStoreReference

Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Keir Fraser <keir@xen.org>
Cc: Tim Deegan <tim@xen.org>
Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
---

Please run autogen.sh after merging please.

 README                                             | 37 +++++++++++++
 m4/xenstored.m4                                    | 60 ++++++++++++++++++++++
 tools/configure.ac                                 | 19 +++++--
 ...ysconfig.xencommons => sysconfig.xencommons.in} | 13 ++++-
 .../init.d/{xencommons.in => xencommons.in.in}     |  8 +--
 5 files changed, 126 insertions(+), 11 deletions(-)
 create mode 100644 m4/xenstored.m4
 rename tools/hotplug/Linux/init.d/{sysconfig.xencommons => sysconfig.xencommons.in} (64%)
 rename tools/hotplug/Linux/init.d/{xencommons.in => xencommons.in.in} (92%)

diff --git a/README b/README
index 34d7c0b..eaf23e4 100644
--- a/README
+++ b/README
@@ -147,6 +147,43 @@ For more details refer to:
 
 http://wiki.xen.org/wiki/Category:Host_Configuration#Linux_kernel_modules
 
+xenstore: xenstored and oxenstored
+====================================
+
+Xen uses a configuration database called xenstore [0] to maintain configuration
+and status information shared between domains. A daemon is implemented as part
+of xenstore to act as an interface for access to the database for dom0 and
+guests. Two xenstored daemons are supported, one written in C which we refer
+to as the xenstored (sometimes referred to as cxenstored), and another written
+in Ocaml called oxenstored. Details for xenstore and the different
+implementations can be found on the wiki's xenstore reference guide [1] and
+the xenstored [2] page. You can choose which xenstore you want to enable as
+default on a system through configure:
+
+	./configure --with-xenstored=xenstored
+	./configure --with-xenstored=oxenstored
+
+By default oxenstored will be used if the ocaml development tools are found.
+If you enable oxenstored the xenstored will still be built and installed,
+the xenstored used can be changed through the configuration file:
+
+/etc/sysconfig/xencommons
+or
+/etc/default/xencommons
+
+This file has one relevant variables which is specific to the version of
+xenstored used:
+
+	* XENSTORED - specifies the full path of the xenstored binary
+
+You can change the preferred xenstored you want to use in the configuration
+but since we cannot stop the daemon a reboot will be required to make the
+change take effect.
+
+[0] http://wiki.xen.org/wiki/XenStore
+[1] http://wiki.xen.org/wiki/XenStoreReference
+[2] http://wiki.xen.org/wiki/Xenstored
+
 Python Runtime Libraries
 ========================
 
diff --git a/m4/xenstored.m4 b/m4/xenstored.m4
new file mode 100644
index 0000000..5a4d891
--- /dev/null
+++ b/m4/xenstored.m4
@@ -0,0 +1,60 @@
+AC_DEFUN([AX_XEN_OCAML_XENSTORE_CHECK], [
+	AS_IF([test "x$OCAMLC" = "xno" || test "x$OCAMLFIND" = "xno"], [
+		AC_MSG_ERROR([Missing ocaml dependencies for oxenstored, try installing ocaml ocaml-compiler-libs ocaml-runtime ocaml-findlib])
+	])
+])
+
+AC_DEFUN([AX_XEN_OCAML_XENSTORE_DEFAULTS], [
+	xenstore="oxenstored"
+	xenstored=$SBINDIR/oxenstored
+	AS_IF([test "x$OCAMLC" = "xno" || test "x$OCAMLFIND" = "xno"], [
+		xenstore="xenstored"
+		xenstored=$SBINDIR/xenstored
+	])
+])
+
+AC_DEFUN([AX_XENSTORE_OPTIONS], [
+AS_IF([test "x$XENSTORE" = "x"], [
+AC_ARG_WITH([xenstored],
+	AS_HELP_STRING([--with-xenstored@<:@=oxenstored|xenstored@:>@],
+		[This lets you choose which xenstore daemon you want, you have
+		two options: the original xenstored written in C (xenstored)
+		or the newer and robust one written in Ocaml (oxenstored).
+		The oxenstored daemon is the default but will but can only
+		be used if you have ocaml library / build dependencies solved,
+		if you have not specified a preference and do not have ocaml
+		dependencies resolved we'll enable the C xenstored for you. If
+		you ask for oxenstored we'll complain until you resolve those
+		dependencies]),
+	[
+		AS_IF([test "x$withval" = "xxenstored"], [
+			xenstore=$withval
+			xenstored=$SBINDIR/xenstored
+		])
+		AS_IF([test "x$withval" = "xoxenstored"], [
+			xenstore=$withval
+			xenstored=$SBINDIR/oxenstored
+			AX_XEN_OCAML_XENSTORE_CHECK()
+		])
+		AS_IF([test "x$withval" != "xoxenstored" && test "x$withval" != "xxenstored"], [
+			AC_MSG_ERROR([Unsupported xenstored specified, supported types: oxenstored xenstored])
+		])
+	],
+	[
+		AX_XEN_OCAML_XENSTORE_DEFAULTS()
+	])
+])
+])
+
+AC_DEFUN([AX_XENSTORE_SET], [
+	XENSTORE=$xenstore
+	AC_SUBST(XENSTORE)
+
+	AS_IF([test "x$XENSTORED" = "x"], [
+		XENSTORED=$xenstored
+	])
+	AC_SUBST(XENSTORED)
+
+	AS_IF([test "x$XENSTORE" != "xxenstored" && test "x$XENSTORE" != "xoxenstored"],
+		[AC_MSG_ERROR([Invalid xenstore: $XENSTORE])])
+])
diff --git a/tools/configure.ac b/tools/configure.ac
index 25d7ca3..0a29dbf 100644
--- a/tools/configure.ac
+++ b/tools/configure.ac
@@ -5,7 +5,11 @@ AC_PREREQ([2.67])
 AC_INIT([Xen Hypervisor Tools], m4_esyscmd([../version.sh ../xen/Makefile]),
     [xen-devel@lists.xen.org], [xen], [http://www.xen.org/])
 AC_CONFIG_SRCDIR([libxl/libxl.c])
-AC_CONFIG_FILES([../config/Tools.mk])
+AC_CONFIG_FILES([
+../config/Tools.mk
+hotplug/Linux/init.d/xencommons.in
+hotplug/Linux/init.d/sysconfig.xencommons
+])
 AC_CONFIG_HEADERS([config.h])
 AC_CONFIG_AUX_DIR([../])
 
@@ -47,6 +51,10 @@ m4_include([../m4/ptyfuncs.m4])
 m4_include([../m4/extfs.m4])
 m4_include([../m4/fetcher.m4])
 m4_include([../m4/ax_compare_version.m4])
+m4_include([../m4/paths.m4])
+m4_include([../m4/xenstored.m4])
+
+AX_XEN_EXPAND_CONFIG()
 
 # Enable/disable options
 AX_ARG_DEFAULT_DISABLE([githttp], [Download GIT repositories via HTTP])
@@ -159,9 +167,14 @@ AC_PROG_INSTALL
 AC_PATH_PROG([BISON], [bison])
 AC_PATH_PROG([FLEX], [flex])
 AX_PATH_PROG_OR_FAIL([PERL], [perl])
+
+AC_PROG_OCAML
+AC_PROG_FINDLIB
+
+AX_XENSTORE_OPTIONS
+AX_XENSTORE_SET
+
 AS_IF([test "x$ocamltools" = "xy"], [
-    AC_PROG_OCAML
-    AC_PROG_FINDLIB
     AS_IF([test "x$OCAMLC" = "xno" || test "x$OCAMLFIND" = "xno"], [
         AS_IF([test "x$enable_ocamltools" = "xyes"], [
             AC_MSG_ERROR([Ocaml tools enabled, but unable to find Ocaml])])
diff --git a/tools/hotplug/Linux/init.d/sysconfig.xencommons b/tools/hotplug/Linux/init.d/sysconfig.xencommons.in
similarity index 64%
rename from tools/hotplug/Linux/init.d/sysconfig.xencommons
rename to tools/hotplug/Linux/init.d/sysconfig.xencommons.in
index 25f7f00..d7d09ff 100644
--- a/tools/hotplug/Linux/init.d/sysconfig.xencommons
+++ b/tools/hotplug/Linux/init.d/sysconfig.xencommons.in
@@ -8,8 +8,17 @@
 ## Type: string
 ## Default: xenstored
 #
-# Select xenstored implementation
-#XENSTORED=[oxenstored|xenstored]
+# Select xenstore implementation, this can be either
+# of these below. If using systemd its preferred you
+# just edit the xenstored.service unit file and change
+# the XENSTORED variable there.
+#
+# This can be either of:
+#  * @SBINDIR@/oxenstored
+#  * @SBINDIR@/xenstored
+#
+# Changing this requires a reboot to take effect.
+#XENSTORED=@XENSTORED@
 
 ## Type: string
 ## Default: Not defined, tracing off
diff --git a/tools/hotplug/Linux/init.d/xencommons.in b/tools/hotplug/Linux/init.d/xencommons.in.in
similarity index 92%
rename from tools/hotplug/Linux/init.d/xencommons.in
rename to tools/hotplug/Linux/init.d/xencommons.in.in
index 3939bcc..b311bb8 100644
--- a/tools/hotplug/Linux/init.d/xencommons.in
+++ b/tools/hotplug/Linux/init.d/xencommons.in.in
@@ -18,6 +18,8 @@
 # Description:       Starts and stops the daemons neeeded for xl/xend
 ### END INIT INFO
 
+XENSTORED=@XENSTORED@
+
 . /etc/xen/scripts/hotplugpath.sh
 
 if [ -d /etc/sysconfig ]; then
@@ -69,12 +71,6 @@ do_start () {
 		if [ -n "$XENSTORED" ] ; then
 		    echo -n Starting $XENSTORED...
 		    $XENSTORED --pid-file /var/run/xenstored.pid $XENSTORED_ARGS
-		elif [ -x ${SBINDIR}/oxenstored ] ; then
-		    echo -n Starting oxenstored...
-		    ${SBINDIR}/oxenstored --pid-file /var/run/xenstored.pid $XENSTORED_ARGS
-		elif [ -x ${SBINDIR}/xenstored ] ; then
-		    echo -n Starting C xenstored...
-		    ${SBINDIR}/xenstored --pid-file /var/run/xenstored.pid $XENSTORED_ARGS
 		else
 		    echo "No xenstored found"
 		    exit 1
-- 
2.0.0.rc3.18.g00a5b79

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

* [PATCH v6 13/13] systemd: add xen systemd service and module files
  2014-06-13  1:18 [PATCH v6 00/13] xen: add systemd support Luis R. Rodriguez
                   ` (11 preceding siblings ...)
  2014-06-13  1:18 ` [PATCH v6 12/13] autoconf: xen: enable explicit preference option for xenstored preference Luis R. Rodriguez
@ 2014-06-13  1:18 ` Luis R. Rodriguez
  2014-06-13 19:55   ` Luis R. Rodriguez
                     ` (2 more replies)
  2014-06-19 19:03 ` [PATCH v6 00/13] xen: add systemd support Luis R. Rodriguez
  2014-07-02 14:48 ` Ian Campbell
  14 siblings, 3 replies; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-06-13  1:18 UTC (permalink / raw)
  To: xen-devel
  Cc: Ian Campbell, Stefano Stabellini, Luis R. Rodriguez,
	Jan Rękorajski, Ian Jackson, Jacek Konieczny, M A Young

From: "Luis R. Rodriguez" <mcgrof@suse.com>

This adds the systemd xen service / module files. All of this
is disabled for now, and won't install / build until we hook
up proper support for systemd into the build system.

This goes in with AX_AVAILABLE_SYSTEMD() which will enable
systemd if development libraries have been found on your
build system. If you don't have systemd on target systems
for binaries built with systemd then the binary will not
work, you must explicitly disable systemd support if you
do not want to build systemd support.

When systemd libraries are present only systems that
have booted into systemd go through the systemd initialization,
otherwise the legacy init is used.

These are originally based on the Fedora systemd files.

Changes made from Fedora's systemd files:

  * split sockets into two files to claim different permissions
  * Use /bin/sh -c exec to for a simple launcher implementation
  * enables systemd socket activation for C xenstored and Ocaml
    oxenstored
  * use sd_notify(), so change the service to Type=notify, because of
    this we remove the PIDFile specification as we don't care for it, and let
    systemd do its magic for us, this also means we don't have to fork
    so we use --no-fork with systemd
  * defines a modules-load.d, its original source file will be shared
    between systemd and old init systems
  * simplify service files with ConditionVirtualization=xen which uses
    the built in systemd virtualization backend detection, these
    service files will not be available to start on systems that do not
    boot with xen as a hypervisor
  * use autoconf to replace @variable@ paths for us which piggy
    backs on top of the latest autoconf changes to xen
  * removes oxenstored service file in favor of a system variable which
    controls which which xentored to use at run time, we avoid multiple
    service files this way.
  * simplifies startup to not require polling on the sockets
    as initial socket management is handled by systemd, we just
    take on the socket later once anything pokes at it, a simple nc -U
    (as root) on any of the sockets files can activate the service for example.
    Anything queued up will be sent to us once we start. Socket activation
    should in theory also let us dynamically switch between xenstores but more
    importantly we could upgrade xenstored while keeping all active
    socket communication queued up, but in order to take advantage of
    this we eventually would need to remove the requirement of not being
    able to bring down the xenstored. Even though active sockets are
    supported since most libxl communication doesn't triggger a check
    on the unix socket first administrators are encouraged to enable
    the xenstored.service to triggger an initialization of the xenstored
    upon bring up. Some systems also never use unix sockets for
    communication with the xenstored and as such active sockets will
    not be used there.
  * allow for xenstored configuration through *either* of these
    configuration files:
	- /etc/sysconfig/xenstored
	- /etc/default/xenstored
    The /etc/default/xenstored will let debian based systems do
    the same, while SUSE/OpenSUSE/Fedora/RedHat can keep on chugging
    with sysconfig. We leave these files all commented out by default
    though given that for systemd we want to encourage not using them.
  * ensures we create the run directory as most systems will likely
    be using a tmpfs for run dirs for the pid files
  * Some systems define the selinux context in the systemd Option for the
    /var/lib/xenstored tmpfs:
	Options=mode=755,context="system_u:object_r:xenstored_var_lib_t:s0"
    For the upstream version we remove that and let systems specify the
    context on their system /etc/default/xenstored or /etc/sysconfig/xenstored
    $XENSTORED_MOUNT_CTX variable, with a default to none.
  * takes advantage of the shared xendomains helper for the xendomains
    service
  * Add the new dom0 that gets kicked off for disk backend access into
    its own systemd service associated to xen

We end up with these systemd files:

General requirements:

  * proc-xen.mount
  * var-lib-xenstored.mount

xenstored:

  * xenstored.service
  * xenstored.socket
  * xenstored_ro.socket
  * xenconsoled.service
  * xen-qemu-dom0-disk-backend.service.in

Optional:

  * xendomains.service
  * xen-watchdog.service

As for integration with xen, we house keep all the systemd files
under a new directory tools/hotplug/Linux/systemd/ and will be targetted
by default when building on Linux systems if systemd enabled at
build time, which is only required on the build box, not the user
system.

The systemd files will be sanitized for meta @VARIABLES@ upon
configuration and installed upon the install target. Systems that
do not use systemd can still get systemd service unit files installed
if the build system enabled systemd support, this however does not
mandate a requirement of having systemd libraries present. Old init
scripts are always installed.

If you don't specify a prefix you will end up with the services
files under /usr/local/lib/systemd/system/ by default, and systemd
modules-load.d conf files under /usr/local/lib/modules-load.d/ which
systemd does look for (although it seems this is not documented).

Distributions are expected to provide their /usr/ prefix to end up in
the more generic location upon distribution install at
/usr/lib/systemd/system/ and /usr/lib/modules-load.d/ respectively.

Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Jan Rękorajski <baggins@pld-linux.org>
Cc: M A Young <m.a.young@durham.ac.uk>
Cc: Jacek Konieczny <jajcus@jajcus.net>
Cc: xen-devel@lists.xenproject.org
Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
---

Please run autogen.sh after merging please.

 .gitignore                                         |   5 +
 Makefile                                           |   6 +-
 README                                             |  22 ++++
 config/Tools.mk.in                                 |   6 +
 m4/README.source                                   |  10 ++
 m4/systemd.m4                                      | 123 +++++++++++++++++++++
 tools/configure.ac                                 |  11 ++
 tools/hotplug/Linux/Makefile                       |   8 +-
 tools/hotplug/Linux/systemd/Makefile               |  67 +++++++++++
 tools/hotplug/Linux/systemd/proc-xen.mount.in      |   9 ++
 .../Linux/systemd/var-lib-xenstored.mount.in       |  13 +++
 .../systemd/xen-qemu-dom0-disk-backend.service.in  |  22 ++++
 .../hotplug/Linux/systemd/xen-watchdog.service.in  |  13 +++
 tools/hotplug/Linux/systemd/xenconsoled.service.in |  20 ++++
 tools/hotplug/Linux/systemd/xendomains.service.in  |  16 +++
 tools/hotplug/Linux/systemd/xenstored.service.in   |  27 +++++
 tools/hotplug/Linux/systemd/xenstored.socket.in    |  11 ++
 tools/hotplug/Linux/systemd/xenstored_ro.socket.in |  11 ++
 tools/ocaml/xenstored/Makefile                     |   5 +
 tools/xenstore/Makefile                            |   6 +
 20 files changed, 407 insertions(+), 4 deletions(-)
 create mode 100644 m4/systemd.m4
 create mode 100644 tools/hotplug/Linux/systemd/Makefile
 create mode 100644 tools/hotplug/Linux/systemd/proc-xen.mount.in
 create mode 100644 tools/hotplug/Linux/systemd/var-lib-xenstored.mount.in
 create mode 100644 tools/hotplug/Linux/systemd/xen-qemu-dom0-disk-backend.service.in
 create mode 100644 tools/hotplug/Linux/systemd/xen-watchdog.service.in
 create mode 100644 tools/hotplug/Linux/systemd/xenconsoled.service.in
 create mode 100644 tools/hotplug/Linux/systemd/xendomains.service.in
 create mode 100644 tools/hotplug/Linux/systemd/xenstored.service.in
 create mode 100644 tools/hotplug/Linux/systemd/xenstored.socket.in
 create mode 100644 tools/hotplug/Linux/systemd/xenstored_ro.socket.in

diff --git a/.gitignore b/.gitignore
index 588a76d..af7218e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -389,3 +389,8 @@ tools/xenstore/xenstore-watch
 docs/txt/misc/*.txt
 docs/txt/man/*.txt
 docs/figs/*.png
+
+tools/hotplug/Linux/systemd/*.conf
+tools/hotplug/Linux/systemd/*.mount
+tools/hotplug/Linux/systemd/*.socket
+tools/hotplug/Linux/systemd/*.service
diff --git a/Makefile b/Makefile
index 41dabbf..104e39d 100644
--- a/Makefile
+++ b/Makefile
@@ -216,8 +216,12 @@ uninstall:
 	rm -f  $(D)$(CONFIG_DIR)/udev/rules.d/xen-backend.rules
 	rm -f  $(D)$(CONFIG_DIR)/udev/rules.d/xend.rules
 	rm -f  $(D)$(SYSCONFIG_DIR)/xendomains
+	rm -f  $(D)$(SBINDIR)/xendomains
 	rm -f  $(D)$(SYSCONFIG_DIR)/xencommons
-	rm -rf $(D)/var/run/xen* $(D)/var/lib/xen*
+	rm -f  $(D)$(XEN_SYSTEMD_DIR)/*.service
+	rm -f  $(D)$(XEN_SYSTEMD_DIR)/*.mount
+	rm -f  $(D)$(XEN_SYSTEMD_MODULES_LOAD)/*.conf
+	rm -rf $(D)${XEN_RUN_DIR}* $(D)/var/lib/xen*
 	make -C tools uninstall
 	rm -rf $(D)/boot/tboot*
 
diff --git a/README b/README
index eaf23e4..5374c78 100644
--- a/README
+++ b/README
@@ -72,6 +72,7 @@ disabled at compile time:
     * cmake (if building vtpm stub domains)
     * markdown
     * figlet (for generating the traditional Xen start of day banner)
+    * systemd daemon development files
 
 Second, you need to acquire a suitable kernel for use in domain 0. If
 possible you should use a kernel provided by your OS distributor. If
@@ -184,6 +185,27 @@ change take effect.
 [1] http://wiki.xen.org/wiki/XenStoreReference
 [2] http://wiki.xen.org/wiki/Xenstored
 
+Systemd and legacy init support
+===============================
+
+If you have systemd development packages installed you can build binaries
+with systemd support. Systemd support is enabled by default if you have
+systemd development libraries present. Binaries built with systemd supprot
+will require systemd libraries to be present on the host system, however
+systemd initialization will only occur if the system booted with systemd as its
+init. If systemd was not the init the legacy initialization will be used.
+Systemd is enabled by default if you have systemd development libraries
+present however if you want to force enable systemd to ensure you build
+binaries with systemd support you can use --enable-systemd flag. Likewise
+if you want to force disable systemd you can use either of these two options:
+
+	./configure --disable-systemd
+	./configure --enable-systemd=no
+
+For more details refer to the xen xenstored systemd wiki page [3].
+
+[3] http://wiki.xen.org/wiki/Xenstored#xenstored_systemd_support
+
 Python Runtime Libraries
 ========================
 
diff --git a/config/Tools.mk.in b/config/Tools.mk.in
index 84b2612..fbaf11e 100644
--- a/config/Tools.mk.in
+++ b/config/Tools.mk.in
@@ -57,6 +57,12 @@ CONFIG_BLKTAP1      := @blktap1@
 CONFIG_VTPM         := @vtpm@
 CONFIG_QEMUU_EXTRA_ARGS:= @EXTRA_QEMUU_CONFIGURE_ARGS@
 
+CONFIG_SYSTEMD      := @systemd@
+SYSTEMD_CFLAGS      := @SYSTEMD_CFLAGS@
+SYSTEMD_LIBS        := @SYSTEMD_LIBS@
+XEN_SYSTEMD_DIR     := @SYSTEMD_DIR@
+XEN_SYSTEMD_MODULES_LOAD := @SYSTEMD_MODULES_LOAD@
+
 #System options
 ZLIB                := @zlib@
 CONFIG_LIBICONV     := @libiconv@
diff --git a/m4/README.source b/m4/README.source
index 76f7c5a..8805b8e 100644
--- a/m4/README.source
+++ b/m4/README.source
@@ -26,3 +26,13 @@ Date:   Mon Feb 3 15:59:18 2014 -0800
     With the newly added glib.mk, some of the noinst_* variables need to use
     += in the evaluation to avoid multiple definition warnings from
     automake.
+
+systemd.m4
+==========
+
+systemd.m4 was contributed to by Luis R. Rodriguez <mcgrof@do-not-panic.com>,
+its current home project can be found at:
+
+https://github.com/mcgrof/funk-systemd
+
+There is a plan to upstream this library somehow to systemd.
diff --git a/m4/systemd.m4 b/m4/systemd.m4
new file mode 100644
index 0000000..182a56a
--- /dev/null
+++ b/m4/systemd.m4
@@ -0,0 +1,123 @@
+# systemd.m4 - Macros to check for and enable systemd          -*- Autoconf -*-
+#
+# Copyright (C) 2014 Luis R. Rodriguez <mcgrof@suse.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+dnl Some optional path options
+AC_DEFUN([AX_SYSTEMD_OPTIONS], [
+	AC_ARG_WITH(systemd, [  --with-systemd          set directory for systemd service files],
+		SYSTEMD_DIR="$withval", SYSTEMD_DIR="")
+	AC_SUBST(SYSTEMD_DIR)
+
+	AC_ARG_WITH(systemd, [  --with-systemd-modules-load          set directory for systemd modules load files],
+		SYSTEMD_MODULES_LOAD="$withval", SYSTEMD_MODULES_LOAD="")
+	AC_SUBST(SYSTEMD_MODULES_LOAD)
+])
+
+AC_DEFUN([AX_ENABLE_SYSTEMD_OPTS], [
+	AX_ARG_DEFAULT_ENABLE([systemd], [Disable systemd support])
+	AX_SYSTEMD_OPTIONS()
+])
+
+AC_DEFUN([AX_ALLOW_SYSTEMD_OPTS], [
+	AX_ARG_DEFAULT_DISABLE([systemd], [Enable systemd support])
+	AX_SYSTEMD_OPTIONS()
+])
+
+AC_DEFUN([AX_CHECK_SYSTEMD_LIBS], [
+	AC_CHECK_HEADER([systemd/sd-daemon.h], [
+	    AC_CHECK_LIB([systemd-daemon], [sd_listen_fds], [libsystemddaemon="y"])
+	])
+	AS_IF([test "x$libsystemddaemon" = x], [
+	    AC_MSG_ERROR([Unable to find a suitable libsystemd-daemon library])
+	])
+
+	PKG_CHECK_MODULES([SYSTEMD], [libsystemd-daemon])
+	dnl pkg-config older than 0.24 does not set these for
+	dnl PKG_CHECK_MODULES() worth also noting is that as of version 208
+	dnl of systemd pkg-config --cflags currently yields no extra flags yet.
+	AC_SUBST([SYSTEMD_CFLAGS])
+	AC_SUBST([SYSTEMD_LIBS])
+
+	AS_IF([test "x$SYSTEMD_DIR" = x], [
+	    dnl In order to use the line below we need to fix upstream systemd
+	    dnl to properly ${prefix} for child variables in
+	    dnl src/core/systemd.pc.in but this is a bit complex at the
+	    dnl moment as they depend on another rootprefix, which can vary
+	    dnl from prefix in practice. We provide our own definition as we
+	    dnl *know* where systemd will dump this to, but this does limit
+	    dnl us to stick to a non custom systemdsystemunitdir, dnl to work
+	    dnl around this we provide the additional configure option
+	    dnl --with-systemd where you can specify the directory for the unit
+	    dnl files. It would also be best to just extend the upstream
+	    dnl pkg-config  pkg.m4 with an AC_DEFUN() to do this neatly.
+	    dnl SYSTEMD_DIR="`$PKG_CONFIG --define-variable=prefix=$PREFIX --variable=systemdsystemunitdir systemd`"
+	    SYSTEMD_DIR="\$(prefix)/lib/systemd/system/"
+	], [])
+
+	AS_IF([test "x$SYSTEMD_DIR" = x], [
+	    AC_MSG_ERROR([SYSTEMD_DIR is unset])
+	], [])
+
+	dnl There is no variable for this yet for some reason
+	AS_IF([test "x$SYSTEMD_MODULES_LOAD" = x], [
+	    SYSTEMD_MODULES_LOAD="\$(prefix)/lib/modules-load.d/"
+	], [])
+
+	AS_IF([test "x$SYSTEMD_MODULES_LOAD" = x], [
+	    AC_MSG_ERROR([SYSTEMD_MODULES_LOAD is unset])
+	], [])
+])
+
+AC_DEFUN([AX_CHECK_SYSTEMD], [
+	dnl Respect user override to disable
+	AS_IF([test "x$enable_systemd" != "xno"], [
+	     AS_IF([test "x$systemd" = "xy" ], [
+		AC_DEFINE([HAVE_SYSTEMD], [1], [Systemd available and enabled])
+			systemd=y
+			AX_CHECK_SYSTEMD_LIBS()
+	    ],[systemd=n])
+	],[systemd=n])
+])
+
+AC_DEFUN([AX_CHECK_SYSTEMD_ENABLE_AVAILABLE], [
+	AC_CHECK_HEADER([systemd/sd-daemon.h], [
+	    AC_CHECK_LIB([systemd-daemon], [sd_listen_fds], [systemd="y"])
+	])
+])
+
+dnl Enables systemd by default and requires a --disable-systemd option flag
+dnl to configure if you want to disable.
+AC_DEFUN([AX_ENABLE_SYSTEMD], [
+	AX_ENABLE_SYSTEMD_OPTS()
+	AX_CHECK_SYSTEMD()
+])
+
+dnl Systemd will be disabled by default and requires you to run configure with
+dnl --enable-systemd to look for and enable systemd.
+AC_DEFUN([AX_ALLOW_SYSTEMD], [
+	AX_ALLOW_SYSTEMD_OPTS()
+	AX_CHECK_SYSTEMD()
+])
+
+dnl Systemd will be disabled by default but if your build system is detected
+dnl to have systemd build libraries it will be enabled. You can always force
+dnl disable with --disable-systemd
+AC_DEFUN([AX_AVAILABLE_SYSTEMD], [
+	AX_ALLOW_SYSTEMD_OPTS()
+	AX_CHECK_SYSTEMD_ENABLE_AVAILABLE()
+	AX_CHECK_SYSTEMD()
+])
diff --git a/tools/configure.ac b/tools/configure.ac
index 0a29dbf..4839993 100644
--- a/tools/configure.ac
+++ b/tools/configure.ac
@@ -9,6 +9,15 @@ AC_CONFIG_FILES([
 ../config/Tools.mk
 hotplug/Linux/init.d/xencommons.in
 hotplug/Linux/init.d/sysconfig.xencommons
+hotplug/Linux/systemd/proc-xen.mount
+hotplug/Linux/systemd/var-lib-xenstored.mount
+hotplug/Linux/systemd/xenstored.socket
+hotplug/Linux/systemd/xenstored_ro.socket
+hotplug/Linux/systemd/xenstored.service
+hotplug/Linux/systemd/xenconsoled.service
+hotplug/Linux/systemd/xen-qemu-dom0-disk-backend.service
+hotplug/Linux/systemd/xendomains.service
+hotplug/Linux/systemd/xen-watchdog.service
 ])
 AC_CONFIG_HEADERS([config.h])
 AC_CONFIG_AUX_DIR([../])
@@ -53,6 +62,7 @@ m4_include([../m4/fetcher.m4])
 m4_include([../m4/ax_compare_version.m4])
 m4_include([../m4/paths.m4])
 m4_include([../m4/xenstored.m4])
+m4_include([../m4/systemd.m4])
 
 AX_XEN_EXPAND_CONFIG()
 
@@ -260,5 +270,6 @@ esac
 # Checks for header files.
 AC_CHECK_HEADERS([yajl/yajl_version.h sys/eventfd.h])
 
+AX_AVAILABLE_SYSTEMD()
 AC_OUTPUT()
 
diff --git a/tools/hotplug/Linux/Makefile b/tools/hotplug/Linux/Makefile
index 90b0b0c..7d8af99 100644
--- a/tools/hotplug/Linux/Makefile
+++ b/tools/hotplug/Linux/Makefile
@@ -25,6 +25,8 @@ XEN_SCRIPTS += vscsi
 XEN_SCRIPTS += block-iscsi
 XEN_SCRIPTS += $(XEN_SCRIPTS-y)
 
+SUBDIRS-$(CONFIG_SYSTEMD) += systemd
+
 XEN_SCRIPT_DATA = xen-script-common.sh locking.sh logging.sh
 XEN_SCRIPT_DATA += xen-hotplug-common.sh xen-network-common.sh vif-common.sh
 XEN_SCRIPT_DATA += block-common.sh
@@ -33,7 +35,7 @@ UDEV_RULES_DIR = $(CONFIG_DIR)/udev
 UDEV_RULES = xen-backend.rules $(UDEV_RULES-y)
 
 .PHONY: all
-all: $(XENCOMMONS_INITD)
+all: $(XENCOMMONS_INITD) subdirs-all
 
 $(XENCOMMONS_INITD): $(XEN_ROOT)/config/modules $(XENCOMMONS_INITD).in
 	@set -e ;							\
@@ -67,7 +69,7 @@ $(XENCOMMONS_INITD): $(XEN_ROOT)/config/modules $(XENCOMMONS_INITD).in
 build: all
 
 .PHONY: install
-install: all install-initd install-scripts install-udev
+install: all install-initd install-scripts install-udev subdirs-install
 
 # See docs/misc/distro_mapping.txt for INITD_DIR location
 .PHONY: install-initd
@@ -105,4 +107,4 @@ install-udev:
 	done
 
 .PHONY: clean
-clean:
+clean: subdirs-clean
diff --git a/tools/hotplug/Linux/systemd/Makefile b/tools/hotplug/Linux/systemd/Makefile
new file mode 100644
index 0000000..14daac9
--- /dev/null
+++ b/tools/hotplug/Linux/systemd/Makefile
@@ -0,0 +1,67 @@
+XEN_ROOT = $(CURDIR)/../../../..
+include $(XEN_ROOT)/tools/Rules.mk
+
+XEN_SYSTEMD_MODULES = xen.conf
+
+XEN_SYSTEMD_MOUNT =  proc-xen.mount
+XEN_SYSTEMD_MOUNT += var-lib-xenstored.mount
+
+XEN_SYSTEMD_SOCKET  = xenstored.socket
+XEN_SYSTEMD_SOCKET += xenstored_ro.socket
+
+XEN_SYSTEMD_SERVICE  = xenstored.service
+XEN_SYSTEMD_SERVICE += xenconsoled.service
+XEN_SYSTEMD_SERVICE += xen-qemu-dom0-disk-backend.service
+XEN_SYSTEMD_SERVICE += xendomains.service
+XEN_SYSTEMD_SERVICE += xen-watchdog.service
+
+ALL_XEN_SYSTEMD =	$(XEN_SYSTEMD_MODULES)  \
+			$(XEN_SYSTEMD_MOUNT)	\
+			$(XEN_SYSTEMD_SOCKET)	\
+			$(XEN_SYSTEMD_SERVICE)
+
+.PHONY: all
+all:	$(ALL_XEN_SYSTEMD)
+
+.PHONY: clean
+clean:
+
+.PHONY: install
+install: $(ALL_XEN_SYSTEMD)
+	[ -d $(DESTDIR)$(XEN_SYSTEMD_DIR) ] || \
+		$(INSTALL_DIR) $(DESTDIR)$(XEN_SYSTEMD_DIR)
+	[ -d $(DESTDIR)$(XEN_SYSTEMD_MODULES_LOAD) ] || \
+		$(INSTALL_DIR) $(DESTDIR)$(XEN_SYSTEMD_MODULES_LOAD)
+	$(INSTALL_DATA) *.socket $(DESTDIR)$(XEN_SYSTEMD_DIR)
+	$(INSTALL_DATA) *.service $(DESTDIR)$(XEN_SYSTEMD_DIR)
+	$(INSTALL_DATA) *.mount $(DESTDIR)$(XEN_SYSTEMD_DIR)
+	$(INSTALL_DATA) *.conf $(DESTDIR)$(XEN_SYSTEMD_MODULES_LOAD)
+
+$(XEN_SYSTEMD_MODULES): $(XEN_ROOT)/config/modules
+	@set -e ;							\
+	IFS=''								;\
+	cat  $(XEN_ROOT)/config/modules	| (				\
+		while read l ; do					\
+			if echo $${l} | egrep -q "^#" ; then		\
+				continue				;\
+			fi						;\
+			if echo "$${l}" | egrep -q "\|" ; then		\
+				m1=$${l%%|*}				;\
+				m2=$${l#*|} 				;\
+				# Systemd modules-load.d lacks support	;\
+				# for module replacement options, we	;\
+				# need to add that support upstream but ;\
+				# its best instead to ensure this file	;\
+				# is no longer needed. Some folks	;\
+				# however have reported issues with	;\
+				# some modules automatically loading	;\
+				# so we just load all necessary xen	;\
+				# modules and for replacements we load	;\
+				# the latest module			;\
+				echo "$$m1" ;\
+				echo "$$m2" ;\
+			else						\
+				echo "$$l"				;\
+			fi						;\
+		done							\
+	) > $@
diff --git a/tools/hotplug/Linux/systemd/proc-xen.mount.in b/tools/hotplug/Linux/systemd/proc-xen.mount.in
new file mode 100644
index 0000000..f0c4f3a
--- /dev/null
+++ b/tools/hotplug/Linux/systemd/proc-xen.mount.in
@@ -0,0 +1,9 @@
+[Unit]
+Description=Mount /proc/xen files
+ConditionVirtualization=xen
+RefuseManualStop=true
+
+[Mount]
+What=xenfs
+Where=/proc/xen
+Type=xenfs
diff --git a/tools/hotplug/Linux/systemd/var-lib-xenstored.mount.in b/tools/hotplug/Linux/systemd/var-lib-xenstored.mount.in
new file mode 100644
index 0000000..44dfce8
--- /dev/null
+++ b/tools/hotplug/Linux/systemd/var-lib-xenstored.mount.in
@@ -0,0 +1,13 @@
+[Unit]
+Description=mount xenstore file system
+ConditionVirtualization=xen
+RefuseManualStop=true
+
+[Mount]
+Environment=XENSTORED_MOUNT_CTX=none
+EnvironmentFile=-/etc/sysconfig/xenstored
+EnvironmentFile=-/etc/default/xenstored
+What=xenstore
+Where=@XEN_LIB_STORED@
+Type=tmpfs
+Options=mode=755,context="$XENSTORED_MOUNT_CTX"
diff --git a/tools/hotplug/Linux/systemd/xen-qemu-dom0-disk-backend.service.in b/tools/hotplug/Linux/systemd/xen-qemu-dom0-disk-backend.service.in
new file mode 100644
index 0000000..8dbd110
--- /dev/null
+++ b/tools/hotplug/Linux/systemd/xen-qemu-dom0-disk-backend.service.in
@@ -0,0 +1,22 @@
+[Unit]
+Description=qemu for xen dom0 disk backend
+Requires=proc-xen.mount var-lib-xenstored.mount xenstored.socket
+After=xenstored.service xenconsoled.service
+Before=xendomains.service libvirtd.service libvirt-guests.service
+RefuseManualStop=true
+ConditionVirtualization=xen
+
+[Service]
+Type=simple
+EnvironmentFile=-/etc/default/xenstored
+EnvironmentFile=-/etc/sysconfig/xenstored
+PIDFile=@XEN_RUN_DIR@/qemu-dom0.pid
+ExecStartPre=/bin/grep -q control_d /proc/xen/capabilities
+ExecStartPre=/bin/mkdir -p /var/run/xen
+ExecStart=@LIBEXEC@/qemu-system-i386 -xen-domid 0 \
+	-xen-attach -name dom0 -nographic -M xenpv -daemonize \
+	-monitor /dev/null -serial /dev/null -parallel /dev/null \
+	-pidfile @XEN_RUN_DIR@/qemu-dom0.pid
+
+[Install]
+WantedBy=multi-user.target
diff --git a/tools/hotplug/Linux/systemd/xen-watchdog.service.in b/tools/hotplug/Linux/systemd/xen-watchdog.service.in
new file mode 100644
index 0000000..acb2b77
--- /dev/null
+++ b/tools/hotplug/Linux/systemd/xen-watchdog.service.in
@@ -0,0 +1,13 @@
+[Unit]
+Description=Xen-watchdog - run xen watchdog daemon
+Requires=proc-xen.mount
+After=proc-xen.mount xendomains.service
+ConditionVirtualization=xen
+
+[Service]
+Type=forking
+ExecStart=@SBINDIR@/xenwatchdogd 30 15
+KillSignal=USR1
+
+[Install]
+WantedBy=multi-user.target
diff --git a/tools/hotplug/Linux/systemd/xenconsoled.service.in b/tools/hotplug/Linux/systemd/xenconsoled.service.in
new file mode 100644
index 0000000..15fad35
--- /dev/null
+++ b/tools/hotplug/Linux/systemd/xenconsoled.service.in
@@ -0,0 +1,20 @@
+[Unit]
+Description=Xenconsoled - handles logging from guest consoles and hypervisor
+Requires=xenstored.socket
+After=xenstored.service
+ConditionVirtualization=xen
+
+[Service]
+Type=simple
+Environment=XENCONSOLED_ARGS=
+Environment=XENCONSOLED_LOG=none
+Environment=XENCONSOLED_LOG_DIR=@XEN_LOG_DIR@/console
+EnvironmentFile=-/etc/default/xenconsoled
+EnvironmentFile=-/etc/sysconfig/xenconsoled
+PIDFile=@XEN_RUN_DIR@/xenconsoled.pid
+ExecStartPre=/bin/grep -q control_d /proc/xen/capabilities
+ExecStartPre=/bin/mkdir -p ${XENCONSOLED_LOG_DIR}
+ExecStart=@SBINDIR@/xenconsoled --pid-file @XEN_RUN_DIR@/xenconsoled.pid --log=${XENCONSOLED_LOG} --log-dir=${XENCONSOLED_LOG_DIR} $XENCONSOLED_ARGS
+
+[Install]
+WantedBy=multi-user.target
diff --git a/tools/hotplug/Linux/systemd/xendomains.service.in b/tools/hotplug/Linux/systemd/xendomains.service.in
new file mode 100644
index 0000000..70ce7c0
--- /dev/null
+++ b/tools/hotplug/Linux/systemd/xendomains.service.in
@@ -0,0 +1,16 @@
+[Unit]
+Description=Xendomains - start and stop guests on boot and shutdown
+Requires=xenstored.socket
+After=xenstored.service xenconsoled.service
+ConditionVirtualization=xen
+
+[Service]
+Type=oneshot
+RemainAfterExit=true
+ExecStartPre=/bin/grep -q control_d /proc/xen/capabilities
+ExecStart=-@LIBEXEC@/xendomains start
+ExecStop=@LIBEXEC@/xendomains stop
+ExecReload=@LIBEXEC@/xendomains restart
+
+[Install]
+WantedBy=multi-user.target
diff --git a/tools/hotplug/Linux/systemd/xenstored.service.in b/tools/hotplug/Linux/systemd/xenstored.service.in
new file mode 100644
index 0000000..4a9fcee
--- /dev/null
+++ b/tools/hotplug/Linux/systemd/xenstored.service.in
@@ -0,0 +1,27 @@
+[Unit]
+Description=The Xen xenstore
+Requires=xenstored_ro.socket xenstored.socket proc-xen.mount var-lib-xenstored.mount
+After=proc-xen.mount var-lib-xenstored.mount
+Before=libvirtd.service libvirt-guests.service
+RefuseManualStop=true
+ConditionVirtualization=xen
+
+[Service]
+Type=notify
+Environment=XENSTORED_ARGS=
+Environment=XENSTORED_ROOTDIR=@XEN_LIB_STORED@
+Environment=XENSTORED=@XENSTORED@
+EnvironmentFile=-/etc/default/xencommons
+EnvironmentFile=-/etc/sysconfig/xencommons
+ExecStartPre=/bin/grep -q control_d /proc/xen/capabilities
+ExecStartPre=-/bin/rm -f @XEN_LIB_STORED@/tdb*
+ExecStartPre=/bin/mkdir -p @XEN_RUN_DIR@
+ExecStart=/bin/sh -c "exec $XENSTORED --no-fork $XENSTORED_ARGS"
+ExecStartPost=-@BINDIR@/xenstore-write "/local/domain/0/name" "Domain-0"
+ExecStartPost=-@BINDIR@/xenstore-write "/local/domain/0/domid" 0
+
+[Install]
+WantedBy=multi-user.target
+Also=xenstored_ro.socket xenstored.socket
+Also=proc-xen.mount
+Also=var-lib-xenstored.mount
diff --git a/tools/hotplug/Linux/systemd/xenstored.socket.in b/tools/hotplug/Linux/systemd/xenstored.socket.in
new file mode 100644
index 0000000..461e4f4
--- /dev/null
+++ b/tools/hotplug/Linux/systemd/xenstored.socket.in
@@ -0,0 +1,11 @@
+[Unit]
+Description=xenstore socket
+ConditionVirtualization=xen
+
+[Socket]
+ListenStream=/var/run/xenstored/socket
+SocketMode=0600
+Service=xenstored.service
+
+[Install]
+WantedBy=sockets.target
diff --git a/tools/hotplug/Linux/systemd/xenstored_ro.socket.in b/tools/hotplug/Linux/systemd/xenstored_ro.socket.in
new file mode 100644
index 0000000..6ab5c28
--- /dev/null
+++ b/tools/hotplug/Linux/systemd/xenstored_ro.socket.in
@@ -0,0 +1,11 @@
+[Unit]
+Description=xenstore ro socket
+ConditionVirtualization=xen
+
+[Socket]
+ListenStream=/var/run/xenstored/socket_ro
+SocketMode=0660
+Service=xenstored.service
+
+[Install]
+WantedBy=sockets.target
diff --git a/tools/ocaml/xenstored/Makefile b/tools/ocaml/xenstored/Makefile
index 382a813..068e04a 100644
--- a/tools/ocaml/xenstored/Makefile
+++ b/tools/ocaml/xenstored/Makefile
@@ -3,6 +3,11 @@ OCAML_TOPLEVEL = $(CURDIR)/..
 include $(OCAML_TOPLEVEL)/common.make
 
 CFLAGS += -I$(XEN_ROOT)/tools/
+CFLAGS-$(CONFIG_SYSTEMD)  += $(SYSTEMD_CFLAGS)
+LDFLAGS-$(CONFIG_SYSTEMD) += $(SYSTEMD_LIBS)
+
+CFLAGS  += $(CFLAGS-y)
+LDFLAGS += $(LDFLAGS-y)
 
 OCAMLINCLUDE += \
 	-I $(OCAML_TOPLEVEL)/libs/xb \
diff --git a/tools/xenstore/Makefile b/tools/xenstore/Makefile
index 55ca7a3..2adb153 100644
--- a/tools/xenstore/Makefile
+++ b/tools/xenstore/Makefile
@@ -9,6 +9,12 @@ CFLAGS += -I.
 CFLAGS += -I$(XEN_ROOT)/tools/
 CFLAGS += $(CFLAGS_libxenctrl)
 
+CFLAGS-$(CONFIG_SYSTEMD)  += $(SYSTEMD_CFLAGS)
+LDFLAGS-$(CONFIG_SYSTEMD) += $(SYSTEMD_LIBS)
+
+CFLAGS  += $(CFLAGS-y)
+LDFLAGS += $(LDFLAGS-y)
+
 CLIENTS := xenstore-exists xenstore-list xenstore-read xenstore-rm xenstore-chmod
 CLIENTS += xenstore-write xenstore-ls xenstore-watch
 
-- 
2.0.0.rc3.18.g00a5b79


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

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

* Re: [PATCH v6 07/13] tools/xendomains: move to libexec and use a smaller init helper
  2014-06-13  1:18 ` [PATCH v6 07/13] tools/xendomains: move to libexec and use a smaller init helper Luis R. Rodriguez
@ 2014-06-13  7:06   ` Jacek Konieczny
  2014-06-13 18:32     ` Luis R. Rodriguez
  2014-07-02 13:12   ` Ian Campbell
  1 sibling, 1 reply; 66+ messages in thread
From: Jacek Konieczny @ 2014-06-13  7:06 UTC (permalink / raw)
  To: Luis R. Rodriguez, xen-devel
  Cc: Ian Campbell, Stefano Stabellini, Luis R. Rodriguez,
	Jan Rękorajski, Ian Jackson, M A Young

On 06/13/14 03:18, Luis R. Rodriguez wrote:
> From: "Luis R. Rodriguez" <mcgrof@suse.com>
> 
> The xendomains script can be reused with systemd systems as it
> does not control services or sockets per se

It is not quite true. 'xl create' starts a background 'xl' process.

Ideally each of those would be handled by a separate systemd unit
(I have such setup on my xen based system), but I am not sure it can be
easily integrated into the standard xen distribution. So, maybe, reusing
xendomain this way is good enough.

Greets,
	Jacek

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

* Re: [PATCH v6 07/13] tools/xendomains: move to libexec and use a smaller init helper
  2014-06-13  7:06   ` Jacek Konieczny
@ 2014-06-13 18:32     ` Luis R. Rodriguez
  0 siblings, 0 replies; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-06-13 18:32 UTC (permalink / raw)
  To: Jacek Konieczny
  Cc: Ian Campbell, Stefano Stabellini, Jan Rękorajski,
	Ian Jackson, M A Young, xen-devel, Luis R. Rodriguez

On Fri, Jun 13, 2014 at 09:06:12AM +0200, Jacek Konieczny wrote:
> On 06/13/14 03:18, Luis R. Rodriguez wrote:
> > From: "Luis R. Rodriguez" <mcgrof@suse.com>
> > 
> > The xendomains script can be reused with systemd systems as it
> > does not control services or sockets per se
> 
> It is not quite true. 'xl create' starts a background 'xl' process.
> 
> Ideally each of those would be handled by a separate systemd unit
> (I have such setup on my xen based system), but I am not sure it can be
> easily integrated into the standard xen distribution.

We won't know until its tried upstream. Patches welcomed.

> So, maybe, reusing xendomain this way is good enough.

Yeah well we have to start somewhere, we should look a this
as an evolutionairy process.

  Luis

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

* Re: [PATCH v6 13/13] systemd: add xen systemd service and module files
  2014-06-13  1:18 ` [PATCH v6 13/13] systemd: add xen systemd service and module files Luis R. Rodriguez
@ 2014-06-13 19:55   ` Luis R. Rodriguez
  2014-06-19 19:47   ` Bastian Blank
  2014-07-02 14:02   ` Ian Campbell
  2 siblings, 0 replies; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-06-13 19:55 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: Ian Campbell, Stefano Stabellini, Jan Rękorajski,
	Ian Jackson, Jacek Konieczny, M A Young, xen-devel

On Thu, Jun 12, 2014 at 06:18:51PM -0700, Luis R. Rodriguez wrote:
> From: "Luis R. Rodriguez" <mcgrof@suse.com>
> 
> This adds the systemd xen service / module files.

this is correct

> All of this
> is disabled for now, and won't install / build until we hook
> up proper support for systemd into the build system.

Actually this description is wrong and I forgot to remove,
let me know if you can amed yourself if all else goes smooth.
This patch also contains the autoconf integration, I think I
had folded them due to review but I forget now why. If we do
want to split up the autoconf stuff as the last step I can
break this patch in two and resend.

  Luis

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

* Re: [PATCH v6 00/13] xen: add systemd support
  2014-06-13  1:18 [PATCH v6 00/13] xen: add systemd support Luis R. Rodriguez
                   ` (12 preceding siblings ...)
  2014-06-13  1:18 ` [PATCH v6 13/13] systemd: add xen systemd service and module files Luis R. Rodriguez
@ 2014-06-19 19:03 ` Luis R. Rodriguez
  2014-07-02 14:48 ` Ian Campbell
  14 siblings, 0 replies; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-06-19 19:03 UTC (permalink / raw)
  To: Luis R. Rodriguez; +Cc: xen-devel

On Thu, Jun 12, 2014 at 06:18:38PM -0700, Luis R. Rodriguez wrote:
> From: "Luis R. Rodriguez" <mcgrof@suse.com>
> 
> Here's my v6 series. It should address all the feedback I've gotten
> fron the v5 series. I've compile tested and run time tested this
> on both systemd (OpenSUSE 13.1) and non-systemd systems (Debian testing)
> with cxenstored and oxenstored preferences.
> 
> The launcher thing is resolved now by using shell to do the explicit
> launching for us. This all also goes rebased an testd against today's
> git tree master branch.
> 

*poke*

  Luis

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

* Re: [PATCH v6 13/13] systemd: add xen systemd service and module files
  2014-06-13  1:18 ` [PATCH v6 13/13] systemd: add xen systemd service and module files Luis R. Rodriguez
  2014-06-13 19:55   ` Luis R. Rodriguez
@ 2014-06-19 19:47   ` Bastian Blank
  2014-06-19 20:21     ` Luis R. Rodriguez
  2014-07-02 14:02   ` Ian Campbell
  2 siblings, 1 reply; 66+ messages in thread
From: Bastian Blank @ 2014-06-19 19:47 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: Ian Campbell, Stefano Stabellini, Luis R. Rodriguez,
	Jan Rękorajski, Ian Jackson, Jacek Konieczny, M A Young,
	xen-devel

On Thu, Jun 12, 2014 at 06:18:51PM -0700, Luis R. Rodriguez wrote:
> This adds the systemd xen service / module files. All of this
> is disabled for now, and won't install / build until we hook
> up proper support for systemd into the build system.

Why?

> --- /dev/null
> +++ b/tools/hotplug/Linux/systemd/var-lib-xenstored.mount.in
> @@ -0,0 +1,13 @@
> +[Unit]
> +Description=mount xenstore file system
> +ConditionVirtualization=xen

Move the whole shit to /run, as anyone else does.

> --- /dev/null
> +++ b/tools/hotplug/Linux/systemd/xen-qemu-dom0-disk-backend.service.in
> @@ -0,0 +1,22 @@
> +[Service]
> +Type=simple
> +EnvironmentFile=-/etc/default/xenstored
> +EnvironmentFile=-/etc/sysconfig/xenstored
> +PIDFile=@XEN_RUN_DIR@/qemu-dom0.pid
> +ExecStartPre=/bin/grep -q control_d /proc/xen/capabilities

This can fail and will move the unit into failed state.  Please show
that this stuff does not make failed units on non-control domains.

> +ExecStartPre=/bin/mkdir -p /var/run/xen

This is referenced nowhere.

> +ExecStart=/bin/sh -c "exec $XENSTORED --no-fork $XENSTORED_ARGS"
> +ExecStartPost=-@BINDIR@/xenstore-write "/local/domain/0/name" "Domain-0"
> +ExecStartPost=-@BINDIR@/xenstore-write "/local/domain/0/domid" 0

Are you sure this is not racey?

Bastian

-- 
There is an order of things in this universe.
		-- Apollo, "Who Mourns for Adonais?" stardate 3468.1

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

* Re: [PATCH v6 13/13] systemd: add xen systemd service and module files
  2014-06-19 19:47   ` Bastian Blank
@ 2014-06-19 20:21     ` Luis R. Rodriguez
  2014-06-19 20:26       ` Luis R. Rodriguez
  0 siblings, 1 reply; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-06-19 20:21 UTC (permalink / raw)
  To: Bastian Blank, Luis R. Rodriguez, xen-devel, Ian Campbell,
	Stefano Stabellini, Luis R. Rodriguez, Jan Rękorajski,
	Ian Jackson, Jacek Konieczny, M A Young

On Thu, Jun 19, 2014 at 12:47 PM, Bastian Blank <bastian@waldi.eu.org> wrote:
> On Thu, Jun 12, 2014 at 06:18:51PM -0700, Luis R. Rodriguez wrote:
>> This adds the systemd xen service / module files. All of this
>> is disabled for now, and won't install / build until we hook
>> up proper support for systemd into the build system.
>
> Why?

As I noted in my follow up the statement that says that this goes
disabled is not accurate, I folded in the autoconf support here so
ignore that part. I think I was asked to fold them together in
previous reviews and just forgot to update that paragraph.

>> --- /dev/null
>> +++ b/tools/hotplug/Linux/systemd/var-lib-xenstored.mount.in
>> @@ -0,0 +1,13 @@
>> +[Unit]
>> +Description=mount xenstore file system
>> +ConditionVirtualization=xen
>
> Move the whole shit to /run, as anyone else does.

That's a separate atomic change from existing behavior and I'd prefer
that change be done separately.

>> --- /dev/null
>> +++ b/tools/hotplug/Linux/systemd/xen-qemu-dom0-disk-backend.service.in
>> @@ -0,0 +1,22 @@
>> +[Service]
>> +Type=simple
>> +EnvironmentFile=-/etc/default/xenstored
>> +EnvironmentFile=-/etc/sysconfig/xenstored
>> +PIDFile=@XEN_RUN_DIR@/qemu-dom0.pid
>> +ExecStartPre=/bin/grep -q control_d /proc/xen/capabilities
>
> This can fail and will move the unit into failed state.  Please show
> that this stuff does not make failed units on non-control domains.

This was in the legacy init scripts, as such its valid and should not
fail if this is dom0, for non xen dom0 builds the
ConditionVirtualization will prevent this unit from even being
considered and as such will not produced a failed unit.

>> +ExecStartPre=/bin/mkdir -p /var/run/xen
>
> This is referenced nowhere.
>
>> +ExecStart=/bin/sh -c "exec $XENSTORED --no-fork $XENSTORED_ARGS"
>> +ExecStartPost=-@BINDIR@/xenstore-write "/local/domain/0/name" "Domain-0"
>> +ExecStartPost=-@BINDIR@/xenstore-write "/local/domain/0/domid" 0
>
> Are you sure this is not racey?

As per the documentation ExecStartPost are executed one after the
other, serially [0]

[0] http://www.freedesktop.org/software/systemd/man/systemd.service.html

 Luis

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

* Re: [PATCH v6 13/13] systemd: add xen systemd service and module files
  2014-06-19 20:21     ` Luis R. Rodriguez
@ 2014-06-19 20:26       ` Luis R. Rodriguez
  2014-06-20  5:59         ` David Sutton
  0 siblings, 1 reply; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-06-19 20:26 UTC (permalink / raw)
  To: Bastian Blank, Luis R. Rodriguez, xen-devel, Ian Campbell,
	Stefano Stabellini, Luis R. Rodriguez, Jan Rękorajski,
	Ian Jackson, Jacek Konieczny, M A Young

On Thu, Jun 19, 2014 at 1:21 PM, Luis R. Rodriguez
<mcgrof@do-not-panic.com> wrote:
>>> +ExecStartPre=/bin/mkdir -p /var/run/xen
>>
>> This is referenced nowhere.

This is currently statically defined on code on both xenstored and oxenstored.

 Luis

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

* Re: [PATCH v6 13/13] systemd: add xen systemd service and module files
  2014-06-19 20:26       ` Luis R. Rodriguez
@ 2014-06-20  5:59         ` David Sutton
  0 siblings, 0 replies; 66+ messages in thread
From: David Sutton @ 2014-06-20  5:59 UTC (permalink / raw)
  To: xen-devel

Luis R. Rodriguez <mcgrof <at> do-not-panic.com> writes:

> 
> On Thu, Jun 19, 2014 at 1:21 PM, Luis R. Rodriguez
> <mcgrof <at> do-not-panic.com> wrote:
> >>> +ExecStartPre=/bin/mkdir -p /var/run/xen
> >>
> >> This is referenced nowhere.
> 
> This is currently statically defined on code on both xenstored and oxenstored.
> 
>  Luis
> 
Out of interest, would it be better to make use of tmpfiles.d to auto-create
this, rather than the explicit mkdir?

Regards,

  David

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

* Re: [PATCH v6 02/13] cxenstored: add support for systemd active sockets
  2014-06-13  1:18 ` [PATCH v6 02/13] cxenstored: add support for systemd active sockets Luis R. Rodriguez
@ 2014-07-02 13:02   ` Ian Campbell
  2014-07-02 19:00     ` Luis R. Rodriguez
  0 siblings, 1 reply; 66+ messages in thread
From: Ian Campbell @ 2014-07-02 13:02 UTC (permalink / raw)
  To: Luis R. Rodriguez; +Cc: xen-devel, Luis R. Rodriguez

On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
> +int xs_validate_active_socket(const char *connect_to)
> +{
> +	char sock[30];
> +
> +	/* We have to null terminate the socket path */
> +	memset(sock, '\0', sizeof(sock));
> +	memcpy(sock, connect_to, strlen(connect_to));

This risks overrunning sock if connect_to is longer than 30 characters.

But your use of strlen suggests that connect_to is already NULL
terminated, so what is this for?

> +	if ((strncmp("/var/run/xenstored/socket_ro", sock, 28) != 0) &&
> +	    (strncmp("/var/run/xenstored/socket", sock, 25) != 0)) {

Given that sock (or connect_to) is NULL terminated, why strncmp and not
the straightforward strcmp?

As it is I think your code would accept
e.g. /var/run/xenstored/socketwibble, no?

Is it common in systemd support to validate the input socket's path in
this way? As opposed to trusting that the systemd unit file is correct.

> +static void xen_claim_active_sockets(int **psock, int **pro_sock)
> +{
> +	int *sock, *ro_sock;
> +	const char *soc_str = xs_daemon_socket();
> +	const char *soc_str_ro = xs_daemon_socket_ro();
> +	int n;
> +
> +	n = sd_listen_fds(0);
> +	if (n <= 0) {
> +		sd_notifyf(0, "STATUS=Failed to get any active sockets: %s\n"
> +			   "ERRNO=%i",
> +			   strerror(errno),
> +			   errno);
> +		barf_perror("sd_listen_fds() failed\n");
> +	} else if (n > 2) {
> +		fprintf(stderr, SD_ERR "Expected 2 fds but given %d\n", n);
> +		sd_notifyf(0, "STATUS=Mismatch on number (2): %s\n"
> +			   "ERRNO=%d",
> +			   strerror(EBADR),
> +			   EBADR);
> +		barf_perror("sd_listen_fds() gave too many fds\n");

Need this be fatal?

Ian.

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

* Re: [PATCH v6 03/13] oxenstored: add support for systemd active sockets
  2014-06-13  1:18 ` [PATCH v6 03/13] oxenstored: " Luis R. Rodriguez
@ 2014-07-02 13:08   ` Ian Campbell
  2014-07-02 19:09     ` Luis R. Rodriguez
  0 siblings, 1 reply; 66+ messages in thread
From: Ian Campbell @ 2014-07-02 13:08 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: David Scott, Stefano Stabellini, Ian Jackson, Luis R. Rodriguez,
	Vincent Hanquez, xen-devel

On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
> From: "Luis R. Rodriguez" <mcgrof@suse.com>
> 
> This adds systemd socket activation support for the Ocaml xenstored.
> Ocaml lacks systemd library support so we provide our own C helpers
> as is done with other functionality lacking on Ocaml.
> 
> Active sockets enables oxenstored to be loaded only if required by a system
> onto which Xen is installed on. Socket activation is handled by
> systemd, once a port for a service which claims a socket is used
> systemd will start the required services for it, on demand. For more
> details on socket activation refer to Lennart's socket-activation
> post regarding this [0].
> 
> An important difference with socket activation is that systemd will set
> FD_CLOEXEC for us on the socket before giving it to us, we'll sprinkly
> the Unix.set_close_on_exec for LSB init next as a separate commit.
> 
> Right now this code adds a no-op for this functionality, leaving the
> enablement to be done later once systemd is properly hooked into
> the build system. The socket activation is ordered in aligment with
> the socket activation order passed on to systemd.
> 
> [0] http://0pointer.de/blog/projects/socket-activation2.html

I suspect some of my comments against C xenstored will apply to the C
code here too...

> diff --git a/tools/ocaml/xenstored/systemd.ml b/tools/ocaml/xenstored/systemd.ml
> new file mode 100644
> index 0000000..2aa39ea
> --- /dev/null
> +++ b/tools/ocaml/xenstored/systemd.ml

Ideally the systemd ocaml bindings would come from a suitable ocaml
library (opam or whatever). I suppose such a thing doesn't exist
already?

Perhaps Dave or Anil etc could advise on the feasibility of publishing
these bindings as a separate project. In general I'd much rather we
added build dependencies for things like that than incorporate things
which are nothing to do with Xen etc into the tree (we've done too much
of that in the past...)

> +CAMLprim value ocaml_sd_listen_fds(value connect_to)
> +{
> +	CAMLparam1(connect_to);
> +	CAMLlocal1(sock_ret);
> +	int sock = -EBADR, n;
> +
> +	n = sd_listen_fds(0);
> +	if (n <= 0) {
> +		sd_notifyf(0, "STATUS=Failed to get any active sockets: %s\n"
> +			   "ERRNO=%i",
> +			   strerror(errno),
> +			   errno);
> +		caml_failwith("ocaml_sd_listen_fds() failed to get any sockets");
> +	} else if (n > 2) {
> +		fprintf(stderr, SD_ERR "Expected 2 fds but given %d\n", n);
> +		sd_notifyf(0, "STATUS=Mismatch on number (2): %s\n"
> +			   "ERRNO=%d",
> +			   strerror(EBADR),
> +			   EBADR);
> +		caml_failwith("ocaml_sd_listen_fds() mismatch");
> +	}
> +
> +	sock = oxen_verify_socket_socket((const char *) String_val(connect_to));

String_val() gives you a char *, which ought to be automatically
promoted to const as necessary. So I think the case is unnecessary and
only serves to potentially hide actual errors.

> +	if (sock <= 0) {
> +		fprintf(stderr, "failed to verify sock %s\n",
> +			(const char *) String_val(connect_to));

Same, if less critical, here.

Is stderr the best place to shove this message? sd_notify is also used
elsewhere it seems.

> +		caml_failwith("ocaml_sd_listen_fds_init() invalid socket");
> +	}
> +
> +	sock_ret = Val_int(sock);
> +
> +	CAMLreturn(sock_ret);
> +}
> +

Ian.

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

* Re: [PATCH v6 04/13] oxenstored: force FD_CLOEXEC with Unix.set_close_on_exec on LSB init
  2014-06-13  1:18 ` [PATCH v6 04/13] oxenstored: force FD_CLOEXEC with Unix.set_close_on_exec on LSB init Luis R. Rodriguez
@ 2014-07-02 13:08   ` Ian Campbell
  0 siblings, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2014-07-02 13:08 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: David Scott, Stefano Stabellini, Vincent Hanquez,
	Luis R. Rodriguez, Anil Madhavapeddy, Ian Jackson, xen-devel

On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
> From: "Luis R. Rodriguez" <mcgrof@suse.com>
> 
> Lets match the systemd active socket activation implementation and
> ensure that FD_CLOEXEC is set by usin Unix.set_close_on_exec. David
> notes oxenstored likely does not exec but there is no harm in being
> careful just in case things change in the future.
> 
> Cc: David Scott <dave.scott@eu.citrix.com>
> Cc: Anil Madhavapeddy <anil@recoil.org>
> Cc: Ian Jackson <ian.jackson@eu.citrix.com>
> Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>

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

> Cc: Vincent Hanquez <Vincent.Hanquez@eu.citrix.com>
> Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
> ---
>  tools/ocaml/xenstored/utils.ml | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/tools/ocaml/xenstored/utils.ml b/tools/ocaml/xenstored/utils.ml
> index 0cfeded..61321c6 100644
> --- a/tools/ocaml/xenstored/utils.ml
> +++ b/tools/ocaml/xenstored/utils.ml
> @@ -78,6 +78,7 @@ let create_regular_unix_socket name =
>          Unixext.mkdir_rec (Filename.dirname name) 0o700;
>          let sockaddr = Unix.ADDR_UNIX(name) in
>          let sock = Unix.socket Unix.PF_UNIX Unix.SOCK_STREAM 0 in
> +        Unix.set_close_on_exec sock;
>          Unix.bind sock sockaddr;
>          Unix.listen sock 1;
>          sock

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

* Re: [PATCH v6 07/13] tools/xendomains: move to libexec and use a smaller init helper
  2014-06-13  1:18 ` [PATCH v6 07/13] tools/xendomains: move to libexec and use a smaller init helper Luis R. Rodriguez
  2014-06-13  7:06   ` Jacek Konieczny
@ 2014-07-02 13:12   ` Ian Campbell
  1 sibling, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2014-07-02 13:12 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: Stefano Stabellini, Luis R. Rodriguez, Jan Rękorajski,
	Ian Jackson, Jacek Konieczny, M A Young, xen-devel

On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
> From: "Luis R. Rodriguez" <mcgrof@suse.com>
> 
> The xendomains script can be reused with systemd systems as it
> does not control services or sockets per se, but does a one shot
> scrape of domUs it needs start bring up, stop, reload so we're
> going to reuse it. This moves the core of the script to libexec
> and leaves only a helper on init.
> 
> Cc: Ian Jackson <ian.jackson@eu.citrix.com>
> Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>

Assuming it just the code motion (I've not verified) plus the new
wrapper:
Acked-by: Ian Campbell <ian.campbell@citrix.com>

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

* Re: [PATCH v6 09/13] autoconf: update m4/pkg.m4
  2014-06-13  1:18 ` [PATCH v6 09/13] autoconf: update m4/pkg.m4 Luis R. Rodriguez
@ 2014-07-02 13:13   ` Ian Campbell
  2014-07-02 19:10     ` Luis R. Rodriguez
  0 siblings, 1 reply; 66+ messages in thread
From: Ian Campbell @ 2014-07-02 13:13 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: Keir Fraser, Tim Deegan, Luis R. Rodriguez, Ian Jackson,
	Jan Beulich, xen-devel

On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
> From: "Luis R. Rodriguez" <mcgrof@suse.com>
> 
> The provenance of the m4 pkg.m4 macro library was not documented
> and it was not clear how and if we can update this without breaking
> things. Document where this comes from, update us to the latest
> release from git and put a warning about avoiding private evolutions
> so that instead things go upstream.

Did we have any such private evolutions? Are you retaining them or
throwing them away?

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

* Re: [PATCH v6 10/13] autoconf: xen: move standard path variables to config/Paths.mk.in
  2014-06-13  1:18 ` [PATCH v6 10/13] autoconf: xen: move standard path variables to config/Paths.mk.in Luis R. Rodriguez
@ 2014-07-02 13:34   ` Ian Campbell
  2014-07-02 19:32     ` Luis R. Rodriguez
  2014-07-03 18:53     ` Luis R. Rodriguez
  0 siblings, 2 replies; 66+ messages in thread
From: Ian Campbell @ 2014-07-02 13:34 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: Keir Fraser, Tim Deegan, Luis R. Rodriguez, Ian Jackson,
	Jan Beulich, Samuel Thibault, xen-devel

On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
> From: "Luis R. Rodriguez" <mcgrof@suse.com>
> 
> This moves all generic path variables to a new the config/Paths.mk.in
> input source file to be processed at configure time, tons of files use
> these so this just share them. This also paves the way to let us
> easily dynamically configure these with autoconf, for now we leave the
> same presets as was present before.
> 
> This work was prompted by looking for an autoconf way to do
> replacements for the hotplug global file, while at it I realized
> that a few other files use the same variables and have in places
> around the tree the same constructs for generating their own
> files. This makes use of the old buildmakevars2file() but generalizes
> the definition of the paths at configure time and spreads the
> new definitions out throughout the build system.
> 
> This has no impact on building the hypervisor and extras/mini-os,
> you do not need to, and are not expected to, run configure to build
> those targets.
> 
> While at it lets add some documentation on the for the two files on
> the source file, we can expand further details on the wiki [0].
> 
> [0] http://wiki.xen.org/wiki/Category:Host_Configuration#System_wide_xen_configuration
> 
> Cc: Ian Campbell <ian.campbell@citrix.com>
> Cc: Ian Jackson <ian.jackson@eu.citrix.com>
> Cc: Samuel Thibault <samuel.thibault@ens-lyon.org>
> Cc: Jan Beulich <jbeulich@suse.com>
> Cc: Keir Fraser <keir@xen.org>
> Cc: Tim Deegan <tim@xen.org>
> Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
> ---
> 
> Please run autogen.sh after applying.
> 
>  .gitignore           |  1 +
>  config/Paths.mk.in   | 37 +++++++++++++++++++++++++++++++
>  config/Stubdom.mk.in |  1 +
>  configure.ac         |  8 ++++++-
>  m4/paths.m4          | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  stubdom/Makefile     |  1 +
>  tools/Rules.mk       |  1 +
>  7 files changed, 109 insertions(+), 1 deletion(-)
>  create mode 100644 config/Paths.mk.in
>  create mode 100644 m4/paths.m4
> 
> diff --git a/.gitignore b/.gitignore
> index 562c262..588a76d 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -36,6 +36,7 @@ config.log
>  config.status
>  config.cache
>  config/Toplevel.mk
> +config/Paths.mk
>  
>  build-*
>  dist/*
> diff --git a/config/Paths.mk.in b/config/Paths.mk.in
> new file mode 100644
> index 0000000..507b6d1
> --- /dev/null
> +++ b/config/Paths.mk.in
> @@ -0,0 +1,37 @@
> +# Xen system configuration
> +# ========================
> +#
> +# Xen uses a set of variables for system configuration and at build time,
> +# because of this these variables are defined on one master input source file
> +# and is generated after running ./configure. The master source is located
> +# on the xen source tree at under config/Paths.mk.in and it is used to
> +# generate shell or header files by the build system upon demand through the
> +# use of the helper makefile helper buildmakevars2file().
> +#
> +# For more documentation you can refer to the wiki:
> +#
> +# http://wiki.xen.org/wiki/Category:Host_Configuration#System_wide_xen_configuration
> +
> +SBINDIR                  := @SBINDIR@
> +BINDIR                   := @BINDIR@
> +LIBEXEC                  := @LIBEXEC@
> +
> +SHAREDIR                 := @SHAREDIR@
> +LIBDIR                   := @LIBDIR@
> +
> +XEN_RUN_DIR              := @XEN_RUN_DIR@
> +XEN_LOG_DIR              := @XEN_LOG_DIR@
> +XEN_LIB_STORED           := @XEN_LIB_STORED@
> +
> +CONFIG_DIR               := @CONFIG_DIR@
> +XEN_LOCK_DIR             := @XEN_LOCK_DIR@
> +XEN_PAGING_DIR           := @XEN_PAGING_DIR@
> +
> +PRIVATE_PREFIX           := @PRIVATE_PREFIX@
> +PRIVATE_PREFIX           := @PKG_XEN_PREFIX@
> +PRIVATE_BINDIR           := @PRIVATE_BINDIR@
> +
> +XENFIRMWAREDIR           := @XENFIRMWAREDIR@
> +
> +XEN_CONFIG_DIR           := @XEN_CONFIG_DIR@
> +XEN_SCRIPT_DIR           := @XEN_SCRIPT_DIR@
> diff --git a/config/Stubdom.mk.in b/config/Stubdom.mk.in
> index 302842e..6bce206 100644
> --- a/config/Stubdom.mk.in
> +++ b/config/Stubdom.mk.in
> @@ -1,4 +1,5 @@
>  # Prefix and install folder
> +include $(XEN_ROOT)/config/Paths.mk
>  prefix              := @prefix@
>  PREFIX              := $(prefix)
>  exec_prefix         := @exec_prefix@
> diff --git a/configure.ac b/configure.ac
> index 6c14524..f32f9af 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -5,12 +5,18 @@ AC_PREREQ([2.67])
>  AC_INIT([Xen Hypervisor], m4_esyscmd([./version.sh ./xen/Makefile]),
>      [xen-devel@lists.xen.org], [xen], [http://www.xen.org/])
>  AC_CONFIG_SRCDIR([./xen/common/kernel.c])
> -AC_CONFIG_FILES([./config/Toplevel.mk])
> +AC_CONFIG_FILES([
> +	config/Toplevel.mk
> +	config/Paths.mk
> +])
>  
>  AC_CANONICAL_HOST
>  
>  m4_include([m4/features.m4])
>  m4_include([m4/subsystem.m4])
> +m4_include([m4/paths.m4])
> +
> +AX_XEN_EXPAND_CONFIG()
>  
>  dnl mini-os is only ported to certain platforms
>  case "$host_cpu" in
> diff --git a/m4/paths.m4 b/m4/paths.m4
> new file mode 100644
> index 0000000..717fcd1
> --- /dev/null
> +++ b/m4/paths.m4
> @@ -0,0 +1,61 @@
> +AC_DEFUN([AX_XEN_EXPAND_CONFIG], [
> +dnl expand these early so we can use this for substitutions
> +test "x$prefix" = "xNONE" && prefix=$ac_default_prefix
> +test "x$exec_prefix" = "xNONE" && exec_prefix=$ac_default_prefix

This is a bit of shame. I suppose this needs to happen in the middle of
AC_OUTPUT which isn't possible?

autoconf itself seems to quote the prefix so it is not expanded until
later, i.e. when config.status is run. Would that work here?

Or perhaps we should just PREFIX=$prefix AC_SUBST(PREFIX) and put all
the BINDIR=$PREFIX/bin into Paths.mk.in after PREFIX=@PREFIX@?

> +BINDIR=$prefix/bin
> +AC_SUBST(BINDIR)
> +
> +SBINDIR=$prefix/sbin
> +AC_SUBST(SBINDIR)
> +
> +dnl XXX: this should be changed to use the passed $libexec
> +dnl but can be done as a second step
> +LIBEXEC=$prefix/lib/xen/bin
> +AC_SUBST(LIBEXEC)
> +
> +LIBDIR=`eval echo $libdir`

Why is this one an eval?

> diff --git a/stubdom/Makefile b/stubdom/Makefile
> index c41de27..ef99e3e 100644
> --- a/stubdom/Makefile
> +++ b/stubdom/Makefile
> @@ -7,6 +7,7 @@ export stubdom=y
>  export debug=y
>  include $(XEN_ROOT)/Config.mk
>  -include $(XEN_ROOT)/config/Stubdom.mk
> +include $(XEN_ROOT)/config/Paths.mk

The reason for the -include of Stubdom.mk is so that if it doesn't exist
enogh of the Makefile is still run to get:
ifeq (,$(findstring clean,$(MAKECMDGOALS)))
$(XEN_ROOT)/config/Stubdom.mk:
        $(error You have to run ./configure before building or installing stubdom)
endif

You included Paths.mk from Stubdom.mk (and Tools.mk etc) so I think
these ones are redundant.

Ian.

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

* Re: [PATCH v6 11/13] xencommons: move module list into a generic place
  2014-06-13  1:18 ` [PATCH v6 11/13] xencommons: move module list into a generic place Luis R. Rodriguez
@ 2014-07-02 13:44   ` Ian Campbell
  2014-07-02 21:56     ` Luis R. Rodriguez
  0 siblings, 1 reply; 66+ messages in thread
From: Ian Campbell @ 2014-07-02 13:44 UTC (permalink / raw)
  To: Luis R. Rodriguez; +Cc: xen-devel, Luis R. Rodriguez

On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
> From: "Luis R. Rodriguez" <mcgrof@suse.com>
> 
> This will allows us to share the same module list with
> sysemd, and lets us upkeep it in one place. Document this
> while at it on the top level README and expand on the wiki:
> 
> http://wiki.xen.org/wiki/Category:Host_Configuration#Linux_kernel_modules
> 
> In order to upkeep parallelism builds be explicit about the
> requirement to complete all actions before any installation
> targets.
> 
> Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
> ---
>  README                                             | 18 +++++++++++
>  config/modules                                     | 16 ++++++++++

This list is Linux specific. If tools/hotplug/Linux/config or something
doesn't work for the upcoming system patches then perhaps
config/Linux.modules, where Linux is chosen to match $(XEN_OS) aka
"uname -s".

>  tools/hotplug/Linux/Makefile                       | 36 +++++++++++++++++++---
>  .../Linux/init.d/{xencommons => xencommons.in}     | 16 +---------
>  4 files changed, 67 insertions(+), 19 deletions(-)
>  create mode 100644 config/modules
>  rename tools/hotplug/Linux/init.d/{xencommons => xencommons.in} (89%)
> 
> diff --git a/README b/README
> index 9bbe734..34d7c0b 100644
> --- a/README
> +++ b/README
> @@ -129,6 +129,24 @@ performed with root privileges.]
>     versions of those scripts, so that you can copy the dist directory
>     to another machine and install from that distribution.
>  
> +Required Linux modules
> +======================
> +
> +Xen has a set of Linux modules which the init scripts ensure to load before
> +enablement of xen guests. The list of modules are upkept in one place:

enablement isn't a word. I think "before starting Xen guests" is OK.

upkept also isn't, "maintained" perhaps.

Also, end users don't care a jot about any of this. Move it right to the
end of the README? At the moment it comes before the Python stuff which
is end user focused.

TBH if it were me I'd just put the "The file supports a simple.." as a
comment in config/modules (wherever it ends up) and leave it at that.

> +  * config/modules
> +
> +The file supports a simple language, comments are ignored, and if you there
> +are module replacements this can be listed by using a pipe to show preference
> +for the first module, followed by the older module.
> +
> +We should strive to not require statically loading modules but it seems some
> +systems have had issues with automatically loading some Linux kernel modules.
> +For more details refer to:

This last paragraph is just meta commentary, IMHO it is commit log
material (at best) rather than README material.

> +
> +http://wiki.xen.org/wiki/Category:Host_Configuration#Linux_kernel_modules
> +
>  Python Runtime Libraries
>  ========================
>  
> diff --git a/tools/hotplug/Linux/Makefile b/tools/hotplug/Linux/Makefile
> index d5de9e6..90b0b0c 100644
> --- a/tools/hotplug/Linux/Makefile
> +++ b/tools/hotplug/Linux/Makefile
> @@ -33,17 +33,45 @@ UDEV_RULES_DIR = $(CONFIG_DIR)/udev
>  UDEV_RULES = xen-backend.rules $(UDEV_RULES-y)
>  
>  .PHONY: all
> -all:
> +all: $(XENCOMMONS_INITD)
> +
> +$(XENCOMMONS_INITD): $(XEN_ROOT)/config/modules $(XENCOMMONS_INITD).in
> +	@set -e ;							\
> +	IFS=''								;\
> +	cat  $(XEN_ROOT)/config/modules	| (				\
> +		while read l ; do					\
> +			if echo $${l} | egrep -q "^#" ; then		\
> +				continue				;\
> +			fi						;\
> +			if echo "$${l}" | egrep -q "\|" ; then		\
> +				m1=$${l%%|*}				;\
> +				m2=$${l#*|} 				;\
> +				echo "        modprobe $$m1 2>/dev/null || modprobe $$m2 2>/dev/null" ;\
> +			else						\
> +				echo "        modprobe $$l 2>/dev/null"		;\
> +			fi						;\
> +		done							\
> +	) > $(XENCOMMONS_INITD).modules					;\
> +	cat  $(XENCOMMONS_INITD).in	| (				\
> +		while read l ; do					\
> +			if echo "$${l}" | egrep -q "@LOAD_MODULES@" ; then \
> +				cat $(XENCOMMONS_INITD).modules 	;\
> +			else						\
> +				echo $$l				;\
> +			fi						;\

Sed with something like "/@LOAD_MODULES@/r$(...).modules" can replace
this second loop.

Ian.

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

* Re: [PATCH v6 12/13] autoconf: xen: enable explicit preference option for xenstored preference
  2014-06-13  1:18 ` [PATCH v6 12/13] autoconf: xen: enable explicit preference option for xenstored preference Luis R. Rodriguez
@ 2014-07-02 13:54   ` Ian Campbell
  2014-07-02 20:09     ` Luis R. Rodriguez
  0 siblings, 1 reply; 66+ messages in thread
From: Ian Campbell @ 2014-07-02 13:54 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: Keir Fraser, Tim Deegan, Luis R. Rodriguez, Ian Jackson,
	Jan Beulich, xen-devel

On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
> Since the xenstored preference
> is explicit now and since we require configure substitutions for it we
> make use of the AX_XEN_EXPAND_CONFIG() helpers as otherwise substitution
> for SBINDIR is not propagated from the top level configuration.

I'm afraid I don't understand what is going on here. Why is SBINDIR not
propagated?


> Since we are now parsing an entry within Paths.mk.in on tools we let
> the move the parsing of the file to be the tool's configure.

I can't parse this.

> [0] http://wiki.xen.org/wiki/Xenstored
> [1] http://wiki.xen.org/wiki/XenStore
> [2] http://wiki.xen.org/wiki/XenStoreReference
> 
> Cc: Ian Campbell <ian.campbell@citrix.com>
> Cc: Ian Jackson <ian.jackson@eu.citrix.com>
> Cc: Jan Beulich <jbeulich@suse.com>
> Cc: Keir Fraser <keir@xen.org>
> Cc: Tim Deegan <tim@xen.org>
> Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
> ---
> 
> Please run autogen.sh after merging please.
> 
> diff --git a/m4/xenstored.m4 b/m4/xenstored.m4
> new file mode 100644
> index 0000000..5a4d891
> --- /dev/null
> +++ b/m4/xenstored.m4
> @@ -0,0 +1,60 @@
> +AC_DEFUN([AX_XEN_OCAML_XENSTORE_CHECK], [
> +	AS_IF([test "x$OCAMLC" = "xno" || test "x$OCAMLFIND" = "xno"], [
> +		AC_MSG_ERROR([Missing ocaml dependencies for oxenstored, try installing ocaml ocaml-compiler-libs ocaml-runtime ocaml-findlib])
> +	])
> +])
> +
> +AC_DEFUN([AX_XEN_OCAML_XENSTORE_DEFAULTS], [
> +	xenstore="oxenstored"
> +	xenstored=$SBINDIR/oxenstored
> +	AS_IF([test "x$OCAMLC" = "xno" || test "x$OCAMLFIND" = "xno"], [
> +		xenstore="xenstored"
> +		xenstored=$SBINDIR/xenstored
> +	])
> +])
> +
> +AC_DEFUN([AX_XENSTORE_OPTIONS], [
> +AS_IF([test "x$XENSTORE" = "x"], [
> +AC_ARG_WITH([xenstored],
> +	AS_HELP_STRING([--with-xenstored@<:@=oxenstored|xenstored@:>@],
> +		[This lets you choose which xenstore daemon you want, you have
> +		two options: the original xenstored written in C (xenstored)
> +		or the newer and robust one written in Ocaml (oxenstored).
> +		The oxenstored daemon is the default but will but can only
> +		be used if you have ocaml library / build dependencies solved,
> +		if you have not specified a preference and do not have ocaml
> +		dependencies resolved we'll enable the C xenstored for you. If
> +		you ask for oxenstored we'll complain until you resolve those
> +		dependencies]),
> +	[
> +		AS_IF([test "x$withval" = "xxenstored"], [
> +			xenstore=$withval
> +			xenstored=$SBINDIR/xenstored
> +		])
> +		AS_IF([test "x$withval" = "xoxenstored"], [
> +			xenstore=$withval
> +			xenstored=$SBINDIR/oxenstored
> +			AX_XEN_OCAML_XENSTORE_CHECK()
> +		])
> +		AS_IF([test "x$withval" != "xoxenstored" && test "x$withval" != "xxenstored"], [
> +			AC_MSG_ERROR([Unsupported xenstored specified, supported types: oxenstored xenstored])
> +		])
> +	],
> +	[
> +		AX_XEN_OCAML_XENSTORE_DEFAULTS()
> +	])
> +])
> +])
> +
> +AC_DEFUN([AX_XENSTORE_SET], [
> +	XENSTORE=$xenstore
> +	AC_SUBST(XENSTORE)

This isn't used any more.

> +
> +	AS_IF([test "x$XENSTORED" = "x"], [
> +		XENSTORED=$xenstored
> +	])
> +	AC_SUBST(XENSTORED)
> +
> +	AS_IF([test "x$XENSTORE" != "xxenstored" && test "x$XENSTORE" != "xoxenstored"],
> +		[AC_MSG_ERROR([Invalid xenstore: $XENSTORE])])

You'll have already bailed from the previous incantation before you ever
hit this, no?

> diff --git a/tools/hotplug/Linux/init.d/sysconfig.xencommons b/tools/hotplug/Linux/init.d/sysconfig.xencommons.in
> similarity index 64%
> rename from tools/hotplug/Linux/init.d/sysconfig.xencommons
> rename to tools/hotplug/Linux/init.d/sysconfig.xencommons.in
> index 25f7f00..d7d09ff 100644
> --- a/tools/hotplug/Linux/init.d/sysconfig.xencommons
> +++ b/tools/hotplug/Linux/init.d/sysconfig.xencommons.in
> @@ -8,8 +8,17 @@
>  ## Type: string
>  ## Default: xenstored
>  #
> -# Select xenstored implementation
> -#XENSTORED=[oxenstored|xenstored]
> +# Select xenstore implementation, this can be either
> +# of these below. If using systemd its preferred you

"it's", and I think you are missing a "that" before you.

Ian.

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

* Re: [PATCH v6 13/13] systemd: add xen systemd service and module files
  2014-06-13  1:18 ` [PATCH v6 13/13] systemd: add xen systemd service and module files Luis R. Rodriguez
  2014-06-13 19:55   ` Luis R. Rodriguez
  2014-06-19 19:47   ` Bastian Blank
@ 2014-07-02 14:02   ` Ian Campbell
  2014-07-02 20:25     ` Luis R. Rodriguez
  2 siblings, 1 reply; 66+ messages in thread
From: Ian Campbell @ 2014-07-02 14:02 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: Stefano Stabellini, Luis R. Rodriguez, Jan Rękorajski,
	Ian Jackson, Jacek Konieczny, M A Young, xen-devel

On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:

> As for integration with xen, we house keep all the systemd files
> under a new directory tools/hotplug/Linux/systemd/ and will be targetted

"targeted".

> by default when building on Linux systems if systemd enabled at
> build time,

This should be predicated on the presence of the systemd libraries, not
on actually running systemd. Think e.g. build chroots. Maybe that's what
you were trying to say anyway?

>  which is only required on the build box, not the user
> system.
> 
> The systemd files will be sanitized for meta @VARIABLES@ upon
> configuration and installed upon the install target. Systems that
> do not use systemd can still get systemd service unit files installed
> if the build system enabled systemd support, this however does not
> mandate a requirement of having systemd libraries present. Old init
> scripts are always installed.
> 
> If you don't specify a prefix you will end up with the services
> files under /usr/local/lib/systemd/system/ by default, and systemd
> modules-load.d conf files under /usr/local/lib/modules-load.d/ which
> systemd does look for (although it seems this is not documented).
> 
> Distributions are expected to provide their /usr/ prefix to end up in
> the more generic location upon distribution install at
> /usr/lib/systemd/system/ and /usr/lib/modules-load.d/ respectively.

> @@ -184,6 +185,27 @@ change take effect.
>  [1] http://wiki.xen.org/wiki/XenStoreReference
>  [2] http://wiki.xen.org/wiki/Xenstored
>  
> +Systemd and legacy init support
> +===============================
> +
> +If you have systemd development packages installed you can build binaries
> +with systemd support. Systemd support is enabled by default if you have
> +systemd development libraries present. Binaries built with systemd supprot

"support" (please run a spell checker)

> +will require systemd libraries to be present on the host system, however
> +systemd initialization will only occur if the system booted with systemd as its
> +init. If systemd was not the init the legacy initialization will be used.
> +Systemd is enabled by default if you have systemd development libraries

This is starting to repeat itself I think (this is the second time this
paragraph talks about the default).

> diff --git a/m4/README.source b/m4/README.source
> index 76f7c5a..8805b8e 100644
> --- a/m4/README.source
> +++ b/m4/README.source
> @@ -26,3 +26,13 @@ Date:   Mon Feb 3 15:59:18 2014 -0800
>      With the newly added glib.mk, some of the noinst_* variables need to use
>      += in the evaluation to avoid multiple definition warnings from
>      automake.
> +
> +systemd.m4
> +==========
> +
> +systemd.m4 was contributed to by Luis R. Rodriguez <mcgrof@do-not-panic.com>,
> +its current home project can be found at:
> +
> +https://github.com/mcgrof/funk-systemd
> +
> +There is a plan to upstream this library somehow to systemd.

This last sentence doesn't belong here, we don't much care what upstream
plans to do (whether or not that is you).

> +AC_DEFUN([AX_CHECK_SYSTEMD_LIBS], [
> +	AC_CHECK_HEADER([systemd/sd-daemon.h], [
> +	    AC_CHECK_LIB([systemd-daemon], [sd_listen_fds], [libsystemddaemon="y"])
> +	])
> +	AS_IF([test "x$libsystemddaemon" = x], [
> +	    AC_MSG_ERROR([Unable to find a suitable libsystemd-daemon library])
> +	])
> +
> +	PKG_CHECK_MODULES([SYSTEMD], [libsystemd-daemon])
> +	dnl pkg-config older than 0.24 does not set these for
> +	dnl PKG_CHECK_MODULES()

What is the implication of this? THat we have a workaround for it here
or that we don't support system on systems with pkg-config older than
that?

>  worth also noting is that as of version 208
> +	dnl of systemd pkg-config --cflags currently yields no extra flags yet.

Why is it worth noting that?

> +	AC_SUBST([SYSTEMD_CFLAGS])
> +	AC_SUBST([SYSTEMD_LIBS])
> +
> +	AS_IF([test "x$SYSTEMD_DIR" = x], [
> +	    dnl In order to use the line below we need to fix upstream systemd
> +	    dnl to properly ${prefix} for child variables in
> +	    dnl src/core/systemd.pc.in but this is a bit complex at the
> +	    dnl moment as they depend on another rootprefix, which can vary
> +	    dnl from prefix in practice. We provide our own definition as we
> +	    dnl *know* where systemd will dump this to, but this does limit
> +	    dnl us to stick to a non custom systemdsystemunitdir, dnl to work

dnl in the middle of the line suggests a rewrapping snafu.

> +	    dnl around this we provide the additional configure option
> +	    dnl --with-systemd where you can specify the directory for the unit
> +	    dnl files. It would also be best to just extend the upstream
> +	    dnl pkg-config  pkg.m4 with an AC_DEFUN() to do this neatly.

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

* Re: [PATCH v6 00/13] xen: add systemd support
  2014-06-13  1:18 [PATCH v6 00/13] xen: add systemd support Luis R. Rodriguez
                   ` (13 preceding siblings ...)
  2014-06-19 19:03 ` [PATCH v6 00/13] xen: add systemd support Luis R. Rodriguez
@ 2014-07-02 14:48 ` Ian Campbell
  14 siblings, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2014-07-02 14:48 UTC (permalink / raw)
  To: Luis R. Rodriguez; +Cc: xen-devel, Luis R. Rodriguez

On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:

>   oxenstored: force FD_CLOEXEC with Unix.set_close_on_exec on LSB init

This is acked by me but I thought I'd give the ocaml folks a chance, and
I wasn't sure if it depended textually on something before.

>   tools/xendomains: make xl the default and remove xm usage
>   tools/xendomains: do space cleanups
>   tools/xendomains: move to libexec and use a smaller init helper
>   autoconf: xen: force a refresh with autoconf
>   autoconf: update m4/pkg.m4

I've applied these 5 since they seemed to standalone.

Ian.

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

* Re: [PATCH v6 02/13] cxenstored: add support for systemd active sockets
  2014-07-02 13:02   ` Ian Campbell
@ 2014-07-02 19:00     ` Luis R. Rodriguez
  2014-07-03  9:13       ` Ian Campbell
  0 siblings, 1 reply; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-07-02 19:00 UTC (permalink / raw)
  To: Ian Campbell; +Cc: xen-devel, Luis R. Rodriguez

On Wed, Jul 02, 2014 at 02:02:38PM +0100, Ian Campbell wrote:
> On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
> > +int xs_validate_active_socket(const char *connect_to)
> > +{
> > +	char sock[30];
> > +
> > +	/* We have to null terminate the socket path */
> > +	memset(sock, '\0', sizeof(sock));
> > +	memcpy(sock, connect_to, strlen(connect_to));
> 
> This risks overrunning sock if connect_to is longer than 30 characters.

Yuk, yes. A size check is required.

> But your use of strlen suggests that connect_to is already NULL
> terminated, so what is this for?

strlen() seems to want the string to also be null terminated
in order to work, and I also see that snprintf() is ultimately
used on the C version of the library, that should ensure its null
terminated. This however is not true for the ocaml version and
I suppose that is the root of the issue I saw that got me to
force null terimination as I did run into issues with this path
IIRC when not null terminated.

> > +	if ((strncmp("/var/run/xenstored/socket_ro", sock, 28) != 0) &&
> > +	    (strncmp("/var/run/xenstored/socket", sock, 25) != 0)) {
> 
> Given that sock (or connect_to) is NULL terminated, why strncmp and not
> the straightforward strcmp?

See above.

> As it is I think your code would accept
> e.g. /var/run/xenstored/socketwibble, no?

It indeed would, its best if we resolve the null termination
issue internally then.

> Is it common in systemd support to validate the input socket's path in
> this way? As opposed to trusting that the systemd unit file is correct.

sd_is_socket_unix() is certainly advised and highly encourged. As
for the other check -- yes we want that given that we are using
two socket files specifically in order to avoid having to chmod()
the socket ourelves. Systemd currently doesn't support having two
separate sockets in one file with different permissions. From
what I have seen the order in which systemd sets the sockets and
maps them to fds will very on the unit socket files you use, this
approach lets us allow systemd to give them to us in any order
while my hope is that systemd upstream gets support for just one
stocket file with multiple permissions.

> > +static void xen_claim_active_sockets(int **psock, int **pro_sock)
> > +{
> > +	int *sock, *ro_sock;
> > +	const char *soc_str = xs_daemon_socket();
> > +	const char *soc_str_ro = xs_daemon_socket_ro();
> > +	int n;
> > +
> > +	n = sd_listen_fds(0);
> > +	if (n <= 0) {
> > +		sd_notifyf(0, "STATUS=Failed to get any active sockets: %s\n"
> > +			   "ERRNO=%i",
> > +			   strerror(errno),
> > +			   errno);
> > +		barf_perror("sd_listen_fds() failed\n");
> > +	} else if (n > 2) {
> > +		fprintf(stderr, SD_ERR "Expected 2 fds but given %d\n", n);
> > +		sd_notifyf(0, "STATUS=Mismatch on number (2): %s\n"
> > +			   "ERRNO=%d",
> > +			   strerror(EBADR),
> > +			   EBADR);
> > +		barf_perror("sd_listen_fds() gave too many fds\n");
> 
> Need this be fatal?

You can do anything you want but IMO yes, otherwise we'd be misconfigured and there
is a mismatch.

 Luis

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

* Re: [PATCH v6 03/13] oxenstored: add support for systemd active sockets
  2014-07-02 13:08   ` Ian Campbell
@ 2014-07-02 19:09     ` Luis R. Rodriguez
  2014-07-03  8:42       ` Dave Scott
  0 siblings, 1 reply; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-07-02 19:09 UTC (permalink / raw)
  To: Ian Campbell
  Cc: David Scott, Stefano Stabellini, Ian Jackson, Luis R. Rodriguez,
	Vincent Hanquez, xen-devel

On Wed, Jul 02, 2014 at 02:08:23PM +0100, Ian Campbell wrote:
> On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
> > diff --git a/tools/ocaml/xenstored/systemd.ml b/tools/ocaml/xenstored/systemd.ml
> > new file mode 100644
> > index 0000000..2aa39ea
> > --- /dev/null
> > +++ b/tools/ocaml/xenstored/systemd.ml
> 
> Ideally the systemd ocaml bindings would come from a suitable ocaml
> library (opam or whatever). I suppose such a thing doesn't exist
> already?

Not that I was able to find but Ocaml folks can chime in.

> Perhaps Dave or Anil etc could advise on the feasibility of publishing
> these bindings as a separate project. In general I'd much rather we
> added build dependencies for things like that than incorporate things
> which are nothing to do with Xen etc into the tree (we've done too much
> of that in the past...)

Can't this be done as a separate step? Otherwise Ocaml is holding
Xen behind, has that compromise has already been made and accepted?

> > +CAMLprim value ocaml_sd_listen_fds(value connect_to)
> > +{
> > +	CAMLparam1(connect_to);
> > +	CAMLlocal1(sock_ret);
> > +	int sock = -EBADR, n;
> > +
> > +	n = sd_listen_fds(0);
> > +	if (n <= 0) {
> > +		sd_notifyf(0, "STATUS=Failed to get any active sockets: %s\n"
> > +			   "ERRNO=%i",
> > +			   strerror(errno),
> > +			   errno);
> > +		caml_failwith("ocaml_sd_listen_fds() failed to get any sockets");
> > +	} else if (n > 2) {
> > +		fprintf(stderr, SD_ERR "Expected 2 fds but given %d\n", n);
> > +		sd_notifyf(0, "STATUS=Mismatch on number (2): %s\n"
> > +			   "ERRNO=%d",
> > +			   strerror(EBADR),
> > +			   EBADR);
> > +		caml_failwith("ocaml_sd_listen_fds() mismatch");
> > +	}
> > +
> > +	sock = oxen_verify_socket_socket((const char *) String_val(connect_to));
> 
> String_val() gives you a char *, which ought to be automatically
> promoted to const as necessary. So I think the case is unnecessary and
> only serves to potentially hide actual errors.

OK.

> > +	if (sock <= 0) {
> > +		fprintf(stderr, "failed to verify sock %s\n",
> > +			(const char *) String_val(connect_to));
> 
> Same, if less critical, here.
> 
> Is stderr the best place to shove this message? sd_notify is also used
> elsewhere it seems.

stderr will make it out to the journal, the other errors are to also notify
systemd, additional messages can be pegged with fprintf(stderr, ...). We
want to be very explicit about the root cause of the issue if one triggered.

  Luis

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

* Re: [PATCH v6 09/13] autoconf: update m4/pkg.m4
  2014-07-02 13:13   ` Ian Campbell
@ 2014-07-02 19:10     ` Luis R. Rodriguez
  0 siblings, 0 replies; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-07-02 19:10 UTC (permalink / raw)
  To: Ian Campbell
  Cc: Keir Fraser, Luis R. Rodriguez, Ian Jackson, Tim Deegan,
	Jan Beulich, xen-devel

On Wed, Jul 02, 2014 at 02:13:40PM +0100, Ian Campbell wrote:
> On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
> > From: "Luis R. Rodriguez" <mcgrof@suse.com>
> > 
> > The provenance of the m4 pkg.m4 macro library was not documented
> > and it was not clear how and if we can update this without breaking
> > things. Document where this comes from, update us to the latest
> > release from git and put a warning about avoiding private evolutions
> > so that instead things go upstream.
> 
> Did we have any such private evolutions? Are you retaining them or
> throwing them away?

No.

 Luis

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

* Re: [PATCH v6 10/13] autoconf: xen: move standard path variables to config/Paths.mk.in
  2014-07-02 13:34   ` Ian Campbell
@ 2014-07-02 19:32     ` Luis R. Rodriguez
  2014-07-03  9:15       ` Ian Campbell
  2014-07-03 18:53     ` Luis R. Rodriguez
  1 sibling, 1 reply; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-07-02 19:32 UTC (permalink / raw)
  To: Ian Campbell
  Cc: Keir Fraser, Luis R. Rodriguez, Tim Deegan, Ian Jackson,
	Jan Beulich, Samuel Thibault, xen-devel

On Wed, Jul 02, 2014 at 02:34:14PM +0100, Ian Campbell wrote:
> On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
> > diff --git a/m4/paths.m4 b/m4/paths.m4
> > new file mode 100644
> > index 0000000..717fcd1
> > --- /dev/null
> > +++ b/m4/paths.m4
> > @@ -0,0 +1,61 @@
> > +AC_DEFUN([AX_XEN_EXPAND_CONFIG], [
> > +dnl expand these early so we can use this for substitutions
> > +test "x$prefix" = "xNONE" && prefix=$ac_default_prefix
> > +test "x$exec_prefix" = "xNONE" && exec_prefix=$ac_default_prefix
> 
> This is a bit of shame. I suppose this needs to happen in the middle of
> AC_OUTPUT which isn't possible?
> 
> autoconf itself seems to quote the prefix so it is not expanded until
> later, i.e. when config.status is run. Would that work here?

Its unclear what exactly the recommendation is here.

> Or perhaps we should just PREFIX=$prefix AC_SUBST(PREFIX) and put all
> the BINDIR=$PREFIX/bin into Paths.mk.in after PREFIX=@PREFIX@?

Why though?

> > +BINDIR=$prefix/bin
> > +AC_SUBST(BINDIR)
> > +
> > +SBINDIR=$prefix/sbin
> > +AC_SUBST(SBINDIR)
> > +
> > +dnl XXX: this should be changed to use the passed $libexec
> > +dnl but can be done as a second step
> > +LIBEXEC=$prefix/lib/xen/bin
> > +AC_SUBST(LIBEXEC)
> > +
> > +LIBDIR=`eval echo $libdir`
> 
> Why is this one an eval?

Yeah you're right, its not needed this should work just as well:

LIBDIR=$libdir

I've amended this change.

> > diff --git a/stubdom/Makefile b/stubdom/Makefile
> > index c41de27..ef99e3e 100644
> > --- a/stubdom/Makefile
> > +++ b/stubdom/Makefile
> > @@ -7,6 +7,7 @@ export stubdom=y
> >  export debug=y
> >  include $(XEN_ROOT)/Config.mk
> >  -include $(XEN_ROOT)/config/Stubdom.mk
> > +include $(XEN_ROOT)/config/Paths.mk
> 
> The reason for the -include of Stubdom.mk is so that if it doesn't exist
> enogh of the Makefile is still run to get:
> ifeq (,$(findstring clean,$(MAKECMDGOALS)))
> $(XEN_ROOT)/config/Stubdom.mk:
>         $(error You have to run ./configure before building or installing stubdom)
> endif
> 
> You included Paths.mk from Stubdom.mk (and Tools.mk etc) so I think
> these ones are redundant.

OK ammended.

  Luis

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

* Re: [PATCH v6 12/13] autoconf: xen: enable explicit preference option for xenstored preference
  2014-07-02 13:54   ` Ian Campbell
@ 2014-07-02 20:09     ` Luis R. Rodriguez
  2014-07-03  9:20       ` Ian Campbell
  0 siblings, 1 reply; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-07-02 20:09 UTC (permalink / raw)
  To: Ian Campbell
  Cc: Keir Fraser, Luis R. Rodriguez, Ian Jackson, Tim Deegan,
	Jan Beulich, xen-devel

On Wed, Jul 02, 2014 at 02:54:31PM +0100, Ian Campbell wrote:
> On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
> > Since the xenstored preference
> > is explicit now and since we require configure substitutions for it we
> > make use of the AX_XEN_EXPAND_CONFIG() helpers as otherwise substitution
> > for SBINDIR is not propagated from the top level configuration.
> 
> I'm afraid I don't understand what is going on here. Why is SBINDIR not
> propagated?

Its saying that we need AX_XEN_EXPAND_CONFIG() in order to do substitutions
for variables that include SBINDIR in this case for the xenstore full path.

> > Since we are now parsing an entry within Paths.mk.in on tools we let
> > the move the parsing of the file to be the tool's configure.
>
> I can't parse this.

I meant to clarify that since we now have to do a substitution on tools
we move the calls to AX_XEN_EXPAND_CONFIG() there. This patch should have
also removed the AX_XEN_EXPAND_CONFIG() from the top level configure.ac.

After testing this though and removing AX_XEN_EXPAND_CONFIG() from configure.ac
I do see though that substitution doesn't work, it only works if we leave
AX_XEN_EXPAND_CONFIG() on both places. This is the issue I mentioned that
I ran into and you had proposed we could try to figure out a fix if
this was happening. Well it is. Any ideas ? Or are you OK to live with
calling AX_XEN_EXPAND_CONFIG() twice, once on configure.ac and another
on tools/configure.ac ?

> > diff --git a/m4/xenstored.m4 b/m4/xenstored.m4
> > new file mode 100644
> > index 0000000..5a4d891

<-- snip -->

> > +AC_DEFUN([AX_XENSTORE_SET], [
> > +	XENSTORE=$xenstore
> > +	AC_SUBST(XENSTORE)
> 
> This isn't used any more.

Removed this last AC_SUBST() line.

> > +
> > +	AS_IF([test "x$XENSTORED" = "x"], [
> > +		XENSTORED=$xenstored
> > +	])
> > +	AC_SUBST(XENSTORED)
> > +
> > +	AS_IF([test "x$XENSTORE" != "xxenstored" && test "x$XENSTORE" != "xoxenstored"],
> > +		[AC_MSG_ERROR([Invalid xenstore: $XENSTORE])])
> 
> You'll have already bailed from the previous incantation before you ever
> hit this, no?

Yes true, nuked this superfluous check.

> > diff --git a/tools/hotplug/Linux/init.d/sysconfig.xencommons b/tools/hotplug/Linux/init.d/sysconfig.xencommons.in
> > similarity index 64%
> > rename from tools/hotplug/Linux/init.d/sysconfig.xencommons
> > rename to tools/hotplug/Linux/init.d/sysconfig.xencommons.in
> > index 25f7f00..d7d09ff 100644
> > --- a/tools/hotplug/Linux/init.d/sysconfig.xencommons
> > +++ b/tools/hotplug/Linux/init.d/sysconfig.xencommons.in
> > @@ -8,8 +8,17 @@
> >  ## Type: string
> >  ## Default: xenstored
> >  #
> > -# Select xenstored implementation
> > -#XENSTORED=[oxenstored|xenstored]
> > +# Select xenstore implementation, this can be either
> > +# of these below. If using systemd its preferred you
> 
> "it's", and I think you are missing a "that" before you.

Amended, thanks.

  Luis

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

* Re: [PATCH v6 13/13] systemd: add xen systemd service and module files
  2014-07-02 14:02   ` Ian Campbell
@ 2014-07-02 20:25     ` Luis R. Rodriguez
  0 siblings, 0 replies; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-07-02 20:25 UTC (permalink / raw)
  To: Ian Campbell
  Cc: Stefano Stabellini, Jan Rękorajski, Ian Jackson,
	Jacek Konieczny, M A Young, xen-devel, Luis R. Rodriguez

On Wed, Jul 02, 2014 at 03:02:42PM +0100, Ian Campbell wrote:
> On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
> 
> > As for integration with xen, we house keep all the systemd files
> > under a new directory tools/hotplug/Linux/systemd/ and will be targetted
> 
> "targeted".
> 

Amended.

> > by default when building on Linux systems if systemd enabled at
> > build time,
> 
> This should be predicated on the presence of the systemd libraries, not
> on actually running systemd. Think e.g. build chroots. Maybe that's what
> you were trying to say anyway?

Indeed. Fix this up a bit to clarify.

> >  which is only required on the build box, not the user
> > system.
> > 
> > The systemd files will be sanitized for meta @VARIABLES@ upon
> > configuration and installed upon the install target. Systems that
> > do not use systemd can still get systemd service unit files installed
> > if the build system enabled systemd support, this however does not
> > mandate a requirement of having systemd libraries present. Old init
> > scripts are always installed.
> > 
> > If you don't specify a prefix you will end up with the services
> > files under /usr/local/lib/systemd/system/ by default, and systemd
> > modules-load.d conf files under /usr/local/lib/modules-load.d/ which
> > systemd does look for (although it seems this is not documented).
> > 
> > Distributions are expected to provide their /usr/ prefix to end up in
> > the more generic location upon distribution install at
> > /usr/lib/systemd/system/ and /usr/lib/modules-load.d/ respectively.
> 
> > @@ -184,6 +185,27 @@ change take effect.
> >  [1] http://wiki.xen.org/wiki/XenStoreReference
> >  [2] http://wiki.xen.org/wiki/Xenstored
> >  
> > +Systemd and legacy init support
> > +===============================
> > +
> > +If you have systemd development packages installed you can build binaries
> > +with systemd support. Systemd support is enabled by default if you have
> > +systemd development libraries present. Binaries built with systemd supprot
> 
> "support" (please run a spell checker)

Amended.

> > +will require systemd libraries to be present on the host system, however
> > +systemd initialization will only occur if the system booted with systemd as its
> > +init. If systemd was not the init the legacy initialization will be used.
> > +Systemd is enabled by default if you have systemd development libraries
> 
> This is starting to repeat itself I think (this is the second time this
> paragraph talks about the default).

Nuked.

> > diff --git a/m4/README.source b/m4/README.source
> > index 76f7c5a..8805b8e 100644
> > --- a/m4/README.source
> > +++ b/m4/README.source
> > @@ -26,3 +26,13 @@ Date:   Mon Feb 3 15:59:18 2014 -0800
> >      With the newly added glib.mk, some of the noinst_* variables need to use
> >      += in the evaluation to avoid multiple definition warnings from
> >      automake.
> > +
> > +systemd.m4
> > +==========
> > +
> > +systemd.m4 was contributed to by Luis R. Rodriguez <mcgrof@do-not-panic.com>,
> > +its current home project can be found at:
> > +
> > +https://github.com/mcgrof/funk-systemd
> > +
> > +There is a plan to upstream this library somehow to systemd.
> 
> This last sentence doesn't belong here, we don't much care what upstream
> plans to do (whether or not that is you).

OK, nuked verbosity.

> > +AC_DEFUN([AX_CHECK_SYSTEMD_LIBS], [
> > +	AC_CHECK_HEADER([systemd/sd-daemon.h], [
> > +	    AC_CHECK_LIB([systemd-daemon], [sd_listen_fds], [libsystemddaemon="y"])
> > +	])
> > +	AS_IF([test "x$libsystemddaemon" = x], [
> > +	    AC_MSG_ERROR([Unable to find a suitable libsystemd-daemon library])
> > +	])
> > +
> > +	PKG_CHECK_MODULES([SYSTEMD], [libsystemd-daemon])
> > +	dnl pkg-config older than 0.24 does not set these for
> > +	dnl PKG_CHECK_MODULES()
> 
> What is the implication of this? THat we have a workaround for it here
> or that we don't support system on systems with pkg-config older than
> that?

Nothing, the purpose of the additions of the two AC_SUBST() is to ensure the
variables are always present, even if users are on older version of pkg-config.

> >  worth also noting is that as of version 208
> > +	dnl of systemd pkg-config --cflags currently yields no extra flags yet.
> 
> Why is it worth noting that?

I think its worth noting it as although support exists its not yet relevant,
if issues should come up with it at a later point in time it may become more
imporant.

> > +	AC_SUBST([SYSTEMD_CFLAGS])
> > +	AC_SUBST([SYSTEMD_LIBS])
> > +
> > +	AS_IF([test "x$SYSTEMD_DIR" = x], [
> > +	    dnl In order to use the line below we need to fix upstream systemd
> > +	    dnl to properly ${prefix} for child variables in
> > +	    dnl src/core/systemd.pc.in but this is a bit complex at the
> > +	    dnl moment as they depend on another rootprefix, which can vary
> > +	    dnl from prefix in practice. We provide our own definition as we
> > +	    dnl *know* where systemd will dump this to, but this does limit
> > +	    dnl us to stick to a non custom systemdsystemunitdir, dnl to work
> 
> dnl in the middle of the line suggests a rewrapping snafu.

Fixed.

  Luis`

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

* Re: [PATCH v6 11/13] xencommons: move module list into a generic place
  2014-07-02 13:44   ` Ian Campbell
@ 2014-07-02 21:56     ` Luis R. Rodriguez
  2014-07-03  9:15       ` Ian Campbell
  0 siblings, 1 reply; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-07-02 21:56 UTC (permalink / raw)
  To: Ian Campbell; +Cc: xen-devel, Luis R. Rodriguez

On Wed, Jul 02, 2014 at 02:44:03PM +0100, Ian Campbell wrote:
> On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
> > From: "Luis R. Rodriguez" <mcgrof@suse.com>
> > 
> > This will allows us to share the same module list with
> > sysemd, and lets us upkeep it in one place. Document this
> > while at it on the top level README and expand on the wiki:
> > 
> > http://wiki.xen.org/wiki/Category:Host_Configuration#Linux_kernel_modules
> > 
> > In order to upkeep parallelism builds be explicit about the
> > requirement to complete all actions before any installation
> > targets.
> > 
> > Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
> > ---
> >  README                                             | 18 +++++++++++
> >  config/modules                                     | 16 ++++++++++
> 
> This list is Linux specific. If tools/hotplug/Linux/config or something
> doesn't work for the upcoming system patches then perhaps
> config/Linux.modules, where Linux is chosen to match $(XEN_OS) aka
> "uname -s".

Moved to config/Linux.modules, and made the Makefile use $(XEN_OS).

> >  tools/hotplug/Linux/Makefile                       | 36 +++++++++++++++++++---
> >  .../Linux/init.d/{xencommons => xencommons.in}     | 16 +---------
> >  4 files changed, 67 insertions(+), 19 deletions(-)
> >  create mode 100644 config/modules
> >  rename tools/hotplug/Linux/init.d/{xencommons => xencommons.in} (89%)
> > 
> > diff --git a/README b/README
> > index 9bbe734..34d7c0b 100644
> > --- a/README
> > +++ b/README
> > @@ -129,6 +129,24 @@ performed with root privileges.]
> >     versions of those scripts, so that you can copy the dist directory
> >     to another machine and install from that distribution.
> >  
> > +Required Linux modules
> > +======================
> > +
> > +Xen has a set of Linux modules which the init scripts ensure to load before
> > +enablement of xen guests. The list of modules are upkept in one place:
> 
> enablement isn't a word. I think "before starting Xen guests" is OK.
> 
> upkept also isn't, "maintained" perhaps.

Amended.

> 
> Also, end users don't care a jot about any of this. Move it right to the
> end of the README? At the moment it comes before the Python stuff which
> is end user focused.

Moved to the bottom.

> TBH if it were me I'd just put the "The file supports a simple.." as a
> comment in config/modules (wherever it ends up) and leave it at that.

Put as a comment on the config OS Linux file.

> > +  * config/modules
> > +
> > +The file supports a simple language, comments are ignored, and if you there
> > +are module replacements this can be listed by using a pipe to show preference
> > +for the first module, followed by the older module.
> > +
> > +We should strive to not require statically loading modules but it seems some
> > +systems have had issues with automatically loading some Linux kernel modules.
> > +For more details refer to:
> 
> This last paragraph is just meta commentary, IMHO it is commit log
> material (at best) rather than README material.

Nuked.

> > +http://wiki.xen.org/wiki/Category:Host_Configuration#Linux_kernel_modules
> > +
> >  Python Runtime Libraries
> >  ========================
> >  
> > diff --git a/tools/hotplug/Linux/Makefile b/tools/hotplug/Linux/Makefile
> > index d5de9e6..90b0b0c 100644
> > --- a/tools/hotplug/Linux/Makefile
> > +++ b/tools/hotplug/Linux/Makefile
> > @@ -33,17 +33,45 @@ UDEV_RULES_DIR = $(CONFIG_DIR)/udev
> >  UDEV_RULES = xen-backend.rules $(UDEV_RULES-y)
> >  
> >  .PHONY: all
> > -all:
> > +all: $(XENCOMMONS_INITD)
> > +
> > +$(XENCOMMONS_INITD): $(XEN_ROOT)/config/modules $(XENCOMMONS_INITD).in
> > +	@set -e ;							\
> > +	IFS=''								;\
> > +	cat  $(XEN_ROOT)/config/modules	| (				\
> > +		while read l ; do					\
> > +			if echo $${l} | egrep -q "^#" ; then		\
> > +				continue				;\
> > +			fi						;\
> > +			if echo "$${l}" | egrep -q "\|" ; then		\
> > +				m1=$${l%%|*}				;\
> > +				m2=$${l#*|} 				;\
> > +				echo "        modprobe $$m1 2>/dev/null || modprobe $$m2 2>/dev/null" ;\
> > +			else						\
> > +				echo "        modprobe $$l 2>/dev/null"		;\
> > +			fi						;\
> > +		done							\
> > +	) > $(XENCOMMONS_INITD).modules					;\
> > +	cat  $(XENCOMMONS_INITD).in	| (				\
> > +		while read l ; do					\
> > +			if echo "$${l}" | egrep -q "@LOAD_MODULES@" ; then \
> > +				cat $(XENCOMMONS_INITD).modules 	;\
> > +			else						\
> > +				echo $$l				;\
> > +			fi						;\
> 
> Sed with something like "/@LOAD_MODULES@/r$(...).modules" can replace
> this second loop.

I gave this a few minues minutes but couldn't figure it out, surely this can be
an evolution after ? Below is what I tried.

  Luis

diff --git a/tools/hotplug/Linux/Makefile b/tools/hotplug/Linux/Makefile
index 90b0b0c..f652451 100644
--- a/tools/hotplug/Linux/Makefile
+++ b/tools/hotplug/Linux/Makefile
@@ -35,10 +35,10 @@ UDEV_RULES = xen-backend.rules $(UDEV_RULES-y)
 .PHONY: all
 all: $(XENCOMMONS_INITD)
 
-$(XENCOMMONS_INITD): $(XEN_ROOT)/config/modules $(XENCOMMONS_INITD).in
+$(XENCOMMONS_INITD): $(XEN_ROOT)/config/$(XEN_OS).modules $(XENCOMMONS_INITD).in
 	@set -e ;							\
 	IFS=''								;\
-	cat  $(XEN_ROOT)/config/modules	| (				\
+	cat  $(XEN_ROOT)/config/$(XEN_OS).modules	| (		\
 		while read l ; do					\
 			if echo $${l} | egrep -q "^#" ; then		\
 				continue				;\
@@ -52,15 +52,12 @@ $(XENCOMMONS_INITD): $(XEN_ROOT)/config/modules $(XENCOMMONS_INITD).in
 			fi						;\
 		done							\
 	) > $(XENCOMMONS_INITD).modules					;\
-	cat  $(XENCOMMONS_INITD).in	| (				\
-		while read l ; do					\
-			if echo "$${l}" | egrep -q "@LOAD_MODULES@" ; then \
-				cat $(XENCOMMONS_INITD).modules 	;\
-			else						\
-				echo $$l				;\
-			fi						;\
-		done							\
-	) > $@
+	cat $(XENCOMMONS_INITD).in | ( 					\
+			sed -e '/@LOAD_MODULES@/ {			\
+				r $(XENCOMMONS_INITD).modules		\
+				d					\
+			}' 						\
+	) > $@								;\
 	@rm -f $(XENCOMMONS_INITD).modules
 
 .PHONY: build

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

* Re: [PATCH v6 03/13] oxenstored: add support for systemd active sockets
  2014-07-02 19:09     ` Luis R. Rodriguez
@ 2014-07-03  8:42       ` Dave Scott
  2014-07-03 17:43         ` Luis R. Rodriguez
  0 siblings, 1 reply; 66+ messages in thread
From: Dave Scott @ 2014-07-03  8:42 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: Dave Scott, Ian Campbell, Luis R. Rodriguez, Vincent Hanquez,
	Stefano Stabellini, Ian Jackson, xen-devel


On 2 Jul 2014, at 20:09, Luis R. Rodriguez <mcgrof@suse.com> wrote:

> On Wed, Jul 02, 2014 at 02:08:23PM +0100, Ian Campbell wrote:
>> On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
>>> diff --git a/tools/ocaml/xenstored/systemd.ml b/tools/ocaml/xenstored/systemd.ml
>>> new file mode 100644
>>> index 0000000..2aa39ea
>>> --- /dev/null
>>> +++ b/tools/ocaml/xenstored/systemd.ml
>> 
>> Ideally the systemd ocaml bindings would come from a suitable ocaml
>> library (opam or whatever). I suppose such a thing doesn't exist
>> already?
> 
> Not that I was able to find but Ocaml folks can chime in.
> 
>> Perhaps Dave or Anil etc could advise on the feasibility of publishing
>> these bindings as a separate project. In general I'd much rather we
>> added build dependencies for things like that than incorporate things
>> which are nothing to do with Xen etc into the tree (we've done too much
>> of that in the past…)

The bindings could easily be published separately and then shared amongst several projects. They’ll be needed eventually for xapi anyway, so they could live somewhere in the xapi-project on github.

I like the principle that we should prefer build dependencies to incorporating non-core things in-tree. I’d like to do some trimming— for example Mirage has a nice xenstore client library that works in both userspace and kernelspace that we could use instead of the one currently in the tree which is userspace-only. Some of the other mirage libraries (such as the branching key-value store, ‘irmin’) ought to make the oxenstored implementation a lot smaller too.

> Can't this be done as a separate step?

Adding these non-core bindings would violate this nice principle. However, if it’s only a couple of functions within oxenstored and not a whole new library (that would doubtless get packaged and probably end up conflicting with our stand-alone version and confusing people)... I could live with it, if this feature is considered important.

Cheers,
Dave

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

* Re: [PATCH v6 02/13] cxenstored: add support for systemd active sockets
  2014-07-02 19:00     ` Luis R. Rodriguez
@ 2014-07-03  9:13       ` Ian Campbell
  2014-07-03 17:06         ` Luis R. Rodriguez
  0 siblings, 1 reply; 66+ messages in thread
From: Ian Campbell @ 2014-07-03  9:13 UTC (permalink / raw)
  To: Luis R. Rodriguez; +Cc: xen-devel, Luis R. Rodriguez

On Wed, 2014-07-02 at 21:00 +0200, Luis R. Rodriguez wrote:
> On Wed, Jul 02, 2014 at 02:02:38PM +0100, Ian Campbell wrote:
> > On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
> > > +int xs_validate_active_socket(const char *connect_to)
> > > +{
> > > +	char sock[30];
> > > +
> > > +	/* We have to null terminate the socket path */
> > > +	memset(sock, '\0', sizeof(sock));
> > > +	memcpy(sock, connect_to, strlen(connect_to));
> > 
> > This risks overrunning sock if connect_to is longer than 30 characters.
> 
> Yuk, yes. A size check is required.
> 
> > But your use of strlen suggests that connect_to is already NULL
> > terminated, so what is this for?
> 
> strlen() seems to want the string to also be null terminated
> in order to work, and I also see that snprintf() is ultimately
> used on the C version of the library, that should ensure its null
> terminated. This however is not true for the ocaml version and
> I suppose that is the root of the issue I saw that got me to
> force null terimination as I did run into issues with this path
> IIRC when not null terminated.
> 
> > > +	if ((strncmp("/var/run/xenstored/socket_ro", sock, 28) != 0) &&
> > > +	    (strncmp("/var/run/xenstored/socket", sock, 25) != 0)) {
> > 
> > Given that sock (or connect_to) is NULL terminated, why strncmp and not
> > the straightforward strcmp?
> 
> See above.
> 
> > As it is I think your code would accept
> > e.g. /var/run/xenstored/socketwibble, no?
> 
> It indeed would, its best if we resolve the null termination
> issue internally then.

Yeah, I think we should write the C version according to normal C string
conventions. If the ocaml idea of a string differs then perhaps that
version needs to be different.

> > Is it common in systemd support to validate the input socket's path in
> > this way? As opposed to trusting that the systemd unit file is correct.
> 
> sd_is_socket_unix() is certainly advised and highly encourged. As
> for the other check -- yes we want that given that we are using
> two socket files specifically in order to avoid having to chmod()
> the socket ourelves. Systemd currently doesn't support having two
> separate sockets in one file with different permissions. From
> what I have seen the order in which systemd sets the sockets and
> maps them to fds will very on the unit socket files you use, this
> approach lets us allow systemd to give them to us in any order
> while my hope is that systemd upstream gets support for just one
> stocket file with multiple permissions.

OK.

BTW, the permissions on these two sockets should be the same
(read/write), it's the owner/group which might differ.

(You need to be able to write to the ro socket to send operations, the
distinction is that the ro socket will reject XS_WRITE messages)

> > > +static void xen_claim_active_sockets(int **psock, int **pro_sock)
> > > +{
> > > +	int *sock, *ro_sock;
> > > +	const char *soc_str = xs_daemon_socket();
> > > +	const char *soc_str_ro = xs_daemon_socket_ro();
> > > +	int n;
> > > +
> > > +	n = sd_listen_fds(0);
> > > +	if (n <= 0) {
> > > +		sd_notifyf(0, "STATUS=Failed to get any active sockets: %s\n"
> > > +			   "ERRNO=%i",
> > > +			   strerror(errno),
> > > +			   errno);
> > > +		barf_perror("sd_listen_fds() failed\n");
> > > +	} else if (n > 2) {
> > > +		fprintf(stderr, SD_ERR "Expected 2 fds but given %d\n", n);
> > > +		sd_notifyf(0, "STATUS=Mismatch on number (2): %s\n"
> > > +			   "ERRNO=%d",
> > > +			   strerror(EBADR),
> > > +			   EBADR);
> > > +		barf_perror("sd_listen_fds() gave too many fds\n");
> > 
> > Need this be fatal?
> 
> You can do anything you want but IMO yes, otherwise we'd be misconfigured and there
> is a mismatch.

OK.

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

* Re: [PATCH v6 10/13] autoconf: xen: move standard path variables to config/Paths.mk.in
  2014-07-02 19:32     ` Luis R. Rodriguez
@ 2014-07-03  9:15       ` Ian Campbell
  2014-07-03 18:30         ` Luis R. Rodriguez
  0 siblings, 1 reply; 66+ messages in thread
From: Ian Campbell @ 2014-07-03  9:15 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: Keir Fraser, Luis R. Rodriguez, Tim Deegan, Ian Jackson,
	Jan Beulich, Samuel Thibault, xen-devel

On Wed, 2014-07-02 at 21:32 +0200, Luis R. Rodriguez wrote:
> On Wed, Jul 02, 2014 at 02:34:14PM +0100, Ian Campbell wrote:
> > On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
> > > diff --git a/m4/paths.m4 b/m4/paths.m4
> > > new file mode 100644
> > > index 0000000..717fcd1
> > > --- /dev/null
> > > +++ b/m4/paths.m4
> > > @@ -0,0 +1,61 @@
> > > +AC_DEFUN([AX_XEN_EXPAND_CONFIG], [
> > > +dnl expand these early so we can use this for substitutions
> > > +test "x$prefix" = "xNONE" && prefix=$ac_default_prefix
> > > +test "x$exec_prefix" = "xNONE" && exec_prefix=$ac_default_prefix
> > 
> > This is a bit of shame. I suppose this needs to happen in the middle of
> > AC_OUTPUT which isn't possible?
> > 
> > autoconf itself seems to quote the prefix so it is not expanded until
> > later, i.e. when config.status is run. Would that work here?
> 
> Its unclear what exactly the recommendation is here.
> 
> > Or perhaps we should just PREFIX=$prefix AC_SUBST(PREFIX) and put all
> > the BINDIR=$PREFIX/bin into Paths.mk.in after PREFIX=@PREFIX@?
> 
> Why though?

To avoid cutting and pasting the snippet of autoconf internal code:
        test "x$prefix" = "xNONE" && prefix=$ac_default_prefix
into our m4 code.

Ian.

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

* Re: [PATCH v6 11/13] xencommons: move module list into a generic place
  2014-07-02 21:56     ` Luis R. Rodriguez
@ 2014-07-03  9:15       ` Ian Campbell
  0 siblings, 0 replies; 66+ messages in thread
From: Ian Campbell @ 2014-07-03  9:15 UTC (permalink / raw)
  To: Luis R. Rodriguez; +Cc: xen-devel, Luis R. Rodriguez

On Wed, 2014-07-02 at 23:56 +0200, Luis R. Rodriguez wrote:

> > Sed with something like "/@LOAD_MODULES@/r$(...).modules" can replace
> > this second loop.
> 
> I gave this a few minues minutes but couldn't figure it out, surely this can be
> an evolution after ?

OK.

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

* Re: [PATCH v6 12/13] autoconf: xen: enable explicit preference option for xenstored preference
  2014-07-02 20:09     ` Luis R. Rodriguez
@ 2014-07-03  9:20       ` Ian Campbell
  2014-07-03 18:57         ` Luis R. Rodriguez
  0 siblings, 1 reply; 66+ messages in thread
From: Ian Campbell @ 2014-07-03  9:20 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: Keir Fraser, Luis R. Rodriguez, Tim Deegan, Ian Jackson,
	Jan Beulich, xen-devel

On Wed, 2014-07-02 at 22:09 +0200, Luis R. Rodriguez wrote:
> On Wed, Jul 02, 2014 at 02:54:31PM +0100, Ian Campbell wrote:
> > On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
> > > Since the xenstored preference
> > > is explicit now and since we require configure substitutions for it we
> > > make use of the AX_XEN_EXPAND_CONFIG() helpers as otherwise substitution
> > > for SBINDIR is not propagated from the top level configuration.
> > 
> > I'm afraid I don't understand what is going on here. Why is SBINDIR not
> > propagated?
> 
> Its saying that we need AX_XEN_EXPAND_CONFIG() in order to do substitutions
> for variables that include SBINDIR in this case for the xenstore full path.

Specifically you mean that the autoconf/m4 code now uses these variables
in addition to them appearing in Paths.mk? Strictly speaking you don't
need the associated AC_SUBST's but they are harmless.

> 
> > > Since we are now parsing an entry within Paths.mk.in on tools we let
> > > the move the parsing of the file to be the tool's configure.
> >
> > I can't parse this.
> 
> I meant to clarify that since we now have to do a substitution on tools
> we move the calls to AX_XEN_EXPAND_CONFIG() there. This patch should have
> also removed the AX_XEN_EXPAND_CONFIG() from the top level configure.ac.

I think moving it would break stubdoms under ./configure
--disable-tools?

I think I would suggest keeping AX_XEN_EXPAND_CONFIG and the generation
of config/Paths.mk in the top level configure but call
AX_XEN_EXPAND_CONFIG again in tools/configure.ac without the generation
of config/Paths.mk (I think the AC_SUBST's are benign for this second
call)

> After testing this though and removing AX_XEN_EXPAND_CONFIG() from configure.ac
> I do see though that substitution doesn't work, it only works if we leave
> AX_XEN_EXPAND_CONFIG() on both places. 

I should have read this next para before commenting above!

> This is the issue I mentioned that
> I ran into and you had proposed we could try to figure out a fix if
> this was happening. Well it is. Any ideas ? Or are you OK to live with
> calling AX_XEN_EXPAND_CONFIG() twice, once on configure.ac and another
> on tools/configure.ac ?

Yes, so long as the generation of config/Paths.mk remains in the
toplevel configure only.

Ian.

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

* Re: [PATCH v6 02/13] cxenstored: add support for systemd active sockets
  2014-07-03  9:13       ` Ian Campbell
@ 2014-07-03 17:06         ` Luis R. Rodriguez
  2014-07-04 14:32           ` Ian Campbell
  2014-07-17 19:45           ` Luis R. Rodriguez
  0 siblings, 2 replies; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-07-03 17:06 UTC (permalink / raw)
  To: Ian Campbell, David Scott; +Cc: xen-devel, Luis R. Rodriguez

On Thu, Jul 03, 2014 at 10:13:05AM +0100, Ian Campbell wrote:
> On Wed, 2014-07-02 at 21:00 +0200, Luis R. Rodriguez wrote:
> > On Wed, Jul 02, 2014 at 02:02:38PM +0100, Ian Campbell wrote:
> > > On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
> > > > +int xs_validate_active_socket(const char *connect_to)
> > > > +{
> > > > +	char sock[30];
> > > > +
> > > > +	/* We have to null terminate the socket path */
> > > > +	memset(sock, '\0', sizeof(sock));
> > > > +	memcpy(sock, connect_to, strlen(connect_to));
> > > 
> > > This risks overrunning sock if connect_to is longer than 30 characters.
> > 
> > Yuk, yes. A size check is required.
> > 
> > > But your use of strlen suggests that connect_to is already NULL
> > > terminated, so what is this for?
> > 
> > strlen() seems to want the string to also be null terminated
> > in order to work, and I also see that snprintf() is ultimately
> > used on the C version of the library, that should ensure its null
> > terminated. This however is not true for the ocaml version and
> > I suppose that is the root of the issue I saw that got me to
> > force null terimination as I did run into issues with this path
> > IIRC when not null terminated.
> > 
> > > > +	if ((strncmp("/var/run/xenstored/socket_ro", sock, 28) != 0) &&
> > > > +	    (strncmp("/var/run/xenstored/socket", sock, 25) != 0)) {
> > > 
> > > Given that sock (or connect_to) is NULL terminated, why strncmp and not
> > > the straightforward strcmp?
> > 
> > See above.
> > 
> > > As it is I think your code would accept
> > > e.g. /var/run/xenstored/socketwibble, no?
> > 
> > It indeed would, its best if we resolve the null termination
> > issue internally then.
> 
> Yeah, I think we should write the C version according to normal C string
> conventions. If the ocaml idea of a string differs then perhaps that
> version needs to be different.

OK, or we ensure Ocaml's implementation provides a null terminated
string to try to keep the systemd interface similar, poking Dave for
feedback:

String_val() is used for the static string connect_to passed to the
C wrapper, the String_val() documentation [0] says that "there is a null
character after the last character in the string" however its unclear
if this is guaranteed if the string was originally a static Ocaml string
which was not null terminated. 

Now, its unclear which xenstored (cxenstored or oxenstored) gave me issues
that pushed me to ensure I give systemd null terminated strings but
I do know that it was one for sure and it took me quite a bit to figure
out this was needed and that this was the issue. Based on my review just
now since the cxenstored uses snprintf() for both xs_daemon_socket_ro()
and xs_daemon_socket() and since snprintf() man page says that it will
write at most size bytes (including the terminating null byte ('\0') I
am left to only grow suspcicious of the oxenstored as the probable
cause of the issues I saw. I should also highlight that the socket path
can also come from environment variables on cxenstored, XENSTORED_PATH,
and getenv() documentation doesn't say whether or not strings will be
null terminated for us, that might cause unexpected issues if used and
if it doesn't on systemd.

In v5 systemd integration implementation in which I used static structs
for the strings in C I had no issues but note that in that case I simply
used the Ocaml string (after String_val()) to and compare it to the one
on the static C array with:

	(!strcmp(connect_to, xenstore_active_sockets[i].path))

I then used the C static string for sd_is_socket_unix(), not the one
passed from cxenstored or oxenstored.

[0] http://caml.inria.fr/pub/docs/manual-ocaml-400/manual033.html

> > > Is it common in systemd support to validate the input socket's path in
> > > this way? As opposed to trusting that the systemd unit file is correct.
> > 
> > sd_is_socket_unix() is certainly advised and highly encourged. As
> > for the other check -- yes we want that given that we are using
> > two socket files specifically in order to avoid having to chmod()
> > the socket ourelves. Systemd currently doesn't support having two
> > separate sockets in one file with different permissions. From
> > what I have seen the order in which systemd sets the sockets and
> > maps them to fds will very on the unit socket files you use, this
> > approach lets us allow systemd to give them to us in any order
> > while my hope is that systemd upstream gets support for just one
> > stocket file with multiple permissions.
> 
> OK.
> 
> BTW, the permissions on these two sockets should be the same
> (read/write),

tools/xenstore/xenstored_core.c uses chmod to change the
permissions:

        if (chmod(soc_str, 0600) != 0
            || chmod(soc_str_ro, 0660) != 0)
                barf_perror("Could not chmod sockets");

> it's the owner/group which might differ.

On my latest Debian install of the master branch for legacy init
my sockets end up being owned by root, who should be owning the
sockets?

> (You need to be able to write to the ro socket to send operations,

BTW what is the _ro socket used for exactly? I couldn't find usage for
it in existing code.

> the distinction is that the ro socket will reject XS_WRITE messages)

OK, got it.

  Luis

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

* Re: [PATCH v6 03/13] oxenstored: add support for systemd active sockets
  2014-07-03  8:42       ` Dave Scott
@ 2014-07-03 17:43         ` Luis R. Rodriguez
  0 siblings, 0 replies; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-07-03 17:43 UTC (permalink / raw)
  To: Dave Scott
  Cc: Ian Campbell, Luis R. Rodriguez, Vincent Hanquez,
	Stefano Stabellini, Ian Jackson, xen-devel

On Thu, Jul 03, 2014 at 08:42:11AM +0000, Dave Scott wrote:
> 
> On 2 Jul 2014, at 20:09, Luis R. Rodriguez <mcgrof@suse.com> wrote:
> 
> > On Wed, Jul 02, 2014 at 02:08:23PM +0100, Ian Campbell wrote:
> >> On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
> >>> diff --git a/tools/ocaml/xenstored/systemd.ml b/tools/ocaml/xenstored/systemd.ml
> >>> new file mode 100644
> >>> index 0000000..2aa39ea
> >>> --- /dev/null
> >>> +++ b/tools/ocaml/xenstored/systemd.ml
> >> 
> >> Ideally the systemd ocaml bindings would come from a suitable ocaml
> >> library (opam or whatever). I suppose such a thing doesn't exist
> >> already?
> > 
> > Not that I was able to find but Ocaml folks can chime in.
> > 
> >> Perhaps Dave or Anil etc could advise on the feasibility of publishing
> >> these bindings as a separate project. In general I'd much rather we
> >> added build dependencies for things like that than incorporate things
> >> which are nothing to do with Xen etc into the tree (we've done too much
> >> of that in the past…)
> 
> The bindings could easily be published separately and then shared amongst
> several projects. They’ll be needed eventually for xapi anyway, so they could
> live somewhere in the xapi-project on github.
> 
> I like the principle that we should prefer build dependencies to
> incorporating non-core things in-tree. I’d like to do some trimming— for
> example Mirage has a nice xenstore client library that works in both
> userspace and kernelspace that we could use instead of the one currently in
> the tree which is userspace-only. Some of the other mirage libraries (such as
> the branching key-value store, ‘irmin’) ought to make the oxenstored
> implementation a lot smaller too.

I followed the license practice in-use for oxenstored for the systemd
interface, however I'm put to relicense the code to whatever might be
helpful for the purposes you mentioned, let me know.

> > Can't this be done as a separate step?
> 
> Adding these non-core bindings would violate this nice principle. However, if
> it’s only a couple of functions within oxenstored and not a whole new library
> (that would doubtless get packaged and probably end up conflicting with our
> stand-alone version and confusing people)... I could live with it, if this
> feature is considered important.

You folks make the call.

  Luis

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

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

* Re: [PATCH v6 10/13] autoconf: xen: move standard path variables to config/Paths.mk.in
  2014-07-03  9:15       ` Ian Campbell
@ 2014-07-03 18:30         ` Luis R. Rodriguez
  2014-07-04 14:33           ` Ian Campbell
  0 siblings, 1 reply; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-07-03 18:30 UTC (permalink / raw)
  To: Ian Campbell
  Cc: Keir Fraser, Luis R. Rodriguez, Tim Deegan, Ian Jackson,
	Jan Beulich, Samuel Thibault, xen-devel

On Thu, Jul 03, 2014 at 10:15:13AM +0100, Ian Campbell wrote:
> On Wed, 2014-07-02 at 21:32 +0200, Luis R. Rodriguez wrote:
> > On Wed, Jul 02, 2014 at 02:34:14PM +0100, Ian Campbell wrote:
> > > On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
> > > > diff --git a/m4/paths.m4 b/m4/paths.m4
> > > > new file mode 100644
> > > > index 0000000..717fcd1
> > > > --- /dev/null
> > > > +++ b/m4/paths.m4
> > > > @@ -0,0 +1,61 @@
> > > > +AC_DEFUN([AX_XEN_EXPAND_CONFIG], [
> > > > +dnl expand these early so we can use this for substitutions
> > > > +test "x$prefix" = "xNONE" && prefix=$ac_default_prefix
> > > > +test "x$exec_prefix" = "xNONE" && exec_prefix=$ac_default_prefix
> > > 
> > > This is a bit of shame. I suppose this needs to happen in the middle of
> > > AC_OUTPUT which isn't possible?
> > > 
> > > autoconf itself seems to quote the prefix so it is not expanded until
> > > later, i.e. when config.status is run. Would that work here?
> > 
> > Its unclear what exactly the recommendation is here.
> > 
> > > Or perhaps we should just PREFIX=$prefix AC_SUBST(PREFIX) and put all
> > > the BINDIR=$PREFIX/bin into Paths.mk.in after PREFIX=@PREFIX@?
> > 
> > Why though?
> 
> To avoid cutting and pasting the snippet of autoconf internal code:
>         test "x$prefix" = "xNONE" && prefix=$ac_default_prefix
> into our m4 code.

Ah but that would mean not being able to use --prefix then no?

  Luis

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

* Re: [PATCH v6 10/13] autoconf: xen: move standard path variables to config/Paths.mk.in
  2014-07-02 13:34   ` Ian Campbell
  2014-07-02 19:32     ` Luis R. Rodriguez
@ 2014-07-03 18:53     ` Luis R. Rodriguez
  2014-07-04 14:36       ` Ian Campbell
  1 sibling, 1 reply; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-07-03 18:53 UTC (permalink / raw)
  To: Ian Campbell
  Cc: Keir Fraser, Luis R. Rodriguez, Tim Deegan, Ian Jackson,
	Jan Beulich, Samuel Thibault, xen-devel

On Wed, Jul 02, 2014 at 02:34:14PM +0100, Ian Campbell wrote:
> On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
> > From: "Luis R. Rodriguez" <mcgrof@suse.com>
> > +LIBDIR=`eval echo $libdir`
> 
> Why is this one an eval?

BTW I now see why I had used the eval on LIBDIR, its because otherwise Paths.mk
ends up with:

LIBDIR                   := ${exec_prefix}/lib64
...
PRIVATE_PREFIX           := ${exec_prefix}/lib64/xen
PRIVATE_PREFIX           := ${exec_prefix}/lib64/xen
PRIVATE_BINDIR           := ${exec_prefix}/lib64/xen/bin
...

Can I upkeep the eval?

  Luis

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

* Re: [PATCH v6 12/13] autoconf: xen: enable explicit preference option for xenstored preference
  2014-07-03  9:20       ` Ian Campbell
@ 2014-07-03 18:57         ` Luis R. Rodriguez
  2014-07-04 14:37           ` Ian Campbell
  0 siblings, 1 reply; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-07-03 18:57 UTC (permalink / raw)
  To: Ian Campbell
  Cc: Keir Fraser, Luis R. Rodriguez, Tim Deegan, Ian Jackson,
	Jan Beulich, xen-devel

On Thu, Jul 03, 2014 at 10:20:40AM +0100, Ian Campbell wrote:
> On Wed, 2014-07-02 at 22:09 +0200, Luis R. Rodriguez wrote:
> > On Wed, Jul 02, 2014 at 02:54:31PM +0100, Ian Campbell wrote:
> > > On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
> > > > Since the xenstored preference
> > > > is explicit now and since we require configure substitutions for it we
> > > > make use of the AX_XEN_EXPAND_CONFIG() helpers as otherwise substitution
> > > > for SBINDIR is not propagated from the top level configuration.
> > > 
> > > I'm afraid I don't understand what is going on here. Why is SBINDIR not
> > > propagated?
> > 
> > Its saying that we need AX_XEN_EXPAND_CONFIG() in order to do substitutions
> > for variables that include SBINDIR in this case for the xenstore full path.
> 
> Specifically you mean that the autoconf/m4 code now uses these variables
> in addition to them appearing in Paths.mk?

Right.

> Strictly speaking you don't
> need the associated AC_SUBST's but they are harmless.

Without the AC_SUBST() I do not believe substitiution is done by 
autoconf on Paths.mk.

> > > > Since we are now parsing an entry within Paths.mk.in on tools we let
> > > > the move the parsing of the file to be the tool's configure.
> > >
> > > I can't parse this.
> > 
> > I meant to clarify that since we now have to do a substitution on tools
> > we move the calls to AX_XEN_EXPAND_CONFIG() there. This patch should have
> > also removed the AX_XEN_EXPAND_CONFIG() from the top level configure.ac.
> 
> I think moving it would break stubdoms under ./configure
> --disable-tools?
> 
> I think I would suggest keeping AX_XEN_EXPAND_CONFIG and the generation
> of config/Paths.mk in the top level configure but call
> AX_XEN_EXPAND_CONFIG again in tools/configure.ac without the generation
> of config/Paths.mk (I think the AC_SUBST's are benign for this second
> call)

AX_XEN_EXPAND_CONFIG() is needed in both as we rely on some variable
substitutions like SBINDIR on the tools path as well.

> > After testing this though and removing AX_XEN_EXPAND_CONFIG() from configure.ac
> > I do see though that substitution doesn't work, it only works if we leave
> > AX_XEN_EXPAND_CONFIG() on both places. 
> 
> I should have read this next para before commenting above!

OK I take it this means I can keep it on both?

> > This is the issue I mentioned that
> > I ran into and you had proposed we could try to figure out a fix if
> > this was happening. Well it is. Any ideas ? Or are you OK to live with
> > calling AX_XEN_EXPAND_CONFIG() twice, once on configure.ac and another
> > on tools/configure.ac ?
> 
> Yes, so long as the generation of config/Paths.mk remains in the
> toplevel configure only.

OK so use AX_XEN_EXPAND_CONFIG() on both top level configure.ac and
tools/configure.ac but only have config/Paths.mk be a AC_CONFIG_FILES()
for the top level configure.ac ?

I think that's how the v6 patch was then.

  Luis

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

* Re: [PATCH v6 02/13] cxenstored: add support for systemd active sockets
  2014-07-03 17:06         ` Luis R. Rodriguez
@ 2014-07-04 14:32           ` Ian Campbell
  2014-07-08  3:08             ` Luis R. Rodriguez
  2014-07-17 19:45           ` Luis R. Rodriguez
  1 sibling, 1 reply; 66+ messages in thread
From: Ian Campbell @ 2014-07-04 14:32 UTC (permalink / raw)
  To: Luis R. Rodriguez; +Cc: xen-devel, David Scott, Luis R. Rodriguez

On Thu, 2014-07-03 at 19:06 +0200, Luis R. Rodriguez wrote:
> > > > Is it common in systemd support to validate the input socket's path in
> > > > this way? As opposed to trusting that the systemd unit file is correct.
> > > 
> > > sd_is_socket_unix() is certainly advised and highly encourged. As
> > > for the other check -- yes we want that given that we are using
> > > two socket files specifically in order to avoid having to chmod()
> > > the socket ourelves. Systemd currently doesn't support having two
> > > separate sockets in one file with different permissions. From
> > > what I have seen the order in which systemd sets the sockets and
> > > maps them to fds will very on the unit socket files you use, this
> > > approach lets us allow systemd to give them to us in any order
> > > while my hope is that systemd upstream gets support for just one
> > > stocket file with multiple permissions.
> > 
> > OK.
> > 
> > BTW, the permissions on these two sockets should be the same
> > (read/write),
> 
> tools/xenstore/xenstored_core.c uses chmod to change the
> permissions:
> 
>         if (chmod(soc_str, 0600) != 0
>             || chmod(soc_str_ro, 0660) != 0)
>                 barf_perror("Could not chmod sockets");
> 
> > it's the owner/group which might differ.
> 
> On my latest Debian install of the master branch for legacy init
> my sockets end up being owned by root, who should be owning the
> sockets?

My mistake, I thought they were 0660 and root:root and 0660 root:
$something. But 0600 for the rw makes sense too.

Default owner should be root:root for both IMHO. The ro socket is there
for the admin if he wants to chgrp it and put things in that group.

> > (You need to be able to write to the ro socket to send operations,
> 
> BTW what is the _ro socket used for exactly? I couldn't find usage for
> it in existing code.
> 
> > the distinction is that the ro socket will reject XS_WRITE messages)
> 
> OK, got it.
> 
>   Luis

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

* Re: [PATCH v6 10/13] autoconf: xen: move standard path variables to config/Paths.mk.in
  2014-07-03 18:30         ` Luis R. Rodriguez
@ 2014-07-04 14:33           ` Ian Campbell
  2014-07-08 18:41             ` Luis R. Rodriguez
  0 siblings, 1 reply; 66+ messages in thread
From: Ian Campbell @ 2014-07-04 14:33 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: Keir Fraser, Luis R. Rodriguez, Tim Deegan, Ian Jackson,
	Jan Beulich, Samuel Thibault, xen-devel

On Thu, 2014-07-03 at 20:30 +0200, Luis R. Rodriguez wrote:
> On Thu, Jul 03, 2014 at 10:15:13AM +0100, Ian Campbell wrote:
> > On Wed, 2014-07-02 at 21:32 +0200, Luis R. Rodriguez wrote:
> > > On Wed, Jul 02, 2014 at 02:34:14PM +0100, Ian Campbell wrote:
> > > > On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
> > > > > diff --git a/m4/paths.m4 b/m4/paths.m4
> > > > > new file mode 100644
> > > > > index 0000000..717fcd1
> > > > > --- /dev/null
> > > > > +++ b/m4/paths.m4
> > > > > @@ -0,0 +1,61 @@
> > > > > +AC_DEFUN([AX_XEN_EXPAND_CONFIG], [
> > > > > +dnl expand these early so we can use this for substitutions
> > > > > +test "x$prefix" = "xNONE" && prefix=$ac_default_prefix
> > > > > +test "x$exec_prefix" = "xNONE" && exec_prefix=$ac_default_prefix
> > > > 
> > > > This is a bit of shame. I suppose this needs to happen in the middle of
> > > > AC_OUTPUT which isn't possible?
> > > > 
> > > > autoconf itself seems to quote the prefix so it is not expanded until
> > > > later, i.e. when config.status is run. Would that work here?
> > > 
> > > Its unclear what exactly the recommendation is here.
> > > 
> > > > Or perhaps we should just PREFIX=$prefix AC_SUBST(PREFIX) and put all
> > > > the BINDIR=$PREFIX/bin into Paths.mk.in after PREFIX=@PREFIX@?
> > > 
> > > Why though?
> > 
> > To avoid cutting and pasting the snippet of autoconf internal code:
> >         test "x$prefix" = "xNONE" && prefix=$ac_default_prefix
> > into our m4 code.
> 
> Ah but that would mean not being able to use --prefix then no?

I hope not.

autoconf generates this snippet in configure itself, by deferring the
evaluation of things I'm hoping that the content of Paths.mk.in can be
evaluated after that snippet has run.

Ian.

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

* Re: [PATCH v6 10/13] autoconf: xen: move standard path variables to config/Paths.mk.in
  2014-07-03 18:53     ` Luis R. Rodriguez
@ 2014-07-04 14:36       ` Ian Campbell
  2014-07-08 18:52         ` Luis R. Rodriguez
  0 siblings, 1 reply; 66+ messages in thread
From: Ian Campbell @ 2014-07-04 14:36 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: Keir Fraser, Luis R. Rodriguez, Tim Deegan, Ian Jackson,
	Jan Beulich, Samuel Thibault, xen-devel

On Thu, 2014-07-03 at 20:53 +0200, Luis R. Rodriguez wrote:
> On Wed, Jul 02, 2014 at 02:34:14PM +0100, Ian Campbell wrote:
> > On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
> > > From: "Luis R. Rodriguez" <mcgrof@suse.com>
> > > +LIBDIR=`eval echo $libdir`
> > 
> > Why is this one an eval?
> 
> BTW I now see why I had used the eval on LIBDIR, its because otherwise Paths.mk
> ends up with:
> 
> LIBDIR                   := ${exec_prefix}/lib64
> ...
> PRIVATE_PREFIX           := ${exec_prefix}/lib64/xen
> PRIVATE_PREFIX           := ${exec_prefix}/lib64/xen
> PRIVATE_BINDIR           := ${exec_prefix}/lib64/xen/bin
> ...
> 
> Can I upkeep the eval?

Seems a bit odd that this would only affect LIBDIR and not PREFIX.

I'd like to understand why this happens before reaching for the eval (or
to see some autoconf documentation that claims this is the right thing
to do).

Ian.

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

* Re: [PATCH v6 12/13] autoconf: xen: enable explicit preference option for xenstored preference
  2014-07-03 18:57         ` Luis R. Rodriguez
@ 2014-07-04 14:37           ` Ian Campbell
  2014-07-08 18:54             ` Luis R. Rodriguez
  0 siblings, 1 reply; 66+ messages in thread
From: Ian Campbell @ 2014-07-04 14:37 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: Keir Fraser, Luis R. Rodriguez, Tim Deegan, Ian Jackson,
	Jan Beulich, xen-devel

On Thu, 2014-07-03 at 20:57 +0200, Luis R. Rodriguez wrote:

> > Strictly speaking you don't
> > need the associated AC_SUBST's but they are harmless.
> 
> Without the AC_SUBST() I do not believe substitiution is done by 
> autoconf on Paths.mk.

For tools/configure you won't be creating Paths.mk, so it doesn't
matter.

> OK so use AX_XEN_EXPAND_CONFIG() on both top level configure.ac and
> tools/configure.ac but only have config/Paths.mk be a AC_CONFIG_FILES()
> for the top level configure.ac ?

yes.

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

* Re: [PATCH v6 02/13] cxenstored: add support for systemd active sockets
  2014-07-04 14:32           ` Ian Campbell
@ 2014-07-08  3:08             ` Luis R. Rodriguez
  0 siblings, 0 replies; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-07-08  3:08 UTC (permalink / raw)
  To: Ian Campbell; +Cc: xen-devel, David Scott, Luis R. Rodriguez

On Fri, Jul 04, 2014 at 03:32:29PM +0100, Ian Campbell wrote:
> On Thu, 2014-07-03 at 19:06 +0200, Luis R. Rodriguez wrote:
> > > > > Is it common in systemd support to validate the input socket's path in
> > > > > this way? As opposed to trusting that the systemd unit file is correct.
> > > > 
> > > > sd_is_socket_unix() is certainly advised and highly encourged. As
> > > > for the other check -- yes we want that given that we are using
> > > > two socket files specifically in order to avoid having to chmod()
> > > > the socket ourelves. Systemd currently doesn't support having two
> > > > separate sockets in one file with different permissions. From
> > > > what I have seen the order in which systemd sets the sockets and
> > > > maps them to fds will very on the unit socket files you use, this
> > > > approach lets us allow systemd to give them to us in any order
> > > > while my hope is that systemd upstream gets support for just one
> > > > stocket file with multiple permissions.
> > > 
> > > OK.
> > > 
> > > BTW, the permissions on these two sockets should be the same
> > > (read/write),
> > 
> > tools/xenstore/xenstored_core.c uses chmod to change the
> > permissions:
> > 
> >         if (chmod(soc_str, 0600) != 0
> >             || chmod(soc_str_ro, 0660) != 0)
> >                 barf_perror("Could not chmod sockets");
> > 
> > > it's the owner/group which might differ.
> > 
> > On my latest Debian install of the master branch for legacy init
> > my sockets end up being owned by root, who should be owning the
> > sockets?
> 
> My mistake, I thought they were 0660 and root:root and 0660 root:
> $something. But 0600 for the rw makes sense too.
> 
> Default owner should be root:root for both IMHO. The ro socket is there
> for the admin if he wants to chgrp it and put things in that group.

OK my patches upkeep the existing implementation design then.

  Luis

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

* Re: [PATCH v6 10/13] autoconf: xen: move standard path variables to config/Paths.mk.in
  2014-07-04 14:33           ` Ian Campbell
@ 2014-07-08 18:41             ` Luis R. Rodriguez
  2014-07-08 18:53               ` Luis R. Rodriguez
  0 siblings, 1 reply; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-07-08 18:41 UTC (permalink / raw)
  To: Ian Campbell
  Cc: Keir Fraser, Luis R. Rodriguez, Tim Deegan, Ian Jackson,
	Jan Beulich, Samuel Thibault, xen-devel

On Fri, Jul 04, 2014 at 03:33:55PM +0100, Ian Campbell wrote:
> On Thu, 2014-07-03 at 20:30 +0200, Luis R. Rodriguez wrote:
> > On Thu, Jul 03, 2014 at 10:15:13AM +0100, Ian Campbell wrote:
> > > On Wed, 2014-07-02 at 21:32 +0200, Luis R. Rodriguez wrote:
> > > > On Wed, Jul 02, 2014 at 02:34:14PM +0100, Ian Campbell wrote:
> > > > > On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
> > > > > > diff --git a/m4/paths.m4 b/m4/paths.m4
> > > > > > new file mode 100644
> > > > > > index 0000000..717fcd1
> > > > > > --- /dev/null
> > > > > > +++ b/m4/paths.m4
> > > > > > @@ -0,0 +1,61 @@
> > > > > > +AC_DEFUN([AX_XEN_EXPAND_CONFIG], [
> > > > > > +dnl expand these early so we can use this for substitutions
> > > > > > +test "x$prefix" = "xNONE" && prefix=$ac_default_prefix
> > > > > > +test "x$exec_prefix" = "xNONE" && exec_prefix=$ac_default_prefix
> > > > > 
> > > > > This is a bit of shame. I suppose this needs to happen in the middle of
> > > > > AC_OUTPUT which isn't possible?
> > > > > 
> > > > > autoconf itself seems to quote the prefix so it is not expanded until
> > > > > later, i.e. when config.status is run. Would that work here?
> > > > 
> > > > Its unclear what exactly the recommendation is here.
> > > > 
> > > > > Or perhaps we should just PREFIX=$prefix AC_SUBST(PREFIX) and put all
> > > > > the BINDIR=$PREFIX/bin into Paths.mk.in after PREFIX=@PREFIX@?
> > > > 
> > > > Why though?
> > > 
> > > To avoid cutting and pasting the snippet of autoconf internal code:
> > >         test "x$prefix" = "xNONE" && prefix=$ac_default_prefix
> > > into our m4 code.
> > 
> > Ah but that would mean not being able to use --prefix then no?
> 
> I hope not.
> 
> autoconf generates this snippet in configure itself, by deferring the
> evaluation of things I'm hoping that the content of Paths.mk.in can be
> evaluated after that snippet has run.

You're right, this works. OK Great.

  Luis

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

* Re: [PATCH v6 10/13] autoconf: xen: move standard path variables to config/Paths.mk.in
  2014-07-04 14:36       ` Ian Campbell
@ 2014-07-08 18:52         ` Luis R. Rodriguez
  2014-07-10 16:16           ` Ian Campbell
  0 siblings, 1 reply; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-07-08 18:52 UTC (permalink / raw)
  To: Ian Campbell
  Cc: Keir Fraser, Luis R. Rodriguez, Tim Deegan, Ian Jackson,
	Jan Beulich, Samuel Thibault, xen-devel

On Fri, Jul 04, 2014 at 03:36:00PM +0100, Ian Campbell wrote:
> On Thu, 2014-07-03 at 20:53 +0200, Luis R. Rodriguez wrote:
> > On Wed, Jul 02, 2014 at 02:34:14PM +0100, Ian Campbell wrote:
> > > On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
> > > > From: "Luis R. Rodriguez" <mcgrof@suse.com>
> > > > +LIBDIR=`eval echo $libdir`
> > > 
> > > Why is this one an eval?
> > 
> > BTW I now see why I had used the eval on LIBDIR, its because otherwise Paths.mk
> > ends up with:
> > 
> > LIBDIR                   := ${exec_prefix}/lib64
> > ...
> > PRIVATE_PREFIX           := ${exec_prefix}/lib64/xen
> > PRIVATE_PREFIX           := ${exec_prefix}/lib64/xen
> > PRIVATE_BINDIR           := ${exec_prefix}/lib64/xen/bin
> > ...
> > 
> > Can I upkeep the eval?
> 
> Seems a bit odd that this would only affect LIBDIR and not PREFIX.

Yeah I tested this, the substitution does not happen even if I use
AC_SUBST(exec_prefix).

> I'd like to understand why this happens before reaching for the eval (or
> to see some autoconf documentation that claims this is the right thing
> to do).

Um, OK. So this patch series will have to wait then until that's done.
I'm not sure I can help much here.

  Luis

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

* Re: [PATCH v6 10/13] autoconf: xen: move standard path variables to config/Paths.mk.in
  2014-07-08 18:41             ` Luis R. Rodriguez
@ 2014-07-08 18:53               ` Luis R. Rodriguez
  2014-07-10 16:18                 ` Ian Campbell
  0 siblings, 1 reply; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-07-08 18:53 UTC (permalink / raw)
  To: Ian Campbell
  Cc: Keir Fraser, Luis R. Rodriguez, Tim Deegan, Ian Jackson,
	Jan Beulich, Samuel Thibault, xen-devel

On Tue, Jul 08, 2014 at 08:41:09PM +0200, Luis R. Rodriguez wrote:
> On Fri, Jul 04, 2014 at 03:33:55PM +0100, Ian Campbell wrote:
> > On Thu, 2014-07-03 at 20:30 +0200, Luis R. Rodriguez wrote:
> > > On Thu, Jul 03, 2014 at 10:15:13AM +0100, Ian Campbell wrote:
> > > > On Wed, 2014-07-02 at 21:32 +0200, Luis R. Rodriguez wrote:
> > > > > On Wed, Jul 02, 2014 at 02:34:14PM +0100, Ian Campbell wrote:
> > > > > > On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
> > > > > > > diff --git a/m4/paths.m4 b/m4/paths.m4
> > > > > > > new file mode 100644
> > > > > > > index 0000000..717fcd1
> > > > > > > --- /dev/null
> > > > > > > +++ b/m4/paths.m4
> > > > > > > @@ -0,0 +1,61 @@
> > > > > > > +AC_DEFUN([AX_XEN_EXPAND_CONFIG], [
> > > > > > > +dnl expand these early so we can use this for substitutions
> > > > > > > +test "x$prefix" = "xNONE" && prefix=$ac_default_prefix
> > > > > > > +test "x$exec_prefix" = "xNONE" && exec_prefix=$ac_default_prefix
> > > > > > 
> > > > > > This is a bit of shame. I suppose this needs to happen in the middle of
> > > > > > AC_OUTPUT which isn't possible?
> > > > > > 
> > > > > > autoconf itself seems to quote the prefix so it is not expanded until
> > > > > > later, i.e. when config.status is run. Would that work here?
> > > > > 
> > > > > Its unclear what exactly the recommendation is here.
> > > > > 
> > > > > > Or perhaps we should just PREFIX=$prefix AC_SUBST(PREFIX) and put all
> > > > > > the BINDIR=$PREFIX/bin into Paths.mk.in after PREFIX=@PREFIX@?
> > > > > 
> > > > > Why though?
> > > > 
> > > > To avoid cutting and pasting the snippet of autoconf internal code:
> > > >         test "x$prefix" = "xNONE" && prefix=$ac_default_prefix
> > > > into our m4 code.
> > > 
> > > Ah but that would mean not being able to use --prefix then no?
> > 
> > I hope not.
> > 
> > autoconf generates this snippet in configure itself, by deferring the
> > evaluation of things I'm hoping that the content of Paths.mk.in can be
> > evaluated after that snippet has run.
> 
> You're right, this works. OK Great.

Spoke to soon, it only works if and only if --prefix is passed otherwise
it gets assigned a NONE value. Can I revert back to the old solution?

  Luis

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

* Re: [PATCH v6 12/13] autoconf: xen: enable explicit preference option for xenstored preference
  2014-07-04 14:37           ` Ian Campbell
@ 2014-07-08 18:54             ` Luis R. Rodriguez
  0 siblings, 0 replies; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-07-08 18:54 UTC (permalink / raw)
  To: Ian Campbell
  Cc: Keir Fraser, Luis R. Rodriguez, Tim Deegan, Ian Jackson,
	Jan Beulich, xen-devel

On Fri, Jul 04, 2014 at 03:37:23PM +0100, Ian Campbell wrote:
> On Thu, 2014-07-03 at 20:57 +0200, Luis R. Rodriguez wrote:
> 
> > > Strictly speaking you don't
> > > need the associated AC_SUBST's but they are harmless.
> > 
> > Without the AC_SUBST() I do not believe substitiution is done by 
> > autoconf on Paths.mk.
> 
> For tools/configure you won't be creating Paths.mk, so it doesn't
> matter.
> 
> > OK so use AX_XEN_EXPAND_CONFIG() on both top level configure.ac and
> > tools/configure.ac but only have config/Paths.mk be a AC_CONFIG_FILES()
> > for the top level configure.ac ?
> 

OK that's exactly how the patch was so I'll leave it alone.

  Luis

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

* Re: [PATCH v6 10/13] autoconf: xen: move standard path variables to config/Paths.mk.in
  2014-07-08 18:52         ` Luis R. Rodriguez
@ 2014-07-10 16:16           ` Ian Campbell
  2014-07-14 23:42             ` Luis R. Rodriguez
  0 siblings, 1 reply; 66+ messages in thread
From: Ian Campbell @ 2014-07-10 16:16 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: Keir Fraser, Luis R. Rodriguez, Tim Deegan, Ian Jackson,
	Jan Beulich, Samuel Thibault, xen-devel

On Tue, 2014-07-08 at 20:52 +0200, Luis R. Rodriguez wrote:
> On Fri, Jul 04, 2014 at 03:36:00PM +0100, Ian Campbell wrote:
> > On Thu, 2014-07-03 at 20:53 +0200, Luis R. Rodriguez wrote:
> > > On Wed, Jul 02, 2014 at 02:34:14PM +0100, Ian Campbell wrote:
> > > > On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
> > > > > From: "Luis R. Rodriguez" <mcgrof@suse.com>
> > > > > +LIBDIR=`eval echo $libdir`
> > > > 
> > > > Why is this one an eval?
> > > 
> > > BTW I now see why I had used the eval on LIBDIR, its because otherwise Paths.mk
> > > ends up with:
> > > 
> > > LIBDIR                   := ${exec_prefix}/lib64
> > > ...
> > > PRIVATE_PREFIX           := ${exec_prefix}/lib64/xen
> > > PRIVATE_PREFIX           := ${exec_prefix}/lib64/xen
> > > PRIVATE_BINDIR           := ${exec_prefix}/lib64/xen/bin
> > > ...
> > > 
> > > Can I upkeep the eval?
> > 
> > Seems a bit odd that this would only affect LIBDIR and not PREFIX.
> 
> Yeah I tested this, the substitution does not happen even if I use
> AC_SUBST(exec_prefix).

@exec_prefix@ isn't substituted if you use AC_SUBST(exec_prefix)? Ouch.

Ian.

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

* Re: [PATCH v6 10/13] autoconf: xen: move standard path variables to config/Paths.mk.in
  2014-07-08 18:53               ` Luis R. Rodriguez
@ 2014-07-10 16:18                 ` Ian Campbell
  2014-07-14 23:41                   ` Luis R. Rodriguez
  0 siblings, 1 reply; 66+ messages in thread
From: Ian Campbell @ 2014-07-10 16:18 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: Keir Fraser, Luis R. Rodriguez, Tim Deegan, Ian Jackson,
	Jan Beulich, Samuel Thibault, xen-devel

On Tue, 2014-07-08 at 20:53 +0200, Luis R. Rodriguez wrote:
> On Tue, Jul 08, 2014 at 08:41:09PM +0200, Luis R. Rodriguez wrote:
> > On Fri, Jul 04, 2014 at 03:33:55PM +0100, Ian Campbell wrote:
> > > On Thu, 2014-07-03 at 20:30 +0200, Luis R. Rodriguez wrote:
> > > > On Thu, Jul 03, 2014 at 10:15:13AM +0100, Ian Campbell wrote:
> > > > > On Wed, 2014-07-02 at 21:32 +0200, Luis R. Rodriguez wrote:
> > > > > > On Wed, Jul 02, 2014 at 02:34:14PM +0100, Ian Campbell wrote:
> > > > > > > On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
> > > > > > > > diff --git a/m4/paths.m4 b/m4/paths.m4
> > > > > > > > new file mode 100644
> > > > > > > > index 0000000..717fcd1
> > > > > > > > --- /dev/null
> > > > > > > > +++ b/m4/paths.m4
> > > > > > > > @@ -0,0 +1,61 @@
> > > > > > > > +AC_DEFUN([AX_XEN_EXPAND_CONFIG], [
> > > > > > > > +dnl expand these early so we can use this for substitutions
> > > > > > > > +test "x$prefix" = "xNONE" && prefix=$ac_default_prefix
> > > > > > > > +test "x$exec_prefix" = "xNONE" && exec_prefix=$ac_default_prefix
> > > > > > > 
> > > > > > > This is a bit of shame. I suppose this needs to happen in the middle of
> > > > > > > AC_OUTPUT which isn't possible?
> > > > > > > 
> > > > > > > autoconf itself seems to quote the prefix so it is not expanded until
> > > > > > > later, i.e. when config.status is run. Would that work here?
> > > > > > 
> > > > > > Its unclear what exactly the recommendation is here.
> > > > > > 
> > > > > > > Or perhaps we should just PREFIX=$prefix AC_SUBST(PREFIX) and put all
> > > > > > > the BINDIR=$PREFIX/bin into Paths.mk.in after PREFIX=@PREFIX@?
> > > > > > 
> > > > > > Why though?
> > > > > 
> > > > > To avoid cutting and pasting the snippet of autoconf internal code:
> > > > >         test "x$prefix" = "xNONE" && prefix=$ac_default_prefix
> > > > > into our m4 code.
> > > > 
> > > > Ah but that would mean not being able to use --prefix then no?
> > > 
> > > I hope not.
> > > 
> > > autoconf generates this snippet in configure itself, by deferring the
> > > evaluation of things I'm hoping that the content of Paths.mk.in can be
> > > evaluated after that snippet has run.
> > 
> > You're right, this works. OK Great.
> 
> Spoke to soon, it only works if and only if --prefix is passed otherwise
> it gets assigned a NONE value. Can I revert back to the old solution?

I guess so. Stupid autoconf :-)

Ian.

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

* Re: [PATCH v6 10/13] autoconf: xen: move standard path variables to config/Paths.mk.in
  2014-07-10 16:18                 ` Ian Campbell
@ 2014-07-14 23:41                   ` Luis R. Rodriguez
  0 siblings, 0 replies; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-07-14 23:41 UTC (permalink / raw)
  To: Ian Campbell
  Cc: Keir Fraser, Luis R. Rodriguez, Tim Deegan, Ian Jackson,
	Jan Beulich, Samuel Thibault, xen-devel

On Thu, Jul 10, 2014 at 05:18:17PM +0100, Ian Campbell wrote:
> On Tue, 2014-07-08 at 20:53 +0200, Luis R. Rodriguez wrote:
> > On Tue, Jul 08, 2014 at 08:41:09PM +0200, Luis R. Rodriguez wrote:
> > > On Fri, Jul 04, 2014 at 03:33:55PM +0100, Ian Campbell wrote:
> > > > On Thu, 2014-07-03 at 20:30 +0200, Luis R. Rodriguez wrote:
> > > > > On Thu, Jul 03, 2014 at 10:15:13AM +0100, Ian Campbell wrote:
> > > > > > On Wed, 2014-07-02 at 21:32 +0200, Luis R. Rodriguez wrote:
> > > > > > > On Wed, Jul 02, 2014 at 02:34:14PM +0100, Ian Campbell wrote:
> > > > > > > > On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
> > > > > > > > > diff --git a/m4/paths.m4 b/m4/paths.m4
> > > > > > > > > new file mode 100644
> > > > > > > > > index 0000000..717fcd1
> > > > > > > > > --- /dev/null
> > > > > > > > > +++ b/m4/paths.m4
> > > > > > > > > @@ -0,0 +1,61 @@
> > > > > > > > > +AC_DEFUN([AX_XEN_EXPAND_CONFIG], [
> > > > > > > > > +dnl expand these early so we can use this for substitutions
> > > > > > > > > +test "x$prefix" = "xNONE" && prefix=$ac_default_prefix
> > > > > > > > > +test "x$exec_prefix" = "xNONE" && exec_prefix=$ac_default_prefix
> > > > > > > > 
> > > > > > > > This is a bit of shame. I suppose this needs to happen in the middle of
> > > > > > > > AC_OUTPUT which isn't possible?
> > > > > > > > 
> > > > > > > > autoconf itself seems to quote the prefix so it is not expanded until
> > > > > > > > later, i.e. when config.status is run. Would that work here?
> > > > > > > 
> > > > > > > Its unclear what exactly the recommendation is here.
> > > > > > > 
> > > > > > > > Or perhaps we should just PREFIX=$prefix AC_SUBST(PREFIX) and put all
> > > > > > > > the BINDIR=$PREFIX/bin into Paths.mk.in after PREFIX=@PREFIX@?
> > > > > > > 
> > > > > > > Why though?
> > > > > > 
> > > > > > To avoid cutting and pasting the snippet of autoconf internal code:
> > > > > >         test "x$prefix" = "xNONE" && prefix=$ac_default_prefix
> > > > > > into our m4 code.
> > > > > 
> > > > > Ah but that would mean not being able to use --prefix then no?
> > > > 
> > > > I hope not.
> > > > 
> > > > autoconf generates this snippet in configure itself, by deferring the
> > > > evaluation of things I'm hoping that the content of Paths.mk.in can be
> > > > evaluated after that snippet has run.
> > > 
> > > You're right, this works. OK Great.
> > 
> > Spoke to soon, it only works if and only if --prefix is passed otherwise
> > it gets assigned a NONE value. Can I revert back to the old solution?
> 
> I guess so. Stupid autoconf :-)

OK reverted back to the old way.

  Luis

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

* Re: [PATCH v6 10/13] autoconf: xen: move standard path variables to config/Paths.mk.in
  2014-07-10 16:16           ` Ian Campbell
@ 2014-07-14 23:42             ` Luis R. Rodriguez
  0 siblings, 0 replies; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-07-14 23:42 UTC (permalink / raw)
  To: Ian Campbell
  Cc: Keir Fraser, Luis R. Rodriguez, Tim Deegan, Ian Jackson,
	Jan Beulich, Samuel Thibault, xen-devel

On Thu, Jul 10, 2014 at 05:16:58PM +0100, Ian Campbell wrote:
> On Tue, 2014-07-08 at 20:52 +0200, Luis R. Rodriguez wrote:
> > On Fri, Jul 04, 2014 at 03:36:00PM +0100, Ian Campbell wrote:
> > > On Thu, 2014-07-03 at 20:53 +0200, Luis R. Rodriguez wrote:
> > > > On Wed, Jul 02, 2014 at 02:34:14PM +0100, Ian Campbell wrote:
> > > > > On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
> > > > > > From: "Luis R. Rodriguez" <mcgrof@suse.com>
> > > > > > +LIBDIR=`eval echo $libdir`
> > > > > 
> > > > > Why is this one an eval?
> > > > 
> > > > BTW I now see why I had used the eval on LIBDIR, its because otherwise Paths.mk
> > > > ends up with:
> > > > 
> > > > LIBDIR                   := ${exec_prefix}/lib64
> > > > ...
> > > > PRIVATE_PREFIX           := ${exec_prefix}/lib64/xen
> > > > PRIVATE_PREFIX           := ${exec_prefix}/lib64/xen
> > > > PRIVATE_BINDIR           := ${exec_prefix}/lib64/xen/bin
> > > > ...
> > > > 
> > > > Can I upkeep the eval?
> > > 
> > > Seems a bit odd that this would only affect LIBDIR and not PREFIX.
> > 
> > Yeah I tested this, the substitution does not happen even if I use
> > AC_SUBST(exec_prefix).
> 
> @exec_prefix@ isn't substituted if you use AC_SUBST(exec_prefix)? Ouch.

Nope.

  Luis

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

* Re: [PATCH v6 02/13] cxenstored: add support for systemd active sockets
  2014-07-03 17:06         ` Luis R. Rodriguez
  2014-07-04 14:32           ` Ian Campbell
@ 2014-07-17 19:45           ` Luis R. Rodriguez
  2014-07-17 20:16             ` Dave Scott
  1 sibling, 1 reply; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-07-17 19:45 UTC (permalink / raw)
  To: Ian Campbell, David Scott, Anil Madhavapeddy; +Cc: xen-devel, Luis R. Rodriguez

David, Anil, please see below.

On Thu, Jul 03, 2014 at 07:06:24PM +0200, Luis R. Rodriguez wrote:
> On Thu, Jul 03, 2014 at 10:13:05AM +0100, Ian Campbell wrote:
> > On Wed, 2014-07-02 at 21:00 +0200, Luis R. Rodriguez wrote:
> > > On Wed, Jul 02, 2014 at 02:02:38PM +0100, Ian Campbell wrote:
> > > > On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
> > > > > +int xs_validate_active_socket(const char *connect_to)
> > > > > +{
> > > > > +	char sock[30];
> > > > > +
> > > > > +	/* We have to null terminate the socket path */
> > > > > +	memset(sock, '\0', sizeof(sock));
> > > > > +	memcpy(sock, connect_to, strlen(connect_to));
> > > > 
> > > > This risks overrunning sock if connect_to is longer than 30 characters.
> > > 
> > > Yuk, yes. A size check is required.
> > > 
> > > > But your use of strlen suggests that connect_to is already NULL
> > > > terminated, so what is this for?
> > > 
> > > strlen() seems to want the string to also be null terminated
> > > in order to work, and I also see that snprintf() is ultimately
> > > used on the C version of the library, that should ensure its null
> > > terminated. This however is not true for the ocaml version and
> > > I suppose that is the root of the issue I saw that got me to
> > > force null terimination as I did run into issues with this path
> > > IIRC when not null terminated.
> > > 
> > > > > +	if ((strncmp("/var/run/xenstored/socket_ro", sock, 28) != 0) &&
> > > > > +	    (strncmp("/var/run/xenstored/socket", sock, 25) != 0)) {
> > > > 
> > > > Given that sock (or connect_to) is NULL terminated, why strncmp and not
> > > > the straightforward strcmp?
> > > 
> > > See above.
> > > 
> > > > As it is I think your code would accept
> > > > e.g. /var/run/xenstored/socketwibble, no?
> > > 
> > > It indeed would, its best if we resolve the null termination
> > > issue internally then.
> > 
> > Yeah, I think we should write the C version according to normal C string
> > conventions. If the ocaml idea of a string differs then perhaps that
> > version needs to be different.
> 
> OK, or we ensure Ocaml's implementation provides a null terminated
> string to try to keep the systemd interface similar, poking Dave for
> feedback:

Dave, Anil, or other ocaml folks -- feedback is is appreciated on the questions
below.

> String_val() is used for the static string connect_to passed to the
> C wrapper, the String_val() documentation [0] says that "there is a null
> character after the last character in the string" however its unclear
> if this is guaranteed if the string was originally a static Ocaml string
> which was not null terminated. 
> 
> Now, its unclear which xenstored (cxenstored or oxenstored) gave me issues
> that pushed me to ensure I give systemd null terminated strings but
> I do know that it was one for sure and it took me quite a bit to figure
> out this was needed and that this was the issue. Based on my review just
> now since the cxenstored uses snprintf() for both xs_daemon_socket_ro()
> and xs_daemon_socket() and since snprintf() man page says that it will
> write at most size bytes (including the terminating null byte ('\0') I
> am left to only grow suspcicious of the oxenstored as the probable
> cause of the issues I saw. I should also highlight that the socket path
> can also come from environment variables on cxenstored, XENSTORED_PATH,
> and getenv() documentation doesn't say whether or not strings will be
> null terminated for us, that might cause unexpected issues if used and
> if it doesn't on systemd.
> 
> In v5 systemd integration implementation in which I used static structs
> for the strings in C I had no issues but note that in that case I simply
> used the Ocaml string (after String_val()) to and compare it to the one
> on the static C array with:
> 
> 	(!strcmp(connect_to, xenstore_active_sockets[i].path))
> 
> I then used the C static string for sd_is_socket_unix(), not the one
> passed from cxenstored or oxenstored.
> 
> [0] http://caml.inria.fr/pub/docs/manual-ocaml-400/manual033.html

  Luis

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

* Re: [PATCH v6 02/13] cxenstored: add support for systemd active sockets
  2014-07-17 19:45           ` Luis R. Rodriguez
@ 2014-07-17 20:16             ` Dave Scott
  2014-07-17 23:13               ` Luis R. Rodriguez
  0 siblings, 1 reply; 66+ messages in thread
From: Dave Scott @ 2014-07-17 20:16 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: xen-devel, Dave Scott, Luis R. Rodriguez, Ian Campbell,
	Anil Madhavapeddy

Hi Luis,

Sorry I missed this question earlier.

On 17 Jul 2014, at 20:45, Luis R. Rodriguez <mcgrof@suse.com> wrote:

> David, Anil, please see below.
> 
> On Thu, Jul 03, 2014 at 07:06:24PM +0200, Luis R. Rodriguez wrote:
>> On Thu, Jul 03, 2014 at 10:13:05AM +0100, Ian Campbell wrote:
>>> On Wed, 2014-07-02 at 21:00 +0200, Luis R. Rodriguez wrote:
>>>> On Wed, Jul 02, 2014 at 02:02:38PM +0100, Ian Campbell wrote:
>>>>> On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
>>>>>> +int xs_validate_active_socket(const char *connect_to)
>>>>>> +{
>>>>>> +	char sock[30];
>>>>>> +
>>>>>> +	/* We have to null terminate the socket path */
>>>>>> +	memset(sock, '\0', sizeof(sock));
>>>>>> +	memcpy(sock, connect_to, strlen(connect_to));
>>>>> 
>>>>> This risks overrunning sock if connect_to is longer than 30 characters.
>>>> 
>>>> Yuk, yes. A size check is required.
>>>> 
>>>>> But your use of strlen suggests that connect_to is already NULL
>>>>> terminated, so what is this for?
>>>> 
>>>> strlen() seems to want the string to also be null terminated
>>>> in order to work, and I also see that snprintf() is ultimately
>>>> used on the C version of the library, that should ensure its null
>>>> terminated. This however is not true for the ocaml version and
>>>> I suppose that is the root of the issue I saw that got me to
>>>> force null terimination as I did run into issues with this path
>>>> IIRC when not null terminated.
>>>> 
>>>>>> +	if ((strncmp("/var/run/xenstored/socket_ro", sock, 28) != 0) &&
>>>>>> +	    (strncmp("/var/run/xenstored/socket", sock, 25) != 0)) {
>>>>> 
>>>>> Given that sock (or connect_to) is NULL terminated, why strncmp and not
>>>>> the straightforward strcmp?
>>>> 
>>>> See above.
>>>> 
>>>>> As it is I think your code would accept
>>>>> e.g. /var/run/xenstored/socketwibble, no?
>>>> 
>>>> It indeed would, its best if we resolve the null termination
>>>> issue internally then.
>>> 
>>> Yeah, I think we should write the C version according to normal C string
>>> conventions. If the ocaml idea of a string differs then perhaps that
>>> version needs to be different.
>> 
>> OK, or we ensure Ocaml's implementation provides a null terminated
>> string to try to keep the systemd interface similar, poking Dave for
>> feedback:
> 
> Dave, Anil, or other ocaml folks -- feedback is is appreciated on the questions
> below.
> 
>> String_val() is used for the static string connect_to passed to the
>> C wrapper, the String_val() documentation [0] says that "there is a null
>> character after the last character in the string" however its unclear
>> if this is guaranteed if the string was originally a static Ocaml string
>> which was not null terminated.

OCaml strings are best thought of as a pair of a byte array and a length. From the point of view of the OCaml program they don’t contain NULLs unless you put some in there yourself. OCaml code which actually writes NULLs into strings is fairly rare.

The manual, although terse, is trustworthy. If you use String_val on an OCaml string you’ll get a char* which is guaranteed to be NULL terminated. 

>> Now, its unclear which xenstored (cxenstored or oxenstored) gave me issues
>> that pushed me to ensure I give systemd null terminated strings but
>> I do know that it was one for sure and it took me quite a bit to figure
>> out this was needed and that this was the issue. Based on my review just
>> now since the cxenstored uses snprintf() for both xs_daemon_socket_ro()
>> and xs_daemon_socket() and since snprintf() man page says that it will
>> write at most size bytes (including the terminating null byte ('\0’)

I believe that’s true.

>> I
>> am left to only grow suspcicious of the oxenstored as the probable
>> cause of the issues I saw. I should also highlight that the socket path
>> can also come from environment variables on cxenstored, XENSTORED_PATH,
>> and getenv() documentation doesn't say whether or not strings will be
>> null terminated for us, that might cause unexpected issues if used and
>> if it doesn't on systemd.
>> 
>> In v5 systemd integration implementation in which I used static structs
>> for the strings in C I had no issues but note that in that case I simply
>> used the Ocaml string (after String_val()) to and compare it to the one
>> on the static C array with:
>> 
>> 	(!strcmp(connect_to, xenstore_active_sockets[i].path))
>> 
>> I then used the C static string for sd_is_socket_unix(), not the one
>> passed from cxenstored or oxenstored.

If the strings compare equal with ‘strcmp’ then I would have thought either would work, unless the consumer is holding onto the string pointer for longer than the call duration. As soon as your function returns (or allocates) the OCaml strings can be moved around which invalidates the result of String_val— perhaps this is the cause of the difference between the String_val result and your static strings?

Dave

>> 
>> [0] http://caml.inria.fr/pub/docs/manual-ocaml-400/manual033.html
> 
>  Luis

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

* Re: [PATCH v6 02/13] cxenstored: add support for systemd active sockets
  2014-07-17 20:16             ` Dave Scott
@ 2014-07-17 23:13               ` Luis R. Rodriguez
  2014-07-18  9:27                 ` Anil Madhavapeddy
  0 siblings, 1 reply; 66+ messages in thread
From: Luis R. Rodriguez @ 2014-07-17 23:13 UTC (permalink / raw)
  To: Dave Scott; +Cc: xen-devel, Luis R. Rodriguez, Ian Campbell, Anil Madhavapeddy

On Thu, Jul 17, 2014 at 08:16:40PM +0000, Dave Scott wrote:
> Hi Luis,
> 
> Sorry I missed this question earlier.
> 
> On 17 Jul 2014, at 20:45, Luis R. Rodriguez <mcgrof@suse.com> wrote:
> 
> > David, Anil, please see below.
> > 
> > On Thu, Jul 03, 2014 at 07:06:24PM +0200, Luis R. Rodriguez wrote:
> >> On Thu, Jul 03, 2014 at 10:13:05AM +0100, Ian Campbell wrote:
> >>> On Wed, 2014-07-02 at 21:00 +0200, Luis R. Rodriguez wrote:
> >>>> On Wed, Jul 02, 2014 at 02:02:38PM +0100, Ian Campbell wrote:
> >>>>> On Thu, 2014-06-12 at 18:18 -0700, Luis R. Rodriguez wrote:
> >>>>>> +int xs_validate_active_socket(const char *connect_to)
> >>>>>> +{
> >>>>>> +	char sock[30];
> >>>>>> +
> >>>>>> +	/* We have to null terminate the socket path */
> >>>>>> +	memset(sock, '\0', sizeof(sock));
> >>>>>> +	memcpy(sock, connect_to, strlen(connect_to));
> >>>>> 
> >>>>> This risks overrunning sock if connect_to is longer than 30 characters.
> >>>> 
> >>>> Yuk, yes. A size check is required.
> >>>> 
> >>>>> But your use of strlen suggests that connect_to is already NULL
> >>>>> terminated, so what is this for?
> >>>> 
> >>>> strlen() seems to want the string to also be null terminated
> >>>> in order to work, and I also see that snprintf() is ultimately
> >>>> used on the C version of the library, that should ensure its null
> >>>> terminated. This however is not true for the ocaml version and
> >>>> I suppose that is the root of the issue I saw that got me to
> >>>> force null terimination as I did run into issues with this path
> >>>> IIRC when not null terminated.
> >>>> 
> >>>>>> +	if ((strncmp("/var/run/xenstored/socket_ro", sock, 28) != 0) &&
> >>>>>> +	    (strncmp("/var/run/xenstored/socket", sock, 25) != 0)) {
> >>>>> 
> >>>>> Given that sock (or connect_to) is NULL terminated, why strncmp and not
> >>>>> the straightforward strcmp?
> >>>> 
> >>>> See above.
> >>>> 
> >>>>> As it is I think your code would accept
> >>>>> e.g. /var/run/xenstored/socketwibble, no?
> >>>> 
> >>>> It indeed would, its best if we resolve the null termination
> >>>> issue internally then.
> >>> 
> >>> Yeah, I think we should write the C version according to normal C string
> >>> conventions. If the ocaml idea of a string differs then perhaps that
> >>> version needs to be different.
> >> 
> >> OK, or we ensure Ocaml's implementation provides a null terminated
> >> string to try to keep the systemd interface similar, poking Dave for
> >> feedback:
> > 
> > Dave, Anil, or other ocaml folks -- feedback is is appreciated on the questions
> > below.
> > 
> >> String_val() is used for the static string connect_to passed to the
> >> C wrapper, the String_val() documentation [0] says that "there is a null
> >> character after the last character in the string" however its unclear
> >> if this is guaranteed if the string was originally a static Ocaml string
> >> which was not null terminated.
> 
> OCaml strings are best thought of as a pair of a byte array and a length.
> From the point of view of the OCaml program they don’t contain NULLs unless
> you put some in there yourself. OCaml code which actually writes NULLs into
> strings is fairly rare.
> 
> The manual, although terse, is trustworthy. If you use String_val on an OCaml
> string you’ll get a char* which is guaranteed to be NULL terminated. 
> 
> >> Now, its unclear which xenstored (cxenstored or oxenstored) gave me issues
> >> that pushed me to ensure I give systemd null terminated strings but
> >> I do know that it was one for sure and it took me quite a bit to figure
> >> out this was needed and that this was the issue. Based on my review just
> >> now since the cxenstored uses snprintf() for both xs_daemon_socket_ro()
> >> and xs_daemon_socket() and since snprintf() man page says that it will
> >> write at most size bytes (including the terminating null byte ('\0’)
> 
> I believe that’s true.
> 
> >> I
> >> am left to only grow suspcicious of the oxenstored as the probable
> >> cause of the issues I saw. I should also highlight that the socket path
> >> can also come from environment variables on cxenstored, XENSTORED_PATH,
> >> and getenv() documentation doesn't say whether or not strings will be
> >> null terminated for us, that might cause unexpected issues if used and
> >> if it doesn't on systemd.
> >> 
> >> In v5 systemd integration implementation in which I used static structs
> >> for the strings in C I had no issues but note that in that case I simply
> >> used the Ocaml string (after String_val()) to and compare it to the one
> >> on the static C array with:
> >> 
> >> 	(!strcmp(connect_to, xenstore_active_sockets[i].path))
> >> 
> >> I then used the C static string for sd_is_socket_unix(), not the one
> >> passed from cxenstored or oxenstored.
> 
> If the strings compare equal with ‘strcmp’ then I would have thought either
> would work, unless the consumer is holding onto the string pointer for longer
> than the call duration. As soon as your function returns (or allocates) the
> OCaml strings can be moved around which invalidates the result of String_val—
> perhaps this is the cause of the difference between the String_val result and
> your static strings?

Your description gave me enough confidence to go ahead and test this without
the added null characters and for some reason now it all works. I'll respin
and send a v7.

  Luis

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

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

* Re: [PATCH v6 02/13] cxenstored: add support for systemd active sockets
  2014-07-17 23:13               ` Luis R. Rodriguez
@ 2014-07-18  9:27                 ` Anil Madhavapeddy
  0 siblings, 0 replies; 66+ messages in thread
From: Anil Madhavapeddy @ 2014-07-18  9:27 UTC (permalink / raw)
  To: Luis R. Rodriguez; +Cc: xen-devel, David Scott, Ian Campbell, Luis R. Rodriguez

On 18 Jul 2014, at 00:13, Luis R. Rodriguez <mcgrof@suse.com> wrote:
> On Thu, Jul 17, 2014 at 08:16:40PM +0000, Dave Scott wrote:
>> 
>> If the strings compare equal with ‘strcmp’ then I would have thought either
>> would work, unless the consumer is holding onto the string pointer for longer
>> than the call duration. As soon as your function returns (or allocates) the
>> OCaml strings can be moved around which invalidates the result of String_val—
>> perhaps this is the cause of the difference between the String_val result and
>> your static strings?
> 
> Your description gave me enough confidence to go ahead and test this without
> the added null characters and for some reason now it all works. I'll respin
> and send a v7.

The heap layout of OCaml strings is described precisely in Real World OCaml here:
https://realworldocaml.org/v1/en/html/memory-representation-of-values.html#string-values

Nul-termination is guaranteed by the representation (via the padding byte) to
make it easier to pass to-and-from C functions.  OCaml itself tracks the
length of the string explicitly, so it doesn't care if there are NUL values
within it (although this will of course make it difficult to pass to-and-from
C string functions, and care should be taken only to pass NUL-containing
OCaml strings to mem* functions instead of str*).

>>> String_val() is used for the static string connect_to passed to the
>>> C wrapper, the String_val() documentation [0] says that "there is a null
>>> character after the last character in the string" however its unclear
>>> if this is guaranteed if the string was originally a static Ocaml string
>>> which was not null terminated.

In other words, trust the OCaml manual just as you trusted the snprintf
man page :-)

-anil

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

end of thread, other threads:[~2014-07-18  9:27 UTC | newest]

Thread overview: 66+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-13  1:18 [PATCH v6 00/13] xen: add systemd support Luis R. Rodriguez
2014-06-13  1:18 ` [PATCH v6 01/13] xenstored: enable usage of config.h on both xenstored and oxenstored Luis R. Rodriguez
2014-06-13  1:18 ` [PATCH v6 02/13] cxenstored: add support for systemd active sockets Luis R. Rodriguez
2014-07-02 13:02   ` Ian Campbell
2014-07-02 19:00     ` Luis R. Rodriguez
2014-07-03  9:13       ` Ian Campbell
2014-07-03 17:06         ` Luis R. Rodriguez
2014-07-04 14:32           ` Ian Campbell
2014-07-08  3:08             ` Luis R. Rodriguez
2014-07-17 19:45           ` Luis R. Rodriguez
2014-07-17 20:16             ` Dave Scott
2014-07-17 23:13               ` Luis R. Rodriguez
2014-07-18  9:27                 ` Anil Madhavapeddy
2014-06-13  1:18 ` [PATCH v6 03/13] oxenstored: " Luis R. Rodriguez
2014-07-02 13:08   ` Ian Campbell
2014-07-02 19:09     ` Luis R. Rodriguez
2014-07-03  8:42       ` Dave Scott
2014-07-03 17:43         ` Luis R. Rodriguez
2014-06-13  1:18 ` [PATCH v6 04/13] oxenstored: force FD_CLOEXEC with Unix.set_close_on_exec on LSB init Luis R. Rodriguez
2014-07-02 13:08   ` Ian Campbell
2014-06-13  1:18 ` [PATCH v6 05/13] tools/xendomains: make xl the default and remove xm usage Luis R. Rodriguez
2014-06-13  1:18 ` [PATCH v6 06/13] tools/xendomains: do space cleanups Luis R. Rodriguez
2014-06-13  1:18 ` [PATCH v6 07/13] tools/xendomains: move to libexec and use a smaller init helper Luis R. Rodriguez
2014-06-13  7:06   ` Jacek Konieczny
2014-06-13 18:32     ` Luis R. Rodriguez
2014-07-02 13:12   ` Ian Campbell
2014-06-13  1:18 ` [PATCH v6 08/13] autoconf: xen: force a refresh with autoconf Luis R. Rodriguez
2014-06-13  1:18 ` [PATCH v6 09/13] autoconf: update m4/pkg.m4 Luis R. Rodriguez
2014-07-02 13:13   ` Ian Campbell
2014-07-02 19:10     ` Luis R. Rodriguez
2014-06-13  1:18 ` [PATCH v6 10/13] autoconf: xen: move standard path variables to config/Paths.mk.in Luis R. Rodriguez
2014-07-02 13:34   ` Ian Campbell
2014-07-02 19:32     ` Luis R. Rodriguez
2014-07-03  9:15       ` Ian Campbell
2014-07-03 18:30         ` Luis R. Rodriguez
2014-07-04 14:33           ` Ian Campbell
2014-07-08 18:41             ` Luis R. Rodriguez
2014-07-08 18:53               ` Luis R. Rodriguez
2014-07-10 16:18                 ` Ian Campbell
2014-07-14 23:41                   ` Luis R. Rodriguez
2014-07-03 18:53     ` Luis R. Rodriguez
2014-07-04 14:36       ` Ian Campbell
2014-07-08 18:52         ` Luis R. Rodriguez
2014-07-10 16:16           ` Ian Campbell
2014-07-14 23:42             ` Luis R. Rodriguez
2014-06-13  1:18 ` [PATCH v6 11/13] xencommons: move module list into a generic place Luis R. Rodriguez
2014-07-02 13:44   ` Ian Campbell
2014-07-02 21:56     ` Luis R. Rodriguez
2014-07-03  9:15       ` Ian Campbell
2014-06-13  1:18 ` [PATCH v6 12/13] autoconf: xen: enable explicit preference option for xenstored preference Luis R. Rodriguez
2014-07-02 13:54   ` Ian Campbell
2014-07-02 20:09     ` Luis R. Rodriguez
2014-07-03  9:20       ` Ian Campbell
2014-07-03 18:57         ` Luis R. Rodriguez
2014-07-04 14:37           ` Ian Campbell
2014-07-08 18:54             ` Luis R. Rodriguez
2014-06-13  1:18 ` [PATCH v6 13/13] systemd: add xen systemd service and module files Luis R. Rodriguez
2014-06-13 19:55   ` Luis R. Rodriguez
2014-06-19 19:47   ` Bastian Blank
2014-06-19 20:21     ` Luis R. Rodriguez
2014-06-19 20:26       ` Luis R. Rodriguez
2014-06-20  5:59         ` David Sutton
2014-07-02 14:02   ` Ian Campbell
2014-07-02 20:25     ` Luis R. Rodriguez
2014-06-19 19:03 ` [PATCH v6 00/13] xen: add systemd support Luis R. Rodriguez
2014-07-02 14:48 ` Ian Campbell

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.