[libvirt] [PATCH] LXC: support block devices for container
by Gao feng
This patch allows to config block device for container.
the disk node is used to point out source device and target device
source device is the device path in host,
and target device is the device name in container.
such as
<disk type='block' device='disk'>
<driver name="lxc"/>
<source dev='/dev/sda2'/>
<target dev='sda1'/>
</disk>
Unfortunately it's no use to config readonly in disk node now.
Signed-off-by: Gao feng <gaofeng(a)cn.fujitsu.com>
---
src/lxc/lxc_container.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++
src/lxc/lxc_controller.c | 15 +++++++++
2 files changed, 93 insertions(+), 0 deletions(-)
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 9bb6218..062cc8f 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -581,6 +581,80 @@ static int lxcContainerMountFSDevPTS(virDomainFSDefPtr root)
return rc;
}
+static int lxcContainerAddDisk(virDomainDiskDefPtr disk,
+ const char *srcprefix)
+{
+ char *srcPath = NULL;
+ char *dstPath = NULL;
+ struct stat sb;
+ dev_t dev;
+ int ret = -1;
+ switch (disk->device) {
+ case VIR_DOMAIN_DISK_DEVICE_DISK:
+ case VIR_DOMAIN_DISK_DEVICE_LUN:
+ if (virAsprintf(&srcPath, "%s/%s", srcprefix, disk->src) < 0) {
+ virReportOOMError();
+ return ret;
+ }
+ if (virAsprintf(&dstPath, "/dev/%s", disk->dst) < 0) {
+ virReportOOMError();
+ goto cleanup;
+ }
+ if (stat(srcPath, &sb) < 0) {
+ ret = -errno;
+ goto cleanup;
+ }
+ dev = makedev(major(sb.st_rdev), minor(sb.st_rdev));
+ if (mknod(dstPath, S_ISCHR(sb.st_mode) ? S_IFCHR : S_IFBLK, dev) < 0 ||
+ chmod(dstPath, sb.st_mode)) {
+ virReportSystemError(errno,
+ _("Failed to make device %s"),
+ dstPath);
+ goto cleanup;
+ }
+ ret = 0;
+ break;
+ default:
+ lxcError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("unsupported disk device type '%s'."),
+ virDomainDiskDeviceTypeToString(disk->device));
+ break;
+ }
+
+cleanup:
+ VIR_FREE(srcPath);
+ VIR_FREE(dstPath);
+ return ret;
+}
+static int lxcContainerAddDevices(virDomainDefPtr vmDef,
+ const char *srcprefix)
+{
+ int ret = -1;
+ size_t i;
+
+ for (i=0 ; i<vmDef->ndisks ; i++) {
+ virDomainDiskDefPtr disk = vmDef->disks[i];
+
+ if (disk->driverName !=NULL && !STREQ(disk->driverName, "lxc")) {
+ lxcError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("unsupported driver name '%s' for disk '%s'"),
+ disk->driverName, disk->src);
+ continue;
+ }
+ if (disk->type != VIR_DOMAIN_DISK_TYPE_BLOCK) {
+ lxcError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("unsupported disk type '%s'"),
+ virDomainDiskTypeToString(disk->type));
+ continue;
+ }
+ if (lxcContainerAddDisk(disk, srcprefix) < 0)
+ goto cleanup;
+ }
+ ret = 0;
+cleanup:
+ return ret;
+}
+
static int lxcContainerPopulateDevices(char **ttyPaths, size_t nttyPaths)
{
size_t i;
@@ -1144,6 +1218,10 @@ static int lxcContainerSetupPivotRoot(virDomainDefPtr vmDef,
if (lxcContainerMountFSDevPTS(root) < 0)
return -1;
+ /* Create devices */
+ if (lxcContainerAddDevices(vmDef, "/.oldroot") <0)
+ return -1;
+
/* Populates device nodes in /dev/ */
if (lxcContainerPopulateDevices(ttyPaths, nttyPaths) < 0)
return -1;
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index bbc9d9c..5576f99 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -545,6 +545,21 @@ static int lxcSetContainerDeviceACL(virCgroupPtr cgroup, virDomainDefPtr def)
}
}
+ for (i = 0 ; i < def->ndisks ; i++) {
+ if (def->disks[i]->type != VIR_DOMAIN_DISK_TYPE_BLOCK)
+ continue;
+
+ rc = virCgroupAllowDevicePath(cgroup,
+ def->disks[i]->src,
+ VIR_CGROUP_DEVICE_RWM);
+ if (rc != 0) {
+ virReportSystemError(-rc,
+ _("Unable to allow device %s for domain %s"),
+ def->disks[i]->src, def->name);
+ goto cleanup;
+ }
+ }
+
rc = virCgroupAllowDeviceMajor(cgroup, 'c', LXC_DEV_MAJ_PTY,
VIR_CGROUP_DEVICE_RWM);
if (rc != 0) {
--
1.7.7.6
12 years, 7 months
[libvirt] Multithreading crash on Win32
by Marcel Müller
Hello everyone,
Im using libvirt 0.9.11 on a Windows machine with java bindings. This works
fine, as long as the application is single threaded. As soon as I switch
over to more threads libvirt crashes most of the time (but not always!).
Ive tried to track down the issue, but Im at a loss now. Please see
attached file for debug info.
What Ive found out so far:
- It looks like this happens only on Win32 (Win 7 x64), Linux
(Debian Squeeze) looks fine so far
- Its crashing in src/rpc/virnetsocket.c at the end of
virNetSocketNewConnectTCP when calling freeaddrinfo(ai). ai is not a
null value here, Ive checked that.
Im not sure how to debug this any further.
Hope someone has an idea on that.
Best Regards,
Marcel
12 years, 7 months
[libvirt] [PATCH] qemu: change rbd auth_supported separation character to ;
by Josh Durgin
This works with newer qemu that doesn't allow escaping spaces.
It's backwards compatible as well.
Signed-off-by: Josh Durgin <josh.durgin(a)dreamhost.com>
---
src/qemu/qemu_command.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index f971a08..ee3bf48 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1673,8 +1673,8 @@ qemuBuildRBDString(virConnectPtr conn,
virReportOOMError();
goto error;
}
- virBufferEscape(opt, '\\', ":",
- ":key=%s:auth_supported=cephx none",
+ virBufferEscape(opt, '\\', ":;",
+ ":key=%s:auth_supported=cephx;none",
base64);
VIR_FREE(base64);
} else {
--
1.7.5.4
12 years, 7 months
[libvirt] [PATCHv2 00/15] live block migration via virDomainBlockCopy
by Eric Blake
v1 was here:
https://www.redhat.com/archives/libvir-list/2012-April/msg00068.html
changes from v1: Paolo has updated the qemu side of things, and built
a scratch image for RHEL that I was able to test with for the new
semantics. I was actually able to successfully run two different
block copy jobs, one canceled and one pivoted, with SELinux disabled
and this patch series.
Patch 12/15 is for reference only when working with Paolo's build;
it will not go upstream.
Patches 13-15 are optional; the extra flexibility might be nice, but
I haven't yet played with those three enough to know if Paolo's build
behaves like I was expecting.
I obviously have more patches to write, such as supporting the REUSE_EXT
flag to reuse files instead of creating a new one, and fixing several
XXX comments related to SELinux, auditing, and disk locking. But they
can be extra patches on top of this starting series.
Adam Litke (2):
blockjob: add API for async virDomainBlockJobAbort
blockjob: wire up qemu async virDomainBlockJobAbort
Eric Blake (13):
blockjob: allow for fast-finishing job
blockjob: add new API flags
blockjob: add 'blockcopy' to virsh
blockjob: enhance xml to track mirrors across libvirtd restart
blockjob: react to active block copy
blockjob: expose qemu commands for mirrored storage migration
blockjob: return appropriate event and info
blockjob: support pivot operation on cancel
blockjob: implement block copy for qemu
blockjob: accommodate RHEL backport names
blockjob: add virDomainBlockCopy
blockjob: enhance virsh 'blockcopy'
blockjob: wire up qemu and RPC for block copy
docs/apibuild.py | 1 +
docs/formatdomain.html.in | 11 ++
docs/schemas/domaincommon.rng | 19 ++-
include/libvirt/libvirt.h.in | 50 ++++++-
include/libvirt/virterror.h | 1 +
src/conf/domain_conf.c | 54 +++++++
src/conf/domain_conf.h | 6 +
src/driver.h | 5 +
src/libvirt.c | 220 +++++++++++++++++++++++++-
src/libvirt_private.syms | 1 +
src/libvirt_public.syms | 5 +
src/qemu/qemu_capabilities.c | 3 +
src/qemu/qemu_capabilities.h | 2 +
src/qemu/qemu_driver.c | 340 +++++++++++++++++++++++++++++++++++++++--
src/qemu/qemu_hotplug.c | 7 +
src/qemu/qemu_monitor.c | 50 ++++++
src/qemu/qemu_monitor.h | 28 +++-
src/qemu/qemu_monitor_json.c | 154 ++++++++++++++++---
src/qemu/qemu_monitor_json.h | 21 +++-
src/remote/remote_driver.c | 1 +
src/remote/remote_protocol.x | 12 ++-
src/remote_protocol-structs | 9 +
src/rpc/gendispatch.pl | 1 +
src/util/virterror.c | 6 +
tools/virsh.c | 140 ++++++++++++++----
tools/virsh.pod | 40 +++++-
26 files changed, 1099 insertions(+), 88 deletions(-)
--
1.7.7.6
12 years, 7 months
[libvirt] [PATCH] snapshot: fix memory leak on error
by Eric Blake
Leak introduced in commit 0436d32. If we allocate an actions array,
but fail early enough to never consume it with the qemu monitor
transaction call, we leaked memory.
* src/qemu/qemu_driver.c (qemuDomainSnapshotCreateDiskActive):
Free actions array on failure.
---
src/qemu/qemu_driver.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index b29029e..a214593 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -10132,6 +10132,8 @@ qemuDomainSnapshotCreateDiskActive(virConnectPtr conn,
if (actions) {
if (ret == 0)
ret = qemuMonitorTransaction(priv->mon, actions);
+ else
+ virJSONValueFree(actions);
if (ret < 0) {
/* Transaction failed; undo the changes to vm. */
bool need_unlink = !(flags & VIR_DOMAIN_SNAPSHOT_CREATE_REUSE_EXT);
--
1.7.7.6
12 years, 7 months
[libvirt] [PATCH] qemu_ga: Don't overwrite errors on FSThaw
by Michal Privoznik
We can tell qemuDomainSnapshotFSThaw if we want it to report errors or
not. However, if we don't want to and an error has been already set by
previous qemuReportError() we must keep copy of that error not just a
pointer to it. Otherwise, it get overwritten if FSThaw reports an error.
---
src/qemu/qemu_driver.c | 11 ++++-------
1 files changed, 4 insertions(+), 7 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index dd79973..0880f51 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -9636,16 +9636,13 @@ qemuDomainSnapshotFSThaw(struct qemud_driver *driver,
qemuDomainObjEnterAgent(driver, vm);
if (!report)
- err = virGetLastError();
+ err = virSaveLastError();
thawed = qemuAgentFSThaw(priv->agent);
- if (!report) {
- if (err)
- virResetError(err);
- else
- virResetLastError();
- }
+ if (!report)
+ virSetError(err);
qemuDomainObjExitAgent(driver, vm);
+ virFreeError(err);
return thawed;
}
--
1.7.8.5
12 years, 7 months
[libvirt] [test-API PATCHv2 1/2] utils: Add exception for general test errors
by Peter Krempa
This helper exception helps with reporting test errors that don't
produce a libvirt exception. Eg. comparison of returned and expected
value fails although the api call succeeded.
---
Diff to v1:
-- moved the new exception to the exception module
exception.py | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/exception.py b/exception.py
index 0000aab..d0a772f 100644
--- a/exception.py
+++ b/exception.py
@@ -75,3 +75,7 @@ class CaseConfigfileError(LibvirtException):
class MissingVariable(LibvirtException):
code = 210
message = "Variables missing from env.cfg [variables] section"
+
+class TestError(LibvirtException):
+ code = 211
+ message = "Test failed"
--
1.7.3.4
12 years, 7 months
[libvirt] [PATCH] xen config: No vfb in HVM guest configuration
by Stefan Bader
This causes an implicit vkbd device to be added which takes
6min to finally fail being initialized in the guest.
http://lists.xen.org/archives/html/xen-devel/2012-04/msg00409.html
Signed-off-by: Stefan Bader <stefan.bader(a)canonical.com>
---
src/xenxs/xen_sxpr.c | 11 ++++-------
src/xenxs/xen_xm.c | 2 +-
2 files changed, 5 insertions(+), 8 deletions(-)
diff --git a/src/xenxs/xen_sxpr.c b/src/xenxs/xen_sxpr.c
index b26b2bc..b2f98f6 100644
--- a/src/xenxs/xen_sxpr.c
+++ b/src/xenxs/xen_sxpr.c
@@ -2464,9 +2464,8 @@ xenFormatSxpr(virConnectPtr conn,
}
}
- /* PV graphics for xen <= 3.0.4, or HVM graphics for xen <= 3.1.0 */
- if ((!hvm && xendConfigVersion < XEND_CONFIG_MIN_VERS_PVFB_NEWCONF) ||
- (hvm && xendConfigVersion < XEND_CONFIG_VERSION_3_1_0)) {
+ /* PV graphics for xen <= 3.0.4, or HVM graphics */
+ if (hvm || (xendConfigVersion < XEND_CONFIG_MIN_VERS_PVFB_NEWCONF)) {
if ((def->ngraphics == 1) &&
xenFormatSxprGraphicsOld(def->graphics[0],
&buf, xendConfigVersion) < 0)
@@ -2578,10 +2577,8 @@ xenFormatSxpr(virConnectPtr conn,
if (xenFormatSxprAllPCI(def, &buf) < 0)
goto error;
- /* New style PV graphics config xen >= 3.0.4,
- * or HVM graphics config xen >= 3.0.5 */
- if ((xendConfigVersion >= XEND_CONFIG_MIN_VERS_PVFB_NEWCONF && !hvm) ||
- (xendConfigVersion >= XEND_CONFIG_VERSION_3_1_0 && hvm)) {
+ /* New style PV graphics config xen >= 3.0.4 */
+ if (!hmv && (xendConfigVersion >= XEND_CONFIG_MIN_VERS_PVFB_NEWCONF)) {
if ((def->ngraphics == 1) &&
xenFormatSxprGraphicsNew(def->graphics[0], &buf) < 0)
goto error;
diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c
index 8e24fd52..d65e97a 100644
--- a/src/xenxs/xen_xm.c
+++ b/src/xenxs/xen_xm.c
@@ -1779,7 +1779,7 @@ virConfPtr xenFormatXM(virConnectPtr conn,
}
if (def->ngraphics == 1) {
- if (xendConfigVersion < (hvm ? XEND_CONFIG_VERSION_3_1_0 : XEND_CONFIG_MIN_VERS_PVFB_NEWCONF)) {
+ if (hvm || (xendConfigVersion < XEND_CONFIG_MIN_VERS_PVFB_NEWCONF)) {
if (def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) {
if (xenXMConfigSetInt(conf, "sdl", 1) < 0)
goto no_memory;
--
1.7.9.1
12 years, 7 months