Commit 0faa844c by Serge Hallyn Committed by Stéphane Graber

snapshot: fix overlayfs restore

And add a testcase to catch regressions. Without this patch, restoring a snapshot of an overlayfs based container fails, because we do not pass in LXC_CLONE_SNAPSHOT, and overlayfs does not support clone without snapshot. Signed-off-by: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com> Acked-by: 's avatarStéphane Graber <stgraber@ubuntu.com>
parent 94f835fc
......@@ -3044,7 +3044,7 @@ out_free:
static bool lxcapi_snapshot_restore(struct lxc_container *c, const char *snapname, const char *newname)
{
char clonelxcpath[MAXPATHLEN];
int ret;
int flags = 0,ret;
struct lxc_container *snap, *rest;
struct bdev *bdev;
bool b = false;
......@@ -3082,7 +3082,10 @@ static bool lxcapi_snapshot_restore(struct lxc_container *c, const char *snapnam
return false;
}
rest = lxcapi_clone(snap, newname, c->config_path, 0, bdev->type, NULL, 0, NULL);
if (strcmp(bdev->type, "dir") != 0 && strcmp(bdev->type, "loop") != 0)
flags = LXC_CLONE_SNAPSHOT | LXC_CLONE_MAYBE_SNAPSHOT;
rest = lxcapi_clone(snap, newname, c->config_path, flags,
bdev->type, NULL, 0, NULL);
bdev_put(bdev);
if (rest && lxcapi_is_defined(rest))
b = true;
......
......@@ -26,6 +26,7 @@
#include "lxc/lxc.h"
#define MYNAME "snapxxx1"
#define MYNAME2 "snapxxx3"
#define RESTNAME "snapxxx2"
static void try_to_remove(void)
......@@ -45,6 +46,12 @@ static void try_to_remove(void)
c->destroy(c);
lxc_container_put(c);
}
c = lxc_container_new(MYNAME2, NULL);
if (c) {
if (c->is_defined(c))
c->destroy(c);
lxc_container_put(c);
}
c = lxc_container_new(MYNAME, NULL);
if (c) {
if (c->is_defined(c))
......@@ -55,7 +62,7 @@ static void try_to_remove(void)
int main(int argc, char *argv[])
{
struct lxc_container *c;
struct lxc_container *c, *c2 = NULL;
char *template = "busybox";
if (argc > 1)
......@@ -84,7 +91,7 @@ int main(int argc, char *argv[])
c->load_config(c, NULL);
if (c->snapshot(c, NULL) != 0) {
fprintf(stderr, "%s: %d: failed to create snapsot\n", __FILE__, __LINE__);
fprintf(stderr, "%s: %d: failed to create snapshot\n", __FILE__, __LINE__);
goto err;
}
......@@ -126,6 +133,48 @@ int main(int argc, char *argv[])
goto err;
}
c2 = c->clone(c, MYNAME2, NULL, LXC_CLONE_SNAPSHOT, "overlayfs", NULL, 0, NULL);
if (!c2) {
fprintf(stderr, "%d: %s overlayfs clone failed\n", __LINE__, MYNAME2);
goto good;
}
if (c2->snapshot(c2, NULL) != 0) {
fprintf(stderr, "%s: %d: failed to create snapshot\n", __FILE__, __LINE__);
goto err;
}
n = c2->snapshot_list(c2, &s);
if (n < 1) {
fprintf(stderr, "%s: %d: failed listing containers\n", __FILE__, __LINE__);
goto err;
}
if (strcmp(s->name, "snap0") != 0) {
fprintf(stderr, "%s: %d: snapshot had bad name\n", __FILE__, __LINE__);
goto err;
}
for (i=0; i<n; i++) {
s[i].free(&s[i]);
}
free(s);
if (!c2->snapshot_restore(c2, "snap0", NULL)) {
fprintf(stderr, "%s: %d: failed to restore overlayfs snapshot\n", __FILE__, __LINE__);
goto err;
}
if (!c2->snapshot_destroy(c2, "snap0")) {
fprintf(stderr, "%s: %d: failed to destroy overlayfs snapshot\n", __FILE__, __LINE__);
goto err;
}
if (!c2->destroy(c2)) {
fprintf(stderr, "%s: %d: failed to destroy container\n", __FILE__, __LINE__);
goto err;
}
good:
if (!c->destroy(c)) {
fprintf(stderr, "%s: %d: failed to destroy container\n", __FILE__, __LINE__);
goto err;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment