]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/testing/find_smallest_volfile.patch
ebl Change Win32 by Win64 in status
[bacula/bacula] / bacula / patches / testing / find_smallest_volfile.patch
1 Index: src/stored/match_bsr.c
2 ===================================================================
3 --- src/stored/match_bsr.c      (rĂ©vision 8116)
4 +++ src/stored/match_bsr.c      (copie de travail)
5 @@ -36,15 +36,6 @@
6  
7  /*
8   * ***FIXME***
9 - * find_smallest_volfile needs to be fixed to only look at items that
10 - *   are not marked as done.  Otherwise, it can find a bsr
11 - *   that has already been consumed, and this will cause the
12 - *   bsr to be used, thus we may seek back and re-read the
13 - *   same records, causing an error.  This deficiency must
14 - *   be fixed.  For the moment, it has been kludged in 
15 - *   read_record.c to avoid seeking back if find_next_bsr
16 - *   returns a bsr pointing to a smaller address (file/block).
17 - *
18   * Also for efficiency, once a bsr is done, it really should be
19   *   delinked from the bsr chain.  This will avoid the above 
20   *   problem and make traversal of the bsr chain more efficient.
21 @@ -255,68 +246,88 @@
22  }
23  
24  /*
25 - * ***FIXME***
26 - * This routine needs to be fixed to only look at items that
27 - *   are not marked as done.  Otherwise, it can find a bsr
28 - *   that has already been consumed, and this will cause the
29 - *   bsr to be used, thus we may seek back and re-read the
30 - *   same records, causing an error.  This deficiency must
31 - *   be fixed.  For the moment, it has been kludged in 
32 - *   read_record.c to avoid seeking back if find_next_bsr
33 - *   returns a bsr pointing to a smaller address (file/block).
34 + * Get the smallest file number from this volfile part
35 + * Don't use "done" elements
36   */
37 -static BSR *find_smallest_volfile(BSR *found_bsr, BSR *bsr)
38 +static bool get_smallest_volfile(BSR_VOLFILE *vf, uint32_t *ret)
39  {
40 -   BSR *return_bsr = found_bsr;
41 -   BSR_VOLFILE *vf;
42 -   BSR_VOLBLOCK *vb;
43 -   uint32_t found_bsr_sfile, bsr_sfile;
44 -   uint32_t found_bsr_sblock, bsr_sblock;
45 +   bool ok=false;
46 +   uint32_t min_val=0;
47  
48 -   /* Find the smallest file in the found_bsr */
49 -   vf = found_bsr->volfile;
50 -   found_bsr_sfile = vf->sfile;
51 -   while ( (vf=vf->next) ) {
52 -      if (vf->sfile < found_bsr_sfile) {
53 -         found_bsr_sfile = vf->sfile;
54 +   for (; vf ; vf = vf->next) {
55 +      if (!vf->done) {
56 +         if (ok) {
57 +            min_val = MIN(min_val, vf->sfile);
58 +         } else {
59 +            min_val = vf->sfile;
60 +            ok=true;
61 +         }
62        }
63     }
64 +   *ret = min_val;
65 +   return ok;
66 +}
67  
68 -   /* Find the smallest file in the bsr */
69 -   vf = bsr->volfile;
70 -   bsr_sfile = vf->sfile;
71 -   while ( (vf=vf->next) ) {
72 -      if (vf->sfile < bsr_sfile) {
73 -         bsr_sfile = vf->sfile;
74 +/*
75 + * Get the smallest block number from this volblock part
76 + * Don't use "done" elements
77 + */
78 +static bool get_smallest_volblock(BSR_VOLBLOCK *vb, uint32_t *ret)
79 +{
80 +   bool ok=false;
81 +   uint32_t min_val=0;
82 +
83 +   for (; vb ; vb = vb->next) {
84 +      if (!vb->done) {
85 +         if (ok) {
86 +            min_val = MIN(min_val, vb->sblock);
87 +         } else {
88 +            min_val = vb->sblock;
89 +            ok=true;
90 +         }
91        }
92     }
93 +   *ret = min_val;
94 +   return ok;
95 +}
96 +
97 +/*
98 + *
99 + */
100 +static BSR *find_smallest_volfile(BSR *found_bsr, BSR *bsr)
101 +{
102 +   BSR *return_bsr = found_bsr;
103 +   uint32_t found_bsr_sfile=0, bsr_sfile=0;
104 +   uint32_t found_bsr_sblock=0, bsr_sblock=0;
105 +
106 +   if (!get_smallest_volfile(found_bsr->volfile, &found_bsr_sfile)) {
107 +      return bsr;               /* found_bsr seems to be done...*/
108 +   }
109 +   
110 +   if (!get_smallest_volfile(bsr->volfile, &bsr_sfile)) {
111 +      return found_bsr;         /* bsr seems to be done... */
112 +   }
113      
114     /* if the bsr file is less than the found_bsr file, return bsr */
115     if (found_bsr_sfile > bsr_sfile) {
116        return_bsr = bsr;
117     } else if (found_bsr_sfile == bsr_sfile) {
118 -      /* Files are equal */
119 -      /* find smallest block in found_bsr */
120 -      vb = found_bsr->volblock;
121 -      found_bsr_sblock = vb->sblock;
122 -      while ( (vb=vb->next) ) {
123 -         if (vb->sblock < found_bsr_sblock) {
124 -            found_bsr_sblock = vb->sblock;
125 -         }
126 +      /* Files are equal, use block to find the smallest */
127 +      if (!get_smallest_volblock(found_bsr->volblock, &found_bsr_sblock)) {
128 +         return bsr;            /* Should not be there */
129        }
130 -      /* Find smallest block in bsr */
131 -      vb = bsr->volblock;
132 -      bsr_sblock = vb->sblock;
133 -      while ( (vb=vb->next) ) {
134 -         if (vb->sblock < bsr_sblock) {
135 -            bsr_sblock = vb->sblock;
136 -         }
137 +
138 +      if (!get_smallest_volblock(bsr->volblock, &bsr_sblock)) {
139 +         return found_bsr;      /* Should not be there */
140        }
141 +
142        /* Compare and return the smallest */
143        if (found_bsr_sblock > bsr_sblock) {
144           return_bsr = bsr;
145        }
146     }
147 +   Dmsg5(dbglevel, "find_smallest_volfile bsr=0x%p %i > %i | %i > %i\n",
148 +         return_bsr, found_bsr_sfile, bsr_sfile, found_bsr_sblock, bsr_sblock);
149     return return_bsr;
150  }
151  
152 @@ -386,8 +397,6 @@
153           rec->Block, bsr->volblock->sblock, bsr->volblock->eblock);
154        goto no_match;
155     }
156 -   Dmsg3(dbglevel, "OK bsr Block=%u. bsr=%u,%u\n", 
157 -      rec->Block, bsr->volblock->sblock, bsr->volblock->eblock);
158  
159     if (!match_sesstime(bsr, bsr->sesstime, rec, 1)) {
160        Dmsg2(dbglevel, "Fail on sesstime. bsr=%u rec=%u\n",
161 @@ -411,6 +420,9 @@
162     Dmsg3(dbglevel, "match on findex=%d. bsr=%d,%d\n",
163           rec->FileIndex, bsr->FileIndex->findex, bsr->FileIndex->findex2);
164  
165 +   Dmsg3(dbglevel, "OK bsr Block=%u. bsr=%u,%u\n", 
166 +      rec->Block, bsr->volblock->sblock, bsr->volblock->eblock);
167 +
168     if (!match_fileregex(bsr, rec, jcr)) {
169       Dmsg1(dbglevel, "Fail on fileregex='%s'\n", bsr->fileregex);
170       goto no_match;
171 @@ -607,14 +619,7 @@
172  
173  static int match_volblock(BSR *bsr, BSR_VOLBLOCK *volblock, DEV_RECORD *rec, bool done)
174  {
175 -   /*
176 -    * Currently block matching does not work correctly for disk
177 -    * files in all cases, so it is "turned off" by the following 
178 -    * return statement.
179 -    */
180 -   return 1;
181  
182 -
183     if (!volblock) {
184        return 1;                       /* no specification matches all */
185     }
186 @@ -622,8 +627,9 @@
187     if (rec->state & REC_ISTAPE) {
188        return 1;                       /* All File records OK for this match */
189     }
190 -//  Dmsg3(dbglevel, "match_volblock: sblock=%u eblock=%u recblock=%u\n",
191 -//             volblock->sblock, volblock->eblock, rec->Block);
192 +   Dmsg3(dbglevel, "match_volblock: sblock=%u eblock=%u recblock=%u\n",
193 +         volblock->sblock, volblock->eblock, rec->Block);
194 +
195     if (volblock->sblock <= rec->Block && volblock->eblock >= rec->Block) {
196        return 1;
197     }
198 Index: src/stored/read_record.c
199 ===================================================================
200 --- src/stored/read_record.c    (rĂ©vision 8116)
201 +++ src/stored/read_record.c    (copie de travail)
202 @@ -261,8 +261,8 @@
203                 Dmsg2(100, "All done=(file:block) %u:%u\n", dev->file, dev->block_num);
204                 break;
205              } else if (rec->match_stat == 0) {  /* no match */
206 -               Dmsg4(100, "BSR no match: clear rem=%d FI=%d before set_eof pos %u:%u\n",
207 -                  rec->remainder, rec->FileIndex, dev->file, dev->block_num);
208 +               Dmsg7(100, "BSR no match: clear rem=%d FI=%d rec->Block=%d dev->LastBlock=%d dev->EndBlock=%d before set_eof pos %u:%u\n",
209 +                     rec->remainder, rec->FileIndex, rec->Block, dev->LastBlock, dev->EndBlock, dev->file, dev->block_num);
210                 rec->remainder = 0;
211                 rec->state &= ~REC_PARTIAL_RECORD;
212                 if (try_repositioning(jcr, rec, dcr)) {
213 @@ -346,6 +346,9 @@
214         */
215        if (dev->file > bsr->volfile->sfile ||             
216           (dev->file == bsr->volfile->sfile && dev->block_num > bsr->volblock->sblock)) {
217 +         Dmsg4(dbglvl, _("Reposition from (file:block) %u:%u to %u:%u\n"),
218 +            dev->file, dev->block_num, bsr->volfile->sfile,
219 +            bsr->volblock->sblock);
220           return false;
221        }
222        if (verbose) {