Skip to contentSkip to conversation

Linux enclosure services, hot swap issues

PATCH New James Bottomley 1 participant 5 messages Jul 30, 2009 – Aug 1, 2009 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

James Bottomley

author maintainer
#1 lore raw

cc to linux-scsi added

Quoted 167 lines · Chris Ptacek

Hello,
We are attempting to use the enclosure services (ses.c and enclosure.c) with Xyratex shelves (note we may have the same/similar issues with the IBM enclosure shelves) and have been running tests performing hot swapping of drives and seeing issues. There appear to be two similar issues.

1. When we pull a drive the drive information in the enclosure (slot, device link, etc) is not cleaned up and released. It appears that ses_intf_remove() is being called however as the device is not an enclosure it just returns and does nothing. This leaves a stale device link and other information within the sysfs information for that enclosure slot.

2. When we re-add a drive to the system the drive gets assigned a new port and number. At the moment we are unsure if this may be caused by refcounts on the old drive never being fully decremented. However as the drive has a new port name the stale link in the sysfs enclosure slot is no longer pointing to the drive.
It also appears that when adding the drive the ses_intf_add() function checks to see if the device is in an enclosure by examining the parent. However this appears to always fail. On boot when the actual enclosure is added it manages to walk all the drives and add them, however on some systems it appears that the boot ordering may cause only some subset of drives to appear.

Before issue, the device in slot 15 of enclosure looks as follows /sys/block/sde/device/enclosure_device:15/device -> ../../../../devices/pci0000:00/0000:00:06.0/0000:07:00.0/host2/port-2:0/expander-2:0/port-2:0:2/end_device-2:0:2/target2:0:2/2:0:2:0

NOTE: under the expander-2:0 it shows as "port-2:0:2" If we look at this directory it shows following...

-bash-3.2# ls /sys/devices/pci0000:00/0000:00:06.0/0000:07:00.0/host2/port-2:0/expander-2:0/ phy-2:0:10 phy-2:0:16 phy-2:0:22 phy-2:0:28 phy-2:0:34 phy-2:0:40 phy-2:0:9 port-2:0:13 port-2:0:19 port-2:0:24 port-2:0:7 uevent phy-2:0:11 phy-2:0:17 phy-2:0:23 phy-2:0:29 phy-2:0:35 phy-2:0:41 port-2:0:0 port-2:0:14 port-2:0:2 port-2:0:25 port-2:0:8 phy-2:0:12 phy-2:0:18 phy-2:0:24 phy-2:0:30 phy-2:0:36 phy-2:0:42 port-2:0:1 port-2:0:15 port-2:0:20 port-2:0:3 port-2:0:9 phy-2:0:13 phy-2:0:19 phy-2:0:25 phy-2:0:31 phy-2:0:37 phy-2:0:43 port-2:0:10 port-2:0:16 port-2:0:21 port-2:0:4 power
phy-2:0:14 phy-2:0:20 phy-2:0:26 phy-2:0:32 phy-2:0:38 phy-2:0:44 port-2:0:11 port-2:0:17 port-2:0:22 port-2:0:5 sas_device:expander-2:0 phy-2:0:15 phy-2:0:21 phy-2:0:27 phy-2:0:33 phy-2:0:39 phy-2:0:8 port-2:0:12 port-2:0:18 port-2:0:23 port-2:0:6 sas_expander:expander-2:0

=== REMOVE AND INSERT DRIVE =====

However, if we then remove the drive and insert it again the above
relationship breaks down. The link that we follow above is stale and
still points at "port-2:0:2".
/sys/block/sde/device/enclosure_device:15/device -> ../../../../devices/pci0000:00/0000:00:06.0/0000:07:00.0/host2/port-2:0/expander-2:0/port-2:0:2/end_device-2:0:2/target2:0:2/2:0:2:0

Yet, if we look at that expander directory we find that this port no longer exists and a new one was added now as "port-2:0:26".

