From a1dadd9763e69e21dd3f863993032f904eda9d88 Mon Sep 17 00:00:00 2001 From: Zach Brown Date: Tue, 6 Jun 2017 15:35:05 -0700 Subject: [PATCH] scoutfs: lock around dirty item writing Writing dirty items into a segment wasn't protected by locking. It's not racing with item dirtying, bit it's absolutely racing with reads while modifying the rbtree. And shrinking will be modifying the item cache at any old time in the future. Signed-off-by: Zach Brown --- kmod/src/item.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kmod/src/item.c b/kmod/src/item.c index 68895042..b3e9d8f5 100644 --- a/kmod/src/item.c +++ b/kmod/src/item.c @@ -1488,9 +1488,12 @@ int scoutfs_item_dirty_seg(struct super_block *sb, struct scoutfs_segment *seg) struct item_cache *cac = sbi->item_cache; struct cached_item *item = NULL; struct cached_item *del; + unsigned long flags; u32 key_bytes; u32 nr_items; + spin_lock_irqsave(&cac->lock, flags); + count_seg_items(cac, &nr_items, &key_bytes); /* remember nr_items is passed to _first_item */ @@ -1522,6 +1525,8 @@ int scoutfs_item_dirty_seg(struct super_block *sb, struct scoutfs_segment *seg) nr_items--; } + spin_unlock_irqrestore(&cac->lock, flags); + return 0; }