Skip to content

Commit c38b824

Browse files
adam900710kdave
authored andcommitted
btrfs-progs: do not generate checksum nor compress if the inode has NODATACOW or NODATASUM
Currently mkfs.btrfs --rootdir is implying data checksum, but soon we will support per-inode NODATACOW|NODATASUM flags. To support per-inode NODATACOW|NODATASUM flags: - Avoid compression if the inode has either NODATACOW|NODATASUM flag - Do not generate data checksum if the inode has either NODATACOW|NODATASUM flag. Both behaviors are the following the kernel ones. Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 8d30e00 commit c38b824

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

mkfs/rootdir.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -716,12 +716,18 @@ static int add_file_item_extent(struct btrfs_trans_handle *trans,
716716
u64 buf_size;
717717
char *write_buf;
718718
bool do_comp = g_compression != BTRFS_COMPRESS_NONE;
719+
bool datasum = true;
719720
ssize_t comp_ret;
720721
u64 flags = btrfs_stack_inode_flags(btrfs_inode);
721722

722723
if (flags & BTRFS_INODE_NOCOMPRESS)
723724
do_comp = false;
724725

726+
if ((flags & BTRFS_INODE_NODATACOW) || (flags & BTRFS_INODE_NODATASUM)) {
727+
datasum = false;
728+
do_comp = false;
729+
}
730+
725731
buf_size = do_comp ? BTRFS_MAX_COMPRESSED : MAX_EXTENT_SIZE;
726732
to_read = min(file_pos + buf_size, source->size) - file_pos;
727733

@@ -852,13 +858,15 @@ static int add_file_item_extent(struct btrfs_trans_handle *trans,
852858
return ret;
853859
}
854860

855-
for (unsigned int i = 0; i < to_write / sectorsize; i++) {
856-
ret = btrfs_csum_file_block(trans, first_block + (i * sectorsize),
861+
if (datasum) {
862+
for (unsigned int i = 0; i < to_write / sectorsize; i++) {
863+
ret = btrfs_csum_file_block(trans, first_block + (i * sectorsize),
857864
BTRFS_EXTENT_CSUM_OBJECTID,
858865
root->fs_info->csum_type,
859866
write_buf + (i * sectorsize));
860-
if (ret)
861-
return ret;
867+
if (ret)
868+
return ret;
869+
}
862870
}
863871

864872
btrfs_set_stack_file_extent_type(&stack_fi, BTRFS_FILE_EXTENT_REG);

0 commit comments

Comments
 (0)