dbchecker: improve verbose output of do_modify()
[Samba.git] / source3 / lib / gencache.c
blobf566534a1a6601b02065b9435ff358d28e3ced8f
1 /*
2 Unix SMB/CIFS implementation.
4 Generic, persistent and shared between processes cache mechanism for use
5 by various parts of the Samba code
7 Copyright (C) Rafal Szczesniak 2002
8 Copyright (C) Volker Lendecke 2009
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "includes.h"
25 #include "lib/gencache.h"
26 #include "system/filesys.h"
27 #include "system/glob.h"
28 #include "util_tdb.h"
29 #include "tdb_wrap/tdb_wrap.h"
31 #undef DBGC_CLASS
32 #define DBGC_CLASS DBGC_TDB
34 #define CACHE_DATA_FMT "%12u/"
36 static struct tdb_wrap *cache;
37 static struct tdb_wrap *cache_notrans;
39 /**
40 * @file gencache.c
41 * @brief Generic, persistent and shared between processes cache mechanism
42 * for use by various parts of the Samba code
44 **/
46 struct gencache_timeout {
47 time_t timeout;
50 bool gencache_timeout_expired(const struct gencache_timeout *t)
52 return t->timeout <= time(NULL);
55 /**
56 * Cache initialisation function. Opens cache tdb file or creates
57 * it if does not exist.
59 * @return true on successful initialisation of the cache or
60 * false on failure
61 **/
63 static bool gencache_init(void)
65 char* cache_fname = NULL;
66 int open_flags = O_RDWR|O_CREAT;
67 int hash_size;
69 /* skip file open if it's already opened */
70 if (cache) {
71 return true;
74 hash_size = lp_parm_int(-1, "gencache", "hash_size", 10000);
76 cache_fname = cache_path(talloc_tos(), "gencache.tdb");
77 if (cache_fname == NULL) {
78 return false;
81 DEBUG(5, ("Opening cache file at %s\n", cache_fname));
83 cache = tdb_wrap_open(NULL, cache_fname, hash_size,
84 TDB_DEFAULT|TDB_INCOMPATIBLE_HASH,
85 open_flags, 0644);
87 if (!cache && (errno == EACCES)) {
88 open_flags = O_RDONLY;
89 cache = tdb_wrap_open(NULL, cache_fname, hash_size,
90 TDB_DEFAULT|TDB_INCOMPATIBLE_HASH,
91 open_flags, 0644);
92 if (cache) {
93 DEBUG(5, ("gencache_init: Opening cache file %s read-only.\n", cache_fname));
96 TALLOC_FREE(cache_fname);
98 if (!cache) {
99 DEBUG(5, ("Attempt to open gencache.tdb has failed.\n"));
100 return false;
103 cache_fname = lock_path(talloc_tos(), "gencache_notrans.tdb");
104 if (cache_fname == NULL) {
105 TALLOC_FREE(cache);
106 return false;
109 DEBUG(5, ("Opening cache file at %s\n", cache_fname));
111 cache_notrans = tdb_wrap_open(NULL, cache_fname, hash_size,
112 TDB_CLEAR_IF_FIRST|
113 TDB_INCOMPATIBLE_HASH|
114 TDB_NOSYNC|
115 TDB_MUTEX_LOCKING,
116 open_flags, 0644);
117 if (cache_notrans == NULL) {
118 DEBUG(5, ("Opening %s failed: %s\n", cache_fname,
119 strerror(errno)));
120 TALLOC_FREE(cache_fname);
121 TALLOC_FREE(cache);
122 return false;
124 TALLOC_FREE(cache_fname);
126 return true;
129 static TDB_DATA last_stabilize_key(void)
131 const char key[] = "@LAST_STABILIZED";
133 return (TDB_DATA) {
134 .dptr = discard_const_p(uint8_t, key),
135 .dsize = sizeof(key),
139 struct gencache_have_val_state {
140 time_t new_timeout;
141 const DATA_BLOB *data;
142 bool gotit;
145 static void gencache_have_val_parser(const struct gencache_timeout *old_timeout,
146 DATA_BLOB data,
147 void *private_data)
149 struct gencache_have_val_state *state =
150 (struct gencache_have_val_state *)private_data;
151 time_t now = time(NULL);
152 int cache_time_left, new_time_left, additional_time;
155 * Excuse the many variables, but these time calculations are
156 * confusing to me. We do not want to write to gencache with a
157 * possibly expensive transaction if we are about to write the same
158 * value, just extending the remaining timeout by less than 10%.
161 cache_time_left = old_timeout->timeout - now;
162 if (cache_time_left <= 0) {
164 * timed out, write new value
166 return;
169 new_time_left = state->new_timeout - now;
170 if (new_time_left <= 0) {
172 * Huh -- no new timeout?? Write it.
174 return;
177 if (new_time_left < cache_time_left) {
179 * Someone wants to shorten the timeout. Let it happen.
181 return;
185 * By how much does the new timeout extend the remaining cache time?
187 additional_time = new_time_left - cache_time_left;
189 if (additional_time * 10 < 0) {
191 * Integer overflow. We extend by so much that we have to write it.
193 return;
197 * The comparison below is essentially equivalent to
199 * new_time_left > cache_time_left * 1.10
201 * but without floating point calculations.
204 if (additional_time * 10 > cache_time_left) {
206 * We extend the cache timeout by more than 10%. Do it.
208 return;
212 * Now the more expensive data compare.
214 if (data_blob_cmp(state->data, &data) != 0) {
216 * Write a new value. Certainly do it.
218 return;
222 * Extending the timeout by less than 10% for the same cache value is
223 * not worth the trouble writing a value into gencache under a
224 * possibly expensive transaction.
226 state->gotit = true;
229 static bool gencache_have_val(const char *keystr, const DATA_BLOB *data,
230 time_t timeout)
232 struct gencache_have_val_state state;
234 state.new_timeout = timeout;
235 state.data = data;
236 state.gotit = false;
238 if (!gencache_parse(keystr, gencache_have_val_parser, &state)) {
239 return false;
241 return state.gotit;
244 static int last_stabilize_parser(TDB_DATA key, TDB_DATA data,
245 void *private_data)
247 time_t *last_stabilize = private_data;
249 if ((data.dsize != 0) && (data.dptr[data.dsize-1] == '\0')) {
250 *last_stabilize = atoi((char *)data.dptr);
252 return 0;
256 * Set an entry in the cache file. If there's no such
257 * one, then add it.
259 * @param keystr string that represents a key of this entry
260 * @param blob DATA_BLOB value being cached
261 * @param timeout time when the value is expired
263 * @retval true when entry is successfully stored
264 * @retval false on failure
267 bool gencache_set_data_blob(const char *keystr, DATA_BLOB blob,
268 time_t timeout)
270 TDB_DATA key;
271 int ret;
272 fstring hdr;
273 int hdr_len;
274 time_t last_stabilize;
275 static int writecount;
276 TDB_DATA dbufs[2];
278 if ((keystr == NULL) || (blob.data == NULL)) {
279 return false;
282 key = string_term_tdb_data(keystr);
284 ret = tdb_data_cmp(key, last_stabilize_key());
285 if (ret == 0) {
286 DEBUG(10, ("Can't store %s as a key\n", keystr));
287 return false;
290 if (!gencache_init()) {
291 return false;
294 if ((timeout != 0) && gencache_have_val(keystr, &blob, timeout)) {
295 DEBUG(10, ("Did not store value for %s, we already got it\n",
296 keystr));
297 return true;
300 hdr_len = fstr_sprintf(hdr, CACHE_DATA_FMT, (int)timeout);
302 if (hdr_len == -1) {
303 return false;
306 dbufs[0] = (TDB_DATA) { .dptr = (uint8_t *)hdr, .dsize = hdr_len };
307 dbufs[1] = (TDB_DATA) { .dptr = blob.data, .dsize = blob.length };
309 DEBUG(10, ("Adding cache entry with key=[%s] and timeout="
310 "[%s] (%d seconds %s)\n", keystr,
311 timestring(talloc_tos(), timeout),
312 (int)(timeout - time(NULL)),
313 timeout > time(NULL) ? "ahead" : "in the past"));
315 ret = tdb_storev(cache_notrans->tdb, key, dbufs, 2, 0);
316 if (ret != 0) {
317 return false;
321 * Every 100 writes within a single process, stabilize the cache with
322 * a transaction. This is done to prevent a single transaction to
323 * become huge and chew lots of memory.
325 writecount += 1;
326 if (writecount > lp_parm_int(-1, "gencache", "stabilize_count", 100)) {
327 gencache_stabilize();
328 writecount = 0;
329 goto done;
333 * Every 5 minutes, call gencache_stabilize() to not let grow
334 * gencache_notrans.tdb too large.
337 last_stabilize = 0;
339 tdb_parse_record(cache_notrans->tdb, last_stabilize_key(),
340 last_stabilize_parser, &last_stabilize);
342 if ((last_stabilize
343 + lp_parm_int(-1, "gencache", "stabilize_interval", 300))
344 < time(NULL)) {
345 gencache_stabilize();
348 done:
349 return ret == 0;
352 static void gencache_del_parser(const struct gencache_timeout *t,
353 DATA_BLOB blob,
354 void *private_data)
356 if (t->timeout != 0) {
357 bool *exists = private_data;
358 *exists = true;
363 * Delete one entry from the cache file.
365 * @param keystr string that represents a key of this entry
367 * @retval true upon successful deletion
368 * @retval false in case of failure
371 bool gencache_del(const char *keystr)
373 TDB_DATA key = string_term_tdb_data(keystr);
374 bool exists = false;
375 bool result = false;
376 int ret;
378 if (keystr == NULL) {
379 return false;
382 if (!gencache_init()) {
383 return false;
386 DEBUG(10, ("Deleting cache entry (key=[%s])\n", keystr));
388 ret = tdb_chainlock(cache_notrans->tdb, key);
389 if (ret == -1) {
390 return false;
393 gencache_parse(keystr, gencache_del_parser, &exists);
395 if (exists) {
397 * We delete an element by setting its timeout to
398 * 0. This way we don't have to do a transaction on
399 * gencache.tdb every time we delete an element.
401 result = gencache_set(keystr, "", 0);
404 tdb_chainunlock(cache_notrans->tdb, key);
406 return result;
409 static bool gencache_pull_timeout(TDB_DATA data, time_t *pres, DATA_BLOB *payload)
411 time_t res;
412 char *slash = NULL;
413 char *endptr;
415 if (data.dptr == NULL) {
416 return false;
418 slash = memchr(data.dptr, '/', data.dsize);
419 if (slash == NULL) {
420 return false;
423 res = strtol((char *)data.dptr, &endptr, 10);
425 if ((endptr == NULL) || (*endptr != '/')) {
426 DBG_WARNING("Invalid gencache data format\n");
427 return false;
429 if (pres != NULL) {
430 *pres = res;
432 if (payload != NULL) {
433 endptr += 1;
434 *payload = (DATA_BLOB) {
435 .data = discard_const_p(uint8_t, endptr),
436 .length = data.dsize - PTR_DIFF(endptr, data.dptr),
439 return true;
442 struct gencache_parse_state {
443 void (*parser)(const struct gencache_timeout *timeout,
444 DATA_BLOB blob,
445 void *private_data);
446 void *private_data;
447 bool copy_to_notrans;
450 static int gencache_parse_fn(TDB_DATA key, TDB_DATA data, void *private_data)
452 struct gencache_parse_state *state;
453 struct gencache_timeout t;
454 DATA_BLOB payload;
455 bool ret;
457 ret = gencache_pull_timeout(data, &t.timeout, &payload);
458 if (!ret) {
459 return -1;
461 state = (struct gencache_parse_state *)private_data;
462 state->parser(&t, payload, state->private_data);
464 if (state->copy_to_notrans) {
465 tdb_store(cache_notrans->tdb, key, data, 0);
468 return 0;
471 bool gencache_parse(const char *keystr,
472 void (*parser)(const struct gencache_timeout *timeout,
473 DATA_BLOB blob,
474 void *private_data),
475 void *private_data)
477 struct gencache_parse_state state;
478 TDB_DATA key = string_term_tdb_data(keystr);
479 int ret;
481 if (keystr == NULL) {
482 return false;
484 if (tdb_data_cmp(key, last_stabilize_key()) == 0) {
485 return false;
487 if (!gencache_init()) {
488 return false;
491 state.parser = parser;
492 state.private_data = private_data;
493 state.copy_to_notrans = false;
495 ret = tdb_chainlock(cache_notrans->tdb, key);
496 if (ret != 0) {
497 return false;
500 ret = tdb_parse_record(cache_notrans->tdb, key,
501 gencache_parse_fn, &state);
502 if (ret == 0) {
503 tdb_chainunlock(cache_notrans->tdb, key);
504 return true;
507 state.copy_to_notrans = true;
509 ret = tdb_parse_record(cache->tdb, key, gencache_parse_fn, &state);
511 if ((ret == -1) && (tdb_error(cache->tdb) == TDB_ERR_NOEXIST)) {
513 * The record does not exist. Set a delete-marker in
514 * gencache_notrans, so that we don't have to look at
515 * the fcntl-based cache again.
517 gencache_set(keystr, "", 0);
520 tdb_chainunlock(cache_notrans->tdb, key);
522 return (ret == 0);
525 struct gencache_get_data_blob_state {
526 TALLOC_CTX *mem_ctx;
527 DATA_BLOB *blob;
528 time_t timeout;
529 bool result;
532 static void gencache_get_data_blob_parser(const struct gencache_timeout *t,
533 DATA_BLOB blob,
534 void *private_data)
536 struct gencache_get_data_blob_state *state =
537 (struct gencache_get_data_blob_state *)private_data;
539 if (t->timeout == 0) {
540 state->result = false;
541 return;
543 state->timeout = t->timeout;
545 if (state->blob == NULL) {
546 state->result = true;
547 return;
550 *state->blob = data_blob_talloc(state->mem_ctx, blob.data,
551 blob.length);
552 if (state->blob->data == NULL) {
553 state->result = false;
554 return;
556 state->result = true;
560 * Get existing entry from the cache file.
562 * @param keystr string that represents a key of this entry
563 * @param blob DATA_BLOB that is filled with entry's blob
564 * @param timeout pointer to a time_t that is filled with entry's
565 * timeout
567 * @retval true when entry is successfully fetched
568 * @retval false for failure
571 bool gencache_get_data_blob(const char *keystr, TALLOC_CTX *mem_ctx,
572 DATA_BLOB *blob,
573 time_t *timeout, bool *was_expired)
575 struct gencache_get_data_blob_state state;
576 bool expired = false;
578 state.result = false;
579 state.mem_ctx = mem_ctx;
580 state.blob = blob;
582 if (!gencache_parse(keystr, gencache_get_data_blob_parser, &state)) {
583 goto fail;
585 if (!state.result) {
586 goto fail;
588 if (state.timeout <= time(NULL)) {
590 * We're expired, delete the entry. We can't use gencache_del
591 * here, because that uses gencache_get_data_blob for checking
592 * the existence of a record. We know the thing exists and
593 * directly store an empty value with 0 timeout.
595 gencache_set(keystr, "", 0);
596 expired = true;
597 goto fail;
599 if (timeout) {
600 *timeout = state.timeout;
603 return true;
605 fail:
606 if (was_expired != NULL) {
607 *was_expired = expired;
609 if (state.result && state.blob) {
610 data_blob_free(state.blob);
612 return false;
615 struct stabilize_state {
616 bool written;
618 static int stabilize_fn(struct tdb_context *tdb, TDB_DATA key, TDB_DATA val,
619 void *priv);
622 * Stabilize gencache
624 * Migrate the clear-if-first gencache data to the stable,
625 * transaction-based gencache.tdb
628 bool gencache_stabilize(void)
630 struct stabilize_state state;
631 int res;
632 char *now;
634 if (!gencache_init()) {
635 return false;
638 res = tdb_transaction_start_nonblock(cache->tdb);
639 if (res != 0) {
640 if (tdb_error(cache->tdb) == TDB_ERR_NOLOCK)
643 * Someone else already does the stabilize,
644 * this does not have to be done twice
646 return true;
649 DEBUG(10, ("Could not start transaction on gencache.tdb: "
650 "%s\n", tdb_errorstr(cache->tdb)));
651 return false;
654 res = tdb_lockall_nonblock(cache_notrans->tdb);
655 if (res != 0) {
656 tdb_transaction_cancel(cache->tdb);
657 DEBUG(10, ("Could not get allrecord lock on "
658 "gencache_notrans.tdb: %s\n",
659 tdb_errorstr(cache_notrans->tdb)));
660 return false;
663 state.written = false;
665 res = tdb_traverse(cache_notrans->tdb, stabilize_fn, &state);
666 if (res < 0) {
667 tdb_unlockall(cache_notrans->tdb);
668 tdb_transaction_cancel(cache->tdb);
669 return false;
672 if (!state.written) {
673 tdb_unlockall(cache_notrans->tdb);
674 tdb_transaction_cancel(cache->tdb);
675 return true;
678 res = tdb_transaction_commit(cache->tdb);
679 if (res != 0) {
680 DEBUG(10, ("tdb_transaction_commit on gencache.tdb failed: "
681 "%s\n", tdb_errorstr(cache->tdb)));
682 tdb_unlockall(cache_notrans->tdb);
683 return false;
686 res = tdb_wipe_all(cache_notrans->tdb);
687 if (res < 0) {
688 DBG_DEBUG("tdb_wipe_all on gencache_notrans.tdb failed: %s\n",
689 tdb_errorstr(cache_notrans->tdb));
692 now = talloc_asprintf(talloc_tos(), "%d", (int)time(NULL));
693 if (now != NULL) {
694 tdb_store(cache_notrans->tdb, last_stabilize_key(),
695 string_term_tdb_data(now), 0);
696 TALLOC_FREE(now);
699 res = tdb_unlockall(cache_notrans->tdb);
700 if (res != 0) {
701 DEBUG(10, ("tdb_unlockall on gencache.tdb failed: "
702 "%s\n", tdb_errorstr(cache->tdb)));
703 return false;
706 return true;
709 static int stabilize_fn(struct tdb_context *tdb, TDB_DATA key, TDB_DATA val,
710 void *priv)
712 struct stabilize_state *state = (struct stabilize_state *)priv;
713 int res;
714 time_t timeout;
716 if (tdb_data_cmp(key, last_stabilize_key()) == 0) {
717 return 0;
720 if (!gencache_pull_timeout(val, &timeout, NULL)) {
721 DEBUG(10, ("Ignoring invalid entry\n"));
722 return 0;
724 if ((timeout < time(NULL)) || (val.dsize == 0)) {
725 res = tdb_delete(cache->tdb, key);
726 if (res == 0) {
727 state->written = true;
728 } else if (tdb_error(cache->tdb) == TDB_ERR_NOEXIST) {
729 res = 0;
731 } else {
732 res = tdb_store(cache->tdb, key, val, 0);
733 if (res == 0) {
734 state->written = true;
738 if (res != 0) {
739 DEBUG(10, ("Transfer to gencache.tdb failed: %s\n",
740 tdb_errorstr(cache->tdb)));
741 return -1;
744 return 0;
748 * Get existing entry from the cache file.
750 * @param keystr string that represents a key of this entry
751 * @param valstr buffer that is allocated and filled with the entry value
752 * buffer's disposing must be done outside
753 * @param timeout pointer to a time_t that is filled with entry's
754 * timeout
756 * @retval true when entry is successfully fetched
757 * @retval false for failure
760 bool gencache_get(const char *keystr, TALLOC_CTX *mem_ctx, char **value,
761 time_t *ptimeout)
763 DATA_BLOB blob;
764 bool ret = false;
766 ret = gencache_get_data_blob(keystr, mem_ctx, &blob, ptimeout, NULL);
767 if (!ret) {
768 return false;
770 if ((blob.data == NULL) || (blob.length == 0)) {
771 data_blob_free(&blob);
772 return false;
774 if (blob.data[blob.length-1] != '\0') {
775 /* Not NULL terminated, can't be a string */
776 data_blob_free(&blob);
777 return false;
779 if (value) {
781 * talloc_move generates a type-punned warning here. As we
782 * leave the function immediately, do a simple talloc_steal.
784 *value = (char *)talloc_steal(mem_ctx, blob.data);
785 return true;
787 data_blob_free(&blob);
788 return true;
792 * Set an entry in the cache file. If there's no such
793 * one, then add it.
795 * @param keystr string that represents a key of this entry
796 * @param value text representation value being cached
797 * @param timeout time when the value is expired
799 * @retval true when entry is successfully stored
800 * @retval false on failure
803 bool gencache_set(const char *keystr, const char *value, time_t timeout)
805 DATA_BLOB blob = data_blob_const(value, strlen(value)+1);
806 return gencache_set_data_blob(keystr, blob, timeout);
809 struct gencache_iterate_blobs_state {
810 void (*fn)(const char *key, DATA_BLOB value,
811 time_t timeout, void *private_data);
812 const char *pattern;
813 void *private_data;
814 bool in_persistent;
817 static int gencache_iterate_blobs_fn(struct tdb_context *tdb, TDB_DATA key,
818 TDB_DATA data, void *priv)
820 struct gencache_iterate_blobs_state *state =
821 (struct gencache_iterate_blobs_state *)priv;
822 char *keystr;
823 char *free_key = NULL;
824 time_t timeout;
825 DATA_BLOB payload;
827 if (tdb_data_cmp(key, last_stabilize_key()) == 0) {
828 return 0;
830 if (state->in_persistent && tdb_exists(cache_notrans->tdb, key)) {
831 return 0;
834 if (key.dptr[key.dsize-1] == '\0') {
835 keystr = (char *)key.dptr;
836 } else {
837 /* ensure 0-termination */
838 keystr = talloc_strndup(talloc_tos(), (char *)key.dptr, key.dsize);
839 free_key = keystr;
840 if (keystr == NULL) {
841 goto done;
845 if (!gencache_pull_timeout(data, &timeout, &payload)) {
846 goto done;
849 if (timeout == 0) {
850 /* delete marker */
851 goto done;
854 if (fnmatch(state->pattern, keystr, 0) != 0) {
855 goto done;
858 DEBUG(10, ("Calling function with arguments "
859 "(key=[%s], timeout=[%s])\n",
860 keystr, timestring(talloc_tos(), timeout)));
862 state->fn(keystr, payload, timeout, state->private_data);
864 done:
865 TALLOC_FREE(free_key);
866 return 0;
869 void gencache_iterate_blobs(void (*fn)(const char *key, DATA_BLOB value,
870 time_t timeout, void *private_data),
871 void *private_data, const char *pattern)
873 struct gencache_iterate_blobs_state state;
875 if ((fn == NULL) || (pattern == NULL) || !gencache_init()) {
876 return;
879 DEBUG(5, ("Searching cache keys with pattern %s\n", pattern));
881 state.fn = fn;
882 state.pattern = pattern;
883 state.private_data = private_data;
885 state.in_persistent = false;
886 tdb_traverse(cache_notrans->tdb, gencache_iterate_blobs_fn, &state);
888 state.in_persistent = true;
889 tdb_traverse(cache->tdb, gencache_iterate_blobs_fn, &state);
893 * Iterate through all entries which key matches to specified pattern
895 * @param fn pointer to the function that will be supplied with each single
896 * matching cache entry (key, value and timeout) as an arguments
897 * @param data void pointer to an arbitrary data that is passed directly to the fn
898 * function on each call
899 * @param keystr_pattern pattern the existing entries' keys are matched to
903 struct gencache_iterate_state {
904 void (*fn)(const char *key, const char *value, time_t timeout,
905 void *priv);
906 void *private_data;
909 static void gencache_iterate_fn(const char *key, DATA_BLOB value,
910 time_t timeout, void *private_data)
912 struct gencache_iterate_state *state =
913 (struct gencache_iterate_state *)private_data;
914 char *valstr;
915 char *free_val = NULL;
917 if (value.data[value.length-1] == '\0') {
918 valstr = (char *)value.data;
919 } else {
920 /* ensure 0-termination */
921 valstr = talloc_strndup(talloc_tos(), (char *)value.data, value.length);
922 free_val = valstr;
923 if (valstr == NULL) {
924 goto done;
928 DEBUG(10, ("Calling function with arguments "
929 "(key=[%s], value=[%s], timeout=[%s])\n",
930 key, valstr, timestring(talloc_tos(), timeout)));
932 state->fn(key, valstr, timeout, state->private_data);
934 done:
936 TALLOC_FREE(free_val);
939 void gencache_iterate(void (*fn)(const char *key, const char *value,
940 time_t timeout, void *dptr),
941 void *private_data, const char *pattern)
943 struct gencache_iterate_state state;
945 if (fn == NULL) {
946 return;
948 state.fn = fn;
949 state.private_data = private_data;
950 gencache_iterate_blobs(gencache_iterate_fn, &state, pattern);