Re: [PATCH 3/4] qemu_tpm: Drop @logDir argument from qemuTPMEmulatorPrepareHost()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On a Monday in 2021, Michal Privoznik wrote:
After previous commit, the log directory doesn't have to be
passed as an extra argument but can be deducted from logfile
path.


I'm not convinced this is an improvement.

From the execution point of view it's one passed argument vs
finding a slash and copying a string, so extra work.

And for code clarity, the new version adds more lines
and obscures the fact that logDir is configured per-host,
not per-vm.

If you feel qemuTPMEmulatorPrepareHost has too many arguments,
you can pass cfg.

Jano

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
src/qemu/qemu_tpm.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c
index b11c5474a5..5ee5efa6b0 100644
--- a/src/qemu/qemu_tpm.c
+++ b/src/qemu/qemu_tpm.c
@@ -274,7 +274,6 @@ qemuTPMEmulatorGetPid(const char *swtpmStateDir,
 * qemuTPMEmulatorPrepareHost:
 *
 * @tpm: tpm definition
- * @logDir: directory where swtpm writes its logs into
 * @swtpm_user: uid to run the swtpm with
 * @swtpm_group: gid to run the swtpm with
 * @swtpmStateDir: directory for swtpm's persistent state
@@ -287,16 +286,19 @@ qemuTPMEmulatorGetPid(const char *swtpmStateDir,
 */
static int
qemuTPMEmulatorPrepareHost(virDomainTPMDefPtr tpm,
-                           const char *logDir,
                           uid_t swtpm_user,
                           gid_t swtpm_group,
                           const char *swtpmStateDir,
                           uid_t qemu_user,
                           const char *shortName)
{
+    g_autofree char *logDir = NULL;
+
    if (virTPMEmulatorInit() < 0)
        return -1;

+    logDir = g_path_get_dirname(tpm->data.emulator.logfile);
+
    /* create log dir ... allow 'tss' user to cd into it */
    if (virFileMakePathWithMode(logDir, 0711) < 0)
        return -1;
@@ -732,7 +734,7 @@ qemuExtTPMPrepareHost(virQEMUDriverPtr driver,
        if (!shortName)
            return -1;

-        return qemuTPMEmulatorPrepareHost(def->tpms[i], cfg->swtpmLogDir,
+        return qemuTPMEmulatorPrepareHost(def->tpms[i],
                                          cfg->swtpm_user,
                                          cfg->swtpm_group,
                                          cfg->swtpmStateDir, cfg->user,
--
2.26.2

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux