iscsi_target_configfs.c 47.1 KB
Newer Older
1 2 3 4
/*******************************************************************************
 * This file contains the configfs implementation for iSCSI Target mode
 * from the LIO-Target Project.
 *
5
 * (c) Copyright 2007-2013 Datera, Inc.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 ****************************************************************************/

#include <linux/configfs.h>
21
#include <linux/ctype.h>
22
#include <linux/export.h>
23
#include <linux/inet.h>
24
#include <target/target_core_base.h>
25
#include <target/target_core_fabric.h>
26
#include <target/iscsi/iscsi_transport.h>
27

28
#include <target/iscsi/iscsi_target_core.h>
29 30 31 32 33 34 35
#include "iscsi_target_parameters.h"
#include "iscsi_target_device.h"
#include "iscsi_target_erl0.h"
#include "iscsi_target_nodeattrib.h"
#include "iscsi_target_tpg.h"
#include "iscsi_target_util.h"
#include "iscsi_target.h"
36
#include <target/iscsi/iscsi_target_stat.h>
37 38 39 40


/* Start items for lio_target_portal_cit */

41 42 43 44 45 46
static inline struct iscsi_tpg_np *to_iscsi_tpg_np(struct config_item *item)
{
	return container_of(to_tpg_np(item), struct iscsi_tpg_np, se_tpg_np);
}

static ssize_t lio_target_np_sctp_show(struct config_item *item, char *page)
47
{
48
	struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
49 50 51 52 53 54 55 56 57 58 59 60
	struct iscsi_tpg_np *tpg_np_sctp;
	ssize_t rb;

	tpg_np_sctp = iscsit_tpg_locate_child_np(tpg_np, ISCSI_SCTP_TCP);
	if (tpg_np_sctp)
		rb = sprintf(page, "1\n");
	else
		rb = sprintf(page, "0\n");

	return rb;
}

61 62
static ssize_t lio_target_np_sctp_store(struct config_item *item,
		const char *page, size_t count)
63
{
64
	struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
65 66 67 68 69 70
	struct iscsi_np *np;
	struct iscsi_portal_group *tpg;
	struct iscsi_tpg_np *tpg_np_sctp = NULL;
	u32 op;
	int ret;

71 72 73
	ret = kstrtou32(page, 0, &op);
	if (ret)
		return ret;
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
	if ((op != 1) && (op != 0)) {
		pr_err("Illegal value for tpg_enable: %u\n", op);
		return -EINVAL;
	}
	np = tpg_np->tpg_np;
	if (!np) {
		pr_err("Unable to locate struct iscsi_np from"
				" struct iscsi_tpg_np\n");
		return -EINVAL;
	}

	tpg = tpg_np->tpg;
	if (iscsit_get_tpg(tpg) < 0)
		return -EINVAL;

	if (op) {
		/*
		 * Use existing np->np_sockaddr for SCTP network portal reference
		 */
		tpg_np_sctp = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr,
94
					tpg_np, ISCSI_SCTP_TCP);
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
		if (!tpg_np_sctp || IS_ERR(tpg_np_sctp))
			goto out;
	} else {
		tpg_np_sctp = iscsit_tpg_locate_child_np(tpg_np, ISCSI_SCTP_TCP);
		if (!tpg_np_sctp)
			goto out;

		ret = iscsit_tpg_del_network_portal(tpg, tpg_np_sctp);
		if (ret < 0)
			goto out;
	}

	iscsit_put_tpg(tpg);
	return count;
out:
	iscsit_put_tpg(tpg);
	return -EINVAL;
}

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 118 119 120 121 122 123 124 125 126 127 128
	struct iscsi_tpg_np *tpg_np_iser;
	ssize_t rb;

	tpg_np_iser = iscsit_tpg_locate_child_np(tpg_np, ISCSI_INFINIBAND);
	if (tpg_np_iser)
		rb = sprintf(page, "1\n");
	else
		rb = sprintf(page, "0\n");

	return rb;
}

129 130
static ssize_t lio_target_np_iser_store(struct config_item *item,
		const char *page, size_t count)
131
{
132
	struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
133 134 135 136 137
	struct iscsi_np *np;
	struct iscsi_portal_group *tpg;
	struct iscsi_tpg_np *tpg_np_iser = NULL;
	char *endptr;
	u32 op;
138
	int rc = 0;
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156

	op = simple_strtoul(page, &endptr, 0);
	if ((op != 1) && (op != 0)) {
		pr_err("Illegal value for tpg_enable: %u\n", op);
		return -EINVAL;
	}
	np = tpg_np->tpg_np;
	if (!np) {
		pr_err("Unable to locate struct iscsi_np from"
				" struct iscsi_tpg_np\n");
		return -EINVAL;
	}

	tpg = tpg_np->tpg;
	if (iscsit_get_tpg(tpg) < 0)
		return -EINVAL;

	if (op) {
157 158
		rc = request_module("ib_isert");
		if (rc != 0) {
159
			pr_warn("Unable to request_module for ib_isert\n");
160 161
			rc = 0;
		}
162 163

		tpg_np_iser = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr,
164
				tpg_np, ISCSI_INFINIBAND);
165 166
		if (IS_ERR(tpg_np_iser)) {
			rc = PTR_ERR(tpg_np_iser);
167
			goto out;
168
		}
169 170
	} else {
		tpg_np_iser = iscsit_tpg_locate_child_np(tpg_np, ISCSI_INFINIBAND);
171 172 173 174 175
		if (tpg_np_iser) {
			rc = iscsit_tpg_del_network_portal(tpg, tpg_np_iser);
			if (rc < 0)
				goto out;
		}
176 177 178 179 180 181
	}

	iscsit_put_tpg(tpg);
	return count;
out:
	iscsit_put_tpg(tpg);
182
	return rc;
183 184
}

185 186
CONFIGFS_ATTR(lio_target_np_, sctp);
CONFIGFS_ATTR(lio_target_np_, iser);
187

188
static struct configfs_attribute *lio_target_portal_attrs[] = {
189 190
	&lio_target_np_attr_sctp,
	&lio_target_np_attr_iser,
191 192 193 194 195 196 197 198 199
	NULL,
};

/* Stop items for lio_target_portal_cit */

/* Start items for lio_target_np_cit */

#define MAX_PORTAL_LEN		256

