destroy.c: move a log message

Move "Destroying container private area" message from vps_destroy() to
vps_destroy_dir(). Side effect is if vzctl create fails, it will now
print this message.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
vps_destroy_dir(): don't call quota on ploop CT

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Introduce cleanup handler mechanism

... and use it for create action.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
run_script(): use env_wait()

Code is identical, so let's shave off some LOC.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Use cleanup_handler to kill scripts run on host

Using the new cleanup callbacks, in case vzctl is running any script
on the host system and it (vzctl) is terminated, terminate the script
we run. Examples of such include action scripts, create scripts, vzquota
etc.

Note we only do it with scripts running on host (not inside CT).

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Employ cleanup engine for ploop operations

In case a ploop operation is interrupted, call ploop.cancel_operation().

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
vzctl create: fix cleanup

Create CT cleanup introduced in commit 91d1516 was incorrect, since we
create CT private area in a temp dir and then rename this dir to proper
$VE_PRIVATE.

Fix by moving cleanup hook instantiation to fs_create(), and using the
temp dir as its data.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
vzctl create: cleanup CT config if interrupted

Only do it if we're creating it.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
etc/dists/scripts/suse-*_ip.sh: remove extra slash

No need for / in IFCFG_DIR

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
etc/dists/scripts/suse-add_ip.sh: remove a warning

When starting a container with no IPs configured, grep spits an error
which should be ignored (it's fine if file doesn't exist):

 # vzctl --verbose --verbose start 1043
 ...
 Running container script: /etc/vz/dists/scripts/suse-add_ip.sh
 grep: /etc/sysconfig/network//ifcfg-venet0: No such file or directory
 ...

We could redirect grep's stderr to /dev/null, but instead let's
add a check that the file exist.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
src/lib/cpt.c:restore_fn(): log errno

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
vzctl console: recognize ESC as a first character

After commit 88f582e, ESC is only recognized after Enter. While this is
a good thing in general, one possible scenario is a user runs vzctl
console, takes a look and tries to close it, typing ESC and dot.
This particular scenario is broken by the above commit.

I have checked how ssh works, and found that it does recognize ~. as a
first characters. So let's do the same, and fix the man page and the
variable name used accordingly.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Add vzctl to OOM group configuration

In order to prevent it from being killed leaving a CT in some
unpredictable state.

Reference: PSBM-19049
Reference: vzctl@857688
Add VZCTL_E_UMOUNT_SNAPSHOT

Unfortunately, we have to change values for VZCTL_E_COMPACT_IMAGE
and VZCTL_E_LIST_SNAPSHOT in order to make room for VZCTL_E_UMOUNT_SNAPSHOT
which should be 161 for compatibility.

Hope no one relies on these numbers yet.

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

Improve the macro, so now there is
1 no need for struct vzctl_cleanup_handler * variable definition in
  every place which uses the macro
2 an ability to put ; at the end of the statement

Convert code using the macro accordingly

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
vzctl snapshot-[u]mount: implement

Implement, document, add bash-completion support.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
vzctl snapshot-* bash-completion for --id/--uuid

This patch implements autocompletion for existing snapshot IDs,
using snapshot-list functionality. It completes for all snapshot-*
commands except for snapshot (creation requires new unused ID).

A special case is snapshot-umount, it needs a snapshot ID which is
mounted.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
vzctl snapshot-list: add options bash-completion

We do not list -i and -h, but everything else is there, including
--help which can be, well, helpful.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
vzctl_env_snapshot_list(): free tree

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
vzctl_free_snapshot_tree(): free the tree itself

Found by coverity, CID 996915, CID 996914 etc.

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