[Libguestfs] [PATCH v3 08/10] sysprep: Add disks with discard = "besteffort".

Richard W.M. Jones rjones at redhat.com
Wed Mar 12 14:26:15 UTC 2014


Since virt-sysprep tends to delete a lot of files, adding discard
support to it makes some sense.

Note that this probably won't have any effect for most filesystems
since:

(a) ext4 mounts also need to use -o discard,

(b) ext4, and maybe others, require you to call fstrim explicitly,
they don't discard automatically (except for userspace tools like
mkfs.ext4 but that doesn't apply in this case).
---
 sysprep/main.ml | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/sysprep/main.ml b/sysprep/main.ml
index 6f631d5..9047a74 100644
--- a/sysprep/main.ml
+++ b/sysprep/main.ml
@@ -198,7 +198,11 @@ read the man page virt-sysprep(1).
       fun (g : Guestfs.guestfs) readonly ->
         let allowuuid = true in
         let readonlydisk = "ignore" (* ignore CDs, data drives *) in
-        ignore (g#add_domain ~readonly ?libvirturi ~allowuuid ~readonlydisk dom)
+        let discard = if readonly then None else Some "besteffort" in
+        ignore (g#add_domain
+                  ~readonly ?discard
+                  ?libvirturi ~allowuuid ~readonlydisk
+                  dom)
     | _, Some _ ->
       eprintf (f_"%s: you cannot give -a and -d options together\n") prog;
       eprintf (f_"Read virt-sysprep(1) man page for further information.\n");
@@ -209,7 +213,11 @@ read the man page virt-sysprep(1).
           fun (uri, format) ->
             let { URI.path = path; protocol = protocol;
                   server = server; username = username } = uri in
-            g#add_drive ~readonly ?format ~protocol ?server ?username path
+            let discard = if readonly then None else Some "besteffort" in
+            g#add_drive
+              ~readonly ?discard
+              ?format ~protocol ?server ?username
+              path
         ) files
   in
 
-- 
1.8.5.3




More information about the Libguestfs mailing list