scst: Add the 'forward_src' sysfs attribute

Make forwarding source mode configurable per target port instead of
having a compile-time global option.


git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@8776 d57e44dd-8a1f-0410-8b47-8ef2f437770f
This commit is contained in:
Bart Van Assche
2020-02-23 23:05:13 +00:00
parent 2e5620098c
commit 785e721cf3
8 changed files with 90 additions and 33 deletions
+4 -6
View File
@@ -144,6 +144,7 @@ static void disk_detach(struct scst_device *dev)
static int disk_parse(struct scst_cmd *cmd)
{
struct scst_tgt *tgt = cmd->tgt;
int res = SCST_CMD_STATE_DEFAULT, rc;
rc = scst_sbc_generic_parse(cmd);
@@ -152,8 +153,7 @@ static int disk_parse(struct scst_cmd *cmd)
goto out;
}
#ifdef CONFIG_SCST_FORWARD_MODE_PASS_THROUGH
if (unlikely(cmd->op_flags & SCST_LOCAL_CMD)) {
if (unlikely(tgt->tgt_forward_src && cmd->op_flags & SCST_LOCAL_CMD)) {
switch (cmd->cdb[0]) {
case COMPARE_AND_WRITE:
case EXTENDED_COPY:
@@ -164,7 +164,6 @@ static int disk_parse(struct scst_cmd *cmd)
break;
}
}
#endif
cmd->retries = SCST_PASSTHROUGH_RETRIES;
out:
@@ -286,6 +285,7 @@ out_complete:
/* Executes command and split CDB, if necessary */
static enum scst_exec_res disk_exec(struct scst_cmd *cmd)
{
struct scst_tgt *tgt = cmd->tgt;
enum scst_exec_res res;
int rc;
struct disk_work work;
@@ -299,8 +299,7 @@ static enum scst_exec_res disk_exec(struct scst_cmd *cmd)
TRACE_ENTRY();
#ifdef CONFIG_SCST_FORWARD_MODE_PASS_THROUGH
if (unlikely(cmd->op_flags & SCST_LOCAL_CMD)) {
if (unlikely(tgt->tgt_forward_src && cmd->op_flags & SCST_LOCAL_CMD)) {
switch (cmd->cdb[0]) {
case RESERVE:
case RESERVE_10:
@@ -315,7 +314,6 @@ static enum scst_exec_res disk_exec(struct scst_cmd *cmd)
break;
}
}
#endif
/*
* For PC requests we are going to submit max_hw_sectors used instead
+1 -3
View File
@@ -714,15 +714,13 @@ enum scst_exec_res scst_persistent_reserve_in_local(struct scst_cmd *cmd)
goto out_done;
}
#ifndef CONFIG_SCST_FORWARD_MODE_PASS_THROUGH
if (dev->scsi_dev != NULL) {
if (cmd->tgt->tgt_forward_src && dev->scsi_dev) {
PRINT_WARNING("PR commands for pass-through devices not "
"supported (device %s)", dev->virt_name);
scst_set_cmd_error(cmd,
SCST_LOAD_SENSE(scst_sense_invalid_opcode));
goto out_done;
}
#endif
buffer_size = scst_get_buf_full_sense(cmd, &buffer);
if (unlikely(buffer_size <= 0))
+3 -10
View File
@@ -1111,7 +1111,7 @@ static int scst_register_device(struct scsi_device *scsidp)
dev->scsi_dev = scsidp;
#ifdef CONFIG_SCST_FORWARD_MODE_PASS_THROUGH
/* For target ports that function as forwarding source. */
res = scst_pr_set_file_name(dev, NULL, "%s/%s", SCST_PR_DIR,
dev->virt_name);
if (res != 0)
@@ -1120,7 +1120,6 @@ static int scst_register_device(struct scsi_device *scsidp)
res = scst_pr_init_dev(dev);
if (res != 0)
goto out_free_dev;
#endif
list_add_tail(&dev->dev_list_entry, &scst_dev_list);
@@ -1143,14 +1142,9 @@ out:
out_del_unlocked:
mutex_lock(&scst_mutex);
list_del_init(&dev->dev_list_entry);
mutex_unlock(&scst_mutex);
percpu_ref_kill(&dev->refcnt);
goto out;
#ifdef CONFIG_SCST_FORWARD_MODE_PASS_THROUGH
/* If used as a forwarding source (see also tgt_forward_src). */
scst_pr_clear_dev(dev);
#endif
out_free_dev:
percpu_ref_kill(&dev->refcnt);
@@ -1193,9 +1187,8 @@ static void scst_unregister_device(struct scsi_device *scsidp)
list_del_init(&dev->dev_list_entry);
#ifdef CONFIG_SCST_FORWARD_MODE_PASS_THROUGH
/* For forwarding sources (see also tgt_forward_src). */
scst_pr_clear_dev(dev);
#endif
scst_dg_dev_remove_by_dev(dev);
+39
View File
@@ -2513,6 +2513,44 @@ static struct kobj_attribute scst_rel_tgt_id =
__ATTR(rel_tgt_id, S_IRUGO | S_IWUSR, scst_rel_tgt_id_show,
scst_rel_tgt_id_store);
static ssize_t scst_tgt_forward_src_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
{
struct scst_tgt *tgt = container_of(kobj, struct scst_tgt, tgt_kobj);
return sprintf(buf, "%d\n%s", tgt->tgt_forward_src,
tgt->tgt_forward_src ? SCST_SYSFS_KEY_MARK "\n" : "");
}
static ssize_t scst_tgt_forward_src_store(struct kobject *kobj,
struct kobj_attribute *attr, const char *buf, size_t count)
{
struct scst_tgt *tgt = container_of(kobj, struct scst_tgt, tgt_kobj);
int res, old, new;
res = kstrtoint(buf, 0, &new);
if (res < 0)
return res;
if (new < 0 || new > 1)
return -EINVAL;
mutex_lock(&scst_mutex);
old = tgt->tgt_forward_src;
if (old != new) {
tgt->tgt_forward_src = new;
PRINT_INFO("%s target %s as forwarding source",
tgt->tgt_forward_src ? "Set" : "Clear",
tgt->tgt_name);
}
mutex_unlock(&scst_mutex);
return count;
}
static struct kobj_attribute scst_tgt_forward_src =
__ATTR(forward_src, S_IRUGO | S_IWUSR, scst_tgt_forward_src_show,
scst_tgt_forward_src_store);
static ssize_t scst_tgt_forward_dst_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
{
@@ -2885,6 +2923,7 @@ SCST_TGT_SYSFS_STAT_ATTR(cmd_count, none_cmd_count, SCST_DATA_NONE, >> 0);
static struct attribute *scst_tgt_attrs[] = {
&scst_rel_tgt_id.attr,
&scst_tgt_forward_src.attr,
&scst_tgt_forward_dst.attr,
&scst_tgt_forwarding.attr,
&scst_tgt_comment.attr,