X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;ds=sidebyside;f=bacula%2Fsrc%2Fstored%2Fmatch_bsr.c;h=2552eee607b3ae424282c1e445c59eeea7036d43;hb=85879e3483a0b19f132e57f9ea86d26dcc1a6b5c;hp=d02d085c9304e7fe9f16318d09fae57f6a8c3586;hpb=b72090a4c41be3ec1c8ec1e6c0609270eb024cc4;p=bacula%2Fbacula diff --git a/bacula/src/stored/match_bsr.c b/bacula/src/stored/match_bsr.c old mode 100755 new mode 100644 index d02d085c93..2552eee607 --- a/bacula/src/stored/match_bsr.c +++ b/bacula/src/stored/match_bsr.c @@ -1,3 +1,30 @@ +/* + Bacula® - The Network Backup Solution + + Copyright (C) 2002-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. + This program is Free Software; you can redistribute it and/or + modify it under the terms of version two of the GNU General Public + License as published by the Free Software Foundation and included + in the file LICENSE. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. + + Bacula® is a registered trademark of John Walker. + The licensor of Bacula is the Free Software Foundation Europe + (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich, + Switzerland, email:ftf@fsfeurope.org. +*/ /* * Match Bootstrap Records (used for restores) against * Volume Records @@ -6,22 +33,25 @@ * * Version $Id$ */ -/* - Copyright (C) 2002-2006 Kern Sibbald - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - version 2 as amended with additional clauses defined in the - file LICENSE in the main source directory. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - the file LICENSE for additional details. +/* + * ***FIXME*** + * find_smallest_volfile needs to be fixed to only look at items that + * are not marked as done. Otherwise, it can find a bsr + * that has already been consumed, and this will cause the + * bsr to be used, thus we may seek back and re-read the + * same records, causing an error. This deficiency must + * be fixed. For the moment, it has been kludged in + * read_record.c to avoid seeking back if find_next_bsr + * returns a bsr pointing to a smaller address (file/block). + * + * Also for efficiency, once a bsr is done, it really should be + * delinked from the bsr chain. This will avoid the above + * problem and make traversal of the bsr chain more efficient. + * + * To be done ... */ - #include "bacula.h" #include "stored.h" #ifdef HAVE_FNMATCH @@ -30,6 +60,8 @@ #include "lib/fnmatch.h" #endif +const int dbglevel = 500; + /* Forward references */ static int match_volume(BSR *bsr, BSR_VOLUME *volume, VOLUME_LABEL *volrec, bool done); static int match_sesstime(BSR *bsr, BSR_SESSTIME *sesstime, DEV_RECORD *rec, bool done); @@ -159,18 +191,20 @@ BSR *find_next_bsr(BSR *root_bsr, DEVICE *dev) { BSR *bsr; BSR *found_bsr = NULL; - bool no_file_seek = !dev->is_tape(); -#ifdef FILE_SEEK - no_file_seek = false; -#endif - if (!root_bsr || !root_bsr->use_positioning || - !root_bsr->reposition || no_file_seek) { - Dmsg2(300, "No nxt_bsr use_pos=%d repos=%d\n", root_bsr->use_positioning, root_bsr->reposition); + /* Do tape/disk seeking only if CAP_POSITIONBLOCKS is on */ + if (!root_bsr) { + Dmsg0(dbglevel, "NULL root bsr pointer passed to find_next_bsr.\n"); return NULL; } - Dmsg2(300, "use_pos=%d repos=%d\n", root_bsr->use_positioning, root_bsr->reposition); + if (!root_bsr->use_positioning || + !root_bsr->reposition || !dev->has_cap(CAP_POSITIONBLOCKS)) { + Dmsg2(dbglevel, "No nxt_bsr use_pos=%d repos=%d\n", root_bsr->use_positioning, root_bsr->reposition); + return NULL; + } + Dmsg2(dbglevel, "use_pos=%d repos=%d\n", root_bsr->use_positioning, root_bsr->reposition); root_bsr->mount_next_volume = false; + /* Walk through all bsrs to find the next one to use => smallest file,block */ for (bsr=root_bsr; bsr; bsr=bsr->next) { if (bsr->done || !match_volume(bsr, bsr->volume, &dev->VolHdr, 1)) { continue; @@ -192,6 +226,17 @@ BSR *find_next_bsr(BSR *root_bsr, DEVICE *dev) return found_bsr; } +/* + * ***FIXME*** + * This routine needs to be fixed to only look at items that + * are not marked as done. Otherwise, it can find a bsr + * that has already been consumed, and this will cause the + * bsr to be used, thus we may seek back and re-read the + * same records, causing an error. This deficiency must + * be fixed. For the moment, it has been kludged in + * read_record.c to avoid seeking back if find_next_bsr + * returns a bsr pointing to a smaller address (file/block). + */ static BSR *find_smallest_volfile(BSR *found_bsr, BSR *bsr) { BSR *return_bsr = found_bsr; @@ -200,6 +245,7 @@ static BSR *find_smallest_volfile(BSR *found_bsr, BSR *bsr) uint32_t found_bsr_sfile, bsr_sfile; uint32_t found_bsr_sblock, bsr_sblock; + /* Find the smallest file in the found_bsr */ vf = found_bsr->volfile; found_bsr_sfile = vf->sfile; while ( (vf=vf->next) ) { @@ -207,6 +253,8 @@ static BSR *find_smallest_volfile(BSR *found_bsr, BSR *bsr) found_bsr_sfile = vf->sfile; } } + + /* Find the smallest file in the bsr */ vf = bsr->volfile; bsr_sfile = vf->sfile; while ( (vf=vf->next) ) { @@ -214,10 +262,13 @@ static BSR *find_smallest_volfile(BSR *found_bsr, BSR *bsr) bsr_sfile = vf->sfile; } } + + /* if the bsr file is less than the found_bsr file, return bsr */ if (found_bsr_sfile > bsr_sfile) { return_bsr = bsr; } else if (found_bsr_sfile == bsr_sfile) { - /* Must check block */ + /* Files are equal */ + /* find smallest block in found_bsr */ vb = found_bsr->volblock; found_bsr_sblock = vb->sblock; while ( (vb=vb->next) ) { @@ -225,6 +276,7 @@ static BSR *find_smallest_volfile(BSR *found_bsr, BSR *bsr) found_bsr_sblock = vb->sblock; } } + /* Find smallest block in bsr */ vb = bsr->volblock; bsr_sblock = vb->sblock; while ( (vb=vb->next) ) { @@ -232,11 +284,11 @@ static BSR *find_smallest_volfile(BSR *found_bsr, BSR *bsr) bsr_sblock = vb->sblock; } } + /* Compare and return the smallest */ if (found_bsr_sblock > bsr_sblock) { return_bsr = bsr; } } - return return_bsr; } @@ -253,7 +305,7 @@ static BSR *find_smallest_volfile(BSR *found_bsr, BSR *bsr) bool is_this_bsr_done(BSR *bsr, DEV_RECORD *rec) { BSR *rbsr = rec->bsr; - Dmsg1(300, "match_set %d\n", rbsr != NULL); + Dmsg1(dbglevel, "match_set %d\n", rbsr != NULL); if (!rbsr) { return false; } @@ -262,7 +314,7 @@ bool is_this_bsr_done(BSR *bsr, DEV_RECORD *rec) if (rbsr->count && rbsr->found >= rbsr->count) { rbsr->done = true; rbsr->root->reposition = true; - Dmsg2(500, "is_end_this_bsr set reposition=1 count=%d found=%d\n", + Dmsg2(dbglevel, "is_end_this_bsr set reposition=1 count=%d found=%d\n", rbsr->count, rbsr->found); return true; } @@ -279,35 +331,36 @@ static int match_all(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec, SESSION_LABEL *sessrec, bool done) { if (bsr->done) { - Dmsg0(300, "bsr->done set\n"); +// Dmsg0(dbglevel, "bsr->done set\n"); goto no_match; } if (!match_volume(bsr, bsr->volume, volrec, 1)) { - Dmsg2(300, "bsr vol=%s != rec vol=%s\n", bsr->volume, volrec); + Dmsg2(dbglevel, "bsr fail vol=%s != rec vol=%s\n", bsr->volume->VolumeName, + volrec->VolumeName); goto no_match; } if (!match_volfile(bsr, bsr->volfile, rec, 1)) { - Dmsg2(300, "Fail on file. bsr=%d rec=%d\n", bsr->volfile->efile, - rec->File); + Dmsg3(dbglevel, "Fail on file=%d. bsr=%d,%d\n", + rec->File, bsr->volfile->sfile, bsr->volfile->efile); goto no_match; } if (!match_sesstime(bsr, bsr->sesstime, rec, 1)) { - Dmsg2(300, "Fail on sesstime. bsr=%d rec=%d\n", + Dmsg2(dbglevel, "Fail on sesstime. bsr=%d rec=%d\n", bsr->sesstime->sesstime, rec->VolSessionTime); goto no_match; } /* NOTE!! This test MUST come after the sesstime test */ if (!match_sessid(bsr, bsr->sessid, rec)) { - Dmsg2(300, "Fail on sessid. bsr=%d rec=%d\n", + Dmsg2(dbglevel, "Fail on sessid. bsr=%d rec=%d\n", bsr->sessid->sessid, rec->VolSessionId); goto no_match; } /* NOTE!! This test MUST come after sesstime and sessid tests */ if (!match_findex(bsr, bsr->FileIndex, rec, 1)) { - Dmsg2(300, "Fail on findex. bsr=%d rec=%d\n", - bsr->FileIndex->findex2, rec->FileIndex); + Dmsg3(dbglevel, "Fail on findex=%d. bsr=%d,%d\n", + rec->FileIndex, bsr->FileIndex->findex, bsr->FileIndex->findex2); goto no_match; } /* @@ -329,28 +382,28 @@ static int match_all(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec, * the rec->bsr = bsr optimization above. */ if (!match_jobid(bsr, bsr->JobId, sessrec, 1)) { - Dmsg0(300, "fail on JobId\n"); + Dmsg0(dbglevel, "fail on JobId\n"); goto no_match; } if (!match_job(bsr, bsr->job, sessrec, 1)) { - Dmsg0(300, "fail on Job\n"); + Dmsg0(dbglevel, "fail on Job\n"); goto no_match; } if (!match_client(bsr, bsr->client, sessrec, 1)) { - Dmsg0(300, "fail on Client\n"); + Dmsg0(dbglevel, "fail on Client\n"); goto no_match; } if (!match_job_type(bsr, bsr->JobType, sessrec, 1)) { - Dmsg0(300, "fail on Job type\n"); + Dmsg0(dbglevel, "fail on Job type\n"); goto no_match; } if (!match_job_level(bsr, bsr->JobLevel, sessrec, 1)) { - Dmsg0(300, "fail on Job level\n"); + Dmsg0(dbglevel, "fail on Job level\n"); goto no_match; } if (!match_stream(bsr, bsr->stream, rec, 1)) { - Dmsg0(300, "fail on stream\n"); + Dmsg0(dbglevel, "fail on stream\n"); goto no_match; } return 1; @@ -384,7 +437,7 @@ static int match_client(BSR *bsr, BSR_CLIENT *client, SESSION_LABEL *sessrec, bo if (!client) { return 1; /* no specification matches all */ } - if (fnmatch(client->ClientName, sessrec->ClientName, 0) == 0) { + if (strcmp(client->ClientName, sessrec->ClientName) == 0) { return 1; } if (client->next) { @@ -398,7 +451,7 @@ static int match_job(BSR *bsr, BSR_JOB *job, SESSION_LABEL *sessrec, bool done) if (!job) { return 1; /* no specification matches all */ } - if (fnmatch(job->Job, sessrec->Job, 0) == 0) { + if (strcmp(job->Job, sessrec->Job) == 0) { return 1; } if (job->next) { @@ -458,7 +511,7 @@ static int match_volfile(BSR *bsr, BSR_VOLFILE *volfile, DEV_RECORD *rec, bool d if (!(rec->state & REC_ISTAPE)) { return 1; /* All File records OK for this match */ } -// Dmsg3(300, "match_volfile: sfile=%d efile=%d recfile=%d\n", +// Dmsg3(dbglevel, "match_volfile: sfile=%d efile=%d recfile=%d\n", // volfile->sfile, volfile->efile, rec->File); if (volfile->sfile <= rec->File && volfile->efile >= rec->File) { return 1; @@ -475,7 +528,7 @@ static int match_volfile(BSR *bsr, BSR_VOLFILE *volfile, DEV_RECORD *rec, bool d if (volfile->done && done) { bsr->done = true; bsr->root->reposition = true; - Dmsg2(300, "bsr done from volfile rec=%d volefile=%d\n", + Dmsg2(dbglevel, "bsr done from volfile rec=%d volefile=%d\n", rec->File, volfile->efile); } return 0; @@ -512,7 +565,7 @@ static int match_sesstime(BSR *bsr, BSR_SESSTIME *sesstime, DEV_RECORD *rec, boo if (sesstime->done && done) { bsr->done = true; bsr->root->reposition = true; - Dmsg0(300, "bsr done from sesstime\n"); + Dmsg0(dbglevel, "bsr done from sesstime\n"); } return 0; } @@ -538,19 +591,22 @@ static int match_sessid(BSR *bsr, BSR_SESSID *sessid, DEV_RECORD *rec) * ***FIXME*** optimizations * We could optimize a lot here by removing the recursion, and * stopping the search earlier -- say when rec->FileIndex > findex->findex2 - * and findex->next == NULL. Also, the current entry tests could be skipped - * if findex->done is set. + * and findex->next == NULL. */ static int match_findex(BSR *bsr, BSR_FINDEX *findex, DEV_RECORD *rec, bool done) { if (!findex) { return 1; /* no specification matches all */ } - if (findex->findex <= rec->FileIndex && findex->findex2 >= rec->FileIndex) { - return 1; - } - if (rec->FileIndex > findex->findex2) { - findex->done = true; + if (!findex->done) { + if (findex->findex <= rec->FileIndex && findex->findex2 >= rec->FileIndex) { + Dmsg3(dbglevel, "Match on findex=%d. bsr=%d,%d\n", + rec->FileIndex, findex->findex, findex->findex2); + return 1; + } + if (rec->FileIndex > findex->findex2) { + findex->done = true; + } } if (findex->next) { return match_findex(bsr, findex->next, rec, findex->done && done); @@ -558,7 +614,7 @@ static int match_findex(BSR *bsr, BSR_FINDEX *findex, DEV_RECORD *rec, bool done if (findex->done && done) { bsr->done = true; bsr->root->reposition = true; - Dmsg1(300, "bsr done from findex %d\n", rec->FileIndex); + Dmsg1(dbglevel, "bsr done from findex %d\n", rec->FileIndex); } return 0; }