diff options
author | Roger Leigh <rleigh@debian.org> | 2013-04-28 12:24:04 +0100 |
---|---|---|
committer | Roger Leigh <rleigh@debian.org> | 2013-05-04 17:17:17 +0100 |
commit | dc6bdbc920d8b3e141447453aeeecd6970cd68d2 (patch) | |
tree | bcd7656fe10eeaf386f776c6adfebfdbc8de2c3f /lib | |
parent | 176be0c58ce22af68b6661d1fe384ad8a59c5c9f (diff) | |
download | schroot-dc6bdbc920d8b3e141447453aeeecd6970cd68d2.tar.gz |
sbuild::chroot: Migrate btrfs-snapshot to storage facet
Diffstat (limited to 'lib')
-rw-r--r-- | lib/sbuild/Makefile.am | 2 | ||||
-rw-r--r-- | lib/sbuild/chroot/btrfs-snapshot.cc | 190 | ||||
-rw-r--r-- | lib/sbuild/chroot/btrfs-snapshot.h | 94 | ||||
-rw-r--r-- | lib/sbuild/chroot/facet/btrfs-snapshot.cc | 451 | ||||
-rw-r--r-- | lib/sbuild/chroot/facet/btrfs-snapshot.h | 267 | ||||
-rw-r--r-- | lib/sbuild/chroot/facet/session-clonable.cc | 10 |
6 files changed, 372 insertions, 642 deletions
diff --git a/lib/sbuild/Makefile.am b/lib/sbuild/Makefile.am index 85a120a2..986571a7 100644 --- a/lib/sbuild/Makefile.am +++ b/lib/sbuild/Makefile.am @@ -25,6 +25,7 @@ lib_sbuild_public_h_sources = \ lib/sbuild/chroot/custom.h \ lib/sbuild/chroot/directory.h \ lib/sbuild/chroot/directory-base.h \ + lib/sbuild/chroot/facet/btrfs-snapshot.cc \ lib/sbuild/chroot/facet/facet.h \ lib/sbuild/chroot/facet/directory-base.h \ lib/sbuild/chroot/facet/mountable.h \ @@ -115,6 +116,7 @@ lib_sbuild_public_cc_sources = \ lib/sbuild/chroot/custom.cc \ lib/sbuild/chroot/directory.cc \ lib/sbuild/chroot/directory-base.cc \ + lib/sbuild/chroot/facet/btrfs-snapshot.cc \ lib/sbuild/chroot/facet/facet.cc \ lib/sbuild/chroot/facet/directory-base.cc \ lib/sbuild/chroot/facet/mountable.cc \ diff --git a/lib/sbuild/chroot/btrfs-snapshot.cc b/lib/sbuild/chroot/btrfs-snapshot.cc index 60437e86..e497acd4 100644 --- a/lib/sbuild/chroot/btrfs-snapshot.cc +++ b/lib/sbuild/chroot/btrfs-snapshot.cc @@ -18,8 +18,9 @@ #include <config.h> -#include <chroot/btrfs-snapshot.h> +#include <sbuild/chroot/btrfs-snapshot.h> #include <sbuild/chroot/directory.h> +#include <sbuild/chroot/facet/btrfs-snapshot.h> #include <sbuild/chroot/facet/session.h> #include <sbuild/chroot/facet/session-clonable.h> #include <sbuild/chroot/facet/source-clonable.h> @@ -41,19 +42,13 @@ namespace sbuild { btrfs_snapshot::btrfs_snapshot (): - chroot(), - source_subvolume(), - snapshot_directory(), - snapshot_name() + chroot() { - add_facet(facet::source_clonable::create()); + add_facet(facet::btrfs_snapshot::create()); } btrfs_snapshot::btrfs_snapshot (const btrfs_snapshot& rhs): - chroot(rhs), - source_subvolume(rhs.source_subvolume), - snapshot_directory(rhs.snapshot_directory), - snapshot_name(rhs.snapshot_name) + chroot(rhs) { } @@ -97,180 +92,5 @@ namespace sbuild return clone; } - std::string const& - btrfs_snapshot::get_source_subvolume () const - { - return this->source_subvolume; - } - - void - btrfs_snapshot::set_source_subvolume (std::string const& source_subvolume) - { - if (!is_absname(source_subvolume)) - throw error(source_subvolume, DIRECTORY_ABS); - - this->source_subvolume = source_subvolume; - } - - std::string const& - btrfs_snapshot::get_snapshot_directory () const - { - return this->snapshot_directory; - } - - void - btrfs_snapshot::set_snapshot_directory (std::string const& snapshot_directory) - { - if (!is_absname(snapshot_directory)) - throw error(source_subvolume, DIRECTORY_ABS); - - this->snapshot_directory = snapshot_directory; - } - - std::string const& - btrfs_snapshot::get_snapshot_name () const - { - return this->snapshot_name; - } - - void - btrfs_snapshot::set_snapshot_name (std::string const& snapshot_name) - { - if (!is_absname(snapshot_name)) - throw error(source_subvolume, DIRECTORY_ABS); - - this->snapshot_name = snapshot_name; - } - - std::string const& - btrfs_snapshot::get_chroot_type () const - { - static const std::string type("btrfs-snapshot"); - - return type; - } - - std::string - btrfs_snapshot::get_path () const - { - return get_mount_location(); - } - - void - btrfs_snapshot::setup_env (chroot const& chroot, - environment& env) const - { - chroot::setup_env(chroot, env); - - env.add("CHROOT_BTRFS_SOURCE_SUBVOLUME", get_source_subvolume()); - env.add("CHROOT_BTRFS_SNAPSHOT_DIRECTORY", get_snapshot_directory()); - env.add("CHROOT_BTRFS_SNAPSHOT_NAME", get_snapshot_name()); - } - - void - btrfs_snapshot::setup_lock (chroot::setup_type type, - bool lock, - int status) - { - /* Create or unlink session information. */ - if ((type == SETUP_START && lock == true) || - (type == SETUP_STOP && lock == false && status == 0)) - { - bool start = (type == SETUP_START); - get_facet_strict<facet::session>()->setup_session_info(start); - } - } - - chroot::chroot::session_flags - btrfs_snapshot::get_session_flags (chroot const& chroot) const - { - session_flags flags = SESSION_NOFLAGS; - - if (get_facet<facet::session>()) - flags = flags | SESSION_PURGE; - - return flags; - } - - void - btrfs_snapshot::get_details (chroot const& chroot, - format_detail& detail) const - { - chroot::get_details(chroot, detail); - - if (!this->get_source_subvolume().empty()) - detail.add(_("Btrfs Source Subvolume"), get_source_subvolume()); - if (!this->get_snapshot_directory().empty()) - detail.add(_("Btrfs Snapshot Directory"), get_snapshot_directory()); - if (!this->get_snapshot_name().empty()) - detail.add(_("Btrfs Snapshot Name"), get_snapshot_name()); - } - - void - btrfs_snapshot::get_used_keys (string_list& used_keys) const - { - chroot::get_used_keys(used_keys); - - used_keys.push_back("btrfs-source-subvolume"); - used_keys.push_back("btrfs-snapshot-directory"); - used_keys.push_back("btrfs-snapshot-name"); - } - - void - btrfs_snapshot::get_keyfile (chroot const& chroot, - keyfile& keyfile) const - { - chroot::get_keyfile(chroot, keyfile); - - bool issession = static_cast<bool>(get_facet<facet::session>()); - - if (!issession) - keyfile::set_object_value(*this, - &btrfs_snapshot::get_source_subvolume, - keyfile, get_name(), - "btrfs-source-subvolume"); - - if (!issession) - keyfile::set_object_value(*this, - &btrfs_snapshot::get_snapshot_directory, - keyfile, get_name(), - "btrfs-snapshot-directory"); - - if (issession) - keyfile::set_object_value(*this, - &btrfs_snapshot::get_snapshot_name, - keyfile, get_name(), - "btrfs-snapshot-name"); - } - - void - btrfs_snapshot::set_keyfile (chroot& chroot, - keyfile const& keyfile) - { - chroot::set_keyfile(chroot, keyfile); - - bool issession = static_cast<bool>(get_facet<facet::session>()); - - keyfile::get_object_value(*this, &btrfs_snapshot::set_source_subvolume, - keyfile, get_name(), "btrfs-source-subvolume", - issession ? - keyfile::PRIORITY_DISALLOWED : - keyfile::PRIORITY_REQUIRED - ); // Only needed for creating snapshot, not using snapshot - - keyfile::get_object_value(*this, &btrfs_snapshot::set_snapshot_directory, - keyfile, get_name(), "btrfs-snapshot-directory", - issession ? - keyfile::PRIORITY_DISALLOWED : - keyfile::PRIORITY_REQUIRED - ); // Only needed for creating snapshot, not using snapshot - - keyfile::get_object_value(*this, &btrfs_snapshot::set_snapshot_name, - keyfile, get_name(), "btrfs-snapshot-name", - issession ? - keyfile::PRIORITY_REQUIRED : - keyfile::PRIORITY_DISALLOWED); - } - } } diff --git a/lib/sbuild/chroot/btrfs-snapshot.h b/lib/sbuild/chroot/btrfs-snapshot.h index 81b64387..4e424c86 100644 --- a/lib/sbuild/chroot/btrfs-snapshot.h +++ b/lib/sbuild/chroot/btrfs-snapshot.h @@ -56,100 +56,6 @@ namespace sbuild virtual chroot::ptr clone_source () const; - - /** - * Get the source subvolume path. This is used by "btrfs - * subvolume snapshot". - * - * @returns the source subvolume. - */ - std::string const& - get_source_subvolume () const; - - /** - * Set the source subvolume path. This is used by "btrfs - * subvolume snapshot". - * - * @param source_subvolume the source subvolume. - */ - void - set_source_subvolume (std::string const& source_subvolume); - - /** - * Get the snapshot directory. - * - * @returns the directory. - */ - std::string const& - get_snapshot_directory () const; - - /** - * Set the snapshot directory. - * - * @param snapshot_directory the snapshot directory. - */ - void - set_snapshot_directory (std::string const& snapshot_directory); - - /** - * Get the snapshot name. This is used by "btrfs subvolume - * snapshot", and is the full path to the snapshot. - * - * @returns the name. - */ - std::string const& - get_snapshot_name () const; - - /** - * Set the snapshot name. This is used by "btrfs subvolume - * snapshot", and is the full path to the snapshot. - * - * @param snapshot_name the snapshot name. - */ - void - set_snapshot_name (std::string const& snapshot_name); - - virtual std::string const& - get_chroot_type () const; - - virtual std::string - get_path () const; - - virtual void - setup_env (chroot const& chroot, - environment& env) const; - - virtual session_flags - get_session_flags (chroot const& chroot) const; - - protected: - virtual void - setup_lock (chroot::setup_type type, - bool lock, - int status); - - 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: - /// Btrfs source subvolume - std::string source_subvolume; - /// Btrfs snapshot path - std::string snapshot_directory; - /// Btrfs snapshot name - std::string snapshot_name; }; } diff --git a/lib/sbuild/chroot/facet/btrfs-snapshot.cc b/lib/sbuild/chroot/facet/btrfs-snapshot.cc index 407b70a3..f0c2ba3b 100644 --- a/lib/sbuild/chroot/facet/btrfs-snapshot.cc +++ b/lib/sbuild/chroot/facet/btrfs-snapshot.cc @@ -18,13 +18,12 @@ #include <config.h> -#include <chroot/btrfs-snapshot.h> -#include <sbuild/chroot/directory.h> -#include <sbuild/chroot/facet/session.h> +#include <sbuild/chroot/facet/btrfs-snapshot.h> +#include <sbuild/chroot/facet/mountable.h> #include <sbuild/chroot/facet/session-clonable.h> +#include <sbuild/chroot/facet/session.h> #include <sbuild/chroot/facet/source-clonable.h> #include "format-detail.h" -#include "lock.h" #include <cassert> #include <cerrno> @@ -39,238 +38,224 @@ namespace sbuild { namespace chroot { - - btrfs_snapshot::btrfs_snapshot (): - chroot(), - source_subvolume(), - snapshot_directory(), - snapshot_name() - { - add_facet(facet::source_clonable::create()); - } - - btrfs_snapshot::btrfs_snapshot (const btrfs_snapshot& rhs): - chroot(rhs), - source_subvolume(rhs.source_subvolume), - snapshot_directory(rhs.snapshot_directory), - snapshot_name(rhs.snapshot_name) - { - } - - btrfs_snapshot::~btrfs_snapshot () - { - } - - chroot::chroot::ptr - btrfs_snapshot::clone () const - { - return ptr(new btrfs_snapshot(*this)); - } - - chroot::chroot::ptr - btrfs_snapshot::clone_session (std::string const& session_id, - std::string const& alias, - std::string const& user, - bool root) const - { - facet::session_clonable::const_ptr psess - (get_facet<facet::session_clonable>()); - assert(psess); - - ptr session(new btrfs_snapshot(*this)); - psess->clone_session_setup(*this, session, session_id, alias, user, root); - - return session; - } - - chroot::chroot::ptr - btrfs_snapshot::clone_source () const - { - ptr clone(new directory(*this)); - - facet::source_clonable::const_ptr psrc - (get_facet<facet::source_clonable>()); - assert(psrc); - - psrc->clone_source_setup(*this, clone); - - return clone; - } - - std::string const& - btrfs_snapshot::get_source_subvolume () const + namespace facet { - return this->source_subvolume; - } - void - btrfs_snapshot::set_source_subvolume (std::string const& source_subvolume) - { - if (!is_absname(source_subvolume)) - throw error(source_subvolume, DIRECTORY_ABS); + btrfs_snapshot::btrfs_snapshot (): + storage(), + source_subvolume(), + snapshot_directory(), + snapshot_name() + { + } + + btrfs_snapshot::btrfs_snapshot (const btrfs_snapshot& rhs): + storage(rhs), + source_subvolume(rhs.source_subvolume), + snapshot_directory(rhs.snapshot_directory), + snapshot_name(rhs.snapshot_name) + { + } + + btrfs_snapshot::~btrfs_snapshot () + { + } + + void + btrfs_snapshot::set_chroot (chroot& chroot) + { + storage::set_chroot(chroot); + if (!owner->get_facet<source_clonable>()) + owner->add_facet(source_clonable::create()); + } + + std::string const& + btrfs_snapshot::get_name () const + { + static const std::string name("btrfs-snapshot"); + + return name; + } + + btrfs_snapshot::ptr + btrfs_snapshot::create () + { + return ptr(new btrfs_snapshot()); + } + + facet::ptr + btrfs_snapshot::clone () const + { + return ptr(new btrfs_snapshot(*this)); + } + + std::string const& + btrfs_snapshot::get_source_subvolume () const + { + return this->source_subvolume; + } + + void + btrfs_snapshot::set_source_subvolume (std::string const& source_subvolume) + { + if (!is_absname(source_subvolume)) + throw error(source_subvolume, chroot::DIRECTORY_ABS); + + this->source_subvolume = source_subvolume; + } + + std::string const& + btrfs_snapshot::get_snapshot_directory () const + { + return this->snapshot_directory; + } + + void + btrfs_snapshot::set_snapshot_directory (std::string const& snapshot_directory) + { + if (!is_absname(snapshot_directory)) + throw error(source_subvolume, chroot::DIRECTORY_ABS); + + this->snapshot_directory = snapshot_directory; + } + + std::string const& + btrfs_snapshot::get_snapshot_name () const + { + return this->snapshot_name; + } + + void + btrfs_snapshot::set_snapshot_name (std::string const& snapshot_name) + { + if (!is_absname(snapshot_name)) + throw error(source_subvolume, chroot::DIRECTORY_ABS); + + this->snapshot_name = snapshot_name; + } + + std::string + btrfs_snapshot::get_path () const + { + return owner->get_mount_location(); + } + + void + btrfs_snapshot::setup_env (chroot const& chroot, + environment& env) const + { + storage::setup_env(chroot, env); + + env.add("CHROOT_BTRFS_SOURCE_SUBVOLUME", get_source_subvolume()); + env.add("CHROOT_BTRFS_SNAPSHOT_DIRECTORY", get_snapshot_directory()); + env.add("CHROOT_BTRFS_SNAPSHOT_NAME", get_snapshot_name()); + } + + void + btrfs_snapshot::setup_lock (chroot::setup_type type, + bool lock, + int status) + { + /* Create or unlink session information. */ + if ((type == chroot::SETUP_START && lock == true) || + (type == chroot::SETUP_STOP && lock == false && status == 0)) + { + bool start = (type == chroot::SETUP_START); + owner->get_facet_strict<session>()->setup_session_info(start); + } + } + + chroot::session_flags + btrfs_snapshot::get_session_flags (chroot const& chroot) const + { + chroot::session_flags flags = chroot::SESSION_NOFLAGS; + + if (owner->get_facet<session>()) + flags = flags | chroot::SESSION_PURGE; + + return flags; + } + + void + btrfs_snapshot::get_details (chroot const& chroot, + format_detail& detail) const + { + storage::get_details(chroot, detail); + + if (!this->get_source_subvolume().empty()) + detail.add(_("Btrfs Source Subvolume"), get_source_subvolume()); + if (!this->get_snapshot_directory().empty()) + detail.add(_("Btrfs Snapshot Directory"), get_snapshot_directory()); + if (!this->get_snapshot_name().empty()) + detail.add(_("Btrfs Snapshot Name"), get_snapshot_name()); + } + + void + btrfs_snapshot::get_used_keys (string_list& used_keys) const + { + storage::get_used_keys(used_keys); + + used_keys.push_back("btrfs-source-subvolume"); + used_keys.push_back("btrfs-snapshot-directory"); + used_keys.push_back("btrfs-snapshot-name"); + } + + void + btrfs_snapshot::get_keyfile (chroot const& chroot, + keyfile& keyfile) const + { + storage::get_keyfile(chroot, keyfile); + + bool issession = static_cast<bool>(owner->get_facet<session>()); + + if (!issession) + keyfile::set_object_value(*this, + &btrfs_snapshot::get_source_subvolume, + keyfile, chroot.get_name(), + "btrfs-source-subvolume"); + + if (!issession) + keyfile::set_object_value(*this, + &btrfs_snapshot::get_snapshot_directory, + keyfile, chroot.get_name(), + "btrfs-snapshot-directory"); + + if (issession) + keyfile::set_object_value(*this, + &btrfs_snapshot::get_snapshot_name, + keyfile, chroot.get_name(), + "btrfs-snapshot-name"); + } + + void + btrfs_snapshot::set_keyfile (chroot& chroot, + keyfile const& keyfile) + { + storage::set_keyfile(chroot, keyfile); + + bool issession = static_cast<bool>(owner->get_facet<session>()); + + keyfile::get_object_value(*this, &btrfs_snapshot::set_source_subvolume, + keyfile, chroot.get_name(), "btrfs-source-subvolume", + issession ? + keyfile::PRIORITY_DISALLOWED : + keyfile::PRIORITY_REQUIRED + ); // Only needed for creating snapshot, not using snapshot + + keyfile::get_object_value(*this, &btrfs_snapshot::set_snapshot_directory, + keyfile, chroot.get_name(), "btrfs-snapshot-directory", + issession ? + keyfile::PRIORITY_DISALLOWED : + keyfile::PRIORITY_REQUIRED + ); // Only needed for creating snapshot, not using snapshot + + keyfile::get_object_value(*this, &btrfs_snapshot::set_snapshot_name, + keyfile, chroot.get_name(), "btrfs-snapshot-name", + issession ? + keyfile::PRIORITY_REQUIRED : + keyfile::PRIORITY_DISALLOWED); + } - this->source_subvolume = source_subvolume; - } - - std::string const& - btrfs_snapshot::get_snapshot_directory () const - { - return this->snapshot_directory; - } - - void - btrfs_snapshot::set_snapshot_directory (std::string const& snapshot_directory) - { - if (!is_absname(snapshot_directory)) - throw error(source_subvolume, DIRECTORY_ABS); - - this->snapshot_directory = snapshot_directory; - } - - std::string const& - btrfs_snapshot::get_snapshot_name () const - { - return this->snapshot_name; } - - void - btrfs_snapshot::set_snapshot_name (std::string const& snapshot_name) - { - if (!is_absname(snapshot_name)) - throw error(source_subvolume, DIRECTORY_ABS); - - this->snapshot_name = snapshot_name; - } - - std::string const& - btrfs_snapshot::get_chroot_type () const - { - static const std::string type("btrfs-snapshot"); - - return type; - } - - std::string - btrfs_snapshot::get_path () const - { - return get_mount_location(); - } - - void - btrfs_snapshot::setup_env (chroot const& chroot, - environment& env) const - { - chroot::setup_env(chroot, env); - - env.add("CHROOT_BTRFS_SOURCE_SUBVOLUME", get_source_subvolume()); - env.add("CHROOT_BTRFS_SNAPSHOT_DIRECTORY", get_snapshot_directory()); - env.add("CHROOT_BTRFS_SNAPSHOT_NAME", get_snapshot_name()); - } - - void - btrfs_snapshot::setup_lock (chroot::setup_type type, - bool lock, - int status) - { - /* Create or unlink session information. */ - if ((type == SETUP_START && lock == true) || - (type == SETUP_STOP && lock == false && status == 0)) - { - bool start = (type == SETUP_START); - setup_session_info(start); - } - } - - chroot::chroot::session_flags - btrfs_snapshot::get_session_flags (chroot const& chroot) const - { - session_flags flags = SESSION_NOFLAGS; - - if (get_facet<facet::session>()) - flags = flags | SESSION_PURGE; - - return flags; - } - - void - btrfs_snapshot::get_details (chroot const& chroot, - format_detail& detail) const - { - chroot::get_details(chroot, detail); - - if (!this->get_source_subvolume().empty()) - detail.add(_("Btrfs Source Subvolume"), get_source_subvolume()); - if (!this->get_snapshot_directory().empty()) - detail.add(_("Btrfs Snapshot Directory"), get_snapshot_directory()); - if (!this->get_snapshot_name().empty()) - detail.add(_("Btrfs Snapshot Name"), get_snapshot_name()); - } - - void - btrfs_snapshot::get_used_keys (string_list& used_keys) const - { - chroot::get_used_keys(used_keys); - - used_keys.push_back("btrfs-source-subvolume"); - used_keys.push_back("btrfs-snapshot-directory"); - used_keys.push_back("btrfs-snapshot-name"); - } - - void - btrfs_snapshot::get_keyfile (chroot const& chroot, - keyfile& keyfile) const - { - chroot::get_keyfile(chroot, keyfile); - - bool issession = static_cast<bool>(get_facet<facet::session>()); - - if (!issession) - keyfile::set_object_value(*this, - &btrfs_snapshot::get_source_subvolume, - keyfile, get_name(), - "btrfs-source-subvolume"); - - if (!issession) - keyfile::set_object_value(*this, - &btrfs_snapshot::get_snapshot_directory, - keyfile, get_name(), - "btrfs-snapshot-directory"); - - if (issession) - keyfile::set_object_value(*this, - &btrfs_snapshot::get_snapshot_name, - keyfile, get_name(), - "btrfs-snapshot-name"); - } - - void - btrfs_snapshot::set_keyfile (chroot& chroot, - keyfile const& keyfile) - { - chroot::set_keyfile(chroot, keyfile); - - bool issession = static_cast<bool>(get_facet<facet::session>()); - - keyfile::get_object_value(*this, &btrfs_snapshot::set_source_subvolume, - keyfile, get_name(), "btrfs-source-subvolume", - issession ? - keyfile::PRIORITY_DISALLOWED : - keyfile::PRIORITY_REQUIRED - ); // Only needed for creating snapshot, not using snapshot - - keyfile::get_object_value(*this, &btrfs_snapshot::set_snapshot_directory, - keyfile, get_name(), "btrfs-snapshot-directory", - issession ? - keyfile::PRIORITY_DISALLOWED : - keyfile::PRIORITY_REQUIRED - ); // Only needed for creating snapshot, not using snapshot - - keyfile::get_object_value(*this, &btrfs_snapshot::set_snapshot_name, - keyfile, get_name(), "btrfs-snapshot-name", - issession ? - keyfile::PRIORITY_REQUIRED : - keyfile::PRIORITY_DISALLOWED); - } - } } diff --git a/lib/sbuild/chroot/facet/btrfs-snapshot.h b/lib/sbuild/chroot/facet/btrfs-snapshot.h index 81b64387..5f92c9ed 100644 --- a/lib/sbuild/chroot/facet/btrfs-snapshot.h +++ b/lib/sbuild/chroot/facet/btrfs-snapshot.h @@ -16,146 +16,163 @@ * *********************************************************************/ -#ifndef SBUILD_CHROOT_BTRFS_SNAPSHOT_H -#define SBUILD_CHROOT_BTRFS_SNAPSHOT_H +#ifndef SBUILD_CHROOT_FACET_BTRFS_SNAPSHOT_H +#define SBUILD_CHROOT_FACET_BTRFS_SNAPSHOT_H #include <sbuild/chroot/chroot.h> +#include <sbuild/chroot/facet/storage.h> namespace sbuild { namespace chroot { - /** - * A chroot stored on an BTRFS logical volume (LV). - * - * A snapshot LV will be created and mounted on demand. - */ - class btrfs_snapshot : public chroot + namespace facet { - protected: - /// The constructor. - btrfs_snapshot (); - - /// The copy constructor. - btrfs_snapshot (const btrfs_snapshot& rhs); - - friend class chroot; - - public: - /// The destructor. - virtual ~btrfs_snapshot (); - - virtual chroot::ptr - clone () const; - - virtual chroot::ptr - clone_session (std::string const& session_id, - std::string const& alias, - std::string const& user, - bool root) const; - - virtual chroot::ptr - clone_source () const; - - /** - * Get the source subvolume path. This is used by "btrfs - * subvolume snapshot". - * - * @returns the source subvolume. - */ - std::string const& - get_source_subvolume () const; /** - * Set the source subvolume path. This is used by "btrfs - * subvolume snapshot". + * A chroot stored on an BTRFS subvolume. * - * @param source_subvolume the source subvolume. + * A snapshot subvolume will be created and mounted on demand. */ - void - set_source_subvolume (std::string const& source_subvolume); - - /** - * Get the snapshot directory. - * - * @returns the directory. - */ - std::string const& - get_snapshot_directory () const; - - /** - * Set the snapshot directory. - * - * @param snapshot_directory the snapshot directory. - */ - void - set_snapshot_directory (std::string const& snapshot_directory); - - /** - * Get the snapshot name. This is used by "btrfs subvolume - * snapshot", and is the full path to the snapshot. - * - * @returns the name. - */ - std::string const& - get_snapshot_name () const; - - /** - * Set the snapshot name. This is used by "btrfs subvolume - * snapshot", and is the full path to the snapshot. - * - * @param snapshot_name the snapshot name. - */ - void - set_snapshot_name (std::string const& snapshot_name); - - virtual std::string const& - get_chroot_type () const; - - virtual std::string - get_path () const; - - virtual void - setup_env (chroot const& chroot, - environment& env) const; - - virtual session_flags - get_session_flags (chroot const& chroot) const; - - protected: - virtual void - setup_lock (chroot::setup_type type, - bool lock, - int status); - - 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: - /// Btrfs source subvolume - std::string source_subvolume; - /// Btrfs snapshot path - std::string snapshot_directory; - /// Btrfs snapshot name - std::string snapshot_name; - }; - + class btrfs_snapshot : public storage + { + public: + /// Exception type. + typedef chroot::error error; + + /// A shared_ptr to a chroot facet object. + typedef std::shared_ptr<btrfs_snapshot> ptr; + + /// A shared_ptr to a const chroot facet object. + typedef std::shared_ptr<const btrfs_snapshot> const_ptr; + + protected: + /// The constructor. + btrfs_snapshot (); + + /// The copy constructor. + btrfs_snapshot (const btrfs_snapshot& rhs); + + void + set_chroot (chroot& chroot); + + friend class chroot; + + public: + /// The destructor. + virtual ~btrfs_snapshot (); + + virtual std::string const& + get_name () const; + + /** + * Create a chroot facet. + * + * @returns a shared_ptr to the new chroot facet. + */ + static ptr + create (); + + facet::ptr + clone () const; + + /** + * Get the source subvolume path. This is used by "btrfs + * subvolume snapshot". + * + * @returns the source subvolume. + */ + std::string const& + get_source_subvolume () const; + + /** + * Set the source subvolume path. This is used by "btrfs + * subvolume snapshot". + * + * @param source_subvolume the source subvolume. + */ + void + set_source_subvolume (std::string const& source_subvolume); + + /** + * Get the snapshot directory. + * + * @returns the directory. + */ + std::string const& + get_snapshot_directory () const; + + /** + * Set the snapshot directory. + * + * @param snapshot_directory the snapshot directory. + */ + void + set_snapshot_directory (std::string const& snapshot_directory); + + /** + * Get the snapshot name. This is used by "btrfs subvolume + * snapshot", and is the full path to the snapshot. + * + * @returns the name. + */ + std::string const& + get_snapshot_name () const; + + /** + * Set the snapshot name. This is used by "btrfs subvolume + * snapshot", and is the full path to the snapshot. + * + * @param snapshot_name the snapshot name. + */ + void + set_snapshot_name (std::string const& snapshot_name); + + virtual std::string + get_path () const; + + virtual void + setup_env (chroot const& chroot, + environment& env) const; + + virtual chroot::session_flags + get_session_flags (chroot const& chroot) const; + + protected: + virtual void + setup_lock (chroot::setup_type type, + bool lock, + int status); + + 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: + /// Btrfs source subvolume + std::string source_subvolume; + /// Btrfs snapshot path + std::string snapshot_directory; + /// Btrfs snapshot name + std::string snapshot_name; + }; + + } } } -#endif /* SBUILD_CHROOT_BTRFS_SNAPSHOT_H */ +#endif /* SBUILD_CHROOT_FACET_BTRFS_SNAPSHOT_H */ /* * Local Variables: diff --git a/lib/sbuild/chroot/facet/session-clonable.cc b/lib/sbuild/chroot/facet/session-clonable.cc index bc347631..6b6efc18 100644 --- a/lib/sbuild/chroot/facet/session-clonable.cc +++ b/lib/sbuild/chroot/facet/session-clonable.cc @@ -34,7 +34,7 @@ #include <sbuild/chroot/loopback.h> #endif // SBUILD_FEATURE_LOOPBACK #ifdef SBUILD_FEATURE_BTRFSSNAP -#include <sbuild/chroot/btrfs-snapshot.h> +#include <sbuild/chroot/facet/btrfs-snapshot.h> #endif // SBUILD_FEATURE_BTRFSSNAP #ifdef SBUILD_FEATURE_UNION #include <sbuild/chroot/facet/fsunion.h> @@ -192,12 +192,12 @@ namespace sbuild #ifdef SBUILD_FEATURE_BTRFSSNAP /* Btrfs snapshots need the snapshot name specifying. */ - std::shared_ptr<btrfs_snapshot> btrfs_snapshot(std::dynamic_pointer_cast<btrfs_snapshot>(clone)); - if (btrfs_snapshot && !btrfs_snapshot->get_snapshot_directory().empty()) + btrfs_snapshot::ptr btrfs_snap(clone->get_facet<btrfs_snapshot>()); + if (btrfs_snap && !btrfs_snap->get_snapshot_directory().empty()) { - std::string snapname(btrfs_snapshot->get_snapshot_directory()); + std::string snapname(btrfs_snap->get_snapshot_directory()); snapname += "/" + clone->get_name(); - btrfs_snapshot->set_snapshot_name(snapname); + btrfs_snap->set_snapshot_name(snapname); } #endif // SBUILD_FEATURE_BTRFSSNAP |