[Libguestfs] [PATCH] Fix out-of-tree builds of OCaml components

2018-04-09 Thread Hilko Bengen
- Add $(srcdir), $(builddir) to Makefiles where required
- Post-process ocamldep output
- generate ocaml/.depends
---
 builder/Makefile.am   |  7 ---
 common/mlgettext/Makefile.am  |  2 +-
 common/mlpcre/Makefile.am |  2 +-
 common/mlprogress/Makefile.am |  2 +-
 common/mlstdutils/Makefile.am |  2 +-
 common/mltools/Makefile.am|  2 +-
 common/mlutils/Makefile.am|  2 +-
 common/mlvisit/Makefile.am|  2 +-
 common/mlxml/Makefile.am  |  2 +-
 customize/Makefile.am |  2 +-
 daemon/Makefile.am| 10 +-
 generator/Makefile.am |  2 +-
 get-kernel/Makefile.am|  2 +-
 ocaml-dep.sh.in   | 18 --
 ocaml/Makefile.am |  3 +--
 resize/Makefile.am|  2 +-
 sparsify/Makefile.am  |  2 +-
 subdir-rules.mk   |  6 +++---
 v2v/Makefile.am   |  2 +-
 v2v/test-harness/Makefile.am  |  2 +-
 20 files changed, 44 insertions(+), 30 deletions(-)

diff --git a/builder/Makefile.am b/builder/Makefile.am
index a17a2aa6d6..c7b50778a1 100644
--- a/builder/Makefile.am
+++ b/builder/Makefile.am
@@ -142,11 +142,12 @@ bin_PROGRAMS += virt-builder virt-builder-repository
 
 virt_builder_SOURCES = $(SOURCES_C)
 virt_builder_CPPFLAGS = \
-   -I. \
+   -I$(builddir) -I$(srcdir) \
-I$(top_builddir) \
-I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib \
-I$(shell $(OCAMLC) -where) \
-I$(top_srcdir)/gnulib/lib \
+   -I$(top_builddir)/common/utils \
-I$(top_srcdir)/common/utils \
-I$(top_srcdir)/lib
 virt_builder_CFLAGS = \
@@ -163,7 +164,7 @@ XOBJECTS = $(BOBJECTS:.cmo=.cmx)
 
 virt_builder_repository_SOURCES = $(REPOSITORY_SOURCES_C)
 virt_builder_repository_CPPFLAGS = \
-   -I. \
+   -I$(builddir) -I$(srcdir) \
-I$(top_builddir) \
-I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib \
-I$(shell $(OCAMLC) -where) \
@@ -446,7 +447,7 @@ CLEANFILES += \
console-*.out
 
 # OCaml dependencies.
