Commit Graph

1439 Commits

Author SHA1 Message Date
Richard W.M. Jones
396397ac8d generator: Implement StringList for OCaml functions
No existing OCaml functions have a StringList parameter, but we would
like to add one.

The original plan seems to have been to map these to 'string array'
types, but 'string list' is more natural, albeit marginally less
efficient.  The implementation here just has to convert the 'char **'
into the OCaml linked list of values.

(cherry picked from commit fd4db60cff)
2025-08-13 16:09:36 +01:00
Richard W.M. Jones
67a261c47a daemon: sysroot: Avoid copying the path every time we call sysroot ()
This path never changes once the daemon has started up, so we don't
need to call into C code and copy the string every time.

(cherry picked from commit c931ab3bc8)
2025-08-13 16:09:25 +01:00
Richard W.M. Jones
4a0a1e7cd7 daemon: sysroot: Avoid double-/ when creating sysroot paths in OCaml
Previously calling 'sysroot_path "/dev"' for example would return the
string "/sysroot//dev".  While this is not wrong, it confuses some
external programs (hello, setfiles), and it's not very "clean".  Be a
bit more careful to avoid doubling the '/' character in the common case.

(cherry picked from commit 1e0099671a)
2025-08-13 16:09:19 +01:00
Richard W.M. Jones
f4f84a8824 daemon: Add contents of /etc/fstab to verbose log
Also some mdadm configuration files.  This is useful for debugging.

The output looks like this:

  info: /etc/fstab in /dev/VG/Root
  LABEL=BOOT /boot ext2 default 0 0$
  LABEL=ROOT / ext2 default 0 0$

Fixes: https://issues.redhat.com/browse/RHEL-106490
2025-07-30 11:01:03 +01:00
Cole Robinson
bcf204ad68 daemon: inspect: factor out resolve_dev_mapper function
This is just code movement.

Signed-off-by: Cole Robinson <crobinso@redhat.com>

RWMJ: Renamed and moved the function for consistency with surrounding
code.
2025-06-13 09:10:30 +01:00
Richard W.M. Jones
8f5e4f07ba inspection: Ignore btrfs snapshots of roots
In SLES guests in particular, btrfs snapshots seem to be used to allow
rollback of changes made to the filesystem.  Dozens of snapshots may
be present.  Technically therefore these are multi-boot guests.  The
libguestfs concept of "root" of an operating system does not map well
to this, causing problems in virt-inspector and virt-v2v.

In this commit we ignore these duplicates.  The test is quite narrow
to avoid false positives: We only remove a duplicate if it is a member
of a parent device, both are btrfs, both the snapshot and parent have
a root role, and the roles are otherwise very similar.

There may be a case for reporting this information separately in
future, although it's also easy to find this out now.  For example,
when you see a btrfs root device returned by inspect_os, you could
call btrfs_subvolume_list on the root device to list the snapshots.

Fixes: https://issues.redhat.com/browse/RHEL-93109
2025-05-27 17:01:09 +01:00
Richard W.M. Jones
ebaba43221 daemon/inspect.ml: Fix comment
Back in commit 8289aa1ad6 ("New APIs for guest inspection.", 2010)
when inspection was first added, we did inspection in the library, so
it was accurate to say that inspection information was stored "in the
handle".  Much later, in commit 394d11be49 and commit 3a00c4d179
(2017) we moved inspection to the daemon, but left the comment the
same.

Fixes: commit 3a00c4d179
2025-05-27 17:01:09 +01:00
Richard W.M. Jones
b2ec671abd daemon/inspect.ml: Pipeline style when mapping and filtering filesystems
No actual change in the functionality, just make it clear that this is
a pipeline of transformations on the list of filesystems.
2025-05-27 17:01:09 +01:00
Richard W.M. Jones
7ac190ed20 daemon/listfs.ml: Add more debugging to list_filesystems
This function is used from other parts of the daemon, especially for
example with inspection.  However it was difficult to follow exactly
what filesystems it was returning because of insufficient debugging
information.
2025-05-27 17:01:09 +01:00
Richard W.M. Jones
b98cc96129 daemon: Implement e2fsck -n flag (as FORCENO option)
Fixes: https://issues.redhat.com/browse/RHEL-92599
2025-05-20 14:40:58 +01:00
Richard W.M. Jones
ea3dd97f1d New API: Replace btrfs-fsck with btrfs-scrub-full
The old btrfs-fsck API used "btrfs check" which appears to be broken
or deprecated.  The real tool you should use is "btrfs scrub".  We
have already implemented that API, but it is very awkward to use from
libguestfs.  In particular there's no existing way to run the scrub
and wait for it to finish.

