aboutsummaryrefslogtreecommitdiff
path: root/lib/util
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-07-21 13:30:34 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-07-21 13:30:34 +0200
commit321290241e84a3a2cfc30b65fc6e79ecd266e420 (patch)
tree1a12686dd3ea7afe0d6e6d93fac3440d2c70bd8d /lib/util
parent1bb19e4e6980019d0e4ac348f99d9d2cf0074d6b (diff)
Keep track of xattr key & value references AFTER deduplication
This commit adds a reference count functionality to the string table implementation and uses this functionality in the fstree code to count how often each key and value is referenced by the deduplicated Xattr blocks. This is needed to support deduplication through out-of-band storage of xattrs. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/util')
-rw-r--r--lib/util/str_table.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/util/str_table.c b/lib/util/str_table.c
index a9d91e5..72579ce 100644
--- a/lib/util/str_table.c
+++ b/lib/util/str_table.c
@@ -128,3 +128,49 @@ const char *str_table_get_string(str_table_t *table, size_t index)
return table->strings[index];
}
+
+static str_bucket_t *bucket_by_index(str_table_t *table, size_t index)
+{
+ str_bucket_t *bucket = NULL;
+ uint32_t hash;
+
+ if (index < table->num_strings) {
+ hash = strhash(table->strings[index]);
+ bucket = table->buckets[hash % table->num_buckets];
+
+ while (bucket != NULL && bucket->index != index)
+ bucket = bucket->next;
+ }
+
+ return bucket;
+}
+
+void str_table_reset_ref_count(str_table_t *table)
+{
+ str_bucket_t *bucket;
+ size_t i;
+
+ for (i = 0; i < table->num_buckets; ++i) {
+ bucket = table->buckets[i];
+
+ while (bucket != NULL) {
+ bucket->refcount = 0;
+ bucket = bucket->next;
+ }
+ }
+}
+
+void str_table_add_ref(str_table_t *table, size_t index)
+{
+ str_bucket_t *bucket = bucket_by_index(table, index);
+
+ if (bucket != NULL && bucket->refcount < ~((size_t)0))
+ bucket->refcount += 1;
+}
+
+size_t str_table_get_ref_count(str_table_t *table, size_t index)
+{
+ str_bucket_t *bucket = bucket_by_index(table, index);
+
+ return bucket != NULL ? bucket->refcount : 0;
+}