Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: target: tcmu: Make pgr_support and alua_support attributes writable

Currently in tcmu reservation commands are handled by core's pr
implementation (default) or completely rejected (emulate_pr set to 0). We
additionally want to be able to do full reservation handling in
userspace. Therefore we need a way to set TRANSPORT_FLAG_PASSTHROUGH_PGR.

The inverted flag is displayed by attribute pgr_support. Since we moved
the flag from transport/backend to se_device in the previous commit, we now
can make it changeable per device by allowing to write the attribute. The
new field transport_flags_changeable in transport/backend is used to reject
writing if not allowed for a backend.

Regarding ALUA we also want to be able to passthrough commands to userspace
in tcmu. Therefore we need TRANSPORT_FLAG_PASSTHROUGH_ALUA to be
changeable, because by setting it we can switch off all ALUA checks in
core. So we also set TRANSPORT_FLAG_PASSTHROUGH_ALUA in tcmu's
transport_flags_changeable.

Of course, ALUA and reservation handling in userspace will work only, if
session/nexus information is sent to userspace along with every
command. This will be object of a patch series announced by Mike Christie.

Link: https://lore.kernel.org/r/20200427150823.15350-5-bstroesser@ts.fujitsu.com
Reviewed-by: Mike Christie <mchristi@redhat.com>
Signed-off-by: Bodo Stroesser <bstroesser@ts.fujitsu.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Bodo Stroesser and committed by
Martin K. Petersen
356ba2a8 69088a04

+57 -2
+54 -2
drivers/target/target_core_configfs.c
··· 1105 1105 flags & TRANSPORT_FLAG_PASSTHROUGH_ALUA ? 0 : 1); 1106 1106 } 1107 1107 1108 + static ssize_t alua_support_store(struct config_item *item, 1109 + const char *page, size_t count) 1110 + { 1111 + struct se_dev_attrib *da = to_attrib(item); 1112 + struct se_device *dev = da->da_dev; 1113 + bool flag; 1114 + int ret; 1115 + 1116 + if (!(dev->transport->transport_flags_changeable & 1117 + TRANSPORT_FLAG_PASSTHROUGH_ALUA)) { 1118 + pr_err("dev[%p]: Unable to change SE Device alua_support:" 1119 + " alua_support has fixed value\n", dev); 1120 + return -EINVAL; 1121 + } 1122 + 1123 + ret = strtobool(page, &flag); 1124 + if (ret < 0) 1125 + return ret; 1126 + 1127 + if (flag) 1128 + dev->transport_flags &= ~TRANSPORT_FLAG_PASSTHROUGH_ALUA; 1129 + else 1130 + dev->transport_flags |= TRANSPORT_FLAG_PASSTHROUGH_ALUA; 1131 + return count; 1132 + } 1133 + 1108 1134 static ssize_t pgr_support_show(struct config_item *item, char *page) 1109 1135 { 1110 1136 struct se_dev_attrib *da = to_attrib(item); ··· 1138 1112 1139 1113 return snprintf(page, PAGE_SIZE, "%d\n", 1140 1114 flags & TRANSPORT_FLAG_PASSTHROUGH_PGR ? 0 : 1); 1115 + } 1116 + 1117 + static ssize_t pgr_support_store(struct config_item *item, 1118 + const char *page, size_t count) 1119 + { 1120 + struct se_dev_attrib *da = to_attrib(item); 1121 + struct se_device *dev = da->da_dev; 1122 + bool flag; 1123 + int ret; 1124 + 1125 + if (!(dev->transport->transport_flags_changeable & 1126 + TRANSPORT_FLAG_PASSTHROUGH_PGR)) { 1127 + pr_err("dev[%p]: Unable to change SE Device pgr_support:" 1128 + " pgr_support has fixed value\n", dev); 1129 + return -EINVAL; 1130 + } 1131 + 1132 + ret = strtobool(page, &flag); 1133 + if (ret < 0) 1134 + return ret; 1135 + 1136 + if (flag) 1137 + dev->transport_flags &= ~TRANSPORT_FLAG_PASSTHROUGH_PGR; 1138 + else 1139 + dev->transport_flags |= TRANSPORT_FLAG_PASSTHROUGH_PGR; 1140 + return count; 1141 1141 } 1142 1142 1143 1143 CONFIGFS_ATTR(, emulate_model_alias); ··· 1198 1146 CONFIGFS_ATTR(, unmap_granularity_alignment); 1199 1147 CONFIGFS_ATTR(, unmap_zeroes_data); 1200 1148 CONFIGFS_ATTR(, max_write_same_len); 1201 - CONFIGFS_ATTR_RO(, alua_support); 1202 - CONFIGFS_ATTR_RO(, pgr_support); 1149 + CONFIGFS_ATTR(, alua_support); 1150 + CONFIGFS_ATTR(, pgr_support); 1203 1151 1204 1152 /* 1205 1153 * dev_attrib attributes for devices using the target core SBC/SPC
+2
drivers/target/target_core_user.c
··· 2617 2617 .name = "user", 2618 2618 .owner = THIS_MODULE, 2619 2619 .transport_flags_default = TRANSPORT_FLAG_PASSTHROUGH, 2620 + .transport_flags_changeable = TRANSPORT_FLAG_PASSTHROUGH_PGR | 2621 + TRANSPORT_FLAG_PASSTHROUGH_ALUA, 2620 2622 .attach_hba = tcmu_attach_hba, 2621 2623 .detach_hba = tcmu_detach_hba, 2622 2624 .alloc_device = tcmu_alloc_device,
+1
include/target/target_core_backend.h
··· 24 24 struct module *owner; 25 25 26 26 u8 transport_flags_default; 27 + u8 transport_flags_changeable; 27 28 28 29 int (*attach_hba)(struct se_hba *, u32); 29 30 void (*detach_hba)(struct se_hba *);