From: Kern Sibbald Date: Mon, 10 Oct 2005 16:21:12 +0000 (+0000) Subject: - Mark DVD volume in error if part cannot be written. X-Git-Tag: Release-1.38.0~83 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b846949a3e71e49424e366ae84fe20163d52ba01;p=bacula%2Fbacula - Mark DVD volume in error if part cannot be written. - If a DVD is mounted, unmount it before asking operator to mount an different one. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2430 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/kes-1.37 b/bacula/kes-1.37 index dc06ad95f8..15d2447900 100644 --- a/bacula/kes-1.37 +++ b/bacula/kes-1.37 @@ -5,6 +5,9 @@ General: Changes to 1.37.41: 10Oct05 +- Mark DVD volume in error if part cannot be written. +- If a DVD is mounted, unmount it before asking operator + to mount an different one. - Add Arno's dvd-handler script to the scripts directory and integrate with configure. It replaces both existing scripts. - Make default schedule start at 23:10 diff --git a/bacula/src/stored/askdir.c b/bacula/src/stored/askdir.c index aa764c9a8e..c5545b62d1 100644 --- a/bacula/src/stored/askdir.c +++ b/bacula/src/stored/askdir.c @@ -114,15 +114,15 @@ bool dir_update_changer(JCR *jcr, AUTOCHANGER *changer) /* This is mostly to indicate that we are here */ ok = bnet_fsend(dir, Device_update, jcr->Job, - dev_name.c_str(), /* Changer name */ - 0, 0, 0, /* append, read, num_writers */ - 0, 0, 0, /* is_open, is_labeled, offline */ - 0, 0, /* reserved, max_writers */ - 0, /* Autoselect */ - changer->device->size(), /* Number of devices */ + dev_name.c_str(), /* Changer name */ + 0, 0, 0, /* append, read, num_writers */ + 0, 0, 0, /* is_open, is_labeled, offline */ + 0, 0, /* reserved, max_writers */ + 0, /* Autoselect */ + changer->device->size(), /* Number of devices */ "0", /* PoolId */ "*", /* ChangerName */ - MediaType.c_str(), /* MediaType */ + MediaType.c_str(), /* MediaType */ "*"); /* VolName */ Dmsg1(100, ">dird: %s\n", dir->msg); return ok; @@ -145,7 +145,7 @@ bool dir_send_job_status(JCR *jcr) * dir_find_next_appendable_volume() * * Returns: true on success and vol info in dcr->VolCatInfo - * false on failure + * false on failure */ static bool do_get_volume_info(DCR *dcr) { @@ -155,7 +155,7 @@ static bool do_get_volume_info(DCR *dcr) int n; int InChanger; - dcr->VolumeName[0] = 0; /* No volume */ + dcr->VolumeName[0] = 0; /* No volume */ if (bnet_recv(dir) <= 0) { Dmsg0(200, "getvolname error bnet_recv\n"); Mmsg(jcr->errmsg, _("Network error on bnet_recv in req_vol_info.\n")); @@ -164,27 +164,27 @@ static bool do_get_volume_info(DCR *dcr) memset(&vol, 0, sizeof(vol)); Dmsg1(100, "msg); n = sscanf(dir->msg, OK_media, vol.VolCatName, - &vol.VolCatJobs, &vol.VolCatFiles, - &vol.VolCatBlocks, &vol.VolCatBytes, - &vol.VolCatMounts, &vol.VolCatErrors, - &vol.VolCatWrites, &vol.VolCatMaxBytes, - &vol.VolCatCapacityBytes, vol.VolCatStatus, - &vol.Slot, &vol.VolCatMaxJobs, &vol.VolCatMaxFiles, - &InChanger, &vol.VolReadTime, &vol.VolWriteTime, - &vol.EndFile, &vol.EndBlock, &vol.VolCatParts, - &vol.LabelType); + &vol.VolCatJobs, &vol.VolCatFiles, + &vol.VolCatBlocks, &vol.VolCatBytes, + &vol.VolCatMounts, &vol.VolCatErrors, + &vol.VolCatWrites, &vol.VolCatMaxBytes, + &vol.VolCatCapacityBytes, vol.VolCatStatus, + &vol.Slot, &vol.VolCatMaxJobs, &vol.VolCatMaxFiles, + &InChanger, &vol.VolReadTime, &vol.VolWriteTime, + &vol.EndFile, &vol.EndBlock, &vol.VolCatParts, + &vol.LabelType); if (n != 21) { Dmsg2(100, "Bad response from Dir fields=%d: %s\n", n, dir->msg); Mmsg(jcr->errmsg, _("Error getting Volume info: %s\n"), dir->msg); return false; } - vol.InChanger = InChanger; /* bool in structure */ + vol.InChanger = InChanger; /* bool in structure */ unbash_spaces(vol.VolCatName); bstrncpy(dcr->VolumeName, vol.VolCatName, sizeof(dcr->VolumeName)); memcpy(&dcr->VolCatInfo, &vol, sizeof(dcr->VolCatInfo)); Dmsg2(300, "do_reqest_vol_info return true slot=%d Volume=%s\n", - vol.Slot, vol.VolCatName); + vol.Slot, vol.VolCatName); return true; } @@ -193,11 +193,11 @@ static bool do_get_volume_info(DCR *dcr) * Get Volume info for a specific volume from the Director's Database * * Returns: true on success (Director guarantees that Pool and MediaType - * are correct and VolStatus==Append or - * VolStatus==Recycle) - * false on failure + * are correct and VolStatus==Append or + * VolStatus==Recycle) + * false on failure * - * Volume information returned in dcr->VolCatInfo + * Volume information returned in dcr->VolCatInfo */ bool dir_get_volume_info(DCR *dcr, enum get_vol_info_rw writing) { @@ -216,9 +216,9 @@ bool dir_get_volume_info(DCR *dcr, enum get_vol_info_rw writing) /* * Get info on the next appendable volume in the Director's database * Returns: true on success - * false on failure + * false on failure * - * Volume information returned in dcr + * Volume information returned in dcr * */ bool dir_find_next_appendable_volume(DCR *dcr) @@ -230,8 +230,8 @@ bool dir_find_next_appendable_volume(DCR *dcr) Dmsg0(200, "dir_find_next_appendable_volume\n"); /* * Try the twenty oldest or most available volumes. Note, - * the most available could already be mounted on another - * drive, so we continue looking for a not in use Volume. + * the most available could already be mounted on another + * drive, so we continue looking for a not in use Volume. */ for (int vol_index=1; vol_index < 20; vol_index++) { bash_spaces(dcr->media_type); @@ -242,16 +242,16 @@ bool dir_find_next_appendable_volume(DCR *dcr) Dmsg1(100, ">dird: %s", dir->msg); bool OK = do_get_volume_info(dcr); if (OK) { - if (dcr->any_volume || !is_volume_in_use(dcr)) { - found = true; - break; - } else { + if (dcr->any_volume || !is_volume_in_use(dcr)) { + found = true; + break; + } else { Dmsg1(100, "Volume %s is in use.\n", dcr->VolumeName); - continue; - } + continue; + } } else { Dmsg0(200, "No volume info, return false\n"); - return false; + return false; } } if (found) { @@ -295,7 +295,7 @@ bool dir_update_volume_info(DCR *dcr, bool label) /* Just labeled or relabeled the tape */ if (label) { bstrncpy(vol->VolCatStatus, "Append", sizeof(vol->VolCatStatus)); - vol->VolCatBytes = 1; /* indicates tape labeled */ + vol->VolCatBytes = 1; /* indicates tape labeled */ } pm_strcpy(VolumeName, vol->VolCatName); bash_spaces(VolumeName); @@ -306,7 +306,7 @@ bool dir_update_volume_info(DCR *dcr, bool label) vol->VolCatMounts, vol->VolCatErrors, vol->VolCatWrites, edit_uint64(vol->VolCatMaxBytes, ed2), LastWritten, vol->VolCatStatus, vol->Slot, label, - InChanger, /* bool in structure */ + InChanger, /* bool in structure */ edit_uint64(vol->VolReadTime, ed3), edit_uint64(vol->VolWriteTime, ed4), vol->VolCatParts); @@ -316,7 +316,7 @@ bool dir_update_volume_info(DCR *dcr, bool label) if (!do_get_volume_info(dcr)) { Jmsg(jcr, M_FATAL, 0, "%s", jcr->errmsg); Pmsg2(000, _("Didn't get vol info vol=%s: ERR=%s"), - vol->VolCatName, jcr->errmsg); + vol->VolCatName, jcr->errmsg); return false; } Dmsg1(420, "get_volume_info(): %s", dir->msg); @@ -334,7 +334,7 @@ bool dir_create_jobmedia_record(DCR *dcr) BSOCK *dir = jcr->dir_bsock; if (!dcr->WroteVol) { - return true; /* nothing written to tape */ + return true; /* nothing written to tape */ } dcr->WroteVol = false; @@ -347,7 +347,7 @@ bool dir_create_jobmedia_record(DCR *dcr) if (bnet_recv(dir) <= 0) { Dmsg0(190, "create_jobmedia error bnet_recv\n"); Jmsg(jcr, M_FATAL, 0, _("Error creating JobMedia record: ERR=%s\n"), - bnet_strerror(dir)); + bnet_strerror(dir)); return false; } Dmsg1(100, "msg); @@ -375,7 +375,7 @@ bool dir_update_file_attributes(DCR *dcr, DEV_RECORD *rec) dir->msglen = sprintf(dir->msg, FileAttributes, jcr->Job); dir->msg = check_pool_memory_size(dir->msg, dir->msglen + - sizeof(DEV_RECORD) + rec->data_len); + sizeof(DEV_RECORD) + rec->data_len); ser_begin(dir->msg + dir->msglen, 0); ser_uint32(rec->VolSessionId); ser_uint32(rec->VolSessionTime); @@ -396,16 +396,16 @@ bool dir_update_file_attributes(DCR *dcr, DEV_RECORD *rec) * Leaves with device blocked. * * Returns: true on success (operator issues a mount command) - * false on failure - * Note, must create dev->errmsg on error return. + * false on failure + * Note, must create dev->errmsg on error return. * * On success, dcr->VolumeName and dcr->VolCatInfo contain - * information on suggested volume, but this may not be the - * same as what is actually mounted. + * information on suggested volume, but this may not be the + * same as what is actually mounted. * * When we return with success, the correct tape may or may not - * actually be mounted. The calling routine must read it and - * verify the label. + * actually be mounted. The calling routine must read it and + * verify the label. */ bool dir_ask_sysop_to_create_appendable_volume(DCR *dcr) { @@ -420,55 +420,55 @@ bool dir_ask_sysop_to_create_appendable_volume(DCR *dcr) ASSERT(dev->dev_blocked); for ( ;; ) { if (job_canceled(jcr)) { - Mmsg(dev->errmsg, + Mmsg(dev->errmsg, _("Job %s canceled while waiting for mount on Storage Device \"%s\".\n"), - jcr->Job, dev->print_name()); + jcr->Job, dev->print_name()); Jmsg(jcr, M_INFO, 0, "%s", dev->errmsg); - return false; + return false; } /* First pass, we *know* there are no appendable volumes, so no need to call */ if (!first) { - P(dev->mutex); - OK = dir_find_next_appendable_volume(dcr); /* get suggested volume */ - V(dev->mutex); + P(dev->mutex); + OK = dir_find_next_appendable_volume(dcr); /* get suggested volume */ + V(dev->mutex); } if (!first && OK) { - unmounted = is_device_unmounted(dev); - /* - * If we have a valid volume name and we are not - * removable media, return now, or if we have a - * Slot for an autochanger, otherwise wait - * for the operator to mount the media. - */ - if (!unmounted && ((dcr->VolumeName[0] && !dev_cap(dev, CAP_REM) && - dev_cap(dev, CAP_LABEL)) || - (dcr->VolumeName[0] && dcr->VolCatInfo.Slot))) { + unmounted = is_device_unmounted(dev); + /* + * If we have a valid volume name and we are not + * removable media, return now, or if we have a + * Slot for an autochanger, otherwise wait + * for the operator to mount the media. + */ + if (!unmounted && ((dcr->VolumeName[0] && !dev_cap(dev, CAP_REM) && + dev_cap(dev, CAP_LABEL)) || + (dcr->VolumeName[0] && dcr->VolCatInfo.Slot))) { Dmsg0(400, "Return 1 from mount without wait.\n"); - return true; - } - jstat = JS_WaitMount; - if (!dev->poll) { - Jmsg(jcr, M_MOUNT, 0, _( + return true; + } + jstat = JS_WaitMount; + if (!dev->poll) { + Jmsg(jcr, M_MOUNT, 0, _( "Please mount Volume \"%s\" on Storage Device %s for Job %s\n" "Use \"mount\" command to release Job.\n"), - dcr->VolumeName, dev->print_name(), jcr->Job); + dcr->VolumeName, dev->print_name(), jcr->Job); Dmsg3(400, "Mount %s on %s for Job %s\n", - dcr->VolumeName, dcr->dev_name, jcr->Job); - } + dcr->VolumeName, dcr->dev_name, jcr->Job); + } } else { - jstat = JS_WaitMedia; - if (!dev->poll) { - Jmsg(jcr, M_MOUNT, 0, _( + jstat = JS_WaitMedia; + if (!dev->poll) { + Jmsg(jcr, M_MOUNT, 0, _( "Job %s waiting. Cannot find any appendable volumes.\n" "Please use the \"label\" command to create a new Volume for:\n" " Storage: %s\n" " Media type: %s\n" " Pool: %s\n"), - jcr->Job, - dev->print_name(), - dcr->media_type, - dcr->pool_name); - } + jcr->Job, + dev->print_name(), + dcr->media_type, + dcr->pool_name); + } } first = false; @@ -478,50 +478,50 @@ bool dir_ask_sysop_to_create_appendable_volume(DCR *dcr) stat = wait_for_sysop(dcr); if (dev->poll) { Dmsg1(400, "Poll timeout in create append vol on device %s\n", dev->print_name()); - continue; + continue; } if (stat == ETIMEDOUT) { - if (!double_dev_wait_time(dev)) { + if (!double_dev_wait_time(dev)) { Mmsg(dev->errmsg, _("Max time exceeded waiting to mount Storage Device %s for Job %s\n"), - dev->print_name(), jcr->Job); + dev->print_name(), jcr->Job); Jmsg(jcr, M_FATAL, 0, "%s", dev->errmsg); Dmsg1(400, "Gave up waiting on device %s\n", dev->print_name()); - return false; /* exceeded maximum waits */ - } - continue; + return false; /* exceeded maximum waits */ + } + continue; } if (stat == EINVAL) { - berrno be; + berrno be; Mmsg2(dev->errmsg, _("pthread error in mount_next_volume stat=%d ERR=%s\n"), - stat, be.strerror(stat)); + stat, be.strerror(stat)); Jmsg(jcr, M_FATAL, 0, "%s", dev->errmsg); - return false; + return false; } if (stat != 0) { - berrno be; + berrno be; Jmsg(jcr, M_WARNING, 0, _("pthread error in mount_next_volume stat=%d ERR=%s\n"), stat, - be.strerror(stat)); + be.strerror(stat)); } Dmsg1(400, "Someone woke me for device %s\n", dev->print_name()); /* If no VolumeName, and cannot get one, try again */ P(dev->mutex); if (dcr->VolumeName[0] == 0 && !job_canceled(jcr) && - !dir_find_next_appendable_volume(dcr)) { - V(dev->mutex); - Jmsg(jcr, M_MOUNT, 0, _( + !dir_find_next_appendable_volume(dcr)) { + V(dev->mutex); + Jmsg(jcr, M_MOUNT, 0, _( "Someone woke me up, but I cannot find any appendable\n" "volumes for Job=%s.\n"), jcr->Job); - /* Restart wait counters after user interaction */ - init_device_wait_timers(dcr); - continue; + /* Restart wait counters after user interaction */ + init_device_wait_timers(dcr); + continue; } V(dev->mutex); unmounted = is_device_unmounted(dev); if (unmounted) { Dmsg0(400, "Device is unmounted. Must wait.\n"); - continue; /* continue to wait */ + continue; /* continue to wait */ } /* @@ -539,12 +539,12 @@ bool dir_ask_sysop_to_create_appendable_volume(DCR *dcr) * Request to mount specific Volume * * Entered with device blocked and dcr->VolumeName is desired - * volume. + * volume. * Leaves with device blocked. * * Returns: true on success (operator issues a mount command) - * false on failure - * Note, must create dev->errmsg on error return. + * false on failure + * Note, must create dev->errmsg on error return. * */ bool dir_ask_sysop_to_mount_volume(DCR *dcr) @@ -562,48 +562,51 @@ bool dir_ask_sysop_to_mount_volume(DCR *dcr) for ( ;; ) { if (job_canceled(jcr)) { Mmsg(dev->errmsg, _("Job %s canceled while waiting for mount on Storage Device %s.\n"), - jcr->Job, dev->print_name()); - return false; + jcr->Job, dev->print_name()); + return false; } + if (dev->is_dvd()) { + unmount_dev(dev, 0); + } if (!dev->poll) { Jmsg(jcr, M_MOUNT, 0, _("Please mount Volume \"%s\" on Storage Device %s for Job %s\n"), - dcr->VolumeName, dev->print_name(), jcr->Job); + dcr->VolumeName, dev->print_name(), jcr->Job); Dmsg3(400, "Mount \"%s\" on device \"%s\" for Job %s\n", - dcr->VolumeName, dev->print_name(), jcr->Job); + dcr->VolumeName, dev->print_name(), jcr->Job); } jcr->JobStatus = JS_WaitMount; dir_send_job_status(jcr); - stat = wait_for_sysop(dcr); ; /* wait on device */ + stat = wait_for_sysop(dcr); ; /* wait on device */ if (dev->poll) { Dmsg1(400, "Poll timeout in mount vol on device %s\n", dev->print_name()); Dmsg1(400, "Blocked=%s\n", dev->print_blocked()); - return true; + return true; } if (stat == ETIMEDOUT) { - if (!double_dev_wait_time(dev)) { + if (!double_dev_wait_time(dev)) { Mmsg(dev->errmsg, _("Max time exceeded waiting to mount Storage Device %s for Job %s\n"), - dev->print_name(), jcr->Job); + dev->print_name(), jcr->Job); Jmsg(jcr, M_FATAL, 0, "%s", dev->errmsg); Dmsg1(400, "Gave up waiting on device %s\n", dev->print_name()); - return false; /* exceeded maximum waits */ - } - continue; + return false; /* exceeded maximum waits */ + } + continue; } if (stat == EINVAL) { - berrno be; + berrno be; Mmsg2(dev->errmsg, _("pthread error in mount_volume stat=%d ERR=%s\n"), - stat, be.strerror(stat)); + stat, be.strerror(stat)); Jmsg(jcr, M_FATAL, 0, "%s", dev->errmsg); - return false; + return false; } if (stat != 0) { - berrno be; + berrno be; Jmsg(jcr, M_FATAL, 0, _("pthread error in mount_next_volume stat=%d: ERR=%s\n"), stat, - be.strerror(stat)); + be.strerror(stat)); } Dmsg1(400, "Someone woke me for device %s\n", dev->print_name()); break; diff --git a/bacula/src/stored/dvd.c b/bacula/src/stored/dvd.c index 4e160712dd..70c25c2940 100644 --- a/bacula/src/stored/dvd.c +++ b/bacula/src/stored/dvd.c @@ -313,29 +313,30 @@ static bool dvd_write_part(DCR *dcr) Dmsg2(29, "dvd_write_part: cmd=%s timeout=%d\n", ocmd.c_str(), timeout); -{ - POOL_MEM results(PM_MESSAGE); - sm_check(__FILE__, __LINE__, false); - status = run_program_full_output(ocmd.c_str(), timeout, results.c_str()); - sm_check(__FILE__, __LINE__, false); - if (status != 0) { - Mmsg1(dev->errmsg, _("Error while writing current part to the DVD: %s"), - results.c_str()); - Dmsg1(000, "%s", dev->errmsg); - dev->dev_errno = EIO; - return false; + { + POOL_MEM results(PM_MESSAGE); + sm_check(__FILE__, __LINE__, false); + status = run_program_full_output(ocmd.c_str(), timeout, results.c_str()); + sm_check(__FILE__, __LINE__, false); + if (status != 0) { + Mmsg1(dev->errmsg, _("Error while writing current part to the DVD: %s"), + results.c_str()); + Dmsg1(000, "%s", dev->errmsg); + dev->dev_errno = EIO; + mark_volume_in_error(dcr); + return false; + } + sm_check(__FILE__, __LINE__, false); } - sm_check(__FILE__, __LINE__, false); -} -{ - POOL_MEM archive_name(PM_FNAME); - /* Delete spool file */ - make_spooled_dvd_filename(dev, archive_name); - unlink(archive_name.c_str()); - Dmsg1(29, "unlink(%s)\n", archive_name.c_str()); - sm_check(__FILE__, __LINE__, false); -} + { + POOL_MEM archive_name(PM_FNAME); + /* Delete spool file */ + make_spooled_dvd_filename(dev, archive_name); + unlink(archive_name.c_str()); + Dmsg1(29, "unlink(%s)\n", archive_name.c_str()); + sm_check(__FILE__, __LINE__, false); + } /* growisofs umount the device, so remount it (it will update the free space) */ dev->clear_mounted(); @@ -630,7 +631,6 @@ bool dvd_close_job(DCR *dcr) You must open the next part, it will automatically write the part and update the part number. */ if (ok && (open_next_part(dcr) < 0)) { -// if (ok && !dvd_write_part(dcr)) { Jmsg2(jcr, M_FATAL, 0, _("Unable to write part %s: ERR=%s\n"), dev->print_name(), strerror_dev(dev)); dev->dev_errno = EIO; diff --git a/bacula/src/stored/mount.c b/bacula/src/stored/mount.c index 0ebd073a9b..a70e13e219 100644 --- a/bacula/src/stored/mount.c +++ b/bacula/src/stored/mount.c @@ -368,15 +368,19 @@ read_volume: return false; } - /* DVD : check if the last part was removed or truncated, or if a written - * part was overwritten. */ - /* We need to do it after dir_update_volume_info, so we have the EndBlock + /* + * DVD : check if the last part was removed or truncated, or if a written + * part was overwritten. + * We need to do it after dir_update_volume_info, so we have the EndBlock * info. (nb: I don't understand why VolCatFiles is set (used to check - * tape file number), but not EndBlock) */ - /* Maybe could it be changed "dev->is_file()" (would remove the fixme above) */ - - /* Disabled: I had problems with this code... (maybe is it related to the seek bug ?) */ - /*if (dev->is_dvd()) { + * tape file number), but not EndBlock) + * Maybe could it be changed "dev->is_file()" (would remove the fixme above) + * + * Disabled: I had problems with this code... + * (maybe is it related to the seek bug ?) + */ +#ifdef xxx + if (dev->is_dvd()) { Dmsg2(100, "DVD/File sanity check addr=%u vs endblock=%u\n", (unsigned int)dev->file_addr, (unsigned int)dev->VolCatInfo.EndBlock); if (dev->file_addr == dev->VolCatInfo.EndBlock+1) { Jmsg(jcr, M_INFO, 0, _("Ready to append to end of Volume \"%s\" at file address=%u.\n"), @@ -390,7 +394,8 @@ read_volume: mark_volume_in_error(dcr); goto mount_next_vol; } - }*/ + } +#endif /* Return an empty block */ empty_block(block); /* we used it for reading so set for write */