2009-10-09 18:07:55 +00:00
|
|
|
/*
|
|
|
|
* qemu_monitor.c: interaction with QEMU monitor console
|
|
|
|
*
|
2013-01-31 00:18:44 +00:00
|
|
|
* Copyright (C) 2006-2013 Red Hat, Inc.
|
2009-10-09 18:07:55 +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-10-09 18:07:55 +00:00
|
|
|
*
|
|
|
|
* Author: Daniel P. Berrange <berrange@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <poll.h>
|
2013-05-30 20:51:58 +00:00
|
|
|
#include <sys/socket.h>
|
2009-10-09 18:07:55 +00:00
|
|
|
#include <sys/un.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#include "qemu_monitor.h"
|
2009-10-09 20:13:06 +00:00
|
|
|
#include "qemu_monitor_text.h"
|
2009-11-03 18:59:18 +00:00
|
|
|
#include "qemu_monitor_json.h"
|
2012-12-13 18:21:53 +00:00
|
|
|
#include "virerror.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2012-12-12 17:59:27 +00:00
|
|
|
#include "virlog.h"
|
2011-07-19 18:32:58 +00:00
|
|
|
#include "virfile.h"
|
2012-09-24 16:54:51 +00:00
|
|
|
#include "virprocess.h"
|
2012-07-11 13:35:47 +00:00
|
|
|
#include "virobject.h"
|
2013-04-03 10:36:23 +00:00
|
|
|
#include "virstring.h"
|
2009-10-09 18:07:55 +00:00
|
|
|
|
2012-04-02 17:24:29 +00:00
|
|
|
#ifdef WITH_DTRACE_PROBES
|
|
|
|
# include "libvirt_qemu_probes.h"
|
|
|
|
#endif
|
|
|
|
|
2009-10-09 18:07:55 +00:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_QEMU
|
|
|
|
|
2010-03-22 18:44:58 +00:00
|
|
|
#define DEBUG_IO 0
|
|
|
|
#define DEBUG_RAW_IO 0
|
2009-12-08 18:05:02 +00:00
|
|
|
|
2009-10-09 19:13:29 +00:00
|
|
|
struct _qemuMonitor {
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectLockable parent;
|
2012-07-11 13:35:47 +00:00
|
|
|
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
virCond notify;
|
|
|
|
|
2009-10-09 19:13:29 +00:00
|
|
|
int fd;
|
|
|
|
int watch;
|
|
|
|
int hasSendFD;
|
|
|
|
|
|
|
|
virDomainObjPtr vm;
|
|
|
|
|
2009-10-15 17:56:52 +00:00
|
|
|
qemuMonitorCallbacksPtr cb;
|
2013-07-25 17:26:15 +00:00
|
|
|
void *callbackOpaque;
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
|
|
|
|
/* If there's a command being processed this will be
|
|
|
|
* non-NULL */
|
|
|
|
qemuMonitorMessagePtr msg;
|
|
|
|
|
|
|
|
/* Buffer incoming data ready for Text/QMP monitor
|
|
|
|
* code to process & find message boundaries */
|
|
|
|
size_t bufferOffset;
|
|
|
|
size_t bufferLength;
|
|
|
|
char *buffer;
|
|
|
|
|
|
|
|
/* If anything went wrong, this will be fed back
|
|
|
|
* the next monitor msg */
|
2011-05-29 12:51:08 +00:00
|
|
|
virError lastError;
|
|
|
|
|
|
|
|
int nextSerial;
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
|
2013-04-26 02:32:41 +00:00
|
|
|
bool json;
|
|
|
|
bool waitGreeting;
|
2013-04-26 17:13:45 +00:00
|
|
|
|
|
|
|
/* cache of query-command-line-options results */
|
|
|
|
virJSONValuePtr options;
|
2013-06-27 15:00:31 +00:00
|
|
|
|
|
|
|
/* If found, path to the virtio memballoon driver */
|
|
|
|
char *balloonpath;
|
|
|
|
bool ballooninit;
|
2009-10-09 19:13:29 +00:00
|
|
|
};
|
|
|
|
|
2012-07-11 13:35:47 +00:00
|
|
|
static virClassPtr qemuMonitorClass;
|
|
|
|
static void qemuMonitorDispose(void *obj);
|
|
|
|
|
|
|
|
static int qemuMonitorOnceInit(void)
|
|
|
|
{
|
2013-01-09 21:00:32 +00:00
|
|
|
if (!(qemuMonitorClass = virClassNew(virClassForObjectLockable(),
|
2013-01-09 17:37:27 +00:00
|
|
|
"qemuMonitor",
|
|
|
|
sizeof(qemuMonitor),
|
|
|
|
qemuMonitorDispose)))
|
2012-07-11 13:35:47 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_ONCE_GLOBAL_INIT(qemuMonitor)
|
|
|
|
|
2009-11-26 13:29:29 +00:00
|
|
|
|
2009-11-26 13:37:11 +00:00
|
|
|
VIR_ENUM_IMPL(qemuMonitorMigrationStatus,
|
|
|
|
QEMU_MONITOR_MIGRATION_STATUS_LAST,
|
|
|
|
"inactive", "active", "completed", "failed", "cancelled")
|
|
|
|
|
2013-01-14 11:45:20 +00:00
|
|
|
VIR_ENUM_IMPL(qemuMonitorMigrationCaps,
|
|
|
|
QEMU_MONITOR_MIGRATION_CAPS_LAST,
|
|
|
|
"xbzrle")
|
|
|
|
|
2011-09-27 09:42:04 +00:00
|
|
|
VIR_ENUM_IMPL(qemuMonitorVMStatus,
|
|
|
|
QEMU_MONITOR_VM_STATUS_LAST,
|
|
|
|
"debug", "inmigrate", "internal-error", "io-error", "paused",
|
|
|
|
"postmigrate", "prelaunch", "finish-migrate", "restore-vm",
|
2013-06-07 10:23:34 +00:00
|
|
|
"running", "save-vm", "shutdown", "watchdog", "guest-panic")
|
2011-09-27 09:42:04 +00:00
|
|
|
|
2012-01-19 16:58:58 +00:00
|
|
|
typedef enum {
|
|
|
|
QEMU_MONITOR_BLOCK_IO_STATUS_OK,
|
|
|
|
QEMU_MONITOR_BLOCK_IO_STATUS_FAILED,
|
|
|
|
QEMU_MONITOR_BLOCK_IO_STATUS_NOSPACE,
|
|
|
|
|
|
|
|
QEMU_MONITOR_BLOCK_IO_STATUS_LAST
|
|
|
|
} qemuMonitorBlockIOStatus;
|
|
|
|
|
|
|
|
VIR_ENUM_DECL(qemuMonitorBlockIOStatus)
|
|
|
|
|
|
|
|
VIR_ENUM_IMPL(qemuMonitorBlockIOStatus,
|
|
|
|
QEMU_MONITOR_BLOCK_IO_STATUS_LAST,
|
|
|
|
"ok", "failed", "nospace")
|
|
|
|
|
qemu: Fix escape_monitor(escape_shell(command))
Suspending a VM which contains shell meta characters doesn't work with
libvirt-0.8.7:
/var/log/libvirt/qemu/andreas_231-ne\ doch\ nicht.log:
sh: -c: line 0: syntax error near unexpected token `doch'
sh: -c: line 0: `cat | { dd bs=4096 seek=1 if=/dev/null && dd bs=1048576; }
Although target="andreas_231-ne doch nicht" contains shell meta
characters (here: blanks), they are not properly escaped by
src/qemu/qemu_monitor_{json,text}.c#qemuMonitor{JSON,Text}MigrateToFile()
First, the filename needs to be properly escaped for the shell, than
this command line has to be properly escaped for qemu again.
For this to work, remove the old qemuMonitorEscapeArg() wrapper, rename
qemuMonitorEscape() to it removing the handling for shell=TRUE, and
implement a new qemuMonitorEscapeShell() returning strings using single
quotes.
Using double quotes or escaping special shell characters with backslashes
would also be possible, but the set of special characters heavily
depends on the concrete shell (dsh, bash, zsh) and its setting (history
expansion, interactive use, ...)
Signed-off-by: Philipp Hahn <hahn@univention.de>
2011-02-11 12:59:11 +00:00
|
|
|
char *qemuMonitorEscapeArg(const char *in)
|
2009-11-26 13:37:11 +00:00
|
|
|
{
|
|
|
|
int len = 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, j;
|
2009-11-26 13:37:11 +00:00
|
|
|
char *out;
|
|
|
|
|
|
|
|
/* To pass through the QEMU monitor, we need to use escape
|
|
|
|
sequences: \r, \n, \", \\
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (i = 0; in[i] != '\0'; i++) {
|
2012-10-17 09:23:12 +00:00
|
|
|
switch (in[i]) {
|
2009-11-26 13:37:11 +00:00
|
|
|
case '\r':
|
|
|
|
case '\n':
|
|
|
|
case '"':
|
|
|
|
case '\\':
|
|
|
|
len += 2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
len += 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VIR_ALLOC_N(out, len + 1) < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (i = j = 0; in[i] != '\0'; i++) {
|
2012-10-17 09:23:12 +00:00
|
|
|
switch (in[i]) {
|
2009-11-26 13:37:11 +00:00
|
|
|
case '\r':
|
|
|
|
out[j++] = '\\';
|
|
|
|
out[j++] = 'r';
|
|
|
|
break;
|
|
|
|
case '\n':
|
|
|
|
out[j++] = '\\';
|
|
|
|
out[j++] = 'n';
|
|
|
|
break;
|
|
|
|
case '"':
|
|
|
|
case '\\':
|
|
|
|
out[j++] = '\\';
|
|
|
|
out[j++] = in[i];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
out[j++] = in[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out[j] = '\0';
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2012-02-26 00:48:02 +00:00
|
|
|
char *qemuMonitorUnescapeArg(const char *in)
|
|
|
|
{
|
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, j;
|
2012-02-26 00:48:02 +00:00
|
|
|
char *out;
|
2012-06-14 08:29:36 +00:00
|
|
|
int len = strlen(in);
|
2012-02-26 00:48:02 +00:00
|
|
|
char next;
|
|
|
|
|
2012-06-14 08:29:36 +00:00
|
|
|
if (VIR_ALLOC_N(out, len + 1) < 0)
|
2012-02-26 00:48:02 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (i = j = 0; i < len; ++i) {
|
|
|
|
next = in[i];
|
|
|
|
if (in[i] == '\\') {
|
|
|
|
++i;
|
2012-10-17 09:23:12 +00:00
|
|
|
switch (in[i]) {
|
2012-02-26 00:48:02 +00:00
|
|
|
case 'r':
|
|
|
|
next = '\r';
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
next = '\n';
|
|
|
|
break;
|
|
|
|
case '"':
|
|
|
|
case '\\':
|
|
|
|
next = in[i];
|
|
|
|
break;
|
|
|
|
default:
|
2012-06-14 08:29:36 +00:00
|
|
|
/* invalid input (including trailing '\' at end of in) */
|
2012-02-26 00:48:02 +00:00
|
|
|
VIR_FREE(out);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out[j++] = next;
|
|
|
|
}
|
|
|
|
out[j] = '\0';
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2010-04-27 08:11:46 +00:00
|
|
|
#if DEBUG_RAW_IO
|
2010-03-09 18:22:22 +00:00
|
|
|
# include <c-ctype.h>
|
2009-12-08 18:05:02 +00:00
|
|
|
static char * qemuMonitorEscapeNonPrintable(const char *text)
|
|
|
|
{
|
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;
|
2009-12-08 18:05:02 +00:00
|
|
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
2013-05-21 07:21:20 +00:00
|
|
|
for (i = 0; text[i] != '\0'; i++) {
|
2009-12-08 18:05:02 +00:00
|
|
|
if (c_isprint(text[i]) ||
|
|
|
|
text[i] == '\n' ||
|
|
|
|
(text[i] == '\r' && text[i+1] == '\n'))
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf,"%c", text[i]);
|
2009-12-08 18:05:02 +00:00
|
|
|
else
|
2011-04-30 16:34:49 +00:00
|
|
|
virBufferAsprintf(&buf, "0x%02x", text[i]);
|
2009-12-08 18:05:02 +00:00
|
|
|
}
|
|
|
|
return virBufferContentAndReset(&buf);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-07-11 13:35:47 +00:00
|
|
|
static void qemuMonitorDispose(void *obj)
|
2009-10-09 18:07:55 +00:00
|
|
|
{
|
2012-07-11 13:35:47 +00:00
|
|
|
qemuMonitorPtr mon = obj;
|
|
|
|
|
2009-11-26 13:29:29 +00:00
|
|
|
VIR_DEBUG("mon=%p", mon);
|
2010-06-29 10:57:54 +00:00
|
|
|
if (mon->cb && mon->cb->destroy)
|
2013-07-25 17:26:15 +00:00
|
|
|
(mon->cb->destroy)(mon, mon->vm, mon->callbackOpaque);
|
2013-02-07 14:03:17 +00:00
|
|
|
virCondDestroy(&mon->notify);
|
2010-11-24 16:04:33 +00:00
|
|
|
VIR_FREE(mon->buffer);
|
2013-04-26 17:13:45 +00:00
|
|
|
virJSONValueFree(mon->options);
|
2013-06-27 15:00:31 +00:00
|
|
|
VIR_FREE(mon->balloonpath);
|
2009-10-09 18:07:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2011-06-13 19:59:58 +00:00
|
|
|
qemuMonitorOpenUnix(const char *monitor, pid_t cpid)
|
2009-10-09 18:07:55 +00:00
|
|
|
{
|
|
|
|
struct sockaddr_un addr;
|
|
|
|
int monfd;
|
|
|
|
int timeout = 3; /* In seconds */
|
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
|
|
|
int ret;
|
|
|
|
size_t i = 0;
|
2009-10-09 18:07:55 +00:00
|
|
|
|
|
|
|
if ((monfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno,
|
2009-10-09 18:07:55 +00:00
|
|
|
"%s", _("failed to create socket"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&addr, 0, sizeof(addr));
|
|
|
|
addr.sun_family = AF_UNIX;
|
|
|
|
if (virStrcpyStatic(addr.sun_path, monitor) == NULL) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Monitor path %s too big for destination"), monitor);
|
2009-10-09 18:07:55 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
ret = connect(monfd, (struct sockaddr *) &addr, sizeof(addr));
|
|
|
|
|
|
|
|
if (ret == 0)
|
|
|
|
break;
|
|
|
|
|
2011-06-13 19:59:58 +00:00
|
|
|
if ((errno == ENOENT || errno == ECONNREFUSED) &&
|
2012-11-26 14:17:12 +00:00
|
|
|
(!cpid || virProcessKill(cpid, 0) == 0)) {
|
2009-10-09 18:07:55 +00:00
|
|
|
/* ENOENT : Socket may not have shown up yet
|
|
|
|
* ECONNREFUSED : Leftover socket hasn't been removed yet */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno, "%s",
|
2009-10-09 18:07:55 +00:00
|
|
|
_("failed to connect to monitor socket"));
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
} while ((++i <= timeout*5) && (usleep(.2 * 1000000) <= 0));
|
|
|
|
|
|
|
|
if (ret != 0) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno, "%s",
|
2012-11-29 13:15:35 +00:00
|
|
|
_("monitor socket did not show up"));
|
2009-10-09 18:07:55 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2009-10-09 19:13:29 +00:00
|
|
|
return monfd;
|
2009-10-09 18:07:55 +00:00
|
|
|
|
|
|
|
error:
|
2010-11-09 20:48:48 +00:00
|
|
|
VIR_FORCE_CLOSE(monfd);
|
2009-10-09 18:07:55 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
qemuMonitorOpenPty(const char *monitor)
|
2009-10-09 18:07:55 +00:00
|
|
|
{
|
|
|
|
int monfd;
|
|
|
|
|
|
|
|
if ((monfd = open(monitor, O_RDWR)) < 0) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Unable to open monitor path %s"), monitor);
|
2009-10-09 18:07:55 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-10-09 19:13:29 +00:00
|
|
|
return monfd;
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
}
|
2009-10-09 18:07:55 +00:00
|
|
|
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
|
2011-05-29 12:51:08 +00:00
|
|
|
/* This method processes data that has been received
|
|
|
|
* from the monitor. Looking for async events and
|
|
|
|
* replies/errors.
|
|
|
|
*/
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
static int
|
|
|
|
qemuMonitorIOProcess(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
qemuMonitorMessagePtr msg = NULL;
|
|
|
|
|
|
|
|
/* See if there's a message & whether its ready for its reply
|
|
|
|
* ie whether its completed writing all its data */
|
|
|
|
if (mon->msg && mon->msg->txOffset == mon->msg->txLength)
|
|
|
|
msg = mon->msg;
|
|
|
|
|
2010-03-22 18:44:58 +00:00
|
|
|
#if DEBUG_IO
|
2010-03-26 16:00:50 +00:00
|
|
|
# if DEBUG_RAW_IO
|
2009-12-08 18:05:02 +00:00
|
|
|
char *str1 = qemuMonitorEscapeNonPrintable(msg ? msg->txBuffer : "");
|
|
|
|
char *str2 = qemuMonitorEscapeNonPrintable(mon->buffer);
|
2010-05-20 06:15:46 +00:00
|
|
|
VIR_ERROR(_("Process %d %p %p [[[[%s]]][[[%s]]]"), (int)mon->bufferOffset, mon->msg, msg, str1, str2);
|
2009-12-08 18:05:02 +00:00
|
|
|
VIR_FREE(str1);
|
|
|
|
VIR_FREE(str2);
|
2010-03-26 16:00:50 +00:00
|
|
|
# else
|
2009-11-11 10:30:01 +00:00
|
|
|
VIR_DEBUG("Process %d", (int)mon->bufferOffset);
|
2010-03-26 16:00:50 +00:00
|
|
|
# endif
|
2010-03-22 18:44:58 +00:00
|
|
|
#endif
|
|
|
|
|
2011-10-24 14:31:37 +00:00
|
|
|
PROBE(QEMU_MONITOR_IO_PROCESS,
|
|
|
|
"mon=%p buf=%s len=%zu", mon, mon->buffer, mon->bufferOffset);
|
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
|
|
|
len = qemuMonitorJSONIOProcess(mon,
|
|
|
|
mon->buffer, mon->bufferOffset,
|
|
|
|
msg);
|
|
|
|
else
|
|
|
|
len = qemuMonitorTextIOProcess(mon,
|
|
|
|
mon->buffer, mon->bufferOffset,
|
|
|
|
msg);
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
|
2011-05-29 12:51:08 +00:00
|
|
|
if (len < 0)
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
return -1;
|
|
|
|
|
2013-04-26 02:32:41 +00:00
|
|
|
if (len && mon->waitGreeting)
|
|
|
|
mon->waitGreeting = false;
|
2012-09-06 15:14:25 +00:00
|
|
|
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
if (len < mon->bufferOffset) {
|
|
|
|
memmove(mon->buffer, mon->buffer + len, mon->bufferOffset - len);
|
|
|
|
mon->bufferOffset -= len;
|
|
|
|
} else {
|
|
|
|
VIR_FREE(mon->buffer);
|
|
|
|
mon->bufferOffset = mon->bufferLength = 0;
|
|
|
|
}
|
2010-03-22 18:44:58 +00:00
|
|
|
#if DEBUG_IO
|
2009-11-11 10:30:01 +00:00
|
|
|
VIR_DEBUG("Process done %d used %d", (int)mon->bufferOffset, len);
|
2010-03-22 18:44:58 +00:00
|
|
|
#endif
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
if (msg && msg->finished)
|
|
|
|
virCondBroadcast(&mon->notify);
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-17 15:19:13 +00:00
|
|
|
/* Call this function while holding the monitor lock. */
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
static int
|
|
|
|
qemuMonitorIOWriteWithFD(qemuMonitorPtr mon,
|
|
|
|
const char *data,
|
|
|
|
size_t len,
|
|
|
|
int fd)
|
|
|
|
{
|
|
|
|
struct msghdr msg;
|
|
|
|
struct iovec iov[1];
|
|
|
|
int ret;
|
|
|
|
char control[CMSG_SPACE(sizeof(int))];
|
|
|
|
struct cmsghdr *cmsg;
|
|
|
|
|
|
|
|
memset(&msg, 0, sizeof(msg));
|
2011-06-30 14:04:23 +00:00
|
|
|
memset(control, 0, sizeof(control));
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
|
|
|
|
iov[0].iov_base = (void *)data;
|
|
|
|
iov[0].iov_len = len;
|
|
|
|
|
|
|
|
msg.msg_iov = iov;
|
|
|
|
msg.msg_iovlen = 1;
|
|
|
|
|
|
|
|
msg.msg_control = control;
|
|
|
|
msg.msg_controllen = sizeof(control);
|
|
|
|
|
|
|
|
cmsg = CMSG_FIRSTHDR(&msg);
|
2010-05-05 17:14:54 +00:00
|
|
|
/* Some static analyzers, like clang 2.6-0.6.pre2, fail to see
|
|
|
|
that our use of CMSG_FIRSTHDR will not return NULL. */
|
|
|
|
sa_assert(cmsg);
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
cmsg->cmsg_len = CMSG_LEN(sizeof(int));
|
|
|
|
cmsg->cmsg_level = SOL_SOCKET;
|
|
|
|
cmsg->cmsg_type = SCM_RIGHTS;
|
|
|
|
memcpy(CMSG_DATA(cmsg), &fd, sizeof(int));
|
|
|
|
|
|
|
|
do {
|
|
|
|
ret = sendmsg(mon->fd, &msg, 0);
|
|
|
|
} while (ret < 0 && errno == EINTR);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-11-17 15:19:13 +00:00
|
|
|
/*
|
|
|
|
* Called when the monitor is able to write data
|
|
|
|
* Call this function while holding the monitor lock.
|
|
|
|
*/
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
static int
|
|
|
|
qemuMonitorIOWrite(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
int done;
|
|
|
|
|
|
|
|
/* If no active message, or fully transmitted, the no-op */
|
|
|
|
if (!mon->msg || mon->msg->txOffset == mon->msg->txLength)
|
|
|
|
return 0;
|
|
|
|
|
2011-05-29 12:51:08 +00:00
|
|
|
if (mon->msg->txFD != -1 && !mon->hasSendFD) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Monitor does not support sending of file descriptors"));
|
2011-05-29 12:51:08 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
if (mon->msg->txFD == -1)
|
|
|
|
done = write(mon->fd,
|
|
|
|
mon->msg->txBuffer + mon->msg->txOffset,
|
|
|
|
mon->msg->txLength - mon->msg->txOffset);
|
|
|
|
else
|
|
|
|
done = qemuMonitorIOWriteWithFD(mon,
|
|
|
|
mon->msg->txBuffer + mon->msg->txOffset,
|
|
|
|
mon->msg->txLength - mon->msg->txOffset,
|
|
|
|
mon->msg->txFD);
|
|
|
|
|
2011-10-24 14:31:37 +00:00
|
|
|
PROBE(QEMU_MONITOR_IO_WRITE,
|
|
|
|
"mon=%p buf=%s len=%d ret=%d errno=%d",
|
|
|
|
mon,
|
|
|
|
mon->msg->txBuffer + mon->msg->txOffset,
|
|
|
|
mon->msg->txLength - mon->msg->txOffset,
|
|
|
|
done, errno);
|
|
|
|
|
|
|
|
if (mon->msg->txFD != -1)
|
|
|
|
PROBE(QEMU_MONITOR_IO_SEND_FD,
|
|
|
|
"mon=%p fd=%d ret=%d errno=%d",
|
|
|
|
mon, mon->msg->txFD, done, errno);
|
|
|
|
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
if (done < 0) {
|
|
|
|
if (errno == EAGAIN)
|
|
|
|
return 0;
|
|
|
|
|
2011-05-29 12:51:08 +00:00
|
|
|
virReportSystemError(errno, "%s",
|
|
|
|
_("Unable to write to monitor"));
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
mon->msg->txOffset += done;
|
|
|
|
return done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called when the monitor has incoming data to read
|
2010-11-17 15:19:13 +00:00
|
|
|
* Call this function while holding the monitor lock.
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
*
|
|
|
|
* Returns -1 on error, or number of bytes read
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
qemuMonitorIORead(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
size_t avail = mon->bufferLength - mon->bufferOffset;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (avail < 1024) {
|
|
|
|
if (VIR_REALLOC_N(mon->buffer,
|
2013-07-04 10:14:12 +00:00
|
|
|
mon->bufferLength + 1024) < 0)
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
return -1;
|
|
|
|
mon->bufferLength += 1024;
|
|
|
|
avail += 1024;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read as much as we can get into our buffer,
|
|
|
|
until we block on EAGAIN, or hit EOF */
|
|
|
|
while (avail > 1) {
|
|
|
|
int got;
|
|
|
|
got = read(mon->fd,
|
|
|
|
mon->buffer + mon->bufferOffset,
|
|
|
|
avail - 1);
|
|
|
|
if (got < 0) {
|
|
|
|
if (errno == EAGAIN)
|
|
|
|
break;
|
2011-05-29 12:51:08 +00:00
|
|
|
virReportSystemError(errno, "%s",
|
|
|
|
_("Unable to read from monitor"));
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
ret = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (got == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
ret += got;
|
|
|
|
avail -= got;
|
|
|
|
mon->bufferOffset += got;
|
|
|
|
mon->buffer[mon->bufferOffset] = '\0';
|
|
|
|
}
|
|
|
|
|
2010-03-22 18:44:58 +00:00
|
|
|
#if DEBUG_IO
|
2009-11-11 10:30:01 +00:00
|
|
|
VIR_DEBUG("Now read %d bytes of data", (int)mon->bufferOffset);
|
2010-03-22 18:44:58 +00:00
|
|
|
#endif
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void qemuMonitorUpdateWatch(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
int events =
|
|
|
|
VIR_EVENT_HANDLE_HANGUP |
|
|
|
|
VIR_EVENT_HANDLE_ERROR;
|
|
|
|
|
2012-09-28 14:27:39 +00:00
|
|
|
if (!mon->watch)
|
|
|
|
return;
|
|
|
|
|
2011-05-29 12:51:08 +00:00
|
|
|
if (mon->lastError.code == VIR_ERR_OK) {
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
events |= VIR_EVENT_HANDLE_READABLE;
|
|
|
|
|
2012-09-06 15:14:25 +00:00
|
|
|
if ((mon->msg && mon->msg->txOffset < mon->msg->txLength) &&
|
2013-04-26 02:32:41 +00:00
|
|
|
!mon->waitGreeting)
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
events |= VIR_EVENT_HANDLE_WRITABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
virEventUpdateHandle(mon->watch, events);
|
2009-10-09 18:07:55 +00:00
|
|
|
}
|
|
|
|
|
2009-10-09 19:13:29 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
qemuMonitorIO(int watch, int fd, int events, void *opaque) {
|
|
|
|
qemuMonitorPtr mon = opaque;
|
2011-05-29 12:37:29 +00:00
|
|
|
bool error = false;
|
|
|
|
bool eof = false;
|
2009-10-09 19:13:29 +00:00
|
|
|
|
2012-07-11 13:35:47 +00:00
|
|
|
virObjectRef(mon);
|
|
|
|
|
2010-11-17 15:19:13 +00:00
|
|
|
/* lock access to the monitor and protect fd */
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectLock(mon);
|
2010-03-22 18:44:58 +00:00
|
|
|
#if DEBUG_IO
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
VIR_DEBUG("Monitor %p I/O on watch %d fd %d events %d", mon, watch, fd, events);
|
2010-03-22 18:44:58 +00:00
|
|
|
#endif
|
2012-09-28 14:27:39 +00:00
|
|
|
if (mon->fd == -1 || mon->watch == 0) {
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(mon);
|
2012-09-28 14:27:39 +00:00
|
|
|
virObjectUnref(mon);
|
|
|
|
return;
|
|
|
|
}
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
|
2009-10-09 19:13:29 +00:00
|
|
|
if (mon->fd != fd || mon->watch != watch) {
|
2011-06-02 10:50:03 +00:00
|
|
|
if (events & (VIR_EVENT_HANDLE_HANGUP | VIR_EVENT_HANDLE_ERROR))
|
2011-05-29 12:51:08 +00:00
|
|
|
eof = true;
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("event from unexpected fd %d!=%d / watch %d!=%d"),
|
|
|
|
mon->fd, fd, mon->watch, watch);
|
2011-05-29 12:51:08 +00:00
|
|
|
error = true;
|
|
|
|
} else if (mon->lastError.code != VIR_ERR_OK) {
|
2011-06-02 10:50:03 +00:00
|
|
|
if (events & (VIR_EVENT_HANDLE_HANGUP | VIR_EVENT_HANDLE_ERROR))
|
2011-05-29 12:51:08 +00:00
|
|
|
eof = true;
|
2011-05-29 12:37:29 +00:00
|
|
|
error = true;
|
2009-10-09 19:13:29 +00:00
|
|
|
} else {
|
2011-05-29 12:51:08 +00:00
|
|
|
if (events & VIR_EVENT_HANDLE_WRITABLE) {
|
|
|
|
if (qemuMonitorIOWrite(mon) < 0)
|
|
|
|
error = true;
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
events &= ~VIR_EVENT_HANDLE_WRITABLE;
|
|
|
|
}
|
2011-05-29 12:51:08 +00:00
|
|
|
|
|
|
|
if (!error &&
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
events & VIR_EVENT_HANDLE_READABLE) {
|
|
|
|
int got = qemuMonitorIORead(mon);
|
2011-05-29 12:51:08 +00:00
|
|
|
events &= ~VIR_EVENT_HANDLE_READABLE;
|
|
|
|
if (got < 0) {
|
2011-05-29 12:37:29 +00:00
|
|
|
error = true;
|
2011-05-29 12:51:08 +00:00
|
|
|
} else if (got == 0) {
|
|
|
|
eof = true;
|
|
|
|
} else {
|
|
|
|
/* Ignore hangup/error events if we read some data, to
|
|
|
|
* give time for that data to be consumed */
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
events = 0;
|
|
|
|
|
|
|
|
if (qemuMonitorIOProcess(mon) < 0)
|
2011-05-29 12:37:29 +00:00
|
|
|
error = true;
|
2011-05-29 12:51:08 +00:00
|
|
|
}
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
}
|
|
|
|
|
2011-05-29 12:51:08 +00:00
|
|
|
if (!error &&
|
|
|
|
events & VIR_EVENT_HANDLE_HANGUP) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("End of file from monitor"));
|
2013-05-24 10:14:02 +00:00
|
|
|
eof = true;
|
2011-05-29 12:51:08 +00:00
|
|
|
events &= ~VIR_EVENT_HANDLE_HANGUP;
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
}
|
|
|
|
|
2011-05-29 12:51:08 +00:00
|
|
|
if (!error && !eof &&
|
|
|
|
events & VIR_EVENT_HANDLE_ERROR) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Invalid file descriptor while waiting for monitor"));
|
2013-05-24 10:14:02 +00:00
|
|
|
eof = true;
|
2011-06-02 10:50:03 +00:00
|
|
|
events &= ~VIR_EVENT_HANDLE_ERROR;
|
2011-05-29 12:51:08 +00:00
|
|
|
}
|
|
|
|
if (!error && events) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Unhandled event %d for monitor fd %d"),
|
|
|
|
events, mon->fd);
|
2013-05-24 10:14:02 +00:00
|
|
|
error = true;
|
2009-10-09 19:13:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-29 12:51:08 +00:00
|
|
|
if (error || eof) {
|
|
|
|
if (mon->lastError.code != VIR_ERR_OK) {
|
|
|
|
/* Already have an error, so clear any new error */
|
|
|
|
virResetLastError();
|
|
|
|
} else {
|
|
|
|
virErrorPtr err = virGetLastError();
|
|
|
|
if (!err)
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Error while processing monitor IO"));
|
2011-05-29 12:51:08 +00:00
|
|
|
virCopyLastError(&mon->lastError);
|
|
|
|
virResetLastError();
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_DEBUG("Error on monitor %s", NULLSTR(mon->lastError.message));
|
|
|
|
/* If IO process resulted in an error & we have a message,
|
|
|
|
* then wakeup that waiter */
|
|
|
|
if (mon->msg && !mon->msg->finished) {
|
|
|
|
mon->msg->finished = 1;
|
|
|
|
virCondSignal(&mon->notify);
|
|
|
|
}
|
|
|
|
}
|
2011-05-29 12:37:29 +00:00
|
|
|
|
|
|
|
qemuMonitorUpdateWatch(mon);
|
|
|
|
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
/* We have to unlock to avoid deadlock against command thread,
|
|
|
|
* but is this safe ? I think it is, because the callback
|
|
|
|
* will try to acquire the virDomainObjPtr mutex next */
|
2011-05-29 12:37:29 +00:00
|
|
|
if (eof) {
|
2013-07-25 15:27:52 +00:00
|
|
|
qemuMonitorEofNotifyCallback eofNotify = mon->cb->eofNotify;
|
2009-11-26 13:29:29 +00:00
|
|
|
virDomainObjPtr vm = mon->vm;
|
2011-03-30 01:43:25 +00:00
|
|
|
|
2011-05-29 12:37:29 +00:00
|
|
|
/* Make sure anyone waiting wakes up now */
|
|
|
|
virCondSignal(&mon->notify);
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(mon);
|
2012-07-11 13:35:47 +00:00
|
|
|
virObjectUnref(mon);
|
2011-05-29 12:37:29 +00:00
|
|
|
VIR_DEBUG("Triggering EOF callback");
|
2013-07-25 17:26:15 +00:00
|
|
|
(eofNotify)(mon, vm, mon->callbackOpaque);
|
2011-05-29 12:37:29 +00:00
|
|
|
} else if (error) {
|
2013-07-25 15:27:52 +00:00
|
|
|
qemuMonitorErrorNotifyCallback errorNotify = mon->cb->errorNotify;
|
2011-05-29 12:37:29 +00:00
|
|
|
virDomainObjPtr vm = mon->vm;
|
2011-03-30 01:43:25 +00:00
|
|
|
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
/* Make sure anyone waiting wakes up now */
|
|
|
|
virCondSignal(&mon->notify);
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(mon);
|
2012-07-11 13:35:47 +00:00
|
|
|
virObjectUnref(mon);
|
2011-05-29 12:37:29 +00:00
|
|
|
VIR_DEBUG("Triggering error callback");
|
2013-07-25 17:26:15 +00:00
|
|
|
(errorNotify)(mon, vm, mon->callbackOpaque);
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
} else {
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(mon);
|
2012-07-11 13:35:47 +00:00
|
|
|
virObjectUnref(mon);
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
}
|
2009-10-09 19:13:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-06 15:23:57 +00:00
|
|
|
static qemuMonitorPtr
|
|
|
|
qemuMonitorOpenInternal(virDomainObjPtr vm,
|
|
|
|
int fd,
|
|
|
|
bool hasSendFD,
|
2013-04-26 02:32:41 +00:00
|
|
|
bool json,
|
2013-07-25 17:26:15 +00:00
|
|
|
qemuMonitorCallbacksPtr cb,
|
|
|
|
void *opaque)
|
2009-10-09 18:07:55 +00:00
|
|
|
{
|
2009-10-09 19:13:29 +00:00
|
|
|
qemuMonitorPtr mon;
|
|
|
|
|
2012-08-20 12:39:47 +00:00
|
|
|
if (!cb->eofNotify) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("EOF notify callback must be supplied"));
|
2009-10-15 17:56:52 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-08-20 12:39:47 +00:00
|
|
|
if (!cb->errorNotify) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Error notify callback must be supplied"));
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-10-15 17:56:52 +00:00
|
|
|
|
2012-07-11 13:35:47 +00:00
|
|
|
if (qemuMonitorInitialize() < 0)
|
|
|
|
return NULL;
|
|
|
|
|
2013-01-09 21:00:32 +00:00
|
|
|
if (!(mon = virObjectLockableNew(qemuMonitorClass)))
|
2009-10-09 19:13:29 +00:00
|
|
|
return NULL;
|
|
|
|
|
2013-01-09 21:00:32 +00:00
|
|
|
mon->fd = -1;
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
if (virCondInit(&mon->notify) < 0) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("cannot initialize monitor condition"));
|
2013-01-09 21:00:32 +00:00
|
|
|
goto cleanup;
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
}
|
2012-09-06 15:23:57 +00:00
|
|
|
mon->fd = fd;
|
|
|
|
mon->hasSendFD = hasSendFD;
|
2009-10-09 19:13:29 +00:00
|
|
|
mon->vm = vm;
|
2009-11-03 18:59:18 +00:00
|
|
|
mon->json = json;
|
2012-09-06 15:14:25 +00:00
|
|
|
if (json)
|
2013-04-26 02:32:41 +00:00
|
|
|
mon->waitGreeting = true;
|
2009-10-15 17:56:52 +00:00
|
|
|
mon->cb = cb;
|
2013-07-25 17:26:15 +00:00
|
|
|
mon->callbackOpaque = opaque;
|
2009-10-09 19:13:29 +00:00
|
|
|
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
if (virSetCloseExec(mon->fd) < 0) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("Unable to set monitor close-on-exec flag"));
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (virSetNonBlock(mon->fd) < 0) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("Unable to put monitor into non-blocking mode"));
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-22 20:19:43 +00:00
|
|
|
virObjectLock(mon);
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectRef(mon);
|
2009-10-09 19:13:29 +00:00
|
|
|
if ((mon->watch = virEventAddHandle(mon->fd,
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
VIR_EVENT_HANDLE_HANGUP |
|
|
|
|
VIR_EVENT_HANDLE_ERROR |
|
|
|
|
VIR_EVENT_HANDLE_READABLE,
|
2009-10-09 19:13:29 +00:00
|
|
|
qemuMonitorIO,
|
2012-07-11 13:35:47 +00:00
|
|
|
mon,
|
|
|
|
virObjectFreeCallback)) < 0) {
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnref(mon);
|
2013-02-22 20:19:43 +00:00
|
|
|
virObjectUnlock(mon);
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("unable to register monitor events"));
|
2009-10-09 19:13:29 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2011-10-24 14:31:37 +00:00
|
|
|
PROBE(QEMU_MONITOR_NEW,
|
|
|
|
"mon=%p refs=%d fd=%d",
|
2013-01-09 21:00:32 +00:00
|
|
|
mon, mon->parent.parent.refs, mon->fd);
|
|
|
|
virObjectUnlock(mon);
|
2009-10-09 19:34:24 +00:00
|
|
|
|
2009-10-09 19:13:29 +00:00
|
|
|
return mon;
|
|
|
|
|
|
|
|
cleanup:
|
2010-06-29 10:57:54 +00:00
|
|
|
/* We don't want the 'destroy' callback invoked during
|
|
|
|
* cleanup from construction failure, because that can
|
|
|
|
* give a double-unref on virDomainObjPtr in the caller,
|
|
|
|
* so kill the callbacks now.
|
|
|
|
*/
|
|
|
|
mon->cb = NULL;
|
2012-09-06 15:23:57 +00:00
|
|
|
/* The caller owns 'fd' on failure */
|
|
|
|
mon->fd = -1;
|
2009-10-09 19:13:29 +00:00
|
|
|
qemuMonitorClose(mon);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-09-06 15:23:57 +00:00
|
|
|
qemuMonitorPtr
|
|
|
|
qemuMonitorOpen(virDomainObjPtr vm,
|
|
|
|
virDomainChrSourceDefPtr config,
|
2013-04-26 02:32:41 +00:00
|
|
|
bool json,
|
2013-07-25 17:26:15 +00:00
|
|
|
qemuMonitorCallbacksPtr cb,
|
|
|
|
void *opaque)
|
2012-09-06 15:23:57 +00:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
bool hasSendFD = false;
|
|
|
|
qemuMonitorPtr ret;
|
|
|
|
|
|
|
|
switch (config->type) {
|
|
|
|
case VIR_DOMAIN_CHR_TYPE_UNIX:
|
|
|
|
hasSendFD = true;
|
2012-09-28 14:26:36 +00:00
|
|
|
if ((fd = qemuMonitorOpenUnix(config->data.nix.path, vm ? vm->pid : 0)) < 0)
|
2012-09-06 15:23:57 +00:00
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VIR_DOMAIN_CHR_TYPE_PTY:
|
|
|
|
if ((fd = qemuMonitorOpenPty(config->data.file.path)) < 0)
|
|
|
|
return NULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("unable to handle monitor type: %s"),
|
|
|
|
virDomainChrTypeToString(config->type));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-07-25 17:26:15 +00:00
|
|
|
ret = qemuMonitorOpenInternal(vm, fd, hasSendFD, json, cb, opaque);
|
2012-09-06 15:23:57 +00:00
|
|
|
if (!ret)
|
|
|
|
VIR_FORCE_CLOSE(fd);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
qemuMonitorPtr qemuMonitorOpenFD(virDomainObjPtr vm,
|
|
|
|
int sockfd,
|
2013-04-26 02:32:41 +00:00
|
|
|
bool json,
|
2013-07-25 17:26:15 +00:00
|
|
|
qemuMonitorCallbacksPtr cb,
|
|
|
|
void *opaque)
|
2012-09-06 15:23:57 +00:00
|
|
|
{
|
2013-07-25 17:26:15 +00:00
|
|
|
return qemuMonitorOpenInternal(vm, sockfd, true, json, cb, opaque);
|
2012-09-06 15:23:57 +00:00
|
|
|
}
|
|
|
|
|
2009-10-09 19:13:29 +00:00
|
|
|
|
2010-06-10 14:11:30 +00:00
|
|
|
void qemuMonitorClose(qemuMonitorPtr mon)
|
2009-10-09 19:13:29 +00:00
|
|
|
{
|
|
|
|
if (!mon)
|
2010-06-10 14:11:30 +00:00
|
|
|
return;
|
2009-11-26 13:29:29 +00:00
|
|
|
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectLock(mon);
|
2011-10-24 14:31:37 +00:00
|
|
|
PROBE(QEMU_MONITOR_CLOSE,
|
2013-01-09 21:00:32 +00:00
|
|
|
"mon=%p refs=%d", mon, mon->parent.parent.refs);
|
2010-11-17 15:19:13 +00:00
|
|
|
|
|
|
|
if (mon->fd >= 0) {
|
2012-09-28 14:27:39 +00:00
|
|
|
if (mon->watch) {
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
virEventRemoveHandle(mon->watch);
|
2012-09-28 14:27:39 +00:00
|
|
|
mon->watch = 0;
|
|
|
|
}
|
2010-11-17 15:19:13 +00:00
|
|
|
VIR_FORCE_CLOSE(mon->fd);
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
}
|
2009-10-09 19:13:29 +00:00
|
|
|
|
2011-12-14 08:57:07 +00:00
|
|
|
/* In case another thread is waiting for its monitor command to be
|
|
|
|
* processed, we need to wake it up with appropriate error set.
|
|
|
|
*/
|
|
|
|
if (mon->msg) {
|
|
|
|
if (mon->lastError.code == VIR_ERR_OK) {
|
|
|
|
virErrorPtr err = virSaveLastError();
|
|
|
|
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
|
|
|
|
_("Qemu monitor was closed"));
|
2011-12-14 08:57:07 +00:00
|
|
|
virCopyLastError(&mon->lastError);
|
|
|
|
if (err) {
|
|
|
|
virSetError(err);
|
|
|
|
virFreeError(err);
|
|
|
|
} else {
|
|
|
|
virResetLastError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mon->msg->finished = 1;
|
|
|
|
virCondSignal(&mon->notify);
|
|
|
|
}
|
|
|
|
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(mon);
|
2012-07-11 13:35:47 +00:00
|
|
|
virObjectUnref(mon);
|
2009-10-09 19:13:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-29 12:51:08 +00:00
|
|
|
char *qemuMonitorNextCommandID(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
char *id;
|
|
|
|
|
2013-07-04 10:14:12 +00:00
|
|
|
ignore_value(virAsprintf(&id, "libvirt-%d", ++mon->nextSerial));
|
2011-05-29 12:51:08 +00:00
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
int qemuMonitorSend(qemuMonitorPtr mon,
|
|
|
|
qemuMonitorMessagePtr msg)
|
2009-10-09 19:13:29 +00:00
|
|
|
{
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
int ret = -1;
|
2009-10-09 19:13:29 +00:00
|
|
|
|
2011-03-30 01:43:25 +00:00
|
|
|
/* Check whether qemu quited unexpectedly */
|
2011-05-29 12:51:08 +00:00
|
|
|
if (mon->lastError.code != VIR_ERR_OK) {
|
|
|
|
VIR_DEBUG("Attempt to send command while error is set %s",
|
|
|
|
NULLSTR(mon->lastError.message));
|
|
|
|
virSetError(&mon->lastError);
|
2011-03-30 01:43:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
mon->msg = msg;
|
|
|
|
qemuMonitorUpdateWatch(mon);
|
2009-10-09 19:13:29 +00:00
|
|
|
|
2011-10-24 14:31:37 +00:00
|
|
|
PROBE(QEMU_MONITOR_SEND_MSG,
|
|
|
|
"mon=%p msg=%s fd=%d",
|
|
|
|
mon, mon->msg->txBuffer, mon->msg->txFD);
|
|
|
|
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
while (!mon->msg->finished) {
|
2013-01-09 21:00:32 +00:00
|
|
|
if (virCondWait(&mon->notify, &mon->parent.lock) < 0) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Unable to wait on monitor condition"));
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
goto cleanup;
|
2011-05-29 12:51:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mon->lastError.code != VIR_ERR_OK) {
|
|
|
|
VIR_DEBUG("Send command resulted in error %s",
|
|
|
|
NULLSTR(mon->lastError.message));
|
|
|
|
virSetError(&mon->lastError);
|
|
|
|
goto cleanup;
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
}
|
2009-10-09 19:13:29 +00:00
|
|
|
|
2011-05-29 12:51:08 +00:00
|
|
|
ret = 0;
|
2009-10-09 19:13:29 +00:00
|
|
|
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
cleanup:
|
|
|
|
mon->msg = NULL;
|
|
|
|
qemuMonitorUpdateWatch(mon);
|
2009-10-09 19:13:29 +00:00
|
|
|
|
Fully asynchronous monitor I/O processing
Change the QEMU monitor file handle watch to poll for both
read & write events, as well as EOF. All I/O to/from the
QEMU monitor FD is now done in the event callback thread.
When the QEMU driver needs to send a command, it puts the
data to be sent into a qemuMonitorMessagePtr object instance,
queues it for dispatch, and then goes to sleep on a condition
variable. The event thread sends all the data, and then waits
for the reply to arrive, putting the response / error data
back into the qemuMonitorMessagePtr and notifying the condition
variable.
There is a temporary hack in the disk passphrase callback to
avoid acquiring the domain lock. This avoids a deadlock in
the command processing, since the domain lock is still held
when running monitor commands. The next commit will remove
the locking when running commands & thus allow re-introduction
of locking the disk passphrase callback
* src/qemu/qemu_driver.c: Temporarily don't acquire lock in
disk passphrase callback. To be reverted in next commit
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Remove
raw I/O functions, and a generic qemuMonitorSend() for
invoking a command
* src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h:
Remove all low level I/O, and use the new qemuMonitorSend()
API. Provide a qemuMonitorTextIOProcess() method for detecting
command/reply/prompt boundaries in the monitor data stream
2009-10-14 17:40:51 +00:00
|
|
|
return ret;
|
2009-10-09 18:07:55 +00:00
|
|
|
}
|
2009-10-09 19:34:24 +00:00
|
|
|
|
|
|
|
|
2013-04-26 17:13:45 +00:00
|
|
|
virJSONValuePtr
|
|
|
|
qemuMonitorGetOptions(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
return mon->options;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
qemuMonitorSetOptions(qemuMonitorPtr mon, virJSONValuePtr options)
|
|
|
|
{
|
|
|
|
mon->options = options;
|
|
|
|
}
|
|
|
|
|
2013-06-27 15:00:31 +00:00
|
|
|
/* Search the qom objects for the balloon driver object by it's known name
|
|
|
|
* of "virtio-balloon-pci". The entry for the driver will be found in the
|
|
|
|
* returned 'type' field using the syntax "child<virtio-balloon-pci>".
|
|
|
|
*
|
|
|
|
* Once found, check the entry to ensure it has the correct property listed.
|
|
|
|
* If it does not, then obtaining statistics from qemu will not be possible.
|
|
|
|
* This feature was added to qemu 1.5.
|
|
|
|
*
|
|
|
|
* This procedure will be call recursively until found or the qom-list is
|
|
|
|
* exhausted.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
*
|
|
|
|
* 1 - Found
|
|
|
|
* 0 - Not found still looking
|
|
|
|
* -1 - Error bail out
|
|
|
|
*
|
|
|
|
* NOTE: This assumes we have already called qemuDomainObjEnterMonitor()
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
qemuMonitorFindBalloonObjectPath(qemuMonitorPtr mon,
|
|
|
|
virDomainObjPtr vm,
|
|
|
|
const char *curpath)
|
|
|
|
{
|
|
|
|
size_t i, j, npaths = 0, nprops = 0;
|
|
|
|
int ret = 0;
|
|
|
|
char *nextpath = NULL;
|
|
|
|
qemuMonitorJSONListPathPtr *paths = NULL;
|
|
|
|
qemuMonitorJSONListPathPtr *bprops = NULL;
|
|
|
|
|
|
|
|
if (mon->balloonpath) {
|
|
|
|
return 1;
|
|
|
|
} else if (mon->ballooninit) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Cannot determine balloon device path"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Not supported */
|
|
|
|
if (!vm->def->memballoon ||
|
|
|
|
vm->def->memballoon->model != VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Memory balloon model must be virtio to "
|
|
|
|
"get memballoon path"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_DEBUG("Searching for Balloon Object Path starting at %s", curpath);
|
|
|
|
|
|
|
|
npaths = qemuMonitorJSONGetObjectListPaths(mon, curpath, &paths);
|
|
|
|
|
|
|
|
for (i = 0; i < npaths && ret == 0; i++) {
|
|
|
|
|
|
|
|
if (STREQ_NULLABLE(paths[i]->type, "link<virtio-balloon-pci>")) {
|
|
|
|
VIR_DEBUG("Path to <virtio-balloon-pci> is '%s/%s'",
|
|
|
|
curpath, paths[i]->name);
|
|
|
|
if (virAsprintf(&nextpath, "%s/%s", curpath, paths[i]->name) < 0) {
|
|
|
|
ret = -1;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now look at the each of the property entries to determine
|
|
|
|
* whether "guest-stats-polling-interval" exists. If not,
|
|
|
|
* then this version of qemu/kvm does not support the feature.
|
|
|
|
*/
|
|
|
|
nprops = qemuMonitorJSONGetObjectListPaths(mon, nextpath, &bprops);
|
|
|
|
for (j = 0; j < nprops; j++) {
|
|
|
|
if (STREQ(bprops[j]->name, "guest-stats-polling-interval")) {
|
|
|
|
VIR_DEBUG("Found Balloon Object Path %s", nextpath);
|
|
|
|
mon->balloonpath = nextpath;
|
|
|
|
nextpath = NULL;
|
|
|
|
ret = 1;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we get here, we found the path, but not the property */
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Property 'guest-stats-polling-interval' "
|
|
|
|
"not found on memory balloon driver."));
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
ret = qemuMonitorFindBalloonObjectPath(mon, vm, nextpath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
for (i = 0; i < npaths; i++)
|
|
|
|
qemuMonitorJSONListPathFree(paths[i]);
|
|
|
|
VIR_FREE(paths);
|
|
|
|
for (j = 0; j < nprops; j++)
|
|
|
|
qemuMonitorJSONListPathFree(bprops[j]);
|
|
|
|
VIR_FREE(bprops);
|
|
|
|
VIR_FREE(nextpath);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-03-10 08:33:01 +00:00
|
|
|
int qemuMonitorHMPCommandWithFd(qemuMonitorPtr mon,
|
|
|
|
const char *cmd,
|
|
|
|
int scm_fd,
|
|
|
|
char **reply)
|
2011-03-09 20:24:04 +00:00
|
|
|
{
|
2012-02-26 00:48:02 +00:00
|
|
|
char *json_cmd = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
if (mon->json) {
|
|
|
|
/* hack to avoid complicating each call to text monitor functions */
|
|
|
|
json_cmd = qemuMonitorUnescapeArg(cmd);
|
|
|
|
if (!json_cmd) {
|
|
|
|
VIR_DEBUG("Could not unescape command: %s", cmd);
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Unable to unescape command"));
|
2012-02-26 00:48:02 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
ret = qemuMonitorJSONHumanCommandWithFd(mon, json_cmd, scm_fd, reply);
|
|
|
|
} else {
|
|
|
|
ret = qemuMonitorTextCommandWithFd(mon, cmd, scm_fd, reply);
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(json_cmd);
|
|
|
|
return ret;
|
2011-03-09 20:24:04 +00:00
|
|
|
}
|
|
|
|
|
2011-03-18 17:27:14 +00:00
|
|
|
/* Ensure proper locking around callbacks. */
|
|
|
|
#define QEMU_MONITOR_CALLBACK(mon, ret, callback, ...) \
|
|
|
|
do { \
|
2012-07-11 13:35:47 +00:00
|
|
|
virObjectRef(mon); \
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectUnlock(mon); \
|
2011-03-18 17:27:14 +00:00
|
|
|
if ((mon)->cb && (mon)->cb->callback) \
|
2013-07-25 17:26:15 +00:00
|
|
|
(ret) = (mon)->cb->callback(mon, __VA_ARGS__, \
|
|
|
|
(mon)->callbackOpaque); \
|
2013-01-09 21:00:32 +00:00
|
|
|
virObjectLock(mon); \
|
2012-07-11 13:35:47 +00:00
|
|
|
virObjectUnref(mon); \
|
2011-03-18 17:27:14 +00:00
|
|
|
} while (0)
|
2011-03-09 20:24:04 +00:00
|
|
|
|
2009-10-09 19:34:24 +00:00
|
|
|
int qemuMonitorGetDiskSecret(qemuMonitorPtr mon,
|
|
|
|
virConnectPtr conn,
|
|
|
|
const char *path,
|
|
|
|
char **secret,
|
|
|
|
size_t *secretLen)
|
|
|
|
{
|
2009-10-15 17:56:52 +00:00
|
|
|
int ret = -1;
|
2009-10-09 19:34:24 +00:00
|
|
|
*secret = NULL;
|
|
|
|
*secretLen = 0;
|
|
|
|
|
2011-03-18 17:27:14 +00:00
|
|
|
QEMU_MONITOR_CALLBACK(mon, ret, diskSecretLookup, conn, mon->vm,
|
|
|
|
path, secret, secretLen);
|
2009-10-15 17:56:52 +00:00
|
|
|
return ret;
|
2009-10-09 19:34:24 +00:00
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
|
|
|
|
2009-11-26 13:05:24 +00:00
|
|
|
int qemuMonitorEmitShutdown(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
VIR_DEBUG("mon=%p", mon);
|
|
|
|
|
2011-03-18 17:27:14 +00:00
|
|
|
QEMU_MONITOR_CALLBACK(mon, ret, domainShutdown, mon->vm);
|
2009-11-26 13:05:24 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorEmitReset(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
VIR_DEBUG("mon=%p", mon);
|
|
|
|
|
2011-03-18 17:27:14 +00:00
|
|
|
QEMU_MONITOR_CALLBACK(mon, ret, domainReset, mon->vm);
|
2009-11-26 13:05:24 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorEmitPowerdown(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
VIR_DEBUG("mon=%p", mon);
|
|
|
|
|
2011-03-18 17:27:14 +00:00
|
|
|
QEMU_MONITOR_CALLBACK(mon, ret, domainPowerdown, mon->vm);
|
2009-11-26 13:05:24 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorEmitStop(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
VIR_DEBUG("mon=%p", mon);
|
|
|
|
|
2011-03-18 17:27:14 +00:00
|
|
|
QEMU_MONITOR_CALLBACK(mon, ret, domainStop, mon->vm);
|
2009-11-26 13:05:24 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-07 21:25:01 +00:00
|
|
|
int qemuMonitorEmitResume(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
VIR_DEBUG("mon=%p", mon);
|
|
|
|
|
|
|
|
QEMU_MONITOR_CALLBACK(mon, ret, domainResume, mon->vm);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-07 10:23:34 +00:00
|
|
|
int qemuMonitorEmitGuestPanic(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
VIR_DEBUG("mon=%p", mon);
|
|
|
|
QEMU_MONITOR_CALLBACK(mon, ret, domainGuestPanic, mon->vm);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-18 18:28:15 +00:00
|
|
|
int qemuMonitorEmitRTCChange(qemuMonitorPtr mon, long long offset)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
VIR_DEBUG("mon=%p", mon);
|
|
|
|
|
2011-03-18 17:27:14 +00:00
|
|
|
QEMU_MONITOR_CALLBACK(mon, ret, domainRTCChange, mon->vm, offset);
|
2010-03-18 18:28:15 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
int qemuMonitorEmitWatchdog(qemuMonitorPtr mon, int action)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
VIR_DEBUG("mon=%p", mon);
|
|
|
|
|
2011-03-18 17:27:14 +00:00
|
|
|
QEMU_MONITOR_CALLBACK(mon, ret, domainWatchdog, mon->vm, action);
|
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
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 qemuMonitorEmitIOError(qemuMonitorPtr mon,
|
|
|
|
const char *diskAlias,
|
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
|
|
|
int action,
|
|
|
|
const char *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
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
VIR_DEBUG("mon=%p", mon);
|
|
|
|
|
2011-03-18 17:27:14 +00:00
|
|
|
QEMU_MONITOR_CALLBACK(mon, ret, domainIOError, mon->vm,
|
|
|
|
diskAlias, action, 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
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
int qemuMonitorEmitGraphics(qemuMonitorPtr mon,
|
|
|
|
int phase,
|
|
|
|
int localFamily,
|
|
|
|
const char *localNode,
|
|
|
|
const char *localService,
|
|
|
|
int remoteFamily,
|
|
|
|
const char *remoteNode,
|
|
|
|
const char *remoteService,
|
|
|
|
const char *authScheme,
|
|
|
|
const char *x509dname,
|
|
|
|
const char *saslUsername)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
VIR_DEBUG("mon=%p", mon);
|
|
|
|
|
2011-03-18 17:27:14 +00:00
|
|
|
QEMU_MONITOR_CALLBACK(mon, ret, domainGraphics, mon->vm, phase,
|
|
|
|
localFamily, localNode, localService,
|
|
|
|
remoteFamily, remoteNode, remoteService,
|
|
|
|
authScheme, x509dname, saslUsername);
|
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 ret;
|
|
|
|
}
|
|
|
|
|
2012-03-23 13:44:50 +00:00
|
|
|
int qemuMonitorEmitTrayChange(qemuMonitorPtr mon,
|
|
|
|
const char *devAlias,
|
|
|
|
int reason)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
VIR_DEBUG("mon=%p", mon);
|
|
|
|
|
|
|
|
QEMU_MONITOR_CALLBACK(mon, ret, domainTrayChange, mon->vm,
|
|
|
|
devAlias, reason);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-03-23 14:43:14 +00:00
|
|
|
int qemuMonitorEmitPMWakeup(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
VIR_DEBUG("mon=%p", mon);
|
|
|
|
|
|
|
|
QEMU_MONITOR_CALLBACK(mon, ret, domainPMWakeup, mon->vm);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-03-23 14:50:36 +00:00
|
|
|
int qemuMonitorEmitPMSuspend(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
VIR_DEBUG("mon=%p", mon);
|
|
|
|
|
|
|
|
QEMU_MONITOR_CALLBACK(mon, ret, domainPMSuspend, mon->vm);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-10-12 19:13:39 +00:00
|
|
|
int qemuMonitorEmitPMSuspendDisk(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
VIR_DEBUG("mon=%p", mon);
|
|
|
|
|
|
|
|
QEMU_MONITOR_CALLBACK(mon, ret, domainPMSuspendDisk, mon->vm);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-07-22 05:57:42 +00:00
|
|
|
int qemuMonitorEmitBlockJob(qemuMonitorPtr mon,
|
|
|
|
const char *diskAlias,
|
|
|
|
int type,
|
|
|
|
int status)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
VIR_DEBUG("mon=%p", mon);
|
|
|
|
|
|
|
|
QEMU_MONITOR_CALLBACK(mon, ret, domainBlockJob, mon->vm,
|
|
|
|
diskAlias, type, status);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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-07-12 15:45:57 +00:00
|
|
|
int qemuMonitorEmitBalloonChange(qemuMonitorPtr mon,
|
|
|
|
unsigned long long actual)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
VIR_DEBUG("mon=%p", mon);
|
|
|
|
|
|
|
|
QEMU_MONITOR_CALLBACK(mon, ret, domainBalloonChange, mon->vm, actual);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2013-07-11 15:07:26 +00:00
|
|
|
int
|
|
|
|
qemuMonitorEmitDeviceDeleted(qemuMonitorPtr mon,
|
|
|
|
const char *devAlias)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
VIR_DEBUG("mon=%p", mon);
|
|
|
|
|
|
|
|
QEMU_MONITOR_CALLBACK(mon, ret, domainDeviceDeleted, mon->vm, devAlias);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-13 14:54:02 +00:00
|
|
|
int qemuMonitorSetCapabilities(qemuMonitorPtr mon)
|
2010-02-12 13:45:20 +00:00
|
|
|
{
|
|
|
|
int ret;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p", mon);
|
2010-05-17 11:43:36 +00:00
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2010-02-12 13:45:20 +00:00
|
|
|
|
2011-03-16 19:34:01 +00:00
|
|
|
if (mon->json) {
|
2010-02-12 13:45:20 +00:00
|
|
|
ret = qemuMonitorJSONSetCapabilities(mon);
|
2012-07-12 15:45:57 +00:00
|
|
|
if (ret < 0)
|
2012-02-13 11:19:24 +00:00
|
|
|
goto cleanup;
|
2011-03-16 19:34:01 +00:00
|
|
|
} else {
|
2010-02-12 13:45:20 +00:00
|
|
|
ret = 0;
|
2011-03-16 19:34:01 +00:00
|
|
|
}
|
2012-02-13 11:19:24 +00:00
|
|
|
|
|
|
|
cleanup:
|
2010-02-12 13:45:20 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-09 20:13:06 +00:00
|
|
|
int
|
|
|
|
qemuMonitorStartCPUs(qemuMonitorPtr mon,
|
|
|
|
virConnectPtr conn)
|
|
|
|
{
|
2009-11-03 18:59:18 +00:00
|
|
|
int ret;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p", mon);
|
2010-05-17 11:43:36 +00:00
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONStartCPUs(mon, conn);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextStartCPUs(mon, conn);
|
|
|
|
return ret;
|
2009-10-09 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
qemuMonitorStopCPUs(qemuMonitorPtr mon)
|
|
|
|
{
|
2009-11-03 18:59:18 +00:00
|
|
|
int ret;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p", mon);
|
2010-05-17 11:43:36 +00:00
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONStopCPUs(mon);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextStopCPUs(mon);
|
|
|
|
return ret;
|
2009-10-09 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-05 11:50:25 +00:00
|
|
|
int
|
2011-09-27 09:42:04 +00:00
|
|
|
qemuMonitorGetStatus(qemuMonitorPtr mon,
|
|
|
|
bool *running,
|
|
|
|
virDomainPausedReason *reason)
|
2011-05-05 11:50:25 +00:00
|
|
|
{
|
|
|
|
int ret;
|
2011-09-27 09:42:04 +00:00
|
|
|
VIR_DEBUG("mon=%p, running=%p, reason=%p", mon, running, reason);
|
2011-05-05 11:50:25 +00:00
|
|
|
|
|
|
|
if (!mon || !running) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("both monitor and running must not be NULL"));
|
2011-05-05 11:50:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mon->json)
|
2011-09-27 09:42:04 +00:00
|
|
|
ret = qemuMonitorJSONGetStatus(mon, running, reason);
|
2011-05-05 11:50:25 +00:00
|
|
|
else
|
2011-09-27 09:42:04 +00:00
|
|
|
ret = qemuMonitorTextGetStatus(mon, running, reason);
|
2011-05-05 11:50:25 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-09 20:13:06 +00:00
|
|
|
int qemuMonitorSystemPowerdown(qemuMonitorPtr mon)
|
|
|
|
{
|
2009-11-03 18:59:18 +00:00
|
|
|
int ret;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p", mon);
|
2010-05-17 11:43:36 +00:00
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONSystemPowerdown(mon);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextSystemPowerdown(mon);
|
|
|
|
return ret;
|
2009-10-09 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-15 16:49:58 +00:00
|
|
|
int qemuMonitorSystemReset(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
VIR_DEBUG("mon=%p", mon);
|
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2011-06-15 16:49:58 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONSystemReset(mon);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextSystemReset(mon);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-09 20:13:06 +00:00
|
|
|
int qemuMonitorGetCPUInfo(qemuMonitorPtr mon,
|
|
|
|
int **pids)
|
|
|
|
{
|
2009-11-03 18:59:18 +00:00
|
|
|
int ret;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p", mon);
|
2010-05-17 11:43:36 +00:00
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONGetCPUInfo(mon, pids);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextGetCPUInfo(mon, pids);
|
|
|
|
return ret;
|
2009-10-09 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
2011-09-06 08:18:57 +00:00
|
|
|
int qemuMonitorSetLink(qemuMonitorPtr mon,
|
|
|
|
const char *name,
|
|
|
|
enum virDomainNetInterfaceLinkState state)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
VIR_DEBUG("mon=%p, name=%p:%s, state=%u", mon, name, name, state);
|
|
|
|
|
|
|
|
if (!mon || !name) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor || name must not be NULL"));
|
2011-09-06 08:18:57 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONSetLink(mon, name, state);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextSetLink(mon, name, state);
|
|
|
|
return ret;
|
|
|
|
}
|
2011-06-17 14:31:45 +00:00
|
|
|
|
|
|
|
int qemuMonitorGetVirtType(qemuMonitorPtr mon,
|
|
|
|
int *virtType)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
VIR_DEBUG("mon=%p", mon);
|
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2011-06-17 14:31:45 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONGetVirtType(mon, virtType);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextGetVirtType(mon, virtType);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-09 20:13:06 +00:00
|
|
|
int qemuMonitorGetBalloonInfo(qemuMonitorPtr mon,
|
2012-03-02 20:27:39 +00:00
|
|
|
unsigned long long *currmem)
|
2009-10-09 20:13:06 +00:00
|
|
|
{
|
2009-11-03 18:59:18 +00:00
|
|
|
int ret;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p", mon);
|
2010-05-17 11:43:36 +00:00
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONGetBalloonInfo(mon, currmem);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextGetBalloonInfo(mon, currmem);
|
|
|
|
return ret;
|
2009-10-09 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-12 11:31:15 +00:00
|
|
|
int qemuMonitorGetMemoryStats(qemuMonitorPtr mon,
|
|
|
|
virDomainMemoryStatPtr stats,
|
|
|
|
unsigned int nr_stats)
|
|
|
|
{
|
|
|
|
int ret;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p stats=%p nstats=%u", mon, stats, nr_stats);
|
2010-05-17 11:43:36 +00:00
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2010-04-12 11:31:15 +00:00
|
|
|
|
2013-07-11 23:18:48 +00:00
|
|
|
if (mon->json) {
|
|
|
|
ignore_value(qemuMonitorFindBalloonObjectPath(mon, mon->vm, "/"));
|
|
|
|
mon->ballooninit = true;
|
|
|
|
ret = qemuMonitorJSONGetMemoryStats(mon, mon->balloonpath,
|
|
|
|
stats, nr_stats);
|
|
|
|
} else {
|
2010-04-12 11:31:15 +00:00
|
|
|
ret = qemuMonitorTextGetMemoryStats(mon, stats, nr_stats);
|
2013-07-11 23:18:48 +00:00
|
|
|
}
|
2010-04-12 11:31:15 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-06-27 15:00:31 +00:00
|
|
|
int qemuMonitorSetMemoryStatsPeriod(qemuMonitorPtr mon,
|
|
|
|
int period)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
VIR_DEBUG("mon=%p period=%d", mon, period);
|
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mon->json) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
|
|
|
_("JSON monitor is required"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (qemuMonitorFindBalloonObjectPath(mon, mon->vm, "/") == 1) {
|
|
|
|
ret = qemuMonitorJSONSetMemoryStatsPeriod(mon, mon->balloonpath,
|
|
|
|
period);
|
|
|
|
}
|
|
|
|
mon->ballooninit = true;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-01-19 16:58:58 +00:00
|
|
|
int
|
|
|
|
qemuMonitorBlockIOStatusToError(const char *status)
|
|
|
|
{
|
|
|
|
int st = qemuMonitorBlockIOStatusTypeFromString(status);
|
|
|
|
|
|
|
|
if (st < 0) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("unknown block IO status: %s"), status);
|
2012-01-19 16:58:58 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ((qemuMonitorBlockIOStatus) st) {
|
|
|
|
case QEMU_MONITOR_BLOCK_IO_STATUS_OK:
|
|
|
|
return VIR_DOMAIN_DISK_ERROR_NONE;
|
|
|
|
case QEMU_MONITOR_BLOCK_IO_STATUS_FAILED:
|
|
|
|
return VIR_DOMAIN_DISK_ERROR_UNSPEC;
|
|
|
|
case QEMU_MONITOR_BLOCK_IO_STATUS_NOSPACE:
|
|
|
|
return VIR_DOMAIN_DISK_ERROR_NO_SPACE;
|
|
|
|
|
|
|
|
/* unreachable */
|
|
|
|
case QEMU_MONITOR_BLOCK_IO_STATUS_LAST:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-01-18 21:01:30 +00:00
|
|
|
virHashTablePtr
|
|
|
|
qemuMonitorGetBlockInfo(qemuMonitorPtr mon)
|
2011-09-13 13:49:50 +00:00
|
|
|
{
|
|
|
|
int ret;
|
2012-01-18 21:01:30 +00:00
|
|
|
virHashTablePtr table;
|
|
|
|
|
|
|
|
VIR_DEBUG("mon=%p", mon);
|
2011-09-13 13:49:50 +00:00
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2012-01-18 21:01:30 +00:00
|
|
|
return NULL;
|
2011-09-13 13:49:50 +00:00
|
|
|
}
|
|
|
|
|
2012-01-18 21:01:30 +00:00
|
|
|
if (!(table = virHashCreate(32, (virHashDataFree) free)))
|
|
|
|
return NULL;
|
|
|
|
|
2011-09-13 13:49:50 +00:00
|
|
|
if (mon->json)
|
2012-01-18 21:01:30 +00:00
|
|
|
ret = qemuMonitorJSONGetBlockInfo(mon, table);
|
2011-09-13 13:49:50 +00:00
|
|
|
else
|
2012-01-18 21:01:30 +00:00
|
|
|
ret = qemuMonitorTextGetBlockInfo(mon, table);
|
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
virHashFree(table);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return table;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct qemuDomainDiskInfo *
|
|
|
|
qemuMonitorBlockInfoLookup(virHashTablePtr blockInfo,
|
2012-12-14 19:02:10 +00:00
|
|
|
const char *dev)
|
2012-01-18 21:01:30 +00:00
|
|
|
{
|
|
|
|
struct qemuDomainDiskInfo *info;
|
|
|
|
|
2012-12-14 19:02:10 +00:00
|
|
|
VIR_DEBUG("blockInfo=%p dev=%s", blockInfo, NULLSTR(dev));
|
2012-01-18 21:01:30 +00:00
|
|
|
|
2012-12-14 19:02:10 +00:00
|
|
|
if (!(info = virHashLookup(blockInfo, dev))) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("cannot find info for device '%s'"),
|
2012-12-14 19:02:10 +00:00
|
|
|
NULLSTR(dev));
|
2012-01-18 21:01:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return info;
|
2011-09-13 13:49:50 +00:00
|
|
|
}
|
2010-04-12 11:31:15 +00:00
|
|
|
|
2009-10-09 20:13:06 +00:00
|
|
|
int qemuMonitorGetBlockStatsInfo(qemuMonitorPtr mon,
|
2011-09-16 12:05:58 +00:00
|
|
|
const char *dev_name,
|
2009-10-09 20:13:06 +00:00
|
|
|
long long *rd_req,
|
|
|
|
long long *rd_bytes,
|
2011-09-05 08:22:17 +00:00
|
|
|
long long *rd_total_times,
|
2009-10-09 20:13:06 +00:00
|
|
|
long long *wr_req,
|
|
|
|
long long *wr_bytes,
|
2011-09-05 08:22:17 +00:00
|
|
|
long long *wr_total_times,
|
|
|
|
long long *flush_req,
|
|
|
|
long long *flush_total_times,
|
2009-10-09 20:13:06 +00:00
|
|
|
long long *errs)
|
|
|
|
{
|
2009-11-03 18:59:18 +00:00
|
|
|
int ret;
|
2011-09-16 12:05:58 +00:00
|
|
|
VIR_DEBUG("mon=%p dev=%s", mon, dev_name);
|
2010-05-17 11:43:36 +00:00
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
2011-09-16 12:05:58 +00:00
|
|
|
ret = qemuMonitorJSONGetBlockStatsInfo(mon, dev_name,
|
2009-11-03 18:59:18 +00:00
|
|
|
rd_req, rd_bytes,
|
2011-09-05 08:22:17 +00:00
|
|
|
rd_total_times,
|
2009-11-03 18:59:18 +00:00
|
|
|
wr_req, wr_bytes,
|
2011-09-05 08:22:17 +00:00
|
|
|
wr_total_times,
|
|
|
|
flush_req,
|
|
|
|
flush_total_times,
|
2009-11-03 18:59:18 +00:00
|
|
|
errs);
|
|
|
|
else
|
2011-09-16 12:05:58 +00:00
|
|
|
ret = qemuMonitorTextGetBlockStatsInfo(mon, dev_name,
|
2009-11-03 18:59:18 +00:00
|
|
|
rd_req, rd_bytes,
|
2011-09-05 08:22:17 +00:00
|
|
|
rd_total_times,
|
2009-11-03 18:59:18 +00:00
|
|
|
wr_req, wr_bytes,
|
2011-09-05 08:22:17 +00:00
|
|
|
wr_total_times,
|
|
|
|
flush_req,
|
|
|
|
flush_total_times,
|
2009-11-03 18:59:18 +00:00
|
|
|
errs);
|
|
|
|
return ret;
|
2009-10-09 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
2011-09-05 08:22:17 +00:00
|
|
|
/* Return 0 and update @nparams with the number of block stats
|
|
|
|
* QEMU supports if success. Return -1 if failure.
|
|
|
|
*/
|
|
|
|
int qemuMonitorGetBlockStatsParamsNumber(qemuMonitorPtr mon,
|
|
|
|
int *nparams)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
VIR_DEBUG("mon=%p nparams=%p", mon, nparams);
|
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2011-09-05 08:22:17 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONGetBlockStatsParamsNumber(mon, nparams);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextGetBlockStatsParamsNumber(mon, nparams);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-05-14 13:10:01 +00:00
|
|
|
int qemuMonitorGetBlockExtent(qemuMonitorPtr mon,
|
2011-09-16 12:05:58 +00:00
|
|
|
const char *dev_name,
|
2010-05-14 13:10:01 +00:00
|
|
|
unsigned long long *extent)
|
|
|
|
{
|
|
|
|
int ret;
|
2013-02-22 20:19:43 +00:00
|
|
|
VIR_DEBUG("mon=%p, dev_name=%p", mon, dev_name);
|
2010-05-14 13:10:01 +00:00
|
|
|
|
|
|
|
if (mon->json)
|
2011-09-16 12:05:58 +00:00
|
|
|
ret = qemuMonitorJSONGetBlockExtent(mon, dev_name, extent);
|
2010-05-14 13:10:01 +00:00
|
|
|
else
|
2011-09-16 12:05:58 +00:00
|
|
|
ret = qemuMonitorTextGetBlockExtent(mon, dev_name, extent);
|
2010-05-14 13:10:01 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-11-29 07:34:53 +00:00
|
|
|
int qemuMonitorBlockResize(qemuMonitorPtr mon,
|
|
|
|
const char *device,
|
|
|
|
unsigned long long size)
|
|
|
|
{
|
|
|
|
int ret;
|
2013-02-22 20:19:43 +00:00
|
|
|
VIR_DEBUG("mon=%p, devname=%p size=%llu", mon, device, size);
|
2011-11-29 07:34:53 +00:00
|
|
|
|
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONBlockResize(mon, device, size);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextBlockResize(mon, device, size);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
|
|
|
int qemuMonitorSetVNCPassword(qemuMonitorPtr mon,
|
|
|
|
const char *password)
|
|
|
|
{
|
2009-11-03 18:59:18 +00:00
|
|
|
int ret;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p, password=%p",
|
2010-05-17 11:43:36 +00:00
|
|
|
mon, password);
|
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2010-03-22 18:44:58 +00:00
|
|
|
if (!password)
|
|
|
|
password = "";
|
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONSetVNCPassword(mon, password);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextSetVNCPassword(mon, password);
|
|
|
|
return ret;
|
2009-10-09 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
2011-01-10 11:12:32 +00:00
|
|
|
static const char* qemuMonitorTypeToProtocol(int type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case VIR_DOMAIN_GRAPHICS_TYPE_VNC:
|
|
|
|
return "vnc";
|
|
|
|
case VIR_DOMAIN_GRAPHICS_TYPE_SPICE:
|
|
|
|
return "spice";
|
|
|
|
default:
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("unsupported protocol type %s"),
|
|
|
|
virDomainGraphicsTypeToString(type));
|
2011-01-10 11:12:32 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns -2 if not supported with this monitor connection */
|
|
|
|
int qemuMonitorSetPassword(qemuMonitorPtr mon,
|
|
|
|
int type,
|
|
|
|
const char *password,
|
|
|
|
const char *action_if_connected)
|
|
|
|
{
|
|
|
|
const char *protocol = qemuMonitorTypeToProtocol(type);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!protocol)
|
|
|
|
return -1;
|
|
|
|
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p, protocol=%s, password=%p, action_if_connected=%s",
|
2011-01-10 11:12:32 +00:00
|
|
|
mon, protocol, password, action_if_connected);
|
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2011-01-10 11:12:32 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!password)
|
|
|
|
password = "";
|
|
|
|
|
|
|
|
if (!action_if_connected)
|
|
|
|
action_if_connected = "keep";
|
|
|
|
|
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONSetPassword(mon, protocol, password, action_if_connected);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextSetPassword(mon, protocol, password, action_if_connected);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int qemuMonitorExpirePassword(qemuMonitorPtr mon,
|
|
|
|
int type,
|
|
|
|
const char *expire_time)
|
|
|
|
{
|
|
|
|
const char *protocol = qemuMonitorTypeToProtocol(type);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!protocol)
|
|
|
|
return -1;
|
|
|
|
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p, protocol=%s, expire_time=%s",
|
2011-01-10 11:12:32 +00:00
|
|
|
mon, protocol, expire_time);
|
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2011-01-10 11:12:32 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!expire_time)
|
|
|
|
expire_time = "now";
|
|
|
|
|
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONExpirePassword(mon, protocol, expire_time);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextExpirePassword(mon, protocol, expire_time);
|
|
|
|
return ret;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
|
|
|
int qemuMonitorSetBalloon(qemuMonitorPtr mon,
|
|
|
|
unsigned long newmem)
|
|
|
|
{
|
2009-11-03 18:59:18 +00:00
|
|
|
int ret;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p newmem=%lu", mon, newmem);
|
2010-05-17 11:43:36 +00:00
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONSetBalloon(mon, newmem);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextSetBalloon(mon, newmem);
|
|
|
|
return ret;
|
2009-10-09 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
2010-02-08 16:37:17 +00:00
|
|
|
|
2013-05-27 13:35:35 +00:00
|
|
|
int qemuMonitorSetCPU(qemuMonitorPtr mon, int cpu, bool online)
|
2010-02-08 16:37:17 +00:00
|
|
|
{
|
|
|
|
int ret;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p cpu=%d online=%d", mon, cpu, online);
|
2010-05-17 11:43:36 +00:00
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2010-02-08 16:37:17 +00:00
|
|
|
|
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONSetCPU(mon, cpu, online);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextSetCPU(mon, cpu, online);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-09 20:13:06 +00:00
|
|
|
int qemuMonitorEjectMedia(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-10-09 20:13:06 +00:00
|
|
|
{
|
2009-11-03 18:59:18 +00:00
|
|
|
int ret;
|
2011-09-16 12:05:58 +00:00
|
|
|
VIR_DEBUG("mon=%p dev_name=%s force=%d", mon, dev_name, force);
|
2010-05-17 11:43:36 +00:00
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
2011-09-16 12:05:58 +00:00
|
|
|
ret = qemuMonitorJSONEjectMedia(mon, dev_name, force);
|
2009-11-03 18:59:18 +00:00
|
|
|
else
|
2011-09-16 12:05:58 +00:00
|
|
|
ret = qemuMonitorTextEjectMedia(mon, dev_name, force);
|
2009-11-03 18:59:18 +00:00
|
|
|
return ret;
|
2009-10-09 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorChangeMedia(qemuMonitorPtr mon,
|
2011-09-16 12:05:58 +00:00
|
|
|
const char *dev_name,
|
2009-11-26 13:48:17 +00:00
|
|
|
const char *newmedia,
|
|
|
|
const char *format)
|
2009-10-09 20:13:06 +00:00
|
|
|
{
|
2009-11-03 18:59:18 +00:00
|
|
|
int ret;
|
2011-09-16 12:05:58 +00:00
|
|
|
VIR_DEBUG("mon=%p dev_name=%s newmedia=%s format=%s",
|
|
|
|
mon, dev_name, newmedia, format);
|
2010-05-17 11:43:36 +00:00
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
2011-09-16 12:05:58 +00:00
|
|
|
ret = qemuMonitorJSONChangeMedia(mon, dev_name, newmedia, format);
|
2009-11-03 18:59:18 +00:00
|
|
|
else
|
2011-09-16 12:05:58 +00:00
|
|
|
ret = qemuMonitorTextChangeMedia(mon, dev_name, newmedia, format);
|
2009-11-03 18:59:18 +00:00
|
|
|
return ret;
|
2009-10-09 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorSaveVirtualMemory(qemuMonitorPtr mon,
|
|
|
|
unsigned long long offset,
|
|
|
|
size_t length,
|
|
|
|
const char *path)
|
|
|
|
{
|
2009-11-03 18:59:18 +00:00
|
|
|
int ret;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p offset=%llu length=%zu path=%s",
|
2010-05-17 11:43:36 +00:00
|
|
|
mon, offset, length, path);
|
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONSaveVirtualMemory(mon, offset, length, path);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextSaveVirtualMemory(mon, offset, length, path);
|
|
|
|
return ret;
|
2009-10-09 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int qemuMonitorSavePhysicalMemory(qemuMonitorPtr mon,
|
|
|
|
unsigned long long offset,
|
|
|
|
size_t length,
|
|
|
|
const char *path)
|
|
|
|
{
|
2009-11-03 18:59:18 +00:00
|
|
|
int ret;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p offset=%llu length=%zu path=%s",
|
2010-05-17 11:43:36 +00:00
|
|
|
mon, offset, length, path);
|
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONSavePhysicalMemory(mon, offset, length, path);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextSavePhysicalMemory(mon, offset, length, path);
|
|
|
|
return ret;
|
2009-10-09 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorSetMigrationSpeed(qemuMonitorPtr mon,
|
|
|
|
unsigned long bandwidth)
|
|
|
|
{
|
2009-11-03 18:59:18 +00:00
|
|
|
int ret;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p bandwidth=%lu", mon, bandwidth);
|
2010-05-17 11:43:36 +00:00
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONSetMigrationSpeed(mon, bandwidth);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextSetMigrationSpeed(mon, bandwidth);
|
|
|
|
return ret;
|
2009-10-09 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
2010-03-17 15:53:14 +00:00
|
|
|
|
|
|
|
int qemuMonitorSetMigrationDowntime(qemuMonitorPtr mon,
|
|
|
|
unsigned long long downtime)
|
|
|
|
{
|
|
|
|
int ret;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p downtime=%llu", mon, downtime);
|
2010-05-17 11:43:36 +00:00
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2010-03-17 15:53:14 +00:00
|
|
|
|
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONSetMigrationDowntime(mon, downtime);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextSetMigrationDowntime(mon, downtime);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-18 20:54:58 +00:00
|
|
|
int
|
|
|
|
qemuMonitorGetMigrationCacheSize(qemuMonitorPtr mon,
|
|
|
|
unsigned long long *cacheSize)
|
|
|
|
{
|
|
|
|
VIR_DEBUG("mon=%p cacheSize=%p", mon, cacheSize);
|
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mon->json) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
|
|
|
_("JSON monitor is required"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return qemuMonitorJSONGetMigrationCacheSize(mon, cacheSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
qemuMonitorSetMigrationCacheSize(qemuMonitorPtr mon,
|
|
|
|
unsigned long long cacheSize)
|
|
|
|
{
|
|
|
|
VIR_DEBUG("mon=%p cacheSize=%llu", mon, cacheSize);
|
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mon->json) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
|
|
|
_("JSON monitor is required"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return qemuMonitorJSONSetMigrationCacheSize(mon, cacheSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-09 20:13:06 +00:00
|
|
|
int qemuMonitorGetMigrationStatus(qemuMonitorPtr mon,
|
2013-02-08 08:58:03 +00:00
|
|
|
qemuMonitorMigrationStatusPtr status)
|
2009-10-09 20:13:06 +00:00
|
|
|
{
|
2009-11-03 18:59:18 +00:00
|
|
|
int ret;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p", mon);
|
2010-05-17 11:43:36 +00:00
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
2013-02-08 08:58:03 +00:00
|
|
|
ret = qemuMonitorJSONGetMigrationStatus(mon, status);
|
2009-11-03 18:59:18 +00:00
|
|
|
else
|
2013-02-08 08:58:03 +00:00
|
|
|
ret = qemuMonitorTextGetMigrationStatus(mon, status);
|
2009-11-03 18:59:18 +00:00
|
|
|
return ret;
|
2009-10-09 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-20 09:15:31 +00:00
|
|
|
int qemuMonitorGetSpiceMigrationStatus(qemuMonitorPtr mon,
|
|
|
|
bool *spice_migrated)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
VIR_DEBUG("mon=%p", mon);
|
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mon->json) {
|
|
|
|
ret = qemuMonitorJSONGetSpiceMigrationStatus(mon, spice_migrated);
|
|
|
|
} else {
|
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
|
|
|
_("JSON monitor is required"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-02 04:37:30 +00:00
|
|
|
int qemuMonitorMigrateToFd(qemuMonitorPtr mon,
|
|
|
|
unsigned int flags,
|
|
|
|
int fd)
|
|
|
|
{
|
|
|
|
int ret;
|
2011-07-08 15:18:48 +00:00
|
|
|
VIR_DEBUG("mon=%p fd=%d flags=%x",
|
2011-03-02 04:37:30 +00:00
|
|
|
mon, fd, flags);
|
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2011-03-02 04:37:30 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (qemuMonitorSendFileHandle(mon, "migrate", fd) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONMigrate(mon, flags, "fd:migrate");
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextMigrate(mon, flags, "fd:migrate");
|
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
if (qemuMonitorCloseFileHandle(mon, "migrate") < 0)
|
2011-05-09 09:24:09 +00:00
|
|
|
VIR_WARN("failed to close migration handle");
|
2011-03-02 04:37:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-09 20:13:06 +00:00
|
|
|
int qemuMonitorMigrateToHost(qemuMonitorPtr mon,
|
2010-06-24 18:58:36 +00:00
|
|
|
unsigned int flags,
|
2009-10-09 20:13:06 +00:00
|
|
|
const char *hostname,
|
|
|
|
int port)
|
|
|
|
{
|
2009-11-03 18:59:18 +00:00
|
|
|
int ret;
|
2011-03-04 18:51:48 +00:00
|
|
|
char *uri = NULL;
|
2011-07-08 15:18:48 +00:00
|
|
|
VIR_DEBUG("mon=%p hostname=%s port=%d flags=%x",
|
2010-06-24 18:58:36 +00:00
|
|
|
mon, hostname, port, flags);
|
2010-05-17 11:43:36 +00:00
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2011-03-04 18:51:48 +00:00
|
|
|
|
2013-07-04 10:14:12 +00:00
|
|
|
if (virAsprintf(&uri, "tcp:%s:%d", hostname, port) < 0)
|
2011-03-04 18:51:48 +00:00
|
|
|
return -1;
|
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
2011-03-04 18:51:48 +00:00
|
|
|
ret = qemuMonitorJSONMigrate(mon, flags, uri);
|
2009-11-03 18:59:18 +00:00
|
|
|
else
|
2011-03-04 18:51:48 +00:00
|
|
|
ret = qemuMonitorTextMigrate(mon, flags, uri);
|
|
|
|
|
|
|
|
VIR_FREE(uri);
|
2009-11-03 18:59:18 +00:00
|
|
|
return ret;
|
2009-10-09 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorMigrateToCommand(qemuMonitorPtr mon,
|
2010-06-24 18:58:36 +00:00
|
|
|
unsigned int flags,
|
2010-04-21 13:06:37 +00:00
|
|
|
const char * const *argv)
|
2009-10-09 20:13:06 +00:00
|
|
|
{
|
2011-03-04 18:51:48 +00:00
|
|
|
char *argstr;
|
|
|
|
char *dest = NULL;
|
|
|
|
int ret = -1;
|
2011-07-08 15:18:48 +00:00
|
|
|
VIR_DEBUG("mon=%p argv=%p flags=%x",
|
2010-06-24 18:58:36 +00:00
|
|
|
mon, argv, flags);
|
2010-05-17 11:43:36 +00:00
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2011-03-04 18:51:48 +00:00
|
|
|
argstr = virArgvToString(argv);
|
2013-07-04 10:14:12 +00:00
|
|
|
if (!argstr)
|
2011-03-04 18:51:48 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-07-04 10:14:12 +00:00
|
|
|
if (virAsprintf(&dest, "exec:%s", argstr) < 0)
|
2011-03-04 18:51:48 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
2011-03-04 18:51:48 +00:00
|
|
|
ret = qemuMonitorJSONMigrate(mon, flags, dest);
|
2009-11-03 18:59:18 +00:00
|
|
|
else
|
2011-03-04 18:51:48 +00:00
|
|
|
ret = qemuMonitorTextMigrate(mon, flags, dest);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(argstr);
|
|
|
|
VIR_FREE(dest);
|
2010-04-21 13:06:37 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int qemuMonitorMigrateToFile(qemuMonitorPtr mon,
|
2010-06-24 18:58:36 +00:00
|
|
|
unsigned int flags,
|
2010-04-21 13:06:37 +00:00
|
|
|
const char * const *argv,
|
|
|
|
const char *target,
|
|
|
|
unsigned long long offset)
|
|
|
|
{
|
2011-03-04 18:51:48 +00:00
|
|
|
char *argstr;
|
|
|
|
char *dest = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
char *safe_target = NULL;
|
2011-10-18 19:09:13 +00:00
|
|
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
2011-07-08 15:18:48 +00:00
|
|
|
VIR_DEBUG("mon=%p argv=%p target=%s offset=%llu flags=%x",
|
2010-06-24 18:58:36 +00:00
|
|
|
mon, argv, target, offset, flags);
|
2010-05-17 11:43:36 +00:00
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2010-04-21 13:06:37 +00:00
|
|
|
|
|
|
|
if (offset % QEMU_MONITOR_MIGRATE_TO_FILE_BS) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("file offset must be a multiple of %llu"),
|
|
|
|
QEMU_MONITOR_MIGRATE_TO_FILE_BS);
|
2010-04-21 13:06:37 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-03-04 18:51:48 +00:00
|
|
|
argstr = virArgvToString(argv);
|
2013-07-04 10:14:12 +00:00
|
|
|
if (!argstr)
|
2011-03-04 18:51:48 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* Migrate to file */
|
2011-10-18 19:09:13 +00:00
|
|
|
virBufferEscapeShell(&buf, target);
|
|
|
|
if (virBufferError(&buf)) {
|
2011-03-04 18:51:48 +00:00
|
|
|
virReportOOMError();
|
2011-10-18 19:09:13 +00:00
|
|
|
virBufferFreeAndReset(&buf);
|
2011-03-04 18:51:48 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2011-10-18 19:09:13 +00:00
|
|
|
safe_target = virBufferContentAndReset(&buf);
|
2011-03-04 18:51:48 +00:00
|
|
|
|
|
|
|
/* Two dd processes, sharing the same stdout, are necessary to
|
|
|
|
* allow starting at an alignment of 512, but without wasting
|
|
|
|
* padding to get to the larger alignment useful for speed. Use
|
|
|
|
* <> redirection to avoid truncating a regular file. */
|
|
|
|
if (virAsprintf(&dest, "exec:" VIR_WRAPPER_SHELL_PREFIX "%s | "
|
|
|
|
"{ dd bs=%llu seek=%llu if=/dev/null && "
|
qemu: improve efficiency of dd during snapshots
POSIX states about dd:
If the bs=expr operand is specified and no conversions other than
sync, noerror, or notrunc are requested, the data returned from each
input block shall be written as a separate output block; if the read
returns less than a full block and the sync conversion is not
specified, the resulting output block shall be the same size as the
input block. If the bs=expr operand is not specified, or a conversion
other than sync, noerror, or notrunc is requested, the input shall be
processed and collected into full-sized output blocks until the end of
the input is reached.
Since we aren't using conv=sync, there is no zero-padding, but our
use of bs= means that a short read results in a short write. If
instead we use ibs= and obs=, then short reads are collected and dd
only has to do a single write, which can make dd more efficient.
* src/qemu/qemu_monitor.c (qemuMonitorMigrateToFile):
Avoid 'dd bs=', since it can cause short writes.
2010-12-22 20:48:05 +00:00
|
|
|
"dd ibs=%llu obs=%llu; } 1<>%s" VIR_WRAPPER_SHELL_SUFFIX,
|
2011-03-04 18:51:48 +00:00
|
|
|
argstr, QEMU_MONITOR_MIGRATE_TO_FILE_BS,
|
|
|
|
offset / QEMU_MONITOR_MIGRATE_TO_FILE_BS,
|
|
|
|
QEMU_MONITOR_MIGRATE_TO_FILE_TRANSFER_SIZE,
|
qemu: improve efficiency of dd during snapshots
POSIX states about dd:
If the bs=expr operand is specified and no conversions other than
sync, noerror, or notrunc are requested, the data returned from each
input block shall be written as a separate output block; if the read
returns less than a full block and the sync conversion is not
specified, the resulting output block shall be the same size as the
input block. If the bs=expr operand is not specified, or a conversion
other than sync, noerror, or notrunc is requested, the input shall be
processed and collected into full-sized output blocks until the end of
the input is reached.
Since we aren't using conv=sync, there is no zero-padding, but our
use of bs= means that a short read results in a short write. If
instead we use ibs= and obs=, then short reads are collected and dd
only has to do a single write, which can make dd more efficient.
* src/qemu/qemu_monitor.c (qemuMonitorMigrateToFile):
Avoid 'dd bs=', since it can cause short writes.
2010-12-22 20:48:05 +00:00
|
|
|
QEMU_MONITOR_MIGRATE_TO_FILE_TRANSFER_SIZE,
|
2013-07-04 10:14:12 +00:00
|
|
|
safe_target) < 0)
|
2011-03-04 18:51:48 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2010-04-21 13:06:37 +00:00
|
|
|
if (mon->json)
|
2011-03-04 18:51:48 +00:00
|
|
|
ret = qemuMonitorJSONMigrate(mon, flags, dest);
|
2010-04-21 13:06:37 +00:00
|
|
|
else
|
2011-03-04 18:51:48 +00:00
|
|
|
ret = qemuMonitorTextMigrate(mon, flags, dest);
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(safe_target);
|
|
|
|
VIR_FREE(argstr);
|
|
|
|
VIR_FREE(dest);
|
2009-11-03 18:59:18 +00:00
|
|
|
return ret;
|
2009-10-09 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int qemuMonitorMigrateToUnix(qemuMonitorPtr mon,
|
2010-06-24 18:58:36 +00:00
|
|
|
unsigned int flags,
|
2009-10-09 20:13:06 +00:00
|
|
|
const char *unixfile)
|
|
|
|
{
|
2011-03-04 18:51:48 +00:00
|
|
|
char *dest = NULL;
|
|
|
|
int ret = -1;
|
2011-07-08 15:18:48 +00:00
|
|
|
VIR_DEBUG("mon=%p, unixfile=%s flags=%x",
|
2010-06-24 18:58:36 +00:00
|
|
|
mon, unixfile, flags);
|
2010-05-17 11:43:36 +00:00
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2013-07-04 10:14:12 +00:00
|
|
|
if (virAsprintf(&dest, "unix:%s", unixfile) < 0)
|
2011-03-04 18:51:48 +00:00
|
|
|
return -1;
|
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
2011-03-04 18:51:48 +00:00
|
|
|
ret = qemuMonitorJSONMigrate(mon, flags, dest);
|
2009-11-03 18:59:18 +00:00
|
|
|
else
|
2011-03-04 18:51:48 +00:00
|
|
|
ret = qemuMonitorTextMigrate(mon, flags, dest);
|
|
|
|
|
|
|
|
VIR_FREE(dest);
|
2009-11-03 18:59:18 +00:00
|
|
|
return ret;
|
2009-10-09 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int qemuMonitorMigrateCancel(qemuMonitorPtr mon)
|
|
|
|
{
|
2009-11-03 18:59:18 +00:00
|
|
|
int ret;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p", mon);
|
2010-05-17 11:43:36 +00:00
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONMigrateCancel(mon);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextMigrateCancel(mon);
|
|
|
|
return ret;
|
2009-10-09 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
2012-09-17 19:05:29 +00:00
|
|
|
int
|
|
|
|
qemuMonitorDumpToFd(qemuMonitorPtr mon, int fd)
|
2012-06-12 03:04:51 +00:00
|
|
|
{
|
|
|
|
int ret;
|
2012-09-17 19:05:29 +00:00
|
|
|
VIR_DEBUG("mon=%p fd=%d", mon, fd);
|
2012-06-12 03:04:51 +00:00
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2012-06-12 03:04:51 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mon->json) {
|
|
|
|
/* We don't have qemuMonitorTextDump(), so we should check mon->json
|
|
|
|
* here.
|
|
|
|
*/
|
2013-03-20 15:57:08 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
2012-07-18 15:22:03 +00:00
|
|
|
_("dump-guest-memory is not supported in text mode"));
|
2012-06-12 03:04:51 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (qemuMonitorSendFileHandle(mon, "dump", fd) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2012-09-17 19:05:29 +00:00
|
|
|
ret = qemuMonitorJSONDump(mon, "fd:dump");
|
2012-06-12 03:04:51 +00:00
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
if (qemuMonitorCloseFileHandle(mon, "dump") < 0)
|
|
|
|
VIR_WARN("failed to close dumping handle");
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2011-02-17 13:39:36 +00:00
|
|
|
|
|
|
|
int qemuMonitorGraphicsRelocate(qemuMonitorPtr mon,
|
|
|
|
int type,
|
|
|
|
const char *hostname,
|
|
|
|
int port,
|
|
|
|
int tlsPort,
|
|
|
|
const char *tlsSubject)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
VIR_DEBUG("mon=%p type=%d hostname=%s port=%d tlsPort=%d tlsSubject=%s",
|
|
|
|
mon, type, hostname, port, tlsPort, NULLSTR(tlsSubject));
|
|
|
|
|
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONGraphicsRelocate(mon,
|
|
|
|
type,
|
|
|
|
hostname,
|
|
|
|
port,
|
|
|
|
tlsPort,
|
|
|
|
tlsSubject);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextGraphicsRelocate(mon,
|
|
|
|
type,
|
|
|
|
hostname,
|
|
|
|
port,
|
|
|
|
tlsPort,
|
|
|
|
tlsSubject);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-09 20:13:06 +00:00
|
|
|
int qemuMonitorAddUSBDisk(qemuMonitorPtr mon,
|
|
|
|
const char *path)
|
|
|
|
{
|
2009-11-03 18:59:18 +00:00
|
|
|
int ret;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p path=%s", mon, path);
|
2010-05-17 11:43:36 +00:00
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONAddUSBDisk(mon, path);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextAddUSBDisk(mon, path);
|
|
|
|
return ret;
|
2009-10-09 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorAddUSBDeviceExact(qemuMonitorPtr mon,
|
|
|
|
int bus,
|
|
|
|
int dev)
|
|
|
|
{
|
2009-11-03 18:59:18 +00:00
|
|
|
int ret;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p bus=%d dev=%d", mon, bus, dev);
|
2010-05-17 11:43:36 +00:00
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONAddUSBDeviceExact(mon, bus, dev);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextAddUSBDeviceExact(mon, bus, dev);
|
|
|
|
return ret;
|
2009-10-09 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int qemuMonitorAddUSBDeviceMatch(qemuMonitorPtr mon,
|
|
|
|
int vendor,
|
|
|
|
int product)
|
|
|
|
{
|
2009-11-03 18:59:18 +00:00
|
|
|
int ret;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p vendor=%d product=%d",
|
2010-05-17 11:43:36 +00:00
|
|
|
mon, vendor, product);
|
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONAddUSBDeviceMatch(mon, vendor, product);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextAddUSBDeviceMatch(mon, vendor, product);
|
|
|
|
return ret;
|
2009-10-09 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorAddPCIHostDevice(qemuMonitorPtr mon,
|
2012-08-16 15:41:06 +00:00
|
|
|
virDevicePCIAddress *hostAddr,
|
|
|
|
virDevicePCIAddress *guestAddr)
|
2009-10-09 20:13:06 +00:00
|
|
|
{
|
2009-11-03 18:59:18 +00:00
|
|
|
int ret;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p domain=%d bus=%d slot=%d function=%d",
|
2010-05-17 11:43:36 +00:00
|
|
|
mon,
|
2009-12-07 19:07:39 +00:00
|
|
|
hostAddr->domain, hostAddr->bus, hostAddr->slot, hostAddr->function);
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2010-05-17 11:43:36 +00:00
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
2009-12-07 19:07:39 +00:00
|
|
|
ret = qemuMonitorJSONAddPCIHostDevice(mon, hostAddr, guestAddr);
|
2009-11-03 18:59:18 +00:00
|
|
|
else
|
2009-12-07 19:07:39 +00:00
|
|
|
ret = qemuMonitorTextAddPCIHostDevice(mon, hostAddr, guestAddr);
|
2009-11-03 18:59:18 +00:00
|
|
|
return ret;
|
2009-10-09 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorAddPCIDisk(qemuMonitorPtr mon,
|
|
|
|
const char *path,
|
|
|
|
const char *bus,
|
2012-08-16 15:41:06 +00:00
|
|
|
virDevicePCIAddress *guestAddr)
|
2009-10-09 20:13:06 +00:00
|
|
|
{
|
2009-11-03 18:59:18 +00:00
|
|
|
int ret;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p path=%s bus=%s",
|
2010-05-17 11:43:36 +00:00
|
|
|
mon, path, bus);
|
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
2009-12-07 19:07:39 +00:00
|
|
|
ret = qemuMonitorJSONAddPCIDisk(mon, path, bus, guestAddr);
|
2009-11-03 18:59:18 +00:00
|
|
|
else
|
2009-12-07 19:07:39 +00:00
|
|
|
ret = qemuMonitorTextAddPCIDisk(mon, path, bus, guestAddr);
|
2009-11-03 18:59:18 +00:00
|
|
|
return ret;
|
2009-10-09 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorAddPCINetwork(qemuMonitorPtr mon,
|
|
|
|
const char *nicstr,
|
2012-08-16 15:41:06 +00:00
|
|
|
virDevicePCIAddress *guestAddr)
|
2009-10-09 20:13:06 +00:00
|
|
|
{
|
2009-11-03 18:59:18 +00:00
|
|
|
int ret;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p nicstr=%s", mon, nicstr);
|
2010-05-17 11:43:36 +00:00
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
2009-12-07 19:07:39 +00:00
|
|
|
ret = qemuMonitorJSONAddPCINetwork(mon, nicstr, guestAddr);
|
2009-11-03 18:59:18 +00:00
|
|
|
else
|
2009-12-07 19:07:39 +00:00
|
|
|
ret = qemuMonitorTextAddPCINetwork(mon, nicstr, guestAddr);
|
2009-11-03 18:59:18 +00:00
|
|
|
return ret;
|
2009-10-09 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorRemovePCIDevice(qemuMonitorPtr mon,
|
2012-08-16 15:41:06 +00:00
|
|
|
virDevicePCIAddress *guestAddr)
|
2009-10-09 20:13:06 +00:00
|
|
|
{
|
2009-11-03 18:59:18 +00:00
|
|
|
int ret;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p domain=%d bus=%d slot=%d function=%d",
|
2010-05-17 11:43:36 +00:00
|
|
|
mon, guestAddr->domain, guestAddr->bus,
|
2009-12-07 19:07:39 +00:00
|
|
|
guestAddr->slot, guestAddr->function);
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2010-05-17 11:43:36 +00:00
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
2009-12-07 19:07:39 +00:00
|
|
|
ret = qemuMonitorJSONRemovePCIDevice(mon, guestAddr);
|
2009-11-03 18:59:18 +00:00
|
|
|
else
|
2009-12-07 19:07:39 +00:00
|
|
|
ret = qemuMonitorTextRemovePCIDevice(mon, guestAddr);
|
2009-11-03 18:59:18 +00:00
|
|
|
return ret;
|
2009-10-09 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorSendFileHandle(qemuMonitorPtr mon,
|
|
|
|
const char *fdname,
|
|
|
|
int fd)
|
|
|
|
{
|
2009-11-03 18:59:18 +00:00
|
|
|
int ret;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p, fdname=%s fd=%d",
|
2010-05-17 11:43:36 +00:00
|
|
|
mon, fdname, fd);
|
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2011-03-16 01:38:06 +00:00
|
|
|
if (fd < 0) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("fd must be valid"));
|
2011-03-16 01:38:06 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mon->hasSendFD) {
|
qemu: improve error for failed JSON commands
Only one error in qemu_monitor was already using the relatively
new OPERATION_UNSUPPORTED error, even though it is a better fit
for all of the messages related to options that are unsupported
due to the version of qemu in use rather than due to a user's
XML or .conf file choice. Suggested by Osier Yang.
* src/qemu/qemu_monitor.c (qemuMonitorSendFileHandle)
(qemuMonitorAddHostNetwork, qemuMonitorRemoveHostNetwork)
(qemuMonitorAttachDrive, qemuMonitorDiskSnapshot)
(qemuMonitorDriveMirror, qemuMonitorTransaction)
(qemuMonitorBlockCommit, qemuMonitorDrivePivot)
(qemuMonitorBlockJob, qemuMonitorSystemWakeup)
(qemuMonitorGetVersion, qemuMonitorGetMachines)
(qemuMonitorGetCPUDefinitions, qemuMonitorGetCommands)
(qemuMonitorGetEvents, qemuMonitorGetKVMState)
(qemuMonitorGetObjectTypes, qemuMonitorGetObjectProps)
(qemuMonitorGetTargetArch): Use better error category.
2012-12-04 20:24:40 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
|
2012-07-18 15:22:03 +00:00
|
|
|
_("qemu is not using a unix socket monitor, "
|
|
|
|
"cannot send fd %s"), fdname);
|
2011-03-16 01:38:06 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONSendFileHandle(mon, fdname, fd);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextSendFileHandle(mon, fdname, fd);
|
|
|
|
return ret;
|
2009-10-09 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorCloseFileHandle(qemuMonitorPtr mon,
|
|
|
|
const char *fdname)
|
|
|
|
{
|
2011-07-13 09:16:20 +00:00
|
|
|
int ret = -1;
|
|
|
|
virErrorPtr error;
|
|
|
|
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p fdname=%s",
|
2010-05-17 11:43:36 +00:00
|
|
|
mon, fdname);
|
|
|
|
|
2011-07-13 09:16:20 +00:00
|
|
|
error = virSaveLastError();
|
|
|
|
|
2010-05-17 11:43:36 +00:00
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2011-07-13 09:16:20 +00:00
|
|
|
goto cleanup;
|
2010-05-17 11:43:36 +00:00
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONCloseFileHandle(mon, fdname);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextCloseFileHandle(mon, fdname);
|
2011-07-13 09:16:20 +00:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (error) {
|
|
|
|
virSetError(error);
|
|
|
|
virFreeError(error);
|
|
|
|
}
|
2009-11-03 18:59:18 +00:00
|
|
|
return ret;
|
2009-10-09 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-31 00:18:44 +00:00
|
|
|
/* Add the open file descriptor FD into the non-negative set FDSET.
|
|
|
|
* If NAME is present, it will be passed along for logging purposes.
|
|
|
|
* Returns the counterpart fd that qemu received, or -1 on error. */
|
|
|
|
int
|
|
|
|
qemuMonitorAddFd(qemuMonitorPtr mon, int fdset, int fd, const char *name)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
VIR_DEBUG("mon=%p, fdset=%d, fd=%d, name=%s",
|
|
|
|
mon, fdset, fd, NULLSTR(name));
|
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fd < 0 || fdset < 0) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("fd and fdset must be valid"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mon->hasSendFD) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
|
|
|
|
_("qemu is not using a unix socket monitor, "
|
|
|
|
"cannot send fd %s"), NULLSTR(name));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONAddFd(mon, fdset, fd, name);
|
|
|
|
else
|
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
|
|
|
_("add fd requires JSON monitor"));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Remove one of qemu's fds from the given FDSET, or if FD is
|
|
|
|
* negative, remove the entire set. Preserve any previous error on
|
|
|
|
* entry. Returns 0 on success, -1 on error. */
|
|
|
|
int
|
|
|
|
qemuMonitorRemoveFd(qemuMonitorPtr mon, int fdset, int fd)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
virErrorPtr error;
|
|
|
|
|
|
|
|
VIR_DEBUG("mon=%p, fdset=%d, fd=%d", mon, fdset, fd);
|
|
|
|
|
|
|
|
error = virSaveLastError();
|
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONRemoveFd(mon, fdset, fd);
|
|
|
|
else
|
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
|
|
|
_("remove fd requires JSON monitor"));
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (error) {
|
|
|
|
virSetError(error);
|
|
|
|
virFreeError(error);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-09 20:13:06 +00:00
|
|
|
int qemuMonitorAddHostNetwork(qemuMonitorPtr mon,
|
2011-03-16 02:21:45 +00:00
|
|
|
const char *netstr,
|
2013-05-21 13:50:09 +00:00
|
|
|
int *tapfd, char **tapfdName, int tapfdSize,
|
|
|
|
int *vhostfd, char **vhostfdName, int vhostfdSize)
|
2009-10-09 20:13:06 +00:00
|
|
|
{
|
2011-03-16 02:21:45 +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 = 0, j = 0;
|
2013-05-21 13:50:09 +00:00
|
|
|
|
|
|
|
VIR_DEBUG("mon=%p netstr=%s tapfd=%p tapfdName=%p tapfdSize=%d "
|
|
|
|
"vhostfd=%p vhostfdName=%p vhostfdSize=%d",
|
|
|
|
mon, netstr, tapfd, tapfdName, tapfdSize,
|
|
|
|
vhostfd, vhostfdName, vhostfdSize);
|
2010-05-17 11:43:36 +00:00
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2013-05-21 13:50:09 +00:00
|
|
|
for (i = 0; i < tapfdSize; i++) {
|
|
|
|
if (qemuMonitorSendFileHandle(mon, tapfdName[i], tapfd[i]) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
for (j = 0; j < vhostfdSize; j++) {
|
|
|
|
if (qemuMonitorSendFileHandle(mon, vhostfdName[j], vhostfd[j]) < 0)
|
|
|
|
goto cleanup;
|
2011-03-16 02:21:45 +00:00
|
|
|
}
|
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
qemu: improve error for failed JSON commands
Only one error in qemu_monitor was already using the relatively
new OPERATION_UNSUPPORTED error, even though it is a better fit
for all of the messages related to options that are unsupported
due to the version of qemu in use rather than due to a user's
XML or .conf file choice. Suggested by Osier Yang.
* src/qemu/qemu_monitor.c (qemuMonitorSendFileHandle)
(qemuMonitorAddHostNetwork, qemuMonitorRemoveHostNetwork)
(qemuMonitorAttachDrive, qemuMonitorDiskSnapshot)
(qemuMonitorDriveMirror, qemuMonitorTransaction)
(qemuMonitorBlockCommit, qemuMonitorDrivePivot)
(qemuMonitorBlockJob, qemuMonitorSystemWakeup)
(qemuMonitorGetVersion, qemuMonitorGetMachines)
(qemuMonitorGetCPUDefinitions, qemuMonitorGetCommands)
(qemuMonitorGetEvents, qemuMonitorGetKVMState)
(qemuMonitorGetObjectTypes, qemuMonitorGetObjectProps)
(qemuMonitorGetTargetArch): Use better error category.
2012-12-04 20:24:40 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
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
|
|
|
_("JSON monitor should be using AddNetdev"));
|
2009-11-03 18:59:18 +00:00
|
|
|
else
|
|
|
|
ret = qemuMonitorTextAddHostNetwork(mon, netstr);
|
2011-03-16 02:21:45 +00:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (ret < 0) {
|
2013-05-21 13:50:09 +00:00
|
|
|
while (i--) {
|
|
|
|
if (qemuMonitorCloseFileHandle(mon, tapfdName[i]) < 0)
|
|
|
|
VIR_WARN("failed to close device handle '%s'", tapfdName[i]);
|
|
|
|
}
|
|
|
|
while (j--) {
|
|
|
|
if (qemuMonitorCloseFileHandle(mon, vhostfdName[j]) < 0)
|
|
|
|
VIR_WARN("failed to close device handle '%s'", vhostfdName[j]);
|
|
|
|
}
|
2011-03-16 02:21:45 +00:00
|
|
|
}
|
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
return ret;
|
2009-10-09 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorRemoveHostNetwork(qemuMonitorPtr mon,
|
|
|
|
int vlan,
|
|
|
|
const char *netname)
|
|
|
|
{
|
2012-11-30 17:51:28 +00:00
|
|
|
int ret = -1;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p netname=%s",
|
2010-05-17 11:43:36 +00:00
|
|
|
mon, netname);
|
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
qemu: improve error for failed JSON commands
Only one error in qemu_monitor was already using the relatively
new OPERATION_UNSUPPORTED error, even though it is a better fit
for all of the messages related to options that are unsupported
due to the version of qemu in use rather than due to a user's
XML or .conf file choice. Suggested by Osier Yang.
* src/qemu/qemu_monitor.c (qemuMonitorSendFileHandle)
(qemuMonitorAddHostNetwork, qemuMonitorRemoveHostNetwork)
(qemuMonitorAttachDrive, qemuMonitorDiskSnapshot)
(qemuMonitorDriveMirror, qemuMonitorTransaction)
(qemuMonitorBlockCommit, qemuMonitorDrivePivot)
(qemuMonitorBlockJob, qemuMonitorSystemWakeup)
(qemuMonitorGetVersion, qemuMonitorGetMachines)
(qemuMonitorGetCPUDefinitions, qemuMonitorGetCommands)
(qemuMonitorGetEvents, qemuMonitorGetKVMState)
(qemuMonitorGetObjectTypes, qemuMonitorGetObjectProps)
(qemuMonitorGetTargetArch): Use better error category.
2012-12-04 20:24:40 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
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
|
|
|
_("JSON monitor should be using RemoveNetdev"));
|
2009-11-03 18:59:18 +00:00
|
|
|
else
|
|
|
|
ret = qemuMonitorTextRemoveHostNetwork(mon, vlan, netname);
|
|
|
|
return ret;
|
2009-10-09 20:13:06 +00:00
|
|
|
}
|
2009-12-14 09:50:01 +00:00
|
|
|
|
2010-04-15 13:52:03 +00:00
|
|
|
|
|
|
|
int qemuMonitorAddNetdev(qemuMonitorPtr mon,
|
2011-03-16 02:21:45 +00:00
|
|
|
const char *netdevstr,
|
2013-05-21 13:50:09 +00:00
|
|
|
int *tapfd, char **tapfdName, int tapfdSize,
|
|
|
|
int *vhostfd, char **vhostfdName, int vhostfdSize)
|
2010-04-15 13:52:03 +00:00
|
|
|
{
|
2011-03-16 02:21:45 +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 = 0, j = 0;
|
2013-05-21 13:50:09 +00:00
|
|
|
|
|
|
|
VIR_DEBUG("mon=%p netdevstr=%s tapfd=%p tapfdName=%p tapfdSize=%d"
|
|
|
|
"vhostfd=%p vhostfdName=%p vhostfdSize=%d",
|
|
|
|
mon, netdevstr, tapfd, tapfdName, tapfdSize,
|
|
|
|
vhostfd, vhostfdName, tapfdSize);
|
2010-05-17 11:43:36 +00:00
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2010-04-15 13:52:03 +00:00
|
|
|
|
2013-05-21 13:50:09 +00:00
|
|
|
for (i = 0; i < tapfdSize; i++) {
|
|
|
|
if (qemuMonitorSendFileHandle(mon, tapfdName[i], tapfd[i]) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
for (j = 0; j < vhostfdSize; j++) {
|
|
|
|
if (qemuMonitorSendFileHandle(mon, vhostfdName[j], vhostfd[j]) < 0)
|
|
|
|
goto cleanup;
|
2011-03-16 02:21:45 +00:00
|
|
|
}
|
|
|
|
|
2010-04-15 13:52:03 +00:00
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONAddNetdev(mon, netdevstr);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextAddNetdev(mon, netdevstr);
|
2011-03-16 02:21:45 +00:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (ret < 0) {
|
2013-05-21 13:50:09 +00:00
|
|
|
while (i--) {
|
|
|
|
if (qemuMonitorCloseFileHandle(mon, tapfdName[i]) < 0)
|
|
|
|
VIR_WARN("failed to close device handle '%s'", tapfdName[i]);
|
|
|
|
}
|
|
|
|
while (j--) {
|
|
|
|
if (qemuMonitorCloseFileHandle(mon, vhostfdName[j]) < 0)
|
|
|
|
VIR_WARN("failed to close device handle '%s'", vhostfdName[j]);
|
|
|
|
}
|
2011-03-16 02:21:45 +00:00
|
|
|
}
|
|
|
|
|
2010-04-15 13:52:03 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int qemuMonitorRemoveNetdev(qemuMonitorPtr mon,
|
|
|
|
const char *alias)
|
|
|
|
{
|
|
|
|
int ret;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p alias=%s",
|
2010-05-17 11:43:36 +00:00
|
|
|
mon, alias);
|
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2010-04-15 13:52:03 +00:00
|
|
|
|
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONRemoveNetdev(mon, alias);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextRemoveNetdev(mon, alias);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-14 09:50:01 +00:00
|
|
|
int qemuMonitorGetPtyPaths(qemuMonitorPtr mon,
|
|
|
|
virHashTablePtr paths)
|
|
|
|
{
|
2010-01-22 13:22:53 +00:00
|
|
|
int ret;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p",
|
2010-05-17 11:43:36 +00:00
|
|
|
mon);
|
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2009-12-14 09:50:01 +00:00
|
|
|
|
2010-01-22 13:22:53 +00:00
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONGetPtyPaths(mon, paths);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextGetPtyPaths(mon, paths);
|
|
|
|
return ret;
|
2009-12-14 09:50:01 +00:00
|
|
|
}
|
2009-12-07 19:28:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorAttachPCIDiskController(qemuMonitorPtr mon,
|
|
|
|
const char *bus,
|
2012-08-16 15:41:06 +00:00
|
|
|
virDevicePCIAddress *guestAddr)
|
2009-12-07 19:28:05 +00:00
|
|
|
{
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p type=%s", mon, bus);
|
2009-12-07 19:28:05 +00:00
|
|
|
int ret;
|
|
|
|
|
2010-05-17 11:43:36 +00:00
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-12-07 19:28:05 +00:00
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONAttachPCIDiskController(mon, bus, guestAddr);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextAttachPCIDiskController(mon, bus, guestAddr);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
Properly support SCSI drive hotplug
The current SCSI hotplug support attaches a brand new SCSI controller
for every disk. This is broken because the semantics differ from those
used when starting the VM initially. In the latter case, each SCSI
controller is filled before a new one is added.
If the user specifies an high drive index (sdazz) then at initial
startup, many intermediate SCSI controllers may be added with no
drives.
This patch changes SCSI hotplug so that it exactly matches the
behaviour of initial startup. First the SCSI controller number is
determined for the drive to be hotplugged. If any controller upto
and including that controller number is not yet present, it is
attached. Then finally the drive is attached to the last controller.
NB, this breaks SCSI hotunplug, because there is no 'drive_del'
command in current QEMU. Previous SCSI hotunplug was broken in
any case because it was unplugging the entire controller, not
just the drive in question.
A future QEMU will allow proper SCSI hotunplug of a drive.
This patch is derived from work done by Wolfgang Mauerer on disk
controllers.
* src/qemu/qemu_driver.c: Fix SCSI hotplug to add a drive to
the correct controller, instead of just attaching a new
controller.
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c, src/qemu/qemu_monitor_json.h,
src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h: Add
support for 'drive_add' command
2009-12-09 17:57:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorAttachDrive(qemuMonitorPtr mon,
|
|
|
|
const char *drivestr,
|
2012-08-16 15:41:06 +00:00
|
|
|
virDevicePCIAddress *controllerAddr,
|
Properly support SCSI drive hotplug
The current SCSI hotplug support attaches a brand new SCSI controller
for every disk. This is broken because the semantics differ from those
used when starting the VM initially. In the latter case, each SCSI
controller is filled before a new one is added.
If the user specifies an high drive index (sdazz) then at initial
startup, many intermediate SCSI controllers may be added with no
drives.
This patch changes SCSI hotplug so that it exactly matches the
behaviour of initial startup. First the SCSI controller number is
determined for the drive to be hotplugged. If any controller upto
and including that controller number is not yet present, it is
attached. Then finally the drive is attached to the last controller.
NB, this breaks SCSI hotunplug, because there is no 'drive_del'
command in current QEMU. Previous SCSI hotunplug was broken in
any case because it was unplugging the entire controller, not
just the drive in question.
A future QEMU will allow proper SCSI hotunplug of a drive.
This patch is derived from work done by Wolfgang Mauerer on disk
controllers.
* src/qemu/qemu_driver.c: Fix SCSI hotplug to add a drive to
the correct controller, instead of just attaching a new
controller.
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c, src/qemu/qemu_monitor_json.h,
src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h: Add
support for 'drive_add' command
2009-12-09 17:57:09 +00:00
|
|
|
virDomainDeviceDriveAddress *driveAddr)
|
|
|
|
{
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p drivestr=%s domain=%d bus=%d slot=%d function=%d",
|
2010-05-17 11:43:36 +00:00
|
|
|
mon, drivestr,
|
Properly support SCSI drive hotplug
The current SCSI hotplug support attaches a brand new SCSI controller
for every disk. This is broken because the semantics differ from those
used when starting the VM initially. In the latter case, each SCSI
controller is filled before a new one is added.
If the user specifies an high drive index (sdazz) then at initial
startup, many intermediate SCSI controllers may be added with no
drives.
This patch changes SCSI hotplug so that it exactly matches the
behaviour of initial startup. First the SCSI controller number is
determined for the drive to be hotplugged. If any controller upto
and including that controller number is not yet present, it is
attached. Then finally the drive is attached to the last controller.
NB, this breaks SCSI hotunplug, because there is no 'drive_del'
command in current QEMU. Previous SCSI hotunplug was broken in
any case because it was unplugging the entire controller, not
just the drive in question.
A future QEMU will allow proper SCSI hotunplug of a drive.
This patch is derived from work done by Wolfgang Mauerer on disk
controllers.
* src/qemu/qemu_driver.c: Fix SCSI hotplug to add a drive to
the correct controller, instead of just attaching a new
controller.
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c, src/qemu/qemu_monitor_json.h,
src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h: Add
support for 'drive_add' command
2009-12-09 17:57:09 +00:00
|
|
|
controllerAddr->domain, controllerAddr->bus,
|
|
|
|
controllerAddr->slot, controllerAddr->function);
|
2012-11-30 17:51:28 +00:00
|
|
|
int ret = 1;
|
Properly support SCSI drive hotplug
The current SCSI hotplug support attaches a brand new SCSI controller
for every disk. This is broken because the semantics differ from those
used when starting the VM initially. In the latter case, each SCSI
controller is filled before a new one is added.
If the user specifies an high drive index (sdazz) then at initial
startup, many intermediate SCSI controllers may be added with no
drives.
This patch changes SCSI hotplug so that it exactly matches the
behaviour of initial startup. First the SCSI controller number is
determined for the drive to be hotplugged. If any controller upto
and including that controller number is not yet present, it is
attached. Then finally the drive is attached to the last controller.
NB, this breaks SCSI hotunplug, because there is no 'drive_del'
command in current QEMU. Previous SCSI hotunplug was broken in
any case because it was unplugging the entire controller, not
just the drive in question.
A future QEMU will allow proper SCSI hotunplug of a drive.
This patch is derived from work done by Wolfgang Mauerer on disk
controllers.
* src/qemu/qemu_driver.c: Fix SCSI hotplug to add a drive to
the correct controller, instead of just attaching a new
controller.
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c, src/qemu/qemu_monitor_json.h,
src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h: Add
support for 'drive_add' command
2009-12-09 17:57:09 +00:00
|
|
|
|
2010-05-17 11:43:36 +00:00
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
Properly support SCSI drive hotplug
The current SCSI hotplug support attaches a brand new SCSI controller
for every disk. This is broken because the semantics differ from those
used when starting the VM initially. In the latter case, each SCSI
controller is filled before a new one is added.
If the user specifies an high drive index (sdazz) then at initial
startup, many intermediate SCSI controllers may be added with no
drives.
This patch changes SCSI hotplug so that it exactly matches the
behaviour of initial startup. First the SCSI controller number is
determined for the drive to be hotplugged. If any controller upto
and including that controller number is not yet present, it is
attached. Then finally the drive is attached to the last controller.
NB, this breaks SCSI hotunplug, because there is no 'drive_del'
command in current QEMU. Previous SCSI hotunplug was broken in
any case because it was unplugging the entire controller, not
just the drive in question.
A future QEMU will allow proper SCSI hotunplug of a drive.
This patch is derived from work done by Wolfgang Mauerer on disk
controllers.
* src/qemu/qemu_driver.c: Fix SCSI hotplug to add a drive to
the correct controller, instead of just attaching a new
controller.
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c, src/qemu/qemu_monitor_json.h,
src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h: Add
support for 'drive_add' command
2009-12-09 17:57:09 +00:00
|
|
|
if (mon->json)
|
qemu: improve error for failed JSON commands
Only one error in qemu_monitor was already using the relatively
new OPERATION_UNSUPPORTED error, even though it is a better fit
for all of the messages related to options that are unsupported
due to the version of qemu in use rather than due to a user's
XML or .conf file choice. Suggested by Osier Yang.
* src/qemu/qemu_monitor.c (qemuMonitorSendFileHandle)
(qemuMonitorAddHostNetwork, qemuMonitorRemoveHostNetwork)
(qemuMonitorAttachDrive, qemuMonitorDiskSnapshot)
(qemuMonitorDriveMirror, qemuMonitorTransaction)
(qemuMonitorBlockCommit, qemuMonitorDrivePivot)
(qemuMonitorBlockJob, qemuMonitorSystemWakeup)
(qemuMonitorGetVersion, qemuMonitorGetMachines)
(qemuMonitorGetCPUDefinitions, qemuMonitorGetCommands)
(qemuMonitorGetEvents, qemuMonitorGetKVMState)
(qemuMonitorGetObjectTypes, qemuMonitorGetObjectProps)
(qemuMonitorGetTargetArch): Use better error category.
2012-12-04 20:24:40 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
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
|
|
|
_("JSON monitor should be using AddDrive"));
|
Properly support SCSI drive hotplug
The current SCSI hotplug support attaches a brand new SCSI controller
for every disk. This is broken because the semantics differ from those
used when starting the VM initially. In the latter case, each SCSI
controller is filled before a new one is added.
If the user specifies an high drive index (sdazz) then at initial
startup, many intermediate SCSI controllers may be added with no
drives.
This patch changes SCSI hotplug so that it exactly matches the
behaviour of initial startup. First the SCSI controller number is
determined for the drive to be hotplugged. If any controller upto
and including that controller number is not yet present, it is
attached. Then finally the drive is attached to the last controller.
NB, this breaks SCSI hotunplug, because there is no 'drive_del'
command in current QEMU. Previous SCSI hotunplug was broken in
any case because it was unplugging the entire controller, not
just the drive in question.
A future QEMU will allow proper SCSI hotunplug of a drive.
This patch is derived from work done by Wolfgang Mauerer on disk
controllers.
* src/qemu/qemu_driver.c: Fix SCSI hotplug to add a drive to
the correct controller, instead of just attaching a new
controller.
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c, src/qemu/qemu_monitor_json.h,
src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h: Add
support for 'drive_add' command
2009-12-09 17:57:09 +00:00
|
|
|
else
|
|
|
|
ret = qemuMonitorTextAttachDrive(mon, drivestr, controllerAddr, driveAddr);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
Detect PCI addresses at QEMU startup
Hotunplug of devices requires that we know their PCI address. Even
hotplug of SCSI drives, required that we know the PCI address of
the SCSI controller to attach the drive to. We can find this out
by running 'info pci' and then correlating the vendor/product IDs
with the devices we booted with.
Although this approach is somewhat fragile, it is the only viable
option with QEMU < 0.12, since there is no way for libvirto set
explicit PCI addresses when creating devices in the first place.
For QEMU > 0.12, this code will not be used.
* src/qemu/qemu_driver.c: Assign all dynamic PCI addresses on
startup of QEMU VM, matching vendor/product IDs
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c, src/qemu/qemu_monitor_json.h,
src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h: Add
API for fetching PCI device address mapping
2009-12-09 21:59:04 +00:00
|
|
|
|
|
|
|
int qemuMonitorGetAllPCIAddresses(qemuMonitorPtr mon,
|
|
|
|
qemuMonitorPCIAddress **addrs)
|
|
|
|
{
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p addrs=%p", mon, addrs);
|
Detect PCI addresses at QEMU startup
Hotunplug of devices requires that we know their PCI address. Even
hotplug of SCSI drives, required that we know the PCI address of
the SCSI controller to attach the drive to. We can find this out
by running 'info pci' and then correlating the vendor/product IDs
with the devices we booted with.
Although this approach is somewhat fragile, it is the only viable
option with QEMU < 0.12, since there is no way for libvirto set
explicit PCI addresses when creating devices in the first place.
For QEMU > 0.12, this code will not be used.
* src/qemu/qemu_driver.c: Assign all dynamic PCI addresses on
startup of QEMU VM, matching vendor/product IDs
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c, src/qemu/qemu_monitor_json.h,
src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h: Add
API for fetching PCI device address mapping
2009-12-09 21:59:04 +00:00
|
|
|
int ret;
|
|
|
|
|
2010-05-17 11:43:36 +00:00
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
Detect PCI addresses at QEMU startup
Hotunplug of devices requires that we know their PCI address. Even
hotplug of SCSI drives, required that we know the PCI address of
the SCSI controller to attach the drive to. We can find this out
by running 'info pci' and then correlating the vendor/product IDs
with the devices we booted with.
Although this approach is somewhat fragile, it is the only viable
option with QEMU < 0.12, since there is no way for libvirto set
explicit PCI addresses when creating devices in the first place.
For QEMU > 0.12, this code will not be used.
* src/qemu/qemu_driver.c: Assign all dynamic PCI addresses on
startup of QEMU VM, matching vendor/product IDs
* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h,
src/qemu/qemu_monitor_json.c, src/qemu/qemu_monitor_json.h,
src/qemu/qemu_monitor_text.c, src/qemu/qemu_monitor_text.h: Add
API for fetching PCI device address mapping
2009-12-09 21:59:04 +00:00
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONGetAllPCIAddresses(mon, addrs);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextGetAllPCIAddresses(mon, addrs);
|
|
|
|
return ret;
|
|
|
|
}
|
2010-01-26 15:34:46 +00:00
|
|
|
|
2010-12-08 21:30:12 +00:00
|
|
|
int qemuMonitorDriveDel(qemuMonitorPtr mon,
|
|
|
|
const char *drivestr)
|
2010-10-22 14:14:22 +00:00
|
|
|
{
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p drivestr=%s", mon, drivestr);
|
2010-10-22 14:14:22 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-10-22 14:14:22 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mon->json)
|
2010-12-08 21:30:12 +00:00
|
|
|
ret = qemuMonitorJSONDriveDel(mon, drivestr);
|
2010-10-22 14:14:22 +00:00
|
|
|
else
|
2010-12-08 21:30:12 +00:00
|
|
|
ret = qemuMonitorTextDriveDel(mon, drivestr);
|
2010-10-22 14:14:22 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-03-02 08:40:51 +00:00
|
|
|
int qemuMonitorDelDevice(qemuMonitorPtr mon,
|
2010-04-14 14:36:42 +00:00
|
|
|
const char *devalias)
|
2010-03-02 08:40:51 +00:00
|
|
|
{
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p devalias=%s", mon, devalias);
|
2010-03-02 08:40:51 +00:00
|
|
|
int ret;
|
|
|
|
|
2010-05-17 11:43:36 +00:00
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-03-02 08:40:51 +00:00
|
|
|
if (mon->json)
|
2010-04-14 14:36:42 +00:00
|
|
|
ret = qemuMonitorJSONDelDevice(mon, devalias);
|
2010-03-02 08:40:51 +00:00
|
|
|
else
|
2010-04-14 14:36:42 +00:00
|
|
|
ret = qemuMonitorTextDelDevice(mon, devalias);
|
2010-03-02 08:40:51 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-01-26 15:34:46 +00:00
|
|
|
|
2011-03-15 23:10:16 +00:00
|
|
|
int qemuMonitorAddDeviceWithFd(qemuMonitorPtr mon,
|
|
|
|
const char *devicestr,
|
|
|
|
int fd,
|
|
|
|
const char *fdname)
|
2010-01-26 15:34:46 +00:00
|
|
|
{
|
2011-03-15 23:10:16 +00:00
|
|
|
VIR_DEBUG("mon=%p device=%s fd=%d fdname=%s", mon, devicestr, fd,
|
|
|
|
NULLSTR(fdname));
|
2010-01-26 15:34:46 +00:00
|
|
|
int ret;
|
|
|
|
|
2010-05-17 11:43:36 +00:00
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-03-15 23:10:16 +00:00
|
|
|
if (fd >= 0 && qemuMonitorSendFileHandle(mon, fdname, fd) < 0)
|
|
|
|
return -1;
|
|
|
|
|
2010-01-26 15:34:46 +00:00
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONAddDevice(mon, devicestr);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextAddDevice(mon, devicestr);
|
2011-03-15 23:10:16 +00:00
|
|
|
|
|
|
|
if (ret < 0 && fd >= 0) {
|
|
|
|
if (qemuMonitorCloseFileHandle(mon, fdname) < 0)
|
|
|
|
VIR_WARN("failed to close device handle '%s'", fdname);
|
|
|
|
}
|
|
|
|
|
2010-01-26 15:34:46 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-03-15 23:10:16 +00:00
|
|
|
int qemuMonitorAddDevice(qemuMonitorPtr mon,
|
|
|
|
const char *devicestr)
|
|
|
|
{
|
|
|
|
return qemuMonitorAddDeviceWithFd(mon, devicestr, -1, NULL);
|
|
|
|
}
|
|
|
|
|
2010-01-26 15:34:46 +00:00
|
|
|
int qemuMonitorAddDrive(qemuMonitorPtr mon,
|
|
|
|
const char *drivestr)
|
|
|
|
{
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p drive=%s", mon, drivestr);
|
2010-01-26 15:34:46 +00:00
|
|
|
int ret;
|
|
|
|
|
2010-05-17 11:43:36 +00:00
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-01-26 15:34:46 +00:00
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONAddDrive(mon, drivestr);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextAddDrive(mon, drivestr);
|
|
|
|
return ret;
|
|
|
|
}
|
2010-02-11 14:28:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorSetDrivePassphrase(qemuMonitorPtr mon,
|
|
|
|
const char *alias,
|
|
|
|
const char *passphrase)
|
|
|
|
{
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p alias=%s passphrase=%p(value hidden)", mon, alias, passphrase);
|
2010-02-11 14:28:16 +00:00
|
|
|
int ret;
|
|
|
|
|
2010-05-17 11:43:36 +00:00
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-02-11 14:28:16 +00:00
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONSetDrivePassphrase(mon, alias, passphrase);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextSetDrivePassphrase(mon, alias, passphrase);
|
|
|
|
return ret;
|
|
|
|
}
|
2010-04-02 14:10:37 +00:00
|
|
|
|
|
|
|
int qemuMonitorCreateSnapshot(qemuMonitorPtr mon, const char *name)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p, name=%s",mon,name);
|
2010-04-02 14:10:37 +00:00
|
|
|
|
2010-05-17 11:43:36 +00:00
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-04-02 14:10:37 +00:00
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONCreateSnapshot(mon, name);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextCreateSnapshot(mon, name);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int qemuMonitorLoadSnapshot(qemuMonitorPtr mon, const char *name)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p, name=%s",mon,name);
|
2010-04-02 14:10:37 +00:00
|
|
|
|
2010-05-17 11:43:36 +00:00
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-04-02 14:10:37 +00:00
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONLoadSnapshot(mon, name);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextLoadSnapshot(mon, name);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int qemuMonitorDeleteSnapshot(qemuMonitorPtr mon, const char *name)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p, name=%s",mon,name);
|
2010-04-02 14:10:37 +00:00
|
|
|
|
2010-05-17 11:43:36 +00:00
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2010-05-17 11:43:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-04-02 14:10:37 +00:00
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONDeleteSnapshot(mon, name);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextDeleteSnapshot(mon, name);
|
|
|
|
return ret;
|
|
|
|
}
|
2010-04-17 02:12:45 +00:00
|
|
|
|
2011-08-15 23:25:54 +00:00
|
|
|
/* Use the snapshot_blkdev command to convert the existing file for
|
|
|
|
* device into a read-only backing file of a new qcow2 image located
|
|
|
|
* at file. */
|
|
|
|
int
|
2012-03-17 04:17:28 +00:00
|
|
|
qemuMonitorDiskSnapshot(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-12-03 21:25:30 +00:00
|
|
|
int ret = -1;
|
2011-08-15 23:25:54 +00:00
|
|
|
|
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
|
|
|
VIR_DEBUG("mon=%p, actions=%p, device=%s, file=%s, format=%s, reuse=%d",
|
|
|
|
mon, actions, device, file, format, reuse);
|
2011-08-15 23:25:54 +00:00
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2011-08-15 23:25:54 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-12-03 21:25:30 +00:00
|
|
|
if (mon->json)
|
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
|
|
|
ret = qemuMonitorJSONDiskSnapshot(mon, actions, device, file, format,
|
|
|
|
reuse);
|
2012-12-03 21:25:30 +00:00
|
|
|
else
|
qemu: improve error for failed JSON commands
Only one error in qemu_monitor was already using the relatively
new OPERATION_UNSUPPORTED error, even though it is a better fit
for all of the messages related to options that are unsupported
due to the version of qemu in use rather than due to a user's
XML or .conf file choice. Suggested by Osier Yang.
* src/qemu/qemu_monitor.c (qemuMonitorSendFileHandle)
(qemuMonitorAddHostNetwork, qemuMonitorRemoveHostNetwork)
(qemuMonitorAttachDrive, qemuMonitorDiskSnapshot)
(qemuMonitorDriveMirror, qemuMonitorTransaction)
(qemuMonitorBlockCommit, qemuMonitorDrivePivot)
(qemuMonitorBlockJob, qemuMonitorSystemWakeup)
(qemuMonitorGetVersion, qemuMonitorGetMachines)
(qemuMonitorGetCPUDefinitions, qemuMonitorGetCommands)
(qemuMonitorGetEvents, qemuMonitorGetKVMState)
(qemuMonitorGetObjectTypes, qemuMonitorGetObjectProps)
(qemuMonitorGetTargetArch): Use better error category.
2012-12-04 20:24:40 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
2012-12-03 21:25:30 +00:00
|
|
|
_("disk snapshot requires JSON monitor"));
|
2012-03-17 04:17:28 +00:00
|
|
|
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
|
|
|
/* Start a drive-mirror block job. bandwidth is in MiB/sec. */
|
|
|
|
int
|
|
|
|
qemuMonitorDriveMirror(qemuMonitorPtr mon,
|
|
|
|
const char *device, const char *file,
|
|
|
|
const char *format, unsigned long bandwidth,
|
|
|
|
unsigned int flags)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
unsigned long long speed;
|
|
|
|
|
|
|
|
VIR_DEBUG("mon=%p, device=%s, file=%s, format=%s, bandwidth=%ld, "
|
|
|
|
"flags=%x",
|
|
|
|
mon, device, file, NULLSTR(format), bandwidth, flags);
|
|
|
|
|
2013-04-03 08:36:03 +00:00
|
|
|
/* Convert bandwidth MiB to bytes - unfortunately the JSON QMP protocol is
|
|
|
|
* limited to LLONG_MAX also for unsigned values */
|
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 = bandwidth;
|
2013-04-03 08:36:03 +00:00
|
|
|
if (speed > LLONG_MAX >> 20) {
|
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
|
|
|
virReportError(VIR_ERR_OVERFLOW,
|
|
|
|
_("bandwidth must be less than %llu"),
|
2013-04-03 08:36:03 +00:00
|
|
|
LLONG_MAX >> 20);
|
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
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
speed <<= 20;
|
|
|
|
|
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONDriveMirror(mon, device, file, format, speed,
|
|
|
|
flags);
|
|
|
|
else
|
qemu: improve error for failed JSON commands
Only one error in qemu_monitor was already using the relatively
new OPERATION_UNSUPPORTED error, even though it is a better fit
for all of the messages related to options that are unsupported
due to the version of qemu in use rather than due to a user's
XML or .conf file choice. Suggested by Osier Yang.
* src/qemu/qemu_monitor.c (qemuMonitorSendFileHandle)
(qemuMonitorAddHostNetwork, qemuMonitorRemoveHostNetwork)
(qemuMonitorAttachDrive, qemuMonitorDiskSnapshot)
(qemuMonitorDriveMirror, qemuMonitorTransaction)
(qemuMonitorBlockCommit, qemuMonitorDrivePivot)
(qemuMonitorBlockJob, qemuMonitorSystemWakeup)
(qemuMonitorGetVersion, qemuMonitorGetMachines)
(qemuMonitorGetCPUDefinitions, qemuMonitorGetCommands)
(qemuMonitorGetEvents, qemuMonitorGetKVMState)
(qemuMonitorGetObjectTypes, qemuMonitorGetObjectProps)
(qemuMonitorGetTargetArch): Use better error category.
2012-12-04 20:24:40 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
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
|
|
|
_("drive-mirror requires JSON monitor"));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-03-17 04:17:28 +00:00
|
|
|
/* Use the transaction QMP command to run atomic snapshot commands. */
|
|
|
|
int
|
|
|
|
qemuMonitorTransaction(qemuMonitorPtr mon, virJSONValuePtr actions)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
VIR_DEBUG("mon=%p, actions=%p", mon, actions);
|
|
|
|
|
2011-08-15 23:25:54 +00:00
|
|
|
if (mon->json)
|
2012-03-17 04:17:28 +00:00
|
|
|
ret = qemuMonitorJSONTransaction(mon, actions);
|
2011-08-15 23:25:54 +00:00
|
|
|
else
|
qemu: improve error for failed JSON commands
Only one error in qemu_monitor was already using the relatively
new OPERATION_UNSUPPORTED error, even though it is a better fit
for all of the messages related to options that are unsupported
due to the version of qemu in use rather than due to a user's
XML or .conf file choice. Suggested by Osier Yang.
* src/qemu/qemu_monitor.c (qemuMonitorSendFileHandle)
(qemuMonitorAddHostNetwork, qemuMonitorRemoveHostNetwork)
(qemuMonitorAttachDrive, qemuMonitorDiskSnapshot)
(qemuMonitorDriveMirror, qemuMonitorTransaction)
(qemuMonitorBlockCommit, qemuMonitorDrivePivot)
(qemuMonitorBlockJob, qemuMonitorSystemWakeup)
(qemuMonitorGetVersion, qemuMonitorGetMachines)
(qemuMonitorGetCPUDefinitions, qemuMonitorGetCommands)
(qemuMonitorGetEvents, qemuMonitorGetKVMState)
(qemuMonitorGetObjectTypes, qemuMonitorGetObjectProps)
(qemuMonitorGetTargetArch): Use better error category.
2012-12-04 20:24:40 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
2012-07-18 15:22:03 +00:00
|
|
|
_("transaction requires JSON monitor"));
|
2011-08-15 23:25:54 +00:00
|
|
|
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
|
|
|
/* Start a block-commit block job. bandwidth is in MiB/sec. */
|
2012-10-03 21:13:21 +00:00
|
|
|
int
|
|
|
|
qemuMonitorBlockCommit(qemuMonitorPtr mon, const char *device,
|
|
|
|
const char *top, const char *base,
|
|
|
|
unsigned long bandwidth)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
unsigned long long speed;
|
|
|
|
|
|
|
|
VIR_DEBUG("mon=%p, device=%s, top=%s, base=%s, bandwidth=%ld",
|
|
|
|
mon, device, NULLSTR(top), NULLSTR(base), bandwidth);
|
|
|
|
|
2013-04-03 08:36:03 +00:00
|
|
|
/* Convert bandwidth MiB to bytes - unfortunately the JSON QMP protocol is
|
|
|
|
* limited to LLONG_MAX also for unsigned values */
|
2012-10-03 21:13:21 +00:00
|
|
|
speed = bandwidth;
|
2013-04-03 08:36:03 +00:00
|
|
|
if (speed > LLONG_MAX >> 20) {
|
2012-10-03 21:13:21 +00:00
|
|
|
virReportError(VIR_ERR_OVERFLOW,
|
|
|
|
_("bandwidth must be less than %llu"),
|
2013-04-03 08:36:03 +00:00
|
|
|
LLONG_MAX >> 20);
|
2012-10-03 21:13:21 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
speed <<= 20;
|
|
|
|
|
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONBlockCommit(mon, device, top, base, speed);
|
|
|
|
else
|
qemu: improve error for failed JSON commands
Only one error in qemu_monitor was already using the relatively
new OPERATION_UNSUPPORTED error, even though it is a better fit
for all of the messages related to options that are unsupported
due to the version of qemu in use rather than due to a user's
XML or .conf file choice. Suggested by Osier Yang.
* src/qemu/qemu_monitor.c (qemuMonitorSendFileHandle)
(qemuMonitorAddHostNetwork, qemuMonitorRemoveHostNetwork)
(qemuMonitorAttachDrive, qemuMonitorDiskSnapshot)
(qemuMonitorDriveMirror, qemuMonitorTransaction)
(qemuMonitorBlockCommit, qemuMonitorDrivePivot)
(qemuMonitorBlockJob, qemuMonitorSystemWakeup)
(qemuMonitorGetVersion, qemuMonitorGetMachines)
(qemuMonitorGetCPUDefinitions, qemuMonitorGetCommands)
(qemuMonitorGetEvents, qemuMonitorGetKVMState)
(qemuMonitorGetObjectTypes, qemuMonitorGetObjectProps)
(qemuMonitorGetTargetArch): Use better error category.
2012-12-04 20:24:40 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
2012-10-03 21:13:21 +00:00
|
|
|
_("block-commit requires JSON monitor"));
|
|
|
|
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
|
|
|
/* Use the block-job-complete monitor command to pivot a block copy
|
|
|
|
* job. */
|
|
|
|
int
|
|
|
|
qemuMonitorDrivePivot(qemuMonitorPtr mon, const char *device,
|
|
|
|
const char *file, const char *format)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
VIR_DEBUG("mon=%p, device=%s, file=%s, format=%s",
|
|
|
|
mon, device, file, NULLSTR(format));
|
|
|
|
|
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONDrivePivot(mon, device, file, format);
|
|
|
|
else
|
qemu: improve error for failed JSON commands
Only one error in qemu_monitor was already using the relatively
new OPERATION_UNSUPPORTED error, even though it is a better fit
for all of the messages related to options that are unsupported
due to the version of qemu in use rather than due to a user's
XML or .conf file choice. Suggested by Osier Yang.
* src/qemu/qemu_monitor.c (qemuMonitorSendFileHandle)
(qemuMonitorAddHostNetwork, qemuMonitorRemoveHostNetwork)
(qemuMonitorAttachDrive, qemuMonitorDiskSnapshot)
(qemuMonitorDriveMirror, qemuMonitorTransaction)
(qemuMonitorBlockCommit, qemuMonitorDrivePivot)
(qemuMonitorBlockJob, qemuMonitorSystemWakeup)
(qemuMonitorGetVersion, qemuMonitorGetMachines)
(qemuMonitorGetCPUDefinitions, qemuMonitorGetCommands)
(qemuMonitorGetEvents, qemuMonitorGetKVMState)
(qemuMonitorGetObjectTypes, qemuMonitorGetObjectProps)
(qemuMonitorGetTargetArch): Use better error category.
2012-12-04 20:24:40 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
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
|
|
|
_("drive pivot requires JSON monitor"));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-02-02 15:37:10 +00:00
|
|
|
int qemuMonitorArbitraryCommand(qemuMonitorPtr mon,
|
|
|
|
const char *cmd,
|
|
|
|
char **reply,
|
|
|
|
bool hmp)
|
2010-04-17 02:12:45 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p, cmd=%s, reply=%p, hmp=%d", mon, cmd, reply, hmp);
|
2010-04-17 02:12:45 +00:00
|
|
|
|
|
|
|
if (mon->json)
|
2011-02-02 15:37:10 +00:00
|
|
|
ret = qemuMonitorJSONArbitraryCommand(mon, cmd, reply, hmp);
|
2010-04-17 02:12:45 +00:00
|
|
|
else
|
|
|
|
ret = qemuMonitorTextArbitraryCommand(mon, cmd, reply);
|
|
|
|
return ret;
|
|
|
|
}
|
2011-05-10 08:26:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorInjectNMI(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
VIR_DEBUG("mon=%p", mon);
|
|
|
|
|
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONInjectNMI(mon);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextInjectNMI(mon);
|
|
|
|
return ret;
|
|
|
|
}
|
2011-04-01 06:23:58 +00:00
|
|
|
|
2011-07-21 07:55:56 +00:00
|
|
|
int qemuMonitorSendKey(qemuMonitorPtr mon,
|
|
|
|
unsigned int holdtime,
|
|
|
|
unsigned int *keycodes,
|
|
|
|
unsigned int nkeycodes)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
VIR_DEBUG("mon=%p, holdtime=%u, nkeycodes=%u",
|
|
|
|
mon, holdtime, nkeycodes);
|
|
|
|
|
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONSendKey(mon, holdtime, keycodes, nkeycodes);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextSendKey(mon, holdtime, keycodes, nkeycodes);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-04-01 06:23:58 +00:00
|
|
|
int qemuMonitorScreendump(qemuMonitorPtr mon,
|
|
|
|
const char *file)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
VIR_DEBUG("mon=%p, file=%s", mon, file);
|
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG,"%s",
|
|
|
|
_("monitor must not be NULL"));
|
2011-04-01 06:23:58 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONScreendump(mon, file);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextScreendump(mon, file);
|
|
|
|
return ret;
|
|
|
|
}
|
2011-07-22 05:39:37 +00:00
|
|
|
|
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
|
|
|
/* bandwidth is in MiB/sec */
|
2011-07-22 05:39:37 +00:00
|
|
|
int qemuMonitorBlockJob(qemuMonitorPtr mon,
|
|
|
|
const char *device,
|
2012-02-18 16:20:01 +00:00
|
|
|
const char *base,
|
2011-07-22 05:39:37 +00:00
|
|
|
unsigned long bandwidth,
|
|
|
|
virDomainBlockJobInfoPtr info,
|
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
|
|
|
qemuMonitorBlockJobCmd mode,
|
|
|
|
bool modern)
|
2011-07-22 05:39:37 +00:00
|
|
|
{
|
2012-02-17 21:55:35 +00:00
|
|
|
int ret = -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
|
|
|
unsigned long long speed;
|
2011-07-22 05:39:37 +00:00
|
|
|
|
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
|
|
|
VIR_DEBUG("mon=%p, device=%s, base=%s, bandwidth=%luM, info=%p, mode=%o, "
|
|
|
|
"modern=%d", mon, device, NULLSTR(base), bandwidth, info, mode,
|
|
|
|
modern);
|
|
|
|
|
2013-04-03 08:36:03 +00:00
|
|
|
/* Convert bandwidth MiB to bytes - unfortunately the JSON QMP protocol is
|
|
|
|
* limited to LLONG_MAX also for unsigned values */
|
2012-05-12 13:24:08 +00:00
|
|
|
speed = bandwidth;
|
2013-04-03 08:36:03 +00:00
|
|
|
if (speed > LLONG_MAX >> 20) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_OVERFLOW,
|
|
|
|
_("bandwidth must be less than %llu"),
|
2013-04-03 08:36:03 +00:00
|
|
|
LLONG_MAX >> 20);
|
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
|
|
|
return -1;
|
|
|
|
}
|
2012-05-12 13:24:08 +00:00
|
|
|
speed <<= 20;
|
2011-07-22 05:39:37 +00:00
|
|
|
|
|
|
|
if (mon->json)
|
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
|
|
|
ret = qemuMonitorJSONBlockJob(mon, device, base, speed, info, mode,
|
|
|
|
modern);
|
2011-07-22 05:39:37 +00:00
|
|
|
else
|
qemu: improve error for failed JSON commands
Only one error in qemu_monitor was already using the relatively
new OPERATION_UNSUPPORTED error, even though it is a better fit
for all of the messages related to options that are unsupported
due to the version of qemu in use rather than due to a user's
XML or .conf file choice. Suggested by Osier Yang.
* src/qemu/qemu_monitor.c (qemuMonitorSendFileHandle)
(qemuMonitorAddHostNetwork, qemuMonitorRemoveHostNetwork)
(qemuMonitorAttachDrive, qemuMonitorDiskSnapshot)
(qemuMonitorDriveMirror, qemuMonitorTransaction)
(qemuMonitorBlockCommit, qemuMonitorDrivePivot)
(qemuMonitorBlockJob, qemuMonitorSystemWakeup)
(qemuMonitorGetVersion, qemuMonitorGetMachines)
(qemuMonitorGetCPUDefinitions, qemuMonitorGetCommands)
(qemuMonitorGetEvents, qemuMonitorGetKVMState)
(qemuMonitorGetObjectTypes, qemuMonitorGetObjectProps)
(qemuMonitorGetTargetArch): Use better error category.
2012-12-04 20:24:40 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
2012-07-18 15:22:03 +00:00
|
|
|
_("block jobs require JSON monitor"));
|
2011-07-22 05:39:37 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2011-09-27 09:42:04 +00:00
|
|
|
|
2011-11-15 09:02:45 +00:00
|
|
|
int qemuMonitorSetBlockIoThrottle(qemuMonitorPtr mon,
|
|
|
|
const char *device,
|
|
|
|
virDomainBlockIoTuneInfoPtr info)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
VIR_DEBUG("mon=%p, device=%p, info=%p", mon, device, info);
|
|
|
|
|
|
|
|
if (mon->json) {
|
|
|
|
ret = qemuMonitorJSONSetBlockIoThrottle(mon, device, info);
|
|
|
|
} else {
|
|
|
|
ret = qemuMonitorTextSetBlockIoThrottle(mon, device, info);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int qemuMonitorGetBlockIoThrottle(qemuMonitorPtr mon,
|
|
|
|
const char *device,
|
|
|
|
virDomainBlockIoTuneInfoPtr reply)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
VIR_DEBUG("mon=%p, device=%p, reply=%p", mon, device, reply);
|
|
|
|
|
|
|
|
if (mon->json) {
|
|
|
|
ret = qemuMonitorJSONGetBlockIoThrottle(mon, device, reply);
|
|
|
|
} else {
|
|
|
|
ret = qemuMonitorTextGetBlockIoThrottle(mon, device, reply);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-27 09:42:04 +00:00
|
|
|
int qemuMonitorVMStatusToPausedReason(const char *status)
|
|
|
|
{
|
|
|
|
int st;
|
|
|
|
|
|
|
|
if (!status)
|
|
|
|
return VIR_DOMAIN_PAUSED_UNKNOWN;
|
|
|
|
|
|
|
|
if ((st = qemuMonitorVMStatusTypeFromString(status)) < 0) {
|
|
|
|
VIR_WARN("Qemu reported unknown VM status: '%s'", status);
|
|
|
|
return VIR_DOMAIN_PAUSED_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ((qemuMonitorVMStatus) st) {
|
|
|
|
case QEMU_MONITOR_VM_STATUS_DEBUG:
|
|
|
|
case QEMU_MONITOR_VM_STATUS_INTERNAL_ERROR:
|
|
|
|
case QEMU_MONITOR_VM_STATUS_RESTORE_VM:
|
|
|
|
return VIR_DOMAIN_PAUSED_UNKNOWN;
|
|
|
|
|
|
|
|
case QEMU_MONITOR_VM_STATUS_INMIGRATE:
|
|
|
|
case QEMU_MONITOR_VM_STATUS_POSTMIGRATE:
|
|
|
|
case QEMU_MONITOR_VM_STATUS_FINISH_MIGRATE:
|
|
|
|
return VIR_DOMAIN_PAUSED_MIGRATION;
|
|
|
|
|
|
|
|
case QEMU_MONITOR_VM_STATUS_IO_ERROR:
|
|
|
|
return VIR_DOMAIN_PAUSED_IOERROR;
|
|
|
|
|
|
|
|
case QEMU_MONITOR_VM_STATUS_PAUSED:
|
|
|
|
case QEMU_MONITOR_VM_STATUS_PRELAUNCH:
|
|
|
|
return VIR_DOMAIN_PAUSED_USER;
|
|
|
|
|
|
|
|
case QEMU_MONITOR_VM_STATUS_RUNNING:
|
|
|
|
VIR_WARN("Qemu reports the guest is paused but status is 'running'");
|
|
|
|
return VIR_DOMAIN_PAUSED_UNKNOWN;
|
|
|
|
|
|
|
|
case QEMU_MONITOR_VM_STATUS_SAVE_VM:
|
|
|
|
return VIR_DOMAIN_PAUSED_SAVE;
|
|
|
|
|
|
|
|
case QEMU_MONITOR_VM_STATUS_SHUTDOWN:
|
|
|
|
return VIR_DOMAIN_PAUSED_SHUTTING_DOWN;
|
|
|
|
|
|
|
|
case QEMU_MONITOR_VM_STATUS_WATCHDOG:
|
|
|
|
return VIR_DOMAIN_PAUSED_WATCHDOG;
|
|
|
|
|
2013-06-07 10:23:34 +00:00
|
|
|
case QEMU_MONITOR_VM_STATUS_GUEST_PANICKED:
|
2013-07-29 16:54:57 +00:00
|
|
|
return VIR_DOMAIN_PAUSED_CRASHED;
|
2013-06-07 10:23:34 +00:00
|
|
|
|
2011-09-27 09:42:04 +00:00
|
|
|
/* unreachable from this point on */
|
|
|
|
case QEMU_MONITOR_VM_STATUS_LAST:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
return VIR_DOMAIN_PAUSED_UNKNOWN;
|
|
|
|
}
|
2011-10-21 08:00:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorOpenGraphics(qemuMonitorPtr mon,
|
|
|
|
const char *protocol,
|
|
|
|
int fd,
|
|
|
|
const char *fdname,
|
|
|
|
bool skipauth)
|
|
|
|
{
|
|
|
|
VIR_DEBUG("mon=%p protocol=%s fd=%d fdname=%s skipauth=%d",
|
|
|
|
mon, protocol, fd, NULLSTR(fdname), skipauth);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2011-10-21 08:00:13 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (qemuMonitorSendFileHandle(mon, fdname, fd) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONOpenGraphics(mon, protocol, fdname, skipauth);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextOpenGraphics(mon, protocol, fdname, skipauth);
|
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
if (qemuMonitorCloseFileHandle(mon, fdname) < 0)
|
|
|
|
VIR_WARN("failed to close device handle '%s'", fdname);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2012-02-10 12:33:52 +00:00
|
|
|
|
|
|
|
int qemuMonitorSystemWakeup(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
VIR_DEBUG("mon=%p", mon);
|
|
|
|
|
|
|
|
if (!mon) {
|
2012-07-18 15:22:03 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
2012-02-10 12:33:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mon->json) {
|
qemu: improve error for failed JSON commands
Only one error in qemu_monitor was already using the relatively
new OPERATION_UNSUPPORTED error, even though it is a better fit
for all of the messages related to options that are unsupported
due to the version of qemu in use rather than due to a user's
XML or .conf file choice. Suggested by Osier Yang.
* src/qemu/qemu_monitor.c (qemuMonitorSendFileHandle)
(qemuMonitorAddHostNetwork, qemuMonitorRemoveHostNetwork)
(qemuMonitorAttachDrive, qemuMonitorDiskSnapshot)
(qemuMonitorDriveMirror, qemuMonitorTransaction)
(qemuMonitorBlockCommit, qemuMonitorDrivePivot)
(qemuMonitorBlockJob, qemuMonitorSystemWakeup)
(qemuMonitorGetVersion, qemuMonitorGetMachines)
(qemuMonitorGetCPUDefinitions, qemuMonitorGetCommands)
(qemuMonitorGetEvents, qemuMonitorGetKVMState)
(qemuMonitorGetObjectTypes, qemuMonitorGetObjectProps)
(qemuMonitorGetTargetArch): Use better error category.
2012-12-04 20:24:40 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
2012-07-18 15:22:03 +00:00
|
|
|
_("JSON monitor is required"));
|
2012-02-10 12:33:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return qemuMonitorJSONSystemWakeup(mon);
|
|
|
|
}
|
2012-08-15 14:04:09 +00:00
|
|
|
|
|
|
|
int qemuMonitorGetVersion(qemuMonitorPtr mon,
|
|
|
|
int *major,
|
|
|
|
int *minor,
|
|
|
|
int *micro,
|
|
|
|
char **package)
|
|
|
|
{
|
|
|
|
VIR_DEBUG("mon=%p major=%p minor=%p micro=%p package=%p",
|
|
|
|
mon, major, minor, micro, package);
|
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mon->json) {
|
qemu: improve error for failed JSON commands
Only one error in qemu_monitor was already using the relatively
new OPERATION_UNSUPPORTED error, even though it is a better fit
for all of the messages related to options that are unsupported
due to the version of qemu in use rather than due to a user's
XML or .conf file choice. Suggested by Osier Yang.
* src/qemu/qemu_monitor.c (qemuMonitorSendFileHandle)
(qemuMonitorAddHostNetwork, qemuMonitorRemoveHostNetwork)
(qemuMonitorAttachDrive, qemuMonitorDiskSnapshot)
(qemuMonitorDriveMirror, qemuMonitorTransaction)
(qemuMonitorBlockCommit, qemuMonitorDrivePivot)
(qemuMonitorBlockJob, qemuMonitorSystemWakeup)
(qemuMonitorGetVersion, qemuMonitorGetMachines)
(qemuMonitorGetCPUDefinitions, qemuMonitorGetCommands)
(qemuMonitorGetEvents, qemuMonitorGetKVMState)
(qemuMonitorGetObjectTypes, qemuMonitorGetObjectProps)
(qemuMonitorGetTargetArch): Use better error category.
2012-12-04 20:24:40 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
2012-08-15 14:04:09 +00:00
|
|
|
_("JSON monitor is required"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return qemuMonitorJSONGetVersion(mon, major, minor, micro, package);
|
|
|
|
}
|
2012-08-15 15:18:41 +00:00
|
|
|
|
|
|
|
int qemuMonitorGetMachines(qemuMonitorPtr mon,
|
|
|
|
qemuMonitorMachineInfoPtr **machines)
|
|
|
|
{
|
|
|
|
VIR_DEBUG("mon=%p machines=%p",
|
|
|
|
mon, machines);
|
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mon->json) {
|
qemu: improve error for failed JSON commands
Only one error in qemu_monitor was already using the relatively
new OPERATION_UNSUPPORTED error, even though it is a better fit
for all of the messages related to options that are unsupported
due to the version of qemu in use rather than due to a user's
XML or .conf file choice. Suggested by Osier Yang.
* src/qemu/qemu_monitor.c (qemuMonitorSendFileHandle)
(qemuMonitorAddHostNetwork, qemuMonitorRemoveHostNetwork)
(qemuMonitorAttachDrive, qemuMonitorDiskSnapshot)
(qemuMonitorDriveMirror, qemuMonitorTransaction)
(qemuMonitorBlockCommit, qemuMonitorDrivePivot)
(qemuMonitorBlockJob, qemuMonitorSystemWakeup)
(qemuMonitorGetVersion, qemuMonitorGetMachines)
(qemuMonitorGetCPUDefinitions, qemuMonitorGetCommands)
(qemuMonitorGetEvents, qemuMonitorGetKVMState)
(qemuMonitorGetObjectTypes, qemuMonitorGetObjectProps)
(qemuMonitorGetTargetArch): Use better error category.
2012-12-04 20:24:40 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
2012-08-15 15:18:41 +00:00
|
|
|
_("JSON monitor is required"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return qemuMonitorJSONGetMachines(mon, machines);
|
|
|
|
}
|
|
|
|
|
|
|
|
void qemuMonitorMachineInfoFree(qemuMonitorMachineInfoPtr machine)
|
|
|
|
{
|
|
|
|
if (!machine)
|
|
|
|
return;
|
|
|
|
VIR_FREE(machine->name);
|
|
|
|
VIR_FREE(machine->alias);
|
|
|
|
VIR_FREE(machine);
|
|
|
|
}
|
2012-08-20 14:58:20 +00:00
|
|
|
|
|
|
|
int qemuMonitorGetCPUDefinitions(qemuMonitorPtr mon,
|
|
|
|
char ***cpus)
|
|
|
|
{
|
|
|
|
VIR_DEBUG("mon=%p cpus=%p",
|
|
|
|
mon, cpus);
|
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mon->json) {
|
qemu: improve error for failed JSON commands
Only one error in qemu_monitor was already using the relatively
new OPERATION_UNSUPPORTED error, even though it is a better fit
for all of the messages related to options that are unsupported
due to the version of qemu in use rather than due to a user's
XML or .conf file choice. Suggested by Osier Yang.
* src/qemu/qemu_monitor.c (qemuMonitorSendFileHandle)
(qemuMonitorAddHostNetwork, qemuMonitorRemoveHostNetwork)
(qemuMonitorAttachDrive, qemuMonitorDiskSnapshot)
(qemuMonitorDriveMirror, qemuMonitorTransaction)
(qemuMonitorBlockCommit, qemuMonitorDrivePivot)
(qemuMonitorBlockJob, qemuMonitorSystemWakeup)
(qemuMonitorGetVersion, qemuMonitorGetMachines)
(qemuMonitorGetCPUDefinitions, qemuMonitorGetCommands)
(qemuMonitorGetEvents, qemuMonitorGetKVMState)
(qemuMonitorGetObjectTypes, qemuMonitorGetObjectProps)
(qemuMonitorGetTargetArch): Use better error category.
2012-12-04 20:24:40 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
2012-08-20 14:58:20 +00:00
|
|
|
_("JSON monitor is required"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return qemuMonitorJSONGetCPUDefinitions(mon, cpus);
|
|
|
|
}
|
2012-08-22 09:25:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorGetCommands(qemuMonitorPtr mon,
|
|
|
|
char ***commands)
|
|
|
|
{
|
|
|
|
VIR_DEBUG("mon=%p commands=%p",
|
|
|
|
mon, commands);
|
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mon->json) {
|
qemu: improve error for failed JSON commands
Only one error in qemu_monitor was already using the relatively
new OPERATION_UNSUPPORTED error, even though it is a better fit
for all of the messages related to options that are unsupported
due to the version of qemu in use rather than due to a user's
XML or .conf file choice. Suggested by Osier Yang.
* src/qemu/qemu_monitor.c (qemuMonitorSendFileHandle)
(qemuMonitorAddHostNetwork, qemuMonitorRemoveHostNetwork)
(qemuMonitorAttachDrive, qemuMonitorDiskSnapshot)
(qemuMonitorDriveMirror, qemuMonitorTransaction)
(qemuMonitorBlockCommit, qemuMonitorDrivePivot)
(qemuMonitorBlockJob, qemuMonitorSystemWakeup)
(qemuMonitorGetVersion, qemuMonitorGetMachines)
(qemuMonitorGetCPUDefinitions, qemuMonitorGetCommands)
(qemuMonitorGetEvents, qemuMonitorGetKVMState)
(qemuMonitorGetObjectTypes, qemuMonitorGetObjectProps)
(qemuMonitorGetTargetArch): Use better error category.
2012-12-04 20:24:40 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
2012-08-22 09:25:20 +00:00
|
|
|
_("JSON monitor is required"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return qemuMonitorJSONGetCommands(mon, commands);
|
|
|
|
}
|
2012-08-22 09:48:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorGetEvents(qemuMonitorPtr mon,
|
|
|
|
char ***events)
|
|
|
|
{
|
|
|
|
VIR_DEBUG("mon=%p events=%p",
|
|
|
|
mon, events);
|
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mon->json) {
|
qemu: improve error for failed JSON commands
Only one error in qemu_monitor was already using the relatively
new OPERATION_UNSUPPORTED error, even though it is a better fit
for all of the messages related to options that are unsupported
due to the version of qemu in use rather than due to a user's
XML or .conf file choice. Suggested by Osier Yang.
* src/qemu/qemu_monitor.c (qemuMonitorSendFileHandle)
(qemuMonitorAddHostNetwork, qemuMonitorRemoveHostNetwork)
(qemuMonitorAttachDrive, qemuMonitorDiskSnapshot)
(qemuMonitorDriveMirror, qemuMonitorTransaction)
(qemuMonitorBlockCommit, qemuMonitorDrivePivot)
(qemuMonitorBlockJob, qemuMonitorSystemWakeup)
(qemuMonitorGetVersion, qemuMonitorGetMachines)
(qemuMonitorGetCPUDefinitions, qemuMonitorGetCommands)
(qemuMonitorGetEvents, qemuMonitorGetKVMState)
(qemuMonitorGetObjectTypes, qemuMonitorGetObjectProps)
(qemuMonitorGetTargetArch): Use better error category.
2012-12-04 20:24:40 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
2012-08-22 09:48:41 +00:00
|
|
|
_("JSON monitor is required"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return qemuMonitorJSONGetEvents(mon, events);
|
|
|
|
}
|
2012-08-22 09:48:41 +00:00
|
|
|
|
|
|
|
|
2013-04-26 17:13:45 +00:00
|
|
|
/* Collect the parameters associated with a given command line option.
|
|
|
|
* Return count of known parameters or -1 on error. */
|
|
|
|
int
|
|
|
|
qemuMonitorGetCommandLineOptionParameters(qemuMonitorPtr mon,
|
|
|
|
const char *option,
|
|
|
|
char ***params)
|
|
|
|
{
|
|
|
|
VIR_DEBUG("mon=%p option=%s params=%p", mon, option, params);
|
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mon->json) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
|
|
|
_("JSON monitor is required"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return qemuMonitorJSONGetCommandLineOptionParameters(mon, option, params);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 qemuMonitorGetKVMState(qemuMonitorPtr mon,
|
|
|
|
bool *enabled,
|
|
|
|
bool *present)
|
|
|
|
{
|
|
|
|
VIR_DEBUG("mon=%p enabled=%p present=%p",
|
|
|
|
mon, enabled, present);
|
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mon->json) {
|
qemu: improve error for failed JSON commands
Only one error in qemu_monitor was already using the relatively
new OPERATION_UNSUPPORTED error, even though it is a better fit
for all of the messages related to options that are unsupported
due to the version of qemu in use rather than due to a user's
XML or .conf file choice. Suggested by Osier Yang.
* src/qemu/qemu_monitor.c (qemuMonitorSendFileHandle)
(qemuMonitorAddHostNetwork, qemuMonitorRemoveHostNetwork)
(qemuMonitorAttachDrive, qemuMonitorDiskSnapshot)
(qemuMonitorDriveMirror, qemuMonitorTransaction)
(qemuMonitorBlockCommit, qemuMonitorDrivePivot)
(qemuMonitorBlockJob, qemuMonitorSystemWakeup)
(qemuMonitorGetVersion, qemuMonitorGetMachines)
(qemuMonitorGetCPUDefinitions, qemuMonitorGetCommands)
(qemuMonitorGetEvents, qemuMonitorGetKVMState)
(qemuMonitorGetObjectTypes, qemuMonitorGetObjectProps)
(qemuMonitorGetTargetArch): Use better error category.
2012-12-04 20:24:40 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
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
|
|
|
_("JSON monitor is required"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return qemuMonitorJSONGetKVMState(mon, enabled, present);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-22 09:48:41 +00:00
|
|
|
int qemuMonitorGetObjectTypes(qemuMonitorPtr mon,
|
|
|
|
char ***types)
|
|
|
|
{
|
|
|
|
VIR_DEBUG("mon=%p types=%p",
|
|
|
|
mon, types);
|
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mon->json) {
|
qemu: improve error for failed JSON commands
Only one error in qemu_monitor was already using the relatively
new OPERATION_UNSUPPORTED error, even though it is a better fit
for all of the messages related to options that are unsupported
due to the version of qemu in use rather than due to a user's
XML or .conf file choice. Suggested by Osier Yang.
* src/qemu/qemu_monitor.c (qemuMonitorSendFileHandle)
(qemuMonitorAddHostNetwork, qemuMonitorRemoveHostNetwork)
(qemuMonitorAttachDrive, qemuMonitorDiskSnapshot)
(qemuMonitorDriveMirror, qemuMonitorTransaction)
(qemuMonitorBlockCommit, qemuMonitorDrivePivot)
(qemuMonitorBlockJob, qemuMonitorSystemWakeup)
(qemuMonitorGetVersion, qemuMonitorGetMachines)
(qemuMonitorGetCPUDefinitions, qemuMonitorGetCommands)
(qemuMonitorGetEvents, qemuMonitorGetKVMState)
(qemuMonitorGetObjectTypes, qemuMonitorGetObjectProps)
(qemuMonitorGetTargetArch): Use better error category.
2012-12-04 20:24:40 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
2012-08-22 09:48:41 +00:00
|
|
|
_("JSON monitor is required"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return qemuMonitorJSONGetObjectTypes(mon, types);
|
|
|
|
}
|
2012-08-22 09:48:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorGetObjectProps(qemuMonitorPtr mon,
|
|
|
|
const char *type,
|
|
|
|
char ***props)
|
|
|
|
{
|
|
|
|
VIR_DEBUG("mon=%p type=%s props=%p",
|
|
|
|
mon, type, props);
|
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mon->json) {
|
qemu: improve error for failed JSON commands
Only one error in qemu_monitor was already using the relatively
new OPERATION_UNSUPPORTED error, even though it is a better fit
for all of the messages related to options that are unsupported
due to the version of qemu in use rather than due to a user's
XML or .conf file choice. Suggested by Osier Yang.
* src/qemu/qemu_monitor.c (qemuMonitorSendFileHandle)
(qemuMonitorAddHostNetwork, qemuMonitorRemoveHostNetwork)
(qemuMonitorAttachDrive, qemuMonitorDiskSnapshot)
(qemuMonitorDriveMirror, qemuMonitorTransaction)
(qemuMonitorBlockCommit, qemuMonitorDrivePivot)
(qemuMonitorBlockJob, qemuMonitorSystemWakeup)
(qemuMonitorGetVersion, qemuMonitorGetMachines)
(qemuMonitorGetCPUDefinitions, qemuMonitorGetCommands)
(qemuMonitorGetEvents, qemuMonitorGetKVMState)
(qemuMonitorGetObjectTypes, qemuMonitorGetObjectProps)
(qemuMonitorGetTargetArch): Use better error category.
2012-12-04 20:24:40 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
2012-08-22 09:48:41 +00:00
|
|
|
_("JSON monitor is required"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return qemuMonitorJSONGetObjectProps(mon, type, props);
|
|
|
|
}
|
2012-08-22 09:48:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
char *qemuMonitorGetTargetArch(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
VIR_DEBUG("mon=%p",
|
|
|
|
mon);
|
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mon->json) {
|
qemu: improve error for failed JSON commands
Only one error in qemu_monitor was already using the relatively
new OPERATION_UNSUPPORTED error, even though it is a better fit
for all of the messages related to options that are unsupported
due to the version of qemu in use rather than due to a user's
XML or .conf file choice. Suggested by Osier Yang.
* src/qemu/qemu_monitor.c (qemuMonitorSendFileHandle)
(qemuMonitorAddHostNetwork, qemuMonitorRemoveHostNetwork)
(qemuMonitorAttachDrive, qemuMonitorDiskSnapshot)
(qemuMonitorDriveMirror, qemuMonitorTransaction)
(qemuMonitorBlockCommit, qemuMonitorDrivePivot)
(qemuMonitorBlockJob, qemuMonitorSystemWakeup)
(qemuMonitorGetVersion, qemuMonitorGetMachines)
(qemuMonitorGetCPUDefinitions, qemuMonitorGetCommands)
(qemuMonitorGetEvents, qemuMonitorGetKVMState)
(qemuMonitorGetObjectTypes, qemuMonitorGetObjectProps)
(qemuMonitorGetTargetArch): Use better error category.
2012-12-04 20:24:40 +00:00
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
2012-08-22 09:48:41 +00:00
|
|
|
_("JSON monitor is required"));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return qemuMonitorJSONGetTargetArch(mon);
|
|
|
|
}
|
2013-01-14 11:45:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns 1 if @capability is supported, 0 if it's not, or -1 on error.
|
|
|
|
*/
|
|
|
|
int qemuMonitorGetMigrationCapability(qemuMonitorPtr mon,
|
|
|
|
qemuMonitorMigrationCaps capability)
|
|
|
|
{
|
|
|
|
VIR_DEBUG("mon=%p capability=%d", mon, capability);
|
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No capability is supported without JSON monitor */
|
|
|
|
if (!mon->json)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return qemuMonitorJSONGetMigrationCapability(mon, capability);
|
|
|
|
}
|
|
|
|
|
|
|
|
int qemuMonitorSetMigrationCapability(qemuMonitorPtr mon,
|
|
|
|
qemuMonitorMigrationCaps capability)
|
|
|
|
{
|
|
|
|
VIR_DEBUG("mon=%p capability=%d", mon, capability);
|
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mon->json) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
|
|
|
_("JSON monitor is required"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return qemuMonitorJSONSetMigrationCapability(mon, capability);
|
|
|
|
}
|
2012-11-22 15:08:52 +00:00
|
|
|
|
|
|
|
int qemuMonitorNBDServerStart(qemuMonitorPtr mon,
|
|
|
|
const char *host,
|
|
|
|
unsigned int port)
|
|
|
|
{
|
|
|
|
VIR_DEBUG("mon=%p host=%s port=%u",
|
|
|
|
mon, host, port);
|
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mon->json) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
|
|
|
_("JSON monitor is required"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return qemuMonitorJSONNBDServerStart(mon, host, port);
|
|
|
|
}
|
2012-11-22 15:17:13 +00:00
|
|
|
|
|
|
|
int qemuMonitorNBDServerAdd(qemuMonitorPtr mon,
|
|
|
|
const char *deviceID,
|
|
|
|
bool writable)
|
|
|
|
{
|
|
|
|
VIR_DEBUG("mon=%p deviceID=%s",
|
|
|
|
mon, deviceID);
|
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mon->json) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
|
|
|
_("JSON monitor is required"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return qemuMonitorJSONNBDServerAdd(mon, deviceID, writable);
|
|
|
|
}
|
2013-01-31 13:47:49 +00:00
|
|
|
|
|
|
|
int qemuMonitorNBDServerStop(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
VIR_DEBUG("mon=%p", mon);
|
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mon->json) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
|
|
|
_("JSON monitor is required"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return qemuMonitorJSONNBDServerStop(mon);
|
|
|
|
}
|
2013-04-12 20:55:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorGetTPMModels(qemuMonitorPtr mon,
|
|
|
|
char ***tpmmodels)
|
|
|
|
{
|
|
|
|
VIR_DEBUG("mon=%p tpmmodels=%p",
|
|
|
|
mon, tpmmodels);
|
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mon->json) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
|
|
|
_("JSON monitor is required"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return qemuMonitorJSONGetTPMModels(mon, tpmmodels);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorGetTPMTypes(qemuMonitorPtr mon,
|
|
|
|
char ***tpmtypes)
|
|
|
|
{
|
|
|
|
VIR_DEBUG("mon=%p tpmtypes=%p",
|
|
|
|
mon, tpmtypes);
|
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mon->json) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
|
|
|
_("JSON monitor is required"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return qemuMonitorJSONGetTPMTypes(mon, tpmtypes);
|
|
|
|
}
|
2013-03-12 18:48:04 +00:00
|
|
|
|
|
|
|
int qemuMonitorAttachCharDev(qemuMonitorPtr mon,
|
|
|
|
const char *chrID,
|
|
|
|
virDomainChrSourceDefPtr chr)
|
|
|
|
{
|
|
|
|
VIR_DEBUG("mon=%p chrID=%s chr=%p", mon, chrID, chr);
|
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mon->json) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
|
|
|
_("JSON monitor is required"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return qemuMonitorJSONAttachCharDev(mon, chrID, chr);
|
|
|
|
}
|
2013-03-12 18:57:48 +00:00
|
|
|
|
|
|
|
int qemuMonitorDetachCharDev(qemuMonitorPtr mon,
|
|
|
|
const char *chrID)
|
|
|
|
{
|
|
|
|
VIR_DEBUG("mon=%p chrID=%s", mon, chrID);
|
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mon->json) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
|
|
|
_("JSON monitor is required"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return qemuMonitorJSONDetachCharDev(mon, chrID);
|
|
|
|
}
|
2013-07-19 13:01:38 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
qemuMonitorGetDeviceAliases(qemuMonitorPtr mon,
|
|
|
|
char ***aliases)
|
|
|
|
{
|
|
|
|
VIR_DEBUG("mon=%p, aliases=%p", mon, aliases);
|
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mon->json) {
|
|
|
|
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
|
|
|
_("JSON monitor is required"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return qemuMonitorJSONGetDeviceAliases(mon, aliases);
|
|
|
|
}
|