2009-11-03 18:59:18 +00:00
|
|
|
/*
|
|
|
|
* qemu_monitor_json.c: interaction with QEMU monitor console
|
|
|
|
*
|
2016-02-10 12:33:47 +00:00
|
|
|
* Copyright (C) 2006-2016 Red Hat, Inc.
|
2009-11-03 18:59:18 +00:00
|
|
|
* Copyright (C) 2006 Daniel P. Berrange
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2009-11-03 18:59:18 +00:00
|
|
|
*
|
|
|
|
* Author: Daniel P. Berrange <berrange@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/un.h>
|
|
|
|
#include <poll.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
2011-02-23 11:12:11 +00:00
|
|
|
#include "qemu_monitor_text.h"
|
2009-11-03 18:59:18 +00:00
|
|
|
#include "qemu_monitor_json.h"
|
2016-06-29 16:37:39 +00:00
|
|
|
#include "qemu_alias.h"
|
2016-02-10 12:33:47 +00:00
|
|
|
#include "qemu_parse_command.h"
|
2012-02-13 11:19:24 +00:00
|
|
|
#include "qemu_capabilities.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2012-12-12 17:59:27 +00:00
|
|
|
#include "virlog.h"
|
2009-11-03 18:59:18 +00:00
|
|
|
#include "driver.h"
|
|
|
|
#include "datatypes.h"
|
2012-12-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2012-12-12 17:53:50 +00:00
|
|
|
#include "virjson.h"
|
2014-02-27 13:41:11 +00:00
|
|
|
#include "virprobe.h"
|
2013-04-12 20:55:45 +00:00
|
|
|
#include "virstring.h"
|
2013-07-22 11:07:23 +00:00
|
|
|
#include "cpu/cpu_x86.h"
|
2015-06-29 14:18:53 +00:00
|
|
|
#include "c-strcasestr.h"
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2012-04-02 17:24:29 +00:00
|
|
|
#ifdef WITH_DTRACE_PROBES
|
|
|
|
# include "libvirt_qemu_probes.h"
|
|
|
|
#endif
|
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_QEMU
|
|
|
|
|
2014-02-28 12:16:17 +00:00
|
|
|
VIR_LOG_INIT("qemu.qemu_monitor_json");
|
|
|
|
|
2013-07-22 11:07:23 +00:00
|
|
|
#define QOM_CPU_PATH "/machine/unattached/device[0]"
|
2009-11-03 18:59:18 +00:00
|
|
|
|
|
|
|
#define LINE_ENDING "\r\n"
|
|
|
|
|
2009-11-26 13:06:24 +00:00
|
|
|
static void qemuMonitorJSONHandleShutdown(qemuMonitorPtr mon, virJSONValuePtr data);
|
|
|
|
static void qemuMonitorJSONHandleReset(qemuMonitorPtr mon, virJSONValuePtr data);
|
|
|
|
static void qemuMonitorJSONHandlePowerdown(qemuMonitorPtr mon, virJSONValuePtr data);
|
|
|
|
static void qemuMonitorJSONHandleStop(qemuMonitorPtr mon, virJSONValuePtr data);
|
2013-01-07 21:25:01 +00:00
|
|
|
static void qemuMonitorJSONHandleResume(qemuMonitorPtr mon, virJSONValuePtr data);
|
2010-03-18 18:28:15 +00:00
|
|
|
static void qemuMonitorJSONHandleRTCChange(qemuMonitorPtr mon, virJSONValuePtr data);
|
Add support for an explicit watchdog event
This introduces a new event type
VIR_DOMAIN_EVENT_ID_WATCHDOG
This event includes the action that is about to be taken
as a result of the watchdog triggering
typedef enum {
VIR_DOMAIN_EVENT_WATCHDOG_NONE = 0,
VIR_DOMAIN_EVENT_WATCHDOG_PAUSE,
VIR_DOMAIN_EVENT_WATCHDOG_RESET,
VIR_DOMAIN_EVENT_WATCHDOG_POWEROFF,
VIR_DOMAIN_EVENT_WATCHDOG_SHUTDOWN,
VIR_DOMAIN_EVENT_WATCHDOG_DEBUG,
} virDomainEventWatchdogAction;
Thus there is a new callback definition for this event type
typedef void (*virConnectDomainEventWatchdogCallback)(virConnectPtr conn,
virDomainPtr dom,
int action,
void *opaque);
* daemon/remote.c: Dispatch watchdog events to client
* examples/domain-events/events-c/event-test.c: Watch for
watchdog events
* include/libvirt/libvirt.h.in: Define new watchdg event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle watchdog events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for watchdogs and emit a libvirt watchdog event
* src/remote/remote_driver.c: Receive and dispatch watchdog
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
watchdog events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for WATCHDOG event
from QEMU monitor
2010-03-18 19:07:48 +00:00
|
|
|
static void qemuMonitorJSONHandleWatchdog(qemuMonitorPtr mon, virJSONValuePtr data);
|
Add support for an explicit IO error event
This introduces a new event type
VIR_DOMAIN_EVENT_ID_IO_ERROR
This event includes the action that is about to be taken
as a result of the watchdog triggering
typedef enum {
VIR_DOMAIN_EVENT_IO_ERROR_NONE = 0,
VIR_DOMAIN_EVENT_IO_ERROR_PAUSE,
VIR_DOMAIN_EVENT_IO_ERROR_REPORT,
} virDomainEventIOErrorAction;
In addition it has the source path of the disk that had the
error and its unique device alias. It does not include the
target device name (/dev/sda), since this would preclude
triggering IO errors from other file backed devices (eg
serial ports connected to a file)
Thus there is a new callback definition for this event type
typedef void (*virConnectDomainEventIOErrorCallback)(virConnectPtr conn,
virDomainPtr dom,
const char *srcPath,
const char *devAlias,
int action,
void *opaque);
This is currently wired up to the QEMU block IO error events
* daemon/remote.c: Dispatch IO error events to client
* examples/domain-events/events-c/event-test.c: Watch for
IO error events
* include/libvirt/libvirt.h.in: Define new IO error event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle IO error events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for block IO errors and emit a libvirt IO error event
* src/remote/remote_driver.c: Receive and dispatch IO error
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
IO error events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for BLOCK_IO_ERROR event
from QEMU monitor
2010-03-18 19:37:44 +00:00
|
|
|
static void qemuMonitorJSONHandleIOError(qemuMonitorPtr mon, virJSONValuePtr data);
|
Add domain events for graphics network clients
This introduces a new event type
VIR_DOMAIN_EVENT_ID_GRAPHICS
The same event can be emitted in 3 scenarios
typedef enum {
VIR_DOMAIN_EVENT_GRAPHICS_CONNECT = 0,
VIR_DOMAIN_EVENT_GRAPHICS_INITIALIZE,
VIR_DOMAIN_EVENT_GRAPHICS_DISCONNECT,
} virDomainEventGraphicsPhase;
Connect/disconnect are triggered at socket accept/close.
The initialize phase is immediately after the protocol
setup and authentication has completed. ie when the
client is authorized and about to start interacting with
the graphical desktop
This event comes with *a lot* of potential information
- IP address, port & address family of client
- IP address, port & address family of server
- Authentication scheme (arbitrary string)
- Authenticated subject identity. A subject may have
multiple identities with some authentication schemes.
For example, vencrypt+sasl results in a x509dname
and saslUsername identities.
This results in a very complicated callback :-(
typedef enum {
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV4,
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV6,
} virDomainEventGraphicsAddressType;
struct _virDomainEventGraphicsAddress {
int family;
const char *node;
const char *service;
};
typedef struct _virDomainEventGraphicsAddress virDomainEventGraphicsAddress;
typedef virDomainEventGraphicsAddress *virDomainEventGraphicsAddressPtr;
struct _virDomainEventGraphicsSubject {
int nidentity;
struct {
const char *type;
const char *name;
} *identities;
};
typedef struct _virDomainEventGraphicsSubject virDomainEventGraphicsSubject;
typedef virDomainEventGraphicsSubject *virDomainEventGraphicsSubjectPtr;
typedef void (*virConnectDomainEventGraphicsCallback)(virConnectPtr conn,
virDomainPtr dom,
int phase,
virDomainEventGraphicsAddressPtr local,
virDomainEventGraphicsAddressPtr remote,
const char *authScheme,
virDomainEventGraphicsSubjectPtr subject,
void *opaque);
The wire protocol is similarly complex
struct remote_domain_event_graphics_address {
int family;
remote_nonnull_string node;
remote_nonnull_string service;
};
const REMOTE_DOMAIN_EVENT_GRAPHICS_IDENTITY_MAX = 20;
struct remote_domain_event_graphics_identity {
remote_nonnull_string type;
remote_nonnull_string name;
};
struct remote_domain_event_graphics_msg {
remote_nonnull_domain dom;
int phase;
remote_domain_event_graphics_address local;
remote_domain_event_graphics_address remote;
remote_nonnull_string authScheme;
remote_domain_event_graphics_identity subject<REMOTE_DOMAIN_EVENT_GRAPHICS_IDENTITY_MAX>;
};
This is currently implemented in QEMU for the VNC graphics
protocol, but designed to be usable with SPICE graphics in
the future too.
* daemon/remote.c: Dispatch graphics events to client
* examples/domain-events/events-c/event-test.c: Watch for
graphics events
* include/libvirt/libvirt.h.in: Define new graphics event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle graphics events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for VNC events and emit a libvirt graphics event
* src/remote/remote_driver.c: Receive and dispatch graphics
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
graphics events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for VNC_CONNECTED,
VNC_INITIALIZED & VNC_DISCONNETED events from QEMU monitor
2010-03-19 13:27:45 +00:00
|
|
|
static void qemuMonitorJSONHandleVNCConnect(qemuMonitorPtr mon, virJSONValuePtr data);
|
|
|
|
static void qemuMonitorJSONHandleVNCInitialize(qemuMonitorPtr mon, virJSONValuePtr data);
|
|
|
|
static void qemuMonitorJSONHandleVNCDisconnect(qemuMonitorPtr mon, virJSONValuePtr data);
|
2012-03-14 05:41:35 +00:00
|
|
|
static void qemuMonitorJSONHandleSPICEConnect(qemuMonitorPtr mon, virJSONValuePtr data);
|
|
|
|
static void qemuMonitorJSONHandleSPICEInitialize(qemuMonitorPtr mon, virJSONValuePtr data);
|
|
|
|
static void qemuMonitorJSONHandleSPICEDisconnect(qemuMonitorPtr mon, virJSONValuePtr data);
|
2012-03-23 13:44:50 +00:00
|
|
|
static void qemuMonitorJSONHandleTrayChange(qemuMonitorPtr mon, virJSONValuePtr data);
|
2012-03-23 14:43:14 +00:00
|
|
|
static void qemuMonitorJSONHandlePMWakeup(qemuMonitorPtr mon, virJSONValuePtr data);
|
2012-03-23 14:50:36 +00:00
|
|
|
static void qemuMonitorJSONHandlePMSuspend(qemuMonitorPtr mon, virJSONValuePtr data);
|
2012-04-11 22:17:36 +00:00
|
|
|
static void qemuMonitorJSONHandleBlockJobCompleted(qemuMonitorPtr mon, virJSONValuePtr data);
|
|
|
|
static void qemuMonitorJSONHandleBlockJobCanceled(qemuMonitorPtr mon, virJSONValuePtr data);
|
2012-10-12 20:06:10 +00:00
|
|
|
static void qemuMonitorJSONHandleBlockJobReady(qemuMonitorPtr mon, virJSONValuePtr data);
|
2012-07-12 15:45:57 +00:00
|
|
|
static void qemuMonitorJSONHandleBalloonChange(qemuMonitorPtr mon, virJSONValuePtr data);
|
2012-10-12 19:13:39 +00:00
|
|
|
static void qemuMonitorJSONHandlePMSuspendDisk(qemuMonitorPtr mon, virJSONValuePtr data);
|
2013-06-07 10:23:34 +00:00
|
|
|
static void qemuMonitorJSONHandleGuestPanic(qemuMonitorPtr mon, virJSONValuePtr data);
|
2013-07-11 15:07:26 +00:00
|
|
|
static void qemuMonitorJSONHandleDeviceDeleted(qemuMonitorPtr mon, virJSONValuePtr data);
|
2014-09-17 17:07:50 +00:00
|
|
|
static void qemuMonitorJSONHandleNicRxFilterChanged(qemuMonitorPtr mon, virJSONValuePtr data);
|
2014-11-13 13:09:39 +00:00
|
|
|
static void qemuMonitorJSONHandleSerialChange(qemuMonitorPtr mon, virJSONValuePtr data);
|
2015-05-28 11:35:06 +00:00
|
|
|
static void qemuMonitorJSONHandleSpiceMigrated(qemuMonitorPtr mon, virJSONValuePtr data);
|
2015-05-28 11:35:52 +00:00
|
|
|
static void qemuMonitorJSONHandleMigrationStatus(qemuMonitorPtr mon, virJSONValuePtr data);
|
2015-12-08 14:23:35 +00:00
|
|
|
static void qemuMonitorJSONHandleMigrationPass(qemuMonitorPtr mon, virJSONValuePtr data);
|
2016-04-01 14:41:08 +00:00
|
|
|
static void qemuMonitorJSONHandleAcpiOstInfo(qemuMonitorPtr mon, virJSONValuePtr data);
|
2017-02-22 15:52:22 +00:00
|
|
|
static void qemuMonitorJSONHandleBlockThreshold(qemuMonitorPtr mon, virJSONValuePtr data);
|
2009-11-26 13:06:24 +00:00
|
|
|
|
2012-04-11 14:58:09 +00:00
|
|
|
typedef struct {
|
2009-11-26 13:06:24 +00:00
|
|
|
const char *type;
|
|
|
|
void (*handler)(qemuMonitorPtr mon, virJSONValuePtr data);
|
2012-04-11 14:58:09 +00:00
|
|
|
} qemuEventHandler;
|
|
|
|
|
|
|
|
static qemuEventHandler eventHandlers[] = {
|
2016-04-01 14:41:08 +00:00
|
|
|
{ "ACPI_DEVICE_OST", qemuMonitorJSONHandleAcpiOstInfo, },
|
2012-07-12 15:45:57 +00:00
|
|
|
{ "BALLOON_CHANGE", qemuMonitorJSONHandleBalloonChange, },
|
2010-02-16 12:07:49 +00:00
|
|
|
{ "BLOCK_IO_ERROR", qemuMonitorJSONHandleIOError, },
|
2012-04-11 22:17:36 +00:00
|
|
|
{ "BLOCK_JOB_CANCELLED", qemuMonitorJSONHandleBlockJobCanceled, },
|
|
|
|
{ "BLOCK_JOB_COMPLETED", qemuMonitorJSONHandleBlockJobCompleted, },
|
2012-10-12 20:06:10 +00:00
|
|
|
{ "BLOCK_JOB_READY", qemuMonitorJSONHandleBlockJobReady, },
|
2017-02-22 15:52:22 +00:00
|
|
|
{ "BLOCK_WRITE_THRESHOLD", qemuMonitorJSONHandleBlockThreshold, },
|
2013-07-11 15:07:26 +00:00
|
|
|
{ "DEVICE_DELETED", qemuMonitorJSONHandleDeviceDeleted, },
|
2012-04-11 14:58:09 +00:00
|
|
|
{ "DEVICE_TRAY_MOVED", qemuMonitorJSONHandleTrayChange, },
|
2013-06-07 10:23:34 +00:00
|
|
|
{ "GUEST_PANICKED", qemuMonitorJSONHandleGuestPanic, },
|
2015-05-28 11:35:52 +00:00
|
|
|
{ "MIGRATION", qemuMonitorJSONHandleMigrationStatus, },
|
2015-12-08 14:23:35 +00:00
|
|
|
{ "MIGRATION_PASS", qemuMonitorJSONHandleMigrationPass, },
|
2014-09-17 17:07:50 +00:00
|
|
|
{ "NIC_RX_FILTER_CHANGED", qemuMonitorJSONHandleNicRxFilterChanged, },
|
2012-04-11 14:58:09 +00:00
|
|
|
{ "POWERDOWN", qemuMonitorJSONHandlePowerdown, },
|
|
|
|
{ "RESET", qemuMonitorJSONHandleReset, },
|
2013-01-07 21:25:01 +00:00
|
|
|
{ "RESUME", qemuMonitorJSONHandleResume, },
|
2012-04-11 14:58:09 +00:00
|
|
|
{ "RTC_CHANGE", qemuMonitorJSONHandleRTCChange, },
|
|
|
|
{ "SHUTDOWN", qemuMonitorJSONHandleShutdown, },
|
2012-03-14 05:41:35 +00:00
|
|
|
{ "SPICE_CONNECTED", qemuMonitorJSONHandleSPICEConnect, },
|
|
|
|
{ "SPICE_DISCONNECTED", qemuMonitorJSONHandleSPICEDisconnect, },
|
2012-04-11 14:58:09 +00:00
|
|
|
{ "SPICE_INITIALIZED", qemuMonitorJSONHandleSPICEInitialize, },
|
2015-05-28 11:35:06 +00:00
|
|
|
{ "SPICE_MIGRATE_COMPLETED", qemuMonitorJSONHandleSpiceMigrated, },
|
2012-04-11 14:58:09 +00:00
|
|
|
{ "STOP", qemuMonitorJSONHandleStop, },
|
2012-03-23 14:50:36 +00:00
|
|
|
{ "SUSPEND", qemuMonitorJSONHandlePMSuspend, },
|
2012-10-12 19:13:39 +00:00
|
|
|
{ "SUSPEND_DISK", qemuMonitorJSONHandlePMSuspendDisk, },
|
2012-04-11 14:58:09 +00:00
|
|
|
{ "VNC_CONNECTED", qemuMonitorJSONHandleVNCConnect, },
|
|
|
|
{ "VNC_DISCONNECTED", qemuMonitorJSONHandleVNCDisconnect, },
|
|
|
|
{ "VNC_INITIALIZED", qemuMonitorJSONHandleVNCInitialize, },
|
2014-11-13 13:09:39 +00:00
|
|
|
{ "VSERPORT_CHANGE", qemuMonitorJSONHandleSerialChange, },
|
2012-04-11 14:58:09 +00:00
|
|
|
{ "WAKEUP", qemuMonitorJSONHandlePMWakeup, },
|
|
|
|
{ "WATCHDOG", qemuMonitorJSONHandleWatchdog, },
|
|
|
|
/* We use bsearch, so keep this list sorted. */
|
2009-11-26 13:06:24 +00:00
|
|
|
};
|
|
|
|
|
2012-04-11 14:58:09 +00:00
|
|
|
static int
|
|
|
|
qemuMonitorEventCompare(const void *key, const void *elt)
|
|
|
|
{
|
|
|
|
const char *type = key;
|
|
|
|
const qemuEventHandler *handler = elt;
|
|
|
|
return strcmp(type, handler->type);
|
|
|
|
}
|
2009-11-26 13:06:24 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
qemuMonitorJSONIOProcessEvent(qemuMonitorPtr mon,
|
|
|
|
virJSONValuePtr obj)
|
|
|
|
{
|
2010-01-22 13:22:53 +00:00
|
|
|
const char *type;
|
2012-04-11 14:58:09 +00:00
|
|
|
qemuEventHandler *handler;
|
2014-01-30 00:14:44 +00:00
|
|
|
virJSONValuePtr data;
|
|
|
|
char *details = NULL;
|
|
|
|
virJSONValuePtr timestamp;
|
|
|
|
long long seconds = -1;
|
|
|
|
unsigned int micros = 0;
|
|
|
|
|
2009-11-26 13:06:24 +00:00
|
|
|
VIR_DEBUG("mon=%p obj=%p", mon, obj);
|
|
|
|
|
|
|
|
type = virJSONValueObjectGetString(obj, "event");
|
|
|
|
if (!type) {
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_WARN("missing event type in message");
|
2009-11-26 13:06:24 +00:00
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-01-30 00:14:44 +00:00
|
|
|
/* Not all events have data; and event reporting is best-effort only */
|
|
|
|
if ((data = virJSONValueObjectGet(obj, "data")))
|
|
|
|
details = virJSONValueToString(data, false);
|
|
|
|
if ((timestamp = virJSONValueObjectGet(obj, "timestamp"))) {
|
qemu: simplify json parsing
Rather than grabbing an arbitrary JSON value and then checking
if it has the right type, we might as well request the correct
type to begin with.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONIOProcessEvent)
(qemuMonitorJSONCommandWithFd, qemuMonitorJSONHandleGraphics)
(qemuMonitorJSONGetStatus, qemuMonitorJSONExtractCPUInfo)
(qemuMonitorJSONGetVirtType, qemuMonitorJSONGetBalloonInfo)
(qemuMonitorJSONGetMemoryStats)
(qemuMonitorJSONDevGetBlockExtent)
(qemuMonitorJSONGetOneBlockStatsInfo)
(qemuMonitorJSONGetAllBlockStatsInfo)
(qemuMonitorJSONBlockStatsUpdateCapacityOne)
(qemuMonitorJSONBlockStatsUpdateCapacity)
(qemuMonitorJSONGetBlockExtent)
(qemuMonitorJSONGetMigrationStatusReply)
(qemuMonitorJSONGetDumpGuestMemoryCapability)
(qemuMonitorJSONAddFd, qemuMonitorJSONQueryRxFilterParse)
(qemuMonitorJSONExtractChardevInfo)
(qemuMonitorJSONDiskNameLookupOne)
(qemuMonitorJSONDiskNameLookup)
(qemuMonitorJSONGetAllBlockJobInfo)
(qemuMonitorJSONBlockIoThrottleInfo, qemuMonitorJSONGetVersion)
(qemuMonitorJSONGetMachines, qemuMonitorJSONGetCPUDefinitions)
(qemuMonitorJSONGetCommands, qemuMonitorJSONGetEvents)
(qemuMonitorJSONGetKVMState, qemuMonitorJSONGetObjectTypes)
(qemuMonitorJSONGetObjectListPaths)
(qemuMonitorJSONGetObjectProps, qemuMonitorJSONGetTargetArch)
(qemuMonitorJSONGetMigrationCapabilities)
(qemuMonitorJSONGetStringArray, qemuMonitorJSONAttachCharDev)
(qemuMonitorJSONGetCPUx86Data, qemuMonitorJSONGetIOThreads)
(qemuMonitorJSONGetMemoryDeviceInfo): Use shorter idioms.
Signed-off-by: Eric Blake <eblake@redhat.com>
2015-06-20 19:40:21 +00:00
|
|
|
ignore_value(virJSONValueObjectGetNumberLong(timestamp, "seconds",
|
|
|
|
&seconds));
|
|
|
|
ignore_value(virJSONValueObjectGetNumberUint(timestamp, "microseconds",
|
|
|
|
µs));
|
2014-01-30 00:14:44 +00:00
|
|
|
}
|
|
|
|
qemuMonitorEmitEvent(mon, type, seconds, micros, details);
|
|
|
|
VIR_FREE(details);
|
|
|
|
|
2012-04-11 14:58:09 +00:00
|
|
|
handler = bsearch(type, eventHandlers, ARRAY_CARDINALITY(eventHandlers),
|
|
|
|
sizeof(eventHandlers[0]), qemuMonitorEventCompare);
|
|
|
|
if (handler) {
|
|
|
|
VIR_DEBUG("handle %s handler=%p data=%p", type,
|
|
|
|
handler->handler, data);
|
|
|
|
(handler->handler)(mon, data);
|
2009-11-26 13:06:24 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-27 14:50:43 +00:00
|
|
|
int
|
2009-11-26 13:06:24 +00:00
|
|
|
qemuMonitorJSONIOProcessLine(qemuMonitorPtr mon,
|
2009-11-03 18:59:18 +00:00
|
|
|
const char *line,
|
|
|
|
qemuMonitorMessagePtr msg)
|
|
|
|
{
|
|
|
|
virJSONValuePtr obj = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
VIR_DEBUG("Line [%s]", line);
|
|
|
|
|
2011-05-29 12:51:08 +00:00
|
|
|
if (!(obj = virJSONValueFromString(line)))
|
2009-11-03 18:59:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (obj->type != VIR_JSON_TYPE_OBJECT) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Parsed JSON reply '%s' isn't an object"), line);
|
2011-05-29 12:51:08 +00:00
|
|
|
goto cleanup;
|
2009-11-03 18:59:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (virJSONValueObjectHasKey(obj, "QMP") == 1) {
|
|
|
|
ret = 0;
|
2011-05-29 12:51:08 +00:00
|
|
|
} else if (virJSONValueObjectHasKey(obj, "event") == 1) {
|
2011-10-24 14:31:37 +00:00
|
|
|
PROBE(QEMU_MONITOR_RECV_EVENT,
|
|
|
|
"mon=%p event=%s", mon, line);
|
2009-11-26 13:06:24 +00:00
|
|
|
ret = qemuMonitorJSONIOProcessEvent(mon, obj);
|
2011-05-29 12:51:08 +00:00
|
|
|
} else if (virJSONValueObjectHasKey(obj, "error") == 1 ||
|
|
|
|
virJSONValueObjectHasKey(obj, "return") == 1) {
|
2011-10-24 14:31:37 +00:00
|
|
|
PROBE(QEMU_MONITOR_RECV_REPLY,
|
|
|
|
"mon=%p reply=%s", mon, line);
|
2011-05-29 12:51:08 +00:00
|
|
|
if (msg) {
|
|
|
|
msg->rxObject = obj;
|
|
|
|
msg->finished = 1;
|
2011-06-30 14:03:31 +00:00
|
|
|
obj = NULL;
|
2011-05-29 12:51:08 +00:00
|
|
|
ret = 0;
|
|
|
|
} else {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Unexpected JSON reply '%s'"), line);
|
2009-11-03 18:59:18 +00:00
|
|
|
}
|
|
|
|
} else {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Unknown JSON reply '%s'"), line);
|
2009-11-03 18:59:18 +00:00
|
|
|
}
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2011-06-30 14:03:31 +00:00
|
|
|
virJSONValueFree(obj);
|
2009-11-03 18:59:18 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int qemuMonitorJSONIOProcess(qemuMonitorPtr mon,
|
|
|
|
const char *data,
|
|
|
|
size_t len,
|
|
|
|
qemuMonitorMessagePtr msg)
|
|
|
|
{
|
|
|
|
int used = 0;
|
|
|
|
/*VIR_DEBUG("Data %d bytes [%s]", len, data);*/
|
|
|
|
|
|
|
|
while (used < len) {
|
|
|
|
char *nl = strstr(data + used, LINE_ENDING);
|
|
|
|
|
|
|
|
if (nl) {
|
|
|
|
int got = nl - (data + used);
|
2013-05-20 09:23:13 +00:00
|
|
|
char *line;
|
|
|
|
if (VIR_STRNDUP(line, data + used, got) < 0)
|
2009-11-03 18:59:18 +00:00
|
|
|
return -1;
|
|
|
|
used += got + strlen(LINE_ENDING);
|
|
|
|
line[got] = '\0'; /* kill \n */
|
|
|
|
if (qemuMonitorJSONIOProcessLine(mon, line, msg) < 0) {
|
|
|
|
VIR_FREE(line);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_FREE(line);
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_DEBUG("Total used %d bytes out of %zd available in buffer", used, len);
|
|
|
|
return used;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
qemuMonitorJSONCommandWithFd(qemuMonitorPtr mon,
|
|
|
|
virJSONValuePtr cmd,
|
|
|
|
int scm_fd,
|
|
|
|
virJSONValuePtr *reply)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
qemuMonitorMessage msg;
|
|
|
|
char *cmdstr = NULL;
|
2011-05-29 12:51:08 +00:00
|
|
|
char *id = NULL;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
|
|
|
*reply = NULL;
|
|
|
|
|
2012-03-29 09:52:04 +00:00
|
|
|
memset(&msg, 0, sizeof(msg));
|
2009-11-03 18:59:18 +00:00
|
|
|
|
qemu: simplify json parsing
Rather than grabbing an arbitrary JSON value and then checking
if it has the right type, we might as well request the correct
type to begin with.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONIOProcessEvent)
(qemuMonitorJSONCommandWithFd, qemuMonitorJSONHandleGraphics)
(qemuMonitorJSONGetStatus, qemuMonitorJSONExtractCPUInfo)
(qemuMonitorJSONGetVirtType, qemuMonitorJSONGetBalloonInfo)
(qemuMonitorJSONGetMemoryStats)
(qemuMonitorJSONDevGetBlockExtent)
(qemuMonitorJSONGetOneBlockStatsInfo)
(qemuMonitorJSONGetAllBlockStatsInfo)
(qemuMonitorJSONBlockStatsUpdateCapacityOne)
(qemuMonitorJSONBlockStatsUpdateCapacity)
(qemuMonitorJSONGetBlockExtent)
(qemuMonitorJSONGetMigrationStatusReply)
(qemuMonitorJSONGetDumpGuestMemoryCapability)
(qemuMonitorJSONAddFd, qemuMonitorJSONQueryRxFilterParse)
(qemuMonitorJSONExtractChardevInfo)
(qemuMonitorJSONDiskNameLookupOne)
(qemuMonitorJSONDiskNameLookup)
(qemuMonitorJSONGetAllBlockJobInfo)
(qemuMonitorJSONBlockIoThrottleInfo, qemuMonitorJSONGetVersion)
(qemuMonitorJSONGetMachines, qemuMonitorJSONGetCPUDefinitions)
(qemuMonitorJSONGetCommands, qemuMonitorJSONGetEvents)
(qemuMonitorJSONGetKVMState, qemuMonitorJSONGetObjectTypes)
(qemuMonitorJSONGetObjectListPaths)
(qemuMonitorJSONGetObjectProps, qemuMonitorJSONGetTargetArch)
(qemuMonitorJSONGetMigrationCapabilities)
(qemuMonitorJSONGetStringArray, qemuMonitorJSONAttachCharDev)
(qemuMonitorJSONGetCPUx86Data, qemuMonitorJSONGetIOThreads)
(qemuMonitorJSONGetMemoryDeviceInfo): Use shorter idioms.
Signed-off-by: Eric Blake <eblake@redhat.com>
2015-06-20 19:40:21 +00:00
|
|
|
if (virJSONValueObjectHasKey(cmd, "execute") == 1) {
|
2011-05-29 12:51:08 +00:00
|
|
|
if (!(id = qemuMonitorNextCommandID(mon)))
|
|
|
|
goto cleanup;
|
|
|
|
if (virJSONValueObjectAppendString(cmd, "id", id) < 0) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Unable to append command 'id' string"));
|
2011-05-29 12:51:08 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-22 16:41:38 +00:00
|
|
|
if (!(cmdstr = virJSONValueToString(cmd, false)))
|
2009-11-03 18:59:18 +00:00
|
|
|
goto cleanup;
|
2013-07-04 10:14:12 +00:00
|
|
|
if (virAsprintf(&msg.txBuffer, "%s\r\n", cmdstr) < 0)
|
2009-11-03 18:59:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
msg.txLength = strlen(msg.txBuffer);
|
|
|
|
msg.txFD = scm_fd;
|
|
|
|
|
|
|
|
VIR_DEBUG("Send command '%s' for write with FD %d", cmdstr, scm_fd);
|
|
|
|
|
|
|
|
ret = qemuMonitorSend(mon, &msg);
|
|
|
|
|
2011-05-29 12:51:08 +00:00
|
|
|
VIR_DEBUG("Receive command reply ret=%d rxObject=%p",
|
|
|
|
ret, msg.rxObject);
|
2009-11-03 18:59:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (ret == 0) {
|
2011-05-29 12:51:08 +00:00
|
|
|
if (!msg.rxObject) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing monitor reply object"));
|
2011-05-29 12:51:08 +00:00
|
|
|
ret = -1;
|
|
|
|
} else {
|
|
|
|
*reply = msg.rxObject;
|
2009-11-03 18:59:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2011-05-29 12:51:08 +00:00
|
|
|
VIR_FREE(id);
|
2009-11-03 18:59:18 +00:00
|
|
|
VIR_FREE(cmdstr);
|
|
|
|
VIR_FREE(msg.txBuffer);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
qemuMonitorJSONCommand(qemuMonitorPtr mon,
|
|
|
|
virJSONValuePtr cmd,
|
2014-03-18 08:15:21 +00:00
|
|
|
virJSONValuePtr *reply)
|
|
|
|
{
|
2009-11-03 18:59:18 +00:00
|
|
|
return qemuMonitorJSONCommandWithFd(mon, cmd, -1, reply);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ignoring OOM in this method, since we're already reporting
|
|
|
|
* a more important error
|
|
|
|
*
|
|
|
|
* XXX see qerror.h for different klasses & fill out useful params
|
|
|
|
*/
|
2010-02-12 16:45:11 +00:00
|
|
|
static const char *
|
|
|
|
qemuMonitorJSONStringifyError(virJSONValuePtr error)
|
2009-11-03 18:59:18 +00:00
|
|
|
{
|
2010-01-22 13:22:53 +00:00
|
|
|
const char *klass = virJSONValueObjectGetString(error, "class");
|
2010-02-12 16:45:11 +00:00
|
|
|
const char *detail = NULL;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2010-02-12 16:45:11 +00:00
|
|
|
/* The QMP 'desc' field is usually sufficient for our generic
|
|
|
|
* error reporting needs.
|
|
|
|
*/
|
|
|
|
if (klass)
|
|
|
|
detail = virJSONValueObjectGetString(error, "desc");
|
|
|
|
|
|
|
|
|
|
|
|
if (!detail)
|
|
|
|
detail = "unknown QEMU command error";
|
|
|
|
|
|
|
|
return detail;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
qemuMonitorJSONCommandName(virJSONValuePtr cmd)
|
|
|
|
{
|
|
|
|
const char *name = virJSONValueObjectGetString(cmd, "execute");
|
|
|
|
if (name)
|
|
|
|
return name;
|
|
|
|
else
|
|
|
|
return "<unknown>";
|
2009-11-03 18:59:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
qemuMonitorJSONCheckError(virJSONValuePtr cmd,
|
|
|
|
virJSONValuePtr reply)
|
|
|
|
{
|
|
|
|
if (virJSONValueObjectHasKey(reply, "error")) {
|
|
|
|
virJSONValuePtr error = virJSONValueObjectGet(reply, "error");
|
2012-08-09 10:46:29 +00:00
|
|
|
char *cmdstr = virJSONValueToString(cmd, false);
|
|
|
|
char *replystr = virJSONValueToString(reply, false);
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2010-02-12 16:45:11 +00:00
|
|
|
/* Log the full JSON formatted command & error */
|
|
|
|
VIR_DEBUG("unable to execute QEMU command %s: %s",
|
2013-02-22 16:41:38 +00:00
|
|
|
NULLSTR(cmdstr), NULLSTR(replystr));
|
2010-02-12 16:45:11 +00:00
|
|
|
|
|
|
|
/* Only send the user the command name + friendly error */
|
|
|
|
if (!error)
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("unable to execute QEMU command '%s'"),
|
|
|
|
qemuMonitorJSONCommandName(cmd));
|
2010-02-12 16:45:11 +00:00
|
|
|
else
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("unable to execute QEMU command '%s': %s"),
|
|
|
|
qemuMonitorJSONCommandName(cmd),
|
|
|
|
qemuMonitorJSONStringifyError(error));
|
2010-02-12 16:45:11 +00:00
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
VIR_FREE(cmdstr);
|
|
|
|
VIR_FREE(replystr);
|
|
|
|
return -1;
|
|
|
|
} else if (!virJSONValueObjectHasKey(reply, "return")) {
|
2012-08-09 10:46:29 +00:00
|
|
|
char *cmdstr = virJSONValueToString(cmd, false);
|
|
|
|
char *replystr = virJSONValueToString(reply, false);
|
2009-11-03 18:59:18 +00:00
|
|
|
|
|
|
|
VIR_DEBUG("Neither 'return' nor 'error' is set in the JSON reply %s: %s",
|
2013-02-22 16:41:38 +00:00
|
|
|
NULLSTR(cmdstr), NULLSTR(replystr));
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("unable to execute QEMU command '%s'"),
|
|
|
|
qemuMonitorJSONCommandName(cmd));
|
2009-11-03 18:59:18 +00:00
|
|
|
VIR_FREE(cmdstr);
|
|
|
|
VIR_FREE(replystr);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-09 09:26:43 +00:00
|
|
|
static bool
|
|
|
|
qemuMonitorJSONErrorIsClass(virJSONValuePtr error,
|
|
|
|
const char *klass)
|
|
|
|
{
|
|
|
|
return STREQ_NULLABLE(virJSONValueObjectGetString(error, "class"), klass);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool
|
2009-11-03 18:59:18 +00:00
|
|
|
qemuMonitorJSONHasError(virJSONValuePtr reply,
|
|
|
|
const char *klass)
|
|
|
|
{
|
|
|
|
virJSONValuePtr error;
|
|
|
|
|
2015-04-09 09:26:43 +00:00
|
|
|
if (!(error = virJSONValueObjectGet(reply, "error")))
|
|
|
|
return false;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2015-04-09 09:26:43 +00:00
|
|
|
return qemuMonitorJSONErrorIsClass(error, klass);
|
2009-11-03 18:59:18 +00:00
|
|
|
}
|
|
|
|
|
2015-04-09 09:26:43 +00:00
|
|
|
|
2012-03-17 04:17:28 +00:00
|
|
|
/* Top-level commands and nested transaction list elements share a
|
|
|
|
* common structure for everything except the dictionary names. */
|
2009-11-03 18:59:18 +00:00
|
|
|
static virJSONValuePtr ATTRIBUTE_SENTINEL
|
2012-03-17 04:17:28 +00:00
|
|
|
qemuMonitorJSONMakeCommandRaw(bool wrap, const char *cmdname, ...)
|
2009-11-03 18:59:18 +00:00
|
|
|
{
|
|
|
|
virJSONValuePtr obj;
|
|
|
|
virJSONValuePtr jargs = NULL;
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, cmdname);
|
|
|
|
|
|
|
|
if (!(obj = virJSONValueNewObject()))
|
2013-07-04 10:14:12 +00:00
|
|
|
goto error;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2012-03-17 04:17:28 +00:00
|
|
|
if (virJSONValueObjectAppendString(obj, wrap ? "type" : "execute",
|
|
|
|
cmdname) < 0)
|
2013-07-04 10:14:12 +00:00
|
|
|
goto error;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2014-09-22 14:35:02 +00:00
|
|
|
if (virJSONValueObjectCreateVArgs(&jargs, args) < 0)
|
|
|
|
goto error;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
|
|
|
if (jargs &&
|
2012-03-17 04:17:28 +00:00
|
|
|
virJSONValueObjectAppend(obj, wrap ? "data" : "arguments", jargs) < 0)
|
2013-07-04 10:14:12 +00:00
|
|
|
goto error;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
error:
|
2009-11-03 18:59:18 +00:00
|
|
|
virJSONValueFree(obj);
|
|
|
|
virJSONValueFree(jargs);
|
|
|
|
va_end(args);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-03-17 04:17:28 +00:00
|
|
|
#define qemuMonitorJSONMakeCommand(cmdname, ...) \
|
|
|
|
qemuMonitorJSONMakeCommandRaw(false, cmdname, __VA_ARGS__)
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2010-04-15 13:52:03 +00:00
|
|
|
|
|
|
|
static virJSONValuePtr
|
|
|
|
qemuMonitorJSONKeywordStringToJSON(const char *str, const char *firstkeyword)
|
|
|
|
{
|
|
|
|
virJSONValuePtr ret = NULL;
|
|
|
|
char **keywords = NULL;
|
|
|
|
char **values = NULL;
|
|
|
|
int nkeywords = 0;
|
Convert 'int i' to 'size_t i' in src/qemu files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2010-04-15 13:52:03 +00:00
|
|
|
|
|
|
|
if (!(ret = virJSONValueNewObject()))
|
2014-09-04 20:12:44 +00:00
|
|
|
return NULL;
|
2010-04-15 13:52:03 +00:00
|
|
|
|
2013-09-23 13:16:09 +00:00
|
|
|
if (qemuParseKeywords(str, &keywords, &values, &nkeywords, 1) < 0)
|
2010-04-15 13:52:03 +00:00
|
|
|
goto error;
|
|
|
|
|
2013-05-21 07:21:20 +00:00
|
|
|
for (i = 0; i < nkeywords; i++) {
|
2010-04-15 13:52:03 +00:00
|
|
|
if (values[i] == NULL) {
|
|
|
|
if (i != 0) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("unexpected empty keyword in %s"), str);
|
2010-04-15 13:52:03 +00:00
|
|
|
goto error;
|
|
|
|
} else {
|
|
|
|
/* This 3rd arg isn't a typo - the way the parser works is
|
|
|
|
* that the value ended up in the keyword field */
|
|
|
|
if (virJSONValueObjectAppendString(ret, firstkeyword, keywords[i]) < 0)
|
2013-07-04 10:14:12 +00:00
|
|
|
goto error;
|
2010-04-15 13:52:03 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (virJSONValueObjectAppendString(ret, keywords[i], values[i]) < 0)
|
2013-07-04 10:14:12 +00:00
|
|
|
goto error;
|
2010-04-15 13:52:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-16 20:20:04 +00:00
|
|
|
qemuParseKeywordsFree(nkeywords, keywords, values);
|
2010-04-15 13:52:03 +00:00
|
|
|
return ret;
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
error:
|
2017-10-16 20:20:04 +00:00
|
|
|
qemuParseKeywordsFree(nkeywords, keywords, values);
|
2010-04-15 13:52:03 +00:00
|
|
|
virJSONValueFree(ret);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-12 10:00:37 +00:00
|
|
|
static void qemuMonitorJSONHandleShutdown(qemuMonitorPtr mon, virJSONValuePtr data)
|
2009-11-26 13:06:24 +00:00
|
|
|
{
|
2017-04-12 10:00:37 +00:00
|
|
|
bool guest = false;
|
|
|
|
virTristateBool guest_initiated = VIR_TRISTATE_BOOL_ABSENT;
|
|
|
|
|
2017-05-30 08:28:18 +00:00
|
|
|
if (data && virJSONValueObjectGetBoolean(data, "guest", &guest) == 0)
|
2017-04-12 10:00:37 +00:00
|
|
|
guest_initiated = guest ? VIR_TRISTATE_BOOL_YES : VIR_TRISTATE_BOOL_NO;
|
|
|
|
|
|
|
|
qemuMonitorEmitShutdown(mon, guest_initiated);
|
2009-11-26 13:06:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void qemuMonitorJSONHandleReset(qemuMonitorPtr mon, virJSONValuePtr data ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
qemuMonitorEmitReset(mon);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void qemuMonitorJSONHandlePowerdown(qemuMonitorPtr mon, virJSONValuePtr data ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
qemuMonitorEmitPowerdown(mon);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void qemuMonitorJSONHandleStop(qemuMonitorPtr mon, virJSONValuePtr data ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
qemuMonitorEmitStop(mon);
|
|
|
|
}
|
|
|
|
|
2013-01-07 21:25:01 +00:00
|
|
|
static void qemuMonitorJSONHandleResume(qemuMonitorPtr mon, virJSONValuePtr data ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
qemuMonitorEmitResume(mon);
|
|
|
|
}
|
|
|
|
|
2017-03-20 13:35:33 +00:00
|
|
|
|
|
|
|
static qemuMonitorEventPanicInfoPtr
|
|
|
|
qemuMonitorJSONGuestPanicExtractInfoHyperv(virJSONValuePtr data)
|
2013-06-07 10:23:34 +00:00
|
|
|
{
|
2017-03-20 13:35:33 +00:00
|
|
|
qemuMonitorEventPanicInfoPtr ret;
|
|
|
|
|
|
|
|
if (VIR_ALLOC(ret) < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ret->type = QEMU_MONITOR_EVENT_PANIC_INFO_TYPE_HYPERV;
|
|
|
|
|
|
|
|
if (virJSONValueObjectGetNumberUlong(data, "arg1", &ret->data.hyperv.arg1) < 0 ||
|
|
|
|
virJSONValueObjectGetNumberUlong(data, "arg2", &ret->data.hyperv.arg2) < 0 ||
|
|
|
|
virJSONValueObjectGetNumberUlong(data, "arg3", &ret->data.hyperv.arg3) < 0 ||
|
|
|
|
virJSONValueObjectGetNumberUlong(data, "arg4", &ret->data.hyperv.arg4) < 0 ||
|
|
|
|
virJSONValueObjectGetNumberUlong(data, "arg5", &ret->data.hyperv.arg5) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("malformed hyperv panic data"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
error:
|
|
|
|
qemuMonitorEventPanicInfoFree(ret);
|
|
|
|
return NULL;
|
2013-06-07 10:23:34 +00:00
|
|
|
}
|
|
|
|
|
2017-03-20 13:35:33 +00:00
|
|
|
|
|
|
|
static qemuMonitorEventPanicInfoPtr
|
|
|
|
qemuMonitorJSONGuestPanicExtractInfo(virJSONValuePtr data)
|
|
|
|
{
|
|
|
|
const char *type = virJSONValueObjectGetString(data, "type");
|
|
|
|
|
|
|
|
if (STREQ_NULLABLE(type, "hyper-v"))
|
|
|
|
return qemuMonitorJSONGuestPanicExtractInfoHyperv(data);
|
|
|
|
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("unknown panic info type '%s'"), NULLSTR(type));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
qemuMonitorJSONHandleGuestPanic(qemuMonitorPtr mon,
|
|
|
|
virJSONValuePtr data)
|
|
|
|
{
|
|
|
|
virJSONValuePtr infojson = virJSONValueObjectGetObject(data, "info");
|
|
|
|
qemuMonitorEventPanicInfoPtr info = NULL;
|
|
|
|
|
|
|
|
if (infojson)
|
|
|
|
info = qemuMonitorJSONGuestPanicExtractInfo(infojson);
|
|
|
|
|
|
|
|
qemuMonitorEmitGuestPanic(mon, info);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-18 18:28:15 +00:00
|
|
|
static void qemuMonitorJSONHandleRTCChange(qemuMonitorPtr mon, virJSONValuePtr data)
|
|
|
|
{
|
|
|
|
long long offset = 0;
|
|
|
|
if (virJSONValueObjectGetNumberLong(data, "offset", &offset) < 0) {
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_WARN("missing offset in RTC change event");
|
2010-03-18 18:28:15 +00:00
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
qemuMonitorEmitRTCChange(mon, offset);
|
|
|
|
}
|
|
|
|
|
Add support for an explicit watchdog event
This introduces a new event type
VIR_DOMAIN_EVENT_ID_WATCHDOG
This event includes the action that is about to be taken
as a result of the watchdog triggering
typedef enum {
VIR_DOMAIN_EVENT_WATCHDOG_NONE = 0,
VIR_DOMAIN_EVENT_WATCHDOG_PAUSE,
VIR_DOMAIN_EVENT_WATCHDOG_RESET,
VIR_DOMAIN_EVENT_WATCHDOG_POWEROFF,
VIR_DOMAIN_EVENT_WATCHDOG_SHUTDOWN,
VIR_DOMAIN_EVENT_WATCHDOG_DEBUG,
} virDomainEventWatchdogAction;
Thus there is a new callback definition for this event type
typedef void (*virConnectDomainEventWatchdogCallback)(virConnectPtr conn,
virDomainPtr dom,
int action,
void *opaque);
* daemon/remote.c: Dispatch watchdog events to client
* examples/domain-events/events-c/event-test.c: Watch for
watchdog events
* include/libvirt/libvirt.h.in: Define new watchdg event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle watchdog events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for watchdogs and emit a libvirt watchdog event
* src/remote/remote_driver.c: Receive and dispatch watchdog
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
watchdog events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for WATCHDOG event
from QEMU monitor
2010-03-18 19:07:48 +00:00
|
|
|
VIR_ENUM_DECL(qemuMonitorWatchdogAction)
|
2012-01-20 21:00:58 +00:00
|
|
|
VIR_ENUM_IMPL(qemuMonitorWatchdogAction, VIR_DOMAIN_EVENT_WATCHDOG_LAST,
|
2015-06-24 09:28:41 +00:00
|
|
|
"none", "pause", "reset", "poweroff", "shutdown", "debug", "inject-nmi");
|
Add support for an explicit watchdog event
This introduces a new event type
VIR_DOMAIN_EVENT_ID_WATCHDOG
This event includes the action that is about to be taken
as a result of the watchdog triggering
typedef enum {
VIR_DOMAIN_EVENT_WATCHDOG_NONE = 0,
VIR_DOMAIN_EVENT_WATCHDOG_PAUSE,
VIR_DOMAIN_EVENT_WATCHDOG_RESET,
VIR_DOMAIN_EVENT_WATCHDOG_POWEROFF,
VIR_DOMAIN_EVENT_WATCHDOG_SHUTDOWN,
VIR_DOMAIN_EVENT_WATCHDOG_DEBUG,
} virDomainEventWatchdogAction;
Thus there is a new callback definition for this event type
typedef void (*virConnectDomainEventWatchdogCallback)(virConnectPtr conn,
virDomainPtr dom,
int action,
void *opaque);
* daemon/remote.c: Dispatch watchdog events to client
* examples/domain-events/events-c/event-test.c: Watch for
watchdog events
* include/libvirt/libvirt.h.in: Define new watchdg event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle watchdog events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for watchdogs and emit a libvirt watchdog event
* src/remote/remote_driver.c: Receive and dispatch watchdog
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
watchdog events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for WATCHDOG event
from QEMU monitor
2010-03-18 19:07:48 +00:00
|
|
|
|
|
|
|
static void qemuMonitorJSONHandleWatchdog(qemuMonitorPtr mon, virJSONValuePtr data)
|
|
|
|
{
|
|
|
|
const char *action;
|
|
|
|
int actionID;
|
2014-11-13 14:25:30 +00:00
|
|
|
if (!(action = virJSONValueObjectGetString(data, "action")))
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_WARN("missing action in watchdog event");
|
Add support for an explicit watchdog event
This introduces a new event type
VIR_DOMAIN_EVENT_ID_WATCHDOG
This event includes the action that is about to be taken
as a result of the watchdog triggering
typedef enum {
VIR_DOMAIN_EVENT_WATCHDOG_NONE = 0,
VIR_DOMAIN_EVENT_WATCHDOG_PAUSE,
VIR_DOMAIN_EVENT_WATCHDOG_RESET,
VIR_DOMAIN_EVENT_WATCHDOG_POWEROFF,
VIR_DOMAIN_EVENT_WATCHDOG_SHUTDOWN,
VIR_DOMAIN_EVENT_WATCHDOG_DEBUG,
} virDomainEventWatchdogAction;
Thus there is a new callback definition for this event type
typedef void (*virConnectDomainEventWatchdogCallback)(virConnectPtr conn,
virDomainPtr dom,
int action,
void *opaque);
* daemon/remote.c: Dispatch watchdog events to client
* examples/domain-events/events-c/event-test.c: Watch for
watchdog events
* include/libvirt/libvirt.h.in: Define new watchdg event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle watchdog events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for watchdogs and emit a libvirt watchdog event
* src/remote/remote_driver.c: Receive and dispatch watchdog
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
watchdog events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for WATCHDOG event
from QEMU monitor
2010-03-18 19:07:48 +00:00
|
|
|
if (action) {
|
|
|
|
if ((actionID = qemuMonitorWatchdogActionTypeFromString(action)) < 0) {
|
|
|
|
VIR_WARN("unknown action %s in watchdog event", action);
|
|
|
|
actionID = VIR_DOMAIN_EVENT_WATCHDOG_NONE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
actionID = VIR_DOMAIN_EVENT_WATCHDOG_NONE;
|
|
|
|
}
|
2010-04-08 15:01:00 +00:00
|
|
|
qemuMonitorEmitWatchdog(mon, actionID);
|
Add support for an explicit watchdog event
This introduces a new event type
VIR_DOMAIN_EVENT_ID_WATCHDOG
This event includes the action that is about to be taken
as a result of the watchdog triggering
typedef enum {
VIR_DOMAIN_EVENT_WATCHDOG_NONE = 0,
VIR_DOMAIN_EVENT_WATCHDOG_PAUSE,
VIR_DOMAIN_EVENT_WATCHDOG_RESET,
VIR_DOMAIN_EVENT_WATCHDOG_POWEROFF,
VIR_DOMAIN_EVENT_WATCHDOG_SHUTDOWN,
VIR_DOMAIN_EVENT_WATCHDOG_DEBUG,
} virDomainEventWatchdogAction;
Thus there is a new callback definition for this event type
typedef void (*virConnectDomainEventWatchdogCallback)(virConnectPtr conn,
virDomainPtr dom,
int action,
void *opaque);
* daemon/remote.c: Dispatch watchdog events to client
* examples/domain-events/events-c/event-test.c: Watch for
watchdog events
* include/libvirt/libvirt.h.in: Define new watchdg event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle watchdog events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for watchdogs and emit a libvirt watchdog event
* src/remote/remote_driver.c: Receive and dispatch watchdog
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
watchdog events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for WATCHDOG event
from QEMU monitor
2010-03-18 19:07:48 +00:00
|
|
|
}
|
|
|
|
|
Add support for an explicit IO error event
This introduces a new event type
VIR_DOMAIN_EVENT_ID_IO_ERROR
This event includes the action that is about to be taken
as a result of the watchdog triggering
typedef enum {
VIR_DOMAIN_EVENT_IO_ERROR_NONE = 0,
VIR_DOMAIN_EVENT_IO_ERROR_PAUSE,
VIR_DOMAIN_EVENT_IO_ERROR_REPORT,
} virDomainEventIOErrorAction;
In addition it has the source path of the disk that had the
error and its unique device alias. It does not include the
target device name (/dev/sda), since this would preclude
triggering IO errors from other file backed devices (eg
serial ports connected to a file)
Thus there is a new callback definition for this event type
typedef void (*virConnectDomainEventIOErrorCallback)(virConnectPtr conn,
virDomainPtr dom,
const char *srcPath,
const char *devAlias,
int action,
void *opaque);
This is currently wired up to the QEMU block IO error events
* daemon/remote.c: Dispatch IO error events to client
* examples/domain-events/events-c/event-test.c: Watch for
IO error events
* include/libvirt/libvirt.h.in: Define new IO error event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle IO error events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for block IO errors and emit a libvirt IO error event
* src/remote/remote_driver.c: Receive and dispatch IO error
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
IO error events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for BLOCK_IO_ERROR event
from QEMU monitor
2010-03-18 19:37:44 +00:00
|
|
|
VIR_ENUM_DECL(qemuMonitorIOErrorAction)
|
2012-01-20 21:00:58 +00:00
|
|
|
VIR_ENUM_IMPL(qemuMonitorIOErrorAction, VIR_DOMAIN_EVENT_IO_ERROR_LAST,
|
Add support for an explicit IO error event
This introduces a new event type
VIR_DOMAIN_EVENT_ID_IO_ERROR
This event includes the action that is about to be taken
as a result of the watchdog triggering
typedef enum {
VIR_DOMAIN_EVENT_IO_ERROR_NONE = 0,
VIR_DOMAIN_EVENT_IO_ERROR_PAUSE,
VIR_DOMAIN_EVENT_IO_ERROR_REPORT,
} virDomainEventIOErrorAction;
In addition it has the source path of the disk that had the
error and its unique device alias. It does not include the
target device name (/dev/sda), since this would preclude
triggering IO errors from other file backed devices (eg
serial ports connected to a file)
Thus there is a new callback definition for this event type
typedef void (*virConnectDomainEventIOErrorCallback)(virConnectPtr conn,
virDomainPtr dom,
const char *srcPath,
const char *devAlias,
int action,
void *opaque);
This is currently wired up to the QEMU block IO error events
* daemon/remote.c: Dispatch IO error events to client
* examples/domain-events/events-c/event-test.c: Watch for
IO error events
* include/libvirt/libvirt.h.in: Define new IO error event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle IO error events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for block IO errors and emit a libvirt IO error event
* src/remote/remote_driver.c: Receive and dispatch IO error
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
IO error events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for BLOCK_IO_ERROR event
from QEMU monitor
2010-03-18 19:37:44 +00:00
|
|
|
"ignore", "stop", "report");
|
|
|
|
|
|
|
|
|
qemu: support nospace reason in io error event
Aeons ago (commit 34dcbbb4, v0.8.2), we added a new libvirt event
(VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON) in order to tell the user WHY
the guest halted. This is because at least VDSM wants to react
differently to ENOSPC events (resize the lvm partition to be larger,
and resume the guest as if nothing had happened) from all other events
(I/O is hosed, throw up our hands and flag things as broken). At the
time this was done, downstream RHEL qemu added a vendor extension
'__com.redhat_reason', which would be exactly one of these strings:
"enospc", "eperm", "eio", and "eother". In our stupidity, we exposed
those exact strings to clients, rather than an enum, and we also
return "" if we did not have access to a reason (which was the case
for upstream qemu).
Fast forward to now: upstream qemu commit c7c2ff0c (will be qemu 2.2)
FINALLY adds a 'nospace' boolean, after discussion with multiple
projects determined that VDSM really doesn't care about distinction
between any other error types. So this patch converts 'nospace' into
the string "enospc" for compatibility with RHEL clients that were
already used to the downstream extension, while leaving the reason
blank for all other cases (no change from the status quo).
See also https://bugzilla.redhat.com/show_bug.cgi?id=1119784
* src/qemu/qemu_monitor_json.c (qewmuMonitorJSONHandleIOError):
Parse reason field from modern qemu.
* include/libvirt/libvirt.h.in
(virConnectDomainEventIOErrorReasonCallback): Document it.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-10-03 14:46:25 +00:00
|
|
|
static void
|
|
|
|
qemuMonitorJSONHandleIOError(qemuMonitorPtr mon, virJSONValuePtr data)
|
Add support for an explicit IO error event
This introduces a new event type
VIR_DOMAIN_EVENT_ID_IO_ERROR
This event includes the action that is about to be taken
as a result of the watchdog triggering
typedef enum {
VIR_DOMAIN_EVENT_IO_ERROR_NONE = 0,
VIR_DOMAIN_EVENT_IO_ERROR_PAUSE,
VIR_DOMAIN_EVENT_IO_ERROR_REPORT,
} virDomainEventIOErrorAction;
In addition it has the source path of the disk that had the
error and its unique device alias. It does not include the
target device name (/dev/sda), since this would preclude
triggering IO errors from other file backed devices (eg
serial ports connected to a file)
Thus there is a new callback definition for this event type
typedef void (*virConnectDomainEventIOErrorCallback)(virConnectPtr conn,
virDomainPtr dom,
const char *srcPath,
const char *devAlias,
int action,
void *opaque);
This is currently wired up to the QEMU block IO error events
* daemon/remote.c: Dispatch IO error events to client
* examples/domain-events/events-c/event-test.c: Watch for
IO error events
* include/libvirt/libvirt.h.in: Define new IO error event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle IO error events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for block IO errors and emit a libvirt IO error event
* src/remote/remote_driver.c: Receive and dispatch IO error
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
IO error events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for BLOCK_IO_ERROR event
from QEMU monitor
2010-03-18 19:37:44 +00:00
|
|
|
{
|
|
|
|
const char *device;
|
|
|
|
const char *action;
|
qemu: support nospace reason in io error event
Aeons ago (commit 34dcbbb4, v0.8.2), we added a new libvirt event
(VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON) in order to tell the user WHY
the guest halted. This is because at least VDSM wants to react
differently to ENOSPC events (resize the lvm partition to be larger,
and resume the guest as if nothing had happened) from all other events
(I/O is hosed, throw up our hands and flag things as broken). At the
time this was done, downstream RHEL qemu added a vendor extension
'__com.redhat_reason', which would be exactly one of these strings:
"enospc", "eperm", "eio", and "eother". In our stupidity, we exposed
those exact strings to clients, rather than an enum, and we also
return "" if we did not have access to a reason (which was the case
for upstream qemu).
Fast forward to now: upstream qemu commit c7c2ff0c (will be qemu 2.2)
FINALLY adds a 'nospace' boolean, after discussion with multiple
projects determined that VDSM really doesn't care about distinction
between any other error types. So this patch converts 'nospace' into
the string "enospc" for compatibility with RHEL clients that were
already used to the downstream extension, while leaving the reason
blank for all other cases (no change from the status quo).
See also https://bugzilla.redhat.com/show_bug.cgi?id=1119784
* src/qemu/qemu_monitor_json.c (qewmuMonitorJSONHandleIOError):
Parse reason field from modern qemu.
* include/libvirt/libvirt.h.in
(virConnectDomainEventIOErrorReasonCallback): Document it.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-10-03 14:46:25 +00:00
|
|
|
const char *reason = "";
|
|
|
|
bool nospc = false;
|
Add support for an explicit IO error event
This introduces a new event type
VIR_DOMAIN_EVENT_ID_IO_ERROR
This event includes the action that is about to be taken
as a result of the watchdog triggering
typedef enum {
VIR_DOMAIN_EVENT_IO_ERROR_NONE = 0,
VIR_DOMAIN_EVENT_IO_ERROR_PAUSE,
VIR_DOMAIN_EVENT_IO_ERROR_REPORT,
} virDomainEventIOErrorAction;
In addition it has the source path of the disk that had the
error and its unique device alias. It does not include the
target device name (/dev/sda), since this would preclude
triggering IO errors from other file backed devices (eg
serial ports connected to a file)
Thus there is a new callback definition for this event type
typedef void (*virConnectDomainEventIOErrorCallback)(virConnectPtr conn,
virDomainPtr dom,
const char *srcPath,
const char *devAlias,
int action,
void *opaque);
This is currently wired up to the QEMU block IO error events
* daemon/remote.c: Dispatch IO error events to client
* examples/domain-events/events-c/event-test.c: Watch for
IO error events
* include/libvirt/libvirt.h.in: Define new IO error event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle IO error events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for block IO errors and emit a libvirt IO error event
* src/remote/remote_driver.c: Receive and dispatch IO error
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
IO error events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for BLOCK_IO_ERROR event
from QEMU monitor
2010-03-18 19:37:44 +00:00
|
|
|
int actionID;
|
|
|
|
|
|
|
|
/* Throughout here we try our best to carry on upon errors,
|
|
|
|
since it's imporatant to get as much info as possible out
|
|
|
|
to the application */
|
|
|
|
|
|
|
|
if ((action = virJSONValueObjectGetString(data, "action")) == NULL) {
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_WARN("Missing action in disk io error event");
|
Add support for an explicit IO error event
This introduces a new event type
VIR_DOMAIN_EVENT_ID_IO_ERROR
This event includes the action that is about to be taken
as a result of the watchdog triggering
typedef enum {
VIR_DOMAIN_EVENT_IO_ERROR_NONE = 0,
VIR_DOMAIN_EVENT_IO_ERROR_PAUSE,
VIR_DOMAIN_EVENT_IO_ERROR_REPORT,
} virDomainEventIOErrorAction;
In addition it has the source path of the disk that had the
error and its unique device alias. It does not include the
target device name (/dev/sda), since this would preclude
triggering IO errors from other file backed devices (eg
serial ports connected to a file)
Thus there is a new callback definition for this event type
typedef void (*virConnectDomainEventIOErrorCallback)(virConnectPtr conn,
virDomainPtr dom,
const char *srcPath,
const char *devAlias,
int action,
void *opaque);
This is currently wired up to the QEMU block IO error events
* daemon/remote.c: Dispatch IO error events to client
* examples/domain-events/events-c/event-test.c: Watch for
IO error events
* include/libvirt/libvirt.h.in: Define new IO error event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle IO error events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for block IO errors and emit a libvirt IO error event
* src/remote/remote_driver.c: Receive and dispatch IO error
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
IO error events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for BLOCK_IO_ERROR event
from QEMU monitor
2010-03-18 19:37:44 +00:00
|
|
|
action = "ignore";
|
|
|
|
}
|
|
|
|
|
2014-11-13 14:25:30 +00:00
|
|
|
if ((device = virJSONValueObjectGetString(data, "device")) == NULL)
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_WARN("missing device in disk io error event");
|
Add support for an explicit IO error event
This introduces a new event type
VIR_DOMAIN_EVENT_ID_IO_ERROR
This event includes the action that is about to be taken
as a result of the watchdog triggering
typedef enum {
VIR_DOMAIN_EVENT_IO_ERROR_NONE = 0,
VIR_DOMAIN_EVENT_IO_ERROR_PAUSE,
VIR_DOMAIN_EVENT_IO_ERROR_REPORT,
} virDomainEventIOErrorAction;
In addition it has the source path of the disk that had the
error and its unique device alias. It does not include the
target device name (/dev/sda), since this would preclude
triggering IO errors from other file backed devices (eg
serial ports connected to a file)
Thus there is a new callback definition for this event type
typedef void (*virConnectDomainEventIOErrorCallback)(virConnectPtr conn,
virDomainPtr dom,
const char *srcPath,
const char *devAlias,
int action,
void *opaque);
This is currently wired up to the QEMU block IO error events
* daemon/remote.c: Dispatch IO error events to client
* examples/domain-events/events-c/event-test.c: Watch for
IO error events
* include/libvirt/libvirt.h.in: Define new IO error event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle IO error events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for block IO errors and emit a libvirt IO error event
* src/remote/remote_driver.c: Receive and dispatch IO error
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
IO error events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for BLOCK_IO_ERROR event
from QEMU monitor
2010-03-18 19:37:44 +00:00
|
|
|
|
qemu: support nospace reason in io error event
Aeons ago (commit 34dcbbb4, v0.8.2), we added a new libvirt event
(VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON) in order to tell the user WHY
the guest halted. This is because at least VDSM wants to react
differently to ENOSPC events (resize the lvm partition to be larger,
and resume the guest as if nothing had happened) from all other events
(I/O is hosed, throw up our hands and flag things as broken). At the
time this was done, downstream RHEL qemu added a vendor extension
'__com.redhat_reason', which would be exactly one of these strings:
"enospc", "eperm", "eio", and "eother". In our stupidity, we exposed
those exact strings to clients, rather than an enum, and we also
return "" if we did not have access to a reason (which was the case
for upstream qemu).
Fast forward to now: upstream qemu commit c7c2ff0c (will be qemu 2.2)
FINALLY adds a 'nospace' boolean, after discussion with multiple
projects determined that VDSM really doesn't care about distinction
between any other error types. So this patch converts 'nospace' into
the string "enospc" for compatibility with RHEL clients that were
already used to the downstream extension, while leaving the reason
blank for all other cases (no change from the status quo).
See also https://bugzilla.redhat.com/show_bug.cgi?id=1119784
* src/qemu/qemu_monitor_json.c (qewmuMonitorJSONHandleIOError):
Parse reason field from modern qemu.
* include/libvirt/libvirt.h.in
(virConnectDomainEventIOErrorReasonCallback): Document it.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-10-03 14:46:25 +00:00
|
|
|
if (virJSONValueObjectGetBoolean(data, "nospace", &nospc) == 0 && nospc)
|
|
|
|
reason = "enospc";
|
Add support for another explicit IO error event
This introduces a new event type
VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON
This event is the same as the previous VIR_DOMAIN_ID_IO_ERROR
event, but also includes a string describing the cause of
the event.
Thus there is a new callback definition for this event type
typedef void (*virConnectDomainEventIOErrorReasonCallback)(virConnectPtr conn,
virDomainPtr dom,
const char *srcPath,
const char *devAlias,
int action,
const char *reason,
void *opaque);
This is currently wired up to the QEMU block IO error events
* daemon/remote.c: Dispatch IO error events to client
* examples/domain-events/events-c/event-test.c: Watch for
IO error events
* include/libvirt/libvirt.h.in: Define new IO error event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle IO error events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for block IO errors and emit a libvirt IO error event
* src/remote/remote_driver.c: Receive and dispatch IO error
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
IO error events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for BLOCK_IO_ERROR event
from QEMU monitor
2010-03-18 19:37:44 +00:00
|
|
|
|
Add support for an explicit IO error event
This introduces a new event type
VIR_DOMAIN_EVENT_ID_IO_ERROR
This event includes the action that is about to be taken
as a result of the watchdog triggering
typedef enum {
VIR_DOMAIN_EVENT_IO_ERROR_NONE = 0,
VIR_DOMAIN_EVENT_IO_ERROR_PAUSE,
VIR_DOMAIN_EVENT_IO_ERROR_REPORT,
} virDomainEventIOErrorAction;
In addition it has the source path of the disk that had the
error and its unique device alias. It does not include the
target device name (/dev/sda), since this would preclude
triggering IO errors from other file backed devices (eg
serial ports connected to a file)
Thus there is a new callback definition for this event type
typedef void (*virConnectDomainEventIOErrorCallback)(virConnectPtr conn,
virDomainPtr dom,
const char *srcPath,
const char *devAlias,
int action,
void *opaque);
This is currently wired up to the QEMU block IO error events
* daemon/remote.c: Dispatch IO error events to client
* examples/domain-events/events-c/event-test.c: Watch for
IO error events
* include/libvirt/libvirt.h.in: Define new IO error event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle IO error events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for block IO errors and emit a libvirt IO error event
* src/remote/remote_driver.c: Receive and dispatch IO error
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
IO error events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for BLOCK_IO_ERROR event
from QEMU monitor
2010-03-18 19:37:44 +00:00
|
|
|
if ((actionID = qemuMonitorIOErrorActionTypeFromString(action)) < 0) {
|
|
|
|
VIR_WARN("unknown disk io error action '%s'", action);
|
|
|
|
actionID = VIR_DOMAIN_EVENT_IO_ERROR_NONE;
|
|
|
|
}
|
|
|
|
|
Add support for another explicit IO error event
This introduces a new event type
VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON
This event is the same as the previous VIR_DOMAIN_ID_IO_ERROR
event, but also includes a string describing the cause of
the event.
Thus there is a new callback definition for this event type
typedef void (*virConnectDomainEventIOErrorReasonCallback)(virConnectPtr conn,
virDomainPtr dom,
const char *srcPath,
const char *devAlias,
int action,
const char *reason,
void *opaque);
This is currently wired up to the QEMU block IO error events
* daemon/remote.c: Dispatch IO error events to client
* examples/domain-events/events-c/event-test.c: Watch for
IO error events
* include/libvirt/libvirt.h.in: Define new IO error event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle IO error events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for block IO errors and emit a libvirt IO error event
* src/remote/remote_driver.c: Receive and dispatch IO error
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
IO error events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for BLOCK_IO_ERROR event
from QEMU monitor
2010-03-18 19:37:44 +00:00
|
|
|
qemuMonitorEmitIOError(mon, device, actionID, reason);
|
Add support for an explicit IO error event
This introduces a new event type
VIR_DOMAIN_EVENT_ID_IO_ERROR
This event includes the action that is about to be taken
as a result of the watchdog triggering
typedef enum {
VIR_DOMAIN_EVENT_IO_ERROR_NONE = 0,
VIR_DOMAIN_EVENT_IO_ERROR_PAUSE,
VIR_DOMAIN_EVENT_IO_ERROR_REPORT,
} virDomainEventIOErrorAction;
In addition it has the source path of the disk that had the
error and its unique device alias. It does not include the
target device name (/dev/sda), since this would preclude
triggering IO errors from other file backed devices (eg
serial ports connected to a file)
Thus there is a new callback definition for this event type
typedef void (*virConnectDomainEventIOErrorCallback)(virConnectPtr conn,
virDomainPtr dom,
const char *srcPath,
const char *devAlias,
int action,
void *opaque);
This is currently wired up to the QEMU block IO error events
* daemon/remote.c: Dispatch IO error events to client
* examples/domain-events/events-c/event-test.c: Watch for
IO error events
* include/libvirt/libvirt.h.in: Define new IO error event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle IO error events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for block IO errors and emit a libvirt IO error event
* src/remote/remote_driver.c: Receive and dispatch IO error
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
IO error events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for BLOCK_IO_ERROR event
from QEMU monitor
2010-03-18 19:37:44 +00:00
|
|
|
}
|
|
|
|
|
2009-11-26 13:06:24 +00:00
|
|
|
|
Add domain events for graphics network clients
This introduces a new event type
VIR_DOMAIN_EVENT_ID_GRAPHICS
The same event can be emitted in 3 scenarios
typedef enum {
VIR_DOMAIN_EVENT_GRAPHICS_CONNECT = 0,
VIR_DOMAIN_EVENT_GRAPHICS_INITIALIZE,
VIR_DOMAIN_EVENT_GRAPHICS_DISCONNECT,
} virDomainEventGraphicsPhase;
Connect/disconnect are triggered at socket accept/close.
The initialize phase is immediately after the protocol
setup and authentication has completed. ie when the
client is authorized and about to start interacting with
the graphical desktop
This event comes with *a lot* of potential information
- IP address, port & address family of client
- IP address, port & address family of server
- Authentication scheme (arbitrary string)
- Authenticated subject identity. A subject may have
multiple identities with some authentication schemes.
For example, vencrypt+sasl results in a x509dname
and saslUsername identities.
This results in a very complicated callback :-(
typedef enum {
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV4,
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV6,
} virDomainEventGraphicsAddressType;
struct _virDomainEventGraphicsAddress {
int family;
const char *node;
const char *service;
};
typedef struct _virDomainEventGraphicsAddress virDomainEventGraphicsAddress;
typedef virDomainEventGraphicsAddress *virDomainEventGraphicsAddressPtr;
struct _virDomainEventGraphicsSubject {
int nidentity;
struct {
const char *type;
const char *name;
} *identities;
};
typedef struct _virDomainEventGraphicsSubject virDomainEventGraphicsSubject;
typedef virDomainEventGraphicsSubject *virDomainEventGraphicsSubjectPtr;
typedef void (*virConnectDomainEventGraphicsCallback)(virConnectPtr conn,
virDomainPtr dom,
int phase,
virDomainEventGraphicsAddressPtr local,
virDomainEventGraphicsAddressPtr remote,
const char *authScheme,
virDomainEventGraphicsSubjectPtr subject,
void *opaque);
The wire protocol is similarly complex
struct remote_domain_event_graphics_address {
int family;
remote_nonnull_string node;
remote_nonnull_string service;
};
const REMOTE_DOMAIN_EVENT_GRAPHICS_IDENTITY_MAX = 20;
struct remote_domain_event_graphics_identity {
remote_nonnull_string type;
remote_nonnull_string name;
};
struct remote_domain_event_graphics_msg {
remote_nonnull_domain dom;
int phase;
remote_domain_event_graphics_address local;
remote_domain_event_graphics_address remote;
remote_nonnull_string authScheme;
remote_domain_event_graphics_identity subject<REMOTE_DOMAIN_EVENT_GRAPHICS_IDENTITY_MAX>;
};
This is currently implemented in QEMU for the VNC graphics
protocol, but designed to be usable with SPICE graphics in
the future too.
* daemon/remote.c: Dispatch graphics events to client
* examples/domain-events/events-c/event-test.c: Watch for
graphics events
* include/libvirt/libvirt.h.in: Define new graphics event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle graphics events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for VNC events and emit a libvirt graphics event
* src/remote/remote_driver.c: Receive and dispatch graphics
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
graphics events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for VNC_CONNECTED,
VNC_INITIALIZED & VNC_DISCONNETED events from QEMU monitor
2010-03-19 13:27:45 +00:00
|
|
|
VIR_ENUM_DECL(qemuMonitorGraphicsAddressFamily)
|
2012-01-20 21:00:58 +00:00
|
|
|
VIR_ENUM_IMPL(qemuMonitorGraphicsAddressFamily,
|
|
|
|
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_LAST,
|
2011-10-21 08:14:02 +00:00
|
|
|
"ipv4", "ipv6", "unix");
|
Add domain events for graphics network clients
This introduces a new event type
VIR_DOMAIN_EVENT_ID_GRAPHICS
The same event can be emitted in 3 scenarios
typedef enum {
VIR_DOMAIN_EVENT_GRAPHICS_CONNECT = 0,
VIR_DOMAIN_EVENT_GRAPHICS_INITIALIZE,
VIR_DOMAIN_EVENT_GRAPHICS_DISCONNECT,
} virDomainEventGraphicsPhase;
Connect/disconnect are triggered at socket accept/close.
The initialize phase is immediately after the protocol
setup and authentication has completed. ie when the
client is authorized and about to start interacting with
the graphical desktop
This event comes with *a lot* of potential information
- IP address, port & address family of client
- IP address, port & address family of server
- Authentication scheme (arbitrary string)
- Authenticated subject identity. A subject may have
multiple identities with some authentication schemes.
For example, vencrypt+sasl results in a x509dname
and saslUsername identities.
This results in a very complicated callback :-(
typedef enum {
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV4,
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV6,
} virDomainEventGraphicsAddressType;
struct _virDomainEventGraphicsAddress {
int family;
const char *node;
const char *service;
};
typedef struct _virDomainEventGraphicsAddress virDomainEventGraphicsAddress;
typedef virDomainEventGraphicsAddress *virDomainEventGraphicsAddressPtr;
struct _virDomainEventGraphicsSubject {
int nidentity;
struct {
const char *type;
const char *name;
} *identities;
};
typedef struct _virDomainEventGraphicsSubject virDomainEventGraphicsSubject;
typedef virDomainEventGraphicsSubject *virDomainEventGraphicsSubjectPtr;
typedef void (*virConnectDomainEventGraphicsCallback)(virConnectPtr conn,
virDomainPtr dom,
int phase,
virDomainEventGraphicsAddressPtr local,
virDomainEventGraphicsAddressPtr remote,
const char *authScheme,
virDomainEventGraphicsSubjectPtr subject,
void *opaque);
The wire protocol is similarly complex
struct remote_domain_event_graphics_address {
int family;
remote_nonnull_string node;
remote_nonnull_string service;
};
const REMOTE_DOMAIN_EVENT_GRAPHICS_IDENTITY_MAX = 20;
struct remote_domain_event_graphics_identity {
remote_nonnull_string type;
remote_nonnull_string name;
};
struct remote_domain_event_graphics_msg {
remote_nonnull_domain dom;
int phase;
remote_domain_event_graphics_address local;
remote_domain_event_graphics_address remote;
remote_nonnull_string authScheme;
remote_domain_event_graphics_identity subject<REMOTE_DOMAIN_EVENT_GRAPHICS_IDENTITY_MAX>;
};
This is currently implemented in QEMU for the VNC graphics
protocol, but designed to be usable with SPICE graphics in
the future too.
* daemon/remote.c: Dispatch graphics events to client
* examples/domain-events/events-c/event-test.c: Watch for
graphics events
* include/libvirt/libvirt.h.in: Define new graphics event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle graphics events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for VNC events and emit a libvirt graphics event
* src/remote/remote_driver.c: Receive and dispatch graphics
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
graphics events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for VNC_CONNECTED,
VNC_INITIALIZED & VNC_DISCONNETED events from QEMU monitor
2010-03-19 13:27:45 +00:00
|
|
|
|
2015-06-29 14:10:51 +00:00
|
|
|
static void
|
|
|
|
qemuMonitorJSONHandleGraphicsVNC(qemuMonitorPtr mon,
|
|
|
|
virJSONValuePtr data,
|
|
|
|
int phase)
|
Add domain events for graphics network clients
This introduces a new event type
VIR_DOMAIN_EVENT_ID_GRAPHICS
The same event can be emitted in 3 scenarios
typedef enum {
VIR_DOMAIN_EVENT_GRAPHICS_CONNECT = 0,
VIR_DOMAIN_EVENT_GRAPHICS_INITIALIZE,
VIR_DOMAIN_EVENT_GRAPHICS_DISCONNECT,
} virDomainEventGraphicsPhase;
Connect/disconnect are triggered at socket accept/close.
The initialize phase is immediately after the protocol
setup and authentication has completed. ie when the
client is authorized and about to start interacting with
the graphical desktop
This event comes with *a lot* of potential information
- IP address, port & address family of client
- IP address, port & address family of server
- Authentication scheme (arbitrary string)
- Authenticated subject identity. A subject may have
multiple identities with some authentication schemes.
For example, vencrypt+sasl results in a x509dname
and saslUsername identities.
This results in a very complicated callback :-(
typedef enum {
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV4,
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV6,
} virDomainEventGraphicsAddressType;
struct _virDomainEventGraphicsAddress {
int family;
const char *node;
const char *service;
};
typedef struct _virDomainEventGraphicsAddress virDomainEventGraphicsAddress;
typedef virDomainEventGraphicsAddress *virDomainEventGraphicsAddressPtr;
struct _virDomainEventGraphicsSubject {
int nidentity;
struct {
const char *type;
const char *name;
} *identities;
};
typedef struct _virDomainEventGraphicsSubject virDomainEventGraphicsSubject;
typedef virDomainEventGraphicsSubject *virDomainEventGraphicsSubjectPtr;
typedef void (*virConnectDomainEventGraphicsCallback)(virConnectPtr conn,
virDomainPtr dom,
int phase,
virDomainEventGraphicsAddressPtr local,
virDomainEventGraphicsAddressPtr remote,
const char *authScheme,
virDomainEventGraphicsSubjectPtr subject,
void *opaque);
The wire protocol is similarly complex
struct remote_domain_event_graphics_address {
int family;
remote_nonnull_string node;
remote_nonnull_string service;
};
const REMOTE_DOMAIN_EVENT_GRAPHICS_IDENTITY_MAX = 20;
struct remote_domain_event_graphics_identity {
remote_nonnull_string type;
remote_nonnull_string name;
};
struct remote_domain_event_graphics_msg {
remote_nonnull_domain dom;
int phase;
remote_domain_event_graphics_address local;
remote_domain_event_graphics_address remote;
remote_nonnull_string authScheme;
remote_domain_event_graphics_identity subject<REMOTE_DOMAIN_EVENT_GRAPHICS_IDENTITY_MAX>;
};
This is currently implemented in QEMU for the VNC graphics
protocol, but designed to be usable with SPICE graphics in
the future too.
* daemon/remote.c: Dispatch graphics events to client
* examples/domain-events/events-c/event-test.c: Watch for
graphics events
* include/libvirt/libvirt.h.in: Define new graphics event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle graphics events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for VNC events and emit a libvirt graphics event
* src/remote/remote_driver.c: Receive and dispatch graphics
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
graphics events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for VNC_CONNECTED,
VNC_INITIALIZED & VNC_DISCONNETED events from QEMU monitor
2010-03-19 13:27:45 +00:00
|
|
|
{
|
|
|
|
const char *localNode, *localService, *localFamily;
|
|
|
|
const char *remoteNode, *remoteService, *remoteFamily;
|
|
|
|
const char *authScheme, *saslUsername, *x509dname;
|
|
|
|
int localFamilyID, remoteFamilyID;
|
|
|
|
virJSONValuePtr client;
|
|
|
|
virJSONValuePtr server;
|
|
|
|
|
qemu: simplify json parsing
Rather than grabbing an arbitrary JSON value and then checking
if it has the right type, we might as well request the correct
type to begin with.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONIOProcessEvent)
(qemuMonitorJSONCommandWithFd, qemuMonitorJSONHandleGraphics)
(qemuMonitorJSONGetStatus, qemuMonitorJSONExtractCPUInfo)
(qemuMonitorJSONGetVirtType, qemuMonitorJSONGetBalloonInfo)
(qemuMonitorJSONGetMemoryStats)
(qemuMonitorJSONDevGetBlockExtent)
(qemuMonitorJSONGetOneBlockStatsInfo)
(qemuMonitorJSONGetAllBlockStatsInfo)
(qemuMonitorJSONBlockStatsUpdateCapacityOne)
(qemuMonitorJSONBlockStatsUpdateCapacity)
(qemuMonitorJSONGetBlockExtent)
(qemuMonitorJSONGetMigrationStatusReply)
(qemuMonitorJSONGetDumpGuestMemoryCapability)
(qemuMonitorJSONAddFd, qemuMonitorJSONQueryRxFilterParse)
(qemuMonitorJSONExtractChardevInfo)
(qemuMonitorJSONDiskNameLookupOne)
(qemuMonitorJSONDiskNameLookup)
(qemuMonitorJSONGetAllBlockJobInfo)
(qemuMonitorJSONBlockIoThrottleInfo, qemuMonitorJSONGetVersion)
(qemuMonitorJSONGetMachines, qemuMonitorJSONGetCPUDefinitions)
(qemuMonitorJSONGetCommands, qemuMonitorJSONGetEvents)
(qemuMonitorJSONGetKVMState, qemuMonitorJSONGetObjectTypes)
(qemuMonitorJSONGetObjectListPaths)
(qemuMonitorJSONGetObjectProps, qemuMonitorJSONGetTargetArch)
(qemuMonitorJSONGetMigrationCapabilities)
(qemuMonitorJSONGetStringArray, qemuMonitorJSONAttachCharDev)
(qemuMonitorJSONGetCPUx86Data, qemuMonitorJSONGetIOThreads)
(qemuMonitorJSONGetMemoryDeviceInfo): Use shorter idioms.
Signed-off-by: Eric Blake <eblake@redhat.com>
2015-06-20 19:40:21 +00:00
|
|
|
if (!(client = virJSONValueObjectGetObject(data, "client"))) {
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_WARN("missing client info in VNC event");
|
Add domain events for graphics network clients
This introduces a new event type
VIR_DOMAIN_EVENT_ID_GRAPHICS
The same event can be emitted in 3 scenarios
typedef enum {
VIR_DOMAIN_EVENT_GRAPHICS_CONNECT = 0,
VIR_DOMAIN_EVENT_GRAPHICS_INITIALIZE,
VIR_DOMAIN_EVENT_GRAPHICS_DISCONNECT,
} virDomainEventGraphicsPhase;
Connect/disconnect are triggered at socket accept/close.
The initialize phase is immediately after the protocol
setup and authentication has completed. ie when the
client is authorized and about to start interacting with
the graphical desktop
This event comes with *a lot* of potential information
- IP address, port & address family of client
- IP address, port & address family of server
- Authentication scheme (arbitrary string)
- Authenticated subject identity. A subject may have
multiple identities with some authentication schemes.
For example, vencrypt+sasl results in a x509dname
and saslUsername identities.
This results in a very complicated callback :-(
typedef enum {
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV4,
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV6,
} virDomainEventGraphicsAddressType;
struct _virDomainEventGraphicsAddress {
int family;
const char *node;
const char *service;
};
typedef struct _virDomainEventGraphicsAddress virDomainEventGraphicsAddress;
typedef virDomainEventGraphicsAddress *virDomainEventGraphicsAddressPtr;
struct _virDomainEventGraphicsSubject {
int nidentity;
struct {
const char *type;
const char *name;
} *identities;
};
typedef struct _virDomainEventGraphicsSubject virDomainEventGraphicsSubject;
typedef virDomainEventGraphicsSubject *virDomainEventGraphicsSubjectPtr;
typedef void (*virConnectDomainEventGraphicsCallback)(virConnectPtr conn,
virDomainPtr dom,
int phase,
virDomainEventGraphicsAddressPtr local,
virDomainEventGraphicsAddressPtr remote,
const char *authScheme,
virDomainEventGraphicsSubjectPtr subject,
void *opaque);
The wire protocol is similarly complex
struct remote_domain_event_graphics_address {
int family;
remote_nonnull_string node;
remote_nonnull_string service;
};
const REMOTE_DOMAIN_EVENT_GRAPHICS_IDENTITY_MAX = 20;
struct remote_domain_event_graphics_identity {
remote_nonnull_string type;
remote_nonnull_string name;
};
struct remote_domain_event_graphics_msg {
remote_nonnull_domain dom;
int phase;
remote_domain_event_graphics_address local;
remote_domain_event_graphics_address remote;
remote_nonnull_string authScheme;
remote_domain_event_graphics_identity subject<REMOTE_DOMAIN_EVENT_GRAPHICS_IDENTITY_MAX>;
};
This is currently implemented in QEMU for the VNC graphics
protocol, but designed to be usable with SPICE graphics in
the future too.
* daemon/remote.c: Dispatch graphics events to client
* examples/domain-events/events-c/event-test.c: Watch for
graphics events
* include/libvirt/libvirt.h.in: Define new graphics event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle graphics events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for VNC events and emit a libvirt graphics event
* src/remote/remote_driver.c: Receive and dispatch graphics
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
graphics events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for VNC_CONNECTED,
VNC_INITIALIZED & VNC_DISCONNETED events from QEMU monitor
2010-03-19 13:27:45 +00:00
|
|
|
return;
|
|
|
|
}
|
qemu: simplify json parsing
Rather than grabbing an arbitrary JSON value and then checking
if it has the right type, we might as well request the correct
type to begin with.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONIOProcessEvent)
(qemuMonitorJSONCommandWithFd, qemuMonitorJSONHandleGraphics)
(qemuMonitorJSONGetStatus, qemuMonitorJSONExtractCPUInfo)
(qemuMonitorJSONGetVirtType, qemuMonitorJSONGetBalloonInfo)
(qemuMonitorJSONGetMemoryStats)
(qemuMonitorJSONDevGetBlockExtent)
(qemuMonitorJSONGetOneBlockStatsInfo)
(qemuMonitorJSONGetAllBlockStatsInfo)
(qemuMonitorJSONBlockStatsUpdateCapacityOne)
(qemuMonitorJSONBlockStatsUpdateCapacity)
(qemuMonitorJSONGetBlockExtent)
(qemuMonitorJSONGetMigrationStatusReply)
(qemuMonitorJSONGetDumpGuestMemoryCapability)
(qemuMonitorJSONAddFd, qemuMonitorJSONQueryRxFilterParse)
(qemuMonitorJSONExtractChardevInfo)
(qemuMonitorJSONDiskNameLookupOne)
(qemuMonitorJSONDiskNameLookup)
(qemuMonitorJSONGetAllBlockJobInfo)
(qemuMonitorJSONBlockIoThrottleInfo, qemuMonitorJSONGetVersion)
(qemuMonitorJSONGetMachines, qemuMonitorJSONGetCPUDefinitions)
(qemuMonitorJSONGetCommands, qemuMonitorJSONGetEvents)
(qemuMonitorJSONGetKVMState, qemuMonitorJSONGetObjectTypes)
(qemuMonitorJSONGetObjectListPaths)
(qemuMonitorJSONGetObjectProps, qemuMonitorJSONGetTargetArch)
(qemuMonitorJSONGetMigrationCapabilities)
(qemuMonitorJSONGetStringArray, qemuMonitorJSONAttachCharDev)
(qemuMonitorJSONGetCPUx86Data, qemuMonitorJSONGetIOThreads)
(qemuMonitorJSONGetMemoryDeviceInfo): Use shorter idioms.
Signed-off-by: Eric Blake <eblake@redhat.com>
2015-06-20 19:40:21 +00:00
|
|
|
if (!(server = virJSONValueObjectGetObject(data, "server"))) {
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_WARN("missing server info in VNC event");
|
Add domain events for graphics network clients
This introduces a new event type
VIR_DOMAIN_EVENT_ID_GRAPHICS
The same event can be emitted in 3 scenarios
typedef enum {
VIR_DOMAIN_EVENT_GRAPHICS_CONNECT = 0,
VIR_DOMAIN_EVENT_GRAPHICS_INITIALIZE,
VIR_DOMAIN_EVENT_GRAPHICS_DISCONNECT,
} virDomainEventGraphicsPhase;
Connect/disconnect are triggered at socket accept/close.
The initialize phase is immediately after the protocol
setup and authentication has completed. ie when the
client is authorized and about to start interacting with
the graphical desktop
This event comes with *a lot* of potential information
- IP address, port & address family of client
- IP address, port & address family of server
- Authentication scheme (arbitrary string)
- Authenticated subject identity. A subject may have
multiple identities with some authentication schemes.
For example, vencrypt+sasl results in a x509dname
and saslUsername identities.
This results in a very complicated callback :-(
typedef enum {
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV4,
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV6,
} virDomainEventGraphicsAddressType;
struct _virDomainEventGraphicsAddress {
int family;
const char *node;
const char *service;
};
typedef struct _virDomainEventGraphicsAddress virDomainEventGraphicsAddress;
typedef virDomainEventGraphicsAddress *virDomainEventGraphicsAddressPtr;
struct _virDomainEventGraphicsSubject {
int nidentity;
struct {
const char *type;
const char *name;
} *identities;
};
typedef struct _virDomainEventGraphicsSubject virDomainEventGraphicsSubject;
typedef virDomainEventGraphicsSubject *virDomainEventGraphicsSubjectPtr;
typedef void (*virConnectDomainEventGraphicsCallback)(virConnectPtr conn,
virDomainPtr dom,
int phase,
virDomainEventGraphicsAddressPtr local,
virDomainEventGraphicsAddressPtr remote,
const char *authScheme,
virDomainEventGraphicsSubjectPtr subject,
void *opaque);
The wire protocol is similarly complex
struct remote_domain_event_graphics_address {
int family;
remote_nonnull_string node;
remote_nonnull_string service;
};
const REMOTE_DOMAIN_EVENT_GRAPHICS_IDENTITY_MAX = 20;
struct remote_domain_event_graphics_identity {
remote_nonnull_string type;
remote_nonnull_string name;
};
struct remote_domain_event_graphics_msg {
remote_nonnull_domain dom;
int phase;
remote_domain_event_graphics_address local;
remote_domain_event_graphics_address remote;
remote_nonnull_string authScheme;
remote_domain_event_graphics_identity subject<REMOTE_DOMAIN_EVENT_GRAPHICS_IDENTITY_MAX>;
};
This is currently implemented in QEMU for the VNC graphics
protocol, but designed to be usable with SPICE graphics in
the future too.
* daemon/remote.c: Dispatch graphics events to client
* examples/domain-events/events-c/event-test.c: Watch for
graphics events
* include/libvirt/libvirt.h.in: Define new graphics event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle graphics events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for VNC events and emit a libvirt graphics event
* src/remote/remote_driver.c: Receive and dispatch graphics
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
graphics events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for VNC_CONNECTED,
VNC_INITIALIZED & VNC_DISCONNETED events from QEMU monitor
2010-03-19 13:27:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-06-29 15:03:14 +00:00
|
|
|
if (!(authScheme = virJSONValueObjectGetString(server, "auth"))) {
|
2012-09-04 14:52:47 +00:00
|
|
|
/* not all events are required to contain auth scheme */
|
2015-06-29 15:03:14 +00:00
|
|
|
VIR_DEBUG("missing auth scheme in VNC event");
|
2012-09-04 14:52:47 +00:00
|
|
|
authScheme = "";
|
2012-03-14 05:41:35 +00:00
|
|
|
}
|
Add domain events for graphics network clients
This introduces a new event type
VIR_DOMAIN_EVENT_ID_GRAPHICS
The same event can be emitted in 3 scenarios
typedef enum {
VIR_DOMAIN_EVENT_GRAPHICS_CONNECT = 0,
VIR_DOMAIN_EVENT_GRAPHICS_INITIALIZE,
VIR_DOMAIN_EVENT_GRAPHICS_DISCONNECT,
} virDomainEventGraphicsPhase;
Connect/disconnect are triggered at socket accept/close.
The initialize phase is immediately after the protocol
setup and authentication has completed. ie when the
client is authorized and about to start interacting with
the graphical desktop
This event comes with *a lot* of potential information
- IP address, port & address family of client
- IP address, port & address family of server
- Authentication scheme (arbitrary string)
- Authenticated subject identity. A subject may have
multiple identities with some authentication schemes.
For example, vencrypt+sasl results in a x509dname
and saslUsername identities.
This results in a very complicated callback :-(
typedef enum {
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV4,
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV6,
} virDomainEventGraphicsAddressType;
struct _virDomainEventGraphicsAddress {
int family;
const char *node;
const char *service;
};
typedef struct _virDomainEventGraphicsAddress virDomainEventGraphicsAddress;
typedef virDomainEventGraphicsAddress *virDomainEventGraphicsAddressPtr;
struct _virDomainEventGraphicsSubject {
int nidentity;
struct {
const char *type;
const char *name;
} *identities;
};
typedef struct _virDomainEventGraphicsSubject virDomainEventGraphicsSubject;
typedef virDomainEventGraphicsSubject *virDomainEventGraphicsSubjectPtr;
typedef void (*virConnectDomainEventGraphicsCallback)(virConnectPtr conn,
virDomainPtr dom,
int phase,
virDomainEventGraphicsAddressPtr local,
virDomainEventGraphicsAddressPtr remote,
const char *authScheme,
virDomainEventGraphicsSubjectPtr subject,
void *opaque);
The wire protocol is similarly complex
struct remote_domain_event_graphics_address {
int family;
remote_nonnull_string node;
remote_nonnull_string service;
};
const REMOTE_DOMAIN_EVENT_GRAPHICS_IDENTITY_MAX = 20;
struct remote_domain_event_graphics_identity {
remote_nonnull_string type;
remote_nonnull_string name;
};
struct remote_domain_event_graphics_msg {
remote_nonnull_domain dom;
int phase;
remote_domain_event_graphics_address local;
remote_domain_event_graphics_address remote;
remote_nonnull_string authScheme;
remote_domain_event_graphics_identity subject<REMOTE_DOMAIN_EVENT_GRAPHICS_IDENTITY_MAX>;
};
This is currently implemented in QEMU for the VNC graphics
protocol, but designed to be usable with SPICE graphics in
the future too.
* daemon/remote.c: Dispatch graphics events to client
* examples/domain-events/events-c/event-test.c: Watch for
graphics events
* include/libvirt/libvirt.h.in: Define new graphics event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle graphics events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for VNC events and emit a libvirt graphics event
* src/remote/remote_driver.c: Receive and dispatch graphics
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
graphics events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for VNC_CONNECTED,
VNC_INITIALIZED & VNC_DISCONNETED events from QEMU monitor
2010-03-19 13:27:45 +00:00
|
|
|
|
2015-06-29 15:03:14 +00:00
|
|
|
if (!(localFamily = virJSONValueObjectGetString(server, "family"))) {
|
|
|
|
VIR_WARN("missing local address family in VNC event");
|
2012-03-14 05:41:35 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-06-29 15:03:14 +00:00
|
|
|
if (!(localNode = virJSONValueObjectGetString(server, "host"))) {
|
|
|
|
VIR_WARN("missing local hostname in VNC event");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!(localService = virJSONValueObjectGetString(server, "service"))) {
|
|
|
|
VIR_WARN("missing local service in VNC event");
|
2012-03-14 05:41:35 +00:00
|
|
|
return;
|
|
|
|
}
|
Add domain events for graphics network clients
This introduces a new event type
VIR_DOMAIN_EVENT_ID_GRAPHICS
The same event can be emitted in 3 scenarios
typedef enum {
VIR_DOMAIN_EVENT_GRAPHICS_CONNECT = 0,
VIR_DOMAIN_EVENT_GRAPHICS_INITIALIZE,
VIR_DOMAIN_EVENT_GRAPHICS_DISCONNECT,
} virDomainEventGraphicsPhase;
Connect/disconnect are triggered at socket accept/close.
The initialize phase is immediately after the protocol
setup and authentication has completed. ie when the
client is authorized and about to start interacting with
the graphical desktop
This event comes with *a lot* of potential information
- IP address, port & address family of client
- IP address, port & address family of server
- Authentication scheme (arbitrary string)
- Authenticated subject identity. A subject may have
multiple identities with some authentication schemes.
For example, vencrypt+sasl results in a x509dname
and saslUsername identities.
This results in a very complicated callback :-(
typedef enum {
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV4,
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV6,
} virDomainEventGraphicsAddressType;
struct _virDomainEventGraphicsAddress {
int family;
const char *node;
const char *service;
};
typedef struct _virDomainEventGraphicsAddress virDomainEventGraphicsAddress;
typedef virDomainEventGraphicsAddress *virDomainEventGraphicsAddressPtr;
struct _virDomainEventGraphicsSubject {
int nidentity;
struct {
const char *type;
const char *name;
} *identities;
};
typedef struct _virDomainEventGraphicsSubject virDomainEventGraphicsSubject;
typedef virDomainEventGraphicsSubject *virDomainEventGraphicsSubjectPtr;
typedef void (*virConnectDomainEventGraphicsCallback)(virConnectPtr conn,
virDomainPtr dom,
int phase,
virDomainEventGraphicsAddressPtr local,
virDomainEventGraphicsAddressPtr remote,
const char *authScheme,
virDomainEventGraphicsSubjectPtr subject,
void *opaque);
The wire protocol is similarly complex
struct remote_domain_event_graphics_address {
int family;
remote_nonnull_string node;
remote_nonnull_string service;
};
const REMOTE_DOMAIN_EVENT_GRAPHICS_IDENTITY_MAX = 20;
struct remote_domain_event_graphics_identity {
remote_nonnull_string type;
remote_nonnull_string name;
};
struct remote_domain_event_graphics_msg {
remote_nonnull_domain dom;
int phase;
remote_domain_event_graphics_address local;
remote_domain_event_graphics_address remote;
remote_nonnull_string authScheme;
remote_domain_event_graphics_identity subject<REMOTE_DOMAIN_EVENT_GRAPHICS_IDENTITY_MAX>;
};
This is currently implemented in QEMU for the VNC graphics
protocol, but designed to be usable with SPICE graphics in
the future too.
* daemon/remote.c: Dispatch graphics events to client
* examples/domain-events/events-c/event-test.c: Watch for
graphics events
* include/libvirt/libvirt.h.in: Define new graphics event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle graphics events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for VNC events and emit a libvirt graphics event
* src/remote/remote_driver.c: Receive and dispatch graphics
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
graphics events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for VNC_CONNECTED,
VNC_INITIALIZED & VNC_DISCONNETED events from QEMU monitor
2010-03-19 13:27:45 +00:00
|
|
|
|
2015-06-29 15:03:14 +00:00
|
|
|
if (!(remoteFamily = virJSONValueObjectGetString(client, "family"))) {
|
|
|
|
VIR_WARN("missing remote address family in VNC event");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!(remoteNode = virJSONValueObjectGetString(client, "host"))) {
|
|
|
|
VIR_WARN("missing remote hostname in VNC event");
|
2012-03-14 05:41:35 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-06-29 15:03:14 +00:00
|
|
|
if (!(remoteService = virJSONValueObjectGetString(client, "service"))) {
|
|
|
|
VIR_WARN("missing remote service in VNC event");
|
2012-03-14 05:41:35 +00:00
|
|
|
return;
|
|
|
|
}
|
Add domain events for graphics network clients
This introduces a new event type
VIR_DOMAIN_EVENT_ID_GRAPHICS
The same event can be emitted in 3 scenarios
typedef enum {
VIR_DOMAIN_EVENT_GRAPHICS_CONNECT = 0,
VIR_DOMAIN_EVENT_GRAPHICS_INITIALIZE,
VIR_DOMAIN_EVENT_GRAPHICS_DISCONNECT,
} virDomainEventGraphicsPhase;
Connect/disconnect are triggered at socket accept/close.
The initialize phase is immediately after the protocol
setup and authentication has completed. ie when the
client is authorized and about to start interacting with
the graphical desktop
This event comes with *a lot* of potential information
- IP address, port & address family of client
- IP address, port & address family of server
- Authentication scheme (arbitrary string)
- Authenticated subject identity. A subject may have
multiple identities with some authentication schemes.
For example, vencrypt+sasl results in a x509dname
and saslUsername identities.
This results in a very complicated callback :-(
typedef enum {
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV4,
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV6,
} virDomainEventGraphicsAddressType;
struct _virDomainEventGraphicsAddress {
int family;
const char *node;
const char *service;
};
typedef struct _virDomainEventGraphicsAddress virDomainEventGraphicsAddress;
typedef virDomainEventGraphicsAddress *virDomainEventGraphicsAddressPtr;
struct _virDomainEventGraphicsSubject {
int nidentity;
struct {
const char *type;
const char *name;
} *identities;
};
typedef struct _virDomainEventGraphicsSubject virDomainEventGraphicsSubject;
typedef virDomainEventGraphicsSubject *virDomainEventGraphicsSubjectPtr;
typedef void (*virConnectDomainEventGraphicsCallback)(virConnectPtr conn,
virDomainPtr dom,
int phase,
virDomainEventGraphicsAddressPtr local,
virDomainEventGraphicsAddressPtr remote,
const char *authScheme,
virDomainEventGraphicsSubjectPtr subject,
void *opaque);
The wire protocol is similarly complex
struct remote_domain_event_graphics_address {
int family;
remote_nonnull_string node;
remote_nonnull_string service;
};
const REMOTE_DOMAIN_EVENT_GRAPHICS_IDENTITY_MAX = 20;
struct remote_domain_event_graphics_identity {
remote_nonnull_string type;
remote_nonnull_string name;
};
struct remote_domain_event_graphics_msg {
remote_nonnull_domain dom;
int phase;
remote_domain_event_graphics_address local;
remote_domain_event_graphics_address remote;
remote_nonnull_string authScheme;
remote_domain_event_graphics_identity subject<REMOTE_DOMAIN_EVENT_GRAPHICS_IDENTITY_MAX>;
};
This is currently implemented in QEMU for the VNC graphics
protocol, but designed to be usable with SPICE graphics in
the future too.
* daemon/remote.c: Dispatch graphics events to client
* examples/domain-events/events-c/event-test.c: Watch for
graphics events
* include/libvirt/libvirt.h.in: Define new graphics event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle graphics events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for VNC events and emit a libvirt graphics event
* src/remote/remote_driver.c: Receive and dispatch graphics
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
graphics events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for VNC_CONNECTED,
VNC_INITIALIZED & VNC_DISCONNETED events from QEMU monitor
2010-03-19 13:27:45 +00:00
|
|
|
|
|
|
|
saslUsername = virJSONValueObjectGetString(client, "sasl_username");
|
|
|
|
x509dname = virJSONValueObjectGetString(client, "x509_dname");
|
|
|
|
|
|
|
|
if ((localFamilyID = qemuMonitorGraphicsAddressFamilyTypeFromString(localFamily)) < 0) {
|
|
|
|
VIR_WARN("unknown address family '%s'", localFamily);
|
|
|
|
localFamilyID = VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV4;
|
|
|
|
}
|
|
|
|
if ((remoteFamilyID = qemuMonitorGraphicsAddressFamilyTypeFromString(remoteFamily)) < 0) {
|
|
|
|
VIR_WARN("unknown address family '%s'", remoteFamily);
|
|
|
|
remoteFamilyID = VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV4;
|
|
|
|
}
|
|
|
|
|
|
|
|
qemuMonitorEmitGraphics(mon, phase,
|
|
|
|
localFamilyID, localNode, localService,
|
|
|
|
remoteFamilyID, remoteNode, remoteService,
|
|
|
|
authScheme, x509dname, saslUsername);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void qemuMonitorJSONHandleVNCConnect(qemuMonitorPtr mon, virJSONValuePtr data)
|
|
|
|
{
|
2015-06-29 14:10:51 +00:00
|
|
|
qemuMonitorJSONHandleGraphicsVNC(mon, data, VIR_DOMAIN_EVENT_GRAPHICS_CONNECT);
|
Add domain events for graphics network clients
This introduces a new event type
VIR_DOMAIN_EVENT_ID_GRAPHICS
The same event can be emitted in 3 scenarios
typedef enum {
VIR_DOMAIN_EVENT_GRAPHICS_CONNECT = 0,
VIR_DOMAIN_EVENT_GRAPHICS_INITIALIZE,
VIR_DOMAIN_EVENT_GRAPHICS_DISCONNECT,
} virDomainEventGraphicsPhase;
Connect/disconnect are triggered at socket accept/close.
The initialize phase is immediately after the protocol
setup and authentication has completed. ie when the
client is authorized and about to start interacting with
the graphical desktop
This event comes with *a lot* of potential information
- IP address, port & address family of client
- IP address, port & address family of server
- Authentication scheme (arbitrary string)
- Authenticated subject identity. A subject may have
multiple identities with some authentication schemes.
For example, vencrypt+sasl results in a x509dname
and saslUsername identities.
This results in a very complicated callback :-(
typedef enum {
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV4,
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV6,
} virDomainEventGraphicsAddressType;
struct _virDomainEventGraphicsAddress {
int family;
const char *node;
const char *service;
};
typedef struct _virDomainEventGraphicsAddress virDomainEventGraphicsAddress;
typedef virDomainEventGraphicsAddress *virDomainEventGraphicsAddressPtr;
struct _virDomainEventGraphicsSubject {
int nidentity;
struct {
const char *type;
const char *name;
} *identities;
};
typedef struct _virDomainEventGraphicsSubject virDomainEventGraphicsSubject;
typedef virDomainEventGraphicsSubject *virDomainEventGraphicsSubjectPtr;
typedef void (*virConnectDomainEventGraphicsCallback)(virConnectPtr conn,
virDomainPtr dom,
int phase,
virDomainEventGraphicsAddressPtr local,
virDomainEventGraphicsAddressPtr remote,
const char *authScheme,
virDomainEventGraphicsSubjectPtr subject,
void *opaque);
The wire protocol is similarly complex
struct remote_domain_event_graphics_address {
int family;
remote_nonnull_string node;
remote_nonnull_string service;
};
const REMOTE_DOMAIN_EVENT_GRAPHICS_IDENTITY_MAX = 20;
struct remote_domain_event_graphics_identity {
remote_nonnull_string type;
remote_nonnull_string name;
};
struct remote_domain_event_graphics_msg {
remote_nonnull_domain dom;
int phase;
remote_domain_event_graphics_address local;
remote_domain_event_graphics_address remote;
remote_nonnull_string authScheme;
remote_domain_event_graphics_identity subject<REMOTE_DOMAIN_EVENT_GRAPHICS_IDENTITY_MAX>;
};
This is currently implemented in QEMU for the VNC graphics
protocol, but designed to be usable with SPICE graphics in
the future too.
* daemon/remote.c: Dispatch graphics events to client
* examples/domain-events/events-c/event-test.c: Watch for
graphics events
* include/libvirt/libvirt.h.in: Define new graphics event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle graphics events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for VNC events and emit a libvirt graphics event
* src/remote/remote_driver.c: Receive and dispatch graphics
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
graphics events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for VNC_CONNECTED,
VNC_INITIALIZED & VNC_DISCONNETED events from QEMU monitor
2010-03-19 13:27:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void qemuMonitorJSONHandleVNCInitialize(qemuMonitorPtr mon, virJSONValuePtr data)
|
|
|
|
{
|
2015-06-29 14:10:51 +00:00
|
|
|
qemuMonitorJSONHandleGraphicsVNC(mon, data, VIR_DOMAIN_EVENT_GRAPHICS_INITIALIZE);
|
Add domain events for graphics network clients
This introduces a new event type
VIR_DOMAIN_EVENT_ID_GRAPHICS
The same event can be emitted in 3 scenarios
typedef enum {
VIR_DOMAIN_EVENT_GRAPHICS_CONNECT = 0,
VIR_DOMAIN_EVENT_GRAPHICS_INITIALIZE,
VIR_DOMAIN_EVENT_GRAPHICS_DISCONNECT,
} virDomainEventGraphicsPhase;
Connect/disconnect are triggered at socket accept/close.
The initialize phase is immediately after the protocol
setup and authentication has completed. ie when the
client is authorized and about to start interacting with
the graphical desktop
This event comes with *a lot* of potential information
- IP address, port & address family of client
- IP address, port & address family of server
- Authentication scheme (arbitrary string)
- Authenticated subject identity. A subject may have
multiple identities with some authentication schemes.
For example, vencrypt+sasl results in a x509dname
and saslUsername identities.
This results in a very complicated callback :-(
typedef enum {
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV4,
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV6,
} virDomainEventGraphicsAddressType;
struct _virDomainEventGraphicsAddress {
int family;
const char *node;
const char *service;
};
typedef struct _virDomainEventGraphicsAddress virDomainEventGraphicsAddress;
typedef virDomainEventGraphicsAddress *virDomainEventGraphicsAddressPtr;
struct _virDomainEventGraphicsSubject {
int nidentity;
struct {
const char *type;
const char *name;
} *identities;
};
typedef struct _virDomainEventGraphicsSubject virDomainEventGraphicsSubject;
typedef virDomainEventGraphicsSubject *virDomainEventGraphicsSubjectPtr;
typedef void (*virConnectDomainEventGraphicsCallback)(virConnectPtr conn,
virDomainPtr dom,
int phase,
virDomainEventGraphicsAddressPtr local,
virDomainEventGraphicsAddressPtr remote,
const char *authScheme,
virDomainEventGraphicsSubjectPtr subject,
void *opaque);
The wire protocol is similarly complex
struct remote_domain_event_graphics_address {
int family;
remote_nonnull_string node;
remote_nonnull_string service;
};
const REMOTE_DOMAIN_EVENT_GRAPHICS_IDENTITY_MAX = 20;
struct remote_domain_event_graphics_identity {
remote_nonnull_string type;
remote_nonnull_string name;
};
struct remote_domain_event_graphics_msg {
remote_nonnull_domain dom;
int phase;
remote_domain_event_graphics_address local;
remote_domain_event_graphics_address remote;
remote_nonnull_string authScheme;
remote_domain_event_graphics_identity subject<REMOTE_DOMAIN_EVENT_GRAPHICS_IDENTITY_MAX>;
};
This is currently implemented in QEMU for the VNC graphics
protocol, but designed to be usable with SPICE graphics in
the future too.
* daemon/remote.c: Dispatch graphics events to client
* examples/domain-events/events-c/event-test.c: Watch for
graphics events
* include/libvirt/libvirt.h.in: Define new graphics event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle graphics events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for VNC events and emit a libvirt graphics event
* src/remote/remote_driver.c: Receive and dispatch graphics
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
graphics events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for VNC_CONNECTED,
VNC_INITIALIZED & VNC_DISCONNETED events from QEMU monitor
2010-03-19 13:27:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void qemuMonitorJSONHandleVNCDisconnect(qemuMonitorPtr mon, virJSONValuePtr data)
|
|
|
|
{
|
2015-06-29 14:10:51 +00:00
|
|
|
qemuMonitorJSONHandleGraphicsVNC(mon, data, VIR_DOMAIN_EVENT_GRAPHICS_DISCONNECT);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
qemuMonitorJSONHandleGraphicsSPICE(qemuMonitorPtr mon,
|
|
|
|
virJSONValuePtr data,
|
|
|
|
int phase)
|
|
|
|
{
|
|
|
|
const char *lhost, *lport, *lfamily;
|
|
|
|
const char *rhost, *rport, *rfamily;
|
|
|
|
const char *auth = "";
|
|
|
|
int lfamilyID, rfamilyID;
|
|
|
|
virJSONValuePtr client;
|
|
|
|
virJSONValuePtr server;
|
|
|
|
|
|
|
|
if (!(client = virJSONValueObjectGetObject(data, "client")) ||
|
|
|
|
!(server = virJSONValueObjectGetObject(data, "server"))) {
|
|
|
|
VIR_WARN("missing server or client info in SPICE event");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (phase == VIR_DOMAIN_EVENT_GRAPHICS_INITIALIZE &&
|
|
|
|
!(auth = virJSONValueObjectGetString(server, "auth"))) {
|
|
|
|
VIR_DEBUG("missing auth scheme in SPICE event");
|
|
|
|
auth = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(lfamily = virJSONValueObjectGetString(server, "family"))) {
|
|
|
|
VIR_WARN("missing local address family in SPICE event");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!(lhost = virJSONValueObjectGetString(server, "host"))) {
|
|
|
|
VIR_WARN("missing local hostname in SPICE event");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!(lport = virJSONValueObjectGetString(server, "port"))) {
|
|
|
|
VIR_WARN("missing local port in SPICE event");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(rfamily = virJSONValueObjectGetString(client, "family"))) {
|
|
|
|
VIR_WARN("missing remote address family in SPICE event");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!(rhost = virJSONValueObjectGetString(client, "host"))) {
|
|
|
|
VIR_WARN("missing remote hostname in SPICE event");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!(rport = virJSONValueObjectGetString(client, "port"))) {
|
|
|
|
VIR_WARN("missing remote service in SPICE event");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((lfamilyID = qemuMonitorGraphicsAddressFamilyTypeFromString(lfamily)) < 0) {
|
|
|
|
VIR_WARN("unknown address family '%s'", lfamily);
|
|
|
|
lfamilyID = VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV4;
|
|
|
|
}
|
|
|
|
if ((rfamilyID = qemuMonitorGraphicsAddressFamilyTypeFromString(rfamily)) < 0) {
|
|
|
|
VIR_WARN("unknown address family '%s'", rfamily);
|
|
|
|
rfamilyID = VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV4;
|
|
|
|
}
|
|
|
|
|
|
|
|
qemuMonitorEmitGraphics(mon, phase, lfamilyID, lhost, lport, rfamilyID,
|
|
|
|
rhost, rport, auth, NULL, NULL);
|
2012-03-14 05:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void qemuMonitorJSONHandleSPICEConnect(qemuMonitorPtr mon, virJSONValuePtr data)
|
|
|
|
{
|
2015-06-29 14:10:51 +00:00
|
|
|
qemuMonitorJSONHandleGraphicsSPICE(mon, data, VIR_DOMAIN_EVENT_GRAPHICS_CONNECT);
|
2012-03-14 05:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void qemuMonitorJSONHandleSPICEInitialize(qemuMonitorPtr mon, virJSONValuePtr data)
|
|
|
|
{
|
2015-06-29 14:10:51 +00:00
|
|
|
qemuMonitorJSONHandleGraphicsSPICE(mon, data, VIR_DOMAIN_EVENT_GRAPHICS_INITIALIZE);
|
2012-03-14 05:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void qemuMonitorJSONHandleSPICEDisconnect(qemuMonitorPtr mon, virJSONValuePtr data)
|
|
|
|
{
|
2015-06-29 14:10:51 +00:00
|
|
|
qemuMonitorJSONHandleGraphicsSPICE(mon, data, VIR_DOMAIN_EVENT_GRAPHICS_DISCONNECT);
|
Add domain events for graphics network clients
This introduces a new event type
VIR_DOMAIN_EVENT_ID_GRAPHICS
The same event can be emitted in 3 scenarios
typedef enum {
VIR_DOMAIN_EVENT_GRAPHICS_CONNECT = 0,
VIR_DOMAIN_EVENT_GRAPHICS_INITIALIZE,
VIR_DOMAIN_EVENT_GRAPHICS_DISCONNECT,
} virDomainEventGraphicsPhase;
Connect/disconnect are triggered at socket accept/close.
The initialize phase is immediately after the protocol
setup and authentication has completed. ie when the
client is authorized and about to start interacting with
the graphical desktop
This event comes with *a lot* of potential information
- IP address, port & address family of client
- IP address, port & address family of server
- Authentication scheme (arbitrary string)
- Authenticated subject identity. A subject may have
multiple identities with some authentication schemes.
For example, vencrypt+sasl results in a x509dname
and saslUsername identities.
This results in a very complicated callback :-(
typedef enum {
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV4,
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV6,
} virDomainEventGraphicsAddressType;
struct _virDomainEventGraphicsAddress {
int family;
const char *node;
const char *service;
};
typedef struct _virDomainEventGraphicsAddress virDomainEventGraphicsAddress;
typedef virDomainEventGraphicsAddress *virDomainEventGraphicsAddressPtr;
struct _virDomainEventGraphicsSubject {
int nidentity;
struct {
const char *type;
const char *name;
} *identities;
};
typedef struct _virDomainEventGraphicsSubject virDomainEventGraphicsSubject;
typedef virDomainEventGraphicsSubject *virDomainEventGraphicsSubjectPtr;
typedef void (*virConnectDomainEventGraphicsCallback)(virConnectPtr conn,
virDomainPtr dom,
int phase,
virDomainEventGraphicsAddressPtr local,
virDomainEventGraphicsAddressPtr remote,
const char *authScheme,
virDomainEventGraphicsSubjectPtr subject,
void *opaque);
The wire protocol is similarly complex
struct remote_domain_event_graphics_address {
int family;
remote_nonnull_string node;
remote_nonnull_string service;
};
const REMOTE_DOMAIN_EVENT_GRAPHICS_IDENTITY_MAX = 20;
struct remote_domain_event_graphics_identity {
remote_nonnull_string type;
remote_nonnull_string name;
};
struct remote_domain_event_graphics_msg {
remote_nonnull_domain dom;
int phase;
remote_domain_event_graphics_address local;
remote_domain_event_graphics_address remote;
remote_nonnull_string authScheme;
remote_domain_event_graphics_identity subject<REMOTE_DOMAIN_EVENT_GRAPHICS_IDENTITY_MAX>;
};
This is currently implemented in QEMU for the VNC graphics
protocol, but designed to be usable with SPICE graphics in
the future too.
* daemon/remote.c: Dispatch graphics events to client
* examples/domain-events/events-c/event-test.c: Watch for
graphics events
* include/libvirt/libvirt.h.in: Define new graphics event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle graphics events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for VNC events and emit a libvirt graphics event
* src/remote/remote_driver.c: Receive and dispatch graphics
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
graphics events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for VNC_CONNECTED,
VNC_INITIALIZED & VNC_DISCONNETED events from QEMU monitor
2010-03-19 13:27:45 +00:00
|
|
|
}
|
|
|
|
|
2012-04-11 22:17:36 +00:00
|
|
|
static void
|
|
|
|
qemuMonitorJSONHandleBlockJobImpl(qemuMonitorPtr mon,
|
|
|
|
virJSONValuePtr data,
|
|
|
|
int event)
|
2011-07-22 05:57:42 +00:00
|
|
|
{
|
|
|
|
const char *device;
|
|
|
|
const char *type_str;
|
|
|
|
int type = VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN;
|
|
|
|
unsigned long long offset, len;
|
|
|
|
|
|
|
|
if ((device = virJSONValueObjectGetString(data, "device")) == NULL) {
|
|
|
|
VIR_WARN("missing device in block job event");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virJSONValueObjectGetNumberUlong(data, "offset", &offset) < 0) {
|
|
|
|
VIR_WARN("missing offset in block job event");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virJSONValueObjectGetNumberUlong(data, "len", &len) < 0) {
|
|
|
|
VIR_WARN("missing len in block job event");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((type_str = virJSONValueObjectGetString(data, "type")) == NULL) {
|
|
|
|
VIR_WARN("missing type in block job event");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (STREQ(type_str, "stream"))
|
|
|
|
type = VIR_DOMAIN_BLOCK_JOB_TYPE_PULL;
|
2012-10-03 21:13:21 +00:00
|
|
|
else if (STREQ(type_str, "commit"))
|
|
|
|
type = VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT;
|
2012-10-12 20:06:10 +00:00
|
|
|
else if (STREQ(type_str, "mirror"))
|
|
|
|
type = VIR_DOMAIN_BLOCK_JOB_TYPE_COPY;
|
2011-07-22 05:57:42 +00:00
|
|
|
|
2012-04-11 22:17:36 +00:00
|
|
|
switch ((virConnectDomainEventBlockJobStatus) event) {
|
|
|
|
case VIR_DOMAIN_BLOCK_JOB_COMPLETED:
|
|
|
|
/* Make sure the whole device has been processed */
|
|
|
|
if (offset != len)
|
|
|
|
event = VIR_DOMAIN_BLOCK_JOB_FAILED;
|
|
|
|
break;
|
|
|
|
case VIR_DOMAIN_BLOCK_JOB_CANCELED:
|
2012-10-12 20:06:10 +00:00
|
|
|
case VIR_DOMAIN_BLOCK_JOB_READY:
|
2012-04-11 22:17:36 +00:00
|
|
|
break;
|
|
|
|
case VIR_DOMAIN_BLOCK_JOB_FAILED:
|
|
|
|
case VIR_DOMAIN_BLOCK_JOB_LAST:
|
2012-10-12 20:06:10 +00:00
|
|
|
VIR_DEBUG("should not get here");
|
|
|
|
break;
|
2012-04-11 22:17:36 +00:00
|
|
|
}
|
2011-07-22 05:57:42 +00:00
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
out:
|
2012-04-11 22:17:36 +00:00
|
|
|
qemuMonitorEmitBlockJob(mon, device, type, event);
|
2011-07-22 05:57:42 +00:00
|
|
|
}
|
|
|
|
|
2012-03-23 13:44:50 +00:00
|
|
|
static void
|
|
|
|
qemuMonitorJSONHandleTrayChange(qemuMonitorPtr mon,
|
|
|
|
virJSONValuePtr data)
|
|
|
|
{
|
|
|
|
const char *devAlias = NULL;
|
|
|
|
bool trayOpened;
|
|
|
|
int reason;
|
|
|
|
|
|
|
|
if ((devAlias = virJSONValueObjectGetString(data, "device")) == NULL) {
|
|
|
|
VIR_WARN("missing device in tray change event");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virJSONValueObjectGetBoolean(data, "tray-open", &trayOpened) < 0) {
|
|
|
|
VIR_WARN("missing tray-open in tray change event");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (trayOpened)
|
|
|
|
reason = VIR_DOMAIN_EVENT_TRAY_CHANGE_OPEN;
|
|
|
|
else
|
|
|
|
reason = VIR_DOMAIN_EVENT_TRAY_CHANGE_CLOSE;
|
|
|
|
|
|
|
|
qemuMonitorEmitTrayChange(mon, devAlias, reason);
|
|
|
|
}
|
Add domain events for graphics network clients
This introduces a new event type
VIR_DOMAIN_EVENT_ID_GRAPHICS
The same event can be emitted in 3 scenarios
typedef enum {
VIR_DOMAIN_EVENT_GRAPHICS_CONNECT = 0,
VIR_DOMAIN_EVENT_GRAPHICS_INITIALIZE,
VIR_DOMAIN_EVENT_GRAPHICS_DISCONNECT,
} virDomainEventGraphicsPhase;
Connect/disconnect are triggered at socket accept/close.
The initialize phase is immediately after the protocol
setup and authentication has completed. ie when the
client is authorized and about to start interacting with
the graphical desktop
This event comes with *a lot* of potential information
- IP address, port & address family of client
- IP address, port & address family of server
- Authentication scheme (arbitrary string)
- Authenticated subject identity. A subject may have
multiple identities with some authentication schemes.
For example, vencrypt+sasl results in a x509dname
and saslUsername identities.
This results in a very complicated callback :-(
typedef enum {
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV4,
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_IPV6,
} virDomainEventGraphicsAddressType;
struct _virDomainEventGraphicsAddress {
int family;
const char *node;
const char *service;
};
typedef struct _virDomainEventGraphicsAddress virDomainEventGraphicsAddress;
typedef virDomainEventGraphicsAddress *virDomainEventGraphicsAddressPtr;
struct _virDomainEventGraphicsSubject {
int nidentity;
struct {
const char *type;
const char *name;
} *identities;
};
typedef struct _virDomainEventGraphicsSubject virDomainEventGraphicsSubject;
typedef virDomainEventGraphicsSubject *virDomainEventGraphicsSubjectPtr;
typedef void (*virConnectDomainEventGraphicsCallback)(virConnectPtr conn,
virDomainPtr dom,
int phase,
virDomainEventGraphicsAddressPtr local,
virDomainEventGraphicsAddressPtr remote,
const char *authScheme,
virDomainEventGraphicsSubjectPtr subject,
void *opaque);
The wire protocol is similarly complex
struct remote_domain_event_graphics_address {
int family;
remote_nonnull_string node;
remote_nonnull_string service;
};
const REMOTE_DOMAIN_EVENT_GRAPHICS_IDENTITY_MAX = 20;
struct remote_domain_event_graphics_identity {
remote_nonnull_string type;
remote_nonnull_string name;
};
struct remote_domain_event_graphics_msg {
remote_nonnull_domain dom;
int phase;
remote_domain_event_graphics_address local;
remote_domain_event_graphics_address remote;
remote_nonnull_string authScheme;
remote_domain_event_graphics_identity subject<REMOTE_DOMAIN_EVENT_GRAPHICS_IDENTITY_MAX>;
};
This is currently implemented in QEMU for the VNC graphics
protocol, but designed to be usable with SPICE graphics in
the future too.
* daemon/remote.c: Dispatch graphics events to client
* examples/domain-events/events-c/event-test.c: Watch for
graphics events
* include/libvirt/libvirt.h.in: Define new graphics event ID
and callback signature
* src/conf/domain_event.c, src/conf/domain_event.h,
src/libvirt_private.syms: Extend API to handle graphics events
* src/qemu/qemu_driver.c: Connect to the QEMU monitor event
for VNC events and emit a libvirt graphics event
* src/remote/remote_driver.c: Receive and dispatch graphics
events to application
* src/remote/remote_protocol.x: Wire protocol definition for
graphics events
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c: Watch for VNC_CONNECTED,
VNC_INITIALIZED & VNC_DISCONNETED events from QEMU monitor
2010-03-19 13:27:45 +00:00
|
|
|
|
2012-03-23 14:43:14 +00:00
|
|
|
static void
|
|
|
|
qemuMonitorJSONHandlePMWakeup(qemuMonitorPtr mon,
|
|
|
|
virJSONValuePtr data ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
qemuMonitorEmitPMWakeup(mon);
|
|
|
|
}
|
|
|
|
|
2012-03-23 14:50:36 +00:00
|
|
|
static void
|
|
|
|
qemuMonitorJSONHandlePMSuspend(qemuMonitorPtr mon,
|
|
|
|
virJSONValuePtr data ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
qemuMonitorEmitPMSuspend(mon);
|
|
|
|
}
|
|
|
|
|
2012-04-11 22:17:36 +00:00
|
|
|
static void
|
|
|
|
qemuMonitorJSONHandleBlockJobCompleted(qemuMonitorPtr mon,
|
|
|
|
virJSONValuePtr data)
|
|
|
|
{
|
|
|
|
qemuMonitorJSONHandleBlockJobImpl(mon, data,
|
|
|
|
VIR_DOMAIN_BLOCK_JOB_COMPLETED);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
qemuMonitorJSONHandleBlockJobCanceled(qemuMonitorPtr mon,
|
|
|
|
virJSONValuePtr data)
|
|
|
|
{
|
|
|
|
qemuMonitorJSONHandleBlockJobImpl(mon, data,
|
|
|
|
VIR_DOMAIN_BLOCK_JOB_CANCELED);
|
|
|
|
}
|
|
|
|
|
2012-10-12 20:06:10 +00:00
|
|
|
static void
|
|
|
|
qemuMonitorJSONHandleBlockJobReady(qemuMonitorPtr mon,
|
|
|
|
virJSONValuePtr data)
|
|
|
|
{
|
|
|
|
qemuMonitorJSONHandleBlockJobImpl(mon, data,
|
|
|
|
VIR_DOMAIN_BLOCK_JOB_READY);
|
|
|
|
}
|
|
|
|
|
2012-07-12 15:45:57 +00:00
|
|
|
static void
|
|
|
|
qemuMonitorJSONHandleBalloonChange(qemuMonitorPtr mon,
|
|
|
|
virJSONValuePtr data)
|
|
|
|
{
|
|
|
|
unsigned long long actual = 0;
|
|
|
|
if (virJSONValueObjectGetNumberUlong(data, "actual", &actual) < 0) {
|
|
|
|
VIR_WARN("missing actual in balloon change event");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
actual = VIR_DIV_UP(actual, 1024);
|
|
|
|
qemuMonitorEmitBalloonChange(mon, actual);
|
|
|
|
}
|
|
|
|
|
2012-10-12 19:13:39 +00:00
|
|
|
static void
|
|
|
|
qemuMonitorJSONHandlePMSuspendDisk(qemuMonitorPtr mon,
|
|
|
|
virJSONValuePtr data ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
qemuMonitorEmitPMSuspendDisk(mon);
|
|
|
|
}
|
|
|
|
|
2013-07-11 15:07:26 +00:00
|
|
|
static void
|
|
|
|
qemuMonitorJSONHandleDeviceDeleted(qemuMonitorPtr mon, virJSONValuePtr data)
|
|
|
|
{
|
|
|
|
const char *device;
|
|
|
|
|
|
|
|
if (!(device = virJSONValueObjectGetString(data, "device"))) {
|
2016-09-02 12:52:15 +00:00
|
|
|
VIR_DEBUG("missing device in device deleted event");
|
2013-07-11 15:07:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qemuMonitorEmitDeviceDeleted(mon, device);
|
|
|
|
}
|
|
|
|
|
2014-09-17 17:07:50 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
qemuMonitorJSONHandleNicRxFilterChanged(qemuMonitorPtr mon, virJSONValuePtr data)
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
if (!(name = virJSONValueObjectGetString(data, "name"))) {
|
|
|
|
VIR_WARN("missing device in NIC_RX_FILTER_CHANGED event");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qemuMonitorEmitNicRxFilterChanged(mon, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-13 13:09:39 +00:00
|
|
|
static void
|
|
|
|
qemuMonitorJSONHandleSerialChange(qemuMonitorPtr mon,
|
|
|
|
virJSONValuePtr data)
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
bool connected;
|
|
|
|
|
|
|
|
if (!(name = virJSONValueObjectGetString(data, "id"))) {
|
|
|
|
VIR_WARN("missing device alias in VSERPORT_CHANGE event");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virJSONValueObjectGetBoolean(data, "open", &connected) < 0) {
|
|
|
|
VIR_WARN("missing port state for '%s' in VSERPORT_CHANGE event", name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qemuMonitorEmitSerialChange(mon, name, connected);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-28 11:35:06 +00:00
|
|
|
static void
|
|
|
|
qemuMonitorJSONHandleSpiceMigrated(qemuMonitorPtr mon,
|
|
|
|
virJSONValuePtr data ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
qemuMonitorEmitSpiceMigrated(mon);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-28 11:35:52 +00:00
|
|
|
static void
|
|
|
|
qemuMonitorJSONHandleMigrationStatus(qemuMonitorPtr mon,
|
|
|
|
virJSONValuePtr data)
|
|
|
|
{
|
|
|
|
const char *str;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
if (!(str = virJSONValueObjectGetString(data, "status"))) {
|
|
|
|
VIR_WARN("missing status in migration event");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((status = qemuMonitorMigrationStatusTypeFromString(str)) == -1) {
|
|
|
|
VIR_WARN("unknown status '%s' in migration event", str);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qemuMonitorEmitMigrationStatus(mon, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-08 14:23:35 +00:00
|
|
|
static void
|
|
|
|
qemuMonitorJSONHandleMigrationPass(qemuMonitorPtr mon,
|
|
|
|
virJSONValuePtr data)
|
|
|
|
{
|
|
|
|
int pass;
|
|
|
|
|
|
|
|
if (virJSONValueObjectGetNumberInt(data, "pass", &pass) < 0) {
|
|
|
|
VIR_WARN("missing dirty-sync-count in migration-pass event");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qemuMonitorEmitMigrationPass(mon, pass);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-01 14:41:08 +00:00
|
|
|
static void
|
|
|
|
qemuMonitorJSONHandleAcpiOstInfo(qemuMonitorPtr mon, virJSONValuePtr data)
|
|
|
|
{
|
|
|
|
virJSONValuePtr info;
|
|
|
|
const char *alias;
|
|
|
|
const char *slotType;
|
|
|
|
const char *slot;
|
|
|
|
unsigned int source;
|
|
|
|
unsigned int status;
|
|
|
|
|
|
|
|
if (!(info = virJSONValueObjectGetObject(data, "info")))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* optional */
|
|
|
|
alias = virJSONValueObjectGetString(info, "device");
|
|
|
|
|
|
|
|
if (!(slotType = virJSONValueObjectGetString(info, "slot-type")))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!(slot = virJSONValueObjectGetString(info, "slot")))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (virJSONValueObjectGetNumberUint(info, "source", &source) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (virJSONValueObjectGetNumberUint(info, "status", &status) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
qemuMonitorEmitAcpiOstInfo(mon, alias, slotType, slot, source, status);
|
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
|
|
|
VIR_WARN("malformed ACPI_DEVICE_OST event");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-22 15:52:22 +00:00
|
|
|
static void
|
|
|
|
qemuMonitorJSONHandleBlockThreshold(qemuMonitorPtr mon, virJSONValuePtr data)
|
|
|
|
{
|
|
|
|
const char *nodename;
|
|
|
|
unsigned long long threshold;
|
|
|
|
unsigned long long excess;
|
|
|
|
|
|
|
|
if (!(nodename = virJSONValueObjectGetString(data, "node-name")))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (virJSONValueObjectGetNumberUlong(data, "write-threshold", &threshold) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (virJSONValueObjectGetNumberUlong(data, "amount-exceeded", &excess) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
qemuMonitorEmitBlockThreshold(mon, nodename, threshold, excess);
|
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
|
|
|
VIR_WARN("malformed 'BLOCK_WRITE_THRESHOLD' event");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-09 20:24:04 +00:00
|
|
|
int
|
|
|
|
qemuMonitorJSONHumanCommandWithFd(qemuMonitorPtr mon,
|
|
|
|
const char *cmd_str,
|
|
|
|
int scm_fd,
|
|
|
|
char **reply_str)
|
|
|
|
{
|
|
|
|
virJSONValuePtr cmd = NULL;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
virJSONValuePtr obj;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
cmd = qemuMonitorJSONMakeCommand("human-monitor-command",
|
|
|
|
"s:command-line", cmd_str,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (!cmd || qemuMonitorJSONCommandWithFd(mon, cmd, scm_fd, &reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2012-09-06 15:28:53 +00:00
|
|
|
if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
|
|
|
|
_("Human monitor command is not available to run %s"),
|
|
|
|
cmd_str);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2011-03-09 20:24:04 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply))
|
|
|
|
goto cleanup;
|
|
|
|
|
2016-05-03 08:55:41 +00:00
|
|
|
obj = virJSONValueObjectGet(reply, "return");
|
2011-03-09 20:24:04 +00:00
|
|
|
|
|
|
|
if (reply_str) {
|
|
|
|
const char *data;
|
|
|
|
|
2013-05-20 09:23:13 +00:00
|
|
|
data = virJSONValueGetString(obj);
|
|
|
|
if (VIR_STRDUP(*reply_str, data ? data : "") < 0)
|
2011-03-09 20:24:04 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2011-03-09 20:24:04 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-12 13:45:20 +00:00
|
|
|
int
|
|
|
|
qemuMonitorJSONSetCapabilities(qemuMonitorPtr mon)
|
|
|
|
{
|
2016-05-03 09:29:11 +00:00
|
|
|
int ret = -1;
|
2010-02-12 13:45:20 +00:00
|
|
|
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("qmp_capabilities", NULL);
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2010-02-12 13:45:20 +00:00
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2010-02-12 13:45:20 +00:00
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2010-02-12 13:45:20 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
int
|
|
|
|
qemuMonitorJSONStartCPUs(qemuMonitorPtr mon,
|
|
|
|
virConnectPtr conn ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("cont", NULL);
|
|
|
|
virJSONValuePtr reply = NULL;
|
Convert 'int i' to 'size_t i' in src/qemu files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i = 0;
|
|
|
|
int timeout = 3;
|
2009-11-03 18:59:18 +00:00
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2011-01-13 19:52:23 +00:00
|
|
|
do {
|
|
|
|
ret = qemuMonitorJSONCommand(mon, cmd, &reply);
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2011-01-13 19:52:23 +00:00
|
|
|
if (ret != 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* If no error, we're done */
|
|
|
|
if ((ret = qemuMonitorJSONCheckError(cmd, reply)) == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* If error class is not MigrationExpected, we're done.
|
|
|
|
* Otherwise try 'cont' cmd again */
|
|
|
|
if (!qemuMonitorJSONHasError(reply, "MigrationExpected"))
|
|
|
|
break;
|
|
|
|
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
reply = NULL;
|
|
|
|
usleep(250000);
|
|
|
|
} while (++i <= timeout);
|
2009-11-03 18:59:18 +00:00
|
|
|
|
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
qemuMonitorJSONStopCPUs(qemuMonitorPtr mon)
|
|
|
|
{
|
2016-05-03 09:29:11 +00:00
|
|
|
int ret = -1;
|
2009-11-03 18:59:18 +00:00
|
|
|
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("stop", NULL);
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2009-11-03 18:59:18 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-05 11:50:25 +00:00
|
|
|
int
|
2011-09-27 09:42:04 +00:00
|
|
|
qemuMonitorJSONGetStatus(qemuMonitorPtr mon,
|
|
|
|
bool *running,
|
|
|
|
virDomainPausedReason *reason)
|
2011-05-05 11:50:25 +00:00
|
|
|
{
|
2016-05-03 09:29:11 +00:00
|
|
|
int ret = -1;
|
2011-09-27 09:42:04 +00:00
|
|
|
const char *status;
|
2011-05-05 11:50:25 +00:00
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
virJSONValuePtr data;
|
|
|
|
|
2011-09-27 09:42:04 +00:00
|
|
|
if (reason)
|
|
|
|
*reason = VIR_DOMAIN_PAUSED_UNKNOWN;
|
|
|
|
|
2011-05-05 11:50:25 +00:00
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("query-status", NULL)))
|
|
|
|
return -1;
|
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
2011-05-05 11:50:25 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2011-05-05 11:50:25 +00:00
|
|
|
|
2016-11-20 23:10:06 +00:00
|
|
|
data = virJSONValueObjectGetObject(reply, "return");
|
2011-05-05 11:50:25 +00:00
|
|
|
|
|
|
|
if (virJSONValueObjectGetBoolean(data, "running", running) < 0) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-status reply was missing running state"));
|
2011-05-05 11:50:25 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2011-09-27 09:42:04 +00:00
|
|
|
if ((status = virJSONValueObjectGetString(data, "status"))) {
|
|
|
|
if (!*running && reason)
|
|
|
|
*reason = qemuMonitorVMStatusToPausedReason(status);
|
|
|
|
} else if (!*running) {
|
|
|
|
VIR_DEBUG("query-status reply was missing status details");
|
|
|
|
}
|
|
|
|
|
2011-05-05 11:50:25 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2011-05-05 11:50:25 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
int qemuMonitorJSONSystemPowerdown(qemuMonitorPtr mon)
|
|
|
|
{
|
2016-05-03 09:29:11 +00:00
|
|
|
int ret = -1;
|
2009-11-03 18:59:18 +00:00
|
|
|
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("system_powerdown", NULL);
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2009-11-03 18:59:18 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-09-06 08:18:57 +00:00
|
|
|
int qemuMonitorJSONSetLink(qemuMonitorPtr mon,
|
|
|
|
const char *name,
|
2014-06-01 00:22:30 +00:00
|
|
|
virDomainNetInterfaceLinkState state)
|
2011-09-06 08:18:57 +00:00
|
|
|
{
|
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
int ret = -1;
|
2011-09-06 08:18:57 +00:00
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("set_link",
|
|
|
|
"s:name", name,
|
|
|
|
"b:up", state != VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DOWN,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2011-09-06 08:18:57 +00:00
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2011-09-06 08:18:57 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2011-06-15 16:49:58 +00:00
|
|
|
int qemuMonitorJSONSystemReset(qemuMonitorPtr mon)
|
|
|
|
{
|
2016-05-03 09:29:11 +00:00
|
|
|
int ret = -1;
|
2011-06-15 16:49:58 +00:00
|
|
|
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("system_reset", NULL);
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2011-06-15 16:49:58 +00:00
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2011-06-15 16:49:58 +00:00
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2011-06-15 16:49:58 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-22 14:52:05 +00:00
|
|
|
/*
|
2016-07-28 08:33:10 +00:00
|
|
|
*
|
|
|
|
* [{ "arch": "x86",
|
|
|
|
* "current": true,
|
|
|
|
* "CPU": 0,
|
|
|
|
* "qom_path": "/machine/unattached/device[0]",
|
|
|
|
* "pc": -2130415978,
|
|
|
|
* "halted": true,
|
|
|
|
* "thread_id": 2631237},
|
|
|
|
* {...}
|
|
|
|
* ]
|
2010-01-22 14:52:05 +00:00
|
|
|
*/
|
|
|
|
static int
|
2016-08-01 11:44:25 +00:00
|
|
|
qemuMonitorJSONExtractCPUInfo(virJSONValuePtr data,
|
|
|
|
struct qemuMonitorQueryCpusEntry **entries,
|
|
|
|
size_t *nentries)
|
2010-01-22 14:52:05 +00:00
|
|
|
{
|
2016-08-01 11:44:25 +00:00
|
|
|
struct qemuMonitorQueryCpusEntry *cpus = NULL;
|
2010-01-22 14:52:05 +00:00
|
|
|
int ret = -1;
|
Convert 'int i' to 'size_t i' in src/qemu files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2015-10-08 08:17:42 +00:00
|
|
|
ssize_t ncpus;
|
2010-01-22 14:52:05 +00:00
|
|
|
|
2016-08-01 11:44:25 +00:00
|
|
|
if ((ncpus = virJSONValueArraySize(data)) <= 0)
|
|
|
|
return -2;
|
2010-01-22 14:52:05 +00:00
|
|
|
|
2016-08-01 11:44:25 +00:00
|
|
|
if (VIR_ALLOC_N(cpus, ncpus) < 0)
|
2010-01-22 14:52:05 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-05-21 07:21:20 +00:00
|
|
|
for (i = 0; i < ncpus; i++) {
|
2010-01-22 14:52:05 +00:00
|
|
|
virJSONValuePtr entry = virJSONValueArrayGet(data, i);
|
2016-11-21 13:57:54 +00:00
|
|
|
int cpuid = -1;
|
2016-08-01 11:44:25 +00:00
|
|
|
int thread = 0;
|
2016-10-13 11:42:44 +00:00
|
|
|
bool halted = false;
|
2016-07-28 08:33:10 +00:00
|
|
|
const char *qom_path;
|
2010-01-22 14:52:05 +00:00
|
|
|
if (!entry) {
|
2016-08-01 11:44:25 +00:00
|
|
|
ret = -2;
|
2010-01-22 14:52:05 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2016-08-01 11:44:25 +00:00
|
|
|
/* Some older qemu versions don't report the thread_id so treat this as
|
|
|
|
* non-fatal, simply returning no data */
|
2016-11-21 13:57:54 +00:00
|
|
|
ignore_value(virJSONValueObjectGetNumberInt(entry, "CPU", &cpuid));
|
2016-08-01 11:44:25 +00:00
|
|
|
ignore_value(virJSONValueObjectGetNumberInt(entry, "thread_id", &thread));
|
2016-10-13 11:42:44 +00:00
|
|
|
ignore_value(virJSONValueObjectGetBoolean(entry, "halted", &halted));
|
2016-07-28 08:33:10 +00:00
|
|
|
qom_path = virJSONValueObjectGetString(entry, "qom_path");
|
2010-01-22 14:52:05 +00:00
|
|
|
|
2016-11-21 13:57:54 +00:00
|
|
|
cpus[i].qemu_id = cpuid;
|
2016-08-01 11:44:25 +00:00
|
|
|
cpus[i].tid = thread;
|
2016-10-13 11:42:44 +00:00
|
|
|
cpus[i].halted = halted;
|
2016-07-28 08:33:10 +00:00
|
|
|
if (VIR_STRDUP(cpus[i].qom_path, qom_path) < 0)
|
|
|
|
goto cleanup;
|
2010-01-22 14:52:05 +00:00
|
|
|
}
|
|
|
|
|
2016-08-01 11:44:25 +00:00
|
|
|
VIR_STEAL_PTR(*entries, cpus);
|
|
|
|
*nentries = ncpus;
|
|
|
|
ret = 0;
|
2010-01-22 14:52:05 +00:00
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2016-08-01 11:44:25 +00:00
|
|
|
qemuMonitorQueryCpusFree(cpus, ncpus);
|
2010-01-22 14:52:05 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-01 11:44:25 +00:00
|
|
|
/**
|
|
|
|
* qemuMonitorJSONQueryCPUs:
|
|
|
|
*
|
|
|
|
* @mon: monitor object
|
|
|
|
* @entries: filled with detected entries on success
|
|
|
|
* @nentries: number of entries returned
|
|
|
|
*
|
|
|
|
* Queries qemu for cpu-related information. Failure to execute the command or
|
|
|
|
* extract results does not produce an error as libvirt can continue without
|
|
|
|
* this information.
|
|
|
|
*
|
2017-04-22 19:06:20 +00:00
|
|
|
* Returns 0 on success, -1 on a fatal error (oom ...) and -2 if the
|
2016-08-01 11:44:25 +00:00
|
|
|
* query failed gracefully.
|
|
|
|
*/
|
2016-07-08 13:36:27 +00:00
|
|
|
int
|
|
|
|
qemuMonitorJSONQueryCPUs(qemuMonitorPtr mon,
|
2016-08-01 11:44:25 +00:00
|
|
|
struct qemuMonitorQueryCpusEntry **entries,
|
2016-12-04 17:53:03 +00:00
|
|
|
size_t *nentries,
|
|
|
|
bool force)
|
2009-11-03 18:59:18 +00:00
|
|
|
{
|
2016-05-03 09:29:11 +00:00
|
|
|
int ret = -1;
|
2016-08-01 11:44:25 +00:00
|
|
|
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("query-cpus", NULL);
|
2009-11-03 18:59:18 +00:00
|
|
|
virJSONValuePtr reply = NULL;
|
2016-08-01 11:44:25 +00:00
|
|
|
virJSONValuePtr data;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2016-12-04 17:53:03 +00:00
|
|
|
if (force && qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2016-08-01 11:44:25 +00:00
|
|
|
if (!(data = virJSONValueObjectGetArray(reply, "return"))) {
|
|
|
|
ret = -2;
|
2016-05-03 09:29:11 +00:00
|
|
|
goto cleanup;
|
2016-08-01 11:44:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = qemuMonitorJSONExtractCPUInfo(data, entries, nentries);
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
cleanup:
|
2009-11-03 18:59:18 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-17 14:31:45 +00:00
|
|
|
int qemuMonitorJSONGetVirtType(qemuMonitorPtr mon,
|
2015-09-17 08:46:56 +00:00
|
|
|
virDomainVirtType *virtType)
|
2011-06-17 14:31:45 +00:00
|
|
|
{
|
2016-05-03 09:29:11 +00:00
|
|
|
int ret = -1;
|
2011-06-17 14:31:45 +00:00
|
|
|
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("query-kvm",
|
|
|
|
NULL);
|
|
|
|
virJSONValuePtr reply = NULL;
|
2016-05-03 09:29:11 +00:00
|
|
|
virJSONValuePtr data;
|
|
|
|
bool val = false;
|
2011-06-17 14:31:45 +00:00
|
|
|
|
|
|
|
*virtType = VIR_DOMAIN_VIRT_QEMU;
|
|
|
|
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2011-06-17 14:31:45 +00:00
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2011-06-17 14:31:45 +00:00
|
|
|
|
2016-11-20 23:10:06 +00:00
|
|
|
data = virJSONValueObjectGetObject(reply, "return");
|
2011-06-17 14:31:45 +00:00
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
if (virJSONValueObjectGetBoolean(data, "enabled", &val) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("info kvm reply missing 'enabled' field"));
|
|
|
|
goto cleanup;
|
2011-06-17 14:31:45 +00:00
|
|
|
}
|
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
if (val)
|
|
|
|
*virtType = VIR_DOMAIN_VIRT_KVM;
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2011-06-17 14:31:45 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-10 14:31:23 +00:00
|
|
|
/**
|
|
|
|
* Loads correct video memory size values from QEMU and update the video
|
|
|
|
* definition.
|
|
|
|
*
|
|
|
|
* Return 0 on success, -1 on failure and set proper error message.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
qemuMonitorJSONUpdateVideoMemorySize(qemuMonitorPtr mon,
|
|
|
|
virDomainVideoDefPtr video,
|
|
|
|
char *path)
|
|
|
|
{
|
|
|
|
qemuMonitorJSONObjectProperty prop = {
|
|
|
|
QEMU_MONITOR_OBJECT_PROPERTY_ULONG,
|
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
|
|
|
switch (video->type) {
|
|
|
|
case VIR_DOMAIN_VIDEO_TYPE_VGA:
|
|
|
|
if (qemuMonitorJSONGetObjectProperty(mon, path, "vgamem_mb", &prop) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
2015-02-25 13:12:33 +00:00
|
|
|
_("QOM Object '%s' has no property 'vgamem_mb'"),
|
2014-12-10 14:31:23 +00:00
|
|
|
path);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
video->vram = prop.val.ul * 1024;
|
|
|
|
break;
|
|
|
|
case VIR_DOMAIN_VIDEO_TYPE_QXL:
|
|
|
|
if (qemuMonitorJSONGetObjectProperty(mon, path, "vram_size", &prop) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
2015-02-25 13:12:33 +00:00
|
|
|
_("QOM Object '%s' has no property 'vram_size'"),
|
2014-12-10 14:31:23 +00:00
|
|
|
path);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
video->vram = prop.val.ul / 1024;
|
2016-02-23 16:04:19 +00:00
|
|
|
|
2014-12-10 14:31:23 +00:00
|
|
|
if (qemuMonitorJSONGetObjectProperty(mon, path, "ram_size", &prop) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
2015-02-25 13:12:33 +00:00
|
|
|
_("QOM Object '%s' has no property 'ram_size'"),
|
2014-12-10 14:31:23 +00:00
|
|
|
path);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
video->ram = prop.val.ul / 1024;
|
|
|
|
if (qemuMonitorJSONGetObjectProperty(mon, path, "vgamem_mb", &prop) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
2015-02-25 13:12:33 +00:00
|
|
|
_("QOM Object '%s' has no property 'vgamem_mb'"),
|
2014-12-10 14:31:23 +00:00
|
|
|
path);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
video->vgamem = prop.val.ul * 1024;
|
|
|
|
break;
|
|
|
|
case VIR_DOMAIN_VIDEO_TYPE_VMVGA:
|
|
|
|
if (qemuMonitorJSONGetObjectProperty(mon, path, "vgamem_mb", &prop) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
2015-02-25 13:12:33 +00:00
|
|
|
_("QOM Object '%s' has no property 'vgamem_mb'"),
|
2014-12-10 14:31:23 +00:00
|
|
|
path);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
video->vram = prop.val.ul * 1024;
|
|
|
|
break;
|
|
|
|
case VIR_DOMAIN_VIDEO_TYPE_CIRRUS:
|
|
|
|
case VIR_DOMAIN_VIDEO_TYPE_XEN:
|
|
|
|
case VIR_DOMAIN_VIDEO_TYPE_VBOX:
|
|
|
|
case VIR_DOMAIN_VIDEO_TYPE_LAST:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-02-23 16:04:19 +00:00
|
|
|
/**
|
|
|
|
* Loads correct video vram64 size value from QEMU and update the video
|
|
|
|
* definition.
|
|
|
|
*
|
|
|
|
* Return 0 on success, -1 on failure and set proper error message.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
qemuMonitorJSONUpdateVideoVram64Size(qemuMonitorPtr mon,
|
|
|
|
virDomainVideoDefPtr video,
|
|
|
|
char *path)
|
|
|
|
{
|
|
|
|
qemuMonitorJSONObjectProperty prop = {
|
|
|
|
QEMU_MONITOR_OBJECT_PROPERTY_ULONG,
|
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
|
|
|
switch (video->type) {
|
|
|
|
case VIR_DOMAIN_VIDEO_TYPE_QXL:
|
|
|
|
if (video->vram64 != 0) {
|
|
|
|
if (qemuMonitorJSONGetObjectProperty(mon, path,
|
|
|
|
"vram64_size_mb", &prop) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("QOM Object '%s' has no property 'vram64_size_mb'"),
|
|
|
|
path);
|
|
|
|
return -1;
|
|
|
|
}
|
2016-04-13 08:13:16 +00:00
|
|
|
video->vram64 = prop.val.ul * 1024;
|
2016-02-23 16:04:19 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case VIR_DOMAIN_VIDEO_TYPE_VGA:
|
|
|
|
case VIR_DOMAIN_VIDEO_TYPE_VMVGA:
|
|
|
|
case VIR_DOMAIN_VIDEO_TYPE_CIRRUS:
|
|
|
|
case VIR_DOMAIN_VIDEO_TYPE_XEN:
|
|
|
|
case VIR_DOMAIN_VIDEO_TYPE_VBOX:
|
|
|
|
case VIR_DOMAIN_VIDEO_TYPE_LAST:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-27 11:42:32 +00:00
|
|
|
int
|
|
|
|
qemuMonitorJSONGetBalloonInfo(qemuMonitorPtr mon,
|
|
|
|
unsigned long long *currmem)
|
2009-11-03 18:59:18 +00:00
|
|
|
{
|
2016-05-03 09:29:11 +00:00
|
|
|
int ret = -1;
|
|
|
|
virJSONValuePtr data;
|
|
|
|
unsigned long long mem;
|
2009-11-03 18:59:18 +00:00
|
|
|
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("query-balloon",
|
|
|
|
NULL);
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
|
|
|
|
*currmem = 0;
|
|
|
|
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
/* See if balloon soft-failed */
|
|
|
|
if (qemuMonitorJSONHasError(reply, "DeviceNotActive") ||
|
|
|
|
qemuMonitorJSONHasError(reply, "KVMMissingCap")) {
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
/* See if any other fatal error occurred */
|
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2010-01-22 13:22:53 +00:00
|
|
|
|
2016-11-20 23:10:06 +00:00
|
|
|
data = virJSONValueObjectGetObject(reply, "return");
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
if (virJSONValueObjectGetNumberUlong(data, "actual", &mem) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("info balloon reply was missing balloon data"));
|
|
|
|
goto cleanup;
|
2009-11-03 18:59:18 +00:00
|
|
|
}
|
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
*currmem = (mem/1024);
|
|
|
|
ret = 1;
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2009-11-03 18:59:18 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-11 23:18:48 +00:00
|
|
|
/* Process the balloon driver statistics. The request and data returned
|
|
|
|
* will be as follows (although the 'child[#]' entry will differ based on
|
|
|
|
* where it's run).
|
|
|
|
*
|
|
|
|
* { "execute": "qom-get","arguments": \
|
|
|
|
* { "path": "/machine/i440fx/pci.0/child[7]","property": "guest-stats"} }
|
|
|
|
*
|
|
|
|
* {"return": {"stats": \
|
|
|
|
* {"stat-swap-out": 0,
|
|
|
|
* "stat-free-memory": 686350336,
|
|
|
|
* "stat-minor-faults": 697283,
|
|
|
|
* "stat-major-faults": 951,
|
|
|
|
* "stat-total-memory": 1019924480,
|
|
|
|
* "stat-swap-in": 0},
|
|
|
|
* "last-update": 1371221540}}
|
|
|
|
*
|
|
|
|
* A value in "stats" can be -1 indicating it's never been collected/stored.
|
|
|
|
* The 'last-update' value could be used in the future in order to determine
|
|
|
|
* rates and/or whether data has been collected since a previous cycle.
|
|
|
|
* It's currently unused.
|
|
|
|
*/
|
2016-06-01 17:07:07 +00:00
|
|
|
#define GET_BALLOON_STATS(OBJECT, FIELD, TAG, DIVISOR) \
|
|
|
|
if (virJSONValueObjectHasKey(OBJECT, FIELD) && \
|
2013-07-11 23:18:48 +00:00
|
|
|
(got < nr_stats)) { \
|
2016-06-01 17:07:07 +00:00
|
|
|
if (virJSONValueObjectGetNumberUlong(OBJECT, FIELD, &mem) < 0) { \
|
2013-07-11 23:18:48 +00:00
|
|
|
VIR_DEBUG("Failed to get '%s' value", FIELD); \
|
|
|
|
} else { \
|
|
|
|
/* Not being collected? No point in providing bad data */ \
|
|
|
|
if (mem != -1UL) { \
|
|
|
|
stats[got].tag = TAG; \
|
|
|
|
stats[got].val = mem / DIVISOR; \
|
|
|
|
got++; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-12 11:31:15 +00:00
|
|
|
int qemuMonitorJSONGetMemoryStats(qemuMonitorPtr mon,
|
2013-07-11 23:18:48 +00:00
|
|
|
char *balloonpath,
|
2010-04-12 11:31:15 +00:00
|
|
|
virDomainMemoryStatPtr stats,
|
|
|
|
unsigned int nr_stats)
|
|
|
|
{
|
2016-05-03 09:29:11 +00:00
|
|
|
int ret = -1;
|
2013-07-11 23:18:48 +00:00
|
|
|
virJSONValuePtr cmd = NULL;
|
2010-04-12 11:31:15 +00:00
|
|
|
virJSONValuePtr reply = NULL;
|
2013-07-11 23:18:48 +00:00
|
|
|
virJSONValuePtr data;
|
|
|
|
virJSONValuePtr statsdata;
|
|
|
|
unsigned long long mem;
|
|
|
|
int got = 0;
|
2010-04-12 11:31:15 +00:00
|
|
|
|
2013-07-11 23:18:48 +00:00
|
|
|
ret = qemuMonitorJSONGetBalloonInfo(mon, &mem);
|
|
|
|
if (ret == 1 && (got < nr_stats)) {
|
|
|
|
stats[got].tag = VIR_DOMAIN_MEMORY_STAT_ACTUAL_BALLOON;
|
|
|
|
stats[got].val = mem;
|
|
|
|
got++;
|
|
|
|
}
|
2010-04-12 11:31:15 +00:00
|
|
|
|
2013-07-11 23:18:48 +00:00
|
|
|
if (!balloonpath)
|
|
|
|
goto cleanup;
|
2010-04-12 11:31:15 +00:00
|
|
|
|
2013-07-11 23:18:48 +00:00
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("qom-get",
|
|
|
|
"s:path", balloonpath,
|
|
|
|
"s:property", "guest-stats",
|
|
|
|
NULL)))
|
|
|
|
goto cleanup;
|
2010-04-12 11:31:15 +00:00
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
2014-05-14 07:35:18 +00:00
|
|
|
goto cleanup;
|
2010-04-12 11:31:15 +00:00
|
|
|
|
qemu: simplify json parsing
Rather than grabbing an arbitrary JSON value and then checking
if it has the right type, we might as well request the correct
type to begin with.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONIOProcessEvent)
(qemuMonitorJSONCommandWithFd, qemuMonitorJSONHandleGraphics)
(qemuMonitorJSONGetStatus, qemuMonitorJSONExtractCPUInfo)
(qemuMonitorJSONGetVirtType, qemuMonitorJSONGetBalloonInfo)
(qemuMonitorJSONGetMemoryStats)
(qemuMonitorJSONDevGetBlockExtent)
(qemuMonitorJSONGetOneBlockStatsInfo)
(qemuMonitorJSONGetAllBlockStatsInfo)
(qemuMonitorJSONBlockStatsUpdateCapacityOne)
(qemuMonitorJSONBlockStatsUpdateCapacity)
(qemuMonitorJSONGetBlockExtent)
(qemuMonitorJSONGetMigrationStatusReply)
(qemuMonitorJSONGetDumpGuestMemoryCapability)
(qemuMonitorJSONAddFd, qemuMonitorJSONQueryRxFilterParse)
(qemuMonitorJSONExtractChardevInfo)
(qemuMonitorJSONDiskNameLookupOne)
(qemuMonitorJSONDiskNameLookup)
(qemuMonitorJSONGetAllBlockJobInfo)
(qemuMonitorJSONBlockIoThrottleInfo, qemuMonitorJSONGetVersion)
(qemuMonitorJSONGetMachines, qemuMonitorJSONGetCPUDefinitions)
(qemuMonitorJSONGetCommands, qemuMonitorJSONGetEvents)
(qemuMonitorJSONGetKVMState, qemuMonitorJSONGetObjectTypes)
(qemuMonitorJSONGetObjectListPaths)
(qemuMonitorJSONGetObjectProps, qemuMonitorJSONGetTargetArch)
(qemuMonitorJSONGetMigrationCapabilities)
(qemuMonitorJSONGetStringArray, qemuMonitorJSONAttachCharDev)
(qemuMonitorJSONGetCPUx86Data, qemuMonitorJSONGetIOThreads)
(qemuMonitorJSONGetMemoryDeviceInfo): Use shorter idioms.
Signed-off-by: Eric Blake <eblake@redhat.com>
2015-06-20 19:40:21 +00:00
|
|
|
if ((data = virJSONValueObjectGetObject(reply, "error"))) {
|
2014-05-14 07:35:18 +00:00
|
|
|
const char *klass = virJSONValueObjectGetString(data, "class");
|
|
|
|
const char *desc = virJSONValueObjectGetString(data, "desc");
|
2010-04-12 11:31:15 +00:00
|
|
|
|
2014-05-14 07:35:18 +00:00
|
|
|
if (STREQ_NULLABLE(klass, "GenericError") &&
|
|
|
|
STREQ_NULLABLE(desc, "guest hasn't updated any stats yet")) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
|
|
|
_("the guest hasn't updated any stats yet"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
2013-07-11 23:18:48 +00:00
|
|
|
goto cleanup;
|
2010-04-12 11:31:15 +00:00
|
|
|
|
2016-11-20 23:10:06 +00:00
|
|
|
data = virJSONValueObjectGetObject(reply, "return");
|
qemu: Parse current balloon value returned by query_balloon
Qemu once supported following memory stats which will returned by
"query_balloon":
stat_put(dict, "actual", actual);
stat_put(dict, "mem_swapped_in", dev->stats[VIRTIO_BALLOON_S_SWAP_IN]);
stat_put(dict, "mem_swapped_out", dev->stats[VIRTIO_BALLOON_S_SWAP_OUT]);
stat_put(dict, "major_page_faults", dev->stats[VIRTIO_BALLOON_S_MAJFLT]);
stat_put(dict, "minor_page_faults", dev->stats[VIRTIO_BALLOON_S_MINFLT]);
stat_put(dict, "free_mem", dev->stats[VIRTIO_BALLOON_S_MEMFREE]);
stat_put(dict, "total_mem", dev->stats[VIRTIO_BALLOON_S_MEMTOT]);
But it later disabled all the stats except "actual" by commit
07b0403dfc2b2ac179ae5b48105096cc2d03375a.
libvirt doesn't parse "actual", so user will always see a empty result
with "virsh dommemstat $domain". Even qemu haven't disabled the stats,
we should support parsing "actual".
2011-06-14 03:21:35 +00:00
|
|
|
|
2013-07-11 23:18:48 +00:00
|
|
|
if (!(statsdata = virJSONValueObjectGet(data, "stats"))) {
|
|
|
|
VIR_DEBUG("data does not include 'stats'");
|
|
|
|
goto cleanup;
|
2010-04-12 11:31:15 +00:00
|
|
|
}
|
|
|
|
|
2016-06-01 17:07:07 +00:00
|
|
|
GET_BALLOON_STATS(statsdata, "stat-swap-in",
|
2013-07-11 23:18:48 +00:00
|
|
|
VIR_DOMAIN_MEMORY_STAT_SWAP_IN, 1024);
|
2016-06-01 17:07:07 +00:00
|
|
|
GET_BALLOON_STATS(statsdata, "stat-swap-out",
|
2013-07-11 23:18:48 +00:00
|
|
|
VIR_DOMAIN_MEMORY_STAT_SWAP_OUT, 1024);
|
2016-06-01 17:07:07 +00:00
|
|
|
GET_BALLOON_STATS(statsdata, "stat-major-faults",
|
2013-07-11 23:18:48 +00:00
|
|
|
VIR_DOMAIN_MEMORY_STAT_MAJOR_FAULT, 1);
|
2016-06-01 17:07:07 +00:00
|
|
|
GET_BALLOON_STATS(statsdata, "stat-minor-faults",
|
2013-07-11 23:18:48 +00:00
|
|
|
VIR_DOMAIN_MEMORY_STAT_MINOR_FAULT, 1);
|
2016-06-01 17:07:07 +00:00
|
|
|
GET_BALLOON_STATS(statsdata, "stat-free-memory",
|
2013-07-11 23:18:48 +00:00
|
|
|
VIR_DOMAIN_MEMORY_STAT_UNUSED, 1024);
|
2016-06-01 17:07:07 +00:00
|
|
|
GET_BALLOON_STATS(statsdata, "stat-total-memory",
|
2013-07-11 23:18:48 +00:00
|
|
|
VIR_DOMAIN_MEMORY_STAT_AVAILABLE, 1024);
|
2016-06-01 17:07:07 +00:00
|
|
|
GET_BALLOON_STATS(statsdata, "stat-available-memory",
|
2016-06-01 17:07:06 +00:00
|
|
|
VIR_DOMAIN_MEMORY_STAT_USABLE, 1024);
|
2016-06-01 17:07:07 +00:00
|
|
|
GET_BALLOON_STATS(data, "last-update",
|
|
|
|
VIR_DOMAIN_MEMORY_STAT_LAST_UPDATE, 1);
|
2016-05-03 09:29:11 +00:00
|
|
|
ret = got;
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2010-04-12 11:31:15 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
2013-07-11 23:18:48 +00:00
|
|
|
#undef GET_BALLOON_STATS
|
2010-04-12 11:31:15 +00:00
|
|
|
|
|
|
|
|
2013-06-27 15:00:31 +00:00
|
|
|
/*
|
|
|
|
* Using the provided balloonpath, determine if we need to set the
|
|
|
|
* collection interval property to enable statistics gathering.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
qemuMonitorJSONSetMemoryStatsPeriod(qemuMonitorPtr mon,
|
|
|
|
char *balloonpath,
|
|
|
|
int period)
|
|
|
|
{
|
|
|
|
qemuMonitorJSONObjectProperty prop;
|
|
|
|
|
|
|
|
/* Set to the value in memballoon (could enable or disable) */
|
|
|
|
memset(&prop, 0, sizeof(qemuMonitorJSONObjectProperty));
|
|
|
|
prop.type = QEMU_MONITOR_OBJECT_PROPERTY_INT;
|
|
|
|
prop.val.iv = period;
|
|
|
|
if (qemuMonitorJSONSetObjectProperty(mon, balloonpath,
|
|
|
|
"guest-stats-polling-interval",
|
|
|
|
&prop) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-27 13:39:21 +00:00
|
|
|
/* qemuMonitorJSONQueryBlock:
|
|
|
|
* @mon: Monitor pointer
|
|
|
|
*
|
|
|
|
* This helper will attempt to make a "query-block" call and check for
|
|
|
|
* errors before returning with the reply.
|
|
|
|
*
|
|
|
|
* Returns: NULL on error, reply on success
|
|
|
|
*/
|
|
|
|
static virJSONValuePtr
|
|
|
|
qemuMonitorJSONQueryBlock(qemuMonitorPtr mon)
|
2011-09-13 13:49:50 +00:00
|
|
|
{
|
2016-09-27 13:39:21 +00:00
|
|
|
virJSONValuePtr cmd;
|
2011-09-13 13:49:50 +00:00
|
|
|
virJSONValuePtr reply = NULL;
|
2016-09-27 13:39:21 +00:00
|
|
|
virJSONValuePtr devices = NULL;
|
2011-09-13 13:49:50 +00:00
|
|
|
|
2016-09-27 13:39:21 +00:00
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("query-block", NULL)))
|
|
|
|
return NULL;
|
2011-09-13 13:49:50 +00:00
|
|
|
|
2016-09-27 13:39:21 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0 ||
|
|
|
|
qemuMonitorJSONCheckError(cmd, reply) < 0)
|
2016-05-03 09:29:11 +00:00
|
|
|
goto cleanup;
|
2011-09-13 13:49:50 +00:00
|
|
|
|
2016-09-27 13:39:21 +00:00
|
|
|
if (!(devices = virJSONValueObjectStealArray(reply, "return"))) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
2016-09-27 13:39:21 +00:00
|
|
|
_("query-block reply was missing device list"));
|
2011-09-13 13:49:50 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2016-09-27 13:39:21 +00:00
|
|
|
cleanup:
|
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return devices;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-03 18:58:59 +00:00
|
|
|
static virJSONValuePtr
|
|
|
|
qemuMonitorJSONGetBlockDev(virJSONValuePtr devices,
|
|
|
|
size_t idx)
|
|
|
|
{
|
|
|
|
virJSONValuePtr dev = virJSONValueArrayGet(devices, idx);
|
|
|
|
|
|
|
|
if (!dev || dev->type != VIR_JSON_TYPE_OBJECT) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-block device entry was not in expected format"));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-03 19:04:32 +00:00
|
|
|
static const char *
|
|
|
|
qemuMonitorJSONGetBlockDevDevice(virJSONValuePtr dev)
|
|
|
|
{
|
|
|
|
const char *thisdev;
|
|
|
|
|
|
|
|
if (!(thisdev = virJSONValueObjectGetString(dev, "device"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-block device entry was not in expected format"));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return thisdev;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-27 13:39:21 +00:00
|
|
|
int qemuMonitorJSONGetBlockInfo(qemuMonitorPtr mon,
|
|
|
|
virHashTablePtr table)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
virJSONValuePtr devices;
|
|
|
|
|
|
|
|
if (!(devices = qemuMonitorJSONQueryBlock(mon)))
|
|
|
|
return -1;
|
|
|
|
|
2011-09-13 13:49:50 +00:00
|
|
|
for (i = 0; i < virJSONValueArraySize(devices); i++) {
|
2016-10-03 18:58:59 +00:00
|
|
|
virJSONValuePtr dev;
|
2017-02-23 18:36:52 +00:00
|
|
|
virJSONValuePtr image;
|
2012-01-18 21:01:30 +00:00
|
|
|
struct qemuDomainDiskInfo *info;
|
2011-09-13 13:49:50 +00:00
|
|
|
const char *thisdev;
|
2012-01-19 16:58:58 +00:00
|
|
|
const char *status;
|
2017-02-23 18:36:52 +00:00
|
|
|
const char *nodename;
|
2011-09-13 13:49:50 +00:00
|
|
|
|
2016-10-03 18:58:59 +00:00
|
|
|
if (!(dev = qemuMonitorJSONGetBlockDev(devices, i)))
|
2011-09-13 13:49:50 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-10-03 19:04:32 +00:00
|
|
|
if (!(thisdev = qemuMonitorJSONGetBlockDevDevice(dev)))
|
2011-09-13 13:49:50 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-06-29 17:34:00 +00:00
|
|
|
thisdev = qemuAliasDiskDriveSkipPrefix(thisdev);
|
2011-09-13 13:49:50 +00:00
|
|
|
|
2013-07-04 10:14:12 +00:00
|
|
|
if (VIR_ALLOC(info) < 0)
|
2012-01-18 21:01:30 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virHashAddEntry(table, thisdev, info) < 0) {
|
|
|
|
VIR_FREE(info);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2011-09-13 13:49:50 +00:00
|
|
|
|
|
|
|
if (virJSONValueObjectGetBoolean(dev, "removable", &info->removable) < 0) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("cannot read %s value"),
|
|
|
|
"removable");
|
2011-09-13 13:49:50 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virJSONValueObjectGetBoolean(dev, "locked", &info->locked) < 0) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("cannot read %s value"),
|
|
|
|
"locked");
|
2011-09-13 13:49:50 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2016-05-19 12:57:41 +00:00
|
|
|
/* 'tray_open' is present only if the device has a tray */
|
|
|
|
if (virJSONValueObjectGetBoolean(dev, "tray_open", &info->tray_open) == 0)
|
|
|
|
info->tray = true;
|
|
|
|
|
|
|
|
/* presence of 'inserted' notifies that a medium is in the device */
|
2017-02-23 18:36:52 +00:00
|
|
|
if ((image = virJSONValueObjectGetObject(dev, "inserted"))) {
|
|
|
|
if ((nodename = virJSONValueObjectGetString(image, "node-name")))
|
|
|
|
ignore_value(VIR_STRDUP(info->nodename, nodename));
|
|
|
|
} else {
|
2016-05-19 12:57:41 +00:00
|
|
|
info->empty = true;
|
2017-02-23 18:36:52 +00:00
|
|
|
}
|
2012-01-19 16:58:58 +00:00
|
|
|
|
|
|
|
/* Missing io-status indicates no error */
|
|
|
|
if ((status = virJSONValueObjectGetString(dev, "io-status"))) {
|
|
|
|
info->io_status = qemuMonitorBlockIOStatusToError(status);
|
|
|
|
if (info->io_status < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2011-09-13 13:49:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2016-09-27 13:39:21 +00:00
|
|
|
virJSONValueFree(devices);
|
2011-09-13 13:49:50 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-11 22:28:41 +00:00
|
|
|
static int
|
|
|
|
qemuMonitorJSONGetOneBlockStatsInfo(virJSONValuePtr dev,
|
|
|
|
const char *dev_name,
|
2014-12-12 16:53:33 +00:00
|
|
|
int depth,
|
2014-12-11 22:28:41 +00:00
|
|
|
virHashTablePtr hash,
|
2014-12-12 16:53:33 +00:00
|
|
|
bool backingChain)
|
2014-12-11 22:28:41 +00:00
|
|
|
{
|
|
|
|
qemuBlockStatsPtr bstats = NULL;
|
|
|
|
virJSONValuePtr stats;
|
2015-06-23 14:58:07 +00:00
|
|
|
virJSONValuePtr parent;
|
|
|
|
virJSONValuePtr parentstats;
|
2014-12-11 22:28:41 +00:00
|
|
|
int ret = -1;
|
2015-03-10 13:40:58 +00:00
|
|
|
int nstats = 0;
|
2014-12-12 16:53:33 +00:00
|
|
|
char *entry_name = qemuDomainStorageAlias(dev_name, depth);
|
|
|
|
virJSONValuePtr backing;
|
2014-12-11 22:28:41 +00:00
|
|
|
|
2014-12-12 16:53:33 +00:00
|
|
|
if (!entry_name)
|
|
|
|
goto cleanup;
|
2014-12-11 22:28:41 +00:00
|
|
|
if (VIR_ALLOC(bstats) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
qemu: simplify json parsing
Rather than grabbing an arbitrary JSON value and then checking
if it has the right type, we might as well request the correct
type to begin with.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONIOProcessEvent)
(qemuMonitorJSONCommandWithFd, qemuMonitorJSONHandleGraphics)
(qemuMonitorJSONGetStatus, qemuMonitorJSONExtractCPUInfo)
(qemuMonitorJSONGetVirtType, qemuMonitorJSONGetBalloonInfo)
(qemuMonitorJSONGetMemoryStats)
(qemuMonitorJSONDevGetBlockExtent)
(qemuMonitorJSONGetOneBlockStatsInfo)
(qemuMonitorJSONGetAllBlockStatsInfo)
(qemuMonitorJSONBlockStatsUpdateCapacityOne)
(qemuMonitorJSONBlockStatsUpdateCapacity)
(qemuMonitorJSONGetBlockExtent)
(qemuMonitorJSONGetMigrationStatusReply)
(qemuMonitorJSONGetDumpGuestMemoryCapability)
(qemuMonitorJSONAddFd, qemuMonitorJSONQueryRxFilterParse)
(qemuMonitorJSONExtractChardevInfo)
(qemuMonitorJSONDiskNameLookupOne)
(qemuMonitorJSONDiskNameLookup)
(qemuMonitorJSONGetAllBlockJobInfo)
(qemuMonitorJSONBlockIoThrottleInfo, qemuMonitorJSONGetVersion)
(qemuMonitorJSONGetMachines, qemuMonitorJSONGetCPUDefinitions)
(qemuMonitorJSONGetCommands, qemuMonitorJSONGetEvents)
(qemuMonitorJSONGetKVMState, qemuMonitorJSONGetObjectTypes)
(qemuMonitorJSONGetObjectListPaths)
(qemuMonitorJSONGetObjectProps, qemuMonitorJSONGetTargetArch)
(qemuMonitorJSONGetMigrationCapabilities)
(qemuMonitorJSONGetStringArray, qemuMonitorJSONAttachCharDev)
(qemuMonitorJSONGetCPUx86Data, qemuMonitorJSONGetIOThreads)
(qemuMonitorJSONGetMemoryDeviceInfo): Use shorter idioms.
Signed-off-by: Eric Blake <eblake@redhat.com>
2015-06-20 19:40:21 +00:00
|
|
|
if ((stats = virJSONValueObjectGetObject(dev, "stats")) == NULL) {
|
2014-12-11 22:28:41 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("blockstats stats entry was not "
|
|
|
|
"in expected format"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2015-03-10 13:32:46 +00:00
|
|
|
#define QEMU_MONITOR_BLOCK_STAT_GET(NAME, VAR, MANDATORY) \
|
|
|
|
if (MANDATORY || virJSONValueObjectHasKey(stats, NAME)) { \
|
2015-03-10 13:40:58 +00:00
|
|
|
nstats++; \
|
2015-03-10 13:32:46 +00:00
|
|
|
if (virJSONValueObjectGetNumberLong(stats, NAME, &VAR) < 0) { \
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, \
|
|
|
|
_("cannot read %s statistic"), NAME); \
|
|
|
|
goto cleanup; \
|
|
|
|
} \
|
|
|
|
}
|
2015-06-23 13:11:17 +00:00
|
|
|
QEMU_MONITOR_BLOCK_STAT_GET("rd_bytes", bstats->rd_bytes, true);
|
|
|
|
QEMU_MONITOR_BLOCK_STAT_GET("wr_bytes", bstats->wr_bytes, true);
|
|
|
|
QEMU_MONITOR_BLOCK_STAT_GET("rd_operations", bstats->rd_req, true);
|
|
|
|
QEMU_MONITOR_BLOCK_STAT_GET("wr_operations", bstats->wr_req, true);
|
|
|
|
QEMU_MONITOR_BLOCK_STAT_GET("rd_total_time_ns", bstats->rd_total_times, false);
|
|
|
|
QEMU_MONITOR_BLOCK_STAT_GET("wr_total_time_ns", bstats->wr_total_times, false);
|
|
|
|
QEMU_MONITOR_BLOCK_STAT_GET("flush_operations", bstats->flush_req, false);
|
|
|
|
QEMU_MONITOR_BLOCK_STAT_GET("flush_total_time_ns", bstats->flush_total_times, false);
|
2015-03-10 13:32:46 +00:00
|
|
|
#undef QEMU_MONITOR_BLOCK_STAT_GET
|
2014-12-11 22:28:41 +00:00
|
|
|
|
2015-06-23 14:58:07 +00:00
|
|
|
if ((parent = virJSONValueObjectGetObject(dev, "parent")) &&
|
|
|
|
(parentstats = virJSONValueObjectGetObject(parent, "stats"))) {
|
|
|
|
if (virJSONValueObjectGetNumberUlong(parentstats, "wr_highest_offset",
|
|
|
|
&bstats->wr_highest_offset) == 0)
|
|
|
|
bstats->wr_highest_offset_valid = true;
|
|
|
|
}
|
2014-12-11 22:28:41 +00:00
|
|
|
|
2014-12-12 16:53:33 +00:00
|
|
|
if (virHashAddEntry(hash, entry_name, bstats) < 0)
|
2014-12-11 22:28:41 +00:00
|
|
|
goto cleanup;
|
|
|
|
bstats = NULL;
|
2014-12-12 16:53:33 +00:00
|
|
|
|
|
|
|
if (backingChain &&
|
qemu: simplify json parsing
Rather than grabbing an arbitrary JSON value and then checking
if it has the right type, we might as well request the correct
type to begin with.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONIOProcessEvent)
(qemuMonitorJSONCommandWithFd, qemuMonitorJSONHandleGraphics)
(qemuMonitorJSONGetStatus, qemuMonitorJSONExtractCPUInfo)
(qemuMonitorJSONGetVirtType, qemuMonitorJSONGetBalloonInfo)
(qemuMonitorJSONGetMemoryStats)
(qemuMonitorJSONDevGetBlockExtent)
(qemuMonitorJSONGetOneBlockStatsInfo)
(qemuMonitorJSONGetAllBlockStatsInfo)
(qemuMonitorJSONBlockStatsUpdateCapacityOne)
(qemuMonitorJSONBlockStatsUpdateCapacity)
(qemuMonitorJSONGetBlockExtent)
(qemuMonitorJSONGetMigrationStatusReply)
(qemuMonitorJSONGetDumpGuestMemoryCapability)
(qemuMonitorJSONAddFd, qemuMonitorJSONQueryRxFilterParse)
(qemuMonitorJSONExtractChardevInfo)
(qemuMonitorJSONDiskNameLookupOne)
(qemuMonitorJSONDiskNameLookup)
(qemuMonitorJSONGetAllBlockJobInfo)
(qemuMonitorJSONBlockIoThrottleInfo, qemuMonitorJSONGetVersion)
(qemuMonitorJSONGetMachines, qemuMonitorJSONGetCPUDefinitions)
(qemuMonitorJSONGetCommands, qemuMonitorJSONGetEvents)
(qemuMonitorJSONGetKVMState, qemuMonitorJSONGetObjectTypes)
(qemuMonitorJSONGetObjectListPaths)
(qemuMonitorJSONGetObjectProps, qemuMonitorJSONGetTargetArch)
(qemuMonitorJSONGetMigrationCapabilities)
(qemuMonitorJSONGetStringArray, qemuMonitorJSONAttachCharDev)
(qemuMonitorJSONGetCPUx86Data, qemuMonitorJSONGetIOThreads)
(qemuMonitorJSONGetMemoryDeviceInfo): Use shorter idioms.
Signed-off-by: Eric Blake <eblake@redhat.com>
2015-06-20 19:40:21 +00:00
|
|
|
(backing = virJSONValueObjectGetObject(dev, "backing")) &&
|
2014-12-12 16:53:33 +00:00
|
|
|
qemuMonitorJSONGetOneBlockStatsInfo(backing, dev_name, depth + 1,
|
|
|
|
hash, true) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2015-03-10 13:40:58 +00:00
|
|
|
ret = nstats;
|
2014-12-11 22:28:41 +00:00
|
|
|
cleanup:
|
|
|
|
VIR_FREE(bstats);
|
2014-12-12 16:53:33 +00:00
|
|
|
VIR_FREE(entry_name);
|
2014-12-11 22:28:41 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-24 10:51:10 +00:00
|
|
|
virJSONValuePtr
|
|
|
|
qemuMonitorJSONQueryBlockstats(qemuMonitorPtr mon)
|
2014-09-15 08:48:09 +00:00
|
|
|
{
|
2014-09-25 08:12:15 +00:00
|
|
|
virJSONValuePtr cmd;
|
2014-09-15 08:48:09 +00:00
|
|
|
virJSONValuePtr reply = NULL;
|
2017-07-24 10:51:10 +00:00
|
|
|
virJSONValuePtr ret = NULL;
|
2014-09-15 08:48:09 +00:00
|
|
|
|
2014-09-25 08:12:15 +00:00
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("query-blockstats", NULL)))
|
2017-07-24 10:51:10 +00:00
|
|
|
return NULL;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2017-07-24 10:51:10 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
2014-09-25 08:12:15 +00:00
|
|
|
goto cleanup;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2014-09-25 08:12:15 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
2010-07-12 13:07:02 +00:00
|
|
|
goto cleanup;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2017-07-24 10:51:10 +00:00
|
|
|
if (!(ret = virJSONValueObjectStealArray(reply, "return"))) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
2017-07-24 10:51:10 +00:00
|
|
|
_("query-blockstats reply was missing device list"));
|
2009-11-03 18:59:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2017-07-24 10:51:10 +00:00
|
|
|
cleanup:
|
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon,
|
|
|
|
virHashTablePtr hash,
|
|
|
|
bool backingChain)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
int nstats = 0;
|
|
|
|
int rc;
|
|
|
|
size_t i;
|
|
|
|
virJSONValuePtr devices;
|
|
|
|
|
|
|
|
if (!(devices = qemuMonitorJSONQueryBlockstats(mon)))
|
|
|
|
return -1;
|
|
|
|
|
2014-09-25 08:12:15 +00:00
|
|
|
for (i = 0; i < virJSONValueArraySize(devices); i++) {
|
2009-11-03 18:59:18 +00:00
|
|
|
virJSONValuePtr dev = virJSONValueArrayGet(devices, i);
|
2014-09-30 09:41:43 +00:00
|
|
|
const char *dev_name;
|
2014-09-25 08:12:15 +00:00
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (!dev || dev->type != VIR_JSON_TYPE_OBJECT) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
2014-09-15 08:48:09 +00:00
|
|
|
_("blockstats device entry was not "
|
|
|
|
"in expected format"));
|
2009-11-03 18:59:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-09-30 09:41:43 +00:00
|
|
|
if (!(dev_name = virJSONValueObjectGetString(dev, "device"))) {
|
2014-09-25 08:12:15 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("blockstats device entry was not "
|
|
|
|
"in expected format"));
|
|
|
|
goto cleanup;
|
2014-09-15 08:48:09 +00:00
|
|
|
}
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2015-03-10 13:40:58 +00:00
|
|
|
rc = qemuMonitorJSONGetOneBlockStatsInfo(dev, dev_name, 0, hash,
|
|
|
|
backingChain);
|
|
|
|
|
|
|
|
if (rc < 0)
|
2009-11-03 18:59:18 +00:00
|
|
|
goto cleanup;
|
2014-09-15 15:42:52 +00:00
|
|
|
|
2015-03-10 13:40:58 +00:00
|
|
|
if (rc > nstats)
|
|
|
|
nstats = rc;
|
2009-11-03 18:59:18 +00:00
|
|
|
}
|
2014-09-15 08:48:09 +00:00
|
|
|
|
2015-03-10 13:40:58 +00:00
|
|
|
ret = nstats;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2017-07-24 10:51:10 +00:00
|
|
|
virJSONValueFree(devices);
|
2009-11-03 18:59:18 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-11 22:28:41 +00:00
|
|
|
static int
|
|
|
|
qemuMonitorJSONBlockStatsUpdateCapacityOne(virJSONValuePtr image,
|
|
|
|
const char *dev_name,
|
2014-12-12 16:53:33 +00:00
|
|
|
int depth,
|
2014-12-11 22:28:41 +00:00
|
|
|
virHashTablePtr stats,
|
2014-12-12 16:53:33 +00:00
|
|
|
bool backingChain)
|
2014-12-11 22:28:41 +00:00
|
|
|
{
|
|
|
|
qemuBlockStatsPtr bstats;
|
|
|
|
int ret = -1;
|
2014-12-12 16:53:33 +00:00
|
|
|
char *entry_name = qemuDomainStorageAlias(dev_name, depth);
|
|
|
|
virJSONValuePtr backing;
|
2014-12-11 22:28:41 +00:00
|
|
|
|
2014-12-12 16:53:33 +00:00
|
|
|
if (!(bstats = virHashLookup(stats, entry_name))) {
|
2014-12-11 22:28:41 +00:00
|
|
|
if (VIR_ALLOC(bstats) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2014-12-12 16:53:33 +00:00
|
|
|
if (virHashAddEntry(stats, entry_name, bstats) < 0) {
|
2014-12-11 22:28:41 +00:00
|
|
|
VIR_FREE(bstats);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* After this point, we ignore failures; the stats were
|
|
|
|
* zero-initialized when created which is a sane fallback. */
|
|
|
|
ret = 0;
|
|
|
|
if (virJSONValueObjectGetNumberUlong(image, "virtual-size",
|
|
|
|
&bstats->capacity) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* if actual-size is missing, image is not thin provisioned */
|
|
|
|
if (virJSONValueObjectGetNumberUlong(image, "actual-size",
|
|
|
|
&bstats->physical) < 0)
|
|
|
|
bstats->physical = bstats->capacity;
|
2014-12-12 16:53:33 +00:00
|
|
|
|
|
|
|
if (backingChain &&
|
qemu: simplify json parsing
Rather than grabbing an arbitrary JSON value and then checking
if it has the right type, we might as well request the correct
type to begin with.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONIOProcessEvent)
(qemuMonitorJSONCommandWithFd, qemuMonitorJSONHandleGraphics)
(qemuMonitorJSONGetStatus, qemuMonitorJSONExtractCPUInfo)
(qemuMonitorJSONGetVirtType, qemuMonitorJSONGetBalloonInfo)
(qemuMonitorJSONGetMemoryStats)
(qemuMonitorJSONDevGetBlockExtent)
(qemuMonitorJSONGetOneBlockStatsInfo)
(qemuMonitorJSONGetAllBlockStatsInfo)
(qemuMonitorJSONBlockStatsUpdateCapacityOne)
(qemuMonitorJSONBlockStatsUpdateCapacity)
(qemuMonitorJSONGetBlockExtent)
(qemuMonitorJSONGetMigrationStatusReply)
(qemuMonitorJSONGetDumpGuestMemoryCapability)
(qemuMonitorJSONAddFd, qemuMonitorJSONQueryRxFilterParse)
(qemuMonitorJSONExtractChardevInfo)
(qemuMonitorJSONDiskNameLookupOne)
(qemuMonitorJSONDiskNameLookup)
(qemuMonitorJSONGetAllBlockJobInfo)
(qemuMonitorJSONBlockIoThrottleInfo, qemuMonitorJSONGetVersion)
(qemuMonitorJSONGetMachines, qemuMonitorJSONGetCPUDefinitions)
(qemuMonitorJSONGetCommands, qemuMonitorJSONGetEvents)
(qemuMonitorJSONGetKVMState, qemuMonitorJSONGetObjectTypes)
(qemuMonitorJSONGetObjectListPaths)
(qemuMonitorJSONGetObjectProps, qemuMonitorJSONGetTargetArch)
(qemuMonitorJSONGetMigrationCapabilities)
(qemuMonitorJSONGetStringArray, qemuMonitorJSONAttachCharDev)
(qemuMonitorJSONGetCPUx86Data, qemuMonitorJSONGetIOThreads)
(qemuMonitorJSONGetMemoryDeviceInfo): Use shorter idioms.
Signed-off-by: Eric Blake <eblake@redhat.com>
2015-06-20 19:40:21 +00:00
|
|
|
(backing = virJSONValueObjectGetObject(image, "backing-image"))) {
|
2014-12-12 16:53:33 +00:00
|
|
|
ret = qemuMonitorJSONBlockStatsUpdateCapacityOne(backing,
|
|
|
|
dev_name,
|
|
|
|
depth + 1,
|
|
|
|
stats,
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
|
2014-12-11 22:28:41 +00:00
|
|
|
cleanup:
|
2014-12-12 16:53:33 +00:00
|
|
|
VIR_FREE(entry_name);
|
2014-12-11 22:28:41 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
qemuMonitorJSONBlockStatsUpdateCapacity(qemuMonitorPtr mon,
|
|
|
|
virHashTablePtr stats,
|
|
|
|
bool backingChain)
|
2014-09-25 10:03:26 +00:00
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
size_t i;
|
|
|
|
virJSONValuePtr devices;
|
|
|
|
|
2016-09-27 13:39:21 +00:00
|
|
|
if (!(devices = qemuMonitorJSONQueryBlock(mon)))
|
2014-09-25 10:03:26 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (i = 0; i < virJSONValueArraySize(devices); i++) {
|
2016-10-03 18:58:59 +00:00
|
|
|
virJSONValuePtr dev;
|
2014-09-25 10:03:26 +00:00
|
|
|
virJSONValuePtr inserted;
|
|
|
|
virJSONValuePtr image;
|
2014-10-01 12:39:23 +00:00
|
|
|
const char *dev_name;
|
2014-09-25 10:03:26 +00:00
|
|
|
|
2016-10-03 18:58:59 +00:00
|
|
|
if (!(dev = qemuMonitorJSONGetBlockDev(devices, i)))
|
2014-09-25 10:03:26 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-10-03 19:04:32 +00:00
|
|
|
if (!(dev_name = qemuMonitorJSONGetBlockDevDevice(dev)))
|
2014-09-25 10:03:26 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* drive may be empty */
|
qemu: simplify json parsing
Rather than grabbing an arbitrary JSON value and then checking
if it has the right type, we might as well request the correct
type to begin with.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONIOProcessEvent)
(qemuMonitorJSONCommandWithFd, qemuMonitorJSONHandleGraphics)
(qemuMonitorJSONGetStatus, qemuMonitorJSONExtractCPUInfo)
(qemuMonitorJSONGetVirtType, qemuMonitorJSONGetBalloonInfo)
(qemuMonitorJSONGetMemoryStats)
(qemuMonitorJSONDevGetBlockExtent)
(qemuMonitorJSONGetOneBlockStatsInfo)
(qemuMonitorJSONGetAllBlockStatsInfo)
(qemuMonitorJSONBlockStatsUpdateCapacityOne)
(qemuMonitorJSONBlockStatsUpdateCapacity)
(qemuMonitorJSONGetBlockExtent)
(qemuMonitorJSONGetMigrationStatusReply)
(qemuMonitorJSONGetDumpGuestMemoryCapability)
(qemuMonitorJSONAddFd, qemuMonitorJSONQueryRxFilterParse)
(qemuMonitorJSONExtractChardevInfo)
(qemuMonitorJSONDiskNameLookupOne)
(qemuMonitorJSONDiskNameLookup)
(qemuMonitorJSONGetAllBlockJobInfo)
(qemuMonitorJSONBlockIoThrottleInfo, qemuMonitorJSONGetVersion)
(qemuMonitorJSONGetMachines, qemuMonitorJSONGetCPUDefinitions)
(qemuMonitorJSONGetCommands, qemuMonitorJSONGetEvents)
(qemuMonitorJSONGetKVMState, qemuMonitorJSONGetObjectTypes)
(qemuMonitorJSONGetObjectListPaths)
(qemuMonitorJSONGetObjectProps, qemuMonitorJSONGetTargetArch)
(qemuMonitorJSONGetMigrationCapabilities)
(qemuMonitorJSONGetStringArray, qemuMonitorJSONAttachCharDev)
(qemuMonitorJSONGetCPUx86Data, qemuMonitorJSONGetIOThreads)
(qemuMonitorJSONGetMemoryDeviceInfo): Use shorter idioms.
Signed-off-by: Eric Blake <eblake@redhat.com>
2015-06-20 19:40:21 +00:00
|
|
|
if (!(inserted = virJSONValueObjectGetObject(dev, "inserted")) ||
|
|
|
|
!(image = virJSONValueObjectGetObject(inserted, "image")))
|
2014-09-25 10:03:26 +00:00
|
|
|
continue;
|
|
|
|
|
2014-12-12 16:53:33 +00:00
|
|
|
if (qemuMonitorJSONBlockStatsUpdateCapacityOne(image, dev_name, 0,
|
|
|
|
stats,
|
2014-12-11 22:28:41 +00:00
|
|
|
backingChain) < 0)
|
|
|
|
goto cleanup;
|
2014-09-25 10:03:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
2016-09-27 13:39:21 +00:00
|
|
|
virJSONValueFree(devices);
|
2014-09-25 10:03:26 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-03 14:43:22 +00:00
|
|
|
/* Return 0 on success, -1 on failure, or -2 if not supported. Size
|
|
|
|
* is in bytes. */
|
2011-11-29 07:34:53 +00:00
|
|
|
int qemuMonitorJSONBlockResize(qemuMonitorPtr mon,
|
|
|
|
const char *device,
|
|
|
|
unsigned long long size)
|
|
|
|
{
|
2016-05-03 09:29:11 +00:00
|
|
|
int ret = -1;
|
2011-11-29 07:34:53 +00:00
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
|
|
|
|
cmd = qemuMonitorJSONMakeCommand("block_resize",
|
|
|
|
"s:device", device,
|
2012-03-03 14:43:22 +00:00
|
|
|
"U:size", size,
|
2011-11-29 07:34:53 +00:00
|
|
|
NULL);
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2011-11-29 07:34:53 +00:00
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
|
|
|
|
ret = -2;
|
|
|
|
goto cleanup;
|
2011-11-29 07:34:53 +00:00
|
|
|
}
|
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2011-11-29 07:34:53 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
2010-05-14 13:10:01 +00:00
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
int qemuMonitorJSONSetVNCPassword(qemuMonitorPtr mon,
|
|
|
|
const char *password)
|
|
|
|
{
|
2016-05-03 09:29:11 +00:00
|
|
|
int ret = -1;
|
2009-11-03 18:59:18 +00:00
|
|
|
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("change",
|
|
|
|
"s:device", "vnc",
|
|
|
|
"s:target", "password",
|
|
|
|
"s:arg", password,
|
|
|
|
NULL);
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2009-11-03 18:59:18 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-01-10 11:12:32 +00:00
|
|
|
/* Returns -1 on error, -2 if not supported */
|
|
|
|
int qemuMonitorJSONSetPassword(qemuMonitorPtr mon,
|
|
|
|
const char *protocol,
|
|
|
|
const char *password,
|
|
|
|
const char *action_if_connected)
|
|
|
|
{
|
2016-05-03 09:29:11 +00:00
|
|
|
int ret = -1;
|
2011-01-10 11:12:32 +00:00
|
|
|
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("set_password",
|
|
|
|
"s:protocol", protocol,
|
|
|
|
"s:password", password,
|
|
|
|
"s:connected", action_if_connected,
|
|
|
|
NULL);
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2011-01-10 11:12:32 +00:00
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
|
|
|
|
ret = -2;
|
|
|
|
goto cleanup;
|
2011-01-10 11:12:32 +00:00
|
|
|
}
|
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2011-01-10 11:12:32 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-01-18 18:37:45 +00:00
|
|
|
/* Returns -1 on error, -2 if not supported */
|
2011-01-10 11:12:32 +00:00
|
|
|
int qemuMonitorJSONExpirePassword(qemuMonitorPtr mon,
|
|
|
|
const char *protocol,
|
|
|
|
const char *expire_time)
|
|
|
|
{
|
2016-05-03 09:29:11 +00:00
|
|
|
int ret = -1;
|
2011-01-10 11:12:32 +00:00
|
|
|
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("expire_password",
|
|
|
|
"s:protocol", protocol,
|
|
|
|
"s:time", expire_time,
|
|
|
|
NULL);
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2011-01-18 18:37:45 +00:00
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
|
|
|
|
ret = -2;
|
|
|
|
goto cleanup;
|
2011-01-18 18:37:45 +00:00
|
|
|
}
|
2011-01-10 11:12:32 +00:00
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2011-01-10 11:12:32 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-05-27 12:03:17 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
qemuMonitorJSONSetBalloon(qemuMonitorPtr mon,
|
|
|
|
unsigned long long newmem)
|
2009-11-03 18:59:18 +00:00
|
|
|
{
|
2016-05-03 09:29:11 +00:00
|
|
|
int ret = -1;
|
2009-11-03 18:59:18 +00:00
|
|
|
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("balloon",
|
2015-05-27 12:03:17 +00:00
|
|
|
"U:value", newmem * 1024,
|
2009-11-03 18:59:18 +00:00
|
|
|
NULL);
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
/* See if balloon soft-failed */
|
|
|
|
if (qemuMonitorJSONHasError(reply, "DeviceNotActive") ||
|
|
|
|
qemuMonitorJSONHasError(reply, "KVMMissingCap")) {
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
2009-11-03 18:59:18 +00:00
|
|
|
}
|
|
|
|
|
2016-05-03 09:29:11 +00:00
|
|
|
/* See if any other fatal error occurred */
|
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* Real success */
|
|
|
|
ret = 1;
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2009-11-03 18:59:18 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-08 16:37:17 +00:00
|
|
|
int qemuMonitorJSONSetCPU(qemuMonitorPtr mon,
|
2013-05-27 13:35:35 +00:00
|
|
|
int cpu, bool online)
|
2010-02-08 16:37:17 +00:00
|
|
|
{
|
2013-05-27 14:08:30 +00:00
|
|
|
int ret = -1;
|
|
|
|
virJSONValuePtr cmd = NULL;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
|
|
|
|
if (online) {
|
|
|
|
cmd = qemuMonitorJSONMakeCommand("cpu-add",
|
|
|
|
"i:id", cpu,
|
|
|
|
NULL);
|
|
|
|
} else {
|
|
|
|
/* offlining is not yet implemented in qmp */
|
|
|
|
goto fallback;
|
|
|
|
}
|
|
|
|
if (!cmd)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (qemuMonitorJSONHasError(reply, "CommandNotFound"))
|
|
|
|
goto fallback;
|
|
|
|
else
|
|
|
|
ret = qemuMonitorJSONCheckError(cmd, reply);
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2013-05-27 14:08:30 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
fallback:
|
qemu: don't attempt undefined QMP commands
https://bugzilla.redhat.com/show_bug.cgi?id=872292
Libvirt should not attempt to call a QMP command that has not been
documented in qemu.git - if future qemu introduces a command by the
same name but with subtly different semantics, then libvirt will be
broken when trying to use that command.
We also had some code that could never be reached - some of our
commands have an alternate for new vs. old qemu HMP commands; but
if we are new enough to support QMP, we only need a fallback to
the new HMP counterpart, and don't need to try for a QMP counterpart
for the old HMP version.
See also this attempt to convert the three snapshot commands to QMP:
https://lists.gnu.org/archive/html/qemu-devel/2012-07/msg01597.html
although it looks like that will still not happen before qemu 1.3.
That thread eventually decided that qemu would use the name
'save-vm' rather than 'savevm', which mitigates the fact that
libvirt's attempt to use a QMP 'savevm' would be broken, but we
might not be as lucky on the other commands.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONSetCPU)
(qemuMonitorJSONAddDrive, qemuMonitorJSONDriveDel)
(qemuMonitorJSONCreateSnapshot, qemuMonitorJSONLoadSnapshot)
(qemuMonitorJSONDeleteSnapshot): Use only HMP fallback for now.
(qemuMonitorJSONAddHostNetwork, qemuMonitorJSONRemoveHostNetwork)
(qemuMonitorJSONAttachDrive, qemuMonitorJSONGetGuestDriveAddress):
Delete; QMP implies QEMU_CAPS_DEVICE, which prefers AddNetdev,
RemoveNetdev, and AddDrive anyways (qemu_hotplug.c has all callers).
* src/qemu/qemu_monitor.c (qemuMonitorAddHostNetwork)
(qemuMonitorRemoveHostNetwork, qemuMonitorAttachDrive): Reflect
deleted commands.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONAddHostNetwork)
(qemuMonitorJSONRemoveHostNetwork, qemuMonitorJSONAttachDrive):
Likewise.
2012-11-30 00:35:23 +00:00
|
|
|
VIR_DEBUG("no QMP support for cpu_set, trying HMP");
|
2013-05-27 14:08:30 +00:00
|
|
|
ret = qemuMonitorTextSetCPU(mon, cpu, online);
|
|
|
|
goto cleanup;
|
2010-02-08 16:37:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-29 14:18:53 +00:00
|
|
|
/**
|
|
|
|
* Run QMP command to eject a media from ejectable device.
|
|
|
|
*
|
|
|
|
* Returns:
|
2016-03-17 15:38:28 +00:00
|
|
|
* -1 on error
|
2015-06-29 14:18:53 +00:00
|
|
|
* 0 on success
|
|
|
|
*/
|
2009-11-03 18:59:18 +00:00
|
|
|
int qemuMonitorJSONEjectMedia(qemuMonitorPtr mon,
|
2011-09-16 12:05:58 +00:00
|
|
|
const char *dev_name,
|
2010-11-08 17:52:48 +00:00
|
|
|
bool force)
|
2009-11-03 18:59:18 +00:00
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2009-11-03 18:59:18 +00:00
|
|
|
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("eject",
|
2011-09-16 12:05:58 +00:00
|
|
|
"s:device", dev_name,
|
2010-11-08 17:52:48 +00:00
|
|
|
"b:force", force ? 1 : 0,
|
2009-11-03 18:59:18 +00:00
|
|
|
NULL);
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2009-11-03 18:59:18 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorJSONChangeMedia(qemuMonitorPtr mon,
|
2011-09-16 12:05:58 +00:00
|
|
|
const char *dev_name,
|
2009-11-03 18:59:18 +00:00
|
|
|
const char *newmedia,
|
|
|
|
const char *format)
|
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2009-11-03 18:59:18 +00:00
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
2014-05-13 15:28:45 +00:00
|
|
|
|
|
|
|
cmd = qemuMonitorJSONMakeCommand("change",
|
|
|
|
"s:device", dev_name,
|
|
|
|
"s:target", newmedia,
|
|
|
|
"S:arg", format,
|
|
|
|
NULL);
|
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2009-11-03 18:59:18 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int qemuMonitorJSONSaveMemory(qemuMonitorPtr mon,
|
|
|
|
const char *cmdtype,
|
|
|
|
unsigned long long offset,
|
|
|
|
size_t length,
|
|
|
|
const char *path)
|
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2009-11-03 18:59:18 +00:00
|
|
|
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand(cmdtype,
|
|
|
|
"U:val", offset,
|
|
|
|
"u:size", length,
|
|
|
|
"s:filename", path,
|
|
|
|
NULL);
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2009-11-03 18:59:18 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorJSONSaveVirtualMemory(qemuMonitorPtr mon,
|
|
|
|
unsigned long long offset,
|
|
|
|
size_t length,
|
|
|
|
const char *path)
|
|
|
|
{
|
|
|
|
return qemuMonitorJSONSaveMemory(mon, "memsave", offset, length, path);
|
|
|
|
}
|
|
|
|
|
|
|
|
int qemuMonitorJSONSavePhysicalMemory(qemuMonitorPtr mon,
|
|
|
|
unsigned long long offset,
|
|
|
|
size_t length,
|
|
|
|
const char *path)
|
|
|
|
{
|
|
|
|
return qemuMonitorJSONSaveMemory(mon, "pmemsave", offset, length, path);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorJSONSetMigrationSpeed(qemuMonitorPtr mon,
|
|
|
|
unsigned long bandwidth)
|
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2009-11-03 18:59:18 +00:00
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
cmd = qemuMonitorJSONMakeCommand("migrate_set_speed",
|
2010-11-25 08:38:32 +00:00
|
|
|
"U:value", bandwidth * 1024ULL * 1024ULL,
|
2009-11-03 18:59:18 +00:00
|
|
|
NULL);
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2009-11-03 18:59:18 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-17 15:53:14 +00:00
|
|
|
int qemuMonitorJSONSetMigrationDowntime(qemuMonitorPtr mon,
|
|
|
|
unsigned long long downtime)
|
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2010-03-17 15:53:14 +00:00
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
2010-08-19 13:59:25 +00:00
|
|
|
|
2010-03-17 15:53:14 +00:00
|
|
|
cmd = qemuMonitorJSONMakeCommand("migrate_set_downtime",
|
2010-08-19 13:59:25 +00:00
|
|
|
"d:value", downtime / 1000.0,
|
2010-03-17 15:53:14 +00:00
|
|
|
NULL);
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2010-03-17 15:53:14 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2010-03-17 15:53:14 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2010-03-17 15:53:14 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-18 20:54:58 +00:00
|
|
|
int
|
|
|
|
qemuMonitorJSONGetMigrationCacheSize(qemuMonitorPtr mon,
|
|
|
|
unsigned long long *cacheSize)
|
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2013-02-18 20:54:58 +00:00
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
|
|
|
|
*cacheSize = 0;
|
|
|
|
|
|
|
|
cmd = qemuMonitorJSONMakeCommand("query-migrate-cache-size", NULL);
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2013-02-18 20:54:58 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
2013-02-18 20:54:58 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (virJSONValueObjectGetNumberUlong(reply, "return", cacheSize) < 0) {
|
2013-02-18 20:54:58 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-migrate-cache-size reply was missing "
|
|
|
|
"'return' data"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2013-02-18 20:54:58 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
qemuMonitorJSONSetMigrationCacheSize(qemuMonitorPtr mon,
|
|
|
|
unsigned long long cacheSize)
|
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2013-02-18 20:54:58 +00:00
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
|
|
|
|
cmd = qemuMonitorJSONMakeCommand("migrate-set-cache-size",
|
|
|
|
"U:value", cacheSize,
|
|
|
|
NULL);
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2013-02-18 20:54:58 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2013-02-18 20:54:58 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2013-02-18 20:54:58 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-14 10:33:49 +00:00
|
|
|
int
|
2016-06-20 13:47:46 +00:00
|
|
|
qemuMonitorJSONGetMigrationParams(qemuMonitorPtr mon,
|
|
|
|
qemuMonitorMigrationParamsPtr params)
|
2016-04-14 10:33:49 +00:00
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virJSONValuePtr result;
|
|
|
|
virJSONValuePtr cmd = NULL;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
|
2016-06-20 14:54:24 +00:00
|
|
|
memset(params, 0, sizeof(*params));
|
|
|
|
|
2016-04-14 10:33:49 +00:00
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("query-migrate-parameters", NULL)))
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
2016-04-14 10:33:49 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2017-04-26 21:18:35 +00:00
|
|
|
if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
2016-04-14 10:33:49 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-05-03 08:55:41 +00:00
|
|
|
result = virJSONValueObjectGet(reply, "return");
|
2016-04-14 10:33:49 +00:00
|
|
|
|
2017-10-23 15:11:10 +00:00
|
|
|
#define PARSE_SET(API, VAR, FIELD) \
|
2016-06-20 14:54:24 +00:00
|
|
|
do { \
|
2017-10-23 15:11:10 +00:00
|
|
|
if (API(result, FIELD, ¶ms->VAR) == 0) \
|
2016-06-20 14:54:24 +00:00
|
|
|
params->VAR ## _set = true; \
|
|
|
|
} while (0)
|
2016-04-14 10:33:49 +00:00
|
|
|
|
2017-10-23 15:11:10 +00:00
|
|
|
#define PARSE_INT(VAR, FIELD) \
|
|
|
|
PARSE_SET(virJSONValueObjectGetNumberInt, VAR, FIELD)
|
2016-04-14 10:33:49 +00:00
|
|
|
|
2017-10-23 15:17:58 +00:00
|
|
|
#define PARSE_ULONG(VAR, FIELD) \
|
|
|
|
PARSE_SET(virJSONValueObjectGetNumberUlong, VAR, FIELD)
|
|
|
|
|
2017-10-23 15:15:32 +00:00
|
|
|
#define PARSE_STR(VAR, FIELD) \
|
|
|
|
do { \
|
|
|
|
const char *str; \
|
|
|
|
if ((str = virJSONValueObjectGetString(result, FIELD))) { \
|
|
|
|
if (VIR_STRDUP(params->VAR, str) < 0) \
|
|
|
|
goto cleanup; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2017-10-23 15:11:10 +00:00
|
|
|
PARSE_INT(compressLevel, "compress-level");
|
|
|
|
PARSE_INT(compressThreads, "compress-threads");
|
|
|
|
PARSE_INT(decompressThreads, "decompress-threads");
|
|
|
|
PARSE_INT(cpuThrottleInitial, "cpu-throttle-initial");
|
|
|
|
PARSE_INT(cpuThrottleIncrement, "cpu-throttle-increment");
|
2017-10-23 15:15:32 +00:00
|
|
|
PARSE_STR(migrateTLSAlias, "tls-creds");
|
|
|
|
PARSE_STR(migrateTLSHostname, "tls-hostname");
|
2017-10-23 15:17:58 +00:00
|
|
|
PARSE_ULONG(downtimeLimit, "downtime-limit");
|
2017-10-23 15:11:10 +00:00
|
|
|
|
|
|
|
#undef PARSE_SET
|
|
|
|
#undef PARSE_INT
|
2017-10-23 15:17:58 +00:00
|
|
|
#undef PARSE_ULONG
|
2017-10-23 15:15:32 +00:00
|
|
|
#undef PARSE_STR
|
2016-04-14 10:33:49 +00:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2016-06-20 13:47:46 +00:00
|
|
|
qemuMonitorJSONSetMigrationParams(qemuMonitorPtr mon,
|
|
|
|
qemuMonitorMigrationParamsPtr params)
|
2016-04-14 10:33:49 +00:00
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virJSONValuePtr cmd = NULL;
|
|
|
|
virJSONValuePtr args = NULL;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
|
|
|
|
if (!(cmd = virJSONValueNewObject()))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virJSONValueObjectAppendString(cmd, "execute",
|
|
|
|
"migrate-set-parameters") < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!(args = virJSONValueNewObject()))
|
|
|
|
goto cleanup;
|
|
|
|
|
2017-10-23 15:03:25 +00:00
|
|
|
#define APPEND(VALID, API, VAR, FIELD) \
|
2016-06-20 14:55:07 +00:00
|
|
|
do { \
|
2017-10-23 15:03:25 +00:00
|
|
|
if (VALID && API(args, FIELD, params->VAR) < 0) \
|
2016-06-20 14:55:07 +00:00
|
|
|
goto cleanup; \
|
|
|
|
} while (0)
|
2016-04-14 10:33:49 +00:00
|
|
|
|
2017-10-23 15:03:25 +00:00
|
|
|
#define APPEND_INT(VAR, FIELD) \
|
|
|
|
APPEND(params->VAR ## _set, \
|
|
|
|
virJSONValueObjectAppendNumberInt, VAR, FIELD)
|
|
|
|
|
2017-10-23 15:06:57 +00:00
|
|
|
#define APPEND_STR(VAR, FIELD) \
|
|
|
|
APPEND(params->VAR, \
|
|
|
|
virJSONValueObjectAppendString, VAR, FIELD)
|
|
|
|
|
2017-10-23 14:55:02 +00:00
|
|
|
#define APPEND_ULONG(VAR, FIELD) \
|
|
|
|
APPEND(params->VAR ## _set, \
|
|
|
|
virJSONValueObjectAppendNumberUlong, VAR, FIELD)
|
|
|
|
|
2017-10-23 15:03:25 +00:00
|
|
|
APPEND_INT(compressLevel, "compress-level");
|
|
|
|
APPEND_INT(compressThreads, "compress-threads");
|
|
|
|
APPEND_INT(decompressThreads, "decompress-threads");
|
|
|
|
APPEND_INT(cpuThrottleInitial, "cpu-throttle-initial");
|
|
|
|
APPEND_INT(cpuThrottleIncrement, "cpu-throttle-increment");
|
2017-10-23 15:06:57 +00:00
|
|
|
APPEND_STR(migrateTLSAlias, "tls-creds");
|
|
|
|
APPEND_STR(migrateTLSHostname, "tls-hostname");
|
2017-10-23 14:55:02 +00:00
|
|
|
APPEND_ULONG(downtimeLimit, "downtime-limit");
|
2016-04-14 10:33:49 +00:00
|
|
|
|
2016-06-20 14:55:07 +00:00
|
|
|
#undef APPEND
|
2017-10-23 15:03:25 +00:00
|
|
|
#undef APPEND_INT
|
2017-10-23 15:06:57 +00:00
|
|
|
#undef APPEND_STR
|
2017-10-23 14:55:02 +00:00
|
|
|
#undef APPEND_ULONG
|
2017-02-16 23:33:22 +00:00
|
|
|
|
2017-10-26 20:10:31 +00:00
|
|
|
if (virJSONValueObjectKeysNumber(args) == 0) {
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2016-04-14 10:33:49 +00:00
|
|
|
if (virJSONValueObjectAppend(cmd, "arguments", args) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
args = NULL;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
2016-04-14 10:33:49 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2016-04-14 10:33:49 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
2016-04-14 10:33:49 +00:00
|
|
|
cleanup:
|
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(args);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
static int
|
2015-11-26 12:23:08 +00:00
|
|
|
qemuMonitorJSONGetMigrationStatsReply(virJSONValuePtr reply,
|
2017-10-12 13:19:19 +00:00
|
|
|
qemuMonitorMigrationStatsPtr stats,
|
|
|
|
char **error)
|
2009-11-03 18:59:18 +00:00
|
|
|
{
|
|
|
|
virJSONValuePtr ret;
|
2015-11-26 12:24:31 +00:00
|
|
|
virJSONValuePtr ram;
|
|
|
|
virJSONValuePtr disk;
|
|
|
|
virJSONValuePtr comp;
|
2010-01-22 13:22:53 +00:00
|
|
|
const char *statusstr;
|
2013-02-08 08:58:03 +00:00
|
|
|
int rc;
|
2014-01-13 06:28:10 +00:00
|
|
|
double mbps;
|
2017-10-12 13:19:19 +00:00
|
|
|
const char *tmp;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2016-11-20 23:10:06 +00:00
|
|
|
ret = virJSONValueObjectGetObject(reply, "return");
|
2009-11-03 18:59:18 +00:00
|
|
|
|
|
|
|
if (!(statusstr = virJSONValueObjectGetString(ret, "status"))) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("info migration reply was missing return status"));
|
2009-11-03 18:59:18 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-11-26 12:23:08 +00:00
|
|
|
stats->status = qemuMonitorMigrationStatusTypeFromString(statusstr);
|
|
|
|
if (stats->status < 0) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("unexpected migration status in %s"), statusstr);
|
2009-11-03 18:59:18 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-09-09 08:17:46 +00:00
|
|
|
ignore_value(virJSONValueObjectGetNumberUlong(ret, "total-time",
|
2015-11-26 12:23:08 +00:00
|
|
|
&stats->total_time));
|
|
|
|
if (stats->status == QEMU_MONITOR_MIGRATION_STATUS_COMPLETED) {
|
2013-02-08 08:58:03 +00:00
|
|
|
rc = virJSONValueObjectGetNumberUlong(ret, "downtime",
|
2015-11-26 12:23:08 +00:00
|
|
|
&stats->downtime);
|
2013-02-08 08:58:03 +00:00
|
|
|
} else {
|
|
|
|
rc = virJSONValueObjectGetNumberUlong(ret, "expected-downtime",
|
2015-11-26 12:23:08 +00:00
|
|
|
&stats->downtime);
|
2013-02-08 08:58:03 +00:00
|
|
|
}
|
|
|
|
if (rc == 0)
|
2015-11-26 12:23:08 +00:00
|
|
|
stats->downtime_set = true;
|
2013-02-08 08:58:03 +00:00
|
|
|
|
2014-01-13 06:28:10 +00:00
|
|
|
if (virJSONValueObjectGetNumberUlong(ret, "setup-time",
|
2015-11-26 12:23:08 +00:00
|
|
|
&stats->setup_time) == 0)
|
|
|
|
stats->setup_time_set = true;
|
2014-01-13 06:28:10 +00:00
|
|
|
|
2016-06-21 11:40:33 +00:00
|
|
|
ignore_value(virJSONValueObjectGetNumberInt(ret, "cpu-throttle-percentage",
|
|
|
|
&stats->cpu_throttle_percentage));
|
|
|
|
|
2015-11-26 12:24:31 +00:00
|
|
|
switch ((qemuMonitorMigrationStatus) stats->status) {
|
|
|
|
case QEMU_MONITOR_MIGRATION_STATUS_INACTIVE:
|
|
|
|
case QEMU_MONITOR_MIGRATION_STATUS_SETUP:
|
|
|
|
case QEMU_MONITOR_MIGRATION_STATUS_CANCELLED:
|
|
|
|
case QEMU_MONITOR_MIGRATION_STATUS_LAST:
|
|
|
|
break;
|
|
|
|
|
2017-10-12 13:19:19 +00:00
|
|
|
case QEMU_MONITOR_MIGRATION_STATUS_ERROR:
|
|
|
|
if (error) {
|
|
|
|
tmp = virJSONValueObjectGetString(ret, "error-desc");
|
|
|
|
if (tmp && VIR_STRDUP(*error, tmp) < 0)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-11-26 12:24:31 +00:00
|
|
|
case QEMU_MONITOR_MIGRATION_STATUS_ACTIVE:
|
2015-11-26 14:37:23 +00:00
|
|
|
case QEMU_MONITOR_MIGRATION_STATUS_POSTCOPY:
|
2015-11-26 12:24:31 +00:00
|
|
|
case QEMU_MONITOR_MIGRATION_STATUS_COMPLETED:
|
|
|
|
case QEMU_MONITOR_MIGRATION_STATUS_CANCELLING:
|
2017-10-20 08:11:32 +00:00
|
|
|
case QEMU_MONITOR_MIGRATION_STATUS_PRE_SWITCHOVER:
|
|
|
|
case QEMU_MONITOR_MIGRATION_STATUS_DEVICE:
|
2015-11-26 12:24:31 +00:00
|
|
|
ram = virJSONValueObjectGetObject(ret, "ram");
|
2009-11-03 18:59:18 +00:00
|
|
|
if (!ram) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("migration was active, but no RAM info was set"));
|
2009-11-03 18:59:18 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-08-17 06:30:02 +00:00
|
|
|
if (virJSONValueObjectGetNumberUlong(ram, "transferred",
|
2015-11-26 12:23:08 +00:00
|
|
|
&stats->ram_transferred) < 0) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("migration was active, but RAM 'transferred' "
|
|
|
|
"data was missing"));
|
2009-11-03 18:59:18 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2013-02-08 08:58:03 +00:00
|
|
|
if (virJSONValueObjectGetNumberUlong(ram, "remaining",
|
2015-11-26 12:23:08 +00:00
|
|
|
&stats->ram_remaining) < 0) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("migration was active, but RAM 'remaining' "
|
|
|
|
"data was missing"));
|
2009-11-03 18:59:18 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2013-02-08 08:58:03 +00:00
|
|
|
if (virJSONValueObjectGetNumberUlong(ram, "total",
|
2015-11-26 12:23:08 +00:00
|
|
|
&stats->ram_total) < 0) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("migration was active, but RAM 'total' "
|
|
|
|
"data was missing"));
|
2009-11-03 18:59:18 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2011-08-17 06:30:02 +00:00
|
|
|
|
2014-01-13 06:28:10 +00:00
|
|
|
if (virJSONValueObjectGetNumberDouble(ram, "mbps", &mbps) == 0 &&
|
|
|
|
mbps > 0) {
|
|
|
|
/* mpbs from QEMU reports Mbits/s (M as in 10^6 not Mi as 2^20) */
|
2015-11-26 12:23:08 +00:00
|
|
|
stats->ram_bps = mbps * (1000 * 1000 / 8);
|
2014-01-13 06:28:10 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 08:58:03 +00:00
|
|
|
if (virJSONValueObjectGetNumberUlong(ram, "duplicate",
|
2015-11-26 12:23:08 +00:00
|
|
|
&stats->ram_duplicate) == 0)
|
|
|
|
stats->ram_duplicate_set = true;
|
2014-09-09 08:17:46 +00:00
|
|
|
ignore_value(virJSONValueObjectGetNumberUlong(ram, "normal",
|
2015-11-26 12:23:08 +00:00
|
|
|
&stats->ram_normal));
|
2014-09-09 08:17:46 +00:00
|
|
|
ignore_value(virJSONValueObjectGetNumberUlong(ram, "normal-bytes",
|
2015-11-26 12:23:08 +00:00
|
|
|
&stats->ram_normal_bytes));
|
2015-11-27 11:30:09 +00:00
|
|
|
ignore_value(virJSONValueObjectGetNumberUlong(ram, "dirty-pages-rate",
|
|
|
|
&stats->ram_dirty_rate));
|
2017-10-09 02:00:03 +00:00
|
|
|
ignore_value(virJSONValueObjectGetNumberUlong(ram, "page-size",
|
|
|
|
&stats->ram_page_size));
|
2015-11-27 11:30:09 +00:00
|
|
|
ignore_value(virJSONValueObjectGetNumberUlong(ram, "dirty-sync-count",
|
|
|
|
&stats->ram_iteration));
|
2013-02-08 08:58:03 +00:00
|
|
|
|
2015-11-26 12:24:31 +00:00
|
|
|
disk = virJSONValueObjectGetObject(ret, "disk");
|
2013-02-08 08:58:03 +00:00
|
|
|
if (disk) {
|
|
|
|
rc = virJSONValueObjectGetNumberUlong(disk, "transferred",
|
2015-11-26 12:23:08 +00:00
|
|
|
&stats->disk_transferred);
|
2013-02-08 08:58:03 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("disk migration was active, but "
|
|
|
|
"'transferred' data was missing"));
|
|
|
|
return -1;
|
|
|
|
}
|
2011-08-17 06:30:02 +00:00
|
|
|
|
2013-02-08 08:58:03 +00:00
|
|
|
rc = virJSONValueObjectGetNumberUlong(disk, "remaining",
|
2015-11-26 12:23:08 +00:00
|
|
|
&stats->disk_remaining);
|
2013-02-08 08:58:03 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("disk migration was active, but 'remaining' "
|
|
|
|
"data was missing"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = virJSONValueObjectGetNumberUlong(disk, "total",
|
2015-11-26 12:23:08 +00:00
|
|
|
&stats->disk_total);
|
2013-02-08 08:58:03 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("disk migration was active, but 'total' "
|
|
|
|
"data was missing"));
|
|
|
|
return -1;
|
|
|
|
}
|
2014-01-13 06:28:10 +00:00
|
|
|
|
|
|
|
if (virJSONValueObjectGetNumberDouble(disk, "mbps", &mbps) == 0 &&
|
|
|
|
mbps > 0) {
|
|
|
|
/* mpbs from QEMU reports Mbits/s (M as in 10^6 not Mi as 2^20) */
|
2015-11-26 12:23:08 +00:00
|
|
|
stats->disk_bps = mbps * (1000 * 1000 / 8);
|
2014-01-13 06:28:10 +00:00
|
|
|
}
|
2011-08-17 06:30:02 +00:00
|
|
|
}
|
2013-02-08 08:58:03 +00:00
|
|
|
|
2015-11-26 12:24:31 +00:00
|
|
|
comp = virJSONValueObjectGetObject(ret, "xbzrle-cache");
|
2013-02-08 08:58:03 +00:00
|
|
|
if (comp) {
|
2015-11-26 12:23:08 +00:00
|
|
|
stats->xbzrle_set = true;
|
2013-02-08 08:58:03 +00:00
|
|
|
rc = virJSONValueObjectGetNumberUlong(comp, "cache-size",
|
2015-11-26 12:23:08 +00:00
|
|
|
&stats->xbzrle_cache_size);
|
2013-02-08 08:58:03 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("XBZRLE is active, but 'cache-size' data "
|
|
|
|
"was missing"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = virJSONValueObjectGetNumberUlong(comp, "bytes",
|
2015-11-26 12:23:08 +00:00
|
|
|
&stats->xbzrle_bytes);
|
2013-02-08 08:58:03 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("XBZRLE is active, but 'bytes' data "
|
|
|
|
"was missing"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = virJSONValueObjectGetNumberUlong(comp, "pages",
|
2015-11-26 12:23:08 +00:00
|
|
|
&stats->xbzrle_pages);
|
2013-02-08 08:58:03 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("XBZRLE is active, but 'pages' data "
|
|
|
|
"was missing"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = virJSONValueObjectGetNumberUlong(comp, "cache-miss",
|
2015-11-26 12:23:08 +00:00
|
|
|
&stats->xbzrle_cache_miss);
|
2013-02-08 08:58:03 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("XBZRLE is active, but 'cache-miss' data "
|
|
|
|
"was missing"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = virJSONValueObjectGetNumberUlong(comp, "overflow",
|
2015-11-26 12:23:08 +00:00
|
|
|
&stats->xbzrle_overflow);
|
2013-02-08 08:58:03 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("XBZRLE is active, but 'overflow' data "
|
|
|
|
"was missing"));
|
|
|
|
return -1;
|
|
|
|
}
|
2011-08-17 06:30:02 +00:00
|
|
|
}
|
2015-11-26 12:24:31 +00:00
|
|
|
break;
|
2009-11-03 18:59:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-26 12:23:08 +00:00
|
|
|
int qemuMonitorJSONGetMigrationStats(qemuMonitorPtr mon,
|
2017-10-12 13:19:19 +00:00
|
|
|
qemuMonitorMigrationStatsPtr stats,
|
|
|
|
char **error)
|
2009-11-03 18:59:18 +00:00
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2010-03-03 17:07:50 +00:00
|
|
|
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("query-migrate",
|
2009-11-03 18:59:18 +00:00
|
|
|
NULL);
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
|
2015-11-26 12:23:08 +00:00
|
|
|
memset(stats, 0, sizeof(*stats));
|
2009-11-03 18:59:18 +00:00
|
|
|
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2017-10-12 13:19:19 +00:00
|
|
|
if (qemuMonitorJSONGetMigrationStatsReply(reply, stats, error) < 0)
|
2016-05-04 08:28:43 +00:00
|
|
|
goto cleanup;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2013-02-08 08:58:03 +00:00
|
|
|
if (ret < 0)
|
2015-11-26 12:23:08 +00:00
|
|
|
memset(stats, 0, sizeof(*stats));
|
2009-11-03 18:59:18 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-04 18:51:48 +00:00
|
|
|
int qemuMonitorJSONMigrate(qemuMonitorPtr mon,
|
|
|
|
unsigned int flags,
|
|
|
|
const char *uri)
|
2009-11-03 18:59:18 +00:00
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2010-06-24 18:58:36 +00:00
|
|
|
virJSONValuePtr cmd =
|
|
|
|
qemuMonitorJSONMakeCommand("migrate",
|
2010-09-09 21:05:03 +00:00
|
|
|
"b:detach", flags & QEMU_MONITOR_MIGRATE_BACKGROUND ? 1 : 0,
|
|
|
|
"b:blk", flags & QEMU_MONITOR_MIGRATE_NON_SHARED_DISK ? 1 : 0,
|
|
|
|
"b:inc", flags & QEMU_MONITOR_MIGRATE_NON_SHARED_INC ? 1 : 0,
|
2010-06-24 18:58:36 +00:00
|
|
|
"s:uri", uri,
|
|
|
|
NULL);
|
2009-11-03 18:59:18 +00:00
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2009-11-03 18:59:18 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int qemuMonitorJSONMigrateCancel(qemuMonitorPtr mon)
|
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2009-11-03 18:59:18 +00:00
|
|
|
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("migrate_cancel", NULL);
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2009-11-03 18:59:18 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-03-23 03:51:13 +00:00
|
|
|
int
|
|
|
|
qemuMonitorJSONGetDumpGuestMemoryCapability(qemuMonitorPtr mon,
|
|
|
|
const char *capability)
|
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2014-03-23 03:51:13 +00:00
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
virJSONValuePtr caps;
|
|
|
|
virJSONValuePtr formats;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("query-dump-guest-memory-capability",
|
|
|
|
NULL)))
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2014-03-23 03:51:13 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
2014-03-23 03:51:13 +00:00
|
|
|
}
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
2014-03-23 03:51:13 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-11-20 23:10:06 +00:00
|
|
|
caps = virJSONValueObjectGetObject(reply, "return");
|
2014-03-23 03:51:13 +00:00
|
|
|
|
qemu: simplify json parsing
Rather than grabbing an arbitrary JSON value and then checking
if it has the right type, we might as well request the correct
type to begin with.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONIOProcessEvent)
(qemuMonitorJSONCommandWithFd, qemuMonitorJSONHandleGraphics)
(qemuMonitorJSONGetStatus, qemuMonitorJSONExtractCPUInfo)
(qemuMonitorJSONGetVirtType, qemuMonitorJSONGetBalloonInfo)
(qemuMonitorJSONGetMemoryStats)
(qemuMonitorJSONDevGetBlockExtent)
(qemuMonitorJSONGetOneBlockStatsInfo)
(qemuMonitorJSONGetAllBlockStatsInfo)
(qemuMonitorJSONBlockStatsUpdateCapacityOne)
(qemuMonitorJSONBlockStatsUpdateCapacity)
(qemuMonitorJSONGetBlockExtent)
(qemuMonitorJSONGetMigrationStatusReply)
(qemuMonitorJSONGetDumpGuestMemoryCapability)
(qemuMonitorJSONAddFd, qemuMonitorJSONQueryRxFilterParse)
(qemuMonitorJSONExtractChardevInfo)
(qemuMonitorJSONDiskNameLookupOne)
(qemuMonitorJSONDiskNameLookup)
(qemuMonitorJSONGetAllBlockJobInfo)
(qemuMonitorJSONBlockIoThrottleInfo, qemuMonitorJSONGetVersion)
(qemuMonitorJSONGetMachines, qemuMonitorJSONGetCPUDefinitions)
(qemuMonitorJSONGetCommands, qemuMonitorJSONGetEvents)
(qemuMonitorJSONGetKVMState, qemuMonitorJSONGetObjectTypes)
(qemuMonitorJSONGetObjectListPaths)
(qemuMonitorJSONGetObjectProps, qemuMonitorJSONGetTargetArch)
(qemuMonitorJSONGetMigrationCapabilities)
(qemuMonitorJSONGetStringArray, qemuMonitorJSONAttachCharDev)
(qemuMonitorJSONGetCPUx86Data, qemuMonitorJSONGetIOThreads)
(qemuMonitorJSONGetMemoryDeviceInfo): Use shorter idioms.
Signed-off-by: Eric Blake <eblake@redhat.com>
2015-06-20 19:40:21 +00:00
|
|
|
if (!(formats = virJSONValueObjectGetArray(caps, "formats"))) {
|
2014-03-23 03:51:13 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("missing supported dump formats"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < virJSONValueArraySize(formats); i++) {
|
|
|
|
virJSONValuePtr dumpformat = virJSONValueArrayGet(formats, i);
|
|
|
|
|
|
|
|
if (!dumpformat || dumpformat->type != VIR_JSON_TYPE_STRING) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("missing entry in supported dump formats"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (STREQ(virJSONValueGetString(dumpformat), capability)) {
|
|
|
|
ret = 1;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2014-03-23 03:51:13 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-09-17 19:05:29 +00:00
|
|
|
int
|
|
|
|
qemuMonitorJSONDump(qemuMonitorPtr mon,
|
2014-03-23 03:51:14 +00:00
|
|
|
const char *protocol,
|
|
|
|
const char *dumpformat)
|
2012-06-12 03:04:51 +00:00
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2012-06-12 03:04:51 +00:00
|
|
|
virJSONValuePtr cmd = NULL;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
|
2014-03-23 03:51:14 +00:00
|
|
|
if (dumpformat) {
|
|
|
|
cmd = qemuMonitorJSONMakeCommand("dump-guest-memory",
|
|
|
|
"b:paging", false,
|
|
|
|
"s:protocol", protocol,
|
|
|
|
"s:format", dumpformat,
|
|
|
|
NULL);
|
|
|
|
} else {
|
|
|
|
cmd = qemuMonitorJSONMakeCommand("dump-guest-memory",
|
|
|
|
"b:paging", false,
|
|
|
|
"s:protocol", protocol,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2012-06-12 03:04:51 +00:00
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2012-06-12 03:04:51 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2012-06-12 03:04:51 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2012-06-12 03:04:51 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2011-02-17 13:39:36 +00:00
|
|
|
int qemuMonitorJSONGraphicsRelocate(qemuMonitorPtr mon,
|
|
|
|
int type,
|
|
|
|
const char *hostname,
|
|
|
|
int port,
|
|
|
|
int tlsPort,
|
|
|
|
const char *tlsSubject)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("client_migrate_info",
|
|
|
|
"s:protocol",
|
|
|
|
(type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE ? "spice" : "vnc"),
|
|
|
|
"s:hostname", hostname,
|
|
|
|
"i:port", port,
|
|
|
|
"i:tls-port", tlsPort,
|
2014-05-13 15:28:45 +00:00
|
|
|
"S:cert-subject", tlsSubject,
|
2011-02-17 13:39:36 +00:00
|
|
|
NULL);
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2011-02-17 13:39:36 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2011-02-17 13:39:36 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2011-02-17 13:39:36 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
int qemuMonitorJSONSendFileHandle(qemuMonitorPtr mon,
|
|
|
|
const char *fdname,
|
|
|
|
int fd)
|
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2009-11-03 18:59:18 +00:00
|
|
|
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("getfd",
|
|
|
|
"s:fdname", fdname,
|
|
|
|
NULL);
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommandWithFd(mon, cmd, fd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2009-11-03 18:59:18 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorJSONCloseFileHandle(qemuMonitorPtr mon,
|
|
|
|
const char *fdname)
|
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2009-11-03 18:59:18 +00:00
|
|
|
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("closefd",
|
|
|
|
"s:fdname", fdname,
|
|
|
|
NULL);
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2009-11-03 18:59:18 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2009-11-03 18:59:18 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-31 00:18:44 +00:00
|
|
|
int
|
|
|
|
qemuMonitorJSONAddFd(qemuMonitorPtr mon, int fdset, int fd, const char *name)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("add-fd",
|
|
|
|
"i:fdset-id", fdset,
|
2014-05-13 15:28:45 +00:00
|
|
|
"S:opaque", name,
|
|
|
|
NULL);
|
2013-01-31 00:18:44 +00:00
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
ret = qemuMonitorJSONCommandWithFd(mon, cmd, fd, &reply);
|
|
|
|
|
2013-02-05 15:50:00 +00:00
|
|
|
if (ret == 0) {
|
|
|
|
/* qemu 1.2 lacks the functionality we need; but we have to
|
|
|
|
* probe to find that out. Don't log errors in that case. */
|
|
|
|
if (STREQ_NULLABLE(name, "/dev/null") &&
|
|
|
|
qemuMonitorJSONHasError(reply, "GenericError")) {
|
|
|
|
ret = -2;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-01-31 00:18:44 +00:00
|
|
|
ret = qemuMonitorJSONCheckError(cmd, reply);
|
2013-02-05 15:50:00 +00:00
|
|
|
}
|
2013-01-31 00:18:44 +00:00
|
|
|
if (ret == 0) {
|
qemu: simplify json parsing
Rather than grabbing an arbitrary JSON value and then checking
if it has the right type, we might as well request the correct
type to begin with.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONIOProcessEvent)
(qemuMonitorJSONCommandWithFd, qemuMonitorJSONHandleGraphics)
(qemuMonitorJSONGetStatus, qemuMonitorJSONExtractCPUInfo)
(qemuMonitorJSONGetVirtType, qemuMonitorJSONGetBalloonInfo)
(qemuMonitorJSONGetMemoryStats)
(qemuMonitorJSONDevGetBlockExtent)
(qemuMonitorJSONGetOneBlockStatsInfo)
(qemuMonitorJSONGetAllBlockStatsInfo)
(qemuMonitorJSONBlockStatsUpdateCapacityOne)
(qemuMonitorJSONBlockStatsUpdateCapacity)
(qemuMonitorJSONGetBlockExtent)
(qemuMonitorJSONGetMigrationStatusReply)
(qemuMonitorJSONGetDumpGuestMemoryCapability)
(qemuMonitorJSONAddFd, qemuMonitorJSONQueryRxFilterParse)
(qemuMonitorJSONExtractChardevInfo)
(qemuMonitorJSONDiskNameLookupOne)
(qemuMonitorJSONDiskNameLookup)
(qemuMonitorJSONGetAllBlockJobInfo)
(qemuMonitorJSONBlockIoThrottleInfo, qemuMonitorJSONGetVersion)
(qemuMonitorJSONGetMachines, qemuMonitorJSONGetCPUDefinitions)
(qemuMonitorJSONGetCommands, qemuMonitorJSONGetEvents)
(qemuMonitorJSONGetKVMState, qemuMonitorJSONGetObjectTypes)
(qemuMonitorJSONGetObjectListPaths)
(qemuMonitorJSONGetObjectProps, qemuMonitorJSONGetTargetArch)
(qemuMonitorJSONGetMigrationCapabilities)
(qemuMonitorJSONGetStringArray, qemuMonitorJSONAttachCharDev)
(qemuMonitorJSONGetCPUx86Data, qemuMonitorJSONGetIOThreads)
(qemuMonitorJSONGetMemoryDeviceInfo): Use shorter idioms.
Signed-off-by: Eric Blake <eblake@redhat.com>
2015-06-20 19:40:21 +00:00
|
|
|
virJSONValuePtr data = virJSONValueObjectGetObject(reply, "return");
|
2013-01-31 00:18:44 +00:00
|
|
|
|
qemu: simplify json parsing
Rather than grabbing an arbitrary JSON value and then checking
if it has the right type, we might as well request the correct
type to begin with.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONIOProcessEvent)
(qemuMonitorJSONCommandWithFd, qemuMonitorJSONHandleGraphics)
(qemuMonitorJSONGetStatus, qemuMonitorJSONExtractCPUInfo)
(qemuMonitorJSONGetVirtType, qemuMonitorJSONGetBalloonInfo)
(qemuMonitorJSONGetMemoryStats)
(qemuMonitorJSONDevGetBlockExtent)
(qemuMonitorJSONGetOneBlockStatsInfo)
(qemuMonitorJSONGetAllBlockStatsInfo)
(qemuMonitorJSONBlockStatsUpdateCapacityOne)
(qemuMonitorJSONBlockStatsUpdateCapacity)
(qemuMonitorJSONGetBlockExtent)
(qemuMonitorJSONGetMigrationStatusReply)
(qemuMonitorJSONGetDumpGuestMemoryCapability)
(qemuMonitorJSONAddFd, qemuMonitorJSONQueryRxFilterParse)
(qemuMonitorJSONExtractChardevInfo)
(qemuMonitorJSONDiskNameLookupOne)
(qemuMonitorJSONDiskNameLookup)
(qemuMonitorJSONGetAllBlockJobInfo)
(qemuMonitorJSONBlockIoThrottleInfo, qemuMonitorJSONGetVersion)
(qemuMonitorJSONGetMachines, qemuMonitorJSONGetCPUDefinitions)
(qemuMonitorJSONGetCommands, qemuMonitorJSONGetEvents)
(qemuMonitorJSONGetKVMState, qemuMonitorJSONGetObjectTypes)
(qemuMonitorJSONGetObjectListPaths)
(qemuMonitorJSONGetObjectProps, qemuMonitorJSONGetTargetArch)
(qemuMonitorJSONGetMigrationCapabilities)
(qemuMonitorJSONGetStringArray, qemuMonitorJSONAttachCharDev)
(qemuMonitorJSONGetCPUx86Data, qemuMonitorJSONGetIOThreads)
(qemuMonitorJSONGetMemoryDeviceInfo): Use shorter idioms.
Signed-off-by: Eric Blake <eblake@redhat.com>
2015-06-20 19:40:21 +00:00
|
|
|
if (virJSONValueObjectGetNumberInt(data, "fd", &ret) < 0) {
|
2013-01-31 00:18:44 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("incomplete return information"));
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2013-01-31 00:18:44 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
error:
|
2013-01-31 00:18:44 +00:00
|
|
|
/* Best effort cleanup - kill the entire fdset (even if it has
|
|
|
|
* earlier successful fd registrations), since we don't know which
|
|
|
|
* fd qemu got, and don't want to leave the fd leaked in qemu. */
|
|
|
|
qemuMonitorJSONRemoveFd(mon, fdset, -1);
|
|
|
|
ret = -1;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
qemuMonitorJSONRemoveFd(qemuMonitorPtr mon, int fdset, int fd)
|
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2013-01-31 00:18:44 +00:00
|
|
|
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("remove-fd",
|
|
|
|
"i:fdset-id", fdset,
|
|
|
|
fd < 0 ? NULL : "i:fd",
|
|
|
|
fd, NULL);
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2013-01-31 00:18:44 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2013-01-31 00:18:44 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2013-01-31 00:18:44 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-15 13:52:03 +00:00
|
|
|
int qemuMonitorJSONAddNetdev(qemuMonitorPtr mon,
|
|
|
|
const char *netdevstr)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virJSONValuePtr cmd = NULL;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
virJSONValuePtr args = NULL;
|
|
|
|
|
|
|
|
cmd = qemuMonitorJSONMakeCommand("netdev_add", NULL);
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
args = qemuMonitorJSONKeywordStringToJSON(netdevstr, "type");
|
|
|
|
if (!args)
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-07-04 10:14:12 +00:00
|
|
|
if (virJSONValueObjectAppend(cmd, "arguments", args) < 0)
|
2010-04-15 13:52:03 +00:00
|
|
|
goto cleanup;
|
|
|
|
args = NULL; /* obj owns reference to args now */
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2010-04-15 13:52:03 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2010-04-15 13:52:03 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2010-04-15 13:52:03 +00:00
|
|
|
virJSONValueFree(args);
|
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorJSONRemoveNetdev(qemuMonitorPtr mon,
|
|
|
|
const char *alias)
|
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2010-04-15 13:52:03 +00:00
|
|
|
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("netdev_del",
|
|
|
|
"s:id", alias,
|
|
|
|
NULL);
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2010-04-15 13:52:03 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2010-04-15 13:52:03 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2010-04-15 13:52:03 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
qemu: qemuMonitorQueryRxFilter - retrieve guest netdev rx-filter
This function can be called at any time to get the current status of a
guest's network device rx-filter. In particular it is useful to call
after libvirt recieves a NIC_RX_FILTER_CHANGED event - this event only
tells you that something has changed in the rx-filter, the details are
retrieved with the query-rx-filter monitor command (only available in
the json monitor). The command sent to the qemu monitor looks like this:
{"execute":"query-rx-filter", "arguments": {"name":"net2"} }'
and the results will look something like this:
{
"return": [
{
"promiscuous": false,
"name": "net2",
"main-mac": "52:54:00:98:2d:e3",
"unicast": "normal",
"vlan": "normal",
"vlan-table": [
42,
0
],
"unicast-table": [
],
"multicast": "normal",
"multicast-overflow": false,
"unicast-overflow": false,
"multicast-table": [
"33:33:ff:98:2d:e3",
"01:80:c2:00:00:21",
"01:00:5e:00:00:fb",
"33:33:ff:98:2d:e2",
"01:00:5e:00:00:01",
"33:33:00:00:00:01"
],
"broadcast-allowed": false
}
],
"id": "libvirt-14"
}
This is all parsed from JSON into a virNetDevRxFilter object for
easier consumption. (unicast-table is usually empty, but is also an
array of mac addresses similar to multicast-table).
(NB: LIBNL_CFLAGS was added to tests/Makefile.am because virnetdev.h
now includes util/virnetlink.h, which includes netlink/msg.h when
appropriate. Without LIBNL_CFLAGS, gcc can't find that file (if
libnl/netlink isn't available, LIBNL_CFLAGS will be empty and
virnetlink.h won't try to include netlink/msg.h anyway).)
2014-09-22 16:19:41 +00:00
|
|
|
static int
|
|
|
|
qemuMonitorJSONQueryRxFilterParse(virJSONValuePtr msg,
|
|
|
|
virNetDevRxFilterPtr *filter)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
const char *tmp;
|
|
|
|
virJSONValuePtr returnArray, entry, table, element;
|
2015-10-08 08:17:42 +00:00
|
|
|
ssize_t nTable;
|
qemu: qemuMonitorQueryRxFilter - retrieve guest netdev rx-filter
This function can be called at any time to get the current status of a
guest's network device rx-filter. In particular it is useful to call
after libvirt recieves a NIC_RX_FILTER_CHANGED event - this event only
tells you that something has changed in the rx-filter, the details are
retrieved with the query-rx-filter monitor command (only available in
the json monitor). The command sent to the qemu monitor looks like this:
{"execute":"query-rx-filter", "arguments": {"name":"net2"} }'
and the results will look something like this:
{
"return": [
{
"promiscuous": false,
"name": "net2",
"main-mac": "52:54:00:98:2d:e3",
"unicast": "normal",
"vlan": "normal",
"vlan-table": [
42,
0
],
"unicast-table": [
],
"multicast": "normal",
"multicast-overflow": false,
"unicast-overflow": false,
"multicast-table": [
"33:33:ff:98:2d:e3",
"01:80:c2:00:00:21",
"01:00:5e:00:00:fb",
"33:33:ff:98:2d:e2",
"01:00:5e:00:00:01",
"33:33:00:00:00:01"
],
"broadcast-allowed": false
}
],
"id": "libvirt-14"
}
This is all parsed from JSON into a virNetDevRxFilter object for
easier consumption. (unicast-table is usually empty, but is also an
array of mac addresses similar to multicast-table).
(NB: LIBNL_CFLAGS was added to tests/Makefile.am because virnetdev.h
now includes util/virnetlink.h, which includes netlink/msg.h when
appropriate. Without LIBNL_CFLAGS, gcc can't find that file (if
libnl/netlink isn't available, LIBNL_CFLAGS will be empty and
virnetlink.h won't try to include netlink/msg.h anyway).)
2014-09-22 16:19:41 +00:00
|
|
|
size_t i;
|
|
|
|
virNetDevRxFilterPtr fil = virNetDevRxFilterNew();
|
|
|
|
|
|
|
|
if (!fil)
|
|
|
|
goto cleanup;
|
|
|
|
|
qemu: simplify json parsing
Rather than grabbing an arbitrary JSON value and then checking
if it has the right type, we might as well request the correct
type to begin with.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONIOProcessEvent)
(qemuMonitorJSONCommandWithFd, qemuMonitorJSONHandleGraphics)
(qemuMonitorJSONGetStatus, qemuMonitorJSONExtractCPUInfo)
(qemuMonitorJSONGetVirtType, qemuMonitorJSONGetBalloonInfo)
(qemuMonitorJSONGetMemoryStats)
(qemuMonitorJSONDevGetBlockExtent)
(qemuMonitorJSONGetOneBlockStatsInfo)
(qemuMonitorJSONGetAllBlockStatsInfo)
(qemuMonitorJSONBlockStatsUpdateCapacityOne)
(qemuMonitorJSONBlockStatsUpdateCapacity)
(qemuMonitorJSONGetBlockExtent)
(qemuMonitorJSONGetMigrationStatusReply)
(qemuMonitorJSONGetDumpGuestMemoryCapability)
(qemuMonitorJSONAddFd, qemuMonitorJSONQueryRxFilterParse)
(qemuMonitorJSONExtractChardevInfo)
(qemuMonitorJSONDiskNameLookupOne)
(qemuMonitorJSONDiskNameLookup)
(qemuMonitorJSONGetAllBlockJobInfo)
(qemuMonitorJSONBlockIoThrottleInfo, qemuMonitorJSONGetVersion)
(qemuMonitorJSONGetMachines, qemuMonitorJSONGetCPUDefinitions)
(qemuMonitorJSONGetCommands, qemuMonitorJSONGetEvents)
(qemuMonitorJSONGetKVMState, qemuMonitorJSONGetObjectTypes)
(qemuMonitorJSONGetObjectListPaths)
(qemuMonitorJSONGetObjectProps, qemuMonitorJSONGetTargetArch)
(qemuMonitorJSONGetMigrationCapabilities)
(qemuMonitorJSONGetStringArray, qemuMonitorJSONAttachCharDev)
(qemuMonitorJSONGetCPUx86Data, qemuMonitorJSONGetIOThreads)
(qemuMonitorJSONGetMemoryDeviceInfo): Use shorter idioms.
Signed-off-by: Eric Blake <eblake@redhat.com>
2015-06-20 19:40:21 +00:00
|
|
|
if (!(returnArray = virJSONValueObjectGetArray(msg, "return"))) {
|
qemu: qemuMonitorQueryRxFilter - retrieve guest netdev rx-filter
This function can be called at any time to get the current status of a
guest's network device rx-filter. In particular it is useful to call
after libvirt recieves a NIC_RX_FILTER_CHANGED event - this event only
tells you that something has changed in the rx-filter, the details are
retrieved with the query-rx-filter monitor command (only available in
the json monitor). The command sent to the qemu monitor looks like this:
{"execute":"query-rx-filter", "arguments": {"name":"net2"} }'
and the results will look something like this:
{
"return": [
{
"promiscuous": false,
"name": "net2",
"main-mac": "52:54:00:98:2d:e3",
"unicast": "normal",
"vlan": "normal",
"vlan-table": [
42,
0
],
"unicast-table": [
],
"multicast": "normal",
"multicast-overflow": false,
"unicast-overflow": false,
"multicast-table": [
"33:33:ff:98:2d:e3",
"01:80:c2:00:00:21",
"01:00:5e:00:00:fb",
"33:33:ff:98:2d:e2",
"01:00:5e:00:00:01",
"33:33:00:00:00:01"
],
"broadcast-allowed": false
}
],
"id": "libvirt-14"
}
This is all parsed from JSON into a virNetDevRxFilter object for
easier consumption. (unicast-table is usually empty, but is also an
array of mac addresses similar to multicast-table).
(NB: LIBNL_CFLAGS was added to tests/Makefile.am because virnetdev.h
now includes util/virnetlink.h, which includes netlink/msg.h when
appropriate. Without LIBNL_CFLAGS, gcc can't find that file (if
libnl/netlink isn't available, LIBNL_CFLAGS will be empty and
virnetlink.h won't try to include netlink/msg.h anyway).)
2014-09-22 16:19:41 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-rx-filter reply was missing return data"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (!(entry = virJSONValueArrayGet(returnArray, 0))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query -rx-filter return data missing array element"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(tmp = virJSONValueObjectGetString(entry, "name"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing or invalid name "
|
|
|
|
"in query-rx-filter response"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (VIR_STRDUP(fil->name, tmp) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
if ((!(tmp = virJSONValueObjectGetString(entry, "main-mac"))) ||
|
|
|
|
virMacAddrParse(tmp, &fil->mac) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing or invalid 'main-mac' "
|
|
|
|
"in query-rx-filter response"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (virJSONValueObjectGetBoolean(entry, "promiscuous",
|
|
|
|
&fil->promiscuous) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing or invalid 'promiscuous' "
|
|
|
|
"in query-rx-filter response"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (virJSONValueObjectGetBoolean(entry, "broadcast-allowed",
|
|
|
|
&fil->broadcastAllowed) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing or invalid 'broadcast-allowed' "
|
|
|
|
"in query-rx-filter response"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((!(tmp = virJSONValueObjectGetString(entry, "unicast"))) ||
|
|
|
|
((fil->unicast.mode
|
|
|
|
= virNetDevRxFilterModeTypeFromString(tmp)) < 0)) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing or invalid 'unicast' "
|
|
|
|
"in query-rx-filter response"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (virJSONValueObjectGetBoolean(entry, "unicast-overflow",
|
|
|
|
&fil->unicast.overflow) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing or invalid 'unicast-overflow' "
|
|
|
|
"in query-rx-filter response"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if ((!(table = virJSONValueObjectGet(entry, "unicast-table"))) ||
|
|
|
|
((nTable = virJSONValueArraySize(table)) < 0)) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing or invalid 'unicast-table' array "
|
|
|
|
"in query-rx-filter response"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (VIR_ALLOC_N(fil->unicast.table, nTable))
|
|
|
|
goto cleanup;
|
|
|
|
for (i = 0; i < nTable; i++) {
|
|
|
|
if (!(element = virJSONValueArrayGet(table, i)) ||
|
|
|
|
!(tmp = virJSONValueGetString(element))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Missing or invalid element %zu of 'unicast' "
|
|
|
|
"list in query-rx-filter response"), i);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (virMacAddrParse(tmp, &fil->unicast.table[i]) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("invalid mac address '%s' in 'unicast-table' "
|
|
|
|
"array in query-rx-filter response"), tmp);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fil->unicast.nTable = nTable;
|
|
|
|
|
|
|
|
if ((!(tmp = virJSONValueObjectGetString(entry, "multicast"))) ||
|
|
|
|
((fil->multicast.mode
|
|
|
|
= virNetDevRxFilterModeTypeFromString(tmp)) < 0)) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing or invalid 'multicast' "
|
|
|
|
"in query-rx-filter response"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (virJSONValueObjectGetBoolean(entry, "multicast-overflow",
|
|
|
|
&fil->multicast.overflow) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing or invalid 'multicast-overflow' "
|
|
|
|
"in query-rx-filter response"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if ((!(table = virJSONValueObjectGet(entry, "multicast-table"))) ||
|
|
|
|
((nTable = virJSONValueArraySize(table)) < 0)) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing or invalid 'multicast-table' array "
|
|
|
|
"in query-rx-filter response"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (VIR_ALLOC_N(fil->multicast.table, nTable))
|
|
|
|
goto cleanup;
|
|
|
|
for (i = 0; i < nTable; i++) {
|
|
|
|
if (!(element = virJSONValueArrayGet(table, i)) ||
|
|
|
|
!(tmp = virJSONValueGetString(element))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Missing or invalid element %zu of 'multicast' "
|
|
|
|
"list in query-rx-filter response"), i);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (virMacAddrParse(tmp, &fil->multicast.table[i]) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("invalid mac address '%s' in 'multicast-table' "
|
|
|
|
"array in query-rx-filter response"), tmp);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fil->multicast.nTable = nTable;
|
|
|
|
|
|
|
|
if ((!(tmp = virJSONValueObjectGetString(entry, "vlan"))) ||
|
|
|
|
((fil->vlan.mode
|
|
|
|
= virNetDevRxFilterModeTypeFromString(tmp)) < 0)) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing or invalid 'vlan' "
|
|
|
|
"in query-rx-filter response"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if ((!(table = virJSONValueObjectGet(entry, "vlan-table"))) ||
|
|
|
|
((nTable = virJSONValueArraySize(table)) < 0)) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Missing or invalid 'vlan-table' array "
|
|
|
|
"in query-rx-filter response"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (VIR_ALLOC_N(fil->vlan.table, nTable))
|
|
|
|
goto cleanup;
|
|
|
|
for (i = 0; i < nTable; i++) {
|
|
|
|
if (!(element = virJSONValueArrayGet(table, i)) ||
|
|
|
|
virJSONValueGetNumberUint(element, &fil->vlan.table[i]) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Missing or invalid element %zu of 'vlan-table' "
|
|
|
|
"array in query-rx-filter response"), i);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fil->vlan.nTable = nTable;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
if (ret < 0) {
|
|
|
|
virNetDevRxFilterFree(fil);
|
|
|
|
fil = NULL;
|
|
|
|
}
|
|
|
|
*filter = fil;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
qemuMonitorJSONQueryRxFilter(qemuMonitorPtr mon, const char *alias,
|
|
|
|
virNetDevRxFilterPtr *filter)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("query-rx-filter",
|
|
|
|
"s:name", alias,
|
|
|
|
NULL);
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
|
|
|
|
if (!cmd)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2016-05-03 08:44:13 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
qemu: qemuMonitorQueryRxFilter - retrieve guest netdev rx-filter
This function can be called at any time to get the current status of a
guest's network device rx-filter. In particular it is useful to call
after libvirt recieves a NIC_RX_FILTER_CHANGED event - this event only
tells you that something has changed in the rx-filter, the details are
retrieved with the query-rx-filter monitor command (only available in
the json monitor). The command sent to the qemu monitor looks like this:
{"execute":"query-rx-filter", "arguments": {"name":"net2"} }'
and the results will look something like this:
{
"return": [
{
"promiscuous": false,
"name": "net2",
"main-mac": "52:54:00:98:2d:e3",
"unicast": "normal",
"vlan": "normal",
"vlan-table": [
42,
0
],
"unicast-table": [
],
"multicast": "normal",
"multicast-overflow": false,
"unicast-overflow": false,
"multicast-table": [
"33:33:ff:98:2d:e3",
"01:80:c2:00:00:21",
"01:00:5e:00:00:fb",
"33:33:ff:98:2d:e2",
"01:00:5e:00:00:01",
"33:33:00:00:00:01"
],
"broadcast-allowed": false
}
],
"id": "libvirt-14"
}
This is all parsed from JSON into a virNetDevRxFilter object for
easier consumption. (unicast-table is usually empty, but is also an
array of mac addresses similar to multicast-table).
(NB: LIBNL_CFLAGS was added to tests/Makefile.am because virnetdev.h
now includes util/virnetlink.h, which includes netlink/msg.h when
appropriate. Without LIBNL_CFLAGS, gcc can't find that file (if
libnl/netlink isn't available, LIBNL_CFLAGS will be empty and
virnetlink.h won't try to include netlink/msg.h anyway).)
2014-09-22 16:19:41 +00:00
|
|
|
if (qemuMonitorJSONQueryRxFilterParse(reply, filter) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
if (ret < 0) {
|
|
|
|
virNetDevRxFilterFree(*filter);
|
|
|
|
*filter = NULL;
|
|
|
|
}
|
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-22 13:22:53 +00:00
|
|
|
/*
|
|
|
|
* Example return data
|
|
|
|
*
|
|
|
|
* {"return": [
|
|
|
|
* {"filename": "stdio", "label": "monitor"},
|
2014-11-13 18:29:14 +00:00
|
|
|
* {"filename": "pty:/dev/pts/6", "label": "serial0", "frontend-open": true},
|
2010-01-22 13:22:53 +00:00
|
|
|
* {"filename": "pty:/dev/pts/7", "label": "parallel0"}
|
|
|
|
* ]}
|
|
|
|
*
|
|
|
|
*/
|
2014-11-13 15:17:21 +00:00
|
|
|
static int
|
|
|
|
qemuMonitorJSONExtractChardevInfo(virJSONValuePtr reply,
|
|
|
|
virHashTablePtr info)
|
2010-01-22 13:22:53 +00:00
|
|
|
{
|
|
|
|
virJSONValuePtr data;
|
|
|
|
int ret = -1;
|
Convert 'int i' to 'size_t i' in src/qemu files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2014-11-13 18:29:14 +00:00
|
|
|
qemuMonitorChardevInfoPtr entry = NULL;
|
2010-01-22 13:22:53 +00:00
|
|
|
|
qemu: simplify json parsing
Rather than grabbing an arbitrary JSON value and then checking
if it has the right type, we might as well request the correct
type to begin with.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONIOProcessEvent)
(qemuMonitorJSONCommandWithFd, qemuMonitorJSONHandleGraphics)
(qemuMonitorJSONGetStatus, qemuMonitorJSONExtractCPUInfo)
(qemuMonitorJSONGetVirtType, qemuMonitorJSONGetBalloonInfo)
(qemuMonitorJSONGetMemoryStats)
(qemuMonitorJSONDevGetBlockExtent)
(qemuMonitorJSONGetOneBlockStatsInfo)
(qemuMonitorJSONGetAllBlockStatsInfo)
(qemuMonitorJSONBlockStatsUpdateCapacityOne)
(qemuMonitorJSONBlockStatsUpdateCapacity)
(qemuMonitorJSONGetBlockExtent)
(qemuMonitorJSONGetMigrationStatusReply)
(qemuMonitorJSONGetDumpGuestMemoryCapability)
(qemuMonitorJSONAddFd, qemuMonitorJSONQueryRxFilterParse)
(qemuMonitorJSONExtractChardevInfo)
(qemuMonitorJSONDiskNameLookupOne)
(qemuMonitorJSONDiskNameLookup)
(qemuMonitorJSONGetAllBlockJobInfo)
(qemuMonitorJSONBlockIoThrottleInfo, qemuMonitorJSONGetVersion)
(qemuMonitorJSONGetMachines, qemuMonitorJSONGetCPUDefinitions)
(qemuMonitorJSONGetCommands, qemuMonitorJSONGetEvents)
(qemuMonitorJSONGetKVMState, qemuMonitorJSONGetObjectTypes)
(qemuMonitorJSONGetObjectListPaths)
(qemuMonitorJSONGetObjectProps, qemuMonitorJSONGetTargetArch)
(qemuMonitorJSONGetMigrationCapabilities)
(qemuMonitorJSONGetStringArray, qemuMonitorJSONAttachCharDev)
(qemuMonitorJSONGetCPUx86Data, qemuMonitorJSONGetIOThreads)
(qemuMonitorJSONGetMemoryDeviceInfo): Use shorter idioms.
Signed-off-by: Eric Blake <eblake@redhat.com>
2015-06-20 19:40:21 +00:00
|
|
|
if (!(data = virJSONValueObjectGetArray(reply, "return"))) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("character device reply was missing return data"));
|
2010-01-22 13:22:53 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-05-21 07:21:20 +00:00
|
|
|
for (i = 0; i < virJSONValueArraySize(data); i++) {
|
2014-11-13 18:29:14 +00:00
|
|
|
virJSONValuePtr chardev = virJSONValueArrayGet(data, i);
|
2010-01-22 13:22:53 +00:00
|
|
|
const char *type;
|
2014-11-13 18:29:14 +00:00
|
|
|
const char *alias;
|
|
|
|
bool connected;
|
|
|
|
|
|
|
|
if (!chardev) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("character device information was missing array element"));
|
2010-01-22 13:22:53 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-11-13 18:29:14 +00:00
|
|
|
if (!(alias = virJSONValueObjectGetString(chardev, "label"))) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
2014-11-13 18:29:14 +00:00
|
|
|
_("character device information was missing label"));
|
2010-01-22 13:22:53 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-11-13 18:29:14 +00:00
|
|
|
if (!(type = virJSONValueObjectGetString(chardev, "filename"))) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("character device information was missing filename"));
|
2010-01-22 13:22:53 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-11-13 18:29:14 +00:00
|
|
|
if (VIR_ALLOC(entry) < 0)
|
|
|
|
goto cleanup;
|
2010-01-22 13:22:53 +00:00
|
|
|
|
2014-11-13 18:29:14 +00:00
|
|
|
if (STRPREFIX(type, "pty:") &&
|
|
|
|
VIR_STRDUP(entry->ptyPath, type + strlen("pty:")) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virJSONValueObjectGetBoolean(chardev, "frontend-open", &connected) == 0) {
|
|
|
|
if (connected)
|
|
|
|
entry->state = VIR_DOMAIN_CHR_DEVICE_STATE_CONNECTED;
|
|
|
|
else
|
|
|
|
entry->state = VIR_DOMAIN_CHR_DEVICE_STATE_DISCONNECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virHashAddEntry(info, alias, entry) < 0) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
|
|
|
_("failed to add chardev '%s' info"), alias);
|
|
|
|
goto cleanup;
|
2010-01-22 13:22:53 +00:00
|
|
|
}
|
2014-11-13 18:29:14 +00:00
|
|
|
|
|
|
|
entry = NULL;
|
2010-01-22 13:22:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2014-11-13 18:29:14 +00:00
|
|
|
if (entry) {
|
|
|
|
VIR_FREE(entry->ptyPath);
|
|
|
|
VIR_FREE(entry);
|
|
|
|
}
|
|
|
|
|
2010-01-22 13:22:53 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-11-13 15:17:21 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
qemuMonitorJSONGetChardevInfo(qemuMonitorPtr mon,
|
|
|
|
virHashTablePtr info)
|
2010-01-22 13:22:53 +00:00
|
|
|
|
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2010-01-22 13:22:53 +00:00
|
|
|
virJSONValuePtr cmd = qemuMonitorJSONMakeCommand("query-chardev",
|
|
|
|
NULL);
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2010-01-22 13:22:53 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2010-01-22 13:22:53 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = qemuMonitorJSONExtractChardevInfo(reply, info);
|
|
|
|
cleanup:
|
2010-01-22 13:22:53 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-02 08:40:51 +00:00
|
|
|
int qemuMonitorJSONDelDevice(qemuMonitorPtr mon,
|
2010-04-14 14:36:42 +00:00
|
|
|
const char *devalias)
|
2010-03-02 08:40:51 +00:00
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2010-03-02 08:40:51 +00:00
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
|
|
|
|
cmd = qemuMonitorJSONMakeCommand("device_del",
|
2010-04-15 11:17:29 +00:00
|
|
|
"s:id", devalias,
|
2010-03-02 08:40:51 +00:00
|
|
|
NULL);
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2010-03-02 08:40:51 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2010-03-02 08:40:51 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2010-03-02 08:40:51 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-31 13:26:12 +00:00
|
|
|
int
|
|
|
|
qemuMonitorJSONAddDeviceArgs(qemuMonitorPtr mon,
|
|
|
|
virJSONValuePtr args)
|
2010-01-26 15:34:46 +00:00
|
|
|
{
|
2010-04-14 15:02:37 +00:00
|
|
|
int ret = -1;
|
2016-07-31 13:26:12 +00:00
|
|
|
virJSONValuePtr cmd = NULL;
|
2010-01-26 15:34:46 +00:00
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
|
2016-07-31 13:26:12 +00:00
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("device_add", NULL)))
|
2010-04-14 15:02:37 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-07-04 10:14:12 +00:00
|
|
|
if (virJSONValueObjectAppend(cmd, "arguments", args) < 0)
|
2010-04-14 15:02:37 +00:00
|
|
|
goto cleanup;
|
|
|
|
args = NULL; /* obj owns reference to args now */
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2010-01-26 15:34:46 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2010-01-26 15:34:46 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2010-04-14 15:02:37 +00:00
|
|
|
virJSONValueFree(args);
|
2010-01-26 15:34:46 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-31 13:26:12 +00:00
|
|
|
int
|
|
|
|
qemuMonitorJSONAddDevice(qemuMonitorPtr mon,
|
|
|
|
const char *devicestr)
|
|
|
|
{
|
|
|
|
virJSONValuePtr args;
|
|
|
|
|
|
|
|
if (!(args = qemuMonitorJSONKeywordStringToJSON(devicestr, "driver")))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return qemuMonitorJSONAddDeviceArgs(mon, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-23 11:25:25 +00:00
|
|
|
int qemuMonitorJSONAddObject(qemuMonitorPtr mon,
|
|
|
|
const char *type,
|
|
|
|
const char *objalias,
|
|
|
|
virJSONValuePtr props)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
|
|
|
|
cmd = qemuMonitorJSONMakeCommand("object-add",
|
|
|
|
"s:qom-type", type,
|
|
|
|
"s:id", objalias,
|
|
|
|
"A:props", props,
|
|
|
|
NULL);
|
|
|
|
if (!cmd)
|
|
|
|
goto cleanup;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
/* @props is part of @cmd now. Avoid double free */
|
2014-09-23 11:25:25 +00:00
|
|
|
props = NULL;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2014-09-23 11:25:25 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2014-09-23 11:25:25 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
2014-09-23 11:25:25 +00:00
|
|
|
cleanup:
|
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
virJSONValueFree(props);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorJSONDelObject(qemuMonitorPtr mon,
|
|
|
|
const char *objalias)
|
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2014-09-23 11:25:25 +00:00
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
|
|
|
|
cmd = qemuMonitorJSONMakeCommand("object-del",
|
|
|
|
"s:id", objalias,
|
|
|
|
NULL);
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2014-09-23 11:25:25 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2014-09-23 11:25:25 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2014-09-23 11:25:25 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-11 14:28:16 +00:00
|
|
|
int qemuMonitorJSONSetDrivePassphrase(qemuMonitorPtr mon,
|
|
|
|
const char *alias,
|
|
|
|
const char *passphrase)
|
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2010-02-11 14:28:16 +00:00
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
|
|
|
|
cmd = qemuMonitorJSONMakeCommand("block_passwd",
|
2016-08-01 12:11:44 +00:00
|
|
|
"s:device", alias,
|
2010-02-11 14:28:16 +00:00
|
|
|
"s:password", passphrase,
|
|
|
|
NULL);
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2010-02-11 14:28:16 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2010-02-11 14:28:16 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2010-02-11 14:28:16 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
2010-04-02 14:10:37 +00:00
|
|
|
|
|
|
|
int qemuMonitorJSONCreateSnapshot(qemuMonitorPtr mon, const char *name)
|
|
|
|
{
|
qemu: don't attempt undefined QMP commands
https://bugzilla.redhat.com/show_bug.cgi?id=872292
Libvirt should not attempt to call a QMP command that has not been
documented in qemu.git - if future qemu introduces a command by the
same name but with subtly different semantics, then libvirt will be
broken when trying to use that command.
We also had some code that could never be reached - some of our
commands have an alternate for new vs. old qemu HMP commands; but
if we are new enough to support QMP, we only need a fallback to
the new HMP counterpart, and don't need to try for a QMP counterpart
for the old HMP version.
See also this attempt to convert the three snapshot commands to QMP:
https://lists.gnu.org/archive/html/qemu-devel/2012-07/msg01597.html
although it looks like that will still not happen before qemu 1.3.
That thread eventually decided that qemu would use the name
'save-vm' rather than 'savevm', which mitigates the fact that
libvirt's attempt to use a QMP 'savevm' would be broken, but we
might not be as lucky on the other commands.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONSetCPU)
(qemuMonitorJSONAddDrive, qemuMonitorJSONDriveDel)
(qemuMonitorJSONCreateSnapshot, qemuMonitorJSONLoadSnapshot)
(qemuMonitorJSONDeleteSnapshot): Use only HMP fallback for now.
(qemuMonitorJSONAddHostNetwork, qemuMonitorJSONRemoveHostNetwork)
(qemuMonitorJSONAttachDrive, qemuMonitorJSONGetGuestDriveAddress):
Delete; QMP implies QEMU_CAPS_DEVICE, which prefers AddNetdev,
RemoveNetdev, and AddDrive anyways (qemu_hotplug.c has all callers).
* src/qemu/qemu_monitor.c (qemuMonitorAddHostNetwork)
(qemuMonitorRemoveHostNetwork, qemuMonitorAttachDrive): Reflect
deleted commands.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONAddHostNetwork)
(qemuMonitorJSONRemoveHostNetwork, qemuMonitorJSONAttachDrive):
Likewise.
2012-11-30 00:35:23 +00:00
|
|
|
/* XXX Update to use QMP, if QMP ever adds support for savevm */
|
|
|
|
VIR_DEBUG("savevm command not found, trying HMP");
|
|
|
|
return qemuMonitorTextCreateSnapshot(mon, name);
|
2010-04-02 14:10:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int qemuMonitorJSONLoadSnapshot(qemuMonitorPtr mon, const char *name)
|
|
|
|
{
|
qemu: don't attempt undefined QMP commands
https://bugzilla.redhat.com/show_bug.cgi?id=872292
Libvirt should not attempt to call a QMP command that has not been
documented in qemu.git - if future qemu introduces a command by the
same name but with subtly different semantics, then libvirt will be
broken when trying to use that command.
We also had some code that could never be reached - some of our
commands have an alternate for new vs. old qemu HMP commands; but
if we are new enough to support QMP, we only need a fallback to
the new HMP counterpart, and don't need to try for a QMP counterpart
for the old HMP version.
See also this attempt to convert the three snapshot commands to QMP:
https://lists.gnu.org/archive/html/qemu-devel/2012-07/msg01597.html
although it looks like that will still not happen before qemu 1.3.
That thread eventually decided that qemu would use the name
'save-vm' rather than 'savevm', which mitigates the fact that
libvirt's attempt to use a QMP 'savevm' would be broken, but we
might not be as lucky on the other commands.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONSetCPU)
(qemuMonitorJSONAddDrive, qemuMonitorJSONDriveDel)
(qemuMonitorJSONCreateSnapshot, qemuMonitorJSONLoadSnapshot)
(qemuMonitorJSONDeleteSnapshot): Use only HMP fallback for now.
(qemuMonitorJSONAddHostNetwork, qemuMonitorJSONRemoveHostNetwork)
(qemuMonitorJSONAttachDrive, qemuMonitorJSONGetGuestDriveAddress):
Delete; QMP implies QEMU_CAPS_DEVICE, which prefers AddNetdev,
RemoveNetdev, and AddDrive anyways (qemu_hotplug.c has all callers).
* src/qemu/qemu_monitor.c (qemuMonitorAddHostNetwork)
(qemuMonitorRemoveHostNetwork, qemuMonitorAttachDrive): Reflect
deleted commands.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONAddHostNetwork)
(qemuMonitorJSONRemoveHostNetwork, qemuMonitorJSONAttachDrive):
Likewise.
2012-11-30 00:35:23 +00:00
|
|
|
/* XXX Update to use QMP, if QMP ever adds support for loadvm */
|
|
|
|
VIR_DEBUG("loadvm command not found, trying HMP");
|
|
|
|
return qemuMonitorTextLoadSnapshot(mon, name);
|
2010-04-02 14:10:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int qemuMonitorJSONDeleteSnapshot(qemuMonitorPtr mon, const char *name)
|
|
|
|
{
|
qemu: don't attempt undefined QMP commands
https://bugzilla.redhat.com/show_bug.cgi?id=872292
Libvirt should not attempt to call a QMP command that has not been
documented in qemu.git - if future qemu introduces a command by the
same name but with subtly different semantics, then libvirt will be
broken when trying to use that command.
We also had some code that could never be reached - some of our
commands have an alternate for new vs. old qemu HMP commands; but
if we are new enough to support QMP, we only need a fallback to
the new HMP counterpart, and don't need to try for a QMP counterpart
for the old HMP version.
See also this attempt to convert the three snapshot commands to QMP:
https://lists.gnu.org/archive/html/qemu-devel/2012-07/msg01597.html
although it looks like that will still not happen before qemu 1.3.
That thread eventually decided that qemu would use the name
'save-vm' rather than 'savevm', which mitigates the fact that
libvirt's attempt to use a QMP 'savevm' would be broken, but we
might not be as lucky on the other commands.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONSetCPU)
(qemuMonitorJSONAddDrive, qemuMonitorJSONDriveDel)
(qemuMonitorJSONCreateSnapshot, qemuMonitorJSONLoadSnapshot)
(qemuMonitorJSONDeleteSnapshot): Use only HMP fallback for now.
(qemuMonitorJSONAddHostNetwork, qemuMonitorJSONRemoveHostNetwork)
(qemuMonitorJSONAttachDrive, qemuMonitorJSONGetGuestDriveAddress):
Delete; QMP implies QEMU_CAPS_DEVICE, which prefers AddNetdev,
RemoveNetdev, and AddDrive anyways (qemu_hotplug.c has all callers).
* src/qemu/qemu_monitor.c (qemuMonitorAddHostNetwork)
(qemuMonitorRemoveHostNetwork, qemuMonitorAttachDrive): Reflect
deleted commands.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONAddHostNetwork)
(qemuMonitorJSONRemoveHostNetwork, qemuMonitorJSONAttachDrive):
Likewise.
2012-11-30 00:35:23 +00:00
|
|
|
/* XXX Update to use QMP, if QMP ever adds support for delvm */
|
|
|
|
VIR_DEBUG("delvm command not found, trying HMP");
|
|
|
|
return qemuMonitorTextDeleteSnapshot(mon, name);
|
2010-04-02 14:10:37 +00:00
|
|
|
}
|
2010-04-17 02:12:45 +00:00
|
|
|
|
2011-08-15 23:25:54 +00:00
|
|
|
int
|
2012-03-17 04:17:28 +00:00
|
|
|
qemuMonitorJSONDiskSnapshot(qemuMonitorPtr mon, virJSONValuePtr actions,
|
snapshot: improve qemu handling of reused snapshot targets
The oVirt developers have stated that the real reasons they want
to have qemu reuse existing volumes when creating a snapshot are:
1. the management framework is set up so that creation has to be
done from a central node for proper resource tracking, and having
libvirt and/or qemu create things violates the framework, and
2. qemu defaults to creating snapshots with an absolute path to
the backing file, but oVirt wants to manage a backing chain that
uses just relative names, to allow for easier migration of a chain
across storage locations.
When 0.9.10 added VIR_DOMAIN_SNAPSHOT_CREATE_REUSE_EXT (commit
4e9953a4), it only addressed point 1, but libvirt was still using
O_TRUNC which violates point 2. Meanwhile, the new qemu
'transaction' monitor command includes a new optional mode argument
that will force qemu to reuse the metadata of the file it just
opened (with the burden on the caller to have valid metadata there
in the first place). So, this tweaks the meaning of the flag to
cover both points as intended for use by oVirt. It is not strictly
backward-compatible to 0.9.10 behavior, but it can be argued that
the O_TRUNC of 0.9.10 was a bug.
Note that this flag is all-or-nothing, and only selects between
'existing' and the default 'absolute-paths'. A more flexible
approach that would allow per-disk selections, as well as adding
support for the 'no-backing-file' mode, would be possible by
extending the <domainsnapshot> xml to have a per-disk mode, but
until we have a management application expressing a need for that
additional complexity, it is not worth doing.
* src/libvirt.c (virDomainSnapshotCreateXML): Tweak documentation.
* src/qemu/qemu_monitor.h (qemuMonitorDiskSnapshot): Add
parameters.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONDiskSnapshot):
Likewise.
* src/qemu/qemu_monitor.c (qemuMonitorDiskSnapshot): Pass them
through.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONDiskSnapshot): Use
new monitor command arguments.
* src/qemu/qemu_driver.c (qemuDomainSnapshotCreateDiskActive)
(qemuDomainSnapshotCreateSingleDiskActive): Adjust callers.
(qemuDomainSnapshotDiskPrepare): Allow qed, modify rules on reuse.
2012-03-20 21:03:45 +00:00
|
|
|
const char *device, const char *file,
|
|
|
|
const char *format, bool reuse)
|
2011-08-15 23:25:54 +00:00
|
|
|
{
|
2012-04-11 21:40:16 +00:00
|
|
|
int ret = -1;
|
2011-08-15 23:25:54 +00:00
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
|
2012-03-17 04:17:28 +00:00
|
|
|
cmd = qemuMonitorJSONMakeCommandRaw(actions != NULL,
|
|
|
|
"blockdev-snapshot-sync",
|
|
|
|
"s:device", device,
|
|
|
|
"s:snapshot-file", file,
|
snapshot: improve qemu handling of reused snapshot targets
The oVirt developers have stated that the real reasons they want
to have qemu reuse existing volumes when creating a snapshot are:
1. the management framework is set up so that creation has to be
done from a central node for proper resource tracking, and having
libvirt and/or qemu create things violates the framework, and
2. qemu defaults to creating snapshots with an absolute path to
the backing file, but oVirt wants to manage a backing chain that
uses just relative names, to allow for easier migration of a chain
across storage locations.
When 0.9.10 added VIR_DOMAIN_SNAPSHOT_CREATE_REUSE_EXT (commit
4e9953a4), it only addressed point 1, but libvirt was still using
O_TRUNC which violates point 2. Meanwhile, the new qemu
'transaction' monitor command includes a new optional mode argument
that will force qemu to reuse the metadata of the file it just
opened (with the burden on the caller to have valid metadata there
in the first place). So, this tweaks the meaning of the flag to
cover both points as intended for use by oVirt. It is not strictly
backward-compatible to 0.9.10 behavior, but it can be argued that
the O_TRUNC of 0.9.10 was a bug.
Note that this flag is all-or-nothing, and only selects between
'existing' and the default 'absolute-paths'. A more flexible
approach that would allow per-disk selections, as well as adding
support for the 'no-backing-file' mode, would be possible by
extending the <domainsnapshot> xml to have a per-disk mode, but
until we have a management application expressing a need for that
additional complexity, it is not worth doing.
* src/libvirt.c (virDomainSnapshotCreateXML): Tweak documentation.
* src/qemu/qemu_monitor.h (qemuMonitorDiskSnapshot): Add
parameters.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONDiskSnapshot):
Likewise.
* src/qemu/qemu_monitor.c (qemuMonitorDiskSnapshot): Pass them
through.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONDiskSnapshot): Use
new monitor command arguments.
* src/qemu/qemu_driver.c (qemuDomainSnapshotCreateDiskActive)
(qemuDomainSnapshotCreateSingleDiskActive): Adjust callers.
(qemuDomainSnapshotDiskPrepare): Allow qed, modify rules on reuse.
2012-03-20 21:03:45 +00:00
|
|
|
"s:format", format,
|
2014-05-13 15:28:45 +00:00
|
|
|
"S:mode", reuse ? "existing" : NULL,
|
2012-03-17 04:17:28 +00:00
|
|
|
NULL);
|
2011-08-15 23:25:54 +00:00
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2012-03-17 04:17:28 +00:00
|
|
|
if (actions) {
|
2013-07-04 10:14:12 +00:00
|
|
|
if (virJSONValueArrayAppend(actions, cmd) == 0) {
|
2012-03-17 04:17:28 +00:00
|
|
|
ret = 0;
|
|
|
|
cmd = NULL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ((ret = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0)
|
2012-04-11 21:40:16 +00:00
|
|
|
goto cleanup;
|
2011-08-15 23:25:54 +00:00
|
|
|
|
2012-03-17 04:17:28 +00:00
|
|
|
ret = qemuMonitorJSONCheckError(cmd, reply);
|
2011-08-15 23:25:54 +00:00
|
|
|
}
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2012-03-17 04:17:28 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
blockjob: add qemu capabilities related to block jobs
Upstream qemu 1.3 is adding two new monitor commands, 'drive-mirror'
and 'block-job-complete'[1], which can drive live block copy and
storage migration. [Additionally, RHEL 6.3 had backported an earlier
version of most of the same functionality, but under the names
'__com.redhat_drive-mirror' and '__com.redhat_drive-reopen' and with
slightly different JSON arguments, and has been using patches similar
to these upstream patches for several months now.]
The libvirt API virDomainBlockRebase as already committed for 0.9.12
is flexible enough to expose the basics of block copy, but some
additional features in the 'drive-mirror' qemu command, such as
setting error policy, setting granularity, or using a persistent
bitmap, may later require a new libvirt API virDomainBlockCopy. I
will wait to add that API until we know more about what qemu 1.3
will finally provide.
This patch caters only to the upstream qemu 1.3 interface, although
I have proven that the changes for RHEL 6.3 can be isolated to
just qemu_monitor_json.c, and the rest of this series will
gracefully handle either interface once the JSON differences are
papered over in a downstream patch.
For consistency with other block job commands, libvirt must handle
the bandwidth argument as MiB/sec from the user, even though qemu
exposes the speed argument as bytes/sec; then again, qemu rounds
up to cluster size internally, so using MiB hides the worst effects
of that rounding if you pass small numbers.
[1]https://lists.gnu.org/archive/html/qemu-devel/2012-10/msg04123.html
* src/qemu/qemu_capabilities.h (QEMU_CAPS_DRIVE_MIRROR)
(QEMU_CAPS_DRIVE_REOPEN): New bits.
* src/qemu/qemu_capabilities.c (qemuCaps): Name them.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONCheckCommands): Set
them.
(qemuMonitorJSONDriveMirror, qemuMonitorDrivePivot): New functions.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONDriveMirror)
(qemuMonitorDrivePivot): Declare them.
* src/qemu/qemu_monitor.c (qemuMonitorDriveMirror)
(qemuMonitorDrivePivot): New passthroughs.
* src/qemu/qemu_monitor.h (qemuMonitorDriveMirror)
(qemuMonitorDrivePivot): Declare them.
2012-09-28 23:29:53 +00:00
|
|
|
/* speed is in bytes/sec */
|
|
|
|
int
|
|
|
|
qemuMonitorJSONDriveMirror(qemuMonitorPtr mon,
|
|
|
|
const char *device, const char *file,
|
|
|
|
const char *format, unsigned long long speed,
|
blockcopy: add qemu implementation of new tunables
Upstream qemu 1.4 added some drive-mirror tunables not present
when it was first introduced in 1.3. Management apps may want
to set these in some cases (for example, without tuning
granularity down to sector size, a copy may end up occupying
more bytes than the original because an entire cluster is
copied even when only a sector within the cluster is dirty,
although tuning it down results in more CPU time to do the
copy). I haven't personally needed to use the parameters, but
since they exist, and since the new API supports virTypedParams,
we might as well expose them.
Since the tuning parameters aren't often used, and omitted from
the QMP command when unspecified, I think it is safe to rely on
qemu 1.3 to issue an error about them being unsupported, rather
than trying to create a new capability bit in libvirt.
Meanwhile, all versions of qemu from 1.4 to 2.1 have a bug where
a bad granularity (such as non-power-of-2) gives a poor message:
error: internal error: unable to execute QEMU command 'drive-mirror': Invalid parameter 'drive-virtio-disk0'
because of abuse of QERR_INVALID_PARAMETER (which is supposed to
name the parameter that was given a bad value, rather than the
value passed to some other parameter). I don't see that a
capability check will help, so we'll just live with it (and it
has since been improved in upstream qemu).
* src/qemu/qemu_monitor.h (qemuMonitorDriveMirror): Add
parameters.
* src/qemu/qemu_monitor.c (qemuMonitorDriveMirror): Likewise.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONDriveMirror):
Likewise.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONDriveMirror):
Likewise.
* src/qemu/qemu_driver.c (qemuDomainBlockCopyCommon): Likewise.
(qemuDomainBlockRebase, qemuDomainBlockCopy): Adjust callers.
* src/qemu/qemu_migration.c (qemuMigrationDriveMirror): Likewise.
* tests/qemumonitorjsontest.c (qemuMonitorJSONDriveMirror): Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-09-08 20:53:12 +00:00
|
|
|
unsigned int granularity,
|
|
|
|
unsigned long long buf_size,
|
blockjob: add qemu capabilities related to block jobs
Upstream qemu 1.3 is adding two new monitor commands, 'drive-mirror'
and 'block-job-complete'[1], which can drive live block copy and
storage migration. [Additionally, RHEL 6.3 had backported an earlier
version of most of the same functionality, but under the names
'__com.redhat_drive-mirror' and '__com.redhat_drive-reopen' and with
slightly different JSON arguments, and has been using patches similar
to these upstream patches for several months now.]
The libvirt API virDomainBlockRebase as already committed for 0.9.12
is flexible enough to expose the basics of block copy, but some
additional features in the 'drive-mirror' qemu command, such as
setting error policy, setting granularity, or using a persistent
bitmap, may later require a new libvirt API virDomainBlockCopy. I
will wait to add that API until we know more about what qemu 1.3
will finally provide.
This patch caters only to the upstream qemu 1.3 interface, although
I have proven that the changes for RHEL 6.3 can be isolated to
just qemu_monitor_json.c, and the rest of this series will
gracefully handle either interface once the JSON differences are
papered over in a downstream patch.
For consistency with other block job commands, libvirt must handle
the bandwidth argument as MiB/sec from the user, even though qemu
exposes the speed argument as bytes/sec; then again, qemu rounds
up to cluster size internally, so using MiB hides the worst effects
of that rounding if you pass small numbers.
[1]https://lists.gnu.org/archive/html/qemu-devel/2012-10/msg04123.html
* src/qemu/qemu_capabilities.h (QEMU_CAPS_DRIVE_MIRROR)
(QEMU_CAPS_DRIVE_REOPEN): New bits.
* src/qemu/qemu_capabilities.c (qemuCaps): Name them.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONCheckCommands): Set
them.
(qemuMonitorJSONDriveMirror, qemuMonitorDrivePivot): New functions.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONDriveMirror)
(qemuMonitorDrivePivot): Declare them.
* src/qemu/qemu_monitor.c (qemuMonitorDriveMirror)
(qemuMonitorDrivePivot): New passthroughs.
* src/qemu/qemu_monitor.h (qemuMonitorDriveMirror)
(qemuMonitorDrivePivot): Declare them.
2012-09-28 23:29:53 +00:00
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
bool shallow = (flags & VIR_DOMAIN_BLOCK_REBASE_SHALLOW) != 0;
|
|
|
|
bool reuse = (flags & VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT) != 0;
|
|
|
|
|
|
|
|
cmd = qemuMonitorJSONMakeCommand("drive-mirror",
|
|
|
|
"s:device", device,
|
|
|
|
"s:target", file,
|
2014-09-05 11:31:47 +00:00
|
|
|
"Y:speed", speed,
|
blockcopy: add qemu implementation of new tunables
Upstream qemu 1.4 added some drive-mirror tunables not present
when it was first introduced in 1.3. Management apps may want
to set these in some cases (for example, without tuning
granularity down to sector size, a copy may end up occupying
more bytes than the original because an entire cluster is
copied even when only a sector within the cluster is dirty,
although tuning it down results in more CPU time to do the
copy). I haven't personally needed to use the parameters, but
since they exist, and since the new API supports virTypedParams,
we might as well expose them.
Since the tuning parameters aren't often used, and omitted from
the QMP command when unspecified, I think it is safe to rely on
qemu 1.3 to issue an error about them being unsupported, rather
than trying to create a new capability bit in libvirt.
Meanwhile, all versions of qemu from 1.4 to 2.1 have a bug where
a bad granularity (such as non-power-of-2) gives a poor message:
error: internal error: unable to execute QEMU command 'drive-mirror': Invalid parameter 'drive-virtio-disk0'
because of abuse of QERR_INVALID_PARAMETER (which is supposed to
name the parameter that was given a bad value, rather than the
value passed to some other parameter). I don't see that a
capability check will help, so we'll just live with it (and it
has since been improved in upstream qemu).
* src/qemu/qemu_monitor.h (qemuMonitorDriveMirror): Add
parameters.
* src/qemu/qemu_monitor.c (qemuMonitorDriveMirror): Likewise.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONDriveMirror):
Likewise.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONDriveMirror):
Likewise.
* src/qemu/qemu_driver.c (qemuDomainBlockCopyCommon): Likewise.
(qemuDomainBlockRebase, qemuDomainBlockCopy): Adjust callers.
* src/qemu/qemu_migration.c (qemuMigrationDriveMirror): Likewise.
* tests/qemumonitorjsontest.c (qemuMonitorJSONDriveMirror): Likewise.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-09-08 20:53:12 +00:00
|
|
|
"z:granularity", granularity,
|
|
|
|
"P:buf-size", buf_size,
|
blockjob: add qemu capabilities related to block jobs
Upstream qemu 1.3 is adding two new monitor commands, 'drive-mirror'
and 'block-job-complete'[1], which can drive live block copy and
storage migration. [Additionally, RHEL 6.3 had backported an earlier
version of most of the same functionality, but under the names
'__com.redhat_drive-mirror' and '__com.redhat_drive-reopen' and with
slightly different JSON arguments, and has been using patches similar
to these upstream patches for several months now.]
The libvirt API virDomainBlockRebase as already committed for 0.9.12
is flexible enough to expose the basics of block copy, but some
additional features in the 'drive-mirror' qemu command, such as
setting error policy, setting granularity, or using a persistent
bitmap, may later require a new libvirt API virDomainBlockCopy. I
will wait to add that API until we know more about what qemu 1.3
will finally provide.
This patch caters only to the upstream qemu 1.3 interface, although
I have proven that the changes for RHEL 6.3 can be isolated to
just qemu_monitor_json.c, and the rest of this series will
gracefully handle either interface once the JSON differences are
papered over in a downstream patch.
For consistency with other block job commands, libvirt must handle
the bandwidth argument as MiB/sec from the user, even though qemu
exposes the speed argument as bytes/sec; then again, qemu rounds
up to cluster size internally, so using MiB hides the worst effects
of that rounding if you pass small numbers.
[1]https://lists.gnu.org/archive/html/qemu-devel/2012-10/msg04123.html
* src/qemu/qemu_capabilities.h (QEMU_CAPS_DRIVE_MIRROR)
(QEMU_CAPS_DRIVE_REOPEN): New bits.
* src/qemu/qemu_capabilities.c (qemuCaps): Name them.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONCheckCommands): Set
them.
(qemuMonitorJSONDriveMirror, qemuMonitorDrivePivot): New functions.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONDriveMirror)
(qemuMonitorDrivePivot): Declare them.
* src/qemu/qemu_monitor.c (qemuMonitorDriveMirror)
(qemuMonitorDrivePivot): New passthroughs.
* src/qemu/qemu_monitor.h (qemuMonitorDriveMirror)
(qemuMonitorDrivePivot): Declare them.
2012-09-28 23:29:53 +00:00
|
|
|
"s:sync", shallow ? "top" : "full",
|
2014-05-13 15:28:45 +00:00
|
|
|
"s:mode", reuse ? "existing" : "absolute-paths",
|
|
|
|
"S:format", format,
|
blockjob: add qemu capabilities related to block jobs
Upstream qemu 1.3 is adding two new monitor commands, 'drive-mirror'
and 'block-job-complete'[1], which can drive live block copy and
storage migration. [Additionally, RHEL 6.3 had backported an earlier
version of most of the same functionality, but under the names
'__com.redhat_drive-mirror' and '__com.redhat_drive-reopen' and with
slightly different JSON arguments, and has been using patches similar
to these upstream patches for several months now.]
The libvirt API virDomainBlockRebase as already committed for 0.9.12
is flexible enough to expose the basics of block copy, but some
additional features in the 'drive-mirror' qemu command, such as
setting error policy, setting granularity, or using a persistent
bitmap, may later require a new libvirt API virDomainBlockCopy. I
will wait to add that API until we know more about what qemu 1.3
will finally provide.
This patch caters only to the upstream qemu 1.3 interface, although
I have proven that the changes for RHEL 6.3 can be isolated to
just qemu_monitor_json.c, and the rest of this series will
gracefully handle either interface once the JSON differences are
papered over in a downstream patch.
For consistency with other block job commands, libvirt must handle
the bandwidth argument as MiB/sec from the user, even though qemu
exposes the speed argument as bytes/sec; then again, qemu rounds
up to cluster size internally, so using MiB hides the worst effects
of that rounding if you pass small numbers.
[1]https://lists.gnu.org/archive/html/qemu-devel/2012-10/msg04123.html
* src/qemu/qemu_capabilities.h (QEMU_CAPS_DRIVE_MIRROR)
(QEMU_CAPS_DRIVE_REOPEN): New bits.
* src/qemu/qemu_capabilities.c (qemuCaps): Name them.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONCheckCommands): Set
them.
(qemuMonitorJSONDriveMirror, qemuMonitorDrivePivot): New functions.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONDriveMirror)
(qemuMonitorDrivePivot): Declare them.
* src/qemu/qemu_monitor.c (qemuMonitorDriveMirror)
(qemuMonitorDrivePivot): New passthroughs.
* src/qemu/qemu_monitor.h (qemuMonitorDriveMirror)
(qemuMonitorDrivePivot): Declare them.
2012-09-28 23:29:53 +00:00
|
|
|
NULL);
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
blockjob: add qemu capabilities related to block jobs
Upstream qemu 1.3 is adding two new monitor commands, 'drive-mirror'
and 'block-job-complete'[1], which can drive live block copy and
storage migration. [Additionally, RHEL 6.3 had backported an earlier
version of most of the same functionality, but under the names
'__com.redhat_drive-mirror' and '__com.redhat_drive-reopen' and with
slightly different JSON arguments, and has been using patches similar
to these upstream patches for several months now.]
The libvirt API virDomainBlockRebase as already committed for 0.9.12
is flexible enough to expose the basics of block copy, but some
additional features in the 'drive-mirror' qemu command, such as
setting error policy, setting granularity, or using a persistent
bitmap, may later require a new libvirt API virDomainBlockCopy. I
will wait to add that API until we know more about what qemu 1.3
will finally provide.
This patch caters only to the upstream qemu 1.3 interface, although
I have proven that the changes for RHEL 6.3 can be isolated to
just qemu_monitor_json.c, and the rest of this series will
gracefully handle either interface once the JSON differences are
papered over in a downstream patch.
For consistency with other block job commands, libvirt must handle
the bandwidth argument as MiB/sec from the user, even though qemu
exposes the speed argument as bytes/sec; then again, qemu rounds
up to cluster size internally, so using MiB hides the worst effects
of that rounding if you pass small numbers.
[1]https://lists.gnu.org/archive/html/qemu-devel/2012-10/msg04123.html
* src/qemu/qemu_capabilities.h (QEMU_CAPS_DRIVE_MIRROR)
(QEMU_CAPS_DRIVE_REOPEN): New bits.
* src/qemu/qemu_capabilities.c (qemuCaps): Name them.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONCheckCommands): Set
them.
(qemuMonitorJSONDriveMirror, qemuMonitorDrivePivot): New functions.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONDriveMirror)
(qemuMonitorDrivePivot): Declare them.
* src/qemu/qemu_monitor.c (qemuMonitorDriveMirror)
(qemuMonitorDrivePivot): New passthroughs.
* src/qemu/qemu_monitor.h (qemuMonitorDriveMirror)
(qemuMonitorDrivePivot): Declare them.
2012-09-28 23:29:53 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
blockjob: add qemu capabilities related to block jobs
Upstream qemu 1.3 is adding two new monitor commands, 'drive-mirror'
and 'block-job-complete'[1], which can drive live block copy and
storage migration. [Additionally, RHEL 6.3 had backported an earlier
version of most of the same functionality, but under the names
'__com.redhat_drive-mirror' and '__com.redhat_drive-reopen' and with
slightly different JSON arguments, and has been using patches similar
to these upstream patches for several months now.]
The libvirt API virDomainBlockRebase as already committed for 0.9.12
is flexible enough to expose the basics of block copy, but some
additional features in the 'drive-mirror' qemu command, such as
setting error policy, setting granularity, or using a persistent
bitmap, may later require a new libvirt API virDomainBlockCopy. I
will wait to add that API until we know more about what qemu 1.3
will finally provide.
This patch caters only to the upstream qemu 1.3 interface, although
I have proven that the changes for RHEL 6.3 can be isolated to
just qemu_monitor_json.c, and the rest of this series will
gracefully handle either interface once the JSON differences are
papered over in a downstream patch.
For consistency with other block job commands, libvirt must handle
the bandwidth argument as MiB/sec from the user, even though qemu
exposes the speed argument as bytes/sec; then again, qemu rounds
up to cluster size internally, so using MiB hides the worst effects
of that rounding if you pass small numbers.
[1]https://lists.gnu.org/archive/html/qemu-devel/2012-10/msg04123.html
* src/qemu/qemu_capabilities.h (QEMU_CAPS_DRIVE_MIRROR)
(QEMU_CAPS_DRIVE_REOPEN): New bits.
* src/qemu/qemu_capabilities.c (qemuCaps): Name them.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONCheckCommands): Set
them.
(qemuMonitorJSONDriveMirror, qemuMonitorDrivePivot): New functions.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONDriveMirror)
(qemuMonitorDrivePivot): Declare them.
* src/qemu/qemu_monitor.c (qemuMonitorDriveMirror)
(qemuMonitorDrivePivot): New passthroughs.
* src/qemu/qemu_monitor.h (qemuMonitorDriveMirror)
(qemuMonitorDrivePivot): Declare them.
2012-09-28 23:29:53 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-03-17 04:17:28 +00:00
|
|
|
int
|
|
|
|
qemuMonitorJSONTransaction(qemuMonitorPtr mon, virJSONValuePtr actions)
|
|
|
|
{
|
2012-04-05 19:15:03 +00:00
|
|
|
int ret = -1;
|
2012-03-17 04:17:28 +00:00
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
2012-04-05 19:15:03 +00:00
|
|
|
bool protect = actions->protect;
|
2012-03-17 04:17:28 +00:00
|
|
|
|
2012-04-05 19:15:03 +00:00
|
|
|
/* We do NOT want to free actions when recursively freeing cmd. */
|
|
|
|
actions->protect = true;
|
2012-03-17 04:17:28 +00:00
|
|
|
cmd = qemuMonitorJSONMakeCommand("transaction",
|
|
|
|
"a:actions", actions,
|
|
|
|
NULL);
|
2012-04-05 19:15:03 +00:00
|
|
|
if (!cmd)
|
|
|
|
goto cleanup;
|
2012-03-17 04:17:28 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
2012-03-17 04:17:28 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2011-08-15 23:25:54 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2011-08-15 23:25:54 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
2012-04-05 19:15:03 +00:00
|
|
|
actions->protect = protect;
|
2011-08-15 23:25:54 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
blockjob: allow omitted arguments to QMP block-commit
We are about to turn on support for active block commit. Although
qemu 2.0 was the first version to mostly support it, that version
mis-handles 0-length files, and doesn't have anything available for
easy probing. But qemu 2.1 fixed bugs, and made life simpler by
letting the 'top' argument be optional. Unless someone begs for
active commit with qemu 2.0, for now we are just going to enable
it only by probing for qemu 2.1 behavior (anyone backporting active
commit can also backport the optional argument behavior). This
requires qemu.git commit 7676e2c597000eff3a7233b40cca768b358f9bc9.
Although all our actual uses of block-commit supply arguments for
both base and top, we can omit both arguments and use a bogus
device string to trigger an interesting behavior in qemu. All QMP
commands first do argument validation, failing with GenericError
if a mandatory argument is missing. Once that passes, the code
in the specific command gets to do further checking, and the qemu
developers made sure that if device is the only supplied argument,
then the block-commit code will look up the device first, with a
failure of DeviceNotFound, before attempting any further argument
validation (most other validations fail with GenericError). Thus,
the category of error class can reliably be used to decipher
whether the top argument was optional, which in turn implies a
working active commit. Since we expect our bogus device string to
trigger an error either way, the code is written to return a
distinct return value without spamming the logs.
* src/qemu/qemu_monitor.h (qemuMonitorSupportsActiveCommit): New
prototype.
* src/qemu/qemu_monitor.c (qemuMonitorSupportsActiveCommit):
Implement it.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONBlockCommit):
Allow NULL for top and base, for probing purposes.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONBlockCommit):
Likewise, implementing the probe.
* tests/qemumonitorjsontest.c (mymain): Enable...
(testQemuMonitorJSONqemuMonitorSupportsActiveCommit): ...a new test.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-06-17 03:42:49 +00:00
|
|
|
/* speed is in bytes/sec. Returns 0 on success, -1 with error message
|
|
|
|
* emitted on failure.
|
|
|
|
*
|
|
|
|
* Additionally, can be used to probe if active commit is supported:
|
|
|
|
* pass in a bogus device and NULL top and base. The probe return is
|
|
|
|
* -2 if active commit is detected, -3 if inconclusive; with no error
|
|
|
|
* message issued.
|
|
|
|
*/
|
2012-10-03 21:13:21 +00:00
|
|
|
int
|
|
|
|
qemuMonitorJSONBlockCommit(qemuMonitorPtr mon, const char *device,
|
|
|
|
const char *top, const char *base,
|
2014-05-13 15:41:33 +00:00
|
|
|
const char *backingName,
|
2012-10-03 21:13:21 +00:00
|
|
|
unsigned long long speed)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
|
|
|
|
cmd = qemuMonitorJSONMakeCommand("block-commit",
|
|
|
|
"s:device", device,
|
2014-09-05 11:31:47 +00:00
|
|
|
"Y:speed", speed,
|
blockjob: allow omitted arguments to QMP block-commit
We are about to turn on support for active block commit. Although
qemu 2.0 was the first version to mostly support it, that version
mis-handles 0-length files, and doesn't have anything available for
easy probing. But qemu 2.1 fixed bugs, and made life simpler by
letting the 'top' argument be optional. Unless someone begs for
active commit with qemu 2.0, for now we are just going to enable
it only by probing for qemu 2.1 behavior (anyone backporting active
commit can also backport the optional argument behavior). This
requires qemu.git commit 7676e2c597000eff3a7233b40cca768b358f9bc9.
Although all our actual uses of block-commit supply arguments for
both base and top, we can omit both arguments and use a bogus
device string to trigger an interesting behavior in qemu. All QMP
commands first do argument validation, failing with GenericError
if a mandatory argument is missing. Once that passes, the code
in the specific command gets to do further checking, and the qemu
developers made sure that if device is the only supplied argument,
then the block-commit code will look up the device first, with a
failure of DeviceNotFound, before attempting any further argument
validation (most other validations fail with GenericError). Thus,
the category of error class can reliably be used to decipher
whether the top argument was optional, which in turn implies a
working active commit. Since we expect our bogus device string to
trigger an error either way, the code is written to return a
distinct return value without spamming the logs.
* src/qemu/qemu_monitor.h (qemuMonitorSupportsActiveCommit): New
prototype.
* src/qemu/qemu_monitor.c (qemuMonitorSupportsActiveCommit):
Implement it.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONBlockCommit):
Allow NULL for top and base, for probing purposes.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONBlockCommit):
Likewise, implementing the probe.
* tests/qemumonitorjsontest.c (mymain): Enable...
(testQemuMonitorJSONqemuMonitorSupportsActiveCommit): ...a new test.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-06-17 03:42:49 +00:00
|
|
|
"S:top", top,
|
|
|
|
"S:base", base,
|
2014-05-13 15:41:33 +00:00
|
|
|
"S:backing-file", backingName,
|
2012-10-03 21:13:21 +00:00
|
|
|
NULL);
|
blockjob: add qemu capabilities related to block jobs
Upstream qemu 1.3 is adding two new monitor commands, 'drive-mirror'
and 'block-job-complete'[1], which can drive live block copy and
storage migration. [Additionally, RHEL 6.3 had backported an earlier
version of most of the same functionality, but under the names
'__com.redhat_drive-mirror' and '__com.redhat_drive-reopen' and with
slightly different JSON arguments, and has been using patches similar
to these upstream patches for several months now.]
The libvirt API virDomainBlockRebase as already committed for 0.9.12
is flexible enough to expose the basics of block copy, but some
additional features in the 'drive-mirror' qemu command, such as
setting error policy, setting granularity, or using a persistent
bitmap, may later require a new libvirt API virDomainBlockCopy. I
will wait to add that API until we know more about what qemu 1.3
will finally provide.
This patch caters only to the upstream qemu 1.3 interface, although
I have proven that the changes for RHEL 6.3 can be isolated to
just qemu_monitor_json.c, and the rest of this series will
gracefully handle either interface once the JSON differences are
papered over in a downstream patch.
For consistency with other block job commands, libvirt must handle
the bandwidth argument as MiB/sec from the user, even though qemu
exposes the speed argument as bytes/sec; then again, qemu rounds
up to cluster size internally, so using MiB hides the worst effects
of that rounding if you pass small numbers.
[1]https://lists.gnu.org/archive/html/qemu-devel/2012-10/msg04123.html
* src/qemu/qemu_capabilities.h (QEMU_CAPS_DRIVE_MIRROR)
(QEMU_CAPS_DRIVE_REOPEN): New bits.
* src/qemu/qemu_capabilities.c (qemuCaps): Name them.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONCheckCommands): Set
them.
(qemuMonitorJSONDriveMirror, qemuMonitorDrivePivot): New functions.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONDriveMirror)
(qemuMonitorDrivePivot): Declare them.
* src/qemu/qemu_monitor.c (qemuMonitorDriveMirror)
(qemuMonitorDrivePivot): New passthroughs.
* src/qemu/qemu_monitor.h (qemuMonitorDriveMirror)
(qemuMonitorDrivePivot): Declare them.
2012-09-28 23:29:53 +00:00
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
blockjob: add qemu capabilities related to block jobs
Upstream qemu 1.3 is adding two new monitor commands, 'drive-mirror'
and 'block-job-complete'[1], which can drive live block copy and
storage migration. [Additionally, RHEL 6.3 had backported an earlier
version of most of the same functionality, but under the names
'__com.redhat_drive-mirror' and '__com.redhat_drive-reopen' and with
slightly different JSON arguments, and has been using patches similar
to these upstream patches for several months now.]
The libvirt API virDomainBlockRebase as already committed for 0.9.12
is flexible enough to expose the basics of block copy, but some
additional features in the 'drive-mirror' qemu command, such as
setting error policy, setting granularity, or using a persistent
bitmap, may later require a new libvirt API virDomainBlockCopy. I
will wait to add that API until we know more about what qemu 1.3
will finally provide.
This patch caters only to the upstream qemu 1.3 interface, although
I have proven that the changes for RHEL 6.3 can be isolated to
just qemu_monitor_json.c, and the rest of this series will
gracefully handle either interface once the JSON differences are
papered over in a downstream patch.
For consistency with other block job commands, libvirt must handle
the bandwidth argument as MiB/sec from the user, even though qemu
exposes the speed argument as bytes/sec; then again, qemu rounds
up to cluster size internally, so using MiB hides the worst effects
of that rounding if you pass small numbers.
[1]https://lists.gnu.org/archive/html/qemu-devel/2012-10/msg04123.html
* src/qemu/qemu_capabilities.h (QEMU_CAPS_DRIVE_MIRROR)
(QEMU_CAPS_DRIVE_REOPEN): New bits.
* src/qemu/qemu_capabilities.c (qemuCaps): Name them.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONCheckCommands): Set
them.
(qemuMonitorJSONDriveMirror, qemuMonitorDrivePivot): New functions.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONDriveMirror)
(qemuMonitorDrivePivot): Declare them.
* src/qemu/qemu_monitor.c (qemuMonitorDriveMirror)
(qemuMonitorDrivePivot): New passthroughs.
* src/qemu/qemu_monitor.h (qemuMonitorDriveMirror)
(qemuMonitorDrivePivot): Declare them.
2012-09-28 23:29:53 +00:00
|
|
|
goto cleanup;
|
blockjob: allow omitted arguments to QMP block-commit
We are about to turn on support for active block commit. Although
qemu 2.0 was the first version to mostly support it, that version
mis-handles 0-length files, and doesn't have anything available for
easy probing. But qemu 2.1 fixed bugs, and made life simpler by
letting the 'top' argument be optional. Unless someone begs for
active commit with qemu 2.0, for now we are just going to enable
it only by probing for qemu 2.1 behavior (anyone backporting active
commit can also backport the optional argument behavior). This
requires qemu.git commit 7676e2c597000eff3a7233b40cca768b358f9bc9.
Although all our actual uses of block-commit supply arguments for
both base and top, we can omit both arguments and use a bogus
device string to trigger an interesting behavior in qemu. All QMP
commands first do argument validation, failing with GenericError
if a mandatory argument is missing. Once that passes, the code
in the specific command gets to do further checking, and the qemu
developers made sure that if device is the only supplied argument,
then the block-commit code will look up the device first, with a
failure of DeviceNotFound, before attempting any further argument
validation (most other validations fail with GenericError). Thus,
the category of error class can reliably be used to decipher
whether the top argument was optional, which in turn implies a
working active commit. Since we expect our bogus device string to
trigger an error either way, the code is written to return a
distinct return value without spamming the logs.
* src/qemu/qemu_monitor.h (qemuMonitorSupportsActiveCommit): New
prototype.
* src/qemu/qemu_monitor.c (qemuMonitorSupportsActiveCommit):
Implement it.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONBlockCommit):
Allow NULL for top and base, for probing purposes.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONBlockCommit):
Likewise, implementing the probe.
* tests/qemumonitorjsontest.c (mymain): Enable...
(testQemuMonitorJSONqemuMonitorSupportsActiveCommit): ...a new test.
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-06-17 03:42:49 +00:00
|
|
|
if (!top && !base) {
|
|
|
|
/* Normally we always specify top and base; but omitting them
|
|
|
|
* allows for probing whether qemu is new enough to support
|
|
|
|
* live commit. */
|
|
|
|
if (qemuMonitorJSONHasError(reply, "DeviceNotFound")) {
|
|
|
|
VIR_DEBUG("block-commit supports active commit");
|
|
|
|
ret = -2;
|
|
|
|
} else {
|
|
|
|
/* This is a false negative for qemu 2.0; but probably not
|
|
|
|
* worth the additional complexity to worry about it */
|
|
|
|
VIR_DEBUG("block-commit requires 'top' parameter, "
|
|
|
|
"assuming it lacks active commit");
|
|
|
|
ret = -3;
|
|
|
|
}
|
|
|
|
goto cleanup;
|
|
|
|
}
|
blockjob: add qemu capabilities related to block jobs
Upstream qemu 1.3 is adding two new monitor commands, 'drive-mirror'
and 'block-job-complete'[1], which can drive live block copy and
storage migration. [Additionally, RHEL 6.3 had backported an earlier
version of most of the same functionality, but under the names
'__com.redhat_drive-mirror' and '__com.redhat_drive-reopen' and with
slightly different JSON arguments, and has been using patches similar
to these upstream patches for several months now.]
The libvirt API virDomainBlockRebase as already committed for 0.9.12
is flexible enough to expose the basics of block copy, but some
additional features in the 'drive-mirror' qemu command, such as
setting error policy, setting granularity, or using a persistent
bitmap, may later require a new libvirt API virDomainBlockCopy. I
will wait to add that API until we know more about what qemu 1.3
will finally provide.
This patch caters only to the upstream qemu 1.3 interface, although
I have proven that the changes for RHEL 6.3 can be isolated to
just qemu_monitor_json.c, and the rest of this series will
gracefully handle either interface once the JSON differences are
papered over in a downstream patch.
For consistency with other block job commands, libvirt must handle
the bandwidth argument as MiB/sec from the user, even though qemu
exposes the speed argument as bytes/sec; then again, qemu rounds
up to cluster size internally, so using MiB hides the worst effects
of that rounding if you pass small numbers.
[1]https://lists.gnu.org/archive/html/qemu-devel/2012-10/msg04123.html
* src/qemu/qemu_capabilities.h (QEMU_CAPS_DRIVE_MIRROR)
(QEMU_CAPS_DRIVE_REOPEN): New bits.
* src/qemu/qemu_capabilities.c (qemuCaps): Name them.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONCheckCommands): Set
them.
(qemuMonitorJSONDriveMirror, qemuMonitorDrivePivot): New functions.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONDriveMirror)
(qemuMonitorDrivePivot): Declare them.
* src/qemu/qemu_monitor.c (qemuMonitorDriveMirror)
(qemuMonitorDrivePivot): New passthroughs.
* src/qemu/qemu_monitor.h (qemuMonitorDriveMirror)
(qemuMonitorDrivePivot): Declare them.
2012-09-28 23:29:53 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
blockjob: add qemu capabilities related to block jobs
Upstream qemu 1.3 is adding two new monitor commands, 'drive-mirror'
and 'block-job-complete'[1], which can drive live block copy and
storage migration. [Additionally, RHEL 6.3 had backported an earlier
version of most of the same functionality, but under the names
'__com.redhat_drive-mirror' and '__com.redhat_drive-reopen' and with
slightly different JSON arguments, and has been using patches similar
to these upstream patches for several months now.]
The libvirt API virDomainBlockRebase as already committed for 0.9.12
is flexible enough to expose the basics of block copy, but some
additional features in the 'drive-mirror' qemu command, such as
setting error policy, setting granularity, or using a persistent
bitmap, may later require a new libvirt API virDomainBlockCopy. I
will wait to add that API until we know more about what qemu 1.3
will finally provide.
This patch caters only to the upstream qemu 1.3 interface, although
I have proven that the changes for RHEL 6.3 can be isolated to
just qemu_monitor_json.c, and the rest of this series will
gracefully handle either interface once the JSON differences are
papered over in a downstream patch.
For consistency with other block job commands, libvirt must handle
the bandwidth argument as MiB/sec from the user, even though qemu
exposes the speed argument as bytes/sec; then again, qemu rounds
up to cluster size internally, so using MiB hides the worst effects
of that rounding if you pass small numbers.
[1]https://lists.gnu.org/archive/html/qemu-devel/2012-10/msg04123.html
* src/qemu/qemu_capabilities.h (QEMU_CAPS_DRIVE_MIRROR)
(QEMU_CAPS_DRIVE_REOPEN): New bits.
* src/qemu/qemu_capabilities.c (qemuCaps): Name them.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONCheckCommands): Set
them.
(qemuMonitorJSONDriveMirror, qemuMonitorDrivePivot): New functions.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONDriveMirror)
(qemuMonitorDrivePivot): Declare them.
* src/qemu/qemu_monitor.c (qemuMonitorDriveMirror)
(qemuMonitorDrivePivot): New passthroughs.
* src/qemu/qemu_monitor.h (qemuMonitorDriveMirror)
(qemuMonitorDrivePivot): Declare them.
2012-09-28 23:29:53 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2015-04-01 08:06:55 +00:00
|
|
|
qemuMonitorJSONDrivePivot(qemuMonitorPtr mon,
|
|
|
|
const char *device)
|
blockjob: add qemu capabilities related to block jobs
Upstream qemu 1.3 is adding two new monitor commands, 'drive-mirror'
and 'block-job-complete'[1], which can drive live block copy and
storage migration. [Additionally, RHEL 6.3 had backported an earlier
version of most of the same functionality, but under the names
'__com.redhat_drive-mirror' and '__com.redhat_drive-reopen' and with
slightly different JSON arguments, and has been using patches similar
to these upstream patches for several months now.]
The libvirt API virDomainBlockRebase as already committed for 0.9.12
is flexible enough to expose the basics of block copy, but some
additional features in the 'drive-mirror' qemu command, such as
setting error policy, setting granularity, or using a persistent
bitmap, may later require a new libvirt API virDomainBlockCopy. I
will wait to add that API until we know more about what qemu 1.3
will finally provide.
This patch caters only to the upstream qemu 1.3 interface, although
I have proven that the changes for RHEL 6.3 can be isolated to
just qemu_monitor_json.c, and the rest of this series will
gracefully handle either interface once the JSON differences are
papered over in a downstream patch.
For consistency with other block job commands, libvirt must handle
the bandwidth argument as MiB/sec from the user, even though qemu
exposes the speed argument as bytes/sec; then again, qemu rounds
up to cluster size internally, so using MiB hides the worst effects
of that rounding if you pass small numbers.
[1]https://lists.gnu.org/archive/html/qemu-devel/2012-10/msg04123.html
* src/qemu/qemu_capabilities.h (QEMU_CAPS_DRIVE_MIRROR)
(QEMU_CAPS_DRIVE_REOPEN): New bits.
* src/qemu/qemu_capabilities.c (qemuCaps): Name them.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONCheckCommands): Set
them.
(qemuMonitorJSONDriveMirror, qemuMonitorDrivePivot): New functions.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONDriveMirror)
(qemuMonitorDrivePivot): Declare them.
* src/qemu/qemu_monitor.c (qemuMonitorDriveMirror)
(qemuMonitorDrivePivot): New passthroughs.
* src/qemu/qemu_monitor.h (qemuMonitorDriveMirror)
(qemuMonitorDrivePivot): Declare them.
2012-09-28 23:29:53 +00:00
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
blockjob: add qemu capabilities related to block jobs
Upstream qemu 1.3 is adding two new monitor commands, 'drive-mirror'
and 'block-job-complete'[1], which can drive live block copy and
storage migration. [Additionally, RHEL 6.3 had backported an earlier
version of most of the same functionality, but under the names
'__com.redhat_drive-mirror' and '__com.redhat_drive-reopen' and with
slightly different JSON arguments, and has been using patches similar
to these upstream patches for several months now.]
The libvirt API virDomainBlockRebase as already committed for 0.9.12
is flexible enough to expose the basics of block copy, but some
additional features in the 'drive-mirror' qemu command, such as
setting error policy, setting granularity, or using a persistent
bitmap, may later require a new libvirt API virDomainBlockCopy. I
will wait to add that API until we know more about what qemu 1.3
will finally provide.
This patch caters only to the upstream qemu 1.3 interface, although
I have proven that the changes for RHEL 6.3 can be isolated to
just qemu_monitor_json.c, and the rest of this series will
gracefully handle either interface once the JSON differences are
papered over in a downstream patch.
For consistency with other block job commands, libvirt must handle
the bandwidth argument as MiB/sec from the user, even though qemu
exposes the speed argument as bytes/sec; then again, qemu rounds
up to cluster size internally, so using MiB hides the worst effects
of that rounding if you pass small numbers.
[1]https://lists.gnu.org/archive/html/qemu-devel/2012-10/msg04123.html
* src/qemu/qemu_capabilities.h (QEMU_CAPS_DRIVE_MIRROR)
(QEMU_CAPS_DRIVE_REOPEN): New bits.
* src/qemu/qemu_capabilities.c (qemuCaps): Name them.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONCheckCommands): Set
them.
(qemuMonitorJSONDriveMirror, qemuMonitorDrivePivot): New functions.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONDriveMirror)
(qemuMonitorDrivePivot): Declare them.
* src/qemu/qemu_monitor.c (qemuMonitorDriveMirror)
(qemuMonitorDrivePivot): New passthroughs.
* src/qemu/qemu_monitor.h (qemuMonitorDriveMirror)
(qemuMonitorDrivePivot): Declare them.
2012-09-28 23:29:53 +00:00
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
|
|
|
|
cmd = qemuMonitorJSONMakeCommand("block-job-complete",
|
|
|
|
"s:device", device,
|
|
|
|
NULL);
|
2012-10-03 21:13:21 +00:00
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
2012-10-03 21:13:21 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2012-10-03 21:13:21 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
qemu: read backing chain names from qemu
https://bugzilla.redhat.com/show_bug.cgi?id=1199182 documents that
after a series of disk snapshots into existing destination images,
followed by active commits of the top image, it is possible for
qemu 2.2 and earlier to end up tracking a different name for the
image than what it would have had when opening the chain afresh.
That is, when starting with the chain 'a <- b <- c', the name
associated with 'b' is how it was spelled in the metadata of 'c',
but when starting with 'a', taking two snapshots into 'a <- b <- c',
then committing 'c' back into 'b', the name associated with 'b' is
now the name used when taking the first snapshot.
Sadly, older qemu doesn't know how to treat different spellings of
the same filename as identical files (it uses strcmp() instead of
checking for the same inode), which means libvirt's attempt to
commit an image using solely the names learned from qcow2 metadata
fails with a cryptic:
error: internal error: unable to execute QEMU command 'block-commit': Top image file /tmp/images/c/../b/b not found
even though the file exists. Trying to teach libvirt the rules on
which name qemu will expect is not worth the effort (besides, we'd
have to remember it across libvirtd restarts, and track whether a
file was opened via metadata or via snapshot creation for a given
qemu process); it is easier to just always directly ask qemu what
string it expects to see in the first place.
As a safety valve, we validate that any name returned by qemu
still maps to the same local file as we have tracked it, so that
a compromised qemu cannot accidentally cause us to act on an
incorrect file.
* src/qemu/qemu_monitor.h (qemuMonitorDiskNameLookup): New
prototype.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONDiskNameLookup):
Likewise.
* src/qemu/qemu_monitor.c (qemuMonitorDiskNameLookup): New function.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONDiskNameLookup)
(qemuMonitorJSONDiskNameLookupOne): Likewise.
* src/qemu/qemu_driver.c (qemuDomainBlockCommit)
(qemuDomainBlockJobImpl): Use it.
Signed-off-by: Eric Blake <eblake@redhat.com>
2015-03-11 20:37:04 +00:00
|
|
|
static char *
|
|
|
|
qemuMonitorJSONDiskNameLookupOne(virJSONValuePtr image,
|
|
|
|
virStorageSourcePtr top,
|
|
|
|
virStorageSourcePtr target)
|
|
|
|
{
|
|
|
|
virJSONValuePtr backing;
|
|
|
|
char *ret;
|
|
|
|
|
|
|
|
/* The caller will report a generic message if we return NULL
|
|
|
|
* without an error; but in some cases we can improve by reporting
|
|
|
|
* a more specific message. */
|
|
|
|
if (!top || !image)
|
|
|
|
return NULL;
|
|
|
|
if (top != target) {
|
qemu: simplify json parsing
Rather than grabbing an arbitrary JSON value and then checking
if it has the right type, we might as well request the correct
type to begin with.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONIOProcessEvent)
(qemuMonitorJSONCommandWithFd, qemuMonitorJSONHandleGraphics)
(qemuMonitorJSONGetStatus, qemuMonitorJSONExtractCPUInfo)
(qemuMonitorJSONGetVirtType, qemuMonitorJSONGetBalloonInfo)
(qemuMonitorJSONGetMemoryStats)
(qemuMonitorJSONDevGetBlockExtent)
(qemuMonitorJSONGetOneBlockStatsInfo)
(qemuMonitorJSONGetAllBlockStatsInfo)
(qemuMonitorJSONBlockStatsUpdateCapacityOne)
(qemuMonitorJSONBlockStatsUpdateCapacity)
(qemuMonitorJSONGetBlockExtent)
(qemuMonitorJSONGetMigrationStatusReply)
(qemuMonitorJSONGetDumpGuestMemoryCapability)
(qemuMonitorJSONAddFd, qemuMonitorJSONQueryRxFilterParse)
(qemuMonitorJSONExtractChardevInfo)
(qemuMonitorJSONDiskNameLookupOne)
(qemuMonitorJSONDiskNameLookup)
(qemuMonitorJSONGetAllBlockJobInfo)
(qemuMonitorJSONBlockIoThrottleInfo, qemuMonitorJSONGetVersion)
(qemuMonitorJSONGetMachines, qemuMonitorJSONGetCPUDefinitions)
(qemuMonitorJSONGetCommands, qemuMonitorJSONGetEvents)
(qemuMonitorJSONGetKVMState, qemuMonitorJSONGetObjectTypes)
(qemuMonitorJSONGetObjectListPaths)
(qemuMonitorJSONGetObjectProps, qemuMonitorJSONGetTargetArch)
(qemuMonitorJSONGetMigrationCapabilities)
(qemuMonitorJSONGetStringArray, qemuMonitorJSONAttachCharDev)
(qemuMonitorJSONGetCPUx86Data, qemuMonitorJSONGetIOThreads)
(qemuMonitorJSONGetMemoryDeviceInfo): Use shorter idioms.
Signed-off-by: Eric Blake <eblake@redhat.com>
2015-06-20 19:40:21 +00:00
|
|
|
backing = virJSONValueObjectGetObject(image, "backing-image");
|
qemu: read backing chain names from qemu
https://bugzilla.redhat.com/show_bug.cgi?id=1199182 documents that
after a series of disk snapshots into existing destination images,
followed by active commits of the top image, it is possible for
qemu 2.2 and earlier to end up tracking a different name for the
image than what it would have had when opening the chain afresh.
That is, when starting with the chain 'a <- b <- c', the name
associated with 'b' is how it was spelled in the metadata of 'c',
but when starting with 'a', taking two snapshots into 'a <- b <- c',
then committing 'c' back into 'b', the name associated with 'b' is
now the name used when taking the first snapshot.
Sadly, older qemu doesn't know how to treat different spellings of
the same filename as identical files (it uses strcmp() instead of
checking for the same inode), which means libvirt's attempt to
commit an image using solely the names learned from qcow2 metadata
fails with a cryptic:
error: internal error: unable to execute QEMU command 'block-commit': Top image file /tmp/images/c/../b/b not found
even though the file exists. Trying to teach libvirt the rules on
which name qemu will expect is not worth the effort (besides, we'd
have to remember it across libvirtd restarts, and track whether a
file was opened via metadata or via snapshot creation for a given
qemu process); it is easier to just always directly ask qemu what
string it expects to see in the first place.
As a safety valve, we validate that any name returned by qemu
still maps to the same local file as we have tracked it, so that
a compromised qemu cannot accidentally cause us to act on an
incorrect file.
* src/qemu/qemu_monitor.h (qemuMonitorDiskNameLookup): New
prototype.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONDiskNameLookup):
Likewise.
* src/qemu/qemu_monitor.c (qemuMonitorDiskNameLookup): New function.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONDiskNameLookup)
(qemuMonitorJSONDiskNameLookupOne): Likewise.
* src/qemu/qemu_driver.c (qemuDomainBlockCommit)
(qemuDomainBlockJobImpl): Use it.
Signed-off-by: Eric Blake <eblake@redhat.com>
2015-03-11 20:37:04 +00:00
|
|
|
return qemuMonitorJSONDiskNameLookupOne(backing, top->backingStore,
|
|
|
|
target);
|
|
|
|
}
|
|
|
|
if (VIR_STRDUP(ret, virJSONValueObjectGetString(image, "filename")) < 0)
|
|
|
|
return NULL;
|
|
|
|
/* Sanity check - the name qemu gave us should resolve to the same
|
|
|
|
file tracked by our target description. */
|
|
|
|
if (virStorageSourceIsLocalStorage(target) &&
|
|
|
|
STRNEQ(ret, target->path) &&
|
|
|
|
!virFileLinkPointsTo(ret, target->path)) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("qemu block name '%s' doesn't match expected '%s'"),
|
|
|
|
ret, target->path);
|
|
|
|
VIR_FREE(ret);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char *
|
|
|
|
qemuMonitorJSONDiskNameLookup(qemuMonitorPtr mon,
|
|
|
|
const char *device,
|
|
|
|
virStorageSourcePtr top,
|
|
|
|
virStorageSourcePtr target)
|
|
|
|
{
|
|
|
|
char *ret = NULL;
|
|
|
|
virJSONValuePtr devices;
|
|
|
|
size_t i;
|
|
|
|
|
2016-09-27 13:39:21 +00:00
|
|
|
if (!(devices = qemuMonitorJSONQueryBlock(mon)))
|
qemu: read backing chain names from qemu
https://bugzilla.redhat.com/show_bug.cgi?id=1199182 documents that
after a series of disk snapshots into existing destination images,
followed by active commits of the top image, it is possible for
qemu 2.2 and earlier to end up tracking a different name for the
image than what it would have had when opening the chain afresh.
That is, when starting with the chain 'a <- b <- c', the name
associated with 'b' is how it was spelled in the metadata of 'c',
but when starting with 'a', taking two snapshots into 'a <- b <- c',
then committing 'c' back into 'b', the name associated with 'b' is
now the name used when taking the first snapshot.
Sadly, older qemu doesn't know how to treat different spellings of
the same filename as identical files (it uses strcmp() instead of
checking for the same inode), which means libvirt's attempt to
commit an image using solely the names learned from qcow2 metadata
fails with a cryptic:
error: internal error: unable to execute QEMU command 'block-commit': Top image file /tmp/images/c/../b/b not found
even though the file exists. Trying to teach libvirt the rules on
which name qemu will expect is not worth the effort (besides, we'd
have to remember it across libvirtd restarts, and track whether a
file was opened via metadata or via snapshot creation for a given
qemu process); it is easier to just always directly ask qemu what
string it expects to see in the first place.
As a safety valve, we validate that any name returned by qemu
still maps to the same local file as we have tracked it, so that
a compromised qemu cannot accidentally cause us to act on an
incorrect file.
* src/qemu/qemu_monitor.h (qemuMonitorDiskNameLookup): New
prototype.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONDiskNameLookup):
Likewise.
* src/qemu/qemu_monitor.c (qemuMonitorDiskNameLookup): New function.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONDiskNameLookup)
(qemuMonitorJSONDiskNameLookupOne): Likewise.
* src/qemu/qemu_driver.c (qemuDomainBlockCommit)
(qemuDomainBlockJobImpl): Use it.
Signed-off-by: Eric Blake <eblake@redhat.com>
2015-03-11 20:37:04 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < virJSONValueArraySize(devices); i++) {
|
2016-10-03 18:58:59 +00:00
|
|
|
virJSONValuePtr dev;
|
qemu: read backing chain names from qemu
https://bugzilla.redhat.com/show_bug.cgi?id=1199182 documents that
after a series of disk snapshots into existing destination images,
followed by active commits of the top image, it is possible for
qemu 2.2 and earlier to end up tracking a different name for the
image than what it would have had when opening the chain afresh.
That is, when starting with the chain 'a <- b <- c', the name
associated with 'b' is how it was spelled in the metadata of 'c',
but when starting with 'a', taking two snapshots into 'a <- b <- c',
then committing 'c' back into 'b', the name associated with 'b' is
now the name used when taking the first snapshot.
Sadly, older qemu doesn't know how to treat different spellings of
the same filename as identical files (it uses strcmp() instead of
checking for the same inode), which means libvirt's attempt to
commit an image using solely the names learned from qcow2 metadata
fails with a cryptic:
error: internal error: unable to execute QEMU command 'block-commit': Top image file /tmp/images/c/../b/b not found
even though the file exists. Trying to teach libvirt the rules on
which name qemu will expect is not worth the effort (besides, we'd
have to remember it across libvirtd restarts, and track whether a
file was opened via metadata or via snapshot creation for a given
qemu process); it is easier to just always directly ask qemu what
string it expects to see in the first place.
As a safety valve, we validate that any name returned by qemu
still maps to the same local file as we have tracked it, so that
a compromised qemu cannot accidentally cause us to act on an
incorrect file.
* src/qemu/qemu_monitor.h (qemuMonitorDiskNameLookup): New
prototype.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONDiskNameLookup):
Likewise.
* src/qemu/qemu_monitor.c (qemuMonitorDiskNameLookup): New function.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONDiskNameLookup)
(qemuMonitorJSONDiskNameLookupOne): Likewise.
* src/qemu/qemu_driver.c (qemuDomainBlockCommit)
(qemuDomainBlockJobImpl): Use it.
Signed-off-by: Eric Blake <eblake@redhat.com>
2015-03-11 20:37:04 +00:00
|
|
|
virJSONValuePtr inserted;
|
|
|
|
virJSONValuePtr image;
|
|
|
|
const char *thisdev;
|
|
|
|
|
2016-10-03 18:58:59 +00:00
|
|
|
if (!(dev = qemuMonitorJSONGetBlockDev(devices, i)))
|
qemu: read backing chain names from qemu
https://bugzilla.redhat.com/show_bug.cgi?id=1199182 documents that
after a series of disk snapshots into existing destination images,
followed by active commits of the top image, it is possible for
qemu 2.2 and earlier to end up tracking a different name for the
image than what it would have had when opening the chain afresh.
That is, when starting with the chain 'a <- b <- c', the name
associated with 'b' is how it was spelled in the metadata of 'c',
but when starting with 'a', taking two snapshots into 'a <- b <- c',
then committing 'c' back into 'b', the name associated with 'b' is
now the name used when taking the first snapshot.
Sadly, older qemu doesn't know how to treat different spellings of
the same filename as identical files (it uses strcmp() instead of
checking for the same inode), which means libvirt's attempt to
commit an image using solely the names learned from qcow2 metadata
fails with a cryptic:
error: internal error: unable to execute QEMU command 'block-commit': Top image file /tmp/images/c/../b/b not found
even though the file exists. Trying to teach libvirt the rules on
which name qemu will expect is not worth the effort (besides, we'd
have to remember it across libvirtd restarts, and track whether a
file was opened via metadata or via snapshot creation for a given
qemu process); it is easier to just always directly ask qemu what
string it expects to see in the first place.
As a safety valve, we validate that any name returned by qemu
still maps to the same local file as we have tracked it, so that
a compromised qemu cannot accidentally cause us to act on an
incorrect file.
* src/qemu/qemu_monitor.h (qemuMonitorDiskNameLookup): New
prototype.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONDiskNameLookup):
Likewise.
* src/qemu/qemu_monitor.c (qemuMonitorDiskNameLookup): New function.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONDiskNameLookup)
(qemuMonitorJSONDiskNameLookupOne): Likewise.
* src/qemu/qemu_driver.c (qemuDomainBlockCommit)
(qemuDomainBlockJobImpl): Use it.
Signed-off-by: Eric Blake <eblake@redhat.com>
2015-03-11 20:37:04 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-10-03 19:04:32 +00:00
|
|
|
if (!(thisdev = qemuMonitorJSONGetBlockDevDevice(dev)))
|
qemu: read backing chain names from qemu
https://bugzilla.redhat.com/show_bug.cgi?id=1199182 documents that
after a series of disk snapshots into existing destination images,
followed by active commits of the top image, it is possible for
qemu 2.2 and earlier to end up tracking a different name for the
image than what it would have had when opening the chain afresh.
That is, when starting with the chain 'a <- b <- c', the name
associated with 'b' is how it was spelled in the metadata of 'c',
but when starting with 'a', taking two snapshots into 'a <- b <- c',
then committing 'c' back into 'b', the name associated with 'b' is
now the name used when taking the first snapshot.
Sadly, older qemu doesn't know how to treat different spellings of
the same filename as identical files (it uses strcmp() instead of
checking for the same inode), which means libvirt's attempt to
commit an image using solely the names learned from qcow2 metadata
fails with a cryptic:
error: internal error: unable to execute QEMU command 'block-commit': Top image file /tmp/images/c/../b/b not found
even though the file exists. Trying to teach libvirt the rules on
which name qemu will expect is not worth the effort (besides, we'd
have to remember it across libvirtd restarts, and track whether a
file was opened via metadata or via snapshot creation for a given
qemu process); it is easier to just always directly ask qemu what
string it expects to see in the first place.
As a safety valve, we validate that any name returned by qemu
still maps to the same local file as we have tracked it, so that
a compromised qemu cannot accidentally cause us to act on an
incorrect file.
* src/qemu/qemu_monitor.h (qemuMonitorDiskNameLookup): New
prototype.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONDiskNameLookup):
Likewise.
* src/qemu/qemu_monitor.c (qemuMonitorDiskNameLookup): New function.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONDiskNameLookup)
(qemuMonitorJSONDiskNameLookupOne): Likewise.
* src/qemu/qemu_driver.c (qemuDomainBlockCommit)
(qemuDomainBlockJobImpl): Use it.
Signed-off-by: Eric Blake <eblake@redhat.com>
2015-03-11 20:37:04 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (STREQ(thisdev, device)) {
|
qemu: simplify json parsing
Rather than grabbing an arbitrary JSON value and then checking
if it has the right type, we might as well request the correct
type to begin with.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONIOProcessEvent)
(qemuMonitorJSONCommandWithFd, qemuMonitorJSONHandleGraphics)
(qemuMonitorJSONGetStatus, qemuMonitorJSONExtractCPUInfo)
(qemuMonitorJSONGetVirtType, qemuMonitorJSONGetBalloonInfo)
(qemuMonitorJSONGetMemoryStats)
(qemuMonitorJSONDevGetBlockExtent)
(qemuMonitorJSONGetOneBlockStatsInfo)
(qemuMonitorJSONGetAllBlockStatsInfo)
(qemuMonitorJSONBlockStatsUpdateCapacityOne)
(qemuMonitorJSONBlockStatsUpdateCapacity)
(qemuMonitorJSONGetBlockExtent)
(qemuMonitorJSONGetMigrationStatusReply)
(qemuMonitorJSONGetDumpGuestMemoryCapability)
(qemuMonitorJSONAddFd, qemuMonitorJSONQueryRxFilterParse)
(qemuMonitorJSONExtractChardevInfo)
(qemuMonitorJSONDiskNameLookupOne)
(qemuMonitorJSONDiskNameLookup)
(qemuMonitorJSONGetAllBlockJobInfo)
(qemuMonitorJSONBlockIoThrottleInfo, qemuMonitorJSONGetVersion)
(qemuMonitorJSONGetMachines, qemuMonitorJSONGetCPUDefinitions)
(qemuMonitorJSONGetCommands, qemuMonitorJSONGetEvents)
(qemuMonitorJSONGetKVMState, qemuMonitorJSONGetObjectTypes)
(qemuMonitorJSONGetObjectListPaths)
(qemuMonitorJSONGetObjectProps, qemuMonitorJSONGetTargetArch)
(qemuMonitorJSONGetMigrationCapabilities)
(qemuMonitorJSONGetStringArray, qemuMonitorJSONAttachCharDev)
(qemuMonitorJSONGetCPUx86Data, qemuMonitorJSONGetIOThreads)
(qemuMonitorJSONGetMemoryDeviceInfo): Use shorter idioms.
Signed-off-by: Eric Blake <eblake@redhat.com>
2015-06-20 19:40:21 +00:00
|
|
|
if ((inserted = virJSONValueObjectGetObject(dev, "inserted")) &&
|
|
|
|
(image = virJSONValueObjectGetObject(inserted, "image"))) {
|
qemu: read backing chain names from qemu
https://bugzilla.redhat.com/show_bug.cgi?id=1199182 documents that
after a series of disk snapshots into existing destination images,
followed by active commits of the top image, it is possible for
qemu 2.2 and earlier to end up tracking a different name for the
image than what it would have had when opening the chain afresh.
That is, when starting with the chain 'a <- b <- c', the name
associated with 'b' is how it was spelled in the metadata of 'c',
but when starting with 'a', taking two snapshots into 'a <- b <- c',
then committing 'c' back into 'b', the name associated with 'b' is
now the name used when taking the first snapshot.
Sadly, older qemu doesn't know how to treat different spellings of
the same filename as identical files (it uses strcmp() instead of
checking for the same inode), which means libvirt's attempt to
commit an image using solely the names learned from qcow2 metadata
fails with a cryptic:
error: internal error: unable to execute QEMU command 'block-commit': Top image file /tmp/images/c/../b/b not found
even though the file exists. Trying to teach libvirt the rules on
which name qemu will expect is not worth the effort (besides, we'd
have to remember it across libvirtd restarts, and track whether a
file was opened via metadata or via snapshot creation for a given
qemu process); it is easier to just always directly ask qemu what
string it expects to see in the first place.
As a safety valve, we validate that any name returned by qemu
still maps to the same local file as we have tracked it, so that
a compromised qemu cannot accidentally cause us to act on an
incorrect file.
* src/qemu/qemu_monitor.h (qemuMonitorDiskNameLookup): New
prototype.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONDiskNameLookup):
Likewise.
* src/qemu/qemu_monitor.c (qemuMonitorDiskNameLookup): New function.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONDiskNameLookup)
(qemuMonitorJSONDiskNameLookupOne): Likewise.
* src/qemu/qemu_driver.c (qemuDomainBlockCommit)
(qemuDomainBlockJobImpl): Use it.
Signed-off-by: Eric Blake <eblake@redhat.com>
2015-03-11 20:37:04 +00:00
|
|
|
ret = qemuMonitorJSONDiskNameLookupOne(image, top, target);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Guarantee an error when returning NULL, but don't override a
|
|
|
|
* more specific error if one was already generated. */
|
|
|
|
if (!ret && !virGetLastError())
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("unable to find backing name for device %s"),
|
|
|
|
device);
|
|
|
|
|
|
|
|
cleanup:
|
2016-09-27 13:39:21 +00:00
|
|
|
virJSONValueFree(devices);
|
qemu: read backing chain names from qemu
https://bugzilla.redhat.com/show_bug.cgi?id=1199182 documents that
after a series of disk snapshots into existing destination images,
followed by active commits of the top image, it is possible for
qemu 2.2 and earlier to end up tracking a different name for the
image than what it would have had when opening the chain afresh.
That is, when starting with the chain 'a <- b <- c', the name
associated with 'b' is how it was spelled in the metadata of 'c',
but when starting with 'a', taking two snapshots into 'a <- b <- c',
then committing 'c' back into 'b', the name associated with 'b' is
now the name used when taking the first snapshot.
Sadly, older qemu doesn't know how to treat different spellings of
the same filename as identical files (it uses strcmp() instead of
checking for the same inode), which means libvirt's attempt to
commit an image using solely the names learned from qcow2 metadata
fails with a cryptic:
error: internal error: unable to execute QEMU command 'block-commit': Top image file /tmp/images/c/../b/b not found
even though the file exists. Trying to teach libvirt the rules on
which name qemu will expect is not worth the effort (besides, we'd
have to remember it across libvirtd restarts, and track whether a
file was opened via metadata or via snapshot creation for a given
qemu process); it is easier to just always directly ask qemu what
string it expects to see in the first place.
As a safety valve, we validate that any name returned by qemu
still maps to the same local file as we have tracked it, so that
a compromised qemu cannot accidentally cause us to act on an
incorrect file.
* src/qemu/qemu_monitor.h (qemuMonitorDiskNameLookup): New
prototype.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONDiskNameLookup):
Likewise.
* src/qemu/qemu_monitor.c (qemuMonitorDiskNameLookup): New function.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONDiskNameLookup)
(qemuMonitorJSONDiskNameLookupOne): Likewise.
* src/qemu/qemu_driver.c (qemuDomainBlockCommit)
(qemuDomainBlockJobImpl): Use it.
Signed-off-by: Eric Blake <eblake@redhat.com>
2015-03-11 20:37:04 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-17 02:12:45 +00:00
|
|
|
int qemuMonitorJSONArbitraryCommand(qemuMonitorPtr mon,
|
|
|
|
const char *cmd_str,
|
2011-02-02 15:37:10 +00:00
|
|
|
char **reply_str,
|
|
|
|
bool hmp)
|
2010-04-17 02:12:45 +00:00
|
|
|
{
|
|
|
|
virJSONValuePtr cmd = NULL;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
2011-03-09 20:24:04 +00:00
|
|
|
if (hmp) {
|
|
|
|
return qemuMonitorJSONHumanCommandWithFd(mon, cmd_str, -1, reply_str);
|
2011-02-02 15:37:10 +00:00
|
|
|
} else {
|
2011-03-09 20:24:04 +00:00
|
|
|
if (!(cmd = virJSONValueFromString(cmd_str)))
|
|
|
|
goto cleanup;
|
2010-04-17 02:12:45 +00:00
|
|
|
|
2011-03-09 20:24:04 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2010-04-17 02:12:45 +00:00
|
|
|
|
2012-08-09 10:46:29 +00:00
|
|
|
if (!(*reply_str = virJSONValueToString(reply, false)))
|
2011-02-02 15:37:10 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-04-17 02:12:45 +00:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2010-04-17 02:12:45 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
2011-05-10 08:26:06 +00:00
|
|
|
|
|
|
|
int qemuMonitorJSONInjectNMI(qemuMonitorPtr mon)
|
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2011-05-10 08:26:06 +00:00
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
|
|
|
|
cmd = qemuMonitorJSONMakeCommand("inject-nmi", NULL);
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
2011-05-10 08:26:06 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2012-09-06 15:28:53 +00:00
|
|
|
if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_DEBUG("inject-nmi command not found, trying HMP");
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorTextInjectNMI(mon) < 0)
|
|
|
|
goto cleanup;
|
2011-05-10 08:26:06 +00:00
|
|
|
} else {
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2011-05-10 08:26:06 +00:00
|
|
|
}
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2011-05-10 08:26:06 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
2011-04-01 06:23:58 +00:00
|
|
|
|
2011-07-21 07:55:56 +00:00
|
|
|
int qemuMonitorJSONSendKey(qemuMonitorPtr mon,
|
|
|
|
unsigned int holdtime,
|
|
|
|
unsigned int *keycodes,
|
|
|
|
unsigned int nkeycodes)
|
|
|
|
{
|
2013-04-11 12:33:43 +00:00
|
|
|
int ret = -1;
|
|
|
|
virJSONValuePtr cmd = NULL;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
virJSONValuePtr keys = NULL;
|
|
|
|
virJSONValuePtr key = NULL;
|
Convert 'int i' to 'size_t i' in src/qemu files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2013-04-11 12:33:43 +00:00
|
|
|
|
|
|
|
/* create the key data array */
|
|
|
|
if (!(keys = virJSONValueNewArray()))
|
2013-07-04 10:14:12 +00:00
|
|
|
goto cleanup;
|
2013-04-11 12:33:43 +00:00
|
|
|
|
|
|
|
for (i = 0; i < nkeycodes; i++) {
|
|
|
|
if (keycodes[i] > 0xffff) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
Convert 'int i' to 'size_t i' in src/qemu files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
_("keycode %zu is invalid: 0x%X"), i, keycodes[i]);
|
2013-04-11 12:33:43 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create single key object */
|
|
|
|
if (!(key = virJSONValueNewObject()))
|
2013-07-04 10:14:12 +00:00
|
|
|
goto cleanup;
|
2013-04-11 12:33:43 +00:00
|
|
|
|
|
|
|
/* Union KeyValue has two types, use the generic one */
|
|
|
|
if (virJSONValueObjectAppendString(key, "type", "number") < 0)
|
2013-07-04 10:14:12 +00:00
|
|
|
goto cleanup;
|
2013-04-11 12:33:43 +00:00
|
|
|
|
|
|
|
/* with the keycode */
|
|
|
|
if (virJSONValueObjectAppendNumberInt(key, "data", keycodes[i]) < 0)
|
2013-07-04 10:14:12 +00:00
|
|
|
goto cleanup;
|
2013-04-11 12:33:43 +00:00
|
|
|
|
|
|
|
if (virJSONValueArrayAppend(keys, key) < 0)
|
2013-07-04 10:14:12 +00:00
|
|
|
goto cleanup;
|
2013-04-11 12:33:43 +00:00
|
|
|
|
|
|
|
key = NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd = qemuMonitorJSONMakeCommand("send-key",
|
|
|
|
"a:keys", keys,
|
2014-06-03 09:19:51 +00:00
|
|
|
"p:hold-time", holdtime,
|
2014-05-13 15:28:45 +00:00
|
|
|
NULL);
|
2013-04-11 12:33:43 +00:00
|
|
|
if (!cmd)
|
|
|
|
goto cleanup;
|
|
|
|
|
2013-10-02 16:18:13 +00:00
|
|
|
/* @keys is part of @cmd now. Avoid double free */
|
|
|
|
keys = NULL;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
2013-04-11 12:33:43 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
|
|
|
|
VIR_DEBUG("send-key command not found, trying HMP");
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorTextSendKey(mon, holdtime, keycodes, nkeycodes) < 0)
|
|
|
|
goto cleanup;
|
2013-04-11 12:33:43 +00:00
|
|
|
} else {
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2013-04-11 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2013-04-11 12:33:43 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
virJSONValueFree(keys);
|
|
|
|
virJSONValueFree(key);
|
|
|
|
return ret;
|
2011-07-21 07:55:56 +00:00
|
|
|
}
|
|
|
|
|
2011-04-01 06:23:58 +00:00
|
|
|
int qemuMonitorJSONScreendump(qemuMonitorPtr mon,
|
|
|
|
const char *file)
|
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2011-04-01 06:23:58 +00:00
|
|
|
virJSONValuePtr cmd, reply = NULL;
|
|
|
|
|
|
|
|
cmd = qemuMonitorJSONMakeCommand("screendump",
|
|
|
|
"s:filename", file,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2011-04-01 06:23:58 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2011-04-01 06:23:58 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2011-04-01 06:23:58 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
2011-07-22 05:39:37 +00:00
|
|
|
|
2015-05-22 11:33:49 +00:00
|
|
|
|
2014-08-27 19:29:14 +00:00
|
|
|
static int
|
2015-05-22 11:33:49 +00:00
|
|
|
qemuMonitorJSONParseBlockJobInfo(virHashTablePtr blockJobs,
|
|
|
|
virJSONValuePtr entry)
|
2011-07-22 05:39:37 +00:00
|
|
|
{
|
2015-05-22 11:33:49 +00:00
|
|
|
qemuMonitorBlockJobInfoPtr info = NULL;
|
|
|
|
const char *device;
|
2011-07-22 05:39:37 +00:00
|
|
|
const char *type;
|
2015-07-15 13:11:02 +00:00
|
|
|
bool ready;
|
2011-07-22 05:39:37 +00:00
|
|
|
|
2015-05-22 11:33:49 +00:00
|
|
|
if (!(device = virJSONValueObjectGetString(entry, "device"))) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("entry was missing 'device'"));
|
2011-07-22 05:39:37 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2016-06-29 17:34:00 +00:00
|
|
|
device = qemuAliasDiskDriveSkipPrefix(device);
|
2011-07-22 05:39:37 +00:00
|
|
|
|
2015-05-22 11:33:49 +00:00
|
|
|
if (VIR_ALLOC(info) < 0 ||
|
|
|
|
virHashAddEntry(blockJobs, device, info) < 0) {
|
|
|
|
VIR_FREE(info);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-07-15 13:11:02 +00:00
|
|
|
/* assume we don't know the state */
|
|
|
|
info->ready = -1;
|
|
|
|
|
2015-05-22 11:33:49 +00:00
|
|
|
if (!(type = virJSONValueObjectGetString(entry, "type"))) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("entry was missing 'type'"));
|
2011-07-22 05:39:37 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (STREQ(type, "stream"))
|
|
|
|
info->type = VIR_DOMAIN_BLOCK_JOB_TYPE_PULL;
|
2012-10-03 21:13:21 +00:00
|
|
|
else if (STREQ(type, "commit"))
|
|
|
|
info->type = VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT;
|
2012-10-12 20:06:10 +00:00
|
|
|
else if (STREQ(type, "mirror"))
|
|
|
|
info->type = VIR_DOMAIN_BLOCK_JOB_TYPE_COPY;
|
2011-07-22 05:39:37 +00:00
|
|
|
else
|
|
|
|
info->type = VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN;
|
|
|
|
|
2015-05-22 11:33:49 +00:00
|
|
|
if (virJSONValueObjectGetNumberUlong(entry, "speed", &info->bandwidth) < 0) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("entry was missing 'speed'"));
|
2011-07-22 05:39:37 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virJSONValueObjectGetNumberUlong(entry, "offset", &info->cur) < 0) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("entry was missing 'offset'"));
|
2011-07-22 05:39:37 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virJSONValueObjectGetNumberUlong(entry, "len", &info->end) < 0) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("entry was missing 'len'"));
|
2011-07-22 05:39:37 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2015-05-22 11:33:49 +00:00
|
|
|
|
2015-07-15 13:11:02 +00:00
|
|
|
if (virJSONValueObjectGetBoolean(entry, "ready", &ready) == 0)
|
|
|
|
info->ready = ready;
|
|
|
|
|
2015-05-22 11:33:49 +00:00
|
|
|
return 0;
|
2011-07-22 05:39:37 +00:00
|
|
|
}
|
|
|
|
|
2015-05-22 11:33:49 +00:00
|
|
|
virHashTablePtr
|
|
|
|
qemuMonitorJSONGetAllBlockJobInfo(qemuMonitorPtr mon)
|
2011-07-22 05:39:37 +00:00
|
|
|
{
|
2014-08-27 19:29:14 +00:00
|
|
|
virJSONValuePtr cmd = NULL;
|
|
|
|
virJSONValuePtr reply = NULL;
|
2011-07-22 05:39:37 +00:00
|
|
|
virJSONValuePtr data;
|
2015-10-08 08:17:42 +00:00
|
|
|
ssize_t nr_results;
|
Convert 'int i' to 'size_t i' in src/qemu files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2015-05-22 11:33:49 +00:00
|
|
|
virHashTablePtr blockJobs = NULL;
|
2011-07-22 05:39:37 +00:00
|
|
|
|
2014-08-27 19:29:14 +00:00
|
|
|
cmd = qemuMonitorJSONMakeCommand("query-block-jobs", NULL);
|
|
|
|
if (!cmd)
|
2015-05-22 11:33:49 +00:00
|
|
|
return NULL;
|
2014-08-27 19:29:14 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2011-07-22 05:39:37 +00:00
|
|
|
|
qemu: simplify json parsing
Rather than grabbing an arbitrary JSON value and then checking
if it has the right type, we might as well request the correct
type to begin with.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONIOProcessEvent)
(qemuMonitorJSONCommandWithFd, qemuMonitorJSONHandleGraphics)
(qemuMonitorJSONGetStatus, qemuMonitorJSONExtractCPUInfo)
(qemuMonitorJSONGetVirtType, qemuMonitorJSONGetBalloonInfo)
(qemuMonitorJSONGetMemoryStats)
(qemuMonitorJSONDevGetBlockExtent)
(qemuMonitorJSONGetOneBlockStatsInfo)
(qemuMonitorJSONGetAllBlockStatsInfo)
(qemuMonitorJSONBlockStatsUpdateCapacityOne)
(qemuMonitorJSONBlockStatsUpdateCapacity)
(qemuMonitorJSONGetBlockExtent)
(qemuMonitorJSONGetMigrationStatusReply)
(qemuMonitorJSONGetDumpGuestMemoryCapability)
(qemuMonitorJSONAddFd, qemuMonitorJSONQueryRxFilterParse)
(qemuMonitorJSONExtractChardevInfo)
(qemuMonitorJSONDiskNameLookupOne)
(qemuMonitorJSONDiskNameLookup)
(qemuMonitorJSONGetAllBlockJobInfo)
(qemuMonitorJSONBlockIoThrottleInfo, qemuMonitorJSONGetVersion)
(qemuMonitorJSONGetMachines, qemuMonitorJSONGetCPUDefinitions)
(qemuMonitorJSONGetCommands, qemuMonitorJSONGetEvents)
(qemuMonitorJSONGetKVMState, qemuMonitorJSONGetObjectTypes)
(qemuMonitorJSONGetObjectListPaths)
(qemuMonitorJSONGetObjectProps, qemuMonitorJSONGetTargetArch)
(qemuMonitorJSONGetMigrationCapabilities)
(qemuMonitorJSONGetStringArray, qemuMonitorJSONAttachCharDev)
(qemuMonitorJSONGetCPUx86Data, qemuMonitorJSONGetIOThreads)
(qemuMonitorJSONGetMemoryDeviceInfo): Use shorter idioms.
Signed-off-by: Eric Blake <eblake@redhat.com>
2015-06-20 19:40:21 +00:00
|
|
|
if ((data = virJSONValueObjectGetArray(reply, "return")) == NULL) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("reply was missing return data"));
|
2014-08-27 19:29:14 +00:00
|
|
|
goto cleanup;
|
2011-07-22 05:39:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((nr_results = virJSONValueArraySize(data)) < 0) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("unable to determine array size"));
|
2014-08-27 19:29:14 +00:00
|
|
|
goto cleanup;
|
2011-07-22 05:39:37 +00:00
|
|
|
}
|
|
|
|
|
2015-05-22 11:33:49 +00:00
|
|
|
if (!(blockJobs = virHashCreate(nr_results, virHashValueFree)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
for (i = 0; i < nr_results; i++) {
|
2011-07-22 05:39:37 +00:00
|
|
|
virJSONValuePtr entry = virJSONValueArrayGet(data, i);
|
2011-08-02 19:17:04 +00:00
|
|
|
if (!entry) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("missing array element"));
|
2015-05-22 11:33:49 +00:00
|
|
|
goto error;
|
2011-08-02 19:17:04 +00:00
|
|
|
}
|
2015-05-22 11:33:49 +00:00
|
|
|
if (qemuMonitorJSONParseBlockJobInfo(blockJobs, entry) < 0)
|
|
|
|
goto error;
|
2011-07-22 05:39:37 +00:00
|
|
|
}
|
|
|
|
|
2014-08-27 19:29:14 +00:00
|
|
|
cleanup:
|
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
2015-05-22 11:33:49 +00:00
|
|
|
return blockJobs;
|
|
|
|
|
|
|
|
error:
|
|
|
|
virHashFree(blockJobs);
|
|
|
|
blockJobs = NULL;
|
|
|
|
goto cleanup;
|
2011-07-22 05:39:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-31 15:13:21 +00:00
|
|
|
static int
|
|
|
|
qemuMonitorJSONBlockJobError(virJSONValuePtr reply,
|
|
|
|
const char *cmd_name,
|
|
|
|
const char *device)
|
|
|
|
{
|
|
|
|
virJSONValuePtr error;
|
|
|
|
|
|
|
|
if (!(error = virJSONValueObjectGet(reply, "error")))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (qemuMonitorJSONErrorIsClass(error, "DeviceNotActive")) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("No active operation on device: %s"), device);
|
|
|
|
} else if (qemuMonitorJSONErrorIsClass(error, "DeviceInUse")) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
|
|
|
_("Device %s in use"), device);
|
|
|
|
} else if (qemuMonitorJSONErrorIsClass(error, "NotSupported")) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("Operation is not supported for device: %s"), device);
|
|
|
|
} else if (qemuMonitorJSONErrorIsClass(error, "CommandNotFound")) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("Command '%s' is not found"), cmd_name);
|
|
|
|
} else {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Unexpected error: (%s) '%s'"),
|
|
|
|
NULLSTR(virJSONValueObjectGetString(error, "class")),
|
|
|
|
NULLSTR(virJSONValueObjectGetString(error, "desc")));
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
blockjob: fix block-stream bandwidth race
With RHEL 6.2, virDomainBlockPull(dom, dev, bandwidth, 0) has a race
with non-zero bandwidth: there is a window between the block_stream
and block_job_set_speed monitor commands where an unlimited amount
of data was let through, defeating the point of a throttle.
This race was first identified in commit a9d3495e, and libvirt was
able to reduce the size of the window for that race. In the meantime,
the qemu developers decided to fix things properly; per this message:
https://lists.gnu.org/archive/html/qemu-devel/2012-04/msg03793.html
the fix will be in qemu 1.1, and changes block-job-set-speed to use
a different parameter name, as well as adding a new optional parameter
to block-stream, which eliminates the race altogether.
Since our documentation already mentioned that we can refuse a non-zero
bandwidth for some hypervisors, I think the best solution is to do
just that for RHEL 6.2 qemu, so that the race is obvious to the user
(anyone using stock RHEL 6.2 binaries won't have this patch, and anyone
building their own libvirt with this patch for RHEL can also rebuild
qemu to get the modern semantics, so it is no real loss in behavior).
Meanwhile the code must be fixed to honor actual qemu 1.1 naming.
Rename the parameter to 'modern', since the naming difference now
covers more than just 'async' block-job-cancel. And while at it,
fix an unchecked integer overflow.
* src/qemu/qemu_monitor.h (enum BLOCK_JOB_CMD): Drop unused value,
rename enum to match conventions.
* src/qemu/qemu_monitor.c (qemuMonitorBlockJob): Reflect enum rename.
* src/qemu_qemu_monitor_json.h (qemuMonitorJSONBlockJob): Likewise.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONBlockJob): Likewise,
and support difference between RHEL 6.2 and qemu 1.1 block pull.
* src/qemu/qemu_driver.c (qemuDomainBlockJobImpl): Reject
bandwidth during pull with too-old qemu.
* src/libvirt.c (virDomainBlockPull, virDomainBlockRebase):
Document this.
2012-04-25 22:49:44 +00:00
|
|
|
/* speed is in bytes/sec */
|
2012-02-18 16:20:01 +00:00
|
|
|
int
|
2015-04-01 09:45:35 +00:00
|
|
|
qemuMonitorJSONBlockStream(qemuMonitorPtr mon,
|
|
|
|
const char *device,
|
|
|
|
const char *base,
|
|
|
|
const char *backingName,
|
2017-09-13 13:40:46 +00:00
|
|
|
unsigned long long speed)
|
2011-07-22 05:39:37 +00:00
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virJSONValuePtr cmd = NULL;
|
|
|
|
virJSONValuePtr reply = NULL;
|
2017-09-13 13:40:46 +00:00
|
|
|
const char *cmd_name = "block-stream";
|
2014-05-16 15:51:21 +00:00
|
|
|
|
2015-04-01 09:45:35 +00:00
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand(cmd_name,
|
|
|
|
"s:device", device,
|
|
|
|
"Y:speed", speed,
|
|
|
|
"S:base", base,
|
|
|
|
"S:backing-file", backingName,
|
|
|
|
NULL)))
|
2011-07-22 05:39:37 +00:00
|
|
|
return -1;
|
|
|
|
|
2015-03-31 15:13:21 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2011-07-22 05:39:37 +00:00
|
|
|
|
2015-03-31 15:13:21 +00:00
|
|
|
if (qemuMonitorJSONBlockJobError(reply, cmd_name, device) < 0)
|
|
|
|
goto cleanup;
|
2014-03-05 14:08:56 +00:00
|
|
|
|
2015-03-31 15:13:21 +00:00
|
|
|
ret = 0;
|
2011-07-22 05:39:37 +00:00
|
|
|
|
2015-03-31 15:13:21 +00:00
|
|
|
cleanup:
|
2011-07-22 05:39:37 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
2011-10-21 08:00:13 +00:00
|
|
|
|
2015-04-01 07:47:04 +00:00
|
|
|
|
2015-04-01 08:40:06 +00:00
|
|
|
int
|
|
|
|
qemuMonitorJSONBlockJobCancel(qemuMonitorPtr mon,
|
2017-09-13 13:40:46 +00:00
|
|
|
const char *device)
|
2015-04-01 08:40:06 +00:00
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virJSONValuePtr cmd = NULL;
|
|
|
|
virJSONValuePtr reply = NULL;
|
2017-09-13 13:40:46 +00:00
|
|
|
const char *cmd_name = "block-job-cancel";
|
2015-04-01 08:40:06 +00:00
|
|
|
|
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand(cmd_name,
|
|
|
|
"s:device", device,
|
|
|
|
NULL)))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (qemuMonitorJSONBlockJobError(reply, cmd_name, device) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-01 07:47:04 +00:00
|
|
|
int
|
|
|
|
qemuMonitorJSONBlockJobSetSpeed(qemuMonitorPtr mon,
|
|
|
|
const char *device,
|
2017-09-13 13:40:46 +00:00
|
|
|
unsigned long long speed)
|
2015-04-01 07:47:04 +00:00
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
2017-09-13 13:40:46 +00:00
|
|
|
const char *cmd_name = "block-job-set-speed";
|
2015-04-01 07:47:04 +00:00
|
|
|
|
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand(cmd_name,
|
|
|
|
"s:device", device,
|
2017-09-13 13:40:46 +00:00
|
|
|
"J:speed", speed,
|
2015-04-01 07:47:04 +00:00
|
|
|
NULL)))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (qemuMonitorJSONBlockJobError(reply, cmd_name, device) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-21 08:00:13 +00:00
|
|
|
int qemuMonitorJSONOpenGraphics(qemuMonitorPtr mon,
|
|
|
|
const char *protocol,
|
|
|
|
const char *fdname,
|
|
|
|
bool skipauth)
|
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2011-10-21 08:00:13 +00:00
|
|
|
virJSONValuePtr cmd, reply = NULL;
|
|
|
|
|
|
|
|
cmd = qemuMonitorJSONMakeCommand("add_client",
|
|
|
|
"s:protocol", protocol,
|
|
|
|
"s:fdname", fdname,
|
|
|
|
"b:skipauth", skipauth,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2011-10-21 08:00:13 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2011-10-21 08:00:13 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2011-10-21 08:00:13 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
2011-11-15 09:02:45 +00:00
|
|
|
|
|
|
|
|
2014-10-29 12:16:03 +00:00
|
|
|
#define GET_THROTTLE_STATS_OPTIONAL(FIELD, STORE) \
|
|
|
|
if (virJSONValueObjectGetNumberUlong(inserted, \
|
|
|
|
FIELD, \
|
|
|
|
&reply->STORE) < 0) { \
|
|
|
|
reply->STORE = 0; \
|
|
|
|
}
|
2012-08-09 07:58:05 +00:00
|
|
|
#define GET_THROTTLE_STATS(FIELD, STORE) \
|
|
|
|
if (virJSONValueObjectGetNumberUlong(inserted, \
|
|
|
|
FIELD, \
|
|
|
|
&reply->STORE) < 0) { \
|
2012-08-09 13:12:12 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, \
|
2012-08-09 07:58:05 +00:00
|
|
|
_("block_io_throttle field '%s' missing " \
|
|
|
|
"in qemu's output"), \
|
|
|
|
#STORE); \
|
2012-08-09 13:12:12 +00:00
|
|
|
goto cleanup; \
|
2012-08-09 07:58:05 +00:00
|
|
|
}
|
2011-11-15 09:02:45 +00:00
|
|
|
static int
|
|
|
|
qemuMonitorJSONBlockIoThrottleInfo(virJSONValuePtr result,
|
|
|
|
const char *device,
|
2016-05-20 06:30:45 +00:00
|
|
|
virDomainBlockIoTuneInfoPtr reply)
|
2011-11-15 09:02:45 +00:00
|
|
|
{
|
|
|
|
virJSONValuePtr io_throttle;
|
|
|
|
int ret = -1;
|
Convert 'int i' to 'size_t i' in src/qemu files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2012-08-09 07:58:05 +00:00
|
|
|
bool found = false;
|
2011-11-15 09:02:45 +00:00
|
|
|
|
qemu: simplify json parsing
Rather than grabbing an arbitrary JSON value and then checking
if it has the right type, we might as well request the correct
type to begin with.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONIOProcessEvent)
(qemuMonitorJSONCommandWithFd, qemuMonitorJSONHandleGraphics)
(qemuMonitorJSONGetStatus, qemuMonitorJSONExtractCPUInfo)
(qemuMonitorJSONGetVirtType, qemuMonitorJSONGetBalloonInfo)
(qemuMonitorJSONGetMemoryStats)
(qemuMonitorJSONDevGetBlockExtent)
(qemuMonitorJSONGetOneBlockStatsInfo)
(qemuMonitorJSONGetAllBlockStatsInfo)
(qemuMonitorJSONBlockStatsUpdateCapacityOne)
(qemuMonitorJSONBlockStatsUpdateCapacity)
(qemuMonitorJSONGetBlockExtent)
(qemuMonitorJSONGetMigrationStatusReply)
(qemuMonitorJSONGetDumpGuestMemoryCapability)
(qemuMonitorJSONAddFd, qemuMonitorJSONQueryRxFilterParse)
(qemuMonitorJSONExtractChardevInfo)
(qemuMonitorJSONDiskNameLookupOne)
(qemuMonitorJSONDiskNameLookup)
(qemuMonitorJSONGetAllBlockJobInfo)
(qemuMonitorJSONBlockIoThrottleInfo, qemuMonitorJSONGetVersion)
(qemuMonitorJSONGetMachines, qemuMonitorJSONGetCPUDefinitions)
(qemuMonitorJSONGetCommands, qemuMonitorJSONGetEvents)
(qemuMonitorJSONGetKVMState, qemuMonitorJSONGetObjectTypes)
(qemuMonitorJSONGetObjectListPaths)
(qemuMonitorJSONGetObjectProps, qemuMonitorJSONGetTargetArch)
(qemuMonitorJSONGetMigrationCapabilities)
(qemuMonitorJSONGetStringArray, qemuMonitorJSONAttachCharDev)
(qemuMonitorJSONGetCPUx86Data, qemuMonitorJSONGetIOThreads)
(qemuMonitorJSONGetMemoryDeviceInfo): Use shorter idioms.
Signed-off-by: Eric Blake <eblake@redhat.com>
2015-06-20 19:40:21 +00:00
|
|
|
if (!(io_throttle = virJSONValueObjectGetArray(result, "return"))) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_(" block_io_throttle reply was missing device list"));
|
2011-11-15 09:02:45 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < virJSONValueArraySize(io_throttle); i++) {
|
|
|
|
virJSONValuePtr temp_dev = virJSONValueArrayGet(io_throttle, i);
|
|
|
|
virJSONValuePtr inserted;
|
|
|
|
const char *current_dev;
|
|
|
|
|
|
|
|
if (!temp_dev || temp_dev->type != VIR_JSON_TYPE_OBJECT) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
2012-08-09 07:58:05 +00:00
|
|
|
_("block_io_throttle device entry "
|
|
|
|
"was not in expected format"));
|
2011-11-15 09:02:45 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2012-08-09 07:58:05 +00:00
|
|
|
if (!(current_dev = virJSONValueObjectGetString(temp_dev, "device"))) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
2012-08-09 07:58:05 +00:00
|
|
|
_("block_io_throttle device entry "
|
|
|
|
"was not in expected format"));
|
2011-11-15 09:02:45 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2012-11-01 17:20:56 +00:00
|
|
|
if (STRNEQ(current_dev, device))
|
2011-11-15 09:02:45 +00:00
|
|
|
continue;
|
|
|
|
|
2012-08-09 07:58:05 +00:00
|
|
|
found = true;
|
qemu: simplify json parsing
Rather than grabbing an arbitrary JSON value and then checking
if it has the right type, we might as well request the correct
type to begin with.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONIOProcessEvent)
(qemuMonitorJSONCommandWithFd, qemuMonitorJSONHandleGraphics)
(qemuMonitorJSONGetStatus, qemuMonitorJSONExtractCPUInfo)
(qemuMonitorJSONGetVirtType, qemuMonitorJSONGetBalloonInfo)
(qemuMonitorJSONGetMemoryStats)
(qemuMonitorJSONDevGetBlockExtent)
(qemuMonitorJSONGetOneBlockStatsInfo)
(qemuMonitorJSONGetAllBlockStatsInfo)
(qemuMonitorJSONBlockStatsUpdateCapacityOne)
(qemuMonitorJSONBlockStatsUpdateCapacity)
(qemuMonitorJSONGetBlockExtent)
(qemuMonitorJSONGetMigrationStatusReply)
(qemuMonitorJSONGetDumpGuestMemoryCapability)
(qemuMonitorJSONAddFd, qemuMonitorJSONQueryRxFilterParse)
(qemuMonitorJSONExtractChardevInfo)
(qemuMonitorJSONDiskNameLookupOne)
(qemuMonitorJSONDiskNameLookup)
(qemuMonitorJSONGetAllBlockJobInfo)
(qemuMonitorJSONBlockIoThrottleInfo, qemuMonitorJSONGetVersion)
(qemuMonitorJSONGetMachines, qemuMonitorJSONGetCPUDefinitions)
(qemuMonitorJSONGetCommands, qemuMonitorJSONGetEvents)
(qemuMonitorJSONGetKVMState, qemuMonitorJSONGetObjectTypes)
(qemuMonitorJSONGetObjectListPaths)
(qemuMonitorJSONGetObjectProps, qemuMonitorJSONGetTargetArch)
(qemuMonitorJSONGetMigrationCapabilities)
(qemuMonitorJSONGetStringArray, qemuMonitorJSONAttachCharDev)
(qemuMonitorJSONGetCPUx86Data, qemuMonitorJSONGetIOThreads)
(qemuMonitorJSONGetMemoryDeviceInfo): Use shorter idioms.
Signed-off-by: Eric Blake <eblake@redhat.com>
2015-06-20 19:40:21 +00:00
|
|
|
if (!(inserted = virJSONValueObjectGetObject(temp_dev, "inserted"))) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
2012-08-09 07:58:05 +00:00
|
|
|
_("block_io_throttle inserted entry "
|
|
|
|
"was not in expected format"));
|
2011-11-15 09:02:45 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2012-08-09 07:58:05 +00:00
|
|
|
GET_THROTTLE_STATS("bps", total_bytes_sec);
|
|
|
|
GET_THROTTLE_STATS("bps_rd", read_bytes_sec);
|
|
|
|
GET_THROTTLE_STATS("bps_wr", write_bytes_sec);
|
|
|
|
GET_THROTTLE_STATS("iops", total_iops_sec);
|
|
|
|
GET_THROTTLE_STATS("iops_rd", read_iops_sec);
|
|
|
|
GET_THROTTLE_STATS("iops_wr", write_iops_sec);
|
2016-05-20 06:30:45 +00:00
|
|
|
GET_THROTTLE_STATS_OPTIONAL("bps_max", total_bytes_sec_max);
|
|
|
|
GET_THROTTLE_STATS_OPTIONAL("bps_rd_max", read_bytes_sec_max);
|
|
|
|
GET_THROTTLE_STATS_OPTIONAL("bps_wr_max", write_bytes_sec_max);
|
|
|
|
GET_THROTTLE_STATS_OPTIONAL("iops_max", total_iops_sec_max);
|
|
|
|
GET_THROTTLE_STATS_OPTIONAL("iops_rd_max", read_iops_sec_max);
|
|
|
|
GET_THROTTLE_STATS_OPTIONAL("iops_wr_max", write_iops_sec_max);
|
|
|
|
GET_THROTTLE_STATS_OPTIONAL("iops_size", size_iops_sec);
|
2016-10-31 21:22:59 +00:00
|
|
|
|
|
|
|
if (VIR_STRDUP(reply->group_name,
|
|
|
|
virJSONValueObjectGetString(inserted, "group")) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2016-09-18 16:02:50 +00:00
|
|
|
GET_THROTTLE_STATS_OPTIONAL("bps_max_length", total_bytes_sec_max_length);
|
|
|
|
GET_THROTTLE_STATS_OPTIONAL("bps_rd_max_length", read_bytes_sec_max_length);
|
|
|
|
GET_THROTTLE_STATS_OPTIONAL("bps_wr_max_length", write_bytes_sec_max_length);
|
|
|
|
GET_THROTTLE_STATS_OPTIONAL("iops_max_length", total_iops_sec_max_length);
|
|
|
|
GET_THROTTLE_STATS_OPTIONAL("iops_rd_max_length", read_iops_sec_max_length);
|
|
|
|
GET_THROTTLE_STATS_OPTIONAL("iops_wr_max_length", write_iops_sec_max_length);
|
2011-11-15 09:02:45 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("cannot find throttling info for device '%s'"),
|
|
|
|
device);
|
2011-11-15 09:02:45 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2011-11-15 09:02:45 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2012-08-09 07:58:05 +00:00
|
|
|
#undef GET_THROTTLE_STATS
|
2014-10-29 12:16:03 +00:00
|
|
|
#undef GET_THROTTLE_STATS_OPTIONAL
|
2011-11-15 09:02:45 +00:00
|
|
|
|
|
|
|
int qemuMonitorJSONSetBlockIoThrottle(qemuMonitorPtr mon,
|
|
|
|
const char *device,
|
2014-11-10 15:19:09 +00:00
|
|
|
virDomainBlockIoTuneInfoPtr info,
|
2016-09-18 16:02:50 +00:00
|
|
|
bool supportMaxOptions,
|
2016-10-31 21:22:59 +00:00
|
|
|
bool supportGroupNameOption,
|
2016-09-18 16:02:50 +00:00
|
|
|
bool supportMaxLengthOptions)
|
2011-11-15 09:02:45 +00:00
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virJSONValuePtr cmd = NULL;
|
|
|
|
virJSONValuePtr result = NULL;
|
2016-11-07 19:46:09 +00:00
|
|
|
virJSONValuePtr args = NULL;
|
2011-11-15 09:02:45 +00:00
|
|
|
|
2016-11-07 19:46:09 +00:00
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("block_set_io_throttle", NULL)))
|
2011-11-15 09:02:45 +00:00
|
|
|
return -1;
|
|
|
|
|
2016-11-07 19:46:09 +00:00
|
|
|
if (virJSONValueObjectCreate(&args,
|
|
|
|
"s:device", device,
|
|
|
|
"U:bps", info->total_bytes_sec,
|
|
|
|
"U:bps_rd", info->read_bytes_sec,
|
|
|
|
"U:bps_wr", info->write_bytes_sec,
|
|
|
|
"U:iops", info->total_iops_sec,
|
|
|
|
"U:iops_rd", info->read_iops_sec,
|
|
|
|
"U:iops_wr", info->write_iops_sec,
|
|
|
|
NULL) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (supportMaxOptions &&
|
|
|
|
virJSONValueObjectAdd(args,
|
|
|
|
"U:bps_max", info->total_bytes_sec_max,
|
|
|
|
"U:bps_rd_max", info->read_bytes_sec_max,
|
|
|
|
"U:bps_wr_max", info->write_bytes_sec_max,
|
|
|
|
"U:iops_max", info->total_iops_sec_max,
|
|
|
|
"U:iops_rd_max", info->read_iops_sec_max,
|
|
|
|
"U:iops_wr_max", info->write_iops_sec_max,
|
|
|
|
"U:iops_size", info->size_iops_sec,
|
|
|
|
NULL) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2016-10-31 21:22:59 +00:00
|
|
|
if (supportGroupNameOption &&
|
|
|
|
virJSONValueObjectAdd(args,
|
2017-01-24 14:50:00 +00:00
|
|
|
"S:group", info->group_name,
|
2016-10-31 21:22:59 +00:00
|
|
|
NULL) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2016-11-07 19:46:09 +00:00
|
|
|
if (supportMaxLengthOptions &&
|
|
|
|
virJSONValueObjectAdd(args,
|
|
|
|
"P:bps_max_length",
|
|
|
|
info->total_bytes_sec_max_length,
|
|
|
|
"P:bps_rd_max_length",
|
|
|
|
info->read_bytes_sec_max_length,
|
|
|
|
"P:bps_wr_max_length",
|
|
|
|
info->write_bytes_sec_max_length,
|
|
|
|
"P:iops_max_length",
|
|
|
|
info->total_iops_sec_max_length,
|
|
|
|
"P:iops_rd_max_length",
|
|
|
|
info->read_iops_sec_max_length,
|
|
|
|
"P:iops_wr_max_length",
|
|
|
|
info->write_iops_sec_max_length,
|
|
|
|
NULL) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virJSONValueObjectAppend(cmd, "arguments", args) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
args = NULL; /* obj owns reference to args now */
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &result) < 0)
|
|
|
|
goto cleanup;
|
2011-11-15 09:02:45 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (virJSONValueObjectHasKey(result, "error")) {
|
2016-10-06 18:13:27 +00:00
|
|
|
if (qemuMonitorJSONHasError(result, "DeviceNotActive")) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("No active operation on device: %s"), device);
|
2016-10-06 18:13:27 +00:00
|
|
|
} else if (qemuMonitorJSONHasError(result, "NotSupported")) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("Operation is not supported for device: %s"), device);
|
2016-10-06 18:13:27 +00:00
|
|
|
} else {
|
|
|
|
virJSONValuePtr error = virJSONValueObjectGet(result, "error");
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("unable to execute '%s', unexpected error: '%s'"),
|
|
|
|
qemuMonitorJSONCommandName(cmd),
|
|
|
|
qemuMonitorJSONStringifyError(error));
|
|
|
|
}
|
2016-05-04 08:28:43 +00:00
|
|
|
goto cleanup;
|
2011-11-15 09:02:45 +00:00
|
|
|
}
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2011-11-15 09:02:45 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(result);
|
2016-11-07 19:46:09 +00:00
|
|
|
virJSONValueFree(args);
|
2011-11-15 09:02:45 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int qemuMonitorJSONGetBlockIoThrottle(qemuMonitorPtr mon,
|
|
|
|
const char *device,
|
2016-05-20 06:30:45 +00:00
|
|
|
virDomainBlockIoTuneInfoPtr reply)
|
2011-11-15 09:02:45 +00:00
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virJSONValuePtr cmd = NULL;
|
|
|
|
virJSONValuePtr result = NULL;
|
|
|
|
|
|
|
|
cmd = qemuMonitorJSONMakeCommand("query-block", NULL);
|
2014-11-13 14:25:30 +00:00
|
|
|
if (!cmd)
|
2011-11-15 09:02:45 +00:00
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &result) < 0)
|
|
|
|
goto cleanup;
|
2011-11-15 09:02:45 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (virJSONValueObjectHasKey(result, "error")) {
|
2011-11-15 09:02:45 +00:00
|
|
|
if (qemuMonitorJSONHasError(result, "DeviceNotActive"))
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("No active operation on device: %s"), device);
|
2011-11-15 09:02:45 +00:00
|
|
|
else if (qemuMonitorJSONHasError(result, "NotSupported"))
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
|
|
|
_("Operation is not supported for device: %s"), device);
|
2011-11-15 09:02:45 +00:00
|
|
|
else
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Unexpected error"));
|
2016-05-04 08:28:43 +00:00
|
|
|
goto cleanup;
|
2011-11-15 09:02:45 +00:00
|
|
|
}
|
|
|
|
|
2016-05-20 06:30:45 +00:00
|
|
|
ret = qemuMonitorJSONBlockIoThrottleInfo(result, device, reply);
|
2016-05-04 08:28:43 +00:00
|
|
|
cleanup:
|
2011-11-15 09:02:45 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(result);
|
|
|
|
return ret;
|
|
|
|
}
|
2012-02-10 12:33:52 +00:00
|
|
|
|
|
|
|
int qemuMonitorJSONSystemWakeup(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virJSONValuePtr cmd = NULL;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
|
|
|
|
cmd = qemuMonitorJSONMakeCommand("system_wakeup", NULL);
|
2014-11-13 14:25:30 +00:00
|
|
|
if (!cmd)
|
2012-02-10 12:33:52 +00:00
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2012-02-10 12:33:52 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2012-02-10 12:33:52 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2012-02-10 12:33:52 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
2012-08-15 14:04:09 +00:00
|
|
|
|
|
|
|
int qemuMonitorJSONGetVersion(qemuMonitorPtr mon,
|
|
|
|
int *major,
|
|
|
|
int *minor,
|
|
|
|
int *micro,
|
|
|
|
char **package)
|
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2012-08-15 14:04:09 +00:00
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
virJSONValuePtr data;
|
|
|
|
virJSONValuePtr qemu;
|
|
|
|
|
|
|
|
*major = *minor = *micro = 0;
|
|
|
|
if (package)
|
|
|
|
*package = NULL;
|
|
|
|
|
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("query-version", NULL)))
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
2012-08-15 14:04:09 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2012-08-15 14:04:09 +00:00
|
|
|
|
2016-11-20 23:10:06 +00:00
|
|
|
data = virJSONValueObjectGetObject(reply, "return");
|
2012-08-15 14:04:09 +00:00
|
|
|
|
qemu: simplify json parsing
Rather than grabbing an arbitrary JSON value and then checking
if it has the right type, we might as well request the correct
type to begin with.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONIOProcessEvent)
(qemuMonitorJSONCommandWithFd, qemuMonitorJSONHandleGraphics)
(qemuMonitorJSONGetStatus, qemuMonitorJSONExtractCPUInfo)
(qemuMonitorJSONGetVirtType, qemuMonitorJSONGetBalloonInfo)
(qemuMonitorJSONGetMemoryStats)
(qemuMonitorJSONDevGetBlockExtent)
(qemuMonitorJSONGetOneBlockStatsInfo)
(qemuMonitorJSONGetAllBlockStatsInfo)
(qemuMonitorJSONBlockStatsUpdateCapacityOne)
(qemuMonitorJSONBlockStatsUpdateCapacity)
(qemuMonitorJSONGetBlockExtent)
(qemuMonitorJSONGetMigrationStatusReply)
(qemuMonitorJSONGetDumpGuestMemoryCapability)
(qemuMonitorJSONAddFd, qemuMonitorJSONQueryRxFilterParse)
(qemuMonitorJSONExtractChardevInfo)
(qemuMonitorJSONDiskNameLookupOne)
(qemuMonitorJSONDiskNameLookup)
(qemuMonitorJSONGetAllBlockJobInfo)
(qemuMonitorJSONBlockIoThrottleInfo, qemuMonitorJSONGetVersion)
(qemuMonitorJSONGetMachines, qemuMonitorJSONGetCPUDefinitions)
(qemuMonitorJSONGetCommands, qemuMonitorJSONGetEvents)
(qemuMonitorJSONGetKVMState, qemuMonitorJSONGetObjectTypes)
(qemuMonitorJSONGetObjectListPaths)
(qemuMonitorJSONGetObjectProps, qemuMonitorJSONGetTargetArch)
(qemuMonitorJSONGetMigrationCapabilities)
(qemuMonitorJSONGetStringArray, qemuMonitorJSONAttachCharDev)
(qemuMonitorJSONGetCPUx86Data, qemuMonitorJSONGetIOThreads)
(qemuMonitorJSONGetMemoryDeviceInfo): Use shorter idioms.
Signed-off-by: Eric Blake <eblake@redhat.com>
2015-06-20 19:40:21 +00:00
|
|
|
if (!(qemu = virJSONValueObjectGetObject(data, "qemu"))) {
|
2012-08-15 14:04:09 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-version reply was missing 'qemu' data"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virJSONValueObjectGetNumberInt(qemu, "major", major) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-version reply was missing 'major' version"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (virJSONValueObjectGetNumberInt(qemu, "minor", minor) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-version reply was missing 'minor' version"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (virJSONValueObjectGetNumberInt(qemu, "micro", micro) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-version reply was missing 'micro' version"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (package) {
|
|
|
|
const char *tmp;
|
|
|
|
if (!(tmp = virJSONValueObjectGetString(data, "package"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-version reply was missing 'package' version"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-05-20 09:23:13 +00:00
|
|
|
if (VIR_STRDUP(*package, tmp) < 0)
|
2012-08-15 14:04:09 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2012-08-15 14:04:09 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
2012-08-15 15:18:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorJSONGetMachines(qemuMonitorPtr mon,
|
|
|
|
qemuMonitorMachineInfoPtr **machines)
|
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2012-08-15 15:18:41 +00:00
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
virJSONValuePtr data;
|
|
|
|
qemuMonitorMachineInfoPtr *infolist = NULL;
|
2015-10-08 08:17:42 +00:00
|
|
|
ssize_t n = 0;
|
2012-08-15 15:18:41 +00:00
|
|
|
size_t i;
|
|
|
|
|
|
|
|
*machines = NULL;
|
|
|
|
|
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("query-machines", NULL)))
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
2012-08-15 15:18:41 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2012-08-15 15:18:41 +00:00
|
|
|
|
2016-11-20 23:10:06 +00:00
|
|
|
if (!(data = virJSONValueObjectGetArray(reply, "return")) ||
|
|
|
|
(n = virJSONValueArraySize(data)) < 0) {
|
2012-08-15 15:18:41 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-machines reply data was not an array"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-04-26 17:47:23 +00:00
|
|
|
/* null-terminated list */
|
2013-07-04 10:14:12 +00:00
|
|
|
if (VIR_ALLOC_N(infolist, n + 1) < 0)
|
2012-08-15 15:18:41 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-05-21 07:21:20 +00:00
|
|
|
for (i = 0; i < n; i++) {
|
2012-08-15 15:18:41 +00:00
|
|
|
virJSONValuePtr child = virJSONValueArrayGet(data, i);
|
|
|
|
const char *tmp;
|
|
|
|
qemuMonitorMachineInfoPtr info;
|
|
|
|
|
2013-07-04 10:14:12 +00:00
|
|
|
if (VIR_ALLOC(info) < 0)
|
2012-08-15 15:18:41 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
infolist[i] = info;
|
|
|
|
|
|
|
|
if (!(tmp = virJSONValueObjectGetString(child, "name"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-machines reply data was missing 'name'"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-05-20 09:23:13 +00:00
|
|
|
if (VIR_STRDUP(info->name, tmp) < 0)
|
2012-08-15 15:18:41 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virJSONValueObjectHasKey(child, "is-default") &&
|
|
|
|
virJSONValueObjectGetBoolean(child, "is-default", &info->isDefault) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-machines reply has malformed 'is-default' data"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virJSONValueObjectHasKey(child, "alias")) {
|
|
|
|
if (!(tmp = virJSONValueObjectGetString(child, "alias"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-machines reply has malformed 'alias' data"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-05-20 09:23:13 +00:00
|
|
|
if (VIR_STRDUP(info->alias, tmp) < 0)
|
2012-08-15 15:18:41 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2013-06-26 15:46:35 +00:00
|
|
|
if (virJSONValueObjectHasKey(child, "cpu-max") &&
|
|
|
|
virJSONValueObjectGetNumberUint(child, "cpu-max", &info->maxCpus) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-machines reply has malformed 'cpu-max' data"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2016-07-29 07:45:19 +00:00
|
|
|
|
|
|
|
ignore_value(virJSONValueObjectGetBoolean(child, "hotpluggable-cpus",
|
|
|
|
&info->hotplugCpus));
|
2012-08-15 15:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = n;
|
|
|
|
*machines = infolist;
|
2016-05-16 11:47:26 +00:00
|
|
|
infolist = NULL;
|
2012-08-15 15:18:41 +00:00
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2016-05-16 11:47:26 +00:00
|
|
|
if (infolist) {
|
2013-05-21 07:21:20 +00:00
|
|
|
for (i = 0; i < n; i++)
|
2012-08-15 15:18:41 +00:00
|
|
|
qemuMonitorMachineInfoFree(infolist[i]);
|
|
|
|
VIR_FREE(infolist);
|
|
|
|
}
|
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
2012-08-20 14:58:20 +00:00
|
|
|
|
|
|
|
|
2016-04-21 10:51:01 +00:00
|
|
|
int
|
|
|
|
qemuMonitorJSONGetCPUDefinitions(qemuMonitorPtr mon,
|
|
|
|
qemuMonitorCPUDefInfoPtr **cpus)
|
2012-08-20 14:58:20 +00:00
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2012-08-20 14:58:20 +00:00
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
virJSONValuePtr data;
|
2016-04-21 10:51:01 +00:00
|
|
|
qemuMonitorCPUDefInfoPtr *cpulist = NULL;
|
2012-08-20 14:58:20 +00:00
|
|
|
int n = 0;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
*cpus = NULL;
|
|
|
|
|
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("query-cpu-definitions", NULL)))
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2012-08-20 14:58:20 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
/* Urgh, some QEMU architectures have the query-cpu-definitions
|
|
|
|
* command, but return 'GenericError' with string "Not supported",
|
|
|
|
* instead of simply omitting the command entirely :-(
|
|
|
|
*/
|
|
|
|
if (qemuMonitorJSONHasError(reply, "GenericError")) {
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
2012-09-28 14:55:54 +00:00
|
|
|
}
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
2012-08-20 14:58:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-11-20 23:10:06 +00:00
|
|
|
if (!(data = virJSONValueObjectGetArray(reply, "return")) ||
|
|
|
|
(n = virJSONValueArraySize(data)) < 0) {
|
2012-08-20 14:58:20 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-cpu-definitions reply data was not an array"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2016-04-21 10:51:01 +00:00
|
|
|
if (VIR_ALLOC_N(cpulist, n) < 0)
|
2012-08-20 14:58:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-05-21 07:21:20 +00:00
|
|
|
for (i = 0; i < n; i++) {
|
2012-08-20 14:58:20 +00:00
|
|
|
virJSONValuePtr child = virJSONValueArrayGet(data, i);
|
|
|
|
const char *tmp;
|
2016-04-21 10:51:01 +00:00
|
|
|
qemuMonitorCPUDefInfoPtr cpu;
|
|
|
|
|
|
|
|
if (VIR_ALLOC(cpu) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
cpulist[i] = cpu;
|
2012-08-20 14:58:20 +00:00
|
|
|
|
|
|
|
if (!(tmp = virJSONValueObjectGetString(child, "name"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-cpu-definitions reply data was missing 'name'"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2016-04-21 10:51:01 +00:00
|
|
|
if (VIR_STRDUP(cpu->name, tmp) < 0)
|
2012-08-20 14:58:20 +00:00
|
|
|
goto cleanup;
|
2016-04-21 11:08:12 +00:00
|
|
|
|
|
|
|
if (virJSONValueObjectHasKey(child, "unavailable-features")) {
|
|
|
|
virJSONValuePtr blockers;
|
2017-09-20 08:45:49 +00:00
|
|
|
size_t j;
|
|
|
|
int len;
|
2016-04-21 11:08:12 +00:00
|
|
|
|
|
|
|
blockers = virJSONValueObjectGetArray(child,
|
|
|
|
"unavailable-features");
|
|
|
|
if (!blockers) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("unavailable-features in query-cpu-definitions "
|
|
|
|
"reply data was not an array"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2017-09-20 08:45:49 +00:00
|
|
|
len = virJSONValueArraySize(blockers);
|
|
|
|
|
|
|
|
if (len == 0) {
|
2016-04-21 11:08:12 +00:00
|
|
|
cpu->usable = VIR_TRISTATE_BOOL_YES;
|
2017-09-20 08:45:49 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
cpu->usable = VIR_TRISTATE_BOOL_NO;
|
|
|
|
if (VIR_ALLOC_N(cpu->blockers, len + 1) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
for (j = 0; j < len; j++) {
|
|
|
|
virJSONValuePtr blocker = virJSONValueArrayGet(blockers, j);
|
|
|
|
|
|
|
|
if (blocker->type != VIR_JSON_TYPE_STRING) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("unexpected value in unavailable-features "
|
|
|
|
"array"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VIR_STRDUP(cpu->blockers[j], virJSONValueGetString(blocker)) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2016-04-21 11:08:12 +00:00
|
|
|
}
|
2012-08-20 14:58:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = n;
|
|
|
|
*cpus = cpulist;
|
2016-05-16 11:47:26 +00:00
|
|
|
cpulist = NULL;
|
2012-08-20 14:58:20 +00:00
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2016-04-21 10:51:01 +00:00
|
|
|
if (cpulist) {
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
qemuMonitorCPUDefInfoFree(cpulist[i]);
|
|
|
|
VIR_FREE(cpulist);
|
|
|
|
}
|
2012-08-20 14:58:20 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
2012-08-22 09:25:20 +00:00
|
|
|
|
2017-02-22 15:01:30 +00:00
|
|
|
|
|
|
|
VIR_ENUM_IMPL(qemuMonitorCPUProperty,
|
|
|
|
QEMU_MONITOR_CPU_PROPERTY_LAST,
|
|
|
|
"boolean", "string", "number")
|
|
|
|
|
2016-12-18 19:22:26 +00:00
|
|
|
static int
|
|
|
|
qemuMonitorJSONParseCPUModelProperty(const char *key,
|
|
|
|
virJSONValue *value,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
qemuMonitorCPUModelInfoPtr machine_model = opaque;
|
2017-02-22 15:01:30 +00:00
|
|
|
qemuMonitorCPUPropertyPtr prop;
|
2016-12-18 19:22:26 +00:00
|
|
|
|
2017-02-22 15:01:30 +00:00
|
|
|
prop = machine_model->props + machine_model->nprops;
|
2017-01-11 13:35:52 +00:00
|
|
|
|
2017-02-22 15:01:30 +00:00
|
|
|
switch ((virJSONType) value->type) {
|
|
|
|
case VIR_JSON_TYPE_STRING:
|
|
|
|
if (VIR_STRDUP(prop->value.string, virJSONValueGetString(value)) < 0)
|
|
|
|
return -1;
|
|
|
|
prop->type = QEMU_MONITOR_CPU_PROPERTY_STRING;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_JSON_TYPE_NUMBER:
|
|
|
|
/* Ignore numbers which cannot be parsed as unsigned long long */
|
|
|
|
if (virJSONValueGetNumberLong(value, &prop->value.number) < 0)
|
|
|
|
return 0;
|
|
|
|
prop->type = QEMU_MONITOR_CPU_PROPERTY_NUMBER;
|
|
|
|
break;
|
2016-12-18 19:22:26 +00:00
|
|
|
|
2017-02-22 15:01:30 +00:00
|
|
|
case VIR_JSON_TYPE_BOOLEAN:
|
|
|
|
virJSONValueGetBoolean(value, &prop->value.boolean);
|
|
|
|
prop->type = QEMU_MONITOR_CPU_PROPERTY_BOOLEAN;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_JSON_TYPE_OBJECT:
|
|
|
|
case VIR_JSON_TYPE_ARRAY:
|
|
|
|
case VIR_JSON_TYPE_NULL:
|
|
|
|
return 0;
|
|
|
|
}
|
2016-12-18 19:22:26 +00:00
|
|
|
|
|
|
|
machine_model->nprops++;
|
2017-02-22 15:01:30 +00:00
|
|
|
if (VIR_STRDUP(prop->name, key) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2016-12-18 19:22:26 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
|
2017-01-31 12:44:00 +00:00
|
|
|
qemuMonitorCPUModelExpansionType type,
|
2016-12-18 19:22:26 +00:00
|
|
|
const char *model_name,
|
2017-03-29 08:58:41 +00:00
|
|
|
bool migratable,
|
2016-12-18 19:22:26 +00:00
|
|
|
qemuMonitorCPUModelInfoPtr *model_info)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
2017-02-23 12:53:51 +00:00
|
|
|
virJSONValuePtr model = NULL;
|
2017-03-29 08:58:41 +00:00
|
|
|
virJSONValuePtr props = NULL;
|
2016-12-18 19:22:26 +00:00
|
|
|
virJSONValuePtr cmd = NULL;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
virJSONValuePtr data;
|
|
|
|
virJSONValuePtr cpu_model;
|
|
|
|
virJSONValuePtr cpu_props;
|
|
|
|
qemuMonitorCPUModelInfoPtr machine_model = NULL;
|
|
|
|
char const *cpu_name;
|
2017-01-31 12:44:00 +00:00
|
|
|
const char *typeStr = "";
|
2016-12-18 19:22:26 +00:00
|
|
|
|
|
|
|
*model_info = NULL;
|
|
|
|
|
|
|
|
if (!(model = virJSONValueNewObject()))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virJSONValueObjectAppendString(model, "name", model_name) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2017-03-29 08:58:41 +00:00
|
|
|
if (!migratable) {
|
|
|
|
if (!(props = virJSONValueNewObject()) ||
|
|
|
|
virJSONValueObjectAppendBoolean(props, "migratable", false) < 0 ||
|
|
|
|
virJSONValueObjectAppend(model, "props", props) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
props = NULL;
|
|
|
|
}
|
|
|
|
|
2017-02-23 12:53:51 +00:00
|
|
|
retry:
|
2017-01-31 12:44:00 +00:00
|
|
|
switch (type) {
|
|
|
|
case QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC:
|
2017-02-23 12:53:51 +00:00
|
|
|
case QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC_FULL:
|
2017-01-31 12:44:00 +00:00
|
|
|
typeStr = "static";
|
|
|
|
break;
|
2017-02-23 12:53:51 +00:00
|
|
|
|
|
|
|
case QEMU_MONITOR_CPU_MODEL_EXPANSION_FULL:
|
|
|
|
typeStr = "full";
|
|
|
|
break;
|
2017-01-31 12:44:00 +00:00
|
|
|
}
|
|
|
|
|
2016-12-18 19:22:26 +00:00
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("query-cpu-model-expansion",
|
2017-01-31 12:44:00 +00:00
|
|
|
"s:type", typeStr,
|
2016-12-18 19:22:26 +00:00
|
|
|
"a:model", model,
|
|
|
|
NULL)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* model will be freed when cmd is freed. we set model
|
|
|
|
* to NULL to avoid double freeing.
|
|
|
|
*/
|
|
|
|
model = NULL;
|
|
|
|
|
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2017-01-12 16:18:11 +00:00
|
|
|
/* Even though query-cpu-model-expansion is advertised by query-commands it
|
|
|
|
* may just return GenericError if it is not implemented for the requested
|
|
|
|
* guest architecture or it is not supported in the host environment.
|
|
|
|
*/
|
|
|
|
if (qemuMonitorJSONHasError(reply, "GenericError")) {
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2016-12-18 19:22:26 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
data = virJSONValueObjectGetObject(reply, "return");
|
|
|
|
|
|
|
|
if (!(cpu_model = virJSONValueObjectGetObject(data, "model"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-cpu-model-expansion reply data was missing 'model'"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2017-02-23 12:53:51 +00:00
|
|
|
/* QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC_FULL requests "full" expansion
|
|
|
|
* on the result of the initial "static" expansion.
|
|
|
|
*/
|
|
|
|
if (type == QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC_FULL) {
|
|
|
|
if (!(model = virJSONValueCopy(cpu_model)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
type = QEMU_MONITOR_CPU_MODEL_EXPANSION_FULL;
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
2016-12-18 19:22:26 +00:00
|
|
|
if (!(cpu_name = virJSONValueObjectGetString(cpu_model, "name"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-cpu-model-expansion reply data was missing 'name'"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(cpu_props = virJSONValueObjectGetObject(cpu_model, "props"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-cpu-model-expansion reply data was missing 'props'"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VIR_ALLOC(machine_model) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (VIR_STRDUP(machine_model->name, cpu_name) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (VIR_ALLOC_N(machine_model->props, cpu_props->data.object.npairs) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virJSONValueObjectForeachKeyValue(cpu_props,
|
|
|
|
qemuMonitorJSONParseCPUModelProperty,
|
|
|
|
machine_model) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
*model_info = machine_model;
|
|
|
|
machine_model = NULL;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
qemuMonitorCPUModelInfoFree(machine_model);
|
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
virJSONValueFree(model);
|
2017-03-29 08:58:41 +00:00
|
|
|
virJSONValueFree(props);
|
2016-12-18 19:22:26 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-08-22 09:25:20 +00:00
|
|
|
|
|
|
|
int qemuMonitorJSONGetCommands(qemuMonitorPtr mon,
|
|
|
|
char ***commands)
|
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2012-08-22 09:25:20 +00:00
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
virJSONValuePtr data;
|
|
|
|
char **commandlist = NULL;
|
2015-10-08 08:17:42 +00:00
|
|
|
ssize_t n = 0;
|
2012-08-22 09:25:20 +00:00
|
|
|
size_t i;
|
|
|
|
|
|
|
|
*commands = NULL;
|
|
|
|
|
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("query-commands", NULL)))
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
2012-08-22 09:25:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2012-08-22 09:25:20 +00:00
|
|
|
|
2016-11-20 23:10:06 +00:00
|
|
|
if (!(data = virJSONValueObjectGetArray(reply, "return")) ||
|
|
|
|
(n = virJSONValueArraySize(data)) < 0) {
|
2012-08-22 09:25:20 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-commands reply data was not an array"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-04-26 17:47:23 +00:00
|
|
|
/* null-terminated list */
|
2013-07-04 10:14:12 +00:00
|
|
|
if (VIR_ALLOC_N(commandlist, n + 1) < 0)
|
2012-08-22 09:25:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-05-21 07:21:20 +00:00
|
|
|
for (i = 0; i < n; i++) {
|
2012-08-22 09:25:20 +00:00
|
|
|
virJSONValuePtr child = virJSONValueArrayGet(data, i);
|
|
|
|
const char *tmp;
|
|
|
|
|
|
|
|
if (!(tmp = virJSONValueObjectGetString(child, "name"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-commands reply data was missing 'name'"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-05-20 09:23:13 +00:00
|
|
|
if (VIR_STRDUP(commandlist[i], tmp) < 0)
|
2012-08-22 09:25:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = n;
|
|
|
|
*commands = commandlist;
|
2016-05-16 11:47:26 +00:00
|
|
|
commandlist = NULL;
|
|
|
|
|
2012-08-22 09:25:20 +00:00
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2016-11-25 08:18:35 +00:00
|
|
|
virStringListFree(commandlist);
|
2012-08-22 09:25:20 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
2012-08-22 09:48:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorJSONGetEvents(qemuMonitorPtr mon,
|
|
|
|
char ***events)
|
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2012-08-22 09:48:41 +00:00
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
virJSONValuePtr data;
|
|
|
|
char **eventlist = NULL;
|
2015-10-08 08:17:42 +00:00
|
|
|
ssize_t n = 0;
|
2012-08-22 09:48:41 +00:00
|
|
|
size_t i;
|
|
|
|
|
|
|
|
*events = NULL;
|
|
|
|
|
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("query-events", NULL)))
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2012-08-22 09:48:41 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
2012-09-27 14:25:16 +00:00
|
|
|
}
|
2012-08-22 09:48:41 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
2012-08-22 09:48:41 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-11-20 23:10:06 +00:00
|
|
|
if (!(data = virJSONValueObjectGetArray(reply, "return")) ||
|
|
|
|
(n = virJSONValueArraySize(data)) < 0) {
|
2012-08-22 09:48:41 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-events reply data was not an array"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-04-26 17:47:23 +00:00
|
|
|
/* null-terminated list */
|
2013-07-04 10:14:12 +00:00
|
|
|
if (VIR_ALLOC_N(eventlist, n + 1) < 0)
|
2012-08-22 09:48:41 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-05-21 07:21:20 +00:00
|
|
|
for (i = 0; i < n; i++) {
|
2012-08-22 09:48:41 +00:00
|
|
|
virJSONValuePtr child = virJSONValueArrayGet(data, i);
|
|
|
|
const char *tmp;
|
|
|
|
|
|
|
|
if (!(tmp = virJSONValueObjectGetString(child, "name"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-events reply data was missing 'name'"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-05-20 09:23:13 +00:00
|
|
|
if (VIR_STRDUP(eventlist[i], tmp) < 0)
|
2012-08-22 09:48:41 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = n;
|
|
|
|
*events = eventlist;
|
2016-05-16 11:47:26 +00:00
|
|
|
eventlist = NULL;
|
2012-08-22 09:48:41 +00:00
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2016-11-25 08:18:35 +00:00
|
|
|
virStringListFree(eventlist);
|
2012-08-22 09:48:41 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
2012-08-22 09:48:41 +00:00
|
|
|
|
|
|
|
|
2013-04-26 17:13:45 +00:00
|
|
|
int
|
|
|
|
qemuMonitorJSONGetCommandLineOptionParameters(qemuMonitorPtr mon,
|
|
|
|
const char *option,
|
2014-06-17 11:41:16 +00:00
|
|
|
char ***params,
|
|
|
|
bool *found)
|
2013-04-26 17:13:45 +00:00
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2013-05-13 22:48:55 +00:00
|
|
|
virJSONValuePtr cmd = NULL;
|
2013-04-26 17:13:45 +00:00
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
virJSONValuePtr data = NULL;
|
|
|
|
virJSONValuePtr array = NULL;
|
|
|
|
char **paramlist = NULL;
|
2015-10-08 08:17:42 +00:00
|
|
|
ssize_t n = 0;
|
2013-04-26 17:13:45 +00:00
|
|
|
size_t i;
|
|
|
|
|
|
|
|
*params = NULL;
|
2014-06-17 11:41:16 +00:00
|
|
|
if (found)
|
|
|
|
*found = false;
|
2013-04-26 17:13:45 +00:00
|
|
|
|
|
|
|
/* query-command-line-options has fixed output for a given qemu
|
|
|
|
* binary; but since callers want to query parameters for one
|
|
|
|
* option at a time, we cache the option list from qemu. */
|
|
|
|
if (!(array = qemuMonitorGetOptions(mon))) {
|
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("query-command-line-options",
|
|
|
|
NULL)))
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2013-04-26 17:13:45 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
2013-04-26 17:13:45 +00:00
|
|
|
}
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
2013-04-26 17:13:45 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virJSONValueObjectRemoveKey(reply, "return", &array) <= 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-command-line-options reply was missing "
|
|
|
|
"return data"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
qemuMonitorSetOptions(mon, array);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((n = virJSONValueArraySize(array)) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-command-line-options reply data was not "
|
|
|
|
"an array"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-05-21 07:21:20 +00:00
|
|
|
for (i = 0; i < n; i++) {
|
2013-04-26 17:13:45 +00:00
|
|
|
virJSONValuePtr child = virJSONValueArrayGet(array, i);
|
|
|
|
const char *tmp;
|
|
|
|
|
|
|
|
if (!(tmp = virJSONValueObjectGetString(child, "option"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-command-line-options reply data was "
|
|
|
|
"missing 'option'"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (STREQ(tmp, option)) {
|
|
|
|
data = virJSONValueObjectGet(child, "parameters");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!data) {
|
|
|
|
/* Option not found; return 0 parameters rather than an error. */
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-06-17 11:41:16 +00:00
|
|
|
if (found)
|
|
|
|
*found = true;
|
|
|
|
|
2013-04-26 17:13:45 +00:00
|
|
|
if ((n = virJSONValueArraySize(data)) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-command-line-options parameter data was not "
|
|
|
|
"an array"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* null-terminated list */
|
2013-07-04 10:14:12 +00:00
|
|
|
if (VIR_ALLOC_N(paramlist, n + 1) < 0)
|
2013-04-26 17:13:45 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-05-21 07:21:20 +00:00
|
|
|
for (i = 0; i < n; i++) {
|
2013-04-26 17:13:45 +00:00
|
|
|
virJSONValuePtr child = virJSONValueArrayGet(data, i);
|
|
|
|
const char *tmp;
|
|
|
|
|
|
|
|
if (!(tmp = virJSONValueObjectGetString(child, "name"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-command-line-options parameter data was "
|
|
|
|
"missing 'name'"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VIR_STRDUP(paramlist[i], tmp) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = n;
|
|
|
|
*params = paramlist;
|
2016-05-16 11:47:26 +00:00
|
|
|
paramlist = NULL;
|
2013-04-26 17:13:45 +00:00
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2013-04-26 17:13:45 +00:00
|
|
|
/* If we failed before getting the JSON array of options, we (try)
|
|
|
|
* to cache an empty array to speed up the next failure. */
|
|
|
|
if (!qemuMonitorGetOptions(mon))
|
|
|
|
qemuMonitorSetOptions(mon, virJSONValueNewArray());
|
|
|
|
|
2016-11-25 08:18:35 +00:00
|
|
|
virStringListFree(paramlist);
|
2013-04-26 17:13:45 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Make non-KVM machines work with QMP probing
When there is no 'qemu-kvm' binary and the emulator used for a machine
is, for example, 'qemu-system-x86_64' that, by default, runs without
kvm enabled, libvirt still supplies '-no-kvm' option to this process,
even though it does not recognize such option (making the start of a
domain fail in that case).
This patch fixes building a command-line for QEMU machines without KVM
acceleration and is based on following assumptions:
- QEMU_CAPS_KVM flag means that QEMU is running KVM accelerated
machines by default (without explicitly requesting that using a
command-line option). It is the closest to the truth according to
the code with the only exception being the comment next to the
flag, so it's fixed in this patch as well.
- QEMU_CAPS_ENABLE_KVM flag means that QEMU is, by default, running
without KVM acceleration and in case we need KVM acceleration it
needs to be explicitly instructed to do so. This is partially
true for the past (this option essentially means that QEMU
recognizes the '-enable-kvm' option, even though it's almost the
same).
2012-10-31 07:31:49 +00:00
|
|
|
int qemuMonitorJSONGetKVMState(qemuMonitorPtr mon,
|
|
|
|
bool *enabled,
|
|
|
|
bool *present)
|
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
Make non-KVM machines work with QMP probing
When there is no 'qemu-kvm' binary and the emulator used for a machine
is, for example, 'qemu-system-x86_64' that, by default, runs without
kvm enabled, libvirt still supplies '-no-kvm' option to this process,
even though it does not recognize such option (making the start of a
domain fail in that case).
This patch fixes building a command-line for QEMU machines without KVM
acceleration and is based on following assumptions:
- QEMU_CAPS_KVM flag means that QEMU is running KVM accelerated
machines by default (without explicitly requesting that using a
command-line option). It is the closest to the truth according to
the code with the only exception being the comment next to the
flag, so it's fixed in this patch as well.
- QEMU_CAPS_ENABLE_KVM flag means that QEMU is, by default, running
without KVM acceleration and in case we need KVM acceleration it
needs to be explicitly instructed to do so. This is partially
true for the past (this option essentially means that QEMU
recognizes the '-enable-kvm' option, even though it's almost the
same).
2012-10-31 07:31:49 +00:00
|
|
|
virJSONValuePtr cmd = NULL;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
virJSONValuePtr data = NULL;
|
|
|
|
|
|
|
|
/* Safe defaults */
|
|
|
|
*enabled = *present = false;
|
|
|
|
|
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("query-kvm", NULL)))
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
Make non-KVM machines work with QMP probing
When there is no 'qemu-kvm' binary and the emulator used for a machine
is, for example, 'qemu-system-x86_64' that, by default, runs without
kvm enabled, libvirt still supplies '-no-kvm' option to this process,
even though it does not recognize such option (making the start of a
domain fail in that case).
This patch fixes building a command-line for QEMU machines without KVM
acceleration and is based on following assumptions:
- QEMU_CAPS_KVM flag means that QEMU is running KVM accelerated
machines by default (without explicitly requesting that using a
command-line option). It is the closest to the truth according to
the code with the only exception being the comment next to the
flag, so it's fixed in this patch as well.
- QEMU_CAPS_ENABLE_KVM flag means that QEMU is, by default, running
without KVM acceleration and in case we need KVM acceleration it
needs to be explicitly instructed to do so. This is partially
true for the past (this option essentially means that QEMU
recognizes the '-enable-kvm' option, even though it's almost the
same).
2012-10-31 07:31:49 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
Make non-KVM machines work with QMP probing
When there is no 'qemu-kvm' binary and the emulator used for a machine
is, for example, 'qemu-system-x86_64' that, by default, runs without
kvm enabled, libvirt still supplies '-no-kvm' option to this process,
even though it does not recognize such option (making the start of a
domain fail in that case).
This patch fixes building a command-line for QEMU machines without KVM
acceleration and is based on following assumptions:
- QEMU_CAPS_KVM flag means that QEMU is running KVM accelerated
machines by default (without explicitly requesting that using a
command-line option). It is the closest to the truth according to
the code with the only exception being the comment next to the
flag, so it's fixed in this patch as well.
- QEMU_CAPS_ENABLE_KVM flag means that QEMU is, by default, running
without KVM acceleration and in case we need KVM acceleration it
needs to be explicitly instructed to do so. This is partially
true for the past (this option essentially means that QEMU
recognizes the '-enable-kvm' option, even though it's almost the
same).
2012-10-31 07:31:49 +00:00
|
|
|
}
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
Make non-KVM machines work with QMP probing
When there is no 'qemu-kvm' binary and the emulator used for a machine
is, for example, 'qemu-system-x86_64' that, by default, runs without
kvm enabled, libvirt still supplies '-no-kvm' option to this process,
even though it does not recognize such option (making the start of a
domain fail in that case).
This patch fixes building a command-line for QEMU machines without KVM
acceleration and is based on following assumptions:
- QEMU_CAPS_KVM flag means that QEMU is running KVM accelerated
machines by default (without explicitly requesting that using a
command-line option). It is the closest to the truth according to
the code with the only exception being the comment next to the
flag, so it's fixed in this patch as well.
- QEMU_CAPS_ENABLE_KVM flag means that QEMU is, by default, running
without KVM acceleration and in case we need KVM acceleration it
needs to be explicitly instructed to do so. This is partially
true for the past (this option essentially means that QEMU
recognizes the '-enable-kvm' option, even though it's almost the
same).
2012-10-31 07:31:49 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-11-20 23:10:06 +00:00
|
|
|
data = virJSONValueObjectGetObject(reply, "return");
|
Make non-KVM machines work with QMP probing
When there is no 'qemu-kvm' binary and the emulator used for a machine
is, for example, 'qemu-system-x86_64' that, by default, runs without
kvm enabled, libvirt still supplies '-no-kvm' option to this process,
even though it does not recognize such option (making the start of a
domain fail in that case).
This patch fixes building a command-line for QEMU machines without KVM
acceleration and is based on following assumptions:
- QEMU_CAPS_KVM flag means that QEMU is running KVM accelerated
machines by default (without explicitly requesting that using a
command-line option). It is the closest to the truth according to
the code with the only exception being the comment next to the
flag, so it's fixed in this patch as well.
- QEMU_CAPS_ENABLE_KVM flag means that QEMU is, by default, running
without KVM acceleration and in case we need KVM acceleration it
needs to be explicitly instructed to do so. This is partially
true for the past (this option essentially means that QEMU
recognizes the '-enable-kvm' option, even though it's almost the
same).
2012-10-31 07:31:49 +00:00
|
|
|
|
|
|
|
if (virJSONValueObjectGetBoolean(data, "enabled", enabled) < 0 ||
|
|
|
|
virJSONValueObjectGetBoolean(data, "present", present) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-kvm replied unexpected data"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
Make non-KVM machines work with QMP probing
When there is no 'qemu-kvm' binary and the emulator used for a machine
is, for example, 'qemu-system-x86_64' that, by default, runs without
kvm enabled, libvirt still supplies '-no-kvm' option to this process,
even though it does not recognize such option (making the start of a
domain fail in that case).
This patch fixes building a command-line for QEMU machines without KVM
acceleration and is based on following assumptions:
- QEMU_CAPS_KVM flag means that QEMU is running KVM accelerated
machines by default (without explicitly requesting that using a
command-line option). It is the closest to the truth according to
the code with the only exception being the comment next to the
flag, so it's fixed in this patch as well.
- QEMU_CAPS_ENABLE_KVM flag means that QEMU is, by default, running
without KVM acceleration and in case we need KVM acceleration it
needs to be explicitly instructed to do so. This is partially
true for the past (this option essentially means that QEMU
recognizes the '-enable-kvm' option, even though it's almost the
same).
2012-10-31 07:31:49 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-22 09:48:41 +00:00
|
|
|
int qemuMonitorJSONGetObjectTypes(qemuMonitorPtr mon,
|
|
|
|
char ***types)
|
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2012-08-22 09:48:41 +00:00
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
virJSONValuePtr data;
|
|
|
|
char **typelist = NULL;
|
2015-10-08 08:17:42 +00:00
|
|
|
ssize_t n = 0;
|
2012-08-22 09:48:41 +00:00
|
|
|
size_t i;
|
|
|
|
|
|
|
|
*types = NULL;
|
|
|
|
|
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("qom-list-types", NULL)))
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
2012-08-22 09:48:41 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2012-08-22 09:48:41 +00:00
|
|
|
|
2016-11-20 23:10:06 +00:00
|
|
|
if (!(data = virJSONValueObjectGetArray(reply, "return")) ||
|
|
|
|
(n = virJSONValueArraySize(data)) < 0) {
|
2012-08-22 09:48:41 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("qom-list-types reply data was not an array"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-04-26 17:47:23 +00:00
|
|
|
/* null-terminated list */
|
2013-07-04 10:14:12 +00:00
|
|
|
if (VIR_ALLOC_N(typelist, n + 1) < 0)
|
2012-08-22 09:48:41 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-05-21 07:21:20 +00:00
|
|
|
for (i = 0; i < n; i++) {
|
2012-08-22 09:48:41 +00:00
|
|
|
virJSONValuePtr child = virJSONValueArrayGet(data, i);
|
|
|
|
const char *tmp;
|
|
|
|
|
|
|
|
if (!(tmp = virJSONValueObjectGetString(child, "name"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("qom-list-types reply data was missing 'name'"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-05-20 09:23:13 +00:00
|
|
|
if (VIR_STRDUP(typelist[i], tmp) < 0)
|
2012-08-22 09:48:41 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = n;
|
|
|
|
*types = typelist;
|
2016-05-16 11:47:26 +00:00
|
|
|
typelist = NULL;
|
2012-08-22 09:48:41 +00:00
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2016-11-25 08:18:35 +00:00
|
|
|
virStringListFree(typelist);
|
2012-08-22 09:48:41 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
2012-08-22 09:48:41 +00:00
|
|
|
|
|
|
|
|
2013-06-24 17:51:56 +00:00
|
|
|
int qemuMonitorJSONGetObjectListPaths(qemuMonitorPtr mon,
|
|
|
|
const char *path,
|
|
|
|
qemuMonitorJSONListPathPtr **paths)
|
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2013-06-24 17:51:56 +00:00
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
virJSONValuePtr data;
|
|
|
|
qemuMonitorJSONListPathPtr *pathlist = NULL;
|
2015-10-08 08:17:42 +00:00
|
|
|
ssize_t n = 0;
|
2013-06-24 17:51:56 +00:00
|
|
|
size_t i;
|
|
|
|
|
|
|
|
*paths = NULL;
|
|
|
|
|
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("qom-list",
|
|
|
|
"s:path", path,
|
|
|
|
NULL)))
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
2013-06-24 17:51:56 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2013-06-24 17:51:56 +00:00
|
|
|
|
2016-11-20 23:10:06 +00:00
|
|
|
if (!(data = virJSONValueObjectGetArray(reply, "return")) ||
|
|
|
|
(n = virJSONValueArraySize(data)) < 0) {
|
2013-06-24 17:51:56 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("qom-list reply data was not an array"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* null-terminated list */
|
|
|
|
if (VIR_ALLOC_N(pathlist, n + 1) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
virJSONValuePtr child = virJSONValueArrayGet(data, i);
|
|
|
|
const char *tmp;
|
|
|
|
qemuMonitorJSONListPathPtr info;
|
|
|
|
|
|
|
|
if (VIR_ALLOC(info) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
pathlist[i] = info;
|
|
|
|
|
|
|
|
if (!(tmp = virJSONValueObjectGetString(child, "name"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("qom-list reply data was missing 'name'"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VIR_STRDUP(info->name, tmp) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virJSONValueObjectHasKey(child, "type")) {
|
|
|
|
if (!(tmp = virJSONValueObjectGetString(child, "type"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("qom-list reply has malformed 'type' data"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (VIR_STRDUP(info->type, tmp) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = n;
|
|
|
|
*paths = pathlist;
|
2016-05-16 11:47:26 +00:00
|
|
|
pathlist = NULL;
|
2013-06-24 17:51:56 +00:00
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2016-05-16 11:47:26 +00:00
|
|
|
if (pathlist) {
|
2013-06-24 17:51:56 +00:00
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
qemuMonitorJSONListPathFree(pathlist[i]);
|
|
|
|
VIR_FREE(pathlist);
|
|
|
|
}
|
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void qemuMonitorJSONListPathFree(qemuMonitorJSONListPathPtr paths)
|
|
|
|
{
|
|
|
|
if (!paths)
|
|
|
|
return;
|
|
|
|
VIR_FREE(paths->name);
|
|
|
|
VIR_FREE(paths->type);
|
|
|
|
VIR_FREE(paths);
|
|
|
|
}
|
|
|
|
|
2013-07-03 18:15:07 +00:00
|
|
|
|
|
|
|
int qemuMonitorJSONGetObjectProperty(qemuMonitorPtr mon,
|
|
|
|
const char *path,
|
|
|
|
const char *property,
|
|
|
|
qemuMonitorJSONObjectPropertyPtr prop)
|
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2013-07-03 18:15:07 +00:00
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
virJSONValuePtr data;
|
|
|
|
const char *tmp;
|
|
|
|
|
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("qom-get",
|
|
|
|
"s:path", path,
|
|
|
|
"s:property", property,
|
|
|
|
NULL)))
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
2013-07-03 18:15:07 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2013-07-03 18:15:07 +00:00
|
|
|
|
2016-05-03 08:55:41 +00:00
|
|
|
data = virJSONValueObjectGet(reply, "return");
|
2013-07-03 18:15:07 +00:00
|
|
|
|
|
|
|
switch ((qemuMonitorJSONObjectPropertyType) prop->type) {
|
|
|
|
/* Simple cases of boolean, int, long, uint, ulong, double, and string
|
|
|
|
* will receive return value as part of {"return": xxx} statement
|
|
|
|
*/
|
|
|
|
case QEMU_MONITOR_OBJECT_PROPERTY_BOOLEAN:
|
|
|
|
ret = virJSONValueGetBoolean(data, &prop->val.b);
|
|
|
|
break;
|
|
|
|
case QEMU_MONITOR_OBJECT_PROPERTY_INT:
|
|
|
|
ret = virJSONValueGetNumberInt(data, &prop->val.iv);
|
|
|
|
break;
|
|
|
|
case QEMU_MONITOR_OBJECT_PROPERTY_LONG:
|
|
|
|
ret = virJSONValueGetNumberLong(data, &prop->val.l);
|
|
|
|
break;
|
|
|
|
case QEMU_MONITOR_OBJECT_PROPERTY_UINT:
|
|
|
|
ret = virJSONValueGetNumberUint(data, &prop->val.ui);
|
|
|
|
break;
|
|
|
|
case QEMU_MONITOR_OBJECT_PROPERTY_ULONG:
|
|
|
|
ret = virJSONValueGetNumberUlong(data, &prop->val.ul);
|
|
|
|
break;
|
|
|
|
case QEMU_MONITOR_OBJECT_PROPERTY_DOUBLE:
|
|
|
|
ret = virJSONValueGetNumberDouble(data, &prop->val.d);
|
|
|
|
break;
|
|
|
|
case QEMU_MONITOR_OBJECT_PROPERTY_STRING:
|
|
|
|
tmp = virJSONValueGetString(data);
|
|
|
|
if (tmp && VIR_STRDUP(prop->val.str, tmp) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
if (tmp)
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
case QEMU_MONITOR_OBJECT_PROPERTY_LAST:
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("qom-get invalid object property type %d"),
|
|
|
|
prop->type);
|
|
|
|
goto cleanup;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == -1) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("qom-get reply was missing return data"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2013-07-03 18:15:07 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-03 18:42:40 +00:00
|
|
|
#define MAKE_SET_CMD(STRING, VALUE) \
|
|
|
|
cmd = qemuMonitorJSONMakeCommand("qom-set", \
|
|
|
|
"s:path", path, \
|
|
|
|
"s:property", property, \
|
|
|
|
STRING, VALUE, \
|
|
|
|
NULL)
|
|
|
|
int qemuMonitorJSONSetObjectProperty(qemuMonitorPtr mon,
|
|
|
|
const char *path,
|
|
|
|
const char *property,
|
|
|
|
qemuMonitorJSONObjectPropertyPtr prop)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virJSONValuePtr cmd = NULL;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
|
|
|
|
switch ((qemuMonitorJSONObjectPropertyType) prop->type) {
|
|
|
|
/* Simple cases of boolean, int, long, uint, ulong, double, and string
|
|
|
|
* will receive return value as part of {"return": xxx} statement
|
|
|
|
*/
|
|
|
|
case QEMU_MONITOR_OBJECT_PROPERTY_BOOLEAN:
|
|
|
|
MAKE_SET_CMD("b:value", prop->val.b);
|
|
|
|
break;
|
|
|
|
case QEMU_MONITOR_OBJECT_PROPERTY_INT:
|
|
|
|
MAKE_SET_CMD("i:value", prop->val.iv);
|
|
|
|
break;
|
|
|
|
case QEMU_MONITOR_OBJECT_PROPERTY_LONG:
|
|
|
|
MAKE_SET_CMD("I:value", prop->val.l);
|
|
|
|
break;
|
|
|
|
case QEMU_MONITOR_OBJECT_PROPERTY_UINT:
|
|
|
|
MAKE_SET_CMD("u:value", prop->val.ui);
|
|
|
|
break;
|
|
|
|
case QEMU_MONITOR_OBJECT_PROPERTY_ULONG:
|
|
|
|
MAKE_SET_CMD("U:value", prop->val.ul);
|
|
|
|
break;
|
|
|
|
case QEMU_MONITOR_OBJECT_PROPERTY_DOUBLE:
|
|
|
|
MAKE_SET_CMD("d:value", prop->val.d);
|
|
|
|
break;
|
|
|
|
case QEMU_MONITOR_OBJECT_PROPERTY_STRING:
|
|
|
|
MAKE_SET_CMD("s:value", prop->val.str);
|
|
|
|
break;
|
|
|
|
case QEMU_MONITOR_OBJECT_PROPERTY_LAST:
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("qom-set invalid object property type %d"),
|
|
|
|
prop->type);
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
}
|
|
|
|
if (!cmd)
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2013-07-03 18:42:40 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2013-07-03 18:42:40 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#undef MAKE_SET_CMD
|
|
|
|
|
|
|
|
|
2012-08-22 09:48:41 +00:00
|
|
|
int qemuMonitorJSONGetObjectProps(qemuMonitorPtr mon,
|
|
|
|
const char *type,
|
|
|
|
char ***props)
|
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2012-08-22 09:48:41 +00:00
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
virJSONValuePtr data;
|
|
|
|
char **proplist = NULL;
|
2015-10-08 08:17:42 +00:00
|
|
|
ssize_t n = 0;
|
2012-08-22 09:48:41 +00:00
|
|
|
size_t i;
|
|
|
|
|
|
|
|
*props = NULL;
|
|
|
|
|
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("device-list-properties",
|
|
|
|
"s:typename", type,
|
|
|
|
NULL)))
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2012-08-22 09:48:41 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONHasError(reply, "DeviceNotFound")) {
|
|
|
|
ret = 0;
|
2012-08-22 09:48:41 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
2012-08-22 09:48:41 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-11-20 23:10:06 +00:00
|
|
|
if (!(data = virJSONValueObjectGetArray(reply, "return")) ||
|
|
|
|
(n = virJSONValueArraySize(data)) < 0) {
|
2012-08-22 09:48:41 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("device-list-properties reply data was not an array"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-04-26 17:47:23 +00:00
|
|
|
/* null-terminated list */
|
2013-07-04 10:14:12 +00:00
|
|
|
if (VIR_ALLOC_N(proplist, n + 1) < 0)
|
2012-08-22 09:48:41 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-05-21 07:21:20 +00:00
|
|
|
for (i = 0; i < n; i++) {
|
2012-08-22 09:48:41 +00:00
|
|
|
virJSONValuePtr child = virJSONValueArrayGet(data, i);
|
|
|
|
const char *tmp;
|
|
|
|
|
|
|
|
if (!(tmp = virJSONValueObjectGetString(child, "name"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("device-list-properties reply data was missing 'name'"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-05-20 09:23:13 +00:00
|
|
|
if (VIR_STRDUP(proplist[i], tmp) < 0)
|
2012-08-22 09:48:41 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = n;
|
|
|
|
*props = proplist;
|
2016-05-16 11:47:26 +00:00
|
|
|
proplist = NULL;
|
2012-08-22 09:48:41 +00:00
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2016-11-25 08:18:35 +00:00
|
|
|
virStringListFree(proplist);
|
2012-08-22 09:48:41 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
2012-08-22 09:48:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
char *
|
|
|
|
qemuMonitorJSONGetTargetArch(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
char *ret = NULL;
|
|
|
|
const char *arch;
|
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
virJSONValuePtr data;
|
|
|
|
|
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("query-target", NULL)))
|
|
|
|
return NULL;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2012-08-22 09:48:41 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
2012-08-22 09:48:41 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-11-20 23:10:06 +00:00
|
|
|
data = virJSONValueObjectGetObject(reply, "return");
|
2012-08-22 09:48:41 +00:00
|
|
|
|
|
|
|
if (!(arch = virJSONValueObjectGetString(data, "arch"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-target reply was missing arch data"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-05-20 09:23:13 +00:00
|
|
|
ignore_value(VIR_STRDUP(ret, arch));
|
2012-08-22 09:48:41 +00:00
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2012-08-22 09:48:41 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
2013-01-14 11:45:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
int
|
2014-09-11 12:11:54 +00:00
|
|
|
qemuMonitorJSONGetMigrationCapabilities(qemuMonitorPtr mon,
|
|
|
|
char ***capabilities)
|
2013-01-14 11:45:20 +00:00
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2013-01-14 11:45:20 +00:00
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
virJSONValuePtr caps;
|
2014-09-11 12:11:54 +00:00
|
|
|
char **list = NULL;
|
Convert 'int i' to 'size_t i' in src/qemu files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2015-10-08 08:17:42 +00:00
|
|
|
ssize_t n;
|
2014-09-11 12:11:54 +00:00
|
|
|
|
|
|
|
*capabilities = NULL;
|
2013-01-14 11:45:20 +00:00
|
|
|
|
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("query-migrate-capabilities",
|
|
|
|
NULL)))
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2013-01-14 11:45:20 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
2013-01-14 11:45:20 +00:00
|
|
|
}
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
2013-01-14 11:45:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
qemu: simplify json parsing
Rather than grabbing an arbitrary JSON value and then checking
if it has the right type, we might as well request the correct
type to begin with.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONIOProcessEvent)
(qemuMonitorJSONCommandWithFd, qemuMonitorJSONHandleGraphics)
(qemuMonitorJSONGetStatus, qemuMonitorJSONExtractCPUInfo)
(qemuMonitorJSONGetVirtType, qemuMonitorJSONGetBalloonInfo)
(qemuMonitorJSONGetMemoryStats)
(qemuMonitorJSONDevGetBlockExtent)
(qemuMonitorJSONGetOneBlockStatsInfo)
(qemuMonitorJSONGetAllBlockStatsInfo)
(qemuMonitorJSONBlockStatsUpdateCapacityOne)
(qemuMonitorJSONBlockStatsUpdateCapacity)
(qemuMonitorJSONGetBlockExtent)
(qemuMonitorJSONGetMigrationStatusReply)
(qemuMonitorJSONGetDumpGuestMemoryCapability)
(qemuMonitorJSONAddFd, qemuMonitorJSONQueryRxFilterParse)
(qemuMonitorJSONExtractChardevInfo)
(qemuMonitorJSONDiskNameLookupOne)
(qemuMonitorJSONDiskNameLookup)
(qemuMonitorJSONGetAllBlockJobInfo)
(qemuMonitorJSONBlockIoThrottleInfo, qemuMonitorJSONGetVersion)
(qemuMonitorJSONGetMachines, qemuMonitorJSONGetCPUDefinitions)
(qemuMonitorJSONGetCommands, qemuMonitorJSONGetEvents)
(qemuMonitorJSONGetKVMState, qemuMonitorJSONGetObjectTypes)
(qemuMonitorJSONGetObjectListPaths)
(qemuMonitorJSONGetObjectProps, qemuMonitorJSONGetTargetArch)
(qemuMonitorJSONGetMigrationCapabilities)
(qemuMonitorJSONGetStringArray, qemuMonitorJSONAttachCharDev)
(qemuMonitorJSONGetCPUx86Data, qemuMonitorJSONGetIOThreads)
(qemuMonitorJSONGetMemoryDeviceInfo): Use shorter idioms.
Signed-off-by: Eric Blake <eblake@redhat.com>
2015-06-20 19:40:21 +00:00
|
|
|
if (!(caps = virJSONValueObjectGetArray(reply, "return")) ||
|
2014-09-11 12:11:54 +00:00
|
|
|
(n = virJSONValueArraySize(caps)) < 0) {
|
2013-01-14 11:45:20 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("missing migration capabilities"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-09-11 12:11:54 +00:00
|
|
|
if (VIR_ALLOC_N(list, n + 1) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
2013-01-14 11:45:20 +00:00
|
|
|
virJSONValuePtr cap = virJSONValueArrayGet(caps, i);
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
if (!cap || cap->type != VIR_JSON_TYPE_OBJECT) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("missing entry in migration capabilities list"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(name = virJSONValueObjectGetString(cap, "capability"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("missing migration capability name"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-09-11 12:11:54 +00:00
|
|
|
if (VIR_STRDUP(list[i], name) < 1)
|
2013-01-14 11:45:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-09-11 12:11:54 +00:00
|
|
|
ret = n;
|
|
|
|
*capabilities = list;
|
2016-05-16 11:47:26 +00:00
|
|
|
list = NULL;
|
2013-01-14 11:45:20 +00:00
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2016-11-25 08:18:35 +00:00
|
|
|
virStringListFree(list);
|
2013-01-14 11:45:20 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
qemuMonitorJSONSetMigrationCapability(qemuMonitorPtr mon,
|
2014-11-10 13:46:26 +00:00
|
|
|
qemuMonitorMigrationCaps capability,
|
|
|
|
bool state)
|
2013-01-14 11:45:20 +00:00
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
virJSONValuePtr cmd = NULL;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
virJSONValuePtr cap = NULL;
|
|
|
|
virJSONValuePtr caps;
|
|
|
|
|
|
|
|
if (!(caps = virJSONValueNewArray()))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!(cap = virJSONValueNewObject()))
|
2013-07-04 10:14:12 +00:00
|
|
|
goto cleanup;
|
2013-01-14 11:45:20 +00:00
|
|
|
|
|
|
|
if (virJSONValueObjectAppendString(
|
|
|
|
cap, "capability",
|
|
|
|
qemuMonitorMigrationCapsTypeToString(capability)) < 0)
|
2013-07-04 10:14:12 +00:00
|
|
|
goto cleanup;
|
2013-01-14 11:45:20 +00:00
|
|
|
|
2014-11-10 13:46:26 +00:00
|
|
|
if (virJSONValueObjectAppendBoolean(cap, "state", state) < 0)
|
2013-07-04 10:14:12 +00:00
|
|
|
goto cleanup;
|
2013-01-14 11:45:20 +00:00
|
|
|
|
|
|
|
if (virJSONValueArrayAppend(caps, cap) < 0)
|
2013-07-04 10:14:12 +00:00
|
|
|
goto cleanup;
|
2013-01-14 11:45:20 +00:00
|
|
|
|
|
|
|
cap = NULL;
|
|
|
|
|
|
|
|
cmd = qemuMonitorJSONMakeCommand("migrate-set-capabilities",
|
|
|
|
"a:capabilities", caps,
|
|
|
|
NULL);
|
|
|
|
if (!cmd)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
caps = NULL;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
2013-01-14 11:45:20 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2013-01-14 11:45:20 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2013-01-14 11:45:20 +00:00
|
|
|
virJSONValueFree(caps);
|
|
|
|
virJSONValueFree(cap);
|
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
2012-11-22 15:08:52 +00:00
|
|
|
|
2016-03-08 17:24:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* qemuMonitorJSONGetGICCapabilities:
|
|
|
|
* @mon: QEMU JSON monitor
|
|
|
|
* @capabilities: where to store the GIC capabilities
|
|
|
|
*
|
|
|
|
* Use @mon to obtain information about the GIC capabilities for the
|
|
|
|
* corresponding QEMU binary, and store them in @capabilities.
|
|
|
|
*
|
|
|
|
* If the QEMU binary has no GIC capabilities, or if GIC capabilities could
|
|
|
|
* not be determined due to the lack of 'query-gic-capabilities' QMP command,
|
|
|
|
* a NULL pointer will be returned instead of an empty array.
|
|
|
|
*
|
|
|
|
* Returns: the number of GIC capabilities obtained from the monitor,
|
|
|
|
* <0 on failure
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
qemuMonitorJSONGetGICCapabilities(qemuMonitorPtr mon,
|
|
|
|
virGICCapability **capabilities)
|
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2016-03-08 17:24:18 +00:00
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
virJSONValuePtr caps;
|
|
|
|
virGICCapability *list = NULL;
|
|
|
|
size_t i;
|
|
|
|
ssize_t n;
|
|
|
|
|
|
|
|
*capabilities = NULL;
|
|
|
|
|
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("query-gic-capabilities",
|
|
|
|
NULL)))
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2016-03-08 17:24:18 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
/* If the 'query-gic-capabilities' QMP command was not available
|
|
|
|
* we simply successfully return zero capabilities.
|
|
|
|
* This is the case for QEMU <2.6 and all non-ARM architectures */
|
|
|
|
if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
2016-03-08 17:24:18 +00:00
|
|
|
}
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
2016-03-08 17:24:18 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!(caps = virJSONValueObjectGetArray(reply, "return")) ||
|
|
|
|
(n = virJSONValueArraySize(caps)) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("missing GIC capabilities"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the returned array was empty we have to return successfully */
|
|
|
|
if (n == 0) {
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VIR_ALLOC_N(list, n) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
virJSONValuePtr cap = virJSONValueArrayGet(caps, i);
|
|
|
|
int version;
|
|
|
|
bool kernel;
|
|
|
|
bool emulated;
|
|
|
|
|
|
|
|
if (!cap || cap->type != VIR_JSON_TYPE_OBJECT) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("missing entry in GIC capabilities list"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virJSONValueObjectGetNumberInt(cap, "version", &version) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("missing GIC version"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virJSONValueObjectGetBoolean(cap, "kernel", &kernel) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("missing in-kernel GIC information"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virJSONValueObjectGetBoolean(cap, "emulated", &emulated) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("missing emulated GIC information"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
list[i].version = version;
|
|
|
|
if (kernel)
|
|
|
|
list[i].implementation |= VIR_GIC_IMPLEMENTATION_KERNEL;
|
|
|
|
if (emulated)
|
|
|
|
list[i].implementation |= VIR_GIC_IMPLEMENTATION_EMULATED;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = n;
|
|
|
|
*capabilities = list;
|
2016-05-16 11:47:26 +00:00
|
|
|
list = NULL;
|
2016-03-08 17:24:18 +00:00
|
|
|
|
|
|
|
cleanup:
|
2016-05-16 11:47:26 +00:00
|
|
|
VIR_FREE(list);
|
2016-03-08 17:24:18 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-03-12 18:18:22 +00:00
|
|
|
static virJSONValuePtr
|
|
|
|
qemuMonitorJSONBuildInetSocketAddress(const char *host,
|
|
|
|
const char *port)
|
|
|
|
{
|
|
|
|
virJSONValuePtr addr = NULL;
|
|
|
|
virJSONValuePtr data = NULL;
|
|
|
|
|
2016-09-26 15:19:43 +00:00
|
|
|
if (virJSONValueObjectCreate(&data, "s:host", host,
|
|
|
|
"s:port", port, NULL) < 0)
|
|
|
|
return NULL;
|
2013-03-12 18:18:22 +00:00
|
|
|
|
2016-09-26 15:19:43 +00:00
|
|
|
if (virJSONValueObjectCreate(&addr, "s:type", "inet",
|
|
|
|
"a:data", data, NULL) < 0) {
|
|
|
|
virJSONValueFree(data);
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-03-12 18:18:22 +00:00
|
|
|
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
2013-03-12 18:48:04 +00:00
|
|
|
static virJSONValuePtr
|
|
|
|
qemuMonitorJSONBuildUnixSocketAddress(const char *path)
|
|
|
|
{
|
|
|
|
virJSONValuePtr addr = NULL;
|
|
|
|
virJSONValuePtr data = NULL;
|
|
|
|
|
2016-09-26 15:19:43 +00:00
|
|
|
if (virJSONValueObjectCreate(&data, "s:path", path, NULL) < 0)
|
|
|
|
return NULL;
|
2013-03-12 18:48:04 +00:00
|
|
|
|
2016-09-26 15:19:43 +00:00
|
|
|
if (virJSONValueObjectCreate(&addr, "s:type", "unix",
|
|
|
|
"a:data", data, NULL) < 0) {
|
|
|
|
virJSONValueFree(data);
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-03-12 18:48:04 +00:00
|
|
|
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
2012-11-22 15:08:52 +00:00
|
|
|
int
|
|
|
|
qemuMonitorJSONNBDServerStart(qemuMonitorPtr mon,
|
|
|
|
const char *host,
|
|
|
|
unsigned int port)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virJSONValuePtr cmd = NULL;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
virJSONValuePtr addr = NULL;
|
|
|
|
char *port_str = NULL;
|
|
|
|
|
2013-03-12 18:18:22 +00:00
|
|
|
if (virAsprintf(&port_str, "%u", port) < 0)
|
|
|
|
return ret;
|
2012-11-22 15:08:52 +00:00
|
|
|
|
2013-03-12 18:18:22 +00:00
|
|
|
if (!(addr = qemuMonitorJSONBuildInetSocketAddress(host, port_str)))
|
|
|
|
return ret;
|
2012-11-22 15:08:52 +00:00
|
|
|
|
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("nbd-server-start",
|
|
|
|
"a:addr", addr,
|
|
|
|
NULL)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* From now on, @addr is part of @cmd */
|
|
|
|
addr = NULL;
|
|
|
|
|
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2012-11-22 15:08:52 +00:00
|
|
|
VIR_FREE(port_str);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(addr);
|
|
|
|
return ret;
|
|
|
|
}
|
2012-11-22 15:17:13 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
qemuMonitorJSONNBDServerAdd(qemuMonitorPtr mon,
|
|
|
|
const char *deviceID,
|
|
|
|
bool writable)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
|
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("nbd-server-add",
|
|
|
|
"s:device", deviceID,
|
|
|
|
"b:writable", writable,
|
|
|
|
NULL)))
|
|
|
|
return ret;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2012-11-22 15:17:13 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2012-11-22 15:17:13 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2012-11-22 15:17:13 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
2013-01-31 13:47:49 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
qemuMonitorJSONNBDServerStop(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
|
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("nbd-server-stop",
|
|
|
|
NULL)))
|
|
|
|
return ret;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2013-01-31 13:47:49 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2013-01-31 13:47:49 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2013-01-31 13:47:49 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
2013-04-12 20:55:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
qemuMonitorJSONGetStringArray(qemuMonitorPtr mon, const char *qmpCmd,
|
|
|
|
char ***array)
|
|
|
|
{
|
2016-05-04 08:28:43 +00:00
|
|
|
int ret = -1;
|
2013-04-12 20:55:45 +00:00
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
virJSONValuePtr data;
|
|
|
|
char **list = NULL;
|
2015-10-08 08:17:42 +00:00
|
|
|
ssize_t n = 0;
|
2013-04-12 20:55:45 +00:00
|
|
|
size_t i;
|
|
|
|
|
|
|
|
*array = NULL;
|
|
|
|
|
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand(qmpCmd, NULL)))
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2013-04-16 11:05:21 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
2013-04-16 11:05:21 +00:00
|
|
|
}
|
2013-04-12 20:55:45 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
2013-04-12 20:55:45 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-11-20 23:10:06 +00:00
|
|
|
if (!(data = virJSONValueObjectGetArray(reply, "return")) ||
|
|
|
|
(n = virJSONValueArraySize(data)) < 0) {
|
2013-04-12 20:55:45 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("%s reply data was not an array"),
|
|
|
|
qmpCmd);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* null-terminated list */
|
2013-07-04 10:14:12 +00:00
|
|
|
if (VIR_ALLOC_N(list, n + 1) < 0)
|
2013-04-12 20:55:45 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-05-21 07:21:20 +00:00
|
|
|
for (i = 0; i < n; i++) {
|
2013-04-12 20:55:45 +00:00
|
|
|
virJSONValuePtr child = virJSONValueArrayGet(data, i);
|
|
|
|
const char *tmp;
|
|
|
|
|
|
|
|
if (!(tmp = virJSONValueGetString(child))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("%s array element does not contain data"),
|
|
|
|
qmpCmd);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2013-05-20 09:23:13 +00:00
|
|
|
if (VIR_STRDUP(list[i], tmp) < 0)
|
2013-04-12 20:55:45 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = n;
|
|
|
|
*array = list;
|
2016-05-16 11:47:26 +00:00
|
|
|
list = NULL;
|
2013-04-12 20:55:45 +00:00
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2016-11-25 08:18:35 +00:00
|
|
|
virStringListFree(list);
|
2013-04-12 20:55:45 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int qemuMonitorJSONGetTPMModels(qemuMonitorPtr mon,
|
|
|
|
char ***tpmmodels)
|
|
|
|
{
|
|
|
|
return qemuMonitorJSONGetStringArray(mon, "query-tpm-models", tpmmodels);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorJSONGetTPMTypes(qemuMonitorPtr mon,
|
|
|
|
char ***tpmtypes)
|
|
|
|
{
|
|
|
|
return qemuMonitorJSONGetStringArray(mon, "query-tpm-types", tpmtypes);
|
|
|
|
}
|
2013-03-12 18:48:04 +00:00
|
|
|
|
2017-09-13 00:33:40 +00:00
|
|
|
static int
|
|
|
|
qemuMonitorJSONBuildChrChardevReconnect(virJSONValuePtr object,
|
|
|
|
const virDomainChrSourceReconnectDef *def)
|
|
|
|
{
|
|
|
|
if (def->enabled != VIR_TRISTATE_BOOL_YES)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return virJSONValueObjectAppendNumberUint(object, "reconnect", def->timeout);
|
|
|
|
}
|
|
|
|
|
2013-03-12 18:48:04 +00:00
|
|
|
static virJSONValuePtr
|
|
|
|
qemuMonitorJSONAttachCharDevCommand(const char *chrID,
|
2013-10-08 17:07:53 +00:00
|
|
|
const virDomainChrSourceDef *chr)
|
2013-03-12 18:48:04 +00:00
|
|
|
{
|
2017-06-13 15:55:36 +00:00
|
|
|
virJSONValuePtr ret = NULL;
|
|
|
|
virJSONValuePtr backend = NULL;
|
2013-03-12 18:48:04 +00:00
|
|
|
virJSONValuePtr data = NULL;
|
|
|
|
virJSONValuePtr addr = NULL;
|
|
|
|
const char *backend_type = NULL;
|
2017-05-19 10:56:48 +00:00
|
|
|
const char *host;
|
|
|
|
const char *port;
|
2016-06-13 16:30:34 +00:00
|
|
|
char *tlsalias = NULL;
|
2013-03-12 18:48:04 +00:00
|
|
|
bool telnet;
|
|
|
|
|
|
|
|
if (!(backend = virJSONValueNewObject()) ||
|
|
|
|
!(data = virJSONValueNewObject())) {
|
2017-06-13 15:55:36 +00:00
|
|
|
goto cleanup;
|
2013-03-12 18:48:04 +00:00
|
|
|
}
|
|
|
|
|
2014-06-01 00:22:30 +00:00
|
|
|
switch ((virDomainChrType) chr->type) {
|
2013-03-12 18:48:04 +00:00
|
|
|
case VIR_DOMAIN_CHR_TYPE_NULL:
|
|
|
|
case VIR_DOMAIN_CHR_TYPE_VC:
|
|
|
|
backend_type = "null";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_DOMAIN_CHR_TYPE_PTY:
|
|
|
|
backend_type = "pty";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_DOMAIN_CHR_TYPE_FILE:
|
|
|
|
backend_type = "file";
|
|
|
|
if (virJSONValueObjectAppendString(data, "out", chr->data.file.path) < 0)
|
2017-06-13 15:55:36 +00:00
|
|
|
goto cleanup;
|
2013-03-12 18:48:04 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_DOMAIN_CHR_TYPE_DEV:
|
|
|
|
backend_type = STRPREFIX(chrID, "parallel") ? "parallel" : "serial";
|
|
|
|
if (virJSONValueObjectAppendString(data, "device",
|
|
|
|
chr->data.file.path) < 0)
|
2017-06-13 15:55:36 +00:00
|
|
|
goto cleanup;
|
2013-03-12 18:48:04 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_DOMAIN_CHR_TYPE_TCP:
|
|
|
|
backend_type = "socket";
|
|
|
|
addr = qemuMonitorJSONBuildInetSocketAddress(chr->data.tcp.host,
|
|
|
|
chr->data.tcp.service);
|
|
|
|
if (!addr ||
|
|
|
|
virJSONValueObjectAppend(data, "addr", addr) < 0)
|
2017-06-13 15:55:36 +00:00
|
|
|
goto cleanup;
|
2013-03-12 18:48:04 +00:00
|
|
|
addr = NULL;
|
|
|
|
|
|
|
|
telnet = chr->data.tcp.protocol == VIR_DOMAIN_CHR_TCP_PROTOCOL_TELNET;
|
|
|
|
|
|
|
|
if (virJSONValueObjectAppendBoolean(data, "wait", false) < 0 ||
|
|
|
|
virJSONValueObjectAppendBoolean(data, "telnet", telnet) < 0 ||
|
|
|
|
virJSONValueObjectAppendBoolean(data, "server", chr->data.tcp.listen) < 0)
|
2017-06-13 15:55:36 +00:00
|
|
|
goto cleanup;
|
2016-06-13 16:30:34 +00:00
|
|
|
if (chr->data.tcp.tlscreds) {
|
2017-02-16 19:59:06 +00:00
|
|
|
if (!(tlsalias = qemuAliasTLSObjFromSrcAlias(chrID)))
|
2017-06-13 15:55:36 +00:00
|
|
|
goto cleanup;
|
2016-06-13 16:30:34 +00:00
|
|
|
|
|
|
|
if (virJSONValueObjectAppendString(data, "tls-creds", tlsalias) < 0)
|
2017-06-13 15:55:36 +00:00
|
|
|
goto cleanup;
|
2016-06-13 16:30:34 +00:00
|
|
|
}
|
2017-09-13 00:33:40 +00:00
|
|
|
|
|
|
|
if (qemuMonitorJSONBuildChrChardevReconnect(data, &chr->data.tcp.reconnect) < 0)
|
|
|
|
goto cleanup;
|
2013-03-12 18:48:04 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_DOMAIN_CHR_TYPE_UDP:
|
2016-09-27 14:01:55 +00:00
|
|
|
backend_type = "udp";
|
2017-09-26 11:56:36 +00:00
|
|
|
host = chr->data.udp.connectHost;
|
|
|
|
if (!host)
|
|
|
|
host = "";
|
|
|
|
addr = qemuMonitorJSONBuildInetSocketAddress(host,
|
2013-03-12 18:48:04 +00:00
|
|
|
chr->data.udp.connectService);
|
|
|
|
if (!addr ||
|
2016-09-27 14:01:55 +00:00
|
|
|
virJSONValueObjectAppend(data, "remote", addr) < 0)
|
2017-06-13 15:55:36 +00:00
|
|
|
goto cleanup;
|
2016-09-27 14:01:55 +00:00
|
|
|
|
2017-05-19 10:56:48 +00:00
|
|
|
host = chr->data.udp.bindHost;
|
|
|
|
port = chr->data.udp.bindService;
|
|
|
|
if (host || port) {
|
|
|
|
if (!host)
|
|
|
|
host = "";
|
|
|
|
if (!port)
|
|
|
|
port = "";
|
|
|
|
addr = qemuMonitorJSONBuildInetSocketAddress(host, port);
|
2016-09-27 14:01:55 +00:00
|
|
|
if (!addr ||
|
|
|
|
virJSONValueObjectAppend(data, "local", addr) < 0)
|
2017-06-13 15:55:36 +00:00
|
|
|
goto cleanup;
|
2016-09-27 14:01:55 +00:00
|
|
|
}
|
2013-03-12 18:48:04 +00:00
|
|
|
addr = NULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_DOMAIN_CHR_TYPE_UNIX:
|
|
|
|
backend_type = "socket";
|
|
|
|
addr = qemuMonitorJSONBuildUnixSocketAddress(chr->data.nix.path);
|
|
|
|
|
|
|
|
if (!addr ||
|
|
|
|
virJSONValueObjectAppend(data, "addr", addr) < 0)
|
2017-06-13 15:55:36 +00:00
|
|
|
goto cleanup;
|
2013-03-12 18:48:04 +00:00
|
|
|
addr = NULL;
|
|
|
|
|
|
|
|
if (virJSONValueObjectAppendBoolean(data, "wait", false) < 0 ||
|
|
|
|
virJSONValueObjectAppendBoolean(data, "server", chr->data.nix.listen) < 0)
|
2017-06-13 15:55:36 +00:00
|
|
|
goto cleanup;
|
2017-09-13 00:33:40 +00:00
|
|
|
|
|
|
|
if (qemuMonitorJSONBuildChrChardevReconnect(data, &chr->data.nix.reconnect) < 0)
|
|
|
|
goto cleanup;
|
2013-03-12 18:48:04 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_DOMAIN_CHR_TYPE_SPICEVMC:
|
2016-06-08 13:51:27 +00:00
|
|
|
backend_type = "spicevmc";
|
|
|
|
|
|
|
|
if (virJSONValueObjectAppendString(data, "type",
|
|
|
|
virDomainChrSpicevmcTypeToString(chr->data.spicevmc)) < 0)
|
2017-06-13 15:55:36 +00:00
|
|
|
goto cleanup;
|
2016-06-08 13:51:27 +00:00
|
|
|
break;
|
|
|
|
|
2014-02-10 10:18:16 +00:00
|
|
|
case VIR_DOMAIN_CHR_TYPE_SPICEPORT:
|
2013-03-12 18:48:04 +00:00
|
|
|
case VIR_DOMAIN_CHR_TYPE_PIPE:
|
|
|
|
case VIR_DOMAIN_CHR_TYPE_STDIO:
|
2014-03-15 12:30:01 +00:00
|
|
|
case VIR_DOMAIN_CHR_TYPE_NMDM:
|
2013-03-12 18:48:04 +00:00
|
|
|
case VIR_DOMAIN_CHR_TYPE_LAST:
|
2014-11-10 15:52:49 +00:00
|
|
|
if (virDomainChrTypeToString(chr->type)) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
|
|
|
_("Hotplug unsupported for char device type '%s'"),
|
|
|
|
virDomainChrTypeToString(chr->type));
|
|
|
|
} else {
|
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
|
|
|
_("Hotplug unsupported for char device type '%d'"),
|
|
|
|
chr->type);
|
|
|
|
}
|
2017-06-13 15:55:36 +00:00
|
|
|
goto cleanup;
|
2013-03-12 18:48:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (virJSONValueObjectAppendString(backend, "type", backend_type) < 0 ||
|
|
|
|
virJSONValueObjectAppend(backend, "data", data) < 0)
|
2017-06-13 15:55:36 +00:00
|
|
|
goto cleanup;
|
2013-03-12 18:48:04 +00:00
|
|
|
data = NULL;
|
|
|
|
|
|
|
|
if (!(ret = qemuMonitorJSONMakeCommand("chardev-add",
|
|
|
|
"s:id", chrID,
|
|
|
|
"a:backend", backend,
|
|
|
|
NULL)))
|
2017-06-13 15:55:36 +00:00
|
|
|
goto cleanup;
|
|
|
|
backend = NULL;
|
2013-03-12 18:48:04 +00:00
|
|
|
|
2017-06-13 15:55:36 +00:00
|
|
|
cleanup:
|
2016-06-13 16:30:34 +00:00
|
|
|
VIR_FREE(tlsalias);
|
2013-03-12 18:48:04 +00:00
|
|
|
virJSONValueFree(addr);
|
|
|
|
virJSONValueFree(data);
|
|
|
|
virJSONValueFree(backend);
|
2017-06-13 15:55:36 +00:00
|
|
|
return ret;
|
2013-03-12 18:48:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
qemuMonitorJSONAttachCharDev(qemuMonitorPtr mon,
|
|
|
|
const char *chrID,
|
|
|
|
virDomainChrSourceDefPtr chr)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
|
|
|
|
if (!(cmd = qemuMonitorJSONAttachCharDevCommand(chrID, chr)))
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (chr->type == VIR_DOMAIN_CHR_TYPE_PTY) {
|
2016-11-20 23:10:06 +00:00
|
|
|
virJSONValuePtr data = virJSONValueObjectGetObject(reply, "return");
|
2013-03-12 18:48:04 +00:00
|
|
|
const char *path;
|
|
|
|
|
|
|
|
if (!(path = virJSONValueObjectGetString(data, "pty"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("chardev-add reply was missing pty path"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VIR_STRDUP(chr->data.file.path, path) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2013-03-12 18:48:04 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
2013-03-12 18:57:48 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
qemuMonitorJSONDetachCharDev(qemuMonitorPtr mon,
|
|
|
|
const char *chrID)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
|
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("chardev-remove",
|
|
|
|
"s:id", chrID,
|
|
|
|
NULL)))
|
|
|
|
return ret;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2013-03-12 18:57:48 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2013-03-12 18:57:48 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2013-03-12 18:57:48 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
2013-07-19 13:01:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
qemuMonitorJSONGetDeviceAliases(qemuMonitorPtr mon,
|
|
|
|
char ***aliases)
|
|
|
|
{
|
|
|
|
qemuMonitorJSONListPathPtr *paths = NULL;
|
|
|
|
char **alias;
|
|
|
|
int ret = -1;
|
|
|
|
size_t i;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
*aliases = NULL;
|
|
|
|
|
|
|
|
n = qemuMonitorJSONGetObjectListPaths(mon, "/machine/peripheral", &paths);
|
|
|
|
if (n < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (VIR_ALLOC_N(*aliases, n + 1) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
alias = *aliases;
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
if (STRPREFIX(paths[i]->type, "child<")) {
|
|
|
|
*alias = paths[i]->name;
|
|
|
|
paths[i]->name = NULL;
|
|
|
|
alias++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2013-07-19 13:01:38 +00:00
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
qemuMonitorJSONListPathFree(paths[i]);
|
|
|
|
VIR_FREE(paths);
|
|
|
|
return ret;
|
|
|
|
}
|
2013-07-22 11:07:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
qemuMonitorJSONParseCPUx86FeatureWord(virJSONValuePtr data,
|
|
|
|
virCPUx86CPUID *cpuid)
|
|
|
|
{
|
|
|
|
const char *reg;
|
2016-05-20 07:48:21 +00:00
|
|
|
unsigned long long eax_in;
|
2016-05-20 08:59:13 +00:00
|
|
|
unsigned long long ecx_in = 0;
|
2013-07-22 11:07:23 +00:00
|
|
|
unsigned long long features;
|
|
|
|
|
|
|
|
memset(cpuid, 0, sizeof(*cpuid));
|
|
|
|
|
|
|
|
if (!(reg = virJSONValueObjectGetString(data, "cpuid-register"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("missing cpuid-register in CPU data"));
|
|
|
|
return -1;
|
|
|
|
}
|
2016-05-20 07:48:21 +00:00
|
|
|
if (virJSONValueObjectGetNumberUlong(data, "cpuid-input-eax", &eax_in) < 0) {
|
2013-07-22 11:07:23 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("missing or invalid cpuid-input-eax in CPU data"));
|
|
|
|
return -1;
|
|
|
|
}
|
2016-05-20 08:59:13 +00:00
|
|
|
ignore_value(virJSONValueObjectGetNumberUlong(data, "cpuid-input-ecx",
|
|
|
|
&ecx_in));
|
2013-07-22 11:07:23 +00:00
|
|
|
if (virJSONValueObjectGetNumberUlong(data, "features", &features) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("missing or invalid features in CPU data"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-05-20 07:48:21 +00:00
|
|
|
cpuid->eax_in = eax_in;
|
2016-05-20 08:59:13 +00:00
|
|
|
cpuid->ecx_in = ecx_in;
|
2013-07-22 11:07:23 +00:00
|
|
|
if (STREQ(reg, "EAX")) {
|
|
|
|
cpuid->eax = features;
|
|
|
|
} else if (STREQ(reg, "EBX")) {
|
|
|
|
cpuid->ebx = features;
|
|
|
|
} else if (STREQ(reg, "ECX")) {
|
|
|
|
cpuid->ecx = features;
|
|
|
|
} else if (STREQ(reg, "EDX")) {
|
|
|
|
cpuid->edx = features;
|
|
|
|
} else {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("unknown CPU register '%s'"), reg);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-02 11:19:13 +00:00
|
|
|
static virCPUDataPtr
|
|
|
|
qemuMonitorJSONParseCPUx86Features(virJSONValuePtr data)
|
2016-06-03 14:59:59 +00:00
|
|
|
{
|
2017-02-02 11:19:13 +00:00
|
|
|
virCPUDataPtr cpudata = NULL;
|
2016-06-03 14:59:59 +00:00
|
|
|
virCPUx86CPUID cpuid;
|
|
|
|
size_t i;
|
|
|
|
ssize_t n;
|
|
|
|
|
2017-02-13 08:32:21 +00:00
|
|
|
if (!data || (n = virJSONValueArraySize(data)) < 0) {
|
2016-06-03 14:59:59 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("invalid array of CPUID features"));
|
2017-02-02 11:19:13 +00:00
|
|
|
goto error;
|
2016-06-03 14:59:59 +00:00
|
|
|
}
|
|
|
|
|
2017-02-02 11:19:13 +00:00
|
|
|
if (!(cpudata = virCPUDataNew(VIR_ARCH_X86_64)))
|
|
|
|
goto error;
|
|
|
|
|
2016-06-03 14:59:59 +00:00
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
if (qemuMonitorJSONParseCPUx86FeatureWord(virJSONValueArrayGet(data, i),
|
|
|
|
&cpuid) < 0 ||
|
2017-02-02 14:52:13 +00:00
|
|
|
virCPUx86DataAddCPUID(cpudata, &cpuid) < 0)
|
2017-02-02 11:19:13 +00:00
|
|
|
goto error;
|
2016-06-03 14:59:59 +00:00
|
|
|
}
|
|
|
|
|
2017-02-02 11:19:13 +00:00
|
|
|
return cpudata;
|
2016-06-03 14:59:59 +00:00
|
|
|
|
2017-02-02 11:19:13 +00:00
|
|
|
error:
|
2017-02-02 14:37:40 +00:00
|
|
|
virCPUDataFree(cpudata);
|
2017-02-02 11:19:13 +00:00
|
|
|
return NULL;
|
2016-06-03 14:59:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2013-07-22 11:07:23 +00:00
|
|
|
qemuMonitorJSONGetCPUx86Data(qemuMonitorPtr mon,
|
2013-11-11 13:47:08 +00:00
|
|
|
const char *property,
|
|
|
|
virCPUDataPtr *cpudata)
|
2013-07-22 11:07:23 +00:00
|
|
|
{
|
2013-11-11 15:34:53 +00:00
|
|
|
virJSONValuePtr cmd = NULL;
|
2013-07-22 11:07:23 +00:00
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
virJSONValuePtr data;
|
2013-11-11 13:47:08 +00:00
|
|
|
int ret = -1;
|
2013-07-22 11:07:23 +00:00
|
|
|
|
2016-06-03 14:59:59 +00:00
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("qom-get",
|
2013-11-11 15:34:53 +00:00
|
|
|
"s:path", QOM_CPU_PATH,
|
2016-06-03 14:59:59 +00:00
|
|
|
"s:property", property,
|
2013-11-11 15:34:53 +00:00
|
|
|
NULL)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply))
|
|
|
|
goto cleanup;
|
|
|
|
|
qemu: simplify json parsing
Rather than grabbing an arbitrary JSON value and then checking
if it has the right type, we might as well request the correct
type to begin with.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONIOProcessEvent)
(qemuMonitorJSONCommandWithFd, qemuMonitorJSONHandleGraphics)
(qemuMonitorJSONGetStatus, qemuMonitorJSONExtractCPUInfo)
(qemuMonitorJSONGetVirtType, qemuMonitorJSONGetBalloonInfo)
(qemuMonitorJSONGetMemoryStats)
(qemuMonitorJSONDevGetBlockExtent)
(qemuMonitorJSONGetOneBlockStatsInfo)
(qemuMonitorJSONGetAllBlockStatsInfo)
(qemuMonitorJSONBlockStatsUpdateCapacityOne)
(qemuMonitorJSONBlockStatsUpdateCapacity)
(qemuMonitorJSONGetBlockExtent)
(qemuMonitorJSONGetMigrationStatusReply)
(qemuMonitorJSONGetDumpGuestMemoryCapability)
(qemuMonitorJSONAddFd, qemuMonitorJSONQueryRxFilterParse)
(qemuMonitorJSONExtractChardevInfo)
(qemuMonitorJSONDiskNameLookupOne)
(qemuMonitorJSONDiskNameLookup)
(qemuMonitorJSONGetAllBlockJobInfo)
(qemuMonitorJSONBlockIoThrottleInfo, qemuMonitorJSONGetVersion)
(qemuMonitorJSONGetMachines, qemuMonitorJSONGetCPUDefinitions)
(qemuMonitorJSONGetCommands, qemuMonitorJSONGetEvents)
(qemuMonitorJSONGetKVMState, qemuMonitorJSONGetObjectTypes)
(qemuMonitorJSONGetObjectListPaths)
(qemuMonitorJSONGetObjectProps, qemuMonitorJSONGetTargetArch)
(qemuMonitorJSONGetMigrationCapabilities)
(qemuMonitorJSONGetStringArray, qemuMonitorJSONAttachCharDev)
(qemuMonitorJSONGetCPUx86Data, qemuMonitorJSONGetIOThreads)
(qemuMonitorJSONGetMemoryDeviceInfo): Use shorter idioms.
Signed-off-by: Eric Blake <eblake@redhat.com>
2015-06-20 19:40:21 +00:00
|
|
|
data = virJSONValueObjectGetArray(reply, "return");
|
2017-02-02 11:19:13 +00:00
|
|
|
if (!(*cpudata = qemuMonitorJSONParseCPUx86Features(data)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
2013-11-11 15:34:53 +00:00
|
|
|
|
2016-06-03 14:59:59 +00:00
|
|
|
cleanup:
|
2013-11-11 15:34:53 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
2016-06-03 14:59:59 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2013-11-11 15:34:53 +00:00
|
|
|
|
2016-06-03 14:59:59 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns -1 on error, 0 if QEMU does not support reporting CPUID features
|
|
|
|
* of a guest CPU, and 1 if the feature is supported.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
qemuMonitorJSONCheckCPUx86(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
virJSONValuePtr cmd = NULL;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
virJSONValuePtr data;
|
|
|
|
size_t i;
|
|
|
|
ssize_t n;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("qom-list",
|
2013-07-22 11:07:23 +00:00
|
|
|
"s:path", QOM_CPU_PATH,
|
|
|
|
NULL)))
|
2013-11-11 15:34:53 +00:00
|
|
|
goto cleanup;
|
2013-07-22 11:07:23 +00:00
|
|
|
|
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
2016-06-03 14:59:59 +00:00
|
|
|
if ((data = virJSONValueObjectGet(reply, "error"))) {
|
|
|
|
const char *klass = virJSONValueObjectGetString(data, "class");
|
|
|
|
if (STREQ_NULLABLE(klass, "DeviceNotFound") ||
|
|
|
|
STREQ_NULLABLE(klass, "CommandNotFound")) {
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-22 11:07:23 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply))
|
|
|
|
goto cleanup;
|
|
|
|
|
2017-02-13 08:32:21 +00:00
|
|
|
if (!(data = virJSONValueObjectGetArray(reply, "return")) ||
|
|
|
|
(n = virJSONValueArraySize(data)) < 0) {
|
2016-06-03 14:59:59 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("qom-list reply data was not an array"));
|
2013-07-22 11:07:23 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
2016-06-03 14:59:59 +00:00
|
|
|
virJSONValuePtr element = virJSONValueArrayGet(data, i);
|
|
|
|
if (STREQ_NULLABLE(virJSONValueObjectGetString(element, "name"),
|
|
|
|
"feature-words"))
|
|
|
|
break;
|
2013-07-22 11:07:23 +00:00
|
|
|
}
|
|
|
|
|
2016-06-03 14:59:59 +00:00
|
|
|
if (i == n)
|
|
|
|
ret = 0;
|
|
|
|
else
|
|
|
|
ret = 1;
|
2013-11-11 13:47:08 +00:00
|
|
|
|
2014-03-25 06:49:44 +00:00
|
|
|
cleanup:
|
2013-07-22 11:07:23 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* qemuMonitorJSONGetGuestCPU:
|
|
|
|
* @mon: Pointer to the monitor
|
|
|
|
* @arch: arch of the guest
|
2013-11-11 13:47:08 +00:00
|
|
|
* @data: returns the cpu data of the guest
|
2017-03-13 10:00:48 +00:00
|
|
|
* @disabled: returns the CPU data for features which were disabled by QEMU
|
2013-07-22 11:07:23 +00:00
|
|
|
*
|
|
|
|
* Retrieve the definition of the guest CPU from a running qemu instance.
|
|
|
|
*
|
2013-11-11 13:47:08 +00:00
|
|
|
* Returns 0 on success, -2 if guest doesn't support this feature,
|
|
|
|
* -1 on other errors.
|
2013-07-22 11:07:23 +00:00
|
|
|
*/
|
2013-11-11 13:47:08 +00:00
|
|
|
int
|
2013-07-22 11:07:23 +00:00
|
|
|
qemuMonitorJSONGetGuestCPU(qemuMonitorPtr mon,
|
2013-11-11 13:47:08 +00:00
|
|
|
virArch arch,
|
2017-03-13 10:00:48 +00:00
|
|
|
virCPUDataPtr *data,
|
|
|
|
virCPUDataPtr *disabled)
|
2013-07-22 11:07:23 +00:00
|
|
|
{
|
2017-03-13 10:00:48 +00:00
|
|
|
virCPUDataPtr cpuEnabled = NULL;
|
|
|
|
virCPUDataPtr cpuDisabled = NULL;
|
2016-06-03 14:59:59 +00:00
|
|
|
int rc;
|
|
|
|
|
2017-03-13 09:23:37 +00:00
|
|
|
if (ARCH_IS_X86(arch)) {
|
2016-06-03 14:59:59 +00:00
|
|
|
if ((rc = qemuMonitorJSONCheckCPUx86(mon)) < 0)
|
|
|
|
return -1;
|
|
|
|
else if (!rc)
|
|
|
|
return -2;
|
|
|
|
|
2017-03-13 10:00:48 +00:00
|
|
|
if (qemuMonitorJSONGetCPUx86Data(mon, "feature-words",
|
|
|
|
&cpuEnabled) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (disabled &&
|
|
|
|
qemuMonitorJSONGetCPUx86Data(mon, "filtered-features",
|
|
|
|
&cpuDisabled) < 0)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
*data = cpuEnabled;
|
|
|
|
if (disabled)
|
|
|
|
*disabled = cpuDisabled;
|
|
|
|
return 0;
|
2013-07-22 11:07:23 +00:00
|
|
|
}
|
2017-03-13 09:23:37 +00:00
|
|
|
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("CPU definition retrieval isn't supported for '%s'"),
|
|
|
|
virArchToString(arch));
|
|
|
|
return -1;
|
2017-03-13 10:00:48 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
virCPUDataFree(cpuEnabled);
|
|
|
|
virCPUDataFree(cpuDisabled);
|
|
|
|
return -1;
|
2013-07-22 11:07:23 +00:00
|
|
|
}
|
2014-08-13 12:28:24 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
qemuMonitorJSONRTCResetReinjection(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
|
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("rtc-reset-reinjection",
|
|
|
|
NULL)))
|
|
|
|
return ret;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2014-08-13 12:28:24 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2014-08-13 12:28:24 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
2014-08-13 12:28:24 +00:00
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
2014-08-29 20:23:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Query and parse returned array of data such as:
|
|
|
|
*
|
|
|
|
* {u'return': [{u'id': u'iothread1', u'thread-id': 30992}, \
|
|
|
|
* {u'id': u'iothread2', u'thread-id': 30993}]}
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
qemuMonitorJSONGetIOThreads(qemuMonitorPtr mon,
|
2015-03-25 15:59:37 +00:00
|
|
|
qemuMonitorIOThreadInfoPtr **iothreads)
|
2014-08-29 20:23:11 +00:00
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
virJSONValuePtr data;
|
2015-03-25 15:59:37 +00:00
|
|
|
qemuMonitorIOThreadInfoPtr *infolist = NULL;
|
2015-10-08 08:17:42 +00:00
|
|
|
ssize_t n = 0;
|
2014-08-29 20:23:11 +00:00
|
|
|
size_t i;
|
|
|
|
|
|
|
|
*iothreads = NULL;
|
|
|
|
|
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("query-iothreads", NULL)))
|
|
|
|
return ret;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
2014-08-29 20:23:11 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
2014-08-29 20:23:11 +00:00
|
|
|
|
2016-11-20 23:10:06 +00:00
|
|
|
if (!(data = virJSONValueObjectGetArray(reply, "return")) ||
|
|
|
|
(n = virJSONValueArraySize(data)) < 0) {
|
2014-08-29 20:23:11 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-iothreads reply data was not an array"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* null-terminated list */
|
|
|
|
if (VIR_ALLOC_N(infolist, n + 1) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
virJSONValuePtr child = virJSONValueArrayGet(data, i);
|
|
|
|
const char *tmp;
|
2015-03-25 15:59:37 +00:00
|
|
|
qemuMonitorIOThreadInfoPtr info;
|
2014-08-29 20:23:11 +00:00
|
|
|
|
|
|
|
if (!(tmp = virJSONValueObjectGetString(child, "id"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-iothreads reply data was missing 'id'"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2015-04-27 18:16:54 +00:00
|
|
|
if (!STRPREFIX(tmp, "iothread"))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (VIR_ALLOC(info) < 0)
|
2014-08-29 20:23:11 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2015-04-27 18:16:54 +00:00
|
|
|
infolist[i] = info;
|
|
|
|
|
|
|
|
if (virStrToLong_ui(tmp + strlen("iothread"),
|
|
|
|
NULL, 10, &info->iothread_id) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("failed to find iothread id for '%s'"),
|
|
|
|
tmp);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-08-29 20:23:11 +00:00
|
|
|
if (virJSONValueObjectGetNumberInt(child, "thread-id",
|
|
|
|
&info->thread_id) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-iothreads reply has malformed "
|
|
|
|
"'thread-id' data"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = n;
|
|
|
|
*iothreads = infolist;
|
2016-05-16 11:47:26 +00:00
|
|
|
infolist = NULL;
|
2014-08-29 20:23:11 +00:00
|
|
|
|
|
|
|
cleanup:
|
2016-05-16 11:47:26 +00:00
|
|
|
if (infolist) {
|
2014-08-29 20:23:11 +00:00
|
|
|
for (i = 0; i < n; i++)
|
2015-04-28 10:32:52 +00:00
|
|
|
VIR_FREE(infolist[i]);
|
2014-08-29 20:23:11 +00:00
|
|
|
VIR_FREE(infolist);
|
|
|
|
}
|
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
2015-01-19 12:21:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
qemuMonitorJSONGetMemoryDeviceInfo(qemuMonitorPtr mon,
|
|
|
|
virHashTablePtr info)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
virJSONValuePtr data = NULL;
|
|
|
|
qemuMonitorMemoryDeviceInfoPtr meminfo = NULL;
|
|
|
|
ssize_t n;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("query-memory-devices", NULL)))
|
|
|
|
return -1;
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
2015-01-19 12:21:09 +00:00
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
|
|
|
|
ret = -2;
|
|
|
|
goto cleanup;
|
2015-01-19 12:21:09 +00:00
|
|
|
}
|
|
|
|
|
2016-05-04 08:28:43 +00:00
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
2015-01-19 12:21:09 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2016-11-20 23:10:06 +00:00
|
|
|
if (!(data = virJSONValueObjectGetArray(reply, "return")) ||
|
|
|
|
(n = virJSONValueArraySize(data)) < 0) {
|
2015-01-19 12:21:09 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-memory-devices reply data was not an array"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
virJSONValuePtr elem = virJSONValueArrayGet(data, i);
|
|
|
|
const char *type;
|
|
|
|
|
|
|
|
if (!(type = virJSONValueObjectGetString(elem, "type"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-memory-devices reply data doesn't contain "
|
|
|
|
"enum type discriminator"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* dimm memory devices */
|
|
|
|
if (STREQ(type, "dimm")) {
|
|
|
|
virJSONValuePtr dimminfo;
|
|
|
|
const char *devalias;
|
|
|
|
|
qemu: simplify json parsing
Rather than grabbing an arbitrary JSON value and then checking
if it has the right type, we might as well request the correct
type to begin with.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONIOProcessEvent)
(qemuMonitorJSONCommandWithFd, qemuMonitorJSONHandleGraphics)
(qemuMonitorJSONGetStatus, qemuMonitorJSONExtractCPUInfo)
(qemuMonitorJSONGetVirtType, qemuMonitorJSONGetBalloonInfo)
(qemuMonitorJSONGetMemoryStats)
(qemuMonitorJSONDevGetBlockExtent)
(qemuMonitorJSONGetOneBlockStatsInfo)
(qemuMonitorJSONGetAllBlockStatsInfo)
(qemuMonitorJSONBlockStatsUpdateCapacityOne)
(qemuMonitorJSONBlockStatsUpdateCapacity)
(qemuMonitorJSONGetBlockExtent)
(qemuMonitorJSONGetMigrationStatusReply)
(qemuMonitorJSONGetDumpGuestMemoryCapability)
(qemuMonitorJSONAddFd, qemuMonitorJSONQueryRxFilterParse)
(qemuMonitorJSONExtractChardevInfo)
(qemuMonitorJSONDiskNameLookupOne)
(qemuMonitorJSONDiskNameLookup)
(qemuMonitorJSONGetAllBlockJobInfo)
(qemuMonitorJSONBlockIoThrottleInfo, qemuMonitorJSONGetVersion)
(qemuMonitorJSONGetMachines, qemuMonitorJSONGetCPUDefinitions)
(qemuMonitorJSONGetCommands, qemuMonitorJSONGetEvents)
(qemuMonitorJSONGetKVMState, qemuMonitorJSONGetObjectTypes)
(qemuMonitorJSONGetObjectListPaths)
(qemuMonitorJSONGetObjectProps, qemuMonitorJSONGetTargetArch)
(qemuMonitorJSONGetMigrationCapabilities)
(qemuMonitorJSONGetStringArray, qemuMonitorJSONAttachCharDev)
(qemuMonitorJSONGetCPUx86Data, qemuMonitorJSONGetIOThreads)
(qemuMonitorJSONGetMemoryDeviceInfo): Use shorter idioms.
Signed-off-by: Eric Blake <eblake@redhat.com>
2015-06-20 19:40:21 +00:00
|
|
|
if (!(dimminfo = virJSONValueObjectGetObject(elem, "data"))) {
|
2015-01-19 12:21:09 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-memory-devices reply data doesn't "
|
|
|
|
"contain enum data"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(devalias = virJSONValueObjectGetString(dimminfo, "id"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("dimm memory info data is missing 'id'"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VIR_ALLOC(meminfo) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virJSONValueObjectGetNumberUlong(dimminfo, "addr",
|
|
|
|
&meminfo->address) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("malformed/missing addr in dimm memory info"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virJSONValueObjectGetNumberUint(dimminfo, "slot",
|
|
|
|
&meminfo->slot) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("malformed/missing slot in dimm memory info"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virJSONValueObjectGetBoolean(dimminfo, "hotplugged",
|
|
|
|
&meminfo->hotplugged) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("malformed/missing hotplugged in dimm memory info"));
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virJSONValueObjectGetBoolean(dimminfo, "hotpluggable",
|
|
|
|
&meminfo->hotpluggable) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("malformed/missing hotpluggable in dimm memory info"));
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virHashAddEntry(info, devalias, meminfo) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
meminfo = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(meminfo);
|
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
2015-06-03 10:22:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2016-07-25 08:47:00 +00:00
|
|
|
* Search for a QOM object link by alias and name.
|
|
|
|
*
|
|
|
|
* For @alias and @name, this function tries to find QOM object named @name
|
|
|
|
* with id @alias in /machine/peripheral.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* 0 - Found
|
|
|
|
* -1 - Error - bail out
|
|
|
|
* -2 - Not found
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
qemuMonitorJSONFindObjectPathByAlias(qemuMonitorPtr mon,
|
|
|
|
const char *name,
|
|
|
|
const char *alias,
|
|
|
|
char **path)
|
|
|
|
{
|
|
|
|
qemuMonitorJSONListPathPtr *paths = NULL;
|
|
|
|
char *child = NULL;
|
|
|
|
int npaths;
|
|
|
|
int ret = -1;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
npaths = qemuMonitorJSONGetObjectListPaths(mon, "/machine/peripheral", &paths);
|
|
|
|
if (npaths < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (virAsprintf(&child, "child<%s>", name) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
for (i = 0; i < npaths; i++) {
|
|
|
|
if (STREQ(paths[i]->name, alias) && STREQ(paths[i]->type, child)) {
|
|
|
|
if (virAsprintf(path, "/machine/peripheral/%s", alias) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = -2;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
for (i = 0; i < npaths; i++)
|
|
|
|
qemuMonitorJSONListPathFree(paths[i]);
|
|
|
|
VIR_FREE(paths);
|
|
|
|
VIR_FREE(child);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Recursively search for a QOM object link only by name.
|
2015-06-03 10:22:53 +00:00
|
|
|
*
|
2015-06-03 10:40:08 +00:00
|
|
|
* For @name, this function finds the first QOM object
|
|
|
|
* named @name, recursively going through all the "child<>"
|
|
|
|
* entries, starting from @curpath.
|
2015-06-03 10:22:53 +00:00
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* 0 - Found
|
2015-06-03 10:40:08 +00:00
|
|
|
* -1 - Error - bail out
|
2015-06-03 10:22:53 +00:00
|
|
|
* -2 - Not found
|
|
|
|
*/
|
2015-06-03 10:40:08 +00:00
|
|
|
static int
|
2016-07-25 08:47:00 +00:00
|
|
|
qemuMonitorJSONFindObjectPathByName(qemuMonitorPtr mon,
|
|
|
|
const char *curpath,
|
|
|
|
const char *name,
|
|
|
|
char **path)
|
2015-06-03 10:22:53 +00:00
|
|
|
{
|
|
|
|
ssize_t i, npaths = 0;
|
|
|
|
int ret = -2;
|
|
|
|
char *nextpath = NULL;
|
|
|
|
qemuMonitorJSONListPathPtr *paths = NULL;
|
|
|
|
|
2015-06-03 10:40:08 +00:00
|
|
|
VIR_DEBUG("Searching for '%s' Object Path starting at '%s'", name, curpath);
|
2015-06-03 10:22:53 +00:00
|
|
|
|
|
|
|
npaths = qemuMonitorJSONGetObjectListPaths(mon, curpath, &paths);
|
|
|
|
if (npaths < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
for (i = 0; i < npaths && ret == -2; i++) {
|
|
|
|
|
2015-06-03 10:40:08 +00:00
|
|
|
if (STREQ_NULLABLE(paths[i]->type, name)) {
|
|
|
|
VIR_DEBUG("Path to '%s' is '%s/%s'", name, curpath, paths[i]->name);
|
2015-06-03 10:22:53 +00:00
|
|
|
ret = 0;
|
|
|
|
if (virAsprintf(path, "%s/%s", curpath, paths[i]->name) < 0) {
|
|
|
|
*path = NULL;
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Type entries that begin with "child<" are a branch that can be
|
|
|
|
* traversed looking for more entries
|
|
|
|
*/
|
|
|
|
if (paths[i]->type && STRPREFIX(paths[i]->type, "child<")) {
|
|
|
|
if (virAsprintf(&nextpath, "%s/%s", curpath, paths[i]->name) < 0) {
|
|
|
|
ret = -1;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2016-07-25 08:47:00 +00:00
|
|
|
ret = qemuMonitorJSONFindObjectPathByName(mon, nextpath, name, path);
|
2015-06-03 10:22:53 +00:00
|
|
|
VIR_FREE(nextpath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
for (i = 0; i < npaths; i++)
|
|
|
|
qemuMonitorJSONListPathFree(paths[i]);
|
|
|
|
VIR_FREE(paths);
|
|
|
|
VIR_FREE(nextpath);
|
2015-06-03 10:40:08 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Recursively search for a QOM object link.
|
|
|
|
*
|
2016-07-25 08:47:00 +00:00
|
|
|
* For @name and @alias, this function finds the first QOM object.
|
|
|
|
* The search is done at first by @alias and @name and if nothing was found
|
|
|
|
* it continues recursively only with @name.
|
2015-06-03 10:40:08 +00:00
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* 0 - Found
|
|
|
|
* -1 - Error
|
|
|
|
* -2 - Not found
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
qemuMonitorJSONFindLinkPath(qemuMonitorPtr mon,
|
|
|
|
const char *name,
|
2016-07-25 08:47:00 +00:00
|
|
|
const char *alias,
|
2015-06-03 10:40:08 +00:00
|
|
|
char **path)
|
|
|
|
{
|
|
|
|
char *linkname = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
2016-07-25 08:47:00 +00:00
|
|
|
if (alias) {
|
|
|
|
ret = qemuMonitorJSONFindObjectPathByAlias(mon, name, alias, path);
|
|
|
|
if (ret == -1 || ret == 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-06-03 10:40:08 +00:00
|
|
|
if (virAsprintf(&linkname, "link<%s>", name) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2016-07-25 08:47:00 +00:00
|
|
|
ret = qemuMonitorJSONFindObjectPathByName(mon, "/", linkname, path);
|
2015-06-03 10:40:08 +00:00
|
|
|
VIR_FREE(linkname);
|
2015-06-03 10:22:53 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2015-10-20 20:51:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
qemuMonitorJSONMigrateIncoming(qemuMonitorPtr mon,
|
|
|
|
const char *uri)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
|
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("migrate-incoming",
|
|
|
|
"s:uri", uri,
|
|
|
|
NULL)))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = qemuMonitorJSONCheckError(cmd, reply);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
2014-12-01 15:59:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
qemuMonitorJSONMigrateStartPostCopy(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
|
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("migrate-start-postcopy", NULL)))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = qemuMonitorJSONCheckError(cmd, reply);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
2016-04-29 14:01:47 +00:00
|
|
|
|
2017-10-20 07:17:09 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
qemuMonitorJSONMigrateContinue(qemuMonitorPtr mon,
|
|
|
|
qemuMonitorMigrationStatus status)
|
|
|
|
{
|
|
|
|
const char *statusStr = qemuMonitorMigrationStatusTypeToString(status);
|
|
|
|
int ret = -1;
|
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
|
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("migrate-continue",
|
|
|
|
"s:state", statusStr,
|
|
|
|
NULL)))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = qemuMonitorJSONCheckError(cmd, reply);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-29 14:01:47 +00:00
|
|
|
int
|
|
|
|
qemuMonitorJSONGetRTCTime(qemuMonitorPtr mon,
|
|
|
|
struct tm *tm)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
virJSONValuePtr data;
|
|
|
|
|
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("qom-get",
|
|
|
|
"s:path", "/machine",
|
|
|
|
"s:property", "rtc-time",
|
|
|
|
NULL)))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
data = virJSONValueObjectGet(reply, "return");
|
|
|
|
|
|
|
|
if (virJSONValueObjectGetNumberInt(data, "tm_year", &tm->tm_year) < 0 ||
|
|
|
|
virJSONValueObjectGetNumberInt(data, "tm_mon", &tm->tm_mon) < 0 ||
|
|
|
|
virJSONValueObjectGetNumberInt(data, "tm_mday", &tm->tm_mday) < 0 ||
|
|
|
|
virJSONValueObjectGetNumberInt(data, "tm_hour", &tm->tm_hour) < 0 ||
|
|
|
|
virJSONValueObjectGetNumberInt(data, "tm_min", &tm->tm_min) < 0 ||
|
|
|
|
virJSONValueObjectGetNumberInt(data, "tm_sec", &tm->tm_sec) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("qemu returned malformed time"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
2016-07-08 11:52:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
qemuMonitorQueryHotpluggableCpusFree(struct qemuMonitorQueryHotpluggableCpusEntry *entries,
|
|
|
|
size_t nentries)
|
|
|
|
{
|
|
|
|
struct qemuMonitorQueryHotpluggableCpusEntry *entry;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if (!entries)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < nentries; i++) {
|
|
|
|
entry = entries + i;
|
|
|
|
|
|
|
|
VIR_FREE(entry->type);
|
|
|
|
VIR_FREE(entry->qom_path);
|
|
|
|
VIR_FREE(entry->alias);
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_FREE(entries);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* [{
|
|
|
|
* "props": {
|
|
|
|
* "core-id": 0,
|
|
|
|
* "thread-id": 0,
|
|
|
|
* "socket-id": 0
|
|
|
|
* },
|
|
|
|
* "vcpus-count": 1,
|
|
|
|
* "qom-path": "/machine/unattached/device[0]",
|
|
|
|
* "type": "qemu64-x86_64-cpu"
|
|
|
|
* },
|
|
|
|
* {...}
|
|
|
|
* ]
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
qemuMonitorJSONProcessHotpluggableCpusReply(virJSONValuePtr vcpu,
|
|
|
|
struct qemuMonitorQueryHotpluggableCpusEntry *entry)
|
|
|
|
{
|
|
|
|
virJSONValuePtr props;
|
|
|
|
const char *tmp;
|
|
|
|
|
|
|
|
if (!(tmp = virJSONValueObjectGetString(vcpu, "type"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-hotpluggable-cpus didn't return device type"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VIR_STRDUP(entry->type, tmp) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (virJSONValueObjectGetNumberUint(vcpu, "vcpus-count", &entry->vcpus) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-hotpluggable-cpus didn't return vcpus-count"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(props = virJSONValueObjectGetObject(vcpu, "props"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-hotpluggable-cpus didn't return device props"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
entry->node_id = -1;
|
|
|
|
entry->socket_id = -1;
|
|
|
|
entry->core_id = -1;
|
|
|
|
entry->thread_id = -1;
|
|
|
|
|
|
|
|
ignore_value(virJSONValueObjectGetNumberInt(props, "node-id", &entry->node_id));
|
|
|
|
ignore_value(virJSONValueObjectGetNumberInt(props, "socket-id", &entry->socket_id));
|
|
|
|
ignore_value(virJSONValueObjectGetNumberInt(props, "core-id", &entry->core_id));
|
|
|
|
ignore_value(virJSONValueObjectGetNumberInt(props, "thread-id", &entry->thread_id));
|
|
|
|
|
|
|
|
if (entry->node_id == -1 && entry->socket_id == -1 &&
|
|
|
|
entry->core_id == -1 && entry->thread_id == -1) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-hotpluggable-cpus entry doesn't report "
|
|
|
|
"topology information"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* qom path is not present unless the vCPU is online */
|
|
|
|
if ((tmp = virJSONValueObjectGetString(vcpu, "qom-path"))) {
|
|
|
|
if (VIR_STRDUP(entry->qom_path, tmp) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* alias is the part after last slash having a "vcpu" prefix */
|
|
|
|
if ((tmp = strrchr(tmp, '/')) && STRPREFIX(tmp + 1, "vcpu")) {
|
|
|
|
if (VIR_STRDUP(entry->alias, tmp + 1) < 0)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
qemuMonitorQueryHotpluggableCpusEntrySort(const void *p1,
|
|
|
|
const void *p2)
|
|
|
|
{
|
|
|
|
const struct qemuMonitorQueryHotpluggableCpusEntry *a = p1;
|
|
|
|
const struct qemuMonitorQueryHotpluggableCpusEntry *b = p2;
|
|
|
|
|
|
|
|
if (a->socket_id != b->socket_id)
|
|
|
|
return a->socket_id - b->socket_id;
|
|
|
|
|
|
|
|
if (a->core_id != b->core_id)
|
|
|
|
return a->core_id - b->core_id;
|
|
|
|
|
|
|
|
return a->thread_id - b->thread_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
qemuMonitorJSONGetHotpluggableCPUs(qemuMonitorPtr mon,
|
|
|
|
struct qemuMonitorQueryHotpluggableCpusEntry **entries,
|
|
|
|
size_t *nentries)
|
|
|
|
{
|
|
|
|
struct qemuMonitorQueryHotpluggableCpusEntry *info = NULL;
|
|
|
|
ssize_t ninfo = 0;
|
|
|
|
int ret = -1;
|
|
|
|
size_t i;
|
|
|
|
virJSONValuePtr data;
|
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
virJSONValuePtr vcpu;
|
|
|
|
|
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("query-hotpluggable-cpus", NULL)))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
data = virJSONValueObjectGet(reply, "return");
|
|
|
|
|
|
|
|
if ((ninfo = virJSONValueArraySize(data)) < 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("query-hotpluggable-cpus reply is not an array"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VIR_ALLOC_N(info, ninfo) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
for (i = 0; i < ninfo; i++) {
|
|
|
|
vcpu = virJSONValueArrayGet(data, i);
|
|
|
|
|
|
|
|
if (qemuMonitorJSONProcessHotpluggableCpusReply(vcpu, info + i) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
qsort(info, ninfo, sizeof(*info), qemuMonitorQueryHotpluggableCpusEntrySort);
|
|
|
|
|
|
|
|
VIR_STEAL_PTR(*entries, info);
|
|
|
|
*nentries = ninfo;
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
qemuMonitorQueryHotpluggableCpusFree(info, ninfo);
|
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|
2016-10-17 12:20:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
qemuMonitorJSONFillQMPSchema(size_t pos ATTRIBUTE_UNUSED,
|
|
|
|
virJSONValuePtr item,
|
|
|
|
void *opaque)
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
virHashTablePtr schema = opaque;
|
|
|
|
|
|
|
|
if (!(name = virJSONValueObjectGetString(item, "name"))) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("malformed QMP schema"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virHashAddEntry(schema, name, item) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virHashTablePtr
|
|
|
|
qemuMonitorJSONQueryQMPSchema(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
virJSONValuePtr arr;
|
|
|
|
virHashTablePtr schema = NULL;
|
|
|
|
virHashTablePtr ret = NULL;
|
|
|
|
|
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("query-qmp-schema", NULL)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
arr = virJSONValueObjectGet(reply, "return");
|
|
|
|
|
2017-03-16 09:19:32 +00:00
|
|
|
if (!(schema = virHashCreate(512, virJSONValueHashFree)))
|
2016-10-17 12:20:42 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virJSONValueArrayForeachSteal(arr, qemuMonitorJSONFillQMPSchema,
|
|
|
|
schema) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
VIR_STEAL_PTR(ret, schema);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
virHashFree(schema);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2017-02-23 12:50:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
qemuMonitorJSONSetBlockThreshold(qemuMonitorPtr mon,
|
|
|
|
const char *nodename,
|
|
|
|
unsigned long long threshold)
|
|
|
|
{
|
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("block-set-write-threshold",
|
|
|
|
"s:node-name", nodename,
|
|
|
|
"U:write-threshold", threshold,
|
|
|
|
NULL)))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2017-02-24 13:59:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
virJSONValuePtr
|
|
|
|
qemuMonitorJSONQueryNamedBlockNodes(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
virJSONValuePtr ret = NULL;
|
|
|
|
|
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("query-named-block-nodes", NULL)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = virJSONValueObjectStealArray(reply, "return");
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2017-09-01 11:39:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
qemuMonitorJSONSetWatchdogAction(qemuMonitorPtr mon,
|
|
|
|
const char *action)
|
|
|
|
{
|
|
|
|
virJSONValuePtr cmd;
|
|
|
|
virJSONValuePtr reply = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (!(cmd = qemuMonitorJSONMakeCommand("watchdog-set-action",
|
|
|
|
"s:action", action,
|
|
|
|
NULL)))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (qemuMonitorJSONCheckError(cmd, reply) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virJSONValueFree(cmd);
|
|
|
|
virJSONValueFree(reply);
|
|
|
|
return ret;
|
|
|
|
}
|