[ltp] scsi vs ata ?

Dan Sawyer linux-thinkpad@linux-thinkpad.org
Sun, 22 Jun 2008 12:08:50 -0700


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

The script below errors with:

syntax error at - line 7, near "first
        open "
Execution of - aborted due to compilation errors.

I did a diff of the scripts and do not see any difference.

Dan



Dmitry E. Mikhailov wrote:
>> Thanks again. That worked. 
>>     
>
> Let's fix the script. Back to the original.
>
> Let's try to skip 'nicely' powering down the HDD. I think it could be a 
> problem.
>
> Try the next one:
>
> #!/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
>
>
>
>
>   

--------------050401000507070307050202
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">
<small>The script below errors with:<br>
<br>
syntax error at - line 7, near "first<br>
        open "<br>
Execution of - aborted due to compilation errors.<br>
<br>
I did a diff of the scripts and do not see any difference. <br>
<br>
Dan <br>
<br>
</small><br>
<br>
Dmitry E. Mikhailov wrote:
<blockquote cite="mid:200806222018.30250.sexandvodka@gmail.com"
 type="cite">
  <blockquote type="cite">
    <pre wrap="">Thanks again. That worked. 
    </pre>
  </blockquote>
  <pre wrap=""><!---->
Let's fix the script. Back to the original.

Let's try to skip 'nicely' powering down the HDD. I think it could be a 
problem.

Try the next one:

#!/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 - "$@" &lt;&lt;'EOPERL'  # let's do it in Perl
        for $major_minor (@ARGV) {
                $major_minor =~ m/^(\d+):(\d+)$/ or die;
                push(@tgt_rdevs, ($1&lt;&lt;8)|$2);
        }
        # Sort by reverse length of mount point, to unmount sub-directories 
first
        open MOUNTS,"&lt;/proc/mounts" or die "$!";
        @mounts=sort { length($b-&gt;[1]) &lt;=&gt; length($a-&gt;[1]) } map { [ split ] } 
&lt;MOUNTS&gt;;
        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 &gt; /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` &amp;&amp; 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 &gt; $ULTRABAY_SYSDIR/delete
fi
sync
# Turn off power to the UltraBay:
if [ -d /sys/devices/platform/bay.0 ]; then
        echo 1 &gt; /sys/devices/platform/bay.0/eject
elif [ -e /proc/acpi/ibm/bay ]; then
        echo eject &gt; /proc/acpi/ibm/bay
fi
# Tell the user we're OK
echo 12 &gt; /proc/acpi/ibm/beep




  </pre>
</blockquote>
</body>
</html>

--------------050401000507070307050202--