diff options
author | Roger Leigh <rleigh@debian.org> | 2013-04-07 23:17:25 +0100 |
---|---|---|
committer | Roger Leigh <rleigh@debian.org> | 2013-04-09 22:36:44 +0100 |
commit | 96328e8519410ed31c86f0ebe653d0f080168ec9 (patch) | |
tree | d060ffda1db906706c8d9413da09687b1c672644 /lib | |
parent | f819067df270f68620450b2f3fabae440dd4235a (diff) | |
download | schroot-96328e8519410ed31c86f0ebe653d0f080168ec9.tar.gz |
sbuild: Move chroot-facet-union to namespace chroot::facet::fsunion
Diffstat (limited to 'lib')
-rw-r--r-- | lib/sbuild/Makefile.am | 4 | ||||
-rw-r--r-- | lib/sbuild/chroot-facet-union.cc | 280 | ||||
-rw-r--r-- | lib/sbuild/chroot-facet-union.h | 203 | ||||
-rw-r--r-- | lib/sbuild/chroot/block-device.cc | 16 | ||||
-rw-r--r-- | lib/sbuild/chroot/directory.cc | 8 | ||||
-rw-r--r-- | lib/sbuild/chroot/facet/fsunion.cc | 291 | ||||
-rw-r--r-- | lib/sbuild/chroot/facet/fsunion.h | 209 | ||||
-rw-r--r-- | lib/sbuild/chroot/facet/session-clonable.cc | 8 | ||||
-rw-r--r-- | lib/sbuild/chroot/facet/source-clonable.cc | 4 | ||||
-rw-r--r-- | lib/sbuild/chroot/loopback.cc | 4 |
10 files changed, 522 insertions, 505 deletions
diff --git a/lib/sbuild/Makefile.am b/lib/sbuild/Makefile.am index aadda2c9..3886338b 100644 --- a/lib/sbuild/Makefile.am +++ b/lib/sbuild/Makefile.am @@ -95,7 +95,7 @@ endif if BUILD_UNION lib_sbuild_public_union_h_sources = \ - lib/sbuild/chroot-facet-union.h + lib/sbuild/chroot/facet/fsunion.h endif if BUILD_UNSHARE @@ -172,7 +172,7 @@ endif if BUILD_UNION lib_sbuild_public_union_cc_sources = \ - lib/sbuild/chroot-facet-union.cc + lib/sbuild/chroot/facet/fsunion.cc endif if BUILD_UNSHARE diff --git a/lib/sbuild/chroot-facet-union.cc b/lib/sbuild/chroot-facet-union.cc deleted file mode 100644 index 882737c1..00000000 --- a/lib/sbuild/chroot-facet-union.cc +++ /dev/null @@ -1,280 +0,0 @@ -/* Copyright © 2008-2013 Jan-Marek Glogowski <glogow@fbihome.de> - * Copyright © 2009-2013 Roger Leigh <rleigh@debian.org> - * - * schroot is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * schroot is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see - * <http://www.gnu.org/licenses/>. - * - *********************************************************************/ - -#include <config.h> - -#include <sbuild/chroot/chroot.h> -#include <sbuild/chroot/facet/session.h> -#include "chroot-facet-union.h" -#include <sbuild/chroot/facet/source-clonable.h> -#include "feature.h" - -#include <cassert> - -using boost::format; -using std::endl; -using namespace sbuild; - -namespace -{ - - sbuild::feature feature_union("UNION", N_("Support for filesystem unioning")); - -} - -template<> -error<chroot_facet_union::error_code>::map_type -error<chroot_facet_union::error_code>::error_strings = - { - // TRANSLATORS: %1% = chroot fs type - {chroot_facet_union::UNION_TYPE_UNKNOWN, N_("Unknown filesystem union type ‘%1%’")}, - {chroot_facet_union::UNION_OVERLAY_ABS, N_("Union overlay must have an absolute path")}, - {chroot_facet_union::UNION_UNDERLAY_ABS, N_("Union underlay must have an absolute path")} - }; - -chroot_facet_union::chroot_facet_union (): - chroot::facet::facet(), - union_type("none"), - union_overlay_directory(SCHROOT_OVERLAY_DIR), - union_underlay_directory(SCHROOT_UNDERLAY_DIR) -{ -} - -chroot_facet_union::~chroot_facet_union () -{ -} - -chroot_facet_union::ptr -chroot_facet_union::create () -{ - return ptr(new chroot_facet_union()); -} - -chroot::facet::facet::ptr -chroot_facet_union::clone () const -{ - return ptr(new chroot_facet_union(*this)); -} - -std::string const& -chroot_facet_union::get_name () const -{ - static const std::string name("union"); - - return name; -} - -bool -chroot_facet_union::get_union_configured () const -{ - return get_union_type() != "none"; -} - -std::string const& -chroot_facet_union::get_union_overlay_directory () const -{ - return this->union_overlay_directory; -} - -void -chroot_facet_union::set_union_overlay_directory -(std::string const& directory) -{ - if (!is_absname(directory)) - throw error(directory, UNION_OVERLAY_ABS); - - this->union_overlay_directory = directory; -} - -std::string const& -chroot_facet_union::get_union_underlay_directory () const -{ - return this->union_underlay_directory; -} - -void -chroot_facet_union::set_union_underlay_directory -(std::string const& directory) -{ - if (!is_absname(directory)) - throw error(directory, UNION_UNDERLAY_ABS); - - this->union_underlay_directory = directory; -} - -std::string const& -chroot_facet_union::get_union_type () const -{ - return this->union_type; -} - -void -chroot_facet_union::set_union_type (std::string const& type) -{ - if (type == "aufs" || - type == "overlayfs" || - type == "unionfs" || - type == "none") - this->union_type = type; - else - throw error(type, UNION_TYPE_UNKNOWN); - - chroot::chroot *base = dynamic_cast<chroot::chroot *>(this->owner); - assert(base); - - if (this->union_type != "none") - { - if (!base->get_facet<chroot::facet::source_clonable>()) - base->add_facet(chroot::facet::source_clonable::create()); - } - else - base->remove_facet<chroot::facet::source_clonable>(); -} - -std::string const& -chroot_facet_union::get_union_mount_options () const -{ - return union_mount_options; -} - -void -chroot_facet_union::set_union_mount_options -(std::string const& union_mount_options) -{ - this->union_mount_options = union_mount_options; -} - -void -chroot_facet_union::setup_env (chroot::chroot const& chroot, - environment& env) const -{ - env.add("CHROOT_UNION_TYPE", get_union_type()); - if (get_union_configured()) - { - env.add("CHROOT_UNION_MOUNT_OPTIONS", - get_union_mount_options()); - env.add("CHROOT_UNION_OVERLAY_DIRECTORY", - get_union_overlay_directory()); - env.add("CHROOT_UNION_UNDERLAY_DIRECTORY", - get_union_underlay_directory()); - } -} - -chroot::chroot::session_flags -chroot_facet_union::get_session_flags (chroot::chroot const& chroot) const -{ - chroot::chroot::session_flags flags = chroot::chroot::SESSION_NOFLAGS; - - if (get_union_configured() && chroot.get_facet<chroot::facet::session>()) - flags = chroot::chroot::SESSION_PURGE; - - return flags; -} - -void -chroot_facet_union::get_details (chroot::chroot const& chroot, - format_detail& detail) const -{ - detail.add(_("Filesystem Union Type"), get_union_type()); - if (get_union_configured()) - { - if (!this->union_mount_options.empty()) - detail.add(_("Filesystem Union Mount Options"), - get_union_mount_options()); - if (!this->union_overlay_directory.empty()) - detail.add(_("Filesystem Union Overlay Directory"), - get_union_overlay_directory()); - if (!this->union_underlay_directory.empty()) - detail.add(_("Filesystem Union Underlay Directory"), - get_union_underlay_directory()); - } -} - -void -chroot_facet_union::get_used_keys (string_list& used_keys) const -{ - used_keys.push_back("union-type"); - used_keys.push_back("union-mount-options"); - used_keys.push_back("union-overlay-directory"); - used_keys.push_back("union-underlay-directory"); -} - -void -chroot_facet_union::get_keyfile (chroot::chroot const& chroot, - keyfile& keyfile) const -{ - keyfile::set_object_value(*this, &chroot_facet_union::get_union_type, - keyfile, chroot.get_name(), "union-type"); - - if (get_union_configured()) - { - keyfile::set_object_value(*this, - &chroot_facet_union::get_union_mount_options, - keyfile, chroot.get_name(), - "union-mount-options"); - - keyfile::set_object_value(*this, - &chroot_facet_union::get_union_overlay_directory, - keyfile, chroot.get_name(), - "union-overlay-directory"); - - keyfile::set_object_value(*this, - &chroot_facet_union::get_union_underlay_directory, - keyfile, chroot.get_name(), - "union-underlay-directory"); - } -} - -void -chroot_facet_union::set_keyfile (chroot::chroot& chroot, - keyfile const& keyfile) -{ - bool issession = static_cast<bool>(chroot.get_facet<chroot::facet::session>()); - - keyfile::get_object_value(*this, &chroot_facet_union::set_union_type, - keyfile, chroot.get_name(), "union-type", - keyfile::PRIORITY_OPTIONAL); - - // If we are a union, add specific source options here. - chroot::facet::source_clonable::ptr psrc - (chroot.get_facet<chroot::facet::source_clonable>()); - if (psrc) - psrc->set_keyfile(chroot, keyfile); - - keyfile::get_object_value(*this, - &chroot_facet_union::set_union_mount_options, - keyfile, chroot.get_name(), "union-mount-options", - keyfile::PRIORITY_OPTIONAL); - - keyfile::get_object_value(*this, - &chroot_facet_union::set_union_overlay_directory, - keyfile, chroot.get_name(), - "union-overlay-directory", - (issession && get_union_configured()) ? - keyfile::PRIORITY_REQUIRED : - keyfile::PRIORITY_OPTIONAL); - - keyfile::get_object_value(*this, - &chroot_facet_union::set_union_underlay_directory, - keyfile, chroot.get_name(), - "union-underlay-directory", - (issession && get_union_configured()) ? - keyfile::PRIORITY_REQUIRED : - keyfile::PRIORITY_OPTIONAL); -} diff --git a/lib/sbuild/chroot-facet-union.h b/lib/sbuild/chroot-facet-union.h deleted file mode 100644 index 696f8756..00000000 --- a/lib/sbuild/chroot-facet-union.h +++ /dev/null @@ -1,203 +0,0 @@ -/* Copyright © 2008-2013 Jan-Marek Glogowski <glogow@fbihome.de> - * Copyright © 2005-2013 Roger Leigh <rleigh@debian.org> - * - * schroot is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * schroot is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see - * <http://www.gnu.org/licenses/>. - * - *********************************************************************/ - -#ifndef SBUILD_CHROOT_FACET_UNION_H -#define SBUILD_CHROOT_FACET_UNION_H - -#include <sbuild/chroot/facet/facet.h> - -namespace sbuild -{ - - /** - * Chroot support for filesystem union based sessions. - * - * A chroot may offer session support using a filesystem union like - * aufs or unionfs. A new union type may need to adapt the 10mount - * or 05union script to properly populate the underlay and mount - * directory. The overlay directory and union setup is already - * handled. - */ - class chroot_facet_union : public chroot::facet::facet - { - public: - /// Error codes. - enum error_code - { - UNION_TYPE_UNKNOWN, ///< Unknown filesystem union type. - UNION_OVERLAY_ABS, ///< Union overlay must have an absolute path. - UNION_UNDERLAY_ABS ///< Union underlay must have an absolute path. - }; - - /// Exception type. - typedef custom_error<error_code> error; - - /// A shared_ptr to a chroot facet object. - typedef std::shared_ptr<chroot_facet_union> ptr; - - /// A shared_ptr to a const chroot facet object. - typedef std::shared_ptr<const chroot_facet_union> const_ptr; - - private: - /// The constructor. - chroot_facet_union (); - - public: - /// The destructor. - virtual ~chroot_facet_union (); - - /** - * Create a chroot facet. - * - * @returns a shared_ptr to the new chroot facet. - */ - static ptr - create (); - - virtual facet::ptr - clone () const; - - std::string const& - get_name () const; - - /** - * Get fs union configured state. - * - * @returns if fs union is configured - */ - bool - get_union_configured () const; - - /** - * Get the filesystem union type. - * - * @see set_union_type - * @returns the union filesytem type. - */ - virtual std::string const& - get_union_type () const; - - /** - * Set the filesystem union type. - * - * Currently supported values are aufs, unionfs and none. - * - * @param union_type the filesystem type. - **/ - virtual void - set_union_type (std::string const& union_type); - - /** - * Get the filesystem union mount options (branch configuration). - * - * @see set_union_mount_options - * @returns the filesystem union branch configuration. - */ - virtual std::string const& - get_union_mount_options () const; - - /** - * Set the filesystem union mount options (branch configuration). - * - * Normally a temporary directory is used as the writeable branch, - * which is removed on session end. This allows the building of a - * complex union which can merge multiple branches. The string has - * to be constructed as expected by the filesystem union type and - * is directly used as the mount '-o' option string. - * - * @param union_mount_options a union filesystem-specific branch - * description - **/ - virtual void - set_union_mount_options (std::string const& union_mount_options); - - /** - * Get the union overlay directory. - * - * @returns the writeable overlay directory. - */ - virtual std::string const& - get_union_overlay_directory () const; - - /** - * Set the union overlay directory. - * - * @param directory the writeable overlay directory. - */ - virtual void - set_union_overlay_directory (std::string const& directory); - - /** - * Get the union underlay directory. - * - * @returns the writeable underlay directory. - */ - virtual std::string const& - get_union_underlay_directory () const; - - /** - * Set the union underlay directory. - * - * @param directory the writeable underlay directory. - */ - virtual void - set_union_underlay_directory (std::string const& directory); - - virtual void - setup_env (chroot::chroot const& chroot, - environment& env) const; - - virtual chroot::chroot::session_flags - get_session_flags (chroot::chroot const& chroot) const; - - virtual void - get_details (chroot::chroot const& chroot, - format_detail& detail) const; - - virtual void - get_used_keys (string_list& used_keys) const; - - virtual void - get_keyfile (chroot::chroot const& chroot, - keyfile& keyfile) const; - - virtual void - set_keyfile (chroot::chroot& chroot, - keyfile const& keyfile); - - private: - /// filesystem union type. - std::string union_type; - /// Union mount options (branch configuration). - std::string union_mount_options; - /// Union read-write overlay directory. - std::string union_overlay_directory; - /// Union read-only underlay directory. - std::string union_underlay_directory; - }; - -} - -#endif /* SBUILD_CHROOT_FACET_UNION_H */ - -/* - * Local Variables: - * mode:C++ - * End: - */ diff --git a/lib/sbuild/chroot/block-device.cc b/lib/sbuild/chroot/block-device.cc index dbb42e28..c27db24f 100644 --- a/lib/sbuild/chroot/block-device.cc +++ b/lib/sbuild/chroot/block-device.cc @@ -22,7 +22,7 @@ #include <sbuild/chroot/facet/session-clonable.h> #include <sbuild/chroot/facet/source-clonable.h> #ifdef SBUILD_FEATURE_UNION -#include "chroot-facet-union.h" +#include <sbuild/chroot/facet/fsunion.h> #endif // SBUILD_FEATURE_UNION #include "format-detail.h" #include "util.h" @@ -45,7 +45,7 @@ namespace sbuild block_device_base() { #ifdef SBUILD_FEATURE_UNION - add_facet(chroot_facet_union::create()); + add_facet(facet::fsunion::create()); #endif // SBUILD_FEATURE_UNION } @@ -63,8 +63,8 @@ namespace sbuild block_device_base(rhs) { #ifdef SBUILD_FEATURE_UNION - if (!get_facet<chroot_facet_union>()) - add_facet(chroot_facet_union::create()); + if (!get_facet<facet::fsunion>()) + add_facet(facet::fsunion::create()); #endif // SBUILD_FEATURE_UNION } #endif // SBUILD_FEATURE_LVMSNAP @@ -137,12 +137,12 @@ namespace sbuild else { #ifdef SBUILD_FEATURE_UNION - /* We don't lock the device if union is configured. */ + /* We don't lock the device if fsunion is configured. */ const chroot *base = dynamic_cast<const chroot *>(this); assert(base); - chroot_facet_union::const_ptr puni - (base->get_facet<chroot_facet_union>()); -#endif + facet::fsunion::const_ptr puni + (base->get_facet<facet::fsunion>()); +#endif // SBUILD_FEATURE_UNION } } catch (sbuild::stat::error const& e) // Failed to stat diff --git a/lib/sbuild/chroot/directory.cc b/lib/sbuild/chroot/directory.cc index 339ed252..ed8d70e9 100644 --- a/lib/sbuild/chroot/directory.cc +++ b/lib/sbuild/chroot/directory.cc @@ -22,7 +22,7 @@ #include <sbuild/chroot/facet/session-clonable.h> #include <sbuild/chroot/facet/source-clonable.h> #ifdef SBUILD_FEATURE_UNION -#include "chroot-facet-union.h" +#include <sbuild/chroot/facet/fsunion.h> #endif // SBUILD_FEATURE_UNION #include "format-detail.h" #include "lock.h" @@ -46,7 +46,7 @@ namespace sbuild directory_base() { #ifdef SBUILD_FEATURE_UNION - add_facet(chroot_facet_union::create()); + add_facet(facet::fsunion::create()); #endif // SBUILD_FEATURE_UNION } @@ -60,8 +60,8 @@ namespace sbuild directory_base(rhs) { #ifdef SBUILD_FEATURE_UNION - if (!get_facet<chroot_facet_union>()) - add_facet(chroot_facet_union::create()); + if (!get_facet<facet::fsunion>()) + add_facet(facet::fsunion::create()); #endif // SBUILD_FEATURE_UNION set_directory(rhs.get_source_subvolume()); diff --git a/lib/sbuild/chroot/facet/fsunion.cc b/lib/sbuild/chroot/facet/fsunion.cc new file mode 100644 index 00000000..31ed95fe --- /dev/null +++ b/lib/sbuild/chroot/facet/fsunion.cc @@ -0,0 +1,291 @@ +/* Copyright © 2008-2013 Jan-Marek Glogowski <glogow@fbihome.de> + * Copyright © 2009-2013 Roger Leigh <rleigh@debian.org> + * + * schroot is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * schroot is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see + * <http://www.gnu.org/licenses/>. + * + *********************************************************************/ + +#include <config.h> + +#include <sbuild/chroot/chroot.h> +#include <sbuild/chroot/facet/session.h> +#include <sbuild/chroot/facet/fsunion.h> +#include <sbuild/chroot/facet/source-clonable.h> +#include "feature.h" + +#include <cassert> + +using boost::format; +using std::endl; +using namespace sbuild; + +namespace +{ + + sbuild::feature feature_union("UNION", N_("Support for filesystem unioning")); + +} + +namespace sbuild +{ + namespace chroot + { + namespace facet + { + + template<> + error<fsunion::error_code>::map_type + error<fsunion::error_code>::error_strings = + { + // TRANSLATORS: %1% = chroot fs type + {chroot::facet::fsunion::FSUNION_TYPE_UNKNOWN, N_("Unknown filesystem union type ‘%1%’")}, + {chroot::facet::fsunion::FSUNION_OVERLAY_ABS, N_("Union overlay must have an absolute path")}, + {chroot::facet::fsunion::FSUNION_UNDERLAY_ABS, N_("Union underlay must have an absolute path")} + }; + + fsunion::fsunion (): + facet(), + union_type("none"), + union_overlay_directory(SCHROOT_OVERLAY_DIR), + union_underlay_directory(SCHROOT_UNDERLAY_DIR) + { + } + + fsunion::~fsunion () + { + } + + fsunion::ptr + fsunion::create () + { + return ptr(new fsunion()); + } + + facet::ptr + fsunion::clone () const + { + return ptr(new fsunion(*this)); + } + + std::string const& + fsunion::get_name () const + { + static const std::string name("union"); + + return name; + } + + bool + fsunion::get_union_configured () const + { + return get_union_type() != "none"; + } + + std::string const& + fsunion::get_union_overlay_directory () const + { + return this->union_overlay_directory; + } + + void + fsunion::set_union_overlay_directory + (std::string const& directory) + { + if (!is_absname(directory)) + throw error(directory, FSUNION_OVERLAY_ABS); + + this->union_overlay_directory = directory; + } + + std::string const& + fsunion::get_union_underlay_directory () const + { + return this->union_underlay_directory; + } + + void + fsunion::set_union_underlay_directory + (std::string const& directory) + { + if (!is_absname(directory)) + throw error(directory, FSUNION_UNDERLAY_ABS); + + this->union_underlay_directory = directory; + } + + std::string const& + fsunion::get_union_type () const + { + return this->union_type; + } + + void + fsunion::set_union_type (std::string const& type) + { + if (type == "aufs" || + type == "overlayfs" || + type == "unionfs" || + type == "none") + this->union_type = type; + else + throw error(type, FSUNION_TYPE_UNKNOWN); + + chroot *base = dynamic_cast<chroot *>(this->owner); + assert(base); + + if (this->union_type != "none") + { + if (!base->get_facet<source_clonable>()) + base->add_facet(source_clonable::create()); + } + else + base->remove_facet<source_clonable>(); + } + + std::string const& + fsunion::get_union_mount_options () const + { + return union_mount_options; + } + + void + fsunion::set_union_mount_options + (std::string const& union_mount_options) + { + this->union_mount_options = union_mount_options; + } + + void + fsunion::setup_env (chroot const& chroot, + environment& env) const + { + env.add("CHROOT_UNION_TYPE", get_union_type()); + if (get_union_configured()) + { + env.add("CHROOT_UNION_MOUNT_OPTIONS", + get_union_mount_options()); + env.add("CHROOT_UNION_OVERLAY_DIRECTORY", + get_union_overlay_directory()); + env.add("CHROOT_UNION_UNDERLAY_DIRECTORY", + get_union_underlay_directory()); + } + } + + chroot::session_flags + fsunion::get_session_flags (chroot const& chroot) const + { + chroot::session_flags flags = chroot::SESSION_NOFLAGS; + + if (get_union_configured() && chroot.get_facet<session>()) + flags = chroot::SESSION_PURGE; + + return flags; + } + + void + fsunion::get_details (chroot const& chroot, + format_detail& detail) const + { + detail.add(_("Filesystem Union Type"), get_union_type()); + if (get_union_configured()) + { + if (!this->union_mount_options.empty()) + detail.add(_("Filesystem Union Mount Options"), + get_union_mount_options()); + if (!this->union_overlay_directory.empty()) + detail.add(_("Filesystem Union Overlay Directory"), + get_union_overlay_directory()); + if (!this->union_underlay_directory.empty()) + detail.add(_("Filesystem Union Underlay Directory"), + get_union_underlay_directory()); + } + } + + void + fsunion::get_used_keys (string_list& used_keys) const + { + used_keys.push_back("union-type"); + used_keys.push_back("union-mount-options"); + used_keys.push_back("union-overlay-directory"); + used_keys.push_back("union-underlay-directory"); + } + + void + fsunion::get_keyfile (chroot const& chroot, + keyfile& keyfile) const + { + keyfile::set_object_value(*this, &fsunion::get_union_type, + keyfile, chroot.get_name(), "union-type"); + + if (get_union_configured()) + { + keyfile::set_object_value(*this, + &fsunion::get_union_mount_options, + keyfile, chroot.get_name(), + "union-mount-options"); + + keyfile::set_object_value(*this, + &fsunion::get_union_overlay_directory, + keyfile, chroot.get_name(), + "union-overlay-directory"); + + keyfile::set_object_value(*this, + &fsunion::get_union_underlay_directory, + keyfile, chroot.get_name(), + "union-underlay-directory"); + } + } + + void + fsunion::set_keyfile (chroot& chroot, + keyfile const& keyfile) + { + bool issession = static_cast<bool>(chroot.get_facet<session>()); + + keyfile::get_object_value(*this, &fsunion::set_union_type, + keyfile, chroot.get_name(), "union-type", + keyfile::PRIORITY_OPTIONAL); + + // If we are a union, add specific source options here. + source_clonable::ptr psrc + (chroot.get_facet<source_clonable>()); + if (psrc) + psrc->set_keyfile(chroot, keyfile); + + keyfile::get_object_value(*this, + &fsunion::set_union_mount_options, + keyfile, chroot.get_name(), "union-mount-options", + keyfile::PRIORITY_OPTIONAL); + + keyfile::get_object_value(*this, + &fsunion::set_union_overlay_directory, + keyfile, chroot.get_name(), + "union-overlay-directory", + (issession && get_union_configured()) ? + keyfile::PRIORITY_REQUIRED : + keyfile::PRIORITY_OPTIONAL); + + keyfile::get_object_value(*this, + &fsunion::set_union_underlay_directory, + keyfile, chroot.get_name(), + "union-underlay-directory", + (issession && get_union_configured()) ? + keyfile::PRIORITY_REQUIRED : + keyfile::PRIORITY_OPTIONAL); + } + + } + } +} diff --git a/lib/sbuild/chroot/facet/fsunion.h b/lib/sbuild/chroot/facet/fsunion.h new file mode 100644 index 00000000..2cb1627b --- /dev/null +++ b/lib/sbuild/chroot/facet/fsunion.h @@ -0,0 +1,209 @@ +/* Copyright © 2008-2013 Jan-Marek Glogowski <glogow@fbihome.de> + * Copyright © 2005-2013 Roger Leigh <rleigh@debian.org> + * + * schroot is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * schroot is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see + * <http://www.gnu.org/licenses/>. + * + *********************************************************************/ + +#ifndef SBUILD_CHROOT_FACET_FSUNION_H +#define SBUILD_CHROOT_FACET_FSUNION_H + +#include <sbuild/chroot/facet/facet.h> + +namespace sbuild +{ + namespace chroot + { + namespace facet + { + + /** + * Chroot support for filesystem union based sessions. + * + * A chroot may offer session support using a filesystem union like + * aufs or unionfs. A new union type may need to adapt the 10mount + * or 05union script to properly populate the underlay and mount + * directory. The overlay directory and union setup is already + * handled. + */ + class fsunion : public facet + { + public: + /// Error codes. + enum error_code + { + FSUNION_TYPE_UNKNOWN, ///< Unknown filesystem union type. + FSUNION_OVERLAY_ABS, ///< Union overlay must have an absolute path. + FSUNION_UNDERLAY_ABS ///< Union underlay must have an absolute path. + }; + + /// Exception type. + typedef custom_error<error_code> error; + + /// A shared_ptr to a chroot facet object. + typedef std::shared_ptr<fsunion> ptr; + + /// A shared_ptr to a const chroot facet object. + typedef std::shared_ptr<const fsunion> const_ptr; + + private: + /// The constructor. + fsunion (); + + public: + /// The destructor. + virtual ~fsunion (); + + /** + * Create a chroot facet. + * + * @returns a shared_ptr to the new chroot facet. + */ + static ptr + create (); + + virtual facet::ptr + clone () const; + + std::string const& + get_name () const; + + /** + * Get fs union configured state. + * + * @returns if fs union is configured + */ + bool + get_union_configured () const; + + /** + * Get the filesystem union type. + * + * @see set_union_type + * @returns the union filesytem type. + */ + virtual std::string const& + get_union_type () const; + + /** + * Set the filesystem union type. + * + * Currently supported values are aufs, unionfs and none. + * + * @param union_type the filesystem type. + **/ + virtual void + set_union_type (std::string const& union_type); + + /** + * Get the filesystem union mount options (branch configuration). + * + * @see set_union_mount_options + * @returns the filesystem union branch configuration. + */ + virtual std::string const& + get_union_mount_options () const; + + /** + * Set the filesystem union mount options (branch configuration). + * + * Normally a temporary directory is used as the writeable branch, + * which is removed on session end. This allows the building of a + * complex union which can merge multiple branches. The string has + * to be constructed as expected by the filesystem union type and + * is directly used as the mount '-o' option string. + * + * @param union_mount_options a union filesystem-specific branch + * description + **/ + virtual void + set_union_mount_options (std::string const& union_mount_options); + + /** + * Get the union overlay directory. + * + * @returns the writeable overlay directory. + */ + virtual std::string const& + get_union_overlay_directory () const; + + /** + * Set the union overlay directory. + * + * @param directory the writeable overlay directory. + */ + virtual void + set_union_overlay_directory (std::string const& directory); + + /** + * Get the union underlay directory. + * + * @returns the writeable underlay directory. + */ + virtual std::string const& + get_union_underlay_directory () const; + + /** + * Set the union underlay directory. + * + * @param directory the writeable underlay directory. + */ + virtual void + set_union_underlay_directory (std::string const& directory); + + virtual void + setup_env (chroot const& chroot, + environment& env) const; + + virtual chroot::session_flags + get_session_flags (chroot const& chroot) const; + + virtual void + get_details (chroot const& chroot, + format_detail& detail) const; + + virtual void + get_used_keys (string_list& used_keys) const; + + virtual void + get_keyfile (chroot const& chroot, + keyfile& keyfile) const; + + virtual void + set_keyfile (chroot& chroot, + keyfile const& keyfile); + + private: + /// filesystem union type. + std::string union_type; + /// Union mount options (branch configuration). + std::string union_mount_options; + /// Union read-write overlay directory. + std::string union_overlay_directory; + /// Union read-only underlay directory. + std::string union_underlay_directory; + }; + + } + } +} + +#endif /* SBUILD_CHROOT_FACET_FSUNION_H */ + +/* + * Local Variables: + * mode:C++ + * End: + */ diff --git a/lib/sbuild/chroot/facet/session-clonable.cc b/lib/sbuild/chroot/facet/session-clonable.cc index 1cee2dc0..8d3eea02 100644 --- a/lib/sbuild/chroot/facet/session-clonable.cc +++ b/lib/sbuild/chroot/facet/session-clonable.cc @@ -37,7 +37,7 @@ #include <sbuild/chroot/btrfs-snapshot.h> #endif // SBUILD_FEATURE_BTRFSSNAP #ifdef SBUILD_FEATURE_UNION -#include "chroot-facet-union.h" +#include <sbuild/chroot/facet/fsunion.h> #endif // SBUILD_FEATURE_UNION #include "format-detail.h" @@ -203,12 +203,12 @@ namespace sbuild #ifdef SBUILD_FEATURE_UNION // If the parent did not have a union facet, then neither should we. - chroot_facet_union::const_ptr pparentuni(parent.get_facet<chroot_facet_union>()); + fsunion::const_ptr pparentuni(parent.get_facet<fsunion>()); if (!pparentuni) - clone->remove_facet<chroot_facet_union>(); + clone->remove_facet<fsunion>(); /* Filesystem unions need the overlay directory specifying. */ - chroot_facet_union::ptr puni(clone->get_facet<chroot_facet_union>()); + fsunion::ptr puni(clone->get_facet<fsunion>()); if (puni) { diff --git a/lib/sbuild/chroot/facet/source-clonable.cc b/lib/sbuild/chroot/facet/source-clonable.cc index 707950cf..09294e4a 100644 --- a/lib/sbuild/chroot/facet/source-clonable.cc +++ b/lib/sbuild/chroot/facet/source-clonable.cc @@ -23,7 +23,7 @@ #include <sbuild/chroot/facet/source-clonable.h> #include <sbuild/chroot/facet/source.h> #ifdef SBUILD_FEATURE_UNION -#include "chroot-facet-union.h" +#include <sbuild/chroot/facet/fsunion.h> #endif // SBUILD_FEATURE_UNION #include <cassert> @@ -87,7 +87,7 @@ namespace sbuild clone->set_aliases(clone->get_aliases()); #ifdef SBUILD_FEATURE_UNION - clone->remove_facet<chroot_facet_union>(); + clone->remove_facet<fsunion>(); #endif // SBUILD_FEATURE_UNION clone->remove_facet<source_clonable>(); diff --git a/lib/sbuild/chroot/loopback.cc b/lib/sbuild/chroot/loopback.cc index 3e16e789..d09ecbcd 100644 --- a/lib/sbuild/chroot/loopback.cc +++ b/lib/sbuild/chroot/loopback.cc @@ -23,7 +23,7 @@ #include <sbuild/chroot/facet/source-clonable.h> #include <sbuild/chroot/facet/mountable.h> #ifdef SBUILD_FEATURE_UNION -#include "chroot-facet-union.h" +#include <sbuild/chroot/facet/fsunion.h> #endif // SBUILD_FEATURE_UNION #include "format-detail.h" #include "lock.h" @@ -49,7 +49,7 @@ namespace sbuild { add_facet(facet::mountable::create()); #ifdef SBUILD_FEATURE_UNION - add_facet(chroot_facet_union::create()); + add_facet(facet::fsunion::create()); #endif // SBUILD_FEATURE_UNION } |