0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <linux/configfs.h>
0013 #include <linux/ctype.h>
0014 #include <linux/export.h>
0015 #include <linux/inet.h>
0016 #include <linux/module.h>
0017 #include <net/ipv6.h>
0018 #include <target/target_core_base.h>
0019 #include <target/target_core_fabric.h>
0020 #include <target/iscsi/iscsi_transport.h>
0021 #include <target/iscsi/iscsi_target_core.h>
0022 #include "iscsi_target_parameters.h"
0023 #include "iscsi_target_device.h"
0024 #include "iscsi_target_erl0.h"
0025 #include "iscsi_target_nodeattrib.h"
0026 #include "iscsi_target_tpg.h"
0027 #include "iscsi_target_util.h"
0028 #include "iscsi_target.h"
0029 #include <target/iscsi/iscsi_target_stat.h>
0030
0031
0032
0033
0034 static inline struct iscsi_tpg_np *to_iscsi_tpg_np(struct config_item *item)
0035 {
0036 return container_of(to_tpg_np(item), struct iscsi_tpg_np, se_tpg_np);
0037 }
0038
0039 static ssize_t lio_target_np_driver_show(struct config_item *item, char *page,
0040 enum iscsit_transport_type type)
0041 {
0042 struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
0043 struct iscsi_tpg_np *tpg_np_new;
0044 ssize_t rb;
0045
0046 tpg_np_new = iscsit_tpg_locate_child_np(tpg_np, type);
0047 if (tpg_np_new)
0048 rb = sprintf(page, "1\n");
0049 else
0050 rb = sprintf(page, "0\n");
0051
0052 return rb;
0053 }
0054
0055 static ssize_t lio_target_np_driver_store(struct config_item *item,
0056 const char *page, size_t count, enum iscsit_transport_type type,
0057 const char *mod_name)
0058 {
0059 struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
0060 struct iscsi_np *np;
0061 struct iscsi_portal_group *tpg;
0062 struct iscsi_tpg_np *tpg_np_new = NULL;
0063 u32 op;
0064 int rc;
0065
0066 rc = kstrtou32(page, 0, &op);
0067 if (rc)
0068 return rc;
0069 if ((op != 1) && (op != 0)) {
0070 pr_err("Illegal value for tpg_enable: %u\n", op);
0071 return -EINVAL;
0072 }
0073 np = tpg_np->tpg_np;
0074 if (!np) {
0075 pr_err("Unable to locate struct iscsi_np from"
0076 " struct iscsi_tpg_np\n");
0077 return -EINVAL;
0078 }
0079
0080 tpg = tpg_np->tpg;
0081 if (iscsit_get_tpg(tpg) < 0)
0082 return -EINVAL;
0083
0084 if (op) {
0085 if (strlen(mod_name)) {
0086 rc = request_module(mod_name);
0087 if (rc != 0) {
0088 pr_warn("Unable to request_module for %s\n",
0089 mod_name);
0090 rc = 0;
0091 }
0092 }
0093
0094 tpg_np_new = iscsit_tpg_add_network_portal(tpg,
0095 &np->np_sockaddr, tpg_np, type);
0096 if (IS_ERR(tpg_np_new)) {
0097 rc = PTR_ERR(tpg_np_new);
0098 goto out;
0099 }
0100 } else {
0101 tpg_np_new = iscsit_tpg_locate_child_np(tpg_np, type);
0102 if (tpg_np_new) {
0103 rc = iscsit_tpg_del_network_portal(tpg, tpg_np_new);
0104 if (rc < 0)
0105 goto out;
0106 }
0107 }
0108
0109 iscsit_put_tpg(tpg);
0110 return count;
0111 out:
0112 iscsit_put_tpg(tpg);
0113 return rc;
0114 }
0115
0116 static ssize_t lio_target_np_iser_show(struct config_item *item, char *page)
0117 {
0118 return lio_target_np_driver_show(item, page, ISCSI_INFINIBAND);
0119 }
0120
0121 static ssize_t lio_target_np_iser_store(struct config_item *item,
0122 const char *page, size_t count)
0123 {
0124 return lio_target_np_driver_store(item, page, count,
0125 ISCSI_INFINIBAND, "ib_isert");
0126 }
0127 CONFIGFS_ATTR(lio_target_np_, iser);
0128
0129 static ssize_t lio_target_np_cxgbit_show(struct config_item *item, char *page)
0130 {
0131 return lio_target_np_driver_show(item, page, ISCSI_CXGBIT);
0132 }
0133
0134 static ssize_t lio_target_np_cxgbit_store(struct config_item *item,
0135 const char *page, size_t count)
0136 {
0137 return lio_target_np_driver_store(item, page, count,
0138 ISCSI_CXGBIT, "cxgbit");
0139 }
0140 CONFIGFS_ATTR(lio_target_np_, cxgbit);
0141
0142 static struct configfs_attribute *lio_target_portal_attrs[] = {
0143 &lio_target_np_attr_iser,
0144 &lio_target_np_attr_cxgbit,
0145 NULL,
0146 };
0147
0148
0149
0150
0151
0152 #define MAX_PORTAL_LEN 256
0153
0154 static struct se_tpg_np *lio_target_call_addnptotpg(
0155 struct se_portal_group *se_tpg,
0156 struct config_group *group,
0157 const char *name)
0158 {
0159 struct iscsi_portal_group *tpg;
0160 struct iscsi_tpg_np *tpg_np;
0161 char *str, *str2, *ip_str, *port_str;
0162 struct sockaddr_storage sockaddr = { };
0163 int ret;
0164 char buf[MAX_PORTAL_LEN + 1] = { };
0165
0166 if (strlen(name) > MAX_PORTAL_LEN) {
0167 pr_err("strlen(name): %d exceeds MAX_PORTAL_LEN: %d\n",
0168 (int)strlen(name), MAX_PORTAL_LEN);
0169 return ERR_PTR(-EOVERFLOW);
0170 }
0171 snprintf(buf, MAX_PORTAL_LEN + 1, "%s", name);
0172
0173 str = strstr(buf, "[");
0174 if (str) {
0175 str2 = strstr(str, "]");
0176 if (!str2) {
0177 pr_err("Unable to locate trailing \"]\""
0178 " in IPv6 iSCSI network portal address\n");
0179 return ERR_PTR(-EINVAL);
0180 }
0181
0182 ip_str = str + 1;
0183 *str2 = '\0';
0184 str2++;
0185
0186 port_str = strstr(str2, ":");
0187 if (!port_str) {
0188 pr_err("Unable to locate \":port\""
0189 " in IPv6 iSCSI network portal address\n");
0190 return ERR_PTR(-EINVAL);
0191 }
0192 *port_str = '\0';
0193 port_str++;
0194 } else {
0195 ip_str = &buf[0];
0196 port_str = strstr(ip_str, ":");
0197 if (!port_str) {
0198 pr_err("Unable to locate \":port\""
0199 " in IPv4 iSCSI network portal address\n");
0200 return ERR_PTR(-EINVAL);
0201 }
0202 *port_str = '\0';
0203 port_str++;
0204 }
0205
0206 ret = inet_pton_with_scope(&init_net, AF_UNSPEC, ip_str,
0207 port_str, &sockaddr);
0208 if (ret) {
0209 pr_err("malformed ip/port passed: %s\n", name);
0210 return ERR_PTR(ret);
0211 }
0212
0213 tpg = to_iscsi_tpg(se_tpg);
0214 ret = iscsit_get_tpg(tpg);
0215 if (ret < 0)
0216 return ERR_PTR(-EINVAL);
0217
0218 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s TPGT: %hu"
0219 " PORTAL: %s\n",
0220 config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
0221 tpg->tpgt, name);
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235 tpg_np = iscsit_tpg_add_network_portal(tpg, &sockaddr, NULL,
0236 ISCSI_TCP);
0237 if (IS_ERR(tpg_np)) {
0238 iscsit_put_tpg(tpg);
0239 return ERR_CAST(tpg_np);
0240 }
0241 pr_debug("LIO_Target_ConfigFS: addnptotpg done!\n");
0242
0243 iscsit_put_tpg(tpg);
0244 return &tpg_np->se_tpg_np;
0245 }
0246
0247 static void lio_target_call_delnpfromtpg(
0248 struct se_tpg_np *se_tpg_np)
0249 {
0250 struct iscsi_portal_group *tpg;
0251 struct iscsi_tpg_np *tpg_np;
0252 struct se_portal_group *se_tpg;
0253 int ret;
0254
0255 tpg_np = container_of(se_tpg_np, struct iscsi_tpg_np, se_tpg_np);
0256 tpg = tpg_np->tpg;
0257 ret = iscsit_get_tpg(tpg);
0258 if (ret < 0)
0259 return;
0260
0261 se_tpg = &tpg->tpg_se_tpg;
0262 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s TPGT: %hu"
0263 " PORTAL: %pISpc\n", config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
0264 tpg->tpgt, &tpg_np->tpg_np->np_sockaddr);
0265
0266 ret = iscsit_tpg_del_network_portal(tpg, tpg_np);
0267 if (ret < 0)
0268 goto out;
0269
0270 pr_debug("LIO_Target_ConfigFS: delnpfromtpg done!\n");
0271 out:
0272 iscsit_put_tpg(tpg);
0273 }
0274
0275
0276
0277
0278
0279 #define ISCSI_NACL_ATTR(name) \
0280 static ssize_t iscsi_nacl_attrib_##name##_show(struct config_item *item,\
0281 char *page) \
0282 { \
0283 struct se_node_acl *se_nacl = attrib_to_nacl(item); \
0284 struct iscsi_node_acl *nacl = to_iscsi_nacl(se_nacl); \
0285 return sprintf(page, "%u\n", nacl->node_attrib.name); \
0286 } \
0287 \
0288 static ssize_t iscsi_nacl_attrib_##name##_store(struct config_item *item,\
0289 const char *page, size_t count) \
0290 { \
0291 struct se_node_acl *se_nacl = attrib_to_nacl(item); \
0292 struct iscsi_node_acl *nacl = to_iscsi_nacl(se_nacl); \
0293 u32 val; \
0294 int ret; \
0295 \
0296 ret = kstrtou32(page, 0, &val); \
0297 if (ret) \
0298 return ret; \
0299 ret = iscsit_na_##name(nacl, val); \
0300 if (ret < 0) \
0301 return ret; \
0302 \
0303 return count; \
0304 } \
0305 \
0306 CONFIGFS_ATTR(iscsi_nacl_attrib_, name)
0307
0308 ISCSI_NACL_ATTR(dataout_timeout);
0309 ISCSI_NACL_ATTR(dataout_timeout_retries);
0310 ISCSI_NACL_ATTR(default_erl);
0311 ISCSI_NACL_ATTR(nopin_timeout);
0312 ISCSI_NACL_ATTR(nopin_response_timeout);
0313 ISCSI_NACL_ATTR(random_datain_pdu_offsets);
0314 ISCSI_NACL_ATTR(random_datain_seq_offsets);
0315 ISCSI_NACL_ATTR(random_r2t_offsets);
0316
0317 static ssize_t iscsi_nacl_attrib_authentication_show(struct config_item *item,
0318 char *page)
0319 {
0320 struct se_node_acl *se_nacl = attrib_to_nacl(item);
0321 struct iscsi_node_acl *nacl = to_iscsi_nacl(se_nacl);
0322
0323 return sprintf(page, "%d\n", nacl->node_attrib.authentication);
0324 }
0325
0326 static ssize_t iscsi_nacl_attrib_authentication_store(struct config_item *item,
0327 const char *page, size_t count)
0328 {
0329 struct se_node_acl *se_nacl = attrib_to_nacl(item);
0330 struct iscsi_node_acl *nacl = to_iscsi_nacl(se_nacl);
0331 s32 val;
0332 int ret;
0333
0334 ret = kstrtos32(page, 0, &val);
0335 if (ret)
0336 return ret;
0337 if (val != 0 && val != 1 && val != NA_AUTHENTICATION_INHERITED)
0338 return -EINVAL;
0339
0340 nacl->node_attrib.authentication = val;
0341
0342 return count;
0343 }
0344
0345 CONFIGFS_ATTR(iscsi_nacl_attrib_, authentication);
0346
0347 static struct configfs_attribute *lio_target_nacl_attrib_attrs[] = {
0348 &iscsi_nacl_attrib_attr_dataout_timeout,
0349 &iscsi_nacl_attrib_attr_dataout_timeout_retries,
0350 &iscsi_nacl_attrib_attr_default_erl,
0351 &iscsi_nacl_attrib_attr_nopin_timeout,
0352 &iscsi_nacl_attrib_attr_nopin_response_timeout,
0353 &iscsi_nacl_attrib_attr_random_datain_pdu_offsets,
0354 &iscsi_nacl_attrib_attr_random_datain_seq_offsets,
0355 &iscsi_nacl_attrib_attr_random_r2t_offsets,
0356 &iscsi_nacl_attrib_attr_authentication,
0357 NULL,
0358 };
0359
0360
0361
0362
0363
0364 #define __DEF_NACL_AUTH_STR(prefix, name, flags) \
0365 static ssize_t __iscsi_##prefix##_##name##_show( \
0366 struct iscsi_node_acl *nacl, \
0367 char *page) \
0368 { \
0369 struct iscsi_node_auth *auth = &nacl->node_auth; \
0370 \
0371 if (!capable(CAP_SYS_ADMIN)) \
0372 return -EPERM; \
0373 return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \
0374 } \
0375 \
0376 static ssize_t __iscsi_##prefix##_##name##_store( \
0377 struct iscsi_node_acl *nacl, \
0378 const char *page, \
0379 size_t count) \
0380 { \
0381 struct iscsi_node_auth *auth = &nacl->node_auth; \
0382 \
0383 if (!capable(CAP_SYS_ADMIN)) \
0384 return -EPERM; \
0385 if (count >= sizeof(auth->name)) \
0386 return -EINVAL; \
0387 snprintf(auth->name, sizeof(auth->name), "%s", page); \
0388 if (!strncmp("NULL", auth->name, 4)) \
0389 auth->naf_flags &= ~flags; \
0390 else \
0391 auth->naf_flags |= flags; \
0392 \
0393 if ((auth->naf_flags & NAF_USERID_IN_SET) && \
0394 (auth->naf_flags & NAF_PASSWORD_IN_SET)) \
0395 auth->authenticate_target = 1; \
0396 else \
0397 auth->authenticate_target = 0; \
0398 \
0399 return count; \
0400 }
0401
0402 #define DEF_NACL_AUTH_STR(name, flags) \
0403 __DEF_NACL_AUTH_STR(nacl_auth, name, flags) \
0404 static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item, \
0405 char *page) \
0406 { \
0407 struct se_node_acl *nacl = auth_to_nacl(item); \
0408 return __iscsi_nacl_auth_##name##_show(to_iscsi_nacl(nacl), page); \
0409 } \
0410 static ssize_t iscsi_nacl_auth_##name##_store(struct config_item *item, \
0411 const char *page, size_t count) \
0412 { \
0413 struct se_node_acl *nacl = auth_to_nacl(item); \
0414 return __iscsi_nacl_auth_##name##_store(to_iscsi_nacl(nacl), \
0415 page, count); \
0416 } \
0417 \
0418 CONFIGFS_ATTR(iscsi_nacl_auth_, name)
0419
0420
0421
0422
0423 DEF_NACL_AUTH_STR(userid, NAF_USERID_SET);
0424 DEF_NACL_AUTH_STR(password, NAF_PASSWORD_SET);
0425 DEF_NACL_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
0426 DEF_NACL_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
0427
0428 #define __DEF_NACL_AUTH_INT(prefix, name) \
0429 static ssize_t __iscsi_##prefix##_##name##_show( \
0430 struct iscsi_node_acl *nacl, \
0431 char *page) \
0432 { \
0433 struct iscsi_node_auth *auth = &nacl->node_auth; \
0434 \
0435 if (!capable(CAP_SYS_ADMIN)) \
0436 return -EPERM; \
0437 \
0438 return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \
0439 }
0440
0441 #define DEF_NACL_AUTH_INT(name) \
0442 __DEF_NACL_AUTH_INT(nacl_auth, name) \
0443 static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item, \
0444 char *page) \
0445 { \
0446 struct se_node_acl *nacl = auth_to_nacl(item); \
0447 return __iscsi_nacl_auth_##name##_show(to_iscsi_nacl(nacl), page); \
0448 } \
0449 \
0450 CONFIGFS_ATTR_RO(iscsi_nacl_auth_, name)
0451
0452 DEF_NACL_AUTH_INT(authenticate_target);
0453
0454 static struct configfs_attribute *lio_target_nacl_auth_attrs[] = {
0455 &iscsi_nacl_auth_attr_userid,
0456 &iscsi_nacl_auth_attr_password,
0457 &iscsi_nacl_auth_attr_authenticate_target,
0458 &iscsi_nacl_auth_attr_userid_mutual,
0459 &iscsi_nacl_auth_attr_password_mutual,
0460 NULL,
0461 };
0462
0463
0464
0465
0466
0467 #define ISCSI_NACL_PARAM(name) \
0468 static ssize_t iscsi_nacl_param_##name##_show(struct config_item *item, \
0469 char *page) \
0470 { \
0471 struct se_node_acl *se_nacl = param_to_nacl(item); \
0472 struct iscsit_session *sess; \
0473 struct se_session *se_sess; \
0474 ssize_t rb; \
0475 \
0476 spin_lock_bh(&se_nacl->nacl_sess_lock); \
0477 se_sess = se_nacl->nacl_sess; \
0478 if (!se_sess) { \
0479 rb = snprintf(page, PAGE_SIZE, \
0480 "No Active iSCSI Session\n"); \
0481 } else { \
0482 sess = se_sess->fabric_sess_ptr; \
0483 rb = snprintf(page, PAGE_SIZE, "%u\n", \
0484 (u32)sess->sess_ops->name); \
0485 } \
0486 spin_unlock_bh(&se_nacl->nacl_sess_lock); \
0487 \
0488 return rb; \
0489 } \
0490 \
0491 CONFIGFS_ATTR_RO(iscsi_nacl_param_, name)
0492
0493 ISCSI_NACL_PARAM(MaxConnections);
0494 ISCSI_NACL_PARAM(InitialR2T);
0495 ISCSI_NACL_PARAM(ImmediateData);
0496 ISCSI_NACL_PARAM(MaxBurstLength);
0497 ISCSI_NACL_PARAM(FirstBurstLength);
0498 ISCSI_NACL_PARAM(DefaultTime2Wait);
0499 ISCSI_NACL_PARAM(DefaultTime2Retain);
0500 ISCSI_NACL_PARAM(MaxOutstandingR2T);
0501 ISCSI_NACL_PARAM(DataPDUInOrder);
0502 ISCSI_NACL_PARAM(DataSequenceInOrder);
0503 ISCSI_NACL_PARAM(ErrorRecoveryLevel);
0504
0505 static struct configfs_attribute *lio_target_nacl_param_attrs[] = {
0506 &iscsi_nacl_param_attr_MaxConnections,
0507 &iscsi_nacl_param_attr_InitialR2T,
0508 &iscsi_nacl_param_attr_ImmediateData,
0509 &iscsi_nacl_param_attr_MaxBurstLength,
0510 &iscsi_nacl_param_attr_FirstBurstLength,
0511 &iscsi_nacl_param_attr_DefaultTime2Wait,
0512 &iscsi_nacl_param_attr_DefaultTime2Retain,
0513 &iscsi_nacl_param_attr_MaxOutstandingR2T,
0514 &iscsi_nacl_param_attr_DataPDUInOrder,
0515 &iscsi_nacl_param_attr_DataSequenceInOrder,
0516 &iscsi_nacl_param_attr_ErrorRecoveryLevel,
0517 NULL,
0518 };
0519
0520
0521
0522
0523
0524 static ssize_t lio_target_nacl_info_show(struct config_item *item, char *page)
0525 {
0526 struct se_node_acl *se_nacl = acl_to_nacl(item);
0527 struct iscsit_session *sess;
0528 struct iscsit_conn *conn;
0529 struct se_session *se_sess;
0530 ssize_t rb = 0;
0531 u32 max_cmd_sn;
0532
0533 spin_lock_bh(&se_nacl->nacl_sess_lock);
0534 se_sess = se_nacl->nacl_sess;
0535 if (!se_sess) {
0536 rb += sprintf(page+rb, "No active iSCSI Session for Initiator"
0537 " Endpoint: %s\n", se_nacl->initiatorname);
0538 } else {
0539 sess = se_sess->fabric_sess_ptr;
0540
0541 rb += sprintf(page+rb, "InitiatorName: %s\n",
0542 sess->sess_ops->InitiatorName);
0543 rb += sprintf(page+rb, "InitiatorAlias: %s\n",
0544 sess->sess_ops->InitiatorAlias);
0545
0546 rb += sprintf(page+rb,
0547 "LIO Session ID: %u ISID: 0x%6ph TSIH: %hu ",
0548 sess->sid, sess->isid, sess->tsih);
0549 rb += sprintf(page+rb, "SessionType: %s\n",
0550 (sess->sess_ops->SessionType) ?
0551 "Discovery" : "Normal");
0552 rb += sprintf(page+rb, "Session State: ");
0553 switch (sess->session_state) {
0554 case TARG_SESS_STATE_FREE:
0555 rb += sprintf(page+rb, "TARG_SESS_FREE\n");
0556 break;
0557 case TARG_SESS_STATE_ACTIVE:
0558 rb += sprintf(page+rb, "TARG_SESS_STATE_ACTIVE\n");
0559 break;
0560 case TARG_SESS_STATE_LOGGED_IN:
0561 rb += sprintf(page+rb, "TARG_SESS_STATE_LOGGED_IN\n");
0562 break;
0563 case TARG_SESS_STATE_FAILED:
0564 rb += sprintf(page+rb, "TARG_SESS_STATE_FAILED\n");
0565 break;
0566 case TARG_SESS_STATE_IN_CONTINUE:
0567 rb += sprintf(page+rb, "TARG_SESS_STATE_IN_CONTINUE\n");
0568 break;
0569 default:
0570 rb += sprintf(page+rb, "ERROR: Unknown Session"
0571 " State!\n");
0572 break;
0573 }
0574
0575 rb += sprintf(page+rb, "---------------------[iSCSI Session"
0576 " Values]-----------------------\n");
0577 rb += sprintf(page+rb, " CmdSN/WR : CmdSN/WC : ExpCmdSN"
0578 " : MaxCmdSN : ITT : TTT\n");
0579 max_cmd_sn = (u32) atomic_read(&sess->max_cmd_sn);
0580 rb += sprintf(page+rb, " 0x%08x 0x%08x 0x%08x 0x%08x"
0581 " 0x%08x 0x%08x\n",
0582 sess->cmdsn_window,
0583 (max_cmd_sn - sess->exp_cmd_sn) + 1,
0584 sess->exp_cmd_sn, max_cmd_sn,
0585 sess->init_task_tag, sess->targ_xfer_tag);
0586 rb += sprintf(page+rb, "----------------------[iSCSI"
0587 " Connections]-------------------------\n");
0588
0589 spin_lock(&sess->conn_lock);
0590 list_for_each_entry(conn, &sess->sess_conn_list, conn_list) {
0591 rb += sprintf(page+rb, "CID: %hu Connection"
0592 " State: ", conn->cid);
0593 switch (conn->conn_state) {
0594 case TARG_CONN_STATE_FREE:
0595 rb += sprintf(page+rb,
0596 "TARG_CONN_STATE_FREE\n");
0597 break;
0598 case TARG_CONN_STATE_XPT_UP:
0599 rb += sprintf(page+rb,
0600 "TARG_CONN_STATE_XPT_UP\n");
0601 break;
0602 case TARG_CONN_STATE_IN_LOGIN:
0603 rb += sprintf(page+rb,
0604 "TARG_CONN_STATE_IN_LOGIN\n");
0605 break;
0606 case TARG_CONN_STATE_LOGGED_IN:
0607 rb += sprintf(page+rb,
0608 "TARG_CONN_STATE_LOGGED_IN\n");
0609 break;
0610 case TARG_CONN_STATE_IN_LOGOUT:
0611 rb += sprintf(page+rb,
0612 "TARG_CONN_STATE_IN_LOGOUT\n");
0613 break;
0614 case TARG_CONN_STATE_LOGOUT_REQUESTED:
0615 rb += sprintf(page+rb,
0616 "TARG_CONN_STATE_LOGOUT_REQUESTED\n");
0617 break;
0618 case TARG_CONN_STATE_CLEANUP_WAIT:
0619 rb += sprintf(page+rb,
0620 "TARG_CONN_STATE_CLEANUP_WAIT\n");
0621 break;
0622 default:
0623 rb += sprintf(page+rb,
0624 "ERROR: Unknown Connection State!\n");
0625 break;
0626 }
0627
0628 rb += sprintf(page+rb, " Address %pISc %s", &conn->login_sockaddr,
0629 (conn->network_transport == ISCSI_TCP) ?
0630 "TCP" : "SCTP");
0631 rb += sprintf(page+rb, " StatSN: 0x%08x\n",
0632 conn->stat_sn);
0633 }
0634 spin_unlock(&sess->conn_lock);
0635 }
0636 spin_unlock_bh(&se_nacl->nacl_sess_lock);
0637
0638 return rb;
0639 }
0640
0641 static ssize_t lio_target_nacl_cmdsn_depth_show(struct config_item *item,
0642 char *page)
0643 {
0644 return sprintf(page, "%u\n", acl_to_nacl(item)->queue_depth);
0645 }
0646
0647 static ssize_t lio_target_nacl_cmdsn_depth_store(struct config_item *item,
0648 const char *page, size_t count)
0649 {
0650 struct se_node_acl *se_nacl = acl_to_nacl(item);
0651 struct se_portal_group *se_tpg = se_nacl->se_tpg;
0652 struct iscsi_portal_group *tpg = to_iscsi_tpg(se_tpg);
0653 struct config_item *acl_ci, *tpg_ci, *wwn_ci;
0654 u32 cmdsn_depth = 0;
0655 int ret;
0656
0657 ret = kstrtou32(page, 0, &cmdsn_depth);
0658 if (ret)
0659 return ret;
0660 if (cmdsn_depth > TA_DEFAULT_CMDSN_DEPTH_MAX) {
0661 pr_err("Passed cmdsn_depth: %u exceeds"
0662 " TA_DEFAULT_CMDSN_DEPTH_MAX: %u\n", cmdsn_depth,
0663 TA_DEFAULT_CMDSN_DEPTH_MAX);
0664 return -EINVAL;
0665 }
0666 acl_ci = &se_nacl->acl_group.cg_item;
0667 if (!acl_ci) {
0668 pr_err("Unable to locatel acl_ci\n");
0669 return -EINVAL;
0670 }
0671 tpg_ci = &acl_ci->ci_parent->ci_group->cg_item;
0672 if (!tpg_ci) {
0673 pr_err("Unable to locate tpg_ci\n");
0674 return -EINVAL;
0675 }
0676 wwn_ci = &tpg_ci->ci_group->cg_item;
0677 if (!wwn_ci) {
0678 pr_err("Unable to locate config_item wwn_ci\n");
0679 return -EINVAL;
0680 }
0681
0682 if (iscsit_get_tpg(tpg) < 0)
0683 return -EINVAL;
0684
0685 ret = core_tpg_set_initiator_node_queue_depth(se_nacl, cmdsn_depth);
0686
0687 pr_debug("LIO_Target_ConfigFS: %s/%s Set CmdSN Window: %u for"
0688 "InitiatorName: %s\n", config_item_name(wwn_ci),
0689 config_item_name(tpg_ci), cmdsn_depth,
0690 config_item_name(acl_ci));
0691
0692 iscsit_put_tpg(tpg);
0693 return (!ret) ? count : (ssize_t)ret;
0694 }
0695
0696 static ssize_t lio_target_nacl_tag_show(struct config_item *item, char *page)
0697 {
0698 return snprintf(page, PAGE_SIZE, "%s", acl_to_nacl(item)->acl_tag);
0699 }
0700
0701 static ssize_t lio_target_nacl_tag_store(struct config_item *item,
0702 const char *page, size_t count)
0703 {
0704 struct se_node_acl *se_nacl = acl_to_nacl(item);
0705 int ret;
0706
0707 ret = core_tpg_set_initiator_node_tag(se_nacl->se_tpg, se_nacl, page);
0708
0709 if (ret < 0)
0710 return ret;
0711 return count;
0712 }
0713
0714 CONFIGFS_ATTR_RO(lio_target_nacl_, info);
0715 CONFIGFS_ATTR(lio_target_nacl_, cmdsn_depth);
0716 CONFIGFS_ATTR(lio_target_nacl_, tag);
0717
0718 static struct configfs_attribute *lio_target_initiator_attrs[] = {
0719 &lio_target_nacl_attr_info,
0720 &lio_target_nacl_attr_cmdsn_depth,
0721 &lio_target_nacl_attr_tag,
0722 NULL,
0723 };
0724
0725 static int lio_target_init_nodeacl(struct se_node_acl *se_nacl,
0726 const char *name)
0727 {
0728 struct iscsi_node_acl *acl = to_iscsi_nacl(se_nacl);
0729
0730 config_group_init_type_name(&acl->node_stat_grps.iscsi_sess_stats_group,
0731 "iscsi_sess_stats", &iscsi_stat_sess_cit);
0732 configfs_add_default_group(&acl->node_stat_grps.iscsi_sess_stats_group,
0733 &se_nacl->acl_fabric_stat_group);
0734 return 0;
0735 }
0736
0737
0738
0739
0740
0741 #define DEF_TPG_ATTRIB(name) \
0742 \
0743 static ssize_t iscsi_tpg_attrib_##name##_show(struct config_item *item, \
0744 char *page) \
0745 { \
0746 struct se_portal_group *se_tpg = attrib_to_tpg(item); \
0747 struct iscsi_portal_group *tpg = to_iscsi_tpg(se_tpg); \
0748 ssize_t rb; \
0749 \
0750 if (iscsit_get_tpg(tpg) < 0) \
0751 return -EINVAL; \
0752 \
0753 rb = sprintf(page, "%u\n", tpg->tpg_attrib.name); \
0754 iscsit_put_tpg(tpg); \
0755 return rb; \
0756 } \
0757 \
0758 static ssize_t iscsi_tpg_attrib_##name##_store(struct config_item *item,\
0759 const char *page, size_t count) \
0760 { \
0761 struct se_portal_group *se_tpg = attrib_to_tpg(item); \
0762 struct iscsi_portal_group *tpg = to_iscsi_tpg(se_tpg); \
0763 u32 val; \
0764 int ret; \
0765 \
0766 if (iscsit_get_tpg(tpg) < 0) \
0767 return -EINVAL; \
0768 \
0769 ret = kstrtou32(page, 0, &val); \
0770 if (ret) \
0771 goto out; \
0772 ret = iscsit_ta_##name(tpg, val); \
0773 if (ret < 0) \
0774 goto out; \
0775 \
0776 iscsit_put_tpg(tpg); \
0777 return count; \
0778 out: \
0779 iscsit_put_tpg(tpg); \
0780 return ret; \
0781 } \
0782 CONFIGFS_ATTR(iscsi_tpg_attrib_, name)
0783
0784 DEF_TPG_ATTRIB(authentication);
0785 DEF_TPG_ATTRIB(login_timeout);
0786 DEF_TPG_ATTRIB(netif_timeout);
0787 DEF_TPG_ATTRIB(generate_node_acls);
0788 DEF_TPG_ATTRIB(default_cmdsn_depth);
0789 DEF_TPG_ATTRIB(cache_dynamic_acls);
0790 DEF_TPG_ATTRIB(demo_mode_write_protect);
0791 DEF_TPG_ATTRIB(prod_mode_write_protect);
0792 DEF_TPG_ATTRIB(demo_mode_discovery);
0793 DEF_TPG_ATTRIB(default_erl);
0794 DEF_TPG_ATTRIB(t10_pi);
0795 DEF_TPG_ATTRIB(fabric_prot_type);
0796 DEF_TPG_ATTRIB(tpg_enabled_sendtargets);
0797 DEF_TPG_ATTRIB(login_keys_workaround);
0798
0799 static struct configfs_attribute *lio_target_tpg_attrib_attrs[] = {
0800 &iscsi_tpg_attrib_attr_authentication,
0801 &iscsi_tpg_attrib_attr_login_timeout,
0802 &iscsi_tpg_attrib_attr_netif_timeout,
0803 &iscsi_tpg_attrib_attr_generate_node_acls,
0804 &iscsi_tpg_attrib_attr_default_cmdsn_depth,
0805 &iscsi_tpg_attrib_attr_cache_dynamic_acls,
0806 &iscsi_tpg_attrib_attr_demo_mode_write_protect,
0807 &iscsi_tpg_attrib_attr_prod_mode_write_protect,
0808 &iscsi_tpg_attrib_attr_demo_mode_discovery,
0809 &iscsi_tpg_attrib_attr_default_erl,
0810 &iscsi_tpg_attrib_attr_t10_pi,
0811 &iscsi_tpg_attrib_attr_fabric_prot_type,
0812 &iscsi_tpg_attrib_attr_tpg_enabled_sendtargets,
0813 &iscsi_tpg_attrib_attr_login_keys_workaround,
0814 NULL,
0815 };
0816
0817
0818
0819
0820
0821 #define __DEF_TPG_AUTH_STR(prefix, name, flags) \
0822 static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \
0823 char *page) \
0824 { \
0825 struct iscsi_portal_group *tpg = to_iscsi_tpg(se_tpg); \
0826 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
0827 \
0828 if (!capable(CAP_SYS_ADMIN)) \
0829 return -EPERM; \
0830 \
0831 return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \
0832 } \
0833 \
0834 static ssize_t __iscsi_##prefix##_##name##_store(struct se_portal_group *se_tpg,\
0835 const char *page, size_t count) \
0836 { \
0837 struct iscsi_portal_group *tpg = to_iscsi_tpg(se_tpg); \
0838 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
0839 \
0840 if (!capable(CAP_SYS_ADMIN)) \
0841 return -EPERM; \
0842 \
0843 snprintf(auth->name, sizeof(auth->name), "%s", page); \
0844 if (!(strncmp("NULL", auth->name, 4))) \
0845 auth->naf_flags &= ~flags; \
0846 else \
0847 auth->naf_flags |= flags; \
0848 \
0849 if ((auth->naf_flags & NAF_USERID_IN_SET) && \
0850 (auth->naf_flags & NAF_PASSWORD_IN_SET)) \
0851 auth->authenticate_target = 1; \
0852 else \
0853 auth->authenticate_target = 0; \
0854 \
0855 return count; \
0856 }
0857
0858 #define DEF_TPG_AUTH_STR(name, flags) \
0859 __DEF_TPG_AUTH_STR(tpg_auth, name, flags) \
0860 static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \
0861 char *page) \
0862 { \
0863 return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \
0864 } \
0865 \
0866 static ssize_t iscsi_tpg_auth_##name##_store(struct config_item *item, \
0867 const char *page, size_t count) \
0868 { \
0869 return __iscsi_tpg_auth_##name##_store(auth_to_tpg(item), page, count); \
0870 } \
0871 \
0872 CONFIGFS_ATTR(iscsi_tpg_auth_, name);
0873
0874
0875 DEF_TPG_AUTH_STR(userid, NAF_USERID_SET);
0876 DEF_TPG_AUTH_STR(password, NAF_PASSWORD_SET);
0877 DEF_TPG_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
0878 DEF_TPG_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
0879
0880 #define __DEF_TPG_AUTH_INT(prefix, name) \
0881 static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \
0882 char *page) \
0883 { \
0884 struct iscsi_portal_group *tpg = to_iscsi_tpg(se_tpg); \
0885 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
0886 \
0887 if (!capable(CAP_SYS_ADMIN)) \
0888 return -EPERM; \
0889 \
0890 return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \
0891 }
0892
0893 #define DEF_TPG_AUTH_INT(name) \
0894 __DEF_TPG_AUTH_INT(tpg_auth, name) \
0895 static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \
0896 char *page) \
0897 { \
0898 return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \
0899 } \
0900 CONFIGFS_ATTR_RO(iscsi_tpg_auth_, name);
0901
0902 DEF_TPG_AUTH_INT(authenticate_target);
0903
0904 static struct configfs_attribute *lio_target_tpg_auth_attrs[] = {
0905 &iscsi_tpg_auth_attr_userid,
0906 &iscsi_tpg_auth_attr_password,
0907 &iscsi_tpg_auth_attr_authenticate_target,
0908 &iscsi_tpg_auth_attr_userid_mutual,
0909 &iscsi_tpg_auth_attr_password_mutual,
0910 NULL,
0911 };
0912
0913
0914
0915
0916
0917 #define DEF_TPG_PARAM(name) \
0918 static ssize_t iscsi_tpg_param_##name##_show(struct config_item *item, \
0919 char *page) \
0920 { \
0921 struct se_portal_group *se_tpg = param_to_tpg(item); \
0922 struct iscsi_portal_group *tpg = to_iscsi_tpg(se_tpg); \
0923 struct iscsi_param *param; \
0924 ssize_t rb; \
0925 \
0926 if (iscsit_get_tpg(tpg) < 0) \
0927 return -EINVAL; \
0928 \
0929 param = iscsi_find_param_from_key(__stringify(name), \
0930 tpg->param_list); \
0931 if (!param) { \
0932 iscsit_put_tpg(tpg); \
0933 return -EINVAL; \
0934 } \
0935 rb = snprintf(page, PAGE_SIZE, "%s\n", param->value); \
0936 \
0937 iscsit_put_tpg(tpg); \
0938 return rb; \
0939 } \
0940 static ssize_t iscsi_tpg_param_##name##_store(struct config_item *item, \
0941 const char *page, size_t count) \
0942 { \
0943 struct se_portal_group *se_tpg = param_to_tpg(item); \
0944 struct iscsi_portal_group *tpg = to_iscsi_tpg(se_tpg); \
0945 char *buf; \
0946 int ret, len; \
0947 \
0948 buf = kzalloc(PAGE_SIZE, GFP_KERNEL); \
0949 if (!buf) \
0950 return -ENOMEM; \
0951 len = snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page); \
0952 if (isspace(buf[len-1])) \
0953 buf[len-1] = '\0'; \
0954 \
0955 if (iscsit_get_tpg(tpg) < 0) { \
0956 kfree(buf); \
0957 return -EINVAL; \
0958 } \
0959 \
0960 ret = iscsi_change_param_value(buf, tpg->param_list, 1); \
0961 if (ret < 0) \
0962 goto out; \
0963 \
0964 kfree(buf); \
0965 iscsit_put_tpg(tpg); \
0966 return count; \
0967 out: \
0968 kfree(buf); \
0969 iscsit_put_tpg(tpg); \
0970 return -EINVAL; \
0971 } \
0972 CONFIGFS_ATTR(iscsi_tpg_param_, name)
0973
0974 DEF_TPG_PARAM(AuthMethod);
0975 DEF_TPG_PARAM(HeaderDigest);
0976 DEF_TPG_PARAM(DataDigest);
0977 DEF_TPG_PARAM(MaxConnections);
0978 DEF_TPG_PARAM(TargetAlias);
0979 DEF_TPG_PARAM(InitialR2T);
0980 DEF_TPG_PARAM(ImmediateData);
0981 DEF_TPG_PARAM(MaxRecvDataSegmentLength);
0982 DEF_TPG_PARAM(MaxXmitDataSegmentLength);
0983 DEF_TPG_PARAM(MaxBurstLength);
0984 DEF_TPG_PARAM(FirstBurstLength);
0985 DEF_TPG_PARAM(DefaultTime2Wait);
0986 DEF_TPG_PARAM(DefaultTime2Retain);
0987 DEF_TPG_PARAM(MaxOutstandingR2T);
0988 DEF_TPG_PARAM(DataPDUInOrder);
0989 DEF_TPG_PARAM(DataSequenceInOrder);
0990 DEF_TPG_PARAM(ErrorRecoveryLevel);
0991 DEF_TPG_PARAM(IFMarker);
0992 DEF_TPG_PARAM(OFMarker);
0993 DEF_TPG_PARAM(IFMarkInt);
0994 DEF_TPG_PARAM(OFMarkInt);
0995
0996 static struct configfs_attribute *lio_target_tpg_param_attrs[] = {
0997 &iscsi_tpg_param_attr_AuthMethod,
0998 &iscsi_tpg_param_attr_HeaderDigest,
0999 &iscsi_tpg_param_attr_DataDigest,
1000 &iscsi_tpg_param_attr_MaxConnections,
1001 &iscsi_tpg_param_attr_TargetAlias,
1002 &iscsi_tpg_param_attr_InitialR2T,
1003 &iscsi_tpg_param_attr_ImmediateData,
1004 &iscsi_tpg_param_attr_MaxRecvDataSegmentLength,
1005 &iscsi_tpg_param_attr_MaxXmitDataSegmentLength,
1006 &iscsi_tpg_param_attr_MaxBurstLength,
1007 &iscsi_tpg_param_attr_FirstBurstLength,
1008 &iscsi_tpg_param_attr_DefaultTime2Wait,
1009 &iscsi_tpg_param_attr_DefaultTime2Retain,
1010 &iscsi_tpg_param_attr_MaxOutstandingR2T,
1011 &iscsi_tpg_param_attr_DataPDUInOrder,
1012 &iscsi_tpg_param_attr_DataSequenceInOrder,
1013 &iscsi_tpg_param_attr_ErrorRecoveryLevel,
1014 &iscsi_tpg_param_attr_IFMarker,
1015 &iscsi_tpg_param_attr_OFMarker,
1016 &iscsi_tpg_param_attr_IFMarkInt,
1017 &iscsi_tpg_param_attr_OFMarkInt,
1018 NULL,
1019 };
1020
1021
1022
1023
1024
1025 static ssize_t lio_target_tpg_dynamic_sessions_show(struct config_item *item,
1026 char *page)
1027 {
1028 return target_show_dynamic_sessions(to_tpg(item), page);
1029 }
1030
1031 CONFIGFS_ATTR_RO(lio_target_tpg_, dynamic_sessions);
1032
1033 static struct configfs_attribute *lio_target_tpg_attrs[] = {
1034 &lio_target_tpg_attr_dynamic_sessions,
1035 NULL,
1036 };
1037
1038
1039
1040
1041
1042 static struct se_portal_group *lio_target_tiqn_addtpg(struct se_wwn *wwn,
1043 const char *name)
1044 {
1045 struct iscsi_portal_group *tpg;
1046 struct iscsi_tiqn *tiqn;
1047 char *tpgt_str;
1048 int ret;
1049 u16 tpgt;
1050
1051 tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1052
1053
1054
1055
1056 tpgt_str = strstr(name, "tpgt_");
1057 if (!tpgt_str) {
1058 pr_err("Unable to locate \"tpgt_#\" directory"
1059 " group\n");
1060 return NULL;
1061 }
1062 tpgt_str += 5;
1063 ret = kstrtou16(tpgt_str, 0, &tpgt);
1064 if (ret)
1065 return NULL;
1066
1067 tpg = iscsit_alloc_portal_group(tiqn, tpgt);
1068 if (!tpg)
1069 return NULL;
1070
1071 ret = core_tpg_register(wwn, &tpg->tpg_se_tpg, SCSI_PROTOCOL_ISCSI);
1072 if (ret < 0)
1073 goto free_out;
1074
1075 ret = iscsit_tpg_add_portal_group(tiqn, tpg);
1076 if (ret != 0)
1077 goto out;
1078
1079 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
1080 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated TPG: %s\n",
1081 name);
1082 return &tpg->tpg_se_tpg;
1083 out:
1084 core_tpg_deregister(&tpg->tpg_se_tpg);
1085 free_out:
1086 kfree(tpg);
1087 return NULL;
1088 }
1089
1090 static int lio_target_tiqn_enabletpg(struct se_portal_group *se_tpg,
1091 bool enable)
1092 {
1093 struct iscsi_portal_group *tpg = to_iscsi_tpg(se_tpg);
1094 int ret;
1095
1096 ret = iscsit_get_tpg(tpg);
1097 if (ret < 0)
1098 return -EINVAL;
1099
1100 if (enable) {
1101 ret = iscsit_tpg_enable_portal_group(tpg);
1102 if (ret < 0)
1103 goto out;
1104 } else {
1105
1106
1107
1108 ret = iscsit_tpg_disable_portal_group(tpg, 1);
1109 if (ret < 0)
1110 goto out;
1111 }
1112
1113 iscsit_put_tpg(tpg);
1114 return 0;
1115 out:
1116 iscsit_put_tpg(tpg);
1117 return -EINVAL;
1118 }
1119
1120 static void lio_target_tiqn_deltpg(struct se_portal_group *se_tpg)
1121 {
1122 struct iscsi_portal_group *tpg;
1123 struct iscsi_tiqn *tiqn;
1124
1125 tpg = to_iscsi_tpg(se_tpg);
1126 tiqn = tpg->tpg_tiqn;
1127
1128
1129
1130 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> Releasing TPG\n");
1131 iscsit_tpg_del_portal_group(tiqn, tpg, 1);
1132 }
1133
1134
1135
1136
1137
1138 static ssize_t lio_target_wwn_lio_version_show(struct config_item *item,
1139 char *page)
1140 {
1141 return sprintf(page, "Datera Inc. iSCSI Target "ISCSIT_VERSION"\n");
1142 }
1143
1144 CONFIGFS_ATTR_RO(lio_target_wwn_, lio_version);
1145
1146 static ssize_t lio_target_wwn_cpus_allowed_list_show(
1147 struct config_item *item, char *page)
1148 {
1149 return sprintf(page, "%*pbl\n",
1150 cpumask_pr_args(iscsit_global->allowed_cpumask));
1151 }
1152
1153 static ssize_t lio_target_wwn_cpus_allowed_list_store(
1154 struct config_item *item, const char *page, size_t count)
1155 {
1156 int ret = -ENOMEM;
1157 char *orig;
1158 cpumask_var_t new_allowed_cpumask;
1159
1160 if (!zalloc_cpumask_var(&new_allowed_cpumask, GFP_KERNEL))
1161 goto out;
1162
1163 orig = kstrdup(page, GFP_KERNEL);
1164 if (!orig)
1165 goto out_free_cpumask;
1166
1167 ret = cpulist_parse(orig, new_allowed_cpumask);
1168 if (!ret)
1169 cpumask_copy(iscsit_global->allowed_cpumask,
1170 new_allowed_cpumask);
1171
1172 kfree(orig);
1173 out_free_cpumask:
1174 free_cpumask_var(new_allowed_cpumask);
1175 out:
1176 return ret ? ret : count;
1177 }
1178
1179 CONFIGFS_ATTR(lio_target_wwn_, cpus_allowed_list);
1180
1181 static struct configfs_attribute *lio_target_wwn_attrs[] = {
1182 &lio_target_wwn_attr_lio_version,
1183 &lio_target_wwn_attr_cpus_allowed_list,
1184 NULL,
1185 };
1186
1187 static struct se_wwn *lio_target_call_coreaddtiqn(
1188 struct target_fabric_configfs *tf,
1189 struct config_group *group,
1190 const char *name)
1191 {
1192 struct iscsi_tiqn *tiqn;
1193
1194 tiqn = iscsit_add_tiqn((unsigned char *)name);
1195 if (IS_ERR(tiqn))
1196 return ERR_CAST(tiqn);
1197
1198 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
1199 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated Node:"
1200 " %s\n", name);
1201 return &tiqn->tiqn_wwn;
1202 }
1203
1204 static void lio_target_add_wwn_groups(struct se_wwn *wwn)
1205 {
1206 struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1207
1208 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_instance_group,
1209 "iscsi_instance", &iscsi_stat_instance_cit);
1210 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_instance_group,
1211 &tiqn->tiqn_wwn.fabric_stat_group);
1212
1213 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_sess_err_group,
1214 "iscsi_sess_err", &iscsi_stat_sess_err_cit);
1215 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_sess_err_group,
1216 &tiqn->tiqn_wwn.fabric_stat_group);
1217
1218 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group,
1219 "iscsi_tgt_attr", &iscsi_stat_tgt_attr_cit);
1220 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group,
1221 &tiqn->tiqn_wwn.fabric_stat_group);
1222
1223 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_login_stats_group,
1224 "iscsi_login_stats", &iscsi_stat_login_cit);
1225 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_login_stats_group,
1226 &tiqn->tiqn_wwn.fabric_stat_group);
1227
1228 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group,
1229 "iscsi_logout_stats", &iscsi_stat_logout_cit);
1230 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group,
1231 &tiqn->tiqn_wwn.fabric_stat_group);
1232 }
1233
1234 static void lio_target_call_coredeltiqn(
1235 struct se_wwn *wwn)
1236 {
1237 struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1238
1239 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s\n",
1240 tiqn->tiqn);
1241 iscsit_del_tiqn(tiqn);
1242 }
1243
1244
1245
1246
1247
1248 #define DEF_DISC_AUTH_STR(name, flags) \
1249 __DEF_NACL_AUTH_STR(disc, name, flags) \
1250 static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
1251 { \
1252 return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl,\
1253 page); \
1254 } \
1255 static ssize_t iscsi_disc_##name##_store(struct config_item *item, \
1256 const char *page, size_t count) \
1257 { \
1258 return __iscsi_disc_##name##_store(&iscsit_global->discovery_acl, \
1259 page, count); \
1260 \
1261 } \
1262 CONFIGFS_ATTR(iscsi_disc_, name)
1263
1264 DEF_DISC_AUTH_STR(userid, NAF_USERID_SET);
1265 DEF_DISC_AUTH_STR(password, NAF_PASSWORD_SET);
1266 DEF_DISC_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
1267 DEF_DISC_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
1268
1269 #define DEF_DISC_AUTH_INT(name) \
1270 __DEF_NACL_AUTH_INT(disc, name) \
1271 static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
1272 { \
1273 return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl, \
1274 page); \
1275 } \
1276 CONFIGFS_ATTR_RO(iscsi_disc_, name)
1277
1278 DEF_DISC_AUTH_INT(authenticate_target);
1279
1280
1281 static ssize_t iscsi_disc_enforce_discovery_auth_show(struct config_item *item,
1282 char *page)
1283 {
1284 struct iscsi_node_auth *discovery_auth = &iscsit_global->discovery_acl.node_auth;
1285
1286 return sprintf(page, "%d\n", discovery_auth->enforce_discovery_auth);
1287 }
1288
1289 static ssize_t iscsi_disc_enforce_discovery_auth_store(struct config_item *item,
1290 const char *page, size_t count)
1291 {
1292 struct iscsi_param *param;
1293 struct iscsi_portal_group *discovery_tpg = iscsit_global->discovery_tpg;
1294 u32 op;
1295 int err;
1296
1297 err = kstrtou32(page, 0, &op);
1298 if (err)
1299 return -EINVAL;
1300 if ((op != 1) && (op != 0)) {
1301 pr_err("Illegal value for enforce_discovery_auth:"
1302 " %u\n", op);
1303 return -EINVAL;
1304 }
1305
1306 if (!discovery_tpg) {
1307 pr_err("iscsit_global->discovery_tpg is NULL\n");
1308 return -EINVAL;
1309 }
1310
1311 param = iscsi_find_param_from_key(AUTHMETHOD,
1312 discovery_tpg->param_list);
1313 if (!param)
1314 return -EINVAL;
1315
1316 if (op) {
1317
1318
1319
1320 if (iscsi_update_param_value(param, CHAP) < 0)
1321 return -EINVAL;
1322
1323 discovery_tpg->tpg_attrib.authentication = 1;
1324 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 1;
1325 pr_debug("LIO-CORE[0] Successfully enabled"
1326 " authentication enforcement for iSCSI"
1327 " Discovery TPG\n");
1328 } else {
1329
1330
1331
1332 if (iscsi_update_param_value(param, "CHAP,None") < 0)
1333 return -EINVAL;
1334
1335 discovery_tpg->tpg_attrib.authentication = 0;
1336 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 0;
1337 pr_debug("LIO-CORE[0] Successfully disabled"
1338 " authentication enforcement for iSCSI"
1339 " Discovery TPG\n");
1340 }
1341
1342 return count;
1343 }
1344
1345 CONFIGFS_ATTR(iscsi_disc_, enforce_discovery_auth);
1346
1347 static struct configfs_attribute *lio_target_discovery_auth_attrs[] = {
1348 &iscsi_disc_attr_userid,
1349 &iscsi_disc_attr_password,
1350 &iscsi_disc_attr_authenticate_target,
1351 &iscsi_disc_attr_userid_mutual,
1352 &iscsi_disc_attr_password_mutual,
1353 &iscsi_disc_attr_enforce_discovery_auth,
1354 NULL,
1355 };
1356
1357
1358
1359
1360
1361 static int iscsi_get_cmd_state(struct se_cmd *se_cmd)
1362 {
1363 struct iscsit_cmd *cmd = container_of(se_cmd, struct iscsit_cmd, se_cmd);
1364
1365 return cmd->i_state;
1366 }
1367
1368 static u32 lio_sess_get_index(struct se_session *se_sess)
1369 {
1370 struct iscsit_session *sess = se_sess->fabric_sess_ptr;
1371
1372 return sess->session_index;
1373 }
1374
1375 static u32 lio_sess_get_initiator_sid(
1376 struct se_session *se_sess,
1377 unsigned char *buf,
1378 u32 size)
1379 {
1380 struct iscsit_session *sess = se_sess->fabric_sess_ptr;
1381
1382
1383
1384 return snprintf(buf, size, "%6phN", sess->isid);
1385 }
1386
1387 static int lio_queue_data_in(struct se_cmd *se_cmd)
1388 {
1389 struct iscsit_cmd *cmd = container_of(se_cmd, struct iscsit_cmd, se_cmd);
1390 struct iscsit_conn *conn = cmd->conn;
1391
1392 cmd->i_state = ISTATE_SEND_DATAIN;
1393 return conn->conn_transport->iscsit_queue_data_in(conn, cmd);
1394 }
1395
1396 static int lio_write_pending(struct se_cmd *se_cmd)
1397 {
1398 struct iscsit_cmd *cmd = container_of(se_cmd, struct iscsit_cmd, se_cmd);
1399 struct iscsit_conn *conn = cmd->conn;
1400
1401 if (!cmd->immediate_data && !cmd->unsolicited_data)
1402 return conn->conn_transport->iscsit_get_dataout(conn, cmd, false);
1403
1404 return 0;
1405 }
1406
1407 static int lio_queue_status(struct se_cmd *se_cmd)
1408 {
1409 struct iscsit_cmd *cmd = container_of(se_cmd, struct iscsit_cmd, se_cmd);
1410 struct iscsit_conn *conn = cmd->conn;
1411
1412 cmd->i_state = ISTATE_SEND_STATUS;
1413
1414 if (cmd->se_cmd.scsi_status || cmd->sense_reason) {
1415 return iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state);
1416 }
1417 return conn->conn_transport->iscsit_queue_status(conn, cmd);
1418 }
1419
1420 static void lio_queue_tm_rsp(struct se_cmd *se_cmd)
1421 {
1422 struct iscsit_cmd *cmd = container_of(se_cmd, struct iscsit_cmd, se_cmd);
1423
1424 cmd->i_state = ISTATE_SEND_TASKMGTRSP;
1425 iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
1426 }
1427
1428 static void lio_aborted_task(struct se_cmd *se_cmd)
1429 {
1430 struct iscsit_cmd *cmd = container_of(se_cmd, struct iscsit_cmd, se_cmd);
1431
1432 cmd->conn->conn_transport->iscsit_aborted_task(cmd->conn, cmd);
1433 }
1434
1435 static char *lio_tpg_get_endpoint_wwn(struct se_portal_group *se_tpg)
1436 {
1437 return to_iscsi_tpg(se_tpg)->tpg_tiqn->tiqn;
1438 }
1439
1440 static u16 lio_tpg_get_tag(struct se_portal_group *se_tpg)
1441 {
1442 return to_iscsi_tpg(se_tpg)->tpgt;
1443 }
1444
1445 static u32 lio_tpg_get_default_depth(struct se_portal_group *se_tpg)
1446 {
1447 return to_iscsi_tpg(se_tpg)->tpg_attrib.default_cmdsn_depth;
1448 }
1449
1450 static int lio_tpg_check_demo_mode(struct se_portal_group *se_tpg)
1451 {
1452 return to_iscsi_tpg(se_tpg)->tpg_attrib.generate_node_acls;
1453 }
1454
1455 static int lio_tpg_check_demo_mode_cache(struct se_portal_group *se_tpg)
1456 {
1457 return to_iscsi_tpg(se_tpg)->tpg_attrib.cache_dynamic_acls;
1458 }
1459
1460 static int lio_tpg_check_demo_mode_write_protect(
1461 struct se_portal_group *se_tpg)
1462 {
1463 return to_iscsi_tpg(se_tpg)->tpg_attrib.demo_mode_write_protect;
1464 }
1465
1466 static int lio_tpg_check_prod_mode_write_protect(
1467 struct se_portal_group *se_tpg)
1468 {
1469 return to_iscsi_tpg(se_tpg)->tpg_attrib.prod_mode_write_protect;
1470 }
1471
1472 static int lio_tpg_check_prot_fabric_only(
1473 struct se_portal_group *se_tpg)
1474 {
1475
1476
1477
1478
1479 if (!to_iscsi_tpg(se_tpg)->tpg_attrib.t10_pi)
1480 return 0;
1481 return to_iscsi_tpg(se_tpg)->tpg_attrib.fabric_prot_type;
1482 }
1483
1484
1485
1486
1487
1488 static void lio_tpg_close_session(struct se_session *se_sess)
1489 {
1490 struct iscsit_session *sess = se_sess->fabric_sess_ptr;
1491 struct se_portal_group *se_tpg = &sess->tpg->tpg_se_tpg;
1492
1493 spin_lock_bh(&se_tpg->session_lock);
1494 spin_lock(&sess->conn_lock);
1495 if (atomic_read(&sess->session_fall_back_to_erl0) ||
1496 atomic_read(&sess->session_logout) ||
1497 atomic_read(&sess->session_close) ||
1498 (sess->time2retain_timer_flags & ISCSI_TF_EXPIRED)) {
1499 spin_unlock(&sess->conn_lock);
1500 spin_unlock_bh(&se_tpg->session_lock);
1501 return;
1502 }
1503 iscsit_inc_session_usage_count(sess);
1504 atomic_set(&sess->session_reinstatement, 1);
1505 atomic_set(&sess->session_fall_back_to_erl0, 1);
1506 atomic_set(&sess->session_close, 1);
1507 spin_unlock(&sess->conn_lock);
1508
1509 iscsit_stop_time2retain_timer(sess);
1510 spin_unlock_bh(&se_tpg->session_lock);
1511
1512 iscsit_stop_session(sess, 1, 1);
1513 iscsit_dec_session_usage_count(sess);
1514 }
1515
1516 static u32 lio_tpg_get_inst_index(struct se_portal_group *se_tpg)
1517 {
1518 return to_iscsi_tpg(se_tpg)->tpg_tiqn->tiqn_index;
1519 }
1520
1521 static void lio_set_default_node_attributes(struct se_node_acl *se_acl)
1522 {
1523 struct iscsi_node_acl *acl = to_iscsi_nacl(se_acl);
1524 struct se_portal_group *se_tpg = se_acl->se_tpg;
1525 struct iscsi_portal_group *tpg = to_iscsi_tpg(se_tpg);
1526
1527 acl->node_attrib.nacl = acl;
1528 iscsit_set_default_node_attribues(acl, tpg);
1529 }
1530
1531 static int lio_check_stop_free(struct se_cmd *se_cmd)
1532 {
1533 return target_put_sess_cmd(se_cmd);
1534 }
1535
1536 static void lio_release_cmd(struct se_cmd *se_cmd)
1537 {
1538 struct iscsit_cmd *cmd = container_of(se_cmd, struct iscsit_cmd, se_cmd);
1539
1540 pr_debug("Entering lio_release_cmd for se_cmd: %p\n", se_cmd);
1541 iscsit_release_cmd(cmd);
1542 }
1543
1544 const struct target_core_fabric_ops iscsi_ops = {
1545 .module = THIS_MODULE,
1546 .fabric_alias = "iscsi",
1547 .fabric_name = "iSCSI",
1548 .node_acl_size = sizeof(struct iscsi_node_acl),
1549 .tpg_get_wwn = lio_tpg_get_endpoint_wwn,
1550 .tpg_get_tag = lio_tpg_get_tag,
1551 .tpg_get_default_depth = lio_tpg_get_default_depth,
1552 .tpg_check_demo_mode = lio_tpg_check_demo_mode,
1553 .tpg_check_demo_mode_cache = lio_tpg_check_demo_mode_cache,
1554 .tpg_check_demo_mode_write_protect =
1555 lio_tpg_check_demo_mode_write_protect,
1556 .tpg_check_prod_mode_write_protect =
1557 lio_tpg_check_prod_mode_write_protect,
1558 .tpg_check_prot_fabric_only = &lio_tpg_check_prot_fabric_only,
1559 .tpg_get_inst_index = lio_tpg_get_inst_index,
1560 .check_stop_free = lio_check_stop_free,
1561 .release_cmd = lio_release_cmd,
1562 .close_session = lio_tpg_close_session,
1563 .sess_get_index = lio_sess_get_index,
1564 .sess_get_initiator_sid = lio_sess_get_initiator_sid,
1565 .write_pending = lio_write_pending,
1566 .set_default_node_attributes = lio_set_default_node_attributes,
1567 .get_cmd_state = iscsi_get_cmd_state,
1568 .queue_data_in = lio_queue_data_in,
1569 .queue_status = lio_queue_status,
1570 .queue_tm_rsp = lio_queue_tm_rsp,
1571 .aborted_task = lio_aborted_task,
1572 .fabric_make_wwn = lio_target_call_coreaddtiqn,
1573 .fabric_drop_wwn = lio_target_call_coredeltiqn,
1574 .add_wwn_groups = lio_target_add_wwn_groups,
1575 .fabric_make_tpg = lio_target_tiqn_addtpg,
1576 .fabric_enable_tpg = lio_target_tiqn_enabletpg,
1577 .fabric_drop_tpg = lio_target_tiqn_deltpg,
1578 .fabric_make_np = lio_target_call_addnptotpg,
1579 .fabric_drop_np = lio_target_call_delnpfromtpg,
1580 .fabric_init_nodeacl = lio_target_init_nodeacl,
1581
1582 .tfc_discovery_attrs = lio_target_discovery_auth_attrs,
1583 .tfc_wwn_attrs = lio_target_wwn_attrs,
1584 .tfc_tpg_base_attrs = lio_target_tpg_attrs,
1585 .tfc_tpg_attrib_attrs = lio_target_tpg_attrib_attrs,
1586 .tfc_tpg_auth_attrs = lio_target_tpg_auth_attrs,
1587 .tfc_tpg_param_attrs = lio_target_tpg_param_attrs,
1588 .tfc_tpg_np_base_attrs = lio_target_portal_attrs,
1589 .tfc_tpg_nacl_base_attrs = lio_target_initiator_attrs,
1590 .tfc_tpg_nacl_attrib_attrs = lio_target_nacl_attrib_attrs,
1591 .tfc_tpg_nacl_auth_attrs = lio_target_nacl_auth_attrs,
1592 .tfc_tpg_nacl_param_attrs = lio_target_nacl_param_attrs,
1593
1594 .write_pending_must_be_called = true,
1595 };