[libvirt] [PATCH 0/2] qemu: support new HyperV-related features
by Ján Tomko
1/2 prevents memory leaks and hair loss in qemuParseCommandLineCPU
2/2 adds support for the new cpu flags
https://bugzilla.redhat.com/show_bug.cgi?id=784836
Ján Tomko (2):
qemu: use strsep for CPU command line parsing
qemu: add hv_vapic and hv_spinlocks support
docs/formatdomain.html.in | 17 ++-
docs/schemas/domaincommon.rng | 12 ++
src/conf/domain_conf.c | 39 ++++++-
src/conf/domain_conf.h | 3 +
src/qemu/qemu_command.c | 145 +++++++++++++-----------
tests/qemuxml2argvdata/qemuxml2argv-hyperv.args | 2 +-
tests/qemuxml2argvdata/qemuxml2argv-hyperv.xml | 2 +
7 files changed, 148 insertions(+), 72 deletions(-)
--
1.8.1.5
11 years, 6 months
[libvirt] [PATCH 0/2] Fix forgetting of transient networks on daemon restart
by Peter Krempa
Peter Krempa (2):
network: remove autostart flag from network when undefining it
network: bridge_driver: don't lose transient networks on daemon
restart
src/conf/network_conf.c | 220 +++++++++++++++++++++++++++++---------------
src/conf/network_conf.h | 10 +-
src/libvirt_private.syms | 2 +-
src/network/bridge_driver.c | 52 +++++++----
4 files changed, 185 insertions(+), 99 deletions(-)
--
1.8.1.5
11 years, 6 months
[libvirt] [libvirt-glib] object: Add "transfer none" annotation to argv parameter
by Christophe Fergeau
This makes the parameter to be passed "unowned" in Vala. This was
previously done using a vala metadata file, but it's better to do
it directly through a gtk-doc annotation, as this means the gir
file will know about this, and thus any gir-based binding can
make use of this info.
This also makes libvirt-gobject consistent with what was done
for gconfig and glib in commit 431720.
---
libvirt-gobject/libvirt-gobject-main.c | 4 ++--
vapi/LibvirtGObject-1.0.metadata | 2 --
vapi/Makefile.am | 2 +-
3 files changed, 3 insertions(+), 5 deletions(-)
delete mode 100644 vapi/LibvirtGObject-1.0.metadata
diff --git a/libvirt-gobject/libvirt-gobject-main.c b/libvirt-gobject/libvirt-gobject-main.c
index 31d2514..11ea24a 100644
--- a/libvirt-gobject/libvirt-gobject-main.c
+++ b/libvirt-gobject/libvirt-gobject-main.c
@@ -33,7 +33,7 @@
/**
* gvir_init_object:
* @argc: (inout): pointer to application's argc
- * @argv: (inout) (array length=argc) (allow-none): pointer to application's argv
+ * @argv: (inout) (array length=argc) (allow-none) (transfer none): pointer to application's argv
*/
void gvir_init_object(int *argc,
char ***argv)
@@ -58,7 +58,7 @@ static void gvir_log_handler(const gchar *log_domain G_GNUC_UNUSED,
/**
* gvir_init_object_check:
* @argc: (inout): pointer to application's argc
- * @argv: (inout) (array length=argc) (allow-none): pointer to application's argv
+ * @argv: (inout) (array length=argc) (allow-none) (transfer none): pointer to application's argv
* @err: pointer to a #GError to which a message will be posted on error
*/
gboolean gvir_init_object_check(int *argc,
diff --git a/vapi/LibvirtGObject-1.0.metadata b/vapi/LibvirtGObject-1.0.metadata
deleted file mode 100644
index 90e5197..0000000
--- a/vapi/LibvirtGObject-1.0.metadata
+++ /dev/null
@@ -1,2 +0,0 @@
-init_object.argv unowned
-init_object_check.argv unowned
diff --git a/vapi/Makefile.am b/vapi/Makefile.am
index 2ecc3e3..0154104 100644
--- a/vapi/Makefile.am
+++ b/vapi/Makefile.am
@@ -44,4 +44,4 @@ CLEANFILES = \
libvirt-gobject-1.0.vapi \
$(NULL)
-EXTRA_DIST = LibvirtGObject-1.0.metadata libvirt-gobject-1.0.deps
+EXTRA_DIST = libvirt-gobject-1.0.deps
--
1.8.1.4
11 years, 6 months
[libvirt] [PATCH] Fix potential use of undefined variable in remote dispatch code
by Daniel P. Berrange
From: "Daniel P. Berrange" <berrange(a)redhat.com>
If an early dispatch check caused a jump to the 'cleanup' branch
then virTypeParamsFree() would be called with an uninitialized
'nparams' variable. Fortunately 'params' is initialized to NULL,
so the uninitialized 'nparams' variable would not be used.
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
src/rpc/gendispatch.pl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl
index 7b93062..8d3b013 100755
--- a/src/rpc/gendispatch.pl
+++ b/src/rpc/gendispatch.pl
@@ -495,7 +495,7 @@ elsif ($mode eq "server") {
push(@args_list, "args->$1.$1_len");
} elsif ($args_member =~ m/^remote_typed_param (\S+)<(\S+)>;/) {
push(@vars_list, "virTypedParameterPtr $1 = NULL");
- push(@vars_list, "int n$1");
+ push(@vars_list, "int n$1 = 0;");
if ($call->{ProcName} eq "NodeSetMemoryParameters") {
push(@args_list, "priv->conn");
}
--
1.8.2.1
11 years, 6 months
[libvirt] [PATCH] More paranoid initialization of 'nparams' variable in dispatch code
by Daniel P. Berrange
From: "Daniel P. Berrange" <berrange(a)redhat.com>
Since the 'nparams' variable passed to virTypedParametersFree is
supposed to represent the size of the 'params' array, it is bad
practice to initialize it to a non-zero value, until the array
has been allocated.
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
daemon/remote.c | 78 ++++++++++++++++++++++++++++++++-------------------------
1 file changed, 44 insertions(+), 34 deletions(-)
diff --git a/daemon/remote.c b/daemon/remote.c
index e5e3f2c..c5567f4 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -1001,7 +1001,7 @@ remoteDispatchDomainGetSchedulerParameters(virNetServerPtr server ATTRIBUTE_UNUS
{
virDomainPtr dom = NULL;
virTypedParameterPtr params = NULL;
- int nparams = args->nparams;
+ int nparams = 0;
int rv = -1;
struct daemonClientPrivate *priv =
virNetServerClientGetPrivateData(client);
@@ -1011,12 +1011,13 @@ remoteDispatchDomainGetSchedulerParameters(virNetServerPtr server ATTRIBUTE_UNUS
goto cleanup;
}
- if (nparams > REMOTE_DOMAIN_SCHEDULER_PARAMETERS_MAX) {
+ if (args->nparams > REMOTE_DOMAIN_SCHEDULER_PARAMETERS_MAX) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"));
goto cleanup;
}
- if (nparams && VIR_ALLOC_N(params, nparams) < 0)
+ if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0)
goto no_memory;
+ nparams = args->nparams;
if (!(dom = get_nonnull_domain(priv->conn, args->dom)))
goto cleanup;
@@ -1109,7 +1110,7 @@ remoteDispatchDomainGetSchedulerParametersFlags(virNetServerPtr server ATTRIBUTE
{
virDomainPtr dom = NULL;
virTypedParameterPtr params = NULL;
- int nparams = args->nparams;
+ int nparams = 0;
int rv = -1;
struct daemonClientPrivate *priv =
virNetServerClientGetPrivateData(client);
@@ -1119,12 +1120,13 @@ remoteDispatchDomainGetSchedulerParametersFlags(virNetServerPtr server ATTRIBUTE
goto cleanup;
}
- if (nparams > REMOTE_DOMAIN_SCHEDULER_PARAMETERS_MAX) {
+ if (args->nparams > REMOTE_DOMAIN_SCHEDULER_PARAMETERS_MAX) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"));
goto cleanup;
}
- if (nparams && VIR_ALLOC_N(params, nparams) < 0)
+ if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0)
goto no_memory;
+ nparams = args->nparams;
if (!(dom = get_nonnull_domain(priv->conn, args->dom)))
goto cleanup;
@@ -1284,7 +1286,7 @@ remoteDispatchDomainBlockStatsFlags(virNetServerPtr server ATTRIBUTE_UNUSED,
virTypedParameterPtr params = NULL;
virDomainPtr dom = NULL;
const char *path = args->path;
- int nparams = args->nparams;
+ int nparams = 0;
unsigned int flags;
int rv = -1;
struct daemonClientPrivate *priv =
@@ -1299,14 +1301,15 @@ remoteDispatchDomainBlockStatsFlags(virNetServerPtr server ATTRIBUTE_UNUSED,
goto cleanup;
flags = args->flags;
- if (nparams > REMOTE_DOMAIN_BLOCK_STATS_PARAMETERS_MAX) {
+ if (args->nparams > REMOTE_DOMAIN_BLOCK_STATS_PARAMETERS_MAX) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"));
goto cleanup;
}
- if (nparams && VIR_ALLOC_N(params, nparams) < 0) {
+ if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0) {
virReportOOMError();
goto cleanup;
}
+ nparams = args->nparams;
if (virDomainBlockStatsFlags(dom, path, params, &nparams, flags) < 0)
goto cleanup;
@@ -1913,7 +1916,7 @@ remoteDispatchDomainGetMemoryParameters(virNetServerPtr server ATTRIBUTE_UNUSED,
{
virDomainPtr dom = NULL;
virTypedParameterPtr params = NULL;
- int nparams = args->nparams;
+ int nparams = 0;
unsigned int flags;
int rv = -1;
struct daemonClientPrivate *priv =
@@ -1926,14 +1929,15 @@ remoteDispatchDomainGetMemoryParameters(virNetServerPtr server ATTRIBUTE_UNUSED,
flags = args->flags;
- if (nparams > REMOTE_DOMAIN_MEMORY_PARAMETERS_MAX) {
+ if (args->nparams > REMOTE_DOMAIN_MEMORY_PARAMETERS_MAX) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"));
goto cleanup;
}
- if (nparams && VIR_ALLOC_N(params, nparams) < 0) {
+ if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0) {
virReportOOMError();
goto cleanup;
}
+ nparams = args->nparams;
if (!(dom = get_nonnull_domain(priv->conn, args->dom)))
goto cleanup;
@@ -1977,7 +1981,7 @@ remoteDispatchDomainGetNumaParameters(virNetServerPtr server ATTRIBUTE_UNUSED,
{
virDomainPtr dom = NULL;
virTypedParameterPtr params = NULL;
- int nparams = args->nparams;
+ int nparams = 0;
unsigned int flags;
int rv = -1;
struct daemonClientPrivate *priv =
@@ -1990,14 +1994,15 @@ remoteDispatchDomainGetNumaParameters(virNetServerPtr server ATTRIBUTE_UNUSED,
flags = args->flags;
- if (nparams > REMOTE_DOMAIN_NUMA_PARAMETERS_MAX) {
+ if (args->nparams > REMOTE_DOMAIN_NUMA_PARAMETERS_MAX) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"));
goto cleanup;
}
- if (nparams && VIR_ALLOC_N(params, nparams) < 0) {
+ if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0) {
virReportOOMError();
goto cleanup;
}
+ nparams = args->nparams;
if (!(dom = get_nonnull_domain(priv->conn, args->dom)))
goto cleanup;
@@ -2041,7 +2046,7 @@ remoteDispatchDomainGetBlkioParameters(virNetServerPtr server ATTRIBUTE_UNUSED,
{
virDomainPtr dom = NULL;
virTypedParameterPtr params = NULL;
- int nparams = args->nparams;
+ int nparams = 0;
unsigned int flags;
int rv = -1;
struct daemonClientPrivate *priv =
@@ -2054,14 +2059,15 @@ remoteDispatchDomainGetBlkioParameters(virNetServerPtr server ATTRIBUTE_UNUSED,
flags = args->flags;
- if (nparams > REMOTE_DOMAIN_BLKIO_PARAMETERS_MAX) {
+ if (args->nparams > REMOTE_DOMAIN_BLKIO_PARAMETERS_MAX) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"));
goto cleanup;
}
- if (nparams && VIR_ALLOC_N(params, nparams) < 0) {
+ if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0) {
virReportOOMError();
goto cleanup;
}
+ nparams = args->nparams;
if (!(dom = get_nonnull_domain(priv->conn, args->dom)))
goto cleanup;
@@ -2106,7 +2112,7 @@ remoteDispatchNodeGetCPUStats(virNetServerPtr server ATTRIBUTE_UNUSED,
virNodeCPUStatsPtr params = NULL;
int i;
int cpuNum = args->cpuNum;
- int nparams = args->nparams;
+ int nparams = 0;
unsigned int flags;
int rv = -1;
struct daemonClientPrivate *priv =
@@ -2119,14 +2125,15 @@ remoteDispatchNodeGetCPUStats(virNetServerPtr server ATTRIBUTE_UNUSED,
flags = args->flags;
- if (nparams > REMOTE_NODE_CPU_STATS_MAX) {
+ if (args->nparams > REMOTE_NODE_CPU_STATS_MAX) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"));
goto cleanup;
}
- if (VIR_ALLOC_N(params, nparams) < 0) {
+ if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0) {
virReportOOMError();
goto cleanup;
}
+ nparams = args->nparams;
if (virNodeGetCPUStats(priv->conn, cpuNum, params, &nparams, flags) < 0)
goto cleanup;
@@ -2184,7 +2191,7 @@ remoteDispatchNodeGetMemoryStats(virNetServerPtr server ATTRIBUTE_UNUSED,
virNodeMemoryStatsPtr params = NULL;
int i;
int cellNum = args->cellNum;
- int nparams = args->nparams;
+ int nparams = 0;
unsigned int flags;
int rv = -1;
struct daemonClientPrivate *priv =
@@ -2197,14 +2204,15 @@ remoteDispatchNodeGetMemoryStats(virNetServerPtr server ATTRIBUTE_UNUSED,
flags = args->flags;
- if (nparams > REMOTE_NODE_MEMORY_STATS_MAX) {
+ if (args->nparams > REMOTE_NODE_MEMORY_STATS_MAX) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"));
goto cleanup;
}
- if (VIR_ALLOC_N(params, nparams) < 0) {
+ if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0) {
virReportOOMError();
goto cleanup;
}
+ nparams = args->nparams;
if (virNodeGetMemoryStats(priv->conn, cellNum, params, &nparams, flags) < 0)
goto cleanup;
@@ -2303,7 +2311,7 @@ remoteDispatchDomainGetBlockIoTune(virNetServerPtr server ATTRIBUTE_UNUSED,
virDomainPtr dom = NULL;
int rv = -1;
virTypedParameterPtr params = NULL;
- int nparams = args->nparams;
+ int nparams = 0;
struct daemonClientPrivate *priv =
virNetServerClientGetPrivateData(client);
@@ -2312,15 +2320,16 @@ remoteDispatchDomainGetBlockIoTune(virNetServerPtr server ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (nparams > REMOTE_DOMAIN_BLOCK_IO_TUNE_PARAMETERS_MAX) {
+ if (args->nparams > REMOTE_DOMAIN_BLOCK_IO_TUNE_PARAMETERS_MAX) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"));
goto cleanup;
}
- if (nparams && VIR_ALLOC_N(params, nparams) < 0) {
+ if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0) {
virReportOOMError();
goto cleanup;
}
+ nparams = args->nparams;
if (!(dom = get_nonnull_domain(priv->conn, args->dom)))
goto cleanup;
@@ -3800,7 +3809,7 @@ remoteDispatchDomainGetInterfaceParameters(virNetServerPtr server ATTRIBUTE_UNUS
virDomainPtr dom = NULL;
virTypedParameterPtr params = NULL;
const char *device = args->device;
- int nparams = args->nparams;
+ int nparams = 0;
unsigned int flags;
int rv = -1;
struct daemonClientPrivate *priv =
@@ -3813,14 +3822,15 @@ remoteDispatchDomainGetInterfaceParameters(virNetServerPtr server ATTRIBUTE_UNUS
flags = args->flags;
- if (nparams > REMOTE_DOMAIN_INTERFACE_PARAMETERS_MAX) {
+ if (args->nparams > REMOTE_DOMAIN_INTERFACE_PARAMETERS_MAX) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"));
goto cleanup;
}
- if (nparams && VIR_ALLOC_N(params, nparams) < 0) {
+ if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0) {
virReportOOMError();
goto cleanup;
}
+ nparams = args->nparams;
if (!(dom = get_nonnull_domain(priv->conn, args->dom)))
goto cleanup;
@@ -4508,7 +4518,7 @@ remoteDispatchNodeGetMemoryParameters(virNetServerPtr server ATTRIBUTE_UNUSED,
remote_node_get_memory_parameters_ret *ret)
{
virTypedParameterPtr params = NULL;
- int nparams = args->nparams;
+ int nparams = 0;
unsigned int flags;
int rv = -1;
struct daemonClientPrivate *priv =
@@ -4521,15 +4531,15 @@ remoteDispatchNodeGetMemoryParameters(virNetServerPtr server ATTRIBUTE_UNUSED,
flags = args->flags;
- if (nparams > REMOTE_NODE_MEMORY_PARAMETERS_MAX) {
+ if (args->nparams > REMOTE_NODE_MEMORY_PARAMETERS_MAX) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"));
goto cleanup;
}
- if (nparams && VIR_ALLOC_N(params, nparams) < 0) {
+ if (args->nparams && VIR_ALLOC_N(params, args->nparams) < 0) {
virReportOOMError();
goto cleanup;
}
-
+ nparams = args->nparams;
if (virNodeGetMemoryParameters(priv->conn, params, &nparams, flags) < 0)
goto cleanup;
--
1.8.2.1
11 years, 6 months
[libvirt] [RFC] New API to retrieve node CPU map
by Viktor Mihajlovski
Hi,
in order to use the APIs listed below it is necessary for a client to
know the maximum number of node CPUs which is passed via the maplen
argument.
virDomainGetEmulatorPinInfo
virDomainGetVcpuPinInfo
virDomainGetVcpus
virDomainPinEmulator
virDomainPinVcpu
virDomainPinVcpuFlags
The current approach uses virNodeGetInfo to determine the maximum CPU
number. This can lead to incorrect results if not all node CPUs are
online. The maximum CPU number should always be the number of CPUs
present on the host, regardless of their online/offline state.
The following example illustrates the issue:
Host has 3 logical CPUs, 1 socket, 3 cores, 1 thread.
Guest has 1 virtual CPU and is started while all 3 host CPUs are
online.
$ virsh vcpuinfo guest
VCPU: 0
CPU: 0
State: running
CPU time: 35.4s
CPU Affinity: yyy
$ echo 0 > /sys/devices/system/cpu/cpu1/online
$ virsh vcpuinfo guest
VCPU: 0
CPU: 0
State: running
CPU time: 35.5s
CPU Affinity: y-
The correct display for CPU affinity would have been y-y, as the guest
continues to use CPUs 0 and 2.
This is not a display problem only, because it is also not possible to
explicitly pin the virtual CPU to host CPUs 0 and 2, due to the
truncated CPU mask.
PROPOSAL:
To help solve the issue above I suggest two new public API functions:
int
virNodeGetCpuNum(virConnectPtr conn);
returning the number of present CPUs on the host or -1 upon failure
and
int
virNodeGetCpuMap(virConnectPtr conn, unsigned char * cpumap, int maplen);
returning the number of present CPUs or -1 on failure and storing a bit
map of real CPUs as described in virDomainPinVcpu in cpumap. The bits in
the bit map are set to 1 for online CPUs and set to 0 for offline CPUs.
Implementation is facilitated by the function nodeGetCPUmap in nodeinfo.c.
Clients can use virNodeGetCpuNum to properly determine the maximum
number of node CPUs and the online/offline information.
Thanks for your comments.
--
Mit freundlichen Grüßen/Kind Regards
Viktor Mihajlovski
IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Martin Jetter
Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294
11 years, 6 months
[libvirt] [PATCH] portability: handle ifreq differences in virnetdev
by Roman Bogorodskiy
FreeBSD (and maybe other BSDs) have different member
names in struct ifreq when compared to Linux, such as:
- uses ifr_data instead of ifr_newname for setting
interface names
- uses ifr_index instead of ifr_ifindex for interface
index
Also, add a check for SIOCGIFHWADDR for virNetDevValidateConfig().
Use AF_LOCAL if AF_PACKET is not available.
---
configure.ac | 8 ++++++++
src/util/virnetdev.c | 23 +++++++++++++++++------
2 files changed, 25 insertions(+), 6 deletions(-)
diff --git a/configure.ac b/configure.ac
index 23c24d2..4a32f8c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2363,6 +2363,14 @@ AM_CONDITIONAL([HAVE_LIBNL], [test "$have_libnl" = "yes"])
AC_SUBST([LIBNL_CFLAGS])
AC_SUBST([LIBNL_LIBS])
+AC_CHECK_MEMBERS([struct ifreq.ifr_newname,
+ struct ifreq.ifr_ifindex,
+ struct ifreq.ifr_index],
+ [], [],
+ [#include <sys/ioctl.h>
+ #include <net/if.h>
+ ])
+
# Only COPYING.LIB is under version control, yet COPYING
# is included as part of the distribution tarball.
# Copy one to the other, but only if this is a srcdir-build.
diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index 7ffaac1..02c1716 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -38,7 +38,10 @@
#ifdef __linux__
# include <linux/sockios.h>
# include <linux/if_vlan.h>
-#elif !defined(AF_PACKET)
+# define VIR_NETDEV_FAMILY AF_PACKET
+#elif defined(HAVE_STRUCT_IFREQ) && defined(AF_LOCAL)
+# define VIR_NETDEV_FAMILY AF_LOCAL
+#else
# undef HAVE_STRUCT_IFREQ
#endif
@@ -81,7 +84,7 @@ static int virNetDevSetupControlFull(const char *ifname,
static int virNetDevSetupControl(const char *ifname,
struct ifreq *ifr)
{
- return virNetDevSetupControlFull(ifname, ifr, AF_PACKET, SOCK_DGRAM);
+ return virNetDevSetupControlFull(ifname, ifr, VIR_NETDEV_FAMILY, SOCK_DGRAM);
}
#endif
@@ -478,12 +481,16 @@ int virNetDevSetName(const char* ifname, const char *newifname)
if ((fd = virNetDevSetupControl(ifname, &ifr)) < 0)
return -1;
+#if !defined(HAVE_STRUCT_IFREQ_IFR_NEWNAME)
+ ifr.ifr_data = (caddr_t)newifname;
+#else
if (virStrcpyStatic(ifr.ifr_newname, newifname) == NULL) {
virReportSystemError(ERANGE,
_("Network interface name '%s' is too long"),
newifname);
goto cleanup;
}
+#endif
if (ioctl(fd, SIOCSIFNAME, &ifr)) {
virReportSystemError(errno,
@@ -630,7 +637,7 @@ int virNetDevGetIndex(const char *ifname, int *ifindex)
{
int ret = -1;
struct ifreq ifreq;
- int fd = socket(PF_PACKET, SOCK_DGRAM, 0);
+ int fd = socket(VIR_NETDEV_FAMILY, SOCK_DGRAM, 0);
if (fd < 0) {
virReportSystemError(errno, "%s",
@@ -654,7 +661,11 @@ int virNetDevGetIndex(const char *ifname, int *ifindex)
goto cleanup;
}
+#if defined(HAVE_STRUCT_IFREQ_IFR_INDEX)
+ *ifindex = ifreq.ifr_index;
+#else
*ifindex = ifreq.ifr_ifindex;
+#endif
ret = 0;
cleanup:
@@ -870,7 +881,7 @@ int virNetDevGetIPv4Address(const char *ifname ATTRIBUTE_UNUSED,
*
* Returns 1 if the config matches, 0 if the config does not match, or interface does not exist, -1 on error
*/
-#if defined(HAVE_STRUCT_IFREQ)
+#if defined(SIOCGIFHWADDR) && defined(HAVE_STRUCT_IFREQ)
int virNetDevValidateConfig(const char *ifname,
const virMacAddrPtr macaddr, int ifindex)
{
@@ -924,7 +935,7 @@ int virNetDevValidateConfig(const char *ifname,
VIR_FORCE_CLOSE(fd);
return ret;
}
-#else /* ! HAVE_STRUCT_IFREQ */
+#else
int virNetDevValidateConfig(const char *ifname ATTRIBUTE_UNUSED,
const virMacAddrPtr macaddr ATTRIBUTE_UNUSED,
int ifindex ATTRIBUTE_UNUSED)
@@ -933,7 +944,7 @@ int virNetDevValidateConfig(const char *ifname ATTRIBUTE_UNUSED,
_("Unable to check interface config on this platform"));
return -1;
}
-#endif /* ! HAVE_STRUCT_IFREQ */
+#endif
#ifdef __linux__
--
1.8.0
11 years, 6 months
[libvirt] [PATCH] Remove redundant () in expression
by Daniel P. Berrange
From: "Daniel P. Berrange" <berrange(a)redhat.com>
The use of () in a simple boolean comparison was not
required
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
src/qemu/qemu_command.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 7d851e3..77452f0 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3100,7 +3100,7 @@ qemuBuildDriveStr(virConnectPtr conn ATTRIBUTE_UNUSED,
virBufferAsprintf(&opt, "if=%s", bus);
if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM) {
- if ((disk->bus == VIR_DOMAIN_DISK_BUS_SCSI)) {
+ if (disk->bus == VIR_DOMAIN_DISK_BUS_SCSI) {
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_SCSI_CD))
virBufferAddLit(&opt, ",media=cdrom");
} else if (disk->bus == VIR_DOMAIN_DISK_BUS_IDE) {
--
1.8.2.1
11 years, 6 months
[libvirt] [PATCH] Fix format string handling in network driver
by Daniel P. Berrange
From: "Daniel P. Berrange" <berrange(a)redhat.com>
The call to virReportError conditionally switched between
two format strings, with different numbers of placeholders.
This meant the format string with no placeholders was not
protected by a "%s".
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
src/network/bridge_driver.c | 36 +++++++++++++++++++++---------------
1 file changed, 21 insertions(+), 15 deletions(-)
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 8da28e4..327bb08 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -1601,11 +1601,13 @@ networkAddMasqueradingIptablesRules(struct network_driver *driver,
&network->def->forward.addr,
&network->def->forward.port,
NULL) < 0) {
- virReportError(VIR_ERR_SYSTEM_ERROR,
- forwardIf ?
- _("failed to add iptables rule to enable masquerading to %s") :
- _("failed to add iptables rule to enable masquerading"),
- forwardIf);
+ if (forwardIf)
+ virReportError(VIR_ERR_SYSTEM_ERROR,
+ _("failed to add iptables rule to enable masquerading to %s"),
+ forwardIf);
+ else
+ virReportError(VIR_ERR_SYSTEM_ERROR, "%s",
+ _("failed to add iptables rule to enable masquerading"));
goto masqerr3;
}
@@ -1617,11 +1619,13 @@ networkAddMasqueradingIptablesRules(struct network_driver *driver,
&network->def->forward.addr,
&network->def->forward.port,
"udp") < 0) {
- virReportError(VIR_ERR_SYSTEM_ERROR,
- forwardIf ?
- _("failed to add iptables rule to enable UDP masquerading to %s") :
- _("failed to add iptables rule to enable UDP masquerading"),
- forwardIf);
+ if (forwardIf)
+ virReportError(VIR_ERR_SYSTEM_ERROR,
+ _("failed to add iptables rule to enable UDP masquerading to %s"),
+ forwardIf);
+ else
+ virReportError(VIR_ERR_SYSTEM_ERROR, "%s",
+ _("failed to add iptables rule to enable UDP masquerading"));
goto masqerr4;
}
@@ -1633,11 +1637,13 @@ networkAddMasqueradingIptablesRules(struct network_driver *driver,
&network->def->forward.addr,
&network->def->forward.port,
"tcp") < 0) {
- virReportError(VIR_ERR_SYSTEM_ERROR,
- forwardIf ?
- _("failed to add iptables rule to enable TCP masquerading to %s") :
- _("failed to add iptables rule to enable TCP masquerading"),
- forwardIf);
+ if (forwardIf)
+ virReportError(VIR_ERR_SYSTEM_ERROR,
+ _("failed to add iptables rule to enable TCP masquerading to %s"),
+ forwardIf);
+ else
+ virReportError(VIR_ERR_SYSTEM_ERROR, "%s",
+ _("failed to add iptables rule to enable TCP masquerading"));
goto masqerr5;
}
--
1.8.2.1
11 years, 6 months
[libvirt] [sandbox PATCH] Add a option --package if rpm autodetection fail
by Michael Scherer
https://bugzilla.redhat.com/show_bug.cgi?id=954187
If someone use a custom unit file for the sandbox, the rpm
autodetection fail with a exception. Now, this will show
a error message, asking to use --package and use this rpm if
autodetection fail.
---
bin/virt-sandbox-service | 46 +++++++++++++++++++++++++++++++++----
bin/virt-sandbox-service-create.pod | 6 ++++-
2 files changed, 46 insertions(+), 6 deletions(-)
diff --git a/bin/virt-sandbox-service b/bin/virt-sandbox-service
index 3b78512..740209c 100755
--- a/bin/virt-sandbox-service
+++ b/bin/virt-sandbox-service
@@ -363,10 +363,11 @@ class SystemdContainer(Container):
DEFAULT_UNIT = "/etc/systemd/system/%s_sandbox.service"
- def __init__(self, name=None, uri = "lxc:///", path = Container.DEFAULT_PATH, config=None, create=False):
+ def __init__(self, name=None, uri = "lxc:///", path = Container.DEFAULT_PATH, config=None, create=False, rpm=None):
Container.__init__(self, name, uri, path, config, create)
self.copy = False
self.unit_file_list = []
+ self.rpm = rpm
if create:
self.config = LibvirtSandbox.ConfigServiceSystemd.new(name)
else:
@@ -496,8 +497,18 @@ WantedBy=%(TARGET)s
self.ts = rpm.ts()
+ nb_rpm = 0
for u, src in self.unit_file_list:
- self.extract_rpm_for_unit(src)
+ rpm_name = self.get_rpm_for_unit(src)
+ if rpm_name:
+ self.extract_rpm(rpm_name)
+ nb_rpm += 1
+
+ if nb_rpm == 0:
+ if self.rpm:
+ self.extract_rpm(self.rpm)
+ else:
+ raise ValueError([_("Cannot autodetect the package for unit files, please use --package")])
def split_filename(self, filename):
if filename[-4:] == '.rpm':
@@ -521,12 +532,21 @@ WantedBy=%(TARGET)s
name = filename[epochIndex + 1:verIndex]
return name, ver, rel, epoch, arch
- def extract_rpm_for_unit(self, unitfile):
+ def get_rpm_for_unit(self, unitfile):
mi = self.ts.dbMatch(rpm.RPMTAG_BASENAMES, unitfile)
try:
h = mi.next();
except exceptions.StopIteration:
- raise ValueError([_("Cannot find package containing %s") % unitfile])
+ return None
+ return h['name']
+
+
+ def extract_rpm(self, rpm_name):
+ mi = self.ts.dbMatch('name', rpm_name)
+ try:
+ h = mi.next();
+ except exceptions.StopIteration:
+ raise ValueError([_("Cannot find package named %s") % rpm_name])
for fentry in h.fiFromHeader():
fname = fentry[0]
@@ -765,11 +785,14 @@ def create(args):
if len(args.command) == 0 and len(args.unitfiles) == 0:
raise ValueError([_("You must specify a command or a unit file")])
+ if args.rpm and len(args.unitfiles) != 1:
+ raise ValueError([_("Option --package cannot be used without a unit file")])
+
if len(args.command) > 0:
container = GenericContainer(name = args.name, uri=args.uri, create = True)
container.set_command(args.command)
else:
- container = SystemdContainer(name = args.name, uri=args.uri, create = True)
+ container = SystemdContainer(name = args.name, uri=args.uri, create = True, rpm = args.rpm)
container.set_copy(args.copy)
container.set_unit_file_list(args.unitfiles)
for net in args.network:
@@ -972,6 +995,15 @@ class SetNet(argparse.Action):
nets = [values]
setattr(namespace, self.dest, nets)
+class CheckRpm(argparse.Action):
+ def __call__(self, parser, namespace, value, option_string=None):
+ nb_rpm = len(rpm.TransactionSet().dbMatch('name', value))
+ if nb_rpm == 0:
+ raise OSError(_("Cannot find %s rpm") % value)
+ elif nb_rpm > 1:
+ raise OSError(_("%s rpm is installed more than once") % value)
+ setattr(namespace, self.dest, value)
+
def requires_name(parser):
parser.add_argument("name",
help=_("name of the sandbox container"))
@@ -1015,6 +1047,10 @@ def gen_create_args(subparser):
action=CheckUnit,
dest="unitfiles", default=[],
help=_("Systemd Unit file to run within the systemd sandbox container. Commands cannot be specified with unit files."))
+ parser.add_argument("-P", "--package",
+ action=CheckRpm,
+ dest="package", default=None,
+ help=_("Package configuration to use in the container. Default: autodetected from unit files, unless if using a custom unit file."))
parser.add_argument("--username", dest="username",
help=_("Specify the username for the container. Default: UID username."))
parser.add_argument("-U", "--uid", dest="uid",
diff --git a/bin/virt-sandbox-service-create.pod b/bin/virt-sandbox-service-create.pod
index bea6504..ee8cffc 100644
--- a/bin/virt-sandbox-service-create.pod
+++ b/bin/virt-sandbox-service-create.pod
@@ -8,7 +8,7 @@ virt-sandbox-service create - Create a Security container
[--homedir HOMEDIR] [-G GID] [-i IMAGESIZE]
[-N NETWORK] [-p PATH] [-s SECURITY]
[-u UNITFILES] [--username USERNAME]
- [-U UID]
+ [-U UID] [-P package]
name [command [command ...]]
=head1 DESCRIPTION
@@ -146,6 +146,10 @@ Create file system image file of this size to store container content.
systemd Unit file to run within the container
+=item B<-P PACKAGE>, B<--package PACKAGE>
+
+Package used to populate the container if not autodetected based on unit file.
+
=item B<-U UID>, B<--uid UID>
Set uid to use within container.
--
1.8.2.1
11 years, 6 months