Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/config.ml.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ let package_version_full = "@PACKAGE_VERSION_FULL@"
let prefix = "@prefix@"
let datadir = prefix ^ "/share"
let host_cpu = "@host_cpu@"
let nbdkit = if "@NBDKIT@" = "" then None else Some "@NBDKIT@"
let nbdcopy = "@NBDCOPY@"
let nbdinfo = "@NBDINFO@"
3 changes: 3 additions & 0 deletions lib/config.mli
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ val datadir : string
val host_cpu : string
(** The configure value [@host_cpu@] *)

val nbdkit : string option
(** The location of the nbdkit program, from configure value [@NBDKIT@] *)

val nbdcopy : string
(** The location of the nbdcopy program, from configure value [@NBDCOPY@] *)

Expand Down
34 changes: 21 additions & 13 deletions lib/nbdkit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,22 @@ open Unix_utils

open Utils

let nbdkit_cmd : string ref = ref ""

let is_installed =
let test = lazy (Sys.command "nbdkit --version >/dev/null 2>&1" = 0) in
fun () -> Lazy.force test
match Config.nbdkit with
| Some path -> begin
nbdkit_cmd := path;
let cmd = sprintf "%s --version >/dev/null 2>&1" path in
let test = lazy (Sys.command cmd = 0) in
fun () -> Lazy.force test
end
| None -> fun () -> false

type config = (string * string) list

let get_config = lazy (
let cmd = "nbdkit --dump-config" in
let cmd = !nbdkit_cmd ^ " --dump-config" in
let lines = external_command cmd in
List.map (String.split "=") lines
)
Expand All @@ -54,30 +62,30 @@ let get_version = lazy (
and release = int_of_string (PCRE.sub 3) in
if verbose () then (
eprintf "info: nbdkit version:\n%!";
ignore (Sys.command "nbdkit --version >&2");
ignore (Sys.command (!nbdkit_cmd ^ " --version >&2"));
eprintf "parsed version: %d.%d.%d\n%!" major minor release
);
(major, minor, release)
)
let version () = Lazy.force get_version

let probe_plugin name =
let cmd = sprintf "nbdkit %s --version >/dev/null 2>&1" (quote name) in
let cmd = sprintf "%s %s --version >/dev/null 2>&1" !nbdkit_cmd (quote name) in
Sys.command cmd = 0

let probe_plugin_parameter name regex =
let cmd = sprintf "nbdkit %s --help | grep -sq %s"
(quote name) (quote regex) in
let cmd = sprintf "%s %s --help | grep -sq %s"
!nbdkit_cmd (quote name) (quote regex) in
Sys.command cmd = 0

let probe_filter name =
let cmd = sprintf "nbdkit null --filter=%s --version >/dev/null 2>&1"
(quote name) in
let cmd = sprintf "%s null --filter=%s --version >/dev/null 2>&1"
!nbdkit_cmd (quote name) in
Sys.command cmd = 0

let probe_filter_parameter name regex =
let cmd = sprintf "nbdkit null --filter=%s --help | grep -sq %s"
(quote name) (quote regex) in
let cmd = sprintf "%s null --filter=%s --help | grep -sq %s"
!nbdkit_cmd (quote name) (quote regex) in
Sys.command cmd = 0

type cmd = {
Expand Down Expand Up @@ -132,7 +140,7 @@ let run_unix socket cmd =
add_arg, add_args_reversed, get_args
in

add_arg "nbdkit";
add_arg !nbdkit_cmd;
add_arg "--exit-with-parent";
add_arg "--foreground";
add_arg "--pidfile"; add_arg pidfile;
Expand Down Expand Up @@ -173,7 +181,7 @@ let run_unix socket cmd =
if pid = 0 then (
(* Child process (nbdkit). *)
List.iter (fun (k, v) -> putenv k v) cmd.env;
execvp "nbdkit" args
execvp !nbdkit_cmd args
);

(* Wait for the pidfile to appear so we know that nbdkit
Expand Down
5 changes: 5 additions & 0 deletions m4/guestfs-progs.m4
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ AM_CONDITIONAL([HAVE_ZIP],[test "x$ZIP" != "xno"])
AC_PATH_PROGS([UNZIP],[unzip],[no])
AC_DEFINE_UNQUOTED([UNZIP],["$UNZIP"],[Name of unzip program.])

dnl Detect nbdkit also under /usr/sbin or /sbin in case they're not on $PATH
AC_PATH_PROG(NBDKIT,[nbdkit], [no], [/usr/sbin$PATH_SEPARATOR/sbin$PATH_SEPARATOR$PATH])
AS_IF([test "x$NBDKIT" = "xno"],
[AC_MSG_WARN([nbdkit binary (from nbdkit) not found, some runtime functionality will be missing])])

dnl nbdinfo, nbdcopy, required by virt-v2v
AC_CHECK_PROG([NBDINFO], [nbdinfo], [nbdinfo], [no])
AC_CHECK_PROG([NBDCOPY], [nbdcopy], [nbdcopy], [no])
Expand Down