Fix this by deprecating btrfs-fsck.  Implement a new API
btrfs-scrub-full which runs btrfs scrub in the foreground, waits for
it to finish, and handles errors.  It's much more like fsck tools in
other filesystems.

Thanks: Eric Sandeen
Fixes: https://issues.redhat.com/browse/RHEL-91936
2025-05-19 13:42:44 +01:00
Richard W.M. Jones
f9edfc9a18 Update common submodule
This pulls in the commits below, requiring us to replace all uses of
String.is_prefix and String.is_suffix.

Mostly done with Perl like this, and carefully checked by hand
afterwards since this doesn't get everything right:

  $ perl -pi.bak -e 's/String.is_prefix ([^[:space:]\)]+) ([^[:space:]\)]+)/String.starts_with \2 \1/g' -- `git ls-files`

  Richard W.M. Jones (3):
      mlstdutils: Fix comment that still referred to the old function names
      mldrivers: Link to gettext-stub if ocaml-gettext is enabled
      mlstdutils: Rename String.is_prefix -> starts_with, is_suffix -> ends_with
2025-05-11 21:29:23 +01:00
Richard W.M. Jones
c4ebeee505 Update common submodule
Pull in these commits which require minor changes:

  Richard W.M. Jones (3):
      mlstdutils: Remove Std_utils.identity
      mlstdutils: Remove Std_utils.protect
      mlstdutils: Remove List.filter_map
2025-05-11 12:37:23 +01:00
Richard W.M. Jones
5441d3dd0c daemon: inspect: Remove duplicate root mountpoints in /etc/fstab
A customer case was found where /etc/fstab contained multiple root
mountpoints, something like:

  LABEL=System / xfs ...
  LABEL=Boot /boot ext2 ...
  LABEL=System / xfs ...

This causes libguestfs and virt-v2v to fail.  Either (on RHEL 9) we
try to mount the second instance of / which gives an error.  Or (on
upstream kernels) we are able to mount the second instance but then
libguestfs gets confused when trying to unmount them.

In this case as the mounted devices are the same we can just delete
the duplicate.  It's also possible that there could be multiple
non-identical root mountpoints, in which case we have to pick one, and
this code arbitrarily picks the first[*] (but emits a warning).

We don't do anything for non-root mountpoints.

Update common submodule to add 'List.same' function from mlstdutils.

[*] Which one is "the first" depends on what version of ocaml-augeas
we are using.  ocaml-augeas version 0.6 Augeas.matches function
returns entries in reverse order (compared to augeas itself).  This is
fixed in version 0.7:
http://git.annexia.org/?p=ocaml-augeas.git;a=commitdiff;h=b703b92e3d26690aa6f7b822132049ce5435983e

Fixes: https://issues.redhat.com/browse/RHEL-90168
2025-05-08 21:14:23 +01:00
Richard W.M. Jones
9b32056061 Fix miscellaneous spelling mistakes
$ git ls-files | xargs codespell
2025-04-29 19:05:07 +01:00
Richard W.M. Jones
ca87485eea daemon/fstrim.c: Run the fstrim command twice
In upstream kernels, for XFS, you may have to run fstrim twice for it
to be effective.

