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

[PATCH 26/29] tools/xenstored: add helpers for filename handling



Add some helpers for handling filenames which might need different
implementations between stubdom and daemon environments:

- expansion of relative filenames (those are not really defined today,
  just expand them to be relative to /var/lib/xen/xenstore)
- expansion of xenstore_daemon_rundir() (used e.g. for saving the state
  file in case of live update - needs to be unchanged in the daemon
  case, but should result in /var/lib/xen/xenstore for stubdom)

Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
---
 tools/xenstored/core.c      | 9 ++++++++-
 tools/xenstored/core.h      | 3 +++
 tools/xenstored/lu_daemon.c | 4 ++--
 tools/xenstored/minios.c    | 5 +++++
 tools/xenstored/posix.c     | 6 ++++++
 5 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/tools/xenstored/core.c b/tools/xenstored/core.c
index 1764b1af4e..9f48d91027 100644
--- a/tools/xenstored/core.c
+++ b/tools/xenstored/core.c
@@ -158,6 +158,13 @@ void trace_destroy(const void *data, const char *type)
                trace("obj: DESTROY %s %p\n", type, data);
 }
 
+char *absolute_filename(const void *ctx, const char *filename)
+{
+       if (filename[0] != '/')
+               return talloc_asprintf(ctx, XENSTORE_LIB_DIR "/%s", filename);
+       return talloc_strdup(ctx, filename);
+}
+
 /**
  * Signal handler for SIGHUP, which requests that the trace log is reopened
  * (in the main loop).  A single byte is written to reopen_log_pipe, to awaken
@@ -2995,7 +3002,7 @@ int main(int argc, char *argv[])
 
        signal(SIGHUP, trigger_reopen_log);
        if (tracefile)
-               tracefile = talloc_strdup(NULL, tracefile);
+               tracefile = absolute_filename(NULL, tracefile);
 
 #ifndef NO_LIVE_UPDATE
        /* Read state in case of live update. */
diff --git a/tools/xenstored/core.h b/tools/xenstored/core.h
index 48ff659ec5..d3cd4a4c8a 100644
--- a/tools/xenstored/core.h
+++ b/tools/xenstored/core.h
@@ -391,6 +391,9 @@ evtchn_port_t get_xenbus_evtchn(void);
 void mount_9pfs(void);
 #endif
 
+const char *xenstore_rundir(void);
+char *absolute_filename(const void *ctx, const char *filename);
+
 /* Write out the pidfile */
 void write_pidfile(const char *pidfile);
 
diff --git a/tools/xenstored/lu_daemon.c b/tools/xenstored/lu_daemon.c
index 71bcabadd3..6351111ab0 100644
--- a/tools/xenstored/lu_daemon.c
+++ b/tools/xenstored/lu_daemon.c
@@ -24,7 +24,7 @@ void lu_get_dump_state(struct lu_dump_state *state)
        state->size = 0;
 
        state->filename = talloc_asprintf(NULL, "%s/state_dump",
-                                         xenstore_daemon_rundir());
+                                         xenstore_rundir());
        if (!state->filename)
                barf("Allocation failure");
 
@@ -65,7 +65,7 @@ FILE *lu_dump_open(const void *ctx)
        int fd;
 
        filename = talloc_asprintf(ctx, "%s/state_dump",
-                                  xenstore_daemon_rundir());
+                                  xenstore_rundir());
        if (!filename)
                return NULL;
 
diff --git a/tools/xenstored/minios.c b/tools/xenstored/minios.c
index e5a3684df6..104f37587b 100644
--- a/tools/xenstored/minios.c
+++ b/tools/xenstored/minios.c
@@ -89,3 +89,8 @@ void mount_9pfs(void)
 {
        create_thread("mount-9pfs", mount_thread, NULL);
 }
+
+const char *xenstore_rundir(void)
+{
+       return XENSTORE_LIB_DIR;
+}
diff --git a/tools/xenstored/posix.c b/tools/xenstored/posix.c
index 7e03dd982d..d02d0e446f 100644
--- a/tools/xenstored/posix.c
+++ b/tools/xenstored/posix.c
@@ -22,6 +22,7 @@
 #include <fcntl.h>
 #include <stdlib.h>
 #include <sys/mman.h>
+#include <xen-tools/xenstore-common.h>
 
 #include "utils.h"
 #include "core.h"
@@ -157,3 +158,8 @@ void *xenbus_map(void)
 
        return addr;
 }
+
+const char *xenstore_rundir(void)
+{
+       return xenstore_daemon_rundir();
+}
-- 
2.35.3




 


Rackspace

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