334 Commits

Author SHA1 Message Date
Pino Toscano
70514dfaf1 common/mltools: allow fd for machine readable output
Allow to specify a file descriptor for the machine readable output.

Use the same assumption as done in v2v, i.e. that Unix.file_descr is
simply the int file descriptor.
2019-03-29 13:57:47 +01:00
Richard W.M. Jones
ba7fa03923 lib: direct: Set QEMU_AUDIO_DRV=none when testing schema.
Schema parsing was failing with errors such as:

libguestfs: QMP parse error: '[' or '{' expected near end of file (ignored)

This happened because the QMP command was actually completely failing
and never printing a result at all.  This happens because the qemu
audio driver can't be set up without a console.  We can suppress this
by setting the environment variable QEMU_AUDIO_DRV=none, which is the
same thing that libvirt does, and also the same thing that we are
already doing when launching the real appliance subprocess.

See also: https://bugzilla.redhat.com/show_bug.cgi?id=1692047
2019-03-27 11:53:31 +00:00
Pino Toscano
3ed32996dd inspect: return osinfo short IDs for recent Windows versions
Return the right osinfo short IDs for the majority of Windows versions
since Windows XP.
2019-03-25 16:10:20 +01:00
Pino Toscano
c648052690 inspect: fix icon of RHEL
Use a better icon for RHEL guests, still provided by redhat-logos (or
equivalent in downstream distributions), and which fits a better
definition of logo for the distribution.

Thanks to Ray Strode for the hints.
2019-03-25 16:10:20 +01:00
Pino Toscano
c8a26adf1d inspect: get icon of Gentoo guests
The icon is installed by x11-themes/gentoo-artwork, which is not
installed by default (and most probably only on "desktop"
installations), although it's the best hit so far...
2019-02-07 19:00:13 +01:00
Pino Toscano
f41a75cea6 inspect: revamp icon extraction for *SUSE guests
Newer versions do not have the 24px distributor.png icon; OTOH they have
the 48px version, so look for that one before the 24px one.

Also, bump the size limit to 10K, as newer versions of the icon are
bigger than 3K.
2019-02-06 15:19:53 +01:00
Pino Toscano
6ff95acc72 inspect: factor out find_png helper function
Isolate the code for looking for a PNG file among a specified list from
the icon_ubuntu implementation, and switch that function to it.

This is just code refactoring, with no behaviour changes.
2019-02-06 15:15:08 +01:00
Pino Toscano
032b8d4c72 inspect: bump size limit for Mageia guests
Newer versions of the logo in Cauldron are almost 3K, so bump the limit
to 10K for now.
2019-02-06 15:05:51 +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
492a945791 Revert "launch: libvirt: Use qemu-bridge-helper to implement a full network (RHBZ#1148012)."
We've been carrying this exact patch in RHEL 7 for several years.  It
reverts the change made in 2014 where we switched to using the virbr0
bridge for libguestfs networking instead of SLIRP.  We thought SLIRP
was going to become unsupported in qemu, but recently there have been
more encouraging signs since it looks like SLIRP will be spun off as a
separate project, running as a modular process and properly secured
and supported.

This reverts commit 224de20b9a.
2019-01-07 15:03:07 +00:00
Richard W.M. Jones
52ec462fea lib: direct: Move serial option from -drive to -device.
qemu deprecated and removed this option from the -drive parameter,
resulting in:

  Block format 'raw' does not support the option 'serial'

See also:
https://www.mail-archive.com/qemu-devel@nongnu.org/msg574583.html
2018-12-12 12:29:33 +00:00
Pino Toscano
78a29dbd1e lib: inspect: tweak limits of package manager files
Tweak the limits of the files of package managers downloaded to list the
installed applications:
- bump RPM 'Packages' up to 500M: Fedora installations upgraded to each
  new Fedora release have an ever-growing file, reported to be even
  slightly bigger than 400M
- reduce the other files down to 50M: they are usually small, not bigger
  than 1M-5M, so 50M is a good enough high threshold
2018-11-30 13:44:28 +01:00
Pino Toscano
b12e168efc lib: inspect: split limits of package manager files
Use different defines for the limits of the package manager files
downloaded during the inspection of applications.  This way it will be
possible to tweak each of them without affecting the others.

This is a minor refactoring, with no behaviour change.
2018-11-30 13:44:28 +01:00
Pino Toscano
8197336a9b lib: move MAX_PKG_DB_SIZE to inspect-apps
It is used only there, so avoid exposing it to all the users of
guestfs-internal.h.

This is just code motion.
2018-11-30 13:44:28 +01:00
Richard W.M. Jones
9c8d133455 Replace -nodefconfig with -no-user-config.
This option was removed from qemu for no apparent reason except to
break existing consumers.  It does the same as -no-user-config, added
in May 2012, so use that instead.
2018-11-30 12:18:01 +00:00
Martin Kletzander
d3478036a8 Fix include for xattr.h
The proper file that should be included is `sys/xattr.h` as that comes from
`glibc` and not `attr/xattr.h` which ships with the `attr` utility.

New enough `attr` utility (at least 2.4.48 in my case) even includes a #warning
in `attr/xattr.h` for projects that still have this mistake in the code.
2018-11-23 08:34:16 +00:00
Richard W.M. Jones
b0daa89ef0 lib/launch-libvirt.c: Fix tabs/spaces issue in this file.
Convert randomly used tabs into spaces.
2018-11-02 19:42:23 +00:00
Richard W.M. Jones
296d6a9fda lib, p2v: Use single_element() macro where possible.
After the previous commit, wherever we had:

  start_element ("foo") {
    string ("bar");
  } end_element ();

this can now be replaced by:

  single_element ("foo", "bar");
2018-11-02 19:38:11 +00:00
Richard W.M. Jones
6d5959a045 common/utils: Move libxml2 writer macros to a common header file.
In some places when generating XML output in C code we use some clever
macros:

  start_element ("memory") {
    attribute ("unit", "MiB");
    string_format ("%d", g->memsize);
  } end_element ();

This commit which is mostly refactoring moves the repeated definitions
of these macros into a common header file.

I also took this opportunity to change / clean up the macros:

 - The macros are now documented properly.

 - comment() and empty_element() macros are now available everywhere.

 - Error handling has been made generic.

 - Added do..while(0) around some of the macros to make them safe to
   use in all contexts.
