diff options
Diffstat (limited to 'liblfjail/jail_zfs.cc')
| -rw-r--r-- | liblfjail/jail_zfs.cc | 103 |
1 files changed, 5 insertions, 98 deletions
diff --git a/liblfjail/jail_zfs.cc b/liblfjail/jail_zfs.cc index b8d58cc..07b0169 100644 --- a/liblfjail/jail_zfs.cc +++ b/liblfjail/jail_zfs.cc @@ -10,6 +10,7 @@ #include "exec.hh" #include "generic_error.hh" #include "jail_zfs.hh" +#include "zfs.hh" using namespace lfjail; using namespace std::literals; @@ -29,111 +30,17 @@ config::string_option mountpoint( namespace { /* - * Test if the given ZFS dataset exists. - */ -auto dataset_exists(std::string const &/*ds*/) -> bool { - throw("not implemented"); -#if 0 - auto sout = std::string(); - auto serr = std::string(); - - auto const ret = lfjail::cexecl( - std::back_inserter(sout), - std::back_inserter(serr), - "/sbin/zfs", - "zfs", "get", "-H", "-ovalue", "name", ds); - - return (ret == 0); -#endif -} - -/* - * Create a new ZFS dataset. - */ -template<typename... Args> -void dataset_create(std::string const &/*ds*/, Args&& .../*args*/) { - throw("not implemented"); -#if 0 - std::vector<std::string> argv; - argv.emplace_back("zfs"); - argv.emplace_back("create"); - (argv.emplace_back(std::format("-o{}", std::forward<Args>(args))), ...); - argv.emplace_back(ds); - - auto sout = std::string(); - auto serr = std::string(); - - auto const ret = lfjail::cexec(std::back_inserter(sout), - std::back_inserter(serr), - "/sbin/zfs", argv); - - if (!serr.empty()) - throw generic_error("zfs create failed: {}", serr); - if (ret != 0) - throw generic_error("zfs create failed: {}", ret); -#endif -} - -/* - * Destroy a ZFS datset. - */ -void dataset_destroy(std::string const &/*ds*/) { - throw("not implemented"); -#if 0 - auto sout = std::string(); - auto serr = std::string(); - - int ret = lfjail::cexecl(std::back_inserter(sout), - std::back_inserter(serr), - "/sbin/zfs", - "zfs", "destroy", "-r", ds); - - if (!serr.empty()) - throw generic_error("zfs destroy failed: {}", serr); - if (ret != 0) - throw generic_error("zfs destroy failed: {}", ret); -#endif -} - -/* - * Return a ZFS properly for a fileystem. - */ -auto get_property(std::string const &/*fs*/, std::string const &/*prop*/) - -> std::string -{ - throw("not implemented"); -#if 0 - auto sout = std::string(); - auto serr = std::string(); - - int ret = lfjail::cexecl( - std::back_inserter(sout), - std::back_inserter(serr), - "/sbin/zfs", - "zfs", "get", "-H", "-ovalue", prop, fs); - - if (!serr.empty()) - throw generic_error("zfs get failed: {}", serr); - if (ret != 0) - throw generic_error("zfs get failed: {}", ret); - if (sout[sout.size() - 1] == '\n') - sout.resize(sout.size() - 1); - return sout; -#endif -} - -/* * Make sure our top-level ZFS dataset exists. */ void ensure_jroot(context const &) { auto jroot = lfjail::zfs::filesystem.string(); auto mntpt = lfjail::zfs::mountpoint.string(); - if (dataset_exists(jroot)) + if (zfs::dataset_exists(jroot)) return; auto mntptopt = std::format("mountpoint={}", mntpt); - dataset_create(jroot, mntptopt); + zfs::create_dataset(jroot, mntptopt); } } // anonymous namespace @@ -150,7 +57,7 @@ void create_for_jail(context const &ctx, jail const &jailconf) { ensure_jroot(ctx); auto const ds = filesystem.string() + "/" + jailconf.name; - dataset_create(ds); + zfs::create_dataset(ds); } void destroy_for_jail(context const &, jail const &jailconf) { @@ -165,7 +72,7 @@ auto jail_root(context const &ctx) -> std::string { if (fs.empty()) throw generic_error("zfs.filesystem not set"); - return get_property(fs, "mountpoing"); + return ""; // fs.mountpoint } } // namespace lfjail::zfs |