Fixes: https://issues.redhat.com/browse/RHEL-88508
Related: https://issues.redhat.com/browse/RHEL-88450
Thanks: Eric Sandeen
2025-04-28 10:07:34 +01:00
Richard W.M. Jones
e127edcafc daemon/fstrim.c: Issue sync_disks after fstrim
Thanks: Eric Sandeen
2025-04-25 15:24:43 +01:00
Richard W.M. Jones
166395914f daemon: Use $(OCAMLLIB) instead of ocamlc -where
OCAMLLIB is already set to the value of ocamlc -where that was found
at configure time, so there is no need to run that command again at
build time.
2025-04-22 12:37:40 +01:00
Richard W.M. Jones
e43ca19129 daemon: inspect: Resolve Ubuntu 22+ /dev/disk/by-id/dm-uuid-LVM-... in fstab
Linux + LVM supports device names like /dev/disk/by-id/dm-uuid-LVM-
followed by two concatenated UUIDs, firstly for the volume group and
secondly for the logical volume.  We can reverse those to get the
device name (/dev/VG/LV).

fstab entries look like:

  # / was on /dev/vg0/lv-0 during curtin installation
  /dev/disk/by-id/dm-uuid-LVM-OzFWT6NHkstr1hcmrWRRMDGPn9xdZj1YOOycQ533186x288FdU6UubU3OlnWJz6D / ext4 defaults 0 1
  # /usr was on /dev/vg0/lv-1 during curtin installation
  /dev/disk/by-id/dm-uuid-LVM-OzFWT6NHkstr1hcmrWRRMDGPn9xdZj1YZu53m4ZssZ8Jeb3I14RAJwIj5YlHIb9P /usr ext4 defaults 0 1

The upshot of this fix is that we are now able to correctly inspect
and run virt-v2v on Ubuntu 22+ guests with split /usr.  In particular,
we correctly map /etc/fstab entries like the above to LV device names,
which means that /usr merging now works correctly.

Reported-by: Jaroslav Spanko
Thanks: Daniel Berrange
Fixes: https://issues.redhat.com/browse/RHEL-87493
2025-04-16 21:12:49 +01:00
Richard W.M. Jones
a73f248369 daemon: Rewrite {pvs,vgs,lvs}-full APIs in OCaml
These were previously written in very convoluted C which had to deal
with parsing the crazy output of the "lvm" command.  In fact the
parsing was so complex that it was generated by the generator.  It's
easier to do this in OCaml.

These are basically legacy APIs.  They cannot be expanded and LVM
already supports many more fields.  We should replace these with APIs
for getting single named fields from LVM.
2025-04-16 21:12:49 +01:00
Richard W.M. Jones
7a1ffd744b daemon: inspect: Resolve Ubuntu 22+ /dev/disk/by-uuid/ in fstab
Ubuntu 22= uses /dev/disk/by-uuid/ followed by a filesystem UUID in
fstab entries.  Resolve these to mountables.

A typical fstab entry looks like this:

  # /boot was on /dev/vda2 during curtin installation
  /dev/disk/by-uuid/b4e56462-5a64-4272-b76d-f5e58bd8f128 /boot ext4 defaults 0 1

The comment is generated by the installer and appears in the fstab.
This entry would be translated to /dev/sda2.
2025-04-16 21:12:49 +01:00
Richard W.M. Jones
5a16d1120f generator: Use new FDevice type for the pvs-full pv_name field
Remove the code which did explicit reverse device name translation,
and use the generator's code instead.
2025-04-16 12:27:07 +01:00
Richard W.M. Jones
2d1e894130 daemon: inspect: Add some debugging of /usr merging 2025-04-16 10:28:41 +01:00
Richard W.M. Jones
4176b2043f daemon: Fix loongarch64 detection on RHEL 9
$ rpm -q file
file-5.39-16.el9.x86_64
$ file ./test-data/binaries/bin-loongarch64-dynamic
./test-data/binaries/bin-loongarch64-dynamic: ELF 64-bit LSB pie executable, *unknown arch 0x102* version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-loongarch-lp64d.so.1, BuildID[sha1]=7622a1a70bf6e697851ac3790557e1ca686459b5, for GNU/Linux 5.19.0, stripped

Updates: commit 729d6d55ea
2025-03-11 13:40:14 +00:00
denisecheng
0c70675aae support TencentOS
Signed-off-by: denisecheng <denisecheng@tencent.com>
Fixes: https://github.com/libguestfs/libguestfs/pull/172
Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
2025-03-03 14:22:37 +00:00
Richard W.M. Jones
47ac4871b2 daemon: New command_out and sh_out APIs
These APIs allow you to capture output from guest commands that
generate more output than the protocol limit allows.

