]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/acquire.c
Move bnet_despool() into class in bsock.c
[bacula/bacula] / bacula / src / stored / acquire.c
index ab6f6f20c4b7420538d4026fe8de5e25bc48d806..21ae93a3d355cb6b7c3a25bf2c091220131e8e0a 100644 (file)
@@ -281,13 +281,13 @@ default_path:
       dcr->VolumeName, dev->print_name());
 
 get_out:
-   P(dev->mutex);
+   dev->lock();
    if (dcr->reserved_device) {
       dev->reserved_device--;
       Dmsg2(100, "Dec reserve=%d dev=%s\n", dev->reserved_device, dev->print_name());
       dcr->reserved_device = false;
    }
-   V(dev->mutex);
+   dev->unlock();
    dev->unblock();
    Dmsg1(50, "jcr->dcr=%p\n", jcr->dcr);
    return ok;
@@ -378,6 +378,29 @@ DCR *acquire_device_for_append(DCR *dcr)
           if (dev->num_writers == 0) {
              memcpy(&dev->VolCatInfo, &dcr->VolCatInfo, sizeof(dev->VolCatInfo));
           }
+
+          /*
+           *      Insanity check 
+           *
+           * Check to see if the tape position as defined by the OS is
+           *  the same as our concept.  If it is not, we bail out, because
+           *  it means the user has probably manually rewound the tape.
+           * Note, we check only if num_writers == 0, but this code will
+           *  also work fine for any number of writers. If num_writers > 0,
+           *  we probably should cancel all jobs using this device, or 
+           *  perhaps even abort the SD, or at a minimum, mark the tape
+           *  in error.  Another strategy with num_writers == 0, would be
+           *  to rewind the tape and do a new eod() request.
+           */
+          if (dev->is_tape() && dev->num_writers == 0) {
+             int32_t file = dev->get_os_tape_file();
+             if (file >= 0 && file != (int32_t)dev->get_file()) {
+                Jmsg(jcr, M_FATAL, 0, _("Invalid tape position on volume \"%s\"" 
+                     " on device %s. Expected %d, got %d\n"), 
+                     dev->VolHdr.VolumeName, dev->print_name(), dev->get_file(), file);
+                goto get_out;
+             }
+          }
       }
    } else {
       /* Not already in append mode, so mount the device */
@@ -408,13 +431,13 @@ DCR *acquire_device_for_append(DCR *dcr)
    }
    dev->VolCatInfo.VolCatJobs++;              /* increment number of jobs on vol */
    dir_update_volume_info(dcr, false);        /* send Volume info to Director */
-   P(dev->mutex);
+   dev->lock();
    if (dcr->reserved_device) {
       dev->reserved_device--;
       Dmsg2(100, "Dec reserve=%d dev=%s\n", dev->reserved_device, dev->print_name());
       dcr->reserved_device = false;
    }
-   V(dev->mutex);
+   dev->unlock();
    dev->unblock();
    return dcr;
 
@@ -422,13 +445,13 @@ DCR *acquire_device_for_append(DCR *dcr)
  * Error return
  */
 get_out:
-   P(dev->mutex);
+   dev->lock();
    if (dcr->reserved_device) {
       dev->reserved_device--;
       Dmsg2(100, "Dec reserve=%d dev=%s\n", dev->reserved_device, dev->print_name());
       dcr->reserved_device = false;
    }
-   V(dev->mutex);
+   dev->unlock();
    dev->unblock();
    return NULL;
 }