Upstream SHA1 d24a6e1087030b6da286df9433add5fa2f21b83b

This patch is bigger than the original, because some of the fixes in 3.12 ended
up in the wrong patches.

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 <[email protected]>
Cc: linux-stable <[email protected]> # >= v3.10

Conflicts:
        drivers/md/bcache/btree.c

Signed-off-by: Kent Overstreet <[email protected]>
---
 drivers/md/bcache/btree.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c
index 8c8aa484fb..bdf2af992e 100644
--- a/drivers/md/bcache/btree.c
+++ b/drivers/md/bcache/btree.c
@@ -1694,7 +1694,8 @@ static bool fix_overlapping_extents(struct btree *b,
                        if (KEY_START(k) > KEY_START(insert) + sectors_found)
                                goto check_failed;
 
-                       if (KEY_PTRS(&op->replace) != KEY_PTRS(k))
+                       if (KEY_PTRS(k) != KEY_PTRS(&op->replace) ||
+                           KEY_DIRTY(k) != KEY_DIRTY(&op->replace))
                                goto check_failed;
 
                        /* skip past gen */
@@ -1754,6 +1755,9 @@ static bool fix_overlapping_extents(struct btree *b,
                if (bkey_cmp(insert, k) < 0) {
                        bch_cut_front(insert, k);
                } else {
+                       if (bkey_cmp(&START_KEY(insert), &START_KEY(k)) > 0)
+                               old_offset = KEY_START(insert);
+
                        if (bkey_written(b, k) &&
                            bkey_cmp(&START_KEY(insert), &START_KEY(k)) <= 0) {
                                /*
@@ -1815,6 +1819,10 @@ static bool btree_insert_key(struct btree *b, struct 
btree_op *op,
                if (fix_overlapping_extents(b, k, &iter, op))
                        return false;
 
+               if (KEY_DIRTY(k))
+                       bcache_dev_sectors_dirty_add(b->c, KEY_INODE(k),
+                                                    KEY_START(k), KEY_SIZE(k));
+
                while (m != end(i) &&
                       bkey_cmp(k, &START_KEY(m)) > 0)
                        prev = m, m = bkey_next(m);
@@ -1843,10 +1851,6 @@ static bool btree_insert_key(struct btree *b, struct 
btree_op *op,
 insert:        shift_keys(b, m, k);
 copy:  bkey_copy(m, k);
 merged:
-       if (KEY_DIRTY(k))
-               bcache_dev_sectors_dirty_add(b->c, KEY_INODE(k),
-                                            KEY_START(k), KEY_SIZE(k));
-
        bch_check_keys(b, "%s for %s at %s: %s", status,
                       op_type(op), pbtree(b), pkey(k));
        bch_check_key_order_msg(b, i, "%s for %s at %s: %s", status,
-- 
1.8.5.2

--
To unsubscribe from this list: send the line "unsubscribe stable" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to