vzctl.spec: add buildroot rm to %install

As per
http://fedoraproject.org/wiki/EPEL/GuidelinesAndPolicies#Prepping_BuildRoot_For_.25install

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
scripts/.gitignore: add vps-netns_dev_{add,del}

Commit c6f7199 adds these two, and they are generated from .in
files so should be mentioned in .gitignore

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Fix vzctl enter/exec to upstream container

Testing vzctl enter on 3.8rc3 kernel, got this:

	# uname -a
	Linux kirpad 3.8.0-0.rc3.git0.1.fc19.x86_64 #1 SMP Thu Jan 10 21:09:08 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

	# vzctl start 101
	Directory /proc/vz not found, assuming non-OpenVZ kernel
	Starting container...
	Container is mounted
	Container start in progress...

	# vzctl enter 101
	Directory /proc/vz not found, assuming non-OpenVZ kernel
	enter into CT 101 failed
	Can't add task creator to container: (null)

strace shows that vzctl (cgroup_get_cgroup() called from
container_add_task() I guess) checks for existence of
/sys/fs/cgroup/$WHATEVET/vz-101/ and it fails, apparently because
after setns() we don't have these anymore.

Fix my doing setns() after container_add_task() not before.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
vzctl snapshot-list: check if snapshot is supported

Rather than presenting empty snapshot list, bail out with an error,
or crash, check that
1 the container is ploop-based
2 ploop is supported

Crash would happen if ploop library is not avaialble, because
vzctl_env_snapshot_list() now calls ploop functions.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
vzctl snapshot-list: do not return 1

1. Introduce VZCTL_E_SNAPSHOT_LIST exit code,
use it and document it in vzctl(8).

2. Use more generic exit codes where possible in
vzctl_env_snapshot_list() and friends.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
vzctl set --ipadd/ipdel: support for Fedora 18 CT

First, in F18 ifconfig is not included by default, so we (finally) use
ip instead.

Second, it doesn't like having 127.0.0.1 on venet0, the simplest way to
make it like it is to have ARPCHECK="no" in ifcfg-venet0 file.

Slightly tested here and there, looks like it works.

Heavily based on patch by Konstantin Volkov <wolf@parallels.com>,
with all the bugs added by me.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Factor out create_static_dev() out of dev_create()

Very similar code is used in mk_quota_dev(), so let's factor it out.
The next patch will make use of it outside of dev.c scope.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Use make_static_dev() for creating quota device

No need for separate mk_quota_dev() anymore.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
In-container devices: add support for Fedora 18

Fedora 18's systemd employs a new scheme for static devices,
this patch adds support for it.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
vzctl snapshot-list: fix processing first option

First option to snapshot-list were ignored, because getopt_long() starts
processing options from argv[1], assuming argv[0] is binary name.

To fix, do not increment argv (and decrement argc) when calling
run_action(); instead, do this inside run_action when needed.
This way if we would add something that uses getopt() we'd be fine.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
vzlist: fix segfault on ploop CT with no DISKINODES set

If a ploop-based CT have no DISKINODES set in its config file
(which is perfectly legal), vzlist -o diskspace (or vzlist -j)
segfaults:

	# vzlist 1016 -o diskspace
	Segmentation fault (core dumped)

	# vzlist -j 1016
	Segmentation fault (core dumped)

gdb copy-paste:

	Program received signal SIGSEGV, Segmentation fault.
	get_ve_ploop_info (ve=0x64b060) at vzlist.c:1471
	1471		ve->quota->diskspace[1] = ve->quota->diskspace[2] =

	(gdb) p ve->quota
	$1 = (struct Cquota *) 0x0

This happens because the memory for Cquota structure is allocated in
merge_conf() only if *both* DISKSPACE and DISKQUOTA are set. That made
sense before, because vzquota needed both parameters. Now with ploop
DISKINODES is not required (and ignored if set).

Solution implemented by this patch is to change that "both are set"
to "either one is set" logic in merge_conf().

In addition, check that ve->quota is not-null and allocate it in
get_ve_ploop_info(). This should help preventing SIGSEGV in case say
someone started a container and then removed DISKSPACE/DISKINODES from
its config file.

https://bugzilla.openvz.org/2488

Reported-by: Antanas <antanas@antanas.eu>
Reported-by: Maxim Leonov <st@overlogic.org>
Signed-off-by: Kir Kolyshkin <kir@openvz.org>
vzlist -j: fix showing disk usage for stopped CTs

