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

[Xen-changelog] [xen-unstable] xenstored: support running in minios stubdom



# HG changeset patch
# User Daniel De Graaf <dgdegra@xxxxxxxxxxxxx>
# Date 1328812414 0
# Node ID f371834bac0998d1eaa0cb5d8943f1c231afc5d1
# Parent  2094ba2c2f322ae6280e57cafef19557d46a314a
xenstored: support running in minios stubdom

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

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>
Committed-by: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
---


diff -r 2094ba2c2f32 -r f371834bac09 tools/xenstore/Makefile
--- a/tools/xenstore/Makefile   Thu Feb 09 18:33:34 2012 +0000
+++ b/tools/xenstore/Makefile   Thu Feb 09 18:33:34 2012 +0000
@@ -13,9 +13,10 @@
 
 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 @@
 
 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 @@
 xenstored: $(XENSTORED_OBJS)
        $(CC) $(LDFLAGS) $^ $(LDLIBS_libxenctrl) $(SOCKET_LIBS) -o $@ 
$(APPEND_LDFLAGS)
 
+xenstored.a: $(XENSTORED_OBJS)
+       $(AR) cr $@ $^
+
 $(CLIENTS): xenstore
        ln -f xenstore $@
 
diff -r 2094ba2c2f32 -r f371834bac09 tools/xenstore/utils.h
--- a/tools/xenstore/utils.h    Thu Feb 09 18:33:34 2012 +0000
+++ b/tools/xenstore/utils.h    Thu Feb 09 18:33:34 2012 +0000
@@ -19,7 +19,9 @@
        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 -r 2094ba2c2f32 -r f371834bac09 tools/xenstore/xenstored_core.c
--- a/tools/xenstore/xenstored_core.c   Thu Feb 09 18:33:34 2012 +0000
+++ b/tools/xenstore/xenstored_core.c   Thu Feb 09 18:33:34 2012 +0000
@@ -224,7 +224,6 @@
        }
 }
 
-
 static bool write_messages(struct connection *conn)
 {
        int ret;
@@ -327,7 +326,8 @@
                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 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 @@
 
        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 @@
        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 @@
        }
 
        /* 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 @@
                        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 -r 2094ba2c2f32 -r f371834bac09 tools/xenstore/xenstored_core.h
--- a/tools/xenstore/xenstored_core.h   Thu Feb 09 18:33:34 2012 +0000
+++ b/tools/xenstore/xenstored_core.h   Thu Feb 09 18:33:34 2012 +0000
@@ -171,6 +171,7 @@
 
 /* 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 @@
 /* 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 -r 2094ba2c2f32 -r f371834bac09 tools/xenstore/xenstored_domain.c
--- a/tools/xenstore/xenstored_domain.c Thu Feb 09 18:33:34 2012 +0000
+++ b/tools/xenstore/xenstored_domain.c Thu Feb 09 18:33:34 2012 +0000
@@ -200,7 +200,7 @@
                /* 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 -r 2094ba2c2f32 -r f371834bac09 tools/xenstore/xenstored_minios.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/xenstore/xenstored_minios.c Thu Feb 09 18:33:34 2012 +0000
@@ -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 -r 2094ba2c2f32 -r f371834bac09 tools/xenstore/xenstored_posix.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/xenstore/xenstored_posix.c  Thu Feb 09 18:33:34 2012 +0000
@@ -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());
+}

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


 


Rackspace

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