sparsify: Add -o option for passing qemu-img output format options.
authorRichard W.M. Jones <rjones@redhat.com>
Tue, 22 Nov 2011 10:11:10 +0000 (10:11 +0000)
committerRichard W.M. Jones <rjones@redhat.com>
Tue, 22 Nov 2011 10:11:10 +0000 (10:11 +0000)
sparsify/sparsify.ml
sparsify/virt-sparsify.pod

index 47dbbb9..4e438ac 100644 (file)
@@ -29,7 +29,7 @@ let () = Random.self_init ()
 let prog = Filename.basename Sys.executable_name
 
 let indisk, outdisk, compress, convert, format, ignores, machine_readable,
 let prog = Filename.basename Sys.executable_name
 
 let indisk, outdisk, compress, convert, format, ignores, machine_readable,
-  quiet, verbose, trace =
+  option, quiet, verbose, trace =
   let display_version () =
     let g = new G.guestfs () in
     let version = g#version () in
   let display_version () =
     let g = new G.guestfs () in
     let version = g#version () in
@@ -45,6 +45,7 @@ let indisk, outdisk, compress, convert, format, ignores, machine_readable,
   let format = ref "" in
   let ignores = ref [] in
   let machine_readable = ref false in
   let format = ref "" in
   let ignores = ref [] in
   let machine_readable = ref false in
+  let option = ref "" in
   let quiet = ref false in
   let verbose = ref false in
   let trace = ref false in
   let quiet = ref false in
   let verbose = ref false in
   let trace = ref false in
@@ -55,6 +56,7 @@ let indisk, outdisk, compress, convert, format, ignores, machine_readable,
     "--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";
     "--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";
+    "-o",        Arg.Set_string option,     "option Add qemu-img options";
     "-q",        Arg.Set quiet,             " Quiet output";
     "--quiet",   Arg.Set quiet,             " -\"-";
     "-v",        Arg.Set verbose,           " Enable debugging messages";
     "-q",        Arg.Set quiet,             " Quiet output";
     "--quiet",   Arg.Set quiet,             " -\"-";
     "-v",        Arg.Set verbose,           " Enable debugging messages";
@@ -83,6 +85,7 @@ read the man page virt-sparsify(1).
   let format = match !format with "" -> None | str -> Some str in
   let ignores = List.rev !ignores in
   let machine_readable = !machine_readable in
   let format = match !format with "" -> None | str -> Some str in
   let ignores = List.rev !ignores in
   let machine_readable = !machine_readable in
+  let option = match !option with "" -> None | str -> Some str in
   let quiet = !quiet in
   let verbose = !verbose in
   let trace = !trace in
   let quiet = !quiet in
   let verbose = !verbose in
   let trace = !trace in
@@ -126,7 +129,7 @@ read the man page virt-sparsify(1).
     error "input filename '%s' contains a comma; qemu-img command line syntax prevents us from using such an image" indisk;
 
   indisk, outdisk, compress, convert, format, ignores, machine_readable,
     error "input filename '%s' contains a comma; qemu-img command line syntax prevents us from using such an image" indisk;
 
   indisk, outdisk, compress, convert, format, ignores, machine_readable,
-  quiet, verbose, trace
+  option, quiet, verbose, trace
 
 let () =
   if not quiet then
 
 let () =
   if not quiet then
@@ -290,11 +293,14 @@ let () =
     printf "Copy to destination and make sparse ...\n%!";
 
   let cmd =
     printf "Copy to destination and make sparse ...\n%!";
 
   let cmd =
-    sprintf "qemu-img convert -f qcow2 -O %s%s %s %s"
+    sprintf "qemu-img convert -f qcow2 -O %s%s%s %s %s"
       (Filename.quote output_format)
       (if compress then " -c" else "")
       (Filename.quote output_format)
       (if compress then " -c" else "")
+      (match option with
+      | None -> ""
+      | Some option -> " -o " ^ Filename.quote option)
       (Filename.quote overlaydisk) (Filename.quote outdisk) in
       (Filename.quote overlaydisk) (Filename.quote outdisk) in
-  if verbose then
+(*  if verbose then*)
     printf "%s\n%!" cmd;
   if Sys.command cmd <> 0 then
     error "external command failed: %s" cmd
     printf "%s\n%!" cmd;
   if Sys.command cmd <> 0 then
     error "external command failed: %s" cmd
index d25f013..6653787 100644 (file)
@@ -126,7 +126,7 @@ eg. C<vmdk>, but support for other formats is reliant on qemu.
 Specifying the I<--convert> option is usually a good idea, because
 then virt-sparsify doesn't need to try to guess the input format.
 
 Specifying the I<--convert> option is usually a good idea, because
 then virt-sparsify doesn't need to try to guess the input format.
 
-For fine-tuning the output format, see: I<--compress>.
+For fine-tuning the output format, see: I<--compress>, I<-o>.
 
 =item B<--format> raw
 
 
 =item B<--format> raw
 
@@ -156,6 +156,18 @@ This option is used to make the output more machine friendly
 when being parsed by other programs.  See
 L</MACHINE READABLE OUTPUT> below.
 
 when being parsed by other programs.  See
 L</MACHINE READABLE OUTPUT> below.
 
+=item B<-o> option[,option,...]
+
+Pass I<-o> option(s) to the L<qemu-img(1)> command to fine-tune the
+output format.  Options available depend on the output format (see
+I<--convert>) and the installed version of the qemu-img program.
+
+You should use I<-o> at most once.  To pass multiple options, separate
+them with commas, eg:
+
+ virt-sparsify --convert qcow2 \
+   -o cluster_size=512,preallocation=metadata ...
+
 =item B<-q>
 
 =item B<--quiet>
 =item B<-q>
 
 =item B<--quiet>