[PATCH 1/4] build: Use LT_INIT in configure.ac.
by Richard W.M. Jones
Avoids the warning:
libtoolize: Remember to add 'LT_INIT' to configure.ac.
This is the new name for AC_PROG_LIBTOOL, so I removed that.
However to use this macro we must enable AC_USE_SYSTEM_EXTENSIONS.
(AC_GNU_SOURCE was removed back in 2011).
---
configure.ac | 5 +++++
m4/guestfs-progs.m4 | 1 -
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/configure.ac b/configure.ac
index 9cc3f1a99..f04d77848 100644
--- a/configure.ac
+++ b/configure.ac
@@ -32,6 +32,8 @@ m4_define([HEADING],
AC_CONFIG_AUX_DIR([build-aux])
AC_REQUIRE_AUX_FILE([guestfs-test-driver])
+AC_USE_SYSTEM_EXTENSIONS
+
dnl Initialize automake.
AM_INIT_AUTOMAKE(foreign subdir-objects tar-pax) dnl NB: Do not [quote] this parameter.
@@ -40,6 +42,9 @@ AM_SILENT_RULES([yes]) # make --enable-silent-rules the default.
AC_CONFIG_MACRO_DIR([m4])
+dnl Initialize libtool.
+LT_INIT
+
dnl Stable or development version?
BRANCH_NUMBER=libguestfs_major.libguestfs_minor
AC_SUBST([BRANCH_NUMBER])
diff --git a/m4/guestfs-progs.m4 b/m4/guestfs-progs.m4
index d36c6531e..a36b9ad2d 100644
--- a/m4/guestfs-progs.m4
+++ b/m4/guestfs-progs.m4
@@ -37,7 +37,6 @@ m4_ifdef([AC_PROG_SED],[
# Define $(AWK).
AC_PROG_AWK
-AC_PROG_LIBTOOL
AC_PROG_LN_S
dnl Check for cpio which isn't in the default Pardus install amazingly.
--
2.18.0
6 years, 3 months
[PATCH] generator: Do not claim copyright for future years
by Bernhard M. Wiedemann
This change helps to make libguestfs package build reproducible.
See https://reproducible-builds.org/ for why this is good.
Without this patch, building today's libguestfs in 2033, claims
Copyright (C) 2009-2033 Red Hat Inc.
which cannot be correct.
This affected files like
/usr/include/guestfs-gobject.h
/usr/lib/perl5/vendor_perl/5.26.2/x86_64-linux-thread-multi/Sys/Guestfs.pm
/usr/lib64/python2.7/site-packages/guestfs.py
/usr/lib64/ocaml/guestfs/guestfs.mli
Commits like 212762c59351822e9db7d3dc82afe1765808d918
will take care of updating the year.
---
generator/docstrings.ml | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/generator/docstrings.ml b/generator/docstrings.ml
index fa7b1668a..b480d036e 100644
--- a/generator/docstrings.ml
+++ b/generator/docstrings.ml
@@ -68,9 +68,7 @@ let version_added = function
Some (sprintf "%d.%d.%d" major minor release)
| _ -> None
-let copyright_years =
- let this_year = 1900 + (localtime (time ())).tm_year in
- if this_year > 2009 then sprintf "2009-%04d" this_year else "2009"
+let copyright_years = "2009-2018"
(* Generate a header block in a number of standard styles. *)
type comment_style =
--
2.16.4
6 years, 3 months
[PATCH] lib: create: avoid one extra string allocation
by Pino Toscano
When creating the qemu-img command, use the guestfs_int_cmd_add_arg &
guestfs_int_cmd_add_arg_format APIs to add the proper filename directly,
without creating a string for it.
This should cause no functional change.
---
lib/create.c | 25 +++++++++++--------------
1 file changed, 11 insertions(+), 14 deletions(-)
diff --git a/lib/create.c b/lib/create.c
index 60e467fb6..fcc5855e0 100644
--- a/lib/create.c
+++ b/lib/create.c
@@ -250,11 +250,10 @@ is_power_of_2 (unsigned v)
VALID_FLAG_ALPHA|VALID_FLAG_DIGIT, "")
static int
-disk_create_qcow2 (guestfs_h *g, const char *orig_filename, int64_t size,
+disk_create_qcow2 (guestfs_h *g, const char *filename, int64_t size,
const char *backingfile,
const struct guestfs_disk_create_argv *optargs)
{
- CLEANUP_FREE char *filename = NULL;
const char *backingformat = NULL;
const char *preallocation = NULL;
const char *compat = NULL;
@@ -263,16 +262,6 @@ disk_create_qcow2 (guestfs_h *g, const char *orig_filename, int64_t size,
CLEANUP_CMD_CLOSE struct command *cmd = guestfs_int_new_command (g);
int r;
- /* If the filename is something like "file:foo" then qemu-img will
- * try to interpret that as "foo" in the file:/// protocol. To
- * avoid that, if the path is relative prefix it with "./" since
- * qemu-img won't try to interpret such a path.
- */
- if (orig_filename[0] != '/')
- filename = safe_asprintf (g, "./%s", orig_filename);
- else
- filename = safe_strdup (g, orig_filename);
-
if (optargs->bitmask & GUESTFS_DISK_CREATE_BACKINGFORMAT_BITMASK) {
backingformat = optargs->backingformat;
if (!VALID_FORMAT (backingformat)) {
@@ -341,13 +330,21 @@ disk_create_qcow2 (guestfs_h *g, const char *orig_filename, int64_t size,
}
/* Complete the command line. */
- guestfs_int_cmd_add_arg (cmd, filename);
+ /* If the filename is something like "file:foo" then qemu-img will
+ * try to interpret that as "foo" in the file:/// protocol. To
+ * avoid that, if the path is relative prefix it with "./" since
+ * qemu-img won't try to interpret such a path.
+ */
+ if (filename[0] == '/')
+ guestfs_int_cmd_add_arg (cmd, filename);
+ else
+ guestfs_int_cmd_add_arg_format (cmd, "./%s", filename);
if (size >= 0)
guestfs_int_cmd_add_arg_format (cmd, "%" PRIi64, size);
r = guestfs_int_cmd_run (cmd);
if (!WIFEXITED (r) || WEXITSTATUS (r) != 0) {
- guestfs_int_external_command_failed (g, r, "qemu-img", orig_filename);
+ guestfs_int_external_command_failed (g, r, "qemu-img", filename);
return -1;
}
--
2.17.1
6 years, 3 months
[PATCH 0/2] RFC: add output selection for --machine-readable
by Pino Toscano
Hi,
this is a first approach (hence RFC, since it misses tests &
documentation) in selecting the output for --machine-readable.
The possible choices are:
* --machine-readable: to stdout, like before
* --machine-readable=file:name-of-file: to the specified file
* --machine-readable=stream:stdout: explicitly to stdout
* --machine-readable=stream:stderr: explicitly to stderr
This makes it possible to add additional output for machine-readable in
the tools, with the possibility for users to get it separately from the
rest of the output/errors of the tool used.
For example, the proposed --print-estimate for virt-v2v [1] could print
human output (just like the --print-source), while printing e.g. JSON to
the machine-readable stream.
[1] https://www.redhat.com/archives/libguestfs/2018-August/msg00158.html
Thanks,
Pino Toscano (2):
common/mltools: getopt: add Getopt.OptString
OCaml tools: add output selection for --machine-readable
builder/cmdline.ml | 12 ++++----
builder/repository_main.ml | 2 +-
common/mltools/getopt-c.c | 20 ++++++++++++-
common/mltools/getopt.ml | 5 +++-
common/mltools/getopt.mli | 4 +++
common/mltools/getopt_tests.ml | 18 +++++++++++-
common/mltools/test-getopt.sh | 11 +++++++
common/mltools/tools_utils.ml | 52 +++++++++++++++++++++++++++++++++-
common/mltools/tools_utils.mli | 6 ++++
dib/cmdline.ml | 4 +--
get-kernel/get_kernel.ml | 2 +-
resize/resize.ml | 22 +++++++-------
sparsify/cmdline.ml | 16 +++++------
v2v/cmdline.ml | 28 +++++++++---------
14 files changed, 155 insertions(+), 47 deletions(-)
--
2.17.1
6 years, 3 months
[PATCH 0/2] v2v: rhv-upload-plugin: Improve error handling
by Nir Soffer
These patches improve error handling when PUT request fail, including
the error response from oVirt server. This will make it easier to debug
issue when oVirt server logs have been rotated.
Nir Soffer (2):
v2v: rhv-upload-plugin: Handle send send failures
v2v: rhv-upload-plugin: Fix error formatting
v2v/rhv-upload-plugin.py | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
--
2.17.1
6 years, 3 months
[PATCH v3 0/4] file: Zero for block devices and older file systems
by Nir Soffer
This version addresses comments on v3.
Changes since v3:
- Finally got spacing right (Eric)
- Reorder includes (Richard)
- Return 0 or -1 instead of r (Richard)
- Add common/include/isaligned.h to Makefile.am (Richard)
v3 was here:
https://www.redhat.com/archives/libguestfs/2018-August/msg00177.html
Nir Soffer (4):
file: Avoid unsupported fallocate() calls
file: Support zero without ZERO_RANGE
common: Add isaligned helper module
file: Zero for block devices on old kernels
common/include/Makefile.am | 1 +
common/include/isaligned.h | 51 ++++++++++
plugins/file/Makefile.am | 3 +-
plugins/file/file.c | 186 +++++++++++++++++++++++++++++--------
4 files changed, 200 insertions(+), 41 deletions(-)
create mode 100644 common/include/isaligned.h
--
2.17.1
6 years, 3 months
[PATCH 1/2] mlstdutils/mltools: factorize the machine-readable option
by Pino Toscano
Store the machine-readable flag globally, just like done for
verbose/debug/etc, and enhance create_standard_options to provide
--machine-readable automatically.
---
common/mlstdutils/std_utils.ml | 4 ++++
common/mlstdutils/std_utils.mli | 7 +++++--
common/mltools/tools_utils.ml | 7 ++++++-
common/mltools/tools_utils.mli | 5 ++++-
4 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/common/mlstdutils/std_utils.ml b/common/mlstdutils/std_utils.ml
index df443058f..6499b3535 100644
--- a/common/mlstdutils/std_utils.ml
+++ b/common/mlstdutils/std_utils.ml
@@ -645,6 +645,10 @@ let verbose = ref false
let set_verbose () = verbose := true
let verbose () = !verbose
+let machine_readable = ref false
+let set_machine_readable () = machine_readable := true
+let machine_readable () = !machine_readable
+
let with_open_in filename f =
let chan = open_in filename in
protect ~f:(fun () -> f chan) ~finally:(fun () -> close_in chan)
diff --git a/common/mlstdutils/std_utils.mli b/common/mlstdutils/std_utils.mli
index c887249a5..cb72fef7d 100644
--- a/common/mlstdutils/std_utils.mli
+++ b/common/mlstdutils/std_utils.mli
@@ -374,8 +374,11 @@ val set_trace : unit -> unit
val trace : unit -> bool
val set_verbose : unit -> unit
val verbose : unit -> bool
-(** Stores the colours ([--colours]), quiet ([--quiet]), trace ([-x])
- and verbose ([-v]) flags in global variables. *)
+val set_machine_readable : unit -> unit
+val machine_readable : unit -> bool
+(** Stores the colours ([--colours]), quiet ([--quiet]), trace ([-x]),
+ verbose ([-v]), and machine readable ([--machine-readable]) flags
+ in global variables. *)
val with_open_in : string -> (in_channel -> 'a) -> 'a
(** [with_open_in filename f] calls function [f] with [filename]
diff --git a/common/mltools/tools_utils.ml b/common/mltools/tools_utils.ml
index 09f1bb544..04916b89a 100644
--- a/common/mltools/tools_utils.ml
+++ b/common/mltools/tools_utils.ml
@@ -229,7 +229,7 @@ let human_size i =
)
)
-let create_standard_options argspec ?anon_fun ?(key_opts = false) usage_msg =
+let create_standard_options argspec ?anon_fun ?(key_opts = false) ?(machine_readable = false) usage_msg =
(** Install an exit hook to check gc consistency for --debug-gc *)
let set_debug_gc () =
at_exit (fun () -> Gc.compact()) in
@@ -249,6 +249,11 @@ let create_standard_options argspec ?anon_fun ?(key_opts = false) usage_msg =
[ L"echo-keys" ], Getopt.Unit c_set_echo_keys, s_"Don’t turn off echo for passphrases";
[ L"keys-from-stdin" ], Getopt.Unit c_set_keys_from_stdin, s_"Read passphrases from stdin";
]
+ else []) @
+ (if machine_readable then
+ [
+ [ L"machine-readable" ], Getopt.Unit set_machine_readable, s_"Make output machine readable";
+ ]
else []) in
Getopt.create argspec ?anon_fun usage_msg
diff --git a/common/mltools/tools_utils.mli b/common/mltools/tools_utils.mli
index dac6b4120..44fd20be3 100644
--- a/common/mltools/tools_utils.mli
+++ b/common/mltools/tools_utils.mli
@@ -64,13 +64,16 @@ val parse_resize : int64 -> string -> int64
val human_size : int64 -> string
(** Converts a size in bytes to a human-readable string. *)
-val create_standard_options : Getopt.speclist -> ?anon_fun:Getopt.anon_fun -> ?key_opts:bool -> Getopt.usage_msg -> Getopt.t
+val create_standard_options : Getopt.speclist -> ?anon_fun:Getopt.anon_fun -> ?key_opts:bool -> ?machine_readable:bool -> Getopt.usage_msg -> Getopt.t
(** Adds the standard libguestfs command line options to the specified ones,
sorting them, and setting [long_options] to them.
[key_opts] specifies whether add the standard options related to
keys management, i.e. [--echo-keys] and [--keys-from-stdin].
+ [machine_readable] specifies whether add the [--machine-readable]
+ option.
+
Returns a new [Getopt.t] handle. *)
val external_command : ?echo_cmd:bool -> string -> string list
--
2.17.1
6 years, 3 months
[PATCH] common/mltools: getopt: add Getopt.OptString
by Pino Toscano
Introduce a new type of option with an optional string argument.
---
common/mltools/getopt-c.c | 20 +++++++++++++++++++-
common/mltools/getopt.ml | 5 ++++-
common/mltools/getopt.mli | 4 ++++
common/mltools/getopt_tests.ml | 18 +++++++++++++++++-
common/mltools/test-getopt.sh | 11 +++++++++++
5 files changed, 55 insertions(+), 3 deletions(-)
diff --git a/common/mltools/getopt-c.c b/common/mltools/getopt-c.c
index 7b7e39be2..5fa703428 100644
--- a/common/mltools/getopt-c.c
+++ b/common/mltools/getopt-c.c
@@ -274,6 +274,10 @@ guestfs_int_mllib_getopt_parse (value argsv, value specsv, value anon_funv, valu
has_arg = 1;
break;
+ case 8: /* OptString of string * (string option -> unit) */
+ has_arg = 2;
+ break;
+
default:
error (EXIT_FAILURE, 0,
"internal error: unhandled Tag_val (actionv) = %d",
@@ -286,8 +290,11 @@ guestfs_int_mllib_getopt_parse (value argsv, value specsv, value anon_funv, valu
caml_raise_out_of_memory ();
optstring = newstring;
optstring[optstring_len++] = key[0];
- if (has_arg)
+ if (has_arg > 0) {
optstring[optstring_len++] = ':';
+ if (has_arg > 1)
+ optstring[optstring_len++] = ':';
+ }
} else {
struct option *newopts = realloc (longopts, (longopts_len + 1 + 1) * sizeof (*longopts));
if (newopts == NULL)
@@ -393,6 +400,17 @@ guestfs_int_mllib_getopt_parse (value argsv, value specsv, value anon_funv, valu
do_call1 (v, v2);
break;
+ case 8: /* OptString of string * (string option -> unit) */
+ v = Field (actionv, 1);
+ if (optarg) {
+ v2 = caml_alloc (1, 0);
+ Store_field (v2, 0, caml_copy_string (optarg));
+ } else {
+ v2 = Val_none;
+ }
+ do_call1 (v, v2);
+ break;
+
default:
error (EXIT_FAILURE, 0,
"internal error: unhandled Tag_val (actionv) = %d",
diff --git a/common/mltools/getopt.ml b/common/mltools/getopt.ml
index 9d20855f7..da461457b 100644
--- a/common/mltools/getopt.ml
+++ b/common/mltools/getopt.ml
@@ -31,6 +31,7 @@ type spec =
| Int of string * (int -> unit)
| Set_int of string * int ref
| Symbol of string * string list * (string -> unit)
+ | OptString of string * (string option -> unit)
module OptionName = struct
type option_name = S of char | L of string | M of string
@@ -97,7 +98,8 @@ let show_help h () =
| Set_string (arg, _)
| Int (arg, _)
| Set_int (arg, _)
- | Symbol (arg, _, _) -> Some arg in
+ | Symbol (arg, _, _)
+ | OptString (arg, _) -> Some arg in
(match arg with
| None -> ()
| Some arg ->
@@ -181,6 +183,7 @@ let create specs ?anon_fun usage_msg =
| Set_string _ -> ()
| Int _ -> ()
| Set_int _ -> ()
+ | OptString _ -> ()
| Symbol (_, elements, _) ->
List.iter (
fun e ->
diff --git a/common/mltools/getopt.mli b/common/mltools/getopt.mli
index 2cae19bb8..b4a4f261f 100644
--- a/common/mltools/getopt.mli
+++ b/common/mltools/getopt.mli
@@ -44,6 +44,10 @@ type spec =
element in the tuple is the documentation string of the
argument, the second is the list of allowed strings,
and the third is the function to call. *)
+ | OptString of string * (string option -> unit)
+ (** Option with an optional argument; the first element in the
+ tuple is the documentation string of the argument, and the
+ second is the function to call. *)
module OptionName : sig
type option_name =
diff --git a/common/mltools/getopt_tests.ml b/common/mltools/getopt_tests.ml
index 751bf1d5f..1617b3056 100644
--- a/common/mltools/getopt_tests.ml
+++ b/common/mltools/getopt_tests.ml
@@ -40,6 +40,15 @@ let set_flag = ref false
let si = ref 42
let ss = ref "not set"
+type optstring_value =
+ | Unset
+ | NoValue
+ | Value of string
+let optstr = ref Unset
+let set_optstr = function
+ | None -> optstr := NoValue
+ | Some s -> optstr := Value s
+
let argspec = [
[ S 'a'; L"add" ], Getopt.String ("string", add_string), "Add string";
[ S 'c'; L"clear" ], Getopt.Clear clear_flag, "Clear flag";
@@ -47,10 +56,16 @@ let argspec = [
[ M"ii"; L"set-int" ], Getopt.Set_int ("int", si), "Set int";
[ M"is"; L"set-string"], Getopt.Set_string ("string", ss), "Set string";
[ S 't'; L"set" ], Getopt.Set set_flag, "Set flag";
+ [ S 'o'; L"optstr" ], Getopt.OptString ("string", set_optstr), "Set optional string";
]
let usage_msg = sprintf "%s: test the Getopt parser" prog
+let print_optstring_value = function
+ | Unset -> "not set"
+ | NoValue -> "<none>"
+ | Value s -> s
+
let opthandle = create_standard_options argspec ~anon_fun usage_msg
let () =
Getopt.parse opthandle;
@@ -66,4 +81,5 @@ let () =
printf "clear_flag = %b\n" !clear_flag;
printf "set_flag = %b\n" !set_flag;
printf "set_int = %d\n" !si;
- printf "set_string = %s\n" !ss
+ printf "set_string = %s\n" !ss;
+ printf "set_optstring = %s\n" (print_optstring_value !optstr)
diff --git a/common/mltools/test-getopt.sh b/common/mltools/test-getopt.sh
index 9db18fb44..58e2d0d59 100755
--- a/common/mltools/test-getopt.sh
+++ b/common/mltools/test-getopt.sh
@@ -52,6 +52,7 @@ $t --help | grep -- '-i, --int <int>'
$t --help | grep -- '-ii, --set-int <int>'
$t --help | grep -- '-v, --verbose'
$t --help | grep -- '-x'
+$t --help | grep -- '-o, --optstr <string>'
# --version
$t --version | grep '^getopt_tests 1\.'
@@ -60,6 +61,7 @@ $t --version | grep '^getopt_tests 1\.'
$t --short-options | grep '^-a'
$t --short-options | grep '^-c'
$t --short-options | grep '^-i'
+$t --short-options | grep '^-o'
$t --short-options | grep '^-q'
$t --short-options | grep '^-ii'
$t --short-options | grep '^-is'
@@ -78,6 +80,7 @@ $t --long-options | grep '^--colour'
$t --long-options | grep '^--colours'
$t --long-options | grep '^--debug-gc'
$t --long-options | grep '^--int'
+$t --long-options | grep '^--optstr'
$t --long-options | grep '^--quiet'
$t --long-options | grep '^--set'
$t --long-options | grep '^--set-int'
@@ -157,6 +160,14 @@ $t --set-string B | grep '^set_string = B'
expect_fail $t --is
expect_fail $t --set-string
+# -o/--optstr parameter.
+$t | grep '^set_optstring = not set'
+$t -o | grep '^set_optstring = <none>'
+$t --optstr | grep '^set_optstring = <none>'
+$t -o=A | grep '^set_optstring = A'
+$t --optstr=A | grep '^set_optstring = A'
+$t --optstr=A --optstr | grep '^set_optstring = <none>'
+
# Anonymous parameters.
$t | grep '^anons = \[\]'
$t 1 | grep '^anons = \[1\]'
--
2.17.1
6 years, 3 months