-bash-3.2# ls /sys/devices/pci0000\:00/0000:00:06.0/0000:07:00.0/host2/port-2:0/expander-2:0/ phy-2:0:10 phy-2:0:16 phy-2:0:22 phy-2:0:28 phy-2:0:34 phy-2:0:40 phy-2:0:9 port-2:0:13 port-2:0:19 port-2:0:25 port-2:0:7 uevent phy-2:0:11 phy-2:0:17 phy-2:0:23 phy-2:0:29 phy-2:0:35 phy-2:0:41 port-2:0:0 port-2:0:14 port-2:0:20 port-2:0:26 port-2:0:8 phy-2:0:12 phy-2:0:18 phy-2:0:24 phy-2:0:30 phy-2:0:36 phy-2:0:42 port-2:0:1 port-2:0:15 port-2:0:21 port-2:0:3 port-2:0:9 phy-2:0:13 phy-2:0:19 phy-2:0:25 phy-2:0:31 phy-2:0:37 phy-2:0:43 port-2:0:10 port-2:0:16 port-2:0:22 port-2:0:4 power
phy-2:0:14 phy-2:0:20 phy-2:0:26 phy-2:0:32 phy-2:0:38 phy-2:0:44 port-2:0:11 port-2:0:17 port-2:0:23 port-2:0:5 sas_device:expander-2:0 phy-2:0:15 phy-2:0:21 phy-2:0:27 phy-2:0:33 phy-2:0:39 phy-2:0:8 port-2:0:12 port-2:0:18 port-2:0:24 port-2:0:6 sas_expander:expander-2:0

When adding the drive we are printing out the names and the parents.

Jul 30 11:29:53 sweng72 kernel: sd 2:0:51:0: [sdad] 976773168 512-byte 
hardware sectors: (500 GB/465 GiB)
Jul 30 11:29:53 sweng72 kernel: sd 2:0:51:0: [sdad] Write Protect is off
Jul 30 11:29:53 sweng72 kernel: sd 2:0:51:0: [sdad] Write cache: 
disabled, read cache: enabled, supports DPO and FUA
Jul 30 11:29:53 sweng72 kernel: sd 2:0:51:0: Attached scsi generic sg33 
type 0
## In ses_intf_add we are printing the name of the device passed in:
##  printk("%s : %s\n", __func__, dev_name(cdev));
Jul 30 11:29:53 sweng72 kernel: ses_intf_add : 2:0:51:0
Jul 30 11:29:53 sweng72 kernel: device: 'sdad': device_add

## In enclosure_add we are printing the name of the host passed in and the parentage:
## printk("%s : %s (%p)\n", __func__, dev_name(dev), dev);
## Then per enclosure
## printk("%s : edev %s parent %s \n", __func__,
dev_name(&edev->edev), dev_name(edev->edev.parent));

##   pdev = edev->edev.parent;
##   while(pdev != NULL)
##   {

## printk("%s : parent %s (%p)\n", __func__,
dev_name(pdev), pdev);
## pdev = pdev->parent;
## }

Jul 30 11:29:53 sweng72 kernel: enclosure_find : host2 (ffff8804cb804178)
Jul 30 11:29:54 sweng72 kernel: enclosure_find : edev 0:3:0:0 parent 0:3:0:0
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 0:3:0:0 
(ffff8804c9d63928)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 
target0:3:0 (ffff8804c9d62828)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent host0 
(ffff8804ca3d6978)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 
0000:04:00.0 (ffff8804cb867880)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 
0000:00:03.0 (ffff8804cb802880)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 
pci0000:00 (ffff8804cb800e00)
Jul 30 11:29:54 sweng72 kernel: enclosure_find : edev 2:0:24:0 parent 
2:0:24:0
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 2:0:24:0 
(ffff8804c98f5128)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 
target2:0:24 (ffff8804c9916428)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 
end_device-2:0:25 (ffff8804c9914000)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 
port-2:0:25 (ffff8804c9914800)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 
expander-2:0 (ffff8804c9c0b838)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent port-2:0 
(ffff8804c9c0d400)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent host2 
(ffff8804cb804178)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 
0000:07:00.0 (ffff8804cb86d880)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 
0000:00:06.0 (ffff8804cb803080)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 
pci0000:00 (ffff8804cb800e00)
Jul 30 11:29:54 sweng72 kernel: enclosure_find : edev 2:0:49:0 parent 
2:0:49:0
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 2:0:49:0 
(ffff8804c9a85928)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 
target2:0:49 (ffff8804c9a82828)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 
end_device-2:1:25 (ffff8804c9a81400)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 
port-2:1:25 (ffff8804c9a81c00)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 
expander-2:1 (ffff8804c9d11838)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent port-2:1 
(ffff8804ca1d3400)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent host2 
(ffff8804cb804178)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 
0000:07:00.0 (ffff8804cb86d880)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 
0000:00:06.0 (ffff8804cb803080)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 

