|
|
9de337 |
From aef9198f67350910494edb38b64b1c5e71a32e4e Mon Sep 17 00:00:00 2001
|
|
|
9de337 |
Message-Id: <aef9198f67350910494edb38b64b1c5e71a32e4e@dist-git>
|
|
|
9de337 |
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
|
|
|
9de337 |
Date: Thu, 5 Aug 2021 13:49:46 +0200
|
|
|
9de337 |
Subject: [PATCH] util: virPidFileForceCleanupPath: add group argument
|
|
|
9de337 |
MIME-Version: 1.0
|
|
|
9de337 |
Content-Type: text/plain; charset=UTF-8
|
|
|
9de337 |
Content-Transfer-Encoding: 8bit
|
|
|
9de337 |
|
|
|
9de337 |
Add a version of virPidFileForceCleanupPath that takes
|
|
|
9de337 |
a 'group' bool argument and propagate it all the way
|
|
|
9de337 |
down to virProcessKillPainfullyDelay.
|
|
|
9de337 |
|
|
|
9de337 |
Signed-off-by: Ján Tomko <jtomko@redhat.com>
|
|
|
9de337 |
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
|
|
|
9de337 |
(cherry picked from commit ff7b8043b68ff8e03008a9328dccb0b310d8f7a2)
|
|
|
9de337 |
Signed-off-by: Ján Tomko <jtomko@redhat.com>
|
|
|
9de337 |
|
|
|
9de337 |
https://bugzilla.redhat.com/show_bug.cgi?id=1940276
|
|
|
9de337 |
Message-Id: <ef5e4377704c1f64553b28971335d331e4d84e84.1628164129.git.jtomko@redhat.com>
|
|
|
9de337 |
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
|
|
|
9de337 |
---
|
|
|
9de337 |
src/libvirt_private.syms | 1 +
|
|
|
9de337 |
src/qemu/qemu_process.c | 3 ++-
|
|
|
9de337 |
src/util/virpidfile.c | 15 +++++++++++++--
|
|
|
9de337 |
src/util/virpidfile.h | 2 ++
|
|
|
9de337 |
src/util/virprocess.c | 17 ++++++++++++-----
|
|
|
9de337 |
src/util/virprocess.h | 3 ++-
|
|
|
9de337 |
6 files changed, 32 insertions(+), 9 deletions(-)
|
|
|
9de337 |
|
|
|
9de337 |
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
|
|
|
9de337 |
index 8b892cf255..c80e690da4 100644
|
|
|
9de337 |
--- a/src/libvirt_private.syms
|
|
|
9de337 |
+++ b/src/libvirt_private.syms
|
|
|
9de337 |
@@ -3037,6 +3037,7 @@ virPidFileConstructPath;
|
|
|
9de337 |
virPidFileDelete;
|
|
|
9de337 |
virPidFileDeletePath;
|
|
|
9de337 |
virPidFileForceCleanupPath;
|
|
|
9de337 |
+virPidFileForceCleanupPathFull;
|
|
|
9de337 |
virPidFileRead;
|
|
|
9de337 |
virPidFileReadIfAlive;
|
|
|
9de337 |
virPidFileReadPath;
|
|
|
9de337 |
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
|
|
|
9de337 |
index 521fda57da..6ef8ebd83e 100644
|
|
|
9de337 |
--- a/src/qemu/qemu_process.c
|
|
|
9de337 |
+++ b/src/qemu/qemu_process.c
|
|
|
9de337 |
@@ -7700,7 +7700,8 @@ qemuProcessKill(virDomainObj *vm, unsigned int flags)
|
|
|
9de337 |
* to be safe against stalls by the kernel freeing up the resources */
|
|
|
9de337 |
return virProcessKillPainfullyDelay(vm->pid,
|
|
|
9de337 |
!!(flags & VIR_QEMU_PROCESS_KILL_FORCE),
|
|
|
9de337 |
- vm->def->nhostdevs * 2);
|
|
|
9de337 |
+ vm->def->nhostdevs * 2,
|
|
|
9de337 |
+ false);
|
|
|
9de337 |
}
|
|
|
9de337 |
|
|
|
9de337 |
|
|
|
9de337 |
diff --git a/src/util/virpidfile.c b/src/util/virpidfile.c
|
|
|
9de337 |
index c6389c1869..7069f8343d 100644
|
|
|
9de337 |
--- a/src/util/virpidfile.c
|
|
|
9de337 |
+++ b/src/util/virpidfile.c
|
|
|
9de337 |
@@ -514,7 +514,7 @@ virPidFileConstructPath(bool privileged,
|
|
|
9de337 |
* Returns 0 if the pidfile was successfully cleaned up, -1 otherwise.
|
|
|
9de337 |
*/
|
|
|
9de337 |
int
|
|
|
9de337 |
-virPidFileForceCleanupPath(const char *path)
|
|
|
9de337 |
+virPidFileForceCleanupPathFull(const char *path, bool group)
|
|
|
9de337 |
{
|
|
|
9de337 |
pid_t pid = 0;
|
|
|
9de337 |
int fd = -1;
|
|
|
9de337 |
@@ -529,10 +529,15 @@ virPidFileForceCleanupPath(const char *path)
|
|
|
9de337 |
if (fd < 0) {
|
|
|
9de337 |
virResetLastError();
|
|
|
9de337 |
|
|
|
9de337 |
+ if (pid > 1 && group)
|
|
|
9de337 |
+ pid = virProcessGroupGet(pid);
|
|
|
9de337 |
+
|
|
|
9de337 |
/* Only kill the process if the pid is valid one. 0 means
|
|
|
9de337 |
* there is somebody else doing the same pidfile cleanup
|
|
|
9de337 |
* machinery. */
|
|
|
9de337 |
- if (pid)
|
|
|
9de337 |
+ if (group)
|
|
|
9de337 |
+ virProcessKillPainfullyDelay(pid, true, 0, true);
|
|
|
9de337 |
+ else if (pid)
|
|
|
9de337 |
virProcessKillPainfully(pid, true);
|
|
|
9de337 |
|
|
|
9de337 |
if (virPidFileDeletePath(path) < 0)
|
|
|
9de337 |
@@ -544,3 +549,9 @@ virPidFileForceCleanupPath(const char *path)
|
|
|
9de337 |
|
|
|
9de337 |
return 0;
|
|
|
9de337 |
}
|
|
|
9de337 |
+
|
|
|
9de337 |
+int
|
|
|
9de337 |
+virPidFileForceCleanupPath(const char *path)
|
|
|
9de337 |
+{
|
|
|
9de337 |
+ return virPidFileForceCleanupPathFull(path, false);
|
|
|
9de337 |
+}
|
|
|
9de337 |
diff --git a/src/util/virpidfile.h b/src/util/virpidfile.h
|
|
|
9de337 |
index 370a59892e..fd8013c41e 100644
|
|
|
9de337 |
--- a/src/util/virpidfile.h
|
|
|
9de337 |
+++ b/src/util/virpidfile.h
|
|
|
9de337 |
@@ -73,4 +73,6 @@ int virPidFileConstructPath(bool privileged,
|
|
|
9de337 |
const char *progname,
|
|
|
9de337 |
char **pidfile);
|
|
|
9de337 |
|
|
|
9de337 |
+int virPidFileForceCleanupPathFull(const char *path,
|
|
|
9de337 |
+ bool group) ATTRIBUTE_NONNULL(1);
|
|
|
9de337 |
int virPidFileForceCleanupPath(const char *path) ATTRIBUTE_NONNULL(1);
|
|
|
9de337 |
diff --git a/src/util/virprocess.c b/src/util/virprocess.c
|
|
|
9de337 |
index 1bc840120a..0b57522936 100644
|
|
|
9de337 |
--- a/src/util/virprocess.c
|
|
|
9de337 |
+++ b/src/util/virprocess.c
|
|
|
9de337 |
@@ -406,15 +406,15 @@ pid_t virProcessGroupGet(pid_t pid)
|
|
|
9de337 |
* wait longer than the default.
|
|
|
9de337 |
*/
|
|
|
9de337 |
int
|
|
|
9de337 |
-virProcessKillPainfullyDelay(pid_t pid, bool force, unsigned int extradelay)
|
|
|
9de337 |
+virProcessKillPainfullyDelay(pid_t pid, bool force, unsigned int extradelay, bool group)
|
|
|
9de337 |
{
|
|
|
9de337 |
size_t i;
|
|
|
9de337 |
/* This is in 1/5th seconds since polling is on a 0.2s interval */
|
|
|
9de337 |
unsigned int polldelay = (force ? 200 : 75) + (extradelay*5);
|
|
|
9de337 |
const char *signame = "TERM";
|
|
|
9de337 |
|
|
|
9de337 |
- VIR_DEBUG("vpid=%lld force=%d extradelay=%u",
|
|
|
9de337 |
- (long long)pid, force, extradelay);
|
|
|
9de337 |
+ VIR_DEBUG("vpid=%lld force=%d extradelay=%u group=%d",
|
|
|
9de337 |
+ (long long)pid, force, extradelay, group);
|
|
|
9de337 |
|
|
|
9de337 |
/* This loop sends SIGTERM, then waits a few iterations (10 seconds)
|
|
|
9de337 |
* to see if it dies. If the process still hasn't exited, and
|
|
|
9de337 |
@@ -429,6 +429,8 @@ virProcessKillPainfullyDelay(pid_t pid, bool force, unsigned int extradelay)
|
|
|
9de337 |
*/
|
|
|
9de337 |
for (i = 0; i < polldelay; i++) {
|
|
|
9de337 |
int signum;
|
|
|
9de337 |
+ int rc;
|
|
|
9de337 |
+
|
|
|
9de337 |
if (i == 0) {
|
|
|
9de337 |
signum = SIGTERM; /* kindly suggest it should exit */
|
|
|
9de337 |
} else if (i == 50 && force) {
|
|
|
9de337 |
@@ -447,7 +449,12 @@ virProcessKillPainfullyDelay(pid_t pid, bool force, unsigned int extradelay)
|
|
|
9de337 |
signum = 0; /* Just check for existence */
|
|
|
9de337 |
}
|
|
|
9de337 |
|
|
|
9de337 |
- if (virProcessKill(pid, signum) < 0) {
|
|
|
9de337 |
+ if (group)
|
|
|
9de337 |
+ rc = virProcessGroupKill(pid, signum);
|
|
|
9de337 |
+ else
|
|
|
9de337 |
+ rc = virProcessKill(pid, signum);
|
|
|
9de337 |
+
|
|
|
9de337 |
+ if (rc < 0) {
|
|
|
9de337 |
if (errno != ESRCH) {
|
|
|
9de337 |
virReportSystemError(errno,
|
|
|
9de337 |
_("Failed to terminate process %lld with SIG%s"),
|
|
|
9de337 |
@@ -470,7 +477,7 @@ virProcessKillPainfullyDelay(pid_t pid, bool force, unsigned int extradelay)
|
|
|
9de337 |
|
|
|
9de337 |
int virProcessKillPainfully(pid_t pid, bool force)
|
|
|
9de337 |
{
|
|
|
9de337 |
- return virProcessKillPainfullyDelay(pid, force, 0);
|
|
|
9de337 |
+ return virProcessKillPainfullyDelay(pid, force, 0, false);
|
|
|
9de337 |
}
|
|
|
9de337 |
|
|
|
9de337 |
#if WITH_SCHED_GETAFFINITY
|
|
|
9de337 |
diff --git a/src/util/virprocess.h b/src/util/virprocess.h
|
|
|
9de337 |
index 9d7c0f479a..9910331a0c 100644
|
|
|
9de337 |
--- a/src/util/virprocess.h
|
|
|
9de337 |
+++ b/src/util/virprocess.h
|
|
|
9de337 |
@@ -58,7 +58,8 @@ pid_t virProcessGroupGet(pid_t pid);
|
|
|
9de337 |
int virProcessKillPainfully(pid_t pid, bool force);
|
|
|
9de337 |
int virProcessKillPainfullyDelay(pid_t pid,
|
|
|
9de337 |
bool force,
|
|
|
9de337 |
- unsigned int extradelay);
|
|
|
9de337 |
+ unsigned int extradelay,
|
|
|
9de337 |
+ bool group);
|
|
|
9de337 |
|
|
|
9de337 |
int virProcessSetAffinity(pid_t pid, virBitmap *map, bool quiet);
|
|
|
9de337 |
|
|
|
9de337 |
--
|
|
|
9de337 |
2.32.0
|
|
|
9de337 |
|