[Pkg-libvirt-commits] [libguestfs] 33/66: v2v: lib_ovf: Change create_meta_files so it doesn't write the files.
Hilko Bengen
bengen at moszumanska.debian.org
Fri Oct 3 14:47:44 UTC 2014
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to annotated tag debian/1%1.27.54-1
in repository libguestfs.
commit 15556b614d5125cedb55d79a793e027a01e5fe67
Author: Richard W.M. Jones <rjones at redhat.com>
Date: Mon Sep 22 19:31:37 2014 +0100
v2v: lib_ovf: Change create_meta_files so it doesn't write the files.
Change Lib_ovf.create_meta_files so that instead of writing the
.meta files, it just returns the content. Output_rhev and
Output_vdsm are correspondingly changed so that they write the
content to the .meta files.
This is just code refactoring, there is no functional change.
---
v2v/lib_ovf.ml | 40 +++++++++++++++++++---------------------
v2v/lib_ovf.mli | 10 ++++++++--
v2v/output_rhev.ml | 11 ++++++++++-
v2v/output_vdsm.ml | 12 ++++++++++--
4 files changed, 47 insertions(+), 26 deletions(-)
diff --git a/v2v/lib_ovf.ml b/v2v/lib_ovf.ml
index 5bb1794..fcba087 100644
--- a/v2v/lib_ovf.ml
+++ b/v2v/lib_ovf.ml
@@ -157,10 +157,8 @@ let create_meta_files verbose output_alloc sd_uuid image_uuid targets =
| `Sparse -> "SPARSE"
| `Preallocated -> "PREALLOCATED" in
- List.iter (
- fun ({ target_overlay = ov; target_file = target_file } as t) ->
- let vol_meta = target_file ^ ".meta" in
-
+ List.map (
+ fun ({ target_overlay = ov } as t) ->
let size_in_sectors =
if ov.ov_virtual_size &^ 511L <> 0L then
error (f_"the virtual size of the input disk %s is not an exact multiple of 512 bytes. The virtual size is: %Ld.\n\nThis probably means something unexpected is going on, so please file a bug about this issue.")
@@ -175,23 +173,23 @@ let create_meta_files verbose output_alloc sd_uuid image_uuid targets =
| _ ->
error (f_"RHEV does not support the output format '%s', only raw or qcow2") t.target_format in
- let chan = open_out vol_meta in
- let fpf fs = fprintf chan fs in
- fpf "DOMAIN=%s\n" sd_uuid; (* "Domain" as in Storage Domain *)
- fpf "VOLTYPE=LEAF\n";
- fpf "CTIME=%.0f\n" time;
- fpf "MTIME=%.0f\n" time;
- fpf "IMAGE=%s\n" image_uuid;
- fpf "DISKTYPE=1\n";
- fpf "PUUID=00000000-0000-0000-0000-000000000000\n";
- fpf "LEGALITY=LEGAL\n";
- fpf "POOL_UUID=\n";
- fpf "SIZE=%Ld\n" size_in_sectors;
- fpf "FORMAT=%s\n" format_for_rhev;
- fpf "TYPE=%s\n" output_alloc_for_rhev;
- fpf "DESCRIPTION=%s\n" title;
- fpf "EOF\n";
- close_out chan;
+ let buf = Buffer.create 256 in
+ let bpf fs = bprintf buf fs in
+ bpf "DOMAIN=%s\n" sd_uuid; (* "Domain" as in Storage Domain *)
+ bpf "VOLTYPE=LEAF\n";
+ bpf "CTIME=%.0f\n" time;
+ bpf "MTIME=%.0f\n" time;
+ bpf "IMAGE=%s\n" image_uuid;
+ bpf "DISKTYPE=1\n";
+ bpf "PUUID=00000000-0000-0000-0000-000000000000\n";
+ bpf "LEGALITY=LEGAL\n";
+ bpf "POOL_UUID=\n";
+ bpf "SIZE=%Ld\n" size_in_sectors;
+ bpf "FORMAT=%s\n" format_for_rhev;
+ bpf "TYPE=%s\n" output_alloc_for_rhev;
+ bpf "DESCRIPTION=%s\n" title;
+ bpf "EOF\n";
+ Buffer.contents buf
) targets
(* Create the OVF file. *)
diff --git a/v2v/lib_ovf.mli b/v2v/lib_ovf.mli
index b3d185b..6c5ceab 100644
--- a/v2v/lib_ovf.mli
+++ b/v2v/lib_ovf.mli
@@ -18,8 +18,14 @@
(** Functions for dealing with OVF files. *)
-val create_meta_files : bool -> [`Sparse|`Preallocated] -> string -> string -> Types.target list -> unit
-(** Generate the .meta file associated with each volume. *)
+val create_meta_files : bool -> [`Sparse|`Preallocated] -> string -> string -> Types.target list -> string list
+(** Create the .meta file associated with each target.
+
+
+ Note this does not write them, since output_rhev has to do a
+ permissions dance when writing files. Instead the contents of each
+ file is returned (one per target), and they must be written to
+ [target_file ^ ".meta"]. *)
val create_ovf : bool -> Types.source -> Types.target list -> Types.guestcaps -> Types.inspect -> [`Sparse|`Preallocated] -> [`Server|`Desktop] option -> string -> string -> string list -> string -> DOM.doc
(** Create the OVF file. *)
diff --git a/v2v/output_rhev.ml b/v2v/output_rhev.ml
index b90d200..59991ba 100644
--- a/v2v/output_rhev.ml
+++ b/v2v/output_rhev.ml
@@ -221,7 +221,16 @@ object
) (List.combine targets vol_uuids) in
(* Generate the .meta file associated with each volume. *)
- Lib_ovf.create_meta_files verbose output_alloc esd_uuid image_uuid targets;
+ let metas =
+ Lib_ovf.create_meta_files verbose output_alloc esd_uuid image_uuid
+ targets in
+ List.iter (
+ fun ({ target_file = target_file }, meta) ->
+ let meta_filename = target_file ^ ".meta" in
+ let chan = open_out meta_filename in
+ output_string chan meta;
+ close_out chan
+ ) (List.combine targets metas);
(* Return the list of targets. *)
targets
diff --git a/v2v/output_vdsm.ml b/v2v/output_vdsm.ml
index 08d3f09..375fdc4 100644
--- a/v2v/output_vdsm.ml
+++ b/v2v/output_vdsm.ml
@@ -130,8 +130,16 @@ object
) (List.combine targets vdsm_params.vol_uuids) in
(* Generate the .meta files associated with each volume. *)
- Lib_ovf.create_meta_files verbose output_alloc dd_uuid
- vdsm_params.image_uuid targets;
+ let metas =
+ Lib_ovf.create_meta_files verbose output_alloc dd_uuid
+ vdsm_params.image_uuid targets in
+ List.iter (
+ fun ({ target_file = target_file }, meta) ->
+ let meta_filename = target_file ^ ".meta" in
+ let chan = open_out meta_filename in
+ output_string chan meta;
+ close_out chan
+ ) (List.combine targets metas);
(* Return the list of targets. *)
targets
--
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