From 5325aff69894db34956769c59244f74727be7b29 Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Sun, 17 Sep 2017 08:48:59 -0700 Subject: [PATCH] scoutfs: add item count update function The item cache maintains a count of the number of dirty items, keys, and values. It updates the counts as it dirties and cleans items. There are callers who want to modify the accounting directly instead of having the accounting updated as a side effect of cleaning and re-dirtying the item. Signed-off-by: Zach Brown --- kmod/src/item.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/kmod/src/item.c b/kmod/src/item.c index 15caddaf..38662a98 100644 --- a/kmod/src/item.c +++ b/kmod/src/item.c @@ -307,6 +307,19 @@ static void update_dirty_parents(struct cached_item *item) scoutfs_item_rb_propagate(rb_parent(&item->node), NULL); } +static void update_dirty_item_counts(struct super_block *sb, signed items, + signed keys, signed vals) +{ + struct scoutfs_sb_info *sbi = SCOUTFS_SB(sb); + struct item_cache *cac = sbi->item_cache; + + cac->nr_dirty_items += items; + cac->dirty_key_bytes += keys; + cac->dirty_val_bytes += vals; + + scoutfs_trans_track_item(sb, items, keys, vals); +} + static void mark_item_dirty(struct super_block *sb, struct item_cache *cac, struct cached_item *item) { @@ -320,11 +333,7 @@ static void mark_item_dirty(struct super_block *sb, struct item_cache *cac, list_del_init(&item->entry); cac->lru_nr--; - cac->nr_dirty_items++; - cac->dirty_key_bytes += item->key->key_len; - cac->dirty_val_bytes += scoutfs_kvec_length(item->val); - - scoutfs_trans_track_item(sb, 1, item->key->key_len, + update_dirty_item_counts(sb, 1, item->key->key_len, scoutfs_kvec_length(item->val)); update_dirty_parents(item); @@ -343,11 +352,7 @@ static void clear_item_dirty(struct super_block *sb, struct item_cache *cac, list_add_tail(&item->entry, &cac->lru_list); cac->lru_nr++; - cac->nr_dirty_items--; - cac->dirty_key_bytes -= item->key->key_len; - cac->dirty_val_bytes -= scoutfs_kvec_length(item->val); - - scoutfs_trans_track_item(sb, -1, -item->key->key_len, + update_dirty_item_counts(sb, -1, -item->key->key_len, -scoutfs_kvec_length(item->val)); WARN_ON_ONCE(cac->nr_dirty_items < 0 || cac->dirty_key_bytes < 0 ||