Commit abab7609 authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: Fix bch2_extent_fallocate() in nocow mode

When we allocate disk space, we need to be incrementing the WRITE io
clock, which perhaps should be renamed to sectors allocated - copygc
uses this io clock to know when to run.

Also, we should be incrementing the same clock when allocating btree
nodes.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 711bf946
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "btree_iter.h" #include "btree_iter.h"
#include "btree_locking.h" #include "btree_locking.h"
#include "buckets.h" #include "buckets.h"
#include "clock.h"
#include "error.h" #include "error.h"
#include "extents.h" #include "extents.h"
#include "journal.h" #include "journal.h"
...@@ -363,6 +364,7 @@ static struct btree *bch2_btree_node_alloc(struct btree_update *as, ...@@ -363,6 +364,7 @@ static struct btree *bch2_btree_node_alloc(struct btree_update *as,
BUG_ON(ret); BUG_ON(ret);
trace_and_count(c, btree_node_alloc, c, b); trace_and_count(c, btree_node_alloc, c, b);
bch2_increment_clock(c, btree_sectors(c), WRITE);
return b; return b;
} }
......
...@@ -384,6 +384,7 @@ int bch2_extent_fallocate(struct btree_trans *trans, ...@@ -384,6 +384,7 @@ int bch2_extent_fallocate(struct btree_trans *trans,
struct open_buckets open_buckets; struct open_buckets open_buckets;
struct bkey_s_c k; struct bkey_s_c k;
struct bkey_buf old, new; struct bkey_buf old, new;
unsigned sectors_allocated;
bool have_reservation = false; bool have_reservation = false;
bool unwritten = opts.nocow && bool unwritten = opts.nocow &&
c->sb.version >= bcachefs_metadata_version_unwritten_extents; c->sb.version >= bcachefs_metadata_version_unwritten_extents;
...@@ -394,6 +395,8 @@ int bch2_extent_fallocate(struct btree_trans *trans, ...@@ -394,6 +395,8 @@ int bch2_extent_fallocate(struct btree_trans *trans,
closure_init_stack(&cl); closure_init_stack(&cl);
open_buckets.nr = 0; open_buckets.nr = 0;
retry: retry:
sectors_allocated = 0;
k = bch2_btree_iter_peek_slot(iter); k = bch2_btree_iter_peek_slot(iter);
ret = bkey_err(k); ret = bkey_err(k);
if (ret) if (ret)
...@@ -459,6 +462,7 @@ int bch2_extent_fallocate(struct btree_trans *trans, ...@@ -459,6 +462,7 @@ int bch2_extent_fallocate(struct btree_trans *trans,
return ret; return ret;
sectors = min(sectors, wp->sectors_free); sectors = min(sectors, wp->sectors_free);
sectors_allocated = sectors;
bch2_key_resize(&e->k, sectors); bch2_key_resize(&e->k, sectors);
...@@ -485,6 +489,9 @@ int bch2_extent_fallocate(struct btree_trans *trans, ...@@ -485,6 +489,9 @@ int bch2_extent_fallocate(struct btree_trans *trans,
goto retry; goto retry;
} }
if (!ret && sectors_allocated)
bch2_increment_clock(c, sectors_allocated, WRITE);
bch2_open_buckets_put(c, &open_buckets); bch2_open_buckets_put(c, &open_buckets);
bch2_disk_reservation_put(c, &disk_res); bch2_disk_reservation_put(c, &disk_res);
bch2_bkey_buf_exit(&new, c); bch2_bkey_buf_exit(&new, c);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment