[libvirt] [PATCH] Fix cgroups when all are mounted on /sys/fs/cgroup
by Daniel P. Berrange
From: "Daniel P. Berrange" <berrange(a)redhat.com>
Some users in Ubuntu/Debian seem to have a setup where all the
cgroup controllers are mounted on /sys/fs/cgroup rather than
any /sys/fs/cgroup/<controller> name. In the loop which detects
which controllers are present for a mount point we were modifying
'mnt_dir' field in the 'struct mntent' var, but not always restoring
the original value. This caused detection to break in the all-in-one
mount setup.
Fix that logic bug and add test case coverage for this mount
setup.
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
src/util/vircgroup.c | 3 ++-
tests/vircgroupmock.c | 42 ++++++++++++++++++++++++++++++++++++---
tests/vircgrouptest.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 96 insertions(+), 4 deletions(-)
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 16458a3..a260356 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -342,10 +342,11 @@ virCgroupDetectMounts(virCgroupPtr group)
entry.mnt_dir);
goto error;
}
- *tmp2 = '\0';
+
/* If it is a co-mount it has a filename like "cpu,cpuacct"
* and we must identify the symlink path */
if (strchr(tmp2 + 1, ',')) {
+ *tmp2 = '\0';
if (virAsprintf(&linksrc, "%s/%s",
entry.mnt_dir, typestr) < 0)
goto error;
diff --git a/tests/vircgroupmock.c b/tests/vircgroupmock.c
index f1a5700..bf52843 100644
--- a/tests/vircgroupmock.c
+++ b/tests/vircgroupmock.c
@@ -103,6 +103,27 @@ const char *proccgroups =
"blkio 8 4 1\n";
+const char *procmountsallinone =
+ "rootfs / rootfs rw 0 0\n"
+ "sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0\n"
+ "proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0\n"
+ "udev /dev devtmpfs rw,relatime,size=16458560k,nr_inodes=4114640,mode=755 0 0\n"
+ "devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0\n"
+ "nfsd /proc/fs/nfsd nfsd rw,relatime 0 0\n"
+ "cgroup /not/really/sys/fs/cgroup cgroup rw,relatime,blkio,devices,memory,cpuacct,cpu,cpuset 0 0\n";
+
+const char *procselfcgroupsallinone =
+ "6:blkio,devices,memory,cpuacct,cpu,cpuset:/";
+
+const char *proccgroupsallinone =
+ "#subsys_name hierarchy num_cgroups enabled\n"
+ "cpuset 6 1 1\n"
+ "cpu 6 1 1\n"
+ "cpuacct 6 1 1\n"
+ "memory 6 1 1\n"
+ "devices 6 1 1\n"
+ "blkio 6 1 1\n";
+
static int make_file(const char *path,
const char *name,
const char *value)
@@ -378,11 +399,20 @@ static void init_sysfs(void)
FILE *fopen(const char *path, const char *mode)
{
+ const char *mock;
+ bool allinone = false;
init_syms();
+ mock = getenv("VIR_CGROUP_MOCK_MODE");
+ if (mock && STREQ(mock, "allinone"))
+ allinone = true;
+
if (STREQ(path, "/proc/mounts")) {
if (STREQ(mode, "r")) {
- return fmemopen((void *)procmounts, strlen(procmounts), mode);
+ if (allinone)
+ return fmemopen((void *)procmountsallinone, strlen(procmountsallinone), mode);
+ else
+ return fmemopen((void *)procmounts, strlen(procmounts), mode);
} else {
errno = EACCES;
return NULL;
@@ -390,7 +420,10 @@ FILE *fopen(const char *path, const char *mode)
}
if (STREQ(path, "/proc/cgroups")) {
if (STREQ(mode, "r")) {
- return fmemopen((void *)proccgroups, strlen(proccgroups), mode);
+ if (allinone)
+ return fmemopen((void *)proccgroupsallinone, strlen(proccgroupsallinone), mode);
+ else
+ return fmemopen((void *)proccgroups, strlen(proccgroups), mode);
} else {
errno = EACCES;
return NULL;
@@ -398,7 +431,10 @@ FILE *fopen(const char *path, const char *mode)
}
if (STREQ(path, "/proc/self/cgroup")) {
if (STREQ(mode, "r")) {
- return fmemopen((void *)procselfcgroups, strlen(procselfcgroups), mode);
+ if (allinone)
+ return fmemopen((void *)procselfcgroupsallinone, strlen(procselfcgroupsallinone), mode);
+ else
+ return fmemopen((void *)procselfcgroups, strlen(procselfcgroups), mode);
} else {
errno = EACCES;
return NULL;
diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c
index 4bdd4c9..f12587c 100644
--- a/tests/vircgrouptest.c
+++ b/tests/vircgrouptest.c
@@ -99,6 +99,16 @@ const char *mountsFull[VIR_CGROUP_CONTROLLER_LAST] = {
[VIR_CGROUP_CONTROLLER_BLKIO] = "/not/really/sys/fs/cgroup/blkio",
[VIR_CGROUP_CONTROLLER_SYSTEMD] = "/not/really/sys/fs/cgroup/systemd",
};
+const char *mountsAllInOne[VIR_CGROUP_CONTROLLER_LAST] = {
+ [VIR_CGROUP_CONTROLLER_CPU] = "/not/really/sys/fs/cgroup",
+ [VIR_CGROUP_CONTROLLER_CPUACCT] = "/not/really/sys/fs/cgroup",
+ [VIR_CGROUP_CONTROLLER_CPUSET] = "/not/really/sys/fs/cgroup",
+ [VIR_CGROUP_CONTROLLER_MEMORY] = "/not/really/sys/fs/cgroup",
+ [VIR_CGROUP_CONTROLLER_DEVICES] = "/not/really/sys/fs/cgroup",
+ [VIR_CGROUP_CONTROLLER_FREEZER] = NULL,
+ [VIR_CGROUP_CONTROLLER_BLKIO] = "/not/really/sys/fs/cgroup",
+ [VIR_CGROUP_CONTROLLER_SYSTEMD] = NULL,
+};
const char *links[VIR_CGROUP_CONTROLLER_LAST] = {
[VIR_CGROUP_CONTROLLER_CPU] = "/not/really/sys/fs/cgroup/cpu",
@@ -108,6 +118,18 @@ const char *links[VIR_CGROUP_CONTROLLER_LAST] = {
[VIR_CGROUP_CONTROLLER_DEVICES] = NULL,
[VIR_CGROUP_CONTROLLER_FREEZER] = NULL,
[VIR_CGROUP_CONTROLLER_BLKIO] = NULL,
+ [VIR_CGROUP_CONTROLLER_SYSTEMD] = NULL,
+};
+
+const char *linksAllInOne[VIR_CGROUP_CONTROLLER_LAST] = {
+ [VIR_CGROUP_CONTROLLER_CPU] = NULL,
+ [VIR_CGROUP_CONTROLLER_CPUACCT] = NULL,
+ [VIR_CGROUP_CONTROLLER_CPUSET] = NULL,
+ [VIR_CGROUP_CONTROLLER_MEMORY] = NULL,
+ [VIR_CGROUP_CONTROLLER_DEVICES] = NULL,
+ [VIR_CGROUP_CONTROLLER_FREEZER] = NULL,
+ [VIR_CGROUP_CONTROLLER_BLKIO] = NULL,
+ [VIR_CGROUP_CONTROLLER_SYSTEMD] = NULL,
};
@@ -417,6 +439,34 @@ cleanup:
return ret;
}
+static int testCgroupNewForSelfAllInOne(const void *args ATTRIBUTE_UNUSED)
+{
+ virCgroupPtr cgroup = NULL;
+ int ret = -1;
+ const char *placement[VIR_CGROUP_CONTROLLER_LAST] = {
+ [VIR_CGROUP_CONTROLLER_CPU] = "/",
+ [VIR_CGROUP_CONTROLLER_CPUACCT] = "/",
+ [VIR_CGROUP_CONTROLLER_CPUSET] = "/",
+ [VIR_CGROUP_CONTROLLER_MEMORY] = "/",
+ [VIR_CGROUP_CONTROLLER_DEVICES] = "/",
+ [VIR_CGROUP_CONTROLLER_FREEZER] = NULL,
+ [VIR_CGROUP_CONTROLLER_BLKIO] = "/",
+ };
+
+ if (virCgroupNewSelf(&cgroup) < 0) {
+ fprintf(stderr, "Cannot create cgroup for self\n");
+ goto cleanup;
+ }
+
+ ret = validateCgroup(cgroup, "", mountsAllInOne, linksAllInOne, placement);
+
+cleanup:
+ virCgroupFree(&cgroup);
+ return ret;
+}
+
+
+
# define FAKESYSFSDIRTEMPLATE abs_builddir "/fakesysfsdir-XXXXXX"
static int
@@ -455,6 +505,11 @@ mymain(void)
if (virtTestRun("New cgroup for domain partition escaped", 1, testCgroupNewForPartitionDomainEscaped, NULL) < 0)
ret = -1;
+ setenv("VIR_CGROUP_MOCK_MODE", "allinone", 1);
+ if (virtTestRun("New cgroup for self (allinone)", 1, testCgroupNewForSelfAllInOne, NULL) < 0)
+ ret = -1;
+ unsetenv("VIR_CGROUP_MOCK_MODE");
+
if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
virFileDeleteTree(fakesysfsdir);
--
1.8.3.1
11 years, 2 months
[libvirt] [PATCH] qemu: endjob returns a bool
by Eric Blake
Osier Yang pointed out that ever since commit 31cb030, the
signature of qemuDomainObjEndJob was changed to return a bool.
While comparison against 0 or > 0 still gives the right results,
it looks fishy; we also had one place that was comparing < 0
which is effectively dead code.
* src/qemu/qemu_migration.c (qemuMigrationPrepareAny): Fix dead
code bug.
(qemuMigrationBegin): Use more canonical form of bool check.
* src/qemu/qemu_driver.c (qemuAutostartDomain)
(qemuDomainCreateXML, qemuDomainSuspend, qemuDomainResume)
(qemuDomainShutdownFlags, qemuDomainReboot, qemuDomainReset)
(qemuDomainDestroyFlags, qemuDomainSetMemoryFlags)
(qemuDomainSetMemoryStatsPeriod, qemuDomainInjectNMI)
(qemuDomainSendKey, qemuDomainGetInfo, qemuDomainScreenshot)
(qemuDomainSetVcpusFlags, qemuDomainGetVcpusFlags)
(qemuDomainRestoreFlags, qemuDomainGetXMLDesc)
(qemuDomainCreateWithFlags, qemuDomainAttachDeviceFlags)
(qemuDomainUpdateDeviceFlags, qemuDomainDetachDeviceFlags)
(qemuDomainBlockResize, qemuDomainBlockStats)
(qemuDomainBlockStatsFlags, qemuDomainMemoryStats)
(qemuDomainMemoryPeek, qemuDomainGetBlockInfo)
(qemuDomainAbortJob, qemuDomainMigrateSetMaxDowntime)
(qemuDomainMigrateGetCompressionCache)
(qemuDomainMigrateSetCompressionCache)
(qemuDomainMigrateSetMaxSpeed)
(qemuDomainSnapshotCreateActiveInternal)
(qemuDomainRevertToSnapshot, qemuDomainSnapshotDelete)
(qemuDomainQemuMonitorCommand, qemuDomainQemuAttach)
(qemuDomainBlockJobImpl, qemuDomainBlockCopy)
(qemuDomainBlockCommit, qemuDomainOpenGraphics)
(qemuDomainGetBlockIoTune, qemuDomainGetDiskErrors)
(qemuDomainPMSuspendForDuration, qemuDomainPMWakeup)
(qemuDomainQemuAgentCommand, qemuDomainFSTrim): Likewise.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
Most of this is mechanical, but the change to qemuMigrationPrepareAny
requires special care to ensure that checking for 0 instead of negative
isn't introducing a bug on failure to start incoming migration.
src/qemu/qemu_driver.c | 115 +++++++++++++++++++++-------------------------
src/qemu/qemu_migration.c | 4 +-
2 files changed, 55 insertions(+), 64 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 9b5d126..bbf2d23 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -293,7 +293,7 @@ qemuAutostartDomain(virDomainObjPtr vm,
err ? err->message : _("unknown error"));
}
- if (qemuDomainObjEndJob(data->driver, vm) == 0)
+ if (!qemuDomainObjEndJob(data->driver, vm))
vm = NULL;
}
@@ -1612,7 +1612,7 @@ static virDomainPtr qemuDomainCreateXML(virConnectPtr conn,
VIR_NETDEV_VPORT_PROFILE_OP_CREATE,
start_flags) < 0) {
virDomainAuditStart(vm, "booted", false);
- if (qemuDomainObjEndJob(driver, vm) > 0)
+ if (qemuDomainObjEndJob(driver, vm))
qemuDomainRemoveInactive(driver, vm);
vm = NULL;
goto cleanup;
@@ -1637,7 +1637,7 @@ static virDomainPtr qemuDomainCreateXML(virConnectPtr conn,
if (dom)
dom->id = vm->def->id;
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
@@ -1722,7 +1722,7 @@ static int qemuDomainSuspend(virDomainPtr dom) {
ret = 0;
endjob:
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
@@ -1787,7 +1787,7 @@ static int qemuDomainResume(virDomainPtr dom) {
ret = 0;
endjob:
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
@@ -1882,7 +1882,7 @@ static int qemuDomainShutdownFlags(virDomainPtr dom, unsigned int flags) {
}
endjob:
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
@@ -1992,7 +1992,7 @@ qemuDomainReboot(virDomainPtr dom, unsigned int flags)
}
endjob:
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
@@ -2035,7 +2035,7 @@ qemuDomainReset(virDomainPtr dom, unsigned int flags)
priv->fakeReboot = false;
endjob:
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
@@ -2121,15 +2121,14 @@ qemuDomainDestroyFlags(virDomainPtr dom,
virDomainAuditStop(vm, "destroyed");
if (!vm->persistent) {
- if (qemuDomainObjEndJob(driver, vm) > 0)
+ if (qemuDomainObjEndJob(driver, vm))
qemuDomainRemoveInactive(driver, vm);
vm = NULL;
}
ret = 0;
endjob:
- if (vm &&
- qemuDomainObjEndJob(driver, vm) == 0)
+ if (vm && !qemuDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
@@ -2274,7 +2273,7 @@ static int qemuDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem,
ret = 0;
endjob:
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
@@ -2348,7 +2347,7 @@ static int qemuDomainSetMemoryStatsPeriod(virDomainPtr dom, int period,
ret = 0;
endjob:
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
@@ -2396,10 +2395,8 @@ static int qemuDomainInjectNMI(virDomainPtr domain, unsigned int flags)
qemuDomainObjExitMonitor(driver, vm);
endjob:
- if (qemuDomainObjEndJob(driver, vm) == 0) {
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
- goto cleanup;
- }
cleanup:
if (vm)
@@ -2462,7 +2459,7 @@ static int qemuDomainSendKey(virDomainPtr domain,
qemuDomainObjExitMonitor(driver, vm);
endjob:
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
@@ -2518,7 +2515,7 @@ static int qemuDomainGetInfo(virDomainPtr dom,
err = qemuMonitorGetBalloonInfo(priv->mon, &balloon);
qemuDomainObjExitMonitor(driver, vm);
}
- if (qemuDomainObjEndJob(driver, vm) == 0) {
+ if (!qemuDomainObjEndJob(driver, vm)) {
vm = NULL;
goto cleanup;
}
@@ -3670,7 +3667,7 @@ endjob:
unlink(tmp);
VIR_FREE(tmp);
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
@@ -4225,7 +4222,7 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
ret = 0;
endjob:
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
@@ -4919,7 +4916,7 @@ qemuDomainGetVcpusFlags(virDomainPtr dom, unsigned int flags)
qemuDomainObjExitAgent(vm);
endjob:
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
if (ncpuinfo < 0)
@@ -5446,7 +5443,7 @@ qemuDomainRestoreFlags(virConnectPtr conn,
if (virFileWrapperFdClose(wrapperFd) < 0)
VIR_WARN("Failed to close %s", path);
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
else if (ret < 0 && !vm->persistent) {
qemuDomainRemoveInactive(driver, vm);
@@ -5666,7 +5663,7 @@ static char *qemuDomainGetXMLDesc(virDomainPtr dom,
qemuDomainObjExitMonitor(driver, vm);
endjob:
- if (qemuDomainObjEndJob(driver, vm) == 0) {
+ if (!qemuDomainObjEndJob(driver, vm)) {
vm = NULL;
goto cleanup;
}
@@ -6065,7 +6062,7 @@ qemuDomainCreateWithFlags(virDomainPtr dom, unsigned int flags)
ret = 0;
endjob:
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
@@ -6937,7 +6934,7 @@ static int qemuDomainAttachDeviceFlags(virDomainPtr dom, const char *xml,
}
endjob:
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
@@ -7081,7 +7078,7 @@ static int qemuDomainUpdateDeviceFlags(virDomainPtr dom,
}
endjob:
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
@@ -7219,7 +7216,7 @@ static int qemuDomainDetachDeviceFlags(virDomainPtr dom, const char *xml,
}
endjob:
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
@@ -8917,7 +8914,7 @@ qemuDomainBlockResize(virDomainPtr dom,
ret = 0;
endjob:
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
@@ -8993,7 +8990,7 @@ qemuDomainBlockStats(virDomainPtr dom,
qemuDomainObjExitMonitor(driver, vm);
endjob:
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
@@ -9161,7 +9158,7 @@ qemuDomainBlockStatsFlags(virDomainPtr dom,
*nparams = tmp;
endjob:
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
@@ -9556,7 +9553,7 @@ qemuDomainMemoryStats(virDomainPtr dom,
}
}
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
@@ -9699,7 +9696,7 @@ qemuDomainMemoryPeek(virDomainPtr dom,
ret = 0;
endjob:
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
@@ -9848,7 +9845,7 @@ static int qemuDomainGetBlockInfo(virDomainPtr dom,
ret = 0;
}
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
} else {
ret = 0;
@@ -11145,7 +11142,7 @@ static int qemuDomainAbortJob(virDomainPtr dom) {
qemuDomainObjExitMonitor(driver, vm);
endjob:
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
@@ -11196,7 +11193,7 @@ qemuDomainMigrateSetMaxDowntime(virDomainPtr dom,
qemuDomainObjExitMonitor(driver, vm);
endjob:
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
@@ -11251,7 +11248,7 @@ qemuDomainMigrateGetCompressionCache(virDomainPtr dom,
qemuDomainObjExitMonitor(driver, vm);
endjob:
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
@@ -11307,7 +11304,7 @@ qemuDomainMigrateSetCompressionCache(virDomainPtr dom,
qemuDomainObjExitMonitor(driver, vm);
endjob:
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
@@ -11355,7 +11352,7 @@ qemuDomainMigrateSetMaxSpeed(virDomainPtr dom,
priv->migMaxBandwidth = bandwidth;
endjob:
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
} else {
priv->migMaxBandwidth = bandwidth;
@@ -11708,7 +11705,7 @@ cleanup:
}
endjob:
- if (vm && qemuDomainObjEndJob(driver, vm) == 0) {
+ if (vm && !qemuDomainObjEndJob(driver, vm)) {
/* Only possible if a transient vm quit while our locks were down,
* in which case we don't want to save snapshot metadata. */
*vmptr = NULL;
@@ -13290,7 +13287,7 @@ static int qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
if (qemuDomainSnapshotRevertInactive(driver, vm, snap) < 0) {
if (!vm->persistent) {
- if (qemuDomainObjEndJob(driver, vm) > 0)
+ if (qemuDomainObjEndJob(driver, vm))
qemuDomainRemoveInactive(driver, vm);
vm = NULL;
goto cleanup;
@@ -13317,7 +13314,7 @@ static int qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
virDomainAuditStart(vm, "from-snapshot", rc >= 0);
if (rc < 0) {
if (!vm->persistent) {
- if (qemuDomainObjEndJob(driver, vm) > 0)
+ if (qemuDomainObjEndJob(driver, vm))
qemuDomainRemoveInactive(driver, vm);
vm = NULL;
goto cleanup;
@@ -13340,7 +13337,7 @@ static int qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
ret = 0;
endjob:
- if (vm && qemuDomainObjEndJob(driver, vm) == 0)
+ if (vm && !qemuDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
@@ -13506,7 +13503,7 @@ static int qemuDomainSnapshotDelete(virDomainSnapshotPtr snapshot,
}
endjob:
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
@@ -13559,7 +13556,7 @@ static int qemuDomainQemuMonitorCommand(virDomainPtr domain, const char *cmd,
qemuDomainObjExitMonitor(driver, vm);
endjob:
- if (qemuDomainObjEndJob(driver, vm) == 0) {
+ if (!qemuDomainObjEndJob(driver, vm)) {
vm = NULL;
}
@@ -13641,7 +13638,7 @@ static virDomainPtr qemuDomainQemuAttach(virConnectPtr conn,
if (qemuProcessAttach(conn, driver, vm, pid,
pidfile, monConfig, monJSON) < 0) {
- if (qemuDomainObjEndJob(driver, vm) > 0)
+ if (qemuDomainObjEndJob(driver, vm))
qemuDomainRemoveInactive(driver, vm);
vm = NULL;
monConfig = NULL;
@@ -13654,7 +13651,7 @@ static virDomainPtr qemuDomainQemuAttach(virConnectPtr conn,
if (dom)
dom->id = vm->def->id;
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
@@ -14149,7 +14146,7 @@ qemuDomainBlockJobImpl(virDomainObjPtr vm,
}
endjob:
- if (qemuDomainObjEndJob(driver, vm) == 0) {
+ if (!qemuDomainObjEndJob(driver, vm)) {
vm = NULL;
goto cleanup;
}
@@ -14380,10 +14377,8 @@ endjob:
if (ret < 0)
disk->mirrorFormat = VIR_STORAGE_FILE_NONE;
VIR_FREE(mirror);
- if (qemuDomainObjEndJob(driver, vm) == 0) {
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
- goto cleanup;
- }
cleanup:
VIR_FREE(device);
@@ -14572,10 +14567,8 @@ endjob:
top_parent,
VIR_DISK_CHAIN_READ_ONLY);
}
- if (qemuDomainObjEndJob(driver, vm) == 0) {
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
- goto cleanup;
- }
cleanup:
VIR_FREE(device);
@@ -14641,10 +14634,8 @@ qemuDomainOpenGraphics(virDomainPtr dom,
ret = qemuMonitorOpenGraphics(priv->mon, protocol, fd, "graphicsfd",
(flags & VIR_DOMAIN_OPEN_GRAPHICS_SKIPAUTH) != 0);
qemuDomainObjExitMonitor(driver, vm);
- if (qemuDomainObjEndJob(driver, vm) == 0) {
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
- goto cleanup;
- }
cleanup:
if (vm)
@@ -14956,7 +14947,7 @@ qemuDomainGetBlockIoTune(virDomainPtr dom,
ret = 0;
endjob:
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
@@ -15030,7 +15021,7 @@ qemuDomainGetDiskErrors(virDomainPtr dom,
ret = n;
endjob:
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
@@ -15561,7 +15552,7 @@ qemuDomainPMSuspendForDuration(virDomainPtr dom,
qemuDomainObjExitAgent(vm);
endjob:
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
@@ -15610,7 +15601,7 @@ qemuDomainPMWakeup(virDomainPtr dom,
qemuDomainObjExitMonitor(driver, vm);
endjob:
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
@@ -15696,7 +15687,7 @@ qemuDomainQemuAgentCommand(virDomainPtr domain,
VIR_FREE(result);
endjob:
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
@@ -15766,7 +15757,7 @@ qemuDomainFSTrim(virDomainPtr dom,
qemuDomainObjExitAgent(vm);
endjob:
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
cleanup:
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 3177756..69a9013 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2125,7 +2125,7 @@ endjob:
if (qemuMigrationJobFinish(driver, vm) == 0)
vm = NULL;
} else {
- if (qemuDomainObjEndJob(driver, vm) == 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
}
goto cleanup;
@@ -2334,7 +2334,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
VIR_QEMU_PROCESS_START_PAUSED |
VIR_QEMU_PROCESS_START_AUTODESTROY) < 0) {
virDomainAuditStart(vm, "migrated", false);
- if (qemuDomainObjEndJob(driver, vm) < 0)
+ if (!qemuDomainObjEndJob(driver, vm))
vm = NULL;
goto endjob;
}
--
1.8.3.1
11 years, 2 months
[libvirt] [PATCH] qemu: Fix connectGetType() API
by Michal Novotny
This patch fixes qemuConnectGetType() API function to return KVM if
appropriate, i.e. when /dev/kvm exists as the KVM module is loaded.
No further check is being done so it's merely showing the possibility
that KVM virtualization is available on the host however we don't
have any guest information (as it's connection-only related) so we
cannot sure we can use KVM. This can be useful to identify we have
KVM (Virt Support) available on the host if host and guest archs
are the same.
Testing:
Done using a simple application with C source code below.
[before patch applied]$ ./test
Hypervisor type: QEMU
[after patch applied]$ ./test
Hypervisor type: KVM
$
Testing C code:
int main()
{
virConnectPtr conn = NULL;
conn = virConnectOpen("qemu:///system");
if (!conn)
return 1;
printf("Hypervisor type: %s\n", virConnectGetType(conn));
virConnectClose(conn);
return 0;
}
Compiled on F-17 x86_64 host using: gcc -o test test.c -lvirt
Signed-off-by: Michal Novotny <minovotn(a)redhat.com>
---
src/qemu/qemu_driver.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 9b5d126..b770967 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1132,6 +1132,16 @@ static const char *qemuConnectGetType(virConnectPtr conn ATTRIBUTE_UNUSED) {
if (virConnectGetTypeEnsureACL(conn) < 0)
return NULL;
+ /*
+ * If KVM is available for the host architecture then report KVM support.
+ * This approach merely shows it is possible to have KVM support as module is
+ * loaded however if you select different architecture, e.g. ARM on x86_64 host,
+ * the KVM option will not be available as there is no KVM virtualization
+ * support for ARM architecture that could be running on top of x86_64 host.
+ */
+ if (access("/dev/kvm", F_OK) == 0)
+ return "KVM";
+
return "QEMU";
}
--
1.7.11.7
11 years, 2 months
[libvirt] [PATCH] systemd: add debug message when virDBusCallMethod failed
by Gao feng
Generate debug message when systemd doesn't support
interface org.freedesktop.machine1.Manager.
Signed-off-by: Gao feng <gaofeng(a)cn.fujitsu.com>
---
src/util/virsystemd.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c
index 3e69ef6..c631557 100644
--- a/src/util/virsystemd.c
+++ b/src/util/virsystemd.c
@@ -233,6 +233,7 @@ int virSystemdCreateMachine(const char *name,
if (err->code == VIR_ERR_DBUS_SERVICE &&
STREQ(err->str2, "org.freedesktop.DBus.Error.ServiceUnknown")) {
virResetLastError();
+ VIR_DEBUG("systemd doesn't support interface org.freedesktop.machine1.Manager");
ret = -2;
}
goto cleanup;
--
1.8.3.1
11 years, 2 months
[libvirt] link fow downloading libvirt-0.10.2-19.el6
by arun abhinay
Hi,
In reference to comment28 in below link
https://bugzilla.redhat.com/show_bug.cgi?id=911609#c28
The issue was fixed in libvirt-0.10.2-19.el6 version. I am facing similar
crash and want to check with libvirt-0.10.2-19.el6 version. But i couldnt
find this version from opensource. We could only find below version of
libvirt from http://libvirt.org/sources/
*libvirt-0.10.2-1.fc17.src.rpm 24-Sep-2012 07:32 21M
libvirt-0.10.2-1.fc17.x86_64.rpm 24-Sep-2012 07:32 21K
libvirt-0.10.2.tar.gz 24-Sep-2012 07:53 21M** *
*Can any one please provide me a link from where i can download
libvirt-0.10.2-19.el6 version.*
I am pasting my BT of my core ffor reference below
#0 0x00007f068e9f951b in remoteClientCloseFunc (client=<value optimized
out>, reason=1, opaque=0x2100110)
at remote/remote_driver.c:340
#1 0x00007f068ea1a152 in virNetClientIOHandleOutput (client=0x2100110) at
rpc/virnetclient.c:1200
#2 0x0000000000000009 in ?? ()
#3 0x0000000002100a50 in ?? ()
#4 0x0000000000000002 in ?? ()
#5 0x00007f0684000988 in ?? ()
#6 0x00007f068ea1caa1 in virNetClientIOEventLoop (client=0x2100890,
thiscall=0xc02179369c522bee) at rpc/virnetclient.c:1525
#7 0x0000000000000000 in ?? ()
Thanks
Abhinay
11 years, 2 months
[libvirt] [PATCH 0/4] build: use subdir-objects
by Eric Blake
Automake 1.14 is annoyingly loud about warning that the future
automake 2.0 will turn on subdir-objects by default. Since
automake 1.9 also supports subdir-objects, the best course of
action is to enable the feature. But we have to fix some
problems before doing so. Also, I noticed some issues with .x
files while searching for places that needed fixing.
Eric Blake (4):
build: avoid $(srcdir) in *_SOURCES
build: use library rather than cross-directory compilation
tests: check remaining .x files
build: use automake subdir-objects
.gitignore | 1 +
cfg.mk | 3 +-
configure.ac | 2 +-
daemon/Makefile.am | 55 +++++++++++-----
src/Makefile.am | 139 +++++++++++++++++++++++----------------
src/lock_protocol-structs | 55 ++++++++++++++++
src/lxc_monitor_protocol-structs | 16 +++++
tests/Makefile.am | 4 +-
8 files changed, 198 insertions(+), 77 deletions(-)
create mode 100644 src/lock_protocol-structs
create mode 100644 src/lxc_monitor_protocol-structs
--
1.8.3.1
11 years, 2 months
[libvirt] [PATCH]LXC doc: Add warns if net namespace not enabled
by Chen Hanxiao
From: Chen Hanxiao <chenhanxiao(a)cn.fujitsu.com>
If we don't enable network namespace, we could shutdown host
by executing command 'shutdown' inside container.
This patch will add some warnings in LXC docs and give some
advice to readers.
Signed-off-by: Chen Hanxiao <chenhanxiao(a)cn.fujitsu.com>
---
docs/drvlxc.html.in | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/docs/drvlxc.html.in b/docs/drvlxc.html.in
index 640968f..8f3a36a 100644
--- a/docs/drvlxc.html.in
+++ b/docs/drvlxc.html.in
@@ -50,6 +50,13 @@ processes inside containers cannot be securely isolated from host
process without the use of a mandatory access control technology
such as SELinux or AppArmor.</strong>
</p>
+<p>
+<strong>WARNING: If 'net' namespace <i>not</i> enabled for container,
+host OS could be <i>shutdown</i> by executing command like 'reboot'
+inside container.<br/>So make sure 'net' namespace was available and
+set the <privnet/> feature in the XML, or configure virtual NICs.
+Then this issue could be circumvented.</strong>
+</p>
<h2><a name="init">Default container setup</a></h2>
--
1.7.1
11 years, 2 months
[libvirt] [PATCH] Ensure root filesystem is recursively mounted readonly
by Daniel P. Berrange
From: "Daniel P. Berrange" <berrange(a)redhat.com>
If the guest is configured with
<filesystem type='mount'>
<source dir='/'/>
<target dir='/'/>
<readonly/>
</filesystem>
Then any submounts under / should also end up readonly. eg if
the user has /home on a separate volume, they'd expect /home
to be readonly.
Users can selectively make sub-mounts read-write again by
simply listing them as new mounts without the <readonly>
flag set
<filesystem type='mount'>
<source dir='/home'/>
<target dir='/home'/>
</filesystem>
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
src/lxc/lxc_container.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 73 insertions(+), 2 deletions(-)
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 9c04d06..ae672c8 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -532,7 +532,6 @@ static int lxcContainerGetSubtree(const char *prefix,
}
while (getmntent_r(procmnt, &mntent, mntbuf, sizeof(mntbuf)) != NULL) {
- VIR_DEBUG("Got %s", mntent.mnt_dir);
if (!STRPREFIX(mntent.mnt_dir, prefix))
continue;
@@ -541,7 +540,6 @@ static int lxcContainerGetSubtree(const char *prefix,
if (VIR_STRDUP(mounts[nmounts], mntent.mnt_dir) < 0)
goto cleanup;
nmounts++;
- VIR_DEBUG("Grabbed %s", mntent.mnt_dir);
}
if (mounts)
@@ -750,6 +748,61 @@ err:
}
+static int lxcContainerSetReadOnly(virDomainFSDefPtr root)
+{
+ FILE *procmnt;
+ struct mntent mntent;
+ char mntbuf[1024];
+ int ret = -1;
+ char **mounts = NULL;
+ size_t nmounts = 0;
+ size_t i;
+
+ VIR_DEBUG("root=%s", root->src);
+
+ if (!(procmnt = setmntent("/proc/mounts", "r"))) {
+ virReportSystemError(errno, "%s",
+ _("Failed to read /proc/mounts"));
+ return -1;
+ }
+
+ while (getmntent_r(procmnt, &mntent, mntbuf, sizeof(mntbuf)) != NULL) {
+ if (STREQ(mntent.mnt_dir, "/") ||
+ STRPREFIX(mntent.mnt_dir, "/.oldroot"))
+ continue;
+
+ if (VIR_REALLOC_N(mounts, nmounts+1) < 0)
+ goto cleanup;
+ if (VIR_STRDUP(mounts[nmounts], mntent.mnt_dir) < 0)
+ goto cleanup;
+ nmounts++;
+ }
+
+ if (mounts)
+ qsort(mounts, nmounts, sizeof(mounts[0]),
+ lxcContainerChildMountSort);
+
+ for (i = 0 ; i < nmounts ; i++) {
+ VIR_DEBUG("Bind readonly %s", mounts[i]);
+ if (mount(mounts[i], mounts[i], NULL, MS_BIND|MS_REC|MS_RDONLY|MS_REMOUNT, NULL) < 0) {
+ virReportSystemError(errno,
+ _("Failed to make mount %s readonly"),
+ mounts[i]);
+ goto cleanup;
+ }
+ }
+
+ ret = 0;
+cleanup:
+ for (i = 0; i < nmounts; i++)
+ VIR_FREE(mounts[i]);
+ VIR_FREE(mounts);
+ endmntent(procmnt);
+ return ret;
+
+}
+
+
static int lxcContainerMountBasicFS(bool userns_enabled)
{
const struct {
@@ -1001,6 +1054,8 @@ static int lxcContainerMountFSBind(virDomainFSDefPtr fs,
int ret = -1;
struct stat st;
+ VIR_DEBUG("src=%s dst=%s", fs->src, fs->dst);
+
if (virAsprintf(&src, "%s%s", srcprefix, fs->src) < 0)
goto cleanup;
@@ -1057,6 +1112,13 @@ static int lxcContainerMountFSBind(virDomainFSDefPtr fs,
_("Failed to make directory %s readonly"),
fs->dst);
}
+ } else {
+ VIR_DEBUG("Binding %s readwrite", fs->dst);
+ if (mount(src, fs->dst, NULL, MS_BIND|MS_REMOUNT, NULL) < 0) {
+ virReportSystemError(errno,
+ _("Failed to make directory %s readwrite"),
+ fs->dst);
+ }
}
ret = 0;
@@ -1330,6 +1392,8 @@ static int lxcContainerMountFSBlock(virDomainFSDefPtr fs,
char *src = NULL;
int ret = -1;
+ VIR_DEBUG("src=%s dst=%s", fs->src, fs->dst);
+
if (virAsprintf(&src, "%s%s", srcprefix, fs->src) < 0)
goto cleanup;
@@ -1349,6 +1413,8 @@ static int lxcContainerMountFSTmpfs(virDomainFSDefPtr fs,
int ret = -1;
char *data = NULL;
+ VIR_DEBUG("usage=%lld sec=%s", fs->usage, sec_mount_options);
+
if (virAsprintf(&data,
"size=%lldk%s", fs->usage, sec_mount_options) < 0)
goto cleanup;
@@ -1536,6 +1602,11 @@ static int lxcContainerSetupPivotRoot(virDomainDefPtr vmDef,
if (lxcContainerMountBasicFS(vmDef->idmap.nuidmap) < 0)
goto cleanup;
+ /* Ensure entire root filesystem (except /.oldroot) is readonly */
+ if (root->readonly &&
+ lxcContainerSetReadOnly(root) < 0)
+ goto cleanup;
+
/* Mounts /proc/meminfo etc sysinfo */
if (lxcContainerMountProcFuse(vmDef, stateDir) < 0)
goto cleanup;
--
1.8.3.1
11 years, 2 months
[libvirt] [PATCH libvirt-sandbox] include <locale.h> where needed.
by Ian Main
For some reason this does not build out of the box for me as I get
errors about 'setlocale()' being used without declaration. This patch
adds the appropriate header to the appropriate files.
Signed-off-by: Ian Main <imain(a)redhat.com>
---
bin/virt-sandbox-service-util.c | 1 +
bin/virt-sandbox.c | 1 +
libvirt-sandbox/libvirt-sandbox-init-common.c | 1 +
3 files changed, 3 insertions(+)
diff --git a/bin/virt-sandbox-service-util.c b/bin/virt-sandbox-service-util.c
index 83ff17c..c7757fd 100644
--- a/bin/virt-sandbox-service-util.c
+++ b/bin/virt-sandbox-service-util.c
@@ -25,6 +25,7 @@
#include <libvirt-sandbox/libvirt-sandbox.h>
#include <glib/gi18n.h>
+#include <locale.h>
#define STREQ(x,y) (strcmp(x,y) == 0)
diff --git a/bin/virt-sandbox.c b/bin/virt-sandbox.c
index b16217b..b9d6825 100644
--- a/bin/virt-sandbox.c
+++ b/bin/virt-sandbox.c
@@ -24,6 +24,7 @@
#include <libvirt-sandbox/libvirt-sandbox.h>
#include <glib/gi18n.h>
+#include <locale.h>
static gboolean do_close(GVirSandboxConsole *con G_GNUC_UNUSED,
gboolean error G_GNUC_UNUSED,
diff --git a/libvirt-sandbox/libvirt-sandbox-init-common.c b/libvirt-sandbox/libvirt-sandbox-init-common.c
index 262f4e1..d3c21c2 100644
--- a/libvirt-sandbox/libvirt-sandbox-init-common.c
+++ b/libvirt-sandbox/libvirt-sandbox-init-common.c
@@ -44,6 +44,7 @@
#include <unistd.h>
#include <limits.h>
#include <grp.h>
+#include <locale.h>
#include "libvirt-sandbox-rpcpacket.h"
--
1.8.1.4
11 years, 2 months