Commit 1081f3a7 authored by Jan Höppner's avatar Jan Höppner Committed by Martin Schwidefsky

s390/dasd: Make use of dasd_set_feature() more often

When setting certain attributes, we actually set the according feature
flag. Do this by using dasd_set_feature() at a few occurrences and
remove duplicate code.

In dasd_set_feature() dasd_find_busid() is used to retrieve the devmap
for the device in question. Combined with the change above, this would
require the device to be set online at least once so that a devmap is
being created. Change that by using dasd_devmap_from_cdev() instead,
which uses dasd_find_busid() first and will create a devmap accordingly
if there is none yet.
Reviewed-by: default avatarStefan Haberland <sth@linux.vnet.ibm.com>
Signed-off-by: default avatarJan Höppner <hoeppner@linux.vnet.ibm.com>
Signed-off-by: default avatarMartin Schwidefsky <schwidefsky@de.ibm.com>
parent ce7a788f
......@@ -725,25 +725,15 @@ static ssize_t dasd_ff_show(struct device *dev, struct device_attribute *attr,
static ssize_t dasd_ff_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
struct dasd_devmap *devmap;
unsigned int val;
devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
if (IS_ERR(devmap))
return PTR_ERR(devmap);
int rc;
if (kstrtouint(buf, 0, &val) || val > 1)
return -EINVAL;
spin_lock(&dasd_devmap_lock);
if (val)
devmap->features |= DASD_FEATURE_FAILFAST;
else
devmap->features &= ~DASD_FEATURE_FAILFAST;
if (devmap->device)
devmap->device->features = devmap->features;
spin_unlock(&dasd_devmap_lock);
return count;
rc = dasd_set_feature(to_ccwdev(dev), DASD_FEATURE_FAILFAST, val);
return rc ? : count;
}
static DEVICE_ATTR(failfast, 0644, dasd_ff_show, dasd_ff_store);
......@@ -769,30 +759,28 @@ static ssize_t
dasd_ro_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
struct dasd_devmap *devmap;
struct ccw_device *cdev = to_ccwdev(dev);
struct dasd_device *device;
unsigned int val;
devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
if (IS_ERR(devmap))
return PTR_ERR(devmap);
int rc;
if (kstrtouint(buf, 0, &val) || val > 1)
return -EINVAL;
spin_lock(&dasd_devmap_lock);
if (val)
devmap->features |= DASD_FEATURE_READONLY;
else
devmap->features &= ~DASD_FEATURE_READONLY;
device = devmap->device;
if (device) {
device->features = devmap->features;
rc = dasd_set_feature(cdev, DASD_FEATURE_READONLY, val);
if (rc)
return rc;
device = dasd_device_from_cdev(cdev);
if (IS_ERR(device))
return PTR_ERR(device);
val = val || test_bit(DASD_FLAG_DEVICE_RO, &device->flags);
}
spin_unlock(&dasd_devmap_lock);
if (device && device->block && device->block->gdp)
if (device->block && device->block->gdp)
set_disk_ro(device->block->gdp, val);
dasd_put_device(device);
return count;
}
......@@ -819,25 +807,15 @@ static ssize_t
dasd_erplog_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
struct dasd_devmap *devmap;
unsigned int val;
devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
if (IS_ERR(devmap))
return PTR_ERR(devmap);
int rc;
if (kstrtouint(buf, 0, &val) || val > 1)
return -EINVAL;
spin_lock(&dasd_devmap_lock);
if (val)
devmap->features |= DASD_FEATURE_ERPLOG;
else
devmap->features &= ~DASD_FEATURE_ERPLOG;
if (devmap->device)
devmap->device->features = devmap->features;
spin_unlock(&dasd_devmap_lock);
return count;
rc = dasd_set_feature(to_ccwdev(dev), DASD_FEATURE_ERPLOG, val);
return rc ? : count;
}
static DEVICE_ATTR(erplog, 0644, dasd_erplog_show, dasd_erplog_store);
......@@ -1376,27 +1354,17 @@ static ssize_t dasd_reservation_policy_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct dasd_devmap *devmap;
struct ccw_device *cdev = to_ccwdev(dev);
int rc;
devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
if (IS_ERR(devmap))
return PTR_ERR(devmap);
rc = 0;
spin_lock(&dasd_devmap_lock);
if (sysfs_streq("ignore", buf))
devmap->features &= ~DASD_FEATURE_FAILONSLCK;
rc = dasd_set_feature(cdev, DASD_FEATURE_FAILONSLCK, 0);
else if (sysfs_streq("fail", buf))
devmap->features |= DASD_FEATURE_FAILONSLCK;
rc = dasd_set_feature(cdev, DASD_FEATURE_FAILONSLCK, 1);
else
rc = -EINVAL;
if (devmap->device)
devmap->device->features = devmap->features;
spin_unlock(&dasd_devmap_lock);
if (rc)
return rc;
else
return count;
return rc ? : count;
}
static DEVICE_ATTR(reservation_policy, 0644,
......@@ -1522,7 +1490,7 @@ dasd_set_feature(struct ccw_device *cdev, int feature, int flag)
{
struct dasd_devmap *devmap;
devmap = dasd_find_busid(dev_name(&cdev->dev));
devmap = dasd_devmap_from_cdev(cdev);
if (IS_ERR(devmap))
return PTR_ERR(devmap);
......
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