sbuild  1.6.10
Public Member Functions | Protected Member Functions | Private Attributes | Friends | List of all members
sbuild::chroot_btrfs_snapshot Class Reference

A chroot stored on an BTRFS logical volume (LV). More...

#include <sbuild-chroot-btrfs-snapshot.h>

+ Inheritance diagram for sbuild::chroot_btrfs_snapshot:
+ Collaboration diagram for sbuild::chroot_btrfs_snapshot:

Public Member Functions

virtual ~chroot_btrfs_snapshot ()
 The destructor.
 
virtual chroot::ptr clone () const
 Copy the chroot. More...
 
virtual chroot::ptr clone_session (std::string const &session_id, std::string const &alias, std::string const &user, bool root) const
 Create a session chroot. More...
 
virtual chroot::ptr clone_source () const
 Create a source chroot. More...
 
std::string const & get_source_subvolume () const
 Get the source subvolume path. More...
 
void set_source_subvolume (std::string const &source_subvolume)
 Set the source subvolume path. More...
 
std::string const & get_snapshot_directory () const
 Get the snapshot directory. More...
 
void set_snapshot_directory (std::string const &snapshot_directory)
 Set the snapshot directory. More...
 
std::string const & get_snapshot_name () const
 Get the snapshot name. More...
 
void set_snapshot_name (std::string const &snapshot_name)
 Set the snapshot name. More...
 
virtual std::string const & get_chroot_type () const
 Get the type of the chroot. More...
 
virtual std::string get_path () const
 Get the path to the chroot. More...
 
virtual void setup_env (chroot const &chroot, environment &env) const
 Set environment. More...
 
virtual session_flags get_session_flags (chroot const &chroot) const
 Get the session flags of the chroot. More...
 
- Public Member Functions inherited from sbuild::chroot
virtual ~chroot ()
 The destructor.
 
std::string const & get_name () const
 Get the name of the chroot. More...
 
void set_name (std::string const &name)
 Set the name of the chroot. More...
 
std::string const & get_description () const
 Get the description of the chroot. More...
 
void set_description (std::string const &description)
 Set the description of the chroot. More...
 
std::string const & get_mount_location () const
 Get the mount location of the chroot. More...
 
void set_mount_location (std::string const &location)
 Set the mount location of the chroot. More...
 
string_list const & get_users () const
 Get the users allowed to access the chroot. More...
 
void set_users (string_list const &users)
 Set the users allowed to access the chroot. More...
 
string_list const & get_groups () const
 Get the groups allowed to access the chroot. More...
 
void set_groups (string_list const &groups)
 Set the users allowed to access the chroot. More...
 
string_list const & get_root_users () const
 Get the users allowed to access the chroot as root. More...
 
void set_root_users (string_list const &users)
 Set the users allowed to access the chroot as root. More...
 
string_list const & get_root_groups () const
 Get the groups allowed to access the chroot as root. More...
 
void set_root_groups (string_list const &groups)
 Set the groups allowed to access the chroot as root. More...
 
string_list const & get_aliases () const
 Get the aliases of the chroot. More...
 
void set_aliases (string_list const &aliases)
 Set the aliases of the chroot. More...
 
bool get_preserve_environment () const
 Check if the environment should be preserved in the chroot. More...
 
void set_preserve_environment (bool preserve_environment)
 Set if the environment should be preserved in the chroot. More...
 
std::string const & get_default_shell () const
 Get default shell. More...
 
void set_default_shell (std::string const &default_shell)
 Set the default shell. More...
 
regex const & get_environment_filter () const
 Get the environment filter of the chroot. More...
 
void set_environment_filter (regex const &environment_filter)
 Set the environment filter of the chroot. More...
 
bool get_active () const
 Get the activity status of the chroot. More...
 
bool get_original () const
 Get the originality of the chroot. More...
 
void set_original (bool original)
 Set the originality of the chroot. More...
 
bool get_run_setup_scripts () const
 Check if chroot setup scripts will be run. More...
 
std::string const & get_script_config () const
 Get the script configuration file for the chroot. More...
 
void set_script_config (std::string const &script_config)
 Set the script configuration file for the chroot. More...
 
