LXC: Make the drop capabilities list a hvparam

This patch adds the new hvparam "lxc_drop_capabilities" to the LXC
hypervisor.
This parameter specifies the list of capabilities which should be
dropped for the LXC container.
The default value of this parameter was hardcoded, but making this
parameter a hvparam improves user customizability.

Signed-off-by: Yuto KAWAMURA(kawamuray) <kawamuray.dadada@gmail.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
LXC: Implement RebootInstance of LXCHypervisor

This patch implements the RebootInstance functionality of the
LXCHypervisor.
Reboot of the LXC container can be done by using the lxc-stop command
with the --reboot switch. Internally this just sends SIGINT to the
init process of the container.
Since the init process is working on the host machine natively, it
requires CAP_SYS_BOOT capability to call the reboot(2) system call.
This function detects if CAP_SYS_BOOT was dropped from the container
and raises an error to enforce that requirement.
It is up to users to decide if they use the soft reboot of the LXC
container by allowing CAP_SYS_BOOT or drop it and do not use the soft
reboot.

Signed-off-by: Yuto KAWAMURA(kawamuray) <kawamuray.dadada@gmail.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
LXC: Split _GetCgroupInstanceValue function

Add the _GetCgroupInstanceParamPath function which returns the path of
the specified cgroup parameter file and change the
_GetCgroupInstanceValue to use this function.
With this patch, "subsystem" argument for this function was removed
because it can be determined by the param_name argument.

Signed-off-by: Yuto KAWAMURA(kawamuray) <kawamuray.dadada@gmail.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
LXC: Add _SetCgroupInstanceValue function

Add the _SetCgroupInstanceValue function which can be used to set the
value of an instance cgroup parameter.

Signed-off-by: Yuto KAWAMURA(kawamuray) <kawamuray.dadada@gmail.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
LXC: Implement BalloonInstanceMemory

This patch implements the BalloonInstanceMemory functionality of the
LXCHypervisor.
Memory ballooning for the LXC container can be done by using the
memory.limit_in_bytes and memory.memsw.limit_in_bytes cgroup
parameters.
The Linux kernel does not kill processes inside the cgroup whose
accounted memory we are shrinking, so the update for
memory.memsw.limit_in_bytes can fail even if the update for
memory.limit_in_bytes was successful, so this function must care that
all cgroup memory limit parameters are consistently updated.

Signed-off-by: Yuto KAWAMURA(kawamuray) <kawamuray.dadada@gmail.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
LXC: Additional check for cgroup subsystems existence

The LXC hypervisor of the Ganeti requires several cgroup subsystems
to provide hardware resources limitation regardless to the
lxc_cgroup_use hvparam.
These requirements should be checked before the instance startup.

Signed-off-by: Yuto KAWAMURA(kawamuray) <kawamuray.dadada@gmail.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
Fix LUInstanceSetParams prereq check wrt cpu_mask

Once I tried to modify a hvparam of the LXC hypervisor, I got this error:

    ValueError: max() arg is an empty sequence

This is because the current default value of the cpu_mask hypervisor
parameter of the LXC hypervisor is the zero-length string, so the
cpu_list returned by the ParseMultiCpuMask is empty.
The zero-length string is a valid value for the cpu_mask hvparam, so
we need to skip this check if the cpu_list is empty.

Signed-off-by: Yuto KAWAMURA(kawamuray) <kawamuray.dadada@gmail.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
LXC: Make devices ACL list an hvparam

This patch adds a new hvparam "lxc_devices" to the LXC hypervisor.
This parameter specifies the access control list for direct device
access from inside the LXC container.
The default value of this parameter was hardcoded, but making this
parameter an hvparam is worthwhile for users customizability.

Signed-off-by: Yuto KAWAMURA(kawamuray) <kawamuray.dadada@gmail.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
LXC: Include cputime in return value of GetInstanceInfo

Read the cputime(usage) of the LXC instance from the cpuacct.usage
cgroup parameter and include it as the "time" field of the return value
of GetInstanceInfo.
This commit also discards the TODO comment about something which is
already not accurate.

Signed-off-by: Yuto KAWAMURA(kawamuray) <kawamuray.dadada@gmail.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
LXC: Remove comment

This commit discards comments in LXCHypervisor which are already
solved, or already not accurate.

Signed-off-by: Yuto KAWAMURA(kawamuray) <kawamuray.dadada@gmail.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
LXC: Remove unused function

Remove the unused _GetMountSubdirs function from LXCHypervisor class.

Signed-off-by: Yuto KAWAMURA(kawamuray) <kawamuray.dadada@gmail.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
LXC: Add lxc_extra_config hvparam

Add the new hvparam lxc_extra_config which is used to specify
additional LXC container config parameters which are not supported by
the Ganeti LXC hypervisor natively.

Signed-off-by: Yuto KAWAMURA(kawamuray) <kawamuray.dadada@gmail.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
LXC: Raise an error if failed to read cgroup memory limit

Since we support the memory limit for the LXC container, we should
always have the memory subsystem mounted somewere, so failing to get
the memory limit from the cgroup fs is not acceptable.

Signed-off-by: Yuto KAWAMURA(kawamuray) <kawamuray.dadada@gmail.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
LXC: Make the number of ttys a hvparam

This patch adds a new hvparam "lxc_tty" to the LXC hypervisor.
This parameter specifies the number of ttys(actually ptys) that should
be allocated for the container.
The value of lxc.tty should be configurable because in some cases we
want to disable pts instance allocation for the LXC container.

Signed-off-by: Yuto KAWAMURA(kawamuray) <kawamuray.dadada@gmail.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>
Fix BaseHypervisor: CheckParameterSyntax,ValidateParameters

Currently both of these functions check if the value satisfies
bool(value) == False.
Using this approach, numerical 0 would not be allowed as a value of a
hvparam.
We know that unspecified hvparams have a value of either None or the
zero-length string, so these functions need to check if the value is
the one of these unspecified values.

Signed-off-by: Yuto KAWAMURA(kawamuray) <kawamuray.dadada@gmail.com>
Reviewed-by: Hrvoje Ribicic <riba@google.com>