[libvirt] [PATCH] qemu: Do not free the device from activePciHostdevs if it's in use
by Osier Yang
* src/qemu/qemu_hostdev.c (qemuDomainReAttachHostdevDevices):
pciDeviceListFree(pcidevs) at the end free()s the device even if
it's in use by other domain, this is complete wrong, and will
cause race. E.g.
# sh test1.sh
Device pci_0000_00_19_0 dettached
Domain test started
Device attached successfully
error: Failed to start domain test2
error: Requested operation is not valid: PCI device 0000:00:19.0 is in use by domain test
[ -- 1th time --]
Device pci_0000_00_19_0 re-attached
[ -- 2th time --]
Device pci_0000_00_19_0 re-attached
[ -- 3th time --]
Device pci_0000_00_19_0 re-attached
[ -- 4th time --]
Device pci_0000_00_19_0 re-attached
[ -- 5th time --]
Device pci_0000_00_19_0 re-attached
clean up
Domain test destroyed
Device pci_0000_00_19_0 re-attached
[root@Osier libvirt]# sh test1.sh
Device pci_0000_00_19_0 dettached
Domain test started
Device attached successfully
error: Failed to start domain test2
error: Requested operation is not valid: PCI device 0000:00:19.0 is in use by domain test
[ -- 1th time --]
Device pci_0000_00_19_0 re-attached
[ -- 2th time --]
Device pci_0000_00_19_0 re-attached
[ -- 3th time --]
Device pci_0000_00_19_0 re-attached
[ -- 4th time --]
Device pci_0000_00_19_0 re-attached
[ -- 5th time --]
Device pci_0000_00_19_0 re-attached
clean up
Domain test destroyed
Device pci_0000_00_19_0 re-attached
[root@Osier libvirt]# sh test1.sh
Device pci_0000_00_19_0 dettached
Domain test started
Device attached successfully
error: Failed to start domain test2
error: Requested operation is not valid: PCI device 0000:00:19.0 is in use by domain test
[ -- 1th time --]
Device pci_0000_00_19_0 re-attached
[ -- 2th time --]
Device pci_0000_00_19_0 re-attached
[ -- 3th time --]
Device pci_0000_00_19_0 re-attached
[ -- 4th time --]
Device pci_0000_00_19_0 re-attached
[ -- 5th time --]
Device pci_0000_00_19_0 re-attached
clean up
Domain test destroyed
Device pci_0000_00_19_0 re-attached
[root@Osier libvirt]# sh test1.sh
Device pci_0000_00_19_0 dettached
Domain test started
Device attached successfully
error: Failed to start domain test2
error: Requested operation is not valid: PCI device 0000:00:19.0 is in use by domain test
[ -- 1th time --]
error: Failed to re-attach device pci_0000_00_19_0
error: internal error Not reattaching active device 0000:00:19.0
[ -- 2th time --]
Device pci_0000_00_19_0 re-attached
[ -- 3th time --]
Device pci_0000_00_19_0 re-attached
[ -- 4th time --]
Device pci_0000_00_19_0 re-attached
[ -- 5th time --]
Device pci_0000_00_19_0 re-attached
clean up
Domain test destroyed
Device pci_0000_00_19_0 re-attached
The patch also fixes another problem alongside, there won't
be error like "qemuDomainReAttachHostdevDevices: Not reattaching active
device 0000:00:19.0" in daemon log if some device is in active.
As pciResetDevice and pciReattachDevice won't be called for
the device anymore. This is sensiable as we already reported
error when preparing the device if it's active. Blindly trying
to pciResetDevice & pciReattachDevice on the device and getting
an error is just redundant.
---
src/qemu/qemu_hostdev.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
index 1fb373e..7efbab0 100644
--- a/src/qemu/qemu_hostdev.c
+++ b/src/qemu/qemu_hostdev.c
@@ -369,8 +369,10 @@ void qemuDomainReAttachHostdevDevices(struct qemud_driver *driver,
*/
activeDev = pciDeviceListFind(driver->activePciHostdevs, dev);
if (activeDev &&
- STRNEQ_NULLABLE(name, pciDeviceGetUsedBy(activeDev)))
+ STRNEQ_NULLABLE(name, pciDeviceGetUsedBy(activeDev))) {
+ pciDeviceListSteal(pcidevs, dev);
continue;
+ }
/* pciDeviceListFree() will take care of freeing the dev. */
pciDeviceListSteal(driver->activePciHostdevs, dev);
--
1.7.6
13 years, 1 month
Re: [libvirt] [PATCH] snapshot: use correct qmp monitor command
by lvroyce
Tested by:lvroyce
test with cmd snapshot-create domain --disk-only ,patch works when qmp
or hmp monitor accessible,
Got trace below when issue cmd "snapshot-delete domain --snapshotname
name",no "delvm/savevm" in qmp, only "delvm/savevm" commands in hmp.Is
this for future compability?
2011-09-19 16:15:54.938: 25648: debug : qemuMonitorJSONIOProcessLine:115
: Line [{"id": "libvirt-11", "error": {"class": "CommandNotFound",
"desc": "The command delvm has not been found", "data": {"name": "delvm"}}}]
2011-09-19 16:15:54.939: 25666: debug : virJSONValueToString:1071 :
result={"execute":"human-monitor-command","arguments":{"command-line":"delvm
\"1319011620\""},"id":"libvirt-12"}
2011-09-19 16:15:54.939: 25666: debug : qemuMonitorJSONCommandWithFd:224
: Send command
'{"execute":"human-monitor-command","arguments":{"command-line":"delvm
\"1319011620\""},"id":"libvirt-12"}' for write with FD -1
13 years, 1 month
[libvirt] [PATCH] Replace virBufferAdd with virBufferAddLit for const string
by Daniel P. Berrange
From: "Daniel P. Berrange" <berrange(a)redhat.com>
The statement
virBufferAdd(buf, "''", 2);
triggers a syntax-check warning
* src/util/buf.c: Replace virBufferAdd with virBufferAddLit
---
src/util/buf.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
Pushed as a build-breaker fix
diff --git a/src/util/buf.c b/src/util/buf.c
index b7fcf6d..5893e11 100644
--- a/src/util/buf.c
+++ b/src/util/buf.c
@@ -520,7 +520,7 @@ virBufferEscapeShell(virBufferPtr buf, const char *str)
return;
}
} else {
- virBufferAdd(buf, "''", 2);
+ virBufferAddLit(buf, "''");
return;
}
--
1.7.6.4
13 years, 1 month
[libvirt] [PATCH] documentation: trivial spelling fix
by Philipp Hahn
Signed-off-by: Philipp Hahn <hahn(a)univention.de>
---
docs/formatdomain.html.in | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index c007dff..4a75026 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -778,7 +778,7 @@
The guest clock will have an arbitrary offset applied
relative to UTC. The delta relative to UTC is specified
in seconds, using the <code>adjustment</code> attribute.
- The guest is free to adjust the RTC over time an expect
+ The guest is free to adjust the RTC over time and expect
that it will be honoured at next reboot. This is in
contrast to 'utc' mode, where the RTC adjustments are
lost at each reboot. <span class="since">Since 0.7.7</span>
--
1.7.1
13 years, 1 month
[libvirt] [PATCH 1/3] virBufferEscapeShell: Emit quotes for the empty string
by Guido Günther
Make the empty string return '' to match cmdEcho's behavior.
---
src/util/buf.c | 15 ++++++++++-----
1 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/src/util/buf.c b/src/util/buf.c
index f582cd2..b7fcf6d 100644
--- a/src/util/buf.c
+++ b/src/util/buf.c
@@ -507,15 +507,20 @@ virBufferEscapeShell(virBufferPtr buf, const char *str)
return;
/* Only quote if str includes shell metacharacters. */
- if (!strpbrk(str, "\r\t\n !\"#$&'()*;<>?[\\]^`{|}~")) {
+ if (*str && !strpbrk(str, "\r\t\n !\"#$&'()*;<>?[\\]^`{|}~")) {
virBufferAdd(buf, str, -1);
return;
}
- len = strlen(str);
- if (xalloc_oversized(4, len) ||
- VIR_ALLOC_N(escaped, 4 * len + 3) < 0) {
- virBufferSetError(buf);
+ if (*str) {
+ len = strlen(str);
+ if (xalloc_oversized(4, len) ||
+ VIR_ALLOC_N(escaped, 4 * len + 3) < 0) {
+ virBufferSetError(buf);
+ return;
+ }
+ } else {
+ virBufferAdd(buf, "''", 2);
return;
}
--
1.7.6.3
13 years, 1 month
[libvirt] [PATCH] snapshot: detect when qemu lacks disk-snapshot support
by Eric Blake
Noticed when testing new libvirt against old qemu that lacked the
snapshot_blkdev HMP command. Libvirt was mistakenly treating the
command as successful, and re-writing the domain XML to use the
just-created 0-byte file, rendering the domain broken on restart.
* src/qemu/qemu_monitor_text.c (qemuMonitorTextDiskSnapshot):
Notice another possible error message.
---
src/qemu/qemu_monitor_text.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c
index 2f31d99..4774df9 100644
--- a/src/qemu/qemu_monitor_text.c
+++ b/src/qemu/qemu_monitor_text.c
@@ -3064,7 +3064,8 @@ qemuMonitorTextDiskSnapshot(qemuMonitorPtr mon, const char *device,
goto cleanup;
}
- if (strstr(reply, "error while creating qcow2") != NULL) {
+ if (strstr(reply, "error while creating qcow2") != NULL ||
+ strstr(reply, "unknown command:") != NULL) {
qemuReportError(VIR_ERR_OPERATION_FAILED,
_("Failed to take snapshot: %s"), reply);
goto cleanup;
--
1.7.4.4
13 years, 1 month
[libvirt] [PATCH 3/3] qemu: replace qemuMonitorEscapeShell by virBufferEscapeShell
by Guido Günther
---
src/qemu/qemu_monitor.c | 49 ++++------------------------------------------
src/qemu/qemu_monitor.h | 1 -
2 files changed, 5 insertions(+), 45 deletions(-)
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index c9dd69e..182e63d 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -139,48 +139,6 @@ char *qemuMonitorEscapeArg(const char *in)
return out;
}
-char *qemuMonitorEscapeShell(const char *in)
-{
- 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;
-}
-
-
#if DEBUG_RAW_IO
# include <c-ctype.h>
static char * qemuMonitorEscapeNonPrintable(const char *text)
@@ -1734,6 +1692,7 @@ int qemuMonitorMigrateToFile(qemuMonitorPtr mon,
char *dest = NULL;
int ret = -1;
char *safe_target = NULL;
+ virBuffer buf = VIR_BUFFER_INITIALIZER;
VIR_DEBUG("mon=%p argv=%p target=%s offset=%llu flags=%x",
mon, argv, target, offset, flags);
@@ -1757,11 +1716,13 @@ int qemuMonitorMigrateToFile(qemuMonitorPtr mon,
}
/* Migrate to file */
- safe_target = qemuMonitorEscapeShell(target);
- if (!safe_target) {
+ virBufferEscapeShell(&buf, target);
+ if (virBufferError(&buf)) {
virReportOOMError();
+ virBufferFreeAndReset(&buf);
goto cleanup;
}
+ safe_target = virBufferContentAndReset(&buf);
/* Two dd processes, sharing the same stdout, are necessary to
* allow starting at an alignment of 512, but without wasting
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 3ec78ad..90e7b45 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -127,7 +127,6 @@ struct _qemuMonitorCallbacks {
char *qemuMonitorEscapeArg(const char *in);
-char *qemuMonitorEscapeShell(const char *in);
qemuMonitorPtr qemuMonitorOpen(virDomainObjPtr vm,
virDomainChrSourceDefPtr config,
--
1.7.6.3
13 years, 1 month
[libvirt] [PATCH 2/3] Use virBufferEscapeShell in cmdEcho
by Guido Günther
---
tools/virsh.c | 39 ++++++++++++++++++---------------------
1 files changed, 18 insertions(+), 21 deletions(-)
diff --git a/tools/virsh.c b/tools/virsh.c
index 54684f6..d45baa6 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -12322,7 +12322,7 @@ static const vshCmdOptDef opts_echo[] = {
* quotes for later evaluation.
*/
static bool
-cmdEcho (vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd)
+cmdEcho (vshControl *ctl, const vshCmd *cmd)
{
bool shell = false;
bool xml = false;
@@ -12337,34 +12337,31 @@ cmdEcho (vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd)
xml = true;
while ((opt = vshCommandOptArgv(cmd, opt))) {
- bool close_quote = false;
- char *q;
+ char *str;
+ virBuffer xmlbuf = VIR_BUFFER_INITIALIZER;
arg = opt->data;
+
if (count)
virBufferAddChar(&buf, ' ');
- /* Add outer '' only if arg included shell metacharacters. */
- if (shell &&
- (strpbrk(arg, "\r\t\n !\"#$&'()*;<>?[\\]^`{|}~") || !*arg)) {
- virBufferAddChar(&buf, '\'');
- close_quote = true;
- }
+
if (xml) {
- virBufferEscapeString(&buf, "%s", arg);
- } else {
- if (shell && (q = strchr(arg, '\''))) {
- do {
- virBufferAdd(&buf, arg, q - arg);
- virBufferAddLit(&buf, "'\\''");
- arg = q + 1;
- q = strchr(arg, '\'');
- } while (q);
+ virBufferEscapeString(&xmlbuf, "%s", arg);
+ if (virBufferError(&buf)) {
+ vshPrint(ctl, "%s", _("Failed to allocate XML buffer"));
+ return false;
}
- virBufferAdd(&buf, arg, strlen(arg));
+ str = virBufferContentAndReset(&xmlbuf);
+ } else {
+ str = vshStrdup(ctl, arg);
}
- if (close_quote)
- virBufferAddChar(&buf, '\'');
+
+ if (shell)
+ virBufferEscapeShell(&buf, str);
+ else
+ virBufferAdd(&buf, str, -1);
count++;
+ VIR_FREE(str);
}
if (virBufferError(&buf)) {
--
1.7.6.3
13 years, 1 month
[libvirt] [PATCH] virNetSocketNewConnectSSH: Escape netcat path too
by Guido Günther
What holds for netcat is also true for the socket path since it can be
part of the connection URI as well. Make both subject to the same amount
of shell parsing.
Cheers,
-- Guido
---
src/rpc/virnetsocket.c | 30 +++++++++++++++++++++---------
tests/virnetsockettest.c | 14 +++++++-------
2 files changed, 28 insertions(+), 16 deletions(-)
diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
index e4eff49..d7a055f 100644
--- a/src/rpc/virnetsocket.c
+++ b/src/rpc/virnetsocket.c
@@ -612,9 +612,10 @@ int virNetSocketNewConnectSSH(const char *nodename,
const char *path,
virNetSocketPtr *retsock)
{
- char *quoted;
+ char *qnetcat, *qpath;
virCommandPtr cmd;
- virBuffer buf = VIR_BUFFER_INITIALIZER;
+ virBuffer ncbuf = VIR_BUFFER_INITIALIZER;
+ virBuffer pathbuf = VIR_BUFFER_INITIALIZER;
*retsock = NULL;
@@ -643,13 +644,23 @@ int virNetSocketNewConnectSSH(const char *nodename,
virCommandAddArgList(cmd, nodename, "sh", "-c", NULL);
- virBufferEscapeShell(&buf, netcat);
- if (virBufferError(&buf)) {
- virBufferFreeAndReset(&buf);
+ virBufferEscapeShell(&ncbuf, netcat);
+ if (virBufferError(&ncbuf)) {
+ virBufferFreeAndReset(&ncbuf);
virReportOOMError();
return -1;
}
- quoted = virBufferContentAndReset(&buf);
+
+ virBufferEscapeShell(&pathbuf, path);
+ if (virBufferError(&pathbuf)) {
+ virBufferFreeAndReset(&ncbuf);
+ virBufferFreeAndReset(&pathbuf);
+ virReportOOMError();
+ return -1;
+ }
+
+ qnetcat = virBufferContentAndReset(&ncbuf);
+ qpath = virBufferContentAndReset(&pathbuf);
/*
* This ugly thing is a shell script to detect availability of
* the -q option for 'nc': debian and suse based distros need this
@@ -666,10 +677,11 @@ int virNetSocketNewConnectSSH(const char *nodename,
"else "
"ARG=;"
"fi;"
- "'%s' $ARG -U %s'",
- quoted, quoted, path);
+ "'%s' $ARG -U '%s",
+ qnetcat, qnetcat, qpath);
- VIR_FREE(quoted);
+ VIR_FREE(qnetcat);
+ VIR_FREE(qpath);
return virNetSocketNewConnectCommand(cmd, retsock);
}
diff --git a/tests/virnetsockettest.c b/tests/virnetsockettest.c
index 6320ce0..5c93f0f 100644
--- a/tests/virnetsockettest.c
+++ b/tests/virnetsockettest.c
@@ -501,7 +501,7 @@ mymain(void)
"else "
"ARG=;"
"fi;"
- "'nc' $ARG -U /tmp/socket'\n",
+ "'nc' $ARG -U '/tmp/socket\n",
};
if (virtTestRun("SSH test 1", 1, testSocketSSH, &sshData1) < 0)
ret = -1;
@@ -520,7 +520,7 @@ mymain(void)
"else "
"ARG=;"
"fi;"
- "'netcat' $ARG -U /tmp/socket'\n",
+ "'netcat' $ARG -U '/tmp/socket\n",
};
if (virtTestRun("SSH test 2", 1, testSocketSSH, &sshData2) < 0)
ret = -1;
@@ -539,7 +539,7 @@ mymain(void)
"else "
"ARG=;"
"fi;"
- "'netcat' $ARG -U /tmp/socket'\n",
+ "'netcat' $ARG -U '/tmp/socket\n",
};
if (virtTestRun("SSH test 3", 1, testSocketSSH, &sshData3) < 0)
ret = -1;
@@ -561,7 +561,7 @@ mymain(void)
"else "
"ARG=;"
"fi;"
- "'nc' $ARG -U /tmp/socket'\n",
+ "'nc' $ARG -U '/tmp/socket\n",
.dieEarly = true,
};
if (virtTestRun("SSH test 5", 1, testSocketSSH, &sshData5) < 0)
@@ -578,7 +578,7 @@ mymain(void)
"else "
"ARG=;"
"fi;"
- "'nc' $ARG -U /tmp/socket'\n",
+ "'nc' $ARG -U '/tmp/socket\n",
};
if (virtTestRun("SSH test 6", 1, testSocketSSH, &sshData6) < 0)
ret = -1;
@@ -586,13 +586,13 @@ mymain(void)
struct testSSHData sshData7 = {
.nodename = "somehost",
.netcat = "nc -4",
- .path = "/tmp/socket",
+ .path = "/tmp/so cket",
.expectOut = "somehost sh -c 'if ''nc -4'' -q 2>&1 | grep \"requires an argument\" >/dev/null 2>&1; then "
"ARG=-q0;"
"else "
"ARG=;"
"fi;"
- "''nc -4'' $ARG -U /tmp/socket'\n",
+ "''nc -4'' $ARG -U ''/tmp/so cket'\n",
};
if (virtTestRun("SSH test 7", 1, testSocketSSH, &sshData7) < 0)
ret = -1;
--
1.7.6.3
13 years, 1 month
[libvirt] [PATCH 0/3] Consolidate shell escape functions
by Guido Günther
The attached patches use virBufferEscapeShell in virsh's virCmd and
eliminate qemuMonitorEscapeShell so we have only one function that does
the shell escaping.
Cheers,
-- Guido
Guido Günther (3):
virBufferEscapeShell: Emit quotes for the empty string
Use virBufferEscapeShell in cmdEcho
qemu: replace qemuMonitorEscapeShell by virBufferEscapeShell
src/qemu/qemu_monitor.c | 49 ++++------------------------------------------
src/qemu/qemu_monitor.h | 1 -
src/util/buf.c | 15 +++++++++----
tools/virsh.c | 39 +++++++++++++++++--------------------
4 files changed, 33 insertions(+), 71 deletions(-)
--
1.7.6.3
13 years, 1 month