mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
sparsify: Exit with error code 3 if fstrim is not supported by the appliance.
This replaces the indirect exception catching from commit931aec5b88with a direct feature test. Fixes commit931aec5b88.
This commit is contained in:
@@ -29,7 +29,7 @@ open Cmdline
|
||||
|
||||
module G = Guestfs
|
||||
|
||||
let rec run disk format ignores machine_readable zeroes =
|
||||
let run disk format ignores machine_readable zeroes =
|
||||
(* Connect to libguestfs. *)
|
||||
let g = open_guestfs () in
|
||||
|
||||
@@ -40,17 +40,6 @@ let rec run disk format ignores machine_readable zeroes =
|
||||
Sys.set_signal Sys.sigquit (Sys.Signal_handle set_quit);
|
||||
g#set_pgroup true;
|
||||
|
||||
try
|
||||
perform g disk format ignores machine_readable zeroes quit
|
||||
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 zeroes quit =
|
||||
(* XXX Current limitation of the API. Can remove this hunk in future. *)
|
||||
let format =
|
||||
match format with
|
||||
@@ -62,6 +51,12 @@ and perform g disk format ignores machine_readable zeroes quit =
|
||||
if not (quiet ()) then Progress.set_up_progress_bar ~machine_readable g;
|
||||
g#launch ();
|
||||
|
||||
(* If discard is not supported in the appliance, we must return exit
|
||||
* code 3. See the man page.
|
||||
*)
|
||||
if not (g#feature_available [|"fstrim"|]) then
|
||||
error ~exit_code:3 (f_"discard/trim is not supported");
|
||||
|
||||
(* Discard non-ignored filesystems that we are able to mount, and
|
||||
* selected swap partitions.
|
||||
*)
|
||||
|
||||
Reference in New Issue
Block a user