std::string const & get_profile () const
 Get the configuration profile for the chroot. More...
 
void set_profile (std::string const &profile)
 Set configuration profile for the chroot. More...
 
string_list const & get_command_prefix () const
 Get the command_prefix for the chroot. More...
 
void set_command_prefix (string_list const &command_prefix)
 Set the command_prefix for the chroot. More...
 
verbosity get_verbosity () const
 Get the message verbosity. More...
 
const char * get_verbosity_string () const
 Get the message verbosity as a readable string. More...
 
void set_verbosity (verbosity verbosity)
 Set the message verbosity. More...
 
void set_verbosity (std::string const &verbosity)
 Set the message verbosity. More...
 
void setup_env (environment &env) const
 Set environment. More...
 
void lock (setup_type type)
 Lock a chroot during setup. More...
 
void unlock (setup_type type, int status)
 Unlock a chroot during setup. More...
 
template<typename T >
std::shared_ptr< T > get_facet ()
 Get a chroot facet. More...
 
template<typename T >
const std::shared_ptr< const T > get_facet () const
 Get a chroot facet. More...
 
template<typename T >
void add_facet (std::shared_ptr< T > facet)
 Add a chroot facet. More...
 
template<typename T >
void remove_facet ()
 Remove a chroot facet. More...
 
template<typename T >
void remove_facet (std::shared_ptr< T > facet)
 Remove a chroot facet. More...
 
template<typename T >
void replace_facet (std::shared_ptr< T > facet)
 Replace an existing chroot facet with a new facet. More...
 
string_list list_facets () const
 List all registered chroot facets. More...
 
session_flags get_session_flags () const
 Get the session flags of the chroot. More...
 
void get_details (format_detail &detail) const
 Get detailed information about the chroot for output. More...
 
void print_details (std::ostream &stream) const
 Print detailed information about the chroot to a stream. More...
 
void get_keyfile (keyfile &keyfile) const
 Copy the chroot properties into a keyfile. More...
 
void set_keyfile (keyfile const &keyfile)
 Set the chroot properties from a keyfile. More...
 

Protected Member Functions

 chroot_btrfs_snapshot ()
 The constructor.
 
 chroot_btrfs_snapshot (const chroot_btrfs_snapshot &rhs)
 The copy constructor.
 
virtual void setup_lock (chroot::setup_type type, bool lock, int status)
 Unlock a chroot during setup. More...
 
virtual void get_details (chroot const &chroot, format_detail &detail) const
 Get detailed information about the chroot for output. More...
 
virtual void get_keyfile (chroot const &chroot, keyfile &keyfile) const
 Copy the chroot properties into a keyfile. More...
 
virtual void set_keyfile (chroot &chroot, keyfile const &keyfile, string_list &used_keys)
 Set the chroot properties from a keyfile. More...
 
- Protected Member Functions inherited from sbuild::chroot
 chroot ()
 The constructor.
 
 chroot (const chroot &rhs)
 The copy constructor. More...
 
void set_run_setup_scripts (bool run_setup_scripts)
 Set whether chroot setup scripts will be run. More...
 
virtual void setup_session_info (bool start)
 Set up persistent session information. More...
 

Private Attributes

std::string source_subvolume
 Btrfs source subvolume.
 
std::string snapshot_directory
 Btrfs snapshot path.
 
std::string snapshot_name
 Btrfs snapshot name.
 

Friends

class chroot
 

Additional Inherited Members

- Public Types inherited from sbuild::chroot
enum  setup_type { SETUP_START, SETUP_RECOVER, SETUP_STOP }
 Type of setup to perform. More...
 
enum  session_flags {
  SESSION_NOFLAGS = 0, SESSION_CREATE = 1 << 0, SESSION_CLONE = 1 << 1, SESSION_PURGE = 1 << 2,
  SESSION_SOURCE = 1 << 3
}
 Chroot session properties. More...
 
enum  verbosity { VERBOSITY_QUIET, VERBOSITY_NORMAL, VERBOSITY_VERBOSE }
 Message verbosity. More...
 