2018-11-02 15:15:04 +00:00
Richard W.M. Jones
ba82fb023d lib: Increase default memory assigned to the appliance.
With recent Linux kernels, adding and partitioning 255 disks causes
the appliance to run out of memory.  This causes a test failure in
tests/disks/test-255-disks.sh.  This change gives the appliance enough
memory to complete the test.
2018-11-02 13:44:26 +00:00
Richard W.M. Jones
f00f920ad3 lib: Use qemu-img info -U option to avoid locking error.
https://bugs.launchpad.net/qemu/+bug/1740364
2018-11-02 13:19:51 +00:00
Richard W.M. Jones
6f605a0804 lib: direct: Query qemu binary for availability of KVM (RHBZ#1605071).
When using the direct backend, you should see the result of testing
the qemu binary for the availability of KVM:

  libguestfs: qemu KVM: enabled

Thanks: Andrea Bolognani.
2018-09-21 10:56:25 +01:00
Richard W.M. Jones
56318f0b5f ppc64le: Don't use -cpu parameter under any circumstances (RHBZ#1605071). 2018-08-28 22:24:46 +01:00
Pino Toscano
afa8111b75 OCaml tools: add output selection for --machine-readable
Add an optional argument for --machine-readable to select the output,
adding a new function to specifically write data to that output stream.
The possible choices are:
* --machine-readable: to stdout, like before
* --machine-readable=file:name-of-file: to the specified file
* --machine-readable=stream:stdout: explicitly to stdout
* --machine-readable=stream:stderr: explicitly to stderr

Adapt all the OCaml-based tools to use the new function, so the
--machine-readable choice is respected.
2018-08-23 18:03:39 +02:00
Pino Toscano
962e8b6255 lib: create: avoid one extra string allocation
When creating the qemu-img command, use the guestfs_int_cmd_add_arg &
guestfs_int_cmd_add_arg_format APIs to add the proper filename directly,
without creating a string for it.

This should cause no functional change.
2018-08-23 13:22:00 +02:00
Richard W.M. Jones
55dfcb2211 New API: lvm_scan, deprecate vgscan (RHBZ#1602353).
The old vgscan API literally ran vgscan.  When we switched to using
lvmetad (in commit dd162d2cd5) this
stopped working because lvmetad now ignores plain *scan commands
without the --cache option.

We documented that vgscan would rescan PVs, VGs and LVs, but without
activating them.

I have introduced a new API (lvm_scan) which scans or rescans PVs, VGs
and LVs.  It has an optional activate parameter allowing activation of
any new LVs that are found.

With lvmetad this nicely maps to the single command:

 pvscan --cache [--activate ay]
2018-07-26 12:02:59 +01:00
Yuri Chornoivan
adbf1bc320 Fix minor typos 2018-06-25 08:35:43 +01:00
Richard W.M. Jones
70bc83f893 lib: libvirt: Convert all socket parameters to an absolute path (RHBZ#1588451). 2018-06-21 13:19:04 +01:00
Pino Toscano
4f927e58a9 fuse: fix build when not available
The 'localmountpoint' variable in the handle is available only when
building with FUSE support, so guard it in a proper #ifdef block.

Fixes commit 296370fb86.

Thanks to: Corentin Labbe (both reporting, and testing)
2018-06-15 18:36:39 +02:00
Richard W.M. Jones
2add3c6995 utils: Factor out hexdump code used by --enable-packet-dump.
Factor out the common code used to hexdump the protocol when
./configure --enable-packet-dump is used.

It's not quite a straight refactor because I had to fix some
signedness bugs in the code which were not revealed before because
this code is usually disabled.
2018-06-04 05:36:56 -04: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
2dd9fd8530 appliance: initialize the appliance_files struct
Some compilers do not manage to figure out that the members of it are
set only when search_appliance() in the end returns 1, which is already
checked.  Help them a bit by resetting the appliance_files struct on our
own, so they will not report that 'appliance.kernel', and the others are
used as uninitialized.
2018-05-04 15:49:20 +02:00
Mykola Ivanets
296370fb86 fuse: mount_local: Fix crash when called from Java binding.
"localmountpoint" parameter is allocated in JNI before calling
mount_local and freed afterward.  But guestfs handle keeps reference
to passed "localmountpoint" parameter and will try to access it in
umount_local and free after mount_local_run caller thread ends
which leads to a crash (an attempt to access to already freed memory).

RWMJ: Remove ‘const’ from definition of localmountpoint, and
wrap a comment at 80 columns.
2018-05-02 12:07:16 +01:00
Pino Toscano
526f6b4012 launch: libvirt: free format string
When the result guestfs_disk_format() is not known, free the string
before returning an error.
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
Richard W.M. Jones
e79286f717 qemu: Fix transcription error in conversion of yajl to jansson.
This broke qemu mandatory locking detection.

Fixes commit bd1c5c9f4d.
2018-03-29 20:19:53 +01:00
Pino Toscano
286b88891c New API: inspect_get_osinfo
Try to guess the possible osinfo-db short ID for the specified OS.

Related to: https://bugzilla.redhat.com/show_bug.cgi?id=1544842
2018-02-22 17:30:41 +01:00
Pino Toscano
491970b82f lib: qemu: help GCC 8 by break'ing a case in a switch
GCC 8 thinks that the case drive_protocol_gluster may fall through, most
probably because the only code is a switch case that handles the
elements of an enum, and thus letting other fall through. In reality
this ought to not happen at all, so help GCC by break'ing the case,
which will then lead to the abort() at the end of
guestfs_int_drive_source_qemu_param.
2018-02-19 17:14:18 +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
Richard W.M. Jones
6893c40627 tmpdirs: Make the ‘su broken’ error message actionable.
Revert "tmpdirs: Blame systemd because su is broken."

This reverts commit 9464304d7a.

Replace with an actionable error message.
2018-02-07 17:26:58 +00:00
Richard W.M. Jones
9464304d7a tmpdirs: Blame systemd because su is broken. 2018-02-07 14:36:15 +00:00
Richard W.M. Jones
e4c3968880 lib/info: Remove /dev/fd hacking and pass a true filename to qemu-img info.
It obscures what's really going on and is no longer necessary
for the original purpose.

This reverts commit d50cb7bbb4.

See also:

  https://www.redhat.com/archives/libguestfs/2017-November/thread.html#00226
  https://www.redhat.com/archives/libguestfs/2017-December/thread.html#00044
2018-01-23 20:57:16 +00:00
Richard W.M. Jones
a30b51747f launch: direct: Use old-style file= and format= parameters when not disabling locking (RHBZ#1503497).
Ancient qemu 1.5 (in RHEL 7) does not understand the
file.file.filename= and file.driver= parameters.  Go back to using the
old-style file= and format= parameters when we're not trying to set
the file.backing.file.locking=off parameter.

Fixes commit 9fe592808c.

Thanks: Yongkui Guo, Václav Kadlčík.
2018-01-19 16:01:01 +00: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
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
Pino Toscano
614f680dc6 lib: libvirt: stop using <shareable/> for appliance disk (RHBZ#1518517)
Commit aa9e0057b1 made the libvirt backend
use <shareable/> for the disk of the appliance, since at that time all
the instances were using the disk directly.
OTOH, commit 3ad44c8660 switched to
overlays for read-only disks, including the appliance, so effectively
protecting the appliance.

Because of this, the libvirt backend does not need <shareable/> anymore.

Thanks to: Daniel Berrange, Richard W.M. Jones,  Peter Krempa.
2017-12-05 18:14:21 +01:00
Lars Seipel
35320dd0ed launch: direct: Omit locking option for non-file disks (RHBZ#1516094)
QEMU does not accept options unrecognized by the block driver
in use. Disable locking only for read-only disks that are
file-backed, as that's the only block driver it is supported
with.

Signed-off-by: Lars Seipel <ls@slrz.net>
2017-11-23 08:42:46 +00:00
Cédric Bosdonnat
a442d2c321 New tool: virt-builder-repository
virt-builder-repository allows users to easily create or update
a virt-builder source repository out of disk images. The tool can
be run in either interactive or automated mode.
2017-11-21 16:36:32 +00:00
Richard W.M. Jones
f2fe422909 lib: command: If command fails, exit with 126 or 127 as defined by POSIX.
If running the external command fails in "argv mode" (ie. when
not using the shell), then exit with either 126 or 127 as defined
by POSIX.

This is mostly the same as what bash does, see
execute_cmd.c:shell_execve in the bash sources.

Note: saving errno around perror(3) if necessary, otherwise you will
see different behaviour between verbose and non-verbose mode.  In
non-verbose mode, perror(3) tried to print to a closed file
descriptor, failing and overwriting errno.  That took some time to
debug.
2017-11-16 12:55:19 +00:00