From 2d88cb93b1642244fa4bad0f7c780cf8e0b871b7 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Fri, 24 Oct 2008 13:04:16 +0000 Subject: [PATCH] kes Fix editing of retention time difference to use 64 bit int instead of 64 bit unsigned. This should permit very long retention periods. kes Implement code to prohibit a write job from appending to a Volume that will be used for a read operation. This is new code and could possibly cause some conflicts. git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@7892 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/dird/fd_cmds.c | 4 +-- bacula/src/dird/job.c | 2 +- bacula/src/dird/ua_prune.c | 14 +++++------ bacula/src/stored/askdir.c | 2 +- bacula/src/stored/dev.h | 3 +++ bacula/src/stored/vol_mgr.c | 49 +++++++++++++++++++++++++++++++++++++ bacula/src/version.h | 4 +-- bacula/technotes-2.5 | 39 ++++++----------------------- 8 files changed, 72 insertions(+), 45 deletions(-) diff --git a/bacula/src/dird/fd_cmds.c b/bacula/src/dird/fd_cmds.c index 99b123b38f..5badf778bf 100644 --- a/bacula/src/dird/fd_cmds.c +++ b/bacula/src/dird/fd_cmds.c @@ -164,7 +164,7 @@ void get_level_since_time(JCR *jcr, char *since, int since_len) bool have_full; bool do_full = false; bool do_diff = false; - time_t now; + utime_t now; utime_t last_full_time; utime_t last_diff_time; @@ -189,7 +189,7 @@ void get_level_since_time(JCR *jcr, char *since, int since_len) case L_INCREMENTAL: POOLMEM *stime = get_pool_memory(PM_MESSAGE); /* Look up start time of last Full job */ - now = time(NULL); + now = (utime_t)time(NULL); jcr->jr.JobId = 0; /* flag to return since time */ have_full = db_find_job_start_time(jcr, jcr->db, &jcr->jr, &jcr->stime); /* If there was a successful job, make sure it is recent enough */ diff --git a/bacula/src/dird/job.c b/bacula/src/dird/job.c index 5529ee6f84..adaf765a10 100644 --- a/bacula/src/dird/job.c +++ b/bacula/src/dird/job.c @@ -662,7 +662,7 @@ bool allow_duplicate_job(JCR *jcr) if (strcmp(job->name(), djcr->job->name()) == 0) { bool cancel_queued = false; if (job->DuplicateJobProximity > 0) { - time_t now = time(NULL); + utime_t now = (utime_t)time(NULL); if ((now - djcr->start_time) > job->DuplicateJobProximity) { continue; /* not really a duplicate */ } diff --git a/bacula/src/dird/ua_prune.c b/bacula/src/dird/ua_prune.c index 102ec3e35a..2621d3f7ea 100644 --- a/bacula/src/dird/ua_prune.c +++ b/bacula/src/dird/ua_prune.c @@ -195,7 +195,7 @@ int prune_stats(UAContext *ua, utime_t retention) db_lock(ua->db); Mmsg(query, "DELETE FROM JobHistory WHERE JobTDate < %s", - edit_uint64(now - retention, ed1)); + edit_int64(now - retention, ed1)); db_sql_query(ua->db, query.c_str(), NULL, NULL); db_unlock(ua->db); @@ -237,7 +237,7 @@ int prune_files(UAContext *ua, CLIENT *client) now = (utime_t)time(NULL); /* Select Jobs -- for counting */ - Mmsg(query, count_select_job, edit_uint64(now - period, ed1), + Mmsg(query, count_select_job, edit_int64(now - period, ed1), edit_int64(cr.ClientId, ed2)); Dmsg3(050, "select now=%u period=%u sql=%s\n", (uint32_t)now, (uint32_t)period, query.c_str()); @@ -265,7 +265,7 @@ int prune_files(UAContext *ua, CLIENT *client) del.JobId = (JobId_t *)malloc(sizeof(JobId_t) * del.max_ids); /* Now process same set but making a delete list */ - Mmsg(query, select_job, edit_uint64(now - period, ed1), + Mmsg(query, select_job, edit_int64(now - period, ed1), edit_int64(cr.ClientId, ed2)); db_sql_query(ua->db, query.c_str(), file_delete_handler, (void *)&del); @@ -355,7 +355,7 @@ int prune_jobs(UAContext *ua, CLIENT *client, int JobType) * Select all files that are older than the JobRetention period * and stuff them into the "DeletionCandidates" table. */ - edit_uint64(now - period, ed1); + edit_int64(now - period, ed1); Mmsg(query, insert_delcand, (char)JobType, ed1, edit_int64(cr.ClientId, ed2)); if (!db_sql_query(ua->db, query.c_str(), NULL, (void *)NULL)) { @@ -483,10 +483,10 @@ int get_prune_list_for_volume(UAContext *ua, MEDIA_DBR *mr, del_ctx *del) edit_int64(mr->MediaId, ed1); period = mr->VolRetention; now = (utime_t)time(NULL); - edit_uint64(now-period, ed2); + edit_int64(now-period, ed2); Mmsg(query, sel_JobMedia, ed1, ed2); - Dmsg3(250, "Now=%d period=%d now-period=%d\n", (int)now, (int)period, - (int)(now-period)); + Dmsg3(250, "Now=%d period=%d now-period=%s\n", (int)now, (int)period, + ed2); Dmsg1(050, "Query=%s\n", query.c_str()); if (!db_sql_query(ua->db, query.c_str(), file_delete_handler, (void *)del)) { diff --git a/bacula/src/stored/askdir.c b/bacula/src/stored/askdir.c index 4d33c255ae..276a5020cf 100644 --- a/bacula/src/stored/askdir.c +++ b/bacula/src/stored/askdir.c @@ -281,7 +281,7 @@ bool dir_find_next_appendable_volume(DCR *dcr) break; } bstrncpy(lastVolume, dcr->VolumeName, sizeof(lastVolume)); - if (dcr->can_i_use_volume()) { + if (dcr->can_i_write_volume()) { Dmsg1(100, "Call reserve_volume. Vol=%s\n", dcr->VolumeName); if (reserve_volume(dcr, dcr->VolumeName) == NULL) { Dmsg2(100, "Could not reserve volume %s on %s\n", dcr->VolumeName, diff --git a/bacula/src/stored/dev.h b/bacula/src/stored/dev.h index 57adacce32..8c044f0003 100644 --- a/bacula/src/stored/dev.h +++ b/bacula/src/stored/dev.h @@ -538,7 +538,10 @@ public: void clear_reserved(); void set_reserved(); void unreserve_device(); + + /* Methods in vol_mgr.c */ bool can_i_use_volume(); + bool can_i_write_volume(); /* Methods in mount.c */ bool mount_next_write_volume(); diff --git a/bacula/src/stored/vol_mgr.c b/bacula/src/stored/vol_mgr.c index f48dddb58f..a3c7dc15b0 100644 --- a/bacula/src/stored/vol_mgr.c +++ b/bacula/src/stored/vol_mgr.c @@ -498,6 +498,10 @@ void switch_device(DCR *dcr, DEVICE *dev) VOLRES *find_volume(const char *VolumeName) { VOLRES vol, *fvol; + + if (vol_list->empty()) { + return NULL; + } /* Do not lock reservations here */ lock_volumes(); vol.vol_name = bstrdup(VolumeName); @@ -509,6 +513,31 @@ VOLRES *find_volume(const char *VolumeName) return fvol; } +/* + * Search for a Volume name in the read Volume list. + * + * Returns: VOLRES entry on success + * NULL if the Volume is not in the list + */ +static VOLRES *find_read_volume(const char *VolumeName) +{ + VOLRES vol, *fvol; + + if (read_vol_list->empty()) { + return NULL; + } + /* Do not lock reservations here */ + lock_read_volumes(); + vol.vol_name = bstrdup(VolumeName); + /* Note, we do want a simple my_compare on volume name only here */ + fvol = (VOLRES *)read_vol_list->binary_search(&vol, my_compare); + free(vol.vol_name); + Dmsg2(dbglvl, "find_read_vol=%s found=%d\n", VolumeName, fvol!=NULL); + unlock_read_volumes(); + return fvol; +} + + /* * Free a Volume from the Volume list if it is no longer used * Note, for tape drives we want to remember where the Volume @@ -643,6 +672,26 @@ void free_volume_lists() } } +/* + * Determine if caller can write on volume + */ +bool DCR::can_i_write_volume() +{ + VOLRES *vol; + + lock_read_volumes(); + vol = find_read_volume(VolumeName); + unlock_read_volumes(); + if (vol) { + Dmsg1(100, "Found in read list; cannot write vol=%s\n", VolumeName); + return false; + } + return can_i_use_volume(); +} + +/* + * Determine if caller can read or write volume + */ bool DCR::can_i_use_volume() { bool rtn = true; diff --git a/bacula/src/version.h b/bacula/src/version.h index a3ff69825b..6bd9d09bf4 100644 --- a/bacula/src/version.h +++ b/bacula/src/version.h @@ -4,8 +4,8 @@ #undef VERSION #define VERSION "2.5.17" -#define BDATE "23 October 2008" -#define LSMDATE "23Oct08" +#define BDATE "24 October 2008" +#define LSMDATE "24Oct08" #define PROG_COPYRIGHT "Copyright (C) %d-2008 Free Software Foundation Europe e.V.\n" #define BYEAR "2008" /* year for copyright messages in progs */ diff --git a/bacula/technotes-2.5 b/bacula/technotes-2.5 index 7c92cbce7c..bb10defe89 100644 --- a/bacula/technotes-2.5 +++ b/bacula/technotes-2.5 @@ -11,45 +11,20 @@ dbi database driver --with-db-port enhancement to wait command: wait mount ... parse config - dbport in dbcheck dbdriver filepattern (restore with regex in bsr) libtool - remove reader/writer in FOPTS???? -================== Warning !!!!!! ========================== -This BETA release of Bacula 2.5.x development code uses libtool -to generate the Bacula libraries as shared objects rather than -being directly linked in as in prior versions. This means that -the Bacula shared objects, must either be in a shared object -directory known to the loader or they must be in the directory -that may be specified on the ./configure line using the ---libdir option as: - - ./configure --libdir=/full-path/dir - -the default /usr/lib. If --libdir is specified, there should be -no need to modify your loader configuration provided that -the shared objects are installed in that directory (Bacula -does this with the make install command). The shared objects -that Bacula references are: - -libbaccfg.so -libbacfind.so -libbacpy.so -libbac.so - -If you have problems with libtool or you wish to use the old -way of building static libraries, you can do so by disabling -libtool on the configure command line with: - - ./configure --disable-libtool -============================================================== - - General: +24Oct08 +kes Fix editing of retention time difference to use 64 bit + int instead of 64 bit unsigned. This should permit very + long retention periods. +kes Implement code to prohibit a write job from appending to a + Volume that will be used for a read operation. This is + new code and could possibly cause some conflicts. 23Oct08 kes Integrate James Harper's Exchange Win32 plugin patch. kes Apply patch from Marco van Wieringen that implements the new -- 2.39.5