Commit Graph

1266 Commits

Author SHA1 Message Date
Richard W.M. Jones
dd162d2cd5 daemon: Move lvmetad to early in the appliance boot process.
When the daemon starts up it creates a fresh (empty) LVM configuration
and starts up lvmetad (which depends on the LVM configuration).

However this appears to cause problems: Some types of PV seem to
require lvmetad and don't work without it
(https://bugzilla.redhat.com/show_bug.cgi?id=1581810).  If we don't
start lvmetad earlier, the device nodes are not created.

Therefore move the whole initialization step into appliance/init.

Two further changes had to be made:

Now we are using lvmetad all the time, using vgchange is incorrect.
With lvmetad activated early we must use ‘pvscan --cache --activate ay’
to scan all disks for PVs and activate any VGs on them (although the
documentation is complex, confusing and contradictory so I'm not
completely sure about this).

The ‘lvm_system_dir’ local variable in ‘daemon/lvm-filter.c’
previously contained the path of the directory above $LVM_SYSTEM_DIR
(eg. $LVM_SYSTEM_DIR = "/etc/lvm", lvm_system_dir = "/etc").  As this
was highly confusing, I have changed it so the local variable and the
environment variable have identical contents.  This involved removing
the ‘lvm/’ component from a couple of paths since it is now included
in the local variable.
2018-05-29 20:38:40 +01:00
Adam Robinson
431d8c8c1e macOS: Include <rpc/types.h> before <rpc/xdr.h>.
The ordering of includes is required on this platform.
2018-05-15 11:15:54 +01:00
Pino Toscano
3151d5e927 daemon: tweak regexp for file type detection (RHBZ#1575640)
Newer versions of file slightly changed the output, removing the comma
between the type, and the architecture string.

Tweak the regular expression so:
- the comma is optional, but if missing then only the architecture
  string will follow
- the architecture string has no commas
2018-05-07 17:06:11 +02:00
Nikolay Ivanets
994ca1f8eb daemon: Reimplement 'part_get_mbr_part_type' API in OCaml.
Instead of parsing 'parted' output OCaml implementation relies on the following facts:

1. MBR partition table can hold up to 4 "primary" partitions.
2. Partition with number greater then 4 is "logical" partition.
3. Partition with number less then or equal to 4 with MBR ID 0x05 or 0x0f is "extended" partition (http://thestarman.pcministry.com/asm/mbr/PartTypes.htm; https://en.wikipedia.org/wiki/Partition_type) or "primary" otherwise.
2018-05-02 12:07:16 +01:00
Pino Toscano
9667587366 daemon: simplify string allocation
When creating an helper string for do_aug_match(), use a simpler
asprintf() with manual free(), since the code block is small enough.

This slightly helps static code analyzers.
2018-05-01 17:26:16 +01:00
Pino Toscano
fced132718 daemon: upload: fix fd leak on lseek failure
Make sure to not leak the file descriptor in the upload() function, in
case lseek() fails.
2018-05-01 17:26:16 +01:00
Pino Toscano
d00e860ef0 New API: f2fs_expand
Expose the resize.f2fs utility from f2fs-tools, to expand a f2fs
filesystem.
2018-04-19 11:30:29 +02:00
Hilko Bengen
802c5d2055 Fix out-of-tree builds of OCaml components
- Add $(srcdir), $(builddir) to Makefiles where required
- Post-process ocamldep output
- generate ocaml/.depends
2018-04-12 11:43:56 +02:00
Pino Toscano
e655676157 daemon: autogenerate OCaml interfaces
Add a way to generate OCaml interfaces for all the 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.
2018-04-10 12:55:37 +02:00
Pino Toscano
6c13d2356e daemon: move Mount.umount_all to new Mount_utils module
This way the Mount module contains only the OCaml implementations of
mount-related daemon APIs.

This is simple refactoring, with no functional changes.
2018-04-10 12:12:10 +02:00
Pino Toscano
2bdc7b83ce daemon: move Lvm.lv_canonical to new Lvm_utils module
This way the Lvm module contains only the OCaml implementations of LVM
daemon APIs.

This is simple refactoring, with no functional changes.
2018-04-10 12:12:09 +02:00
Pino Toscano
188e995d32 daemon: use the structs from the Structs module
No need to redeclare them again in few modules, just use them from the
Structs module.
2018-04-10 12:12:09 +02:00
Pino Toscano
a43bdb9379 daemon: directly use Optgroups
Avoid extra module variables, and just use Optgroups directly.
2018-04-10 12:12:09 +02:00
Richard W.M. Jones
07ead43cbb daemon: Fix type signature of mount_vfs (RHBZ#1564983).
Reported-by: Yongkui Guo.

Fixes commit 82bbd9c8a5.
2018-04-09 13:31:40 +01:00
Pino Toscano
1c996bf314 daemon: tsk: handle new enum values in sleuthkit 4.5
Resort to a version check for them, as they do not exist in older
versions.
2018-02-19 17:14:18 +01:00
Pino Toscano
535a4471f3 inspect: use check_tests also for detecting Hurd
Even though the list of checks is very short, at least this migrates
from imperative checks to a "declarative" one.

There should be no behaviour change, other than using os-release if it
contains all the needed information.
2018-02-14 17:19:52 +01:00
Pino Toscano
1dd11d2276 inspect: recognize the Kali Linux distribution (RHBZ#1544227)
Read the information from os-release, and make it behave like a
Debian distribution (i.e. using dpkg, and apt).
2018-02-12 14:32:19 +01:00
Pino Toscano
bd1c5c9f4d Switch from YAJL to Jansson
While YAJL mostly works fine, it did not see any active development in
the last 3 years.  OTOH, Jansson is another JSON C implementation, with
a very liberal license, and a much nicer API.

Hence, switch all of libguestfs from YAJL to Jansson:
- configure checks, and buildsystem in general
- packages pulled in the appliance
- actual implementations
- contrib scripts
- documentation

This also makes use of the better APIs available (e.g. json_object_get,
json_array_foreach, and json_object_foreach).  This does not change the
API of our OCaml Yajl module.
2018-02-12 11:24:06 +01:00
Daniel P. Berrangé
3c7bbf97e2 daemon: add inspector support for MS-DOS distro
An installation of MS-DOS has various files in a /DOS directory,
which COMMAND.COM looking like a reasonable signal that its MS-DOS
or a very close relative there-of.

This is validated with an MS-DOS 6.22 install.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-07 18:18:27 +00:00
Pino Toscano
82fbf294fd daemon: build also without Hivex.OPEN_UNSAFE (RHBZ#1493048)
Do a configure check for the OPEN_UNSAFE flag in the OCaml binding of
Hivex, using it only when available.  This makes it possible to use
hivex < 1.3.14 to build libguestfs (the daemon, actually).

Amend the building documentation accordingly, bringing the minimum
version of hivex back as it was before
commit 64f49df747.
2018-02-06 17:27:23 +01:00
Cédric Bosdonnat
c5fdc4f764 New APIs: part_set_gpt_attributes and part_get_gpt_attributes
Allow reading and setting the GPT partition attribute flags.
2018-01-16 13:03:39 +00:00
Cédric Bosdonnat
5f26f70262 daemon: make sgdisk_info_extract_uuid_field more generic
Rename the sgdisk_info_extract_uuid_field to
sgdisk_info_extract_field in order to reuse it for other field types.
Just like its C ancestor, it now needs an extractor function to be
passed as parameter.
2018-01-16 12:51:46 +00:00
Richard W.M. Jones
4ac3be3d04 daemon: tests: Compile tests with compiler warnings.
And fix the problems.
2018-01-09 12:17:53 +00:00
Richard W.M. Jones
04031269f6 tests: Further instances of $(RPC_CFLAGS). 2018-01-09 12:17:53 +00:00
Richard W.M. Jones
212762c593 Update copyright dates for 2018.
Run the following command over the source:

  perl -pi.bak -e 's/(20[01][0-9])-2017/$1-2018/g' `git ls-files`
2018-01-04 15:30:10 +00:00
Richard W.M. Jones
a93a06dc59 daemon: Rewrite inspection code using ‘return’ statements.
When rewriting this, I revisited the original C code and changed the
OCaml code so it's now reasonably similar to the original.
2017-12-08 16:22:14 +00:00
Richard W.M. Jones
0eb23230fa common/mlstdutils: Move list functions into extended List module.
However some existing functions had names which shadowed existing
functions in the List module, so I had to rename them:

  assoc -> List.assoc_lbl
  append -> List.push_back_list
  prepend -> List.push_front_list

This is an extension of the previous commit.
2017-12-08 16:22:11 +00:00
Richard W.M. Jones
3ef6794b09 common/mlstdutils: Add with_openfile function.
This safe wrapper around Unix.openfile ensures that exceptions
escaping cannot leave unclosed files.

There are only a few places in the code where this wrapper can be used
currently.  There are other occurences of Unix.openfile but they are
not suitable for replacement.
2017-11-16 12:32:58 +00:00
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