Thanks: Nijin Ashok
Fixes: https://issues.redhat.com/browse/RHEL-80159
2025-02-19 12:01:10 +00:00
Richard W.M. Jones
72cfaff5c5 Update copyright dates for 2025
Automated using this command:

perl -pi.bak -e 's/(20[012][0-9])-20[12][01234]/$1-2025/g' `git ls-files`
2025-02-16 17:00:46 +00:00
Richard W.M. Jones
ed21af3b0a daemon: Translate file 5.46 "Intel i386" to "i386"
Fixes: https://github.com/libguestfs/libguestfs/issues/162
Reported-by: Toolybird
2025-01-02 16:13:35 +00:00
Richard W.M. Jones
996dd8774f build: Move baseline OCaml to 4.08
OCaml 4.08.0 was released on 2019-06-14, over 5 years ago.  By
requiring a slightly later OCaml version, we can drop more
compatibility code which was only used by older versions.

Consistent with qemu & libvirt, this drops support for compiling
upstream libguestfs on RHEL 8 (ocaml-4.07.0-4.el8.x86_64).

Qemu policy:
https://www.qemu.org/docs/master/about/build-platforms.html

Libvirt policy:
https://libvirt.org/platforms.html

Update the common submodule, pulling in:

  Richard W.M. Jones (4):
      qemuopts: Add ability to add raw, unquoted output to qemu scripts
      qemuopts: Fix missing break statement
      mlstdutils: Remove Option module
      Remove test for caml_alloc_initialized_string
2024-11-21 14:30:44 +00:00
Richard W.M. Jones
5ea1e899e0 daemon/ldm.c: Replace jansson with json-c 2024-10-22 11:02:38 +01:00
Richard W.M. Jones
e37768d889 build: Assume __attribute__((cleanup)) always works
All recent compilers support this (except MS compilers which we don't
care about).  Assume it is supported.  We test it in ./configure and
hard fail if it doesn't work.

We still define HAVE_ATTRIBUTE_CLEANUP but you can now assume it is
always defined and don't have to check it.
2024-10-18 21:55:21 +01:00
Richard W.M. Jones
e55eac12d4 docs: Update libguestfs email address in a couple more places
Reported-by: Julian Euler
2024-09-12 12:45:54 +01:00
Wang Guoquan
1d8924c343 libguestfs: Support openEuler
openEuler is simliar to CentOS, but the ID is not lower-case string,
as below:

    NAME="openEuler"
    VERSION="24.03 (LTS)"
    ID="openEuler"
    VERSION_ID="24.03"
    PRETTY_NAME="openEuler 24.03 (LTS)"
    ANSI_COLOR="0;31"

Signed-off-by: Wang Guoquan <wangguoquan03@foxmail.com>
2024-09-10 11:33:20 +01:00
Richard W.M. Jones
3d2061b83c daemon/inspect_fs.ml: Sort lists of distros
No change, just tidying up the lists.
2024-07-11 13:12:41 +01:00
grass-lu
a429ab3319 Kylin is centos derivative
Acked-by: Richard W.M. Jones <rjones@redhat.com>
2024-07-11 13:12:24 +01:00
Richard W.M. Jones
e616c8f286 inspection: Resolve PARTUUID= and PARTLABEL= in /etc/fstab
Fixes: https://issues.redhat.com/browse/RHEL-46596
2024-07-08 14:44:01 +01:00
Richard W.M. Jones
1816651f3c New APIs: findfs_partuuid and findfs_partlabel
These search for partitions by UUID or label (name).  They only work
for GPT.
2024-07-08 14:44:01 +01:00
Richard W.M. Jones
4c5c0782af daemon/findfs.ml: Fix whitespace 2024-07-08 14:37:06 +01:00
Richard W.M. Jones
24c1f7b03a daemon: Fix parsing in part_get_gpt_attributes
The actual output of sfdisk --part-attrs is bizarre and doesn't match
the documentation.  After looking at the source from util-linux, fix
the parsing to match what sfdisk produces.

