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 <zab@versity.com>
This commit is contained in:
Zach Brown
2017-06-06 15:35:05 -07:00
parent 1652512af7
commit a1dadd9763
+5
View File
@@ -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;
}