2
0
mirror of git://github.com/lxc/lxc synced 2025-09-03 16:29:38 +00:00

storage: non-functional changes

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
This commit is contained in:
Christian Brauner
2017-07-29 17:27:18 +02:00
parent 10bc186195
commit 07db51a27c
3 changed files with 53 additions and 53 deletions

View File

@@ -3116,7 +3116,7 @@ static int copy_storage(struct lxc_container *c0, struct lxc_container *c,
uint64_t newsize) uint64_t newsize)
{ {
struct lxc_storage *bdev; struct lxc_storage *bdev;
int need_rdep; bool need_rdep;
if (should_default_to_snapshot(c0, c)) if (should_default_to_snapshot(c0, c))
flags |= LXC_CLONE_SNAPSHOT; flags |= LXC_CLONE_SNAPSHOT;

View File

@@ -315,22 +315,22 @@ bool storage_can_backup(struct lxc_conf *conf)
/* If we're not snaphotting, then storage_copy becomes a simple case of mount /* If we're not snaphotting, then storage_copy becomes a simple case of mount
* the original, mount the new, and rsync the contents. * the original, mount the new, and rsync the contents.
*/ */
struct lxc_storage *storage_copy(struct lxc_container *c0, const char *cname, struct lxc_storage *storage_copy(struct lxc_container *c, const char *cname,
const char *lxcpath, const char *bdevtype, const char *lxcpath, const char *bdevtype,
int flags, const char *bdevdata, int flags, const char *bdevdata,
uint64_t newsize, int *needs_rdep) uint64_t newsize, bool *needs_rdep)
{ {
struct lxc_storage *orig, *new;
int ret; int ret;
struct lxc_storage *orig, *new;
char *src_no_prefix; char *src_no_prefix;
bool snap = flags & LXC_CLONE_SNAPSHOT; bool snap = flags & LXC_CLONE_SNAPSHOT;
bool maybe_snap = flags & LXC_CLONE_MAYBE_SNAPSHOT; bool maybe_snap = flags & LXC_CLONE_MAYBE_SNAPSHOT;
bool keepbdevtype = flags & LXC_CLONE_KEEPBDEVTYPE; bool keepbdevtype = flags & LXC_CLONE_KEEPBDEVTYPE;
const char *src = c0->lxc_conf->rootfs.path; const char *src = c->lxc_conf->rootfs.path;
const char *oldname = c0->name; const char *oldname = c->name;
const char *oldpath = c0->config_path; const char *oldpath = c->config_path;
struct rsync_data data; struct rsync_data data = {0};
char cmd_output[MAXPATHLEN]; char cmd_output[MAXPATHLEN] = {0};
/* If the container name doesn't show up in the rootfs path, then we /* If the container name doesn't show up in the rootfs path, then we
* don't know how to come up with a new name. * don't know how to come up with a new name.
@@ -341,7 +341,7 @@ struct lxc_storage *storage_copy(struct lxc_container *c0, const char *cname,
return NULL; return NULL;
} }
orig = storage_init(c0->lxc_conf, src, NULL, NULL); orig = storage_init(c->lxc_conf, src, NULL, NULL);
if (!orig) { if (!orig) {
ERROR("Failed to detect storage driver for \"%s\"", src); ERROR("Failed to detect storage driver for \"%s\"", src);
return NULL; return NULL;
@@ -356,15 +356,13 @@ struct lxc_storage *storage_copy(struct lxc_container *c0, const char *cname,
orig->dest = malloc(len); orig->dest = malloc(len);
if (!orig->dest) { if (!orig->dest) {
ERROR("Failed to allocate memory"); ERROR("Failed to allocate memory");
storage_put(orig); goto on_error_put_orig;
return NULL;
} }
ret = snprintf(orig->dest, len, "%s/%s/rootfs", oldpath, oldname); ret = snprintf(orig->dest, len, "%s/%s/rootfs", oldpath, oldname);
if (ret < 0 || (size_t)ret >= len) { if (ret < 0 || (size_t)ret >= len) {
ERROR("Failed to create string"); ERROR("Failed to create string");
storage_put(orig); goto on_error_put_orig;
return NULL;
} }
ret = stat(orig->dest, &sb); ret = stat(orig->dest, &sb);
@@ -389,19 +387,18 @@ struct lxc_storage *storage_copy(struct lxc_container *c0, const char *cname,
if (am_unpriv() && !unpriv_snap_allowed(orig, bdevtype, snap, maybe_snap)) { if (am_unpriv() && !unpriv_snap_allowed(orig, bdevtype, snap, maybe_snap)) {
ERROR("Unsupported snapshot type \"%s\" for unprivileged users", ERROR("Unsupported snapshot type \"%s\" for unprivileged users",
bdevtype ? bdevtype : "(null)"); bdevtype ? bdevtype : "(null)");
storage_put(orig); goto on_error_put_orig;
return NULL;
} }
*needs_rdep = 0; *needs_rdep = false;
if (bdevtype && !strcmp(orig->type, "dir") && 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 = true;
} else if (snap && !strcmp(orig->type, "lvm") && } else if (snap && !strcmp(orig->type, "lvm") &&
!lvm_is_thin_volume(orig->src)) { !lvm_is_thin_volume(orig->src)) {
*needs_rdep = 1; *needs_rdep = true;
} }
if (strcmp(oldpath, lxcpath) && !bdevtype && !snap) if (strcmp(oldpath, lxcpath) && !bdevtype && !snap)
@@ -414,42 +411,43 @@ struct lxc_storage *storage_copy(struct lxc_container *c0, const char *cname,
if (!new) { if (!new) {
ERROR("Failed to initialize \"%s\" storage driver", ERROR("Failed to initialize \"%s\" storage driver",
bdevtype ? bdevtype : orig->type); bdevtype ? bdevtype : orig->type);
storage_put(orig); goto on_error_put_orig;
return NULL;
} }
TRACE("Initialized \"%s\" storage driver", new->type); TRACE("Initialized \"%s\" storage driver", new->type);
/* create new paths */ /* create new paths */
ret = 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); snap, newsize, c->lxc_conf);
if (ret < 0) { if (ret < 0) {
ERROR("Failed creating new paths for clone of \"%s\"", src); ERROR("Failed creating new paths for clone of \"%s\"", src);
goto err; goto on_error_put_new;
} }
/* btrfs */ /* 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)
bret = new->ops->snapshot(c0->lxc_conf, orig, new, 0); bret = new->ops->snapshot(c->lxc_conf, orig, new, 0);
else else
bret = new->ops->copy(c0->lxc_conf, orig, new, 0); bret = new->ops->copy(c->lxc_conf, orig, new, 0);
if (!bret) if (!bret)
return NULL; goto on_error_put_new;
return new;
goto on_success;
} }
/* lvm */ /* 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)
bret = new->ops->snapshot(c0->lxc_conf, orig, bret = new->ops->snapshot(c->lxc_conf, orig,
new, newsize); new, newsize);
else else
bret = new->ops->copy(c0->lxc_conf, orig, new, newsize); bret = new->ops->copy(c->lxc_conf, orig, new, newsize);
if (!bret) if (!bret)
return NULL; goto on_error_put_new;
return new;
goto on_success;
} }
/* zfs */ /* zfs */
@@ -457,13 +455,14 @@ struct lxc_storage *storage_copy(struct lxc_container *c0, const char *cname,
bool bret = false; bool bret = false;
if (snap) if (snap)
bret = new->ops->snapshot(c0->lxc_conf, orig, new, bret = new->ops->snapshot(c->lxc_conf, orig, new,
newsize); newsize);
else else
bret = new->ops->copy(c0->lxc_conf, orig, new, newsize); bret = new->ops->copy(c->lxc_conf, orig, new, newsize);
if (!bret) if (!bret)
return NULL; goto on_error_put_new;
return new;
goto on_success;
} }
if (strcmp(bdevtype, "btrfs")) { if (strcmp(bdevtype, "btrfs")) {
@@ -473,42 +472,43 @@ struct lxc_storage *storage_copy(struct lxc_container *c0, const char *cname,
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()) { if (am_unpriv()) {
ret = chown_mapped_root(src_no_prefix, c0->lxc_conf); ret = chown_mapped_root(src_no_prefix, c->lxc_conf);
if (ret < 0) if (ret < 0)
WARN("Failed to chown \"%s\"", new->src); WARN("Failed to chown \"%s\"", new->src);
} }
} }
if (snap) if (snap)
return new; goto on_success;
/* rsync the contents from source to target */ /* rsync the contents from source to target */
data.orig = orig; data.orig = orig;
data.new = new; data.new = new;
if (am_unpriv()) { if (am_unpriv())
ret = userns_exec_1(c0->lxc_conf, lxc_rsync_exec_wrapper, &data, ret = userns_exec_1(c->lxc_conf, lxc_rsync_exec_wrapper, &data,
"lxc_rsync_exec_wrapper"); "lxc_rsync_exec_wrapper");
if (ret < 0) { else
ERROR("Failed to rsync from \"%s\" into \"%s\"",
orig->dest, new->dest);
goto err;
}
} else {
ret = run_command(cmd_output, sizeof(cmd_output), ret = run_command(cmd_output, sizeof(cmd_output),
lxc_rsync_exec_wrapper, (void *)&data); lxc_rsync_exec_wrapper, (void *)&data);
if (ret < 0) { if (ret < 0) {
ERROR("Failed to rsync from \"%s\" into \"%s\": %s", ERROR("Failed to rsync from \"%s\" into \"%s\"%s%s", orig->dest,
orig->dest, new->dest, cmd_output); new->dest,
goto err; cmd_output[0] != '\0' ? ": " : "",
} cmd_output[0] != '\0' ? cmd_output : "");
goto on_error_put_new;
} }
on_success:
storage_put(orig); storage_put(orig);
return new; return new;
err: on_error_put_new:
storage_put(orig);
storage_put(new); storage_put(new);
on_error_put_orig:
storage_put(orig);
return NULL; return NULL;
} }

View File

@@ -119,7 +119,7 @@ extern struct lxc_storage *storage_copy(struct lxc_container *c0,
const char *cname, const char *lxcpath, const char *cname, const char *lxcpath,
const char *bdevtype, int flags, const char *bdevtype, int flags,
const char *bdevdata, uint64_t newsize, const char *bdevdata, uint64_t newsize,
int *needs_rdep); bool *needs_rdep);
extern struct lxc_storage *storage_create(const char *dest, const char *type, extern struct lxc_storage *storage_create(const char *dest, const char *type,
const char *cname, const char *cname,
struct bdev_specs *specs); struct bdev_specs *specs);