Просмотр исходного кода

build: make libstatgrab the facto default for monitoring service

drop duplicate code and remove the last COROSYNC_LINUX ifdefs
around

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
Reviewed-by: Jan Friesse <jfriesse@redhat.com>
Fabio M. Di Nitto 13 лет назад
Родитель
Сommit
5c5db34e56
3 измененных файлов с 4 добавлено и 63 удалено
  1. 1 10
      configure.ac
  2. 3 0
      corosync.spec.in
  3. 0 53
      exec/mon.c

+ 1 - 10
configure.ac

@@ -413,16 +413,7 @@ if test "x${enable_rdma}" = xyes; then
 fi
 
 if test "x${enable_monitoring}" = xyes; then
-
-	PKG_CHECK_MODULES([statgrab], [libstatgrab], [have_libstatgrab="yes"], [have_libstatgrab="no"])
-
-	if test "x${have_libstatgrab}" = xyes; then
-		AC_DEFINE_UNQUOTED([HAVE_LIBSTATGRAB], 1, [have libstatgrab])
-	else
-		if test "x${have_linux}" = xno; then
-			AC_MSG_ERROR(monitoring requires libstatgrab on non-linux systems)
-		fi
-	fi
+	PKG_CHECK_MODULES([statgrab], [libstatgrab])
 	AC_DEFINE_UNQUOTED([HAVE_MONITORING], 1, [have resource monitoring])
 	PACKAGE_FEATURES="$PACKAGE_FEATURES monitoring"
 fi

+ 3 - 0
corosync.spec.in

@@ -44,6 +44,9 @@ BuildRequires: nss-devel
 %if %{buildtrunk}
 BuildRequires: autoconf automake
 %endif
+%if %{with monitoring}
+BuildRequires: libstatgrab-devel
+%endif
 %if %{with rdma}
 BuildRequires: libibverbs-devel librdmacm-devel
 %endif

+ 0 - 53
exec/mon.c

@@ -35,9 +35,7 @@
 #include <config.h>
 
 #include <unistd.h>
-#if defined(HAVE_LIBSTATGRAB)
 #include <statgrab.h>
-#endif
 
 #include <corosync/corotypes.h>
 #include <corosync/corodefs.h>
@@ -305,7 +303,6 @@ void mon_resource_failed (struct cs_fsm* fsm, int32_t event, void * data)
 
 static int32_t percent_mem_used_get(void)
 {
-#if defined(HAVE_LIBSTATGRAB)
 	sg_mem_stats *mem_stats;
 	sg_swap_stats *swap_stats;
 	long long total, freemem;
@@ -321,42 +318,6 @@ static int32_t percent_mem_used_get(void)
 	total = mem_stats->total + swap_stats->total;
 	freemem = mem_stats->free + swap_stats->free;
 	return ((total - freemem) * 100) / total;
-#else
-#if defined(COROSYNC_LINUX)
-	char *line_ptr;
-	char line[512];
-	unsigned long long value;
-	FILE *f;
-	long long total = 0;
-	long long freemem = 0;
-
-	if ((f = fopen("/proc/meminfo", "r")) == NULL) {
-		return -1;
-	}
-
-	while ((line_ptr = fgets(line, sizeof(line), f)) != NULL) {
-		if (sscanf(line_ptr, "%*s %llu kB", &value) != 1) {
-			continue;
-		}
-		value *= 1024;
-
-		if (strncmp(line_ptr, "MemTotal:", 9) == 0) {
-			total += value;
-		} else if (strncmp(line_ptr, "MemFree:", 8) == 0) {
-			freemem += value;
-		} else if (strncmp(line_ptr, "SwapTotal:", 10) == 0) {
-			total += value;
-		} else if (strncmp(line_ptr, "SwapFree:", 9) == 0) {
-			freemem += value;
-		}
-	}
-
-	fclose(f);
-	return ((total - freemem) * 100) / total;
-#else
-#error need libstatgrab or linux.
-#endif /* COROSYNC_LINUX */
-#endif /* HAVE_LIBSTATGRAB */
 }
 
 static void mem_update_stats_fn (void *data)
@@ -386,7 +347,6 @@ static void mem_update_stats_fn (void *data)
 
 static double min15_loadavg_get(void)
 {
-#if defined(HAVE_LIBSTATGRAB)
 	sg_load_stats *load_stats;
 	load_stats = sg_get_load_stats ();
 	if (load_stats == NULL) {
@@ -395,17 +355,6 @@ static double min15_loadavg_get(void)
 		return -1;
 	}
 	return load_stats->min15;
-#else
-#if defined(COROSYNC_LINUX)
-	double loadav[3];
-	if (getloadavg(loadav,3) < 0) {
-		return -1;
-	}
-	return loadav[2];
-#else
-#error need libstatgrab or linux.
-#endif /* COROSYNC_LINUX */
-#endif /* HAVE_LIBSTATGRAB */
 }
 
 static void load_update_stats_fn (void *data)
@@ -515,9 +464,7 @@ static void mon_instance_init (struct resource_instance* inst)
 static char *mon_exec_init_fn (struct corosync_api_v1 *corosync_api)
 {
 
-#ifdef HAVE_LIBSTATGRAB
 	sg_init();
-#endif /* HAVE_LIBSTATGRAB */
 
 #ifdef COROSYNC_SOLARIS
 	logsys_subsys_init();