From nobody@FreeBSD.org  Wed Sep 22 19:45:48 2004
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 1FB5B16A4DD
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 22 Sep 2004 19:45:48 +0000 (GMT)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id D980F43D53
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 22 Sep 2004 19:45:47 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.12.11/8.12.11) with ESMTP id i8MJjlCc086496
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 22 Sep 2004 19:45:47 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.12.11/8.12.11/Submit) id i8MJjlGu086495;
	Wed, 22 Sep 2004 19:45:47 GMT
	(envelope-from nobody)
Message-Id: <200409221945.i8MJjlGu086495@www.freebsd.org>
Date: Wed, 22 Sep 2004 19:45:47 GMT
From: Carl Reisinger <cer@datadomain.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: mt -f /dev/rsa0.ctl comp off, or on, failes due to bug in scsi_sa.c:saioctl
X-Send-Pr-Version: www-2.3

>Number:         72010
>Category:       kern
>Synopsis:       [patch] mt -f /dev/rsa0.ctl comp off, or on, failes due to bug in scsi_sa.c:saioctl
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-scsi
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Sep 22 19:50:20 GMT 2004
>Closed-Date:    Thu Apr 14 04:51:48 GMT 2005
>Last-Modified:  Thu Apr 14 18:33:43 GMT 2005
>Originator:     Carl Reisinger
>Release:        4.9-STABLE
>Organization:
Mirapoint
>Environment:
FreeBSD trillian.mirapoint.com 4.9-STABLE FreeBSD 4.9-STABLE #2: Sat Feb 7 14:59:42 PST 2004   root@trillian.mirapoint.com:/usr/src/sys/compile/Trillian  i386   
>Description:
The comments in scsi_sa.c:saioctl claim one should be able to
disable/enable compression via the tape control device (along with
setting blocksize and density). However this does not work.

The issue is the switch(cmd) statement (second switch in the sourse code).
The cases for MTSETBSIZ, MTSETDNSTY and MTCOMP are incorrect. These three
are operations belonging to the cmd MTIOCTOP.
>How-To-Repeat:
With a SCSI tape device attached and no tape mounted

mt -f /dev/rsa0.ctl comp off

EINVAL is returned from the ioctl performed by mt(1).

With a tape mounted a

mt -f /dev/rsa0 comp off

will work
>Fix:
Brute force copy and paste approach:

case MTIOCSETEOTMODEL:
     /*
      * We need to acquire the peripheral here rather
      * than at open time because we are sharing writable
      * access to data structures.
      */
      s = splsoftcam();
      error = cam_periph_lock(periph, PRIBIO|PCATCH);
      if (error != 0) {
              splx(s);
              return (error);
      }
      didlockperiph = 1;
      break;

case MTIOCTOP: {
     struct mtop *mt;

     mt = (struct mtop *)arg;
     switch (mt->mt_op) {
     case MTSETBSIZ:
     case MTSETDNSTY:
     case MTCOMP:
     /*
      * We need to acquire the peripheral here rather
      * than at open time because we are sharing
      * writable access to data structures.
      */
          s = splsoftcam();
          error = cam_periph_lock(periph, PRIBIO|PCATCH);
          if (error != 0) {
                 splx(s);
                 return (error);
          }
          didlockperiph = 1;
          break;

default:
      return (EINVAL);
}

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-scsi 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Wed Sep 22 20:42:43 GMT 2004 
Responsible-Changed-Why:  
Over to mailing list. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=72010 
State-Changed-From-To: open->closed 
State-Changed-By: mjacob 
State-Changed-When: Thu Apr 14 04:51:31 GMT 2005 
State-Changed-Why:  
Fixed the bug (not quite the copy && paste, but close) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=72010 
>Unformatted:
