Unverified Commit 8608cb0b by Christian Brauner Committed by Stéphane Graber

bdev: non-functional changes

parent 23eb8575
...@@ -337,12 +337,12 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname, ...@@ -337,12 +337,12 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname,
const char *oldpath = c0->config_path; const char *oldpath = c0->config_path;
struct rsync_data data; struct rsync_data data;
/* if the container name doesn't show up in the rootfs path, then /* If the container name doesn't show up in the rootfs path, then we
* we don't know how to come up with a new name * don't know how to come up with a new name.
*/ */
if (!strstr(src, oldname)) { if (!strstr(src, oldname)) {
ERROR("original rootfs path %s doesn't include container name %s", ERROR("Original rootfs path \"%s\" does not include container "
src, oldname); "name \"%s\"", src, oldname);
return NULL; return NULL;
} }
...@@ -371,12 +371,13 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname, ...@@ -371,12 +371,13 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname,
bdev_put(orig); bdev_put(orig);
return NULL; return NULL;
} }
ret = stat(orig->dest, &sb);
if (ret < 0 && errno == ENOENT) ret = stat(orig->dest, &sb);
if (mkdir_p(orig->dest, 0755) < 0) if (ret < 0 && errno == ENOENT) {
WARN("Failed to create directoy \"%s\"", ret = mkdir_p(orig->dest, 0755);
orig->dest); if (ret < 0)
WARN("Failed to create directoy \"%s\"", orig->dest);
}
} }
/* Special case for snapshot. If the caller requested maybe_snapshot and /* Special case for snapshot. If the caller requested maybe_snapshot and
...@@ -386,11 +387,8 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname, ...@@ -386,11 +387,8 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname,
if (maybe_snap && keepbdevtype && !bdevtype && !orig->ops->can_snapshot) if (maybe_snap && keepbdevtype && !bdevtype && !orig->ops->can_snapshot)
snap = false; snap = false;
/* /* If newtype is NULL and snapshot is set, then use overlay. */
* If newtype is NULL and snapshot is set, then use overlayfs if (!bdevtype && !keepbdevtype && snap && strcmp(orig->type, "dir") == 0)
*/
if (!bdevtype && !keepbdevtype && snap &&
strcmp(orig->type, "dir") == 0)
bdevtype = "overlay"; bdevtype = "overlay";
if (am_unpriv() && !unpriv_snap_allowed(orig, bdevtype, snap, maybe_snap)) { if (am_unpriv() && !unpriv_snap_allowed(orig, bdevtype, snap, maybe_snap)) {
...@@ -401,12 +399,12 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname, ...@@ -401,12 +399,12 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname,
} }
*needs_rdep = 0; *needs_rdep = 0;
if (bdevtype && strcmp(orig->type, "dir") == 0 && if (bdevtype && !strcmp(orig->type, "dir") &&
(strcmp(bdevtype, "aufs") == 0 || (strcmp(bdevtype, "aufs") == 0 ||
strcmp(bdevtype, "overlayfs") == 0 || strcmp(bdevtype, "overlayfs") == 0 ||
strcmp(bdevtype, "overlay") == 0)) { strcmp(bdevtype, "overlay") == 0)) {
*needs_rdep = 1; *needs_rdep = 1;
} else if (snap && strcmp(orig->type, "lvm") == 0 && } else if (snap && !strcmp(orig->type, "lvm") &&
!lvm_is_thin_volume(orig->src)) { !lvm_is_thin_volume(orig->src)) {
*needs_rdep = 1; *needs_rdep = 1;
} }
...@@ -419,20 +417,22 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname, ...@@ -419,20 +417,22 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname,
/* get new bdev type */ /* get new bdev type */
new = bdev_get(bdevtype); new = bdev_get(bdevtype);
if (!new) { if (!new) {
ERROR("no such block device type: %s", ERROR("Failed to initialize \"%s\" storage driver",
bdevtype ? bdevtype : orig->type); bdevtype ? bdevtype : orig->type);
bdev_put(orig); bdev_put(orig);
return NULL; return NULL;
} }
TRACE("Detected \"%s\" storage driver", new->type); TRACE("Initialized \"%s\" storage driver", new->type);
/* create new paths */ /* create new paths */
if (new->ops->clone_paths(orig, new, oldname, cname, oldpath, lxcpath, ret = new->ops->clone_paths(orig, new, oldname, cname, oldpath, lxcpath,
snap, newsize, c0->lxc_conf) < 0) { snap, newsize, c0->lxc_conf);
ERROR("Failed getting pathnames for clone of \"%s\"", src); if (ret < 0) {
ERROR("Failed creating new paths for clone of \"%s\"", src);
goto err; goto err;
} }
/* btrfs */
if (!strcmp(orig->type, "btrfs") && !strcmp(new->type, "btrfs")) { if (!strcmp(orig->type, "btrfs") && !strcmp(new->type, "btrfs")) {
bool bret = false; bool bret = false;
if (snap || btrfs_same_fs(orig->dest, new->dest) == 0) if (snap || btrfs_same_fs(orig->dest, new->dest) == 0)
...@@ -444,6 +444,7 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname, ...@@ -444,6 +444,7 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname,
return new; return new;
} }
/* lvm */
if (!strcmp(orig->type, "lvm") && !strcmp(new->type, "lvm")) { if (!strcmp(orig->type, "lvm") && !strcmp(new->type, "lvm")) {
bool bret = false; bool bret = false;
if (snap) if (snap)
...@@ -458,19 +459,22 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname, ...@@ -458,19 +459,22 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname,
} }
if (strcmp(bdevtype, "btrfs")) { if (strcmp(bdevtype, "btrfs")) {
if (!strcmp(new->type, "overlay") || if (!strcmp(new->type, "overlay") || !strcmp(new->type, "overlayfs"))
!strcmp(new->type, "overlayfs"))
src_no_prefix = ovl_get_lower(new->src); src_no_prefix = ovl_get_lower(new->src);
else else
src_no_prefix = lxc_storage_get_path(new->src, new->type); src_no_prefix = lxc_storage_get_path(new->src, new->type);
if (am_unpriv() && chown_mapped_root(src_no_prefix, c0->lxc_conf) < 0) if (am_unpriv()) {
WARN("Failed to chown \"%s\"", src_no_prefix); ret = chown_mapped_root(src_no_prefix, c0->lxc_conf);
if (ret < 0)
WARN("Failed to chown \"%s\"", new->src);
}
} }
if (snap) if (snap)
return new; return new;
/* rsync the contents from source to target */
pid = fork(); pid = fork();
if (pid < 0) { if (pid < 0) {
SYSERROR("fork"); SYSERROR("fork");
......
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