From d71718486238588886b9e683556c938d2a069e49 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sun, 4 Nov 2007 19:57:42 +0000 Subject: [PATCH] kes Cleanup of code in SD that sets the LastWritten date. This doesn't really change anything, but is the beginning of doing it *right*. To do it completely right the LastWritten date must be passed to the SD, but it is not yet done. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@5852 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/dird/catreq.c | 17 +++++++++++------ bacula/src/stored/acquire.c | 6 +++--- bacula/src/stored/askdir.c | 13 ++++++++----- bacula/src/stored/bcopy.c | 2 +- bacula/src/stored/bextract.c | 2 +- bacula/src/stored/block.c | 6 +++--- bacula/src/stored/bls.c | 2 +- bacula/src/stored/bscan.c | 2 +- bacula/src/stored/btape.c | 2 +- bacula/src/stored/dev.h | 1 + bacula/src/stored/device.c | 2 +- bacula/src/stored/dvd.c | 22 +++++++++++----------- bacula/src/stored/label.c | 2 +- bacula/src/stored/mount.c | 8 ++++---- bacula/src/stored/protos.h | 2 +- bacula/src/version.h | 4 ++-- bacula/technotes-2.3 | 4 ++++ 17 files changed, 55 insertions(+), 42 deletions(-) diff --git a/bacula/src/dird/catreq.c b/bacula/src/dird/catreq.c index cc1903615f..709707069d 100644 --- a/bacula/src/dird/catreq.c +++ b/bacula/src/dird/catreq.c @@ -54,10 +54,10 @@ static char Find_media[] = "CatReq Job=%127s FindMedia=%d pool_name=%127s media_ static char Get_Vol_Info[] = "CatReq Job=%127s GetVolInfo VolName=%127s write=%d\n"; static char Update_media[] = "CatReq Job=%127s UpdateMedia VolName=%s" - " VolJobs=%u VolFiles=%u VolBlocks=%u VolBytes=%" lld " VolMounts=%u" - " VolErrors=%u VolWrites=%u MaxVolBytes=%" lld " EndTime=%d VolStatus=%10s" - " Slot=%d relabel=%d InChanger=%d VolReadTime=%" lld " VolWriteTime=%" lld - " VolFirstWritten=%" lld " VolParts=%u\n"; + " VolJobs=%u VolFiles=%u VolBlocks=%u VolBytes=%lld VolMounts=%u" + " VolErrors=%u VolWrites=%u MaxVolBytes=%lld EndTime=%lld VolStatus=%10s" + " Slot=%d relabel=%d InChanger=%d VolReadTime=%lld VolWriteTime=%lld" + " VolFirstWritten=%lld VolParts=%u\n"; static char Create_job_media[] = "CatReq Job=%127s CreateJobMedia " " FirstIndex=%u LastIndex=%u StartFile=%u EndFile=%u " @@ -113,6 +113,7 @@ void catalog_request(JCR *jcr, BSOCK *bs) uint32_t Stripe; uint64_t MediaId; utime_t VolFirstWritten; + utime_t VolLastWritten; memset(&mr, 0, sizeof(mr)); memset(&sdmr, 0, sizeof(sdmr)); @@ -217,7 +218,7 @@ void catalog_request(JCR *jcr, BSOCK *bs) } else if (sscanf(bs->msg, Update_media, &Job, &sdmr.VolumeName, &sdmr.VolJobs, &sdmr.VolFiles, &sdmr.VolBlocks, &sdmr.VolBytes, &sdmr.VolMounts, &sdmr.VolErrors, &sdmr.VolWrites, &sdmr.MaxVolBytes, - &sdmr.LastWritten, &sdmr.VolStatus, &sdmr.Slot, &label, &sdmr.InChanger, + &VolLastWritten, &sdmr.VolStatus, &sdmr.Slot, &label, &sdmr.InChanger, &sdmr.VolReadTime, &sdmr.VolWriteTime, &VolFirstWritten, &sdmr.VolParts) == 19) { @@ -266,6 +267,11 @@ void catalog_request(JCR *jcr, BSOCK *bs) } } Dmsg2(400, "Update media: BefVolJobs=%u After=%u\n", mr.VolJobs, sdmr.VolJobs); + /* Check if the volume has been written by the job, + * and update the LastWritten field if needed */ + if (mr.VolBlocks != sdmr.VolBlocks && VolLastWritten != 0) { + mr.LastWritten = VolLastWritten; + } /* Copy updated values to original media record */ mr.VolJobs = sdmr.VolJobs; mr.VolFiles = sdmr.VolFiles; @@ -274,7 +280,6 @@ void catalog_request(JCR *jcr, BSOCK *bs) mr.VolMounts = sdmr.VolMounts; mr.VolErrors = sdmr.VolErrors; mr.VolWrites = sdmr.VolWrites; - mr.LastWritten = sdmr.LastWritten; mr.Slot = sdmr.Slot; mr.InChanger = sdmr.InChanger; mr.VolReadTime = sdmr.VolReadTime; diff --git a/bacula/src/stored/acquire.c b/bacula/src/stored/acquire.c index 3de501061b..2fba360056 100644 --- a/bacula/src/stored/acquire.c +++ b/bacula/src/stored/acquire.c @@ -436,7 +436,7 @@ DCR *acquire_device_for_append(DCR *dcr) jcr->NumWriteVolumes = 1; } dev->VolCatInfo.VolCatJobs++; /* increment number of jobs on vol */ - dir_update_volume_info(dcr, false); /* send Volume info to Director */ + dir_update_volume_info(dcr, false, false); /* send Volume info to Director */ dev->dlock(); if (dcr->reserved_device) { dev->reserved_device--; @@ -505,7 +505,7 @@ bool release_device(DCR *dcr) if (dev->can_read()) { dev->clear_read(); /* clear read bit */ Dmsg0(100, "dir_update_vol_info. Release0\n"); - dir_update_volume_info(dcr, false); /* send Volume info to Director */ + dir_update_volume_info(dcr, false, false); /* send Volume info to Director */ } else if (dev->num_writers > 0) { /* @@ -531,7 +531,7 @@ bool release_device(DCR *dcr) dev->VolCatInfo.VolCatFiles = dev->file; /* set number of files */ /* Note! do volume update before close, which zaps VolCatInfo */ Dmsg0(100, "dir_update_vol_info. Release0\n"); - dir_update_volume_info(dcr, false); /* send Volume info to Director */ + dir_update_volume_info(dcr, false, false); /* send Volume info to Director */ } } diff --git a/bacula/src/stored/askdir.c b/bacula/src/stored/askdir.c index 40bde43760..a4dc84ed7f 100644 --- a/bacula/src/stored/askdir.c +++ b/bacula/src/stored/askdir.c @@ -42,7 +42,7 @@ static char Find_media[] = "CatReq Job=%s FindMedia=%d pool_name=%s media_type static char Get_Vol_Info[] = "CatReq Job=%s GetVolInfo VolName=%s write=%d\n"; static char Update_media[] = "CatReq Job=%s UpdateMedia VolName=%s" " VolJobs=%u VolFiles=%u VolBlocks=%u VolBytes=%s VolMounts=%u" - " VolErrors=%u VolWrites=%u MaxVolBytes=%s EndTime=%d VolStatus=%s" + " VolErrors=%u VolWrites=%u MaxVolBytes=%s EndTime=%s VolStatus=%s" " Slot=%d relabel=%d InChanger=%d VolReadTime=%s VolWriteTime=%s" " VolFirstWritten=%s VolParts=%u\n"; static char Create_job_media[] = "CatReq Job=%s CreateJobMedia" @@ -314,14 +314,13 @@ bail_out: * back to the director. The information comes from the * dev record. */ -bool dir_update_volume_info(DCR *dcr, bool label) +bool dir_update_volume_info(DCR *dcr, bool label, bool update_LastWritten) { JCR *jcr = dcr->jcr; BSOCK *dir = jcr->dir_bsock; DEVICE *dev = dcr->dev; - time_t LastWritten = time(NULL); VOLUME_CAT_INFO *vol = &dev->VolCatInfo; - char ed1[50], ed2[50], ed3[50], ed4[50], ed5[50]; + char ed1[50], ed2[50], ed3[50], ed4[50], ed5[50], ed6[50]; int InChanger; bool ok = false; POOL_MEM VolumeName; @@ -344,6 +343,9 @@ bool dir_update_volume_info(DCR *dcr, bool label) if (label) { bstrncpy(vol->VolCatStatus, "Append", sizeof(vol->VolCatStatus)); } +// if (update_LastWritten) { + vol->VolLastWritten = time(NULL); +// } pm_strcpy(VolumeName, vol->VolCatName); bash_spaces(VolumeName); InChanger = vol->InChanger; @@ -352,7 +354,8 @@ bool dir_update_volume_info(DCR *dcr, bool label) vol->VolCatBlocks, edit_uint64(vol->VolCatBytes, ed1), vol->VolCatMounts, vol->VolCatErrors, vol->VolCatWrites, edit_uint64(vol->VolCatMaxBytes, ed2), - LastWritten, vol->VolCatStatus, vol->Slot, label, + edit_uint64(vol->VolLastWritten, ed6), + vol->VolCatStatus, vol->Slot, label, InChanger, /* bool in structure */ edit_int64(vol->VolReadTime, ed3), edit_int64(vol->VolWriteTime, ed4), diff --git a/bacula/src/stored/bcopy.c b/bacula/src/stored/bcopy.c index 73416afbe4..0faaf89d73 100644 --- a/bacula/src/stored/bcopy.c +++ b/bacula/src/stored/bcopy.c @@ -298,7 +298,7 @@ static bool record_cb(DCR *in_dcr, DEV_RECORD *rec) /* Dummies to replace askdir.c */ bool dir_find_next_appendable_volume(DCR *dcr) { return 1;} -bool dir_update_volume_info(DCR *dcr, bool relabel) { return 1; } +bool dir_update_volume_info(DCR *dcr, bool relabel, bool update_LastWritten) { return 1; } bool dir_create_jobmedia_record(DCR *dcr) { return 1; } bool dir_ask_sysop_to_create_appendable_volume(DCR *dcr) { return 1; } bool dir_update_file_attributes(DCR *dcr, DEV_RECORD *rec) { return 1;} diff --git a/bacula/src/stored/bextract.c b/bacula/src/stored/bextract.c index cfa5b5b8bf..70508df1f4 100644 --- a/bacula/src/stored/bextract.c +++ b/bacula/src/stored/bextract.c @@ -482,7 +482,7 @@ static bool record_cb(DCR *dcr, DEV_RECORD *rec) /* Dummies to replace askdir.c */ bool dir_find_next_appendable_volume(DCR *dcr) { return 1;} -bool dir_update_volume_info(DCR *dcr, bool relabel) { return 1; } +bool dir_update_volume_info(DCR *dcr, bool relabel, bool update_LastWritten) { return 1; } bool dir_create_jobmedia_record(DCR *dcr) { return 1; } bool dir_ask_sysop_to_create_appendable_volume(DCR *dcr) { return 1; } bool dir_update_file_attributes(DCR *dcr, DEV_RECORD *rec) { return 1;} diff --git a/bacula/src/stored/block.c b/bacula/src/stored/block.c index e5b95b624d..d257f05b63 100644 --- a/bacula/src/stored/block.c +++ b/bacula/src/stored/block.c @@ -746,7 +746,7 @@ static bool terminate_writing_volume(DCR *dcr) dev->VolCatInfo.VolCatParts = dev->num_dvd_parts; } - if (!dir_update_volume_info(dcr, false)) { + if (!dir_update_volume_info(dcr, false, true)) { ok = false; } Dmsg1(100, "dir_update_volume_info terminate writing -- %s\n", ok?"OK":"ERROR"); @@ -798,7 +798,7 @@ static bool do_new_file_bookkeeping(DCR *dcr) return false; } dev->VolCatInfo.VolCatFiles = dev->file; - if (!dir_update_volume_info(dcr, false)) { + if (!dir_update_volume_info(dcr, false, false)) { Dmsg0(190, "Error from update_vol_info.\n"); terminate_writing_volume(dcr); dev->dev_errno = EIO; @@ -856,7 +856,7 @@ static bool do_dvd_size_checks(DCR *dcr) dev->VolCatInfo.VolCatParts = dev->num_dvd_parts; - if (!dir_update_volume_info(dcr, false)) { + if (!dir_update_volume_info(dcr, false, false)) { Dmsg0(190, "Error from update_vol_info.\n"); dev->dev_errno = EIO; return false; diff --git a/bacula/src/stored/bls.c b/bacula/src/stored/bls.c index 218db4e64e..7f74b99bb0 100644 --- a/bacula/src/stored/bls.c +++ b/bacula/src/stored/bls.c @@ -446,7 +446,7 @@ static void get_session_record(DEVICE *dev, DEV_RECORD *rec, SESSION_LABEL *sess /* Dummies to replace askdir.c */ bool dir_find_next_appendable_volume(DCR *dcr) { return 1;} -bool dir_update_volume_info(DCR *dcr, bool relabel) { return 1; } +bool dir_update_volume_info(DCR *dcr, bool relabel, bool update_LastWritten) { return 1; } bool dir_create_jobmedia_record(DCR *dcr) { return 1; } bool dir_ask_sysop_to_create_appendable_volume(DCR *dcr) { return 1; } bool dir_update_file_attributes(DCR *dcr, DEV_RECORD *rec) { return 1;} diff --git a/bacula/src/stored/bscan.c b/bacula/src/stored/bscan.c index fd0924c340..f5ef83bf97 100644 --- a/bacula/src/stored/bscan.c +++ b/bacula/src/stored/bscan.c @@ -1277,7 +1277,7 @@ static JCR *create_jcr(JOB_DBR *jr, DEV_RECORD *rec, uint32_t JobId) /* Dummies to replace askdir.c */ bool dir_find_next_appendable_volume(DCR *dcr) { return 1;} -bool dir_update_volume_info(DCR *dcr, bool relabel) { return 1; } +bool dir_update_volume_info(DCR *dcr, bool relabel, bool update_LastWritten) { return 1; } bool dir_create_jobmedia_record(DCR *dcr) { return 1; } bool dir_ask_sysop_to_create_appendable_volume(DCR *dcr) { return 1; } bool dir_update_file_attributes(DCR *dcr, DEV_RECORD *rec) { return 1;} diff --git a/bacula/src/stored/btape.c b/bacula/src/stored/btape.c index f63f3403a7..81237ece1b 100644 --- a/bacula/src/stored/btape.c +++ b/bacula/src/stored/btape.c @@ -2649,7 +2649,7 @@ get_cmd(const char *prompt) bool dir_update_file_attributes(DCR *dcr, DEV_RECORD *rec) { return 1;} bool dir_send_job_status(JCR *jcr) {return 1;} -bool dir_update_volume_info(DCR *dcr, bool relabel) +bool dir_update_volume_info(DCR *dcr, bool relabel, bool update_LastWritten) { return 1; } diff --git a/bacula/src/stored/dev.h b/bacula/src/stored/dev.h index 45cd39f6ac..d2a2243ebb 100644 --- a/bacula/src/stored/dev.h +++ b/bacula/src/stored/dev.h @@ -158,6 +158,7 @@ struct VOLUME_CAT_INFO { btime_t VolWriteTime; /* time spent writing this Volume */ int64_t VolMediaId; /* MediaId */ utime_t VolFirstWritten; /* Time of first write */ + utime_t VolLastWritten; /* Time of last write */ bool InChanger; /* Set if vol in current magazine */ char VolCatStatus[20]; /* Volume status */ char VolCatName[MAX_NAME_LENGTH]; /* Desired volume to mount */ diff --git a/bacula/src/stored/device.c b/bacula/src/stored/device.c index 473b3e7950..3aeaf86927 100644 --- a/bacula/src/stored/device.c +++ b/bacula/src/stored/device.c @@ -132,7 +132,7 @@ bool fixup_device_block_write_error(DCR *dcr) dev->dlock(); /* lock again */ dev->VolCatInfo.VolCatJobs++; /* increment number of jobs on vol */ - dir_update_volume_info(dcr, false); /* send Volume info to Director */ + dir_update_volume_info(dcr, false, false); /* send Volume info to Director */ Jmsg(jcr, M_INFO, 0, _("New volume \"%s\" mounted on device %s at %s.\n"), dcr->VolumeName, dev->print_name(), bstrftime(dt, sizeof(dt), time(NULL))); diff --git a/bacula/src/stored/dvd.c b/bacula/src/stored/dvd.c index 367e6a8a01..142027f446 100644 --- a/bacula/src/stored/dvd.c +++ b/bacula/src/stored/dvd.c @@ -1,16 +1,7 @@ -/* - * - * dvd.c -- Routines specific to DVD devices (and - * possibly other removable hard media). - * - * Nicolas Boichat, MMV - * - * Version $Id$ - */ /* Bacula® - The Network Backup Solution - Copyright (C) 2005-2006 Free Software Foundation Europe e.V. + Copyright (C) 2005-2007 Free Software Foundation Europe e.V. The main author of Bacula is Kern Sibbald, with contributions from many others, a complete list can be found in the file AUTHORS. @@ -34,6 +25,15 @@ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, Switzerland, email:ftf@fsfeurope.org. */ +/* + * + * dvd.c -- Routines specific to DVD devices (and + * possibly other removable hard media). + * + * Nicolas Boichat, MMV + * + * Version $Id$ + */ #include "bacula.h" #include "stored.h" @@ -686,7 +686,7 @@ bool truncate_dvd(DCR *dcr) dcr->VolCatInfo.VolCatBytes = 0; /* Update catalog */ - if (!dir_update_volume_info(dcr, false)) { + if (!dir_update_volume_info(dcr, false, true)) { return false; } diff --git a/bacula/src/stored/label.c b/bacula/src/stored/label.c index 77afb82da1..e3db2c7c7e 100644 --- a/bacula/src/stored/label.c +++ b/bacula/src/stored/label.c @@ -505,7 +505,7 @@ bool rewrite_volume_label(DCR *dcr, bool recycle) } Dmsg0(150, "dir_update_vol_info. Set Append\n"); bstrncpy(dev->VolCatInfo.VolCatStatus, "Append", sizeof(dev->VolCatInfo.VolCatStatus)); - if (!dir_update_volume_info(dcr, true)) { /* indicate doing relabel */ + if (!dir_update_volume_info(dcr, true, true)) { /* indicate doing relabel */ return false; } if (recycle) { diff --git a/bacula/src/stored/mount.c b/bacula/src/stored/mount.c index 6733f9a6e8..9462815a20 100644 --- a/bacula/src/stored/mount.c +++ b/bacula/src/stored/mount.c @@ -436,7 +436,7 @@ read_volume: } dev->VolCatInfo.VolCatMounts++; /* Update mounts */ Dmsg1(150, "update volinfo mounts=%d\n", dev->VolCatInfo.VolCatMounts); - if (!dir_update_volume_info(dcr, false)) { + if (!dir_update_volume_info(dcr, false, false)) { return false; } @@ -523,7 +523,7 @@ static int try_autolabel(DCR *dcr, bool opened) Dmsg0(150, "dir_update_vol_info. Set Append\n"); /* Copy Director's info into the device info */ dev->VolCatInfo = dcr->VolCatInfo; /* structure assignment */ - if (!dir_update_volume_info(dcr, true)) { /* indicate tape labeled */ + if (!dir_update_volume_info(dcr, true, true)) { /* indicate tape labeled */ return try_error; } Jmsg(dcr->jcr, M_INFO, 0, _("Labeled new Volume \"%s\" on device %s.\n"), @@ -556,7 +556,7 @@ void mark_volume_in_error(DCR *dcr) dev->VolCatInfo = dcr->VolCatInfo; /* structure assignment */ bstrncpy(dev->VolCatInfo.VolCatStatus, "Error", sizeof(dev->VolCatInfo.VolCatStatus)); Dmsg0(150, "dir_update_vol_info. Set Error.\n"); - dir_update_volume_info(dcr, false); + dir_update_volume_info(dcr, false, false); } /* @@ -574,7 +574,7 @@ static void mark_volume_not_inchanger(DCR *dcr) dcr->VolCatInfo.InChanger = false; dev->VolCatInfo.InChanger = false; Dmsg0(400, "update vol info in mount\n"); - dir_update_volume_info(dcr, true); /* set new status */ + dir_update_volume_info(dcr, true, false); /* set new status */ } /* diff --git a/bacula/src/stored/protos.h b/bacula/src/stored/protos.h index 77225f932d..f9e98a243c 100644 --- a/bacula/src/stored/protos.h +++ b/bacula/src/stored/protos.h @@ -49,7 +49,7 @@ enum get_vol_info_rw { }; bool dir_get_volume_info(DCR *dcr, enum get_vol_info_rw); bool dir_find_next_appendable_volume(DCR *dcr); -bool dir_update_volume_info(DCR *dcr, bool label); +bool dir_update_volume_info(DCR *dcr, bool label, bool update_LastWritten); bool dir_ask_sysop_to_create_appendable_volume(DCR *dcr); bool dir_ask_sysop_to_mount_volume(DCR *dcr); bool dir_update_file_attributes(DCR *dcr, DEV_RECORD *rec); diff --git a/bacula/src/version.h b/bacula/src/version.h index e2db23da2f..4becebd444 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -4,8 +4,8 @@ #undef VERSION #define VERSION "2.3.6" -#define BDATE "19 October 2007" -#define LSMDATE "19Oct07" +#define BDATE "04 November 2007" +#define LSMDATE "04Nov07" #define PROG_COPYRIGHT "Copyright (C) %d-2007 Free Software Foundation Europe e.V.\n" #define BYEAR "2007" /* year for copyright messages in progs */ diff --git a/bacula/technotes-2.3 b/bacula/technotes-2.3 index 7ca5025ed7..3832586b4c 100644 --- a/bacula/technotes-2.3 +++ b/bacula/technotes-2.3 @@ -2,6 +2,10 @@ General: 04Nov07 +kes Cleanup of code in SD that sets the LastWritten date. This doesn't + really change anything, but is the beginning of doing it *right*. + To do it completely right the LastWritten date must be passed to + the SD, but it is not yet done. kes Minor tweaks to some bat restore SQL. kes This patch fixes bug #1003 where putting the message output from a Verify job into the catalog results in a recursive loop. The problem -- 2.39.5