[libvirt] [PATCH] lxc: create the required directories upon driver start

/var/run may reside on a tmpfs and we fail to create the PID file if /var/run/lxc does not exist. Other drivers (well, BHYVE) seem to do the same thing. Signed-off-by: Lubomir Rintel <lkundrak@v3.sk> --- src/lxc/lxc_driver.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 245000d..4363898 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -1648,6 +1648,20 @@ static int lxcStateInitialize(bool privileged, if (!(caps = virLXCDriverGetCapabilities(lxc_driver, false))) goto cleanup; + if (virFileMakePath(LXC_LOG_DIR) < 0) { + virReportSystemError(errno, + _("Failed to mkdir %s"), + LXC_LOG_DIR); + goto cleanup; + } + + if (virFileMakePath(LXC_STATE_DIR) < 0) { + virReportSystemError(errno, + _("Failed to mkdir %s"), + LXC_STATE_DIR); + goto cleanup; + } + /* Get all the running persistent or transient configs first */ if (virDomainObjListLoadAllConfigs(lxc_driver->domains, cfg->stateDir, -- 2.1.0

Hello Lubomir On Tue, 2015-04-07 at 15:37 +0200, Lubomir Rintel wrote:
/var/run may reside on a tmpfs and we fail to create the PID file if /var/run/lxc does not exist.
Just mentioning the fact that this folder may not exist is OK. We have the same problem right after the libvirt installation too when creating an lxc domain.
Other drivers (well, BHYVE) seem to do the same thing.
Signed-off-by: Lubomir Rintel <lkundrak@v3.sk> --- src/lxc/lxc_driver.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 245000d..4363898 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -1648,6 +1648,20 @@ static int lxcStateInitialize(bool privileged, if (!(caps = virLXCDriverGetCapabilities(lxc_driver, false))) goto cleanup;
+ if (virFileMakePath(LXC_LOG_DIR) < 0) { + virReportSystemError(errno, + _("Failed to mkdir %s"), + LXC_LOG_DIR); + goto cleanup; + }
Isn't that one automatically created so far?
+ + if (virFileMakePath(LXC_STATE_DIR) < 0) {
I'ld rather use lxc_driver->config->stateDir instead LXC_STATE_DIR. I wrote a patch for that this morning and was about to email it ;) -- Cedric
+ virReportSystemError(errno, + _("Failed to mkdir %s"), + LXC_STATE_DIR); + goto cleanup; + } + /* Get all the running persistent or transient configs first */ if (virDomainObjListLoadAllConfigs(lxc_driver->domains, cfg->stateDir,

Hi Cedric, On Tue, 2015-04-07 at 16:18 +0200, Cedric Bosdonnat wrote:
Hello Lubomir
On Tue, 2015-04-07 at 15:37 +0200, Lubomir Rintel wrote:
/var/run may reside on a tmpfs and we fail to create the PID file if /var/run/lxc does not exist.
Just mentioning the fact that this folder may not exist is OK. We have the same problem right after the libvirt installation too when creating an lxc domain.
Other drivers (well, BHYVE) seem to do the same thing.
Signed-off-by: Lubomir Rintel <lkundrak@v3.sk> --- src/lxc/lxc_driver.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 245000d..4363898 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -1648,6 +1648,20 @@ static int lxcStateInitialize(bool privileged, if (!(caps = virLXCDriverGetCapabilities(lxc_driver, false))) goto cleanup;
+ if (virFileMakePath(LXC_LOG_DIR) < 0) { + virReportSystemError(errno, + _("Failed to mkdir %s"), + LXC_LOG_DIR); + goto cleanup; + }
Isn't that one automatically created so far?
Not sure really. I didn't run into any problems with this one, just noticed that BYHIVE creates it upon start and I didn't see LXC doing that...
+ + if (virFileMakePath(LXC_STATE_DIR) < 0) {
I'ld rather use lxc_driver->config->stateDir instead LXC_STATE_DIR. I wrote a patch for that this morning and was about to email it ;)
Well, I don't really know. I was thinking that maybe virPidFileWritePath() should create the path when needed, analogously to virPidFileWrite(), but creating it on start seemed a bit more consostent and less laborous. I don't feel strongly either way; feel free to send your patch instead of this one. Thanks, Lubo

On Tue, Apr 07, 2015 at 04:29:42PM +0200, Lubomir Rintel wrote:
Hi Cedric,
On Tue, 2015-04-07 at 16:18 +0200, Cedric Bosdonnat wrote:
Hello Lubomir
On Tue, 2015-04-07 at 15:37 +0200, Lubomir Rintel wrote:
/var/run may reside on a tmpfs and we fail to create the PID file if /var/run/lxc does not exist.
Just mentioning the fact that this folder may not exist is OK. We have the same problem right after the libvirt installation too when creating an lxc domain.
Other drivers (well, BHYVE) seem to do the same thing.
Signed-off-by: Lubomir Rintel <lkundrak@v3.sk> --- src/lxc/lxc_driver.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 245000d..4363898 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -1648,6 +1648,20 @@ static int lxcStateInitialize(bool privileged, if (!(caps = virLXCDriverGetCapabilities(lxc_driver, false))) goto cleanup;
+ if (virFileMakePath(LXC_LOG_DIR) < 0) { + virReportSystemError(errno, + _("Failed to mkdir %s"), + LXC_LOG_DIR); + goto cleanup; + }
Isn't that one automatically created so far?
Yes, logDir is created by lxcProcessStart
Not sure really. I didn't run into any problems with this one, just noticed that BYHIVE creates it upon start and I didn't see LXC doing that...
+ + if (virFileMakePath(LXC_STATE_DIR) < 0) {
I'ld rather use lxc_driver->config->stateDir instead LXC_STATE_DIR. I wrote a patch for that this morning and was about to email it ;)
And using cfg->stateDir is nicer, even though LXC domains can be only started by a privileged daemon so it's always filled with the compiled-in value.
Well, I don't really know.
I was thinking that maybe virPidFileWritePath() should create the path when needed, analogously to virPidFileWrite(), but creating it on start seemed a bit more consostent and less laborous.
Oddly enough, virDomainSaveState does auto-create the directory, but we can only get there after we've successfully run a domain. Jan

/var/run may reside on a tmpfs and we fail to create the PID file if /var/run/lxc does not exist. [cbosdonnat@suse.com: use cfg->stateDir instead of LXC_STATE_DIR] Signed-off-by: Lubomir Rintel <lkundrak@v3.sk> --- src/lxc/lxc_driver.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 245000d..8dfa686 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -1648,6 +1648,13 @@ static int lxcStateInitialize(bool privileged, if (!(caps = virLXCDriverGetCapabilities(lxc_driver, false))) goto cleanup; + if (virFileMakePath(cfg->stateDir) < 0) { + virReportSystemError(errno, + _("Failed to mkdir %s"), + cfg->stateDir); + goto cleanup; + } + /* Get all the running persistent or transient configs first */ if (virDomainObjListLoadAllConfigs(lxc_driver->domains, cfg->stateDir, -- 2.1.0

Hi Lubomir, On Wed, 2015-04-08 at 19:16 +0200, Lubomir Rintel wrote:
/var/run may reside on a tmpfs and we fail to create the PID file if /var/run/lxc does not exist.
I would enhance the commit message with something like this: Since commit 0a8addc1, the lxc driver's state directory isn't automatically created before starting a domain. Now, the lxc driver makes sure the state directory exists when it initializes.
[cbosdonnat@suse.com: use cfg->stateDir instead of LXC_STATE_DIR]
This line shouldn't be in the commit message: see my other comment.
Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
You don't have to sign-off your patches.
---
The changes with the previous version should go here: this way they won't appear in the git commit message. I'll push your patch with those changes. Thanks for your help. -- Cedric
src/lxc/lxc_driver.c | 7 +++++++ 1 file changed, 7 insertions(+)
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 245000d..8dfa686 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -1648,6 +1648,13 @@ static int lxcStateInitialize(bool privileged, if (!(caps = virLXCDriverGetCapabilities(lxc_driver, false))) goto cleanup;
+ if (virFileMakePath(cfg->stateDir) < 0) { + virReportSystemError(errno, + _("Failed to mkdir %s"), + cfg->stateDir); + goto cleanup; + } + /* Get all the running persistent or transient configs first */ if (virDomainObjListLoadAllConfigs(lxc_driver->domains, cfg->stateDir,
participants (3)
-
Cedric Bosdonnat
-
Ján Tomko
-
Lubomir Rintel