200
static struct se_tpg_np *lio_target_call_addnptotpg(
201 202 203 204 205 206 207
	struct se_portal_group *se_tpg,
	struct config_group *group,
	const char *name)
{
	struct iscsi_portal_group *tpg;
	struct iscsi_tpg_np *tpg_np;
	char *str, *str2, *ip_str, *port_str;
208
	struct sockaddr_storage sockaddr;
209 210 211 212 213 214 215 216 217 218 219 220
	struct sockaddr_in *sock_in;
	struct sockaddr_in6 *sock_in6;
	unsigned long port;
	int ret;
	char buf[MAX_PORTAL_LEN + 1];

	if (strlen(name) > MAX_PORTAL_LEN) {
		pr_err("strlen(name): %d exceeds MAX_PORTAL_LEN: %d\n",
			(int)strlen(name), MAX_PORTAL_LEN);
		return ERR_PTR(-EOVERFLOW);
	}
	memset(buf, 0, MAX_PORTAL_LEN + 1);
221
	snprintf(buf, MAX_PORTAL_LEN + 1, "%s", name);
222

223
	memset(&sockaddr, 0, sizeof(struct sockaddr_storage));
224 225 226 227 228 229 230 231 232 233 234 235

	str = strstr(buf, "[");
	if (str) {
		const char *end;

		str2 = strstr(str, "]");
		if (!str2) {
			pr_err("Unable to locate trailing \"]\""
				" in IPv6 iSCSI network portal address\n");
			return ERR_PTR(-EINVAL);
		}
		str++; /* Skip over leading "[" */
236 237
		*str2 = '\0'; /* Terminate the unbracketed IPv6 address */
		str2++; /* Skip over the \0 */
238 239 240 241 242 243 244 245 246
		port_str = strstr(str2, ":");
		if (!port_str) {
			pr_err("Unable to locate \":port\""
				" in IPv6 iSCSI network portal address\n");
			return ERR_PTR(-EINVAL);
		}
		*port_str = '\0'; /* Terminate string for IP */
		port_str++; /* Skip over ":" */

247
		ret = kstrtoul(port_str, 0, &port);
248
		if (ret < 0) {
249
			pr_err("kstrtoul() failed for port_str: %d\n", ret);
250 251 252 253 254
			return ERR_PTR(ret);
		}
		sock_in6 = (struct sockaddr_in6 *)&sockaddr;
		sock_in6->sin6_family = AF_INET6;
		sock_in6->sin6_port = htons((unsigned short)port);
255
		ret = in6_pton(str, -1,
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
				(void *)&sock_in6->sin6_addr.in6_u, -1, &end);
		if (ret <= 0) {
			pr_err("in6_pton returned: %d\n", ret);
			return ERR_PTR(-EINVAL);
		}
	} else {
		str = ip_str = &buf[0];
		port_str = strstr(ip_str, ":");
		if (!port_str) {
			pr_err("Unable to locate \":port\""
				" in IPv4 iSCSI network portal address\n");
			return ERR_PTR(-EINVAL);
		}
		*port_str = '\0'; /* Terminate string for IP */
		port_str++; /* Skip over ":" */

272
		ret = kstrtoul(port_str, 0, &port);
273
		if (ret < 0) {
274
			pr_err("kstrtoul() failed for port_str: %d\n", ret);
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
			return ERR_PTR(ret);
		}
		sock_in = (struct sockaddr_in *)&sockaddr;
		sock_in->sin_family = AF_INET;
		sock_in->sin_port = htons((unsigned short)port);
		sock_in->sin_addr.s_addr = in_aton(ip_str);
	}
	tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
	ret = iscsit_get_tpg(tpg);
	if (ret < 0)
		return ERR_PTR(-EINVAL);

	pr_debug("LIO_Target_ConfigFS: REGISTER -> %s TPGT: %hu"
		" PORTAL: %s\n",
		config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
		tpg->tpgt, name);
	/*
	 * Assume ISCSI_TCP by default.  Other network portals for other
	 * iSCSI fabrics:
	 *
	 * Traditional iSCSI over SCTP (initial support)
	 * iSER/TCP (TODO, hardware available)
	 * iSER/SCTP (TODO, software emulation with osc-iwarp)
	 * iSER/IB (TODO, hardware available)
	 *
300
	 * can be enabled with attributes under
301 302 303
	 * sys/kernel/config/iscsi/$IQN/$TPG/np/$IP:$PORT/
	 *
	 */
304
	tpg_np = iscsit_tpg_add_network_portal(tpg, &sockaddr, NULL,
305 306 307
				ISCSI_TCP);
	if (IS_ERR(tpg_np)) {
		iscsit_put_tpg(tpg);
308
		return ERR_CAST(tpg_np);
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
	}
	pr_debug("LIO_Target_ConfigFS: addnptotpg done!\n");

	iscsit_put_tpg(tpg);
	return &tpg_np->se_tpg_np;
}

static void lio_target_call_delnpfromtpg(
	struct se_tpg_np *se_tpg_np)
{
	struct iscsi_portal_group *tpg;
	struct iscsi_tpg_np *tpg_np;
	struct se_portal_group *se_tpg;
	int ret;

	tpg_np = container_of(se_tpg_np, struct iscsi_tpg_np, se_tpg_np);
	tpg = tpg_np->tpg;
	ret = iscsit_get_tpg(tpg);
	if (ret < 0)
		return;

	se_tpg = &tpg->tpg_se_tpg;
	pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s TPGT: %hu"
332 333
		" PORTAL: %pISpc\n", config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
		tpg->tpgt, &tpg_np->tpg_np->np_sockaddr);
334 335 336 337 338 339 340 341 342 343 344 345 346 347

	ret = iscsit_tpg_del_network_portal(tpg, tpg_np);
	if (ret < 0)
		goto out;

	pr_debug("LIO_Target_ConfigFS: delnpfromtpg done!\n");
out:
	iscsit_put_tpg(tpg);
}

/* End items for lio_target_np_cit */

/* Start items for lio_target_nacl_attrib_cit */

348 349 350
#define ISCSI_NACL_ATTR(name)						\
static ssize_t iscsi_nacl_attrib_##name##_show(struct config_item *item,\
		char *page)						\
351
{									\
352
	struct se_node_acl *se_nacl = attrib_to_nacl(item);		\
353 354 355
	struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
					se_node_acl);			\
									\
356
	return sprintf(page, "%u\n", nacl->node_attrib.name);		\
357 358
}									\
									\
359 360
static ssize_t iscsi_nacl_attrib_##name##_store(struct config_item *item,\
		const char *page, size_t count)				\
361
{									\
362
	struct se_node_acl *se_nacl = attrib_to_nacl(item);		\
363 364 365 366 367
	struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
					se_node_acl);			\
	u32 val;							\
	int ret;							\
									\
368 369 370
	ret = kstrtou32(page, 0, &val);					\
	if (ret)							\
		return ret;						\
371 372 373 374 375
	ret = iscsit_na_##name(nacl, val);				\
	if (ret < 0)							\
		return ret;						\
									\
	return count;							\
376 377 378
}									\
									\
CONFIGFS_ATTR(iscsi_nacl_attrib_, name)
379

380 381 382 383 384 385 386 387
ISCSI_NACL_ATTR(dataout_timeout);
ISCSI_NACL_ATTR(dataout_timeout_retries);
ISCSI_NACL_ATTR(default_erl);
ISCSI_NACL_ATTR(nopin_timeout);
ISCSI_NACL_ATTR(nopin_response_timeout);
ISCSI_NACL_ATTR(random_datain_pdu_offsets);
ISCSI_NACL_ATTR(random_datain_seq_offsets);
ISCSI_NACL_ATTR(random_r2t_offsets);
388 389

static struct configfs_attribute *lio_target_nacl_attrib_attrs[] = {
390 391 392 393 394 395 396 397
	&iscsi_nacl_attrib_attr_dataout_timeout,
	&iscsi_nacl_attrib_attr_dataout_timeout_retries,
	&iscsi_nacl_attrib_attr_default_erl,
	&iscsi_nacl_attrib_attr_nopin_timeout,
	&iscsi_nacl_attrib_attr_nopin_response_timeout,
	&iscsi_nacl_attrib_attr_random_datain_pdu_offsets,
	&iscsi_nacl_attrib_attr_random_datain_seq_offsets,
	&iscsi_nacl_attrib_attr_random_r2t_offsets,
398 399 400 401 402 403 404 405
	NULL,
};

/* End items for lio_target_nacl_attrib_cit */

/* Start items for lio_target_nacl_auth_cit */

#define __DEF_NACL_AUTH_STR(prefix, name, flags)			\
406
static ssize_t __iscsi_##prefix##_##name##_show(			\
407 408 409 410 411 412 413 414 415 416
	struct iscsi_node_acl *nacl,					\
	char *page)							\
{									\
	struct iscsi_node_auth *auth = &nacl->node_auth;		\
									\
	if (!capable(CAP_SYS_ADMIN))					\
		return -EPERM;						\
	return snprintf(page, PAGE_SIZE, "%s\n", auth->name);		\
}									\
									\
417
static ssize_t __iscsi_##prefix##_##name##_store(			\
418 419 420 421 422 423 424 425
	struct iscsi_node_acl *nacl,					\
	const char *page,						\
	size_t count)							\
{									\
	struct iscsi_node_auth *auth = &nacl->node_auth;		\
									\
	if (!capable(CAP_SYS_ADMIN))					\
		return -EPERM;						\
426 427
	if (count >= sizeof(auth->name))				\
		return -EINVAL;						\
428
	snprintf(auth->name, sizeof(auth->name), "%s", page);		\
429 430 431 432 433 434 435 436 437 438 439 440 441 442
	if (!strncmp("NULL", auth->name, 4))				\
		auth->naf_flags &= ~flags;				\
	else								\
		auth->naf_flags |= flags;				\
									\
	if ((auth->naf_flags & NAF_USERID_IN_SET) &&			\
	    (auth->naf_flags & NAF_PASSWORD_IN_SET))			\
		auth->authenticate_target = 1;				\
	else								\
		auth->authenticate_target = 0;				\
									\
	return count;							\
}

443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
#define DEF_NACL_AUTH_STR(name, flags)					\
	__DEF_NACL_AUTH_STR(nacl_auth, name, flags)			\
