X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=sparsify%2Fsparsify.ml;h=9a46495e5c80040f3597f3a9b1f42c72e0d4f8bf;hb=eb77965e00365e8c5652264ad569653c82b0de23;hp=89a2c1377d024eed0aad1b3d976869a4cc6e06d8;hpb=fac15924f59a076c903d453d20305e00e1ae258a;p=libguestfs.git diff --git a/sparsify/sparsify.ml b/sparsify/sparsify.ml index 89a2c13..9a46495 100644 --- a/sparsify/sparsify.ml +++ b/sparsify/sparsify.ml @@ -28,7 +28,8 @@ let () = Random.self_init () (* Command line argument parsing. *) let prog = Filename.basename Sys.executable_name -let indisk, outdisk, convert, format, ignores, machine_readable, quiet, +let indisk, outdisk, convert, debug_gc, + format, ignores, machine_readable, quiet, verbose, trace = let display_version () = let g = new G.guestfs () in @@ -41,6 +42,7 @@ let indisk, outdisk, convert, format, ignores, machine_readable, quiet, let add xs s = xs := s :: !xs in let convert = ref "" in + let debug_gc = ref false in let format = ref "" in let ignores = ref [] in let machine_readable = ref false in @@ -50,6 +52,7 @@ let indisk, outdisk, convert, format, ignores, machine_readable, quiet, let argspec = Arg.align [ "--convert", Arg.Set_string convert, "format Format of output disk (default: same as input)"; + "--debug-gc", Arg.Set debug_gc, " Debug GC and memory allocations"; "--format", Arg.Set_string format, "format Format of input disk"; "--ignore", Arg.String (add ignores), "fs Ignore filesystem"; "--machine-readable", Arg.Set machine_readable, " Make output machine readable"; @@ -77,6 +80,7 @@ read the man page virt-sparsify(1). (* Dereference the rest of the args. *) let convert = match !convert with "" -> None | str -> Some str in + let debug_gc = !debug_gc in let format = match !format with "" -> None | str -> Some str in let ignores = List.rev !ignores in let machine_readable = !machine_readable in @@ -122,8 +126,9 @@ read the man page virt-sparsify(1). if contains_comma then error "input filename '%s' contains a comma; qemu-img command line syntax prevents us from using such an image" indisk; - indisk, outdisk, convert, format, ignores, machine_readable, quiet, - verbose, trace + indisk, outdisk, convert, + debug_gc, format, ignores, machine_readable, quiet, + verbose, trace let () = if not quiet then @@ -177,10 +182,15 @@ let () = let filesystems = g#list_filesystems () in let filesystems = List.map fst filesystems in let filesystems = List.sort compare filesystems in + + let is_ignored fs = + let fs = canonicalize fs in + List.exists (fun fs' -> fs = canonicalize fs') ignores + in + List.iter ( fun fs -> - if not (List.mem fs ignores) then ( - + if not (is_ignored fs) then ( let mounted = try g#mount_options "" fs "/"; true with _ -> false in @@ -269,6 +279,8 @@ let output_format = ); if string_prefix line "QEMU QCOW Image (v2)" then "qcow2" + else if string_find line "VirtualBox" >= 0 then + "vdi" else "raw" (* XXX guess *) @@ -295,4 +307,7 @@ let () = wrap "Sparsify operation completed with no errors. Before deleting the old disk, carefully check that the target disk boots and works correctly.\n"; ); + if debug_gc then + Gc.compact (); + exit 0