|
23 | 23 | /* default to 600 seconds of reconnect attempts before giving up */ |
24 | 24 | #define NVMF_DEF_CTRL_LOSS_TMO 600 |
25 | 25 |
|
26 | | -struct nvmf_context; |
27 | | - |
28 | | -int nvmf_context_create(struct nvme_global_ctx *ctx, |
29 | | - bool (*decide_retry)(struct nvmf_context *fctx, int err, |
30 | | - void *user_data), |
31 | | - void (*connected)(struct nvmf_context *fctx, |
32 | | - struct nvme_ctrl *c, void *user_data), |
33 | | - void (*already_connected)(struct nvmf_context *fctx, |
34 | | - struct nvme_host *host, const char *subsysnqn, |
35 | | - const char *transport, const char *traddr, |
36 | | - const char *trsvcid, void *user_data), |
37 | | - void *user_data, struct nvmf_context **fctxp); |
38 | | -int nvmf_context_set_discovery_cbs(struct nvmf_context *fctx, |
39 | | - void (*discovery_log)(struct nvmf_context *fctx, |
40 | | - bool connect, |
41 | | - struct nvmf_discovery_log *log, |
42 | | - uint64_t numrec, void *user_data), |
43 | | - int (*parser_init)(struct nvmf_context *fctx, |
44 | | - void *user_data), |
45 | | - void (*parser_cleanup)(struct nvmf_context *fctx, |
46 | | - void *user_data), |
47 | | - int (*parser_next_line)(struct nvmf_context *fctx, |
48 | | - void *user_data)); |
49 | | -int nvmf_context_set_discovery_defaults(struct nvmf_context *fctx, |
50 | | - int max_discovery_retries, int keep_alive_timeout); |
51 | | -int nvmf_context_set_fabrics_config(struct nvmf_context *fctx, |
52 | | - struct nvme_fabrics_config *cfg); |
53 | | -int nvmf_context_set_connection(struct nvmf_context *fctx, |
54 | | - const char *subsysnqn, const char *transport, |
55 | | - const char *traddr, const char *trsvcid, |
56 | | - const char *host_traddr, const char *host_iface); |
57 | | -int nvmf_context_set_hostnqn(struct nvmf_context *fctx, |
58 | | - const char *hostnqn, const char *hostid); |
59 | | -int nvmf_context_set_crypto(struct nvmf_context *fctx, |
60 | | - const char *hostkey, const char *ctrlkey, |
61 | | - const char *keyring, const char *tls_key, |
62 | | - const char *tls_key_identity); |
63 | | -int nvmf_context_set_persistent(struct nvmf_context *fctx, bool persistent); |
64 | | -int nvmf_context_set_device(struct nvmf_context *fctx, const char *device); |
65 | | - |
66 | 26 | /** |
67 | 27 | * struct nvme_fabrics_config - Defines all linux nvme fabrics initiator options |
68 | 28 | * @queue_size: Number of IO queue entries |
@@ -427,27 +387,278 @@ int nvme_parse_uri(const char *str, struct nvme_fabrics_uri **uri); |
427 | 387 | */ |
428 | 388 | void nvme_free_uri(struct nvme_fabrics_uri *uri); |
429 | 389 |
|
430 | | -char *nvmf_get_default_trsvcid(const char *transport, bool discovery_ctrl); |
| 390 | +/** |
| 391 | + * nvmf_get_default_trsvcid() - Get default transport service ID |
| 392 | + * @transport: Transport type string (e.g., "tcp", "rdma") |
| 393 | + * @discovery_ctrl: True if for discovery controller, false otherwise |
| 394 | + * |
| 395 | + * Returns the default trsvcid (port) for the given transport and controller |
| 396 | + * type. |
| 397 | + * |
| 398 | + * Return: Allocated string with default trsvcid, or NULL on failure. |
| 399 | + */ |
| 400 | +const char *nvmf_get_default_trsvcid(const char *transport, |
| 401 | + bool discovery_ctrl); |
| 402 | +/* |
| 403 | + * struct nvmf_context - Opaque context for fabrics operations |
| 404 | + * |
| 405 | + * Used to manage state and configuration for fabrics discovery and connect |
| 406 | + * operations. |
| 407 | + */ |
| 408 | +struct nvmf_context; |
| 409 | + |
| 410 | +/** |
| 411 | + * nvmf_context_create() - Create a new fabrics context for discovery/connect |
| 412 | + * @ctx: Global context |
| 413 | + * @decide_retry: Callback to decide if a retry should be attempted |
| 414 | + * @connected: Callback invoked when a connection is established |
| 415 | + * @already_connected: Callback invoked if already connected |
| 416 | + * @user_data: User data passed to callbacks |
| 417 | + * @fctxp: Pointer to store the created context |
| 418 | + * |
| 419 | + * Allocates and initializes a new fabrics context for discovery/connect |
| 420 | + * operations. |
| 421 | + * |
| 422 | + * Return: 0 on success, or a negative error code on failure. |
| 423 | + */ |
| 424 | +int nvmf_context_create(struct nvme_global_ctx *ctx, |
| 425 | + bool (*decide_retry)(struct nvmf_context *fctx, int err, |
| 426 | + void *user_data), |
| 427 | + void (*connected)(struct nvmf_context *fctx, |
| 428 | + struct nvme_ctrl *c, void *user_data), |
| 429 | + void (*already_connected)(struct nvmf_context *fctx, |
| 430 | + struct nvme_host *host, const char *subsysnqn, |
| 431 | + const char *transport, const char *traddr, |
| 432 | + const char *trsvcid, void *user_data), |
| 433 | + void *user_data, struct nvmf_context **fctxp); |
| 434 | + |
| 435 | +/** |
| 436 | + * nvmf_context_set_discovery_cbs() - Set discovery callbacks for context |
| 437 | + * @fctx: Fabrics context |
| 438 | + * @discovery_log: Callback for discovery log events |
| 439 | + * @parser_init: Callback to initialize parser |
| 440 | + * @parser_cleanup: Callback to cleanup parser |
| 441 | + * @parser_next_line: Callback to parse next line |
| 442 | + * |
| 443 | + * Sets the callbacks used during discovery operations for the given context. |
| 444 | + * |
| 445 | + * Return: 0 on success, or a negative error code on failure. |
| 446 | + */ |
| 447 | +int nvmf_context_set_discovery_cbs(struct nvmf_context *fctx, |
| 448 | + void (*discovery_log)(struct nvmf_context *fctx, |
| 449 | + bool connect, struct nvmf_discovery_log *log, |
| 450 | + uint64_t numrec, void *user_data), |
| 451 | + int (*parser_init)(struct nvmf_context *fctx, |
| 452 | + void *user_data), |
| 453 | + void (*parser_cleanup)(struct nvmf_context *fctx, |
| 454 | + void *user_data), |
| 455 | + int (*parser_next_line)(struct nvmf_context *fctx, |
| 456 | + void *user_data)); |
| 457 | + |
| 458 | +/** |
| 459 | + * nvmf_context_set_discovery_defaults() - Set default discovery parameters |
| 460 | + * @fctx: Fabrics context |
| 461 | + * @max_discovery_retries: Maximum number of discovery retries |
| 462 | + * @keep_alive_timeout: Keep-alive timeout in seconds |
| 463 | + * |
| 464 | + * Sets default values for discovery retries and keep-alive timeout. |
| 465 | + * |
| 466 | + * Return: 0 on success, or a negative error code on failure. |
| 467 | + */ |
| 468 | +int nvmf_context_set_discovery_defaults(struct nvmf_context *fctx, |
| 469 | + int max_discovery_retries, int keep_alive_timeout); |
431 | 470 |
|
| 471 | +/** |
| 472 | + * nvmf_context_set_fabrics_config() - Set fabrics configuration for context |
| 473 | + * @fctx: Fabrics context |
| 474 | + * @cfg: Fabrics configuration to apply |
| 475 | + * |
| 476 | + * Applies the given fabrics configuration to the context. |
| 477 | + * |
| 478 | + * Return: 0 on success, or a negative error code on failure. |
| 479 | + */ |
| 480 | +int nvmf_context_set_fabrics_config(struct nvmf_context *fctx, |
| 481 | + struct nvme_fabrics_config *cfg); |
| 482 | + |
| 483 | +/** |
| 484 | + * nvmf_context_set_connection() - Set connection parameters for context |
| 485 | + * @fctx: Fabrics context |
| 486 | + * @subsysnqn: Subsystem NQN |
| 487 | + * @transport: Transport type |
| 488 | + * @traddr: Transport address |
| 489 | + * @trsvcid: Transport service ID |
| 490 | + * @host_traddr: Host transport address |
| 491 | + * @host_iface: Host interface |
| 492 | + * |
| 493 | + * Sets the connection parameters for the context. |
| 494 | + * |
| 495 | + * Return: 0 on success, or a negative error code on failure. |
| 496 | + */ |
| 497 | +int nvmf_context_set_connection(struct nvmf_context *fctx, |
| 498 | + const char *subsysnqn, const char *transport, |
| 499 | + const char *traddr, const char *trsvcid, |
| 500 | + const char *host_traddr, const char *host_iface); |
| 501 | + |
| 502 | +/** |
| 503 | + * nvmf_context_set_hostnqn() - Set host NQN and host ID for context |
| 504 | + * @fctx: Fabrics context |
| 505 | + * @hostnqn: Host NQN |
| 506 | + * @hostid: Host identifier |
| 507 | + * |
| 508 | + * Sets the host NQN and host ID for the context. |
| 509 | + * |
| 510 | + * Return: 0 on success, or a negative error code on failure. |
| 511 | + */ |
| 512 | +int nvmf_context_set_hostnqn(struct nvmf_context *fctx, |
| 513 | + const char *hostnqn, const char *hostid); |
| 514 | + |
| 515 | +/** |
| 516 | + * nvmf_context_set_crypto() - Set cryptographic parameters for context |
| 517 | + * @fctx: Fabrics context |
| 518 | + * @hostkey: Host key |
| 519 | + * @ctrlkey: Controller key |
| 520 | + * @keyring: Keyring identifier |
| 521 | + * @tls_key: TLS key |
| 522 | + * @tls_key_identity: TLS key identity |
| 523 | + * |
| 524 | + * Sets cryptographic and TLS parameters for the context. |
| 525 | + * |
| 526 | + * Return: 0 on success, or a negative error code on failure. |
| 527 | + */ |
| 528 | +int nvmf_context_set_crypto(struct nvmf_context *fctx, |
| 529 | + const char *hostkey, const char *ctrlkey, |
| 530 | + const char *keyring, const char *tls_key, |
| 531 | + const char *tls_key_identity); |
| 532 | + |
| 533 | +/** |
| 534 | + * nvmf_context_set_persistent() - Set persistence for context |
| 535 | + * @fctx: Fabrics context |
| 536 | + * @persistent: Whether to enable persistent connections |
| 537 | + * |
| 538 | + * Sets whether the context should use persistent connections. |
| 539 | + * |
| 540 | + * Return: 0 on success, or a negative error code on failure. |
| 541 | + */ |
| 542 | + |
| 543 | +int nvmf_context_set_persistent(struct nvmf_context *fctx, bool persistent); |
| 544 | + |
| 545 | +/** |
| 546 | + * nvmf_context_set_device() - Set device for context |
| 547 | + * @fctx: Fabrics context |
| 548 | + * @device: Device path or identifier |
| 549 | + * |
| 550 | + * Sets the device to be used by the context. |
| 551 | + * |
| 552 | + * Return: 0 on success, or a negative error code on failure. |
| 553 | + */ |
| 554 | +int nvmf_context_set_device(struct nvmf_context *fctx, const char *device); |
| 555 | + |
| 556 | +/** |
| 557 | + * nvmf_discovery() - Perform fabrics discovery |
| 558 | + * @ctx: Global context |
| 559 | + * @fctx: Fabrics context |
| 560 | + * @connect: Whether to connect discovered subsystems |
| 561 | + * @force: Force discovery even if already connected |
| 562 | + * |
| 563 | + * Performs discovery for fabrics subsystems and optionally connects. |
| 564 | + * |
| 565 | + * Return: 0 on success, or a negative error code on failure. |
| 566 | + */ |
432 | 567 | int nvmf_discovery(struct nvme_global_ctx *ctx, |
433 | 568 | struct nvmf_context *fctx, bool connect, bool force); |
| 569 | + |
| 570 | +/** |
| 571 | + * nvmf_discovery_config_json() - Perform discovery using JSON config |
| 572 | + * @ctx: Global context |
| 573 | + * @fctx: Fabrics context |
| 574 | + * @connect: Whether to connect discovered subsystems |
| 575 | + * @force: Force discovery even if already connected |
| 576 | + * |
| 577 | + * Performs discovery using a JSON configuration. |
| 578 | + * |
| 579 | + * Return: 0 on success, or a negative error code on failure. |
| 580 | + */ |
434 | 581 | int nvmf_discovery_config_json(struct nvme_global_ctx *ctx, |
435 | 582 | struct nvmf_context *fctx, bool connect, bool force); |
| 583 | + |
| 584 | +/** |
| 585 | + * nvmf_discovery_config_file() - Perform discovery using config file |
| 586 | + * @ctx: Global context |
| 587 | + * @fctx: Fabrics context |
| 588 | + * @connect: Whether to connect discovered subsystems |
| 589 | + * @force: Force discovery even if already connected |
| 590 | + * |
| 591 | + * Performs discovery using a configuration file. |
| 592 | + * |
| 593 | + * Return: 0 on success, or a negative error code on failure. |
| 594 | + */ |
436 | 595 | int nvmf_discovery_config_file(struct nvme_global_ctx *ctx, |
437 | 596 | struct nvmf_context *fctx, bool connect, bool force); |
| 597 | + |
| 598 | +/** |
| 599 | + * nvmf_discovery_nbft() - Perform discovery using NBFT |
| 600 | + * @ctx: Global context |
| 601 | + * @fctx: Fabrics context |
| 602 | + * @connect: Whether to connect discovered subsystems |
| 603 | + * @nbft_path: Path to NBFT file |
| 604 | + * |
| 605 | + * Performs discovery using the specified NBFT file. |
| 606 | + * |
| 607 | + * Return: 0 on success, or a negative error code on failure. |
| 608 | + */ |
438 | 609 | int nvmf_discovery_nbft(struct nvme_global_ctx *ctx, |
439 | 610 | struct nvmf_context *fctx, bool connect, char *nbft_path); |
440 | 611 |
|
| 612 | +/** |
| 613 | + * nvmf_connect() - Connect to fabrics subsystem |
| 614 | + * @ctx: Global context |
| 615 | + * @fctx: Fabrics context |
| 616 | + * |
| 617 | + * Connects to the fabrics subsystem using the provided context. |
| 618 | + * |
| 619 | + * Return: 0 on success, or a negative error code on failure. |
| 620 | + */ |
441 | 621 | int nvmf_connect(struct nvme_global_ctx *ctx, struct nvmf_context *fctx); |
| 622 | + |
| 623 | +/** |
| 624 | + * nvmf_connect_config_json() - Connect using JSON config |
| 625 | + * @ctx: Global context |
| 626 | + * @fctx: Fabrics context |
| 627 | + * |
| 628 | + * Connects to the fabrics subsystem using a JSON configuration. |
| 629 | + * |
| 630 | + * Return: 0 on success, or a negative error code on failure. |
| 631 | + */ |
442 | 632 | int nvmf_connect_config_json(struct nvme_global_ctx *ctx, |
443 | 633 | struct nvmf_context *fctx); |
444 | 634 |
|
| 635 | +/** |
| 636 | + * struct nbft_file_entry - Linked list entry for NBFT files |
| 637 | + * @next: Pointer to next entry |
| 638 | + * @nbft: Pointer to NBFT info structure |
| 639 | + */ |
445 | 640 | struct nbft_file_entry { |
446 | 641 | struct nbft_file_entry *next; |
447 | 642 | struct nbft_info *nbft; |
448 | 643 | }; |
449 | 644 |
|
| 645 | +/** |
| 646 | + * nvmf_nbft_read_files() - Read NBFT files from path |
| 647 | + * @path: Path to NBFT files |
| 648 | + * @head: Pointer to store linked list of NBFT file entries |
| 649 | + * |
| 650 | + * Reads NBFT files from the specified path and populates a linked list. |
| 651 | + * |
| 652 | + * Return: 0 on success, or a negative error code on failure. |
| 653 | + */ |
450 | 654 | int nvmf_nbft_read_files(char *path, struct nbft_file_entry **head); |
| 655 | + |
| 656 | +/** |
| 657 | + * nvmf_nbft_free() - Free NBFT file entry list |
| 658 | + * @head: Head of the NBFT file entry list |
| 659 | + * |
| 660 | + * Frees all memory associated with the NBFT file entry list. |
| 661 | + */ |
451 | 662 | void nvmf_nbft_free(struct nbft_file_entry *head); |
452 | 663 |
|
453 | 664 | #endif /* _LIBNVME_FABRICS_H */ |
0 commit comments