Message ID | 20190128212437.11597-2-dennis@kernel.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | btrfs: add zstd compression level support | expand |
On 28.01.19 г. 23:24 ч., Dennis Zhou wrote: > It is very easy to miss places that rely on a certain bitshifting for > decyphering the type_level overloading. Make macros handle this instead. > > Signed-off-by: Dennis Zhou <dennis@kernel.org> Reviewed-by: Nikolay Borisov <nborisov@suse.com>
On Mon, Jan 28, 2019 at 04:24:27PM -0500, Dennis Zhou wrote: > It is very easy to miss places that rely on a certain bitshifting for > decyphering the type_level overloading. Make macros handle this instead. > > Signed-off-by: Dennis Zhou <dennis@kernel.org> Reviewed-by: Josef Bacik <josef@toxicpanda.com> Thanks, Josef
On Mon, Jan 28, 2019 at 04:24:27PM -0500, Dennis Zhou wrote: > It is very easy to miss places that rely on a certain bitshifting for > decyphering the type_level overloading. Make macros handle this instead. > > Signed-off-by: Dennis Zhou <dennis@kernel.org> > --- > fs/btrfs/compression.c | 2 +- > fs/btrfs/compression.h | 3 +++ > fs/btrfs/zlib.c | 2 +- > 3 files changed, 5 insertions(+), 2 deletions(-) > > diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c > index 548057630b69..586f95ac0aea 100644 > --- a/fs/btrfs/compression.c > +++ b/fs/btrfs/compression.c > @@ -1036,9 +1036,9 @@ int btrfs_compress_pages(unsigned int type_level, struct address_space *mapping, > unsigned long *total_in, > unsigned long *total_out) > { > + int type = BTRFS_COMPRESS_TYPE(type_level); > struct list_head *workspace; > int ret; > - int type = type_level & 0xF; > > workspace = find_workspace(type); > > diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h > index ddda9b80bf20..69a9197dadc3 100644 > --- a/fs/btrfs/compression.h > +++ b/fs/btrfs/compression.h > @@ -25,6 +25,9 @@ > > #define BTRFS_ZLIB_DEFAULT_LEVEL 3 > > +#define BTRFS_COMPRESS_TYPE(type_level) (type_level & 0xF) > +#define BTRFS_COMPRESS_LEVEL(type_level) ((type_level & 0xF0) >> 4) Nit: these can be inline functions rather than macros. > struct compressed_bio { > /* number of bios pending for this compressed extent */ > refcount_t pending_bios; > diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c > index 970ff3e35bb3..1480b3eee306 100644 > --- a/fs/btrfs/zlib.c > +++ b/fs/btrfs/zlib.c > @@ -393,7 +393,7 @@ static int zlib_decompress(struct list_head *ws, unsigned char *data_in, > static void zlib_set_level(struct list_head *ws, unsigned int type) > { > struct workspace *workspace = list_entry(ws, struct workspace, list); > - unsigned level = (type & 0xF0) >> 4; > + unsigned int level = BTRFS_COMPRESS_LEVEL(type); > > if (level > 9) > level = 9; > -- > 2.17.1 >
On Mon, Jan 28, 2019 at 04:24:27PM -0500, Dennis Zhou wrote: > It is very easy to miss places that rely on a certain bitshifting for > decyphering the type_level overloading. Make macros handle this instead. This encoding was a simple way to introduce the combined type and level for zlib and it could certainly be improved. Either we'll use helpers like you suggest or add a new structure that contains type and level as members. That way we'd see where the level still matters and where the just the type is ok. I haven't checked how much intrusive this would be, so that's for later consideration. Some indirection can be removed for the .set_level callbacks as it does not necessarily need to be a function so I'm expecting that the code around that would be touched anyway.
On Thu, Jan 31, 2019 at 05:00:10PM +0100, David Sterba wrote: > On Mon, Jan 28, 2019 at 04:24:27PM -0500, Dennis Zhou wrote: > > It is very easy to miss places that rely on a certain bitshifting for > > decyphering the type_level overloading. Make macros handle this instead. > > This encoding was a simple way to introduce the combined type and level > for zlib and it could certainly be improved. Either we'll use helpers > like you suggest or add a new structure that contains type and level as > members. That way we'd see where the level still matters and where the > just the type is ok. > > I haven't checked how much intrusive this would be, so that's for later > consideration. Some indirection can be removed for the .set_level > callbacks as it does not necessarily need to be a function so I'm > expecting that the code around that would be touched anyway. The only user of type_level is btrfs_compress_pages(). I do make an extra call to .set_level() there just to be safe, but that can be taken out as it should be correctly set from when we mounted. I envisioned .set_level() to be called when setting the compression level of the mount. This can be used in the same place if we were to add per-file compression levels too. I mention later, but an important part of .set_level() is to repurpose the meaning of 0 from meaning use the default to meaning use any workspace available. Thanks, Dennis
diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 548057630b69..586f95ac0aea 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -1036,9 +1036,9 @@ int btrfs_compress_pages(unsigned int type_level, struct address_space *mapping, unsigned long *total_in, unsigned long *total_out) { + int type = BTRFS_COMPRESS_TYPE(type_level); struct list_head *workspace; int ret; - int type = type_level & 0xF; workspace = find_workspace(type); diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h index ddda9b80bf20..69a9197dadc3 100644 --- a/fs/btrfs/compression.h +++ b/fs/btrfs/compression.h @@ -25,6 +25,9 @@ #define BTRFS_ZLIB_DEFAULT_LEVEL 3 +#define BTRFS_COMPRESS_TYPE(type_level) (type_level & 0xF) +#define BTRFS_COMPRESS_LEVEL(type_level) ((type_level & 0xF0) >> 4) + struct compressed_bio { /* number of bios pending for this compressed extent */ refcount_t pending_bios; diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c index 970ff3e35bb3..1480b3eee306 100644 --- a/fs/btrfs/zlib.c +++ b/fs/btrfs/zlib.c @@ -393,7 +393,7 @@ static int zlib_decompress(struct list_head *ws, unsigned char *data_in, static void zlib_set_level(struct list_head *ws, unsigned int type) { struct workspace *workspace = list_entry(ws, struct workspace, list); - unsigned level = (type & 0xF0) >> 4; + unsigned int level = BTRFS_COMPRESS_LEVEL(type); if (level > 9) level = 9;
It is very easy to miss places that rely on a certain bitshifting for decyphering the type_level overloading. Make macros handle this instead. Signed-off-by: Dennis Zhou <dennis@kernel.org> --- fs/btrfs/compression.c | 2 +- fs/btrfs/compression.h | 3 +++ fs/btrfs/zlib.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-)