Skip to content

Commit

Permalink
Update bcachefs sources to 8eca47e4d5 bcachefs: Improved check_direct…
Browse files Browse the repository at this point in the history
…ory_structure()
  • Loading branch information
koverstreet committed Apr 13, 2021
1 parent b422ff5 commit 967c870
Show file tree
Hide file tree
Showing 12 changed files with 293 additions and 281 deletions.
2 changes: 1 addition & 1 deletion .bcachefs_revision
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a8b3ce75990057fc2e3a1c64310668e1ac9ed0f5
8eca47e4d5c4e6817ad4c020be4280bd82104efd
43 changes: 42 additions & 1 deletion include/linux/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,48 @@
#include <linux/byteorder.h>
#include <linux/compiler.h>

#define IS_ENABLED(opt) 0
#define __ARG_PLACEHOLDER_1 0,
#define __take_second_arg(__ignored, val, ...) val

#define __and(x, y) ___and(x, y)
#define ___and(x, y) ____and(__ARG_PLACEHOLDER_##x, y)
#define ____and(arg1_or_junk, y) __take_second_arg(arg1_or_junk y, 0)

#define __or(x, y) ___or(x, y)
#define ___or(x, y) ____or(__ARG_PLACEHOLDER_##x, y)
#define ____or(arg1_or_junk, y) __take_second_arg(arg1_or_junk 1, y)

#define __is_defined(x) ___is_defined(x)
#define ___is_defined(val) ____is_defined(__ARG_PLACEHOLDER_##val)
#define ____is_defined(arg1_or_junk) __take_second_arg(arg1_or_junk 1, 0)

/*
* IS_BUILTIN(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y', 0
* otherwise. For boolean options, this is equivalent to
* IS_ENABLED(CONFIG_FOO).
*/
#define IS_BUILTIN(option) __is_defined(option)

/*
* IS_MODULE(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'm', 0
* otherwise.
*/
#define IS_MODULE(option) __is_defined(option##_MODULE)

/*
* IS_REACHABLE(CONFIG_FOO) evaluates to 1 if the currently compiled
* code can call a function defined in code compiled based on CONFIG_FOO.
* This is similar to IS_ENABLED(), but returns false when invoked from
* built-in code when CONFIG_FOO is set to 'm'.
*/
#define IS_REACHABLE(option) __or(IS_BUILTIN(option), \
__and(IS_MODULE(option), __is_defined(MODULE)))

/*
* IS_ENABLED(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y' or 'm',
* 0 otherwise.
*/
#define IS_ENABLED(option) __or(IS_BUILTIN(option), IS_MODULE(option))
#define EXPORT_SYMBOL(sym)

#define U8_MAX ((u8)~0U)
Expand Down
14 changes: 3 additions & 11 deletions libbcachefs/alloc_background.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static void pd_controllers_update(struct work_struct *work)
struct bch_dev_usage stats = bch2_dev_usage_read(ca);

