Commit Graph

12244 Commits

Author SHA1 Message Date
Cole Robinson
acb785fede lib/launch-libvirt.c: check if g->hv symlink matches libvirt default
On fedora, ./configure will set QEMU=qemu-kvm, but libvirt
domcaps will default to qemu-system-x86_64. The former is a symlink
to the latter, but libguestfs doesn't know that, so determines
the user requested a non-default hv override and changes some
settings as a result (like disabling svirt).

Check for the symlink case and consider it a non-custom config
if realpath matches libvirt's default

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2025-10-23 11:22:55 +01:00
Cole Robinson
55ea21d4b3 lib/launch-libvirt.c: debug is_custom_hv result
Add debugging about is_custom_hv result.
cache the initial call so we are only hitting the debug() once.

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2025-10-23 11:22:55 +01:00
Cole Robinson
81e9f81a6e lib/launch-libvirt.c: simplify is_custom_hv
g->hv is always set in lib/handle.c

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2025-10-23 11:22:55 +01:00
Cole Robinson
e051891347 lib/launch-libvirt.c: make model='selinux' disabling explicit
Using `<seclabel type='none'/>` implies `model=selinux`, so lets fill it
in to be explicit.

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2025-10-23 11:22:55 +01:00
Cole Robinson
949679993e lib/launch-libvirt.c: Simplify root socket permissions
libvirt has DAC relabeled sockets for us for a decade, so we don't
need to do chowning here anymore

The chmod calls are still required, otherwise our created sockets
may be too permissive.

Update the comment to try and preserve the still relevant info,
though now it's a bit awkwardly placed.

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2025-10-23 11:22:55 +01:00
Cole Robinson
62309ab40c lib/launch-libvirt.c: don't write <seclabel><imagelabel>
<imagelabel> is an output-only XML element. setting it when
defining XML does nothing

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2025-10-23 11:22:55 +01:00
Richard W.M. Jones
f6a63d08d4 Version 1.57.5. v1.57.5 2025-10-17 10:43:32 +01:00
Richard W.M. Jones
7398fdc77c lib/launch-direct.c: Remove workaround that disabled 5-level page tables
https://bugzilla.redhat.com/2082806 is a private kernel bug (sigh) for
RHEL 8, where some missing backports caused 5-level page tables to
fail when qemu emulated them.  This was fixed back in 2023, so let's
remove this workaround now.
2025-10-17 09:57:53 +01:00
Richard W.M. Jones
ac1cb3cd7c lib/qemu.c: Add -cpu max when testing for KVM via QMP
On RHEL 10.2 aarch64 (only) we see:

  $ echo '{ "execute": "qmp_capabilities" }' '{ "execute": "query-kvm" }' '{ "execute": "quit" }'  | QEMU_AUDIO_DRV=none "/usr/libexec/qemu-kvm" -display none -machine "virt,accel=kvm:hvf:tcg" -qmp stdio
  qemu-kvm: invalid accelerator hvf
  qemu-kvm: falling back to KVM
  {"QMP": {"version": {"qemu": {"micro": 0, "minor": 1, "major": 9}, "package": "qemu-kvm-9.1.0-15.el10_0.4"}, "capabilities": ["oob"]}}
  qemu-kvm: warning: CPU model cortex-a57-arm-cpu is deprecated -- use 'host' / 'max'
  qemu-kvm: kvm_init_vcpu: kvm_arch_init_vcpu failed (0): Invalid argument

Unfortunately we cannot use guestfs_int_get_cpu_model (as that
requires us to already know if KVM is supported), so we just have to
guess that -cpu max will work, at least enough for QMP to work.

Fixes: https://issues.redhat.com/browse/RHEL-121076
Reported-by: Xiang Hua Chen
2025-10-17 09:57:14 +01:00
Cole Robinson
d42227e083 generator: deprecate and remove --sm-* options
virt-customize and friends have the following options:

--sm-register
--sm-unregister
--sm-attach
--sm-remove
--sm-credentials

