[libvirt] Non-blocking virStreamRecv always returns -2 (EAGAIN)?
by John Eckersberg
I'm running the following test program, and it works as written with a
blocking stream. Inside the guest I'm running:
[root@f17-minimal ~]# socat /usr/share/dict/words /dev/virtio-ports/org.libguestfs.channel.0
As expected on the client side, I get all the words dumped. However if
I swap the virStreamNew lines and instead use the non-blocking stream,
the virStreamRecv call always returns -2.
>From http://libvirt.org/internals/rpc.html#apiclientdispatch, I see:
When no thread is performing any RPC method call, or sending stream
data there is still a need to monitor the socket for incoming I/O
related to asynchronous events, or stream data receipt. For this task,
a watch is registered with the event loop which triggers whenever the
socket is readable. This watch is automatically disabled whenever any
other thread grabs the buck, and re-enabled when the buck is released.
If I understand that correctly, shouldn't the watch be responsible for
reading the stream data in this case? Or am I just completely missing
something?
-----
#include <libvirt.h>
int main()
{
virConnectPtr conn;
virDomainPtr dom;
virStreamPtr st;
char buf[1024+1];
int got = 0;
conn = virConnectOpen("qemu+ssh://root@localhost/system");
dom = virDomainLookupByName(conn, "f17-minimal");
/* st = virStreamNew(conn, VIR_STREAM_NONBLOCK); */
st = virStreamNew(conn, 0);
virDomainOpenChannel(dom, "org.libguestfs.channel.0", st, 0);
while (1) {
got = virStreamRecv(st, buf, 1024);
switch (got) {
case 0:
goto finish;
case -1:
goto free;
case -2:
puts("Retrying");
sleep(1);
continue;
}
buf[got] = '\0';
puts(buf);
}
finish:
virStreamFinish(st);
free:
virStreamFree(st);
return 0;
}
11 years, 11 months
[libvirt] [PATCH] S390: Enhance memballoon handling for virtio-s390
by Viktor Mihajlovski
The way in that memory balloon suppression was handled for S390
is flawed for a number or reasons.
1. Just preventing the default balloon to be created in the case
of VIR_ARCH_S390[X] is not sufficient. An explicit memballoon
element in the guest definition will still be honored, resulting
both in a -balloon option and the allocation of a PCI bus address,
neither being supported.
2. Prohibiting balloon for S390 altogether at a domain_conf level
is no good solution either as there's work in progress on the QEMU
side to implement a virtio-balloon device, although in
conjunction with a new machine type. Suppressing the balloon
should therefore be done at the QEMU driver level depending
on the present capabilities.
Therefore we remove the conditional suppression of the default
balloon in domain_conf.c.
Further, we are claiming the memballoon device for virtio-s390
during device address assignment to prevent it from being considered
as a PCI device.
Finally, we suppress the generation of the balloon command line option
if this is a virtio-s390 machine.
Signed-off-by: Viktor Mihajlovski <mihajlov(a)linux.vnet.ibm.com>
---
src/conf/domain_conf.c | 4 +---
src/qemu/qemu_command.c | 9 ++++++++-
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 6feded4..325e1ee 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -10285,9 +10285,7 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
def->memballoon = memballoon;
VIR_FREE(nodes);
- } else if (def->os.arch != VIR_ARCH_S390 &&
- def->os.arch != VIR_ARCH_S390X) {
- /* TODO: currently no balloon support on s390 -> no default balloon */
+ } else {
if (def->virtType == VIR_DOMAIN_VIRT_XEN ||
def->virtType == VIR_DOMAIN_VIRT_QEMU ||
def->virtType == VIR_DOMAIN_VIRT_KQEMU ||
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 981c692..3496dbf 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -795,7 +795,7 @@ qemuDomainPrimeS390VirtioDevices(virDomainDefPtr def,
{
/*
declare address-less virtio devices to be of address type 'type'
- only disks, networks, consoles and controllers for now
+ only disks, networks, consoles, controllers and memballoon for now
*/
int i;
@@ -825,6 +825,10 @@ qemuDomainPrimeS390VirtioDevices(virDomainDefPtr def,
def->controllers[i]->info.type = type;
}
+ if (def->memballoon &&
+ def->memballoon->model == VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO &&
+ def->memballoon->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE)
+ def->memballoon->info.type = type;
}
static void
@@ -6956,6 +6960,9 @@ qemuBuildCommandLine(virConnectPtr conn,
* NB: Earlier we declared that VirtIO balloon will always be in
* slot 0x3 on bus 0x0
*/
+ if (qemuCapsGet(caps, QEMU_CAPS_VIRTIO_S390) && (def->memballoon))
+ def->memballoon->model = VIR_DOMAIN_MEMBALLOON_MODEL_NONE;
+
if ((def->memballoon) &&
(def->memballoon->model != VIR_DOMAIN_MEMBALLOON_MODEL_NONE)) {
if (def->memballoon->model != VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO) {
--
1.7.9.5
11 years, 11 months
[libvirt] [PATCH] qemu: Move one misplaced driver unlock to the right function
by Viktor Mihajlovski
This should have been commit 56fd513 already, but was missed
by initially. The driver unlock call in the cleanup section of
DomainManagedSave does actually belong to DomainSendKey.
Signed-off-by: Viktor Mihajlovski <mihajlov(a)linux.vnet.ibm.com>
---
src/qemu/qemu_driver.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index c28c223..853e35d 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -2434,6 +2434,7 @@ endjob:
cleanup:
if (vm)
virObjectUnlock(vm);
+ qemuDriverUnlock(driver);
return ret;
}
@@ -3174,7 +3175,6 @@ qemuDomainManagedSave(virDomainPtr dom, unsigned int flags)
cleanup:
if (vm)
virObjectUnlock(vm);
- qemuDriverUnlock(driver);
VIR_FREE(name);
return ret;
--
1.7.9.5
11 years, 11 months
[libvirt] [PATCH v2] selinux: Only create the selabel_handle once.
by Richard W.M. Jones
From: "Richard W.M. Jones" <rjones(a)redhat.com>
According to Eric Paris this is slightly more efficient because it
only loads the regular expressions in libselinux once.
---
src/security/security_selinux.c | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index a3ef728..d4f0595 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -935,20 +935,30 @@ virSecuritySELinuxFSetFilecon(int fd, char *tcon)
return 0;
}
+#if HAVE_SELINUX_LABEL_H
+
+static struct selabel_handle *seLabelHandle = NULL;
+
+static int
+seLabelHandleOnceInit (void)
+{
+ seLabelHandle = selabel_open(SELABEL_CTX_FILE, NULL, 0);
+ return seLabelHandle ? 0 : -1;
+}
+
+VIR_ONCE_GLOBAL_INIT(seLabelHandle)
+
+#endif
+
/* Set fcon to the appropriate label for path and mode, or return -1. */
static int
getContext(const char *newpath, mode_t mode, security_context_t *fcon)
{
#if HAVE_SELINUX_LABEL_H
- struct selabel_handle *handle = selabel_open(SELABEL_CTX_FILE, NULL, 0);
- int ret;
-
- if (handle == NULL)
+ if (seLabelHandleInitialize() < 0)
return -1;
- ret = selabel_lookup_raw(handle, fcon, newpath, mode);
- selabel_close(handle);
- return ret;
+ return selabel_lookup_raw(seLabelHandle, fcon, newpath, mode);
#else
return matchpathcon(newpath, mode, fcon);
#endif
--
1.8.1
11 years, 11 months
[libvirt] [PATCH] selinux: Only create the selabel_handle once.
by Richard W.M. Jones
From: "Richard W.M. Jones" <rjones(a)redhat.com>
According to Eric Paris this is slightly more efficient because it
only loads the regular expressions in libselinux once.
---
src/security/security_selinux.c | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index a3ef728..8b88785 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -935,20 +935,26 @@ virSecuritySELinuxFSetFilecon(int fd, char *tcon)
return 0;
}
+#if HAVE_SELINUX_LABEL_H
+static struct selabel_handle *sehandle = NULL;
+static virOnceControl sehandleonce = VIR_ONCE_CONTROL_INITIALIZER;
+
+static void
+seHandleInit (void)
+{
+ sehandle = selabel_open(SELABEL_CTX_FILE, NULL, 0);
+}
+#endif
+
/* Set fcon to the appropriate label for path and mode, or return -1. */
static int
getContext(const char *newpath, mode_t mode, security_context_t *fcon)
{
#if HAVE_SELINUX_LABEL_H
- struct selabel_handle *handle = selabel_open(SELABEL_CTX_FILE, NULL, 0);
- int ret;
-
- if (handle == NULL)
+ if (virOnce(&sehandleonce, seHandleInit) < 0 || sehandle == NULL)
return -1;
- ret = selabel_lookup_raw(handle, fcon, newpath, mode);
- selabel_close(handle);
- return ret;
+ return selabel_lookup_raw(sehandle, fcon, newpath, mode);
#else
return matchpathcon(newpath, mode, fcon);
#endif
--
1.8.1
11 years, 11 months
[libvirt] Network stops with CentOS 6.3 guest on Ubuntu 12.10
by Andy Howell
I'm still have not resolved this, any idea how to debug it?
Thanks,
Andy
Hello,
I'm trying to get CentOS 6.3 running under Ubuntu 12.10. When the interface comes up, I
can ping another machine for 9 packets. After that it stops working. Bouncing the guest
network interface gets it going again for another 10 packets.
Monitoring the vnet0 interface on the host, I see ARP requests from the host to the guest
are not getting replies.
I cleared out iptables to eliminate that. No luck.
I have Fedora 17 and Windows 7 running on the machine with no problems. Any ideas?
Thanks,
Andy
--
libvir-list mailing list
libvir-list(a)redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
11 years, 11 months
[libvirt] [PATCH] Ensure nodeinfo struct is initialized to zero
by Daniel P. Berrange
From: "Daniel P. Berrange" <berrange(a)redhat.com>
When linuxNodeInfoCPUPopulate() method triggered use of an
uninitialize value, since it did not initialize the 'sockets'
field in the virNodeInfoPtr struct:
==30020== Conditional jump or move depends on uninitialised value(s)
==30020== at 0x5125DBD: linuxNodeInfoCPUPopulate (nodeinfo.c:513)
==30020== by 0x51261A0: nodeGetInfo (nodeinfo.c:884)
==30020== by 0x149B9B10: qemuCapsInit (qemu_capabilities.c:846)
==30020== by 0x14A11B25: qemuCreateCapabilities (qemu_driver.c:424)
==30020== by 0x14A12426: qemuStartup (qemu_driver.c:874)
==30020== by 0x512A7AF: virStateInitialize (libvirt.c:822)
==30020== by 0x40DE04: daemonRunStateInit (libvirtd.c:877)
==30020== by 0x50ADCE5: virThreadHelper (virthreadpthread.c:161)
==30020== by 0x328CA07D14: start_thread (pthread_create.c:308)
==30020== by 0x328C6F246C: clone (clone.S:114)
(happened twice)
if (socks > nodeinfo->sockets) <--- here
nodeinfo->sockets = socks;
Rather than doing this for each field, just make the caller memset
the entire struct to zero.
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
src/nodeinfo.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/src/nodeinfo.c b/src/nodeinfo.c
index 477104f..5b91a12 100644
--- a/src/nodeinfo.c
+++ b/src/nodeinfo.c
@@ -387,11 +387,6 @@ int linuxNodeInfoCPUPopulate(FILE *cpuinfo,
char *sysfs_nodedir = NULL;
char *sysfs_cpudir = NULL;
- nodeinfo->cpus = 0;
- nodeinfo->mhz = 0;
- nodeinfo->cores = 0;
- nodeinfo->nodes = 0;
-
/* Start with parsing CPU clock speed from /proc/cpuinfo */
while (fgets(line, sizeof(line), cpuinfo) != NULL) {
# if defined(__x86_64__) || \
@@ -868,6 +863,8 @@ int nodeGetInfo(virConnectPtr conn ATTRIBUTE_UNUSED, virNodeInfoPtr nodeinfo)
{
virArch hostarch = virArchFromHost();
+ memset(nodeinfo, 0, sizeof(nodeinfo));
+
if (virStrcpyStatic(nodeinfo->model, virArchToString(hostarch)) == NULL)
return -1;
--
1.8.1
11 years, 11 months
[libvirt] [PATCH] Avoid use of free'd memory in auto destroy callback
by Daniel P. Berrange
From: "Daniel P. Berrange" <berrange(a)redhat.com>
The autodestroy callback code has the following function
called from a hash iterator
qemuDriverCloseCallbackRun(void *payload,
const void *name,
void *opaque)
{
...
char *uuidstr = name
...
dom = closeDef->cb(data->driver, dom, data->conn);
if (dom)
virObjectUnlock(dom);
virHashRemoveEntry(data->driver->closeCallbacks, uuidstr);
}
The closeDef->cb function may well cause the current callback
to be removed, if it shuts down 'dom'. As such the use of
'uuidstr' in virHashRemoveEntry is accessing free'd memory.
We must make a copy of the uuid str before invoking the
callback to be safe.
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
src/qemu/qemu_conf.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index b21392e..ee48333 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -510,20 +510,25 @@ qemuDriverCloseCallbackRun(void *payload,
{
struct qemuDriverCloseCallbackData *data = opaque;
qemuDriverCloseDefPtr closeDef = payload;
- const char *uuidstr = name;
unsigned char uuid[VIR_UUID_BUFLEN];
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
virDomainObjPtr dom;
VIR_DEBUG("conn=%p, thisconn=%p, uuid=%s, cb=%p",
- closeDef->conn, data->conn, uuidstr, closeDef->cb);
+ closeDef->conn, data->conn, (const char *)name, closeDef->cb);
if (data->conn != closeDef->conn || !closeDef->cb)
return;
- if (virUUIDParse(uuidstr, uuid) < 0) {
- VIR_WARN("Failed to parse %s", uuidstr);
+ if (virUUIDParse(name, uuid) < 0) {
+ VIR_WARN("Failed to parse %s", (const char *)name);
return;
}
+ /* We need to reformat uuidstr, because closeDef->cb
+ * might cause the current hash entry to be removed,
+ * which means 'name' will have been free()d
+ */
+ virUUIDFormat(uuid, uuidstr);
if (!(dom = virDomainFindByUUID(&data->driver->domains, uuid))) {
VIR_DEBUG("No domain object with UUID %s", uuidstr);
--
1.8.1
11 years, 11 months
[libvirt] [PATCH] Fix leak of securityDriverNames
by Daniel P. Berrange
From: "Daniel P. Berrange" <berrange(a)redhat.com>
When shutting down, the QEMU driver forgot to free the
securityDriverNames string list
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
src/qemu/qemu_driver.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 72907d2..b3d6199 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1134,6 +1134,9 @@ qemuShutdown(void) {
VIR_FREE(qemu_driver->saveImageFormat);
VIR_FREE(qemu_driver->dumpImageFormat);
+ for (i = 0 ; qemu_driver->securityDriverNames[i] != NULL ; i++)
+ VIR_FREE(qemu_driver->securityDriverNames[i]);
+ VIR_FREE(qemu_driver->securityDriverNames);
virSecurityManagerFree(qemu_driver->securityManager);
ebtablesContextFree(qemu_driver->ebtables);
--
1.8.1
11 years, 11 months
[libvirt] ssh not working with libvirt
by varun bhatnagar
Hi,
I am having issue while doing *ssh* to a virtual node through libvirt. The
nodes's ip address is 192.168.82.1. When I am giving the command it is
giving the following error message:
*virsh# connect vbox+ssh://192.168.82.1/session*
*Password:*
*error: Failed to connect to the hypervisor*
*error: End of ifle while reading data: sh: nc: command not found:
Input/output error.*
Can anyone tell me why am I facing this problem and how to resolve it.
Thanks in advance.
11 years, 11 months