]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/testing/fix_1190.patch
3de44d107bae7d1f0323db52c60aae932108c6e2
[bacula/bacula] / bacula / patches / testing / fix_1190.patch
1 Index: match_bsr.c
2 ===================================================================
3 --- match_bsr.c (révision 8116)
4 +++ match_bsr.c (copie de travail)
5 @@ -36,16 +36,7 @@
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 + * For efficiency, once a bsr is done, it really should be
20   *   delinked from the bsr chain.  This will avoid the above 
21   *   problem and make traversal of the bsr chain more efficient.
22   *
23 @@ -254,41 +245,72 @@
24     return found_bsr;
25  }
26  
27 +
28 +static bool volfile_min(BSR_VOLFILE *volfile, uint32_t *ret)
29 +{
30 +   BSR_VOLFILE *vf;
31 +   uint32_t bsr_sfile=0;
32 +
33 +   /* Find the smallest file in the volfile */
34 +   bool ok=false;
35 +   for (vf = volfile; vf ; vf = vf->next) {
36 +      if (!vf->done) {
37 +         if (ok) {
38 +            bsr_sfile = MIN(bsr_sfile, vf->sfile);
39 +         } else {
40 +            bsr_sfile = vf->sfile;
41 +            ok=true;
42 +         }
43 +      }
44 +   }
45 +
46 +   *ret = bsr_sfile;
47 +   return ok;
48 +}
49 +
50 +static bool volblock_min(BSR_VOLBLOCK *volblock, uint32_t *ret)
51 +{
52 +   BSR_VOLBLOCK *vb;
53 +   uint32_t bsr_sblock=0;
54 +
55 +   bool ok = false;
56 +   for (vb = volblock; vb ; vb = vb->next) {
57 +      if (!vb->done) {
58 +         if (ok) {
59 +            bsr_sblock = MIN(bsr_sblock, vb->sblock);
60 +         } else {
61 +            bsr_sblock = vb->sblock;
62 +            ok=true;
63 +         }
64 +      }
65 +   }
66 +   *ret = bsr_sblock;
67 +   return ok;
68 +}
69 +
70 +
71  /*
72 - * ***FIXME***
73 - * This routine needs to be fixed to only look at items that
74 - *   are not marked as done.  Otherwise, it can find a bsr
75 - *   that has already been consumed, and this will cause the
76 - *   bsr to be used, thus we may seek back and re-read the
77 - *   same records, causing an error.  This deficiency must
78 - *   be fixed.  For the moment, it has been kludged in 
79 - *   read_record.c to avoid seeking back if find_next_bsr
80 - *   returns a bsr pointing to a smaller address (file/block).
81 + * This routine compare 2 bsr and return the one with the
82 + * smallest volfile/volblock
83   */
84  static BSR *find_smallest_volfile(BSR *found_bsr, BSR *bsr)
85  {
86     BSR *return_bsr = found_bsr;
87 -   BSR_VOLFILE *vf;
88 -   BSR_VOLBLOCK *vb;
89 -   uint32_t found_bsr_sfile, bsr_sfile;
90 -   uint32_t found_bsr_sblock, bsr_sblock;
91 +   uint32_t found_bsr_sfile=0, bsr_sfile=0;
92 +   uint32_t found_bsr_sblock=0, bsr_sblock=0;
93  
94 -   /* Find the smallest file in the found_bsr */
95 -   vf = found_bsr->volfile;
96 -   found_bsr_sfile = vf->sfile;
97 -   while ( (vf=vf->next) ) {
98 -      if (vf->sfile < found_bsr_sfile) {
99 -         found_bsr_sfile = vf->sfile;
100 -      }
101 +   if (!volfile_min(found_bsr->volfile, &found_bsr_sfile)) {
102 +      /* the found_bsr contains no volfile, it must be mark as done
103 +       * we can skip it and try the next one
104 +       */
105 +      return bsr;               /* No unused volfile in found_bsr, try bsr */
106     }
107  
108 -   /* Find the smallest file in the bsr */
109 -   vf = bsr->volfile;
110 -   bsr_sfile = vf->sfile;
111 -   while ( (vf=vf->next) ) {
112 -      if (vf->sfile < bsr_sfile) {
113 -         bsr_sfile = vf->sfile;
114 -      }
115 +   if (!volfile_min(bsr->volfile, &bsr_sfile)) {
116 +      /* the next bsr contains no volfile, it must be mark as done
117 +       * we can skip it a keep the previous one
118 +       */
119 +      return found_bsr;         /* No unused volfile in bsr */
120     }
121      
122     /* if the bsr file is less than the found_bsr file, return bsr */
123 @@ -297,26 +319,21 @@
124     } else if (found_bsr_sfile == bsr_sfile) {
125        /* Files are equal */
126        /* find smallest block in found_bsr */
127 -      vb = found_bsr->volblock;
128 -      found_bsr_sblock = vb->sblock;
129 -      while ( (vb=vb->next) ) {
130 -         if (vb->sblock < found_bsr_sblock) {
131 -            found_bsr_sblock = vb->sblock;
132 -         }
133 +      if (!volblock_min(found_bsr->volblock, &found_bsr_sblock)) {
134 +         return bsr;            /* should not fail */
135        }
136 -      /* Find smallest block in bsr */
137 -      vb = bsr->volblock;
138 -      bsr_sblock = vb->sblock;
139 -      while ( (vb=vb->next) ) {
140 -         if (vb->sblock < bsr_sblock) {
141 -            bsr_sblock = vb->sblock;
142 -         }
143 +
144 +      if (!volblock_min(bsr->volblock, &bsr_sblock)) {
145 +         return found_bsr;      /* should not fail */
146        }
147 +
148        /* Compare and return the smallest */
149        if (found_bsr_sblock > bsr_sblock) {
150           return_bsr = bsr;
151        }
152     }
153 +   Dmsg5(dbglevel, "find_smallest_volfile bsr=0x%p %i > %i | %i > %i\n", 
154 +         return_bsr, found_bsr_sfile, bsr_sfile, found_bsr_sblock, bsr_sblock);
155     return return_bsr;
156  }
157  
158 @@ -360,7 +377,7 @@
159  static int match_all(BSR *bsr, DEV_RECORD *rec, VOLUME_LABEL *volrec,
160                       SESSION_LABEL *sessrec, bool done, JCR *jcr)
161  {
162 -   Dmsg0(050, "Enter match_all\n");
163 +   Dmsg1(050, "Enter match_all bsr=0x%p\n", bsr);
164     if (bsr->done) {
165  //    Dmsg0(dbglevel, "bsr->done set\n");
166        goto no_match;
167 @@ -612,9 +629,7 @@
168      * files in all cases, so it is "turned off" by the following 
169      * return statement.
170      */
171 -   return 1;
172  
173 -
174     if (!volblock) {
175        return 1;                       /* no specification matches all */
176     }
177 @@ -622,8 +637,8 @@
178     if (rec->state & REC_ISTAPE) {
179        return 1;                       /* All File records OK for this match */
180     }
181 -//  Dmsg3(dbglevel, "match_volblock: sblock=%u eblock=%u recblock=%u\n",
182 -//             volblock->sblock, volblock->eblock, rec->Block);
183 +   Dmsg3(dbglevel, "match_volblock: sblock=%u eblock=%u recblock=%u\n",
184 +         volblock->sblock, volblock->eblock, rec->Block);
185     if (volblock->sblock <= rec->Block && volblock->eblock >= rec->Block) {
186        return 1;
187     }
188 Index: read_record.c
189 ===================================================================
190 --- read_record.c       (révision 8116)
191 +++ read_record.c       (copie de travail)
192 @@ -346,6 +346,9 @@
193         */
194        if (dev->file > bsr->volfile->sfile ||             
195           (dev->file == bsr->volfile->sfile && dev->block_num > bsr->volblock->sblock)) {
196 +         Jmsg(jcr, M_ERROR, 0, _("Reposition from (file:block) %u:%u to %u:%u\n"),
197 +            dev->file, dev->block_num, bsr->volfile->sfile,
198 +            bsr->volblock->sblock);
199           return false;
200        }
201        if (verbose) {
202 Index: parse_bsr.c
203 ===================================================================
204 --- parse_bsr.c (révision 8116)
205 +++ parse_bsr.c (copie de travail)
206 @@ -139,7 +139,7 @@
207     BSR *root_bsr = new_bsr();
208     BSR *bsr = root_bsr;
209  
210 -   Dmsg1(300, "Enter parse_bsf %s\n", fname);
211 +   Dmsg2(300, "Enter parse_bsf %s 0x%p\n", fname, bsr);
212     if ((lc = lex_open_file(lc, fname, s_err)) == NULL) {
213        berrno be;
214        Emsg2(M_ERROR_TERM, 0, _("Cannot open bootstrap file %s: %s\n"),
215 @@ -190,6 +190,7 @@
216     for (bsr=root_bsr; bsr; bsr=bsr->next) {
217        bsr->root = root_bsr;
218     }
219 +   dump_bsr(root_bsr, true);
220     return root_bsr;
221  }
222  
223 Index: bscan.c
224 ===================================================================
225 --- bscan.c     (révision 8136)
226 +++ bscan.c     (copie de travail)
227 @@ -420,9 +420,9 @@
228     }
229  
230     if (list_records) {
231 -      Pmsg5(000, _("Record: SessId=%u SessTim=%u FileIndex=%d Stream=%d len=%u\n"),
232 +      Pmsg6(000, _("Record: SessId=%u SessTim=%u FileIndex=%d Stream=%d len=%u block=%u\n"),
233              rec->VolSessionId, rec->VolSessionTime, rec->FileIndex,
234 -            rec->Stream, rec->data_len);
235 +            rec->Stream, rec->data_len, rec->Block);
236     }
237     /*
238      * Check for Start or End of Session Record