]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/testing/find_smallest_volfile.patch
ebl cleanup
[bacula/bacula] / bacula / patches / testing / find_smallest_volfile.patch
1 Index: match_bsr.c
2 ===================================================================
3 --- match_bsr.c (rĂ©vision 8116)
4 +++ match_bsr.c (copie de travail)
5 @@ -270,26 +270,42 @@
6     BSR *return_bsr = found_bsr;
7     BSR_VOLFILE *vf;
8     BSR_VOLBLOCK *vb;
9 -   uint32_t found_bsr_sfile, bsr_sfile;
10 -   uint32_t found_bsr_sblock, bsr_sblock;
11 +   uint32_t found_bsr_sfile=0, bsr_sfile=0;
12 +   uint32_t found_bsr_sblock=0, bsr_sblock=0;
13  
14     /* Find the smallest file in the found_bsr */
15 -   vf = found_bsr->volfile;
16 -   found_bsr_sfile = vf->sfile;
17 -   while ( (vf=vf->next) ) {
18 -      if (vf->sfile < found_bsr_sfile) {
19 -         found_bsr_sfile = vf->sfile;
20 +   bool ok=false;
21 +   for (vf = found_bsr->volfile; vf ; vf = vf->next) {
22 +      if (!vf->done) {
23 +         if (ok) {
24 +            found_bsr_sfile = MIN(found_bsr_sfile, vf->sfile);
25 +         } else {
26 +            found_bsr_sfile = vf->sfile;
27 +            ok=true;
28 +         }
29        }
30     }
31  
32 -   /* Find the smallest file in the bsr */
33 -   vf = bsr->volfile;
34 -   bsr_sfile = vf->sfile;
35 -   while ( (vf=vf->next) ) {
36 -      if (vf->sfile < bsr_sfile) {
37 -         bsr_sfile = vf->sfile;
38 +   if (!ok) {                   /* No unused volfile in found_bsr */
39 +      return NULL;
40 +   }
41 +   
42 +   /* Find the smallest file in the found_bsr */
43 +   ok=false;
44 +   for (vf = bsr->volfile; vf ; vf = vf->next) {
45 +      if (!vf->done) {
46 +         if (ok) {
47 +            bsr_sfile = MIN(bsr_sfile, vf->sfile);
48 +         } else {
49 +            bsr_sfile = vf->sfile;
50 +            ok=true;
51 +         }
52        }
53     }
54 +
55 +   if (!ok) {                   /* No unused volfile in bsr */
56 +      return found_bsr;
57 +   }
58      
59     /* if the bsr file is less than the found_bsr file, return bsr */
60     if (found_bsr_sfile > bsr_sfile) {
61 @@ -297,26 +313,39 @@
62     } else if (found_bsr_sfile == bsr_sfile) {
63        /* Files are equal */
64        /* find smallest block in found_bsr */
65 -      vb = found_bsr->volblock;
66 -      found_bsr_sblock = vb->sblock;
67 -      while ( (vb=vb->next) ) {
68 -         if (vb->sblock < found_bsr_sblock) {
69 -            found_bsr_sblock = vb->sblock;
70 +      ok = false;
71 +      for (vb = found_bsr->volblock; vb ; vb = vb->next) {
72 +         if (!vb->done) {
73 +            if (ok) {
74 +               found_bsr_sblock = MIN(found_bsr_sblock, vb->sblock);
75 +            } else {
76 +               found_bsr_sblock = vb->sblock;
77 +               ok=true;
78 +            }
79           }
80        }
81 +      ASSERT(ok);               /* a file is not done, so we have a bloc... */
82 +
83        /* Find smallest block in bsr */
84 -      vb = bsr->volblock;
85 -      bsr_sblock = vb->sblock;
86 -      while ( (vb=vb->next) ) {
87 -         if (vb->sblock < bsr_sblock) {
88 -            bsr_sblock = vb->sblock;
89 +      ok = false;
90 +      for (vb = bsr->volblock; vb ; vb = vb->next) {
91 +         if (!vb->done) {
92 +            if (ok) {
93 +               bsr_sblock = MIN(bsr_sblock, vb->sblock);
94 +            } else {
95 +               bsr_sblock = vb->sblock;
96 +               ok=true;
97 +            }
98           }
99        }
100 +      ASSERT(ok);
101 +
102        /* Compare and return the smallest */
103        if (found_bsr_sblock > bsr_sblock) {
104           return_bsr = bsr;
105        }
106     }
107 +   Dmsg5(dbglevel, "find_smallest_volfile bsr=0x%p %i > %i | %i > %i\n", return_bsr, found_bsr_sfile, bsr_sfile, found_bsr_sblock, bsr_sblock);
108     return return_bsr;
109  }
110