softwarecontainer
0.18.0-739e8d7 2017-05-04
|
This gateway is responsible for exposing device nodes in an LXC container. More...
#include <devicenodegateway.h>
Public Types | |
enum | GatewayState : unsigned int { CREATED, CONFIGURED, ACTIVATED } |
Public Member Functions | |
DeviceNodeGateway (std::shared_ptr< ContainerAbstractInterface > container) | |
virtual bool | readConfigElement (const json_t *element) override |
Gateway specific parsing of config elements. More... | |
virtual bool | activateGateway () override |
Implements Gateway::activateGateway. More... | |
virtual bool | teardownGateway () override |
Implements Gateway::teardownGateway. More... | |
virtual std::string | id () const |
Returns the ID of the gateway. More... | |
virtual bool | setConfig (const json_t *config) |
Configure this gateway according to the supplied JSON configuration string. More... | |
virtual bool | activate () |
Applies any configuration set by setConfig() More... | |
virtual bool | teardown () |
Restore system to the state prior to launching of gateway. More... | |
virtual bool | isConfigured () |
Is the gateway configured or not? More... | |
virtual bool | isActivated () |
Is the gateway activated or not? More... | |
bool | bindMount (const std::string &src, const std::string &dst, const std::string &tmpContainerRoot, bool readOnly, bool writeBufferEnabled=false) |
bindMount Bind mount a src directory to another position dst. More... | |
bool | tmpfsMount (const std::string dst, const int maxSize) |
tmpfsMount Mount a tmpfs in the dst path and limit size of the tmpfs to maxSize More... | |
Static Public Attributes | |
static constexpr const char * | ID |
Protected Member Functions | |
std::shared_ptr< ContainerAbstractInterface > | getContainer () |
Get a handle to the associated container. More... | |
bool | setEnvironmentVariable (const std::string &variable, const std::string &value) |
Set an environment variable in the associated container. More... | |
bool | writeToFile (const std::string &path, const std::string &content) |
void | markFileForDeletion (const std::string &path) |
bool | overlayMount (const std::string &lower, const std::string &upper, const std::string &work, const std::string &dst) |
overlayMount Mount a directory with an overlay on top of it. More... | |
bool | syncOverlayMount (const std::string &lower, const std::string &upper) |
syncOverlayMount Copy the directory structure from upper layer to the lower layer More... | |
bool | createSharedMountPoint (const std::string &path) |
createSharedMountPoint Make the mount point shared, ie new mount points created in one bind mount will also be created in the other mount point. More... | |
bool | pathInList (const std::string path) |
checks whether given path is already added to clean up handlers or not More... | |
Protected Attributes | |
bool | m_activatedOnce |
std::vector< std::unique_ptr< CleanUpHandler > > | m_cleanupHandlers |
m_cleanupHandlers A vector of cleanupHandlers added during the lifetime of the FileToolKitWithUndo that will be run from the destructor. More... | |
std::vector< std::unique_ptr< CreateDir > > | m_createDirList |
m_createDirList A vector of CreateDir classes. More... | |
This gateway is responsible for exposing device nodes in an LXC container.
The basic operation looks as follows:
Notes:
Definition at line 41 of file devicenodegateway.h.
|
overridevirtual |
Gateway specific parsing of config elements.
All gateways implement this method in order to provide gateway specific parsing of the configuration content.
element | A JSON configuration item. |
Implements softwarecontainer::Gateway.
Definition at line 32 of file devicenodegateway.cpp.
References softwarecontainer::Device::parse().
|
overridevirtual |
Implements Gateway::activateGateway.
This function will iterate over all devices and issue mknod and chmod commands, which are run in the container.
Implements softwarecontainer::Gateway.
Definition at line 44 of file devicenodegateway.cpp.
|
overridevirtual |
Implements Gateway::teardownGateway.
Implements softwarecontainer::Gateway.
Definition at line 60 of file devicenodegateway.cpp.
|
virtualinherited |
Returns the ID of the gateway.
Definition at line 36 of file gateway.cpp.
Referenced by softwarecontainer::Gateway::activate(), softwarecontainer::DBusGatewayInstance::DBusGatewayInstance(), softwarecontainer::Gateway::setConfig(), and softwarecontainer::Gateway::teardown().
|
virtualinherited |
Configure this gateway according to the supplied JSON configuration string.
config | JSON string containing gateway-specific JSON configuration |
config
was successfully parsed, false otherwiseGatewayError | If called on an already activated gateway. |
Reimplemented in softwarecontainer::DBusGateway.
Definition at line 41 of file gateway.cpp.
References softwarecontainer::Gateway::id(), and softwarecontainer::Gateway::readConfigElement().
|
virtualinherited |
Applies any configuration set by setConfig()
GatewayError | If called on an already activated gateway, or if the gateway has not been previously configured, or if there is not container instance set. |
Reimplemented in softwarecontainer::DBusGateway.
Definition at line 78 of file gateway.cpp.
References softwarecontainer::Gateway::id().
|
virtualinherited |
Restore system to the state prior to launching of gateway.
Any cleanup code (removal of files, virtual interfaces, etc) should be placed here.
GatewayError | If called on a non activated gateway. |
Reimplemented in softwarecontainer::DBusGateway.
Definition at line 103 of file gateway.cpp.
References softwarecontainer::Gateway::id().
Referenced by softwarecontainer::DBusGatewayInstance::DBusGatewayInstance().
|
virtualinherited |
Is the gateway configured or not?
Reimplemented in softwarecontainer::DBusGateway.
Definition at line 134 of file gateway.cpp.
|
virtualinherited |
Is the gateway activated or not?
Dynamic gateways will return true if they have been activated at least once. Non-dynamic gateways will return true if they are in state ACTIVATED
Reimplemented in softwarecontainer::DBusGateway.
Definition at line 139 of file gateway.cpp.
Referenced by softwarecontainer::DBusGatewayInstance::DBusGatewayInstance().
|
protectedinherited |
Get a handle to the associated container.
GatewayError | If called before setContainer() has been called. |
Definition at line 128 of file gateway.cpp.
Referenced by softwarecontainer::NetworkGateway::activateGateway(), softwarecontainer::DBusGatewayInstance::activateGateway(), softwarecontainer::WaylandGateway::readConfigElement(), and softwarecontainer::NetworkGateway::teardownGateway().
|
protectedinherited |
Set an environment variable in the associated container.
|
inherited |
bindMount Bind mount a src directory to another position dst.
src | Path to mount from |
dst | Path to mount to |
readOnly | Make the bind mount destination read only |
writeBufferEnabled | Enable write buffers on the bind mount. |
Definition at line 53 of file filetoolkitwithundo.cpp.
References softwarecontainer::existsInFileSystem(), softwarecontainer::isDirectory(), and softwarecontainer::FileToolkitWithUndo::m_createDirList.
Referenced by softwarecontainer::Container::bindMountInContainer().
|
inherited |
tmpfsMount Mount a tmpfs in the dst path and limit size of the tmpfs to maxSize
dst | The destination to mount a tmpfs on |
maxSize | The max size of the tmpfs being mounted |
Definition at line 177 of file filetoolkitwithundo.cpp.
References softwarecontainer::isDirectoryEmpty(), softwarecontainer::FileToolkitWithUndo::m_cleanupHandlers, and softwarecontainer::FileToolkitWithUndo::m_createDirList.
Referenced by softwarecontainer::SoftwareContainer::SoftwareContainer().
|
protectedinherited |
overlayMount Mount a directory with an overlay on top of it.
An overlay protects the lower filesystem from writes by writing to the upper file system through the work directory.
lower | The lower file system, this will be read only. |
upper | The upper file system, this can be a tmpfs/ramfs of some kind. This is where final writes wind up |
work | This is a work directory, preferably a tmpfs/ramfs of some kind. This is where writes wind up temporarily. |
dst | Where the overlay filesystem will be mounted. |
Definition at line 130 of file filetoolkitwithundo.cpp.
References softwarecontainer::FileToolkitWithUndo::m_cleanupHandlers, and softwarecontainer::FileToolkitWithUndo::m_createDirList.
Referenced by softwarecontainer::Container::create().
|
protectedinherited |
syncOverlayMount Copy the directory structure from upper layer to the lower layer
lower | The lower layer used in an overlay file system. |
upper | The upper layer in an overlay file system. |
Definition at line 171 of file filetoolkitwithundo.cpp.
References softwarecontainer::RecursiveCopy::copy(), and softwarecontainer::RecursiveCopy::getInstance().
|
protectedinherited |
createSharedMountPoint Make the mount point shared, ie new mount points created in one bind mount will also be created in the other mount point.
path | The mount path to make shared. |
Definition at line 206 of file filetoolkitwithundo.cpp.
References softwarecontainer::FileToolkitWithUndo::m_cleanupHandlers.
Referenced by softwarecontainer::Container::initialize().
|
protectedinherited |
checks whether given path is already added to clean up handlers or not
This function will be called only before adding new CleanUpHandler for FileCleanUpHandler and DirectoryCleanUpHandler. The reason behind this, only indicated CleanUpHandlers are related with file/directory removal operations.
a | string path name to check |
Definition at line 232 of file filetoolkitwithundo.cpp.
References softwarecontainer::FileToolkitWithUndo::m_cleanupHandlers.
Referenced by softwarecontainer::Container::bindMountInContainer().
|
protectedinherited |
m_cleanupHandlers A vector of cleanupHandlers added during the lifetime of the FileToolKitWithUndo that will be run from the destructor.
Definition at line 121 of file filetoolkitwithundo.h.
Referenced by softwarecontainer::Container::bindMountInContainer(), softwarecontainer::FileToolkitWithUndo::createSharedMountPoint(), softwarecontainer::FileToolkitWithUndo::overlayMount(), softwarecontainer::FileToolkitWithUndo::pathInList(), and softwarecontainer::FileToolkitWithUndo::tmpfsMount().
|
protectedinherited |
m_createDirList A vector of CreateDir classes.
This class handles directory cleaning operations when either interfered errors or when its destructor runs.
Definition at line 127 of file filetoolkitwithundo.h.
Referenced by softwarecontainer::FileToolkitWithUndo::bindMount(), softwarecontainer::Container::bindMountInContainer(), softwarecontainer::Container::initialize(), softwarecontainer::FileToolkitWithUndo::overlayMount(), softwarecontainer::SoftwareContainer::previouslyConfigured(), and softwarecontainer::FileToolkitWithUndo::tmpfsMount().