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
This commit is contained in:
Richard W.M. Jones
2025-09-29 13:01:52 +01:00
committed by rwmjones
parent 788a1e4993
commit 593a382840
3 changed files with 18 additions and 36 deletions

View File

@@ -61,6 +61,13 @@ struct backend_direct_data {
char guestfsd_sock[UNIX_PATH_MAX]; /* Path to daemon socket. */
};
/* Helper that sends all output from a command to debug. */
static void
debug_lines (guestfs_h *g, void *retv, const char *buf, size_t len)
{
debug (g, "qemu: %s", buf);
}
static char *
create_cow_overlay_direct (guestfs_h *g, void *datav, struct drive *drv)
{
@@ -479,16 +486,21 @@ launch_direct (guestfs_h *g, void *datav, const char *arg)
debug (g, "begin testing qemu features");
/* Get qemu help text and version. */
if (data->qemu_data == NULL) {
struct version qemu_version;
/* If debugging, print the qemu version. */
if (g->verbose) {
CLEANUP_CMD_CLOSE struct command *cmd = guestfs_int_new_command (g);
guestfs_int_cmd_add_arg (cmd, g->hv);
guestfs_int_cmd_add_arg (cmd, "-version");
guestfs_int_cmd_set_stdout_callback (cmd, debug_lines, NULL, 0);
guestfs_int_cmd_run (cmd);
}
/* Get qemu help text. */
if (data->qemu_data == NULL) {
data->qemu_data = guestfs_int_test_qemu (g);
if (data->qemu_data == NULL)
goto cleanup0;
qemu_version = guestfs_int_qemu_version (g, data->qemu_data);
debug (g, "qemu version: %d.%d",
qemu_version.v_major, qemu_version.v_minor);
}
/* Work out if KVM is supported or if the user wants to force TCG. */