Turns out there are two issues:
 1. A snapshot isn't activated automatically --- one needs to supply
    the -K flag to lvcreate to have the snapshot usable immediately.
 2. The kernel really doesn't like not having unique UUIDs when
    mounting filesystems, so the snapshot needs to have its UUID
 reset.

This patch fixes both these issues, at least for ext[234] and XFS.
---
 src/lxc/storage/lvm.c |   24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

Index: lxc-2.0.9/src/lxc/storage/lvm.c
===================================================================
--- lxc-2.0.9.orig/src/lxc/storage/lvm.c
+++ lxc-2.0.9/src/lxc/storage/lvm.c
@@ -267,9 +267,9 @@ int lvm_snapshot(const char *orig, const
 
        (void)setenv("LVM_SUPPRESS_FD_WARNINGS", "1", 1);
        if (!ret) {
-               ret = execlp("lvcreate", "lvcreate", "-s", "-L", sz, "-n", lv, 
orig, (char *)NULL);
+               ret = execlp("lvcreate", "lvcreate", "-K", "-s", "-L", sz, 
"-n", lv, orig, (char *)NULL);
        } else {
-               ret = execlp("lvcreate", "lvcreate", "-s", "-n", lv, orig, 
(char *)NULL);
+               ret = execlp("lvcreate", "lvcreate", "-K", "-s", "-n", lv, 
orig, (char *)NULL);
        }
 
        free(pathdup);
@@ -347,6 +347,26 @@ int lvm_clonepaths(struct lxc_storage *o
                        ERROR("could not create %s snapshot of %s", new->src, 
orig->src);
                        return -1;
                }
+               if (!strcmp(fstype, "xfs") || !strncmp(fstype, "ext", 3)) {
+                       int kidpid = fork();
+                       switch (kidpid) {
+                       case 0:
+                               if (fstype[0] == 'x')
+                                       execlp("xfs_admin", "xfs_admin", "-U", 
"generate", new->src, (char *)NULL);
+                               else
+                                       execlp("tune2fs", "tune2fs", "-U", 
"random", new->src, (char *)NULL);
+                               SYSERROR("execlp");
+                               exit(EXIT_FAILURE);
+                               ;;
+                       case -1:
+                               SYSERROR("fork");
+                               return -1;
+                               ;;
+                       default:
+                               wait_for_pid(kidpid);
+                               ;;
+                       }
+               }
        } else {
                if (do_lvm_create(new->src, size, 
lxc_global_config_value("lxc.bdev.lvm.thin_pool")) < 0) {
                        ERROR("Error creating new lvm blockdev");


-- 
Dr Peter Chubb         Tel: +61 2 9490 5852      http://ts.data61.csiro.au/
Trustworthy Systems Group                           Data61 (formerly NICTA)

Reply via email to