xref: /spdk/lib/iscsi/tgt_node.h (revision d1165a653907c85812beba21bf9cb6c657cf3bf1)
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 "spdk/scsi.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 
47 #define MAX_TARGET_MAP			256
48 #define SPDK_TN_TAG_MAX 		0x0000ffff
49 
50 struct spdk_iscsi_ig_map {
51 	struct spdk_iscsi_init_grp *ig;
52 	TAILQ_ENTRY(spdk_iscsi_ig_map) tailq;
53 };
54 
55 struct spdk_iscsi_pg_map {
56 	struct spdk_iscsi_portal_grp *pg;
57 	int num_ig_maps;
58 	TAILQ_HEAD(, spdk_iscsi_ig_map) ig_map_head;
59 	TAILQ_ENTRY(spdk_iscsi_pg_map) tailq ;
60 };
61 
62 struct spdk_iscsi_tgt_node {
63 	int num;
64 	char *name;
65 	char *alias;
66 
67 	pthread_mutex_t mutex;
68 
69 	bool disable_chap;
70 	bool require_chap;
71 	bool mutual_chap;
72 	int chap_group;
73 	bool header_digest;
74 	bool data_digest;
75 	int queue_depth;
76 
77 	struct spdk_scsi_dev *dev;
78 	/**
79 	 * Counts number of active iSCSI connections associated with this
80 	 *  target node.
81 	 */
82 	uint32_t num_active_conns;
83 	int lcore;
84 
85 	int num_pg_maps;
86 	TAILQ_HEAD(, spdk_iscsi_pg_map) pg_map_head;
87 	TAILQ_ENTRY(spdk_iscsi_tgt_node) tailq;
88 };
89 
90 int spdk_iscsi_init_tgt_nodes(void);
91 
92 void spdk_iscsi_shutdown_tgt_nodes(void);
93 int spdk_iscsi_shutdown_tgt_node_by_name(const char *target_name);
94 int spdk_iscsi_send_tgts(struct spdk_iscsi_conn *conn, const char *iiqn,
95 			 const char *iaddr, const char *tiqn, uint8_t *data, int alloc_len,
96 			 int data_len);
97 
98 /* This typedef exists to work around an astyle 2.05 bug.
99  * Remove it when astyle is fixed.
100  */
101 typedef struct spdk_iscsi_tgt_node _spdk_iscsi_tgt_node;
102 
103 /*
104  * bdev_name_list and lun_id_list are equal sized arrays of size num_luns.
105  * bdev_name_list refers to the names of the bdevs that will be used for the LUNs on the
106  *  new target node.
107  * lun_id_list refers to the LUN IDs that will be used for the LUNs on the target node.
108  */
109 _spdk_iscsi_tgt_node *
110 spdk_iscsi_tgt_node_construct(int target_index,
111 			      const char *name, const char *alias,
112 			      int *pg_tag_list, int *ig_tag_list, uint16_t num_maps,
113 			      const char *bdev_name_list[], int *lun_id_list, int num_luns,
114 			      int queue_depth,
115 			      bool disable_chap, bool require_chap, bool mutual_chap, int chap_group,
116 			      bool header_digest, bool data_digest);
117 
118 int spdk_iscsi_tgt_node_add_pg_ig_maps(struct spdk_iscsi_tgt_node *target,
119 				       int *pg_tag_list, int *ig_tag_list,
120 				       uint16_t num_maps);
121 int spdk_iscsi_tgt_node_delete_pg_ig_maps(struct spdk_iscsi_tgt_node *target,
122 		int *pg_tag_list, int *ig_tag_list,
123 		uint16_t num_maps);
124 
125 bool spdk_iscsi_tgt_node_access(struct spdk_iscsi_conn *conn,
126 				struct spdk_iscsi_tgt_node *target, const char *iqn,
127 				const char *addr);
128 struct spdk_iscsi_tgt_node *spdk_iscsi_find_tgt_node(const char *target_name);
129 int spdk_iscsi_tgt_node_reset(struct spdk_iscsi_tgt_node *target,
130 			      uint64_t lun);
131 int spdk_iscsi_tgt_node_cleanup_luns(struct spdk_iscsi_conn *conn,
132 				     struct spdk_iscsi_tgt_node *target);
133 void spdk_iscsi_tgt_node_delete_map(struct spdk_iscsi_portal_grp *portal_group,
134 				    struct spdk_iscsi_init_grp *initiator_group);
135 int spdk_iscsi_tgt_node_add_lun(struct spdk_iscsi_tgt_node *target,
136 				const char *bdev_name, int lun_id);
137 #endif /* SPDK_ISCSI_TGT_NODE_H_ */
138