[libvirt] [PATCH 00/10] Implement shared memory device - Part 1
by Luyao Huang
This part contains some small fix and Implement the hot-plug/hot-unplug
and cold-plug/cold-unplug for Inter-VM Shared Memory PCI device.
Luyao Huang (10):
qemu: auto assign pci address for shared memory device
qemu: always build id when generate shared memory device CLI
qemu: Refactor creation of shared memory device commandline
conf: use virDomainChrSourceDef to save the path
conf:audit: introduce audit function for shared memory device
conf: Add helpers to insert/remove/find shmem devices in domain def
qemu: Implement shared memory device cold (un)plug
qemu: Implement share memory device hot-plug
qemu: Implement shared memory device hot-unplug
qemu: report error when shmem have a invalid address
docs/auditlog.html.in | 16 +++
src/conf/domain_audit.c | 16 +++
src/conf/domain_audit.h | 6 +
src/conf/domain_conf.c | 69 ++++++++++-
src/conf/domain_conf.h | 9 +-
src/libvirt_private.syms | 5 +
src/qemu/qemu_command.c | 82 +++++++------
src/qemu/qemu_command.h | 7 ++
src/qemu/qemu_driver.c | 35 +++++-
src/qemu/qemu_hotplug.c | 156 ++++++++++++++++++++++++-
src/qemu/qemu_hotplug.h | 6 +
tests/qemuxml2argvdata/qemuxml2argv-shmem.args | 16 +--
12 files changed, 372 insertions(+), 51 deletions(-)
--
1.8.3.1
9 years, 4 months
[libvirt] [PATCH] qemu: fix no error settings if fail to find a disk match path
by Luyao Huang
When we use get blockjob info to a unexist disk path, we will
get a error like this:
# virsh blockjob r7 vdc
error: An error occurred, but the cause is unknown
This is because we do not set the error when jump to endjob.
As virDomainDiskByName won't set the error, we need set them
in the callers function.
Signed-off-by: Luyao Huang <lhuang(a)redhat.com>
---
src/qemu/qemu_driver.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 900740e..f134248 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -16414,8 +16414,11 @@ qemuDomainGetBlockJobInfo(virDomainPtr dom,
if (qemuDomainSupportsBlockJobs(vm, NULL) < 0)
goto endjob;
- if (!(disk = virDomainDiskByName(vm->def, path, true)))
+ if (!(disk = virDomainDiskByName(vm->def, path, true))) {
+ virReportError(VIR_ERR_INVALID_ARG,
+ _("invalid path %s not assigned to domain"), path);
goto endjob;
+ }
qemuDomainObjEnterMonitor(driver, vm);
ret = qemuMonitorGetBlockJobInfo(qemuDomainGetMonitor(vm),
--
1.8.3.1
9 years, 4 months
[libvirt] [PATCH] libxl: rework setting the state of virDomainObj
by Jim Fehlig
Set the state of virDomainObj in the functions that
actually change the domain state, instead of the generic
libxlDomainCleanup function. This approach gives functions
calling libxlDomainCleanup more flexibility wrt when and
how they change virDomainObj state via virDomainObjSetState.
The prior approach of calling virDomainObjSetState in
libxlDomainCleanup resulted in the following incorrect
coding pattern in the various functions that change
domain state
libxlDomain<DoStateTransition>
call libxl function to do state transition
emit lifecycle event
libxlDomainCleanup
virDomainObjSetState
Once simple manifestation of this bug is seeing a domain
running in virt-manager after selecting the shutdown button,
even after the domain has long shutdown.
Signed-off-by: Jim Fehlig <jfehlig(a)suse.com>
---
I considered emitting the lifecycle event in libxlDomainCleanup,
but IMO it is best to change the state and emit the event where
where the state change actually occurs.
src/libxl/libxl_domain.c | 23 ++++++++++++-----------
src/libxl/libxl_domain.h | 3 +--
src/libxl/libxl_driver.c | 28 ++++++++++++++++++----------
src/libxl/libxl_migration.c | 8 ++++++--
4 files changed, 37 insertions(+), 25 deletions(-)
diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index 8e8a292..224ff77 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -397,7 +397,6 @@ libxlDomainShutdownThread(void *opaque)
libxlDriverPrivatePtr driver = shutdown_info->driver;
virObjectEventPtr dom_event = NULL;
libxl_shutdown_reason xl_reason = ev->u.domain_shutdown.shutdown_reason;
- virDomainShutoffReason reason = VIR_DOMAIN_SHUTOFF_SHUTDOWN;
libxlDriverConfigPtr cfg;
cfg = libxlDriverConfigGet(driver);
@@ -406,12 +405,14 @@ libxlDomainShutdownThread(void *opaque)
goto cleanup;
if (xl_reason == LIBXL_SHUTDOWN_REASON_POWEROFF) {
+ virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF,
+ VIR_DOMAIN_SHUTOFF_SHUTDOWN);
+
dom_event = virDomainEventLifecycleNewFromObj(vm,
VIR_DOMAIN_EVENT_STOPPED,
VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN);
switch ((virDomainLifecycleAction) vm->def->onPoweroff) {
case VIR_DOMAIN_LIFECYCLE_DESTROY:
- reason = VIR_DOMAIN_SHUTOFF_SHUTDOWN;
goto destroy;
case VIR_DOMAIN_LIFECYCLE_RESTART:
case VIR_DOMAIN_LIFECYCLE_RESTART_RENAME:
@@ -421,12 +422,14 @@ libxlDomainShutdownThread(void *opaque)
goto endjob;
}
} else if (xl_reason == LIBXL_SHUTDOWN_REASON_CRASH) {
+ virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF,
+ VIR_DOMAIN_SHUTOFF_CRASHED);
+
dom_event = virDomainEventLifecycleNewFromObj(vm,
VIR_DOMAIN_EVENT_STOPPED,
VIR_DOMAIN_EVENT_STOPPED_CRASHED);
switch ((virDomainLifecycleCrashAction) vm->def->onCrash) {
case VIR_DOMAIN_LIFECYCLE_CRASH_DESTROY:
- reason = VIR_DOMAIN_SHUTOFF_CRASHED;
goto destroy;
case VIR_DOMAIN_LIFECYCLE_CRASH_RESTART:
case VIR_DOMAIN_LIFECYCLE_CRASH_RESTART_RENAME:
@@ -442,12 +445,14 @@ libxlDomainShutdownThread(void *opaque)
goto restart;
}
} else if (xl_reason == LIBXL_SHUTDOWN_REASON_REBOOT) {
+ virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF,
+ VIR_DOMAIN_SHUTOFF_SHUTDOWN);
+
dom_event = virDomainEventLifecycleNewFromObj(vm,
VIR_DOMAIN_EVENT_STOPPED,
VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN);
switch ((virDomainLifecycleAction) vm->def->onReboot) {
case VIR_DOMAIN_LIFECYCLE_DESTROY:
- reason = VIR_DOMAIN_SHUTOFF_SHUTDOWN;
goto destroy;
case VIR_DOMAIN_LIFECYCLE_RESTART:
case VIR_DOMAIN_LIFECYCLE_RESTART_RENAME:
@@ -467,7 +472,7 @@ libxlDomainShutdownThread(void *opaque)
dom_event = NULL;
}
libxlDomainDestroyInternal(driver, vm);
- libxlDomainCleanup(driver, vm, reason);
+ libxlDomainCleanup(driver, vm);
if (!vm->persistent)
virDomainObjListRemove(driver->domains, vm);
@@ -479,7 +484,7 @@ libxlDomainShutdownThread(void *opaque)
dom_event = NULL;
}
libxlDomainDestroyInternal(driver, vm);
- libxlDomainCleanup(driver, vm, VIR_DOMAIN_SHUTOFF_SHUTDOWN);
+ libxlDomainCleanup(driver, vm);
if (libxlDomainStart(driver, vm, false, -1) < 0) {
virErrorPtr err = virGetLastError();
VIR_ERROR(_("Failed to restart VM '%s': %s"),
@@ -685,8 +690,7 @@ libxlDomainDestroyInternal(libxlDriverPrivatePtr driver,
*/
void
libxlDomainCleanup(libxlDriverPrivatePtr driver,
- virDomainObjPtr vm,
- virDomainShutoffReason reason)
+ virDomainObjPtr vm)
{
libxlDomainObjPrivatePtr priv = vm->privateData;
libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
@@ -709,9 +713,6 @@ libxlDomainCleanup(libxlDriverPrivatePtr driver,
priv->deathW = NULL;
}
- if (vm->persistent)
- virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF, reason);
-
if (virAtomicIntDecAndTest(&driver->nactive) && driver->inhibitCallback)
driver->inhibitCallback(false, driver->inhibitOpaque);
diff --git a/src/libxl/libxl_domain.h b/src/libxl/libxl_domain.h
index 8c73cc4..44b3e0b 100644
--- a/src/libxl/libxl_domain.h
+++ b/src/libxl/libxl_domain.h
@@ -110,8 +110,7 @@ libxlDomainDestroyInternal(libxlDriverPrivatePtr driver,
void
libxlDomainCleanup(libxlDriverPrivatePtr driver,
- virDomainObjPtr vm,
- virDomainShutoffReason reason);
+ virDomainObjPtr vm);
/*
* Note: Xen 4.3 removed the const from the event handler signature.
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 149ef70..50861ac 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -383,7 +383,7 @@ libxlReconnectDomain(virDomainObjPtr vm,
return 0;
out:
- libxlDomainCleanup(driver, vm, VIR_DOMAIN_SHUTOFF_UNKNOWN);
+ libxlDomainCleanup(driver, vm);
if (!vm->persistent)
virDomainObjListRemoveLocked(driver->domains, vm);
else
@@ -1266,16 +1266,19 @@ libxlDomainDestroyFlags(virDomainPtr dom,
goto endjob;
}
+ if (libxlDomainDestroyInternal(driver, vm) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Failed to destroy domain '%d'"), vm->def->id);
+ goto endjob;
+ }
+
+ virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF,
+ VIR_DOMAIN_SHUTOFF_DESTROYED);
+
event = virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_STOPPED,
VIR_DOMAIN_EVENT_STOPPED_DESTROYED);
- if (libxlDomainDestroyInternal(driver, vm) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Failed to destroy domain '%d'"), vm->def->id);
- goto endjob;
- }
-
- libxlDomainCleanup(driver, vm, VIR_DOMAIN_SHUTOFF_DESTROYED);
+ libxlDomainCleanup(driver, vm);
if (!vm->persistent)
virDomainObjListRemove(driver->domains, vm);
@@ -1609,6 +1612,9 @@ libxlDoDomainSave(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
goto cleanup;
}
+ virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF,
+ VIR_DOMAIN_SHUTOFF_SAVED);
+
event = virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_STOPPED,
VIR_DOMAIN_EVENT_STOPPED_SAVED);
@@ -1618,7 +1624,7 @@ libxlDoDomainSave(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
goto cleanup;
}
- libxlDomainCleanup(driver, vm, VIR_DOMAIN_SHUTOFF_SAVED);
+ libxlDomainCleanup(driver, vm);
vm->hasManagedSave = true;
ret = 0;
@@ -1825,7 +1831,9 @@ libxlDomainCoreDump(virDomainPtr dom, const char *to, unsigned int flags)
goto unpause;
}
- libxlDomainCleanup(driver, vm, VIR_DOMAIN_SHUTOFF_CRASHED);
+ libxlDomainCleanup(driver, vm);
+ virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF,
+ VIR_DOMAIN_SHUTOFF_CRASHED);
event = virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_STOPPED,
VIR_DOMAIN_EVENT_STOPPED_CRASHED);
if (!vm->persistent)
diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c
index 39e4a65..aa9547b 100644
--- a/src/libxl/libxl_migration.c
+++ b/src/libxl/libxl_migration.c
@@ -585,7 +585,9 @@ libxlDomainMigrationFinish(virConnectPtr dconn,
cleanup:
if (dom == NULL) {
libxlDomainDestroyInternal(driver, vm);
- libxlDomainCleanup(driver, vm, VIR_DOMAIN_SHUTOFF_FAILED);
+ libxlDomainCleanup(driver, vm);
+ virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF,
+ VIR_DOMAIN_SHUTOFF_FAILED);
event = virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_STOPPED,
VIR_DOMAIN_EVENT_STOPPED_FAILED);
if (!vm->persistent)
@@ -624,7 +626,9 @@ libxlDomainMigrationConfirm(libxlDriverPrivatePtr driver,
}
libxlDomainDestroyInternal(driver, vm);
- libxlDomainCleanup(driver, vm, VIR_DOMAIN_SHUTOFF_MIGRATED);
+ libxlDomainCleanup(driver, vm);
+ virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF,
+ VIR_DOMAIN_SHUTOFF_MIGRATED);
event = virDomainEventLifecycleNewFromObj(vm, VIR_DOMAIN_EVENT_STOPPED,
VIR_DOMAIN_EVENT_STOPPED_MIGRATED);
--
2.1.4
9 years, 4 months
[libvirt] [PATCH] libxl: support dom0
by Jim Fehlig
In Xen, dom0 is really just another domain that supports ballooning,
adding/removing devices, changing vcpu configuration, etc. This patch
adds support to the libxl driver for managing dom0. Note that the
legacy xend driver has long supported managing dom0.
Operations that are not supported on dom0 are filtered in libvirt
where a sensible error is reported. Errors from libxl are not
always helpful. E.g., attempting a save on dom0 results in
2015-06-23 15:25:05 MDT libxl: debug: libxl_dom.c:1570:libxl__toolstack_save: domain=0 toolstack data size=8
2015-06-23 15:25:05 MDT libxl: debug: libxl.c:979:do_libxl_domain_suspend: ao 0x7f7e68000b70: inprogress: poller=0x7f7e68000930, flags=i
2015-06-23 15:25:05 MDT libxl-save-helper: debug: starting save: Success
2015-06-23 15:25:05 MDT xc: detail: xc_domain_save_suse: starting save of domid 0
2015-06-23 15:25:05 MDT xc: error: Couldn't map live_shinfo (3 = No such process): Internal error
2015-06-23 15:25:05 MDT xc: detail: Save exit of domid 0 with errno=3
2015-06-23 15:25:05 MDT libxl-save-helper: debug: complete r=1: No such process
2015-06-23 15:25:05 MDT libxl: error: libxl_dom.c:1876:libxl__xc_domain_save_done: saving domain: domain did not respond to suspend request: No such process
2015-06-23 15:25:05 MDT libxl: error: libxl_dom.c:2033:remus_teardown_done: Remus: failed to teardown device for guest with domid 0, rc -8
Signed-off-by: Jim Fehlig <jfehlig(a)suse.com>
---
src/libxl/libxl_driver.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 95 insertions(+)
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 149ef70..d0b76ac 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -79,6 +79,15 @@ VIR_LOG_INIT("libxl.libxl_driver");
/* Number of Xen scheduler parameters */
#define XEN_SCHED_CREDIT_NPARAM 2
+#define LIBXL_CHECK_DOM0_GOTO(name, label) \
+ do { \
+ if (STREQ_NULLABLE(name, "Domain-0")) { \
+ virReportError(VIR_ERR_OPERATION_INVALID, "%s", \
+ _("Domain-0 does not support requested operation")); \
+ goto label; \
+ } \
+ } while (0)
+
static libxlDriverPrivatePtr libxl_driver;
@@ -501,6 +510,62 @@ const struct libxl_event_hooks ev_hooks = {
};
static int
+libxlAddDom0(libxlDriverPrivatePtr driver)
+{
+ libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+ virDomainDefPtr def = NULL;
+ virDomainObjPtr vm = NULL;
+ virDomainDefPtr oldDef = NULL;
+ libxl_dominfo d_info;
+ int ret = -1;
+
+ libxl_dominfo_init(&d_info);
+
+ /* Ensure we have a dom0 */
+ if (libxl_domain_info(cfg->ctx, &d_info, 0) != 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ "%s", _("unable to get Domain-0 information from libxenlight"));
+ goto cleanup;
+ }
+
+ if (!(def = virDomainDefNew()))
+ goto cleanup;
+
+ def->id = 0;
+ def->virtType = VIR_DOMAIN_VIRT_XEN;
+ if (VIR_STRDUP(def->name, "Domain-0") < 0)
+ goto cleanup;
+
+ def->os.type = VIR_DOMAIN_OSTYPE_XEN;
+
+ if (virUUIDParse("00000000-0000-0000-0000-000000000000", def->uuid) < 0)
+ goto cleanup;
+
+ vm->def->vcpus = d_info.vcpu_online;
+ vm->def->maxvcpus = d_info.vcpu_max_id + 1;
+ vm->def->mem.cur_balloon = d_info.current_memkb;
+ vm->def->mem.max_balloon = d_info.max_memkb;
+
+ if (!(vm = virDomainObjListAdd(driver->domains, def,
+ driver->xmlopt,
+ 0,
+ &oldDef)))
+ goto cleanup;
+
+ def = NULL;
+ ret = 0;
+
+ cleanup:
+ libxl_dominfo_dispose(&d_info);
+ virDomainDefFree(def);
+ virDomainDefFree(oldDef);
+ if (vm)
+ virObjectUnlock(vm);
+ virObjectUnref(cfg);
+ return ret;
+}
+
+static int
libxlStateInitialize(bool privileged,
virStateInhibitCallback callback ATTRIBUTE_UNUSED,
void *opaque ATTRIBUTE_UNUSED)
@@ -616,6 +681,10 @@ libxlStateInitialize(bool privileged,
if (!(libxl_driver->xmlopt = libxlCreateXMLConf()))
goto error;
+ /* Add Domain-0 */
+ if (libxlAddDom0(libxl_driver) < 0)
+ goto error;
+
/* Load running domains first. */
if (virDomainObjListLoadAllConfigs(libxl_driver->domains,
cfg->stateDir,
@@ -1030,6 +1099,8 @@ libxlDomainSuspend(virDomainPtr dom)
if (!(vm = libxlDomObjFromDomain(dom)))
goto cleanup;
+ LIBXL_CHECK_DOM0_GOTO(vm->def->name, cleanup);
+
if (virDomainSuspendEnsureACL(dom->conn, vm->def) < 0)
goto cleanup;
@@ -1086,6 +1157,8 @@ libxlDomainResume(virDomainPtr dom)
if (!(vm = libxlDomObjFromDomain(dom)))
goto cleanup;
+ LIBXL_CHECK_DOM0_GOTO(vm->def->name, cleanup);
+
if (virDomainResumeEnsureACL(dom->conn, vm->def) < 0)
goto cleanup;
@@ -1147,6 +1220,8 @@ libxlDomainShutdownFlags(virDomainPtr dom, unsigned int flags)
if (!(vm = libxlDomObjFromDomain(dom)))
goto cleanup;
+ LIBXL_CHECK_DOM0_GOTO(vm->def->name, cleanup);
+
if (virDomainShutdownFlagsEnsureACL(dom->conn, vm->def, flags) < 0)
goto cleanup;
@@ -1212,6 +1287,8 @@ libxlDomainReboot(virDomainPtr dom, unsigned int flags)
if (!(vm = libxlDomObjFromDomain(dom)))
goto cleanup;
+ LIBXL_CHECK_DOM0_GOTO(vm->def->name, cleanup);
+
if (virDomainRebootEnsureACL(dom->conn, vm->def, flags) < 0)
goto cleanup;
@@ -1254,6 +1331,8 @@ libxlDomainDestroyFlags(virDomainPtr dom,
if (!(vm = libxlDomObjFromDomain(dom)))
goto cleanup;
+ LIBXL_CHECK_DOM0_GOTO(vm->def->name, cleanup);
+
if (virDomainDestroyFlagsEnsureACL(dom->conn, vm->def) < 0)
goto cleanup;
@@ -1656,6 +1735,8 @@ libxlDomainSaveFlags(virDomainPtr dom, const char *to, const char *dxml,
if (!(vm = libxlDomObjFromDomain(dom)))
goto cleanup;
+ LIBXL_CHECK_DOM0_GOTO(vm->def->name, cleanup);
+
if (virDomainSaveFlagsEnsureACL(dom->conn, vm->def) < 0)
goto cleanup;
@@ -1782,6 +1863,8 @@ libxlDomainCoreDump(virDomainPtr dom, const char *to, unsigned int flags)
if (!(vm = libxlDomObjFromDomain(dom)))
goto cleanup;
+ LIBXL_CHECK_DOM0_GOTO(vm->def->name, cleanup);
+
if (virDomainCoreDumpEnsureACL(dom->conn, vm->def) < 0)
goto cleanup;
@@ -1877,6 +1960,8 @@ libxlDomainManagedSave(virDomainPtr dom, unsigned int flags)
if (!(vm = libxlDomObjFromDomain(dom)))
goto cleanup;
+ LIBXL_CHECK_DOM0_GOTO(vm->def->name, cleanup);
+
if (virDomainManagedSaveEnsureACL(dom->conn, vm->def) < 0)
goto cleanup;
@@ -4000,6 +4085,8 @@ libxlDomainSetAutostart(virDomainPtr dom, int autostart)
if (!(vm = libxlDomObjFromDomain(dom)))
goto cleanup;
+ LIBXL_CHECK_DOM0_GOTO(vm->def->name, cleanup);
+
if (virDomainSetAutostartEnsureACL(dom->conn, vm->def) < 0)
goto cleanup;
@@ -4294,6 +4381,8 @@ libxlDomainOpenConsole(virDomainPtr dom,
if (!(vm = libxlDomObjFromDomain(dom)))
goto cleanup;
+ LIBXL_CHECK_DOM0_GOTO(vm->def->name, cleanup);
+
if (virDomainOpenConsoleEnsureACL(dom->conn, vm->def) < 0)
goto cleanup;
@@ -4817,6 +4906,12 @@ libxlDomainMigrateBegin3Params(virDomainPtr domain,
if (!(vm = libxlDomObjFromDomain(domain)))
return NULL;
+ if (STREQ_NULLABLE(vm->def->name, "Domain-0")) {
+ virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+ _("Domain-0 cannot be migrated"));
+ return NULL;
+ }
+
if (virDomainMigrateBegin3ParamsEnsureACL(domain->conn, vm->def) < 0) {
virObjectUnlock(vm);
return NULL;
--
2.1.4
9 years, 4 months
[libvirt] [PATCH v2 0/4] virt-aa-helper fixes
by Cédric Bosdonnat
This patch series includes a new version for the trailing slash fix, but also
includes other fixes to get virt-sandbox run nicely with apparmor. Thus only
one patch has v2 ;)
Cédric Bosdonnat (4):
virt-aa-helper: fix rules for paths with trailing slash
Get more libvirt errors from virt-aa-helper
virt-aa-helper: rename ctl->hvm to ctl->os
virt-aa-helper: add DomainGuest to mockup caps
src/security/security_apparmor.c | 4 ++++
src/security/virt-aa-helper.c | 38 ++++++++++++++++++++++++++++++++++----
tests/virt-aa-helper-test | 3 ---
3 files changed, 38 insertions(+), 7 deletions(-)
--
2.1.4
9 years, 4 months
[libvirt] [[PATCH v5] autocreate tap device for VIR_DOMAIN_NET_TYPE_ETHERNET] autocreate tap device for VIR_DOMAIN_NET_TYPE_ETHERNET
by Vasiliy Tolstov
If a user specify ehernet device create it via libvirt and run
script if it provided. After this commit user does not need to
run external script to create tap device or add root to qemu
process.
Signed-off-by: Vasiliy Tolstov <v.tolstov(a)selfip.ru>
---
src/qemu/qemu_command.c | 139 ++++++++++++++++++++++++++++++------------------
src/qemu/qemu_hotplug.c | 13 ++---
src/qemu/qemu_process.c | 6 +++
3 files changed, 98 insertions(+), 60 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 3886b4f..f9008e4 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -332,10 +332,39 @@ static int qemuCreateInBridgePortWithHelper(virQEMUDriverConfigPtr cfg,
return *tapfd < 0 ? -1 : 0;
}
+/**
+ * qemuExecuteEthernetScript:
+ * @ifname: the interface name
+ * @script: the script name
+ *
+ * This function executes script for new tap device created by libvirt.
+ * Returns 0 in case of success or -1 on failure
+ */
+static int
+qemuExecuteEthernetScript(const char *ifname, const char *script)
+{
+ virCommandPtr cmd;
+ int ret;
+
+ cmd = virCommandNew(script);
+ virCommandAddArgFormat(cmd, "%s", ifname);
+ virCommandClearCaps(cmd);
+#ifdef CAP_NET_ADMIN
+ virCommandAllowCap(cmd, CAP_NET_ADMIN);
+#endif
+ virCommandAddEnvPassCommon(cmd);
+
+ ret = virCommandRun(cmd, NULL);
+
+ virCommandFree(cmd);
+ return ret;
+}
+
/* qemuNetworkIfaceConnect - *only* called if actualType is
- * VIR_DOMAIN_NET_TYPE_NETWORK or VIR_DOMAIN_NET_TYPE_BRIDGE (i.e. if
- * the connection is made with a tap device connecting to a bridge
- * device)
+ * VIR_DOMAIN_NET_TYPE_NETWORK, VIR_DOMAIN_NET_TYPE_BRIDGE
+ * VIR_DOMAIN_NET_TYPE_ETHERNET (i.e. if the connection is
+ * made with a tap device connecting to a bridge device or
+ * use plain tap device)
*/
int
qemuNetworkIfaceConnect(virDomainDefPtr def,
@@ -351,6 +380,7 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
bool template_ifname = false;
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
const char *tunpath = "/dev/net/tun";
+ virMacAddr tapmac;
if (net->backend.tap) {
tunpath = net->backend.tap;
@@ -361,11 +391,6 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
}
}
- if (!(brname = virDomainNetGetActualBridgeName(net))) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing bridge name"));
- goto cleanup;
- }
-
if (!net->ifname ||
STRPREFIX(net->ifname, VIR_NET_GENERATED_PREFIX) ||
strchr(net->ifname, '%')) {
@@ -381,40 +406,62 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
tap_create_flags |= VIR_NETDEV_TAP_CREATE_VNET_HDR;
}
- if (cfg->privileged) {
- if (virNetDevTapCreateInBridgePort(brname, &net->ifname, &net->mac,
- def->uuid, tunpath, tapfd, *tapfdSize,
- virDomainNetGetActualVirtPortProfile(net),
- virDomainNetGetActualVlan(net),
- tap_create_flags) < 0) {
+ if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_ETHERNET) {
+ if (virNetDevTapCreate(&net->ifname, tunpath, tapfd, *tapfdSize,
+ tap_create_flags) < 0) {
virDomainAuditNetDevice(def, net, tunpath, false);
goto cleanup;
}
- if (virDomainNetGetActualBridgeMACTableManager(net)
- == VIR_NETWORK_BRIDGE_MAC_TABLE_MANAGER_LIBVIRT) {
- /* libvirt is managing the FDB of the bridge this device
- * is attaching to, so we need to turn off learning and
- * unicast_flood on the device to prevent the kernel from
- * adding any FDB entries for it. We will add add an fdb
- * entry ourselves (during qemuInterfaceStartDevices(),
- * using the MAC address from the interface config.
- */
- if (virNetDevBridgePortSetLearning(brname, net->ifname, false) < 0)
- goto cleanup;
- if (virNetDevBridgePortSetUnicastFlood(brname, net->ifname, false) < 0)
+ virMacAddrSet(&tapmac, &net->mac);
+
+ if (virNetDevSetMAC(net->ifname, &tapmac) < 0)
+ goto cleanup;
+
+ if (net->script) {
+ if (qemuExecuteEthernetScript(net->ifname, net->script) < 0)
goto cleanup;
}
} else {
- if (qemuCreateInBridgePortWithHelper(cfg, brname,
- &net->ifname,
- tapfd, tap_create_flags) < 0) {
- virDomainAuditNetDevice(def, net, tunpath, false);
+ if (!(brname = virDomainNetGetActualBridgeName(net))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing bridge name"));
goto cleanup;
}
- /* qemuCreateInBridgePortWithHelper can only create a single FD */
- if (*tapfdSize > 1) {
- VIR_WARN("Ignoring multiqueue network request");
- *tapfdSize = 1;
+
+ if (cfg->privileged) {
+ if (virNetDevTapCreateInBridgePort(brname, &net->ifname, &net->mac,
+ def->uuid, tunpath, tapfd, *tapfdSize,
+ virDomainNetGetActualVirtPortProfile(net),
+ virDomainNetGetActualVlan(net),
+ tap_create_flags) < 0) {
+ virDomainAuditNetDevice(def, net, tunpath, false);
+ goto cleanup;
+ }
+ if (virDomainNetGetActualBridgeMACTableManager(net)
+ == VIR_NETWORK_BRIDGE_MAC_TABLE_MANAGER_LIBVIRT) {
+ /* libvirt is managing the FDB of the bridge this device
+ * is attaching to, so we need to turn off learning and
+ * unicast_flood on the device to prevent the kernel from
+ * adding any FDB entries for it. We will add add an fdb
+ * entry ourselves (during qemuInterfaceStartDevices(),
+ * using the MAC address from the interface config.
+ */
+ if (virNetDevBridgePortSetLearning(brname, net->ifname, false) < 0)
+ goto cleanup;
+ if (virNetDevBridgePortSetUnicastFlood(brname, net->ifname, false) < 0)
+ goto cleanup;
+ }
+ } else {
+ if (qemuCreateInBridgePortWithHelper(cfg, brname,
+ &net->ifname,
+ tapfd, tap_create_flags) < 0) {
+ virDomainAuditNetDevice(def, net, tunpath, false);
+ goto cleanup;
+ }
+ /* qemuCreateInBridgePortWithHelper can only create a single FD */
+ if (*tapfdSize > 1) {
+ VIR_WARN("Ignoring multiqueue network request");
+ *tapfdSize = 1;
+ }
}
}
@@ -5221,6 +5268,7 @@ qemuBuildHostNetStr(virDomainNetDefPtr net,
case VIR_DOMAIN_NET_TYPE_BRIDGE:
case VIR_DOMAIN_NET_TYPE_NETWORK:
case VIR_DOMAIN_NET_TYPE_DIRECT:
+ case VIR_DOMAIN_NET_TYPE_ETHERNET:
virBufferAsprintf(&buf, "tap%c", type_sep);
/* for one tapfd 'fd=' shall be used,
* for more than one 'fds=' is the right choice */
@@ -5238,20 +5286,6 @@ qemuBuildHostNetStr(virDomainNetDefPtr net,
is_tap = true;
break;
- case VIR_DOMAIN_NET_TYPE_ETHERNET:
- virBufferAddLit(&buf, "tap");
- if (net->ifname) {
- virBufferAsprintf(&buf, "%cifname=%s", type_sep, net->ifname);
- type_sep = ',';
- }
- if (net->script) {
- virBufferAsprintf(&buf, "%cscript=%s", type_sep,
- net->script);
- type_sep = ',';
- }
- is_tap = true;
- break;
-
case VIR_DOMAIN_NET_TYPE_CLIENT:
virBufferAsprintf(&buf, "socket%cconnect=%s:%d",
type_sep,
@@ -8226,7 +8260,8 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
/* Currently nothing besides TAP devices supports multiqueue. */
if (net->driver.virtio.queues > 0 &&
!(actualType == VIR_DOMAIN_NET_TYPE_NETWORK ||
- actualType == VIR_DOMAIN_NET_TYPE_BRIDGE)) {
+ actualType == VIR_DOMAIN_NET_TYPE_BRIDGE ||
+ actualType == VIR_DOMAIN_NET_TYPE_ETHERNET)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Multiqueue network is not supported for: %s"),
virDomainNetTypeToString(actualType));
@@ -8235,7 +8270,8 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
if (net->backend.tap &&
!(actualType == VIR_DOMAIN_NET_TYPE_NETWORK ||
- actualType == VIR_DOMAIN_NET_TYPE_BRIDGE)) {
+ actualType == VIR_DOMAIN_NET_TYPE_BRIDGE ||
+ actualType == VIR_DOMAIN_NET_TYPE_ETHERNET)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Custom tap device path is not supported for: %s"),
virDomainNetTypeToString(actualType));
@@ -8245,7 +8281,8 @@ qemuBuildInterfaceCommandLine(virCommandPtr cmd,
cfg = virQEMUDriverGetConfig(driver);
if (actualType == VIR_DOMAIN_NET_TYPE_NETWORK ||
- actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) {
+ actualType == VIR_DOMAIN_NET_TYPE_BRIDGE ||
+ actualType == VIR_DOMAIN_NET_TYPE_ETHERNET) {
tapfdSize = net->driver.virtio.queues;
if (!tapfdSize)
tapfdSize = 1;
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index cc86a3b..21ea3fd 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -908,7 +908,8 @@ int qemuDomainAttachNetDevice(virConnectPtr conn,
/* Currently nothing besides TAP devices supports multiqueue. */
if (net->driver.virtio.queues > 0 &&
!(actualType == VIR_DOMAIN_NET_TYPE_NETWORK ||
- actualType == VIR_DOMAIN_NET_TYPE_BRIDGE)) {
+ actualType == VIR_DOMAIN_NET_TYPE_BRIDGE ||
+ actualType == VIR_DOMAIN_NET_TYPE_ETHERNET)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Multiqueue network is not supported for: %s"),
virDomainNetTypeToString(actualType));
@@ -916,7 +917,8 @@ int qemuDomainAttachNetDevice(virConnectPtr conn,
}
if (actualType == VIR_DOMAIN_NET_TYPE_BRIDGE ||
- actualType == VIR_DOMAIN_NET_TYPE_NETWORK) {
+ actualType == VIR_DOMAIN_NET_TYPE_NETWORK ||
+ actualType == VIR_DOMAIN_NET_TYPE_ETHERNET) {
tapfdSize = vhostfdSize = net->driver.virtio.queues;
if (!tapfdSize)
tapfdSize = vhostfdSize = 1;
@@ -947,13 +949,6 @@ int qemuDomainAttachNetDevice(virConnectPtr conn,
iface_connected = true;
if (qemuOpenVhostNet(vm->def, net, priv->qemuCaps, vhostfd, &vhostfdSize) < 0)
goto cleanup;
- } else if (actualType == VIR_DOMAIN_NET_TYPE_ETHERNET) {
- vhostfdSize = 1;
- if (VIR_ALLOC(vhostfd) < 0)
- goto cleanup;
- *vhostfd = -1;
- if (qemuOpenVhostNet(vm->def, net, priv->qemuCaps, vhostfd, &vhostfdSize) < 0)
- goto cleanup;
}
/* Set device online immediately */
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 64ee049..d866e44 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -5205,6 +5205,12 @@ void qemuProcessStop(virQEMUDriverPtr driver,
cfg->stateDir));
VIR_FREE(net->ifname);
break;
+ case VIR_DOMAIN_NET_TYPE_ETHERNET:
+ if (net->ifname) {
+ ignore_value(virNetDevTapDelete(net->ifname, net->backend.tap));
+ VIR_FREE(net->ifname);
+ }
+ break;
case VIR_DOMAIN_NET_TYPE_BRIDGE:
case VIR_DOMAIN_NET_TYPE_NETWORK:
#ifdef VIR_NETDEV_TAP_REQUIRE_MANUAL_CLEANUP
--
2.3.3
9 years, 4 months
[libvirt] [PATCH v3 0/3] Allow PCI virtio on ARM "virt" machine
by Pavel Fedin
Virt machine in qemu since v2.3.0 has PCI generic host controller, and can use
PCI devices. This provides performance improvement as well as vhost-net with
irqfd support for virtio-net. However libvirt currently does not allow ARM virt
machine to have PCI devices. This patchset adds the necessary support.
This version is completely reworked and uses different approach.
Changes since v2:
- Correctly model PCI Express bus on the machine. It is now possible to
explicitly specify <address-type='pci'> with attributes. This allows to
attach not only virtio, but any other PCI device to the model.
- Default is not changed and still mmio, for backwards compatibility with
existing installations. PCI bus has to be explicitly specified.
- Check for the capability in correct place, in v2 it actually did not work
Changes since v1:
- Added capability based on qemu version number
- Recognize also "virt-" prefix
Pavel Fedin (3):
Introduce QEMU_CAPS_ARM_VIRT_PCI
Add PCI-Express root to ARM virt machine
Build correct command line for PCI NICs on ARM
src/qemu/qemu_capabilities.c | 5 +++++
src/qemu/qemu_capabilities.h | 1 +
src/qemu/qemu_command.c | 3 ++-
src/qemu/qemu_domain.c | 12 ++++++++----
4 files changed, 16 insertions(+), 5 deletions(-)
--
1.9.5.msysgit.0
9 years, 4 months
[libvirt] [PATCH] vz: use PRL_USE_VNET_NAME_FOR_BRIDGE_NAME
by Maxim Nestratov
It is better not to assume that newly created network should be
connected to a bridge with same name, but specify it explicitly
by PRL_USE_VNET_NAME_FOR_BRIDGE_NAME flag.
Signed-off-by: Maxim Nestratov <mnestratov(a)virtuozzo.com>
---
src/vz/vz_sdk.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index 1b66958..1c56655 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -2834,7 +2834,9 @@ static int prlsdkAddNet(PRL_HANDLE sdkdom,
pret = PrlVirtNet_SetNetworkType(vnet, PVN_BRIDGED_ETHERNET);
prlsdkCheckRetGoto(pret, cleanup);
- job = PrlSrv_AddVirtualNetwork(privconn->server, vnet, 0);
+ job = PrlSrv_AddVirtualNetwork(privconn->server,
+ vnet,
+ PRL_USE_VNET_NAME_FOR_BRIDGE_NAME);
if (PRL_FAILED(pret = waitJob(job)))
goto cleanup;
--
1.7.1
9 years, 4 months
[libvirt] [PATCH v2 00/10] Restore code to allow unpriv_sgio for hostdev SCSI generic
by John Ferlan
v1 here:
http://www.redhat.com/archives/libvir-list/2015-June/msg00814.html
Changes since v1:
- Add doc patch 1 to indicate that this feature may only be supported by
certain kernels
- Adjust former patch 1 to add call to qemuIsSharedHostdev from
qemuSetUnprivSGIO
- Insert patches 7 & 8 which essentially refactor qemuSetUnprivSGIO a bit.
There should be no functional difference
- Patch 9 is now a much slimmer former patch 6
The end result is that 'generically speaking' if any kernel supports
setting the unprivileged SGIO feature, then these patches provide
the capability to do so.
Although as pointed out in the review of v1 only one specific downstream
kernel supports the feature, that doesn't mean other distros couldn't add
support in the same manner. So rather than just remove all traces from
libvirt completely, it seems it would be reasonable to keep the checks
in place and if a kernel then decides to add support this code exists
to assist.
John Ferlan (10):
docs: Clarify unprivileged sgio feature for host devices
qemu: Introduce qemuIsSharedHostdev
qemu: Introduce qemuGetHostdevPath
qemu: Refactor qemuCheckSharedDisk to create virCheckUnprivSGIO
qemu: Refactor qemuAddSharedHostdev and qemuRemoveSharedHostdev
qemu: Extract qemuGetHostdevPath from qemuGetSharedHostdevKey
qemu: Refactor qemuSetUnprivSGIO return values
qemu: Fix integer/boolean logic in qemuSetUnprivSGIO
qemu: Add ability to set sgio values for hostdev
qemu: Add check for unpriv sgio for SCSI generic host device
docs/formatdomain.html.in | 7 +-
src/qemu/qemu_conf.c | 226 ++++++++++++++++++++++++++++++----------------
2 files changed, 154 insertions(+), 79 deletions(-)
--
2.1.0
9 years, 4 months
[libvirt] [PATCH v2 0/2] Add support for portable-rpcgen from portablexdr library
by Pavel Fedin
This patch set allows to build libvirt natively under MinGW/MSYS using
portablexdr library. An updated version of portablexdr with fixed bugs
is available as part of MSYS2 project.
Differences from v1:
- Split into two parts
- Reflect structure definiton change also in xc_monitor_protocol-structs,
fix "make syntax-check"
Pavel Fedin (2):
Remove explicit enum from protocol structures
Add support for portable-rpcgen from portablexdr library
configure.ac | 2 +-
src/lxc/lxc_monitor_protocol.x | 2 +-
src/lxc_monitor_protocol-structs | 2 +-
src/rpc/genprotocol.pl | 5 ++++-
4 files changed, 7 insertions(+), 4 deletions(-)
--
1.9.5.msysgit.0
9 years, 4 months