[libvirt] [PATCH v4] leaseshelper: improvements to support all events
by Nehal J Wani
This patch enables the helper program to detect event(s) triggered when there
is a change in lease length or expiry and client-id. This transfers complete
control of leases database to libvirt and obsoletes use of the lease database
file (<network-name>.leases). That file will not be created, read, or written.
This is achieved by adding the option --leasefile-ro to dnsmasq and passing a
custom env var to leaseshelper, which helps us map events related to leases
with their corresponding network bridges, no matter what the event be.
Also, this requires the addition of a new non-lease entry in our custom lease
database: "server-duid". It is required to identify a DHCPv6 server.
Now that dnsmasq doesn't maintain its own leases database, it relies on our
helper program to tell it about previous leases and server duid. Thus, this
patch makes our leases program honor an extra action: "init", in which it sends
the known info in a particular format to dnsmasq by printing it to stdout.
---
This is compatible with libvirt 1.2.6 as only additions have been
introduced, and the old leases file (*.status) will still be supported.
v4: * Removed extra data structures for segregating ipv4 and ipv6 leases.
v3: * Add server-duid as an entry in the lease object for every ipv6 lease.
* Remove unnecessary variables and double copies.
* Take value from DNSMASQ_OLD_HOSTNAME if hostname is not known.
http://www.redhat.com/archives/libvir-list/2014-August/msg00028.html
v2: http://www.redhat.com/archives/libvir-list/2014-July/msg01109.html
v1: https://www.redhat.com/archives/libvir-list/2014-July/msg00568.html
---
src/network/bridge_driver.c | 3 +
src/network/leaseshelper.c | 142 +++++++++++++++++++++++++++++++++++---------
2 files changed, 117 insertions(+), 28 deletions(-)
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 6cb421c..6ecbc37 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -1280,7 +1280,10 @@ networkBuildDhcpDaemonCommandLine(virNetworkObjPtr network,
cmd = virCommandNew(dnsmasqCapsGetBinaryPath(caps));
virCommandAddArgFormat(cmd, "--conf-file=%s", configfile);
+ /* Libvirt gains full control of leases database */
+ virCommandAddArgFormat(cmd, "--leasefile-ro");
virCommandAddArgFormat(cmd, "--dhcp-script=%s", leaseshelper_path);
+ virCommandAddEnvPair(cmd, "VIR_BRIDGE_NAME", network->def->bridge);
*cmdout = cmd;
ret = 0;
diff --git a/src/network/leaseshelper.c b/src/network/leaseshelper.c
index 5b3c9c3..fdd04a3 100644
--- a/src/network/leaseshelper.c
+++ b/src/network/leaseshelper.c
@@ -50,6 +50,12 @@
*/
#define VIR_NETWORK_DHCP_LEASE_FILE_SIZE_MAX (32 * 1024 * 1024)
+/*
+ * Use this when passing possibly-NULL strings to printf-a-likes.
+ * Required for unknown parameters during init call.
+ */
+#define EMPTY_STR(s) ((s) ? (s) : "*")
+
static const char *program_name;
/* Display version information. */
@@ -65,7 +71,7 @@ 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"
+ printf(_("Usage: %s add|old|del|init 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);
@@ -89,6 +95,7 @@ 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_INIT, /* Tell dnsmasq of existing leases on restart */
VIR_LEASE_ACTION_LAST
};
@@ -96,7 +103,7 @@ enum virLeaseActionFlags {
VIR_ENUM_DECL(virLeaseAction);
VIR_ENUM_IMPL(virLeaseAction, VIR_LEASE_ACTION_LAST,
- "add", "old", "del");
+ "add", "old", "del", "init");
int
main(int argc, char **argv)
@@ -107,12 +114,15 @@ main(int argc, char **argv)
char *custom_lease_file = NULL;
const char *ip = NULL;
const char *mac = NULL;
+ const char *ip_tmp = NULL;
+ const char *leases_str = NULL;
+ const char *server_duid_tmp = 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;
+ const char *server_duid = virGetEnvAllowSUID("DNSMASQ_SERVER_DUID");
long long currtime = 0;
long long expirytime = 0;
size_t i = 0;
@@ -120,7 +130,6 @@ main(int argc, char **argv)
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;
@@ -156,16 +165,17 @@ main(int argc, char **argv)
}
}
- if (argc != 4 && argc != 5) {
+ if (argc != 4 && argc != 5 && argc != 2) {
/* 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)
+ * via env variable set by dnsmasq when dnsmasq (re)starts and throws 'del'
+ * events for expired leases. So, libvirtd sets another env var for this
+ * purpose */
+ if (!interface &&
+ !(interface = virGetEnvAllowSUID("VIR_BRIDGE_NAME")))
goto cleanup;
ip = argv[3];
@@ -176,6 +186,10 @@ main(int argc, char **argv)
if (argc == 5)
hostname = argv[4];
+ /* In case hostname is still unknown, use the last known one */
+ if (!hostname)
+ hostname = virGetEnvAllowSUID("DNSMASQ_OLD_HOSTNAME");
+
if (VIR_STRDUP(exptime, exptime_tmp) < 0)
goto cleanup;
@@ -184,7 +198,7 @@ main(int argc, char **argv)
exptime[strlen(exptime) - 1] = '\0';
/* Check if it is an IPv6 lease */
- if (virGetEnvAllowSUID("DNSMASQ_IAID")) {
+ if (iaid) {
mac = virGetEnvAllowSUID("DNSMASQ_MAC");
clientid = argv[2];
}
@@ -234,7 +248,6 @@ main(int argc, char **argv)
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",
@@ -259,11 +272,13 @@ main(int argc, char **argv)
goto cleanup;
if (clientid && virJSONValueObjectAppendString(lease_new, "client-id", clientid) < 0)
goto cleanup;
+ if (server_duid && virJSONValueObjectAppendString(lease_new, "server-duid", server_duid) < 0)
+ goto cleanup;
if (expirytime && virJSONValueObjectAppendNumberLong(lease_new, "expiry-time", expirytime) < 0)
goto cleanup;
}
}
- } else {
+ } else if (action != VIR_LEASE_ACTION_INIT) {
fprintf(stderr, _("Unsupported action: %s\n"),
virLeaseActionTypeToString(action));
exit(EXIT_FAILURE);
@@ -292,8 +307,6 @@ main(int argc, char **argv)
i = 0;
while (i < virJSONValueArraySize(leases_array)) {
- const char *ip_tmp = NULL;
- long long expirytime_tmp = -1;
if (!(lease_tmp = virJSONValueArrayGet(leases_array, i))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -302,14 +315,13 @@ main(int argc, char **argv)
}
if (!(ip_tmp = virJSONValueObjectGetString(lease_tmp, "ip-address")) ||
- (virJSONValueObjectGetNumberLong(lease_tmp, "expiry-time", &expirytime_tmp) < 0)) {
+ (virJSONValueObjectGetNumberLong(lease_tmp, "expiry-time", &expirytime) < 0)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("failed to parse json"));
goto cleanup;
}
-
/* Check whether lease has expired or not */
- if (expirytime_tmp < currtime) {
+ if (expirytime < currtime) {
i++;
continue;
}
@@ -320,6 +332,25 @@ main(int argc, char **argv)
continue;
}
+ if (strchr(ip_tmp, ':')) {
+ /* This is an ipv6 lease */
+ if ((server_duid_tmp
+ = virJSONValueObjectGetString(lease_tmp, "server-duid"))) {
+ if (!server_duid) {
+ /* Control reaches here when the 'action' is not for an
+ * ipv6 lease or, for some weird reason the env var
+ * DNSMASQ_SERVER_DUID wasn't set*/
+ server_duid = server_duid_tmp;
+ }
+ } else {
+ /* Inject server-duid into those ipv6 leases which
+ * didn't have it previously, for example, those
+ * created by leaseshelper from libvirt 1.2.6 */
+ if (virJSONValueObjectAppendString(lease_tmp, "server-duid", server_duid) < 0)
+ goto cleanup;
+ }
+ }
+
/* Move old lease to new array */
if (virJSONValueArrayAppend(leases_array_new, lease_tmp) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -332,25 +363,80 @@ main(int argc, char **argv)
}
}
- if (add) {
+ switch ((enum virLeaseActionFlags) action) {
+ case VIR_LEASE_ACTION_INIT:
+ /* Man page of dnsmasq says: the script (helper program, in our case)
+ * should write the saved state of the lease database, in dnsmasq
+ * leasefile format, to stdout and exit with zero exit code, when
+ * called with argument init. Format:
+ * $expirytime $mac $ip $hostname $clientid # For all ipv4 leases
+ * duid $server-duid # If DHCPv6 is present
+ * $expirytime $iaid $ip $hostname $clientduid # For all ipv6 leases */
+
+ /* Traversing the ipv4 leases */
+ for (i = 0; i < virJSONValueArraySize(leases_array_new); i++) {
+ lease_tmp = virJSONValueArrayGet(leases_array_new, i);
+ if (!(ip_tmp = virJSONValueObjectGetString(lease_tmp, "ip-address"))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("failed to parse json"));
+ goto cleanup;
+ }
+ if (!strchr(ip_tmp, ':')) {
+ virJSONValueObjectGetNumberLong(lease_tmp, "expiry-time", &expirytime);
+ printf("%lld %s %s %s %s\n",
+ expirytime,
+ virJSONValueObjectGetString(lease_tmp, "mac-address"),
+ virJSONValueObjectGetString(lease_tmp, "ip-address"),
+ EMPTY_STR(virJSONValueObjectGetString(lease_tmp, "hostname")),
+ EMPTY_STR(virJSONValueObjectGetString(lease_tmp, "client-id")));
+ }
+ }
+
+ /* Traversing the ipv6 leases */
+ if (server_duid) {
+ printf("duid %s\n", server_duid);
+ for (i = 0; i < virJSONValueArraySize(leases_array_new); i++) {
+ lease_tmp = virJSONValueArrayGet(leases_array_new, i);
+ if (!(ip_tmp = virJSONValueObjectGetString(lease_tmp, "ip-address"))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("failed to parse json"));
+ goto cleanup;
+ }
+ if (strchr(ip_tmp, ':')) {
+ virJSONValueObjectGetNumberLong(lease_tmp, "expiry-time", &expirytime);
+ printf("%lld %s %s %s %s\n",
+ expirytime,
+ virJSONValueObjectGetString(lease_tmp, "iaid"),
+ virJSONValueObjectGetString(lease_tmp, "ip-address"),
+ EMPTY_STR(virJSONValueObjectGetString(lease_tmp, "hostname")),
+ EMPTY_STR(virJSONValueObjectGetString(lease_tmp, "client-id")));
+ }
+ }
+ }
+
+ break;
+
+ case VIR_LEASE_ACTION_OLD:
+ case VIR_LEASE_ACTION_ADD:
if (virJSONValueArrayAppend(leases_array_new, lease_new) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("failed to create json"));
goto cleanup;
}
lease_new = NULL;
- }
- if (!(leases_str = virJSONValueToString(leases_array_new, true))) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("empty json array"));
- goto cleanup;
- }
+ default:
+ 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;
+ /* Write to file */
+ if (virFileRewrite(custom_lease_file, 0644,
+ customLeaseRewriteFile, &leases_str) < 0)
+ goto cleanup;
+ }
rv = EXIT_SUCCESS;
--
1.9.3
10 years, 1 month
[libvirt] [PATCHv2] virsh: Fix msg: blockjob is aborted from another client
by Erik Skultety
When a block{pull, copy, commit} is aborted via keyboard interrupt,
the job is properly canceled followed by proper error message.
However, when the job receives an abort from another client connected
to the same domain, the error message incorrectly indicates that
a blockjob has been finished successfully, though the abort request
took effect. This patch introduces a new blockjob abort handler, which
is registered when the client calls block{copy,commit,pull} routine,
providing its caller the status of the finished blockjob.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1135442
---
tools/virsh-domain.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 62 insertions(+), 3 deletions(-)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index a7e9151..90960e9 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -1709,6 +1709,17 @@ static void vshCatchInt(int sig ATTRIBUTE_UNUSED,
intCaught = 1;
}
+static void
+vshBlockJobStatusHandler(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virDomainPtr dom ATTRIBUTE_UNUSED,
+ const char *disk ATTRIBUTE_UNUSED,
+ int type ATTRIBUTE_UNUSED,
+ int status,
+ void *opaque)
+{
+ *(int *) opaque = status;
+}
+
/*
* "blockcommit" command
*/
@@ -1808,6 +1819,8 @@ cmdBlockCommit(vshControl *ctl, const vshCmd *cmd)
const char *path = NULL;
bool quit = false;
int abort_flags = 0;
+ int status = -1;
+ int cb_id = -1;
blocking |= vshCommandOptBool(cmd, "timeout") || pivot || finish;
if (blocking) {
@@ -1837,6 +1850,16 @@ cmdBlockCommit(vshControl *ctl, const vshCmd *cmd)
return false;
}
+ virConnectDomainEventGenericCallback cb =
+ VIR_DOMAIN_EVENT_CALLBACK(vshBlockJobStatusHandler);
+
+ cb_id = virConnectDomainEventRegisterAny(ctl->conn,
+ dom,
+ VIR_DOMAIN_EVENT_ID_BLOCK_JOB,
+ cb,
+ &status,
+ NULL);
+
if (!blockJobImpl(ctl, cmd, VSH_CMD_BLOCK_JOB_COMMIT, &dom))
goto cleanup;
@@ -1878,7 +1901,7 @@ cmdBlockCommit(vshControl *ctl, const vshCmd *cmd)
intCaught ? "interrupted" : "timeout");
intCaught = 0;
timeout = 0;
- quit = true;
+ status = VIR_DOMAIN_BLOCK_JOB_CANCELED;
if (virDomainBlockJobAbort(dom, path, abort_flags) < 0) {
vshError(ctl, _("failed to abort job for disk %s"), path);
goto cleanup;
@@ -1890,6 +1913,9 @@ cmdBlockCommit(vshControl *ctl, const vshCmd *cmd)
}
}
+ if (status == VIR_DOMAIN_BLOCK_JOB_CANCELED)
+ quit = true;
+
if (verbose && !quit) {
/* printf [100 %] */
vshPrintJobProgress(_("Block Commit"), 0, 1);
@@ -1920,6 +1946,7 @@ cmdBlockCommit(vshControl *ctl, const vshCmd *cmd)
virDomainFree(dom);
if (blocking)
sigaction(SIGINT, &old_sig_action, NULL);
+ virConnectDomainEventDeregisterAny(ctl->conn, cb_id);
return ret;
}
@@ -2043,6 +2070,8 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd)
char *xmlstr = NULL;
virTypedParameterPtr params = NULL;
int nparams = 0;
+ int status = -1;
+ int cb_id = -1;
if (vshCommandOptStringReq(ctl, cmd, "path", &path) < 0)
return false;
@@ -2083,6 +2112,16 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd)
return false;
}
+ virConnectDomainEventGenericCallback cb =
+ VIR_DOMAIN_EVENT_CALLBACK(vshBlockJobStatusHandler);
+
+ cb_id = virConnectDomainEventRegisterAny(ctl->conn,
+ dom,
+ VIR_DOMAIN_EVENT_ID_BLOCK_JOB,
+ cb,
+ &status,
+ NULL);
+
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
goto cleanup;
@@ -2216,7 +2255,7 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd)
intCaught ? "interrupted" : "timeout");
intCaught = 0;
timeout = 0;
- quit = true;
+ status = VIR_DOMAIN_BLOCK_JOB_CANCELED;
if (virDomainBlockJobAbort(dom, path, abort_flags) < 0) {
vshError(ctl, _("failed to abort job for disk %s"), path);
goto cleanup;
@@ -2228,6 +2267,9 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd)
}
}
+ if (status == VIR_DOMAIN_BLOCK_JOB_CANCELED)
+ quit = true;
+
if (!quit && pivot) {
abort_flags |= VIR_DOMAIN_BLOCK_JOB_ABORT_PIVOT;
if (virDomainBlockJobAbort(dom, path, abort_flags) < 0) {
@@ -2256,6 +2298,7 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd)
virDomainFree(dom);
if (blocking)
sigaction(SIGINT, &old_sig_action, NULL);
+ virConnectDomainEventDeregisterAny(ctl->conn, cb_id);
return ret;
}
@@ -2513,6 +2556,8 @@ cmdBlockPull(vshControl *ctl, const vshCmd *cmd)
const char *path = NULL;
bool quit = false;
int abort_flags = 0;
+ int status = -1;
+ int cb_id = -1;
if (blocking) {
if (vshCommandOptTimeoutToMs(ctl, cmd, &timeout) < 0)
@@ -2538,6 +2583,16 @@ cmdBlockPull(vshControl *ctl, const vshCmd *cmd)
return false;
}
+ virConnectDomainEventGenericCallback cb =
+ VIR_DOMAIN_EVENT_CALLBACK(vshBlockJobStatusHandler);
+
+ cb_id = virConnectDomainEventRegisterAny(ctl->conn,
+ dom,
+ VIR_DOMAIN_EVENT_ID_BLOCK_JOB,
+ cb,
+ &status,
+ NULL);
+
if (!blockJobImpl(ctl, cmd, VSH_CMD_BLOCK_JOB_PULL, &dom))
goto cleanup;
@@ -2574,7 +2629,7 @@ cmdBlockPull(vshControl *ctl, const vshCmd *cmd)
intCaught ? "interrupted" : "timeout");
intCaught = 0;
timeout = 0;
- quit = true;
+ status = VIR_DOMAIN_BLOCK_JOB_CANCELED;
if (virDomainBlockJobAbort(dom, path, abort_flags) < 0) {
vshError(ctl, _("failed to abort job for disk %s"), path);
goto cleanup;
@@ -2586,6 +2641,9 @@ cmdBlockPull(vshControl *ctl, const vshCmd *cmd)
}
}
+ if (status == VIR_DOMAIN_BLOCK_JOB_CANCELED)
+ quit = true;
+
if (verbose && !quit) {
/* printf [100 %] */
vshPrintJobProgress(_("Block Pull"), 0, 1);
@@ -2598,6 +2656,7 @@ cmdBlockPull(vshControl *ctl, const vshCmd *cmd)
virDomainFree(dom);
if (blocking)
sigaction(SIGINT, &old_sig_action, NULL);
+ virConnectDomainEventDeregisterAny(ctl->conn, cb_id);
return ret;
}
--
1.9.3
10 years, 1 month
[libvirt] [PATCH] maint: use portable shell
by Eric Blake
Reported in https://bugzilla.redhat.com/show_bug.cgi?id=1165827;
dash complains:
checking for pkcheck... /usr/bin/pkcheck
checking whether pkcheck supports uid value... yes
./configure: 63906: test: xno: unexpected operator
checking for dtrace... no
Broken in commit bf15638 (v0.10.0)
* configure.ac: Use '=' not '==' in test.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
Pushing under the build-breaker rule.
configure.ac | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/configure.ac b/configure.ac
index 5a670eb..9fd44b2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1389,7 +1389,7 @@ AC_ARG_WITH([firewalld],
if test "x$with_firewalld" = "xcheck" ; then
with_firewalld=$with_dbus
fi
-if test "x$with_firewalld" == "xyes" ; then
+if test "x$with_firewalld" = "xyes" ; then
if test "x$with_dbus" != "xyes" ; then
AC_MSG_ERROR([You must have dbus enabled for firewalld support])
fi
--
1.9.3
10 years, 1 month
[libvirt] [libvirt-glib] Add gvir_domain_open_graphics_fd()
by Zeeshan Ali (Khattak)
Add binding for virDomainOpenGraphicsFD.
---
libvirt-gobject/libvirt-gobject-domain.c | 36 ++++++++++++++++++++++++++++++++
libvirt-gobject/libvirt-gobject-domain.h | 4 ++++
libvirt-gobject/libvirt-gobject.sym | 5 +++++
3 files changed, 45 insertions(+)
diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c
index 8df30d7..9c1aa6e 100644
--- a/libvirt-gobject/libvirt-gobject-domain.c
+++ b/libvirt-gobject/libvirt-gobject-domain.c
@@ -1222,6 +1222,42 @@ cleanup:
}
/**
+ * gvir_domain_open_graphics_fd:
+ * @dom: the domain
+ * @idx: the graphics index
+ * @flags: extra flags, currently unused
+ *
+ * This will create a socket pair connected to the graphics backend of @dom. One
+ * end of the socket will be returned on success, and the other end is handed to
+ * the hypervisor. If @dom has multiple graphics backends configured, then @idx
+ * will determine which one is opened, starting from @idx 0.
+ *
+ * Returns: An fd on success, -1 on failure.
+ */
+int gvir_domain_open_graphics_fd(GVirDomain *dom,
+ guint idx,
+ unsigned int flags,
+ GError **err)
+{
+ GVirDomainPrivate *priv;
+ int ret = -1;
+
+ g_return_val_if_fail(GVIR_IS_DOMAIN(dom), -1);
+ g_return_val_if_fail(err == NULL || *err == NULL, -1);
+
+ priv = dom->priv;
+
+ ret = virDomainOpenGraphicsFD(priv->handle, idx, flags);
+ if (ret <= 0) {
+ gvir_set_error_literal(err, GVIR_DOMAIN_ERROR,
+ 0,
+ "Unable to open graphics");
+ }
+
+ return ret;
+}
+
+/**
* gvir_domain_suspend:
* @dom: the domain to suspend
* @err: Place-holder for possible errors
diff --git a/libvirt-gobject/libvirt-gobject-domain.h b/libvirt-gobject/libvirt-gobject-domain.h
index 47ed784..4fe381e 100644
--- a/libvirt-gobject/libvirt-gobject-domain.h
+++ b/libvirt-gobject/libvirt-gobject-domain.h
@@ -332,6 +332,10 @@ gboolean gvir_domain_open_graphics(GVirDomain *dom,
int fd,
unsigned int flags,
GError **err);
+int gvir_domain_open_graphics_fd(GVirDomain *dom,
+ guint idx,
+ unsigned int flags,
+ GError **err);
gboolean gvir_domain_suspend (GVirDomain *dom,
GError **err);
diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym
index d18769b..927cad9 100644
--- a/libvirt-gobject/libvirt-gobject.sym
+++ b/libvirt-gobject/libvirt-gobject.sym
@@ -260,4 +260,9 @@ LIBVIRT_GOBJECT_0.1.9 {
gvir_stream_io_condition_get_type;
} LIBVIRT_GOBJECT_0.1.5;
+LIBVIRT_GOBJECT_0.2.0 {
+ global:
+ gvir_domain_open_graphics_fd;
+} LIBVIRT_GOBJECT_0.1.9;
+
# .... define new API here using predicted next version number ....
--
2.1.0
10 years, 1 month
[libvirt] [PATCH] qemu: Support OVMF on aarch64 guests
by Michal Privoznik
Currently, we are whitelisting architectures, that we know how to run
OVMF on. So far, only x86_64 was enabled. However, looking at qemu
code, the same commandline can be used to enable OVMF for aarch64.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/qemu/qemu_command.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index d2e6991..ca57e35 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -7749,7 +7749,8 @@ qemuBuildDomainLoaderCommandLine(virCommandPtr cmd,
case VIR_DOMAIN_LOADER_TYPE_PFLASH:
/* UEFI is supported only for x86_64 currently */
- if (def->os.arch != VIR_ARCH_X86_64) {
+ if (def->os.arch != VIR_ARCH_X86_64 &&
+ def->os.arch != VIR_ARCH_AARCH64) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("pflash is not supported for %s guest architecture"),
virArchToString(def->os.arch));
--
2.0.4
10 years, 1 month
[libvirt] [PATCH v2 0/7] optionally expose disk usage during dumpxml
by Eric Blake
v1 was here:
https://www.redhat.com/archives/libvir-list/2014-September/msg01077.html
This adds the framework for exposing disk of all disks from a single
dumpxml command. I'm still working on a followup patch to further
list usage of disks in the backing chain, rather than just the
top-level disk, but want to get review started on this code.
Eric Blake (7):
dumpxml: add flag to virDomainGetXMLDesc
qemu: refactor dumpxml job handling
qemu: refactor blockinfo job handling
dumpxml: let blockinfo reuse virStorageSource
qemu: refactor blockinfo data gathering
dumpxml: query disk limits as needed for qemu
dumpxml: add output of block info
docs/schemas/domaincommon.rng | 22 +++
include/libvirt/libvirt-domain.h | 1 +
src/conf/domain_conf.c | 16 +-
src/libvirt-domain-snapshot.c | 5 +-
src/libvirt-domain.c | 10 +-
src/qemu/qemu_driver.c | 397 ++++++++++++++++++++++-----------------
src/util/virstoragefile.h | 3 +-
tools/virsh-domain.c | 6 +
tools/virsh.pod | 6 +-
9 files changed, 284 insertions(+), 182 deletions(-)
--
1.9.3
10 years, 1 month
[libvirt] [PATCH] storage: wrap storage_driver.c to 80 columns
by Chen Hanxiao
Signed-off-by: Chen Hanxiao <chenhanxiao(a)cn.fujitsu.com>
---
src/storage/storage_driver.c | 35 +++++++++++++++++++++++------------
1 file changed, 23 insertions(+), 12 deletions(-)
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index fe6059a..d5485e7 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -174,8 +174,9 @@ storageStateInitialize(bool privileged,
}
driver->privileged = privileged;
- /* Configuration paths are either $USER_CONFIG_HOME/libvirt/storage/... (session) or
- * /etc/libvirt/storage/... (system).
+ /*
+ * Configuration paths are either $USER_CONFIG_HOME/libvirt/storage/...
+ * (session) or /etc/libvirt/storage/... (system).
*/
if (virAsprintf(&driver->configDir,
"%s/storage", base) == -1)
@@ -338,7 +339,8 @@ storagePoolLookupByVolume(virStorageVolPtr vol)
if (!pool) {
virReportError(VIR_ERR_NO_STORAGE_POOL,
- _("no storage pool with matching name '%s'"), vol->pool);
+ _("no storage pool with matching name '%s'"),
+ vol->pool);
return NULL;
}
@@ -732,7 +734,9 @@ storagePoolUndefine(virStoragePoolPtr obj)
if (virStoragePoolObjDeleteDef(pool) < 0)
goto cleanup;
- if (unlink(pool->autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR) {
+ if (unlink(pool->autostartLink) < 0 &&
+ errno != ENOENT &&
+ errno != ENOTDIR) {
char ebuf[1024];
VIR_ERROR(_("Failed to delete autostart link '%s': %s"),
pool->autostartLink, virStrerror(errno, ebuf, sizeof(ebuf)));
@@ -1344,13 +1348,14 @@ storageVolLookupByKey(virConnectPtr conn,
virStorageVolDefFindByKey(driver->pools.objs[i], key);
if (vol) {
- if (virStorageVolLookupByKeyEnsureACL(conn, driver->pools.objs[i]->def, vol) < 0) {
+ virStoragePoolDefPtr def = driver->pools.objs[i]->def;
+ if (virStorageVolLookupByKeyEnsureACL(conn, def, vol) < 0) {
virStoragePoolObjUnlock(driver->pools.objs[i]);
goto cleanup;
}
ret = virGetStorageVol(conn,
- driver->pools.objs[i]->def->name,
+ def->name,
vol->name,
vol->key,
NULL, NULL);
@@ -1774,7 +1779,8 @@ storageVolCreateXMLFrom(virStoragePoolPtr obj,
if ((backend = virStorageBackendForType(pool->def->type)) == NULL)
goto cleanup;
- origvol = virStorageVolDefFindByName(origpool ? origpool : pool, vobj->name);
+ origvol = virStorageVolDefFindByName(origpool ?
+ origpool : pool, vobj->name);
if (!origvol) {
virReportError(VIR_ERR_NO_STORAGE_VOL,
_("no storage vol with matching name '%s'"),
@@ -1807,7 +1813,8 @@ storageVolCreateXMLFrom(virStoragePoolPtr obj,
if (!backend->buildVolFrom) {
virReportError(VIR_ERR_NO_SUPPORT,
- "%s", _("storage pool does not support volume creation from an existing volume"));
+ "%s", _("storage pool does not support"
+ " volume creation from an existing volume"));
goto cleanup;
}
@@ -2333,7 +2340,8 @@ storageConnectListAllStoragePools(virConnectPtr conn,
storageDriverLock();
ret = virStoragePoolObjListExport(conn, driver->pools, pools,
- virConnectListAllStoragePoolsCheckACL, flags);
+ virConnectListAllStoragePoolsCheckACL,
+ flags);
storageDriverUnlock();
cleanup:
@@ -2642,7 +2650,8 @@ virStorageFileStat(virStorageSourcePtr src,
* @buf: buffer to read the data into. buffer shall be freed by caller)
*
* Returns the count of bytes read on success and -1 on failure, -2 if the
- * function isn't supported by the backend. Libvirt error is reported on failure.
+ * function isn't supported by the backend.
+ * Libvirt error is reported on failure.
*/
ssize_t
virStorageFileReadHeader(virStorageSourcePtr src,
@@ -2898,7 +2907,8 @@ virStorageFileGetMetadata(virStorageSourcePtr src,
return -1;
if (src->format <= VIR_STORAGE_FILE_NONE)
- src->format = allow_probe ? VIR_STORAGE_FILE_AUTO : VIR_STORAGE_FILE_RAW;
+ src->format = allow_probe ?
+ VIR_STORAGE_FILE_AUTO : VIR_STORAGE_FILE_RAW;
ret = virStorageFileGetMetadataRecurse(src, src, uid, gid,
allow_probe, report_broken, cycle);
@@ -3113,7 +3123,8 @@ virStorageTranslateDiskSourcePool(virConnectPtr conn,
def->src->srcpool->actualtype = VIR_STORAGE_TYPE_NETWORK;
def->src->protocol = VIR_STORAGE_NET_PROTOCOL_ISCSI;
- if (virStorageTranslateDiskSourcePoolAuth(def, &pooldef->source) < 0)
+ if (virStorageTranslateDiskSourcePoolAuth(def,
+ &pooldef->source) < 0)
goto cleanup;
if (virStorageAddISCSIPoolSourceHost(def, pooldef) < 0)
--
1.9.3
10 years, 1 month
[libvirt] [PATCH] vbox: fix a bug in _machineStateInactive
by Yohan BELLEGUIC
This function returned non-inactive domains instead of active domains.
This broke virConnectNumOfDefinedDomains() and virConnectListDefinedDomains()
functions.
---
src/vbox/vbox_tmpl.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index de8744d..37ec8e1 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -4607,8 +4607,8 @@ static bool _machineStateOnline(PRUint32 state)
static bool _machineStateInactive(PRUint32 state)
{
- return ((state > MachineState_FirstOnline) &&
- (state < MachineState_LastOnline));
+ return ((state < MachineState_FirstOnline) ||
+ (state > MachineState_LastOnline));
}
static bool _machineStateNotStart(PRUint32 state)
--
1.7.10.4
10 years, 1 month
[libvirt] [PATCH] docs: Document NVRAM behavior on transient domains
by Michal Privoznik
Since 1.2.8 it's possible to use OVMF on domains. Moreover, it's
possible to have libvirt create NVRAM file per domain. Later,
when domain is undefined, the file is removed too. However,
things are a bit complicated when domain's transient. There's no
undefine to transient domains. There are two options: 1) leave
the file behind and let mgmt app remove it. 2) remove it
automatically as domain dies.
But, in some scenarios mgmt app may want to preserve the file,
copy it somewhere safe, and then copy it back when the domain is
starting again. And this wouldn't be possible with case 2). So,
even though case 1) leaves some files behind (possibly undeleted
for a long time), the files themselves are small (128K each). And
data loss is worse than full disk, isn't it?
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
docs/formatdomain.html.in | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index d4189e6..705d497 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -147,7 +147,10 @@
started up libvirt copies so called master NVRAM store file defined
in <code>qemu.conf</code>. If needed, the <code>template</code>
attribute can be used to per domain override map of master NVRAM stores
- from the config file. <span class="since">Since 1.2.8</span></dd>
+ from the config file. Note, that for transient domains if the NVRAM file
+ has been created by libvirt it is left behind and it management
+ application's responsibility to save and remove file (if needed to be
+ persistent). <span class="since">Since 1.2.8</span></dd>
<dt><code>boot</code></dt>
<dd>The <code>dev</code> attribute takes one of the values "fd", "hd",
"cdrom" or "network" and is used to specify the next boot device
--
2.0.4
10 years, 1 month
[libvirt] [PATCH v5] network: Add network bandwidth support to ethernet interfaces
by Anirban Chakraborty
>From 7db513698bfcc30d2d0b020c3fcf9e0337c66ff4 Mon Sep 17 00:00:00 2001
From: Anirban Chakraborty <abchak(a)juniper.net>
Date: Wed, 12 Nov 2014 14:24:43 -0800
Subject: [PATCH] network: Add network bandwidth support to ethernet interfaces
Ethernet interfaces in libvirt currently do not support bandwidth setting.
For example, following xml file for an interface will not apply these
settings to corresponding qdiscs.
<interface type="ethernet">
<mac address="02:36:1d:18:2a:e4"/>
<model type="virtio"/>
<script path=""/>
<target dev="tap361d182a-e4"/>
<bandwidth>
<inbound average="984" peak="1024" burst="64"/>
<outbound average="2000" peak="2048" burst="128"/>
</bandwidth>
</interface>
Signed-off-by: Anirban Chakraborty <abchak(a)juniper.net>
---
src/conf/netdev_bandwidth_conf.c | 14 ++++++++++-
src/conf/netdev_bandwidth_conf.h | 25 +++++++++++++++++++
src/libvirt_private.syms | 1 +
src/lxc/lxc_driver.c | 8 +++++++
src/lxc/lxc_process.c | 52 +++++++++++++++++++++++-----------------
src/qemu/qemu_command.c | 16 ++++++++-----
src/qemu/qemu_hotplug.c | 12 ++++++++++
src/qemu/qemu_process.c | 4 ++++
src/util/virnetdevmacvlan.c | 10 --------
src/util/virnetdevmacvlan.h | 1 -
10 files changed, 104 insertions(+), 41 deletions(-)
diff --git a/src/conf/netdev_bandwidth_conf.c b/src/conf/netdev_bandwidth_conf.c
index 2e5b564..63a39e3 100644
--- a/src/conf/netdev_bandwidth_conf.c
+++ b/src/conf/netdev_bandwidth_conf.c
@@ -25,7 +25,6 @@
#include "netdev_bandwidth_conf.h"
#include "virerror.h"
#include "viralloc.h"
-#include "domain_conf.h"
#include "virstring.h"
#define VIR_FROM_THIS VIR_FROM_NONE
@@ -269,3 +268,16 @@ virNetDevBandwidthFormat(virNetDevBandwidthPtr def, virBufferPtr buf)
cleanup:
return ret;
}
+
+void
+virDomainClearNetBandwidth(virDomainObjPtr vm)
+{
+ size_t i;
+ virDomainNetType type;
+
+ for (i = 0; i < vm->def->nnets; i++) {
+ type = virDomainNetGetActualType(vm->def->nets[i]);
+ if (virNetDevSupportBandwidth(type))
+ virNetDevBandwidthClear(vm->def->nets[i]->ifname);
+ }
+}
diff --git a/src/conf/netdev_bandwidth_conf.h b/src/conf/netdev_bandwidth_conf.h
index 23aaaf3..60dacc6 100644
--- a/src/conf/netdev_bandwidth_conf.h
+++ b/src/conf/netdev_bandwidth_conf.h
@@ -27,6 +27,7 @@
# include "virnetdevbandwidth.h"
# include "virbuffer.h"
# include "virxml.h"
+# include "domain_conf.h"
virNetDevBandwidthPtr virNetDevBandwidthParse(xmlNodePtr node,
int net_type)
@@ -35,4 +36,28 @@ int virNetDevBandwidthFormat(virNetDevBandwidthPtr def,
virBufferPtr buf)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+void virDomainClearNetBandwidth(virDomainObjPtr vm)
+ ATTRIBUTE_NONNULL(1);
+
+static inline bool virNetDevSupportBandwidth(virDomainNetType type)
+{
+ switch (type) {
+ case VIR_DOMAIN_NET_TYPE_BRIDGE:
+ case VIR_DOMAIN_NET_TYPE_NETWORK:
+ case VIR_DOMAIN_NET_TYPE_DIRECT:
+ case VIR_DOMAIN_NET_TYPE_ETHERNET:
+ return true;
+ case VIR_DOMAIN_NET_TYPE_USER:
+ case VIR_DOMAIN_NET_TYPE_VHOSTUSER:
+ case VIR_DOMAIN_NET_TYPE_SERVER:
+ case VIR_DOMAIN_NET_TYPE_CLIENT:
+ case VIR_DOMAIN_NET_TYPE_MCAST:
+ case VIR_DOMAIN_NET_TYPE_INTERNAL:
+ case VIR_DOMAIN_NET_TYPE_HOSTDEV:
+ case VIR_DOMAIN_NET_TYPE_LAST:
+ break;
+ }
+ return false;
+}
+
#endif /* __VIR_NETDEV_BANDWIDTH_CONF_H__ */
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 0864618..1c0cfb1 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -509,6 +509,7 @@ virInterfaceRemove;
# conf/netdev_bandwidth_conf.h
virNetDevBandwidthFormat;
virNetDevBandwidthParse;
+virDomainClearNetBandwidth;
# conf/netdev_vlan_conf.h
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 6a58d50..e418f8e 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -72,6 +72,7 @@
#include "viraccessapicheck.h"
#include "viraccessapichecklxc.h"
#include "virhostdev.h"
+#include "netdev_bandwidth_conf.h"
#define VIR_FROM_THIS VIR_FROM_LXC
@@ -4212,6 +4213,11 @@ lxcDomainAttachDeviceNetLive(virConnectPtr conn,
_("Network device type is not supported"));
goto cleanup;
}
+ /* set network bandwidth */
+ if (virNetDevSupportBandwidth(actualType) &&
+ virNetDevBandwidthSet(net->ifname,
+ virDomainNetGetActualBandwidth(net), false) < 0)
+ goto cleanup;
if (virNetDevSetNamespace(veth, priv->initpid) < 0) {
virDomainAuditNet(vm, NULL, net, "attach", false);
@@ -4643,6 +4649,8 @@ lxcDomainDetachDeviceNetLive(virDomainObjPtr vm,
detach = vm->def->nets[detachidx];
+ virDomainClearNetBandwidth(vm);
+
switch (virDomainNetGetActualType(detach)) {
case VIR_DOMAIN_NET_TYPE_BRIDGE:
case VIR_DOMAIN_NET_TYPE_NETWORK:
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index 6c83fdb..77069b9 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -51,6 +51,7 @@
#include "viratomic.h"
#include "virprocess.h"
#include "virsystemd.h"
+#include "netdev_bandwidth_conf.h"
#define VIR_FROM_THIS VIR_FROM_LXC
@@ -274,11 +275,6 @@ char *virLXCProcessSetupInterfaceBridged(virConnectPtr conn,
if (virNetDevSetOnline(parentVeth, true) < 0)
goto cleanup;
- if (virNetDevBandwidthSet(net->ifname,
- virDomainNetGetActualBandwidth(net),
- false) < 0)
- goto cleanup;
-
if (net->filter &&
virDomainConfNWFilterInstantiate(conn, vm->uuid, net) < 0)
goto cleanup;
@@ -300,6 +296,7 @@ char *virLXCProcessSetupInterfaceDirect(virConnectPtr conn,
virNetDevBandwidthPtr bw;
virNetDevVPortProfilePtr prof;
virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
+ const char *linkdev = virDomainNetGetActualDirectDev(net);
/* XXX how todo bandwidth controls ?
* Since the 'net-ifname' is about to be moved to a different
@@ -329,14 +326,13 @@ char *virLXCProcessSetupInterfaceDirect(virConnectPtr conn,
if (virNetDevMacVLanCreateWithVPortProfile(
net->ifname, &net->mac,
- virDomainNetGetActualDirectDev(net),
+ linkdev,
virDomainNetGetActualDirectMode(net),
false, def->uuid,
- virDomainNetGetActualVirtPortProfile(net),
+ prof,
&res_ifname,
VIR_NETDEV_VPORT_PROFILE_OP_CREATE,
- cfg->stateDir,
- virDomainNetGetActualBandwidth(net), 0) < 0)
+ cfg->stateDir, 0) < 0)
goto cleanup;
ret = res_ifname;
@@ -368,6 +364,8 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn,
int ret = -1;
size_t i;
size_t niface = 0;
+ virDomainNetDefPtr net;
+ virDomainNetType type;
for (i = 0; i < def->nnets; i++) {
char *veth = NULL;
@@ -375,13 +373,15 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn,
* network's pool of devices, or resolve bridge device name
* to the one defined in the network definition.
*/
- if (networkAllocateActualDevice(def, def->nets[i]) < 0)
+ net = def->nets[i];
+ if (networkAllocateActualDevice(def, net) < 0)
goto cleanup;
if (VIR_EXPAND_N(*veths, *nveths, 1) < 0)
goto cleanup;
- switch (virDomainNetGetActualType(def->nets[i])) {
+ type = virDomainNetGetActualType(net);
+ switch (type) {
case VIR_DOMAIN_NET_TYPE_NETWORK: {
virNetworkPtr network;
char *brname = NULL;
@@ -389,7 +389,7 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn,
virErrorPtr errobj;
if (!(network = virNetworkLookupByName(conn,
- def->nets[i]->data.network.name)))
+ net->data.network.name)))
goto cleanup;
if (!(brname = virNetworkGetBridgeName(network)))
fail = true;
@@ -405,7 +405,7 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn,
if (!(veth = virLXCProcessSetupInterfaceBridged(conn,
def,
- def->nets[i],
+ net,
brname))) {
VIR_FREE(brname);
goto cleanup;
@@ -414,7 +414,7 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn,
break;
}
case VIR_DOMAIN_NET_TYPE_BRIDGE: {
- const char *brname = virDomainNetGetActualBridgeName(def->nets[i]);
+ const char *brname = virDomainNetGetActualBridgeName(net);
if (!brname) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("No bridge name specified"));
@@ -422,7 +422,7 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn,
}
if (!(veth = virLXCProcessSetupInterfaceBridged(conn,
def,
- def->nets[i],
+ net,
brname)))
goto cleanup;
} break;
@@ -430,31 +430,39 @@ static int virLXCProcessSetupInterfaces(virConnectPtr conn,
case VIR_DOMAIN_NET_TYPE_DIRECT:
if (!(veth = virLXCProcessSetupInterfaceDirect(conn,
def,
- def->nets[i])))
+ net)))
goto cleanup;
break;
- case VIR_DOMAIN_NET_TYPE_USER:
case VIR_DOMAIN_NET_TYPE_ETHERNET:
+ break;
+
+ case VIR_DOMAIN_NET_TYPE_USER:
case VIR_DOMAIN_NET_TYPE_VHOSTUSER:
case VIR_DOMAIN_NET_TYPE_SERVER:
case VIR_DOMAIN_NET_TYPE_CLIENT:
case VIR_DOMAIN_NET_TYPE_MCAST:
case VIR_DOMAIN_NET_TYPE_INTERNAL:
case VIR_DOMAIN_NET_TYPE_LAST:
+ case VIR_DOMAIN_NET_TYPE_HOSTDEV:
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unsupported network type %s"),
- virDomainNetTypeToString(
- virDomainNetGetActualType(def->nets[i])
- ));
+ virDomainNetTypeToString(type));
goto cleanup;
+
}
+ /* set network bandwidth */
+ if (virNetDevSupportBandwidth(type) &&
+ virNetDevBandwidthSet(net->ifname,
+ virDomainNetGetActualBandwidth(net), false) < 0)
+ goto cleanup;
+
(*veths)[(*nveths)-1] = veth;
/* Make sure all net definitions will have a name in the container */
- if (!def->nets[i]->ifname_guest) {
- if (virAsprintf(&def->nets[i]->ifname_guest, "eth%zu", niface) < 0)
+ if (!net->ifname_guest) {
+ if (virAsprintf(&net->ifname_guest, "eth%zu", niface) < 0)
return -1;
niface++;
}
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index f674ba9..146f2e2 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -43,6 +43,7 @@
#include "domain_addr.h"
#include "domain_audit.h"
#include "domain_conf.h"
+#include "netdev_bandwidth_conf.h"
#include "snapshot_conf.h"
#include "storage_conf.h"
#include "secret_conf.h"
@@ -192,7 +193,6 @@ qemuPhysIfaceConnect(virDomainDefPtr def,
virDomainNetGetActualVirtPortProfile(net),
&res_ifname,
vmop, cfg->stateDir,
- virDomainNetGetActualBandwidth(net),
macvlan_create_flags);
if (rc >= 0) {
virDomainAuditNetDevice(def, net, res_ifname, true);
@@ -372,11 +372,6 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
&net->mac) < 0)
goto cleanup;
- if (virNetDevBandwidthSet(net->ifname,
- virDomainNetGetActualBandwidth(net),
- false) < 0)
- goto cleanup;
-
if (net->filter &&
virDomainConfNWFilterInstantiate(conn, def->uuid, net) < 0) {
goto cleanup;
@@ -7499,6 +7494,15 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
goto cleanup;
}
+ /* Set Bandwidth */
+ if (net->ifname && strlen(net->ifname)) {
+ if (virNetDevSupportBandwidth(actualType) &&
+ virNetDevBandwidthSet(net->ifname,
+ virDomainNetGetActualBandwidth(net),
+ false) < 0)
+ goto cleanup;
+ }
+
if ((actualType == VIR_DOMAIN_NET_TYPE_NETWORK ||
actualType == VIR_DOMAIN_NET_TYPE_BRIDGE ||
actualType == VIR_DOMAIN_NET_TYPE_ETHERNET ||
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 13bcd88..d17d860 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -31,6 +31,7 @@
#include "qemu_command.h"
#include "qemu_hostdev.h"
#include "domain_audit.h"
+#include "netdev_bandwidth_conf.h"
#include "domain_nwfilter.h"
#include "virlog.h"
#include "datatypes.h"
@@ -948,6 +949,12 @@ int qemuDomainAttachNetDevice(virConnectPtr conn,
goto cleanup;
}
+ /* Set Bandwidth */
+ if (virNetDevSupportBandwidth(actualType) &&
+ virNetDevBandwidthSet(net->ifname,
+ virDomainNetGetActualBandwidth(net), false) < 0)
+ goto cleanup;
+
for (i = 0; i < tapfdSize; i++) {
if (virSecurityManagerSetTapFDLabel(driver->securityManager,
vm->def, tapfd[i]) < 0)
@@ -3547,6 +3554,11 @@ qemuDomainDetachNetDevice(virQEMUDriverPtr driver,
goto cleanup;
}
+ if (virNetDevSupportBandwidth(virDomainNetGetActualType(detach)) &&
+ virNetDevBandwidthClear(detach->ifname) < 0)
+ VIR_WARN("cannot clear bandwidth setting for device : %s",
+ detach->ifname);
+
qemuDomainMarkDeviceForRemoval(vm, &detach->info);
qemuDomainObjEnterMonitor(driver, vm);
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 24e5f0f..9c1a417 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -68,6 +68,7 @@
#include "virhostdev.h"
#include "storage/storage_driver.h"
#include "configmake.h"
+#include "netdev_bandwidth_conf.h"
#define VIR_FROM_THIS VIR_FROM_QEMU
@@ -4842,6 +4843,9 @@ void qemuProcessStop(virQEMUDriverPtr driver,
virStrerror(errno, ebuf, sizeof(ebuf)));
}
+ /* Clear network bandwidth */
+ virDomainClearNetBandwidth(vm);
+
virDomainConfVMNWFilterTeardown(vm);
if (cfg->macFilter) {
diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c
index c83341c..956a96b 100644
--- a/src/util/virnetdevmacvlan.c
+++ b/src/util/virnetdevmacvlan.c
@@ -811,7 +811,6 @@ int virNetDevMacVLanCreateWithVPortProfile(const char *tgifname,
char **res_ifname,
virNetDevVPortProfileOp vmOp,
char *stateDir,
- virNetDevBandwidthPtr bandwidth,
unsigned int flags)
{
const char *type = (flags & VIR_NETDEV_MACVLAN_CREATE_WITH_TAP) ?
@@ -925,14 +924,6 @@ int virNetDevMacVLanCreateWithVPortProfile(const char *tgifname,
rc = 0;
}
- if (virNetDevBandwidthSet(cr_ifname, bandwidth, false) < 0) {
- if (flags & VIR_NETDEV_MACVLAN_CREATE_WITH_TAP)
- VIR_FORCE_CLOSE(rc); /* sets rc to -1 */
- else
- rc = -1;
- goto disassociate_exit;
- }
-
if (vmOp == VIR_NETDEV_VPORT_PROFILE_OP_CREATE ||
vmOp == VIR_NETDEV_VPORT_PROFILE_OP_RESTORE) {
/* Only directly register upon a create or restore (restarting
@@ -1076,7 +1067,6 @@ int virNetDevMacVLanCreateWithVPortProfile(const char *ifname ATTRIBUTE_UNUSED,
char **res_ifname ATTRIBUTE_UNUSED,
virNetDevVPortProfileOp vmop ATTRIBUTE_UNUSED,
char *stateDir ATTRIBUTE_UNUSED,
- virNetDevBandwidthPtr bandwidth ATTRIBUTE_UNUSED,
unsigned int flags)
{
virCheckFlags(0, -1);
diff --git a/src/util/virnetdevmacvlan.h b/src/util/virnetdevmacvlan.h
index 41aa4e2..f08d32b 100644
--- a/src/util/virnetdevmacvlan.h
+++ b/src/util/virnetdevmacvlan.h
@@ -68,7 +68,6 @@ int virNetDevMacVLanCreateWithVPortProfile(const char *ifname,
char **res_ifname,
virNetDevVPortProfileOp vmop,
char *stateDir,
- virNetDevBandwidthPtr bandwidth,
unsigned int flags)
ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(6)
ATTRIBUTE_NONNULL(8) ATTRIBUTE_NONNULL(10) ATTRIBUTE_RETURN_CHECK;
--
1.8.2.3
10 years, 1 month