Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 9 May 2017 19:16:18 +0000 (UTC)
From:      Ngie Cooper <ngie@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r318098 - head/tests/sys/aio
Message-ID:  <201705091916.v49JGIgd004982@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ngie
Date: Tue May  9 19:16:18 2017
New Revision: 318098
URL: https://svnweb.freebsd.org/changeset/base/318098

Log:
  Refactor ATF_REQUIRE_UNSAFE_AIO and PLAIN_REQUIRE_UNSAFE_AIO
  
  This is being done to reduce duplication between the two macros.
  
  MFC after:	3 weeks
  Sponsored by:	Dell EMC Isilon

Modified:
  head/tests/sys/aio/local.h

Modified: head/tests/sys/aio/local.h
==============================================================================
--- head/tests/sys/aio/local.h	Tue May  9 19:15:11 2017	(r318097)
+++ head/tests/sys/aio/local.h	Tue May  9 19:16:18 2017	(r318098)
@@ -39,36 +39,49 @@
 
 #include <atf-c.h>
 
-#define	ATF_REQUIRE_UNSAFE_AIO() do {					\
-	size_t _len;							\
-	int _unsafe;							\
-									\
-	_len = sizeof(_unsafe);						\
-	if (sysctlbyname("vfs.aio.enable_unsafe", &_unsafe, &_len, NULL,\
-	    0) < 0) {							\
-		if (errno != ENOENT)					\
-			atf_libc_error(errno,				\
-			    "Failed to read vfs.aio.enable_unsafe");	\
-	} else if (_unsafe == 0)					\
-		atf_tc_skip("Unsafe AIO is disabled");			\
+static const char	*sysctl_oid_name = "vfs.aio.enable_unsafe";
+
+static int
+is_unsafe_aio_enabled(void)
+{
+	size_t len;
+	int unsafe;
+
+	len = sizeof(unsafe);
+	if (sysctlbyname(sysctl_oid_name, &unsafe, &len, NULL, 0) < 0) {
+		if (errno == ENOENT)
+			return (-1);
+		return (0);
+	}
+	return (unsafe == 0 ? 0 : 1);
+}
+
+#define	ATF_REQUIRE_UNSAFE_AIO() do {						\
+	switch (is_unsafe_aio_enabled()) {					\
+	case -1:								\
+		atf_libc_error(errno, "Failed to read %s", sysctl_oid_name);	\
+		break;								\
+	case 0:									\
+		atf_tc_skip("Unsafe AIO is disabled");				\
+		break;								\
+	default:								\
+		break;								\
+	}									\
 } while (0)
 
-#define	PLAIN_REQUIRE_UNSAFE_AIO(_exit_code) do {			\
-	size_t _len;							\
-	int _unsafe;							\
-									\
-	_len = sizeof(_unsafe);						\
-	if (sysctlbyname("vfs.aio.enable_unsafe", &_unsafe, &_len, NULL,\
-	    0) < 0) {							\
-		if (errno != ENOENT) {					\
-			printf("Failed to read vfs.aio.enable_unsafe: %s\n",\
-			    strerror(errno));				\
-			_exit(1);					\
-		}							\
-	} else if (_unsafe == 0) {					\
-		printf("Unsafe AIO is disabled");			\
-		_exit(_exit_code);					\
-	}								\
+#define	PLAIN_REQUIRE_UNSAFE_AIO(_exit_code) do {				\
+	switch (is_unsafe_aio_enabled()) {					\
+	case -1:								\
+		printf("Failed to read %s", sysctl_oid_name);			\
+		_exit(_exit_code);						\
+		break;								\
+	case 0:									\
+		printf("Unsafe AIO is disabled\n");				\
+		_exit(_exit_code);						\
+		break;								\
+	default:								\
+		break;								\
+	}									\
 } while (0)
 
 #endif /* !_AIO_TEST_LOCAL_H_ */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201705091916.v49JGIgd004982>