]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/testing/accurate-db.patch
ebl Fix bad flag
[bacula/bacula] / bacula / patches / testing / accurate-db.patch
1 Index: src/filed/accurate.c
2 ===================================================================
3 --- src/filed/accurate.c        (révision 7288)
4 +++ src/filed/accurate.c        (copie de travail)
5 @@ -36,7 +36,7 @@
6  static int dbglvl=200;
7  
8  typedef struct PrivateCurFile {
9 -#ifndef USE_TCADB
10 +#ifdef USE_HTABLE
11     hlink link;
12  #endif
13     char *fname;                        /* not stored with tchdb mode */
14 @@ -45,9 +45,9 @@
15     bool seen;
16  } CurFile;
17  
18 +
19  #ifdef USE_TCADB
20 -static void realfree(void *p); /* used by tokyo code */
21 -
22 +static void realfree(void *p); /* used by tokyo/db code */
23  /*
24   * Update hash element seen=1
25   */
26 @@ -190,10 +190,152 @@
27     return true;
28  }
29  
30 -#else  /* HTABLE mode */
31 +#endif /* USE_TCADB */
32 +#ifdef USE_DB
33  
34 +/*
35 + * Update hash element seen=1
36 + */
37  static bool accurate_mark_file_as_seen(JCR *jcr, CurFile *elt)
38  {
39 +   bool ret=true;
40 +   DBT dbkey, dbdata;
41 +
42 +   elt->seen = 1;
43 +
44 +   dbkey.data = elt->fname;
45 +   dbkey.size = strlen(elt->fname)+1;
46 +   dbdata.data = elt;
47 +   dbdata.size = sizeof(CurFile);
48 +   if ((ret = jcr->file_list->put(jcr->file_list, NULL, &dbkey, &dbdata, 0))) {
49 +      Jmsg(jcr, M_ERROR, 1, _("Can't update accurate hash disk ERR=%i\n"), ret);
50 +      return 0;
51 +   }
52 +   return 1;
53 +}
54 +
55 +static bool accurate_lookup(JCR *jcr, char *fname, CurFile *elt)
56 +{
57 +   int ret=false;
58 +   elt->seen = 0;
59 +   DBT dbkey, dbdata;
60 +   /* Zero out the DBTs before using them. */
61 +   memset(&dbkey, 0, sizeof(DBT));
62 +   memset(&dbdata, 0, sizeof(DBT));
63 +
64 +   dbkey.data = fname;
65 +   dbkey.size = strlen(fname)+1;
66 +   
67 +   dbdata.data = elt;
68 +   dbdata.ulen = sizeof(CurFile);
69 +   dbdata.flags = DB_DBT_USERMEM;
70 +
71 +   if (jcr->file_list->get(jcr->file_list, NULL, &dbkey, &dbdata, 0) == 0) {
72 +      ret=true;
73 +   }
74 +   elt->fname = fname;
75 +   return ret;
76 +}
77 +
78 +/* Create tokyo dbm hash file 
79 + * If something goes wrong, we cancel accurate mode.
80 + */
81 +static bool accurate_init(JCR *jcr, int nbfile)
82 +{
83 +   int ret;
84 +
85 +   if ((ret = db_create(&jcr->file_list, NULL, 0)) != 0) {
86 +      Jmsg(jcr, M_ERROR, 1, _("Can't open accurate hash disk ERR=%i\n"), ret);
87 +      return 0;
88 +   }
89 +
90 +   jcr->file_list->set_errfile(jcr->file_list, stderr);
91 +   jcr->file_list->set_errpfx(jcr->file_list, "hash");
92 +
93 +   if ((ret = jcr->file_list->set_cachesize(jcr->file_list, 0, 32 * 1024 * 1024, 0)) != 0) {
94 +      Jmsg(jcr, M_ERROR, 1, _("Can't setup hash disk cache size ERR=%i\n"), ret);
95 +   }
96 +
97 +   jcr->hash_name  = get_pool_memory(PM_MESSAGE);
98 +   make_unique_filename(&jcr->hash_name, jcr->JobId, "accurate");
99 +
100 +   if ((ret = jcr->file_list->open(jcr->file_list,
101 +                                  NULL, jcr->hash_name, NULL, 
102 +                                  DB_BTREE, DB_CREATE, 0600)) != 0)
103 +   {
104 +      jcr->file_list->close(jcr->file_list, DB_NOSYNC);
105 +      jcr->file_list=NULL;
106 +      free_pool_memory(jcr->hash_name);
107 +      jcr->hash_name = NULL;
108 +      Jmsg(jcr, M_ERROR, 1, _("Can't setup hash disk cache size ERR=%i\n"), ret);
109 +      return 0;
110 +   }
111 +
112 +   return jcr->file_list != NULL;
113 +}
114 +
115 +/* This function is called at the end of backup
116 + * We walk over all hash disk element, and we check
117 + * for elt.seen.
118 + */
119 +bool accurate_send_deleted_list(JCR *jcr)
120 +{
121 +   CurFile elt;
122 +   FF_PKT *ff_pkt;
123 +   int stream = STREAM_UNIX_ATTRIBUTES;
124 +   DBC *cursorp=NULL;
125 +   DBT dbkey, dbdata;
126 +   /* Zero out the DBTs before using them. */
127 +   memset(&dbkey, 0, sizeof(DBT));
128 +   memset(&dbdata, 0, sizeof(DBT));
129 +   dbdata.data = &elt;
130 +   dbdata.ulen = sizeof(CurFile);
131 +   dbdata.flags = DB_DBT_USERMEM;
132 +
133 +   if (!jcr->accurate || jcr->JobLevel == L_FULL) {
134 +      goto bail_out;
135 +   }
136 +
137 +   if (jcr->file_list == NULL) {
138 +      goto bail_out;
139 +   }
140 +
141 +   ff_pkt = init_find_files();
142 +   ff_pkt->type = FT_DELETED;
143 +
144 +   /* traverse records */
145 +   jcr->file_list->cursor(jcr->file_list, NULL, &cursorp, 0); 
146 +
147 +   while(cursorp->c_get(cursorp, &dbkey, &dbdata, DB_NEXT) == 0) {
148 +      if (!elt.seen) { /* already seen */
149 +        ff_pkt->fname = (char *) dbkey.data;
150 +        ff_pkt->statp.st_mtime = elt.mtime;
151 +        ff_pkt->statp.st_ctime = elt.ctime;
152 +        encode_and_send_attributes(jcr, ff_pkt, stream);
153 +      }
154 +   }
155 +   cursorp->c_close(cursorp);
156 +
157 +   term_find_files(ff_pkt);
158 +bail_out:
159 +
160 +   if (jcr->file_list) {
161 +      jcr->file_list->close(jcr->file_list, DB_NOSYNC);
162 +      if (!bstrcmp(jcr->hash_name, "*")) {
163 +        unlink(jcr->hash_name);
164 +      }
165 +      free_pool_memory(jcr->hash_name);
166 +      jcr->hash_name = NULL;
167 +      jcr->file_list = NULL;
168 +   }
169 +   return true;
170 +}
171 +
172 +#endif /* USE_DB */
173 +#ifdef USE_HTABLE
174 +
175 +static bool accurate_mark_file_as_seen(JCR *jcr, CurFile *elt)
176 +{
177     CurFile *temp = (CurFile *)jcr->file_list->lookup(elt->fname);
178     temp->seen = 1;             /* records are in memory */
179     return true;
180 @@ -286,7 +428,21 @@
181        Jmsg(jcr, M_ERROR, 1, _("Can't update accurate hash disk ERR=%s\n"));
182        ret = false;
183     }
184 -#else  /* HTABLE */
185 +#endif
186 +#ifdef USE_DB
187 +   DBT dbkey, dbdata;
188 +   memset(&dbkey, 0, sizeof(DBT));
189 +   memset(&dbdata, 0, sizeof(DBT));
190 +   dbkey.data = fname;
191 +   dbkey.size = strlen(fname)+1;
192 +   dbdata.data = &elt;
193 +   dbdata.size = sizeof(CurFile);
194 +   if ((ret = jcr->file_list->put(jcr->file_list, NULL, &dbkey, &dbdata, 0))) {
195 +      Jmsg(jcr, M_ERROR, 1, _("Can't update accurate hash disk ERR=%i\n"), ret);
196 +      return false;
197 +   }
198 +#endif
199 +#ifdef USE_HTABLE
200     CurFile *item;
201     /* we store CurFile, fname and ctime/mtime in the same chunk */
202     item = (CurFile *)jcr->file_list->hash_malloc(sizeof(CurFile)+strlen(fname)+1);
203 @@ -296,7 +452,7 @@
204     jcr->file_list->insert(item->fname, item); 
205  #endif
206  
207 -// Dmsg2(dbglvl, "add fname=<%s> lstat=%s\n", fname, lstat);
208 +   //Dmsg2(dbglvl, "add fname=<%s> lstat=%s\n", fname, lstat);
209     return ret;
210  }
211  
212 Index: src/filed/filed.h
213 ===================================================================
214 --- src/filed/filed.h   (révision 7288)
215 +++ src/filed/filed.h   (copie de travail)
216 @@ -37,7 +37,11 @@
217  #define FILE_DAEMON 1
218  #ifdef USE_TCADB                     /* hash disk based */
219  # include <tcadb.h>
220 -#else
221 +#endif
222 +#ifdef  USE_DB
223 +# include <db.h>
224 +#endif
225 +#ifdef USE_HTABLE
226  # include "lib/htable.h"
227  #endif
228  #include "filed_conf.h"
229 Index: src/baconfig.h
230 ===================================================================
231 --- src/baconfig.h      (révision 7288)
232 +++ src/baconfig.h      (copie de travail)
233 @@ -113,6 +113,12 @@
234  
235  #endif /* HAVE_WIN32 */
236  
237 +/* Select db backend for accurate mode */
238 +#ifndef USE_TCADB
239 +# ifndef USE_DB
240 +#  define USE_HTABLE
241 +# endif
242 +#endif
243  
244  #ifdef ENABLE_NLS
245     #include <libintl.h>
246 Index: src/win32/build-depkgs-mingw32
247 ===================================================================
248 --- src/win32/build-depkgs-mingw32      (révision 7288)
249 +++ src/win32/build-depkgs-mingw32      (copie de travail)
250 @@ -519,7 +519,7 @@
251     process_cmd_utils
252     process_mkisofs
253     process_dvd_rw_tools
254 -   process_qt4
255 +#   process_qt4
256  else
257     for dependency in "$@"
258     do
259 Index: src/jcr.h
260 ===================================================================
261 --- src/jcr.h   (révision 7288)
262 +++ src/jcr.h   (copie de travail)
263 @@ -344,7 +344,12 @@
264  #ifdef USE_TCADB
265     TCADB *file_list;                  /* Previous file list (accurate mode) */
266     POOLMEM *hash_name;
267 -#else
268 +#endif
269 +#ifdef USE_DB
270 +   DB *file_list;
271 +   POOLMEM *hash_name;
272 +#endif
273 +#ifdef USE_HTABLE
274     htable *file_list;                 /* Previous file list (accurate mode) */
275  #endif
276  #endif /* FILE_DAEMON */