enum  error_code {
  CHROOT_CREATE, CHROOT_DEVICE, CHROOT_TYPE, DEVICE_ABS,
  DEVICE_LOCK, DEVICE_NOTBLOCK, DEVICE_UNLOCK, DIRECTORY_ABS,
  FACET_INVALID, FACET_PRESENT, FILE_ABS, FILE_LOCK,
  FILE_NOTREG, FILE_OWNER, FILE_PERMS, FILE_UNLOCK,
  LOCATION_ABS, NAME_INVALID, SCRIPT_CONFIG_CV, SESSION_UNLINK,
  SESSION_WRITE, VERBOSITY_INVALID
}
 Error codes. More...
 
typedef custom_error< error_codeerror
 Exception type.
 
typedef std::shared_ptr< chrootptr
 A shared_ptr to a chroot object.
 
typedef std::shared_ptr< const chrootconst_ptr
 A shared_ptr to a const chroot object.
 
- Static Public Member Functions inherited from sbuild::chroot
static ptr create (std::string const &type)
 Create a chroot. More...
 

Detailed Description

A chroot stored on an BTRFS logical volume (LV).

A snapshot LV will be created and mounted on demand.

Member Function Documentation

sbuild::chroot::ptr chroot_btrfs_snapshot::clone ( ) const
virtual

Copy the chroot.

This is a virtual copy constructor.

Returns
a shared_ptr to the new copy of the chroot.

Implements sbuild::chroot.

References chroot_btrfs_snapshot().

Referenced by clone_source().

+ Here is the caller graph for this function:

sbuild::chroot::ptr chroot_btrfs_snapshot::clone_session ( std::string const &  session_id,
std::string const &  alias,
std::string const &  user,
bool  root 
) const
virtual

Create a session chroot.

Parameters
session_idthe identifier (session_id) for the new session.
aliasused to initially identify the chroot.
userthe user creating the session.
roottrue if the user has root access, otherwise false.
Returns
a session chroot.

Implements sbuild::chroot.

References chroot_btrfs_snapshot().

sbuild::chroot::ptr chroot_btrfs_snapshot::clone_source ( ) const
virtual

Create a source chroot.

Returns
a source chroot.

Implements sbuild::chroot.

References clone().

std::string const & chroot_btrfs_snapshot::get_chroot_type ( ) const
virtual

Get the type of the chroot.

Returns
the chroot type.

Implements sbuild::chroot.

void chroot_btrfs_snapshot::get_details ( chroot const &  chroot,
format_detail detail 
) const
protectedvirtual

Get detailed information about the chroot for output.

Parameters
chrootthe chroot to use.
detailthe details to output to.

Implements sbuild::chroot.

References sbuild::_(), sbuild::format_detail::add(), sbuild::chroot::get_details(), get_snapshot_directory(), get_snapshot_name(), and get_source_subvolume().

void chroot_btrfs_snapshot::get_keyfile ( chroot const &  chroot,
keyfile keyfile 
) const
protectedvirtual

Copy the chroot properties into a keyfile.

The keyfile group with the name of the chroot will be set; if it already exists, it will be removed before setting it.

Parameters
chrootthe chroot to use.
keyfilethe keyfile to use.

Implements sbuild::chroot.

References sbuild::chroot::get_keyfile(), sbuild::chroot::get_name(), get_snapshot_directory(), get_snapshot_name(), get_source_subvolume(), and sbuild::basic_keyfile< K, P >::set_object_value().

std::string chroot_btrfs_snapshot::get_path ( ) const
virtual

Get the path to the chroot.

This is the absolute path to the root of the chroot, and is typically the same as the mount location and location concatenated together, but is overridden by the chroot type if required.

Returns
the path.

Implements sbuild::chroot.

References sbuild::chroot::get_mount_location().

sbuild::chroot::session_flags chroot_btrfs_snapshot::get_session_flags ( chroot const &  chroot) const
virtual

Get the session flags of the chroot.

These determine how the Session controlling the chroot will operate.

Parameters
chrootthe chroot to use.
Returns
the session flags.

Implements sbuild::chroot.

References sbuild::chroot::SESSION_NOFLAGS, and sbuild::chroot::SESSION_PURGE.

