diff options
author | Kent Overstreet <kmo@daterainc.com> | 2013-11-11 00:55:27 -0500 |
---|---|---|
committer | Kent Overstreet <kmo@daterainc.com> | 2013-11-11 00:55:27 -0500 |
commit | 1fa8455deb92e9ec7756df23030e73b2d28eeca7 (patch) | |
tree | 432564c5f626b36e4cb9f7b8bb5856a251717ab0 | |
parent | f7cb20f03dc6dff1b19942cf3dda6d154c86f29b (diff) |
bcache: Fix dirty_data accounting
Dirty data accounting wasn't quite right - firstly, we were adding the key we're
inserting after it could have merged with another dirty key already in the
btree, and secondly we could sometimes pass the wrong offset to
bcache_dev_sectors_dirty_add() for dirty data we were overwriting - which is
important when tracking dirty data by stripe.
Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Cc: linux-stable <stable@vger.kernel.org> # >= v3.10
-rw-r--r-- | drivers/md/bcache/btree.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c index f42fc7ed9cd6..d1734d9d9c79 100644 --- a/drivers/md/bcache/btree.c +++ b/drivers/md/bcache/btree.c | |||
@@ -1742,6 +1742,9 @@ static bool fix_overlapping_extents(struct btree *b, | |||
1742 | if (bkey_cmp(insert, k) < 0) { | 1742 | if (bkey_cmp(insert, k) < 0) { |
1743 | bch_cut_front(insert, k); | 1743 | bch_cut_front(insert, k); |
1744 | } else { | 1744 | } else { |
1745 | if (bkey_cmp(&START_KEY(insert), &START_KEY(k)) > 0) | ||
1746 | old_offset = KEY_START(insert); | ||
1747 | |||
1745 | if (bkey_written(b, k) && | 1748 | if (bkey_written(b, k) && |
1746 | bkey_cmp(&START_KEY(insert), &START_KEY(k)) <= 0) { | 1749 | bkey_cmp(&START_KEY(insert), &START_KEY(k)) <= 0) { |
1747 | /* | 1750 | /* |
@@ -1803,6 +1806,10 @@ static bool btree_insert_key(struct btree *b, struct btree_op *op, | |||
1803 | if (fix_overlapping_extents(b, k, &iter, op)) | 1806 | if (fix_overlapping_extents(b, k, &iter, op)) |
1804 | return false; | 1807 | return false; |
1805 | 1808 | ||
1809 | if (KEY_DIRTY(k)) | ||
1810 | bcache_dev_sectors_dirty_add(b->c, KEY_INODE(k), | ||
1811 | KEY_START(k), KEY_SIZE(k)); | ||
1812 | |||
1806 | while (m != end(i) && | 1813 | while (m != end(i) && |
1807 | bkey_cmp(k, &START_KEY(m)) > 0) | 1814 | bkey_cmp(k, &START_KEY(m)) > 0) |
1808 | prev = m, m = bkey_next(m); | 1815 | prev = m, m = bkey_next(m); |
@@ -1831,10 +1838,6 @@ static bool btree_insert_key(struct btree *b, struct btree_op *op, | |||
1831 | insert: shift_keys(b, m, k); | 1838 | insert: shift_keys(b, m, k); |
1832 | copy: bkey_copy(m, k); | 1839 | copy: bkey_copy(m, k); |
1833 | merged: | 1840 | merged: |
1834 | if (KEY_DIRTY(k)) | ||
1835 | bcache_dev_sectors_dirty_add(b->c, KEY_INODE(k), | ||
1836 | KEY_START(k), KEY_SIZE(k)); | ||
1837 | |||
1838 | bch_check_keys(b, "%u for %s", status, op_type(op)); | 1841 | bch_check_keys(b, "%u for %s", status, op_type(op)); |
1839 | 1842 | ||
1840 | if (b->level && !KEY_OFFSET(k)) | 1843 | if (b->level && !KEY_OFFSET(k)) |