Commit Graph

539 Commits

Author SHA1 Message Date
Richard W.M. Jones
75abec1f70 include: Move lib/guestfs.h to include/guestfs.h
This brings libguestfs into line with other projects which have a
separate include/ directory for the public header.

It's also the case that <guestfs.h> has never particularly belonged in
the lib/ subdirectory.  Some tools add -Ilib/ but they only need
<guestfs.h> and not any other headers from that directory, and
separating out the public header allows us to clean those up.  This is
certainly the case for examples, and some language bindings and some
tests.

In future I'm hopeful we can use this as the basis to tease out other
dependencies, as a prelude to separating them out from the repo.
2020-09-21 18:38:28 +01:00
Richard W.M. Jones
0e17236d7d Update copyright dates to 2020. 2020-03-06 19:32:32 +00:00
Richard W.M. Jones
eb17229c3e tests/disks: Don't segfault if guestfs_list_devices returns an error.
Although it's highly unlikely in normal use, while testing device name
translation patches it did happen and caused the test to segfault
instead of exiting with an error.
2020-03-05 12:08:35 +00:00
Nikolay Ivanets
94843f155a lib: add support for disks with 4096 bytes sector size
Nowadays there are hard drives and operating systems which support
"4K native" sector size.  In this mode physical and logical block size
exposed to the operating system is equal to 4096 bytes.

GPT partition table (as a known example) being created in this mode will
place GPT header at LBA1 which is 4096 bytes.  libguetfs is unable to
recognize partition table on such physical block devices or disk images.
The reason is that libguestfs appliance will look for a GPT header at
LBA1 which is seen at 512 byte offset.

In order to fix the issue we need a way to provide correct logical block
size for attached disks.  Fortunately QEMU and libvirt already provides
a way to specify physical/logical block size per disk basis.

After discussion in a mailing list we agreed that physical block size is
rarely used and is not so important.  Thus both physical and logical
block size will be set to the same value.

In this patch one more optional parameter 'blocksize' is added
to add_drive_opts API method.  Valid values are 512 and 4096.

add_drive_scratch has the same optional parameter for a consistency and
testing purpose.

add-domain and add_libvirt_dom will pass logical_block_size value from
libvirt XML to add_drive_opts method.
2020-02-11 15:20:09 +00:00
Richard W.M. Jones
815eab8a66 tests: Use explicit backing format for all backing disks.
Libvirt 6.0 now requires that every disk in the backing chain has an
explicit backing format.  For example this will be rejected by
libvirt:

  qemu-img create -f qcow2 -b backing-disk disk.qcow2

