btrfs-progs: sync file-item.h into progs

This patch syncs file-item.h into btrfs-progs.  This carries with it an
API change for btrfs_del_csums, which takes a root argument in the
kernel, so all callsites have been updated accordingly.

I didn't sync file-item.c because it carries with it a bunch of bio
related helpers which are difficult to adapt to the kernel.
Additionally there's a few helpers in the local copy of file-item.c that
aren't in the kernel that are required for different tools.

This requires more cleanups in both the kernel and progs in order to
sync file-item.c, so for now just do file-item.h in order to pull things
out of ctree.h.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Josef Bacik 2023-04-19 17:17:17 -04:00 committed by David Sterba
parent c979ffd787
commit f8efe9f724
18 changed files with 126 additions and 57 deletions

View File

@ -28,6 +28,7 @@
#include "kernel-shared/disk-io.h"
#include "kernel-shared/transaction.h"
#include "kernel-shared/extent_io.h"
#include "kernel-shared/file-item.h"
#include "common/utils.h"
#include "common/help.h"
#include "common/extent-cache.h"
@ -1098,7 +1099,7 @@ static int delete_csum(struct btrfs_root *root, u64 bytenr, u64 bytes)
return ret;
}
ret = btrfs_del_csums(trans, bytenr, bytes);
ret = btrfs_del_csums(trans, root, bytenr, bytes);
if (ret)
error("error deleting csums %d", ret);
btrfs_commit_transaction(trans, root);

View File

@ -21,6 +21,7 @@
#include "kernel-shared/free-space-tree.h"
#include "kernel-shared/volumes.h"
#include "kernel-shared/transaction.h"
#include "kernel-shared/file-item.h"
#include "common/internal.h"
#include "common/messages.h"
#include "check/common.h"
@ -465,6 +466,7 @@ int truncate_free_ino_items(struct btrfs_root *root)
while (1) {
struct extent_buffer *leaf;
struct btrfs_file_extent_item *fi;
struct btrfs_root *csum_root;
struct btrfs_key found_key;
u8 found_type;
@ -523,7 +525,10 @@ int truncate_free_ino_items(struct btrfs_root *root)
goto out;
}
ret = btrfs_del_csums(trans, extent_disk_bytenr,
csum_root = btrfs_csum_root(trans->fs_info,
extent_disk_bytenr);
ret = btrfs_del_csums(trans, csum_root,
extent_disk_bytenr,
extent_num_bytes);
if (ret < 0) {
btrfs_abort_transaction(trans, ret);

View File

@ -42,6 +42,7 @@
#include "kernel-shared/free-space-tree.h"
#include "kernel-shared/backref.h"
#include "kernel-shared/ulist.h"
#include "kernel-shared/file-item.h"
#include "common/defs.h"
#include "common/extent-cache.h"
#include "common/internal.h"

View File

@ -28,6 +28,7 @@
#include "kernel-shared/volumes.h"
#include "kernel-shared/backref.h"
#include "kernel-shared/compression.h"
#include "kernel-shared/file-item.h"
#include "common/internal.h"
#include "common/messages.h"
#include "common/utils.h"
@ -1311,7 +1312,7 @@ static int fill_csum_tree_from_one_fs_root(struct btrfs_trans_handle *trans,
if (type == BTRFS_FILE_EXTENT_PREALLOC) {
start += btrfs_file_extent_offset(node, fi);
len = btrfs_file_extent_num_bytes(node, fi);
ret = btrfs_del_csums(trans, start, len);
ret = btrfs_del_csums(trans, csum_root, start, len);
if (ret < 0)
goto out;
}
@ -1473,7 +1474,8 @@ static int remove_csum_for_file_extent(u64 ino, u64 offset, u64 rootid, void *ct
btrfs_release_path(&path);
/* Now delete the csum for the preallocated or nodatasum range */
ret = btrfs_del_csums(trans, disk_bytenr, disk_len);
root = btrfs_csum_root(fs_info, disk_bytenr);
ret = btrfs_del_csums(trans, root, disk_bytenr, disk_len);
out:
btrfs_release_path(&path);
return ret;

View File

@ -30,6 +30,7 @@
#include "kernel-shared/backref.h"
#include "kernel-shared/compression.h"
#include "kernel-shared/volumes.h"
#include "kernel-shared/file-item.h"
#include "common/messages.h"
#include "common/internal.h"
#include "common/utils.h"

View File

@ -28,6 +28,7 @@
#include "kernel-shared/ctree.h"
#include "kernel-shared/disk-io.h"
#include "kernel-shared/extent_io.h"
#include "kernel-shared/file-item.h"
#include "common/utils.h"
#include "common/help.h"
#include "common/messages.h"

View File

@ -44,6 +44,7 @@
#include "kernel-shared/volumes.h"
#include "kernel-shared/extent_io.h"
#include "kernel-shared/compression.h"
#include "kernel-shared/file-item.h"
#include "common/utils.h"
#include "common/help.h"
#include "common/open-utils.h"

View File

@ -99,6 +99,7 @@
#include "kernel-shared/disk-io.h"
#include "kernel-shared/volumes.h"
#include "kernel-shared/transaction.h"
#include "kernel-shared/file-item.h"
#include "crypto/hash.h"
#include "common/defs.h"
#include "common/extent-cache.h"

View File

@ -27,6 +27,7 @@
#include <string.h>
#include "kernel-lib/sizes.h"
#include "kernel-shared/transaction.h"
#include "kernel-shared/file-item.h"
#include "common/extent-cache.h"
#include "common/messages.h"
#include "convert/common.h"

View File

@ -31,6 +31,7 @@
#include "kernel-shared/disk-io.h"
#include "kernel-shared/transaction.h"
#include "kernel-shared/extent_io.h"
#include "kernel-shared/file-item.h"
#include "common/extent-cache.h"
#include "common/internal.h"
#include "common/messages.h"

View File

@ -40,6 +40,7 @@
#include "kernel-shared/transaction.h"
#include "kernel-shared/volumes.h"
#include "kernel-shared/extent_io.h"
#include "kernel-shared/file-item.h"
#include "crypto/crc32c.h"
#include "crypto/hash.h"
#include "common/internal.h"

View File

@ -431,14 +431,6 @@ static inline u32 BTRFS_NODEPTRS_PER_EXTENT_BUFFER(const struct extent_buffer *e
return BTRFS_LEAF_DATA_SIZE(eb->fs_info) / sizeof(struct btrfs_key_ptr);
}
#define BTRFS_FILE_EXTENT_INLINE_DATA_START \
(offsetof(struct btrfs_file_extent_item, disk_bytenr))
static inline u32 BTRFS_MAX_INLINE_DATA_SIZE(const struct btrfs_fs_info *info)
{
return BTRFS_MAX_ITEM_SIZE(info) -
BTRFS_FILE_EXTENT_INLINE_DATA_START;
}
static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info)
{
return BTRFS_MAX_ITEM_SIZE(info) - sizeof(struct btrfs_dir_item);
@ -719,19 +711,6 @@ static inline u8 *btrfs_dev_extent_chunk_tree_uuid(struct btrfs_dev_extent *dev)
return (u8 *)((unsigned long)dev + ptr);
}
static inline unsigned long btrfs_file_extent_inline_start(struct
btrfs_file_extent_item *e)
{
unsigned long offset = (unsigned long)e;
offset += offsetof(struct btrfs_file_extent_item, disk_bytenr);
return offset;
}
static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
{
return offsetof(struct btrfs_file_extent_item, disk_bytenr) + datasize;
}
static inline u64 btrfs_dev_stats_value(const struct extent_buffer *eb,
const struct btrfs_dev_stats_item *ptr,
int index)
@ -745,17 +724,6 @@ static inline u64 btrfs_dev_stats_value(const struct extent_buffer *eb,
return val;
}
/*
* this returns the number of bytes used by the item on disk, minus the
* size of any extent headers. If a file is compressed on disk, this is
* the compressed size
*/
static inline u32 btrfs_file_extent_inline_item_len(struct extent_buffer *eb,
int nr)
{
return btrfs_item_size(eb, nr) - BTRFS_FILE_EXTENT_INLINE_DATA_START;
}
/* struct btrfs_ioctl_search_header */
static inline u64 btrfs_search_header_transid(struct btrfs_ioctl_search_header *sh)
{
@ -1091,19 +1059,6 @@ int btrfs_del_inode_ref(struct btrfs_trans_handle *trans,
struct btrfs_root *root, const char *name, int name_len,
u64 ino, u64 parent_ino, u64 *index);
/* file-item.c */
int btrfs_del_csums(struct btrfs_trans_handle *trans, u64 bytenr, u64 len);
int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
u64 objectid, u64 pos, u64 offset,
u64 disk_num_bytes,
u64 num_bytes);
int btrfs_insert_inline_extent(struct btrfs_trans_handle *trans,
struct btrfs_root *root, u64 objectid,
u64 offset, const char *buffer, size_t size);
int btrfs_csum_file_block(struct btrfs_trans_handle *trans, u64 alloc_end,
u64 bytenr, char *data, size_t len);
/* uuid-tree.c, interface for mounted mounted filesystem */
int btrfs_lookup_uuid_subvol_item(int fd, const u8 *uuid, u64 *subvol_id);
int btrfs_lookup_uuid_received_subvol_item(int fd, const u8 *uuid,

View File

@ -27,11 +27,12 @@
#include "kernel-shared/disk-io.h"
#include "kernel-shared/print-tree.h"
#include "kernel-shared/transaction.h"
#include "crypto/crc32c.h"
#include "kernel-shared/volumes.h"
#include "kernel-shared/free-space-cache.h"
#include "kernel-shared/free-space-tree.h"
#include "kernel-shared/zoned.h"
#include "kernel-shared/file-item.h"
#include "crypto/crc32c.h"
#include "common/utils.h"
#define PENDING_EXTENT_INSERT 0
@ -2115,7 +2116,11 @@ static int __free_extent(struct btrfs_trans_handle *trans,
btrfs_release_path(path);
if (is_data) {
ret = btrfs_del_csums(trans, bytenr, num_bytes);
struct btrfs_root *csum_root;
csum_root = btrfs_csum_root(trans->fs_info, bytenr);
ret = btrfs_del_csums(trans, csum_root, bytenr,
num_bytes);
BUG_ON(ret);
}

View File

@ -23,6 +23,7 @@
#include "kernel-shared/disk-io.h"
#include "kernel-shared/transaction.h"
#include "kernel-shared/print-tree.h"
#include "kernel-shared/file-item.h"
#include "crypto/crc32c.h"
#include "common/internal.h"
@ -400,7 +401,8 @@ static noinline int truncate_one_csum(struct btrfs_root *root,
* deletes the csum items from the csum tree for a given
* range of bytes.
*/
int btrfs_del_csums(struct btrfs_trans_handle *trans, u64 bytenr, u64 len)
int btrfs_del_csums(struct btrfs_trans_handle *trans, struct btrfs_root *root,
u64 bytenr, u64 len)
{
struct btrfs_path *path;
struct btrfs_key key;
@ -410,7 +412,6 @@ int btrfs_del_csums(struct btrfs_trans_handle *trans, u64 bytenr, u64 len)
int ret;
u16 csum_size = trans->fs_info->csum_size;
int blocksize = trans->fs_info->sectorsize;
struct btrfs_root *csum_root = btrfs_csum_root(trans->fs_info, bytenr);
path = btrfs_alloc_path();
if (!path)
@ -421,7 +422,7 @@ int btrfs_del_csums(struct btrfs_trans_handle *trans, u64 bytenr, u64 len)
key.offset = end_byte - 1;
key.type = BTRFS_EXTENT_CSUM_KEY;
ret = btrfs_search_slot(trans, csum_root, &key, path, -1, 1);
ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
if (ret > 0) {
if (path->slots[0] == 0)
goto out;
@ -448,7 +449,7 @@ int btrfs_del_csums(struct btrfs_trans_handle *trans, u64 bytenr, u64 len)
/* delete the entire item, it is inside our range */
if (key.offset >= bytenr && csum_end <= end_byte) {
ret = btrfs_del_item(trans, csum_root, path);
ret = btrfs_del_item(trans, root, path);
BUG_ON(ret);
} else if (key.offset < bytenr && csum_end > end_byte) {
unsigned long offset;
@ -488,13 +489,13 @@ int btrfs_del_csums(struct btrfs_trans_handle *trans, u64 bytenr, u64 len)
* btrfs_split_item returns -EAGAIN when the
* item changed size or key
*/
ret = btrfs_split_item(trans, csum_root, path, &key,
ret = btrfs_split_item(trans, root, path, &key,
offset);
BUG_ON(ret && ret != -EAGAIN);
key.offset = end_byte - 1;
} else {
ret = truncate_one_csum(csum_root, path, &key, bytenr,
ret = truncate_one_csum(root, path, &key, bytenr,
len);
BUG_ON(ret);
}

89
kernel-shared/file-item.h Normal file
View File

@ -0,0 +1,89 @@
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef BTRFS_FILE_ITEM_H
#define BTRFS_FILE_ITEM_H
#include "kerncompat.h"
#include "kernel-shared/accessors.h"
struct bio;
struct inode;
struct btrfs_ordered_sum;
struct btrfs_inode;
struct extent_map;
#define BTRFS_FILE_EXTENT_INLINE_DATA_START \
(offsetof(struct btrfs_file_extent_item, disk_bytenr))
static inline u32 BTRFS_MAX_INLINE_DATA_SIZE(const struct btrfs_fs_info *info)
{
return BTRFS_MAX_ITEM_SIZE(info) -
BTRFS_FILE_EXTENT_INLINE_DATA_START;
}
/*
* Returns the number of bytes used by the item on disk, minus the size of any
* extent headers. If a file is compressed on disk, this is the compressed
* size.
*/
static inline u32 btrfs_file_extent_inline_item_len(
const struct extent_buffer *eb,
int nr)
{
return btrfs_item_size(eb, nr) - BTRFS_FILE_EXTENT_INLINE_DATA_START;
}
static inline unsigned long btrfs_file_extent_inline_start(
const struct btrfs_file_extent_item *e)
{
return (unsigned long)e + BTRFS_FILE_EXTENT_INLINE_DATA_START;
}
static inline u32 btrfs_file_extent_calc_inline_size(u32 datasize)
{
return BTRFS_FILE_EXTENT_INLINE_DATA_START + datasize;
}
int btrfs_del_csums(struct btrfs_trans_handle *trans,
struct btrfs_root *root, u64 bytenr, u64 len);
blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio, u8 *dst);
int btrfs_insert_hole_extent(struct btrfs_trans_handle *trans,
struct btrfs_root *root, u64 objectid, u64 pos,
u64 num_bytes);
int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
struct btrfs_path *path, u64 objectid,
u64 bytenr, int mod);
int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
struct btrfs_ordered_sum *sums);
blk_status_t btrfs_csum_one_bio(struct btrfs_inode *inode, struct bio *bio,
u64 offset, bool one_ordered);
int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end,
struct list_head *list, int search_commit,
bool nowait);
void btrfs_extent_item_to_extent_map(struct btrfs_inode *inode,
const struct btrfs_path *path,
struct btrfs_file_extent_item *fi,
struct extent_map *em);
int btrfs_inode_clear_file_extent_range(struct btrfs_inode *inode, u64 start,
u64 len);
int btrfs_inode_set_file_extent_range(struct btrfs_inode *inode, u64 start, u64 len);
void btrfs_inode_safe_disk_i_size_write(struct btrfs_inode *inode, u64 new_i_size);
u64 btrfs_file_extent_end(const struct btrfs_path *path);
/*
* MODIFIED:
* - This function doesn't exist in the kernel.
*/
int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
u64 objectid, u64 pos, u64 offset,
u64 disk_num_bytes, u64 num_bytes);
int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
u64 alloc_end, u64 bytenr, char *data, size_t len);
int btrfs_insert_inline_extent(struct btrfs_trans_handle *trans,
struct btrfs_root *root, u64 objectid,
u64 offset, const char *buffer, size_t size);
#endif

View File

@ -22,6 +22,7 @@
#include "kernel-shared/disk-io.h"
#include "kernel-shared/transaction.h"
#include "kernel-shared/compression.h"
#include "kernel-shared/file-item.h"
#include "common/utils.h"
/*

View File

@ -27,6 +27,7 @@
#include "kernel-shared/volumes.h"
#include "kernel-shared/compression.h"
#include "kernel-shared/accessors.h"
#include "kernel-shared/file-item.h"
#include "common/utils.h"
static void print_dir_item_type(struct extent_buffer *eb,

View File

@ -35,6 +35,7 @@
#include "kernel-shared/volumes.h"
#include "kernel-shared/disk-io.h"
#include "kernel-shared/transaction.h"
#include "kernel-shared/file-item.h"
#include "common/internal.h"
#include "common/messages.h"
#include "common/path-utils.h"