Skip to content

Commit

Permalink
Update bcachefs sources to 72f65ef02ee2 bcachefs: bch2_opt_set_sb() c…
Browse files Browse the repository at this point in the history
…an now set (some) device options
  • Loading branch information
Kent Overstreet committed Jul 15, 2024
1 parent 2d60567 commit bbce7e6
Show file tree
Hide file tree
Showing 22 changed files with 158 additions and 125 deletions.
2 changes: 1 addition & 1 deletion .bcachefs_revision
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4d1d53862afb768e4edcf7256f8fe0634c96b40e
5a50e6ec9e94549d60c25787928c20816b92886c
2 changes: 1 addition & 1 deletion c_src/libbcachefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ struct bch_sb *bch2_format(struct bch_opt_strs fs_opt_strs,
? bch2_opt_get_by_id(&fs_opts, opt_id)
: bch2_opt_get_by_id(&bch2_opts_default, opt_id);

__bch2_opt_set_sb(sb.sb, &bch2_opt_table[opt_id], v);
__bch2_opt_set_sb(sb.sb, -1, &bch2_opt_table[opt_id], v);
}

struct timespec now;
Expand Down
2 changes: 1 addition & 1 deletion c_src/posix_to_bcachefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ static void write_data(struct bch_fs *c,

closure_call(&op.cl, bch2_write, NULL, NULL);

BUG_ON(!(op.flags & BCH_WRITE_DONE));
BUG_ON(!(op.flags & BCH_WRITE_SUBMITTED));
dst_inode->bi_sectors += len >> 9;

if (op.error)
Expand Down
8 changes: 7 additions & 1 deletion libbcachefs/alloc_foreground.c
Original file line number Diff line number Diff line change
Expand Up @@ -662,8 +662,14 @@ static struct open_bucket *bch2_bucket_alloc_trans(struct btree_trans *trans,
goto alloc;
}
err:
if (!ob)
if (!ob) {
rcu_read_lock();
struct task_struct *t = rcu_dereference(c->copygc_thread);
if (t)
wake_up_process(t);
rcu_read_unlock();
ob = ERR_PTR(-BCH_ERR_no_buckets_found);
}

if (!IS_ERR(ob))
ob->data_type = data_type;
Expand Down
2 changes: 1 addition & 1 deletion libbcachefs/bcachefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ struct bch_fs {
struct bch_fs_rebalance rebalance;

/* COPYGC */
struct task_struct *copygc_thread;
struct task_struct __rcu *copygc_thread;
struct write_point copygc_write_point;
s64 copygc_wait_at;
s64 copygc_wait;
Expand Down
6 changes: 0 additions & 6 deletions libbcachefs/btree_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ void bch2_btree_node_io_unlock(struct btree *b)

void bch2_btree_node_io_lock(struct btree *b)
{
bch2_assert_btree_nodes_not_locked();

wait_on_bit_lock_io(&b->flags, BTREE_NODE_write_in_flight,
TASK_UNINTERRUPTIBLE);
}
Expand All @@ -66,16 +64,12 @@ void __bch2_btree_node_wait_on_write(struct btree *b)

void bch2_btree_node_wait_on_read(struct btree *b)
{
bch2_assert_btree_nodes_not_locked();

wait_on_bit_io(&b->flags, BTREE_NODE_read_in_flight,
TASK_UNINTERRUPTIBLE);
}

void bch2_btree_node_wait_on_write(struct btree *b)
{
bch2_assert_btree_nodes_not_locked();

wait_on_bit_io(&b->flags, BTREE_NODE_write_in_flight,
TASK_UNINTERRUPTIBLE);
}
Expand Down
3 changes: 2 additions & 1 deletion libbcachefs/btree_iter.c
Original file line number Diff line number Diff line change
Expand Up @@ -3282,7 +3282,8 @@ bool bch2_current_has_btree_trans(struct bch_fs *c)
struct btree_trans *trans;
bool ret = false;
list_for_each_entry(trans, &c->btree_trans_list, list)
if (trans->locking_wait.task == current) {
if (trans->locking_wait.task == current &&
trans->locked) {
ret = true;
break;
}
Expand Down
10 changes: 0 additions & 10 deletions libbcachefs/btree_locking.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,6 @@ void bch2_btree_lock_init(struct btree_bkey_cached_common *b,
lockdep_set_notrack_class(&b->lock);
}

#ifdef CONFIG_LOCKDEP
void bch2_assert_btree_nodes_not_locked(void)
{
#if 0
//Re-enable when lock_class_is_held() is merged:
BUG_ON(lock_class_is_held(&bch2_btree_node_lock_key));
#endif
}
#endif

/* Btree node locking: */

struct six_lock_count bch2_btree_node_lock_counts(struct btree_trans *trans,
Expand Down
6 changes: 0 additions & 6 deletions libbcachefs/btree_locking.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@

void bch2_btree_lock_init(struct btree_bkey_cached_common *, enum six_lock_init_flags);

#ifdef CONFIG_LOCKDEP
void bch2_assert_btree_nodes_not_locked(void);
#else
static inline void bch2_assert_btree_nodes_not_locked(void) {}
#endif

void bch2_trans_unlock_noassert(struct btree_trans *);

static inline bool is_btree_node(struct btree_path *path, unsigned l)
Expand Down
3 changes: 2 additions & 1 deletion libbcachefs/darray.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ int __bch2_darray_resize(darray_char *d, size_t element_size, size_t new_size, g
if (!data)
return -ENOMEM;

memcpy(data, d->data, d->size * element_size);
if (d->size)
memcpy(data, d->data, d->size * element_size);
if (d->data != d->preallocated)
kvfree(d->data);
d->data = data;
Expand Down
45 changes: 19 additions & 26 deletions libbcachefs/io_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -1147,42 +1147,35 @@ void __bch2_read(struct bch_fs *c, struct bch_read_bio *rbio,
struct btree_iter iter;
struct bkey_buf sk;
struct bkey_s_c k;
u32 snapshot;
int ret;

BUG_ON(flags & BCH_READ_NODECODE);

bch2_bkey_buf_init(&sk);
retry:
bch2_trans_begin(trans);
iter = (struct btree_iter) { NULL };

ret = bch2_subvolume_get_snapshot(trans, inum.subvol, &snapshot);
if (ret)
goto err;

bch2_trans_iter_init(trans, &iter, BTREE_ID_extents,
SPOS(inum.inum, bvec_iter.bi_sector, snapshot),
POS(inum.inum, bvec_iter.bi_sector),
BTREE_ITER_slots);

while (1) {
unsigned bytes, sectors, offset_into_extent;
enum btree_id data_btree = BTREE_ID_extents;

/*
* read_extent -> io_time_reset may cause a transaction restart
* without returning an error, we need to check for that here:
*/
ret = bch2_trans_relock(trans);
bch2_trans_begin(trans);

u32 snapshot;
ret = bch2_subvolume_get_snapshot(trans, inum.subvol, &snapshot);
if (ret)
break;
goto err;

bch2_btree_iter_set_snapshot(&iter, snapshot);

bch2_btree_iter_set_pos(&iter,
POS(inum.inum, bvec_iter.bi_sector));

k = bch2_btree_iter_peek_slot(&iter);
ret = bkey_err(k);
if (ret)
break;
goto err;

offset_into_extent = iter.pos.offset -
bkey_start_offset(k.k);
Expand All @@ -1193,7 +1186,7 @@ void __bch2_read(struct bch_fs *c, struct bch_read_bio *rbio,
ret = bch2_read_indirect_extent(trans, &data_btree,
&offset_into_extent, &sk);
if (ret)
break;
goto err;

k = bkey_i_to_s_c(sk.k);

Expand All @@ -1213,7 +1206,7 @@ void __bch2_read(struct bch_fs *c, struct bch_read_bio *rbio,
data_btree, k,
offset_into_extent, failed, flags);
if (ret)
break;
goto err;

if (flags & BCH_READ_LAST_FRAGMENT)
break;
Expand All @@ -1223,16 +1216,16 @@ void __bch2_read(struct bch_fs *c, struct bch_read_bio *rbio,

ret = btree_trans_too_many_iters(trans);
if (ret)
goto err;
err:
if (ret &&
!bch2_err_matches(ret, BCH_ERR_transaction_restart) &&
ret != READ_RETRY &&
ret != READ_RETRY_AVOID)
break;
}
err:
bch2_trans_iter_exit(trans, &iter);

if (bch2_err_matches(ret, BCH_ERR_transaction_restart) ||
ret == READ_RETRY ||
ret == READ_RETRY_AVOID)
goto retry;

bch2_trans_iter_exit(trans, &iter);
bch2_trans_put(trans);
bch2_bkey_buf_exit(&sk, c);

Expand Down
24 changes: 12 additions & 12 deletions libbcachefs/io_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ static void __bch2_write_index(struct bch_write_op *op)
err:
keys->top = keys->keys;
op->error = ret;
op->flags |= BCH_WRITE_DONE;
op->flags |= BCH_WRITE_SUBMITTED;
goto out;
}

Expand Down Expand Up @@ -589,7 +589,7 @@ static CLOSURE_CALLBACK(bch2_write_index)
struct workqueue_struct *wq = index_update_wq(op);
unsigned long flags;

if ((op->flags & BCH_WRITE_DONE) &&
if ((op->flags & BCH_WRITE_SUBMITTED) &&
(op->flags & BCH_WRITE_MOVE))
bch2_bio_free_pages_pool(op->c, &op->wbio.bio);

Expand Down Expand Up @@ -634,7 +634,7 @@ void bch2_write_point_do_index_updates(struct work_struct *work)

__bch2_write_index(op);

if (!(op->flags & BCH_WRITE_DONE))
if (!(op->flags & BCH_WRITE_SUBMITTED))
__bch2_write(op);
else
bch2_write_done(&op->cl);
Expand Down Expand Up @@ -1318,7 +1318,7 @@ static void bch2_nocow_write(struct bch_write_op *op)
wbio_init(bio)->put_bio = true;
bio->bi_opf = op->wbio.bio.bi_opf;
} else {
op->flags |= BCH_WRITE_DONE;
op->flags |= BCH_WRITE_SUBMITTED;
}

op->pos.offset += bio_sectors(bio);
Expand All @@ -1332,7 +1332,7 @@ static void bch2_nocow_write(struct bch_write_op *op)
op->insert_keys.top, true);

bch2_keylist_push(&op->insert_keys);
if (op->flags & BCH_WRITE_DONE)
if (op->flags & BCH_WRITE_SUBMITTED)
break;
bch2_btree_iter_advance(&iter);
}
Expand All @@ -1347,14 +1347,14 @@ static void bch2_nocow_write(struct bch_write_op *op)
op->pos.inode, op->pos.offset << 9,
"%s: btree lookup error %s", __func__, bch2_err_str(ret));
op->error = ret;
op->flags |= BCH_WRITE_DONE;
op->flags |= BCH_WRITE_SUBMITTED;
}

bch2_trans_put(trans);
darray_exit(&buckets);

/* fallback to cow write path? */
if (!(op->flags & BCH_WRITE_DONE)) {
if (!(op->flags & BCH_WRITE_SUBMITTED)) {
closure_sync(&op->cl);
__bch2_nocow_write_done(op);
op->insert_keys.top = op->insert_keys.keys;
Expand Down Expand Up @@ -1410,7 +1410,7 @@ static void __bch2_write(struct bch_write_op *op)

if (unlikely(op->opts.nocow && c->opts.nocow_enabled)) {
bch2_nocow_write(op);
if (op->flags & BCH_WRITE_DONE)
if (op->flags & BCH_WRITE_SUBMITTED)
goto out_nofs_restore;
}
again:
Expand Down Expand Up @@ -1465,7 +1465,7 @@ static void __bch2_write(struct bch_write_op *op)
bch2_alloc_sectors_done_inlined(c, wp);
err:
if (ret <= 0) {
op->flags |= BCH_WRITE_DONE;
op->flags |= BCH_WRITE_SUBMITTED;

if (ret < 0) {
if (!(op->flags & BCH_WRITE_ALLOC_NOWAIT))
Expand Down Expand Up @@ -1501,7 +1501,7 @@ static void __bch2_write(struct bch_write_op *op)
* once, as that signals backpressure to the caller.
*/
if ((op->flags & BCH_WRITE_SYNC) ||
(!(op->flags & BCH_WRITE_DONE) &&
(!(op->flags & BCH_WRITE_SUBMITTED) &&
!(op->flags & BCH_WRITE_IN_WORKER))) {
if (closure_sync_timeout(&op->cl, HZ * 10)) {
bch2_print_allocator_stuck(c);
Expand All @@ -1510,7 +1510,7 @@ static void __bch2_write(struct bch_write_op *op)

__bch2_write_index(op);

if (!(op->flags & BCH_WRITE_DONE))
if (!(op->flags & BCH_WRITE_SUBMITTED))
goto again;
bch2_write_done(&op->cl);
} else {
Expand All @@ -1532,7 +1532,7 @@ static void bch2_write_data_inline(struct bch_write_op *op, unsigned data_len)
memset(&op->failed, 0, sizeof(op->failed));

op->flags |= BCH_WRITE_WROTE_DATA_INLINE;
op->flags |= BCH_WRITE_DONE;
op->flags |= BCH_WRITE_SUBMITTED;

bch2_check_set_feature(op->c, BCH_FEATURE_inline_data);

Expand Down
2 changes: 1 addition & 1 deletion libbcachefs/io_write.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void bch2_submit_wbio_replicas(struct bch_write_bio *, struct bch_fs *,
x(SYNC) \
x(MOVE) \
x(IN_WORKER) \
x(DONE) \
x(SUBMITTED) \
x(IO_ERROR) \
x(CONVERT_UNWRITTEN)

Expand Down
11 changes: 11 additions & 0 deletions libbcachefs/journal_reclaim.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,17 @@ void bch2_journal_space_available(struct journal *j)
j->can_discard = can_discard;

if (nr_online < metadata_replicas_required(c)) {
struct printbuf buf = PRINTBUF;
prt_printf(&buf, "insufficient writeable journal devices available: have %u, need %u\n"
"rw journal devs:", nr_online, metadata_replicas_required(c));

rcu_read_lock();
for_each_member_device_rcu(c, ca, &c->rw_devs[BCH_DATA_journal])
prt_printf(&buf, " %s", ca->name);
rcu_read_unlock();

bch_err(c, "%s", buf.buf);
printbuf_exit(&buf);
ret = JOURNAL_ERR_insufficient_devices;
goto out;
}
Expand Down
6 changes: 3 additions & 3 deletions libbcachefs/mean_and_variance.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ static inline u128_u u128_shl(u128_u i, s8 shift)
{
u128_u r;

r.lo = i.lo << shift;
r.lo = i.lo << (shift & 63);
if (shift < 64)
r.hi = (i.hi << shift) | (i.lo >> (64 - shift));
r.hi = (i.hi << (shift & 63)) | (i.lo >> (-shift & 63));
else {
r.hi = i.lo << (shift - 64);
r.hi = i.lo << (-shift & 63);
r.lo = 0;
}
return r;
Expand Down
Loading

0 comments on commit bbce7e6

Please sign in to comment.