bcachefs: Guard against unknown compression options

Since compression options now include compression level, proper
validation is a bit more involved.

This adds bch2_compression_opt_valid(), and plumbs it around
appropriately.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet
2023-10-22 18:29:54 -04:00
parent ef435abd6a
commit 6ddedca218
6 changed files with 45 additions and 12 deletions

View File

@ -708,3 +708,13 @@ void bch2_opt_compression_to_text(struct printbuf *out,
if (opt.level)
prt_printf(out, ":%u", opt.level);
}
int bch2_opt_compression_validate(u64 v, struct printbuf *err)
{
if (!bch2_compression_opt_valid(v)) {
prt_printf(err, "invalid compression opt %llu", v);
return -BCH_ERR_invalid_sb_opt_compression;
}
return 0;
}