xref: /spdk/lib/iscsi/tgt_node.h (revision 877573897ad52be4fa8989f7617bd655b87e05c4)
1 /*   SPDX-License-Identifier: BSD-3-Clause
2  *   Copyright (C) 2008-2012 Daisuke Aoyama <aoyama@peach.ne.jp>.
3  *   Copyright (C) 2016 Intel Corporation.
4  *   All rights reserved.
5  */
6 
7 #ifndef SPDK_ISCSI_TGT_NODE_H_
8 #define SPDK_ISCSI_TGT_NODE_H_
9 
10 #include "spdk/stdinc.h"
11 
12 #include "iscsi/iscsi.h"
13 
14 struct spdk_iscsi_conn;
15 struct spdk_iscsi_init_grp;
16 struct spdk_iscsi_portal_grp;
17 struct spdk_iscsi_portal;
18 struct spdk_json_write_ctx;
19 
20 #define MAX_TARGET_MAP			256
21 #define SPDK_TN_TAG_MAX			0x0000ffff
22 
23 typedef void (*iscsi_tgt_node_destruct_cb)(void *cb_arg, int rc);
24 
25 struct spdk_iscsi_ig_map {
26 	struct spdk_iscsi_init_grp *ig;
27 	TAILQ_ENTRY(spdk_iscsi_ig_map) tailq;
28 };
29 
30 struct spdk_iscsi_pg_map {
31 	struct spdk_iscsi_portal_grp *pg;
32 	int num_ig_maps;
33 	TAILQ_HEAD(, spdk_iscsi_ig_map) ig_map_head;
34 	char redirect_host[MAX_PORTAL_ADDR + 1];
35 	char redirect_port[MAX_PORTAL_PORT + 1];
36 	TAILQ_ENTRY(spdk_iscsi_pg_map) tailq ;
37 };
38 
39 struct spdk_iscsi_tgt_node {
40 	int num;
41 	char name[MAX_TARGET_NAME + 1];
42 	char alias[MAX_TARGET_NAME + 1];
43 
44 	pthread_mutex_t mutex;
45 
46 	bool disable_chap;
47 	bool require_chap;
48 	bool mutual_chap;
49 	int chap_group;
50 	bool header_digest;
51 	bool data_digest;
52 	int queue_depth;
53 
54 	struct spdk_scsi_dev *dev;
55 	/**
56 	 * Counts number of active iSCSI connections associated with this
57 	 *  target node.
58 	 */
59 	uint32_t num_active_conns;
60 	struct spdk_iscsi_poll_group *pg;
61 
62 	int num_pg_maps;
63 	TAILQ_HEAD(, spdk_iscsi_pg_map) pg_map_head;
64 	TAILQ_ENTRY(spdk_iscsi_tgt_node) tailq;
65 
66 	bool destructed;
67 	struct spdk_poller *destruct_poller;
68 	iscsi_tgt_node_destruct_cb destruct_cb_fn;
69 	void *destruct_cb_arg;
70 };
71 
72 void iscsi_shutdown_tgt_nodes(void);
73 void iscsi_shutdown_tgt_node_by_name(const char *target_name,
74 				     iscsi_tgt_node_destruct_cb cb_fn, void *cb_arg);
75 bool iscsi_tgt_node_is_destructed(struct spdk_iscsi_tgt_node *target);
76 int iscsi_send_tgts(struct spdk_iscsi_conn *conn, const char *iiqn,
77 		    const char *tiqn, uint8_t *data, int alloc_len, int data_len);
78 
79 /*
80  * bdev_name_list and lun_id_list are equal sized arrays of size num_luns.
81  * bdev_name_list refers to the names of the bdevs that will be used for the LUNs on the
82  *  new target node.
83  * lun_id_list refers to the LUN IDs that will be used for the LUNs on the target node.
84  */
85 struct spdk_iscsi_tgt_node *iscsi_tgt_node_construct(int target_index,
86 		const char *name, const char *alias,
87 		int *pg_tag_list, int *ig_tag_list, uint16_t num_maps,
88 		const char *bdev_name_list[], int *lun_id_list, int num_luns,
89 		int queue_depth,
90 		bool disable_chap, bool require_chap, bool mutual_chap, int chap_group,
91 		bool header_digest, bool data_digest);
92 
93 bool iscsi_check_chap_params(bool disable, bool require, bool mutual, int group);
94 
95 int iscsi_target_node_add_pg_ig_maps(struct spdk_iscsi_tgt_node *target,
96 				     int *pg_tag_list, int *ig_tag_list,
97 				     uint16_t num_maps);
98 int iscsi_target_node_remove_pg_ig_maps(struct spdk_iscsi_tgt_node *target,
99 					int *pg_tag_list, int *ig_tag_list,
100 					uint16_t num_maps);
101 int iscsi_tgt_node_redirect(struct spdk_iscsi_tgt_node *target, int pg_tag,
102 			    const char *host, const char *port);
103 bool iscsi_tgt_node_is_redirected(struct spdk_iscsi_conn *conn,
104 				  struct spdk_iscsi_tgt_node *target,
105 				  char *buf, int buf_len);
106 
107 bool iscsi_tgt_node_access(struct spdk_iscsi_conn *conn,
108 			   struct spdk_iscsi_tgt_node *target, const char *iqn,
109 			   const char *addr);
110 struct spdk_iscsi_tgt_node *iscsi_find_tgt_node(const char *target_name);
111 int iscsi_tgt_node_cleanup_luns(struct spdk_iscsi_conn *conn,
112 				struct spdk_iscsi_tgt_node *target);
113 void iscsi_tgt_node_delete_map(struct spdk_iscsi_portal_grp *portal_group,
114 			       struct spdk_iscsi_init_grp *initiator_group);
115 int iscsi_tgt_node_add_lun(struct spdk_iscsi_tgt_node *target,
116 			   const char *bdev_name, int lun_id);
117 int iscsi_tgt_node_set_chap_params(struct spdk_iscsi_tgt_node *target,
118 				   bool disable_chap, bool require_chap,
119 				   bool mutual_chap, int32_t chap_group);
120 void iscsi_tgt_nodes_info_json(struct spdk_json_write_ctx *w);
121 void iscsi_tgt_nodes_config_json(struct spdk_json_write_ctx *w);
122 #endif /* SPDK_ISCSI_TGT_NODE_H_ */
123