mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
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:
committed by
rwmjones
parent
788a1e4993
commit
593a382840
@@ -793,7 +793,6 @@ void guestfs_int_init_libvirt_backend (void) __attribute__((constructor));
|
|||||||
/* qemu.c */
|
/* qemu.c */
|
||||||
struct qemu_data;
|
struct qemu_data;
|
||||||
extern struct qemu_data *guestfs_int_test_qemu (guestfs_h *g);
|
extern struct qemu_data *guestfs_int_test_qemu (guestfs_h *g);
|
||||||
extern struct version guestfs_int_qemu_version (guestfs_h *g, struct qemu_data *);
|
|
||||||
extern int guestfs_int_qemu_supports_device (guestfs_h *g, const struct qemu_data *, const char *device_name);
|
extern int guestfs_int_qemu_supports_device (guestfs_h *g, const struct qemu_data *, const char *device_name);
|
||||||
extern bool guestfs_int_platform_has_kvm (guestfs_h *g, const struct qemu_data *data);
|
extern bool guestfs_int_platform_has_kvm (guestfs_h *g, const struct qemu_data *data);
|
||||||
extern char *guestfs_int_drive_source_qemu_param (guestfs_h *g, const struct drive_source *src);
|
extern char *guestfs_int_drive_source_qemu_param (guestfs_h *g, const struct drive_source *src);
|
||||||
|
|||||||
@@ -61,6 +61,13 @@ struct backend_direct_data {
|
|||||||
char guestfsd_sock[UNIX_PATH_MAX]; /* Path to daemon socket. */
|
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 *
|
static char *
|
||||||
create_cow_overlay_direct (guestfs_h *g, void *datav, struct drive *drv)
|
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");
|
debug (g, "begin testing qemu features");
|
||||||
|
|
||||||
/* Get qemu help text and version. */
|
/* If debugging, print the qemu version. */
|
||||||
if (data->qemu_data == NULL) {
|
if (g->verbose) {
|
||||||
struct version qemu_version;
|
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);
|
data->qemu_data = guestfs_int_test_qemu (g);
|
||||||
if (data->qemu_data == NULL)
|
if (data->qemu_data == NULL)
|
||||||
goto cleanup0;
|
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. */
|
/* Work out if KVM is supported or if the user wants to force TCG. */
|
||||||
|
|||||||
29
lib/qemu.c
29
lib/qemu.c
@@ -65,7 +65,6 @@ struct qemu_data {
|
|||||||
char *query_kvm; /* Output of QMP query-kvm. */
|
char *query_kvm; /* Output of QMP query-kvm. */
|
||||||
|
|
||||||
/* The following fields are derived from the fields above. */
|
/* The following fields are derived from the fields above. */
|
||||||
struct version qemu_version; /* Parsed qemu version number. */
|
|
||||||
bool has_kvm; /* If KVM is available. */
|
bool has_kvm; /* If KVM is available. */
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -81,7 +80,6 @@ static int read_cache_query_kvm (guestfs_h *g, struct qemu_data *data, const cha
|
|||||||
static int write_cache_query_kvm (guestfs_h *g, const struct qemu_data *data, const char *filename);
|
static int write_cache_query_kvm (guestfs_h *g, const struct qemu_data *data, const char *filename);
|
||||||
static int read_cache_qemu_stat (guestfs_h *g, struct qemu_data *data, const char *filename);
|
static int read_cache_qemu_stat (guestfs_h *g, struct qemu_data *data, const char *filename);
|
||||||
static int write_cache_qemu_stat (guestfs_h *g, const struct qemu_data *data, const char *filename);
|
static int write_cache_qemu_stat (guestfs_h *g, const struct qemu_data *data, const char *filename);
|
||||||
static void parse_qemu_version (guestfs_h *g, const char *, struct version *qemu_version);
|
|
||||||
static void parse_has_kvm (guestfs_h *g, const char *, bool *);
|
static void parse_has_kvm (guestfs_h *g, const char *, bool *);
|
||||||
static void read_all (guestfs_h *g, void *retv, const char *buf, size_t len);
|
static void read_all (guestfs_h *g, void *retv, const char *buf, size_t len);
|
||||||
static int generic_read_cache (guestfs_h *g, const char *filename, char **strp);
|
static int generic_read_cache (guestfs_h *g, const char *filename, char **strp);
|
||||||
@@ -218,7 +216,6 @@ guestfs_int_test_qemu (guestfs_h *g)
|
|||||||
|
|
||||||
out:
|
out:
|
||||||
/* Derived fields. */
|
/* Derived fields. */
|
||||||
parse_qemu_version (g, data->qemu_help, &data->qemu_version);
|
|
||||||
parse_has_kvm (g, data->query_kvm, &data->has_kvm);
|
parse_has_kvm (g, data->query_kvm, &data->has_kvm);
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
@@ -392,23 +389,6 @@ write_cache_qemu_stat (guestfs_h *g, const struct qemu_data *data,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse the first line of C<qemu_help> into the major and minor
|
|
||||||
* version of qemu, but don't fail if parsing is not possible.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
parse_qemu_version (guestfs_h *g, const char *qemu_help,
|
|
||||||
struct version *qemu_version)
|
|
||||||
{
|
|
||||||
version_init_null (qemu_version);
|
|
||||||
|
|
||||||
if (guestfs_int_version_from_x_y (g, qemu_version, qemu_help) < 1) {
|
|
||||||
debug (g, "%s: failed to parse qemu version string from the first line of the output of '%s -help'. When reporting this bug please include the -help output.",
|
|
||||||
__func__, g->hv);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse the json output from QMP query-kvm to find out if KVM is
|
* Parse the json output from QMP query-kvm to find out if KVM is
|
||||||
* enabled on this machine. Don't fail if parsing is not possible,
|
* enabled on this machine. Don't fail if parsing is not possible,
|
||||||
@@ -579,15 +559,6 @@ read_all (guestfs_h *g, void *retv, const char *buf, size_t len)
|
|||||||
*ret = safe_strndup (g, buf, len);
|
*ret = safe_strndup (g, buf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the parsed version of qemu.
|
|
||||||
*/
|
|
||||||
struct version
|
|
||||||
guestfs_int_qemu_version (guestfs_h *g, struct qemu_data *data)
|
|
||||||
{
|
|
||||||
return data->qemu_version;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test if device is supported by qemu (currently just greps the
|
* Test if device is supported by qemu (currently just greps the
|
||||||
* C<qemu -device ?> output).
|
* C<qemu -device ?> output).
|
||||||
|
|||||||
Reference in New Issue
Block a user