Update bcachefs sources to d464ec667b2b bcachefs: Add missing printk newlines

This commit is contained in:
Kent Overstreet 2023-11-03 12:09:59 -04:00
parent 37ee7f0591
commit 13a9480722
16 changed files with 118 additions and 59 deletions

View File

@ -1 +1 @@
b9bd69421f7364ca4ff11c827fd0e171a8b826ea d464ec667b2b9de097e39d1505b45aafd87a9552

View File

@ -297,15 +297,6 @@ fsck_err:
return ret; return ret;
} }
static inline u64 swab40(u64 x)
{
return (((x & 0x00000000ffULL) << 32)|
((x & 0x000000ff00ULL) << 16)|
((x & 0x0000ff0000ULL) >> 0)|
((x & 0x00ff000000ULL) >> 16)|
((x & 0xff00000000ULL) >> 32));
}
void bch2_alloc_v4_swab(struct bkey_s k) void bch2_alloc_v4_swab(struct bkey_s k)
{ {
struct bch_alloc_v4 *a = bkey_s_to_alloc_v4(k).v; struct bch_alloc_v4 *a = bkey_s_to_alloc_v4(k).v;
@ -319,6 +310,7 @@ void bch2_alloc_v4_swab(struct bkey_s k)
a->io_time[1] = swab64(a->io_time[1]); a->io_time[1] = swab64(a->io_time[1]);
a->stripe = swab32(a->stripe); a->stripe = swab32(a->stripe);
a->nr_external_backpointers = swab32(a->nr_external_backpointers); a->nr_external_backpointers = swab32(a->nr_external_backpointers);
a->fragmentation_lru = swab64(a->fragmentation_lru);
bps = alloc_v4_backpointers(a); bps = alloc_v4_backpointers(a);
for (bp = bps; bp < bps + BCH_ALLOC_V4_NR_BACKPOINTERS(a); bp++) { for (bp = bps; bp < bps + BCH_ALLOC_V4_NR_BACKPOINTERS(a); bp++) {

View File

@ -77,7 +77,7 @@ void bch2_backpointer_swab(struct bkey_s k)
{ {
struct bkey_s_backpointer bp = bkey_s_to_backpointer(k); struct bkey_s_backpointer bp = bkey_s_to_backpointer(k);
bp.v->bucket_offset = swab32(bp.v->bucket_offset); bp.v->bucket_offset = swab40(bp.v->bucket_offset);
bp.v->bucket_len = swab32(bp.v->bucket_len); bp.v->bucket_len = swab32(bp.v->bucket_len);
bch2_bpos_swab(&bp.v->pos); bch2_bpos_swab(&bp.v->pos);
} }

View File

@ -7,6 +7,15 @@
#include "buckets.h" #include "buckets.h"
#include "super.h" #include "super.h"
static inline u64 swab40(u64 x)
{
return (((x & 0x00000000ffULL) << 32)|
((x & 0x000000ff00ULL) << 16)|
((x & 0x0000ff0000ULL) >> 0)|
((x & 0x00ff000000ULL) >> 16)|
((x & 0xff00000000ULL) >> 32));
}
int bch2_backpointer_invalid(struct bch_fs *, struct bkey_s_c k, int bch2_backpointer_invalid(struct bch_fs *, struct bkey_s_c k,
enum bkey_invalid_flags, struct printbuf *); enum bkey_invalid_flags, struct printbuf *);
void bch2_backpointer_to_text(struct printbuf *, const struct bch_backpointer *); void bch2_backpointer_to_text(struct printbuf *, const struct bch_backpointer *);

View File

@ -92,19 +92,15 @@ enum bkey_lr_packed {
#define bkey_lr_packed(_l, _r) \ #define bkey_lr_packed(_l, _r) \
((_l)->format + ((_r)->format << 1)) ((_l)->format + ((_r)->format << 1))
#define bkey_copy(_dst, _src) \ static inline void bkey_p_copy(struct bkey_packed *dst, const struct bkey_packed *src)
do { \ {
BUILD_BUG_ON(!type_is(_dst, struct bkey_i *) && \ memcpy_u64s_small(dst, src, src->u64s);
!type_is(_dst, struct bkey_packed *)); \ }
BUILD_BUG_ON(!type_is(_src, struct bkey_i *) && \
!type_is(_src, struct bkey_packed *)); \ static inline void bkey_copy(struct bkey_i *dst, const struct bkey_i *src)
EBUG_ON((u64 *) (_dst) > (u64 *) (_src) && \ {
(u64 *) (_dst) < (u64 *) (_src) + \ memcpy_u64s_small(dst, src, src->k.u64s);
((struct bkey *) (_src))->u64s); \ }
\
memcpy_u64s_small((_dst), (_src), \
((struct bkey *) (_src))->u64s); \
} while (0)
struct btree; struct btree;

View File

@ -106,7 +106,7 @@ bch2_key_sort_fix_overlapping(struct bch_fs *c, struct bset *dst,
while ((k = sort_iter_peek(iter))) { while ((k = sort_iter_peek(iter))) {
if (!bkey_deleted(k) && if (!bkey_deleted(k) &&
!should_drop_next_key(iter)) { !should_drop_next_key(iter)) {
bkey_copy(out, k); bkey_p_copy(out, k);
btree_keys_account_key_add(&nr, 0, out); btree_keys_account_key_add(&nr, 0, out);
out = bkey_p_next(out); out = bkey_p_next(out);
} }
@ -137,7 +137,7 @@ bch2_sort_repack(struct bset *dst, struct btree *src,
continue; continue;
if (!transform) if (!transform)
bkey_copy(out, in); bkey_p_copy(out, in);
else if (bch2_bkey_transform(out_f, out, bkey_packed(in) else if (bch2_bkey_transform(out_f, out, bkey_packed(in)
? in_f : &bch2_bkey_format_current, in)) ? in_f : &bch2_bkey_format_current, in))
out->format = KEY_FORMAT_LOCAL_BTREE; out->format = KEY_FORMAT_LOCAL_BTREE;
@ -191,7 +191,7 @@ unsigned bch2_sort_keys(struct bkey_packed *dst,
memcpy_u64s_small(out, in, bkeyp_key_u64s(f, in)); memcpy_u64s_small(out, in, bkeyp_key_u64s(f, in));
set_bkeyp_val_u64s(f, out, 0); set_bkeyp_val_u64s(f, out, 0);
} else { } else {
bkey_copy(out, in); bkey_p_copy(out, in);
} }
out->needs_whiteout |= needs_whiteout; out->needs_whiteout |= needs_whiteout;
out = bkey_p_next(out); out = bkey_p_next(out);

View File

@ -184,7 +184,7 @@ static void bch2_sort_whiteouts(struct bch_fs *c, struct btree *b)
k = new_whiteouts; k = new_whiteouts;
while (ptrs != ptrs_end) { while (ptrs != ptrs_end) {
bkey_copy(k, *ptrs); bkey_p_copy(k, *ptrs);
k = bkey_p_next(k); k = bkey_p_next(k);
ptrs++; ptrs++;
} }
@ -260,7 +260,7 @@ static bool bch2_drop_whiteouts(struct btree *b, enum compact_mode mode)
n = bkey_p_next(k); n = bkey_p_next(k);
if (!bkey_deleted(k)) { if (!bkey_deleted(k)) {
bkey_copy(out, k); bkey_p_copy(out, k);
out = bkey_p_next(out); out = bkey_p_next(out);
} else { } else {
BUG_ON(k->needs_whiteout); BUG_ON(k->needs_whiteout);

View File

@ -303,7 +303,7 @@ static inline void push_whiteout(struct bch_fs *c, struct btree *b,
k.needs_whiteout = true; k.needs_whiteout = true;
b->whiteout_u64s += k.u64s; b->whiteout_u64s += k.u64s;
bkey_copy(unwritten_whiteouts_start(c, b), &k); bkey_p_copy(unwritten_whiteouts_start(c, b), &k);
} }
/* /*

View File

@ -3,6 +3,8 @@
#define _BCACHEFS_ERRCODE_H #define _BCACHEFS_ERRCODE_H
#define BCH_ERRCODES() \ #define BCH_ERRCODES() \
x(ERANGE, ERANGE_option_too_small) \
x(ERANGE, ERANGE_option_too_big) \
x(ENOMEM, ENOMEM_stripe_buf) \ x(ENOMEM, ENOMEM_stripe_buf) \
x(ENOMEM, ENOMEM_replicas_table) \ x(ENOMEM, ENOMEM_replicas_table) \
x(ENOMEM, ENOMEM_cpu_replicas) \ x(ENOMEM, ENOMEM_cpu_replicas) \

View File

@ -389,6 +389,21 @@ static inline struct bch_writepage_state bch_writepage_state_init(struct bch_fs
return ret; return ret;
} }
/*
* Determine when a writepage io is full. We have to limit writepage bios to a
* single page per bvec (i.e. 1MB with 4k pages) because that is the limit to
* what the bounce path in bch2_write_extent() can handle. In theory we could
* loosen this restriction for non-bounce I/O, but we don't have that context
* here. Ideally, we can up this limit and make it configurable in the future
* when the bounce path can be enhanced to accommodate larger source bios.
*/
static inline bool bch_io_full(struct bch_writepage_io *io, unsigned len)
{
struct bio *bio = &io->op.wbio.bio;
return bio_full(bio, len) ||
(bio->bi_iter.bi_size + len > BIO_MAX_VECS * PAGE_SIZE);
}
static void bch2_writepage_io_done(struct bch_write_op *op) static void bch2_writepage_io_done(struct bch_write_op *op)
{ {
struct bch_writepage_io *io = struct bch_writepage_io *io =
@ -606,9 +621,7 @@ do_io:
if (w->io && if (w->io &&
(w->io->op.res.nr_replicas != nr_replicas_this_write || (w->io->op.res.nr_replicas != nr_replicas_this_write ||
bio_full(&w->io->op.wbio.bio, sectors << 9) || bch_io_full(w->io, sectors << 9) ||
w->io->op.wbio.bio.bi_iter.bi_size + (sectors << 9) >=
(BIO_MAX_VECS * PAGE_SIZE) ||
bio_end_sector(&w->io->op.wbio.bio) != sector)) bio_end_sector(&w->io->op.wbio.bio) != sector))
bch2_writepage_do_io(w); bch2_writepage_do_io(w);

View File

@ -1213,9 +1213,6 @@ static struct dentry *bch2_get_parent(struct dentry *child)
.inum = inode->ei_inode.bi_dir, .inum = inode->ei_inode.bi_dir,
}; };
if (!parent_inum.inum)
return NULL;
return d_obtain_alias(bch2_vfs_inode_get(c, parent_inum)); return d_obtain_alias(bch2_vfs_inode_get(c, parent_inum));
} }

View File

@ -367,9 +367,10 @@ int bch2_inode_peek(struct btree_trans *trans,
return ret; return ret;
} }
int bch2_inode_write(struct btree_trans *trans, int bch2_inode_write_flags(struct btree_trans *trans,
struct btree_iter *iter, struct btree_iter *iter,
struct bch_inode_unpacked *inode) struct bch_inode_unpacked *inode,
enum btree_update_flags flags)
{ {
struct bkey_inode_buf *inode_p; struct bkey_inode_buf *inode_p;
@ -379,7 +380,7 @@ int bch2_inode_write(struct btree_trans *trans,
bch2_inode_pack_inlined(inode_p, inode); bch2_inode_pack_inlined(inode_p, inode);
inode_p->inode.k.p.snapshot = iter->snapshot; inode_p->inode.k.p.snapshot = iter->snapshot;
return bch2_trans_update(trans, iter, &inode_p->inode.k_i, 0); return bch2_trans_update(trans, iter, &inode_p->inode.k_i, flags);
} }
struct bkey_i *bch2_inode_to_v3(struct btree_trans *trans, struct bkey_i *k) struct bkey_i *bch2_inode_to_v3(struct btree_trans *trans, struct bkey_i *k)
@ -1065,24 +1066,18 @@ err:
return ret ?: -BCH_ERR_transaction_restart_nested; return ret ?: -BCH_ERR_transaction_restart_nested;
} }
static int may_delete_deleted_inode(struct btree_trans *trans, struct bpos pos) static int may_delete_deleted_inode(struct btree_trans *trans,
struct btree_iter *iter,
struct bpos pos,
bool *need_another_pass)
{ {
struct bch_fs *c = trans->c; struct bch_fs *c = trans->c;
struct btree_iter iter; struct btree_iter inode_iter;
struct bkey_s_c k; struct bkey_s_c k;
struct bch_inode_unpacked inode; struct bch_inode_unpacked inode;
int ret; int ret;
if (bch2_snapshot_is_internal_node(c, pos.snapshot)) k = bch2_bkey_get_iter(trans, &inode_iter, BTREE_ID_inodes, pos, BTREE_ITER_CACHED);
return 0;
if (!fsck_err_on(c->sb.clean, c,
deleted_inode_but_clean,
"filesystem marked as clean but have deleted inode %llu:%u",
pos.offset, pos.snapshot))
return 0;
k = bch2_bkey_get_iter(trans, &iter, BTREE_ID_inodes, pos, BTREE_ITER_CACHED);
ret = bkey_err(k); ret = bkey_err(k);
if (ret) if (ret)
return ret; return ret;
@ -1110,6 +1105,36 @@ static int may_delete_deleted_inode(struct btree_trans *trans, struct bpos pos)
pos.offset, pos.snapshot)) pos.offset, pos.snapshot))
goto delete; goto delete;
if (c->sb.clean &&
!fsck_err(c,
deleted_inode_but_clean,
"filesystem marked as clean but have deleted inode %llu:%u",
pos.offset, pos.snapshot))
return 0;
if (bch2_snapshot_is_internal_node(c, pos.snapshot)) {
struct bpos new_min_pos;
ret = bch2_propagate_key_to_snapshot_leaves(trans, inode_iter.btree_id, k, &new_min_pos);
if (ret)
goto err;
inode.bi_flags &= ~BCH_INODE_unlinked;
ret = bch2_inode_write_flags(trans, &inode_iter, &inode,
BTREE_UPDATE_INTERNAL_SNAPSHOT_NODE);
bch_err_msg(c, ret, "clearing inode unlinked flag");
if (ret)
return ret;
/*
* We'll need another write buffer flush to pick up the new
* unlinked inodes in the snapshot leaves:
*/
*need_another_pass = true;
return 0;
}
return 1; return 1;
err: err:
fsck_err: fsck_err:
@ -1123,7 +1148,10 @@ int bch2_delete_dead_inodes(struct bch_fs *c)
struct btree_trans *trans = bch2_trans_get(c); struct btree_trans *trans = bch2_trans_get(c);
struct btree_iter iter; struct btree_iter iter;
struct bkey_s_c k; struct bkey_s_c k;
bool need_another_pass;
int ret; int ret;
again:
need_another_pass = false;
ret = bch2_btree_write_buffer_flush_sync(trans); ret = bch2_btree_write_buffer_flush_sync(trans);
if (ret) if (ret)
@ -1137,7 +1165,8 @@ int bch2_delete_dead_inodes(struct bch_fs *c)
*/ */
for_each_btree_key(trans, iter, BTREE_ID_deleted_inodes, POS_MIN, for_each_btree_key(trans, iter, BTREE_ID_deleted_inodes, POS_MIN,
BTREE_ITER_PREFETCH|BTREE_ITER_ALL_SNAPSHOTS, k, ret) { BTREE_ITER_PREFETCH|BTREE_ITER_ALL_SNAPSHOTS, k, ret) {
ret = lockrestart_do(trans, may_delete_deleted_inode(trans, k.k->p)); ret = lockrestart_do(trans, may_delete_deleted_inode(trans, &iter, k.k->p,
&need_another_pass));
if (ret < 0) if (ret < 0)
break; break;
@ -1147,12 +1176,17 @@ int bch2_delete_dead_inodes(struct bch_fs *c)
bch2_fs_lazy_rw(c); bch2_fs_lazy_rw(c);
} }
bch_verbose(c, "deleting unlinked inode %llu:%u", k.k->p.offset, k.k->p.snapshot);
ret = bch2_inode_rm_snapshot(trans, k.k->p.offset, k.k->p.snapshot); ret = bch2_inode_rm_snapshot(trans, k.k->p.offset, k.k->p.snapshot);
if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart)) if (ret && !bch2_err_matches(ret, BCH_ERR_transaction_restart))
break; break;
} }
} }
bch2_trans_iter_exit(trans, &iter); bch2_trans_iter_exit(trans, &iter);
if (!ret && need_another_pass)
goto again;
err: err:
bch2_trans_put(trans); bch2_trans_put(trans);

