2009-10-09 18:07:55 +00:00
|
|
|
/*
|
|
|
|
* qemu_monitor.c: interaction with QEMU monitor console
|
|
|
|
*
|
domain_conf: split source data out from ChrDef
This opens up the possibility of reusing the smaller ChrSourceDef
for both qemu monitor and a passthrough smartcard device.
* src/conf/domain_conf.h (_virDomainChrDef): Factor host
details...
(_virDomainChrSourceDef): ...into new struct.
(virDomainChrSourceDefFree): New prototype.
* src/conf/domain_conf.c (virDomainChrDefFree)
(virDomainChrDefParseXML, virDomainChrDefFormat): Split...
(virDomainChrSourceDefClear, virDomainChrSourceDefFree)
(virDomainChrSourceDefParseXML, virDomainChrSourceDefFormat):
...into new functions.
(virDomainChrDefParseTargetXML): Update clients to reflect type
split.
* src/vmx/vmx.c (virVMXParseSerial, virVMXParseParallel)
(virVMXFormatSerial, virVMXFormatParallel): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainOpenConsole): Likewise.
* src/xen/xend_internal.c (xenDaemonParseSxprChar)
(xenDaemonFormatSxprChr): Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainDumpXML, vboxAttachSerial)
(vboxAttachParallel): Likewise.
* src/security/security_dac.c (virSecurityDACSetChardevLabel)
(virSecurityDACSetChardevCallback)
(virSecurityDACRestoreChardevLabel)
(virSecurityDACRestoreChardevCallback): Likewise.
* src/security/security_selinux.c (SELinuxSetSecurityChardevLabel)
(SELinuxSetSecurityChardevCallback)
(SELinuxRestoreSecurityChardevLabel)
(SELinuxSetSecurityChardevCallback): Likewise.
* src/security/virt-aa-helper.c (get_files): Likewise.
* src/lxc/lxc_driver.c (lxcVmStart, lxcDomainOpenConsole):
Likewise.
* src/uml/uml_conf.c (umlBuildCommandLineChr): Likewise.
* src/uml/uml_driver.c (umlIdentifyOneChrPTY, umlIdentifyChrPTY)
(umlDomainOpenConsole): Likewise.
* src/qemu/qemu_command.c (qemuBuildChrChardevStr)
(qemuBuildChrArgStr, qemuBuildCommandLine)
(qemuParseCommandLineChr): Likewise.
* src/qemu/qemu_domain.c (qemuDomainObjPrivateXMLFormat)
(qemuDomainObjPrivateXMLParse): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupChardevCgroup): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/qemu/qemu_driver.c (qemudFindCharDevicePTYsMonitor)
(qemudFindCharDevicePTYs, qemuPrepareChardevDevice)
(qemuPrepareMonitorChr, qemudShutdownVMDaemon)
(qemuDomainOpenConsole): Likewise.
* src/qemu/qemu_command.h (qemuBuildChrChardevStr)
(qemuBuildChrArgStr): Delete, now that they are static.
* src/libvirt_private.syms (domain_conf.h): New exports.
* cfg.mk (useless_free_options): Update list.
* tests/qemuxml2argvtest.c (testCompareXMLToArgvFiles): Update
tests.
2011-01-07 22:45:01 +00:00
|
|
|
* Copyright (C) 2006-2011 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
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
* Author: Daniel P. Berrange <berrange@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <poll.h>
|
|
|
|
#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"
|
2009-10-09 18:07:55 +00:00
|
|
|
#include "qemu_conf.h"
|
|
|
|
#include "event.h"
|
|
|
|
#include "virterror_internal.h"
|
2009-10-09 19:13:29 +00:00
|
|
|
#include "memory.h"
|
|
|
|
#include "logging.h"
|
2010-11-09 20:48:48 +00:00
|
|
|
#include "files.h"
|
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 {
|
2010-11-17 15:19:13 +00:00
|
|
|
virMutex lock; /* also used to protect 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
|
|
|
virCond notify;
|
|
|
|
|
2009-11-26 13:29:29 +00:00
|
|
|
int refs;
|
2009-10-13 14:27:58 +00:00
|
|
|
|
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;
|
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 */
|
|
|
|
int lastErrno;
|
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
unsigned json: 1;
|
2009-10-09 19:13:29 +00:00
|
|
|
};
|
|
|
|
|
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")
|
|
|
|
|
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;
|
|
|
|
int i, j;
|
|
|
|
char *out;
|
|
|
|
|
|
|
|
/* To pass through the QEMU monitor, we need to use escape
|
|
|
|
sequences: \r, \n, \", \\
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (i = 0; in[i] != '\0'; i++) {
|
|
|
|
switch(in[i]) {
|
|
|
|
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++) {
|
|
|
|
switch(in[i]) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *qemuMonitorEscapeShell(const char *in)
|
|
|
|
{
|
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
|
|
|
int len = 2; /* leading and trailing single quote */
|
|
|
|
int i, j;
|
|
|
|
char *out;
|
|
|
|
|
|
|
|
for (i = 0; in[i] != '\0'; i++) {
|
|
|
|
switch(in[i]) {
|
|
|
|
case '\'':
|
|
|
|
len += 4; /* '\'' */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
len += 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VIR_ALLOC_N(out, len + 1) < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
j = 0;
|
|
|
|
out[j++] = '\'';
|
|
|
|
for (i = 0; in[i] != '\0'; i++) {
|
|
|
|
switch(in[i]) {
|
|
|
|
case '\'':
|
|
|
|
out[j++] = '\'';
|
|
|
|
out[j++] = '\\';
|
|
|
|
out[j++] = '\'';
|
|
|
|
out[j++] = '\'';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
out[j++] = in[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out[j++] = '\'';
|
|
|
|
out[j] = '\0';
|
|
|
|
|
|
|
|
return out;
|
2009-11-26 13:37:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
|
|
|
for (i = 0 ; text[i] != '\0' ; i++) {
|
|
|
|
if (c_isprint(text[i]) ||
|
|
|
|
text[i] == '\n' ||
|
|
|
|
(text[i] == '\r' && text[i+1] == '\n'))
|
|
|
|
virBufferVSprintf(&buf,"%c", text[i]);
|
|
|
|
else
|
|
|
|
virBufferVSprintf(&buf, "0x%02x", text[i]);
|
|
|
|
}
|
|
|
|
return virBufferContentAndReset(&buf);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-10-13 14:27:58 +00:00
|
|
|
void qemuMonitorLock(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
virMutexLock(&mon->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void qemuMonitorUnlock(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
virMutexUnlock(&mon->lock);
|
|
|
|
}
|
|
|
|
|
2009-10-09 18:07:55 +00:00
|
|
|
|
2009-11-26 13:29:29 +00:00
|
|
|
static void qemuMonitorFree(qemuMonitorPtr mon)
|
2009-10-09 18:07:55 +00:00
|
|
|
{
|
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)
|
2010-06-10 14:11:30 +00:00
|
|
|
(mon->cb->destroy)(mon, mon->vm);
|
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 (virCondDestroy(&mon->notify) < 0)
|
|
|
|
{}
|
|
|
|
virMutexDestroy(&mon->lock);
|
2010-11-24 16:04:33 +00:00
|
|
|
VIR_FREE(mon->buffer);
|
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_FREE(mon);
|
2009-10-09 18:07:55 +00:00
|
|
|
}
|
|
|
|
|
2009-11-26 13:29:29 +00:00
|
|
|
int qemuMonitorRef(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
mon->refs++;
|
|
|
|
return mon->refs;
|
|
|
|
}
|
|
|
|
|
|
|
|
int qemuMonitorUnref(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
mon->refs--;
|
|
|
|
|
|
|
|
if (mon->refs == 0) {
|
|
|
|
qemuMonitorUnlock(mon);
|
|
|
|
qemuMonitorFree(mon);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mon->refs;
|
|
|
|
}
|
|
|
|
|
2010-05-12 09:50:52 +00:00
|
|
|
static void
|
|
|
|
qemuMonitorUnwatch(void *monitor)
|
|
|
|
{
|
|
|
|
qemuMonitorPtr mon = monitor;
|
|
|
|
|
|
|
|
qemuMonitorLock(mon);
|
|
|
|
qemuMonitorUnref(mon);
|
|
|
|
}
|
2009-10-09 18:07:55 +00:00
|
|
|
|
|
|
|
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
|
|
|
qemuMonitorOpenUnix(const char *monitor)
|
2009-10-09 18:07:55 +00:00
|
|
|
{
|
|
|
|
struct sockaddr_un addr;
|
|
|
|
int monfd;
|
|
|
|
int timeout = 3; /* In seconds */
|
|
|
|
int ret, i = 0;
|
|
|
|
|
|
|
|
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) {
|
2010-02-09 18:15:41 +00:00
|
|
|
qemuReportError(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;
|
|
|
|
|
|
|
|
if (errno == ENOENT || errno == ECONNREFUSED) {
|
|
|
|
/* 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",
|
2009-10-09 18:07:55 +00:00
|
|
|
_("monitor socket did not show up."));
|
|
|
|
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) {
|
2010-02-09 18:15:41 +00:00
|
|
|
qemuReportError(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
|
|
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
|
|
if (len < 0) {
|
|
|
|
mon->lastErrno = errno;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (!mon->hasSendFD) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&msg, 0, sizeof(msg));
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (done < 0) {
|
|
|
|
if (errno == EAGAIN)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
mon->lastErrno = errno;
|
|
|
|
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,
|
|
|
|
mon->bufferLength + 1024) < 0) {
|
|
|
|
errno = ENOMEM;
|
|
|
|
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;
|
|
|
|
mon->lastErrno = errno;
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (!mon->lastErrno) {
|
|
|
|
events |= VIR_EVENT_HANDLE_READABLE;
|
|
|
|
|
|
|
|
if (mon->msg && mon->msg->txOffset < mon->msg->txLength)
|
|
|
|
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;
|
|
|
|
int quit = 0, failed = 0;
|
|
|
|
|
2010-11-17 15:19:13 +00:00
|
|
|
/* lock access to the monitor and protect 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
|
|
|
qemuMonitorLock(mon);
|
2009-11-26 13:29:29 +00:00
|
|
|
qemuMonitorRef(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
|
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) {
|
2010-05-20 06:15:46 +00:00
|
|
|
VIR_ERROR(_("event from unexpected fd %d!=%d / watch %d!=%d"), mon->fd, fd, mon->watch, watch);
|
2009-10-09 19:13:29 +00:00
|
|
|
failed = 1;
|
|
|
|
} else {
|
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->lastErrno &&
|
|
|
|
events & VIR_EVENT_HANDLE_WRITABLE) {
|
|
|
|
int done = qemuMonitorIOWrite(mon);
|
|
|
|
if (done < 0)
|
|
|
|
failed = 1;
|
|
|
|
events &= ~VIR_EVENT_HANDLE_WRITABLE;
|
|
|
|
}
|
|
|
|
if (!mon->lastErrno &&
|
|
|
|
events & VIR_EVENT_HANDLE_READABLE) {
|
|
|
|
int got = qemuMonitorIORead(mon);
|
|
|
|
if (got < 0)
|
|
|
|
failed = 1;
|
|
|
|
/* Ignore hangup/error events if we read some data, to
|
|
|
|
* give time for that data to be consumed */
|
|
|
|
if (got > 0) {
|
|
|
|
events = 0;
|
|
|
|
|
|
|
|
if (qemuMonitorIOProcess(mon) < 0)
|
|
|
|
failed = 1;
|
|
|
|
} else
|
|
|
|
events &= ~VIR_EVENT_HANDLE_READABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If IO process resulted in an error & we have a message,
|
|
|
|
* then wakeup that waiter */
|
|
|
|
if (mon->lastErrno && mon->msg && !mon->msg->finished) {
|
|
|
|
mon->msg->lastErrno = mon->lastErrno;
|
|
|
|
mon->msg->finished = 1;
|
|
|
|
virCondSignal(&mon->notify);
|
|
|
|
}
|
|
|
|
|
|
|
|
qemuMonitorUpdateWatch(mon);
|
|
|
|
|
2010-12-13 16:05:41 +00:00
|
|
|
if (events & (VIR_EVENT_HANDLE_HANGUP |
|
|
|
|
VIR_EVENT_HANDLE_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
|
|
|
/* If IO process resulted in EOF & we have a message,
|
|
|
|
* then wakeup that waiter */
|
|
|
|
if (mon->msg && !mon->msg->finished) {
|
|
|
|
mon->msg->finished = 1;
|
|
|
|
mon->msg->lastErrno = EIO;
|
|
|
|
virCondSignal(&mon->notify);
|
|
|
|
}
|
2009-10-09 19:13:29 +00:00
|
|
|
quit = 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
|
|
|
} else if (events) {
|
2009-10-09 19:13:29 +00:00
|
|
|
VIR_ERROR(_("unhandled fd event %d for monitor fd %d"),
|
|
|
|
events, mon->fd);
|
|
|
|
failed = 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
|
|
|
/* 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 */
|
|
|
|
if (failed || quit) {
|
2009-10-15 17:56:52 +00:00
|
|
|
void (*eofNotify)(qemuMonitorPtr, virDomainObjPtr, int)
|
|
|
|
= mon->cb->eofNotify;
|
2009-11-26 13:29:29 +00:00
|
|
|
virDomainObjPtr vm = mon->vm;
|
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);
|
2009-11-26 13:29:29 +00:00
|
|
|
if (qemuMonitorUnref(mon) > 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
|
|
|
qemuMonitorUnlock(mon);
|
2009-11-26 13:29:29 +00:00
|
|
|
VIR_DEBUG("Triggering EOF callback error? %d", failed);
|
2009-10-15 17:56:52 +00:00
|
|
|
(eofNotify)(mon, vm, failed);
|
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 {
|
2009-11-26 13:29:29 +00:00
|
|
|
if (qemuMonitorUnref(mon) > 0)
|
|
|
|
qemuMonitorUnlock(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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
qemuMonitorPtr
|
2009-10-09 18:07:55 +00:00
|
|
|
qemuMonitorOpen(virDomainObjPtr vm,
|
2011-01-07 23:36:25 +00:00
|
|
|
virDomainChrSourceDefPtr config,
|
2009-11-03 18:59:18 +00:00
|
|
|
int json,
|
2009-10-15 17:56:52 +00:00
|
|
|
qemuMonitorCallbacksPtr cb)
|
2009-10-09 18:07:55 +00:00
|
|
|
{
|
2009-10-09 19:13:29 +00:00
|
|
|
qemuMonitorPtr mon;
|
|
|
|
|
2009-10-15 17:56:52 +00:00
|
|
|
if (!cb || !cb->eofNotify) {
|
2010-02-09 18:15:41 +00:00
|
|
|
qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("EOF notify callback must be supplied"));
|
2009-10-15 17:56:52 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-10-09 19:13:29 +00:00
|
|
|
if (VIR_ALLOC(mon) < 0) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2009-10-09 19:13:29 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-10-13 14:27:58 +00:00
|
|
|
if (virMutexInit(&mon->lock) < 0) {
|
2010-02-09 18:15:41 +00:00
|
|
|
qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("cannot initialize monitor mutex"));
|
2009-10-13 14:27:58 +00:00
|
|
|
VIR_FREE(mon);
|
|
|
|
return NULL;
|
|
|
|
}
|
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) {
|
2010-02-09 18:15:41 +00:00
|
|
|
qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("cannot initialize 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
|
|
|
virMutexDestroy(&mon->lock);
|
|
|
|
VIR_FREE(mon);
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-10-09 19:13:29 +00:00
|
|
|
mon->fd = -1;
|
2009-11-26 13:29:29 +00:00
|
|
|
mon->refs = 1;
|
2009-10-09 19:13:29 +00:00
|
|
|
mon->vm = vm;
|
2009-11-03 18:59:18 +00:00
|
|
|
mon->json = json;
|
2009-10-15 17:56:52 +00:00
|
|
|
mon->cb = cb;
|
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
|
|
|
qemuMonitorLock(mon);
|
2009-10-09 19:13:29 +00:00
|
|
|
|
2011-01-07 23:36:25 +00:00
|
|
|
switch (config->type) {
|
2009-10-09 18:07:55 +00:00
|
|
|
case VIR_DOMAIN_CHR_TYPE_UNIX:
|
2009-10-09 19:13:29 +00:00
|
|
|
mon->hasSendFD = 1;
|
2011-01-07 23:36:25 +00:00
|
|
|
mon->fd = qemuMonitorOpenUnix(config->data.nix.path);
|
2009-10-09 19:13:29 +00:00
|
|
|
break;
|
|
|
|
|
2009-10-09 18:07:55 +00:00
|
|
|
case VIR_DOMAIN_CHR_TYPE_PTY:
|
2011-01-07 23:36:25 +00:00
|
|
|
mon->fd = qemuMonitorOpenPty(config->data.file.path);
|
2009-10-09 19:13:29 +00:00
|
|
|
break;
|
|
|
|
|
2009-10-09 18:07:55 +00:00
|
|
|
default:
|
2010-02-09 18:15:41 +00:00
|
|
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("unable to handle monitor type: %s"),
|
2011-01-07 23:36:25 +00:00
|
|
|
virDomainChrTypeToString(config->type));
|
2009-10-09 19:13:29 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2009-11-12 10:33:30 +00:00
|
|
|
if (mon->fd == -1) 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
|
|
|
if (virSetCloseExec(mon->fd) < 0) {
|
2010-02-09 18:15:41 +00:00
|
|
|
qemuReportError(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) {
|
2010-02-09 18:15:41 +00:00
|
|
|
qemuReportError(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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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,
|
2010-05-12 09:50:52 +00:00
|
|
|
mon, qemuMonitorUnwatch)) < 0) {
|
2010-02-09 18:15:41 +00:00
|
|
|
qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("unable to register monitor events"));
|
2009-10-09 19:13:29 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
2010-05-12 09:50:52 +00:00
|
|
|
qemuMonitorRef(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
|
|
|
VIR_DEBUG("New mon %p fd =%d watch=%d", mon, mon->fd, mon->watch);
|
|
|
|
qemuMonitorUnlock(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;
|
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
|
|
|
qemuMonitorUnlock(mon);
|
2009-10-09 19:13:29 +00:00
|
|
|
qemuMonitorClose(mon);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
VIR_DEBUG("mon=%p", 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
|
|
|
qemuMonitorLock(mon);
|
2010-11-17 15:19:13 +00:00
|
|
|
|
|
|
|
if (mon->fd >= 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
|
|
|
if (mon->watch)
|
|
|
|
virEventRemoveHandle(mon->watch);
|
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
|
|
|
|
2010-07-30 17:33:26 +00:00
|
|
|
if (qemuMonitorUnref(mon) > 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
|
|
|
qemuMonitorUnlock(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
|
|
|
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
|
|
|
|
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
|
|
|
|
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) {
|
|
|
|
if (virCondWait(&mon->notify, &mon->lock) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
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 (mon->lastErrno == 0)
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
if (mon->json)
|
|
|
|
return qemuMonitorJSONHumanCommandWithFd(mon, cmd, scm_fd, reply);
|
|
|
|
else
|
|
|
|
return qemuMonitorTextCommandWithFd(mon, cmd, scm_fd, reply);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2009-10-15 17:56:52 +00:00
|
|
|
qemuMonitorRef(mon);
|
|
|
|
qemuMonitorUnlock(mon);
|
|
|
|
if (mon->cb && mon->cb->diskSecretLookup)
|
|
|
|
ret = mon->cb->diskSecretLookup(mon, conn, mon->vm, path, secret, secretLen);
|
|
|
|
qemuMonitorLock(mon);
|
|
|
|
qemuMonitorUnref(mon);
|
|
|
|
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);
|
|
|
|
|
|
|
|
qemuMonitorRef(mon);
|
|
|
|
qemuMonitorUnlock(mon);
|
|
|
|
if (mon->cb && mon->cb->domainShutdown)
|
|
|
|
ret = mon->cb->domainShutdown(mon, mon->vm);
|
|
|
|
qemuMonitorLock(mon);
|
|
|
|
qemuMonitorUnref(mon);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorEmitReset(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
VIR_DEBUG("mon=%p", mon);
|
|
|
|
|
|
|
|
qemuMonitorRef(mon);
|
|
|
|
qemuMonitorUnlock(mon);
|
|
|
|
if (mon->cb && mon->cb->domainReset)
|
|
|
|
ret = mon->cb->domainReset(mon, mon->vm);
|
|
|
|
qemuMonitorLock(mon);
|
|
|
|
qemuMonitorUnref(mon);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorEmitPowerdown(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
VIR_DEBUG("mon=%p", mon);
|
|
|
|
|
|
|
|
qemuMonitorRef(mon);
|
|
|
|
qemuMonitorUnlock(mon);
|
|
|
|
if (mon->cb && mon->cb->domainPowerdown)
|
|
|
|
ret = mon->cb->domainPowerdown(mon, mon->vm);
|
|
|
|
qemuMonitorLock(mon);
|
|
|
|
qemuMonitorUnref(mon);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorEmitStop(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
VIR_DEBUG("mon=%p", mon);
|
|
|
|
|
|
|
|
qemuMonitorRef(mon);
|
|
|
|
qemuMonitorUnlock(mon);
|
|
|
|
if (mon->cb && mon->cb->domainStop)
|
|
|
|
ret = mon->cb->domainStop(mon, mon->vm);
|
|
|
|
qemuMonitorLock(mon);
|
|
|
|
qemuMonitorUnref(mon);
|
|
|
|
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);
|
|
|
|
|
|
|
|
qemuMonitorRef(mon);
|
|
|
|
qemuMonitorUnlock(mon);
|
|
|
|
if (mon->cb && mon->cb->domainRTCChange)
|
|
|
|
ret = mon->cb->domainRTCChange(mon, mon->vm, offset);
|
|
|
|
qemuMonitorLock(mon);
|
|
|
|
qemuMonitorUnref(mon);
|
|
|
|
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);
|
|
|
|
|
|
|
|
qemuMonitorRef(mon);
|
|
|
|
qemuMonitorUnlock(mon);
|
|
|
|
if (mon->cb && mon->cb->domainWatchdog)
|
|
|
|
ret = mon->cb->domainWatchdog(mon, mon->vm, action);
|
|
|
|
qemuMonitorLock(mon);
|
|
|
|
qemuMonitorUnref(mon);
|
|
|
|
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);
|
|
|
|
|
|
|
|
qemuMonitorRef(mon);
|
|
|
|
qemuMonitorUnlock(mon);
|
|
|
|
if (mon->cb && mon->cb->domainIOError)
|
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
|
|
|
ret = mon->cb->domainIOError(mon, 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
|
|
|
qemuMonitorLock(mon);
|
|
|
|
qemuMonitorUnref(mon);
|
|
|
|
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);
|
|
|
|
|
|
|
|
qemuMonitorRef(mon);
|
|
|
|
qemuMonitorUnlock(mon);
|
|
|
|
if (mon->cb && mon->cb->domainGraphics)
|
|
|
|
ret = mon->cb->domainGraphics(mon, mon->vm,
|
|
|
|
phase,
|
|
|
|
localFamily, localNode, localService,
|
|
|
|
remoteFamily, remoteNode, remoteService,
|
|
|
|
authScheme, x509dname, saslUsername);
|
|
|
|
qemuMonitorLock(mon);
|
|
|
|
qemuMonitorUnref(mon);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-02-12 13:45:20 +00:00
|
|
|
int qemuMonitorSetCapabilities(qemuMonitorPtr mon)
|
|
|
|
{
|
|
|
|
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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
2010-02-12 13:45:20 +00:00
|
|
|
|
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONSetCapabilities(mon);
|
|
|
|
else
|
|
|
|
ret = 0;
|
|
|
|
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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
int qemuMonitorGetBalloonInfo(qemuMonitorPtr mon,
|
|
|
|
unsigned long *currmem)
|
|
|
|
{
|
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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
2010-04-12 11:31:15 +00:00
|
|
|
|
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONGetMemoryStats(mon, stats, nr_stats);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextGetMemoryStats(mon, stats, nr_stats);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-09 20:13:06 +00:00
|
|
|
int qemuMonitorGetBlockStatsInfo(qemuMonitorPtr mon,
|
|
|
|
const char *devname,
|
|
|
|
long long *rd_req,
|
|
|
|
long long *rd_bytes,
|
|
|
|
long long *wr_req,
|
|
|
|
long long *wr_bytes,
|
|
|
|
long long *errs)
|
|
|
|
{
|
2009-11-03 18:59:18 +00:00
|
|
|
int ret;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p dev=%s", mon, devname);
|
2010-05-17 11:43:36 +00:00
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONGetBlockStatsInfo(mon, devname,
|
|
|
|
rd_req, rd_bytes,
|
|
|
|
wr_req, wr_bytes,
|
|
|
|
errs);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextGetBlockStatsInfo(mon, devname,
|
|
|
|
rd_req, rd_bytes,
|
|
|
|
wr_req, wr_bytes,
|
|
|
|
errs);
|
|
|
|
return ret;
|
2009-10-09 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
2010-05-14 13:10:01 +00:00
|
|
|
int qemuMonitorGetBlockExtent(qemuMonitorPtr mon,
|
|
|
|
const char *devname,
|
|
|
|
unsigned long long *extent)
|
|
|
|
{
|
|
|
|
int ret;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p, fd=%d, devname=%p",
|
2010-05-14 13:10:01 +00:00
|
|
|
mon, mon->fd, devname);
|
|
|
|
|
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONGetBlockExtent(mon, devname, extent);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextGetBlockExtent(mon, devname, extent);
|
|
|
|
|
|
|
|
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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
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:
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("unsupported protocol type %s"),
|
|
|
|
virDomainGraphicsTypeToString(type));
|
|
|
|
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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
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
|
|
|
|
|
|
|
int qemuMonitorSetCPU(qemuMonitorPtr mon, int cpu, int online)
|
|
|
|
{
|
|
|
|
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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
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,
|
2010-11-08 17:52:48 +00:00
|
|
|
const char *devname,
|
|
|
|
bool force)
|
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 devname=%s force=%d", mon, devname, force);
|
2010-05-17 11:43:36 +00:00
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
2010-11-08 17:52:48 +00:00
|
|
|
ret = qemuMonitorJSONEjectMedia(mon, devname, force);
|
2009-11-03 18:59:18 +00:00
|
|
|
else
|
2010-11-08 17:52:48 +00:00
|
|
|
ret = qemuMonitorTextEjectMedia(mon, devname, force);
|
2009-11-03 18:59:18 +00:00
|
|
|
return ret;
|
2009-10-09 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorChangeMedia(qemuMonitorPtr mon,
|
|
|
|
const char *devname,
|
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-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p devname=%s newmedia=%s format=%s",
|
2010-05-17 11:43:36 +00:00
|
|
|
mon, devname, newmedia, format);
|
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONChangeMedia(mon, devname, newmedia, format);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextChangeMedia(mon, devname, newmedia, format);
|
|
|
|
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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
2010-03-17 15:53:14 +00:00
|
|
|
|
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONSetMigrationDowntime(mon, downtime);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextSetMigrationDowntime(mon, downtime);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-09 20:13:06 +00:00
|
|
|
int qemuMonitorGetMigrationStatus(qemuMonitorPtr mon,
|
|
|
|
int *status,
|
|
|
|
unsigned long long *transferred,
|
|
|
|
unsigned long long *remaining,
|
|
|
|
unsigned long long *total)
|
|
|
|
{
|
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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONGetMigrationStatus(mon, status,
|
|
|
|
transferred,
|
|
|
|
remaining,
|
|
|
|
total);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextGetMigrationStatus(mon, status,
|
|
|
|
transferred,
|
|
|
|
remaining,
|
|
|
|
total);
|
|
|
|
return ret;
|
2009-10-09 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-02 04:37:30 +00:00
|
|
|
int qemuMonitorMigrateToFd(qemuMonitorPtr mon,
|
|
|
|
unsigned int flags,
|
|
|
|
int fd)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
VIR_DEBUG("mon=%p fd=%d flags=%u",
|
|
|
|
mon, fd, flags);
|
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
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)
|
|
|
|
VIR_WARN0("failed to close migration handle");
|
|
|
|
}
|
|
|
|
|
|
|
|
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-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p hostname=%s port=%d flags=%u",
|
2010-06-24 18:58:36 +00:00
|
|
|
mon, hostname, port, flags);
|
2010-05-17 11:43:36 +00:00
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2011-03-04 18:51:48 +00:00
|
|
|
|
|
|
|
if (virAsprintf(&uri, "tcp:%s:%d", hostname, port) < 0) {
|
|
|
|
virReportOOMError();
|
|
|
|
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-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p argv=%p flags=%u",
|
2010-06-24 18:58:36 +00:00
|
|
|
mon, argv, flags);
|
2010-05-17 11:43:36 +00:00
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2011-03-04 18:51:48 +00:00
|
|
|
argstr = virArgvToString(argv);
|
|
|
|
if (!argstr) {
|
|
|
|
virReportOOMError();
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virAsprintf(&dest, "exec:%s", argstr) < 0) {
|
|
|
|
virReportOOMError();
|
|
|
|
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-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p argv=%p target=%s offset=%llu flags=%u",
|
2010-06-24 18:58:36 +00:00
|
|
|
mon, argv, target, offset, flags);
|
2010-05-17 11:43:36 +00:00
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
2010-04-21 13:06:37 +00:00
|
|
|
|
|
|
|
if (offset % QEMU_MONITOR_MIGRATE_TO_FILE_BS) {
|
|
|
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("file offset must be a multiple of %llu"),
|
|
|
|
QEMU_MONITOR_MIGRATE_TO_FILE_BS);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-03-04 18:51:48 +00:00
|
|
|
argstr = virArgvToString(argv);
|
|
|
|
if (!argstr) {
|
|
|
|
virReportOOMError();
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Migrate to file */
|
|
|
|
safe_target = qemuMonitorEscapeShell(target);
|
|
|
|
if (!safe_target) {
|
|
|
|
virReportOOMError();
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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,
|
2011-03-04 18:51:48 +00:00
|
|
|
safe_target) < 0) {
|
|
|
|
virReportOOMError();
|
|
|
|
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-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p, unixfile=%s flags=%u",
|
2010-06-24 18:58:36 +00:00
|
|
|
mon, unixfile, flags);
|
2010-05-17 11:43:36 +00:00
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2011-03-04 18:51:48 +00:00
|
|
|
if (virAsprintf(&dest, "unix:%s", unixfile) < 0) {
|
|
|
|
virReportOOMError();
|
|
|
|
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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
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,
|
2009-12-07 19:07:39 +00:00
|
|
|
virDomainDevicePCIAddress *hostAddr,
|
|
|
|
virDomainDevicePCIAddress *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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
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,
|
2009-12-07 19:07:39 +00:00
|
|
|
virDomainDevicePCIAddress *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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
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,
|
2009-12-07 19:07:39 +00:00
|
|
|
virDomainDevicePCIAddress *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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
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,
|
2009-12-07 19:07:39 +00:00
|
|
|
virDomainDevicePCIAddress *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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
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)
|
|
|
|
{
|
2009-11-03 18:59:18 +00:00
|
|
|
int ret;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p fdname=%s",
|
2010-05-17 11:43:36 +00:00
|
|
|
mon, fdname);
|
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
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);
|
|
|
|
return ret;
|
2009-10-09 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorAddHostNetwork(qemuMonitorPtr mon,
|
|
|
|
const char *netstr)
|
|
|
|
{
|
2009-11-03 18:59:18 +00:00
|
|
|
int ret;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p netstr=%s",
|
2010-05-17 11:43:36 +00:00
|
|
|
mon, netstr);
|
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONAddHostNetwork(mon, netstr);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextAddHostNetwork(mon, netstr);
|
|
|
|
return ret;
|
2009-10-09 20:13:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int qemuMonitorRemoveHostNetwork(qemuMonitorPtr mon,
|
|
|
|
int vlan,
|
|
|
|
const char *netname)
|
|
|
|
{
|
2009-11-03 18:59:18 +00:00
|
|
|
int ret;
|
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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
2009-10-09 20:13:06 +00:00
|
|
|
|
2009-11-03 18:59:18 +00:00
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONRemoveHostNetwork(mon, vlan, netname);
|
|
|
|
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,
|
|
|
|
const char *netdevstr)
|
|
|
|
{
|
|
|
|
int ret;
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p netdevstr=%s",
|
2010-05-17 11:43:36 +00:00
|
|
|
mon, netdevstr);
|
|
|
|
|
|
|
|
if (!mon) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
2010-04-15 13:52:03 +00:00
|
|
|
|
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONAddNetdev(mon, netdevstr);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextAddNetdev(mon, netdevstr);
|
|
|
|
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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
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,
|
|
|
|
virDomainDevicePCIAddress *guestAddr)
|
|
|
|
{
|
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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
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,
|
|
|
|
virDomainDevicePCIAddress *controllerAddr,
|
|
|
|
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);
|
|
|
|
int ret;
|
|
|
|
|
2010-05-17 11:43:36 +00:00
|
|
|
if (!mon) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
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)
|
|
|
|
ret = qemuMonitorJSONAttachDrive(mon, drivestr, controllerAddr, driveAddr);
|
|
|
|
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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
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
|
|
|
|
|
|
|
int qemuMonitorAddDevice(qemuMonitorPtr mon,
|
|
|
|
const char *devicestr)
|
|
|
|
{
|
2011-02-16 23:37:57 +00:00
|
|
|
VIR_DEBUG("mon=%p device=%s", mon, devicestr);
|
2010-01-26 15:34:46 +00:00
|
|
|
int ret;
|
|
|
|
|
2010-05-17 11:43:36 +00:00
|
|
|
if (!mon) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-01-26 15:34:46 +00:00
|
|
|
if (mon->json)
|
|
|
|
ret = qemuMonitorJSONAddDevice(mon, devicestr);
|
|
|
|
else
|
|
|
|
ret = qemuMonitorTextAddDevice(mon, devicestr);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
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) {
|
|
|
|
qemuReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("monitor must not be NULL"));
|
|
|
|
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-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;
|
|
|
|
}
|