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

Re: [Xen-devel] [PATCH 19/24] xenstored: support running in minios stubdom



On Fri, 27 Jan 2012, Daniel De Graaf wrote:
> A previous versions of this patch has been sent to xen-devel. See
> http://lists.xensource.com/archives/html/xen-devel/2009-03/msg01655.html

This is exactly what I had in mind.
The patch looks good to me now.


> 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>
> Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
> Cc: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
> ---
>  tools/xenstore/Makefile           |   14 ++++-
>  tools/xenstore/utils.h            |    2 +
>  tools/xenstore/xenstored_core.c   |   88 ++++-----------------------------
>  tools/xenstore/xenstored_core.h   |   12 +++++
>  tools/xenstore/xenstored_domain.c |    2 +-
>  tools/xenstore/xenstored_minios.c |   60 ++++++++++++++++++++++
>  tools/xenstore/xenstored_posix.c  |   99 
> +++++++++++++++++++++++++++++++++++++
>  7 files changed, 195 insertions(+), 82 deletions(-)
>  create mode 100644 tools/xenstore/xenstored_minios.c
>  create mode 100644 tools/xenstore/xenstored_posix.c
> 
> diff --git a/tools/xenstore/Makefile b/tools/xenstore/Makefile
> index 4facb62..e510b4f 100644
> --- a/tools/xenstore/Makefile
> +++ b/tools/xenstore/Makefile
> @@ -13,9 +13,10 @@ CLIENTS += xenstore-write xenstore-ls xenstore-watch
>  
>  XENSTORED_OBJS = xenstored_core.o xenstored_watch.o xenstored_domain.o 
> xenstored_transaction.o xs_lib.o talloc.o utils.o tdb.o hashtable.o
>  
> -XENSTORED_OBJS_$(CONFIG_Linux) = xenstored_linux.o
> -XENSTORED_OBJS_$(CONFIG_SunOS) = xenstored_solaris.o xenstored_probes.o
> -XENSTORED_OBJS_$(CONFIG_NetBSD) = xenstored_netbsd.o
> +XENSTORED_OBJS_$(CONFIG_Linux) = xenstored_linux.o xenstored_posix.o
> +XENSTORED_OBJS_$(CONFIG_SunOS) = xenstored_solaris.o xenstored_posix.o 
> xenstored_probes.o
> +XENSTORED_OBJS_$(CONFIG_NetBSD) = xenstored_netbsd.o xenstored_posix.o
> +XENSTORED_OBJS_$(CONFIG_MiniOS) = xenstored_minios.o
>  
>  XENSTORED_OBJS += $(XENSTORED_OBJS_y)
>  
> @@ -28,6 +29,10 @@ endif
>  
>  ALL_TARGETS = libxenstore.so libxenstore.a clients xs_tdb_dump xenstored
>  
> +ifdef CONFIG_STUBDOM
> +CFLAGS += -DNO_SOCKETS=1
> +endif
> +
>  .PHONY: all
>  all: $(ALL_TARGETS)
>  
> @@ -49,6 +54,9 @@ endif
>  xenstored: $(XENSTORED_OBJS)
>       $(CC) $(LDFLAGS) $^ $(LDLIBS_libxenctrl) $(SOCKET_LIBS) -o $@ 
> $(APPEND_LDFLAGS)
>  
> +xenstored.a: $(XENSTORED_OBJS)
> +     $(AR) cr $@ $^
> +
>  $(CLIENTS): xenstore
>       ln -f xenstore $@
>  
> diff --git a/tools/xenstore/utils.h b/tools/xenstore/utils.h
> index f378343..2effd17 100644
> --- a/tools/xenstore/utils.h
> +++ b/tools/xenstore/utils.h
> @@ -19,7 +19,9 @@ static inline bool strends(const char *a, const char *b)
>       return streq(a + strlen(a) - strlen(b), b);
>  }
>  
> +#ifndef ARRAY_SIZE
>  #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
> +#endif
>  
>  void barf(const char *fmt, ...) __attribute__((noreturn));
>  void barf_perror(const char *fmt, ...) __attribute__((noreturn));
> diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c
> index 4b12cf2..a762db7 100644
> --- a/tools/xenstore/xenstored_core.c
> +++ b/tools/xenstore/xenstored_core.c
> @@ -224,7 +224,6 @@ static void reopen_log(void)
>       }
>  }
>  
> -
>  static bool write_messages(struct connection *conn)
>  {
>       int ret;
> @@ -327,7 +326,8 @@ static int initialize_set(fd_set *inset, fd_set *outset, 
> int sock, int ro_sock,
>               set_fd(sock, inset, &max);
>       if (ro_sock != -1)
>               set_fd(ro_sock, inset, &max);
> -     set_fd(reopen_log_pipe[0], inset, &max);
> +     if (reopen_log_pipe[0] != -1)
> +             set_fd(reopen_log_pipe[0], inset, &max);
>  
>       if (xce_handle != NULL)
>               set_fd(xc_evtchn_fd(xce_handle), inset, &max);
> @@ -1664,53 +1664,6 @@ static void corrupt(struct connection *conn, const 
> char *fmt, ...)
>  }
>  
>  
> -static void write_pidfile(const char *pidfile)
> -{
> -     char buf[100];
> -     int len;
> -     int fd;
> -
> -     fd = open(pidfile, O_RDWR | O_CREAT, 0600);
> -     if (fd == -1)
> -             barf_perror("Opening pid file %s", pidfile);
> -
> -     /* We exit silently if daemon already running. */
> -     if (lockf(fd, F_TLOCK, 0) == -1)
> -             exit(0);
> -
> -     len = snprintf(buf, sizeof(buf), "%ld\n", (long)getpid());
> -     if (write(fd, buf, len) != len)
> -             barf_perror("Writing pid file %s", pidfile);
> -}
> -
> -/* Stevens. */
> -static void daemonize(void)
> -{
> -     pid_t pid;
> -
> -     /* Separate from our parent via fork, so init inherits us. */
> -     if ((pid = fork()) < 0)
> -             barf_perror("Failed to fork daemon");
> -     if (pid != 0)
> -             exit(0);
> -
> -     /* Session leader so ^C doesn't whack us. */
> -     setsid();
> -
> -     /* Let session leader exit so child cannot regain CTTY */
> -     if ((pid = fork()) < 0)
> -             barf_perror("Failed to fork daemon");
> -     if (pid != 0)
> -             exit(0);
> -
> -     /* Move off any mount points we might be in. */
> -     if (chdir("/") == -1)
> -             barf_perror("Failed to chdir");
> -
> -     /* Discard our parent's old-fashioned umask prejudices. */
> -     umask(0);
> -}
> -
>  #ifdef NO_SOCKETS
>  static void init_sockets(int **psock, int **pro_sock)
>  {
> @@ -1874,20 +1827,10 @@ int main(int argc, char *argv[])
>  
>       reopen_log();
>  
> -     /* make sure xenstored directory exists */
> -     if (mkdir(xs_daemon_rundir(), 0755)) {
> -             if (errno != EEXIST) {
> -                     perror("error: mkdir daemon rundir");
> -                     exit(-1);
> -             }
> -     }
> -
> -     if (mkdir(xs_daemon_rootdir(), 0755)) {
> -             if (errno != EEXIST) {
> -                     perror("error: mkdir daemon rootdir");
> -                     exit(-1);
> -             }
> -     }
> +     /* make sure xenstored directories exist */
> +     /* Errors ignored here, will be reported when we open files */
> +     mkdir(xs_daemon_rundir(), 0755);
> +     mkdir(xs_daemon_rootdir(), 0755);
>  
>       if (dofork) {
>               openlog("xenstored", 0, LOG_DAEMON);
> @@ -1904,10 +1847,7 @@ int main(int argc, char *argv[])
>       signal(SIGPIPE, SIG_IGN);
>  
>       init_sockets(&sock, &ro_sock);
> -
> -     if (pipe(reopen_log_pipe)) {
> -             barf_perror("pipe");
> -     }
> +     init_pipe(reopen_log_pipe);
>  
>       /* Setup the database */
>       setup_structure();
> @@ -1925,16 +1865,8 @@ int main(int argc, char *argv[])
>       }
>  
>       /* redirect to /dev/null now we're ready to accept connections */
> -     if (dofork) {
> -             int devnull = open("/dev/null", O_RDWR);
> -             if (devnull == -1)
> -                     barf_perror("Could not open /dev/null\n");
> -             dup2(devnull, STDIN_FILENO);
> -             dup2(devnull, STDOUT_FILENO);
> -             dup2(devnull, STDERR_FILENO);
> -             close(devnull);
> -             xprintf = trace;
> -     }
> +     if (dofork)
> +             finish_daemonize();
>  
>       signal(SIGHUP, trigger_reopen_log);
>  
> @@ -1957,7 +1889,7 @@ int main(int argc, char *argv[])
>                       barf_perror("Select failed");
>               }
>  
> -             if (FD_ISSET(reopen_log_pipe[0], &inset)) {
> +             if (reopen_log_pipe[0] != -1 && FD_ISSET(reopen_log_pipe[0], 
> &inset)) {
>                       char c;
>                       if (read(reopen_log_pipe[0], &c, 1) != 1)
>                               barf_perror("read failed");
> diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_core.h
> index c487089..f074955 100644
> --- a/tools/xenstore/xenstored_core.h
> +++ b/tools/xenstore/xenstored_core.h
> @@ -171,6 +171,7 @@ extern int event_fd;
>  
>  /* Map the kernel's xenstore page. */
>  void *xenbus_map(void);
> +void unmap_xenbus(void *interface);
>  
>  /* Return the event channel used by xenbus. */
>  evtchn_port_t xenbus_evtchn(void);
> @@ -178,6 +179,17 @@ evtchn_port_t xenbus_evtchn(void);
>  /* Tell the kernel xenstored is running. */
>  void xenbus_notify_running(void);
>  
> +/* Write out the pidfile */
> +void write_pidfile(const char *pidfile);
> +
> +/* Fork but do not close terminal FDs */
> +void daemonize(void);
> +/* Close stdin/stdout/stderr to complete daemonize */
> +void finish_daemonize(void);
> +
> +/* Open a pipe for signal handling */
> +void init_pipe(int reopen_log_pipe[2]);
> +
>  #endif /* _XENSTORED_CORE_H */
>  
>  /*
> diff --git a/tools/xenstore/xenstored_domain.c 
> b/tools/xenstore/xenstored_domain.c
> index c521e52..6206961 100644
> --- a/tools/xenstore/xenstored_domain.c
> +++ b/tools/xenstore/xenstored_domain.c
> @@ -200,7 +200,7 @@ static int destroy_domain(void *_domain)
>               /* Domain 0 was mapped by dom0_init, so it must be unmapped
>                  using munmap() and not the grant unmap call. */
>               if (domain->domid == 0)
> -                     munmap(domain->interface, getpagesize());
> +                     unmap_xenbus(domain->interface);
>               else
>                       unmap_interface(domain->interface);
>       }
> diff --git a/tools/xenstore/xenstored_minios.c 
> b/tools/xenstore/xenstored_minios.c
> new file mode 100644
> index 0000000..c8700ba
> --- /dev/null
> +++ b/tools/xenstore/xenstored_minios.c
> @@ -0,0 +1,60 @@
> +/* 
> +    Simple prototype Xen Store Daemon providing simple tree-like database.
> +    Copyright (C) 2005 Rusty Russell IBM Corporation
> +
> +    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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
> +*/
> +#include <sys/types.h>
> +#include <sys/mman.h>
> +#include <xenctrl.h>
> +#include "xenstored_core.h"
> +#include <xen/grant_table.h>
> +
> +void write_pidfile(const char *pidfile)
> +{
> +}
> +
> +void daemonize(void)
> +{
> +}
> +
> +void finish_daemonize(void)
> +{
> +}
> +
> +void init_pipe(int reopen_log_pipe[2])
> +{
> +     reopen_log_pipe[0] = -1;
> +     reopen_log_pipe[1] = -1;
> +}
> +
> +void xenbus_notify_running(void)
> +{
> +}
> +
> +evtchn_port_t xenbus_evtchn(void)
> +{
> +     return -1;
> +}
> +
> +void *xenbus_map(void)
> +{
> +     return NULL;
> +}
> +
> +void unmap_xenbus(void *interface)
> +{
> +}
> +
> diff --git a/tools/xenstore/xenstored_posix.c 
> b/tools/xenstore/xenstored_posix.c
> new file mode 100644
> index 0000000..25bdf74
> --- /dev/null
> +++ b/tools/xenstore/xenstored_posix.c
> @@ -0,0 +1,99 @@
> +/* 
> +    Simple prototype Xen Store Daemon providing simple tree-like database.
> +    Copyright (C) 2005 Rusty Russell IBM Corporation
> +
> +    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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
> +*/
> +
> +#include <sys/types.h>
> +#include <sys/stat.h>
> +#include <unistd.h>
> +#include <fcntl.h>
> +#include <stdlib.h>
> +#include <sys/mman.h>
> +
> +#include "utils.h"
> +#include "xenstored_core.h"
> +
> +void write_pidfile(const char *pidfile)
> +{
> +     char buf[100];
> +     int len;
> +     int fd;
> +
> +     fd = open(pidfile, O_RDWR | O_CREAT, 0600);
> +     if (fd == -1)
> +             barf_perror("Opening pid file %s", pidfile);
> +
> +     /* We exit silently if daemon already running. */
> +     if (lockf(fd, F_TLOCK, 0) == -1)
> +             exit(0);
> +
> +     len = snprintf(buf, sizeof(buf), "%ld\n", (long)getpid());
> +     if (write(fd, buf, len) != len)
> +             barf_perror("Writing pid file %s", pidfile);
> +}
> +
> +/* Stevens. */
> +void daemonize(void)
> +{
> +     pid_t pid;
> +
> +     /* Separate from our parent via fork, so init inherits us. */
> +     if ((pid = fork()) < 0)
> +             barf_perror("Failed to fork daemon");
> +     if (pid != 0)
> +             exit(0);
> +
> +     /* Session leader so ^C doesn't whack us. */
> +     setsid();
> +
> +     /* Let session leader exit so child cannot regain CTTY */
> +     if ((pid = fork()) < 0)
> +             barf_perror("Failed to fork daemon");
> +     if (pid != 0)
> +             exit(0);
> +
> +     /* Move off any mount points we might be in. */
> +     if (chdir("/") == -1)
> +             barf_perror("Failed to chdir");
> +
> +     /* Discard our parent's old-fashioned umask prejudices. */
> +     umask(0);
> +}
> +
> +void finish_daemonize(void)
> +{
> +     int devnull = open("/dev/null", O_RDWR);
> +     if (devnull == -1)
> +             barf_perror("Could not open /dev/null\n");
> +     dup2(devnull, STDIN_FILENO);
> +     dup2(devnull, STDOUT_FILENO);
> +     dup2(devnull, STDERR_FILENO);
> +     close(devnull);
> +     xprintf = trace;
> +}
> +
> +void init_pipe(int reopen_log_pipe[2])
> +{
> +     if (pipe(reopen_log_pipe)) {
> +             barf_perror("pipe");
> +     }
> +}
> +
> +void unmap_xenbus(void *interface)
> +{
> +     munmap(interface, getpagesize());
> +}
> -- 
> 1.7.7.6
> 

_______________________________________________
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®.