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, ...@@ -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, static ssize_t dasd_ff_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct dasd_devmap *devmap;
unsigned int val; unsigned int val;
int rc;
devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
if (IS_ERR(devmap))
return PTR_ERR(devmap);
if (kstrtouint(buf, 0, &val) || val > 1) if (kstrtouint(buf, 0, &val) || val > 1)
return -EINVAL; return -EINVAL;
spin_lock(&dasd_devmap_lock); rc = dasd_set_feature(to_ccwdev(dev), DASD_FEATURE_FAILFAST, val);
if (val)
devmap->features |= DASD_FEATURE_FAILFAST; return rc ? : count;
else
devmap->features &= ~DASD_FEATURE_FAILFAST;
if (devmap->device)
devmap->device->features = devmap->features;
spin_unlock(&dasd_devmap_lock);
return count;
} }
static DEVICE_ATTR(failfast, 0644, dasd_ff_show, dasd_ff_store); static DEVICE_ATTR(failfast, 0644, dasd_ff_show, dasd_ff_store);
...@@ -769,30 +759,28 @@ static ssize_t ...@@ -769,30 +759,28 @@ static ssize_t
dasd_ro_store(struct device *dev, struct device_attribute *attr, dasd_ro_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct dasd_devmap *devmap; struct ccw_device *cdev = to_ccwdev(dev);
struct dasd_device *device; struct dasd_device *device;
unsigned int val; unsigned int val;
int rc;
devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
if (IS_ERR(devmap))
return PTR_ERR(devmap);
if (kstrtouint(buf, 0, &val) || val > 1) if (kstrtouint(buf, 0, &val) || val > 1)
return -EINVAL; return -EINVAL;
spin_lock(&dasd_devmap_lock); rc = dasd_set_feature(cdev, DASD_FEATURE_READONLY, val);
if (val) if (rc)
devmap->features |= DASD_FEATURE_READONLY; return rc;
else
devmap->features &= ~DASD_FEATURE_READONLY; device = dasd_device_from_cdev(cdev);
device = devmap->device; if (IS_ERR(device))
if (device) { return PTR_ERR(device);
device->features = devmap->features;
val = val || test_bit(DASD_FLAG_DEVICE_RO, &device->flags); val = val || test_bit(DASD_FLAG_DEVICE_RO, &device->flags);
} if (device->block && device->block->gdp)
spin_unlock(&dasd_devmap_lock);
if (device && device->block && device->block->gdp)
set_disk_ro(device->block->gdp, val); set_disk_ro(device->block->gdp, val);
dasd_put_device(device);
return count; return count;
} }
...@@ -819,25 +807,15 @@ static ssize_t ...@@ -819,25 +807,15 @@ static ssize_t
dasd_erplog_store(struct device *dev, struct device_attribute *attr, dasd_erplog_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct dasd_devmap *devmap;
unsigned int val; unsigned int val;
int rc;
devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
if (IS_ERR(devmap))
return PTR_ERR(devmap);
if (kstrtouint(buf, 0, &val) || val > 1) if (kstrtouint(buf, 0, &val) || val > 1)
return -EINVAL; return -EINVAL;
spin_lock(&dasd_devmap_lock); rc = dasd_set_feature(to_ccwdev(dev), DASD_FEATURE_ERPLOG, val);
if (val)
devmap->features |= DASD_FEATURE_ERPLOG; return rc ? : count;
else
devmap->features &= ~DASD_FEATURE_ERPLOG;
if (devmap->device)
devmap->device->features = devmap->features;
spin_unlock(&dasd_devmap_lock);
return count;
} }
static DEVICE_ATTR(erplog, 0644, dasd_erplog_show, dasd_erplog_store); 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, ...@@ -1376,27 +1354,17 @@ static ssize_t dasd_reservation_policy_store(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct dasd_devmap *devmap; struct ccw_device *cdev = to_ccwdev(dev);
int rc; 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)) 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)) else if (sysfs_streq("fail", buf))
devmap->features |= DASD_FEATURE_FAILONSLCK; rc = dasd_set_feature(cdev, DASD_FEATURE_FAILONSLCK, 1);
else else
rc = -EINVAL; rc = -EINVAL;
if (devmap->device)
devmap->device->features = devmap->features; return rc ? : count;
spin_unlock(&dasd_devmap_lock);
if (rc)
return rc;
else
return count;
} }
static DEVICE_ATTR(reservation_policy, 0644, static DEVICE_ATTR(reservation_policy, 0644,
...@@ -1522,7 +1490,7 @@ dasd_set_feature(struct ccw_device *cdev, int feature, int flag) ...@@ -1522,7 +1490,7 @@ dasd_set_feature(struct ccw_device *cdev, int feature, int flag)
{ {
struct dasd_devmap *devmap; struct dasd_devmap *devmap;
devmap = dasd_find_busid(dev_name(&cdev->dev)); devmap = dasd_devmap_from_cdev(cdev);
if (IS_ERR(devmap)) if (IS_ERR(devmap))
return PTR_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