]> git.ozlabs.org Git - ccan/blobdiff - ccan/tdb2/io.c
tdb2: Add stats attribute.
[ccan] / ccan / tdb2 / io.c
index 6c8f847b2b8bb19e29ce482d5a3a82c78779102c..e264940954405dca6e7aea3c57b277e8b9a5b4bb 100644 (file)
@@ -443,7 +443,7 @@ static int tdb_expand_file(struct tdb_context *tdb, tdb_len_t addition)
                   file isn't sparse, which would be very bad if we ran out of
                   disk. This must be done with write, not via mmap */
                memset(buf, 0x43, sizeof(buf));
-               if (fill(tdb, buf, sizeof(buf), tdb->map_size, addition) == -1)
+               if (0 || fill(tdb, buf, sizeof(buf), tdb->map_size, addition) == -1)
                        return -1;
                tdb->map_size += addition;
                tdb_mmap(tdb);
@@ -546,6 +546,12 @@ static void *tdb_direct(struct tdb_context *tdb, tdb_off_t off, size_t len)
        return (char *)tdb->map_ptr + off;
 }
 
+void add_stat_(struct tdb_context *tdb, uint64_t *stat, size_t val)
+{
+       if ((uintptr_t)stat < (uintptr_t)tdb->stats + tdb->stats->size)
+               *stat += val;
+}
+
 static const struct tdb_methods io_methods = {
        tdb_read,
        tdb_write,