qemu: Move utility functions close together

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
This commit is contained in:
Andrea Bolognani 2022-02-04 19:37:51 +01:00
parent 8367ad8a38
commit e74d87c43b

View File

@ -98,6 +98,68 @@ qemuTPMEmulatorLogBuildPath(const char *logDir,
}
/**
* qemuTPMEmulatorSocketBuildPath:
* @swtpmStateDir: directory for swtpm runtime state
* @shortName: short and unique name of the domain
*
* Generate the swtpm's Unix socket path.
*/
static char *
qemuTPMEmulatorSocketBuildPath(const char *swtpmStateDir,
const char *shortName)
{
return g_strdup_printf("%s/%s-swtpm.sock", swtpmStateDir, shortName);
}
/**
* qemuTPMEmulatorPidFileBuildPath:
* @swtpmStateDir: directory for swtpm runtime state
* @shortName: short and unique name of the domain
*
* Generate the swtpm's pidfile path.
*/
static char *
qemuTPMEmulatorPidFileBuildPath(const char *swtpmStateDir,
const char *shortName)
{
g_autofree char *devicename = NULL;
devicename = g_strdup_printf("%s-swtpm", shortName);
return virPidFileBuildPath(swtpmStateDir, devicename);
}
/*
* qemuTPMEmulatorGetPid
*
* @swtpmStateDir: the directory where swtpm writes the pidfile into
* @shortName: short name of the domain
* @pid: pointer to pid
*
* Return -1 upon error, or zero on successful reading of the pidfile.
* If the PID was not still alive, zero will be returned, and @pid will be
* set to -1;
*/
static int
qemuTPMEmulatorGetPid(const char *swtpmStateDir,
const char *shortName,
pid_t *pid)
{
g_autofree char *pidfile = qemuTPMEmulatorPidFileBuildPath(swtpmStateDir,
shortName);
if (!pidfile)
return -1;
if (virPidFileReadPathIfLocked(pidfile, pid) < 0)
return -1;
return 0;
}
/**
* qemuTPMEmulatorCreateStorage:
* @tpm: TPM definition for an emulator type
@ -162,21 +224,6 @@ qemuTPMEmulatorDeleteStorage(virDomainTPMDef *tpm)
}
/**
* qemuTPMEmulatorSocketBuildPath:
* @swtpmStateDir: directory for swtpm runtime state
* @shortName: short and unique name of the domain
*
* Generate the swtpm's Unix socket path.
*/
static char *
qemuTPMEmulatorSocketBuildPath(const char *swtpmStateDir,
const char *shortName)
{
return g_strdup_printf("%s/%s-swtpm.sock", swtpmStateDir, shortName);
}
/*
* qemuTPMEmulatorInitPaths:
*
@ -213,53 +260,6 @@ qemuTPMEmulatorInitPaths(virDomainTPMDef *tpm,
}
/**
* qemuTPMEmulatorPidFileBuildPath:
* @swtpmStateDir: directory for swtpm runtime state
* @shortName: short and unique name of the domain
*
* Generate the swtpm's pidfile path.
*/
static char *
qemuTPMEmulatorPidFileBuildPath(const char *swtpmStateDir,
const char *shortName)
{
g_autofree char *devicename = NULL;
devicename = g_strdup_printf("%s-swtpm", shortName);
return virPidFileBuildPath(swtpmStateDir, devicename);
}
/*
* qemuTPMEmulatorGetPid
*
* @swtpmStateDir: the directory where swtpm writes the pidfile into
* @shortName: short name of the domain
* @pid: pointer to pid
*
* Return -1 upon error, or zero on successful reading of the pidfile.
* If the PID was not still alive, zero will be returned, and @pid will be
* set to -1;
*/
static int
qemuTPMEmulatorGetPid(const char *swtpmStateDir,
const char *shortName,
pid_t *pid)
{
g_autofree char *pidfile = qemuTPMEmulatorPidFileBuildPath(swtpmStateDir,
shortName);
if (!pidfile)
return -1;
if (virPidFileReadPathIfLocked(pidfile, pid) < 0)
return -1;
return 0;
}
/**
* qemuTPMEmulatorCleanupHost:
* @tpm: TPM definition