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 * Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 5 */ 6 7 #ifndef __NVMF_INTERNAL_H__ 8 #define __NVMF_INTERNAL_H__ 9 10 #include "spdk/stdinc.h" 11 12 #include "spdk/keyring.h" 13 #include "spdk/likely.h" 14 #include "spdk/nvmf.h" 15 #include "spdk/nvmf_cmd.h" 16 #include "spdk/nvmf_transport.h" 17 #include "spdk/nvmf_spec.h" 18 #include "spdk/assert.h" 19 #include "spdk/bdev.h" 20 #include "spdk/queue.h" 21 #include "spdk/util.h" 22 #include "spdk/thread.h" 23 #include "spdk/tree.h" 24 #include "spdk/bit_array.h" 25 26 /* The spec reserves cntlid values in the range FFF0h to FFFFh. */ 27 #define NVMF_MIN_CNTLID 1 28 #define NVMF_MAX_CNTLID 0xFFEF 29 30 enum spdk_nvmf_tgt_state { 31 NVMF_TGT_IDLE = 0, 32 NVMF_TGT_RUNNING, 33 NVMF_TGT_PAUSING, 34 NVMF_TGT_PAUSED, 35 NVMF_TGT_RESUMING, 36 }; 37 38 enum spdk_nvmf_subsystem_state { 39 SPDK_NVMF_SUBSYSTEM_INACTIVE = 0, 40 SPDK_NVMF_SUBSYSTEM_ACTIVATING, 41 SPDK_NVMF_SUBSYSTEM_ACTIVE, 42 SPDK_NVMF_SUBSYSTEM_PAUSING, 43 SPDK_NVMF_SUBSYSTEM_PAUSED, 44 SPDK_NVMF_SUBSYSTEM_RESUMING, 45 SPDK_NVMF_SUBSYSTEM_DEACTIVATING, 46 SPDK_NVMF_SUBSYSTEM_NUM_STATES, 47 }; 48 49 RB_HEAD(subsystem_tree, spdk_nvmf_subsystem); 50 51 struct spdk_nvmf_tgt { 52 char name[NVMF_TGT_NAME_MAX_LENGTH]; 53 54 pthread_mutex_t mutex; 55 56 uint64_t discovery_genctr; 57 58 uint32_t max_subsystems; 59 60 enum spdk_nvmf_tgt_discovery_filter discovery_filter; 61 62 enum spdk_nvmf_tgt_state state; 63 64 struct spdk_bit_array *subsystem_ids; 65 66 struct subsystem_tree subsystems; 67 68 TAILQ_HEAD(, spdk_nvmf_transport) transports; 69 TAILQ_HEAD(, spdk_nvmf_poll_group) poll_groups; 70 TAILQ_HEAD(, spdk_nvmf_referral) referrals; 71 72 /* Used for round-robin assignment of connections to poll groups */ 73 struct spdk_nvmf_poll_group *next_poll_group; 74 75 spdk_nvmf_tgt_destroy_done_fn *destroy_cb_fn; 76 void *destroy_cb_arg; 77 78 uint16_t crdt[3]; 79 uint16_t num_poll_groups; 80 81 TAILQ_ENTRY(spdk_nvmf_tgt) link; 82 }; 83 84 struct spdk_nvmf_host { 85 char nqn[SPDK_NVMF_NQN_MAX_LEN + 1]; 86 struct spdk_key *dhchap_key; 87 struct spdk_key *dhchap_ctrlr_key; 88 TAILQ_ENTRY(spdk_nvmf_host) link; 89 }; 90 91 struct spdk_nvmf_subsystem_listener { 92 struct spdk_nvmf_subsystem *subsystem; 93 spdk_nvmf_tgt_subsystem_listen_done_fn cb_fn; 94 void *cb_arg; 95 struct spdk_nvme_transport_id *trid; 96 struct spdk_nvmf_transport *transport; 97 enum spdk_nvme_ana_state *ana_state; 98 uint64_t ana_state_change_count; 99 uint16_t id; 100 struct spdk_nvmf_listener_opts opts; 101 TAILQ_ENTRY(spdk_nvmf_subsystem_listener) link; 102 }; 103 104 struct spdk_nvmf_referral { 105 /* Discovery Log Page Entry for this referral */ 106 struct spdk_nvmf_discovery_log_page_entry entry; 107 /* Transport ID */ 108 struct spdk_nvme_transport_id trid; 109 TAILQ_ENTRY(spdk_nvmf_referral) link; 110 }; 111 112 struct spdk_nvmf_subsystem_pg_ns_info { 113 struct spdk_io_channel *channel; 114 struct spdk_uuid uuid; 115 /* current reservation key, no reservation if the value is 0 */ 116 uint64_t crkey; 117 /* reservation type */ 118 enum spdk_nvme_reservation_type rtype; 119 /* Host ID which holds the reservation */ 120 struct spdk_uuid holder_id; 121 /* Host ID for the registrants with the namespace */ 122 struct spdk_uuid reg_hostid[SPDK_NVMF_MAX_NUM_REGISTRANTS]; 123 uint64_t num_blocks; 124 125 /* I/O outstanding to this namespace */ 126 uint64_t io_outstanding; 127 enum spdk_nvmf_subsystem_state state; 128 }; 129 130 typedef void(*spdk_nvmf_poll_group_mod_done)(void *cb_arg, int status); 131 132 struct spdk_nvmf_subsystem_poll_group { 133 /* Array of namespace information for each namespace indexed by nsid - 1 */ 134 struct spdk_nvmf_subsystem_pg_ns_info *ns_info; 135 uint32_t num_ns; 136 enum spdk_nvmf_subsystem_state state; 137 138 /* Number of ADMIN and FABRICS requests outstanding */ 139 uint64_t mgmt_io_outstanding; 140 spdk_nvmf_poll_group_mod_done cb_fn; 141 void *cb_arg; 142 143 TAILQ_HEAD(, spdk_nvmf_request) queued; 144 }; 145 146 struct spdk_nvmf_registrant { 147 TAILQ_ENTRY(spdk_nvmf_registrant) link; 148 struct spdk_uuid hostid; 149 /* Registration key */ 150 uint64_t rkey; 151 }; 152 153 struct spdk_nvmf_ns { 154 uint32_t nsid; 155 uint32_t anagrpid; 156 struct spdk_nvmf_subsystem *subsystem; 157 struct spdk_bdev *bdev; 158 struct spdk_bdev_desc *desc; 159 struct spdk_nvmf_ns_opts opts; 160 /* reservation notification mask */ 161 uint32_t mask; 162 /* generation code */ 163 uint32_t gen; 164 /* registrants head */ 165 TAILQ_HEAD(, spdk_nvmf_registrant) registrants; 166 /* current reservation key */ 167 uint64_t crkey; 168 /* reservation type */ 169 enum spdk_nvme_reservation_type rtype; 170 /* current reservation holder, only valid if reservation type can only have one holder */ 171 struct spdk_nvmf_registrant *holder; 172 /* Persist Through Power Loss file which contains the persistent reservation */ 173 char *ptpl_file; 174 /* Persist Through Power Loss feature is enabled */ 175 bool ptpl_activated; 176 /* ZCOPY supported on bdev device */ 177 bool zcopy; 178 /* Command Set Identifier */ 179 enum spdk_nvme_csi csi; 180 /* Make namespace visible to controllers of these hosts */ 181 TAILQ_HEAD(, spdk_nvmf_host) hosts; 182 /* Namespace is always visible to all controllers */ 183 bool always_visible; 184 }; 185 186 /* 187 * NVMf reservation notification log page. 188 */ 189 struct spdk_nvmf_reservation_log { 190 struct spdk_nvme_reservation_notification_log log; 191 TAILQ_ENTRY(spdk_nvmf_reservation_log) link; 192 struct spdk_nvmf_ctrlr *ctrlr; 193 }; 194 195 /* 196 * NVMf async event completion. 197 */ 198 struct spdk_nvmf_async_event_completion { 199 union spdk_nvme_async_event_completion event; 200 STAILQ_ENTRY(spdk_nvmf_async_event_completion) link; 201 }; 202 203 /* 204 * This structure represents an NVMe-oF controller, 205 * which is like a "session" in networking terms. 206 */ 207 struct spdk_nvmf_ctrlr { 208 uint16_t cntlid; 209 char hostnqn[SPDK_NVMF_NQN_MAX_LEN + 1]; 210 struct spdk_nvmf_subsystem *subsys; 211 struct spdk_bit_array *visible_ns; 212 213 struct spdk_nvmf_ctrlr_data cdata; 214 215 struct spdk_nvmf_registers vcprop; 216 217 struct spdk_nvmf_ctrlr_feat feat; 218 219 struct spdk_nvmf_qpair *admin_qpair; 220 struct spdk_thread *thread; 221 struct spdk_bit_array *qpair_mask; 222 223 const struct spdk_nvmf_subsystem_listener *listener; 224 225 struct spdk_nvmf_request *aer_req[SPDK_NVMF_MAX_ASYNC_EVENTS]; 226 STAILQ_HEAD(, spdk_nvmf_async_event_completion) async_events; 227 uint64_t notice_aen_mask; 228 uint8_t nr_aer_reqs; 229 struct spdk_uuid hostid; 230 231 uint32_t association_timeout; /* in milliseconds */ 232 uint16_t changed_ns_list_count; 233 struct spdk_nvme_ns_list changed_ns_list; 234 uint64_t log_page_count; 235 uint8_t num_avail_log_pages; 236 TAILQ_HEAD(log_page_head, spdk_nvmf_reservation_log) log_head; 237 238 /* Time to trigger keep-alive--poller_time = now_tick + period */ 239 uint64_t last_keep_alive_tick; 240 struct spdk_poller *keep_alive_poller; 241 242 struct spdk_poller *association_timer; 243 244 struct spdk_poller *cc_timer; 245 uint64_t cc_timeout_tsc; 246 struct spdk_poller *cc_timeout_timer; 247 248 bool dif_insert_or_strip; 249 bool in_destruct; 250 bool disconnect_in_progress; 251 /* valid only when disconnect_in_progress is true */ 252 bool disconnect_is_shn; 253 bool acre_enabled; 254 bool dynamic_ctrlr; 255 256 TAILQ_ENTRY(spdk_nvmf_ctrlr) link; 257 }; 258 259 #define NVMF_MAX_LISTENERS_PER_SUBSYSTEM 16 260 261 struct nvmf_subsystem_state_change_ctx { 262 struct spdk_nvmf_subsystem *subsystem; 263 uint16_t nsid; 264 265 enum spdk_nvmf_subsystem_state original_state; 266 enum spdk_nvmf_subsystem_state requested_state; 267 int status; 268 struct spdk_thread *thread; 269 270 spdk_nvmf_subsystem_state_change_done cb_fn; 271 void *cb_arg; 272 TAILQ_ENTRY(nvmf_subsystem_state_change_ctx) link; 273 }; 274 275 struct spdk_nvmf_subsystem { 276 struct spdk_thread *thread; 277 278 uint32_t id; 279 280 enum spdk_nvmf_subsystem_state state; 281 enum spdk_nvmf_subtype subtype; 282 283 uint16_t next_cntlid; 284 struct { 285 uint8_t allow_any_listener : 1; 286 uint8_t ana_reporting : 1; 287 uint8_t reserved : 6; 288 } flags; 289 290 /* Protected against concurrent access by ->mutex */ 291 bool allow_any_host; 292 293 bool destroying; 294 bool async_destroy; 295 296 /* FDP related fields */ 297 bool fdp_supported; 298 299 /* Zoned storage related fields */ 300 bool zone_append_supported; 301 uint64_t max_zone_append_size_kib; 302 303 struct spdk_nvmf_tgt *tgt; 304 RB_ENTRY(spdk_nvmf_subsystem) link; 305 306 /* Array of pointers to namespaces of size max_nsid indexed by nsid - 1 */ 307 struct spdk_nvmf_ns **ns; 308 uint32_t max_nsid; 309 310 uint16_t min_cntlid; 311 uint16_t max_cntlid; 312 313 uint64_t max_discard_size_kib; 314 uint64_t max_write_zeroes_size_kib; 315 316 TAILQ_HEAD(, spdk_nvmf_ctrlr) ctrlrs; 317 318 /* This mutex is used to protect fields that aren't touched on the I/O path (e.g. it's 319 * needed for handling things like the CONNECT command) instead of requiring the subsystem 320 * to be paused. It makes it possible to modify those fields (e.g. add/remove hosts) 321 * without affecting outstanding I/O requests. 322 */ 323 pthread_mutex_t mutex; 324 /* Protected against concurrent access by ->mutex */ 325 TAILQ_HEAD(, spdk_nvmf_host) hosts; 326 TAILQ_HEAD(, spdk_nvmf_subsystem_listener) listeners; 327 struct spdk_bit_array *used_listener_ids; 328 329 TAILQ_ENTRY(spdk_nvmf_subsystem) entries; 330 331 nvmf_subsystem_destroy_cb async_destroy_cb; 332 void *async_destroy_cb_arg; 333 334 char sn[SPDK_NVME_CTRLR_SN_LEN + 1]; 335 char mn[SPDK_NVME_CTRLR_MN_LEN + 1]; 336 char subnqn[SPDK_NVMF_NQN_MAX_LEN + 1]; 337 338 /* Array of namespace count per ANA group of size max_nsid indexed anagrpid - 1 339 * It will be enough for ANA group to use the same size as namespaces. 340 */ 341 uint32_t *ana_group; 342 /* Queue of a state change requests */ 343 TAILQ_HEAD(, nvmf_subsystem_state_change_ctx) state_changes; 344 /* In-band authentication sequence number, protected by ->mutex */ 345 uint32_t auth_seqnum; 346 }; 347 348 static int 349 subsystem_cmp(struct spdk_nvmf_subsystem *subsystem1, struct spdk_nvmf_subsystem *subsystem2) 350 { 351 return strncmp(subsystem1->subnqn, subsystem2->subnqn, sizeof(subsystem1->subnqn)); 352 } 353 354 RB_GENERATE_STATIC(subsystem_tree, spdk_nvmf_subsystem, link, subsystem_cmp); 355 356 int nvmf_poll_group_update_subsystem(struct spdk_nvmf_poll_group *group, 357 struct spdk_nvmf_subsystem *subsystem); 358 int nvmf_poll_group_add_subsystem(struct spdk_nvmf_poll_group *group, 359 struct spdk_nvmf_subsystem *subsystem, 360 spdk_nvmf_poll_group_mod_done cb_fn, void *cb_arg); 361 void nvmf_poll_group_remove_subsystem(struct spdk_nvmf_poll_group *group, 362 struct spdk_nvmf_subsystem *subsystem, spdk_nvmf_poll_group_mod_done cb_fn, void *cb_arg); 363 void nvmf_poll_group_pause_subsystem(struct spdk_nvmf_poll_group *group, 364 struct spdk_nvmf_subsystem *subsystem, 365 uint32_t nsid, 366 spdk_nvmf_poll_group_mod_done cb_fn, void *cb_arg); 367 void nvmf_poll_group_resume_subsystem(struct spdk_nvmf_poll_group *group, 368 struct spdk_nvmf_subsystem *subsystem, spdk_nvmf_poll_group_mod_done cb_fn, void *cb_arg); 369 370 void nvmf_update_discovery_log(struct spdk_nvmf_tgt *tgt, const char *hostnqn); 371 void nvmf_get_discovery_log_page(struct spdk_nvmf_tgt *tgt, const char *hostnqn, struct iovec *iov, 372 uint32_t iovcnt, uint64_t offset, uint32_t length, 373 struct spdk_nvme_transport_id *cmd_source_trid); 374 375 void nvmf_ctrlr_destruct(struct spdk_nvmf_ctrlr *ctrlr); 376 int nvmf_ctrlr_process_admin_cmd(struct spdk_nvmf_request *req); 377 int nvmf_ctrlr_process_io_cmd(struct spdk_nvmf_request *req); 378 bool nvmf_ctrlr_dsm_supported(struct spdk_nvmf_ctrlr *ctrlr); 379 bool nvmf_ctrlr_write_zeroes_supported(struct spdk_nvmf_ctrlr *ctrlr); 380 bool nvmf_ctrlr_copy_supported(struct spdk_nvmf_ctrlr *ctrlr); 381 void nvmf_ctrlr_ns_changed(struct spdk_nvmf_ctrlr *ctrlr, uint32_t nsid); 382 bool nvmf_ctrlr_use_zcopy(struct spdk_nvmf_request *req); 383 384 void nvmf_bdev_ctrlr_identify_ns(struct spdk_nvmf_ns *ns, struct spdk_nvme_ns_data *nsdata, 385 bool dif_insert_or_strip); 386 int nvmf_bdev_ctrlr_read_cmd(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, 387 struct spdk_io_channel *ch, struct spdk_nvmf_request *req); 388 int nvmf_bdev_ctrlr_write_cmd(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, 389 struct spdk_io_channel *ch, struct spdk_nvmf_request *req); 390 int nvmf_bdev_ctrlr_compare_cmd(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, 391 struct spdk_io_channel *ch, struct spdk_nvmf_request *req); 392 int nvmf_bdev_ctrlr_compare_and_write_cmd(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, 393 struct spdk_io_channel *ch, struct spdk_nvmf_request *cmp_req, struct spdk_nvmf_request *write_req); 394 int nvmf_bdev_ctrlr_write_zeroes_cmd(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, 395 struct spdk_io_channel *ch, struct spdk_nvmf_request *req); 396 int nvmf_bdev_ctrlr_flush_cmd(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, 397 struct spdk_io_channel *ch, struct spdk_nvmf_request *req); 398 int nvmf_bdev_ctrlr_dsm_cmd(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, 399 struct spdk_io_channel *ch, struct spdk_nvmf_request *req); 400 int nvmf_bdev_ctrlr_copy_cmd(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, 401 struct spdk_io_channel *ch, struct spdk_nvmf_request *req); 402 int nvmf_bdev_ctrlr_nvme_passthru_io(struct spdk_bdev *bdev, struct spdk_bdev_desc *desc, 403 struct spdk_io_channel *ch, struct spdk_nvmf_request *req); 404 bool nvmf_bdev_ctrlr_get_dif_ctx(struct spdk_bdev *bdev, struct spdk_nvme_cmd *cmd, 405 struct spdk_dif_ctx *dif_ctx); 406 bool nvmf_bdev_zcopy_enabled(struct spdk_bdev *bdev); 407 408 int nvmf_subsystem_add_ctrlr(struct spdk_nvmf_subsystem *subsystem, 409 struct spdk_nvmf_ctrlr *ctrlr); 410 void nvmf_subsystem_remove_ctrlr(struct spdk_nvmf_subsystem *subsystem, 411 struct spdk_nvmf_ctrlr *ctrlr); 412 void nvmf_subsystem_remove_all_listeners(struct spdk_nvmf_subsystem *subsystem, 413 bool stop); 414 struct spdk_nvmf_ctrlr *nvmf_subsystem_get_ctrlr(struct spdk_nvmf_subsystem *subsystem, 415 uint16_t cntlid); 416 bool nvmf_subsystem_host_auth_required(struct spdk_nvmf_subsystem *subsystem, const char *hostnqn); 417 enum nvmf_auth_key_type { 418 NVMF_AUTH_KEY_HOST, 419 NVMF_AUTH_KEY_CTRLR, 420 }; 421 struct spdk_key *nvmf_subsystem_get_dhchap_key(struct spdk_nvmf_subsystem *subsys, const char *nqn, 422 enum nvmf_auth_key_type type); 423 struct spdk_nvmf_subsystem_listener *nvmf_subsystem_find_listener( 424 struct spdk_nvmf_subsystem *subsystem, 425 const struct spdk_nvme_transport_id *trid); 426 struct spdk_nvmf_listener *nvmf_transport_find_listener( 427 struct spdk_nvmf_transport *transport, 428 const struct spdk_nvme_transport_id *trid); 429 void nvmf_transport_dump_opts(struct spdk_nvmf_transport *transport, struct spdk_json_write_ctx *w, 430 bool named); 431 void nvmf_transport_listen_dump_trid(const struct spdk_nvme_transport_id *trid, 432 struct spdk_json_write_ctx *w); 433 434 /** 435 * Sets the controller ID range for a subsystem. 436 * Valid range is [1, 0xFFEF]. 437 * 438 * May only be performed on subsystems in the INACTIVE state. 439 * 440 * \param subsystem Subsystem to modify. 441 * \param min_cntlid Minimum controller ID. 442 * \param max_cntlid Maximum controller ID. 443 * 444 * \return 0 on success, or negated errno value on failure. 445 */ 446 int nvmf_subsystem_set_cntlid_range(struct spdk_nvmf_subsystem *subsystem, 447 uint16_t min_cntlid, uint16_t max_cntlid); 448 449 int nvmf_ctrlr_async_event_ns_notice(struct spdk_nvmf_ctrlr *ctrlr); 450 int nvmf_ctrlr_async_event_ana_change_notice(struct spdk_nvmf_ctrlr *ctrlr); 451 void nvmf_ctrlr_async_event_discovery_log_change_notice(void *ctx); 452 void nvmf_ctrlr_async_event_reservation_notification(struct spdk_nvmf_ctrlr *ctrlr); 453 454 void nvmf_ns_reservation_request(void *ctx); 455 void nvmf_ctrlr_reservation_notice_log(struct spdk_nvmf_ctrlr *ctrlr, 456 struct spdk_nvmf_ns *ns, 457 enum spdk_nvme_reservation_notification_log_page_type type); 458 459 bool nvmf_ns_is_ptpl_capable(const struct spdk_nvmf_ns *ns); 460 461 static inline struct spdk_nvmf_host * 462 nvmf_ns_find_host(struct spdk_nvmf_ns *ns, const char *hostnqn) 463 { 464 struct spdk_nvmf_host *host = NULL; 465 466 TAILQ_FOREACH(host, &ns->hosts, link) { 467 if (strcmp(hostnqn, host->nqn) == 0) { 468 return host; 469 } 470 } 471 472 return NULL; 473 } 474 475 /* 476 * Abort zero-copy requests that already got the buffer (received zcopy_start cb), but haven't 477 * started zcopy_end. These requests are kept on the outstanding queue, but are not waiting for a 478 * completion from the bdev layer, so, when a qpair is being disconnected, we need to kick them to 479 * force their completion. 480 */ 481 void nvmf_qpair_abort_pending_zcopy_reqs(struct spdk_nvmf_qpair *qpair); 482 483 /* 484 * Free aer simply frees the rdma resources for the aer without informing the host. 485 * This function should be called when deleting a qpair when one wants to make sure 486 * the qpair is completely empty before freeing the request. The reason we free the 487 * AER without sending a completion is to prevent the host from sending another AER. 488 */ 489 void nvmf_qpair_free_aer(struct spdk_nvmf_qpair *qpair); 490 491 int nvmf_ctrlr_abort_request(struct spdk_nvmf_request *req); 492 493 void nvmf_ctrlr_set_fatal_status(struct spdk_nvmf_ctrlr *ctrlr); 494 495 static inline bool 496 nvmf_ctrlr_ns_is_visible(struct spdk_nvmf_ctrlr *ctrlr, uint32_t nsid) 497 { 498 return spdk_bit_array_get(ctrlr->visible_ns, nsid - 1); 499 } 500 501 static inline struct spdk_nvmf_ns * 502 _nvmf_subsystem_get_ns(struct spdk_nvmf_subsystem *subsystem, uint32_t nsid) 503 { 504 /* NOTE: This implicitly also checks for 0, since 0 - 1 wraps around to UINT32_MAX. */ 505 if (spdk_unlikely(nsid - 1 >= subsystem->max_nsid)) { 506 return NULL; 507 } 508 509 return subsystem->ns[nsid - 1]; 510 } 511 512 static inline struct spdk_nvmf_ns * 513 nvmf_ctrlr_get_ns(struct spdk_nvmf_ctrlr *ctrlr, uint32_t nsid) 514 { 515 struct spdk_nvmf_subsystem *subsystem = ctrlr->subsys; 516 struct spdk_nvmf_ns *ns = _nvmf_subsystem_get_ns(subsystem, nsid); 517 518 return ns && nvmf_ctrlr_ns_is_visible(ctrlr, nsid) ? ns : NULL; 519 } 520 521 static inline bool 522 nvmf_qpair_is_admin_queue(struct spdk_nvmf_qpair *qpair) 523 { 524 return qpair->qid == 0; 525 } 526 527 void nvmf_qpair_set_state(struct spdk_nvmf_qpair *qpair, enum spdk_nvmf_qpair_state state); 528 529 int nvmf_qpair_auth_init(struct spdk_nvmf_qpair *qpair); 530 void nvmf_qpair_auth_destroy(struct spdk_nvmf_qpair *qpair); 531 void nvmf_qpair_auth_dump(struct spdk_nvmf_qpair *qpair, struct spdk_json_write_ctx *w); 532 533 int nvmf_auth_request_exec(struct spdk_nvmf_request *req); 534 bool nvmf_auth_is_supported(void); 535 536 static inline bool 537 nvmf_request_is_fabric_connect(struct spdk_nvmf_request *req) 538 { 539 return req->cmd->nvmf_cmd.opcode == SPDK_NVME_OPC_FABRIC && 540 req->cmd->nvmf_cmd.fctype == SPDK_NVMF_FABRIC_COMMAND_CONNECT; 541 } 542 543 /* 544 * Tests whether a given string represents a valid NQN. 545 */ 546 bool nvmf_nqn_is_valid(const char *nqn); 547 548 /* 549 * Tests whether a given NQN describes a discovery subsystem. 550 */ 551 bool nvmf_nqn_is_discovery(const char *nqn); 552 553 /** 554 * Initiates a zcopy start operation 555 * 556 * \param bdev The \ref spdk_bdev 557 * \param desc The \ref spdk_bdev_desc 558 * \param ch The \ref spdk_io_channel 559 * \param req The \ref spdk_nvmf_request passed to the bdev for processing 560 * 561 * \return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE if the command was completed immediately or 562 * SPDK_NVMF_REQUEST_EXEC_STATUS_ASYNCHRONOUS if the command was submitted and will be 563 * completed asynchronously. Asynchronous completions are notified through 564 * spdk_nvmf_request_complete(). 565 */ 566 int nvmf_bdev_ctrlr_zcopy_start(struct spdk_bdev *bdev, 567 struct spdk_bdev_desc *desc, 568 struct spdk_io_channel *ch, 569 struct spdk_nvmf_request *req); 570 571 /** 572 * Ends a zcopy operation 573 * 574 * \param req The NVMe-oF request 575 * \param commit Flag indicating whether the buffers should be committed 576 */ 577 void nvmf_bdev_ctrlr_zcopy_end(struct spdk_nvmf_request *req, bool commit); 578 579 /** 580 * Publishes the mDNS PRR (Pull Registration Request) for the NVMe-oF target. 581 * 582 * \param tgt The NVMe-oF target 583 * 584 * \return 0 on success, negative errno on failure 585 */ 586 int nvmf_publish_mdns_prr(struct spdk_nvmf_tgt *tgt); 587 588 /** 589 * Stops the mDNS PRR (Pull Registration Request) for the NVMe-oF target. 590 * 591 * \param tgt The NVMe-oF target 592 */ 593 void nvmf_tgt_stop_mdns_prr(struct spdk_nvmf_tgt *tgt); 594 595 #endif /* __NVMF_INTERNAL_H__ */ 596