Fork Vasum on GitHub Official Vasum Wiki on Tizen.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vasum::Zone Class Reference

#include <zone.hpp>

Public Types

typedef netdev::Attrs NetdevAttrs
 
typedef std::function< void(bool
succeeded)> 
StartAsyncResultCallback
 

Public Member Functions

 Zone (const std::string &zoneId, const std::string &zonesPath, const std::string &zoneTemplatePath, const std::string &dbPath, const std::string &zoneTemplateDir, const std::string &baseRunMountPointPath)
 Zone constructor. More...
 
 Zone (const Zone &)=delete
 
Zoneoperator= (const Zone &)=delete
 
 ~Zone ()
 
const std::string & getId () const
 Get the zone id. More...
 
int getPrivilege () const
 Get the zone privilege. More...
 
void restore ()
 Restore zone to the previous state. More...
 
void start ()
 Boot the zone to the background. More...
 
void stop (bool saveState)
 Try to shutdown the zone, if failed, destroy it. More...
 
bool activateVT ()
 Activate this zone's VT. More...
 
void goForeground ()
 Setup this zone to be put in the foreground. More...
 
void goBackground ()
 Setup this zone to be put in the background. More...
 
void setDetachOnExit ()
 Set if zone should be detached on exit. More...
 
void setDestroyOnExit ()
 Set if zone should be destroyed on exit. More...
 
bool isRunning ()
 
bool isStopped ()
 Check if the zone is stopped. More...
 
void suspend ()
 Suspends an active zone, the process is frozen without further access to CPU resources and I/O, but the memory used by the zone at the hypervisor level will stay allocated. More...
 
void resume ()
 Resume zone. More...
 
bool isPaused ()
 
bool isSwitchToDefaultAfterTimeoutAllowed () const
 
int getVT () const
 Get id of VT. More...
 
int createFile (const std::string &path, const std::int32_t flags, const std::int32_t mode)
 Create file inside zone, return its fd. More...
 
std::string declareFile (const int32_t &type, const std::string &path, const int32_t &flags, const int32_t &mode)
 Declare file, directory or pipe that will be created while zone startup. More...
 
std::string declareMount (const std::string &source, const std::string &target, const std::string &type, const int64_t &flags, const std::string &data)
 Declare mount that will be created while zone startup. More...
 
std::string declareLink (const std::string &source, const std::string &target)
 Declare link that will be created while zone startup. More...
 
std::vector< std::string > getDeclarations () const
 Gets all declarations. More...
 
void removeDeclaration (const std::string &declarationId)
 Remove declaration. More...
 
std::string getRootPath () const
 Get zone root path. More...
 
void createNetdevVeth (const std::string &zoneDev, const std::string &hostDev)
 Create veth network device. More...
 
void createNetdevMacvlan (const std::string &zoneDev, const std::string &hostDev, const uint32_t &mode)
 Create macvlan network device. More...
 
void moveNetdev (const std::string &devId)
 Move network device to zone. More...
 
void destroyNetdev (const std::string &devId)
 Destroy network device in zone. More...
 
void setNetdevAttrs (const std::string &netdev, const NetdevAttrs &attrs)
 Set network device attributes. More...
 
NetdevAttrs getNetdevAttrs (const std::string &netdev)
 Get network device attributes. More...
 
std::vector< std::string > getNetdevList ()
 Get network device list. More...
 
void deleteNetdevIpAddress (const std::string &netdev, const std::string &ip)
 Remove ipv4/ipv6 address from network device. More...
 
void setSchedulerLevel (SchedulerLevel sched)
 Sets the zones scheduler CFS quota. More...
 
std::int64_t getSchedulerQuota ()
 

Private Member Functions

void onNameLostCallback ()
 
void saveDynamicConfig ()
 
void updateRequestedState (const std::string &state)
 
void setSchedulerParams (std::uint64_t cpuShares, std::uint64_t vcpuPeriod, std::int64_t vcpuQuota)
 

Private Attributes

ZoneConfig mConfig
 
ZoneDynamicConfig mDynamicConfig
 
std::unique_ptr< ZoneProvisionmProvision
 
std::recursive_mutex mReconnectMutex
 
std::string mRunMountPoint
 
std::string mRootPath
 
std::string mDbPath
 
lxc::LxcZone mZone
 
const std::string mId
 
bool mDetachOnExit
 
bool mDestroyOnExit
 

Member Typedef Documentation

typedef netdev::Attrs vasum::Zone::NetdevAttrs
typedef std::function<void(bool succeeded)> vasum::Zone::StartAsyncResultCallback

Constructor & Destructor Documentation

vasum::Zone::Zone ( const std::string &  zoneId,
const std::string &  zonesPath,
const std::string &  zoneTemplatePath,
const std::string &  dbPath,
const std::string &  zoneTemplateDir,
const std::string &  baseRunMountPointPath 
)

Zone constructor.

Parameters
zoneIdzone id
zonesPathdirectory where zones are defined (configs, rootfs etc)
zoneTemplatePathpath for zones config template
dbPathpath to dynamic config db file
zoneTemplateDirdirectory where templates are stored
baseRunMountPointPathbase directory for run mount point
vasum::Zone::Zone ( const Zone )
delete
vasum::Zone::~Zone ( )

Member Function Documentation

bool vasum::Zone::activateVT ( )