pci0000:00 (ffff8804cb800e00)

Note these enclosures are double cabled, we have tried without it with the same results.
If we examine the parentage of the enclosures the host2 entry is way down the list, not the direct parent of the device passed in. This causes no enclosure to be found and no links, etc are handled for the drive that was added.

Quoted 2 lines

We were wondering if you may have any input on these issues and their expected operation?

The problems are basically because ses has no hotplug code (it doesn't expect the configuration to change). It shouldn't be too hard to add via the SCSI interface function, though; I'll take a look.

James

author maintainer
#2 lore raw
Quoted 170 lines · James Bottomley

cc to linux-scsi added

Quoted 167 lines · Chris Ptacek

Hello,
We are attempting to use the enclosure services (ses.c and enclosure.c) with Xyratex shelves (note we may have the same/similar issues with the IBM enclosure shelves) and have been running tests performing hot swapping of drives and seeing issues. There appear to be two similar issues.

1. When we pull a drive the drive information in the enclosure (slot, device link, etc) is not cleaned up and released. It appears that ses_intf_remove() is being called however as the device is not an enclosure it just returns and does nothing. This leaves a stale device link and other information within the sysfs information for that enclosure slot.

2. When we re-add a drive to the system the drive gets assigned a new port and number. At the moment we are unsure if this may be caused by refcounts on the old drive never being fully decremented. However as the drive has a new port name the stale link in the sysfs enclosure slot is no longer pointing to the drive.
It also appears that when adding the drive the ses_intf_add() function checks to see if the device is in an enclosure by examining the parent. However this appears to always fail. On boot when the actual enclosure is added it manages to walk all the drives and add them, however on some systems it appears that the boot ordering may cause only some subset of drives to appear.

Before issue, the device in slot 15 of enclosure looks as follows /sys/block/sde/device/enclosure_device:15/device -> ../../../../devices/pci0000:00/0000:00:06.0/0000:07:00.0/host2/port-2:0/expander-2:0/port-2:0:2/end_device-2:0:2/target2:0:2/2:0:2:0

NOTE: under the expander-2:0 it shows as "port-2:0:2" If we look at this directory it shows following...

-bash-3.2# ls /sys/devices/pci0000:00/0000:00:06.0/0000:07:00.0/host2/port-2:0/expander-2:0/ phy-2:0:10 phy-2:0:16 phy-2:0:22 phy-2:0:28 phy-2:0:34 phy-2:0:40 phy-2:0:9 port-2:0:13 port-2:0:19 port-2:0:24 port-2:0:7 uevent phy-2:0:11 phy-2:0:17 phy-2:0:23 phy-2:0:29 phy-2:0:35 phy-2:0:41 port-2:0:0 port-2:0:14 port-2:0:2 port-2:0:25 port-2:0:8 phy-2:0:12 phy-2:0:18 phy-2:0:24 phy-2:0:30 phy-2:0:36 phy-2:0:42 port-2:0:1 port-2:0:15 port-2:0:20 port-2:0:3 port-2:0:9 phy-2:0:13 phy-2:0:19 phy-2:0:25 phy-2:0:31 phy-2:0:37 phy-2:0:43 port-2:0:10 port-2:0:16 port-2:0:21 port-2:0:4 power
phy-2:0:14 phy-2:0:20 phy-2:0:26 phy-2:0:32 phy-2:0:38 phy-2:0:44 port-2:0:11 port-2:0:17 port-2:0:22 port-2:0:5 sas_device:expander-2:0 phy-2:0:15 phy-2:0:21 phy-2:0:27 phy-2:0:33 phy-2:0:39 phy-2:0:8 port-2:0:12 port-2:0:18 port-2:0:23 port-2:0:6 sas_expander:expander-2:0

=== REMOVE AND INSERT DRIVE =====

However, if we then remove the drive and insert it again the above
relationship breaks down. The link that we follow above is stale and
still points at "port-2:0:2".
/sys/block/sde/device/enclosure_device:15/device -> ../../../../devices/pci0000:00/0000:00:06.0/0000:07:00.0/host2/port-2:0/expander-2:0/port-2:0:2/end_device-2:0:2/target2:0:2/2:0:2:0

Yet, if we look at that expander directory we find that this port no longer exists and a new one was added now as "port-2:0:26".

-bash-3.2# ls /sys/devices/pci0000\:00/0000:00:06.0/0000:07:00.0/host2/port-2:0/expander-2:0/ phy-2:0:10 phy-2:0:16 phy-2:0:22 phy-2:0:28 phy-2:0:34 phy-2:0:40 phy-2:0:9 port-2:0:13 port-2:0:19 port-2:0:25 port-2:0:7 uevent phy-2:0:11 phy-2:0:17 phy-2:0:23 phy-2:0:29 phy-2:0:35 phy-2:0:41 port-2:0:0 port-2:0:14 port-2:0:20 port-2:0:26 port-2:0:8 phy-2:0:12 phy-2:0:18 phy-2:0:24 phy-2:0:30 phy-2:0:36 phy-2:0:42 port-2:0:1 port-2:0:15 port-2:0:21 port-2:0:3 port-2:0:9 phy-2:0:13 phy-2:0:19 phy-2:0:25 phy-2:0:31 phy-2:0:37 phy-2:0:43 port-2:0:10 port-2:0:16 port-2:0:22 port-2:0:4 power
phy-2:0:14 phy-2:0:20 phy-2:0:26 phy-2:0:32 phy-2:0:38 phy-2:0:44 port-2:0:11 port-2:0:17 port-2:0:23 port-2:0:5 sas_device:expander-2:0 phy-2:0:15 phy-2:0:21 phy-2:0:27 phy-2:0:33 phy-2:0:39 phy-2:0:8 port-2:0:12 port-2:0:18 port-2:0:24 port-2:0:6 sas_expander:expander-2:0

When adding the drive we are printing out the names and the parents.

Jul 30 11:29:53 sweng72 kernel: sd 2:0:51:0: [sdad] 976773168 512-byte 
hardware sectors: (500 GB/465 GiB)
Jul 30 11:29:53 sweng72 kernel: sd 2:0:51:0: [sdad] Write Protect is off
Jul 30 11:29:53 sweng72 kernel: sd 2:0:51:0: [sdad] Write cache: 
disabled, read cache: enabled, supports DPO and FUA
Jul 30 11:29:53 sweng72 kernel: sd 2:0:51:0: Attached scsi generic sg33 
type 0
## In ses_intf_add we are printing the name of the device passed in:
##  printk("%s : %s\n", __func__, dev_name(cdev));
Jul 30 11:29:53 sweng72 kernel: ses_intf_add : 2:0:51:0
Jul 30 11:29:53 sweng72 kernel: device: 'sdad': device_add

## In enclosure_add we are printing the name of the host passed in and the parentage:
## printk("%s : %s (%p)\n", __func__, dev_name(dev), dev);
## Then per enclosure
## printk("%s : edev %s parent %s \n", __func__,
dev_name(&edev->edev), dev_name(edev->edev.parent));

