[lxc-devel] [go-lxc/v2] Use preserve inodes

tych0 on Github lxc-bot at linuxcontainers.org
Wed May 11 15:37:47 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 302 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160511/05ff051a/attachment.bin>
-------------- next part --------------
From a981ab97deea4c873f7897bfeab5966ef3358bd5 Mon Sep 17 00:00:00 2001
From: Tycho Andersen <tycho.andersen at canonical.com>
Date: Mon, 9 May 2016 16:43:34 +0000
Subject: [PATCH 1/2] remove commented out code

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 lxc-binding.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/lxc-binding.h b/lxc-binding.h
index 1efd888..dd10716 100644
--- a/lxc-binding.h
+++ b/lxc-binding.h
@@ -84,4 +84,3 @@ int go_lxc_migrate(struct lxc_container *c, unsigned int cmd, struct migrate_opt
 
 extern bool go_lxc_attach_interface(struct lxc_container *c, const char *dev, const char *dst_dev);
 extern bool go_lxc_detach_interface(struct lxc_container *c, const char *dev, const char *dst_dev);
-// void lxc_log_close(void);

From 15809f61ec23cd52bf671489ec2ab63ff8db134d Mon Sep 17 00:00:00 2001
From: Tycho Andersen <tycho.andersen at canonical.com>
Date: Wed, 11 May 2016 14:03:31 +0000
Subject: [PATCH 2/2] add support for lxc's preserves_inodes

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 container.go  |  9 ++++++++-
 lxc-binding.c |  6 +++++-
 lxc-binding.h | 10 +++++++++-
 options.go    |  9 +++++----
 4 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/container.go b/container.go
index 9b047ca..d8d0a93 100644
--- a/container.go
+++ b/container.go
@@ -1509,6 +1509,9 @@ func (c *Container) Migrate(cmd uint, opts MigrateOptions) error {
 		defer C.free(unsafe.Pointer(cpredumpdir))
 	}
 
+	/* Since we can't do conditional compilation here, we allocate the
+	 * "extras" struct and then merge them in the C code.
+	 */
 	copts := C.struct_migrate_opts{
 		directory:   cdirectory,
 		verbose:     C.bool(opts.Verbose),
@@ -1516,7 +1519,11 @@ func (c *Container) Migrate(cmd uint, opts MigrateOptions) error {
 		predump_dir: cpredumpdir,
 	}
 
-	ret := C.int(C.go_lxc_migrate(c.container, C.uint(cmd), &copts))
+	extras := C.struct_extra_migrate_opts{
+		preserves_inodes: C.bool(opts.PreservesInodes),
+	}
+
+	ret := C.int(C.go_lxc_migrate(c.container, C.uint(cmd), &copts, &extras))
 	if ret != 0 {
 		return fmt.Errorf("migration failed %d\n", ret)
 	}
diff --git a/lxc-binding.c b/lxc-binding.c
index a3dd0a4..90ba45c 100644
--- a/lxc-binding.c
+++ b/lxc-binding.c
@@ -365,7 +365,11 @@ bool go_lxc_restore(struct lxc_container *c, char *directory, bool verbose) {
 #endif
 }
 
-int go_lxc_migrate(struct lxc_container *c, unsigned int cmd, struct migrate_opts *opts) {
+int go_lxc_migrate(struct lxc_container *c, unsigned int cmd, struct migrate_opts *opts, struct extra_migrate_opts *extras) {
+#if VERSION_AT_LEAST(2, 0, 1)
+	opts->preserves_inodes = extras->preserves_inodes;
+#endif
+
 #if VERSION_AT_LEAST(2, 0, 0)
 	return c->migrate(c, cmd, opts, sizeof(*opts));
 #else
diff --git a/lxc-binding.h b/lxc-binding.h
index dd10716..e114494 100644
--- a/lxc-binding.h
+++ b/lxc-binding.h
@@ -80,7 +80,15 @@ struct migrate_opts {
 	char *predump_dir;
 };
 #endif
-int go_lxc_migrate(struct lxc_container *c, unsigned int cmd, struct migrate_opts *opts);
+
+/* This is a struct that we can add "extra" (i.e. options added after 2.0.0)
+ * migrate options to, so that we don't have to have a massive function
+ * signature when the list of options grows.
+ */
+struct extra_migrate_opts {
+	bool preserves_inodes;
+};
+int go_lxc_migrate(struct lxc_container *c, unsigned int cmd, struct migrate_opts *opts, struct extra_migrate_opts *extras);
 
 extern bool go_lxc_attach_interface(struct lxc_container *c, const char *dev, const char *dst_dev);
 extern bool go_lxc_detach_interface(struct lxc_container *c, const char *dev, const char *dst_dev);
diff --git a/options.go b/options.go
index 4d9ea6d..030c35f 100644
--- a/options.go
+++ b/options.go
@@ -189,8 +189,9 @@ type RestoreOptions struct {
 }
 
 type MigrateOptions struct {
-	Directory  string
-	Verbose    bool
-	Stop       bool
-	PredumpDir string
+	Directory       string
+	Verbose         bool
+	Stop            bool
+	PredumpDir      string
+	PreservesInodes bool
 }


More information about the lxc-devel mailing list