Activate this zone's VT.

Returns
Was activation successful?
int vasum::Zone::createFile ( const std::string &  path,
const std::int32_t  flags,
const std::int32_t  mode 
)

Create file inside zone, return its fd.

Parameters
pathPath where the file should be created
flagsFlags used when opening the file. See common/lxc/zone.hpp for more info.
modePermissions with which file is created
Returns
Created files fd
void vasum::Zone::createNetdevMacvlan ( const std::string &  zoneDev,
const std::string &  hostDev,
const uint32_t &  mode 
)

Create macvlan network device.

void vasum::Zone::createNetdevVeth ( const std::string &  zoneDev,
const std::string &  hostDev 
)

Create veth network device.

std::string vasum::Zone::declareFile ( const int32_t &  type,
const std::string &  path,
const int32_t &  flags,
const int32_t &  mode 
)

Declare file, directory or pipe that will be created while zone startup.

std::string vasum::Zone::declareLink ( const std::string &  source,
const std::string &  target 
)

Declare link that will be created while zone startup.

std::string vasum::Zone::declareMount ( const std::string &  source,
const std::string &  target,
const std::string &  type,
const int64_t &  flags,
const std::string &  data 
)

Declare mount that will be created while zone startup.

void vasum::Zone::deleteNetdevIpAddress ( const std::string &  netdev,
const std::string &  ip 
)

Remove ipv4/ipv6 address from network device.

void vasum::Zone::destroyNetdev ( const std::string &  devId)

Destroy network device in zone.

std::vector< std::string > vasum::Zone::getDeclarations ( ) const

Gets all declarations.

const std::string & vasum::Zone::getId ( ) const

Get the zone id.

Zone::NetdevAttrs vasum::Zone::getNetdevAttrs ( const std::string &  netdev)

Get network device attributes.

std::vector< std::string > vasum::Zone::getNetdevList ( )

Get network device list.

int vasum::Zone::getPrivilege ( ) const

Get the zone privilege.

std::string vasum::Zone::getRootPath ( ) const

Get zone root path.

std::int64_t vasum::Zone::getSchedulerQuota ( )
Returns
Scheduler CFS quota, TODO: this function is only for UNIT TESTS
int vasum::Zone::getVT ( ) const

Get id of VT.

void vasum::Zone::goBackground ( )

Setup this zone to be put in the background.

I.e. set appropriate scheduler level.

void vasum::Zone::goForeground ( )

Setup this zone to be put in the foreground.

I.e. set appropriate scheduler level.

bool vasum::Zone::isPaused ( )
Returns
Is the zone in a paused state?
bool vasum::Zone::isRunning ( )
Returns
Is the zone running?
bool vasum::Zone::isStopped ( )

Check if the zone is stopped.

It's NOT equivalent to !isRunning, because it checks different internal zone states. There are other states, (e.g. paused) when the zone isn't running nor stopped.

Returns
Is the zone stopped?
bool vasum::Zone::isSwitchToDefaultAfterTimeoutAllowed ( ) const
Returns
Is switching to default zone after timeout allowed?
void vasum::Zone::moveNetdev ( const std::string &  devId)

Move network device to zone.

void vasum::Zone::onNameLostCallback ( )
private
Zone& vasum::Zone::operator= ( const Zone )
delete
void vasum::Zone::removeDeclaration ( const std::string &  declarationId)

Remove declaration.

void vasum::Zone::restore ( )

Restore zone to the previous state.

void vasum::Zone::resume ( )

Resume zone.

void vasum::Zone::saveDynamicConfig ( )
private
void vasum::Zone::setDestroyOnExit ( )

Set if zone should be destroyed on exit.

void vasum::Zone::setDetachOnExit ( )

Set if zone should be detached on exit.

void vasum::Zone::setNetdevAttrs ( const std::string &  netdev,
const NetdevAttrs attrs 
)

Set network device attributes.

void vasum::Zone::setSchedulerLevel ( SchedulerLevel  sched)

Sets the zones scheduler CFS quota.

void vasum::Zone::setSchedulerParams ( std::uint64_t  cpuShares,
std::uint64_t  vcpuPeriod,
std::int64_t  vcpuQuota 
)
private
void vasum::Zone::start ( )

Boot the zone to the background.

void vasum::Zone::stop ( bool  saveState)

Try to shutdown the zone, if failed, destroy it.

Parameters
saveStatesave zone's state
void vasum::Zone::suspend ( )

Suspends an active zone, the process is frozen without further access to CPU resources and I/O, but the memory used by the zone at the hypervisor level will stay allocated.

void vasum::Zone::updateRequestedState ( const std::string &  state)
private

Member Data Documentation

ZoneConfig vasum::Zone::mConfig
private
std::string vasum::Zone::mDbPath
private
bool vasum::Zone::mDestroyOnExit
private
bool vasum::Zone::mDetachOnExit
private
ZoneDynamicConfig vasum::Zone::mDynamicConfig
private
const std::string vasum::Zone::mId
private
std::unique_ptr<ZoneProvision> vasum::Zone::mProvision
private
std::recursive_mutex vasum::Zone::mReconnectMutex
mutableprivate
std::string vasum::Zone::mRootPath
private
std::string vasum::Zone::mRunMountPoint
private
lxc::LxcZone vasum::Zone::mZone
private

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