##   pdev = edev->edev.parent;
##   while(pdev != NULL)
##   {

## printk("%s : parent %s (%p)\n", __func__,
dev_name(pdev), pdev);
## pdev = pdev->parent;
## }

Jul 30 11:29:53 sweng72 kernel: enclosure_find : host2 (ffff8804cb804178)
Jul 30 11:29:54 sweng72 kernel: enclosure_find : edev 0:3:0:0 parent 0:3:0:0
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 0:3:0:0 
(ffff8804c9d63928)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 
target0:3:0 (ffff8804c9d62828)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent host0 
(ffff8804ca3d6978)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 
0000:04:00.0 (ffff8804cb867880)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 
0000:00:03.0 (ffff8804cb802880)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 
pci0000:00 (ffff8804cb800e00)
Jul 30 11:29:54 sweng72 kernel: enclosure_find : edev 2:0:24:0 parent 
2:0:24:0
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 2:0:24:0 
(ffff8804c98f5128)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 
target2:0:24 (ffff8804c9916428)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 
end_device-2:0:25 (ffff8804c9914000)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 
port-2:0:25 (ffff8804c9914800)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 
expander-2:0 (ffff8804c9c0b838)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent port-2:0 
(ffff8804c9c0d400)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent host2 
(ffff8804cb804178)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 
0000:07:00.0 (ffff8804cb86d880)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 
0000:00:06.0 (ffff8804cb803080)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 
pci0000:00 (ffff8804cb800e00)
Jul 30 11:29:54 sweng72 kernel: enclosure_find : edev 2:0:49:0 parent 
2:0:49:0
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 2:0:49:0 
(ffff8804c9a85928)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 
target2:0:49 (ffff8804c9a82828)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 
end_device-2:1:25 (ffff8804c9a81400)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 
port-2:1:25 (ffff8804c9a81c00)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 
expander-2:1 (ffff8804c9d11838)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent port-2:1 
(ffff8804ca1d3400)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent host2 
(ffff8804cb804178)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 
0000:07:00.0 (ffff8804cb86d880)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 
0000:00:06.0 (ffff8804cb803080)
Jul 30 11:29:54 sweng72 kernel: enclosure_find :         parent 

