Преглед изворни кода

Remove libcgroup

Libcgroup is deprecated and not shipping with new distributions
(OpenSuSE is one example). Solution is to have a partial implementation
of required functionality of libcgroup in the corosync code.

Patch uses hardcoded cgroup mount point, because most of the systems are
now systemd and systemd is also using hardcoded mountpoint (see
https://github.com/systemd/systemd/blob/master/src/core/mount-setup.c)

Configuration option --enable-cgroup is gone, because it's not needed
any longer.

Big thanks to Christine Caulfield <ccaulfie@redhat.com> for example of
simplified implementation of cgroup management code primitives.

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Reviewed-by: Christine Caulfield <ccaulfie@redhat.com>
Jan Friesse пре 7 година
родитељ
комит
c9e5d6db13
5 измењених фајлова са 28 додато и 90 уклоњено
  1. 0 12
      configure.ac
  2. 0 7
      corosync.spec.in
  3. 0 5
      exec/Makefile.am
  4. 24 64
      exec/main.c
  5. 4 2
      man/corosync.8

+ 0 - 12
configure.ac

@@ -394,11 +394,6 @@ AC_ARG_ENABLE([xmlconf],
 	[ enable_xmlconf="no" ])
 	[ enable_xmlconf="no" ])
 AM_CONDITIONAL(INSTALL_XMLCONF, test x$enable_xmlconf = xyes)
 AM_CONDITIONAL(INSTALL_XMLCONF, test x$enable_xmlconf = xyes)
 
 
-AC_ARG_ENABLE([libcgroup],
-	[  --enable-libcgroup                  : Enable libcgroup support ],,
-	[ enable_libcgroup="no" ])
-AM_CONDITIONAL(ENABLE_LIBCGROUP, test x$enable_libcgroup = xyes)
-
 AC_ARG_ENABLE([vqsim],
 AC_ARG_ENABLE([vqsim],
 	[  --enable-vqsim               : Quorum simulator support ],,
 	[  --enable-vqsim               : Quorum simulator support ],,
 	[ enable_vqsim="no" ])
 	[ enable_vqsim="no" ])
@@ -527,13 +522,6 @@ if test "x${enable_snmp}" = xyes; then
 fi
 fi
 AM_CONDITIONAL(BUILD_SNMP, test "${do_snmp}" = "1")
 AM_CONDITIONAL(BUILD_SNMP, test "${do_snmp}" = "1")
 
 
-if test "x${enable_libcgroup}" = xyes; then
-    PKG_CHECK_MODULES([libcgroup], [libcgroup])
-    AC_DEFINE_UNQUOTED([HAVE_LIBCGROUP], 1, [have libcgroup])
-    PACKAGE_FEATURES="$PACKAGE_FEATURES libcgroup"
-    WITH_LIST="$WITH_LIST --with libcgroup"
-fi
-
 # extra warnings
 # extra warnings
 EXTRA_WARNINGS=""
 EXTRA_WARNINGS=""
 
 

+ 0 - 7
corosync.spec.in

@@ -13,7 +13,6 @@
 %bcond_with systemd
 %bcond_with systemd
 %bcond_with xmlconf
 %bcond_with xmlconf
 %bcond_with runautogen
 %bcond_with runautogen
-%bcond_with libcgroup
 
 
 %global gitver %{?numcomm:.%{numcomm}}%{?alphatag:.%{alphatag}}%{?dirty:.%{dirty}}
 %global gitver %{?numcomm:.%{numcomm}}%{?alphatag:.%{alphatag}}%{?dirty:.%{dirty}}
 %global gittarver %{?numcomm:.%{numcomm}}%{?alphatag:-%{alphatag}}%{?dirty:-%{dirty}}
 %global gittarver %{?numcomm:.%{numcomm}}%{?alphatag:-%{alphatag}}%{?dirty:-%{dirty}}
@@ -73,9 +72,6 @@ Requires(preun): /sbin/chkconfig
 %if %{with xmlconf}
 %if %{with xmlconf}
 Requires: libxslt
 Requires: libxslt
 %endif
 %endif
-%if %{with libcgroup}
-BuildRequires: libcgroup-devel
-%endif
 
 
 %prep
 %prep
 %setup -q -n %{name}-%{version}%{?gittarver}
 %setup -q -n %{name}-%{version}%{?gittarver}
@@ -106,9 +102,6 @@ BuildRequires: libcgroup-devel
 %endif
 %endif
 %if %{with xmlconf}
 %if %{with xmlconf}
 	--enable-xmlconf \
 	--enable-xmlconf \