std::string const & chroot_btrfs_snapshot::get_snapshot_directory ( ) const

Get the snapshot directory.

Returns
the directory.

References snapshot_directory.

Referenced by get_details(), get_keyfile(), and setup_env().

+ Here is the caller graph for this function:

std::string const & chroot_btrfs_snapshot::get_snapshot_name ( ) const

Get the snapshot name.

This is used by "btrfs subvolume snapshot", and is the full path to the snapshot.

Returns
the name.

References snapshot_name.

Referenced by get_details(), get_keyfile(), and setup_env().

+ Here is the caller graph for this function:

std::string const & chroot_btrfs_snapshot::get_source_subvolume ( ) const

Get the source subvolume path.

This is used by "btrfs subvolume snapshot".

Returns
the source subvolume.

References source_subvolume.

Referenced by sbuild::chroot_directory::chroot_directory(), get_details(), get_keyfile(), and setup_env().

+ Here is the caller graph for this function:

void chroot_btrfs_snapshot::set_keyfile ( chroot chroot,
keyfile const &  keyfile,
string_list used_keys 
)
protectedvirtual

Set the chroot properties from a keyfile.

The chroot name must have previously been set, so that the correct keyfile group may be determined.

Parameters
chrootthe chroot to use.
keyfilethe keyfile to get the properties from.
used_keysa list of the keys used will be set.

Implements sbuild::chroot.

References sbuild::chroot::get_name(), sbuild::basic_keyfile< K, P >::get_object_value(), sbuild::keyfile_base::PRIORITY_DISALLOWED, sbuild::keyfile_base::PRIORITY_REQUIRED, sbuild::chroot::set_keyfile(), set_snapshot_directory(), set_snapshot_name(), and set_source_subvolume().

void chroot_btrfs_snapshot::set_snapshot_directory ( std::string const &  snapshot_directory)

Set the snapshot directory.

Parameters
snapshot_directorythe snapshot directory.

References sbuild::chroot::DIRECTORY_ABS, sbuild::is_absname(), snapshot_directory, and source_subvolume.

Referenced by set_keyfile().

+ Here is the caller graph for this function:

void chroot_btrfs_snapshot::set_snapshot_name ( std::string const &  snapshot_name)

Set the snapshot name.

This is used by "btrfs subvolume snapshot", and is the full path to the snapshot.

Parameters
snapshot_namethe snapshot name.

References sbuild::chroot::DIRECTORY_ABS, sbuild::is_absname(), snapshot_name, and source_subvolume.

Referenced by set_keyfile().

+ Here is the caller graph for this function:

void chroot_btrfs_snapshot::set_source_subvolume ( std::string const &  source_subvolume)

Set the source subvolume path.

This is used by "btrfs subvolume snapshot".

Parameters
source_subvolumethe source subvolume.

References sbuild::chroot::DIRECTORY_ABS, sbuild::is_absname(), and source_subvolume.

Referenced by set_keyfile().

+ Here is the caller graph for this function:

void chroot_btrfs_snapshot::setup_env ( chroot const &  chroot,
environment env 
) const
virtual

Set environment.

Set the environment that the setup scripts will see during execution.

Parameters
chrootthe chroot to use.
envthe environment to set.

Implements sbuild::chroot.

References sbuild::environment::add(), get_snapshot_directory(), get_snapshot_name(), get_source_subvolume(), and sbuild::chroot::setup_env().

void chroot_btrfs_snapshot::setup_lock ( chroot::setup_type  type,
bool  lock,
int  status 
)
protectedvirtual

Unlock a chroot during setup.

The locking technique (if any) may vary depending upon the chroot type and setup stage. For example, during creation of an LVM snapshot a block device might require locking, but afterwards this will change to the new block device.

An error will be thrown on failure.

Parameters
typethe type of setup being performed
locktrue to lock, false to unlock
statusthe exit status of the setup commands (0 for success, nonzero for failure).

Implements sbuild::chroot.

References sbuild::chroot::setup_session_info(), sbuild::chroot::SETUP_START, and sbuild::chroot::SETUP_STOP.


The documentation for this class was generated from the following files: