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 #include <target/target_core_fabric_configfs.h> 44c66ac9dbSNicholas Bellinger #include <target/target_core_configfs.h> 45c66ac9dbSNicholas Bellinger #include <target/configfs_macros.h> 46c66ac9dbSNicholas Bellinger 47e26d99aeSChristoph Hellwig #include "target_core_internal.h" 48c66ac9dbSNicholas Bellinger #include "target_core_alua.h" 49c66ac9dbSNicholas Bellinger #include "target_core_pr.h" 50c66ac9dbSNicholas Bellinger #include "target_core_rd.h" 51f99715acSNicholas Bellinger #include "target_core_xcopy.h" 52c66ac9dbSNicholas Bellinger 53e3d6f909SAndy Grover extern struct t10_alua_lu_gp *default_lu_gp; 54e3d6f909SAndy Grover 55d0f474e5SRoland Dreier static LIST_HEAD(g_tf_list); 56d0f474e5SRoland Dreier static DEFINE_MUTEX(g_tf_lock); 57c66ac9dbSNicholas Bellinger 58c66ac9dbSNicholas Bellinger struct target_core_configfs_attribute { 59c66ac9dbSNicholas Bellinger struct configfs_attribute attr; 60c66ac9dbSNicholas Bellinger ssize_t (*show)(void *, char *); 61c66ac9dbSNicholas Bellinger ssize_t (*store)(void *, const char *, size_t); 62c66ac9dbSNicholas Bellinger }; 63c66ac9dbSNicholas Bellinger 64e3d6f909SAndy Grover static struct config_group target_core_hbagroup; 65e3d6f909SAndy Grover static struct config_group alua_group; 66e3d6f909SAndy Grover static struct config_group alua_lu_gps_group; 67e3d6f909SAndy Grover 68c66ac9dbSNicholas Bellinger static inline struct se_hba * 69c66ac9dbSNicholas Bellinger item_to_hba(struct config_item *item) 70c66ac9dbSNicholas Bellinger { 71c66ac9dbSNicholas Bellinger return container_of(to_config_group(item), struct se_hba, hba_group); 72c66ac9dbSNicholas Bellinger } 73c66ac9dbSNicholas Bellinger 74c66ac9dbSNicholas Bellinger /* 75c66ac9dbSNicholas Bellinger * Attributes for /sys/kernel/config/target/ 76c66ac9dbSNicholas Bellinger */ 77c66ac9dbSNicholas Bellinger static ssize_t target_core_attr_show(struct config_item *item, 78c66ac9dbSNicholas Bellinger struct configfs_attribute *attr, 79c66ac9dbSNicholas Bellinger char *page) 80c66ac9dbSNicholas Bellinger { 81c66ac9dbSNicholas Bellinger return sprintf(page, "Target Engine Core ConfigFS Infrastructure %s" 82c66ac9dbSNicholas Bellinger " on %s/%s on "UTS_RELEASE"\n", TARGET_CORE_CONFIGFS_VERSION, 83c66ac9dbSNicholas Bellinger utsname()->sysname, utsname()->machine); 84c66ac9dbSNicholas Bellinger } 85c66ac9dbSNicholas Bellinger 86c66ac9dbSNicholas Bellinger static struct configfs_item_operations target_core_fabric_item_ops = { 87c66ac9dbSNicholas Bellinger .show_attribute = target_core_attr_show, 88c66ac9dbSNicholas Bellinger }; 89c66ac9dbSNicholas Bellinger 90c66ac9dbSNicholas Bellinger static struct configfs_attribute target_core_item_attr_version = { 91c66ac9dbSNicholas Bellinger .ca_owner = THIS_MODULE, 92c66ac9dbSNicholas Bellinger .ca_name = "version", 93c66ac9dbSNicholas Bellinger .ca_mode = S_IRUGO, 94c66ac9dbSNicholas Bellinger }; 95c66ac9dbSNicholas Bellinger 96c66ac9dbSNicholas Bellinger static struct target_fabric_configfs *target_core_get_fabric( 97c66ac9dbSNicholas Bellinger const char *name) 98c66ac9dbSNicholas Bellinger { 99c66ac9dbSNicholas Bellinger struct target_fabric_configfs *tf; 100c66ac9dbSNicholas Bellinger 1016708bb27SAndy Grover if (!name) 102c66ac9dbSNicholas Bellinger return NULL; 103c66ac9dbSNicholas Bellinger 104c66ac9dbSNicholas Bellinger mutex_lock(&g_tf_lock); 105c66ac9dbSNicholas Bellinger list_for_each_entry(tf, &g_tf_list, tf_list) { 1066708bb27SAndy Grover if (!strcmp(tf->tf_name, name)) { 107c66ac9dbSNicholas Bellinger atomic_inc(&tf->tf_access_cnt); 108c66ac9dbSNicholas Bellinger mutex_unlock(&g_tf_lock); 109c66ac9dbSNicholas Bellinger return tf; 110c66ac9dbSNicholas Bellinger } 111c66ac9dbSNicholas Bellinger } 112c66ac9dbSNicholas Bellinger mutex_unlock(&g_tf_lock); 113c66ac9dbSNicholas Bellinger 114c66ac9dbSNicholas Bellinger return NULL; 115c66ac9dbSNicholas Bellinger } 116c66ac9dbSNicholas Bellinger 117c66ac9dbSNicholas Bellinger /* 118c66ac9dbSNicholas Bellinger * Called from struct target_core_group_ops->make_group() 119c66ac9dbSNicholas Bellinger */ 120c66ac9dbSNicholas Bellinger static struct config_group *target_core_register_fabric( 121c66ac9dbSNicholas Bellinger struct config_group *group, 122c66ac9dbSNicholas Bellinger const char *name) 123c66ac9dbSNicholas Bellinger { 124c66ac9dbSNicholas Bellinger struct target_fabric_configfs *tf; 125c66ac9dbSNicholas Bellinger int ret; 126c66ac9dbSNicholas Bellinger 1276708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: REGISTER -> group: %p name:" 128c66ac9dbSNicholas Bellinger " %s\n", group, name); 129c66ac9dbSNicholas Bellinger /* 130c66ac9dbSNicholas Bellinger * Below are some hardcoded request_module() calls to automatically 131c66ac9dbSNicholas Bellinger * local fabric modules when the following is called: 132c66ac9dbSNicholas Bellinger * 133c66ac9dbSNicholas Bellinger * mkdir -p /sys/kernel/config/target/$MODULE_NAME 134c66ac9dbSNicholas Bellinger * 135c66ac9dbSNicholas Bellinger * Note that this does not limit which TCM fabric module can be 136c66ac9dbSNicholas Bellinger * registered, but simply provids auto loading logic for modules with 137c66ac9dbSNicholas Bellinger * mkdir(2) system calls with known TCM fabric modules. 138c66ac9dbSNicholas Bellinger */ 1396708bb27SAndy Grover if (!strncmp(name, "iscsi", 5)) { 140c66ac9dbSNicholas Bellinger /* 141c66ac9dbSNicholas Bellinger * Automatically load the LIO Target fabric module when the 142c66ac9dbSNicholas Bellinger * following is called: 143c66ac9dbSNicholas Bellinger * 144c66ac9dbSNicholas Bellinger * mkdir -p $CONFIGFS/target/iscsi 145c66ac9dbSNicholas Bellinger */ 146c66ac9dbSNicholas Bellinger ret = request_module("iscsi_target_mod"); 147c66ac9dbSNicholas Bellinger if (ret < 0) { 1486708bb27SAndy Grover pr_err("request_module() failed for" 149c66ac9dbSNicholas Bellinger " iscsi_target_mod.ko: %d\n", ret); 150c66ac9dbSNicholas Bellinger return ERR_PTR(-EINVAL); 151c66ac9dbSNicholas Bellinger } 1526708bb27SAndy Grover } else if (!strncmp(name, "loopback", 8)) { 153c66ac9dbSNicholas Bellinger /* 154c66ac9dbSNicholas Bellinger * Automatically load the tcm_loop fabric module when the 155c66ac9dbSNicholas Bellinger * following is called: 156c66ac9dbSNicholas Bellinger * 157c66ac9dbSNicholas Bellinger * mkdir -p $CONFIGFS/target/loopback 158c66ac9dbSNicholas Bellinger */ 159c66ac9dbSNicholas Bellinger ret = request_module("tcm_loop"); 160c66ac9dbSNicholas Bellinger if (ret < 0) { 1616708bb27SAndy Grover pr_err("request_module() failed for" 162c66ac9dbSNicholas Bellinger " tcm_loop.ko: %d\n", ret); 163c66ac9dbSNicholas Bellinger return ERR_PTR(-EINVAL); 164c66ac9dbSNicholas Bellinger } 165c66ac9dbSNicholas Bellinger } 166c66ac9dbSNicholas Bellinger 167c66ac9dbSNicholas Bellinger tf = target_core_get_fabric(name); 1686708bb27SAndy Grover if (!tf) { 1696708bb27SAndy Grover pr_err("target_core_get_fabric() failed for %s\n", 170c66ac9dbSNicholas Bellinger name); 171c66ac9dbSNicholas Bellinger return ERR_PTR(-EINVAL); 172c66ac9dbSNicholas Bellinger } 1736708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: REGISTER -> Located fabric:" 174c66ac9dbSNicholas Bellinger " %s\n", tf->tf_name); 175c66ac9dbSNicholas Bellinger /* 176c66ac9dbSNicholas Bellinger * On a successful target_core_get_fabric() look, the returned 177c66ac9dbSNicholas Bellinger * struct target_fabric_configfs *tf will contain a usage reference. 178c66ac9dbSNicholas Bellinger */ 1796708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: REGISTER tfc_wwn_cit -> %p\n", 180c66ac9dbSNicholas Bellinger &TF_CIT_TMPL(tf)->tfc_wwn_cit); 181c66ac9dbSNicholas Bellinger 182c66ac9dbSNicholas Bellinger tf->tf_group.default_groups = tf->tf_default_groups; 183c66ac9dbSNicholas Bellinger tf->tf_group.default_groups[0] = &tf->tf_disc_group; 184c66ac9dbSNicholas Bellinger tf->tf_group.default_groups[1] = NULL; 185c66ac9dbSNicholas Bellinger 186c66ac9dbSNicholas Bellinger config_group_init_type_name(&tf->tf_group, name, 187c66ac9dbSNicholas Bellinger &TF_CIT_TMPL(tf)->tfc_wwn_cit); 188c66ac9dbSNicholas Bellinger config_group_init_type_name(&tf->tf_disc_group, "discovery_auth", 189c66ac9dbSNicholas Bellinger &TF_CIT_TMPL(tf)->tfc_discovery_cit); 190c66ac9dbSNicholas Bellinger 1916708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: REGISTER -> Allocated Fabric:" 192c66ac9dbSNicholas Bellinger " %s\n", tf->tf_group.cg_item.ci_name); 193c66ac9dbSNicholas Bellinger /* 194c66ac9dbSNicholas Bellinger * Setup tf_ops.tf_subsys pointer for usage with configfs_depend_item() 195c66ac9dbSNicholas Bellinger */ 196c66ac9dbSNicholas Bellinger tf->tf_ops.tf_subsys = tf->tf_subsys; 197c66ac9dbSNicholas Bellinger tf->tf_fabric = &tf->tf_group.cg_item; 1986708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: REGISTER -> Set tf->tf_fabric" 199c66ac9dbSNicholas Bellinger " for %s\n", name); 200c66ac9dbSNicholas Bellinger 201c66ac9dbSNicholas Bellinger return &tf->tf_group; 202c66ac9dbSNicholas Bellinger } 203c66ac9dbSNicholas Bellinger 204c66ac9dbSNicholas Bellinger /* 205c66ac9dbSNicholas Bellinger * Called from struct target_core_group_ops->drop_item() 206c66ac9dbSNicholas Bellinger */ 207c66ac9dbSNicholas Bellinger static void target_core_deregister_fabric( 208c66ac9dbSNicholas Bellinger struct config_group *group, 209c66ac9dbSNicholas Bellinger struct config_item *item) 210c66ac9dbSNicholas Bellinger { 211c66ac9dbSNicholas Bellinger struct target_fabric_configfs *tf = container_of( 212c66ac9dbSNicholas Bellinger to_config_group(item), struct target_fabric_configfs, tf_group); 213c66ac9dbSNicholas Bellinger struct config_group *tf_group; 214c66ac9dbSNicholas Bellinger struct config_item *df_item; 215c66ac9dbSNicholas Bellinger int i; 216c66ac9dbSNicholas Bellinger 2176708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: DEREGISTER -> Looking up %s in" 218c66ac9dbSNicholas Bellinger " tf list\n", config_item_name(item)); 219c66ac9dbSNicholas Bellinger 2206708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: DEREGISTER -> located fabric:" 221c66ac9dbSNicholas Bellinger " %s\n", tf->tf_name); 222c66ac9dbSNicholas Bellinger atomic_dec(&tf->tf_access_cnt); 223c66ac9dbSNicholas Bellinger 2246708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing" 225c66ac9dbSNicholas Bellinger " tf->tf_fabric for %s\n", tf->tf_name); 226c66ac9dbSNicholas Bellinger tf->tf_fabric = NULL; 227c66ac9dbSNicholas Bellinger 2286708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing ci" 229c66ac9dbSNicholas Bellinger " %s\n", config_item_name(item)); 230c66ac9dbSNicholas Bellinger 231c66ac9dbSNicholas Bellinger tf_group = &tf->tf_group; 232c66ac9dbSNicholas Bellinger for (i = 0; tf_group->default_groups[i]; i++) { 233c66ac9dbSNicholas Bellinger df_item = &tf_group->default_groups[i]->cg_item; 234c66ac9dbSNicholas Bellinger tf_group->default_groups[i] = NULL; 235c66ac9dbSNicholas Bellinger config_item_put(df_item); 236c66ac9dbSNicholas Bellinger } 237c66ac9dbSNicholas Bellinger config_item_put(item); 238c66ac9dbSNicholas Bellinger } 239c66ac9dbSNicholas Bellinger 240c66ac9dbSNicholas Bellinger static struct configfs_group_operations target_core_fabric_group_ops = { 241c66ac9dbSNicholas Bellinger .make_group = &target_core_register_fabric, 242c66ac9dbSNicholas Bellinger .drop_item = &target_core_deregister_fabric, 243c66ac9dbSNicholas Bellinger }; 244c66ac9dbSNicholas Bellinger 245c66ac9dbSNicholas Bellinger /* 246c66ac9dbSNicholas Bellinger * All item attributes appearing in /sys/kernel/target/ appear here. 247c66ac9dbSNicholas Bellinger */ 248c66ac9dbSNicholas Bellinger static struct configfs_attribute *target_core_fabric_item_attrs[] = { 249c66ac9dbSNicholas Bellinger &target_core_item_attr_version, 250c66ac9dbSNicholas Bellinger NULL, 251c66ac9dbSNicholas Bellinger }; 252c66ac9dbSNicholas Bellinger 253c66ac9dbSNicholas Bellinger /* 254c66ac9dbSNicholas Bellinger * Provides Fabrics Groups and Item Attributes for /sys/kernel/config/target/ 255c66ac9dbSNicholas Bellinger */ 256c66ac9dbSNicholas Bellinger static struct config_item_type target_core_fabrics_item = { 257c66ac9dbSNicholas Bellinger .ct_item_ops = &target_core_fabric_item_ops, 258c66ac9dbSNicholas Bellinger .ct_group_ops = &target_core_fabric_group_ops, 259c66ac9dbSNicholas Bellinger .ct_attrs = target_core_fabric_item_attrs, 260c66ac9dbSNicholas Bellinger .ct_owner = THIS_MODULE, 261c66ac9dbSNicholas Bellinger }; 262c66ac9dbSNicholas Bellinger 263c66ac9dbSNicholas Bellinger static struct configfs_subsystem target_core_fabrics = { 264c66ac9dbSNicholas Bellinger .su_group = { 265c66ac9dbSNicholas Bellinger .cg_item = { 266c66ac9dbSNicholas Bellinger .ci_namebuf = "target", 267c66ac9dbSNicholas Bellinger .ci_type = &target_core_fabrics_item, 268c66ac9dbSNicholas Bellinger }, 269c66ac9dbSNicholas Bellinger }, 270c66ac9dbSNicholas Bellinger }; 271c66ac9dbSNicholas Bellinger 27256d128faSNicholas Bellinger struct configfs_subsystem *target_core_subsystem[] = { 273c66ac9dbSNicholas Bellinger &target_core_fabrics, 274c66ac9dbSNicholas Bellinger NULL, 275c66ac9dbSNicholas Bellinger }; 276c66ac9dbSNicholas Bellinger 277c66ac9dbSNicholas Bellinger /*############################################################################## 278c66ac9dbSNicholas Bellinger // Start functions called by external Target Fabrics Modules 279c66ac9dbSNicholas Bellinger //############################################################################*/ 280c66ac9dbSNicholas Bellinger 281c66ac9dbSNicholas Bellinger /* 282c66ac9dbSNicholas Bellinger * First function called by fabric modules to: 283c66ac9dbSNicholas Bellinger * 284c66ac9dbSNicholas Bellinger * 1) Allocate a struct target_fabric_configfs and save the *fabric_cit pointer. 285c66ac9dbSNicholas Bellinger * 2) Add struct target_fabric_configfs to g_tf_list 286c66ac9dbSNicholas Bellinger * 3) Return struct target_fabric_configfs to fabric module to be passed 287c66ac9dbSNicholas Bellinger * into target_fabric_configfs_register(). 288c66ac9dbSNicholas Bellinger */ 289c66ac9dbSNicholas Bellinger struct target_fabric_configfs *target_fabric_configfs_init( 290c66ac9dbSNicholas Bellinger struct module *fabric_mod, 291c66ac9dbSNicholas Bellinger const char *name) 292c66ac9dbSNicholas Bellinger { 293c66ac9dbSNicholas Bellinger struct target_fabric_configfs *tf; 294c66ac9dbSNicholas Bellinger 295c66ac9dbSNicholas Bellinger if (!(name)) { 2966708bb27SAndy Grover pr_err("Unable to locate passed fabric name\n"); 297e3d6f909SAndy Grover return ERR_PTR(-EINVAL); 298c66ac9dbSNicholas Bellinger } 29960d645a4SDan Carpenter if (strlen(name) >= TARGET_FABRIC_NAME_SIZE) { 3006708bb27SAndy Grover pr_err("Passed name: %s exceeds TARGET_FABRIC" 301c66ac9dbSNicholas Bellinger "_NAME_SIZE\n", name); 302e3d6f909SAndy Grover return ERR_PTR(-EINVAL); 303c66ac9dbSNicholas Bellinger } 304c66ac9dbSNicholas Bellinger 305c66ac9dbSNicholas Bellinger tf = kzalloc(sizeof(struct target_fabric_configfs), GFP_KERNEL); 3066708bb27SAndy Grover if (!tf) 307e3d6f909SAndy Grover return ERR_PTR(-ENOMEM); 308c66ac9dbSNicholas Bellinger 309c66ac9dbSNicholas Bellinger INIT_LIST_HEAD(&tf->tf_list); 310c66ac9dbSNicholas Bellinger atomic_set(&tf->tf_access_cnt, 0); 311c66ac9dbSNicholas Bellinger /* 312c66ac9dbSNicholas Bellinger * Setup the default generic struct config_item_type's (cits) in 313c66ac9dbSNicholas Bellinger * struct target_fabric_configfs->tf_cit_tmpl 314c66ac9dbSNicholas Bellinger */ 315c66ac9dbSNicholas Bellinger tf->tf_module = fabric_mod; 316c66ac9dbSNicholas Bellinger target_fabric_setup_cits(tf); 317c66ac9dbSNicholas Bellinger 318c66ac9dbSNicholas Bellinger tf->tf_subsys = target_core_subsystem[0]; 319c66ac9dbSNicholas Bellinger snprintf(tf->tf_name, TARGET_FABRIC_NAME_SIZE, "%s", name); 320c66ac9dbSNicholas Bellinger 321c66ac9dbSNicholas Bellinger mutex_lock(&g_tf_lock); 322c66ac9dbSNicholas Bellinger list_add_tail(&tf->tf_list, &g_tf_list); 323c66ac9dbSNicholas Bellinger mutex_unlock(&g_tf_lock); 324c66ac9dbSNicholas Bellinger 3256708bb27SAndy Grover pr_debug("<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>" 326c66ac9dbSNicholas Bellinger ">>>>>>>>>>>>>>\n"); 3276708bb27SAndy Grover pr_debug("Initialized struct target_fabric_configfs: %p for" 328c66ac9dbSNicholas Bellinger " %s\n", tf, tf->tf_name); 329c66ac9dbSNicholas Bellinger return tf; 330c66ac9dbSNicholas Bellinger } 331c66ac9dbSNicholas Bellinger EXPORT_SYMBOL(target_fabric_configfs_init); 332c66ac9dbSNicholas Bellinger 333c66ac9dbSNicholas Bellinger /* 334c66ac9dbSNicholas Bellinger * Called by fabric plugins after FAILED target_fabric_configfs_register() call. 335c66ac9dbSNicholas Bellinger */ 336c66ac9dbSNicholas Bellinger void target_fabric_configfs_free( 337c66ac9dbSNicholas Bellinger struct target_fabric_configfs *tf) 338c66ac9dbSNicholas Bellinger { 339c66ac9dbSNicholas Bellinger mutex_lock(&g_tf_lock); 340c66ac9dbSNicholas Bellinger list_del(&tf->tf_list); 341c66ac9dbSNicholas Bellinger mutex_unlock(&g_tf_lock); 342c66ac9dbSNicholas Bellinger 343c66ac9dbSNicholas Bellinger kfree(tf); 344c66ac9dbSNicholas Bellinger } 345c66ac9dbSNicholas Bellinger EXPORT_SYMBOL(target_fabric_configfs_free); 346c66ac9dbSNicholas Bellinger 347c66ac9dbSNicholas Bellinger /* 348c66ac9dbSNicholas Bellinger * Perform a sanity check of the passed tf->tf_ops before completing 349c66ac9dbSNicholas Bellinger * TCM fabric module registration. 350c66ac9dbSNicholas Bellinger */ 351c66ac9dbSNicholas Bellinger static int target_fabric_tf_ops_check( 352c66ac9dbSNicholas Bellinger struct target_fabric_configfs *tf) 353c66ac9dbSNicholas Bellinger { 354c66ac9dbSNicholas Bellinger struct target_core_fabric_ops *tfo = &tf->tf_ops; 355c66ac9dbSNicholas Bellinger 3566708bb27SAndy Grover if (!tfo->get_fabric_name) { 3576708bb27SAndy Grover pr_err("Missing tfo->get_fabric_name()\n"); 358c66ac9dbSNicholas Bellinger return -EINVAL; 359c66ac9dbSNicholas Bellinger } 3606708bb27SAndy Grover if (!tfo->get_fabric_proto_ident) { 3616708bb27SAndy Grover pr_err("Missing tfo->get_fabric_proto_ident()\n"); 362c66ac9dbSNicholas Bellinger return -EINVAL; 363c66ac9dbSNicholas Bellinger } 3646708bb27SAndy Grover if (!tfo->tpg_get_wwn) { 3656708bb27SAndy Grover pr_err("Missing tfo->tpg_get_wwn()\n"); 366c66ac9dbSNicholas Bellinger return -EINVAL; 367c66ac9dbSNicholas Bellinger } 3686708bb27SAndy Grover if (!tfo->tpg_get_tag) { 3696708bb27SAndy Grover pr_err("Missing tfo->tpg_get_tag()\n"); 370c66ac9dbSNicholas Bellinger return -EINVAL; 371c66ac9dbSNicholas Bellinger } 3726708bb27SAndy Grover if (!tfo->tpg_get_default_depth) { 3736708bb27SAndy Grover pr_err("Missing tfo->tpg_get_default_depth()\n"); 374c66ac9dbSNicholas Bellinger return -EINVAL; 375c66ac9dbSNicholas Bellinger } 3766708bb27SAndy Grover if (!tfo->tpg_get_pr_transport_id) { 3776708bb27SAndy Grover pr_err("Missing tfo->tpg_get_pr_transport_id()\n"); 378c66ac9dbSNicholas Bellinger return -EINVAL; 379c66ac9dbSNicholas Bellinger } 3806708bb27SAndy Grover if (!tfo->tpg_get_pr_transport_id_len) { 3816708bb27SAndy Grover pr_err("Missing tfo->tpg_get_pr_transport_id_len()\n"); 382c66ac9dbSNicholas Bellinger return -EINVAL; 383c66ac9dbSNicholas Bellinger } 3846708bb27SAndy Grover if (!tfo->tpg_check_demo_mode) { 3856708bb27SAndy Grover pr_err("Missing tfo->tpg_check_demo_mode()\n"); 386c66ac9dbSNicholas Bellinger return -EINVAL; 387c66ac9dbSNicholas Bellinger } 3886708bb27SAndy Grover if (!tfo->tpg_check_demo_mode_cache) { 3896708bb27SAndy Grover pr_err("Missing tfo->tpg_check_demo_mode_cache()\n"); 390c66ac9dbSNicholas Bellinger return -EINVAL; 391c66ac9dbSNicholas Bellinger } 3926708bb27SAndy Grover if (!tfo->tpg_check_demo_mode_write_protect) { 3936708bb27SAndy Grover pr_err("Missing tfo->tpg_check_demo_mode_write_protect()\n"); 394c66ac9dbSNicholas Bellinger return -EINVAL; 395c66ac9dbSNicholas Bellinger } 3966708bb27SAndy Grover if (!tfo->tpg_check_prod_mode_write_protect) { 3976708bb27SAndy Grover pr_err("Missing tfo->tpg_check_prod_mode_write_protect()\n"); 398c66ac9dbSNicholas Bellinger return -EINVAL; 399c66ac9dbSNicholas Bellinger } 4006708bb27SAndy Grover if (!tfo->tpg_alloc_fabric_acl) { 4016708bb27SAndy Grover pr_err("Missing tfo->tpg_alloc_fabric_acl()\n"); 402c66ac9dbSNicholas Bellinger return -EINVAL; 403c66ac9dbSNicholas Bellinger } 4046708bb27SAndy Grover if (!tfo->tpg_release_fabric_acl) { 4056708bb27SAndy Grover pr_err("Missing tfo->tpg_release_fabric_acl()\n"); 406c66ac9dbSNicholas Bellinger return -EINVAL; 407c66ac9dbSNicholas Bellinger } 4086708bb27SAndy Grover if (!tfo->tpg_get_inst_index) { 4096708bb27SAndy Grover pr_err("Missing tfo->tpg_get_inst_index()\n"); 410c66ac9dbSNicholas Bellinger return -EINVAL; 411c66ac9dbSNicholas Bellinger } 41235462975SChristoph Hellwig if (!tfo->release_cmd) { 4136708bb27SAndy Grover pr_err("Missing tfo->release_cmd()\n"); 414c66ac9dbSNicholas Bellinger return -EINVAL; 415c66ac9dbSNicholas Bellinger } 4166708bb27SAndy Grover if (!tfo->shutdown_session) { 4176708bb27SAndy Grover pr_err("Missing tfo->shutdown_session()\n"); 418c66ac9dbSNicholas Bellinger return -EINVAL; 419c66ac9dbSNicholas Bellinger } 4206708bb27SAndy Grover if (!tfo->close_session) { 4216708bb27SAndy Grover pr_err("Missing tfo->close_session()\n"); 422c66ac9dbSNicholas Bellinger return -EINVAL; 423c66ac9dbSNicholas Bellinger } 4246708bb27SAndy Grover if (!tfo->sess_get_index) { 4256708bb27SAndy Grover pr_err("Missing tfo->sess_get_index()\n"); 426c66ac9dbSNicholas Bellinger return -EINVAL; 427c66ac9dbSNicholas Bellinger } 4286708bb27SAndy Grover if (!tfo->write_pending) { 4296708bb27SAndy Grover pr_err("Missing tfo->write_pending()\n"); 430c66ac9dbSNicholas Bellinger return -EINVAL; 431c66ac9dbSNicholas Bellinger } 4326708bb27SAndy Grover if (!tfo->write_pending_status) { 4336708bb27SAndy Grover pr_err("Missing tfo->write_pending_status()\n"); 434c66ac9dbSNicholas Bellinger return -EINVAL; 435c66ac9dbSNicholas Bellinger } 4366708bb27SAndy Grover if (!tfo->set_default_node_attributes) { 4376708bb27SAndy Grover pr_err("Missing tfo->set_default_node_attributes()\n"); 438c66ac9dbSNicholas Bellinger return -EINVAL; 439c66ac9dbSNicholas Bellinger } 4406708bb27SAndy Grover if (!tfo->get_task_tag) { 4416708bb27SAndy Grover pr_err("Missing tfo->get_task_tag()\n"); 442c66ac9dbSNicholas Bellinger return -EINVAL; 443c66ac9dbSNicholas Bellinger } 4446708bb27SAndy Grover if (!tfo->get_cmd_state) { 4456708bb27SAndy Grover pr_err("Missing tfo->get_cmd_state()\n"); 446c66ac9dbSNicholas Bellinger return -EINVAL; 447c66ac9dbSNicholas Bellinger } 4486708bb27SAndy Grover if (!tfo->queue_data_in) { 4496708bb27SAndy Grover pr_err("Missing tfo->queue_data_in()\n"); 450c66ac9dbSNicholas Bellinger return -EINVAL; 451c66ac9dbSNicholas Bellinger } 4526708bb27SAndy Grover if (!tfo->queue_status) { 4536708bb27SAndy Grover pr_err("Missing tfo->queue_status()\n"); 454c66ac9dbSNicholas Bellinger return -EINVAL; 455c66ac9dbSNicholas Bellinger } 4566708bb27SAndy Grover if (!tfo->queue_tm_rsp) { 4576708bb27SAndy Grover pr_err("Missing tfo->queue_tm_rsp()\n"); 458c66ac9dbSNicholas Bellinger return -EINVAL; 459c66ac9dbSNicholas Bellinger } 460c66ac9dbSNicholas Bellinger /* 461c66ac9dbSNicholas Bellinger * We at least require tfo->fabric_make_wwn(), tfo->fabric_drop_wwn() 462c66ac9dbSNicholas Bellinger * tfo->fabric_make_tpg() and tfo->fabric_drop_tpg() in 463c66ac9dbSNicholas Bellinger * target_core_fabric_configfs.c WWN+TPG group context code. 464c66ac9dbSNicholas Bellinger */ 4656708bb27SAndy Grover if (!tfo->fabric_make_wwn) { 4666708bb27SAndy Grover pr_err("Missing tfo->fabric_make_wwn()\n"); 467c66ac9dbSNicholas Bellinger return -EINVAL; 468c66ac9dbSNicholas Bellinger } 4696708bb27SAndy Grover if (!tfo->fabric_drop_wwn) { 4706708bb27SAndy Grover pr_err("Missing tfo->fabric_drop_wwn()\n"); 471c66ac9dbSNicholas Bellinger return -EINVAL; 472c66ac9dbSNicholas Bellinger } 4736708bb27SAndy Grover if (!tfo->fabric_make_tpg) { 4746708bb27SAndy Grover pr_err("Missing tfo->fabric_make_tpg()\n"); 475c66ac9dbSNicholas Bellinger return -EINVAL; 476c66ac9dbSNicholas Bellinger } 4776708bb27SAndy Grover if (!tfo->fabric_drop_tpg) { 4786708bb27SAndy Grover pr_err("Missing tfo->fabric_drop_tpg()\n"); 479c66ac9dbSNicholas Bellinger return -EINVAL; 480c66ac9dbSNicholas Bellinger } 481c66ac9dbSNicholas Bellinger 482c66ac9dbSNicholas Bellinger return 0; 483c66ac9dbSNicholas Bellinger } 484c66ac9dbSNicholas Bellinger 485c66ac9dbSNicholas Bellinger /* 486c66ac9dbSNicholas Bellinger * Called 2nd from fabric module with returned parameter of 487c66ac9dbSNicholas Bellinger * struct target_fabric_configfs * from target_fabric_configfs_init(). 488c66ac9dbSNicholas Bellinger * 489c66ac9dbSNicholas Bellinger * Upon a successful registration, the new fabric's struct config_item is 490c66ac9dbSNicholas Bellinger * return. Also, a pointer to this struct is set in the passed 491c66ac9dbSNicholas Bellinger * struct target_fabric_configfs. 492c66ac9dbSNicholas Bellinger */ 493c66ac9dbSNicholas Bellinger int target_fabric_configfs_register( 494c66ac9dbSNicholas Bellinger struct target_fabric_configfs *tf) 495c66ac9dbSNicholas Bellinger { 496c66ac9dbSNicholas Bellinger int ret; 497c66ac9dbSNicholas Bellinger 4986708bb27SAndy Grover if (!tf) { 4996708bb27SAndy Grover pr_err("Unable to locate target_fabric_configfs" 500c66ac9dbSNicholas Bellinger " pointer\n"); 501c66ac9dbSNicholas Bellinger return -EINVAL; 502c66ac9dbSNicholas Bellinger } 5036708bb27SAndy Grover if (!tf->tf_subsys) { 5046708bb27SAndy Grover pr_err("Unable to target struct config_subsystem" 505c66ac9dbSNicholas Bellinger " pointer\n"); 506c66ac9dbSNicholas Bellinger return -EINVAL; 507c66ac9dbSNicholas Bellinger } 508c66ac9dbSNicholas Bellinger ret = target_fabric_tf_ops_check(tf); 509c66ac9dbSNicholas Bellinger if (ret < 0) 510c66ac9dbSNicholas Bellinger return ret; 511c66ac9dbSNicholas Bellinger 5126708bb27SAndy Grover pr_debug("<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>" 513c66ac9dbSNicholas Bellinger ">>>>>>>>>>\n"); 514c66ac9dbSNicholas Bellinger return 0; 515c66ac9dbSNicholas Bellinger } 516c66ac9dbSNicholas Bellinger EXPORT_SYMBOL(target_fabric_configfs_register); 517c66ac9dbSNicholas Bellinger 518c66ac9dbSNicholas Bellinger void target_fabric_configfs_deregister( 519c66ac9dbSNicholas Bellinger struct target_fabric_configfs *tf) 520c66ac9dbSNicholas Bellinger { 521c66ac9dbSNicholas Bellinger struct configfs_subsystem *su; 522c66ac9dbSNicholas Bellinger 5236708bb27SAndy Grover if (!tf) { 5246708bb27SAndy Grover pr_err("Unable to locate passed target_fabric_" 525c66ac9dbSNicholas Bellinger "configfs\n"); 526c66ac9dbSNicholas Bellinger return; 527c66ac9dbSNicholas Bellinger } 528c66ac9dbSNicholas Bellinger su = tf->tf_subsys; 5296708bb27SAndy Grover if (!su) { 5306708bb27SAndy Grover pr_err("Unable to locate passed tf->tf_subsys" 531c66ac9dbSNicholas Bellinger " pointer\n"); 532c66ac9dbSNicholas Bellinger return; 533c66ac9dbSNicholas Bellinger } 5346708bb27SAndy Grover pr_debug("<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>>>" 535c66ac9dbSNicholas Bellinger ">>>>>>>>>>>>\n"); 536c66ac9dbSNicholas Bellinger mutex_lock(&g_tf_lock); 537c66ac9dbSNicholas Bellinger if (atomic_read(&tf->tf_access_cnt)) { 538c66ac9dbSNicholas Bellinger mutex_unlock(&g_tf_lock); 5396708bb27SAndy Grover pr_err("Non zero tf->tf_access_cnt for fabric %s\n", 540c66ac9dbSNicholas Bellinger tf->tf_name); 541c66ac9dbSNicholas Bellinger BUG(); 542c66ac9dbSNicholas Bellinger } 543c66ac9dbSNicholas Bellinger list_del(&tf->tf_list); 544c66ac9dbSNicholas Bellinger mutex_unlock(&g_tf_lock); 545c66ac9dbSNicholas Bellinger 5466708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing tf:" 547c66ac9dbSNicholas Bellinger " %s\n", tf->tf_name); 548c66ac9dbSNicholas Bellinger tf->tf_module = NULL; 549c66ac9dbSNicholas Bellinger tf->tf_subsys = NULL; 550c66ac9dbSNicholas Bellinger kfree(tf); 551c66ac9dbSNicholas Bellinger 5526708bb27SAndy Grover pr_debug("<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>>>>>>" 553c66ac9dbSNicholas Bellinger ">>>>>\n"); 554c66ac9dbSNicholas Bellinger } 555c66ac9dbSNicholas Bellinger EXPORT_SYMBOL(target_fabric_configfs_deregister); 556c66ac9dbSNicholas Bellinger 557c66ac9dbSNicholas Bellinger /*############################################################################## 558c66ac9dbSNicholas Bellinger // Stop functions called by external Target Fabrics Modules 559c66ac9dbSNicholas Bellinger //############################################################################*/ 560c66ac9dbSNicholas Bellinger 561c66ac9dbSNicholas Bellinger /* Start functions for struct config_item_type target_core_dev_attrib_cit */ 562c66ac9dbSNicholas Bellinger 563c66ac9dbSNicholas Bellinger #define DEF_DEV_ATTRIB_SHOW(_name) \ 564c66ac9dbSNicholas Bellinger static ssize_t target_core_dev_show_attr_##_name( \ 565c66ac9dbSNicholas Bellinger struct se_dev_attrib *da, \ 566c66ac9dbSNicholas Bellinger char *page) \ 567c66ac9dbSNicholas Bellinger { \ 5680fd97ccfSChristoph Hellwig return snprintf(page, PAGE_SIZE, "%u\n", \ 5690fd97ccfSChristoph Hellwig (u32)da->da_dev->dev_attrib._name); \ 570c66ac9dbSNicholas Bellinger } 571c66ac9dbSNicholas Bellinger 572c66ac9dbSNicholas Bellinger #define DEF_DEV_ATTRIB_STORE(_name) \ 573c66ac9dbSNicholas Bellinger static ssize_t target_core_dev_store_attr_##_name( \ 574c66ac9dbSNicholas Bellinger struct se_dev_attrib *da, \ 575c66ac9dbSNicholas Bellinger const char *page, \ 576c66ac9dbSNicholas Bellinger size_t count) \ 577c66ac9dbSNicholas Bellinger { \ 578c66ac9dbSNicholas Bellinger unsigned long val; \ 579c66ac9dbSNicholas Bellinger int ret; \ 580c66ac9dbSNicholas Bellinger \ 58157103d7fSJingoo Han ret = kstrtoul(page, 0, &val); \ 582c66ac9dbSNicholas Bellinger if (ret < 0) { \ 58357103d7fSJingoo Han pr_err("kstrtoul() failed with" \ 584c66ac9dbSNicholas Bellinger " ret: %d\n", ret); \ 585c66ac9dbSNicholas Bellinger return -EINVAL; \ 586c66ac9dbSNicholas Bellinger } \ 5870fd97ccfSChristoph Hellwig ret = se_dev_set_##_name(da->da_dev, (u32)val); \ 588c66ac9dbSNicholas Bellinger \ 589c66ac9dbSNicholas Bellinger return (!ret) ? count : -EINVAL; \ 590c66ac9dbSNicholas Bellinger } 591c66ac9dbSNicholas Bellinger 592c66ac9dbSNicholas Bellinger #define DEF_DEV_ATTRIB(_name) \ 593c66ac9dbSNicholas Bellinger DEF_DEV_ATTRIB_SHOW(_name); \ 594c66ac9dbSNicholas Bellinger DEF_DEV_ATTRIB_STORE(_name); 595c66ac9dbSNicholas Bellinger 596c66ac9dbSNicholas Bellinger #define DEF_DEV_ATTRIB_RO(_name) \ 597c66ac9dbSNicholas Bellinger DEF_DEV_ATTRIB_SHOW(_name); 598c66ac9dbSNicholas Bellinger 599c66ac9dbSNicholas Bellinger CONFIGFS_EATTR_STRUCT(target_core_dev_attrib, se_dev_attrib); 600c66ac9dbSNicholas Bellinger #define SE_DEV_ATTR(_name, _mode) \ 601c66ac9dbSNicholas Bellinger static struct target_core_dev_attrib_attribute \ 602c66ac9dbSNicholas Bellinger target_core_dev_attrib_##_name = \ 603c66ac9dbSNicholas Bellinger __CONFIGFS_EATTR(_name, _mode, \ 604c66ac9dbSNicholas Bellinger target_core_dev_show_attr_##_name, \ 605c66ac9dbSNicholas Bellinger target_core_dev_store_attr_##_name); 606c66ac9dbSNicholas Bellinger 607c66ac9dbSNicholas Bellinger #define SE_DEV_ATTR_RO(_name); \ 608c66ac9dbSNicholas Bellinger static struct target_core_dev_attrib_attribute \ 609c66ac9dbSNicholas Bellinger target_core_dev_attrib_##_name = \ 610c66ac9dbSNicholas Bellinger __CONFIGFS_EATTR_RO(_name, \ 611c66ac9dbSNicholas Bellinger target_core_dev_show_attr_##_name); 612c66ac9dbSNicholas Bellinger 613adfa9570STregaron Bayly DEF_DEV_ATTRIB(emulate_model_alias); 614adfa9570STregaron Bayly SE_DEV_ATTR(emulate_model_alias, S_IRUGO | S_IWUSR); 615adfa9570STregaron Bayly 616c66ac9dbSNicholas Bellinger DEF_DEV_ATTRIB(emulate_dpo); 617c66ac9dbSNicholas Bellinger SE_DEV_ATTR(emulate_dpo, S_IRUGO | S_IWUSR); 618c66ac9dbSNicholas Bellinger 619c66ac9dbSNicholas Bellinger DEF_DEV_ATTRIB(emulate_fua_write); 620c66ac9dbSNicholas Bellinger SE_DEV_ATTR(emulate_fua_write, S_IRUGO | S_IWUSR); 621c66ac9dbSNicholas Bellinger 622c66ac9dbSNicholas Bellinger DEF_DEV_ATTRIB(emulate_fua_read); 623c66ac9dbSNicholas Bellinger SE_DEV_ATTR(emulate_fua_read, S_IRUGO | S_IWUSR); 624c66ac9dbSNicholas Bellinger 625c66ac9dbSNicholas Bellinger DEF_DEV_ATTRIB(emulate_write_cache); 626c66ac9dbSNicholas Bellinger SE_DEV_ATTR(emulate_write_cache, S_IRUGO | S_IWUSR); 627c66ac9dbSNicholas Bellinger 628c66ac9dbSNicholas Bellinger DEF_DEV_ATTRIB(emulate_ua_intlck_ctrl); 629c66ac9dbSNicholas Bellinger SE_DEV_ATTR(emulate_ua_intlck_ctrl, S_IRUGO | S_IWUSR); 630c66ac9dbSNicholas Bellinger 631c66ac9dbSNicholas Bellinger DEF_DEV_ATTRIB(emulate_tas); 632c66ac9dbSNicholas Bellinger SE_DEV_ATTR(emulate_tas, S_IRUGO | S_IWUSR); 633c66ac9dbSNicholas Bellinger 634c66ac9dbSNicholas Bellinger DEF_DEV_ATTRIB(emulate_tpu); 635c66ac9dbSNicholas Bellinger SE_DEV_ATTR(emulate_tpu, S_IRUGO | S_IWUSR); 636c66ac9dbSNicholas Bellinger 637c66ac9dbSNicholas Bellinger DEF_DEV_ATTRIB(emulate_tpws); 638c66ac9dbSNicholas Bellinger SE_DEV_ATTR(emulate_tpws, S_IRUGO | S_IWUSR); 639c66ac9dbSNicholas Bellinger 6400123a9ecSNicholas Bellinger DEF_DEV_ATTRIB(emulate_caw); 6410123a9ecSNicholas Bellinger SE_DEV_ATTR(emulate_caw, S_IRUGO | S_IWUSR); 6420123a9ecSNicholas Bellinger 643d397a445SNicholas Bellinger DEF_DEV_ATTRIB(emulate_3pc); 644d397a445SNicholas Bellinger SE_DEV_ATTR(emulate_3pc, S_IRUGO | S_IWUSR); 645d397a445SNicholas Bellinger 646c66ac9dbSNicholas Bellinger DEF_DEV_ATTRIB(enforce_pr_isids); 647c66ac9dbSNicholas Bellinger SE_DEV_ATTR(enforce_pr_isids, S_IRUGO | S_IWUSR); 648c66ac9dbSNicholas Bellinger 649e22a7f07SRoland Dreier DEF_DEV_ATTRIB(is_nonrot); 650e22a7f07SRoland Dreier SE_DEV_ATTR(is_nonrot, S_IRUGO | S_IWUSR); 651e22a7f07SRoland Dreier 6525de619a3SNicholas Bellinger DEF_DEV_ATTRIB(emulate_rest_reord); 6535de619a3SNicholas Bellinger SE_DEV_ATTR(emulate_rest_reord, S_IRUGO | S_IWUSR); 6545de619a3SNicholas Bellinger 655c66ac9dbSNicholas Bellinger DEF_DEV_ATTRIB_RO(hw_block_size); 656c66ac9dbSNicholas Bellinger SE_DEV_ATTR_RO(hw_block_size); 657c66ac9dbSNicholas Bellinger 658c66ac9dbSNicholas Bellinger DEF_DEV_ATTRIB(block_size); 659c66ac9dbSNicholas Bellinger SE_DEV_ATTR(block_size, S_IRUGO | S_IWUSR); 660c66ac9dbSNicholas Bellinger 661c66ac9dbSNicholas Bellinger DEF_DEV_ATTRIB_RO(hw_max_sectors); 662c66ac9dbSNicholas Bellinger SE_DEV_ATTR_RO(hw_max_sectors); 663c66ac9dbSNicholas Bellinger 664015487b8SRoland Dreier DEF_DEV_ATTRIB(fabric_max_sectors); 665015487b8SRoland Dreier SE_DEV_ATTR(fabric_max_sectors, S_IRUGO | S_IWUSR); 666015487b8SRoland Dreier 667c66ac9dbSNicholas Bellinger DEF_DEV_ATTRIB(optimal_sectors); 668c66ac9dbSNicholas Bellinger SE_DEV_ATTR(optimal_sectors, S_IRUGO | S_IWUSR); 669c66ac9dbSNicholas Bellinger 670c66ac9dbSNicholas Bellinger DEF_DEV_ATTRIB_RO(hw_queue_depth); 671c66ac9dbSNicholas Bellinger SE_DEV_ATTR_RO(hw_queue_depth); 672c66ac9dbSNicholas Bellinger 673c66ac9dbSNicholas Bellinger DEF_DEV_ATTRIB(queue_depth); 674c66ac9dbSNicholas Bellinger SE_DEV_ATTR(queue_depth, S_IRUGO | S_IWUSR); 675c66ac9dbSNicholas Bellinger 676c66ac9dbSNicholas Bellinger DEF_DEV_ATTRIB(max_unmap_lba_count); 677c66ac9dbSNicholas Bellinger SE_DEV_ATTR(max_unmap_lba_count, S_IRUGO | S_IWUSR); 678c66ac9dbSNicholas Bellinger 679c66ac9dbSNicholas Bellinger DEF_DEV_ATTRIB(max_unmap_block_desc_count); 680c66ac9dbSNicholas Bellinger SE_DEV_ATTR(max_unmap_block_desc_count, S_IRUGO | S_IWUSR); 681c66ac9dbSNicholas Bellinger 682c66ac9dbSNicholas Bellinger DEF_DEV_ATTRIB(unmap_granularity); 683c66ac9dbSNicholas Bellinger SE_DEV_ATTR(unmap_granularity, S_IRUGO | S_IWUSR); 684c66ac9dbSNicholas Bellinger 685c66ac9dbSNicholas Bellinger DEF_DEV_ATTRIB(unmap_granularity_alignment); 686c66ac9dbSNicholas Bellinger SE_DEV_ATTR(unmap_granularity_alignment, S_IRUGO | S_IWUSR); 687c66ac9dbSNicholas Bellinger 688773cbaf7SNicholas Bellinger DEF_DEV_ATTRIB(max_write_same_len); 689773cbaf7SNicholas Bellinger SE_DEV_ATTR(max_write_same_len, S_IRUGO | S_IWUSR); 690773cbaf7SNicholas Bellinger 691c66ac9dbSNicholas Bellinger CONFIGFS_EATTR_OPS(target_core_dev_attrib, se_dev_attrib, da_group); 692c66ac9dbSNicholas Bellinger 693c66ac9dbSNicholas Bellinger static struct configfs_attribute *target_core_dev_attrib_attrs[] = { 694adfa9570STregaron Bayly &target_core_dev_attrib_emulate_model_alias.attr, 695c66ac9dbSNicholas Bellinger &target_core_dev_attrib_emulate_dpo.attr, 696c66ac9dbSNicholas Bellinger &target_core_dev_attrib_emulate_fua_write.attr, 697c66ac9dbSNicholas Bellinger &target_core_dev_attrib_emulate_fua_read.attr, 698c66ac9dbSNicholas Bellinger &target_core_dev_attrib_emulate_write_cache.attr, 699c66ac9dbSNicholas Bellinger &target_core_dev_attrib_emulate_ua_intlck_ctrl.attr, 700c66ac9dbSNicholas Bellinger &target_core_dev_attrib_emulate_tas.attr, 701c66ac9dbSNicholas Bellinger &target_core_dev_attrib_emulate_tpu.attr, 702c66ac9dbSNicholas Bellinger &target_core_dev_attrib_emulate_tpws.attr, 7030123a9ecSNicholas Bellinger &target_core_dev_attrib_emulate_caw.attr, 704d397a445SNicholas Bellinger &target_core_dev_attrib_emulate_3pc.attr, 705c66ac9dbSNicholas Bellinger &target_core_dev_attrib_enforce_pr_isids.attr, 706e22a7f07SRoland Dreier &target_core_dev_attrib_is_nonrot.attr, 7075de619a3SNicholas Bellinger &target_core_dev_attrib_emulate_rest_reord.attr, 708c66ac9dbSNicholas Bellinger &target_core_dev_attrib_hw_block_size.attr, 709c66ac9dbSNicholas Bellinger &target_core_dev_attrib_block_size.attr, 710c66ac9dbSNicholas Bellinger &target_core_dev_attrib_hw_max_sectors.attr, 711015487b8SRoland Dreier &target_core_dev_attrib_fabric_max_sectors.attr, 712c66ac9dbSNicholas Bellinger &target_core_dev_attrib_optimal_sectors.attr, 713c66ac9dbSNicholas Bellinger &target_core_dev_attrib_hw_queue_depth.attr, 714c66ac9dbSNicholas Bellinger &target_core_dev_attrib_queue_depth.attr, 715c66ac9dbSNicholas Bellinger &target_core_dev_attrib_max_unmap_lba_count.attr, 716c66ac9dbSNicholas Bellinger &target_core_dev_attrib_max_unmap_block_desc_count.attr, 717c66ac9dbSNicholas Bellinger &target_core_dev_attrib_unmap_granularity.attr, 718c66ac9dbSNicholas Bellinger &target_core_dev_attrib_unmap_granularity_alignment.attr, 719773cbaf7SNicholas Bellinger &target_core_dev_attrib_max_write_same_len.attr, 720c66ac9dbSNicholas Bellinger NULL, 721c66ac9dbSNicholas Bellinger }; 722c66ac9dbSNicholas Bellinger 723c66ac9dbSNicholas Bellinger static struct configfs_item_operations target_core_dev_attrib_ops = { 724c66ac9dbSNicholas Bellinger .show_attribute = target_core_dev_attrib_attr_show, 725c66ac9dbSNicholas Bellinger .store_attribute = target_core_dev_attrib_attr_store, 726c66ac9dbSNicholas Bellinger }; 727c66ac9dbSNicholas Bellinger 728c66ac9dbSNicholas Bellinger static struct config_item_type target_core_dev_attrib_cit = { 729c66ac9dbSNicholas Bellinger .ct_item_ops = &target_core_dev_attrib_ops, 730c66ac9dbSNicholas Bellinger .ct_attrs = target_core_dev_attrib_attrs, 731c66ac9dbSNicholas Bellinger .ct_owner = THIS_MODULE, 732c66ac9dbSNicholas Bellinger }; 733c66ac9dbSNicholas Bellinger 734c66ac9dbSNicholas Bellinger /* End functions for struct config_item_type target_core_dev_attrib_cit */ 735c66ac9dbSNicholas Bellinger 736c66ac9dbSNicholas Bellinger /* Start functions for struct config_item_type target_core_dev_wwn_cit */ 737c66ac9dbSNicholas Bellinger 738c66ac9dbSNicholas Bellinger CONFIGFS_EATTR_STRUCT(target_core_dev_wwn, t10_wwn); 739c66ac9dbSNicholas Bellinger #define SE_DEV_WWN_ATTR(_name, _mode) \ 740c66ac9dbSNicholas Bellinger static struct target_core_dev_wwn_attribute target_core_dev_wwn_##_name = \ 741c66ac9dbSNicholas Bellinger __CONFIGFS_EATTR(_name, _mode, \ 742c66ac9dbSNicholas Bellinger target_core_dev_wwn_show_attr_##_name, \ 743c66ac9dbSNicholas Bellinger target_core_dev_wwn_store_attr_##_name); 744c66ac9dbSNicholas Bellinger 745c66ac9dbSNicholas Bellinger #define SE_DEV_WWN_ATTR_RO(_name); \ 746c66ac9dbSNicholas Bellinger do { \ 747c66ac9dbSNicholas Bellinger static struct target_core_dev_wwn_attribute \ 748c66ac9dbSNicholas Bellinger target_core_dev_wwn_##_name = \ 749c66ac9dbSNicholas Bellinger __CONFIGFS_EATTR_RO(_name, \ 750c66ac9dbSNicholas Bellinger target_core_dev_wwn_show_attr_##_name); \ 751c66ac9dbSNicholas Bellinger } while (0); 752c66ac9dbSNicholas Bellinger 753c66ac9dbSNicholas Bellinger /* 754c66ac9dbSNicholas Bellinger * VPD page 0x80 Unit serial 755c66ac9dbSNicholas Bellinger */ 756c66ac9dbSNicholas Bellinger static ssize_t target_core_dev_wwn_show_attr_vpd_unit_serial( 757c66ac9dbSNicholas Bellinger struct t10_wwn *t10_wwn, 758c66ac9dbSNicholas Bellinger char *page) 759c66ac9dbSNicholas Bellinger { 760c66ac9dbSNicholas Bellinger return sprintf(page, "T10 VPD Unit Serial Number: %s\n", 761c66ac9dbSNicholas Bellinger &t10_wwn->unit_serial[0]); 762c66ac9dbSNicholas Bellinger } 763c66ac9dbSNicholas Bellinger 764c66ac9dbSNicholas Bellinger static ssize_t target_core_dev_wwn_store_attr_vpd_unit_serial( 765c66ac9dbSNicholas Bellinger struct t10_wwn *t10_wwn, 766c66ac9dbSNicholas Bellinger const char *page, 767c66ac9dbSNicholas Bellinger size_t count) 768c66ac9dbSNicholas Bellinger { 7690fd97ccfSChristoph Hellwig struct se_device *dev = t10_wwn->t10_dev; 770c66ac9dbSNicholas Bellinger unsigned char buf[INQUIRY_VPD_SERIAL_LEN]; 771c66ac9dbSNicholas Bellinger 772c66ac9dbSNicholas Bellinger /* 773c66ac9dbSNicholas Bellinger * If Linux/SCSI subsystem_api_t plugin got a VPD Unit Serial 774c66ac9dbSNicholas Bellinger * from the struct scsi_device level firmware, do not allow 775c66ac9dbSNicholas Bellinger * VPD Unit Serial to be emulated. 776c66ac9dbSNicholas Bellinger * 777c66ac9dbSNicholas Bellinger * Note this struct scsi_device could also be emulating VPD 778c66ac9dbSNicholas Bellinger * information from its drivers/scsi LLD. But for now we assume 779c66ac9dbSNicholas Bellinger * it is doing 'the right thing' wrt a world wide unique 780c66ac9dbSNicholas Bellinger * VPD Unit Serial Number that OS dependent multipath can depend on. 781c66ac9dbSNicholas Bellinger */ 7820fd97ccfSChristoph Hellwig if (dev->dev_flags & DF_FIRMWARE_VPD_UNIT_SERIAL) { 7836708bb27SAndy Grover pr_err("Underlying SCSI device firmware provided VPD" 784c66ac9dbSNicholas Bellinger " Unit Serial, ignoring request\n"); 785c66ac9dbSNicholas Bellinger return -EOPNOTSUPP; 786c66ac9dbSNicholas Bellinger } 787c66ac9dbSNicholas Bellinger 78860d645a4SDan Carpenter if (strlen(page) >= INQUIRY_VPD_SERIAL_LEN) { 7896708bb27SAndy Grover pr_err("Emulated VPD Unit Serial exceeds" 790c66ac9dbSNicholas Bellinger " INQUIRY_VPD_SERIAL_LEN: %d\n", INQUIRY_VPD_SERIAL_LEN); 791c66ac9dbSNicholas Bellinger return -EOVERFLOW; 792c66ac9dbSNicholas Bellinger } 793c66ac9dbSNicholas Bellinger /* 794c66ac9dbSNicholas Bellinger * Check to see if any active $FABRIC_MOD exports exist. If they 795c66ac9dbSNicholas Bellinger * do exist, fail here as changing this information on the fly 796c66ac9dbSNicholas Bellinger * (underneath the initiator side OS dependent multipath code) 797c66ac9dbSNicholas Bellinger * could cause negative effects. 798c66ac9dbSNicholas Bellinger */ 7990fd97ccfSChristoph Hellwig if (dev->export_count) { 8006708bb27SAndy Grover pr_err("Unable to set VPD Unit Serial while" 801c66ac9dbSNicholas Bellinger " active %d $FABRIC_MOD exports exist\n", 8020fd97ccfSChristoph Hellwig dev->export_count); 803c66ac9dbSNicholas Bellinger return -EINVAL; 804c66ac9dbSNicholas Bellinger } 8050fd97ccfSChristoph Hellwig 806c66ac9dbSNicholas Bellinger /* 807c66ac9dbSNicholas Bellinger * This currently assumes ASCII encoding for emulated VPD Unit Serial. 808c66ac9dbSNicholas Bellinger * 809c66ac9dbSNicholas Bellinger * Also, strip any newline added from the userspace 810c66ac9dbSNicholas Bellinger * echo $UUID > $TARGET/$HBA/$STORAGE_OBJECT/wwn/vpd_unit_serial 811c66ac9dbSNicholas Bellinger */ 812c66ac9dbSNicholas Bellinger memset(buf, 0, INQUIRY_VPD_SERIAL_LEN); 813c66ac9dbSNicholas Bellinger snprintf(buf, INQUIRY_VPD_SERIAL_LEN, "%s", page); 8140fd97ccfSChristoph Hellwig snprintf(dev->t10_wwn.unit_serial, INQUIRY_VPD_SERIAL_LEN, 815c66ac9dbSNicholas Bellinger "%s", strstrip(buf)); 8160fd97ccfSChristoph Hellwig dev->dev_flags |= DF_EMULATED_VPD_UNIT_SERIAL; 817c66ac9dbSNicholas Bellinger 8186708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: Set emulated VPD Unit Serial:" 8190fd97ccfSChristoph Hellwig " %s\n", dev->t10_wwn.unit_serial); 820c66ac9dbSNicholas Bellinger 821c66ac9dbSNicholas Bellinger return count; 822c66ac9dbSNicholas Bellinger } 823c66ac9dbSNicholas Bellinger 824c66ac9dbSNicholas Bellinger SE_DEV_WWN_ATTR(vpd_unit_serial, S_IRUGO | S_IWUSR); 825c66ac9dbSNicholas Bellinger 826c66ac9dbSNicholas Bellinger /* 827c66ac9dbSNicholas Bellinger * VPD page 0x83 Protocol Identifier 828c66ac9dbSNicholas Bellinger */ 829c66ac9dbSNicholas Bellinger static ssize_t target_core_dev_wwn_show_attr_vpd_protocol_identifier( 830c66ac9dbSNicholas Bellinger struct t10_wwn *t10_wwn, 831c66ac9dbSNicholas Bellinger char *page) 832c66ac9dbSNicholas Bellinger { 833c66ac9dbSNicholas Bellinger struct t10_vpd *vpd; 834c66ac9dbSNicholas Bellinger unsigned char buf[VPD_TMP_BUF_SIZE]; 835c66ac9dbSNicholas Bellinger ssize_t len = 0; 836c66ac9dbSNicholas Bellinger 837c66ac9dbSNicholas Bellinger memset(buf, 0, VPD_TMP_BUF_SIZE); 838c66ac9dbSNicholas Bellinger 839c66ac9dbSNicholas Bellinger spin_lock(&t10_wwn->t10_vpd_lock); 840c66ac9dbSNicholas Bellinger list_for_each_entry(vpd, &t10_wwn->t10_vpd_list, vpd_list) { 8416708bb27SAndy Grover if (!vpd->protocol_identifier_set) 842c66ac9dbSNicholas Bellinger continue; 843c66ac9dbSNicholas Bellinger 844c66ac9dbSNicholas Bellinger transport_dump_vpd_proto_id(vpd, buf, VPD_TMP_BUF_SIZE); 845c66ac9dbSNicholas Bellinger 8466708bb27SAndy Grover if (len + strlen(buf) >= PAGE_SIZE) 847c66ac9dbSNicholas Bellinger break; 848c66ac9dbSNicholas Bellinger 849c66ac9dbSNicholas Bellinger len += sprintf(page+len, "%s", buf); 850c66ac9dbSNicholas Bellinger } 851c66ac9dbSNicholas Bellinger spin_unlock(&t10_wwn->t10_vpd_lock); 852c66ac9dbSNicholas Bellinger 853c66ac9dbSNicholas Bellinger return len; 854c66ac9dbSNicholas Bellinger } 855c66ac9dbSNicholas Bellinger 856c66ac9dbSNicholas Bellinger static ssize_t target_core_dev_wwn_store_attr_vpd_protocol_identifier( 857c66ac9dbSNicholas Bellinger struct t10_wwn *t10_wwn, 858c66ac9dbSNicholas Bellinger const char *page, 859c66ac9dbSNicholas Bellinger size_t count) 860c66ac9dbSNicholas Bellinger { 861c66ac9dbSNicholas Bellinger return -ENOSYS; 862c66ac9dbSNicholas Bellinger } 863c66ac9dbSNicholas Bellinger 864c66ac9dbSNicholas Bellinger SE_DEV_WWN_ATTR(vpd_protocol_identifier, S_IRUGO | S_IWUSR); 865c66ac9dbSNicholas Bellinger 866c66ac9dbSNicholas Bellinger /* 867c66ac9dbSNicholas Bellinger * Generic wrapper for dumping VPD identifiers by association. 868c66ac9dbSNicholas Bellinger */ 869c66ac9dbSNicholas Bellinger #define DEF_DEV_WWN_ASSOC_SHOW(_name, _assoc) \ 870c66ac9dbSNicholas Bellinger static ssize_t target_core_dev_wwn_show_attr_##_name( \ 871c66ac9dbSNicholas Bellinger struct t10_wwn *t10_wwn, \ 872c66ac9dbSNicholas Bellinger char *page) \ 873c66ac9dbSNicholas Bellinger { \ 874c66ac9dbSNicholas Bellinger struct t10_vpd *vpd; \ 875c66ac9dbSNicholas Bellinger unsigned char buf[VPD_TMP_BUF_SIZE]; \ 876c66ac9dbSNicholas Bellinger ssize_t len = 0; \ 877c66ac9dbSNicholas Bellinger \ 878c66ac9dbSNicholas Bellinger spin_lock(&t10_wwn->t10_vpd_lock); \ 879c66ac9dbSNicholas Bellinger list_for_each_entry(vpd, &t10_wwn->t10_vpd_list, vpd_list) { \ 880c66ac9dbSNicholas Bellinger if (vpd->association != _assoc) \ 881c66ac9dbSNicholas Bellinger continue; \ 882c66ac9dbSNicholas Bellinger \ 883c66ac9dbSNicholas Bellinger memset(buf, 0, VPD_TMP_BUF_SIZE); \ 884c66ac9dbSNicholas Bellinger transport_dump_vpd_assoc(vpd, buf, VPD_TMP_BUF_SIZE); \ 8856708bb27SAndy Grover if (len + strlen(buf) >= PAGE_SIZE) \ 886c66ac9dbSNicholas Bellinger break; \ 887c66ac9dbSNicholas Bellinger len += sprintf(page+len, "%s", buf); \ 888c66ac9dbSNicholas Bellinger \ 889c66ac9dbSNicholas Bellinger memset(buf, 0, VPD_TMP_BUF_SIZE); \ 890c66ac9dbSNicholas Bellinger transport_dump_vpd_ident_type(vpd, buf, VPD_TMP_BUF_SIZE); \ 8916708bb27SAndy Grover if (len + strlen(buf) >= PAGE_SIZE) \ 892c66ac9dbSNicholas Bellinger break; \ 893c66ac9dbSNicholas Bellinger len += sprintf(page+len, "%s", buf); \ 894c66ac9dbSNicholas Bellinger \ 895c66ac9dbSNicholas Bellinger memset(buf, 0, VPD_TMP_BUF_SIZE); \ 896c66ac9dbSNicholas Bellinger transport_dump_vpd_ident(vpd, buf, VPD_TMP_BUF_SIZE); \ 8976708bb27SAndy Grover if (len + strlen(buf) >= PAGE_SIZE) \ 898c66ac9dbSNicholas Bellinger break; \ 899c66ac9dbSNicholas Bellinger len += sprintf(page+len, "%s", buf); \ 900c66ac9dbSNicholas Bellinger } \ 901c66ac9dbSNicholas Bellinger spin_unlock(&t10_wwn->t10_vpd_lock); \ 902c66ac9dbSNicholas Bellinger \ 903c66ac9dbSNicholas Bellinger return len; \ 904c66ac9dbSNicholas Bellinger } 905c66ac9dbSNicholas Bellinger 906c66ac9dbSNicholas Bellinger /* 907163cd5faSAndy Shevchenko * VPD page 0x83 Association: Logical Unit 908c66ac9dbSNicholas Bellinger */ 909c66ac9dbSNicholas Bellinger DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_logical_unit, 0x00); 910c66ac9dbSNicholas Bellinger 911c66ac9dbSNicholas Bellinger static ssize_t target_core_dev_wwn_store_attr_vpd_assoc_logical_unit( 912c66ac9dbSNicholas Bellinger struct t10_wwn *t10_wwn, 913c66ac9dbSNicholas Bellinger const char *page, 914c66ac9dbSNicholas Bellinger size_t count) 915c66ac9dbSNicholas Bellinger { 916c66ac9dbSNicholas Bellinger return -ENOSYS; 917c66ac9dbSNicholas Bellinger } 918c66ac9dbSNicholas Bellinger 919c66ac9dbSNicholas Bellinger SE_DEV_WWN_ATTR(vpd_assoc_logical_unit, S_IRUGO | S_IWUSR); 920c66ac9dbSNicholas Bellinger 921c66ac9dbSNicholas Bellinger /* 922c66ac9dbSNicholas Bellinger * VPD page 0x83 Association: Target Port 923c66ac9dbSNicholas Bellinger */ 924c66ac9dbSNicholas Bellinger DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_target_port, 0x10); 925c66ac9dbSNicholas Bellinger 926c66ac9dbSNicholas Bellinger static ssize_t target_core_dev_wwn_store_attr_vpd_assoc_target_port( 927c66ac9dbSNicholas Bellinger struct t10_wwn *t10_wwn, 928c66ac9dbSNicholas Bellinger const char *page, 929c66ac9dbSNicholas Bellinger size_t count) 930c66ac9dbSNicholas Bellinger { 931c66ac9dbSNicholas Bellinger return -ENOSYS; 932c66ac9dbSNicholas Bellinger } 933c66ac9dbSNicholas Bellinger 934c66ac9dbSNicholas Bellinger SE_DEV_WWN_ATTR(vpd_assoc_target_port, S_IRUGO | S_IWUSR); 935c66ac9dbSNicholas Bellinger 936c66ac9dbSNicholas Bellinger /* 937c66ac9dbSNicholas Bellinger * VPD page 0x83 Association: SCSI Target Device 938c66ac9dbSNicholas Bellinger */ 939c66ac9dbSNicholas Bellinger DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_scsi_target_device, 0x20); 940c66ac9dbSNicholas Bellinger 941c66ac9dbSNicholas Bellinger static ssize_t target_core_dev_wwn_store_attr_vpd_assoc_scsi_target_device( 942c66ac9dbSNicholas Bellinger struct t10_wwn *t10_wwn, 943c66ac9dbSNicholas Bellinger const char *page, 944c66ac9dbSNicholas Bellinger size_t count) 945c66ac9dbSNicholas Bellinger { 946c66ac9dbSNicholas Bellinger return -ENOSYS; 947c66ac9dbSNicholas Bellinger } 948c66ac9dbSNicholas Bellinger 949c66ac9dbSNicholas Bellinger SE_DEV_WWN_ATTR(vpd_assoc_scsi_target_device, S_IRUGO | S_IWUSR); 950c66ac9dbSNicholas Bellinger 951c66ac9dbSNicholas Bellinger CONFIGFS_EATTR_OPS(target_core_dev_wwn, t10_wwn, t10_wwn_group); 952c66ac9dbSNicholas Bellinger 953c66ac9dbSNicholas Bellinger static struct configfs_attribute *target_core_dev_wwn_attrs[] = { 954c66ac9dbSNicholas Bellinger &target_core_dev_wwn_vpd_unit_serial.attr, 955c66ac9dbSNicholas Bellinger &target_core_dev_wwn_vpd_protocol_identifier.attr, 956c66ac9dbSNicholas Bellinger &target_core_dev_wwn_vpd_assoc_logical_unit.attr, 957c66ac9dbSNicholas Bellinger &target_core_dev_wwn_vpd_assoc_target_port.attr, 958c66ac9dbSNicholas Bellinger &target_core_dev_wwn_vpd_assoc_scsi_target_device.attr, 959c66ac9dbSNicholas Bellinger NULL, 960c66ac9dbSNicholas Bellinger }; 961c66ac9dbSNicholas Bellinger 962c66ac9dbSNicholas Bellinger static struct configfs_item_operations target_core_dev_wwn_ops = { 963c66ac9dbSNicholas Bellinger .show_attribute = target_core_dev_wwn_attr_show, 964c66ac9dbSNicholas Bellinger .store_attribute = target_core_dev_wwn_attr_store, 965c66ac9dbSNicholas Bellinger }; 966c66ac9dbSNicholas Bellinger 967c66ac9dbSNicholas Bellinger static struct config_item_type target_core_dev_wwn_cit = { 968c66ac9dbSNicholas Bellinger .ct_item_ops = &target_core_dev_wwn_ops, 969c66ac9dbSNicholas Bellinger .ct_attrs = target_core_dev_wwn_attrs, 970c66ac9dbSNicholas Bellinger .ct_owner = THIS_MODULE, 971c66ac9dbSNicholas Bellinger }; 972c66ac9dbSNicholas Bellinger 973c66ac9dbSNicholas Bellinger /* End functions for struct config_item_type target_core_dev_wwn_cit */ 974c66ac9dbSNicholas Bellinger 975c66ac9dbSNicholas Bellinger /* Start functions for struct config_item_type target_core_dev_pr_cit */ 976c66ac9dbSNicholas Bellinger 9770fd97ccfSChristoph Hellwig CONFIGFS_EATTR_STRUCT(target_core_dev_pr, se_device); 978c66ac9dbSNicholas Bellinger #define SE_DEV_PR_ATTR(_name, _mode) \ 979c66ac9dbSNicholas Bellinger static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \ 980c66ac9dbSNicholas Bellinger __CONFIGFS_EATTR(_name, _mode, \ 981c66ac9dbSNicholas Bellinger target_core_dev_pr_show_attr_##_name, \ 982c66ac9dbSNicholas Bellinger target_core_dev_pr_store_attr_##_name); 983c66ac9dbSNicholas Bellinger 984c66ac9dbSNicholas Bellinger #define SE_DEV_PR_ATTR_RO(_name); \ 985c66ac9dbSNicholas Bellinger static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \ 986c66ac9dbSNicholas Bellinger __CONFIGFS_EATTR_RO(_name, \ 987c66ac9dbSNicholas Bellinger target_core_dev_pr_show_attr_##_name); 988c66ac9dbSNicholas Bellinger 989d977f437SChristoph Hellwig static ssize_t target_core_dev_pr_show_spc3_res(struct se_device *dev, 990d977f437SChristoph Hellwig char *page) 991c66ac9dbSNicholas Bellinger { 992c66ac9dbSNicholas Bellinger struct se_node_acl *se_nacl; 993c66ac9dbSNicholas Bellinger struct t10_pr_registration *pr_reg; 994c66ac9dbSNicholas Bellinger char i_buf[PR_REG_ISID_ID_LEN]; 995c66ac9dbSNicholas Bellinger 996c66ac9dbSNicholas Bellinger memset(i_buf, 0, PR_REG_ISID_ID_LEN); 997c66ac9dbSNicholas Bellinger 998c66ac9dbSNicholas Bellinger pr_reg = dev->dev_pr_res_holder; 999d977f437SChristoph Hellwig if (!pr_reg) 1000d977f437SChristoph Hellwig return sprintf(page, "No SPC-3 Reservation holder\n"); 1001d977f437SChristoph Hellwig 1002c66ac9dbSNicholas Bellinger se_nacl = pr_reg->pr_reg_nacl; 1003d2843c17SAndy Grover core_pr_dump_initiator_port(pr_reg, i_buf, PR_REG_ISID_ID_LEN); 1004c66ac9dbSNicholas Bellinger 1005d977f437SChristoph Hellwig return sprintf(page, "SPC-3 Reservation: %s Initiator: %s%s\n", 1006e3d6f909SAndy Grover se_nacl->se_tpg->se_tpg_tfo->get_fabric_name(), 1007d2843c17SAndy Grover se_nacl->initiatorname, i_buf); 1008c66ac9dbSNicholas Bellinger } 1009c66ac9dbSNicholas Bellinger 1010d977f437SChristoph Hellwig static ssize_t target_core_dev_pr_show_spc2_res(struct se_device *dev, 1011d977f437SChristoph Hellwig char *page) 1012c66ac9dbSNicholas Bellinger { 1013c66ac9dbSNicholas Bellinger struct se_node_acl *se_nacl; 1014d977f437SChristoph Hellwig ssize_t len; 1015c66ac9dbSNicholas Bellinger 1016c66ac9dbSNicholas Bellinger se_nacl = dev->dev_reserved_node_acl; 1017d977f437SChristoph Hellwig if (se_nacl) { 1018d977f437SChristoph Hellwig len = sprintf(page, 1019d977f437SChristoph Hellwig "SPC-2 Reservation: %s Initiator: %s\n", 1020e3d6f909SAndy Grover se_nacl->se_tpg->se_tpg_tfo->get_fabric_name(), 1021c66ac9dbSNicholas Bellinger se_nacl->initiatorname); 1022d977f437SChristoph Hellwig } else { 1023d977f437SChristoph Hellwig len = sprintf(page, "No SPC-2 Reservation holder\n"); 1024d977f437SChristoph Hellwig } 1025d977f437SChristoph Hellwig return len; 1026c66ac9dbSNicholas Bellinger } 1027c66ac9dbSNicholas Bellinger 10280fd97ccfSChristoph Hellwig static ssize_t target_core_dev_pr_show_attr_res_holder(struct se_device *dev, 1029c66ac9dbSNicholas Bellinger char *page) 1030c66ac9dbSNicholas Bellinger { 1031d977f437SChristoph Hellwig int ret; 1032c66ac9dbSNicholas Bellinger 1033d977f437SChristoph Hellwig if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) 1034d977f437SChristoph Hellwig return sprintf(page, "Passthrough\n"); 1035c66ac9dbSNicholas Bellinger 1036d977f437SChristoph Hellwig spin_lock(&dev->dev_reservation_lock); 1037d977f437SChristoph Hellwig if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS) 1038d977f437SChristoph Hellwig ret = target_core_dev_pr_show_spc2_res(dev, page); 1039d977f437SChristoph Hellwig else 1040d977f437SChristoph Hellwig ret = target_core_dev_pr_show_spc3_res(dev, page); 1041d977f437SChristoph Hellwig spin_unlock(&dev->dev_reservation_lock); 1042d977f437SChristoph Hellwig return ret; 1043c66ac9dbSNicholas Bellinger } 1044c66ac9dbSNicholas Bellinger 1045c66ac9dbSNicholas Bellinger SE_DEV_PR_ATTR_RO(res_holder); 1046c66ac9dbSNicholas Bellinger 1047c66ac9dbSNicholas Bellinger static ssize_t target_core_dev_pr_show_attr_res_pr_all_tgt_pts( 10480fd97ccfSChristoph Hellwig struct se_device *dev, char *page) 1049c66ac9dbSNicholas Bellinger { 1050c66ac9dbSNicholas Bellinger ssize_t len = 0; 1051c66ac9dbSNicholas Bellinger 1052c66ac9dbSNicholas Bellinger spin_lock(&dev->dev_reservation_lock); 1053d977f437SChristoph Hellwig if (!dev->dev_pr_res_holder) { 1054c66ac9dbSNicholas Bellinger len = sprintf(page, "No SPC-3 Reservation holder\n"); 1055d977f437SChristoph Hellwig } else if (dev->dev_pr_res_holder->pr_reg_all_tg_pt) { 1056c66ac9dbSNicholas Bellinger len = sprintf(page, "SPC-3 Reservation: All Target" 1057c66ac9dbSNicholas Bellinger " Ports registration\n"); 1058d977f437SChristoph Hellwig } else { 1059c66ac9dbSNicholas Bellinger len = sprintf(page, "SPC-3 Reservation: Single" 1060c66ac9dbSNicholas Bellinger " Target Port registration\n"); 1061d977f437SChristoph Hellwig } 1062c66ac9dbSNicholas Bellinger 1063d977f437SChristoph Hellwig spin_unlock(&dev->dev_reservation_lock); 1064c66ac9dbSNicholas Bellinger return len; 1065c66ac9dbSNicholas Bellinger } 1066c66ac9dbSNicholas Bellinger 1067c66ac9dbSNicholas Bellinger SE_DEV_PR_ATTR_RO(res_pr_all_tgt_pts); 1068c66ac9dbSNicholas Bellinger 1069c66ac9dbSNicholas Bellinger static ssize_t target_core_dev_pr_show_attr_res_pr_generation( 10700fd97ccfSChristoph Hellwig struct se_device *dev, char *page) 1071c66ac9dbSNicholas Bellinger { 10720fd97ccfSChristoph Hellwig return sprintf(page, "0x%08x\n", dev->t10_pr.pr_generation); 1073c66ac9dbSNicholas Bellinger } 1074c66ac9dbSNicholas Bellinger 1075c66ac9dbSNicholas Bellinger SE_DEV_PR_ATTR_RO(res_pr_generation); 1076c66ac9dbSNicholas Bellinger 1077c66ac9dbSNicholas Bellinger /* 1078c66ac9dbSNicholas Bellinger * res_pr_holder_tg_port 1079c66ac9dbSNicholas Bellinger */ 1080c66ac9dbSNicholas Bellinger static ssize_t target_core_dev_pr_show_attr_res_pr_holder_tg_port( 10810fd97ccfSChristoph Hellwig struct se_device *dev, char *page) 1082c66ac9dbSNicholas Bellinger { 1083c66ac9dbSNicholas Bellinger struct se_node_acl *se_nacl; 1084c66ac9dbSNicholas Bellinger struct se_lun *lun; 1085c66ac9dbSNicholas Bellinger struct se_portal_group *se_tpg; 1086c66ac9dbSNicholas Bellinger struct t10_pr_registration *pr_reg; 1087c66ac9dbSNicholas Bellinger struct target_core_fabric_ops *tfo; 1088c66ac9dbSNicholas Bellinger ssize_t len = 0; 1089c66ac9dbSNicholas Bellinger 1090c66ac9dbSNicholas Bellinger spin_lock(&dev->dev_reservation_lock); 1091c66ac9dbSNicholas Bellinger pr_reg = dev->dev_pr_res_holder; 10926708bb27SAndy Grover if (!pr_reg) { 1093c66ac9dbSNicholas Bellinger len = sprintf(page, "No SPC-3 Reservation holder\n"); 1094d977f437SChristoph Hellwig goto out_unlock; 1095c66ac9dbSNicholas Bellinger } 1096d977f437SChristoph Hellwig 1097c66ac9dbSNicholas Bellinger se_nacl = pr_reg->pr_reg_nacl; 1098c66ac9dbSNicholas Bellinger se_tpg = se_nacl->se_tpg; 1099c66ac9dbSNicholas Bellinger lun = pr_reg->pr_reg_tg_pt_lun; 1100e3d6f909SAndy Grover tfo = se_tpg->se_tpg_tfo; 1101c66ac9dbSNicholas Bellinger 1102c66ac9dbSNicholas Bellinger len += sprintf(page+len, "SPC-3 Reservation: %s" 1103c66ac9dbSNicholas Bellinger " Target Node Endpoint: %s\n", tfo->get_fabric_name(), 1104c66ac9dbSNicholas Bellinger tfo->tpg_get_wwn(se_tpg)); 1105c66ac9dbSNicholas Bellinger len += sprintf(page+len, "SPC-3 Reservation: Relative Port" 110635d1efe8SMasanari Iida " Identifier Tag: %hu %s Portal Group Tag: %hu" 1107c66ac9dbSNicholas Bellinger " %s Logical Unit: %u\n", lun->lun_sep->sep_rtpi, 1108c66ac9dbSNicholas Bellinger tfo->get_fabric_name(), tfo->tpg_get_tag(se_tpg), 1109c66ac9dbSNicholas Bellinger tfo->get_fabric_name(), lun->unpacked_lun); 1110c66ac9dbSNicholas Bellinger 1111d977f437SChristoph Hellwig out_unlock: 1112d977f437SChristoph Hellwig spin_unlock(&dev->dev_reservation_lock); 1113c66ac9dbSNicholas Bellinger return len; 1114c66ac9dbSNicholas Bellinger } 1115c66ac9dbSNicholas Bellinger 1116c66ac9dbSNicholas Bellinger SE_DEV_PR_ATTR_RO(res_pr_holder_tg_port); 1117c66ac9dbSNicholas Bellinger 1118c66ac9dbSNicholas Bellinger static ssize_t target_core_dev_pr_show_attr_res_pr_registered_i_pts( 11190fd97ccfSChristoph Hellwig struct se_device *dev, char *page) 1120c66ac9dbSNicholas Bellinger { 1121c66ac9dbSNicholas Bellinger struct target_core_fabric_ops *tfo; 1122c66ac9dbSNicholas Bellinger struct t10_pr_registration *pr_reg; 1123c66ac9dbSNicholas Bellinger unsigned char buf[384]; 1124c66ac9dbSNicholas Bellinger char i_buf[PR_REG_ISID_ID_LEN]; 1125c66ac9dbSNicholas Bellinger ssize_t len = 0; 1126d2843c17SAndy Grover int reg_count = 0; 1127c66ac9dbSNicholas Bellinger 1128c66ac9dbSNicholas Bellinger len += sprintf(page+len, "SPC-3 PR Registrations:\n"); 1129c66ac9dbSNicholas Bellinger 11300fd97ccfSChristoph Hellwig spin_lock(&dev->t10_pr.registration_lock); 11310fd97ccfSChristoph Hellwig list_for_each_entry(pr_reg, &dev->t10_pr.registration_list, 1132c66ac9dbSNicholas Bellinger pr_reg_list) { 1133c66ac9dbSNicholas Bellinger 1134c66ac9dbSNicholas Bellinger memset(buf, 0, 384); 1135c66ac9dbSNicholas Bellinger memset(i_buf, 0, PR_REG_ISID_ID_LEN); 1136c66ac9dbSNicholas Bellinger tfo = pr_reg->pr_reg_nacl->se_tpg->se_tpg_tfo; 1137d2843c17SAndy Grover core_pr_dump_initiator_port(pr_reg, i_buf, 1138c66ac9dbSNicholas Bellinger PR_REG_ISID_ID_LEN); 1139c66ac9dbSNicholas Bellinger sprintf(buf, "%s Node: %s%s Key: 0x%016Lx PRgen: 0x%08x\n", 1140c66ac9dbSNicholas Bellinger tfo->get_fabric_name(), 1141d2843c17SAndy Grover pr_reg->pr_reg_nacl->initiatorname, i_buf, pr_reg->pr_res_key, 1142c66ac9dbSNicholas Bellinger pr_reg->pr_res_generation); 1143c66ac9dbSNicholas Bellinger 11446708bb27SAndy Grover if (len + strlen(buf) >= PAGE_SIZE) 1145c66ac9dbSNicholas Bellinger break; 1146c66ac9dbSNicholas Bellinger 1147c66ac9dbSNicholas Bellinger len += sprintf(page+len, "%s", buf); 1148c66ac9dbSNicholas Bellinger reg_count++; 1149c66ac9dbSNicholas Bellinger } 11500fd97ccfSChristoph Hellwig spin_unlock(&dev->t10_pr.registration_lock); 1151c66ac9dbSNicholas Bellinger 11526708bb27SAndy Grover if (!reg_count) 1153c66ac9dbSNicholas Bellinger len += sprintf(page+len, "None\n"); 1154c66ac9dbSNicholas Bellinger 1155c66ac9dbSNicholas Bellinger return len; 1156c66ac9dbSNicholas Bellinger } 1157c66ac9dbSNicholas Bellinger 1158c66ac9dbSNicholas Bellinger SE_DEV_PR_ATTR_RO(res_pr_registered_i_pts); 1159c66ac9dbSNicholas Bellinger 1160c66ac9dbSNicholas Bellinger static ssize_t target_core_dev_pr_show_attr_res_pr_type( 11610fd97ccfSChristoph Hellwig struct se_device *dev, char *page) 1162c66ac9dbSNicholas Bellinger { 1163c66ac9dbSNicholas Bellinger struct t10_pr_registration *pr_reg; 1164c66ac9dbSNicholas Bellinger ssize_t len = 0; 1165c66ac9dbSNicholas Bellinger 1166c66ac9dbSNicholas Bellinger spin_lock(&dev->dev_reservation_lock); 1167c66ac9dbSNicholas Bellinger pr_reg = dev->dev_pr_res_holder; 1168d977f437SChristoph Hellwig if (pr_reg) { 1169c66ac9dbSNicholas Bellinger len = sprintf(page, "SPC-3 Reservation Type: %s\n", 1170c66ac9dbSNicholas Bellinger core_scsi3_pr_dump_type(pr_reg->pr_res_type)); 1171d977f437SChristoph Hellwig } else { 1172d977f437SChristoph Hellwig len = sprintf(page, "No SPC-3 Reservation holder\n"); 1173d977f437SChristoph Hellwig } 1174c66ac9dbSNicholas Bellinger 1175d977f437SChristoph Hellwig spin_unlock(&dev->dev_reservation_lock); 1176c66ac9dbSNicholas Bellinger return len; 1177c66ac9dbSNicholas Bellinger } 1178c66ac9dbSNicholas Bellinger 1179c66ac9dbSNicholas Bellinger SE_DEV_PR_ATTR_RO(res_pr_type); 1180c66ac9dbSNicholas Bellinger 1181c66ac9dbSNicholas Bellinger static ssize_t target_core_dev_pr_show_attr_res_type( 11820fd97ccfSChristoph Hellwig struct se_device *dev, char *page) 1183c66ac9dbSNicholas Bellinger { 1184d977f437SChristoph Hellwig if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) 1185d977f437SChristoph Hellwig return sprintf(page, "SPC_PASSTHROUGH\n"); 1186d977f437SChristoph Hellwig else if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS) 1187d977f437SChristoph Hellwig return sprintf(page, "SPC2_RESERVATIONS\n"); 1188d977f437SChristoph Hellwig else 1189d977f437SChristoph Hellwig return sprintf(page, "SPC3_PERSISTENT_RESERVATIONS\n"); 1190c66ac9dbSNicholas Bellinger } 1191c66ac9dbSNicholas Bellinger 1192c66ac9dbSNicholas Bellinger SE_DEV_PR_ATTR_RO(res_type); 1193c66ac9dbSNicholas Bellinger 1194c66ac9dbSNicholas Bellinger static ssize_t target_core_dev_pr_show_attr_res_aptpl_active( 11950fd97ccfSChristoph Hellwig struct se_device *dev, char *page) 1196c66ac9dbSNicholas Bellinger { 1197d977f437SChristoph Hellwig if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) 1198c66ac9dbSNicholas Bellinger return 0; 1199c66ac9dbSNicholas Bellinger 1200c66ac9dbSNicholas Bellinger return sprintf(page, "APTPL Bit Status: %s\n", 12010fd97ccfSChristoph Hellwig (dev->t10_pr.pr_aptpl_active) ? "Activated" : "Disabled"); 1202c66ac9dbSNicholas Bellinger } 1203c66ac9dbSNicholas Bellinger 1204c66ac9dbSNicholas Bellinger SE_DEV_PR_ATTR_RO(res_aptpl_active); 1205c66ac9dbSNicholas Bellinger 1206c66ac9dbSNicholas Bellinger /* 1207c66ac9dbSNicholas Bellinger * res_aptpl_metadata 1208c66ac9dbSNicholas Bellinger */ 1209c66ac9dbSNicholas Bellinger static ssize_t target_core_dev_pr_show_attr_res_aptpl_metadata( 12100fd97ccfSChristoph Hellwig struct se_device *dev, char *page) 1211c66ac9dbSNicholas Bellinger { 1212d977f437SChristoph Hellwig if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) 1213c66ac9dbSNicholas Bellinger return 0; 1214c66ac9dbSNicholas Bellinger 1215c66ac9dbSNicholas Bellinger return sprintf(page, "Ready to process PR APTPL metadata..\n"); 1216c66ac9dbSNicholas Bellinger } 1217c66ac9dbSNicholas Bellinger 1218c66ac9dbSNicholas Bellinger enum { 1219c66ac9dbSNicholas Bellinger Opt_initiator_fabric, Opt_initiator_node, Opt_initiator_sid, 1220c66ac9dbSNicholas Bellinger Opt_sa_res_key, Opt_res_holder, Opt_res_type, Opt_res_scope, 1221c66ac9dbSNicholas Bellinger Opt_res_all_tg_pt, Opt_mapped_lun, Opt_target_fabric, 1222c66ac9dbSNicholas Bellinger Opt_target_node, Opt_tpgt, Opt_port_rtpi, Opt_target_lun, Opt_err 1223c66ac9dbSNicholas Bellinger }; 1224c66ac9dbSNicholas Bellinger 1225c66ac9dbSNicholas Bellinger static match_table_t tokens = { 1226c66ac9dbSNicholas Bellinger {Opt_initiator_fabric, "initiator_fabric=%s"}, 1227c66ac9dbSNicholas Bellinger {Opt_initiator_node, "initiator_node=%s"}, 1228c66ac9dbSNicholas Bellinger {Opt_initiator_sid, "initiator_sid=%s"}, 1229c66ac9dbSNicholas Bellinger {Opt_sa_res_key, "sa_res_key=%s"}, 1230c66ac9dbSNicholas Bellinger {Opt_res_holder, "res_holder=%d"}, 1231c66ac9dbSNicholas Bellinger {Opt_res_type, "res_type=%d"}, 1232c66ac9dbSNicholas Bellinger {Opt_res_scope, "res_scope=%d"}, 1233c66ac9dbSNicholas Bellinger {Opt_res_all_tg_pt, "res_all_tg_pt=%d"}, 1234c66ac9dbSNicholas Bellinger {Opt_mapped_lun, "mapped_lun=%d"}, 1235c66ac9dbSNicholas Bellinger {Opt_target_fabric, "target_fabric=%s"}, 1236c66ac9dbSNicholas Bellinger {Opt_target_node, "target_node=%s"}, 1237c66ac9dbSNicholas Bellinger {Opt_tpgt, "tpgt=%d"}, 1238c66ac9dbSNicholas Bellinger {Opt_port_rtpi, "port_rtpi=%d"}, 1239c66ac9dbSNicholas Bellinger {Opt_target_lun, "target_lun=%d"}, 1240c66ac9dbSNicholas Bellinger {Opt_err, NULL} 1241c66ac9dbSNicholas Bellinger }; 1242c66ac9dbSNicholas Bellinger 1243c66ac9dbSNicholas Bellinger static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata( 12440fd97ccfSChristoph Hellwig struct se_device *dev, 1245c66ac9dbSNicholas Bellinger const char *page, 1246c66ac9dbSNicholas Bellinger size_t count) 1247c66ac9dbSNicholas Bellinger { 12486d180253SJesper Juhl unsigned char *i_fabric = NULL, *i_port = NULL, *isid = NULL; 12496d180253SJesper Juhl unsigned char *t_fabric = NULL, *t_port = NULL; 1250c66ac9dbSNicholas Bellinger char *orig, *ptr, *arg_p, *opts; 1251c66ac9dbSNicholas Bellinger substring_t args[MAX_OPT_ARGS]; 1252c66ac9dbSNicholas Bellinger unsigned long long tmp_ll; 1253c66ac9dbSNicholas Bellinger u64 sa_res_key = 0; 1254c66ac9dbSNicholas Bellinger u32 mapped_lun = 0, target_lun = 0; 1255c66ac9dbSNicholas Bellinger int ret = -1, res_holder = 0, all_tg_pt = 0, arg, token; 1256c66ac9dbSNicholas Bellinger u16 port_rpti = 0, tpgt = 0; 1257c66ac9dbSNicholas Bellinger u8 type = 0, scope; 1258c66ac9dbSNicholas Bellinger 1259d977f437SChristoph Hellwig if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) 1260d977f437SChristoph Hellwig return 0; 1261d977f437SChristoph Hellwig if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS) 1262c66ac9dbSNicholas Bellinger return 0; 1263c66ac9dbSNicholas Bellinger 12640fd97ccfSChristoph Hellwig if (dev->export_count) { 12656708bb27SAndy Grover pr_debug("Unable to process APTPL metadata while" 1266c66ac9dbSNicholas Bellinger " active fabric exports exist\n"); 1267c66ac9dbSNicholas Bellinger return -EINVAL; 1268c66ac9dbSNicholas Bellinger } 1269c66ac9dbSNicholas Bellinger 1270c66ac9dbSNicholas Bellinger opts = kstrdup(page, GFP_KERNEL); 1271c66ac9dbSNicholas Bellinger if (!opts) 1272c66ac9dbSNicholas Bellinger return -ENOMEM; 1273c66ac9dbSNicholas Bellinger 1274c66ac9dbSNicholas Bellinger orig = opts; 127590c161b6SSebastian Andrzej Siewior while ((ptr = strsep(&opts, ",\n")) != NULL) { 1276c66ac9dbSNicholas Bellinger if (!*ptr) 1277c66ac9dbSNicholas Bellinger continue; 1278c66ac9dbSNicholas Bellinger 1279c66ac9dbSNicholas Bellinger token = match_token(ptr, tokens, args); 1280c66ac9dbSNicholas Bellinger switch (token) { 1281c66ac9dbSNicholas Bellinger case Opt_initiator_fabric: 1282c66ac9dbSNicholas Bellinger i_fabric = match_strdup(&args[0]); 12836d180253SJesper Juhl if (!i_fabric) { 12846d180253SJesper Juhl ret = -ENOMEM; 12856d180253SJesper Juhl goto out; 12866d180253SJesper Juhl } 1287c66ac9dbSNicholas Bellinger break; 1288c66ac9dbSNicholas Bellinger case Opt_initiator_node: 1289c66ac9dbSNicholas Bellinger i_port = match_strdup(&args[0]); 12906d180253SJesper Juhl if (!i_port) { 12916d180253SJesper Juhl ret = -ENOMEM; 12926d180253SJesper Juhl goto out; 12936d180253SJesper Juhl } 129460d645a4SDan Carpenter if (strlen(i_port) >= PR_APTPL_MAX_IPORT_LEN) { 12956708bb27SAndy Grover pr_err("APTPL metadata initiator_node=" 1296c66ac9dbSNicholas Bellinger " exceeds PR_APTPL_MAX_IPORT_LEN: %d\n", 1297c66ac9dbSNicholas Bellinger PR_APTPL_MAX_IPORT_LEN); 1298c66ac9dbSNicholas Bellinger ret = -EINVAL; 1299c66ac9dbSNicholas Bellinger break; 1300c66ac9dbSNicholas Bellinger } 1301c66ac9dbSNicholas Bellinger break; 1302c66ac9dbSNicholas Bellinger case Opt_initiator_sid: 1303c66ac9dbSNicholas Bellinger isid = match_strdup(&args[0]); 13046d180253SJesper Juhl if (!isid) { 13056d180253SJesper Juhl ret = -ENOMEM; 13066d180253SJesper Juhl goto out; 13076d180253SJesper Juhl } 130860d645a4SDan Carpenter if (strlen(isid) >= PR_REG_ISID_LEN) { 13096708bb27SAndy Grover pr_err("APTPL metadata initiator_isid" 1310c66ac9dbSNicholas Bellinger "= exceeds PR_REG_ISID_LEN: %d\n", 1311c66ac9dbSNicholas Bellinger PR_REG_ISID_LEN); 1312c66ac9dbSNicholas Bellinger ret = -EINVAL; 1313c66ac9dbSNicholas Bellinger break; 1314c66ac9dbSNicholas Bellinger } 1315c66ac9dbSNicholas Bellinger break; 1316c66ac9dbSNicholas Bellinger case Opt_sa_res_key: 1317c66ac9dbSNicholas Bellinger arg_p = match_strdup(&args[0]); 13186d180253SJesper Juhl if (!arg_p) { 13196d180253SJesper Juhl ret = -ENOMEM; 13206d180253SJesper Juhl goto out; 13216d180253SJesper Juhl } 132257103d7fSJingoo Han ret = kstrtoull(arg_p, 0, &tmp_ll); 1323c66ac9dbSNicholas Bellinger if (ret < 0) { 132457103d7fSJingoo Han pr_err("kstrtoull() failed for" 1325c66ac9dbSNicholas Bellinger " sa_res_key=\n"); 1326c66ac9dbSNicholas Bellinger goto out; 1327c66ac9dbSNicholas Bellinger } 1328c66ac9dbSNicholas Bellinger sa_res_key = (u64)tmp_ll; 1329c66ac9dbSNicholas Bellinger break; 1330c66ac9dbSNicholas Bellinger /* 1331c66ac9dbSNicholas Bellinger * PR APTPL Metadata for Reservation 1332c66ac9dbSNicholas Bellinger */ 1333c66ac9dbSNicholas Bellinger case Opt_res_holder: 1334c66ac9dbSNicholas Bellinger match_int(args, &arg); 1335c66ac9dbSNicholas Bellinger res_holder = arg; 1336c66ac9dbSNicholas Bellinger break; 1337c66ac9dbSNicholas Bellinger case Opt_res_type: 1338c66ac9dbSNicholas Bellinger match_int(args, &arg); 1339c66ac9dbSNicholas Bellinger type = (u8)arg; 1340c66ac9dbSNicholas Bellinger break; 1341c66ac9dbSNicholas Bellinger case Opt_res_scope: 1342c66ac9dbSNicholas Bellinger match_int(args, &arg); 1343c66ac9dbSNicholas Bellinger scope = (u8)arg; 1344c66ac9dbSNicholas Bellinger break; 1345c66ac9dbSNicholas Bellinger case Opt_res_all_tg_pt: 1346c66ac9dbSNicholas Bellinger match_int(args, &arg); 1347c66ac9dbSNicholas Bellinger all_tg_pt = (int)arg; 1348c66ac9dbSNicholas Bellinger break; 1349c66ac9dbSNicholas Bellinger case Opt_mapped_lun: 1350c66ac9dbSNicholas Bellinger match_int(args, &arg); 1351c66ac9dbSNicholas Bellinger mapped_lun = (u32)arg; 1352c66ac9dbSNicholas Bellinger break; 1353c66ac9dbSNicholas Bellinger /* 1354c66ac9dbSNicholas Bellinger * PR APTPL Metadata for Target Port 1355c66ac9dbSNicholas Bellinger */ 1356c66ac9dbSNicholas Bellinger case Opt_target_fabric: 1357c66ac9dbSNicholas Bellinger t_fabric = match_strdup(&args[0]); 13586d180253SJesper Juhl if (!t_fabric) { 13596d180253SJesper Juhl ret = -ENOMEM; 13606d180253SJesper Juhl goto out; 13616d180253SJesper Juhl } 1362c66ac9dbSNicholas Bellinger break; 1363c66ac9dbSNicholas Bellinger case Opt_target_node: 1364c66ac9dbSNicholas Bellinger t_port = match_strdup(&args[0]); 13656d180253SJesper Juhl if (!t_port) { 13666d180253SJesper Juhl ret = -ENOMEM; 13676d180253SJesper Juhl goto out; 13686d180253SJesper Juhl } 136960d645a4SDan Carpenter if (strlen(t_port) >= PR_APTPL_MAX_TPORT_LEN) { 13706708bb27SAndy Grover pr_err("APTPL metadata target_node=" 1371c66ac9dbSNicholas Bellinger " exceeds PR_APTPL_MAX_TPORT_LEN: %d\n", 1372c66ac9dbSNicholas Bellinger PR_APTPL_MAX_TPORT_LEN); 1373c66ac9dbSNicholas Bellinger ret = -EINVAL; 1374c66ac9dbSNicholas Bellinger break; 1375c66ac9dbSNicholas Bellinger } 1376c66ac9dbSNicholas Bellinger break; 1377c66ac9dbSNicholas Bellinger case Opt_tpgt: 1378c66ac9dbSNicholas Bellinger match_int(args, &arg); 1379c66ac9dbSNicholas Bellinger tpgt = (u16)arg; 1380c66ac9dbSNicholas Bellinger break; 1381c66ac9dbSNicholas Bellinger case Opt_port_rtpi: 1382c66ac9dbSNicholas Bellinger match_int(args, &arg); 1383c66ac9dbSNicholas Bellinger port_rpti = (u16)arg; 1384c66ac9dbSNicholas Bellinger break; 1385c66ac9dbSNicholas Bellinger case Opt_target_lun: 1386c66ac9dbSNicholas Bellinger match_int(args, &arg); 1387c66ac9dbSNicholas Bellinger target_lun = (u32)arg; 1388c66ac9dbSNicholas Bellinger break; 1389c66ac9dbSNicholas Bellinger default: 1390c66ac9dbSNicholas Bellinger break; 1391c66ac9dbSNicholas Bellinger } 1392c66ac9dbSNicholas Bellinger } 1393c66ac9dbSNicholas Bellinger 13946708bb27SAndy Grover if (!i_port || !t_port || !sa_res_key) { 13956708bb27SAndy Grover pr_err("Illegal parameters for APTPL registration\n"); 1396c66ac9dbSNicholas Bellinger ret = -EINVAL; 1397c66ac9dbSNicholas Bellinger goto out; 1398c66ac9dbSNicholas Bellinger } 1399c66ac9dbSNicholas Bellinger 1400c66ac9dbSNicholas Bellinger if (res_holder && !(type)) { 14016708bb27SAndy Grover pr_err("Illegal PR type: 0x%02x for reservation" 1402c66ac9dbSNicholas Bellinger " holder\n", type); 1403c66ac9dbSNicholas Bellinger ret = -EINVAL; 1404c66ac9dbSNicholas Bellinger goto out; 1405c66ac9dbSNicholas Bellinger } 1406c66ac9dbSNicholas Bellinger 14070fd97ccfSChristoph Hellwig ret = core_scsi3_alloc_aptpl_registration(&dev->t10_pr, sa_res_key, 1408c66ac9dbSNicholas Bellinger i_port, isid, mapped_lun, t_port, tpgt, target_lun, 1409c66ac9dbSNicholas Bellinger res_holder, all_tg_pt, type); 1410c66ac9dbSNicholas Bellinger out: 14116d180253SJesper Juhl kfree(i_fabric); 14126d180253SJesper Juhl kfree(i_port); 14136d180253SJesper Juhl kfree(isid); 14146d180253SJesper Juhl kfree(t_fabric); 14156d180253SJesper Juhl kfree(t_port); 1416c66ac9dbSNicholas Bellinger kfree(orig); 1417c66ac9dbSNicholas Bellinger return (ret == 0) ? count : ret; 1418c66ac9dbSNicholas Bellinger } 1419c66ac9dbSNicholas Bellinger 1420c66ac9dbSNicholas Bellinger SE_DEV_PR_ATTR(res_aptpl_metadata, S_IRUGO | S_IWUSR); 1421c66ac9dbSNicholas Bellinger 14220fd97ccfSChristoph Hellwig CONFIGFS_EATTR_OPS(target_core_dev_pr, se_device, dev_pr_group); 1423c66ac9dbSNicholas Bellinger 1424c66ac9dbSNicholas Bellinger static struct configfs_attribute *target_core_dev_pr_attrs[] = { 1425c66ac9dbSNicholas Bellinger &target_core_dev_pr_res_holder.attr, 1426c66ac9dbSNicholas Bellinger &target_core_dev_pr_res_pr_all_tgt_pts.attr, 1427c66ac9dbSNicholas Bellinger &target_core_dev_pr_res_pr_generation.attr, 1428c66ac9dbSNicholas Bellinger &target_core_dev_pr_res_pr_holder_tg_port.attr, 1429c66ac9dbSNicholas Bellinger &target_core_dev_pr_res_pr_registered_i_pts.attr, 1430c66ac9dbSNicholas Bellinger &target_core_dev_pr_res_pr_type.attr, 1431c66ac9dbSNicholas Bellinger &target_core_dev_pr_res_type.attr, 1432c66ac9dbSNicholas Bellinger &target_core_dev_pr_res_aptpl_active.attr, 1433c66ac9dbSNicholas Bellinger &target_core_dev_pr_res_aptpl_metadata.attr, 1434c66ac9dbSNicholas Bellinger NULL, 1435c66ac9dbSNicholas Bellinger }; 1436c66ac9dbSNicholas Bellinger 1437c66ac9dbSNicholas Bellinger static struct configfs_item_operations target_core_dev_pr_ops = { 1438c66ac9dbSNicholas Bellinger .show_attribute = target_core_dev_pr_attr_show, 1439c66ac9dbSNicholas Bellinger .store_attribute = target_core_dev_pr_attr_store, 1440c66ac9dbSNicholas Bellinger }; 1441c66ac9dbSNicholas Bellinger 1442c66ac9dbSNicholas Bellinger static struct config_item_type target_core_dev_pr_cit = { 1443c66ac9dbSNicholas Bellinger .ct_item_ops = &target_core_dev_pr_ops, 1444c66ac9dbSNicholas Bellinger .ct_attrs = target_core_dev_pr_attrs, 1445c66ac9dbSNicholas Bellinger .ct_owner = THIS_MODULE, 1446c66ac9dbSNicholas Bellinger }; 1447c66ac9dbSNicholas Bellinger 1448c66ac9dbSNicholas Bellinger /* End functions for struct config_item_type target_core_dev_pr_cit */ 1449c66ac9dbSNicholas Bellinger 1450c66ac9dbSNicholas Bellinger /* Start functions for struct config_item_type target_core_dev_cit */ 1451c66ac9dbSNicholas Bellinger 1452c66ac9dbSNicholas Bellinger static ssize_t target_core_show_dev_info(void *p, char *page) 1453c66ac9dbSNicholas Bellinger { 14540fd97ccfSChristoph Hellwig struct se_device *dev = p; 14550fd97ccfSChristoph Hellwig struct se_subsystem_api *t = dev->transport; 1456c66ac9dbSNicholas Bellinger int bl = 0; 1457c66ac9dbSNicholas Bellinger ssize_t read_bytes = 0; 1458c66ac9dbSNicholas Bellinger 14590fd97ccfSChristoph Hellwig transport_dump_dev_state(dev, page, &bl); 1460c66ac9dbSNicholas Bellinger read_bytes += bl; 14610fd97ccfSChristoph Hellwig read_bytes += t->show_configfs_dev_params(dev, page+read_bytes); 1462c66ac9dbSNicholas Bellinger return read_bytes; 1463c66ac9dbSNicholas Bellinger } 1464c66ac9dbSNicholas Bellinger 1465c66ac9dbSNicholas Bellinger static struct target_core_configfs_attribute target_core_attr_dev_info = { 1466c66ac9dbSNicholas Bellinger .attr = { .ca_owner = THIS_MODULE, 1467c66ac9dbSNicholas Bellinger .ca_name = "info", 1468c66ac9dbSNicholas Bellinger .ca_mode = S_IRUGO }, 1469c66ac9dbSNicholas Bellinger .show = target_core_show_dev_info, 1470c66ac9dbSNicholas Bellinger .store = NULL, 1471c66ac9dbSNicholas Bellinger }; 1472c66ac9dbSNicholas Bellinger 1473c66ac9dbSNicholas Bellinger static ssize_t target_core_store_dev_control( 1474c66ac9dbSNicholas Bellinger void *p, 1475c66ac9dbSNicholas Bellinger const char *page, 1476c66ac9dbSNicholas Bellinger size_t count) 1477c66ac9dbSNicholas Bellinger { 14780fd97ccfSChristoph Hellwig struct se_device *dev = p; 14790fd97ccfSChristoph Hellwig struct se_subsystem_api *t = dev->transport; 1480c66ac9dbSNicholas Bellinger 14810fd97ccfSChristoph Hellwig return t->set_configfs_dev_params(dev, page, count); 1482c66ac9dbSNicholas Bellinger } 1483c66ac9dbSNicholas Bellinger 1484c66ac9dbSNicholas Bellinger static struct target_core_configfs_attribute target_core_attr_dev_control = { 1485c66ac9dbSNicholas Bellinger .attr = { .ca_owner = THIS_MODULE, 1486c66ac9dbSNicholas Bellinger .ca_name = "control", 1487c66ac9dbSNicholas Bellinger .ca_mode = S_IWUSR }, 1488c66ac9dbSNicholas Bellinger .show = NULL, 1489c66ac9dbSNicholas Bellinger .store = target_core_store_dev_control, 1490c66ac9dbSNicholas Bellinger }; 1491c66ac9dbSNicholas Bellinger 1492c66ac9dbSNicholas Bellinger static ssize_t target_core_show_dev_alias(void *p, char *page) 1493c66ac9dbSNicholas Bellinger { 14940fd97ccfSChristoph Hellwig struct se_device *dev = p; 1495c66ac9dbSNicholas Bellinger 14960fd97ccfSChristoph Hellwig if (!(dev->dev_flags & DF_USING_ALIAS)) 1497c66ac9dbSNicholas Bellinger return 0; 1498c66ac9dbSNicholas Bellinger 14990fd97ccfSChristoph Hellwig return snprintf(page, PAGE_SIZE, "%s\n", dev->dev_alias); 1500c66ac9dbSNicholas Bellinger } 1501c66ac9dbSNicholas Bellinger 1502c66ac9dbSNicholas Bellinger static ssize_t target_core_store_dev_alias( 1503c66ac9dbSNicholas Bellinger void *p, 1504c66ac9dbSNicholas Bellinger const char *page, 1505c66ac9dbSNicholas Bellinger size_t count) 1506c66ac9dbSNicholas Bellinger { 15070fd97ccfSChristoph Hellwig struct se_device *dev = p; 15080fd97ccfSChristoph Hellwig struct se_hba *hba = dev->se_hba; 1509c66ac9dbSNicholas Bellinger ssize_t read_bytes; 1510c66ac9dbSNicholas Bellinger 1511c66ac9dbSNicholas Bellinger if (count > (SE_DEV_ALIAS_LEN-1)) { 15126708bb27SAndy Grover pr_err("alias count: %d exceeds" 1513c66ac9dbSNicholas Bellinger " SE_DEV_ALIAS_LEN-1: %u\n", (int)count, 1514c66ac9dbSNicholas Bellinger SE_DEV_ALIAS_LEN-1); 1515c66ac9dbSNicholas Bellinger return -EINVAL; 1516c66ac9dbSNicholas Bellinger } 1517c66ac9dbSNicholas Bellinger 15180fd97ccfSChristoph Hellwig read_bytes = snprintf(&dev->dev_alias[0], SE_DEV_ALIAS_LEN, "%s", page); 15193011684cSDan Carpenter if (!read_bytes) 15203011684cSDan Carpenter return -EINVAL; 15210fd97ccfSChristoph Hellwig if (dev->dev_alias[read_bytes - 1] == '\n') 15220fd97ccfSChristoph Hellwig dev->dev_alias[read_bytes - 1] = '\0'; 15230877eafdSSebastian Andrzej Siewior 15240fd97ccfSChristoph Hellwig dev->dev_flags |= DF_USING_ALIAS; 15253011684cSDan Carpenter 15266708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: %s/%s set alias: %s\n", 1527c66ac9dbSNicholas Bellinger config_item_name(&hba->hba_group.cg_item), 15280fd97ccfSChristoph Hellwig config_item_name(&dev->dev_group.cg_item), 15290fd97ccfSChristoph Hellwig dev->dev_alias); 1530c66ac9dbSNicholas Bellinger 1531c66ac9dbSNicholas Bellinger return read_bytes; 1532c66ac9dbSNicholas Bellinger } 1533c66ac9dbSNicholas Bellinger 1534c66ac9dbSNicholas Bellinger static struct target_core_configfs_attribute target_core_attr_dev_alias = { 1535c66ac9dbSNicholas Bellinger .attr = { .ca_owner = THIS_MODULE, 1536c66ac9dbSNicholas Bellinger .ca_name = "alias", 1537c66ac9dbSNicholas Bellinger .ca_mode = S_IRUGO | S_IWUSR }, 1538c66ac9dbSNicholas Bellinger .show = target_core_show_dev_alias, 1539c66ac9dbSNicholas Bellinger .store = target_core_store_dev_alias, 1540c66ac9dbSNicholas Bellinger }; 1541c66ac9dbSNicholas Bellinger 1542c66ac9dbSNicholas Bellinger static ssize_t target_core_show_dev_udev_path(void *p, char *page) 1543c66ac9dbSNicholas Bellinger { 15440fd97ccfSChristoph Hellwig struct se_device *dev = p; 1545c66ac9dbSNicholas Bellinger 15460fd97ccfSChristoph Hellwig if (!(dev->dev_flags & DF_USING_UDEV_PATH)) 1547c66ac9dbSNicholas Bellinger return 0; 1548c66ac9dbSNicholas Bellinger 15490fd97ccfSChristoph Hellwig return snprintf(page, PAGE_SIZE, "%s\n", dev->udev_path); 1550c66ac9dbSNicholas Bellinger } 1551c66ac9dbSNicholas Bellinger 1552c66ac9dbSNicholas Bellinger static ssize_t target_core_store_dev_udev_path( 1553c66ac9dbSNicholas Bellinger void *p, 1554c66ac9dbSNicholas Bellinger const char *page, 1555c66ac9dbSNicholas Bellinger size_t count) 1556c66ac9dbSNicholas Bellinger { 15570fd97ccfSChristoph Hellwig struct se_device *dev = p; 15580fd97ccfSChristoph Hellwig struct se_hba *hba = dev->se_hba; 1559c66ac9dbSNicholas Bellinger ssize_t read_bytes; 1560c66ac9dbSNicholas Bellinger 1561c66ac9dbSNicholas Bellinger if (count > (SE_UDEV_PATH_LEN-1)) { 15626708bb27SAndy Grover pr_err("udev_path count: %d exceeds" 1563c66ac9dbSNicholas Bellinger " SE_UDEV_PATH_LEN-1: %u\n", (int)count, 1564c66ac9dbSNicholas Bellinger SE_UDEV_PATH_LEN-1); 1565c66ac9dbSNicholas Bellinger return -EINVAL; 1566c66ac9dbSNicholas Bellinger } 1567c66ac9dbSNicholas Bellinger 15680fd97ccfSChristoph Hellwig read_bytes = snprintf(&dev->udev_path[0], SE_UDEV_PATH_LEN, 1569c66ac9dbSNicholas Bellinger "%s", page); 15703011684cSDan Carpenter if (!read_bytes) 15713011684cSDan Carpenter return -EINVAL; 15720fd97ccfSChristoph Hellwig if (dev->udev_path[read_bytes - 1] == '\n') 15730fd97ccfSChristoph Hellwig dev->udev_path[read_bytes - 1] = '\0'; 15740877eafdSSebastian Andrzej Siewior 15750fd97ccfSChristoph Hellwig dev->dev_flags |= DF_USING_UDEV_PATH; 15763011684cSDan Carpenter 15776708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: %s/%s set udev_path: %s\n", 1578c66ac9dbSNicholas Bellinger config_item_name(&hba->hba_group.cg_item), 15790fd97ccfSChristoph Hellwig config_item_name(&dev->dev_group.cg_item), 15800fd97ccfSChristoph Hellwig dev->udev_path); 1581c66ac9dbSNicholas Bellinger 1582c66ac9dbSNicholas Bellinger return read_bytes; 1583c66ac9dbSNicholas Bellinger } 1584c66ac9dbSNicholas Bellinger 1585c66ac9dbSNicholas Bellinger static struct target_core_configfs_attribute target_core_attr_dev_udev_path = { 1586c66ac9dbSNicholas Bellinger .attr = { .ca_owner = THIS_MODULE, 1587c66ac9dbSNicholas Bellinger .ca_name = "udev_path", 1588c66ac9dbSNicholas Bellinger .ca_mode = S_IRUGO | S_IWUSR }, 1589c66ac9dbSNicholas Bellinger .show = target_core_show_dev_udev_path, 1590c66ac9dbSNicholas Bellinger .store = target_core_store_dev_udev_path, 1591c66ac9dbSNicholas Bellinger }; 1592c66ac9dbSNicholas Bellinger 159364146db7SAndy Grover static ssize_t target_core_show_dev_enable(void *p, char *page) 159464146db7SAndy Grover { 159564146db7SAndy Grover struct se_device *dev = p; 159664146db7SAndy Grover 159764146db7SAndy Grover return snprintf(page, PAGE_SIZE, "%d\n", !!(dev->dev_flags & DF_CONFIGURED)); 159864146db7SAndy Grover } 159964146db7SAndy Grover 1600c66ac9dbSNicholas Bellinger static ssize_t target_core_store_dev_enable( 1601c66ac9dbSNicholas Bellinger void *p, 1602c66ac9dbSNicholas Bellinger const char *page, 1603c66ac9dbSNicholas Bellinger size_t count) 1604c66ac9dbSNicholas Bellinger { 16050fd97ccfSChristoph Hellwig struct se_device *dev = p; 1606c66ac9dbSNicholas Bellinger char *ptr; 16070fd97ccfSChristoph Hellwig int ret; 1608c66ac9dbSNicholas Bellinger 1609c66ac9dbSNicholas Bellinger ptr = strstr(page, "1"); 16106708bb27SAndy Grover if (!ptr) { 16116708bb27SAndy Grover pr_err("For dev_enable ops, only valid value" 1612c66ac9dbSNicholas Bellinger " is \"1\"\n"); 1613c66ac9dbSNicholas Bellinger return -EINVAL; 1614c66ac9dbSNicholas Bellinger } 1615c66ac9dbSNicholas Bellinger 16160fd97ccfSChristoph Hellwig ret = target_configure_device(dev); 16170fd97ccfSChristoph Hellwig if (ret) 16180fd97ccfSChristoph Hellwig return ret; 1619c66ac9dbSNicholas Bellinger return count; 1620c66ac9dbSNicholas Bellinger } 1621c66ac9dbSNicholas Bellinger 1622c66ac9dbSNicholas Bellinger static struct target_core_configfs_attribute target_core_attr_dev_enable = { 1623c66ac9dbSNicholas Bellinger .attr = { .ca_owner = THIS_MODULE, 1624c66ac9dbSNicholas Bellinger .ca_name = "enable", 162564146db7SAndy Grover .ca_mode = S_IRUGO | S_IWUSR }, 162664146db7SAndy Grover .show = target_core_show_dev_enable, 1627c66ac9dbSNicholas Bellinger .store = target_core_store_dev_enable, 1628c66ac9dbSNicholas Bellinger }; 1629c66ac9dbSNicholas Bellinger 1630c66ac9dbSNicholas Bellinger static ssize_t target_core_show_alua_lu_gp(void *p, char *page) 1631c66ac9dbSNicholas Bellinger { 16320fd97ccfSChristoph Hellwig struct se_device *dev = p; 1633c66ac9dbSNicholas Bellinger struct config_item *lu_ci; 1634c66ac9dbSNicholas Bellinger struct t10_alua_lu_gp *lu_gp; 1635c66ac9dbSNicholas Bellinger struct t10_alua_lu_gp_member *lu_gp_mem; 1636c66ac9dbSNicholas Bellinger ssize_t len = 0; 1637c66ac9dbSNicholas Bellinger 1638c66ac9dbSNicholas Bellinger lu_gp_mem = dev->dev_alua_lu_gp_mem; 1639c87fbd56SChristoph Hellwig if (!lu_gp_mem) 1640c87fbd56SChristoph Hellwig return 0; 1641c66ac9dbSNicholas Bellinger 1642c66ac9dbSNicholas Bellinger spin_lock(&lu_gp_mem->lu_gp_mem_lock); 1643c66ac9dbSNicholas Bellinger lu_gp = lu_gp_mem->lu_gp; 16446708bb27SAndy Grover if (lu_gp) { 1645c66ac9dbSNicholas Bellinger lu_ci = &lu_gp->lu_gp_group.cg_item; 1646c66ac9dbSNicholas Bellinger len += sprintf(page, "LU Group Alias: %s\nLU Group ID: %hu\n", 1647c66ac9dbSNicholas Bellinger config_item_name(lu_ci), lu_gp->lu_gp_id); 1648c66ac9dbSNicholas Bellinger } 1649c66ac9dbSNicholas Bellinger spin_unlock(&lu_gp_mem->lu_gp_mem_lock); 1650c66ac9dbSNicholas Bellinger 1651c66ac9dbSNicholas Bellinger return len; 1652c66ac9dbSNicholas Bellinger } 1653c66ac9dbSNicholas Bellinger 1654c66ac9dbSNicholas Bellinger static ssize_t target_core_store_alua_lu_gp( 1655c66ac9dbSNicholas Bellinger void *p, 1656c66ac9dbSNicholas Bellinger const char *page, 1657c66ac9dbSNicholas Bellinger size_t count) 1658c66ac9dbSNicholas Bellinger { 16590fd97ccfSChristoph Hellwig struct se_device *dev = p; 16600fd97ccfSChristoph Hellwig struct se_hba *hba = dev->se_hba; 1661c66ac9dbSNicholas Bellinger struct t10_alua_lu_gp *lu_gp = NULL, *lu_gp_new = NULL; 1662c66ac9dbSNicholas Bellinger struct t10_alua_lu_gp_member *lu_gp_mem; 1663c66ac9dbSNicholas Bellinger unsigned char buf[LU_GROUP_NAME_BUF]; 1664c66ac9dbSNicholas Bellinger int move = 0; 1665c66ac9dbSNicholas Bellinger 1666c87fbd56SChristoph Hellwig lu_gp_mem = dev->dev_alua_lu_gp_mem; 1667c87fbd56SChristoph Hellwig if (!lu_gp_mem) 1668c87fbd56SChristoph Hellwig return 0; 1669c87fbd56SChristoph Hellwig 1670c66ac9dbSNicholas Bellinger if (count > LU_GROUP_NAME_BUF) { 16716708bb27SAndy Grover pr_err("ALUA LU Group Alias too large!\n"); 1672c66ac9dbSNicholas Bellinger return -EINVAL; 1673c66ac9dbSNicholas Bellinger } 1674c66ac9dbSNicholas Bellinger memset(buf, 0, LU_GROUP_NAME_BUF); 1675c66ac9dbSNicholas Bellinger memcpy(buf, page, count); 1676c66ac9dbSNicholas Bellinger /* 1677c66ac9dbSNicholas Bellinger * Any ALUA logical unit alias besides "NULL" means we will be 1678c66ac9dbSNicholas Bellinger * making a new group association. 1679c66ac9dbSNicholas Bellinger */ 1680c66ac9dbSNicholas Bellinger if (strcmp(strstrip(buf), "NULL")) { 1681c66ac9dbSNicholas Bellinger /* 1682c66ac9dbSNicholas Bellinger * core_alua_get_lu_gp_by_name() will increment reference to 1683c66ac9dbSNicholas Bellinger * struct t10_alua_lu_gp. This reference is released with 1684c66ac9dbSNicholas Bellinger * core_alua_get_lu_gp_by_name below(). 1685c66ac9dbSNicholas Bellinger */ 1686c66ac9dbSNicholas Bellinger lu_gp_new = core_alua_get_lu_gp_by_name(strstrip(buf)); 16876708bb27SAndy Grover if (!lu_gp_new) 1688c66ac9dbSNicholas Bellinger return -ENODEV; 1689c66ac9dbSNicholas Bellinger } 1690c66ac9dbSNicholas Bellinger 1691c66ac9dbSNicholas Bellinger spin_lock(&lu_gp_mem->lu_gp_mem_lock); 1692c66ac9dbSNicholas Bellinger lu_gp = lu_gp_mem->lu_gp; 16936708bb27SAndy Grover if (lu_gp) { 1694c66ac9dbSNicholas Bellinger /* 1695c66ac9dbSNicholas Bellinger * Clearing an existing lu_gp association, and replacing 1696c66ac9dbSNicholas Bellinger * with NULL 1697c66ac9dbSNicholas Bellinger */ 16986708bb27SAndy Grover if (!lu_gp_new) { 16996708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: Releasing %s/%s" 1700c66ac9dbSNicholas Bellinger " from ALUA LU Group: core/alua/lu_gps/%s, ID:" 1701c66ac9dbSNicholas Bellinger " %hu\n", 1702c66ac9dbSNicholas Bellinger config_item_name(&hba->hba_group.cg_item), 17030fd97ccfSChristoph Hellwig config_item_name(&dev->dev_group.cg_item), 1704c66ac9dbSNicholas Bellinger config_item_name(&lu_gp->lu_gp_group.cg_item), 1705c66ac9dbSNicholas Bellinger lu_gp->lu_gp_id); 1706c66ac9dbSNicholas Bellinger 1707c66ac9dbSNicholas Bellinger __core_alua_drop_lu_gp_mem(lu_gp_mem, lu_gp); 1708c66ac9dbSNicholas Bellinger spin_unlock(&lu_gp_mem->lu_gp_mem_lock); 1709c66ac9dbSNicholas Bellinger 1710c66ac9dbSNicholas Bellinger return count; 1711c66ac9dbSNicholas Bellinger } 1712c66ac9dbSNicholas Bellinger /* 1713c66ac9dbSNicholas Bellinger * Removing existing association of lu_gp_mem with lu_gp 1714c66ac9dbSNicholas Bellinger */ 1715c66ac9dbSNicholas Bellinger __core_alua_drop_lu_gp_mem(lu_gp_mem, lu_gp); 1716c66ac9dbSNicholas Bellinger move = 1; 1717c66ac9dbSNicholas Bellinger } 1718c66ac9dbSNicholas Bellinger /* 1719c66ac9dbSNicholas Bellinger * Associate lu_gp_mem with lu_gp_new. 1720c66ac9dbSNicholas Bellinger */ 1721c66ac9dbSNicholas Bellinger __core_alua_attach_lu_gp_mem(lu_gp_mem, lu_gp_new); 1722c66ac9dbSNicholas Bellinger spin_unlock(&lu_gp_mem->lu_gp_mem_lock); 1723c66ac9dbSNicholas Bellinger 17246708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: %s %s/%s to ALUA LU Group:" 1725c66ac9dbSNicholas Bellinger " core/alua/lu_gps/%s, ID: %hu\n", 1726c66ac9dbSNicholas Bellinger (move) ? "Moving" : "Adding", 1727c66ac9dbSNicholas Bellinger config_item_name(&hba->hba_group.cg_item), 17280fd97ccfSChristoph Hellwig config_item_name(&dev->dev_group.cg_item), 1729c66ac9dbSNicholas Bellinger config_item_name(&lu_gp_new->lu_gp_group.cg_item), 1730c66ac9dbSNicholas Bellinger lu_gp_new->lu_gp_id); 1731c66ac9dbSNicholas Bellinger 1732c66ac9dbSNicholas Bellinger core_alua_put_lu_gp_from_name(lu_gp_new); 1733c66ac9dbSNicholas Bellinger return count; 1734c66ac9dbSNicholas Bellinger } 1735c66ac9dbSNicholas Bellinger 1736c66ac9dbSNicholas Bellinger static struct target_core_configfs_attribute target_core_attr_dev_alua_lu_gp = { 1737c66ac9dbSNicholas Bellinger .attr = { .ca_owner = THIS_MODULE, 1738c66ac9dbSNicholas Bellinger .ca_name = "alua_lu_gp", 1739c66ac9dbSNicholas Bellinger .ca_mode = S_IRUGO | S_IWUSR }, 1740c66ac9dbSNicholas Bellinger .show = target_core_show_alua_lu_gp, 1741c66ac9dbSNicholas Bellinger .store = target_core_store_alua_lu_gp, 1742c66ac9dbSNicholas Bellinger }; 1743c66ac9dbSNicholas Bellinger 1744c66ac9dbSNicholas Bellinger static struct configfs_attribute *lio_core_dev_attrs[] = { 1745c66ac9dbSNicholas Bellinger &target_core_attr_dev_info.attr, 1746c66ac9dbSNicholas Bellinger &target_core_attr_dev_control.attr, 1747c66ac9dbSNicholas Bellinger &target_core_attr_dev_alias.attr, 1748c66ac9dbSNicholas Bellinger &target_core_attr_dev_udev_path.attr, 1749c66ac9dbSNicholas Bellinger &target_core_attr_dev_enable.attr, 1750c66ac9dbSNicholas Bellinger &target_core_attr_dev_alua_lu_gp.attr, 1751c66ac9dbSNicholas Bellinger NULL, 1752c66ac9dbSNicholas Bellinger }; 1753c66ac9dbSNicholas Bellinger 1754c66ac9dbSNicholas Bellinger static void target_core_dev_release(struct config_item *item) 1755c66ac9dbSNicholas Bellinger { 17560fd97ccfSChristoph Hellwig struct config_group *dev_cg = to_config_group(item); 17570fd97ccfSChristoph Hellwig struct se_device *dev = 17580fd97ccfSChristoph Hellwig container_of(dev_cg, struct se_device, dev_group); 1759c66ac9dbSNicholas Bellinger 1760c66ac9dbSNicholas Bellinger kfree(dev_cg->default_groups); 17610fd97ccfSChristoph Hellwig target_free_device(dev); 1762c66ac9dbSNicholas Bellinger } 1763c66ac9dbSNicholas Bellinger 1764c66ac9dbSNicholas Bellinger static ssize_t target_core_dev_show(struct config_item *item, 1765c66ac9dbSNicholas Bellinger struct configfs_attribute *attr, 1766c66ac9dbSNicholas Bellinger char *page) 1767c66ac9dbSNicholas Bellinger { 17680fd97ccfSChristoph Hellwig struct config_group *dev_cg = to_config_group(item); 17690fd97ccfSChristoph Hellwig struct se_device *dev = 17700fd97ccfSChristoph Hellwig container_of(dev_cg, struct se_device, dev_group); 1771c66ac9dbSNicholas Bellinger struct target_core_configfs_attribute *tc_attr = container_of( 1772c66ac9dbSNicholas Bellinger attr, struct target_core_configfs_attribute, attr); 1773c66ac9dbSNicholas Bellinger 17746708bb27SAndy Grover if (!tc_attr->show) 1775c66ac9dbSNicholas Bellinger return -EINVAL; 1776c66ac9dbSNicholas Bellinger 17770fd97ccfSChristoph Hellwig return tc_attr->show(dev, page); 1778c66ac9dbSNicholas Bellinger } 1779c66ac9dbSNicholas Bellinger 1780c66ac9dbSNicholas Bellinger static ssize_t target_core_dev_store(struct config_item *item, 1781c66ac9dbSNicholas Bellinger struct configfs_attribute *attr, 1782c66ac9dbSNicholas Bellinger const char *page, size_t count) 1783c66ac9dbSNicholas Bellinger { 17840fd97ccfSChristoph Hellwig struct config_group *dev_cg = to_config_group(item); 17850fd97ccfSChristoph Hellwig struct se_device *dev = 17860fd97ccfSChristoph Hellwig container_of(dev_cg, struct se_device, dev_group); 1787c66ac9dbSNicholas Bellinger struct target_core_configfs_attribute *tc_attr = container_of( 1788c66ac9dbSNicholas Bellinger attr, struct target_core_configfs_attribute, attr); 1789c66ac9dbSNicholas Bellinger 17906708bb27SAndy Grover if (!tc_attr->store) 1791c66ac9dbSNicholas Bellinger return -EINVAL; 1792c66ac9dbSNicholas Bellinger 17930fd97ccfSChristoph Hellwig return tc_attr->store(dev, page, count); 1794c66ac9dbSNicholas Bellinger } 1795c66ac9dbSNicholas Bellinger 1796c66ac9dbSNicholas Bellinger static struct configfs_item_operations target_core_dev_item_ops = { 1797c66ac9dbSNicholas Bellinger .release = target_core_dev_release, 1798c66ac9dbSNicholas Bellinger .show_attribute = target_core_dev_show, 1799c66ac9dbSNicholas Bellinger .store_attribute = target_core_dev_store, 1800c66ac9dbSNicholas Bellinger }; 1801c66ac9dbSNicholas Bellinger 1802c66ac9dbSNicholas Bellinger static struct config_item_type target_core_dev_cit = { 1803c66ac9dbSNicholas Bellinger .ct_item_ops = &target_core_dev_item_ops, 1804c66ac9dbSNicholas Bellinger .ct_attrs = lio_core_dev_attrs, 1805c66ac9dbSNicholas Bellinger .ct_owner = THIS_MODULE, 1806c66ac9dbSNicholas Bellinger }; 1807c66ac9dbSNicholas Bellinger 1808c66ac9dbSNicholas Bellinger /* End functions for struct config_item_type target_core_dev_cit */ 1809c66ac9dbSNicholas Bellinger 1810c66ac9dbSNicholas Bellinger /* Start functions for struct config_item_type target_core_alua_lu_gp_cit */ 1811c66ac9dbSNicholas Bellinger 1812c66ac9dbSNicholas Bellinger CONFIGFS_EATTR_STRUCT(target_core_alua_lu_gp, t10_alua_lu_gp); 1813c66ac9dbSNicholas Bellinger #define SE_DEV_ALUA_LU_ATTR(_name, _mode) \ 1814c66ac9dbSNicholas Bellinger static struct target_core_alua_lu_gp_attribute \ 1815c66ac9dbSNicholas Bellinger target_core_alua_lu_gp_##_name = \ 1816c66ac9dbSNicholas Bellinger __CONFIGFS_EATTR(_name, _mode, \ 1817c66ac9dbSNicholas Bellinger target_core_alua_lu_gp_show_attr_##_name, \ 1818c66ac9dbSNicholas Bellinger target_core_alua_lu_gp_store_attr_##_name); 1819c66ac9dbSNicholas Bellinger 1820c66ac9dbSNicholas Bellinger #define SE_DEV_ALUA_LU_ATTR_RO(_name) \ 1821c66ac9dbSNicholas Bellinger static struct target_core_alua_lu_gp_attribute \ 1822c66ac9dbSNicholas Bellinger target_core_alua_lu_gp_##_name = \ 1823c66ac9dbSNicholas Bellinger __CONFIGFS_EATTR_RO(_name, \ 1824c66ac9dbSNicholas Bellinger target_core_alua_lu_gp_show_attr_##_name); 1825c66ac9dbSNicholas Bellinger 1826c66ac9dbSNicholas Bellinger /* 1827c66ac9dbSNicholas Bellinger * lu_gp_id 1828c66ac9dbSNicholas Bellinger */ 1829c66ac9dbSNicholas Bellinger static ssize_t target_core_alua_lu_gp_show_attr_lu_gp_id( 1830c66ac9dbSNicholas Bellinger struct t10_alua_lu_gp *lu_gp, 1831c66ac9dbSNicholas Bellinger char *page) 1832c66ac9dbSNicholas Bellinger { 18336708bb27SAndy Grover if (!lu_gp->lu_gp_valid_id) 1834c66ac9dbSNicholas Bellinger return 0; 1835c66ac9dbSNicholas Bellinger 1836c66ac9dbSNicholas Bellinger return sprintf(page, "%hu\n", lu_gp->lu_gp_id); 1837c66ac9dbSNicholas Bellinger } 1838c66ac9dbSNicholas Bellinger 1839c66ac9dbSNicholas Bellinger static ssize_t target_core_alua_lu_gp_store_attr_lu_gp_id( 1840c66ac9dbSNicholas Bellinger struct t10_alua_lu_gp *lu_gp, 1841c66ac9dbSNicholas Bellinger const char *page, 1842c66ac9dbSNicholas Bellinger size_t count) 1843c66ac9dbSNicholas Bellinger { 1844c66ac9dbSNicholas Bellinger struct config_group *alua_lu_gp_cg = &lu_gp->lu_gp_group; 1845c66ac9dbSNicholas Bellinger unsigned long lu_gp_id; 1846c66ac9dbSNicholas Bellinger int ret; 1847c66ac9dbSNicholas Bellinger 184857103d7fSJingoo Han ret = kstrtoul(page, 0, &lu_gp_id); 1849c66ac9dbSNicholas Bellinger if (ret < 0) { 185057103d7fSJingoo Han pr_err("kstrtoul() returned %d for" 1851c66ac9dbSNicholas Bellinger " lu_gp_id\n", ret); 185257103d7fSJingoo Han return ret; 1853c66ac9dbSNicholas Bellinger } 1854c66ac9dbSNicholas Bellinger if (lu_gp_id > 0x0000ffff) { 18556708bb27SAndy Grover pr_err("ALUA lu_gp_id: %lu exceeds maximum:" 1856c66ac9dbSNicholas Bellinger " 0x0000ffff\n", lu_gp_id); 1857c66ac9dbSNicholas Bellinger return -EINVAL; 1858c66ac9dbSNicholas Bellinger } 1859c66ac9dbSNicholas Bellinger 1860c66ac9dbSNicholas Bellinger ret = core_alua_set_lu_gp_id(lu_gp, (u16)lu_gp_id); 1861c66ac9dbSNicholas Bellinger if (ret < 0) 1862c66ac9dbSNicholas Bellinger return -EINVAL; 1863c66ac9dbSNicholas Bellinger 18646708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: Set ALUA Logical Unit" 1865c66ac9dbSNicholas Bellinger " Group: core/alua/lu_gps/%s to ID: %hu\n", 1866c66ac9dbSNicholas Bellinger config_item_name(&alua_lu_gp_cg->cg_item), 1867c66ac9dbSNicholas Bellinger lu_gp->lu_gp_id); 1868c66ac9dbSNicholas Bellinger 1869c66ac9dbSNicholas Bellinger return count; 1870c66ac9dbSNicholas Bellinger } 1871c66ac9dbSNicholas Bellinger 1872c66ac9dbSNicholas Bellinger SE_DEV_ALUA_LU_ATTR(lu_gp_id, S_IRUGO | S_IWUSR); 1873c66ac9dbSNicholas Bellinger 1874c66ac9dbSNicholas Bellinger /* 1875c66ac9dbSNicholas Bellinger * members 1876c66ac9dbSNicholas Bellinger */ 1877c66ac9dbSNicholas Bellinger static ssize_t target_core_alua_lu_gp_show_attr_members( 1878c66ac9dbSNicholas Bellinger struct t10_alua_lu_gp *lu_gp, 1879c66ac9dbSNicholas Bellinger char *page) 1880c66ac9dbSNicholas Bellinger { 1881c66ac9dbSNicholas Bellinger struct se_device *dev; 1882c66ac9dbSNicholas Bellinger struct se_hba *hba; 1883c66ac9dbSNicholas Bellinger struct t10_alua_lu_gp_member *lu_gp_mem; 1884c66ac9dbSNicholas Bellinger ssize_t len = 0, cur_len; 1885c66ac9dbSNicholas Bellinger unsigned char buf[LU_GROUP_NAME_BUF]; 1886c66ac9dbSNicholas Bellinger 1887c66ac9dbSNicholas Bellinger memset(buf, 0, LU_GROUP_NAME_BUF); 1888c66ac9dbSNicholas Bellinger 1889c66ac9dbSNicholas Bellinger spin_lock(&lu_gp->lu_gp_lock); 1890c66ac9dbSNicholas Bellinger list_for_each_entry(lu_gp_mem, &lu_gp->lu_gp_mem_list, lu_gp_mem_list) { 1891c66ac9dbSNicholas Bellinger dev = lu_gp_mem->lu_gp_mem_dev; 18920fd97ccfSChristoph Hellwig hba = dev->se_hba; 1893c66ac9dbSNicholas Bellinger 1894c66ac9dbSNicholas Bellinger cur_len = snprintf(buf, LU_GROUP_NAME_BUF, "%s/%s\n", 1895c66ac9dbSNicholas Bellinger config_item_name(&hba->hba_group.cg_item), 18960fd97ccfSChristoph Hellwig config_item_name(&dev->dev_group.cg_item)); 1897c66ac9dbSNicholas Bellinger cur_len++; /* Extra byte for NULL terminator */ 1898c66ac9dbSNicholas Bellinger 1899c66ac9dbSNicholas Bellinger if ((cur_len + len) > PAGE_SIZE) { 19006708bb27SAndy Grover pr_warn("Ran out of lu_gp_show_attr" 1901c66ac9dbSNicholas Bellinger "_members buffer\n"); 1902c66ac9dbSNicholas Bellinger break; 1903c66ac9dbSNicholas Bellinger } 1904c66ac9dbSNicholas Bellinger memcpy(page+len, buf, cur_len); 1905c66ac9dbSNicholas Bellinger len += cur_len; 1906c66ac9dbSNicholas Bellinger } 1907c66ac9dbSNicholas Bellinger spin_unlock(&lu_gp->lu_gp_lock); 1908c66ac9dbSNicholas Bellinger 1909c66ac9dbSNicholas Bellinger return len; 1910c66ac9dbSNicholas Bellinger } 1911c66ac9dbSNicholas Bellinger 1912c66ac9dbSNicholas Bellinger SE_DEV_ALUA_LU_ATTR_RO(members); 1913c66ac9dbSNicholas Bellinger 1914c66ac9dbSNicholas Bellinger CONFIGFS_EATTR_OPS(target_core_alua_lu_gp, t10_alua_lu_gp, lu_gp_group); 1915c66ac9dbSNicholas Bellinger 1916c66ac9dbSNicholas Bellinger static struct configfs_attribute *target_core_alua_lu_gp_attrs[] = { 1917c66ac9dbSNicholas Bellinger &target_core_alua_lu_gp_lu_gp_id.attr, 1918c66ac9dbSNicholas Bellinger &target_core_alua_lu_gp_members.attr, 1919c66ac9dbSNicholas Bellinger NULL, 1920c66ac9dbSNicholas Bellinger }; 1921c66ac9dbSNicholas Bellinger 19221f6fe7cbSNicholas Bellinger static void target_core_alua_lu_gp_release(struct config_item *item) 19231f6fe7cbSNicholas Bellinger { 19241f6fe7cbSNicholas Bellinger struct t10_alua_lu_gp *lu_gp = container_of(to_config_group(item), 19251f6fe7cbSNicholas Bellinger struct t10_alua_lu_gp, lu_gp_group); 19261f6fe7cbSNicholas Bellinger 19271f6fe7cbSNicholas Bellinger core_alua_free_lu_gp(lu_gp); 19281f6fe7cbSNicholas Bellinger } 19291f6fe7cbSNicholas Bellinger 1930c66ac9dbSNicholas Bellinger static struct configfs_item_operations target_core_alua_lu_gp_ops = { 19311f6fe7cbSNicholas Bellinger .release = target_core_alua_lu_gp_release, 1932c66ac9dbSNicholas Bellinger .show_attribute = target_core_alua_lu_gp_attr_show, 1933c66ac9dbSNicholas Bellinger .store_attribute = target_core_alua_lu_gp_attr_store, 1934c66ac9dbSNicholas Bellinger }; 1935c66ac9dbSNicholas Bellinger 1936c66ac9dbSNicholas Bellinger static struct config_item_type target_core_alua_lu_gp_cit = { 1937c66ac9dbSNicholas Bellinger .ct_item_ops = &target_core_alua_lu_gp_ops, 1938c66ac9dbSNicholas Bellinger .ct_attrs = target_core_alua_lu_gp_attrs, 1939c66ac9dbSNicholas Bellinger .ct_owner = THIS_MODULE, 1940c66ac9dbSNicholas Bellinger }; 1941c66ac9dbSNicholas Bellinger 1942c66ac9dbSNicholas Bellinger /* End functions for struct config_item_type target_core_alua_lu_gp_cit */ 1943c66ac9dbSNicholas Bellinger 1944c66ac9dbSNicholas Bellinger /* Start functions for struct config_item_type target_core_alua_lu_gps_cit */ 1945c66ac9dbSNicholas Bellinger 1946c66ac9dbSNicholas Bellinger static struct config_group *target_core_alua_create_lu_gp( 1947c66ac9dbSNicholas Bellinger struct config_group *group, 1948c66ac9dbSNicholas Bellinger const char *name) 1949c66ac9dbSNicholas Bellinger { 1950c66ac9dbSNicholas Bellinger struct t10_alua_lu_gp *lu_gp; 1951c66ac9dbSNicholas Bellinger struct config_group *alua_lu_gp_cg = NULL; 1952c66ac9dbSNicholas Bellinger struct config_item *alua_lu_gp_ci = NULL; 1953c66ac9dbSNicholas Bellinger 1954c66ac9dbSNicholas Bellinger lu_gp = core_alua_allocate_lu_gp(name, 0); 1955c66ac9dbSNicholas Bellinger if (IS_ERR(lu_gp)) 1956c66ac9dbSNicholas Bellinger return NULL; 1957c66ac9dbSNicholas Bellinger 1958c66ac9dbSNicholas Bellinger alua_lu_gp_cg = &lu_gp->lu_gp_group; 1959c66ac9dbSNicholas Bellinger alua_lu_gp_ci = &alua_lu_gp_cg->cg_item; 1960c66ac9dbSNicholas Bellinger 1961c66ac9dbSNicholas Bellinger config_group_init_type_name(alua_lu_gp_cg, name, 1962c66ac9dbSNicholas Bellinger &target_core_alua_lu_gp_cit); 1963c66ac9dbSNicholas Bellinger 19646708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: Allocated ALUA Logical Unit" 1965c66ac9dbSNicholas Bellinger " Group: core/alua/lu_gps/%s\n", 1966c66ac9dbSNicholas Bellinger config_item_name(alua_lu_gp_ci)); 1967c66ac9dbSNicholas Bellinger 1968c66ac9dbSNicholas Bellinger return alua_lu_gp_cg; 1969c66ac9dbSNicholas Bellinger 1970c66ac9dbSNicholas Bellinger } 1971c66ac9dbSNicholas Bellinger 1972c66ac9dbSNicholas Bellinger static void target_core_alua_drop_lu_gp( 1973c66ac9dbSNicholas Bellinger struct config_group *group, 1974c66ac9dbSNicholas Bellinger struct config_item *item) 1975c66ac9dbSNicholas Bellinger { 1976c66ac9dbSNicholas Bellinger struct t10_alua_lu_gp *lu_gp = container_of(to_config_group(item), 1977c66ac9dbSNicholas Bellinger struct t10_alua_lu_gp, lu_gp_group); 1978c66ac9dbSNicholas Bellinger 19796708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: Releasing ALUA Logical Unit" 1980c66ac9dbSNicholas Bellinger " Group: core/alua/lu_gps/%s, ID: %hu\n", 1981c66ac9dbSNicholas Bellinger config_item_name(item), lu_gp->lu_gp_id); 19821f6fe7cbSNicholas Bellinger /* 19831f6fe7cbSNicholas Bellinger * core_alua_free_lu_gp() is called from target_core_alua_lu_gp_ops->release() 19841f6fe7cbSNicholas Bellinger * -> target_core_alua_lu_gp_release() 19851f6fe7cbSNicholas Bellinger */ 1986c66ac9dbSNicholas Bellinger config_item_put(item); 1987c66ac9dbSNicholas Bellinger } 1988c66ac9dbSNicholas Bellinger 1989c66ac9dbSNicholas Bellinger static struct configfs_group_operations target_core_alua_lu_gps_group_ops = { 1990c66ac9dbSNicholas Bellinger .make_group = &target_core_alua_create_lu_gp, 1991c66ac9dbSNicholas Bellinger .drop_item = &target_core_alua_drop_lu_gp, 1992c66ac9dbSNicholas Bellinger }; 1993c66ac9dbSNicholas Bellinger 1994c66ac9dbSNicholas Bellinger static struct config_item_type target_core_alua_lu_gps_cit = { 1995c66ac9dbSNicholas Bellinger .ct_item_ops = NULL, 1996c66ac9dbSNicholas Bellinger .ct_group_ops = &target_core_alua_lu_gps_group_ops, 1997c66ac9dbSNicholas Bellinger .ct_owner = THIS_MODULE, 1998c66ac9dbSNicholas Bellinger }; 1999c66ac9dbSNicholas Bellinger 2000c66ac9dbSNicholas Bellinger /* End functions for struct config_item_type target_core_alua_lu_gps_cit */ 2001c66ac9dbSNicholas Bellinger 2002c66ac9dbSNicholas Bellinger /* Start functions for struct config_item_type target_core_alua_tg_pt_gp_cit */ 2003c66ac9dbSNicholas Bellinger 2004c66ac9dbSNicholas Bellinger CONFIGFS_EATTR_STRUCT(target_core_alua_tg_pt_gp, t10_alua_tg_pt_gp); 2005c66ac9dbSNicholas Bellinger #define SE_DEV_ALUA_TG_PT_ATTR(_name, _mode) \ 2006c66ac9dbSNicholas Bellinger static struct target_core_alua_tg_pt_gp_attribute \ 2007c66ac9dbSNicholas Bellinger target_core_alua_tg_pt_gp_##_name = \ 2008c66ac9dbSNicholas Bellinger __CONFIGFS_EATTR(_name, _mode, \ 2009c66ac9dbSNicholas Bellinger target_core_alua_tg_pt_gp_show_attr_##_name, \ 2010c66ac9dbSNicholas Bellinger target_core_alua_tg_pt_gp_store_attr_##_name); 2011c66ac9dbSNicholas Bellinger 2012c66ac9dbSNicholas Bellinger #define SE_DEV_ALUA_TG_PT_ATTR_RO(_name) \ 2013c66ac9dbSNicholas Bellinger static struct target_core_alua_tg_pt_gp_attribute \ 2014c66ac9dbSNicholas Bellinger target_core_alua_tg_pt_gp_##_name = \ 2015c66ac9dbSNicholas Bellinger __CONFIGFS_EATTR_RO(_name, \ 2016c66ac9dbSNicholas Bellinger target_core_alua_tg_pt_gp_show_attr_##_name); 2017c66ac9dbSNicholas Bellinger 2018c66ac9dbSNicholas Bellinger /* 2019c66ac9dbSNicholas Bellinger * alua_access_state 2020c66ac9dbSNicholas Bellinger */ 2021c66ac9dbSNicholas Bellinger static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_access_state( 2022c66ac9dbSNicholas Bellinger struct t10_alua_tg_pt_gp *tg_pt_gp, 2023c66ac9dbSNicholas Bellinger char *page) 2024c66ac9dbSNicholas Bellinger { 2025c66ac9dbSNicholas Bellinger return sprintf(page, "%d\n", 2026c66ac9dbSNicholas Bellinger atomic_read(&tg_pt_gp->tg_pt_gp_alua_access_state)); 2027c66ac9dbSNicholas Bellinger } 2028c66ac9dbSNicholas Bellinger 2029c66ac9dbSNicholas Bellinger static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_access_state( 2030c66ac9dbSNicholas Bellinger struct t10_alua_tg_pt_gp *tg_pt_gp, 2031c66ac9dbSNicholas Bellinger const char *page, 2032c66ac9dbSNicholas Bellinger size_t count) 2033c66ac9dbSNicholas Bellinger { 20340fd97ccfSChristoph Hellwig struct se_device *dev = tg_pt_gp->tg_pt_gp_dev; 2035c66ac9dbSNicholas Bellinger unsigned long tmp; 2036c66ac9dbSNicholas Bellinger int new_state, ret; 2037c66ac9dbSNicholas Bellinger 20386708bb27SAndy Grover if (!tg_pt_gp->tg_pt_gp_valid_id) { 20396708bb27SAndy Grover pr_err("Unable to do implict ALUA on non valid" 2040c66ac9dbSNicholas Bellinger " tg_pt_gp ID: %hu\n", tg_pt_gp->tg_pt_gp_valid_id); 2041c66ac9dbSNicholas Bellinger return -EINVAL; 2042c66ac9dbSNicholas Bellinger } 2043c66ac9dbSNicholas Bellinger 204457103d7fSJingoo Han ret = kstrtoul(page, 0, &tmp); 2045c66ac9dbSNicholas Bellinger if (ret < 0) { 20466708bb27SAndy Grover pr_err("Unable to extract new ALUA access state from" 2047c66ac9dbSNicholas Bellinger " %s\n", page); 204857103d7fSJingoo Han return ret; 2049c66ac9dbSNicholas Bellinger } 2050c66ac9dbSNicholas Bellinger new_state = (int)tmp; 2051c66ac9dbSNicholas Bellinger 2052c66ac9dbSNicholas Bellinger if (!(tg_pt_gp->tg_pt_gp_alua_access_type & TPGS_IMPLICT_ALUA)) { 20536708bb27SAndy Grover pr_err("Unable to process implict configfs ALUA" 20545e58b029SMasanari Iida " transition while TPGS_IMPLICT_ALUA is disabled\n"); 2055c66ac9dbSNicholas Bellinger return -EINVAL; 2056c66ac9dbSNicholas Bellinger } 2057c66ac9dbSNicholas Bellinger 20580fd97ccfSChristoph Hellwig ret = core_alua_do_port_transition(tg_pt_gp, dev, 2059c66ac9dbSNicholas Bellinger NULL, NULL, new_state, 0); 2060c66ac9dbSNicholas Bellinger return (!ret) ? count : -EINVAL; 2061c66ac9dbSNicholas Bellinger } 2062c66ac9dbSNicholas Bellinger 2063c66ac9dbSNicholas Bellinger SE_DEV_ALUA_TG_PT_ATTR(alua_access_state, S_IRUGO | S_IWUSR); 2064c66ac9dbSNicholas Bellinger 2065c66ac9dbSNicholas Bellinger /* 2066c66ac9dbSNicholas Bellinger * alua_access_status 2067c66ac9dbSNicholas Bellinger */ 2068c66ac9dbSNicholas Bellinger static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_access_status( 2069c66ac9dbSNicholas Bellinger struct t10_alua_tg_pt_gp *tg_pt_gp, 2070c66ac9dbSNicholas Bellinger char *page) 2071c66ac9dbSNicholas Bellinger { 2072c66ac9dbSNicholas Bellinger return sprintf(page, "%s\n", 2073c66ac9dbSNicholas Bellinger core_alua_dump_status(tg_pt_gp->tg_pt_gp_alua_access_status)); 2074c66ac9dbSNicholas Bellinger } 2075c66ac9dbSNicholas Bellinger 2076c66ac9dbSNicholas Bellinger static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_access_status( 2077c66ac9dbSNicholas Bellinger struct t10_alua_tg_pt_gp *tg_pt_gp, 2078c66ac9dbSNicholas Bellinger const char *page, 2079c66ac9dbSNicholas Bellinger size_t count) 2080c66ac9dbSNicholas Bellinger { 2081c66ac9dbSNicholas Bellinger unsigned long tmp; 2082c66ac9dbSNicholas Bellinger int new_status, ret; 2083c66ac9dbSNicholas Bellinger 20846708bb27SAndy Grover if (!tg_pt_gp->tg_pt_gp_valid_id) { 20856708bb27SAndy Grover pr_err("Unable to do set ALUA access status on non" 2086c66ac9dbSNicholas Bellinger " valid tg_pt_gp ID: %hu\n", 2087c66ac9dbSNicholas Bellinger tg_pt_gp->tg_pt_gp_valid_id); 2088c66ac9dbSNicholas Bellinger return -EINVAL; 2089c66ac9dbSNicholas Bellinger } 2090c66ac9dbSNicholas Bellinger 209157103d7fSJingoo Han ret = kstrtoul(page, 0, &tmp); 2092c66ac9dbSNicholas Bellinger if (ret < 0) { 20936708bb27SAndy Grover pr_err("Unable to extract new ALUA access status" 2094c66ac9dbSNicholas Bellinger " from %s\n", page); 209557103d7fSJingoo Han return ret; 2096c66ac9dbSNicholas Bellinger } 2097c66ac9dbSNicholas Bellinger new_status = (int)tmp; 2098c66ac9dbSNicholas Bellinger 2099c66ac9dbSNicholas Bellinger if ((new_status != ALUA_STATUS_NONE) && 2100c66ac9dbSNicholas Bellinger (new_status != ALUA_STATUS_ALTERED_BY_EXPLICT_STPG) && 2101c66ac9dbSNicholas Bellinger (new_status != ALUA_STATUS_ALTERED_BY_IMPLICT_ALUA)) { 21026708bb27SAndy Grover pr_err("Illegal ALUA access status: 0x%02x\n", 2103c66ac9dbSNicholas Bellinger new_status); 2104c66ac9dbSNicholas Bellinger return -EINVAL; 2105c66ac9dbSNicholas Bellinger } 2106c66ac9dbSNicholas Bellinger 2107c66ac9dbSNicholas Bellinger tg_pt_gp->tg_pt_gp_alua_access_status = new_status; 2108c66ac9dbSNicholas Bellinger return count; 2109c66ac9dbSNicholas Bellinger } 2110c66ac9dbSNicholas Bellinger 2111c66ac9dbSNicholas Bellinger SE_DEV_ALUA_TG_PT_ATTR(alua_access_status, S_IRUGO | S_IWUSR); 2112c66ac9dbSNicholas Bellinger 2113c66ac9dbSNicholas Bellinger /* 2114c66ac9dbSNicholas Bellinger * alua_access_type 2115c66ac9dbSNicholas Bellinger */ 2116c66ac9dbSNicholas Bellinger static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_access_type( 2117c66ac9dbSNicholas Bellinger struct t10_alua_tg_pt_gp *tg_pt_gp, 2118c66ac9dbSNicholas Bellinger char *page) 2119c66ac9dbSNicholas Bellinger { 2120c66ac9dbSNicholas Bellinger return core_alua_show_access_type(tg_pt_gp, page); 2121c66ac9dbSNicholas Bellinger } 2122c66ac9dbSNicholas Bellinger 2123c66ac9dbSNicholas Bellinger static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_access_type( 2124c66ac9dbSNicholas Bellinger struct t10_alua_tg_pt_gp *tg_pt_gp, 2125c66ac9dbSNicholas Bellinger const char *page, 2126c66ac9dbSNicholas Bellinger size_t count) 2127c66ac9dbSNicholas Bellinger { 2128c66ac9dbSNicholas Bellinger return core_alua_store_access_type(tg_pt_gp, page, count); 2129c66ac9dbSNicholas Bellinger } 2130c66ac9dbSNicholas Bellinger 2131c66ac9dbSNicholas Bellinger SE_DEV_ALUA_TG_PT_ATTR(alua_access_type, S_IRUGO | S_IWUSR); 2132c66ac9dbSNicholas Bellinger 2133c66ac9dbSNicholas Bellinger /* 2134c66ac9dbSNicholas Bellinger * alua_write_metadata 2135c66ac9dbSNicholas Bellinger */ 2136c66ac9dbSNicholas Bellinger static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_write_metadata( 2137c66ac9dbSNicholas Bellinger struct t10_alua_tg_pt_gp *tg_pt_gp, 2138c66ac9dbSNicholas Bellinger char *page) 2139c66ac9dbSNicholas Bellinger { 2140c66ac9dbSNicholas Bellinger return sprintf(page, "%d\n", tg_pt_gp->tg_pt_gp_write_metadata); 2141c66ac9dbSNicholas Bellinger } 2142c66ac9dbSNicholas Bellinger 2143c66ac9dbSNicholas Bellinger static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_write_metadata( 2144c66ac9dbSNicholas Bellinger struct t10_alua_tg_pt_gp *tg_pt_gp, 2145c66ac9dbSNicholas Bellinger const char *page, 2146c66ac9dbSNicholas Bellinger size_t count) 2147c66ac9dbSNicholas Bellinger { 2148c66ac9dbSNicholas Bellinger unsigned long tmp; 2149c66ac9dbSNicholas Bellinger int ret; 2150c66ac9dbSNicholas Bellinger 215157103d7fSJingoo Han ret = kstrtoul(page, 0, &tmp); 2152c66ac9dbSNicholas Bellinger if (ret < 0) { 21536708bb27SAndy Grover pr_err("Unable to extract alua_write_metadata\n"); 215457103d7fSJingoo Han return ret; 2155c66ac9dbSNicholas Bellinger } 2156c66ac9dbSNicholas Bellinger 2157c66ac9dbSNicholas Bellinger if ((tmp != 0) && (tmp != 1)) { 21586708bb27SAndy Grover pr_err("Illegal value for alua_write_metadata:" 2159c66ac9dbSNicholas Bellinger " %lu\n", tmp); 2160c66ac9dbSNicholas Bellinger return -EINVAL; 2161c66ac9dbSNicholas Bellinger } 2162c66ac9dbSNicholas Bellinger tg_pt_gp->tg_pt_gp_write_metadata = (int)tmp; 2163c66ac9dbSNicholas Bellinger 2164c66ac9dbSNicholas Bellinger return count; 2165c66ac9dbSNicholas Bellinger } 2166c66ac9dbSNicholas Bellinger 2167c66ac9dbSNicholas Bellinger SE_DEV_ALUA_TG_PT_ATTR(alua_write_metadata, S_IRUGO | S_IWUSR); 2168c66ac9dbSNicholas Bellinger 2169c66ac9dbSNicholas Bellinger 2170c66ac9dbSNicholas Bellinger 2171c66ac9dbSNicholas Bellinger /* 2172c66ac9dbSNicholas Bellinger * nonop_delay_msecs 2173c66ac9dbSNicholas Bellinger */ 2174c66ac9dbSNicholas Bellinger static ssize_t target_core_alua_tg_pt_gp_show_attr_nonop_delay_msecs( 2175c66ac9dbSNicholas Bellinger struct t10_alua_tg_pt_gp *tg_pt_gp, 2176c66ac9dbSNicholas Bellinger char *page) 2177c66ac9dbSNicholas Bellinger { 2178c66ac9dbSNicholas Bellinger return core_alua_show_nonop_delay_msecs(tg_pt_gp, page); 2179c66ac9dbSNicholas Bellinger 2180c66ac9dbSNicholas Bellinger } 2181c66ac9dbSNicholas Bellinger 2182c66ac9dbSNicholas Bellinger static ssize_t target_core_alua_tg_pt_gp_store_attr_nonop_delay_msecs( 2183c66ac9dbSNicholas Bellinger struct t10_alua_tg_pt_gp *tg_pt_gp, 2184c66ac9dbSNicholas Bellinger const char *page, 2185c66ac9dbSNicholas Bellinger size_t count) 2186c66ac9dbSNicholas Bellinger { 2187c66ac9dbSNicholas Bellinger return core_alua_store_nonop_delay_msecs(tg_pt_gp, page, count); 2188c66ac9dbSNicholas Bellinger } 2189c66ac9dbSNicholas Bellinger 2190c66ac9dbSNicholas Bellinger SE_DEV_ALUA_TG_PT_ATTR(nonop_delay_msecs, S_IRUGO | S_IWUSR); 2191c66ac9dbSNicholas Bellinger 2192c66ac9dbSNicholas Bellinger /* 2193c66ac9dbSNicholas Bellinger * trans_delay_msecs 2194c66ac9dbSNicholas Bellinger */ 2195c66ac9dbSNicholas Bellinger static ssize_t target_core_alua_tg_pt_gp_show_attr_trans_delay_msecs( 2196c66ac9dbSNicholas Bellinger struct t10_alua_tg_pt_gp *tg_pt_gp, 2197c66ac9dbSNicholas Bellinger char *page) 2198c66ac9dbSNicholas Bellinger { 2199c66ac9dbSNicholas Bellinger return core_alua_show_trans_delay_msecs(tg_pt_gp, page); 2200c66ac9dbSNicholas Bellinger } 2201c66ac9dbSNicholas Bellinger 2202c66ac9dbSNicholas Bellinger static ssize_t target_core_alua_tg_pt_gp_store_attr_trans_delay_msecs( 2203c66ac9dbSNicholas Bellinger struct t10_alua_tg_pt_gp *tg_pt_gp, 2204c66ac9dbSNicholas Bellinger const char *page, 2205c66ac9dbSNicholas Bellinger size_t count) 2206c66ac9dbSNicholas Bellinger { 2207c66ac9dbSNicholas Bellinger return core_alua_store_trans_delay_msecs(tg_pt_gp, page, count); 2208c66ac9dbSNicholas Bellinger } 2209c66ac9dbSNicholas Bellinger 2210c66ac9dbSNicholas Bellinger SE_DEV_ALUA_TG_PT_ATTR(trans_delay_msecs, S_IRUGO | S_IWUSR); 2211c66ac9dbSNicholas Bellinger 2212c66ac9dbSNicholas Bellinger /* 22135b9a4d72SNicholas Bellinger * implict_trans_secs 22145b9a4d72SNicholas Bellinger */ 22155b9a4d72SNicholas Bellinger static ssize_t target_core_alua_tg_pt_gp_show_attr_implict_trans_secs( 22165b9a4d72SNicholas Bellinger struct t10_alua_tg_pt_gp *tg_pt_gp, 22175b9a4d72SNicholas Bellinger char *page) 22185b9a4d72SNicholas Bellinger { 22195b9a4d72SNicholas Bellinger return core_alua_show_implict_trans_secs(tg_pt_gp, page); 22205b9a4d72SNicholas Bellinger } 22215b9a4d72SNicholas Bellinger 22225b9a4d72SNicholas Bellinger static ssize_t target_core_alua_tg_pt_gp_store_attr_implict_trans_secs( 22235b9a4d72SNicholas Bellinger struct t10_alua_tg_pt_gp *tg_pt_gp, 22245b9a4d72SNicholas Bellinger const char *page, 22255b9a4d72SNicholas Bellinger size_t count) 22265b9a4d72SNicholas Bellinger { 22275b9a4d72SNicholas Bellinger return core_alua_store_implict_trans_secs(tg_pt_gp, page, count); 22285b9a4d72SNicholas Bellinger } 22295b9a4d72SNicholas Bellinger 22305b9a4d72SNicholas Bellinger SE_DEV_ALUA_TG_PT_ATTR(implict_trans_secs, S_IRUGO | S_IWUSR); 22315b9a4d72SNicholas Bellinger 22325b9a4d72SNicholas Bellinger /* 2233c66ac9dbSNicholas Bellinger * preferred 2234c66ac9dbSNicholas Bellinger */ 2235c66ac9dbSNicholas Bellinger 2236c66ac9dbSNicholas Bellinger static ssize_t target_core_alua_tg_pt_gp_show_attr_preferred( 2237c66ac9dbSNicholas Bellinger struct t10_alua_tg_pt_gp *tg_pt_gp, 2238c66ac9dbSNicholas Bellinger char *page) 2239c66ac9dbSNicholas Bellinger { 2240c66ac9dbSNicholas Bellinger return core_alua_show_preferred_bit(tg_pt_gp, page); 2241c66ac9dbSNicholas Bellinger } 2242c66ac9dbSNicholas Bellinger 2243c66ac9dbSNicholas Bellinger static ssize_t target_core_alua_tg_pt_gp_store_attr_preferred( 2244c66ac9dbSNicholas Bellinger struct t10_alua_tg_pt_gp *tg_pt_gp, 2245c66ac9dbSNicholas Bellinger const char *page, 2246c66ac9dbSNicholas Bellinger size_t count) 2247c66ac9dbSNicholas Bellinger { 2248c66ac9dbSNicholas Bellinger return core_alua_store_preferred_bit(tg_pt_gp, page, count); 2249c66ac9dbSNicholas Bellinger } 2250c66ac9dbSNicholas Bellinger 2251c66ac9dbSNicholas Bellinger SE_DEV_ALUA_TG_PT_ATTR(preferred, S_IRUGO | S_IWUSR); 2252c66ac9dbSNicholas Bellinger 2253c66ac9dbSNicholas Bellinger /* 2254c66ac9dbSNicholas Bellinger * tg_pt_gp_id 2255c66ac9dbSNicholas Bellinger */ 2256c66ac9dbSNicholas Bellinger static ssize_t target_core_alua_tg_pt_gp_show_attr_tg_pt_gp_id( 2257c66ac9dbSNicholas Bellinger struct t10_alua_tg_pt_gp *tg_pt_gp, 2258c66ac9dbSNicholas Bellinger char *page) 2259c66ac9dbSNicholas Bellinger { 22606708bb27SAndy Grover if (!tg_pt_gp->tg_pt_gp_valid_id) 2261c66ac9dbSNicholas Bellinger return 0; 2262c66ac9dbSNicholas Bellinger 2263c66ac9dbSNicholas Bellinger return sprintf(page, "%hu\n", tg_pt_gp->tg_pt_gp_id); 2264c66ac9dbSNicholas Bellinger } 2265c66ac9dbSNicholas Bellinger 2266c66ac9dbSNicholas Bellinger static ssize_t target_core_alua_tg_pt_gp_store_attr_tg_pt_gp_id( 2267c66ac9dbSNicholas Bellinger struct t10_alua_tg_pt_gp *tg_pt_gp, 2268c66ac9dbSNicholas Bellinger const char *page, 2269c66ac9dbSNicholas Bellinger size_t count) 2270c66ac9dbSNicholas Bellinger { 2271c66ac9dbSNicholas Bellinger struct config_group *alua_tg_pt_gp_cg = &tg_pt_gp->tg_pt_gp_group; 2272c66ac9dbSNicholas Bellinger unsigned long tg_pt_gp_id; 2273c66ac9dbSNicholas Bellinger int ret; 2274c66ac9dbSNicholas Bellinger 227557103d7fSJingoo Han ret = kstrtoul(page, 0, &tg_pt_gp_id); 2276c66ac9dbSNicholas Bellinger if (ret < 0) { 227757103d7fSJingoo Han pr_err("kstrtoul() returned %d for" 2278c66ac9dbSNicholas Bellinger " tg_pt_gp_id\n", ret); 227957103d7fSJingoo Han return ret; 2280c66ac9dbSNicholas Bellinger } 2281c66ac9dbSNicholas Bellinger if (tg_pt_gp_id > 0x0000ffff) { 22826708bb27SAndy Grover pr_err("ALUA tg_pt_gp_id: %lu exceeds maximum:" 2283c66ac9dbSNicholas Bellinger " 0x0000ffff\n", tg_pt_gp_id); 2284c66ac9dbSNicholas Bellinger return -EINVAL; 2285c66ac9dbSNicholas Bellinger } 2286c66ac9dbSNicholas Bellinger 2287c66ac9dbSNicholas Bellinger ret = core_alua_set_tg_pt_gp_id(tg_pt_gp, (u16)tg_pt_gp_id); 2288c66ac9dbSNicholas Bellinger if (ret < 0) 2289c66ac9dbSNicholas Bellinger return -EINVAL; 2290c66ac9dbSNicholas Bellinger 22916708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: Set ALUA Target Port Group: " 2292c66ac9dbSNicholas Bellinger "core/alua/tg_pt_gps/%s to ID: %hu\n", 2293c66ac9dbSNicholas Bellinger config_item_name(&alua_tg_pt_gp_cg->cg_item), 2294c66ac9dbSNicholas Bellinger tg_pt_gp->tg_pt_gp_id); 2295c66ac9dbSNicholas Bellinger 2296c66ac9dbSNicholas Bellinger return count; 2297c66ac9dbSNicholas Bellinger } 2298c66ac9dbSNicholas Bellinger 2299c66ac9dbSNicholas Bellinger SE_DEV_ALUA_TG_PT_ATTR(tg_pt_gp_id, S_IRUGO | S_IWUSR); 2300c66ac9dbSNicholas Bellinger 2301c66ac9dbSNicholas Bellinger /* 2302c66ac9dbSNicholas Bellinger * members 2303c66ac9dbSNicholas Bellinger */ 2304c66ac9dbSNicholas Bellinger static ssize_t target_core_alua_tg_pt_gp_show_attr_members( 2305c66ac9dbSNicholas Bellinger struct t10_alua_tg_pt_gp *tg_pt_gp, 2306c66ac9dbSNicholas Bellinger char *page) 2307c66ac9dbSNicholas Bellinger { 2308c66ac9dbSNicholas Bellinger struct se_port *port; 2309c66ac9dbSNicholas Bellinger struct se_portal_group *tpg; 2310c66ac9dbSNicholas Bellinger struct se_lun *lun; 2311c66ac9dbSNicholas Bellinger struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem; 2312c66ac9dbSNicholas Bellinger ssize_t len = 0, cur_len; 2313c66ac9dbSNicholas Bellinger unsigned char buf[TG_PT_GROUP_NAME_BUF]; 2314c66ac9dbSNicholas Bellinger 2315c66ac9dbSNicholas Bellinger memset(buf, 0, TG_PT_GROUP_NAME_BUF); 2316c66ac9dbSNicholas Bellinger 2317c66ac9dbSNicholas Bellinger spin_lock(&tg_pt_gp->tg_pt_gp_lock); 2318c66ac9dbSNicholas Bellinger list_for_each_entry(tg_pt_gp_mem, &tg_pt_gp->tg_pt_gp_mem_list, 2319c66ac9dbSNicholas Bellinger tg_pt_gp_mem_list) { 2320c66ac9dbSNicholas Bellinger port = tg_pt_gp_mem->tg_pt; 2321c66ac9dbSNicholas Bellinger tpg = port->sep_tpg; 2322c66ac9dbSNicholas Bellinger lun = port->sep_lun; 2323c66ac9dbSNicholas Bellinger 2324c66ac9dbSNicholas Bellinger cur_len = snprintf(buf, TG_PT_GROUP_NAME_BUF, "%s/%s/tpgt_%hu" 2325e3d6f909SAndy Grover "/%s\n", tpg->se_tpg_tfo->get_fabric_name(), 2326e3d6f909SAndy Grover tpg->se_tpg_tfo->tpg_get_wwn(tpg), 2327e3d6f909SAndy Grover tpg->se_tpg_tfo->tpg_get_tag(tpg), 2328c66ac9dbSNicholas Bellinger config_item_name(&lun->lun_group.cg_item)); 2329c66ac9dbSNicholas Bellinger cur_len++; /* Extra byte for NULL terminator */ 2330c66ac9dbSNicholas Bellinger 2331c66ac9dbSNicholas Bellinger if ((cur_len + len) > PAGE_SIZE) { 23326708bb27SAndy Grover pr_warn("Ran out of lu_gp_show_attr" 2333c66ac9dbSNicholas Bellinger "_members buffer\n"); 2334c66ac9dbSNicholas Bellinger break; 2335c66ac9dbSNicholas Bellinger } 2336c66ac9dbSNicholas Bellinger memcpy(page+len, buf, cur_len); 2337c66ac9dbSNicholas Bellinger len += cur_len; 2338c66ac9dbSNicholas Bellinger } 2339c66ac9dbSNicholas Bellinger spin_unlock(&tg_pt_gp->tg_pt_gp_lock); 2340c66ac9dbSNicholas Bellinger 2341c66ac9dbSNicholas Bellinger return len; 2342c66ac9dbSNicholas Bellinger } 2343c66ac9dbSNicholas Bellinger 2344c66ac9dbSNicholas Bellinger SE_DEV_ALUA_TG_PT_ATTR_RO(members); 2345c66ac9dbSNicholas Bellinger 2346c66ac9dbSNicholas Bellinger CONFIGFS_EATTR_OPS(target_core_alua_tg_pt_gp, t10_alua_tg_pt_gp, 2347c66ac9dbSNicholas Bellinger tg_pt_gp_group); 2348c66ac9dbSNicholas Bellinger 2349c66ac9dbSNicholas Bellinger static struct configfs_attribute *target_core_alua_tg_pt_gp_attrs[] = { 2350c66ac9dbSNicholas Bellinger &target_core_alua_tg_pt_gp_alua_access_state.attr, 2351c66ac9dbSNicholas Bellinger &target_core_alua_tg_pt_gp_alua_access_status.attr, 2352c66ac9dbSNicholas Bellinger &target_core_alua_tg_pt_gp_alua_access_type.attr, 2353c66ac9dbSNicholas Bellinger &target_core_alua_tg_pt_gp_alua_write_metadata.attr, 2354c66ac9dbSNicholas Bellinger &target_core_alua_tg_pt_gp_nonop_delay_msecs.attr, 2355c66ac9dbSNicholas Bellinger &target_core_alua_tg_pt_gp_trans_delay_msecs.attr, 23565b9a4d72SNicholas Bellinger &target_core_alua_tg_pt_gp_implict_trans_secs.attr, 2357c66ac9dbSNicholas Bellinger &target_core_alua_tg_pt_gp_preferred.attr, 2358c66ac9dbSNicholas Bellinger &target_core_alua_tg_pt_gp_tg_pt_gp_id.attr, 2359c66ac9dbSNicholas Bellinger &target_core_alua_tg_pt_gp_members.attr, 2360c66ac9dbSNicholas Bellinger NULL, 2361c66ac9dbSNicholas Bellinger }; 2362c66ac9dbSNicholas Bellinger 23631f6fe7cbSNicholas Bellinger static void target_core_alua_tg_pt_gp_release(struct config_item *item) 23641f6fe7cbSNicholas Bellinger { 23651f6fe7cbSNicholas Bellinger struct t10_alua_tg_pt_gp *tg_pt_gp = container_of(to_config_group(item), 23661f6fe7cbSNicholas Bellinger struct t10_alua_tg_pt_gp, tg_pt_gp_group); 23671f6fe7cbSNicholas Bellinger 23681f6fe7cbSNicholas Bellinger core_alua_free_tg_pt_gp(tg_pt_gp); 23691f6fe7cbSNicholas Bellinger } 23701f6fe7cbSNicholas Bellinger 2371c66ac9dbSNicholas Bellinger static struct configfs_item_operations target_core_alua_tg_pt_gp_ops = { 23721f6fe7cbSNicholas Bellinger .release = target_core_alua_tg_pt_gp_release, 2373c66ac9dbSNicholas Bellinger .show_attribute = target_core_alua_tg_pt_gp_attr_show, 2374c66ac9dbSNicholas Bellinger .store_attribute = target_core_alua_tg_pt_gp_attr_store, 2375c66ac9dbSNicholas Bellinger }; 2376c66ac9dbSNicholas Bellinger 2377c66ac9dbSNicholas Bellinger static struct config_item_type target_core_alua_tg_pt_gp_cit = { 2378c66ac9dbSNicholas Bellinger .ct_item_ops = &target_core_alua_tg_pt_gp_ops, 2379c66ac9dbSNicholas Bellinger .ct_attrs = target_core_alua_tg_pt_gp_attrs, 2380c66ac9dbSNicholas Bellinger .ct_owner = THIS_MODULE, 2381c66ac9dbSNicholas Bellinger }; 2382c66ac9dbSNicholas Bellinger 2383c66ac9dbSNicholas Bellinger /* End functions for struct config_item_type target_core_alua_tg_pt_gp_cit */ 2384c66ac9dbSNicholas Bellinger 2385c66ac9dbSNicholas Bellinger /* Start functions for struct config_item_type target_core_alua_tg_pt_gps_cit */ 2386c66ac9dbSNicholas Bellinger 2387c66ac9dbSNicholas Bellinger static struct config_group *target_core_alua_create_tg_pt_gp( 2388c66ac9dbSNicholas Bellinger struct config_group *group, 2389c66ac9dbSNicholas Bellinger const char *name) 2390c66ac9dbSNicholas Bellinger { 2391c66ac9dbSNicholas Bellinger struct t10_alua *alua = container_of(group, struct t10_alua, 2392c66ac9dbSNicholas Bellinger alua_tg_pt_gps_group); 2393c66ac9dbSNicholas Bellinger struct t10_alua_tg_pt_gp *tg_pt_gp; 2394c66ac9dbSNicholas Bellinger struct config_group *alua_tg_pt_gp_cg = NULL; 2395c66ac9dbSNicholas Bellinger struct config_item *alua_tg_pt_gp_ci = NULL; 2396c66ac9dbSNicholas Bellinger 23970fd97ccfSChristoph Hellwig tg_pt_gp = core_alua_allocate_tg_pt_gp(alua->t10_dev, name, 0); 23986708bb27SAndy Grover if (!tg_pt_gp) 2399c66ac9dbSNicholas Bellinger return NULL; 2400c66ac9dbSNicholas Bellinger 2401c66ac9dbSNicholas Bellinger alua_tg_pt_gp_cg = &tg_pt_gp->tg_pt_gp_group; 2402c66ac9dbSNicholas Bellinger alua_tg_pt_gp_ci = &alua_tg_pt_gp_cg->cg_item; 2403c66ac9dbSNicholas Bellinger 2404c66ac9dbSNicholas Bellinger config_group_init_type_name(alua_tg_pt_gp_cg, name, 2405c66ac9dbSNicholas Bellinger &target_core_alua_tg_pt_gp_cit); 2406c66ac9dbSNicholas Bellinger 24076708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: Allocated ALUA Target Port" 2408c66ac9dbSNicholas Bellinger " Group: alua/tg_pt_gps/%s\n", 2409c66ac9dbSNicholas Bellinger config_item_name(alua_tg_pt_gp_ci)); 2410c66ac9dbSNicholas Bellinger 2411c66ac9dbSNicholas Bellinger return alua_tg_pt_gp_cg; 2412c66ac9dbSNicholas Bellinger } 2413c66ac9dbSNicholas Bellinger 2414c66ac9dbSNicholas Bellinger static void target_core_alua_drop_tg_pt_gp( 2415c66ac9dbSNicholas Bellinger struct config_group *group, 2416c66ac9dbSNicholas Bellinger struct config_item *item) 2417c66ac9dbSNicholas Bellinger { 2418c66ac9dbSNicholas Bellinger struct t10_alua_tg_pt_gp *tg_pt_gp = container_of(to_config_group(item), 2419c66ac9dbSNicholas Bellinger struct t10_alua_tg_pt_gp, tg_pt_gp_group); 2420c66ac9dbSNicholas Bellinger 24216708bb27SAndy Grover pr_debug("Target_Core_ConfigFS: Releasing ALUA Target Port" 2422c66ac9dbSNicholas Bellinger " Group: alua/tg_pt_gps/%s, ID: %hu\n", 2423c66ac9dbSNicholas Bellinger config_item_name(item), tg_pt_gp->tg_pt_gp_id); 24241f6fe7cbSNicholas Bellinger /* 24251f6fe7cbSNicholas Bellinger * core_alua_free_tg_pt_gp() is called from target_core_alua_tg_pt_gp_ops->release() 24261f6fe7cbSNicholas Bellinger * -> target_core_alua_tg_pt_gp_release(). 24271f6fe7cbSNicholas Bellinger */ 2428c66ac9dbSNicholas Bellinger config_item_put(item); 2429c66ac9dbSNicholas Bellinger } 2430c66ac9dbSNicholas Bellinger 2431c66ac9dbSNicholas Bellinger static struct configfs_group_operations target_core_alua_tg_pt_gps_group_ops = { 2432c66ac9dbSNicholas Bellinger .make_group = &target_core_alua_create_tg_pt_gp, 2433c66ac9dbSNicholas Bellinger .drop_item = &target_core_alua_drop_tg_pt_gp, 2434c66ac9dbSNicholas Bellinger }; 2435c66ac9dbSNicholas Bellinger 2436c66ac9dbSNicholas Bellinger static struct config_item_type target_core_alua_tg_pt_gps_cit = { 2437c66ac9dbSNicholas Bellinger .ct_group_ops = &target_core_alua_tg_pt_gps_group_ops, 2438c66ac9dbSNicholas Bellinger .ct_owner = THIS_MODULE, 2439c66ac9dbSNicholas Bellinger }; 2440c66ac9dbSNicholas Bellinger 2441c66ac9dbSNicholas Bellinger /* End functions for struct config_item_type target_core_alua_tg_pt_gps_cit */ 2442c66ac9dbSNicholas Bellinger 2443c66ac9dbSNicholas Bellinger /* Start functions for struct config_item_type target_core_alua_cit */ 2444c66ac9dbSNicholas Bellinger 2445c66ac9dbSNicholas Bellinger /* 2446c66ac9dbSNicholas Bellinger * target_core_alua_cit is a ConfigFS group that lives under 2447c66ac9dbSNicholas Bellinger * /sys/kernel/config/target/core/alua. There are default groups 2448c66ac9dbSNicholas Bellinger * core/alua/lu_gps and core/alua/tg_pt_gps that are attached to 2449c66ac9dbSNicholas Bellinger * target_core_alua_cit in target_core_init_configfs() below. 2450c66ac9dbSNicholas Bellinger */ 2451c66ac9dbSNicholas Bellinger static struct config_item_type target_core_alua_cit = { 2452c66ac9dbSNicholas Bellinger .ct_item_ops = NULL, 2453c66ac9dbSNicholas Bellinger .ct_attrs = NULL, 2454c66ac9dbSNicholas Bellinger .ct_owner = THIS_MODULE, 2455c66ac9dbSNicholas Bellinger }; 2456c66ac9dbSNicholas Bellinger 2457c66ac9dbSNicholas Bellinger /* End functions for struct config_item_type target_core_alua_cit */ 2458c66ac9dbSNicholas Bellinger 245912d23384SNicholas Bellinger /* Start functions for struct config_item_type target_core_stat_cit */ 246012d23384SNicholas Bellinger 246112d23384SNicholas Bellinger static struct config_group *target_core_stat_mkdir( 246212d23384SNicholas Bellinger struct config_group *group, 246312d23384SNicholas Bellinger const char *name) 246412d23384SNicholas Bellinger { 246512d23384SNicholas Bellinger return ERR_PTR(-ENOSYS); 246612d23384SNicholas Bellinger } 246712d23384SNicholas Bellinger 246812d23384SNicholas Bellinger static void target_core_stat_rmdir( 246912d23384SNicholas Bellinger struct config_group *group, 247012d23384SNicholas Bellinger struct config_item *item) 247112d23384SNicholas Bellinger { 247212d23384SNicholas Bellinger return; 247312d23384SNicholas Bellinger } 247412d23384SNicholas Bellinger 247512d23384SNicholas Bellinger static struct configfs_group_operations target_core_stat_group_ops = { 247612d23384SNicholas Bellinger .make_group = &target_core_stat_mkdir, 247712d23384SNicholas Bellinger .drop_item = &target_core_stat_rmdir, 247812d23384SNicholas Bellinger }; 247912d23384SNicholas Bellinger 248012d23384SNicholas Bellinger static struct config_item_type target_core_stat_cit = { 248112d23384SNicholas Bellinger .ct_group_ops = &target_core_stat_group_ops, 248212d23384SNicholas Bellinger .ct_owner = THIS_MODULE, 248312d23384SNicholas Bellinger }; 248412d23384SNicholas Bellinger 248512d23384SNicholas Bellinger /* End functions for struct config_item_type target_core_stat_cit */ 248612d23384SNicholas Bellinger 2487c66ac9dbSNicholas Bellinger /* Start functions for struct config_item_type target_core_hba_cit */ 2488c66ac9dbSNicholas Bellinger 2489c66ac9dbSNicholas Bellinger static struct config_group *target_core_make_subdev( 2490c66ac9dbSNicholas Bellinger struct config_group *group, 2491c66ac9dbSNicholas Bellinger const char *name) 2492c66ac9dbSNicholas Bellinger { 2493c66ac9dbSNicholas Bellinger struct t10_alua_tg_pt_gp *tg_pt_gp; 2494c66ac9dbSNicholas Bellinger struct se_subsystem_api *t; 2495c66ac9dbSNicholas Bellinger struct config_item *hba_ci = &group->cg_item; 2496c66ac9dbSNicholas Bellinger struct se_hba *hba = item_to_hba(hba_ci); 24970fd97ccfSChristoph Hellwig struct se_device *dev; 2498c66ac9dbSNicholas Bellinger struct config_group *dev_cg = NULL, *tg_pt_gp_cg = NULL; 249912d23384SNicholas Bellinger struct config_group *dev_stat_grp = NULL; 250012d23384SNicholas Bellinger int errno = -ENOMEM, ret; 2501c66ac9dbSNicholas Bellinger 250212d23384SNicholas Bellinger ret = mutex_lock_interruptible(&hba->hba_access_mutex); 250312d23384SNicholas Bellinger if (ret) 250412d23384SNicholas Bellinger return ERR_PTR(ret); 2505c66ac9dbSNicholas Bellinger /* 2506c66ac9dbSNicholas Bellinger * Locate the struct se_subsystem_api from parent's struct se_hba. 2507c66ac9dbSNicholas Bellinger */ 2508c66ac9dbSNicholas Bellinger t = hba->transport; 2509c66ac9dbSNicholas Bellinger 25100fd97ccfSChristoph Hellwig dev = target_alloc_device(hba, name); 25110fd97ccfSChristoph Hellwig if (!dev) 25120fd97ccfSChristoph Hellwig goto out_unlock; 2513c66ac9dbSNicholas Bellinger 25140fd97ccfSChristoph Hellwig dev_cg = &dev->dev_group; 2515c66ac9dbSNicholas Bellinger 251613f6a914SSebastian Andrzej Siewior dev_cg->default_groups = kmalloc(sizeof(struct config_group *) * 6, 2517c66ac9dbSNicholas Bellinger GFP_KERNEL); 25186708bb27SAndy Grover if (!dev_cg->default_groups) 25190fd97ccfSChristoph Hellwig goto out_free_device; 2520c66ac9dbSNicholas Bellinger 25210fd97ccfSChristoph Hellwig config_group_init_type_name(dev_cg, name, &target_core_dev_cit); 25220fd97ccfSChristoph Hellwig config_group_init_type_name(&dev->dev_attrib.da_group, "attrib", 2523c66ac9dbSNicholas Bellinger &target_core_dev_attrib_cit); 25240fd97ccfSChristoph Hellwig config_group_init_type_name(&dev->dev_pr_group, "pr", 2525c66ac9dbSNicholas Bellinger &target_core_dev_pr_cit); 25260fd97ccfSChristoph Hellwig config_group_init_type_name(&dev->t10_wwn.t10_wwn_group, "wwn", 2527c66ac9dbSNicholas Bellinger &target_core_dev_wwn_cit); 25280fd97ccfSChristoph Hellwig config_group_init_type_name(&dev->t10_alua.alua_tg_pt_gps_group, 2529c66ac9dbSNicholas Bellinger "alua", &target_core_alua_tg_pt_gps_cit); 25300fd97ccfSChristoph Hellwig config_group_init_type_name(&dev->dev_stat_grps.stat_group, 253112d23384SNicholas Bellinger "statistics", &target_core_stat_cit); 253212d23384SNicholas Bellinger 25330fd97ccfSChristoph Hellwig dev_cg->default_groups[0] = &dev->dev_attrib.da_group; 25340fd97ccfSChristoph Hellwig dev_cg->default_groups[1] = &dev->dev_pr_group; 25350fd97ccfSChristoph Hellwig dev_cg->default_groups[2] = &dev->t10_wwn.t10_wwn_group; 25360fd97ccfSChristoph Hellwig dev_cg->default_groups[3] = &dev->t10_alua.alua_tg_pt_gps_group; 25370fd97ccfSChristoph Hellwig dev_cg->default_groups[4] = &dev->dev_stat_grps.stat_group; 253812d23384SNicholas Bellinger dev_cg->default_groups[5] = NULL; 2539c66ac9dbSNicholas Bellinger /* 254012d23384SNicholas Bellinger * Add core/$HBA/$DEV/alua/default_tg_pt_gp 2541c66ac9dbSNicholas Bellinger */ 25420fd97ccfSChristoph Hellwig tg_pt_gp = core_alua_allocate_tg_pt_gp(dev, "default_tg_pt_gp", 1); 25436708bb27SAndy Grover if (!tg_pt_gp) 25440fd97ccfSChristoph Hellwig goto out_free_dev_cg_default_groups; 25450fd97ccfSChristoph Hellwig dev->t10_alua.default_tg_pt_gp = tg_pt_gp; 2546c66ac9dbSNicholas Bellinger 25470fd97ccfSChristoph Hellwig tg_pt_gp_cg = &dev->t10_alua.alua_tg_pt_gps_group; 254813f6a914SSebastian Andrzej Siewior tg_pt_gp_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, 2549c66ac9dbSNicholas Bellinger GFP_KERNEL); 25506708bb27SAndy Grover if (!tg_pt_gp_cg->default_groups) { 25516708bb27SAndy Grover pr_err("Unable to allocate tg_pt_gp_cg->" 2552c66ac9dbSNicholas Bellinger "default_groups\n"); 25530fd97ccfSChristoph Hellwig goto out_free_tg_pt_gp; 2554c66ac9dbSNicholas Bellinger } 2555c66ac9dbSNicholas Bellinger 2556c66ac9dbSNicholas Bellinger config_group_init_type_name(&tg_pt_gp->tg_pt_gp_group, 2557c66ac9dbSNicholas Bellinger "default_tg_pt_gp", &target_core_alua_tg_pt_gp_cit); 2558c66ac9dbSNicholas Bellinger tg_pt_gp_cg->default_groups[0] = &tg_pt_gp->tg_pt_gp_group; 2559c66ac9dbSNicholas Bellinger tg_pt_gp_cg->default_groups[1] = NULL; 256012d23384SNicholas Bellinger /* 256112d23384SNicholas Bellinger * Add core/$HBA/$DEV/statistics/ default groups 256212d23384SNicholas Bellinger */ 25630fd97ccfSChristoph Hellwig dev_stat_grp = &dev->dev_stat_grps.stat_group; 256413f6a914SSebastian Andrzej Siewior dev_stat_grp->default_groups = kmalloc(sizeof(struct config_group *) * 4, 256512d23384SNicholas Bellinger GFP_KERNEL); 256612d23384SNicholas Bellinger if (!dev_stat_grp->default_groups) { 25676708bb27SAndy Grover pr_err("Unable to allocate dev_stat_grp->default_groups\n"); 25680fd97ccfSChristoph Hellwig goto out_free_tg_pt_gp_cg_default_groups; 256912d23384SNicholas Bellinger } 25700fd97ccfSChristoph Hellwig target_stat_setup_dev_default_groups(dev); 2571c66ac9dbSNicholas Bellinger 2572c66ac9dbSNicholas Bellinger mutex_unlock(&hba->hba_access_mutex); 25730fd97ccfSChristoph Hellwig return dev_cg; 25740fd97ccfSChristoph Hellwig 25750fd97ccfSChristoph Hellwig out_free_tg_pt_gp_cg_default_groups: 2576c66ac9dbSNicholas Bellinger kfree(tg_pt_gp_cg->default_groups); 25770fd97ccfSChristoph Hellwig out_free_tg_pt_gp: 25780fd97ccfSChristoph Hellwig core_alua_free_tg_pt_gp(tg_pt_gp); 25790fd97ccfSChristoph Hellwig out_free_dev_cg_default_groups: 2580c66ac9dbSNicholas Bellinger kfree(dev_cg->default_groups); 25810fd97ccfSChristoph Hellwig out_free_device: 25820fd97ccfSChristoph Hellwig target_free_device(dev); 25830fd97ccfSChristoph Hellwig out_unlock: 2584c66ac9dbSNicholas Bellinger mutex_unlock(&hba->hba_access_mutex); 258512d23384SNicholas Bellinger return ERR_PTR(errno); 2586c66ac9dbSNicholas Bellinger } 2587c66ac9dbSNicholas Bellinger 2588c66ac9dbSNicholas Bellinger static void target_core_drop_subdev( 2589c66ac9dbSNicholas Bellinger struct config_group *group, 2590c66ac9dbSNicholas Bellinger struct config_item *item) 2591c66ac9dbSNicholas Bellinger { 25920fd97ccfSChristoph Hellwig struct config_group *dev_cg = to_config_group(item); 25930fd97ccfSChristoph Hellwig struct se_device *dev = 25940fd97ccfSChristoph Hellwig container_of(dev_cg, struct se_device, dev_group); 2595c66ac9dbSNicholas Bellinger struct se_hba *hba; 2596c66ac9dbSNicholas Bellinger struct config_item *df_item; 25970fd97ccfSChristoph Hellwig struct config_group *tg_pt_gp_cg, *dev_stat_grp; 25981f6fe7cbSNicholas Bellinger int i; 2599c66ac9dbSNicholas Bellinger 26000fd97ccfSChristoph Hellwig hba = item_to_hba(&dev->se_hba->hba_group.cg_item); 2601c66ac9dbSNicholas Bellinger 26021f6fe7cbSNicholas Bellinger mutex_lock(&hba->hba_access_mutex); 2603c66ac9dbSNicholas Bellinger 26040fd97ccfSChristoph Hellwig dev_stat_grp = &dev->dev_stat_grps.stat_group; 260512d23384SNicholas Bellinger for (i = 0; dev_stat_grp->default_groups[i]; i++) { 260612d23384SNicholas Bellinger df_item = &dev_stat_grp->default_groups[i]->cg_item; 260712d23384SNicholas Bellinger dev_stat_grp->default_groups[i] = NULL; 260812d23384SNicholas Bellinger config_item_put(df_item); 260912d23384SNicholas Bellinger } 261012d23384SNicholas Bellinger kfree(dev_stat_grp->default_groups); 261112d23384SNicholas Bellinger 26120fd97ccfSChristoph Hellwig tg_pt_gp_cg = &dev->t10_alua.alua_tg_pt_gps_group; 2613c66ac9dbSNicholas Bellinger for (i = 0; tg_pt_gp_cg->default_groups[i]; i++) { 2614c66ac9dbSNicholas Bellinger df_item = &tg_pt_gp_cg->default_groups[i]->cg_item; 2615c66ac9dbSNicholas Bellinger tg_pt_gp_cg->default_groups[i] = NULL; 2616c66ac9dbSNicholas Bellinger config_item_put(df_item); 2617c66ac9dbSNicholas Bellinger } 2618c66ac9dbSNicholas Bellinger kfree(tg_pt_gp_cg->default_groups); 26191f6fe7cbSNicholas Bellinger /* 26201f6fe7cbSNicholas Bellinger * core_alua_free_tg_pt_gp() is called from ->default_tg_pt_gp 26211f6fe7cbSNicholas Bellinger * directly from target_core_alua_tg_pt_gp_release(). 26221f6fe7cbSNicholas Bellinger */ 26230fd97ccfSChristoph Hellwig dev->t10_alua.default_tg_pt_gp = NULL; 2624c66ac9dbSNicholas Bellinger 2625c66ac9dbSNicholas Bellinger for (i = 0; dev_cg->default_groups[i]; i++) { 2626c66ac9dbSNicholas Bellinger df_item = &dev_cg->default_groups[i]->cg_item; 2627c66ac9dbSNicholas Bellinger dev_cg->default_groups[i] = NULL; 2628c66ac9dbSNicholas Bellinger config_item_put(df_item); 2629c66ac9dbSNicholas Bellinger } 26301f6fe7cbSNicholas Bellinger /* 26310fd97ccfSChristoph Hellwig * se_dev is released from target_core_dev_item_ops->release() 26321f6fe7cbSNicholas Bellinger */ 2633c66ac9dbSNicholas Bellinger config_item_put(item); 2634c66ac9dbSNicholas Bellinger mutex_unlock(&hba->hba_access_mutex); 2635c66ac9dbSNicholas Bellinger } 2636c66ac9dbSNicholas Bellinger 2637c66ac9dbSNicholas Bellinger static struct configfs_group_operations target_core_hba_group_ops = { 2638c66ac9dbSNicholas Bellinger .make_group = target_core_make_subdev, 2639c66ac9dbSNicholas Bellinger .drop_item = target_core_drop_subdev, 2640c66ac9dbSNicholas Bellinger }; 2641c66ac9dbSNicholas Bellinger 2642c66ac9dbSNicholas Bellinger CONFIGFS_EATTR_STRUCT(target_core_hba, se_hba); 2643c66ac9dbSNicholas Bellinger #define SE_HBA_ATTR(_name, _mode) \ 2644c66ac9dbSNicholas Bellinger static struct target_core_hba_attribute \ 2645c66ac9dbSNicholas Bellinger target_core_hba_##_name = \ 2646c66ac9dbSNicholas Bellinger __CONFIGFS_EATTR(_name, _mode, \ 2647c66ac9dbSNicholas Bellinger target_core_hba_show_attr_##_name, \ 2648c66ac9dbSNicholas Bellinger target_core_hba_store_attr_##_name); 2649c66ac9dbSNicholas Bellinger 2650c66ac9dbSNicholas Bellinger #define SE_HBA_ATTR_RO(_name) \ 2651c66ac9dbSNicholas Bellinger static struct target_core_hba_attribute \ 2652c66ac9dbSNicholas Bellinger target_core_hba_##_name = \ 2653c66ac9dbSNicholas Bellinger __CONFIGFS_EATTR_RO(_name, \ 2654c66ac9dbSNicholas Bellinger target_core_hba_show_attr_##_name); 2655c66ac9dbSNicholas Bellinger 2656c66ac9dbSNicholas Bellinger static ssize_t target_core_hba_show_attr_hba_info( 2657c66ac9dbSNicholas Bellinger struct se_hba *hba, 2658c66ac9dbSNicholas Bellinger char *page) 2659c66ac9dbSNicholas Bellinger { 2660c66ac9dbSNicholas Bellinger return sprintf(page, "HBA Index: %d plugin: %s version: %s\n", 2661c66ac9dbSNicholas Bellinger hba->hba_id, hba->transport->name, 2662c66ac9dbSNicholas Bellinger TARGET_CORE_CONFIGFS_VERSION); 2663c66ac9dbSNicholas Bellinger } 2664c66ac9dbSNicholas Bellinger 2665c66ac9dbSNicholas Bellinger SE_HBA_ATTR_RO(hba_info); 2666c66ac9dbSNicholas Bellinger 2667c66ac9dbSNicholas Bellinger static ssize_t target_core_hba_show_attr_hba_mode(struct se_hba *hba, 2668c66ac9dbSNicholas Bellinger char *page) 2669c66ac9dbSNicholas Bellinger { 2670c66ac9dbSNicholas Bellinger int hba_mode = 0; 2671c66ac9dbSNicholas Bellinger 2672c66ac9dbSNicholas Bellinger if (hba->hba_flags & HBA_FLAGS_PSCSI_MODE) 2673c66ac9dbSNicholas Bellinger hba_mode = 1; 2674c66ac9dbSNicholas Bellinger 2675c66ac9dbSNicholas Bellinger return sprintf(page, "%d\n", hba_mode); 2676c66ac9dbSNicholas Bellinger } 2677c66ac9dbSNicholas Bellinger 2678c66ac9dbSNicholas Bellinger static ssize_t target_core_hba_store_attr_hba_mode(struct se_hba *hba, 2679c66ac9dbSNicholas Bellinger const char *page, size_t count) 2680c66ac9dbSNicholas Bellinger { 2681c66ac9dbSNicholas Bellinger struct se_subsystem_api *transport = hba->transport; 2682c66ac9dbSNicholas Bellinger unsigned long mode_flag; 2683c66ac9dbSNicholas Bellinger int ret; 2684c66ac9dbSNicholas Bellinger 2685c66ac9dbSNicholas Bellinger if (transport->pmode_enable_hba == NULL) 2686c66ac9dbSNicholas Bellinger return -EINVAL; 2687c66ac9dbSNicholas Bellinger 268857103d7fSJingoo Han ret = kstrtoul(page, 0, &mode_flag); 2689c66ac9dbSNicholas Bellinger if (ret < 0) { 26906708bb27SAndy Grover pr_err("Unable to extract hba mode flag: %d\n", ret); 269157103d7fSJingoo Han return ret; 2692c66ac9dbSNicholas Bellinger } 2693c66ac9dbSNicholas Bellinger 26940fd97ccfSChristoph Hellwig if (hba->dev_count) { 26956708bb27SAndy Grover pr_err("Unable to set hba_mode with active devices\n"); 2696c66ac9dbSNicholas Bellinger return -EINVAL; 2697c66ac9dbSNicholas Bellinger } 2698c66ac9dbSNicholas Bellinger 2699c66ac9dbSNicholas Bellinger ret = transport->pmode_enable_hba(hba, mode_flag); 2700c66ac9dbSNicholas Bellinger if (ret < 0) 2701c66ac9dbSNicholas Bellinger return -EINVAL; 2702c66ac9dbSNicholas Bellinger if (ret > 0) 2703c66ac9dbSNicholas Bellinger hba->hba_flags |= HBA_FLAGS_PSCSI_MODE; 2704c66ac9dbSNicholas Bellinger else if (ret == 0) 2705c66ac9dbSNicholas Bellinger hba->hba_flags &= ~HBA_FLAGS_PSCSI_MODE; 2706c66ac9dbSNicholas Bellinger 2707c66ac9dbSNicholas Bellinger return count; 2708c66ac9dbSNicholas Bellinger } 2709c66ac9dbSNicholas Bellinger 2710c66ac9dbSNicholas Bellinger SE_HBA_ATTR(hba_mode, S_IRUGO | S_IWUSR); 2711c66ac9dbSNicholas Bellinger 2712c66ac9dbSNicholas Bellinger CONFIGFS_EATTR_OPS(target_core_hba, se_hba, hba_group); 2713c66ac9dbSNicholas Bellinger 27141f6fe7cbSNicholas Bellinger static void target_core_hba_release(struct config_item *item) 27151f6fe7cbSNicholas Bellinger { 27161f6fe7cbSNicholas Bellinger struct se_hba *hba = container_of(to_config_group(item), 27171f6fe7cbSNicholas Bellinger struct se_hba, hba_group); 27181f6fe7cbSNicholas Bellinger core_delete_hba(hba); 27191f6fe7cbSNicholas Bellinger } 27201f6fe7cbSNicholas Bellinger 2721c66ac9dbSNicholas Bellinger static struct configfs_attribute *target_core_hba_attrs[] = { 2722c66ac9dbSNicholas Bellinger &target_core_hba_hba_info.attr, 2723c66ac9dbSNicholas Bellinger &target_core_hba_hba_mode.attr, 2724c66ac9dbSNicholas Bellinger NULL, 2725c66ac9dbSNicholas Bellinger }; 2726c66ac9dbSNicholas Bellinger 2727c66ac9dbSNicholas Bellinger static struct configfs_item_operations target_core_hba_item_ops = { 27281f6fe7cbSNicholas Bellinger .release = target_core_hba_release, 2729c66ac9dbSNicholas Bellinger .show_attribute = target_core_hba_attr_show, 2730c66ac9dbSNicholas Bellinger .store_attribute = target_core_hba_attr_store, 2731c66ac9dbSNicholas Bellinger }; 2732c66ac9dbSNicholas Bellinger 2733c66ac9dbSNicholas Bellinger static struct config_item_type target_core_hba_cit = { 2734c66ac9dbSNicholas Bellinger .ct_item_ops = &target_core_hba_item_ops, 2735c66ac9dbSNicholas Bellinger .ct_group_ops = &target_core_hba_group_ops, 2736c66ac9dbSNicholas Bellinger .ct_attrs = target_core_hba_attrs, 2737c66ac9dbSNicholas Bellinger .ct_owner = THIS_MODULE, 2738c66ac9dbSNicholas Bellinger }; 2739c66ac9dbSNicholas Bellinger 2740c66ac9dbSNicholas Bellinger static struct config_group *target_core_call_addhbatotarget( 2741c66ac9dbSNicholas Bellinger struct config_group *group, 2742c66ac9dbSNicholas Bellinger const char *name) 2743c66ac9dbSNicholas Bellinger { 2744c66ac9dbSNicholas Bellinger char *se_plugin_str, *str, *str2; 2745c66ac9dbSNicholas Bellinger struct se_hba *hba; 2746c66ac9dbSNicholas Bellinger char buf[TARGET_CORE_NAME_MAX_LEN]; 2747c66ac9dbSNicholas Bellinger unsigned long plugin_dep_id = 0; 2748c66ac9dbSNicholas Bellinger int ret; 2749c66ac9dbSNicholas Bellinger 2750c66ac9dbSNicholas Bellinger memset(buf, 0, TARGET_CORE_NAME_MAX_LEN); 275160d645a4SDan Carpenter if (strlen(name) >= TARGET_CORE_NAME_MAX_LEN) { 27526708bb27SAndy Grover pr_err("Passed *name strlen(): %d exceeds" 2753c66ac9dbSNicholas Bellinger " TARGET_CORE_NAME_MAX_LEN: %d\n", (int)strlen(name), 2754c66ac9dbSNicholas Bellinger TARGET_CORE_NAME_MAX_LEN); 2755c66ac9dbSNicholas Bellinger return ERR_PTR(-ENAMETOOLONG); 2756c66ac9dbSNicholas Bellinger } 2757c66ac9dbSNicholas Bellinger snprintf(buf, TARGET_CORE_NAME_MAX_LEN, "%s", name); 2758c66ac9dbSNicholas Bellinger 2759c66ac9dbSNicholas Bellinger str = strstr(buf, "_"); 27606708bb27SAndy Grover if (!str) { 27616708bb27SAndy Grover pr_err("Unable to locate \"_\" for $SUBSYSTEM_PLUGIN_$HOST_ID\n"); 2762c66ac9dbSNicholas Bellinger return ERR_PTR(-EINVAL); 2763c66ac9dbSNicholas Bellinger } 2764c66ac9dbSNicholas Bellinger se_plugin_str = buf; 2765c66ac9dbSNicholas Bellinger /* 2766c66ac9dbSNicholas Bellinger * Special case for subsystem plugins that have "_" in their names. 2767c66ac9dbSNicholas Bellinger * Namely rd_direct and rd_mcp.. 2768c66ac9dbSNicholas Bellinger */ 2769c66ac9dbSNicholas Bellinger str2 = strstr(str+1, "_"); 27706708bb27SAndy Grover if (str2) { 2771c66ac9dbSNicholas Bellinger *str2 = '\0'; /* Terminate for *se_plugin_str */ 2772c66ac9dbSNicholas Bellinger str2++; /* Skip to start of plugin dependent ID */ 2773c66ac9dbSNicholas Bellinger str = str2; 2774c66ac9dbSNicholas Bellinger } else { 2775c66ac9dbSNicholas Bellinger *str = '\0'; /* Terminate for *se_plugin_str */ 2776c66ac9dbSNicholas Bellinger str++; /* Skip to start of plugin dependent ID */ 2777c66ac9dbSNicholas Bellinger } 2778c66ac9dbSNicholas Bellinger 277957103d7fSJingoo Han ret = kstrtoul(str, 0, &plugin_dep_id); 2780c66ac9dbSNicholas Bellinger if (ret < 0) { 278157103d7fSJingoo Han pr_err("kstrtoul() returned %d for" 2782c66ac9dbSNicholas Bellinger " plugin_dep_id\n", ret); 278357103d7fSJingoo Han return ERR_PTR(ret); 2784c66ac9dbSNicholas Bellinger } 2785c66ac9dbSNicholas Bellinger /* 2786c66ac9dbSNicholas Bellinger * Load up TCM subsystem plugins if they have not already been loaded. 2787c66ac9dbSNicholas Bellinger */ 2788dbc5623eSNicholas Bellinger transport_subsystem_check_init(); 2789c66ac9dbSNicholas Bellinger 2790c66ac9dbSNicholas Bellinger hba = core_alloc_hba(se_plugin_str, plugin_dep_id, 0); 2791c66ac9dbSNicholas Bellinger if (IS_ERR(hba)) 2792c66ac9dbSNicholas Bellinger return ERR_CAST(hba); 2793c66ac9dbSNicholas Bellinger 2794c66ac9dbSNicholas Bellinger config_group_init_type_name(&hba->hba_group, name, 2795c66ac9dbSNicholas Bellinger &target_core_hba_cit); 2796c66ac9dbSNicholas Bellinger 2797c66ac9dbSNicholas Bellinger return &hba->hba_group; 2798c66ac9dbSNicholas Bellinger } 2799c66ac9dbSNicholas Bellinger 2800c66ac9dbSNicholas Bellinger static void target_core_call_delhbafromtarget( 2801c66ac9dbSNicholas Bellinger struct config_group *group, 2802c66ac9dbSNicholas Bellinger struct config_item *item) 2803c66ac9dbSNicholas Bellinger { 28041f6fe7cbSNicholas Bellinger /* 28051f6fe7cbSNicholas Bellinger * core_delete_hba() is called from target_core_hba_item_ops->release() 28061f6fe7cbSNicholas Bellinger * -> target_core_hba_release() 28071f6fe7cbSNicholas Bellinger */ 2808c66ac9dbSNicholas Bellinger config_item_put(item); 2809c66ac9dbSNicholas Bellinger } 2810c66ac9dbSNicholas Bellinger 2811c66ac9dbSNicholas Bellinger static struct configfs_group_operations target_core_group_ops = { 2812c66ac9dbSNicholas Bellinger .make_group = target_core_call_addhbatotarget, 2813c66ac9dbSNicholas Bellinger .drop_item = target_core_call_delhbafromtarget, 2814c66ac9dbSNicholas Bellinger }; 2815c66ac9dbSNicholas Bellinger 2816c66ac9dbSNicholas Bellinger static struct config_item_type target_core_cit = { 2817c66ac9dbSNicholas Bellinger .ct_item_ops = NULL, 2818c66ac9dbSNicholas Bellinger .ct_group_ops = &target_core_group_ops, 2819c66ac9dbSNicholas Bellinger .ct_attrs = NULL, 2820c66ac9dbSNicholas Bellinger .ct_owner = THIS_MODULE, 2821c66ac9dbSNicholas Bellinger }; 2822c66ac9dbSNicholas Bellinger 2823c66ac9dbSNicholas Bellinger /* Stop functions for struct config_item_type target_core_hba_cit */ 2824c66ac9dbSNicholas Bellinger 282554550fabSAxel Lin static int __init target_core_init_configfs(void) 2826c66ac9dbSNicholas Bellinger { 2827c66ac9dbSNicholas Bellinger struct config_group *target_cg, *hba_cg = NULL, *alua_cg = NULL; 2828c66ac9dbSNicholas Bellinger struct config_group *lu_gp_cg = NULL; 2829c66ac9dbSNicholas Bellinger struct configfs_subsystem *subsys; 2830c66ac9dbSNicholas Bellinger struct t10_alua_lu_gp *lu_gp; 2831c66ac9dbSNicholas Bellinger int ret; 2832c66ac9dbSNicholas Bellinger 28336708bb27SAndy Grover pr_debug("TARGET_CORE[0]: Loading Generic Kernel Storage" 2834c66ac9dbSNicholas Bellinger " Engine: %s on %s/%s on "UTS_RELEASE"\n", 2835c66ac9dbSNicholas Bellinger TARGET_CORE_VERSION, utsname()->sysname, utsname()->machine); 2836c66ac9dbSNicholas Bellinger 2837c66ac9dbSNicholas Bellinger subsys = target_core_subsystem[0]; 2838c66ac9dbSNicholas Bellinger config_group_init(&subsys->su_group); 2839c66ac9dbSNicholas Bellinger mutex_init(&subsys->su_mutex); 2840c66ac9dbSNicholas Bellinger 2841e3d6f909SAndy Grover ret = init_se_kmem_caches(); 2842c66ac9dbSNicholas Bellinger if (ret < 0) 2843e3d6f909SAndy Grover return ret; 2844c66ac9dbSNicholas Bellinger /* 2845c66ac9dbSNicholas Bellinger * Create $CONFIGFS/target/core default group for HBA <-> Storage Object 2846c66ac9dbSNicholas Bellinger * and ALUA Logical Unit Group and Target Port Group infrastructure. 2847c66ac9dbSNicholas Bellinger */ 2848c66ac9dbSNicholas Bellinger target_cg = &subsys->su_group; 284913f6a914SSebastian Andrzej Siewior target_cg->default_groups = kmalloc(sizeof(struct config_group) * 2, 2850c66ac9dbSNicholas Bellinger GFP_KERNEL); 28516708bb27SAndy Grover if (!target_cg->default_groups) { 28526708bb27SAndy Grover pr_err("Unable to allocate target_cg->default_groups\n"); 285337bb7899SPeter Senna Tschudin ret = -ENOMEM; 2854c66ac9dbSNicholas Bellinger goto out_global; 2855c66ac9dbSNicholas Bellinger } 2856c66ac9dbSNicholas Bellinger 2857e3d6f909SAndy Grover config_group_init_type_name(&target_core_hbagroup, 2858c66ac9dbSNicholas Bellinger "core", &target_core_cit); 2859e3d6f909SAndy Grover target_cg->default_groups[0] = &target_core_hbagroup; 2860c66ac9dbSNicholas Bellinger target_cg->default_groups[1] = NULL; 2861c66ac9dbSNicholas Bellinger /* 2862c66ac9dbSNicholas Bellinger * Create ALUA infrastructure under /sys/kernel/config/target/core/alua/ 2863c66ac9dbSNicholas Bellinger */ 2864e3d6f909SAndy Grover hba_cg = &target_core_hbagroup; 286513f6a914SSebastian Andrzej Siewior hba_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, 2866c66ac9dbSNicholas Bellinger GFP_KERNEL); 28676708bb27SAndy Grover if (!hba_cg->default_groups) { 28686708bb27SAndy Grover pr_err("Unable to allocate hba_cg->default_groups\n"); 286937bb7899SPeter Senna Tschudin ret = -ENOMEM; 2870c66ac9dbSNicholas Bellinger goto out_global; 2871c66ac9dbSNicholas Bellinger } 2872e3d6f909SAndy Grover config_group_init_type_name(&alua_group, 2873c66ac9dbSNicholas Bellinger "alua", &target_core_alua_cit); 2874e3d6f909SAndy Grover hba_cg->default_groups[0] = &alua_group; 2875c66ac9dbSNicholas Bellinger hba_cg->default_groups[1] = NULL; 2876c66ac9dbSNicholas Bellinger /* 2877c66ac9dbSNicholas Bellinger * Add ALUA Logical Unit Group and Target Port Group ConfigFS 2878c66ac9dbSNicholas Bellinger * groups under /sys/kernel/config/target/core/alua/ 2879c66ac9dbSNicholas Bellinger */ 2880e3d6f909SAndy Grover alua_cg = &alua_group; 288113f6a914SSebastian Andrzej Siewior alua_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, 2882c66ac9dbSNicholas Bellinger GFP_KERNEL); 28836708bb27SAndy Grover if (!alua_cg->default_groups) { 28846708bb27SAndy Grover pr_err("Unable to allocate alua_cg->default_groups\n"); 288537bb7899SPeter Senna Tschudin ret = -ENOMEM; 2886c66ac9dbSNicholas Bellinger goto out_global; 2887c66ac9dbSNicholas Bellinger } 2888c66ac9dbSNicholas Bellinger 2889e3d6f909SAndy Grover config_group_init_type_name(&alua_lu_gps_group, 2890c66ac9dbSNicholas Bellinger "lu_gps", &target_core_alua_lu_gps_cit); 2891e3d6f909SAndy Grover alua_cg->default_groups[0] = &alua_lu_gps_group; 2892c66ac9dbSNicholas Bellinger alua_cg->default_groups[1] = NULL; 2893c66ac9dbSNicholas Bellinger /* 2894c66ac9dbSNicholas Bellinger * Add core/alua/lu_gps/default_lu_gp 2895c66ac9dbSNicholas Bellinger */ 2896c66ac9dbSNicholas Bellinger lu_gp = core_alua_allocate_lu_gp("default_lu_gp", 1); 289737bb7899SPeter Senna Tschudin if (IS_ERR(lu_gp)) { 289837bb7899SPeter Senna Tschudin ret = -ENOMEM; 2899c66ac9dbSNicholas Bellinger goto out_global; 290037bb7899SPeter Senna Tschudin } 2901c66ac9dbSNicholas Bellinger 2902e3d6f909SAndy Grover lu_gp_cg = &alua_lu_gps_group; 290313f6a914SSebastian Andrzej Siewior lu_gp_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, 2904c66ac9dbSNicholas Bellinger GFP_KERNEL); 29056708bb27SAndy Grover if (!lu_gp_cg->default_groups) { 29066708bb27SAndy Grover pr_err("Unable to allocate lu_gp_cg->default_groups\n"); 290737bb7899SPeter Senna Tschudin ret = -ENOMEM; 2908c66ac9dbSNicholas Bellinger goto out_global; 2909c66ac9dbSNicholas Bellinger } 2910c66ac9dbSNicholas Bellinger 2911c66ac9dbSNicholas Bellinger config_group_init_type_name(&lu_gp->lu_gp_group, "default_lu_gp", 2912c66ac9dbSNicholas Bellinger &target_core_alua_lu_gp_cit); 2913c66ac9dbSNicholas Bellinger lu_gp_cg->default_groups[0] = &lu_gp->lu_gp_group; 2914c66ac9dbSNicholas Bellinger lu_gp_cg->default_groups[1] = NULL; 2915e3d6f909SAndy Grover default_lu_gp = lu_gp; 2916c66ac9dbSNicholas Bellinger /* 2917c66ac9dbSNicholas Bellinger * Register the target_core_mod subsystem with configfs. 2918c66ac9dbSNicholas Bellinger */ 2919c66ac9dbSNicholas Bellinger ret = configfs_register_subsystem(subsys); 2920c66ac9dbSNicholas Bellinger if (ret < 0) { 29216708bb27SAndy Grover pr_err("Error %d while registering subsystem %s\n", 2922c66ac9dbSNicholas Bellinger ret, subsys->su_group.cg_item.ci_namebuf); 2923c66ac9dbSNicholas Bellinger goto out_global; 2924c66ac9dbSNicholas Bellinger } 29256708bb27SAndy Grover pr_debug("TARGET_CORE[0]: Initialized ConfigFS Fabric" 2926c66ac9dbSNicholas Bellinger " Infrastructure: "TARGET_CORE_CONFIGFS_VERSION" on %s/%s" 2927c66ac9dbSNicholas Bellinger " on "UTS_RELEASE"\n", utsname()->sysname, utsname()->machine); 2928c66ac9dbSNicholas Bellinger /* 2929c66ac9dbSNicholas Bellinger * Register built-in RAMDISK subsystem logic for virtual LUN 0 2930c66ac9dbSNicholas Bellinger */ 2931c66ac9dbSNicholas Bellinger ret = rd_module_init(); 2932c66ac9dbSNicholas Bellinger if (ret < 0) 2933c66ac9dbSNicholas Bellinger goto out; 2934c66ac9dbSNicholas Bellinger 29350d0f9dfbSRoland Dreier ret = core_dev_setup_virtual_lun0(); 29360d0f9dfbSRoland Dreier if (ret < 0) 2937c66ac9dbSNicholas Bellinger goto out; 2938c66ac9dbSNicholas Bellinger 2939f99715acSNicholas Bellinger ret = target_xcopy_setup_pt(); 2940f99715acSNicholas Bellinger if (ret < 0) 2941f99715acSNicholas Bellinger goto out; 2942f99715acSNicholas Bellinger 2943c66ac9dbSNicholas Bellinger return 0; 2944c66ac9dbSNicholas Bellinger 2945c66ac9dbSNicholas Bellinger out: 2946c66ac9dbSNicholas Bellinger configfs_unregister_subsystem(subsys); 2947c66ac9dbSNicholas Bellinger core_dev_release_virtual_lun0(); 2948c66ac9dbSNicholas Bellinger rd_module_exit(); 2949c66ac9dbSNicholas Bellinger out_global: 2950e3d6f909SAndy Grover if (default_lu_gp) { 2951e3d6f909SAndy Grover core_alua_free_lu_gp(default_lu_gp); 2952e3d6f909SAndy Grover default_lu_gp = NULL; 2953c66ac9dbSNicholas Bellinger } 2954c66ac9dbSNicholas Bellinger if (lu_gp_cg) 2955c66ac9dbSNicholas Bellinger kfree(lu_gp_cg->default_groups); 2956c66ac9dbSNicholas Bellinger if (alua_cg) 2957c66ac9dbSNicholas Bellinger kfree(alua_cg->default_groups); 2958c66ac9dbSNicholas Bellinger if (hba_cg) 2959c66ac9dbSNicholas Bellinger kfree(hba_cg->default_groups); 2960c66ac9dbSNicholas Bellinger kfree(target_cg->default_groups); 2961e3d6f909SAndy Grover release_se_kmem_caches(); 2962e3d6f909SAndy Grover return ret; 2963c66ac9dbSNicholas Bellinger } 2964c66ac9dbSNicholas Bellinger 296554550fabSAxel Lin static void __exit target_core_exit_configfs(void) 2966c66ac9dbSNicholas Bellinger { 2967c66ac9dbSNicholas Bellinger struct configfs_subsystem *subsys; 2968c66ac9dbSNicholas Bellinger struct config_group *hba_cg, *alua_cg, *lu_gp_cg; 2969c66ac9dbSNicholas Bellinger struct config_item *item; 2970c66ac9dbSNicholas Bellinger int i; 2971c66ac9dbSNicholas Bellinger 2972c66ac9dbSNicholas Bellinger subsys = target_core_subsystem[0]; 2973c66ac9dbSNicholas Bellinger 2974e3d6f909SAndy Grover lu_gp_cg = &alua_lu_gps_group; 2975c66ac9dbSNicholas Bellinger for (i = 0; lu_gp_cg->default_groups[i]; i++) { 2976c66ac9dbSNicholas Bellinger item = &lu_gp_cg->default_groups[i]->cg_item; 2977c66ac9dbSNicholas Bellinger lu_gp_cg->default_groups[i] = NULL; 2978c66ac9dbSNicholas Bellinger config_item_put(item); 2979c66ac9dbSNicholas Bellinger } 2980c66ac9dbSNicholas Bellinger kfree(lu_gp_cg->default_groups); 29817c2bf6e9SNicholas Bellinger lu_gp_cg->default_groups = NULL; 2982c66ac9dbSNicholas Bellinger 2983e3d6f909SAndy Grover alua_cg = &alua_group; 2984c66ac9dbSNicholas Bellinger for (i = 0; alua_cg->default_groups[i]; i++) { 2985c66ac9dbSNicholas Bellinger item = &alua_cg->default_groups[i]->cg_item; 2986c66ac9dbSNicholas Bellinger alua_cg->default_groups[i] = NULL; 2987c66ac9dbSNicholas Bellinger config_item_put(item); 2988c66ac9dbSNicholas Bellinger } 2989c66ac9dbSNicholas Bellinger kfree(alua_cg->default_groups); 29907c2bf6e9SNicholas Bellinger alua_cg->default_groups = NULL; 2991c66ac9dbSNicholas Bellinger 2992e3d6f909SAndy Grover hba_cg = &target_core_hbagroup; 2993c66ac9dbSNicholas Bellinger for (i = 0; hba_cg->default_groups[i]; i++) { 2994c66ac9dbSNicholas Bellinger item = &hba_cg->default_groups[i]->cg_item; 2995c66ac9dbSNicholas Bellinger hba_cg->default_groups[i] = NULL; 2996c66ac9dbSNicholas Bellinger config_item_put(item); 2997c66ac9dbSNicholas Bellinger } 2998c66ac9dbSNicholas Bellinger kfree(hba_cg->default_groups); 29997c2bf6e9SNicholas Bellinger hba_cg->default_groups = NULL; 30007c2bf6e9SNicholas Bellinger /* 30017c2bf6e9SNicholas Bellinger * We expect subsys->su_group.default_groups to be released 30027c2bf6e9SNicholas Bellinger * by configfs subsystem provider logic.. 30037c2bf6e9SNicholas Bellinger */ 30047c2bf6e9SNicholas Bellinger configfs_unregister_subsystem(subsys); 3005c66ac9dbSNicholas Bellinger kfree(subsys->su_group.default_groups); 3006c66ac9dbSNicholas Bellinger 3007e3d6f909SAndy Grover core_alua_free_lu_gp(default_lu_gp); 3008e3d6f909SAndy Grover default_lu_gp = NULL; 30097c2bf6e9SNicholas Bellinger 30106708bb27SAndy Grover pr_debug("TARGET_CORE[0]: Released ConfigFS Fabric" 3011c66ac9dbSNicholas Bellinger " Infrastructure\n"); 3012c66ac9dbSNicholas Bellinger 3013c66ac9dbSNicholas Bellinger core_dev_release_virtual_lun0(); 3014c66ac9dbSNicholas Bellinger rd_module_exit(); 3015f99715acSNicholas Bellinger target_xcopy_release_pt(); 3016e3d6f909SAndy Grover release_se_kmem_caches(); 3017c66ac9dbSNicholas Bellinger } 3018c66ac9dbSNicholas Bellinger 3019c66ac9dbSNicholas Bellinger MODULE_DESCRIPTION("Target_Core_Mod/ConfigFS"); 3020c66ac9dbSNicholas Bellinger MODULE_AUTHOR("nab@Linux-iSCSI.org"); 3021c66ac9dbSNicholas Bellinger MODULE_LICENSE("GPL"); 3022c66ac9dbSNicholas Bellinger 3023c66ac9dbSNicholas Bellinger module_init(target_core_init_configfs); 3024c66ac9dbSNicholas Bellinger module_exit(target_core_exit_configfs); 3025