[ltp] scsi vs ata ?

Dan Sawyer linux-thinkpad@linux-thinkpad.org
Mon, 23 Jun 2008 19:21:52 -0700


This is a multi-part message in MIME format.
--------------060201000301040703070302
Content-Type: text/plain; charset=windows-1251; format=flowed
Content-Transfer-Encoding: 7bit

Dmitry,

If the script1 is run first script2 works. If script2 is run first it 
errors with the long error tone. (It runs now without the syntax error?) 
Any idea on how to debug the error?

script1:
#!/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

script2
#!/bin/bash
ULTRABAY_SYSDIR='/sys/class/scsi_device/1:0:0:0/device'
shopt -s nullglob

# Umount the filesystem(s) backed by the given major:minor device(s)
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
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
        sync
        # Unmount filesystems backed by this device
        unmount_rdev `cat $ULTRABAY_SYSDIR/block\:*/dev     \
                          $ULTRABAY_SYSDIR/block\:*/*/dev`  \
        || {
                echo 10 > /proc/acpi/ibm/beep;  # error tone
                exit 1;
        }
        sync

#DMITRY: Let's try NOT to 'nicely' power off the HDD
        # Nicely power off the device
#        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



--------------060201000301040703070302
Content-Type: text/html; charset=windows-1251
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=windows-1251"
 http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<font size="-1">Dmitry,<br>
<br>
If the script1 is run first script2 works. If script2 is run first it
errors with the long error tone. (It runs now without the syntax
error?) Any idea on how to debug the error? <br>
<br>
script1:<br>
#!/bin/bash<br>
ULTRABAY_SYSDIR='/sys/class/scsi_device/1:0:0:0/device'<br>
#DMITRY: it looks like true<br>
shopt -s nullglob<br>
if [ -d $ULTRABAY_SYSDIR ]; then <br>
        sync<br>
        echo 1 &gt; $ULTRABAY_SYSDIR/delete<br>
fi<br>
sync<br>
# Turn off power to the UltraBay:<br>
if [ -d /sys/devices/platform/bay.0 ]; then<br>
        echo 1 &gt; /sys/devices/platform/bay.0/eject<br>
elif [ -e /proc/acpi/ibm/bay ]; then<br>
        echo eject &gt; /proc/acpi/ibm/bay<br>
fi<br>
<br>
script2<br>
#!/bin/bash<br>
ULTRABAY_SYSDIR='/sys/class/scsi_device/1:0:0:0/device'<br>
shopt -s nullglob<br>
<br>
# Umount the filesystem(s) backed by the given major:minor device(s)<br>
unmount_rdev() { perl - "$@" &lt;&lt;'EOPERL'  # let's do it in Perl<br>
        for $major_minor (@ARGV) {<br>
                $major_minor =~ m/^(\d+):(\d+)$/ or die;<br>
                push(@tgt_rdevs, ($1&lt;&lt;8)|$2);<br>
        }<br>
        # Sort by reverse length of mount point, to unmount
sub-directories <br>
first<br>
        open MOUNTS,"&lt;/proc/mounts" or die "$!";<br>
        @mounts=sort { length($b-&gt;[1]) &lt;=&gt; length($a-&gt;[1])
} map { [ split ] } <br>
&lt;MOUNTS&gt;;<br>
        close MOUNTS;<br>
        foreach $m (@mounts) {<br>
                ($dev,$dir)=@$m;<br>
                next unless -b $dev;  $rdev=(stat($dev))[6];<br>
                next unless grep($_==$rdev, @tgt_rdevs);<br>
                system("umount","-v","$dir")==0  or  $bad=1;<br>
        }<br>
        exit 1 if $bad;<br>
EOPERL<br>
}<br>
<br>
# Get the UltraBay's /dev/foo block device node<br>
ultrabay_dev_node() {<br>
        UDEV_PATH="`readlink -e "$ULTRABAY_SYSDIR/block:"*`" || return 1<br>
        UDEV_NAME="`udevinfo -q name -p $UDEV_PATH`" || return 1<br>
        echo /dev/$UDEV_NAME<br>
}<br>
<br>
if [ -d $ULTRABAY_SYSDIR ]; then<br>
        sync<br>
        # Unmount filesystems backed by this device<br>
        unmount_rdev `cat $ULTRABAY_SYSDIR/block\:*/dev     \<br>
                          $ULTRABAY_SYSDIR/block\:*/*/dev`  \<br>
        || {<br>
                echo 10 &gt; /proc/acpi/ibm/beep;  # error tone<br>
                exit 1;<br>
        }<br>
        sync<br>
<br>
#DMITRY: Let's try NOT to 'nicely' power off the HDD<br>
        # Nicely power off the device<br>
#        DEVNODE=`ultrabay_dev_node` &amp;&amp; hdparm -Y $DEVNODE<br>
        # Let HAL+KDE notice the unmount and let the disk spin down<br>
#        sleep 0.5<br>
        # Unregister this SCSI device:<br>
        sync<br>
        echo 1 &gt; $ULTRABAY_SYSDIR/delete<br>
fi<br>
sync<br>
# Turn off power to the UltraBay:<br>
if [ -d /sys/devices/platform/bay.0 ]; then<br>
        echo 1 &gt; /sys/devices/platform/bay.0/eject<br>
elif [ -e /proc/acpi/ibm/bay ]; then<br>
        echo eject &gt; /proc/acpi/ibm/bay<br>
fi<br>
# Tell the user we're OK<br>
echo 12 &gt; /proc/acpi/ibm/beep<br>
<br>
</font><br>
</body>
</html>

--------------060201000301040703070302--