static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item,	\
		char *page)						\
{									\
	struct se_node_acl *nacl = auth_to_nacl(item);			\
	return __iscsi_nacl_auth_##name##_show(container_of(nacl,	\
			struct iscsi_node_acl, se_node_acl), page);	\
}									\
static ssize_t iscsi_nacl_auth_##name##_store(struct config_item *item,	\
		const char *page, size_t count)				\
{									\
	struct se_node_acl *nacl = auth_to_nacl(item);			\
	return __iscsi_nacl_auth_##name##_store(container_of(nacl,	\
			struct iscsi_node_acl, se_node_acl), page, count); \
}									\
									\
CONFIGFS_ATTR(iscsi_nacl_auth_, name)

/*
 * One-way authentication userid
 */
DEF_NACL_AUTH_STR(userid, NAF_USERID_SET);
DEF_NACL_AUTH_STR(password, NAF_PASSWORD_SET);
DEF_NACL_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
DEF_NACL_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);

470
#define __DEF_NACL_AUTH_INT(prefix, name)				\
471
static ssize_t __iscsi_##prefix##_##name##_show(				\
472 473 474 475 476 477 478 479 480 481 482 483 484
	struct iscsi_node_acl *nacl,					\
	char *page)							\
{									\
	struct iscsi_node_auth *auth = &nacl->node_auth;		\
									\
	if (!capable(CAP_SYS_ADMIN))					\
		return -EPERM;						\
									\
	return snprintf(page, PAGE_SIZE, "%d\n", auth->name);		\
}

#define DEF_NACL_AUTH_INT(name)						\
	__DEF_NACL_AUTH_INT(nacl_auth, name)				\
485 486
static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item,	\
		char *page)						\
487
{									\
488 489 490 491 492 493
	struct se_node_acl *nacl = auth_to_nacl(item);			\
	return __iscsi_nacl_auth_##name##_show(container_of(nacl,	\
			struct iscsi_node_acl, se_node_acl), page);	\
}									\
									\
CONFIGFS_ATTR_RO(iscsi_nacl_auth_, name)
494 495 496 497

DEF_NACL_AUTH_INT(authenticate_target);

static struct configfs_attribute *lio_target_nacl_auth_attrs[] = {
498 499 500 501 502
	&iscsi_nacl_auth_attr_userid,
	&iscsi_nacl_auth_attr_password,
	&iscsi_nacl_auth_attr_authenticate_target,
	&iscsi_nacl_auth_attr_userid_mutual,
	&iscsi_nacl_auth_attr_password_mutual,
503 504 505 506 507 508 509
	NULL,
};

/* End items for lio_target_nacl_auth_cit */

/* Start items for lio_target_nacl_param_cit */

510 511 512
#define ISCSI_NACL_PARAM(name)						\
static ssize_t iscsi_nacl_param_##name##_show(struct config_item *item,	\
		char *page)						\
513
{									\
514
	struct se_node_acl *se_nacl = param_to_nacl(item);		\
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531
	struct iscsi_session *sess;					\
	struct se_session *se_sess;					\
	ssize_t rb;							\
									\
	spin_lock_bh(&se_nacl->nacl_sess_lock);				\
	se_sess = se_nacl->nacl_sess;					\
	if (!se_sess) {							\
		rb = snprintf(page, PAGE_SIZE,				\
			"No Active iSCSI Session\n");			\
	} else {							\
		sess = se_sess->fabric_sess_ptr;			\
		rb = snprintf(page, PAGE_SIZE, "%u\n",			\
			(u32)sess->sess_ops->name);			\
	}								\
	spin_unlock_bh(&se_nacl->nacl_sess_lock);			\
									\
	return rb;							\
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546
}									\
									\
CONFIGFS_ATTR_RO(iscsi_nacl_param_, name)

ISCSI_NACL_PARAM(MaxConnections);
ISCSI_NACL_PARAM(InitialR2T);
ISCSI_NACL_PARAM(ImmediateData);
ISCSI_NACL_PARAM(MaxBurstLength);
ISCSI_NACL_PARAM(FirstBurstLength);
ISCSI_NACL_PARAM(DefaultTime2Wait);
ISCSI_NACL_PARAM(DefaultTime2Retain);
ISCSI_NACL_PARAM(MaxOutstandingR2T);
ISCSI_NACL_PARAM(DataPDUInOrder);
ISCSI_NACL_PARAM(DataSequenceInOrder);
ISCSI_NACL_PARAM(ErrorRecoveryLevel);
547 548

static struct configfs_attribute *lio_target_nacl_param_attrs[] = {
549 550 551 552 553 554 555 556 557 558 559
	&iscsi_nacl_param_attr_MaxConnections,
	&iscsi_nacl_param_attr_InitialR2T,
	&iscsi_nacl_param_attr_ImmediateData,
	&iscsi_nacl_param_attr_MaxBurstLength,
	&iscsi_nacl_param_attr_FirstBurstLength,
	&iscsi_nacl_param_attr_DefaultTime2Wait,
	&iscsi_nacl_param_attr_DefaultTime2Retain,
	&iscsi_nacl_param_attr_MaxOutstandingR2T,
	&iscsi_nacl_param_attr_DataPDUInOrder,
	&iscsi_nacl_param_attr_DataSequenceInOrder,
	&iscsi_nacl_param_attr_ErrorRecoveryLevel,
560 561 562 563 564 565 566
	NULL,
};

/* End items for lio_target_nacl_param_cit */

/* Start items for lio_target_acl_cit */

567
static ssize_t lio_target_nacl_info_show(struct config_item *item, char *page)
568
{
569
	struct se_node_acl *se_nacl = acl_to_nacl(item);
570 571 572 573
	struct iscsi_session *sess;
	struct iscsi_conn *conn;
	struct se_session *se_sess;
	ssize_t rb = 0;
574
	u32 max_cmd_sn;
575 576 577 578 579 580 581 582 583

	spin_lock_bh(&se_nacl->nacl_sess_lock);
	se_sess = se_nacl->nacl_sess;
	if (!se_sess) {
		rb += sprintf(page+rb, "No active iSCSI Session for Initiator"
			" Endpoint: %s\n", se_nacl->initiatorname);
	} else {
		sess = se_sess->fabric_sess_ptr;

584 585 586 587
		rb += sprintf(page+rb, "InitiatorName: %s\n",
			sess->sess_ops->InitiatorName);
		rb += sprintf(page+rb, "InitiatorAlias: %s\n",
			sess->sess_ops->InitiatorAlias);
588

589 590 591
		rb += sprintf(page+rb,
			      "LIO Session ID: %u   ISID: 0x%6ph  TSIH: %hu  ",
			      sess->sid, sess->isid, sess->tsih);
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621
		rb += sprintf(page+rb, "SessionType: %s\n",
				(sess->sess_ops->SessionType) ?
				"Discovery" : "Normal");
		rb += sprintf(page+rb, "Session State: ");
		switch (sess->session_state) {
		case TARG_SESS_STATE_FREE:
			rb += sprintf(page+rb, "TARG_SESS_FREE\n");
			break;
		case TARG_SESS_STATE_ACTIVE:
			rb += sprintf(page+rb, "TARG_SESS_STATE_ACTIVE\n");
			break;
		case TARG_SESS_STATE_LOGGED_IN:
			rb += sprintf(page+rb, "TARG_SESS_STATE_LOGGED_IN\n");
			break;
		case TARG_SESS_STATE_FAILED:
			rb += sprintf(page+rb, "TARG_SESS_STATE_FAILED\n");
			break;
		case TARG_SESS_STATE_IN_CONTINUE:
			rb += sprintf(page+rb, "TARG_SESS_STATE_IN_CONTINUE\n");
			break;
		default:
			rb += sprintf(page+rb, "ERROR: Unknown Session"
					" State!\n");
			break;
		}

		rb += sprintf(page+rb, "---------------------[iSCSI Session"
				" Values]-----------------------\n");
		rb += sprintf(page+rb, "  CmdSN/WR  :  CmdSN/WC  :  ExpCmdSN"
				"  :  MaxCmdSN  :     ITT    :     TTT\n");
622
		max_cmd_sn = (u32) atomic_read(&sess->max_cmd_sn);
623 624 625
		rb += sprintf(page+rb, " 0x%08x   0x%08x   0x%08x   0x%08x"
				"   0x%08x   0x%08x\n",
			sess->cmdsn_window,
626 627
			(max_cmd_sn - sess->exp_cmd_sn) + 1,
			sess->exp_cmd_sn, max_cmd_sn,
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670
			sess->init_task_tag, sess->targ_xfer_tag);
		rb += sprintf(page+rb, "----------------------[iSCSI"
				" Connections]-------------------------\n");

		spin_lock(&sess->conn_lock);
		list_for_each_entry(conn, &sess->sess_conn_list, conn_list) {
			rb += sprintf(page+rb, "CID: %hu  Connection"
					" State: ", conn->cid);
			switch (conn->conn_state) {
			case TARG_CONN_STATE_FREE:
				rb += sprintf(page+rb,
					"TARG_CONN_STATE_FREE\n");
				break;
			case TARG_CONN_STATE_XPT_UP:
				rb += sprintf(page+rb,
					"TARG_CONN_STATE_XPT_UP\n");
				break;
			case TARG_CONN_STATE_IN_LOGIN:
				rb += sprintf(page+rb,
					"TARG_CONN_STATE_IN_LOGIN\n");
				break;
			case TARG_CONN_STATE_LOGGED_IN:
				rb += sprintf(page+rb,
					"TARG_CONN_STATE_LOGGED_IN\n");
				break;
			case TARG_CONN_STATE_IN_LOGOUT:
				rb += sprintf(page+rb,
					"TARG_CONN_STATE_IN_LOGOUT\n");
				break;
			case TARG_CONN_STATE_LOGOUT_REQUESTED:
				rb += sprintf(page+rb,
					"TARG_CONN_STATE_LOGOUT_REQUESTED\n");
				break;
			case TARG_CONN_STATE_CLEANUP_WAIT:
				rb += sprintf(page+rb,
					"TARG_CONN_STATE_CLEANUP_WAIT\n");
				break;
			default:
				rb += sprintf(page+rb,
					"ERROR: Unknown Connection State!\n");
				break;
			}

671
			rb += sprintf(page+rb, "   Address %pISc %s", &conn->login_sockaddr,
672 673 674 675 676 677 678 679 680 681 682 683
				(conn->network_transport == ISCSI_TCP) ?
				"TCP" : "SCTP");
			rb += sprintf(page+rb, "  StatSN: 0x%08x\n",
				conn->stat_sn);
		}
		spin_unlock(&sess->conn_lock);
	}
	spin_unlock_bh(&se_nacl->nacl_sess_lock);

	return rb;
}

