xref: /spdk/lib/iscsi/tgt_node.h (revision 7961de43413e7f818f7499bf8518909beb59c82f)
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright (C) 2008-2012 Daisuke Aoyama <aoyama@peach.ne.jp>.
5  *   Copyright (c) Intel Corporation.
6  *   All rights reserved.
7  *
8  *   Redistribution and use in source and binary forms, with or without
9  *   modification, are permitted provided that the following conditions
10  *   are met:
11  *
12  *     * Redistributions of source code must retain the above copyright
13  *       notice, this list of conditions and the following disclaimer.
14  *     * Redistributions in binary form must reproduce the above copyright
15  *       notice, this list of conditions and the following disclaimer in
16  *       the documentation and/or other materials provided with the
17  *       distribution.
18  *     * Neither the name of Intel Corporation nor the names of its
19  *       contributors may be used to endorse or promote products derived
20  *       from this software without specific prior written permission.
21  *
22  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #ifndef SPDK_ISCSI_TGT_NODE_H_
36 #define SPDK_ISCSI_TGT_NODE_H_
37 
38 #include "spdk/stdinc.h"
39 
40 #include "iscsi/iscsi.h"
41 
42 struct spdk_iscsi_conn;
43 struct spdk_iscsi_init_grp;
44 struct spdk_iscsi_portal_grp;
45 struct spdk_iscsi_portal;
46 struct spdk_json_write_ctx;
47 
48 #define MAX_TARGET_MAP			256
49 #define SPDK_TN_TAG_MAX			0x0000ffff
50 
51 typedef void (*iscsi_tgt_node_destruct_cb)(void *cb_arg, int rc);
52 
53 struct spdk_iscsi_ig_map {
54 	struct spdk_iscsi_init_grp *ig;
55 	TAILQ_ENTRY(spdk_iscsi_ig_map) tailq;
56 };
57 
58 struct spdk_iscsi_pg_map {
59 	struct spdk_iscsi_portal_grp *pg;
60 	int num_ig_maps;
61 	TAILQ_HEAD(, spdk_iscsi_ig_map) ig_map_head;
62 	TAILQ_ENTRY(spdk_iscsi_pg_map) tailq ;
63 };
64 
65 struct spdk_iscsi_tgt_node {
66 	int num;
67 	char name[MAX_TARGET_NAME + 1];
68 	char alias[MAX_TARGET_NAME + 1];
69 
70 	pthread_mutex_t mutex;
71 
72 	bool disable_chap;
73 	bool require_chap;
74 	bool mutual_chap;
75 	int chap_group;
76 	bool header_digest;
77 	bool data_digest;
78 	int queue_depth;
79 
80 	struct spdk_scsi_dev *dev;
81 	/**
82 	 * Counts number of active iSCSI connections associated with this
83 	 *  target node.
84 	 */
85 	uint32_t num_active_conns;
86 	struct spdk_iscsi_poll_group *pg;
87 
88 	int num_pg_maps;
89 	TAILQ_HEAD(, spdk_iscsi_pg_map) pg_map_head;
90 	TAILQ_ENTRY(spdk_iscsi_tgt_node) tailq;
91 
92 	bool destructed;
93 	struct spdk_poller *destruct_poller;
94 	iscsi_tgt_node_destruct_cb destruct_cb_fn;
95 	void *destruct_cb_arg;
96 };
97 
98 int spdk_iscsi_parse_tgt_nodes(void);
99 
100 void spdk_iscsi_shutdown_tgt_nodes(void);
101 void spdk_iscsi_shutdown_tgt_node_by_name(const char *target_name,
102 		iscsi_tgt_node_destruct_cb cb_fn, void *cb_arg);
103 bool spdk_iscsi_tgt_node_is_destructed(struct spdk_iscsi_tgt_node *target);
104 int spdk_iscsi_send_tgts(struct spdk_iscsi_conn *conn, const char *iiqn,
105 			 const char *iaddr, const char *tiqn, uint8_t *data, int alloc_len,
106 			 int data_len);
107 
108 /* This typedef exists to work around an astyle 2.05 bug.
109  * Remove it when astyle is fixed.
110  */
111 typedef struct spdk_iscsi_tgt_node _spdk_iscsi_tgt_node;
112 
113 /*
114  * bdev_name_list and lun_id_list are equal sized arrays of size num_luns.
115  * bdev_name_list refers to the names of the bdevs that will be used for the LUNs on the
116  *  new target node.
117  * lun_id_list refers to the LUN IDs that will be used for the LUNs on the target node.
118  */
119 _spdk_iscsi_tgt_node *
120 spdk_iscsi_tgt_node_construct(int target_index,
121 			      const char *name, const char *alias,
122 			      int *pg_tag_list, int *ig_tag_list, uint16_t num_maps,
123 			      const char *bdev_name_list[], int *lun_id_list, int num_luns,
124 			      int queue_depth,
125 			      bool disable_chap, bool require_chap, bool mutual_chap, int chap_group,
126 			      bool header_digest, bool data_digest);
127 
128 bool spdk_iscsi_check_chap_params(bool disable, bool require, bool mutual, int group);
129 
130 int spdk_iscsi_target_node_add_pg_ig_maps(struct spdk_iscsi_tgt_node *target,
131 		int *pg_tag_list, int *ig_tag_list,
132 		uint16_t num_maps);
133 int spdk_iscsi_target_node_remove_pg_ig_maps(struct spdk_iscsi_tgt_node *target,
134 		int *pg_tag_list, int *ig_tag_list,
135 		uint16_t num_maps);
136 
137 bool spdk_iscsi_tgt_node_access(struct spdk_iscsi_conn *conn,
138 				struct spdk_iscsi_tgt_node *target, const char *iqn,
139 				const char *addr);
140 struct spdk_iscsi_tgt_node *spdk_iscsi_find_tgt_node(const char *target_name);
141 int spdk_iscsi_tgt_node_reset(struct spdk_iscsi_tgt_node *target,
142 			      uint64_t lun);
143 int spdk_iscsi_tgt_node_cleanup_luns(struct spdk_iscsi_conn *conn,
144 				     struct spdk_iscsi_tgt_node *target);
145 void spdk_iscsi_tgt_node_delete_map(struct spdk_iscsi_portal_grp *portal_group,
146 				    struct spdk_iscsi_init_grp *initiator_group);
147 int spdk_iscsi_tgt_node_add_lun(struct spdk_iscsi_tgt_node *target,
148 				const char *bdev_name, int lun_id);
149 int spdk_iscsi_tgt_node_set_chap_params(struct spdk_iscsi_tgt_node *target,
150 					bool disable_chap, bool require_chap,
151 					bool mutual_chap, int32_t chap_group);
152 void spdk_iscsi_tgt_nodes_config_text(FILE *fp);
153 void spdk_iscsi_tgt_nodes_info_json(struct spdk_json_write_ctx *w);
154 void spdk_iscsi_tgt_nodes_config_json(struct spdk_json_write_ctx *w);
155 #endif /* SPDK_ISCSI_TGT_NODE_H_ */
156