Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright (C) 2016 Intel Corporation. All rights reserved.
3 : : * Copyright (c) 2019 Mellanox Technologies LTD. All rights reserved.
4 : : */
5 : :
6 : : #include "spdk/stdinc.h"
7 : :
8 : : #include "common/lib/ut_multithread.c"
9 : : #include "spdk_internal/cunit.h"
10 : : #include "spdk/nvmf.h"
11 : : #include "spdk_internal/mock.h"
12 : :
13 : : #include "spdk/bdev_module.h"
14 : : #include "nvmf/subsystem.c"
15 : : #include "nvmf/transport.c"
16 : :
17 : 5 : SPDK_LOG_REGISTER_COMPONENT(nvmf)
18 : :
19 [ - + ]: 25 : DEFINE_STUB(spdk_bdev_module_claim_bdev,
20 : : int,
21 : : (struct spdk_bdev *bdev, struct spdk_bdev_desc *desc,
22 : : struct spdk_bdev_module *module), 0);
23 : :
24 : 30 : DEFINE_STUB_V(spdk_bdev_module_release_bdev,
25 : : (struct spdk_bdev *bdev));
26 : :
27 [ # # ]: 0 : DEFINE_STUB(spdk_bdev_get_block_size, uint32_t,
28 : : (const struct spdk_bdev *bdev), 512);
29 : :
30 [ - + ]: 25 : DEFINE_STUB(spdk_bdev_get_md_size, uint32_t,
31 : : (const struct spdk_bdev *bdev), 0);
32 : :
33 [ # # # # ]: 0 : DEFINE_STUB(spdk_bdev_is_md_interleaved, bool,
34 : : (const struct spdk_bdev *bdev), false);
35 : :
36 [ - + - + ]: 25 : DEFINE_STUB(spdk_bdev_io_type_supported, bool,
37 : : (struct spdk_bdev *bdev,
38 : : enum spdk_bdev_io_type io_type), false);
39 : :
40 : 0 : DEFINE_STUB_V(nvmf_update_discovery_log,
41 : : (struct spdk_nvmf_tgt *tgt, const char *hostnqn));
42 [ # # ]: 0 : DEFINE_STUB(spdk_nvmf_qpair_disconnect, int, (struct spdk_nvmf_qpair *qpair), 0);
43 : :
44 [ # # ]: 0 : DEFINE_STUB(spdk_nvmf_request_complete,
45 : : int,
46 : : (struct spdk_nvmf_request *req), 0);
47 : :
48 [ # # ]: 0 : DEFINE_STUB(nvmf_ctrlr_async_event_ana_change_notice,
49 : : int,
50 : : (struct spdk_nvmf_ctrlr *ctrlr), 0);
51 : :
52 [ # # ]: 0 : DEFINE_STUB(spdk_nvme_transport_id_trtype_str,
53 : : const char *,
54 : : (enum spdk_nvme_transport_type trtype), NULL);
55 : :
56 [ - + - + ]: 25 : DEFINE_STUB(spdk_bdev_is_zoned, bool,
57 : : (const struct spdk_bdev *bdev), false);
58 : :
59 [ # # ]: 0 : DEFINE_STUB(spdk_bdev_get_max_zone_append_size, uint32_t,
60 : : (const struct spdk_bdev *bdev), 0);
61 : :
62 [ # # ]: 0 : DEFINE_STUB(spdk_mempool_lookup, struct spdk_mempool *,
63 : : (const char *name), NULL);
64 : :
65 [ # # ]: 0 : DEFINE_STUB(spdk_nvme_transport_id_adrfam_str, const char *,
66 : : (enum spdk_nvmf_adrfam adrfam), NULL);
67 : :
68 [ # # ]: 0 : DEFINE_STUB(spdk_nvmf_qpair_get_listen_trid, int,
69 : : (struct spdk_nvmf_qpair *qpair,
70 : : struct spdk_nvme_transport_id *trid), 0);
71 [ # # ]: 0 : DEFINE_STUB(spdk_key_dup, struct spdk_key *, (struct spdk_key *k), NULL);
72 [ # # ]: 0 : DEFINE_STUB(spdk_key_get_name, const char *, (struct spdk_key *k), NULL);
73 : 20 : DEFINE_STUB_V(spdk_keyring_put_key, (struct spdk_key *k));
74 [ # # # # ]: 0 : DEFINE_STUB(nvmf_auth_is_supported, bool, (void), false);
75 : :
76 : : static struct spdk_nvmf_transport g_transport = {};
77 : :
78 : : struct spdk_nvmf_subsystem *
79 : 110 : spdk_nvmf_tgt_find_subsystem(struct spdk_nvmf_tgt *tgt, const char *subnqn)
80 : : {
81 : 110 : return NULL;
82 : : }
83 : :
84 : : struct spdk_nvmf_transport *
85 : 0 : spdk_nvmf_tgt_get_transport(struct spdk_nvmf_tgt *tgt, const char *transport_name)
86 : : {
87 [ # # # # ]: 0 : if (strncmp(transport_name, SPDK_NVME_TRANSPORT_NAME_RDMA, SPDK_NVMF_TRSTRING_MAX_LEN)) {
88 : 0 : return &g_transport;
89 : : }
90 : :
91 : 0 : return NULL;
92 : : }
93 : :
94 : : int
95 : 0 : nvmf_poll_group_update_subsystem(struct spdk_nvmf_poll_group *group,
96 : : struct spdk_nvmf_subsystem *subsystem)
97 : : {
98 : 0 : return 0;
99 : : }
100 : :
101 : : int
102 : 0 : nvmf_poll_group_add_subsystem(struct spdk_nvmf_poll_group *group,
103 : : struct spdk_nvmf_subsystem *subsystem,
104 : : spdk_nvmf_poll_group_mod_done cb_fn, void *cb_arg)
105 : : {
106 : 0 : return 0;
107 : : }
108 : :
109 : : void
110 : 0 : nvmf_poll_group_remove_subsystem(struct spdk_nvmf_poll_group *group,
111 : : struct spdk_nvmf_subsystem *subsystem,
112 : : spdk_nvmf_poll_group_mod_done cb_fn, void *cb_arg)
113 : : {
114 : 0 : }
115 : :
116 : : void
117 : 0 : nvmf_poll_group_pause_subsystem(struct spdk_nvmf_poll_group *group,
118 : : struct spdk_nvmf_subsystem *subsystem,
119 : : uint32_t nsid,
120 : : spdk_nvmf_poll_group_mod_done cb_fn, void *cb_arg)
121 : : {
122 : 0 : }
123 : :
124 : : void
125 : 0 : nvmf_poll_group_resume_subsystem(struct spdk_nvmf_poll_group *group,
126 : : struct spdk_nvmf_subsystem *subsystem,
127 : : spdk_nvmf_poll_group_mod_done cb_fn, void *cb_arg)
128 : : {
129 : 0 : }
130 : :
131 : : int
132 : 0 : spdk_nvme_transport_id_parse_trtype(enum spdk_nvme_transport_type *trtype, const char *str)
133 : : {
134 [ # # # # ]: 0 : if (trtype == NULL || str == NULL) {
135 : 0 : return -EINVAL;
136 : : }
137 : :
138 [ # # # # ]: 0 : if (strcasecmp(str, "PCIe") == 0) {
139 : 0 : *trtype = SPDK_NVME_TRANSPORT_PCIE;
140 [ # # # # ]: 0 : } else if (strcasecmp(str, "RDMA") == 0) {
141 : 0 : *trtype = SPDK_NVME_TRANSPORT_RDMA;
142 : : } else {
143 : 0 : return -ENOENT;
144 : : }
145 : 0 : return 0;
146 : : }
147 : :
148 : : int
149 : 0 : spdk_nvme_transport_id_compare(const struct spdk_nvme_transport_id *trid1,
150 : : const struct spdk_nvme_transport_id *trid2)
151 : : {
152 : 0 : return 0;
153 : : }
154 : :
155 : : int32_t
156 : 0 : spdk_nvme_ctrlr_process_admin_completions(struct spdk_nvme_ctrlr *ctrlr)
157 : : {
158 : 0 : return -1;
159 : : }
160 : :
161 : : int32_t
162 : 0 : spdk_nvme_qpair_process_completions(struct spdk_nvme_qpair *qpair, uint32_t max_completions)
163 : : {
164 : 0 : return -1;
165 : : }
166 : :
167 : : int
168 : 0 : spdk_nvme_detach(struct spdk_nvme_ctrlr *ctrlr)
169 : : {
170 : 0 : return -1;
171 : : }
172 : :
173 : : void
174 : 0 : nvmf_ctrlr_destruct(struct spdk_nvmf_ctrlr *ctrlr)
175 : : {
176 : 0 : }
177 : :
178 : : static struct spdk_nvmf_ctrlr *g_ns_changed_ctrlr = NULL;
179 : : static uint32_t g_ns_changed_nsid = 0;
180 : : void
181 : 30 : nvmf_ctrlr_ns_changed(struct spdk_nvmf_ctrlr *ctrlr, uint32_t nsid)
182 : : {
183 : 30 : g_ns_changed_ctrlr = ctrlr;
184 : 30 : g_ns_changed_nsid = nsid;
185 : 30 : }
186 : :
187 : :
188 : : static struct spdk_nvmf_ctrlr *g_async_event_ctrlr = NULL;
189 : : int
190 : 15 : nvmf_ctrlr_async_event_ns_notice(struct spdk_nvmf_ctrlr *ctrlr)
191 : : {
192 : 15 : g_async_event_ctrlr = ctrlr;
193 : 15 : return 0;
194 : : }
195 : :
196 : : static struct spdk_bdev g_bdevs[] = {
197 : : { .name = "bdev1" },
198 : : { .name = "bdev2" },
199 : : { .name = "bdev3", .ctratt.raw = 0x80000 },
200 : : };
201 : :
202 : : struct spdk_bdev_desc {
203 : : struct spdk_bdev *bdev;
204 : : };
205 : :
206 : : int
207 : 25 : spdk_bdev_open_ext(const char *bdev_name, bool write, spdk_bdev_event_cb_t event_cb,
208 : : void *event_ctx, struct spdk_bdev_desc **_desc)
209 : : {
210 : : struct spdk_bdev_desc *desc;
211 : : size_t i;
212 : :
213 [ + - ]: 45 : for (i = 0; i < sizeof(g_bdevs); i++) {
214 [ + + - + : 45 : if (strcmp(bdev_name, g_bdevs[i].name) == 0) {
+ + ]
215 : :
216 : 25 : desc = calloc(1, sizeof(*desc));
217 [ - + ]: 25 : SPDK_CU_ASSERT_FATAL(desc != NULL);
218 : :
219 : 25 : desc->bdev = &g_bdevs[i];
220 : 25 : *_desc = desc;
221 : 25 : return 0;
222 : : }
223 : : }
224 : :
225 : 0 : return -EINVAL;
226 : : }
227 : :
228 : : void
229 : 30 : spdk_bdev_close(struct spdk_bdev_desc *desc)
230 : : {
231 : 30 : free(desc);
232 : 30 : }
233 : :
234 : : struct spdk_bdev *
235 : 25 : spdk_bdev_desc_get_bdev(struct spdk_bdev_desc *desc)
236 : : {
237 : 25 : return desc->bdev;
238 : : }
239 : :
240 : : const char *
241 : 0 : spdk_bdev_get_name(const struct spdk_bdev *bdev)
242 : : {
243 : 0 : return "test";
244 : : }
245 : :
246 : : const struct spdk_uuid *
247 : 105 : spdk_bdev_get_uuid(const struct spdk_bdev *bdev)
248 : : {
249 : 105 : return &bdev->uuid;
250 : : }
251 : :
252 : 35 : union spdk_bdev_nvme_ctratt spdk_bdev_get_nvme_ctratt(struct spdk_bdev *bdev)
253 : : {
254 : 35 : return bdev->ctratt;
255 : : }
256 : :
257 : : static void
258 : 5 : test_spdk_nvmf_subsystem_add_ns(void)
259 : : {
260 : 5 : struct spdk_nvmf_tgt tgt = {};
261 : 5 : struct spdk_nvmf_subsystem subsystem = {
262 : : .max_nsid = 1024,
263 : : .ns = NULL,
264 : : .tgt = &tgt,
265 : : };
266 : 4 : struct spdk_nvmf_ns_opts ns_opts;
267 : : uint32_t nsid;
268 : : int rc;
269 : :
270 : 5 : subsystem.ns = calloc(subsystem.max_nsid, sizeof(struct spdk_nvmf_subsystem_ns *));
271 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(subsystem.ns != NULL);
272 : 5 : subsystem.ana_group = calloc(subsystem.max_nsid, sizeof(uint32_t));
273 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(subsystem.ana_group != NULL);
274 : :
275 : 5 : tgt.max_subsystems = 1024;
276 : 5 : RB_INIT(&tgt.subsystems);
277 : :
278 : : /* Request a specific NSID */
279 : 5 : spdk_nvmf_ns_opts_get_defaults(&ns_opts, sizeof(ns_opts));
280 : 5 : ns_opts.nsid = 5;
281 : 5 : nsid = spdk_nvmf_subsystem_add_ns_ext(&subsystem, "bdev2", &ns_opts, sizeof(ns_opts), NULL);
282 : 5 : CU_ASSERT(nsid == 5);
283 : 5 : CU_ASSERT(subsystem.max_nsid == 1024);
284 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(subsystem.ns[nsid - 1] != NULL);
285 : 5 : CU_ASSERT(subsystem.ns[nsid - 1]->bdev == &g_bdevs[1]);
286 : :
287 : : /* Request an NSID that is already in use */
288 : 5 : spdk_nvmf_ns_opts_get_defaults(&ns_opts, sizeof(ns_opts));
289 : 5 : ns_opts.nsid = 5;
290 : 5 : nsid = spdk_nvmf_subsystem_add_ns_ext(&subsystem, "bdev2", &ns_opts, sizeof(ns_opts), NULL);
291 : 5 : CU_ASSERT(nsid == 0);
292 : 5 : CU_ASSERT(subsystem.max_nsid == 1024);
293 : :
294 : : /* Request 0xFFFFFFFF (invalid NSID, reserved for broadcast) */
295 : 5 : spdk_nvmf_ns_opts_get_defaults(&ns_opts, sizeof(ns_opts));
296 : 5 : ns_opts.nsid = 0xFFFFFFFF;
297 : 5 : nsid = spdk_nvmf_subsystem_add_ns_ext(&subsystem, "bdev2", &ns_opts, sizeof(ns_opts), NULL);
298 : 5 : CU_ASSERT(nsid == 0);
299 : 5 : CU_ASSERT(subsystem.max_nsid == 1024);
300 : :
301 : 5 : rc = spdk_nvmf_subsystem_remove_ns(&subsystem, 5);
302 : 5 : CU_ASSERT(rc == 0);
303 : :
304 : 5 : free(subsystem.ns);
305 : 5 : free(subsystem.ana_group);
306 : 5 : }
307 : :
308 : : static void
309 : 5 : test_spdk_nvmf_subsystem_add_fdp_ns(void)
310 : : {
311 : 5 : struct spdk_nvmf_tgt tgt = {};
312 : 5 : struct spdk_nvmf_subsystem subsystem = {
313 : : .max_nsid = 1024,
314 : : .ns = NULL,
315 : : .tgt = &tgt,
316 : : };
317 : 4 : struct spdk_nvmf_ns_opts ns_opts;
318 : : uint32_t nsid;
319 : : int rc;
320 : :
321 : 5 : subsystem.ns = calloc(subsystem.max_nsid, sizeof(struct spdk_nvmf_subsystem_ns *));
322 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(subsystem.ns != NULL);
323 : 5 : subsystem.ana_group = calloc(subsystem.max_nsid, sizeof(uint32_t));
324 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(subsystem.ana_group != NULL);
325 : :
326 : 5 : tgt.max_subsystems = 1024;
327 : 5 : RB_INIT(&tgt.subsystems);
328 : :
329 [ - + ]: 5 : CU_ASSERT(subsystem.fdp_supported == false);
330 : :
331 : : /* Add a FDP supported namespace to the subsystem */
332 : 5 : spdk_nvmf_ns_opts_get_defaults(&ns_opts, sizeof(ns_opts));
333 : 5 : ns_opts.nsid = 3;
334 : 5 : nsid = spdk_nvmf_subsystem_add_ns_ext(&subsystem, "bdev3", &ns_opts, sizeof(ns_opts), NULL);
335 : 5 : CU_ASSERT(nsid == 3);
336 : 5 : CU_ASSERT(subsystem.max_nsid == 1024);
337 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(subsystem.ns[nsid - 1] != NULL);
338 : 5 : CU_ASSERT(subsystem.ns[nsid - 1]->bdev == &g_bdevs[2]);
339 [ - + ]: 5 : CU_ASSERT(subsystem.fdp_supported == true);
340 : :
341 : : /* Try to add a non FDP supported namespace to the subsystem */
342 : 5 : spdk_nvmf_ns_opts_get_defaults(&ns_opts, sizeof(ns_opts));
343 : 5 : ns_opts.nsid = 5;
344 : 5 : nsid = spdk_nvmf_subsystem_add_ns_ext(&subsystem, "bdev2", &ns_opts, sizeof(ns_opts), NULL);
345 : 5 : CU_ASSERT(nsid == 0);
346 : 5 : CU_ASSERT(subsystem.max_nsid == 1024);
347 [ - + ]: 5 : CU_ASSERT(subsystem.fdp_supported == true);
348 : :
349 : : /* Remove last FDP namespace from the subsystem */
350 : 5 : rc = spdk_nvmf_subsystem_remove_ns(&subsystem, 3);
351 : 5 : CU_ASSERT(rc == 0);
352 [ - + ]: 5 : CU_ASSERT(subsystem.fdp_supported == false);
353 : :
354 : 5 : free(subsystem.ns);
355 : 5 : free(subsystem.ana_group);
356 : 5 : }
357 : :
358 : : static void
359 : 5 : nvmf_test_create_subsystem(void)
360 : : {
361 : 5 : struct spdk_nvmf_tgt tgt = {};
362 : 4 : char nqn[256];
363 : : struct spdk_nvmf_subsystem *subsystem;
364 : : int rc;
365 : :
366 : 5 : tgt.max_subsystems = 1024;
367 : 5 : tgt.subsystem_ids = spdk_bit_array_create(tgt.max_subsystems);
368 : 5 : RB_INIT(&tgt.subsystems);
369 : :
370 : 5 : snprintf(nqn, sizeof(nqn), "nqn.2016-06.io.spdk:subsystem1");
371 : 5 : subsystem = spdk_nvmf_subsystem_create(&tgt, nqn, SPDK_NVMF_SUBTYPE_NVME, 0);
372 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(subsystem != NULL);
373 [ - + ]: 5 : CU_ASSERT_STRING_EQUAL(subsystem->subnqn, nqn);
374 : 5 : rc = spdk_nvmf_subsystem_destroy(subsystem, NULL, NULL);
375 : 5 : CU_ASSERT(rc == 0);
376 : :
377 : : /* valid name with complex reverse domain */
378 : 5 : snprintf(nqn, sizeof(nqn), "nqn.2016-06.io.spdk-full--rev-domain.name:subsystem1");
379 : 5 : subsystem = spdk_nvmf_subsystem_create(&tgt, nqn, SPDK_NVMF_SUBTYPE_NVME, 0);
380 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(subsystem != NULL);
381 [ - + ]: 5 : CU_ASSERT_STRING_EQUAL(subsystem->subnqn, nqn);
382 : 5 : rc = spdk_nvmf_subsystem_destroy(subsystem, NULL, NULL);
383 : 5 : CU_ASSERT(rc == 0);
384 : :
385 : : /* Valid name discovery controller */
386 : 5 : snprintf(nqn, sizeof(nqn), "nqn.2016-06.io.spdk:subsystem1");
387 : 5 : subsystem = spdk_nvmf_subsystem_create(&tgt, nqn, SPDK_NVMF_SUBTYPE_NVME, 0);
388 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(subsystem != NULL);
389 [ - + ]: 5 : CU_ASSERT_STRING_EQUAL(subsystem->subnqn, nqn);
390 : 5 : rc = spdk_nvmf_subsystem_destroy(subsystem, NULL, NULL);
391 : 5 : CU_ASSERT(rc == 0);
392 : :
393 : : /* Invalid name, no user supplied string */
394 : 5 : snprintf(nqn, sizeof(nqn), "nqn.2016-06.io.spdk:");
395 : 5 : subsystem = spdk_nvmf_subsystem_create(&tgt, nqn, SPDK_NVMF_SUBTYPE_NVME, 0);
396 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(subsystem == NULL);
397 : :
398 : : /* Valid name, only contains top-level domain name */
399 : 5 : snprintf(nqn, sizeof(nqn), "nqn.2016-06.io.spdk:subsystem1");
400 : 5 : subsystem = spdk_nvmf_subsystem_create(&tgt, nqn, SPDK_NVMF_SUBTYPE_NVME, 0);
401 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(subsystem != NULL);
402 [ - + ]: 5 : CU_ASSERT_STRING_EQUAL(subsystem->subnqn, nqn);
403 : 5 : rc = spdk_nvmf_subsystem_destroy(subsystem, NULL, NULL);
404 : 5 : CU_ASSERT(rc == 0);
405 : :
406 : : /* Invalid name, domain label > 63 characters */
407 : 5 : snprintf(nqn, sizeof(nqn),
408 : : "nqn.2016-06.io.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz:sub");
409 : 5 : subsystem = spdk_nvmf_subsystem_create(&tgt, nqn, SPDK_NVMF_SUBTYPE_NVME, 0);
410 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(subsystem == NULL);
411 : :
412 : : /* Invalid name, domain label starts with digit */
413 : 5 : snprintf(nqn, sizeof(nqn), "nqn.2016-06.io.3spdk:sub");
414 : 5 : subsystem = spdk_nvmf_subsystem_create(&tgt, nqn, SPDK_NVMF_SUBTYPE_NVME, 0);
415 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(subsystem == NULL);
416 : :
417 : : /* Invalid name, domain label starts with - */
418 : 5 : snprintf(nqn, sizeof(nqn), "nqn.2016-06.io.-spdk:subsystem1");
419 : 5 : subsystem = spdk_nvmf_subsystem_create(&tgt, nqn, SPDK_NVMF_SUBTYPE_NVME, 0);
420 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(subsystem == NULL);
421 : :
422 : : /* Invalid name, domain label ends with - */
423 : 5 : snprintf(nqn, sizeof(nqn), "nqn.2016-06.io.spdk-:subsystem1");
424 : 5 : subsystem = spdk_nvmf_subsystem_create(&tgt, nqn, SPDK_NVMF_SUBTYPE_NVME, 0);
425 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(subsystem == NULL);
426 : :
427 : : /* Invalid name, domain label with multiple consecutive periods */
428 : 5 : snprintf(nqn, sizeof(nqn), "nqn.2016-06.io..spdk:subsystem1");
429 : 5 : subsystem = spdk_nvmf_subsystem_create(&tgt, nqn, SPDK_NVMF_SUBTYPE_NVME, 0);
430 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(subsystem == NULL);
431 : :
432 : : /* Longest valid name */
433 : 5 : snprintf(nqn, sizeof(nqn), "nqn.2016-06.io.spdk:");
434 [ - + ]: 5 : memset(nqn + strlen(nqn), 'a', 223 - strlen(nqn));
435 : 5 : nqn[223] = '\0';
436 : 5 : CU_ASSERT(strlen(nqn) == 223);
437 : 5 : subsystem = spdk_nvmf_subsystem_create(&tgt, nqn, SPDK_NVMF_SUBTYPE_NVME, 0);
438 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(subsystem != NULL);
439 [ - + ]: 5 : CU_ASSERT_STRING_EQUAL(subsystem->subnqn, nqn);
440 : 5 : rc = spdk_nvmf_subsystem_destroy(subsystem, NULL, NULL);
441 : 5 : CU_ASSERT(rc == 0);
442 : :
443 : : /* Invalid name, too long */
444 : 5 : snprintf(nqn, sizeof(nqn), "nqn.2016-06.io.spdk:");
445 [ - + ]: 5 : memset(nqn + strlen(nqn), 'a', 224 - strlen(nqn));
446 : 5 : nqn[224] = '\0';
447 : 5 : CU_ASSERT(strlen(nqn) == 224);
448 : 5 : subsystem = spdk_nvmf_subsystem_create(&tgt, nqn, SPDK_NVMF_SUBTYPE_NVME, 0);
449 : 5 : CU_ASSERT(subsystem == NULL);
450 : :
451 : : /* Valid name using uuid format */
452 : 5 : snprintf(nqn, sizeof(nqn), "nqn.2014-08.org.nvmexpress:uuid:ff9b6406-0fc8-4779-80ca-4dca14bda0d2");
453 : 5 : subsystem = spdk_nvmf_subsystem_create(&tgt, nqn, SPDK_NVMF_SUBTYPE_NVME, 0);
454 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(subsystem != NULL);
455 [ - + ]: 5 : CU_ASSERT_STRING_EQUAL(subsystem->subnqn, nqn);
456 : 5 : rc = spdk_nvmf_subsystem_destroy(subsystem, NULL, NULL);
457 : 5 : CU_ASSERT(rc == 0);
458 : :
459 : : /* Invalid name user string contains an invalid utf-8 character */
460 : 5 : snprintf(nqn, sizeof(nqn), "nqn.2016-06.io.spdk:\xFFsubsystem1");
461 : 5 : subsystem = spdk_nvmf_subsystem_create(&tgt, nqn, SPDK_NVMF_SUBTYPE_NVME, 0);
462 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(subsystem == NULL);
463 : :
464 : : /* Valid name with non-ascii but valid utf-8 characters */
465 : 5 : snprintf(nqn, sizeof(nqn), "nqn.2016-06.io.spdk:\xe1\x8a\x88subsystem1\xca\x80");
466 : 5 : subsystem = spdk_nvmf_subsystem_create(&tgt, nqn, SPDK_NVMF_SUBTYPE_NVME, 0);
467 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(subsystem != NULL);
468 [ - + ]: 5 : CU_ASSERT_STRING_EQUAL(subsystem->subnqn, nqn);
469 : 5 : rc = spdk_nvmf_subsystem_destroy(subsystem, NULL, NULL);
470 : 5 : CU_ASSERT(rc == 0);
471 : :
472 : : /* Invalid uuid (too long) */
473 : 5 : snprintf(nqn, sizeof(nqn),
474 : : "nqn.2014-08.org.nvmexpress:uuid:ff9b6406-0fc8-4779-80ca-4dca14bda0d2aaaa");
475 : 5 : subsystem = spdk_nvmf_subsystem_create(&tgt, nqn, SPDK_NVMF_SUBTYPE_NVME, 0);
476 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(subsystem == NULL);
477 : :
478 : : /* Invalid uuid (dashes placed incorrectly) */
479 : 5 : snprintf(nqn, sizeof(nqn), "nqn.2014-08.org.nvmexpress:uuid:ff9b64-060fc8-4779-80ca-4dca14bda0d2");
480 : 5 : subsystem = spdk_nvmf_subsystem_create(&tgt, nqn, SPDK_NVMF_SUBTYPE_NVME, 0);
481 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(subsystem == NULL);
482 : :
483 : : /* Invalid uuid (invalid characters in uuid) */
484 : 5 : snprintf(nqn, sizeof(nqn), "nqn.2014-08.org.nvmexpress:uuid:ff9hg406-0fc8-4779-80ca-4dca14bda0d2");
485 : 5 : subsystem = spdk_nvmf_subsystem_create(&tgt, nqn, SPDK_NVMF_SUBTYPE_NVME, 0);
486 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(subsystem == NULL);
487 : :
488 : 5 : spdk_bit_array_free(&tgt.subsystem_ids);
489 : 5 : }
490 : :
491 : : static void
492 : 5 : test_spdk_nvmf_subsystem_set_sn(void)
493 : : {
494 : 5 : struct spdk_nvmf_subsystem subsystem = {};
495 : :
496 : : /* Basic valid serial number */
497 : 5 : CU_ASSERT(spdk_nvmf_subsystem_set_sn(&subsystem, "abcd xyz") == 0);
498 : 5 : CU_ASSERT(strcmp(subsystem.sn, "abcd xyz") == 0);
499 : :
500 : : /* Exactly 20 characters (valid) */
501 : 5 : CU_ASSERT(spdk_nvmf_subsystem_set_sn(&subsystem, "12345678901234567890") == 0);
502 : 5 : CU_ASSERT(strcmp(subsystem.sn, "12345678901234567890") == 0);
503 : :
504 : : /* 21 characters (too long, invalid) */
505 : 5 : CU_ASSERT(spdk_nvmf_subsystem_set_sn(&subsystem, "123456789012345678901") < 0);
506 : :
507 : : /* Non-ASCII characters (invalid) */
508 : 5 : CU_ASSERT(spdk_nvmf_subsystem_set_sn(&subsystem, "abcd\txyz") < 0);
509 : 5 : }
510 : :
511 : : static void
512 : 5 : test_spdk_nvmf_ns_visible(void)
513 : : {
514 : 5 : struct spdk_nvmf_subsystem subsystem = {};
515 : 5 : struct spdk_nvmf_ns ns1 = {
516 : : .nsid = 1,
517 : : .anagrpid = 1,
518 : : .always_visible = false
519 : : };
520 : 5 : struct spdk_nvmf_ns ns2 = {
521 : : .nsid = 2,
522 : : .anagrpid = 2,
523 : : .always_visible = false
524 : : };
525 : : struct spdk_nvmf_ns *ns3;
526 : 5 : struct spdk_nvmf_ctrlr ctrlrA = {
527 : : .subsys = &subsystem
528 : : };
529 : 5 : struct spdk_nvmf_ctrlr ctrlrB = {
530 : : .subsys = &subsystem
531 : : };
532 : : struct spdk_thread *thread;
533 : 5 : struct spdk_nvmf_tgt tgt = {};
534 : : uint32_t nsid;
535 : : int rc;
536 : :
537 : 5 : thread = spdk_get_thread();
538 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(thread != NULL);
539 : 5 : ctrlrA.thread = thread;
540 : 5 : ctrlrB.thread = thread;
541 : :
542 : 5 : subsystem.max_nsid = 1024;
543 : 5 : subsystem.ns = calloc(subsystem.max_nsid, sizeof(subsystem.ns));
544 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(subsystem.ns != NULL);
545 : 5 : subsystem.ana_group = calloc(subsystem.max_nsid, sizeof(uint32_t));
546 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(subsystem.ana_group != NULL);
547 : 5 : TAILQ_INIT(&tgt.transports);
548 : 5 : subsystem.tgt = &tgt;
549 : :
550 : 5 : subsystem.ns[1] = &ns1;
551 : 5 : subsystem.ns[2] = &ns2;
552 : 5 : ns3 = calloc(1, sizeof(*ns3));
553 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(ns3 != NULL);
554 : 5 : ns3->nsid = 3;
555 : 5 : ns3->anagrpid = 3;
556 : 5 : subsystem.ana_group[ns3->anagrpid - 1] = 1;
557 : 5 : subsystem.ns[3] = ns3;
558 : :
559 [ - + ]: 5 : snprintf(ctrlrA.hostnqn, sizeof(ctrlrA.hostnqn), "nqn.2016-06.io.spdk:host1");
560 : 5 : ctrlrA.visible_ns = spdk_bit_array_create(subsystem.max_nsid);
561 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(ctrlrA.visible_ns != NULL);
562 [ - + ]: 5 : snprintf(ctrlrB.hostnqn, sizeof(ctrlrB.hostnqn), "nqn.2016-06.io.spdk:host2");
563 : 5 : ctrlrB.visible_ns = spdk_bit_array_create(subsystem.max_nsid);
564 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(ctrlrB.visible_ns != NULL);
565 : :
566 : : /* Add two controllers ctrlrA and ctrlrB */
567 : 5 : TAILQ_INIT(&subsystem.ctrlrs);
568 : 5 : TAILQ_INSERT_TAIL(&subsystem.ctrlrs, &ctrlrA, link);
569 : 5 : TAILQ_INSERT_TAIL(&subsystem.ctrlrs, &ctrlrB, link);
570 : :
571 : : /* Invalid host nqn */
572 : 5 : nsid = 1;
573 : 5 : rc = spdk_nvmf_ns_add_host(&subsystem, nsid, "", 0);
574 : 5 : CU_ASSERT(rc == -EINVAL);
575 : 5 : rc = spdk_nvmf_ns_add_host(&subsystem, nsid, NULL, 0);
576 : 5 : CU_ASSERT(rc == -EINVAL);
577 : 5 : rc = spdk_nvmf_ns_remove_host(&subsystem, nsid, NULL, 0);
578 : 5 : CU_ASSERT(rc == -EINVAL);
579 : :
580 : : /* Invalid nsid */
581 : 5 : nsid = 0;
582 : 5 : rc = spdk_nvmf_ns_add_host(&subsystem, nsid, ctrlrA.hostnqn, 0);
583 : 5 : CU_ASSERT(rc == -EINVAL);
584 : 5 : rc = spdk_nvmf_ns_remove_host(&subsystem, nsid, ctrlrA.hostnqn, 0);
585 : 5 : CU_ASSERT(rc == -EINVAL);
586 : :
587 : : /* Unallocated ns */
588 : 5 : nsid = 1;
589 : 5 : rc = spdk_nvmf_ns_add_host(&subsystem, nsid, ctrlrA.hostnqn, 0);
590 : 5 : CU_ASSERT(rc == -ENOENT);
591 : 5 : rc = spdk_nvmf_ns_remove_host(&subsystem, nsid, ctrlrA.hostnqn, 0);
592 : 5 : CU_ASSERT(rc == -ENOENT);
593 : :
594 : : /* Attach any is active => do not allow individual host control */
595 : 5 : ns1.always_visible = true;
596 : 5 : nsid = 2;
597 : 5 : rc = spdk_nvmf_ns_add_host(&subsystem, nsid, ctrlrA.hostnqn, 0);
598 : 5 : CU_ASSERT(rc == -EPERM);
599 : 5 : rc = spdk_nvmf_ns_remove_host(&subsystem, nsid, ctrlrA.hostnqn, 0);
600 : 5 : CU_ASSERT(rc == -EPERM);
601 : 5 : ns1.always_visible = false;
602 : :
603 : : /* Attach ctrlrA to namespace 2 hot + cold */
604 : 5 : nsid = 2;
605 : 5 : g_async_event_ctrlr = NULL;
606 : 5 : g_ns_changed_ctrlr = NULL;
607 : 5 : g_ns_changed_nsid = 0;
608 : 5 : rc = spdk_nvmf_ns_add_host(&subsystem, nsid, ctrlrA.hostnqn, 0);
609 : 5 : CU_ASSERT(rc == 0);
610 : 5 : CU_ASSERT(nvmf_ns_find_host(&ns1, ctrlrA.hostnqn) != NULL);
611 : 5 : CU_ASSERT(nvmf_ns_find_host(&ns1, ctrlrB.hostnqn) == NULL);
612 : 5 : CU_ASSERT(nvmf_ns_find_host(&ns2, ctrlrA.hostnqn) == NULL);
613 : 5 : CU_ASSERT(nvmf_ns_find_host(&ns2, ctrlrB.hostnqn) == NULL);
614 : 5 : CU_ASSERT(spdk_bit_array_get(ctrlrA.visible_ns, nsid - 1));
615 : 5 : CU_ASSERT(!spdk_bit_array_get(ctrlrB.visible_ns, nsid - 1));
616 : 5 : CU_ASSERT(!spdk_bit_array_get(ctrlrA.visible_ns, nsid));
617 : 5 : CU_ASSERT(!spdk_bit_array_get(ctrlrB.visible_ns, nsid));
618 : : /* check last ns_changed */
619 : 5 : CU_ASSERT(g_ns_changed_ctrlr == &ctrlrA);
620 : 5 : CU_ASSERT(g_ns_changed_nsid == nsid);
621 : : /* check async_event */
622 : 5 : poll_threads();
623 : 5 : CU_ASSERT(g_async_event_ctrlr == &ctrlrA);
624 : :
625 : : /* Attach ctrlrA to namespace 2 again => should not create any ns change/async event */
626 : 5 : g_async_event_ctrlr = NULL;
627 : 5 : g_ns_changed_ctrlr = NULL;
628 : 5 : g_ns_changed_nsid = 0;
629 : 5 : rc = spdk_nvmf_ns_add_host(&subsystem, nsid, ctrlrA.hostnqn, 0);
630 : 5 : CU_ASSERT(rc == 0);
631 : 5 : CU_ASSERT(nvmf_ns_find_host(&ns1, ctrlrA.hostnqn) != NULL);
632 : 5 : CU_ASSERT(nvmf_ns_find_host(&ns1, ctrlrB.hostnqn) == NULL);
633 : 5 : CU_ASSERT(nvmf_ns_find_host(&ns2, ctrlrA.hostnqn) == NULL);
634 : 5 : CU_ASSERT(nvmf_ns_find_host(&ns2, ctrlrB.hostnqn) == NULL);
635 : 5 : CU_ASSERT(spdk_bit_array_get(ctrlrA.visible_ns, nsid - 1));
636 : 5 : CU_ASSERT(!spdk_bit_array_get(ctrlrB.visible_ns, nsid - 1));
637 : 5 : CU_ASSERT(!spdk_bit_array_get(ctrlrA.visible_ns, nsid));
638 : 5 : CU_ASSERT(!spdk_bit_array_get(ctrlrB.visible_ns, nsid));
639 : : /* check last ns_changed */
640 : 5 : CU_ASSERT(g_ns_changed_ctrlr == NULL);
641 : 5 : CU_ASSERT(g_ns_changed_nsid == 0);
642 : : /* check async_event */
643 : 5 : poll_threads();
644 : 5 : CU_ASSERT(g_async_event_ctrlr == NULL);
645 : :
646 : : /* Detach ctrlrA from namespace 2 hot + cold */
647 : 5 : g_async_event_ctrlr = NULL;
648 : 5 : g_ns_changed_ctrlr = NULL;
649 : 5 : g_ns_changed_nsid = 0;
650 : 5 : rc = spdk_nvmf_ns_remove_host(&subsystem, nsid, ctrlrA.hostnqn, 0);
651 : 5 : CU_ASSERT(rc == 0);
652 : 5 : CU_ASSERT(nvmf_ns_find_host(&ns1, ctrlrA.hostnqn) == NULL);
653 : 5 : CU_ASSERT(nvmf_ns_find_host(&ns1, ctrlrB.hostnqn) == NULL);
654 : 5 : CU_ASSERT(nvmf_ns_find_host(&ns2, ctrlrA.hostnqn) == NULL);
655 : 5 : CU_ASSERT(nvmf_ns_find_host(&ns2, ctrlrB.hostnqn) == NULL);
656 : 5 : CU_ASSERT(!spdk_bit_array_get(ctrlrA.visible_ns, nsid - 1));
657 : 5 : CU_ASSERT(!spdk_bit_array_get(ctrlrB.visible_ns, nsid - 1));
658 : 5 : CU_ASSERT(!spdk_bit_array_get(ctrlrA.visible_ns, nsid));
659 : 5 : CU_ASSERT(!spdk_bit_array_get(ctrlrB.visible_ns, nsid));
660 : : /* check last ns_changed */
661 : 5 : CU_ASSERT(g_ns_changed_ctrlr == &ctrlrA);
662 : 5 : CU_ASSERT(g_ns_changed_nsid == nsid);
663 : : /* check async_event */
664 : 5 : poll_threads();
665 : 5 : CU_ASSERT(g_async_event_ctrlr == &ctrlrA);
666 : :
667 : : /* Detach ctrlrA from namespace 2 again hot + cold */
668 : 5 : g_async_event_ctrlr = NULL;
669 : 5 : g_ns_changed_ctrlr = NULL;
670 : 5 : g_ns_changed_nsid = 0;
671 : 5 : rc = spdk_nvmf_ns_remove_host(&subsystem, nsid, ctrlrA.hostnqn, 0);
672 : 5 : CU_ASSERT(rc == 0);
673 : 5 : CU_ASSERT(nvmf_ns_find_host(&ns1, ctrlrA.hostnqn) == NULL);
674 : 5 : CU_ASSERT(nvmf_ns_find_host(&ns1, ctrlrB.hostnqn) == NULL);
675 : 5 : CU_ASSERT(nvmf_ns_find_host(&ns2, ctrlrA.hostnqn) == NULL);
676 : 5 : CU_ASSERT(nvmf_ns_find_host(&ns2, ctrlrB.hostnqn) == NULL);
677 : 5 : CU_ASSERT(!spdk_bit_array_get(ctrlrA.visible_ns, nsid - 1));
678 : 5 : CU_ASSERT(!spdk_bit_array_get(ctrlrB.visible_ns, nsid - 1));
679 : 5 : CU_ASSERT(!spdk_bit_array_get(ctrlrA.visible_ns, nsid));
680 : 5 : CU_ASSERT(!spdk_bit_array_get(ctrlrB.visible_ns, nsid));
681 : : /* check last ns_changed */
682 : 5 : CU_ASSERT(g_ns_changed_ctrlr == NULL);
683 : 5 : CU_ASSERT(g_ns_changed_nsid == 0);
684 : : /* check async_event */
685 : 5 : poll_threads();
686 : 5 : CU_ASSERT(g_async_event_ctrlr == NULL);
687 : :
688 : : /* Attach ctrlrA to namespace 4 hot + cold => remove ns */
689 : 5 : nsid = 4;
690 : 5 : g_async_event_ctrlr = NULL;
691 : 5 : g_ns_changed_ctrlr = NULL;
692 : 5 : g_ns_changed_nsid = 0;
693 : 5 : rc = spdk_nvmf_ns_add_host(&subsystem, nsid, ctrlrA.hostnqn, 0);
694 : 5 : CU_ASSERT(rc == 0);
695 : 5 : CU_ASSERT(nvmf_ns_find_host(ns3, ctrlrA.hostnqn) != NULL);
696 : 5 : CU_ASSERT(nvmf_ns_find_host(ns3, ctrlrB.hostnqn) == NULL);
697 : 5 : CU_ASSERT(spdk_bit_array_get(ctrlrA.visible_ns, nsid - 1));
698 : 5 : CU_ASSERT(!spdk_bit_array_get(ctrlrB.visible_ns, nsid - 1));
699 : : /* check last ns_changed */
700 : 5 : CU_ASSERT(g_ns_changed_ctrlr == &ctrlrA);
701 : 5 : CU_ASSERT(g_ns_changed_nsid == nsid);
702 : : /* check async_event */
703 : 5 : poll_threads();
704 : 5 : CU_ASSERT(g_async_event_ctrlr == &ctrlrA);
705 : :
706 : 5 : g_async_event_ctrlr = NULL;
707 : 5 : g_ns_changed_ctrlr = NULL;
708 : 5 : g_ns_changed_nsid = 0;
709 : 5 : rc = spdk_nvmf_subsystem_remove_ns(&subsystem, nsid);
710 : 5 : CU_ASSERT(rc == 0);
711 : 5 : CU_ASSERT(!spdk_bit_array_get(ctrlrA.visible_ns, nsid - 1));
712 : 5 : CU_ASSERT(!spdk_bit_array_get(ctrlrB.visible_ns, nsid - 1));
713 : : /* check last ns_changed */
714 : 5 : CU_ASSERT(g_ns_changed_ctrlr == &ctrlrA);
715 : 5 : CU_ASSERT(g_ns_changed_nsid == nsid);
716 : :
717 : 5 : free(ctrlrA.visible_ns);
718 : 5 : free(ctrlrB.visible_ns);
719 : 5 : free(subsystem.ana_group);
720 : 5 : free(subsystem.ns);
721 : 5 : }
722 : :
723 : : /*
724 : : * Reservation Unit Test Configuration
725 : : * -------- -------- --------
726 : : * | Host A | | Host B | | Host C |
727 : : * -------- -------- --------
728 : : * / \ | |
729 : : * -------- -------- ------- -------
730 : : * |Ctrlr1_A| |Ctrlr2_A| |Ctrlr_B| |Ctrlr_C|
731 : : * -------- -------- ------- -------
732 : : * \ \ / /
733 : : * \ \ / /
734 : : * \ \ / /
735 : : * --------------------------------------
736 : : * | NAMESPACE 1 |
737 : : * --------------------------------------
738 : : */
739 : : static struct spdk_nvmf_subsystem g_subsystem;
740 : : static struct spdk_nvmf_ctrlr g_ctrlr1_A, g_ctrlr2_A, g_ctrlr_B, g_ctrlr_C;
741 : : static struct spdk_nvmf_ns g_ns;
742 : : struct spdk_nvmf_subsystem_pg_ns_info g_ns_info;
743 : :
744 : : void
745 : 0 : nvmf_ctrlr_async_event_reservation_notification(struct spdk_nvmf_ctrlr *ctrlr)
746 : : {
747 : 0 : }
748 : :
749 : : static void
750 : 55 : ut_reservation_init(void)
751 : : {
752 : :
753 : 55 : TAILQ_INIT(&g_subsystem.ctrlrs);
754 : :
755 [ - + ]: 55 : memset(&g_ns, 0, sizeof(g_ns));
756 : 55 : TAILQ_INIT(&g_ns.registrants);
757 : 55 : g_ns.subsystem = &g_subsystem;
758 : 55 : g_ns.ptpl_file = NULL;
759 : 55 : g_ns.ptpl_activated = false;
760 : 55 : spdk_uuid_generate(&g_bdevs[0].uuid);
761 : 55 : g_ns.bdev = &g_bdevs[0];
762 : :
763 : : /* Host A has two controllers */
764 : 55 : spdk_uuid_generate(&g_ctrlr1_A.hostid);
765 : 55 : TAILQ_INIT(&g_ctrlr1_A.log_head);
766 : 55 : g_ctrlr1_A.subsys = &g_subsystem;
767 : 55 : g_ctrlr1_A.num_avail_log_pages = 0;
768 : 55 : TAILQ_INSERT_TAIL(&g_subsystem.ctrlrs, &g_ctrlr1_A, link);
769 : 55 : spdk_uuid_copy(&g_ctrlr2_A.hostid, &g_ctrlr1_A.hostid);
770 : 55 : TAILQ_INIT(&g_ctrlr2_A.log_head);
771 : 55 : g_ctrlr2_A.subsys = &g_subsystem;
772 : 55 : g_ctrlr2_A.num_avail_log_pages = 0;
773 : 55 : TAILQ_INSERT_TAIL(&g_subsystem.ctrlrs, &g_ctrlr2_A, link);
774 : :
775 : : /* Host B has 1 controller */
776 : 55 : spdk_uuid_generate(&g_ctrlr_B.hostid);
777 : 55 : TAILQ_INIT(&g_ctrlr_B.log_head);
778 : 55 : g_ctrlr_B.subsys = &g_subsystem;
779 : 55 : g_ctrlr_B.num_avail_log_pages = 0;
780 : 55 : TAILQ_INSERT_TAIL(&g_subsystem.ctrlrs, &g_ctrlr_B, link);
781 : :
782 : : /* Host C has 1 controller */
783 : 55 : spdk_uuid_generate(&g_ctrlr_C.hostid);
784 : 55 : TAILQ_INIT(&g_ctrlr_C.log_head);
785 : 55 : g_ctrlr_C.subsys = &g_subsystem;
786 : 55 : g_ctrlr_C.num_avail_log_pages = 0;
787 : 55 : TAILQ_INSERT_TAIL(&g_subsystem.ctrlrs, &g_ctrlr_C, link);
788 : 55 : }
789 : :
790 : : static void
791 : 55 : ut_reservation_deinit(void)
792 : : {
793 : : struct spdk_nvmf_registrant *reg, *tmp;
794 : : struct spdk_nvmf_reservation_log *log, *log_tmp;
795 : : struct spdk_nvmf_ctrlr *ctrlr, *ctrlr_tmp;
796 : :
797 [ + + ]: 130 : TAILQ_FOREACH_SAFE(reg, &g_ns.registrants, link, tmp) {
798 [ + + ]: 75 : TAILQ_REMOVE(&g_ns.registrants, reg, link);
799 : 75 : free(reg);
800 : : }
801 [ - + ]: 55 : TAILQ_FOREACH_SAFE(log, &g_ctrlr1_A.log_head, link, log_tmp) {
802 [ # # ]: 0 : TAILQ_REMOVE(&g_ctrlr1_A.log_head, log, link);
803 : 0 : free(log);
804 : : }
805 : 55 : g_ctrlr1_A.num_avail_log_pages = 0;
806 [ - + ]: 55 : TAILQ_FOREACH_SAFE(log, &g_ctrlr2_A.log_head, link, log_tmp) {
807 [ # # ]: 0 : TAILQ_REMOVE(&g_ctrlr2_A.log_head, log, link);
808 : 0 : free(log);
809 : : }
810 : 55 : g_ctrlr2_A.num_avail_log_pages = 0;
811 [ - + ]: 55 : TAILQ_FOREACH_SAFE(log, &g_ctrlr_B.log_head, link, log_tmp) {
812 [ # # ]: 0 : TAILQ_REMOVE(&g_ctrlr_B.log_head, log, link);
813 : 0 : free(log);
814 : : }
815 : 55 : g_ctrlr_B.num_avail_log_pages = 0;
816 [ - + ]: 55 : TAILQ_FOREACH_SAFE(log, &g_ctrlr_C.log_head, link, log_tmp) {
817 [ # # ]: 0 : TAILQ_REMOVE(&g_ctrlr_C.log_head, log, link);
818 : 0 : free(log);
819 : : }
820 : 55 : g_ctrlr_C.num_avail_log_pages = 0;
821 : :
822 [ + + ]: 275 : TAILQ_FOREACH_SAFE(ctrlr, &g_subsystem.ctrlrs, link, ctrlr_tmp) {
823 [ + + ]: 220 : TAILQ_REMOVE(&g_subsystem.ctrlrs, ctrlr, link);
824 : : }
825 : 55 : }
826 : :
827 : : static struct spdk_nvmf_request *
828 : 95 : ut_reservation_build_req(uint32_t length)
829 : : {
830 : : struct spdk_nvmf_request *req;
831 : :
832 : 95 : req = calloc(1, sizeof(*req));
833 [ - + ]: 95 : assert(req != NULL);
834 : :
835 : 95 : SPDK_IOV_ONE(req->iov, &req->iovcnt, calloc(1, length), length);
836 [ - + ]: 95 : assert(req->iov[0].iov_base != NULL);
837 : 95 : req->length = length;
838 : :
839 : 95 : req->cmd = (union nvmf_h2c_msg *)calloc(1, sizeof(union nvmf_h2c_msg));
840 [ - + ]: 95 : assert(req->cmd != NULL);
841 : :
842 : 95 : req->rsp = (union nvmf_c2h_msg *)calloc(1, sizeof(union nvmf_c2h_msg));
843 [ - + ]: 95 : assert(req->rsp != NULL);
844 : :
845 : 95 : return req;
846 : : }
847 : :
848 : : static void
849 : 95 : ut_reservation_free_req(struct spdk_nvmf_request *req)
850 : : {
851 : 95 : free(req->cmd);
852 : 95 : free(req->rsp);
853 : 95 : free(req->iov[0].iov_base);
854 : 95 : free(req);
855 : 95 : }
856 : :
857 : : static void
858 : 225 : ut_reservation_build_register_request(struct spdk_nvmf_request *req,
859 : : uint8_t rrega, uint8_t iekey,
860 : : uint8_t cptpl, uint64_t crkey,
861 : : uint64_t nrkey)
862 : : {
863 : 180 : struct spdk_nvme_reservation_register_data key;
864 : 225 : struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
865 : :
866 : 225 : key.crkey = crkey;
867 : 225 : key.nrkey = nrkey;
868 : 225 : cmd->cdw10 = 0;
869 : 225 : cmd->cdw10_bits.resv_register.rrega = rrega;
870 : 225 : cmd->cdw10_bits.resv_register.iekey = iekey;
871 : 225 : cmd->cdw10_bits.resv_register.cptpl = cptpl;
872 : 225 : memcpy(req->iov[0].iov_base, &key, sizeof(key));
873 : 225 : }
874 : :
875 : : static void
876 : 65 : ut_reservation_build_acquire_request(struct spdk_nvmf_request *req,
877 : : uint8_t racqa, uint8_t iekey,
878 : : uint8_t rtype, uint64_t crkey,
879 : : uint64_t prkey)
880 : : {
881 : 52 : struct spdk_nvme_reservation_acquire_data key;
882 : 65 : struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
883 : :
884 : 65 : key.crkey = crkey;
885 : 65 : key.prkey = prkey;
886 : 65 : cmd->cdw10 = 0;
887 : 65 : cmd->cdw10_bits.resv_acquire.racqa = racqa;
888 : 65 : cmd->cdw10_bits.resv_acquire.iekey = iekey;
889 : 65 : cmd->cdw10_bits.resv_acquire.rtype = rtype;
890 : 65 : memcpy(req->iov[0].iov_base, &key, sizeof(key));
891 : 65 : }
892 : :
893 : : static void
894 : 30 : ut_reservation_build_release_request(struct spdk_nvmf_request *req,
895 : : uint8_t rrela, uint8_t iekey,
896 : : uint8_t rtype, uint64_t crkey)
897 : : {
898 : 30 : struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
899 : :
900 : 30 : cmd->cdw10 = 0;
901 : 30 : cmd->cdw10_bits.resv_release.rrela = rrela;
902 : 30 : cmd->cdw10_bits.resv_release.iekey = iekey;
903 : 30 : cmd->cdw10_bits.resv_release.rtype = rtype;
904 : 30 : memcpy(req->iov[0].iov_base, &crkey, sizeof(crkey));
905 : 30 : }
906 : :
907 : : /*
908 : : * Construct four registrants for other test cases.
909 : : *
910 : : * g_ctrlr1_A register with key 0xa1.
911 : : * g_ctrlr2_A register with key 0xa1.
912 : : * g_ctrlr_B register with key 0xb1.
913 : : * g_ctrlr_C register with key 0xc1.
914 : : * */
915 : : static void
916 : 40 : ut_reservation_build_registrants(void)
917 : : {
918 : : struct spdk_nvmf_request *req;
919 : : struct spdk_nvme_cpl *rsp;
920 : : struct spdk_nvmf_registrant *reg;
921 : : uint32_t gen;
922 : :
923 : 40 : req = ut_reservation_build_req(16);
924 : 40 : rsp = &req->rsp->nvme_cpl;
925 [ - + ]: 40 : SPDK_CU_ASSERT_FATAL(req != NULL);
926 : 40 : gen = g_ns.gen;
927 : :
928 : : /* TEST CASE: g_ctrlr1_A register with a new key */
929 : 40 : ut_reservation_build_register_request(req, SPDK_NVME_RESERVE_REGISTER_KEY,
930 : : 0, 0, 0, 0xa1);
931 : 40 : nvmf_ns_reservation_register(&g_ns, &g_ctrlr1_A, req);
932 [ - + ]: 40 : SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_SUCCESS);
933 : 40 : reg = nvmf_ns_reservation_get_registrant(&g_ns, &g_ctrlr1_A.hostid);
934 [ - + ]: 40 : SPDK_CU_ASSERT_FATAL(reg->rkey == 0xa1);
935 [ - + ]: 40 : SPDK_CU_ASSERT_FATAL(g_ns.gen == gen + 1);
936 : :
937 : : /* TEST CASE: g_ctrlr2_A register with a new key, because it has same
938 : : * Host Identifier with g_ctrlr1_A, so the register key should same.
939 : : */
940 : 40 : ut_reservation_build_register_request(req, SPDK_NVME_RESERVE_REGISTER_KEY,
941 : : 0, 0, 0, 0xa2);
942 : 40 : nvmf_ns_reservation_register(&g_ns, &g_ctrlr2_A, req);
943 : : /* Reservation conflict for other key than 0xa1 */
944 [ - + ]: 40 : SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_RESERVATION_CONFLICT);
945 : :
946 : : /* g_ctrlr_B register with a new key */
947 : 40 : ut_reservation_build_register_request(req, SPDK_NVME_RESERVE_REGISTER_KEY,
948 : : 0, 0, 0, 0xb1);
949 : 40 : nvmf_ns_reservation_register(&g_ns, &g_ctrlr_B, req);
950 [ - + ]: 40 : SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_SUCCESS);
951 : 40 : reg = nvmf_ns_reservation_get_registrant(&g_ns, &g_ctrlr_B.hostid);
952 [ - + ]: 40 : SPDK_CU_ASSERT_FATAL(reg->rkey == 0xb1);
953 [ - + ]: 40 : SPDK_CU_ASSERT_FATAL(g_ns.gen == gen + 2);
954 : :
955 : : /* g_ctrlr_C register with a new key */
956 : 40 : ut_reservation_build_register_request(req, SPDK_NVME_RESERVE_REGISTER_KEY,
957 : : 0, 0, 0, 0xc1);
958 : 40 : nvmf_ns_reservation_register(&g_ns, &g_ctrlr_C, req);
959 [ - + ]: 40 : SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_SUCCESS);
960 : 40 : reg = nvmf_ns_reservation_get_registrant(&g_ns, &g_ctrlr_C.hostid);
961 [ - + ]: 40 : SPDK_CU_ASSERT_FATAL(reg->rkey == 0xc1);
962 [ - + ]: 40 : SPDK_CU_ASSERT_FATAL(g_ns.gen == gen + 3);
963 : :
964 : 40 : ut_reservation_free_req(req);
965 : 40 : }
966 : :
967 : : static void
968 : 5 : test_reservation_register(void)
969 : : {
970 : : struct spdk_nvmf_request *req;
971 : : struct spdk_nvme_cpl *rsp;
972 : : struct spdk_nvmf_registrant *reg;
973 : : uint32_t gen;
974 : :
975 : 5 : ut_reservation_init();
976 : :
977 : 5 : req = ut_reservation_build_req(16);
978 : 5 : rsp = &req->rsp->nvme_cpl;
979 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(req != NULL);
980 : :
981 : 5 : ut_reservation_build_registrants();
982 : :
983 : : /* TEST CASE: Replace g_ctrlr1_A with a new key */
984 : 5 : ut_reservation_build_register_request(req, SPDK_NVME_RESERVE_REPLACE_KEY,
985 : : 0, 0, 0xa1, 0xa11);
986 : 5 : nvmf_ns_reservation_register(&g_ns, &g_ctrlr1_A, req);
987 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_SUCCESS);
988 : 5 : reg = nvmf_ns_reservation_get_registrant(&g_ns, &g_ctrlr1_A.hostid);
989 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(reg->rkey == 0xa11);
990 : :
991 : : /* TEST CASE: Host A with g_ctrlr1_A get reservation with
992 : : * type SPDK_NVME_RESERVE_WRITE_EXCLUSIVE
993 : : */
994 : 5 : ut_reservation_build_acquire_request(req, SPDK_NVME_RESERVE_ACQUIRE, 0,
995 : : SPDK_NVME_RESERVE_WRITE_EXCLUSIVE, 0xa11, 0x0);
996 : 5 : gen = g_ns.gen;
997 : 5 : nvmf_ns_reservation_acquire(&g_ns, &g_ctrlr1_A, req);
998 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_SUCCESS);
999 : 5 : reg = nvmf_ns_reservation_get_registrant(&g_ns, &g_ctrlr1_A.hostid);
1000 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.rtype == SPDK_NVME_RESERVE_WRITE_EXCLUSIVE);
1001 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.crkey == 0xa11);
1002 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.holder == reg);
1003 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.gen == gen);
1004 : :
1005 : : /* TEST CASE: g_ctrlr_C unregister with IEKEY enabled */
1006 : 5 : ut_reservation_build_register_request(req, SPDK_NVME_RESERVE_UNREGISTER_KEY,
1007 : : 1, 0, 0, 0);
1008 : 5 : nvmf_ns_reservation_register(&g_ns, &g_ctrlr_C, req);
1009 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_SUCCESS);
1010 : 5 : reg = nvmf_ns_reservation_get_registrant(&g_ns, &g_ctrlr_C.hostid);
1011 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(reg == NULL);
1012 : :
1013 : : /* TEST CASE: g_ctrlr_B unregister with correct key */
1014 : 5 : ut_reservation_build_register_request(req, SPDK_NVME_RESERVE_UNREGISTER_KEY,
1015 : : 0, 0, 0xb1, 0);
1016 : 5 : nvmf_ns_reservation_register(&g_ns, &g_ctrlr_B, req);
1017 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_SUCCESS);
1018 : 5 : reg = nvmf_ns_reservation_get_registrant(&g_ns, &g_ctrlr_B.hostid);
1019 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(reg == NULL);
1020 : :
1021 : : /* TEST CASE: No registrant now, g_ctrlr_B replace new key with IEKEY disabled */
1022 : 5 : ut_reservation_build_register_request(req, SPDK_NVME_RESERVE_REPLACE_KEY,
1023 : : 0, 0, 0, 0xb1);
1024 : 5 : nvmf_ns_reservation_register(&g_ns, &g_ctrlr_B, req);
1025 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rsp->status.sc != SPDK_NVME_SC_SUCCESS);
1026 : :
1027 : : /* TEST CASE: No registrant now, g_ctrlr_B replace new key with IEKEY enabled */
1028 : 5 : ut_reservation_build_register_request(req, SPDK_NVME_RESERVE_REPLACE_KEY,
1029 : : 1, 0, 0, 0xb1);
1030 : 5 : nvmf_ns_reservation_register(&g_ns, &g_ctrlr_B, req);
1031 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_SUCCESS);
1032 : 5 : reg = nvmf_ns_reservation_get_registrant(&g_ns, &g_ctrlr_B.hostid);
1033 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(reg != NULL);
1034 : :
1035 : : /* TEST CASE: g_ctrlr_B replace new key with IEKEY enabled and wrong crkey */
1036 : 5 : ut_reservation_build_register_request(req, SPDK_NVME_RESERVE_REPLACE_KEY,
1037 : : 1, 0, 0xff, 0xb2);
1038 : 5 : nvmf_ns_reservation_register(&g_ns, &g_ctrlr_B, req);
1039 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_SUCCESS);
1040 : 5 : reg = nvmf_ns_reservation_get_registrant(&g_ns, &g_ctrlr_B.hostid);
1041 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(reg != NULL);
1042 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(reg->rkey == 0xb2);
1043 : :
1044 : : /* TEST CASE: g_ctrlr1_A unregister with correct key,
1045 : : * reservation should be removed as well.
1046 : : */
1047 : 5 : ut_reservation_build_register_request(req, SPDK_NVME_RESERVE_UNREGISTER_KEY,
1048 : : 0, 0, 0xa11, 0);
1049 : 5 : nvmf_ns_reservation_register(&g_ns, &g_ctrlr1_A, req);
1050 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_SUCCESS);
1051 : 5 : reg = nvmf_ns_reservation_get_registrant(&g_ns, &g_ctrlr1_A.hostid);
1052 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(reg == NULL);
1053 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.rtype == 0);
1054 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.crkey == 0);
1055 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.holder == NULL);
1056 : :
1057 : 5 : ut_reservation_free_req(req);
1058 : 5 : ut_reservation_deinit();
1059 : 5 : }
1060 : :
1061 : : static void
1062 : 5 : test_reservation_register_with_ptpl(void)
1063 : : {
1064 : : struct spdk_nvmf_request *req;
1065 : : struct spdk_nvme_cpl *rsp;
1066 : : struct spdk_nvmf_registrant *reg;
1067 : 5 : bool update_sgroup = false;
1068 : : int rc;
1069 : 4 : struct spdk_nvmf_reservation_info info;
1070 : :
1071 : 5 : ut_reservation_init();
1072 : :
1073 : 5 : req = ut_reservation_build_req(16);
1074 : 5 : rsp = &req->rsp->nvme_cpl;
1075 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(req != NULL);
1076 : :
1077 : : /* TEST CASE: No persistent file, register with PTPL enabled will fail */
1078 : 5 : g_ns.ptpl_file = NULL;
1079 : 5 : ut_reservation_build_register_request(req, SPDK_NVME_RESERVE_REGISTER_KEY, 0,
1080 : : SPDK_NVME_RESERVE_PTPL_PERSIST_POWER_LOSS, 0, 0xa1);
1081 : 5 : update_sgroup = nvmf_ns_reservation_register(&g_ns, &g_ctrlr1_A, req);
1082 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(update_sgroup == false);
1083 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rsp->status.sc != SPDK_NVME_SC_SUCCESS);
1084 : 5 : reg = nvmf_ns_reservation_get_registrant(&g_ns, &g_ctrlr1_A.hostid);
1085 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(reg == NULL);
1086 : :
1087 : : /* TEST CASE: Enable PTPL */
1088 : 5 : g_ns.ptpl_file = "/tmp/Ns1PR.cfg";
1089 : 5 : ut_reservation_build_register_request(req, SPDK_NVME_RESERVE_REGISTER_KEY, 0,
1090 : : SPDK_NVME_RESERVE_PTPL_PERSIST_POWER_LOSS, 0, 0xa1);
1091 : 5 : update_sgroup = nvmf_ns_reservation_register(&g_ns, &g_ctrlr1_A, req);
1092 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(update_sgroup == true);
1093 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_SUCCESS);
1094 [ - + - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.ptpl_activated == true);
1095 : 5 : rc = nvmf_ns_update_reservation_info(&g_ns);
1096 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rc == 0);
1097 : 5 : reg = nvmf_ns_reservation_get_registrant(&g_ns, &g_ctrlr1_A.hostid);
1098 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(reg != NULL);
1099 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(!spdk_uuid_compare(&g_ctrlr1_A.hostid, ®->hostid));
1100 : : /* Load reservation information from configuration file */
1101 [ - + ]: 5 : memset(&info, 0, sizeof(info));
1102 : 5 : rc = nvmf_ns_reservation_load(&g_ns, &info);
1103 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rc == 0);
1104 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(info.ptpl_activated == true);
1105 : :
1106 : : /* TEST CASE: Disable PTPL */
1107 : 5 : rsp->status.sc = SPDK_NVME_SC_INVALID_FIELD;
1108 : 5 : ut_reservation_build_register_request(req, SPDK_NVME_RESERVE_REGISTER_KEY, 0,
1109 : : SPDK_NVME_RESERVE_PTPL_CLEAR_POWER_ON, 0, 0xa1);
1110 : 5 : update_sgroup = nvmf_ns_reservation_register(&g_ns, &g_ctrlr1_A, req);
1111 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(update_sgroup == true);
1112 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_SUCCESS);
1113 [ - + - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.ptpl_activated == false);
1114 : 5 : rc = nvmf_ns_update_reservation_info(&g_ns);
1115 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rc == 0);
1116 : 5 : rc = nvmf_ns_reservation_load(&g_ns, &info);
1117 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rc < 0);
1118 [ - + ]: 5 : unlink(g_ns.ptpl_file);
1119 : :
1120 : 5 : ut_reservation_free_req(req);
1121 : 5 : ut_reservation_deinit();
1122 : 5 : }
1123 : :
1124 : : static void
1125 : 5 : test_reservation_acquire_preempt_1(void)
1126 : : {
1127 : : struct spdk_nvmf_request *req;
1128 : : struct spdk_nvme_cpl *rsp;
1129 : : struct spdk_nvmf_registrant *reg;
1130 : : uint32_t gen;
1131 : :
1132 : 5 : ut_reservation_init();
1133 : :
1134 : 5 : req = ut_reservation_build_req(16);
1135 : 5 : rsp = &req->rsp->nvme_cpl;
1136 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(req != NULL);
1137 : :
1138 : 5 : ut_reservation_build_registrants();
1139 : :
1140 : 5 : gen = g_ns.gen;
1141 : : /* ACQUIRE: Host A with g_ctrlr1_A acquire reservation with
1142 : : * type SPDK_NVME_RESERVE_WRITE_EXCLUSIVE.
1143 : : */
1144 : 5 : ut_reservation_build_acquire_request(req, SPDK_NVME_RESERVE_ACQUIRE, 0,
1145 : : SPDK_NVME_RESERVE_WRITE_EXCLUSIVE_REG_ONLY, 0xa1, 0x0);
1146 : 5 : nvmf_ns_reservation_acquire(&g_ns, &g_ctrlr1_A, req);
1147 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_SUCCESS);
1148 : 5 : reg = nvmf_ns_reservation_get_registrant(&g_ns, &g_ctrlr1_A.hostid);
1149 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.rtype == SPDK_NVME_RESERVE_WRITE_EXCLUSIVE_REG_ONLY);
1150 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.crkey == 0xa1);
1151 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.holder == reg);
1152 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.gen == gen);
1153 : :
1154 : : /* TEST CASE: g_ctrlr1_A holds the reservation, g_ctrlr_B preempt g_ctrl1_A,
1155 : : * g_ctrl1_A registrant is unregistered.
1156 : : */
1157 : 5 : gen = g_ns.gen;
1158 : 5 : ut_reservation_build_acquire_request(req, SPDK_NVME_RESERVE_PREEMPT, 0,
1159 : : SPDK_NVME_RESERVE_WRITE_EXCLUSIVE_ALL_REGS, 0xb1, 0xa1);
1160 : 5 : nvmf_ns_reservation_acquire(&g_ns, &g_ctrlr_B, req);
1161 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_SUCCESS);
1162 : 5 : reg = nvmf_ns_reservation_get_registrant(&g_ns, &g_ctrlr1_A.hostid);
1163 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(reg == NULL);
1164 : 5 : reg = nvmf_ns_reservation_get_registrant(&g_ns, &g_ctrlr_B.hostid);
1165 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(reg != NULL);
1166 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.holder == reg);
1167 : 5 : reg = nvmf_ns_reservation_get_registrant(&g_ns, &g_ctrlr_C.hostid);
1168 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(reg != NULL);
1169 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.rtype == SPDK_NVME_RESERVE_WRITE_EXCLUSIVE_ALL_REGS);
1170 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.gen > gen);
1171 : :
1172 : : /* TEST CASE: g_ctrlr_B holds the reservation, g_ctrlr_C preempt g_ctrlr_B
1173 : : * with valid key and PRKEY set to 0, all registrants other the host that issued
1174 : : * the command are unregistered.
1175 : : */
1176 : 5 : gen = g_ns.gen;
1177 : 5 : ut_reservation_build_acquire_request(req, SPDK_NVME_RESERVE_PREEMPT, 0,
1178 : : SPDK_NVME_RESERVE_WRITE_EXCLUSIVE_ALL_REGS, 0xc1, 0x0);
1179 : 5 : nvmf_ns_reservation_acquire(&g_ns, &g_ctrlr_C, req);
1180 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_SUCCESS);
1181 : 5 : reg = nvmf_ns_reservation_get_registrant(&g_ns, &g_ctrlr2_A.hostid);
1182 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(reg == NULL);
1183 : 5 : reg = nvmf_ns_reservation_get_registrant(&g_ns, &g_ctrlr_B.hostid);
1184 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(reg == NULL);
1185 : 5 : reg = nvmf_ns_reservation_get_registrant(&g_ns, &g_ctrlr_C.hostid);
1186 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(reg != NULL);
1187 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.holder == reg);
1188 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.rtype == SPDK_NVME_RESERVE_WRITE_EXCLUSIVE_ALL_REGS);
1189 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.gen > gen);
1190 : :
1191 : 5 : ut_reservation_free_req(req);
1192 : 5 : ut_reservation_deinit();
1193 : 5 : }
1194 : :
1195 : : static void
1196 : 5 : test_reservation_acquire_release_with_ptpl(void)
1197 : : {
1198 : : struct spdk_nvmf_request *req;
1199 : : struct spdk_nvme_cpl *rsp;
1200 : : struct spdk_nvmf_registrant *reg;
1201 : 5 : bool update_sgroup = false;
1202 : 4 : struct spdk_uuid holder_uuid;
1203 : : int rc;
1204 : 4 : struct spdk_nvmf_reservation_info info;
1205 : :
1206 : 5 : ut_reservation_init();
1207 : :
1208 : 5 : req = ut_reservation_build_req(16);
1209 : 5 : rsp = &req->rsp->nvme_cpl;
1210 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(req != NULL);
1211 : :
1212 : : /* TEST CASE: Enable PTPL */
1213 : 5 : g_ns.ptpl_file = "/tmp/Ns1PR.cfg";
1214 : 5 : ut_reservation_build_register_request(req, SPDK_NVME_RESERVE_REGISTER_KEY, 0,
1215 : : SPDK_NVME_RESERVE_PTPL_PERSIST_POWER_LOSS, 0, 0xa1);
1216 : 5 : update_sgroup = nvmf_ns_reservation_register(&g_ns, &g_ctrlr1_A, req);
1217 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(update_sgroup == true);
1218 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_SUCCESS);
1219 [ - + - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.ptpl_activated == true);
1220 : 5 : rc = nvmf_ns_update_reservation_info(&g_ns);
1221 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rc == 0);
1222 : 5 : reg = nvmf_ns_reservation_get_registrant(&g_ns, &g_ctrlr1_A.hostid);
1223 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(reg != NULL);
1224 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(!spdk_uuid_compare(&g_ctrlr1_A.hostid, ®->hostid));
1225 : : /* Load reservation information from configuration file */
1226 [ - + ]: 5 : memset(&info, 0, sizeof(info));
1227 : 5 : rc = nvmf_ns_reservation_load(&g_ns, &info);
1228 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rc == 0);
1229 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(info.ptpl_activated == true);
1230 : :
1231 : : /* TEST CASE: Acquire the reservation */
1232 : 5 : rsp->status.sc = SPDK_NVME_SC_INVALID_FIELD;
1233 : 5 : ut_reservation_build_acquire_request(req, SPDK_NVME_RESERVE_ACQUIRE, 0,
1234 : : SPDK_NVME_RESERVE_WRITE_EXCLUSIVE_REG_ONLY, 0xa1, 0x0);
1235 : 5 : update_sgroup = nvmf_ns_reservation_acquire(&g_ns, &g_ctrlr1_A, req);
1236 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(update_sgroup == true);
1237 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_SUCCESS);
1238 : 5 : rc = nvmf_ns_update_reservation_info(&g_ns);
1239 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rc == 0);
1240 [ - + ]: 5 : memset(&info, 0, sizeof(info));
1241 : 5 : rc = nvmf_ns_reservation_load(&g_ns, &info);
1242 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rc == 0);
1243 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(info.ptpl_activated == true);
1244 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(info.rtype == SPDK_NVME_RESERVE_WRITE_EXCLUSIVE_REG_ONLY);
1245 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(info.crkey == 0xa1);
1246 : 5 : spdk_uuid_parse(&holder_uuid, info.holder_uuid);
1247 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(!spdk_uuid_compare(&g_ctrlr1_A.hostid, &holder_uuid));
1248 : :
1249 : : /* TEST CASE: Release the reservation */
1250 : 5 : rsp->status.sc = SPDK_NVME_SC_INVALID_FIELD;
1251 : 5 : ut_reservation_build_release_request(req, SPDK_NVME_RESERVE_RELEASE, 0,
1252 : : SPDK_NVME_RESERVE_WRITE_EXCLUSIVE_REG_ONLY, 0xa1);
1253 : 5 : update_sgroup = nvmf_ns_reservation_release(&g_ns, &g_ctrlr1_A, req);
1254 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(update_sgroup == true);
1255 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_SUCCESS);
1256 : 5 : rc = nvmf_ns_update_reservation_info(&g_ns);
1257 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rc == 0);
1258 [ - + ]: 5 : memset(&info, 0, sizeof(info));
1259 : 5 : rc = nvmf_ns_reservation_load(&g_ns, &info);
1260 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rc == 0);
1261 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(info.rtype == 0);
1262 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(info.crkey == 0);
1263 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(info.ptpl_activated == true);
1264 [ - + ]: 5 : unlink(g_ns.ptpl_file);
1265 : :
1266 : 5 : ut_reservation_free_req(req);
1267 : 5 : ut_reservation_deinit();
1268 : 5 : }
1269 : :
1270 : : static void
1271 : 5 : test_reservation_release(void)
1272 : : {
1273 : : struct spdk_nvmf_request *req;
1274 : : struct spdk_nvme_cpl *rsp;
1275 : : struct spdk_nvmf_registrant *reg;
1276 : :
1277 : 5 : ut_reservation_init();
1278 : :
1279 : 5 : req = ut_reservation_build_req(16);
1280 : 5 : rsp = &req->rsp->nvme_cpl;
1281 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(req != NULL);
1282 : :
1283 : 5 : ut_reservation_build_registrants();
1284 : :
1285 : : /* ACQUIRE: Host A with g_ctrlr1_A get reservation with
1286 : : * type SPDK_NVME_RESERVE_WRITE_EXCLUSIVE_ALL_REGS
1287 : : */
1288 : 5 : ut_reservation_build_acquire_request(req, SPDK_NVME_RESERVE_ACQUIRE, 0,
1289 : : SPDK_NVME_RESERVE_WRITE_EXCLUSIVE_ALL_REGS, 0xa1, 0x0);
1290 : 5 : nvmf_ns_reservation_acquire(&g_ns, &g_ctrlr1_A, req);
1291 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_SUCCESS);
1292 : 5 : reg = nvmf_ns_reservation_get_registrant(&g_ns, &g_ctrlr1_A.hostid);
1293 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.rtype == SPDK_NVME_RESERVE_WRITE_EXCLUSIVE_ALL_REGS);
1294 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.holder == reg);
1295 : :
1296 : : /* Test Case: Host B release the reservation */
1297 : 5 : ut_reservation_build_release_request(req, SPDK_NVME_RESERVE_RELEASE, 0,
1298 : : SPDK_NVME_RESERVE_WRITE_EXCLUSIVE_ALL_REGS, 0xb1);
1299 : 5 : nvmf_ns_reservation_release(&g_ns, &g_ctrlr_B, req);
1300 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_SUCCESS);
1301 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.rtype == 0);
1302 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.crkey == 0);
1303 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.holder == NULL);
1304 : :
1305 : : /* Test Case: Host C clear the registrants */
1306 : 5 : ut_reservation_build_release_request(req, SPDK_NVME_RESERVE_CLEAR, 0,
1307 : : 0, 0xc1);
1308 : 5 : nvmf_ns_reservation_release(&g_ns, &g_ctrlr_C, req);
1309 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_SUCCESS);
1310 : 5 : reg = nvmf_ns_reservation_get_registrant(&g_ns, &g_ctrlr1_A.hostid);
1311 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(reg == NULL);
1312 : 5 : reg = nvmf_ns_reservation_get_registrant(&g_ns, &g_ctrlr2_A.hostid);
1313 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(reg == NULL);
1314 : 5 : reg = nvmf_ns_reservation_get_registrant(&g_ns, &g_ctrlr_B.hostid);
1315 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(reg == NULL);
1316 : 5 : reg = nvmf_ns_reservation_get_registrant(&g_ns, &g_ctrlr_C.hostid);
1317 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(reg == NULL);
1318 : :
1319 : 5 : ut_reservation_free_req(req);
1320 : 5 : ut_reservation_deinit();
1321 : 5 : }
1322 : :
1323 : : void
1324 : 110 : nvmf_ctrlr_reservation_notice_log(struct spdk_nvmf_ctrlr *ctrlr,
1325 : : struct spdk_nvmf_ns *ns,
1326 : : enum spdk_nvme_reservation_notification_log_page_type type)
1327 : : {
1328 : 110 : ctrlr->num_avail_log_pages++;
1329 : 110 : }
1330 : :
1331 : : static void
1332 : 5 : test_reservation_unregister_notification(void)
1333 : : {
1334 : : struct spdk_nvmf_request *req;
1335 : : struct spdk_nvme_cpl *rsp;
1336 : :
1337 : 5 : ut_reservation_init();
1338 : :
1339 : 5 : req = ut_reservation_build_req(16);
1340 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(req != NULL);
1341 : 5 : rsp = &req->rsp->nvme_cpl;
1342 : :
1343 : 5 : ut_reservation_build_registrants();
1344 : :
1345 : : /* ACQUIRE: Host B with g_ctrlr_B get reservation with
1346 : : * type SPDK_NVME_RESERVE_WRITE_EXCLUSIVE_REG_ONLY
1347 : : */
1348 : 5 : rsp->status.sc = 0xff;
1349 : 5 : ut_reservation_build_acquire_request(req, SPDK_NVME_RESERVE_ACQUIRE, 0,
1350 : : SPDK_NVME_RESERVE_WRITE_EXCLUSIVE_REG_ONLY, 0xb1, 0x0);
1351 : 5 : nvmf_ns_reservation_acquire(&g_ns, &g_ctrlr_B, req);
1352 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_SUCCESS);
1353 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.rtype == SPDK_NVME_RESERVE_WRITE_EXCLUSIVE_REG_ONLY);
1354 : :
1355 : : /* Test Case : g_ctrlr_B holds the reservation, g_ctrlr_B unregister the registration.
1356 : : * Reservation release notification sends to g_ctrlr1_A/g_ctrlr2_A/g_ctrlr_C only for
1357 : : * SPDK_NVME_RESERVE_WRITE_EXCLUSIVE_REG_ONLY or SPDK_NVME_RESERVE_EXCLUSIVE_ACCESS_REG_ONLY
1358 : : * type.
1359 : : */
1360 : 5 : rsp->status.sc = 0xff;
1361 : 5 : g_ctrlr1_A.num_avail_log_pages = 0;
1362 : 5 : g_ctrlr2_A.num_avail_log_pages = 0;
1363 : 5 : g_ctrlr_B.num_avail_log_pages = 5;
1364 : 5 : g_ctrlr_C.num_avail_log_pages = 0;
1365 : 5 : ut_reservation_build_register_request(req, SPDK_NVME_RESERVE_UNREGISTER_KEY,
1366 : : 0, 0, 0xb1, 0);
1367 : 5 : nvmf_ns_reservation_register(&g_ns, &g_ctrlr_B, req);
1368 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_SUCCESS);
1369 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.rtype == 0);
1370 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(1 == g_ctrlr1_A.num_avail_log_pages);
1371 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(1 == g_ctrlr2_A.num_avail_log_pages);
1372 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(5 == g_ctrlr_B.num_avail_log_pages);
1373 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(1 == g_ctrlr_C.num_avail_log_pages);
1374 : :
1375 : 5 : ut_reservation_free_req(req);
1376 : 5 : ut_reservation_deinit();
1377 : 5 : }
1378 : :
1379 : : static void
1380 : 5 : test_reservation_release_notification(void)
1381 : : {
1382 : : struct spdk_nvmf_request *req;
1383 : : struct spdk_nvme_cpl *rsp;
1384 : :
1385 : 5 : ut_reservation_init();
1386 : :
1387 : 5 : req = ut_reservation_build_req(16);
1388 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(req != NULL);
1389 : 5 : rsp = &req->rsp->nvme_cpl;
1390 : :
1391 : 5 : ut_reservation_build_registrants();
1392 : :
1393 : : /* ACQUIRE: Host B with g_ctrlr_B get reservation with
1394 : : * type SPDK_NVME_RESERVE_WRITE_EXCLUSIVE_REG_ONLY
1395 : : */
1396 : 5 : rsp->status.sc = 0xff;
1397 : 5 : ut_reservation_build_acquire_request(req, SPDK_NVME_RESERVE_ACQUIRE, 0,
1398 : : SPDK_NVME_RESERVE_WRITE_EXCLUSIVE_REG_ONLY, 0xb1, 0x0);
1399 : 5 : nvmf_ns_reservation_acquire(&g_ns, &g_ctrlr_B, req);
1400 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_SUCCESS);
1401 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.rtype == SPDK_NVME_RESERVE_WRITE_EXCLUSIVE_REG_ONLY);
1402 : :
1403 : : /* Test Case : g_ctrlr_B holds the reservation, g_ctrlr_B release the reservation.
1404 : : * Reservation release notification sends to g_ctrlr1_A/g_ctrlr2_A/g_ctrlr_C.
1405 : : */
1406 : 5 : rsp->status.sc = 0xff;
1407 : 5 : g_ctrlr1_A.num_avail_log_pages = 0;
1408 : 5 : g_ctrlr2_A.num_avail_log_pages = 0;
1409 : 5 : g_ctrlr_B.num_avail_log_pages = 5;
1410 : 5 : g_ctrlr_C.num_avail_log_pages = 0;
1411 : 5 : ut_reservation_build_release_request(req, SPDK_NVME_RESERVE_RELEASE, 0,
1412 : : SPDK_NVME_RESERVE_WRITE_EXCLUSIVE_REG_ONLY, 0xb1);
1413 : 5 : nvmf_ns_reservation_release(&g_ns, &g_ctrlr_B, req);
1414 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_SUCCESS);
1415 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.rtype == 0);
1416 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(1 == g_ctrlr1_A.num_avail_log_pages);
1417 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(1 == g_ctrlr2_A.num_avail_log_pages);
1418 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(5 == g_ctrlr_B.num_avail_log_pages);
1419 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(1 == g_ctrlr_C.num_avail_log_pages);
1420 : :
1421 : 5 : ut_reservation_free_req(req);
1422 : 5 : ut_reservation_deinit();
1423 : 5 : }
1424 : :
1425 : : static void
1426 : 5 : test_reservation_release_notification_write_exclusive(void)
1427 : : {
1428 : : struct spdk_nvmf_request *req;
1429 : : struct spdk_nvme_cpl *rsp;
1430 : :
1431 : 5 : ut_reservation_init();
1432 : :
1433 : 5 : req = ut_reservation_build_req(16);
1434 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(req != NULL);
1435 : 5 : rsp = &req->rsp->nvme_cpl;
1436 : :
1437 : 5 : ut_reservation_build_registrants();
1438 : :
1439 : : /* ACQUIRE: Host B with g_ctrlr_B get reservation with
1440 : : * type SPDK_NVME_RESERVE_WRITE_EXCLUSIVE
1441 : : */
1442 : 5 : rsp->status.sc = 0xff;
1443 : 5 : ut_reservation_build_acquire_request(req, SPDK_NVME_RESERVE_ACQUIRE, 0,
1444 : : SPDK_NVME_RESERVE_WRITE_EXCLUSIVE, 0xb1, 0x0);
1445 : 5 : nvmf_ns_reservation_acquire(&g_ns, &g_ctrlr_B, req);
1446 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_SUCCESS);
1447 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.rtype == SPDK_NVME_RESERVE_WRITE_EXCLUSIVE);
1448 : :
1449 : : /* Test Case : g_ctrlr_B holds the reservation, g_ctrlr_B release the reservation.
1450 : : * Because the reservation type is SPDK_NVME_RESERVE_WRITE_EXCLUSIVE,
1451 : : * no reservation notification occurs.
1452 : : */
1453 : 5 : rsp->status.sc = 0xff;
1454 : 5 : g_ctrlr1_A.num_avail_log_pages = 5;
1455 : 5 : g_ctrlr2_A.num_avail_log_pages = 5;
1456 : 5 : g_ctrlr_B.num_avail_log_pages = 5;
1457 : 5 : g_ctrlr_C.num_avail_log_pages = 5;
1458 : 5 : ut_reservation_build_release_request(req, SPDK_NVME_RESERVE_RELEASE, 0,
1459 : : SPDK_NVME_RESERVE_WRITE_EXCLUSIVE, 0xb1);
1460 : 5 : nvmf_ns_reservation_release(&g_ns, &g_ctrlr_B, req);
1461 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_SUCCESS);
1462 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.rtype == 0);
1463 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(5 == g_ctrlr1_A.num_avail_log_pages);
1464 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(5 == g_ctrlr2_A.num_avail_log_pages);
1465 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(5 == g_ctrlr_B.num_avail_log_pages);
1466 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(5 == g_ctrlr_C.num_avail_log_pages);
1467 : :
1468 : 5 : ut_reservation_free_req(req);
1469 : 5 : ut_reservation_deinit();
1470 : 5 : }
1471 : :
1472 : : static void
1473 : 5 : test_reservation_clear_notification(void)
1474 : : {
1475 : : struct spdk_nvmf_request *req;
1476 : : struct spdk_nvme_cpl *rsp;
1477 : :
1478 : 5 : ut_reservation_init();
1479 : :
1480 : 5 : req = ut_reservation_build_req(16);
1481 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(req != NULL);
1482 : 5 : rsp = &req->rsp->nvme_cpl;
1483 : :
1484 : 5 : ut_reservation_build_registrants();
1485 : :
1486 : : /* ACQUIRE: Host B with g_ctrlr_B get reservation with
1487 : : * type SPDK_NVME_RESERVE_WRITE_EXCLUSIVE_REG_ONLY
1488 : : */
1489 : 5 : rsp->status.sc = 0xff;
1490 : 5 : ut_reservation_build_acquire_request(req, SPDK_NVME_RESERVE_ACQUIRE, 0,
1491 : : SPDK_NVME_RESERVE_WRITE_EXCLUSIVE_REG_ONLY, 0xb1, 0x0);
1492 : 5 : nvmf_ns_reservation_acquire(&g_ns, &g_ctrlr_B, req);
1493 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_SUCCESS);
1494 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.rtype == SPDK_NVME_RESERVE_WRITE_EXCLUSIVE_REG_ONLY);
1495 : :
1496 : : /* Test Case : g_ctrlr_B holds the reservation, g_ctrlr_B clear the reservation.
1497 : : * Reservation Preempted notification sends to g_ctrlr1_A/g_ctrlr2_A/g_ctrlr_C.
1498 : : */
1499 : 5 : rsp->status.sc = 0xff;
1500 : 5 : g_ctrlr1_A.num_avail_log_pages = 0;
1501 : 5 : g_ctrlr2_A.num_avail_log_pages = 0;
1502 : 5 : g_ctrlr_B.num_avail_log_pages = 5;
1503 : 5 : g_ctrlr_C.num_avail_log_pages = 0;
1504 : 5 : ut_reservation_build_release_request(req, SPDK_NVME_RESERVE_CLEAR, 0,
1505 : : 0, 0xb1);
1506 : 5 : nvmf_ns_reservation_release(&g_ns, &g_ctrlr_B, req);
1507 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_SUCCESS);
1508 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.rtype == 0);
1509 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(1 == g_ctrlr1_A.num_avail_log_pages);
1510 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(1 == g_ctrlr2_A.num_avail_log_pages);
1511 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(5 == g_ctrlr_B.num_avail_log_pages);
1512 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(1 == g_ctrlr_C.num_avail_log_pages);
1513 : :
1514 : 5 : ut_reservation_free_req(req);
1515 : 5 : ut_reservation_deinit();
1516 : 5 : }
1517 : :
1518 : : static void
1519 : 5 : test_reservation_preempt_notification(void)
1520 : : {
1521 : : struct spdk_nvmf_request *req;
1522 : : struct spdk_nvme_cpl *rsp;
1523 : :
1524 : 5 : ut_reservation_init();
1525 : :
1526 : 5 : req = ut_reservation_build_req(16);
1527 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(req != NULL);
1528 : 5 : rsp = &req->rsp->nvme_cpl;
1529 : :
1530 : 5 : ut_reservation_build_registrants();
1531 : :
1532 : : /* ACQUIRE: Host B with g_ctrlr_B get reservation with
1533 : : * type SPDK_NVME_RESERVE_WRITE_EXCLUSIVE_REG_ONLY
1534 : : */
1535 : 5 : rsp->status.sc = 0xff;
1536 : 5 : ut_reservation_build_acquire_request(req, SPDK_NVME_RESERVE_ACQUIRE, 0,
1537 : : SPDK_NVME_RESERVE_WRITE_EXCLUSIVE_REG_ONLY, 0xb1, 0x0);
1538 : 5 : nvmf_ns_reservation_acquire(&g_ns, &g_ctrlr_B, req);
1539 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_SUCCESS);
1540 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.rtype == SPDK_NVME_RESERVE_WRITE_EXCLUSIVE_REG_ONLY);
1541 : :
1542 : : /* Test Case : g_ctrlr_B holds the reservation, g_ctrlr_C preempt g_ctrlr_B,
1543 : : * g_ctrlr_B registrant is unregistered, and reservation is preempted.
1544 : : * Registration Preempted notification sends to g_ctrlr_B.
1545 : : * Reservation Preempted notification sends to g_ctrlr1_A/g_ctrlr2_A.
1546 : : */
1547 : 5 : rsp->status.sc = 0xff;
1548 : 5 : g_ctrlr1_A.num_avail_log_pages = 0;
1549 : 5 : g_ctrlr2_A.num_avail_log_pages = 0;
1550 : 5 : g_ctrlr_B.num_avail_log_pages = 0;
1551 : 5 : g_ctrlr_C.num_avail_log_pages = 5;
1552 : 5 : ut_reservation_build_acquire_request(req, SPDK_NVME_RESERVE_PREEMPT, 0,
1553 : : SPDK_NVME_RESERVE_WRITE_EXCLUSIVE_ALL_REGS, 0xc1, 0xb1);
1554 : 5 : nvmf_ns_reservation_acquire(&g_ns, &g_ctrlr_C, req);
1555 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_SUCCESS);
1556 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.rtype == SPDK_NVME_RESERVE_WRITE_EXCLUSIVE_ALL_REGS);
1557 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(1 == g_ctrlr1_A.num_avail_log_pages);
1558 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(1 == g_ctrlr2_A.num_avail_log_pages);
1559 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(1 == g_ctrlr_B.num_avail_log_pages);
1560 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(5 == g_ctrlr_C.num_avail_log_pages);
1561 : :
1562 : 5 : ut_reservation_free_req(req);
1563 : 5 : ut_reservation_deinit();
1564 : 5 : }
1565 : :
1566 : : static int
1567 : 0 : nvmf_tgt_create_poll_group(void *io_device, void *ctx_buf)
1568 : : {
1569 : 0 : return 0;
1570 : : }
1571 : :
1572 : : static void
1573 : 0 : nvmf_tgt_destroy_poll_group(void *io_device, void *ctx_buf)
1574 : : {
1575 : 0 : }
1576 : :
1577 : : static void
1578 : 5 : test_spdk_nvmf_ns_event(void)
1579 : : {
1580 : 5 : struct spdk_nvmf_tgt tgt = {};
1581 : 5 : struct spdk_nvmf_subsystem subsystem = {
1582 : : .max_nsid = 1024,
1583 : : .ns = NULL,
1584 : : .tgt = &tgt,
1585 : : .state_changes = TAILQ_HEAD_INITIALIZER(subsystem.state_changes),
1586 : : };
1587 : 5 : struct spdk_nvmf_ctrlr ctrlr = {
1588 : : .subsys = &subsystem
1589 : : };
1590 : 4 : struct spdk_nvmf_ns_opts ns_opts;
1591 : : uint32_t nsid;
1592 : : struct spdk_bdev *bdev;
1593 : : struct spdk_thread *thread;
1594 : :
1595 : 5 : ctrlr.visible_ns = spdk_bit_array_create(1);
1596 : 5 : spdk_bit_array_set(ctrlr.visible_ns, 0);
1597 : :
1598 : 5 : thread = spdk_get_thread();
1599 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(thread != NULL);
1600 : :
1601 : 5 : subsystem.ns = calloc(subsystem.max_nsid, sizeof(struct spdk_nvmf_subsystem_ns *));
1602 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(subsystem.ns != NULL);
1603 : 5 : subsystem.ana_group = calloc(subsystem.max_nsid, sizeof(uint32_t));
1604 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(subsystem.ana_group != NULL);
1605 : :
1606 : 5 : tgt.max_subsystems = 1024;
1607 : 5 : tgt.subsystem_ids = spdk_bit_array_create(tgt.max_subsystems);
1608 : 5 : RB_INIT(&tgt.subsystems);
1609 : :
1610 : 5 : spdk_io_device_register(&tgt,
1611 : : nvmf_tgt_create_poll_group,
1612 : : nvmf_tgt_destroy_poll_group,
1613 : : sizeof(struct spdk_nvmf_poll_group),
1614 : : NULL);
1615 : :
1616 : : /* Add one namespace */
1617 : 5 : spdk_nvmf_ns_opts_get_defaults(&ns_opts, sizeof(ns_opts));
1618 : 5 : nsid = spdk_nvmf_subsystem_add_ns_ext(&subsystem, "bdev1", &ns_opts, sizeof(ns_opts), NULL);
1619 : 5 : CU_ASSERT(nsid == 1);
1620 : 5 : CU_ASSERT(NULL != subsystem.ns[0]);
1621 : 5 : CU_ASSERT(subsystem.ns[nsid - 1]->bdev == &g_bdevs[nsid - 1]);
1622 : :
1623 : 5 : bdev = subsystem.ns[nsid - 1]->bdev;
1624 : :
1625 : : /* Add one controller */
1626 : 5 : TAILQ_INIT(&subsystem.ctrlrs);
1627 : 5 : TAILQ_INSERT_TAIL(&subsystem.ctrlrs, &ctrlr, link);
1628 : :
1629 : : /* Namespace resize event */
1630 : 5 : subsystem.state = SPDK_NVMF_SUBSYSTEM_ACTIVE;
1631 : 5 : g_ns_changed_nsid = 0xFFFFFFFF;
1632 : 5 : g_ns_changed_ctrlr = NULL;
1633 : 5 : nvmf_ns_event(SPDK_BDEV_EVENT_RESIZE, bdev, subsystem.ns[0]);
1634 : 5 : CU_ASSERT(SPDK_NVMF_SUBSYSTEM_PAUSING == subsystem.state);
1635 : :
1636 : 5 : poll_threads();
1637 : 5 : CU_ASSERT(1 == g_ns_changed_nsid);
1638 : 5 : CU_ASSERT(&ctrlr == g_ns_changed_ctrlr);
1639 : 5 : CU_ASSERT(SPDK_NVMF_SUBSYSTEM_ACTIVE == subsystem.state);
1640 : :
1641 : : /* Namespace remove event */
1642 : 5 : subsystem.state = SPDK_NVMF_SUBSYSTEM_ACTIVE;
1643 : 5 : g_ns_changed_nsid = 0xFFFFFFFF;
1644 : 5 : g_ns_changed_ctrlr = NULL;
1645 : 5 : nvmf_ns_event(SPDK_BDEV_EVENT_REMOVE, bdev, subsystem.ns[0]);
1646 : 5 : CU_ASSERT(SPDK_NVMF_SUBSYSTEM_PAUSING == subsystem.state);
1647 : 5 : CU_ASSERT(0xFFFFFFFF == g_ns_changed_nsid);
1648 : 5 : CU_ASSERT(NULL == g_ns_changed_ctrlr);
1649 : :
1650 : 5 : poll_threads();
1651 : 5 : CU_ASSERT(1 == g_ns_changed_nsid);
1652 : 5 : CU_ASSERT(&ctrlr == g_ns_changed_ctrlr);
1653 : 5 : CU_ASSERT(NULL == subsystem.ns[0]);
1654 : 5 : CU_ASSERT(SPDK_NVMF_SUBSYSTEM_ACTIVE == subsystem.state);
1655 : :
1656 : 5 : spdk_io_device_unregister(&tgt, NULL);
1657 : :
1658 : 5 : poll_threads();
1659 : :
1660 : 5 : free(subsystem.ns);
1661 : 5 : free(subsystem.ana_group);
1662 : 5 : spdk_bit_array_free(&ctrlr.visible_ns);
1663 : 5 : spdk_bit_array_free(&tgt.subsystem_ids);
1664 : 5 : }
1665 : :
1666 : : static void
1667 : 5 : test_nvmf_ns_reservation_add_remove_registrant(void)
1668 : : {
1669 : 5 : struct spdk_nvmf_ns ns = {};
1670 : 5 : struct spdk_nvmf_ctrlr ctrlr = {};
1671 : 5 : struct spdk_nvmf_registrant *reg = NULL;
1672 : : int rc;
1673 : :
1674 : 5 : TAILQ_INIT(&ns.registrants);
1675 : 5 : spdk_uuid_generate(&ctrlr.hostid);
1676 : :
1677 : 5 : rc = nvmf_ns_reservation_add_registrant(&ns, &ctrlr, 0xa11);
1678 : 5 : CU_ASSERT(rc == 0);
1679 : 5 : reg = TAILQ_FIRST(&ns.registrants);
1680 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(reg != NULL);
1681 : 5 : CU_ASSERT(ns.gen == 1);
1682 : 5 : CU_ASSERT(reg->rkey == 0xa11);
1683 [ - + ]: 5 : CU_ASSERT(!strncmp((uint8_t *)®->hostid, (uint8_t *)&ctrlr.hostid, sizeof(ctrlr.hostid)));
1684 : :
1685 : 5 : nvmf_ns_reservation_remove_registrant(&ns, reg);
1686 : 5 : CU_ASSERT(TAILQ_EMPTY(&ns.registrants));
1687 : 5 : CU_ASSERT(ns.gen == 2);
1688 : 5 : }
1689 : :
1690 : : static void
1691 : 0 : test_nvmf_subsystem_destroy_cb(void *cb_arg)
1692 : : {
1693 : 0 : }
1694 : :
1695 : : static void
1696 : 5 : test_nvmf_subsystem_add_ctrlr(void)
1697 : : {
1698 : : int rc;
1699 : 5 : struct spdk_nvmf_ctrlr ctrlr = {};
1700 : 5 : struct spdk_nvmf_tgt tgt = {};
1701 : 5 : char nqn[256] = "nqn.2016-06.io.spdk:subsystem1";
1702 : 5 : struct spdk_nvmf_subsystem *subsystem = NULL;
1703 : :
1704 : 5 : tgt.max_subsystems = 1024;
1705 : 5 : tgt.subsystem_ids = spdk_bit_array_create(tgt.max_subsystems);
1706 : 5 : RB_INIT(&tgt.subsystems);
1707 : :
1708 : 5 : subsystem = spdk_nvmf_subsystem_create(&tgt, nqn, SPDK_NVMF_SUBTYPE_NVME, 0);
1709 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(subsystem != NULL);
1710 : 5 : ctrlr.subsys = subsystem;
1711 : :
1712 : 5 : ctrlr.dynamic_ctrlr = true;
1713 : 5 : rc = nvmf_subsystem_add_ctrlr(subsystem, &ctrlr);
1714 : 5 : CU_ASSERT(rc == 0);
1715 : 5 : CU_ASSERT(!TAILQ_EMPTY(&subsystem->ctrlrs));
1716 : 5 : CU_ASSERT(ctrlr.cntlid == 1);
1717 : 5 : CU_ASSERT(nvmf_subsystem_get_ctrlr(subsystem, 1) == &ctrlr);
1718 : :
1719 : 5 : nvmf_subsystem_remove_ctrlr(subsystem, &ctrlr);
1720 : 5 : CU_ASSERT(TAILQ_EMPTY(&subsystem->ctrlrs));
1721 : 5 : rc = spdk_nvmf_subsystem_destroy(subsystem, test_nvmf_subsystem_destroy_cb, NULL);
1722 : 5 : CU_ASSERT(rc == 0);
1723 : 5 : spdk_bit_array_free(&tgt.subsystem_ids);
1724 : 5 : }
1725 : :
1726 : : static void
1727 : 0 : _add_transport_cb(void *arg, int status)
1728 : : {
1729 : 0 : CU_ASSERT(status == 0);
1730 : 0 : }
1731 : :
1732 : : static int
1733 : 5 : transport_subsystem_add_host_err(struct spdk_nvmf_transport *transport,
1734 : : const struct spdk_nvmf_subsystem *subsystem,
1735 : : const char *hostnqn,
1736 : : const struct spdk_json_val *transport_specific)
1737 : : {
1738 : 5 : return -1;
1739 : : }
1740 : :
1741 : : void
1742 : 5 : spdk_nvmf_tgt_add_transport(struct spdk_nvmf_tgt *tgt,
1743 : : struct spdk_nvmf_transport *transport,
1744 : : spdk_nvmf_tgt_add_transport_done_fn cb_fn,
1745 : : void *cb_arg)
1746 : : {
1747 : 5 : TAILQ_INSERT_TAIL(&tgt->transports, transport, link);
1748 : 5 : }
1749 : :
1750 : : static struct spdk_nvmf_transport *
1751 : 5 : transport_create(struct spdk_nvmf_transport_opts *opts)
1752 : : {
1753 : 5 : return &g_transport;
1754 : : }
1755 : :
1756 : : static void
1757 : 5 : test_spdk_nvmf_subsystem_add_host(void)
1758 : : {
1759 : 5 : struct spdk_nvmf_tgt tgt = {};
1760 : 5 : struct spdk_nvmf_subsystem *subsystem = NULL;
1761 : : int rc;
1762 : 5 : const char hostnqn[] = "nqn.2016-06.io.spdk:host1";
1763 : 5 : const char subsystemnqn[] = "nqn.2016-06.io.spdk:subsystem1";
1764 : 5 : struct spdk_nvmf_transport_opts opts = {
1765 : : .opts_size = sizeof(struct spdk_nvmf_transport_opts),
1766 : : .io_unit_size = 8192
1767 : : };
1768 : 5 : const struct spdk_nvmf_transport_ops test_ops = {
1769 : : .name = "transport_ut",
1770 : : .create = transport_create,
1771 : : .subsystem_add_host = transport_subsystem_add_host_err,
1772 : : };
1773 : : struct spdk_nvmf_transport *transport;
1774 : :
1775 : 5 : tgt.max_subsystems = 1024;
1776 : 5 : tgt.subsystem_ids = spdk_bit_array_create(tgt.max_subsystems);
1777 : 5 : RB_INIT(&tgt.subsystems);
1778 : :
1779 : 5 : subsystem = spdk_nvmf_subsystem_create(&tgt, subsystemnqn, SPDK_NVMF_SUBTYPE_NVME, 0);
1780 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(subsystem != NULL);
1781 [ - + ]: 5 : CU_ASSERT_STRING_EQUAL(subsystem->subnqn, subsystemnqn);
1782 : :
1783 : 5 : rc = spdk_nvmf_subsystem_add_host(subsystem, hostnqn, NULL);
1784 : 5 : CU_ASSERT(rc == 0);
1785 : 5 : CU_ASSERT(!TAILQ_EMPTY(&subsystem->hosts));
1786 : :
1787 : : /* Add existing nqn, this function isn't allowed to be called if the nqn was previously added. */
1788 : 5 : rc = spdk_nvmf_subsystem_add_host(subsystem, hostnqn, NULL);
1789 : 5 : CU_ASSERT(rc == -EINVAL);
1790 : :
1791 : 5 : rc = spdk_nvmf_subsystem_remove_host(subsystem, hostnqn);
1792 : 5 : CU_ASSERT(rc == 0);
1793 : 5 : CU_ASSERT(TAILQ_EMPTY(&subsystem->hosts));
1794 : :
1795 : : /* No available nqn */
1796 : 5 : rc = spdk_nvmf_subsystem_remove_host(subsystem, hostnqn);
1797 : 5 : CU_ASSERT(rc == -ENOENT);
1798 : :
1799 : : /* Ensure hostnqn list remains empty after transport callback fails */
1800 : 5 : spdk_nvmf_transport_register(&test_ops);
1801 : 5 : transport = spdk_nvmf_transport_create("transport_ut", &opts);
1802 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(transport != NULL);
1803 : :
1804 : 5 : TAILQ_INIT(&tgt.transports);
1805 : 5 : spdk_nvmf_tgt_add_transport(&tgt, transport, _add_transport_cb, 0);
1806 : :
1807 : 5 : rc = spdk_nvmf_subsystem_add_host(subsystem, hostnqn, NULL);
1808 : 5 : CU_ASSERT(rc != 0);
1809 : 5 : CU_ASSERT(TAILQ_EMPTY(&subsystem->hosts));
1810 : :
1811 : 5 : spdk_nvmf_subsystem_destroy(subsystem, NULL, NULL);
1812 : 5 : spdk_bit_array_free(&tgt.subsystem_ids);
1813 : 5 : }
1814 : :
1815 : : static void
1816 : 5 : test_nvmf_ns_reservation_report(void)
1817 : : {
1818 : 5 : struct spdk_nvmf_ns ns = {};
1819 : 5 : struct spdk_nvmf_ctrlr ctrlr = {};
1820 : 5 : struct spdk_nvmf_request req = {};
1821 : 5 : union nvmf_h2c_msg cmd = {};
1822 : 5 : union nvmf_c2h_msg rsp = {};
1823 : : struct spdk_nvme_registered_ctrlr_extended_data *ctrlr_data;
1824 : : struct spdk_nvme_reservation_status_extended_data *status_data;
1825 : : struct spdk_nvmf_registrant *reg;
1826 : : void *data;
1827 : :
1828 : 5 : data = calloc(1, sizeof(*status_data) + sizeof(*ctrlr_data) * 2);
1829 : 5 : reg = calloc(2, sizeof(struct spdk_nvmf_registrant));
1830 [ + - + - : 5 : SPDK_CU_ASSERT_FATAL(data != NULL && reg != NULL);
- + ]
1831 : :
1832 : 5 : req.length = sizeof(*status_data) + sizeof(*ctrlr_data) * 2;
1833 : 5 : SPDK_IOV_ONE(req.iov, &req.iovcnt, data, req.length);
1834 : :
1835 : 5 : req.cmd = &cmd;
1836 : 5 : req.rsp = &rsp;
1837 : 5 : ns.gen = 1;
1838 : 5 : ns.rtype = SPDK_NVME_RESERVE_WRITE_EXCLUSIVE;
1839 : 5 : ns.ptpl_activated = true;
1840 : 5 : cmd.nvme_cmd.cdw11_bits.resv_report.eds = true;
1841 : 5 : cmd.nvme_cmd.cdw10 = 100;
1842 : 5 : reg[0].rkey = 0xa;
1843 : 5 : reg[1].rkey = 0xb;
1844 : 5 : spdk_uuid_generate(®[0].hostid);
1845 : 5 : spdk_uuid_generate(®[1].hostid);
1846 : 5 : TAILQ_INIT(&ns.registrants);
1847 : 5 : TAILQ_INSERT_TAIL(&ns.registrants, ®[0], link);
1848 : 5 : TAILQ_INSERT_TAIL(&ns.registrants, ®[1], link);
1849 : :
1850 : 5 : nvmf_ns_reservation_report(&ns, &ctrlr, &req);
1851 : 5 : CU_ASSERT(req.rsp->nvme_cpl.status.sct == SPDK_NVME_SCT_GENERIC);
1852 : 5 : CU_ASSERT(req.rsp->nvme_cpl.status.sc == SPDK_NVME_SC_SUCCESS);
1853 : : /* Get ctrlr data and status data pointers */
1854 : 5 : ctrlr_data = (void *)((char *)req.iov[0].iov_base + sizeof(*status_data));
1855 : 5 : status_data = (void *)req.iov[0].iov_base;
1856 [ + - + - : 5 : SPDK_CU_ASSERT_FATAL(status_data != NULL && ctrlr_data != NULL);
- + ]
1857 : 5 : CU_ASSERT(status_data->data.gen == 1);
1858 : 5 : CU_ASSERT(status_data->data.rtype == SPDK_NVME_RESERVE_WRITE_EXCLUSIVE);
1859 : 5 : CU_ASSERT(status_data->data.ptpls == true);
1860 : 5 : CU_ASSERT(status_data->data.regctl == 2);
1861 : 5 : CU_ASSERT(ctrlr_data->cntlid == 0xffff);
1862 : 5 : CU_ASSERT(ctrlr_data->rcsts.status == false);
1863 : 5 : CU_ASSERT(ctrlr_data->rkey == 0xa);
1864 : 5 : CU_ASSERT(!spdk_uuid_compare((struct spdk_uuid *)ctrlr_data->hostid, ®[0].hostid));
1865 : : /* Check second ctrlr data */
1866 : 5 : ctrlr_data++;
1867 : 5 : CU_ASSERT(ctrlr_data->cntlid == 0xffff);
1868 : 5 : CU_ASSERT(ctrlr_data->rcsts.status == false);
1869 : 5 : CU_ASSERT(ctrlr_data->rkey == 0xb);
1870 : 5 : CU_ASSERT(!spdk_uuid_compare((struct spdk_uuid *)ctrlr_data->hostid, ®[1].hostid));
1871 : :
1872 : : /* extended controller data structure */
1873 : 5 : spdk_iov_memset(req.iov, req.iovcnt, 0);
1874 [ - + ]: 5 : memset(req.rsp, 0, sizeof(*req.rsp));
1875 : 5 : cmd.nvme_cmd.cdw11_bits.resv_report.eds = false;
1876 : :
1877 : 5 : nvmf_ns_reservation_report(&ns, &ctrlr, &req);
1878 : 5 : CU_ASSERT(req.rsp->nvme_cpl.status.sc == SPDK_NVME_SC_HOSTID_INCONSISTENT_FORMAT);
1879 : 5 : CU_ASSERT(req.rsp->nvme_cpl.status.sct == SPDK_NVME_SCT_GENERIC);
1880 : :
1881 : : /* Transfer length invalid */
1882 : 5 : spdk_iov_memset(req.iov, req.iovcnt, 0);
1883 [ - + ]: 5 : memset(req.rsp, 0, sizeof(*req.rsp));
1884 : 5 : cmd.nvme_cmd.cdw11_bits.resv_report.eds = true;
1885 : 5 : cmd.nvme_cmd.cdw10 = 0;
1886 : :
1887 : 5 : nvmf_ns_reservation_report(&ns, &ctrlr, &req);
1888 : 5 : CU_ASSERT(req.rsp->nvme_cpl.status.sc == SPDK_NVME_SC_INTERNAL_DEVICE_ERROR);
1889 : 5 : CU_ASSERT(req.rsp->nvme_cpl.status.sct == SPDK_NVME_SCT_GENERIC);
1890 : :
1891 : 5 : free(req.iov[0].iov_base);
1892 : 5 : free(reg);
1893 : 5 : }
1894 : :
1895 : : static void
1896 : 5 : test_nvmf_nqn_is_valid(void)
1897 : : {
1898 : : bool rc;
1899 : 5 : char uuid[SPDK_NVMF_UUID_STRING_LEN + 1] = {};
1900 : 5 : char nqn[SPDK_NVMF_NQN_MAX_LEN + 1] = {};
1901 : 5 : struct spdk_uuid s_uuid = {};
1902 : :
1903 : 5 : spdk_uuid_generate(&s_uuid);
1904 : 5 : spdk_uuid_fmt_lower(uuid, sizeof(uuid), &s_uuid);
1905 : :
1906 : : /* discovery nqn */
1907 [ - + ]: 5 : snprintf(nqn, sizeof(nqn), "%s", SPDK_NVMF_DISCOVERY_NQN);
1908 : :
1909 : 5 : rc = nvmf_nqn_is_valid(nqn);
1910 : 5 : CU_ASSERT(rc == true);
1911 : :
1912 : : /* nqn with uuid */
1913 [ - + ]: 5 : memset(nqn, 0xff, sizeof(nqn));
1914 [ - + ]: 5 : snprintf(nqn, sizeof(nqn), "%s%s", SPDK_NVMF_NQN_UUID_PRE, uuid);
1915 : :
1916 : 5 : rc = nvmf_nqn_is_valid(nqn);
1917 : 5 : CU_ASSERT(rc == true);
1918 : :
1919 : : /* Check nqn valid reverse domain */
1920 [ - + ]: 5 : memset(nqn, 0xff, sizeof(nqn));
1921 [ - + ]: 5 : snprintf(nqn, sizeof(nqn), "%s", "nqn.2016-06.io.spdk:cnode1");
1922 : :
1923 : 5 : rc = nvmf_nqn_is_valid(nqn);
1924 : 5 : CU_ASSERT(rc == true);
1925 : :
1926 : : /* Invalid nqn length */
1927 [ - + ]: 5 : memset(nqn, 0xff, sizeof(nqn));
1928 [ - + ]: 5 : snprintf(nqn, sizeof(nqn), "%s", "nqn.");
1929 : :
1930 : 5 : rc = nvmf_nqn_is_valid(nqn);
1931 : 5 : CU_ASSERT(rc == false);
1932 : :
1933 : : /* Copy uuid to the nqn string, but omit the last character to make it invalid */
1934 [ - + ]: 5 : memset(nqn, 0, SPDK_NVMF_NQN_MAX_LEN + 1);
1935 [ - + ]: 5 : snprintf(nqn, sizeof(nqn), "%s", SPDK_NVMF_NQN_UUID_PRE);
1936 [ - + - + ]: 5 : memcpy(&nqn[SPDK_NVMF_NQN_UUID_PRE_LEN], uuid, SPDK_NVMF_UUID_STRING_LEN - 1);
1937 : :
1938 : 5 : rc = nvmf_nqn_is_valid(nqn);
1939 : 5 : CU_ASSERT(rc == false);
1940 : :
1941 : : /* Invalid domain */
1942 [ - + ]: 5 : memset(nqn, 0xff, SPDK_NVMF_NQN_MAX_LEN + 1);
1943 [ - + ]: 5 : snprintf(nqn, sizeof(nqn), "%s", "nqn.2016-06.io...spdk:cnode1");
1944 : :
1945 : 5 : rc = nvmf_nqn_is_valid(nqn);
1946 : 5 : CU_ASSERT(rc == false);
1947 : 5 : }
1948 : :
1949 : : static void
1950 : 5 : test_nvmf_ns_reservation_restore(void)
1951 : : {
1952 : 5 : struct spdk_nvmf_ns ns = {};
1953 : 5 : struct spdk_nvmf_reservation_info info = {};
1954 : 5 : struct spdk_bdev bdev = {};
1955 : 5 : struct spdk_uuid s_uuid = {};
1956 : : struct spdk_nvmf_registrant *reg0, *reg1;
1957 : 5 : char uuid[SPDK_UUID_STRING_LEN] = {};
1958 : : int rc;
1959 : :
1960 : 5 : ns.bdev = &bdev;
1961 : 5 : TAILQ_INIT(&ns.registrants);
1962 : 5 : info.ptpl_activated = true;
1963 : 5 : info.num_regs = 2;
1964 : 5 : info.rtype = SPDK_NVME_RESERVE_WRITE_EXCLUSIVE_ALL_REGS;
1965 : 5 : info.registrants[0].rkey = 0xb;
1966 : 5 : info.registrants[1].rkey = 0xc;
1967 : :
1968 : : /* Generate and prepare uuids, make sure bdev and info uuid are the same */
1969 : 5 : spdk_uuid_generate(&s_uuid);
1970 : 5 : spdk_uuid_fmt_lower(uuid, sizeof(uuid), &s_uuid);
1971 [ - + ]: 5 : snprintf(info.holder_uuid, SPDK_UUID_STRING_LEN, "%s", uuid);
1972 [ - + ]: 5 : snprintf(info.bdev_uuid, SPDK_UUID_STRING_LEN, "%s", uuid);
1973 [ - + ]: 5 : snprintf(info.registrants[0].host_uuid, SPDK_UUID_STRING_LEN, "%s", uuid);
1974 : 5 : spdk_uuid_copy(&bdev.uuid, &s_uuid);
1975 : 5 : spdk_uuid_generate(&s_uuid);
1976 : 5 : spdk_uuid_fmt_lower(uuid, sizeof(uuid), &s_uuid);
1977 [ - + ]: 5 : snprintf(info.registrants[1].host_uuid, SPDK_UUID_STRING_LEN, "%s", uuid);
1978 : :
1979 : : /* info->rkey not exist in registrants */
1980 : 5 : info.crkey = 0xa;
1981 : :
1982 : 5 : rc = nvmf_ns_reservation_restore(&ns, &info);
1983 : 5 : CU_ASSERT(rc == -EINVAL);
1984 : :
1985 : : /* info->rkey exists in registrants */
1986 : 5 : info.crkey = 0xb;
1987 : :
1988 : 5 : rc = nvmf_ns_reservation_restore(&ns, &info);
1989 : 5 : CU_ASSERT(rc == 0);
1990 : 5 : CU_ASSERT(ns.crkey == 0xb);
1991 : 5 : CU_ASSERT(ns.rtype == SPDK_NVME_RESERVE_WRITE_EXCLUSIVE_ALL_REGS);
1992 [ - + ]: 5 : CU_ASSERT(ns.ptpl_activated == true);
1993 : : /* Check two registrant`s rkey */
1994 : 5 : reg0 = TAILQ_FIRST(&ns.registrants);
1995 : 5 : reg1 = TAILQ_NEXT(reg0, link);
1996 : 5 : CU_ASSERT(ns.holder == reg0);
1997 : 5 : CU_ASSERT(reg0->rkey = 0xb);
1998 : 5 : CU_ASSERT(reg1->rkey = 0xc);
1999 : :
2000 : 5 : rc = nvmf_ns_reservation_clear_all_registrants(&ns);
2001 : 5 : CU_ASSERT(rc == 2);
2002 : 5 : CU_ASSERT(TAILQ_EMPTY(&ns.registrants));
2003 : :
2004 : : /* Existing bdev UUID is different with configuration */
2005 : 5 : spdk_uuid_generate(&s_uuid);
2006 : 5 : spdk_uuid_fmt_lower(uuid, sizeof(uuid), &s_uuid);
2007 [ - + ]: 5 : snprintf(info.bdev_uuid, SPDK_UUID_STRING_LEN, "%s", uuid);
2008 : 5 : spdk_uuid_generate(&s_uuid);
2009 : 5 : spdk_uuid_copy(&bdev.uuid, &s_uuid);
2010 : :
2011 : 5 : rc = nvmf_ns_reservation_restore(&ns, &info);
2012 : 5 : CU_ASSERT(rc == -EINVAL);
2013 : :
2014 : : /* Check restore without reservation */
2015 : 5 : spdk_uuid_fmt_lower(info.bdev_uuid, sizeof(info.bdev_uuid), &bdev.uuid);
2016 : 5 : info.rtype = 0;
2017 : 5 : info.crkey = 0;
2018 [ - + ]: 5 : memset(info.holder_uuid, 0, SPDK_UUID_STRING_LEN);
2019 : :
2020 : 5 : rc = nvmf_ns_reservation_restore(&ns, &info);
2021 : 5 : CU_ASSERT(rc == 0);
2022 : 5 : CU_ASSERT(ns.crkey == 0);
2023 : 5 : CU_ASSERT(ns.rtype == 0);
2024 [ - + ]: 5 : CU_ASSERT(ns.ptpl_activated == true);
2025 : 5 : CU_ASSERT(ns.holder == NULL);
2026 : 5 : reg0 = TAILQ_FIRST(&ns.registrants);
2027 : 5 : reg1 = TAILQ_NEXT(reg0, link);
2028 : 5 : CU_ASSERT(reg0->rkey = 0xb);
2029 : 5 : CU_ASSERT(reg1->rkey = 0xc);
2030 : :
2031 : 5 : rc = nvmf_ns_reservation_clear_all_registrants(&ns);
2032 : 5 : CU_ASSERT(rc == 2);
2033 : 5 : CU_ASSERT(TAILQ_EMPTY(&ns.registrants));
2034 : 5 : }
2035 : :
2036 : : static void
2037 : 5 : ut_nvmf_subsystem_paused(struct spdk_nvmf_subsystem *subsystem, void *ctx, int status)
2038 : : {
2039 : 5 : CU_ASSERT_EQUAL(status, 0);
2040 : 5 : CU_ASSERT_EQUAL(subsystem->state, SPDK_NVMF_SUBSYSTEM_PAUSED);
2041 : 5 : }
2042 : :
2043 : : static void
2044 : 5 : test_nvmf_subsystem_state_change(void)
2045 : : {
2046 : 5 : struct spdk_nvmf_tgt tgt = {};
2047 : : struct spdk_nvmf_subsystem *subsystem, *discovery_subsystem;
2048 : : int rc;
2049 : :
2050 : 5 : tgt.max_subsystems = 1024;
2051 : 5 : tgt.subsystem_ids = spdk_bit_array_create(tgt.max_subsystems);
2052 : 5 : RB_INIT(&tgt.subsystems);
2053 : :
2054 : 5 : discovery_subsystem = spdk_nvmf_subsystem_create(&tgt, SPDK_NVMF_DISCOVERY_NQN,
2055 : : SPDK_NVMF_SUBTYPE_DISCOVERY_CURRENT, 0);
2056 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(discovery_subsystem != NULL);
2057 : 5 : subsystem = spdk_nvmf_subsystem_create(&tgt, "nqn.2016-06.io.spdk:subsystem1",
2058 : : SPDK_NVMF_SUBTYPE_NVME, 0);
2059 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(subsystem != NULL);
2060 : :
2061 : 5 : spdk_io_device_register(&tgt,
2062 : : nvmf_tgt_create_poll_group,
2063 : : nvmf_tgt_destroy_poll_group,
2064 : : sizeof(struct spdk_nvmf_poll_group),
2065 : : NULL);
2066 : :
2067 : 5 : rc = spdk_nvmf_subsystem_start(discovery_subsystem, NULL, NULL);
2068 : 5 : CU_ASSERT(rc == 0);
2069 : 5 : poll_threads();
2070 : 5 : CU_ASSERT(discovery_subsystem->state == SPDK_NVMF_SUBSYSTEM_ACTIVE);
2071 : 5 : rc = spdk_nvmf_subsystem_start(subsystem, NULL, NULL);
2072 : 5 : CU_ASSERT(rc == 0);
2073 : 5 : poll_threads();
2074 : 5 : CU_ASSERT(subsystem->state == SPDK_NVMF_SUBSYSTEM_ACTIVE);
2075 : :
2076 : 5 : rc = spdk_nvmf_subsystem_pause(subsystem, SPDK_NVME_GLOBAL_NS_TAG,
2077 : : ut_nvmf_subsystem_paused, NULL);
2078 : 5 : CU_ASSERT(rc == 0);
2079 : 5 : rc = spdk_nvmf_subsystem_stop(subsystem, NULL, NULL);
2080 : 5 : CU_ASSERT(rc == 0);
2081 : 5 : poll_threads();
2082 : 5 : CU_ASSERT(subsystem->state == SPDK_NVMF_SUBSYSTEM_INACTIVE);
2083 : :
2084 : 5 : rc = spdk_nvmf_subsystem_stop(discovery_subsystem, NULL, NULL);
2085 : 5 : CU_ASSERT(rc == 0);
2086 : 5 : poll_threads();
2087 : 5 : CU_ASSERT(discovery_subsystem->state == SPDK_NVMF_SUBSYSTEM_INACTIVE);
2088 : 5 : rc = spdk_nvmf_subsystem_stop(subsystem, NULL, NULL);
2089 : 5 : CU_ASSERT(rc == 0);
2090 : 5 : poll_threads();
2091 : 5 : CU_ASSERT(subsystem->state == SPDK_NVMF_SUBSYSTEM_INACTIVE);
2092 : :
2093 : 5 : rc = spdk_nvmf_subsystem_destroy(subsystem, NULL, NULL);
2094 : 5 : CU_ASSERT(rc == 0);
2095 : 5 : rc = spdk_nvmf_subsystem_destroy(discovery_subsystem, NULL, NULL);
2096 : 5 : CU_ASSERT(rc == 0);
2097 : :
2098 : 5 : spdk_io_device_unregister(&tgt, NULL);
2099 : 5 : poll_threads();
2100 : :
2101 : 5 : spdk_bit_array_free(&tgt.subsystem_ids);
2102 : 5 : }
2103 : :
2104 : : static bool
2105 : 20 : ut_is_ptpl_capable(const struct spdk_nvmf_ns *ns)
2106 : : {
2107 : 20 : return true;
2108 : : }
2109 : :
2110 : : static struct spdk_nvmf_reservation_info g_resv_info;
2111 : :
2112 : : static int
2113 : 10 : ut_update_reservation(const struct spdk_nvmf_ns *ns, const struct spdk_nvmf_reservation_info *info)
2114 : : {
2115 : 10 : g_resv_info = *info;
2116 : :
2117 : 10 : return 0;
2118 : : }
2119 : :
2120 : : static int
2121 : 5 : ut_load_reservation(const struct spdk_nvmf_ns *ns, struct spdk_nvmf_reservation_info *info)
2122 : : {
2123 : 5 : *info = g_resv_info;
2124 : :
2125 : 5 : return 0;
2126 : : }
2127 : :
2128 : : static void
2129 : 5 : test_nvmf_reservation_custom_ops(void)
2130 : : {
2131 : 5 : struct spdk_nvmf_ns_reservation_ops ops = {
2132 : : .is_ptpl_capable = ut_is_ptpl_capable,
2133 : : .update = ut_update_reservation,
2134 : : .load = ut_load_reservation,
2135 : : };
2136 : : struct spdk_nvmf_request *req;
2137 : : struct spdk_nvme_cpl *rsp;
2138 : : struct spdk_nvmf_registrant *reg;
2139 : 5 : bool update_sgroup = false;
2140 : 5 : struct spdk_nvmf_tgt tgt = {};
2141 : 5 : struct spdk_nvmf_subsystem subsystem = {
2142 : : .max_nsid = 4,
2143 : : .tgt = &tgt,
2144 : : };
2145 : : uint32_t nsid;
2146 : : struct spdk_nvmf_ns *ns;
2147 : : int rc;
2148 : :
2149 : 5 : subsystem.ns = calloc(subsystem.max_nsid, sizeof(struct spdk_nvmf_subsystem_ns *));
2150 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(subsystem.ns != NULL);
2151 : 5 : subsystem.ana_group = calloc(subsystem.max_nsid, sizeof(uint32_t));
2152 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(subsystem.ana_group != NULL);
2153 : :
2154 : 5 : spdk_nvmf_set_custom_ns_reservation_ops(&ops);
2155 : :
2156 : 5 : ut_reservation_init();
2157 : :
2158 : 5 : req = ut_reservation_build_req(16);
2159 : 5 : rsp = &req->rsp->nvme_cpl;
2160 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(req != NULL);
2161 : :
2162 : : /* Add a registrant and activate ptpl */
2163 : 5 : ut_reservation_build_register_request(req, SPDK_NVME_RESERVE_REGISTER_KEY, 0,
2164 : : SPDK_NVME_RESERVE_PTPL_PERSIST_POWER_LOSS, 0, 0xa1);
2165 : 5 : update_sgroup = nvmf_ns_reservation_register(&g_ns, &g_ctrlr1_A, req);
2166 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(update_sgroup == true);
2167 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_SUCCESS);
2168 [ - + - + ]: 5 : SPDK_CU_ASSERT_FATAL(g_ns.ptpl_activated == true);
2169 : 5 : rc = nvmf_ns_update_reservation_info(&g_ns);
2170 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rc == 0);
2171 : :
2172 : : /* Acquire a reservation */
2173 : 5 : rsp->status.sc = SPDK_NVME_SC_INVALID_FIELD;
2174 : 5 : ut_reservation_build_acquire_request(req, SPDK_NVME_RESERVE_ACQUIRE, 0,
2175 : : SPDK_NVME_RESERVE_WRITE_EXCLUSIVE_REG_ONLY, 0xa1, 0x0);
2176 : 5 : update_sgroup = nvmf_ns_reservation_acquire(&g_ns, &g_ctrlr1_A, req);
2177 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(update_sgroup == true);
2178 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rsp->status.sc == SPDK_NVME_SC_SUCCESS);
2179 : 5 : rc = nvmf_ns_update_reservation_info(&g_ns);
2180 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(rc == 0);
2181 : :
2182 : : /* Add the namespace using a different subsystem.
2183 : : * Reservation information should be restored. */
2184 : 5 : nsid = spdk_nvmf_subsystem_add_ns_ext(&subsystem, g_ns.bdev->name, NULL, 0, NULL);
2185 : 5 : CU_ASSERT(nsid == 1);
2186 : :
2187 : 5 : ns = _nvmf_subsystem_get_ns(&subsystem, nsid);
2188 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(ns != NULL);
2189 : 5 : CU_ASSERT(ns->crkey == 0xa1);
2190 : 5 : CU_ASSERT(ns->rtype == SPDK_NVME_RESERVE_WRITE_EXCLUSIVE_REG_ONLY);
2191 [ - + ]: 5 : CU_ASSERT(ns->ptpl_activated == true);
2192 : :
2193 : 5 : reg = nvmf_ns_reservation_get_registrant(ns, &g_ctrlr1_A.hostid);
2194 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(reg != NULL);
2195 [ - + ]: 5 : SPDK_CU_ASSERT_FATAL(!spdk_uuid_compare(&g_ctrlr1_A.hostid, ®->hostid));
2196 : 5 : CU_ASSERT(reg == ns->holder);
2197 : :
2198 : 5 : rc = spdk_nvmf_subsystem_remove_ns(&subsystem, nsid);
2199 : 5 : CU_ASSERT(rc == 0);
2200 : :
2201 : 5 : free(subsystem.ns);
2202 : 5 : free(subsystem.ana_group);
2203 : 5 : ut_reservation_free_req(req);
2204 : 5 : ut_reservation_deinit();
2205 : 5 : }
2206 : :
2207 : : int
2208 : 5 : main(int argc, char **argv)
2209 : : {
2210 : 5 : CU_pSuite suite = NULL;
2211 : : unsigned int num_failures;
2212 : :
2213 : 5 : CU_initialize_registry();
2214 : :
2215 : 5 : suite = CU_add_suite("nvmf", NULL, NULL);
2216 : :
2217 : 5 : CU_ADD_TEST(suite, nvmf_test_create_subsystem);
2218 : 5 : CU_ADD_TEST(suite, test_spdk_nvmf_subsystem_add_ns);
2219 : 5 : CU_ADD_TEST(suite, test_spdk_nvmf_subsystem_add_fdp_ns);
2220 : 5 : CU_ADD_TEST(suite, test_spdk_nvmf_subsystem_set_sn);
2221 : 5 : CU_ADD_TEST(suite, test_spdk_nvmf_ns_visible);
2222 : 5 : CU_ADD_TEST(suite, test_reservation_register);
2223 : 5 : CU_ADD_TEST(suite, test_reservation_register_with_ptpl);
2224 : 5 : CU_ADD_TEST(suite, test_reservation_acquire_preempt_1);
2225 : 5 : CU_ADD_TEST(suite, test_reservation_acquire_release_with_ptpl);
2226 : 5 : CU_ADD_TEST(suite, test_reservation_release);
2227 : 5 : CU_ADD_TEST(suite, test_reservation_unregister_notification);
2228 : 5 : CU_ADD_TEST(suite, test_reservation_release_notification);
2229 : 5 : CU_ADD_TEST(suite, test_reservation_release_notification_write_exclusive);
2230 : 5 : CU_ADD_TEST(suite, test_reservation_clear_notification);
2231 : 5 : CU_ADD_TEST(suite, test_reservation_preempt_notification);
2232 : 5 : CU_ADD_TEST(suite, test_spdk_nvmf_ns_event);
2233 : 5 : CU_ADD_TEST(suite, test_nvmf_ns_reservation_add_remove_registrant);
2234 : 5 : CU_ADD_TEST(suite, test_nvmf_subsystem_add_ctrlr);
2235 : 5 : CU_ADD_TEST(suite, test_spdk_nvmf_subsystem_add_host);
2236 : 5 : CU_ADD_TEST(suite, test_nvmf_ns_reservation_report);
2237 : 5 : CU_ADD_TEST(suite, test_nvmf_nqn_is_valid);
2238 : 5 : CU_ADD_TEST(suite, test_nvmf_ns_reservation_restore);
2239 : 5 : CU_ADD_TEST(suite, test_nvmf_subsystem_state_change);
2240 : 5 : CU_ADD_TEST(suite, test_nvmf_reservation_custom_ops);
2241 : :
2242 : 5 : allocate_threads(1);
2243 : 5 : set_thread(0);
2244 : :
2245 : 5 : num_failures = spdk_ut_run_tests(argc, argv, NULL);
2246 : 5 : CU_cleanup_registry();
2247 : :
2248 : 5 : free_threads();
2249 : :
2250 : 5 : return num_failures;
2251 : : }
|