[libvirt] [PATCH 0/2] Make managed-save path configurable

Some users/sysadmins don't really create big partition for / or /var; Therefore number of domains that can be managed-save is limited to only a few because we simply run out of free space. Yes, one can override the path at compile time, but it's sort of overkill. Having said that, I think this is nice to have feature. We can make more paths configurable if this gains enough fame. Michal Privoznik (2): qemu_conf: Move paths initialization to qemudLoadDriverConfig qemu_conf: Allow overriding of path for managed-save src/qemu/qemu.conf | 7 +++ src/qemu/qemu_conf.c | 60 ++++++++++++++++++++++++++++- src/qemu/qemu_conf.h | 4 +- src/qemu/qemu_driver.c | 101 ++++++++++++++---------------------------------- 4 files changed, 98 insertions(+), 74 deletions(-) -- 1.7.3.4

This is needed as next patch allows their modification via qemu.conf. --- src/qemu/qemu_conf.c | 51 ++++++++++++++++++++++++- src/qemu/qemu_conf.h | 4 +- src/qemu/qemu_driver.c | 101 ++++++++++++++---------------------------------- 3 files changed, 82 insertions(+), 74 deletions(-) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index e95c7a5..a22f3c7 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -67,7 +67,9 @@ void qemuDriverUnlock(struct qemud_driver *driver) int qemudLoadDriverConfig(struct qemud_driver *driver, - const char *filename) { + const char *filename, + const char *userdir, + const char *base) { virConfPtr conf; virConfValuePtr p; char *user; @@ -486,6 +488,53 @@ int qemudLoadDriverConfig(struct qemud_driver *driver, CHECK_TYPE("keepalive_count", VIR_CONF_LONG); if (p) driver->keepAliveCount = p->l; + + if (driver->privileged) { + if (virAsprintf(&driver->logDir, + "%s/log/libvirt/qemu", LOCALSTATEDIR) == -1) + goto out_of_memory; + + if (virAsprintf(&driver->stateDir, + "%s/run/libvirt/qemu", LOCALSTATEDIR) == -1) + goto out_of_memory; + + if (virAsprintf(&driver->libDir, + "%s/lib/libvirt/qemu", LOCALSTATEDIR) == -1) + goto out_of_memory; + + if (virAsprintf(&driver->cacheDir, + "%s/cache/libvirt/qemu", LOCALSTATEDIR) == -1) + goto out_of_memory; + if (virAsprintf(&driver->saveDir, + "%s/lib/libvirt/qemu/save", LOCALSTATEDIR) == -1) + goto out_of_memory; + if (virAsprintf(&driver->snapshotDir, + "%s/lib/libvirt/qemu/snapshot", LOCALSTATEDIR) == -1) + goto out_of_memory; + if (virAsprintf(&driver->autoDumpPath, + "%s/lib/libvirt/qemu/dump", LOCALSTATEDIR) == -1) + goto out_of_memory; + } else { + if (virAsprintf(&driver->logDir, + "%s/.libvirt/qemu/log", userdir) == -1) + goto out_of_memory; + if (virAsprintf(&driver->stateDir, "%s/qemu/run", base) == -1) + goto out_of_memory; + if (virAsprintf(&driver->libDir, "%s/qemu/lib", base) == -1) + goto out_of_memory; + if (virAsprintf(&driver->cacheDir, "%s/qemu/cache", base) == -1) + goto out_of_memory; + if (virAsprintf(&driver->saveDir, "%s/qemu/save", base) == -1) + goto out_of_memory; + if (virAsprintf(&driver->snapshotDir, "%s/qemu/snapshot", base) == -1) + goto out_of_memory; + if (virAsprintf(&driver->autoDumpPath, "%s/qemu/dump", base) == -1) + goto out_of_memory; + } virConfFree (conf); return 0; + +out_of_memory: + virReportOOMError(); + return -1; } diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 36f1c4c..186404b 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -171,7 +171,9 @@ struct _qemuDomainCmdlineDef { void qemuDriverLock(struct qemud_driver *driver); void qemuDriverUnlock(struct qemud_driver *driver); int qemudLoadDriverConfig(struct qemud_driver *driver, - const char *filename); + const char *filename, + const char *userdir, + const char *base); struct qemuDomainDiskInfo { bool removable; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index c6bdd29..7e11d15 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -420,6 +420,7 @@ cleanup: static int qemudStartup(int privileged) { char *base = NULL; + char *userdir = NULL; char *driverConf = NULL; int rc; virConnectPtr conn = NULL; @@ -451,70 +452,47 @@ qemudStartup(int privileged) { virBitmapAlloc(QEMU_VNC_PORT_MAX - QEMU_VNC_PORT_MIN)) == NULL) goto out_of_memory; - /* read the host sysinfo */ - if (privileged) - qemu_driver->hostsysinfo = virSysinfoRead(); - + /* Configuration paths are either ~/.libvirt/qemu/... (session) or + * /etc/libvirt/qemu/... (system). + */ if (privileged) { - if (virAsprintf(&qemu_driver->logDir, - "%s/log/libvirt/qemu", LOCALSTATEDIR) == -1) - goto out_of_memory; - if ((base = strdup (SYSCONFDIR "/libvirt")) == NULL) goto out_of_memory; - - if (virAsprintf(&qemu_driver->stateDir, - "%s/run/libvirt/qemu", LOCALSTATEDIR) == -1) - goto out_of_memory; - - if (virAsprintf(&qemu_driver->libDir, - "%s/lib/libvirt/qemu", LOCALSTATEDIR) == -1) - goto out_of_memory; - - if (virAsprintf(&qemu_driver->cacheDir, - "%s/cache/libvirt/qemu", LOCALSTATEDIR) == -1) - goto out_of_memory; - if (virAsprintf(&qemu_driver->saveDir, - "%s/lib/libvirt/qemu/save", LOCALSTATEDIR) == -1) - goto out_of_memory; - if (virAsprintf(&qemu_driver->snapshotDir, - "%s/lib/libvirt/qemu/snapshot", LOCALSTATEDIR) == -1) - goto out_of_memory; - if (virAsprintf(&qemu_driver->autoDumpPath, - "%s/lib/libvirt/qemu/dump", LOCALSTATEDIR) == -1) - goto out_of_memory; } else { uid_t uid = geteuid(); - char *userdir = virGetUserDirectory(uid); + userdir = virGetUserDirectory(uid); if (!userdir) goto error; - if (virAsprintf(&qemu_driver->logDir, - "%s/.libvirt/qemu/log", userdir) == -1) { - VIR_FREE(userdir); - goto out_of_memory; - } - if (virAsprintf(&base, "%s/.libvirt", userdir) == -1) { VIR_FREE(userdir); goto out_of_memory; } - VIR_FREE(userdir); - - if (virAsprintf(&qemu_driver->stateDir, "%s/qemu/run", base) == -1) - goto out_of_memory; - if (virAsprintf(&qemu_driver->libDir, "%s/qemu/lib", base) == -1) - goto out_of_memory; - if (virAsprintf(&qemu_driver->cacheDir, "%s/qemu/cache", base) == -1) - goto out_of_memory; - if (virAsprintf(&qemu_driver->saveDir, "%s/qemu/save", base) == -1) - goto out_of_memory; - if (virAsprintf(&qemu_driver->snapshotDir, "%s/qemu/snapshot", base) == -1) - goto out_of_memory; - if (virAsprintf(&qemu_driver->autoDumpPath, "%s/qemu/dump", base) == -1) - goto out_of_memory; } + if (virAsprintf(&driverConf, "%s/qemu.conf", base) < 0 || + virAsprintf(&qemu_driver->configDir, "%s/qemu", base) < 0 || + virAsprintf(&qemu_driver->autostartDir, "%s/qemu/autostart", base) < 0) + goto out_of_memory; + + rc = virCgroupForDriver("qemu", &qemu_driver->cgroup, privileged, 1); + if (rc < 0) { + char buf[1024]; + VIR_INFO("Unable to create cgroup for driver: %s", + virStrerror(-rc, buf, sizeof(buf))); + } + + if (qemudLoadDriverConfig(qemu_driver, driverConf, userdir, base) < 0) { + goto error; + } + VIR_FREE(base); + VIR_FREE(userdir); + VIR_FREE(driverConf); + + /* read the host sysinfo */ + if (privileged) + qemu_driver->hostsysinfo = virSysinfoRead(); + if (virFileMakePath(qemu_driver->stateDir) < 0) { char ebuf[1024]; VIR_ERROR(_("Failed to create state dir '%s': %s"), @@ -552,28 +530,6 @@ qemudStartup(int privileged) { goto error; } - /* Configuration paths are either ~/.libvirt/qemu/... (session) or - * /etc/libvirt/qemu/... (system). - */ - if (virAsprintf(&driverConf, "%s/qemu.conf", base) < 0 || - virAsprintf(&qemu_driver->configDir, "%s/qemu", base) < 0 || - virAsprintf(&qemu_driver->autostartDir, "%s/qemu/autostart", base) < 0) - goto out_of_memory; - - VIR_FREE(base); - - rc = virCgroupForDriver("qemu", &qemu_driver->cgroup, privileged, 1); - if (rc < 0) { - char buf[1024]; - VIR_INFO("Unable to create cgroup for driver: %s", - virStrerror(-rc, buf, sizeof(buf))); - } - - if (qemudLoadDriverConfig(qemu_driver, driverConf) < 0) { - goto error; - } - VIR_FREE(driverConf); - /* We should always at least have the 'nop' manager, so * NULLs here are a fatal error */ @@ -708,6 +664,7 @@ error: if (conn) virConnectClose(conn); VIR_FREE(base); + VIR_FREE(userdir); VIR_FREE(driverConf); qemudShutdown(); return -1; -- 1.7.3.4

This patch allows users to set different path for managed-save images than under /var/lib/libvirt/qemu/save; Some sysadmins do have small / and thus /var but don't want to compile libvirt on their own just to override this path. --- src/qemu/qemu.conf | 7 +++++++ src/qemu/qemu_conf.c | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu.conf b/src/qemu/qemu.conf index 95428c1..ae634ef 100644 --- a/src/qemu/qemu.conf +++ b/src/qemu/qemu.conf @@ -350,3 +350,10 @@ # #keepalive_interval = 5 #keepalive_count = 5 + +################################################################### +# Configurable paths: +# This allows user to override some paths libvirt uses for storing +# files like managed-save, etc. +# +# managed_save_dir = "/var/lib/libvirt/qemu/save/" diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index a22f3c7..0b06ef2 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -505,9 +505,18 @@ int qemudLoadDriverConfig(struct qemud_driver *driver, if (virAsprintf(&driver->cacheDir, "%s/cache/libvirt/qemu", LOCALSTATEDIR) == -1) goto out_of_memory; - if (virAsprintf(&driver->saveDir, - "%s/lib/libvirt/qemu/save", LOCALSTATEDIR) == -1) - goto out_of_memory; + + p = virConfGetValue (conf, "managed_save_dir"); + CHECK_TYPE ("managed_save_dir", VIR_CONF_STRING); + if (p && p->str) { + if (!(driver->saveDir = strdup(p->str))) + goto out_of_memory; + } else { + if (virAsprintf(&driver->saveDir, + "%s/lib/libvirt/qemu/save", LOCALSTATEDIR) == -1) + goto out_of_memory; + } + if (virAsprintf(&driver->snapshotDir, "%s/lib/libvirt/qemu/snapshot", LOCALSTATEDIR) == -1) goto out_of_memory; -- 1.7.3.4

On 03/01/2012 07:54 AM, Michal Privoznik wrote:
This patch allows users to set different path for managed-save images than under /var/lib/libvirt/qemu/save; Some sysadmins do have small / and thus /var but don't want to compile libvirt on their own just to override this path.
I agree with Dan; sysadmins are better off working around this by adding mount points. We already document at http://libvirt.org/locking.html that /var/lib/libvirt/sanlock should be a mount point; perhaps what we really need is a single documentation page describing all of the recommended mount points that an administrator should consider setting up (/var/lib/libvirt/sanlock for locking, /var/lib/libvirt/qemu/save for managed save, /var/lib/libvirt/image for images, ...). -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On Thu, Mar 01, 2012 at 03:54:49PM +0100, Michal Privoznik wrote:
Some users/sysadmins don't really create big partition for / or /var; Therefore number of domains that can be managed-save is limited to only a few because we simply run out of free space. Yes, one can override the path at compile time, but it's sort of overkill.
You can easily do it at runtime too # mount --bind /big/data /var/lib/libvirt/qemu/save which IMHO is preferrable to actually changing locations, because you then still find everything in its normal place. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
participants (3)
-
Daniel P. Berrange
-
Eric Blake
-
Michal Privoznik