The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

App::LXC::Container::Mounts - manage mount-points for LXC container configuration

SYNOPSIS

    use App::LXC::Container::Mounts;
    my $mounts = App::LXC::Container::Mounts->new();
    $mounts->mount_point($path, EXPLICIT);
    if ($mounts->mount_point($path) == IMPLICIT) { ... }
    $mounts->mount_point($path, REMOVE);

    $mounts->merge_mount_points(12);
    ... foreach $mounts->sub_directories($path);

    say $out $_  foreach  $mounts->implicit_mount_lines('/');
    $mounts->create_mount_points('/');

ABSTRACT

This module is used by App::LXC::Container::Update to manage the (possible) mount-points of a container that is updated.

DESCRIPTION

The module handles all kinds of mount-points of an LXC container configuration created (and maybe destroyed again) during the update of an LXC container.

EXPORT

All access functions are exported by default as that's the point of this module.

MAIN METHODS

The module defines the following main methods which are used by App::LXC::Container:

new - create object to manage mount-points

    $mounts = App::LXC::Container::Mounts->new();

description:

This is the constructor for the object used to manage the possible mount-poins and directories of an LXC application container.

returns:

the management object

implicit_mount_lines - get list of implicit mount-lines for path

    say $out $_  foreach  $mounts->implicit_mount_lines('/');

parameters:

    $path               root path

description:

This method (recursively) returns a list of mount-lines for the LXC configuration. It returns all implicit mount-points below (including) the given path.

returns:

list of implicit mount-lines for path

merge_mount_points - merge mount-points

    $mounts->merge_mount_points($limit2, $limit3, $limit4, $limit5);

parameters:

    $limitN             heuristic limit for depth N used for the merge decision

description:

This method merges all IMPLICIT mount-points gathered so far. The heuristic limits are the maximum number of children a directory of the corresponding depth may have as separate mount-points.

mount_point - access child in specific new

    $state = $mounts->mount_point($path);
        or
    $mounts->mount_point($path, $state);

parameters:

    $path               the path to be checked or set
    $value              state to be set for path

description:

This method either sets the state for a path (including for each parent directory) or determines its current state. Note that the method does not prevent every possible contradicting settings!

The state is one of the following values:

UNDEFINED - not yet defined
IGNORE - completely ignored
NO_MERGE, EMPTY, COPY - special states from filters
EXPLICIT - explicit mount-point or filtered as not ignore
IMPLICIT - will be used as implicit mount-point (or merged with others)
REMOVE - remove state for specific path

returns:

state of the path

sub_directories - get sub-directories of a path

    foreach ($mounts->sub_directories($path)) { ... }

parameters:

    $path               parent path of sub-directories

description:

This method returns the alphabetically sorted list of all sub-directories of the given path.

returns:

list of all sub-directories

HELPER METHODS / FUNCTIONS

The following methods and functions should not be used outside of this module itself:

_depth_of - return depth of path

    $depth = _depth_of($path);

parameters:

    $path               the path to be checked

description:

This method function returns the depth of a given path.

returns:

depth of path

_depth_sort - sort paths depth first

    $depth = _depth_sort($path);

parameters:

    $path1              1st path to be sorted
    $path2              2nd path to be sorted

description:

This method compares two paths for sorting them depth first followed by alphabetic.

returns:

sort value

_set - set values for a specific path

    $self->_set($path, $state, \@parents, $parent_state);

parameters:

    $path               the path to be set
    $state              the state to be set for path itself
    $parents            reference to array of parent directories
    $parent_state       the state to be set for all parents of the path

description:

This method function sets the state for a path and its parents. It also creates the internal directory tree, if necessary.

SEE ALSO

man pages lxc.container.conf, lxc and lxcfs

LXC documentation on https://linuxcontainers.org

LICENSE

Copyright (C) Thomas Dorner.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See LICENSE file for more details.

AUTHOR

Thomas Dorner <dorner (at) cpan (dot) org>

Contributors

none so far