/*******************************************************************************
* This file contains the configfs implementation for iSCSI Target mode
* from the LIO-Target Project.
*
* (c) Copyright 2007-2013 Datera, Inc.
*
* 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>
#include <linux/ctype.h>
#include <linux/export.h>
#include <linux/inet.h>
#include <target/target_core_base.h>
#include <target/target_core_fabric.h>
#include <target/iscsi/iscsi_transport.h>
#include <target/iscsi/iscsi_target_core.h>
#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"
#include <target/iscsi/iscsi_target_stat.h>
/* Start items for lio_target_portal_cit */
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_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_new;
ssize_t rb;
tpg_np_new = iscsit_tpg_locate_child_np(tpg_np, type);
if (tpg_np_new)
rb = sprintf(page, "1\n");
else
rb = sprintf(page, "0\n");
return rb;
}
static ssize_t lio_target_np_driver_store(struct config_item *item,
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_np *np;
struct iscsi_portal_group *tpg;
struct iscsi_tpg_np *tpg_np_new = NULL;
u32 op;
int rc;
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) {
if (strlen(mod_name)) {
rc = request_module(mod_name);
if (rc != 0) {
pr_warn("Unable to request_module for %s\n",
mod_name);
rc = 0;
}
}
tpg_np_new = iscsit_tpg_add_network_portal(tpg,
&np->np_sockaddr, tpg_np, type);
if (IS_ERR(tpg_np_new))
goto out;
} else {
tpg_np_new = iscsit_tpg_locate_child_np(tpg_np, type);
if (tpg_np_new) {
rc = iscsit_tpg_del_network_portal(tpg, tpg_np_new);
if (rc < 0)
goto out;
}
}
iscsit_put_tpg(tpg);
return count;
out:
iscsit_put_tpg(tpg);
return rc;
}
static ssize_t lio_target_np_iser_show(struct config_item *item, char *page)
{
return lio_target_np_driver_show(item, page, ISCSI_INFINIBAND);
}
static ssize_t lio_target_np_iser_store(struct config_item *item,
const char *page, size_t count)
{
return lio_target_np_driver_store(item, page, count,
ISCSI_INFINIBAND, "ib_isert");
}
CONFIGFS_ATTR(lio_target_np_, iser);
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,
const char *page, size_t count)
{
return lio_target_np_dr
|