]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - libbcachefs/data_update.c
Merge pull request #211 from oz123/master
[bcachefs-tools-debian] / libbcachefs / data_update.c
index 31090796cb6bc950e0ca202c2f38d419893c5354..4150feca42a2e65e63a59234a3e806ebbd09e1ac 100644 (file)
@@ -285,9 +285,7 @@ restart_drop_extra_replicas:
                                                k.k->p, bkey_start_pos(&insert->k)) ?:
                        bch2_insert_snapshot_whiteouts(trans, m->btree_id,
                                                k.k->p, insert->k.p) ?:
-                       bch2_bkey_set_needs_rebalance(c, insert,
-                                                     op->opts.background_target,
-                                                     op->opts.background_compression) ?:
+                       bch2_bkey_set_needs_rebalance(c, insert, &op->opts) ?:
                        bch2_trans_update(trans, &iter, insert,
                                BTREE_UPDATE_INTERNAL_SNAPSHOT_NODE) ?:
                        bch2_trans_commit(trans, &op->res,
@@ -314,14 +312,14 @@ next:
                }
                continue;
 nowork:
-               if (m->stats && m->stats) {
+               if (m->stats) {
                        BUG_ON(k.k->p.offset <= iter.pos.offset);
                        atomic64_inc(&m->stats->keys_raced);
                        atomic64_add(k.k->p.offset - iter.pos.offset,
                                     &m->stats->sectors_raced);
                }
 
-               this_cpu_inc(c->counters[BCH_COUNTER_move_extent_fail]);
+               count_event(c, move_extent_fail);
 
                bch2_btree_iter_advance(&iter);
                goto next;
@@ -356,7 +354,6 @@ void bch2_data_update_exit(struct data_update *update)
        struct bch_fs *c = update->op.c;
        struct bkey_ptrs_c ptrs =
                bch2_bkey_ptrs_c(bkey_i_to_s_c(update->k.k));
-       const struct bch_extent_ptr *ptr;
 
        bkey_for_each_ptr(ptrs, ptr) {
                if (c->opts.nocow_enabled)
@@ -377,7 +374,6 @@ static void bch2_update_unwritten_extent(struct btree_trans *trans,
        struct bio *bio = &update->op.wbio.bio;
        struct bkey_i_extent *e;
        struct write_point *wp;
-       struct bch_extent_ptr *ptr;
        struct closure cl;
        struct btree_iter iter;
        struct bkey_s_c k;
@@ -418,6 +414,8 @@ static void bch2_update_unwritten_extent(struct btree_trans *trans,
                        continue;
                }
 
+               bch_err_fn_ratelimited(c, ret);
+
                if (ret)
                        return;
 
@@ -485,7 +483,7 @@ int bch2_extent_drop_ptrs(struct btree_trans *trans,
         * we aren't using the extent overwrite path to delete, we're
         * just using the normal key deletion path:
         */
-       if (bkey_deleted(&n->k))
+       if (bkey_deleted(&n->k) && !(iter->flags & BTREE_ITER_IS_EXTENTS))
                n->k.size = 0;
 
        return bch2_trans_relock(trans) ?:
@@ -507,7 +505,6 @@ int bch2_data_update_init(struct btree_trans *trans,
        struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
        const union bch_extent_entry *entry;
        struct extent_ptr_decoded p;
-       const struct bch_extent_ptr *ptr;
        unsigned i, reserve_sectors = k.k->size * data_opts.extra_replicas;
        unsigned ptrs_locked = 0;
        int ret = 0;
@@ -530,7 +527,7 @@ int bch2_data_update_init(struct btree_trans *trans,
                BCH_WRITE_DATA_ENCODED|
                BCH_WRITE_MOVE|
                m->data_opts.write_flags;
-       m->op.compression_opt   = io_opts.background_compression ?: io_opts.compression;
+       m->op.compression_opt   = background_compression(io_opts);
        m->op.watermark         = m->data_opts.btree_insert_flags & BCH_WATERMARK_MASK;
 
        bkey_for_each_ptr(ptrs, ptr)
@@ -574,7 +571,8 @@ int bch2_data_update_init(struct btree_trans *trans,
                                move_ctxt_wait_event(ctxt,
                                                (locked = bch2_bucket_nocow_trylock(&c->nocow_locks,
                                                                          PTR_BUCKET_POS(c, &p.ptr), 0)) ||
-                                               !atomic_read(&ctxt->read_sectors));
+                                               (!atomic_read(&ctxt->read_sectors) &&
+                                                !atomic_read(&ctxt->write_sectors)));
 
                                if (!locked)
                                        bch2_bucket_nocow_lock(&c->nocow_locks,
@@ -600,12 +598,13 @@ int bch2_data_update_init(struct btree_trans *trans,
         * Increasing replication is an explicit operation triggered by
         * rereplicate, currently, so that users don't get an unexpected -ENOSPC
         */
-       if (durability_have >= io_opts.data_replicas) {
+       if (!(m->data_opts.write_flags & BCH_WRITE_CACHED) &&
+           durability_have >= io_opts.data_replicas) {
                m->data_opts.kill_ptrs |= m->data_opts.rewrite_ptrs;
                m->data_opts.rewrite_ptrs = 0;
                /* if iter == NULL, it's just a promote */
                if (iter)
-                       ret = bch2_extent_drop_ptrs(trans, iter, k, data_opts);
+                       ret = bch2_extent_drop_ptrs(trans, iter, k, m->data_opts);
                goto done;
        }
 
@@ -651,7 +650,6 @@ done:
 void bch2_data_update_opts_normalize(struct bkey_s_c k, struct data_update_opts *opts)
 {
        struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
-       const struct bch_extent_ptr *ptr;
        unsigned i = 0;
 
        bkey_for_each_ptr(ptrs, ptr) {