[ltp] scsi vs ata ?

Dmitry E. Mikhailov linux-thinkpad@linux-thinkpad.org
Sun, 22 Jun 2008 12:54:52 +0600


> Thanks for the instructions! Those all work, except there is no libata.
> The unload works.

Great. Hardware is Ok, just as your kernel. There's a problem in the script.

> If I execute the echo > /sys/.../delete and then run the script it works.

It looks like truth. If we don't notify the kernel that HDD was removed, it'll 
wait for it forever.

Let's look through the script.

#!/bin/bash
ULTRABAY_SYSDIR='/sys/class/scsi_device/1:0:0:0/device'
#DMITRY: it looks like true
shopt -s nullglob

# Umount the filesystem(s) backed by the given major:minor device(s)
#DMITRY: this procedure would be invoked later. 
#DMITRY: it's not important because we don't mount filesystems in our test.
unmount_rdev() { perl - "$@" <<'EOPERL'  # let's do it in Perl
        for $major_minor (@ARGV) {
                $major_minor =~ m/^(\d+):(\d+)$/ or die;
                push(@tgt_rdevs, ($1<<8)|$2);
        }
        # Sort by reverse length of mount point, to unmount sub-directories 
first
        open MOUNTS,"</proc/mounts" or die "$!";
        @mounts=sort { length($b->[1]) <=> length($a->[1]) } map { [ split ] } 
<MOUNTS>;
        close MOUNTS;
        foreach $m (@mounts) {
                ($dev,$dir)=@$m;
                next unless -b $dev;  $rdev=(stat($dev))[6];
                next unless grep($_==$rdev, @tgt_rdevs);
                system("umount","-v","$dir")==0  or  $bad=1;
        }
        exit 1 if $bad;
EOPERL
}

# Get the UltraBay's /dev/foo block device node
#DMITRY: don't know if this procedure works, but it's not really important
ultrabay_dev_node() {
        UDEV_PATH="`readlink -e "$ULTRABAY_SYSDIR/block:"*`" || return 1
        UDEV_NAME="`udevinfo -q name -p $UDEV_PATH`" || return 1
        echo /dev/$UDEV_NAME
}


if [ -d $ULTRABAY_SYSDIR ]; then #DMITRY: if exists and is a directory
        sync
        # Unmount filesystems backed by this device
	#DMITRY: we don't mount so it doesn't matter.
#        unmount_rdev `cat $ULTRABAY_SYSDIR/block\:*/dev     \
#                          $ULTRABAY_SYSDIR/block\:*/*/dev`  \
#        || {
#                echo 10 > /proc/acpi/ibm/beep;  # error tone
#                exit 1;
#        }
#        sync
        # Nicely power off the device
#DMITRY: what if we don't power it down?
#        DEVNODE=`ultrabay_dev_node` && hdparm -Y $DEVNODE
        # Let HAL+KDE notice the unmount and let the disk spin down
#        sleep 0.5
        # Unregister this SCSI device:
        sync
        echo 1 > $ULTRABAY_SYSDIR/delete
fi
sync
# Turn off power to the UltraBay:
if [ -d /sys/devices/platform/bay.0 ]; then
        echo 1 > /sys/devices/platform/bay.0/eject
elif [ -e /proc/acpi/ibm/bay ]; then
        echo eject > /proc/acpi/ibm/bay
fi
# Tell the user we're OK
echo 12 > /proc/acpi/ibm/beep



Now the minimalistic version (no powerdowns, no unmounts) of the script is 
that:

#!/bin/bash
ULTRABAY_SYSDIR='/sys/class/scsi_device/1:0:0:0/device'
#DMITRY: it looks like true
shopt -s nullglob
if [ -d $ULTRABAY_SYSDIR ]; then 
        sync
        echo 1 > $ULTRABAY_SYSDIR/delete
fi
sync
# Turn off power to the UltraBay:
if [ -d /sys/devices/platform/bay.0 ]; then
        echo 1 > /sys/devices/platform/bay.0/eject
elif [ -e /proc/acpi/ibm/bay ]; then
        echo eject > /proc/acpi/ibm/bay
fi

Check that is works.

Best regards, Dmitry.



> Dmitry E. Mikhailov wrote:
> > On Saturday 21 June 2008 07:17:18 am Dan Sawyer wrote:
> >> Thanks for the reply,
> >>
> >> I am using the scripts at:
> >>
> >> http://www.thinkwiki.org/wiki/How_to_hotswap_UltraBay_devices
> >
> > Really nice script!
> >
> >> The eject gets to the beep at the end of the script. No files have been
> >> loaded so the only relevant steps are 4 and 5. Are they part of the
> >> scrip?
> >
> > I think the best way to test is doing everything by hand.
> >
> > So, 1st is to connect bay with HDD to the laptop. It doesn't matter
> > what's on that HDD, we wouldn't even try mounting it.
> >
> > Boot single-user: add option 'single' (with no quotes) to your kernel
> > parameters at boot time. That would allow us to remove any possible
> > interference from automount services etc.
> >
> > Once you got root commandline, check that you have ata_piix module:
> > [root@ibm ~]# lsmod|grep piix
> > ata_piix               20996  3
> > libata                140752  1 ata_piix
> >
> > Take an initial look at your /dev/ dir. It could look like this:
> > [root@ibm ~]# ls /dev/sd*
> > /dev/sda  /dev/sda1  /dev/sda2  /dev/sda3
> >
> > Then flush caches and instruct kernel (SCSI hostadapter1) to detect the
> > drive. [root@ibm ~]# sync
> > [root@ibm ~]# echo 0 0 0 > /sys/class/scsi_host/host1/scan
> >
> > Then take a look at /dev again: it should find new sdb:
> > [root@ibm ~]# ls /dev/sd*
> > /dev/sda  /dev/sda1  /dev/sda2  /dev/sda3  /dev/sdb  /dev/sdb1
> >
> > If /dev/sdb exists, then drive is found. It's time to try hot-removing
> > it.
> >
> > We'll skip the part of script which unmounts filesystems because we don't
> > mount it.
> >
> > Now instruct kernel to remove the drive.
> >
> > [root@ibm ~]# echo 1 > /sys/class/scsi_device/1:0:0:0/device/delete
> >
> > Check /dev to be sure the drive is removed. It should look just like the
> > initial one:
> > [root@ibm ~]# ls /dev/sd*
> > /dev/sda  /dev/sda1  /dev/sda2  /dev/sda3
> >
> > If /dev/sdb dissapeared, it's time to pray and trigger dock removal.
> > [root@ibm ~]# echo eject > /proc/acpi/ibm/bay
> >
> > my laptop has no bay device compiled into custom kernel, so I got this:
> > -bash: /proc/acpi/ibm/bay: No such file or directory
> > If you got the same, you also don't have it so don't try to physically
> > remove the drive. You need to recompile the kernel. Otherwise try
> > undocking. And post the results. After issuing dock eject command, but
> > before physically undocking the drive, save your kernel messages (you
> > can't post them immediately because in single user mode you won't get
> > Xwin or network). [root@ibm scsi_host]# dmesg>/dmesg
> >
> > Of cource, you'd find kernel messages in /dmesg file.
> >
> > Happy trying,
> > 	Dmitry