684 685
static ssize_t lio_target_nacl_cmdsn_depth_show(struct config_item *item,
		char *page)
686
{
687
	return sprintf(page, "%u\n", acl_to_nacl(item)->queue_depth);
688 689
}

690 691
static ssize_t lio_target_nacl_cmdsn_depth_store(struct config_item *item,
		const char *page, size_t count)
692
{
693
	struct se_node_acl *se_nacl = acl_to_nacl(item);
694 695 696 697 698 699 700
	struct se_portal_group *se_tpg = se_nacl->se_tpg;
	struct iscsi_portal_group *tpg = container_of(se_tpg,
			struct iscsi_portal_group, tpg_se_tpg);
	struct config_item *acl_ci, *tpg_ci, *wwn_ci;
	u32 cmdsn_depth = 0;
	int ret;

701 702 703
	ret = kstrtou32(page, 0, &cmdsn_depth);
	if (ret)
		return ret;
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727
	if (cmdsn_depth > TA_DEFAULT_CMDSN_DEPTH_MAX) {
		pr_err("Passed cmdsn_depth: %u exceeds"
			" TA_DEFAULT_CMDSN_DEPTH_MAX: %u\n", cmdsn_depth,
			TA_DEFAULT_CMDSN_DEPTH_MAX);
		return -EINVAL;
	}
	acl_ci = &se_nacl->acl_group.cg_item;
	if (!acl_ci) {
		pr_err("Unable to locatel acl_ci\n");
		return -EINVAL;
	}
	tpg_ci = &acl_ci->ci_parent->ci_group->cg_item;
	if (!tpg_ci) {
		pr_err("Unable to locate tpg_ci\n");
		return -EINVAL;
	}
	wwn_ci = &tpg_ci->ci_group->cg_item;
	if (!wwn_ci) {
		pr_err("Unable to locate config_item wwn_ci\n");
		return -EINVAL;
	}

	if (iscsit_get_tpg(tpg) < 0)
		return -EINVAL;
728 729

	ret = core_tpg_set_initiator_node_queue_depth(se_nacl, cmdsn_depth);
730 731 732 733 734 735 736 737 738 739

	pr_debug("LIO_Target_ConfigFS: %s/%s Set CmdSN Window: %u for"
		"InitiatorName: %s\n", config_item_name(wwn_ci),
		config_item_name(tpg_ci), cmdsn_depth,
		config_item_name(acl_ci));

	iscsit_put_tpg(tpg);
	return (!ret) ? count : (ssize_t)ret;
}

740
static ssize_t lio_target_nacl_tag_show(struct config_item *item, char *page)
741
{
742
	return snprintf(page, PAGE_SIZE, "%s", acl_to_nacl(item)->acl_tag);
743 744
}

745 746
static ssize_t lio_target_nacl_tag_store(struct config_item *item,
		const char *page, size_t count)
747
{
748
	struct se_node_acl *se_nacl = acl_to_nacl(item);
749 750 751 752 753 754 755 756 757
	int ret;

	ret = core_tpg_set_initiator_node_tag(se_nacl->se_tpg, se_nacl, page);

	if (ret < 0)
		return ret;
	return count;
}

758 759 760
CONFIGFS_ATTR_RO(lio_target_nacl_, info);
CONFIGFS_ATTR(lio_target_nacl_, cmdsn_depth);
CONFIGFS_ATTR(lio_target_nacl_, tag);
761

762
static struct configfs_attribute *lio_target_initiator_attrs[] = {
763 764 765
	&lio_target_nacl_attr_info,
	&lio_target_nacl_attr_cmdsn_depth,
	&lio_target_nacl_attr_tag,
766 767 768
	NULL,
};

769 770
static int lio_target_init_nodeacl(struct se_node_acl *se_nacl,
		const char *name)
771
{
772 773
	struct iscsi_node_acl *acl =
		container_of(se_nacl, struct iscsi_node_acl, se_node_acl);
774

775
	config_group_init_type_name(&acl->node_stat_grps.iscsi_sess_stats_group,
776
			"iscsi_sess_stats", &iscsi_stat_sess_cit);
777 778
	configfs_add_default_group(&acl->node_stat_grps.iscsi_sess_stats_group,
			&se_nacl->acl_fabric_stat_group);
779
	return 0;
780 781 782 783 784 785 786 787
}

/* End items for lio_target_acl_cit */

/* Start items for lio_target_tpg_attrib_cit */

#define DEF_TPG_ATTRIB(name)						\
									\
788 789
static ssize_t iscsi_tpg_attrib_##name##_show(struct config_item *item,	\
		char *page)						\
790
{									\
791
	struct se_portal_group *se_tpg = attrib_to_tpg(item);		\
792 793 794 795 796 797 798
	struct iscsi_portal_group *tpg = container_of(se_tpg,		\
			struct iscsi_portal_group, tpg_se_tpg);	\
	ssize_t rb;							\
									\
	if (iscsit_get_tpg(tpg) < 0)					\
		return -EINVAL;						\
									\
799
	rb = sprintf(page, "%u\n", tpg->tpg_attrib.name);		\
800 801 802 803
	iscsit_put_tpg(tpg);						\
	return rb;							\
}									\
									\
804 805
static ssize_t iscsi_tpg_attrib_##name##_store(struct config_item *item,\
		const char *page, size_t count)				\
806
{									\
807
	struct se_portal_group *se_tpg = attrib_to_tpg(item);		\
808 809 810 811 812 813 814 815
	struct iscsi_portal_group *tpg = container_of(se_tpg,		\
			struct iscsi_portal_group, tpg_se_tpg);	\
	u32 val;							\
	int ret;							\
									\
	if (iscsit_get_tpg(tpg) < 0)					\
		return -EINVAL;						\
									\
816 817 818
	ret = kstrtou32(page, 0, &val);					\
	if (ret)							\
		goto out;						\
819 820 821 822 823 824 825 826 827
	ret = iscsit_ta_##name(tpg, val);				\
	if (ret < 0)							\
		goto out;						\
									\
	iscsit_put_tpg(tpg);						\
	return count;							\
out:									\
	iscsit_put_tpg(tpg);						\
	return ret;							\
828 829
}									\
CONFIGFS_ATTR(iscsi_tpg_attrib_, name)
830 831 832 833 834 835 836 837 838

