xref: /illumos-gate/usr/src/test/nvme-tests/tests/ioctl/bad-lock.c (revision 533affcbc7fc4d0c8132976ea454aaa715fe2307)
1*533affcbSRobert Mustacchi /*
2*533affcbSRobert Mustacchi  * This file and its contents are supplied under the terms of the
3*533affcbSRobert Mustacchi  * Common Development and Distribution License ("CDDL"), version 1.0.
4*533affcbSRobert Mustacchi  * You may only use this file in accordance with the terms of version
5*533affcbSRobert Mustacchi  * 1.0 of the CDDL.
6*533affcbSRobert Mustacchi  *
7*533affcbSRobert Mustacchi  * A full copy of the text of the CDDL should have accompanied this
8*533affcbSRobert Mustacchi  * source.  A copy of the CDDL is also available via the Internet at
9*533affcbSRobert Mustacchi  * http://www.illumos.org/license/CDDL.
10*533affcbSRobert Mustacchi  */
11*533affcbSRobert Mustacchi 
12*533affcbSRobert Mustacchi /*
13*533affcbSRobert Mustacchi  * Copyright 2024 Oxide Computer Company
14*533affcbSRobert Mustacchi  */
15*533affcbSRobert Mustacchi 
16*533affcbSRobert Mustacchi /*
17*533affcbSRobert Mustacchi  * Test various lock scenarios that should always result in an error. This
18*533affcbSRobert Mustacchi  * includes:
19*533affcbSRobert Mustacchi  *
20*533affcbSRobert Mustacchi  *   o Invalid unknown entities on lock and unlock
21*533affcbSRobert Mustacchi  *   o Invalid lock levels
22*533affcbSRobert Mustacchi  *   o Invalid lock flags
23*533affcbSRobert Mustacchi  *   o Namespace fds trying to do anything with the controller lock
24*533affcbSRobert Mustacchi  *
25*533affcbSRobert Mustacchi  * Then test various unlock scenarios that should always result in an error:
26*533affcbSRobert Mustacchi  *   o Asking to unlock when you don't hold a lock
27*533affcbSRobert Mustacchi  *   o Asking to unlock the wrong lock type when you hold the opposite lock
28*533affcbSRobert Mustacchi  *     (controller only)
29*533affcbSRobert Mustacchi  *   o Asking to unlock the controller lock on a ns fd
30*533affcbSRobert Mustacchi  *
31*533affcbSRobert Mustacchi  * The following aren't currently tested because we don't have tests that
32*533affcbSRobert Mustacchi  * currently distinguish between whether or not we have multiple namespaces.
33*533affcbSRobert Mustacchi  *
34*533affcbSRobert Mustacchi  *   o Asking to unlock a namespace that isn't the one you have locked
35*533affcbSRobert Mustacchi  *     (controller only)
36*533affcbSRobert Mustacchi  */
37*533affcbSRobert Mustacchi 
38*533affcbSRobert Mustacchi #include <err.h>
39*533affcbSRobert Mustacchi #include <stdlib.h>
40*533affcbSRobert Mustacchi #include <unistd.h>
41*533affcbSRobert Mustacchi #include <stdbool.h>
42*533affcbSRobert Mustacchi #include <sys/sysmacros.h>
43*533affcbSRobert Mustacchi #include <sys/debug.h>
44*533affcbSRobert Mustacchi 
45*533affcbSRobert Mustacchi #include "nvme_ioctl_util.h"
46*533affcbSRobert Mustacchi 
47*533affcbSRobert Mustacchi typedef struct {
48*533affcbSRobert Mustacchi 	const char *blt_desc;
49*533affcbSRobert Mustacchi 	nvme_ioctl_lock_t blt_lock;
50*533affcbSRobert Mustacchi 	nvme_ioctl_errno_t blt_err;
51*533affcbSRobert Mustacchi } bad_lock_test_t;
52*533affcbSRobert Mustacchi 
53*533affcbSRobert Mustacchi typedef struct {
54*533affcbSRobert Mustacchi 	const char *but_desc;
55*533affcbSRobert Mustacchi 	nvme_ioctl_unlock_t but_unlock;
56*533affcbSRobert Mustacchi 	nvme_ioctl_errno_t but_err;
57*533affcbSRobert Mustacchi } bad_unlock_test_t;
58*533affcbSRobert Mustacchi 
59*533affcbSRobert Mustacchi static const bad_lock_test_t bad_lock_tests_com[] = { {
60*533affcbSRobert Mustacchi 	.blt_desc = "bad lock entity (1)",
61*533affcbSRobert Mustacchi 	.blt_lock = { .nil_ent = 0, .nil_level = NVME_LOCK_L_READ },
62*533affcbSRobert Mustacchi 	.blt_err = NVME_IOCTL_E_BAD_LOCK_ENTITY
63*533affcbSRobert Mustacchi }, {
64*533affcbSRobert Mustacchi 	.blt_desc = "bad lock entity (2)",
65*533affcbSRobert Mustacchi 	.blt_lock = { .nil_ent = 0x23, .nil_level = NVME_LOCK_L_READ },
66*533affcbSRobert Mustacchi 	.blt_err = NVME_IOCTL_E_BAD_LOCK_ENTITY
67*533affcbSRobert Mustacchi }, {
68*533affcbSRobert Mustacchi 	.blt_desc = "bad lock entity (3)",
69*533affcbSRobert Mustacchi 	.blt_lock = { .nil_ent = INT32_MAX, .nil_level = NVME_LOCK_L_READ },
70*533affcbSRobert Mustacchi 	.blt_err = NVME_IOCTL_E_BAD_LOCK_ENTITY
71*533affcbSRobert Mustacchi } };
72*533affcbSRobert Mustacchi 
73*533affcbSRobert Mustacchi static const bad_lock_test_t bad_lock_tests_ctrl[] = { {
74*533affcbSRobert Mustacchi 	.blt_desc = "bad lock level (1)",
75*533affcbSRobert Mustacchi 	.blt_lock = { .nil_ent = NVME_LOCK_E_CTRL, .nil_level = 0 },
76*533affcbSRobert Mustacchi 	.blt_err = NVME_IOCTL_E_BAD_LOCK_LEVEL
77*533affcbSRobert Mustacchi }, {
78*533affcbSRobert Mustacchi 	.blt_desc = "bad lock level (2)",
79*533affcbSRobert Mustacchi 	.blt_lock = { .nil_ent = NVME_LOCK_E_CTRL, .nil_level = 7 },
80*533affcbSRobert Mustacchi 	.blt_err = NVME_IOCTL_E_BAD_LOCK_LEVEL
81*533affcbSRobert Mustacchi }, {
82*533affcbSRobert Mustacchi 	.blt_desc = "bad lock level (3)",
83*533affcbSRobert Mustacchi 	.blt_lock = { .nil_ent = NVME_LOCK_E_CTRL, .nil_level = UINT32_MAX },
84*533affcbSRobert Mustacchi 	.blt_err = NVME_IOCTL_E_BAD_LOCK_LEVEL
85*533affcbSRobert Mustacchi }, {
86*533affcbSRobert Mustacchi 	.blt_desc = "bad lock level on ns (1)",
87*533affcbSRobert Mustacchi 	.blt_lock = {
88*533affcbSRobert Mustacchi 		.nil_common = { .nioc_nsid = 1 },
89*533affcbSRobert Mustacchi 		.nil_ent = NVME_LOCK_E_NS,
90*533affcbSRobert Mustacchi 		.nil_level = 0
91*533affcbSRobert Mustacchi 	},
92*533affcbSRobert Mustacchi 	.blt_err = NVME_IOCTL_E_BAD_LOCK_LEVEL
93*533affcbSRobert Mustacchi }, {
94*533affcbSRobert Mustacchi 	.blt_desc = "bad lock level on ns (2)",
95*533affcbSRobert Mustacchi 	.blt_lock = {
96*533affcbSRobert Mustacchi 		.nil_common = { .nioc_nsid = 1 },
97*533affcbSRobert Mustacchi 		.nil_ent = NVME_LOCK_E_NS,
98*533affcbSRobert Mustacchi 		.nil_level = 7
99*533affcbSRobert Mustacchi 	},
100*533affcbSRobert Mustacchi 	.blt_err = NVME_IOCTL_E_BAD_LOCK_LEVEL
101*533affcbSRobert Mustacchi }, {
102*533affcbSRobert Mustacchi 	.blt_desc = "bad lock level on ns (3)",
103*533affcbSRobert Mustacchi 	.blt_lock = {
104*533affcbSRobert Mustacchi 		.nil_common = { .nioc_nsid = 1 },
105*533affcbSRobert Mustacchi 		.nil_ent = NVME_LOCK_E_NS,
106*533affcbSRobert Mustacchi 		.nil_level = UINT32_MAX
107*533affcbSRobert Mustacchi 	},
108*533affcbSRobert Mustacchi 	.blt_err = NVME_IOCTL_E_BAD_LOCK_LEVEL
109*533affcbSRobert Mustacchi }, {
110*533affcbSRobert Mustacchi 	.blt_desc = "bad lock flags (1)",
111*533affcbSRobert Mustacchi 	.blt_lock = {
112*533affcbSRobert Mustacchi 		.nil_ent = NVME_LOCK_E_CTRL,
113*533affcbSRobert Mustacchi 		.nil_level = NVME_LOCK_L_READ,
114*533affcbSRobert Mustacchi 		.nil_flags = 0x2
115*533affcbSRobert Mustacchi 	},
116*533affcbSRobert Mustacchi 	.blt_err = NVME_IOCTL_E_BAD_LOCK_FLAGS
117*533affcbSRobert Mustacchi }, {
118*533affcbSRobert Mustacchi 	.blt_desc = "bad lock flags (2)",
119*533affcbSRobert Mustacchi 	.blt_lock = {
120*533affcbSRobert Mustacchi 		.nil_ent = NVME_LOCK_E_CTRL,
121*533affcbSRobert Mustacchi 		.nil_level = NVME_LOCK_L_READ,
122*533affcbSRobert Mustacchi 		.nil_flags = 0x23
123*533affcbSRobert Mustacchi 	},
124*533affcbSRobert Mustacchi 	.blt_err = NVME_IOCTL_E_BAD_LOCK_FLAGS
125*533affcbSRobert Mustacchi }, {
126*533affcbSRobert Mustacchi 	.blt_desc = "bad lock flags on ns (1)",
127*533affcbSRobert Mustacchi 	.blt_lock = {
128*533affcbSRobert Mustacchi 		.nil_common = { .nioc_nsid = 1 },
129*533affcbSRobert Mustacchi 		.nil_ent = NVME_LOCK_E_NS,
130*533affcbSRobert Mustacchi 		.nil_level = NVME_LOCK_L_READ,
131*533affcbSRobert Mustacchi 		.nil_flags = 0x2
132*533affcbSRobert Mustacchi 	},
133*533affcbSRobert Mustacchi 	.blt_err = NVME_IOCTL_E_BAD_LOCK_FLAGS
134*533affcbSRobert Mustacchi }, {
135*533affcbSRobert Mustacchi 	.blt_desc = "bad lock flags on ns (2)",
136*533affcbSRobert Mustacchi 	.blt_lock = {
137*533affcbSRobert Mustacchi 		.nil_common = { .nioc_nsid = 1 },
138*533affcbSRobert Mustacchi 		.nil_ent = NVME_LOCK_E_NS,
139*533affcbSRobert Mustacchi 		.nil_level = NVME_LOCK_L_READ,
140*533affcbSRobert Mustacchi 		.nil_flags = 0x23
141*533affcbSRobert Mustacchi 	},
142*533affcbSRobert Mustacchi 	.blt_err = NVME_IOCTL_E_BAD_LOCK_FLAGS
143*533affcbSRobert Mustacchi } };
144*533affcbSRobert Mustacchi 
145*533affcbSRobert Mustacchi static const bad_lock_test_t bad_lock_tests_ns[] = { {
146*533affcbSRobert Mustacchi 	.blt_desc = "bad lock level (1)",
147*533affcbSRobert Mustacchi 	.blt_lock = { .nil_ent = NVME_LOCK_E_NS, .nil_level = 0 },
148*533affcbSRobert Mustacchi 	.blt_err = NVME_IOCTL_E_BAD_LOCK_LEVEL
149*533affcbSRobert Mustacchi }, {
150*533affcbSRobert Mustacchi 	.blt_desc = "bad lock level (2)",
151*533affcbSRobert Mustacchi 	.blt_lock = { .nil_ent = NVME_LOCK_E_NS, .nil_level = 7 },
152*533affcbSRobert Mustacchi 	.blt_err = NVME_IOCTL_E_BAD_LOCK_LEVEL
153*533affcbSRobert Mustacchi }, {
154*533affcbSRobert Mustacchi 	.blt_desc = "bad lock level (3)",
155*533affcbSRobert Mustacchi 	.blt_lock = { .nil_ent = NVME_LOCK_E_NS, .nil_level = UINT32_MAX },
156*533affcbSRobert Mustacchi 	.blt_err = NVME_IOCTL_E_BAD_LOCK_LEVEL
157*533affcbSRobert Mustacchi }, {
158*533affcbSRobert Mustacchi 	.blt_desc = "bad lock flags (1)",
159*533affcbSRobert Mustacchi 	.blt_lock = {
160*533affcbSRobert Mustacchi 		.nil_ent = NVME_LOCK_E_NS,
161*533affcbSRobert Mustacchi 		.nil_level = NVME_LOCK_L_READ,
162*533affcbSRobert Mustacchi 		.nil_flags = 0x2
163*533affcbSRobert Mustacchi 	},
164*533affcbSRobert Mustacchi 	.blt_err = NVME_IOCTL_E_BAD_LOCK_FLAGS
165*533affcbSRobert Mustacchi }, {
166*533affcbSRobert Mustacchi 	.blt_desc = "bad lock flags (2)",
167*533affcbSRobert Mustacchi 	.blt_lock = {
168*533affcbSRobert Mustacchi 		.nil_ent = NVME_LOCK_E_NS,
169*533affcbSRobert Mustacchi 		.nil_level = NVME_LOCK_L_READ,
170*533affcbSRobert Mustacchi 		.nil_flags = 0x23
171*533affcbSRobert Mustacchi 	},
172*533affcbSRobert Mustacchi 	.blt_err = NVME_IOCTL_E_BAD_LOCK_FLAGS
173*533affcbSRobert Mustacchi }, {
174*533affcbSRobert Mustacchi 	.blt_desc = "ns fd cant take ctrl read lock",
175*533affcbSRobert Mustacchi 	.blt_lock = {
176*533affcbSRobert Mustacchi 		.nil_ent = NVME_LOCK_E_CTRL,
177*533affcbSRobert Mustacchi 		.nil_level = NVME_LOCK_L_READ,
178*533affcbSRobert Mustacchi 		.nil_flags = NVME_LOCK_F_DONT_BLOCK
179*533affcbSRobert Mustacchi 	},
180*533affcbSRobert Mustacchi 	.blt_err = NVME_IOCTL_E_NS_CANNOT_LOCK_CTRL
181*533affcbSRobert Mustacchi }, {
182*533affcbSRobert Mustacchi 	.blt_desc = "ns fd cant take ctrl write lock",
183*533affcbSRobert Mustacchi 	.blt_lock = {
184*533affcbSRobert Mustacchi 		.nil_ent = NVME_LOCK_E_CTRL,
185*533affcbSRobert Mustacchi 		.nil_level = NVME_LOCK_L_WRITE,
186*533affcbSRobert Mustacchi 		.nil_flags = NVME_LOCK_F_DONT_BLOCK
187*533affcbSRobert Mustacchi 	},
188*533affcbSRobert Mustacchi 	.blt_err = NVME_IOCTL_E_NS_CANNOT_LOCK_CTRL
189*533affcbSRobert Mustacchi } };
190*533affcbSRobert Mustacchi 
191*533affcbSRobert Mustacchi static const bad_unlock_test_t bad_unlock_tests_cmn[] = { {
192*533affcbSRobert Mustacchi 	.but_desc = "bad unlock entity (1)",
193*533affcbSRobert Mustacchi 	.but_unlock = { .niu_ent = 0 },
194*533affcbSRobert Mustacchi 	.but_err = NVME_IOCTL_E_BAD_LOCK_ENTITY
195*533affcbSRobert Mustacchi }, {
196*533affcbSRobert Mustacchi 	.but_desc = "bad unlock entity (2)",
197*533affcbSRobert Mustacchi 	.but_unlock = { .niu_ent = 0x23 },
198*533affcbSRobert Mustacchi 	.but_err = NVME_IOCTL_E_BAD_LOCK_ENTITY
199*533affcbSRobert Mustacchi }, {
200*533affcbSRobert Mustacchi 	.but_desc = "bad unlock entity (3)",
201*533affcbSRobert Mustacchi 	.but_unlock = { .niu_ent = INT32_MAX },
202*533affcbSRobert Mustacchi 	.but_err = NVME_IOCTL_E_BAD_LOCK_ENTITY
203*533affcbSRobert Mustacchi } };
204*533affcbSRobert Mustacchi 
205*533affcbSRobert Mustacchi static const bad_unlock_test_t bad_unlock_tests_ctrl[] = { {
206*533affcbSRobert Mustacchi 	.but_desc = "unlock ctrl without lock",
207*533affcbSRobert Mustacchi 	.but_unlock = { .niu_ent = NVME_LOCK_E_CTRL },
208*533affcbSRobert Mustacchi 	.but_err = NVME_IOCTL_E_LOCK_NOT_HELD,
209*533affcbSRobert Mustacchi }, {
210*533affcbSRobert Mustacchi 	.but_desc = "unlock ns without lock",
211*533affcbSRobert Mustacchi 	.but_unlock = {
212*533affcbSRobert Mustacchi 		.niu_common = { .nioc_nsid = 1 },
213*533affcbSRobert Mustacchi 		.niu_ent = NVME_LOCK_E_NS
214*533affcbSRobert Mustacchi 	},
215*533affcbSRobert Mustacchi 	.but_err = NVME_IOCTL_E_LOCK_NOT_HELD
216*533affcbSRobert Mustacchi } };
217*533affcbSRobert Mustacchi 
218*533affcbSRobert Mustacchi static const bad_unlock_test_t bad_unlock_tests_ns[] = { {
219*533affcbSRobert Mustacchi 	.but_desc = "unlock ns without lock",
220*533affcbSRobert Mustacchi 	.but_unlock = { .niu_ent = NVME_LOCK_E_NS },
221*533affcbSRobert Mustacchi 	.but_err = NVME_IOCTL_E_LOCK_NOT_HELD
222*533affcbSRobert Mustacchi }, {
223*533affcbSRobert Mustacchi 	.but_desc = "unlock ctrl from ns fd",
224*533affcbSRobert Mustacchi 	.but_unlock = { .niu_ent = NVME_LOCK_E_CTRL },
225*533affcbSRobert Mustacchi 	.but_err = NVME_IOCTL_E_NS_CANNOT_UNLOCK_CTRL
226*533affcbSRobert Mustacchi } };
227*533affcbSRobert Mustacchi 
228*533affcbSRobert Mustacchi static const bad_unlock_test_t bad_unlock_tests_ctrl_w_ctrl[] = { {
229*533affcbSRobert Mustacchi 	.but_desc = "unlock ns with control lock",
230*533affcbSRobert Mustacchi 	.but_unlock = {
231*533affcbSRobert Mustacchi 		.niu_common = { .nioc_nsid = 1 },
232*533affcbSRobert Mustacchi 		.niu_ent = NVME_LOCK_E_NS
233*533affcbSRobert Mustacchi 	},
234*533affcbSRobert Mustacchi 	.but_err = NVME_IOCTL_E_LOCK_NOT_HELD
235*533affcbSRobert Mustacchi } };
236*533affcbSRobert Mustacchi 
237*533affcbSRobert Mustacchi static const bad_unlock_test_t bad_unlock_tests_ctrl_w_ns[] = { {
238*533affcbSRobert Mustacchi 	.but_desc = "unlock ctrl with ns lock",
239*533affcbSRobert Mustacchi 	.but_unlock = {
240*533affcbSRobert Mustacchi 		.niu_ent = NVME_LOCK_E_CTRL
241*533affcbSRobert Mustacchi 	},
242*533affcbSRobert Mustacchi 	.but_err = NVME_IOCTL_E_LOCK_NOT_HELD
243*533affcbSRobert Mustacchi } };
244*533affcbSRobert Mustacchi 
245*533affcbSRobert Mustacchi static bool
bad_lock_test(int fd,const bad_lock_test_t * test,bool ns)246*533affcbSRobert Mustacchi bad_lock_test(int fd, const bad_lock_test_t *test, bool ns)
247*533affcbSRobert Mustacchi {
248*533affcbSRobert Mustacchi 	nvme_ioctl_lock_t lock = test->blt_lock;
249*533affcbSRobert Mustacchi 	const char *type = ns ? "(ns)" : "(ctrl)";
250*533affcbSRobert Mustacchi 
251*533affcbSRobert Mustacchi 	if (ioctl(fd, NVME_IOC_LOCK, &lock) != 0) {
252*533affcbSRobert Mustacchi 		warn("TEST FAILED: %s %s: failed to issue lock ioctl",
253*533affcbSRobert Mustacchi 		    test->blt_desc, type);
254*533affcbSRobert Mustacchi 		return (false);
255*533affcbSRobert Mustacchi 	}
256*533affcbSRobert Mustacchi 
257*533affcbSRobert Mustacchi 	if (lock.nil_common.nioc_drv_err != test->blt_err) {
258*533affcbSRobert Mustacchi 		warnx("TEST FAILED: %s %s: lock ioctl failed with 0x%x, "
259*533affcbSRobert Mustacchi 		    "expected 0x%x", test->blt_desc, type,
260*533affcbSRobert Mustacchi 		    lock.nil_common.nioc_drv_err, test->blt_err);
261*533affcbSRobert Mustacchi 		return (false);
262*533affcbSRobert Mustacchi 	}
263*533affcbSRobert Mustacchi 
264*533affcbSRobert Mustacchi 	(void) printf("TEST PASSED: %s %s\n", test->blt_desc, type);
265*533affcbSRobert Mustacchi 	return (true);
266*533affcbSRobert Mustacchi }
267*533affcbSRobert Mustacchi 
268*533affcbSRobert Mustacchi static bool
bad_unlock_test(int fd,const bad_unlock_test_t * test,bool ns)269*533affcbSRobert Mustacchi bad_unlock_test(int fd, const bad_unlock_test_t *test, bool ns)
270*533affcbSRobert Mustacchi {
271*533affcbSRobert Mustacchi 	nvme_ioctl_unlock_t unlock = test->but_unlock;
272*533affcbSRobert Mustacchi 	const char *type = ns ? "(ns)" : "(ctrl)";
273*533affcbSRobert Mustacchi 
274*533affcbSRobert Mustacchi 	if (ioctl(fd, NVME_IOC_UNLOCK, &unlock) != 0) {
275*533affcbSRobert Mustacchi 		warn("TEST FAILED: %s %s: failed to issue unlock ioctl",
276*533affcbSRobert Mustacchi 		    test->but_desc, type);
277*533affcbSRobert Mustacchi 		return (false);
278*533affcbSRobert Mustacchi 	}
279*533affcbSRobert Mustacchi 
280*533affcbSRobert Mustacchi 	if (unlock.niu_common.nioc_drv_err != test->but_err) {
281*533affcbSRobert Mustacchi 		warnx("TEST FAILED: %s %s: unlock ioctl failed with 0x%x, "
282*533affcbSRobert Mustacchi 		    "expected 0x%x", test->but_desc, type,
283*533affcbSRobert Mustacchi 		    unlock.niu_common.nioc_drv_err, test->but_err);
284*533affcbSRobert Mustacchi 		return (false);
285*533affcbSRobert Mustacchi 	}
286*533affcbSRobert Mustacchi 
287*533affcbSRobert Mustacchi 	(void) printf("TEST PASSED: %s %s\n", test->but_desc, type);
288*533affcbSRobert Mustacchi 	return (true);
289*533affcbSRobert Mustacchi }
290*533affcbSRobert Mustacchi 
291*533affcbSRobert Mustacchi int
main(void)292*533affcbSRobert Mustacchi main(void)
293*533affcbSRobert Mustacchi {
294*533affcbSRobert Mustacchi 	int ret = EXIT_SUCCESS;
295*533affcbSRobert Mustacchi 	int fd = nvme_ioctl_test_get_fd(0);
296*533affcbSRobert Mustacchi 
297*533affcbSRobert Mustacchi 	for (size_t i = 0; i < ARRAY_SIZE(bad_lock_tests_com); i++) {
298*533affcbSRobert Mustacchi 		if (!bad_lock_test(fd, &bad_lock_tests_com[i], false)) {
299*533affcbSRobert Mustacchi 			ret = EXIT_FAILURE;
300*533affcbSRobert Mustacchi 		}
301*533affcbSRobert Mustacchi 	}
302*533affcbSRobert Mustacchi 
303*533affcbSRobert Mustacchi 	for (size_t i = 0; i < ARRAY_SIZE(bad_lock_tests_ctrl); i++) {
304*533affcbSRobert Mustacchi 		if (!bad_lock_test(fd, &bad_lock_tests_ctrl[i], false)) {
305*533affcbSRobert Mustacchi 			ret = EXIT_FAILURE;
306*533affcbSRobert Mustacchi 		}
307*533affcbSRobert Mustacchi 	}
308*533affcbSRobert Mustacchi 
309*533affcbSRobert Mustacchi 	for (size_t i = 0; i < ARRAY_SIZE(bad_unlock_tests_cmn); i++) {
310*533affcbSRobert Mustacchi 		if (!bad_unlock_test(fd, &bad_unlock_tests_cmn[i], false)) {
311*533affcbSRobert Mustacchi 			ret = EXIT_FAILURE;
312*533affcbSRobert Mustacchi 		}
313*533affcbSRobert Mustacchi 	}
314*533affcbSRobert Mustacchi 
315*533affcbSRobert Mustacchi 	for (size_t i = 0; i < ARRAY_SIZE(bad_unlock_tests_ctrl); i++) {
316*533affcbSRobert Mustacchi 		if (!bad_unlock_test(fd, &bad_unlock_tests_ctrl[i], false)) {
317*533affcbSRobert Mustacchi 			ret = EXIT_FAILURE;
318*533affcbSRobert Mustacchi 		}
319*533affcbSRobert Mustacchi 	}
320*533affcbSRobert Mustacchi 
321*533affcbSRobert Mustacchi 	VERIFY0(close(fd));
322*533affcbSRobert Mustacchi 	fd = nvme_ioctl_test_get_fd(1);
323*533affcbSRobert Mustacchi 
324*533affcbSRobert Mustacchi 	for (size_t i = 0; i < ARRAY_SIZE(bad_lock_tests_com); i++) {
325*533affcbSRobert Mustacchi 		if (!bad_lock_test(fd, &bad_lock_tests_com[i], true)) {
326*533affcbSRobert Mustacchi 			ret = EXIT_FAILURE;
327*533affcbSRobert Mustacchi 		}
328*533affcbSRobert Mustacchi 	}
329*533affcbSRobert Mustacchi 
330*533affcbSRobert Mustacchi 	for (size_t i = 0; i < ARRAY_SIZE(bad_lock_tests_ns); i++) {
331*533affcbSRobert Mustacchi 		if (!bad_lock_test(fd, &bad_lock_tests_ns[i], true)) {
332*533affcbSRobert Mustacchi 			ret = EXIT_FAILURE;
333*533affcbSRobert Mustacchi 		}
334*533affcbSRobert Mustacchi 	}
335*533affcbSRobert Mustacchi 
336*533affcbSRobert Mustacchi 	for (size_t i = 0; i < ARRAY_SIZE(bad_unlock_tests_cmn); i++) {
337*533affcbSRobert Mustacchi 		if (!bad_unlock_test(fd, &bad_unlock_tests_cmn[i], true)) {
338*533affcbSRobert Mustacchi 			ret = EXIT_FAILURE;
339*533affcbSRobert Mustacchi 		}
340*533affcbSRobert Mustacchi 	}
341*533affcbSRobert Mustacchi 
342*533affcbSRobert Mustacchi 	for (size_t i = 0; i < ARRAY_SIZE(bad_unlock_tests_ns); i++) {
343*533affcbSRobert Mustacchi 		if (!bad_unlock_test(fd, &bad_unlock_tests_ns[i], true)) {
344*533affcbSRobert Mustacchi 			ret = EXIT_FAILURE;
345*533affcbSRobert Mustacchi 		}
346*533affcbSRobert Mustacchi 	}
347*533affcbSRobert Mustacchi 	VERIFY0(close(fd));
348*533affcbSRobert Mustacchi 
349*533affcbSRobert Mustacchi 	/*
350*533affcbSRobert Mustacchi 	 * Unlock tests that require a lock to be held.
351*533affcbSRobert Mustacchi 	 */
352*533affcbSRobert Mustacchi 	fd = nvme_ioctl_test_get_fd(0);
353*533affcbSRobert Mustacchi 	nvme_ioctl_test_lock(fd, &nvme_test_ctrl_rdlock);
354*533affcbSRobert Mustacchi 	for (size_t i = 0; i < ARRAY_SIZE(bad_unlock_tests_ctrl_w_ctrl); i++) {
355*533affcbSRobert Mustacchi 		if (!bad_unlock_test(fd, &bad_unlock_tests_ctrl_w_ctrl[i],
356*533affcbSRobert Mustacchi 		    false)) {
357*533affcbSRobert Mustacchi 			ret = EXIT_FAILURE;
358*533affcbSRobert Mustacchi 		}
359*533affcbSRobert Mustacchi 	}
360*533affcbSRobert Mustacchi 
361*533affcbSRobert Mustacchi 	VERIFY0(close(fd));
362*533affcbSRobert Mustacchi 	fd = nvme_ioctl_test_get_fd(0);
363*533affcbSRobert Mustacchi 	nvme_ioctl_test_lock(fd, &nvme_test_ns_rdlock);
364*533affcbSRobert Mustacchi 	for (size_t i = 0; i < ARRAY_SIZE(bad_unlock_tests_ctrl_w_ns); i++) {
365*533affcbSRobert Mustacchi 		if (!bad_unlock_test(fd, &bad_unlock_tests_ctrl_w_ns[i],
366*533affcbSRobert Mustacchi 		    false)) {
367*533affcbSRobert Mustacchi 			ret = EXIT_FAILURE;
368*533affcbSRobert Mustacchi 		}
369*533affcbSRobert Mustacchi 	}
370*533affcbSRobert Mustacchi 
371*533affcbSRobert Mustacchi 	VERIFY0(close(fd));
372*533affcbSRobert Mustacchi 
373*533affcbSRobert Mustacchi 	return (ret);
374*533affcbSRobert Mustacchi }
375