fs: btrfs: Re-implement btrfs support using the more widely used extent buffer base code
v2 cover fs: btrfs: Re-implement btrfs support using the more widely used extent buffer base code
The branch can be fetched from github:
https://github.com/adam900710/u-boot/tree/btrfs_rebuild
The current btrfs code in U-boot is using a creative way to read on-disk data.
It's pretty simple, involving the least amount of code, but pretty different from btrfs-progs nor kernel, making it pretty hard to sync code between different projects.
This big patchset will rework the btrfs support, to use code mostly from btrfs-progs, thus all existing btrfs developers will feel at home.
During the rework, the following new features are added:
- More hash algorithm support
SHA256 and XXHASH support are added.
BLAKE2 needs more backport, will happen in a separate patchset.
- The ability to read degraded RAID1
Although we still only support one device btrfs, the new code base can choose from different copies already.
As long as new device scan interface is provided, multi-device support is pretty simple.
- More correct handling of compressed extents with offset For compressed extent with offset, we should read the whole compressed extent, decompress them, then copy the referred part.
There are some more features incoming, with the new code base it would be much easier to implement:
- Data checksum support
The check would happen in read_extent_data(), btrfs-progs has the needed facility to locate data csum.
- BLAKE2 support
Need BLAKE2 library cross ported.
For btrfs it's just several lines of modification.
- Multi-device support along wit degraded RAID support We only need an interface to scan one device without opening it. The infrastructure is already provided in this patchset.
These new features would be submitted after the patchset get merged, since the patchset is already large, I don't want to make it more scary.
Although this patchset look horribly large, most of them are code copy from btrfs-progs.
E.g extent-cache.[ch], rbtree-utils.[ch], btrfs_btree.h. And ctree.h has over 1000 lines copied just for various accessors.
While for disk-io.[ch] and volumes-io.[ch], they have some small modifications to adapt the interface of U-boot.
E.g. btrfs_device::fd is replace with blkdev_desc and disk_partition_t.
The new code for U-boot are related to the following functions:
- btrfs_readlink()
- btrfs_lookup_path()
- btrfs_read_extent_inline()
- btrfs_read_extent_reg()
- lookup_data_extent()
- btrfs_file_read()
- btrfs_list_subvols()
Thus only the following 5 patches need extra review attention:
- Patch 0017
- Patch 0019
- Patch 0023
- Patch 0024
- Patch 0025~0028
Changelog:
v2:
- Implement btrfs_list_subvols()
In v1 it's completely removed thus would cause problem if btrfsolume command is compiled in.
- Rebased to latest master
Only minor conflicts due to header changes.
- Allow next_legnth() to return value > BTRFS_NAME_LEN
Qu Wenruo (30):
fs: btrfs: Sync btrfs_btree.h from kernel
fs: btrfs: Add More checksum algorithm support to btrfs
fs: btrfs: Cross-port btrfs_read_dev_super() from btrfs-progs
fs: btrfs: Cross-port rbtree-utils from btrfs-progs
fs: btrfs: Cross-port extent-cache.[ch] from btrfs-progs
fs: btrfs: Cross-port extent-io.[ch] from btrfs-progs
fs: btrfs: Cross port structure accessor into ctree.h
fs: btrfs: Cross port volumes.[ch] from btrfs-progs
fs: btrfs: Crossport read_tree_block() from btrfs-progs
fs: btrfs: Rename struct btrfs_path to struct __btrfs_path
fs: btrfs: Rename btrfs_root to __btrfs_root
fs: btrfs: Cross port struct btrfs_root to ctree.h
fs: btrfs: Crossport btrfs_search_slot() from btrfs-progs
fs: btrfs: Crossport btrfs_read_sys_array() and
btrfs_read_chunk_tree()
fs: btrfs: Crossport open_ctree_fs_info()
fs: btrfs: Rename path resolve related functions to avoid name
conflicts
fs: btrfs: Use btrfs_readlink() to implement __btrfs_readlink()
fs: btrfs: inode: Allow next_length() to return value > BTRFS_NAME_LEN
fs: btrfs: Implement btrfs_lookup_path()
fs: btrfs: Use btrfs_iter_dir() to replace btrfs_readdir()
fs: btrfs: Use btrfs_lookup_path() to implement btrfs_exists() and
btrfs_size()
fs: btrfs: Rename btrfs_file_read() and its callees to avoid name
conflicts
fs: btrfs: Introduce btrfs_read_extent_inline() and
btrfs_read_extent_reg()
fs: btrfs: Introduce lookup_data_extent() for later use
fs: btrfs: Implement btrfs_file_read()
fs: btrfs: Introduce function to reolve path in one subvolume
fs: btrfs: Introduce function to resolve the path of one subvolume
fs: btrfs: Imeplement btrfs_list_subvols() using new infrastructure
fs: btrfs: Cleanup the old implementation
MAINTAINERS: Add btrfs mail list
MAINTAINERS | 1 + fs/btrfs/Makefile | 5 +- fs/btrfs/btrfs.c | 319 +++--- fs/btrfs/btrfs.h | 67 +- fs/btrfs/btrfs_tree.h | 766 -------------- fs/btrfs/chunk-map.c | 178 ---- fs/btrfs/common/rbtree-utils.c | 83 ++ fs/btrfs/common/rbtree-utils.h | 53 + fs/btrfs/compat.h | 88 ++ fs/btrfs/compression.c | 2 +- fs/btrfs/crypto/hash.c | 55 + fs/btrfs/crypto/hash.h | 17 + fs/btrfs/ctree.c | 866 ++++++++++++---- fs/btrfs/ctree.h | 1453 ++++++++++++++++++++++----- fs/btrfs/dir-item.c | 192 ++-- fs/btrfs/disk-io.c | 1063 ++++++++++++++++++++ fs/btrfs/disk-io.h | 50 + fs/btrfs/extent-cache.c | 318 ++++++ fs/btrfs/extent-cache.h | 104 ++ fs/btrfs/extent-io.c | 848 ++++++++++++++-- fs/btrfs/extent-io.h | 164 +++ fs/btrfs/hash.c | 38 - fs/btrfs/inode.c | 892 +++++++++++----- fs/btrfs/kernel-shared/btrfs_tree.h | 1333 ++++++++++++++++++++++++ fs/btrfs/root-tree.c | 47 + fs/btrfs/root.c | 92 -- fs/btrfs/subvolume.c | 310 ++++-- fs/btrfs/super.c | 257 ----- fs/btrfs/volumes.c | 1173 +++++++++++++++++++++ fs/btrfs/volumes.h | 204 ++++ 30 files changed, 8537 insertions(+), 2501 deletions(-) delete mode 100644 fs/btrfs/btrfs_tree.h delete mode 100644 fs/btrfs/chunk-map.c create mode 100644 fs/btrfs/common/rbtree-utils.c create mode 100644 fs/btrfs/common/rbtree-utils.h create mode 100644 fs/btrfs/compat.h create mode 100644 fs/btrfs/crypto/hash.c create mode 100644 fs/btrfs/crypto/hash.h create mode 100644 fs/btrfs/disk-io.c create mode 100644 fs/btrfs/disk-io.h create mode 100644 fs/btrfs/extent-cache.c create mode 100644 fs/btrfs/extent-cache.h create mode 100644 fs/btrfs/extent-io.h delete mode 100644 fs/btrfs/hash.c create mode 100644 fs/btrfs/kernel-shared/btrfs_tree.h create mode 100644 fs/btrfs/root-tree.c delete mode 100644 fs/btrfs/root.c delete mode 100644 fs/btrfs/super.c create mode 100644 fs/btrfs/volumes.c create mode 100644 fs/btrfs/volumes.h
Signature · 1 line
2.26.2
PATCH v2 1/30 fs: btrfs: Sync btrfs_btree.h from kernel
This version includes all needed on-disk format from kernel.
Only need to modify the include headers for u-boot, everything else is untouched.
Also, since u-boot btrfs is using a different endian convert timing (at tree block read time), it needs some forced type conversion before proper cross port.
--- fs/btrfs/btrfs.c | 3 +- fs/btrfs/btrfs_tree.h | 766 --------------- fs/btrfs/ctree.h | 214 +---- fs/btrfs/inode.c | 5 +- fs/btrfs/kernel-shared/btrfs_tree.h | 1333 +++++++++++++++++++++++++++ fs/btrfs/root.c | 2 +- fs/btrfs/subvolume.c | 2 +- 7 files changed, 1343 insertions(+), 982 deletions(-) delete mode 100644 fs/btrfs/btrfs_tree.h create mode 100644 fs/btrfs/kernel-shared/btrfs_tree.h
fs/btrfs/btrfs.c +2 -1
@@ -32,7 +32,8 @@ static int readdir_callback(const struct btrfs_root *root,char filetime[32 ], *target =NULL ;time_t mtime; -if (btrfs_lookup_inode (root, &item->location, &inode,NULL )) { +if (btrfs_lookup_inode (root, (struct btrfs_key *)&item->location, + &inode,NULL )) {printf ("%s: Cannot find inode item for directory entry %.*s!\n" , __func__, item->name_len, name);return 0 ;
fs/btrfs/btrfs_tree.h deleted +0 -766
766 lines not on this page · raw message
fs/btrfs/ctree.h +3 -211
253 lines not on this page · raw message
fs/btrfs/inode.c +3 -2
@@ -29,7 +29,7 @@ u64 btrfs_lookup_inode_ref(struct btrfs_root *root, u64 inr, *refp = *ref;if (name) { -if (ref->name_len >BTRFS_NAME_MAX ) { +if (ref->name_len >BTRFS_NAME_LEN ) {printf ("%s: inode name too long: %u\n" , __func__, ref->name_len); goto out;
@@ -255,7 +255,8 @@ u64 btrfs_lookup_path(struct btrfs_root *root, u64 inr, const char *path, type = item.type; have_inode =1 ; -if (btrfs_lookup_inode (root, &item.location, &inode_item, root)) +if (btrfs_lookup_inode (root, (struct btrfs_key *)&item.location, + &inode_item, root))return -1ULL ;if (item.type ==BTRFS_FT_SYMLINK && symlink_limit >=0 ) {
fs/btrfs/kernel-shared/btrfs_tree.h new file +1333 -0
1,333 lines not on this page · raw message
fs/btrfs/root.c +1 -1
@@ -75,7 +75,7 @@ u64 btrfs_lookup_root_ref(u64 subvolid, struct btrfs_root_ref *refp, char *name) *refp = *ref;if (name) { -if (ref->name_len >BTRFS_VOL_NAME_MAX ) { +if (ref->name_len >BTRFS_NAME_LEN ) {printf ("%s: volume name too long: %u\n" , __func__, ref->name_len); goto out;
fs/btrfs/subvolume.c +1 -1
@@ -14,7 +14,7 @@ static int get_subvol_name(u64 subvolid, char *name, int max_len)struct btrfs_inode_ref iref;struct btrfs_root root;u64 dir; -char tmp[max (BTRFS_VOL_NAME_MAX ,BTRFS_NAME_MAX )]; +char tmp[BTRFS_NAME_LEN ];char *ptr; ptr = name + max_len -1 ;
Signature · 1 line
2.26.2
PATCH v2 2/30 fs: btrfs: Add More checksum algorithm support to btrfs
In reply to Qu WenruoThis would mostly backport crypto/hash.[ch] from btrfs-progs.
The differences are:
- No blake2 support
No blake2 related library in u-boot yet.
- Use uboot xxhash/sha256 directly
No need to implement the code as U-boot has already provided the interface.
This adds the support for the following csums:
- SHA256
- XXHASH
--- fs/btrfs/Makefile | 2 +- fs/btrfs/btrfs.c | 3 ++- fs/btrfs/btrfs.h | 11 --------- fs/btrfs/crypto/hash.c | 55 ++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/crypto/hash.h | 17 +++++++++++++ fs/btrfs/dir-item.c | 1 + fs/btrfs/disk-io.c | 22 +++++++++++++++++ fs/btrfs/disk-io.h | 20 +++++++++++++++ fs/btrfs/hash.c | 38 ----------------------------- fs/btrfs/super.c | 23 +++++++++--------- 10 files changed, 130 insertions(+), 62 deletions(-) create mode 100644 fs/btrfs/crypto/hash.c create mode 100644 fs/btrfs/crypto/hash.h create mode 100644 fs/btrfs/disk-io.c create mode 100644 fs/btrfs/disk-io.h delete mode 100644 fs/btrfs/hash.c
fs/btrfs/Makefile +1 -1
@@ -3,4 +3,4 @@ # 2017 Marek Behun, CZ.NIC, marek.behun at nic.cz obj-y := btrfs.o chunk-map.o compression.o ctree.o dev.o dir-item.o \ - extent-io.o hash.o inode.o root.o subvolume.o super.o + extent-io.o inode.o root.o subvolume.o super.o crypto/hash.o disk-io.o
fs/btrfs/btrfs.c +2 -1
@@ -5,11 +5,12 @@* 2017 Marek Behun, CZ.NIC, marek.behun at nic.cz */ -#include "btrfs.h" #include <config.h> #include <malloc.h> #include <uuid.h> #include <linux/time.h> +#include "btrfs.h" +#include "crypto/hash.h" struct btrfs_info btrfs_info;
fs/btrfs/btrfs.h +0 -11
@@ -23,17 +23,6 @@ struct btrfs_info {extern struct btrfs_info btrfs_info; -/* hash.c */ -void btrfs_hash_init (void ); -u32 btrfs_crc32c (u32 ,const void *,size_t ); -u32 btrfs_csum_data (char *,u32 ,size_t ); -void btrfs_csum_final (u32 ,void *); - -static inline u64 btrfs_name_hash (const char *name,int len) -{ -return btrfs_crc32c ((u32 ) ~1 , name, len); -} -/* dev.c */ extern struct blk_desc *btrfs_blk_desc;extern struct disk_partition *btrfs_part_info;
fs/btrfs/crypto/hash.c new file +55 -0
55 lines not on this page · raw message
fs/btrfs/crypto/hash.h new file +17 -0
@@ -0,0 +1,17 @@ +#ifndef CRYPTO_HASH_H +#define CRYPTO_HASH_H + +#include <linux/types.h> + +#define CRYPTO_HASH_SIZE_MAX 32 + +void btrfs_hash_init (void ); +int hash_crc32c (const u8 *buf,size_t length,u8 *out); +int hash_xxhash (const u8 *buf,size_t length,u8 *out); +int hash_sha256 (const u8 *buf,size_t length,u8 *out); + +u32 crc32c (u32 seed,const void * data,size_t len); + +/* Blake2B is not yet supported due to lack of library */ + +#endif
fs/btrfs/dir-item.c +1 -0
@@ -6,6 +6,7 @@*/ #include "btrfs.h" +#include "disk-io.h" static int verify_dir_item (struct btrfs_dir_item *item,u32 start,u32 total) {
fs/btrfs/disk-io.c new file +22 -0
@@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0+ +#include <common.h> +#include <fs_internal.h> +#include "disk-io.h" +#include "crypto/hash.h" + +int btrfs_csum_data (u16 csum_type,const u8 *data,u8 *out,size_t len) +{ +memset (out,0 ,BTRFS_CSUM_SIZE ); + +switch (csum_type) { +case BTRFS_CSUM_TYPE_CRC32 : +return hash_crc32c (data, len, out); +case BTRFS_CSUM_TYPE_XXHASH : +return hash_xxhash (data, len, out); +case BTRFS_CSUM_TYPE_SHA256 : +return hash_sha256 (data, len, out); +default : +printf ("Unknown csum type %d\n" , csum_type); +return -EINVAL ; + } +}
fs/btrfs/disk-io.h new file +20 -0
@@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0+ +#ifndef __BTRFS_DISK_IO_H__ +#define __BTRFS_DISK_IO_H__ + +#include "crypto/hash.h" +#include "ctree.h" +#include "disk-io.h" + +static inline u64 btrfs_name_hash (const char *name,int len) +{ +u32 crc; + + crc =crc32c ((u32 )~1 , (unsigned char *)name, len); + +return (u64 )crc; +} + +int btrfs_csum_data (u16 csum_type,const u8 *data,u8 *out,size_t len); + +#endif
fs/btrfs/hash.c deleted +0 -38
@@ -1,38 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* -* BTRFS filesystem implementation for U-Boot -* -* 2017 Marek Behun, CZ.NIC, marek.behun at nic.cz -*/ - -#include "btrfs.h" -#include <u-boot/crc.h> -#include <asm/unaligned.h> - -static u32 btrfs_crc32c_table[256 ]; - -void btrfs_hash_init (void ) -{ -static int inited =0 ; - -if (!inited) { -crc32c_init (btrfs_crc32c_table,0x82F63B78 ); - inited =1 ; - } -} - -u32 btrfs_crc32c (u32 crc,const void *data,size_t length) -{ -return crc32c_cal (crc, (const char *) data, length, - btrfs_crc32c_table); -} - -u32 btrfs_csum_data (char *data,u32 seed,size_t len) -{ -return btrfs_crc32c (seed, data, len); -} - -void btrfs_csum_final (u32 crc,void *result) -{ -put_unaligned (cpu_to_le32 (~crc), (u32 *)result); -}
fs/btrfs/super.c +12 -11
@@ -11,6 +11,7 @@#include <part.h> #include <linux/compat.h> #include "btrfs.h" +#include "disk-io.h" #define BTRFS_SUPER_FLAG_SUPP (BTRFS_HEADER_FLAG_WRITTEN \ | BTRFS_HEADER_FLAG_RELOC \
@@ -61,19 +62,19 @@ static int btrfs_check_super_csum(char *raw_disk_sb) (struct btrfs_super_block *) raw_disk_sb;u16 csum_type =le16_to_cpu (disk_sb->csum_type); -if (csum_type ==BTRFS_CSUM_TYPE_CRC32 ) { -u32 crc = ~(u32 )0 ; -const int csum_size =sizeof (crc); -char result[csum_size]; +if (csum_type ==BTRFS_CSUM_TYPE_CRC32 || + csum_type ==BTRFS_CSUM_TYPE_SHA256 || + csum_type ==BTRFS_CSUM_TYPE_XXHASH ) { +u8 result[BTRFS_CSUM_SIZE ]; - crc =btrfs_csum_data (raw_disk_sb +BTRFS_CSUM_SIZE , crc, -BTRFS_SUPER_INFO_SIZE -BTRFS_CSUM_SIZE ); -btrfs_csum_final (crc, result); +btrfs_csum_data (csum_type, (u8 *)raw_disk_sb +BTRFS_CSUM_SIZE , + result,BTRFS_SUPER_INFO_SIZE -BTRFS_CSUM_SIZE ); -if (memcmp (raw_disk_sb, result, csum_size)) -return -1 ; - }else { -return -1 ; +if (memcmp (raw_disk_sb, result,BTRFS_CSUM_SIZE )) +return -EIO ; + }else if (csum_type ==BTRFS_CSUM_TYPE_BLAKE2 ){ +printf ("Blake2 csum type is not supported yet\n" ); +return -ENOTSUPP ; }return 0 ;
Signature · 1 line
2.26.2
PATCH v2 3/30 fs: btrfs: Cross-port btrfs_read_dev_super() from btrfs-progs
In reply to Qu WenruoThis patch will use generic code shared from btrfs-progs to read one super block from block device.
To support the btrfs-progs style code, the following codes are also cross-ported:
- BTRFS_SETGET_FUNC for btrfs_super_block
- btrfs_check_super() function
- Move btrfs_read_superblock() to disk-io.[ch]
Since super.c only contains pretty small amount of code, and the extra check will be covered in later root read patches.
The different between this implementation from btrfs-progs are:
- No sbflags/sb_bytenr support
Since we only need to read the primary super block (like kernel), thus sbflags/sb_bytenr used by super block recovery is not needed.
Also, this changes the following behavior of U-boot btrfs:
- Only reads the primary super block
The old implementation will read all 3 super blocks, with one non-existing backup super.
This is not correct, especially for fs created after btrfs.
Just like kernel, we only check the primary super block.
--- fs/btrfs/Makefile | 2 +- fs/btrfs/btrfs.c | 1 + fs/btrfs/compat.h | 63 +++++++++++ fs/btrfs/ctree.c | 32 ++++++ fs/btrfs/ctree.h | 67 ++++++++++++ fs/btrfs/disk-io.c | 213 +++++++++++++++++++++++++++++++++++++ fs/btrfs/disk-io.h | 7 ++ fs/btrfs/super.c | 258 --------------------------------------------- 8 files changed, 384 insertions(+), 259 deletions(-) create mode 100644 fs/btrfs/compat.h delete mode 100644 fs/btrfs/super.c
fs/btrfs/Makefile +1 -1
@@ -3,4 +3,4 @@ # 2017 Marek Behun, CZ.NIC, marek.behun at nic.cz obj-y := btrfs.o chunk-map.o compression.o ctree.o dev.o dir-item.o \ - extent-io.o inode.o root.o subvolume.o super.o crypto/hash.o disk-io.o + extent-io.o inode.o root.o subvolume.o crypto/hash.o disk-io.o
fs/btrfs/btrfs.c +1 -0
@@ -11,6 +11,7 @@#include <linux/time.h> #include "btrfs.h" #include "crypto/hash.h" +#include "disk-io.h" struct btrfs_info btrfs_info;
fs/btrfs/compat.h new file +63 -0
63 lines not on this page · raw message
fs/btrfs/ctree.c +32 -0
@@ -10,6 +10,38 @@#include <malloc.h> #include <memalign.h> +static const struct btrfs_csum { +u16 size; +const char name[14 ]; +} btrfs_csums[] = { + [BTRFS_CSUM_TYPE_CRC32 ] = {4 ,"crc32c" }, + [BTRFS_CSUM_TYPE_XXHASH ] = {8 ,"xxhash64" }, + [BTRFS_CSUM_TYPE_SHA256 ] = {32 ,"sha256" }, + [BTRFS_CSUM_TYPE_BLAKE2 ] = {32 ,"blake2" }, +}; + +u16 btrfs_super_csum_size (const struct btrfs_super_block *sb) +{ +const u16 csum_type =btrfs_super_csum_type (sb); + +return btrfs_csums[csum_type].size; +} + +const char *btrfs_super_csum_name (u16 csum_type) +{ +return btrfs_csums[csum_type].name; +} + +size_t btrfs_super_num_csums (void ) +{ +return ARRAY_SIZE (btrfs_csums); +} + +u16 btrfs_csum_type_size (u16 csum_type) +{ +return btrfs_csums[csum_type].size; +} +int btrfs_comp_keys (struct btrfs_key *a,struct btrfs_key *b) {if (a->objectid > b->objectid)
fs/btrfs/ctree.h +67 -0
83 lines not on this page · raw message
fs/btrfs/disk-io.c +213 -0
223 lines not on this page · raw message
fs/btrfs/disk-io.h +7 -0
@@ -2,10 +2,14 @@#ifndef __BTRFS_DISK_IO_H__#define __BTRFS_DISK_IO_H__ +#include <linux/sizes.h> +#include <fs_internal.h> #include "crypto/hash.h" #include "ctree.h" #include "disk-io.h" +#define BTRFS_SUPER_INFO_OFFSET SZ_64K +#define BTRFS_SUPER_INFO_SIZE SZ_4Kstatic inline u64 btrfs_name_hash (const char *name,int len) {u32 crc;
@@ -17,4 +21,7 @@ static inline u64 btrfs_name_hash(const char *name, int len)int btrfs_csum_data (u16 csum_type,const u8 *data,u8 *out,size_t len); +int btrfs_read_dev_super (struct blk_desc *desc,struct disk_partition *part, +struct btrfs_super_block *sb); +int btrfs_read_superblock (void );#endif
fs/btrfs/super.c deleted +0 -258
258 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v2 4/30 fs: btrfs: Cross-port rbtree-utils from btrfs-progs
In reply to Qu WenruoThis is needed for incoming extent-cache infrastructure.
--- fs/btrfs/Makefile | 3 +- fs/btrfs/common/rbtree-utils.c | 83 ++++++++++++++++++++++++++++++++++ fs/btrfs/common/rbtree-utils.h | 53 ++++++++++++++++++++++ 3 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 fs/btrfs/common/rbtree-utils.c create mode 100644 fs/btrfs/common/rbtree-utils.h
fs/btrfs/Makefile +2 -1
@@ -3,4 +3,5 @@ # 2017 Marek Behun, CZ.NIC, marek.behun at nic.cz obj-y := btrfs.o chunk-map.o compression.o ctree.o dev.o dir-item.o \ - extent-io.o inode.o root.o subvolume.o crypto/hash.o disk-io.o + extent-io.o inode.o root.o subvolume.o crypto/hash.o disk-io.o \ + common/rbtree-utils.o extent-cache.o
fs/btrfs/common/rbtree-utils.c new file +83 -0
83 lines not on this page · raw message
fs/btrfs/common/rbtree-utils.h new file +53 -0
53 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v2 5/30 fs: btrfs: Cross-port extent-cache.[ch] from btrfs-progs
In reply to Qu WenruoThis patch implements an infrastructure to insert/search/merge an extent range (with variable length).
This provides the basis for later extent buffer cache used in btrfs.
--- fs/btrfs/extent-cache.c | 318 ++++++++++++++++++++++++++++++++++++++++ fs/btrfs/extent-cache.h | 104 +++++++++++++ 2 files changed, 422 insertions(+) create mode 100644 fs/btrfs/extent-cache.c create mode 100644 fs/btrfs/extent-cache.h
fs/btrfs/extent-cache.c new file +318 -0
@@ -0,0 +1,318 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/* +* Cross-ported from the same named file of btrfs-progs. +* +* Minor modification to include headers. +*/ +#include <linux/kernel.h> +#include <linux/rbtree.h> +#include <linux/errno.h> +#include <linux/bug.h> +#include <stdlib.h> +#include "extent-cache.h" +#include "common/rbtree-utils.h" + +struct cache_extent_search_range { +u64 objectid; +u64 start; +u64 size; +}; + +static int cache_tree_comp_range (struct rb_node *node,void *data) +{ +struct cache_extent *entry; +struct cache_extent_search_range *range; + + range = (struct cache_extent_search_range *)data; + entry = rb_entry(node, struct cache_extent, rb_node); + +if (entry->start + entry->size <= range->start) +return 1 ; +else if (range->start + range->size <= entry->start) +return -1 ; +else +return 0 ; +} + +static int cache_tree_comp_nodes (struct rb_node *node1,struct rb_node *node2) +{ +struct cache_extent *entry; +struct cache_extent_search_range range; + + entry = rb_entry(node2, struct cache_extent, rb_node); + range.start = entry->start; + range.size = entry->size; + +return cache_tree_comp_range (node1, (void *)&range); +} + +static int cache_tree_comp_range2 (struct rb_node *node,void *data) +{ +struct cache_extent *entry; +struct cache_extent_search_range *range; + + range = (struct cache_extent_search_range *)data; + entry = rb_entry(node, struct cache_extent, rb_node); + +if (entry->objectid < range->objectid) +return 1 ; +else if (entry->objectid > range->objectid) +return -1 ; +else if (entry->start + entry->size <= range->start) +return 1 ; +else if (range->start + range->size <= entry->start) +return -1 ; +else +return 0 ; +} + +static int cache_tree_comp_nodes2 (struct rb_node *node1,struct rb_node *node2) +{ +struct cache_extent *entry; +struct cache_extent_search_range range; + + entry = rb_entry(node2, struct cache_extent, rb_node); + range.objectid = entry->objectid; + range.start = entry->start; + range.size = entry->size; + +return cache_tree_comp_range2 (node1, (void *)&range); +} + +void cache_tree_init (struct cache_tree *tree) +{ + tree->root =RB_ROOT ; +} + +static struct cache_extent *alloc_cache_extent (u64 start,u64 size) +{ +struct cache_extent *pe =malloc (sizeof (*pe)); + +if (!pe) +return pe; + + pe->objectid =0 ; + pe->start = start; + pe->size = size; +return pe; +} + +int add_cache_extent (struct cache_tree *tree,u64 start,u64 size) +{ +struct cache_extent *pe =alloc_cache_extent (start, size); +int ret; + +if (!pe) +return -ENOMEM ; + + ret =insert_cache_extent (tree, pe); +if (ret) +free (pe); + +return ret; +} + +int insert_cache_extent (struct cache_tree *tree,struct cache_extent *pe) +{ +return rb_insert (&tree->root, &pe->rb_node, cache_tree_comp_nodes); +} + +int insert_cache_extent2 (struct cache_tree *tree,struct cache_extent *pe) +{ +return rb_insert (&tree->root, &pe->rb_node, cache_tree_comp_nodes2); +} + +struct cache_extent *lookup_cache_extent (struct cache_tree *tree, +u64 start,u64 size) +{ +struct rb_node *node; +struct cache_extent *entry; +struct cache_extent_search_range range; + + range.start = start; + range.size = size; + node =rb_search (&tree->root, &range, cache_tree_comp_range,NULL ); +if (!node) +return NULL ; + + entry = rb_entry(node, struct cache_extent, rb_node); +return entry; +} + +struct cache_extent *lookup_cache_extent2 (struct cache_tree *tree, +u64 objectid,u64 start,u64 size) +{ +struct rb_node *node; +struct cache_extent *entry; +struct cache_extent_search_range range; + + range.objectid = objectid; + range.start = start; + range.size = size; + node =rb_search (&tree->root, &range, cache_tree_comp_range2,NULL ); +if (!node) +return NULL ; + + entry = rb_entry(node, struct cache_extent, rb_node); +return entry; +} + +struct cache_extent *search_cache_extent (struct cache_tree *tree,u64 start) +{ +struct rb_node *next; +struct rb_node *node; +struct cache_extent *entry; +struct cache_extent_search_range range; + + range.start = start; + range.size =1 ; + node =rb_search (&tree->root, &range, cache_tree_comp_range, &next); +if (!node) + node = next; +if (!node) +return NULL ; + + entry = rb_entry(node, struct cache_extent, rb_node); +return entry; +} + +struct cache_extent *search_cache_extent2 (struct cache_tree *tree, +u64 objectid,u64 start) +{ +struct rb_node *next; +struct rb_node *node; +struct cache_extent *entry; +struct cache_extent_search_range range; + + range.objectid = objectid; + range.start = start; + range.size =1 ; + node =rb_search (&tree->root, &range, cache_tree_comp_range2, &next); +if (!node) + node = next; +if (!node) +return NULL ; + + entry = rb_entry(node, struct cache_extent, rb_node); +return entry; +} + +struct cache_extent *first_cache_extent (struct cache_tree *tree) +{ +struct rb_node *node =rb_first (&tree->root); + +if (!node) +return NULL ; + return rb_entry(node, struct cache_extent, rb_node); +} + +struct cache_extent *last_cache_extent (struct cache_tree *tree) +{ +struct rb_node *node =rb_last (&tree->root); + +if (!node) +return NULL ; + return rb_entry(node, struct cache_extent, rb_node); +} + +struct cache_extent *prev_cache_extent (struct cache_extent *pe) +{ +struct rb_node *node =rb_prev (&pe->rb_node); + +if (!node) +return NULL ; + return rb_entry(node, struct cache_extent, rb_node); +} + +struct cache_extent *next_cache_extent (struct cache_extent *pe) +{ +struct rb_node *node =rb_next (&pe->rb_node); + +if (!node) +return NULL ; + return rb_entry(node, struct cache_extent, rb_node); +} + +void remove_cache_extent (struct cache_tree *tree,struct cache_extent *pe) +{ +rb_erase (&pe->rb_node, &tree->root); +} + +void cache_tree_free_extents (struct cache_tree *tree, +free_cache_extent free_func) +{ +struct cache_extent *ce; + +while ((ce =first_cache_extent (tree))) { +remove_cache_extent (tree, ce); +free_func (ce); + } +} + +static void free_extent_cache (struct cache_extent *pe) +{ +free (pe); +} + +void free_extent_cache_tree (struct cache_tree *tree) +{ +cache_tree_free_extents (tree, free_extent_cache); +} + +int add_merge_cache_extent (struct cache_tree *tree,u64 start,u64 size) +{ +struct cache_extent *cache; +struct cache_extent *next =NULL ; +struct cache_extent *prev =NULL ; +int next_merged =0 ; +int prev_merged =0 ; +int ret =0 ; + +if (cache_tree_empty (tree)) + goto insert; + + cache =search_cache_extent (tree, start); +if (!cache) { +/* +* Either the tree is completely empty, or the no range after +* start. +* Either way, the last cache_extent should be prev. +*/ + prev =last_cache_extent (tree); + }else if (start <= cache->start) { + next = cache; + prev =prev_cache_extent (cache); + }else { + prev = cache; + next =next_cache_extent (cache); + } + +/* +* Ensure the range to be inserted won't cover with existings +* Or we will need extra loop to do merge +*/ +BUG_ON (next && start + size > next->start); +BUG_ON (prev && prev->start + prev->size > start); + +if (next && start + size == next->start) { + next_merged =1 ; + next->size = next->start + next->size - start; + next->start = start; + } +if (prev && prev->start + prev->size == start) { + prev_merged =1 ; +if (next_merged) { + next->size = next->start + next->size - prev->start; + next->start = prev->start; +remove_cache_extent (tree, prev); +free (prev); + }else { + prev->size = start + size - prev->start; + } + } +insert: +if (!prev_merged && !next_merged) + ret =add_cache_extent (tree, start, size); +return ret; +}
fs/btrfs/extent-cache.h new file +104 -0
104 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v2 6/30 fs: btrfs: Cross-port extent-io.[ch] from btrfs-progs
In reply to Qu WenruoThis cross port brings the extent_io_tree infrastructure, with that we could finally bring in proper btrfs_fs_info structure to ctree.h.
Also with read/write_extent_buffer() implemented, also backport read/write_eb_member() to ctree.h.
--- fs/btrfs/ctree.h | 55 +++ fs/btrfs/extent-io.c | 802 ++++++++++++++++++++++++++++++++++++++++++- fs/btrfs/extent-io.h | 164 +++++++++ 3 files changed, 1020 insertions(+), 1 deletion(-) create mode 100644 fs/btrfs/extent-io.h
fs/btrfs/ctree.h +55 -0
@@ -11,8 +11,10 @@#include <common.h> #include <compiler.h> +#include <linux/rbtree.h> #include "kernel-shared/btrfs_tree.h" #include "compat.h" +#include "extent-io.h" #define BTRFS_MAX_MIRRORS 3
@@ -48,6 +50,18 @@#define BTRFS_FS_STATE_DEV_REPLACING 3#define BTRFS_FS_STATE_DUMMY_FS_INFO 4 +#define read_eb_member (eb, ptr, type, member, result) ( \ + read_extent_buffer(eb, (char *)(result), \ + ((unsigned long)(ptr)) + \ + offsetof(type, member), \ + sizeof(((type *)0)->member))) + +#define write_eb_member (eb, ptr, type, member, result) ( \ + write_extent_buffer(eb, (char *)(result), \ + ((unsigned long)(ptr)) + \ + offsetof(type, member), \ + sizeof(((type *)0)->member))) +#define BTRFS_SETGET_STACK_FUNCS (name, type, member, bits) \ static inline u##bits btrfs_##name(const type *s) \ { \
@@ -75,6 +89,47 @@ struct btrfs_root {u64 root_dirid; }; +struct btrfs_mapping_tree { +struct cache_tree cache_tree; +}; + +struct btrfs_device ; +struct btrfs_fs_info { +u8 chunk_tree_uuid[BTRFS_UUID_SIZE ]; +u8 *new_chunk_tree_uuid; +struct btrfs_root *fs_root; +struct btrfs_root *tree_root; +struct btrfs_root *chunk_root; +struct btrfs_root *csum_root; + +struct rb_root fs_root_tree; + +struct extent_io_tree extent_cache; +struct extent_io_tree free_space_cache; +struct extent_io_tree pinned_extents; +struct extent_io_tree extent_ins; +struct extent_io_tree *excluded_extents; + +struct rb_root block_group_cache_tree; +/* logical->physical extent mapping */ +struct btrfs_mapping_tree mapping_tree; + +u64 generation; +u64 last_trans_committed; + +struct btrfs_super_block *super_copy; + +u64 super_bytenr; + +/* Only support one device yet */ +struct btrfs_devvice *dev; + +/* Cached block sizes */ +u32 nodesize; +u32 sectorsize; +u32 stripesize; +}; +int btrfs_comp_keys (struct btrfs_key *,struct btrfs_key *);int btrfs_comp_keys_type (struct btrfs_key *,struct btrfs_key *);int btrfs_bin_search (union btrfs_tree_node *,struct btrfs_key *,int *);
fs/btrfs/extent-io.c +801 -1
813 lines not on this page · raw message
fs/btrfs/extent-io.h new file +164 -0
164 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v2 7/30 fs: btrfs: Cross port structure accessor into ctree.h
In reply to Qu WenruoThis will include all structure accessor from btrfs-progs/ctree.h, which is also the same as kernel ctree.h.
All these accessor handles the endian convert at runtime, and since all of them are defined as static inline functions, even we don't use them they won't take extra text space.
--- fs/btrfs/compat.h | 14 + fs/btrfs/ctree.h | 1136 ++++++++++++++++++++++++++++++++++++++++---- fs/btrfs/disk-io.h | 9 - 3 files changed, 1064 insertions(+), 95 deletions(-)
fs/btrfs/compat.h +14 -0
@@ -29,6 +29,20 @@ static inline void error(const char *fmt, ...)#define cpu_to_le8 (v) (v)#define __le8 u8 +/* +* Macros to generate set/get funcs for the struct fields +* assume there is a lefoo_to_cpu for every type, so lets make a simple +* one for u8: +*/ +#define le8_to_cpu (v) (v) +#define cpu_to_le8 (v) (v) +#define __le8 u8 + +#define get_unaligned_le8 (p) (*((u8 *)(p))) +#define get_unaligned_8 (p) (*((u8 *)(p))) +#define put_unaligned_le8 (val,p) ((*((u8 *)(p))) = (val)) +#define put_unaligned_8 (val,p) ((*((u8 *)(p))) = (val)) +/* * Read data from device specified by @desc and @part *
fs/btrfs/ctree.h +1050 -86
1,205 lines not on this page · raw message
fs/btrfs/disk-io.h +0 -9
@@ -4,20 +4,11 @@#include <linux/sizes.h> #include <fs_internal.h> -#include "crypto/hash.h" #include "ctree.h" #include "disk-io.h" #define BTRFS_SUPER_INFO_OFFSET SZ_64K#define BTRFS_SUPER_INFO_SIZE SZ_4K -static inline u64 btrfs_name_hash (const char *name,int len) -{ -u32 crc; - - crc =crc32c ((u32 )~1 , (unsigned char *)name, len); - -return (u64 )crc; -}int btrfs_csum_data (u16 csum_type,const u8 *data,u8 *out,size_t len);
Signature · 1 line
2.26.2
PATCH v2 8/30 fs: btrfs: Cross port volumes.[ch] from btrfs-progs
In reply to Qu WenruoThis patch cross ports volumes.[ch] from btrfs-progs, including:
- btrfs_map_block()
The core mechanism to map btrfs logical address to physical address. This version includes multi-device support, along with RAID56 support.
- btrfs_scan_one_device()
This is the function to register one btrfs device to the list. This is the main part of the multi-device btrfs assembling process. Although we're not going to support multiple devices until U-boot allows us to scan one device without actually opening it.
--- fs/btrfs/Makefile | 2 +- fs/btrfs/compat.h | 5 + fs/btrfs/ctree.h | 1 + fs/btrfs/volumes.c | 872 +++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/volumes.h | 202 +++++++++++ 5 files changed, 1081 insertions(+), 1 deletion(-) create mode 100644 fs/btrfs/volumes.c create mode 100644 fs/btrfs/volumes.h
fs/btrfs/Makefile +1 -1
@@ -4,4 +4,4 @@ obj-y := btrfs.o chunk-map.o compression.o ctree.o dev.o dir-item.o \ extent-io.o inode.o root.o subvolume.o crypto/hash.o disk-io.o \ - common/rbtree-utils.o extent-cache.o + common/rbtree-utils.o extent-cache.o volumes.o
fs/btrfs/compat.h +5 -0
@@ -74,4 +74,9 @@ static inline void uuid_unparse(const u8 *uuid, char *out) return uuid_bin_to_str((unsigned char *)uuid, out, 0); } +static inline int is_power_of_2 (unsigned long n) +{ +return (n !=0 && ((n & (n -1 )) ==0 )); +} +#endif
fs/btrfs/ctree.h +1 -0
@@ -12,6 +12,7 @@#include <common.h> #include <compiler.h> #include <linux/rbtree.h> +#include <linux/bug.h> #include <linux/unaligned/le_byteshift.h> #include <u-boot/crc.h> #include "kernel-shared/btrfs_tree.h"
fs/btrfs/volumes.c new file +872 -0
872 lines not on this page · raw message
fs/btrfs/volumes.h new file +202 -0
202 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v2 9/30 fs: btrfs: Crossport read_tree_block() from btrfs-progs
In reply to Qu WenruoThis is the one of the base stone function for btrfs, which will:
- Do the chunk mapping resolve
- Read data from disk
- Do various sanity check
WIth read_tree_block(), we can finally cross port needed btrfs btree operations to U-boot.
--- fs/btrfs/ctree.c | 188 +++++++++++++++++++++++- fs/btrfs/ctree.h | 50 ++++++- fs/btrfs/disk-io.c | 348 +++++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/disk-io.h | 18 ++- fs/btrfs/inode.c | 6 +- 5 files changed, 602 insertions(+), 8 deletions(-)
fs/btrfs/ctree.c +186 -2
@@ -42,7 +42,7 @@ u16 btrfs_csum_type_size(u16 csum_type)return btrfs_csums[csum_type].size; } -int btrfs_comp_keys (struct btrfs_key *a,struct btrfs_key *b) +int __btrfs_comp_keys (struct btrfs_key *a,struct btrfs_key *b) {if (a->objectid > b->objectid)return 1 ;
@@ -82,7 +82,7 @@ static int generic_bin_search(void *addr, int item_size, struct btrfs_key *key, mid = (low + high) /2 ; tmp = (struct btrfs_key *) ((u8 *) addr + mid*item_size); - ret =btrfs_comp_keys (tmp, key); + ret =__btrfs_comp_keys (tmp, key);if (ret <0 ) { low = mid +1 ;
@@ -321,3 +321,187 @@ int btrfs_next_slot(struct btrfs_path *p) p->slots[0 ]++;return 0 ; } + +int btrfs_comp_cpu_keys (const struct btrfs_key *k1,const struct btrfs_key *k2) +{ +if (k1->objectid > k2->objectid) +return 1 ; +if (k1->objectid < k2->objectid) +return -1 ; +if (k1->type > k2->type) +return 1 ; +if (k1->type < k2->type) +return -1 ; +if (k1->offset > k2->offset) +return 1 ; +if (k1->offset < k2->offset) +return -1 ; +return 0 ; +} + +static int btrfs_comp_keys (struct btrfs_disk_key *disk, +const struct btrfs_key *k2) +{ +struct btrfs_key k1; + +btrfs_disk_key_to_cpu (&k1, disk); +return btrfs_comp_cpu_keys (&k1, k2); +} + +enum btrfs_tree_block_status +btrfs_check_node (struct btrfs_fs_info *fs_info, +struct btrfs_disk_key *parent_key,struct extent_buffer *buf) +{ +int i; +struct btrfs_key cpukey; +struct btrfs_disk_key key; +u32 nritems =btrfs_header_nritems (buf); +enum btrfs_tree_block_status ret =BTRFS_TREE_BLOCK_INVALID_NRITEMS ; + +if (nritems ==0 || nritems >BTRFS_NODEPTRS_PER_BLOCK (fs_info)) + goto fail; + + ret =BTRFS_TREE_BLOCK_INVALID_PARENT_KEY ; +if (parent_key && parent_key->type) { +btrfs_node_key (buf, &key,0 ); +if (memcmp (parent_key, &key,sizeof (key))) + goto fail; + } + ret =BTRFS_TREE_BLOCK_BAD_KEY_ORDER ; +for (i =0 ; nritems >1 && i < nritems -2 ; i++) { +btrfs_node_key (buf, &key, i); +btrfs_node_key_to_cpu (buf, &cpukey, i +1 ); +if (btrfs_comp_keys (&key, &cpukey) >=0 ) + goto fail; + } +return BTRFS_TREE_BLOCK_CLEAN ; +fail: +return ret; +} + +enum btrfs_tree_block_status +btrfs_check_leaf (struct btrfs_fs_info *fs_info, +struct btrfs_disk_key *parent_key,struct extent_buffer *buf) +{ +int i; +struct btrfs_key cpukey; +struct btrfs_disk_key key; +u32 nritems =btrfs_header_nritems (buf); +enum btrfs_tree_block_status ret =BTRFS_TREE_BLOCK_INVALID_NRITEMS ; + +if (nritems *sizeof (struct btrfs_item ) > buf->len) { +fprintf (stderr,"invalid number of items %llu\n" , + (unsigned long long )buf->start); + goto fail; + } + +if (btrfs_header_level (buf) !=0 ) { + ret =BTRFS_TREE_BLOCK_INVALID_LEVEL ; +fprintf (stderr,"leaf is not a leaf %llu\n" , + (unsigned long long )btrfs_header_bytenr (buf)); + goto fail; + } +if (btrfs_leaf_free_space (buf) <0 ) { + ret =BTRFS_TREE_BLOCK_INVALID_FREE_SPACE ; +fprintf (stderr,"leaf free space incorrect %llu %d\n" , + (unsigned long long )btrfs_header_bytenr (buf), +btrfs_leaf_free_space (buf)); + goto fail; + } + +if (nritems ==0 ) +return BTRFS_TREE_BLOCK_CLEAN ; + +btrfs_item_key (buf, &key,0 ); +if (parent_key && parent_key->type && +memcmp (parent_key, &key,sizeof (key))) { + ret =BTRFS_TREE_BLOCK_INVALID_PARENT_KEY ; +fprintf (stderr,"leaf parent key incorrect %llu\n" , + (unsigned long long )btrfs_header_bytenr (buf)); + goto fail; + } +for (i =0 ; nritems >1 && i < nritems -1 ; i++) { +btrfs_item_key (buf, &key, i); +btrfs_item_key_to_cpu (buf, &cpukey, i +1 ); +if (btrfs_comp_keys (&key, &cpukey) >=0 ) { + ret =BTRFS_TREE_BLOCK_BAD_KEY_ORDER ; +fprintf (stderr,"bad key ordering %d %d\n" , i, i+1 ); + goto fail; + } +if (btrfs_item_offset_nr (buf, i) != +btrfs_item_end_nr (buf, i +1 )) { + ret =BTRFS_TREE_BLOCK_INVALID_OFFSETS ; +fprintf (stderr,"incorrect offsets %u %u\n" , +btrfs_item_offset_nr (buf, i), +btrfs_item_end_nr (buf, i +1 )); + goto fail; + } +if (i ==0 &&btrfs_item_end_nr (buf, i) != +BTRFS_LEAF_DATA_SIZE (fs_info)) { + ret =BTRFS_TREE_BLOCK_INVALID_OFFSETS ; +fprintf (stderr,"bad item end %u wanted %u\n" , +btrfs_item_end_nr (buf, i), + (unsigned )BTRFS_LEAF_DATA_SIZE (fs_info)); + goto fail; + } + } + +for (i =0 ; i < nritems; i++) { +if (btrfs_item_end_nr (buf, i) > +BTRFS_LEAF_DATA_SIZE (fs_info)) { +btrfs_item_key (buf, &key,0 ); + ret =BTRFS_TREE_BLOCK_INVALID_OFFSETS ; +fprintf (stderr,"slot end outside of leaf %llu > %llu\n" , + (unsigned long long )btrfs_item_end_nr (buf, i), + (unsigned long long )BTRFS_LEAF_DATA_SIZE ( + fs_info)); + goto fail; + } + } + +return BTRFS_TREE_BLOCK_CLEAN ; +fail: +return ret; +} + +/* +* how many bytes are required to store the items in a leaf. start +* and nr indicate which items in the leaf to check. This totals up the +* space used both by the item structs and the item data +*/ +static int leaf_space_used (struct extent_buffer *l,int start,int nr) +{ +int data_len; +int nritems =btrfs_header_nritems (l); +int end =min (nritems, start + nr) -1 ; + +if (!nr) +return 0 ; + data_len =btrfs_item_end_nr (l, start); + data_len = data_len -btrfs_item_offset_nr (l, end); + data_len +=sizeof (struct btrfs_item ) * nr; +WARN_ON (data_len <0 ); +return data_len; +} + +/* +* The space between the end of the leaf items and +* the start of the leaf data. IOW, how much room +* the leaf has left for both items and data +*/ +int btrfs_leaf_free_space (struct extent_buffer *leaf) +{ +int nritems =btrfs_header_nritems (leaf); +u32 leaf_data_size; +int ret; + +BUG_ON (leaf->fs_info && leaf->fs_info->nodesize != leaf->len); + leaf_data_size =__BTRFS_LEAF_DATA_SIZE (leaf->len); + ret = leaf_data_size -leaf_space_used (leaf,0 ,nritems); +if (ret <0 ) { +printk ("leaf free space ret %d, leaf data size %u, used %d nritems %d\n" , + ret, leaf_data_size,leaf_space_used (leaf,0 , nritems), + nritems); + } +return ret; +}
fs/btrfs/ctree.h +49 -1
72 lines not on this page · raw message
fs/btrfs/disk-io.c +348 -0
359 lines not on this page · raw message
fs/btrfs/disk-io.h +16 -2
@@ -10,9 +10,23 @@#define BTRFS_SUPER_INFO_OFFSET SZ_64K#define BTRFS_SUPER_INFO_SIZE SZ_4K -int btrfs_csum_data (u16 csum_type,const u8 *data,u8 *out,size_t len); +/* U-boot specific */ +int btrfs_read_superblock (void ); + +/* From btrfs-progs */ +int read_whole_eb (struct btrfs_fs_info *info,struct extent_buffer *eb,int mirror); +struct extent_buffer *read_tree_block (struct btrfs_fs_info *fs_info,u64 bytenr, +u64 parent_transid); +struct extent_buffer *btrfs_find_create_tree_block ( +struct btrfs_fs_info *fs_info,u64 bytenr); +struct extent_buffer *btrfs_find_tree_block (struct btrfs_fs_info *fs_info, +u64 bytenr,u32 blocksize);int btrfs_read_dev_super (struct blk_desc *desc,struct disk_partition *part,struct btrfs_super_block *sb); -int btrfs_read_superblock (void ); +int btrfs_buffer_uptodate (struct extent_buffer *buf,u64 parent_transid); +int btrfs_set_buffer_uptodate (struct extent_buffer *buf); +int btrfs_csum_data (u16 csum_type,const u8 *data,u8 *out,size_t len); +int csum_tree_block_size (struct extent_buffer *buf,u16 csum_sectorsize, +int verify,u16 csum_type);#endif
fs/btrfs/inode.c +3 -3
@@ -65,7 +65,7 @@ int btrfs_lookup_inode(const struct btrfs_root *root,if (btrfs_search_tree (&tmp_root, location, &path))return res; -if (btrfs_comp_keys (location,btrfs_path_leaf_key (&path))) +if (__btrfs_comp_keys (location,btrfs_path_leaf_key (&path))) goto out;if (item) {
@@ -98,7 +98,7 @@ int btrfs_readlink(const struct btrfs_root *root, u64 inr, char *target)if (btrfs_search_tree (root, &key, &path))return -1 ; -if (btrfs_comp_keys (&key,btrfs_path_leaf_key (&path))) +if (__btrfs_comp_keys (&key,btrfs_path_leaf_key (&path))) goto out; extent = btrfs_path_item_ptr(&path, struct btrfs_file_extent_item);
@@ -333,7 +333,7 @@ u64 btrfs_file_read(const struct btrfs_root *root, u64 inr, u64 offset,if (btrfs_search_tree (root, &key, &path))return -1ULL ; -if (btrfs_comp_keys (&key,btrfs_path_leaf_key (&path)) <0 ) { +if (__btrfs_comp_keys (&key,btrfs_path_leaf_key (&path)) <0 ) {if (btrfs_prev_slot (&path)) goto out;
Signature · 1 line
2.26.2
PATCH v2 10/30 fs: btrfs: Rename struct btrfs_path to struct __btrfs_path
In reply to Qu WenruoTo avoid name conflicting between the extent buffer based btrfs_path from btrfs-progs.
Also rename btrfs_free_path() to __btrfs_free_path() to avoid conflicts.
--- fs/btrfs/btrfs.h | 4 ++-- fs/btrfs/chunk-map.c | 4 ++-- fs/btrfs/ctree.c | 16 ++++++++-------- fs/btrfs/ctree.h | 20 ++++++++++---------- fs/btrfs/dir-item.c | 10 +++++----- fs/btrfs/extent-io.c | 4 ++-- fs/btrfs/inode.c | 16 ++++++++-------- fs/btrfs/root.c | 10 +++++----- fs/btrfs/subvolume.c | 4 ++-- 9 files changed, 44 insertions(+), 44 deletions(-)
fs/btrfs/btrfs.h +2 -2
@@ -67,10 +67,10 @@ u64 btrfs_file_read(const struct btrfs_root *, u64, u64, u64, char *);u64 btrfs_get_default_subvol_objectid (void );/* extent-io.c */ -u64 btrfs_read_extent_inline (struct btrfs_path *, +u64 btrfs_read_extent_inline (struct __btrfs_path *,struct btrfs_file_extent_item *,u64 ,u64 ,char *); -u64 btrfs_read_extent_reg (struct btrfs_path *,struct btrfs_file_extent_item *, +u64 btrfs_read_extent_reg (struct __btrfs_path *,struct btrfs_file_extent_item *,u64 ,u64 ,char *);#endif /* !__BTRFS_BTRFS_H__ */
fs/btrfs/chunk-map.c +2 -2
@@ -144,7 +144,7 @@ int btrfs_chunk_map_init(void)int btrfs_read_chunk_tree (void ) { -struct btrfs_path path; +struct __btrfs_path path;struct btrfs_key key, *found_key;struct btrfs_chunk *chunk;int res =0 ;
@@ -169,7 +169,7 @@ int btrfs_read_chunk_tree(void) } }while (!(res =btrfs_next_slot (&path))); -btrfs_free_path (&path); +__btrfs_free_path (&path);if (res <0 )return -1 ;
fs/btrfs/ctree.c +8 -8
@@ -115,7 +115,7 @@ int btrfs_bin_search(union btrfs_tree_node *p, struct btrfs_key *key,return generic_bin_search (addr, size, key, p->header.nritems, slot); } -static void clear_path (struct btrfs_path *p) +static void clear_path (struct __btrfs_path *p) {int i;
@@ -125,7 +125,7 @@ static void clear_path(struct btrfs_path *p) } } -void btrfs_free_path (struct btrfs_path *p) +void __btrfs_free_path (struct __btrfs_path *p) {int i;
@@ -182,7 +182,7 @@ static int read_tree_node(u64 physical, union btrfs_tree_node **buf) }int btrfs_search_tree (const struct btrfs_root *root,struct btrfs_key *key, -struct btrfs_path *p) +struct __btrfs_path *p) {u8 lvl, prev_lvl;int i, slot, ret;
@@ -236,13 +236,13 @@ int btrfs_search_tree(const struct btrfs_root *root, struct btrfs_key *key,return 0 ; err: -btrfs_free_path (p); +__btrfs_free_path (p);return -1 ; } -static int jump_leaf (struct btrfs_path *path,int dir) +static int jump_leaf (struct __btrfs_path *path,int dir) { -struct btrfs_path p; +struct __btrfs_path p;u32 slot;int level =1 , from_level, i;
@@ -302,7 +302,7 @@ err:return -1 ; } -int btrfs_prev_slot (struct btrfs_path *p) +int btrfs_prev_slot (struct __btrfs_path *p) {if (!p->slots[0 ])return jump_leaf (p,-1 );
@@ -311,7 +311,7 @@ int btrfs_prev_slot(struct btrfs_path *p)return 0 ; } -int btrfs_next_slot (struct btrfs_path *p) +int btrfs_next_slot (struct __btrfs_path *p) {struct btrfs_leaf *leaf = &p->nodes[0 ]->leaf;
fs/btrfs/ctree.h +10 -10
@@ -1177,7 +1177,7 @@ union btrfs_tree_node {struct btrfs_node node; }; -struct btrfs_path { +struct __btrfs_path {union btrfs_tree_node *nodes[BTRFS_MAX_LEVEL ];u32 slots[BTRFS_MAX_LEVEL ]; };
@@ -1191,20 +1191,20 @@ struct btrfs_root {int __btrfs_comp_keys (struct btrfs_key *,struct btrfs_key *);int btrfs_comp_keys_type (struct btrfs_key *,struct btrfs_key *);int btrfs_bin_search (union btrfs_tree_node *,struct btrfs_key *,int *); -void btrfs_free_path (struct btrfs_path *); +void __btrfs_free_path (struct __btrfs_path *);int btrfs_search_tree (const struct btrfs_root *,struct btrfs_key *, -struct btrfs_path *); -int btrfs_prev_slot (struct btrfs_path *); -int btrfs_next_slot (struct btrfs_path *); +struct __btrfs_path *); +int btrfs_prev_slot (struct __btrfs_path *); +int btrfs_next_slot (struct __btrfs_path *); -static inline struct btrfs_key *btrfs_path_leaf_key (struct btrfs_path *p) { +static inline struct btrfs_key *btrfs_path_leaf_key (struct __btrfs_path *p) {/* At tree read time we have converted the endian for btrfs_disk_key */ return (struct btrfs_key *)&p->nodes[0 ]->leaf.items[p->slots[0 ]].key; }static inline struct btrfs_key *btrfs_search_tree_key_type (const struct btrfs_root *root,u64 objectid, -u8 type,struct btrfs_path *path) +u8 type,struct __btrfs_path *path) {struct btrfs_key key, *res;
@@ -1217,14 +1217,14 @@ btrfs_search_tree_key_type(const struct btrfs_root *root, u64 objectid, res =btrfs_path_leaf_key (path);if (btrfs_comp_keys_type (&key, res)) { -btrfs_free_path (path); +__btrfs_free_path (path);return NULL ; }return res; } -static inline u32 btrfs_path_item_size (struct btrfs_path *p) +static inline u32 btrfs_path_item_size (struct __btrfs_path *p) {return p->nodes[0 ]->leaf.items[p->slots[0 ]].size; }
@@ -1235,7 +1235,7 @@ static inline void *__btrfs_leaf_data(struct btrfs_leaf *leaf, u32 slot) + leaf->items[slot].offset; } -static inline void *btrfs_path_leaf_data (struct btrfs_path *p) +static inline void *btrfs_path_leaf_data (struct __btrfs_path *p) {return __btrfs_leaf_data (&p->nodes[0 ]->leaf, p->slots[0 ]); }
fs/btrfs/dir-item.c +5 -5
@@ -32,7 +32,7 @@ static int verify_dir_item(struct btrfs_dir_item *item, u32 start, u32 total) }static struct btrfs_dir_item * -btrfs_match_dir_item_name (struct btrfs_path *path,const char *name, +btrfs_match_dir_item_name (struct __btrfs_path *path,const char *name,int name_len) {struct btrfs_dir_item *item;
@@ -65,7 +65,7 @@ int btrfs_lookup_dir_item(const struct btrfs_root *root, u64 dir, const char *name, int name_len, struct btrfs_dir_item *item) { - struct btrfs_path path; + struct __btrfs_path path;struct btrfs_key key;struct btrfs_dir_item *res =NULL ;
@@ -83,14 +83,14 @@ int btrfs_lookup_dir_item(const struct btrfs_root *root, u64 dir,if (res) *item = *res; out: -btrfs_free_path (&path); +__btrfs_free_path (&path);return res ?0 :-1 ; }int btrfs_readdir (const struct btrfs_root *root,u64 dir,btrfs_readdir_callback_t callback) { -struct btrfs_path path; +struct __btrfs_path path;struct btrfs_key key, *found_key;struct btrfs_dir_item *item;int res =0 ;
@@ -119,7 +119,7 @@ int btrfs_readdir(const struct btrfs_root *root, u64 dir,break ; }while (!(res =btrfs_next_slot (&path))); -btrfs_free_path (&path); +__btrfs_free_path (&path);return res <0 ?-1 :0 ; }
fs/btrfs/extent-io.c +2 -2
@@ -14,7 +14,7 @@#include "extent-io.h" #include "disk-io.h" -u64 btrfs_read_extent_inline (struct btrfs_path *path, +u64 btrfs_read_extent_inline (struct __btrfs_path *path,struct btrfs_file_extent_item *extent,u64 offset,u64 size,char *out) {
@@ -66,7 +66,7 @@ err:return -1ULL ; } -u64 btrfs_read_extent_reg (struct btrfs_path *path, +u64 btrfs_read_extent_reg (struct __btrfs_path *path,struct btrfs_file_extent_item *extent,u64 offset,u64 size,char *out) {
fs/btrfs/inode.c +8 -8
@@ -11,7 +11,7 @@u64 btrfs_lookup_inode_ref (struct btrfs_root *root,u64 inr,struct btrfs_inode_ref *refp,char *name) { -struct btrfs_path path; +struct __btrfs_path path;struct btrfs_key *key;struct btrfs_inode_ref *ref;u64 res =-1ULL ;
@@ -40,7 +40,7 @@ u64 btrfs_lookup_inode_ref(struct btrfs_root *root, u64 inr, res = key->offset; out: -btrfs_free_path (&path); +__btrfs_free_path (&path);return res; }
@@ -50,7 +50,7 @@ int btrfs_lookup_inode(const struct btrfs_root *root, struct btrfs_root *new_root) {struct btrfs_root tmp_root = *root; -struct btrfs_path path; +struct __btrfs_path path;int res =-1 ;if (location->type ==BTRFS_ROOT_ITEM_KEY ) {
@@ -79,13 +79,13 @@ int btrfs_lookup_inode(const struct btrfs_root *root, res =0 ; out: -btrfs_free_path (&path); +__btrfs_free_path (&path);return res; }int btrfs_readlink (const struct btrfs_root *root,u64 inr,char *target) { -struct btrfs_path path; +struct __btrfs_path path;struct btrfs_key key;struct btrfs_file_extent_item *extent;const char *data_ptr;
@@ -131,7 +131,7 @@ int btrfs_readlink(const struct btrfs_root *root, u64 inr, char *target) target[extent->ram_bytes] ='\0' ; res =0 ; out: -btrfs_free_path (&path); +__btrfs_free_path (&path);return res; }
@@ -320,7 +320,7 @@ u64 btrfs_lookup_path(struct btrfs_root *root, u64 inr, const char *path,u64 btrfs_file_read (const struct btrfs_root *root,u64 inr,u64 offset,u64 size,char *buf) { -struct btrfs_path path; +struct __btrfs_path path;struct btrfs_key key;struct btrfs_file_extent_item *extent;int res =0 ;
@@ -379,6 +379,6 @@ u64 btrfs_file_read(const struct btrfs_root *root, u64 inr, u64 offset,return -1ULL ; out: -btrfs_free_path (&path); +__btrfs_free_path (&path);return rd_all; }
fs/btrfs/root.c +5 -5
@@ -7,7 +7,7 @@#include "btrfs.h" -static void read_root_item (struct btrfs_path *p,struct btrfs_root_item *item) +static void read_root_item (struct __btrfs_path *p,struct btrfs_root_item *item) {u32 len;int reset =0 ;
@@ -34,7 +34,7 @@ static void read_root_item(struct btrfs_path *p, struct btrfs_root_item *item) int btrfs_find_root(u64 objectid, struct btrfs_root *root, struct btrfs_root_item *root_item) { - struct btrfs_path path; + struct __btrfs_path path; struct btrfs_root_item my_root_item; if (!btrfs_search_tree_key_type(&btrfs_info.tree_root, objectid,
@@ -51,13 +51,13 @@ int btrfs_find_root(u64 objectid, struct btrfs_root *root, root->root_dirid = root_item->root_dirid; } -btrfs_free_path (&path); +__btrfs_free_path (&path);return 0 ; }u64 btrfs_lookup_root_ref (u64 subvolid,struct btrfs_root_ref *refp,char *name) { -struct btrfs_path path; +struct __btrfs_path path;struct btrfs_key *key;struct btrfs_root_ref *ref;u64 res =-1ULL ;
@@ -86,7 +86,7 @@ u64 btrfs_lookup_root_ref(u64 subvolid, struct btrfs_root_ref *refp, char *name) res = key->offset; out: -btrfs_free_path (&path); +__btrfs_free_path (&path);return res; }
fs/btrfs/subvolume.c +2 -2
@@ -81,7 +81,7 @@ u64 btrfs_get_default_subvol_objectid(void)static void list_subvols (u64 tree,char *nameptr,int max_name_len,int level) {struct btrfs_key key, *found_key; -struct btrfs_path path; +struct __btrfs_path path;struct btrfs_root_ref *ref;int res;
@@ -116,7 +116,7 @@ static void list_subvols(u64 tree, char *nameptr, int max_name_len, int level) "subvolumes\n", __func__); }while (!(res =btrfs_next_slot (&path))); -btrfs_free_path (&path); +__btrfs_free_path (&path); }void btrfs_list_subvols (void )
Signature · 1 line
2.26.2
PATCH v2 11/30 fs: btrfs: Rename btrfs_root to __btrfs_root
In reply to Qu WenruoThis is to avoid naming conflicts between extent buffer based btrfs_root.
--- fs/btrfs/btrfs.c | 10 +++++----- fs/btrfs/btrfs.h | 26 +++++++++++++------------- fs/btrfs/ctree.c | 2 +- fs/btrfs/ctree.h | 6 +++--- fs/btrfs/dir-item.c | 4 ++-- fs/btrfs/inode.c | 16 ++++++++-------- fs/btrfs/root.c | 2 +- fs/btrfs/subvolume.c | 2 +- 8 files changed, 34 insertions(+), 34 deletions(-)
fs/btrfs/btrfs.c +5 -5
@@ -15,7 +15,7 @@struct btrfs_info btrfs_info; -static int readdir_callback (const struct btrfs_root *root, +static int readdir_callback (const struct __btrfs_root *root,struct btrfs_dir_item *item) {static const char typestr[BTRFS_FT_MAX ][4 ] = {
@@ -116,7 +116,7 @@ int btrfs_probe(struct blk_desc *fs_dev_desc,int btrfs_ls (const char *path) { -struct btrfs_root root = btrfs_info.fs_root; +struct __btrfs_root root = btrfs_info.fs_root;u64 inr;u8 type;
@@ -142,7 +142,7 @@ int btrfs_ls(const char *path)int btrfs_exists (const char *file) { -struct btrfs_root root = btrfs_info.fs_root; +struct __btrfs_root root = btrfs_info.fs_root;u64 inr;u8 type;
@@ -153,7 +153,7 @@ int btrfs_exists(const char *file)int btrfs_size (const char *file,loff_t *size) { -struct btrfs_root root = btrfs_info.fs_root; +struct __btrfs_root root = btrfs_info.fs_root;struct btrfs_inode_item inode;u64 inr;u8 type;
@@ -178,7 +178,7 @@ int btrfs_size(const char *file, loff_t *size)int btrfs_read (const char *file,void *buf,loff_t offset,loff_t len,loff_t *actread) { -struct btrfs_root root = btrfs_info.fs_root; +struct __btrfs_root root = btrfs_info.fs_root;struct btrfs_inode_item inode;u64 inr, rd;u8 type;
fs/btrfs/btrfs.h +13 -13
@@ -14,9 +14,9 @@struct btrfs_info {struct btrfs_super_block sb; -struct btrfs_root tree_root; -struct btrfs_root fs_root; -struct btrfs_root chunk_root; +struct __btrfs_root tree_root; +struct __btrfs_root fs_root; +struct __btrfs_root chunk_root;struct rb_root chunks_root; };
@@ -42,26 +42,26 @@ u32 btrfs_decompress(u8 type, const char *, u32, char *, u32);int btrfs_read_superblock (void );/* dir-item.c */ -typedef int (*btrfs_readdir_callback_t )(const struct btrfs_root *, +typedef int (*btrfs_readdir_callback_t )(const struct __btrfs_root *,struct btrfs_dir_item *); -int btrfs_lookup_dir_item (const struct btrfs_root *,u64 ,const char *,int , +int btrfs_lookup_dir_item (const struct __btrfs_root *,u64 ,const char *,int ,struct btrfs_dir_item *); -int btrfs_readdir (const struct btrfs_root *,u64 ,btrfs_readdir_callback_t ); +int btrfs_readdir (const struct __btrfs_root *,u64 ,btrfs_readdir_callback_t );/* root.c */ -int btrfs_find_root (u64 ,struct btrfs_root *,struct btrfs_root_item *); +int btrfs_find_root (u64 ,struct __btrfs_root *,struct btrfs_root_item *);u64 btrfs_lookup_root_ref (u64 ,struct btrfs_root_ref *,char *);/* inode.c */ -u64 btrfs_lookup_inode_ref (struct btrfs_root *,u64 ,struct btrfs_inode_ref *, +u64 btrfs_lookup_inode_ref (struct __btrfs_root *,u64 ,struct btrfs_inode_ref *,char *); -int btrfs_lookup_inode (const struct btrfs_root *,struct btrfs_key *, -struct btrfs_inode_item *,struct btrfs_root *); -int btrfs_readlink (const struct btrfs_root *,u64 ,char *); -u64 btrfs_lookup_path (struct btrfs_root *,u64 ,const char *,u8 *, +int btrfs_lookup_inode (const struct __btrfs_root *,struct btrfs_key *, +struct btrfs_inode_item *,struct __btrfs_root *); +int btrfs_readlink (const struct __btrfs_root *,u64 ,char *); +u64 btrfs_lookup_path (struct __btrfs_root *,u64 ,const char *,u8 *,struct btrfs_inode_item *,int ); -u64 btrfs_file_read (const struct btrfs_root *,u64 ,u64 ,u64 ,char *); +u64 btrfs_file_read (const struct __btrfs_root *,u64 ,u64 ,u64 ,char *);/* subvolume.c */ u64 btrfs_get_default_subvol_objectid (void );
fs/btrfs/ctree.c +1 -1
@@ -181,7 +181,7 @@ static int read_tree_node(u64 physical, union btrfs_tree_node **buf)return 0 ; } -int btrfs_search_tree (const struct btrfs_root *root,struct btrfs_key *key, +int btrfs_search_tree (const struct __btrfs_root *root,struct btrfs_key *key,struct __btrfs_path *p) {u8 lvl, prev_lvl;
fs/btrfs/ctree.h +3 -3
@@ -1182,7 +1182,7 @@ struct __btrfs_path {u32 slots[BTRFS_MAX_LEVEL ]; }; -struct btrfs_root { +struct __btrfs_root {u64 objectid;u64 bytenr;u64 root_dirid;
@@ -1192,7 +1192,7 @@ int __btrfs_comp_keys(struct btrfs_key *, struct btrfs_key *);int btrfs_comp_keys_type (struct btrfs_key *,struct btrfs_key *);int btrfs_bin_search (union btrfs_tree_node *,struct btrfs_key *,int *);void __btrfs_free_path (struct __btrfs_path *); -int btrfs_search_tree (const struct btrfs_root *,struct btrfs_key *, +int btrfs_search_tree (const struct __btrfs_root *,struct btrfs_key *,struct __btrfs_path *);int btrfs_prev_slot (struct __btrfs_path *);int btrfs_next_slot (struct __btrfs_path *);
@@ -1203,7 +1203,7 @@ static inline struct btrfs_key *btrfs_path_leaf_key(struct __btrfs_path *p) { }static inline struct btrfs_key * -btrfs_search_tree_key_type (const struct btrfs_root *root,u64 objectid, +btrfs_search_tree_key_type (const struct __btrfs_root *root,u64 objectid,u8 type,struct __btrfs_path *path) {struct btrfs_key key, *res;
fs/btrfs/dir-item.c +2 -2
@@ -61,7 +61,7 @@ btrfs_match_dir_item_name(struct __btrfs_path *path, const char *name,return NULL ; } -int btrfs_lookup_dir_item (const struct btrfs_root *root,u64 dir, +int btrfs_lookup_dir_item (const struct __btrfs_root *root,u64 dir,const char *name,int name_len,struct btrfs_dir_item *item) {
@@ -87,7 +87,7 @@ out:return res ?0 :-1 ; } -int btrfs_readdir (const struct btrfs_root *root,u64 dir, +int btrfs_readdir (const struct __btrfs_root *root,u64 dir,btrfs_readdir_callback_t callback) {struct __btrfs_path path;
fs/btrfs/inode.c +8 -8
@@ -8,7 +8,7 @@#include "btrfs.h" #include <malloc.h> -u64 btrfs_lookup_inode_ref (struct btrfs_root *root,u64 inr, +u64 btrfs_lookup_inode_ref (struct __btrfs_root *root,u64 inr,struct btrfs_inode_ref *refp,char *name) {struct __btrfs_path path;
@@ -44,12 +44,12 @@ out:return res; } -int btrfs_lookup_inode (const struct btrfs_root *root, +int btrfs_lookup_inode (const struct __btrfs_root *root,struct btrfs_key *location,struct btrfs_inode_item *item, -struct btrfs_root *new_root) +struct __btrfs_root *new_root) { -struct btrfs_root tmp_root = *root; +struct __btrfs_root tmp_root = *root;struct __btrfs_path path;int res =-1 ;
@@ -83,7 +83,7 @@ out:return res; } -int btrfs_readlink (const struct btrfs_root *root,u64 inr,char *target) +int btrfs_readlink (const struct __btrfs_root *root,u64 inr,char *target) {struct __btrfs_path path;struct btrfs_key key;
@@ -137,7 +137,7 @@ out:/* inr must be a directory (for regular files with multiple hard links this function returns only one of the parents of the file) */ -static u64 get_parent_inode (struct btrfs_root *root,u64 inr, +static u64 get_parent_inode (struct __btrfs_root *root,u64 inr,struct btrfs_inode_item *inode_item) {struct btrfs_key key;
@@ -209,7 +209,7 @@ static inline const char *skip_current_directories(const char *cur)return cur; } -u64 btrfs_lookup_path (struct btrfs_root *root,u64 inr,const char *path, +u64 btrfs_lookup_path (struct __btrfs_root *root,u64 inr,const char *path,u8 *type_p,struct btrfs_inode_item *inode_item_p,int symlink_limit) {
@@ -317,7 +317,7 @@ u64 btrfs_lookup_path(struct btrfs_root *root, u64 inr, const char *path,return inr; } -u64 btrfs_file_read (const struct btrfs_root *root,u64 inr,u64 offset, +u64 btrfs_file_read (const struct __btrfs_root *root,u64 inr,u64 offset,u64 size,char *buf) {struct __btrfs_path path;
fs/btrfs/root.c +1 -1
@@ -31,7 +31,7 @@ static void read_root_item(struct __btrfs_path *p, struct btrfs_root_item *item) } } -int btrfs_find_root (u64 objectid,struct btrfs_root *root, +int btrfs_find_root (u64 objectid,struct __btrfs_root *root,struct btrfs_root_item *root_item) {struct __btrfs_path path;
fs/btrfs/subvolume.c +1 -1
@@ -12,7 +12,7 @@ static int get_subvol_name(u64 subvolid, char *name, int max_len) {struct btrfs_root_ref rref;struct btrfs_inode_ref iref; -struct btrfs_root root; +struct __btrfs_root root;u64 dir;char tmp[BTRFS_NAME_LEN ];char *ptr;
Signature · 1 line
2.26.2
PATCH v2 12/30 fs: btrfs: Cross port struct btrfs_root to ctree.h
In reply to Qu WenruoWith write related members deleted.
--- fs/btrfs/ctree.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
fs/btrfs/ctree.h +17 -0
@@ -69,6 +69,23 @@ enum btrfs_tree_block_status { BTRFS_TREE_BLOCK_INVALID_OFFSETS, }; +struct btrfs_root { +struct extent_buffer *node; +struct btrfs_root_item root_item; +struct btrfs_key root_key; +struct btrfs_fs_info *fs_info; +u64 objectid; +u64 last_trans; + +int ref_cows; +int track_dirty; + +u32 type; +u64 last_inode_alloc; + +struct rb_node rb_node; +}; +struct btrfs_device ;struct btrfs_fs_devices ;struct btrfs_fs_info {
Signature · 1 line
2.26.2
PATCH v2 13/30 fs: btrfs: Crossport btrfs_search_slot() from btrfs-progs
In reply to Qu WenruoThis patch copies the core function, btrfs_search_slot() from btrfs-progs.
This version has the following function removed:
- The ability to COW tree block
Related code is commented, as we may still need this ability later.
- The readahead functionality
That readahead is abused in kernel. Remove it completely.
With the core function in place, btrfs developers should feel at home now.
This also crossports supportive codes like btrfs_previous_item() to ctree.[ch].
--- fs/btrfs/ctree.c | 536 ++++++++++++++++++++++++++++++++++++++++++++++- fs/btrfs/ctree.h | 61 +++++- 2 files changed, 591 insertions(+), 6 deletions(-)
fs/btrfs/ctree.c +531 -5
@@ -5,10 +5,12 @@* 2017 Marek Behun, CZ.NIC, marek.behun at nic.cz */ -#include "btrfs.h" +#include <linux/kernel.h> #include <log.h> #include <malloc.h> #include <memalign.h> +#include "btrfs.h" +#include "disk-io.h" static const struct btrfs_csum { u16 size;
@@ -42,6 +44,32 @@ u16 btrfs_csum_type_size(u16 csum_type)return btrfs_csums[csum_type].size; } +struct btrfs_path *btrfs_alloc_path (void ) +{ +struct btrfs_path *path; + path =kzalloc (sizeof (struct btrfs_path ),GFP_NOFS ); +return path; +} + +void btrfs_free_path (struct btrfs_path *p) +{ +if (!p) +return ; +btrfs_release_path (p); +kfree (p); +} + +void btrfs_release_path (struct btrfs_path *p) +{ +int i; +for (i =0 ; i <BTRFS_MAX_LEVEL ; i++) { +if (!p->nodes[i]) +continue ; +free_extent_buffer (p->nodes[i]); + } +memset (p,0 ,sizeof (*p)); +} +int __btrfs_comp_keys (struct btrfs_key *a,struct btrfs_key *b) {if (a->objectid > b->objectid)
@@ -72,7 +100,17 @@ int btrfs_comp_keys_type(struct btrfs_key *a, struct btrfs_key *b)return 0 ; } -static int generic_bin_search (void *addr,int item_size,struct btrfs_key *key, +/* +* search for key in the extent_buffer. The items start at offset p, +* and they are item_size apart. There are 'max' items in p. +* +* the slot in the array is returned via slot, and it points to +* the place where you would insert key if it is not found in +* the array. +* +* slot may point to max if the key is bigger than all of the keys +*/ +static int __generic_bin_search (void *addr,int item_size,struct btrfs_key *key,int max,int *slot) {int low =0 , high = max, mid, ret;
@@ -98,7 +136,7 @@ static int generic_bin_search(void *addr, int item_size, struct btrfs_key *key,return 1 ; } -int btrfs_bin_search (union btrfs_tree_node *p,struct btrfs_key *key, +int __btrfs_bin_search (union btrfs_tree_node *p,struct btrfs_key *key,int *slot) {void *addr;
@@ -112,7 +150,7 @@ int btrfs_bin_search(union btrfs_tree_node *p, struct btrfs_key *key, size =sizeof (struct btrfs_item ); } -return generic_bin_search (addr, size, key, p->header.nritems, slot); +return __generic_bin_search (addr, size, key, p->header.nritems, slot); }static void clear_path (struct __btrfs_path *p)
@@ -209,7 +247,7 @@ int btrfs_search_tree(const struct __btrfs_root *root, struct btrfs_key *key, } prev_lvl = lvl; - ret =btrfs_bin_search (buf, key, &slot); + ret =__btrfs_bin_search (buf, key, &slot);if (ret <0 ) goto err;if (ret && slot >0 && lvl)
@@ -464,6 +502,350 @@ fail:return ret; } +static int noinline check_block(struct btrfs_fs_info *fs_info, +struct btrfs_path *path,int level) +{ +struct btrfs_disk_key key; +struct btrfs_disk_key *key_ptr =NULL ; +struct extent_buffer *parent; +enum btrfs_tree_block_status ret; + +if (path->nodes[level +1 ]) { + parent = path->nodes[level +1 ]; +btrfs_node_key (parent, &key, path->slots[level +1 ]); + key_ptr = &key; + } +if (level ==0 ) + ret =btrfs_check_leaf (fs_info, key_ptr, path->nodes[0 ]); +else + ret =btrfs_check_node (fs_info, key_ptr, path->nodes[level]); +if (ret ==BTRFS_TREE_BLOCK_CLEAN ) +return 0 ; +return -EIO ; +} + +/* +* search for key in the extent_buffer. The items start at offset p, +* and they are item_size apart. There are 'max' items in p. +* +* the slot in the array is returned via slot, and it points to +* the place where you would insert key if it is not found in +* the array. +* +* slot may point to max if the key is bigger than all of the keys +*/ +static int generic_bin_search (struct extent_buffer *eb,unsigned long p, +int item_size,const struct btrfs_key *key, +int max,int *slot) +{ +int low =0 ; +int high = max; +int mid; +int ret; +unsigned long offset; +struct btrfs_disk_key *tmp; + +while (low < high) { + mid = (low + high) /2 ; + offset = p + mid * item_size; + + tmp = (struct btrfs_disk_key *)(eb->data + offset); + ret =btrfs_comp_keys (tmp, key); + +if (ret <0 ) + low = mid +1 ; +else if (ret >0 ) + high = mid; +else { + *slot = mid; +return 0 ; + } + } + *slot = low; +return 1 ; +} + +/* +* simple bin_search frontend that does the right thing for +* leaves vs nodes +*/ +int btrfs_bin_search (struct extent_buffer *eb,const struct btrfs_key *key, +int *slot) +{ +if (btrfs_header_level (eb) ==0 ) +return generic_bin_search (eb, + offsetof(struct btrfs_leaf , items), +sizeof (struct btrfs_item ), + key,btrfs_header_nritems (eb), + slot); +else +return generic_bin_search (eb, + offsetof(struct btrfs_node , ptrs), +sizeof (struct btrfs_key_ptr ), + key,btrfs_header_nritems (eb), + slot); +} + +struct extent_buffer *read_node_slot (struct btrfs_fs_info *fs_info, +struct extent_buffer *parent,int slot) +{ +struct extent_buffer *ret; +int level =btrfs_header_level (parent); + +if (slot <0 ) +return NULL ; +if (slot >=btrfs_header_nritems (parent)) +return NULL ; + +if (level ==0 ) +return NULL ; + + ret =read_tree_block (fs_info,btrfs_node_blockptr (parent, slot), +btrfs_node_ptr_generation (parent, slot)); +if (!extent_buffer_uptodate (ret)) +return ERR_PTR (-EIO ); + +if (btrfs_header_level (ret) != level -1 ) { +error ( +"child eb corrupted: parent bytenr=%llu item=%d parent level=%d child level=%d" , +btrfs_header_bytenr (parent), slot, +btrfs_header_level (parent),btrfs_header_level (ret)); +free_extent_buffer (ret); +return ERR_PTR (-EIO ); + } +return ret; +} + +int btrfs_find_item (struct btrfs_root *fs_root,struct btrfs_path *found_path, +u64 iobjectid,u64 ioff,u8 key_type, +struct btrfs_key *found_key) +{ +int ret; +struct btrfs_key key; +struct extent_buffer *eb; +struct btrfs_path *path; + + key.type = key_type; + key.objectid = iobjectid; + key.offset = ioff; + +if (found_path ==NULL ) { + path =btrfs_alloc_path (); +if (!path) +return -ENOMEM ; + }else + path = found_path; + + ret =btrfs_search_slot (NULL , fs_root, &key, path,0 ,0 ); +if ((ret <0 ) || (found_key ==NULL )) + goto out; + + eb = path->nodes[0 ]; +if (ret && path->slots[0 ] >=btrfs_header_nritems (eb)) { + ret =btrfs_next_leaf (fs_root, path); +if (ret) + goto out; + eb = path->nodes[0 ]; + } + +btrfs_item_key_to_cpu (eb, found_key, path->slots[0 ]); +if (found_key->type != key.type || + found_key->objectid != key.objectid) { + ret =1 ; + goto out; + } + +out: +if (path != found_path) +btrfs_free_path (path); +return ret; +} + +/* +* look for key in the tree. path is filled in with nodes along the way +* if key is found, we return zero and you can find the item in the leaf +* level of the path (level 0) +* +* If the key isn't found, the path points to the slot where it should +* be inserted, and 1 is returned. If there are other errors during the +* search a negative error number is returned. +* +* if ins_len > 0, nodes and leaves will be split as we walk down the +* tree. if ins_len < 0, nodes will be merged as we walk down the tree (if +* possible) +* +* NOTE: This version has no COW ability, thus we expect trans == NULL, +* ins_len == 0 and cow == 0. +*/ +int btrfs_search_slot (struct btrfs_trans_handle *trans, +struct btrfs_root *root,const struct btrfs_key *key, +struct btrfs_path *p,int ins_len,int cow) +{ +struct extent_buffer *b; +int slot; +int ret; +int level; +struct btrfs_fs_info *fs_info = root->fs_info; +u8 lowest_level =0 ; + +assert (trans ==NULL && ins_len ==0 && cow ==0 ); + lowest_level = p->lowest_level; +WARN_ON (lowest_level && ins_len >0 ); +WARN_ON (p->nodes[0 ] !=NULL ); + + b = root->node; +extent_buffer_get (b); +while (b) { + level =btrfs_header_level (b); +/* +if (cow) { +int wret; +wret = btrfs_cow_block(trans, root, b, +p->nodes[level + 1], +p->slots[level + 1], +&b); +if (wret) { +free_extent_buffer(b); +return wret; +} +} +*/ +BUG_ON (!cow && ins_len); +if (level !=btrfs_header_level (b)) +WARN_ON (1 ); + level =btrfs_header_level (b); + p->nodes[level] = b; + ret =check_block (fs_info, p, level); +if (ret) +return -1 ; + ret =btrfs_bin_search (b, key, &slot); +if (level !=0 ) { +if (ret && slot >0 ) + slot -=1 ; + p->slots[level] = slot; +/* +if ((p->search_for_split || ins_len > 0) && +btrfs_header_nritems(b) >= +BTRFS_NODEPTRS_PER_BLOCK(fs_info) - 3) { +int sret = split_node(trans, root, p, level); +BUG_ON(sret > 0); +if (sret) +return sret; +b = p->nodes[level]; +slot = p->slots[level]; +} else if (ins_len < 0) { +int sret = balance_level(trans, root, p, +level); +if (sret) +return sret; +b = p->nodes[level]; +if (!b) { +btrfs_release_path(p); +goto again; +} +slot = p->slots[level]; +BUG_ON(btrfs_header_nritems(b) == 1); +} +*/ +/* this is only true while dropping a snapshot */ +if (level == lowest_level) +break ; + + b =read_node_slot (fs_info, b, slot); +if (!extent_buffer_uptodate (b)) +return -EIO ; + }else { + p->slots[level] = slot; +/* +if (ins_len > 0 && +ins_len > btrfs_leaf_free_space(b)) { +int sret = split_leaf(trans, root, key, +p, ins_len, ret == 0); +BUG_ON(sret > 0); +if (sret) +return sret; +} +*/ +return ret; + } + } +return 1 ; +} + +/* +* Helper to use instead of search slot if no exact match is needed but +* instead the next or previous item should be returned. +* When find_higher is true, the next higher item is returned, the next lower +* otherwise. +* When return_any and find_higher are both true, and no higher item is found, +* return the next lower instead. +* When return_any is true and find_higher is false, and no lower item is found, +* return the next higher instead. +* It returns 0 if any item is found, 1 if none is found (tree empty), and +* < 0 on error +*/ +int btrfs_search_slot_for_read (struct btrfs_root *root, +const struct btrfs_key *key, +struct btrfs_path *p,int find_higher, +int return_any) +{ +int ret; +struct extent_buffer *leaf; + +again: + ret =btrfs_search_slot (NULL , root, key, p,0 ,0 ); +if (ret <=0 ) +return ret; +/* +* A return value of 1 means the path is at the position where the item +* should be inserted. Normally this is the next bigger item, but in +* case the previous item is the last in a leaf, path points to the +* first free slot in the previous leaf, i.e.@an invalid item. +*/ + leaf = p->nodes[0 ]; + +if (find_higher) { +if (p->slots[0 ] >=btrfs_header_nritems (leaf)) { + ret =btrfs_next_leaf (root, p); +if (ret <=0 ) +return ret; +if (!return_any) +return 1 ; +/* +* No higher item found, return the next lower instead +*/ + return_any =0 ; + find_higher =0 ; +btrfs_release_path (p); + goto again; + } + }else { +if (p->slots[0 ] ==0 ) { + ret =btrfs_prev_leaf (root, p); +if (ret <0 ) +return ret; +if (!ret) { + leaf = p->nodes[0 ]; +if (p->slots[0 ] ==btrfs_header_nritems (leaf)) + p->slots[0 ]--; +return 0 ; + } +if (!return_any) +return 1 ; +/* +* No lower item found, return the next higher instead +*/ + return_any =0 ; + find_higher =1 ; +btrfs_release_path (p); + goto again; + }else { + --p->slots[0 ]; + } + } +return 0 ; +} +/* * how many bytes are required to store the items in a leaf. start * and nr indicate which items in the leaf to check. This totals up the
@@ -505,3 +887,147 @@ int btrfs_leaf_free_space(struct extent_buffer *leaf) }return ret; } + +/* +* walk up the tree as far as required to find the previous leaf. +* returns 0 if it found something or 1 if there are no lesser leaves. +* returns < 0 on io errors. +*/ +int btrfs_prev_leaf (struct btrfs_root *root,struct btrfs_path *path) +{ +int slot; +int level =1 ; +struct extent_buffer *c; +struct extent_buffer *next =NULL ; +struct btrfs_fs_info *fs_info = root->fs_info; + +while (level <BTRFS_MAX_LEVEL ) { +if (!path->nodes[level]) +return 1 ; + + slot = path->slots[level]; + c = path->nodes[level]; +if (slot ==0 ) { + level++; +if (level ==BTRFS_MAX_LEVEL ) +return 1 ; +continue ; + } + slot--; + + next =read_node_slot (fs_info, c, slot); +if (!extent_buffer_uptodate (next)) { +if (IS_ERR (next)) +return PTR_ERR (next); +return -EIO ; + } +break ; + } + path->slots[level] = slot; +while (1 ) { + level--; + c = path->nodes[level]; +free_extent_buffer (c); + slot =btrfs_header_nritems (next); +if (slot !=0 ) + slot--; + path->nodes[level] = next; + path->slots[level] = slot; +if (!level) +break ; + next =read_node_slot (fs_info, next, slot); +if (!extent_buffer_uptodate (next)) { +if (IS_ERR (next)) +return PTR_ERR (next); +return -EIO ; + } + } +return 0 ; +} + +/* +* Walk up the tree as far as necessary to find the next sibling tree block. +* More generic version of btrfs_next_leaf(), as it could find sibling nodes +* if @path->lowest_level is not 0. +* +* returns 0 if it found something or 1 if there are no greater leaves. +* returns < 0 on io errors. +*/ +int btrfs_next_sibling_tree_block (struct btrfs_fs_info *fs_info, +struct btrfs_path *path) +{ +int slot; +int level = path->lowest_level +1 ; +struct extent_buffer *c; +struct extent_buffer *next =NULL ; + +BUG_ON (path->lowest_level +1 >=BTRFS_MAX_LEVEL ); +do { +if (!path->nodes[level]) +return 1 ; + + slot = path->slots[level] +1 ; + c = path->nodes[level]; +if (slot >=btrfs_header_nritems (c)) { + level++; +if (level ==BTRFS_MAX_LEVEL ) +return 1 ; +continue ; + } + + next =read_node_slot (fs_info, c, slot); +if (!extent_buffer_uptodate (next)) +return -EIO ; +break ; + }while (level <BTRFS_MAX_LEVEL ); + path->slots[level] = slot; +while (1 ) { + level--; + c = path->nodes[level]; +free_extent_buffer (c); + path->nodes[level] = next; + path->slots[level] =0 ; +if (level == path->lowest_level) +break ; + next =read_node_slot (fs_info, next,0 ); +if (!extent_buffer_uptodate (next)) +return -EIO ; + } +return 0 ; +} + +int btrfs_previous_item (struct btrfs_root *root, +struct btrfs_path *path,u64 min_objectid, +int type) +{ +struct btrfs_key found_key; +struct extent_buffer *leaf; +u32 nritems; +int ret; + +while (1 ) { +if (path->slots[0 ] ==0 ) { + ret =btrfs_prev_leaf (root, path); +if (ret !=0 ) +return ret; + }else { + path->slots[0 ]--; + } + leaf = path->nodes[0 ]; + nritems =btrfs_header_nritems (leaf); +if (nritems ==0 ) +return 1 ; +if (path->slots[0 ] == nritems) + path->slots[0 ]--; + +btrfs_item_key_to_cpu (leaf, &found_key, path->slots[0 ]); +if (found_key.objectid < min_objectid) +break ; +if (found_key.type == type) +return 0 ; +if (found_key.objectid == min_objectid && + found_key.type < type) +break ; + } +return 1 ; +}
fs/btrfs/ctree.h +60 -1
84 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v2 14/30 fs: btrfs: Crossport btrfs_read_sys_array() and btrfs_read_chunk_tree()
In reply to Qu WenruoThese two functions play a big role in btrfs bootstrap.
The following function is removed:
- Seed device support
Although in theory we can still support multiple devices, we don't have a facility in U-boot to do device scan without opening them.
--- fs/btrfs/btrfs.c | 2 +- fs/btrfs/btrfs.h | 2 +- fs/btrfs/chunk-map.c | 2 +- fs/btrfs/volumes.c | 301 +++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/volumes.h | 2 + 5 files changed, 306 insertions(+), 3 deletions(-)
fs/btrfs/btrfs.c +1 -1
@@ -100,7 +100,7 @@ int btrfs_probe(struct blk_desc *fs_dev_desc, btrfs_info.chunk_root.objectid =0 ; btrfs_info.chunk_root.bytenr = btrfs_info.sb.chunk_root; -if (btrfs_read_chunk_tree ()) { +if (__btrfs_read_chunk_tree ()) {printf ("%s: failed to read chunk tree\n" , __func__);return -1 ; }
fs/btrfs/btrfs.h +1 -1
@@ -33,7 +33,7 @@ int btrfs_devread(u64, int, void *);u64 btrfs_map_logical_to_physical (u64 );int btrfs_chunk_map_init (void );void btrfs_chunk_map_exit (void ); -int btrfs_read_chunk_tree (void ); +int __btrfs_read_chunk_tree (void );/* compression.c */ u32 btrfs_decompress (u8 type,const char *,u32 ,char *,u32 );
fs/btrfs/chunk-map.c +1 -1
@@ -142,7 +142,7 @@ int btrfs_chunk_map_init(void)return 0 ; } -int btrfs_read_chunk_tree (void ) +int __btrfs_read_chunk_tree (void ) {struct __btrfs_path path;struct btrfs_key key, *found_key;
fs/btrfs/volumes.c +301 -0
319 lines not on this page · raw message
fs/btrfs/volumes.h +2 -0
@@ -182,6 +182,8 @@ static inline int btrfs_next_bg_system(struct btrfs_fs_info *fs_info,return btrfs_next_bg (fs_info, logical, size,BTRFS_BLOCK_GROUP_SYSTEM ); } +int btrfs_read_sys_array (struct btrfs_fs_info *fs_info); +int btrfs_read_chunk_tree (struct btrfs_fs_info *fs_info);int btrfs_open_devices (struct btrfs_fs_devices *fs_devices);int btrfs_close_devices (struct btrfs_fs_devices *fs_devices);void btrfs_close_all_devices (void );
Signature · 1 line
2.26.2
PATCH v2 15/30 fs: btrfs: Crossport open_ctree_fs_info()
In reply to Qu Wenruoopen_ctree_fs_info() is the main entry point to open a btrfs.
This version is a simplfied version of __open_ctree_fd() of btrfs-progs, the main differences are:
- Parameters on how to specify a block device
Instead of @fd and @path, uboot uses blk_desc and disk_partition_t.
- Remove open_ctree flags
There will not be multiple open ctree modes in uboot.
Otherwise the function structure are all kept the same.
With open_ctree_fs_info() implemented, also introduce the global current_fs_info pointer to show the current opened btrfs.
--- fs/btrfs/Makefile | 2 +- fs/btrfs/btrfs.c | 15 +- fs/btrfs/btrfs.h | 1 + fs/btrfs/compat.h | 2 + fs/btrfs/ctree.h | 4 + fs/btrfs/disk-io.c | 510 +++++++++++++++++++++++++++++++++++++++++-- fs/btrfs/disk-io.h | 19 ++ fs/btrfs/root-tree.c | 47 ++++ 8 files changed, 580 insertions(+), 20 deletions(-) create mode 100644 fs/btrfs/root-tree.c
fs/btrfs/Makefile +1 -1
@@ -4,4 +4,4 @@ obj-y := btrfs.o chunk-map.o compression.o ctree.o dev.o dir-item.o \ extent-io.o inode.o root.o subvolume.o crypto/hash.o disk-io.o \ - common/rbtree-utils.o extent-cache.o volumes.o + common/rbtree-utils.o extent-cache.o volumes.o root-tree.o
fs/btrfs/btrfs.c +14 -1
@@ -14,6 +14,7 @@#include "disk-io.h" struct btrfs_info btrfs_info; +struct btrfs_fs_info *current_fs_info;static int readdir_callback (const struct __btrfs_root *root,struct btrfs_dir_item *item)
@@ -81,6 +82,9 @@ static int readdir_callback(const struct __btrfs_root *root,int btrfs_probe (struct blk_desc *fs_dev_desc,struct disk_partition *fs_partition) { +struct btrfs_fs_info *fs_info; +int ret =-1 ; + btrfs_blk_desc = fs_dev_desc; btrfs_part_info = fs_partition;
@@ -111,7 +115,12 @@ int btrfs_probe(struct blk_desc *fs_dev_desc,return -1 ; } -return 0 ; + fs_info =open_ctree_fs_info (fs_dev_desc, fs_partition); +if (fs_info) { + current_fs_info = fs_info; + ret =0 ; + } +return ret; }int btrfs_ls (const char *path)
@@ -215,6 +224,10 @@ int btrfs_read(const char *file, void *buf, loff_t offset, loff_t len,void btrfs_close (void ) {btrfs_chunk_map_exit (); +if (current_fs_info) { +close_ctree_fs_info (current_fs_info); + current_fs_info =NULL ; + } }int btrfs_uuid (char *uuid_str)
fs/btrfs/btrfs.h +1 -0
@@ -22,6 +22,7 @@ struct btrfs_info { };extern struct btrfs_info btrfs_info; +extern struct btrfs_fs_info *current_fs_info;/* dev.c */ extern struct blk_desc *btrfs_blk_desc;
fs/btrfs/compat.h +2 -0
@@ -18,6 +18,8 @@ static inline void error(const char *fmt, ...)printf ("\n" ); } +#define ASSERT (c) assert(c) +#define BTRFS_UUID_UNPARSED_SIZE 37/*
fs/btrfs/ctree.h +4 -0
@@ -1275,6 +1275,10 @@ const char *btrfs_super_csum_name(u16 csum_type);u16 btrfs_csum_type_size (u16 csum_type);size_t btrfs_super_num_csums (void ); +/* root-tree.c */ +int btrfs_find_last_root (struct btrfs_root *root,u64 objectid, +struct btrfs_root_item *item,struct btrfs_key *key); +/* ctree.c */ int btrfs_comp_cpu_keys (const struct btrfs_key *k1,const struct btrfs_key *k2);enum btrfs_tree_block_status
fs/btrfs/disk-io.c +492 -18
525 lines not on this page · raw message
fs/btrfs/disk-io.h +19 -0
@@ -22,6 +22,25 @@ struct extent_buffer* btrfs_find_create_tree_block( struct btrfs_fs_info *fs_info, u64 bytenr);struct extent_buffer *btrfs_find_tree_block (struct btrfs_fs_info *fs_info,u64 bytenr,u32 blocksize); +struct btrfs_root *btrfs_read_fs_root_no_cache (struct btrfs_fs_info *fs_info, +struct btrfs_key *location); +struct btrfs_root *btrfs_read_fs_root (struct btrfs_fs_info *fs_info, +struct btrfs_key *location); + +void btrfs_setup_root (struct btrfs_root *root,struct btrfs_fs_info *fs_info, +u64 objectid); + +void btrfs_free_fs_info (struct btrfs_fs_info *fs_info); +struct btrfs_fs_info *btrfs_new_fs_info (void ); +int btrfs_check_fs_compatibility (struct btrfs_super_block *sb); +int btrfs_setup_all_roots (struct btrfs_fs_info *fs_info); +void btrfs_release_all_roots (struct btrfs_fs_info *fs_info); +void btrfs_cleanup_all_caches (struct btrfs_fs_info *fs_info); + +struct btrfs_fs_info *open_ctree_fs_info (struct blk_desc *desc, +struct disk_partition *part); +int close_ctree_fs_info (struct btrfs_fs_info *fs_info); +int btrfs_read_dev_super (struct blk_desc *desc,struct disk_partition *part,struct btrfs_super_block *sb);int btrfs_buffer_uptodate (struct extent_buffer *buf,u64 parent_transid);
fs/btrfs/root-tree.c new file +47 -0
47 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v2 16/30 fs: btrfs: Rename path resolve related functions to avoid name conflicts
In reply to Qu WenruoSince the old code are all using __btrfs_path/__btrfs_root other than the regular extent buffer based one, adding "__" prefix for them to avoid name conflicts in the incoming cross ports.
--- fs/btrfs/btrfs.c | 12 ++++++------ fs/btrfs/btrfs.h | 10 +++++----- fs/btrfs/compat.h | 3 +++ fs/btrfs/ctree.h | 7 +++++++ fs/btrfs/dir-item.c | 12 ++++++------ fs/btrfs/inode.c | 28 ++++++++++++++-------------- fs/btrfs/subvolume.c | 4 ++-- 7 files changed, 43 insertions(+), 33 deletions(-)
fs/btrfs/btrfs.c +6 -6
@@ -35,7 +35,7 @@ static int readdir_callback(const struct __btrfs_root *root,char filetime[32 ], *target =NULL ;time_t mtime; -if (btrfs_lookup_inode (root, (struct btrfs_key *)&item->location, +if (__btrfs_lookup_inode (root, (struct btrfs_key *)&item->location, &inode,NULL )) {printf ("%s: Cannot find inode item for directory entry %.*s!\n" , __func__, item->name_len, name);
@@ -49,7 +49,7 @@ static int readdir_callback(const struct __btrfs_root *root, target =malloc (min (inode.size +1 , (u64 ) btrfs_info.sb.sectorsize)); -if (target &&btrfs_readlink (root, item->location.objectid, +if (target &&__btrfs_readlink (root, item->location.objectid, target)) {free (target); target =NULL ;
@@ -129,7 +129,7 @@ int btrfs_ls(const char *path)u64 inr;u8 type; - inr =btrfs_lookup_path (&root, root.root_dirid, path, &type,NULL ,40 ); + inr =__btrfs_lookup_path (&root, root.root_dirid, path, &type,NULL ,40 );if (inr ==-1ULL ) {printf ("Cannot lookup path %s\n" , path);
@@ -155,7 +155,7 @@ int btrfs_exists(const char *file)u64 inr;u8 type; - inr =btrfs_lookup_path (&root, root.root_dirid, file, &type,NULL ,40 ); + inr =__btrfs_lookup_path (&root, root.root_dirid, file, &type,NULL ,40 );return (inr !=-1ULL && type ==BTRFS_FT_REG_FILE ); }
@@ -167,7 +167,7 @@ int btrfs_size(const char *file, loff_t *size)u64 inr;u8 type; - inr =btrfs_lookup_path (&root, root.root_dirid, file, &type, &inode, + inr =__btrfs_lookup_path (&root, root.root_dirid, file, &type, &inode,40 );if (inr ==-1ULL ) {
@@ -192,7 +192,7 @@ int btrfs_read(const char *file, void *buf, loff_t offset, loff_t len,u64 inr, rd;u8 type; - inr =btrfs_lookup_path (&root, root.root_dirid, file, &type, &inode, + inr =__btrfs_lookup_path (&root, root.root_dirid, file, &type, &inode,40 );if (inr ==-1ULL ) {
fs/btrfs/btrfs.h +5 -5
@@ -46,7 +46,7 @@ int btrfs_read_superblock(void);typedef int (*btrfs_readdir_callback_t )(const struct __btrfs_root *,struct btrfs_dir_item *); -int btrfs_lookup_dir_item (const struct __btrfs_root *,u64 ,const char *,int , +int __btrfs_lookup_dir_item (const struct __btrfs_root *,u64 ,const char *,int ,struct btrfs_dir_item *);int btrfs_readdir (const struct __btrfs_root *,u64 ,btrfs_readdir_callback_t );
@@ -55,12 +55,12 @@ int btrfs_find_root(u64, struct __btrfs_root *, struct btrfs_root_item *);u64 btrfs_lookup_root_ref (u64 ,struct btrfs_root_ref *,char *);/* inode.c */ -u64 btrfs_lookup_inode_ref (struct __btrfs_root *,u64 ,struct btrfs_inode_ref *, +u64 __btrfs_lookup_inode_ref (struct __btrfs_root *,u64 ,struct btrfs_inode_ref *,char *); -int btrfs_lookup_inode (const struct __btrfs_root *,struct btrfs_key *, +int __btrfs_lookup_inode (const struct __btrfs_root *,struct btrfs_key *,struct btrfs_inode_item *,struct __btrfs_root *); -int btrfs_readlink (const struct __btrfs_root *,u64 ,char *); -u64 btrfs_lookup_path (struct __btrfs_root *,u64 ,const char *,u8 *, +int __btrfs_readlink (const struct __btrfs_root *,u64 ,char *); +u64 __btrfs_lookup_path (struct __btrfs_root *,u64 ,const char *,u8 *,struct btrfs_inode_item *,int );u64 btrfs_file_read (const struct __btrfs_root *,u64 ,u64 ,u64 ,char *);
fs/btrfs/compat.h +3 -0
@@ -22,6 +22,9 @@ static inline void error(const char *fmt, ...)#define BTRFS_UUID_UNPARSED_SIZE 37 +/* No <linux/limits.h> so have to define it here */ +#define XATTR_NAME_MAX 255 +/* * Macros to generate set/get funcs for the struct fields * assume there is a lefoo_to_cpu for every type, so lets make a simple
fs/btrfs/ctree.h +7 -0
@@ -1279,6 +1279,13 @@ size_t btrfs_super_num_csums(void);int btrfs_find_last_root (struct btrfs_root *root,u64 objectid,struct btrfs_root_item *item,struct btrfs_key *key); +/* dir-item.c */ +struct btrfs_dir_item *btrfs_lookup_dir_item (struct btrfs_trans_handle *trans, +struct btrfs_root *root, +struct btrfs_path *path,u64 dir, +const char *name,int name_len, +int mod); +/* ctree.c */ int btrfs_comp_cpu_keys (const struct btrfs_key *k1,const struct btrfs_key *k2);enum btrfs_tree_block_status
fs/btrfs/dir-item.c +6 -6
@@ -8,7 +8,7 @@#include "btrfs.h" #include "disk-io.h" -static int verify_dir_item (struct btrfs_dir_item *item,u32 start,u32 total) +static int __verify_dir_item (struct btrfs_dir_item *item,u32 start,u32 total) {u16 max_len =BTRFS_NAME_LEN ;u32 end;
@@ -32,7 +32,7 @@ static int verify_dir_item(struct btrfs_dir_item *item, u32 start, u32 total) }static struct btrfs_dir_item * -btrfs_match_dir_item_name (struct __btrfs_path *path,const char *name, +__btrfs_match_dir_item_name (struct __btrfs_path *path,const char *name,int name_len) {struct btrfs_dir_item *item;
@@ -48,7 +48,7 @@ btrfs_match_dir_item_name(struct __btrfs_path *path, const char *name, this_len =sizeof (*item) + item->name_len + item->data_len; name_ptr = (const char *) (item +1 ); -if (verify_dir_item (item, cur, total_len)) +if (__verify_dir_item (item, cur, total_len))return NULL ;if (item->name_len == name_len && !memcmp (name_ptr, name, name_len))
@@ -61,7 +61,7 @@ btrfs_match_dir_item_name(struct __btrfs_path *path, const char *name,return NULL ; } -int btrfs_lookup_dir_item (const struct __btrfs_root *root,u64 dir, +int __btrfs_lookup_dir_item (const struct __btrfs_root *root,u64 dir,const char *name,int name_len,struct btrfs_dir_item *item) {
@@ -79,7 +79,7 @@ int btrfs_lookup_dir_item(const struct __btrfs_root *root, u64 dir,if (btrfs_comp_keys_type (&key,btrfs_path_leaf_key (&path))) goto out; - res =btrfs_match_dir_item_name (&path, name, name_len); + res =__btrfs_match_dir_item_name (&path, name, name_len);if (res) *item = *res; out:
@@ -110,7 +110,7 @@ int btrfs_readdir(const struct __btrfs_root *root, u64 dir, item = btrfs_path_item_ptr(&path, struct btrfs_dir_item);btrfs_dir_item_to_cpu (item); -if (verify_dir_item (item,0 ,sizeof (*item) + item->name_len)) +if (__verify_dir_item (item,0 ,sizeof (*item) + item->name_len))continue ;if (item->type ==BTRFS_FT_XATTR )continue ;
fs/btrfs/inode.c +14 -14
@@ -8,7 +8,7 @@#include "btrfs.h" #include <malloc.h> -u64 btrfs_lookup_inode_ref (struct __btrfs_root *root,u64 inr, +u64 __btrfs_lookup_inode_ref (struct __btrfs_root *root,u64 inr,struct btrfs_inode_ref *refp,char *name) {struct __btrfs_path path;
@@ -44,7 +44,7 @@ out:return res; } -int btrfs_lookup_inode (const struct __btrfs_root *root, +int __btrfs_lookup_inode (const struct __btrfs_root *root,struct btrfs_key *location,struct btrfs_inode_item *item,struct __btrfs_root *new_root)
@@ -83,7 +83,7 @@ out:return res; } -int btrfs_readlink (const struct __btrfs_root *root,u64 inr,char *target) +int __btrfs_readlink (const struct __btrfs_root *root,u64 inr,char *target) {struct __btrfs_path path;struct btrfs_key key;
@@ -137,7 +137,7 @@ out:/* inr must be a directory (for regular files with multiple hard links this function returns only one of the parents of the file) */ -static u64 get_parent_inode (struct __btrfs_root *root,u64 inr, +static u64 __get_parent_inode (struct __btrfs_root *root,u64 inr,struct btrfs_inode_item *inode_item) {struct btrfs_key key;
@@ -164,14 +164,14 @@ static u64 get_parent_inode(struct __btrfs_root *root, u64 inr, key.type =BTRFS_INODE_ITEM_KEY ; key.offset =0 ; -if (btrfs_lookup_inode (root, &key, inode_item,NULL )) +if (__btrfs_lookup_inode (root, &key, inode_item,NULL ))return -1ULL ; }return inr; } - res =btrfs_lookup_inode_ref (root, inr,NULL ,NULL ); + res =__btrfs_lookup_inode_ref (root, inr,NULL ,NULL );if (res ==-1ULL )return -1ULL ;
@@ -180,7 +180,7 @@ static u64 get_parent_inode(struct __btrfs_root *root, u64 inr, key.type =BTRFS_INODE_ITEM_KEY ; key.offset =0 ; -if (btrfs_lookup_inode (root, &key, inode_item,NULL )) +if (__btrfs_lookup_inode (root, &key, inode_item,NULL ))return -1ULL ; }
@@ -209,7 +209,7 @@ static inline const char *skip_current_directories(const char *cur)return cur; } -u64 btrfs_lookup_path (struct __btrfs_root *root,u64 inr,const char *path, +u64 __btrfs_lookup_path (struct __btrfs_root *root,u64 inr,const char *path,u8 *type_p,struct btrfs_inode_item *inode_item_p,int symlink_limit) {
@@ -239,7 +239,7 @@ u64 btrfs_lookup_path(struct __btrfs_root *root, u64 inr, const char *path,if (len ==2 && cur[0 ] =='.' && cur[1 ] =='.' ) { cur +=2 ; - inr =get_parent_inode (root, inr, &inode_item); + inr =__get_parent_inode (root, inr, &inode_item);if (inr ==-1ULL )return -1ULL ;
@@ -250,12 +250,12 @@ u64 btrfs_lookup_path(struct __btrfs_root *root, u64 inr, const char *path,if (!*cur)break ; -if (btrfs_lookup_dir_item (root, inr, cur, len, &item)) +if (__btrfs_lookup_dir_item (root, inr, cur, len, &item))return -1ULL ; type = item.type; have_inode =1 ; -if (btrfs_lookup_inode (root, (struct btrfs_key *)&item.location, +if (__btrfs_lookup_inode (root, (struct btrfs_key *)&item.location, &inode_item, root))return -1ULL ;
@@ -272,13 +272,13 @@ u64 btrfs_lookup_path(struct __btrfs_root *root, u64 inr, const char *path,if (!target)return -1ULL ; -if (btrfs_readlink (root, item.location.objectid, +if (__btrfs_readlink (root, item.location.objectid, target)) {free (target);return -1ULL ; } - inr =btrfs_lookup_path (root, inr, target, &type, + inr =__btrfs_lookup_path (root, inr, target, &type, &inode_item, symlink_limit -1 );free (target);
@@ -307,7 +307,7 @@ u64 btrfs_lookup_path(struct __btrfs_root *root, u64 inr, const char *path, key.type =BTRFS_INODE_ITEM_KEY ; key.offset =0 ; -if (btrfs_lookup_inode (root, &key, &inode_item,NULL )) +if (__btrfs_lookup_inode (root, &key, &inode_item,NULL ))return -1ULL ; }
fs/btrfs/subvolume.c +2 -2
@@ -39,7 +39,7 @@ static int get_subvol_name(u64 subvolid, char *name, int max_len) dir = rref.dirid;while (dir !=BTRFS_FIRST_FREE_OBJECTID ) { - dir =btrfs_lookup_inode_ref (&root, dir, &iref, tmp); + dir =__btrfs_lookup_inode_ref (&root, dir, &iref, tmp);if (dir ==-1ULL )return -1 ;
@@ -71,7 +71,7 @@ u64 btrfs_get_default_subvol_objectid(void) {struct btrfs_dir_item item; -if (btrfs_lookup_dir_item (&btrfs_info.tree_root, +if (__btrfs_lookup_dir_item (&btrfs_info.tree_root, btrfs_info.sb.root_dir_objectid,"default" ,7 , &item))return BTRFS_FS_TREE_OBJECTID ;
Signature · 1 line
2.26.2
PATCH v2 17/30 fs: btrfs: Use btrfs_readlink() to implement __btrfs_readlink()
In reply to Qu WenruoThe existing __btrfs_readlink() can be easily re-implemented using the extent buffer based btrfs_readlink().
This should be the first step to re-implement u-boot btrfs code.
--- fs/btrfs/btrfs.h | 1 + fs/btrfs/inode.c | 101 ++++++++++++++++++++++++++++++----------------- 2 files changed, 65 insertions(+), 37 deletions(-)
fs/btrfs/btrfs.h +1 -0
@@ -60,6 +60,7 @@ u64 __btrfs_lookup_inode_ref(struct __btrfs_root *, u64, struct btrfs_inode_refint __btrfs_lookup_inode (const struct __btrfs_root *,struct btrfs_key *,struct btrfs_inode_item *,struct __btrfs_root *);int __btrfs_readlink (const struct __btrfs_root *,u64 ,char *); +int btrfs_readlink (struct btrfs_root *root,u64 ino,char *target);u64 __btrfs_lookup_path (struct __btrfs_root *,u64 ,const char *,u8 *,struct btrfs_inode_item *,int );u64 btrfs_file_read (const struct __btrfs_root *,u64 ,u64 ,u64 ,char *);
fs/btrfs/inode.c +64 -37
128 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v2 18/30 fs: btrfs: inode: Allow next_length() to return value > BTRFS_NAME_LEN
In reply to Qu WenruoAll existing next_length() caller handles return value > BTRFS_NAME_LEN, so there is no need to do BTRFS_NAME_LEN check in next_length().
But still, we want to exit early if we're beyond BTRFS_NAME_LEN, so this patch will make next_length() to exit as soon as we're beyond BTRFS_NAME_LEN.
--- fs/btrfs/inode.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
fs/btrfs/inode.c +6 -2
@@ -217,8 +217,12 @@ static u64 __get_parent_inode(struct __btrfs_root *root, u64 inr,static inline int next_length (const char *path) {int res =0 ; -while (*path !='\0' && *path !='/' && res <=BTRFS_NAME_LEN ) - ++res, ++path; +while (*path !='\0' && *path !='/' ) { + ++res; + ++path; +if (res >BTRFS_NAME_LEN ) +break ; + }return res; }
Signature · 1 line
2.26.2
PATCH v2 19/30 fs: btrfs: Implement btrfs_lookup_path()
In reply to Qu WenruoThis is the extent buffer based path lookup routine.
To implement this, btrfs_lookup_dir_item() is cross ported from btrfs-progs, and implement btrfs_lookup_path() from scratch.
Unlike the existing __btrfs_lookup_path(), since btrfs_read_fs_root() will check whether a root is orphan at read time, there is no need to check root backref, this make the code a little easier to read.
--- fs/btrfs/ctree.h | 4 + fs/btrfs/dir-item.c | 106 +++++++++++++++++++ fs/btrfs/inode.c | 245 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 355 insertions(+)
fs/btrfs/ctree.h +4 -0
@@ -1285,6 +1285,10 @@ struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, struct btrfs_path *path, u64 dir, const char *name, int name_len, int mod); +/* inode.c */ +int btrfs_lookup_path (struct btrfs_root *root,u64 ino,const char *filename, +struct btrfs_root **root_ret,u64 *ino_ret, +u8 *type_ret,int symlink_limit);/* ctree.c */ int btrfs_comp_cpu_keys (const struct btrfs_key *k1,const struct btrfs_key *k2);
fs/btrfs/dir-item.c +106 -0
112 lines not on this page · raw message
fs/btrfs/inode.c +245 -0
257 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v2 20/30 fs: btrfs: Use btrfs_iter_dir() to replace btrfs_readdir()
In reply to Qu WenruoUse extent buffer based infrastructure to re-implement btrfs_readdir().
Along this rework, some small corner cases fixed:
- Subvolume tree mtime
Mtime of a subvolume tree is recorded in its root item, since there is no INODE_ITEM for it.
This needs extra search from tree root.
- Output the unknown type
If the DIR_ITEM is corrupted, at least don't try to access the memory out of bounday.
--- fs/btrfs/btrfs.c | 157 +++++++++++++++++++++++++++----------------- fs/btrfs/btrfs.h | 5 -- fs/btrfs/ctree.h | 5 ++ fs/btrfs/dir-item.c | 68 +++++++++++-------- 4 files changed, 144 insertions(+), 91 deletions(-)
fs/btrfs/btrfs.c +97 -60
@@ -16,67 +16,102 @@struct btrfs_info btrfs_info;struct btrfs_fs_info *current_fs_info; -static int readdir_callback (const struct __btrfs_root *root, -struct btrfs_dir_item *item) +static int show_dir (struct btrfs_root *root,struct extent_buffer *eb, +struct btrfs_dir_item *di) { -static const char typestr[BTRFS_FT_MAX ][4 ] = { - [BTRFS_FT_UNKNOWN ] =" ? " , - [BTRFS_FT_REG_FILE ] =" " , - [BTRFS_FT_DIR ] ="DIR" , - [BTRFS_FT_CHRDEV ] ="CHR" , - [BTRFS_FT_BLKDEV ] ="BLK" , - [BTRFS_FT_FIFO ] ="FIF" , - [BTRFS_FT_SOCK ] ="SCK" , - [BTRFS_FT_SYMLINK ] ="SYM" , - [BTRFS_FT_XATTR ] =" ? " , +struct btrfs_fs_info *fs_info = root->fs_info; +struct btrfs_inode_item ii; +struct btrfs_key key; +static const char * dir_item_str[] = { + [BTRFS_FT_REG_FILE ] ="FILE" , + [BTRFS_FT_DIR ] ="DIR" , + [BTRFS_FT_CHRDEV ] ="CHRDEV" , + [BTRFS_FT_BLKDEV ] ="BLKDEV" , + [BTRFS_FT_FIFO ] ="FIFO" , + [BTRFS_FT_SOCK ] ="SOCK" , + [BTRFS_FT_SYMLINK ] ="SYMLINK" , + [BTRFS_FT_XATTR ] ="XATTR" }; -struct btrfs_inode_item inode; -const char *name = (const char *) (item +1 ); -char filetime[32 ], *target =NULL ; +u8 type =btrfs_dir_type (eb, di); +char namebuf[BTRFS_NAME_LEN ]; +char *target =NULL ; +char filetime[32 ];time_t mtime; +int ret; -if (__btrfs_lookup_inode (root, (struct btrfs_key *)&item->location, - &inode,NULL )) { -printf ("%s: Cannot find inode item for directory entry %.*s!\n" , - __func__, item->name_len, name); -return 0 ; - } - - mtime = inode.mtime.sec; -ctime_r (&mtime, filetime); +btrfs_dir_item_key_to_cpu (eb, di, &key); -if (item->type ==BTRFS_FT_SYMLINK ) { - target =malloc (min (inode.size +1 , - (u64 ) btrfs_info.sb.sectorsize)); +if (key.type ==BTRFS_ROOT_ITEM_KEY ) { +struct btrfs_root *subvol; -if (target &&__btrfs_readlink (root, item->location.objectid, - target)) { -free (target); - target =NULL ; +/* It's a subvolume, get its mtime from root item */ + subvol =btrfs_read_fs_root (fs_info, &key); +if (IS_ERR (subvol)) { + ret =PTR_ERR (subvol); +error ("Can't find root %llu" , key.objectid); +return ret; } + mtime =btrfs_stack_timespec_sec (&subvol->root_item.otime); + }else { +struct btrfs_path path; + +/* It's regular inode, get its mtime from inode item */ +btrfs_init_path (&path); + ret =btrfs_search_slot (NULL , root, &key, &path,0 ,0 ); +if (ret >0 ) + ret = -ENOENT ; +if (ret <0 ) { +error ("Can't find inode %llu" , key.objectid); +btrfs_release_path (&path); +return ret; + } +read_extent_buffer (path.nodes[0 ], &ii, +btrfs_item_ptr_offset (path.nodes[0 ], path.slots[0 ]), +sizeof (ii)); +btrfs_release_path (&path); + mtime =btrfs_stack_timespec_sec (&ii.mtime); + } +ctime_r (&mtime, filetime); -if (!target) -printf ("%s: Cannot read symlink target!\n" , __func__); +if (type ==BTRFS_FT_SYMLINK ) { + target =malloc (fs_info->sectorsize); +if (!target) { +error ("Can't alloc memory for symlink %llu" , + key.objectid); +return -ENOMEM ; + } + ret =btrfs_readlink (root, key.objectid, target); +if (ret <0 ) { +error ("Failed to read symlink %llu" , key.objectid); + goto out; + } + target[ret] ='\0' ; } -printf ("<%s> " , typestr[item->type]); -if (item->type ==BTRFS_FT_CHRDEV || item->type ==BTRFS_FT_BLKDEV ) -printf ("%4u,%5u " , (unsigned int ) (inode.rdev >>20 ), - (unsigned int ) (inode.rdev &0xfffff )); +if (type <ARRAY_SIZE (dir_item_str) && dir_item_str[type]) +printf ("<%s> " , dir_item_str[type]);else -printf ("%10llu " , inode.size); - -printf ("%24.24s %.*s" , filetime, item->name_len, name); - -if (item->type ==BTRFS_FT_SYMLINK ) { -printf (" -> %s" , target ? target :"?" ); -if (target) -free (target); +printf ("DIR_ITEM.%u" , type); +if (type ==BTRFS_FT_CHRDEV || type ==BTRFS_FT_BLKDEV ) { +ASSERT (key.type ==BTRFS_INODE_ITEM_KEY ); +printf ("%4llu,%5llu " ,btrfs_stack_inode_rdev (&ii) >>20 , +btrfs_stack_inode_rdev (&ii) &0xfffff ); + }else { +if (key.type ==BTRFS_INODE_ITEM_KEY ) +printf ("%10llu " ,btrfs_stack_inode_size (&ii)); +else +printf ("%10llu " ,0ULL ); } +read_extent_buffer (eb, namebuf, (unsigned long )(di +1 ), +btrfs_dir_name_len (eb, di)); +printf ("%24.24s %.*s" , filetime,btrfs_dir_name_len (eb, di), namebuf); +if (type ==BTRFS_FT_SYMLINK ) +printf (" -> %s" , target ? target :"?" );printf ("\n" ); - -return 0 ; +out: +free (target); +return ret; } int btrfs_probe(struct blk_desc *fs_dev_desc,
@@ -125,27 +160,29 @@ int btrfs_probe(struct blk_desc *fs_dev_desc,int btrfs_ls (const char *path) { -struct __btrfs_root root = btrfs_info.fs_root; -u64 inr; +struct btrfs_fs_info *fs_info = current_fs_info; +struct btrfs_root *root = fs_info->fs_root; +u64 ino =BTRFS_FIRST_FREE_OBJECTID ;u8 type; +int ret; - inr =__btrfs_lookup_path (&root, root.root_dirid, path, &type,NULL ,40 ); - -if (inr ==-1ULL ) { +ASSERT (fs_info); + ret =btrfs_lookup_path (fs_info->fs_root,BTRFS_FIRST_FREE_OBJECTID , + path, &root, &ino, &type,40 ); +if (ret <0 ) {printf ("Cannot lookup path %s\n" , path); -return -1 ; +return ret; }if (type !=BTRFS_FT_DIR ) { -printf ("Not a directory: %s\n" , path); -return -1 ; +error ("Not a directory: %s" , path); +return -ENOENT ; } - -if (btrfs_readdir (&root, inr, readdir_callback)) { -printf ("An error occured while listing directory %s\n" , path); -return -1 ; + ret =btrfs_iter_dir (root, ino, show_dir); +if (ret <0 ) { +error ("An error occured while listing directory %s" , path); +return ret; } -return 0 ; }
fs/btrfs/btrfs.h +0 -5
@@ -43,13 +43,8 @@ u32 btrfs_decompress(u8 type, const char *, u32, char *, u32);int btrfs_read_superblock (void );/* dir-item.c */ -typedef int (*btrfs_readdir_callback_t )(const struct __btrfs_root *, -struct btrfs_dir_item *); -int __btrfs_lookup_dir_item (const struct __btrfs_root *,u64 ,const char *,int ,struct btrfs_dir_item *); -int btrfs_readdir (const struct __btrfs_root *,u64 ,btrfs_readdir_callback_t ); -/* root.c */ int btrfs_find_root (u64 ,struct __btrfs_root *,struct btrfs_root_item *);u64 btrfs_lookup_root_ref (u64 ,struct btrfs_root_ref *,char *);
fs/btrfs/ctree.h +5 -0
@@ -1285,6 +1285,11 @@ struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, struct btrfs_path *path, u64 dir, const char *name, int name_len, int mod); +typedef int (*btrfs_iter_dir_callback_t )(struct btrfs_root *root, +struct extent_buffer *eb, +struct btrfs_dir_item *di); +int btrfs_iter_dir (struct btrfs_root *root,u64 ino, +btrfs_iter_dir_callback_t callback);/* inode.c */ int btrfs_lookup_path(struct btrfs_root *root, u64 ino, const char *filename, struct btrfs_root **root_ret, u64 *ino_ret,
fs/btrfs/dir-item.c +42 -26
81 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v2 21/30 fs: btrfs: Use btrfs_lookup_path() to implement btrfs_exists() and btrfs_size()
In reply to Qu WenruoThe remaining function that still utilize __btrfs_lookup_path() is btrfs_read().
--- fs/btrfs/btrfs.c | 65 +++++++++++++++++++++++++++++++++++------------- fs/btrfs/inode.c | 1 - 2 files changed, 48 insertions(+), 18 deletions(-)
fs/btrfs/btrfs.c +48 -17
@@ -188,37 +188,66 @@ int btrfs_ls(const char *path)int btrfs_exists (const char *file) { -struct __btrfs_root root = btrfs_info.fs_root; -u64 inr; +struct btrfs_fs_info *fs_info = current_fs_info; +struct btrfs_root *root; +u64 ino;u8 type; +int ret; + +ASSERT (fs_info); - inr =__btrfs_lookup_path (&root, root.root_dirid, file, &type,NULL ,40 ); + ret =btrfs_lookup_path (fs_info->fs_root,BTRFS_FIRST_FREE_OBJECTID , + file, &root, &ino, &type,40 ); +if (ret <0 ) +return 0 ; -return (inr !=-1ULL && type ==BTRFS_FT_REG_FILE ); +if (type ==BTRFS_FT_REG_FILE ) +return 1 ; +return 0 ; }int btrfs_size (const char *file,loff_t *size) { -struct __btrfs_root root = btrfs_info.fs_root; -struct btrfs_inode_item inode; -u64 inr; +struct btrfs_fs_info *fs_info = current_fs_info; +struct btrfs_inode_item *ii; +struct btrfs_root *root; +struct btrfs_path path; +struct btrfs_key key; +u64 ino;u8 type; +int ret; - inr =__btrfs_lookup_path (&root, root.root_dirid, file, &type, &inode, -40 ); - -if (inr ==-1ULL ) { + ret =btrfs_lookup_path (fs_info->fs_root,BTRFS_FIRST_FREE_OBJECTID , + file, &root, &ino, &type,40 ); +if (ret <0 ) {printf ("Cannot lookup file %s\n" , file); -return -1 ; +return ret; } -if (type !=BTRFS_FT_REG_FILE ) {printf ("Not a regular file: %s\n" , file); -return -1 ; +return -ENOENT ; } +btrfs_init_path (&path); + key.objectid = ino; + key.type =BTRFS_INODE_ITEM_KEY ; + key.offset =0 ; - *size = inode.size; -return 0 ; + ret =btrfs_search_slot (NULL , root, &key, &path,0 ,0 ); +if (ret <0 ) { +printf ("Cannot lookup ino %llu\n" , ino); +return ret; + } +if (ret >0 ) { +printf ("Ino %llu does not exist\n" , ino); + ret = -ENOENT ; + goto out; + } + ii =btrfs_item_ptr (path.nodes[0 ], path.slots[0 ], + struct btrfs_inode_item); + *size =btrfs_inode_size (path.nodes[0 ], ii); +out: +btrfs_release_path (&path); +return ret; } int btrfs_read(const char *file, void *buf, loff_t offset, loff_t len,
@@ -270,7 +299,9 @@ void btrfs_close(void)int btrfs_uuid (char *uuid_str) {#ifdef CONFIG_LIB_UUID -uuid_bin_to_str (btrfs_info.sb.fsid, uuid_str,UUID_STR_FORMAT_STD ); +if (current_fs_info) +uuid_bin_to_str (current_fs_info->super_copy->fsid, uuid_str, +UUID_STR_FORMAT_STD );return 0 ;#endif return -ENOSYS ;
fs/btrfs/inode.c +0 -1
@@ -409,7 +409,6 @@ int btrfs_lookup_path(struct btrfs_root *root, u64 ino, const char *filename, }while (*cur !='\0' ) { - cur =skip_current_directories (cur); len =next_length (cur);if (len >BTRFS_NAME_LEN ) {
Signature · 1 line
2.26.2
PATCH v2 22/30 fs: btrfs: Rename btrfs_file_read() and its callees to avoid name conflicts
In reply to Qu Wenruo--- fs/btrfs/btrfs.c | 2 +- fs/btrfs/btrfs.h | 6 +++--- fs/btrfs/extent-io.c | 4 ++-- fs/btrfs/inode.c | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-)
fs/btrfs/btrfs.c +1 -1
@@ -277,7 +277,7 @@ int btrfs_read(const char *file, void *buf, loff_t offset, loff_t len,if (len > inode.size - offset) len = inode.size - offset; - rd =btrfs_file_read (&root, inr, offset, len, buf); + rd =__btrfs_file_read (&root, inr, offset, len, buf);if (rd ==-1ULL ) {printf ("An error occured while reading file %s\n" , file);return -1 ;
fs/btrfs/btrfs.h +3 -3
@@ -58,16 +58,16 @@ int __btrfs_readlink(const struct __btrfs_root *, u64, char *);int btrfs_readlink (struct btrfs_root *root,u64 ino,char *target);u64 __btrfs_lookup_path (struct __btrfs_root *,u64 ,const char *,u8 *,struct btrfs_inode_item *,int ); -u64 btrfs_file_read (const struct __btrfs_root *,u64 ,u64 ,u64 ,char *); +u64 __btrfs_file_read (const struct __btrfs_root *,u64 ,u64 ,u64 ,char *);/* subvolume.c */ u64 btrfs_get_default_subvol_objectid (void );/* extent-io.c */ -u64 btrfs_read_extent_inline (struct __btrfs_path *, +u64 __btrfs_read_extent_inline (struct __btrfs_path *,struct btrfs_file_extent_item *,u64 ,u64 ,char *); -u64 btrfs_read_extent_reg (struct __btrfs_path *,struct btrfs_file_extent_item *, +u64 __btrfs_read_extent_reg (struct __btrfs_path *,struct btrfs_file_extent_item *,u64 ,u64 ,char *);#endif /* !__BTRFS_BTRFS_H__ */
fs/btrfs/extent-io.c +2 -2
@@ -14,7 +14,7 @@#include "extent-io.h" #include "disk-io.h" -u64 btrfs_read_extent_inline (struct __btrfs_path *path, +u64 __btrfs_read_extent_inline (struct __btrfs_path *path,struct btrfs_file_extent_item *extent,u64 offset,u64 size,char *out) {
@@ -66,7 +66,7 @@ err:return -1ULL ; } -u64 btrfs_read_extent_reg (struct __btrfs_path *path, +u64 __btrfs_read_extent_reg (struct __btrfs_path *path,struct btrfs_file_extent_item *extent,u64 offset,u64 size,char *out) {
fs/btrfs/inode.c +3 -3
@@ -592,7 +592,7 @@ u64 __btrfs_lookup_path(struct __btrfs_root *root, u64 inr, const char *path,return inr; } -u64 btrfs_file_read (const struct __btrfs_root *root,u64 inr,u64 offset, +u64 __btrfs_file_read (const struct __btrfs_root *root,u64 inr,u64 offset,u64 size,char *buf) {struct __btrfs_path path;
@@ -627,11 +627,11 @@ u64 btrfs_file_read(const struct __btrfs_root *root, u64 inr, u64 offset,if (extent->type ==BTRFS_FILE_EXTENT_INLINE ) {btrfs_file_extent_item_to_cpu_inl (extent); - rd =btrfs_read_extent_inline (&path, extent, offset, + rd =__btrfs_read_extent_inline (&path, extent, offset, size, buf); }else {btrfs_file_extent_item_to_cpu (extent); - rd =btrfs_read_extent_reg (&path, extent, offset, size, + rd =__btrfs_read_extent_reg (&path, extent, offset, size, buf); }
Signature · 1 line
2.26.2
PATCH v2 23/30 fs: btrfs: Introduce btrfs_read_extent_inline() and btrfs_read_extent_reg()
In reply to Qu WenruoThese two functions are used to do sector aligned read, which will be later used to implement btrfs_file_read().
--- fs/btrfs/ctree.h | 5 ++ fs/btrfs/disk-io.c | 36 ++++++++++ fs/btrfs/disk-io.h | 2 + fs/btrfs/inode.c | 162 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 205 insertions(+)
fs/btrfs/ctree.h +5 -0
@@ -1294,6 +1294,11 @@ int btrfs_iter_dir(struct btrfs_root *root, u64 ino,int btrfs_lookup_path (struct btrfs_root *root,u64 ino,const char *filename,struct btrfs_root **root_ret,u64 *ino_ret,u8 *type_ret,int symlink_limit); +int btrfs_read_extent_inline (struct btrfs_path *path, +struct btrfs_file_extent_item *fi,char *dest); +int btrfs_read_extent_reg (struct btrfs_path *path, +struct btrfs_file_extent_item *fi,u64 offset, +int len,char *dest);/* ctree.c */ int btrfs_comp_cpu_keys (const struct btrfs_key *k1,const struct btrfs_key *k2);
fs/btrfs/disk-io.c +36 -0
@@ -565,6 +565,42 @@ struct extent_buffer* read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr,return ERR_PTR (ret); } +int read_extent_data (struct btrfs_fs_info *fs_info,char *data,u64 logical, +u64 *len,int mirror) +{ +u64 offset =0 ; +struct btrfs_multi_bio *multi =NULL ; +struct btrfs_device *device; +int ret =0 ; +u64 max_len = *len; + + ret =btrfs_map_block (fs_info,READ , logical, len, &multi, mirror, +NULL ); +if (ret) { +fprintf (stderr,"Couldn't map the block %llu\n" , + logical + offset); + goto err; + } + device = multi->stripes[0 ].dev; + +if (*len > max_len) + *len = max_len; +if (!device->desc || !device->part) { + ret = -EIO ; + goto err; + } + + ret =__btrfs_devread (device->desc, device->part, data, *len, + multi->stripes[0 ].physical); +if (ret != *len) + ret = -EIO ; +else + ret =0 ; +err: +kfree (multi); +return ret; +} +void btrfs_setup_root (struct btrfs_root *root,struct btrfs_fs_info *fs_info,u64 objectid) {
fs/btrfs/disk-io.h +2 -0
@@ -18,6 +18,8 @@ int read_whole_eb(struct btrfs_fs_info *info, struct extent_buffer *eb, int mirrstruct extent_buffer *read_tree_block (struct btrfs_fs_info *fs_info,u64 bytenr,u64 parent_transid); +int read_extent_data (struct btrfs_fs_info *fs_info,char *data,u64 logical, +u64 *len,int mirror);struct extent_buffer *btrfs_find_create_tree_block (struct btrfs_fs_info *fs_info,u64 bytenr); struct extent_buffer *btrfs_find_tree_block(struct btrfs_fs_info *fs_info,
fs/btrfs/inode.c +162 -0
174 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v2 24/30 fs: btrfs: Introduce lookup_data_extent() for later use
In reply to Qu Wenruo--- fs/btrfs/inode.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+)
fs/btrfs/inode.c +101 -0
@@ -819,3 +819,104 @@ out:free (dbuf);return ret; } + +/* +* Get the first file extent that covers bytenr @file_offset. +* +* @file_offset must be aligned to sectorsize. +* +* return 0 for found, and path points to the file extent. +* return >0 for not found, and fill @next_offset. +* @next_offset can be 0 if there is no next file extent. +* return <0 for error. +*/ +static int lookup_data_extent (struct btrfs_root *root,struct btrfs_path *path, +u64 ino,u64 file_offset,u64 *next_offset) +{ +struct btrfs_key key; +struct btrfs_file_extent_item *fi; +u8 extent_type; +int ret =0 ; + +ASSERT (IS_ALIGNED (file_offset, root->fs_info->sectorsize)); + key.objectid = ino; + key.type =BTRFS_EXTENT_DATA_KEY ; + key.offset = file_offset; + + ret =btrfs_search_slot (NULL , root, &key, path,0 ,0 ); +/* Error or we're already at the file extent */ +if (ret <=0 ) +return ret; +if (ret >0 ) { +/* Check previous file extent */ + ret =btrfs_previous_item (root, path, ino, +BTRFS_EXTENT_DATA_KEY ); +if (ret <0 ) +return ret; +if (ret >0 ) + goto check_next; + } +/* Now the key.offset must be smaller than @file_offset */ +btrfs_item_key_to_cpu (path->nodes[0 ], &key, path->slots[0 ]); +if (key.objectid != ino || + key.type !=BTRFS_EXTENT_DATA_KEY ) + goto check_next; + + fi =btrfs_item_ptr (path->nodes[0 ], path->slots[0 ], + struct btrfs_file_extent_item); + extent_type =btrfs_file_extent_type (path->nodes[0 ], fi); +if (extent_type ==BTRFS_FILE_EXTENT_INLINE ) { +if (file_offset ==0 ) +return 0 ; +/* Inline extent should be the only extent, no next extent. */ + *next_offset =0 ; +return 1 ; + } + +/* This file extent covers @file_offset */ +if (key.offset <= file_offset && key.offset + +btrfs_file_extent_num_bytes (path->nodes[0 ], fi) > file_offset) +return 0 ; +check_next: + ret =btrfs_next_item (root, path); +if (ret <0 ) +return ret; +if (ret >0 ) { + *next_offset =0 ; +return 1 ; + } + +btrfs_item_key_to_cpu (path->nodes[0 ], &key, path->slots[0 ]); + fi =btrfs_item_ptr (path->nodes[0 ], path->slots[0 ], + struct btrfs_file_extent_item); +/* Next next data extent */ +if (key.objectid != ino || + key.type !=BTRFS_EXTENT_DATA_KEY ) { + *next_offset =0 ; +return 1 ; + } +/* Current file extent already beyond @file_offset */ +if (key.offset > file_offset) { + *next_offset = key.offset; +return 1 ; + } +/* This file extent covers @file_offset */ +if (key.offset <= file_offset && key.offset + +btrfs_file_extent_num_bytes (path->nodes[0 ], fi) > file_offset) +return 0 ; +/* This file extent ends before @file_offset, check next */ + ret =btrfs_next_item (root, path); +if (ret <0 ) +return ret; +if (ret >0 ) { + *next_offset =0 ; +return 1 ; + } +btrfs_item_key_to_cpu (path->nodes[0 ], &key, path->slots[0 ]); +if (key.type !=BTRFS_EXTENT_DATA_KEY || key.objectid != ino) { + *next_offset =0 ; +return 1 ; + } + *next_offset = key.offset; +return 1 ; +}
Signature · 1 line
2.26.2
PATCH v2 25/30 fs: btrfs: Implement btrfs_file_read()
In reply to Qu WenruoThis version of btrfs_file_read() will have the following new features:
- Try all mirrors
- More hanlding on unaligned size
- Better compressed extent handling
The old implementation doesn't handle compressed extent with offset properly.
As we need to read out the whole compressed extent, then decompress the whole extent, then only copy the referred part.
--- fs/btrfs/btrfs.c | 48 +++++++++------- fs/btrfs/btrfs.h | 2 + fs/btrfs/inode.c | 146 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 176 insertions(+), 20 deletions(-)
fs/btrfs/btrfs.c +28 -20
@@ -253,37 +253,45 @@ out:int btrfs_read (const char *file,void *buf,loff_t offset,loff_t len,loff_t *actread) { -struct __btrfs_root root = btrfs_info.fs_root; -struct btrfs_inode_item inode; -u64 inr, rd; +struct btrfs_fs_info *fs_info = current_fs_info; +struct btrfs_root *root; +loff_t real_size; +u64 ino;u8 type; +int ret; - inr =__btrfs_lookup_path (&root, root.root_dirid, file, &type, &inode, -40 ); - -if (inr ==-1ULL ) { -printf ("Cannot lookup file %s\n" , file); -return -1 ; +ASSERT (fs_info); + ret =btrfs_lookup_path (fs_info->fs_root,BTRFS_FIRST_FREE_OBJECTID , + file, &root, &ino, &type,40 ); +if (ret <0 ) { +error ("Cannot lookup file %s" , file); +return ret; }if (type !=BTRFS_FT_REG_FILE ) { -printf ("Not a regular file: %s\n" , file); -return -1 ; +error ("Not a regular file: %s" , file); +return -EINVAL ; } -if (!len) - len = inode.size; +if (!len) { + ret =btrfs_size (file, &real_size); +if (ret <0 ) { +error ("Failed to get inode size: %s" , file); +return ret; + } + len = real_size; + } -if (len > inode.size - offset) - len = inode.size - offset; +if (len > real_size - offset) + len = real_size - offset; - rd =__btrfs_file_read (&root, inr, offset, len, buf); -if (rd ==-1ULL ) { -printf ("An error occured while reading file %s\n" , file); -return -1 ; + ret =btrfs_file_read (root, ino, offset, len, buf); +if (ret <0 ) { +error ("An error occured while reading file %s" , file); +return ret; } - *actread = rd; + *actread = len;return 0 ; }
fs/btrfs/btrfs.h +2 -0
@@ -59,6 +59,8 @@ int btrfs_readlink(struct btrfs_root *root, u64 ino, char *target);u64 __btrfs_lookup_path (struct __btrfs_root *,u64 ,const char *,u8 *,struct btrfs_inode_item *,int );u64 __btrfs_file_read (const struct __btrfs_root *,u64 ,u64 ,u64 ,char *); +int btrfs_file_read (struct btrfs_root *root,u64 ino,u64 file_offset,u64 len, +char *dest);/* subvolume.c */ u64 btrfs_get_default_subvol_objectid (void );
fs/btrfs/inode.c +146 -0
149 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v2 26/30 fs: btrfs: Introduce function to reolve path in one subvolume
In reply to Qu WenruoThis patch introduces a new function, get_path_in_subvolume(), which resolve inode number into path inside a subvolume.
This function will be later used for btrfs subvolume list functionality.
--- fs/btrfs/compat.h | 1 + fs/btrfs/subvolume.c | 68 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 68 insertions(+), 1 deletion(-)
fs/btrfs/compat.h +1 -0
@@ -24,6 +24,7 @@ static inline void error(const char *fmt, ...)/* No <linux/limits.h> so have to define it here */ #define XATTR_NAME_MAX 255 +#define PATH_MAX 4096/* * Macros to generate set/get funcs for the struct fields
fs/btrfs/subvolume.c +67 -1
75 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v2 27/30 fs: btrfs: Introduce function to resolve the path of one subvolume
In reply to Qu WenruoThis patch introduces a new function, list_one_subvol(), which will resolve the path to FS_TREE of one subvolume.
--- fs/btrfs/subvolume.c | 81 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+)
fs/btrfs/subvolume.c +81 -0
@@ -8,6 +8,7 @@#include <malloc.h> #include "ctree.h" #include "btrfs.h" +#include "disk-io.h" /* * Resolve the path of ino inside subvolume @root into @path_ret.
@@ -74,6 +75,86 @@ out:return ret; } +static int list_one_subvol (struct btrfs_root *root,char *path_ret) +{ +struct btrfs_fs_info *fs_info = root->fs_info; +struct btrfs_root *tree_root = fs_info->tree_root; +struct btrfs_path path; +struct btrfs_key key; +char *tmp; +u64 cur = root->root_key.objectid; +int ret =0 ; + + tmp =malloc (PATH_MAX ); +if (!tmp) +return -ENOMEM ; + tmp[0 ] ='\0' ; + path_ret[0 ] ='\0' ; +btrfs_init_path (&path); +while (cur !=BTRFS_FS_TREE_OBJECTID ) { +struct btrfs_root_ref *rr; +struct btrfs_key location; +int name_len; +u64 ino; + + key.objectid = cur; + key.type =BTRFS_ROOT_BACKREF_KEY ; + key.offset = (u64)-1 ; +btrfs_release_path (&path); + + ret =btrfs_search_slot (NULL , tree_root, &key, &path,0 ,0 ); +if (ret ==0 ) + ret = -EUCLEAN ; +if (ret <0 ) + goto out; + ret =btrfs_previous_item (tree_root, &path, cur, +BTRFS_ROOT_BACKREF_KEY ); +if (ret >0 ) + ret = -ENOENT ; +if (ret <0 ) + goto out; + +/* Get the subvolume name */ + rr =btrfs_item_ptr (path.nodes[0 ], path.slots[0 ], + struct btrfs_root_ref); +strncpy (tmp, path_ret,PATH_MAX ); + name_len =btrfs_root_ref_name_len (path.nodes[0 ], rr); +if (name_len >BTRFS_NAME_LEN ) { + ret = -ENAMETOOLONG ; + goto out; + } + ino =btrfs_root_ref_dirid (path.nodes[0 ], rr); +read_extent_buffer (path.nodes[0 ], path_ret, + (unsigned long )(rr +1 ), name_len); + path_ret[name_len] ='/' ; + path_ret[name_len +1 ] ='\0' ; +strncat (path_ret, tmp,PATH_MAX ); + +/* Get the path inside the parent subvolume */ +btrfs_item_key_to_cpu (path.nodes[0 ], &key, path.slots[0 ]); + location.objectid = key.offset; + location.type =BTRFS_ROOT_ITEM_KEY ; + location.offset = (u64)-1 ; + root =btrfs_read_fs_root (fs_info, &location); +if (IS_ERR (root)) { + ret =PTR_ERR (root); + goto out; + } + ret =get_path_in_subvol (root, ino, path_ret); +if (ret <0 ) + goto out; + cur = key.offset; + } +/* Add the leading '/' */ +strncpy (tmp, path_ret,PATH_MAX ); +strncpy (path_ret,"/" ,PATH_MAX ); +strncat (path_ret, tmp,PATH_MAX ); +out: +btrfs_release_path (&path); +free (tmp); +return ret; +} +static int get_subvol_name (u64 subvolid,char *name,int max_len) {struct btrfs_root_ref rref;
Signature · 1 line
2.26.2
PATCH v2 28/30 fs: btrfs: Imeplement btrfs_list_subvols() using new infrastructure
In reply to Qu Wenruo--- fs/btrfs/subvolume.c | 78 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 73 insertions(+), 5 deletions(-)
fs/btrfs/subvolume.c +73 -5
@@ -155,6 +155,72 @@ out:return ret; } +static int list_subvolums (struct btrfs_fs_info *fs_info) +{ +struct btrfs_root *tree_root = fs_info->tree_root; +struct btrfs_root *root; +struct btrfs_path path; +struct btrfs_key key; +char *result; +int ret =0 ; + + result =malloc (PATH_MAX ); +if (!result) +return -ENOMEM ; + + ret =list_one_subvol (fs_info->fs_root, result); +if (ret <0 ) + goto out; + root = fs_info->fs_root; +printf ("ID %llu gen %llu path %.*s\n" , + root->root_key.objectid,btrfs_root_generation (&root->root_item), +PATH_MAX , result); + + key.objectid =BTRFS_FIRST_FREE_OBJECTID ; + key.type =BTRFS_ROOT_ITEM_KEY ; + key.offset =0 ; +btrfs_init_path (&path); + ret =btrfs_search_slot (NULL , tree_root, &key, &path,0 ,0 ); +if (ret <0 ) + goto out; +while (1 ) { +if (path.slots[0 ] >=btrfs_header_nritems (path.nodes[0 ])) + goto next; + +btrfs_item_key_to_cpu (path.nodes[0 ], &key, path.slots[0 ]); +if (key.objectid >BTRFS_LAST_FREE_OBJECTID ) +break ; +if (key.objectid <BTRFS_FIRST_FREE_OBJECTID || + key.type !=BTRFS_ROOT_ITEM_KEY ) + goto next; + key.offset = (u64)-1 ; + root =btrfs_read_fs_root (fs_info, &key); +if (IS_ERR (root)) { + ret =PTR_ERR (root); +if (ret == -ENOENT ) + goto next; + } + ret =list_one_subvol (root, result); +if (ret <0 ) + goto out; +printf ("ID %llu gen %llu path %.*s\n" , + root->root_key.objectid, +btrfs_root_generation (&root->root_item), +PATH_MAX , result); +next: + ret =btrfs_next_item (tree_root, &path); +if (ret <0 ) + goto out; +if (ret >0 ) { + ret =0 ; +break ; + } + } +out: +free (result); +return ret; +} +static int get_subvol_name (u64 subvolid,char *name,int max_len) {struct btrfs_root_ref rref;
@@ -268,10 +334,12 @@ static void list_subvols(u64 tree, char *nameptr, int max_name_len, int level)void btrfs_list_subvols (void ) { -char *nameptr =malloc (4096 ); - -list_subvols (BTRFS_FS_TREE_OBJECTID , nameptr, nameptr ?4096 :0 ,40 ); +struct btrfs_fs_info *fs_info = current_fs_info; +int ret; -if (nameptr) -free (nameptr); +if (!fs_info) +return ; + ret =list_subvolums (fs_info); +if (ret <0 ) +error ("failed to list subvolume: %d" , ret); }
Signature · 1 line
2.26.2
PATCH v2 29/30 fs: btrfs: Cleanup the old implementation
In reply to Qu Wenruo--- fs/btrfs/Makefile | 4 +- fs/btrfs/btrfs.c | 31 ---- fs/btrfs/btrfs.h | 47 ------ fs/btrfs/chunk-map.c | 178 ----------------------- fs/btrfs/compression.c | 2 +- fs/btrfs/ctree.c | 290 ------------------------------------ fs/btrfs/ctree.h | 63 -------- fs/btrfs/dir-item.c | 79 ---------- fs/btrfs/disk-io.c | 30 ---- fs/btrfs/disk-io.h | 3 - fs/btrfs/extent-io.c | 116 --------------- fs/btrfs/inode.c | 323 ----------------------------------------- fs/btrfs/root.c | 92 ------------ fs/btrfs/subvolume.c | 111 -------------- 14 files changed, 3 insertions(+), 1366 deletions(-) delete mode 100644 fs/btrfs/chunk-map.c delete mode 100644 fs/btrfs/root.c
fs/btrfs/Makefile +2 -2
@@ -2,6 +2,6 @@ # # 2017 Marek Behun, CZ.NIC, marek.behun at nic.cz -obj-y := btrfs.o chunk-map.o compression.o ctree.o dev.o dir-item.o \ - extent-io.o inode.o root.o subvolume.o crypto/hash.o disk-io.o \ +obj-y := btrfs.o compression.o ctree.o dev.o dir-item.o \ + extent-io.o inode.o subvolume.o crypto/hash.o disk-io.o \ common/rbtree-utils.o extent-cache.o volumes.o root-tree.o
fs/btrfs/btrfs.c +0 -31
@@ -13,7 +13,6 @@#include "crypto/hash.h" #include "disk-io.h" -struct btrfs_info btrfs_info;struct btrfs_fs_info *current_fs_info; static int show_dir(struct btrfs_root *root, struct extent_buffer *eb,
@@ -120,36 +119,7 @@ int btrfs_probe(struct blk_desc *fs_dev_desc,struct btrfs_fs_info *fs_info;int ret =-1 ; - btrfs_blk_desc = fs_dev_desc; - btrfs_part_info = fs_partition; - -memset (&btrfs_info,0 ,sizeof (btrfs_info)); -btrfs_hash_init (); -if (btrfs_read_superblock ()) -return -1 ; - -if (btrfs_chunk_map_init ()) { -printf ("%s: failed to init chunk map\n" , __func__); -return -1 ; - } - - btrfs_info.tree_root.objectid =0 ; - btrfs_info.tree_root.bytenr = btrfs_info.sb.root; - btrfs_info.chunk_root.objectid =0 ; - btrfs_info.chunk_root.bytenr = btrfs_info.sb.chunk_root; - -if (__btrfs_read_chunk_tree ()) { -printf ("%s: failed to read chunk tree\n" , __func__); -return -1 ; - } - -if (btrfs_find_root (btrfs_get_default_subvol_objectid (), - &btrfs_info.fs_root,NULL )) { -printf ("%s: failed to find default subvolume\n" , __func__); -return -1 ; - } - fs_info =open_ctree_fs_info (fs_dev_desc, fs_partition);if (fs_info) { current_fs_info = fs_info;
@@ -297,7 +267,6 @@ int btrfs_read(const char *file, void *buf, loff_t offset, loff_t len,void btrfs_close (void ) { -btrfs_chunk_map_exit ();if (current_fs_info) {close_ctree_fs_info (current_fs_info); current_fs_info =NULL ;
fs/btrfs/btrfs.h +0 -47
65 lines not on this page · raw message
fs/btrfs/chunk-map.c deleted +0 -178
178 lines not on this page · raw message
fs/btrfs/compression.c +1 -1
@@ -115,7 +115,7 @@ static u32 decompress_zlib(const u8 *_cbuf, u32 clen, u8 *dbuf, u32 dlen)while (stream.total_in < clen) { stream.next_in = cbuf + stream.total_in; stream.avail_in =min ((u32) (clen - stream.total_in), - (u32 ) btrfs_info.sb.sectorsize); + current_fs_info->sectorsize); ret =inflate (&stream,Z_NO_FLUSH );if (ret !=Z_OK )
fs/btrfs/ctree.c +0 -290
296 lines not on this page · raw message
fs/btrfs/ctree.h +0 -63
69 lines not on this page · raw message
fs/btrfs/dir-item.c +0 -79
85 lines not on this page · raw message
fs/btrfs/disk-io.c +0 -30
@@ -310,36 +310,6 @@ int btrfs_read_dev_super(struct blk_desc *desc, struct disk_partition *part,return 0 ; } -int btrfs_read_superblock (void ) -{ -ALLOC_CACHE_ALIGN_BUFFER (char, raw_sb,BTRFS_SUPER_INFO_SIZE ); -struct btrfs_super_block *sb = (struct btrfs_super_block *) raw_sb; -int ret; - - - btrfs_info.sb.generation =0 ; - - ret =btrfs_read_dev_super (btrfs_blk_desc, btrfs_part_info, sb); -if (ret <0 ) { -pr_debug ("%s: No valid BTRFS superblock found!\n" , __func__); -return ret; - } -btrfs_super_block_to_cpu (sb); -memcpy (&btrfs_info.sb, sb,sizeof (*sb)); - -if (btrfs_info.sb.num_devices !=1 ) { -printf ("%s: Unsupported number of devices (%lli). This driver " -"only supports filesystem on one device.\n" , __func__, - btrfs_info.sb.num_devices); -return -1 ; - } - -pr_debug ("Chosen superblock with generation = %llu\n" , - btrfs_info.sb.generation); - -return 0 ; -} -static int __csum_tree_block_size (struct extent_buffer *buf,u16 csum_size,int verify,int silent,u16 csum_type) {
fs/btrfs/disk-io.h +0 -3
@@ -10,9 +10,6 @@#define BTRFS_SUPER_INFO_OFFSET SZ_64K#define BTRFS_SUPER_INFO_SIZE SZ_4K -/* U-boot specific */ -int btrfs_read_superblock (void ); -/* From btrfs-progs */ int read_whole_eb (struct btrfs_fs_info *info,struct extent_buffer *eb,int mirror); struct extent_buffer* read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr,
fs/btrfs/extent-io.c +0 -116
122 lines not on this page · raw message
fs/btrfs/inode.c +0 -323
347 lines not on this page · raw message
fs/btrfs/root.c deleted +0 -92
92 lines not on this page · raw message
fs/btrfs/subvolume.c +0 -111
117 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v2 30/30 MAINTAINERS: Add btrfs mail list
In reply to Qu WenruoSince the current code base is mostly from btrfs-progs, anyone contributing to U-boot btrfs code could also help us to improve btrfs-progs and btrfs kernel module.
--- MAINTAINERS | 1 + 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
@@ -560,6 +560,7 @@ F: tools/binman/ BTRFS M: Marek Behun <[email protected]> +L: linux-btrfs at vger.kernel.org S: Maintained F: cmd/btrfs.c F: fs/btrfs/
Signature · 1 line
2.26.2
Gentle ping?
Any updates?
Hopes this won't block the incoming new features too long.
Thanks,
Qu
Quoted 168 lines · Qu Wenruo
The branch can be fetched from github:
https://github.com/adam900710/u-boot/tree/btrfs_rebuildThe current btrfs code in U-boot is using a creative way to read on-disk data.
It's pretty simple, involving the least amount of code, but pretty different from btrfs-progs nor kernel, making it pretty hard to sync code between different projects.This big patchset will rework the btrfs support, to use code mostly from btrfs-progs, thus all existing btrfs developers will feel at home.
During the rework, the following new features are added:
- More hash algorithm support
SHA256 and XXHASH support are added.
BLAKE2 needs more backport, will happen in a separate patchset.- The ability to read degraded RAID1
Although we still only support one device btrfs, the new code base can choose from different copies already.
As long as new device scan interface is provided, multi-device support is pretty simple.- More correct handling of compressed extents with offset For compressed extent with offset, we should read the whole compressed extent, decompress them, then copy the referred part.
There are some more features incoming, with the new code base it would be much easier to implement:
- Data checksum support
The check would happen inread_extent_data(), btrfs-progs has the needed facility to locate data csum.- BLAKE2 support
Need BLAKE2 library cross ported.
For btrfs it's just several lines of modification.- Multi-device support along wit degraded RAID support We only need an interface to scan one device without opening it. The infrastructure is already provided in this patchset.
These new features would be submitted after the patchset get merged, since the patchset is already large, I don't want to make it more scary.
Although this patchset look horribly large, most of them are code copy from btrfs-progs.
E.g extent-cache.[ch], rbtree-utils.[ch],btrfs_btree.h. Andctree.hhas over 1000 lines copied just for various accessors.While for disk-io.[ch] and volumes-io.[ch], they have some small modifications to adapt the interface of U-boot.
E.g.btrfs_device::fdis replace withblkdev_descanddisk_partition_t.The new code for U-boot are related to the following functions:
-btrfs_readlink()
-btrfs_lookup_path()
-btrfs_read_extent_inline()
-btrfs_read_extent_reg()
-lookup_data_extent()
-btrfs_file_read()
-btrfs_list_subvols()Thus only the following 5 patches need extra review attention:
- Patch 0017
- Patch 0019
- Patch 0023
- Patch 0024
- Patch 0025~0028Changelog:
v2:
- Implementbtrfs_list_subvols()
In v1 it's completely removed thus would cause problem if btrfsolume command is compiled in.- Rebased to latest master
Only minor conflicts due to header changes.- Allow
next_legnth()to return value >BTRFS_NAME_LENQu Wenruo (30):
fs: btrfs: Syncbtrfs_btree.hfrom kernel
fs: btrfs: Add More checksum algorithm support to btrfs
fs: btrfs: Cross-portbtrfs_read_dev_super()from btrfs-progs
fs: btrfs: Cross-port rbtree-utils from btrfs-progs
fs: btrfs: Cross-port extent-cache.[ch] from btrfs-progs
fs: btrfs: Cross-port extent-io.[ch] from btrfs-progs
fs: btrfs: Cross port structure accessor intoctree.h
fs: btrfs: Cross port volumes.[ch] from btrfs-progs
fs: btrfs: Crossportread_tree_block()from btrfs-progs
fs: btrfs: Rename structbtrfs_pathto struct__btrfs_path
fs: btrfs: Renamebtrfs_rootto__btrfs_root
fs: btrfs: Cross port structbtrfs_roottoctree.h
fs: btrfs: Crossportbtrfs_search_slot()from btrfs-progs
fs: btrfs: Crossportbtrfs_read_sys_array()and
btrfs_read_chunk_tree()
fs: btrfs: Crossportopen_ctree_fs_info()
fs: btrfs: Rename path resolve related functions to avoid name
conflicts
fs: btrfs: Usebtrfs_readlink()to implement__btrfs_readlink()
fs: btrfs: inode: Allownext_length()to return value >BTRFS_NAME_LEN
fs: btrfs: Implementbtrfs_lookup_path()
fs: btrfs: Usebtrfs_iter_dir()to replacebtrfs_readdir()
fs: btrfs: Usebtrfs_lookup_path()to implementbtrfs_exists()and
btrfs_size()
fs: btrfs: Renamebtrfs_file_read()and its callees to avoid name
conflicts
fs: btrfs: Introducebtrfs_read_extent_inline()and
btrfs_read_extent_reg()
fs: btrfs: Introducelookup_data_extent()for later use
fs: btrfs: Implementbtrfs_file_read()
fs: btrfs: Introduce function to reolve path in one subvolume
fs: btrfs: Introduce function to resolve the path of one subvolume
fs: btrfs: Imeplementbtrfs_list_subvols()using new infrastructure
fs: btrfs: Cleanup the old implementation
MAINTAINERS: Add btrfs mail listMAINTAINERS | 1 + fs/btrfs/Makefile | 5 +- fs/btrfs/btrfs.c | 319 +++--- fs/btrfs/btrfs.h | 67 +- fs/btrfs/btrfs_tree.h | 766 -------------- fs/btrfs/chunk-map.c | 178 ---- fs/btrfs/common/rbtree-utils.c | 83 ++ fs/btrfs/common/rbtree-utils.h | 53 + fs/btrfs/compat.h | 88 ++ fs/btrfs/compression.c | 2 +- fs/btrfs/crypto/hash.c | 55 + fs/btrfs/crypto/hash.h | 17 + fs/btrfs/ctree.c | 866 ++++++++++++---- fs/btrfs/ctree.h | 1453 ++++++++++++++++++++++----- fs/btrfs/dir-item.c | 192 ++-- fs/btrfs/disk-io.c | 1063 ++++++++++++++++++++ fs/btrfs/disk-io.h | 50 + fs/btrfs/extent-cache.c | 318 ++++++ fs/btrfs/extent-cache.h | 104 ++ fs/btrfs/extent-io.c | 848 ++++++++++++++-- fs/btrfs/extent-io.h | 164 +++ fs/btrfs/hash.c | 38 - fs/btrfs/inode.c | 892 +++++++++++----- fs/btrfs/kernel-shared/btrfs_tree.h | 1333 ++++++++++++++++++++++++ fs/btrfs/root-tree.c | 47 + fs/btrfs/root.c | 92 -- fs/btrfs/subvolume.c | 310 ++++-- fs/btrfs/super.c | 257 ----- fs/btrfs/volumes.c | 1173 +++++++++++++++++++++ fs/btrfs/volumes.h | 204 ++++ 30 files changed, 8537 insertions(+), 2501 deletions(-) delete mode 100644 fs/btrfs/btrfs_tree.h delete mode 100644 fs/btrfs/chunk-map.c create mode 100644 fs/btrfs/common/rbtree-utils.c create mode 100644 fs/btrfs/common/rbtree-utils.h create mode 100644 fs/btrfs/compat.h create mode 100644 fs/btrfs/crypto/hash.c create mode 100644 fs/btrfs/crypto/hash.h create mode 100644 fs/btrfs/disk-io.c create mode 100644 fs/btrfs/disk-io.h create mode 100644 fs/btrfs/extent-cache.c create mode 100644 fs/btrfs/extent-cache.h create mode 100644 fs/btrfs/extent-io.h delete mode 100644 fs/btrfs/hash.c create mode 100644 fs/btrfs/kernel-shared/btrfs_tree.h create mode 100644 fs/btrfs/root-tree.c delete mode 100644 fs/btrfs/root.c delete mode 100644 fs/btrfs/super.c create mode 100644 fs/btrfs/volumes.c create mode 100644 fs/btrfs/volumes.h
Hi Qu,
when applying whole series, there are several warning spewed by git:
trailing whitespaces, new lines at EOF, spaces before tab in indent. It is possible that this is because the code is copypasted from btrfs-progs and this issues come from there.
Also patches 26 and 27 have almost same subject line, and one contains a typo (reolve instead of resolve).
Sometimes in commit messages you use the work "cross-port", sometimes it is "crossport", sometimes "cross port".
I am going to do a bigger test on this series this week, and if the new code works correctly on all tests, I shall resend your patches with some changes to the commit messages, but I will keep you as author of the commits, and I shall add my Reviewed-by.
Marek
Quoted 180 lines · On Tue, 23 Jun 2020 08:50:57 +0800 Qu Wenruo <[email protected]> wrote:
Gentle ping?
Any updates?
Hopes this won't block the incoming new features too long.Thanks,
QuQuoted 171 lines · Qu Wenruo
The branch can be fetched from github:
https://github.com/adam900710/u-boot/tree/btrfs_rebuildThe current btrfs code in U-boot is using a creative way to read on-disk data.
It's pretty simple, involving the least amount of code, but pretty different from btrfs-progs nor kernel, making it pretty hard to sync code between different projects.This big patchset will rework the btrfs support, to use code mostly from btrfs-progs, thus all existing btrfs developers will feel at home.
During the rework, the following new features are added:
- More hash algorithm support
SHA256 and XXHASH support are added.
BLAKE2 needs more backport, will happen in a separate patchset.- The ability to read degraded RAID1
Although we still only support one device btrfs, the new code base can choose from different copies already.
As long as new device scan interface is provided, multi-device
support is pretty simple.- More correct handling of compressed extents with offset For compressed extent with offset, we should read the whole
compressed extent, decompress them, then copy the referred part.There are some more features incoming, with the new code base it would be much easier to implement:
- Data checksum support
The check would happen inread_extent_data(), btrfs-progs has the needed facility to locate data csum.- BLAKE2 support
Need BLAKE2 library cross ported.
For btrfs it's just several lines of modification.- Multi-device support along wit degraded RAID support We only need an interface to scan one device without opening it. The infrastructure is already provided in this patchset.
These new features would be submitted after the patchset get merged, since the patchset is already large, I don't want to make it more scary.
Although this patchset look horribly large, most of them are code copy from btrfs-progs.
E.g extent-cache.[ch], rbtree-utils.[ch],btrfs_btree.h. Andctree.hhas over 1000 lines copied just for various accessors.While for disk-io.[ch] and volumes-io.[ch], they have some small modifications to adapt the interface of U-boot.
E.g.btrfs_device::fdis replace withblkdev_descanddisk_partition_t.The new code for U-boot are related to the following functions:
-btrfs_readlink()
-btrfs_lookup_path()
-btrfs_read_extent_inline()
-btrfs_read_extent_reg()
-lookup_data_extent()
-btrfs_file_read()
-btrfs_list_subvols()Thus only the following 5 patches need extra review attention:
- Patch 0017
- Patch 0019
- Patch 0023
- Patch 0024
- Patch 0025~0028Changelog:
v2:
- Implementbtrfs_list_subvols()
In v1 it's completely removed thus would cause problem if
btrfsolume command is compiled in.- Rebased to latest master
Only minor conflicts due to header changes.- Allow
next_legnth()to return value >BTRFS_NAME_LENQu Wenruo (30):
fs: btrfs: Syncbtrfs_btree.hfrom kernel
fs: btrfs: Add More checksum algorithm support to btrfs
fs: btrfs: Cross-portbtrfs_read_dev_super()from btrfs-progs
fs: btrfs: Cross-port rbtree-utils from btrfs-progs
fs: btrfs: Cross-port extent-cache.[ch] from btrfs-progs
fs: btrfs: Cross-port extent-io.[ch] from btrfs-progs
fs: btrfs: Cross port structure accessor intoctree.h
fs: btrfs: Cross port volumes.[ch] from btrfs-progs
fs: btrfs: Crossportread_tree_block()from btrfs-progs
fs: btrfs: Rename structbtrfs_pathto struct__btrfs_path
fs: btrfs: Renamebtrfs_rootto__btrfs_root
fs: btrfs: Cross port structbtrfs_roottoctree.h
fs: btrfs: Crossportbtrfs_search_slot()from btrfs-progs
fs: btrfs: Crossportbtrfs_read_sys_array()and
btrfs_read_chunk_tree()
fs: btrfs: Crossportopen_ctree_fs_info()
fs: btrfs: Rename path resolve related functions to avoid name
conflicts
fs: btrfs: Usebtrfs_readlink()to implement__btrfs_readlink()
fs: btrfs: inode: Allownext_length()to return value >BTRFS_NAME_LENfs: btrfs: Implementbtrfs_lookup_path()
fs: btrfs: Usebtrfs_iter_dir()to replacebtrfs_readdir()
fs: btrfs: Usebtrfs_lookup_path()to implementbtrfs_exists()and
btrfs_size()
fs: btrfs: Renamebtrfs_file_read()and its callees to avoid name
conflicts
fs: btrfs: Introducebtrfs_read_extent_inline()and
btrfs_read_extent_reg()
fs: btrfs: Introducelookup_data_extent()for later use
fs: btrfs: Implementbtrfs_file_read()
fs: btrfs: Introduce function to reolve path in one subvolume
fs: btrfs: Introduce function to resolve the path of one subvolume
fs: btrfs: Imeplementbtrfs_list_subvols()using new
infrastructure fs: btrfs: Cleanup the old implementation
MAINTAINERS: Add btrfs mail listMAINTAINERS | 1 + fs/btrfs/Makefile | 5 +- fs/btrfs/btrfs.c | 319 +++--- fs/btrfs/btrfs.h | 67 +- fs/btrfs/btrfs_tree.h | 766 -------------- fs/btrfs/chunk-map.c | 178 ---- fs/btrfs/common/rbtree-utils.c | 83 ++ fs/btrfs/common/rbtree-utils.h | 53 + fs/btrfs/compat.h | 88 ++ fs/btrfs/compression.c | 2 +- fs/btrfs/crypto/hash.c | 55 + fs/btrfs/crypto/hash.h | 17 + fs/btrfs/ctree.c | 866 ++++++++++++---- fs/btrfs/ctree.h | 1453 ++++++++++++++++++++++----- fs/btrfs/dir-item.c | 192 ++-- fs/btrfs/disk-io.c | 1063 ++++++++++++++++++++ fs/btrfs/disk-io.h | 50 + fs/btrfs/extent-cache.c | 318 ++++++ fs/btrfs/extent-cache.h | 104 ++ fs/btrfs/extent-io.c | 848 ++++++++++++++-- fs/btrfs/extent-io.h | 164 +++ fs/btrfs/hash.c | 38 - fs/btrfs/inode.c | 892 +++++++++++----- fs/btrfs/kernel-shared/btrfs_tree.h | 1333 ++++++++++++++++++++++++ fs/btrfs/root-tree.c | 47 + fs/btrfs/root.c | 92 -- fs/btrfs/subvolume.c | 310 ++++-- fs/btrfs/super.c | 257 ----- fs/btrfs/volumes.c | 1173 +++++++++++++++++++++ fs/btrfs/volumes.h | 204 ++++ 30 files changed, 8537 insertions(+), 2501 deletions(-) delete mode 100644 fs/btrfs/btrfs_tree.h delete mode 100644 fs/btrfs/chunk-map.c create mode 100644 fs/btrfs/common/rbtree-utils.c create mode 100644 fs/btrfs/common/rbtree-utils.h create mode 100644 fs/btrfs/compat.h create mode 100644 fs/btrfs/crypto/hash.c create mode 100644 fs/btrfs/crypto/hash.h create mode 100644 fs/btrfs/disk-io.c create mode 100644 fs/btrfs/disk-io.h create mode 100644 fs/btrfs/extent-cache.c create mode 100644 fs/btrfs/extent-cache.h create mode 100644 fs/btrfs/extent-io.h delete mode 100644 fs/btrfs/hash.c create mode 100644 fs/btrfs/kernel-shared/btrfs_tree.h create mode 100644 fs/btrfs/root-tree.c delete mode 100644 fs/btrfs/root.c delete mode 100644 fs/btrfs/super.c create mode 100644 fs/btrfs/volumes.c create mode 100644 fs/btrfs/volumes.h