DEF_TPG_ATTRIB(authentication);
DEF_TPG_ATTRIB(login_timeout);
DEF_TPG_ATTRIB(netif_timeout);
DEF_TPG_ATTRIB(generate_node_acls);
DEF_TPG_ATTRIB(default_cmdsn_depth);
DEF_TPG_ATTRIB(cache_dynamic_acls);
DEF_TPG_ATTRIB(demo_mode_write_protect);
DEF_TPG_ATTRIB(prod_mode_write_protect);
839
DEF_TPG_ATTRIB(demo_mode_discovery);
840
DEF_TPG_ATTRIB(default_erl);
841
DEF_TPG_ATTRIB(t10_pi);
842
DEF_TPG_ATTRIB(fabric_prot_type);
843
DEF_TPG_ATTRIB(tpg_enabled_sendtargets);
844 845

static struct configfs_attribute *lio_target_tpg_attrib_attrs[] = {
846 847 848 849 850 851 852 853 854 855 856 857 858
	&iscsi_tpg_attrib_attr_authentication,
	&iscsi_tpg_attrib_attr_login_timeout,
	&iscsi_tpg_attrib_attr_netif_timeout,
	&iscsi_tpg_attrib_attr_generate_node_acls,
	&iscsi_tpg_attrib_attr_default_cmdsn_depth,
	&iscsi_tpg_attrib_attr_cache_dynamic_acls,
	&iscsi_tpg_attrib_attr_demo_mode_write_protect,
	&iscsi_tpg_attrib_attr_prod_mode_write_protect,
	&iscsi_tpg_attrib_attr_demo_mode_discovery,
	&iscsi_tpg_attrib_attr_default_erl,
	&iscsi_tpg_attrib_attr_t10_pi,
	&iscsi_tpg_attrib_attr_fabric_prot_type,
	&iscsi_tpg_attrib_attr_tpg_enabled_sendtargets,
859 860 861 862 863
	NULL,
};

/* End items for lio_target_tpg_attrib_cit */

864 865 866
/* Start items for lio_target_tpg_auth_cit */

#define __DEF_TPG_AUTH_STR(prefix, name, flags)					\
867 868
static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg,	\
		char *page)							\
869 870 871 872 873 874 875 876 877 878 879
{										\
	struct iscsi_portal_group *tpg = container_of(se_tpg,			\
				struct iscsi_portal_group, tpg_se_tpg);		\
	struct iscsi_node_auth *auth = &tpg->tpg_demo_auth;			\
										\
	if (!capable(CAP_SYS_ADMIN))						\
		return -EPERM;							\
										\
	return snprintf(page, PAGE_SIZE, "%s\n", auth->name);			\
}										\
										\
880 881
static ssize_t __iscsi_##prefix##_##name##_store(struct se_portal_group *se_tpg,\
		const char *page, size_t count)					\
882 883 884 885 886 887 888 889
{										\
	struct iscsi_portal_group *tpg = container_of(se_tpg,			\
				struct iscsi_portal_group, tpg_se_tpg);		\
	struct iscsi_node_auth *auth = &tpg->tpg_demo_auth;			\
										\
	if (!capable(CAP_SYS_ADMIN))						\
		return -EPERM;							\
										\
890
	snprintf(auth->name, sizeof(auth->name), "%s", page);			\
891 892 893 894 895 896 897 898 899 900 901 902 903 904
	if (!(strncmp("NULL", auth->name, 4)))					\
		auth->naf_flags &= ~flags;					\
	else									\
		auth->naf_flags |= flags;					\
										\
	if ((auth->naf_flags & NAF_USERID_IN_SET) &&				\
	    (auth->naf_flags & NAF_PASSWORD_IN_SET))				\
		auth->authenticate_target = 1;					\
	else									\
		auth->authenticate_target = 0;					\
										\
	return count;								\
}

905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926
#define DEF_TPG_AUTH_STR(name, flags)						\
	__DEF_TPG_AUTH_STR(tpg_auth, name, flags)				\
static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item,		\
		char *page)							\
{										\
	return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page);		\
}										\
										\
static ssize_t iscsi_tpg_auth_##name##_store(struct config_item *item,		\
		const char *page, size_t count)					\
{										\
	return __iscsi_tpg_auth_##name##_store(auth_to_tpg(item), page, count);	\
}										\
										\
CONFIGFS_ATTR(iscsi_tpg_auth_, name);


DEF_TPG_AUTH_STR(userid, NAF_USERID_SET);
DEF_TPG_AUTH_STR(password, NAF_PASSWORD_SET);
DEF_TPG_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
DEF_TPG_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);

927
#define __DEF_TPG_AUTH_INT(prefix, name)					\
928 929
static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg,	\
		char *page)								\
930 931 932 933 934 935 936 937 938 939 940 941 942
{										\
	struct iscsi_portal_group *tpg = container_of(se_tpg,			\
				struct iscsi_portal_group, tpg_se_tpg);		\
	struct iscsi_node_auth *auth = &tpg->tpg_demo_auth;			\
										\
	if (!capable(CAP_SYS_ADMIN))						\
		return -EPERM;							\
										\
	return snprintf(page, PAGE_SIZE, "%d\n", auth->name);			\
}

#define DEF_TPG_AUTH_INT(name)							\
	__DEF_TPG_AUTH_INT(tpg_auth, name)					\
943 944
static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item,		\
		char *page) \
945
{										\
946 947 948
	return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page);		\
}										\
CONFIGFS_ATTR_RO(iscsi_tpg_auth_, name);
949 950 951 952

DEF_TPG_AUTH_INT(authenticate_target);

static struct configfs_attribute *lio_target_tpg_auth_attrs[] = {
953 954 955 956 957
	&iscsi_tpg_auth_attr_userid,
	&iscsi_tpg_auth_attr_password,
	&iscsi_tpg_auth_attr_authenticate_target,
	&iscsi_tpg_auth_attr_userid_mutual,
	&iscsi_tpg_auth_attr_password_mutual,
958 959 960 961 962
	NULL,
};

/* End items for lio_target_tpg_auth_cit */

963 964 965
/* Start items for lio_target_tpg_param_cit */

#define DEF_TPG_PARAM(name)						\
966 967
static ssize_t iscsi_tpg_param_##name##_show(struct config_item *item,	\
		char *page)						\
968
{									\
969
	struct se_portal_group *se_tpg = param_to_tpg(item);		\
970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988
	struct iscsi_portal_group *tpg = container_of(se_tpg,		\
			struct iscsi_portal_group, tpg_se_tpg);		\
	struct iscsi_param *param;					\
	ssize_t rb;							\
									\
	if (iscsit_get_tpg(tpg) < 0)					\
		return -EINVAL;						\
									\
	param = iscsi_find_param_from_key(__stringify(name),		\
				tpg->param_list);			\
	if (!param) {							\
		iscsit_put_tpg(tpg);					\
		return -EINVAL;						\
	}								\
	rb = snprintf(page, PAGE_SIZE, "%s\n", param->value);		\
									\
	iscsit_put_tpg(tpg);						\
	return rb;							\
}									\
989 990
static ssize_t iscsi_tpg_param_##name##_store(struct config_item *item, \
		const char *page, size_t count)				\
991
{									\
992
	struct se_portal_group *se_tpg = param_to_tpg(item);		\
993 994 995
	struct iscsi_portal_group *tpg = container_of(se_tpg,		\
			struct iscsi_portal_group, tpg_se_tpg);		\
	char *buf;							\
996
	int ret, len;							\
997 998 999 1000
									\
	buf = kzalloc(PAGE_SIZE, GFP_KERNEL);				\
	if (!buf)							\
		return -ENOMEM;						\
1001 1002 1003
	len = snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page);	\
	if (isspace(buf[len-1]))					\
		buf[len-1] = '\0'; /* Kill newline */			\
1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019
									\
	if (iscsit_get_tpg(tpg) < 0) {					\
		kfree(buf);						\
		return -EINVAL;						\
	}								\
									\
	ret = iscsi_change_param_value(buf, tpg->param_list, 1);	\
	if (ret < 0)							\
		goto out;						\
									\
	kfree(buf);							\
	iscsit_put_tpg(tpg);						\
	return count;							\
out:									\
	kfree(buf);							\
	iscsit_put_tpg(tpg);						\
1020 1021 1022
	return -EINVAL;							\
}									\
CONFIGFS_ATTR(iscsi_tpg_param_, name)
1023 1024 1025 1026 1027 1028 1029 1030 1031