These run `subscription-manager` commands inside the VM, which
is often necessary to get working package install for RHEL VMs.

These were added in 2015ish. Conceptually I understand why we
might want native support in the tools: virt-customize and
virt-builder have package management knowledge, and
for some distros subscription-manager is necessary.

But this support doesn't add much convenience over calling the commands
directly with `--run-command`. And on RHEL10, subscription-manager was
reworked and complete drops the backing commands for `--sm-attach` and
`--sm-remove`.

We _could_ make this code smarter, try to detect that situation,
and not error when subscription-manager is new enough. But if
subscription-manager itself doesn't care about maintaining that kind
of compat, I'm not sure why we should care either.

Instead we decided to just rip it all out and document the
alternatives.

common module is updated to sync related changes:

  Cole Robinson (1):
        mlcustomize: deprecate and remove --sm-* options

  Richard W.M. Jones (3):
        mlstdutils: Export List.find_opt
        daemon, generator: Use power of 2 for initial size of Hashtbl.create
        mlcustomize/inject_virtio_win.ml: Use viostor.inf instead of guestor

https://issues.redhat.com/browse/RHEL-113397
https://issues.redhat.com/browse/RHEL-113398

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2025-10-14 18:47:30 +01:00
Cole Robinson
630628af78 tests: increase guestunmount retries for test-parallel-mount-local
test-parallel-mount-local reliably fails when my machines are
under load (like running the test suite in parallel). The
issue is /usr/libexec/gvfs-udisks2-volume-monitor fiddling with
the fuse mounts, preventing them from being unmounted.

./fuse/guestunmount defaults to 5 unmount retries with increasing
time backoff, but apparently that isn't enough. Bumping it to
use 10 retries makes things more reliable for me.

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2025-10-14 18:26:45 +01:00
Richard W.M. Jones
e75018a534 fuse/guestunmount.c: Include <signal.h>
On macOS this fails with:

  guestunmount.c:170:5: error: call to undeclared function 'sigaction'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    170 |     sigaction (SIGINT, &sa, NULL);
        |     ^
  1 error generated.

Reported-by: Mohamed Akram
Related: https://github.com/libguestfs/libguestfs/pull/188
2025-10-07 14:06:46 +01:00
Richard W.M. Jones
63a2ed92b4 fuse: Ignore extra options parameter on macOS
macOS macfuse has an extra options parameter for the setxattr and
getxattr FUSE callbacks.  The possible options are documented below.
However the underlying libguestfs APIs don't allow us to act on these
flags, so we ignore them for now.

