Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

btrfs-progs: mkfs: add --compress #925

Merged
merged 6 commits into from
Dec 13, 2024
Merged

Conversation

maharmstone
Copy link
Contributor

@maharmstone maharmstone commented Nov 19, 2024

Adds a --compress option to mkfs.btrfs when using --rootdir. (Resurrection of #882, closed by mistake.)

@adam900710, this includes your two patches, and all the suggestions that you made. If you're happy with all this, I suggested accepting this PR and abandoning #919.

@maharmstone maharmstone changed the title btrfs-progs: mkfs: add --compression btrfs-progs: mkfs: add --compress Nov 19, 2024
@adam900710
Copy link
Collaborator

adam900710 commented Nov 19, 2024

Thanks a lot. I'll close #919 and use this branch instead.

Although to avoid previous accidents l'll take a more comprehensive review before merge.
So far the patches looks good to me (through the github WebUI) and I believe we can push this for the next cycle.

Copy link
Collaborator

@adam900710 adam900710 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most small style problems, but the compression parameter and the inode flag handling is not subtle, and affecting all the other compression algorithms.

mkfs/rootdir.c Outdated Show resolved Hide resolved
mkfs/rootdir.c Outdated Show resolved Hide resolved
mkfs/rootdir.c Outdated Show resolved Hide resolved
mkfs/rootdir.c Show resolved Hide resolved
mkfs/rootdir.c Outdated Show resolved Hide resolved
convert/source-reiserfs.c Outdated Show resolved Hide resolved
@kdave kdave force-pushed the devel branch 3 times, most recently from 72c9865 to 164145b Compare November 28, 2024 13:41
adam900710 and others added 6 commits December 12, 2024 20:43
The function btrfs_record_file_extent() has extra handling that's
specific to convert, like allowing the range to be split by block group
boundary and image file extent boundary.

All of these split can only lead to corruption for non-converted fs.
As the only caller out of btrfs-convert is rootdir, which expects the
file extent item insert to respect the reserved data extent, and never
to be split.

Thankfully this is not going to cause huge problem, as
btrfs_record_file_extent() has extra checks if the data extent overlaps
with any existing one, and if it doesn't the handling will be the same
as the kernel.

But to avoid abuse, change btrfs_record_file_extent() by:

- Rename it to btrfs_convert_file_extent()
  And add extra comments on that it is specific to btrfs-convert.

- Move it to convert/common.[ch]

- Introduce a helper insert_reserved_file_extent() for rootdir.c

Signed-off-by: Qu Wenruo <[email protected]>
…extent item

Just like insert_reserved_file_extent() from the kernel, we can make
btrfs_insert_file_extent() accept an on-stack file extent item
directly.

This makes btrfs_insert_file_extent() more flex, and it can now handle
the converted file extent where it has an non-zero offset.

And this makes it much easier to expand for future compressed file
extent generation.

Signed-off-by: Qu Wenruo <[email protected]>
There were two major problems with add_file_items(): it was
writing all files sector-by-sector, making compression impossible, and
it was assuming that pread would never do a short read.

Fix these problems, and create a new helper add_file_item_extent().

Signed-off-by: Mark Harmstone <[email protected]>
Add an option --compress to mkfs.btrfs, to allow creating files
using zlib when using --rootdir.

Signed-off-by: Mark Harmstone <[email protected]>
Allow --compress to work with zstd, when compiled in.

Signed-off-by: Mark Harmstone <[email protected]>
Allow --compress to work with lzo.

Signed-off-by: Mark Harmstone <[email protected]>
@maharmstone
Copy link
Contributor Author

Qu, can you please give this latest version a go?

In addition to the issues mentioned above, I've changed zlib_compress_inline_extent etc. so that like zlib_compress_extent etc. they return the size of the compressed data, rather than putting it in a pointer. I've also removed the confusing 0 / -E2BIG distinction, and put the logic in the caller instead.

@adam900710
Copy link
Collaborator

Looks very good to me now.

I'll merge it after manually verifying the resulted image. You may want to add another series just for the extra test cases.

@adam900710 adam900710 merged commit 3166a31 into kdave:devel Dec 13, 2024
2 checks passed
@adam900710
Copy link
Collaborator

I manually checked the following points, and hopes it will help your next test cases:

  • Super incompat flags for ZSTD and LZO (zlib is supported by default)
  • Incompressible file detection (using /dev/random)
  • Resulted file extents (proper zstd/lzo/zlib compression)
  • Inode flags (should have compression flag)
  • With ZSTD/LZO disabled, compile should pass and using that algo should error out
    LZO failed to compile, fixed in the devel branch now.
    Not sure how we can test the disabled algo, IIRC we have no previous example to test such disable features.
    (maybe NOTRUN if the feature is enabled?)

@maharmstone
Copy link
Contributor Author

Thanks Qu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants