Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

snapshot restore fails spectacularly on btrfs #131

Closed
JohnPeacockMessageSystems opened this issue Jan 10, 2014 · 2 comments
Closed

snapshot restore fails spectacularly on btrfs #131

JohnPeacockMessageSystems opened this issue Jan 10, 2014 · 2 comments
Labels
Bug Confirmed to be a bug
Milestone

Comments

@JohnPeacockMessageSystems

I created a snapshot on a btrfs filesystem and lxc-snapshot correctly
created a btrfs subvolume snapshot. However when restoring the
snapshot, I got this instead:

$ sudo lxc-snapshot -n rh65-dev -r snap0
rsync: writefd_unbuffered failed to write 4 bytes to socket [generator]: Broken pipe (32)
rsync error: error in rsync protocol data stream (code 12) at io.c(1532) [generator=3.0.9]
lxc_container: rsyncing /var/lib/lxc/containersnaps/rh65-dev/snap0/rootfs to /var/lib/lxc/container/rh65-dev/rootfs

lxc_container: Error copying storage
lxc_container: _recursive_rmdir_onedev: failed to delete /var/lib/lxc/container/rh65-dev
lxc_container: Error destroying container directory for rh65-dev
lxc_container: Error restoring snapshot snap0

There are a couple of problems with that:

  1. lxc-snapshot restore is using rsync and not the btrfs snapshot tool, e.g.
btrfs subvolume delete ORIG.ROOTFS
btrfs subvolume snap SNAP.ROOTFS ORIG.ROOTFS
btrfs subvolume delete SNAP.ROOTFS (optional)
  1. lxc-snapshot has now messed up the original subvolume filesystem in such a way that I can no longer restore to the same path:
# rm -r /var/lib/lxc/container/rh65-dev/rootfs
 rm: cannot remove ‘/var/lib/lxc/container/rh65-dev/rootfs’: Operation not permitted

Even though the subvolume was no longer listed by

btrfs subvolume list

(presumably because the rsync had messed it up), but it was apparently
still marked as such in the filesystem metadata (even after a reboot).
I was able to clean up the mess via:

btrfs subvolume delete /var/lib/lxc/container/rh65-dev/rootfs
rm -rf /var/lib/lxc/container/rh65-dev/rootfs

and move the snapshot back in place to restore access to my original
instance.

@ghost ghost assigned hallyn Jan 15, 2014
@hallyn
Copy link
Member

hallyn commented Jan 15, 2014

I will not be able to rework this in the next few weeks. I believe on the mailing list it was agreed that you would attempt a redesign, and I'll look at any patch you send. Otherwise I hope to look at this in february.

@stgraber stgraber modified the milestones: lxc-1.0.1, lxc-1.0 Feb 20, 2014
@caglar10ur
Copy link
Member

Something like following seems to work fine for me. I'm guessing it's not going to work with unprivileged container case but on the other hand I'm not sure whether we support btrfs in that case at all. Pasting here for reference (aka until I find some time to test more and submit to the list)

diff --git a/src/lxc/bdev.c b/src/lxc/bdev.c
index 627c09a..64d0fe0 100644
--- a/src/lxc/bdev.c
+++ b/src/lxc/bdev.c
@@ -2598,6 +2598,30 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname,
        if (snap)
                return new;

+       /*
+        * https://github.com/lxc/lxc/issues/131 - Use btrfs snapshot feature instead of rsync
+        */
+       if (bdevtype && strcmp(orig->type, "btrfs") == 0 && strcmp(new->type, "btrfs") == 0) {
+               if (btrfs_destroy(new) < 0) {
+                       bdev_put(orig);
+                       bdev_put(new);
+                       ERROR("Error destroying %s", new->dest);
+               }
+               if (mkdir_p(new->dest, 0755) < 0) {
+                       ERROR("Error creating %s", new->dest);
+                       bdev_put(orig);
+                       bdev_put(new);
+                       return NULL;
+               }
+               if (btrfs_snapshot(orig->dest, new->dest) < 0) {
+                       bdev_put(orig);
+                       bdev_put(new);
+                       ERROR("Error restoring %s to %s", orig->dest, new->dest);
+               }
+               bdev_put(orig);
+               return new;
+       }
+
        pid = fork();
        if (pid < 0) {
                SYSERROR("fork");

stgraber pushed a commit that referenced this issue Mar 3, 2014
fixes #131

changes since v1;
* uses btrfs snapshot feature only if src and dest are on same fs

Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
z-image pushed a commit to z-image/lxc that referenced this issue Oct 16, 2016
fixes lxc#131

changes since v1;
* uses btrfs snapshot feature only if src and dest are on same fs

Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Confirmed to be a bug
Development

No branches or pull requests

4 participants