zfs: rework zfs storage driver

parent f83dd99e
...@@ -82,8 +82,8 @@ static const struct bdev_ops aufs_ops = { ...@@ -82,8 +82,8 @@ static const struct bdev_ops aufs_ops = {
.clone_paths = &aufs_clonepaths, .clone_paths = &aufs_clonepaths,
.destroy = &aufs_destroy, .destroy = &aufs_destroy,
.create = &aufs_create, .create = &aufs_create,
.create_clone = NULL, .copy = NULL,
.create_snapshot = NULL, .snapshot = NULL,
.can_snapshot = true, .can_snapshot = true,
.can_backup = true, .can_backup = true,
}; };
...@@ -96,8 +96,8 @@ static const struct bdev_ops btrfs_ops = { ...@@ -96,8 +96,8 @@ static const struct bdev_ops btrfs_ops = {
.clone_paths = &btrfs_clonepaths, .clone_paths = &btrfs_clonepaths,
.destroy = &btrfs_destroy, .destroy = &btrfs_destroy,
.create = &btrfs_create, .create = &btrfs_create,
.create_clone = &btrfs_create_clone, .copy = &btrfs_create_clone,
.create_snapshot = &btrfs_create_snapshot, .snapshot = &btrfs_create_snapshot,
.can_snapshot = true, .can_snapshot = true,
.can_backup = true, .can_backup = true,
}; };
...@@ -110,8 +110,8 @@ static const struct bdev_ops dir_ops = { ...@@ -110,8 +110,8 @@ static const struct bdev_ops dir_ops = {
.clone_paths = &dir_clonepaths, .clone_paths = &dir_clonepaths,
.destroy = &dir_destroy, .destroy = &dir_destroy,
.create = &dir_create, .create = &dir_create,
.create_clone = NULL, .copy = NULL,
.create_snapshot = NULL, .snapshot = NULL,
.can_snapshot = false, .can_snapshot = false,
.can_backup = true, .can_backup = true,
}; };
...@@ -124,8 +124,8 @@ static const struct bdev_ops loop_ops = { ...@@ -124,8 +124,8 @@ static const struct bdev_ops loop_ops = {
.clone_paths = &loop_clonepaths, .clone_paths = &loop_clonepaths,
.destroy = &loop_destroy, .destroy = &loop_destroy,
.create = &loop_create, .create = &loop_create,
.create_clone = NULL, .copy = NULL,
.create_snapshot = NULL, .snapshot = NULL,
.can_snapshot = false, .can_snapshot = false,
.can_backup = true, .can_backup = true,
}; };
...@@ -138,8 +138,8 @@ static const struct bdev_ops lvm_ops = { ...@@ -138,8 +138,8 @@ static const struct bdev_ops lvm_ops = {
.clone_paths = &lvm_clonepaths, .clone_paths = &lvm_clonepaths,
.destroy = &lvm_destroy, .destroy = &lvm_destroy,
.create = &lvm_create, .create = &lvm_create,
.create_clone = &lvm_create_clone, .copy = &lvm_create_clone,
.create_snapshot = &lvm_create_snapshot, .snapshot = &lvm_create_snapshot,
.can_snapshot = true, .can_snapshot = true,
.can_backup = false, .can_backup = false,
}; };
...@@ -152,8 +152,8 @@ const struct bdev_ops nbd_ops = { ...@@ -152,8 +152,8 @@ const struct bdev_ops nbd_ops = {
.clone_paths = &nbd_clonepaths, .clone_paths = &nbd_clonepaths,
.destroy = &nbd_destroy, .destroy = &nbd_destroy,
.create = &nbd_create, .create = &nbd_create,
.create_clone = NULL, .copy = NULL,
.create_snapshot = NULL, .snapshot = NULL,
.can_snapshot = true, .can_snapshot = true,
.can_backup = false, .can_backup = false,
}; };
...@@ -166,8 +166,8 @@ static const struct bdev_ops ovl_ops = { ...@@ -166,8 +166,8 @@ static const struct bdev_ops ovl_ops = {
.clone_paths = &ovl_clonepaths, .clone_paths = &ovl_clonepaths,
.destroy = &ovl_destroy, .destroy = &ovl_destroy,
.create = &ovl_create, .create = &ovl_create,
.create_clone = NULL, .copy = NULL,
.create_snapshot = NULL, .snapshot = NULL,
.can_snapshot = true, .can_snapshot = true,
.can_backup = true, .can_backup = true,
}; };
...@@ -180,8 +180,8 @@ static const struct bdev_ops rbd_ops = { ...@@ -180,8 +180,8 @@ static const struct bdev_ops rbd_ops = {
.clone_paths = &rbd_clonepaths, .clone_paths = &rbd_clonepaths,
.destroy = &rbd_destroy, .destroy = &rbd_destroy,
.create = &rbd_create, .create = &rbd_create,
.create_clone = NULL, .copy = NULL,
.create_snapshot = NULL, .snapshot = NULL,
.can_snapshot = false, .can_snapshot = false,
.can_backup = false, .can_backup = false,
}; };
...@@ -194,8 +194,8 @@ static const struct bdev_ops zfs_ops = { ...@@ -194,8 +194,8 @@ static const struct bdev_ops zfs_ops = {
.clone_paths = &zfs_clonepaths, .clone_paths = &zfs_clonepaths,
.destroy = &zfs_destroy, .destroy = &zfs_destroy,
.create = &zfs_create, .create = &zfs_create,
.create_clone = NULL, .copy = &zfs_copy,
.create_snapshot = NULL, .snapshot = &zfs_snapshot,
.can_snapshot = true, .can_snapshot = true,
.can_backup = true, .can_backup = true,
}; };
...@@ -436,9 +436,9 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname, ...@@ -436,9 +436,9 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname,
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->create_snapshot(c0->lxc_conf, orig, new, 0); bret = new->ops->snapshot(c0->lxc_conf, orig, new, 0);
else else
bret = new->ops->create_clone(c0->lxc_conf, orig, new, 0); bret = new->ops->copy(c0->lxc_conf, orig, new, 0);
if (!bret) if (!bret)
return NULL; return NULL;
return new; return new;
...@@ -448,11 +448,24 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname, ...@@ -448,11 +448,24 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname,
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->create_snapshot(c0->lxc_conf, orig, bret = new->ops->snapshot(c0->lxc_conf, orig,
new, newsize); new, newsize);
else else
bret = new->ops->create_clone(c0->lxc_conf, orig, new, bret = new->ops->copy(c0->lxc_conf, orig, new, newsize);
newsize); if (!bret)
return NULL;
return new;
}
/* zfs */
if (!strcmp(orig->type, "zfs") && !strcmp(new->type, "zfs")) {
bool bret = false;
if (snap)
bret = new->ops->snapshot(c0->lxc_conf, orig, new,
newsize);
else
bret = new->ops->copy(c0->lxc_conf, orig, new, newsize);
if (!bret) if (!bret)
return NULL; return NULL;
return new; return new;
......
...@@ -73,10 +73,10 @@ struct bdev_ops { ...@@ -73,10 +73,10 @@ struct bdev_ops {
const char *oldname, const char *cname, const char *oldname, const char *cname,
const char *oldpath, const char *lxcpath, int snap, const char *oldpath, const char *lxcpath, int snap,
uint64_t newsize, struct lxc_conf *conf); uint64_t newsize, struct lxc_conf *conf);
bool (*create_clone)(struct lxc_conf *conf, struct bdev *orig, bool (*copy)(struct lxc_conf *conf, struct bdev *orig, struct bdev *new,
struct bdev *new, uint64_t newsize); uint64_t newsize);
bool (*create_snapshot)(struct lxc_conf *conf, struct bdev *orig, bool (*snapshot)(struct lxc_conf *conf, struct bdev *orig,
struct bdev *new, uint64_t newsize); struct bdev *new, uint64_t newsize);
bool can_snapshot; bool can_snapshot;
bool can_backup; bool can_backup;
}; };
......
...@@ -25,36 +25,30 @@ ...@@ -25,36 +25,30 @@
#define __LXC_ZFS_H #define __LXC_ZFS_H
#define _GNU_SOURCE #define _GNU_SOURCE
#include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
/* defined in bdev.h */
struct bdev; struct bdev;
/* defined in lxccontainer.h */
struct bdev_specs; struct bdev_specs;
/* defined conf.h */
struct lxc_conf; struct lxc_conf;
/* extern int zfs_clonepaths(struct bdev *orig, struct bdev *new,
* Functions associated with an zfs bdev struct. const char *oldname, const char *cname,
*/ const char *oldpath, const char *lxcpath, int snap,
int zfs_clone(const char *opath, const char *npath, const char *oname, uint64_t newsize, struct lxc_conf *conf);
const char *nname, const char *lxcpath, int snapshot); extern int zfs_create(struct bdev *bdev, const char *dest, const char *n,
int zfs_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname, struct bdev_specs *specs);
const char *cname, const char *oldpath, const char *lxcpath, extern int zfs_destroy(struct bdev *orig);
int snap, uint64_t newsize, struct lxc_conf *conf); extern bool zfs_detect(const char *path);
int zfs_create(struct bdev *bdev, const char *dest, const char *n, extern int zfs_mount(struct bdev *bdev);
struct bdev_specs *specs); extern int zfs_umount(struct bdev *bdev);
/*
* TODO: detect whether this was a clone, and if so then also delete the extern bool zfs_copy(struct lxc_conf *conf, struct bdev *orig, struct bdev *new,
* snapshot it was based on, so that we don't hold the original uint64_t newsize);
* container busy. extern bool zfs_snapshot(struct lxc_conf *conf, struct bdev *orig,
*/ struct bdev *new, uint64_t newsize);
int zfs_destroy(struct bdev *orig);
bool zfs_detect(const char *path);
int zfs_mount(struct bdev *bdev);
int zfs_umount(struct bdev *bdev);
#endif /* __LXC_ZFS_H */ #endif /* __LXC_ZFS_H */
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