[PATCH] handle --debug-gc universally via at_exit hook
by Roman Kagan
Several tools handle --debug-gc command-line option, by explicitly
forcing GC on every exit path. This is tedious and prone to forgetting
some of the exit paths.
Instead, add a generic handler for --debug-gc, which installs an at_exit
hook to do the GC consistency check, and which can be called right in
the command-line parser. Also adjust all users of --debug-gc to use
that handler.
Signed-off-by: Roman Kagan <rkagan(a)virtuozzo.com>
---
customize/customize_main.ml | 9 ++-------
mllib/common_utils.ml | 4 ++++
mllib/common_utils.mli | 3 +++
resize/resize.ml | 13 ++++---------
sparsify/cmdline.ml | 6 ++----
sparsify/sparsify.ml | 7 ++-----
sysprep/main.ml | 13 ++++---------
v2v/cmdline.ml | 6 ++----
v2v/v2v.ml | 9 ++-------
9 files changed, 25 insertions(+), 45 deletions(-)
diff --git a/customize/customize_main.ml b/customize/customize_main.ml
index fa55c90..03c97e4 100644
--- a/customize/customize_main.ml
+++ b/customize/customize_main.ml
@@ -39,7 +39,6 @@ let main () =
| s -> attach_format := Some s
in
let attach_disk s = attach := (!attach_format, s) :: !attach in
- let debug_gc = ref false in
let domain = ref None in
let dryrun = ref false in
let files = ref [] in
@@ -79,7 +78,7 @@ let main () =
"format" ^ " " ^ s_"Set attach disk format";
"-c", Arg.Set_string libvirturi, s_"uri" ^ " " ^ s_"Set libvirt URI";
"--connect", Arg.Set_string libvirturi, s_"uri" ^ " " ^ s_"Set libvirt URI";
- "--debug-gc", Arg.Set debug_gc, " " ^ s_"Debug GC and memory allocations (internal)";
+ "--debug-gc", Arg.Unit set_debug_gc, " " ^ s_"Debug GC and memory allocations (internal)";
"-d", Arg.String set_domain, s_"domain" ^ " " ^ s_"Set libvirt guest name";
"--domain", Arg.String set_domain, s_"domain" ^ " " ^ s_"Set libvirt guest name";
"-n", Arg.Set dryrun, " " ^ s_"Perform a dry run";
@@ -174,7 +173,6 @@ read the man page virt-customize(1).
(* Dereference the rest of the args. *)
let attach = List.rev !attach in
- let debug_gc = !debug_gc in
let dryrun = !dryrun in
let memsize = !memsize in
let network = !network in
@@ -239,10 +237,7 @@ read the man page virt-customize(1).
message (f_"Finishing off");
g#shutdown ();
- g#close ();
-
- if debug_gc then
- Gc.compact ()
+ g#close ()
(* Finished. *)
let () = run_main_and_handle_errors main
diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml
index ca6d470..99d2098 100644
--- a/mllib/common_utils.ml
+++ b/mllib/common_utils.ml
@@ -759,3 +759,7 @@ let read_first_line_from_file filename =
let line = input_line chan in
close_in chan;
line
+
+(** Install an exit hook to check gc consistency for --debug-gc *)
+let set_debug_gc () =
+ at_exit (fun () -> Gc.compact())
diff --git a/mllib/common_utils.mli b/mllib/common_utils.mli
index ac232af..9d1ee6a 100644
--- a/mllib/common_utils.mli
+++ b/mllib/common_utils.mli
@@ -190,3 +190,6 @@ val last_part_of : string -> char -> string option
val read_first_line_from_file : string -> string
(** Read only the first line (i.e. until the first newline character)
of a file. *)
+
+val set_debug_gc : unit -> unit
+(** Install an exit hook to check gc consistency for --debug-gc *)
diff --git a/resize/resize.ml b/resize/resize.ml
index 101b303..8ab14f7 100644
--- a/resize/resize.ml
+++ b/resize/resize.ml
@@ -152,7 +152,7 @@ let string_of_expand_content_method = function
(* Main program. *)
let main () =
let infile, outfile, align_first, alignment, copy_boot_loader,
- debug_gc, deletes,
+ deletes,
dryrun, expand, expand_content, extra_partition, format, ignores,
lv_expands, machine_readable, ntfsresize_force, output_format,
resizes, resizes_force, shrink, sparse =
@@ -162,7 +162,6 @@ let main () =
let align_first = ref "auto" in
let alignment = ref 128 in
let copy_boot_loader = ref true in
- let debug_gc = ref false in
let deletes = ref [] in
let dryrun = ref false in
let expand = ref "" in
@@ -196,7 +195,7 @@ let main () =
"--no-copy-boot-loader", Arg.Clear copy_boot_loader, " " ^ s_"Don't copy boot loader";
"-d", Arg.Unit set_verbose, " " ^ s_"Enable debugging messages";
"--debug", Arg.Unit set_verbose, ditto;
- "--debug-gc",Arg.Set debug_gc, " " ^ s_"Debug GC and memory allocations";
+ "--debug-gc",Arg.Unit set_debug_gc, " " ^ s_"Debug GC and memory allocations";
"--delete", Arg.String (add deletes), s_"part" ^ " " ^ s_"Delete partition";
"--expand", Arg.String set_expand, s_"part" ^ " " ^ s_"Expand partition";
"--no-expand-content", Arg.Clear expand_content, " " ^ s_"Don't expand content";
@@ -250,7 +249,6 @@ read the man page virt-resize(1).
(* Dereference the rest of the args. *)
let alignment = !alignment in
let copy_boot_loader = !copy_boot_loader in
- let debug_gc = !debug_gc in
let deletes = List.rev !deletes in
let dryrun = !dryrun in
let expand = match !expand with "" -> None | str -> Some str in
@@ -325,7 +323,7 @@ read the man page virt-resize(1).
infile in
infile, outfile, align_first, alignment, copy_boot_loader,
- debug_gc, deletes,
+ deletes,
dryrun, expand, expand_content, extra_partition, format, ignores,
lv_expands, machine_readable, ntfsresize_force, output_format,
resizes, resizes_force, shrink, sparse in
@@ -1366,9 +1364,6 @@ read the man page virt-resize(1).
if not (quiet ()) then (
print_newline ();
wrap (s_"Resize operation completed with no errors. Before deleting the old disk, carefully check that the resized disk boots and works correctly.\n");
- );
-
- if debug_gc then
- Gc.compact ()
+ )
let () = run_main_and_handle_errors main
diff --git a/sparsify/cmdline.ml b/sparsify/cmdline.ml
index fe388f8..b2a57c3 100644
--- a/sparsify/cmdline.ml
+++ b/sparsify/cmdline.ml
@@ -46,7 +46,6 @@ let parse_cmdline () =
let compress = ref false in
let convert = ref "" in
- let debug_gc = ref false in
let format = ref "" in
let ignores = ref [] in
let in_place = ref false in
@@ -60,7 +59,7 @@ let parse_cmdline () =
"--check-tmpdir", Arg.String set_check_tmpdir, "ignore|..." ^ " " ^ s_"Check there is enough space in $TMPDIR";
"--compress", Arg.Set compress, " " ^ s_"Compressed output format";
"--convert", Arg.Set_string convert, s_"format" ^ " " ^ s_"Format of output disk (default: same as input)";
- "--debug-gc", Arg.Set debug_gc, " " ^ s_"Debug GC and memory allocations";
+ "--debug-gc", Arg.Unit set_debug_gc, " " ^ s_"Debug GC and memory allocations";
"--format", Arg.Set_string format, s_"format" ^ " " ^ s_"Format of input disk";
"--ignore", Arg.String (add ignores), s_"fs" ^ " " ^ s_"Ignore filesystem";
"--in-place", Arg.Set in_place, " " ^ s_"Modify the disk image in-place";
@@ -101,7 +100,6 @@ read the man page virt-sparsify(1).
let check_tmpdir = !check_tmpdir in
let compress = !compress in
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 in_place = !in_place in
@@ -188,4 +186,4 @@ read the man page virt-sparsify(1).
else
Mode_in_place in
- indisk, debug_gc, format, ignores, machine_readable, zeroes, mode
+ indisk, format, ignores, machine_readable, zeroes, mode
diff --git a/sparsify/sparsify.ml b/sparsify/sparsify.ml
index 1f631d8..30e3020 100644
--- a/sparsify/sparsify.ml
+++ b/sparsify/sparsify.ml
@@ -30,7 +30,7 @@ module G = Guestfs
let () = Random.self_init ()
let rec main () =
- let indisk, debug_gc, format, ignores, machine_readable, zeroes, mode =
+ let indisk, format, ignores, machine_readable, zeroes, mode =
parse_cmdline () in
(match mode with
@@ -39,9 +39,6 @@ let rec main () =
format ignores machine_readable option tmp zeroes
| Mode_in_place ->
In_place.run indisk format ignores machine_readable zeroes
- );
-
- if debug_gc then
- Gc.compact ()
+ )
let () = run_main_and_handle_errors main
diff --git a/sysprep/main.ml b/sysprep/main.ml
index da3dfd2..8b71109 100644
--- a/sysprep/main.ml
+++ b/sysprep/main.ml
@@ -34,8 +34,7 @@ let () = Sysprep_operation.bake ()
let () = Random.self_init ()
let main () =
- let debug_gc, operations, g, mount_opts =
- let debug_gc = ref false in
+ let operations, g, mount_opts =
let domain = ref None in
let dryrun = ref false in
let files = ref [] in
@@ -121,7 +120,7 @@ let main () =
"--add", Arg.String add_file, s_"file" ^ " " ^ s_"Add disk image file";
"-c", Arg.Set_string libvirturi, s_"uri" ^ " " ^ s_"Set libvirt URI";
"--connect", Arg.Set_string libvirturi, s_"uri" ^ " " ^ s_"Set libvirt URI";
- "--debug-gc", Arg.Set debug_gc, " " ^ s_"Debug GC and memory allocations (internal)";
+ "--debug-gc", Arg.Unit set_debug_gc, " " ^ s_"Debug GC and memory allocations (internal)";
"-d", Arg.String set_domain, s_"domain" ^ " " ^ s_"Set libvirt guest name";
"--domain", Arg.String set_domain, s_"domain" ^ " " ^ s_"Set libvirt guest name";
"-n", Arg.Set dryrun, " " ^ s_"Perform a dry run";
@@ -207,7 +206,6 @@ read the man page virt-sysprep(1).
in
(* Dereference the rest of the args. *)
- let debug_gc = !debug_gc in
let dryrun = !dryrun in
let operations = !operations in
@@ -234,7 +232,7 @@ read the man page virt-sysprep(1).
add g dryrun;
g#launch ();
- debug_gc, operations, g, mount_opts in
+ operations, g, mount_opts in
(* Inspection. *)
(match Array.to_list (g#inspect_os ()) with
@@ -277,9 +275,6 @@ read the man page virt-sysprep(1).
(* Finish off. *)
g#shutdown ();
- g#close ();
-
- if debug_gc then
- Gc.compact ()
+ g#close ()
let () = run_main_and_handle_errors main
diff --git a/v2v/cmdline.ml b/v2v/cmdline.ml
index eaf57dc..df65426 100644
--- a/v2v/cmdline.ml
+++ b/v2v/cmdline.ml
@@ -27,7 +27,6 @@ open Types
open Utils
let parse_cmdline () =
- let debug_gc = ref false in
let debug_overlays = ref false in
let do_copy = ref true in
let input_conn = ref "" in
@@ -138,7 +137,7 @@ let parse_cmdline () =
let argspec = Arg.align [
"-b", Arg.String add_bridge, "in:out " ^ s_"Map bridge 'in' to 'out'";
"--bridge", Arg.String add_bridge, "in:out " ^ ditto;
- "--debug-gc",Arg.Set debug_gc, " " ^ s_"Debug GC and memory allocations";
+ "--debug-gc",Arg.Unit set_debug_gc, " " ^ s_"Debug GC and memory allocations";
"--debug-overlay",Arg.Set debug_overlays,
" " ^ s_"Save overlay files";
"--debug-overlays",Arg.Set debug_overlays,
@@ -211,7 +210,6 @@ read the man page virt-v2v(1).
(* Dereference the arguments. *)
let args = List.rev !args in
- let debug_gc = !debug_gc in
let debug_overlays = !debug_overlays in
let do_copy = !do_copy in
let input_conn = match !input_conn with "" -> None | s -> Some s in
@@ -385,6 +383,6 @@ read the man page virt-v2v(1).
vmtype output_alloc in
input, output,
- debug_gc, debug_overlays, do_copy, network_map, no_trim,
+ debug_overlays, do_copy, network_map, no_trim,
output_alloc, output_format, output_name,
print_source, root_choice
diff --git a/v2v/v2v.ml b/v2v/v2v.ml
index 4c41ed5..f6ebdd5 100644
--- a/v2v/v2v.ml
+++ b/v2v/v2v.ml
@@ -46,7 +46,7 @@ let () = Random.self_init ()
let rec main () =
(* Handle the command line. *)
let input, output,
- debug_gc, debug_overlays, do_copy, network_map, no_trim,
+ debug_overlays, do_copy, network_map, no_trim,
output_alloc, output_format, output_name, print_source, root_choice =
Cmdline.parse_cmdline () in
@@ -63,8 +63,6 @@ let rec main () =
printf (f_"Source guest information (--print-source option):\n");
printf "\n";
printf "%s\n" (string_of_source source);
- if debug_gc then
- Gc.compact ();
exit 0
);
@@ -461,10 +459,7 @@ let rec main () =
);
message (f_"Finishing off");
- delete_target_on_exit := false; (* Don't delete target on exit. *)
-
- if debug_gc then
- Gc.compact ()
+ delete_target_on_exit := false (* Don't delete target on exit. *)
and inspect_source g root_choice =
let roots = g#inspect_os () in
--
2.4.3
9 years, 2 months
[PATCH v4 0/2] RFE: journal reader in guestfish
by Maros Zatko
There seems to be a minor issue when user wants to run it through pager (more)
and wants cancel it. User will end up with stuck guestfish until journal-view
transfers all journal items.
Output is configurable, it's the same format as virt-log has, since both
uses same code.
Maros Zatko (2):
cat: move get_journal_field to fish/journal.c
fish: add journal-view command
cat/Makefile.am | 1 +
cat/log.c | 113 ++-------------------------------------
fish/Makefile.am | 1 +
fish/fish.h | 3 ++
fish/journal.c | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++
generator/Makefile.am | 6 ++-
generator/actions.ml | 22 ++++++++
generator/main.ml | 3 ++
8 files changed, 179 insertions(+), 112 deletions(-)
create mode 100644 fish/journal.c
--
1.9.3
9 years, 2 months
[PATCH] customize: Use setarch when running commands on i686 guest (RHBZ#1256405).
by Richard W.M. Jones
When running (eg) dnf on a 32 bit i686 guest when the host is 64 bit
x86_64, dnf believes it is running on a 64 bit machine and so tries to
install x86_64 packages. We can 'trick' dnf into believing it's a 32
bit machine using the setarch program.
$ virt-builder fedora-22 --arch i686 --install 'gperf'
...
[ 27.4] Installing packages: gperf
...
Running transaction test
Error: Transaction check error:
package libgcc-5.1.1-4.fc22.x86_64 is intended for a different architecture
...
Thanks: Jan Sedlák for finding the solution.
---
customize/customize_run.ml | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/customize/customize_run.ml b/customize/customize_run.ml
index 828c711..2a4c71e 100644
--- a/customize/customize_run.ml
+++ b/customize/customize_run.ml
@@ -59,6 +59,7 @@ let run (g : Guestfs.guestfs) root (ops : ops) =
* - Pass environment variables through from the host.
* - Send stdout and stderr to a log file so we capture all output
* in error messages.
+ * - Use setarch when running x86_64 host + i686 guest.
* Also catch errors and dump the log file completely on error.
*)
let env_vars =
@@ -69,11 +70,16 @@ let run (g : Guestfs.guestfs) root (ops : ops) =
) [ "http_proxy"; "https_proxy"; "ftp_proxy"; "no_proxy" ] in
let env_vars = String.concat "\n" env_vars ^ "\n" in
+ let setarch =
+ match Config.host_cpu, guest_arch with
+ | "x86_64", ("i386"|"i486"|"i586"|"i686") -> "setarch i686"
+ | _ -> "" in
+
let cmd = sprintf "\
exec >>%s 2>&1
%s
-%s
-" (quote logfile) env_vars cmd in
+%s %s
+" (quote logfile) env_vars setarch cmd in
if verbose () then printf "running command:\n%s\n%!" cmd;
try ignore (g#sh cmd)
--
2.5.0
9 years, 2 months
[PATCH 1/2] inspect: recognize the ALT Linux distribution
by Pino Toscano
Check its presence ahead of /etc/redhat-release, as the distro provides
it and thus previously it was recognized as "redhat-based".
---
generator/actions.ml | 4 ++++
src/guestfs-internal.h | 1 +
src/inspect-fs-unix.c | 21 +++++++++++++++++++++
src/inspect-fs.c | 2 ++
src/inspect-icon.c | 1 +
src/inspect.c | 1 +
6 files changed, 30 insertions(+)
diff --git a/generator/actions.ml b/generator/actions.ml
index 1c22f9f..13c8bc8 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -1059,6 +1059,10 @@ Currently defined distros are:
Alpine Linux.
+=item \"altlinux\"
+
+ALT Linux.
+
=item \"archlinux\"
Arch Linux.
diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h
index 0c8857c..6cf3dad 100644
--- a/src/guestfs-internal.h
+++ b/src/guestfs-internal.h
@@ -553,6 +553,7 @@ enum inspect_os_distro {
OS_DISTRO_NETBSD,
OS_DISTRO_COREOS,
OS_DISTRO_ALPINE_LINUX,
+ OS_DISTRO_ALTLINUX,
};
enum inspect_os_package_format {
diff --git a/src/inspect-fs-unix.c b/src/inspect-fs-unix.c
index abfa527..abbae35 100644
--- a/src/inspect-fs-unix.c
+++ b/src/inspect-fs-unix.c
@@ -84,6 +84,7 @@ COMPILE_REGEXP (re_openbsd, "^OpenBSD (\\d+|\\?)\\.(\\d+|\\?)", 0)
COMPILE_REGEXP (re_openbsd_duid, "^[0-9a-f]{16}\\.[a-z]", 0)
COMPILE_REGEXP (re_openbsd_dev, "^/dev/(s|w)d([0-9])([a-z])$", 0)
COMPILE_REGEXP (re_netbsd_dev, "^/dev/(l|s)d([0-9])([a-z])$", 0)
+COMPILE_REGEXP (re_altlinux, " (?:(\\d+)(?:\\.(\\d+)(?:[\\.\\d]+)?)?)\\s+\\((?:[^)]+)\\)$", 0)
static void check_architecture (guestfs_h *g, struct inspect_fs *fs);
static int check_hostname_unix (guestfs_h *g, struct inspect_fs *fs);
@@ -414,6 +415,26 @@ guestfs_int_check_linux_root (guestfs_h *g, struct inspect_fs *fs)
fs->minor_version = 0;
}
}
+ else if (guestfs_is_file_opts (g, "/etc/altlinux-release",
+ GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
+ fs->distro = OS_DISTRO_ALTLINUX;
+
+ if (parse_release_file (g, fs, "/etc/altlinux-release") == -1)
+ return -1;
+
+ if (match2 (g, fs->product_name, re_altlinux, &major, &minor)) {
+ fs->major_version = guestfs_int_parse_unsigned_int (g, major);
+ free (major);
+ if (fs->major_version == -1) {
+ free (minor);
+ return -1;
+ }
+ fs->minor_version = guestfs_int_parse_unsigned_int (g, minor);
+ free (minor);
+ if (fs->minor_version == -1)
+ return -1;
+ }
+ }
else if (guestfs_is_file_opts (g, "/etc/redhat-release",
GUESTFS_IS_FILE_OPTS_FOLLOWSYMLINKS, 1, -1) > 0) {
fs->distro = OS_DISTRO_REDHAT_BASED; /* Something generic Red Hat-like. */
diff --git a/src/inspect-fs.c b/src/inspect-fs.c
index aa198ad..b239302 100644
--- a/src/inspect-fs.c
+++ b/src/inspect-fs.c
@@ -465,6 +465,7 @@ guestfs_int_check_package_format (guestfs_h *g, struct inspect_fs *fs)
case OS_DISTRO_CENTOS:
case OS_DISTRO_SCIENTIFIC_LINUX:
case OS_DISTRO_ORACLE_LINUX:
+ case OS_DISTRO_ALTLINUX:
fs->package_format = OS_PACKAGE_FORMAT_RPM;
break;
@@ -536,6 +537,7 @@ guestfs_int_check_package_management (guestfs_h *g, struct inspect_fs *fs)
case OS_DISTRO_DEBIAN:
case OS_DISTRO_UBUNTU:
case OS_DISTRO_LINUX_MINT:
+ case OS_DISTRO_ALTLINUX:
fs->package_management = OS_PACKAGE_MANAGEMENT_APT;
break;
diff --git a/src/inspect-icon.c b/src/inspect-icon.c
index 77256a3..93cd67a 100644
--- a/src/inspect-icon.c
+++ b/src/inspect-icon.c
@@ -183,6 +183,7 @@ guestfs_impl_inspect_get_icon (guestfs_h *g, const char *root, size_t *size_r,
case OS_DISTRO_NETBSD:
case OS_DISTRO_OPENBSD:
case OS_DISTRO_ALPINE_LINUX:
+ case OS_DISTRO_ALTLINUX:
case OS_DISTRO_UNKNOWN:
; /* nothing */
}
diff --git a/src/inspect.c b/src/inspect.c
index 9332fc4..c01888a 100644
--- a/src/inspect.c
+++ b/src/inspect.c
@@ -256,6 +256,7 @@ guestfs_impl_inspect_get_distro (guestfs_h *g, const char *root)
switch (fs->distro) {
case OS_DISTRO_ALPINE_LINUX: ret = safe_strdup (g, "alpinelinux"); break;
+ case OS_DISTRO_ALTLINUX: ret = safe_strdup (g, "altlinux"); break;
case OS_DISTRO_ARCHLINUX: ret = safe_strdup (g, "archlinux"); break;
case OS_DISTRO_BUILDROOT: ret = safe_strdup (g, "buildroot"); break;
case OS_DISTRO_CENTOS: ret = safe_strdup (g, "centos"); break;
--
2.1.0
9 years, 3 months
[PATCH 0/4] Various p2v fixes and features
by Richard W.M. Jones
A mixed bag, but all the patches make sense together!
Patch 1: Fix a bug that Tingting found:
https://bugzilla.redhat.com/show_bug.cgi?id=1256222
Patch 2: Revert a patch that makes no sense now that we've added
virt-v2v into base RHEL. This is just included because it's a cleanup
needed before applying patch 3.
Patch 3: Add the ability to use SSH identities (private keys) for
virt-p2v to authenticate with the conversion server (as a possibly
more secure alternative to passwords).
Patch 4: Test the bug fixed in patch 1, which involves for various
convoluted reasons using SSH identities.
Rich.
9 years, 3 months
[PATCH 1/3] ocaml: dynamically generate the content of Guestfs.Errno
by Pino Toscano
Put in a list the errnos to expose, filling the content of the
Guestfs.Errno submodule from that.
Also, generate a separate guestfs-c-errnos.c with the implementations of
the functions returning the errno codes.
Only code motion and refactoring, no actual changes on the content of
the ocaml Guestfs module.
---
.gitignore | 1 +
generator/main.ml | 1 +
generator/ocaml.ml | 77 +++++++++++++++++++++++++++++++++++++++++++++---------
ocaml/Makefile.am | 2 ++
ocaml/guestfs-c.c | 32 -----------------------
po/POTFILES | 1 +
6 files changed, 70 insertions(+), 44 deletions(-)
diff --git a/.gitignore b/.gitignore
index e968399..fb972a7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -332,6 +332,7 @@ Makefile.in
/ocaml/examples/inspect_vm
/ocaml/examples/stamp-guestfs-ocaml.pod
/ocaml/guestfs-c-actions.c
+/ocaml/guestfs-c-errnos.c
/ocaml/guestfs.ml
/ocaml/guestfs.mli
/ocamlinit-stamp
diff --git a/generator/main.ml b/generator/main.ml
index 94f0d09..1e0e7d6 100644
--- a/generator/main.ml
+++ b/generator/main.ml
@@ -125,6 +125,7 @@ Run it from the top source directory using the command
output_to "ocaml/guestfs.mli" generate_ocaml_mli;
output_to "ocaml/guestfs.ml" generate_ocaml_ml;
output_to "ocaml/guestfs-c-actions.c" generate_ocaml_c;
+ output_to "ocaml/guestfs-c-errnos.c" generate_ocaml_c_errnos;
output_to "ocaml/bindtests.ml" generate_ocaml_bindtests;
output_to "perl/Guestfs.xs" generate_perl_xs;
output_to "perl/lib/Sys/Guestfs.pm" generate_perl_pm;
diff --git a/generator/ocaml.ml b/generator/ocaml.ml
index 05c7456..7742209 100644
--- a/generator/ocaml.ml
+++ b/generator/ocaml.ml
@@ -30,6 +30,14 @@ open Structs
open C
open Events
+(* List of errnos to expose on Guestfs.Errno. *)
+let ocaml_errnos = [
+ "EINVAL";
+ "ENOTSUP";
+ "EPERM";
+ "ESRCH";
+]
+
(* Generate the OCaml bindings interface. *)
let rec generate_ocaml_mli () =
generate_header OCamlStyle LGPLv2plus;
@@ -132,10 +140,12 @@ val last_errno : t -> int
which you can use to test the return value of {!Guestfs.last_errno}. *)
module Errno : sig
- val errno_EINVAL : int
- val errno_ENOTSUP : int
- val errno_EPERM : int
- val errno_ESRCH : int
+";
+ List.iter (
+ fun e ->
+ pr " val errno_%s : int\n" e
+ ) ocaml_errnos;
+ pr "\
end
";
@@ -287,14 +297,15 @@ external event_to_string : event list -> string
external last_errno : t -> int = \"ocaml_guestfs_last_errno\"
module Errno = struct
- external einval : unit -> int = \"ocaml_guestfs_get_EINVAL\" \"noalloc\"
- let errno_EINVAL = einval ()
- external enotsup : unit -> int = \"ocaml_guestfs_get_ENOTSUP\" \"noalloc\"
- let errno_ENOTSUP = enotsup ()
- external eperm : unit -> int = \"ocaml_guestfs_get_EPERM\" \"noalloc\"
- let errno_EPERM = eperm ()
- external esrch : unit -> int = \"ocaml_guestfs_get_ESRCH\" \"noalloc\"
- let errno_ESRCH = esrch ()
+";
+ List.iter (
+ fun e ->
+ let le = String.lowercase e in
+ pr " external %s : unit -> int = \"ocaml_guestfs_get_%s\" \"noalloc\"\n"
+ le e;
+ pr " let errno_%s = %s ()\n" e le
+ ) ocaml_errnos;
+ pr "\
end
(* Give the exceptions names, so they can be raised from the C code. *)
@@ -717,6 +728,48 @@ copy_table (char * const * argv)
)
) external_functions_sorted
+(* Generate the OCaml bindings C errnos. *)
+and generate_ocaml_c_errnos () =
+ generate_header CStyle LGPLv2plus;
+
+ pr "\
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include <caml/config.h>
+#include <caml/alloc.h>
+#include <caml/fail.h>
+#include <caml/memory.h>
+#include <caml/mlvalues.h>
+
+#include \"guestfs.h\"
+
+#include \"guestfs-c.h\"
+
+/* These prototypes are solely to quiet gcc warnings. */
+";
+ List.iter (
+ fun e ->
+ pr "value ocaml_guestfs_get_%s (value unitv);\n" e
+ ) ocaml_errnos;
+
+ List.iter (
+ fun e ->
+ pr "\
+
+/* NB: \"noalloc\" function. */
+value
+ocaml_guestfs_get_%s (value unitv)
+{
+ return Val_int (%s);
+}
+" e e
+ ) ocaml_errnos
+
and generate_ocaml_structure_decls () =
List.iter (
fun { s_name = typ; s_cols = cols } ->
diff --git a/ocaml/Makefile.am b/ocaml/Makefile.am
index db13a8f..e781363 100644
--- a/ocaml/Makefile.am
+++ b/ocaml/Makefile.am
@@ -21,6 +21,7 @@ generator_built = \
guestfs.mli \
guestfs.ml \
guestfs-c-actions.c \
+ guestfs-c-errnos.c \
$(srcdir)/bindtests.ml
EXTRA_DIST = \
@@ -89,6 +90,7 @@ libguestfsocaml_a_CFLAGS = \
libguestfsocaml_a_SOURCES = \
guestfs-c.c \
guestfs-c-actions.c \
+ guestfs-c-errnos.c \
../src/utils.c
if HAVE_OCAMLDOC
diff --git a/ocaml/guestfs-c.c b/ocaml/guestfs-c.c
index 9603f04..03e3659 100644
--- a/ocaml/guestfs-c.c
+++ b/ocaml/guestfs-c.c
@@ -63,10 +63,6 @@ value ocaml_guestfs_set_event_callback (value gv, value closure, value events);
value ocaml_guestfs_delete_event_callback (value gv, value eh);
value ocaml_guestfs_event_to_string (value events);
value ocaml_guestfs_last_errno (value gv);
-value ocaml_guestfs_get_EINVAL (value unitv);
-value ocaml_guestfs_get_ENOTSUP (value unitv);
-value ocaml_guestfs_get_EPERM (value unitv);
-value ocaml_guestfs_get_ESRCH (value unitv);
/* Allocate handles and deal with finalization. */
static void
@@ -442,31 +438,3 @@ ocaml_guestfs_last_errno (value gv)
rv = Val_int (r);
CAMLreturn (rv);
}
-
-/* NB: "noalloc" function. */
-value
-ocaml_guestfs_get_EINVAL (value unitv)
-{
- return Val_int (EINVAL);
-}
-
-/* NB: "noalloc" function. */
-value
-ocaml_guestfs_get_ENOTSUP (value unitv)
-{
- return Val_int (ENOTSUP);
-}
-
-/* NB: "noalloc" function. */
-value
-ocaml_guestfs_get_EPERM (value unitv)
-{
- return Val_int (EPERM);
-}
-
-/* NB: "noalloc" function. */
-value
-ocaml_guestfs_get_ESRCH (value unitv)
-{
- return Val_int (ESRCH);
-}
diff --git a/po/POTFILES b/po/POTFILES
index 7f1580c..6a0a3fc 100644
--- a/po/POTFILES
+++ b/po/POTFILES
@@ -263,6 +263,7 @@ mllib/mkdtemp-c.c
mllib/progress-c.c
mllib/uri-c.c
ocaml/guestfs-c-actions.c
+ocaml/guestfs-c-errnos.c
ocaml/guestfs-c.c
p2v/about-authors.c
p2v/about-license.c
--
2.1.0
9 years, 3 months
Can I get some help from you?
by andywood2610@126.com
Hello, there:
I wish to get some help from you. And here is my problem:
When I tried to boot a instance on OpenStack Kilo,
========================================================================================================================
nova boot --flavor m1.tiny --image cirros-0.3.4-x86_64 --nic net-id=3be58b93-32ad-42bb-80c7-7979554d6bc4 --security-group default --key-name demo-key demo-instance7
========================================================================================================================
the instance didn't boot as I expected and the "nova-compute.log" file contains some sentences like this:
===================================nova-compute.log===============================================
2015-08-25 09:42:53.009 6440 WARNING nova.virt.disk.api [req-3bcf4c8f-57e0-4ae1-9a43-730c02b02621 - - - - -] Unable to mount image /var/lib/nova/instances/54626e50-e17a-4bfc-9f0e-a6ed581582be/disk with error libguestfs installed but not usable (/usr/bin/supermin-helper exited with error status 1.
To see full error messages you may need to enable debugging.
See http://libguestfs.org/guestfs-faq.1.html#debugging-libguestfs). Cannot resize.
2015-08-25 09:42:53.128 6440 ERROR nova.compute.manager [req-3bcf4c8f-57e0-4ae1-9a43-730c02b02621 - - - - -] [instance: 54626e50-e17a-4bfc-9f0e-a6ed581582be] Instance failed to spawn
=====================================nova-compute.log=============================================
After I run "libguestfs-test-tool" in my terminal, I get these compute and unedited info below:
================================================================================
************************************************************
* IMPORTANT NOTICE
*
* When reporting bugs, include the COMPLETE, UNEDITED
* output below in your bug report.
*
************************************************************
LIBVIRT_DEFAULT_URI=qemu:///system
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
SELinux: sh: 1: getenforce: not found
guestfs_get_append: (null)
guestfs_get_backend: direct
guestfs_get_autosync: 1
guestfs_get_cachedir: /var/tmp
guestfs_get_direct: 0
guestfs_get_hv: /usr/bin/qemu-system-x86_64
guestfs_get_memsize: 500
guestfs_get_network: 0
guestfs_get_path: /usr/lib/guestfs
guestfs_get_pgroup: 0
guestfs_get_program: libguestfs-test-tool
guestfs_get_recovery_proc: 1
guestfs_get_selinux: 0
guestfs_get_smp: 1
guestfs_get_tmpdir: /tmp
guestfs_get_trace: 0
guestfs_get_verbose: 1
host_cpu: x86_64
Launching appliance, timeout set to 600 seconds.
libguestfs: launch: program=libguestfs-test-tool
libguestfs: launch: version=1.24.5
libguestfs: launch: backend registered: unix
libguestfs: launch: backend registered: uml
libguestfs: launch: backend registered: libvirt
libguestfs: launch: backend registered: direct
libguestfs: launch: backend=direct
libguestfs: launch: tmpdir=/tmp/libguestfsLMdzHt
libguestfs: launch: umask=0022
libguestfs: launch: euid=0
libguestfs: command: run: /usr/bin/supermin-helper
libguestfs: command: run: \ --verbose
libguestfs: command: run: \ -f checksum
libguestfs: command: run: \ --host-cpu x86_64
libguestfs: command: run: \ /usr/lib/guestfs/supermin.d
supermin helper [00000ms] whitelist = (not specified)
supermin helper [00000ms] host_cpu = x86_64
supermin helper [00000ms] dtb_wildcard = (not specified)
supermin helper [00000ms] inputs:
supermin helper [00000ms] inputs[0] = /usr/lib/guestfs/supermin.d
supermin helper [00000ms] outputs:
supermin helper [00000ms] kernel = (none)
supermin helper [00000ms] dtb = (none)
supermin helper [00000ms] initrd = (none)
supermin helper [00000ms] appliance = (none)
checking modpath /lib/modules/3.16.0-30-generic is a directory
checking modpath /lib/modules/3.16.0-45-generic is a directory
picked kernel vmlinuz-3.16.0-45-generic
supermin helper [00000ms] finished creating kernel
supermin helper [00000ms] visiting /usr/lib/guestfs/supermin.d
supermin helper [00000ms] visiting /usr/lib/guestfs/supermin.d/daemon.img.gz
supermin helper [00000ms] visiting /usr/lib/guestfs/supermin.d/init.img
supermin helper [00000ms] visiting /usr/lib/guestfs/supermin.d/udev-rules.img
supermin helper [00000ms] adding kernel modules
supermin helper [00044ms] finished creating appliance
libguestfs: checksum of existing appliance: b6869d6d612edfa2e0c627a79d62b1cbe17737ad5a9c3452b2d349d7c2b6c217
libguestfs: [00047ms] begin building supermin appliance
libguestfs: [00047ms] run supermin-helper
libguestfs: command: run: /usr/bin/supermin-helper
libguestfs: command: run: \ --verbose
libguestfs: command: run: \ --copy-kernel
libguestfs: command: run: \ -f ext2
libguestfs: command: run: \ --host-cpu x86_64
libguestfs: command: run: \ /usr/lib/guestfs/supermin.d
libguestfs: command: run: \ --output-kernel /var/tmp/guestfs.sZ4SFI/kernel
libguestfs: command: run: \ --output-initrd /var/tmp/guestfs.sZ4SFI/initrd
libguestfs: command: run: \ --output-appliance /var/tmp/guestfs.sZ4SFI/root
supermin helper [00000ms] whitelist = (not specified)
supermin helper [00000ms] host_cpu = x86_64
supermin helper [00000ms] dtb_wildcard = (not specified)
supermin helper [00000ms] inputs:
supermin helper [00000ms] inputs[0] = /usr/lib/guestfs/supermin.d
supermin helper [00000ms] outputs:
supermin helper [00000ms] kernel = /var/tmp/guestfs.sZ4SFI/kernel
supermin helper [00000ms] dtb = (none)
supermin helper [00000ms] initrd = /var/tmp/guestfs.sZ4SFI/initrd
supermin helper [00000ms] appliance = /var/tmp/guestfs.sZ4SFI/root
checking modpath /lib/modules/3.16.0-30-generic is a directory
checking modpath /lib/modules/3.16.0-45-generic is a directory
picked kernel vmlinuz-3.16.0-45-generic
supermin helper [00038ms] finished creating kernel
supermin helper [01967ms] finished mke2fs
supermin helper [01968ms] visiting /usr/lib/guestfs/supermin.d
supermin helper [01968ms] visiting /usr/lib/guestfs/supermin.d/daemon.img.gz
supermin helper [02021ms] visiting /usr/lib/guestfs/supermin.d/init.img
supermin helper [02021ms] visiting /usr/lib/guestfs/supermin.d/udev-rules.img
/usr/bin/supermin-helper: ext2: parent directory not found: /lib: File not found by ext2_lookup
libguestfs: error: /usr/bin/supermin-helper exited with error status 1, see debug messages above
libguestfs: command: run: rm
libguestfs: command: run: \ -rf /var/tmp/guestfs.sZ4SFI
libguestfs-test-tool: failed to launch appliance
libguestfs: closing guestfs handle 0xa11480 (state 0)
libguestfs: command: run: rm
libguestfs: command: run: \ -rf /tmp/libguestfsLMdzHt
================================================================================
I wish to get some help from you , thank you
Best wishes!
9 years, 3 months