Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial support for security callbacks. #664

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
04675dd
bcachefs: Fix assert in bch2_backpointer_invalid()
Mar 22, 2024
d15120f
bcachefs: Fix journal pins in btree write buffer
Mar 22, 2024
f07bcae
bcachefs: fix misplaced newline in __bch2_inode_unpacked_to_text()
bertschingert Mar 21, 2024
112b15d
bcachefs: fix mount error path
Mar 28, 2024
87cff80
bcachefs: Add an assertion for trying to evict btree root
Mar 24, 2024
bcfe8c2
bcachefs: Move snapshot table size to struct snapshot_table
Mar 22, 2024
e0e3a56
bcachefs: Add checks for invalid snapshot IDs
Mar 22, 2024
93c6641
bcachefs: Don't do extent merging before journal replay is finished
Mar 23, 2024
cb8292d
bcachefs: fix trans->mem realloc in __bch2_trans_kmalloc
Mar 25, 2024
67d9f61
bcachefs: btree_and_journal_iter now respects trans->journal_replay_n…
Mar 25, 2024
01d89ab
bcachefs: Be careful about btree node splits during journal replay
Mar 26, 2024
e319caa
bcachefs: Improved topology repair checks
Mar 23, 2024
d4f5fed
bcachefs: add REQ_SYNC and REQ_IDLE in write dio
zhuxiaohui400 Mar 26, 2024
88319b4
bcachefs: Check btree ptr min_key in .invalid
Mar 26, 2024
3807441
bcachefs: Fix btree node keys accounting in topology repair path
Mar 26, 2024
47cfd43
bcachefs: Fix use after free in bch2_check_fix_ptrs()
Mar 26, 2024
cc6c618
bcachefs: Fix repair path for missing indirect extents
Mar 26, 2024
f8f966a
bcachefs: Fix use after free in check_root_trans()
Mar 26, 2024
640af35
bcachefs: Kill bch2_bkey_ptr_data_type()
Mar 25, 2024
c47762f
bcachefs: Fix bch2_btree_increase_depth()
Mar 14, 2024
4cd7cc4
bcachefs: fix backpointer for missing alloc key msg
Mar 28, 2024
09b7b38
bcachefs: Split out recovery_passes.c
Mar 24, 2024
6621c10
bcachefs: Add error messages to logged ops fns
Mar 23, 2024
f67c113
bcachefs: Resume logged ops after fsck
Mar 23, 2024
183af40
bcachefs: Flush journal immediately after replay if we did early repair
Mar 28, 2024
b3ab164
bcachefs: Improve -o norecovery
Mar 29, 2024
698a6cb
bcachefs: bch2_shoot_down_journal_keys()
Mar 19, 2024
5132e8b
bcachefs: Etyzinger cleanups
Mar 22, 2024
feee3b9
bcachefs: Flag btrees with missing data
Mar 16, 2024
f150013
bcachefs: bch2_btree_root_alloc() -> bch2_btree_root_alloc_fake()
Mar 15, 2024
d0f9603
bcachefs: Don't skip fake btree roots in fsck
Mar 10, 2024
119f8d8
bcachefs: Repair pass for scanning for btree nodes
Mar 12, 2024
794723f
bcachefs: Topology repair now uses nodes found by scanning to fill holes
Mar 17, 2024
5dc90d3
bcachefs: Initial support for security labels.
xbjfk Mar 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions fs/bcachefs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ bcachefs-y := \
btree_journal_iter.o \
btree_key_cache.o \
btree_locking.o \
btree_node_scan.o \
btree_trans_commit.o \
btree_update.o \
btree_update_interior.o \
Expand All @@ -37,6 +38,7 @@ bcachefs-y := \
error.o \
extents.o \
extent_update.o \
eytzinger.o \
fs.o \
fs-common.o \
fs-ioctl.o \
Expand Down Expand Up @@ -67,6 +69,7 @@ bcachefs-y := \
quota.o \
rebalance.o \
recovery.o \
recovery_passes.o \
reflink.o \
replicas.o \
sb-clean.o \
Expand Down
13 changes: 8 additions & 5 deletions fs/bcachefs/backpointers.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ static bool extent_matches_bp(struct bch_fs *c,
if (p.ptr.cached)
continue;

bch2_extent_ptr_to_bp(c, btree_id, level, k, p,
&bucket2, &bp2);
bch2_extent_ptr_to_bp(c, btree_id, level, k, p, entry, &bucket2, &bp2);
if (bpos_eq(bucket, bucket2) &&
!memcmp(&bp, &bp2, sizeof(bp)))
return true;
Expand All @@ -44,6 +43,11 @@ int bch2_backpointer_invalid(struct bch_fs *c, struct bkey_s_c k,
struct printbuf *err)
{
struct bkey_s_c_backpointer bp = bkey_s_c_to_backpointer(k);

/* these will be caught by fsck */
if (!bch2_dev_exists2(c, bp.k->p.inode))
return 0;

struct bpos bucket = bp_pos_to_bucket(c, bp.k->p);
int ret = 0;

Expand Down Expand Up @@ -378,7 +382,7 @@ static int bch2_check_btree_backpointer(struct btree_trans *trans, struct btree_
backpointer_to_missing_alloc,
"backpointer for nonexistent alloc key: %llu:%llu:0\n%s",
alloc_iter.pos.inode, alloc_iter.pos.offset,
(bch2_bkey_val_to_text(&buf, c, alloc_k), buf.buf))) {
(bch2_bkey_val_to_text(&buf, c, k), buf.buf))) {
ret = bch2_btree_delete_at(trans, bp_iter, 0);
goto out;
}
Expand Down Expand Up @@ -502,8 +506,7 @@ static int check_extent_to_backpointers(struct btree_trans *trans,
if (p.ptr.cached)
continue;

bch2_extent_ptr_to_bp(c, btree, level,
k, p, &bucket_pos, &bp);
bch2_extent_ptr_to_bp(c, btree, level, k, p, entry, &bucket_pos, &bp);

ret = check_bp_exists(trans, s, bucket_pos, bp, k);
if (ret)
Expand Down
32 changes: 26 additions & 6 deletions fs/bcachefs/backpointers.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,40 @@ static inline int bch2_bucket_backpointer_mod(struct btree_trans *trans,
return bch2_trans_update_buffered(trans, BTREE_ID_backpointers, &bp_k.k_i);
}

static inline enum bch_data_type bkey_ptr_data_type(enum btree_id btree_id, unsigned level,
struct bkey_s_c k, struct extent_ptr_decoded p)
static inline enum bch_data_type bch2_bkey_ptr_data_type(struct bkey_s_c k,
struct extent_ptr_decoded p,
const union bch_extent_entry *entry)
{
return level ? BCH_DATA_btree :
p.has_ec ? BCH_DATA_stripe :
BCH_DATA_user;
switch (k.k->type) {
case KEY_TYPE_btree_ptr:
case KEY_TYPE_btree_ptr_v2:
return BCH_DATA_btree;
case KEY_TYPE_extent:
case KEY_TYPE_reflink_v:
return p.has_ec ? BCH_DATA_stripe : BCH_DATA_user;
case KEY_TYPE_stripe: {
const struct bch_extent_ptr *ptr = &entry->ptr;
struct bkey_s_c_stripe s = bkey_s_c_to_stripe(k);

BUG_ON(ptr < s.v->ptrs ||
ptr >= s.v->ptrs + s.v->nr_blocks);

return ptr >= s.v->ptrs + s.v->nr_blocks - s.v->nr_redundant
? BCH_DATA_parity
: BCH_DATA_user;
}
default:
BUG();
}
}

static inline void bch2_extent_ptr_to_bp(struct bch_fs *c,
enum btree_id btree_id, unsigned level,
struct bkey_s_c k, struct extent_ptr_decoded p,
const union bch_extent_entry *entry,
struct bpos *bucket_pos, struct bch_backpointer *bp)
{
enum bch_data_type data_type = bkey_ptr_data_type(btree_id, level, k, p);
enum bch_data_type data_type = bch2_bkey_ptr_data_type(k, p, entry);
s64 sectors = level ? btree_sectors(c) : k.k->size;
u32 bucket_offset;

Expand Down
7 changes: 5 additions & 2 deletions fs/bcachefs/bcachefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
#include "fifo.h"
#include "nocow_locking_types.h"
#include "opts.h"
#include "recovery_types.h"
#include "recovery_passes_types.h"
#include "sb-errors_types.h"
#include "seqmutex.h"
#include "time_stats.h"
Expand Down Expand Up @@ -456,6 +456,7 @@ enum bch_time_stats {

#include "alloc_types.h"
#include "btree_types.h"
#include "btree_node_scan_types.h"
#include "btree_write_buffer_types.h"
#include "buckets_types.h"
#include "buckets_waiting_for_journal_types.h"
Expand Down Expand Up @@ -810,7 +811,6 @@ struct bch_fs {

/* snapshot.c: */
struct snapshot_table __rcu *snapshots;
size_t snapshot_table_size;
struct mutex snapshot_table_lock;
struct rw_semaphore snapshot_create_lock;

Expand All @@ -826,6 +826,7 @@ struct bch_fs {
struct btree_root btree_roots_known[BTREE_ID_NR];
DARRAY(struct btree_root) btree_roots_extra;
struct mutex btree_root_lock;
unsigned long btrees_lost_data; /* bitmask */

struct btree_cache btree_cache;

Expand Down Expand Up @@ -1104,6 +1105,8 @@ struct bch_fs {
struct journal_keys journal_keys;
struct list_head journal_iters;

struct find_btree_nodes found_btree_nodes;

u64 last_bucket_seq_cleanup;

u64 counters_on_mount[BCH_COUNTER_NR];
Expand Down
14 changes: 10 additions & 4 deletions fs/bcachefs/bset.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,24 @@ void bch2_dump_btree_node_iter(struct btree *b,
printbuf_exit(&buf);
}

#ifdef CONFIG_BCACHEFS_DEBUG

void __bch2_verify_btree_nr_keys(struct btree *b)
struct btree_nr_keys bch2_btree_node_count_keys(struct btree *b)
{
struct bset_tree *t;
struct bkey_packed *k;
struct btree_nr_keys nr = { 0 };
struct btree_nr_keys nr = {};

for_each_bset(b, t)
bset_tree_for_each_key(b, t, k)
if (!bkey_deleted(k))
btree_keys_account_key_add(&nr, t - b->set, k);
return nr;
}

#ifdef CONFIG_BCACHEFS_DEBUG

void __bch2_verify_btree_nr_keys(struct btree *b)
{
struct btree_nr_keys nr = bch2_btree_node_count_keys(b);

BUG_ON(memcmp(&nr, &b->nr, sizeof(nr)));
}
Expand Down
2 changes: 2 additions & 0 deletions fs/bcachefs/bset.h
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,8 @@ struct bkey_s_c bch2_btree_node_iter_peek_unpack(struct btree_node_iter *,

/* Accounting: */

struct btree_nr_keys bch2_btree_node_count_keys(struct btree *);

static inline void btree_keys_account_key(struct btree_nr_keys *n,
unsigned bset,
struct bkey_packed *k,
Expand Down
5 changes: 4 additions & 1 deletion fs/bcachefs/btree_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,8 @@ static noinline void btree_bad_header(struct bch_fs *c, struct btree *b)
prt_printf(&buf, "\nmax ");
bch2_bpos_to_text(&buf, b->data->max_key);

bch2_fs_inconsistent(c, "%s", buf.buf);
bch2_fs_topology_error(c, "%s", buf.buf);

printbuf_exit(&buf);
}

Expand Down Expand Up @@ -1134,6 +1135,8 @@ void bch2_btree_node_evict(struct btree_trans *trans, const struct bkey_i *k)
b = btree_cache_find(bc, k);
if (!b)
return;

BUG_ON(b == btree_node_root(trans->c, b));
wait_on_io:
/* not allowed to wait on io with btree locks held: */

Expand Down
Loading