[Pkg-libvirt-commits] [libguestfs] 04/26: virt-sparsify --in-place: Exit with code 3 if discard is not supported.

Hilko Bengen bengen at moszumanska.debian.org
Thu Mar 20 23:06:08 UTC 2014


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to annotated tag upstream/1.25.46
in repository libguestfs.

commit 931aec5b8846ce63b0e2b6beba5861a019b5f694
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Mon Mar 17 12:02:58 2014 +0000

    virt-sparsify --in-place: Exit with code 3 if discard is not supported.
    
    Also skip the test in this case instead of failing.
---
 sparsify/cmdline.ml                     |  2 +-
 sparsify/in_place.ml                    | 13 ++++++++++++-
 sparsify/test-virt-sparsify-in-place.sh |  8 +++++++-
 sparsify/virt-sparsify.pod              | 11 +++++++++++
 4 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/sparsify/cmdline.ml b/sparsify/cmdline.ml
index d25e9e9..c96de57 100644
--- a/sparsify/cmdline.ml
+++ b/sparsify/cmdline.ml
@@ -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
diff --git a/sparsify/in_place.ml b/sparsify/in_place.ml
index 9f46ad3..624f676 100644
--- a/sparsify/in_place.ml
+++ b/sparsify/in_place.ml
@@ -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
diff --git a/sparsify/test-virt-sparsify-in-place.sh b/sparsify/test-virt-sparsify-in-place.sh
index 56311a0..dd32963 100755
--- a/sparsify/test-virt-sparsify-in-place.sh
+++ b/sparsify/test-virt-sparsify-in-place.sh
@@ -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}')
 
diff --git a/sparsify/virt-sparsify.pod b/sparsify/virt-sparsify.pod
index c12a15f..59ef4f2 100644
--- a/sparsify/virt-sparsify.pod
+++ b/sparsify/virt-sparsify.pod
@@ -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)>,

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list