-%endif
-%if %{with libcgroup}
-	--enable-libcgroup \
 %endif
 %endif
 	--with-initddir=%{_initrddir} \
 	--with-initddir=%{_initrddir} \
 	--with-systemddir=%{_unitdir} \
 	--with-systemddir=%{_unitdir} \

+ 0 - 5
exec/Makefile.am

@@ -74,10 +74,5 @@ corosync_LDADD		= libtotem_pg.la ../common_lib/libcorosync_common.la \
 
 
 corosync_DEPENDENCIES	= libtotem_pg.la ../common_lib/libcorosync_common.la
 corosync_DEPENDENCIES	= libtotem_pg.la ../common_lib/libcorosync_common.la
 
 
-if ENABLE_LIBCGROUP
-corosync_CFLAGS		+= $(libcgroup_CFLAGS)
-corosync_LDADD		+= $(libcgroup_LIBS)
-endif
-
 lint:
 lint:
 	-splint $(LINT_FLAGS) $(CPPFLAGS) $(CFLAGS) *.c
 	-splint $(LINT_FLAGS) $(CPPFLAGS) $(CFLAGS) *.c

+ 24 - 64
exec/main.c

@@ -113,10 +113,6 @@
 #include <corosync/logsys.h>
 #include <corosync/logsys.h>
 #include <corosync/icmap.h>
 #include <corosync/icmap.h>
 
 
-#ifdef HAVE_LIBCGROUP
-#include <libcgroup.h>
-#endif
-
 #include "quorum.h"
 #include "quorum.h"
 #include "totemsrp.h"
 #include "totemsrp.h"
 #include "logconfig.h"
 #include "logconfig.h"
@@ -1120,84 +1116,47 @@ error_close:
 }
 }
 
 
 static int corosync_move_to_root_cgroup(void) {
 static int corosync_move_to_root_cgroup(void) {
+	FILE *f;
 	int res = -1;
 	int res = -1;
-#ifdef HAVE_LIBCGROUP
-	int cg_ret;
-	struct cgroup *root_cgroup = NULL;
-	struct cgroup_controller *root_cpu_cgroup_controller = NULL;
-	char *current_cgroup_path = NULL;
-
-	cg_ret = cgroup_init();
-	if (cg_ret) {
-		log_printf(LOGSYS_LEVEL_WARNING, "Unable to initialize libcgroup: %s ",
-		    cgroup_strerror(cg_ret));
-
-		goto exit_res;
-	}
-
-	cg_ret = cgroup_get_current_controller_path(getpid(), "cpu", &current_cgroup_path);
-	if (cg_ret) {
-		log_printf(LOGSYS_LEVEL_WARNING, "Unable to get current cpu cgroup path: %s ",
-		    cgroup_strerror(cg_ret));
 
 
-		goto exit_res;
-	}
-
-	if (strcmp(current_cgroup_path, "/") == 0) {
-		log_printf(LOGSYS_LEVEL_DEBUG, "Corosync is already in root cgroup path");
+	/*
+	 * /sys/fs/cgroup is hardcoded, because most of Linux distributions are now
+	 * using systemd and systemd uses hardcoded path of cgroup mount point.
+	 *
+	 * This feature is expected to be removed as soon as systemd gets support
+	 * for managing RT configuration.
+	 */
+	f = fopen("/sys/fs/cgroup/cpu/cpu.rt_runtime_us", "rt");
+	if (f == NULL) {
+		log_printf(LOGSYS_LEVEL_DEBUG, "cpu.rt_runtime_us doesn't exists -> "
+		    "system without cgroup or with disabled CONFIG_RT_GROUP_SCHED");
 
 
 		res = 0;
 		res = 0;
 		goto exit_res;
 		goto exit_res;
 	}
 	}
+	(void)fclose(f);
 
 
-	root_cgroup = cgroup_new_cgroup("/");
-	if (root_cgroup == NULL) {
-		log_printf(LOGSYS_LEVEL_WARNING, "Can't create root cgroup");
+	f = fopen("/sys/fs/cgroup/cpu/tasks", "w");
+	if (f == NULL) {
+		log_printf(LOGSYS_LEVEL_WARNING, "Can't open cgroups tasks file for writing");
 
 
 		goto exit_res;
 		goto exit_res;
 	}
 	}
 
 
-	root_cpu_cgroup_controller = cgroup_add_controller(root_cgroup, "cpu");
-	if (root_cpu_cgroup_controller == NULL) {
-		log_printf(LOGSYS_LEVEL_WARNING, "Can't create root cgroup cpu controller");
+	if (fprintf(f, "%jd\n", (intmax_t)getpid()) <= 0) {
+		log_printf(LOGSYS_LEVEL_WARNING, "Can't write corosync pid into cgroups tasks file");
 
 
-		goto exit_res;
+		goto close_and_exit_res;
 	}
 	}
 
 
-	cg_ret = cgroup_attach_task(root_cgroup);
-	if (cg_ret) {
-		log_printf(LOGSYS_LEVEL_WARNING, "Can't attach task to root cgroup: %s ",
-		    cgroup_strerror(cg_ret));
+close_and_exit_res:
+	if (fclose(f) != 0) {
+		log_printf(LOGSYS_LEVEL_WARNING, "Can't close cgroups tasks file");
 
 
 		goto exit_res;
 		goto exit_res;
 	}
 	}
 
 
-	cg_ret = cgroup_get_current_controller_path(getpid(), "cpu", &current_cgroup_path);
-	if (cg_ret) {
-		log_printf(LOGSYS_LEVEL_WARNING, "Unable to get current cpu cgroup path: %s ",
-		    cgroup_strerror(cg_ret));
-
-		goto exit_res;
-	}
-
-	if (strcmp(current_cgroup_path, "/") == 0) {
-		log_printf(LOGSYS_LEVEL_NOTICE, "Corosync successfully moved to root cgroup");
-		res = 0;
-	} else {
-		log_printf(LOGSYS_LEVEL_WARNING, "Can't move Corosync to root cgroup");
-	}
-
 exit_res:
 exit_res:
-	if (root_cgroup != NULL) {
-		cgroup_free(&root_cgroup);
-	}
-
-	/*
-	 * libcgroup doesn't define something like cgroup_fini so there is no way how to clean
-	 * it's cache. It has to be called when libcgroup authors decide to implement it.
-	 */
-
-#endif
 	 return (res);
 	 return (res);
 }
 }
 
 
