In near future it will be necessary to know the PID of virtiofsd
started for QEMU. Move the code into a separate function
(qemuVirtioFSGetPid()) and export it in the header file.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
src/qemu/qemu_virtiofs.c | 38 +++++++++++++++++++++++++-------------
src/qemu/qemu_virtiofs.h | 5 +++++
2 files changed, 30 insertions(+), 13 deletions(-)
diff --git a/src/qemu/qemu_virtiofs.c b/src/qemu/qemu_virtiofs.c
index ce55286ab5..2fd4b9f987 100644
--- a/src/qemu/qemu_virtiofs.c
+++ b/src/qemu/qemu_virtiofs.c
@@ -323,26 +323,38 @@ qemuVirtioFSStop(virQEMUDriver *driver G_GNUC_UNUSED,
}
+
+int
+qemuVirtioFSGetPid(virDomainObj *vm,
+ virDomainFSDef *fs,
+ pid_t *pid)
+{
+ g_autofree char *pidfile = NULL;
+ int rc;
+
+ if (!(pidfile = qemuVirtioFSCreatePidFilename(vm, fs->info.alias)))
+ return -1;
+
+ rc = virPidFileReadPathIfAlive(pidfile, pid, NULL);
+ if (rc < 0 || *pid == (pid_t) -1) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("virtiofsd died unexpectedly"));
+ return -1;
+ }
+
+ return 0;
+}
+
+
int
qemuVirtioFSSetupCgroup(virDomainObj *vm,
virDomainFSDef *fs,
virCgroup *cgroup)
{
- g_autofree char *pidfile = NULL;
pid_t pid = -1;
- int rc;
- if (!(pidfile = qemuVirtioFSCreatePidFilename(vm, fs->info.alias)))
- return -1;
-
- rc = virPidFileReadPathIfAlive(pidfile, &pid, NULL);
- if (rc < 0 || pid == (pid_t) -1) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("virtiofsd died unexpectedly"));
- return -1;
- }
-
- if (virCgroupAddProcess(cgroup, pid) < 0)
+ if (qemuVirtioFSGetPid(vm, fs, &pid) < 0 ||
+ virCgroupAddProcess(cgroup, pid) < 0)
return -1;
return 0;
diff --git a/src/qemu/qemu_virtiofs.h b/src/qemu/qemu_virtiofs.h
index 5463acef98..dd3fbfa555 100644
--- a/src/qemu/qemu_virtiofs.h
+++ b/src/qemu/qemu_virtiofs.h
@@ -35,6 +35,11 @@ qemuVirtioFSStop(virQEMUDriver *driver,
virDomainObj *vm,
virDomainFSDef *fs);
+int
+qemuVirtioFSGetPid(virDomainObj *vm,
+ virDomainFSDef *fs,
+ pid_t *pid);
+
int
qemuVirtioFSSetupCgroup(virDomainObj *vm,
virDomainFSDef *fs,
--
2.35.1