diff options
author | Bob Beck <beck@cvs.openbsd.org> | 2006-05-29 01:21:39 +0000 |
---|---|---|
committer | Bob Beck <beck@cvs.openbsd.org> | 2006-05-29 01:21:39 +0000 |
commit | 27a16b790c0ecf158549999962e91682aa8b2955 (patch) | |
tree | fc45d22ba6fffe58631286492b8c78c1590b0a60 /bin/chio/chio.c | |
parent | dcebce3c1b1a2615c854d95091b20ee6520737ca (diff) |
Make chio have a connection between st(4) devices and "drives" in a
changer - chio will then attempt to open the /dev/rstX device when doing
a move from a source of drive X, and will attempt to unload the tape.
this avoids issues where pickers madly attempt to grab a busy tape on
completely decoupled libraries, or fail to grab an unloaded tape
on tightly coupled libraries, the extra unload being harmless if the
media has already been ejected.
The mapping between st(4) devices and ch drives is by default a
simple mapping between picker drive X being mapped to /dev/rstX, however
for non-obvious or complicated configurations, we support a /etc/chio.conf
file in which the drives for a changer may have their corresponding
st(4) devices defined individually. chio will use the default
mapping if the /etc/chio.conf file is not present, or does not define
a st(4) device for a changer drive.
(example chio.conf and man page changes to come)
yacc parser for chio.conf written by henning@,
ok henning@, krw@
Diffstat (limited to 'bin/chio/chio.c')
-rw-r--r-- | bin/chio/chio.c | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/bin/chio/chio.c b/bin/chio/chio.c index e5f37787f15..ec130837bd3 100644 --- a/bin/chio/chio.c +++ b/bin/chio/chio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: chio.c,v 1.12 2006/04/25 15:41:05 deraadt Exp $ */ +/* $OpenBSD: chio.c,v 1.13 2006/05/29 01:21:38 beck Exp $ */ /* $NetBSD: chio.c,v 1.1.1.1 1996/04/03 00:34:38 thorpej Exp $ */ /* @@ -35,6 +35,7 @@ #include <sys/param.h> #include <sys/ioctl.h> +#include <sys/mtio.h> #include <sys/chio.h> #include <err.h> #include <errno.h> @@ -44,10 +45,13 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <util.h> #include "defs.h" #include "pathnames.h" +#define _PATH_CH_CONF "/etc/chio.conf" +extern char *parse_tapedev(const char *, const char *, int); /* parse.y */ extern char *__progname; /* from crt0.o */ static void usage(void); @@ -176,6 +180,28 @@ do_move(char *cname, int argc, char *argv[]) cmd.cm_fromunit = parse_element_unit(*argv); ++argv; --argc; + if (cmd.cm_fromtype == CHET_DT) { + /* + * from unit is a drive - make sure the tape + * in it is unmounted before we attempt to move + * it to avoid errors in "disconnected" type + * pickers where the drive is on a seperate target + * from the changer. + */ + int mtfd; + struct mtop mtoffl = { MTOFFL, 1 }; + char * tapedev = parse_tapedev(_PATH_CH_CONF, changer_name, cmd.cm_fromunit); + mtfd = opendev(tapedev, O_RDONLY, OPENDEV_PART | OPENDEV_DRCT, + NULL); + if (mtfd == -1) + err(1, "%s drive %d (%s): open", changer_name, + cmd.cm_fromunit, tapedev); + if (ioctl(mtfd, MTIOCTOP, &mtoffl) == -1) + err(1, "%s drive %d (%s): rewoffl", changer_name, + cmd.cm_fromunit, tapedev); + close(mtfd); + } + /* <to ET> */ cmd.cm_totype = parse_element_type(*argv); ++argv; --argc; |