View File

@ -3,6 +3,7 @@
#define _BCACHEFS_INODE_H #define _BCACHEFS_INODE_H
#include "bkey.h" #include "bkey.h"
#include "bkey_methods.h"
#include "opts.h" #include "opts.h"
enum bkey_invalid_flags; enum bkey_invalid_flags;
@ -101,8 +102,16 @@ void bch2_inode_unpacked_to_text(struct printbuf *, struct bch_inode_unpacked *)
int bch2_inode_peek(struct btree_trans *, struct btree_iter *, int bch2_inode_peek(struct btree_trans *, struct btree_iter *,
struct bch_inode_unpacked *, subvol_inum, unsigned); struct bch_inode_unpacked *, subvol_inum, unsigned);
int bch2_inode_write(struct btree_trans *, struct btree_iter *,
struct bch_inode_unpacked *); int bch2_inode_write_flags(struct btree_trans *, struct btree_iter *,
struct bch_inode_unpacked *, enum btree_update_flags);
static inline int bch2_inode_write(struct btree_trans *trans,
struct btree_iter *iter,
struct bch_inode_unpacked *inode)
{
return bch2_inode_write_flags(trans, iter, inode, 0);
}
void bch2_inode_init_early(struct bch_fs *, void bch2_inode_init_early(struct bch_fs *,
struct bch_inode_unpacked *); struct bch_inode_unpacked *);

