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

Open
wants to merge 41 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
79ce9b6
libbtrfsutil: bump btrfsutil version, add release steps
kdave Sep 18, 2024
762c7e8
btrfs-progs: libbtrfsutil/python: use MANIFEST.in for headers
adam900710 Sep 21, 2024
c2c922f
btrfs-progs: libbtrfsutil/python: reuse existing README.md for long d…
adam900710 Sep 21, 2024
5d2ef32
btrfs-progs: receive: make option quiet work for chroot
s-hamann Sep 28, 2024
59f74c2
btrfs-progs: mkfs: rework --subvol CLI option
maharmstone Sep 30, 2024
6a1d4ad
btrfs-progs: mkfs: avoid dynamic allocation when doing --subvol
maharmstone Sep 30, 2024
bb1e846
btrfs-progs: tests: also test --subvol modifiers in mkfs-tests/036-ro…
maharmstone Sep 30, 2024
dbabafa
btrfs-progs: fix usage warning in common/help.c
asj Oct 11, 2024
1cc034e
btrfs-progs: docs: update 6.11 contribution graphs
kdave Jan 9, 2024
e671013
btrfs-progs: docs: add kernel changelogs for 6.9, 6.10 and 6.11
kdave Mar 11, 2024
2595fbf
btrfs-progs: docs: fix typo and dead link
maharmstone Oct 16, 2024
f6dc0e8
btrfs-progs: check: explicit holes in log tree don't get csummed
maharmstone Oct 4, 2024
175cbfc
btrfs-progs: check: handle compressed extents when checking tree log
maharmstone Oct 4, 2024
6c7d2a3
btrfs-progs: check: check main csum root if csum not in log tree
maharmstone Oct 7, 2024
9d533a6
btrfs-progs: fix the typo inside kernel-by-version.rst
adam900710 Oct 20, 2024
48655de
btrfs-progs: docs: Added DEV_ITEM object id.
hanyuwei70 Oct 15, 2024
8312024
btrfs-progs: add an image explicit hole to fsck-tests/065-valid-log-tree
maharmstone Oct 24, 2024
d260910
btrfs-progs: add an image with compressed extent to fsck-tests/065-va…
maharmstone Oct 24, 2024
58dfcf8
btrfs-progs: add an image to fsck-tests/065-valid-log-tree where csum…
maharmstone Oct 24, 2024
d2c40c1
btrfs-progs: print-tree: use ARRAY_SIZE() to replace open-coded ones
adam900710 Oct 4, 2024
010b93f
btrfs-progs: print-tree: cleanup __print_readable_flag()
adam900710 Oct 4, 2024
d72ab68
btrfs-progs: print-tree: use readable_flag_entry for inode flags
adam900710 Oct 4, 2024
5b0452d
btrfs-progs: docs: say where to get help
csnover Aug 6, 2024
b3f6300
btrfs-progs: docs: clarify transid verify error recoverability
csnover Aug 6, 2024
d832a32
btrfs-progs: docs: clarify how btrfs check works with replicas
csnover Aug 6, 2024
18dcd2d
btrfs-procs: docs: add warning about balance to replace failing device
csnover Aug 8, 2024
66f08f9
btrfs-progs: docs: enhance the scrub chapter
csnover Aug 5, 2024
f4b2a33
btrfs-progs: docs: fix double word in intro
silopolis Oct 23, 2024
324bea5
btrfs-progs: docs: fix BTRFS capitalization
silopolis Oct 23, 2024
881f1e3
btrfs-progs: docs: subvolume intro editing
silopolis Oct 23, 2024
499a049
btrfs-progs: docs: auto-repair editing
Oct 23, 2024
b5d8449
btrfs-progs: docs: checksumming editing
Oct 23, 2024
479103c
btrfs-progs: docs: add 6.12 kernel development statistics
kdave Jan 9, 2024
bc574b1
btrfs-progs: device-utils: include libgen.h for musl
martinetd Nov 19, 2024
206baf7
btrfs-progs: utils: ask_user: flush stdout after prompt
martinetd Nov 19, 2024
92c7dd2
btrfs-progs: do not call btrfs_record_file_extent() out of btrfs-convert
adam900710 Nov 5, 2024
388f493
btrfs-progs: make btrfs_insert_file_extent() accept an on-stack file …
adam900710 Nov 5, 2024
d5adf75
btrfs-progs: mkfs: refactor add_file_items()
maharmstone Nov 18, 2024
9694490
btrfs-progs: mkfs: add --compress option
maharmstone Nov 19, 2024
0e7774a
btrfs-progs: mkfs: add zstd to --compress option
maharmstone Nov 19, 2024
934b46c
btrfs-progs: mkfs: add lzo to --compress option
maharmstone Nov 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Documentation/mkfs.btrfs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,15 @@ OPTIONS

$ mkfs.btrfs -O list-all

--compress <algo>[:<level>]
Try to compress files when using *--rootdir*. Supported values for *algo* are
*no* (the default) and *zlib*. The optional value *level* is a
compression level, from 1 to 9 for ZLIB.

As with the kernel, :command:`mkfs.btrfs` won't write compressed extents when
they would be larger than the uncompressed versions, and will mark a file as
`nocompress` if its beginning is found to be incompressible.

-f|--force
Forcibly overwrite the block devices when an existing filesystem is detected.
By default, :command:`mkfs.btrfs` will utilize *libblkid* to check for any known
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -740,11 +740,11 @@ btrfsck.static: btrfs.static

mkfs.btrfs: $(mkfs_objects) $(objects) libbtrfsutil.a
@echo " [LD] $@"
$(Q)$(CC) -o $@ $^ $(LDFLAGS) $(LIBS)
$(Q)$(CC) -o $@ $^ $(LDFLAGS) $(LIBS) $(LIBS_COMP)

mkfs.btrfs.static: $(static_mkfs_objects) $(static_objects) $(static_libbtrfs_objects)
@echo " [LD] $@"
$(Q)$(CC) -o $@ $^ $(STATIC_LDFLAGS) $(STATIC_LIBS)
$(Q)$(CC) -o $@ $^ $(STATIC_LDFLAGS) $(STATIC_LIBS) $(STATIC_LIBS_COMP)

btrfstune: $(tune_objects) $(objects) libbtrfsutil.a
@echo " [LD] $@"
Expand Down
1 change: 1 addition & 0 deletions common/extent-tree-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "kernel-shared/uapi/btrfs_tree.h"
#include "kernel-shared/ctree.h"
#include "kernel-shared/disk-io.h"
#include "kernel-shared/free-space-tree.h"
#include "kernel-shared/transaction.h"
#include "common/extent-tree-utils.h"

Expand Down
1 change: 1 addition & 0 deletions common/extent-tree-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "kerncompat.h"
#include "kernel-lib/bitops.h"
#include "kernel-shared/compression.h"

struct btrfs_inode_item;
struct btrfs_path;
Expand Down
6 changes: 4 additions & 2 deletions convert/source-ext2.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,8 @@ static int ext2_create_file_extents(struct btrfs_trans_handle *trans,
if (num_bytes > inode_size)
num_bytes = inode_size;
ret = btrfs_insert_inline_extent(trans, root, objectid,
0, buffer, num_bytes);
0, buffer, num_bytes,
0, num_bytes);
if (ret)
goto fail;
nbytes = btrfs_stack_inode_nbytes(btrfs_inode) + num_bytes;
Expand Down Expand Up @@ -506,7 +507,8 @@ static int ext2_create_symlink(struct btrfs_trans_handle *trans,
pathname = (char *)&(ext2_inode->i_block[0]);
BUG_ON(pathname[inode_size] != 0);
ret = btrfs_insert_inline_extent(trans, root, objectid, 0,
pathname, inode_size);
pathname, inode_size,
0, inode_size);
btrfs_set_stack_inode_nbytes(btrfs_inode, inode_size);
return ret;
}
Expand Down
5 changes: 3 additions & 2 deletions convert/source-reiserfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,8 @@ static int reiserfs_convert_tail(struct btrfs_trans_handle *trans,
length, offset, convert_flags);

ret = btrfs_insert_inline_extent(trans, root, objectid,
offset, body, length);
offset, body, length,
0, length);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use BTRFS_COMPRESS_NONE to replace immediate number 0.

if (ret)
return ret;

Expand Down Expand Up @@ -544,7 +545,7 @@ static int reiserfs_copy_symlink(struct btrfs_trans_handle *trans,
goto fail;
}
ret = btrfs_insert_inline_extent(trans, root, objectid, 0,
symlink, len);
symlink, len, 0, len);
btrfs_set_stack_inode_nbytes(btrfs_inode, len);
fail:
pathrelse(&path);
Expand Down
8 changes: 5 additions & 3 deletions kernel-shared/file-item.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,

