1 Index: src/filed/accurate.c
2 ===================================================================
3 --- src/filed/accurate.c (revision 7617)
4 +++ src/filed/accurate.c (working copy)
9 -static int dbglvl=200;
12 typedef struct PrivateCurFile {
16 - char *fname; /* not stored with tchdb mode */
25 -static void realfree(void *p); /* used by tokyo code */
28 - * Update hash element seen=1
30 -static bool accurate_mark_file_as_seen(JCR *jcr, CurFile *elt)
31 +static int my_cmp(void *item1, void *item2)
36 - if (!tcadbput(jcr->file_list,
37 - elt->fname, strlen(elt->fname)+1,
38 - elt, sizeof(CurFile)))
39 - { /* TODO: disabling accurate mode ? */
40 - Jmsg(jcr, M_ERROR, 1, _("Can't update accurate hash disk\n"));
45 + CurFile *elt1, *elt2;
46 + elt1 = (CurFile *) item1;
47 + elt2 = (CurFile *) item2;
48 + return strcmp(elt1->fname, elt2->fname);
51 -static bool accurate_lookup(JCR *jcr, char *fname, CurFile *ret)
52 +static bool accurate_mark_file_as_seen(JCR *jcr, CurFile *elt)
59 - elt = (CurFile*)tcadbget(jcr->file_list,
60 - fname, strlen(fname)+1, &size);
63 - /* TODO: don't malloc/free results */
66 - memcpy(ret, elt, sizeof(CurFile));
68 -// Dmsg1(dbglvl, "lookup <%s> ok\n", fname);
69 + /* TODO: just use elt->seen = 1 */
70 + CurFile *temp = (CurFile *)jcr->file_list->search(elt, my_cmp);
72 + temp->seen = 1; /* records are in memory */
77 -/* Create tokyo dbm hash file
78 - * If something goes wrong, we cancel accurate mode.
80 -static bool accurate_init(JCR *jcr, int nbfile)
82 - jcr->file_list = tcadbnew();
84 -// tchdbsetcache(jcr->file_list, 300000);
85 -// tchdbtune(jcr->file_list,
86 -// nbfile, /* nb bucket 0.5n to 4n */
87 -// 6, /* size of element 2^x */
89 -// 0); /* options like compression */
91 - jcr->hash_name = get_pool_memory(PM_MESSAGE);
92 - POOLMEM *temp = get_pool_memory(PM_MESSAGE);
94 - if (nbfile > 500000) {
95 - make_unique_filename(&jcr->hash_name, jcr->JobId, "accurate");
96 - pm_strcat(jcr->hash_name, ".tcb");
97 - Mmsg(temp, "%s#bnum=%i#mode=e#opts=l",
98 - jcr->hash_name, nbfile*4);
99 - Dmsg1(dbglvl, "Doing accurate hash on disk %s\n", jcr->hash_name);
101 - Dmsg0(dbglvl, "Doing accurate hash on memory\n");
102 - pm_strcpy(jcr->hash_name, "*");
103 - pm_strcpy(temp, "*");
106 - if(!tcadbopen(jcr->file_list, jcr->hash_name)){
107 - Jmsg(jcr, M_ERROR, 1, _("Can't open accurate hash disk\n"));
108 - Jmsg(jcr, M_INFO, 1, _("Disabling accurate mode\n"));
109 - tcadbdel(jcr->file_list);
110 - jcr->file_list = NULL;
111 - jcr->accurate = false;
113 - free_pool_memory(temp);
114 - return jcr->file_list != NULL;
117 -/* This function is called at the end of backup
118 - * We walk over all hash disk element, and we check
121 -bool accurate_send_deleted_list(JCR *jcr)
127 - int stream = STREAM_UNIX_ATTRIBUTES;
129 - if (!jcr->accurate || jcr->get_JobLevel() == L_FULL) {
133 - if (jcr->file_list == NULL) {
137 - ff_pkt = init_find_files();
138 - ff_pkt->type = FT_DELETED;
140 - /* traverse records */
141 - tcadbiterinit(jcr->file_list);
142 - while((key = tcadbiternext2(jcr->file_list)) != NULL) {
143 - elt = (CurFile *) tcadbget(jcr->file_list,
144 - key, strlen(key)+1, &size);
147 - if (!elt->seen) { /* already seen */
148 - ff_pkt->fname = key;
149 - ff_pkt->statp.st_mtime = elt->mtime;
150 - ff_pkt->statp.st_ctime = elt->ctime;
151 - encode_and_send_attributes(jcr, ff_pkt, stream);
155 - realfree(key); /* tokyo cabinet have to use real free() */
158 - term_find_files(ff_pkt);
160 - /* TODO: clean htable when this function is not reached ? */
161 - if (jcr->file_list) {
162 - if(!tcadbclose(jcr->file_list)){
163 - Jmsg(jcr, M_ERROR, 1, _("Can't close accurate hash disk\n"));
166 - /* delete the object */
167 - tcadbdel(jcr->file_list);
168 - if (!bstrcmp(jcr->hash_name, "*")) {
169 - unlink(jcr->hash_name);
172 - free_pool_memory(jcr->hash_name);
173 - jcr->hash_name = NULL;
174 - jcr->file_list = NULL;
179 -#else /* HTABLE mode */
181 -static bool accurate_mark_file_as_seen(JCR *jcr, CurFile *elt)
183 - CurFile *temp = (CurFile *)jcr->file_list->lookup(elt->fname);
184 - temp->seen = 1; /* records are in memory */
188 static bool accurate_lookup(JCR *jcr, char *fname, CurFile *ret)
193 - CurFile *temp = (CurFile *)jcr->file_list->lookup(fname);
195 + search.fname = fname;
196 + CurFile *temp = (CurFile *)jcr->file_list->search(&search, my_cmp);
198 memcpy(ret, temp, sizeof(CurFile));
200 -// Dmsg1(dbglvl, "lookup <%s> ok\n", fname);
201 + Dmsg1(dbglvl, "lookup <%s> ok\n", fname);
206 static bool accurate_init(JCR *jcr, int nbfile)
209 - jcr->file_list = (htable *)malloc(sizeof(htable));
210 - jcr->file_list->init(elt, &elt->link, nbfile);
211 + jcr->file_list = New(rblist(elt, &elt->link));
216 ff_pkt = init_find_files();
217 ff_pkt->type = FT_DELETED;
219 - foreach_htable(elt, jcr->file_list) {
220 + foreach_rblist(elt, jcr->file_list) {
221 if (!elt->seen) { /* already seen */
222 Dmsg2(dbglvl, "deleted fname=%s seen=%i\n", elt->fname, elt->seen);
223 ff_pkt->fname = elt->fname;
224 @@ -258,15 +121,12 @@
226 /* TODO: clean htable when this function is not reached ? */
227 if (jcr->file_list) {
228 - jcr->file_list->destroy();
229 - free(jcr->file_list);
230 + delete jcr->file_list;
231 jcr->file_list = NULL;
236 -#endif /* common code */
238 static bool accurate_add_file(JCR *jcr, char *fname, char *lstat)
241 @@ -278,25 +138,15 @@
242 elt.mtime = statp.st_mtime;
246 - if (!tcadbput(jcr->file_list,
247 - fname, strlen(fname)+1,
248 - &elt, sizeof(CurFile)))
250 - Jmsg(jcr, M_ERROR, 1, _("Can't update accurate hash disk ERR=%s\n"));
255 /* we store CurFile, fname and ctime/mtime in the same chunk */
256 - item = (CurFile *)jcr->file_list->hash_malloc(sizeof(CurFile)+strlen(fname)+1);
257 + item = (CurFile *)malloc(sizeof(CurFile)+strlen(fname)+1);
258 memcpy(item, &elt, sizeof(CurFile));
259 item->fname = (char *)item+sizeof(CurFile);
260 strcpy(item->fname, fname);
261 - jcr->file_list->insert(item->fname, item);
263 + jcr->file_list->insert(item, my_cmp);
265 -// Dmsg2(dbglvl, "add fname=<%s> lstat=%s\n", fname, lstat);
266 + Dmsg2(dbglvl, "add fname=<%s> lstat=%s\n", fname, lstat);
278 - * Tokyo Cabinet library doesn't use smartalloc by default
279 - * results need to be released with real free()
282 -void realfree(void *p)
289 ===================================================================
290 --- src/jcr.h (revision 7618)
291 +++ src/jcr.h (working copy)
293 CRYPTO_CTX crypto; /* Crypto ctx */
294 DIRRES* director; /* Director resource */
295 bool VSS; /* VSS used by FD */
297 - TCADB *file_list; /* Previous file list (accurate mode) */
298 - POOLMEM *hash_name;
300 - htable *file_list; /* Previous file list (accurate mode) */
302 + rblist *file_list; /* Previous file list (accurate mode) */
303 #endif /* FILE_DAEMON */