DEF_TPG_PARAM(AuthMethod);
DEF_TPG_PARAM(HeaderDigest);
DEF_TPG_PARAM(DataDigest);
DEF_TPG_PARAM(MaxConnections);
DEF_TPG_PARAM(TargetAlias);
DEF_TPG_PARAM(InitialR2T);
DEF_TPG_PARAM(ImmediateData);
DEF_TPG_PARAM(MaxRecvDataSegmentLength);
1032
DEF_TPG_PARAM(MaxXmitDataSegmentLength);
1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046
DEF_TPG_PARAM(MaxBurstLength);
DEF_TPG_PARAM(FirstBurstLength);
DEF_TPG_PARAM(DefaultTime2Wait);
DEF_TPG_PARAM(DefaultTime2Retain);
DEF_TPG_PARAM(MaxOutstandingR2T);
DEF_TPG_PARAM(DataPDUInOrder);
DEF_TPG_PARAM(DataSequenceInOrder);
DEF_TPG_PARAM(ErrorRecoveryLevel);
DEF_TPG_PARAM(IFMarker);
DEF_TPG_PARAM(OFMarker);
DEF_TPG_PARAM(IFMarkInt);
DEF_TPG_PARAM(OFMarkInt);

static struct configfs_attribute *lio_target_tpg_param_attrs[] = {
1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067
	&iscsi_tpg_param_attr_AuthMethod,
	&iscsi_tpg_param_attr_HeaderDigest,
	&iscsi_tpg_param_attr_DataDigest,
	&iscsi_tpg_param_attr_MaxConnections,
	&iscsi_tpg_param_attr_TargetAlias,
	&iscsi_tpg_param_attr_InitialR2T,
	&iscsi_tpg_param_attr_ImmediateData,
	&iscsi_tpg_param_attr_MaxRecvDataSegmentLength,
	&iscsi_tpg_param_attr_MaxXmitDataSegmentLength,
	&iscsi_tpg_param_attr_MaxBurstLength,
	&iscsi_tpg_param_attr_FirstBurstLength,
	&iscsi_tpg_param_attr_DefaultTime2Wait,
	&iscsi_tpg_param_attr_DefaultTime2Retain,
	&iscsi_tpg_param_attr_MaxOutstandingR2T,
	&iscsi_tpg_param_attr_DataPDUInOrder,
	&iscsi_tpg_param_attr_DataSequenceInOrder,
	&iscsi_tpg_param_attr_ErrorRecoveryLevel,
	&iscsi_tpg_param_attr_IFMarker,
	&iscsi_tpg_param_attr_OFMarker,
	&iscsi_tpg_param_attr_IFMarkInt,
	&iscsi_tpg_param_attr_OFMarkInt,
1068 1069 1070 1071 1072 1073 1074
	NULL,
};

/* End items for lio_target_tpg_param_cit */

/* Start items for lio_target_tpg_cit */

1075
static ssize_t lio_target_tpg_enable_show(struct config_item *item, char *page)
1076
{
1077
	struct se_portal_group *se_tpg = to_tpg(item);
1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089
	struct iscsi_portal_group *tpg = container_of(se_tpg,
			struct iscsi_portal_group, tpg_se_tpg);
	ssize_t len;

	spin_lock(&tpg->tpg_state_lock);
	len = sprintf(page, "%d\n",
			(tpg->tpg_state == TPG_STATE_ACTIVE) ? 1 : 0);
	spin_unlock(&tpg->tpg_state_lock);

	return len;
}

1090 1091
static ssize_t lio_target_tpg_enable_store(struct config_item *item,
		const char *page, size_t count)
1092
{
1093
	struct se_portal_group *se_tpg = to_tpg(item);
1094 1095 1096
	struct iscsi_portal_group *tpg = container_of(se_tpg,
			struct iscsi_portal_group, tpg_se_tpg);
	u32 op;
1097
	int ret;
1098

1099 1100 1101
	ret = kstrtou32(page, 0, &op);
	if (ret)
		return ret;
1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131
	if ((op != 1) && (op != 0)) {
		pr_err("Illegal value for tpg_enable: %u\n", op);
		return -EINVAL;
	}

	ret = iscsit_get_tpg(tpg);
	if (ret < 0)
		return -EINVAL;

	if (op) {
		ret = iscsit_tpg_enable_portal_group(tpg);
		if (ret < 0)
			goto out;
	} else {
		/*
		 * iscsit_tpg_disable_portal_group() assumes force=1
		 */
		ret = iscsit_tpg_disable_portal_group(tpg, 1);
		if (ret < 0)
			goto out;
	}

	iscsit_put_tpg(tpg);
	return count;
out:
	iscsit_put_tpg(tpg);
	return -EINVAL;
}


1132 1133
static ssize_t lio_target_tpg_dynamic_sessions_show(struct config_item *item,
		char *page)
1134
{
1135
	return target_show_dynamic_sessions(to_tpg(item), page);
1136 1137
}

1138 1139
CONFIGFS_ATTR(lio_target_tpg_, enable);
CONFIGFS_ATTR_RO(lio_target_tpg_, dynamic_sessions);
1140

1141
static struct configfs_attribute *lio_target_tpg_attrs[] = {
1142 1143
	&lio_target_tpg_attr_enable,
	&lio_target_tpg_attr_dynamic_sessions,
1144 1145 1146 1147 1148 1149 1150
	NULL,
};

/* End items for lio_target_tpg_cit */

/* Start items for lio_target_tiqn_cit */

1151
static struct se_portal_group *lio_target_tiqn_addtpg(
1152 1153 1154 1155 1156 1157
	struct se_wwn *wwn,
	struct config_group *group,
	const char *name)
{
	struct iscsi_portal_group *tpg;
	struct iscsi_tiqn *tiqn;
1158 1159 1160
	char *tpgt_str;
	int ret;
	u16 tpgt;
1161 1162 1163 1164 1165

	tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
	/*
	 * Only tpgt_# directory groups can be created below
	 * target/iscsi/iqn.superturodiskarry/
1166
	 */
1167 1168 1169 1170 1171 1172 1173
	tpgt_str = strstr(name, "tpgt_");
	if (!tpgt_str) {
		pr_err("Unable to locate \"tpgt_#\" directory"
				" group\n");
		return NULL;
	}
	tpgt_str += 5; /* Skip ahead of "tpgt_" */
1174 1175 1176
	ret = kstrtou16(tpgt_str, 0, &tpgt);
	if (ret)
		return NULL;
1177 1178 1179 1180 1181

	tpg = iscsit_alloc_portal_group(tiqn, tpgt);
	if (!tpg)
		return NULL;

1182
	ret = core_tpg_register(wwn, &tpg->tpg_se_tpg, SCSI_PROTOCOL_ISCSI);
1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199
	if (ret < 0)
		return NULL;

	ret = iscsit_tpg_add_portal_group(tiqn, tpg);
	if (ret != 0)
		goto out;

	pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
	pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated TPG: %s\n",
			name);
	return &tpg->tpg_se_tpg;
out:
	core_tpg_deregister(&tpg->tpg_se_tpg);
	kfree(tpg);
	return NULL;
}

1200
static void lio_target_tiqn_deltpg(struct se_portal_group *se_tpg)
1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217
{
	struct iscsi_portal_group *tpg;
	struct iscsi_tiqn *tiqn;

	tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
	tiqn = tpg->tpg_tiqn;
	/*
	 * iscsit_tpg_del_portal_group() assumes force=1
	 */
	pr_debug("LIO_Target_ConfigFS: DEREGISTER -> Releasing TPG\n");
	iscsit_tpg_del_portal_group(tiqn, tpg, 1);
}

/* End items for lio_target_tiqn_cit */

/* Start LIO-Target TIQN struct contig_item lio_target_cit */

1218 1219
static ssize_t lio_target_wwn_lio_version_show(struct config_item *item,
		char *page)
1220
{
1221
	return sprintf(page, "Datera Inc. iSCSI Target "ISCSIT_VERSION"\n");
1222 1223
}

1224
CONFIGFS_ATTR_RO(lio_target_wwn_, lio_version);
1225 1226

static struct configfs_attribute *lio_target_wwn_attrs[] = {
1227
	&lio_target_wwn_attr_lio_version,
1228 1229 1230
	NULL,
};