free += bucket_to_sector(ca,
__dev_buckets_free(ca, stats)) << 9;
__dev_buckets_available(ca, stats)) << 9;
/*
* Bytes of internal fragmentation, which can be
* reclaimed by copy GC
Expand Down Expand Up @@ -477,7 +477,6 @@ static int wait_buckets_available(struct bch_fs *c, struct bch_dev *ca)
{
unsigned long gc_count = c->gc_count;
s64 available;
unsigned i;
int ret = 0;

ca->allocator_state = ALLOCATOR_BLOCKED;
Expand All @@ -493,19 +492,12 @@ static int wait_buckets_available(struct bch_fs *c, struct bch_dev *ca)
if (gc_count != c->gc_count)
ca->inc_gen_really_needs_gc = 0;

available = dev_buckets_available(ca);
available = dev_buckets_reclaimable(ca);
available -= ca->inc_gen_really_needs_gc;

spin_lock(&c->freelist_lock);
for (i = 0; i < RESERVE_NR; i++)
available -= fifo_used(&ca->free[i]);
spin_unlock(&c->freelist_lock);

available = max(available, 0LL);

if (available > fifo_free(&ca->free_inc) ||
(available &&
!fifo_full(&ca->free[RESERVE_MOVINGGC])))
if (available)
break;

up_read(&c->gc_lock);
Expand Down
2 changes: 1 addition & 1 deletion libbcachefs/alloc_foreground.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ void bch2_dev_stripe_increment(struct bch_dev *ca,
struct dev_stripe_state *stripe)
{
u64 *v = stripe->next_alloc + ca->dev_idx;
u64 free_space = dev_buckets_free(ca);
u64 free_space = dev_buckets_available(ca);
u64 free_space_inv = free_space
? div64_u64(1ULL << 48, free_space)
: 1ULL << 48;
Expand Down
3 changes: 1 addition & 2 deletions libbcachefs/btree_iter.c
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,7 @@ bool bch2_trans_relock(struct btree_trans *trans)
struct btree_iter *iter;

trans_for_each_iter(trans, iter)
if (btree_iter_keep(trans, iter) &&
!bch2_btree_iter_relock(iter, true)) {
if (!bch2_btree_iter_relock(iter, true)) {
trace_trans_restart_relock(trans->ip);
return false;
}
Expand Down
9 changes: 6 additions & 3 deletions libbcachefs/btree_update.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,12 @@ static inline int bch2_trans_commit(struct btree_trans *trans,
return __bch2_trans_commit(trans);
}

#define __bch2_trans_do(_trans, _disk_res, _journal_seq, _flags, _do) \
#define lockrestart_do(_trans, _do) \
({ \
int _ret; \
\
while (1) { \
_ret = (_do) ?: bch2_trans_commit(_trans, (_disk_res), \
(_journal_seq), (_flags)); \
_ret = (_do); \
if (_ret != -EINTR) \
break; \
bch2_trans_reset(_trans, 0); \
Expand All @@ -118,6 +117,10 @@ static inline int bch2_trans_commit(struct btree_trans *trans,
_ret; \
})

#define __bch2_trans_do(_trans, _disk_res, _journal_seq, _flags, _do) \
lockrestart_do(_trans, _do ?: bch2_trans_commit(_trans, (_disk_res),\
(_journal_seq), (_flags)))

#define bch2_trans_do(_c, _disk_res, _journal_seq, _flags, _do) \
({ \
struct btree_trans trans; \
Expand Down
25 changes: 15 additions & 10 deletions libbcachefs/buckets.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,25 +175,30 @@ static inline u64 __dev_buckets_available(struct bch_dev *ca,
return total - stats.buckets_unavailable;
}

/*
* Number of reclaimable buckets - only for use by the allocator thread:
*/
static inline u64 dev_buckets_available(struct bch_dev *ca)
{
return __dev_buckets_available(ca, bch2_dev_usage_read(ca));
}

static inline u64 __dev_buckets_free(struct bch_dev *ca,
struct bch_dev_usage stats)
static inline u64 __dev_buckets_reclaimable(struct bch_dev *ca,
struct bch_dev_usage stats)
{
return __dev_buckets_available(ca, stats) +
fifo_used(&ca->free[RESERVE_NONE]) +
fifo_used(&ca->free_inc);
struct bch_fs *c = ca->fs;
s64 available = __dev_buckets_available(ca, stats);
unsigned i;

spin_lock(&c->freelist_lock);
for (i = 0; i < RESERVE_NR; i++)
available -= fifo_used(&ca->free[i]);
available -= fifo_used(&ca->free_inc);
spin_unlock(&c->freelist_lock);

return max(available, 0LL);
}

static inline u64 dev_buckets_free(struct bch_dev *ca)
static inline u64 dev_buckets_reclaimable(struct bch_dev *ca)
{
return __dev_buckets_free(ca, bch2_dev_usage_read(ca));
return __dev_buckets_reclaimable(ca, bch2_dev_usage_read(ca));
}

/* Filesystem usage: */
Expand Down
8 changes: 6 additions & 2 deletions libbcachefs/fs-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ int bch2_link_trans(struct btree_trans *trans, u64 dir_inum,
inode_u->bi_ctime = now;
bch2_inode_nlink_inc(inode_u);

inode_u->bi_flags |= BCH_INODE_BACKPTR_UNTRUSTED;

dir_iter = bch2_inode_peek(trans, dir_u, dir_inum, 0);
ret = PTR_ERR_OR_ZERO(dir_iter);
if (ret)
Expand Down Expand Up @@ -175,6 +173,12 @@ int bch2_unlink_trans(struct btree_trans *trans,
if (ret)
goto err;

if (inode_u->bi_dir == k.k->p.inode &&
inode_u->bi_dir_offset == k.k->p.offset) {
inode_u->bi_dir = 0;
inode_u->bi_dir_offset = 0;
}

dir_u->bi_mtime = dir_u->bi_ctime = inode_u->bi_ctime = now;
dir_u->bi_nlink -= S_ISDIR(inode_u->bi_mode);
bch2_inode_nlink_dec(inode_u);
Expand Down

0 comments on commit 967c870

Please sign in to comment.