[libvirt] [PATCHv2 7/7] qemu: monitor: Refactor and fix monitor checking
John Ferlan
jferlan at redhat.com
Wed Apr 15 12:27:17 UTC 2015
On 04/14/2015 12:05 PM, Peter Krempa wrote:
> Among all the monitor APIs some where checking if mon is NULL and some
> were not. Since it's possible to have mon equal to NULL in case a second
> call is attempted once entered the monitor. This requires that every
> single API checks for the monitor.
>
> This patch adds a macro that helps checking the state of the monitor and
> either refactors existing checking code to use the macro or adds it in
> case it was missing.
> ---
> src/qemu/qemu_monitor.c | 918 +++++++++---------------------------------------
> src/qemu/qemu_monitor.h | 18 +-
> 2 files changed, 174 insertions(+), 762 deletions(-)
>
> diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
> index d5bdfb8..e5630f1 100644
> --- a/src/qemu/qemu_monitor.c
> +++ b/src/qemu/qemu_monitor.c
> @@ -98,6 +98,32 @@ struct _qemuMonitor {
> int logfd;
> };
>
> +/**
> + * QEMU_CHECK_MONITOR_FULL:
> + * @MON: monitor pointer variable to check, evaluated multiple times, no parentheses
> + * @FORCE_JSON: force JSON monitor, true or false
> + * @EXIT: statement that is used to exit the function
> + *
> + * This macro checks that the monitor is valid for given operation and exits
> + * the function if not. The macro also adds a debug statement regarding the
> + * monitor.
> + */
> +#define QEMU_CHECK_MONITOR_FULL(MON, FORCE_JSON, EXIT) \
> + if (!MON) { \
> + virReportError(VIR_ERR_INVALID_ARG, "%s", \
> + _("Monitor must not be NULL")); \
> + EXIT; \
> + } \
> + VIR_DEBUG("Mon:%p vm:%p json:%d fd:%d", MON, MON->vm, MON->json, MON->fd); \
> + if (FORCE_JSON && !MON->json) { \
> + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", \
> + _("JSON monitor is required")); \
> + EXIT; \
> + }
> +
> +#define QEMU_CHECK_MONITOR(MON) QEMU_CHECK_MONITOR_FULL(MON, false, return -1)
> +#define QEMU_CHECK_MONITOR_JSON(MON) QEMU_CHECK_MONITOR_FULL(MON, true, return -1)
> +
...
> @@ -1876,6 +1840,8 @@ qemuMonitorGetAllBlockStatsInfo(qemuMonitorPtr mon,
> if (!(*ret_stats = virHashCreate(10, virHashValueFree)))
> goto error;
>
> + QEMU_CHECK_MONITOR(mon);
> +
Leaks *ret_stats on failure
Looks like you'll need to use the _FULL like other places
> if (mon->json) {
> ret = qemuMonitorJSONGetAllBlockStatsInfo(mon, *ret_stats,
> backingChain);
...
John
More information about the libvir-list
mailing list