View File

@ -265,14 +265,14 @@ int bch2_opt_validate(const struct bch_option *opt, u64 v, struct printbuf *err)
if (err) if (err)
prt_printf(err, "%s: too small (min %llu)", prt_printf(err, "%s: too small (min %llu)",
opt->attr.name, opt->min); opt->attr.name, opt->min);
return -ERANGE; return -BCH_ERR_ERANGE_option_too_small;
} }
if (opt->max && v >= opt->max) { if (opt->max && v >= opt->max) {
if (err) if (err)
prt_printf(err, "%s: too big (max %llu)", prt_printf(err, "%s: too big (max %llu)",
opt->attr.name, opt->max); opt->attr.name, opt->max);
return -ERANGE; return -BCH_ERR_ERANGE_option_too_big;
} }
if ((opt->flags & OPT_SB_FIELD_SECTORS) && (v & 511)) { if ((opt->flags & OPT_SB_FIELD_SECTORS) && (v & 511)) {

View File

@ -735,6 +735,13 @@ int bch2_fs_recovery(struct bch_fs *c)
if (*i) { if (*i) {
last_journal_entry = &(*i)->j; last_journal_entry = &(*i)->j;
(*i)->ignore = false; (*i)->ignore = false;
/*
* This was probably a NO_FLUSH entry,
* so last_seq was garbage - but we know
* we're only using a single journal
* entry, set it here:
*/
(*i)->j.last_seq = (*i)->j.seq;
break; break;
} }
} }

View File

@ -721,7 +721,7 @@ retry:
if (opt_defined(*opts, sb)) if (opt_defined(*opts, sb))
goto err; goto err;
printk(KERN_ERR "bcachefs (%s): error reading default superblock: %s", printk(KERN_ERR "bcachefs (%s): error reading default superblock: %s\n",
path, err.buf); path, err.buf);
printbuf_reset(&err); printbuf_reset(&err);
@ -783,7 +783,7 @@ got_super:
ret = bch2_sb_validate(sb, &err, READ); ret = bch2_sb_validate(sb, &err, READ);
if (ret) { if (ret) {
printk(KERN_ERR "bcachefs (%s): error validating superblock: %s", printk(KERN_ERR "bcachefs (%s): error validating superblock: %s\n",
path, err.buf); path, err.buf);
goto err_no_print; goto err_no_print;
} }
@ -791,7 +791,7 @@ out:
printbuf_exit(&err); printbuf_exit(&err);
return ret; return ret;
err: err:
printk(KERN_ERR "bcachefs (%s): error reading superblock: %s", printk(KERN_ERR "bcachefs (%s): error reading superblock: %s\n",
path, err.buf); path, err.buf);
err_no_print: err_no_print:
bch2_free_super(sb); bch2_free_super(sb);