1231
static struct se_wwn *lio_target_call_coreaddtiqn(
1232 1233 1234 1235 1236 1237 1238 1239
	struct target_fabric_configfs *tf,
	struct config_group *group,
	const char *name)
{
	struct iscsi_tiqn *tiqn;

	tiqn = iscsit_add_tiqn((unsigned char *)name);
	if (IS_ERR(tiqn))
1240
		return ERR_CAST(tiqn);
1241

1242
	config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_instance_group,
1243
			"iscsi_instance", &iscsi_stat_instance_cit);
1244 1245 1246
	configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_instance_group,
			&tiqn->tiqn_wwn.fabric_stat_group);

1247
	config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_sess_err_group,
1248
			"iscsi_sess_err", &iscsi_stat_sess_err_cit);
1249 1250 1251
	configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_sess_err_group,
			&tiqn->tiqn_wwn.fabric_stat_group);

1252
	config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group,
1253
			"iscsi_tgt_attr", &iscsi_stat_tgt_attr_cit);
1254 1255 1256
	configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group,
			&tiqn->tiqn_wwn.fabric_stat_group);

1257
	config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_login_stats_group,
1258
			"iscsi_login_stats", &iscsi_stat_login_cit);
1259 1260 1261
	configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_login_stats_group,
			&tiqn->tiqn_wwn.fabric_stat_group);

1262
	config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group,
1263
			"iscsi_logout_stats", &iscsi_stat_logout_cit);
1264 1265 1266
	configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group,
			&tiqn->tiqn_wwn.fabric_stat_group);

1267 1268 1269 1270 1271 1272 1273

	pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
	pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated Node:"
			" %s\n", name);
	return &tiqn->tiqn_wwn;
}

1274
static void lio_target_call_coredeltiqn(
1275 1276 1277
	struct se_wwn *wwn)
{
	struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1278 1279

	configfs_remove_default_groups(&tiqn->tiqn_wwn.fabric_stat_group);
1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291

	pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s\n",
			tiqn->tiqn);
	iscsit_del_tiqn(tiqn);
}

/* End LIO-Target TIQN struct contig_lio_target_cit */

/* Start lio_target_discovery_auth_cit */

#define DEF_DISC_AUTH_STR(name, flags)					\
	__DEF_NACL_AUTH_STR(disc, name, flags)				\
1292
static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
1293
{									\
1294
	return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl,\
1295 1296
		page);							\
}									\
1297 1298
static ssize_t iscsi_disc_##name##_store(struct config_item *item,	\
		const char *page, size_t count)				\
1299
{									\
1300
	return __iscsi_disc_##name##_store(&iscsit_global->discovery_acl,	\
1301
		page, count);						\
1302 1303 1304 1305 1306 1307 1308 1309
									\
}									\
CONFIGFS_ATTR(iscsi_disc_, name)

DEF_DISC_AUTH_STR(userid, NAF_USERID_SET);
DEF_DISC_AUTH_STR(password, NAF_PASSWORD_SET);
DEF_DISC_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
DEF_DISC_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
1310 1311 1312

#define DEF_DISC_AUTH_INT(name)						\
	__DEF_NACL_AUTH_INT(disc, name)					\
1313
static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
1314
{									\
1315
	return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl, \
1316
			page);						\
1317 1318
}									\
CONFIGFS_ATTR_RO(iscsi_disc_, name)
1319 1320 1321

DEF_DISC_AUTH_INT(authenticate_target);

1322 1323 1324

static ssize_t iscsi_disc_enforce_discovery_auth_show(struct config_item *item,
		char *page)
1325 1326 1327 1328 1329 1330
{
	struct iscsi_node_auth *discovery_auth = &iscsit_global->discovery_acl.node_auth;

	return sprintf(page, "%d\n", discovery_auth->enforce_discovery_auth);
}

1331 1332
static ssize_t iscsi_disc_enforce_discovery_auth_store(struct config_item *item,
		const char *page, size_t count)
1333 1334 1335 1336
{
	struct iscsi_param *param;
	struct iscsi_portal_group *discovery_tpg = iscsit_global->discovery_tpg;
	u32 op;
1337
	int err;
1338

1339 1340 1341
	err = kstrtou32(page, 0, &op);
	if (err)
		return -EINVAL;
1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386
	if ((op != 1) && (op != 0)) {
		pr_err("Illegal value for enforce_discovery_auth:"
				" %u\n", op);
		return -EINVAL;
	}

	if (!discovery_tpg) {
		pr_err("iscsit_global->discovery_tpg is NULL\n");
		return -EINVAL;
	}

	param = iscsi_find_param_from_key(AUTHMETHOD,
				discovery_tpg->param_list);
	if (!param)
		return -EINVAL;

	if (op) {
		/*
		 * Reset the AuthMethod key to CHAP.
		 */
		if (iscsi_update_param_value(param, CHAP) < 0)
			return -EINVAL;

		discovery_tpg->tpg_attrib.authentication = 1;
		iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 1;
		pr_debug("LIO-CORE[0] Successfully enabled"
			" authentication enforcement for iSCSI"
			" Discovery TPG\n");
	} else {
		/*
		 * Reset the AuthMethod key to CHAP,None
		 */
		if (iscsi_update_param_value(param, "CHAP,None") < 0)
			return -EINVAL;

		discovery_tpg->tpg_attrib.authentication = 0;
		iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 0;
		pr_debug("LIO-CORE[0] Successfully disabled"
			" authentication enforcement for iSCSI"
			" Discovery TPG\n");
	}

	return count;
}

1387
CONFIGFS_ATTR(iscsi_disc_, enforce_discovery_auth);
1388 1389

static struct configfs_attribute *lio_target_discovery_auth_attrs[] = {
1390 1391 1392 1393 1394 1395
	&iscsi_disc_attr_userid,
	&iscsi_disc_attr_password,
	&iscsi_disc_attr_authenticate_target,
	&iscsi_disc_attr_userid_mutual,
	&iscsi_disc_attr_password_mutual,
	&iscsi_disc_attr_enforce_discovery_auth,
1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430
	NULL,
};

/* End lio_target_discovery_auth_cit */

/* Start functions for target_core_fabric_ops */

static char *iscsi_get_fabric_name(void)
{
	return "iSCSI";
}

static int iscsi_get_cmd_state(struct se_cmd *se_cmd)
{
	struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);

	return cmd->i_state;
}

static u32 lio_sess_get_index(struct se_session *se_sess)
{
	struct iscsi_session *sess = se_sess->fabric_sess_ptr;

	return sess->session_index;
}

static u32 lio_sess_get_initiator_sid(
	struct se_session *se_sess,
	unsigned char *buf,
	u32 size)
{
	struct iscsi_session *sess = se_sess->fabric_sess_ptr;
	/*
	 * iSCSI Initiator Session Identifier from RFC-3720.
	 */
1431
	return snprintf(buf, size, "%6phN", sess->isid);
1432 1433 1434 1435 1436 1437 1438
}

static int lio_queue_data_in(struct se_cmd *se_cmd)
{
	struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);

	cmd->i_state = ISTATE_SEND_DATAIN;
1439 1440
	cmd->conn->conn_transport->iscsit_queue_data_in(cmd->conn, cmd);

1441 1442 1443 1444 1445 1446
	return 0;
}

static int lio_write_pending(struct se_cmd *se_cmd)
{
	struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1447
	struct iscsi_conn *conn = cmd->conn;
1448 1449

	if (!cmd->immediate_data && !cmd->unsolicited_data)
1450
		return conn->conn_transport->iscsit_get_dataout(conn, cmd, false);
1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471

	return 0;
}

static int lio_write_pending_status(struct se_cmd *se_cmd)
{
	struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
	int ret;

	spin_lock_bh(&cmd->istate_lock);
	ret = !(cmd->cmd_flags & ICF_GOT_LAST_DATAOUT);
	spin_unlock_bh(&cmd->istate_lock);

	return ret;
}

static int lio_queue_status(struct se_cmd *se_cmd)
{
	struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);

	cmd->i_state = ISTATE_SEND_STATUS;
1472 1473 1474 1475 1476

	if (cmd->se_cmd.scsi_status || cmd->sense_reason) {
		iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
		return 0;
	}
1477 1478
	cmd->conn->conn_transport->iscsit_queue_status(cmd->conn, cmd);

1479 1480 1481
	return 0;
}

1482
static void lio_queue_tm_rsp(struct se_cmd *se_cmd)
1483 1484 1485 1486 1487 1488 1489
{
	struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);

	cmd->i_state = ISTATE_SEND_TASKMGTRSP;
	iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
}

