Linux Storage - Hot removal of a LUN
Linux Storage Solution · Config document · referenced from RDAC problems and LUN removal
echo “${DSK} … opens with a typographic quote and never closes it. The eight echo 1>/sys/bus/scsi/devices/…/delete lines have no space before >, so the shell reads 1> as a redirection of file descriptor 1 and echo writes a bare newline into delete; echo 1 > was meant. As I understand it the kernel removes the device on any write to that attribute, so the lines worked, but by accident.Problem 2 of my notes: a LUN had to be removed from the running system without a reboot (hot remove). The notes collect three ways to say "delete" to the SCSI layer through sysfs, the command that shows which disk is which, a quoted English note about taking a path offline, a small script that prints the vendor and model of every block device, and, as the case that was done, the removal of all eight physical paths to the standby array DS5300-SITEB (array ID 1).
| Item | Value |
|---|---|
| Run as | root on mppsrv01 |
| Host | Red Hat Enterprise Linux AS 4, kernel 2.6.9-89.0.9.ELsmp, HBAs host0 and host1, virtual MPP adapter host2 |
| Devices | the virtual disks /dev/sdc and /dev/sdd (LUNs 1 and 2 of DS5300-SITEB on host2) and the eight physical devices behind them, 0:0:2:1 to 1:0:3:2 |
| Writes to | /sys/block/<sd>/device/delete, /sys/bus/scsi/devices/<h:c:t:l>/delete |
| Driver version | RDAC 09.03.0B05.0331 |
The commands
Removing a LUN by its disk name, where sd* is the disk device to be removed from the system. Here sdc and sdd, the two virtual disks of the standby array:
$ echo "1" > /sys/block/sdc/device/delete $ echo "1" > /sys/block/sdd/device/delete
Removing a LUN by its SCSI address, where h is the HBA number, c the channel on the HBA, t the SCSI target ID and l the LUN. The notes keep the pattern, not a run of it:
$ echo 1 > /sys/class/scsi_device/h:c:t:l/device/delete
The device name, the HBA number, the channel, the target and the LUN are found with one listing. The notes keep no output for it:
$ ls -l /dev/disk/by-*
The notes then quote a note in English, which I give as it stands: "Take the path offline using echo offline > /sys/block/sda/device/state. This will cause any subsequent IO sent to the device on this path to be failed immediately. Device-mapper-multipath will continue to use the remaining paths to the device." It speaks of Device-mapper multipath, not of RDAC, and sda in it is an example name, not the sda of this host, which is LUN 1 of the main array.
The small script "who uses what": for every block device that has a vendor attribute, print its name, vendor and model. It is kept as it was in the notes, with its unclosed typographic quote:
for DSK in `ls /sys/block/` do if [ -e "/sys/block/${DSK}/device/vendor" ] then VENDOR=`cat /sys/block/${DSK}/device/vendor` MODEL=`cat /sys/block/${DSK}/device/model` echo “${DSK} ${VENDOR} ${MODEL} fi done
The paths leading to the array with ID 1, DS5300-SITEB:
$ mppUtil -g 1 | grep PathId
output 4 lines
PathId: 77000002 (hostId: 0, channelId: 0, targetId: 2) PathId: 77010002 (hostId: 1, channelId: 0, targetId: 2) PathId: 77000003 (hostId: 0, channelId: 0, targetId: 3) PathId: 77010003 (hostId: 1, channelId: 0, targetId: 3)
Deleting every path to the array with ID 1: two hosts, two targets, two LUNs, eight SCSI devices. The lines are kept exactly, with the 1> of the note above; the notes write them in four pairs, one pair per path, separated by blank lines, which the fence leaves out:
$ echo 1>/sys/bus/scsi/devices/0\:0\:2\:1/delete $ echo 1>/sys/bus/scsi/devices/0\:0\:2\:2/delete $ echo 1>/sys/bus/scsi/devices/1\:0\:2\:1/delete $ echo 1>/sys/bus/scsi/devices/1\:0\:2\:2/delete $ echo 1>/sys/bus/scsi/devices/0\:0\:3\:1/delete $ echo 1>/sys/bus/scsi/devices/0\:0\:3\:2/delete $ echo 1>/sys/bus/scsi/devices/1\:0\:3\:1/delete $ echo 1>/sys/bus/scsi/devices/1\:0\:3\:2/delete
Reading it
| Command | What it does |
|---|---|
echo "1" > /sys/block/sdc/device/delete | asks the SCSI mid-layer to remove the device behind the block device sdc; here that is a virtual disk of the MPP adapter, so it is the virtual LUN that goes, not a physical path |
echo 1 > /sys/class/scsi_device/h:c:t:l/device/delete | the same, addressed by host:channel:target:lun instead of by disk name |
ls -l /dev/disk/by-* | the udev symlinks by id, by path and by uuid, which show which sd name belongs to which SCSI address and which identifier |
echo offline > /sys/block/sda/device/state | from the quoted note: fails all further I/O on that path at once; the sentence about Device-mapper multipath continuing on the remaining paths is about DM-Multipath, which this host did not use |
| the small script | prints <disk> <vendor> <model> for every SCSI block device; on this host that tells the VirtualDisk devices of the MPP adapter from the local disks. As I understand bash, the echo “${DSK} line prints a literal “ in front of each name because the shell does not treat the typographic quote as a quote; I did not run it |
mppUtil -g 1, piped through grep PathId | the four paths of array 1 as the driver sees them: targets 2 and 3 on hosts 0 and 1. The PathId line decodes itself; with two LUNs on each path, that is eight SCSI devices |
echo 1>/sys/bus/scsi/devices/0\:0\:2\:1/delete | removes the physical device 0:0:2:1 (host 0, channel 0, target 2, LUN 1); the colons are escaped for the shell, which is not needed but harmless. With 1> the attribute receives an empty line rather than 1; see the note |
The order of the eight lines follows the PathId list: first both LUNs of target 2 on host 0, then target 2 on host 1, then target 3 on hosts 0 and 1. What the notes do not hold: whether sdc and sdd were removed first (the first two lines) and the eight paths afterwards, or whether the two blocks are alternatives; a listing before and after; and whether the driver's mppBusRescan -d ("remove an unmapped or disconnected device", see mppBusRescan commands) was tried instead. The links section of the notes keeps a forum thread titled "RDAC capable of hot removing unmapped LUNs?", so the question was on my mind.
Checked against the Linux kernel 7.2 and Red Hat Enterprise Linux 10
| As built | Today |
|---|---|
echo 1 > /sys/block/sdX/device/delete, echo 1 > /sys/bus/scsi/devices/h:c:t:l/delete | Both attributes still exist in drivers/scsi/scsi_sysfs.c, and /sys/block/sdX/device/delete is the step Red Hat's current guide gives for removing a block device: after multipath -f and blockdev --flushbufs, "Remove each path to the device from the SCSI subsystem: echo 1 > /sys/block/device-name/device/delete" |
echo offline > /sys/block/sda/device/state, from the quoted note | The state attribute still exists and still knows offline. The step with exactly that wording ("Device-mapper-multipath will continue to use the remaining paths") is in the Red Hat Enterprise Linux 7 storage guide and no longer in the 9 and 10 guides |
| removing the paths behind an RDAC virtual LUN by hand | The package readme states that "the Linux RDAC driver doesn't support LUN deletion", which explains why this was done in sysfs rather than with a driver command. RDAC was discontinued with SANtricity OS 11.25 |
1> instead of 1 > | Still easy to mistype; the research for this write-up did not verify how the kernel treats an empty write to delete, so my reading that any write triggers the removal stays a reading |