Commit ef7ae7f7 authored by Maurizio Lombardi's avatar Maurizio Lombardi Committed by Martin K. Petersen

scsi: target: Fix the pgr/alua_support_store functions

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

This triggers a warning in the targetcli/rtslib code when performing a
target restore that includes non-userbacked backstores:

  # 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 code only if we are really going to
flip the PGR/ALUA bit in the transport_flags field, otherwise we will do
nothing and return success.

Return ENOSYS instead of EINVAL if the pgr/alua attributes can not be
changed, this way it will 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: 356ba2a8 ("scsi: target: tcmu: Make pgr_support and alua_support attributes writable")
Link: https://lore.kernel.org/r/20210906151809.52811-1-mlombard@redhat.comReviewed-by: default avatarBodo Stroesser <bostroesser@gmail.com>
Signed-off-by: default avatarMaurizio Lombardi <mlombard@redhat.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 7215e909
...@@ -1110,20 +1110,24 @@ static ssize_t alua_support_store(struct config_item *item, ...@@ -1110,20 +1110,24 @@ static ssize_t alua_support_store(struct config_item *item,
{ {
struct se_dev_attrib *da = to_attrib(item); struct se_dev_attrib *da = to_attrib(item);
struct se_device *dev = da->da_dev; struct se_device *dev = da->da_dev;
bool flag; bool flag, oldflag;
int ret; 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 & if (!(dev->transport->transport_flags_changeable &
TRANSPORT_FLAG_PASSTHROUGH_ALUA)) { TRANSPORT_FLAG_PASSTHROUGH_ALUA)) {
pr_err("dev[%p]: Unable to change SE Device alua_support:" pr_err("dev[%p]: Unable to change SE Device alua_support:"
" alua_support has fixed value\n", dev); " alua_support has fixed value\n", dev);
return -EINVAL; return -ENOSYS;
} }
ret = strtobool(page, &flag);
if (ret < 0)
return ret;
if (flag) if (flag)
dev->transport_flags &= ~TRANSPORT_FLAG_PASSTHROUGH_ALUA; dev->transport_flags &= ~TRANSPORT_FLAG_PASSTHROUGH_ALUA;
else else
...@@ -1145,20 +1149,24 @@ static ssize_t pgr_support_store(struct config_item *item, ...@@ -1145,20 +1149,24 @@ static ssize_t pgr_support_store(struct config_item *item,
{ {
struct se_dev_attrib *da = to_attrib(item); struct se_dev_attrib *da = to_attrib(item);
struct se_device *dev = da->da_dev; struct se_device *dev = da->da_dev;
bool flag; bool flag, oldflag;
int ret; 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 & if (!(dev->transport->transport_flags_changeable &
TRANSPORT_FLAG_PASSTHROUGH_PGR)) { TRANSPORT_FLAG_PASSTHROUGH_PGR)) {
pr_err("dev[%p]: Unable to change SE Device pgr_support:" pr_err("dev[%p]: Unable to change SE Device pgr_support:"
" pgr_support has fixed value\n", dev); " pgr_support has fixed value\n", dev);
return -EINVAL; return -ENOSYS;
} }
ret = strtobool(page, &flag);
if (ret < 0)
return ret;
if (flag) if (flag)
dev->transport_flags &= ~TRANSPORT_FLAG_PASSTHROUGH_PGR; dev->transport_flags &= ~TRANSPORT_FLAG_PASSTHROUGH_PGR;
else else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment