summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-10-11 13:23:24 +0000
committerRichard W.M. Jones <rjones@redhat.com>2012-10-30 17:14:23 +0000
commit07b409ff9a2b4594b01fad3b6c53adbec2d31ad7 (patch)
treec9014bd4bbe363f8964923ebe61e6e6ba08b3663
parent44d69a19f56f57843ad5b6382bcfca19e99b8af1 (diff)
downloadlibguestfs-07b409ff9a2b4594b01fad3b6c53adbec2d31ad7.tar.gz
libguestfs-07b409ff9a2b4594b01fad3b6c53adbec2d31ad7.tar.xz
libguestfs-07b409ff9a2b4594b01fad3b6c53adbec2d31ad7.zip
sparsify: Re-use progress bar wrapper code from virt-resize.
The code was identical -- just copied with s/resize/sparsify/. Instead of duplicating identical code, cause the Makefile.am to use the code from the ../resize/ directory. Unfortunately because there are two Utils modules (which are different), this means we had to rename those modules to Resize_utils and Sparsify_utils respectively. So this is a rather larger change than intended. However it's just code motion. (cherry picked from commit 91b2238fc8e462c02f697f0c053043a55f43c13d)
-rw-r--r--.gitignore2
-rw-r--r--po/POTFILES1
-rw-r--r--po/POTFILES-ml7
-rw-r--r--resize/Makefile.am12
-rw-r--r--resize/progress.ml2
-rw-r--r--resize/resize.ml2
-rw-r--r--resize/resize_utils.ml (renamed from resize/utils.ml)0
-rw-r--r--resize/resize_utils_tests.ml (renamed from resize/utils_tests.ml)12
-rw-r--r--sparsify/Makefile.am13
-rw-r--r--sparsify/progress-c.c105
-rw-r--r--sparsify/progress.ml54
-rw-r--r--sparsify/progress.mli19
-rw-r--r--sparsify/sparsify.ml2
-rw-r--r--sparsify/sparsify_utils.ml (renamed from sparsify/utils.ml)0
14 files changed, 23 insertions, 208 deletions
diff --git a/.gitignore b/.gitignore
index 4ef05fe9..86fa6072 100644
--- a/.gitignore
+++ b/.gitignore
@@ -313,8 +313,8 @@ Makefile.in
/rescue/virt-rescue.1
/resize/.depend
/resize/resize_gettext.ml
+/resize/resize_utils_tests
/resize/stamp-virt-resize.pod
-/resize/utils_tests
/resize/virt-resize
/resize/virt-resize.1
/ruby/bindtests.rb
diff --git a/po/POTFILES b/po/POTFILES
index 30aff56b..2ad2eb37 100644
--- a/po/POTFILES
+++ b/po/POTFILES
@@ -186,7 +186,6 @@ python/guestfs-py.c
rescue/virt-rescue.c
resize/progress-c.c
ruby/ext/guestfs/_guestfs.c
-sparsify/progress-c.c
src/actions.c
src/appliance.c
src/bindtests.c
diff --git a/po/POTFILES-ml b/po/POTFILES-ml
index 5d5abace..8deeeaa3 100644
--- a/po/POTFILES-ml
+++ b/po/POTFILES-ml
@@ -1,12 +1,11 @@
resize/progress.ml
resize/resize.ml
resize/resize_gettext.ml
-resize/utils.ml
-resize/utils_tests.ml
-sparsify/progress.ml
+resize/resize_utils.ml
+resize/resize_utils_tests.ml
sparsify/sparsify.ml
sparsify/sparsify_gettext.ml
-sparsify/utils.ml
+sparsify/sparsify_utils.ml
sysprep/main.ml
sysprep/sysprep_gettext.ml
sysprep/sysprep_operation.ml
diff --git a/resize/Makefile.am b/resize/Makefile.am
index 8bb093d2..d9123613 100644
--- a/resize/Makefile.am
+++ b/resize/Makefile.am
@@ -37,8 +37,8 @@ SOURCES = \
progress.ml \
resize.ml \
resize_gettext.ml \
- utils.ml \
- utils_tests.ml
+ resize_utils.ml \
+ resize_utils_tests.ml
if HAVE_OCAML
@@ -47,7 +47,7 @@ OBJECTS = \
$(top_builddir)/fish/guestfish-progress.o \
progress-c.o \
resize_gettext.cmx \
- utils.cmx \
+ resize_utils.cmx \
progress.cmx \
resize.cmx
@@ -103,9 +103,9 @@ CLEANFILES += stamp-virt-resize.pod
# Tests.
-check_SCRIPTS = utils_tests
+check_SCRIPTS = resize_utils_tests
-utils_tests: resize_gettext.cmx utils.cmx utils_tests.cmx
+resize_utils_tests: resize_gettext.cmx resize_utils.cmx resize_utils_tests.cmx
$(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) \
mlguestfs.cmxa -linkpkg $^ -cclib -lncurses -o $@
@@ -115,7 +115,7 @@ TESTS_ENVIRONMENT = \
MALLOC_PERTURB_=$(random_val) \
$(top_builddir)/run
-TESTS = utils_tests
+TESTS = resize_utils_tests
if ENABLE_APPLIANCE
TESTS += test-virt-resize.sh
endif
diff --git a/resize/progress.ml b/resize/progress.ml
index e4fd47e0..993a0b7d 100644
--- a/resize/progress.ml
+++ b/resize/progress.ml
@@ -18,8 +18,6 @@
open Printf
-open Utils
-
module G = Guestfs
type progress_bar
diff --git a/resize/resize.ml b/resize/resize.ml
index 23c5101b..cec73b3c 100644
--- a/resize/resize.ml
+++ b/resize/resize.ml
@@ -22,7 +22,7 @@ open Resize_gettext.Gettext
module G = Guestfs
-open Utils
+open Resize_utils
(* Minimum surplus before we create an extra partition. *)
let min_extra_partition = 10L *^ 1024L *^ 1024L
diff --git a/resize/utils.ml b/resize/resize_utils.ml
index d99f489b..d99f489b 100644
--- a/resize/utils.ml
+++ b/resize/resize_utils.ml
diff --git a/resize/utils_tests.ml b/resize/resize_utils_tests.ml
index 9356d7b6..2d4b816e 100644
--- a/resize/utils_tests.ml
+++ b/resize/resize_utils_tests.ml
@@ -16,16 +16,16 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*)
-(* This file tests the Utils module. *)
+(* This file tests the Resize_utils module. *)
-open Utils
+open Resize_utils
-(* Test Utils.int_of_le32 and Utils.le32_of_int. *)
+(* Test Resize_utils.int_of_le32 and Resize_utils.le32_of_int. *)
let () =
assert (int_of_le32 "\x80\x60\x40\x20" = 0x20406080L);
assert (le32_of_int 0x20406080L = "\x80\x60\x40\x20")
-(* Test Utils.canonicalize. *)
+(* Test Resize_utils.canonicalize. *)
let () =
assert (canonicalize "/dev/vda" = "/dev/sda");
assert (canonicalize "/dev/hda3" = "/dev/sda3");
@@ -34,7 +34,7 @@ let () =
assert (canonicalize "/dev/sdaa" = "/dev/sdaa");
assert (canonicalize "/dev/cciss/c0d0p1" = "/dev/cciss/c0d0p1")
-(* Test Utils.parse_size. *)
+(* Test Resize_utils.parse_size. *)
let () =
(* For absolute sizes, oldsize is ignored. *)
assert (parse_size 100_L "100b" = 100_L);
@@ -73,7 +73,7 @@ let () =
assert (parse_size 100000_L "+1.1%" = 101100_L);
assert (parse_size 100000_L "+1.12%" = 101100_L)
-(* Test Utils.human_size. *)
+(* Test Resize_utils.human_size. *)
let () =
assert (human_size 100_L = "100");
assert (human_size (-100_L) = "-100");
diff --git a/sparsify/Makefile.am b/sparsify/Makefile.am
index e037adae..d2a4d8e7 100644
--- a/sparsify/Makefile.am
+++ b/sparsify/Makefile.am
@@ -32,22 +32,19 @@ CLEANFILES = *~ *.cmi *.cmo *.cmx *.cmxa *.o virt-sparsify test.img
# Alphabetical order.
SOURCES = \
- progress-c.c \
- progress.mli \
- progress.ml \
sparsify.ml \
sparsify_gettext.ml \
- utils.ml
+ sparsify_utils.ml
if HAVE_OCAML
# Note this list must be in dependency order.
OBJECTS = \
$(top_builddir)/fish/guestfish-progress.o \
- progress-c.o \
+ $(top_builddir)/resize/progress-c.o \
sparsify_gettext.cmx \
- utils.cmx \
- progress.cmx \
+ sparsify_utils.cmx \
+ $(top_builddir)/resize/progress.cmx \
sparsify.cmx
bin_SCRIPTS = virt-sparsify
@@ -55,7 +52,7 @@ bin_SCRIPTS = virt-sparsify
# -I $(top_builddir)/src/.libs is a hack which forces corresponding -L
# option to be passed to gcc, so we don't try linking against an
# installed copy of libguestfs.
-OCAMLPACKAGES = -package unix -I $(top_builddir)/src/.libs -I $(top_builddir)/ocaml
+OCAMLPACKAGES = -package unix -I $(top_builddir)/src/.libs -I $(top_builddir)/ocaml -I $(top_builddir)/resize
if HAVE_OCAML_PKG_GETTEXT
OCAMLPACKAGES += -package gettext-stub
endif
diff --git a/sparsify/progress-c.c b/sparsify/progress-c.c
deleted file mode 100644
index 81137289..00000000
--- a/sparsify/progress-c.c
+++ /dev/null
@@ -1,105 +0,0 @@
-/* virt-sparsify - interface to progress bar mini library
- * Copyright (C) 2011 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include <config.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
-#include <locale.h>
-
-#include <caml/alloc.h>
-#include <caml/custom.h>
-#include <caml/fail.h>
-#include <caml/memory.h>
-#include <caml/mlvalues.h>
-
-#include "progress.h"
-
-#define Bar_val(v) (*((struct progress_bar **)Data_custom_val(v)))
-
-static void
-progress_bar_finalize (value barv)
-{
- struct progress_bar *bar = Bar_val (barv);
-
- if (bar)
- progress_bar_free (bar);
-}
-
-static struct custom_operations progress_bar_custom_operations = {
- (char *) "progress_bar_custom_operations",
- progress_bar_finalize,
- custom_compare_default,
- custom_hash_default,
- custom_serialize_default,
- custom_deserialize_default
-};
-
-value
-virt_sparsify_progress_bar_init (value machine_readablev)
-{
- CAMLparam1 (machine_readablev);
- CAMLlocal1 (barv);
- struct progress_bar *bar;
- int machine_readable = Bool_val (machine_readablev);
- unsigned flags = 0;
-
- /* XXX Have to do this to get nl_langinfo to work properly. However
- * we should really only call this from main.
- */
- setlocale (LC_ALL, "");
-
- if (machine_readable)
- flags |= PROGRESS_BAR_MACHINE_READABLE;
- bar = progress_bar_init (flags);
- if (bar == NULL)
- caml_raise_out_of_memory ();
-
- barv = caml_alloc_custom (&progress_bar_custom_operations,
- sizeof (struct progress_bar *), 0, 1);
- Bar_val (barv) = bar;
-
- CAMLreturn (barv);
-}
-
-value
-virt_sparsify_progress_bar_reset (value barv)
-{
- CAMLparam1 (barv);
- struct progress_bar *bar = Bar_val (barv);
-
- progress_bar_reset (bar);
-
- CAMLreturn (Val_unit);
-}
-
-value
-virt_sparsify_progress_bar_set (value barv,
- value positionv, value totalv)
-{
- CAMLparam3 (barv, positionv, totalv);
- struct progress_bar *bar = Bar_val (barv);
- uint64_t position = Int64_val (positionv);
- uint64_t total = Int64_val (totalv);
-
- progress_bar_set (bar, position, total);
-
- CAMLreturn (Val_unit);
-}
diff --git a/sparsify/progress.ml b/sparsify/progress.ml
deleted file mode 100644
index f925a9c6..00000000
--- a/sparsify/progress.ml
+++ /dev/null
@@ -1,54 +0,0 @@
-(* virt-sparsify
- * Copyright (C) 2010-2012 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *)
-
-open Printf
-
-open Utils
-
-module G = Guestfs
-
-type progress_bar
-external progress_bar_init : machine_readable:bool -> progress_bar
- = "virt_sparsify_progress_bar_init"
-external progress_bar_reset : progress_bar -> unit
- = "virt_sparsify_progress_bar_reset"
-external progress_bar_set : progress_bar -> int64 -> int64 -> unit
- = "virt_sparsify_progress_bar_set"
-
-let set_up_progress_bar ?(machine_readable = false) (g : Guestfs.guestfs) =
- (* Initialize the C mini library. *)
- let bar = progress_bar_init ~machine_readable in
-
- (* Reset the progress bar before every libguestfs function. *)
- let enter_callback g event evh buf array =
- if event = G.EVENT_ENTER then
- progress_bar_reset bar
- in
-
- (* A progress event: move the progress bar. *)
- let progress_callback g event evh buf array =
- if event = G.EVENT_PROGRESS && Array.length array >= 4 then (
- let position = array.(2)
- and total = array.(3) in
-
- progress_bar_set bar position total
- )
- in
-
- ignore (g#set_event_callback enter_callback [G.EVENT_ENTER]);
- ignore (g#set_event_callback progress_callback [G.EVENT_PROGRESS])
diff --git a/sparsify/progress.mli b/sparsify/progress.mli
deleted file mode 100644
index 677df677..00000000
--- a/sparsify/progress.mli
+++ /dev/null
@@ -1,19 +0,0 @@
-(* virt-sparsify
- * Copyright (C) 2010-2012 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *)
-
-val set_up_progress_bar : ?machine_readable:bool -> Guestfs.guestfs -> unit
diff --git a/sparsify/sparsify.ml b/sparsify/sparsify.ml
index f7a1d561..ccece63b 100644
--- a/sparsify/sparsify.ml
+++ b/sparsify/sparsify.ml
@@ -23,7 +23,7 @@ open Sparsify_gettext.Gettext
module G = Guestfs
-open Utils
+open Sparsify_utils
let () = Random.self_init ()
diff --git a/sparsify/utils.ml b/sparsify/sparsify_utils.ml
index dd27ba88..dd27ba88 100644
--- a/sparsify/utils.ml
+++ b/sparsify/sparsify_utils.ml