From: Christian Brauner Date: Tue, 28 Nov 2017 11:40:22 +0000 (+0100) Subject: storage: make storage_copy() cleaner X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=552e2dd189538b8c254d79a780607071f5c0e636;p=thirdparty%2Flxc.git storage: make storage_copy() cleaner Signed-off-by: Christian Brauner Signed-off-by: Adrian Reber --- diff --git a/src/lxc/storage/storage.c b/src/lxc/storage/storage.c index 6ec109a47..734773ffa 100644 --- a/src/lxc/storage/storage.c +++ b/src/lxc/storage/storage.c @@ -338,16 +338,16 @@ struct lxc_storage *storage_copy(struct lxc_container *c, const char *cname, uint64_t newsize, bool *needs_rdep) { int ret; - struct lxc_storage *orig, *new; char *src_no_prefix; - bool snap = flags & LXC_CLONE_SNAPSHOT; - bool maybe_snap = flags & LXC_CLONE_MAYBE_SNAPSHOT; - bool keepbdevtype = flags & LXC_CLONE_KEEPBDEVTYPE; + struct lxc_storage *new, *orig; + bool snap = (flags & LXC_CLONE_SNAPSHOT); + bool maybe_snap = (flags & LXC_CLONE_MAYBE_SNAPSHOT); + bool keepbdevtype = (flags & LXC_CLONE_KEEPBDEVTYPE); const char *src = c->lxc_conf->rootfs.path; const char *oldname = c->name; const char *oldpath = c->config_path; - struct rsync_data data = {0}; char cmd_output[MAXPATHLEN] = {0}; + struct rsync_data data = {0}; if (!src) { ERROR("No rootfs specified"); @@ -365,7 +365,7 @@ struct lxc_storage *storage_copy(struct lxc_container *c, const char *cname, orig = storage_init(c->lxc_conf); if (!orig) { - ERROR("Failed to detect storage driver for \"%s\"", src); + ERROR("Failed to detect storage driver for \"%s\"", oldname); return NULL; } @@ -434,11 +434,11 @@ struct lxc_storage *storage_copy(struct lxc_container *c, const char *cname, /* get new bdev type */ new = storage_get(bdevtype); if (!new) { - ERROR("Failed to initialize \"%s\" storage driver", + ERROR("Failed to initialize %s storage driver", bdevtype ? bdevtype : orig->type); goto on_error_put_orig; } - TRACE("Initialized \"%s\" storage driver", new->type); + TRACE("Initialized %s storage driver", new->type); /* create new paths */ ret = new->ops->clone_paths(orig, new, oldname, cname, oldpath, lxcpath, @@ -452,14 +452,15 @@ struct lxc_storage *storage_copy(struct lxc_container *c, const char *cname, * snapshot directory under "//snaps/" we don't need to * record a dependency. If we would restore would also fail. */ - if ((!strcmp(new->type, "overlay") || - !strcmp(new->type, "overlayfs")) && + if ((strcmp(new->type, "overlay") == 0 || + strcmp(new->type, "overlayfs") == 0) && ret == LXC_CLONE_SNAPSHOT) *needs_rdep = false; /* btrfs */ if (!strcmp(orig->type, "btrfs") && !strcmp(new->type, "btrfs")) { - bool bret = false; + bool bret; + if (snap || btrfs_same_fs(orig->dest, new->dest) == 0) bret = new->ops->snapshot(c->lxc_conf, orig, new, 0); else @@ -472,10 +473,10 @@ struct lxc_storage *storage_copy(struct lxc_container *c, const char *cname, /* lvm */ if (!strcmp(orig->type, "lvm") && !strcmp(new->type, "lvm")) { - bool bret = false; + bool bret; + if (snap) - bret = new->ops->snapshot(c->lxc_conf, orig, - new, newsize); + bret = new->ops->snapshot(c->lxc_conf, orig, new, newsize); else bret = new->ops->copy(c->lxc_conf, orig, new, newsize); if (!bret) @@ -486,11 +487,10 @@ struct lxc_storage *storage_copy(struct lxc_container *c, const char *cname, /* zfs */ if (!strcmp(orig->type, "zfs") && !strcmp(new->type, "zfs")) { - bool bret = false; + bool bret; if (snap) - bret = new->ops->snapshot(c->lxc_conf, orig, new, - newsize); + bret = new->ops->snapshot(c->lxc_conf, orig, new, newsize); else bret = new->ops->copy(c->lxc_conf, orig, new, newsize); if (!bret) diff --git a/src/lxc/storage/storage.h b/src/lxc/storage/storage.h index 2e6d40ac2..2c420097f 100644 --- a/src/lxc/storage/storage.h +++ b/src/lxc/storage/storage.h @@ -126,7 +126,7 @@ extern bool storage_can_backup(struct lxc_conf *conf); extern struct lxc_storage *storage_init(struct lxc_conf *conf); -extern struct lxc_storage *storage_copy(struct lxc_container *c0, +extern struct lxc_storage *storage_copy(struct lxc_container *c, const char *cname, const char *lxcpath, const char *bdevtype, int flags, const char *bdevdata, uint64_t newsize,