From: Kern Sibbald Date: Tue, 26 Sep 2006 10:30:24 +0000 (+0000) Subject: kes Add back code to open tape device nonblocking, but if rewind fails X-Git-Tag: Release-2.0.0~412 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=79778147c3d9a9885501adfc78b16276d6e59c31;p=bacula%2Fbacula kes Add back code to open tape device nonblocking, but if rewind fails release file descriptor. kes Modify acquire.c to first try autoloading the device. Also, ask operator to mount tape if drive cannot be opened. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@3505 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/stored/acquire.c b/bacula/src/stored/acquire.c index 57b30160fb..728e7cc378 100644 --- a/bacula/src/stored/acquire.c +++ b/bacula/src/stored/acquire.c @@ -167,6 +167,9 @@ bool acquire_device_for_read(DCR *dcr) Mmsg1(dev->errmsg, _("Job %d canceled.\n"), jcr->JobId); goto get_out; /* error return */ } + + autoload_device(dcr, 0, NULL); + /* * This code ensures that the device is ready for * reading. If it is a file, it opens it. @@ -174,15 +177,9 @@ bool acquire_device_for_read(DCR *dcr) */ Dmsg1(100, "bstored: open vol=%s\n", dcr->VolumeName); if (dev->open(dcr, OPEN_READ_ONLY) < 0) { - if (dev->dev_errno == EIO) { /* no tape loaded */ - Jmsg3(jcr, M_WARNING, 0, _("Read open device %s Volume \"%s\" failed (EIO): ERR=%s\n"), - dev->print_name(), dcr->VolumeName, dev->bstrerror()); - goto default_path; - } - - Jmsg3(jcr, M_FATAL, 0, _("Read open device %s Volume \"%s\" failed: ERR=%s\n"), - dev->print_name(), dcr->VolumeName, dev->bstrerror()); - goto get_out; + Jmsg3(jcr, M_WARNING, 0, _("Read open device %s Volume \"%s\" failed: ERR=%s\n"), + dev->print_name(), dcr->VolumeName, dev->bstrerror()); + goto default_path; } Dmsg1(100, "opened dev %s OK\n", dev->print_name()); diff --git a/bacula/src/stored/dev.c b/bacula/src/stored/dev.c index 0d0110510d..805a4183a6 100644 --- a/bacula/src/stored/dev.c +++ b/bacula/src/stored/dev.c @@ -326,6 +326,8 @@ void DEVICE::open_tape_device(DCR *dcr, int omode) int timeout = max_open_wait; struct mtop mt_com; utime_t start_time = time(NULL); + + Dmsg0(29, "Open dev: device is tape\n"); get_autochanger_loaded_slot(dcr); @@ -343,12 +345,17 @@ void DEVICE::open_tape_device(DCR *dcr, int omode) Dmsg2(100, "Try open %s mode=%s\n", print_name(), mode_to_str(omode)); /* Use system open() */ #if defined(HAVE_WIN32) + + /* Windows Code */ if ((fd = tape_open(dev_name, mode)) < 0) { dev_errno = errno; } #else + /* UNIX Code */ + for ( ;; ) { - fd = ::open(dev_name, mode); + /* Try non-blocking open */ + fd = ::open(dev_name, mode+O_NONBLOCK); if (fd < 0) { berrno be; dev_errno = errno; @@ -365,8 +372,23 @@ void DEVICE::open_tape_device(DCR *dcr, int omode) clear_opened(); Dmsg2(100, "Rewind error on %s close: ERR=%s\n", print_name(), be.strerror(dev_errno)); + /* If we get busy, device is probably rewinding, try again */ + if (dev_errno != EBUSY) { + break; /* error -- no medium */ + } } else { - dev_errno = 0; + /* Got fd and rewind worked, so we must have medium in drive */ + ::close(fd); + fd = ::open(dev_name, mode); /* open normally */ + if (fd < 0) { + berrno be; + dev_errno = errno; + Dmsg5(050, "Open error on %s omode=%d mode=%x errno=%d: ERR=%s\n", + print_name(), omode, mode, errno, be.strerror()); + break; + } else { + dev_errno = 0; + } set_os_device_parameters(this); /* do system dependent stuff */ break; /* Successfully opened and rewound */ } diff --git a/bacula/src/version.h b/bacula/src/version.h index 530bbd840c..72716a11ca 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -4,8 +4,8 @@ #undef VERSION #define VERSION "1.39.23" -#define BDATE "24 September 2006" -#define LSMDATE "24Sep06" +#define BDATE "26 September 2006" +#define LSMDATE "26Sep06" #define BYEAR "2006" /* year for copyright messages in progs */ /* Debug flags */ diff --git a/bacula/technotes-1.39 b/bacula/technotes-1.39 index 39099acc75..5e98be19f3 100644 --- a/bacula/technotes-1.39 +++ b/bacula/technotes-1.39 @@ -1,6 +1,11 @@ Technical notes on version 1.39 General: +26Sep06 +kes Add back code to open tape device nonblocking, but if rewind fails + release file descriptor. +kes Modify acquire.c to first try autoloading the device. Also, ask operator + to mount tape if drive cannot be opened. 25Sep06 kes Update src/win32/dll/bacula.def for change in BPIPE definition for Win32 build.