[PATCHv2 7/7] qemu: monitor: Refactor and fix monitor checking

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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)
+
 static virClassPtr qemuMonitorClass;
 static void qemuMonitorDispose(void *obj);

@@ -1188,6 +1214,8 @@ qemuMonitorUpdateVideoMemorySize(qemuMonitorPtr mon,
     int ret = -1;
     char *path = NULL;

+    QEMU_CHECK_MONITOR(mon);
+
     if (mon->json) {
         ret = qemuMonitorFindObjectPath(mon, "/", videoName, &path);
         if (ret < 0) {
@@ -1216,6 +1244,8 @@ qemuMonitorHMPCommandWithFd(qemuMonitorPtr mon,
     char *json_cmd = NULL;
     int ret = -1;

+    QEMU_CHECK_MONITOR(mon);
+
     if (mon->json) {
         /* hack to avoid complicating each call to text monitor functions */
         json_cmd = qemuMonitorUnescapeArg(cmd);
@@ -1527,13 +1557,7 @@ qemuMonitorEmitSerialChange(qemuMonitorPtr mon,
 int
 qemuMonitorSetCapabilities(qemuMonitorPtr mon)
 {
-    VIR_DEBUG("mon=%p", mon);
-
-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (!mon->json)
         return 0;
@@ -1546,13 +1570,7 @@ int
 qemuMonitorStartCPUs(qemuMonitorPtr mon,
                      virConnectPtr conn)
 {
-    VIR_DEBUG("mon=%p", mon);
-
-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONStartCPUs(mon, conn);
@@ -1564,13 +1582,7 @@ qemuMonitorStartCPUs(qemuMonitorPtr mon,
 int
 qemuMonitorStopCPUs(qemuMonitorPtr mon)
 {
-    VIR_DEBUG("mon=%p", mon);
-
-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONStopCPUs(mon);
@@ -1586,11 +1598,7 @@ qemuMonitorGetStatus(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p, running=%p, reason=%p", mon, running, reason);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONGetStatus(mon, running, reason);
@@ -1602,13 +1610,7 @@ qemuMonitorGetStatus(qemuMonitorPtr mon,
 int
 qemuMonitorSystemPowerdown(qemuMonitorPtr mon)
 {
-    VIR_DEBUG("mon=%p", mon);
-
-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONSystemPowerdown(mon);
@@ -1620,13 +1622,7 @@ qemuMonitorSystemPowerdown(qemuMonitorPtr mon)
 int
 qemuMonitorSystemReset(qemuMonitorPtr mon)
 {
-    VIR_DEBUG("mon=%p", mon);
-
-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONSystemReset(mon);
@@ -1639,13 +1635,7 @@ int
 qemuMonitorGetCPUInfo(qemuMonitorPtr mon,
                       int **pids)
 {
-    VIR_DEBUG("mon=%p", mon);
-
-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONGetCPUInfo(mon, pids);
@@ -1661,11 +1651,7 @@ qemuMonitorSetLink(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p, name=%s, state=%u", mon, name, state);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONSetLink(mon, name, state);
@@ -1678,13 +1664,7 @@ int
 qemuMonitorGetVirtType(qemuMonitorPtr mon,
                        int *virtType)
 {
-    VIR_DEBUG("mon=%p", mon);
-
-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONGetVirtType(mon, virtType);
@@ -1697,13 +1677,7 @@ int
 qemuMonitorGetBalloonInfo(qemuMonitorPtr mon,
                           unsigned long long *currmem)
 {
-    VIR_DEBUG("mon=%p", mon);
-
-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONGetBalloonInfo(mon, currmem);
@@ -1719,11 +1693,7 @@ qemuMonitorGetMemoryStats(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p stats=%p nstats=%u", mon, stats, nr_stats);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json) {
         ignore_value(qemuMonitorFindBalloonObjectPath(mon, "/"));
@@ -1810,13 +1780,7 @@ qemuMonitorGetBlockInfo(qemuMonitorPtr mon)
     int ret;
     virHashTablePtr table;

-    VIR_DEBUG("mon=%p", mon);
-
-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return NULL;
-    }
+    QEMU_CHECK_MONITOR_FULL(mon, false, return NULL);

     if (!(table = virHashCreate(32, virHashValueFree)))
         return NULL;
@@ -1876,6 +1840,8 @@ qemuMonitorGetAllBlockStatsInfo(qemuMonitorPtr mon,
     if (!(*ret_stats = virHashCreate(10, virHashValueFree)))
         goto error;

+    QEMU_CHECK_MONITOR(mon);
+
     if (mon->json) {
         ret = qemuMonitorJSONGetAllBlockStatsInfo(mon, *ret_stats,
                                                   backingChain);
@@ -1910,11 +1876,7 @@ qemuMonitorBlockStatsUpdateCapacity(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p, stats=%p, backing=%d", mon, stats, backingChain);

-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("block capacity/size info requires JSON monitor"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     return qemuMonitorJSONBlockStatsUpdateCapacity(mon, stats, backingChain);
 }
@@ -1927,6 +1889,8 @@ qemuMonitorGetBlockExtent(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p, dev_name=%s", mon, dev_name);

+    QEMU_CHECK_MONITOR(mon);
+
     if (mon->json)
         return qemuMonitorJSONGetBlockExtent(mon, dev_name, extent);
     else
@@ -1941,6 +1905,8 @@ qemuMonitorBlockResize(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p, device=%s size=%llu", mon, device, size);

+    QEMU_CHECK_MONITOR(mon);
+
     if (mon->json)
         return qemuMonitorJSONBlockResize(mon, device, size);
     else
@@ -1954,11 +1920,7 @@ qemuMonitorSetVNCPassword(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p, password=%p", mon, password);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (!password)
         password = "";
@@ -2002,11 +1964,7 @@ qemuMonitorSetPassword(qemuMonitorPtr mon,
     VIR_DEBUG("mon=%p, protocol=%s, password=%p, action_if_connected=%s",
           mon, protocol, password, action_if_connected);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (!password)
         password = "";
@@ -2033,11 +1991,7 @@ qemuMonitorExpirePassword(qemuMonitorPtr mon,

     VIR_DEBUG("mon=%p, protocol=%s, expire_time=%s", mon, protocol, expire_time);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (!expire_time)
         expire_time = "now";
@@ -2055,11 +2009,7 @@ qemuMonitorSetBalloon(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p newmem=%lu", mon, newmem);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONSetBalloon(mon, newmem);
@@ -2073,11 +2023,7 @@ qemuMonitorSetCPU(qemuMonitorPtr mon, int cpu, bool online)
 {
     VIR_DEBUG("mon=%p cpu=%d online=%d", mon, cpu, online);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONSetCPU(mon, cpu, online);
@@ -2093,11 +2039,7 @@ qemuMonitorEjectMedia(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p dev_name=%s force=%d", mon, dev_name, force);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONEjectMedia(mon, dev_name, force);
@@ -2115,11 +2057,7 @@ qemuMonitorChangeMedia(qemuMonitorPtr mon,
     VIR_DEBUG("mon=%p dev_name=%s newmedia=%s format=%s",
               mon, dev_name, newmedia, format);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONChangeMedia(mon, dev_name, newmedia, format);
@@ -2137,11 +2075,7 @@ qemuMonitorSaveVirtualMemory(qemuMonitorPtr mon,
     VIR_DEBUG("mon=%p offset=%llu length=%zu path=%s",
               mon, offset, length, path);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONSaveVirtualMemory(mon, offset, length, path);
@@ -2159,11 +2093,7 @@ qemuMonitorSavePhysicalMemory(qemuMonitorPtr mon,
     VIR_DEBUG("mon=%p offset=%llu length=%zu path=%s",
               mon, offset, length, path);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONSavePhysicalMemory(mon, offset, length, path);
@@ -2178,11 +2108,7 @@ qemuMonitorSetMigrationSpeed(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p bandwidth=%lu", mon, bandwidth);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (bandwidth > QEMU_DOMAIN_MIG_BANDWIDTH_MAX) {
         virReportError(VIR_ERR_OVERFLOW,
@@ -2204,11 +2130,7 @@ qemuMonitorSetMigrationDowntime(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p downtime=%llu", mon, downtime);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONSetMigrationDowntime(mon, downtime);
@@ -2223,17 +2145,7 @@ qemuMonitorGetMigrationCacheSize(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p cacheSize=%p", mon, cacheSize);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
-
-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("JSON monitor is required"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     return qemuMonitorJSONGetMigrationCacheSize(mon, cacheSize);
 }
@@ -2245,17 +2157,7 @@ qemuMonitorSetMigrationCacheSize(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p cacheSize=%llu", mon, cacheSize);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
-
-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("JSON monitor is required"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     return qemuMonitorJSONSetMigrationCacheSize(mon, cacheSize);
 }
@@ -2265,13 +2167,7 @@ int
 qemuMonitorGetMigrationStatus(qemuMonitorPtr mon,
                               qemuMonitorMigrationStatusPtr status)
 {
-    VIR_DEBUG("mon=%p", mon);
-
-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONGetMigrationStatus(mon, status);
@@ -2284,21 +2180,9 @@ int
 qemuMonitorGetSpiceMigrationStatus(qemuMonitorPtr mon,
                                    bool *spice_migrated)
 {
-    VIR_DEBUG("mon=%p", mon);
-
-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

-    if (mon->json) {
-        return qemuMonitorJSONGetSpiceMigrationStatus(mon, spice_migrated);
-    } else {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("JSON monitor is required"));
-        return -1;
-    }
+    return qemuMonitorJSONGetSpiceMigrationStatus(mon, spice_migrated);
 }


@@ -2310,11 +2194,7 @@ qemuMonitorMigrateToFd(qemuMonitorPtr mon,
     int ret;
     VIR_DEBUG("mon=%p fd=%d flags=%x", mon, fd, flags);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (qemuMonitorSendFileHandle(mon, "migrate", fd) < 0)
         return -1;
@@ -2344,11 +2224,7 @@ qemuMonitorMigrateToHost(qemuMonitorPtr mon,
     char *uri = NULL;
     VIR_DEBUG("mon=%p hostname=%s port=%d flags=%x", mon, hostname, port, flags);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (virAsprintf(&uri, "%s:%s:%d", protocol, hostname, port) < 0)
         return -1;
@@ -2373,11 +2249,7 @@ qemuMonitorMigrateToCommand(qemuMonitorPtr mon,
     int ret = -1;
     VIR_DEBUG("mon=%p argv=%p flags=%x", mon, argv, flags);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     argstr = virArgvToString(argv);
     if (!argstr)
@@ -2413,11 +2285,7 @@ qemuMonitorMigrateToFile(qemuMonitorPtr mon,
     VIR_DEBUG("mon=%p argv=%p target=%s offset=%llu flags=%x",
               mon, argv, target, offset, flags);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (offset % QEMU_MONITOR_MIGRATE_TO_FILE_BS) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -2472,11 +2340,7 @@ qemuMonitorMigrateToUnix(qemuMonitorPtr mon,
     int ret = -1;
     VIR_DEBUG("mon=%p, unixfile=%s flags=%x", mon, unixfile, flags);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (virAsprintf(&dest, "unix:%s", unixfile) < 0)
         return -1;
@@ -2494,13 +2358,7 @@ qemuMonitorMigrateToUnix(qemuMonitorPtr mon,
 int
 qemuMonitorMigrateCancel(qemuMonitorPtr mon)
 {
-    VIR_DEBUG("mon=%p", mon);
-
-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONMigrateCancel(mon);
@@ -2518,11 +2376,7 @@ qemuMonitorGetDumpGuestMemoryCapability(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p capability=%s", mon, capability);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     /* No capability is supported without JSON monitor */
     if (!mon->json)
@@ -2538,20 +2392,7 @@ qemuMonitorDumpToFd(qemuMonitorPtr mon, int fd, const char *dumpformat)
     int ret;
     VIR_DEBUG("mon=%p fd=%d dumpformat=%s", mon, fd, dumpformat);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
-
-    if (!mon->json) {
-        /* We don't have qemuMonitorTextDump(), so we should check mon->json
-         * here.
-         */
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("dump-guest-memory is not supported in text mode"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     if (qemuMonitorSendFileHandle(mon, "dump", fd) < 0)
         return -1;
@@ -2578,6 +2419,8 @@ qemuMonitorGraphicsRelocate(qemuMonitorPtr mon,
     VIR_DEBUG("mon=%p type=%d hostname=%s port=%d tlsPort=%d tlsSubject=%s",
               mon, type, hostname, port, tlsPort, NULLSTR(tlsSubject));

+    QEMU_CHECK_MONITOR(mon);
+
     if (mon->json)
         return qemuMonitorJSONGraphicsRelocate(mon,
                                                type,
@@ -2601,11 +2444,7 @@ qemuMonitorAddUSBDisk(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p path=%s", mon, path);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONAddUSBDisk(mon, path);
@@ -2621,11 +2460,7 @@ qemuMonitorAddUSBDeviceExact(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p bus=%d dev=%d", mon, bus, dev);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONAddUSBDeviceExact(mon, bus, dev);
@@ -2641,11 +2476,7 @@ qemuMonitorAddUSBDeviceMatch(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p vendor=%d product=%d", mon, vendor, product);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONAddUSBDeviceMatch(mon, vendor, product);
@@ -2663,11 +2494,7 @@ qemuMonitorAddPCIHostDevice(qemuMonitorPtr mon,
               mon, hostAddr->domain, hostAddr->bus, hostAddr->slot,
               hostAddr->function);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONAddPCIHostDevice(mon, hostAddr, guestAddr);
@@ -2684,11 +2511,7 @@ qemuMonitorAddPCIDisk(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p path=%s bus=%s", mon, path, bus);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONAddPCIDisk(mon, path, bus, guestAddr);
@@ -2704,11 +2527,7 @@ qemuMonitorAddPCINetwork(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p nicstr=%s", mon, nicstr);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONAddPCINetwork(mon, nicstr, guestAddr);
@@ -2725,11 +2544,7 @@ qemuMonitorRemovePCIDevice(qemuMonitorPtr mon,
           mon, guestAddr->domain, guestAddr->bus,
           guestAddr->slot, guestAddr->function);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONRemovePCIDevice(mon, guestAddr);
@@ -2745,11 +2560,7 @@ qemuMonitorSendFileHandle(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p, fdname=%s fd=%d", mon, fdname, fd);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (fd < 0) {
         virReportError(VIR_ERR_INVALID_ARG, "%s",
@@ -2782,11 +2593,7 @@ qemuMonitorCloseFileHandle(qemuMonitorPtr mon,

     error = virSaveLastError();

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        goto cleanup;
-    }
+    QEMU_CHECK_MONITOR_FULL(mon, false, goto cleanup);

     if (mon->json)
         ret = qemuMonitorJSONCloseFileHandle(mon, fdname);
@@ -2810,11 +2617,7 @@ qemuMonitorAddFd(qemuMonitorPtr mon, int fdset, int fd, const char *name)
 {
     VIR_DEBUG("mon=%p, fdset=%d, fd=%d, name=%s", mon, fdset, fd, NULLSTR(name));

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     if (fd < 0 || fdset < 0) {
         virReportError(VIR_ERR_INVALID_ARG, "%s",
@@ -2829,13 +2632,7 @@ qemuMonitorAddFd(qemuMonitorPtr mon, int fdset, int fd, const char *name)
         return -1;
     }

-    if (mon->json) {
-        return qemuMonitorJSONAddFd(mon, fdset, fd, name);
-    } else {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("add fd requires JSON monitor"));
-        return -1;
-    }
+    return qemuMonitorJSONAddFd(mon, fdset, fd, name);
 }


@@ -2852,17 +2649,9 @@ qemuMonitorRemoveFd(qemuMonitorPtr mon, int fdset, int fd)

     error = virSaveLastError();

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        goto cleanup;
-    }
+    QEMU_CHECK_MONITOR_FULL(mon, true, goto cleanup);

-    if (mon->json)
-        ret = qemuMonitorJSONRemoveFd(mon, fdset, fd);
-    else
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("remove fd requires JSON monitor"));
+    ret = qemuMonitorJSONRemoveFd(mon, fdset, fd);

  cleanup:
     if (error) {
@@ -2887,11 +2676,7 @@ qemuMonitorAddHostNetwork(qemuMonitorPtr mon,
               mon, netstr, tapfd, tapfdName, tapfdSize,
               vhostfd, vhostfdName, vhostfdSize);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     for (i = 0; i < tapfdSize; i++) {
         if (qemuMonitorSendFileHandle(mon, tapfdName[i], tapfd[i]) < 0)
@@ -2931,11 +2716,7 @@ qemuMonitorRemoveHostNetwork(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p netname=%s", mon, netname);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json) {
         virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
@@ -2961,11 +2742,7 @@ qemuMonitorAddNetdev(qemuMonitorPtr mon,
               mon, netdevstr, tapfd, tapfdName, tapfdSize,
               vhostfd, vhostfdName, vhostfdSize);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     for (i = 0; i < tapfdSize; i++) {
         if (qemuMonitorSendFileHandle(mon, tapfdName[i], tapfd[i]) < 0)
@@ -3003,11 +2780,7 @@ qemuMonitorRemoveNetdev(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p alias=%s", mon, alias);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONRemoveNetdev(mon, alias);
@@ -3022,17 +2795,7 @@ qemuMonitorQueryRxFilter(qemuMonitorPtr mon, const char *alias,
 {
     VIR_DEBUG("mon=%p alias=%s filter=%p", mon, alias, filter);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
-
-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("query-rx-filter requires JSON monitor"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     return qemuMonitorJSONQueryRxFilter(mon, alias, filter);
 }
@@ -3058,11 +2821,7 @@ qemuMonitorGetChardevInfo(qemuMonitorPtr mon,

     VIR_DEBUG("mon=%p retinfo=%p", mon, retinfo);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        goto error;
-    }
+    QEMU_CHECK_MONITOR_FULL(mon, false, goto error);

     if (!(info = virHashCreate(10, qemuMonitorChardevInfoFree)))
         goto error;
@@ -3092,11 +2851,7 @@ qemuMonitorAttachPCIDiskController(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p type=%s", mon, bus);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONAttachPCIDiskController(mon, bus, guestAddr);
@@ -3115,17 +2870,7 @@ qemuMonitorAttachDrive(qemuMonitorPtr mon,
               mon, drivestr, controllerAddr->domain, controllerAddr->bus,
               controllerAddr->slot, controllerAddr->function);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
-
-    if (mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("JSON monitor should be using AddDrive"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     return qemuMonitorTextAttachDrive(mon, drivestr, controllerAddr, driveAddr);
 }
@@ -3137,11 +2882,7 @@ qemuMonitorGetAllPCIAddresses(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p addrs=%p", mon, addrs);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONGetAllPCIAddresses(mon, addrs);
@@ -3156,11 +2897,7 @@ qemuMonitorDriveDel(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p drivestr=%s", mon, drivestr);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONDriveDel(mon, drivestr);
@@ -3175,11 +2912,7 @@ qemuMonitorDelDevice(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p devalias=%s", mon, devalias);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONDelDevice(mon, devalias);
@@ -3198,11 +2931,7 @@ qemuMonitorAddDeviceWithFd(qemuMonitorPtr mon,
               NULLSTR(fdname));
     int ret;

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (fd >= 0 && qemuMonitorSendFileHandle(mon, fdname, fd) < 0)
         return -1;
@@ -3248,15 +2977,14 @@ qemuMonitorAddObject(qemuMonitorPtr mon,
     VIR_DEBUG("mon=%p type=%s objalias=%s props=%p",
               mon, type, objalias, props);

-    if (!mon->json) {
-        virJSONValueFree(props);
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("object adding requires JSON monitor"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_FULL(mon, true, goto error);

     return qemuMonitorJSONAddObject(mon, type, objalias, props);
-}
+
+ error:
+    virJSONValueFree(props);
+    return -1;
+}


 int
@@ -3265,11 +2993,7 @@ qemuMonitorDelObject(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p objalias=%s", mon, objalias);

-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("object deletion requires JSON monitor"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     return qemuMonitorJSONDelObject(mon, objalias);
 }
@@ -3281,11 +3005,7 @@ qemuMonitorAddDrive(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p drive=%s", mon, drivestr);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONAddDrive(mon, drivestr);
@@ -3301,11 +3021,7 @@ qemuMonitorSetDrivePassphrase(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p alias=%s passphrase=%p(value hidden)", mon, alias, passphrase);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONSetDrivePassphrase(mon, alias, passphrase);
@@ -3319,11 +3035,7 @@ qemuMonitorCreateSnapshot(qemuMonitorPtr mon, const char *name)
 {
     VIR_DEBUG("mon=%p, name=%s", mon, name);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONCreateSnapshot(mon, name);
@@ -3336,11 +3048,7 @@ qemuMonitorLoadSnapshot(qemuMonitorPtr mon, const char *name)
 {
     VIR_DEBUG("mon=%p, name=%s", mon, name);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONLoadSnapshot(mon, name);
@@ -3354,11 +3062,7 @@ qemuMonitorDeleteSnapshot(qemuMonitorPtr mon, const char *name)
 {
     VIR_DEBUG("mon=%p, name=%s", mon, name);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONDeleteSnapshot(mon, name);
@@ -3378,16 +3082,7 @@ qemuMonitorDiskSnapshot(qemuMonitorPtr mon, virJSONValuePtr actions,
     VIR_DEBUG("mon=%p, actions=%p, device=%s, file=%s, format=%s, reuse=%d",
               mon, actions, device, file, format, reuse);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
-
-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("disk snapshot requires JSON monitor"));
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     return qemuMonitorJSONDiskSnapshot(mon, actions, device, file, format, reuse);
 }
@@ -3406,11 +3101,7 @@ qemuMonitorDriveMirror(qemuMonitorPtr mon,
               mon, device, file, NULLSTR(format), bandwidth, granularity,
               buf_size, flags);

-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("drive-mirror requires JSON monitor"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     return qemuMonitorJSONDriveMirror(mon, device, file, format, bandwidth,
                                       granularity, buf_size, flags);
@@ -3423,10 +3114,7 @@ qemuMonitorTransaction(qemuMonitorPtr mon, virJSONValuePtr actions)
 {
     VIR_DEBUG("mon=%p, actions=%p", mon, actions);

-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("transaction requires JSON monitor"));
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     return qemuMonitorJSONTransaction(mon, actions);
 }
@@ -3443,11 +3131,7 @@ qemuMonitorBlockCommit(qemuMonitorPtr mon, const char *device,
               "bandwidth=%llu",
               mon, device, top, base, NULLSTR(backingName), bandwidth);

-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("block-commit requires JSON monitor"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     return qemuMonitorJSONBlockCommit(mon, device, top, base,
                                          backingName, bandwidth);
@@ -3458,7 +3142,7 @@ qemuMonitorBlockCommit(qemuMonitorPtr mon, const char *device,
 bool
 qemuMonitorSupportsActiveCommit(qemuMonitorPtr mon)
 {
-    if (!mon->json)
+    if (!mon || !mon->json)
         return false;

     return qemuMonitorJSONBlockCommit(mon, "bogus", NULL, NULL, NULL, 0) == -2;
@@ -3473,11 +3157,7 @@ qemuMonitorDiskNameLookup(qemuMonitorPtr mon,
                           virStorageSourcePtr top,
                           virStorageSourcePtr target)
 {
-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("JSON monitor is required"));
-        return NULL;
-    }
+    QEMU_CHECK_MONITOR_FULL(mon, true, return NULL);

     return qemuMonitorJSONDiskNameLookup(mon, device, top, target);
 }
@@ -3490,11 +3170,7 @@ qemuMonitorDrivePivot(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p, device=%s", mon, device);

-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("drive pivot requires JSON monitor"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     return qemuMonitorJSONDrivePivot(mon, device);
 }
@@ -3508,6 +3184,8 @@ qemuMonitorArbitraryCommand(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p, cmd=%s, reply=%p, hmp=%d", mon, cmd, reply, hmp);

+    QEMU_CHECK_MONITOR(mon);
+
     if (mon->json)
         return qemuMonitorJSONArbitraryCommand(mon, cmd, reply, hmp);
     else
@@ -3518,7 +3196,7 @@ qemuMonitorArbitraryCommand(qemuMonitorPtr mon,
 int
 qemuMonitorInjectNMI(qemuMonitorPtr mon)
 {
-    VIR_DEBUG("mon=%p", mon);
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONInjectNMI(mon);
@@ -3535,6 +3213,8 @@ qemuMonitorSendKey(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p, holdtime=%u, nkeycodes=%u", mon, holdtime, nkeycodes);

+    QEMU_CHECK_MONITOR(mon);
+
     if (mon->json)
         return qemuMonitorJSONSendKey(mon, holdtime, keycodes, nkeycodes);
     else
@@ -3548,11 +3228,7 @@ qemuMonitorScreendump(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p, file=%s", mon, file);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (mon->json)
         return qemuMonitorJSONScreendump(mon, file);
@@ -3575,11 +3251,7 @@ qemuMonitorBlockStream(qemuMonitorPtr mon,
               mon, device, NULLSTR(base), NULLSTR(backingName),
               bandwidth, modern);

-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("block jobs require JSON monitor"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     return qemuMonitorJSONBlockStream(mon, device, base, backingName,
                                       bandwidth, modern);
@@ -3593,11 +3265,7 @@ qemuMonitorBlockJobCancel(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p, device=%s, modern=%d", mon, device, modern);

-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("block jobs require JSON monitor"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     return qemuMonitorJSONBlockJobCancel(mon, device, modern);
 }
@@ -3612,11 +3280,7 @@ qemuMonitorBlockJobSetSpeed(qemuMonitorPtr mon,
     VIR_DEBUG("mon=%p, device=%s, bandwidth=%lluB, modern=%d",
               mon, device, bandwidth, modern);

-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("block jobs require JSON monitor"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     return qemuMonitorJSONBlockJobSetSpeed(mon, device, bandwidth, modern);
 }
@@ -3631,11 +3295,7 @@ qemuMonitorBlockJobInfo(qemuMonitorPtr mon,
     VIR_DEBUG("mon=%p, device=%s, info=%p, bandwidth=%p",
               mon, device, info, bandwidth);

-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("block jobs require JSON monitor"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     return qemuMonitorJSONBlockJobInfo(mon, device, info, bandwidth);
 }
@@ -3649,6 +3309,8 @@ qemuMonitorSetBlockIoThrottle(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p, device=%p, info=%p", mon, device, info);

+    QEMU_CHECK_MONITOR(mon);
+
     if (mon->json)
         return qemuMonitorJSONSetBlockIoThrottle(mon, device, info, supportMaxOptions);
     else
@@ -3664,6 +3326,8 @@ qemuMonitorGetBlockIoThrottle(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p, device=%p, reply=%p", mon, device, reply);

+    QEMU_CHECK_MONITOR(mon);
+
     if (mon->json)
         return qemuMonitorJSONGetBlockIoThrottle(mon, device, reply, supportMaxOptions);
     else
@@ -3737,11 +3401,7 @@ qemuMonitorOpenGraphics(qemuMonitorPtr mon,
               mon, protocol, fd, NULLSTR(fdname), skipauth);
     int ret;

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     if (qemuMonitorSendFileHandle(mon, fdname, fd) < 0)
         return -1;
@@ -3763,44 +3423,23 @@ qemuMonitorOpenGraphics(qemuMonitorPtr mon,
 int
 qemuMonitorSystemWakeup(qemuMonitorPtr mon)
 {
-    VIR_DEBUG("mon=%p", mon);
-
-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
-
-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("JSON monitor is required"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     return qemuMonitorJSONSystemWakeup(mon);
 }


-int qemuMonitorGetVersion(qemuMonitorPtr mon,
-                          int *major,
-                          int *minor,
-                          int *micro,
-                          char **package)
+int
+qemuMonitorGetVersion(qemuMonitorPtr mon,
+                      int *major,
+                      int *minor,
+                      int *micro,
+                      char **package)
 {
     VIR_DEBUG("mon=%p major=%p minor=%p micro=%p package=%p",
               mon, major, minor, micro, package);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
-
-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("JSON monitor is required"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     return qemuMonitorJSONGetVersion(mon, major, minor, micro, package);
 }
@@ -3812,17 +3451,7 @@ qemuMonitorGetMachines(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p machines=%p", mon, machines);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
-
-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("JSON monitor is required"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     return qemuMonitorJSONGetMachines(mon, machines);
 }
@@ -3845,17 +3474,7 @@ qemuMonitorGetCPUDefinitions(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p cpus=%p", mon, cpus);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
-
-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("JSON monitor is required"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     return qemuMonitorJSONGetCPUDefinitions(mon, cpus);
 }
@@ -3867,17 +3486,7 @@ qemuMonitorGetCommands(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p commands=%p", mon, commands);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
-
-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("JSON monitor is required"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     return qemuMonitorJSONGetCommands(mon, commands);
 }
@@ -3889,17 +3498,7 @@ qemuMonitorGetEvents(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p events=%p", mon, events);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
-
-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("JSON monitor is required"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     return qemuMonitorJSONGetEvents(mon, events);
 }
@@ -3915,17 +3514,7 @@ qemuMonitorGetCommandLineOptionParameters(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p option=%s params=%p", mon, option, params);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
-
-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("JSON monitor is required"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     return qemuMonitorJSONGetCommandLineOptionParameters(mon, option,
                                                          params, found);
@@ -3939,17 +3528,7 @@ qemuMonitorGetKVMState(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p enabled=%p present=%p", mon, enabled, present);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
-
-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("JSON monitor is required"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     return qemuMonitorJSONGetKVMState(mon, enabled, present);
 }
@@ -3961,17 +3540,7 @@ qemuMonitorGetObjectTypes(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p types=%p", mon, types);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
-
-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("JSON monitor is required"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     return qemuMonitorJSONGetObjectTypes(mon, types);
 }
@@ -3984,17 +3553,7 @@ qemuMonitorGetObjectProps(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p type=%s props=%p", mon, type, props);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
-
-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("JSON monitor is required"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     return qemuMonitorJSONGetObjectProps(mon, type, props);
 }
@@ -4003,19 +3562,7 @@ qemuMonitorGetObjectProps(qemuMonitorPtr mon,
 char *
 qemuMonitorGetTargetArch(qemuMonitorPtr mon)
 {
-    VIR_DEBUG("mon=%p", mon);
-
-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return NULL;
-    }
-
-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("JSON monitor is required"));
-        return NULL;
-    }
+    QEMU_CHECK_MONITOR_FULL(mon, true, return NULL);

     return qemuMonitorJSONGetTargetArch(mon);
 }
@@ -4025,13 +3572,7 @@ int
 qemuMonitorGetMigrationCapabilities(qemuMonitorPtr mon,
                                     char ***capabilities)
 {
-    VIR_DEBUG("mon=%p", mon);
-
-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     /* No capability is supported without JSON monitor */
     if (!mon->json)
@@ -4050,11 +3591,7 @@ qemuMonitorGetMigrationCapability(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p capability=%d", mon, capability);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     /* No capability is supported without JSON monitor */
     if (!mon->json)
@@ -4071,17 +3608,7 @@ qemuMonitorSetMigrationCapability(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p capability=%d", mon, capability);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
-
-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("JSON monitor is required"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     return qemuMonitorJSONSetMigrationCapability(mon, capability, state);
 }
@@ -4094,17 +3621,7 @@ qemuMonitorNBDServerStart(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p host=%s port=%u", mon, host, port);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
-
-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("JSON monitor is required"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     return qemuMonitorJSONNBDServerStart(mon, host, port);
 }
@@ -4117,17 +3634,7 @@ qemuMonitorNBDServerAdd(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p deviceID=%s", mon, deviceID);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
-
-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("JSON monitor is required"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     return qemuMonitorJSONNBDServerAdd(mon, deviceID, writable);
 }
@@ -4136,19 +3643,7 @@ qemuMonitorNBDServerAdd(qemuMonitorPtr mon,
 int
 qemuMonitorNBDServerStop(qemuMonitorPtr mon)
 {
-    VIR_DEBUG("mon=%p", mon);
-
-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
-
-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("JSON monitor is required"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     return qemuMonitorJSONNBDServerStop(mon);
 }
@@ -4160,17 +3655,7 @@ qemuMonitorGetTPMModels(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p tpmmodels=%p", mon, tpmmodels);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
-
-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("JSON monitor is required"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     return qemuMonitorJSONGetTPMModels(mon, tpmmodels);
 }
@@ -4182,17 +3667,7 @@ qemuMonitorGetTPMTypes(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p tpmtypes=%p", mon, tpmtypes);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
-
-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("JSON monitor is required"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     return qemuMonitorJSONGetTPMTypes(mon, tpmtypes);
 }
@@ -4205,17 +3680,7 @@ qemuMonitorAttachCharDev(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p chrID=%s chr=%p", mon, chrID, chr);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
-
-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("JSON monitor is required"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     return qemuMonitorJSONAttachCharDev(mon, chrID, chr);
 }
@@ -4227,17 +3692,7 @@ qemuMonitorDetachCharDev(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p chrID=%s", mon, chrID);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
-
-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("JSON monitor is required"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     return qemuMonitorJSONDetachCharDev(mon, chrID);
 }
@@ -4249,17 +3704,7 @@ qemuMonitorGetDeviceAliases(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p, aliases=%p", mon, aliases);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
-
-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("JSON monitor is required"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     return qemuMonitorJSONGetDeviceAliases(mon, aliases);
 }
@@ -4305,17 +3750,7 @@ qemuMonitorGetGuestCPU(qemuMonitorPtr mon,
 {
     VIR_DEBUG("mon=%p, arch='%s' data='%p'", mon, virArchToString(arch), data);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
-
-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("JSON monitor is required"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     *data = NULL;

@@ -4338,20 +3773,7 @@ qemuMonitorGetGuestCPU(qemuMonitorPtr mon,
 int
 qemuMonitorRTCResetReinjection(qemuMonitorPtr mon)
 {
-
-    VIR_DEBUG("mon=%p", mon);
-
-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
-
-    if (!mon->json) {
-        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-                       _("JSON monitor is required"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     return qemuMonitorJSONRTCResetReinjection(mon);
 }
@@ -4375,11 +3797,7 @@ qemuMonitorGetIOThreads(qemuMonitorPtr mon,

     VIR_DEBUG("mon=%p iothreads=%p", mon, iothreads);

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR(mon);

     /* Requires JSON to make the query */
     if (!mon->json) {
@@ -4422,11 +3840,7 @@ qemuMonitorGetMemoryDeviceInfo(qemuMonitorPtr mon,

     *info = NULL;

-    if (!mon) {
-        virReportError(VIR_ERR_INVALID_ARG, "%s",
-                       _("monitor must not be NULL"));
-        return -1;
-    }
+    QEMU_CHECK_MONITOR_JSON(mon);

     if (!mon->json)
         return -2;
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 3e9c43c..cd4cc66 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -712,7 +712,7 @@ int qemuMonitorDiskSnapshot(qemuMonitorPtr mon,
                             const char *format,
                             bool reuse);
 int qemuMonitorTransaction(qemuMonitorPtr mon, virJSONValuePtr actions)
-    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+    ATTRIBUTE_NONNULL(2);
 int qemuMonitorDriveMirror(qemuMonitorPtr mon,
                            const char *device,
                            const char *file,
@@ -721,10 +721,10 @@ int qemuMonitorDriveMirror(qemuMonitorPtr mon,
                            unsigned int granularity,
                            unsigned long long buf_size,
                            unsigned int flags)
-    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
+    ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
 int qemuMonitorDrivePivot(qemuMonitorPtr mon,
                           const char *device)
-    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+    ATTRIBUTE_NONNULL(2);

 int qemuMonitorBlockCommit(qemuMonitorPtr mon,
                            const char *device,
@@ -732,15 +732,13 @@ int qemuMonitorBlockCommit(qemuMonitorPtr mon,
                            const char *base,
                            const char *backingName,
                            unsigned long long bandwidth)
-    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
-    ATTRIBUTE_NONNULL(4);
+    ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4);
 bool qemuMonitorSupportsActiveCommit(qemuMonitorPtr mon);
 char *qemuMonitorDiskNameLookup(qemuMonitorPtr mon,
                                 const char *device,
                                 virStorageSourcePtr top,
                                 virStorageSourcePtr target)
-    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
-    ATTRIBUTE_NONNULL(4);
+    ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4);

 int qemuMonitorArbitraryCommand(qemuMonitorPtr mon,
                                 const char *cmd,
@@ -763,12 +761,12 @@ int qemuMonitorBlockStream(qemuMonitorPtr mon,
                            const char *backingName,
                            unsigned long long bandwidth,
                            bool modern)
-    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+    ATTRIBUTE_NONNULL(2);

 int qemuMonitorBlockJobCancel(qemuMonitorPtr mon,
                               const char *device,
                               bool modern)
-    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+    ATTRIBUTE_NONNULL(2);

 int qemuMonitorBlockJobSetSpeed(qemuMonitorPtr mon,
                                 const char *device,
@@ -779,7 +777,7 @@ int qemuMonitorBlockJobInfo(qemuMonitorPtr mon,
                             const char *device,
                             virDomainBlockJobInfoPtr info,
                             unsigned long long *bandwidth)
-    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
+    ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);

 int qemuMonitorOpenGraphics(qemuMonitorPtr mon,
                             const char *protocol,
-- 
2.3.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]