int btrfs_insert_inline_extent(struct btrfs_trans_handle *trans,
struct btrfs_root *root, u64 objectid,
u64 offset, const char *buffer, size_t size)
u64 offset, const char *buffer, size_t size,
enum btrfs_compression_type comp,
u64 ram_bytes)
{
struct btrfs_fs_info *fs_info = trans->fs_info;
struct btrfs_key key;
Expand Down Expand Up @@ -99,8 +101,8 @@ int btrfs_insert_inline_extent(struct btrfs_trans_handle *trans,
struct btrfs_file_extent_item);
btrfs_set_file_extent_generation(leaf, ei, trans->transid);
btrfs_set_file_extent_type(leaf, ei, BTRFS_FILE_EXTENT_INLINE);
btrfs_set_file_extent_ram_bytes(leaf, ei, size);
btrfs_set_file_extent_compression(leaf, ei, 0);
btrfs_set_file_extent_ram_bytes(leaf, ei, ram_bytes);
btrfs_set_file_extent_compression(leaf, ei, comp);
btrfs_set_file_extent_encryption(leaf, ei, 0);
btrfs_set_file_extent_other_encoding(leaf, ei, 0);

Expand Down
4 changes: 3 additions & 1 deletion kernel-shared/file-item.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "kernel-shared/ctree.h"
#include "kernel-shared/uapi/btrfs_tree.h"
#include "kernel-shared/accessors.h"
#include "kernel-shared/compression.h"

struct bio;
struct inode;
Expand Down Expand Up @@ -91,7 +92,8 @@ int btrfs_csum_file_block(struct btrfs_trans_handle *trans, u64 logical,
u64 csum_objectid, u32 csum_type, const char *data);
int btrfs_insert_inline_extent(struct btrfs_trans_handle *trans,
struct btrfs_root *root, u64 objectid,
u64 offset, const char *buffer, size_t size);
u64 offset, const char *buffer, size_t size,
enum btrfs_compression_type comp, u64 ram_bytes);
/*
* For symlink we allow up to PATH_MAX - 1 (PATH_MAX includes the terminating NUL,
* but fs doesn't store that terminating NUL).
Expand Down
45 changes: 44 additions & 1 deletion mkfs/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ static const char * const mkfs_usage[] = {
OPTLINE("-u|--subvol TYPE:SUBDIR", "create SUBDIR as subvolume rather than normal directory, can be specified multiple times"),
OPTLINE("--shrink", "(with --rootdir) shrink the filled filesystem to minimal size"),
OPTLINE("-K|--nodiscard", "do not perform whole device TRIM"),
OPTLINE("--compress ALGO[:LEVEL]", "compression algorithm and level to use; ALGO can be no (default), zlib"),
OPTLINE("-f|--force", "force overwrite of existing filesystem"),
"General:",
OPTLINE("-q|--quiet", "no messages except errors"),
Expand Down Expand Up @@ -1058,6 +1059,8 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
char *source_dir = NULL;
struct rootdir_subvol *rds;
bool has_default_subvol = false;
enum btrfs_compression_type compression = BTRFS_COMPRESS_NONE;
u64 compression_level = 0;
LIST_HEAD(subvols);

cpu_detect_flags();
Expand All @@ -1072,6 +1075,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
GETOPT_VAL_CHECKSUM,
GETOPT_VAL_GLOBAL_ROOTS,
GETOPT_VAL_DEVICE_UUID,
GETOPT_VAL_COMPRESS,
};
static const struct option long_options[] = {
{ "byte-count", required_argument, NULL, 'b' },
Expand Down Expand Up @@ -1099,6 +1103,8 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
{ "quiet", 0, NULL, 'q' },
{ "verbose", 0, NULL, 'v' },
{ "shrink", no_argument, NULL, GETOPT_VAL_SHRINK },
{ "compress", required_argument, NULL,
GETOPT_VAL_COMPRESS },
#if EXPERIMENTAL
{ "param", required_argument, NULL, GETOPT_VAL_PARAM },
{ "num-global-roots", required_argument, NULL, GETOPT_VAL_GLOBAL_ROOTS },
Expand Down Expand Up @@ -1272,6 +1278,42 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
case 'q':
bconf_be_quiet();
break;
case GETOPT_VAL_COMPRESS: {
char *colon;
size_t type_size;

if (!strcmp(optarg, "no")) {
compression = BTRFS_COMPRESS_NONE;
break;
}

colon = strstr(optarg, ":");

if (colon)
type_size = colon - optarg;
else
type_size = strlen(optarg);

if (!strncmp(optarg, "zlib", type_size)) {
compression = BTRFS_COMPRESS_ZLIB;
} else if (!strncmp(optarg, "lzo", type_size)) {
compression = BTRFS_COMPRESS_LZO;
} else if (!strncmp(optarg, "zstd", type_size)) {
compression = BTRFS_COMPRESS_ZSTD;
} else {
error("unrecognized compression type %s",
optarg);
ret = 1;
goto error;
}

if (colon)
compression_level = arg_strtou64(colon + 1);
else
compression_level = 0;

break;
}
case GETOPT_VAL_DEVICE_UUID:
strncpy_null(dev_uuid, optarg, BTRFS_UUID_UNPARSED_SIZE);
break;
Expand Down Expand Up @@ -1953,7 +1995,8 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
}

ret = btrfs_mkfs_fill_dir(trans, source_dir, root,
&subvols);
&subvols, compression,
compression_level);
if (ret) {
error("error while filling filesystem: %d", ret);
btrfs_abort_transaction(trans, ret);
Expand Down
Loading