Attachment 'scsilog.pl'

Download

   1 #!/usr/bin/perl 
   2 # scsilog: control linux 2.6 scsi logging level as with 
   3 # "echo log xxx n >/proc/scsi/scsi" in 2.4
   4 # 
   5 # (c) 2005 Martin Wilck <mwilck>AT<freenet.de>
   6 # This code is licensed under the GPL (http://www.gnu.org/licenses)
   7 
   8 $USAGE = "Usage: $0 [err|tim|sca|hlq|hlc|mlq|mlc|llq|llc|ioc|ALL] [0-7]\n";
   9 $PROC = "/proc/sys/dev/scsi/logging_level";
  10 
  11 if ($#ARGV != 1) { die ($USAGE); };
  12 
  13 $name = $ARGV[0];
  14 $n = $ARGV[1];
  15 
  16 @facilities = ("error", "timeout", "scan", "hlqueue", "hlcomplete", 
  17 	"mlqueue", "mlcomplete", "llqueue", "llcomplete", "ioctl", "ALL");
  18 @offset = (0, 3, 6, 9, 12, 
  19 	15, 18, 21, 24, 27, 30); # bit offset matching the above
  20 
  21 # Allow abbreviated args
  22 @choice = grep  { $facilities[$_] =~ /^$name/; } (0..$#facilities);
  23 if ($#choice != 0 || $n !~ /^[0-9]+$/ || $n < 0 || $n > 7 ) { die ($USAGE); };
  24 
  25 $fac = $choice[0];
  26 $name = $facilities[$fac];
  27 
  28 $old = 0;
  29 open (LL, "<$PROC") || die "cannot open $PROC";
  30 while ( <LL> ) { $old = int($_); };
  31 close LL;
  32 
  33 if ($name =~ /^ALL$/ ) {
  34 	$new = 0;
  35 	foreach $f (0..($#offset-1)) {
  36 		$new += $n * (1 << $offset[$f]);
  37 	}
  38 } else {
  39 	$mask = ((1 << ($offset[$fac+1] - $offset[$fac])) - 1) << $offset[$fac];
  40 	$new = $n * (1 << $offset[$fac]) + ($old & ~$mask)
  41 }
  42 
  43 if ($old != $new) {
  44 	printf "SCSI logging level old: 0x%x, new: 0x%x\n", $old, $new;
  45 	open (LL, ">$PROC") || die "cannot open $PROC for writing";
  46 	printf LL "0x%x\n", $new;
  47 	close LL;
  48 };
  49 
  50 exit 0;

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2006-01-04 23:06:11, 1.4 KB) [[attachment:scsilog.pl]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.