Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/tests/sys/aio/local.h
39481 views
1
/*-
2
* Copyright (c) 2016 Chelsio Communications, Inc.
3
* All rights reserved.
4
* Written by: John Baldwin <[email protected]>
5
*
6
* Redistribution and use in source and binary forms, with or without
7
* modification, are permitted provided that the following conditions
8
* are met:
9
* 1. Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* 2. Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
14
*
15
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25
* SUCH DAMAGE.
26
*/
27
28
#ifndef _AIO_TEST_LOCAL_H_
29
#define _AIO_TEST_LOCAL_H_
30
31
#include <sys/types.h>
32
#include <sys/sysctl.h>
33
#include <errno.h>
34
#include <stdio.h>
35
#include <string.h>
36
#include <unistd.h>
37
38
#include <atf-c.h>
39
40
static const char *sysctl_oid_name = "vfs.aio.enable_unsafe";
41
42
static int
43
is_unsafe_aio_enabled(void)
44
{
45
size_t len;
46
int unsafe;
47
48
len = sizeof(unsafe);
49
if (sysctlbyname(sysctl_oid_name, &unsafe, &len, NULL, 0) < 0) {
50
if (errno == ENOENT)
51
return (-1);
52
return (0);
53
}
54
return (unsafe == 0 ? 0 : 1);
55
}
56
57
#define ATF_REQUIRE_UNSAFE_AIO() do { \
58
switch (is_unsafe_aio_enabled()) { \
59
case -1: \
60
atf_libc_error(errno, "Failed to read %s", sysctl_oid_name); \
61
break; \
62
case 0: \
63
atf_tc_skip("Unsafe AIO is disabled"); \
64
break; \
65
default: \
66
printf("Unsafe AIO is enabled\n"); \
67
break; \
68
} \
69
} while (0)
70
71
#define PLAIN_REQUIRE_UNSAFE_AIO(_exit_code) do { \
72
switch (is_unsafe_aio_enabled()) { \
73
case -1: \
74
printf("Failed to read %s", sysctl_oid_name); \
75
_exit(_exit_code); \
76
break; \
77
case 0: \
78
printf("Unsafe AIO is disabled\n"); \
79
_exit(_exit_code); \
80
break; \
81
default: \
82
printf("Unsafe AIO is enabled\n"); \
83
break; \
84
} \
85
} while (0)
86
87
#endif /* !_AIO_TEST_LOCAL_H_ */
88
89