xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: "Luis R. Rodriguez" <mcgrof@suse.com>
To: Ian Campbell <Ian.Campbell@citrix.com>
Cc: xen-devel@lists.xenproject.org,
	"Luis R. Rodriguez" <mcgrof@do-not-panic.com>
Subject: Re: [PATCH v7 2/8] cxenstored: add support for systemd	active sockets
Date: Sat, 26 Jul 2014 00:45:19 +0200	[thread overview]
Message-ID: <20140725224519.GC4191@wotan.suse.de> (raw)
In-Reply-To: <1406214613.25535.0.camel@kazak.uk.xensource.com>

On Thu, Jul 24, 2014 at 04:10:13PM +0100, Ian Campbell wrote:
> 
> On Thu, 2014-07-17 at 16:28 -0700, Luis R. Rodriguez wrote:
> > 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 | 104 +++++++++++++++++++++++++++++++++++++++-
> >  1 file changed, 103 insertions(+), 1 deletion(-)
> > 
> > diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
> > index 47f0722..7f72f68 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,75 @@ static int destroy_fd(void *_fd)
> >  	return 0;
> >  }
> >  
> > +#if defined(XEN_SYSTEMD_ENABLED)
> > +/* Will work regardless of the order systemd gives them to us */
> > +static 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;
> > +}
> > +
> > +static int xs_validate_active_socket(const char *connect_to)
> > +{
> > +	if ((strcmp("/var/run/xenstored/socket_ro", connect_to) != 0) &&
> > +	    (strcmp("/var/run/xenstored/socket", connect_to) != 0)) {
> > +		sd_notifyf(0, "STATUS=unexpected socket: %s\n"
> > +			   "ERRNO=%i",
> > +			   connect_to,
> > +			   EBADR);
> > +		return -EBADR;
> > +	}
> > +
> > +	return xs_get_sd_fd(connect_to);
> > +}
> > +
> > +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",
> 
> You've used %u everywhere else...

Sorry this was not clear, I don't see usage of %u in my patches.

> Also, you aren't handling the n == 1 case, is that supposed to be an
> error or not? Either "Expected 2" is wrong or the conditions need to
> differ.

Good catch, yeah that should be an error as well.

> Perhaps you wanted to send n in the STATUS?

There's an fprintf(stderr) right above above that provides the n variables,
when you use fprintf(stderr) that goes the systemd journal as well.

> Anyway, none of that seems super critical so perhaps you'd prefer to
> make whichever changes are appropriate in a followup patch?

Sure.

> (I notice that the same comment seems to apply to the ocaml case in the
> too...)

OK I'll send a follow up.

  Luis

  parent reply	other threads:[~2014-07-25 22:45 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-17 23:28 [PATCH v7 0/8] xen: add systemd support Luis R. Rodriguez
2014-07-17 23:28 ` [PATCH v7 1/8] xenstored: enable usage of config.h on both xenstored and oxenstored Luis R. Rodriguez
2014-07-17 23:28 ` [PATCH v7 2/8] cxenstored: add support for systemd active sockets Luis R. Rodriguez
2014-07-24 15:10   ` Ian Campbell
2014-07-24 15:54     ` Ian Campbell
2014-07-25 22:45     ` Luis R. Rodriguez [this message]
2014-07-28  9:48       ` Ian Campbell
2014-07-28 15:06         ` Luis R. Rodriguez
2015-08-05 10:06   ` George Dunlap
2015-08-05 10:17     ` Ian Campbell
2015-08-05 10:56       ` George Dunlap
2015-08-05 11:11         ` Ian Campbell
2015-08-05 11:14           ` Ian Campbell
2015-08-05 11:21           ` George Dunlap
2015-08-05 11:27             ` Ian Campbell
2015-08-05 13:17         ` Wei Liu
2015-08-05 16:30           ` George Dunlap
2015-08-05 17:24             ` Wei Liu
2015-08-05 18:19               ` Wei Liu
2015-08-06  9:13                 ` Ian Campbell
2015-08-06  9:20                   ` Wei Liu
2015-08-06  9:29                     ` Ian Campbell
2015-08-06  9:36                       ` Wei Liu
2015-08-06 10:17                   ` Wei Liu
2015-08-06 10:48                     ` Ian Campbell
2015-08-06 10:56                       ` Wei Liu
2015-08-06 11:03                         ` Ian Campbell
2015-08-06 13:56                 ` George Dunlap
2014-07-17 23:28 ` [PATCH v7 3/8] oxenstored: " Luis R. Rodriguez
2014-07-17 23:28 ` [PATCH v7 4/8] oxenstored: force FD_CLOEXEC with Unix.set_close_on_exec on LSB init Luis R. Rodriguez
2014-07-24 15:09   ` Ian Campbell
2014-07-17 23:28 ` [PATCH v7 5/8] autoconf: xen: move standard path variables to config/Paths.mk.in Luis R. Rodriguez
2014-07-24 15:29   ` Ian Campbell
2014-07-17 23:28 ` [PATCH v7 6/8] xencommons: move module list into a generic place Luis R. Rodriguez
2014-07-24 15:35   ` Ian Campbell
2014-07-25 23:16     ` Luis R. Rodriguez
2014-07-17 23:28 ` [PATCH v7 7/8] autoconf: xen: enable explicit preference option for xenstored preference Luis R. Rodriguez
2014-07-24 15:40   ` Ian Campbell
2014-07-25 23:25     ` Luis R. Rodriguez
2014-07-17 23:28 ` [PATCH v7 8/8] systemd: add xen systemd service and module files Luis R. Rodriguez
2014-07-24 15:47   ` Ian Campbell
2014-07-25 23:34     ` Luis R. Rodriguez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140725224519.GC4191@wotan.suse.de \
    --to=mcgrof@suse.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=mcgrof@do-not-panic.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).