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