[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH 14/21] xenstored: add NO_SOCKETS compilation option



On Fri, 20 Jan 2012, Daniel De Graaf wrote:
> From: Alex Zeffertt <alex.zeffertt@xxxxxxxxxxxxx>
> 
> option for compiling xenstored without unix sockets to support running on 
> mini-OS

The amount of ifdef's introduced by this patch is not ideal.

Do you think is possible to refactor the code to use structures with
function pointers, with a registration mechanism, so that in the dom0
case you would end up with two structs (one for each kind of
connections), while you would have only one on mini-OS?

We could have an initialize, a destroy and an accept_connection
functions.


> Signed-off-by: Diego Ongaro <diego.ongaro@xxxxxxxxxx>
> Signed-off-by: Alex Zeffertt <alex.zeffertt@xxxxxxxxxxxxx>
> Signed-off-by: Daniel De Graaf <dgdegra@xxxxxxxxxxxxx>
> Acked-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
> ---
>  tools/xenstore/xenstored_core.c |   22 +++++++++++++++++++++-
>  tools/xenstore/xs.c             |    2 ++
>  tools/xenstore/xs_lib.c         |    4 ++++
>  3 files changed, 27 insertions(+), 1 deletions(-)
> 
> diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
> index 9e6c2c7..631bfe4 100644
> --- a/tools/xenstore/xenstored_core.c
> +++ b/tools/xenstore/xenstored_core.c
> @@ -19,9 +19,11 @@
>  
>  #include <sys/types.h>
>  #include <sys/stat.h>
> -#include <sys/socket.h>
>  #include <sys/select.h>
> +#ifndef NO_SOCKETS
> +#include <sys/socket.h>
>  #include <sys/un.h>
> +#endif
>  #include <sys/time.h>
>  #include <time.h>
>  #include <unistd.h>
> @@ -320,8 +322,10 @@ static int initialize_set(fd_set *inset, fd_set *outset, 
> int sock, int ro_sock,
>       FD_ZERO(inset);
>       FD_ZERO(outset);
>  
> +#ifndef NO_SOCKETS
>       set_fd(sock,               inset, &max);
>       set_fd(ro_sock,            inset, &max);
> +#endif
>       set_fd(reopen_log_pipe[0], inset, &max);
>  
>       if (xce_handle != NULL)
> @@ -343,12 +347,14 @@ static int initialize_set(fd_set *inset, fd_set 
> *outset, int sock, int ro_sock,
>       return max;
>  }
>  
> +#ifndef NO_SOCKETS
>  static int destroy_fd(void *_fd)
>  {
>       int *fd = _fd;
>       close(*fd);
>       return 0;
>  }
> +#endif
>  
>  /* Is child a subnode of parent, or equal? */
>  bool is_child(const char *child, const char *parent)
> @@ -1352,6 +1358,7 @@ struct connection *new_connection(connwritefn_t *write, 
> connreadfn_t *read)
>       return new;
>  }
>  
> +#ifndef NO_SOCKETS
>  static int writefd(struct connection *conn, const void *data, unsigned int 
> len)
>  {
>       int rc;
> @@ -1406,6 +1413,7 @@ static void accept_connection(int sock, bool canwrite)
>       } else
>               close(fd);
>  }
> +#endif
>  
>  #define TDB_FLAGS 0
>  
> @@ -1753,7 +1761,11 @@ extern void dump_conn(struct connection *conn);
>  int main(int argc, char *argv[])
>  {
>       int opt, *sock, *ro_sock, max;
> +#ifdef NO_SOCKETS
> +     int minus_one = -1;
> +#else
>       struct sockaddr_un addr;
> +#endif
>       fd_set inset, outset;
>       bool dofork = true;
>       bool outputpid = false;
> @@ -1837,6 +1849,9 @@ int main(int argc, char *argv[])
>       if (!dofork)
>               talloc_enable_leak_report_full();
>  
> +#ifdef NO_SOCKETS
> +     sock = ro_sock = &minus_one;
> +#else
>       /* Create sockets for them to listen to. */
>       sock = talloc(talloc_autofree_context(), int);
>       *sock = socket(PF_UNIX, SOCK_STREAM, 0);
> @@ -1848,10 +1863,12 @@ int main(int argc, char *argv[])
>               barf_perror("Could not create socket");
>       talloc_set_destructor(sock, destroy_fd);
>       talloc_set_destructor(ro_sock, destroy_fd);
> +#endif
>  
>       /* Don't kill us with SIGPIPE. */
>       signal(SIGPIPE, SIG_IGN);
>  
> +#ifndef NO_SOCKETS
>       /* FIXME: Be more sophisticated, don't mug running daemon. */
>       unlink(xs_daemon_socket());
>       unlink(xs_daemon_socket_ro());
> @@ -1871,6 +1888,7 @@ int main(int argc, char *argv[])
>       if (listen(*sock, 1) != 0
>           || listen(*ro_sock, 1) != 0)
>               barf_perror("Could not listen on sockets");
> +#endif
>  
>       if (pipe(reopen_log_pipe)) {
>               barf_perror("pipe");
> @@ -1931,11 +1949,13 @@ int main(int argc, char *argv[])
>                       reopen_log();
>               }
>  
> +#ifndef NO_SOCKETS
>               if (FD_ISSET(*sock, &inset))
>                       accept_connection(*sock, true);
>  
>               if (FD_ISSET(*ro_sock, &inset))
>                       accept_connection(*ro_sock, false);
> +#endif
>  
>               if (evtchn_fd != -1 && FD_ISSET(evtchn_fd, &inset))
>                       handle_event();
> diff --git a/tools/xenstore/xs.c b/tools/xenstore/xs.c
> index 0a01675..60f2cee 100644
> --- a/tools/xenstore/xs.c
> +++ b/tools/xenstore/xs.c
> @@ -271,10 +271,12 @@ struct xs_handle *xs_open(unsigned long flags)
>  {
>       struct xs_handle *xsh = NULL;
>  
> +#ifndef NO_SOCKETS
>       if (flags & XS_OPEN_READONLY)
>               xsh = get_handle(xs_daemon_socket_ro());
>       else
>               xsh = get_handle(xs_daemon_socket());
> +#endif
>  
>       if (!xsh && !(flags & XS_OPEN_SOCKETONLY))
>               xsh = get_handle(xs_domain_dev());
> diff --git a/tools/xenstore/xs_lib.c b/tools/xenstore/xs_lib.c
> index 03a9ee4..af3db6b 100644
> --- a/tools/xenstore/xs_lib.c
> +++ b/tools/xenstore/xs_lib.c
> @@ -39,6 +39,7 @@ const char *xs_daemon_rundir(void)
>       return (s ? s : "/var/run/xenstored");
>  }
>  
> +#ifndef NO_SOCKETS
>  static const char *xs_daemon_path(void)
>  {
>       static char buf[PATH_MAX];
> @@ -50,6 +51,7 @@ static const char *xs_daemon_path(void)
>               return NULL;
>       return buf;
>  }
> +#endif
>  
>  const char *xs_daemon_tdb(void)
>  {
> @@ -58,6 +60,7 @@ const char *xs_daemon_tdb(void)
>       return buf;
>  }
>  
> +#ifndef NO_SOCKETS
>  const char *xs_daemon_socket(void)
>  {
>       return xs_daemon_path();
> @@ -73,6 +76,7 @@ const char *xs_daemon_socket_ro(void)
>               return NULL;
>       return buf;
>  }
> +#endif
>  
>  const char *xs_domain_dev(void)
>  {
> -- 
> 1.7.7.5
> 
> 
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@xxxxxxxxxxxxxxxxxxx
> http://lists.xensource.com/xen-devel
> 

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.