]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/testing/next_vol.patch
ebl Try to compile tokyodbm with mingw
[bacula/bacula] / bacula / patches / testing / next_vol.patch
1 Index: src/dird/next_vol.c
2 ===================================================================
3 --- src/dird/next_vol.c (révision 7156)
4 +++ src/dird/next_vol.c (copie de travail)
5 @@ -94,28 +94,30 @@
6                  */
7                 if (prune) {
8                    Dmsg0(150, "Call prune_volumes\n");
9 -                  prune_volumes(jcr, InChanger, mr);
10 +                  ok = prune_volumes(jcr, InChanger, mr);
11                 }
12 -               ok = recycle_oldest_purged_volume(jcr, InChanger, mr);
13 -               if (!ok && create) {
14 -                  Dmsg4(050, "after prune volumes_vol ok=%d index=%d InChanger=%d Vstat=%s\n",
15 -                        ok, index, InChanger, mr->VolStatus);
16 -                  /*
17 -                   * 5. Try pulling a volume from the Scratch pool
18 -                   */ 
19 -                  ok = get_scratch_volume(jcr, InChanger, mr);
20 -               }
21 -               /*
22 -                * If we are using an Autochanger and have not found
23 -                * a volume, retry looking for any volume. 
24 -                */
25 -               if (InChanger) {
26 -                  InChanger = false;
27 -                  if (!ok) {
28 -                     continue;           /* retry again accepting any volume */
29 -                  }
30 -               }
31 -            }
32 +              if (!ok) {
33 +                 ok = recycle_oldest_purged_volume(jcr, InChanger, mr);
34 +                 if (!ok && create) {
35 +                    Dmsg4(050, "after prune volumes_vol ok=%d index=%d InChanger=%d Vstat=%s\n",
36 +                          ok, index, InChanger, mr->VolStatus);
37 +                    /*
38 +                     * 5. Try pulling a volume from the Scratch pool
39 +                     */ 
40 +                    ok = get_scratch_volume(jcr, InChanger, mr);
41 +                    Dmsg4(050, "after get scratch volume ok=%d index=%d InChanger=%d Vstat=%s\n",
42 +                          ok, index, InChanger, mr->VolStatus);
43 +                 }
44 +                 /*
45 +                  * If we are using an Autochanger and have not found
46 +                  * a volume, retry looking for any volume. 
47 +                  */
48 +                 if (!ok && InChanger) {
49 +                    InChanger = false;
50 +                    continue;           /* retry again accepting any volume */
51 +                 }
52 +              }
53 +           }
54           }
55  
56  
57 Index: src/dird/recycle.c
58 ===================================================================
59 --- src/dird/recycle.c  (révision 7156)
60 +++ src/dird/recycle.c  (copie de travail)
61 @@ -40,23 +40,6 @@
62  #include "dird.h"
63  #include "ua.h"
64  
65 -struct s_oldest_ctx {
66 -   uint32_t MediaId;
67 -   char LastWritten[30];
68 -};
69 -
70 -static int oldest_handler(void *ctx, int num_fields, char **row)
71 -{
72 -   struct s_oldest_ctx *oldest = (struct s_oldest_ctx *)ctx;
73 -
74 -   if (row[0]) {
75 -      oldest->MediaId = str_to_int64(row[0]);
76 -      bstrncpy(oldest->LastWritten, row[1]?row[1]:"", sizeof(oldest->LastWritten));
77 -      Dmsg1(100, "New oldest %s\n", row[1]?row[1]:"");
78 -   }
79 -   return 1;
80 -}
81 -
82  /* Forward referenced functions */
83  
84  bool find_recycled_volume(JCR *jcr, bool InChanger, MEDIA_DBR *mr)
85 @@ -71,43 +54,18 @@
86     return false;
87  }
88  
89 -
90  /*
91   *   Look for oldest Purged volume
92   */
93  bool recycle_oldest_purged_volume(JCR *jcr, bool InChanger, MEDIA_DBR *mr)
94  {
95 -   struct s_oldest_ctx oldest;
96 -   char ed1[50];
97 -   POOLMEM *query = get_pool_memory(PM_EMSG);
98 -   const char *select =
99 -          "SELECT MediaId,LastWritten FROM Media "
100 -          "WHERE PoolId=%s AND Recycle=1 AND VolStatus='Purged' "
101 -          "AND Enabled=1 AND MediaType='%s' "
102 -          "ORDER BY LastWritten ASC,MediaId LIMIT 1";
103 -
104 -   Dmsg0(100, "Enter recycle_oldest_purged_volume\n");
105 -   oldest.MediaId = 0;
106 -   Mmsg(query, select, edit_int64(mr->PoolId, ed1), mr->MediaType);
107 -
108 -   if (!db_sql_query(jcr->db, query, oldest_handler, (void *)&oldest)) {
109 -      Jmsg(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));
110 -      Dmsg0(100, "return 0  recycle_oldest_purged_volume query\n");
111 -      free_pool_memory(query);
112 -      return false;
113 -   }
114 -   free_pool_memory(query);
115 -   Dmsg1(100, "Oldest mediaid=%d\n", oldest.MediaId);
116 -   if (oldest.MediaId != 0) {
117 -      mr->MediaId = oldest.MediaId;
118 -      if (db_get_media_record(jcr, jcr->db, mr)) {
119 -         if (recycle_volume(jcr, mr)) {
120 -            Jmsg(jcr, M_INFO, 0, _("Recycled volume \"%s\"\n"), mr->VolumeName);
121 -            Dmsg1(100, "return 1  recycle_oldest_purged_volume Vol=%s\n", mr->VolumeName);
122 -            return true;
123 -         }
124 +   bstrncpy(mr->VolStatus, "Purged", sizeof(mr->VolStatus));
125 +   if (db_find_next_volume(jcr, jcr->db, 1, InChanger, mr)) {
126 +      if (recycle_volume(jcr, mr)) {
127 +         Jmsg(jcr, M_INFO, 0, _("Recycled volume \"%s\"\n"), mr->VolumeName);
128 +         Dmsg1(100, "return 1  recycle_oldest_purged_volume Vol=%s\n", mr->VolumeName);
129 +         return true;
130        }
131 -      Jmsg(jcr, M_ERROR, 0, "%s", db_strerror(jcr->db));
132     }
133     Dmsg0(100, "return 0  recycle_oldest_purged_volume end\n");
134     return false;
135 Index: src/cats/sql_find.c
136 ===================================================================
137 --- src/cats/sql_find.c (révision 7156)
138 +++ src/cats/sql_find.c (copie de travail)
139 @@ -338,17 +338,15 @@
140           edit_int64(mr->PoolId, ed1), mr->MediaType);
141       item = 1;
142     } else {
143 -      char changer[100];
144 +      POOL_MEM changer(PM_FNAME);
145        /* Find next available volume */
146        if (InChanger) {
147 -         bsnprintf(changer, sizeof(changer), "AND InChanger=1 AND StorageId=%s",
148 -            edit_int64(mr->StorageId, ed1));
149 -      } else {
150 -         changer[0] = 0;
151 +         Mmsg(changer, "AND InChanger=1 AND StorageId=%s",
152 +             edit_int64(mr->StorageId, ed1));
153        }
154        if (strcmp(mr->VolStatus, "Recycle") == 0 ||
155            strcmp(mr->VolStatus, "Purged") == 0) {
156 -         order = "ORDER BY LastWritten ASC,MediaId";  /* take oldest */
157 +         order = "AND Recycle=1 ORDER BY LastWritten ASC,MediaId";  /* take oldest that can be recycled */
158        } else {
159           order = "ORDER BY LastWritten IS NULL,LastWritten DESC,MediaId";   /* take most recently written */
160        }
161 @@ -364,7 +362,7 @@
162           "%s "
163           "%s LIMIT %d",
164           edit_int64(mr->PoolId, ed1), mr->MediaType,
165 -         mr->VolStatus, changer, order, item);
166 +         mr->VolStatus, changer.c_str(), order, item);
167     }
168     Dmsg1(050, "fnextvol=%s\n", mdb->cmd);
169     if (!QUERY_DB(jcr, mdb, mdb->cmd)) {