pci0000:00 (ffff8804cb800e00)

Note these enclosures are double cabled, we have tried without it with the same results.
If we examine the parentage of the enclosures the host2 entry is way down the list, not the direct parent of the device passed in. This causes no enclosure to be found and no links, etc are handled for the drive that was added.

Quoted 6 lines
Quoted 2 lines

We were wondering if you may have any input on these issues and their expected operation?

The problems are basically because ses has no hotplug code (it doesn't expect the configuration to change). It shouldn't be too hard to add via the SCSI interface function, though; I'll take a look.

Actually, there turned out to be three separate issues:

1. The way we handle enclosures in hot add doesn't contemplate that there may be more than one per host
2. The hot remove for components simply isn't plumbed in
3. We also need to update the enclosure pages so that we get the new mappings

I've got patches for each of these issues; at the end of the series, hotplug in a dual enclosure device system works pretty well for me.

James

author maintainer
#3 lore raw

PATCH 1/3 ses: fix hotplug with multiple devices and expanders

In a situation either with expanders or with multiple enclosure devices, hot add doesn't always work. This is because we try to find a single enclosure device attached to the host. Fix this by looping over all enclosure devices attached to the host and also by making the find loop recognise that the enclosure devices may be expander remote (i.e. not parented by the host).

---
 drivers/misc/enclosure.c  |   44 ++++++++++++++++++++++++++++++++------------
 drivers/scsi/ses.c        |   10 ++++++----
 include/linux/enclosure.h |    3 ++-
 3 files changed, 40 insertions(+), 17 deletions(-)
drivers/misc/enclosure.c +32 -12
index 348443b..789d121 100644
@@ -33,24 +33,44 @@ static DEFINE_MUTEX(container_list_lock);
 static struct class enclosure_class;
 
 /**
- * enclosure_find - find an enclosure given a device
- * @dev:	the device to find for
+ * enclosure_find - find an enclosure given a parent device
+ * @dev:	the parent to match against
+ * @start:	Optional enclosure device to start from (NULL if none)
  *
- * Looks through the list of registered enclosures to see
- * if it can find a match for a device.  Returns NULL if no
- * enclosure is found. Obtains a reference to the enclosure class
- * device which must be released with device_put().
+ * Looks through the list of registered enclosures to find all those
+ * with @dev as a parent.  Returns NULL if no enclosure is
+ * found. @start can be used as a starting point to obtain multiple
+ * enclosures per parent (should begin with NULL and then be set to
+ * each returned enclosure device). Obtains a reference to the
+ * enclosure class device which must be released with device_put().
+ * If @start is not NULL, a reference must be taken on it which is
+ * released before returning (this allows a loop through all
+ * enclosures to exit with only the reference on the enclosure of
+ * interest held).  Note that the @dev may correspond to the actual
+ * device housing the enclosure, in which case no iteration via @start
+ * is required.
  */
-struct enclosure_device *enclosure_find(struct device *dev)
+struct enclosure_device *enclosure_find(struct device *dev,
+					struct enclosure_device *start)
 {
 	struct enclosure_device *edev;
 
 	mutex_lock(&container_list_lock);
-	list_for_each_entry(edev, &container_list, node) {
-		if (edev->edev.parent == dev) {
-			get_device(&edev->edev);
-			mutex_unlock(&container_list_lock);
-			return edev;
+	edev = list_prepare_entry(start, &container_list, node);
+	if (start)
+		put_device(&start->edev);
+
+	list_for_each_entry_continue(edev, &container_list, node) {
+		struct device *parent = edev->edev.parent;
+		/* parent might not be immediate, so iterate up to
+		 * the root of the tree if necessary */
+		while (parent) {
+			if (parent == dev) {
+				get_device(&edev->edev);
+				mutex_unlock(&container_list_lock);
+				return edev;
+			}
+			parent = parent->parent;
 		}
 	}
 	mutex_unlock(&container_list_lock);
drivers/scsi/ses.c +6 -4
index 4f618f4..e1b8c82 100644
@@ -413,10 +413,11 @@ static int ses_intf_add(struct device *cdev,
 
 	if (!scsi_device_enclosure(sdev)) {
 		/* not an enclosure, but might be in one */
-		edev = enclosure_find(&sdev->host->shost_gendev);
-		if (edev) {
+		struct enclosure_device *prev = NULL;
+
+		while ((edev = enclosure_find(&sdev->host->shost_gendev, prev)) != NULL) {
 			ses_match_to_enclosure(edev, sdev);
-			put_device(&edev->edev);
+			prev = edev;
 		}
 		return -ENODEV;
 	}
@@ -625,7 +626,8 @@ static void ses_intf_remove(struct device *cdev,
 	if (!scsi_device_enclosure(sdev))
 		return;
 
-	edev = enclosure_find(cdev->parent);
+	/*  exact match to this enclosure */
+	edev = enclosure_find(cdev->parent, NULL);
 	if (!edev)
 		return;
 
include/linux/enclosure.h +2 -1
index 4332442..d77811e 100644
@@ -123,7 +123,8 @@ enclosure_component_register(struct enclosure_device *, unsigned int,
 int enclosure_add_device(struct enclosure_device *enclosure, int component,
 			 struct device *dev);
 int enclosure_remove_device(struct enclosure_device *enclosure, int component);
-struct enclosure_device *enclosure_find(struct device *dev);
+struct enclosure_device *enclosure_find(struct device *dev,
+					struct enclosure_device *start);
 int enclosure_for_each_device(int (*fn)(struct enclosure_device *, void *),
 			      void *data);
 
Signature · 1 line
1.6.3.3
author maintainer
#4 lore raw

PATCH 2/3 ses: add support for enclosure component hot removal

In reply to James Bottomley

Right at the moment, hot removal of a device within an enclosure does nothing (because the intf_remove only copes with enclosure removal not with component removal). Fix this by adding a function to remove the component. Also needed to fix the prototype of enclosure_remove_device, since we know the device we've removed but not the internal component number

---
 drivers/misc/enclosure.c  |   22 ++++++++++++++--------
 drivers/scsi/ses.c        |   33 ++++++++++++++++++++++++++-------
 include/linux/enclosure.h |    2 +-
 3 files changed, 41 insertions(+), 16 deletions(-)
drivers/misc/enclosure.c +14 -8
index 789d121..850706a 100644
@@ -332,19 +332,25 @@ EXPORT_SYMBOL_GPL(enclosure_add_device);
  * Returns zero on success or an error.
  *
  */
-int enclosure_remove_device(struct enclosure_device *edev, int component)
+int enclosure_remove_device(struct enclosure_device *edev, struct device *dev)
 {
 	struct enclosure_component *cdev;
+	int i;
 
-	if (!edev || component >= edev->components)
+	if (!edev || !dev)
 		return -EINVAL;
 
-	cdev = &edev->component[component];
-
-	device_del(&cdev->cdev);
-	put_device(cdev->dev);
-	cdev->dev = NULL;
-	return device_add(&cdev->cdev);
+	for (i = 0; i < edev->components; i++) {
+		cdev = &edev->component[i];
+		if (cdev->dev == dev) {
+			enclosure_remove_links(cdev);
+			device_del(&cdev->cdev);
+			put_device(dev);
+			cdev->dev = NULL;
+			return device_add(&cdev->cdev);
+		}
+	}
+	return -ENODEV;
 }
 EXPORT_SYMBOL_GPL(enclosure_remove_device);
 
drivers/scsi/ses.c +26 -7
index e1b8c82..be593c8 100644
@@ -616,18 +616,26 @@ static int ses_remove(struct device *dev)
 	return 0;
 }
 
-static void ses_intf_remove(struct device *cdev,
-			    struct class_interface *intf)
+static void ses_intf_remove_component(struct scsi_device *sdev)
+{
+	struct enclosure_device *edev, *prev = NULL;
+
+	while ((edev = enclosure_find(&sdev->host->shost_gendev, prev)) != NULL) {
+		prev = edev;
+		if (!enclosure_remove_device(edev, &sdev->sdev_gendev))
+			break;
+	}
+	if (edev)
+		put_device(&edev->edev);
+}
+
+static void ses_intf_remove_enclosure(struct scsi_device *sdev)
 {
-	struct scsi_device *sdev = to_scsi_device(cdev->parent);
 	struct enclosure_device *edev;
 	struct ses_device *ses_dev;
 
-	if (!scsi_device_enclosure(sdev))
-		return;
-
 	/*  exact match to this enclosure */
-	edev = enclosure_find(cdev->parent, NULL);
+	edev = enclosure_find(&sdev->sdev_gendev, NULL);
 	if (!edev)
 		return;
 
@@ -645,6 +653,17 @@ static void ses_intf_remove(struct device *cdev,
 	enclosure_unregister(edev);
 }
 
+static void ses_intf_remove(struct device *cdev,
+			    struct class_interface *intf)
+{
+	struct scsi_device *sdev = to_scsi_device(cdev->parent);
+
+	if (!scsi_device_enclosure(sdev))
+		ses_intf_remove_component(sdev);
+	else
+		ses_intf_remove_enclosure(sdev);
+}
+
 static struct class_interface ses_interface = {
 	.add_dev	= ses_intf_add,
 	.remove_dev	= ses_intf_remove,
include/linux/enclosure.h +1 -1
index d77811e..90d1c21 100644
@@ -122,7 +122,7 @@ enclosure_component_register(struct enclosure_device *, unsigned int,
 				 enum enclosure_component_type, const char *);
 int enclosure_add_device(struct enclosure_device *enclosure, int component,
 			 struct device *dev);
-int enclosure_remove_device(struct enclosure_device *enclosure, int component);
+int enclosure_remove_device(struct enclosure_device *, struct device *);
 struct enclosure_device *enclosure_find(struct device *dev,
 					struct enclosure_device *start);
 int enclosure_for_each_device(int (*fn)(struct enclosure_device *, void *),
Signature · 1 line
1.6.3.3
author maintainer
#5 lore raw

ses: update enclosure data on hot add

In reply to James Bottomley

Now that hot add works correctly, if a new device is added, we're still operating on stale enclosure data, so fix that by updating the enclosure diagnostic pages when we get notified of a device hot add

---
 drivers/misc/enclosure.c |    3 +
 drivers/scsi/ses.c       |  168 ++++++++++++++++++++++++++-------------------
 2 files changed, 100 insertions(+), 71 deletions(-)
drivers/misc/enclosure.c +3 -0
index 850706a..7b03930 100644
@@ -315,6 +315,9 @@ int enclosure_add_device(struct enclosure_device *edev, int component,
 
 	cdev = &edev->component[component];
 
+	if (cdev->dev == dev)
+		return -EEXIST;
+
 	if (cdev->dev)
 		enclosure_remove_links(cdev);
 
drivers/scsi/ses.c +97 -71

205 lines not on this page · raw message

Signature · 1 line
1.6.3.3