qos: bugfix for create pidfile

Create pidfile after os.fork in child process.

Signed-off-by: sundongxu <sundongxu3@huawei.com>
This commit is contained in:
sundongxu 2022-08-25 16:43:46 +08:00
parent 9565dd0238
commit bd4c9df0b7
2 changed files with 67 additions and 1 deletions

View File

@ -0,0 +1,62 @@
From 12d0dd3662a21acdde8e2f0264ed4c8aec6e3138 Mon Sep 17 00:00:00 2001
From: Dongxu Sun <sundongxu3@huawei.com>
Date: Wed, 24 Aug 2022 15:47:09 +0800
Subject: [PATCH] framework: create pidfile after os.fork in child process
To prevent the pidfile from being read by systemd when Skylark
does not initialize the pidfile, move create_pid_file() after
os.fork in child process.
Signed-off-by: Dongxu Sun <sundongxu3@huawei.com>
---
skylark.py | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/skylark.py b/skylark.py
index c281a54..6224f9b 100644
--- a/skylark.py
+++ b/skylark.py
@@ -112,15 +112,16 @@ def create_pid_file():
os.fchmod(fd, stat.S_IRUSR | stat.S_IWUSR)
os.close(fd)
try:
- PID_FILE = open(PID_FILE_NAME, 'w')
+ PID_FILE = open(PID_FILE_NAME, 'a')
except IOError:
LOGGER.error("Failed to open pid file")
- exit(1)
+ sys.exit(1)
try:
fcntl.flock(PID_FILE.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
except IOError:
LOGGER.error("A running service instance already creates the pid file! This service will exit!")
+ PID_FILE.close()
os._exit(0)
process_pid = os.getpid()
@@ -153,9 +154,6 @@ def func_daemon():
@atexit.register
def daemon_exit_func():
LIBVIRT_CONN.close()
- remove_pid_file()
-
- create_pid_file()
LOGGER.info("Try to open libvirtd connection")
try:
@@ -186,7 +184,10 @@ def create_daemon():
LOGGER.error('Fork daemon process failed: %d (%s)' % (error.errno, error.strerror))
os._exit(1)
else:
- if pid:
+ if pid == 0:
+ atexit.register(remove_pid_file)
+ create_pid_file()
+ else:
os._exit(0)
os.chdir('/')
os.umask(0)
--
2.17.1

View File

@ -1,6 +1,6 @@
Name: skylark Name: skylark
Version: 1.0.0 Version: 1.0.0
Release: 4 Release: 5
Summary: Skylark is a next-generation QoS-aware scheduler. Summary: Skylark is a next-generation QoS-aware scheduler.
License: Mulan PSL v2 License: Mulan PSL v2
@ -10,6 +10,7 @@ Source0: %{name}-%{version}.tar.gz
Patch0001: guestinfo-Take-another-VM-stop-reason-to-account.patch Patch0001: guestinfo-Take-another-VM-stop-reason-to-account.patch
Patch0002: cpu_qos-Add-aditional-setting-for-cpu-QOS.patch Patch0002: cpu_qos-Add-aditional-setting-for-cpu-QOS.patch
Patch0003: cachembw_qos-Add-a-job-to-sync-VM-pids-to-resctrl.patch Patch0003: cachembw_qos-Add-a-job-to-sync-VM-pids-to-resctrl.patch
Patch0004: framework-create-pidfile-after-os.fork-in-child-proc.patch
BuildRequires: python3-devel make gcc coreutils systemd-units BuildRequires: python3-devel make gcc coreutils systemd-units
Requires: python3 python3-APScheduler python3-libvirt Requires: python3 python3-APScheduler python3-libvirt
@ -59,6 +60,9 @@ make install DESTDIR=%{buildroot}
%changelog %changelog
* Thu Aug 25 2022 Dongxu Sun <sundongxu3@huawei.com> - 1.0.0-5
- framework: create pidfile after os.fork in child process
* Fri Aug 19 2022 Keqian Zhu <zhukeqian1@huawei.com> - 1.0.0-4 * Fri Aug 19 2022 Keqian Zhu <zhukeqian1@huawei.com> - 1.0.0-4
- guestinfo: Take another VM stop reason to account - guestinfo: Take another VM stop reason to account
- cpu_qos: Add aditional setting for cpu QOS - cpu_qos: Add aditional setting for cpu QOS