2018-10-06 00:46:55 -04:00
/* SPDX-License-Identifier: GPL-2.0 */
# ifndef _BCACHEFS_ALLOC_BACKGROUND_H
# define _BCACHEFS_ALLOC_BACKGROUND_H
# include "bcachefs.h"
# include "alloc_types.h"
# include "debug.h"
2019-02-13 14:46:32 -05:00
struct bkey_alloc_unpacked {
u8 gen ;
# define x(_name, _bits) u##_bits _name;
BCH_ALLOC_FIELDS ( )
# undef x
} ;
struct bkey_alloc_unpacked bch2_alloc_unpack ( const struct bch_alloc * ) ;
2018-11-04 22:09:51 -05:00
# define ALLOC_SCAN_BATCH(ca) max_t(size_t, 1, (ca)->mi.nbuckets >> 9)
2018-10-06 00:46:55 -04:00
const char * bch2_alloc_invalid ( const struct bch_fs * , struct bkey_s_c ) ;
2018-11-09 01:24:07 -05:00
void bch2_alloc_to_text ( struct printbuf * , struct bch_fs * , struct bkey_s_c ) ;
2018-10-06 00:46:55 -04:00
2018-11-01 15:10:01 -04:00
# define bch2_bkey_ops_alloc (struct bkey_ops) { \
2018-10-06 00:46:55 -04:00
. key_invalid = bch2_alloc_invalid , \
. val_to_text = bch2_alloc_to_text , \
}
2019-04-11 22:39:39 -04:00
struct journal_keys ;
int bch2_alloc_read ( struct bch_fs * , struct journal_keys * ) ;
2018-11-18 23:20:21 -05:00
int bch2_alloc_replay_key ( struct bch_fs * , struct bkey_i * ) ;
2018-10-06 00:46:55 -04:00
static inline void bch2_wake_allocator ( struct bch_dev * ca )
{
struct task_struct * p ;
rcu_read_lock ( ) ;
p = rcu_dereference ( ca - > alloc_thread ) ;
if ( p )
wake_up_process ( p ) ;
rcu_read_unlock ( ) ;
}
static inline void verify_not_on_freelist ( struct bch_fs * c , struct bch_dev * ca ,
size_t bucket )
{
if ( expensive_debug_checks ( c ) & &
test_bit ( BCH_FS_ALLOCATOR_STARTED , & c - > flags ) ) {
size_t iter ;
long i ;
unsigned j ;
for ( j = 0 ; j < RESERVE_NR ; j + + )
fifo_for_each_entry ( i , & ca - > free [ j ] , iter )
BUG_ON ( i = = bucket ) ;
fifo_for_each_entry ( i , & ca - > free_inc , iter )
BUG_ON ( i = = bucket ) ;
}
}
void bch2_recalc_capacity ( struct bch_fs * ) ;
void bch2_dev_allocator_remove ( struct bch_fs * , struct bch_dev * ) ;
void bch2_dev_allocator_add ( struct bch_fs * , struct bch_dev * ) ;
2018-11-19 01:31:41 -05:00
void bch2_dev_allocator_quiesce ( struct bch_fs * , struct bch_dev * ) ;
2018-10-06 00:46:55 -04:00
void bch2_dev_allocator_stop ( struct bch_dev * ) ;
int bch2_dev_allocator_start ( struct bch_dev * ) ;
2019-04-06 15:12:21 -04:00
int bch2_alloc_write ( struct bch_fs * , unsigned , bool * ) ;
2018-10-06 00:46:55 -04:00
int bch2_fs_allocator_start ( struct bch_fs * ) ;
2018-11-04 21:55:35 -05:00
void bch2_fs_allocator_background_init ( struct bch_fs * ) ;
2018-10-06 00:46:55 -04:00
# endif /* _BCACHEFS_ALLOC_BACKGROUND_H */