Skip to content

Commit 4f564f4

Browse files
author
Kent Overstreet
committed
bcachefs: bch2_prt_compression_type()
bounds checking helper, since compression types are extensible Signed-off-by: Kent Overstreet <[email protected]>
1 parent e58f963 commit 4f564f4

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
lines changed

fs/bcachefs/compress.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ static inline enum bch_compression_type bch2_compression_opt_to_type(unsigned v)
4747
return __bch2_compression_opt_to_type[bch2_compression_decode(v).type];
4848
}
4949

50+
static inline void bch2_prt_compression_type(struct printbuf *out, enum bch_compression_type type)
51+
{
52+
if (type < BCH_COMPRESSION_TYPE_NR)
53+
prt_str(out, __bch2_compression_types[type]);
54+
else
55+
prt_printf(out, "(invalid compression type %u)", type);
56+
}
57+
5058
int bch2_bio_uncompress_inplace(struct bch_fs *, struct bio *,
5159
struct bch_extent_crc_unpacked *);
5260
int bch2_bio_uncompress(struct bch_fs *, struct bio *, struct bio *,

fs/bcachefs/extents.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,12 +1018,12 @@ void bch2_bkey_ptrs_to_text(struct printbuf *out, struct bch_fs *c,
10181018
struct bch_extent_crc_unpacked crc =
10191019
bch2_extent_crc_unpack(k.k, entry_to_crc(entry));
10201020

1021-
prt_printf(out, "crc: c_size %u size %u offset %u nonce %u csum %s compress %s",
1021+
prt_printf(out, "crc: c_size %u size %u offset %u nonce %u csum %s compress ",
10221022
crc.compressed_size,
10231023
crc.uncompressed_size,
10241024
crc.offset, crc.nonce,
1025-
bch2_csum_types[crc.csum_type],
1026-
bch2_compression_types[crc.compression_type]);
1025+
bch2_csum_types[crc.csum_type]);
1026+
bch2_prt_compression_type(out, crc.compression_type);
10271027
break;
10281028
}
10291029
case BCH_EXTENT_ENTRY_stripe_ptr: {

fs/bcachefs/opts.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const char * const bch2_csum_opts[] = {
5252
NULL
5353
};
5454

55-
const char * const bch2_compression_types[] = {
55+
const char * const __bch2_compression_types[] = {
5656
BCH_COMPRESSION_TYPES()
5757
NULL
5858
};

fs/bcachefs/opts.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ extern const char * const bch2_sb_compat[];
1818
extern const char * const __bch2_btree_ids[];
1919
extern const char * const bch2_csum_types[];
2020
extern const char * const bch2_csum_opts[];
21-
extern const char * const bch2_compression_types[];
21+
extern const char * const __bch2_compression_types[];
2222
extern const char * const bch2_compression_opts[];
2323
extern const char * const bch2_str_hash_types[];
2424
extern const char * const bch2_str_hash_opts[];

fs/bcachefs/sysfs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "btree_gc.h"
2222
#include "buckets.h"
2323
#include "clock.h"
24+
#include "compress.h"
2425
#include "disk_groups.h"
2526
#include "ec.h"
2627
#include "inode.h"
@@ -330,7 +331,7 @@ static int bch2_compression_stats_to_text(struct printbuf *out, struct bch_fs *c
330331
prt_newline(out);
331332

332333
for (unsigned i = 0; i < ARRAY_SIZE(s); i++) {
333-
prt_str(out, bch2_compression_types[i]);
334+
bch2_prt_compression_type(out, i);
334335
prt_tab(out);
335336

336337
prt_human_readable_u64(out, s[i].sectors_compressed << 9);

0 commit comments

Comments
 (0)