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