Commit f5ba6c86 authored by Cornelia Huck's avatar Cornelia Huck Committed by Martin Schwidefsky

[S390] cio: Clean up online_store.

Detangle the online_store code and make it more readable.
Signed-off-by: default avatarCornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: default avatarHeiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: default avatarMartin Schwidefsky <schwidefsky@de.ibm.com>
parent c9182e0f
...@@ -413,28 +413,18 @@ ccw_device_set_online(struct ccw_device *cdev) ...@@ -413,28 +413,18 @@ ccw_device_set_online(struct ccw_device *cdev)
return (ret == 0) ? -ENODEV : ret; return (ret == 0) ? -ENODEV : ret;
} }
static ssize_t static void online_store_handle_offline(struct ccw_device *cdev)
online_store (struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{ {
struct ccw_device *cdev = to_ccwdev(dev); if (cdev->private->state == DEV_STATE_DISCONNECTED)
int i, force, ret; ccw_device_remove_disconnected(cdev);
char *tmp; else if (cdev->drv && cdev->drv->set_offline)
ccw_device_set_offline(cdev);
}
if (atomic_cmpxchg(&cdev->private->onoff, 0, 1) != 0) static int online_store_recog_and_online(struct ccw_device *cdev)
return -EAGAIN; {
int ret;
if (cdev->drv && !try_module_get(cdev->drv->owner)) {
atomic_set(&cdev->private->onoff, 0);
return -EINVAL;
}
if (!strncmp(buf, "force\n", count)) {
force = 1;
i = 1;
} else {
force = 0;
i = simple_strtoul(buf, &tmp, 16);
}
if (i == 1) {
/* Do device recognition, if needed. */ /* Do device recognition, if needed. */
if (cdev->id.cu_type == 0) { if (cdev->id.cu_type == 0) {
ret = ccw_device_recognition(cdev); ret = ccw_device_recognition(cdev);
...@@ -442,43 +432,68 @@ online_store (struct device *dev, struct device_attribute *attr, const char *buf ...@@ -442,43 +432,68 @@ online_store (struct device *dev, struct device_attribute *attr, const char *buf
printk(KERN_WARNING"Couldn't start recognition " printk(KERN_WARNING"Couldn't start recognition "
"for device %s (ret=%d)\n", "for device %s (ret=%d)\n",
cdev->dev.bus_id, ret); cdev->dev.bus_id, ret);
goto out; return ret;
} }
wait_event(cdev->private->wait_q, wait_event(cdev->private->wait_q,
cdev->private->flags.recog_done); cdev->private->flags.recog_done);
} }
if (cdev->drv && cdev->drv->set_online) if (cdev->drv && cdev->drv->set_online)
ccw_device_set_online(cdev); ccw_device_set_online(cdev);
} else if (i == 0) { return 0;
if (cdev->private->state == DEV_STATE_DISCONNECTED) }
ccw_device_remove_disconnected(cdev); static void online_store_handle_online(struct ccw_device *cdev, int force)
else if (cdev->drv && cdev->drv->set_offline) {
ccw_device_set_offline(cdev); int ret;
}
ret = online_store_recog_and_online(cdev);
if (ret)
return;
if (force && cdev->private->state == DEV_STATE_BOXED) { if (force && cdev->private->state == DEV_STATE_BOXED) {
ret = ccw_device_stlck(cdev); ret = ccw_device_stlck(cdev);
if (ret) { if (ret) {
printk(KERN_WARNING"ccw_device_stlck for device %s " printk(KERN_WARNING"ccw_device_stlck for device %s "
"returned %d!\n", cdev->dev.bus_id, ret); "returned %d!\n", cdev->dev.bus_id, ret);
goto out; return;
} }
/* Do device recognition, if needed. */ if (cdev->id.cu_type == 0)
if (cdev->id.cu_type == 0) {
cdev->private->state = DEV_STATE_NOT_OPER; cdev->private->state = DEV_STATE_NOT_OPER;
ret = ccw_device_recognition(cdev); online_store_recog_and_online(cdev);
if (ret) {
printk(KERN_WARNING"Couldn't start recognition "
"for device %s (ret=%d)\n",
cdev->dev.bus_id, ret);
goto out;
} }
wait_event(cdev->private->wait_q,
cdev->private->flags.recog_done); }
static ssize_t online_store (struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
struct ccw_device *cdev = to_ccwdev(dev);
int i, force;
char *tmp;
if (atomic_cmpxchg(&cdev->private->onoff, 0, 1) != 0)
return -EAGAIN;
if (cdev->drv && !try_module_get(cdev->drv->owner)) {
atomic_set(&cdev->private->onoff, 0);
return -EINVAL;
} }
if (cdev->drv && cdev->drv->set_online) if (!strncmp(buf, "force\n", count)) {
ccw_device_set_online(cdev); force = 1;
i = 1;
} else {
force = 0;
i = simple_strtoul(buf, &tmp, 16);
}
switch (i) {
case 0:
online_store_handle_offline(cdev);
break;
case 1:
online_store_handle_online(cdev, force);
break;
default:
count = -EINVAL;
} }
out:
if (cdev->drv) if (cdev->drv)
module_put(cdev->drv->owner); module_put(cdev->drv->owner);
atomic_set(&cdev->private->onoff, 0); atomic_set(&cdev->private->onoff, 0);
......
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