All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] target: fix the pgr/alua_support_store functions
@ 2021-09-03 12:48 Maurizio Lombardi
  2021-09-04 17:43 ` Bodo Stroesser
  2021-09-04 20:05 ` michael.christie
  0 siblings, 2 replies; 4+ messages in thread
From: Maurizio Lombardi @ 2021-09-03 12:48 UTC (permalink / raw)
  To: martin.petersen; +Cc: bostroesser, michael.christie, target-devel, linux-scsi

Commit 356ba2a8bc8d ("scsi: target: tcmu: Make pgr_support and
alua_support attributes writable")
introduced support for changeable alua_support and pgr_support
target attributes. They can only be changed
if the backstore is user-backed, otherwise the kernel returns -EINVAL.

This caused a regression in targetcli/rtslib because now a warning
is triggered when performing a target restore that includes
non-userbacked backstores, even if rtslib is not trying to change
the attributes' values:

$ targetctl restore
Storage Object block/storage1: Cannot set attribute alua_support:
[Errno 22] Invalid argument, skipped
Storage Object block/storage1: Cannot set attribute pgr_support:
[Errno 22] Invalid argument, skipped

Fix this warning by returning an error only if we are really
going to flip the PGR/ALUA bit in the transport_flags field,
otherwise we'll do nothing and return success.

Return EOPNOTSUPP instead of EINVAL if the pgr/alua attributes
can't be changed, this way it'll be possible for userspace to understand
if the operation failed because an invalid value has been passed
to strtobool() or because the attributes are fixed.

Fixes: 356ba2a8bc8d ("scsi: target: tcmu: Make pgr_support and alua_support attributes writable")

Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
---
 drivers/target/target_core_configfs.c | 32 +++++++++++++++++----------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c
index 102ec644bc8a..72d750f753bf 100644
--- a/drivers/target/target_core_configfs.c
+++ b/drivers/target/target_core_configfs.c
@@ -1110,20 +1110,24 @@ static ssize_t alua_support_store(struct config_item *item,
 {
 	struct se_dev_attrib *da = to_attrib(item);
 	struct se_device *dev = da->da_dev;
-	bool flag;
+	bool flag, oldflag;
 	int ret;
 
+	ret = strtobool(page, &flag);
+	if (ret < 0)
+		return ret;
+
+	oldflag = !(dev->transport_flags & TRANSPORT_FLAG_PASSTHROUGH_ALUA);
+	if (flag == oldflag)
+		return count;
+
 	if (!(dev->transport->transport_flags_changeable &
 	      TRANSPORT_FLAG_PASSTHROUGH_ALUA)) {
 		pr_err("dev[%p]: Unable to change SE Device alua_support:"
 			" alua_support has fixed value\n", dev);
-		return -EINVAL;
+		return -EOPNOTSUPP;
 	}
 
-	ret = strtobool(page, &flag);
-	if (ret < 0)
-		return ret;
-
 	if (flag)
 		dev->transport_flags &= ~TRANSPORT_FLAG_PASSTHROUGH_ALUA;
 	else
@@ -1145,20 +1149,24 @@ static ssize_t pgr_support_store(struct config_item *item,
 {
 	struct se_dev_attrib *da = to_attrib(item);
 	struct se_device *dev = da->da_dev;
-	bool flag;
+	bool flag, oldflag;
 	int ret;
 
+	ret = strtobool(page, &flag);
+	if (ret < 0)
+		return ret;
+
+	oldflag = !(dev->transport_flags & TRANSPORT_FLAG_PASSTHROUGH_PGR);
+	if (flag == oldflag)
+		return count;
+
 	if (!(dev->transport->transport_flags_changeable &
 	      TRANSPORT_FLAG_PASSTHROUGH_PGR)) {
 		pr_err("dev[%p]: Unable to change SE Device pgr_support:"
 			" pgr_support has fixed value\n", dev);
-		return -EINVAL;
+		return -EOPNOTSUPP;
 	}
 
-	ret = strtobool(page, &flag);
-	if (ret < 0)
-		return ret;
-
 	if (flag)
 		dev->transport_flags &= ~TRANSPORT_FLAG_PASSTHROUGH_PGR;
 	else
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] target: fix the pgr/alua_support_store functions
  2021-09-03 12:48 [PATCH] target: fix the pgr/alua_support_store functions Maurizio Lombardi
@ 2021-09-04 17:43 ` Bodo Stroesser
  2021-09-04 20:05 ` michael.christie
  1 sibling, 0 replies; 4+ messages in thread
From: Bodo Stroesser @ 2021-09-04 17:43 UTC (permalink / raw)
  To: Maurizio Lombardi, martin.petersen
  Cc: michael.christie, target-devel, linux-scsi

On 03.09.21 14:48, Maurizio Lombardi wrote:
> Commit 356ba2a8bc8d ("scsi: target: tcmu: Make pgr_support and
> alua_support attributes writable")
> introduced support for changeable alua_support and pgr_support
> target attributes. They can only be changed
> if the backstore is user-backed, otherwise the kernel returns -EINVAL.
> 
> This caused a regression in targetcli/rtslib because now a warning
> is triggered when performing a target restore that includes
> non-userbacked backstores, even if rtslib is not trying to change
> the attributes' values:
> 
> $ targetctl restore
> Storage Object block/storage1: Cannot set attribute alua_support:
> [Errno 22] Invalid argument, skipped
> Storage Object block/storage1: Cannot set attribute pgr_support:
> [Errno 22] Invalid argument, skipped
> 
> Fix this warning by returning an error only if we are really
> going to flip the PGR/ALUA bit in the transport_flags field,
> otherwise we'll do nothing and return success.
> 
> Return EOPNOTSUPP instead of EINVAL if the pgr/alua attributes
> can't be changed, this way it'll be possible for userspace to understand
> if the operation failed because an invalid value has been passed
> to strtobool() or because the attributes are fixed.
> 
> Fixes: 356ba2a8bc8d ("scsi: target: tcmu: Make pgr_support and alua_support attributes writable")
> 
> Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
> ---
Reviewed-by: Bodo Stroesser <bostroesser@gmail.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] target: fix the pgr/alua_support_store functions
  2021-09-03 12:48 [PATCH] target: fix the pgr/alua_support_store functions Maurizio Lombardi
  2021-09-04 17:43 ` Bodo Stroesser
@ 2021-09-04 20:05 ` michael.christie
  2021-09-06 11:37   ` Maurizio Lombardi
  1 sibling, 1 reply; 4+ messages in thread
From: michael.christie @ 2021-09-04 20:05 UTC (permalink / raw)
  To: Maurizio Lombardi, martin.petersen; +Cc: bostroesser, target-devel, linux-scsi

On 9/3/21 7:48 AM, Maurizio Lombardi wrote:
> Commit 356ba2a8bc8d ("scsi: target: tcmu: Make pgr_support and
> alua_support attributes writable")
> introduced support for changeable alua_support and pgr_support
> target attributes. They can only be changed
> if the backstore is user-backed, otherwise the kernel returns -EINVAL.
> 
> This caused a regression in targetcli/rtslib because now a warning
> is triggered when performing a target restore that includes
> non-userbacked backstores, even if rtslib is not trying to change
> the attributes' values:
> 
> $ targetctl restore
> Storage Object block/storage1: Cannot set attribute alua_support:
> [Errno 22] Invalid argument, skipped
> Storage Object block/storage1: Cannot set attribute pgr_support:
> [Errno 22] Invalid argument, skipped
> 
> Fix this warning by returning an error only if we are really
> going to flip the PGR/ALUA bit in the transport_flags field,
> otherwise we'll do nothing and return success.
> 
> Return EOPNOTSUPP instead of EINVAL if the pgr/alua attributes
> can't be changed, this way it'll be possible for userspace to understand
> if the operation failed because an invalid value has been passed
> to strtobool() or because the attributes are fixed.

Maybe you want to use -ENOSYS. Other lio sysfs files return that when the
operation is not supported. You could then handle all the warnings with
the same check.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] target: fix the pgr/alua_support_store functions
  2021-09-04 20:05 ` michael.christie
@ 2021-09-06 11:37   ` Maurizio Lombardi
  0 siblings, 0 replies; 4+ messages in thread
From: Maurizio Lombardi @ 2021-09-06 11:37 UTC (permalink / raw)
  To: michael.christie
  Cc: martin.petersen, Bodo Stroesser, target-devel, linux-scsi

so 4. 9. 2021 v 22:05 odesílatel <michael.christie@oracle.com> napsal:
>
> Maybe you want to use -ENOSYS. Other lio sysfs files return that when the
> operation is not supported. You could then handle all the warnings with
> the same check.
>

Ok, better to be consistent with other LIO sysfs functions.
I will submit a V2 later today.

Thanks,
Maurizio


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-09-06 11:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-03 12:48 [PATCH] target: fix the pgr/alua_support_store functions Maurizio Lombardi
2021-09-04 17:43 ` Bodo Stroesser
2021-09-04 20:05 ` michael.christie
2021-09-06 11:37   ` Maurizio Lombardi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.