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