1c66ac9dbSNicholas Bellinger /******************************************************************************* 2c66ac9dbSNicholas Bellinger * Filename: target_core_configfs.c 3c66ac9dbSNicholas Bellinger * 4c66ac9dbSNicholas Bellinger * This file contains ConfigFS logic for the Generic Target Engine project. 5c66ac9dbSNicholas Bellinger * 64c76251eSNicholas Bellinger * (c) Copyright 2008-2013 Datera, Inc. 7c66ac9dbSNicholas Bellinger * 8c66ac9dbSNicholas Bellinger * Nicholas A. Bellinger <nab@kernel.org> 9c66ac9dbSNicholas Bellinger * 10c66ac9dbSNicholas Bellinger * based on configfs Copyright (C) 2005 Oracle. All rights reserved. 11c66ac9dbSNicholas Bellinger * 12c66ac9dbSNicholas Bellinger * This program is free software; you can redistribute it and/or modify 13c66ac9dbSNicholas Bellinger * it under the terms of the GNU General Public License as published by 14c66ac9dbSNicholas Bellinger * the Free Software Foundation; either version 2 of the License, or 15c66ac9dbSNicholas Bellinger * (at your option) any later version. 16c66ac9dbSNicholas Bellinger * 17c66ac9dbSNicholas Bellinger * This program is distributed in the hope that it will be useful, 18c66ac9dbSNicholas Bellinger * but WITHOUT ANY WARRANTY; without even the implied warranty of 19c66ac9dbSNicholas Bellinger * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20c66ac9dbSNicholas Bellinger * GNU General Public License for more details. 21c66ac9dbSNicholas Bellinger ****************************************************************************/ 22c66ac9dbSNicholas Bellinger 23c66ac9dbSNicholas Bellinger #include <linux/module.h> 24c66ac9dbSNicholas Bellinger #include <linux/moduleparam.h> 25c66ac9dbSNicholas Bellinger #include <generated/utsrelease.h> 26c66ac9dbSNicholas Bellinger #include <linux/utsname.h> 27c66ac9dbSNicholas Bellinger #include <linux/init.h> 28c66ac9dbSNicholas Bellinger #include <linux/fs.h> 29c66ac9dbSNicholas Bellinger #include <linux/namei.h> 30c66ac9dbSNicholas Bellinger #include <linux/slab.h> 31c66ac9dbSNicholas Bellinger #include <linux/types.h> 32c66ac9dbSNicholas Bellinger #include <linux/delay.h> 33c66ac9dbSNicholas Bellinger #include <linux/unistd.h> 34c66ac9dbSNicholas Bellinger #include <linux/string.h> 35c66ac9dbSNicholas Bellinger #include <linux/parser.h> 36c66ac9dbSNicholas Bellinger #include <linux/syscalls.h> 37c66ac9dbSNicholas Bellinger #include <linux/configfs.h> 38e3d6f909SAndy Grover #include <linux/spinlock.h> 39c66ac9dbSNicholas Bellinger 40c66ac9dbSNicholas Bellinger #include <target/target_core_base.h> 41c4795fb2SChristoph Hellwig #include <target/target_core_backend.h> 42c4795fb2SChristoph Hellwig #include <target/target_core_fabric.h> 43c66ac9dbSNicholas Bellinger 44e26d99aeSChristoph Hellwig #include "target_core_internal.h" 45c66ac9dbSNicholas Bellinger #include "target_core_alua.h" 46c66ac9dbSNicholas Bellinger #include "target_core_pr.h" 47c66ac9dbSNicholas Bellinger #include "target_core_rd.h" 48f99715acSNicholas Bellinger #include "target_core_xcopy.h" 49c66ac9dbSNicholas Bellinger 5073112edcSNicholas Bellinger #define TB_CIT_SETUP(_name, _item_ops, _group_ops, _attrs) \ 510a06d430SChristoph Hellwig static void target_core_setup_##_name##_cit(struct target_backend *tb) \ 5273112edcSNicholas Bellinger { \ 530a06d430SChristoph Hellwig struct config_item_type *cit = &tb->tb_##_name##_cit; \ 5473112edcSNicholas Bellinger \ 5573112edcSNicholas Bellinger cit->ct_item_ops = _item_ops; \ 5673112edcSNicholas Bellinger cit->ct_group_ops = _group_ops; \ 5773112edcSNicholas Bellinger cit->ct_attrs = _attrs; \ 580a06d430SChristoph Hellwig cit->ct_owner = tb->ops->owner; \ 590a06d430SChristoph Hellwig pr_debug("Setup generic %s\n", __stringify(_name)); \ 600a06d430SChristoph Hellwig } 610a06d430SChristoph Hellwig 620a06d430SChristoph Hellwig #define TB_CIT_SETUP_DRV(_name, _item_ops, _group_ops) \ 630a06d430SChristoph Hellwig static void target_core_setup_##_name##_cit(struct target_backend *tb) \ 640a06d430SChristoph Hellwig { \ 650a06d430SChristoph Hellwig struct config_item_type *cit = &tb->tb_##_name##_cit; \ 660a06d430SChristoph Hellwig \ 670a06d430SChristoph Hellwig cit->ct_item_ops = _item_ops; \ 680a06d430SChristoph Hellwig cit->ct_group_ops = _group_ops; \ 690a06d430SChristoph Hellwig cit->ct_attrs = tb->ops->tb_##_name##_attrs; \ 700a06d430SChristoph Hellwig cit->ct_owner = tb->ops->owner; \ 7173112edcSNicholas Bellinger pr_debug("Setup generic %s\n", __stringify(_name)); \ 7273112edcSNicholas Bellinger } 7373112edcSNicholas Bellinger 74e3d6f909SAndy Grover extern struct t10_alua_lu_gp *default_lu_gp; 75e3d6f909SAndy Grover 76d0f474e5SRoland Dreier static LIST_HEAD(g_tf_list); 77d0f474e5SRoland Dreier static DEFINE_MUTEX(g_tf_lock); 78c66ac9dbSNicholas Bellinger 79e3d6f909SAndy Grover static struct config_group target_core_hbagroup; 80e3d6f909SAndy Grover static struct config_group alua_group; 81e3d6f909SAndy Grover static struct config_group alua_lu_gps_group; 82e3d6f909SAndy Grover 83c66ac9dbSNicholas Bellinger static inline struct se_hba * 84c66ac9dbSNicholas Bellinger item_to_hba(struct config_item *item) 85c66ac9dbSNicholas Bellinger { 86c66ac9dbSNicholas Bellinger return container_of(to_config_group(item), struct se_hba, hba_group); 87c66ac9dbSNicholas Bellinger } 88c66ac9dbSNicholas Bellinger 89c66ac9dbSNicholas Bellinger /* 90c66ac9dbSNicholas Bellinger * Attributes for /sys/kernel/config/target/ 91c66ac9dbSNicholas Bellinger */ 922eafd729SChristoph Hellwig static ssize_t target_core_item_version_show(struct config_item *item, 93c66ac9dbSNicholas Bellinger char *page) 94c66ac9dbSNicholas Bellinger { 95c66ac9dbSNicholas Bellinger return sprintf(page, "Target Engine Core ConfigFS Infrastructure %s" 96ce8dd25dSChristoph Hellwig " on %s/%s on "UTS_RELEASE"\n", TARGET_CORE_VERSION, 97c66ac9dbSNicholas Bellinger utsname()->sysname, utsname()->machine); 98c66ac9dbSNicholas Bellinger } 99c66ac9dbSNicholas Bellinger 1002eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_core_item_, version); 101c66ac9dbSNicholas Bellinger 102a96e9783SLee Duncan char db_root[DB_ROOT_LEN] = DB_ROOT_DEFAULT; 103a96e9783SLee Duncan static char db_root_stage[DB_ROOT_LEN]; 104a96e9783SLee Duncan 105a96e9783SLee Duncan static ssize_t target_core_item_dbroot_show(struct config_item *item, 106a96e9783SLee Duncan char *page) 107a96e9783SLee Duncan { 108a96e9783SLee Duncan return sprintf(page, "%s\n", db_root); 109a96e9783SLee Duncan } 110a96e9783SLee Duncan 111a96e9783SLee Duncan static ssize_t target_core_item_dbroot_store(struct config_item *item, 112a96e9783SLee Duncan const char *page, size_t count) 113a96e9783SLee Duncan { 114a96e9783SLee Duncan ssize_t read_bytes; 115a96e9783SLee Duncan struct file *fp; 116a96e9783SLee Duncan 117a96e9783SLee Duncan mutex_lock(&g_tf_lock); 118a96e9783SLee Duncan if (!list_empty(&g_tf_list)) { 119a96e9783SLee Duncan mutex_unlock(&g_tf_lock); 120a96e9783SLee Duncan pr_err("db_root: cannot be changed: target drivers registered"); 121a96e9783SLee Duncan return -EINVAL; 122a96e9783SLee Duncan } 123a96e9783SLee Duncan 124a96e9783SLee Duncan if (count > (DB_ROOT_LEN - 1)) { 125a96e9783SLee Duncan mutex_unlock(&g_tf_lock); 126a96e9783SLee Duncan pr_err("db_root: count %d exceeds DB_ROOT_LEN-1: %u\n", 127a96e9783SLee Duncan (int)count, DB_ROOT_LEN - 1); 128a96e9783SLee Duncan return -EINVAL; 129a96e9783SLee Duncan } 130a96e9783SLee Duncan 131a96e9783SLee Duncan read_bytes = snprintf(db_root_stage, DB_ROOT_LEN, "%s", page); 132a96e9783SLee Duncan if (!read_bytes) { 133a96e9783SLee Duncan mutex_unlock(&g_tf_lock); 134a96e9783SLee Duncan return -EINVAL; 135a96e9783SLee Duncan } 136a96e9783SLee Duncan if (db_root_stage[read_bytes - 1] == '\n') 137a96e9783SLee Duncan db_root_stage[read_bytes - 1] = '\0'; 138a96e9783SLee Duncan 139a96e9783SLee Duncan /* validate new db root before accepting it */ 140a96e9783SLee Duncan fp = filp_open(db_root_stage, O_RDONLY, 0); 141a96e9783SLee Duncan if (IS_ERR(fp)) { 142a96e9783SLee Duncan mutex_unlock(&g_tf_lock); 143a96e9783SLee Duncan pr_err("db_root: cannot open: %s\n", db_root_stage); 144a96e9783SLee Duncan return -EINVAL; 145a96e9783SLee Duncan } 14645063097SAl Viro if (!S_ISDIR(file_inode(fp)->i_mode)) { 1478cc3bb07SBart Van Assche filp_close(fp, NULL); 148a96e9783SLee Duncan mutex_unlock(&g_tf_lock); 149a96e9783SLee Duncan pr_err("db_root: not a directory: %s\n", db_root_stage); 150a96e9783SLee Duncan return -EINVAL; 151a96e9783SLee Duncan } 1528cc3bb07SBart Van Assche filp_close(fp, NULL); 153a96e9783SLee Duncan 154a96e9783SLee Duncan strncpy(db_root, db_root_stage, read_bytes); 155a96e9783SLee Duncan 156a96e9783SLee Duncan mutex_unlock(&g_tf_lock); 157a96e9783SLee Duncan 15878a6295cSLee Duncan pr_debug("Target_Core_ConfigFS: db_root set to %s\n", db_root); 15978a6295cSLee Duncan 160a96e9783SLee Duncan return read_bytes; 161a96e9783SLee Duncan } 162a96e9783SLee Duncan 163a96e9783SLee Duncan CONFIGFS_ATTR(target_core_item_, dbroot); 164a96e9783SLee Duncan 165c66ac9dbSNicholas Bellinger static struct target_fabric_configfs *target_core_get_fabric( 166c66ac9dbSNicholas Bellinger const char *name) 167c66ac9dbSNicholas Bellinger { 168c66ac9dbSNicholas Bellinger struct target_fabric_configfs *tf; 169c66ac9dbSNicholas Bellinger 1706708bb27SAndy Grover if (!name) 171c66ac9dbSNicholas Bellinger return NULL; 172c66ac9dbSNicholas Bellinger 173c66ac9dbSNicholas Bellinger mutex_lock(&g_tf_lock); 174c66ac9dbSNicholas Bellinger list_for_each_entry(tf, &g_tf_list, tf_list) { 1750dc2e8d1SChristoph Hellwig if (!strcmp(tf->tf_ops->name, name)) { 176c66ac9dbSNicholas Bellinger atomic_inc(&tf->tf_access_cnt); 177c66ac9dbSNicholas Bellinger mutex_unlock(&g_tf_lock); 178c66ac9dbSNicholas Bellinger return tf; 179c66ac9dbSNicholas Bellinger } 180c66ac9dbSNicholas Bellinger } 181c66ac9dbSNicholas Bellinger mutex_unlock(&g_tf_lock); 182c66ac9dbSNicholas Bellinger 183c66ac9dbSNicholas Bellinger return NULL; 184c66ac9dbSNicholas Bellinger } 185c66ac9dbSNicholas Bellinger 186c66ac9dbSNicholas Bellinger /* 187c66ac9dbSNicholas Bellinger * Called from struct target_core_group_ops->make_group() 188c66ac9dbSNicholas Bellinger */ 189c66ac9dbSNicholas Bellinger static struct config_group *target_core_register_fabric( 190c66ac9dbSNicholas Bellinger struct config_group *group, 191c66ac9dbSNicholas Bellinger const char *name) 192c66ac9dbSNicholas Bellinger { 193c66ac9dbSNicholas Bellinger struct target_fabric_configfs *tf; 194c66ac9dbSNicholas Bellinger int ret; 195c66ac9dbSNicholas Bellinger 1966708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: REGISTER -> group: %p name:" 197c66ac9dbSNicholas Bellinger " %s\n", group, name); 198e7b7af6eSRoland Dreier 199e7b7af6eSRoland Dreier tf = target_core_get_fabric(name); 200e7b7af6eSRoland Dreier if (!tf) { 20162554910SNicholas Bellinger pr_debug("target_core_register_fabric() trying autoload for %s\n", 202e7b7af6eSRoland Dreier name); 203e7b7af6eSRoland Dreier 204c66ac9dbSNicholas Bellinger /* 205c66ac9dbSNicholas Bellinger * Below are some hardcoded request_module() calls to automatically 206c66ac9dbSNicholas Bellinger * local fabric modules when the following is called: 207c66ac9dbSNicholas Bellinger * 208c66ac9dbSNicholas Bellinger * mkdir -p /sys/kernel/config/target/$MODULE_NAME 209c66ac9dbSNicholas Bellinger * 210c66ac9dbSNicholas Bellinger * Note that this does not limit which TCM fabric module can be 211c66ac9dbSNicholas Bellinger * registered, but simply provids auto loading logic for modules with 212c66ac9dbSNicholas Bellinger * mkdir(2) system calls with known TCM fabric modules. 213c66ac9dbSNicholas Bellinger */ 214e7b7af6eSRoland Dreier 2156708bb27SAndy Grover if (!strncmp(name, "iscsi", 5)) { 216c66ac9dbSNicholas Bellinger /* 217c66ac9dbSNicholas Bellinger * Automatically load the LIO Target fabric module when the 218c66ac9dbSNicholas Bellinger * following is called: 219c66ac9dbSNicholas Bellinger * 220c66ac9dbSNicholas Bellinger * mkdir -p $CONFIGFS/target/iscsi 221c66ac9dbSNicholas Bellinger */ 222c66ac9dbSNicholas Bellinger ret = request_module("iscsi_target_mod"); 223c66ac9dbSNicholas Bellinger if (ret < 0) { 22462554910SNicholas Bellinger pr_debug("request_module() failed for" 225c66ac9dbSNicholas Bellinger " iscsi_target_mod.ko: %d\n", ret); 226c66ac9dbSNicholas Bellinger return ERR_PTR(-EINVAL); 227c66ac9dbSNicholas Bellinger } 2286708bb27SAndy Grover } else if (!strncmp(name, "loopback", 8)) { 229c66ac9dbSNicholas Bellinger /* 230c66ac9dbSNicholas Bellinger * Automatically load the tcm_loop fabric module when the 231c66ac9dbSNicholas Bellinger * following is called: 232c66ac9dbSNicholas Bellinger * 233c66ac9dbSNicholas Bellinger * mkdir -p $CONFIGFS/target/loopback 234c66ac9dbSNicholas Bellinger */ 235c66ac9dbSNicholas Bellinger ret = request_module("tcm_loop"); 236c66ac9dbSNicholas Bellinger if (ret < 0) { 23762554910SNicholas Bellinger pr_debug("request_module() failed for" 238c66ac9dbSNicholas Bellinger " tcm_loop.ko: %d\n", ret); 239c66ac9dbSNicholas Bellinger return ERR_PTR(-EINVAL); 240c66ac9dbSNicholas Bellinger } 241c66ac9dbSNicholas Bellinger } 242c66ac9dbSNicholas Bellinger 243c66ac9dbSNicholas Bellinger tf = target_core_get_fabric(name); 244e7b7af6eSRoland Dreier } 245e7b7af6eSRoland Dreier 2466708bb27SAndy Grover if (!tf) { 24762554910SNicholas Bellinger pr_debug("target_core_get_fabric() failed for %s\n", 248c66ac9dbSNicholas Bellinger name); 249c66ac9dbSNicholas Bellinger return ERR_PTR(-EINVAL); 250c66ac9dbSNicholas Bellinger } 2516708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: REGISTER -> Located fabric:" 2520dc2e8d1SChristoph Hellwig " %s\n", tf->tf_ops->name); 253c66ac9dbSNicholas Bellinger /* 254c66ac9dbSNicholas Bellinger * On a successful target_core_get_fabric() look, the returned 255c66ac9dbSNicholas Bellinger * struct target_fabric_configfs *tf will contain a usage reference. 256c66ac9dbSNicholas Bellinger */ 2576708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: REGISTER tfc_wwn_cit -> %p\n", 258968ebe75SChristoph Hellwig &tf->tf_wwn_cit); 259c66ac9dbSNicholas Bellinger 260968ebe75SChristoph Hellwig config_group_init_type_name(&tf->tf_group, name, &tf->tf_wwn_cit); 2611ae1602dSChristoph Hellwig 262c66ac9dbSNicholas Bellinger config_group_init_type_name(&tf->tf_disc_group, "discovery_auth", 263968ebe75SChristoph Hellwig &tf->tf_discovery_cit); 2641ae1602dSChristoph Hellwig configfs_add_default_group(&tf->tf_disc_group, &tf->tf_group); 265c66ac9dbSNicholas Bellinger 2666708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: REGISTER -> Allocated Fabric:" 267c66ac9dbSNicholas Bellinger " %s\n", tf->tf_group.cg_item.ci_name); 268c66ac9dbSNicholas Bellinger return &tf->tf_group; 269c66ac9dbSNicholas Bellinger } 270c66ac9dbSNicholas Bellinger 271c66ac9dbSNicholas Bellinger /* 272c66ac9dbSNicholas Bellinger * Called from struct target_core_group_ops->drop_item() 273c66ac9dbSNicholas Bellinger */ 274c66ac9dbSNicholas Bellinger static void target_core_deregister_fabric( 275c66ac9dbSNicholas Bellinger struct config_group *group, 276c66ac9dbSNicholas Bellinger struct config_item *item) 277c66ac9dbSNicholas Bellinger { 278c66ac9dbSNicholas Bellinger struct target_fabric_configfs *tf = container_of( 279c66ac9dbSNicholas Bellinger to_config_group(item), struct target_fabric_configfs, tf_group); 280c66ac9dbSNicholas Bellinger 2816708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: DEREGISTER -> Looking up %s in" 282c66ac9dbSNicholas Bellinger " tf list\n", config_item_name(item)); 283c66ac9dbSNicholas Bellinger 2846708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: DEREGISTER -> located fabric:" 2850dc2e8d1SChristoph Hellwig " %s\n", tf->tf_ops->name); 286c66ac9dbSNicholas Bellinger atomic_dec(&tf->tf_access_cnt); 287c66ac9dbSNicholas Bellinger 2886708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing ci" 289c66ac9dbSNicholas Bellinger " %s\n", config_item_name(item)); 290c66ac9dbSNicholas Bellinger 2911ae1602dSChristoph Hellwig configfs_remove_default_groups(&tf->tf_group); 292c66ac9dbSNicholas Bellinger config_item_put(item); 293c66ac9dbSNicholas Bellinger } 294c66ac9dbSNicholas Bellinger 295c66ac9dbSNicholas Bellinger static struct configfs_group_operations target_core_fabric_group_ops = { 296c66ac9dbSNicholas Bellinger .make_group = &target_core_register_fabric, 297c66ac9dbSNicholas Bellinger .drop_item = &target_core_deregister_fabric, 298c66ac9dbSNicholas Bellinger }; 299c66ac9dbSNicholas Bellinger 300c66ac9dbSNicholas Bellinger /* 301c66ac9dbSNicholas Bellinger * All item attributes appearing in /sys/kernel/target/ appear here. 302c66ac9dbSNicholas Bellinger */ 303c66ac9dbSNicholas Bellinger static struct configfs_attribute *target_core_fabric_item_attrs[] = { 304c66ac9dbSNicholas Bellinger &target_core_item_attr_version, 305a96e9783SLee Duncan &target_core_item_attr_dbroot, 306c66ac9dbSNicholas Bellinger NULL, 307c66ac9dbSNicholas Bellinger }; 308c66ac9dbSNicholas Bellinger 309c66ac9dbSNicholas Bellinger /* 310c66ac9dbSNicholas Bellinger * Provides Fabrics Groups and Item Attributes for /sys/kernel/config/target/ 311c66ac9dbSNicholas Bellinger */ 312ece550b5SBhumika Goyal static const struct config_item_type target_core_fabrics_item = { 313c66ac9dbSNicholas Bellinger .ct_group_ops = &target_core_fabric_group_ops, 314c66ac9dbSNicholas Bellinger .ct_attrs = target_core_fabric_item_attrs, 315c66ac9dbSNicholas Bellinger .ct_owner = THIS_MODULE, 316c66ac9dbSNicholas Bellinger }; 317c66ac9dbSNicholas Bellinger 318c66ac9dbSNicholas Bellinger static struct configfs_subsystem target_core_fabrics = { 319c66ac9dbSNicholas Bellinger .su_group = { 320c66ac9dbSNicholas Bellinger .cg_item = { 321c66ac9dbSNicholas Bellinger .ci_namebuf = "target", 322c66ac9dbSNicholas Bellinger .ci_type = &target_core_fabrics_item, 323c66ac9dbSNicholas Bellinger }, 324c66ac9dbSNicholas Bellinger }, 325c66ac9dbSNicholas Bellinger }; 326c66ac9dbSNicholas Bellinger 327d588cf8fSChristoph Hellwig int target_depend_item(struct config_item *item) 328d588cf8fSChristoph Hellwig { 329d588cf8fSChristoph Hellwig return configfs_depend_item(&target_core_fabrics, item); 330d588cf8fSChristoph Hellwig } 331d588cf8fSChristoph Hellwig EXPORT_SYMBOL(target_depend_item); 332d588cf8fSChristoph Hellwig 333d588cf8fSChristoph Hellwig void target_undepend_item(struct config_item *item) 334d588cf8fSChristoph Hellwig { 3359a9e3415SKrzysztof Opasiak return configfs_undepend_item(item); 336d588cf8fSChristoph Hellwig } 337d588cf8fSChristoph Hellwig EXPORT_SYMBOL(target_undepend_item); 338c66ac9dbSNicholas Bellinger 339c66ac9dbSNicholas Bellinger /*############################################################################## 340c66ac9dbSNicholas Bellinger // Start functions called by external Target Fabrics Modules 341c66ac9dbSNicholas Bellinger //############################################################################*/ 342c66ac9dbSNicholas Bellinger 3439ac8928eSChristoph Hellwig static int target_fabric_tf_ops_check(const struct target_core_fabric_ops *tfo) 344c66ac9dbSNicholas Bellinger { 3459ac8928eSChristoph Hellwig if (!tfo->name) { 3469ac8928eSChristoph Hellwig pr_err("Missing tfo->name\n"); 3479ac8928eSChristoph Hellwig return -EINVAL; 348c66ac9dbSNicholas Bellinger } 3499ac8928eSChristoph Hellwig if (strlen(tfo->name) >= TARGET_FABRIC_NAME_SIZE) { 3506708bb27SAndy Grover pr_err("Passed name: %s exceeds TARGET_FABRIC" 3519ac8928eSChristoph Hellwig "_NAME_SIZE\n", tfo->name); 3529ac8928eSChristoph Hellwig return -EINVAL; 353c66ac9dbSNicholas Bellinger } 3546708bb27SAndy Grover if (!tfo->get_fabric_name) { 3556708bb27SAndy Grover pr_err("Missing tfo->get_fabric_name()\n"); 356c66ac9dbSNicholas Bellinger return -EINVAL; 357c66ac9dbSNicholas Bellinger } 3586708bb27SAndy Grover if (!tfo->tpg_get_wwn) { 3596708bb27SAndy Grover pr_err("Missing tfo->tpg_get_wwn()\n"); 360c66ac9dbSNicholas Bellinger return -EINVAL; 361c66ac9dbSNicholas Bellinger } 3626708bb27SAndy Grover if (!tfo->tpg_get_tag) { 3636708bb27SAndy Grover pr_err("Missing tfo->tpg_get_tag()\n"); 364c66ac9dbSNicholas Bellinger return -EINVAL; 365c66ac9dbSNicholas Bellinger } 3666708bb27SAndy Grover if (!tfo->tpg_check_demo_mode) { 3676708bb27SAndy Grover pr_err("Missing tfo->tpg_check_demo_mode()\n"); 368c66ac9dbSNicholas Bellinger return -EINVAL; 369c66ac9dbSNicholas Bellinger } 3706708bb27SAndy Grover if (!tfo->tpg_check_demo_mode_cache) { 3716708bb27SAndy Grover pr_err("Missing tfo->tpg_check_demo_mode_cache()\n"); 372c66ac9dbSNicholas Bellinger return -EINVAL; 373c66ac9dbSNicholas Bellinger } 3746708bb27SAndy Grover if (!tfo->tpg_check_demo_mode_write_protect) { 3756708bb27SAndy Grover pr_err("Missing tfo->tpg_check_demo_mode_write_protect()\n"); 376c66ac9dbSNicholas Bellinger return -EINVAL; 377c66ac9dbSNicholas Bellinger } 3786708bb27SAndy Grover if (!tfo->tpg_check_prod_mode_write_protect) { 3796708bb27SAndy Grover pr_err("Missing tfo->tpg_check_prod_mode_write_protect()\n"); 380c66ac9dbSNicholas Bellinger return -EINVAL; 381c66ac9dbSNicholas Bellinger } 3826708bb27SAndy Grover if (!tfo->tpg_get_inst_index) { 3836708bb27SAndy Grover pr_err("Missing tfo->tpg_get_inst_index()\n"); 384c66ac9dbSNicholas Bellinger return -EINVAL; 385c66ac9dbSNicholas Bellinger } 38635462975SChristoph Hellwig if (!tfo->release_cmd) { 3876708bb27SAndy Grover pr_err("Missing tfo->release_cmd()\n"); 388c66ac9dbSNicholas Bellinger return -EINVAL; 389c66ac9dbSNicholas Bellinger } 3906708bb27SAndy Grover if (!tfo->sess_get_index) { 3916708bb27SAndy Grover pr_err("Missing tfo->sess_get_index()\n"); 392c66ac9dbSNicholas Bellinger return -EINVAL; 393c66ac9dbSNicholas Bellinger } 3946708bb27SAndy Grover if (!tfo->write_pending) { 3956708bb27SAndy Grover pr_err("Missing tfo->write_pending()\n"); 396c66ac9dbSNicholas Bellinger return -EINVAL; 397c66ac9dbSNicholas Bellinger } 3986708bb27SAndy Grover if (!tfo->write_pending_status) { 3996708bb27SAndy Grover pr_err("Missing tfo->write_pending_status()\n"); 400c66ac9dbSNicholas Bellinger return -EINVAL; 401c66ac9dbSNicholas Bellinger } 4026708bb27SAndy Grover if (!tfo->set_default_node_attributes) { 4036708bb27SAndy Grover pr_err("Missing tfo->set_default_node_attributes()\n"); 404c66ac9dbSNicholas Bellinger return -EINVAL; 405c66ac9dbSNicholas Bellinger } 4066708bb27SAndy Grover if (!tfo->get_cmd_state) { 4076708bb27SAndy Grover pr_err("Missing tfo->get_cmd_state()\n"); 408c66ac9dbSNicholas Bellinger return -EINVAL; 409c66ac9dbSNicholas Bellinger } 4106708bb27SAndy Grover if (!tfo->queue_data_in) { 4116708bb27SAndy Grover pr_err("Missing tfo->queue_data_in()\n"); 412c66ac9dbSNicholas Bellinger return -EINVAL; 413c66ac9dbSNicholas Bellinger } 4146708bb27SAndy Grover if (!tfo->queue_status) { 4156708bb27SAndy Grover pr_err("Missing tfo->queue_status()\n"); 416c66ac9dbSNicholas Bellinger return -EINVAL; 417c66ac9dbSNicholas Bellinger } 4186708bb27SAndy Grover if (!tfo->queue_tm_rsp) { 4196708bb27SAndy Grover pr_err("Missing tfo->queue_tm_rsp()\n"); 420c66ac9dbSNicholas Bellinger return -EINVAL; 421c66ac9dbSNicholas Bellinger } 422131e6abcSNicholas Bellinger if (!tfo->aborted_task) { 423131e6abcSNicholas Bellinger pr_err("Missing tfo->aborted_task()\n"); 424131e6abcSNicholas Bellinger return -EINVAL; 425131e6abcSNicholas Bellinger } 4269c28ca4fSNicholas Bellinger if (!tfo->check_stop_free) { 4279c28ca4fSNicholas Bellinger pr_err("Missing tfo->check_stop_free()\n"); 4289c28ca4fSNicholas Bellinger return -EINVAL; 4299c28ca4fSNicholas Bellinger } 430c66ac9dbSNicholas Bellinger /* 431c66ac9dbSNicholas Bellinger * We at least require tfo->fabric_make_wwn(), tfo->fabric_drop_wwn() 432c66ac9dbSNicholas Bellinger * tfo->fabric_make_tpg() and tfo->fabric_drop_tpg() in 433c66ac9dbSNicholas Bellinger * target_core_fabric_configfs.c WWN+TPG group context code. 434c66ac9dbSNicholas Bellinger */ 4356708bb27SAndy Grover if (!tfo->fabric_make_wwn) { 4366708bb27SAndy Grover pr_err("Missing tfo->fabric_make_wwn()\n"); 437c66ac9dbSNicholas Bellinger return -EINVAL; 438c66ac9dbSNicholas Bellinger } 4396708bb27SAndy Grover if (!tfo->fabric_drop_wwn) { 4406708bb27SAndy Grover pr_err("Missing tfo->fabric_drop_wwn()\n"); 441c66ac9dbSNicholas Bellinger return -EINVAL; 442c66ac9dbSNicholas Bellinger } 4436708bb27SAndy Grover if (!tfo->fabric_make_tpg) { 4446708bb27SAndy Grover pr_err("Missing tfo->fabric_make_tpg()\n"); 445c66ac9dbSNicholas Bellinger return -EINVAL; 446c66ac9dbSNicholas Bellinger } 4476708bb27SAndy Grover if (!tfo->fabric_drop_tpg) { 4486708bb27SAndy Grover pr_err("Missing tfo->fabric_drop_tpg()\n"); 449c66ac9dbSNicholas Bellinger return -EINVAL; 450c66ac9dbSNicholas Bellinger } 451c66ac9dbSNicholas Bellinger 452c66ac9dbSNicholas Bellinger return 0; 453c66ac9dbSNicholas Bellinger } 454c66ac9dbSNicholas Bellinger 4559ac8928eSChristoph Hellwig int target_register_template(const struct target_core_fabric_ops *fo) 456c66ac9dbSNicholas Bellinger { 4579ac8928eSChristoph Hellwig struct target_fabric_configfs *tf; 458c66ac9dbSNicholas Bellinger int ret; 459c66ac9dbSNicholas Bellinger 4609ac8928eSChristoph Hellwig ret = target_fabric_tf_ops_check(fo); 4619ac8928eSChristoph Hellwig if (ret) 462c66ac9dbSNicholas Bellinger return ret; 463c66ac9dbSNicholas Bellinger 4649ac8928eSChristoph Hellwig tf = kzalloc(sizeof(struct target_fabric_configfs), GFP_KERNEL); 4659ac8928eSChristoph Hellwig if (!tf) { 4669ac8928eSChristoph Hellwig pr_err("%s: could not allocate memory!\n", __func__); 4679ac8928eSChristoph Hellwig return -ENOMEM; 4689ac8928eSChristoph Hellwig } 4699ac8928eSChristoph Hellwig 4709ac8928eSChristoph Hellwig INIT_LIST_HEAD(&tf->tf_list); 4719ac8928eSChristoph Hellwig atomic_set(&tf->tf_access_cnt, 0); 472ef0caf8dSChristoph Hellwig tf->tf_ops = fo; 4739ac8928eSChristoph Hellwig target_fabric_setup_cits(tf); 4749ac8928eSChristoph Hellwig 4759ac8928eSChristoph Hellwig mutex_lock(&g_tf_lock); 4769ac8928eSChristoph Hellwig list_add_tail(&tf->tf_list, &g_tf_list); 4779ac8928eSChristoph Hellwig mutex_unlock(&g_tf_lock); 4789ac8928eSChristoph Hellwig 479c66ac9dbSNicholas Bellinger return 0; 480c66ac9dbSNicholas Bellinger } 4819ac8928eSChristoph Hellwig EXPORT_SYMBOL(target_register_template); 482c66ac9dbSNicholas Bellinger 4839ac8928eSChristoph Hellwig void target_unregister_template(const struct target_core_fabric_ops *fo) 484c66ac9dbSNicholas Bellinger { 4859ac8928eSChristoph Hellwig struct target_fabric_configfs *t; 486c66ac9dbSNicholas Bellinger 487c66ac9dbSNicholas Bellinger mutex_lock(&g_tf_lock); 4889ac8928eSChristoph Hellwig list_for_each_entry(t, &g_tf_list, tf_list) { 4890dc2e8d1SChristoph Hellwig if (!strcmp(t->tf_ops->name, fo->name)) { 4909ac8928eSChristoph Hellwig BUG_ON(atomic_read(&t->tf_access_cnt)); 4919ac8928eSChristoph Hellwig list_del(&t->tf_list); 49294509182SNicholas Bellinger mutex_unlock(&g_tf_lock); 49394509182SNicholas Bellinger /* 49494509182SNicholas Bellinger * Wait for any outstanding fabric se_deve_entry->rcu_head 49594509182SNicholas Bellinger * callbacks to complete post kfree_rcu(), before allowing 49694509182SNicholas Bellinger * fabric driver unload of TFO->module to proceed. 49794509182SNicholas Bellinger */ 49894509182SNicholas Bellinger rcu_barrier(); 4999ac8928eSChristoph Hellwig kfree(t); 50094509182SNicholas Bellinger return; 501c66ac9dbSNicholas Bellinger } 502c66ac9dbSNicholas Bellinger } 5039ac8928eSChristoph Hellwig mutex_unlock(&g_tf_lock); 5049ac8928eSChristoph Hellwig } 5059ac8928eSChristoph Hellwig EXPORT_SYMBOL(target_unregister_template); 506c66ac9dbSNicholas Bellinger 507c66ac9dbSNicholas Bellinger /*############################################################################## 508c66ac9dbSNicholas Bellinger // Stop functions called by external Target Fabrics Modules 509c66ac9dbSNicholas Bellinger //############################################################################*/ 510c66ac9dbSNicholas Bellinger 5112eafd729SChristoph Hellwig static inline struct se_dev_attrib *to_attrib(struct config_item *item) 5122eafd729SChristoph Hellwig { 5132eafd729SChristoph Hellwig return container_of(to_config_group(item), struct se_dev_attrib, 5142eafd729SChristoph Hellwig da_group); 5155873c4d1SChristoph Hellwig } 5165873c4d1SChristoph Hellwig 5172eafd729SChristoph Hellwig /* Start functions for struct config_item_type tb_dev_attrib_cit */ 5182eafd729SChristoph Hellwig #define DEF_CONFIGFS_ATTRIB_SHOW(_name) \ 5192eafd729SChristoph Hellwig static ssize_t _name##_show(struct config_item *item, char *page) \ 5202eafd729SChristoph Hellwig { \ 5212eafd729SChristoph Hellwig return snprintf(page, PAGE_SIZE, "%u\n", to_attrib(item)->_name); \ 5222eafd729SChristoph Hellwig } 5233effdb90SChristoph Hellwig 5242eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_SHOW(emulate_model_alias); 5252eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_SHOW(emulate_dpo); 5262eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_SHOW(emulate_fua_write); 5272eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_SHOW(emulate_fua_read); 5282eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_SHOW(emulate_write_cache); 5292eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_SHOW(emulate_ua_intlck_ctrl); 5302eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_SHOW(emulate_tas); 5312eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_SHOW(emulate_tpu); 5322eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_SHOW(emulate_tpws); 5332eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_SHOW(emulate_caw); 5342eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_SHOW(emulate_3pc); 5352eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_SHOW(pi_prot_type); 5362eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_SHOW(hw_pi_prot_type); 5372eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_SHOW(pi_prot_format); 538056e8924SDmitry Monakhov DEF_CONFIGFS_ATTRIB_SHOW(pi_prot_verify); 5392eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_SHOW(enforce_pr_isids); 5402eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_SHOW(is_nonrot); 5412eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_SHOW(emulate_rest_reord); 5422eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_SHOW(force_pr_aptpl); 5432eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_SHOW(hw_block_size); 5442eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_SHOW(block_size); 5452eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_SHOW(hw_max_sectors); 5462eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_SHOW(optimal_sectors); 5472eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_SHOW(hw_queue_depth); 5482eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_SHOW(queue_depth); 5492eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_SHOW(max_unmap_lba_count); 5502eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_SHOW(max_unmap_block_desc_count); 5512eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_SHOW(unmap_granularity); 5522eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_SHOW(unmap_granularity_alignment); 553e6f41633SJamie Pocas DEF_CONFIGFS_ATTRIB_SHOW(unmap_zeroes_data); 5542eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_SHOW(max_write_same_len); 5552eafd729SChristoph Hellwig 5562eafd729SChristoph Hellwig #define DEF_CONFIGFS_ATTRIB_STORE_U32(_name) \ 5572eafd729SChristoph Hellwig static ssize_t _name##_store(struct config_item *item, const char *page,\ 5585873c4d1SChristoph Hellwig size_t count) \ 5595873c4d1SChristoph Hellwig { \ 5602eafd729SChristoph Hellwig struct se_dev_attrib *da = to_attrib(item); \ 5613effdb90SChristoph Hellwig u32 val; \ 5625873c4d1SChristoph Hellwig int ret; \ 5635873c4d1SChristoph Hellwig \ 5643effdb90SChristoph Hellwig ret = kstrtou32(page, 0, &val); \ 5653effdb90SChristoph Hellwig if (ret < 0) \ 5663effdb90SChristoph Hellwig return ret; \ 5673effdb90SChristoph Hellwig da->_name = val; \ 5683effdb90SChristoph Hellwig return count; \ 5695873c4d1SChristoph Hellwig } 5705873c4d1SChristoph Hellwig 5712eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_STORE_U32(max_unmap_lba_count); 5722eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_STORE_U32(max_unmap_block_desc_count); 5732eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_STORE_U32(unmap_granularity); 5742eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_STORE_U32(unmap_granularity_alignment); 5752eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_STORE_U32(max_write_same_len); 5765873c4d1SChristoph Hellwig 5772eafd729SChristoph Hellwig #define DEF_CONFIGFS_ATTRIB_STORE_BOOL(_name) \ 5782eafd729SChristoph Hellwig static ssize_t _name##_store(struct config_item *item, const char *page, \ 5793effdb90SChristoph Hellwig size_t count) \ 5803effdb90SChristoph Hellwig { \ 5812eafd729SChristoph Hellwig struct se_dev_attrib *da = to_attrib(item); \ 5823effdb90SChristoph Hellwig bool flag; \ 5833effdb90SChristoph Hellwig int ret; \ 5843effdb90SChristoph Hellwig \ 5853effdb90SChristoph Hellwig ret = strtobool(page, &flag); \ 5863effdb90SChristoph Hellwig if (ret < 0) \ 5873effdb90SChristoph Hellwig return ret; \ 5883effdb90SChristoph Hellwig da->_name = flag; \ 5893effdb90SChristoph Hellwig return count; \ 5903effdb90SChristoph Hellwig } 5913effdb90SChristoph Hellwig 5922eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_STORE_BOOL(emulate_fua_write); 5932eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_STORE_BOOL(emulate_caw); 5942eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_STORE_BOOL(emulate_3pc); 5952eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_STORE_BOOL(enforce_pr_isids); 5962eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_STORE_BOOL(is_nonrot); 5973effdb90SChristoph Hellwig 5982eafd729SChristoph Hellwig #define DEF_CONFIGFS_ATTRIB_STORE_STUB(_name) \ 5992eafd729SChristoph Hellwig static ssize_t _name##_store(struct config_item *item, const char *page,\ 6003effdb90SChristoph Hellwig size_t count) \ 6013effdb90SChristoph Hellwig { \ 6023effdb90SChristoph Hellwig printk_once(KERN_WARNING \ 603234bdbc4SChristophe Vu-Brugier "ignoring deprecated %s attribute\n", \ 604234bdbc4SChristophe Vu-Brugier __stringify(_name)); \ 6053effdb90SChristoph Hellwig return count; \ 6063effdb90SChristoph Hellwig } 6073effdb90SChristoph Hellwig 6082eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_STORE_STUB(emulate_dpo); 6092eafd729SChristoph Hellwig DEF_CONFIGFS_ATTRIB_STORE_STUB(emulate_fua_read); 6103effdb90SChristoph Hellwig 6113effdb90SChristoph Hellwig static void dev_set_t10_wwn_model_alias(struct se_device *dev) 6123effdb90SChristoph Hellwig { 6133effdb90SChristoph Hellwig const char *configname; 6143effdb90SChristoph Hellwig 6153effdb90SChristoph Hellwig configname = config_item_name(&dev->dev_group.cg_item); 6163effdb90SChristoph Hellwig if (strlen(configname) >= 16) { 6173effdb90SChristoph Hellwig pr_warn("dev[%p]: Backstore name '%s' is too long for " 6183effdb90SChristoph Hellwig "INQUIRY_MODEL, truncating to 16 bytes\n", dev, 6193effdb90SChristoph Hellwig configname); 6203effdb90SChristoph Hellwig } 6213effdb90SChristoph Hellwig snprintf(&dev->t10_wwn.model[0], 16, "%s", configname); 6223effdb90SChristoph Hellwig } 6233effdb90SChristoph Hellwig 6242eafd729SChristoph Hellwig static ssize_t emulate_model_alias_store(struct config_item *item, 6253effdb90SChristoph Hellwig const char *page, size_t count) 6263effdb90SChristoph Hellwig { 6272eafd729SChristoph Hellwig struct se_dev_attrib *da = to_attrib(item); 6283effdb90SChristoph Hellwig struct se_device *dev = da->da_dev; 6293effdb90SChristoph Hellwig bool flag; 6303effdb90SChristoph Hellwig int ret; 6313effdb90SChristoph Hellwig 6323effdb90SChristoph Hellwig if (dev->export_count) { 6333effdb90SChristoph Hellwig pr_err("dev[%p]: Unable to change model alias" 6343effdb90SChristoph Hellwig " while export_count is %d\n", 6353effdb90SChristoph Hellwig dev, dev->export_count); 6363effdb90SChristoph Hellwig return -EINVAL; 6373effdb90SChristoph Hellwig } 6383effdb90SChristoph Hellwig 6393effdb90SChristoph Hellwig ret = strtobool(page, &flag); 6403effdb90SChristoph Hellwig if (ret < 0) 6413effdb90SChristoph Hellwig return ret; 6423effdb90SChristoph Hellwig 6433effdb90SChristoph Hellwig if (flag) { 6443effdb90SChristoph Hellwig dev_set_t10_wwn_model_alias(dev); 6453effdb90SChristoph Hellwig } else { 6463effdb90SChristoph Hellwig strncpy(&dev->t10_wwn.model[0], 6473effdb90SChristoph Hellwig dev->transport->inquiry_prod, 16); 6483effdb90SChristoph Hellwig } 6493effdb90SChristoph Hellwig da->emulate_model_alias = flag; 6503effdb90SChristoph Hellwig return count; 6513effdb90SChristoph Hellwig } 6523effdb90SChristoph Hellwig 6532eafd729SChristoph Hellwig static ssize_t emulate_write_cache_store(struct config_item *item, 6543effdb90SChristoph Hellwig const char *page, size_t count) 6553effdb90SChristoph Hellwig { 6562eafd729SChristoph Hellwig struct se_dev_attrib *da = to_attrib(item); 6573effdb90SChristoph Hellwig bool flag; 6583effdb90SChristoph Hellwig int ret; 6593effdb90SChristoph Hellwig 6603effdb90SChristoph Hellwig ret = strtobool(page, &flag); 6613effdb90SChristoph Hellwig if (ret < 0) 6623effdb90SChristoph Hellwig return ret; 6633effdb90SChristoph Hellwig 6643effdb90SChristoph Hellwig if (flag && da->da_dev->transport->get_write_cache) { 6653effdb90SChristoph Hellwig pr_err("emulate_write_cache not supported for this device\n"); 6663effdb90SChristoph Hellwig return -EINVAL; 6673effdb90SChristoph Hellwig } 6683effdb90SChristoph Hellwig 6693effdb90SChristoph Hellwig da->emulate_write_cache = flag; 6703effdb90SChristoph Hellwig pr_debug("dev[%p]: SE Device WRITE_CACHE_EMULATION flag: %d\n", 6713effdb90SChristoph Hellwig da->da_dev, flag); 6723effdb90SChristoph Hellwig return count; 6733effdb90SChristoph Hellwig } 6743effdb90SChristoph Hellwig 6752eafd729SChristoph Hellwig static ssize_t emulate_ua_intlck_ctrl_store(struct config_item *item, 6763effdb90SChristoph Hellwig const char *page, size_t count) 6773effdb90SChristoph Hellwig { 6782eafd729SChristoph Hellwig struct se_dev_attrib *da = to_attrib(item); 6793effdb90SChristoph Hellwig u32 val; 6803effdb90SChristoph Hellwig int ret; 6813effdb90SChristoph Hellwig 6823effdb90SChristoph Hellwig ret = kstrtou32(page, 0, &val); 6833effdb90SChristoph Hellwig if (ret < 0) 6843effdb90SChristoph Hellwig return ret; 6853effdb90SChristoph Hellwig 6863effdb90SChristoph Hellwig if (val != 0 && val != 1 && val != 2) { 6873effdb90SChristoph Hellwig pr_err("Illegal value %d\n", val); 6883effdb90SChristoph Hellwig return -EINVAL; 6893effdb90SChristoph Hellwig } 6903effdb90SChristoph Hellwig 6913effdb90SChristoph Hellwig if (da->da_dev->export_count) { 6923effdb90SChristoph Hellwig pr_err("dev[%p]: Unable to change SE Device" 6933effdb90SChristoph Hellwig " UA_INTRLCK_CTRL while export_count is %d\n", 6943effdb90SChristoph Hellwig da->da_dev, da->da_dev->export_count); 6953effdb90SChristoph Hellwig return -EINVAL; 6963effdb90SChristoph Hellwig } 6973effdb90SChristoph Hellwig da->emulate_ua_intlck_ctrl = val; 6983effdb90SChristoph Hellwig pr_debug("dev[%p]: SE Device UA_INTRLCK_CTRL flag: %d\n", 6993effdb90SChristoph Hellwig da->da_dev, val); 7003effdb90SChristoph Hellwig return count; 7013effdb90SChristoph Hellwig } 7023effdb90SChristoph Hellwig 7032eafd729SChristoph Hellwig static ssize_t emulate_tas_store(struct config_item *item, 7043effdb90SChristoph Hellwig const char *page, size_t count) 7053effdb90SChristoph Hellwig { 7062eafd729SChristoph Hellwig struct se_dev_attrib *da = to_attrib(item); 7073effdb90SChristoph Hellwig bool flag; 7083effdb90SChristoph Hellwig int ret; 7093effdb90SChristoph Hellwig 7103effdb90SChristoph Hellwig ret = strtobool(page, &flag); 7113effdb90SChristoph Hellwig if (ret < 0) 7123effdb90SChristoph Hellwig return ret; 7133effdb90SChristoph Hellwig 7143effdb90SChristoph Hellwig if (da->da_dev->export_count) { 7153effdb90SChristoph Hellwig pr_err("dev[%p]: Unable to change SE Device TAS while" 7163effdb90SChristoph Hellwig " export_count is %d\n", 7173effdb90SChristoph Hellwig da->da_dev, da->da_dev->export_count); 7183effdb90SChristoph Hellwig return -EINVAL; 7193effdb90SChristoph Hellwig } 7203effdb90SChristoph Hellwig da->emulate_tas = flag; 7213effdb90SChristoph Hellwig pr_debug("dev[%p]: SE Device TASK_ABORTED status bit: %s\n", 7223effdb90SChristoph Hellwig da->da_dev, flag ? "Enabled" : "Disabled"); 7233effdb90SChristoph Hellwig 7243effdb90SChristoph Hellwig return count; 7253effdb90SChristoph Hellwig } 7263effdb90SChristoph Hellwig 7272eafd729SChristoph Hellwig static ssize_t emulate_tpu_store(struct config_item *item, 7283effdb90SChristoph Hellwig const char *page, size_t count) 7293effdb90SChristoph Hellwig { 7302eafd729SChristoph Hellwig struct se_dev_attrib *da = to_attrib(item); 7313effdb90SChristoph Hellwig bool flag; 7323effdb90SChristoph Hellwig int ret; 7333effdb90SChristoph Hellwig 7343effdb90SChristoph Hellwig ret = strtobool(page, &flag); 7353effdb90SChristoph Hellwig if (ret < 0) 7363effdb90SChristoph Hellwig return ret; 7373effdb90SChristoph Hellwig 7383effdb90SChristoph Hellwig /* 7393effdb90SChristoph Hellwig * We expect this value to be non-zero when generic Block Layer 7403effdb90SChristoph Hellwig * Discard supported is detected iblock_create_virtdevice(). 7413effdb90SChristoph Hellwig */ 7423effdb90SChristoph Hellwig if (flag && !da->max_unmap_block_desc_count) { 7433effdb90SChristoph Hellwig pr_err("Generic Block Discard not supported\n"); 7443effdb90SChristoph Hellwig return -ENOSYS; 7453effdb90SChristoph Hellwig } 7463effdb90SChristoph Hellwig 7473effdb90SChristoph Hellwig da->emulate_tpu = flag; 7483effdb90SChristoph Hellwig pr_debug("dev[%p]: SE Device Thin Provisioning UNMAP bit: %d\n", 7493effdb90SChristoph Hellwig da->da_dev, flag); 7503effdb90SChristoph Hellwig return count; 7513effdb90SChristoph Hellwig } 7523effdb90SChristoph Hellwig 7532eafd729SChristoph Hellwig static ssize_t emulate_tpws_store(struct config_item *item, 7543effdb90SChristoph Hellwig const char *page, size_t count) 7553effdb90SChristoph Hellwig { 7562eafd729SChristoph Hellwig struct se_dev_attrib *da = to_attrib(item); 7573effdb90SChristoph Hellwig bool flag; 7583effdb90SChristoph Hellwig int ret; 7593effdb90SChristoph Hellwig 7603effdb90SChristoph Hellwig ret = strtobool(page, &flag); 7613effdb90SChristoph Hellwig if (ret < 0) 7623effdb90SChristoph Hellwig return ret; 7633effdb90SChristoph Hellwig 7643effdb90SChristoph Hellwig /* 7653effdb90SChristoph Hellwig * We expect this value to be non-zero when generic Block Layer 7663effdb90SChristoph Hellwig * Discard supported is detected iblock_create_virtdevice(). 7673effdb90SChristoph Hellwig */ 7683effdb90SChristoph Hellwig if (flag && !da->max_unmap_block_desc_count) { 7693effdb90SChristoph Hellwig pr_err("Generic Block Discard not supported\n"); 7703effdb90SChristoph Hellwig return -ENOSYS; 7713effdb90SChristoph Hellwig } 7723effdb90SChristoph Hellwig 7733effdb90SChristoph Hellwig da->emulate_tpws = flag; 7743effdb90SChristoph Hellwig pr_debug("dev[%p]: SE Device Thin Provisioning WRITE_SAME: %d\n", 7753effdb90SChristoph Hellwig da->da_dev, flag); 7763effdb90SChristoph Hellwig return count; 7773effdb90SChristoph Hellwig } 7783effdb90SChristoph Hellwig 7792eafd729SChristoph Hellwig static ssize_t pi_prot_type_store(struct config_item *item, 7803effdb90SChristoph Hellwig const char *page, size_t count) 7813effdb90SChristoph Hellwig { 7822eafd729SChristoph Hellwig struct se_dev_attrib *da = to_attrib(item); 7833effdb90SChristoph Hellwig int old_prot = da->pi_prot_type, ret; 7843effdb90SChristoph Hellwig struct se_device *dev = da->da_dev; 7853effdb90SChristoph Hellwig u32 flag; 7863effdb90SChristoph Hellwig 7873effdb90SChristoph Hellwig ret = kstrtou32(page, 0, &flag); 7883effdb90SChristoph Hellwig if (ret < 0) 7893effdb90SChristoph Hellwig return ret; 7903effdb90SChristoph Hellwig 7913effdb90SChristoph Hellwig if (flag != 0 && flag != 1 && flag != 2 && flag != 3) { 7923effdb90SChristoph Hellwig pr_err("Illegal value %d for pi_prot_type\n", flag); 7933effdb90SChristoph Hellwig return -EINVAL; 7943effdb90SChristoph Hellwig } 7953effdb90SChristoph Hellwig if (flag == 2) { 7963effdb90SChristoph Hellwig pr_err("DIF TYPE2 protection currently not supported\n"); 7973effdb90SChristoph Hellwig return -ENOSYS; 7983effdb90SChristoph Hellwig } 7993effdb90SChristoph Hellwig if (da->hw_pi_prot_type) { 8003effdb90SChristoph Hellwig pr_warn("DIF protection enabled on underlying hardware," 8013effdb90SChristoph Hellwig " ignoring\n"); 8023effdb90SChristoph Hellwig return count; 8033effdb90SChristoph Hellwig } 8043effdb90SChristoph Hellwig if (!dev->transport->init_prot || !dev->transport->free_prot) { 8053effdb90SChristoph Hellwig /* 0 is only allowed value for non-supporting backends */ 8063effdb90SChristoph Hellwig if (flag == 0) 807bc1a7d6aSAndy Grover return count; 8083effdb90SChristoph Hellwig 8093effdb90SChristoph Hellwig pr_err("DIF protection not supported by backend: %s\n", 8103effdb90SChristoph Hellwig dev->transport->name); 8113effdb90SChristoph Hellwig return -ENOSYS; 8123effdb90SChristoph Hellwig } 8133effdb90SChristoph Hellwig if (!(dev->dev_flags & DF_CONFIGURED)) { 8143effdb90SChristoph Hellwig pr_err("DIF protection requires device to be configured\n"); 8153effdb90SChristoph Hellwig return -ENODEV; 8163effdb90SChristoph Hellwig } 8173effdb90SChristoph Hellwig if (dev->export_count) { 8183effdb90SChristoph Hellwig pr_err("dev[%p]: Unable to change SE Device PROT type while" 8193effdb90SChristoph Hellwig " export_count is %d\n", dev, dev->export_count); 8203effdb90SChristoph Hellwig return -EINVAL; 8213effdb90SChristoph Hellwig } 8223effdb90SChristoph Hellwig 8233effdb90SChristoph Hellwig da->pi_prot_type = flag; 8243effdb90SChristoph Hellwig 8253effdb90SChristoph Hellwig if (flag && !old_prot) { 8263effdb90SChristoph Hellwig ret = dev->transport->init_prot(dev); 8273effdb90SChristoph Hellwig if (ret) { 8283effdb90SChristoph Hellwig da->pi_prot_type = old_prot; 829056e8924SDmitry Monakhov da->pi_prot_verify = (bool) da->pi_prot_type; 8303effdb90SChristoph Hellwig return ret; 8313effdb90SChristoph Hellwig } 8323effdb90SChristoph Hellwig 8333effdb90SChristoph Hellwig } else if (!flag && old_prot) { 8343effdb90SChristoph Hellwig dev->transport->free_prot(dev); 8353effdb90SChristoph Hellwig } 8363effdb90SChristoph Hellwig 837056e8924SDmitry Monakhov da->pi_prot_verify = (bool) da->pi_prot_type; 8383effdb90SChristoph Hellwig pr_debug("dev[%p]: SE Device Protection Type: %d\n", dev, flag); 8393effdb90SChristoph Hellwig return count; 8403effdb90SChristoph Hellwig } 8413effdb90SChristoph Hellwig 8422eafd729SChristoph Hellwig static ssize_t pi_prot_format_store(struct config_item *item, 8433effdb90SChristoph Hellwig const char *page, size_t count) 8443effdb90SChristoph Hellwig { 8452eafd729SChristoph Hellwig struct se_dev_attrib *da = to_attrib(item); 8463effdb90SChristoph Hellwig struct se_device *dev = da->da_dev; 8473effdb90SChristoph Hellwig bool flag; 8483effdb90SChristoph Hellwig int ret; 8493effdb90SChristoph Hellwig 8503effdb90SChristoph Hellwig ret = strtobool(page, &flag); 8513effdb90SChristoph Hellwig if (ret < 0) 8523effdb90SChristoph Hellwig return ret; 8533effdb90SChristoph Hellwig 8543effdb90SChristoph Hellwig if (!flag) 8553effdb90SChristoph Hellwig return count; 8563effdb90SChristoph Hellwig 8573effdb90SChristoph Hellwig if (!dev->transport->format_prot) { 8583effdb90SChristoph Hellwig pr_err("DIF protection format not supported by backend %s\n", 8593effdb90SChristoph Hellwig dev->transport->name); 8603effdb90SChristoph Hellwig return -ENOSYS; 8613effdb90SChristoph Hellwig } 8623effdb90SChristoph Hellwig if (!(dev->dev_flags & DF_CONFIGURED)) { 8633effdb90SChristoph Hellwig pr_err("DIF protection format requires device to be configured\n"); 8643effdb90SChristoph Hellwig return -ENODEV; 8653effdb90SChristoph Hellwig } 8663effdb90SChristoph Hellwig if (dev->export_count) { 8673effdb90SChristoph Hellwig pr_err("dev[%p]: Unable to format SE Device PROT type while" 8683effdb90SChristoph Hellwig " export_count is %d\n", dev, dev->export_count); 8693effdb90SChristoph Hellwig return -EINVAL; 8703effdb90SChristoph Hellwig } 8713effdb90SChristoph Hellwig 8723effdb90SChristoph Hellwig ret = dev->transport->format_prot(dev); 8733effdb90SChristoph Hellwig if (ret) 8743effdb90SChristoph Hellwig return ret; 8753effdb90SChristoph Hellwig 8763effdb90SChristoph Hellwig pr_debug("dev[%p]: SE Device Protection Format complete\n", dev); 8773effdb90SChristoph Hellwig return count; 8783effdb90SChristoph Hellwig } 8793effdb90SChristoph Hellwig 880056e8924SDmitry Monakhov static ssize_t pi_prot_verify_store(struct config_item *item, 881056e8924SDmitry Monakhov const char *page, size_t count) 882056e8924SDmitry Monakhov { 883056e8924SDmitry Monakhov struct se_dev_attrib *da = to_attrib(item); 884056e8924SDmitry Monakhov bool flag; 885056e8924SDmitry Monakhov int ret; 886056e8924SDmitry Monakhov 887056e8924SDmitry Monakhov ret = strtobool(page, &flag); 888056e8924SDmitry Monakhov if (ret < 0) 889056e8924SDmitry Monakhov return ret; 890056e8924SDmitry Monakhov 891056e8924SDmitry Monakhov if (!flag) { 892056e8924SDmitry Monakhov da->pi_prot_verify = flag; 893056e8924SDmitry Monakhov return count; 894056e8924SDmitry Monakhov } 895056e8924SDmitry Monakhov if (da->hw_pi_prot_type) { 896056e8924SDmitry Monakhov pr_warn("DIF protection enabled on underlying hardware," 897056e8924SDmitry Monakhov " ignoring\n"); 898056e8924SDmitry Monakhov return count; 899056e8924SDmitry Monakhov } 900056e8924SDmitry Monakhov if (!da->pi_prot_type) { 901056e8924SDmitry Monakhov pr_warn("DIF protection not supported by backend, ignoring\n"); 902056e8924SDmitry Monakhov return count; 903056e8924SDmitry Monakhov } 904056e8924SDmitry Monakhov da->pi_prot_verify = flag; 905056e8924SDmitry Monakhov 906056e8924SDmitry Monakhov return count; 907056e8924SDmitry Monakhov } 908056e8924SDmitry Monakhov 9092eafd729SChristoph Hellwig static ssize_t force_pr_aptpl_store(struct config_item *item, 9103effdb90SChristoph Hellwig const char *page, size_t count) 9113effdb90SChristoph Hellwig { 9122eafd729SChristoph Hellwig struct se_dev_attrib *da = to_attrib(item); 9133effdb90SChristoph Hellwig bool flag; 9143effdb90SChristoph Hellwig int ret; 9153effdb90SChristoph Hellwig 9163effdb90SChristoph Hellwig ret = strtobool(page, &flag); 9173effdb90SChristoph Hellwig if (ret < 0) 9183effdb90SChristoph Hellwig return ret; 9193effdb90SChristoph Hellwig if (da->da_dev->export_count) { 9203effdb90SChristoph Hellwig pr_err("dev[%p]: Unable to set force_pr_aptpl while" 9213effdb90SChristoph Hellwig " export_count is %d\n", 9223effdb90SChristoph Hellwig da->da_dev, da->da_dev->export_count); 9233effdb90SChristoph Hellwig return -EINVAL; 9243effdb90SChristoph Hellwig } 9253effdb90SChristoph Hellwig 9263effdb90SChristoph Hellwig da->force_pr_aptpl = flag; 9273effdb90SChristoph Hellwig pr_debug("dev[%p]: SE Device force_pr_aptpl: %d\n", da->da_dev, flag); 9283effdb90SChristoph Hellwig return count; 9293effdb90SChristoph Hellwig } 9303effdb90SChristoph Hellwig 9312eafd729SChristoph Hellwig static ssize_t emulate_rest_reord_store(struct config_item *item, 9323effdb90SChristoph Hellwig const char *page, size_t count) 9333effdb90SChristoph Hellwig { 9342eafd729SChristoph Hellwig struct se_dev_attrib *da = to_attrib(item); 9353effdb90SChristoph Hellwig bool flag; 9363effdb90SChristoph Hellwig int ret; 9373effdb90SChristoph Hellwig 9383effdb90SChristoph Hellwig ret = strtobool(page, &flag); 9393effdb90SChristoph Hellwig if (ret < 0) 9403effdb90SChristoph Hellwig return ret; 9413effdb90SChristoph Hellwig 9423effdb90SChristoph Hellwig if (flag != 0) { 9433effdb90SChristoph Hellwig printk(KERN_ERR "dev[%p]: SE Device emulation of restricted" 9443effdb90SChristoph Hellwig " reordering not implemented\n", da->da_dev); 9453effdb90SChristoph Hellwig return -ENOSYS; 9463effdb90SChristoph Hellwig } 9473effdb90SChristoph Hellwig da->emulate_rest_reord = flag; 9483effdb90SChristoph Hellwig pr_debug("dev[%p]: SE Device emulate_rest_reord: %d\n", 9493effdb90SChristoph Hellwig da->da_dev, flag); 9503effdb90SChristoph Hellwig return count; 9513effdb90SChristoph Hellwig } 9523effdb90SChristoph Hellwig 953e6f41633SJamie Pocas static ssize_t unmap_zeroes_data_store(struct config_item *item, 954e6f41633SJamie Pocas const char *page, size_t count) 955e6f41633SJamie Pocas { 956e6f41633SJamie Pocas struct se_dev_attrib *da = to_attrib(item); 957e6f41633SJamie Pocas bool flag; 958e6f41633SJamie Pocas int ret; 959e6f41633SJamie Pocas 960e6f41633SJamie Pocas ret = strtobool(page, &flag); 961e6f41633SJamie Pocas if (ret < 0) 962e6f41633SJamie Pocas return ret; 963e6f41633SJamie Pocas 964e6f41633SJamie Pocas if (da->da_dev->export_count) { 965e6f41633SJamie Pocas pr_err("dev[%p]: Unable to change SE Device" 966e6f41633SJamie Pocas " unmap_zeroes_data while export_count is %d\n", 967e6f41633SJamie Pocas da->da_dev, da->da_dev->export_count); 968e6f41633SJamie Pocas return -EINVAL; 969e6f41633SJamie Pocas } 970e6f41633SJamie Pocas /* 971e6f41633SJamie Pocas * We expect this value to be non-zero when generic Block Layer 972e6f41633SJamie Pocas * Discard supported is detected iblock_configure_device(). 973e6f41633SJamie Pocas */ 974e6f41633SJamie Pocas if (flag && !da->max_unmap_block_desc_count) { 975e6f41633SJamie Pocas pr_err("dev[%p]: Thin Provisioning LBPRZ will not be set" 976e6f41633SJamie Pocas " because max_unmap_block_desc_count is zero\n", 977e6f41633SJamie Pocas da->da_dev); 978e6f41633SJamie Pocas return -ENOSYS; 979e6f41633SJamie Pocas } 980e6f41633SJamie Pocas da->unmap_zeroes_data = flag; 981e6f41633SJamie Pocas pr_debug("dev[%p]: SE Device Thin Provisioning LBPRZ bit: %d\n", 982e6f41633SJamie Pocas da->da_dev, flag); 9832e498f25SNicholas Bellinger return count; 984e6f41633SJamie Pocas } 985e6f41633SJamie Pocas 9863effdb90SChristoph Hellwig /* 9873effdb90SChristoph Hellwig * Note, this can only be called on unexported SE Device Object. 9883effdb90SChristoph Hellwig */ 9892eafd729SChristoph Hellwig static ssize_t queue_depth_store(struct config_item *item, 9903effdb90SChristoph Hellwig const char *page, size_t count) 9913effdb90SChristoph Hellwig { 9922eafd729SChristoph Hellwig struct se_dev_attrib *da = to_attrib(item); 9933effdb90SChristoph Hellwig struct se_device *dev = da->da_dev; 9943effdb90SChristoph Hellwig u32 val; 9953effdb90SChristoph Hellwig int ret; 9963effdb90SChristoph Hellwig 9973effdb90SChristoph Hellwig ret = kstrtou32(page, 0, &val); 9983effdb90SChristoph Hellwig if (ret < 0) 9993effdb90SChristoph Hellwig return ret; 10003effdb90SChristoph Hellwig 10013effdb90SChristoph Hellwig if (dev->export_count) { 10023effdb90SChristoph Hellwig pr_err("dev[%p]: Unable to change SE Device TCQ while" 10033effdb90SChristoph Hellwig " export_count is %d\n", 10043effdb90SChristoph Hellwig dev, dev->export_count); 10053effdb90SChristoph Hellwig return -EINVAL; 10063effdb90SChristoph Hellwig } 10073effdb90SChristoph Hellwig if (!val) { 10083effdb90SChristoph Hellwig pr_err("dev[%p]: Illegal ZERO value for queue_depth\n", dev); 10093effdb90SChristoph Hellwig return -EINVAL; 10103effdb90SChristoph Hellwig } 10113effdb90SChristoph Hellwig 10123effdb90SChristoph Hellwig if (val > dev->dev_attrib.queue_depth) { 10133effdb90SChristoph Hellwig if (val > dev->dev_attrib.hw_queue_depth) { 10143effdb90SChristoph Hellwig pr_err("dev[%p]: Passed queue_depth:" 10153effdb90SChristoph Hellwig " %u exceeds TCM/SE_Device MAX" 10163effdb90SChristoph Hellwig " TCQ: %u\n", dev, val, 10173effdb90SChristoph Hellwig dev->dev_attrib.hw_queue_depth); 10183effdb90SChristoph Hellwig return -EINVAL; 10193effdb90SChristoph Hellwig } 10203effdb90SChristoph Hellwig } 10213effdb90SChristoph Hellwig da->queue_depth = dev->queue_depth = val; 10223effdb90SChristoph Hellwig pr_debug("dev[%p]: SE Device TCQ Depth changed to: %u\n", dev, val); 10233effdb90SChristoph Hellwig return count; 10243effdb90SChristoph Hellwig } 10253effdb90SChristoph Hellwig 10262eafd729SChristoph Hellwig static ssize_t optimal_sectors_store(struct config_item *item, 10273effdb90SChristoph Hellwig const char *page, size_t count) 10283effdb90SChristoph Hellwig { 10292eafd729SChristoph Hellwig struct se_dev_attrib *da = to_attrib(item); 10303effdb90SChristoph Hellwig u32 val; 10313effdb90SChristoph Hellwig int ret; 10323effdb90SChristoph Hellwig 10333effdb90SChristoph Hellwig ret = kstrtou32(page, 0, &val); 10343effdb90SChristoph Hellwig if (ret < 0) 10353effdb90SChristoph Hellwig return ret; 10363effdb90SChristoph Hellwig 10373effdb90SChristoph Hellwig if (da->da_dev->export_count) { 10383effdb90SChristoph Hellwig pr_err("dev[%p]: Unable to change SE Device" 10393effdb90SChristoph Hellwig " optimal_sectors while export_count is %d\n", 10403effdb90SChristoph Hellwig da->da_dev, da->da_dev->export_count); 10413effdb90SChristoph Hellwig return -EINVAL; 10423effdb90SChristoph Hellwig } 10433effdb90SChristoph Hellwig if (val > da->hw_max_sectors) { 10443effdb90SChristoph Hellwig pr_err("dev[%p]: Passed optimal_sectors %u cannot be" 10453effdb90SChristoph Hellwig " greater than hw_max_sectors: %u\n", 10463effdb90SChristoph Hellwig da->da_dev, val, da->hw_max_sectors); 10473effdb90SChristoph Hellwig return -EINVAL; 10483effdb90SChristoph Hellwig } 10493effdb90SChristoph Hellwig 10503effdb90SChristoph Hellwig da->optimal_sectors = val; 10513effdb90SChristoph Hellwig pr_debug("dev[%p]: SE Device optimal_sectors changed to %u\n", 10523effdb90SChristoph Hellwig da->da_dev, val); 10533effdb90SChristoph Hellwig return count; 10543effdb90SChristoph Hellwig } 10553effdb90SChristoph Hellwig 10562eafd729SChristoph Hellwig static ssize_t block_size_store(struct config_item *item, 10573effdb90SChristoph Hellwig const char *page, size_t count) 10583effdb90SChristoph Hellwig { 10592eafd729SChristoph Hellwig struct se_dev_attrib *da = to_attrib(item); 10603effdb90SChristoph Hellwig u32 val; 10613effdb90SChristoph Hellwig int ret; 10623effdb90SChristoph Hellwig 10633effdb90SChristoph Hellwig ret = kstrtou32(page, 0, &val); 10643effdb90SChristoph Hellwig if (ret < 0) 10653effdb90SChristoph Hellwig return ret; 10663effdb90SChristoph Hellwig 10673effdb90SChristoph Hellwig if (da->da_dev->export_count) { 10683effdb90SChristoph Hellwig pr_err("dev[%p]: Unable to change SE Device block_size" 10693effdb90SChristoph Hellwig " while export_count is %d\n", 10703effdb90SChristoph Hellwig da->da_dev, da->da_dev->export_count); 10713effdb90SChristoph Hellwig return -EINVAL; 10723effdb90SChristoph Hellwig } 10733effdb90SChristoph Hellwig 10743effdb90SChristoph Hellwig if (val != 512 && val != 1024 && val != 2048 && val != 4096) { 10753effdb90SChristoph Hellwig pr_err("dev[%p]: Illegal value for block_device: %u" 10763effdb90SChristoph Hellwig " for SE device, must be 512, 1024, 2048 or 4096\n", 10773effdb90SChristoph Hellwig da->da_dev, val); 10783effdb90SChristoph Hellwig return -EINVAL; 10793effdb90SChristoph Hellwig } 10803effdb90SChristoph Hellwig 10813effdb90SChristoph Hellwig da->block_size = val; 10823effdb90SChristoph Hellwig if (da->max_bytes_per_io) 10833effdb90SChristoph Hellwig da->hw_max_sectors = da->max_bytes_per_io / val; 10843effdb90SChristoph Hellwig 10853effdb90SChristoph Hellwig pr_debug("dev[%p]: SE Device block_size changed to %u\n", 10863effdb90SChristoph Hellwig da->da_dev, val); 10873effdb90SChristoph Hellwig return count; 10883effdb90SChristoph Hellwig } 10895873c4d1SChristoph Hellwig 1090c17d5d5fSMike Christie static ssize_t alua_support_show(struct config_item *item, char *page) 1091c17d5d5fSMike Christie { 1092c17d5d5fSMike Christie struct se_dev_attrib *da = to_attrib(item); 1093c17d5d5fSMike Christie u8 flags = da->da_dev->transport->transport_flags; 1094c17d5d5fSMike Christie 1095c17d5d5fSMike Christie return snprintf(page, PAGE_SIZE, "%d\n", 1096c17d5d5fSMike Christie flags & TRANSPORT_FLAG_PASSTHROUGH_ALUA ? 0 : 1); 1097c17d5d5fSMike Christie } 1098c17d5d5fSMike Christie 1099c17d5d5fSMike Christie static ssize_t pgr_support_show(struct config_item *item, char *page) 1100c17d5d5fSMike Christie { 1101c17d5d5fSMike Christie struct se_dev_attrib *da = to_attrib(item); 1102c17d5d5fSMike Christie u8 flags = da->da_dev->transport->transport_flags; 1103c17d5d5fSMike Christie 1104c17d5d5fSMike Christie return snprintf(page, PAGE_SIZE, "%d\n", 1105c17d5d5fSMike Christie flags & TRANSPORT_FLAG_PASSTHROUGH_PGR ? 0 : 1); 1106c17d5d5fSMike Christie } 1107c17d5d5fSMike Christie 11082eafd729SChristoph Hellwig CONFIGFS_ATTR(, emulate_model_alias); 11092eafd729SChristoph Hellwig CONFIGFS_ATTR(, emulate_dpo); 11102eafd729SChristoph Hellwig CONFIGFS_ATTR(, emulate_fua_write); 11112eafd729SChristoph Hellwig CONFIGFS_ATTR(, emulate_fua_read); 11122eafd729SChristoph Hellwig CONFIGFS_ATTR(, emulate_write_cache); 11132eafd729SChristoph Hellwig CONFIGFS_ATTR(, emulate_ua_intlck_ctrl); 11142eafd729SChristoph Hellwig CONFIGFS_ATTR(, emulate_tas); 11152eafd729SChristoph Hellwig CONFIGFS_ATTR(, emulate_tpu); 11162eafd729SChristoph Hellwig CONFIGFS_ATTR(, emulate_tpws); 11172eafd729SChristoph Hellwig CONFIGFS_ATTR(, emulate_caw); 11182eafd729SChristoph Hellwig CONFIGFS_ATTR(, emulate_3pc); 11192eafd729SChristoph Hellwig CONFIGFS_ATTR(, pi_prot_type); 11202eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(, hw_pi_prot_type); 11212eafd729SChristoph Hellwig CONFIGFS_ATTR(, pi_prot_format); 1122056e8924SDmitry Monakhov CONFIGFS_ATTR(, pi_prot_verify); 11232eafd729SChristoph Hellwig CONFIGFS_ATTR(, enforce_pr_isids); 11242eafd729SChristoph Hellwig CONFIGFS_ATTR(, is_nonrot); 11252eafd729SChristoph Hellwig CONFIGFS_ATTR(, emulate_rest_reord); 11262eafd729SChristoph Hellwig CONFIGFS_ATTR(, force_pr_aptpl); 11272eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(, hw_block_size); 11282eafd729SChristoph Hellwig CONFIGFS_ATTR(, block_size); 11292eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(, hw_max_sectors); 11302eafd729SChristoph Hellwig CONFIGFS_ATTR(, optimal_sectors); 11312eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(, hw_queue_depth); 11322eafd729SChristoph Hellwig CONFIGFS_ATTR(, queue_depth); 11332eafd729SChristoph Hellwig CONFIGFS_ATTR(, max_unmap_lba_count); 11342eafd729SChristoph Hellwig CONFIGFS_ATTR(, max_unmap_block_desc_count); 11352eafd729SChristoph Hellwig CONFIGFS_ATTR(, unmap_granularity); 11362eafd729SChristoph Hellwig CONFIGFS_ATTR(, unmap_granularity_alignment); 1137e6f41633SJamie Pocas CONFIGFS_ATTR(, unmap_zeroes_data); 11382eafd729SChristoph Hellwig CONFIGFS_ATTR(, max_write_same_len); 1139c17d5d5fSMike Christie CONFIGFS_ATTR_RO(, alua_support); 1140c17d5d5fSMike Christie CONFIGFS_ATTR_RO(, pgr_support); 1141c66ac9dbSNicholas Bellinger 11425873c4d1SChristoph Hellwig /* 11435873c4d1SChristoph Hellwig * dev_attrib attributes for devices using the target core SBC/SPC 11445873c4d1SChristoph Hellwig * interpreter. Any backend using spc_parse_cdb should be using 11455873c4d1SChristoph Hellwig * these. 11465873c4d1SChristoph Hellwig */ 11475873c4d1SChristoph Hellwig struct configfs_attribute *sbc_attrib_attrs[] = { 11482eafd729SChristoph Hellwig &attr_emulate_model_alias, 11492eafd729SChristoph Hellwig &attr_emulate_dpo, 11502eafd729SChristoph Hellwig &attr_emulate_fua_write, 11512eafd729SChristoph Hellwig &attr_emulate_fua_read, 11522eafd729SChristoph Hellwig &attr_emulate_write_cache, 11532eafd729SChristoph Hellwig &attr_emulate_ua_intlck_ctrl, 11542eafd729SChristoph Hellwig &attr_emulate_tas, 11552eafd729SChristoph Hellwig &attr_emulate_tpu, 11562eafd729SChristoph Hellwig &attr_emulate_tpws, 11572eafd729SChristoph Hellwig &attr_emulate_caw, 11582eafd729SChristoph Hellwig &attr_emulate_3pc, 11592eafd729SChristoph Hellwig &attr_pi_prot_type, 11602eafd729SChristoph Hellwig &attr_hw_pi_prot_type, 11612eafd729SChristoph Hellwig &attr_pi_prot_format, 1162056e8924SDmitry Monakhov &attr_pi_prot_verify, 11632eafd729SChristoph Hellwig &attr_enforce_pr_isids, 11642eafd729SChristoph Hellwig &attr_is_nonrot, 11652eafd729SChristoph Hellwig &attr_emulate_rest_reord, 11662eafd729SChristoph Hellwig &attr_force_pr_aptpl, 11672eafd729SChristoph Hellwig &attr_hw_block_size, 11682eafd729SChristoph Hellwig &attr_block_size, 11692eafd729SChristoph Hellwig &attr_hw_max_sectors, 11702eafd729SChristoph Hellwig &attr_optimal_sectors, 11712eafd729SChristoph Hellwig &attr_hw_queue_depth, 11722eafd729SChristoph Hellwig &attr_queue_depth, 11732eafd729SChristoph Hellwig &attr_max_unmap_lba_count, 11742eafd729SChristoph Hellwig &attr_max_unmap_block_desc_count, 11752eafd729SChristoph Hellwig &attr_unmap_granularity, 11762eafd729SChristoph Hellwig &attr_unmap_granularity_alignment, 1177e6f41633SJamie Pocas &attr_unmap_zeroes_data, 11782eafd729SChristoph Hellwig &attr_max_write_same_len, 1179c17d5d5fSMike Christie &attr_alua_support, 1180c17d5d5fSMike Christie &attr_pgr_support, 11815873c4d1SChristoph Hellwig NULL, 11825873c4d1SChristoph Hellwig }; 11835873c4d1SChristoph Hellwig EXPORT_SYMBOL(sbc_attrib_attrs); 11845873c4d1SChristoph Hellwig 11855873c4d1SChristoph Hellwig /* 11865873c4d1SChristoph Hellwig * Minimal dev_attrib attributes for devices passing through CDBs. 11875873c4d1SChristoph Hellwig * In this case we only provide a few read-only attributes for 11885873c4d1SChristoph Hellwig * backwards compatibility. 11895873c4d1SChristoph Hellwig */ 11905873c4d1SChristoph Hellwig struct configfs_attribute *passthrough_attrib_attrs[] = { 11912eafd729SChristoph Hellwig &attr_hw_pi_prot_type, 11922eafd729SChristoph Hellwig &attr_hw_block_size, 11932eafd729SChristoph Hellwig &attr_hw_max_sectors, 11942eafd729SChristoph Hellwig &attr_hw_queue_depth, 1195c17d5d5fSMike Christie &attr_alua_support, 1196c17d5d5fSMike Christie &attr_pgr_support, 11975873c4d1SChristoph Hellwig NULL, 11985873c4d1SChristoph Hellwig }; 11995873c4d1SChristoph Hellwig EXPORT_SYMBOL(passthrough_attrib_attrs); 12005873c4d1SChristoph Hellwig 12012eafd729SChristoph Hellwig TB_CIT_SETUP_DRV(dev_attrib, NULL, NULL); 12028dc31ff9SMike Christie TB_CIT_SETUP_DRV(dev_action, NULL, NULL); 1203c66ac9dbSNicholas Bellinger 1204f79a897eSNicholas Bellinger /* End functions for struct config_item_type tb_dev_attrib_cit */ 1205c66ac9dbSNicholas Bellinger 1206f8d389c6SNicholas Bellinger /* Start functions for struct config_item_type tb_dev_wwn_cit */ 1207c66ac9dbSNicholas Bellinger 12082eafd729SChristoph Hellwig static struct t10_wwn *to_t10_wwn(struct config_item *item) 12092eafd729SChristoph Hellwig { 12102eafd729SChristoph Hellwig return container_of(to_config_group(item), struct t10_wwn, t10_wwn_group); 12112eafd729SChristoph Hellwig } 1212c66ac9dbSNicholas Bellinger 1213c66ac9dbSNicholas Bellinger /* 1214c66ac9dbSNicholas Bellinger * VPD page 0x80 Unit serial 1215c66ac9dbSNicholas Bellinger */ 12162eafd729SChristoph Hellwig static ssize_t target_wwn_vpd_unit_serial_show(struct config_item *item, 1217c66ac9dbSNicholas Bellinger char *page) 1218c66ac9dbSNicholas Bellinger { 1219c66ac9dbSNicholas Bellinger return sprintf(page, "T10 VPD Unit Serial Number: %s\n", 12202eafd729SChristoph Hellwig &to_t10_wwn(item)->unit_serial[0]); 1221c66ac9dbSNicholas Bellinger } 1222c66ac9dbSNicholas Bellinger 12232eafd729SChristoph Hellwig static ssize_t target_wwn_vpd_unit_serial_store(struct config_item *item, 12242eafd729SChristoph Hellwig const char *page, size_t count) 1225c66ac9dbSNicholas Bellinger { 12262eafd729SChristoph Hellwig struct t10_wwn *t10_wwn = to_t10_wwn(item); 12270fd97ccfSChristoph Hellwig struct se_device *dev = t10_wwn->t10_dev; 1228c66ac9dbSNicholas Bellinger unsigned char buf[INQUIRY_VPD_SERIAL_LEN]; 1229c66ac9dbSNicholas Bellinger 1230c66ac9dbSNicholas Bellinger /* 1231c66ac9dbSNicholas Bellinger * If Linux/SCSI subsystem_api_t plugin got a VPD Unit Serial 1232c66ac9dbSNicholas Bellinger * from the struct scsi_device level firmware, do not allow 1233c66ac9dbSNicholas Bellinger * VPD Unit Serial to be emulated. 1234c66ac9dbSNicholas Bellinger * 1235c66ac9dbSNicholas Bellinger * Note this struct scsi_device could also be emulating VPD 1236c66ac9dbSNicholas Bellinger * information from its drivers/scsi LLD. But for now we assume 1237c66ac9dbSNicholas Bellinger * it is doing 'the right thing' wrt a world wide unique 1238c66ac9dbSNicholas Bellinger * VPD Unit Serial Number that OS dependent multipath can depend on. 1239c66ac9dbSNicholas Bellinger */ 12400fd97ccfSChristoph Hellwig if (dev->dev_flags & DF_FIRMWARE_VPD_UNIT_SERIAL) { 12416708bb27SAndy Grover pr_err("Underlying SCSI device firmware provided VPD" 1242c66ac9dbSNicholas Bellinger " Unit Serial, ignoring request\n"); 1243c66ac9dbSNicholas Bellinger return -EOPNOTSUPP; 1244c66ac9dbSNicholas Bellinger } 1245c66ac9dbSNicholas Bellinger 124660d645a4SDan Carpenter if (strlen(page) >= INQUIRY_VPD_SERIAL_LEN) { 12476708bb27SAndy Grover pr_err("Emulated VPD Unit Serial exceeds" 1248c66ac9dbSNicholas Bellinger " INQUIRY_VPD_SERIAL_LEN: %d\n", INQUIRY_VPD_SERIAL_LEN); 1249c66ac9dbSNicholas Bellinger return -EOVERFLOW; 1250c66ac9dbSNicholas Bellinger } 1251c66ac9dbSNicholas Bellinger /* 1252c66ac9dbSNicholas Bellinger * Check to see if any active $FABRIC_MOD exports exist. If they 1253c66ac9dbSNicholas Bellinger * do exist, fail here as changing this information on the fly 1254c66ac9dbSNicholas Bellinger * (underneath the initiator side OS dependent multipath code) 1255c66ac9dbSNicholas Bellinger * could cause negative effects. 1256c66ac9dbSNicholas Bellinger */ 12570fd97ccfSChristoph Hellwig if (dev->export_count) { 12586708bb27SAndy Grover pr_err("Unable to set VPD Unit Serial while" 1259c66ac9dbSNicholas Bellinger " active %d $FABRIC_MOD exports exist\n", 12600fd97ccfSChristoph Hellwig dev->export_count); 1261c66ac9dbSNicholas Bellinger return -EINVAL; 1262c66ac9dbSNicholas Bellinger } 12630fd97ccfSChristoph Hellwig 1264c66ac9dbSNicholas Bellinger /* 1265c66ac9dbSNicholas Bellinger * This currently assumes ASCII encoding for emulated VPD Unit Serial. 1266c66ac9dbSNicholas Bellinger * 1267c66ac9dbSNicholas Bellinger * Also, strip any newline added from the userspace 1268c66ac9dbSNicholas Bellinger * echo $UUID > $TARGET/$HBA/$STORAGE_OBJECT/wwn/vpd_unit_serial 1269c66ac9dbSNicholas Bellinger */ 1270c66ac9dbSNicholas Bellinger memset(buf, 0, INQUIRY_VPD_SERIAL_LEN); 1271c66ac9dbSNicholas Bellinger snprintf(buf, INQUIRY_VPD_SERIAL_LEN, "%s", page); 12720fd97ccfSChristoph Hellwig snprintf(dev->t10_wwn.unit_serial, INQUIRY_VPD_SERIAL_LEN, 1273c66ac9dbSNicholas Bellinger "%s", strstrip(buf)); 12740fd97ccfSChristoph Hellwig dev->dev_flags |= DF_EMULATED_VPD_UNIT_SERIAL; 1275c66ac9dbSNicholas Bellinger 12766708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: Set emulated VPD Unit Serial:" 12770fd97ccfSChristoph Hellwig " %s\n", dev->t10_wwn.unit_serial); 1278c66ac9dbSNicholas Bellinger 1279c66ac9dbSNicholas Bellinger return count; 1280c66ac9dbSNicholas Bellinger } 1281c66ac9dbSNicholas Bellinger 1282c66ac9dbSNicholas Bellinger /* 1283c66ac9dbSNicholas Bellinger * VPD page 0x83 Protocol Identifier 1284c66ac9dbSNicholas Bellinger */ 12852eafd729SChristoph Hellwig static ssize_t target_wwn_vpd_protocol_identifier_show(struct config_item *item, 1286c66ac9dbSNicholas Bellinger char *page) 1287c66ac9dbSNicholas Bellinger { 12882eafd729SChristoph Hellwig struct t10_wwn *t10_wwn = to_t10_wwn(item); 1289c66ac9dbSNicholas Bellinger struct t10_vpd *vpd; 1290c66ac9dbSNicholas Bellinger unsigned char buf[VPD_TMP_BUF_SIZE]; 1291c66ac9dbSNicholas Bellinger ssize_t len = 0; 1292c66ac9dbSNicholas Bellinger 1293c66ac9dbSNicholas Bellinger memset(buf, 0, VPD_TMP_BUF_SIZE); 1294c66ac9dbSNicholas Bellinger 1295c66ac9dbSNicholas Bellinger spin_lock(&t10_wwn->t10_vpd_lock); 1296c66ac9dbSNicholas Bellinger list_for_each_entry(vpd, &t10_wwn->t10_vpd_list, vpd_list) { 12976708bb27SAndy Grover if (!vpd->protocol_identifier_set) 1298c66ac9dbSNicholas Bellinger continue; 1299c66ac9dbSNicholas Bellinger 1300c66ac9dbSNicholas Bellinger transport_dump_vpd_proto_id(vpd, buf, VPD_TMP_BUF_SIZE); 1301c66ac9dbSNicholas Bellinger 13026708bb27SAndy Grover if (len + strlen(buf) >= PAGE_SIZE) 1303c66ac9dbSNicholas Bellinger break; 1304c66ac9dbSNicholas Bellinger 1305c66ac9dbSNicholas Bellinger len += sprintf(page+len, "%s", buf); 1306c66ac9dbSNicholas Bellinger } 1307c66ac9dbSNicholas Bellinger spin_unlock(&t10_wwn->t10_vpd_lock); 1308c66ac9dbSNicholas Bellinger 1309c66ac9dbSNicholas Bellinger return len; 1310c66ac9dbSNicholas Bellinger } 1311c66ac9dbSNicholas Bellinger 1312c66ac9dbSNicholas Bellinger /* 1313c66ac9dbSNicholas Bellinger * Generic wrapper for dumping VPD identifiers by association. 1314c66ac9dbSNicholas Bellinger */ 1315c66ac9dbSNicholas Bellinger #define DEF_DEV_WWN_ASSOC_SHOW(_name, _assoc) \ 13162eafd729SChristoph Hellwig static ssize_t target_wwn_##_name##_show(struct config_item *item, \ 1317c66ac9dbSNicholas Bellinger char *page) \ 1318c66ac9dbSNicholas Bellinger { \ 13192eafd729SChristoph Hellwig struct t10_wwn *t10_wwn = to_t10_wwn(item); \ 1320c66ac9dbSNicholas Bellinger struct t10_vpd *vpd; \ 1321c66ac9dbSNicholas Bellinger unsigned char buf[VPD_TMP_BUF_SIZE]; \ 1322c66ac9dbSNicholas Bellinger ssize_t len = 0; \ 1323c66ac9dbSNicholas Bellinger \ 1324c66ac9dbSNicholas Bellinger spin_lock(&t10_wwn->t10_vpd_lock); \ 1325c66ac9dbSNicholas Bellinger list_for_each_entry(vpd, &t10_wwn->t10_vpd_list, vpd_list) { \ 1326c66ac9dbSNicholas Bellinger if (vpd->association != _assoc) \ 1327c66ac9dbSNicholas Bellinger continue; \ 1328c66ac9dbSNicholas Bellinger \ 1329c66ac9dbSNicholas Bellinger memset(buf, 0, VPD_TMP_BUF_SIZE); \ 1330c66ac9dbSNicholas Bellinger transport_dump_vpd_assoc(vpd, buf, VPD_TMP_BUF_SIZE); \ 13316708bb27SAndy Grover if (len + strlen(buf) >= PAGE_SIZE) \ 1332c66ac9dbSNicholas Bellinger break; \ 1333c66ac9dbSNicholas Bellinger len += sprintf(page+len, "%s", buf); \ 1334c66ac9dbSNicholas Bellinger \ 1335c66ac9dbSNicholas Bellinger memset(buf, 0, VPD_TMP_BUF_SIZE); \ 1336c66ac9dbSNicholas Bellinger transport_dump_vpd_ident_type(vpd, buf, VPD_TMP_BUF_SIZE); \ 13376708bb27SAndy Grover if (len + strlen(buf) >= PAGE_SIZE) \ 1338c66ac9dbSNicholas Bellinger break; \ 1339c66ac9dbSNicholas Bellinger len += sprintf(page+len, "%s", buf); \ 1340c66ac9dbSNicholas Bellinger \ 1341c66ac9dbSNicholas Bellinger memset(buf, 0, VPD_TMP_BUF_SIZE); \ 1342c66ac9dbSNicholas Bellinger transport_dump_vpd_ident(vpd, buf, VPD_TMP_BUF_SIZE); \ 13436708bb27SAndy Grover if (len + strlen(buf) >= PAGE_SIZE) \ 1344c66ac9dbSNicholas Bellinger break; \ 1345c66ac9dbSNicholas Bellinger len += sprintf(page+len, "%s", buf); \ 1346c66ac9dbSNicholas Bellinger } \ 1347c66ac9dbSNicholas Bellinger spin_unlock(&t10_wwn->t10_vpd_lock); \ 1348c66ac9dbSNicholas Bellinger \ 1349c66ac9dbSNicholas Bellinger return len; \ 1350c66ac9dbSNicholas Bellinger } 1351c66ac9dbSNicholas Bellinger 13522eafd729SChristoph Hellwig /* VPD page 0x83 Association: Logical Unit */ 1353c66ac9dbSNicholas Bellinger DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_logical_unit, 0x00); 13542eafd729SChristoph Hellwig /* VPD page 0x83 Association: Target Port */ 1355c66ac9dbSNicholas Bellinger DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_target_port, 0x10); 13562eafd729SChristoph Hellwig /* VPD page 0x83 Association: SCSI Target Device */ 1357c66ac9dbSNicholas Bellinger DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_scsi_target_device, 0x20); 1358c66ac9dbSNicholas Bellinger 13592eafd729SChristoph Hellwig CONFIGFS_ATTR(target_wwn_, vpd_unit_serial); 13602eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_wwn_, vpd_protocol_identifier); 13612eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_wwn_, vpd_assoc_logical_unit); 13622eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_wwn_, vpd_assoc_target_port); 13632eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_wwn_, vpd_assoc_scsi_target_device); 1364c66ac9dbSNicholas Bellinger 1365c66ac9dbSNicholas Bellinger static struct configfs_attribute *target_core_dev_wwn_attrs[] = { 13662eafd729SChristoph Hellwig &target_wwn_attr_vpd_unit_serial, 13672eafd729SChristoph Hellwig &target_wwn_attr_vpd_protocol_identifier, 13682eafd729SChristoph Hellwig &target_wwn_attr_vpd_assoc_logical_unit, 13692eafd729SChristoph Hellwig &target_wwn_attr_vpd_assoc_target_port, 13702eafd729SChristoph Hellwig &target_wwn_attr_vpd_assoc_scsi_target_device, 1371c66ac9dbSNicholas Bellinger NULL, 1372c66ac9dbSNicholas Bellinger }; 1373c66ac9dbSNicholas Bellinger 13742eafd729SChristoph Hellwig TB_CIT_SETUP(dev_wwn, NULL, NULL, target_core_dev_wwn_attrs); 1375c66ac9dbSNicholas Bellinger 1376f8d389c6SNicholas Bellinger /* End functions for struct config_item_type tb_dev_wwn_cit */ 1377c66ac9dbSNicholas Bellinger 137891e2e39bSNicholas Bellinger /* Start functions for struct config_item_type tb_dev_pr_cit */ 1379c66ac9dbSNicholas Bellinger 13802eafd729SChristoph Hellwig static struct se_device *pr_to_dev(struct config_item *item) 13812eafd729SChristoph Hellwig { 13822eafd729SChristoph Hellwig return container_of(to_config_group(item), struct se_device, 13832eafd729SChristoph Hellwig dev_pr_group); 13842eafd729SChristoph Hellwig } 1385c66ac9dbSNicholas Bellinger 1386d977f437SChristoph Hellwig static ssize_t target_core_dev_pr_show_spc3_res(struct se_device *dev, 1387d977f437SChristoph Hellwig char *page) 1388c66ac9dbSNicholas Bellinger { 1389c66ac9dbSNicholas Bellinger struct se_node_acl *se_nacl; 1390c66ac9dbSNicholas Bellinger struct t10_pr_registration *pr_reg; 1391c66ac9dbSNicholas Bellinger char i_buf[PR_REG_ISID_ID_LEN]; 1392c66ac9dbSNicholas Bellinger 1393c66ac9dbSNicholas Bellinger memset(i_buf, 0, PR_REG_ISID_ID_LEN); 1394c66ac9dbSNicholas Bellinger 1395c66ac9dbSNicholas Bellinger pr_reg = dev->dev_pr_res_holder; 1396d977f437SChristoph Hellwig if (!pr_reg) 1397d977f437SChristoph Hellwig return sprintf(page, "No SPC-3 Reservation holder\n"); 1398d977f437SChristoph Hellwig 1399c66ac9dbSNicholas Bellinger se_nacl = pr_reg->pr_reg_nacl; 1400d2843c17SAndy Grover core_pr_dump_initiator_port(pr_reg, i_buf, PR_REG_ISID_ID_LEN); 1401c66ac9dbSNicholas Bellinger 1402d977f437SChristoph Hellwig return sprintf(page, "SPC-3 Reservation: %s Initiator: %s%s\n", 1403e3d6f909SAndy Grover se_nacl->se_tpg->se_tpg_tfo->get_fabric_name(), 1404d2843c17SAndy Grover se_nacl->initiatorname, i_buf); 1405c66ac9dbSNicholas Bellinger } 1406c66ac9dbSNicholas Bellinger 1407d977f437SChristoph Hellwig static ssize_t target_core_dev_pr_show_spc2_res(struct se_device *dev, 1408d977f437SChristoph Hellwig char *page) 1409c66ac9dbSNicholas Bellinger { 1410c66ac9dbSNicholas Bellinger struct se_node_acl *se_nacl; 1411d977f437SChristoph Hellwig ssize_t len; 1412c66ac9dbSNicholas Bellinger 1413c66ac9dbSNicholas Bellinger se_nacl = dev->dev_reserved_node_acl; 1414d977f437SChristoph Hellwig if (se_nacl) { 1415d977f437SChristoph Hellwig len = sprintf(page, 1416d977f437SChristoph Hellwig "SPC-2 Reservation: %s Initiator: %s\n", 1417e3d6f909SAndy Grover se_nacl->se_tpg->se_tpg_tfo->get_fabric_name(), 1418c66ac9dbSNicholas Bellinger se_nacl->initiatorname); 1419d977f437SChristoph Hellwig } else { 1420d977f437SChristoph Hellwig len = sprintf(page, "No SPC-2 Reservation holder\n"); 1421d977f437SChristoph Hellwig } 1422d977f437SChristoph Hellwig return len; 1423c66ac9dbSNicholas Bellinger } 1424c66ac9dbSNicholas Bellinger 14252eafd729SChristoph Hellwig static ssize_t target_pr_res_holder_show(struct config_item *item, char *page) 1426c66ac9dbSNicholas Bellinger { 14272eafd729SChristoph Hellwig struct se_device *dev = pr_to_dev(item); 1428d977f437SChristoph Hellwig int ret; 1429c66ac9dbSNicholas Bellinger 14304ec5bf0eSBryant G. Ly if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH_PGR) 1431d977f437SChristoph Hellwig return sprintf(page, "Passthrough\n"); 1432c66ac9dbSNicholas Bellinger 1433d977f437SChristoph Hellwig spin_lock(&dev->dev_reservation_lock); 1434d977f437SChristoph Hellwig if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS) 1435d977f437SChristoph Hellwig ret = target_core_dev_pr_show_spc2_res(dev, page); 1436d977f437SChristoph Hellwig else 1437d977f437SChristoph Hellwig ret = target_core_dev_pr_show_spc3_res(dev, page); 1438d977f437SChristoph Hellwig spin_unlock(&dev->dev_reservation_lock); 1439d977f437SChristoph Hellwig return ret; 1440c66ac9dbSNicholas Bellinger } 1441c66ac9dbSNicholas Bellinger 14422eafd729SChristoph Hellwig static ssize_t target_pr_res_pr_all_tgt_pts_show(struct config_item *item, 14432eafd729SChristoph Hellwig char *page) 1444c66ac9dbSNicholas Bellinger { 14452eafd729SChristoph Hellwig struct se_device *dev = pr_to_dev(item); 1446c66ac9dbSNicholas Bellinger ssize_t len = 0; 1447c66ac9dbSNicholas Bellinger 1448c66ac9dbSNicholas Bellinger spin_lock(&dev->dev_reservation_lock); 1449d977f437SChristoph Hellwig if (!dev->dev_pr_res_holder) { 1450c66ac9dbSNicholas Bellinger len = sprintf(page, "No SPC-3 Reservation holder\n"); 1451d977f437SChristoph Hellwig } else if (dev->dev_pr_res_holder->pr_reg_all_tg_pt) { 1452c66ac9dbSNicholas Bellinger len = sprintf(page, "SPC-3 Reservation: All Target" 1453c66ac9dbSNicholas Bellinger " Ports registration\n"); 1454d977f437SChristoph Hellwig } else { 1455c66ac9dbSNicholas Bellinger len = sprintf(page, "SPC-3 Reservation: Single" 1456c66ac9dbSNicholas Bellinger " Target Port registration\n"); 1457d977f437SChristoph Hellwig } 1458c66ac9dbSNicholas Bellinger 1459d977f437SChristoph Hellwig spin_unlock(&dev->dev_reservation_lock); 1460c66ac9dbSNicholas Bellinger return len; 1461c66ac9dbSNicholas Bellinger } 1462c66ac9dbSNicholas Bellinger 14632eafd729SChristoph Hellwig static ssize_t target_pr_res_pr_generation_show(struct config_item *item, 14642eafd729SChristoph Hellwig char *page) 1465c66ac9dbSNicholas Bellinger { 14662eafd729SChristoph Hellwig return sprintf(page, "0x%08x\n", pr_to_dev(item)->t10_pr.pr_generation); 1467c66ac9dbSNicholas Bellinger } 1468c66ac9dbSNicholas Bellinger 1469c66ac9dbSNicholas Bellinger 14702eafd729SChristoph Hellwig static ssize_t target_pr_res_pr_holder_tg_port_show(struct config_item *item, 14712eafd729SChristoph Hellwig char *page) 1472c66ac9dbSNicholas Bellinger { 14732eafd729SChristoph Hellwig struct se_device *dev = pr_to_dev(item); 1474c66ac9dbSNicholas Bellinger struct se_node_acl *se_nacl; 1475c66ac9dbSNicholas Bellinger struct se_portal_group *se_tpg; 1476c66ac9dbSNicholas Bellinger struct t10_pr_registration *pr_reg; 14779ac8928eSChristoph Hellwig const struct target_core_fabric_ops *tfo; 1478c66ac9dbSNicholas Bellinger ssize_t len = 0; 1479c66ac9dbSNicholas Bellinger 1480c66ac9dbSNicholas Bellinger spin_lock(&dev->dev_reservation_lock); 1481c66ac9dbSNicholas Bellinger pr_reg = dev->dev_pr_res_holder; 14826708bb27SAndy Grover if (!pr_reg) { 1483c66ac9dbSNicholas Bellinger len = sprintf(page, "No SPC-3 Reservation holder\n"); 1484d977f437SChristoph Hellwig goto out_unlock; 1485c66ac9dbSNicholas Bellinger } 1486d977f437SChristoph Hellwig 1487c66ac9dbSNicholas Bellinger se_nacl = pr_reg->pr_reg_nacl; 1488c66ac9dbSNicholas Bellinger se_tpg = se_nacl->se_tpg; 1489e3d6f909SAndy Grover tfo = se_tpg->se_tpg_tfo; 1490c66ac9dbSNicholas Bellinger 1491c66ac9dbSNicholas Bellinger len += sprintf(page+len, "SPC-3 Reservation: %s" 1492c66ac9dbSNicholas Bellinger " Target Node Endpoint: %s\n", tfo->get_fabric_name(), 1493c66ac9dbSNicholas Bellinger tfo->tpg_get_wwn(se_tpg)); 1494c66ac9dbSNicholas Bellinger len += sprintf(page+len, "SPC-3 Reservation: Relative Port" 149535d1efe8SMasanari Iida " Identifier Tag: %hu %s Portal Group Tag: %hu" 1496f2d30680SHannes Reinecke " %s Logical Unit: %llu\n", pr_reg->tg_pt_sep_rtpi, 1497c66ac9dbSNicholas Bellinger tfo->get_fabric_name(), tfo->tpg_get_tag(se_tpg), 149879dc9c9eSNicholas Bellinger tfo->get_fabric_name(), pr_reg->pr_aptpl_target_lun); 1499c66ac9dbSNicholas Bellinger 1500d977f437SChristoph Hellwig out_unlock: 1501d977f437SChristoph Hellwig spin_unlock(&dev->dev_reservation_lock); 1502c66ac9dbSNicholas Bellinger return len; 1503c66ac9dbSNicholas Bellinger } 1504c66ac9dbSNicholas Bellinger 1505c66ac9dbSNicholas Bellinger 15062eafd729SChristoph Hellwig static ssize_t target_pr_res_pr_registered_i_pts_show(struct config_item *item, 15072eafd729SChristoph Hellwig char *page) 1508c66ac9dbSNicholas Bellinger { 15092eafd729SChristoph Hellwig struct se_device *dev = pr_to_dev(item); 15109ac8928eSChristoph Hellwig const struct target_core_fabric_ops *tfo; 1511c66ac9dbSNicholas Bellinger struct t10_pr_registration *pr_reg; 1512c66ac9dbSNicholas Bellinger unsigned char buf[384]; 1513c66ac9dbSNicholas Bellinger char i_buf[PR_REG_ISID_ID_LEN]; 1514c66ac9dbSNicholas Bellinger ssize_t len = 0; 1515d2843c17SAndy Grover int reg_count = 0; 1516c66ac9dbSNicholas Bellinger 1517c66ac9dbSNicholas Bellinger len += sprintf(page+len, "SPC-3 PR Registrations:\n"); 1518c66ac9dbSNicholas Bellinger 15190fd97ccfSChristoph Hellwig spin_lock(&dev->t10_pr.registration_lock); 15200fd97ccfSChristoph Hellwig list_for_each_entry(pr_reg, &dev->t10_pr.registration_list, 1521c66ac9dbSNicholas Bellinger pr_reg_list) { 1522c66ac9dbSNicholas Bellinger 1523c66ac9dbSNicholas Bellinger memset(buf, 0, 384); 1524c66ac9dbSNicholas Bellinger memset(i_buf, 0, PR_REG_ISID_ID_LEN); 1525c66ac9dbSNicholas Bellinger tfo = pr_reg->pr_reg_nacl->se_tpg->se_tpg_tfo; 1526d2843c17SAndy Grover core_pr_dump_initiator_port(pr_reg, i_buf, 1527c66ac9dbSNicholas Bellinger PR_REG_ISID_ID_LEN); 1528c66ac9dbSNicholas Bellinger sprintf(buf, "%s Node: %s%s Key: 0x%016Lx PRgen: 0x%08x\n", 1529c66ac9dbSNicholas Bellinger tfo->get_fabric_name(), 1530d2843c17SAndy Grover pr_reg->pr_reg_nacl->initiatorname, i_buf, pr_reg->pr_res_key, 1531c66ac9dbSNicholas Bellinger pr_reg->pr_res_generation); 1532c66ac9dbSNicholas Bellinger 15336708bb27SAndy Grover if (len + strlen(buf) >= PAGE_SIZE) 1534c66ac9dbSNicholas Bellinger break; 1535c66ac9dbSNicholas Bellinger 1536c66ac9dbSNicholas Bellinger len += sprintf(page+len, "%s", buf); 1537c66ac9dbSNicholas Bellinger reg_count++; 1538c66ac9dbSNicholas Bellinger } 15390fd97ccfSChristoph Hellwig spin_unlock(&dev->t10_pr.registration_lock); 1540c66ac9dbSNicholas Bellinger 15416708bb27SAndy Grover if (!reg_count) 1542c66ac9dbSNicholas Bellinger len += sprintf(page+len, "None\n"); 1543c66ac9dbSNicholas Bellinger 1544c66ac9dbSNicholas Bellinger return len; 1545c66ac9dbSNicholas Bellinger } 1546c66ac9dbSNicholas Bellinger 15472eafd729SChristoph Hellwig static ssize_t target_pr_res_pr_type_show(struct config_item *item, char *page) 1548c66ac9dbSNicholas Bellinger { 15492eafd729SChristoph Hellwig struct se_device *dev = pr_to_dev(item); 1550c66ac9dbSNicholas Bellinger struct t10_pr_registration *pr_reg; 1551c66ac9dbSNicholas Bellinger ssize_t len = 0; 1552c66ac9dbSNicholas Bellinger 1553c66ac9dbSNicholas Bellinger spin_lock(&dev->dev_reservation_lock); 1554c66ac9dbSNicholas Bellinger pr_reg = dev->dev_pr_res_holder; 1555d977f437SChristoph Hellwig if (pr_reg) { 1556c66ac9dbSNicholas Bellinger len = sprintf(page, "SPC-3 Reservation Type: %s\n", 1557c66ac9dbSNicholas Bellinger core_scsi3_pr_dump_type(pr_reg->pr_res_type)); 1558d977f437SChristoph Hellwig } else { 1559d977f437SChristoph Hellwig len = sprintf(page, "No SPC-3 Reservation holder\n"); 1560d977f437SChristoph Hellwig } 1561c66ac9dbSNicholas Bellinger 1562d977f437SChristoph Hellwig spin_unlock(&dev->dev_reservation_lock); 1563c66ac9dbSNicholas Bellinger return len; 1564c66ac9dbSNicholas Bellinger } 1565c66ac9dbSNicholas Bellinger 15662eafd729SChristoph Hellwig static ssize_t target_pr_res_type_show(struct config_item *item, char *page) 1567c66ac9dbSNicholas Bellinger { 15682eafd729SChristoph Hellwig struct se_device *dev = pr_to_dev(item); 15692eafd729SChristoph Hellwig 15704ec5bf0eSBryant G. Ly if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH_PGR) 1571d977f437SChristoph Hellwig return sprintf(page, "SPC_PASSTHROUGH\n"); 1572d977f437SChristoph Hellwig else if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS) 1573d977f437SChristoph Hellwig return sprintf(page, "SPC2_RESERVATIONS\n"); 1574d977f437SChristoph Hellwig else 1575d977f437SChristoph Hellwig return sprintf(page, "SPC3_PERSISTENT_RESERVATIONS\n"); 1576c66ac9dbSNicholas Bellinger } 1577c66ac9dbSNicholas Bellinger 15782eafd729SChristoph Hellwig static ssize_t target_pr_res_aptpl_active_show(struct config_item *item, 15792eafd729SChristoph Hellwig char *page) 1580c66ac9dbSNicholas Bellinger { 15812eafd729SChristoph Hellwig struct se_device *dev = pr_to_dev(item); 15822eafd729SChristoph Hellwig 15834ec5bf0eSBryant G. Ly if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH_PGR) 1584c66ac9dbSNicholas Bellinger return 0; 1585c66ac9dbSNicholas Bellinger 1586c66ac9dbSNicholas Bellinger return sprintf(page, "APTPL Bit Status: %s\n", 15870fd97ccfSChristoph Hellwig (dev->t10_pr.pr_aptpl_active) ? "Activated" : "Disabled"); 1588c66ac9dbSNicholas Bellinger } 1589c66ac9dbSNicholas Bellinger 15902eafd729SChristoph Hellwig static ssize_t target_pr_res_aptpl_metadata_show(struct config_item *item, 15912eafd729SChristoph Hellwig char *page) 1592c66ac9dbSNicholas Bellinger { 15932eafd729SChristoph Hellwig struct se_device *dev = pr_to_dev(item); 15942eafd729SChristoph Hellwig 15954ec5bf0eSBryant G. Ly if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH_PGR) 1596c66ac9dbSNicholas Bellinger return 0; 1597c66ac9dbSNicholas Bellinger 1598c66ac9dbSNicholas Bellinger return sprintf(page, "Ready to process PR APTPL metadata..\n"); 1599c66ac9dbSNicholas Bellinger } 1600c66ac9dbSNicholas Bellinger 1601c66ac9dbSNicholas Bellinger enum { 1602c66ac9dbSNicholas Bellinger Opt_initiator_fabric, Opt_initiator_node, Opt_initiator_sid, 1603c66ac9dbSNicholas Bellinger Opt_sa_res_key, Opt_res_holder, Opt_res_type, Opt_res_scope, 1604c66ac9dbSNicholas Bellinger Opt_res_all_tg_pt, Opt_mapped_lun, Opt_target_fabric, 1605c66ac9dbSNicholas Bellinger Opt_target_node, Opt_tpgt, Opt_port_rtpi, Opt_target_lun, Opt_err 1606c66ac9dbSNicholas Bellinger }; 1607c66ac9dbSNicholas Bellinger 1608c66ac9dbSNicholas Bellinger static match_table_t tokens = { 1609c66ac9dbSNicholas Bellinger {Opt_initiator_fabric, "initiator_fabric=%s"}, 1610c66ac9dbSNicholas Bellinger {Opt_initiator_node, "initiator_node=%s"}, 1611c66ac9dbSNicholas Bellinger {Opt_initiator_sid, "initiator_sid=%s"}, 1612c66ac9dbSNicholas Bellinger {Opt_sa_res_key, "sa_res_key=%s"}, 1613c66ac9dbSNicholas Bellinger {Opt_res_holder, "res_holder=%d"}, 1614c66ac9dbSNicholas Bellinger {Opt_res_type, "res_type=%d"}, 1615c66ac9dbSNicholas Bellinger {Opt_res_scope, "res_scope=%d"}, 1616c66ac9dbSNicholas Bellinger {Opt_res_all_tg_pt, "res_all_tg_pt=%d"}, 1617a2db857bStangwenji {Opt_mapped_lun, "mapped_lun=%u"}, 1618c66ac9dbSNicholas Bellinger {Opt_target_fabric, "target_fabric=%s"}, 1619c66ac9dbSNicholas Bellinger {Opt_target_node, "target_node=%s"}, 1620c66ac9dbSNicholas Bellinger {Opt_tpgt, "tpgt=%d"}, 1621c66ac9dbSNicholas Bellinger {Opt_port_rtpi, "port_rtpi=%d"}, 1622a2db857bStangwenji {Opt_target_lun, "target_lun=%u"}, 1623c66ac9dbSNicholas Bellinger {Opt_err, NULL} 1624c66ac9dbSNicholas Bellinger }; 1625c66ac9dbSNicholas Bellinger 16262eafd729SChristoph Hellwig static ssize_t target_pr_res_aptpl_metadata_store(struct config_item *item, 16272eafd729SChristoph Hellwig const char *page, size_t count) 1628c66ac9dbSNicholas Bellinger { 16292eafd729SChristoph Hellwig struct se_device *dev = pr_to_dev(item); 16306d180253SJesper Juhl unsigned char *i_fabric = NULL, *i_port = NULL, *isid = NULL; 16316d180253SJesper Juhl unsigned char *t_fabric = NULL, *t_port = NULL; 16328d213559SJoern Engel char *orig, *ptr, *opts; 1633c66ac9dbSNicholas Bellinger substring_t args[MAX_OPT_ARGS]; 1634c66ac9dbSNicholas Bellinger unsigned long long tmp_ll; 1635c66ac9dbSNicholas Bellinger u64 sa_res_key = 0; 1636f2d30680SHannes Reinecke u64 mapped_lun = 0, target_lun = 0; 1637c66ac9dbSNicholas Bellinger int ret = -1, res_holder = 0, all_tg_pt = 0, arg, token; 163845fb94c2SBart Van Assche u16 tpgt = 0; 163945fb94c2SBart Van Assche u8 type = 0; 1640c66ac9dbSNicholas Bellinger 16414ec5bf0eSBryant G. Ly if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH_PGR) 16429105bfc0SAndy Grover return count; 1643d977f437SChristoph Hellwig if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS) 16449105bfc0SAndy Grover return count; 1645c66ac9dbSNicholas Bellinger 16460fd97ccfSChristoph Hellwig if (dev->export_count) { 16476708bb27SAndy Grover pr_debug("Unable to process APTPL metadata while" 1648c66ac9dbSNicholas Bellinger " active fabric exports exist\n"); 1649c66ac9dbSNicholas Bellinger return -EINVAL; 1650c66ac9dbSNicholas Bellinger } 1651c66ac9dbSNicholas Bellinger 1652c66ac9dbSNicholas Bellinger opts = kstrdup(page, GFP_KERNEL); 1653c66ac9dbSNicholas Bellinger if (!opts) 1654c66ac9dbSNicholas Bellinger return -ENOMEM; 1655c66ac9dbSNicholas Bellinger 1656c66ac9dbSNicholas Bellinger orig = opts; 165790c161b6SSebastian Andrzej Siewior while ((ptr = strsep(&opts, ",\n")) != NULL) { 1658c66ac9dbSNicholas Bellinger if (!*ptr) 1659c66ac9dbSNicholas Bellinger continue; 1660c66ac9dbSNicholas Bellinger 1661c66ac9dbSNicholas Bellinger token = match_token(ptr, tokens, args); 1662c66ac9dbSNicholas Bellinger switch (token) { 1663c66ac9dbSNicholas Bellinger case Opt_initiator_fabric: 16648d213559SJoern Engel i_fabric = match_strdup(args); 16656d180253SJesper Juhl if (!i_fabric) { 16666d180253SJesper Juhl ret = -ENOMEM; 16676d180253SJesper Juhl goto out; 16686d180253SJesper Juhl } 1669c66ac9dbSNicholas Bellinger break; 1670c66ac9dbSNicholas Bellinger case Opt_initiator_node: 16718d213559SJoern Engel i_port = match_strdup(args); 16726d180253SJesper Juhl if (!i_port) { 16736d180253SJesper Juhl ret = -ENOMEM; 16746d180253SJesper Juhl goto out; 16756d180253SJesper Juhl } 167660d645a4SDan Carpenter if (strlen(i_port) >= PR_APTPL_MAX_IPORT_LEN) { 16776708bb27SAndy Grover pr_err("APTPL metadata initiator_node=" 1678c66ac9dbSNicholas Bellinger " exceeds PR_APTPL_MAX_IPORT_LEN: %d\n", 1679c66ac9dbSNicholas Bellinger PR_APTPL_MAX_IPORT_LEN); 1680c66ac9dbSNicholas Bellinger ret = -EINVAL; 1681c66ac9dbSNicholas Bellinger break; 1682c66ac9dbSNicholas Bellinger } 1683c66ac9dbSNicholas Bellinger break; 1684c66ac9dbSNicholas Bellinger case Opt_initiator_sid: 16858d213559SJoern Engel isid = match_strdup(args); 16866d180253SJesper Juhl if (!isid) { 16876d180253SJesper Juhl ret = -ENOMEM; 16886d180253SJesper Juhl goto out; 16896d180253SJesper Juhl } 169060d645a4SDan Carpenter if (strlen(isid) >= PR_REG_ISID_LEN) { 16916708bb27SAndy Grover pr_err("APTPL metadata initiator_isid" 1692c66ac9dbSNicholas Bellinger "= exceeds PR_REG_ISID_LEN: %d\n", 1693c66ac9dbSNicholas Bellinger PR_REG_ISID_LEN); 1694c66ac9dbSNicholas Bellinger ret = -EINVAL; 1695c66ac9dbSNicholas Bellinger break; 1696c66ac9dbSNicholas Bellinger } 1697c66ac9dbSNicholas Bellinger break; 1698c66ac9dbSNicholas Bellinger case Opt_sa_res_key: 1699a2db857bStangwenji ret = match_u64(args, &tmp_ll); 1700c66ac9dbSNicholas Bellinger if (ret < 0) { 17018d213559SJoern Engel pr_err("kstrtoull() failed for sa_res_key=\n"); 1702c66ac9dbSNicholas Bellinger goto out; 1703c66ac9dbSNicholas Bellinger } 1704c66ac9dbSNicholas Bellinger sa_res_key = (u64)tmp_ll; 1705c66ac9dbSNicholas Bellinger break; 1706c66ac9dbSNicholas Bellinger /* 1707c66ac9dbSNicholas Bellinger * PR APTPL Metadata for Reservation 1708c66ac9dbSNicholas Bellinger */ 1709c66ac9dbSNicholas Bellinger case Opt_res_holder: 1710c2091026SDavid Disseldorp ret = match_int(args, &arg); 1711c2091026SDavid Disseldorp if (ret) 1712c2091026SDavid Disseldorp goto out; 1713c66ac9dbSNicholas Bellinger res_holder = arg; 1714c66ac9dbSNicholas Bellinger break; 1715c66ac9dbSNicholas Bellinger case Opt_res_type: 1716c2091026SDavid Disseldorp ret = match_int(args, &arg); 1717c2091026SDavid Disseldorp if (ret) 1718c2091026SDavid Disseldorp goto out; 1719c66ac9dbSNicholas Bellinger type = (u8)arg; 1720c66ac9dbSNicholas Bellinger break; 1721c66ac9dbSNicholas Bellinger case Opt_res_scope: 1722c2091026SDavid Disseldorp ret = match_int(args, &arg); 1723c2091026SDavid Disseldorp if (ret) 1724c2091026SDavid Disseldorp goto out; 1725c66ac9dbSNicholas Bellinger break; 1726c66ac9dbSNicholas Bellinger case Opt_res_all_tg_pt: 1727c2091026SDavid Disseldorp ret = match_int(args, &arg); 1728c2091026SDavid Disseldorp if (ret) 1729c2091026SDavid Disseldorp goto out; 1730c66ac9dbSNicholas Bellinger all_tg_pt = (int)arg; 1731c66ac9dbSNicholas Bellinger break; 1732c66ac9dbSNicholas Bellinger case Opt_mapped_lun: 1733a2db857bStangwenji ret = match_u64(args, &tmp_ll); 1734c2091026SDavid Disseldorp if (ret) 1735c2091026SDavid Disseldorp goto out; 1736a2db857bStangwenji mapped_lun = (u64)tmp_ll; 1737c66ac9dbSNicholas Bellinger break; 1738c66ac9dbSNicholas Bellinger /* 1739c66ac9dbSNicholas Bellinger * PR APTPL Metadata for Target Port 1740c66ac9dbSNicholas Bellinger */ 1741c66ac9dbSNicholas Bellinger case Opt_target_fabric: 17428d213559SJoern Engel t_fabric = match_strdup(args); 17436d180253SJesper Juhl if (!t_fabric) { 17446d180253SJesper Juhl ret = -ENOMEM; 17456d180253SJesper Juhl goto out; 17466d180253SJesper Juhl } 1747c66ac9dbSNicholas Bellinger break; 1748c66ac9dbSNicholas Bellinger case Opt_target_node: 17498d213559SJoern Engel t_port = match_strdup(args); 17506d180253SJesper Juhl if (!t_port) { 17516d180253SJesper Juhl ret = -ENOMEM; 17526d180253SJesper Juhl goto out; 17536d180253SJesper Juhl } 175460d645a4SDan Carpenter if (strlen(t_port) >= PR_APTPL_MAX_TPORT_LEN) { 17556708bb27SAndy Grover pr_err("APTPL metadata target_node=" 1756c66ac9dbSNicholas Bellinger " exceeds PR_APTPL_MAX_TPORT_LEN: %d\n", 1757c66ac9dbSNicholas Bellinger PR_APTPL_MAX_TPORT_LEN); 1758c66ac9dbSNicholas Bellinger ret = -EINVAL; 1759c66ac9dbSNicholas Bellinger break; 1760c66ac9dbSNicholas Bellinger } 1761c66ac9dbSNicholas Bellinger break; 1762c66ac9dbSNicholas Bellinger case Opt_tpgt: 1763c2091026SDavid Disseldorp ret = match_int(args, &arg); 1764c2091026SDavid Disseldorp if (ret) 1765c2091026SDavid Disseldorp goto out; 1766c66ac9dbSNicholas Bellinger tpgt = (u16)arg; 1767c66ac9dbSNicholas Bellinger break; 1768c66ac9dbSNicholas Bellinger case Opt_port_rtpi: 1769c2091026SDavid Disseldorp ret = match_int(args, &arg); 1770c2091026SDavid Disseldorp if (ret) 1771c2091026SDavid Disseldorp goto out; 1772c66ac9dbSNicholas Bellinger break; 1773c66ac9dbSNicholas Bellinger case Opt_target_lun: 1774a2db857bStangwenji ret = match_u64(args, &tmp_ll); 1775c2091026SDavid Disseldorp if (ret) 1776c2091026SDavid Disseldorp goto out; 1777a2db857bStangwenji target_lun = (u64)tmp_ll; 1778c66ac9dbSNicholas Bellinger break; 1779c66ac9dbSNicholas Bellinger default: 1780c66ac9dbSNicholas Bellinger break; 1781c66ac9dbSNicholas Bellinger } 1782c66ac9dbSNicholas Bellinger } 1783c66ac9dbSNicholas Bellinger 17846708bb27SAndy Grover if (!i_port || !t_port || !sa_res_key) { 17856708bb27SAndy Grover pr_err("Illegal parameters for APTPL registration\n"); 1786c66ac9dbSNicholas Bellinger ret = -EINVAL; 1787c66ac9dbSNicholas Bellinger goto out; 1788c66ac9dbSNicholas Bellinger } 1789c66ac9dbSNicholas Bellinger 1790c66ac9dbSNicholas Bellinger if (res_holder && !(type)) { 17916708bb27SAndy Grover pr_err("Illegal PR type: 0x%02x for reservation" 1792c66ac9dbSNicholas Bellinger " holder\n", type); 1793c66ac9dbSNicholas Bellinger ret = -EINVAL; 1794c66ac9dbSNicholas Bellinger goto out; 1795c66ac9dbSNicholas Bellinger } 1796c66ac9dbSNicholas Bellinger 17970fd97ccfSChristoph Hellwig ret = core_scsi3_alloc_aptpl_registration(&dev->t10_pr, sa_res_key, 1798c66ac9dbSNicholas Bellinger i_port, isid, mapped_lun, t_port, tpgt, target_lun, 1799c66ac9dbSNicholas Bellinger res_holder, all_tg_pt, type); 1800c66ac9dbSNicholas Bellinger out: 18016d180253SJesper Juhl kfree(i_fabric); 18026d180253SJesper Juhl kfree(i_port); 18036d180253SJesper Juhl kfree(isid); 18046d180253SJesper Juhl kfree(t_fabric); 18056d180253SJesper Juhl kfree(t_port); 1806c66ac9dbSNicholas Bellinger kfree(orig); 1807c66ac9dbSNicholas Bellinger return (ret == 0) ? count : ret; 1808c66ac9dbSNicholas Bellinger } 1809c66ac9dbSNicholas Bellinger 1810c66ac9dbSNicholas Bellinger 18112eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_pr_, res_holder); 18122eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_pr_, res_pr_all_tgt_pts); 18132eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_pr_, res_pr_generation); 18142eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_pr_, res_pr_holder_tg_port); 18152eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_pr_, res_pr_registered_i_pts); 18162eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_pr_, res_pr_type); 18172eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_pr_, res_type); 18182eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_pr_, res_aptpl_active); 18192eafd729SChristoph Hellwig CONFIGFS_ATTR(target_pr_, res_aptpl_metadata); 1820c66ac9dbSNicholas Bellinger 1821c66ac9dbSNicholas Bellinger static struct configfs_attribute *target_core_dev_pr_attrs[] = { 18222eafd729SChristoph Hellwig &target_pr_attr_res_holder, 18232eafd729SChristoph Hellwig &target_pr_attr_res_pr_all_tgt_pts, 18242eafd729SChristoph Hellwig &target_pr_attr_res_pr_generation, 18252eafd729SChristoph Hellwig &target_pr_attr_res_pr_holder_tg_port, 18262eafd729SChristoph Hellwig &target_pr_attr_res_pr_registered_i_pts, 18272eafd729SChristoph Hellwig &target_pr_attr_res_pr_type, 18282eafd729SChristoph Hellwig &target_pr_attr_res_type, 18292eafd729SChristoph Hellwig &target_pr_attr_res_aptpl_active, 18302eafd729SChristoph Hellwig &target_pr_attr_res_aptpl_metadata, 1831c66ac9dbSNicholas Bellinger NULL, 1832c66ac9dbSNicholas Bellinger }; 1833c66ac9dbSNicholas Bellinger 18342eafd729SChristoph Hellwig TB_CIT_SETUP(dev_pr, NULL, NULL, target_core_dev_pr_attrs); 1835c66ac9dbSNicholas Bellinger 183691e2e39bSNicholas Bellinger /* End functions for struct config_item_type tb_dev_pr_cit */ 1837c66ac9dbSNicholas Bellinger 183873112edcSNicholas Bellinger /* Start functions for struct config_item_type tb_dev_cit */ 1839c66ac9dbSNicholas Bellinger 18402eafd729SChristoph Hellwig static inline struct se_device *to_device(struct config_item *item) 1841c66ac9dbSNicholas Bellinger { 18422eafd729SChristoph Hellwig return container_of(to_config_group(item), struct se_device, dev_group); 18432eafd729SChristoph Hellwig } 18442eafd729SChristoph Hellwig 18452eafd729SChristoph Hellwig static ssize_t target_dev_info_show(struct config_item *item, char *page) 18462eafd729SChristoph Hellwig { 18472eafd729SChristoph Hellwig struct se_device *dev = to_device(item); 1848c66ac9dbSNicholas Bellinger int bl = 0; 1849c66ac9dbSNicholas Bellinger ssize_t read_bytes = 0; 1850c66ac9dbSNicholas Bellinger 18510fd97ccfSChristoph Hellwig transport_dump_dev_state(dev, page, &bl); 1852c66ac9dbSNicholas Bellinger read_bytes += bl; 18530a06d430SChristoph Hellwig read_bytes += dev->transport->show_configfs_dev_params(dev, 18540a06d430SChristoph Hellwig page+read_bytes); 1855c66ac9dbSNicholas Bellinger return read_bytes; 1856c66ac9dbSNicholas Bellinger } 1857c66ac9dbSNicholas Bellinger 18582eafd729SChristoph Hellwig static ssize_t target_dev_control_store(struct config_item *item, 18592eafd729SChristoph Hellwig const char *page, size_t count) 1860c66ac9dbSNicholas Bellinger { 18612eafd729SChristoph Hellwig struct se_device *dev = to_device(item); 1862c66ac9dbSNicholas Bellinger 18630a06d430SChristoph Hellwig return dev->transport->set_configfs_dev_params(dev, page, count); 1864c66ac9dbSNicholas Bellinger } 1865c66ac9dbSNicholas Bellinger 18662eafd729SChristoph Hellwig static ssize_t target_dev_alias_show(struct config_item *item, char *page) 1867c66ac9dbSNicholas Bellinger { 18682eafd729SChristoph Hellwig struct se_device *dev = to_device(item); 1869c66ac9dbSNicholas Bellinger 18700fd97ccfSChristoph Hellwig if (!(dev->dev_flags & DF_USING_ALIAS)) 1871c66ac9dbSNicholas Bellinger return 0; 1872c66ac9dbSNicholas Bellinger 18730fd97ccfSChristoph Hellwig return snprintf(page, PAGE_SIZE, "%s\n", dev->dev_alias); 1874c66ac9dbSNicholas Bellinger } 1875c66ac9dbSNicholas Bellinger 18762eafd729SChristoph Hellwig static ssize_t target_dev_alias_store(struct config_item *item, 18772eafd729SChristoph Hellwig const char *page, size_t count) 1878c66ac9dbSNicholas Bellinger { 18792eafd729SChristoph Hellwig struct se_device *dev = to_device(item); 18800fd97ccfSChristoph Hellwig struct se_hba *hba = dev->se_hba; 1881c66ac9dbSNicholas Bellinger ssize_t read_bytes; 1882c66ac9dbSNicholas Bellinger 1883c66ac9dbSNicholas Bellinger if (count > (SE_DEV_ALIAS_LEN-1)) { 18846708bb27SAndy Grover pr_err("alias count: %d exceeds" 1885c66ac9dbSNicholas Bellinger " SE_DEV_ALIAS_LEN-1: %u\n", (int)count, 1886c66ac9dbSNicholas Bellinger SE_DEV_ALIAS_LEN-1); 1887c66ac9dbSNicholas Bellinger return -EINVAL; 1888c66ac9dbSNicholas Bellinger } 1889c66ac9dbSNicholas Bellinger 18900fd97ccfSChristoph Hellwig read_bytes = snprintf(&dev->dev_alias[0], SE_DEV_ALIAS_LEN, "%s", page); 18913011684cSDan Carpenter if (!read_bytes) 18923011684cSDan Carpenter return -EINVAL; 18930fd97ccfSChristoph Hellwig if (dev->dev_alias[read_bytes - 1] == '\n') 18940fd97ccfSChristoph Hellwig dev->dev_alias[read_bytes - 1] = '\0'; 18950877eafdSSebastian Andrzej Siewior 18960fd97ccfSChristoph Hellwig dev->dev_flags |= DF_USING_ALIAS; 18973011684cSDan Carpenter 18986708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: %s/%s set alias: %s\n", 1899c66ac9dbSNicholas Bellinger config_item_name(&hba->hba_group.cg_item), 19000fd97ccfSChristoph Hellwig config_item_name(&dev->dev_group.cg_item), 19010fd97ccfSChristoph Hellwig dev->dev_alias); 1902c66ac9dbSNicholas Bellinger 1903c66ac9dbSNicholas Bellinger return read_bytes; 1904c66ac9dbSNicholas Bellinger } 1905c66ac9dbSNicholas Bellinger 19062eafd729SChristoph Hellwig static ssize_t target_dev_udev_path_show(struct config_item *item, char *page) 1907c66ac9dbSNicholas Bellinger { 19082eafd729SChristoph Hellwig struct se_device *dev = to_device(item); 1909c66ac9dbSNicholas Bellinger 19100fd97ccfSChristoph Hellwig if (!(dev->dev_flags & DF_USING_UDEV_PATH)) 1911c66ac9dbSNicholas Bellinger return 0; 1912c66ac9dbSNicholas Bellinger 19130fd97ccfSChristoph Hellwig return snprintf(page, PAGE_SIZE, "%s\n", dev->udev_path); 1914c66ac9dbSNicholas Bellinger } 1915c66ac9dbSNicholas Bellinger 19162eafd729SChristoph Hellwig static ssize_t target_dev_udev_path_store(struct config_item *item, 19172eafd729SChristoph Hellwig const char *page, size_t count) 1918c66ac9dbSNicholas Bellinger { 19192eafd729SChristoph Hellwig struct se_device *dev = to_device(item); 19200fd97ccfSChristoph Hellwig struct se_hba *hba = dev->se_hba; 1921c66ac9dbSNicholas Bellinger ssize_t read_bytes; 1922c66ac9dbSNicholas Bellinger 1923c66ac9dbSNicholas Bellinger if (count > (SE_UDEV_PATH_LEN-1)) { 19246708bb27SAndy Grover pr_err("udev_path count: %d exceeds" 1925c66ac9dbSNicholas Bellinger " SE_UDEV_PATH_LEN-1: %u\n", (int)count, 1926c66ac9dbSNicholas Bellinger SE_UDEV_PATH_LEN-1); 1927c66ac9dbSNicholas Bellinger return -EINVAL; 1928c66ac9dbSNicholas Bellinger } 1929c66ac9dbSNicholas Bellinger 19300fd97ccfSChristoph Hellwig read_bytes = snprintf(&dev->udev_path[0], SE_UDEV_PATH_LEN, 1931c66ac9dbSNicholas Bellinger "%s", page); 19323011684cSDan Carpenter if (!read_bytes) 19333011684cSDan Carpenter return -EINVAL; 19340fd97ccfSChristoph Hellwig if (dev->udev_path[read_bytes - 1] == '\n') 19350fd97ccfSChristoph Hellwig dev->udev_path[read_bytes - 1] = '\0'; 19360877eafdSSebastian Andrzej Siewior 19370fd97ccfSChristoph Hellwig dev->dev_flags |= DF_USING_UDEV_PATH; 19383011684cSDan Carpenter 19396708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: %s/%s set udev_path: %s\n", 1940c66ac9dbSNicholas Bellinger config_item_name(&hba->hba_group.cg_item), 19410fd97ccfSChristoph Hellwig config_item_name(&dev->dev_group.cg_item), 19420fd97ccfSChristoph Hellwig dev->udev_path); 1943c66ac9dbSNicholas Bellinger 1944c66ac9dbSNicholas Bellinger return read_bytes; 1945c66ac9dbSNicholas Bellinger } 1946c66ac9dbSNicholas Bellinger 19472eafd729SChristoph Hellwig static ssize_t target_dev_enable_show(struct config_item *item, char *page) 194864146db7SAndy Grover { 19492eafd729SChristoph Hellwig struct se_device *dev = to_device(item); 195064146db7SAndy Grover 195164146db7SAndy Grover return snprintf(page, PAGE_SIZE, "%d\n", !!(dev->dev_flags & DF_CONFIGURED)); 195264146db7SAndy Grover } 195364146db7SAndy Grover 19542eafd729SChristoph Hellwig static ssize_t target_dev_enable_store(struct config_item *item, 19552eafd729SChristoph Hellwig const char *page, size_t count) 1956c66ac9dbSNicholas Bellinger { 19572eafd729SChristoph Hellwig struct se_device *dev = to_device(item); 1958c66ac9dbSNicholas Bellinger char *ptr; 19590fd97ccfSChristoph Hellwig int ret; 1960c66ac9dbSNicholas Bellinger 1961c66ac9dbSNicholas Bellinger ptr = strstr(page, "1"); 19626708bb27SAndy Grover if (!ptr) { 19636708bb27SAndy Grover pr_err("For dev_enable ops, only valid value" 1964c66ac9dbSNicholas Bellinger " is \"1\"\n"); 1965c66ac9dbSNicholas Bellinger return -EINVAL; 1966c66ac9dbSNicholas Bellinger } 1967c66ac9dbSNicholas Bellinger 19680fd97ccfSChristoph Hellwig ret = target_configure_device(dev); 19690fd97ccfSChristoph Hellwig if (ret) 19700fd97ccfSChristoph Hellwig return ret; 1971c66ac9dbSNicholas Bellinger return count; 1972c66ac9dbSNicholas Bellinger } 1973c66ac9dbSNicholas Bellinger 19742eafd729SChristoph Hellwig static ssize_t target_dev_alua_lu_gp_show(struct config_item *item, char *page) 1975c66ac9dbSNicholas Bellinger { 19762eafd729SChristoph Hellwig struct se_device *dev = to_device(item); 1977c66ac9dbSNicholas Bellinger struct config_item *lu_ci; 1978c66ac9dbSNicholas Bellinger struct t10_alua_lu_gp *lu_gp; 1979c66ac9dbSNicholas Bellinger struct t10_alua_lu_gp_member *lu_gp_mem; 1980c66ac9dbSNicholas Bellinger ssize_t len = 0; 1981c66ac9dbSNicholas Bellinger 1982c66ac9dbSNicholas Bellinger lu_gp_mem = dev->dev_alua_lu_gp_mem; 1983c87fbd56SChristoph Hellwig if (!lu_gp_mem) 1984c87fbd56SChristoph Hellwig return 0; 1985c66ac9dbSNicholas Bellinger 1986c66ac9dbSNicholas Bellinger spin_lock(&lu_gp_mem->lu_gp_mem_lock); 1987c66ac9dbSNicholas Bellinger lu_gp = lu_gp_mem->lu_gp; 19886708bb27SAndy Grover if (lu_gp) { 1989c66ac9dbSNicholas Bellinger lu_ci = &lu_gp->lu_gp_group.cg_item; 1990c66ac9dbSNicholas Bellinger len += sprintf(page, "LU Group Alias: %s\nLU Group ID: %hu\n", 1991c66ac9dbSNicholas Bellinger config_item_name(lu_ci), lu_gp->lu_gp_id); 1992c66ac9dbSNicholas Bellinger } 1993c66ac9dbSNicholas Bellinger spin_unlock(&lu_gp_mem->lu_gp_mem_lock); 1994c66ac9dbSNicholas Bellinger 1995c66ac9dbSNicholas Bellinger return len; 1996c66ac9dbSNicholas Bellinger } 1997c66ac9dbSNicholas Bellinger 19982eafd729SChristoph Hellwig static ssize_t target_dev_alua_lu_gp_store(struct config_item *item, 19992eafd729SChristoph Hellwig const char *page, size_t count) 2000c66ac9dbSNicholas Bellinger { 20012eafd729SChristoph Hellwig struct se_device *dev = to_device(item); 20020fd97ccfSChristoph Hellwig struct se_hba *hba = dev->se_hba; 2003c66ac9dbSNicholas Bellinger struct t10_alua_lu_gp *lu_gp = NULL, *lu_gp_new = NULL; 2004c66ac9dbSNicholas Bellinger struct t10_alua_lu_gp_member *lu_gp_mem; 2005c66ac9dbSNicholas Bellinger unsigned char buf[LU_GROUP_NAME_BUF]; 2006c66ac9dbSNicholas Bellinger int move = 0; 2007c66ac9dbSNicholas Bellinger 2008c87fbd56SChristoph Hellwig lu_gp_mem = dev->dev_alua_lu_gp_mem; 2009c87fbd56SChristoph Hellwig if (!lu_gp_mem) 20109105bfc0SAndy Grover return count; 2011c87fbd56SChristoph Hellwig 2012c66ac9dbSNicholas Bellinger if (count > LU_GROUP_NAME_BUF) { 20136708bb27SAndy Grover pr_err("ALUA LU Group Alias too large!\n"); 2014c66ac9dbSNicholas Bellinger return -EINVAL; 2015c66ac9dbSNicholas Bellinger } 2016c66ac9dbSNicholas Bellinger memset(buf, 0, LU_GROUP_NAME_BUF); 2017c66ac9dbSNicholas Bellinger memcpy(buf, page, count); 2018c66ac9dbSNicholas Bellinger /* 2019c66ac9dbSNicholas Bellinger * Any ALUA logical unit alias besides "NULL" means we will be 2020c66ac9dbSNicholas Bellinger * making a new group association. 2021c66ac9dbSNicholas Bellinger */ 2022c66ac9dbSNicholas Bellinger if (strcmp(strstrip(buf), "NULL")) { 2023c66ac9dbSNicholas Bellinger /* 2024c66ac9dbSNicholas Bellinger * core_alua_get_lu_gp_by_name() will increment reference to 2025c66ac9dbSNicholas Bellinger * struct t10_alua_lu_gp. This reference is released with 2026c66ac9dbSNicholas Bellinger * core_alua_get_lu_gp_by_name below(). 2027c66ac9dbSNicholas Bellinger */ 2028c66ac9dbSNicholas Bellinger lu_gp_new = core_alua_get_lu_gp_by_name(strstrip(buf)); 20296708bb27SAndy Grover if (!lu_gp_new) 2030c66ac9dbSNicholas Bellinger return -ENODEV; 2031c66ac9dbSNicholas Bellinger } 2032c66ac9dbSNicholas Bellinger 2033c66ac9dbSNicholas Bellinger spin_lock(&lu_gp_mem->lu_gp_mem_lock); 2034c66ac9dbSNicholas Bellinger lu_gp = lu_gp_mem->lu_gp; 20356708bb27SAndy Grover if (lu_gp) { 2036c66ac9dbSNicholas Bellinger /* 2037c66ac9dbSNicholas Bellinger * Clearing an existing lu_gp association, and replacing 2038c66ac9dbSNicholas Bellinger * with NULL 2039c66ac9dbSNicholas Bellinger */ 20406708bb27SAndy Grover if (!lu_gp_new) { 20416708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: Releasing %s/%s" 2042c66ac9dbSNicholas Bellinger " from ALUA LU Group: core/alua/lu_gps/%s, ID:" 2043c66ac9dbSNicholas Bellinger " %hu\n", 2044c66ac9dbSNicholas Bellinger config_item_name(&hba->hba_group.cg_item), 20450fd97ccfSChristoph Hellwig config_item_name(&dev->dev_group.cg_item), 2046c66ac9dbSNicholas Bellinger config_item_name(&lu_gp->lu_gp_group.cg_item), 2047c66ac9dbSNicholas Bellinger lu_gp->lu_gp_id); 2048c66ac9dbSNicholas Bellinger 2049c66ac9dbSNicholas Bellinger __core_alua_drop_lu_gp_mem(lu_gp_mem, lu_gp); 2050c66ac9dbSNicholas Bellinger spin_unlock(&lu_gp_mem->lu_gp_mem_lock); 2051c66ac9dbSNicholas Bellinger 2052c66ac9dbSNicholas Bellinger return count; 2053c66ac9dbSNicholas Bellinger } 2054c66ac9dbSNicholas Bellinger /* 2055c66ac9dbSNicholas Bellinger * Removing existing association of lu_gp_mem with lu_gp 2056c66ac9dbSNicholas Bellinger */ 2057c66ac9dbSNicholas Bellinger __core_alua_drop_lu_gp_mem(lu_gp_mem, lu_gp); 2058c66ac9dbSNicholas Bellinger move = 1; 2059c66ac9dbSNicholas Bellinger } 2060c66ac9dbSNicholas Bellinger /* 2061c66ac9dbSNicholas Bellinger * Associate lu_gp_mem with lu_gp_new. 2062c66ac9dbSNicholas Bellinger */ 2063c66ac9dbSNicholas Bellinger __core_alua_attach_lu_gp_mem(lu_gp_mem, lu_gp_new); 2064c66ac9dbSNicholas Bellinger spin_unlock(&lu_gp_mem->lu_gp_mem_lock); 2065c66ac9dbSNicholas Bellinger 20666708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: %s %s/%s to ALUA LU Group:" 2067c66ac9dbSNicholas Bellinger " core/alua/lu_gps/%s, ID: %hu\n", 2068c66ac9dbSNicholas Bellinger (move) ? "Moving" : "Adding", 2069c66ac9dbSNicholas Bellinger config_item_name(&hba->hba_group.cg_item), 20700fd97ccfSChristoph Hellwig config_item_name(&dev->dev_group.cg_item), 2071c66ac9dbSNicholas Bellinger config_item_name(&lu_gp_new->lu_gp_group.cg_item), 2072c66ac9dbSNicholas Bellinger lu_gp_new->lu_gp_id); 2073c66ac9dbSNicholas Bellinger 2074c66ac9dbSNicholas Bellinger core_alua_put_lu_gp_from_name(lu_gp_new); 2075c66ac9dbSNicholas Bellinger return count; 2076c66ac9dbSNicholas Bellinger } 2077c66ac9dbSNicholas Bellinger 20782eafd729SChristoph Hellwig static ssize_t target_dev_lba_map_show(struct config_item *item, char *page) 2079229d4f11SHannes Reinecke { 20802eafd729SChristoph Hellwig struct se_device *dev = to_device(item); 2081229d4f11SHannes Reinecke struct t10_alua_lba_map *map; 2082229d4f11SHannes Reinecke struct t10_alua_lba_map_member *mem; 2083229d4f11SHannes Reinecke char *b = page; 2084229d4f11SHannes Reinecke int bl = 0; 2085229d4f11SHannes Reinecke char state; 2086229d4f11SHannes Reinecke 2087229d4f11SHannes Reinecke spin_lock(&dev->t10_alua.lba_map_lock); 2088229d4f11SHannes Reinecke if (!list_empty(&dev->t10_alua.lba_map_list)) 2089229d4f11SHannes Reinecke bl += sprintf(b + bl, "%u %u\n", 2090229d4f11SHannes Reinecke dev->t10_alua.lba_map_segment_size, 2091229d4f11SHannes Reinecke dev->t10_alua.lba_map_segment_multiplier); 2092229d4f11SHannes Reinecke list_for_each_entry(map, &dev->t10_alua.lba_map_list, lba_map_list) { 2093229d4f11SHannes Reinecke bl += sprintf(b + bl, "%llu %llu", 2094229d4f11SHannes Reinecke map->lba_map_first_lba, map->lba_map_last_lba); 2095229d4f11SHannes Reinecke list_for_each_entry(mem, &map->lba_map_mem_list, 2096229d4f11SHannes Reinecke lba_map_mem_list) { 2097229d4f11SHannes Reinecke switch (mem->lba_map_mem_alua_state) { 2098229d4f11SHannes Reinecke case ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED: 2099229d4f11SHannes Reinecke state = 'O'; 2100229d4f11SHannes Reinecke break; 2101229d4f11SHannes Reinecke case ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED: 2102229d4f11SHannes Reinecke state = 'A'; 2103229d4f11SHannes Reinecke break; 2104229d4f11SHannes Reinecke case ALUA_ACCESS_STATE_STANDBY: 2105229d4f11SHannes Reinecke state = 'S'; 2106229d4f11SHannes Reinecke break; 2107229d4f11SHannes Reinecke case ALUA_ACCESS_STATE_UNAVAILABLE: 2108229d4f11SHannes Reinecke state = 'U'; 2109229d4f11SHannes Reinecke break; 2110229d4f11SHannes Reinecke default: 2111229d4f11SHannes Reinecke state = '.'; 2112229d4f11SHannes Reinecke break; 2113229d4f11SHannes Reinecke } 2114229d4f11SHannes Reinecke bl += sprintf(b + bl, " %d:%c", 2115229d4f11SHannes Reinecke mem->lba_map_mem_alua_pg_id, state); 2116229d4f11SHannes Reinecke } 2117229d4f11SHannes Reinecke bl += sprintf(b + bl, "\n"); 2118229d4f11SHannes Reinecke } 2119229d4f11SHannes Reinecke spin_unlock(&dev->t10_alua.lba_map_lock); 2120229d4f11SHannes Reinecke return bl; 2121229d4f11SHannes Reinecke } 2122229d4f11SHannes Reinecke 21232eafd729SChristoph Hellwig static ssize_t target_dev_lba_map_store(struct config_item *item, 21242eafd729SChristoph Hellwig const char *page, size_t count) 2125229d4f11SHannes Reinecke { 21262eafd729SChristoph Hellwig struct se_device *dev = to_device(item); 2127229d4f11SHannes Reinecke struct t10_alua_lba_map *lba_map = NULL; 2128229d4f11SHannes Reinecke struct list_head lba_list; 2129f0a8afecSBart Van Assche char *map_entries, *orig, *ptr; 2130229d4f11SHannes Reinecke char state; 2131229d4f11SHannes Reinecke int pg_num = -1, pg; 2132229d4f11SHannes Reinecke int ret = 0, num = 0, pg_id, alua_state; 2133229d4f11SHannes Reinecke unsigned long start_lba = -1, end_lba = -1; 2134229d4f11SHannes Reinecke unsigned long segment_size = -1, segment_mult = -1; 2135229d4f11SHannes Reinecke 2136f0a8afecSBart Van Assche orig = map_entries = kstrdup(page, GFP_KERNEL); 2137229d4f11SHannes Reinecke if (!map_entries) 2138229d4f11SHannes Reinecke return -ENOMEM; 2139229d4f11SHannes Reinecke 2140229d4f11SHannes Reinecke INIT_LIST_HEAD(&lba_list); 2141229d4f11SHannes Reinecke while ((ptr = strsep(&map_entries, "\n")) != NULL) { 2142229d4f11SHannes Reinecke if (!*ptr) 2143229d4f11SHannes Reinecke continue; 2144229d4f11SHannes Reinecke 2145229d4f11SHannes Reinecke if (num == 0) { 2146229d4f11SHannes Reinecke if (sscanf(ptr, "%lu %lu\n", 2147229d4f11SHannes Reinecke &segment_size, &segment_mult) != 2) { 2148229d4f11SHannes Reinecke pr_err("Invalid line %d\n", num); 2149229d4f11SHannes Reinecke ret = -EINVAL; 2150229d4f11SHannes Reinecke break; 2151229d4f11SHannes Reinecke } 2152229d4f11SHannes Reinecke num++; 2153229d4f11SHannes Reinecke continue; 2154229d4f11SHannes Reinecke } 2155229d4f11SHannes Reinecke if (sscanf(ptr, "%lu %lu", &start_lba, &end_lba) != 2) { 2156229d4f11SHannes Reinecke pr_err("Invalid line %d\n", num); 2157229d4f11SHannes Reinecke ret = -EINVAL; 2158229d4f11SHannes Reinecke break; 2159229d4f11SHannes Reinecke } 2160229d4f11SHannes Reinecke ptr = strchr(ptr, ' '); 2161229d4f11SHannes Reinecke if (!ptr) { 2162229d4f11SHannes Reinecke pr_err("Invalid line %d, missing end lba\n", num); 2163229d4f11SHannes Reinecke ret = -EINVAL; 2164229d4f11SHannes Reinecke break; 2165229d4f11SHannes Reinecke } 2166229d4f11SHannes Reinecke ptr++; 2167229d4f11SHannes Reinecke ptr = strchr(ptr, ' '); 2168229d4f11SHannes Reinecke if (!ptr) { 2169229d4f11SHannes Reinecke pr_err("Invalid line %d, missing state definitions\n", 2170229d4f11SHannes Reinecke num); 2171229d4f11SHannes Reinecke ret = -EINVAL; 2172229d4f11SHannes Reinecke break; 2173229d4f11SHannes Reinecke } 2174229d4f11SHannes Reinecke ptr++; 2175229d4f11SHannes Reinecke lba_map = core_alua_allocate_lba_map(&lba_list, 2176229d4f11SHannes Reinecke start_lba, end_lba); 2177229d4f11SHannes Reinecke if (IS_ERR(lba_map)) { 2178229d4f11SHannes Reinecke ret = PTR_ERR(lba_map); 2179229d4f11SHannes Reinecke break; 2180229d4f11SHannes Reinecke } 2181229d4f11SHannes Reinecke pg = 0; 2182229d4f11SHannes Reinecke while (sscanf(ptr, "%d:%c", &pg_id, &state) == 2) { 2183229d4f11SHannes Reinecke switch (state) { 2184229d4f11SHannes Reinecke case 'O': 2185229d4f11SHannes Reinecke alua_state = ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED; 2186229d4f11SHannes Reinecke break; 2187229d4f11SHannes Reinecke case 'A': 2188229d4f11SHannes Reinecke alua_state = ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED; 2189229d4f11SHannes Reinecke break; 2190229d4f11SHannes Reinecke case 'S': 2191229d4f11SHannes Reinecke alua_state = ALUA_ACCESS_STATE_STANDBY; 2192229d4f11SHannes Reinecke break; 2193229d4f11SHannes Reinecke case 'U': 2194229d4f11SHannes Reinecke alua_state = ALUA_ACCESS_STATE_UNAVAILABLE; 2195229d4f11SHannes Reinecke break; 2196229d4f11SHannes Reinecke default: 2197229d4f11SHannes Reinecke pr_err("Invalid ALUA state '%c'\n", state); 2198229d4f11SHannes Reinecke ret = -EINVAL; 2199229d4f11SHannes Reinecke goto out; 2200229d4f11SHannes Reinecke } 2201229d4f11SHannes Reinecke 2202229d4f11SHannes Reinecke ret = core_alua_allocate_lba_map_mem(lba_map, 2203229d4f11SHannes Reinecke pg_id, alua_state); 2204229d4f11SHannes Reinecke if (ret) { 2205229d4f11SHannes Reinecke pr_err("Invalid target descriptor %d:%c " 2206229d4f11SHannes Reinecke "at line %d\n", 2207229d4f11SHannes Reinecke pg_id, state, num); 2208229d4f11SHannes Reinecke break; 2209229d4f11SHannes Reinecke } 2210229d4f11SHannes Reinecke pg++; 2211229d4f11SHannes Reinecke ptr = strchr(ptr, ' '); 2212229d4f11SHannes Reinecke if (ptr) 2213229d4f11SHannes Reinecke ptr++; 2214229d4f11SHannes Reinecke else 2215229d4f11SHannes Reinecke break; 2216229d4f11SHannes Reinecke } 2217229d4f11SHannes Reinecke if (pg_num == -1) 2218229d4f11SHannes Reinecke pg_num = pg; 2219229d4f11SHannes Reinecke else if (pg != pg_num) { 2220229d4f11SHannes Reinecke pr_err("Only %d from %d port groups definitions " 2221229d4f11SHannes Reinecke "at line %d\n", pg, pg_num, num); 2222229d4f11SHannes Reinecke ret = -EINVAL; 2223229d4f11SHannes Reinecke break; 2224229d4f11SHannes Reinecke } 2225229d4f11SHannes Reinecke num++; 2226229d4f11SHannes Reinecke } 2227229d4f11SHannes Reinecke out: 2228229d4f11SHannes Reinecke if (ret) { 2229229d4f11SHannes Reinecke core_alua_free_lba_map(&lba_list); 2230229d4f11SHannes Reinecke count = ret; 2231229d4f11SHannes Reinecke } else 2232229d4f11SHannes Reinecke core_alua_set_lba_map(dev, &lba_list, 2233229d4f11SHannes Reinecke segment_size, segment_mult); 2234f0a8afecSBart Van Assche kfree(orig); 2235229d4f11SHannes Reinecke return count; 2236229d4f11SHannes Reinecke } 2237229d4f11SHannes Reinecke 22382eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_dev_, info); 22392eafd729SChristoph Hellwig CONFIGFS_ATTR_WO(target_dev_, control); 22402eafd729SChristoph Hellwig CONFIGFS_ATTR(target_dev_, alias); 22412eafd729SChristoph Hellwig CONFIGFS_ATTR(target_dev_, udev_path); 22422eafd729SChristoph Hellwig CONFIGFS_ATTR(target_dev_, enable); 22432eafd729SChristoph Hellwig CONFIGFS_ATTR(target_dev_, alua_lu_gp); 22442eafd729SChristoph Hellwig CONFIGFS_ATTR(target_dev_, lba_map); 2245229d4f11SHannes Reinecke 224673112edcSNicholas Bellinger static struct configfs_attribute *target_core_dev_attrs[] = { 22472eafd729SChristoph Hellwig &target_dev_attr_info, 22482eafd729SChristoph Hellwig &target_dev_attr_control, 22492eafd729SChristoph Hellwig &target_dev_attr_alias, 22502eafd729SChristoph Hellwig &target_dev_attr_udev_path, 22512eafd729SChristoph Hellwig &target_dev_attr_enable, 22522eafd729SChristoph Hellwig &target_dev_attr_alua_lu_gp, 22532eafd729SChristoph Hellwig &target_dev_attr_lba_map, 2254c66ac9dbSNicholas Bellinger NULL, 2255c66ac9dbSNicholas Bellinger }; 2256c66ac9dbSNicholas Bellinger 2257c66ac9dbSNicholas Bellinger static void target_core_dev_release(struct config_item *item) 2258c66ac9dbSNicholas Bellinger { 22590fd97ccfSChristoph Hellwig struct config_group *dev_cg = to_config_group(item); 22600fd97ccfSChristoph Hellwig struct se_device *dev = 22610fd97ccfSChristoph Hellwig container_of(dev_cg, struct se_device, dev_group); 2262c66ac9dbSNicholas Bellinger 22630fd97ccfSChristoph Hellwig target_free_device(dev); 2264c66ac9dbSNicholas Bellinger } 2265c66ac9dbSNicholas Bellinger 2266c17cd249SNicholas Bellinger /* 2267c17cd249SNicholas Bellinger * Used in target_core_fabric_configfs.c to verify valid se_device symlink 2268c17cd249SNicholas Bellinger * within target_fabric_port_link() 2269c17cd249SNicholas Bellinger */ 2270c17cd249SNicholas Bellinger struct configfs_item_operations target_core_dev_item_ops = { 2271c66ac9dbSNicholas Bellinger .release = target_core_dev_release, 2272c66ac9dbSNicholas Bellinger }; 2273c66ac9dbSNicholas Bellinger 227473112edcSNicholas Bellinger TB_CIT_SETUP(dev, &target_core_dev_item_ops, NULL, target_core_dev_attrs); 2275c66ac9dbSNicholas Bellinger 227673112edcSNicholas Bellinger /* End functions for struct config_item_type tb_dev_cit */ 2277c66ac9dbSNicholas Bellinger 2278c66ac9dbSNicholas Bellinger /* Start functions for struct config_item_type target_core_alua_lu_gp_cit */ 2279c66ac9dbSNicholas Bellinger 22802eafd729SChristoph Hellwig static inline struct t10_alua_lu_gp *to_lu_gp(struct config_item *item) 2281c66ac9dbSNicholas Bellinger { 22822eafd729SChristoph Hellwig return container_of(to_config_group(item), struct t10_alua_lu_gp, 22832eafd729SChristoph Hellwig lu_gp_group); 22842eafd729SChristoph Hellwig } 22852eafd729SChristoph Hellwig 22862eafd729SChristoph Hellwig static ssize_t target_lu_gp_lu_gp_id_show(struct config_item *item, char *page) 22872eafd729SChristoph Hellwig { 22882eafd729SChristoph Hellwig struct t10_alua_lu_gp *lu_gp = to_lu_gp(item); 22892eafd729SChristoph Hellwig 22906708bb27SAndy Grover if (!lu_gp->lu_gp_valid_id) 2291c66ac9dbSNicholas Bellinger return 0; 2292c66ac9dbSNicholas Bellinger return sprintf(page, "%hu\n", lu_gp->lu_gp_id); 2293c66ac9dbSNicholas Bellinger } 2294c66ac9dbSNicholas Bellinger 22952eafd729SChristoph Hellwig static ssize_t target_lu_gp_lu_gp_id_store(struct config_item *item, 22962eafd729SChristoph Hellwig const char *page, size_t count) 2297c66ac9dbSNicholas Bellinger { 22982eafd729SChristoph Hellwig struct t10_alua_lu_gp *lu_gp = to_lu_gp(item); 2299c66ac9dbSNicholas Bellinger struct config_group *alua_lu_gp_cg = &lu_gp->lu_gp_group; 2300c66ac9dbSNicholas Bellinger unsigned long lu_gp_id; 2301c66ac9dbSNicholas Bellinger int ret; 2302c66ac9dbSNicholas Bellinger 230357103d7fSJingoo Han ret = kstrtoul(page, 0, &lu_gp_id); 2304c66ac9dbSNicholas Bellinger if (ret < 0) { 230557103d7fSJingoo Han pr_err("kstrtoul() returned %d for" 2306c66ac9dbSNicholas Bellinger " lu_gp_id\n", ret); 230757103d7fSJingoo Han return ret; 2308c66ac9dbSNicholas Bellinger } 2309c66ac9dbSNicholas Bellinger if (lu_gp_id > 0x0000ffff) { 23106708bb27SAndy Grover pr_err("ALUA lu_gp_id: %lu exceeds maximum:" 2311c66ac9dbSNicholas Bellinger " 0x0000ffff\n", lu_gp_id); 2312c66ac9dbSNicholas Bellinger return -EINVAL; 2313c66ac9dbSNicholas Bellinger } 2314c66ac9dbSNicholas Bellinger 2315c66ac9dbSNicholas Bellinger ret = core_alua_set_lu_gp_id(lu_gp, (u16)lu_gp_id); 2316c66ac9dbSNicholas Bellinger if (ret < 0) 2317c66ac9dbSNicholas Bellinger return -EINVAL; 2318c66ac9dbSNicholas Bellinger 23196708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: Set ALUA Logical Unit" 2320c66ac9dbSNicholas Bellinger " Group: core/alua/lu_gps/%s to ID: %hu\n", 2321c66ac9dbSNicholas Bellinger config_item_name(&alua_lu_gp_cg->cg_item), 2322c66ac9dbSNicholas Bellinger lu_gp->lu_gp_id); 2323c66ac9dbSNicholas Bellinger 2324c66ac9dbSNicholas Bellinger return count; 2325c66ac9dbSNicholas Bellinger } 2326c66ac9dbSNicholas Bellinger 23272eafd729SChristoph Hellwig static ssize_t target_lu_gp_members_show(struct config_item *item, char *page) 2328c66ac9dbSNicholas Bellinger { 23292eafd729SChristoph Hellwig struct t10_alua_lu_gp *lu_gp = to_lu_gp(item); 2330c66ac9dbSNicholas Bellinger struct se_device *dev; 2331c66ac9dbSNicholas Bellinger struct se_hba *hba; 2332c66ac9dbSNicholas Bellinger struct t10_alua_lu_gp_member *lu_gp_mem; 2333c66ac9dbSNicholas Bellinger ssize_t len = 0, cur_len; 2334c66ac9dbSNicholas Bellinger unsigned char buf[LU_GROUP_NAME_BUF]; 2335c66ac9dbSNicholas Bellinger 2336c66ac9dbSNicholas Bellinger memset(buf, 0, LU_GROUP_NAME_BUF); 2337c66ac9dbSNicholas Bellinger 2338c66ac9dbSNicholas Bellinger spin_lock(&lu_gp->lu_gp_lock); 2339c66ac9dbSNicholas Bellinger list_for_each_entry(lu_gp_mem, &lu_gp->lu_gp_mem_list, lu_gp_mem_list) { 2340c66ac9dbSNicholas Bellinger dev = lu_gp_mem->lu_gp_mem_dev; 23410fd97ccfSChristoph Hellwig hba = dev->se_hba; 2342c66ac9dbSNicholas Bellinger 2343c66ac9dbSNicholas Bellinger cur_len = snprintf(buf, LU_GROUP_NAME_BUF, "%s/%s\n", 2344c66ac9dbSNicholas Bellinger config_item_name(&hba->hba_group.cg_item), 23450fd97ccfSChristoph Hellwig config_item_name(&dev->dev_group.cg_item)); 2346c66ac9dbSNicholas Bellinger cur_len++; /* Extra byte for NULL terminator */ 2347c66ac9dbSNicholas Bellinger 2348c66ac9dbSNicholas Bellinger if ((cur_len + len) > PAGE_SIZE) { 23496708bb27SAndy Grover pr_warn("Ran out of lu_gp_show_attr" 2350c66ac9dbSNicholas Bellinger "_members buffer\n"); 2351c66ac9dbSNicholas Bellinger break; 2352c66ac9dbSNicholas Bellinger } 2353c66ac9dbSNicholas Bellinger memcpy(page+len, buf, cur_len); 2354c66ac9dbSNicholas Bellinger len += cur_len; 2355c66ac9dbSNicholas Bellinger } 2356c66ac9dbSNicholas Bellinger spin_unlock(&lu_gp->lu_gp_lock); 2357c66ac9dbSNicholas Bellinger 2358c66ac9dbSNicholas Bellinger return len; 2359c66ac9dbSNicholas Bellinger } 2360c66ac9dbSNicholas Bellinger 23612eafd729SChristoph Hellwig CONFIGFS_ATTR(target_lu_gp_, lu_gp_id); 23622eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_lu_gp_, members); 2363c66ac9dbSNicholas Bellinger 2364c66ac9dbSNicholas Bellinger static struct configfs_attribute *target_core_alua_lu_gp_attrs[] = { 23652eafd729SChristoph Hellwig &target_lu_gp_attr_lu_gp_id, 23662eafd729SChristoph Hellwig &target_lu_gp_attr_members, 2367c66ac9dbSNicholas Bellinger NULL, 2368c66ac9dbSNicholas Bellinger }; 2369c66ac9dbSNicholas Bellinger 23701f6fe7cbSNicholas Bellinger static void target_core_alua_lu_gp_release(struct config_item *item) 23711f6fe7cbSNicholas Bellinger { 23721f6fe7cbSNicholas Bellinger struct t10_alua_lu_gp *lu_gp = container_of(to_config_group(item), 23731f6fe7cbSNicholas Bellinger struct t10_alua_lu_gp, lu_gp_group); 23741f6fe7cbSNicholas Bellinger 23751f6fe7cbSNicholas Bellinger core_alua_free_lu_gp(lu_gp); 23761f6fe7cbSNicholas Bellinger } 23771f6fe7cbSNicholas Bellinger 2378c66ac9dbSNicholas Bellinger static struct configfs_item_operations target_core_alua_lu_gp_ops = { 23791f6fe7cbSNicholas Bellinger .release = target_core_alua_lu_gp_release, 2380c66ac9dbSNicholas Bellinger }; 2381c66ac9dbSNicholas Bellinger 2382ece550b5SBhumika Goyal static const struct config_item_type target_core_alua_lu_gp_cit = { 2383c66ac9dbSNicholas Bellinger .ct_item_ops = &target_core_alua_lu_gp_ops, 2384c66ac9dbSNicholas Bellinger .ct_attrs = target_core_alua_lu_gp_attrs, 2385c66ac9dbSNicholas Bellinger .ct_owner = THIS_MODULE, 2386c66ac9dbSNicholas Bellinger }; 2387c66ac9dbSNicholas Bellinger 2388c66ac9dbSNicholas Bellinger /* End functions for struct config_item_type target_core_alua_lu_gp_cit */ 2389c66ac9dbSNicholas Bellinger 2390c66ac9dbSNicholas Bellinger /* Start functions for struct config_item_type target_core_alua_lu_gps_cit */ 2391c66ac9dbSNicholas Bellinger 2392c66ac9dbSNicholas Bellinger static struct config_group *target_core_alua_create_lu_gp( 2393c66ac9dbSNicholas Bellinger struct config_group *group, 2394c66ac9dbSNicholas Bellinger const char *name) 2395c66ac9dbSNicholas Bellinger { 2396c66ac9dbSNicholas Bellinger struct t10_alua_lu_gp *lu_gp; 2397c66ac9dbSNicholas Bellinger struct config_group *alua_lu_gp_cg = NULL; 2398c66ac9dbSNicholas Bellinger struct config_item *alua_lu_gp_ci = NULL; 2399c66ac9dbSNicholas Bellinger 2400c66ac9dbSNicholas Bellinger lu_gp = core_alua_allocate_lu_gp(name, 0); 2401c66ac9dbSNicholas Bellinger if (IS_ERR(lu_gp)) 2402c66ac9dbSNicholas Bellinger return NULL; 2403c66ac9dbSNicholas Bellinger 2404c66ac9dbSNicholas Bellinger alua_lu_gp_cg = &lu_gp->lu_gp_group; 2405c66ac9dbSNicholas Bellinger alua_lu_gp_ci = &alua_lu_gp_cg->cg_item; 2406c66ac9dbSNicholas Bellinger 2407c66ac9dbSNicholas Bellinger config_group_init_type_name(alua_lu_gp_cg, name, 2408c66ac9dbSNicholas Bellinger &target_core_alua_lu_gp_cit); 2409c66ac9dbSNicholas Bellinger 24106708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: Allocated ALUA Logical Unit" 2411c66ac9dbSNicholas Bellinger " Group: core/alua/lu_gps/%s\n", 2412c66ac9dbSNicholas Bellinger config_item_name(alua_lu_gp_ci)); 2413c66ac9dbSNicholas Bellinger 2414c66ac9dbSNicholas Bellinger return alua_lu_gp_cg; 2415c66ac9dbSNicholas Bellinger 2416c66ac9dbSNicholas Bellinger } 2417c66ac9dbSNicholas Bellinger 2418c66ac9dbSNicholas Bellinger static void target_core_alua_drop_lu_gp( 2419c66ac9dbSNicholas Bellinger struct config_group *group, 2420c66ac9dbSNicholas Bellinger struct config_item *item) 2421c66ac9dbSNicholas Bellinger { 2422c66ac9dbSNicholas Bellinger struct t10_alua_lu_gp *lu_gp = container_of(to_config_group(item), 2423c66ac9dbSNicholas Bellinger struct t10_alua_lu_gp, lu_gp_group); 2424c66ac9dbSNicholas Bellinger 24256708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: Releasing ALUA Logical Unit" 2426c66ac9dbSNicholas Bellinger " Group: core/alua/lu_gps/%s, ID: %hu\n", 2427c66ac9dbSNicholas Bellinger config_item_name(item), lu_gp->lu_gp_id); 24281f6fe7cbSNicholas Bellinger /* 24291f6fe7cbSNicholas Bellinger * core_alua_free_lu_gp() is called from target_core_alua_lu_gp_ops->release() 24301f6fe7cbSNicholas Bellinger * -> target_core_alua_lu_gp_release() 24311f6fe7cbSNicholas Bellinger */ 2432c66ac9dbSNicholas Bellinger config_item_put(item); 2433c66ac9dbSNicholas Bellinger } 2434c66ac9dbSNicholas Bellinger 2435c66ac9dbSNicholas Bellinger static struct configfs_group_operations target_core_alua_lu_gps_group_ops = { 2436c66ac9dbSNicholas Bellinger .make_group = &target_core_alua_create_lu_gp, 2437c66ac9dbSNicholas Bellinger .drop_item = &target_core_alua_drop_lu_gp, 2438c66ac9dbSNicholas Bellinger }; 2439c66ac9dbSNicholas Bellinger 2440ece550b5SBhumika Goyal static const struct config_item_type target_core_alua_lu_gps_cit = { 2441c66ac9dbSNicholas Bellinger .ct_item_ops = NULL, 2442c66ac9dbSNicholas Bellinger .ct_group_ops = &target_core_alua_lu_gps_group_ops, 2443c66ac9dbSNicholas Bellinger .ct_owner = THIS_MODULE, 2444c66ac9dbSNicholas Bellinger }; 2445c66ac9dbSNicholas Bellinger 2446c66ac9dbSNicholas Bellinger /* End functions for struct config_item_type target_core_alua_lu_gps_cit */ 2447c66ac9dbSNicholas Bellinger 2448c66ac9dbSNicholas Bellinger /* Start functions for struct config_item_type target_core_alua_tg_pt_gp_cit */ 2449c66ac9dbSNicholas Bellinger 24502eafd729SChristoph Hellwig static inline struct t10_alua_tg_pt_gp *to_tg_pt_gp(struct config_item *item) 24512eafd729SChristoph Hellwig { 24522eafd729SChristoph Hellwig return container_of(to_config_group(item), struct t10_alua_tg_pt_gp, 24532eafd729SChristoph Hellwig tg_pt_gp_group); 24542eafd729SChristoph Hellwig } 2455c66ac9dbSNicholas Bellinger 24562eafd729SChristoph Hellwig static ssize_t target_tg_pt_gp_alua_access_state_show(struct config_item *item, 2457c66ac9dbSNicholas Bellinger char *page) 2458c66ac9dbSNicholas Bellinger { 2459c66ac9dbSNicholas Bellinger return sprintf(page, "%d\n", 2460d19c4643SMike Christie to_tg_pt_gp(item)->tg_pt_gp_alua_access_state); 2461c66ac9dbSNicholas Bellinger } 2462c66ac9dbSNicholas Bellinger 24632eafd729SChristoph Hellwig static ssize_t target_tg_pt_gp_alua_access_state_store(struct config_item *item, 24642eafd729SChristoph Hellwig const char *page, size_t count) 2465c66ac9dbSNicholas Bellinger { 24662eafd729SChristoph Hellwig struct t10_alua_tg_pt_gp *tg_pt_gp = to_tg_pt_gp(item); 24670fd97ccfSChristoph Hellwig struct se_device *dev = tg_pt_gp->tg_pt_gp_dev; 2468c66ac9dbSNicholas Bellinger unsigned long tmp; 2469c66ac9dbSNicholas Bellinger int new_state, ret; 2470c66ac9dbSNicholas Bellinger 24716708bb27SAndy Grover if (!tg_pt_gp->tg_pt_gp_valid_id) { 2472125d0119SHannes Reinecke pr_err("Unable to do implicit ALUA on non valid" 2473c66ac9dbSNicholas Bellinger " tg_pt_gp ID: %hu\n", tg_pt_gp->tg_pt_gp_valid_id); 2474c66ac9dbSNicholas Bellinger return -EINVAL; 2475c66ac9dbSNicholas Bellinger } 2476f1453773SNicholas Bellinger if (!(dev->dev_flags & DF_CONFIGURED)) { 2477f1453773SNicholas Bellinger pr_err("Unable to set alua_access_state while device is" 2478f1453773SNicholas Bellinger " not configured\n"); 2479f1453773SNicholas Bellinger return -ENODEV; 2480f1453773SNicholas Bellinger } 2481c66ac9dbSNicholas Bellinger 248257103d7fSJingoo Han ret = kstrtoul(page, 0, &tmp); 2483c66ac9dbSNicholas Bellinger if (ret < 0) { 24846708bb27SAndy Grover pr_err("Unable to extract new ALUA access state from" 2485c66ac9dbSNicholas Bellinger " %s\n", page); 248657103d7fSJingoo Han return ret; 2487c66ac9dbSNicholas Bellinger } 2488c66ac9dbSNicholas Bellinger new_state = (int)tmp; 2489c66ac9dbSNicholas Bellinger 2490125d0119SHannes Reinecke if (!(tg_pt_gp->tg_pt_gp_alua_access_type & TPGS_IMPLICIT_ALUA)) { 2491125d0119SHannes Reinecke pr_err("Unable to process implicit configfs ALUA" 2492125d0119SHannes Reinecke " transition while TPGS_IMPLICIT_ALUA is disabled\n"); 2493c66ac9dbSNicholas Bellinger return -EINVAL; 2494c66ac9dbSNicholas Bellinger } 2495c66094bfSHannes Reinecke if (tg_pt_gp->tg_pt_gp_alua_access_type & TPGS_EXPLICIT_ALUA && 2496c66094bfSHannes Reinecke new_state == ALUA_ACCESS_STATE_LBA_DEPENDENT) { 2497c66094bfSHannes Reinecke /* LBA DEPENDENT is only allowed with implicit ALUA */ 2498c66094bfSHannes Reinecke pr_err("Unable to process implicit configfs ALUA transition" 2499c66094bfSHannes Reinecke " while explicit ALUA management is enabled\n"); 2500c66094bfSHannes Reinecke return -EINVAL; 2501c66094bfSHannes Reinecke } 2502c66ac9dbSNicholas Bellinger 25030fd97ccfSChristoph Hellwig ret = core_alua_do_port_transition(tg_pt_gp, dev, 2504c66ac9dbSNicholas Bellinger NULL, NULL, new_state, 0); 2505c66ac9dbSNicholas Bellinger return (!ret) ? count : -EINVAL; 2506c66ac9dbSNicholas Bellinger } 2507c66ac9dbSNicholas Bellinger 25082eafd729SChristoph Hellwig static ssize_t target_tg_pt_gp_alua_access_status_show(struct config_item *item, 2509c66ac9dbSNicholas Bellinger char *page) 2510c66ac9dbSNicholas Bellinger { 25112eafd729SChristoph Hellwig struct t10_alua_tg_pt_gp *tg_pt_gp = to_tg_pt_gp(item); 2512c66ac9dbSNicholas Bellinger return sprintf(page, "%s\n", 2513c66ac9dbSNicholas Bellinger core_alua_dump_status(tg_pt_gp->tg_pt_gp_alua_access_status)); 2514c66ac9dbSNicholas Bellinger } 2515c66ac9dbSNicholas Bellinger 25162eafd729SChristoph Hellwig static ssize_t target_tg_pt_gp_alua_access_status_store( 25172eafd729SChristoph Hellwig struct config_item *item, const char *page, size_t count) 2518c66ac9dbSNicholas Bellinger { 25192eafd729SChristoph Hellwig struct t10_alua_tg_pt_gp *tg_pt_gp = to_tg_pt_gp(item); 2520c66ac9dbSNicholas Bellinger unsigned long tmp; 2521c66ac9dbSNicholas Bellinger int new_status, ret; 2522c66ac9dbSNicholas Bellinger 25236708bb27SAndy Grover if (!tg_pt_gp->tg_pt_gp_valid_id) { 25246708bb27SAndy Grover pr_err("Unable to do set ALUA access status on non" 2525c66ac9dbSNicholas Bellinger " valid tg_pt_gp ID: %hu\n", 2526c66ac9dbSNicholas Bellinger tg_pt_gp->tg_pt_gp_valid_id); 2527c66ac9dbSNicholas Bellinger return -EINVAL; 2528c66ac9dbSNicholas Bellinger } 2529c66ac9dbSNicholas Bellinger 253057103d7fSJingoo Han ret = kstrtoul(page, 0, &tmp); 2531c66ac9dbSNicholas Bellinger if (ret < 0) { 25326708bb27SAndy Grover pr_err("Unable to extract new ALUA access status" 2533c66ac9dbSNicholas Bellinger " from %s\n", page); 253457103d7fSJingoo Han return ret; 2535c66ac9dbSNicholas Bellinger } 2536c66ac9dbSNicholas Bellinger new_status = (int)tmp; 2537c66ac9dbSNicholas Bellinger 2538c66ac9dbSNicholas Bellinger if ((new_status != ALUA_STATUS_NONE) && 2539125d0119SHannes Reinecke (new_status != ALUA_STATUS_ALTERED_BY_EXPLICIT_STPG) && 2540125d0119SHannes Reinecke (new_status != ALUA_STATUS_ALTERED_BY_IMPLICIT_ALUA)) { 25416708bb27SAndy Grover pr_err("Illegal ALUA access status: 0x%02x\n", 2542c66ac9dbSNicholas Bellinger new_status); 2543c66ac9dbSNicholas Bellinger return -EINVAL; 2544c66ac9dbSNicholas Bellinger } 2545c66ac9dbSNicholas Bellinger 2546c66ac9dbSNicholas Bellinger tg_pt_gp->tg_pt_gp_alua_access_status = new_status; 2547c66ac9dbSNicholas Bellinger return count; 2548c66ac9dbSNicholas Bellinger } 2549c66ac9dbSNicholas Bellinger 25502eafd729SChristoph Hellwig static ssize_t target_tg_pt_gp_alua_access_type_show(struct config_item *item, 2551c66ac9dbSNicholas Bellinger char *page) 2552c66ac9dbSNicholas Bellinger { 25532eafd729SChristoph Hellwig return core_alua_show_access_type(to_tg_pt_gp(item), page); 2554c66ac9dbSNicholas Bellinger } 2555c66ac9dbSNicholas Bellinger 25562eafd729SChristoph Hellwig static ssize_t target_tg_pt_gp_alua_access_type_store(struct config_item *item, 25572eafd729SChristoph Hellwig const char *page, size_t count) 2558c66ac9dbSNicholas Bellinger { 25592eafd729SChristoph Hellwig return core_alua_store_access_type(to_tg_pt_gp(item), page, count); 2560c66ac9dbSNicholas Bellinger } 2561c66ac9dbSNicholas Bellinger 25622eafd729SChristoph Hellwig #define ALUA_SUPPORTED_STATE_ATTR(_name, _bit) \ 25632eafd729SChristoph Hellwig static ssize_t target_tg_pt_gp_alua_support_##_name##_show( \ 25642eafd729SChristoph Hellwig struct config_item *item, char *p) \ 2565b0a382c5SHannes Reinecke { \ 25662eafd729SChristoph Hellwig struct t10_alua_tg_pt_gp *t = to_tg_pt_gp(item); \ 25672eafd729SChristoph Hellwig return sprintf(p, "%d\n", \ 25682eafd729SChristoph Hellwig !!(t->tg_pt_gp_alua_supported_states & _bit)); \ 25692eafd729SChristoph Hellwig } \ 25702eafd729SChristoph Hellwig \ 25712eafd729SChristoph Hellwig static ssize_t target_tg_pt_gp_alua_support_##_name##_store( \ 25722eafd729SChristoph Hellwig struct config_item *item, const char *p, size_t c) \ 2573b0a382c5SHannes Reinecke { \ 25742eafd729SChristoph Hellwig struct t10_alua_tg_pt_gp *t = to_tg_pt_gp(item); \ 2575b0a382c5SHannes Reinecke unsigned long tmp; \ 2576b0a382c5SHannes Reinecke int ret; \ 2577b0a382c5SHannes Reinecke \ 2578b0a382c5SHannes Reinecke if (!t->tg_pt_gp_valid_id) { \ 2579c0dcafd8SHannes Reinecke pr_err("Unable to do set " #_name " ALUA state on non" \ 2580b0a382c5SHannes Reinecke " valid tg_pt_gp ID: %hu\n", \ 2581b0a382c5SHannes Reinecke t->tg_pt_gp_valid_id); \ 2582b0a382c5SHannes Reinecke return -EINVAL; \ 2583b0a382c5SHannes Reinecke } \ 2584b0a382c5SHannes Reinecke \ 2585b0a382c5SHannes Reinecke ret = kstrtoul(p, 0, &tmp); \ 2586b0a382c5SHannes Reinecke if (ret < 0) { \ 2587b0a382c5SHannes Reinecke pr_err("Invalid value '%s', must be '0' or '1'\n", p); \ 2588b0a382c5SHannes Reinecke return -EINVAL; \ 2589b0a382c5SHannes Reinecke } \ 2590b0a382c5SHannes Reinecke if (tmp > 1) { \ 2591b0a382c5SHannes Reinecke pr_err("Invalid value '%ld', must be '0' or '1'\n", tmp); \ 2592b0a382c5SHannes Reinecke return -EINVAL; \ 2593b0a382c5SHannes Reinecke } \ 25941f0b030cSSebastian Herbszt if (tmp) \ 25952eafd729SChristoph Hellwig t->tg_pt_gp_alua_supported_states |= _bit; \ 2596b0a382c5SHannes Reinecke else \ 25972eafd729SChristoph Hellwig t->tg_pt_gp_alua_supported_states &= ~_bit; \ 2598b0a382c5SHannes Reinecke \ 2599b0a382c5SHannes Reinecke return c; \ 26006be526c4SHannes Reinecke } 26016be526c4SHannes Reinecke 26022eafd729SChristoph Hellwig ALUA_SUPPORTED_STATE_ATTR(transitioning, ALUA_T_SUP); 26032eafd729SChristoph Hellwig ALUA_SUPPORTED_STATE_ATTR(offline, ALUA_O_SUP); 26042eafd729SChristoph Hellwig ALUA_SUPPORTED_STATE_ATTR(lba_dependent, ALUA_LBD_SUP); 26052eafd729SChristoph Hellwig ALUA_SUPPORTED_STATE_ATTR(unavailable, ALUA_U_SUP); 26062eafd729SChristoph Hellwig ALUA_SUPPORTED_STATE_ATTR(standby, ALUA_S_SUP); 26072eafd729SChristoph Hellwig ALUA_SUPPORTED_STATE_ATTR(active_optimized, ALUA_AO_SUP); 26082eafd729SChristoph Hellwig ALUA_SUPPORTED_STATE_ATTR(active_nonoptimized, ALUA_AN_SUP); 26096be526c4SHannes Reinecke 26102eafd729SChristoph Hellwig static ssize_t target_tg_pt_gp_alua_write_metadata_show( 26112eafd729SChristoph Hellwig struct config_item *item, char *page) 2612c66ac9dbSNicholas Bellinger { 26132eafd729SChristoph Hellwig return sprintf(page, "%d\n", 26142eafd729SChristoph Hellwig to_tg_pt_gp(item)->tg_pt_gp_write_metadata); 2615c66ac9dbSNicholas Bellinger } 2616c66ac9dbSNicholas Bellinger 26172eafd729SChristoph Hellwig static ssize_t target_tg_pt_gp_alua_write_metadata_store( 26182eafd729SChristoph Hellwig struct config_item *item, const char *page, size_t count) 2619c66ac9dbSNicholas Bellinger { 26202eafd729SChristoph Hellwig struct t10_alua_tg_pt_gp *tg_pt_gp = to_tg_pt_gp(item); 2621c66ac9dbSNicholas Bellinger unsigned long tmp; 2622c66ac9dbSNicholas Bellinger int ret; 2623c66ac9dbSNicholas Bellinger 262457103d7fSJingoo Han ret = kstrtoul(page, 0, &tmp); 2625c66ac9dbSNicholas Bellinger if (ret < 0) { 26266708bb27SAndy Grover pr_err("Unable to extract alua_write_metadata\n"); 262757103d7fSJingoo Han return ret; 2628c66ac9dbSNicholas Bellinger } 2629c66ac9dbSNicholas Bellinger 2630c66ac9dbSNicholas Bellinger if ((tmp != 0) && (tmp != 1)) { 26316708bb27SAndy Grover pr_err("Illegal value for alua_write_metadata:" 2632c66ac9dbSNicholas Bellinger " %lu\n", tmp); 2633c66ac9dbSNicholas Bellinger return -EINVAL; 2634c66ac9dbSNicholas Bellinger } 2635c66ac9dbSNicholas Bellinger tg_pt_gp->tg_pt_gp_write_metadata = (int)tmp; 2636c66ac9dbSNicholas Bellinger 2637c66ac9dbSNicholas Bellinger return count; 2638c66ac9dbSNicholas Bellinger } 2639c66ac9dbSNicholas Bellinger 26402eafd729SChristoph Hellwig static ssize_t target_tg_pt_gp_nonop_delay_msecs_show(struct config_item *item, 2641c66ac9dbSNicholas Bellinger char *page) 2642c66ac9dbSNicholas Bellinger { 26432eafd729SChristoph Hellwig return core_alua_show_nonop_delay_msecs(to_tg_pt_gp(item), page); 2644c66ac9dbSNicholas Bellinger } 2645c66ac9dbSNicholas Bellinger 26462eafd729SChristoph Hellwig static ssize_t target_tg_pt_gp_nonop_delay_msecs_store(struct config_item *item, 26472eafd729SChristoph Hellwig const char *page, size_t count) 2648c66ac9dbSNicholas Bellinger { 26492eafd729SChristoph Hellwig return core_alua_store_nonop_delay_msecs(to_tg_pt_gp(item), page, 26502eafd729SChristoph Hellwig count); 2651c66ac9dbSNicholas Bellinger } 2652c66ac9dbSNicholas Bellinger 26532eafd729SChristoph Hellwig static ssize_t target_tg_pt_gp_trans_delay_msecs_show(struct config_item *item, 2654c66ac9dbSNicholas Bellinger char *page) 2655c66ac9dbSNicholas Bellinger { 26562eafd729SChristoph Hellwig return core_alua_show_trans_delay_msecs(to_tg_pt_gp(item), page); 2657c66ac9dbSNicholas Bellinger } 2658c66ac9dbSNicholas Bellinger 26592eafd729SChristoph Hellwig static ssize_t target_tg_pt_gp_trans_delay_msecs_store(struct config_item *item, 26602eafd729SChristoph Hellwig const char *page, size_t count) 2661c66ac9dbSNicholas Bellinger { 26622eafd729SChristoph Hellwig return core_alua_store_trans_delay_msecs(to_tg_pt_gp(item), page, 26632eafd729SChristoph Hellwig count); 2664c66ac9dbSNicholas Bellinger } 2665c66ac9dbSNicholas Bellinger 26662eafd729SChristoph Hellwig static ssize_t target_tg_pt_gp_implicit_trans_secs_show( 26672eafd729SChristoph Hellwig struct config_item *item, char *page) 26682eafd729SChristoph Hellwig { 26692eafd729SChristoph Hellwig return core_alua_show_implicit_trans_secs(to_tg_pt_gp(item), page); 26702eafd729SChristoph Hellwig } 2671c66ac9dbSNicholas Bellinger 26722eafd729SChristoph Hellwig static ssize_t target_tg_pt_gp_implicit_trans_secs_store( 26732eafd729SChristoph Hellwig struct config_item *item, const char *page, size_t count) 26742eafd729SChristoph Hellwig { 26752eafd729SChristoph Hellwig return core_alua_store_implicit_trans_secs(to_tg_pt_gp(item), page, 26762eafd729SChristoph Hellwig count); 26772eafd729SChristoph Hellwig } 26782eafd729SChristoph Hellwig 26792eafd729SChristoph Hellwig static ssize_t target_tg_pt_gp_preferred_show(struct config_item *item, 26805b9a4d72SNicholas Bellinger char *page) 26815b9a4d72SNicholas Bellinger { 26822eafd729SChristoph Hellwig return core_alua_show_preferred_bit(to_tg_pt_gp(item), page); 26835b9a4d72SNicholas Bellinger } 26845b9a4d72SNicholas Bellinger 26852eafd729SChristoph Hellwig static ssize_t target_tg_pt_gp_preferred_store(struct config_item *item, 26862eafd729SChristoph Hellwig const char *page, size_t count) 26875b9a4d72SNicholas Bellinger { 26882eafd729SChristoph Hellwig return core_alua_store_preferred_bit(to_tg_pt_gp(item), page, count); 26895b9a4d72SNicholas Bellinger } 26905b9a4d72SNicholas Bellinger 26912eafd729SChristoph Hellwig static ssize_t target_tg_pt_gp_tg_pt_gp_id_show(struct config_item *item, 2692c66ac9dbSNicholas Bellinger char *page) 2693c66ac9dbSNicholas Bellinger { 26942eafd729SChristoph Hellwig struct t10_alua_tg_pt_gp *tg_pt_gp = to_tg_pt_gp(item); 2695c66ac9dbSNicholas Bellinger 26966708bb27SAndy Grover if (!tg_pt_gp->tg_pt_gp_valid_id) 2697c66ac9dbSNicholas Bellinger return 0; 2698c66ac9dbSNicholas Bellinger return sprintf(page, "%hu\n", tg_pt_gp->tg_pt_gp_id); 2699c66ac9dbSNicholas Bellinger } 2700c66ac9dbSNicholas Bellinger 27012eafd729SChristoph Hellwig static ssize_t target_tg_pt_gp_tg_pt_gp_id_store(struct config_item *item, 27022eafd729SChristoph Hellwig const char *page, size_t count) 2703c66ac9dbSNicholas Bellinger { 27042eafd729SChristoph Hellwig struct t10_alua_tg_pt_gp *tg_pt_gp = to_tg_pt_gp(item); 2705c66ac9dbSNicholas Bellinger struct config_group *alua_tg_pt_gp_cg = &tg_pt_gp->tg_pt_gp_group; 2706c66ac9dbSNicholas Bellinger unsigned long tg_pt_gp_id; 2707c66ac9dbSNicholas Bellinger int ret; 2708c66ac9dbSNicholas Bellinger 270957103d7fSJingoo Han ret = kstrtoul(page, 0, &tg_pt_gp_id); 2710c66ac9dbSNicholas Bellinger if (ret < 0) { 27113d035237SHannes Reinecke pr_err("ALUA tg_pt_gp_id: invalid value '%s' for tg_pt_gp_id\n", 27123d035237SHannes Reinecke page); 271357103d7fSJingoo Han return ret; 2714c66ac9dbSNicholas Bellinger } 2715c66ac9dbSNicholas Bellinger if (tg_pt_gp_id > 0x0000ffff) { 27163d035237SHannes Reinecke pr_err("ALUA tg_pt_gp_id: %lu exceeds maximum: 0x0000ffff\n", 27173d035237SHannes Reinecke tg_pt_gp_id); 2718c66ac9dbSNicholas Bellinger return -EINVAL; 2719c66ac9dbSNicholas Bellinger } 2720c66ac9dbSNicholas Bellinger 2721c66ac9dbSNicholas Bellinger ret = core_alua_set_tg_pt_gp_id(tg_pt_gp, (u16)tg_pt_gp_id); 2722c66ac9dbSNicholas Bellinger if (ret < 0) 2723c66ac9dbSNicholas Bellinger return -EINVAL; 2724c66ac9dbSNicholas Bellinger 27256708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: Set ALUA Target Port Group: " 2726c66ac9dbSNicholas Bellinger "core/alua/tg_pt_gps/%s to ID: %hu\n", 2727c66ac9dbSNicholas Bellinger config_item_name(&alua_tg_pt_gp_cg->cg_item), 2728c66ac9dbSNicholas Bellinger tg_pt_gp->tg_pt_gp_id); 2729c66ac9dbSNicholas Bellinger 2730c66ac9dbSNicholas Bellinger return count; 2731c66ac9dbSNicholas Bellinger } 2732c66ac9dbSNicholas Bellinger 27332eafd729SChristoph Hellwig static ssize_t target_tg_pt_gp_members_show(struct config_item *item, 2734c66ac9dbSNicholas Bellinger char *page) 2735c66ac9dbSNicholas Bellinger { 27362eafd729SChristoph Hellwig struct t10_alua_tg_pt_gp *tg_pt_gp = to_tg_pt_gp(item); 2737c66ac9dbSNicholas Bellinger struct se_lun *lun; 2738c66ac9dbSNicholas Bellinger ssize_t len = 0, cur_len; 2739c66ac9dbSNicholas Bellinger unsigned char buf[TG_PT_GROUP_NAME_BUF]; 2740c66ac9dbSNicholas Bellinger 2741c66ac9dbSNicholas Bellinger memset(buf, 0, TG_PT_GROUP_NAME_BUF); 2742c66ac9dbSNicholas Bellinger 2743c66ac9dbSNicholas Bellinger spin_lock(&tg_pt_gp->tg_pt_gp_lock); 2744adf653f9SChristoph Hellwig list_for_each_entry(lun, &tg_pt_gp->tg_pt_gp_lun_list, 2745adf653f9SChristoph Hellwig lun_tg_pt_gp_link) { 2746adf653f9SChristoph Hellwig struct se_portal_group *tpg = lun->lun_tpg; 2747c66ac9dbSNicholas Bellinger 2748c66ac9dbSNicholas Bellinger cur_len = snprintf(buf, TG_PT_GROUP_NAME_BUF, "%s/%s/tpgt_%hu" 2749e3d6f909SAndy Grover "/%s\n", tpg->se_tpg_tfo->get_fabric_name(), 2750e3d6f909SAndy Grover tpg->se_tpg_tfo->tpg_get_wwn(tpg), 2751e3d6f909SAndy Grover tpg->se_tpg_tfo->tpg_get_tag(tpg), 2752c66ac9dbSNicholas Bellinger config_item_name(&lun->lun_group.cg_item)); 2753c66ac9dbSNicholas Bellinger cur_len++; /* Extra byte for NULL terminator */ 2754c66ac9dbSNicholas Bellinger 2755c66ac9dbSNicholas Bellinger if ((cur_len + len) > PAGE_SIZE) { 27566708bb27SAndy Grover pr_warn("Ran out of lu_gp_show_attr" 2757c66ac9dbSNicholas Bellinger "_members buffer\n"); 2758c66ac9dbSNicholas Bellinger break; 2759c66ac9dbSNicholas Bellinger } 2760c66ac9dbSNicholas Bellinger memcpy(page+len, buf, cur_len); 2761c66ac9dbSNicholas Bellinger len += cur_len; 2762c66ac9dbSNicholas Bellinger } 2763c66ac9dbSNicholas Bellinger spin_unlock(&tg_pt_gp->tg_pt_gp_lock); 2764c66ac9dbSNicholas Bellinger 2765c66ac9dbSNicholas Bellinger return len; 2766c66ac9dbSNicholas Bellinger } 2767c66ac9dbSNicholas Bellinger 27682eafd729SChristoph Hellwig CONFIGFS_ATTR(target_tg_pt_gp_, alua_access_state); 27692eafd729SChristoph Hellwig CONFIGFS_ATTR(target_tg_pt_gp_, alua_access_status); 27702eafd729SChristoph Hellwig CONFIGFS_ATTR(target_tg_pt_gp_, alua_access_type); 27712eafd729SChristoph Hellwig CONFIGFS_ATTR(target_tg_pt_gp_, alua_support_transitioning); 27722eafd729SChristoph Hellwig CONFIGFS_ATTR(target_tg_pt_gp_, alua_support_offline); 27732eafd729SChristoph Hellwig CONFIGFS_ATTR(target_tg_pt_gp_, alua_support_lba_dependent); 27742eafd729SChristoph Hellwig CONFIGFS_ATTR(target_tg_pt_gp_, alua_support_unavailable); 27752eafd729SChristoph Hellwig CONFIGFS_ATTR(target_tg_pt_gp_, alua_support_standby); 27762eafd729SChristoph Hellwig CONFIGFS_ATTR(target_tg_pt_gp_, alua_support_active_optimized); 27772eafd729SChristoph Hellwig CONFIGFS_ATTR(target_tg_pt_gp_, alua_support_active_nonoptimized); 27782eafd729SChristoph Hellwig CONFIGFS_ATTR(target_tg_pt_gp_, alua_write_metadata); 27792eafd729SChristoph Hellwig CONFIGFS_ATTR(target_tg_pt_gp_, nonop_delay_msecs); 27802eafd729SChristoph Hellwig CONFIGFS_ATTR(target_tg_pt_gp_, trans_delay_msecs); 27812eafd729SChristoph Hellwig CONFIGFS_ATTR(target_tg_pt_gp_, implicit_trans_secs); 27822eafd729SChristoph Hellwig CONFIGFS_ATTR(target_tg_pt_gp_, preferred); 27832eafd729SChristoph Hellwig CONFIGFS_ATTR(target_tg_pt_gp_, tg_pt_gp_id); 27842eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_tg_pt_gp_, members); 2785c66ac9dbSNicholas Bellinger 2786c66ac9dbSNicholas Bellinger static struct configfs_attribute *target_core_alua_tg_pt_gp_attrs[] = { 27872eafd729SChristoph Hellwig &target_tg_pt_gp_attr_alua_access_state, 27882eafd729SChristoph Hellwig &target_tg_pt_gp_attr_alua_access_status, 27892eafd729SChristoph Hellwig &target_tg_pt_gp_attr_alua_access_type, 27902eafd729SChristoph Hellwig &target_tg_pt_gp_attr_alua_support_transitioning, 27912eafd729SChristoph Hellwig &target_tg_pt_gp_attr_alua_support_offline, 27922eafd729SChristoph Hellwig &target_tg_pt_gp_attr_alua_support_lba_dependent, 27932eafd729SChristoph Hellwig &target_tg_pt_gp_attr_alua_support_unavailable, 27942eafd729SChristoph Hellwig &target_tg_pt_gp_attr_alua_support_standby, 27952eafd729SChristoph Hellwig &target_tg_pt_gp_attr_alua_support_active_nonoptimized, 27962eafd729SChristoph Hellwig &target_tg_pt_gp_attr_alua_support_active_optimized, 27972eafd729SChristoph Hellwig &target_tg_pt_gp_attr_alua_write_metadata, 27982eafd729SChristoph Hellwig &target_tg_pt_gp_attr_nonop_delay_msecs, 27992eafd729SChristoph Hellwig &target_tg_pt_gp_attr_trans_delay_msecs, 28002eafd729SChristoph Hellwig &target_tg_pt_gp_attr_implicit_trans_secs, 28012eafd729SChristoph Hellwig &target_tg_pt_gp_attr_preferred, 28022eafd729SChristoph Hellwig &target_tg_pt_gp_attr_tg_pt_gp_id, 28032eafd729SChristoph Hellwig &target_tg_pt_gp_attr_members, 2804c66ac9dbSNicholas Bellinger NULL, 2805c66ac9dbSNicholas Bellinger }; 2806c66ac9dbSNicholas Bellinger 28071f6fe7cbSNicholas Bellinger static void target_core_alua_tg_pt_gp_release(struct config_item *item) 28081f6fe7cbSNicholas Bellinger { 28091f6fe7cbSNicholas Bellinger struct t10_alua_tg_pt_gp *tg_pt_gp = container_of(to_config_group(item), 28101f6fe7cbSNicholas Bellinger struct t10_alua_tg_pt_gp, tg_pt_gp_group); 28111f6fe7cbSNicholas Bellinger 28121f6fe7cbSNicholas Bellinger core_alua_free_tg_pt_gp(tg_pt_gp); 28131f6fe7cbSNicholas Bellinger } 28141f6fe7cbSNicholas Bellinger 2815c66ac9dbSNicholas Bellinger static struct configfs_item_operations target_core_alua_tg_pt_gp_ops = { 28161f6fe7cbSNicholas Bellinger .release = target_core_alua_tg_pt_gp_release, 2817c66ac9dbSNicholas Bellinger }; 2818c66ac9dbSNicholas Bellinger 2819ece550b5SBhumika Goyal static const struct config_item_type target_core_alua_tg_pt_gp_cit = { 2820c66ac9dbSNicholas Bellinger .ct_item_ops = &target_core_alua_tg_pt_gp_ops, 2821c66ac9dbSNicholas Bellinger .ct_attrs = target_core_alua_tg_pt_gp_attrs, 2822c66ac9dbSNicholas Bellinger .ct_owner = THIS_MODULE, 2823c66ac9dbSNicholas Bellinger }; 2824c66ac9dbSNicholas Bellinger 2825c66ac9dbSNicholas Bellinger /* End functions for struct config_item_type target_core_alua_tg_pt_gp_cit */ 2826c66ac9dbSNicholas Bellinger 282772aca57bSNicholas Bellinger /* Start functions for struct config_item_type tb_alua_tg_pt_gps_cit */ 2828c66ac9dbSNicholas Bellinger 2829c66ac9dbSNicholas Bellinger static struct config_group *target_core_alua_create_tg_pt_gp( 2830c66ac9dbSNicholas Bellinger struct config_group *group, 2831c66ac9dbSNicholas Bellinger const char *name) 2832c66ac9dbSNicholas Bellinger { 2833c66ac9dbSNicholas Bellinger struct t10_alua *alua = container_of(group, struct t10_alua, 2834c66ac9dbSNicholas Bellinger alua_tg_pt_gps_group); 2835c66ac9dbSNicholas Bellinger struct t10_alua_tg_pt_gp *tg_pt_gp; 2836c66ac9dbSNicholas Bellinger struct config_group *alua_tg_pt_gp_cg = NULL; 2837c66ac9dbSNicholas Bellinger struct config_item *alua_tg_pt_gp_ci = NULL; 2838c66ac9dbSNicholas Bellinger 28390fd97ccfSChristoph Hellwig tg_pt_gp = core_alua_allocate_tg_pt_gp(alua->t10_dev, name, 0); 28406708bb27SAndy Grover if (!tg_pt_gp) 2841c66ac9dbSNicholas Bellinger return NULL; 2842c66ac9dbSNicholas Bellinger 2843c66ac9dbSNicholas Bellinger alua_tg_pt_gp_cg = &tg_pt_gp->tg_pt_gp_group; 2844c66ac9dbSNicholas Bellinger alua_tg_pt_gp_ci = &alua_tg_pt_gp_cg->cg_item; 2845c66ac9dbSNicholas Bellinger 2846c66ac9dbSNicholas Bellinger config_group_init_type_name(alua_tg_pt_gp_cg, name, 2847c66ac9dbSNicholas Bellinger &target_core_alua_tg_pt_gp_cit); 2848c66ac9dbSNicholas Bellinger 28496708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: Allocated ALUA Target Port" 2850c66ac9dbSNicholas Bellinger " Group: alua/tg_pt_gps/%s\n", 2851c66ac9dbSNicholas Bellinger config_item_name(alua_tg_pt_gp_ci)); 2852c66ac9dbSNicholas Bellinger 2853c66ac9dbSNicholas Bellinger return alua_tg_pt_gp_cg; 2854c66ac9dbSNicholas Bellinger } 2855c66ac9dbSNicholas Bellinger 2856c66ac9dbSNicholas Bellinger static void target_core_alua_drop_tg_pt_gp( 2857c66ac9dbSNicholas Bellinger struct config_group *group, 2858c66ac9dbSNicholas Bellinger struct config_item *item) 2859c66ac9dbSNicholas Bellinger { 2860c66ac9dbSNicholas Bellinger struct t10_alua_tg_pt_gp *tg_pt_gp = container_of(to_config_group(item), 2861c66ac9dbSNicholas Bellinger struct t10_alua_tg_pt_gp, tg_pt_gp_group); 2862c66ac9dbSNicholas Bellinger 28636708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: Releasing ALUA Target Port" 2864c66ac9dbSNicholas Bellinger " Group: alua/tg_pt_gps/%s, ID: %hu\n", 2865c66ac9dbSNicholas Bellinger config_item_name(item), tg_pt_gp->tg_pt_gp_id); 28661f6fe7cbSNicholas Bellinger /* 28671f6fe7cbSNicholas Bellinger * core_alua_free_tg_pt_gp() is called from target_core_alua_tg_pt_gp_ops->release() 28681f6fe7cbSNicholas Bellinger * -> target_core_alua_tg_pt_gp_release(). 28691f6fe7cbSNicholas Bellinger */ 2870c66ac9dbSNicholas Bellinger config_item_put(item); 2871c66ac9dbSNicholas Bellinger } 2872c66ac9dbSNicholas Bellinger 2873c66ac9dbSNicholas Bellinger static struct configfs_group_operations target_core_alua_tg_pt_gps_group_ops = { 2874c66ac9dbSNicholas Bellinger .make_group = &target_core_alua_create_tg_pt_gp, 2875c66ac9dbSNicholas Bellinger .drop_item = &target_core_alua_drop_tg_pt_gp, 2876c66ac9dbSNicholas Bellinger }; 2877c66ac9dbSNicholas Bellinger 287872aca57bSNicholas Bellinger TB_CIT_SETUP(dev_alua_tg_pt_gps, NULL, &target_core_alua_tg_pt_gps_group_ops, NULL); 2879c66ac9dbSNicholas Bellinger 288072aca57bSNicholas Bellinger /* End functions for struct config_item_type tb_alua_tg_pt_gps_cit */ 2881c66ac9dbSNicholas Bellinger 2882c66ac9dbSNicholas Bellinger /* Start functions for struct config_item_type target_core_alua_cit */ 2883c66ac9dbSNicholas Bellinger 2884c66ac9dbSNicholas Bellinger /* 2885c66ac9dbSNicholas Bellinger * target_core_alua_cit is a ConfigFS group that lives under 2886c66ac9dbSNicholas Bellinger * /sys/kernel/config/target/core/alua. There are default groups 2887c66ac9dbSNicholas Bellinger * core/alua/lu_gps and core/alua/tg_pt_gps that are attached to 2888c66ac9dbSNicholas Bellinger * target_core_alua_cit in target_core_init_configfs() below. 2889c66ac9dbSNicholas Bellinger */ 2890ece550b5SBhumika Goyal static const struct config_item_type target_core_alua_cit = { 2891c66ac9dbSNicholas Bellinger .ct_item_ops = NULL, 2892c66ac9dbSNicholas Bellinger .ct_attrs = NULL, 2893c66ac9dbSNicholas Bellinger .ct_owner = THIS_MODULE, 2894c66ac9dbSNicholas Bellinger }; 2895c66ac9dbSNicholas Bellinger 2896c66ac9dbSNicholas Bellinger /* End functions for struct config_item_type target_core_alua_cit */ 2897c66ac9dbSNicholas Bellinger 2898d23ab570SNicholas Bellinger /* Start functions for struct config_item_type tb_dev_stat_cit */ 289912d23384SNicholas Bellinger 290012d23384SNicholas Bellinger static struct config_group *target_core_stat_mkdir( 290112d23384SNicholas Bellinger struct config_group *group, 290212d23384SNicholas Bellinger const char *name) 290312d23384SNicholas Bellinger { 290412d23384SNicholas Bellinger return ERR_PTR(-ENOSYS); 290512d23384SNicholas Bellinger } 290612d23384SNicholas Bellinger 290712d23384SNicholas Bellinger static void target_core_stat_rmdir( 290812d23384SNicholas Bellinger struct config_group *group, 290912d23384SNicholas Bellinger struct config_item *item) 291012d23384SNicholas Bellinger { 291112d23384SNicholas Bellinger return; 291212d23384SNicholas Bellinger } 291312d23384SNicholas Bellinger 291412d23384SNicholas Bellinger static struct configfs_group_operations target_core_stat_group_ops = { 291512d23384SNicholas Bellinger .make_group = &target_core_stat_mkdir, 291612d23384SNicholas Bellinger .drop_item = &target_core_stat_rmdir, 291712d23384SNicholas Bellinger }; 291812d23384SNicholas Bellinger 2919d23ab570SNicholas Bellinger TB_CIT_SETUP(dev_stat, NULL, &target_core_stat_group_ops, NULL); 292012d23384SNicholas Bellinger 2921d23ab570SNicholas Bellinger /* End functions for struct config_item_type tb_dev_stat_cit */ 292212d23384SNicholas Bellinger 2923c66ac9dbSNicholas Bellinger /* Start functions for struct config_item_type target_core_hba_cit */ 2924c66ac9dbSNicholas Bellinger 2925c66ac9dbSNicholas Bellinger static struct config_group *target_core_make_subdev( 2926c66ac9dbSNicholas Bellinger struct config_group *group, 2927c66ac9dbSNicholas Bellinger const char *name) 2928c66ac9dbSNicholas Bellinger { 2929c66ac9dbSNicholas Bellinger struct t10_alua_tg_pt_gp *tg_pt_gp; 2930c66ac9dbSNicholas Bellinger struct config_item *hba_ci = &group->cg_item; 2931c66ac9dbSNicholas Bellinger struct se_hba *hba = item_to_hba(hba_ci); 29320a06d430SChristoph Hellwig struct target_backend *tb = hba->backend; 29330fd97ccfSChristoph Hellwig struct se_device *dev; 293412d23384SNicholas Bellinger int errno = -ENOMEM, ret; 2935c66ac9dbSNicholas Bellinger 293612d23384SNicholas Bellinger ret = mutex_lock_interruptible(&hba->hba_access_mutex); 293712d23384SNicholas Bellinger if (ret) 293812d23384SNicholas Bellinger return ERR_PTR(ret); 2939c66ac9dbSNicholas Bellinger 29400fd97ccfSChristoph Hellwig dev = target_alloc_device(hba, name); 29410fd97ccfSChristoph Hellwig if (!dev) 29420fd97ccfSChristoph Hellwig goto out_unlock; 2943c66ac9dbSNicholas Bellinger 29441ae1602dSChristoph Hellwig config_group_init_type_name(&dev->dev_group, name, &tb->tb_dev_cit); 2945c66ac9dbSNicholas Bellinger 29468dc31ff9SMike Christie config_group_init_type_name(&dev->dev_action_group, "action", 29478dc31ff9SMike Christie &tb->tb_dev_action_cit); 29488dc31ff9SMike Christie configfs_add_default_group(&dev->dev_action_group, &dev->dev_group); 29498dc31ff9SMike Christie 29500fd97ccfSChristoph Hellwig config_group_init_type_name(&dev->dev_attrib.da_group, "attrib", 29510a06d430SChristoph Hellwig &tb->tb_dev_attrib_cit); 29521ae1602dSChristoph Hellwig configfs_add_default_group(&dev->dev_attrib.da_group, &dev->dev_group); 29531ae1602dSChristoph Hellwig 29540fd97ccfSChristoph Hellwig config_group_init_type_name(&dev->dev_pr_group, "pr", 29550a06d430SChristoph Hellwig &tb->tb_dev_pr_cit); 29561ae1602dSChristoph Hellwig configfs_add_default_group(&dev->dev_pr_group, &dev->dev_group); 29571ae1602dSChristoph Hellwig 29580fd97ccfSChristoph Hellwig config_group_init_type_name(&dev->t10_wwn.t10_wwn_group, "wwn", 29590a06d430SChristoph Hellwig &tb->tb_dev_wwn_cit); 29601ae1602dSChristoph Hellwig configfs_add_default_group(&dev->t10_wwn.t10_wwn_group, 29611ae1602dSChristoph Hellwig &dev->dev_group); 29621ae1602dSChristoph Hellwig 29630fd97ccfSChristoph Hellwig config_group_init_type_name(&dev->t10_alua.alua_tg_pt_gps_group, 29640a06d430SChristoph Hellwig "alua", &tb->tb_dev_alua_tg_pt_gps_cit); 29651ae1602dSChristoph Hellwig configfs_add_default_group(&dev->t10_alua.alua_tg_pt_gps_group, 29661ae1602dSChristoph Hellwig &dev->dev_group); 29671ae1602dSChristoph Hellwig 29680fd97ccfSChristoph Hellwig config_group_init_type_name(&dev->dev_stat_grps.stat_group, 29690a06d430SChristoph Hellwig "statistics", &tb->tb_dev_stat_cit); 29701ae1602dSChristoph Hellwig configfs_add_default_group(&dev->dev_stat_grps.stat_group, 29711ae1602dSChristoph Hellwig &dev->dev_group); 297212d23384SNicholas Bellinger 2973c66ac9dbSNicholas Bellinger /* 297412d23384SNicholas Bellinger * Add core/$HBA/$DEV/alua/default_tg_pt_gp 2975c66ac9dbSNicholas Bellinger */ 29760fd97ccfSChristoph Hellwig tg_pt_gp = core_alua_allocate_tg_pt_gp(dev, "default_tg_pt_gp", 1); 29776708bb27SAndy Grover if (!tg_pt_gp) 29781ae1602dSChristoph Hellwig goto out_free_device; 29790fd97ccfSChristoph Hellwig dev->t10_alua.default_tg_pt_gp = tg_pt_gp; 2980c66ac9dbSNicholas Bellinger 2981c66ac9dbSNicholas Bellinger config_group_init_type_name(&tg_pt_gp->tg_pt_gp_group, 2982c66ac9dbSNicholas Bellinger "default_tg_pt_gp", &target_core_alua_tg_pt_gp_cit); 29831ae1602dSChristoph Hellwig configfs_add_default_group(&tg_pt_gp->tg_pt_gp_group, 29841ae1602dSChristoph Hellwig &dev->t10_alua.alua_tg_pt_gps_group); 29851ae1602dSChristoph Hellwig 298612d23384SNicholas Bellinger /* 298712d23384SNicholas Bellinger * Add core/$HBA/$DEV/statistics/ default groups 298812d23384SNicholas Bellinger */ 29890fd97ccfSChristoph Hellwig target_stat_setup_dev_default_groups(dev); 2990c66ac9dbSNicholas Bellinger 2991c66ac9dbSNicholas Bellinger mutex_unlock(&hba->hba_access_mutex); 29921ae1602dSChristoph Hellwig return &dev->dev_group; 29930fd97ccfSChristoph Hellwig 29940fd97ccfSChristoph Hellwig out_free_device: 29950fd97ccfSChristoph Hellwig target_free_device(dev); 29960fd97ccfSChristoph Hellwig out_unlock: 2997c66ac9dbSNicholas Bellinger mutex_unlock(&hba->hba_access_mutex); 299812d23384SNicholas Bellinger return ERR_PTR(errno); 2999c66ac9dbSNicholas Bellinger } 3000c66ac9dbSNicholas Bellinger 3001c66ac9dbSNicholas Bellinger static void target_core_drop_subdev( 3002c66ac9dbSNicholas Bellinger struct config_group *group, 3003c66ac9dbSNicholas Bellinger struct config_item *item) 3004c66ac9dbSNicholas Bellinger { 30050fd97ccfSChristoph Hellwig struct config_group *dev_cg = to_config_group(item); 30060fd97ccfSChristoph Hellwig struct se_device *dev = 30070fd97ccfSChristoph Hellwig container_of(dev_cg, struct se_device, dev_group); 3008c66ac9dbSNicholas Bellinger struct se_hba *hba; 3009c66ac9dbSNicholas Bellinger 30100fd97ccfSChristoph Hellwig hba = item_to_hba(&dev->se_hba->hba_group.cg_item); 3011c66ac9dbSNicholas Bellinger 30121f6fe7cbSNicholas Bellinger mutex_lock(&hba->hba_access_mutex); 3013c66ac9dbSNicholas Bellinger 30141ae1602dSChristoph Hellwig configfs_remove_default_groups(&dev->dev_stat_grps.stat_group); 30151ae1602dSChristoph Hellwig configfs_remove_default_groups(&dev->t10_alua.alua_tg_pt_gps_group); 301612d23384SNicholas Bellinger 30171f6fe7cbSNicholas Bellinger /* 30181f6fe7cbSNicholas Bellinger * core_alua_free_tg_pt_gp() is called from ->default_tg_pt_gp 30191f6fe7cbSNicholas Bellinger * directly from target_core_alua_tg_pt_gp_release(). 30201f6fe7cbSNicholas Bellinger */ 30210fd97ccfSChristoph Hellwig dev->t10_alua.default_tg_pt_gp = NULL; 3022c66ac9dbSNicholas Bellinger 30231ae1602dSChristoph Hellwig configfs_remove_default_groups(dev_cg); 30241ae1602dSChristoph Hellwig 30251f6fe7cbSNicholas Bellinger /* 30260fd97ccfSChristoph Hellwig * se_dev is released from target_core_dev_item_ops->release() 30271f6fe7cbSNicholas Bellinger */ 3028c66ac9dbSNicholas Bellinger config_item_put(item); 3029c66ac9dbSNicholas Bellinger mutex_unlock(&hba->hba_access_mutex); 3030c66ac9dbSNicholas Bellinger } 3031c66ac9dbSNicholas Bellinger 3032c66ac9dbSNicholas Bellinger static struct configfs_group_operations target_core_hba_group_ops = { 3033c66ac9dbSNicholas Bellinger .make_group = target_core_make_subdev, 3034c66ac9dbSNicholas Bellinger .drop_item = target_core_drop_subdev, 3035c66ac9dbSNicholas Bellinger }; 3036c66ac9dbSNicholas Bellinger 3037c66ac9dbSNicholas Bellinger 30382eafd729SChristoph Hellwig static inline struct se_hba *to_hba(struct config_item *item) 3039c66ac9dbSNicholas Bellinger { 30402eafd729SChristoph Hellwig return container_of(to_config_group(item), struct se_hba, hba_group); 30412eafd729SChristoph Hellwig } 30422eafd729SChristoph Hellwig 30432eafd729SChristoph Hellwig static ssize_t target_hba_info_show(struct config_item *item, char *page) 30442eafd729SChristoph Hellwig { 30452eafd729SChristoph Hellwig struct se_hba *hba = to_hba(item); 30462eafd729SChristoph Hellwig 3047c66ac9dbSNicholas Bellinger return sprintf(page, "HBA Index: %d plugin: %s version: %s\n", 30480a06d430SChristoph Hellwig hba->hba_id, hba->backend->ops->name, 3049ce8dd25dSChristoph Hellwig TARGET_CORE_VERSION); 3050c66ac9dbSNicholas Bellinger } 3051c66ac9dbSNicholas Bellinger 30522eafd729SChristoph Hellwig static ssize_t target_hba_mode_show(struct config_item *item, char *page) 3053c66ac9dbSNicholas Bellinger { 30542eafd729SChristoph Hellwig struct se_hba *hba = to_hba(item); 3055c66ac9dbSNicholas Bellinger int hba_mode = 0; 3056c66ac9dbSNicholas Bellinger 3057c66ac9dbSNicholas Bellinger if (hba->hba_flags & HBA_FLAGS_PSCSI_MODE) 3058c66ac9dbSNicholas Bellinger hba_mode = 1; 3059c66ac9dbSNicholas Bellinger 3060c66ac9dbSNicholas Bellinger return sprintf(page, "%d\n", hba_mode); 3061c66ac9dbSNicholas Bellinger } 3062c66ac9dbSNicholas Bellinger 30632eafd729SChristoph Hellwig static ssize_t target_hba_mode_store(struct config_item *item, 3064c66ac9dbSNicholas Bellinger const char *page, size_t count) 3065c66ac9dbSNicholas Bellinger { 30662eafd729SChristoph Hellwig struct se_hba *hba = to_hba(item); 3067c66ac9dbSNicholas Bellinger unsigned long mode_flag; 3068c66ac9dbSNicholas Bellinger int ret; 3069c66ac9dbSNicholas Bellinger 30700a06d430SChristoph Hellwig if (hba->backend->ops->pmode_enable_hba == NULL) 3071c66ac9dbSNicholas Bellinger return -EINVAL; 3072c66ac9dbSNicholas Bellinger 307357103d7fSJingoo Han ret = kstrtoul(page, 0, &mode_flag); 3074c66ac9dbSNicholas Bellinger if (ret < 0) { 30756708bb27SAndy Grover pr_err("Unable to extract hba mode flag: %d\n", ret); 307657103d7fSJingoo Han return ret; 3077c66ac9dbSNicholas Bellinger } 3078c66ac9dbSNicholas Bellinger 30790fd97ccfSChristoph Hellwig if (hba->dev_count) { 30806708bb27SAndy Grover pr_err("Unable to set hba_mode with active devices\n"); 3081c66ac9dbSNicholas Bellinger return -EINVAL; 3082c66ac9dbSNicholas Bellinger } 3083c66ac9dbSNicholas Bellinger 30840a06d430SChristoph Hellwig ret = hba->backend->ops->pmode_enable_hba(hba, mode_flag); 3085c66ac9dbSNicholas Bellinger if (ret < 0) 3086c66ac9dbSNicholas Bellinger return -EINVAL; 3087c66ac9dbSNicholas Bellinger if (ret > 0) 3088c66ac9dbSNicholas Bellinger hba->hba_flags |= HBA_FLAGS_PSCSI_MODE; 3089c66ac9dbSNicholas Bellinger else if (ret == 0) 3090c66ac9dbSNicholas Bellinger hba->hba_flags &= ~HBA_FLAGS_PSCSI_MODE; 3091c66ac9dbSNicholas Bellinger 3092c66ac9dbSNicholas Bellinger return count; 3093c66ac9dbSNicholas Bellinger } 3094c66ac9dbSNicholas Bellinger 30952eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(target_, hba_info); 30962eafd729SChristoph Hellwig CONFIGFS_ATTR(target_, hba_mode); 3097c66ac9dbSNicholas Bellinger 30981f6fe7cbSNicholas Bellinger static void target_core_hba_release(struct config_item *item) 30991f6fe7cbSNicholas Bellinger { 31001f6fe7cbSNicholas Bellinger struct se_hba *hba = container_of(to_config_group(item), 31011f6fe7cbSNicholas Bellinger struct se_hba, hba_group); 31021f6fe7cbSNicholas Bellinger core_delete_hba(hba); 31031f6fe7cbSNicholas Bellinger } 31041f6fe7cbSNicholas Bellinger 3105c66ac9dbSNicholas Bellinger static struct configfs_attribute *target_core_hba_attrs[] = { 31062eafd729SChristoph Hellwig &target_attr_hba_info, 31072eafd729SChristoph Hellwig &target_attr_hba_mode, 3108c66ac9dbSNicholas Bellinger NULL, 3109c66ac9dbSNicholas Bellinger }; 3110c66ac9dbSNicholas Bellinger 3111c66ac9dbSNicholas Bellinger static struct configfs_item_operations target_core_hba_item_ops = { 31121f6fe7cbSNicholas Bellinger .release = target_core_hba_release, 3113c66ac9dbSNicholas Bellinger }; 3114c66ac9dbSNicholas Bellinger 3115ece550b5SBhumika Goyal static const struct config_item_type target_core_hba_cit = { 3116c66ac9dbSNicholas Bellinger .ct_item_ops = &target_core_hba_item_ops, 3117c66ac9dbSNicholas Bellinger .ct_group_ops = &target_core_hba_group_ops, 3118c66ac9dbSNicholas Bellinger .ct_attrs = target_core_hba_attrs, 3119c66ac9dbSNicholas Bellinger .ct_owner = THIS_MODULE, 3120c66ac9dbSNicholas Bellinger }; 3121c66ac9dbSNicholas Bellinger 3122c66ac9dbSNicholas Bellinger static struct config_group *target_core_call_addhbatotarget( 3123c66ac9dbSNicholas Bellinger struct config_group *group, 3124c66ac9dbSNicholas Bellinger const char *name) 3125c66ac9dbSNicholas Bellinger { 3126c66ac9dbSNicholas Bellinger char *se_plugin_str, *str, *str2; 3127c66ac9dbSNicholas Bellinger struct se_hba *hba; 3128c66ac9dbSNicholas Bellinger char buf[TARGET_CORE_NAME_MAX_LEN]; 3129c66ac9dbSNicholas Bellinger unsigned long plugin_dep_id = 0; 3130c66ac9dbSNicholas Bellinger int ret; 3131c66ac9dbSNicholas Bellinger 3132c66ac9dbSNicholas Bellinger memset(buf, 0, TARGET_CORE_NAME_MAX_LEN); 313360d645a4SDan Carpenter if (strlen(name) >= TARGET_CORE_NAME_MAX_LEN) { 31346708bb27SAndy Grover pr_err("Passed *name strlen(): %d exceeds" 3135c66ac9dbSNicholas Bellinger " TARGET_CORE_NAME_MAX_LEN: %d\n", (int)strlen(name), 3136c66ac9dbSNicholas Bellinger TARGET_CORE_NAME_MAX_LEN); 3137c66ac9dbSNicholas Bellinger return ERR_PTR(-ENAMETOOLONG); 3138c66ac9dbSNicholas Bellinger } 3139c66ac9dbSNicholas Bellinger snprintf(buf, TARGET_CORE_NAME_MAX_LEN, "%s", name); 3140c66ac9dbSNicholas Bellinger 3141c66ac9dbSNicholas Bellinger str = strstr(buf, "_"); 31426708bb27SAndy Grover if (!str) { 31436708bb27SAndy Grover pr_err("Unable to locate \"_\" for $SUBSYSTEM_PLUGIN_$HOST_ID\n"); 3144c66ac9dbSNicholas Bellinger return ERR_PTR(-EINVAL); 3145c66ac9dbSNicholas Bellinger } 3146c66ac9dbSNicholas Bellinger se_plugin_str = buf; 3147c66ac9dbSNicholas Bellinger /* 3148c66ac9dbSNicholas Bellinger * Special case for subsystem plugins that have "_" in their names. 3149c66ac9dbSNicholas Bellinger * Namely rd_direct and rd_mcp.. 3150c66ac9dbSNicholas Bellinger */ 3151c66ac9dbSNicholas Bellinger str2 = strstr(str+1, "_"); 31526708bb27SAndy Grover if (str2) { 3153c66ac9dbSNicholas Bellinger *str2 = '\0'; /* Terminate for *se_plugin_str */ 3154c66ac9dbSNicholas Bellinger str2++; /* Skip to start of plugin dependent ID */ 3155c66ac9dbSNicholas Bellinger str = str2; 3156c66ac9dbSNicholas Bellinger } else { 3157c66ac9dbSNicholas Bellinger *str = '\0'; /* Terminate for *se_plugin_str */ 3158c66ac9dbSNicholas Bellinger str++; /* Skip to start of plugin dependent ID */ 3159c66ac9dbSNicholas Bellinger } 3160c66ac9dbSNicholas Bellinger 316157103d7fSJingoo Han ret = kstrtoul(str, 0, &plugin_dep_id); 3162c66ac9dbSNicholas Bellinger if (ret < 0) { 316357103d7fSJingoo Han pr_err("kstrtoul() returned %d for" 3164c66ac9dbSNicholas Bellinger " plugin_dep_id\n", ret); 316557103d7fSJingoo Han return ERR_PTR(ret); 3166c66ac9dbSNicholas Bellinger } 3167c66ac9dbSNicholas Bellinger /* 3168c66ac9dbSNicholas Bellinger * Load up TCM subsystem plugins if they have not already been loaded. 3169c66ac9dbSNicholas Bellinger */ 3170dbc5623eSNicholas Bellinger transport_subsystem_check_init(); 3171c66ac9dbSNicholas Bellinger 3172c66ac9dbSNicholas Bellinger hba = core_alloc_hba(se_plugin_str, plugin_dep_id, 0); 3173c66ac9dbSNicholas Bellinger if (IS_ERR(hba)) 3174c66ac9dbSNicholas Bellinger return ERR_CAST(hba); 3175c66ac9dbSNicholas Bellinger 3176c66ac9dbSNicholas Bellinger config_group_init_type_name(&hba->hba_group, name, 3177c66ac9dbSNicholas Bellinger &target_core_hba_cit); 3178c66ac9dbSNicholas Bellinger 3179c66ac9dbSNicholas Bellinger return &hba->hba_group; 3180c66ac9dbSNicholas Bellinger } 3181c66ac9dbSNicholas Bellinger 3182c66ac9dbSNicholas Bellinger static void target_core_call_delhbafromtarget( 3183c66ac9dbSNicholas Bellinger struct config_group *group, 3184c66ac9dbSNicholas Bellinger struct config_item *item) 3185c66ac9dbSNicholas Bellinger { 31861f6fe7cbSNicholas Bellinger /* 31871f6fe7cbSNicholas Bellinger * core_delete_hba() is called from target_core_hba_item_ops->release() 31881f6fe7cbSNicholas Bellinger * -> target_core_hba_release() 31891f6fe7cbSNicholas Bellinger */ 3190c66ac9dbSNicholas Bellinger config_item_put(item); 3191c66ac9dbSNicholas Bellinger } 3192c66ac9dbSNicholas Bellinger 3193c66ac9dbSNicholas Bellinger static struct configfs_group_operations target_core_group_ops = { 3194c66ac9dbSNicholas Bellinger .make_group = target_core_call_addhbatotarget, 3195c66ac9dbSNicholas Bellinger .drop_item = target_core_call_delhbafromtarget, 3196c66ac9dbSNicholas Bellinger }; 3197c66ac9dbSNicholas Bellinger 3198ece550b5SBhumika Goyal static const struct config_item_type target_core_cit = { 3199c66ac9dbSNicholas Bellinger .ct_item_ops = NULL, 3200c66ac9dbSNicholas Bellinger .ct_group_ops = &target_core_group_ops, 3201c66ac9dbSNicholas Bellinger .ct_attrs = NULL, 3202c66ac9dbSNicholas Bellinger .ct_owner = THIS_MODULE, 3203c66ac9dbSNicholas Bellinger }; 3204c66ac9dbSNicholas Bellinger 3205c66ac9dbSNicholas Bellinger /* Stop functions for struct config_item_type target_core_hba_cit */ 3206c66ac9dbSNicholas Bellinger 32070a06d430SChristoph Hellwig void target_setup_backend_cits(struct target_backend *tb) 320873112edcSNicholas Bellinger { 32090a06d430SChristoph Hellwig target_core_setup_dev_cit(tb); 32108dc31ff9SMike Christie target_core_setup_dev_action_cit(tb); 32110a06d430SChristoph Hellwig target_core_setup_dev_attrib_cit(tb); 32120a06d430SChristoph Hellwig target_core_setup_dev_pr_cit(tb); 32130a06d430SChristoph Hellwig target_core_setup_dev_wwn_cit(tb); 32140a06d430SChristoph Hellwig target_core_setup_dev_alua_tg_pt_gps_cit(tb); 32150a06d430SChristoph Hellwig target_core_setup_dev_stat_cit(tb); 321673112edcSNicholas Bellinger } 321773112edcSNicholas Bellinger 321878a6295cSLee Duncan static void target_init_dbroot(void) 321978a6295cSLee Duncan { 322078a6295cSLee Duncan struct file *fp; 322178a6295cSLee Duncan 322278a6295cSLee Duncan snprintf(db_root_stage, DB_ROOT_LEN, DB_ROOT_PREFERRED); 322378a6295cSLee Duncan fp = filp_open(db_root_stage, O_RDONLY, 0); 322478a6295cSLee Duncan if (IS_ERR(fp)) { 322578a6295cSLee Duncan pr_err("db_root: cannot open: %s\n", db_root_stage); 322678a6295cSLee Duncan return; 322778a6295cSLee Duncan } 322878a6295cSLee Duncan if (!S_ISDIR(file_inode(fp)->i_mode)) { 322978a6295cSLee Duncan filp_close(fp, NULL); 323078a6295cSLee Duncan pr_err("db_root: not a valid directory: %s\n", db_root_stage); 323178a6295cSLee Duncan return; 323278a6295cSLee Duncan } 323378a6295cSLee Duncan filp_close(fp, NULL); 323478a6295cSLee Duncan 323578a6295cSLee Duncan strncpy(db_root, db_root_stage, DB_ROOT_LEN); 323678a6295cSLee Duncan pr_debug("Target_Core_ConfigFS: db_root set to %s\n", db_root); 323778a6295cSLee Duncan } 323878a6295cSLee Duncan 323954550fabSAxel Lin static int __init target_core_init_configfs(void) 3240c66ac9dbSNicholas Bellinger { 3241d588cf8fSChristoph Hellwig struct configfs_subsystem *subsys = &target_core_fabrics; 3242c66ac9dbSNicholas Bellinger struct t10_alua_lu_gp *lu_gp; 3243c66ac9dbSNicholas Bellinger int ret; 3244c66ac9dbSNicholas Bellinger 32456708bb27SAndy Grover pr_debug("TARGET_CORE[0]: Loading Generic Kernel Storage" 3246c66ac9dbSNicholas Bellinger " Engine: %s on %s/%s on "UTS_RELEASE"\n", 3247c66ac9dbSNicholas Bellinger TARGET_CORE_VERSION, utsname()->sysname, utsname()->machine); 3248c66ac9dbSNicholas Bellinger 3249c66ac9dbSNicholas Bellinger config_group_init(&subsys->su_group); 3250c66ac9dbSNicholas Bellinger mutex_init(&subsys->su_mutex); 3251c66ac9dbSNicholas Bellinger 3252e3d6f909SAndy Grover ret = init_se_kmem_caches(); 3253c66ac9dbSNicholas Bellinger if (ret < 0) 3254e3d6f909SAndy Grover return ret; 3255c66ac9dbSNicholas Bellinger /* 3256c66ac9dbSNicholas Bellinger * Create $CONFIGFS/target/core default group for HBA <-> Storage Object 3257c66ac9dbSNicholas Bellinger * and ALUA Logical Unit Group and Target Port Group infrastructure. 3258c66ac9dbSNicholas Bellinger */ 32591ae1602dSChristoph Hellwig config_group_init_type_name(&target_core_hbagroup, "core", 32601ae1602dSChristoph Hellwig &target_core_cit); 32611ae1602dSChristoph Hellwig configfs_add_default_group(&target_core_hbagroup, &subsys->su_group); 3262c66ac9dbSNicholas Bellinger 3263c66ac9dbSNicholas Bellinger /* 3264c66ac9dbSNicholas Bellinger * Create ALUA infrastructure under /sys/kernel/config/target/core/alua/ 3265c66ac9dbSNicholas Bellinger */ 32661ae1602dSChristoph Hellwig config_group_init_type_name(&alua_group, "alua", &target_core_alua_cit); 32671ae1602dSChristoph Hellwig configfs_add_default_group(&alua_group, &target_core_hbagroup); 32681ae1602dSChristoph Hellwig 3269c66ac9dbSNicholas Bellinger /* 3270c66ac9dbSNicholas Bellinger * Add ALUA Logical Unit Group and Target Port Group ConfigFS 3271c66ac9dbSNicholas Bellinger * groups under /sys/kernel/config/target/core/alua/ 3272c66ac9dbSNicholas Bellinger */ 32731ae1602dSChristoph Hellwig config_group_init_type_name(&alua_lu_gps_group, "lu_gps", 32741ae1602dSChristoph Hellwig &target_core_alua_lu_gps_cit); 32751ae1602dSChristoph Hellwig configfs_add_default_group(&alua_lu_gps_group, &alua_group); 3276c66ac9dbSNicholas Bellinger 3277c66ac9dbSNicholas Bellinger /* 3278c66ac9dbSNicholas Bellinger * Add core/alua/lu_gps/default_lu_gp 3279c66ac9dbSNicholas Bellinger */ 3280c66ac9dbSNicholas Bellinger lu_gp = core_alua_allocate_lu_gp("default_lu_gp", 1); 328137bb7899SPeter Senna Tschudin if (IS_ERR(lu_gp)) { 328237bb7899SPeter Senna Tschudin ret = -ENOMEM; 3283c66ac9dbSNicholas Bellinger goto out_global; 328437bb7899SPeter Senna Tschudin } 3285c66ac9dbSNicholas Bellinger 3286c66ac9dbSNicholas Bellinger config_group_init_type_name(&lu_gp->lu_gp_group, "default_lu_gp", 3287c66ac9dbSNicholas Bellinger &target_core_alua_lu_gp_cit); 32881ae1602dSChristoph Hellwig configfs_add_default_group(&lu_gp->lu_gp_group, &alua_lu_gps_group); 32891ae1602dSChristoph Hellwig 3290e3d6f909SAndy Grover default_lu_gp = lu_gp; 32911ae1602dSChristoph Hellwig 3292c66ac9dbSNicholas Bellinger /* 3293c66ac9dbSNicholas Bellinger * Register the target_core_mod subsystem with configfs. 3294c66ac9dbSNicholas Bellinger */ 3295c66ac9dbSNicholas Bellinger ret = configfs_register_subsystem(subsys); 3296c66ac9dbSNicholas Bellinger if (ret < 0) { 32976708bb27SAndy Grover pr_err("Error %d while registering subsystem %s\n", 3298c66ac9dbSNicholas Bellinger ret, subsys->su_group.cg_item.ci_namebuf); 3299c66ac9dbSNicholas Bellinger goto out_global; 3300c66ac9dbSNicholas Bellinger } 33016708bb27SAndy Grover pr_debug("TARGET_CORE[0]: Initialized ConfigFS Fabric" 3302ce8dd25dSChristoph Hellwig " Infrastructure: "TARGET_CORE_VERSION" on %s/%s" 3303c66ac9dbSNicholas Bellinger " on "UTS_RELEASE"\n", utsname()->sysname, utsname()->machine); 3304c66ac9dbSNicholas Bellinger /* 3305c66ac9dbSNicholas Bellinger * Register built-in RAMDISK subsystem logic for virtual LUN 0 3306c66ac9dbSNicholas Bellinger */ 3307c66ac9dbSNicholas Bellinger ret = rd_module_init(); 3308c66ac9dbSNicholas Bellinger if (ret < 0) 3309c66ac9dbSNicholas Bellinger goto out; 3310c66ac9dbSNicholas Bellinger 33110d0f9dfbSRoland Dreier ret = core_dev_setup_virtual_lun0(); 33120d0f9dfbSRoland Dreier if (ret < 0) 3313c66ac9dbSNicholas Bellinger goto out; 3314c66ac9dbSNicholas Bellinger 3315f99715acSNicholas Bellinger ret = target_xcopy_setup_pt(); 3316f99715acSNicholas Bellinger if (ret < 0) 3317f99715acSNicholas Bellinger goto out; 3318f99715acSNicholas Bellinger 331978a6295cSLee Duncan target_init_dbroot(); 332078a6295cSLee Duncan 3321c66ac9dbSNicholas Bellinger return 0; 3322c66ac9dbSNicholas Bellinger 3323c66ac9dbSNicholas Bellinger out: 3324c66ac9dbSNicholas Bellinger configfs_unregister_subsystem(subsys); 3325c66ac9dbSNicholas Bellinger core_dev_release_virtual_lun0(); 3326c66ac9dbSNicholas Bellinger rd_module_exit(); 3327c66ac9dbSNicholas Bellinger out_global: 3328e3d6f909SAndy Grover if (default_lu_gp) { 3329e3d6f909SAndy Grover core_alua_free_lu_gp(default_lu_gp); 3330e3d6f909SAndy Grover default_lu_gp = NULL; 3331c66ac9dbSNicholas Bellinger } 3332e3d6f909SAndy Grover release_se_kmem_caches(); 3333e3d6f909SAndy Grover return ret; 3334c66ac9dbSNicholas Bellinger } 3335c66ac9dbSNicholas Bellinger 333654550fabSAxel Lin static void __exit target_core_exit_configfs(void) 3337c66ac9dbSNicholas Bellinger { 33381ae1602dSChristoph Hellwig configfs_remove_default_groups(&alua_lu_gps_group); 33391ae1602dSChristoph Hellwig configfs_remove_default_groups(&alua_group); 33401ae1602dSChristoph Hellwig configfs_remove_default_groups(&target_core_hbagroup); 3341c66ac9dbSNicholas Bellinger 33427c2bf6e9SNicholas Bellinger /* 33437c2bf6e9SNicholas Bellinger * We expect subsys->su_group.default_groups to be released 33447c2bf6e9SNicholas Bellinger * by configfs subsystem provider logic.. 33457c2bf6e9SNicholas Bellinger */ 3346d588cf8fSChristoph Hellwig configfs_unregister_subsystem(&target_core_fabrics); 3347c66ac9dbSNicholas Bellinger 3348e3d6f909SAndy Grover core_alua_free_lu_gp(default_lu_gp); 3349e3d6f909SAndy Grover default_lu_gp = NULL; 33507c2bf6e9SNicholas Bellinger 33516708bb27SAndy Grover pr_debug("TARGET_CORE[0]: Released ConfigFS Fabric" 3352c66ac9dbSNicholas Bellinger " Infrastructure\n"); 3353c66ac9dbSNicholas Bellinger 3354c66ac9dbSNicholas Bellinger core_dev_release_virtual_lun0(); 3355c66ac9dbSNicholas Bellinger rd_module_exit(); 3356f99715acSNicholas Bellinger target_xcopy_release_pt(); 3357e3d6f909SAndy Grover release_se_kmem_caches(); 3358c66ac9dbSNicholas Bellinger } 3359c66ac9dbSNicholas Bellinger 3360c66ac9dbSNicholas Bellinger MODULE_DESCRIPTION("Target_Core_Mod/ConfigFS"); 3361c66ac9dbSNicholas Bellinger MODULE_AUTHOR("nab@Linux-iSCSI.org"); 3362c66ac9dbSNicholas Bellinger MODULE_LICENSE("GPL"); 3363c66ac9dbSNicholas Bellinger 3364c66ac9dbSNicholas Bellinger module_init(target_core_init_configfs); 3365c66ac9dbSNicholas Bellinger module_exit(target_core_exit_configfs); 3366