Signed-off-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
src/qemu/qemu_conf.c | 41 ++++++++++++++++++++++++++---------------
src/qemu/qemu_conf.h | 3 ++-
src/qemu/qemu_driver.c | 2 +-
3 files changed, 29 insertions(+), 17 deletions(-)
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index daea11dacb..35ecb19b29 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -123,7 +123,8 @@ void qemuDomainCmdlineDefFree(qemuDomainCmdlineDefPtr def)
#endif
-virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged)
+virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged,
+ const char *root)
{
virQEMUDriverConfigPtr cfg;
@@ -150,30 +151,31 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged)
if (privileged) {
if (virAsprintf(&cfg->logDir,
- "%s/log/libvirt/qemu", LOCALSTATEDIR) < 0)
+ "%s%s/log/libvirt/qemu", root, LOCALSTATEDIR) < 0)
goto error;
if (virAsprintf(&cfg->swtpmLogDir,
- "%s/log/swtpm/libvirt/qemu", LOCALSTATEDIR) < 0)
+ "%s%s/log/swtpm/libvirt/qemu", root, LOCALSTATEDIR)
< 0)
goto error;
- if (VIR_STRDUP(cfg->configBaseDir, SYSCONFDIR "/libvirt") < 0)
+ if (virAsprintf(&cfg->configBaseDir,
+ "%s%s/libvirt", root, SYSCONFDIR) < 0)
goto error;
if (virAsprintf(&cfg->stateDir,
- "%s/run/libvirt/qemu", LOCALSTATEDIR) < 0)
+ "%s%s/run/libvirt/qemu", root, LOCALSTATEDIR) < 0)
goto error;
if (virAsprintf(&cfg->swtpmStateDir,
- "%s/run/libvirt/qemu/swtpm", LOCALSTATEDIR) < 0)
+ "%s%s/run/libvirt/qemu/swtpm", root, LOCALSTATEDIR)
< 0)
goto error;
if (virAsprintf(&cfg->cacheDir,
- "%s/cache/libvirt/qemu", LOCALSTATEDIR) < 0)
+ "%s%s/cache/libvirt/qemu", root, LOCALSTATEDIR) <
0)
goto error;
if (virAsprintf(&cfg->libDir,
- "%s/lib/libvirt/qemu", LOCALSTATEDIR) < 0)
+ "%s%s/lib/libvirt/qemu", root, LOCALSTATEDIR) < 0)
goto error;
if (virAsprintf(&cfg->saveDir, "%s/save", cfg->libDir) <
0)
goto error;
@@ -188,8 +190,8 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged)
goto error;
if (virAsprintf(&cfg->memoryBackingDir, "%s/ram",
cfg->libDir) < 0)
goto error;
- if (virAsprintf(&cfg->swtpmStorageDir, "%s/lib/libvirt/swtpm",
- LOCALSTATEDIR) < 0)
+ if (virAsprintf(&cfg->swtpmStorageDir,
"%s%s/lib/libvirt/swtpm",
+ root, LOCALSTATEDIR) < 0)
goto error;
if (!virDoesUserExist("tss") ||
virGetUserID("tss", &cfg->swtpm_user) < 0)
@@ -200,22 +202,23 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged)
} else {
char *rundir;
char *cachedir;
+ char *cfgdir;
cachedir = virGetUserCacheDirectory();
if (!cachedir)
goto error;
if (virAsprintf(&cfg->logDir,
- "%s/qemu/log", cachedir) < 0) {
+ "%s%s/qemu/log", root, cachedir) < 0) {
VIR_FREE(cachedir);
goto error;
}
if (virAsprintf(&cfg->swtpmLogDir,
- "%s/qemu/log", cachedir) < 0) {
+ "%s%s/qemu/log", root, cachedir) < 0) {
VIR_FREE(cachedir);
goto error;
}
- if (virAsprintf(&cfg->cacheDir, "%s/qemu/cache", cachedir) <
0) {
+ if (virAsprintf(&cfg->cacheDir, "%s%s/qemu/cache", root,
cachedir) < 0) {
VIR_FREE(cachedir);
goto error;
}
@@ -224,7 +227,7 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged)
rundir = virGetUserRuntimeDirectory();
if (!rundir)
goto error;
- if (virAsprintf(&cfg->stateDir, "%s/qemu/run", rundir) < 0)
{
+ if (virAsprintf(&cfg->stateDir, "%s%s/qemu/run", root, rundir)
< 0) {
VIR_FREE(rundir);
goto error;
}
@@ -233,9 +236,16 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged)
if (virAsprintf(&cfg->swtpmStateDir, "%s/swtpm",
cfg->stateDir) < 0)
goto error;
- if (!(cfg->configBaseDir = virGetUserConfigDirectory()))
+ cfgdir = virGetUserConfigDirectory();
+ if (!cfgdir)
goto error;
+ if (virAsprintf(&cfg->configBaseDir, "%s%s", root, cfgdir) <
0) {
+ VIR_FREE(cfgdir);
+ goto error;
+ }
+ VIR_FREE(cfgdir);
+
if (virAsprintf(&cfg->libDir, "%s/qemu/lib",
cfg->configBaseDir) < 0)
goto error;
if (virAsprintf(&cfg->saveDir, "%s/qemu/save",
cfg->configBaseDir) < 0)
@@ -267,6 +277,7 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged)
* This will then be used as a fallback if the service specific
* directory doesn't exist (although we don't check if this exists).
*/
+ // XXX root ?
if (VIR_STRDUP(cfg->defaultTLSx509certdir,
SYSCONFDIR "/pki/qemu") < 0)
goto error;
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index 983e74a3cf..f93b09c4fe 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -312,7 +312,8 @@ struct _qemuDomainCmdlineDef {
void qemuDomainCmdlineDefFree(qemuDomainCmdlineDefPtr def);
-virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged);
+virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged,
+ const char *root);
int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
const char *filename,
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 659d7b89e1..019f6b2bf3 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -613,7 +613,7 @@ qemuStateInitialize(bool privileged,
if (privileged)
qemu_driver->hostsysinfo = virSysinfoRead();
- if (!(qemu_driver->config = cfg = virQEMUDriverConfigNew(privileged)))
+ if (!(qemu_driver->config = cfg = virQEMUDriverConfigNew(privileged, root)))
goto error;
if (virAsprintf(&driverConf, "%s/qemu.conf", cfg->configBaseDir)
< 0)
--
2.21.0