Launch mdmon via systemctl to avoid it ending up in the wrong cgroup

Resolves bz879327

Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
This commit is contained in:
Jes Sorensen 2013-01-21 14:36:26 +01:00
parent d047b34df2
commit 352851ee4a
2 changed files with 28 additions and 57 deletions

View File

@ -1,38 +0,0 @@
diff -up mdadm-3.2.6/util.c.cgroup mdadm-3.2.6/util.c
--- mdadm-3.2.6/mdmon.c.cgroup 2012-11-15 16:48:03.327035349 -0500
+++ mdadm-3.2.6/mdmon.c 2012-11-15 17:07:16.628751041 -0500
@@ -386,6 +386,25 @@
return mdmon(devname, devnum, do_fork(), takeover);
}
+int set_cgroup(char *group)
+{
+ char pid[8];
+ char pathbuf[PATH_MAX];
+ int tasks_fd, n;
+
+ snprintf(pathbuf, PATH_MAX, "/sys/fs/cgroup/%s/tasks", group);
+ tasks_fd = open(pathbuf, O_WRONLY);
+ if (tasks_fd >= 0) {
+ snprintf(pid, sizeof(pid), "%d", getpid());
+ n = write(tasks_fd, pid, strlen(pid));
+ close(tasks_fd);
+ if (n != (int)strlen(pid)) {
+ return -1;
+ }
+ }
+ return 0;
+}
+
static int mdmon(char *devname, int devnum, int must_fork, int takeover)
{
int mdfd;
@@ -438,6 +457,8 @@
} else
pfd[0] = pfd[1] = -1;
+ set_cgroup("systemd");
+
container = calloc(1, sizeof(*container));
container->devnum = devnum;
container->devname = devname;

View File

@ -1,7 +1,7 @@
Summary: The mdadm program controls Linux md devices (software RAID arrays)
Name: mdadm
Version: 3.2.6
Release: 11%{?dist}
Release: 12%{?dist}
Source: http://www.kernel.org/pub/linux/utils/raid/mdadm/mdadm-%{version}.tar.xz
Source1: mdmonitor.init
Source2: raid-check
@ -9,15 +9,17 @@ Source3: mdadm.rules
Source4: mdadm-raid-check-sysconfig
Source5: mdadm-cron
Source6: mdmonitor.service
Source8: mdadm.conf
Source9: mdadm_event.conf
Patch0: mdadm-3.2.6-cgroup.patch
Source7: mdmon-offroot@.service
Source8: mdmon@.service
Source9: mdadm.conf
Source10: mdadm_event.conf
Patch1: mdadm-3.2.6-Create.c-check-if-freesize-is-equal-0.patch
Patch2: mdadm-3.2.6-imsm-Forbid-spanning-between-multiple-controllers.patch
Patch96: mdadm-3.2.6-Add-support-for-launching-mdmon-via-systemctl-instea.patch
# Fedora customization patches
Patch97: mdadm-3.2.6-udev.patch
Patch98: mdadm-2.5.2-static.patch
# Fedora 15, 16, 17 - only
# Fedora 16, 17 - only
Patch99: mdadm-3.2.4-map-dir.patch
URL: http://www.kernel.org/pub/linux/utils/raid/mdadm/
License: GPLv2+
@ -26,18 +28,15 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
Obsoletes: mdctl,raidtools
%if "%{fedora}" >= "18"
Obsoletes: mdadm-sysvinit
%endif
BuildRequires: systemd-units binutils-devel
%if "%{fedora}" <= "17"
Requires(post): systemd-units systemd-sysv chkconfig coreutils
%else
Conflicts: dracut < 024-23
Requires(post): systemd-units chkconfig coreutils
%endif
Requires(preun): systemd-units
Requires(postun): systemd-units coreutils
%if "%{fedora}" <= "17"
%else
Requires(post): systemd-units systemd-sysv chkconfig coreutils
Requires: udev initscripts
%endif
BuildRequires: systemd-units binutils-devel
Requires(preun): systemd-units
Requires(postun): systemd-units coreutils
%if "%{fedora}" >= "17"
Requires: libreport-filesystem
Conflicts: dracut < 009-14
@ -66,9 +65,9 @@ is not used as the system init process.
%prep
%setup -q
# Only apply cgroups workaround on F18 and higher
# Use systemctl to launch mdmon on F18 and higher
%if "%{fedora}" >= "18"
%patch0 -p1 -b .cgroup
%patch96 -p1 -b .sysctl
%endif
%patch1 -p1 -b .raidsize
@ -77,7 +76,7 @@ is not used as the system init process.
# Fedora customization patches
%patch97 -p1 -b .udev
%patch98 -p1 -b .static
# Fedora 15, 16, 17 - only
# Fedora 16, 17 - only
%if "%{fedora}" <= "17"
%patch99 -p1 -b .map-dir
%endif
@ -100,17 +99,19 @@ mkdir -p -m 700 %{buildroot}/var/run/mdadm
# systemd
mkdir -p %{buildroot}%{_unitdir}
install -m644 %{SOURCE6} %{buildroot}%{_unitdir}
install -m644 %{SOURCE7} %{buildroot}%{_unitdir}
install -m644 %{SOURCE8} %{buildroot}%{_unitdir}
# tmpfile
mkdir -p %{buildroot}%{_prefix}/lib/tmpfiles.d
install -m 0644 %{SOURCE8} %{buildroot}%{_prefix}/lib/tmpfiles.d/%{name}.conf
install -m 0644 %{SOURCE9} %{buildroot}%{_prefix}/lib/tmpfiles.d/%{name}.conf
mkdir -p %{buildroot}%{_localstatedir}/run/
install -d -m 0710 %{buildroot}%{_localstatedir}/run/%{name}/
# abrt
%if "%{fedora}" >= "17"
mkdir -p %{buildroot}/etc/libreport/events.d
install -m644 %{SOURCE9} %{buildroot}/etc/libreport/events.d
install -m644 %{SOURCE10} %{buildroot}/etc/libreport/events.d
%endif
%clean
@ -144,6 +145,8 @@ rm -rf %{buildroot}
/sbin/*
%{_sbindir}/raid-check
%{_unitdir}/mdmonitor.service
%{_unitdir}/mdmon-offroot@.service
%{_unitdir}/mdmon@.service
%{_mandir}/man*/md*
%config(noreplace) %{_sysconfdir}/cron.d/*
%config(noreplace) %{_sysconfdir}/sysconfig/*
@ -159,6 +162,12 @@ rm -rf %{buildroot}
%endif
%changelog
* Mon Jan 21 2013 Jes Sorensen <Jes.Sorensen@redhat.com> - 3.2.6-12
- Launch mdmon via systemctl to avoid it ending up in the wrong cgroup
and getting killed in the boot process when switching from the
initrd to the real root.
- Resolves bz879327
* Tue Jan 8 2013 Jes Sorensen <Jes.Sorensen@redhat.com> - 3.2.6-11
- Move code to leave udev cgroup into mdmon and excute it after we
work, to make sure it actually does the right thing.