Incidentally found this discrepancy between vzlist and vzlist -j:

	# vzlist 1016 -o diskspace,diskspace.s,diskspace.h,diskinodes,diskinodes.s,diskinodes.h
	    DSPACE   DSPACE.S   DSPACE.H    DINODES  DINODES.S  DINODES.H
	    445080    2268740    2268740      25976     144288     144288

	# vzlist 1016 -j -o diskspace,diskinodes
	[
	  {
	    "diskspace": {
	      "usage": 0,
	      "softlimit": 2268740,
	      "hardlimit": 2268740
	    },
	    "diskinodes": {
	      "usage": 0,
	      "softlimit": 144288,
	      "hardlimit": 144288
	    }
	  }
	]

Basically, usage was not shown in json format, but was shown in default
format, because the container was not running.

A bit of history:

Quite some long time ago we only showed usage for a running container.
Later I found we can show usage for mounted CT as well, and implemented
that in commit de32e5472. Then commit 7ab85d9 added support for ploop-based
CTs (and in that case info is also available even for stopped/unmounted CTs).

Then I was porting the JSON patch (commit fc6386d) I screwed it up
(yes, it's my bug, not Roman's). Then this was fixed in commit 63ab6e7,
but only for non-json case.

So this is an addition to the commit 63ab6e7, for json case.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
vzevent: do umount/mount when rebooting CT

Apparently in some cases (like NFS mounts invoked by vzctl mount
scripts) vzevent should do umount/mount when restarting a container.
In general, this is the right thing to do anyway, and this is what vzctl
restart does. So, let's add umount to vzevent-reboot.

Also, since there is a hack to do reboot of Fedora 17 container in
vzevent-stop script, modify it accordingly to do umount before checking
if we need to reboot, not after.

https://bugzilla.openvz.org/2507

Reported-by: Pavel Snajdr <pavel.snajdr@relbit.com>
Signed-off-by: Kir Kolyshkin <kir@openvz.org>
vzctl: fix check for VEID_MAX

Commit af42bbd introduced check for CTID < VEID_MAX.
Apparently this check was only performed if CTID supplied was a name,
i.e. after name -> CTID conversion.

Fix it by moving the check out of if statement.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
vzlist: more strict for cmdline-supplied CTIDs

First, move the veid check out of 'if' statement, similar to the
previous commit aa84f2f for vzctl.

Second, check for VEID_MAX as well to filter out invalid CTIDs as early
as possible.

Related to https://bugzilla.openvz.org/2514

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
vzlist: warn/skip invalid CTIDs in ve.conf files

As original bug reporter puts in, using a CTID of 12 digits in ve.conf
file name results in strange-looking error:

	# mv /etc/vz/conf/2013020601.conf /etc/vz/conf/201302060101.conf ; mv
	# /vz/private/2013020601 /vz/private/201302060101; mv
	# /vz/root/2013020601 /vz/root/201302060101
	# vzlist -a
	Unable to open /etc/vz/conf/-561402811.conf: No such file or directory
	CTID NPROC STATUS IP_ADDR NAME

Fix by adding a check for validity of CTID embedded in config file name.
Configs with invalid CTIDs are warned about and skipped.

https://bugzilla.openvz.org/2514

Reported-by: Justin Albstmeijer <justin@vlamea.nl>
Signed-off-by: Kir Kolyshkin <kir@openvz.org>
etc/dists/scripts/postcreate.sh: Fedora 18 support

For Fedora 18+, we need to set the following caps:

/usr/sbin/arping = cap_net_raw+ep
/usr/sbin/clockdiff = cap_net_raw+ep
/usr/bin/systemd-detect-virt = cap_dac_override,cap_sys_ptrace+ep

ALSO NOTE that in Fedora 17+ ping comes with CAP_NET_ADMIN which is
needed to use ping -m being non-root. But since CAP_NET_ADMIN is not
granted to a container by default, ping with this capability set
will not work at all. So we are NOT setting this cap for ping.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
etc/dists/scripts/etcnet-{add,del}_ip.sh: IPv6 support

This adds IPv6 support for etcnet-based containers (i.e. ALT Linux).

https://bugzilla.openvz.org/2482

[kir@openvz.org: rm empty lines added by original patch]
Released vzctl 4.2

Changes: see http://openvz.org/Download/vzctl/4.2/changes

Signed-off-by: Kir Kolyshkin <kir@openvz.org>