[libvirt] [PATCH v5] 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/network/leaseshelper.c
* Helper program to create the custom lease file
---
v5:
* More comments added, for better explanation
* Use of virFileFindResource() to identify proper path to helper binary
* Use of VIR_ENUM_IMPL for handling action events added
v4:
* Addition of pidfile and a corresponding lock for it
* Make correction for dnsmasq < 2.52 (Only IPv4)
* Move helper file from src/util to src/network
* Increase limit on max size of leases file
* Refer: https://www.redhat.com/archives/libvir-list/2014-March/msg01038.html
v3:
* Improved file handling, removed redundant copying, introduced --help and --version
* Refer: https://www.redhat.com/archives/libvir-list/2014-February/msg01431.html
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 | 22 +++
src/network/bridge_driver.c | 27 ++++
src/network/leaseshelper.c | 360 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 409 insertions(+), 0 deletions(-)
create mode 100644 src/network/leaseshelper.c
diff --git a/src/Makefile.am b/src/Makefile.am
index dd0abe7..fbe72c4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -859,6 +859,9 @@ STORAGE_HELPER_DISK_SOURCES = \
UTIL_IO_HELPER_SOURCES = \
util/iohelper.c
+NETWORK_LEASES_HELPER_SOURCES = \
+ network/leaseshelper.c
+
# Network filters
NWFILTER_DRIVER_SOURCES = \
nwfilter/nwfilter_driver.h nwfilter/nwfilter_driver.c \
@@ -2466,6 +2469,25 @@ libvirt_iohelper_CFLAGS = \
$(AM_CFLAGS) \
$(PIE_CFLAGS) \
$(NULL)
+
+if WITH_NETWORK
+libexec_PROGRAMS += libvirt_leaseshelper
+libvirt_leaseshelper_SOURCES = $(NETWORK_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 = \
+ $(AM_CFLAGS) \
+ $(PIE_CFLAGS) \
+ $(NULL)
+else ! WITH_NETWORK
+EXTRA_DIST += $(NETWORK_LEASES_HELPER_SOURCES)
+endif ! WITH_NETWORK
+
endif WITH_LIBVIRTD
if WITH_STORAGE_DISK
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 201b22f..ade664d 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -210,6 +210,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;
@@ -245,6 +255,7 @@ networkRemoveInactive(virNetworkDriverStatePtr driver,
virNetworkObjPtr net)
{
char *leasefile = NULL;
+ char *customleasefile = NULL;
char *radvdconfigfile = NULL;
char *configfile = NULL;
char *radvdpidbase = NULL;
@@ -263,6 +274,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;
@@ -279,6 +293,7 @@ networkRemoveInactive(virNetworkDriverStatePtr driver,
/* dnsmasq */
dnsmasqDelete(dctx);
unlink(leasefile);
+ unlink(customleasefile);
unlink(configfile);
/* radvd */
@@ -296,6 +311,7 @@ networkRemoveInactive(virNetworkDriverStatePtr driver,
cleanup:
VIR_FREE(leasefile);
VIR_FREE(configfile);
+ VIR_FREE(customleasefile);
VIR_FREE(radvdconfigfile);
VIR_FREE(radvdpidbase);
VIR_FREE(statusfile);
@@ -1120,6 +1136,7 @@ networkBuildDhcpDaemonCommandLine(virNetworkObjPtr network,
int ret = -1;
char *configfile = NULL;
char *configstr = NULL;
+ char *leaseshelper_path;
network->dnsmasqPid = -1;
@@ -1142,11 +1159,21 @@ networkBuildDhcpDaemonCommandLine(virNetworkObjPtr network,
cmd = virCommandNew(dnsmasqCapsGetBinaryPath(caps));
virCommandAddArgFormat(cmd, "--conf-file=%s", configfile);
+
+ /* This helper is used to create custom leases file for libvirt */
+ if (!(leaseshelper_path = virFileFindResource("libvirt_leaseshelper",
+ "src",
+ LIBEXECDIR)))
+ goto cleanup;
+
+ virCommandAddArgFormat(cmd, "--dhcp-script=%s", leaseshelper_path);
+
*cmdout = cmd;
ret = 0;
cleanup:
VIR_FREE(configfile);
VIR_FREE(configstr);
+ VIR_FREE(leaseshelper_path);
return ret;
}
diff --git a/src/network/leaseshelper.c b/src/network/leaseshelper.c
new file mode 100644
index 0000000..d580369
--- /dev/null
+++ b/src/network/leaseshelper.c
@@ -0,0 +1,360 @@
+/*
+ * leasehelper.c: Helper program to create custom leases file
+ *
+ * Copyright (C) 2014 Red Hat, Inc.
+ * Copyright (C) 2014 Nehal J Wani
+ *
+ * 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>
+ *
+ * For IPv6 support, use dnsmasq >= 2.67
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+
+#include "virutil.h"
+#include "virthread.h"
+#include "virfile.h"
+#include "virpidfile.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 (32 * 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 add|old|del mac|clientid ip [hostname]\n"
+ "Designed for use with 'dnsmasq --dhcp-script'\n"
+ "Refer to man page of dnsmasq for more details'\n"),
+ 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;
+}
+
+/* Flags denoting actions for a lease */
+enum virLeaseActionFlags {
+ VIR_LEASE_ACTION_ADD, /* Create new lease */
+ VIR_LEASE_ACTION_OLD, /* Lease already exists, renew it */
+ VIR_LEASE_ACTION_DEL, /* Delete the lease */
+
+ VIR_LEASE_ACTION_LAST
+};
+
+VIR_ENUM_DECL(virLeaseAction);
+
+VIR_ENUM_IMPL(virLeaseAction, VIR_LEASE_ACTION_LAST,
+ "add", "old", "del");
+
+int
+main(int argc, char **argv)
+{
+ char *exptime = NULL;
+ char *pid_file = NULL;
+ char *lease_entries = NULL;
+ char *custom_lease_file = NULL;
+ const char *ip = NULL;
+ const char *mac = NULL;
+ const char *iaid = virGetEnvAllowSUID("DNSMASQ_IAID");
+ const char *clientid = virGetEnvAllowSUID("DNSMASQ_CLIENT_ID");
+ const char *interface = virGetEnvAllowSUID("DNSMASQ_INTERFACE");
+ const char *exptime_tmp = virGetEnvAllowSUID("DNSMASQ_LEASE_EXPIRES");
+ const char *hostname = virGetEnvAllowSUID("DNSMASQ_SUPPLIED_HOSTNAME");
+ const char *leases_str = NULL;
+ long long currtime = 0;
+ long long expirytime = 0;
+ size_t i = 0;
+ int size = 0;
+ int action = -1;
+ int pid_file_fd = -1;
+ int rv = EXIT_FAILURE;
+ 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 = virLeaseActionTypeFromString(argv[1]);
+
+ /* In case hostname is known, it is the 5th argument */
+ if (argc == 5)
+ hostname = argv[4];
+
+ if (VIR_STRDUP(exptime, exptime_tmp) < 0)
+ goto cleanup;
+
+ /* Removed extraneous trailing space in DNSMASQ_LEASE_EXPIRES (dnsmasq < 2.52) */
+ if (exptime[strlen(exptime) - 1] == ' ')
+ exptime[strlen(exptime) - 1] = '\0';
+
+ /* Check if it is an IPv6 lease */
+ if (virGetEnvAllowSUID("DNSMASQ_IAID")) {
+ mac = virGetEnvAllowSUID("DNSMASQ_MAC");
+ clientid = argv[2];
+ }
+
+ if (virAsprintf(&custom_lease_file,
+ LOCALSTATEDIR "/lib/libvirt/dnsmasq/%s.status",
+ interface) < 0)
+ goto cleanup;
+
+ if (VIR_STRDUP(pid_file, LOCALSTATEDIR "/run/leaseshelper.pid") < 0)
+ goto cleanup;
+
+ /* Try to claim the pidfile, exiting if we can't */
+ if ((pid_file_fd = virPidFileAcquirePath(pid_file, true, getpid())) < 0)
+ goto cleanup;
+
+ /* 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 (action == VIR_LEASE_ACTION_ADD ||
+ action == VIR_LEASE_ACTION_OLD ||
+ action == VIR_LEASE_ACTION_DEL) {
+ /* Custom ipv6 leases *will not* be created if the env-var DNSMASQ_MAC
+ * is not set. In the special case, when the $(interface).status file
+ * is not already present and dnsmasq is (re)started, the corresponding
+ * ipv6 custom lease will be created only when the guest sends the
+ * 'old' action for its existing ipv6 interfaces.
+ *
+ * According to rfc3315, the combination of DUID and IAID can be used
+ * to uniquely identify each ipv6 guest interface. So, in future, if
+ * we introduce virNetworkGetDHCPLeaseBy(IAID|DUID|IAID+DUID) for ipv6
+ * interfaces, then, the following if condition won't be required, as
+ * the new lease will be created irrespective of whether the MACID is
+ * known or not.
+ */
+ if (mac || action == VIR_LEASE_ACTION_DEL) {
+ /* Delete the corresponding lease, if it already exists */
+ delete = true;
+ if (action == VIR_LEASE_ACTION_ADD ||
+ action == VIR_LEASE_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)
+ goto cleanup;
+ if (ip && virJSONValueObjectAppendString(lease_new, "ip-address", ip) < 0)
+ goto cleanup;
+ if (mac && virJSONValueObjectAppendString(lease_new, "mac-address", mac) < 0)
+ goto cleanup;
+ if (hostname && virJSONValueObjectAppendString(lease_new, "hostname", hostname) < 0)
+ goto cleanup;
+ if (clientid && virJSONValueObjectAppendString(lease_new, "client-id", clientid) < 0)
+ goto cleanup;
+ if (expirytime && virJSONValueObjectAppendNumberLong(lease_new, "expiry-time", expirytime) < 0)
+ goto cleanup;
+ }
+ }
+ } else {
+ fprintf(stderr, _("Unsupported action: %s\n"),
+ virLeaseActionTypeToString(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;
+ }
+
+ currtime = (long long) time(NULL);
+
+ for (i = 0; i < size; i++) {
+ const char *ip_tmp = NULL;
+ long long expirytime_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", &expirytime_tmp) < 0)) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("failed to parse json"));
+ goto cleanup;
+ }
+
+ /* Check whether lease has expired or not */
+ if (expirytime_tmp < currtime)
+ 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:
+ if (pid_file_fd != -1)
+ virPidFileReleasePath(pid_file, pid_file_fd);
+
+ VIR_FREE(pid_file);
+ VIR_FREE(exptime_tmp);
+ VIR_FREE(custom_lease_file);
+ virJSONValueFree(lease_new);
+ virJSONValueFree(leases_array);
+ virJSONValueFree(leases_array_new);
+
+ return rv;
+}
--
1.7.1
10 years, 5 months
[libvirt] [PATCH] bhyve: domain events support
by Roman Bogorodskiy
Tested with a sequance of virsh commands like that:
- Redefine already defined domain (bhyve) using 'define' command
- 'undefine bhyve'
- 'define /path/to/bhyve.xml'
- 'start bhyve'
- 'destroy bhyve'
- 'start --file /path/to/bhyve.xml'
- 'destroy bhyve'
This procudes list of events from 'event --all --loop':
event 'lifecycle' for domain bhyve: Defined Updated
event 'lifecycle' for domain bhyve: Undefined Removed
event 'lifecycle' for domain bhyve: Defined Added
event 'lifecycle' for domain bhyve: Started Booted
event 'lifecycle' for domain bhyve: Stopped Destroyed
event 'lifecycle' for domain bhyve: Started Booted
event 'lifecycle' for domain bhyve: Stopped Destroyed
Roman Bogorodskiy (1):
bhyve: domain events support
src/bhyve/bhyve_driver.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++-
src/bhyve/bhyve_utils.h | 3 ++
2 files changed, 90 insertions(+), 1 deletion(-)
--
1.9.0
10 years, 6 months
[libvirt] [RFC 0/5] Allow object-add on X86CPU subclasses, for CPU model probing
by Eduardo Habkost
This series allows management code to use object-add on X86CPU subclasses, so it
can use it to probe for CPU model information without re-running QEMU. The main
use case for this is to allow management code to create CPU objects and query
the "feature-words" and "filtered-features" properties on the new objects, to
find out which features each CPU model needs, and to do the same using the
"host" CPU model to check which features can be enabled in a given host.
There's experimental libvirt code to use the new command at:
https://github.com/ehabkost/libvirt/tree/work/cpu-feature-word-query
The experimental code just create the CPU objects to query for feature
information, but doesn't do anything with that data.
Eduardo Habkost (5):
cpu: Initialize cpu->stopped=true earlier
cpu: Don't try to pause CPUs if they are already stopped
pc: Don't crash on apic_accept_pic_intr() if CPU has no apic_state
target-i386: Make CPU objects user-creatable
target-i386: Report QOM class name for CPU definitions
cpus.c | 13 ++++++++++---
exec.c | 1 +
hw/i386/pc.c | 2 +-
qapi-schema.json | 6 +++++-
target-i386/cpu.c | 7 +++++++
5 files changed, 24 insertions(+), 5 deletions(-)
--
1.9.0
10 years, 6 months
[libvirt] [PATCHv2 0/2] Honor DAC norelabel attribute
by Michal Privoznik
Version two, this time split into two patches.
Michal Privoznik (2):
security_dac: Rework to make it more readable
security_dac: Honor norelabel attribute
src/security/security_dac.c | 355 ++++++++++++++++++++++++++------------------
1 file changed, 213 insertions(+), 142 deletions(-)
--
1.9.0
10 years, 6 months
[libvirt] [PATCH] bhyve: implement connectGetSysinfo
by Roman Bogorodskiy
---
src/bhyve/bhyve_driver.c | 31 +++++++++++++++++++++++++++++++
src/bhyve/bhyve_utils.h | 1 +
2 files changed, 32 insertions(+)
diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index 0cafe4c..ec1ba69 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -237,6 +237,33 @@ bhyveConnectGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED)
return virGetHostname();
}
+static char *
+bhyveConnectGetSysinfo(virConnectPtr conn, unsigned int flags)
+{
+ bhyveConnPtr privconn = conn->privateData;
+ virBuffer buf = VIR_BUFFER_INITIALIZER;
+
+ virCheckFlags(0, NULL);
+
+ if (virConnectGetSysinfoEnsureACL(conn) < 0)
+ return NULL;
+
+ if (!privconn->hostsysinfo) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("Host SMBIOS information is not available"));
+ return NULL;
+ }
+
+ if (virSysinfoFormat(&buf, privconn->hostsysinfo) < 0)
+ return NULL;
+ if (virBufferError(&buf)) {
+ virReportOOMError();
+ return NULL;
+ }
+
+ return virBufferContentAndReset(&buf);
+}
+
static int
bhyveConnectGetVersion(virConnectPtr conn ATTRIBUTE_UNUSED, unsigned long *version)
{
@@ -976,6 +1003,7 @@ bhyveStateCleanup(void)
virObjectUnref(bhyve_driver->domains);
virObjectUnref(bhyve_driver->caps);
virObjectUnref(bhyve_driver->xmlopt);
+ virObjectUnref(bhyve_driver->hostsysinfo);
virObjectUnref(bhyve_driver->closeCallbacks);
virMutexDestroy(&bhyve_driver->lock);
@@ -1015,6 +1043,8 @@ bhyveStateInitialize(bool priveleged ATTRIBUTE_UNUSED,
if (!(bhyve_driver->domains = virDomainObjListNew()))
goto cleanup;
+ bhyve_driver->hostsysinfo = virSysinfoRead();
+
if (virFileMakePath(BHYVE_LOG_DIR) < 0) {
virReportSystemError(errno,
_("Failed to mkdir %s"),
@@ -1173,6 +1203,7 @@ static virDriver bhyveDriver = {
.connectClose = bhyveConnectClose, /* 1.2.2 */
.connectGetVersion = bhyveConnectGetVersion, /* 1.2.2 */
.connectGetHostname = bhyveConnectGetHostname, /* 1.2.2 */
+ .connectGetSysinfo = bhyveConnectGetSysinfo, /* 1.2.4 */
.domainGetInfo = bhyveDomainGetInfo, /* 1.2.2 */
.domainGetState = bhyveDomainGetState, /* 1.2.2 */
.connectGetCapabilities = bhyveConnectGetCapabilities, /* 1.2.2 */
diff --git a/src/bhyve/bhyve_utils.h b/src/bhyve/bhyve_utils.h
index 94f31b0..22f458d 100644
--- a/src/bhyve/bhyve_utils.h
+++ b/src/bhyve/bhyve_utils.h
@@ -39,6 +39,7 @@ struct _bhyveConn {
virCapsPtr caps;
virDomainXMLOptionPtr xmlopt;
char *pidfile;
+ virSysinfoDefPtr hostsysinfo;
virCloseCallbacksPtr closeCallbacks;
};
--
1.9.0
10 years, 6 months
[libvirt] [PATCH] ESX: add virStorageVolGetInfo in iSCSI backend.
by Dawid Zamirski
Since the ESX storage implements VMFS and iSCSI storage backends and
chooses relevant backend dynamically at runtime, there was a segfault
when issuing vol-info on iSCSI volume due to unimplemented
virStorageGetInfo function. This patch implements that function that was
missing in iSCSI backend and returns expected result without a segfault.
---
src/esx/esx_storage_backend_iscsi.c | 47 +++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
diff --git a/src/esx/esx_storage_backend_iscsi.c b/src/esx/esx_storage_backend_iscsi.c
index 4619629..3d31908 100644
--- a/src/esx/esx_storage_backend_iscsi.c
+++ b/src/esx/esx_storage_backend_iscsi.c
@@ -621,6 +621,52 @@ esxStorageVolCreateXMLFrom(virStoragePoolPtr pool ATTRIBUTE_UNUSED,
+static int
+esxStorageVolGetInfo(virStorageVolPtr volume,
+ virStorageVolInfoPtr info)
+{
+ int result = -1;
+ esxPrivate *priv = volume->conn->storagePrivateData;
+ esxVI_ScsiLun *scsiLunList = NULL;
+ esxVI_ScsiLun *scsiLun;
+ esxVI_HostScsiDisk *hostScsiDisk = NULL;
+
+ if (esxVI_LookupScsiLunList(priv->primary, &scsiLunList) < 0) {
+ goto cleanup;
+ }
+
+ for (scsiLun = scsiLunList; scsiLun;
+ scsiLun = scsiLun->_next) {
+ hostScsiDisk = esxVI_HostScsiDisk_DynamicCast(scsiLun);
+
+ if (hostScsiDisk &&
+ STREQ(hostScsiDisk->deviceName, volume->name)) {
+ break;
+ }
+ }
+
+ if (!hostScsiDisk) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Could not find volume with name: %s"),
+ volume->name);
+ goto cleanup;
+ }
+
+ info->type = VIR_STORAGE_VOL_BLOCK;
+ info->capacity = hostScsiDisk->capacity->block->value *
+ hostScsiDisk->capacity->blockSize->value;
+ info->allocation = info->capacity;
+
+ result = 0;
+
+ cleanup:
+ esxVI_ScsiLun_Free(&scsiLunList);
+
+ return result;
+}
+
+
+
static char *
esxStorageVolGetXMLDesc(virStorageVolPtr volume,
unsigned int flags)
@@ -752,6 +798,7 @@ virStorageDriver esxStorageBackendISCSI = {
.storageVolLookupByKey = esxStorageVolLookupByKey, /* 1.0.1 */
.storageVolCreateXML = esxStorageVolCreateXML, /* 1.0.1 */
.storageVolCreateXMLFrom = esxStorageVolCreateXMLFrom, /* 1.0.1 */
+ .storageVolGetInfo = esxStorageVolGetInfo, /* 1.2.4 */
.storageVolGetXMLDesc = esxStorageVolGetXMLDesc, /* 1.0.1 */
.storageVolDelete = esxStorageVolDelete, /* 1.0.1 */
.storageVolWipe = esxStorageVolWipe, /* 1.0.1 */
--
1.9.0
10 years, 6 months
[libvirt] [PATCH] qemu: Adjust size for qcow2/qed if not on sector boundary
by John Ferlan
https://bugzilla.redhat.com/show_bug.cgi?id=1002813
If qemuDomainBlockResize() is passed a size not on a KiB boundary - that
is passed a size based in bytes (VIR_DOMAIN_BLOCK_RESIZE_BYTES), then
depending on the source format (qcow2 or qed), the value passed must
be on a sector (or 512 byte) boundary. Since other libvirt code quietly
adjusts the capacity values, then do so here as well - of course ensuring
that adjustment still fits.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/qemu/qemu_driver.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 4bb4819..3e407d7 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -9421,6 +9421,7 @@ qemuDomainBlockResize(virDomainPtr dom,
virDomainObjPtr vm;
qemuDomainObjPrivatePtr priv;
int ret = -1, idx;
+ unsigned long long size_up;
char *device = NULL;
virDomainDiskDefPtr disk = NULL;
@@ -9441,6 +9442,12 @@ qemuDomainBlockResize(virDomainPtr dom,
return -1;
}
size *= 1024;
+ size_up = size;
+ } else {
+ /* For 'qcow2' and 'qed', qemu resize blocks expects values
+ * on sector boundary, so round our value up to prepare
+ */
+ size_up = VIR_ROUND_UP(size, 512);
}
if (!(vm = qemuDomObjFromDomain(dom)))
@@ -9467,6 +9474,21 @@ qemuDomainBlockResize(virDomainPtr dom,
}
disk = vm->def->disks[idx];
+ /* qcow2 and qed must be sized appropriately, so be sure our value
+ * is sized appropriately and will fit
+ */
+ if (size != size_up &&
+ (disk->src.format == VIR_STORAGE_FILE_QCOW2 ||
+ disk->src.format == VIR_STORAGE_FILE_QED)) {
+ if (size_up > ULLONG_MAX) {
+ virReportError(VIR_ERR_OVERFLOW,
+ _("size must be less than %llu KiB"),
+ ULLONG_MAX / 1024);
+ goto endjob;
+ }
+ size = size_up;
+ }
+
if (virAsprintf(&device, "%s%s", QEMU_DRIVE_HOST_PREFIX,
disk->info.alias) < 0)
goto endjob;
--
1.9.0
10 years, 6 months
[libvirt] [PATCH 0/4] parallels: a set of fixes
by Dmitry Guryanov
Hello,
I'd like to continue working on the parallels driver. So here
is a set of patches, which resolves some problems.
Now Parallels has a definite goal with this driver: we want
OpenStack to be working with Parallels Cloud Server (PCS) over
libvirt, and we a ready to implement all needed API calls
in libvirt's driver and make necessary changes in PCS.
P.S.
I appreciate greatly effort needed to support the driver in
compilable state and a lot of refactoring made by libvirt
team, thanks!
Dmitry Guryanov (4):
parallels: fix virDomainDef.features comparison
parallels: don't enable VNC when we define a new domain
parallels: don't add domain to the list twice
parallels: add a set of trivial functions
src/parallels/parallels_driver.c | 57 ++++++++++++++++++++++------------------
1 file changed, 31 insertions(+), 26 deletions(-)
--
1.9.0
10 years, 6 months
[libvirt] [libvirt PATCH] udev: consider the device a CDROM when ID_CDROM=1
by Giuseppe Scrivano
Some CDROM devices are reported by udev to have an ID_TYPE="generic"
thus it is necessary to check if ID_CDROM is present.
As a side effect, treating ID_TYPE="generic" as a missing ID_TYPE will
enable checks for ID_DRIVE_FLASH_SD and ID_DRIVE_FLOPPY and the
udevKludgeStorageType heuristic.
Signed-off-by: Giuseppe Scrivano <gscrivan(a)redhat.com>
---
src/node_device/node_device_udev.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index 71b3c79..de1cc67 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -1,7 +1,7 @@
/*
* node_device_udev.c: node device enumeration - libudev implementation
*
- * Copyright (C) 2009-2013 Red Hat, Inc.
+ * Copyright (C) 2009-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
@@ -1093,7 +1093,8 @@ static int udevProcessStorage(struct udev_device *device,
if (udevGetStringProperty(device,
"ID_TYPE",
- &data->storage.drive_type) != PROPERTY_FOUND) {
+ &data->storage.drive_type) != PROPERTY_FOUND
+ || STREQ(def->caps->data.storage.drive_type, "generic")) {
int tmp_int = 0;
/* All floppy drives have the ID_DRIVE_FLOPPY prop. This is
@@ -1104,6 +1105,12 @@ static int udevProcessStorage(struct udev_device *device,
if (VIR_STRDUP(data->storage.drive_type, "floppy") < 0)
goto out;
+ } else if ((udevGetIntProperty(device, "ID_CDROM",
+ &tmp_int, 0) == PROPERTY_FOUND) &&
+ (tmp_int == 1)) {
+
+ if (VIR_STRDUP(data->storage.drive_type, "cd") < 0)
+ goto out;
} else if ((udevGetIntProperty(device, "ID_DRIVE_FLASH_SD",
&tmp_int, 0) == PROPERTY_FOUND) &&
(tmp_int == 1)) {
--
1.9.0
10 years, 6 months
[libvirt] [PATCH] PCI: Introduce new device binding path using pci_dev.driver_override
by Alex Williamson
The driver_override field allows us to specify the driver for a device
rather than relying on the driver to provide a positive match of the
device. This shortcuts the existing process of looking up the vendor
and device ID, adding them to the driver new_id, binding the device,
then removing the ID, but it also provides a couple advantages.
First, the above existing process allows the driver to bind to any
device matching the new_id for the window where it's enabled. This is
often not desired, such as the case of trying to bind a single device
to a meta driver like pci-stub or vfio-pci. Using driver_override we
can do this deterministically using:
echo pci-stub > /sys/bus/pci/devices/0000:03:00.0/driver_override
echo 0000:03:00.0 > /sys/bus/pci/devices/0000:03:00.0/driver/unbind
echo 0000:03:00.0 > /sys/bus/pci/drivers_probe
Previously we could not invoke drivers_probe after adding a device
to new_id for a driver as we get non-deterministic behavior whether
the driver we intend or the standard driver will claim the device.
Now it becomes a deterministic process, only the driver matching
driver_override will probe the device.
To return the device to the standard driver, we simply clear the
driver_override and reprobe the device:
echo > /sys/bus/pci/devices/0000:03:00.0/preferred_driver
echo 0000:03:00.0 > /sys/bus/pci/devices/0000:03:00.0/driver/unbind
echo 0000:03:00.0 > /sys/bus/pci/drivers_probe
Another advantage to this approach is that we can specify a driver
override to force a specific binding or prevent any binding. For
instance when an IOMMU group is exposed to userspace through VFIO
we require that all devices within that group are owned by VFIO.
However, devices can be hot-added into an IOMMU group, in which case
we want to prevent the device from binding to any driver (preferred
driver = "none") or perhaps have it automatically bind to vfio-pci.
With driver_override it's a simple matter for this field to be set
internally when the device is first discovered to prevent driver
matches.
Signed-off-by: Alex Williamson <alex.williamson(a)redhat.com>
---
Changes since RFC:
- Add ABI documentation (gregkh)
- Documentation wording clarification (Christoffer)
Nobody puked on the RFC and platform folks have posted a working
version of this for platform devices, so I guess the only thing left
to do is formally propose this as a new driver binding mechanism. I
don't see much incentive to push this into the driver core since the
match ultimately needs to be done by the bus driver. I think this is
therefore like new_id/remove_id where PCI and USB implement separate,
but consistent interfaces.
I've pruned the CC list a bit from the RFC, but I've added libvirt
folks since I expect they would be the first userspace tool that would
adopt this. Thanks,
Alex
Documentation/ABI/testing/sysfs-bus-pci | 21 ++++++++++++++++
drivers/pci/pci-driver.c | 25 +++++++++++++++++--
drivers/pci/pci-sysfs.c | 40 +++++++++++++++++++++++++++++++
include/linux/pci.h | 1 +
4 files changed, 84 insertions(+), 3 deletions(-)
diff --git a/Documentation/ABI/testing/sysfs-bus-pci b/Documentation/ABI/testing/sysfs-bus-pci
index a3c5a66..898ddc4 100644
--- a/Documentation/ABI/testing/sysfs-bus-pci
+++ b/Documentation/ABI/testing/sysfs-bus-pci
@@ -250,3 +250,24 @@ Description:
valid. For example, writing a 2 to this file when sriov_numvfs
is not 0 and not 2 already will return an error. Writing a 10
when the value of sriov_totalvfs is 8 will return an error.
+
+What: /sys/bus/pci/devices/.../driver_override
+Date: April 2014
+Contact: Alex Williamson <alex.williamson(a)redhat.com>
+Description:
+ This file allows the driver for a device to be specified which
+ will override standard static and dynamic ID matching. When
+ specified, only a driver with a name matching the value written
+ to driver_override will have an opportunity to bind to the
+ device. The override is specified by writing a string to the
+ driver_override file (echo pci-stub > driver_override) and
+ may be cleared with an empty string (echo > driver_override).
+ This returns the device to standard matching rules binding.
+ Writing to driver_override does not automatically unbind the
+ device from its current driver or make any attempt to
+ automatically load the specified driver. If no driver with a
+ matching name is currently loaded in the kernel, the device
+ will not bind to any driver. This also allows devices to
+ opt-out of driver binding using a driver_override name such as
+ "none". Only a single driver may be specified in the override,
+ there is no support for parsing delimiters.
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 25f0bc6..f780eb8 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -216,6 +216,13 @@ const struct pci_device_id *pci_match_id(const struct pci_device_id *ids,
return NULL;
}
+static const struct pci_device_id pci_device_id_any = {
+ .vendor = PCI_ANY_ID,
+ .device = PCI_ANY_ID,
+ .subvendor = PCI_ANY_ID,
+ .subdevice = PCI_ANY_ID,
+};
+
/**
* pci_match_device - Tell if a PCI device structure has a matching PCI device id structure
* @drv: the PCI driver to match against
@@ -229,18 +236,30 @@ static const struct pci_device_id *pci_match_device(struct pci_driver *drv,
struct pci_dev *dev)
{
struct pci_dynid *dynid;
+ const struct pci_device_id *found_id = NULL;
+
+ /* When driver_override is set, only bind to the matching driver */
+ if (dev->driver_override && strcmp(dev->driver_override, drv->name))
+ return NULL;
/* Look at the dynamic ids first, before the static ones */
spin_lock(&drv->dynids.lock);
list_for_each_entry(dynid, &drv->dynids.list, node) {
if (pci_match_one_device(&dynid->id, dev)) {
- spin_unlock(&drv->dynids.lock);
- return &dynid->id;
+ found_id = &dynid->id;
+ break;
}
}
spin_unlock(&drv->dynids.lock);
- return pci_match_id(drv->id_table, dev);
+ if (!found_id)
+ found_id = pci_match_id(drv->id_table, dev);
+
+ /* driver_override will always match, send a dummy id */
+ if (!found_id && dev->driver_override)
+ found_id = &pci_device_id_any;
+
+ return found_id;
}
struct drv_dev_and_id {
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 276ef9c..70cb39d 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -510,6 +510,45 @@ static struct device_attribute sriov_numvfs_attr =
sriov_numvfs_show, sriov_numvfs_store);
#endif /* CONFIG_PCI_IOV */
+static ssize_t driver_override_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct pci_dev *pdev = to_pci_dev(dev);
+ char *driver_override, *old = pdev->driver_override;
+
+ if (count > PATH_MAX)
+ return -EINVAL;
+
+ driver_override = kstrndup(buf, count, GFP_KERNEL);
+ if (!driver_override)
+ return -ENOMEM;
+
+ while (strlen(driver_override) &&
+ driver_override[strlen(driver_override) - 1] == '\n')
+ driver_override[strlen(driver_override) - 1] = '\0';
+
+ if (strlen(driver_override)) {
+ pdev->driver_override = driver_override;
+ } else {
+ kfree(driver_override);
+ pdev->driver_override = NULL;
+ }
+
+ kfree(old);
+
+ return count;
+}
+
+static ssize_t driver_override_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct pci_dev *pdev = to_pci_dev(dev);
+
+ return sprintf(buf, "%s\n", pdev->driver_override);
+}
+static DEVICE_ATTR_RW(driver_override);
+
static struct attribute *pci_dev_attrs[] = {
&dev_attr_resource.attr,
&dev_attr_vendor.attr,
@@ -532,6 +571,7 @@ static struct attribute *pci_dev_attrs[] = {
#if defined(CONFIG_PM_RUNTIME) && defined(CONFIG_ACPI)
&dev_attr_d3cold_allowed.attr,
#endif
+ &dev_attr_driver_override.attr,
NULL,
};
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 33aa2ca..6b666af 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -364,6 +364,7 @@ struct pci_dev {
#endif
phys_addr_t rom; /* Physical address of ROM if it's not from the BAR */
size_t romlen; /* Length of ROM if it's not from the BAR */
+ char *driver_override; /* Driver name to force a match */
};
static inline struct pci_dev *pci_physfn(struct pci_dev *dev)
10 years, 6 months