]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Revert "btrfs: switch to new rsync helpers"
authorChristian Brauner <christian.brauner@ubuntu.com>
Tue, 15 Aug 2017 16:06:42 +0000 (18:06 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 15 Aug 2017 16:44:26 +0000 (18:44 +0200)
This reverts commit d8bb582ae3ffd1864f20bd0a9548b2a06ded66c0.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/bdev/lxcbtrfs.c

index 746099630e97391ef95ff2028494af3a863f148f..2eaf27e86d11ec277d2f84ac200673c6f69e01f7 100644 (file)
@@ -242,8 +242,8 @@ static int btrfs_subvolume_create(const char *path)
        *p = '\0';
 
        fd = open(newfull, O_RDONLY);
+       free(newfull);
        if (fd < 0) {
-               free(newfull);
                return -errno;
        }
 
@@ -255,7 +255,6 @@ static int btrfs_subvolume_create(const char *path)
        saved_errno = errno;
 
        close(fd);
-       free(newfull);
        errno = saved_errno;
        return ret;
 }
@@ -417,9 +416,8 @@ int btrfs_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
 bool btrfs_create_clone(struct lxc_conf *conf, struct bdev *orig,
                        struct bdev *new, uint64_t newsize)
 {
-       int ret;
-       struct rsync_data data = {0, 0};
-       char cmd_output[MAXPATHLEN] = {0};
+       int pid, ret;
+       struct rsync_data data;
 
        ret = rmdir(new->dest);
        if (ret < 0 && errno != ENOENT)
@@ -431,29 +429,37 @@ bool btrfs_create_clone(struct lxc_conf *conf, struct bdev *orig,
                return false;
        }
 
-       /* rsync the contents from source to target */
-       data.orig = orig;
-       data.new = new;
-       if (am_unpriv()) {
-               ret = userns_exec_1(conf, lxc_rsync_exec_wrapper, &data,
-                                   "lxc_rsync_exec_wrapper");
+       /* rsync contents */
+       pid = fork();
+       if (pid < 0) {
+               SYSERROR("fork");
+               return false;
+       }
+
+       if (pid > 0) {
+               int ret = wait_for_pid(pid);
+               bdev_put(orig);
                if (ret < 0) {
-                       ERROR("Failed to rsync from \"%s\" into \"%s\"",
-                             orig->dest, new->dest);
+                       bdev_put(new);
                        return false;
                }
-
                return true;
        }
 
-       ret = run_command(cmd_output, sizeof(cmd_output),
-                       lxc_rsync_exec_wrapper, (void *)&data);
+       data.orig = orig;
+       data.new = new;
+
+       if (am_unpriv())
+               ret = userns_exec_1(conf, rsync_rootfs_wrapper, &data,
+                                   "rsync_rootfs_wrapper");
+       else
+               ret = rsync_rootfs(&data);
        if (ret < 0) {
-               ERROR("Failed to rsync from \"%s\" into \"%s\": %s", orig->dest,
-                     new->dest, cmd_output);
+               ERROR("Failed to rsync");
                return false;
        }
 
+       TRACE("Created btrfs subvolume \"%s\"", new->dest);
        return true;
 }
 
@@ -839,27 +845,16 @@ int btrfs_create(struct bdev *bdev, const char *dest, const char *n,
        /* strlen("btrfs:") */
        len += 6;
        bdev->src = malloc(len);
-       if (!bdev->src) {
-               ERROR("Failed to allocate memory");
+       if (!bdev->src)
                return -1;
-       }
 
        ret = snprintf(bdev->src, len, "btrfs:%s", dest);
-       if (ret < 0 || (size_t)ret >= len) {
-               ERROR("Failed to create string");
+       if (ret < 0 || (size_t)ret >= len)
                return -1;
-       }
 
        bdev->dest = strdup(dest);
-       if (!bdev->dest) {
-               ERROR("Failed to duplicate string \"%s\"", dest);
+       if (!bdev->dest)
                return -1;
-       }
 
-       ret = btrfs_subvolume_create(bdev->dest);
-       if (ret < 0) {
-               SYSERROR("Failed to create btrfs subvolume \"%s\"", bdev->dest);
-       }
-
-       return ret;
+       return btrfs_subvolume_create(bdev->dest);
 }