mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
virt-sparsify --in-place: Exit with code 3 if discard is not supported.
Also skip the test in this case instead of failing.
This commit is contained in:
@@ -24,7 +24,7 @@ open Common_gettext.Gettext
|
||||
open Common_utils
|
||||
|
||||
let prog = Filename.basename Sys.executable_name
|
||||
let error fs = error ~prog fs
|
||||
let error ?exit_code fs = error ~prog ?exit_code fs
|
||||
|
||||
type mode_t =
|
||||
| Mode_copying of string * check_t * bool * string option * string option
|
||||
|
||||
@@ -28,12 +28,23 @@ module G = Guestfs
|
||||
open Common_utils
|
||||
open Cmdline
|
||||
|
||||
let run disk format ignores machine_readable quiet verbose trace zeroes =
|
||||
let rec run disk format ignores machine_readable quiet verbose trace zeroes =
|
||||
(* Connect to libguestfs. *)
|
||||
let g = new G.guestfs () in
|
||||
if trace then g#set_trace true;
|
||||
if verbose then g#set_verbose true;
|
||||
|
||||
try
|
||||
perform g disk format ignores machine_readable quiet zeroes
|
||||
with
|
||||
G.Error msg as exn ->
|
||||
if g#last_errno () = G.Errno.errno_ENOTSUP then (
|
||||
(* for exit code 3, see man page *)
|
||||
error ~exit_code:3 (f_"discard/trim is not supported: %s") msg;
|
||||
)
|
||||
else raise exn
|
||||
|
||||
and perform g disk format ignores machine_readable quiet zeroes =
|
||||
(* XXX Current limitation of the API. Can remove this hunk in future. *)
|
||||
let format =
|
||||
match format with
|
||||
|
||||
@@ -49,7 +49,13 @@ EOF
|
||||
|
||||
size_before=$(du -s test-virt-sparsify-in-place.img | awk '{print $1}')
|
||||
|
||||
$VG ./virt-sparsify --debug-gc --in-place test-virt-sparsify-in-place.img
|
||||
$VG ./virt-sparsify --debug-gc --in-place test-virt-sparsify-in-place.img || {
|
||||
if [ "$?" -eq 3 ]; then
|
||||
echo "$0: discard not supported in virt-sparsify"
|
||||
exit 77
|
||||
fi
|
||||
exit 1
|
||||
}
|
||||
|
||||
size_after=$(du -s test-virt-sparsify-in-place.img | awk '{print $1}')
|
||||
|
||||
|
||||
@@ -381,6 +381,17 @@ temporary space are B<not> required.
|
||||
|
||||
For other environment variables, see L<guestfs(3)/ENVIRONMENT VARIABLES>.
|
||||
|
||||
=head1 EXIT STATUS
|
||||
|
||||
This program returns 0 if the operation completed without errors.
|
||||
(This doesn't necessarily mean that space could be freed up.)
|
||||
|
||||
A non-zero exit code indicates an error.
|
||||
|
||||
If the exit code is C<3> and the I<--in-place> option was used, that
|
||||
indicates that discard support is not available in libguestfs, so
|
||||
copying mode must be used instead.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
L<virt-filesystems(1)>,
|
||||
|
||||
Reference in New Issue
Block a user