diff options
author | Nicholas Bellinger <nab@linux-iscsi.org> | 2016-05-15 00:44:01 -0400 |
---|---|---|
committer | Nicholas Bellinger <nab@linux-iscsi.org> | 2016-05-17 01:14:29 -0400 |
commit | d4b3fa4b0881b600ddeee9dd47b27dea9709f322 (patch) | |
tree | 1e44c18d5df566fed74e936c6bd86034449affce | |
parent | 54a5e73f4d6e31d5628e08b4d575c71d71670e09 (diff) |
iscsi-target: Make iscsi_tpg_np driver show/store use generic code
Go ahead and fold the duplicate iscsi_tpg_np driver attribute
show/store functions into generic callers, invoked by current
driver specific functions.
This allows for future v4.8+ changes to have iscsi_target_mod
use tpg_np driver attributes at runtime, instead of having
the defaults hardcoded in iscsi_target_configfs.c.
Also, drop the unused/legacy 'sctp' attribute for non standard
RFC-3720 operation with IPPROTO_SCTP.
Cc: Varun Prakash <varun@chelsio.com>
Cc: Hariprasad Shenai <hariprasad@chelsio.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
-rw-r--r-- | drivers/target/iscsi/iscsi_target_configfs.c | 199 |
1 files changed, 41 insertions, 158 deletions
diff --git a/drivers/target/iscsi/iscsi_target_configfs.c b/drivers/target/iscsi/iscsi_target_configfs.c index 1b8f885dbfeb..33d811ac9539 100644 --- a/drivers/target/iscsi/iscsi_target_configfs.c +++ b/drivers/target/iscsi/iscsi_target_configfs.c | |||
@@ -43,14 +43,15 @@ static inline struct iscsi_tpg_np *to_iscsi_tpg_np(struct config_item *item) | |||
43 | return container_of(to_tpg_np(item), struct iscsi_tpg_np, se_tpg_np); | 43 | return container_of(to_tpg_np(item), struct iscsi_tpg_np, se_tpg_np); |
44 | } | 44 | } |
45 | 45 | ||
46 | static ssize_t lio_target_np_sctp_show(struct config_item *item, char *page) | 46 | static ssize_t lio_target_np_driver_show(struct config_item *item, char *page, |
47 | enum iscsit_transport_type type) | ||
47 | { | 48 | { |
48 | struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item); | 49 | struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item); |
49 | struct iscsi_tpg_np *tpg_np_sctp; | 50 | struct iscsi_tpg_np *tpg_np_new; |
50 | ssize_t rb; | 51 | ssize_t rb; |
51 | 52 | ||
52 | tpg_np_sctp = iscsit_tpg_locate_child_np(tpg_np, ISCSI_SCTP_TCP); | 53 | tpg_np_new = iscsit_tpg_locate_child_np(tpg_np, type); |
53 | if (tpg_np_sctp) | 54 | if (tpg_np_new) |
54 | rb = sprintf(page, "1\n"); | 55 | rb = sprintf(page, "1\n"); |
55 | else | 56 | else |
56 | rb = sprintf(page, "0\n"); | 57 | rb = sprintf(page, "0\n"); |
@@ -58,86 +59,20 @@ static ssize_t lio_target_np_sctp_show(struct config_item *item, char *page) | |||
58 | return rb; | 59 | return rb; |
59 | } | 60 | } |
60 | 61 | ||
61 | static ssize_t lio_target_np_sctp_store(struct config_item *item, | 62 | static ssize_t lio_target_np_driver_store(struct config_item *item, |
62 | const char *page, size_t count) | 63 | const char *page, size_t count, enum iscsit_transport_type type, |
64 | const char *mod_name) | ||
63 | { | 65 | { |
64 | struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item); | 66 | struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item); |
65 | struct iscsi_np *np; | 67 | struct iscsi_np *np; |
66 | struct iscsi_portal_group *tpg; | 68 | struct iscsi_portal_group *tpg; |
67 | struct iscsi_tpg_np *tpg_np_sctp = NULL; | 69 | struct iscsi_tpg_np *tpg_np_new = NULL; |
68 | u32 op; | 70 | u32 op; |
69 | int ret; | 71 | int rc; |
70 | |||
71 | ret = kstrtou32(page, 0, &op); | ||
72 | if (ret) | ||
73 | return ret; | ||
74 | if ((op != 1) && (op != 0)) { | ||
75 | pr_err("Illegal value for tpg_enable: %u\n", op); | ||
76 | return -EINVAL; | ||
77 | } | ||
78 | np = tpg_np->tpg_np; | ||
79 | if (!np) { | ||
80 | pr_err("Unable to locate struct iscsi_np from" | ||
81 | " struct iscsi_tpg_np\n"); | ||
82 | return -EINVAL; | ||
83 | } | ||
84 | |||
85 | tpg = tpg_np->tpg; | ||
86 | if (iscsit_get_tpg(tpg) < 0) | ||
87 | return -EINVAL; | ||
88 | 72 | ||
89 | if (op) { | 73 | rc = kstrtou32(page, 0, &op); |
90 | /* | 74 | if (rc) |
91 | * Use existing np->np_sockaddr for SCTP network portal reference | 75 | return rc; |
92 | */ | ||
93 | tpg_np_sctp = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr, | ||
94 | tpg_np, ISCSI_SCTP_TCP); | ||
95 | if (!tpg_np_sctp || IS_ERR(tpg_np_sctp)) | ||
96 | goto out; | ||
97 | } else { | ||
98 | tpg_np_sctp = iscsit_tpg_locate_child_np(tpg_np, ISCSI_SCTP_TCP); | ||
99 | if (!tpg_np_sctp) | ||
100 | goto out; | ||
101 | |||
102 | ret = iscsit_tpg_del_network_portal(tpg, tpg_np_sctp); | ||
103 | if (ret < 0) | ||
104 | goto out; | ||
105 | } | ||
106 | |||
107 | iscsit_put_tpg(tpg); | ||
108 | return count; | ||
109 | out: | ||
110 | iscsit_put_tpg(tpg); | ||
111 | return -EINVAL; | ||
112 | } | ||
113 | |||
114 | static ssize_t lio_target_np_iser_show(struct config_item *item, char *page) | ||
115 | { | ||
116 | struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item); | ||
117 | struct iscsi_tpg_np *tpg_np_iser; | ||
118 | ssize_t rb; | ||
119 | |||
120 | tpg_np_iser = iscsit_tpg_locate_child_np(tpg_np, ISCSI_INFINIBAND); | ||
121 | if (tpg_np_iser) | ||
122 | rb = sprintf(page, "1\n"); | ||
123 | else | ||
124 | rb = sprintf(page, "0\n"); | ||
125 | |||
126 | return rb; | ||
127 | } | ||
128 | |||
129 | static ssize_t lio_target_np_iser_store(struct config_item *item, | ||
130 | const char *page, size_t count) | ||
131 | { | ||
132 | struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item); | ||
133 | struct iscsi_np *np; | ||
134 | struct iscsi_portal_group *tpg; | ||
135 | struct iscsi_tpg_np *tpg_np_iser = NULL; | ||
136 | char *endptr; | ||
137 | u32 op; | ||
138 | int rc = 0; | ||
139 | |||
140 | op = simple_strtoul(page, &endptr, 0); | ||
141 | if ((op != 1) && (op != 0)) { | 76 | if ((op != 1) && (op != 0)) { |
142 | pr_err("Illegal value for tpg_enable: %u\n", op); | 77 | pr_err("Illegal value for tpg_enable: %u\n", op); |
143 | return -EINVAL; | 78 | return -EINVAL; |
@@ -154,22 +89,23 @@ static ssize_t lio_target_np_iser_store(struct config_item *item, | |||
154 | return -EINVAL; | 89 | return -EINVAL; |
155 | 90 | ||
156 | if (op) { | 91 | if (op) { |
157 | rc = request_module("ib_isert"); | 92 | if (strlen(mod_name)) { |
158 | if (rc != 0) { | 93 | rc = request_module(mod_name); |
159 | pr_warn("Unable to request_module for ib_isert\n"); | 94 | if (rc != 0) { |
160 | rc = 0; | 95 | pr_warn("Unable to request_module for %s\n", |
96 | mod_name); | ||
97 | rc = 0; | ||
98 | } | ||
161 | } | 99 | } |
162 | 100 | ||
163 | tpg_np_iser = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr, | 101 | tpg_np_new = iscsit_tpg_add_network_portal(tpg, |
164 | tpg_np, ISCSI_INFINIBAND); | 102 | &np->np_sockaddr, tpg_np, type); |
165 | if (IS_ERR(tpg_np_iser)) { | 103 | if (IS_ERR(tpg_np_new)) |
166 | rc = PTR_ERR(tpg_np_iser); | ||
167 | goto out; | 104 | goto out; |
168 | } | ||
169 | } else { | 105 | } else { |
170 | tpg_np_iser = iscsit_tpg_locate_child_np(tpg_np, ISCSI_INFINIBAND); | 106 | tpg_np_new = iscsit_tpg_locate_child_np(tpg_np, type); |
171 | if (tpg_np_iser) { | 107 | if (tpg_np_new) { |
172 | rc = iscsit_tpg_del_network_portal(tpg, tpg_np_iser); | 108 | rc = iscsit_tpg_del_network_portal(tpg, tpg_np_new); |
173 | if (rc < 0) | 109 | if (rc < 0) |
174 | goto out; | 110 | goto out; |
175 | } | 111 | } |
@@ -182,86 +118,33 @@ out: | |||
182 | return rc; | 118 | return rc; |
183 | } | 119 | } |
184 | 120 | ||
185 | static ssize_t lio_target_np_hw_offload_show(struct config_item *item, | 121 | static ssize_t lio_target_np_iser_show(struct config_item *item, char *page) |
186 | char *page) | ||
187 | { | 122 | { |
188 | struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item); | 123 | return lio_target_np_driver_show(item, page, ISCSI_INFINIBAND); |
189 | struct iscsi_tpg_np *tpg_np_hw_offload; | 124 | } |
190 | ssize_t rb; | ||
191 | 125 | ||
192 | tpg_np_hw_offload = iscsit_tpg_locate_child_np(tpg_np, | 126 | static ssize_t lio_target_np_iser_store(struct config_item *item, |
193 | ISCSI_HW_OFFLOAD); | 127 | const char *page, size_t count) |
194 | if (tpg_np_hw_offload) | 128 | { |
195 | rb = sprintf(page, "1\n"); | 129 | return lio_target_np_driver_store(item, page, count, |
196 | else | 130 | ISCSI_INFINIBAND, "ib_isert"); |
197 | rb = sprintf(page, "0\n"); | 131 | } |
132 | CONFIGFS_ATTR(lio_target_np_, iser); | ||
198 | 133 | ||
199 | return rb; | 134 | static ssize_t lio_target_np_hw_offload_show(struct config_item *item, char *page) |
135 | { | ||
136 | return lio_target_np_driver_show(item, page, ISCSI_HW_OFFLOAD); | ||
200 | } | 137 | } |
201 | 138 | ||
202 | static ssize_t lio_target_np_hw_offload_store(struct config_item *item, | 139 | static ssize_t lio_target_np_hw_offload_store(struct config_item *item, |
203 | const char *page, size_t count) | 140 | const char *page, size_t count) |
204 | { | 141 | { |
205 | struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item); | 142 | return lio_target_np_driver_store(item, page, count, |
206 | struct iscsi_np *np; | 143 | ISCSI_HW_OFFLOAD, ""); |
207 | struct iscsi_portal_group *tpg; | ||
208 | struct iscsi_tpg_np *tpg_np_hw_offload = NULL; | ||
209 | u32 op; | ||
210 | int rc = 0; | ||
211 | |||
212 | rc = kstrtou32(page, 0, &op); | ||
213 | if (rc) | ||
214 | return rc; | ||
215 | |||
216 | if ((op != 1) && (op != 0)) { | ||
217 | pr_err("Illegal value for tpg_enable: %u\n", op); | ||
218 | return -EINVAL; | ||
219 | } | ||
220 | |||
221 | np = tpg_np->tpg_np; | ||
222 | if (!np) { | ||
223 | pr_err("Unable to locate struct iscsi_np from" | ||
224 | " struct iscsi_tpg_np\n"); | ||
225 | return -EINVAL; | ||
226 | } | ||
227 | |||
228 | tpg = tpg_np->tpg; | ||
229 | if (iscsit_get_tpg(tpg) < 0) | ||
230 | return -EINVAL; | ||
231 | |||
232 | if (op) { | ||
233 | tpg_np_hw_offload = iscsit_tpg_add_network_portal(tpg, | ||
234 | &np->np_sockaddr, tpg_np, ISCSI_HW_OFFLOAD); | ||
235 | |||
236 | if (IS_ERR(tpg_np_hw_offload)) { | ||
237 | rc = PTR_ERR(tpg_np_hw_offload); | ||
238 | goto out; | ||
239 | } | ||
240 | } else { | ||
241 | tpg_np_hw_offload = iscsit_tpg_locate_child_np(tpg_np, | ||
242 | ISCSI_HW_OFFLOAD); | ||
243 | |||
244 | if (tpg_np_hw_offload) { | ||
245 | rc = iscsit_tpg_del_network_portal(tpg, | ||
246 | tpg_np_hw_offload); | ||
247 | if (rc < 0) | ||
248 | goto out; | ||
249 | } | ||
250 | } | ||
251 | |||
252 | iscsit_put_tpg(tpg); | ||
253 | return count; | ||
254 | out: | ||
255 | iscsit_put_tpg(tpg); | ||
256 | return rc; | ||
257 | } | 144 | } |
258 | |||
259 | CONFIGFS_ATTR(lio_target_np_, sctp); | ||
260 | CONFIGFS_ATTR(lio_target_np_, iser); | ||
261 | CONFIGFS_ATTR(lio_target_np_, hw_offload); | 145 | CONFIGFS_ATTR(lio_target_np_, hw_offload); |
262 | 146 | ||
263 | static struct configfs_attribute *lio_target_portal_attrs[] = { | 147 | static struct configfs_attribute *lio_target_portal_attrs[] = { |
264 | &lio_target_np_attr_sctp, | ||
265 | &lio_target_np_attr_iser, | 148 | &lio_target_np_attr_iser, |
266 | &lio_target_np_attr_hw_offload, | 149 | &lio_target_np_attr_hw_offload, |
267 | NULL, | 150 | NULL, |