From: Jordyn Hamilton <j.hamilton@proxmox.com>
To: pve-devel@lists.proxmox.com
Cc: j.hamilton@proxmox.com, c.hughes@proxmox.com
Subject: [PATCH common v2] Added D state checking to `run` subroutine
Date: Thu, 19 Nov 2026 13:45:01 -0500 [thread overview]
Message-ID: <20261119184502.22359-1-j.hamilton@proxmox.com> (raw)
Added a subroutine to check if a process is in a D state. It does so by
reading the processes `stat` file from `/proc/$pid/stat`, then using
regex to grab a group containing the status character. It then returns
true or false if the status is 'D'. Not checking for any other status
types as D state is the only one that needs special logic.
Added flow to check for a D state and customize the error message to
reflect that state within the timeout logic tree. The timeout branch was
chosen since the d state check would only be required if the process
takes long enough to time out.
Logic tree queues a `SIGKILL` prior to any D state checking, as the
system would queue the signal if the process is in a D state, meaning it
would auto terminate once the state resolves. This also means the
standard timeout error checking remains untouched, it still sends the
signal, waits for the process to terminate then dies.
Since there is no way to terminate D state processes programatically,
the program only overwrites the error message then dies, orphaning the
D state process while allowing future processes relying on the
completion of this one to run. It directs the user in the right
direction for debugging and provides all the information necessary for
beginning that process including the `$pid` and `$cmd_str`.
from v2:
- Pulled master from remote and rebased branch off master to resolve
merge conflicts.
- Modified function calls to use parentheses in accordance with the perl
style guide
- Modified error message string to be fomatted by perl style guides
- Squashed commits into one
Signed-off-by: Jordyn Hamilton <j.hamilton@proxmox.com>
---
src/PVE/Cmd.pm | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/src/PVE/Cmd.pm b/src/PVE/Cmd.pm
index 7dee654..9715a06 100644
--- a/src/PVE/Cmd.pm
+++ b/src/PVE/Cmd.pm
@@ -44,6 +44,18 @@ sub split_args($str) {
return $str ? [Text::ParseWords::shellwords($str)] : [];
}
+# check a subprocesses `/proc/<PID>/stat` file for a D state
+sub in_d_state($pid) {
+ open(my $pstat_h, '<', "/proc/$pid/stat") or die $!;
+ my $stat_in = <$pstat_h>;
+ close($pstat_h);
+
+ # extracting the stat character from the input
+ my $status = $1 if ($stat_in =~ /^\d+\s+\(.*\)\s+([A-Z])/);
+
+ return ($status eq 'D');
+}
+
# The $cmd parameter can be:
# -) a string
# This is generally executed by passing it to the shell with the -c option.
@@ -321,6 +333,18 @@ sub run($cmd, %param) {
if ($err) {
if ($pid && ($err eq "got timeout\n")) {
+ kill(9, $pid);
+ if (in_d_state($pid)) {
+ $err = "process '$pid' is in an uninterruptible sleep"
+ . " and cannot resolve or be terminated by this program.\n"
+ . "This process can only be terminated by"
+ . " resolving the errors or performing a system reboot.\n"
+ . "This is due to underlying kernel or hardware errors,"
+ . " check dmesg for errors or"
+ . " kernel messages.\n";
+ }else {
+ waitpid($pid, 0);
+ }
die "command '$cmdstr' failed: $err";
}
--
2.47.3
next reply other threads:[~2026-11-19 18:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 18:45 Jordyn Hamilton [this message]
2026-11-19 22:00 ` [PATCH common v2] Added D state checking to `run` subroutine Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261119184502.22359-1-j.hamilton@proxmox.com \
--to=j.hamilton@proxmox.com \
--cc=c.hughes@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.