X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Fstored%2Fmount.c;h=98c3b80b3eb7780810439dd0af747f52aed2414e;hb=5c358307600ad7cd6983b8773f8d7dc1e7346c56;hp=2f292de2091c3d28fd4cd36e465ac069f61ee6ce;hpb=5dfc1f669ea6d5b83c3a32b0ac2bbe5d9d7afe8f;p=bacula%2Fbacula diff --git a/bacula/src/stored/mount.c b/bacula/src/stored/mount.c index 2f292de209..98c3b80b3e 100644 --- a/bacula/src/stored/mount.c +++ b/bacula/src/stored/mount.c @@ -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.