xref: /spdk/lib/iscsi/tgt_node.h (revision 04c48172b9879a8824de83c842087d871c433d12)
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 <pthread.h>
39 #include <time.h>
40 
41 #include "spdk/scsi.h"
42 
43 struct spdk_iscsi_conn;
44 
45 #define SPDK_ISCSI_MAX_QUEUE_DEPTH	64
46 #define MAX_TARGET_MAP			256
47 #define SPDK_TN_TAG_MAX 0x0000ffff
48 
49 struct spdk_iscsi_tgt_node_map {
50 	struct spdk_iscsi_portal_grp	*pg;
51 	struct spdk_iscsi_init_grp	*ig;
52 };
53 
54 struct spdk_iscsi_tgt_node {
55 	int num;
56 	char *name;
57 	char *alias;
58 
59 	pthread_mutex_t mutex;
60 
61 	int auth_chap_disabled;
62 	int auth_chap_required;
63 	int auth_chap_mutual;
64 	int auth_group;
65 	int header_digest;
66 	int data_digest;
67 	int queue_depth;
68 
69 	struct spdk_scsi_dev *dev;
70 	/**
71 	 * Counts number of active iSCSI connections associated with this
72 	 *  target node.
73 	 */
74 	uint32_t num_active_conns;
75 	int lcore;
76 
77 	int maxmap;
78 	struct spdk_iscsi_tgt_node_map map[MAX_TARGET_MAP];
79 };
80 
81 int spdk_iscsi_init_tgt_nodes(void);
82 
83 int spdk_iscsi_shutdown_tgt_nodes(void);
84 int spdk_iscsi_shutdown_tgt_node_by_name(const char *target_name);
85 int spdk_iscsi_send_tgts(struct spdk_iscsi_conn *conn, const char *iiqn,
86 			 const char *iaddr, const char *tiqn, uint8_t *data, int alloc_len,
87 			 int data_len);
88 
89 struct spdk_iscsi_init_grp *
90 spdk_iscsi_find_init_grp(int tag);
91 
92 /* This typedef exists to work around an astyle 2.05 bug.
93  * Remove it when astyle is fixed.
94 */
95 typedef struct spdk_iscsi_tgt_node _spdk_iscsi_tgt_node;
96 
97 _spdk_iscsi_tgt_node *
98 spdk_iscsi_tgt_node_construct(int target_index,
99 			      const char *name, const char *alias,
100 			      int *pg_tag_list, int *ig_tag_list, uint16_t num_maps,
101 			      char *lun_name_list[], int *lun_id_list, int num_luns,
102 			      int queue_depth,
103 			      int no_auth_chap, int auth_chap, int auth_chap_mutual, int auth_group,
104 			      int header_digest, int data_digest);
105 
106 int spdk_iscsi_tgt_node_access(struct spdk_iscsi_conn *conn,
107 			       struct spdk_iscsi_tgt_node *target, const char *iqn,
108 			       const char *addr);
109 struct spdk_iscsi_tgt_node *spdk_iscsi_find_tgt_node(const char *target_name);
110 int spdk_iscsi_tgt_node_reset(struct spdk_iscsi_tgt_node *target,
111 			      uint64_t lun);
112 int spdk_iscsi_tgt_node_cleanup_luns(struct spdk_iscsi_conn *conn,
113 				     struct spdk_iscsi_tgt_node *target);
114 void spdk_iscsi_tgt_node_delete_map(struct spdk_iscsi_portal_grp *portal_group,
115 				    struct spdk_iscsi_init_grp *initiator_group);
116 #endif /* SPDK_ISCSI_TGT_NODE_H_ */
117