1488 Commits

Author SHA1 Message Date
Richard W.M. Jones
dca92e4cf1 daemon: Use a configure-time test to find the best OCaml runtime.
In OCaml 4.06 we need to link to daemon to libasmrun_pic.a (the OCaml
runtime linked with -fPIC).  Otherwise you will see many errors like
this:

    /usr/bin/ld: /usr/lib64/ocaml/libasmrun.a(startup_aux.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
    /usr/bin/ld: /usr/lib64/ocaml/libasmrun.a(startup.o): relocation R_X86_64_32S against symbol `caml_data_segments' can not be used when making a shared object; recompile with -fPIC
    /usr/bin/ld: /usr/lib64/ocaml/libasmrun.a(fail.o): relocation R_X86_64_32 against symbol `caml_exn_Failure' can not be used when making a shared object; recompile with -fPIC
    /usr/bin/ld: /usr/lib64/ocaml/libasmrun.a(roots.o): relocation R_X86_64_32 against symbol `caml_frametable' can not be used when making a shared object; recompile with -fPIC

This commit use a configure-time test to find the best OCaml runtime.
2017-11-14 19:54:43 +00:00
Pino Toscano
b91ec0697d daemon: btrfs: fix bad handling of a couple of errors
Remove two wrong error handling situations in btrfs_balance_status:
- if the calloc for 'ret' fails, the 'goto error' would try to
  dereference the resulting null pointer (to free the items of the
  return struct); hence, just return null directly, instead of jumping
  to 'error'
- if the strdup() for 'btrfsbalance_status' fails, then the directly
  return would leak 'ret'
2017-11-03 16:44:20 +01:00
Pino Toscano
8213a572e4 daemon: btrfs: remove dead check
In btrfs_subvolume_show, an extra check on 'key' is used in a place
where this variable is already checked to be non-null.
2017-11-03 16:33:09 +01:00
Pino Toscano
62c9d5d8ca daemon: ldm: avoid manual free()
When the LDM code was converted to the CLEANUP_* macros, a free()
invocation for a CLEANUP_FREE variable was left in the
ldmtool_diskgroup_volumes implementation, causing double-free on
success.

Updates commit 950951c67d.
2017-11-03 16:29:28 +01:00
Pino Toscano
840ac44c9b daemon: simplify usage of Chroot.f
Rely on currying, and avoid extra helper functions.

No behaviour changes.
2017-10-17 14:20:45 +02:00
Pino Toscano
303abf899e daemon: use parse_key_value_strings
Make use of parse_key_value_strings to slightly simplify the parsing of
mdadm output, and the parsing of os-release, and lsb-release files.
In particular, the parsing of lsb-release is simplified a lot, bringing
it much like the parsing of os-release.
2017-10-16 18:31:37 +02:00
Pino Toscano
93ceed59a3 daemon: add split_key_value_strings helper
Add a simple helper to turn a list of strings into key/value pairs,
splitting by '=', with the possibility to apply a function to unquote
values.

Add also a simple unquote function.
2017-10-16 18:30:24 +02:00
Pino Toscano
d583352b7e daemon: inspection: discard os-release w/o version
In case os-release does not contain VERSION_ID, and it is not an
exception (like Void Linux), then discard the results got from
os-release.

This matches what the old C code did -- e.g. see
commit 32d19e3289, and the changes in
commit 0251c0fcaa.
2017-10-16 17:12:37 +02:00
Richard W.M. Jones
c30dd32c9c daemon: blkid: Use Option.default.
Plain refactoring.
2017-10-13 21:33:33 +01:00
Richard W.M. Jones
b92f74458f common/mlstdutils: Introduce Option submodule.
Inspired by ocaml-extlib, introduce a module for handling option
types.

We already had the ‘may’ function (which becomes ‘Option.may’).  This
adds also ‘Option.map’ (unused), and ‘Option.default’ functions.

Note this does *not* introduce the unsafe ‘Option.get’ function from
extlib.
2017-10-12 16:31:47 +01:00
Richard W.M. Jones
0b631d739b daemon: proto: Make the guestfsd main loop messages consistent and useful.
After this change the debugging output looks like this:

  guestfsd: <= mount (0x1) request length 64 bytes
  commandrvf: stdout=n stderr=y flags=0x0
  commandrvf: udevadm --debug settle -E /dev/sda1
  calling: settle
  command: mount '/dev/sda1' '/sysroot//'
  [    1.152813] EXT4-fs (sda1): mounting ext2 file system using the ext4 subsystem
  [    1.154815] EXT4-fs (sda1): mounted filesystem without journal. Opts: (null)
  guestfsd: => mount (0x1) took 0.01 secs
  guestfsd: <= touch (0x3) request length 52 bytes
  guestfsd: => touch (0x3) took 0.00 secs

Thanks: Pino Toscano
2017-10-12 16:26:43 +01:00
Richard W.M. Jones
cd08039d24 daemon: inspection: Add support for NeoKylin (RHBZ#1476081).
Thanks: Qingzheng Zhang
2017-10-12 15:38:06 +01:00
Richard W.M. Jones
bf22909dd6 daemon: inspection: Sort cases in check_package_* functions.
No change, just sorts the cases into alphabetical order for easier
modification.

Tidies up commit 394d11be49.
2017-10-12 10:39:07 +01:00
Richard W.M. Jones
fbc3ca4fe8 daemon: Enable warn-error in OCaml code.
This was accidentally disabled because I used the wrong
variable name.

Fixes commit d5b6f1df5f.
2017-10-12 10:39:07 +01:00
Richard W.M. Jones
45d6f8bef9 daemon: Use O_CLOEXEC instead of Unix.set_close_on_exec.
In fact we already used O_CLOEXEC in daemon/inspect_fs_windows.c,
meaning that the code wouldn't have compiled on OCaml 3.11.

Thanks: Pino Toscano
2017-10-05 11:32:54 +01:00
Richard W.M. Jones
c7651744da ocaml: Replace pattern matching { field = field } with { field }.
If you have a struct containing ‘field’, eg:

  type t = { field : int }

then previously to pattern-match on this type, eg. in function
parameters, you had to write:

  let f { field = field } =
    (* ... use field ... *)

In OCaml >= 3.12 it is possible to abbreviate cases where the field
being matched and the variable being bound have the same name, so now
you can just write:

  let f { field } =
    (* ... use field ... *)

(Similarly for a field prefixed by a Module name you can use
‘{ Module.field }’ instead of ‘{ Module.field = field }’).

This style is widely used inside the OCaml compiler sources, and is
briefer than the long form, so it makes sense to use it.  Furthermore
there was one place in virt-dib where we are already using this new
style, so the old code did not compile on OCaml < 3.12.

See also:
https://forge.ocamlcore.org/docman/view.php/77/112/leroy-cug2010.pdf
2017-10-05 11:32:54 +01:00
Richard W.M. Jones
bbd54295d3 daemon: Reimplement statvfs API in OCaml, drop gnulib fallback.
common/mlutils: Unix_utils.StatVFS.statvfs: This commit implements a
full-featured binding for the statvfs(3) function.

We then use this to reimplement the daemon statvfs API in OCaml.

Note that the Gnulib fallback is dropped in this commit.  It
previously referenced non-existent field names in the fs_usage struct
so it didn't work.  Also it's not necessary as POSIX has supported
statvfs(3) since 2001, it's supported in *BSD, macOS > 10.4, and there
is already a Windows fallback.
2017-10-04 15:25:32 +01:00
Richard W.M. Jones
a706ecb8f7 Make sure every *.ml file has a corresponding *.mli file. 2017-09-21 18:05:07 +01:00
Richard W.M. Jones
290e4608f4 daemon: Remove vestigial daemon/types.ml file.
This file was empty and unused, likely left over from refactorings
while the daemon inspection code was being written.

Fixes commit d5b6f1df5f.
2017-09-21 18:05:07 +01:00
Richard W.M. Jones
6a12065f34 daemon: inspect: Simplify parse_version_from_major_minor.
Thanks: Pino Toscano.

Updates commit cb7696a5d2.
2017-09-20 17:49:27 +01:00
Richard W.M. Jones
5aad7e779c daemon: Implement inspection of Windows.
Mostly a line-for-line translation of the C inspection code.
2017-09-16 22:27:16 +01:00
Richard W.M. Jones
394d11be49 daemon: Implement inspection of Linux and other Unix-like operating systems.
This is essentially a line-for-line translation of the C inspection
code.
2017-09-16 22:27:16 +01:00
Richard W.M. Jones
cb7696a5d2 daemon: Implement inspection types and utility functions.
Define the types which will be used to communicate between the
different parts of the inspection code.  The main types are:

  fs        corresponds to ‘struct inspect_fs’ in C code

  root      no direct correspondence with the C code, but in the C
            code, ‘inspect_fs’ was overloaded to store roots

  inspection_data
            the inspection data which is incrementally collected about
            each filesystem as we perform inspection steps

Other types have simple and obvious correspondences with the
equivalent C code.

Add some utility function which will be used by inspection.

Note that this commit has no effect on its own, it just links extra
dead code into the daemon.
2017-09-16 22:27:16 +01:00
Richard W.M. Jones
984d83ac57 generator: daemon: Implement RStringList (RMountable, _) and RHashtable (RPlainString, RMountable, _).
Implement returning these two types from OCaml daemon functions.
2017-09-16 22:27:16 +01:00
Richard W.M. Jones
9af6ee0d78 daemon: Implement umount_all in OCaml.
Unlike previous ‘daemon: Reimplement ...’ patches, this does not
reimplement the umount_all API completely (yet, but this
implementation could be completed in future and then replace the C
one).  However it is necessary to have a version of umount_all which
we can call from the OCaml inspection code.
2017-09-16 22:27:16 +01:00
Richard W.M. Jones
19940fc2bd New API: Deprecate hivex_value_utf8 and replace with hivex_value_string.
hivex has a function hivex_value_string.  We were not calling it under
the mistaken belief that because hivex implements this using iconv,
the function wouldn't work inside the daemon.  Instead we
reimplemented the functionality in the library.

This commit deprecates hivex_value_utf8 and removes the library side
code.  It replaces it with a plain wrapper around hivex_value_string.

Thanks: Pino Toscano
2017-09-16 22:27:16 +01:00
Richard W.M. Jones
11b8a5db19 daemon: utils: New functions and tests.
These utility functions will be used in the OCaml inspection code.
2017-09-16 22:27:16 +01:00
Richard W.M. Jones
2ffb8a6b25 common: Bundle the ocaml-augeas library for use by the daemon.
This commit bundles the ocaml-augeas library (upstream here:
http://git.annexia.org/?p=ocaml-augeas.git;a=summary).  It's identical
to the upstream version and should remain so.

We can work towards using system ocaml-augeas, when it's more widely
available.
2017-09-16 22:27:16 +01:00
Richard W.M. Jones
a0c1e6120c daemon: chroot: Enhance module documentation. 2017-09-16 22:26:58 +01:00
Richard W.M. Jones
692195c6ba build: Add a common script for generating OCaml dependencies correctly.
These are generated in many different ways in the various
subdirectories, and sometimes not generated correctly.  Introduce a
script to do this in one place, and hopefully correctly.

This is mostly simple refactoring, but I got rid of a couple of
things:

(1) The ‘make depend’ rule doesn't appear to be needed.  automake (or
make?)  seems to rebuild the ‘.depend’ file automatically just because
it is included.

(2) I got rid of the hairy path rewriting sed expression.  Possibly
that is needed for srcdir != builddir.
2017-08-09 14:45:48 +01:00
Richard W.M. Jones
63071bb8f9 daemon: lvm: Pass device parameter of lvm_canonical_lv_name as PlainString.
All sorts of strings might be passed here hoping to make them
canonical LV names.  We cannot be sure that the strings passed will be
devices which exist in the appliance.
2017-08-08 17:50:23 +01:00
Richard W.M. Jones
07ba8b6d6b daemon: Refine check for Device and Dev_or_Path parameters (RHBZ#1477623).
For Device parameters we expect a block device name.  However we were
only testing for "/dev/..." and so chardevs (from the appliance) could
be passed here, resulting in strange effects.  This adds a function
is_device_parameter which tests for a valid block device name.

For Dev_or_Path parameters much the same, except we can also use the
is_device_parameter function elsewhere in the daemon to distinguish if
we were called with a device or path parameter.  Previously we used a
simple test if the path begins with "/dev/...".

Reported by Mathieu Tarral.
2017-08-08 17:50:23 +01:00
Richard W.M. Jones
0bf521cfcb daemon: Deduplicate some utility functions.
The following functions were previously reimplemented in OCaml.  This
commit replaces them with calls to the C functions:

 - is_root_device
 - prog_exists
 - udev_settle

plus the internal get_verbose_flag function.

However note that we cannot do this for every utility function.  In
particular the C function must not call any reply* functions.
2017-08-08 16:23:42 +01:00
Richard W.M. Jones
403692bdac daemon: Move utility functions to a separate file.
This allows us to share certain utility functions with OCaml code.
2017-08-08 16:23:42 +01:00
Richard W.M. Jones
42085b6bd5 daemon: utils: Small refactoring to hide ‘chan’ from code. 2017-08-08 16:23:42 +01:00
Richard W.M. Jones
2eac205e25 daemon: Remove extra space from debug message. 2017-08-08 16:14:36 +01:00
Richard W.M. Jones
38359eaf3e daemon: Restore PCRE regular expressions in OCaml code.
When parts of the daemon were previously converted to OCaml, the
previous PCRE regexps were converted to Str regexps.  Restore the
original PCRE regexps.

There was also one case where an original call to glob(3) was replaced
by a Str regexp, and this is replaced by a PCRE regexp (although it is
in fact identical in this instance).

This updates commit b48da89dd6
and commit eeda6edca1
and commit 2ca0fa778d.
2017-08-03 17:36:09 +01:00
Richard W.M. Jones
c73f0a6675 daemon: ntfs: fix name of the ntfs-3g.probe tool in one other place.
Fixes commit 381c8b68c4, which forgot to
add the dash in the name.

See also commit ef53cd5619 which fixed
the same thing elsewhere.
2017-07-31 16:20:50 +01:00
Pino Toscano
ef53cd5619 daemon: ntfs: fix name of the ntfs-3g.probe tool
Fixes commit 381c8b68c4, which forgot to
add the dash in the name.
2017-07-31 11:16:17 +02:00
Nikos Skalkotos
c355b744bf New partition API: part_resize
This can be used to enlarge or shrink an existing partition.
2017-07-31 10:51:18 +02:00
Richard W.M. Jones
70b6f33566 daemon: Reimplement ‘device_index’ API in OCaml. 2017-07-27 22:31:22 +01:00
Richard W.M. Jones
3027a33110 daemon: Reimplement ‘part_get_parttype’, ‘part_get_gpt_type’, ‘part_get_gpt_guid’ APIs in OCaml. 2017-07-27 22:31:22 +01:00
Richard W.M. Jones
1e956dfc7d daemon: Reimplement ‘realpath’ API in OCaml. 2017-07-27 22:31:22 +01:00
Richard W.M. Jones
fe01905729 daemon: Reimplement ‘md_detail’ API in OCaml. 2017-07-27 22:31:22 +01:00
Richard W.M. Jones
90c6bffcdd daemon: Reimplement ‘nr_devices’ API in OCaml. 2017-07-27 22:31:22 +01:00
Richard W.M. Jones
c37c8e770d daemon: Reimplement ‘findfs_uuid’ and ‘findfs_label’ APIs in OCaml.
This also reimplements the lv_canonical function in OCaml.  We cannot
call the original C function because it calls reply_with_perror which
would break the OCaml bindings.
2017-07-27 22:31:22 +01:00
Richard W.M. Jones
32e661f421 daemon: Reimplement ‘part_list’ API in OCaml. 2017-07-27 22:31:22 +01:00
Richard W.M. Jones
4052f613d2 daemon: Reimplement ‘list_filesystems’ API in the daemon, in OCaml.
Move the list_filesystems API into the daemon, reimplementing it in
OCaml.  Since this API makes many other API calls, it runs a lot
faster in the daemon.
2017-07-27 22:31:22 +01:00
Richard W.M. Jones
eeda6edca1 daemon: Reimplement ‘btrfs_subvolume_list’ and ‘btrfs_subvolume_get_default’ in OCaml. 2017-07-27 22:31:22 +01:00
Richard W.M. Jones
2ca0fa778d daemon: Reimplement ‘list_md_devices’ API in OCaml. 2017-07-27 22:31:22 +01:00