[lxc-devel] [PATCH 1/1] add dir support

Serge Hallyn serge.hallyn at ubuntu.com
Fri Feb 21 20:36:06 UTC 2014


It used to be supported with the lxc-create.in script, and
the manpage says it's supported...  So let's just support it.

Now

sudo lxc-create -t download --dir /opt/ab -n ab

works, creating the container rootfs under /opt/ab.  This
generally isn't something I'd recommend, however telling users
to use a different lxc-path isn't as friendly as I'd like,
because each lxcpath requires separate lxc-ls and lxc-autostart
runs.

Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
---
 debian/changelog     | 6 ++++++
 src/lxc/bdev.c       | 5 ++++-
 src/lxc/bdev.h       | 1 +
 src/lxc/lxc_create.c | 3 +--
 4 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 9d18421..2deb678 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+lxc (1.0.0+master~20140220-2000-0ubuntu1~ppa1~trusty1ubuntu1) UNRELEASED; urgency=medium
+
+  * implement --dir support
+
+ -- LXC buildbot <ubuntu at c-trusty-2.lxc>  Fri, 21 Feb 2014 20:18:16 +0000
+
 lxc (1.0.0+master~20140220-2000-0ubuntu1~ppa1~trusty1) trusty; urgency=low
 
   * Automated build of git://github.com/lxc/lxc (master branch)
diff --git a/src/lxc/bdev.c b/src/lxc/bdev.c
index 6d88609..952cfeb 100644
--- a/src/lxc/bdev.c
+++ b/src/lxc/bdev.c
@@ -477,7 +477,10 @@ static int dir_destroy(struct bdev *orig)
 static int dir_create(struct bdev *bdev, const char *dest, const char *n,
 			struct bdev_specs *specs)
 {
-	bdev->src = strdup(dest);
+	if (specs->dir)
+		bdev->src = strdup(specs->dir);
+	else
+		bdev->src = strdup(dest);
 	bdev->dest = strdup(dest);
 	if (!bdev->src || !bdev->dest) {
 		ERROR("Out of memory");
diff --git a/src/lxc/bdev.h b/src/lxc/bdev.h
index 7efc164..cc0bf02 100644
--- a/src/lxc/bdev.h
+++ b/src/lxc/bdev.h
@@ -48,6 +48,7 @@ struct bdev_specs {
 		char *lv;
 		char *thinpool; // lvm thin pool to use, if any
 	} lvm;
+	char *dir;
 };
 
 struct bdev_ops {
diff --git a/src/lxc/lxc_create.c b/src/lxc/lxc_create.c
index a3684c1..eee6ffd 100644
--- a/src/lxc/lxc_create.c
+++ b/src/lxc/lxc_create.c
@@ -256,8 +256,7 @@ int main(int argc, char *argv[])
 			spec.lvm.thinpool = my_args.thinpool;
 	}
 	if (my_args.dir) {
-		ERROR("--dir is not yet supported");
-		exit(1);
+		spec.dir = my_args.dir;
 	}
 
 	if (strcmp(my_args.bdevtype, "_unset") == 0)
-- 
1.9.0



More information about the lxc-devel mailing list