Reported-by: Yongkui Guo
Fixes: commit c6c266a85d
Fixes: https://issues.redhat.com/browse/RHEL-35998
2024-06-28 09:42:20 +01:00
Jonatan Pålsson
465be22d9b daemon: cryptsetup_open: Add --cipher
This allows passing the --cipher argument to cryptsetup as an optional
parameter.
2024-06-20 07:42:55 +02:00
Richard W.M. Jones
c6c266a85d daemon: Reimplement partition GPT functions using sfdisk
sfdisk can now do everything with GPT that sgdisk was needed for
before.  In particular we are able to reimplement the following
functions using sfdisk:

- part_set_disk_guid   (replace with sfdisk --disk-id)
- part_get_disk_guid
- part_set_disk_guid_random
- part_set_gpt_attributes           (sfdisk --part-attrs)
- part_get_gpt_attributes
- part_set_gpt_guid                 (sfdisk --part-uuid)
- part_get_gpt_guid
- part_set_gpt_type                 (sfdisk --part-type)
- part_get_gpt_type

This allows us to drop the requirement for gdisk in many cases.

There is only one API remaining which requires gdisk, part_expand_gpt,
which we do not use in our tools.  In a prior commit I already moved
this solitary function to a new source file (daemon/gdisk.c).

Fixes: https://issues.redhat.com/browse/RHEL-35998
2024-05-10 16:25:13 +01:00
Richard W.M. Jones
a25f419802 daemon: Add an OCaml binding for get_random_uuid function 2024-05-10 16:07:20 +01:00
Richard W.M. Jones
d5c6e15180 daemon: Move gdisk function to a new file
After subsequent commits, this will be the only remaining use of
gdisk, so put it in its own file now.
2024-05-10 15:36:03 +01:00
Richard W.M. Jones
2811e42b43 daemon: part_get_gpt_type: Remove unhelpful MBR fallback behaviour
This was an accident of the parted implementation, and wasn't really
used anywhere.  Remove it.
2024-05-10 15:29:07 +01:00
Richard W.M. Jones
857615d6d2 daemon/parted: Assume sfdisk --part-type exists
This "new" parameter was added in 2014:

  commit 8eab3194ce1737a167812d5e84d83b0dfc253fac
  Author: Karel Zak <kzak@redhat.com>
  Date:   Mon Sep 15 12:37:52 2014 +0200

    sfdisk: add --parttype

    The patch also makes --{id,change-id,print-id} deprecated in favour
    of --parttype. The original --id is too generic option name and the
    --print-id and --change-id are unnecessary and inconsistent with
    another sfdisk options (e.g. we don't have --change-bootable)

Also remove an extraneous / incorrect comment about parted.  As
history has played out, sfdisk proves to be the better tool and parted
is a PITA.
2024-05-10 15:29:07 +01:00
Richard W.M. Jones
37d2379be2 daemon: Fix file architecture translation for LoongArch
Fixes: commit 729d6d55ea
2024-03-07 16:50:29 +00:00
Richard W.M. Jones
c8cefa6f0f daemon: parted: Print field we are extracting in error message 2024-03-07 14:17:45 +00:00
Bella Zhang
72f99817c7 Add detection support for Circle Linux 2024-02-06 12:22:00 +00:00
Alexey Shabalin
f878f72430 daemon: Add gost checksum command support
gostsum - generates or checks GOST R34.11-94 message digests
gost12sum - generates or checks GOST R34.11-2012 message digests

A reference implementation https://github.com/gost-engine/engine

Fixes: https://github.com/libguestfs/libguestfs/pull/132
Signed-off-by: Alexey Shabalin <shaba@altlinux.org>

[RWMJ: Added documentation, and added gostsum package to
the appliance]
2024-01-25 13:28:22 +00:00
Juergen Hoetzel
102e503648 daemon/btrfs: Use new syntax for balance command
Support for the obsolete short syntax 'btrfs balance /path' was
removed in btrfs-progs 6.6.
2023-12-14 16:53:50 +00:00