+ set_bit(1, &cdev->private->registered);
+ if (device_add_files(&cdev->dev)) {
+ if (test_and_clear_bit(1, &cdev->private->registered))
+ device_unregister(&cdev->dev);
+ }
+}
+
+extern int css_get_ssd_info(struct subchannel *sch);
+
+void
+ccw_device_do_unreg_rereg(void *data)
+{
+ struct ccw_device *cdev;
+ struct subchannel *sch;
+ int need_rename;
+
+ cdev = (struct ccw_device *)data;
+ sch = to_subchannel(cdev->dev.parent);
+ if (cdev->private->devno != sch->schib.pmcw.dev) {
+ /*
+ * The device number has changed. This is usually only when
+ * a device has been detached under VM and then re-appeared
+ * on another subchannel because of a different attachment
+ * order than before. Ideally, we should should just switch
+ * subchannels, but unfortunately, this is not possible with
+ * the current implementation.
+ * Instead, we search for the old subchannel for this device
+ * number and deregister so there are no collisions with the
+ * newly registered ccw_device.
+ * FIXME: Find another solution so the block layer doesn't
+ * get possibly sick...
+ */
+ struct ccw_device *other_cdev;
+
+ need_rename = 1;
+ other_cdev = get_disc_ccwdev_by_devno(sch->schib.pmcw.dev,
+ cdev);
+ if (other_cdev) {
+ struct subchannel *other_sch;
+
+ other_sch = to_subchannel(other_cdev->dev.parent);
+ if (get_device(&other_sch->dev)) {
+ stsch(other_sch->irq, &other_sch->schib);
+ if (other_sch->schib.pmcw.dnv) {
+ other_sch->schib.pmcw.intparm = 0;
+ cio_modify(other_sch);
+ }
+ device_unregister(&other_sch->dev);
+ }
+ }
+ /* Update ssd info here. */
+ css_get_ssd_info(sch);
+ cdev->private->devno = sch->schib.pmcw.dev;
+ } else
+ need_rename = 0;
+ device_remove_files(&cdev->dev);
+ if (test_and_clear_bit(1, &cdev->private->registered))
+ device_del(&cdev->dev);
+ if (need_rename)
+ snprintf (cdev->dev.bus_id, BUS_ID_SIZE, "0.0.%04x",
+ sch->schib.pmcw.dev);
+ PREPARE_WORK(&cdev->private->kick_work,
+ ccw_device_add_changed, (void *)cdev);
+ queue_work(ccw_device_work, &cdev->private->kick_work);