Commit Graph

1368 Commits

Author SHA1 Message Date
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
9b32056061 Fix miscellaneous spelling mistakes
$ git ls-files | xargs codespell
2025-04-29 19:05:07 +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
bcd6b3ec3a generator: Fix implementation of FUUID for OCaml functions
This was implemented wrongly.  In the XDR protocol, UUIDs are fixed
buffers of length 32.  We can just use memcpy to copy from the OCaml
string to the UUID, but we have to ensure the string length returned
by OCaml is correct (if not we just assert, it's an internal error).

(It didn't even compile before, so we know it was never used).
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
0ff73a42c7 generator: Implement struct FDevice type
This acts just like FString except that we do reverse device name
translation on it.  The only use is in the 'pvs-full' API where we
will use it (in a subsequent commit) to reverse translate the pv_name
field (a device name) before returning it from the daemon.

Compare this to the 'pvs' API which also returns a list of device
names, but using the generator's 'RStructList (RDevice,...)'  return
type, where RDevice is similarly reverse translated.

Note in the library-side bindings, because the name has already been
translated in the daemon, we just treat it exactly the same as
FString.  The vast majority of this patch is this mechanical change.
2025-04-16 12:27:07 +01:00
Cole Robinson
abdec091c4 common: update submodule
Cole Robinson (2):
          mltools: decouple and simplify osinfo device support checks
          mlcustomize: disable `--inject-virtio-win osinfo`

    Richard W.M. Jones (3):
          mltools: Fix de-oUnit-ized tests
          mltools: Unreference various objects
          Revert "mltools: Unreference various objects"

And update customize docs to match

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2025-04-09 16:12:44 -04: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
b5fbc7e617 tests: Replace $TEST_FUNCTIONS
Replace strange $TEST_FUNCTIONS variable/expansion thing with
something more like what we use in nbdkit, a simple tests/functions.sh
script that gets sourced into each test script.

Update the common submodule to get:

  commit 8137d47d0e654065391151eb275e3b64f230f6f5
  Author: Richard W.M. Jones <rjones@redhat.com>
  Date:   Thu Feb 13 11:13:55 2025 +0000

    mlcustomize, mltools: Replace $TEST_FUNCTIONS

    TEST_FUNCTIONS is being removed from libguestfs and guestfs-tools (it
    was removed from virt-v2v a while back).  Make the same adjustment in
    the common submodule.

(and some other commits which are not relevant to libguestfs)
2025-02-13 11:15:34 +00:00
Richard W.M. Jones
73186b154c generator: Remove common/mlv2v/uefi.ml{,i} files
Stop generating these files.  They are currently only used by virt-v2v
-o qemu mode, and there are better ways to locate the UEFI files
there.

Update the common submodule to bring in:

  Richard W.M. Jones (5):
      mlcustomize: Add heuristic support for Windows Server 2025
      mlcustomize/customize_run.ml: Move 'in' to new line
      mlstdutils/guestfs_config: Define host_os
      mlcustomize, mltools: Check guest OS is compatible before allowing --run
      Remove mlv2v/ subdirectory
2024-11-15 11:43:50 +00: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
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
fe1ce09242 generator: Don't include virt-customize --inject* options in virt-v2v
Virt-v2v already includes facilities for injecting QEMU guest agent
etc.  We shouldn't add the virt-customize options for this.

Update common submodule to include:

Richard W.M. Jones (2):
      mlcustomize: Move virt-customize modules to mlcustomize/
      mlcustomize: Update generated options for virt-v2v
2024-08-20 21:22:30 +01:00
Richard W.M. Jones
6bf22df62a generator/actions_core.ml: Fix version field for new APIs
Fixes: commit 1816651f3c
2024-07-08 16:27:13 +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
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
Richard W.M. Jones
882ef4d93a generator/daemon: Don't truncate 64 bit results from OCaml functions
Commit d5b6f1df5f ("daemon: Allow parts of the daemon and APIs to be
written in OCaml.", 2017) contained a bug where in any OCaml function
that returns int64_t, the result was truncated to an int.  This
particularly affected part_get_gpt_attributes as that returns large 64
bit numbers, but probably affects other functions too, undetected.

Fixes: commit d5b6f1df5f
2024-06-28 09:39:59 +01:00
Richard W.M. Jones
8b3e8a9056 Remove tftp drive support
This was only theoretically supported, via curl.  It's unlikely that
it really worked as it was never tested.

If needed it's better to use nbdkit-curl-plugin instead (this applies
to http and ftp as well).
2024-06-27 16:27:06 +01:00
Richard W.M. Jones
b1db7847ee Remove sheepdog support
This was discontinued in qemu quite a long time ago.
2024-06-27 16:22:52 +01:00
Richard W.M. Jones
c080449511 Remove gluster support
Development on gluster has stopped upstream, see:

https://marc.info/?l=fedora-devel-list&m=171934833215726&w=2
2024-06-27 16:13:09 +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
219845d5d0 generator/customize.ml: Add virt-customize --inject-blnsvr operation
Also updates the common submodule with the generated files.
2024-05-16 12:48:51 +01:00
Richard W.M. Jones
c7fe9fd917 tests: btrfs: Remove another test that used qgroup 0/*
This was failing with recent Linux:

  libguestfs: error: btrfs_subvolume_snapshot: /dir/test3: /dir/test6: ERROR: cannot snapshot '/sysroot/dir/test3': Invalid argument

I tried to change the test to use 1/1000 instead, but that fails with
a different error which I don't understand at all.

As we're not meant to be testing btrfs here, only that libguestfs can
translate between the guestfs API and btrfs commands and we know it
can do that, I simply deleted the sub-test entirely.
2024-05-13 14:35:36 +01: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
53eb96099a generator: Allow String(GUID) parameter in daemon OCaml bindings 2024-05-10 15:37:08 +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
7211aac047 tests: btrfs: Don't try to create qgroup 0/_
This used to work in kernel <= 6.7 but has been forbidden in later
kernels:
0c309d66da

Reported-by: David Runge
Thanks: Jan Alexander Steffens
Fixes: https://github.com/libguestfs/libguestfs/issues/136
2024-03-07 16:50:29 +00:00
liuxiang
729d6d55ea Add support for LoongArch.
Signed-off-by: liuxiang <liuxiang@loongson.cn>
2024-02-21 10:50:07 +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
Richard W.M. Jones
e9a728bb22 generator/customize.ml: Split --chown parameter on ':' character
The previous code split it on ',' which was completely wrong.
(It reveals the lack of testing however).

Fixes: commit c08032ebe2
Reported-by: Yongkui Guo
2024-01-19 13:24:37 +00:00
Richard W.M. Jones
61418535ad ocaml: Use Gc.finalise instead of a C finalizer
Since OCaml 5.1.1, changes to custom blocks caused C finalizers that
call caml_enter_blocking_section to stop working (if they ever did
before).  They are relatively inflexible compared to registering an
OCaml finalizer (Gc.finalise) to call Guestfs.close, so use that
instead.

Suggested-by: Guillaume Munch-Maccagnoni
See: https://github.com/ocaml/ocaml/issues/12820
See: db48794fa8
2023-12-13 22:55:03 +00:00
Richard W.M. Jones
b5f7b0ec18 generator: Add new virt-customize --tar-in operation
Using 'virt-customize --tar-in some.tar:/dir -a disk.img' will unpack
'some.tar' into '/dir' in the guest.  Note that this will not work for
compressed tar files as written since the underlying guestfs_tar_in
function requires the compression type to be set explicitly and
defaults to no compression (it does not auto-detect or default to
compression).
2023-10-26 21:16:41 +01:00
Richard W.M. Jones
297db5cccc generator: Sort virt-customize options into alphabetical order 2023-10-26 21:07:57 +01:00
Richard W.M. Jones
c08032ebe2 generator: customize: Add new StringTriplet for use by --chown
The just added --chown option previously used StringPair, splitting
the argument as ‘UID.GID:FILENAME’.  However this will not work if we
ever extend this with the ability to use user or group names, since
they may contain dot (but not colon).  Add a new StringTriplet type
and split the argument string three ways.  The new option becomes:

  virt-customize ... --chown UID:GID:FILENAME

Include the following commit from the common submodule:

  commit e70d89a58dae068be2e19c7c21558707261af96a
  Author: Richard W.M. Jones <rjones@redhat.com>
  Date:   Sat Jul 15 16:42:06 2023 +0100

    customize: Update generated files for --chown with StringTriplet

Updates: commit d8e48bff21
2023-07-15 16:45:57 +01:00
Laszlo Ersek
21ccddecf7 docs: clarify sockdir's separation
There's another reason for separating sockdir from tmpdir, beyond "shorter
pathnames needed": permissions. For example, passt drops privileges such
that it cannot access "/tmp", and that restricts both the unix domain
socket and the PID file of passt.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2184967
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
Message-Id: <20230714132213.96616-5-lersek@redhat.com>
2023-07-14 17:57:15 +02:00
Richard W.M. Jones
d8e48bff21 generator: Add --chown option for virt-customize
Also this updates the common submodule to include the changes.

Fixes: https://github.com/rwmjones/guestfs-tools/issues/12
Acked-by: Laszlo Ersek <lersek@redhat.com>
2023-06-29 17:14:43 +01:00
Richard W.M. Jones
7e1d7c1330 ocaml: Replace old enter/leave_blocking_section calls
Since OCaml 4 the old and confusing caml_enter_blocking_section and
caml_leave_blocking_section calls have been replaced with
caml_release_runtime_system and caml_acquire_runtime_system (in that
order).  Use the new names.
2023-06-27 11:34:21 +01:00
Richard W.M. Jones
3cb094083e Replace Pervasives.* with Stdlib.*
Since OCaml 4.07 (released 2018-07-10) the always-loaded standard
library module has been called Stdlib.  The old Pervasives module was
finally removed in OCaml 5.

$ perl -pi.bak -e 's/Pervasives\./Stdlib./g' -- `git ls-files`

OCaml >= 4.07 is now required.

Also update the common submodule with:

  commit d61cd820b49e403848d15c5deaccbf8dd7045370
  Author: Jürgen Hötzel
  Date:   Sat May 20 18:16:40 2023 +0200

    Add support for OCaml 5.0
2023-05-22 16:42:31 +01:00
Zixun LI
692802bf96 daemon/tar: support more compression methods.
Add support for lzma and zstd compression methods.

Signed-off-by: Zixun LI <admin@hifiphile.com>
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
2023-05-02 11:15:02 +01:00
Richard W.M. Jones
f68752462e build: Remove RELEASES file
The presence of this file complicates ./configure and you also have to
remember to update it on each release.  Replace it with a simple
RELEASE_DATE set in ./configure when the version is updated.

I also had to make a minor change to the generator which was using
this file both to check it was run from the source directory and to
get an exclusive lock.  We now use podwrapper.pl.in for this.
2023-02-16 11:58:30 +00:00
Richard W.M. Jones
e2c7bddf10 Update copyright dates for 2023
Run this command across the source:

  perl -pi.bak -e 's/(20[012][0-9])-20[12][012]/$1-2023/g' `git ls-files`

and remove changes to po{,-docs}/*.po{,t} (these will be regenerated
later when we run 'make dist').
2023-02-07 10:50:48 +00:00
Richard W.M. Jones
e0d23c861c generator: customize: Add --inject-qemu-ga and --inject-virtio-win
Add the new flags / operations for virt-customize.
2023-01-17 11:59:00 +00:00
Richard W.M. Jones
f3dd67affe New API: inspect_get_build_id
Add an API to return the build ID of the guest.  This to allow a
future change to be able to distinguish between Windows 10 and Windows 11
which can only be done using the build ID.

For Windows we can read the CurrentBuildNumber key from the registry.
For Linux there happens to be a BUILD_ID field in /etc/os-release.
I've never seen a Linux distro that actually uses this.

Reviewed-by: Laszlo Ersek <lersek@redhat.com>
2022-12-02 10:16:57 +00:00
Richard W.M. Jones
23986d3c4f file: Use -S option with -z
The file(1) manual suggests using -S (disable seccomp) with -z since
the set of system calls provided by the seccomp policy does not allow
the subprocess to run.  This is obvious when you use file -z on a
compressed file on a Linux distro that enables file's seccomp policy
(Arch does this, Fedora does not):

  $ file -zbsL lib-i586.so.zst
  Bad system call

I also fixed some incorrect text in the manual.

Thanks: Toolybird for pointing to this fix
Reported-by: David Runge
Fixes: https://github.com/libguestfs/libguestfs/issues/100
2022-11-28 10:21:00 +00:00
Richard W.M. Jones
e657e45b43 tests: Increase size of disk in xfs_growfs_0 test
I cannot reproduce the originally reported error:

libguestfs: error: mkfs: xfs: /dev/VG/LV: Filesystem must be larger than 300MB.

Thanks: David Runge
Related: https://github.com/libguestfs/libguestfs/issues/100
2022-11-22 16:32:08 +00:00
Richard W.M. Jones
5c63ec2a53 gobject: Remove bogus NULL test for UUIDs
Many warnings such as:

src/session.c: In function 'guestfs_session_internal_test_rstruct':
src/session.c:14755:7: warning: the comparison will always evaluate as 'true' for the address of 'pv_uuid' will never be NULL [-Waddress]
14755 |   if (ret->pv_uuid) memcpy (s->pv_uuid, ret->pv_uuid, sizeof (s->pv_uuid));
      |       ^~~
In file included from src/session.c:40:
../include/guestfs.h:551:8: note: 'pv_uuid' declared here
  551 |   char pv_uuid[32]; /* this is NOT nul-terminated, be careful when printing */
      |        ^~~~~~~
2022-10-24 11:27:53 +01:00