[libvirt] [PATCH] nwfilter: Add ARP src/dst IP mask for ebtables ARP
by Stefan Berger
From: Stefan Berger <stefanb(a)linux.vnet.ibm.com>
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=862887
Add a netmask for the source and destination IP address for the
ebtables --arp-ip-src and --arp-ip-dst options. Extend the XML
parser with support for XML attributes for these netmasks similar
to already supported netmasks. Extend the documentation.
Signed-off-by: Stefan Berger <stefanb(a)linux.vnet.ibm.com>
---
docs/formatnwfilter.html.in | 10 ++++++++++
src/conf/nwfilter_conf.c | 12 ++++++++++++
src/conf/nwfilter_conf.h | 2 ++
src/nwfilter/nwfilter_ebiptables_driver.c | 28 ++++++++++++++++++++++++----
4 files changed, 48 insertions(+), 4 deletions(-)
diff --git a/docs/formatnwfilter.html.in b/docs/formatnwfilter.html.in
index 5c06bf2..fb3a326 100644
--- a/docs/formatnwfilter.html.in
+++ b/docs/formatnwfilter.html.in
@@ -990,11 +990,21 @@
<td>Source IP address in ARP/RARP packet</td>
</tr>
<tr>
+ <td>arpsrcipmask <span class="since">(Since 1.2.3)</span></td>
+ <td>IP_MASK</td>
+ <td>Source IP mask</td>
+ </tr>
+ <tr>
<td>arpdstipaddr</td>
<td>IP_ADDR</td>
<td>Destination IP address in ARP/RARP packet</td>
</tr>
<tr>
+ <td>arpdstipmask <span class="since">(Since 1.2.3)</span></td>
+ <td>IP_MASK</td>
+ <td>Destination IP mask</td>
+ </tr>
+ <tr>
<td>comment <span class="since">(Since 0.8.5)</span></td>
<td>STRING</td>
<td>text with max. 256 characters</td>
diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c
index d25e0cc..73e668f 100644
--- a/src/conf/nwfilter_conf.c
+++ b/src/conf/nwfilter_conf.c
@@ -173,7 +173,9 @@ static const char dstmacmask_str[] = "dstmacmask";
static const char arpsrcmacaddr_str[] = "arpsrcmacaddr";
static const char arpdstmacaddr_str[] = "arpdstmacaddr";
static const char arpsrcipaddr_str[] = "arpsrcipaddr";
+static const char arpsrcipmask_str[] = "arpsrcipmask";
static const char arpdstipaddr_str[] = "arpdstipaddr";
+static const char arpdstipmask_str[] = "arpdstipmask";
static const char srcipaddr_str[] = "srcipaddr";
static const char srcipmask_str[] = "srcipmask";
static const char dstipaddr_str[] = "dstipaddr";
@@ -198,7 +200,9 @@ static const char ipsetflags_str[] = "ipsetflags";
#define ARPSRCMACADDR arpsrcmacaddr_str
#define ARPDSTMACADDR arpdstmacaddr_str
#define ARPSRCIPADDR arpsrcipaddr_str
+#define ARPSRCIPMASK arpsrcipmask_str
#define ARPDSTIPADDR arpdstipaddr_str
+#define ARPDSTIPMASK arpdstipmask_str
#define SRCIPADDR srcipaddr_str
#define SRCIPMASK srcipmask_str
#define DSTIPADDR dstipaddr_str
@@ -1302,10 +1306,18 @@ static const virXMLAttr2Struct arpAttributes[] = {
.datatype = DATATYPE_IPADDR,
.dataIdx = offsetof(virNWFilterRuleDef, p.arpHdrFilter.dataARPSrcIPAddr),
}, {
+ .name = ARPSRCIPMASK,
+ .datatype = DATATYPE_IPMASK,
+ .dataIdx = offsetof(virNWFilterRuleDef, p.arpHdrFilter.dataARPSrcIPMask),
+ }, {
.name = ARPDSTIPADDR,
.datatype = DATATYPE_IPADDR,
.dataIdx = offsetof(virNWFilterRuleDef, p.arpHdrFilter.dataARPDstIPAddr),
}, {
+ .name = ARPDSTIPMASK,
+ .datatype = DATATYPE_IPMASK,
+ .dataIdx = offsetof(virNWFilterRuleDef, p.arpHdrFilter.dataARPDstIPMask),
+ }, {
.name = "gratuitous",
.datatype = DATATYPE_BOOLEAN,
.dataIdx = offsetof(virNWFilterRuleDef, p.arpHdrFilter.dataGratuitousARP),
diff --git a/src/conf/nwfilter_conf.h b/src/conf/nwfilter_conf.h
index 8c59330..071343e 100644
--- a/src/conf/nwfilter_conf.h
+++ b/src/conf/nwfilter_conf.h
@@ -209,8 +209,10 @@ struct _arpHdrFilterDef {
nwItemDesc dataOpcode;
nwItemDesc dataARPSrcMACAddr;
nwItemDesc dataARPSrcIPAddr;
+ nwItemDesc dataARPSrcIPMask;
nwItemDesc dataARPDstMACAddr;
nwItemDesc dataARPDstIPAddr;
+ nwItemDesc dataARPDstIPMask;
nwItemDesc dataGratuitousARP;
nwItemDesc dataComment;
};
diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfilter_ebiptables_driver.c
index bea9535..a4b38e7 100644
--- a/src/nwfilter/nwfilter_ebiptables_driver.c
+++ b/src/nwfilter/nwfilter_ebiptables_driver.c
@@ -2059,6 +2059,7 @@ ebtablesCreateRuleInstance(char chainPrefix,
{
char macaddr[VIR_MAC_STRING_BUFLEN],
ipaddr[INET_ADDRSTRLEN],
+ ipmask[INET_ADDRSTRLEN],
ipv6addr[INET6_ADDRSTRLEN],
number[MAX(INT_BUFSIZE_BOUND(uint32_t),
INT_BUFSIZE_BOUND(int))],
@@ -2066,6 +2067,7 @@ ebtablesCreateRuleInstance(char chainPrefix,
char chain[MAX_CHAINNAME_LENGTH];
virBuffer buf = VIR_BUFFER_INITIALIZER;
const char *target;
+ bool hasMask;
if (!ebtables_cmd_path) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -2269,11 +2271,20 @@ ebtablesCreateRuleInstance(char chainPrefix,
&rule->p.arpHdrFilter.dataARPSrcIPAddr) < 0)
goto err_exit;
+ if (HAS_ENTRY_ITEM(&rule->p.arpHdrFilter.dataARPSrcIPMask)) {
+ if (printDataType(vars,
+ ipmask, sizeof(ipmask),
+ &rule->p.arpHdrFilter.dataARPSrcIPMask) < 0)
+ goto err_exit;
+ hasMask = true;
+ }
+
virBufferAsprintf(&buf,
- " %s %s %s",
+ " %s %s %s/%s",
reverse ? "--arp-ip-dst" : "--arp-ip-src",
ENTRY_GET_NEG_SIGN(&rule->p.arpHdrFilter.dataARPSrcIPAddr),
- ipaddr);
+ ipaddr,
+ hasMask ? ipmask : "32");
}
if (HAS_ENTRY_ITEM(&rule->p.arpHdrFilter.dataARPDstIPAddr)) {
@@ -2282,11 +2293,20 @@ ebtablesCreateRuleInstance(char chainPrefix,
&rule->p.arpHdrFilter.dataARPDstIPAddr) < 0)
goto err_exit;
+ if (HAS_ENTRY_ITEM(&rule->p.arpHdrFilter.dataARPDstIPMask)) {
+ if (printDataType(vars,
+ ipmask, sizeof(ipmask),
+ &rule->p.arpHdrFilter.dataARPDstIPMask) < 0)
+ goto err_exit;
+ hasMask = true;
+ }
+
virBufferAsprintf(&buf,
- " %s %s %s",
+ " %s %s %s/%s",
reverse ? "--arp-ip-src" : "--arp-ip-dst",
ENTRY_GET_NEG_SIGN(&rule->p.arpHdrFilter.dataARPDstIPAddr),
- ipaddr);
+ ipaddr,
+ hasMask ? ipmask : "32");
}
if (HAS_ENTRY_ITEM(&rule->p.arpHdrFilter.dataARPSrcMACAddr)) {
--
1.8.1.4
10 years, 9 months
[libvirt] [PATCH] nwfilter: Fix rule priority problem
by Stefan Berger
From: Stefan Berger <stefanb(a)linux.vnet.ibm.com>
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1072292
Fix a problem related to rule priorities that did not allow to
have rules applied that had a higher priority than the chain they
were in. In this case the chain did not exist yet when the rule
was instantiated. The solution is to adjust the priority of rules
if the priority of the chain is of higher value. That way the chain
will be created before the rule.
Signed-off-by: Stefan Berger <stefanb(a)linux.vnet.ibm.com>
---
src/nwfilter/nwfilter_ebiptables_driver.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfilter_ebiptables_driver.c
index 9d6cc90..59e07f6 100644
--- a/src/nwfilter/nwfilter_ebiptables_driver.c
+++ b/src/nwfilter/nwfilter_ebiptables_driver.c
@@ -3736,7 +3736,6 @@ ebiptablesApplyNewRules(const char *ifname,
}
}
-
/* cleanup whatever may exist */
if (ebtables_cmd_path) {
NWFILTER_SET_EBTABLES_SHELLVAR(&buf);
@@ -3770,6 +3769,23 @@ ebiptablesApplyNewRules(const char *ifname,
NWFILTER_SET_EBTABLES_SHELLVAR(&buf);
+ /* walk the list of rules and increase the priority
+ * of rules in case the chain priority is of higher value;
+ * this preserves the order of the rules and ensures that
+ * the chain will be created before the chain's rules
+ * are created; don't adjust rules in the root chain
+ * example: a rule of priority -510 will be adjusted to
+ * priority -500 and the chain with priority -500 will
+ * then be created before it.
+ */
+ for (i = 0; i < nruleInstances; i++) {
+ if (inst[i]->chainPriority > inst[i]->priority &&
+ !strstr("root", inst[i]->neededProtocolChain)) {
+
+ inst[i]->priority = inst[i]->chainPriority;
+ }
+ }
+
/* process ebtables commands; interleave commands from filters with
commands for creating and connecting ebtables chains */
j = 0;
--
1.8.1.4
10 years, 9 months
[libvirt] [PATCH] hostdev: add virObject field to virHostdevManager struct
by Jim Fehlig
Commit 6b306d66 converted virHostdevManager to a virObject, but
missed adding a virObject field to the virHostdevManager struct.
Result is memory corruption when taking a reference on an instance
of the object, where atomic inc is done on the stateDir field.
Later use of stateDir crashes libvirtd.
Signed-off-by: Jim Fehlig <jfehlig(a)suse.com>
---
src/util/virhostdev.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/util/virhostdev.h b/src/util/virhostdev.h
index ade7e2f..a56a2b5 100644
--- a/src/util/virhostdev.h
+++ b/src/util/virhostdev.h
@@ -45,6 +45,8 @@ typedef enum {
typedef struct _virHostdevManager virHostdevManager;
typedef virHostdevManager *virHostdevManagerPtr;
struct _virHostdevManager {
+ virObject parent;
+
char *stateDir;
virPCIDeviceListPtr activePCIHostdevs;
--
1.8.1.4
10 years, 9 months
[libvirt] How to build libvirt installation environment on ARM64?
by Chenqun (kuhn)
Hi all,
The libvirt can be used for ARM64? If it can be used for ARM64, what resources are needed for setup ?
How to build libvirt installation environment on ARM64?
I got some resource as follow:
1.ARM64 hardware is based Cortex-A57 fastmodel
2.Host and Guest kernel is linux 3.13.0
3.ARM64 filesystem from linaro releases (http://releases.linaro.org/latest/openembedded/aarch64/)
4.Qemu 1.6.50
5.Libvirt-1.2.0
My configure shell as follow:
export PKG_CONFIG=/usr/local/bin/pkg-config
export PKG_CONFIG_SYSROOT_DIR=/home/aarch64
export PKG_CONFIG_PATH=/home/aarch64/usr/lib/pkgconfig
./configure --target=aarch64 \
--prefix=/home/chenq/libvirt/install \
--host=aarch64-linux-gnu \
--libdir=/home/aarch64
CC=aarch64-linux-gnu-gcc \
LIBXML_CFLAGS="/home/aarch64/usr/lib"
CFLAGS="/home/aarch64/usr/include/libfdt"
LDFLAGS="/home/aarch64/lib"
Then configure error as follow:
…
checking for DEVMAPPER... no
checking for dm_task_run in -ldevmapper... no
checking libdevmapper.h usability... no
checking libdevmapper.h presence... no
checking for libdevmapper.h... no
configure: error: You must install device-mapper-devel/libdevmapper >= 1.0.0 to compile libvirt
I think this only one error is found. The libvirt depends on a lot of other libs,it will be find more similar errors.
So, how to create a friendly environment to compile and install libvirt on ARM64 ?
Thanks,
--Kuhn
10 years, 9 months
[libvirt] [PATCH 0/4] Fix capitalization of abbreviations
by Daniel P. Berrange
Complete the cleanup of bogus capitalization of Pci/Scsi/Usb
Daniel P. Berrange (4):
Replace Scsi with SCSI throughout
Replace Usb with USB throughout
Replace Pci with PCI throughout
Add syntax check to validate capitalization of abbreviations
cfg.mk | 8 +++++
src/conf/device_conf.c | 4 +--
src/conf/device_conf.h | 6 ++--
src/conf/domain_conf.c | 70 +++++++++++++++++++-------------------
src/conf/domain_conf.h | 30 ++++++++--------
src/conf/node_device_conf.c | 28 +++++++--------
src/conf/node_device_conf.h | 2 +-
src/libvirt_private.syms | 10 +++---
src/libxl/libxl_conf.c | 8 ++---
src/libxl/libxl_conf.h | 2 +-
src/libxl/libxl_driver.c | 4 +--
src/lxc/lxc_cgroup.c | 6 ++--
src/lxc/lxc_cgroup.h | 4 +--
src/lxc/lxc_driver.c | 6 ++--
src/lxc/lxc_hostdev.c | 6 ++--
src/lxc/lxc_hostdev.h | 2 +-
src/lxc/lxc_process.c | 2 +-
src/network/bridge_driver.c | 2 +-
src/node_device/node_device_udev.c | 4 +--
src/qemu/qemu_capabilities.c | 58 +++++++++++++++----------------
src/qemu/qemu_cgroup.c | 10 +++---
src/qemu/qemu_command.c | 30 ++++++++--------
src/qemu/qemu_command.h | 2 +-
src/qemu/qemu_hostdev.c | 2 +-
src/qemu/qemu_hotplug.c | 2 +-
src/qemu/qemu_monitor_text.c | 10 +++---
src/util/virhostdev.c | 2 +-
src/vmx/vmx.c | 2 +-
src/xen/xen_driver.c | 10 +++---
tests/virpcimock.c | 16 ++++-----
30 files changed, 178 insertions(+), 170 deletions(-)
--
1.8.5.3
10 years, 9 months
[libvirt] [PATCH v3] Add helper program to create custom leases
by Nehal J Wani
Introduce helper program to catch events from dnsmasq and maintain a custom
lease file per network. It supports dhcpv4 and dhcpv6. The file is saved as
"<interface-name>.status".
Each lease contains the following info:
<expiry-time (epoch time)> <mac> <iaid> <ip-address> <hostname> <clientid>
Example of custom leases file content:
[
{
"iaid": "1221229",
"ip-address": "2001:db8:ca2:2:1::95",
"mac-address": "52:54:00:12:a2:6d",
"hostname": "Fedora20",
"client-id": "00:04:1a:c1:d9:6b:5a:0a:e2:bc:f8:4b:1e:37:2e:38:22:55",
"expiry-time": 1393244216
},
{
"ip-address": "192.168.150.208",
"mac-address": "52:54:00:11:56:b3",
"hostname": "Wani-PC",
"client-id": "01:52:54:00:11:56:b3",
"expiry-time": 1393244248
}
]
src/Makefile.am:
* Add options to compile the helper program
src/network/bridge_driver.c:
* Introduce networkDnsmasqLeaseFileNameCustom()
* Invoke helper program along with dnsmasq
* Delete the .status file when corresponding n/w is destroyed.
src/util/leaseshelper.c
* Helper program to create the custom lease file
---
v3:
* Improved file handling, removed redundant copying, introduced --help and --version
v2:
* Changed format to JSON
* Refer: https://www.redhat.com/archives/libvir-list/2014-January/msg01234.html
v1:
* Refer: https://www.redhat.com/archives/libvir-list/2014-January/msg00626.html
src/Makefile.am | 16 +++
src/network/bridge_driver.c | 19 +++
src/util/leaseshelper.c | 303 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 338 insertions(+), 0 deletions(-)
create mode 100644 src/util/leaseshelper.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 6d21e5d..b8e1993 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -849,6 +849,9 @@ STORAGE_HELPER_DISK_SOURCES = \
UTIL_IO_HELPER_SOURCES = \
util/iohelper.c
+UTIL_LEASES_HELPER_SOURCES = \
+ util/leaseshelper.c
+
# Network filters
NWFILTER_DRIVER_SOURCES = \
nwfilter/nwfilter_driver.h nwfilter/nwfilter_driver.c \
@@ -2444,6 +2447,19 @@ libvirt_iohelper_CFLAGS = \
$(AM_CFLAGS) \
$(PIE_CFLAGS) \
$(NULL)
+
+libexec_PROGRAMS += libvirt_leaseshelper
+libvirt_leaseshelper_SOURCES = $(UTIL_LEASES_HELPER_SOURCES)
+libvirt_leaseshelper_LDADD = \
+ libvirt_util.la \
+ ../gnulib/lib/libgnu.la
+if WITH_DTRACE_PROBES
+libvirt_leaseshelper_LDADD += libvirt_probes.lo
+endif WITH_DTRACE_PROBES
+
+libvirt_leaseshelper_CFLAGS = \
+ $(PIE_CFLAGS) \
+ $(NULL)
endif WITH_LIBVIRTD
if WITH_STORAGE_DISK
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index a6c719d..9fb750f 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -205,6 +205,16 @@ networkDnsmasqLeaseFileNameFunc networkDnsmasqLeaseFileName =
networkDnsmasqLeaseFileNameDefault;
static char *
+networkDnsmasqLeaseFileNameCustom(const char *bridge)
+{
+ char *leasefile;
+
+ ignore_value(virAsprintf(&leasefile, "%s/%s.status",
+ driverState->dnsmasqStateDir, bridge));
+ return leasefile;
+}
+
+static char *
networkDnsmasqConfigFileName(const char *netname)
{
char *conffile;
@@ -240,6 +250,7 @@ networkRemoveInactive(virNetworkDriverStatePtr driver,
virNetworkObjPtr net)
{
char *leasefile = NULL;
+ char *customleasefile = NULL;
char *radvdconfigfile = NULL;
char *configfile = NULL;
char *radvdpidbase = NULL;
@@ -258,6 +269,9 @@ networkRemoveInactive(virNetworkDriverStatePtr driver,
if (!(leasefile = networkDnsmasqLeaseFileName(def->name)))
goto cleanup;
+ if (!(customleasefile = networkDnsmasqLeaseFileNameCustom(def->bridge)))
+ goto cleanup;
+
if (!(radvdconfigfile = networkRadvdConfigFileName(def->name)))
goto cleanup;
@@ -274,6 +288,7 @@ networkRemoveInactive(virNetworkDriverStatePtr driver,
/* dnsmasq */
dnsmasqDelete(dctx);
unlink(leasefile);
+ unlink(customleasefile);
unlink(configfile);
/* radvd */
@@ -1117,6 +1132,10 @@ networkBuildDhcpDaemonCommandLine(virNetworkObjPtr network,
cmd = virCommandNew(dnsmasqCapsGetBinaryPath(caps));
virCommandAddArgFormat(cmd, "--conf-file=%s", configfile);
+
+ /* This helper is used to create custom leases file for libvirt */
+ virCommandAddArgFormat(cmd, "--dhcp-script=%s", LIBEXECDIR "/libvirt_leaseshelper");
+
*cmdout = cmd;
ret = 0;
cleanup:
diff --git a/src/util/leaseshelper.c b/src/util/leaseshelper.c
new file mode 100644
index 0000000..bd8110f
--- /dev/null
+++ b/src/util/leaseshelper.c
@@ -0,0 +1,303 @@
+/*
+ * leasehelper.c: Helper program to create custom leases file
+ *
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * 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, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Author: Nehal J Wani <nehaljw.kkd1(a)gmail.com>
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+
+#include "virutil.h"
+#include "virthread.h"
+#include "virfile.h"
+#include "virbuffer.h"
+#include "virstring.h"
+#include "virerror.h"
+#include "viralloc.h"
+#include "virjson.h"
+#include "configmake.h"
+
+#define VIR_FROM_THIS VIR_FROM_NETWORK
+
+/**
+ * VIR_NETWORK_DHCP_LEASE_FILE_SIZE_MAX:
+ *
+ * Macro providing the upper limit on the size of leases file
+ */
+#define VIR_NETWORK_DHCP_LEASE_FILE_SIZE_MAX (2 * 1024 * 1024)
+
+static const char *program_name;
+
+/* Display version information. */
+static void
+helperVersion(const char *argv0)
+{
+ printf("%s (%s) %s\n", argv0, PACKAGE_NAME, PACKAGE_VERSION);
+}
+
+ATTRIBUTE_NORETURN static void
+usage(int status)
+{
+ if (status) {
+ fprintf(stderr, _("%s: try --help for more details\n"), program_name);
+ } else {
+ printf(_("Usage: %s ACTION MAC|CLIENTID IP HOSTNAME\n"
+ " or: %s ACTION MAC|CLIENTID IP\n"),
+ program_name, program_name);
+ }
+ exit(status);
+}
+
+static int
+customLeaseRewriteFile(int fd, void *opaque)
+{
+ char **data = opaque;
+
+ if (safewrite(fd, *data, strlen(*data)) < 0)
+ return -1;
+
+ return 0;
+}
+
+int
+main(int argc, char **argv)
+{
+ char *lease_entries = NULL;
+ char *custom_lease_file = NULL;
+ const char *ip = NULL;
+ const char *mac = NULL;
+ const char *action = NULL;
+ const char *iaid = virGetEnvAllowSUID("DNSMASQ_IAID");
+ const char *clientid = virGetEnvAllowSUID("DNSMASQ_CLIENT_ID");
+ const char *interface = virGetEnvAllowSUID("DNSMASQ_INTERFACE");
+ const char *exptime = virGetEnvAllowSUID("DNSMASQ_LEASE_EXPIRES");
+ const char *hostname = virGetEnvAllowSUID("DNSMASQ_SUPPLIED_HOSTNAME");
+ const char *leases_str = NULL;
+ long long expirytime = 0;
+ size_t i = 0;
+ int rv = EXIT_FAILURE;
+ int size = 0;
+ int custom_lease_file_len = 0;
+ bool add = false;
+ bool delete = false;
+ virJSONValuePtr lease_new = NULL;
+ virJSONValuePtr lease_tmp = NULL;
+ virJSONValuePtr leases_array = NULL;
+ virJSONValuePtr leases_array_new = NULL;
+
+ virSetErrorFunc(NULL, NULL);
+ virSetErrorLogPriorityFunc(NULL);
+
+ program_name = argv[0];
+
+ if (setlocale(LC_ALL, "") == NULL ||
+ bindtextdomain(PACKAGE, LOCALEDIR) == NULL ||
+ textdomain(PACKAGE) == NULL) {
+ fprintf(stderr, _("%s: initialization failed\n"), program_name);
+ exit(EXIT_FAILURE);
+ }
+
+ if (virThreadInitialize() < 0 ||
+ virErrorInitialize() < 0) {
+ fprintf(stderr, _("%s: initialization failed\n"), program_name);
+ exit(EXIT_FAILURE);
+ }
+
+ /* Doesn't hurt to check */
+ if (argc > 1) {
+ if(STREQ(argv[1], "--help"))
+ usage(EXIT_SUCCESS);
+
+ if (STREQ(argv[1], "--version")) {
+ helperVersion(argv[0]);
+ exit(EXIT_SUCCESS);
+ }
+ }
+
+ if (argc != 4 && argc != 5) {
+ /* Refer man page of dnsmasq --dhcp-script for more details */
+ usage(EXIT_FAILURE);
+ }
+
+ /* Make sure dnsmasq knows the interface. The interface name is not known
+ * when dnsmasq (re)starts and throws 'del' events for expired leases.
+ * So, if any old lease has expired, it will be automatically removed the
+ * next time this program is invoked */
+ if (!interface)
+ goto cleanup;
+
+ ip = argv[3];
+ mac = argv[2];
+ action = argv[1];
+
+ /* In case hostname is known, it is the 5th argument */
+ if (argc == 5)
+ hostname = argv[4];
+
+ if (virAsprintf(&custom_lease_file, "%s/%s.status", LOCALSTATEDIR
+ "/lib/libvirt/dnsmasq/", interface) < 0)
+ goto cleanup;
+
+ /* Check if it is an IPv6 lease */
+ if (virGetEnvAllowSUID("DNSMASQ_IAID")) {
+ mac = virGetEnvAllowSUID("DNSMASQ_MAC");
+ clientid=argv[2];
+ }
+
+ /* Since interfaces can be hot plugged, we need to make sure that the
+ * corresponding custom lease file exists. If not, 'touch' it */
+ if (virFileTouch(custom_lease_file, 0644) < 0)
+ goto cleanup;
+
+ /* Read entire contents */
+ if ((custom_lease_file_len = virFileReadAll(custom_lease_file,
+ VIR_NETWORK_DHCP_LEASE_FILE_SIZE_MAX,
+ &lease_entries)) < 0) {
+ goto cleanup;
+ }
+
+ if (STREQ(action, "add") || STREQ(action, "old") || STREQ(action, "del")) {
+ if (mac || STREQ(action, "del")) {
+ /* Delete the corresponding lease */
+ delete = true;
+ if (STREQ(action, "add") || STREQ(action, "old")) {
+ add = true;
+ /* Create new lease */
+ if (!(lease_new = virJSONValueNewObject())) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("failed to create json"));
+ goto cleanup;
+ }
+
+ if (virStrToLong_ll(exptime, NULL, 10, &expirytime) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unable to convert lease expiry time to long long: %s"),
+ exptime);
+ goto cleanup;
+ }
+
+ if ((iaid && virJSONValueObjectAppendString(lease_new, "iaid",
+ iaid) < 0) ||
+ (ip && virJSONValueObjectAppendString(lease_new, "ip-address",
+ ip) < 0) ||
+ (mac && virJSONValueObjectAppendString(lease_new, "mac-address",
+ mac) < 0) ||
+ (hostname && virJSONValueObjectAppendString(lease_new, "hostname",
+ hostname) < 0) ||
+ (clientid && virJSONValueObjectAppendString(lease_new, "client-id",
+ clientid) < 0) ||
+ (expirytime && virJSONValueObjectAppendNumberLong(lease_new, "expiry-time",
+ expirytime) < 0)) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("failed to create json"));
+ goto cleanup;
+ }
+ }
+ }
+ }
+ else {
+ fprintf(stderr, _("Unsupported action: %s\n"), action);
+ exit(EXIT_FAILURE);
+ }
+
+ /* Check for previous leases */
+ if (custom_lease_file_len) {
+ if (!(leases_array = virJSONValueFromString(lease_entries))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("invalid json in file: %s"), custom_lease_file);
+ goto cleanup;
+ }
+
+ if ((size = virJSONValueArraySize(leases_array)) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("couldn't fetch array of leases"));
+ goto cleanup;
+ }
+ }
+
+ if (!(leases_array_new = virJSONValueNewArray())) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("failed to create json"));
+ goto cleanup;
+ }
+
+ for (i = 0; i < size; i++) {
+ const char *ip_tmp = NULL;
+ long long exptime_tmp = -1;
+
+ if (!(lease_tmp = virJSONValueArrayGet(leases_array, i))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("failed to parse json"));
+ goto cleanup;
+ }
+
+ if (!(ip_tmp = virJSONValueObjectGetString(lease_tmp, "ip-address")) ||
+ (virJSONValueObjectGetNumberLong(lease_tmp, "expiry-time", &exptime_tmp) < 0)) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("failed to parse json"));
+ goto cleanup;
+ }
+
+ /* Check whether lease has expired or not */
+ if (exptime_tmp < (long long) time(NULL))
+ continue;
+
+ /* Check whether lease has to be included or not */
+ if (delete && STREQ(ip_tmp, ip))
+ continue;
+
+ /* Add old lease to new array */
+ if (virJSONValueArrayAppend(leases_array_new, lease_tmp) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("failed to create json"));
+ goto cleanup;
+ }
+ }
+
+ if (add) {
+ if (virJSONValueArrayAppend(leases_array_new, lease_new) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("failed to create json"));
+ goto cleanup;
+ }
+ }
+
+ if (!(leases_str = virJSONValueToString(leases_array_new, true))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("empty json array"));
+ goto cleanup;
+ }
+
+ /* Write to file */
+ if (virFileRewrite(custom_lease_file, 0644,
+ customLeaseRewriteFile, &leases_str) < 0)
+ goto cleanup;
+
+ rv = EXIT_SUCCESS;
+
+cleanup:
+ VIR_FREE(custom_lease_file);
+ virJSONValueFree(lease_new);
+ virJSONValueFree(leases_array);
+ virJSONValueFree(leases_array_new);
+ return rv;
+}
--
1.7.1
10 years, 9 months
[libvirt] [PATCH] hotplug:Fix log mistake in qemuMonitorAddNetdev
by Wangrui (K)
>From 81de0ce710bad91a2df18247e681b5a83872b8d5 Mon Sep 17 00:00:00 2001
From: Wang Rui <moon.wangrui(a)huawei.com>
Date: Thu, 13 Mar 2014 17:05:03 +0000
Subject: [PATCH] hotplug:Fix log mistake in qemuMonitorAddNetdev
VIR_DEBUG in qemuMonitorAddNetdev should print vhostfdSize
Signed-off-by: Wang Rui <moon.wangrui(a)huawei.com>
---
src/qemu/qemu_monitor.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index e4707b7..b2af0ae 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -2781,7 +2781,7 @@ int qemuMonitorAddNetdev(qemuMonitorPtr mon,
VIR_DEBUG("mon=%p netdevstr=%s tapfd=%p tapfdName=%p tapfdSize=%d"
"vhostfd=%p vhostfdName=%p vhostfdSize=%d",
mon, netdevstr, tapfd, tapfdName, tapfdSize,
- vhostfd, vhostfdName, tapfdSize);
+ vhostfd, vhostfdName, vhostfdSize);
if (!mon) {
virReportError(VIR_ERR_INVALID_ARG, "%s",
--
1.8.3.4
10 years, 9 months
[libvirt] [PATCH] Make ABI stability issue easier to debug
by Jiri Denemark
When ABI stability check fails, we only log the error message describing
the incompatibility. Let's log both XMLs in case of an error to make it
easier to analyze where and why the stability check failed.
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
src/conf/domain_conf.c | 125 ++++++++++++++++++++++++++++---------------------
1 file changed, 72 insertions(+), 53 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index e1b0115..a528257 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -13866,13 +13866,16 @@ virDomainDefCheckABIStability(virDomainDefPtr src,
virDomainDefPtr dst)
{
size_t i;
+ virErrorPtr err;
+ char *strSrc;
+ char *strDst;
if (src->virtType != dst->virtType) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Target domain virt type %s does not match source %s"),
virDomainVirtTypeToString(dst->virtType),
virDomainVirtTypeToString(src->virtType));
- return false;
+ goto error;
}
if (memcmp(src->uuid, dst->uuid, VIR_UUID_BUFLEN) != 0) {
@@ -13883,7 +13886,7 @@ virDomainDefCheckABIStability(virDomainDefPtr src,
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Target domain uuid %s does not match source %s"),
uuiddst, uuidsrc);
- return false;
+ goto error;
}
/* Not strictly ABI related, but we want to make sure domains
@@ -13894,60 +13897,60 @@ virDomainDefCheckABIStability(virDomainDefPtr src,
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Target domain name '%s' does not match source '%s'"),
dst->name, src->name);
- return false;
+ goto error;
}
if (src->mem.max_balloon != dst->mem.max_balloon) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Target domain max memory %lld does not match source %lld"),
dst->mem.max_balloon, src->mem.max_balloon);
- return false;
+ goto error;
}
if (src->mem.cur_balloon != dst->mem.cur_balloon) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Target domain current memory %lld does not match source %lld"),
dst->mem.cur_balloon, src->mem.cur_balloon);
- return false;
+ goto error;
}
if (src->mem.hugepage_backed != dst->mem.hugepage_backed) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Target domain huge page backing %d does not match source %d"),
dst->mem.hugepage_backed,
src->mem.hugepage_backed);
- return false;
+ goto error;
}
if (src->vcpus != dst->vcpus) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Target domain vCPU count %d does not match source %d"),
dst->vcpus, src->vcpus);
- return false;
+ goto error;
}
if (src->maxvcpus != dst->maxvcpus) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Target domain vCPU max %d does not match source %d"),
dst->maxvcpus, src->maxvcpus);
- return false;
+ goto error;
}
if (STRNEQ(src->os.type, dst->os.type)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Target domain OS type %s does not match source %s"),
dst->os.type, src->os.type);
- return false;
+ goto error;
}
if (src->os.arch != dst->os.arch){
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Target domain architecture %s does not match source %s"),
virArchToString(dst->os.arch),
virArchToString(src->os.arch));
- return false;
+ goto error;
}
if (STRNEQ_NULLABLE(src->os.machine, dst->os.machine)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Target domain OS type %s does not match source %s"),
dst->os.machine, src->os.machine);
- return false;
+ goto error;
}
if (src->os.smbios_mode != dst->os.smbios_mode) {
@@ -13955,203 +13958,203 @@ virDomainDefCheckABIStability(virDomainDefPtr src,
_("Target domain SMBIOS mode %s does not match source %s"),
virDomainSmbiosModeTypeToString(dst->os.smbios_mode),
virDomainSmbiosModeTypeToString(src->os.smbios_mode));
- return false;
+ goto error;
}
if (!virDomainDefFeaturesCheckABIStability(src, dst))
- return false;
+ goto error;
if (src->clock.ntimers != dst->clock.ntimers) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Target domain timers do not match source"));
- return false;
+ goto error;
}
for (i = 0; i < src->clock.ntimers; i++) {
if (!virDomainTimerDefCheckABIStability(src->clock.timers[i],
dst->clock.timers[i]))
- return false;
+ goto error;
}
if (!virCPUDefIsEqual(src->cpu, dst->cpu))
- return false;
+ goto error;
if (!virSysinfoIsEqual(src->sysinfo, dst->sysinfo))
- return false;
+ goto error;
if (src->ndisks != dst->ndisks) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Target domain disk count %zu does not match source %zu"),
dst->ndisks, src->ndisks);
- return false;
+ goto error;
}
for (i = 0; i < src->ndisks; i++)
if (!virDomainDiskDefCheckABIStability(src->disks[i], dst->disks[i]))
- return false;
+ goto error;
if (src->ncontrollers != dst->ncontrollers) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Target domain controller count %zu "
"does not match source %zu"),
dst->ncontrollers, src->ncontrollers);
- return false;
+ goto error;
}
for (i = 0; i < src->ncontrollers; i++)
if (!virDomainControllerDefCheckABIStability(src->controllers[i],
dst->controllers[i]))
- return false;
+ goto error;
if (src->nfss != dst->nfss) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Target domain filesystem count %zu "
"does not match source %zu"),
dst->nfss, src->nfss);
- return false;
+ goto error;
}
for (i = 0; i < src->nfss; i++)
if (!virDomainFsDefCheckABIStability(src->fss[i], dst->fss[i]))
- return false;
+ goto error;
if (src->nnets != dst->nnets) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Target domain net card count %zu "
"does not match source %zu"),
dst->nnets, src->nnets);
- return false;
+ goto error;
}
for (i = 0; i < src->nnets; i++)
if (!virDomainNetDefCheckABIStability(src->nets[i], dst->nets[i]))
- return false;
+ goto error;
if (src->ninputs != dst->ninputs) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Target domain input device count %zu "
"does not match source %zu"),
dst->ninputs, src->ninputs);
- return false;
+ goto error;
}
for (i = 0; i < src->ninputs; i++)
if (!virDomainInputDefCheckABIStability(src->inputs[i], dst->inputs[i]))
- return false;
+ goto error;
if (src->nsounds != dst->nsounds) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Target domain sound card count %zu "
"does not match source %zu"),
dst->nsounds, src->nsounds);
- return false;
+ goto error;
}
for (i = 0; i < src->nsounds; i++)
if (!virDomainSoundDefCheckABIStability(src->sounds[i], dst->sounds[i]))
- return false;
+ goto error;
if (src->nvideos != dst->nvideos) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Target domain video card count %zu "
"does not match source %zu"),
dst->nvideos, src->nvideos);
- return false;
+ goto error;
}
for (i = 0; i < src->nvideos; i++)
if (!virDomainVideoDefCheckABIStability(src->videos[i], dst->videos[i]))
- return false;
+ goto error;
if (src->nhostdevs != dst->nhostdevs) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Target domain host device count %zu "
"does not match source %zu"),
dst->nhostdevs, src->nhostdevs);
- return false;
+ goto error;
}
for (i = 0; i < src->nhostdevs; i++)
if (!virDomainHostdevDefCheckABIStability(src->hostdevs[i],
dst->hostdevs[i]))
- return false;
+ goto error;
if (src->nsmartcards != dst->nsmartcards) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Target domain smartcard count %zu "
"does not match source %zu"),
dst->nsmartcards, src->nsmartcards);
- return false;
+ goto error;
}
for (i = 0; i < src->nsmartcards; i++)
if (!virDomainSmartcardDefCheckABIStability(src->smartcards[i],
dst->smartcards[i]))
- return false;
+ goto error;
if (src->nserials != dst->nserials) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Target domain serial port count %zu "
"does not match source %zu"),
dst->nserials, src->nserials);
- return false;
+ goto error;
}
for (i = 0; i < src->nserials; i++)
if (!virDomainSerialDefCheckABIStability(src->serials[i],
dst->serials[i]))
- return false;
+ goto error;
if (src->nparallels != dst->nparallels) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Target domain parallel port count %zu "
"does not match source %zu"),
dst->nparallels, src->nparallels);
- return false;
+ goto error;
}
for (i = 0; i < src->nparallels; i++)
if (!virDomainParallelDefCheckABIStability(src->parallels[i],
dst->parallels[i]))
- return false;
+ goto error;
if (src->nchannels != dst->nchannels) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Target domain channel count %zu "
"does not match source %zu"),
dst->nchannels, src->nchannels);
- return false;
+ goto error;
}
for (i = 0; i < src->nchannels; i++)
if (!virDomainChannelDefCheckABIStability(src->channels[i],
dst->channels[i]))
- return false;
+ goto error;
if (src->nconsoles != dst->nconsoles) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Target domain console count %zu "
"does not match source %zu"),
dst->nconsoles, src->nconsoles);
- return false;
+ goto error;
}
for (i = 0; i < src->nconsoles; i++)
if (!virDomainConsoleDefCheckABIStability(src->consoles[i],
dst->consoles[i]))
- return false;
+ goto error;
if (src->nhubs != dst->nhubs) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Target domain hub device count %zu "
"does not match source %zu"),
dst->nhubs, src->nhubs);
- return false;
+ goto error;
}
for (i = 0; i < src->nhubs; i++)
if (!virDomainHubDefCheckABIStability(src->hubs[i], dst->hubs[i]))
- return false;
+ goto error;
if ((!src->redirfilter && dst->redirfilter) ||
(src->redirfilter && !dst->redirfilter)) {
@@ -14159,13 +14162,13 @@ virDomainDefCheckABIStability(virDomainDefPtr src,
_("Target domain USB redirection filter count %d "
"does not match source %d"),
dst->redirfilter ? 1 : 0, src->redirfilter ? 1 : 0);
- return false;
+ goto error;
}
if (src->redirfilter &&
!virDomainRedirFilterDefCheckABIStability(src->redirfilter,
dst->redirfilter))
- return false;
+ goto error;
if ((!src->watchdog && dst->watchdog) ||
(src->watchdog && !dst->watchdog)) {
@@ -14173,12 +14176,12 @@ virDomainDefCheckABIStability(virDomainDefPtr src,
_("Target domain watchdog count %d "
"does not match source %d"),
dst->watchdog ? 1 : 0, src->watchdog ? 1 : 0);
- return false;
+ goto error;
}
if (src->watchdog &&
!virDomainWatchdogDefCheckABIStability(src->watchdog, dst->watchdog))
- return false;
+ goto error;
if ((!src->memballoon && dst->memballoon) ||
(src->memballoon && !dst->memballoon)) {
@@ -14186,21 +14189,37 @@ virDomainDefCheckABIStability(virDomainDefPtr src,
_("Target domain memory balloon count %d "
"does not match source %d"),
dst->memballoon ? 1 : 0, src->memballoon ? 1 : 0);
- return false;
+ goto error;
}
if (src->memballoon &&
!virDomainMemballoonDefCheckABIStability(src->memballoon,
dst->memballoon))
- return false;
+ goto error;
if (!virDomainRNGDefCheckABIStability(src->rng, dst->rng))
- return false;
+ goto error;
if (!virDomainPanicCheckABIStability(src->panic, dst->panic))
- return false;
+ goto error;
return true;
+
+error:
+ err = virSaveLastError();
+
+ strSrc = virDomainDefFormat(src, 0);
+ strDst = virDomainDefFormat(dst, 0);
+ VIR_DEBUG("XMLs that failed stability check were: src=\"%s\", dst=\"%s\"",
+ NULLSTR(strSrc), NULLSTR(strDst));
+ VIR_FREE(strSrc);
+ VIR_FREE(strDst);
+
+ if (err) {
+ virSetError(err);
+ virFreeError(err);
+ }
+ return false;
}
--
1.9.0
10 years, 9 months
[libvirt] [PATCH 0/7] Test parsing of iscsiadm output
by Ján Tomko
Introduce virCommandSetMockOutputFile for faking output of
asynchronous commands and use it to test parsing of iscsiadm
output in virStorageBackendISCSISession and
virStorageBackendISCSIScanTargets
Ján Tomko (7):
Change virStorageBackendISCSISession 'probe' arg to bool
Introduce virStoragePoolSourceDeviceClear
Use size_t for ndevice in pool source definition
Introduce vircommandpriv.h for functions used by tests
Add virCommandSetMockOutputFile
Add test for virStorageBackendISCSISession
Add a test for virStorageBackendISCSIScanTargets
src/Makefile.am | 5 +-
src/conf/storage_conf.c | 36 ++---
src/conf/storage_conf.h | 3 +-
src/libvirt_private.syms | 2 +
src/storage/storage_backend_iscsi.c | 14 +-
src/storage/storage_backend_iscsipriv.h | 36 +++++
src/util/vircommand.c | 35 ++++-
src/util/vircommand.h | 2 -
src/util/vircommandpriv.h | 29 ++++
tests/Makefile.am | 14 +-
tests/storageiscsidata/iscsiadm_sendtargets | 6 +
tests/storageiscsidata/iscsiadm_session | 6 +
tests/storageiscsidata/iscsiadm_session_nonflash | 6 +
tests/storageiscsitest.c | 186 +++++++++++++++++++++++
tests/virkmodtest.c | 2 +-
tests/virnetdevbandwidthtest.c | 2 +-
16 files changed, 350 insertions(+), 34 deletions(-)
create mode 100644 src/storage/storage_backend_iscsipriv.h
create mode 100644 src/util/vircommandpriv.h
create mode 100644 tests/storageiscsidata/iscsiadm_sendtargets
create mode 100644 tests/storageiscsidata/iscsiadm_session
create mode 100644 tests/storageiscsidata/iscsiadm_session_nonflash
create mode 100644 tests/storageiscsitest.c
--
1.8.3.2
10 years, 9 months
[libvirt] [PATCH] qemu: Forbid "sgio" support for SCSI generic host device
by Osier Yang
The kernel didn't support the unprivileged SGIO for SCSI generic
device finally, and since it's unknow whether the way to support
unprivileged SGIO for SCSI generic device will be similar as for
SCSI block device or not, even it's simliar (I.e. via sysfs, for
SCSI block device, it's /sys/dev/block/8\:0/queue/unpriv_sgio,
for example), the file name might be different, So it's better not
guess what it should be like currently.
This patch removes the related code (mainly about the "shareable"
checking on the "sgio" setting, it's not supported at all, why
we leave checking code there? :-), and error out if "sgio" is
specified in the domain config.
---
src/qemu/qemu_conf.c | 87 ++++++++++++----------------------------------------
1 file changed, 20 insertions(+), 67 deletions(-)
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 2c397b0..ad6348d 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -739,12 +739,8 @@ qemuCheckSharedDevice(virHashTablePtr sharedDevices,
virDomainDeviceDefPtr dev)
{
virDomainDiskDefPtr disk = NULL;
- virDomainHostdevDefPtr hostdev = NULL;
char *sysfs_path = NULL;
char *key = NULL;
- char *hostdev_name = NULL;
- char *hostdev_path = NULL;
- char *device_path = NULL;
int val;
int ret = 0;
@@ -756,27 +752,11 @@ qemuCheckSharedDevice(virHashTablePtr sharedDevices,
*/
if (disk->device != VIR_DOMAIN_DISK_DEVICE_LUN)
return 0;
-
- device_path = disk->src;
- } else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) {
- hostdev = dev->data.hostdev;
-
- if (!(hostdev_name = virSCSIDeviceGetDevName(NULL,
- hostdev->source.subsys.u.scsi.adapter,
- hostdev->source.subsys.u.scsi.bus,
- hostdev->source.subsys.u.scsi.target,
- hostdev->source.subsys.u.scsi.unit)))
- goto cleanup;
-
- if (virAsprintf(&hostdev_path, "/dev/%s", hostdev_name) < 0)
- goto cleanup;
-
- device_path = hostdev_path;
} else {
return 0;
}
- if (!(sysfs_path = virGetUnprivSGIOSysfsPath(device_path, NULL))) {
+ if (!(sysfs_path = virGetUnprivSGIOSysfsPath(disk->src, NULL))) {
ret = -1;
goto cleanup;
}
@@ -787,7 +767,7 @@ qemuCheckSharedDevice(virHashTablePtr sharedDevices,
if (!virFileExists(sysfs_path))
goto cleanup;
- if (!(key = qemuGetSharedDeviceKey(device_path))) {
+ if (!(key = qemuGetSharedDeviceKey(disk->src))) {
ret = -1;
goto cleanup;
}
@@ -798,7 +778,7 @@ qemuCheckSharedDevice(virHashTablePtr sharedDevices,
if (!(virHashLookup(sharedDevices, key)))
goto cleanup;
- if (virGetDeviceUnprivSGIO(device_path, NULL, &val) < 0) {
+ if (virGetDeviceUnprivSGIO(disk->src, NULL, &val) < 0) {
ret = -1;
goto cleanup;
}
@@ -810,36 +790,25 @@ qemuCheckSharedDevice(virHashTablePtr sharedDevices,
disk->sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED))
goto cleanup;
- if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
- if (disk->type == VIR_DOMAIN_DISK_TYPE_VOLUME) {
- virReportError(VIR_ERR_OPERATION_INVALID,
- _("sgio of shared disk 'pool=%s' 'volume=%s' conflicts "
- "with other active domains"),
- disk->srcpool->pool,
- disk->srcpool->volume);
- } else {
- virReportError(VIR_ERR_OPERATION_INVALID,
- _("sgio of shared disk '%s' conflicts with other "
- "active domains"), disk->src);
- }
+ if (disk->type == VIR_DOMAIN_DISK_TYPE_VOLUME) {
+ virReportError(VIR_ERR_OPERATION_INVALID,
+ _("sgio of shared disk 'pool=%s' 'volume=%s' conflicts "
+ "with other active domains"),
+ disk->srcpool->pool,
+ disk->srcpool->volume);
} else {
virReportError(VIR_ERR_OPERATION_INVALID,
- _("sgio of shared scsi host device '%s-%d-%d-%d' conflicts "
- "with other active domains"),
- hostdev->source.subsys.u.scsi.adapter,
- hostdev->source.subsys.u.scsi.bus,
- hostdev->source.subsys.u.scsi.target,
- hostdev->source.subsys.u.scsi.unit);
+ _("sgio of shared disk '%s' conflicts with other "
+ "active domains"), disk->src);
}
ret = -1;
cleanup:
- VIR_FREE(hostdev_name);
- VIR_FREE(hostdev_path);
VIR_FREE(sysfs_path);
VIR_FREE(key);
return ret;
}
+
bool
qemuSharedDeviceEntryDomainExists(qemuSharedDeviceEntryPtr entry,
const char *name,
@@ -1116,8 +1085,6 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
virDomainHostdevDefPtr hostdev = NULL;
char *sysfs_path = NULL;
char *path = NULL;
- char *hostdev_name = NULL;
- char *hostdev_path = NULL;
int val = -1;
int ret = 0;
@@ -1135,22 +1102,15 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
} else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) {
hostdev = dev->data.hostdev;
- if (!hostdev->shareable ||
- !(hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
- hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI))
- return 0;
-
- if (!(hostdev_name = virSCSIDeviceGetDevName(NULL,
- hostdev->source.subsys.u.scsi.adapter,
- hostdev->source.subsys.u.scsi.bus,
- hostdev->source.subsys.u.scsi.target,
- hostdev->source.subsys.u.scsi.unit)))
- goto cleanup;
-
- if (virAsprintf(&hostdev_path, "/dev/%s", hostdev_name) < 0)
+ if (hostdev->source.subsys.u.scsi.sgio) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("'sgio' is not supported for SCSI "
+ "generic device yet "));
+ ret = -1;
goto cleanup;
+ }
- path = hostdev_path;
+ return 0;
} else {
return 0;
}
@@ -1162,12 +1122,7 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
}
/* By default, filter the SG_IO commands, i.e. set unpriv_sgio to 0. */
-
- if (dev->type == VIR_DOMAIN_DEVICE_DISK)
- val = (disk->sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED);
- else
- val = (hostdev->source.subsys.u.scsi.sgio ==
- VIR_DOMAIN_DEVICE_SGIO_UNFILTERED);
+ val = (disk->sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED);
/* Do not do anything if unpriv_sgio is not supported by the kernel and the
* whitelist is enabled. But if requesting unfiltered access, always call
@@ -1179,8 +1134,6 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
cleanup:
VIR_FREE(sysfs_path);
- VIR_FREE(hostdev_name);
- VIR_FREE(hostdev_path);
return ret;
}
--
1.8.1.4
10 years, 9 months