ploop_replace_image(): improve error message

Make an error message about invalid level more informative
by showing the allowed level range.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
plooptool_replace(): simplify param check

Since we have added level check to replace_delta(), there is no need
to check it here.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
ploop_replace_image(): move check for level

In case level is specified indirectly, via UUID, we need to check
it anyway. In case top level image UUID is specified, we'd rather
say about it early and error out.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
ploop_replace_image(): move ploop_find_dev()

Move ploop_find_dev() earlier to error out earlier. We don't care
if UUID or level is valid or not, in case ploop is not running we
can't do replace.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
ploop_replace(): specify delta by current image

In ploop_replace() we can specify delta to replace by either its level
or by UUID. Yet another, more obvious, way is to specify it by currently
used delta image file. Add this way.

TODO: we can check that the old and the new delta files are identical
(perhaps by comparing their headers).

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
ploop replace: simplify/improve args check

One has to specify either device or mount point (or DiskDescriptor.xml).
Simplify and fix the check that one of these options is provided, and
improve the appropriate error message.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
replace_delta(): open file/dev at the start

Let's start by trying to open file and ploop device, to be able to fail
earlier. This makes error diagnostics easier to understand.

Before:
 # ploop replace -d ploop1 -i file -l 0
 Can't open or read /sys/block/ploop1/pstate/block_size: No such file or directory

After:
 # ploop replace -d ploop1 -i file -l 0
 Can't open device ploop1: No such file or directory

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
plooptool_replace(): improve an error message

This is an addition to commit c17e01f.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
ploop replace: add -o option

Commit ec43484 added a way to specify current delta by an image file.
This commit adds this functionality to ploop replace tool. Option
-o can be used for both -d/-m or DiskDescriptor.xml forms.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
lib/ploop.h: rm ploop_check_delta()

Commit 848f3e4 renamed ploop_check_delta() function but didn't care
to remove its prototype. Fix that.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
ploop replace: add checking images are the same

1. Add check_deltas_same() function. Currently it checks that files
   are of the same file, and image headers are the same (with the
   exception of in-use flag).

2. Use check_deltas_same() from ploop_replace_image().

3. Use check_deltas_same() from plooptool_replace()
   in case dd.xml is not used but -o is provided.

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