(from https://manp.gs/mac/2/setxattr)

  XATTR_NOFOLLOW
    do not follow symbolic links. setxattr() normally sets attributes
    on the target of path if it is a symbolic link. With this option,
    setxattr() will act on the link itself.
  XATTR_NOFOLLOW_ANY
    do not follow any symbolic links encountered during pathname
    resolution. An error is returned if a symlink is encountered
    before the last component of path.
  XATTR_CREATE
    fail if the named attribute already exists.
  XATTR_REPLACE
    fail if the named attribute does not exist. Failure to specify
    XATTR_REPLACE or XATTR_CREATE allows creation and replacement.

Reported-by: Mohamed Akram
Fixes: https://github.com/libguestfs/libguestfs/issues/180
Related: https://github.com/macfuse/macfuse/issues/1065
2025-10-07 14:06:46 +01:00
Richard W.M. Jones
84e15e784f Version 1.57.4. v1.57.4 2025-09-30 10:06:44 +01:00
Richard W.M. Jones
669eda1e24 lib/launch-direct.c: Simplify test for KVM, remove qemu caching
Previously we tested if KVM was available, and cached that for the
qemu binary.  I think this was actually wrong.  For example, if the
machine restarts, then the cache is still around, but KVM might be
enabled or disabled because of a new host kernel.

In any case, let's radically simplify this.

Test for KVM on each run.  Consequently we can remove all the qemu
test caching stuff as it is no longer used anywhere.

I also tightened up the code that runs the QMP query-kvm command, so
now any unexpected output will cause a runtime failure.  This command
ought to work, and if it breaks we ought to know about it and fix it.
2025-09-29 16:49:03 +01:00
Richard W.M. Jones
cfbdf9bcc7 lib/qemu.c: Remove guestfs_int_qemu_supports_device
Previously we ran 'qemu -device ?' to list devices, using the output
to test if qemu supported particular devices.  This was extensively
used in the past, but after recent commits there are no further users
of this code, so we can remove it all completely.
2025-09-29 16:49:03 +01:00
Richard W.M. Jones
4872c0cf09 lib/launch-direct.c: Assume virtio-rng
It's always a good idea to provide proper entropy to the libguestfs
appliance (eg. for any cryptographic operations).  We already assume
virtio, so we can assume virtio-rng is present.
2025-09-29 16:49:03 +01:00
Richard W.M. Jones
d8b08eac38 lib/launch-libvirt.c: Don't store libvirt_version in handle
We no longer use the libvirt version anywhere, except when reporting
the version.  Remove this from the handle.

Simplify the remaining code.  In particular:

* don't bother parsing the libvirt version, just print what
  virGetVersion gives us

* guestfs_int_version_from_libvirt is dead code, so it can be removed
2025-09-29 16:49:03 +01:00
Richard W.M. Jones
48bad58024 lib/launch-libvirt.c: Assume libvirt >= 9.0.0 and passt support
Libvirt 9.0.0 was released in January 2023, and it seems safe to
assume that if you're enabling the non-default backend, you can at
least use a new version of libvirt.

If you're using new libvirt, might as well also assume passt is
available.
2025-09-29 16:49:03 +01:00
Richard W.M. Jones
d730fc8b7c lib/launch-libvirt.c: Remove a workaround for libvirt < 3.8.0
This version of libvirt was released in 2017.
2025-09-29 16:49:03 +01:00
Richard W.M. Jones
a68f3eee15 lib/launch-libvirt.c: Add virtio-rng unconditionally
This tested for an ancient version of libvirt, but we can assume we
are always using something more recent.
2025-09-29 16:49:03 +01:00
Richard W.M. Jones
1a45db7465 lib/qemu.c: Remove qemu -help invocation
Previously we parsed qemu -help output to get the version of qemu and
to test for other features.  After prior commits, this is no longer
done, so we can remove the qemu -help invocation and associated code
completely.
2025-09-29 16:49:03 +01:00
Richard W.M. Jones
593a382840 lib: Remove guestfs_int_qemu_version
This function is now only used in one place, to print the version of
qemu in direct mode, when debugging is enabled.

Remove this function and replace with a direct command invocation
('qemu --version').  We only need to run this command when debugging
is enabled, and we copy all of the output to the debug channel.

I have made the assumption here that qemu -version does not try to
create a display device.  (The previous invocation of qemu -help
actually ran 'qemu -display none -help' indicating that this was not
always the case.)

This is actually an improvement on before, since now we get to see the
full output of 'qemu --version'.  The new output looks like:

  libguestfs: begin testing qemu features
  libguestfs: command: run: /usr/bin/qemu-kvm
  libguestfs: command: run: \ -version
  libguestfs: qemu: QEMU emulator version 10.1.0 (qemu-10.1.0-8.fc44)
  libguestfs: qemu: Copyright (c) 2003-2025 Fabrice Bellard and the QEMU Project developers
2025-09-29 16:49:03 +01:00
Richard W.M. Jones
788a1e4993 lib/launch-direct.c: Don't store qemu_version in handle
As we no longer use this field, no longer store it in the handle
struct.
2025-09-29 16:49:03 +01:00
Richard W.M. Jones
99921de6e0 lib/launch-direct.c: Move baseline to qemu 7.2.0 and assume passt support
We already effectively assume that qemu is much newer than the 1.3.0
baseline previously documented.  As one example, commit 47857751a7
("lib: direct: Remove test for qemu mandatory locking") assumes that
qemu >= 2.10.  Because passt support is desirable in general, let's
assume that qemu is at least version 7.2.0, and document it.

qemu 7.2.0 was released in December 2022, nearly 3 years ago, and RHEL
9 is currently on qemu 9.1.0.

This keeps the SLIRP fallback path in case passt isn't installed, but
we should remove that fallback in future too.
2025-09-29 16:49:03 +01:00
Richard W.M. Jones
dce5ce605d lib/launch-direct.c: Set lost_tick_policy=discard unconditionally
We already assume qemu version is must greater than 1.3.0 so we do not
need this qemu version test.
2025-09-29 16:49:03 +01:00
Richard W.M. Jones
ec47331b12 lib/launch-libvirt.c: Don't store qemu_version in handle
After previous commits, we no longer use the qemu version elsewhere
(after simply reporting it).  Remove all the code for storing the qemu
version.
2025-09-29 16:49:03 +01:00
Richard W.M. Jones
02d82a3c3a lib: Remove qemu version when testing for discard feature
We can assume much more recent qemu, so we don't need to have special
cases for qemu 1.5/1.6.
2025-09-29 16:49:03 +01:00
Richard W.M. Jones
5df7da7e81 lib/qemu.c: Remove int_qemu_supports function
This function, which grepped the qemu -help output to see if a command
line option was supported, is no longer used and can be removed.
2025-09-29 16:49:03 +01:00
Richard W.M. Jones
fc243a36bd lib/launch-direct.c: Remove unnecessary tests for ancient qemu features
We can safely assume that qemu supports -nodefaults and
-no-user-config, since these have been supported since forever.

-no-hpet was deprecated in qemu 8.0 and the option removed in early
2024, replaced with -machine hpet=off.  HPET defaults to 'on' in
upstream qemu, and to 'off' in downstream RHEL rebuilds.

Since (for libguestfs) we can assume an up to date Linux kernel is
running inside the guest, and that the kernel will do the right thing
with regards to timers, we don't need to mess with qemu defaults.  In
practice, Linux chooses kvm-clock.

Thanks: Thomas Huth, Daniel Berrange
2025-09-29 16:49:03 +01:00
Richard W.M. Jones
1f1ac69b11 lib/qemu.c: Remove qmp_schema
We used to read the QMP schema so we could see if the binary supported
qemu mandatory locking.  However after commit 47857751a7 ("lib:
direct: Remove test for qemu mandatory locking") this is dead code, so
remove it.

Updates: commit 47857751a7
2025-09-29 16:49:03 +01:00
Richard W.M. Jones
bc431d9b64 tests/regressions/rhbz790721.c: Remove this test
This was a test for a 13 year old problem to do with problems
launching libguestfs appliances in parallel.  That problem does not
affect current code.

Testing build/launch of libguestfs appliances is a valuable thing to
test.  However we start libguestfs in parallel in both the current
test suite and in higher level tools, and this test was dubious (and
breaks with recent changes).  Therefore remove the test.
2025-09-29 16:49:03 +01:00
Richard W.M. Jones
495f71affc daemon, generator: Use power of 2 for initial size of Hashtbl.create
Before 2011 it was recommended to use a prime number for the initial
size.  In 2011 the OCaml hash table was reimplemented using a hash
function based on Murmur 3.  Hashtbl.create now adjusts the initial
size to the next power of 2 (minimum 16).  So replace obsolete
'Hashtbl.create 13' with 'Hashtbl.create 16'.
2025-09-12 08:37:58 +01:00
Richard W.M. Jones
30ccb9a3e6 daemon/selinux.ml: Use setfiles -A option to reduce memory usage
In filesystems that have many millions of files, the default behaviour
of setfiles is to build a huge hash table containing every filename.
This uses up lots of memory which prevents relabelling from happening
in the reduced memory environment of the libguestfs appliance.

I added the setfiles -A option to change this default behaviour.  If
setfiles has the option then use it.

Fixes: https://issues.redhat.com/browse/RHEL-114292
Related: https://issues.redhat.com/browse/RHEL-111165
Related: https://issues.redhat.com/browse/RHEL-111505
2025-09-11 21:03:37 +01:00
Richard W.M. Jones
5f47af7f3e Version 1.57.3. v1.57.3 2025-09-09 19:18:04 +01:00
Richard W.M. Jones
a5b7de4a71 github: Add workflows file to EXTRA_DIST
Fixes: commit e218dd73cc
2025-09-09 19:11:31 +01:00
Richard W.M. Jones
365e7d79f7 github: Don't test on Ubuntu 24.04 twice
It turns out that ubuntu-latest is the same as 24.04, so we're just
testing on the same version twice.  Remove the duplication.

Thanks: Stephen Gallagher
Fixes: commit e218dd73cc
2025-09-09 17:34:15 +01:00
Cole Robinson
a2e7dfc73b New API: ntfs_chmod
Add an API to do the equivalent of `chmod [-r] MODE PATH` for
NTFS filesystems.

Files created on a linux ntfs-3g mount can not change permissions
directly. New files and directories are created with rough windows
equivalent of `chmod 777`. These wide open permissions can generate
security warnings on windows after virt-v2v installs bits into
`Program Files\Guestfs`.

Behind the scenes we use `ntfssecaudit(8)` from `ntfsprogs`
which is already part of the appliance. We only expose the chmod-style
feature; the rest of `ntfssecaudit` is concerned reporting and
managing fine grained windows security info which is way more than
we need.

Also note, `ntfssecaudit` needs to run on an unmounted partition
so using this is more complicated than a traditional `chmod` call.

Related: https://issues.redhat.com/browse/RHEL-104352

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2025-09-09 16:29:13 +01:00
Richard W.M. Jones
e218dd73cc github: Add basic github CI tests
This builds libguestfs and runs the in-tree tests, ie. the basic
'./configure && make && make check'.

We're using the "free for public repositories" plan.  We run the tests
directly on an Ubuntu VM, versions 24.04 & latest.  Also on Fedora 42,
43 in a container (running on the Ubuntu VM).

The tests are run on pushes to the master branch, and on pull
requests to the master branch.

GObject is not built, since the tests fail and anyway there are some
deep problems with the GObject bindings and they probably will be
removed.

Thanks: Stephen Gallagher, Cole Robinson
2025-09-09 13:40:49 +01:00
Richard W.M. Jones
e7b36e0eba generator: Use quoted string literals for regexps
The output of the generator is identical after this change.
2025-09-02 09:11:38 +01:00
Richard W.M. Jones
02b64d5cec generator: Use quoted string literals in many places
This change was done almost entirely automatically using the script
below.  This uses the OCaml lexer to read the source files and extract
the strings and locations.  Strings which are "candidates" (in this
case, longer than 3 lines) are replaced in the output with quoted
string literals.

Since the OCaml lexer is used, it already substitutes all escape
sequences correctly.  I diffed the output of the generator and it is
identical after this change, except for UUIDs, which change because of
how Utils.stable_uuid is implemented.

Thanks: Nicolas Ojeda Bar

$ ocamlfind opt -package unix,compiler-libs.common find_strings.ml \
                -o find_strings.opt -linkpkg
$ for f in $( git ls-files -- \*.ml ) ; do ./find_strings.opt $f ; done

open Printf

let read_whole_file path =
  let buf = Buffer.create 16384 in
  let chan = open_in path in
  let maxlen = 16384 in
  let b = Bytes.create maxlen in
  let rec loop () =
    let r = input chan b 0 maxlen in
    if r > 0 then (
      Buffer.add_substring buf (Bytes.to_string b) 0 r;
      loop ()
    )
  in
  loop ();
  close_in chan;
  Buffer.contents buf

let count_chars c str =
  let count = ref 0 in
  for i = 0 to String.length str - 1 do
    if c = String.unsafe_get str i then incr count
  done;
  !count

let subs = ref []

let consider_string str loc =
  let nr_lines = count_chars '\n' str in
  if nr_lines > 3 then
    subs := (str, loc) :: !subs

let () =
  Lexer.init ();
  let filename = Sys.argv.(1) in
  let content = read_whole_file filename in
  let lexbuf = Lexing.from_string content in
  let rec loop () =
    let token = Lexer.token lexbuf in
    (match token with
     | Parser.EOF -> ();
     | STRING (s, loc, sopt) ->
        consider_string s loc; (* sopt? *)
        loop ();
     | token ->
        loop ();
    )
  in
  loop ();

  (* The list of subs is already reversed, which is convenient
   * because we must the file substitutions in reverse order.
   *)
  let subs = !subs in
  let new_content = ref content in
  List.iter (
    fun (str, loc) ->
      let { Location.loc_start = { pos_cnum = p1 };
            loc_end = { pos_cnum = p2 } } = loc in
      let len = String.length !new_content in
      let before = String.sub !new_content 0 (p1-1) in
      let after = String.sub !new_content (p2+1) (len - p2 - 1) in
      new_content := before ^ "{|" ^ str ^ "|}" ^ after
  ) subs;

  let new_content = !new_content in

  if content <> new_content then (
    (* Update the file in place. *)
    let new_filename = filename ^ ".new"
    and backup_filename = filename ^ ".bak" in
    let chan = open_out new_filename in
    fprintf chan "%s" new_content;
    close_out chan;
    Unix.rename filename backup_filename;
    Unix.rename new_filename filename
  )
2025-09-01 17:08:52 +01:00
Richard W.M. Jones
b4a98fe13a generator/actions_core.ml: Fix typo in description of read_file 2025-09-01 16:54:43 +01:00
Richard W.M. Jones
32b911a061 daemon/inspect_fs_windows.ml: Use {|..|} string literal 2025-09-01 13:59:56 +01:00
Richard W.M. Jones
f857f39a2d daemon/selinux.ml: Simplify setfiles option testing
Updates: commit 1c0b56158a
2025-08-30 14:05:34 +01:00
Richard W.M. Jones
91ee98523e daemon/selinux.ml: Fix typo in comment
Fixes: commit d0d8e67384
2025-08-27 10:43:00 +01:00
Richard W.M. Jones
e6f93dfb9f Update common submodule
Pulls in the commits listed below.  This has no effect as all changes
are confined to the common/mlcustomize subdirectory which we do not
use or ship.

  Richard W.M. Jones (4):
      mlcustomize/SELinux_relabel.ml: Add comment
      mlcustomize/SELinux_relabel.ml: Use new guestfs_setfiles API
      mlcustomize/SELinux_relabel.ml: Relabel every mountpoint
      mlcustomize/firstboot.ml: Use quoted string literals for firstboot

  Vadim Rozenfeld (1):
      Modify the firstboot script to check the scripts execution return status
2025-08-20 10:36:48 +01:00
Richard W.M. Jones
6b19b97aa6 website: Remove very old stable branches from the index page
There's no point linking to anything other than the current stable
branch.
2025-08-15 21:37:30 +01:00
Richard W.M. Jones
82764f1b3a Version 1.57.2. v1.57.2 2025-08-15 10:56:08 +01:00
Richard W.M. Jones
1c00248ac1 daemon/inspect_fs_windows.ml: Ignore blank disks in drive mapping
If HKLM\System\MountedDevices references a blank disk, then when we
try to search for the actual backing device we will get an error from
parted:

  parted: /dev/sdb: parted exited with status 1: Error: /dev/sdb: unrecognised disk label: Invalid argument

Just ignore these errors instead of failing inspection.

Fixes: https://issues.redhat.com/browse/RHEL-108803
Reported-by: Ameen Barakat
Thanks: Ming Xie
2025-08-14 15:45:59 +01:00
Richard W.M. Jones
5c7e15cfae daemon/inspect_fs_windows.ml: Add debugging when we start registry analysis
Add some debugging when we begin the process of analyzing the Windows
registry of a guest.
2025-08-14 15:45:59 +01:00