X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Fstored%2Fmount.c;h=98c3b80b3eb7780810439dd0af747f52aed2414e;hb=5c358307600ad7cd6983b8773f8d7dc1e7346c56;hp=6e5e1ff3fa3433d9a644d9b8cb9a59b378b56171;hpb=d4bec3ebd408991f16f56bc31cb5139e92cfaa9f;p=bacula%2Fbacula diff --git a/bacula/src/stored/mount.c b/bacula/src/stored/mount.c index 6e5e1ff3fa..98c3b80b3e 100644 --- a/bacula/src/stored/mount.c +++ b/bacula/src/stored/mount.c @@ -227,7 +227,7 @@ mount_next_vol: } /* If DVD, ignore the error, very often you cannot open the device * (when there is no DVD, or when the one inserted is a wrong one) */ - if (dev->poll || dev->is_dvd() || dev->is_removable()) { + if (dev->poll || dev->is_dvd()) { goto mount_next_vol; } else { Jmsg(jcr, M_ERROR, 0, _("Could not open device %s: ERR=%s\n"), @@ -474,7 +474,6 @@ void DCR::do_swapping(bool is_writing) { if (dev->must_unload()) { Dmsg1(100, "swapping: unloading %s\n", dev->print_name()); - unload_autochanger(this, -1); release_volume(); dev->clear_unload(); } @@ -486,12 +485,11 @@ void DCR::do_swapping(bool is_writing) if (dev->swap_dev) { if (dev->swap_dev->must_unload()) { if (dev->vol) { - dev->swap_dev->Slot = dev->vol->get_slot(); + dev->swap_dev->set_slot(dev->vol->get_slot()); } - Dmsg2(100, "Swap unloading slot=%d %s\n", dev->swap_dev->Slot, + Dmsg2(100, "Swap unloading slot=%d %s\n", dev->swap_dev->get_slot(), dev->swap_dev->print_name()); unload_dev(this, dev->swap_dev); - dev->Slot = -1; } if (dev->vol) { dev->vol->clear_swapping(); @@ -670,6 +668,8 @@ void DCR::mark_volume_not_inchanger() */ void DCR::release_volume() { + unload_autochanger(this, -1); + if (WroteVol) { Jmsg0(jcr, M_ERROR, 0, _("Hey!!!!! WroteVol non-zero !!!!!\n")); Dmsg0(190, "Hey!!!!! WroteVol non-zero !!!!!\n"); @@ -702,6 +702,44 @@ void DCR::release_volume() Dmsg0(190, "release_volume\n"); } +/* + * Insanity check + * + * Check to see if the tape position as defined by the OS is + * the same as our concept. If it is not, + * 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. + */ +bool DCR::is_tape_position_ok() +{ + 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_ERROR, 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); + /* + * If the current file is greater than zero, it means we probably + * have some bad count of EOF marks, so mark tape in error. Otherwise + * the operator might have moved the tape, so we just release it + * and try again. + */ + if (file > 0) { + mark_volume_in_error(); + } + release_volume(); + return false; + } + } + return true; +} + + /* * If we are reading, we come here at the end of the tape * and see if there are more volumes to be mounted.