From ip@albatross.mcc.ac.uk  Wed Aug  9 04:07:05 2000
Return-Path: <ip@albatross.mcc.ac.uk>
Received: from probity.mcc.ac.uk (probity.mcc.ac.uk [130.88.200.94])
	by hub.freebsd.org (Postfix) with ESMTP id 632EC37B9FF
	for <FreeBSD-gnats-submit@freebsd.org>; Wed,  9 Aug 2000 04:07:03 -0700 (PDT)
	(envelope-from ip@albatross.mcc.ac.uk)
Received: from albatross.mcc.ac.uk ([130.88.202.16])
	by probity.mcc.ac.uk with esmtp (Exim 2.05 #4)
	id 13MThO-000EO1-00
	for FreeBSD-gnats-submit@freebsd.org; Wed, 9 Aug 2000 12:07:02 +0100
Received: (from ip@localhost)
	by albatross.mcc.ac.uk (8.9.3/8.9.1) id MAA14134;
	Wed, 9 Aug 2000 12:07:01 +0100 (BST)
	(envelope-from ip)
Message-Id: <200008091107.MAA14134@albatross.mcc.ac.uk>
Date: Wed, 9 Aug 2000 12:07:01 +0100 (BST)
From: ip@mcc.ac.uk
Sender: ip@albatross.mcc.ac.uk
Reply-To: ip@mcc.ac.uk
To: FreeBSD-gnats-submit@freebsd.org
Subject: autoloader support in dump(8)
X-Send-Pr-Version: 3.2

>Number:         20501
>Category:       bin
>Synopsis:       [patch] dump(8) extra flag to dump to offline autoloaders at EOT
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Aug 09 04:10:01 PDT 2000
>Closed-Date:    
>Last-Modified:  Sat May 24 14:39:51 UTC 2008
>Originator:     Ian Pallfreeman
>Release:        FreeBSD 3.5-STABLE i386
>Organization:
Manchester Computing
	         The University
		 Oxford Road
	         Manchester M13 9PL
		 UK
>Environment:

Half-a-dozen or so clunky old HP DAT autoloaders and no Solaris

>Description:

Solaris has an additional ("l") flag to dump (aka ufsdump) which offlines
a tape drive after EOT is detected. This tells DAT autoloaders which are
in manual mode (i.e. the changer LUN hasn't seen any commands since the
pod was loaded) to unload the current tape and load the next, if possible.
The dump then continues without manual intervention until all tapes are
written.

The code is pretty simple. When EOT is reached, and we've waited for the tape
to rewind, we do an OFFLINE ioctl and then wait again for two minutes or so
until the tape opens successfully. If it doesn't, we assume we've used all
the tapes in the pod and ask for manual intervention as before.

Similar patches applied to FreeBSD 4.1-STABLE and NetBSD/SPARC 1.4.1.

>How-To-Repeat:



>Fix:

--- main.c.orig	Mon May  8 10:52:15 2000
+++ main.c	Wed Aug  9 11:46:32 2000
@@ -87,6 +87,7 @@
 long	dev_bsize = 1;	/* recalculated below */
 long	blocksperfile;	/* output blocks per file */
 char	*host = NULL;	/* remote host (if any) */
+int	loader = 0;	/* offline tape autoloader */
 
 static long numarg __P((char *, long, long));
 static void obsolete __P((int *, char **[]));
@@ -123,9 +124,9 @@
 
 	obsolete(&argc, &argv);
 #ifdef KERBEROS
-#define optstring "0123456789aB:b:cd:f:h:kns:T:uWw"
+#define optstring "0123456789aB:b:cd:f:h:klns:T:uWw"
 #else
-#define optstring "0123456789aB:b:cd:f:h:ns:T:uWw"
+#define optstring "0123456789aB:b:cd:f:h:lns:T:uWw"
 #endif
 	while ((ch = getopt(argc, argv, optstring)) != -1)
 #undef optstring
@@ -173,6 +174,10 @@
 			dokerberos = 1;
 			break;
 #endif
+
+		case 'l':		/* tape loader */
+			loader = 1;
+			break;
 
 		case 'n':		/* notify operators */
 			notify = 1;
--- tape.c.orig	Sat Aug 28 01:12:39 1999
+++ tape.c	Wed Aug  9 11:46:03 2000
@@ -43,6 +43,8 @@
 #include <sys/socket.h>
 #include <sys/time.h>
 #include <sys/wait.h>
+#include <sys/ioctl.h>
+#include <sys/mtio.h>
 #ifdef sunos
 #include <sys/vnode.h>
 
@@ -78,6 +80,7 @@
 extern	int ntrec;		/* blocking factor on tape */
 extern	int cartridge;
 extern	char *host;
+extern  int loader;
 char	*nexttape;
 
 static	int atomic __P((ssize_t (*)(), int, char *, int));
@@ -374,20 +377,46 @@
 close_rewind()
 {
 	time_t tstart_changevol, tend_changevol;
+	int gottape=0;
 
 	trewind();
 	if (nexttape)
 		return;
 	(void)time((time_t *)&(tstart_changevol));
-	if (!nogripe) {
-		msg("Change Volumes: Mount volume #%d\n", tapeno+1);
-		broadcast("CHANGE DUMP VOLUMES!\7\7\n");
+	if (loader) {
+		struct mtop MtOp;
+		int f,tx=0;
+
+		msg("Mounting next tape on %s\n",tape);
+
+		if ((f = open(tape,0)) < 0) 
+		        quit("can't re-open tape loader after rewind");
+		
+		MtOp.mt_op = MTOFFL;
+		MtOp.mt_count = 1;
+		if (ioctl(f,MTIOCTOP,&MtOp) < 0)
+			quit("can't offline tape loader");
+                (void) close(f);
+		sleep(10);
+                while ((f = open(tape,0)) < 0 && tx++ < 12)
+                        sleep (10);
+		if (f >= 0) {
+		        (void) close(f);
+                        gottape = 1;
+		}
 	}
-	while (!query("Is the new volume mounted and ready to go?"))
-		if (query("Do you want to abort?")) {
-			dumpabort(0);
-			/*NOTREACHED*/
+	if (!gottape) {
+		if (!nogripe) {
+	        	msg("Change Volumes: Mount volume #%d\n", tapeno+1);
+                        broadcast("CHANGE DUMP VOLUMES!\7\7\n");               
 		}
+		while (!query("Is the new volume mounted and ready to go?"))
+	        	if (query("Do you want to abort?")) {
+	                	dumpabort(0);
+		         	/*NOTREACHED*/
+	         	}
+	}
+
 	(void)time((time_t *)&(tend_changevol));
 	if ((tstart_changevol != (time_t)-1) && (tend_changevol != (time_t)-1))
 		tstart_writing += (tend_changevol - tstart_changevol);


>Release-Note:
>Audit-Trail:

From: Matthew Jacob <mjacob@feral.com>
To: ip@mcc.ac.uk
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: bin/20501: autoloader support in dump(8)
Date: Wed, 9 Aug 2000 08:56:35 -0700 (PDT)

 Why don't you just use the 'eject on close' tape device?
 

From: Ian Pallfreeman <ip@albatross.mcc.ac.uk>
To: mjacob@feral.com
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: bin/20501: autoloader support in dump(8)
Date: Wed, 9 Aug 2000 17:12:33 +0100 (BST)

 Hi Matt,
 
 > Why don't you just use the 'eject on close' tape device?
 
 First thought: doh... didn't know there was one... can't find it in the
 mtio manpage.
 
 But I'd still need to tell dump to proceed. Doing it this way means I can
 write an entire pod without manual intervention. 
 
 Cheers,
 
 Ian.
 -- 
      Network Unit, Manchester Computing, The University, Manchester, UK.
      mail: ip@mcc.ac.uk | phone: +44-161-275-6006 | fax: +44-161-275-6040
 	     "Europe's Premier Research Supercomputing Facility"
            Another android exhibiting signs of the Munich Syndrome.
 

From: Matthew Jacob <mjacob@feral.com>
To: ip@mcc.ac.uk
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: bin/20501: autoloader support in dump(8)
Date: Wed, 9 Aug 2000 09:21:53 -0700 (PDT)

 'sa(4)' man page
 
 I see your point, but if you're going to use dump, this method only works for
 stackers. It'd be better if you swiped amanda's perl script which also can
 then work with real changers using chio, no?
 
Responsible-Changed-From-To: freebsd-bugs->mjacob 
Responsible-Changed-By: mjacob 
Responsible-Changed-When: Mon Oct 1 22:36:42 PDT 2001 
Responsible-Changed-Why:  
I'll look at it. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=20501 
State-Changed-From-To: open->feedback 
State-Changed-By: linimon 
State-Changed-When: Thu Aug 26 02:36:17 GMT 2004 
State-Changed-Why:  
With bugmeister hat on, reassign from inactive committer. 


Responsible-Changed-From-To: mjacob->freebsd-bugs 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Thu Aug 26 02:36:17 GMT 2004 
Responsible-Changed-Why:  
Is this still a problem with modern versions of FreeBSD? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=20501 
Responsible-Changed-From-To: freebsd-bugs->mjacob 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Thu Aug 26 06:06:04 GMT 2004 
Responsible-Changed-Why:  
mjacob has reactived his commit bit.  mea culpa for the bogus reassignment. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=20501 
State-Changed-From-To: feedback->open 
State-Changed-By: linimon 
State-Changed-When: Thu Aug 26 19:16:01 GMT 2004 
State-Changed-Why:  
Feedback received. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=20501 

Adding to audit trail from personal email recevied 07/04/2005 as a
side-effect of some old email being reposted:

I'm not quite sure why this reappeared in my mailbox. I've had a few people ask
me for the patch over the years, including one guy who wanted it to work with
rmt for remote drives -- it'll need tweaking for $OSVER > 4.11. I'd assumed
this PR was forgotten about.

AFAIK, modern versions of FreeBSD still don't do this, but I don't have a
-CURRENT box right now, just 5.4. But the DAT autoloaders are no longer in
use, so its not a problem (for me).

Cheers,

Ian.
Responsible-Changed-From-To: mjacob->freebsd-bugs 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Sat Aug 4 12:11:22 UTC 2007 
Responsible-Changed-Why:  
Assignee has turned in his commit bit, so return to pool. 

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