cregit-Linux how code gets into the kernel

Release 4.11 drivers/target/target_core_ua.c

Directory: drivers/target
/*******************************************************************************
 * Filename: target_core_ua.c
 *
 * This file contains logic for SPC-3 Unit Attention emulation
 *
 * (c) Copyright 2009-2013 Datera, Inc.
 *
 * Nicholas A. Bellinger <nab@kernel.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 ******************************************************************************/

#include <linux/slab.h>
#include <linux/spinlock.h>
#include <scsi/scsi_proto.h>

#include <target/target_core_base.h>
#include <target/target_core_fabric.h>

#include "target_core_internal.h"
#include "target_core_alua.h"
#include "target_core_pr.h"
#include "target_core_ua.h"


sense_reason_t target_scsi3_ua_check(struct se_cmd *cmd) { struct se_dev_entry *deve; struct se_session *sess = cmd->se_sess; struct se_node_acl *nacl; if (!sess) return 0; nacl = sess->se_node_acl; if (!nacl) return 0; rcu_read_lock(); deve = target_nacl_find_deve(nacl, cmd->orig_fe_lun); if (!deve) { rcu_read_unlock(); return 0; } if (!atomic_read(&deve->ua_count)) { rcu_read_unlock(); return 0; } rcu_read_unlock(); /* * From sam4r14, section 5.14 Unit attention condition: * * a) if an INQUIRY command enters the enabled command state, the * device server shall process the INQUIRY command and shall neither * report nor clear any unit attention condition; * b) if a REPORT LUNS command enters the enabled command state, the * device server shall process the REPORT LUNS command and shall not * report any unit attention condition; * e) if a REQUEST SENSE command enters the enabled command state while * a unit attention condition exists for the SCSI initiator port * associated with the I_T nexus on which the REQUEST SENSE command * was received, then the device server shall process the command * and either: */ switch (cmd->t_task_cdb[0]) { case INQUIRY: case REPORT_LUNS: case REQUEST_SENSE: return 0; default: return TCM_CHECK_CONDITION_UNIT_ATTENTION; } }

Contributors

PersonTokensPropCommitsCommitProp
Nicholas Bellinger12295.31%266.67%
Christoph Hellwig64.69%133.33%
Total128100.00%3100.00%


int core_scsi3_ua_allocate( struct se_dev_entry *deve, u8 asc, u8 ascq) { struct se_ua *ua, *ua_p, *ua_tmp; ua = kmem_cache_zalloc(se_ua_cache, GFP_ATOMIC); if (!ua) { pr_err("Unable to allocate struct se_ua\n"); return -ENOMEM; } INIT_LIST_HEAD(&ua->ua_nacl_list); ua->ua_asc = asc; ua->ua_ascq = ascq; spin_lock(&deve->ua_lock); list_for_each_entry_safe(ua_p, ua_tmp, &deve->ua_list, ua_nacl_list) { /* * Do not report the same UNIT ATTENTION twice.. */ if ((ua_p->ua_asc == asc) && (ua_p->ua_ascq == ascq)) { spin_unlock(&deve->ua_lock); kmem_cache_free(se_ua_cache, ua); return 0; } /* * Attach the highest priority Unit Attention to * the head of the list following sam4r14, * Section 5.14 Unit Attention Condition: * * POWER ON, RESET, OR BUS DEVICE RESET OCCURRED highest * POWER ON OCCURRED or * DEVICE INTERNAL RESET * SCSI BUS RESET OCCURRED or * MICROCODE HAS BEEN CHANGED or * protocol specific * BUS DEVICE RESET FUNCTION OCCURRED * I_T NEXUS LOSS OCCURRED * COMMANDS CLEARED BY POWER LOSS NOTIFICATION * all others Lowest * * Each of the ASCQ codes listed above are defined in * the 29h ASC family, see spc4r17 Table D.1 */ if (ua_p->ua_asc == 0x29) { if ((asc == 0x29) && (ascq > ua_p->ua_ascq)) list_add(&ua->ua_nacl_list, &deve->ua_list); else list_add_tail(&ua->ua_nacl_list, &deve->ua_list); } else if (ua_p->ua_asc == 0x2a) { /* * Incoming Family 29h ASCQ codes will override * Family 2AHh ASCQ codes for Unit Attention condition. */ if ((asc == 0x29) || (ascq > ua_p->ua_asc)) list_add(&ua->ua_nacl_list, &deve->ua_list); else list_add_tail(&ua->ua_nacl_list, &deve->ua_list); } else list_add_tail(&ua->ua_nacl_list, &deve->ua_list); spin_unlock(&deve->ua_lock); atomic_inc_mb(&deve->ua_count); return 0; } list_add_tail(&ua->ua_nacl_list, &deve->ua_list); spin_unlock(&deve->ua_lock); pr_debug("Allocated UNIT ATTENTION, mapped LUN: %llu, ASC:" " 0x%02x, ASCQ: 0x%02x\n", deve->mapped_lun, asc, ascq); atomic_inc_mb(&deve->ua_count); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Nicholas Bellinger30996.87%120.00%
Hannes Reinecke51.57%120.00%
Andy Grover30.94%240.00%
Jörn Engel20.63%120.00%
Total319100.00%5100.00%


void target_ua_allocate_lun(struct se_node_acl *nacl, u32 unpacked_lun, u8 asc, u8 ascq) { struct se_dev_entry *deve; if (!nacl) return; rcu_read_lock(); deve = target_nacl_find_deve(nacl, unpacked_lun); if (!deve) { rcu_read_unlock(); return; } core_scsi3_ua_allocate(deve, asc, ascq); rcu_read_unlock(); }

Contributors

PersonTokensPropCommitsCommitProp
Hannes Reinecke65100.00%1100.00%
Total65100.00%1100.00%


void core_scsi3_ua_release_all( struct se_dev_entry *deve) { struct se_ua *ua, *ua_p; spin_lock(&deve->ua_lock); list_for_each_entry_safe(ua, ua_p, &deve->ua_list, ua_nacl_list) { list_del(&ua->ua_nacl_list); kmem_cache_free(se_ua_cache, ua); atomic_dec_mb(&deve->ua_count); } spin_unlock(&deve->ua_lock); }

Contributors

PersonTokensPropCommitsCommitProp
Nicholas Bellinger6898.55%150.00%
Jörn Engel11.45%150.00%
Total69100.00%2100.00%


void core_scsi3_ua_for_check_condition( struct se_cmd *cmd, u8 *asc, u8 *ascq) { struct se_device *dev = cmd->se_dev; struct se_dev_entry *deve; struct se_session *sess = cmd->se_sess; struct se_node_acl *nacl; struct se_ua *ua = NULL, *ua_p; int head = 1; if (!sess) return; nacl = sess->se_node_acl; if (!nacl) return; rcu_read_lock(); deve = target_nacl_find_deve(nacl, cmd->orig_fe_lun); if (!deve) { rcu_read_unlock(); return; } if (!atomic_read(&deve->ua_count)) { rcu_read_unlock(); return; } /* * The highest priority Unit Attentions are placed at the head of the * struct se_dev_entry->ua_list, and will be returned in CHECK_CONDITION + * sense data for the received CDB. */ spin_lock(&deve->ua_lock); list_for_each_entry_safe(ua, ua_p, &deve->ua_list, ua_nacl_list) { /* * For ua_intlck_ctrl code not equal to 00b, only report the * highest priority UNIT_ATTENTION and ASC/ASCQ without * clearing it. */ if (dev->dev_attrib.emulate_ua_intlck_ctrl != 0) { *asc = ua->ua_asc; *ascq = ua->ua_ascq; break; } /* * Otherwise for the default 00b, release the UNIT ATTENTION * condition. Return the ASC/ASCQ of the highest priority UA * (head of the list) in the outgoing CHECK_CONDITION + sense. */ if (head) { *asc = ua->ua_asc; *ascq = ua->ua_ascq; head = 0; } list_del(&ua->ua_nacl_list); kmem_cache_free(se_ua_cache, ua); atomic_dec_mb(&deve->ua_count); } spin_unlock(&deve->ua_lock); rcu_read_unlock(); pr_debug("[%s]: %s UNIT ATTENTION condition with" " INTLCK_CTRL: %d, mapped LUN: %llu, got CDB: 0x%02x" " reported ASC: 0x%02x, ASCQ: 0x%02x\n", nacl->se_tpg->se_tpg_tfo->get_fabric_name(), (dev->dev_attrib.emulate_ua_intlck_ctrl != 0) ? "Reporting" : "Releasing", dev->dev_attrib.emulate_ua_intlck_ctrl, cmd->orig_fe_lun, cmd->t_task_cdb[0], *asc, *ascq); }

Contributors

PersonTokensPropCommitsCommitProp
Nicholas Bellinger26794.68%222.22%
Andy Grover93.19%333.33%
Christoph Hellwig31.06%111.11%
Hannes Reinecke10.35%111.11%
Lucas De Marchi10.35%111.11%
Jörn Engel10.35%111.11%
Total282100.00%9100.00%


int core_scsi3_ua_clear_for_request_sense( struct se_cmd *cmd, u8 *asc, u8 *ascq) { struct se_dev_entry *deve; struct se_session *sess = cmd->se_sess; struct se_node_acl *nacl; struct se_ua *ua = NULL, *ua_p; int head = 1; if (!sess) return -EINVAL; nacl = sess->se_node_acl; if (!nacl) return -EINVAL; rcu_read_lock(); deve = target_nacl_find_deve(nacl, cmd->orig_fe_lun); if (!deve) { rcu_read_unlock(); return -EINVAL; } if (!atomic_read(&deve->ua_count)) { rcu_read_unlock(); return -EPERM; } /* * The highest priority Unit Attentions are placed at the head of the * struct se_dev_entry->ua_list. The First (and hence highest priority) * ASC/ASCQ will be returned in REQUEST_SENSE payload data for the * matching struct se_lun. * * Once the returning ASC/ASCQ values are set, we go ahead and * release all of the Unit Attention conditions for the associated * struct se_lun. */ spin_lock(&deve->ua_lock); list_for_each_entry_safe(ua, ua_p, &deve->ua_list, ua_nacl_list) { if (head) { *asc = ua->ua_asc; *ascq = ua->ua_ascq; head = 0; } list_del(&ua->ua_nacl_list); kmem_cache_free(se_ua_cache, ua); atomic_dec_mb(&deve->ua_count); } spin_unlock(&deve->ua_lock); rcu_read_unlock(); pr_debug("[%s]: Released UNIT ATTENTION condition, mapped" " LUN: %llu, got REQUEST_SENSE reported ASC: 0x%02x," " ASCQ: 0x%02x\n", nacl->se_tpg->se_tpg_tfo->get_fabric_name(), cmd->orig_fe_lun, *asc, *ascq); return (head) ? -EPERM : 0; }

Contributors

PersonTokensPropCommitsCommitProp
Nicholas Bellinger22995.82%228.57%
Andy Grover72.93%228.57%
Hannes Reinecke10.42%114.29%
Jörn Engel10.42%114.29%
Lucas De Marchi10.42%114.29%
Total239100.00%7100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
Nicholas Bellinger101990.18%320.00%
Hannes Reinecke726.37%213.33%
Andy Grover191.68%320.00%
Christoph Hellwig121.06%426.67%
Jörn Engel50.44%16.67%
Lucas De Marchi20.18%16.67%
Bart Van Assche10.09%16.67%
Total1130100.00%15100.00%
Directory: drivers/target
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.