Skip to content

Commit

Permalink
Update bcachefs sources to a8115093df bcachefs: Fix divide by zero in…
Browse files Browse the repository at this point in the history
… rebalance_work()
  • Loading branch information
Kent Overstreet committed Aug 17, 2023
1 parent 4d04fe4 commit 505c326
Show file tree
Hide file tree
Showing 43 changed files with 1,484 additions and 1,251 deletions.
2 changes: 1 addition & 1 deletion .bcachefs_revision
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b0788c47d97935856809bd1357423978dbfcdf9f
a8115093df3e08c3e4bf6dab222e1cac132fff69
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,6 @@ update-bcachefs-sources:
git add include/linux/xxhash.h
cp $(LINUX_DIR)/lib/xxhash.c linux/
git add linux/xxhash.c
cp $(LINUX_DIR)/kernel/locking/six.c linux/
git add linux/six.c
cp $(LINUX_DIR)/include/linux/six.h include/linux/
git add include/linux/six.h
cp $(LINUX_DIR)/include/linux/list_nulls.h include/linux/
git add include/linux/list_nulls.h
cp $(LINUX_DIR)/include/linux/poison.h include/linux/
Expand Down
7 changes: 6 additions & 1 deletion include/linux/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ extern __thread struct task_struct *current;
#define set_current_state(state_value) \
smp_store_mb(current->state, (state_value))

#define get_task_struct(tsk) do { atomic_inc(&(tsk)->usage); } while(0)
static inline struct task_struct *get_task_struct(struct task_struct *task)
{
atomic_inc(&task->usage);
return task;

}

extern void __put_task_struct(struct task_struct *t);

Expand Down
57 changes: 44 additions & 13 deletions libbcachefs/alloc_foreground.c
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,6 @@ static int __open_bucket_add_buckets(struct btree_trans *trans,
cl = _cl;
goto retry_blocking;
}

}

return ret;
Expand Down Expand Up @@ -1031,6 +1030,16 @@ static int open_bucket_add_buckets(struct btree_trans *trans,
return ret < 0 ? ret : 0;
}

/**
* should_drop_bucket - check if this is open_bucket should go away
* @ca: if set, we're killing buckets for a particular device
* @ec: if true, we're shutting down erasure coding and killing all ec
* open_buckets
* otherwise, return true
*
* We're killing open_buckets because we're shutting down a device, erasure
* coding, or the entire filesystem - check if this open_bucket matches:
*/
static bool should_drop_bucket(struct open_bucket *ob, struct bch_fs *c,
struct bch_dev *ca, bool ec)
{
Expand Down Expand Up @@ -1516,25 +1525,47 @@ static const char * const bch2_write_point_states[] = {
NULL
};

static void bch2_write_point_to_text(struct printbuf *out, struct bch_fs *c,
struct write_point *wp)
{
struct open_bucket *ob;
unsigned i;

prt_printf(out, "%lu: ", wp->write_point);
prt_human_readable_u64(out, wp->sectors_allocated);

prt_printf(out, " last wrote: ");
bch2_pr_time_units(out, sched_clock() - wp->last_used);

for (i = 0; i < WRITE_POINT_STATE_NR; i++) {
prt_printf(out, " %s: ", bch2_write_point_states[i]);
bch2_pr_time_units(out, wp->time[i]);
}

prt_newline(out);

printbuf_indent_add(out, 2);
open_bucket_for_each(c, &wp->ptrs, ob, i)
bch2_open_bucket_to_text(out, c, ob);
printbuf_indent_sub(out, 2);
}

void bch2_write_points_to_text(struct printbuf *out, struct bch_fs *c)
{
struct write_point *wp;
unsigned i;

prt_str(out, "Foreground write points\n");
for (wp = c->write_points;
wp < c->write_points + ARRAY_SIZE(c->write_points);
wp++) {
prt_printf(out, "%lu: ", wp->write_point);
prt_human_readable_u64(out, wp->sectors_allocated);
wp++)
bch2_write_point_to_text(out, c, wp);

prt_printf(out, " last wrote: ");
bch2_pr_time_units(out, sched_clock() - wp->last_used);
prt_str(out, "Copygc write point\n");
bch2_write_point_to_text(out, c, &c->copygc_write_point);

for (i = 0; i < WRITE_POINT_STATE_NR; i++) {
prt_printf(out, " %s: ", bch2_write_point_states[i]);
bch2_pr_time_units(out, wp->time[i]);
}
prt_str(out, "Rebalance write point\n");
bch2_write_point_to_text(out, c, &c->rebalance_write_point);

prt_newline(out);
}
prt_str(out, "Btree write point\n");
bch2_write_point_to_text(out, c, &c->btree_write_point);
}
9 changes: 6 additions & 3 deletions libbcachefs/bcachefs_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -916,9 +916,7 @@ struct bch_dirent {
#define DT_SUBVOL 16
#define BCH_DT_MAX 17

#define BCH_NAME_MAX ((unsigned) (U8_MAX * sizeof(__u64) - \
sizeof(struct bkey) - \
offsetof(struct bch_dirent, d_name)))
#define BCH_NAME_MAX 512