1490 1491 1492 1493 1494 1495 1496
static void lio_aborted_task(struct se_cmd *se_cmd)
{
	struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);

	cmd->conn->conn_transport->iscsit_aborted_task(cmd->conn, cmd);
}

1497
static inline struct iscsi_portal_group *iscsi_tpg(struct se_portal_group *se_tpg)
1498
{
1499 1500
	return container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
}
1501

1502 1503 1504
static char *lio_tpg_get_endpoint_wwn(struct se_portal_group *se_tpg)
{
	return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn;
1505 1506 1507 1508
}

static u16 lio_tpg_get_tag(struct se_portal_group *se_tpg)
{
1509
	return iscsi_tpg(se_tpg)->tpgt;
1510 1511 1512 1513
}

static u32 lio_tpg_get_default_depth(struct se_portal_group *se_tpg)
{
1514
	return iscsi_tpg(se_tpg)->tpg_attrib.default_cmdsn_depth;
1515 1516 1517 1518
}

static int lio_tpg_check_demo_mode(struct se_portal_group *se_tpg)
{
1519
	return iscsi_tpg(se_tpg)->tpg_attrib.generate_node_acls;
1520 1521 1522 1523
}

static int lio_tpg_check_demo_mode_cache(struct se_portal_group *se_tpg)
{
1524
	return iscsi_tpg(se_tpg)->tpg_attrib.cache_dynamic_acls;
1525 1526 1527 1528 1529
}

static int lio_tpg_check_demo_mode_write_protect(
	struct se_portal_group *se_tpg)
{
1530
	return iscsi_tpg(se_tpg)->tpg_attrib.demo_mode_write_protect;
1531 1532 1533 1534 1535
}

static int lio_tpg_check_prod_mode_write_protect(
	struct se_portal_group *se_tpg)
{
1536
	return iscsi_tpg(se_tpg)->tpg_attrib.prod_mode_write_protect;
1537 1538
}

1539 1540 1541 1542 1543 1544 1545
static int lio_tpg_check_prot_fabric_only(
	struct se_portal_group *se_tpg)
{
	/*
	 * Only report fabric_prot_type if t10_pi has also been enabled
	 * for incoming ib_isert sessions.
	 */
1546
	if (!iscsi_tpg(se_tpg)->tpg_attrib.t10_pi)
1547
		return 0;
1548
	return iscsi_tpg(se_tpg)->tpg_attrib.fabric_prot_type;
1549 1550
}

1551
/*
1552
 * This function calls iscsit_inc_session_usage_count() on the
1553 1554 1555 1556 1557
 * struct iscsi_session in question.
 */
static int lio_tpg_shutdown_session(struct se_session *se_sess)
{
	struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1558
	struct se_portal_group *se_tpg = &sess->tpg->tpg_se_tpg;
1559

1560
	spin_lock_bh(&se_tpg->session_lock);
1561 1562 1563 1564 1565
	spin_lock(&sess->conn_lock);
	if (atomic_read(&sess->session_fall_back_to_erl0) ||
	    atomic_read(&sess->session_logout) ||
	    (sess->time2retain_timer_flags & ISCSI_TF_EXPIRED)) {
		spin_unlock(&sess->conn_lock);
1566
		spin_unlock_bh(&se_tpg->session_lock);
1567 1568 1569 1570 1571 1572
		return 0;
	}
	atomic_set(&sess->session_reinstatement, 1);
	spin_unlock(&sess->conn_lock);

	iscsit_stop_time2retain_timer(sess);
1573
	spin_unlock_bh(&se_tpg->session_lock);
1574

1575
	iscsit_stop_session(sess, 1, 1);
1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594
	return 1;
}

/*
 * Calls iscsit_dec_session_usage_count() as inverse of
 * lio_tpg_shutdown_session()
 */
static void lio_tpg_close_session(struct se_session *se_sess)
{
	struct iscsi_session *sess = se_sess->fabric_sess_ptr;
	/*
	 * If the iSCSI Session for the iSCSI Initiator Node exists,
	 * forcefully shutdown the iSCSI NEXUS.
	 */
	iscsit_close_session(sess);
}

static u32 lio_tpg_get_inst_index(struct se_portal_group *se_tpg)
{
1595
	return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn_index;
1596 1597 1598 1599 1600 1601
}

static void lio_set_default_node_attributes(struct se_node_acl *se_acl)
{
	struct iscsi_node_acl *acl = container_of(se_acl, struct iscsi_node_acl,
				se_node_acl);
1602 1603 1604
	struct se_portal_group *se_tpg = se_acl->se_tpg;
	struct iscsi_portal_group *tpg = container_of(se_tpg,
				struct iscsi_portal_group, tpg_se_tpg);
1605

1606
	acl->node_attrib.nacl = acl;
1607
	iscsit_set_default_node_attribues(acl, tpg);
1608 1609
}

1610 1611
static int lio_check_stop_free(struct se_cmd *se_cmd)
{
1612
	return target_put_sess_cmd(se_cmd);
1613 1614
}

1615 1616 1617 1618
static void lio_release_cmd(struct se_cmd *se_cmd)
{
	struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);

1619
	pr_debug("Entering lio_release_cmd for se_cmd: %p\n", se_cmd);
1620
	iscsit_release_cmd(cmd);
1621 1622
}

1623 1624 1625
const struct target_core_fabric_ops iscsi_ops = {
	.module				= THIS_MODULE,
	.name				= "iscsi",
1626
	.node_acl_size			= sizeof(struct iscsi_node_acl),
1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658
	.get_fabric_name		= iscsi_get_fabric_name,
	.tpg_get_wwn			= lio_tpg_get_endpoint_wwn,
	.tpg_get_tag			= lio_tpg_get_tag,
	.tpg_get_default_depth		= lio_tpg_get_default_depth,
	.tpg_check_demo_mode		= lio_tpg_check_demo_mode,
	.tpg_check_demo_mode_cache	= lio_tpg_check_demo_mode_cache,
	.tpg_check_demo_mode_write_protect =
			lio_tpg_check_demo_mode_write_protect,
	.tpg_check_prod_mode_write_protect =
			lio_tpg_check_prod_mode_write_protect,
	.tpg_check_prot_fabric_only	= &lio_tpg_check_prot_fabric_only,
	.tpg_get_inst_index		= lio_tpg_get_inst_index,
	.check_stop_free		= lio_check_stop_free,
	.release_cmd			= lio_release_cmd,
	.shutdown_session		= lio_tpg_shutdown_session,
	.close_session			= lio_tpg_close_session,
	.sess_get_index			= lio_sess_get_index,
	.sess_get_initiator_sid		= lio_sess_get_initiator_sid,
	.write_pending			= lio_write_pending,
	.write_pending_status		= lio_write_pending_status,
	.set_default_node_attributes	= lio_set_default_node_attributes,
	.get_cmd_state			= iscsi_get_cmd_state,
	.queue_data_in			= lio_queue_data_in,
	.queue_status			= lio_queue_status,
	.queue_tm_rsp			= lio_queue_tm_rsp,
	.aborted_task			= lio_aborted_task,
	.fabric_make_wwn		= lio_target_call_coreaddtiqn,
	.fabric_drop_wwn		= lio_target_call_coredeltiqn,
	.fabric_make_tpg		= lio_target_tiqn_addtpg,
	.fabric_drop_tpg		= lio_target_tiqn_deltpg,
	.fabric_make_np			= lio_target_call_addnptotpg,
	.fabric_drop_np			= lio_target_call_delnpfromtpg,
1659
	.fabric_init_nodeacl		= lio_target_init_nodeacl,
1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672

	.tfc_discovery_attrs		= lio_target_discovery_auth_attrs,
	.tfc_wwn_attrs			= lio_target_wwn_attrs,
	.tfc_tpg_base_attrs		= lio_target_tpg_attrs,
	.tfc_tpg_attrib_attrs		= lio_target_tpg_attrib_attrs,
	.tfc_tpg_auth_attrs		= lio_target_tpg_auth_attrs,
	.tfc_tpg_param_attrs		= lio_target_tpg_param_attrs,
	.tfc_tpg_np_base_attrs		= lio_target_portal_attrs,
	.tfc_tpg_nacl_base_attrs	= lio_target_initiator_attrs,
	.tfc_tpg_nacl_attrib_attrs	= lio_target_nacl_attrib_attrs,
	.tfc_tpg_nacl_auth_attrs	= lio_target_nacl_auth_attrs,
	.tfc_tpg_nacl_param_attrs	= lio_target_nacl_param_attrs,
};