with the error:

  Original error from libvirt: Requested operation is not valid:
  format of backing image 'backing-disk' of image 'disk.qcow2' was not
  specified in the image metadata (See
  https://libvirt.org/kbase/backing_chains.html for troubleshooting)
  [code=55 int1=-1]

Instead you have to use the -F option to specify the format, eg:

  qemu-img create -f qcow2 -b backing-disk -F raw disk.qcow2
2020-02-06 16:06:19 +00:00
Pino Toscano
54a9d04f72 build: add an empty config.sh
This helper script will contain variables with results of configure
checks, so other scripts can source it.

Source it automatically in test-functions.sh, so every test can already
make use of it.
2019-12-16 10:48:14 +01:00
Pino Toscano
323909d92e build: stop shipping files generated by configure
They will be generated by configure.
2019-12-12 18:01:32 +01:00
Pino Toscano
355bed63f4 tests: test --key for a real guest (with inspection)
Test both the decryption by device name, and UUID.
2019-11-29 13:03:20 +01:00
Pino Toscano
a2b37a495c tests: switch away from xgetcwd
xgetcwd is used only in a test, so there is no need to pull a gnulib
module just for it.

Switch to use getcwd directly with a fixed buffer: the tests would have
failed with paths longer than 992 characters, as the libvirt_uri would
have been truncated.  Since there were no reports of issues, we can
assume that the current working directory will fit in 1024 characters;
adapt the size of libvirt_uri accordingly.
2019-11-28 13:09:21 +01:00
Richard W.M. Jones
38ff3354ea tests: luks: Test the --key options.
Previously untested, and as always happens they were quite buggy.
2019-11-28 10:13:57 +00:00
Richard W.M. Jones
85c99edec1 v2v: Remove virt-v2v.
It has moved to a new repository:
https://github.com/libguestfs/virt-v2v
2019-11-13 12:49:55 +00:00
Pino Toscano
d8d8c856a1 lib: introduce GUESTFS_NO_DEPRECATED
Add a simple way to do not even provide prototypes of deprecated
functions in the C library: this way, users (like our tools) can build
against the library making sure to not use any deprecated function, not
even when compiler deprecation warnings are disabled.

Add it to the majority of our tools/internal libraries, and make sure
that it is not defined when building the API bridges of our bindings.
2019-04-23 18:08:19 +02:00
Pino Toscano
9d1fc91cca build: stop using GUESTFS_WARN_DEPRECATED
This is no more used now, as compiler deprecation warnings are triggered
by default.
2019-04-23 18:08:19 +02:00
Pino Toscano
84d0f5aa9f lib: enable deprecation warnings by default
Right now, deprecated functions of the library do not trigger any
compiler deprecation warning by default; they do that only if
GUESTFS_WARN_DEPRECATED=1 is defined.  However, this is not something
that seems to be done often -- at least none of the projects using the
libguestfs C API does that.

Hence, do a small behaviour change to change this on the other way
round: now deprecated functions trigger compiler deprecation warnings by
default, using GUESTFS_NO_WARN_DEPRECATED to disable this (and revert
to the previous behaviour).  Even though deprecated functions will not
be removed, we really want users to migrate away from them, as they were
deprecated for good reasons.

Define GUESTFS_NO_WARN_DEPRECATED where needed:
- in all the bindings, as they bind all the functions including the
  deprecated ones
- in the guestfish actions, as it exposes almost all the APIs
- in the C API test, as it runs the automated tests of all the APIs that
  have them
- for two tests that explicitly test deprecated functions
2019-04-23 18:08:19 +02:00
Pino Toscano
7a54596aaf tests: switch last-errno away from deprecated APIs
This test only calls stat to check the failure on missing file, so
switch to statns to get the same behaviour with a non-deprecated API.
2019-04-23 18:06:31 +02:00
Denis Plotnikov
4cfc071a84 daemon: drop error message check in do_part_expand_gpt
part-expand-gpt takes extreme cautions and doesn't proceed to writing
to the disk if the preliminary dry run of sgdisk has generated any
warnings on stdout.

This blocks the use of part-expand-gpt on disk shrink (with disk
resize being the main usecase for part-expand-gpt), because sgdisk dry
run produces a warning in that case.

So remove the excessive safety check, and leave it up to the caller.

Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com>
Reviewed-by: Roman Kagan <rkagan@virtuozzo.com>
2019-04-16 09:32:02 +01:00
Richard W.M. Jones
e047cc4da8 lib: qemu: rbd: Properly escape IPv6 addresses.
Each ':' character in the address must be escaped from qemu.

Thanks: Jonathan Wright
2019-04-01 17:31:25 +01:00
Pino Toscano
89b5dabf8d tests: skip test-relabel.pl when selinuxrelabel is not available
test-relabel.pl performs a full SELinux relabelling of the phony guest,
and the selinux_relabel API does not work if the "selinuxrelabel"
feature is not available.
2019-02-11 16:43:53 +01:00
Pino Toscano
27cd2888c3 automake2junit.ml: string -> bytes
Make it usable OOTB with OCaml >= 4.02.0.
2019-01-14 15:19:32 +01:00
Richard W.M. Jones
05d4fcb64d Update copyright dates for 2019.
This command run over the source:

perl -pi.bak -e 's/(20[01][0-9])-2018/$1-2019/g' `git ls-files`
2019-01-08 11:58:30 +00:00
Richard W.M. Jones
e62a443165 tests: Provide a way for skipping tests/bigdirs/test-big-dirs.pl.
This test is currently broken because of a kernel bug
(https://bugzilla.redhat.com/show_bug.cgi?id=1657200).
2018-12-11 17:53:29 +00:00
Richard W.M. Jones
b0c11adee7 tests: md: Increase size of MD partitions in test.
Commit c11a92751e chose some strangely
sized partitions for testing Linux MD devices.  The disks were 100M
however the four partitions only covered the first 10M of disk space
(with the rest being unallocated and unused in the test).

This worked until Linux 4.20 where the ~2M-sized partitions become too
small for a Linux MD device.

This commit changes the test to use four 20M-sized partitions which is
sufficient space to create the MD device with recent kernels.  I also
modified the partition allocation code to use explicit calculations
and variables, making it considerably clearer.
2018-11-30 14:59:32 +00:00
Richard W.M. Jones
da48f4e5ff sparsify: Fix test-virt-sparsify-in-place-fstrim-unsupported.sh
Since Linux commit f663b5b38fff trimming vfat is now supported by
Linux.  This broke the test which assumed it was not supported.  Use
another filesystem (minix) which does not support trimming instead.

Thanks: Daniel P. Berrangé and Pino Toscano.
2018-09-21 13:32:58 +01:00
Mykola Ivanets
b699111e04 daemon: list-filesystems: Filter out MBR extended partitions.
Extended MBR partitions cannot hold filesystems - filter them out.

RWMJ:

* Simplify is_mbr_extended function.

* Fix regression test rhbz1285847:

  The test assumed that list-filesystems would return an extended MBR
  partition (as "unknown").  However such partitions only contain
  logical partitions inside them, not filesystems.

* Some minor whitespace changes.
2018-06-01 15:09:34 +01:00
Mykola Ivanets
af63e6e491 tests: list-filesystems command ignores partitioned MD devices.
Test guestfish list-filesystems command finds file system on partitioned md device and doesn't take into account md device itself (similar to as physical devices are filtered out if they are partitioned).
2018-06-01 15:09:34 +01:00
Pino Toscano
2bf88b102c tests: regressions: make test-big-heap use a temporary empty file
Newer versions of qemu use file locking for the images by default, and
apparently that does not work with /dev/null.  Since this test just
calls qemu-img to get the format of an empty image, create a temporary
one instead.
2018-03-21 13:40:59 +01:00
Pino Toscano
ba53251ab9 automake2junit.ml: use LargeFile to stat'ing files
While scanning the sources, some of the files (i.e. the cached
appliance) may be larger than 4G, and thus raise EOVERFLOW on 32bit
architectures.

Fixes commit b4e119d8b7.
2018-03-01 10:14:32 +01:00
Pino Toscano
b4e119d8b7 automake2junit.ml: ignore symlinks when searching for .trs files
One gnulib test creates a symlink to the same directory, causing our
iteration to read the same test directory over and over, every time
considering it as new level of subdirectory.

As solution (or workaround), when iterating through a directory consider
only regular files, and directories, ignoring any other file type
(symlinks included).
2018-02-23 14:38:26 +01:00
Mykola Ivanets
079681058e tests: md: test guestfish finds md and LV devices in different combinations
Test guestfish finds:
1. md device created from physical block device and LV,
2. md device created from LVs
3. LV created on md device

raid0 is used for md device because it is inoperable if one of its components is inaccessible so it is easy observable that md device is missing (raid1 in this case will be operable but in degraded state).
2018-01-16 09:49:21 +00:00
Mykola Ivanets
c71e9e9acd tests: md: test guestfish finds logical volume on md device
Test guestfish finds logical volume (LV) created on md device
2018-01-16 09:49:21 +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
6407f23e3d tests: Make filtering code in rhbz557655.sh test more liberal.
Because of vagaries in how the debug messages get printed they can get
split over lines:

  gulibguestfs: trace: truncate_size = 0
  estfsd: => truncate_size (0xc8) took 0.00 secs

and the code which filtered out those messages before comparison was
failing.  This makes the code more liberal on how it matches and
filters out these messages.
2017-11-16 22:43:53 +00:00
Richard W.M. Jones
8295e44004 tests: disks: Enhance the test output by naming the test failures.
Makes it easier to find which test is failing.
2017-10-18 14:54:22 +01:00
Richard W.M. Jones
b7f5919aa7 tests: disks: Small adjustment for new libvirt iscsi qemu parameter.
Latest libvirt (3.8, I think) made a very small adjustment to the
format of the generated -drive parameter when using iscsi, from:

  file=iscsi://1.2.3.4:1234/iqn.2003-01.org.linux-iscsi.fedora,

to:

  file=iscsi://1.2.3.4:1234/iqn.2003-01.org.linux-iscsi.fedora/0,

This makes a corresponding change to the test so that both patterns
can be recognized.
2017-10-18 14:54:22 +01:00
Richard W.M. Jones
f397049191 tests: Fix regression test to work with new debug messages from guestfsd.
Commit 0b631d739b changed the debug
message format from the main loop in guestfsd.  This test tried to
filter out these messages when comparing output, but that stopped
working.  The problem was only evident when enabling debugging while
running the tests.
2017-10-17 23:31:36 +01:00
Richard W.M. Jones
9ac5d9859c threads: Add a test. 2017-09-16 23:06:25 +01:00
Richard W.M. Jones
4662c95266 tests: md: Temporarily disable test which requires device name hints.
These are broken after inspection was rewritten, but we should
fix them before 1.38 is released.
2017-09-16 22:27:16 +01:00
Richard W.M. Jones
4c474aba91 tests/qemu: Make the isolation tests more read and write heavy.
Do more reading of the backing file data, and more writes to the
overlay.
2017-09-14 16:58:17 +01:00
Richard W.M. Jones
52be0a6c50 tests/qemu: Split qemu snapshot isolation into 3 tests.
It contained 3 tests before.  It's better to run them in parallel.

Just a simple refactoring, no change.
2017-09-14 16:58:17 +01:00
Richard W.M. Jones
b237418678 tests: Add a regression test for RHBZ#1477623. 2017-08-08 17:50:23 +01:00
Richard W.M. Jones
58ecca0432 tests: discard: Remove dubious use of "/dev/urandom" as a Device parameter.
This API docs don't state that this is permitted.
2017-08-08 17:50:23 +01:00
Richard W.M. Jones
a20859f563 tests: lvm: Make the lvm_set_filter test easier to understand.
No functional change.
2017-07-27 14:39:46 +01:00
Richard W.M. Jones
2cb0413049 gobject: Use TEST_FUNCTIONS framework in tests. 2017-07-10 17:03:19 +01:00
Richard W.M. Jones
e6c89f9631 utils: Rename ‘guestfs-internal-frontend.h’ to ‘guestfs-utils.h’.
The reason it's not just ‘utils.h’ is because Pino is worried that we
might pick up /usr/include/utils.h from a rogue library.
2017-07-10 17:01:59 +01:00
Richard W.M. Jones
5efebd8c7e utils: Split out structs cleanups and printing into common/structs.
These won't be used by the daemon, so interferes with us using
common/utils in the daemon, so they are moved to a different library.
2017-07-10 17:01:59 +01:00
Richard W.M. Jones
c77837e6f2 s390x: tests: 9p: Use virtio-9p-ccw as the 9p device in this test. 2017-05-18 19:02:01 +01:00
Richard W.M. Jones
93af83de85 s390x: tests: regressions: Skip IDE tests on S/390.
IDE interface is not supported.
2017-05-18 19:02:01 +01:00
Matteo Cafasso
f3d3136a17 yara_scan: added API tests
Signed-off-by: Matteo Cafasso <noxdafox@gmail.com>
2017-05-02 13:42:29 +01:00
Richard W.M. Jones
99ac577a5b tests: Replace test-max-disks with several tests.
Replace the monolithic 'test-max-disks.pl' script with a test program
written in C.  The program is completely equivalent to the old script,
except for the enhancement that it is able to detect if disks are
added to the appliance in the wrong order.

The tests themselves are split out into some shell scripts:

 - test-27-disks: Fully tests 27 disks.
   This is the minimum supported configuration for all backends.

 - test-255-disks: Fully tests 255 disks.
   This is the most disks that libguestfs up to 1.36 supported.

 - test-add-lots-of-disks: Add ‘a lot’ of disks and exit (without
   any further testing).  This is meant to try to exercise > 255
   disk case but without being as slow as a test of the max number
   of disks (which takes ages, even for as few as 4000 disks).

 - test-max-disks: Test the maximum possible number of disks.
   The maximum depends on several factors, notably which backend
   is in use, and the limit on the number of open files.

   ‘test-max-disks’ is a slow test.
2017-04-21 15:20:16 +01:00