]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/testing/fix_1190.patch
ebl small fix
[bacula/bacula] / bacula / patches / testing / fix_1190.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" element in account
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" element in account
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 @@ -607,14 +618,7 @@
153  
154  static int match_volblock(BSR *bsr, BSR_VOLBLOCK *volblock, DEV_RECORD *rec, bool done)
155  {
156 -   /*
157 -    * Currently block matching does not work correctly for disk
158 -    * files in all cases, so it is "turned off" by the following 
159 -    * return statement.
160 -    */
161 -   return 1;
162  
163 -
164     if (!volblock) {
165        return 1;                       /* no specification matches all */
166     }
167 @@ -622,8 +626,9 @@
168     if (rec->state & REC_ISTAPE) {
169        return 1;                       /* All File records OK for this match */
170     }
171 -//  Dmsg3(dbglevel, "match_volblock: sblock=%u eblock=%u recblock=%u\n",
172 -//             volblock->sblock, volblock->eblock, rec->Block);
173 +   Dmsg3(dbglevel, "match_volblock: sblock=%u eblock=%u recblock=%u\n",
174 +         volblock->sblock, volblock->eblock, rec->Block);
175 +
176     if (volblock->sblock <= rec->Block && volblock->eblock >= rec->Block) {
177        return 1;
178     }
179 Index: src/stored/bscan.c
180 ===================================================================
181 --- src/stored/bscan.c  (révision 8146)
182 +++ src/stored/bscan.c  (copie de travail)
183 @@ -420,9 +420,9 @@
184     }
185  
186     if (list_records) {
187 -      Pmsg5(000, _("Record: SessId=%u SessTim=%u FileIndex=%d Stream=%d len=%u\n"),
188 +      Pmsg6(000, _("Record: SessId=%u SessTim=%u FileIndex=%d Stream=%d len=%u block=%u\n"),
189              rec->VolSessionId, rec->VolSessionTime, rec->FileIndex,
190 -            rec->Stream, rec->data_len);
191 +            rec->Stream, rec->data_len, rec->Block);
192     }
193     /*
194      * Check for Start or End of Session Record
195 Index: src/stored/block.c
196 ===================================================================
197 --- src/stored/block.c  (révision 8116)
198 +++ src/stored/block.c  (copie de travail)
199 @@ -1116,7 +1116,7 @@
200        dcr->EndBlock = dev->EndBlock;
201        dcr->EndFile  = dev->EndFile;
202     } else {
203 -      uint64_t addr = dev->file_addr + block->read_len - 1;
204 +      uint64_t addr = dev->file_addr + block->read_len;
205        dcr->EndBlock = (uint32_t)addr;
206        dcr->EndFile = (uint32_t)(addr >> 32);
207        dev->block_num = dcr->EndBlock;