[Libguestfs] [PATCH] v2v: ova: Don't rely on qemu-img version, test "offset" and "size" features.

Tomáš Golembiovský tgolembi at redhat.com
Mon Feb 6 18:41:05 UTC 2017


On Mon,  6 Feb 2017 15:40:01 +0000
"Richard W.M. Jones" <rjones at redhat.com> wrote:

> +let qemu_img_supports_offset_and_size () =
> +  (* We actually attempt to create a qcow2 file with a raw backing
> +   * file that has an offset and size.
> +   *)
> +  let tmp1 = Filename.temp_file "v2vqemuimgtst" ".img"
> +  and tmp2 = Filename.temp_file "v2vqemuimgtst" ".img" in
> +  Unix.truncate tmp2 1024;
> +
> +  let json = [
> +      "file", JSON.Dict [
> +        "driver", JSON.String "raw";
> +        "offset", JSON.Int 512;
> +        "size", JSON.Int 512;
> +        "file", JSON.Dict [
> +          "filename", JSON.String tmp2
> +        ]
> +      ]
> +  ] in
> +
> +  let cmd =
> +    sprintf "qemu-img create %s -f qcow2 -b 'json:%s'%s"
> +            (quote tmp1)
> +            (quote (JSON.string_of_doc ~fmt:JSON.Compact json))
> +            (if verbose () then "" else " >/dev/null 2>&1") in
> +
> +  let r = Sys.command cmd in
> +
> +  Unix.unlink tmp1;
> +  Unix.unlink tmp2;
> +

LGTM. But you can avoid the temporary files as I mentioned here:

https://www.redhat.com/archives/libguestfs/2017-February/msg00079.html

    Tomas

-- 
Tomáš Golembiovský <tgolembi at redhat.com>




More information about the Libguestfs mailing list