[libvirt] [PATCH 1/3] Fix the syntax-check failure
by Osier Yang
Introduced by commit 7ac2c4fe624, pushed under build-breaker rule.
---
src/conf/interface_conf.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/conf/interface_conf.h b/src/conf/interface_conf.h
index ae93811..ed6986c 100644
--- a/src/conf/interface_conf.h
+++ b/src/conf/interface_conf.h
@@ -211,7 +211,7 @@ char *virInterfaceDefFormat(const virInterfaceDefPtr def);
void virInterfaceObjLock(virInterfaceObjPtr obj);
void virInterfaceObjUnlock(virInterfaceObjPtr obj);
-#define VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE \
+# define VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE \
(VIR_CONNECT_LIST_INTERFACES_ACTIVE | \
VIR_CONNECT_LIST_INTERFACES_INACTIVE)
--
1.8.1.4
11 years, 6 months
[libvirt] [PATCH v2] interface: list all interfaces with flags == 0
by Guannan Ren
virConnectListAllInterfaces should support to list all of
interfaces when the value of flags is 0. The behaviour is
consistent with other virConnectListAll* APIs
---
src/conf/interface_conf.h | 4 ++++
src/interface/interface_backend_netcf.c | 29 +++++++++++++++--------------
src/interface/interface_backend_udev.c | 25 ++++++++++++-------------
3 files changed, 31 insertions(+), 27 deletions(-)
diff --git a/src/conf/interface_conf.h b/src/conf/interface_conf.h
index e636c35..ae93811 100644
--- a/src/conf/interface_conf.h
+++ b/src/conf/interface_conf.h
@@ -211,4 +211,8 @@ char *virInterfaceDefFormat(const virInterfaceDefPtr def);
void virInterfaceObjLock(virInterfaceObjPtr obj);
void virInterfaceObjUnlock(virInterfaceObjPtr obj);
+#define VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE \
+ (VIR_CONNECT_LIST_INTERFACES_ACTIVE | \
+ VIR_CONNECT_LIST_INTERFACES_INACTIVE)
+
#endif /* __INTERFACE_CONF_H__ */
diff --git a/src/interface/interface_backend_netcf.c b/src/interface/interface_backend_netcf.c
index cbba4fd..d626017 100644
--- a/src/interface/interface_backend_netcf.c
+++ b/src/interface/interface_backend_netcf.c
@@ -260,6 +260,7 @@ static int netcfConnectListDefinedInterfaces(virConnectPtr conn, char **const na
}
+#define MATCH(FLAG) (flags & (FLAG))
static int
netcfConnectListAllInterfaces(virConnectPtr conn,
virInterfacePtr **ifaces,
@@ -276,8 +277,7 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
int ret = -1;
char **names = NULL;
- virCheckFlags(VIR_CONNECT_LIST_INTERFACES_ACTIVE |
- VIR_CONNECT_LIST_INTERFACES_INACTIVE, -1);
+ virCheckFlags(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE, -1);
interfaceDriverLock(driver);
@@ -293,7 +293,6 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
_("failed to get number of host interfaces: %s%s%s"),
errmsg, details ? " - " : "",
details ? details : "");
- ret = -1;
goto cleanup;
}
@@ -304,7 +303,6 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
if (VIR_ALLOC_N(names, count) < 0) {
virReportOOMError();
- ret = -1;
goto cleanup;
}
@@ -361,16 +359,19 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
/* XXX: Filter the result, need to be splitted once new filter flags
* except active|inactive are supported.
*/
- if (((status & NETCF_IFACE_ACTIVE) &&
- (flags & VIR_CONNECT_LIST_INTERFACES_ACTIVE)) ||
- ((status & NETCF_IFACE_INACTIVE) &&
- (flags & VIR_CONNECT_LIST_INTERFACES_INACTIVE))) {
- if (ifaces) {
- iface_obj = virGetInterface(conn, ncf_if_name(iface),
- ncf_if_mac_string(iface));
- tmp_iface_objs[niface_objs] = iface_obj;
- }
- niface_objs++;
+ if (MATCH(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE) &&
+ !((MATCH(VIR_CONNECT_LIST_INTERFACES_ACTIVE) &&
+ (status & NETCF_IFACE_ACTIVE)) ||
+ (MATCH(VIR_CONNECT_LIST_INTERFACES_INACTIVE) &&
+ (status & NETCF_IFACE_INACTIVE)))) {
+ ncf_if_free(iface);
+ continue;
+ }
+
+ if (ifaces) {
+ iface_obj = virGetInterface(conn, ncf_if_name(iface),
+ ncf_if_mac_string(iface));
+ tmp_iface_objs[niface_objs++] = iface_obj;
}
ncf_if_free(iface);
diff --git a/src/interface/interface_backend_udev.c b/src/interface/interface_backend_udev.c
index 1fd7d46..428adc8 100644
--- a/src/interface/interface_backend_udev.c
+++ b/src/interface/interface_backend_udev.c
@@ -282,6 +282,7 @@ udevConnectListDefinedInterfaces(virConnectPtr conn,
VIR_UDEV_IFACE_INACTIVE);
}
+#define MATCH(FLAG) (flags & (FLAG))
static int
udevConnectListAllInterfaces(virConnectPtr conn,
virInterfacePtr **ifaces,
@@ -299,8 +300,7 @@ udevConnectListAllInterfaces(virConnectPtr conn,
int status = 0;
int ret;
- virCheckFlags(VIR_CONNECT_LIST_INTERFACES_ACTIVE |
- VIR_CONNECT_LIST_INTERFACES_INACTIVE, -1);
+ virCheckFlags(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE, -1);
/* Grab a udev reference */
udev = udev_ref(driverState->udev);
@@ -354,7 +354,6 @@ udevConnectListAllInterfaces(virConnectPtr conn,
const char *path;
const char *name;
const char *macaddr;
- int add_to_list = 0;
path = udev_list_entry_get_name(dev_entry);
dev = udev_device_new_from_syspath(udev, path);
@@ -363,18 +362,17 @@ udevConnectListAllInterfaces(virConnectPtr conn,
status = STREQ(udev_device_get_sysattr_value(dev, "operstate"), "up");
/* Filter the results */
- if (status && (flags & VIR_CONNECT_LIST_INTERFACES_ACTIVE))
- add_to_list = 1;
- else if (!status && (flags & VIR_CONNECT_LIST_INTERFACES_INACTIVE))
- add_to_list = 1;
+ if (MATCH(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE) &&
+ !((MATCH(VIR_CONNECT_LIST_INTERFACES_ACTIVE) && status) ||
+ (MATCH(VIR_CONNECT_LIST_INTERFACES_INACTIVE) && !status))) {
+ udev_device_unref(dev);
+ continue;
+ }
/* If we matched a filter, then add it */
- if (add_to_list) {
- if (ifaces) {
- iface_obj = virGetInterface(conn, name, macaddr);
- ifaces_list[count] = iface_obj;
- }
- count++;
+ if (ifaces) {
+ iface_obj = virGetInterface(conn, name, macaddr);
+ ifaces_list[count++] = iface_obj;
}
udev_device_unref(dev);
}
@@ -387,6 +385,7 @@ udevConnectListAllInterfaces(virConnectPtr conn,
if (ifaces) {
ignore_value(VIR_REALLOC_N(ifaces_list, count + 1));
*ifaces = ifaces_list;
+ ifaces_list = NULL;
}
return count;
--
1.8.1.4
11 years, 6 months
[libvirt] [PATCH] cgroup: be robust against cgroup movement races
by Eric Blake
https://bugzilla.redhat.com/show_bug.cgi?id=965169 documents a
problem starting domains when cgroups are enabled; I was able
to reliably reproduce the race about 5% of the time when I added
hooks to domain startup by 3 seconds (as that seemed to be about
the length of time that qemu created and then closed a temporary
thread, probably related to aio handling of initially opening
a disk image).
There are some inherent TOCTTOU races when moving tasks between
kernel cgroups, precisely because threads can be created or
completed in the window between when we read a thread id from the
source and when we write to the destination. As the goal of
virCgroupMoveTask is merely to move ALL tasks into the new
cgroup, it is sufficient to iterate until no more threads are
being created in the old group, and ignoring any threads that
die before we can move them.
It would be nicer to start the threads in the right cgroup to
begin with, but by default, all child threads are created in
the same cgroup as their parent, and we don't want vcpu child
threads in the emulator cgroup, so I don't see any good way
of avoiding the move. It would also be nice if the kernel were
to implement something like rename() as a way to atomically move
a group of threads from one cgroup to another, instead of forcing
a window where we have to read and parse the source, then format
and write back into the destination.
* src/util/vircgroup.c (virCgroupAddTaskStrController): Ignore
ESRCH, because a thread ended between read and write attempts.
(virCgroupMoveTask): Loop until all threads have moved.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
src/util/vircgroup.c | 28 ++++++++++++++++++++--------
1 file changed, 20 insertions(+), 8 deletions(-)
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 07ea2c3..6d44694 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -1037,7 +1037,11 @@ static int virCgroupAddTaskStrController(virCgroupPtr group,
goto cleanup;
rc = virCgroupAddTaskController(group, p, controller);
- if (rc != 0)
+ /* A thread that exits between when we first read the source
+ * tasks and now is not fatal. */
+ if (rc == -ESRCH)
+ rc = 0;
+ else if (rc != 0)
goto cleanup;
next = strchr(cur, '\n');
@@ -1074,15 +1078,23 @@ int virCgroupMoveTask(virCgroupPtr src_group, virCgroupPtr dest_group)
!dest_group->controllers[i].mountPoint)
continue;
- rc = virCgroupGetValueStr(src_group, i, "tasks", &content);
- if (rc != 0)
- return rc;
+ /* New threads are created in the same group as their parent;
+ * but if a thread is created after we first read we aren't
+ * aware that it needs to move. Therefore, we must iterate
+ * until content is empty. */
+ while (1) {
+ rc = virCgroupGetValueStr(src_group, i, "tasks", &content);
+ if (rc != 0)
+ return rc;
+ if (!*content)
+ break;
- rc = virCgroupAddTaskStrController(dest_group, content, i);
- if (rc != 0)
- goto cleanup;
+ rc = virCgroupAddTaskStrController(dest_group, content, i);
+ if (rc != 0)
+ goto cleanup;
- VIR_FREE(content);
+ VIR_FREE(content);
+ }
}
cleanup:
--
1.8.1.4
11 years, 6 months
[libvirt] [PATCH] interface: list all interfaces with flags == 0
by Guannan Ren
virConnectListAllInterfaces should support to list all of
interfaces when the value of flags is 0. The behaviour is
consistent with other virConnectListAll* APIs
---
src/conf/interface_conf.h | 4 ++++
src/interface/interface_backend_netcf.c | 27 +++++++++++++--------------
src/interface/interface_backend_udev.c | 23 ++++++++++-------------
3 files changed, 27 insertions(+), 27 deletions(-)
diff --git a/src/conf/interface_conf.h b/src/conf/interface_conf.h
index e636c35..ae93811 100644
--- a/src/conf/interface_conf.h
+++ b/src/conf/interface_conf.h
@@ -211,4 +211,8 @@ char *virInterfaceDefFormat(const virInterfaceDefPtr def);
void virInterfaceObjLock(virInterfaceObjPtr obj);
void virInterfaceObjUnlock(virInterfaceObjPtr obj);
+#define VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE \
+ (VIR_CONNECT_LIST_INTERFACES_ACTIVE | \
+ VIR_CONNECT_LIST_INTERFACES_INACTIVE)
+
#endif /* __INTERFACE_CONF_H__ */
diff --git a/src/interface/interface_backend_netcf.c b/src/interface/interface_backend_netcf.c
index cbba4fd..c6e069a 100644
--- a/src/interface/interface_backend_netcf.c
+++ b/src/interface/interface_backend_netcf.c
@@ -260,6 +260,7 @@ static int netcfConnectListDefinedInterfaces(virConnectPtr conn, char **const na
}
+#define MATCH(FLAG) (flags & (FLAG))
static int
netcfConnectListAllInterfaces(virConnectPtr conn,
virInterfacePtr **ifaces,
@@ -276,8 +277,7 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
int ret = -1;
char **names = NULL;
- virCheckFlags(VIR_CONNECT_LIST_INTERFACES_ACTIVE |
- VIR_CONNECT_LIST_INTERFACES_INACTIVE, -1);
+ virCheckFlags(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE, -1);
interfaceDriverLock(driver);
@@ -293,7 +293,6 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
_("failed to get number of host interfaces: %s%s%s"),
errmsg, details ? " - " : "",
details ? details : "");
- ret = -1;
goto cleanup;
}
@@ -304,7 +303,6 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
if (VIR_ALLOC_N(names, count) < 0) {
virReportOOMError();
- ret = -1;
goto cleanup;
}
@@ -361,16 +359,17 @@ netcfConnectListAllInterfaces(virConnectPtr conn,
/* XXX: Filter the result, need to be splitted once new filter flags
* except active|inactive are supported.
*/
- if (((status & NETCF_IFACE_ACTIVE) &&
- (flags & VIR_CONNECT_LIST_INTERFACES_ACTIVE)) ||
- ((status & NETCF_IFACE_INACTIVE) &&
- (flags & VIR_CONNECT_LIST_INTERFACES_INACTIVE))) {
- if (ifaces) {
- iface_obj = virGetInterface(conn, ncf_if_name(iface),
- ncf_if_mac_string(iface));
- tmp_iface_objs[niface_objs] = iface_obj;
- }
- niface_objs++;
+ if (MATCH(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE) &&
+ !((MATCH(VIR_CONNECT_LIST_INTERFACES_ACTIVE) &&
+ (status & NETCF_IFACE_ACTIVE)) ||
+ (MATCH(VIR_CONNECT_LIST_INTERFACES_INACTIVE) &&
+ (status & NETCF_IFACE_INACTIVE))))
+ continue;
+
+ if (ifaces) {
+ iface_obj = virGetInterface(conn, ncf_if_name(iface),
+ ncf_if_mac_string(iface));
+ tmp_iface_objs[niface_objs++] = iface_obj;
}
ncf_if_free(iface);
diff --git a/src/interface/interface_backend_udev.c b/src/interface/interface_backend_udev.c
index 1fd7d46..242fc15 100644
--- a/src/interface/interface_backend_udev.c
+++ b/src/interface/interface_backend_udev.c
@@ -282,6 +282,7 @@ udevConnectListDefinedInterfaces(virConnectPtr conn,
VIR_UDEV_IFACE_INACTIVE);
}
+#define MATCH(FLAG) (flags & (FLAG))
static int
udevConnectListAllInterfaces(virConnectPtr conn,
virInterfacePtr **ifaces,
@@ -299,8 +300,7 @@ udevConnectListAllInterfaces(virConnectPtr conn,
int status = 0;
int ret;
- virCheckFlags(VIR_CONNECT_LIST_INTERFACES_ACTIVE |
- VIR_CONNECT_LIST_INTERFACES_INACTIVE, -1);
+ virCheckFlags(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE, -1);
/* Grab a udev reference */
udev = udev_ref(driverState->udev);
@@ -354,7 +354,6 @@ udevConnectListAllInterfaces(virConnectPtr conn,
const char *path;
const char *name;
const char *macaddr;
- int add_to_list = 0;
path = udev_list_entry_get_name(dev_entry);
dev = udev_device_new_from_syspath(udev, path);
@@ -363,18 +362,15 @@ udevConnectListAllInterfaces(virConnectPtr conn,
status = STREQ(udev_device_get_sysattr_value(dev, "operstate"), "up");
/* Filter the results */
- if (status && (flags & VIR_CONNECT_LIST_INTERFACES_ACTIVE))
- add_to_list = 1;
- else if (!status && (flags & VIR_CONNECT_LIST_INTERFACES_INACTIVE))
- add_to_list = 1;
+ if (MATCH(VIR_CONNECT_LIST_INTERFACES_FILTERS_ACTIVE) &&
+ !((MATCH(VIR_CONNECT_LIST_INTERFACES_ACTIVE) && status) ||
+ (MATCH(VIR_CONNECT_LIST_INTERFACES_INACTIVE) && !status)))
+ continue;
/* If we matched a filter, then add it */
- if (add_to_list) {
- if (ifaces) {
- iface_obj = virGetInterface(conn, name, macaddr);
- ifaces_list[count] = iface_obj;
- }
- count++;
+ if (ifaces) {
+ iface_obj = virGetInterface(conn, name, macaddr);
+ ifaces_list[count++] = iface_obj;
}
udev_device_unref(dev);
}
@@ -387,6 +383,7 @@ udevConnectListAllInterfaces(virConnectPtr conn,
if (ifaces) {
ignore_value(VIR_REALLOC_N(ifaces_list, count + 1));
*ifaces = ifaces_list;
+ ifaces_list = NULL;
}
return count;
--
1.8.1.4
11 years, 6 months
[libvirt] [PATCH] qemu: Don't remove the "return 0"
by Osier Yang
Commit f60a50c7957 intended to remove the warning only, but not with
the "return 0" together.
---
src/qemu/qemu_cgroup.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index ff9a075..fb88802 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -471,6 +471,8 @@ qemuSetupMemoryCgroup(virDomainObjPtr vm)
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Memory cgroup is not available on this host"));
return -1;
+ } else {
+ return 0;
}
}
--
1.8.1.4
11 years, 6 months
[libvirt] [PATCH] udev: should not list bridge devices
by Guannan Ren
When using udev backend, virsh iface-list outputs bridge devices
like:
Name State MAC Address
--------------------------------------------
em1 active e8:39:35:58:d5:94
lo active 00:00:00:00:00:00
virbr0 active fe:54:00:a5:f6:42
The patch filters out bridge devices.
---
src/interface/interface_backend_udev.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/interface/interface_backend_udev.c b/src/interface/interface_backend_udev.c
index 1fd7d46..92648e8 100644
--- a/src/interface/interface_backend_udev.c
+++ b/src/interface/interface_backend_udev.c
@@ -78,6 +78,9 @@ udevGetDevices(struct udev *udev, virUdevStatus status)
/* Ignore devices that are part of a bridge */
udev_enumerate_add_nomatch_sysattr(enumerate, "brport/state", NULL);
+ /* Ignore bridge devices */
+ udev_enumerate_add_nomatch_sysattr(enumerate, "bridge/bridge_id", NULL);
+
/* State of the device */
switch (status) {
case VIR_UDEV_IFACE_ACTIVE:
--
1.8.1.4
11 years, 6 months
[libvirt] [PATCH 0/3] Resolve Coverity found issues
by John Ferlan
Upgraded to Coverity 6.5.3 which uncovered a few code paths with issues.
John Ferlan (3):
lxc_process: Resolve Coverity NULL_RETURNS error
xencapstest: Resolve Coverity CHECKED_RETURN error
shunloadtest: Resolve Coverity CHECKED_RETURN error
src/lxc/lxc_process.c | 4 ++--
tests/shunloadhelper.c | 12 ++++++++----
tests/shunloadtest.c | 26 +++++++++++++++++---------
tests/xencapstest.c | 3 ++-
4 files changed, 29 insertions(+), 16 deletions(-)
--
1.8.1.4
11 years, 6 months
[libvirt] [PATCH 0/3 v3]add 'sharePolicy' attribute for qemu vnc sharing policy
by Guannan Ren
v2->v3
rebase work.
v1->v2:
changed attribute name from 'policy' to 'sharePolicy'
renamed caps flag name: QEMU_CAPS_VNC_SHARE_POLICY
fixed issues pointed out in v1 review
have to keep hard-coded version probe after checking qemu -help and qmp command.
As there were some vnc patches recently, I chose do rebase work a little later.
These patches try to add a new attribute 'sharePolicy' to element graphics of
vnc type. This attribute has three values:
allow-exclusive,force-shared and ignore.
Guannan Ren(3)
[PATCH 1/3 v3] qemu: new vnc display sharing policy caps flag
[PATCH 2/3 v3] conf: add 'sharePolicy' attribute to graphics element for
[PATCH 3/3 v3] qemu: add ',share=<policy>' to qemu commandline
docs/formatdomain.html.in | 13 +++++++++++--
docs/schemas/domaincommon.rng | 9 +++++++++
src/conf/domain_conf.c | 28 ++++++++++++++++++++++++++++
src/conf/domain_conf.h | 11 +++++++++++
src/libvirt_private.syms | 2 ++
src/qemu/qemu_capabilities.c | 6 +++++-
src/qemu/qemu_capabilities.h | 1 +
src/qemu/qemu_command.c | 36 ++++++++++++++++++++++++++++++++++++
tests/qemuargv2xmltest.c | 1 +
tests/qemuhelptest.c | 9 ++++++---
tests/qemuxml2argvtest.c | 1 +
11 files changed, 111 insertions(+), 6 deletions(-)
11 years, 6 months
[libvirt] [PATCH] qemu: fix a typo in qemuAddSharedDevice
by Guannan Ren
---
src/qemu/qemu_conf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 41fe0b9..7266d3b 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1184,7 +1184,7 @@ qemuAddSharedDevice(virQEMUDriverPtr driver,
if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
disk = dev->data.disk;
- if (disk->shared ||
+ if (!disk->shared ||
!disk->src ||
(disk->type != VIR_DOMAIN_DISK_TYPE_BLOCK &&
!(disk->type == VIR_DOMAIN_DISK_TYPE_VOLUME &&
--
1.8.1.4
11 years, 6 months