bcache: Fix dirty_data accounting
[deliverable/linux.git] / drivers / md / bcache / btree.c
index f42fc7ed9cd63b14fd4cf54a879dfd9d046584d1..d1734d9d9c797c24047223d2fb7df05438a60a57 100644 (file)
@@ -1742,6 +1742,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) {
                                /*
@@ -1803,6 +1806,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);
@@ -1831,10 +1838,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, "%u for %s", status, op_type(op));
 
        if (b->level && !KEY_OFFSET(k))
This page took 0.024318 seconds and 5 git commands to generate.