qemu: Build nvram directory at driver startup

Similar to what was done for the channel socket in the previous commit.

(cherry picked from commit 19425d110b)
This commit is contained in:
Cole Robinson 2015-04-23 20:01:05 -04:00
parent 9ed89d783b
commit ab87fb1cbc
6 changed files with 21 additions and 5 deletions

View File

@ -1961,7 +1961,6 @@ exit 0
%dir %attr(0700, root, root) %{_localstatedir}/log/libvirt/qemu/
%ghost %dir %attr(0700, root, root) %{_localstatedir}/run/libvirt/qemu/
%dir %attr(0750, %{qemu_user}, %{qemu_group}) %{_localstatedir}/lib/libvirt/qemu/
%dir %attr(0711, %{qemu_user}, %{qemu_group}) %{_localstatedir}/lib/libvirt/qemu/nvram/
%dir %attr(0750, %{qemu_user}, %{qemu_group}) %{_localstatedir}/cache/libvirt/qemu/
%{_datadir}/augeas/lenses/libvirtd_qemu.aug
%{_datadir}/augeas/lenses/tests/test_libvirtd_qemu.aug
@ -2062,7 +2061,6 @@ exit 0
%config(noreplace) %{_sysconfdir}/logrotate.d/libvirtd.qemu
%ghost %dir %attr(0700, root, root) %{_localstatedir}/run/libvirt/qemu/
%dir %attr(0750, %{qemu_user}, %{qemu_group}) %{_localstatedir}/lib/libvirt/qemu/
%dir %attr(0711, %{qemu_user}, %{qemu_group}) %{_localstatedir}/lib/libvirt/qemu/nvram/
%dir %attr(0750, %{qemu_user}, %{qemu_group}) %{_localstatedir}/cache/libvirt/qemu/
%{_datadir}/augeas/lenses/libvirtd_qemu.aug
%{_datadir}/augeas/lenses/tests/test_libvirtd_qemu.aug

View File

@ -2685,7 +2685,6 @@ if WITH_SANLOCK
endif WITH_SANLOCK
if WITH_QEMU
$(MKDIR_P) "$(DESTDIR)$(localstatedir)/lib/libvirt/qemu"
$(MKDIR_P) "$(DESTDIR)$(localstatedir)/lib/libvirt/qemu/nvram"
$(MKDIR_P) "$(DESTDIR)$(localstatedir)/run/libvirt/qemu"
$(MKDIR_P) "$(DESTDIR)$(localstatedir)/cache/libvirt/qemu"
$(MKDIR_P) "$(DESTDIR)$(localstatedir)/log/libvirt/qemu"

View File

@ -208,6 +208,8 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged)
if (virAsprintf(&cfg->channelTargetDir,
"%s/channel/target", cfg->libDir) < 0)
goto error;
if (virAsprintf(&cfg->nvramDir, "%s/nvram", cfg->libDir) < 0)
goto error;
} else {
char *rundir;
char *cachedir;
@ -250,6 +252,9 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged)
if (virAsprintf(&cfg->channelTargetDir,
"%s/qemu/channel/target", cfg->configBaseDir) < 0)
goto error;
if (virAsprintf(&cfg->nvramDir,
"%s/qemu/nvram", cfg->configBaseDir) < 0)
goto error;
}
if (virAsprintf(&cfg->configDir, "%s/qemu", cfg->configBaseDir) < 0)
@ -349,6 +354,7 @@ static void virQEMUDriverConfigDispose(void *obj)
VIR_FREE(cfg->saveDir);
VIR_FREE(cfg->snapshotDir);
VIR_FREE(cfg->channelTargetDir);
VIR_FREE(cfg->nvramDir);
VIR_FREE(cfg->vncTLSx509certdir);
VIR_FREE(cfg->vncListen);

View File

@ -105,6 +105,7 @@ struct _virQEMUDriverConfig {
char *saveDir;
char *snapshotDir;
char *channelTargetDir;
char *nvramDir;
bool vncAutoUnixSocket;
bool vncTLS;

View File

@ -709,6 +709,11 @@ qemuStateInitialize(bool privileged,
virStrerror(errno, ebuf, sizeof(ebuf)));
goto error;
}
if (virFileMakePath(cfg->nvramDir) < 0) {
VIR_ERROR(_("Failed to create nvram dir '%s': %s"),
cfg->nvramDir, virStrerror(errno, ebuf, sizeof(ebuf)));
goto error;
}
qemu_driver->qemuImgBinary = virFindFileInPath("kvm-img");
if (!qemu_driver->qemuImgBinary)
@ -825,6 +830,13 @@ qemuStateInitialize(bool privileged,
(int) cfg->group);
goto error;
}
if (chown(cfg->nvramDir, cfg->user, cfg->group) < 0) {
virReportSystemError(errno,
_("unable to set ownership of '%s' to %d:%d"),
cfg->nvramDir, (int) cfg->user,
(int) cfg->group);
goto error;
}
run_uid = cfg->user;
run_gid = cfg->group;

View File

@ -4216,8 +4216,8 @@ qemuPrepareNVRAM(virQEMUDriverConfigPtr cfg,
/* Autogenerate nvram path if needed.*/
if (!loader->nvram) {
if (virAsprintf(&loader->nvram,
"%s/lib/libvirt/qemu/nvram/%s_VARS.fd",
LOCALSTATEDIR, vm->def->name) < 0)
"%s/%s_VARS.fd",
cfg->nvramDir, vm->def->name) < 0)
goto cleanup;
generated = true;