ploop_store_diskdescriptor: fsync DiskDescriptor.xml

Problem: DiskDescriptor.xml is empty after host's hard reboot

Solution: call fsync() before rename

Reference: PSBM-27028
Reference: ploop@1013886
ploop_store_diskdescriptor: fix typo, show errno

1 s/Faled/Failed/ to fix a typo.

2 s/Failed/Can't/ to use a verb we tend to use more often.

3 Pass errno to ploop_err() to show why exactly we can't.

This is an addition to commit b519e4c

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
ploop_store_diskdescriptor(): fix error msg

After commit b519e4c, we call a different function, so
fix the error message accordingly.

@noreview
Signed-off-by: Kir Kolyshkin <kir@openvz.org>
ploop_resize_image: auto-mount fs

Problem: unable to resize ploop if it is running but fs is not mounted

Solution: automount file system before performing online resize

Reference: PSBM-26764
Reference: ploop@1013361
ploop_resize_image(): handle get_mount_dir() error

get_mount_dir() return value is not boolean, but rather a 3-state.
It doesn't make sense to proceed if it returned an error, as it's
probably fatal.

While at it, document get_mount_dir() return values.

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

git-svn-id: https://svn.parallels.com/parallels/vzlin/utils/current/ploop@1015021 3f79cd19-dd19-0410-83c5-8b167e6f9dce
Signed-off-by: Kir Kolyshkin <kir@openvz.org>
do_delete_snapshot: fix wrt temp snapshot uuid

Temporary snapshot uuid is changed if topdelta is deleted.
Call check_snapshot_mount() to validate snapshot-delete action

Use case:
 ploop tsnapshot
 ploop snapshot-delete <TOP_DELTA_UUID>

Reference: ploop@1015313
ploop_switch_snapshot_ex(): don't return 0 if guid_old is bad

Code checks that param->guid_old is (1) valid and (2) non-existent,
and prints and error if any of those checks fails, but returns 0
instead of an error.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
BUGFIX Can not delete snapshot with multiple refs

The direct way to delete snapshot with > 1 references is
to make a copy of a snapshot image and merge with the copy

    * Delete A
    A -> B  => A -> B => B
     \-> C     A -> C    A -> C

Let's handle in another way, mark as temporary and merge
when it will be possible

Reference: PSBM-27154 "Can not delete snapshot of Container - double referenced"
Reference: ploop@1016663
do_delete_snapshot: deny delete top delta in case parent snapshot is temporary

Creating temporary snapshot and deleting top delta broke DiskDescriptor.xml:

	ploop tsnapshot -u {aff55492-7320-4d72-aedd-c1e303a22cc1} -c test DiskDescriptor.xml
	ploop snapshot-delete -u {5fbaabe3-6958-40ff-92a7-860e329aab41} DiskDescriptor.xml
	ploop mount DiskDescriptor.xml

	Error in validate_disk_descriptor (xml.c:327): Validation of
	/vz/igor/Virtuozzo/current/ploop/DiskDescriptor.xml failed:
	top delta {5fbaabe3-6958-40ff-92a7-860e329aab41} is temporary

Reference: ploop@1016684
do_delete_snapshot(): fix a warning

Fix and improve a warning message about inability to remove a snapshot
with >1 references to it, and marking it as temp.

This is an addition to commit ploop@1016663 aka 32711a4.

Reference: ploop@1016859
Signed-off-by: Kir Kolyshkin <kir@openvz.org>
merge_temporary_snapshots: fix infinite loop

In case a snapshot with references deleted, there's an infinite loop.

Reference: ploop@1019621
ploop_switch_snapshot_ex: fixed case with PLOOP_SNAP_SKIP_TOPDELTA_CREATE

The PLOOP_SNAP_SKIP_TOPDELTA_CREATE used in rollback, move logic to separate function

Reference: ploop@1019626
reset_top_delta(): rm irrelevant message

Apparently a copy-paste leftover.

This is an addition to commit 86f3119 (ploop@1019626)

Reference: ploop@1020175
Signed-off-by: Kir Kolyshkin <kir@openvz.org>
ploop_delete_snapshot: fix for temp snapshot

In case snapshot guid supplied is one of temp snapshot, we first
implicitly delete it in merge_temporary_snapshots(), then try to
delete it again explicitly in do_delete_snapshot() and we fail.

To fix, move merge_temporary_snapshots() to after do_delete_snapshot.

Reference: PSBM-27327 "Error in do_delete_snapshot (snapshot.c:61): Can't find snapshot by uuid"
Reference: ploop@1021028, ploop@1021092
Signed-off-by: Kir Kolyshkin <kir@openvz.org>
tune_fs(): use EXT4_IOC_SET_RSV_BLOCKS if available

We have to update reservation block counts according to balloon size.
One can do that directly via tune2fs which is not good for mounted fs,
and should use this ioctl instead

EXT4_IOC_SET_RSV_BLOCKS is available since 042stab092.1. In case it's
not there, fall back to old implementation.

Signed-off-by: dmonakhov@openvz.org
Committed-by: igor@openvz.org
Reference: PSBM-25929 "Error in __ploop_discard (balloon.c:1053): The trim process failed with code 1"
Reference: ploop@1022894
tune_fs: fix error message, assorted nitpicks

A few nitpicks after commit 5a0ab39 (ploop@1022894),
in the order of importance;

1. Fix an error message (s/for size/to/, obviously a copy-paste error)

2. Pass errno to ploop_err() to know why ioctl failed

3. An empty line between variable declarations and code

4. Some more empty lines to improve code readability.

5. A comma in a comment.

Reference: ploop@1025878
Signed-off-by: Kir Kolyshkin <kir@openvz.org>
ploop info: add -d to show ploop device

Reference: PSBM-26990

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@parallels.com>
Acked-by: Igor Sukhih <igor@parallels.com>
References: ploop@1025015, ploop@1026043
ploop(8): document ploop info -d

This is an addition to commit 0b51f0d

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
create_snapshot: clear stale top delta inuse flag

Sometimes after the node crash the top delta in-use flag is left set, so
snapshot creation returns an error.

Handle this particular case by calling check_delta to validate top delta
and drop inuse flag on create snapshot.

Reference: PSBM-27694 "Failed to create the snapshot: Operation failed. %1 after node crash"
References: ploop@1025736, ploop@1026188
Signed-off-by: Kir Kolyshkin <kir@openvz.org>
De-introduce SYSEXIT_INUSE

This was introduced by the previous commit 22ff44b (aka ploop@1025736)
for the sole purpose of reporting the "in-use flag is set" condition
from get_image_param_offline(), which, in turn, takes it from
errno value explicitly set to EBUSY by open_delta().
This condition is then checked in the only place --
do_create_snapshot().

Note that SYSEXIT_* codes are part of public API, but this
new value is not actually returned by any of the public API
functions. Therefore, let's apply the Occam razor here.

That abovementioned commit also silently fixes returning -1 from
get_image_param_offline() -- this is good and this patch retains
the fix.

So, this patch reverts the logic of checking errno in
get_image_param_offline(), moving the check directly to
do_create_snapshot().

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