aboutsummaryrefslogtreecommitdiffstats
path: root/tools/xenstore
diff options
context:
space:
mode:
authorAlex Zeffertt <alex.zeffertt@eu.citrix.com>2012-02-09 18:33:33 +0000
committerAlex Zeffertt <alex.zeffertt@eu.citrix.com>2012-02-09 18:33:33 +0000
commit70e3b0ad2a058a8c2a8bce254321dfcce5459a18 (patch)
treeee98f926fcb2f1ada6f51021ba861d3313cd9464 /tools/xenstore
parent179daa44debfdac406d7590c81dff60d97e788c9 (diff)
downloadxen-70e3b0ad2a058a8c2a8bce254321dfcce5459a18.tar.gz
xen-70e3b0ad2a058a8c2a8bce254321dfcce5459a18.tar.bz2
xen-70e3b0ad2a058a8c2a8bce254321dfcce5459a18.zip
xenstored: support for tdb_copy with TDB_INTERNAL
The tdb_copy function should honor the TDB_INTERNAL flag for in-memory databases; this is required to run in mini-os which does not use a filesystem. Signed-off-by: Diego Ongaro <diego.ongaro@citrix.com> Signed-off-by: Alex Zeffertt <alex.zeffertt@eu.citrix.com> Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov> Acked-by: Ian Campbell <ian.campbell@citrix.com> Cc: Ian Jackson <ian.jackson@eu.citrix.com> Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Committed-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Diffstat (limited to 'tools/xenstore')
-rw-r--r--tools/xenstore/tdb.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/tools/xenstore/tdb.c b/tools/xenstore/tdb.c
index 63205e1042..3ecd3fc648 100644
--- a/tools/xenstore/tdb.c
+++ b/tools/xenstore/tdb.c
@@ -2103,6 +2103,41 @@ TDB_CONTEXT *tdb_copy(TDB_CONTEXT *tdb, const char *outfile)
int fd, saved_errno;
TDB_CONTEXT *copy;
+ if (tdb->flags & TDB_INTERNAL) {
+ struct tdb_header *copydb;
+
+ copy = talloc_zero(outfile, TDB_CONTEXT);
+ if (copy == NULL) {
+ errno = ENOMEM;
+ goto intfail;
+ }
+ memcpy(copy, tdb, sizeof(TDB_CONTEXT));
+
+ if (copy->name || copy->locked || copy->device || copy->inode) {
+ fprintf(stderr, "tdb_copy assumption(s) failed\n");
+ goto intfail;
+ }
+
+ copydb = talloc_zero_size(copy, copy->map_size);
+ if (copydb == NULL) {
+ errno = ENOMEM;
+ goto intfail;
+ }
+ memcpy(copydb, copy->map_ptr, copy->map_size);
+ copy->map_ptr = (char*) copydb;
+
+ if (tdb_brlock(tdb, GLOBAL_LOCK, F_UNLCK, F_SETLKW, 0) == -1)
+ goto intfail;
+
+ copy->next = tdbs;
+ tdbs = copy;
+
+ return copy;
+intfail:
+ talloc_free(copy);
+ return NULL;
+ }
+
fd = open(outfile, O_TRUNC|O_CREAT|O_WRONLY, 0640);
if (fd < 0)
return NULL;