Mailing List Archive

[PATCH 12/18] xenstored support for in-memory rather than FS based trivial DB (needed to run on mini-OS)
From: Alex Zeffertt <alex.zeffertt@eu.citrix.com>

tdb_copy (a xen modification to tdb?) should honor the TDB_INTERNAL flag
for in-memory databases.

TODO: leaks memory on error case

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>
---
tools/xenstore/tdb.c | 36 ++++++++++++++++++++++++++++++++++++
1 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/tools/xenstore/tdb.c b/tools/xenstore/tdb.c
index 63205e1..639ce6e 100644
--- a/tools/xenstore/tdb.c
+++ b/tools/xenstore/tdb.c
@@ -2103,6 +2103,42 @@ 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:
+ /* TODO (leaking memory is easier) */
+ return NULL;
+ }
+
fd = open(outfile, O_TRUNC|O_CREAT|O_WRONLY, 0640);
if (fd < 0)
return NULL;
--
1.7.7.5


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
[PATCH 12/18] xenstored support for in-memory rather than FS based trivial DB (needed to run on mini-OS) [ In reply to ]
From: Alex Zeffertt <alex.zeffertt@eu.citrix.com>

tdb_copy (a xen modification to tdb?) should honor the TDB_INTERNAL flag
for in-memory databases.

TODO: leaks memory on error case

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>
---
tools/xenstore/tdb.c | 36 ++++++++++++++++++++++++++++++++++++
1 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/tools/xenstore/tdb.c b/tools/xenstore/tdb.c
index 63205e1..639ce6e 100644
--- a/tools/xenstore/tdb.c
+++ b/tools/xenstore/tdb.c
@@ -2103,6 +2103,42 @@ 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:
+ /* TODO (leaking memory is easier) */
+ return NULL;
+ }
+
fd = open(outfile, O_TRUNC|O_CREAT|O_WRONLY, 0640);
if (fd < 0)
return NULL;
--
1.7.7.5


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
Re: [PATCH 12/18] xenstored support for in-memory rather than FS based trivial DB (needed to run on mini-OS) [ In reply to ]
On Thu, 2012-01-12 at 23:35 +0000, Daniel De Graaf wrote:
> From: Alex Zeffertt <alex.zeffertt@eu.citrix.com>
>
> tdb_copy (a xen modification to tdb?)

I believe so, the original author of xenstored was also the author of
tdb, IIRC.

> should honor the TDB_INTERNAL flag
> for in-memory databases.
>
> TODO: leaks memory on error case

Does this happen on every/any transaction conflict or just if a bad
thing has occurred?

In any case, is fixing it not just a case of calling talloc_free?

FWIW this bit of C xenstored is the main reason I think oxenstored
is/would be a better fit for a stub xenstored.


> 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>
> ---
> tools/xenstore/tdb.c | 36 ++++++++++++++++++++++++++++++++++++
> 1 files changed, 36 insertions(+), 0 deletions(-)
>
> diff --git a/tools/xenstore/tdb.c b/tools/xenstore/tdb.c
> index 63205e1..639ce6e 100644
> --- a/tools/xenstore/tdb.c
> +++ b/tools/xenstore/tdb.c
> @@ -2103,6 +2103,42 @@ 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:
> + /* TODO (leaking memory is easier) */
> + return NULL;
> + }
> +
> fd = open(outfile, O_TRUNC|O_CREAT|O_WRONLY, 0640);
> if (fd < 0)
> return NULL;



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