]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/dev.c
Extend idea of Prefer Mounted Volumes to mean a volume about
[bacula/bacula] / bacula / src / stored / dev.c
index f63f70f79afadcaaf2576cee08e6c20117847c13..4c9e0d20c0780f9b6bac11901125e8b223e95bc9 100644 (file)
@@ -1,3 +1,30 @@
+/*
+   Bacula® - The Network Backup Solution
+
+   Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
+
+   The main author of Bacula is Kern Sibbald, with contributions from
+   many others, a complete list can be found in the file AUTHORS.
+   This program is Free Software; you can redistribute it and/or
+   modify it under the terms of version two of the GNU General Public
+   License as published by the Free Software Foundation plus additions
+   that are listed in the file LICENSE.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
+
+   Bacula® is a registered trademark of John Walker.
+   The licensor of Bacula is the Free Software Foundation Europe
+   (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+   Switzerland, email:ftf@fsfeurope.org.
+*/
 /*
  *
  *   dev.c  -- low level operations on device (storage device)
@@ -5,7 +32,7 @@
  *              Kern Sibbald, MM
  *
  *     NOTE!!!! None of these routines are reentrant. You must
- *        use lock_device() and dev->unlock() at a higher level,
+ *        use dev->r_dlock() and dev->unlock() at a higher level,
  *        or use the xxx_device() equivalents.  By moving the
  *        thread synchronization to a higher level, we permit
  *        the higher level routines to "seize" the device and
  *
  *   Version $Id$
  */
-/*
-   Bacula® - The Network Backup Solution
-
-   Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
-
-   The main author of Bacula is Kern Sibbald, with contributions from
-   many others, a complete list can be found in the file AUTHORS.
-   This program is Free Software; you can redistribute it and/or
-   modify it under the terms of version two of the GNU General Public
-   License as published by the Free Software Foundation plus additions
-   that are listed in the file LICENSE.
-
-   This program is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-   02110-1301, USA.
-
-   Bacula® is a registered trademark of John Walker.
-   The licensor of Bacula is the Free Software Foundation Europe
-   (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
-   Switzerland, email:ftf@fsfeurope.org.
-*/
 
 /*
  * Handling I/O errors and end of tape conditions are a bit tricky.
@@ -254,6 +254,7 @@ init_dev(JCR *jcr, DEVRES *device)
    dev->clear_opened();
    dev->attached_dcrs = New(dlist(dcr, &dcr->dev_link));
    Dmsg2(29, "init_dev: tape=%d dev_name=%s\n", dev->is_tape(), dev->dev_name);
+   dev->initiated = true;
    
    return dev;
 }
@@ -782,18 +783,21 @@ bool DEVICE::rewind(DCR *dcr)
 
 void DEVICE::block(int why)
 {
-   lock_device(this);
+   r_dlock();              /* need recursive lock to block */
    block_device(this, why);
-   unlock();
+   r_dunlock();
 }
 
-void DEVICE::unblock()
-{  
-   lock();   
+void DEVICE::unblock(bool locked)
+{
+   if (!locked) {
+      dlock();
+   }
    unblock_device(this);
-   unlock();
+   dunlock();
 }
 
+
 const char *DEVICE::print_blocked() const 
 {
    switch (m_blocked) {
@@ -1806,14 +1810,10 @@ void DEVICE::clrerror(int func)
    /* On some systems such as NetBSD, this clears all errors */
    get_os_tape_file();
 
-/* Found on Linux */
+/* Found on Solaris */
 #ifdef MTIOCLRERR
 {
-   struct mtop mt_com;
-   mt_com.mt_op = MTIOCLRERR;
-   mt_com.mt_count = 1;
-   /* Clear any error condition on the tape */
-   tape_ioctl(m_fd, MTIOCTOP, (char *)&mt_com);
+   tape_ioctl(m_fd, MTIOCLRERR);
    Dmsg0(200, "Did MTIOCLRERR\n");
 }
 #endif
@@ -1849,7 +1849,11 @@ void DEVICE::clrerror(int func)
  */
 void DEVICE::clear_volhdr()
 {
-   free_volume(this);
+   /* If we have an unused volume associated with this drive, free it */
+   if (vol && !is_busy()) {
+      free_volume(this);
+   }
+   Dmsg1(100, "Clear volhdr vol=%s\n", VolHdr.VolumeName);
    memset(&VolHdr, 0, sizeof(VolHdr));
 }