Commit d4b3fa4b authored by Nicholas Bellinger's avatar Nicholas Bellinger

iscsi-target: Make iscsi_tpg_np driver show/store use generic code

Go ahead and fold the duplicate iscsi_tpg_np driver attribute
show/store functions into generic callers, invoked by current
driver specific functions.

This allows for future v4.8+ changes to have iscsi_target_mod
use tpg_np driver attributes at runtime, instead of having
the defaults hardcoded in iscsi_target_configfs.c.

Also, drop the unused/legacy 'sctp' attribute for non standard
RFC-3720 operation with IPPROTO_SCTP.

Cc: Varun Prakash <varun@chelsio.com>
Cc: Hariprasad Shenai <hariprasad@chelsio.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: default avatarNicholas Bellinger <nab@linux-iscsi.org>
parent 54a5e73f
...@@ -43,14 +43,15 @@ static inline struct iscsi_tpg_np *to_iscsi_tpg_np(struct config_item *item) ...@@ -43,14 +43,15 @@ 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); 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) static ssize_t lio_target_np_driver_show(struct config_item *item, char *page,
enum iscsit_transport_type type)
{ {
struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item); struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
struct iscsi_tpg_np *tpg_np_sctp; struct iscsi_tpg_np *tpg_np_new;
ssize_t rb; ssize_t rb;
tpg_np_sctp = iscsit_tpg_locate_child_np(tpg_np, ISCSI_SCTP_TCP); tpg_np_new = iscsit_tpg_locate_child_np(tpg_np, type);
if (tpg_np_sctp) if (tpg_np_new)
rb = sprintf(page, "1\n"); rb = sprintf(page, "1\n");
else else
rb = sprintf(page, "0\n"); rb = sprintf(page, "0\n");
...@@ -58,86 +59,20 @@ static ssize_t lio_target_np_sctp_show(struct config_item *item, char *page) ...@@ -58,86 +59,20 @@ static ssize_t lio_target_np_sctp_show(struct config_item *item, char *page)
return rb; return rb;
} }
static ssize_t lio_target_np_sctp_store(struct config_item *item, static ssize_t lio_target_np_driver_store(struct config_item *item,
const char *page, size_t count) const char *page, size_t count, enum iscsit_transport_type type,
const char *mod_name)
{ {
struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item); struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
struct iscsi_np *np; struct iscsi_np *np;
struct iscsi_portal_group *tpg; struct iscsi_portal_group *tpg;
struct iscsi_tpg_np *tpg_np_sctp = NULL; struct iscsi_tpg_np *tpg_np_new = NULL;
u32 op; u32 op;
int ret; int rc;
ret = kstrtou32(page, 0, &op);
if (ret)
return ret;
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,
tpg_np, ISCSI_SCTP_TCP);
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); rc = kstrtou32(page, 0, &op);
return count; if (rc)
out: return rc;
iscsit_put_tpg(tpg);
return -EINVAL;
}
static ssize_t lio_target_np_iser_show(struct config_item *item, char *page)
{
struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
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;
}
static ssize_t lio_target_np_iser_store(struct config_item *item,
const char *page, size_t count)
{
struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
struct iscsi_np *np;
struct iscsi_portal_group *tpg;
struct iscsi_tpg_np *tpg_np_iser = NULL;
char *endptr;
u32 op;
int rc = 0;
op = simple_strtoul(page, &endptr, 0);
if ((op != 1) && (op != 0)) { if ((op != 1) && (op != 0)) {
pr_err("Illegal value for tpg_enable: %u\n", op); pr_err("Illegal value for tpg_enable: %u\n", op);
return -EINVAL; return -EINVAL;
...@@ -154,22 +89,23 @@ static ssize_t lio_target_np_iser_store(struct config_item *item, ...@@ -154,22 +89,23 @@ static ssize_t lio_target_np_iser_store(struct config_item *item,
return -EINVAL; return -EINVAL;
if (op) { if (op) {
rc = request_module("ib_isert"); if (strlen(mod_name)) {
rc = request_module(mod_name);
if (rc != 0) { if (rc != 0) {
pr_warn("Unable to request_module for ib_isert\n"); pr_warn("Unable to request_module for %s\n",
mod_name);
rc = 0; rc = 0;
} }
}
tpg_np_iser = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr, tpg_np_new = iscsit_tpg_add_network_portal(tpg,
tpg_np, ISCSI_INFINIBAND); &np->np_sockaddr, tpg_np, type);
if (IS_ERR(tpg_np_iser)) { if (IS_ERR(tpg_np_new))
rc = PTR_ERR(tpg_np_iser);
goto out; goto out;
}
} else { } else {
tpg_np_iser = iscsit_tpg_locate_child_np(tpg_np, ISCSI_INFINIBAND); tpg_np_new = iscsit_tpg_locate_child_np(tpg_np, type);
if (tpg_np_iser) { if (tpg_np_new) {
rc = iscsit_tpg_del_network_portal(tpg, tpg_np_iser); rc = iscsit_tpg_del_network_portal(tpg, tpg_np_new);
if (rc < 0) if (rc < 0)
goto out; goto out;
} }
...@@ -182,86 +118,33 @@ static ssize_t lio_target_np_iser_store(struct config_item *item, ...@@ -182,86 +118,33 @@ static ssize_t lio_target_np_iser_store(struct config_item *item,
return rc; return rc;
} }
static ssize_t lio_target_np_hw_offload_show(struct config_item *item, static ssize_t lio_target_np_iser_show(struct config_item *item, char *page)
char *page)
{ {
struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item); return lio_target_np_driver_show(item, page, ISCSI_INFINIBAND);
struct iscsi_tpg_np *tpg_np_hw_offload; }
ssize_t rb;
tpg_np_hw_offload = iscsit_tpg_locate_child_np(tpg_np, static ssize_t lio_target_np_iser_store(struct config_item *item,
ISCSI_HW_OFFLOAD); const char *page, size_t count)
if (tpg_np_hw_offload) {
rb = sprintf(page, "1\n"); return lio_target_np_driver_store(item, page, count,
else ISCSI_INFINIBAND, "ib_isert");
rb = sprintf(page, "0\n"); }
CONFIGFS_ATTR(lio_target_np_, iser);
return rb; static ssize_t lio_target_np_hw_offload_show(struct config_item *item, char *page)
{
return lio_target_np_driver_show(item, page, ISCSI_HW_OFFLOAD);
} }
static ssize_t lio_target_np_hw_offload_store(struct config_item *item, static ssize_t lio_target_np_hw_offload_store(struct config_item *item,
const char *page, size_t count) const char *page, size_t count)
{ {
struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item); return lio_target_np_driver_store(item, page, count,
struct iscsi_np *np; ISCSI_HW_OFFLOAD, "");
struct iscsi_portal_group *tpg;
struct iscsi_tpg_np *tpg_np_hw_offload = NULL;
u32 op;
int rc = 0;
rc = kstrtou32(page, 0, &op);
if (rc)
return rc;
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) {
tpg_np_hw_offload = iscsit_tpg_add_network_portal(tpg,
&np->np_sockaddr, tpg_np, ISCSI_HW_OFFLOAD);
if (IS_ERR(tpg_np_hw_offload)) {
rc = PTR_ERR(tpg_np_hw_offload);
goto out;
}
} else {
tpg_np_hw_offload = iscsit_tpg_locate_child_np(tpg_np,
ISCSI_HW_OFFLOAD);
if (tpg_np_hw_offload) {
rc = iscsit_tpg_del_network_portal(tpg,
tpg_np_hw_offload);
if (rc < 0)
goto out;
}
}
iscsit_put_tpg(tpg);
return count;
out:
iscsit_put_tpg(tpg);
return rc;
} }
CONFIGFS_ATTR(lio_target_np_, sctp);
CONFIGFS_ATTR(lio_target_np_, iser);
CONFIGFS_ATTR(lio_target_np_, hw_offload); CONFIGFS_ATTR(lio_target_np_, hw_offload);
static struct configfs_attribute *lio_target_portal_attrs[] = { static struct configfs_attribute *lio_target_portal_attrs[] = {
&lio_target_np_attr_sctp,
&lio_target_np_attr_iser, &lio_target_np_attr_iser,
&lio_target_np_attr_hw_offload, &lio_target_np_attr_hw_offload,
NULL, NULL,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment