Redesign read DiskDescriptor functionality

DiskDescriptor represents the images stacked configuration and should be
in consistend state before an action starts. The DiskDescriptor.xml
could be modified after read and before lock.

This patch adds set of functions to change read DiskDescriptor.xml
logic after lock:

ploop_open_dd() - allocate
ploop_lock_dd() - lock and reread
ploop_unlock_dd() - unlock
ploop_close_dd() - release

[kir@openvz.org: Only ploop_open_dd() and ploop_close_dd() are put in
the public API, reading and locking is internal to the library. It is
assumed that all public API functions do ploop_lock_dd() -- in fact
currently some are not but this is to be discussed and fixed.]

Reference: PSBM-21570
Reference: ploop@964773
Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Redesign the read DiskDescriptor functionality 2/2

Use ploop_open_dd()/ploop_lock_dd() API to reread DiskDescriptor.xml
after lock in our code.

Reference: PSBM-21570
Reference: ploop@964778
ploop_open_dd(): don't return -1

This function return code is used to exit from main() in tools,
and we already return SYSEXIT_MALLOC. Therefore, don't return -1
but use SYSEXIT_DISKDESCR code.

Reference: ploop@971083
Signed-off-by: Kir Kolyshkin <kir@openvz.org>
ploop_open_dd(): use realpath() to do malloc

Save some stack space, one strdup() and its error checking.

Reference: ploop@971084
Signed-off-by: Kir Kolyshkin <kir@openvz.org>
plooptool_info(): use ploop_{open,close}_dd()

Switch to the new API. This is an addition to commit 0f71d9d / ploop@964778

Reference: ploop@971085
Signed-off-by: Kir Kolyshkin <kir@openvz.org>
ploop_resize_image: resize up to end of device

There is logic to reserve '4 * cluster_block' so it is impossible to
resize an image if resize delta is less than reservation. Let's skip
size parameter and resize fs up to end of device.

Reference: PSBM-24316
Reference: ploop@964902
ploop_delete_top_delta(): fix wrt top_guid

ploop_delete_snapshot calls ploop_lock_di first. The latter is successful
and reloads the disk descriptor info. This frees the old top_guid
and it starts to point to garbage actually.

Backup the top_guid value before the ploop_delete_snapshot() call
and pass it as the second argument.

[kir@openvz.org: s/SYSEXIT_BAD_DELTA/SYSEXIT_PLOOPFMT/]

Reference: PSBM-24407
Reference: ploop@964816
check_and_repair_sparse(): log filefrag output

Call 'filefrag -vs' before and after the image repair

Reference: PSBM-24671
Reference: ploop@968951
ploop snapshot-list: add snapshot mode

Add new option '--snapshot|-s' to list in terms of snapshots.
By default snapshot-list action list all deltas, the current delta
is always the top delta with hardcoded UUID.

Reference: PSBM-24699
Reference: ploop@969534
ploop_resize_image: enhanced inflate balloon to max size logic

fallocate() could fail with 'No space left on device' error.
Try  to find suitable value by iteratively inflating balloon.

Reference: PSBM-24679
Reference: ploop@970874