2017-03-17 09:18:50 +03:00
/* SPDX-License-Identifier: GPL-2.0 */
# ifndef _BCACHEFS_COMPRESS_H
# define _BCACHEFS_COMPRESS_H
# include "extents_types.h"
2023-10-23 01:29:54 +03:00
static const unsigned __bch2_compression_opt_to_type [ ] = {
# define x(t, n) [BCH_COMPRESSION_OPT_##t] = BCH_COMPRESSION_TYPE_##t,
BCH_COMPRESSION_OPTS ( )
# undef x
} ;
2023-07-13 05:27:16 +03:00
struct bch_compression_opt {
u8 type : 4 ,
level : 4 ;
} ;
2023-10-23 01:29:54 +03:00
static inline struct bch_compression_opt __bch2_compression_decode ( unsigned v )
2023-07-13 05:27:16 +03:00
{
return ( struct bch_compression_opt ) {
. type = v & 15 ,
. level = v > > 4 ,
} ;
}
2023-10-23 01:29:54 +03:00
static inline bool bch2_compression_opt_valid ( unsigned v )
{
struct bch_compression_opt opt = __bch2_compression_decode ( v ) ;
return opt . type < ARRAY_SIZE ( __bch2_compression_opt_to_type ) & & ! ( ! opt . type & & opt . level ) ;
}
static inline struct bch_compression_opt bch2_compression_decode ( unsigned v )
{
return bch2_compression_opt_valid ( v )
? __bch2_compression_decode ( v )
: ( struct bch_compression_opt ) { 0 } ;
}
2023-07-13 05:27:16 +03:00
static inline unsigned bch2_compression_encode ( struct bch_compression_opt opt )
{
return opt . type | ( opt . level < < 4 ) ;
}
static inline enum bch_compression_type bch2_compression_opt_to_type ( unsigned v )
{
return __bch2_compression_opt_to_type [ bch2_compression_decode ( v ) . type ] ;
}
2017-03-17 09:18:50 +03:00
int bch2_bio_uncompress_inplace ( struct bch_fs * , struct bio * ,
struct bch_extent_crc_unpacked * ) ;
int bch2_bio_uncompress ( struct bch_fs * , struct bio * , struct bio * ,
struct bvec_iter , struct bch_extent_crc_unpacked ) ;
unsigned bch2_bio_compress ( struct bch_fs * , struct bio * , size_t * ,
struct bio * , size_t * , unsigned ) ;
int bch2_check_set_has_compressed_data ( struct bch_fs * , unsigned ) ;
void bch2_fs_compress_exit ( struct bch_fs * ) ;
int bch2_fs_compress_init ( struct bch_fs * ) ;
bcachefs: rebalance_work
This adds a new btree, rebalance_work, to eliminate scanning required
for finding extents that need work done on them in the background - i.e.
for the background_target and background_compression options.
rebalance_work is a bitset btree, where a KEY_TYPE_set corresponds to an
extent in the extents or reflink btree at the same pos.
A new extent field is added, bch_extent_rebalance, which indicates that
this extent has work that needs to be done in the background - and which
options to use. This allows per-inode options to be propagated to
indirect extents - at least in some circumstances. In this patch,
changing IO options on a file will not propagate the new options to
indirect extents pointed to by that file.
Updating (setting/clearing) the rebalance_work btree is done by the
extent trigger, which looks at the bch_extent_rebalance field.
Scanning is still requrired after changing IO path options - either just
for a given inode, or for the whole filesystem. We indicate that
scanning is required by adding a KEY_TYPE_cookie key to the
rebalance_work btree: the cookie counter is so that we can detect that
scanning is still required when an option has been flipped mid-way
through an existing scan.
Future possible work:
- Propagate options to indirect extents when being changed
- Add other IO path options - nr_replicas, ec, to rebalance_work so
they can be applied in the background when they change
- Add a counter, for bcachefs fs usage output, showing the pending
amount of rebalance work: we'll probably want to do this after the
disk space accounting rewrite (moving it to a new btree)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-10-20 20:33:14 +03:00
void bch2_compression_opt_to_text ( struct printbuf * , u64 ) ;
2023-07-13 05:27:16 +03:00
int bch2_opt_compression_parse ( struct bch_fs * , const char * , u64 * , struct printbuf * ) ;
void bch2_opt_compression_to_text ( struct printbuf * , struct bch_fs * , struct bch_sb * , u64 ) ;
2023-10-23 01:29:54 +03:00
int bch2_opt_compression_validate ( u64 , struct printbuf * ) ;
2023-07-13 05:27:16 +03:00
# define bch2_opt_compression (struct bch_opt_fn) { \
2023-10-23 01:29:54 +03:00
. parse = bch2_opt_compression_parse , \
. to_text = bch2_opt_compression_to_text , \
. validate = bch2_opt_compression_validate , \
2023-07-13 05:27:16 +03:00
}
2017-03-17 09:18:50 +03:00
# endif /* _BCACHEFS_COMPRESS_H */