2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2017 Kern Sibbald
6 The original author of Bacula is Kern Sibbald, with contributions
7 from many others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
21 * Routines for handling mounting tapes for reading and for
24 * Kern Sibbald, August MMII
28 #include "bacula.h" /* pull in global headers */
29 #include "stored.h" /* pull in Storage Deamon headers */
31 /* Make sure some EROFS is defined */
32 #ifndef EROFS /* read-only file system */
33 #define EROFS -1 /* make impossible errno */
36 static pthread_mutex_t mount_mutex = PTHREAD_MUTEX_INITIALIZER;
53 * If release is set, we rewind the current volume,
54 * which we no longer want, and ask the user (console)
55 * to mount the next volume.
57 * Continue trying until we get it, and then ensure
58 * that we can write on it.
60 * This routine returns a 0 only if it is REALLY
61 * impossible to get the requested Volume.
63 * This routine is entered with the device blocked, but not
67 bool DCR::mount_next_write_volume()
70 bool ask = false, recycle, autochanger;
75 Dmsg2(100, "Enter mount_next_volume(release=%d) dev=%s\n", dev->must_unload(),
78 init_device_wait_timers(dcr);
83 * Attempt to mount the next volume. If something non-fatal goes
84 * wrong, we come back here to re-try (new op messages, re-read
88 Dmsg1(100, "mount_next_vol retry=%d\n", retry);
89 /* Ignore retry if this is poll request */
90 if (dev->is_nospace() || retry++ > 4) {
91 /* Last ditch effort before giving up, force operator to respond */
94 if (!dir_ask_sysop_to_mount_volume(dcr, SD_APPEND)) {
95 Jmsg(jcr, M_FATAL, 0, _("Too many errors trying to mount %s device %s.\n"),
96 dev->print_type(), dev->print_name());
97 goto no_lock_bail_out;
100 Dmsg1(90, "Continue after dir_ask_sysop_to_mount. must_load=%d\n", dev->must_load());
102 if (job_canceled(jcr)) {
103 Jmsg(jcr, M_FATAL, 0, _("Job %d canceled.\n"), jcr->JobId);
108 if (dev->must_unload()) {
109 ask = true; /* ask operator to mount tape */
112 do_swapping(SD_APPEND);
115 if (!find_a_volume()) {
119 if (job_canceled(jcr)) {
122 Dmsg3(100, "After find_a_volume. Vol=%s Slot=%d VolType=%d\n",
123 getVolCatName(), VolCatInfo.Slot, VolCatInfo.VolCatType);
125 dev->notify_newvol_in_attached_dcrs(getVolCatName());
128 * Get next volume and ready it for append
129 * This code ensures that the device is ready for
130 * writing. We start from the assumption that there
131 * may not be a tape mounted.
133 * If the device is a file, we create the output
134 * file. If it is a tape, we check the volume name
135 * and move the tape to the end of data.
138 dcr->setVolCatInfo(false); /* out of date when Vols unlocked */
139 if (autoload_device(dcr, SD_APPEND, NULL) > 0) {
145 if (dev->is_autochanger() && !VolCatInfo.InChanger) {
146 ask = true; /* not in changer, do not retry */
151 Dmsg1(100, "autoload_dev returns %d\n", autochanger);
153 * If we autochanged to correct Volume or (we have not just
154 * released the Volume AND we can automount) we go ahead
155 * and read the label. If there is no tape in the drive,
156 * we will fail, recurse and ask the operator the next time.
158 if (!dev->must_unload() && dev->is_tape() && dev->has_cap(CAP_AUTOMOUNT)) {
159 Dmsg0(250, "(1)Ask=0\n");
160 ask = false; /* don't ask SYSOP this time */
162 /* Don't ask if not removable */
163 if (!dev->is_removable()) {
164 Dmsg0(250, "(2)Ask=0\n");
167 Dmsg2(100, "Ask=%d autochanger=%d\n", ask, autochanger);
171 dcr->setVolCatInfo(false); /* out of date when Vols unlocked */
172 if (!dir_ask_sysop_to_mount_volume(dcr, SD_APPEND)) {
173 Dmsg0(150, "Error return ask_sysop ...\n");
174 goto no_lock_bail_out;
178 if (job_canceled(jcr)) {
181 Dmsg3(100, "want vol=%s devvol=%s dev=%s\n", VolumeName,
182 dev->VolHdr.VolumeName, dev->print_name());
184 if (dev->poll && dev->has_cap(CAP_CLOSEONPOLL)) {
189 /* Try autolabel if enabled */
190 Dmsg1(100, "Try open Vol=%s\n", getVolCatName());
191 if (!dev->open_device(dcr, OPEN_READ_WRITE)) {
192 Dmsg1(100, "Try autolabel Vol=%s\n", getVolCatName());
194 try_autolabel(false); /* try to create a new volume label */
197 while (!dev->open_device(dcr, OPEN_READ_WRITE)) {
198 Dmsg1(100, "open_device failed: ERR=%s", dev->bstrerror());
199 if (dev->is_file() && dev->is_removable()) {
201 Dmsg0(150, "call scan_dir_for_vol\n");
202 if (ok && dev->scan_dir_for_volume(dcr)) {
203 if (dev->open_device(dcr, OPEN_READ_WRITE)) {
204 break; /* got a valid volume */
208 if (try_autolabel(false) == try_read_vol) {
209 break; /* created a new volume label */
212 /* ***FIXME*** if autochanger, before giving up try unload and load */
214 Jmsg4(jcr, M_WARNING, 0, _("Open of %s device %s Volume \"%s\" failed: ERR=%s\n"),
215 dev->print_type(), dev->print_name(), dcr->VolumeName, dev->bstrerror());
217 /* If not removable, Volume is broken. This is a serious issue here. */
218 if (dev->is_file() && !dev->is_removable()) {
219 Dmsg3(40, "Volume \"%s\" not loaded on %s device %s.\n",
220 dcr->VolumeName, dev->print_type(), dev->print_name());
221 if (dev->dev_errno == EACCES || dev->dev_errno == EROFS) {
222 mark_volume_read_only();
224 mark_volume_in_error();
228 Dmsg0(100, "set_unload\n");
229 if (dev->dev_errno == EACCES || dev->dev_errno == EROFS) {
230 mark_volume_read_only();
232 dev->set_unload(); /* force ask sysop */
236 Dmsg0(100, "goto mount_next_vol\n");
241 * Now check the volume label to make sure we have the right tape mounted
244 switch (check_volume_label(ask, autochanger)) {
246 Dmsg0(50, "set_unload\n");
247 dev->set_unload(); /* want a different Volume */
248 Dmsg0(100, "goto mount_next_vol\n");
258 * Check that volcatinfo is good
260 if (!dev->haveVolCatInfo()) {
261 Dmsg0(100, "Do not have volcatinfo\n");
262 if (!find_a_volume()) {
265 dev->set_volcatinfo_from_dcr(this);
269 * See if we have a fresh tape or a tape with data.
271 * Note, if the LabelType is PRE_LABEL, it was labeled
272 * but never written. If so, rewrite the label but set as
273 * VOL_LABEL. We rewind and return the label (reconstructed)
274 * in the block so that in the case of a new tape, data can
275 * be appended just after the block label. If we are writing
276 * a second volume, the calling routine will write the label
277 * before writing the overflow block.
279 * If the tape is marked as Recycle, we rewrite the label.
281 recycle = strcmp(dev->VolCatInfo.VolCatStatus, "Recycle") == 0;
282 if (dev->VolHdr.LabelType == PRE_LABEL || recycle) {
283 dcr->WroteVol = false;
284 if (!dev->rewrite_volume_label(dcr, recycle)) {
285 mark_volume_in_error();
290 * OK, at this point, we have a valid Bacula label, but
291 * we need to position to the end of the volume, since we are
292 * just now putting it into append mode.
294 Dmsg1(100, "Device previously written, moving to end of data. Expect %lld bytes\n",
295 dev->VolCatInfo.VolCatBytes);
296 Jmsg(jcr, M_INFO, 0, _("Volume \"%s\" previously written, moving to end of data.\n"),
299 if (!dev->eod(dcr)) {
300 Dmsg3(050, "Unable to position to end of data on %s device %s: ERR=%s\n",
301 dev->print_type(), dev->print_name(), dev->bstrerror());
302 Jmsg(jcr, M_ERROR, 0, _("Unable to position to end of data on %s device %s: ERR=%s\n"),
303 dev->print_type(), dev->print_name(), dev->bstrerror());
304 mark_volume_in_error();
308 if (!dev->is_eod_valid(dcr)) {
309 Dmsg0(100, "goto mount_next_vol\n");
313 dev->VolCatInfo.VolCatMounts++; /* Update mounts */
314 Dmsg1(150, "update volinfo mounts=%d\n", dev->VolCatInfo.VolCatMounts);
315 if (!dir_update_volume_info(dcr, false, false)) {
319 /* Return an empty block */
320 empty_block(block); /* we used it for reading so set for write */
323 Dmsg1(150, "set APPEND, normal return from mount_next_write_volume. dev=%s\n",
338 * This routine is meant to be called once the first pass
339 * to ensure that we have a candidate volume to mount.
340 * Otherwise, we ask the sysop to created one.
341 * Note, mount_mutex is already locked on entry and thus
342 * must remain locked on exit from this function.
344 bool DCR::find_a_volume()
349 if (!is_suitable_volume_mounted()) {
350 bool have_vol = false;
351 /* Do we have a candidate volume? */
353 bstrncpy(VolumeName, dev->vol->vol_name, sizeof(VolumeName));
354 have_vol = dir_get_volume_info(this, VolumeName, GET_VOL_INFO_FOR_WRITE);
357 * Get Director's idea of what tape we should have mounted.
361 Dmsg0(200, "Before dir_find_next_appendable_volume.\n");
362 while (!dir_find_next_appendable_volume(dcr)) {
363 Dmsg0(200, "not dir_find_next\n");
364 if (job_canceled(jcr)) {
368 * Unlock the mount mutex while waiting or
369 * the Director for a new volume
372 if (dev->must_wait()) {
374 Dmsg0(40, "No appendable volume. Calling wait_for_device\n");
375 wait_for_device(dcr, retries);
378 ok = dir_ask_sysop_to_create_appendable_volume(dcr);
381 if (!ok || job_canceled(jcr)) {
384 Dmsg0(150, "Again dir_find_next_append...\n");
389 if (dcr->haveVolCatInfo()) {
392 return dir_get_volume_info(dcr, VolumeName, GET_VOL_INFO_FOR_WRITE);
395 int DCR::check_volume_label(bool &ask, bool &autochanger)
397 int vol_label_status;
403 * If we are writing to a stream device, ASSUME the volume label
406 if (dev->has_cap(CAP_STREAM)) {
407 vol_label_status = VOL_OK;
408 create_volume_header(dev, VolumeName, "Default", false);
409 dev->VolHdr.LabelType = PRE_LABEL;
411 vol_label_status = dev->read_dev_volume_label(this);
413 if (job_canceled(jcr)) {
417 Dmsg2(150, "Want dirVol=%s dirStat=%s\n", VolumeName,
418 VolCatInfo.VolCatStatus);
421 * At this point, dev->VolCatInfo has what is in the drive, if anything,
422 * and dcr->VolCatInfo has what the Director wants.
424 switch (vol_label_status) {
426 Dmsg1(150, "Vol OK name=%s\n", dev->VolHdr.VolumeName);
427 dev->VolCatInfo = VolCatInfo; /* structure assignment */
428 break; /* got a Volume */
430 VOLUME_CAT_INFO dcrVolCatInfo, devVolCatInfo;
431 char saveVolumeName[MAX_NAME_LENGTH];
433 Dmsg2(40, "Vol NAME Error Have=%s, want=%s\n", dev->VolHdr.VolumeName, VolumeName);
434 if (dev->is_volume_to_unload()) {
436 goto check_next_volume;
440 /* If not removable, Volume is broken */
441 if (!dev->is_removable()) {
442 Jmsg3(jcr, M_WARNING, 0, _("Volume \"%s\" not loaded on %s device %s.\n"),
443 VolumeName, dev->print_type(), dev->print_name());
444 Dmsg3(40, "Volume \"%s\" not loaded on %s device %s.\n",
445 VolumeName, dev->print_type(), dev->print_name());
446 mark_volume_in_error();
447 goto check_next_volume;
452 * OK, we got a different volume mounted. First save the
453 * requested Volume info (dcr) structure, then query if
454 * this volume is really OK. If not, put back the desired
455 * volume name, mark it not in changer and continue.
457 dcrVolCatInfo = VolCatInfo; /* structure assignment */
458 devVolCatInfo = dev->VolCatInfo; /* structure assignment */
459 /* Check if this is a valid Volume in the pool */
460 bstrncpy(saveVolumeName, VolumeName, sizeof(saveVolumeName));
461 bstrncpy(VolumeName, dev->VolHdr.VolumeName, sizeof(VolumeName));
462 if (!dir_get_volume_info(this, VolumeName, GET_VOL_INFO_FOR_WRITE)) {
463 POOL_MEM vol_info_msg;
464 pm_strcpy(vol_info_msg, jcr->dir_bsock->msg); /* save error message */
465 /* Restore desired volume name, note device info out of sync */
466 /* This gets the info regardless of the Pool */
467 bstrncpy(VolumeName, dev->VolHdr.VolumeName, sizeof(VolumeName));
468 if (autochanger && !dir_get_volume_info(this, VolumeName, GET_VOL_INFO_FOR_READ)) {
470 * If we get here, we know we cannot write on the Volume,
471 * and we know that we cannot read it either, so it
472 * is not in the autochanger.
474 mark_volume_not_inchanger();
476 dev->VolCatInfo = devVolCatInfo; /* structure assignment */
477 dev->set_unload(); /* unload this volume */
478 Jmsg(jcr, M_WARNING, 0, _("Director wanted Volume \"%s\".\n"
479 " Current Volume \"%s\" not acceptable because:\n"
481 dcrVolCatInfo.VolCatName, dev->VolHdr.VolumeName,
482 vol_info_msg.c_str());
484 /* Restore saved DCR before continuing */
485 bstrncpy(VolumeName, saveVolumeName, sizeof(VolumeName));
486 VolCatInfo = dcrVolCatInfo; /* structure assignment */
487 goto check_next_volume;
490 * This was not the volume we expected, but it is OK with
491 * the Director, so use it.
493 Dmsg1(150, "Got new Volume name=%s\n", VolumeName);
494 dev->VolCatInfo = VolCatInfo; /* structure assignment */
495 Dmsg1(100, "Call reserve_volume=%s\n", dev->VolHdr.VolumeName);
496 if (reserve_volume(this, dev->VolHdr.VolumeName) == NULL) {
497 if (!jcr->errmsg[0]) {
498 Jmsg3(jcr, M_WARNING, 0, _("Could not reserve volume %s on %s device %s\n"),
499 dev->VolHdr.VolumeName, dev->print_type(), dev->print_name());
501 Jmsg(jcr, M_WARNING, 0, "%s", jcr->errmsg);
504 dev->setVolCatInfo(false);
505 setVolCatInfo(false);
506 goto check_next_volume;
508 break; /* got a Volume */
510 * At this point, we assume we have a blank tape mounted.
513 /* Fall through wanted */
515 switch (try_autolabel(true)) {
517 goto check_next_volume;
519 goto check_read_volume;
525 /* NOTE! Fall-through wanted. */
528 Dmsg0(200, "VOL_NO_MEDIA or default.\n");
529 /* Send error message */
532 Dmsg1(200, "Msg suppressed by poll: %s\n", jcr->errmsg);
535 /* Needed, so the medium can be changed */
536 if (dev->requires_mount()) {
540 goto check_next_volume;
546 dev->setVolCatInfo(false);
547 setVolCatInfo(false);
549 return check_next_vol;
557 return check_read_vol;
562 bool DCR::is_suitable_volume_mounted()
566 /* Volume mounted? */
567 if (dev->VolHdr.VolumeName[0] == 0 || dev->swap_dev || dev->must_unload()) {
568 return false; /* no */
570 bstrncpy(VolumeName, dev->VolHdr.VolumeName, sizeof(VolumeName));
571 ok = dir_get_volume_info(this, VolumeName, GET_VOL_INFO_FOR_WRITE);
573 Dmsg1(40, "dir_get_volume_info failed: %s", jcr->errmsg);
579 bool DCR::do_unload()
581 if (dev->must_unload()) {
582 Dmsg1(100, "must_unload release %s\n", dev->print_name());
588 bool DCR::do_load(bool is_writing)
590 if (dev->must_load()) {
591 Dmsg1(100, "Must load dev=%s\n", dev->print_name());
592 if (autoload_device(this, is_writing, NULL) > 0) {
601 void DCR::do_swapping(bool is_writing)
604 * See if we are asked to swap the Volume from another device
605 * if so, unload the other device here, and attach the
606 * volume to our drive.
609 if (dev->swap_dev->must_unload()) {
611 dev->swap_dev->set_slot(dev->vol->get_slot());
613 Dmsg2(100, "Swap unloading slot=%d %s\n", dev->swap_dev->get_slot(),
614 dev->swap_dev->print_name());
615 unload_dev(this, dev->swap_dev);
618 dev->vol->clear_swapping();
619 Dmsg1(100, "=== set in_use vol=%s\n", dev->vol->vol_name);
620 dev->vol->clear_in_use();
621 dev->VolHdr.VolumeName[0] = 0; /* don't yet have right Volume */
623 Dmsg1(100, "No vol on dev=%s\n", dev->print_name());
625 if (dev->swap_dev->vol) {
626 Dmsg2(100, "Vol=%s on dev=%s\n", dev->swap_dev->vol->vol_name,
627 dev->swap_dev->print_name());
629 Dmsg2(100, "Set swap_dev=NULL for dev=%s swap_dev=%s\n",
630 dev->print_name(), dev->swap_dev->print_name());
631 dev->swap_dev = NULL;
634 Dmsg1(100, "No swap_dev set. dev->vol=%p\n", dev->vol);
636 Dmsg1(100, "No swap_dev set. dev->vol=%p\n", dev->vol);
642 * If permitted, we label the device, make sure we can do
643 * it by checking that the VolCatBytes is zero => not labeled,
644 * once the Volume is labeled we don't want to label another
645 * blank tape with the same name. For disk, we go ahead and
646 * label it anyway, because the OS insures that there is only
647 * one Volume with that name.
648 * As noted above, at this point dcr->VolCatInfo has what
649 * the Director wants and dev->VolCatInfo has info on the
650 * previous tape (or nothing).
653 * try_next_vol label failed, look for another volume
654 * try_read_vol labeled volume, now re-read the label
655 * try_error hard error (catalog update)
656 * try_default I couldn't do anything
658 int DCR::try_autolabel(bool opened)
662 if (dev->poll && !dev->is_tape()) {
663 Dmsg0(100, "No autolabel because polling.\n");
664 return try_default; /* if polling, don't try to create new labels */
666 /* For a tape require it to be opened and read before labeling */
667 if (!opened && (dev->is_tape() || dev->is_null())) {
670 if (dev->has_cap(CAP_LABEL) && (VolCatInfo.VolCatBytes == 0 ||
671 (!dev->is_tape() && strcmp(VolCatInfo.VolCatStatus,
673 Dmsg1(40, "Create new volume label vol=%s\n", VolumeName);
674 /* Create a new Volume label and write it to the device */
675 if (!dev->write_volume_label(dcr, VolumeName,
676 pool_name, false, /* no relabel */ false /* defer label */)) {
677 Dmsg2(100, "write_vol_label failed. vol=%s, pool=%s\n",
678 VolumeName, pool_name);
680 mark_volume_in_error();
684 Dmsg0(150, "dir_update_vol_info. Set Append\n");
685 /* Copy Director's info into the device info */
686 dev->VolCatInfo = VolCatInfo; /* structure assignment */
687 if (!dir_update_volume_info(dcr, true, true)) { /* indicate tape labeled */
688 Dmsg3(100, "Update_vol_info failed no autolabel Volume \"%s\" on %s device %s.\n",
689 VolumeName, dev->print_type(), dev->print_name());
692 Jmsg(dcr->jcr, M_INFO, 0, _("Labeled new Volume \"%s\" on %s device %s.\n"),
693 VolumeName, dev->print_type(), dev->print_name());
694 Dmsg3(100, "Labeled new Volume \"%s\" on %s device %s.\n",
695 VolumeName, dev->print_type(), dev->print_name());
696 return try_read_vol; /* read label we just wrote */
698 Dmsg4(40, "=== Cannot autolabel: cap_label=%d VolCatBytes=%lld is_tape=%d VolCatStatus=%s\n",
699 dev->has_cap(CAP_LABEL), VolCatInfo.VolCatBytes, dev->is_tape(),
700 VolCatInfo.VolCatStatus);
702 if (!dev->has_cap(CAP_LABEL) && VolCatInfo.VolCatBytes == 0) {
703 Jmsg(jcr, M_WARNING, 0, _("%s device %s not configured to autolabel Volumes.\n"),
704 dev->print_type(), dev->print_name());
707 /* If not removable, Volume is broken */
708 if (!dev->is_removable()) {
709 Jmsg3(jcr, M_WARNING, 0, _("Volume \"%s\" not loaded on %s device %s.\n"),
710 VolumeName, dev->print_type(), dev->print_name());
711 Dmsg3(40, "Volume \"%s\" not loaded on %s device %s.\n",
712 VolumeName, dev->print_type(), dev->print_name());
714 mark_volume_in_error();
723 * Mark volume in error in catalog
725 void DCR::mark_volume_in_error()
727 Jmsg(jcr, M_INFO, 0, _("Marking Volume \"%s\" in Error in Catalog.\n"),
729 dev->VolCatInfo = VolCatInfo; /* structure assignment */
730 dev->setVolCatStatus("Error");
731 Dmsg0(150, "dir_update_vol_info. Set Error.\n");
732 dir_update_volume_info(this, false, false);
734 Dmsg0(50, "set_unload\n");
735 dev->set_unload(); /* must get a new volume */
739 * Mark volume read_only in catalog
741 void DCR::mark_volume_read_only()
743 Jmsg(jcr, M_INFO, 0, _("Marking Volume \"%s\" Read-Only in Catalog.\n"),
745 dev->VolCatInfo = VolCatInfo; /* structure assignment */
746 dev->setVolCatStatus("Read-Only");
747 Dmsg0(150, "dir_update_vol_info. Set Read-Only.\n");
748 dir_update_volume_info(this, false, false);
750 Dmsg0(50, "set_unload\n");
751 dev->set_unload(); /* must get a new volume */
756 * The Volume is not in the correct slot, so mark this
757 * Volume as not being in the Changer.
759 void DCR::mark_volume_not_inchanger()
761 Jmsg(jcr, M_ERROR, 0, _("Autochanger Volume \"%s\" not found in slot %d.\n"
762 " Setting InChanger to zero in catalog.\n"),
763 getVolCatName(), VolCatInfo.Slot);
764 dev->VolCatInfo = VolCatInfo; /* structure assignment */
765 VolCatInfo.InChanger = false;
766 dev->VolCatInfo.InChanger = false;
767 Dmsg0(400, "update vol info in mount\n");
768 dir_update_volume_info(this, true, false); /* set new status */
772 * Either because we are going to hang a new volume, or because
773 * of explicit user request, we release the current volume.
775 void DCR::release_volume()
777 unload_autochanger(this, -1);
780 Jmsg0(jcr, M_ERROR, 0, _("Hey!!!!! WroteVol non-zero !!!!!\n"));
781 Pmsg0(190, "Hey!!!!! WroteVol non-zero !!!!!\n");
784 if (dev->is_open() && (!dev->is_tape() || !dev->has_cap(CAP_ALWAYSOPEN))) {
785 generate_plugin_event(jcr, bsdEventDeviceClose, this);
789 /* If we have not closed the device, then at least rewind the tape */
790 if (dev->is_open()) {
791 dev->offline_or_rewind(this);
795 * Erase all memory of the current volume
798 dev->block_num = dev->file = 0;
799 dev->EndBlock = dev->EndFile = 0;
800 memset(&dev->VolCatInfo, 0, sizeof(dev->VolCatInfo));
802 /* Force re-read of label */
803 dev->clear_labeled();
806 dev->label_type = B_BACULA_LABEL;
809 Dmsg0(190, "release_volume\n");
815 * Check to see if the tape position as defined by the OS is
816 * the same as our concept. If it is not,
817 * it means the user has probably manually rewound the tape.
818 * Note, we check only if num_writers == 0, but this code will
819 * also work fine for any number of writers. If num_writers > 0,
820 * we probably should cancel all jobs using this device, or
821 * perhaps even abort the SD, or at a minimum, mark the tape
822 * in error. Another strategy with num_writers == 0, would be
823 * to rewind the tape and do a new eod() request.
825 bool DCR::is_tape_position_ok()
827 if (dev->is_tape() && dev->num_writers == 0) {
828 int32_t file = dev->get_os_tape_file();
829 if (file >= 0 && file != (int32_t)dev->get_file()) {
830 Jmsg(jcr, M_ERROR, 0, _("Invalid tape position on volume \"%s\""
831 " on device %s. Expected %d, got %d\n"),
832 dev->VolHdr.VolumeName, dev->print_name(), dev->get_file(), file);
834 * If the current file is greater than zero, it means we probably
835 * have some bad count of EOF marks, so mark tape in error. Otherwise
836 * the operator might have moved the tape, so we just release it
840 mark_volume_in_error();
851 * If we are reading, we come here at the end of the tape
852 * and see if there are more volumes to be mounted.
854 bool mount_next_read_volume(DCR *dcr)
856 DEVICE *dev = dcr->dev;
858 Dmsg2(90, "NumReadVolumes=%d CurReadVolume=%d\n", jcr->NumReadVolumes, jcr->CurReadVolume);
860 volume_unused(dcr); /* release current volume */
862 * End Of Tape -- mount next Volume (if another specified)
864 if (jcr->NumReadVolumes > 1 && jcr->CurReadVolume < jcr->NumReadVolumes) {
868 dcr->set_reserved_for_read();
870 if (!acquire_device_for_read(dcr)) {
871 Jmsg3(jcr, M_FATAL, 0, _("Cannot open %s Dev=%s, Vol=%s for reading.\n"),
872 dev->print_type(), dev->print_name(), dcr->VolumeName);
873 jcr->setJobStatus(JS_FatalError); /* Jmsg is not working for *SystemJob* */
876 return true; /* next volume mounted */
878 Dmsg0(90, "End of Device reached.\n");