-.depend: *.mli *.ml osinfo_config.mli osinfo_config.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml osinfo_config.mli osinfo_config.ml
$(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
diff --git a/common/mlgettext/Makefile.am b/common/mlgettext/Makefile.am
index 4cca6b4db0..cdcea33ec5 100644
--- a/common/mlgettext/Makefile.am
+++ b/common/mlgettext/Makefile.am
@@ -79,7 +79,7 @@ mlgettext.cmxa: $(XOBJECTS)
 endif
 
 # Dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
$(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
diff --git a/common/mlpcre/Makefile.am b/common/mlpcre/Makefile.am
index 4ff74cf972..f9699f5922 100644
--- a/common/mlpcre/Makefile.am
+++ b/common/mlpcre/Makefile.am
@@ -122,7 +122,7 @@ check-valgrind:
$(MAKE) VG="@VG@" check
 
 # Dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
$(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
diff --git a/common/mlprogress/Makefile.am b/common/mlprogress/Makefile.am
index f031a5a69e..be88ef2dee 100644
--- a/common/mlprogress/Makefile.am
+++ b/common/mlprogress/Makefile.am
@@ -93,7 +93,7 @@ $(MLPROGRESS_CMA): $(OBJECTS) libmlprogress.a
-o mlprogress
 
 # OCaml dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
$(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
diff --git a/common/mlstdutils/Makefile.am b/common/mlstdutils/Makefile.am
index cc05c5a73f..e38230db8a 100644
--- a/common/mlstdutils/Makefile.am
+++ b/common/mlstdutils/Makefile.am
@@ -141,7 +141,7 @@ check-valgrind:
$(MAKE) VG="@VG@" check
 
 # OCaml dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
$(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
diff --git a/common/mltools/Makefile.am b/common/mltools/Makefile.am
index 2ea1fee8ff..66b18f5ded 100644
--- a/common/mltools/Makefile.am
+++ b/common/mltools/Makefile.am
@@ -253,7 +253,7 @@ check-valgrind:
$(MAKE) VG="@VG@" check
 
 # Dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
$(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
diff --git a/common/mlutils/Makefile.am b/common/mlutils/Makefile.am
index 33d742f4c3..8627e5b10c 100644
--- a/common/mlutils/Makefile.am
+++ b/common/mlutils/Makefile.am
@@ -135,7 +135,7 @@ c_utils_unit_tests_LINK = \
  $(c_utils_unit_tests_THEOBJECTS) -o $@
 
 # Dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
$(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
diff --git a/common/mlvisit/Makefile.am b/common/mlvisit/Makefile.am
index 6902c9a2a9..add1fe56e8 100644
--- a/common/mlvisit/Makefile.am
+++ b/common/mlvisit/Makefile.am
@@ -139,7 +139,7 @@ check-valgrind:
$(MAKE) VG="@VG@" check
 
 # OCaml dependencies.
-.depend: *.mli *.ml
+.depend: $(srcdir)/*.mli $(srcdir)/*.ml
$(top_builddir)/ocaml-dep.sh $^
 -include .depend
 
diff --git 

[Libguestfs] [nbdkit PATCH 2/1] RFC: tests: Run tests that don't require libguestfs

2018-04-09 Thread Eric Blake
A bit of refactoring to the HAVE_LIBGUESTFS conditional,
coupled with the addition of a LIBGUESTFS_TESTS intermediate
list, allows us to run a few more tests on CentOS 6 (adding
some tests of command-line behavior and filters that was
previously completely skipped).

For the two tests that we can't run, using check_PROGRAMS
still causes those programs to try to compile (which leads to
compile errors); but using EXTRA_PROGRAMS keeps automake
silent without getting those sources in the way, while still
distributing the sources for someone motivated to fix the
tests.

Compared to the previous patch (14/14 pass and 5 skip), I now
have 15/18 pass and 9 skip.

Signed-off-by: Eric Blake 
---

This one was more invasive than the previous, but may still be
worth having on top of the configure change that disables
HAVE_LIBGUESTFS on CentOS 7.  The three test failures are now:

./test-dump-plugin-example4.sh: unexpected output from nbdkit example4 
--dump-plugin
path=/home/dummy/nbdkit/plugins/perl/.libs/nbdkit-perl-plugin.so
name=perl
version=1.3.0
...
has__zero_old=1
FAIL: test-dump-plugin-example4.sh


nbd://?socket=cache.sock: No such file or directory
./test-cache.sh: line 64: kill: (32161) - No such process
FAIL: test-cache.sh
guestfish: -N parameter 'cow-base.img=fs': no such prepared disk image known.
Use 'guestfish -N help' to list possible values for the -N parameter.
FAIL: test-cow.sh

(hmm, so my attempt to guard test-cache.sh and test-cow.sh by
HAVE_GUESTFISH didn't really help)

 tests/Makefile.am | 71 +--
 1 file changed, 32 insertions(+), 39 deletions(-)

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 2cc2344..4582120 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -190,7 +190,11 @@ TESTS += \

 # Most in-depth tests need libguestfs, since that is a convenient way to
 # drive qemu.
+LIBGUESTFS_TESTS =
+EXTRA_PROGRAMS =
 if HAVE_LIBGUESTFS
+check_PROGRAMS += $(LIBGUESTFS_TESTS)
+TESTS += $(LIBGUESTFS_TESTS)

 # Use the 'direct' backend, and ensure maximum libguestfs debugging is
 # written to the *.log files in case there is a problem.
@@ -206,32 +210,30 @@ libtest_la_SOURCES = test.c test.h
 libtest_la_CFLAGS = $(WARNINGS_CFLAGS)

 # Basic connection test.
-check_PROGRAMS += test-connect
-TESTS += test-connect
+LIBGUESTFS_TESTS += test-connect

 test_connect_SOURCES = test-connect.c test.h
 test_connect_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
 test_connect_LDADD = libtest.la $(LIBGUESTFS_LIBS)

 # newstyle protocol test.
-check_PROGRAMS += test-newstyle
-TESTS += test-newstyle
+LIBGUESTFS_TESTS += test-newstyle

 test_newstyle_SOURCES = test-newstyle.c test.h
 test_newstyle_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
 test_newstyle_LDADD = libtest.la $(LIBGUESTFS_LIBS)

 # oldstyle protocol test.
-check_PROGRAMS += test-oldstyle
-TESTS += test-oldstyle
+LIBGUESTFS_TESTS += test-oldstyle

 test_oldstyle_SOURCES = test-oldstyle.c test.h
 test_oldstyle_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
 test_oldstyle_LDADD = libtest.la $(LIBGUESTFS_LIBS)

+endif HAVE_LIBGUESTFS
+
 # file plugin test.
-check_PROGRAMS += test-file
-TESTS += test-file
+LIBGUESTFS_TESTS += test-file

 test_file_SOURCES = test-file.c test.h
 test_file_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
@@ -241,8 +243,7 @@ test_file_LDADD = libtest.la $(LIBGUESTFS_LIBS)
 if HAVE_ZLIB
 if HAVE_GUESTFISH

-check_PROGRAMS += test-gzip
-TESTS += test-gzip
+LIBGUESTFS_TESTS += test-gzip
 check_DATA += disk disk.gz
 MAINTAINERCLEANFILES += disk disk.gz

@@ -263,24 +264,21 @@ endif HAVE_GUESTFISH
 endif HAVE_ZLIB

 # memory plugin test.
-check_PROGRAMS += test-memory
-TESTS += test-memory
+LIBGUESTFS_TESTS += test-memory

 test_memory_SOURCES = test-memory.c test.h
 test_memory_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
 test_memory_LDADD = libtest.la $(LIBGUESTFS_LIBS)

 # nbd plugin test.
-check_PROGRAMS += test-nbd
-TESTS += test-nbd
+LIBGUESTFS_TESTS += test-nbd

 test_nbd_SOURCES = test-nbd.c test.h
 test_nbd_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
 test_nbd_LDADD = libtest.la $(LIBGUESTFS_LIBS)

 # null plugin test.
-check_PROGRAMS += test-null
-TESTS += test-null
+LIBGUESTFS_TESTS += test-null

 test_null_SOURCES = test-null.c test.h
 test_null_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
@@ -301,17 +299,16 @@ split3: file-data
rm -f $@ $@-t
dd if=$< of=$@-t bs=1 skip=200
mv $@-t $@
-check_PROGRAMS += test-split
-TESTS += test-split
+LIBGUESTFS_TESTS += test-split

 test_split_SOURCES = test-split.c test.h
 test_split_CFLAGS = $(WARNINGS_CFLAGS) $(LIBGUESTFS_CFLAGS)
 test_split_LDADD = libtest.la $(LIBGUESTFS_LIBS)

 # streaming plugin test.
-check_PROGRAMS += test-streaming
 # Doesn't work:
-#TESTS += test-streaming
+#LIBGUESTFS_TESTS += test-streaming
+EXTRA_PROGRAMS += test-streaming

 test_streaming_SOURCES = test-streaming.c test.h
 test_streaming_CFLAGS = $(WARNINGS_CFLAGS) 

Re: [Libguestfs] [PATCH 3/3] daemon: autogenerate most of OCaml interfaces

2018-04-09 Thread Richard W.M. Jones
On Mon, Apr 09, 2018 at 04:06:32PM +0200, Pino Toscano wrote:
> diff --git a/generator/daemon.ml b/generator/daemon.ml
> index 7fb7052a0..03b191ac8 100644
> --- a/generator/daemon.ml
> +++ b/generator/daemon.ml
> @@ -490,6 +490,91 @@ let generate_daemon_caml_callbacks_ml () =
>else
>  pr "let init_callbacks () = ()\n"
>  
> +let rec generate_daemon_caml_interface modname () =
> +  generate_header OCamlStyle GPLv2plus;
> +
> +  let is_ocaml_module_function = function
> +| { impl = OCaml m } when String.is_prefix m (modname ^ ".") -> true
> +| { impl = OCaml _ } -> false
> +| { impl = C } -> false
> +  in
> +
> +  let ocaml_actions = actions |> (List.filter is_ocaml_module_function) in
> +  if ocaml_actions == [] then
> +failwithf "no OCaml implementations for module %s" modname;
> +
> +  let prefix_length = String.length modname + 1 in
> +  List.iter (
> +fun ({ name; style } as f) ->
> +  let ocaml_function =
> +match f.impl with
> +| OCaml f -> String.sub f prefix_length (String.length f - 
> prefix_length)
> +| C -> assert false in
> +
> +  generate_ocaml_daemon_prototype ocaml_function style
> +  ) ocaml_actions
> +
> +and generate_ocaml_daemon_prototype name style =
> +  pr "val %s : " name;
> +  generate_ocaml_daemon_function_type style;
> +  pr "\n"
> +
> +and generate_ocaml_daemon_function_type (ret, args, optargs) =
> +  let type_for_stringt = function
> +| Mountable
> +| Mountable_or_Path -> "Mountable.t"
> +| PlainString
> +| Device
> +| Pathname
> +| FileIn
> +| FileOut
> +| Key
> +| GUID
> +| Filename
> +| Dev_or_Path -> "string"
> +  in
> +  let type_for_rstringt = function
> +| RMountable -> "Mountable.t"
> +| RPlainString
> +| RDevice -> "string"
> +  in
> +  List.iter (
> +function
> +| OBool n -> pr "?%s:bool -> " n
> +| OInt n -> pr "?%s:int -> " n
> +| OInt64 n -> pr "?%s:int64 -> " n
> +| OString n -> pr "?%s:string -> " n
> +| OStringList n -> pr "?%s:string array -> " n
> +  ) optargs;
> +  if args <> [] then
> +List.iter (
> +  function
> +  | String (typ, _)-> pr "%s -> " (type_for_stringt typ)
> +  | BufferIn _ -> pr "string -> "
> +  | OptString _ -> pr "string option -> "
> +  | StringList (typ, _)-> pr "%s array -> " (type_for_stringt typ)
> +  | Bool _ -> pr "bool -> "
> +  | Int _ -> pr "int -> "
> +  | Int64 _ | Pointer _ -> pr "int64 -> "
> +) args
> +  else
> +pr "unit -> ";
> +  (match ret with
> +   | RErr -> pr "unit" (* all errors are turned into exceptions *)
> +   | RInt _ -> pr "int"
> +   | RInt64 _ -> pr "int64"
> +   | RBool _ -> pr "bool"
> +   | RConstString _ -> pr "string"
> +   | RConstOptString _ -> pr "string option"
> +   | RString (typ, _) -> pr "%s" (type_for_rstringt typ)
> +   | RBufferOut _ -> pr "string"
> +   | RStringList (typ, _) -> pr "%s list" (type_for_rstringt typ)
> +   | RStruct (_, typ) -> pr "Structs.%s" typ
> +   | RStructList (_, typ) -> pr "Structs.%s list" typ
> +   | RHashtable (typea, typeb, _) ->
> +   pr "(%s * %s) list" (type_for_rstringt typea) (type_for_rstringt 
> typeb)
> +  )
> +
>  (* Generate stubs for the functions implemented in OCaml.
>   * Basically we implement the do_ function here, and
>   * have it call out to OCaml code.

> diff --git a/generator/main.ml b/generator/main.ml
> index 34bca68d9..ed75d1005 100644
> --- a/generator/main.ml
> +++ b/generator/main.ml
> @@ -46,6 +46,11 @@ let output_to_subset fs f =
>for i = 0 to nr_actions_files-1 do
>  ksprintf (fun filename -> output_to filename (f actions_subsets.(i))) fs 
> i
>done
> +let output_to_ocaml_daemon modname =
> +  let fn = Char.escaped (Char.lowercase_ascii (String.unsafe_get modname 0)) 
> ^
> +   String.sub modname 1 (String.length modname - 1) in
> +  output_to (sprintf "daemon/%s.mli" fn)
> +(Daemon.generate_daemon_caml_interface modname)
>  
>  (* Main program. *)
>  let () =
> @@ -155,6 +160,11 @@ Run it from the top source directory using the command
>  Daemon.generate_daemon_structs_cleanups_c;
>output_to "daemon/structs-cleanups.h"
>  Daemon.generate_daemon_structs_cleanups_h;
> +  let daemon_ocaml_interfaces = [
> +"Blkid"; "Btrfs"; "Devsparts"; "File"; "Filearch"; "Findfs"; "Inspect";
> +"Is"; "Ldm"; "Link"; "Listfs"; "Md"; "Parted"; "Realpath"; "Statvfs";
> +  ] in

This list should be generated from the list of APIs, splitting the
OCaml "module.function" fields to get module name.

Also "Mount" is not included in this list (and possibly others, I
didn't check).  Mount has a non-generated interface (umount_all) which
I guess is the reason, but unfortunately this reduces the value of
generating these interfaces.

> +  List.iter output_to_ocaml_daemon daemon_ocaml_interfaces;

Is there a reason this isn't inlined?  It seems a bit awkward
to have the actual body elsewhere in the file.

Rich.

>  

Re: [Libguestfs] [PATCH 2/3] daemon: use the structs from the Structs module

2018-04-09 Thread Richard W.M. Jones

ACK 1/3 and 2/3.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW

___
Libguestfs mailing list
Libguestfs@redhat.com
https://www.redhat.com/mailman/listinfo/libguestfs


Re: [Libguestfs] [PATCH v3 2/3] v2v: OVF: write ovirt:id attribute for the OS in OVirt flavour

2018-04-09 Thread Pino Toscano
On Friday, 6 April 2018 17:45:22 CEST Tomáš Golembiovský wrote:
> On Thu,  5 Apr 2018 14:53:51 +0200
> Pino Toscano  wrote:
> 
> > @@ -383,8 +581,9 @@ let rec create_ovf source targets guestcaps inspect
> >  ] in
> >  (match ovf_flavour with
> >  | OVirt ->
> > -  e "OperatingSystemSection" ["ovf:id", vm_uuid;
> > -  "ovf:required", "false"]
> > +  let ovirt_osid = get_ovirt_osid inspect in
> > +  e "OperatingSystemSection" ["ovf:required", "false";
> > +  "ovirt:id", string_of_int ovirt_osid]
> 
> Sadly, OVF schema says ovf:id is reqiured. But since the generated OVF
> is not used by anything besides oVirt I think we can live without it.

Not a problem them: I did put it back, and push the patch.

Thanks,
-- 
Pino Toscano

signature.asc
Description: This is a digitally signed message part.
___
Libguestfs mailing list
Libguestfs@redhat.com
https://www.redhat.com/mailman/listinfo/libguestfs

Re: [Libguestfs] Change in ovirt-imageio[master]: Document the random I/O APIs

2018-04-09 Thread Richard W.M. Jones
On Wed, Mar 28, 2018 at 04:10:28PM +, Daniel Erez wrote:
> Hi Richard,
> 
> We've added zero and flush functionality to imageio-daemon.
> 
> You can download and test the latest build (for el7/fc) from:
> -
> http://jenkins.ovirt.org/job/ovirt-imageio_master_build-artifacts-el7-x86_64/200/artifact/exported-artifacts/
> -
> http://jenkins.ovirt.org/job/ovirt-imageio_master_build-artifacts-fc27-x86_64/53/artifact/exported-artifacts/
> -
> http://jenkins.ovirt.org/job/ovirt-imageio_master_build-artifacts-fcraw-x86_64/11/artifact/exported-artifacts/
> 
> The latest documentation and examples for Random I/O:
> - https://github.com/oVirt/ovirt-imageio/blob/master/docs/random-io.md
> - https://github.com/oVirt/ovirt-imageio/tree/master/examples
> 
> Notes:
> - We plan to introduce the functionality also to the proxy soon.
> - We plan to implement trim later during ovirt 4.2 release:
> https://gerrit.ovirt.org/89470
> - Additional pending patches:
> https://gerrit.ovirt.org/#/q/status:open+project:ovirt-imageio+branch:master+topic:random-io

I can't remember if I replied to this already, but anyway I tested
updated packages last week and the zero/flush functionality works fine
(once I corrected a small mistake in my Python code).

Thanks,

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html

___
Libguestfs mailing list
Libguestfs@redhat.com
https://www.redhat.com/mailman/listinfo/libguestfs


[Libguestfs] [PATCH] daemon: Fix type signature of mount_vfs (RHBZ#1564983).

2018-04-09 Thread Richard W.M. Jones
Reported-by: Yongkui Guo.

Fixes commit 82bbd9c8a503661528289589976697d08cb41090.
---
 daemon/inspect_fs.ml |  6 ++
 daemon/mount.ml  | 18 +-
 daemon/mount.mli |  2 +-
 3 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/daemon/inspect_fs.ml b/daemon/inspect_fs.ml
index 383e3e0a7..02e2060b9 100644
--- a/daemon/inspect_fs.ml
+++ b/daemon/inspect_fs.ml
@@ -39,14 +39,12 @@ let rec check_for_filesystem_on mountable vfs_type =
 if vfs_type = "ufs" then ( (* Hack for the *BSDs. *)
   (* FreeBSD fs is a variant of ufs called ufs2 ... *)
   try
-Mount.mount_vfs (Some "ro,ufstype=ufs2") (Some "ufs")
-mountable "/";
+Mount.mount_vfs "ro,ufstype=ufs2" "ufs" mountable "/";
 true
   with _ ->
 (* while NetBSD and OpenBSD use another variant labeled 44bsd *)
 try
-  Mount.mount_vfs (Some "ro,ufstype=44bsd") (Some "ufs")
-  mountable "/";
+  Mount.mount_vfs "ro,ufstype=44bsd" "ufs" mountable "/";
   true
 with _ -> false
 ) else (
diff --git a/daemon/mount.ml b/daemon/mount.ml
index a4e744f7b..e42ea1580 100644
--- a/daemon/mount.ml
+++ b/daemon/mount.ml
@@ -32,22 +32,22 @@ let mount_vfs options vfs mountable mountpoint =
 
   (* -o options *)
   (match options, mountable.m_type with
-   | (None | Some ""), (MountableDevice | MountablePath) -> ()
-   | Some options, (MountableDevice | MountablePath) ->
+   | "", (MountableDevice | MountablePath) -> ()
+   | options, (MountableDevice | MountablePath) ->
   List.push_back args "-o";
   List.push_back args options
-   | (None | Some ""), MountableBtrfsVol subvol ->
+   | "", MountableBtrfsVol subvol ->
   List.push_back args "-o";
   List.push_back args ("subvol=" ^ subvol)
-   | Some options, MountableBtrfsVol subvol ->
+   | options, MountableBtrfsVol subvol ->
   List.push_back args "-o";
   List.push_back args ("subvol=" ^ subvol ^ "," ^ options)
   );
 
   (* -t vfs *)
   (match vfs with
-   | None | Some "" -> ()
-   | Some t ->
+   | "" -> ()
+   | t ->
   List.push_back args "-t";
   List.push_back args t
   );
@@ -57,9 +57,9 @@ let mount_vfs options vfs mountable mountpoint =
 
   ignore (command "mount" !args)
 
-let mount = mount_vfs None None
-let mount_ro = mount_vfs (Some "ro") None
-let mount_options options = mount_vfs (Some options) None
+let mount = mount_vfs "" ""
+let mount_ro = mount_vfs "ro" ""
+let mount_options options = mount_vfs options ""
 
 (* Unmount everything mounted under /sysroot.
  *
diff --git a/daemon/mount.mli b/daemon/mount.mli
index 553630667..96c400190 100644
--- a/daemon/mount.mli
+++ b/daemon/mount.mli
@@ -19,6 +19,6 @@
 val mount : Mountable.t -> string -> unit
 val mount_ro : Mountable.t -> string -> unit
 val mount_options : string -> Mountable.t -> string -> unit
-val mount_vfs : string option -> string option -> Mountable.t -> string -> unit
+val mount_vfs : string -> string -> Mountable.t -> string -> unit
 
 val umount_all : unit -> unit
-- 
2.16.2

___
Libguestfs mailing list
Libguestfs@redhat.com
https://www.redhat.com/mailman/listinfo/libguestfs


Re: [Libguestfs] [PATCH] daemon: Fix type signature of mount_vfs (RHBZ#1564983).

2018-04-09 Thread Pino Toscano
On Monday, 9 April 2018 09:54:51 CEST Richard W.M. Jones wrote:
> https://bugzilla.redhat.com/show_bug.cgi?id=1564983
> 
> Because Mount.mount_vfs was declared with the wrong type signature it
> could never be called correctly from outside the daemon.

LGTM.

> The root cause of this problem is that the generator doesn't generate
> the type signatures automatically (which it could do, and fairly
> easily).  Therefore there are probably other similar bugs waiting to
> be found.

Let's see how this turns out.

-- 
Pino Toscano

signature.asc
Description: This is a digitally signed message part.
___
Libguestfs mailing list
Libguestfs@redhat.com
https://www.redhat.com/mailman/listinfo/libguestfs

[Libguestfs] [PATCH] daemon: Fix type signature of mount_vfs (RHBZ#1564983).

2018-04-09 Thread Richard W.M. Jones
https://bugzilla.redhat.com/show_bug.cgi?id=1564983

Because Mount.mount_vfs was declared with the wrong type signature it
could never be called correctly from outside the daemon.

The root cause of this problem is that the generator doesn't generate
the type signatures automatically (which it could do, and fairly
easily).  Therefore there are probably other similar bugs waiting to
be found.

Rich.

___
Libguestfs mailing list
Libguestfs@redhat.com
https://www.redhat.com/mailman/listinfo/libguestfs


[Libguestfs] [PATCH 3/3] daemon: autogenerate most of OCaml interfaces

2018-04-09 Thread Pino Toscano
Add a way to generate OCaml interfaces for a whilelist of modules in
the daemon that implement APIs: this makes sure that for them the
interface of each function matches the actual API specified in the
generator.

Only the modules specified in a list are generated for now, although
this coverts almost all the daemon APIs implemented in OCaml.
---
 .gitignore   | 15 ++
 daemon/blkid.mli | 19 
 daemon/btrfs.mli | 20 -
 daemon/devsparts.mli | 25 
 daemon/file.mli  | 19 
 daemon/filearch.mli  | 19 
 daemon/findfs.mli| 20 -
 daemon/inspect.mli   | 41 -
 daemon/is.mli| 21 -
 daemon/ldm.mli   | 20 -
 daemon/link.mli  | 19 
 daemon/listfs.mli| 19 
 daemon/md.mli| 20 -
 daemon/parted.mli| 27 -
 daemon/realpath.mli  | 20 -
 daemon/statvfs.mli   | 19 
 generator/daemon.ml  | 85 
 generator/daemon.mli |  1 +
 generator/main.ml| 10 +++
 19 files changed, 111 insertions(+), 328 deletions(-)
 delete mode 100644 daemon/blkid.mli
 delete mode 100644 daemon/btrfs.mli
 delete mode 100644 daemon/devsparts.mli
 delete mode 100644 daemon/file.mli
 delete mode 100644 daemon/filearch.mli
 delete mode 100644 daemon/findfs.mli
 delete mode 100644 daemon/inspect.mli
 delete mode 100644 daemon/is.mli
 delete mode 100644 daemon/ldm.mli
 delete mode 100644 daemon/link.mli
 delete mode 100644 daemon/listfs.mli
 delete mode 100644 daemon/md.mli
 delete mode 100644 daemon/parted.mli
 delete mode 100644 daemon/realpath.mli
 delete mode 100644 daemon/statvfs.mli

diff --git a/.gitignore b/.gitignore
index bb7026537..6927b8bb5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -185,21 +185,36 @@ Makefile.in
 /customize/virt-customize.1
 /daemon/.depend
 /daemon/actions.h
+/daemon/blkid.mli
+/daemon/btrfs.mli
 /daemon/callbacks.ml
 /daemon/caml-stubs.c
 /daemon/daemon_config.ml
 /daemon/daemon_utils_tests
+/daemon/devsparts.mli
 /daemon/dispatch.c
+/daemon/file.mli
+/daemon/filearch.mli
+/daemon/findfs.mli
 /daemon/guestfsd
 /daemon/guestfsd.8
 /daemon/guestfsd.exe
+/daemon/inspect.mli
+/daemon/is.mli
+/daemon/ldm.mli
+/daemon/link.mli
+/daemon/listfs.mli
 /daemon/lvm-tokenization.c
+/daemon/md.mli
 /daemon/names.c
 /daemon/optgroups.c
 /daemon/optgroups.h
 /daemon/optgroups.ml
 /daemon/optgroups.mli
+/daemon/parted.mli
+/daemon/realpath.mli
 /daemon/stamp-guestfsd.pod
+/daemon/statvfs.mli
 /daemon/structs-cleanups.c
 /daemon/structs-cleanups.h
 /daemon/structs.ml
diff --git a/daemon/blkid.mli b/daemon/blkid.mli
deleted file mode 100644
index 65a61def4..0
--- a/daemon/blkid.mli
+++ /dev/null
@@ -1,19 +0,0 @@
-(* guestfs-inspection
- * Copyright (C) 2009-2018 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 vfs_type : Mountable.t -> string
diff --git a/daemon/btrfs.mli b/daemon/btrfs.mli
deleted file mode 100644
index ce1c2b66f..0
--- a/daemon/btrfs.mli
+++ /dev/null
@@ -1,20 +0,0 @@
-(* guestfs-inspection
- * Copyright (C) 2009-2018 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 btrfs_subvolume_list : Mountable.t -> Structs.btrfssubvolume list
-val btrfs_subvolume_get_default : Mountable.t -> int64
diff --git a/daemon/devsparts.mli b/daemon/devsparts.mli
deleted file mode 100644
index 7b669c269..0
--- a/daemon/devsparts.mli
+++ /dev/null
@@ -1,25 +0,0 @@
-(* guestfs-inspection
- * Copyright (C) 2009-2018 Red Hat 

[Libguestfs] [PATCH 0/3] daemon: generate almost all the API OCaml interfaces

2018-04-09 Thread Pino Toscano
Hi,

as a followup for the signature fix for mount_vfs [1], here it is a
patch series to generate automatically most of the OCaml interfaces of
daemon actions.  Only the Lvm and Mount modules are left with
hand-written interfaces.

[1] https://www.redhat.com/archives/libguestfs/2018-April/msg00059.html

Thanks,

Pino Toscano (3):
  daemon: directly use Optgroups
  daemon: use the structs from the Structs module
  daemon: autogenerate most of OCaml interfaces

 .gitignore   | 15 
 daemon/blkid.mli | 19 --
 daemon/btrfs.mli | 26 --
 daemon/devsparts.mli | 25 -
 daemon/file.mli  | 19 --
 daemon/filearch.mli  | 19 --
 daemon/findfs.mli| 20 ---
 daemon/inspect.mli   | 41 -
 daemon/inspect_fs_windows.ml |  4 +--
 daemon/is.mli| 21 ---
 daemon/ldm.ml|  2 --
 daemon/ldm.mli   | 22 
 daemon/link.mli  | 19 --
 daemon/listfs.ml |  8 ++---
 daemon/listfs.mli| 19 --
 daemon/lvm.ml|  2 --
 daemon/lvm.mli   |  2 --
 daemon/md.mli| 20 ---
 daemon/parted.mli| 34 --
 daemon/realpath.mli  | 20 ---
 daemon/statvfs.mli   | 33 -
 generator/daemon.ml  | 85 
 generator/daemon.mli |  1 +
 generator/main.ml| 10 ++
 24 files changed, 117 insertions(+), 369 deletions(-)
 delete mode 100644 daemon/blkid.mli
 delete mode 100644 daemon/btrfs.mli
 delete mode 100644 daemon/devsparts.mli
 delete mode 100644 daemon/file.mli
 delete mode 100644 daemon/filearch.mli
 delete mode 100644 daemon/findfs.mli
 delete mode 100644 daemon/inspect.mli
 delete mode 100644 daemon/is.mli
 delete mode 100644 daemon/ldm.mli
 delete mode 100644 daemon/link.mli
 delete mode 100644 daemon/listfs.mli
 delete mode 100644 daemon/md.mli
 delete mode 100644 daemon/parted.mli
 delete mode 100644 daemon/realpath.mli
 delete mode 100644 daemon/statvfs.mli

-- 
2.14.3

___
Libguestfs mailing list
Libguestfs@redhat.com
https://www.redhat.com/mailman/listinfo/libguestfs


[Libguestfs] [PATCH 2/3] daemon: use the structs from the Structs module

2018-04-09 Thread Pino Toscano
No need to redeclare them again in few modules, just use them from the
Structs module.
---
 daemon/btrfs.mli |  8 +---
 daemon/inspect_fs_windows.ml |  4 ++--
 daemon/listfs.ml |  4 ++--
 daemon/parted.mli|  9 +
 daemon/statvfs.mli   | 16 +---
 5 files changed, 7 insertions(+), 34 deletions(-)

diff --git a/daemon/btrfs.mli b/daemon/btrfs.mli
index 8ca91fb47..ce1c2b66f 100644
--- a/daemon/btrfs.mli
+++ b/daemon/btrfs.mli
@@ -16,11 +16,5 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *)
 
-type btrfssubvolume = {
-  btrfssubvolume_id : int64;
-  btrfssubvolume_top_level_id : int64;
-  btrfssubvolume_path : string;
-}
-
-val btrfs_subvolume_list : Mountable.t -> btrfssubvolume list
+val btrfs_subvolume_list : Mountable.t -> Structs.btrfssubvolume list
 val btrfs_subvolume_get_default : Mountable.t -> int64
diff --git a/daemon/inspect_fs_windows.ml b/daemon/inspect_fs_windows.ml
index e9d056cd9..8b2aad8d3 100644
--- a/daemon/inspect_fs_windows.ml
+++ b/daemon/inspect_fs_windows.ml
@@ -372,10 +372,10 @@ and map_registry_disk_blob devices blob =
 let offset = int_of_le64 offset in
 let partitions = Parted.part_list device in
 let partition =
-  List.find (fun { Parted.part_start = s } -> s = offset) partitions in
+  List.find (fun { Structs.part_start = s } -> s = offset) partitions in
 
 (* Construct the full device name. *)
-Some (sprintf "%s%ld" device partition.Parted.part_num)
+Some (sprintf "%s%ld" device partition.Structs.part_num)
   with
   | Not_found -> None
 
diff --git a/daemon/listfs.ml b/daemon/listfs.ml
index f6e3dcd6e..56ebadeda 100644
--- a/daemon/listfs.ml
+++ b/daemon/listfs.ml
@@ -125,13 +125,13 @@ and check_with_vfs_type device =
 let default_volume = Btrfs.btrfs_subvolume_get_default mountable in
 let vols =
   List.filter (
-fun { Btrfs.btrfssubvolume_id = id } -> id <> default_volume
+fun { Structs.btrfssubvolume_id = id } -> id <> default_volume
   ) vols in
 
 Some (
   (mountable, vfs_type) (* whole device = default volume *)
   :: List.map (
-   fun { Btrfs.btrfssubvolume_path = path } ->
+   fun { Structs.btrfssubvolume_path = path } ->
  let mountable = Mountable.of_btrfsvol device path in
  (mountable, "btrfs")
  ) vols
diff --git a/daemon/parted.mli b/daemon/parted.mli
index d547f2f2a..0b7eb87f4 100644
--- a/daemon/parted.mli
+++ b/daemon/parted.mli
@@ -16,15 +16,8 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *)
 
-type partition = {
-  part_num : int32;
-  part_start : int64;
-  part_end : int64;
-  part_size : int64;
-}
-
 val part_get_mbr_id : string -> int -> int
-val part_list : string -> partition list
+val part_list : string -> Structs.partition list
 
 val part_get_parttype : string -> string
 
diff --git a/daemon/statvfs.mli b/daemon/statvfs.mli
index d241f995b..13b22f88d 100644
--- a/daemon/statvfs.mli
+++ b/daemon/statvfs.mli
@@ -16,18 +16,4 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *)
 
-type statvfs = {
-  bsize : int64;
-  frsize : int64;
-  blocks : int64;
-  bfree : int64;
-  bavail : int64;
-  files : int64;
-  ffree : int64;
-  favail : int64;
-  fsid : int64;
-  flag : int64;
-  namemax : int64;
-}
-
-val statvfs : string -> statvfs
+val statvfs : string -> Structs.statvfs
-- 
2.14.3

___
Libguestfs mailing list
Libguestfs@redhat.com
https://www.redhat.com/mailman/listinfo/libguestfs


Re: [Libguestfs] [nbdkit PATCH 2/2] python: Simplify calling into plugin

2018-04-09 Thread Eric Blake
On 04/06/2018 05:24 PM, Eric Blake wrote:
> PyObject_CallObject is powerful, but awkward - we have to wrap
> all arguments into a temporary tuple before using it.
> 
> Let python do more of the work by using PyObject_CallFunction
> anywhere that all arguments can be described by a Py_BuildValue()
> format string, instead of creating one-shot arguments ourselves.
> In fact, for our py_config(), this makes it easier to not worry
> about python 2 String vs. python 3 Unicode.
> 
> Similarly, PyObject_CallFunctionObjArgs is nicer when we
> already have PyObjects for all parameters (including in py_open(),
> where we can't use a Py_BuildValue() string for converting a
> C int into Py_True or Py_False, but can easily avoid the tuple
> wrapper).
> 
> py_zero() is not converted, as it will be changed differently
> to make 'may_trim' an optional callback parameter.
> 
> Signed-off-by: Eric Blake 
> ---
>  plugins/python/python.c | 97 
> -
>  1 file changed, 15 insertions(+), 82 deletions(-)
> 

> @@ -258,17 +257,8 @@ py_config (const char *key, const char *value)
>  /* Other parameters are passed to the Python .config callback. */
>  PyErr_Clear ();
> 
> -args = PyTuple_New (2);

In fact, this patch is a corner-case bug fix.  Here, and in all sorts of
similar places, we are failing to check for args == NULL (unlikely
except on OOM conditions, but still a valid error condition, where we
would presumably have a nice Python error object to report failure with)...

> -#ifdef HAVE_PYSTRING_FROMSTRING
> -PyTuple_SetItem (args, 0, PyString_FromString (key));

...and instead passing NULL on to a function that would crash.  We are
likewise not checking for errors here (although such errors should never
be possible).

> -PyTuple_SetItem (args, 1, PyString_FromString (value));
> -#else
> -PyTuple_SetItem (args, 0, PyUnicode_FromString (key));
> -PyTuple_SetItem (args, 1, PyUnicode_FromString (value));
> -#endif
> -r = PyObject_CallObject (fn, args);
> +r = PyObject_CallFunction (fn, "ss", key, value);

The replacement code is not only shorter, it has fewer places to worry
about corner-case boilerplate error checking.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3266
Virtualization:  qemu.org | libvirt.org



signature.asc
Description: OpenPGP digital signature
___
Libguestfs mailing list
Libguestfs@redhat.com
https://www.redhat.com/mailman/listinfo/libguestfs