static int lxc_setup_rootfs(struct lxc_conf *conf)
{
int ret;
- struct bdev *bdev;
+ struct lxc_storage *bdev;
const struct lxc_rootfs *rootfs;
rootfs = &conf->rootfs;
return -1;
}
- bdev = bdev_init(conf, rootfs->path, rootfs->mount, rootfs->options);
+ bdev = storage_init(conf, rootfs->path, rootfs->mount, rootfs->options);
if (!bdev) {
ERROR("Failed to mount rootfs \"%s\" onto \"%s\" with options \"%s\".",
rootfs->path, rootfs->mount,
}
ret = bdev->ops->mount(bdev);
- bdev_put(bdev);
+ storage_put(bdev);
if (ret < 0) {
ERROR("Failed to mount rootfs \"%s\" onto \"%s\" with options \"%s\".",
rootfs->path, rootfs->mount,
return 0;
}
- if (!is_valid_bdev_type(value)) {
+ if (!is_valid_storage_type(value)) {
ERROR("Bad rootfs.backend: '%s'", value);
return -1;
}
return ret == 0;
}
-/*
- * do_bdev_create: thin wrapper around bdev_create(). Like bdev_create(),
- * it returns a mounted bdev on success, NULL on error.
+/* do_storage_create: thin wrapper around storage_create(). Like
+ * storage_create(), it returns a mounted bdev on success, NULL on error.
*/
-static struct bdev *do_bdev_create(struct lxc_container *c, const char *type,
- struct bdev_specs *specs)
+static struct lxc_storage *do_storage_create(struct lxc_container *c,
+ const char *type,
+ struct bdev_specs *specs)
{
char *dest;
size_t len;
- struct bdev *bdev;
+ struct lxc_storage *bdev;
int ret;
/* rootfs.path or lxcpath/lxcname/rootfs */
if (ret < 0 || ret >= len)
return NULL;
- bdev = bdev_create(dest, type, c->name, specs);
+ bdev = storage_create(dest, type, c->name, specs);
if (!bdev) {
ERROR("Failed to create backing store type %s", type);
return NULL;
if (chown_mapped_root(bdev->dest, c->lxc_conf) < 0) {
ERROR("Error chowning %s to container root", bdev->dest);
suggest_default_idmap();
- bdev_put(bdev);
+ storage_put(bdev);
return NULL;
}
}
if (pid == 0) { // child
char *patharg, *namearg, *rootfsarg;
- struct bdev *bdev = NULL;
+ struct lxc_storage *bdev = NULL;
int i;
int ret, len, nargs = 0;
char **newargv;
exit(1);
}
- bdev = bdev_init(c->lxc_conf, c->lxc_conf->rootfs.path, c->lxc_conf->rootfs.mount, NULL);
+ bdev = storage_init(c->lxc_conf, c->lxc_conf->rootfs.path, c->lxc_conf->rootfs.mount, NULL);
if (!bdev) {
ERROR("Error opening rootfs");
exit(1);
}
if (pid == 0) { // child
- struct bdev *bdev = NULL;
+ struct lxc_storage *bdev = NULL;
- if (!(bdev = do_bdev_create(c, bdevtype, specs))) {
+ bdev = do_storage_create(c, bdevtype, specs);
+ if (!bdev) {
ERROR("Error creating backing store type %s for %s",
bdevtype ? bdevtype : "(none)", c->name);
- exit(1);
+ exit(EXIT_FAILURE);
}
/* save config file again to store the new rootfs location */
// parent task won't see bdev in config so we delete it
bdev->ops->umount(bdev);
bdev->ops->destroy(bdev);
- exit(1);
+ exit(EXIT_FAILURE);
}
- exit(0);
+ exit(EXIT_SUCCESS);
}
if (wait_for_pid(pid) != 0)
goto out_unlock;
static bool do_destroy_container(struct lxc_conf *conf) {
if (am_unpriv()) {
- if (userns_exec_1(conf, bdev_destroy_wrapper, conf,
- "bdev_destroy_wrapper") < 0)
+ if (userns_exec_1(conf, storage_destroy_wrapper, conf,
+ "storage_destroy_wrapper") < 0)
return false;
return true;
}
- return bdev_destroy(conf);
+ return storage_destroy(conf);
}
static int lxc_rmdir_onedev_wrapper(void *data)
const char *newtype, int flags, const char *bdevdata,
uint64_t newsize)
{
- struct bdev *bdev;
+ struct lxc_storage *bdev;
int need_rdep;
if (should_default_to_snapshot(c0, c))
flags |= LXC_CLONE_SNAPSHOT;
- bdev = bdev_copy(c0, c->name, c->config_path, newtype, flags, bdevdata,
- newsize, &need_rdep);
+ bdev = storage_copy(c0, c->name, c->config_path, newtype, flags,
+ bdevdata, newsize, &need_rdep);
if (!bdev) {
ERROR("Error copying storage.");
return -1;
/* Set new bdev type. */
free(c->lxc_conf->rootfs.bdev_type);
c->lxc_conf->rootfs.bdev_type = strdup(bdev->type);
- bdev_put(bdev);
+ storage_put(bdev);
if (!c->lxc_conf->rootfs.path) {
ERROR("Out of memory while setting storage path.");
char **hookargs = data->hookargs;
int ret = -1;
char path[MAXPATHLEN];
- struct bdev *bdev;
+ struct lxc_storage *bdev;
FILE *fout;
struct lxc_conf *conf = c->lxc_conf;
if (unshare(CLONE_NEWNS) < 0)
return -1;
- bdev = bdev_init(c->lxc_conf, c->lxc_conf->rootfs.path, c->lxc_conf->rootfs.mount, NULL);
+ bdev = storage_init(c->lxc_conf, c->lxc_conf->rootfs.path, c->lxc_conf->rootfs.mount, NULL);
if (!bdev)
return -1;
if (strcmp(bdev->type, "dir") != 0) {
if (unshare(CLONE_NEWNS) < 0) {
ERROR("error unsharing mounts");
- bdev_put(bdev);
+ storage_put(bdev);
return -1;
}
if (detect_shared_rootfs()) {
}
}
if (bdev->ops->mount(bdev) < 0) {
- bdev_put(bdev);
+ storage_put(bdev);
return -1;
}
} else { // TODO come up with a better way
if (run_lxc_hooks(c->name, "clone", conf, c->get_config_path(c), hookargs)) {
ERROR("Error executing clone hook for %s", c->name);
- bdev_put(bdev);
+ storage_put(bdev);
return -1;
}
}
if (!(flags & LXC_CLONE_KEEPNAME)) {
ret = snprintf(path, MAXPATHLEN, "%s/etc/hostname", bdev->dest);
- bdev_put(bdev);
+ storage_put(bdev);
if (ret < 0 || ret >= MAXPATHLEN)
return -1;
}
if (fclose(fout) < 0)
return -1;
+ } else {
+ storage_put(bdev);
}
- else
- bdev_put(bdev);
return 0;
}
static bool do_lxcapi_rename(struct lxc_container *c, const char *newname)
{
- struct bdev *bdev;
+ struct lxc_storage *bdev;
struct lxc_container *newc;
if (!c || !c->name || !c->config_path || !c->lxc_conf)
ERROR("Renaming a container with snapshots is not supported");
return false;
}
- bdev = bdev_init(c->lxc_conf, c->lxc_conf->rootfs.path, c->lxc_conf->rootfs.mount, NULL);
+ bdev = storage_init(c->lxc_conf, c->lxc_conf->rootfs.path, c->lxc_conf->rootfs.mount, NULL);
if (!bdev) {
ERROR("Failed to find original backing store type");
return false;
}
newc = lxcapi_clone(c, newname, c->config_path, LXC_CLONE_KEEPMACADDR, NULL, bdev->type, 0, NULL);
- bdev_put(bdev);
+ storage_put(bdev);
if (!newc) {
lxc_container_put(newc);
return false;
if (!c || !lxcapi_is_defined(c))
return -1;
- if (!bdev_can_backup(c->lxc_conf)) {
+ if (!storage_can_backup(c->lxc_conf)) {
ERROR("%s's backing store cannot be backed up.", c->name);
ERROR("Your container must use another backing store type.");
return -1;
*/
flags = LXC_CLONE_SNAPSHOT | LXC_CLONE_KEEPMACADDR | LXC_CLONE_KEEPNAME |
LXC_CLONE_KEEPBDEVTYPE | LXC_CLONE_MAYBE_SNAPSHOT;
- if (bdev_is_dir(c->lxc_conf, c->lxc_conf->rootfs.path)) {
+ if (storage_is_dir(c->lxc_conf, c->lxc_conf->rootfs.path)) {
ERROR("Snapshot of directory-backed container requested.");
ERROR("Making a copy-clone. If you do want snapshots, then");
ERROR("please create an aufs or overlayfs clone first, snapshot that");
char clonelxcpath[MAXPATHLEN];
int flags = 0;
struct lxc_container *snap, *rest;
- struct bdev *bdev;
+ struct lxc_storage *bdev;
bool b = false;
if (!c || !c->name || !c->config_path)
return false;
}
- bdev = bdev_init(c->lxc_conf, c->lxc_conf->rootfs.path, c->lxc_conf->rootfs.mount, NULL);
+ bdev = storage_init(c->lxc_conf, c->lxc_conf->rootfs.path, c->lxc_conf->rootfs.mount, NULL);
if (!bdev) {
ERROR("Failed to find original backing store type");
return false;
newname = c->name;
if (!get_snappath_dir(c, clonelxcpath)) {
- bdev_put(bdev);
+ storage_put(bdev);
return false;
}
// how should we lock this?
if (!snap || !lxcapi_is_defined(snap)) {
ERROR("Could not open snapshot %s", snapname);
if (snap) lxc_container_put(snap);
- bdev_put(bdev);
+ storage_put(bdev);
return false;
}
if (!container_destroy(c)) {
ERROR("Could not destroy existing container %s", newname);
lxc_container_put(snap);
- bdev_put(bdev);
+ storage_put(bdev);
return false;
}
}
flags = LXC_CLONE_SNAPSHOT | LXC_CLONE_MAYBE_SNAPSHOT;
rest = lxcapi_clone(snap, newname, c->config_path, flags,
bdev->type, NULL, 0, NULL);
- bdev_put(bdev);
+ storage_put(bdev);
if (rest && lxcapi_is_defined(rest))
b = true;
if (rest)
static bool do_destroy_container(struct lxc_conf *conf) {
if (am_unpriv()) {
- if (userns_exec_1(conf, bdev_destroy_wrapper, conf,
- "bdev_destroy_wrapper") < 0)
+ if (userns_exec_1(conf, storage_destroy_wrapper, conf,
+ "storage_destroy_wrapper") < 0)
return false;
+
return true;
}
- return bdev_destroy(conf);
+
+ return storage_destroy(conf);
}
#include "storage.h"
#include "utils.h"
-lxc_log_define(lxcaufs, lxc);
+lxc_log_define(aufs, lxc);
/* the bulk of this needs to become a common helper */
extern char *dir_new_path(char *src, const char *oldname, const char *name,
const char *oldpath, const char *lxcpath);
-int aufs_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
- const char *cname, const char *oldpath, const char *lxcpath,
- int snap, uint64_t newsize, struct lxc_conf *conf)
+int aufs_clonepaths(struct lxc_storage *orig, struct lxc_storage *new,
+ const char *oldname, const char *cname, const char *oldpath,
+ const char *lxcpath, int snap, uint64_t newsize,
+ struct lxc_conf *conf)
{
if (!snap) {
ERROR("aufs is only for snapshot clones");
* changes after starting the container are written to
* $lxcpath/$lxcname/delta0
*/
-int aufs_create(struct bdev *bdev, const char *dest, const char *n,
+int aufs_create(struct lxc_storage *bdev, const char *dest, const char *n,
struct bdev_specs *specs)
{
char *delta;
return 0;
}
-int aufs_destroy(struct bdev *orig)
+int aufs_destroy(struct lxc_storage *orig)
{
char *upper;
return 0;
}
-int aufs_mount(struct bdev *bdev)
+int aufs_mount(struct lxc_storage *bdev)
{
char *tmp, *options, *dup, *lower, *upper;
int len;
return ret;
}
-int aufs_umount(struct bdev *bdev)
+int aufs_umount(struct lxc_storage *bdev)
{
if (strcmp(bdev->type, "aufs"))
return -22;
#include <mntent.h>
#endif
-/* defined in bdev.h */
-struct bdev;
+struct lxc_storage;
-/* defined in lxccontainer.h */
struct bdev_specs;
-/* defined conf.h */
struct lxc_conf;
-/* defined in conf.h */
struct lxc_rootfs;
-/*
- * Functions associated with an aufs bdev struct.
- */
-int aufs_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
- const char *cname, const char *oldpath, const char *lxcpath,
- int snap, uint64_t newsize, struct lxc_conf *conf);
-int aufs_create(struct bdev *bdev, const char *dest, const char *n,
+int aufs_clonepaths(struct lxc_storage *orig, struct lxc_storage *new,
+ const char *oldname, const char *cname, const char *oldpath,
+ const char *lxcpath, int snap, uint64_t newsize,
+ struct lxc_conf *conf);
+int aufs_create(struct lxc_storage *bdev, const char *dest, const char *n,
struct bdev_specs *specs);
-int aufs_destroy(struct bdev *orig);
+int aufs_destroy(struct lxc_storage *orig);
int aufs_detect(const char *path);
-int aufs_mount(struct bdev *bdev);
-int aufs_umount(struct bdev *bdev);
+int aufs_mount(struct lxc_storage *bdev);
+int aufs_umount(struct lxc_storage *bdev);
-/*
- * Get rootfs path for aufs backed containers. Allocated memory must be freed
- * by caller.
+/* Get rootfs path for aufs backed containers. Allocated memory must be freed by
+ * caller.
*/
char *aufs_get_rootfs(const char *rootfs_path, size_t *rootfslen);
#include "storage.h"
#include "utils.h"
-lxc_log_define(lxcbtrfs, lxc);
+lxc_log_define(btrfs, lxc);
/* defined in lxccontainer.c: needs to become common helper */
extern char *dir_new_path(char *src, const char *oldname, const char *name,
return 0;
}
-int btrfs_mount(struct bdev *bdev)
+int btrfs_mount(struct lxc_storage *bdev)
{
unsigned long mntflags;
char *mntdata;
return ret;
}
-int btrfs_umount(struct bdev *bdev)
+int btrfs_umount(struct lxc_storage *bdev)
{
if (strcmp(bdev->type, "btrfs"))
return -22;
return ret;
}
-static int btrfs_snapshot_wrapper(void *data)
+int btrfs_snapshot_wrapper(void *data)
{
struct rsync_data_char *arg = data;
if (setgid(0) < 0) {
return btrfs_snapshot(arg->src, arg->dest);
}
-int btrfs_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
- const char *cname, const char *oldpath,
- const char *lxcpath, int snap, uint64_t newsize,
- struct lxc_conf *conf)
+int btrfs_clonepaths(struct lxc_storage *orig, struct lxc_storage *new,
+ const char *oldname, const char *cname,
+ const char *oldpath, const char *lxcpath, int snap,
+ uint64_t newsize, struct lxc_conf *conf)
{
if (!orig->dest || !orig->src)
return -1;
// in case rootfs is in custom path, reuse it
if ((new->src = dir_new_path(orig->src, oldname, cname, oldpath, lxcpath)) == NULL)
return -1;
-
}
if ((new->dest = strdup(new->src)) == NULL)
return btrfs_recursive_destroy(path) == 0;
}
-int btrfs_destroy(struct bdev *orig)
+int btrfs_destroy(struct lxc_storage *orig)
{
return btrfs_recursive_destroy(orig->src);
}
-int btrfs_create(struct bdev *bdev, const char *dest, const char *n,
+int btrfs_create(struct lxc_storage *bdev, const char *dest, const char *n,
struct bdev_specs *specs)
{
bdev->src = strdup(dest);
/* defined as btrfs_stack_root_ref_name_len */
BTRFS_SETGET_STACK_FUNCS(stack_root_ref_name_len, struct btrfs_root_ref, name_len, 16);
-/* defined in bdev.h */
-struct bdev;
+struct lxc_storage;
-/* defined in lxccontainer.h */
struct bdev_specs;
-/* defined conf.h */
struct lxc_conf;
struct mytree_node {
int num;
};
-/*
- * Functions associated with a btrfs bdev struct.
- */
-int btrfs_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
- const char *cname, const char *oldpath,
- const char *lxcpath, int snap, uint64_t newsize,
- struct lxc_conf *conf);
-int btrfs_create(struct bdev *bdev, const char *dest, const char *n,
- struct bdev_specs *specs);
-int btrfs_destroy(struct bdev *orig);
-int btrfs_detect(const char *path);
-int btrfs_mount(struct bdev *bdev);
-int btrfs_umount(struct bdev *bdev);
-
-/*
- * Helper functions
- */
-char *get_btrfs_subvol_path(int fd, u64 dir_id, u64 objid, char *name,
- int name_len);
-int btrfs_list_get_path_rootid(int fd, u64 *treeid);
-bool is_btrfs_fs(const char *path);
-int is_btrfs_subvol(const char *path);
-bool btrfs_try_remove_subvol(const char *path);
-int btrfs_same_fs(const char *orig, const char *new);
-int btrfs_snapshot(const char *orig, const char *new);
-
-#endif // __LXC_BTRFS_H
+extern int btrfs_clonepaths(struct lxc_storage *orig, struct lxc_storage *new,
+ const char *oldname, const char *cname,
+ const char *oldpath, const char *lxcpath, int snap,
+ uint64_t newsize, struct lxc_conf *conf);
+extern int btrfs_create(struct lxc_storage *bdev, const char *dest,
+ const char *n, struct bdev_specs *specs);
+extern int btrfs_destroy(struct lxc_storage *orig);
+extern int btrfs_detect(const char *path);
+extern int btrfs_mount(struct lxc_storage *bdev);
+extern int btrfs_umount(struct lxc_storage *bdev);
+
+extern char *get_btrfs_subvol_path(int fd, u64 dir_id, u64 objid, char *name,
+ int name_len);
+extern int btrfs_list_get_path_rootid(int fd, u64 *treeid);
+extern bool is_btrfs_fs(const char *path);
+extern int is_btrfs_subvol(const char *path);
+extern bool btrfs_try_remove_subvol(const char *path);
+extern int btrfs_same_fs(const char *orig, const char *new);
+extern int btrfs_snapshot(const char *orig, const char *new);
+extern int btrfs_snapshot_wrapper(void *data);
+extern bool btrfs_create_clone(struct lxc_conf *conf, struct lxc_storage *orig,
+ struct lxc_storage *new, uint64_t newsize);
+extern bool btrfs_create_snapshot(struct lxc_conf *conf,
+ struct lxc_storage *orig,
+ struct lxc_storage *new, uint64_t newsize);
+
+#endif /* __LXC_BTRFS_H */
#include "storage.h"
#include "utils.h"
-lxc_log_define(lxcdir, lxc);
+lxc_log_define(dir, lxc);
-/*
- * for a simple directory bind mount, we substitute the old container
- * name and paths for the new
+/* For a simple directory bind mount, we substitute the old container name and
+ * paths for the new.
*/
-int dir_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
- const char *cname, const char *oldpath, const char *lxcpath,
- int snap, uint64_t newsize, struct lxc_conf *conf)
+int dir_clonepaths(struct lxc_storage *orig, struct lxc_storage *new,
+ const char *oldname, const char *cname, const char *oldpath,
+ const char *lxcpath, int snap, uint64_t newsize,
+ struct lxc_conf *conf)
{
int len, ret;
return 0;
}
-int dir_create(struct bdev *bdev, const char *dest, const char *n,
- struct bdev_specs *specs)
+int dir_create(struct lxc_storage *bdev, const char *dest, const char *n,
+ struct bdev_specs *specs)
{
if (specs && specs->dir)
bdev->src = strdup(specs->dir);
return 0;
}
-int dir_destroy(struct bdev *orig)
+int dir_destroy(struct lxc_storage *orig)
{
if (lxc_rmdir_onedev(orig->src, NULL) < 0)
return -1;
return 0;
}
-int dir_mount(struct bdev *bdev)
+int dir_mount(struct lxc_storage *bdev)
{
unsigned long mntflags;
char *mntdata;
return ret;
}
-int dir_umount(struct bdev *bdev)
+int dir_umount(struct lxc_storage *bdev)
{
if (strcmp(bdev->type, "dir"))
return -22;
#define _GNU_SOURCE
#include <stdint.h>
-/* defined in bdev.h */
-struct bdev;
+struct lxc_storage;
-/* defined in lxccontainer.h */
struct bdev_specs;
-/* defined conf.h */
struct lxc_conf;
-/*
- * Functions associated with a dir bdev struct.
- */
-int dir_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
- const char *cname, const char *oldpath, const char *lxcpath,
- int snap, uint64_t newsize, struct lxc_conf *conf);
-int dir_create(struct bdev *bdev, const char *dest, const char *n,
- struct bdev_specs *specs);
-int dir_destroy(struct bdev *orig);
-int dir_detect(const char *path);
-int dir_mount(struct bdev *bdev);
-int dir_umount(struct bdev *bdev);
+extern int dir_clonepaths(struct lxc_storage *orig, struct lxc_storage *new,
+ const char *oldname, const char *cname,
+ const char *oldpath, const char *lxcpath, int snap,
+ uint64_t newsize, struct lxc_conf *conf);
+extern int dir_create(struct lxc_storage *bdev, const char *dest, const char *n,
+ struct bdev_specs *specs);
+extern int dir_destroy(struct lxc_storage *orig);
+extern int dir_detect(const char *path);
+extern int dir_mount(struct lxc_storage *bdev);
+extern int dir_umount(struct lxc_storage *bdev);
#endif /* __LXC_DIR_H */
#include "storage_utils.h"
#include "utils.h"
-lxc_log_define(lxcloop, lxc);
+lxc_log_define(loop, lxc);
static int do_loop_create(const char *path, uint64_t size, const char *fstype);
* No idea what the original blockdev will be called, but the copy will be
* called $lxcpath/$lxcname/rootdev
*/
-int loop_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
- const char *cname, const char *oldpath, const char *lxcpath,
- int snap, uint64_t newsize, struct lxc_conf *conf)
+int loop_clonepaths(struct lxc_storage *orig, struct lxc_storage *new,
+ const char *oldname, const char *cname, const char *oldpath,
+ const char *lxcpath, int snap, uint64_t newsize,
+ struct lxc_conf *conf)
{
char fstype[100];
uint64_t size = newsize;
return do_loop_create(srcdev, size, fstype);
}
-int loop_create(struct bdev *bdev, const char *dest, const char *n,
+int loop_create(struct lxc_storage *bdev, const char *dest, const char *n,
struct bdev_specs *specs)
{
const char *fstype;
return do_loop_create(srcdev, sz, fstype);
}
-int loop_destroy(struct bdev *orig)
-{
+int loop_destroy(struct lxc_storage *orig) {
return unlink(orig->src + 5);
}
return 0;
}
-int loop_mount(struct bdev *bdev)
+int loop_mount(struct lxc_storage *bdev)
{
int ret, loopfd;
char loname[MAXPATHLEN];
return ret;
}
-int loop_umount(struct bdev *bdev)
+int loop_umount(struct lxc_storage *bdev)
{
int ret;
#define _GNU_SOURCE
#include <stdint.h>
-/* defined in bdev.h */
-struct bdev;
+struct lxc_storage;
-/* defined in lxccontainer.h */
struct bdev_specs;
-/* defined conf.h */
struct lxc_conf;
-/*
- * functions associated with a loop bdev struct
- */
-int loop_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
- const char *cname, const char *oldpath, const char *lxcpath,
- int snap, uint64_t newsize, struct lxc_conf *conf);
-int loop_create(struct bdev *bdev, const char *dest, const char *n,
- struct bdev_specs *specs);
-int loop_destroy(struct bdev *orig);
-int loop_detect(const char *path);
-int loop_mount(struct bdev *bdev);
-int loop_umount(struct bdev *bdev);
+extern int loop_clonepaths(struct lxc_storage *orig, struct lxc_storage *new,
+ const char *oldname, const char *cname,
+ const char *oldpath, const char *lxcpath, int snap,
+ uint64_t newsize, struct lxc_conf *conf);
+extern int loop_create(struct lxc_storage *bdev, const char *dest,
+ const char *n, struct bdev_specs *specs);
+extern int loop_destroy(struct lxc_storage *orig);
+extern int loop_detect(const char *path);
+extern int loop_mount(struct lxc_storage *bdev);
+extern int loop_umount(struct lxc_storage *bdev);
#endif /* __LXC_LOOP_H */
# include <sys/mkdev.h>
#endif
-lxc_log_define(lxclvm, lxc);
+lxc_log_define(lvm, lxc);
extern char *dir_new_path(char *src, const char *oldname, const char *name,
const char *oldpath, const char *lxcpath);
return 1;
}
-int lvm_mount(struct bdev *bdev)
+int lvm_mount(struct lxc_storage *bdev)
{
if (strcmp(bdev->type, "lvm"))
return -22;
return mount_unknown_fs(bdev->src, bdev->dest, bdev->mntopts);
}
-int lvm_umount(struct bdev *bdev)
+int lvm_umount(struct lxc_storage *bdev)
{
if (strcmp(bdev->type, "lvm"))
return -22;
exit(EXIT_FAILURE);
}
-int lvm_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
- const char *cname, const char *oldpath, const char *lxcpath, int snap,
- uint64_t newsize, struct lxc_conf *conf)
+int lvm_clonepaths(struct lxc_storage *orig, struct lxc_storage *new,
+ const char *oldname, const char *cname, const char *oldpath,
+ const char *lxcpath, int snap, uint64_t newsize,
+ struct lxc_conf *conf)
{
char fstype[100];
uint64_t size = newsize;
return 0;
}
-int lvm_destroy(struct bdev *orig)
+int lvm_destroy(struct lxc_storage *orig)
{
pid_t pid;
return wait_for_pid(pid);
}
-int lvm_create(struct bdev *bdev, const char *dest, const char *n,
- struct bdev_specs *specs)
+int lvm_create(struct lxc_storage *bdev, const char *dest, const char *n,
+ struct bdev_specs *specs)
{
const char *vg, *thinpool, *fstype, *lv = n;
uint64_t sz;
#define _GNU_SOURCE
#include <stdint.h>
-/* defined in bdev.h */
-struct bdev;
+struct lxc_storage;
-/* defined in lxccontainer.h */
struct bdev_specs;
-/* defined conf.h */
struct lxc_conf;
-/*
- * Functions associated with an lvm bdev struct.
- */
-int lvm_detect(const char *path);
-int lvm_mount(struct bdev *bdev);
-int lvm_umount(struct bdev *bdev);
-int lvm_compare_lv_attr(const char *path, int pos, const char expected);
-int lvm_is_thin_volume(const char *path);
-int lvm_is_thin_pool(const char *path);
-int lvm_snapshot(const char *orig, const char *path, uint64_t size);
-int lvm_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
- const char *cname, const char *oldpath, const char *lxcpath, int snap,
- uint64_t newsize, struct lxc_conf *conf);
-int lvm_destroy(struct bdev *orig);
-int lvm_create(struct bdev *bdev, const char *dest, const char *n,
- struct bdev_specs *specs);
+extern int lvm_detect(const char *path);
+extern int lvm_mount(struct lxc_storage *bdev);
+extern int lvm_umount(struct lxc_storage *bdev);
+extern int lvm_compare_lv_attr(const char *path, int pos, const char expected);
+extern int lvm_is_thin_volume(const char *path);
+extern int lvm_is_thin_pool(const char *path);
+extern int lvm_snapshot(const char *orig, const char *path, uint64_t size);
+extern int lvm_clonepaths(struct lxc_storage *orig, struct lxc_storage *new,
+ const char *oldname, const char *cname,
+ const char *oldpath, const char *lxcpath, int snap,
+ uint64_t newsize, struct lxc_conf *conf);
+extern int lvm_destroy(struct lxc_storage *orig);
+extern int lvm_create(struct lxc_storage *bdev, const char *dest, const char *n,
+ struct bdev_specs *specs);
+extern bool lvm_create_clone(struct lxc_conf *conf, struct lxc_storage *orig,
+ struct lxc_storage *new, uint64_t newsize);
+extern bool lvm_create_snapshot(struct lxc_conf *conf, struct lxc_storage *orig,
+ struct lxc_storage *new, uint64_t newsize);
#endif /* __LXC_LVM_H */
#include "storage_utils.h"
#include "utils.h"
-lxc_log_define(lxcnbd, lxc);
+lxc_log_define(nbd, lxc);
struct nbd_attach_data {
const char *nbd;
nbd_detach(path);
}
-int nbd_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
- const char *cname, const char *oldpath, const char *lxcpath,
- int snap, uint64_t newsize, struct lxc_conf *conf)
+int nbd_clonepaths(struct lxc_storage *orig, struct lxc_storage *new,
+ const char *oldname, const char *cname, const char *oldpath,
+ const char *lxcpath, int snap, uint64_t newsize,
+ struct lxc_conf *conf)
{
return -ENOSYS;
}
-int nbd_create(struct bdev *bdev, const char *dest, const char *n,
- struct bdev_specs *specs)
+int nbd_create(struct lxc_storage *bdev, const char *dest, const char *n,
+ struct bdev_specs *specs)
{
return -ENOSYS;
}
-int nbd_destroy(struct bdev *orig)
+int nbd_destroy(struct lxc_storage *orig)
{
return -ENOSYS;
}
return 0;
}
-int nbd_mount(struct bdev *bdev)
+int nbd_mount(struct lxc_storage *bdev)
{
int ret = -1, partition;
char path[50];
return ret;
}
-int nbd_umount(struct bdev *bdev)
+int nbd_umount(struct lxc_storage *bdev)
{
int ret;
#include <stdbool.h>
#include <stdint.h>
-/* defined in bdev.h */
-struct bdev;
+struct lxc_storage;
-/* defined in lxccontainer.h */
struct bdev_specs;
-/* defined conf.h */
struct lxc_conf;
-/*
- * Functions associated with an nbd bdev struct.
- */
-int nbd_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
- const char *cname, const char *oldpath, const char *lxcpath,
- int snap, uint64_t newsize, struct lxc_conf *conf);
-int nbd_create(struct bdev *bdev, const char *dest, const char *n,
- struct bdev_specs *specs);
-int nbd_destroy(struct bdev *orig);
-int nbd_detect(const char *path);
-int nbd_mount(struct bdev *bdev);
-int nbd_umount(struct bdev *bdev);
-
-/* helpers */
-bool attach_nbd(char *src, struct lxc_conf *conf);
-void detach_nbd_idx(int idx);
-bool requires_nbd(const char *path);
+extern int nbd_clonepaths(struct lxc_storage *orig, struct lxc_storage *new,
+ const char *oldname, const char *cname,
+ const char *oldpath, const char *lxcpath, int snap,
+ uint64_t newsize, struct lxc_conf *conf);
+extern int nbd_create(struct lxc_storage *bdev, const char *dest, const char *n,
+ struct bdev_specs *specs);
+extern int nbd_destroy(struct lxc_storage *orig);
+extern int nbd_detect(const char *path);
+extern int nbd_mount(struct lxc_storage *bdev);
+extern int nbd_umount(struct lxc_storage *bdev);
+
+extern bool attach_nbd(char *src, struct lxc_conf *conf);
+extern void detach_nbd_idx(int idx);
+extern bool requires_nbd(const char *path);
#endif /* __LXC_NBD_H */
#include "storage_utils.h"
#include "utils.h"
-lxc_log_define(lxcoverlay, lxc);
+lxc_log_define(overlay, lxc);
static char *ovl_name;
static char *ovl_version[] = {"overlay", "overlayfs"};
const char *oldpath, const char *lxcpath);
static char *ovl_detect_name(void);
-static int ovl_do_rsync(struct bdev *orig, struct bdev *new,
+static int ovl_do_rsync(struct lxc_storage *orig, struct lxc_storage *new,
struct lxc_conf *conf);
static int ovl_rsync(struct rsync_data *data);
static int ovl_rsync_wrapper(void *data);
const char *name, unsigned long mountflags,
const void *options);
-int ovl_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
+int ovl_clonepaths(struct lxc_storage *orig, struct lxc_storage *new, const char *oldname,
const char *cname, const char *oldpath, const char *lxcpath,
int snap, uint64_t newsize, struct lxc_conf *conf)
{
* changes after starting the container are written to
* $lxcpath/$lxcname/delta0
*/
-int ovl_create(struct bdev *bdev, const char *dest, const char *n,
- struct bdev_specs *specs)
+int ovl_create(struct lxc_storage *bdev, const char *dest, const char *n,
+ struct bdev_specs *specs)
{
char *delta;
int ret, len = strlen(dest), newlen;
return 0;
}
-int ovl_destroy(struct bdev *orig)
+int ovl_destroy(struct lxc_storage *orig)
{
char *upper;
return p;
}
-int ovl_mount(struct bdev *bdev)
+int ovl_mount(struct lxc_storage *bdev)
{
char *tmp, *options, *dup, *lower, *upper;
char *options_work, *work, *lastslash;
return ret;
}
-int ovl_umount(struct bdev *bdev)
+int ovl_umount(struct lxc_storage *bdev)
{
if (strcmp(bdev->type, "overlayfs"))
return -22;
return v;
}
-static int ovl_do_rsync(struct bdev *orig, struct bdev *new, struct lxc_conf *conf)
+static int ovl_do_rsync(struct lxc_storage *orig, struct lxc_storage *new,
+ struct lxc_conf *conf)
{
int ret = -1;
struct rsync_data rdata;
#include <mntent.h>
#endif
-/* defined in bdev.h */
-struct bdev;
+struct lxc_storage;
-/* defined in lxccontainer.h */
struct bdev_specs;
-/* defined conf.h */
struct lxc_conf;
-/* defined in conf.h */
struct lxc_rootfs;
-/*
- * Functions associated with an overlay bdev struct.
- */
-int ovl_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
- const char *cname, const char *oldpath, const char *lxcpath,
- int snap, uint64_t newsize, struct lxc_conf *conf);
-int ovl_create(struct bdev *bdev, const char *dest, const char *n,
- struct bdev_specs *specs);
-int ovl_destroy(struct bdev *orig);
-int ovl_detect(const char *path);
-int ovl_mount(struct bdev *bdev);
-int ovl_umount(struct bdev *bdev);
+extern int ovl_clonepaths(struct lxc_storage *orig, struct lxc_storage *new,
+ const char *oldname, const char *cname,
+ const char *oldpath, const char *lxcpath, int snap,
+ uint64_t newsize, struct lxc_conf *conf);
+extern int ovl_create(struct lxc_storage *bdev, const char *dest, const char *n,
+ struct bdev_specs *specs);
+extern int ovl_destroy(struct lxc_storage *orig);
+extern int ovl_detect(const char *path);
+extern int ovl_mount(struct lxc_storage *bdev);
+extern int ovl_umount(struct lxc_storage *bdev);
-/*
- * To be called from lxcapi_clone() in lxccontainer.c: When we clone a container
+/* To be called from lxcapi_clone() in lxccontainer.c: When we clone a container
* with overlay lxc.mount.entry entries we need to update absolute paths for
* upper- and workdir. This update is done in two locations:
* lxc_conf->unexpanded_config and lxc_conf->mount_list. Both updates are done
* independent of each other since lxc_conf->mountlist may container more mount
* entries (e.g. from other included files) than lxc_conf->unexpanded_config .
*/
-int ovl_update_abs_paths(struct lxc_conf *lxc_conf, const char *lxc_path,
- const char *lxc_name, const char *newpath,
- const char *newname);
+extern int ovl_update_abs_paths(struct lxc_conf *lxc_conf, const char *lxc_path,
+ const char *lxc_name, const char *newpath,
+ const char *newname);
-/*
- * To be called from functions in lxccontainer.c: Get lower directory for
+/* To be called from functions in lxccontainer.c: Get lower directory for
* overlay rootfs.
*/
-char *ovl_getlower(char *p);
+extern char *ovl_get_lower(const char *rootfs_path);
-/*
- * Get rootfs path for overlay backed containers. Allocated memory must be freed
+/* Get rootfs path for overlay backed containers. Allocated memory must be freed
* by caller.
*/
-char *ovl_get_rootfs(const char *rootfs_path, size_t *rootfslen);
+extern char *ovl_get_rootfs(const char *rootfs_path, size_t *rootfslen);
-/*
- * Create upper- and workdirs for overlay mounts.
+/* Create upper- and workdirs for overlay mounts.
*/
-int ovl_mkdir(const struct mntent *mntent, const struct lxc_rootfs *rootfs,
- const char *lxc_name, const char *lxc_path);
+extern int ovl_mkdir(const struct mntent *mntent,
+ const struct lxc_rootfs *rootfs, const char *lxc_name,
+ const char *lxc_path);
#endif /* __LXC_OVERLAY_H */
#include "storage_utils.h"
#include "utils.h"
-lxc_log_define(lxcrbd, lxc);
+lxc_log_define(rbd, lxc);
-int rbd_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
+int rbd_clonepaths(struct lxc_storage *orig, struct lxc_storage *new, const char *oldname,
const char *cname, const char *oldpath, const char *lxcpath,
int snap, uint64_t newsize, struct lxc_conf *conf)
{
return -1;
}
-int rbd_create(struct bdev *bdev, const char *dest, const char *n,
- struct bdev_specs *specs)
+int rbd_create(struct lxc_storage *bdev, const char *dest, const char *n,
+ struct bdev_specs *specs)
{
const char *rbdpool, *rbdname = n, *fstype;
uint64_t size;
return 0;
}
-int rbd_destroy(struct bdev *orig)
+int rbd_destroy(struct lxc_storage *orig)
{
pid_t pid;
char *rbdfullname;
return 0;
}
-int rbd_mount(struct bdev *bdev)
+int rbd_mount(struct lxc_storage *bdev)
{
if (strcmp(bdev->type, "rbd"))
return -22;
return mount_unknown_fs(bdev->src, bdev->dest, bdev->mntopts);
}
-int rbd_umount(struct bdev *bdev)
+int rbd_umount(struct lxc_storage *bdev)
{
if (strcmp(bdev->type, "rbd"))
return -22;
#define _GNU_SOURCE
#include <stdint.h>
-/* defined in bdev.h */
-struct bdev;
+struct lxc_storage;
-/* defined in lxccontainer.h */
struct bdev_specs;
-/* defined conf.h */
struct lxc_conf;
-/*
- * Functions associated with an rdb bdev struct.
- */
-int rbd_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
- const char *cname, const char *oldpath, const char *lxcpath,
- int snap, uint64_t newsize, struct lxc_conf *conf);
-int rbd_create(struct bdev *bdev, const char *dest, const char *n,
- struct bdev_specs *specs);
-int rbd_destroy(struct bdev *orig);
-int rbd_detect(const char *path);
-int rbd_mount(struct bdev *bdev);
-int rbd_umount(struct bdev *bdev);
+extern int rbd_clonepaths(struct lxc_storage *orig, struct lxc_storage *new,
+ const char *oldname, const char *cname,
+ const char *oldpath, const char *lxcpath, int snap,
+ uint64_t newsize, struct lxc_conf *conf);
+extern int rbd_create(struct lxc_storage *bdev, const char *dest, const char *n,
+ struct bdev_specs *specs);
+extern int rbd_destroy(struct lxc_storage *orig);
+extern int rbd_detect(const char *path);
+extern int rbd_mount(struct lxc_storage *bdev);
+extern int rbd_umount(struct lxc_storage *bdev);
#endif /* __LXC_RDB_H */
#include "storage.h"
#include "utils.h"
-lxc_log_define(lxcrsync, lxc);
+lxc_log_define(rsync, lxc);
/* the bulk of this needs to become a common helper */
int do_rsync(const char *src, const char *dest)
int rsync_rootfs(struct rsync_data *data)
{
- struct bdev *orig = data->orig,
- *new = data->new;
+ struct lxc_storage *orig = data->orig, *new = data->new;
if (unshare(CLONE_NEWNS) < 0) {
SYSERROR("unshare CLONE_NEWNS");
struct rsync_data *arg = data;
return rsync_rootfs(arg);
}
-
#include <stdio.h>
struct rsync_data {
- struct bdev *orig;
- struct bdev *new;
+ struct lxc_storage *orig;
+ struct lxc_storage *new;
};
struct rsync_data_char {
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-/*
- * this is all just a first shot for experiment. If we go this route, much
- * should change. bdev should be a directory with per-bdev file. Things which
- * I'm doing by calling out to userspace should sometimes be done through
- * libraries like liblvm2
- */
-
#define _GNU_SOURCE
#include <dirent.h>
#include <errno.h>
lxc_log_define(storage, lxc);
/* aufs */
-static const struct bdev_ops aufs_ops = {
+static const struct lxc_storage_ops aufs_ops = {
.detect = &aufs_detect,
.mount = &aufs_mount,
.umount = &aufs_umount,
};
/* btrfs */
-static const struct bdev_ops btrfs_ops = {
+static const struct lxc_storage_ops btrfs_ops = {
.detect = &btrfs_detect,
.mount = &btrfs_mount,
.umount = &btrfs_umount,
};
/* dir */
-static const struct bdev_ops dir_ops = {
+static const struct lxc_storage_ops dir_ops = {
.detect = &dir_detect,
.mount = &dir_mount,
.umount = &dir_umount,
};
/* loop */
-static const struct bdev_ops loop_ops = {
+static const struct lxc_storage_ops loop_ops = {
.detect = &loop_detect,
.mount = &loop_mount,
.umount = &loop_umount,
};
/* lvm */
-static const struct bdev_ops lvm_ops = {
+static const struct lxc_storage_ops lvm_ops = {
.detect = &lvm_detect,
.mount = &lvm_mount,
.umount = &lvm_umount,
};
/* nbd */
-const struct bdev_ops nbd_ops = {
+const struct lxc_storage_ops nbd_ops = {
.detect = &nbd_detect,
.mount = &nbd_mount,
.umount = &nbd_umount,
};
/* overlay */
-static const struct bdev_ops ovl_ops = {
+static const struct lxc_storage_ops ovl_ops = {
.detect = &ovl_detect,
.mount = &ovl_mount,
.umount = &ovl_umount,
};
/* rbd */
-static const struct bdev_ops rbd_ops = {
+static const struct lxc_storage_ops rbd_ops = {
.detect = &rbd_detect,
.mount = &rbd_mount,
.umount = &rbd_umount,
};
/* zfs */
-static const struct bdev_ops zfs_ops = {
+static const struct lxc_storage_ops zfs_ops = {
.detect = &zfs_detect,
.mount = &zfs_mount,
.umount = &zfs_umount,
.can_backup = true,
};
-struct bdev_type {
+struct lxc_storage_type {
const char *name;
- const struct bdev_ops *ops;
+ const struct lxc_storage_ops *ops;
};
-static const struct bdev_type bdevs[] = {
+static const struct lxc_storage_type bdevs[] = {
{ .name = "zfs", .ops = &zfs_ops, },
{ .name = "lvm", .ops = &lvm_ops, },
{ .name = "rbd", .ops = &rbd_ops, },
{ .name = "nbd", .ops = &nbd_ops, },
};
-static const size_t numbdevs = sizeof(bdevs) / sizeof(struct bdev_type);
+static const size_t numbdevs = sizeof(bdevs) / sizeof(struct lxc_storage_type);
-static const struct bdev_type *get_bdev_by_name(const char *name)
+static const struct lxc_storage_type *get_storage_by_name(const char *name)
{
size_t i, cmplen;
return &bdevs[i];
}
-const struct bdev_type *bdev_query(struct lxc_conf *conf, const char *src)
+const struct lxc_storage_type *storage_query(struct lxc_conf *conf,
+ const char *src)
{
size_t i;
- const struct bdev_type *bdev;
+ const struct lxc_storage_type *bdev;
- bdev = get_bdev_by_name(src);
+ bdev = get_storage_by_name(src);
if (bdev)
return bdev;
return &bdevs[i];
}
-struct bdev *bdev_get(const char *type)
+struct lxc_storage *storage_get(const char *type)
{
size_t i;
- struct bdev *bdev;
+ struct lxc_storage *bdev;
for (i = 0; i < numbdevs; i++) {
if (strcmp(bdevs[i].name, type) == 0)
if (i == numbdevs)
return NULL;
- bdev = malloc(sizeof(struct bdev));
+ bdev = malloc(sizeof(struct lxc_storage));
if (!bdev)
return NULL;
- memset(bdev, 0, sizeof(struct bdev));
+ memset(bdev, 0, sizeof(struct lxc_storage));
bdev->ops = bdevs[i].ops;
bdev->type = bdevs[i].name;
return bdev;
}
-static struct bdev *do_bdev_create(const char *dest, const char *type,
- const char *cname, struct bdev_specs *specs)
+static struct lxc_storage *do_storage_create(const char *dest, const char *type,
+ const char *cname,
+ struct bdev_specs *specs)
{
- struct bdev *bdev;
+ struct lxc_storage *bdev;
if (!type)
type = "dir";
- bdev = bdev_get(type);
+ bdev = storage_get(type);
if (!bdev)
return NULL;
if (bdev->ops->create(bdev, dest, cname, specs) < 0) {
- bdev_put(bdev);
+ storage_put(bdev);
return NULL;
}
return bdev;
}
-bool bdev_can_backup(struct lxc_conf *conf)
+bool storage_can_backup(struct lxc_conf *conf)
{
- struct bdev *bdev = bdev_init(conf, NULL, NULL, NULL);
+ struct lxc_storage *bdev = storage_init(conf, NULL, NULL, NULL);
bool ret;
if (!bdev)
return false;
ret = bdev->ops->can_backup;
- bdev_put(bdev);
+ storage_put(bdev);
return ret;
}
-/*
- * If we're not snaphotting, then bdev_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.
*/
-struct bdev *bdev_copy(struct lxc_container *c0, const char *cname,
- const char *lxcpath, const char *bdevtype, int flags,
- const char *bdevdata, uint64_t newsize, int *needs_rdep)
+struct lxc_storage *storage_copy(struct lxc_container *c0, const char *cname,
+ const char *lxcpath, const char *bdevtype,
+ int flags, const char *bdevdata,
+ uint64_t newsize, int *needs_rdep)
{
- struct bdev *orig, *new;
+ struct lxc_storage *orig, *new;
pid_t pid;
int ret;
bool snap = flags & LXC_CLONE_SNAPSHOT;
return NULL;
}
- orig = bdev_init(c0->lxc_conf, src, NULL, NULL);
+ orig = storage_init(c0->lxc_conf, src, NULL, NULL);
if (!orig) {
ERROR("failed to detect blockdev type for %s", src);
return NULL;
len = strlen(oldpath) + strlen(oldname) + strlen("/rootfs") + 2;
orig->dest = malloc(len);
if (!orig->dest) {
- ERROR("out of memory");
- bdev_put(orig);
+ ERROR("Failed to allocate memory");
+ storage_put(orig);
return NULL;
}
ret = snprintf(orig->dest, len, "%s/%s/rootfs", oldpath, oldname);
if (ret < 0 || (size_t)ret >= len) {
- ERROR("rootfs path too long");
- bdev_put(orig);
+ ERROR("Failed to create string");
+ storage_put(orig);
return NULL;
}
ret = stat(orig->dest, &sb);
bdevtype = "overlayfs";
if (am_unpriv() && !unpriv_snap_allowed(orig, bdevtype, snap, maybe_snap)) {
- ERROR("Unsupported snapshot type for unprivileged users");
- bdev_put(orig);
+ ERROR("Unsupported snapshot type \"%s\" for unprivileged users",
+ bdevtype ? bdevtype : "(null)");
+ storage_put(orig);
return NULL;
}
else if (!bdevtype)
bdevtype = orig->type;
- new = bdev_get(bdevtype);
+ /* get new bdev type */
+ new = storage_get(bdevtype);
if (!new) {
ERROR("no such block device type: %s",
bdevtype ? bdevtype : orig->type);
- bdev_put(orig);
+ storage_put(orig);
return NULL;
}
new->dest);
goto err;
}
- bdev_put(orig);
+ storage_put(orig);
return new;
}
if (pid > 0) {
int ret = wait_for_pid(pid);
- bdev_put(orig);
+ storage_put(orig);
if (ret < 0) {
- bdev_put(new);
+ storage_put(new);
return NULL;
}
return new;
exit(ret == 0 ? 0 : 1);
err:
- bdev_put(orig);
- bdev_put(new);
+ storage_put(orig);
+ storage_put(new);
return NULL;
}
-/*
- * bdev_create:
- * Create a backing store for a container.
+/* Create a backing store for a container.
* If successful, return a struct bdev *, with the bdev mounted and ready
* for use. Before completing, the caller will need to call the
- * umount operation and bdev_put().
+ * umount operation and storage_put().
* @dest: the mountpoint (i.e. /var/lib/lxc/$name/rootfs)
* @type: the bdevtype (dir, btrfs, zfs, rbd, etc)
* @cname: the container name
* @specs: details about the backing store to create, like fstype
*/
-struct bdev *bdev_create(const char *dest, const char *type, const char *cname,
- struct bdev_specs *specs)
+struct lxc_storage *storage_create(const char *dest, const char *type,
+ const char *cname, struct bdev_specs *specs)
{
- struct bdev *bdev;
+ struct lxc_storage *bdev;
char *best_options[] = {"btrfs", "zfs", "lvm", "dir", "rbd", NULL};
if (!type)
- return do_bdev_create(dest, "dir", cname, specs);
+ return do_storage_create(dest, "dir", cname, specs);
if (strcmp(type, "best") == 0) {
int i;
- // try for the best backing store type, according to our
- // opinionated preferences
+ /* Try for the best backing store type, according to our
+ * opinionated preferences.
+ */
for (i = 0; best_options[i]; i++) {
- if ((bdev = do_bdev_create(dest, best_options[i], cname,
- specs)))
+ bdev = do_storage_create(dest, best_options[i], cname,
+ specs);
+ if (bdev)
return bdev;
}
- return NULL; // 'dir' should never fail, so this shouldn't
- // happen
+ return NULL;
}
- // -B lvm,dir
+ /* -B lvm,dir */
if (strchr(type, ',') != NULL) {
char *dup = alloca(strlen(type) + 1), *saveptr = NULL, *token;
strcpy(dup, type);
for (token = strtok_r(dup, ",", &saveptr); token;
token = strtok_r(NULL, ",", &saveptr)) {
- if ((bdev = do_bdev_create(dest, token, cname, specs)))
+ if ((bdev = do_storage_create(dest, token, cname, specs)))
return bdev;
}
}
- return do_bdev_create(dest, type, cname, specs);
+ return do_storage_create(dest, type, cname, specs);
}
-bool bdev_destroy(struct lxc_conf *conf)
+bool storage_destroy(struct lxc_conf *conf)
{
- struct bdev *r;
+ struct lxc_storage *r;
bool ret = false;
- r = bdev_init(conf, conf->rootfs.path, conf->rootfs.mount, NULL);
+ r = storage_init(conf, conf->rootfs.path, conf->rootfs.mount, NULL);
if (!r)
return ret;
if (r->ops->destroy(r) == 0)
ret = true;
- bdev_put(r);
+ storage_put(r);
return ret;
}
-struct bdev *bdev_init(struct lxc_conf *conf, const char *src, const char *dst,
- const char *mntopts)
+struct lxc_storage *storage_init(struct lxc_conf *conf, const char *src,
+ const char *dst, const char *mntopts)
{
- struct bdev *bdev;
- const struct bdev_type *q;
+ struct lxc_storage *bdev;
+ const struct lxc_storage_type *q;
if (!src)
src = conf->rootfs.path;
if (!src)
return NULL;
- q = bdev_query(conf, src);
+ q = storage_query(conf, src);
if (!q)
return NULL;
- bdev = malloc(sizeof(struct bdev));
+ bdev = malloc(sizeof(struct lxc_storage));
if (!bdev)
return NULL;
- memset(bdev, 0, sizeof(struct bdev));
+ memset(bdev, 0, sizeof(struct lxc_storage));
bdev->ops = q->ops;
bdev->type = q->name;
if (mntopts)
return bdev;
}
-bool bdev_is_dir(struct lxc_conf *conf, const char *path)
+bool storage_is_dir(struct lxc_conf *conf, const char *path)
{
- struct bdev *orig = bdev_init(conf, path, NULL, NULL);
- bool ret = false;
+ struct lxc_storage *orig;
+ bool bret = false;
+
+ orig = storage_init(conf, path, NULL, NULL);
if (!orig)
- return ret;
+ return bret;
+
if (strcmp(orig->type, "dir") == 0)
- ret = true;
- bdev_put(orig);
- return ret;
+ bret = true;
+
+ storage_put(orig);
+ return bret;
}
-void bdev_put(struct bdev *bdev)
+void storage_put(struct lxc_storage *bdev)
{
free(bdev->mntopts);
free(bdev->src);
bool rootfs_is_blockdev(struct lxc_conf *conf)
{
- const struct bdev_type *q;
+ const struct lxc_storage_type *q;
struct stat st;
int ret;
if (ret == 0 && S_ISBLK(st.st_mode))
return true;
- q = bdev_query(conf, conf->rootfs.path);
+ q = storage_query(conf, conf->rootfs.path);
if (!q)
return false;
#define DEFAULT_FS_SIZE 1073741824
#define DEFAULT_FSTYPE "ext3"
-struct bdev;
+struct lxc_storage;
-struct bdev_ops {
+struct lxc_storage_ops {
/* detect whether path is of this bdev type */
int (*detect)(const char *path);
// mount requires src and dest to be set.
- int (*mount)(struct bdev *bdev);
- int (*umount)(struct bdev *bdev);
- int (*destroy)(struct bdev *bdev);
- int (*create)(struct bdev *bdev, const char *dest, const char *n,
+ int (*mount)(struct lxc_storage *bdev);
+ int (*umount)(struct lxc_storage *bdev);
+ int (*destroy)(struct lxc_storage *bdev);
+ int (*create)(struct lxc_storage *bdev, const char *dest, const char *n,
struct bdev_specs *specs);
/* given original mount, rename the paths for cloned container */
- int (*clone_paths)(struct bdev *orig, struct bdev *new,
+ int (*clone_paths)(struct lxc_storage *orig, struct lxc_storage *new,
const char *oldname, const char *cname,
const char *oldpath, const char *lxcpath, int snap,
uint64_t newsize, struct lxc_conf *conf);
bool can_backup;
};
-/*
- * When lxc-start is mounting a rootfs, then src will be the "lxc.rootfs" value,
- * dest will be mount dir (i.e. $libdir/lxc) When clone or create is doing so,
- * then dest will be $lxcpath/$lxcname/rootfs, since we may need to rsync from
- * one to the other.
- * data is so far unused.
+/* When lxc is mounting a rootfs, then src will be the "lxc.rootfs.path" value,
+ * dest will be the mount dir (i.e. "<libdir>/lxc") When clone or create is
+ * doing so, then dest will be "<lxcpath>/<lxcname>/rootfs", since we may need
+ * to rsync from one to the other.
*/
-struct bdev {
- const struct bdev_ops *ops;
+struct lxc_storage {
+ const struct lxc_storage_ops *ops;
const char *type;
char *src;
char *dest;
int nbd_idx;
};
-bool bdev_is_dir(struct lxc_conf *conf, const char *path);
-bool bdev_can_backup(struct lxc_conf *conf);
+extern bool storage_is_dir(struct lxc_conf *conf, const char *path);
+extern bool storage_can_backup(struct lxc_conf *conf);
-/*
- * Instantiate a bdev object. The src is used to determine which blockdev type
- * this should be. The dst and data are optional, and will be used in case of
- * mount/umount.
+/* Instantiate a lxc_storage object. The src is used to determine which blockdev
+ * type this should be. The dst and data are optional, and will be used in case
+ * of mount/umount.
*
- * Optionally, src can be 'dir:/var/lib/lxc/c1' or 'lvm:/dev/lxc/c1'. For
- * other backing stores, this will allow additional options. In particular,
- * "overlayfs:/var/lib/lxc/canonical/rootfs:/var/lib/lxc/c1/delta" will mean
- * use /var/lib/lxc/canonical/rootfs as lower dir, and /var/lib/lxc/c1/delta
- * as the upper, writeable layer.
+ * The source will be "dir:/var/lib/lxc/c1" or "lvm:/dev/lxc/c1". For other
+ * backing stores, this will allow additional options. In particular,
+ * "overlayfs:/var/lib/lxc/canonical/rootfs:/var/lib/lxc/c1/delta" will mean use
+ * /var/lib/lxc/canonical/rootfs as lower dir, and /var/lib/lxc/c1/delta as the
+ * upper, writeable layer.
*/
-struct bdev *bdev_init(struct lxc_conf *conf, const char *src, const char *dst,
- const char *data);
-
-struct bdev *bdev_copy(struct lxc_container *c0, const char *cname,
- const char *lxcpath, const char *bdevtype, int flags,
- const char *bdevdata, uint64_t newsize, int *needs_rdep);
-struct bdev *bdev_create(const char *dest, const char *type, const char *cname,
- struct bdev_specs *specs);
-void bdev_put(struct bdev *bdev);
-bool bdev_destroy(struct lxc_conf *conf);
+extern struct lxc_storage *storage_init(struct lxc_conf *conf, const char *src,
+ const char *dst, const char *data);
+
+extern struct lxc_storage *storage_copy(struct lxc_container *c0,
+ const char *cname, const char *lxcpath,
+ const char *bdevtype, int flags,
+ const char *bdevdata, uint64_t newsize,
+ int *needs_rdep);
+extern struct lxc_storage *storage_create(const char *dest, const char *type,
+ const char *cname,
+ struct bdev_specs *specs);
+extern void storage_put(struct lxc_storage *bdev);
+extern bool storage_destroy(struct lxc_conf *conf);
/* callback function to be used with userns_exec_1() */
-int bdev_destroy_wrapper(void *data);
+extern int storage_destroy_wrapper(void *data);
extern bool rootfs_is_blockdev(struct lxc_conf *conf);
#endif // __LXC_STORAGE_H
/*
* return block size of dev->src in units of bytes
*/
-int blk_getsize(struct bdev *bdev, uint64_t *size)
+int blk_getsize(struct lxc_storage *bdev, uint64_t *size)
{
int fd, ret;
char *path = bdev->src;
}
/*
- * Given a bdev (presumably blockdev-based), detect the fstype
+ * Given a lxc_storage (presumably blockdev-based), detect the fstype
* by trying mounting (in a private mntns) it.
- * @bdev: bdev to investigate
+ * @lxc_storage: bdev to investigate
* @type: preallocated char* in which to write the fstype
* @len: length of passed in char*
* Returns length of fstype, of -1 on error
*/
-int detect_fs(struct bdev *bdev, char *type, int len)
+int detect_fs(struct lxc_storage *bdev, char *type, int len)
{
int p[2], ret;
size_t linelen;
* This will return 1 for physical disks, qemu-nbd, loop, etc right now only lvm
* is a block device.
*/
-int is_blktype(struct bdev *b)
+int is_blktype(struct lxc_storage *b)
{
if (strcmp(b->type, "lvm") == 0)
return 1;
/*
* is an unprivileged user allowed to make this kind of snapshot
*/
-bool unpriv_snap_allowed(struct bdev *b, const char *t, bool snap,
+bool unpriv_snap_allowed(struct lxc_storage *b, const char *t, bool snap,
bool maybesnap)
{
if (!t) {
return false;
}
-bool is_valid_bdev_type(const char *type)
+bool is_valid_storage_type(const char *type)
{
if (strcmp(type, "dir") == 0 ||
strcmp(type, "btrfs") == 0 ||
return false;
}
-int bdev_destroy_wrapper(void *data)
+int storage_destroy_wrapper(void *data)
{
struct lxc_conf *conf = data;
return -1;
}
- if (!bdev_destroy(conf))
+ if (!storage_destroy(conf))
return -1;
return 0;
#include "conf.h"
-struct bdev;
+struct lxc_storage;
struct lxc_conf;
extern char *dir_new_path(char *src, const char *oldname, const char *name,
const char *oldpath, const char *lxcpath);
extern bool attach_block_device(struct lxc_conf *conf);
extern void detach_block_device(struct lxc_conf *conf);
-extern int blk_getsize(struct bdev *bdev, uint64_t *size);
-extern int detect_fs(struct bdev *bdev, char *type, int len);
+extern int blk_getsize(struct lxc_storage *bdev, uint64_t *size);
+extern int detect_fs(struct lxc_storage *bdev, char *type, int len);
extern int do_mkfs_exec_wrapper(void *args);
-extern int is_blktype(struct bdev *b);
+extern int is_blktype(struct lxc_storage *b);
extern int mount_unknown_fs(const char *rootfs, const char *target,
const char *options);
extern int find_fstype_cb(char *buffer, void *data);
extern char *linkderef(char *path, char *dest);
-extern bool unpriv_snap_allowed(struct bdev *b, const char *t, bool snap,
+extern bool unpriv_snap_allowed(struct lxc_storage *b, const char *t, bool snap,
bool maybesnap);
-extern bool is_valid_bdev_type(const char *type);
-extern int bdev_destroy_wrapper(void *data);
+extern bool is_valid_storage_type(const char *type);
+extern int storage_destroy_wrapper(void *data);
-#endif // __LXC_STORAGE_UTILS_H
+#endif /* __LXC_STORAGE_UTILS_H */
#include "utils.h"
#include "zfs.h"
-lxc_log_define(lxczfs, lxc);
+lxc_log_define(zfs, lxc);
/*
* zfs ops:
return found;
}
-int zfs_mount(struct bdev *bdev)
+int zfs_mount(struct lxc_storage *bdev)
{
if (strcmp(bdev->type, "zfs"))
return -22;
return ret;
}
-int zfs_umount(struct bdev *bdev)
+int zfs_umount(struct lxc_storage *bdev)
{
if (strcmp(bdev->type, "zfs"))
return -22;
}
}
-int zfs_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
+int zfs_clonepaths(struct lxc_storage *orig, struct lxc_storage *new, const char *oldname,
const char *cname, const char *oldpath, const char *lxcpath, int snap,
uint64_t newsize, struct lxc_conf *conf)
{
* snapshot it was based on, so that we don't hold the original
* container busy.
*/
-int zfs_destroy(struct bdev *orig)
+int zfs_destroy(struct lxc_storage *orig)
{
pid_t pid;
char output[MAXPATHLEN];
exit(EXIT_FAILURE);
}
-int zfs_create(struct bdev *bdev, const char *dest, const char *n,
- struct bdev_specs *specs)
+int zfs_create(struct lxc_storage *bdev, const char *dest, const char *n,
+ struct bdev_specs *specs)
{
const char *zfsroot;
char option[MAXPATHLEN];
#include <stdio.h>
#include <stdint.h>
-/* defined in bdev.h */
-struct bdev;
+struct lxc_storage;
/* defined in lxccontainer.h */
struct bdev_specs;
/* defined conf.h */
struct lxc_conf;
-/*
- * Functions associated with an zfs bdev struct.
- */
-int zfs_clone(const char *opath, const char *npath, const char *oname,
- const char *nname, const char *lxcpath, int snapshot);
-int zfs_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
- const char *cname, const char *oldpath, const char *lxcpath,
- int snap, uint64_t newsize, struct lxc_conf *conf);
-int zfs_create(struct bdev *bdev, const char *dest, const char *n,
- struct bdev_specs *specs);
-/*
- * TODO: detect whether this was a clone, and if so then also delete the
- * snapshot it was based on, so that we don't hold the original
- * container busy.
- */
-int zfs_destroy(struct bdev *orig);
-int zfs_detect(const char *path);
-int zfs_list_entry(const char *path, char *output, size_t inlen);
-int zfs_mount(struct bdev *bdev);
-int zfs_umount(struct bdev *bdev);
+extern int zfs_clonepaths(struct lxc_storage *orig, struct lxc_storage *new,
+ const char *oldname, const char *cname,
+ const char *oldpath, const char *lxcpath, int snap,
+ uint64_t newsize, struct lxc_conf *conf);
+extern int zfs_create(struct lxc_storage *bdev, const char *dest, const char *n,
+ struct bdev_specs *specs);
+extern int zfs_destroy(struct lxc_storage *orig);
+extern int zfs_detect(const char *path);
+extern int zfs_mount(struct lxc_storage *bdev);
+extern int zfs_umount(struct lxc_storage *bdev);
+
+extern bool zfs_copy(struct lxc_conf *conf, struct lxc_storage *orig,
+ struct lxc_storage *new, uint64_t newsize);
+extern bool zfs_snapshot(struct lxc_conf *conf, struct lxc_storage *orig,
+ struct lxc_storage *new, uint64_t newsize);
#endif /* __LXC_ZFS_H */
// Final check whether the user gave use a valid bdev type.
if (strcmp(my_args.bdevtype, "best") &&
strcmp(my_args.bdevtype, "_unset") &&
- !is_valid_bdev_type(my_args.bdevtype)) {
+ !is_valid_storage_type(my_args.bdevtype)) {
fprintf(stderr, "%s is not a valid backing storage type.\n", my_args.bdevtype);
exit(EXIT_FAILURE);
}