@@ -1272,7 +1231,8 @@ int main (int argc, char **argv, char **envp)
 					"        -f     : Start application in foreground.\n"\
 					"        -f     : Start application in foreground.\n"\
 					"        -p     : Do not set realtime scheduling.\n"\
 					"        -p     : Do not set realtime scheduling.\n"\
 					"        -r     : Set round robin realtime scheduling (default).\n"\
 					"        -r     : Set round robin realtime scheduling (default).\n"\
-					"        -R     : Do not try move corosync to root cpu cgroup (valid when built with libcgroup)\n" \
+					"        -R     : Do not try move corosync to root cpu cgroup (valid for cgroups enabled systems)\n"\
+					"                 Feature is expected to be removed - see corosync.8 man page\n" \
 					"        -P num : Set priority of process (no effect when -r is used)\n"\
 					"        -P num : Set priority of process (no effect when -r is used)\n"\
 					"        -t     : Test configuration and exit.\n"\
 					"        -t     : Test configuration and exit.\n"\
 					"        -v     : Display version and SVN revision of Corosync and exit.\n");
 					"        -v     : Display version and SVN revision of Corosync and exit.\n");

+ 4 - 2
man/corosync.8

@@ -31,7 +31,7 @@
 .\" * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 .\" * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 .\" * THE POSSIBILITY OF SUCH DAMAGE.
 .\" * THE POSSIBILITY OF SUCH DAMAGE.
 .\" */
 .\" */
-.TH COROSYNC 8 2017-07-07
+.TH COROSYNC 8 2018-08-14
 .SH NAME
 .SH NAME
 corosync \- The Corosync Cluster Engine.
 corosync \- The Corosync Cluster Engine.
 .SH SYNOPSIS
 .SH SYNOPSIS
@@ -64,7 +64,9 @@ of scheduler fails, fallback to set maximal priority.
 .TP
 .TP
 .B -R
 .B -R
 Do not try to move Corosync to root cpu cgroup. This feature is available only
 Do not try to move Corosync to root cpu cgroup. This feature is available only
-for corosync with libcgroup enabled during the build.
+for cgroups with RT sched enabled systems (Linux with
+CONFIG_RT_GROUP_SCHED kernel option). It's also expected to be removed as soon as
+systemd gets support for managing RT configuration.
 .TP
 .TP
 .B -t
 .B -t
 Test configuration and then exit.
 Test configuration and then exit.