/* Xattrs */

Expand Down Expand Up @@ -1126,6 +1124,11 @@ struct bch_subvolume {
__le32 flags;
__le32 snapshot;
__le64 inode;
/*
* Snapshot subvolumes form a tree, separate from the snapshot nodes
* tree - if this subvolume is a snapshot, this is the ID of the
* subvolume it was created from:
*/
__le32 parent;
__le32 pad;
bch_le128 otime;
Expand Down
6 changes: 4 additions & 2 deletions libbcachefs/bkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,10 @@ struct bkey_format bch2_bkey_format_done(struct bkey_format_state *s)

/* allow for extent merging: */
if (ret.bits_per_field[BKEY_FIELD_SIZE]) {
ret.bits_per_field[BKEY_FIELD_SIZE] += 4;
bits += 4;
unsigned b = min(4U, 32U - ret.bits_per_field[BKEY_FIELD_SIZE]);

ret.bits_per_field[BKEY_FIELD_SIZE] += b;
bits += b;
}

ret.key_u64s = DIV_ROUND_UP(bits, 64);
Expand Down
1 change: 1 addition & 0 deletions libbcachefs/bkey_methods.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "lru.h"
#include "quota.h"
#include "reflink.h"
#include "snapshot.h"
#include "subvolume.h"
#include "xattr.h"

Expand Down
14 changes: 8 additions & 6 deletions libbcachefs/btree_iter.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "extents.h"
#include "journal.h"
#include "replicas.h"
#include "subvolume.h"
#include "snapshot.h"
#include "trace.h"

#include <linux/random.h>
Expand Down Expand Up @@ -2898,12 +2898,14 @@ static void bch2_trans_alloc_paths(struct btree_trans *trans, struct bch_fs *c)
#ifdef __KERNEL__
p = this_cpu_xchg(c->btree_paths_bufs->path, NULL);
#endif
if (!p)
if (!p) {
p = mempool_alloc(&trans->c->btree_paths_pool, GFP_NOFS);
/*
* paths need to be zeroed, bch2_check_for_deadlock looks at paths in
* other threads
*/
/*
* paths need to be zeroed, bch2_check_for_deadlock looks at
* paths in other threads
*/
memset(p, 0, paths_bytes);
}

trans->paths = p; p += paths_bytes;
trans->updates = p; p += updates_bytes;
Expand Down
3 changes: 1 addition & 2 deletions libbcachefs/btree_locking.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
* updating the iterator state
*/

#include <linux/six.h>

#include "btree_iter.h"
#include "six.h"

void bch2_btree_lock_init(struct btree_bkey_cached_common *, enum six_lock_init_flags);

Expand Down
2 changes: 1 addition & 1 deletion libbcachefs/btree_trans_commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "journal.h"
#include "journal_reclaim.h"
#include "replicas.h"
#include "subvolume.h"
#include "snapshot.h"

#include <linux/prefetch.h>

Expand Down
2 changes: 1 addition & 1 deletion libbcachefs/btree_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

#include <linux/list.h>
#include <linux/rhashtable.h>
#include <linux/six.h>

//#include "bkey_methods.h"
#include "buckets_types.h"
#include "darray.h"
#include "errcode.h"
#include "journal_types.h"
#include "replicas_types.h"
#include "six.h"

struct open_bucket;
struct btree_update;
Expand Down
2 changes: 1 addition & 1 deletion libbcachefs/btree_update.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "error.h"
#include "extents.h"
#include "keylist.h"
#include "subvolume.h"
#include "snapshot.h"
#include "trace.h"

static inline int btree_insert_entry_cmp(const struct btree_insert_entry *l,
Expand Down
2 changes: 1 addition & 1 deletion libbcachefs/btree_update_interior.c
Original file line number Diff line number Diff line change
Expand Up @@ -2385,7 +2385,7 @@ void bch2_btree_updates_to_text(struct printbuf *out, struct bch_fs *c)
as,
as->mode,
as->nodes_written,
atomic_read(&as->cl.remaining) & CLOSURE_REMAINING_MASK,
closure_nr_remaining(&as->cl),
as->journal.seq);
mutex_unlock(&c->btree_interior_update_lock);
}
Expand Down
2 changes: 1 addition & 1 deletion libbcachefs/data_update.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ void bch2_update_unwritten_extent(struct btree_trans *trans,
break;
}

if ((atomic_read(&cl.remaining) & CLOSURE_REMAINING_MASK) != 1) {
if (closure_nr_remaining(&cl) != 1) {
bch2_trans_unlock(trans);
closure_sync(&cl);
}
Expand Down
Loading

0 comments on commit 505c326

Please sign in to comment.