summaryrefslogtreecommitdiff
path: root/fs/btrfs
Commit message (Collapse)AuthorAgeFilesLines
* btrfs: fix offset when reading compressed extentsDominique Martinet2023-05-081-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | btrfs_read_extent_reg correctly computed the extent offset in the BTRFS_COMPRESS_NONE case, but did not account for the 'offset - key.offset' part correctly in the compressed case, making the function read incorrect data. In the case I examined, the last 4k of a file was corrupted and contained data from a few blocks prior, e.g. reading a 10k file with a single extent: btrfs_file_read() -> btrfs_read_extent_reg (aligned part loop, until 8k) -> read_and_truncate_page -> btrfs_read_extent_reg (re-reads the last extent from 8k to the end, incorrectly reading the first 2k of data) This can be reproduced as follow: $ truncate -s 200M btr $ mount btr -o compress /mnt $ pat() { dd if=/dev/zero bs=1M count=$1 iflag=count_bytes status=none | tr '\0' "\\$2"; } $ { pat 4K 1; pat 4K 2; pat 2K 3; } > /mnt/file $ sync $ filefrag -v /mnt/file File size of /mnt/file is 10240 (3 blocks of 4096 bytes) ext: logical_offset: physical_offset: length: expected: flags: 0: 0.. 2: 3328.. 3330: 3: last,encoded,eof $ umount /mnt Then in u-boot: => load scsi 0 2000000 file 10240 bytes read in 3 ms (3.3 MiB/s) => md 2001ff0 02001ff0: 02020202 02020202 02020202 02020202 ................ 02002000: 01010101 01010101 01010101 01010101 ................ 02002010: 01010101 01010101 01010101 01010101 ................ (02002000 onwards should contain '03' pattern but went back to 01, start of the extent) After patch, data is read properly: => md 2001ff0 02001ff0: 02020202 02020202 02020202 02020202 ................ 02002000: 03030303 03030303 03030303 03030303 ................ 02002010: 03030303 03030303 03030303 03030303 ................ Note that the code previously (before commit e3427184f38a ("fs: btrfs: Implement btrfs_file_read()")) did not split that read in two, so this is a regression even if the previous code might not have been handling offsets correctly either (something that booted now fails to boot) Fixes: a26a6bedafcf ("fs: btrfs: Introduce btrfs_read_extent_inline() and btrfs_read_extent_reg()") Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com> Reviewed-by: Qu Wenruo <wqu@suse.com>
* fs: btrfs: limit the mapped length to the original lengthQu Wenruo2023-02-231-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | [BUG] There is a bug report that btrfs driver caused hang during file read: This breaks btrfs on the HiFive Unmatched. => pci enum PCIE-0: Link up (Gen1-x8, Bus0) => nvme scan => load nvme 0:2 0x8c000000 /boot/dtb/sifive/hifive-unmatched-a00.dtb [hangs] [CAUSE] The reporter provided some debug output: read_extent_data: cur=615817216, orig_len=16384, cur_len=16384 read_extent_data: btrfs_map_block: cur_len=479944704; ret=0 read_extent_data: ret=0 read_extent_data: cur=615833600, orig_len=4096, cur_len=4096 read_extent_data: btrfs_map_block: cur_len=479928320; ret=0 Note the second and the last line, the @cur_len is 450+MiB, which is almost a chunk size. And inside __btrfs_map_block(), we limits the returned value to stripe length, but that's depending on the chunk type: if (map->type & (BTRFS_BLOCK_GROUP_RAID0 | BTRFS_BLOCK_GROUP_RAID1 | BTRFS_BLOCK_GROUP_RAID1C3 | BTRFS_BLOCK_GROUP_RAID1C4 | BTRFS_BLOCK_GROUP_RAID5 | BTRFS_BLOCK_GROUP_RAID6 | BTRFS_BLOCK_GROUP_RAID10 | BTRFS_BLOCK_GROUP_DUP)) { /* we limit the length of each bio to what fits in a stripe */ *length = min_t(u64, ce->size - offset, map->stripe_len - stripe_offset); } else { *length = ce->size - offset; } This means, if the chunk is SINGLE profile, then we don't limit the returned length at all, and even for other profiles, we can still return a length much larger than the requested one. [FIX] Properly clamp the returned length, preventing it from returning a much larger range than expected. Reported-by: Andreas Schwab <schwab@linux-m68k.org> Signed-off-by: Qu Wenruo <wqu@suse.com>
* fs/btrfs: handle data extents, which crosss stripe boundaries, correctlyQu Wenruo2023-01-111-22/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | [BUG] Since btrfs supports single device RAID0 at mkfs time after btrfs-progs v5.14, if we create a single device raid0 btrfs, and created a file crossing stripe boundary: # mkfs.btrfs -m dup -d raid0 test.img # mount test.img mnt # xfs_io -f -c "pwrite 0 128K" mnt/file # umount mnt Since btrfs is using 64K as stripe length, above 128K data write is definitely going to cross at least one stripe boundary. Then u-boot would fail to read above 128K file: => host bind 0 /home/adam/test.img => ls host 0 < > 131072 Fri Dec 30 00:18:25 2022 file => load host 0 0 file BTRFS: An error occurred while reading file file Failed to load 'file' [CAUSE] Unlike tree blocks read, data extent reads doesn't consider cases in which one data extent can cross stripe boundary. In read_data_extent(), we just call btrfs_map_block() once and read the first mapped range. And if the first mapped range is smaller than the desired range, it would return error. But since even single device btrfs can utilize RAID0 profiles, the first mapped range can only be at most 64K for RAID0 profiles, and cause false error. [FIX] Just like read_whole_eb(), we should call btrfs_map_block() in a loop until we read all data. Since we're here, also add extra error messages for the following cases: - btrfs_map_block() failure We already have the error message for it. - Missing device This should not happen, as we only support single device for now. - __btrfs_devread() failure With this bug fixed, btrfs driver of u-boot can properly read the above 128K file, and have the correct content: => host bind 0 /home/adam/test.img => ls host 0 < > 131072 Fri Dec 30 00:18:25 2022 file => load host 0 0 file 131072 bytes read in 0 ms => md5sum 0 0x20000 md5 for 00000000 ... 0001ffff ==> d48858312a922db7eb86377f638dbc9f ^^^ Above md5sum also matches. Reported-by: Sam Winchenbach <swichenbach@tethers.com> Signed-off-by: Qu Wenruo <wqu@suse.com>
* fs: Quieten down the filesystems moreSimon Glass2022-10-171-3/+4
| | | | | | | | | | When looking for a filesystem on a partition we should do so quietly. At present if the filesystem is very small (e.g. 512 bytes) we get a host of messages. Update these to only show when debugging. Signed-off-by: Simon Glass <sjg@chromium.org>
* fs: btrfs: remove the usage of undeclared fs_mutex variablePankaj Raghav2022-09-291-2/+0
| | | | | | | | This line probably got in by mistake as there is no fs_mutex member in the btrfs_fs_info struct. Signed-off-by: Pankaj Raghav <p.raghav@samsung.com> Reviewed-by: Qu Wenruo <wqu@suse.com>
* treewide: Fix Marek's name and change my e-mail addressMarek Behún2022-07-2112-12/+12
| | | | | | | | | | Fix diacritics in some instances of my name and change my e-mail address to kabel@kernel.org. Add corresponding .mailmap entries. Signed-off-by: Marek Behún <kabel@kernel.org> Reviewed-by: Stefan Roese <sr@denx.de>
* btrfs: simplify lookup_data_extent()Heinrich Schuchardt2022-06-061-9/+6
| | | | | | | | After returning if ret <= 0 we know that ret > 0. No need to check it. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Reviewed-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Anand Jain <anand.jain>
* btrfs: Fix compilation on big endian systemsPali Rohár2022-04-192-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix following two compile errors on big endian systems: CC fs/btrfs/btrfs.o In file included from include/linux/byteorder/big_endian.h:107, from ./arch/powerpc/include/asm/byteorder.h:82, from ./arch/powerpc/include/asm/bitops.h:8, from include/linux/bitops.h:152, from include/uuid.h:9, from fs/btrfs/btrfs.c:10: fs/btrfs/conv-funcs.h: In function ‘btrfs_key_to_disk’: include/linux/byteorder/generic.h:90:21: error: ‘__cpu_to_le16’ undeclared (first use in this function); did you mean ‘__cpu_to_le16p’? #define cpu_to_le16 __cpu_to_le16 ^~~~~~~~~~~~~ fs/btrfs/conv-funcs.h:79:10: note: in expansion of macro ‘cpu_to_le16’ __u16: cpu_to_le16, \ ^~~~~~~~~~~ CC fs/btrfs/compression.o In file included from ./arch/powerpc/include/asm/unaligned.h:9, from fs/btrfs/compression.c:16: include/linux/unaligned/access_ok.h:6:19: error: redefinition of ‘get_unaligned_le16’ static inline u16 get_unaligned_le16(const void *p) ^~~~~~~~~~~~~~~~~~ In file included from fs/btrfs/ctree.h:16, from fs/btrfs/btrfs.h:12, from fs/btrfs/compression.c:8: include/linux/unaligned/le_byteshift.h:40:19: note: previous definition of ‘get_unaligned_le16’ was here static inline u16 get_unaligned_le16(const void *p) ^~~~~~~~~~~~~~~~~~ Include file asm/unaligned.h contains arch specific macros and functions for unaligned access as opposite to linux/unaligned le_byteshift.h which contains macros and functions specific to little endian systems only. Signed-off-by: Pali Rohár <pali@kernel.org> Reviewed-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Qu Wenruo <wqu@suse.com>
* fs/btrfs: fix a bug that U-boot fs btrfs implementation doesn't handle ↵Qu Wenruo2022-01-181-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | NO_HOLE feature correctly [BUG] When passing a btrfs with NO_HOLE feature to U-boot, and if one file contains holes, then the hash of the file is not correct in U-boot: # mkfs.btrfs -f test.img # Since v5.15, mkfs defaults to NO_HOLES # mount test.img /mnt/btrfs # xfs_io -f -c "pwrite 0 4k" -c "pwrite 8k 4k" /mnt/btrfs/file # md5sum /mnt/btrfs/file 277f3840b275c74d01e979ea9d75ac19 /mnt/btrfs/file # umount /mnt/btrfs # ./u-boot => host bind 0 /home/adam/test.img => ls host 0 < > 12288 Mon Dec 27 05:35:23 2021 file => load host 0 0x1000000 file 12288 bytes read in 0 ms => md5sum 0x1000000 0x3000 md5 for 01000000 ... 01002fff ==> 855ffdbe4d0ccc5acab92e1b5330e4c1 The md5sum doesn't match at all. [CAUSE] In U-boot btrfs implementation, the function btrfs_read_file() has the following iteration for file extent iteration: /* Read the aligned part */ while (cur < aligned_end) { ret = lookup_data_extent(root, &path, ino, cur, &next_offset); if (ret < 0) goto out; if (ret > 0) { /* No next, direct exit */ if (!next_offset) { ret = 0; goto out; } } /* Read file extent */ But for NO_HOLES features, hole extents will not have any extent item for it. Thus if @cur is at a hole, lookup_data_extent() will just return >0, and update @next_offset. But we still believe there is some data to read for @cur for ret > 0 case, causing we read extent data from the next file extent. This means, what we do for above NO_HOLES btrfs is: - Read 4K data from disk to file offset [0, 4K) So far the data is still correct - Read 4K data from disk to file offset [4K, 8K) We didn't skip the 4K hole, but read the data at file offset [8K, 12K) into file offset [4K, 8K). This causes the checksum mismatch. [FIX] Add extra check to skip to the next non-hole range after lookup_data_extent(). Signed-off-by: Qu Wenruo <wqu@suse.com>
* fs/btrfs: add dependency on BLAKE2 hashQu Wenruo2022-01-184-0/+18
| | | | | | Now btrfs can utilize the newly intorudced BLAKE2 hash. Signed-off-by: Qu Wenruo <wqu@suse.com>
* btrfs: Use U-Boot API for decompressionSimon Glass2021-10-081-46/+5
| | | | | | | Use the common function to avoid code duplication. Acked-by: Qu Wenruo <wqu@suse.com> Signed-off-by: Simon Glass <sjg@chromium.org>
* WS cleanup: remove SPACE(s) followed by TABWIP/2021-09-30-whitespace-cleanupsWolfgang Denk2021-09-301-1/+1
| | | | Signed-off-by: Wolfgang Denk <wd@denx.de>
* WS cleanup: remove excessive empty linesWolfgang Denk2021-09-301-1/+0
| | | | Signed-off-by: Wolfgang Denk <wd@denx.de>
* btrfs: Suppress the message about missing filesystemSimon Glass2021-09-161-2/+6
| | | | | | | | | | | | | This message comes up a lot when scanning filesystems. It suggests to the user that there is some sort of error, but in fact there is no reason to expect that a particular partition has a btrfs filesystem. Other filesystems don't print this error. Turn it into a debug message. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Marek Behún <marek.behun@nic.cz> Reviewed-by: Qu Wenruo <wqu@suse.com>
* btrfs: Use default subvolume as filesystem rootMatwey V. Kornilov2021-09-011-3/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | BTRFS volume consists of a number of subvolumes which can be mounted separately from each other. The top-level subvolume always exists even if no subvolumes were created manually. A subvolume can be denoted as the default subvolume i.e. the subvolume which is mounted by default. The default "default subvolume" is the top-level one, but this is far from the common practices used in the wild. For instance, openSUSE provides an OS snapshot/rollback feature based on BTRFS. To achieve this, the actual OS root filesystem is located into a separate subvolume which is "default" but not "top-level". That means that the /boot/dtb/ directory is also located inside this default subvolume instead of top-level one. However, the existing btrfs u-boot driver always uses the top-level subvolume as the filesystem root. This behaviour 1) is inconsistent with mount /dev/sda1 /target command, which mount the default subvolume 2) leads to the issues when /boot/dtb cannot be found properly (see the reference). This patch uses the default subvolume as the filesystem root to overcome mentioned issues. Reference: https://bugzilla.suse.com/show_bug.cgi?id=1185656 Signed-off-by: Matwey V. Kornilov <matwey.kornilov@gmail.com> Fixes: f06bfcf54d0e ("fs: btrfs: Crossport open_ctree_fs_info() from btrfs-progs") Reviewed-by: Qu Wenruo <wqu@suse.com>
* Use LIB_UUID with ACPIGEN and FS_BTRFSSimon Glass2021-07-281-0/+1
| | | | | | | | | Since the ACPI-generation code makes use of UUIDs we typically need to enabled UUID support for it to build. Add a new Kconfig condition. Use it for BTRFS also. Signed-off-by: Simon Glass <sjg@chromium.org>
* fs: btrfs: Add missing cache aligned allocationMarek Vasut2021-05-261-1/+1
| | | | | | | | | | | | | | The superblock buffer must be cache aligned, since it might be used in DMA context, allocate it using ALLOC_CACHE_ALIGN_BUFFER() just like it was done in btrfs_read_superblock() and read_tree_node(). This fixes this output on boot and non-working btrfs on iMX53: CACHE: Misaligned operation at range [ced299d0, ced2a9d0] Signed-off-by: Marek Vasut <marex@denx.de> Cc: Marek Behún <marek.behun@nic.cz> Cc: Qu Wenruo <wqu@suse.com> Reviewed-by: Marek Behún <marek.behun@nic.cz>
* fs: btrfs: fix the false alert of decompression failureQu Wenruo2021-04-271-2/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | There are some cases where decompressed sectors can have padding zeros. In kernel code, we have lines to address such situation: /* * btrfs_getblock is doing a zero on the tail of the page too, * but this will cover anything missing from the decompressed * data. */ if (bytes < destlen) memset(kaddr+bytes, 0, destlen-bytes); kunmap_local(kaddr); But not in U-boot code, thus we have some reports of U-boot failed to read compressed files in btrfs. Fix it by doing the same thing of the kernel, for both inline and regular compressed extents. Reported-by: Matwey Kornilov <matwey.kornilov@gmail.com> Link: https://bugzilla.suse.com/show_bug.cgi?id=1183717 Fixes: a26a6bedafcf ("fs: btrfs: Introduce btrfs_read_extent_inline() and btrfs_read_extent_reg()") Signed-off-by: Qu Wenruo <wqu@suse.com>
* fs: btrfs: do not fail when offset of a ROOT_ITEM is not -1Marek Behún2021-03-011-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | When the btrfs_read_fs_root() function is searching a ROOT_ITEM with location key offset other than -1, it currently fails via BUG_ON. The offset can have other value than -1, though. This can happen for example if a subvolume is renamed: $ btrfs subvolume create X && sync Create subvolume './X' $ btrfs inspect-internal dump-tree /dev/root | grep -B 2 'name: X$ location key (270 ROOT_ITEM 18446744073709551615) type DIR transid 283 data_len 0 name_len 1 name: X $ mv X Y && sync $ btrfs inspect-internal dump-tree /dev/root | grep -B 2 'name: Y$ location key (270 ROOT_ITEM 0) type DIR transid 285 data_len 0 name_len 1 name: Y As can be seen the offset changed from -1ULL to 0. Do not fail in this case. Signed-off-by: Marek Behún <marek.behun@nic.cz> Cc: David Sterba <dsterba@suse.com> Cc: Qu Wenruo <wqu@suse.com> Cc: Tom Rini <trini@konsulko.com>
* fs: btrfs: change directory list output to be aligned as beforeMarek Behún2021-02-241-7/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since commit 325dd1f642dd ("fs: btrfs: Use btrfs_iter_dir() to ...") when btrfs is listing a directory, the output is not aligned: <SYMLINK> 15 Wed Sep 09 13:20:03 2020 boot.scr -> @/boot/boot.scr <DIR> 0 Tue Feb 02 12:42:09 2021 @ <FILE> 108 Tue Feb 02 12:54:04 2021 1.info Return back to how it was displayed previously, i.e.: <SYM> 15 Wed Sep 09 13:20:03 2020 boot.scr -> @/boot/boot.scr <DIR> 0 Tue Feb 02 12:42:09 2021 @ < > 108 Tue Feb 02 12:54:04 2021 1.info Instead of '<FILE>', print '< >', as ext4 driver. If an unknown directory item type is encountered, we will print the type number left padded with spaces, enclosed by '?', instead of '<' and '>', i.e.: ? 30? ............................. name Signed-off-by: Marek Behún <marek.behun@nic.cz> Fixes: 325dd1f642dd ("fs: btrfs: Use btrfs_iter_dir() to replace ...") Cc: David Sterba <dsterba@suse.com> Cc: Qu Wenruo <wqu@suse.com> Cc: Tom Rini <trini@konsulko.com> Reviewed-by: Qu Wenruo <wqu@suse.com>
* fs: btrfs: skip xattrs in directory listingMarek Behún2021-02-241-1/+4
| | | | | | | | | | | Skip xattrs in directory listing. U-Boot filesystem drivers do not list xattrs. Signed-off-by: Marek Behún <marek.behun@nic.cz> Cc: David Sterba <dsterba@suse.com> Cc: Qu Wenruo <wqu@suse.com> Cc: Tom Rini <trini@konsulko.com> Reviewed-by: Qu Wenruo <wqu@suse.com>
* fs: btrfs: Select SHA256 in KconfigMatthias Brugger2021-01-291-0/+1
| | | | | | | | | | | | | Since commit 565a4147d17a ("fs: btrfs: Add more checksum algorithms") btrfs uses the sha256 checksum algorithm. But Kconfig lacks to select it. This leads to compilation errors: fs/built-in.o: In function `hash_sha256': fs/btrfs/crypto/hash.c:25: undefined reference to `sha256_starts' fs/btrfs/crypto/hash.c:26: undefined reference to `sha256_update' fs/btrfs/crypto/hash.c:27: undefined reference to `sha256_finish' Signed-off-by: Matthias Brugger <mbrugger@suse.com> Reviewed-by: Qu Wenruo <wqu@suse.com>
* fs: btrfs: simplify close_ctree_fs_info()Heinrich Schuchardt2021-01-201-4/+1
| | | | | | | | | | | At the beginning of close_ctree_fs_info() the value 0 is assigned to err and never changed before testing it. Let's get rid of the superfluous variable. Fixes: f06bfcf54d0e ("fs: btrfs: Crossport open_ctree_fs_info() from btrfs-progs") Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Qu Wenruo <wqu@suse.com>
* fs: btrfs: volumes: prevent overflow for multiplyingQu Wenruo2021-01-201-2/+2
| | | | | | | | | | | | | | | | | | In __btrfs_map_block() we do a int * int and assign it to u64. This is not safe as the result (int * int) is still evaluated as (int) thus it can overflow. Convert one of the multiplier to u64 to prevent such problem. In real world, this should not cause problem as we have device number limit thus it won't go beyond 4G for a single stripe. But it's harder to teach coverity about all these hidden limits, so just fix the possible overflow. Reported-by: Coverity CID 312957 Reported-by: Coverity CID 312948 Signed-off-by: Qu Wenruo <wqu@suse.com>
* fs: btrfs: initialize @ret to 0 to prevent uninitialized return valueQu Wenruo2020-11-191-1/+1
| | | | | | | | | | | In show_dir() if we hit a ROOT_ITEM, we can exit with uninitialized @ret. Fix it by initializing it to 0. Reported-by: Coverity CID 312955 Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Marek Behún <marek.behun@nic.cz>
* fs: btrfs: inode: handle uninitialized type before returning itQu Wenruo2020-11-191-1/+5
| | | | | | | | | | | | | | | | | | | | In btrfs_lookup_path() the local variable @type should always be updated after we hit any file/dir. But if @filename is NULL from the very beginning, then we don't initialize it and return it directly. To prevent such problem from happening, we initialize @type to BTRFS_FT_UNKNOWN. For normal execution route, it will get updated for each filename we resolved. Buf if we didn't find any path, we check if the type is still FT_UNKNOWN and ret == 0. If true we know there is something wrong, just return -EUCLEAN to inform the caller. Reported-by: Coverity CID 312958 Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Marek Behún <marek.behun@nic.cz>
* fs: btrfs: Fix typo in error messageNaoki Hayama2020-10-221-2/+2
| | | | | | | | %s/occured/occurred/ Signed-off-by: Naoki Hayama <naoki.hayama@lineo.co.jp> Reviewed-by: Marek Behún <kabel@kernel.org> Reviewed-by: Qu Wenruo <wqu@suse.com>
* fs: btrfs: Cleanup the old implementationQu Wenruo2020-09-0714-1366/+3
| | | | | | | This cleans up the now unneeded code from the old btrfs implementation. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Marek Behún <marek.behun@nic.cz>
* fs: btrfs: Imeplement btrfs_list_subvols() using new infrastructureQu Wenruo2020-09-071-5/+73
| | | | | | | Reimplement btrfs_list_subvols() to use new code. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Marek Behún <marek.behun@nic.cz>
* fs: btrfs: Introduce function to resolve the path of one subvolumeQu Wenruo2020-09-071-0/+81
| | | | | | | | This patch introduces a new function, list_one_subvol(), which will resolve the path to FS_TREE of one subvolume. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Marek Behún <marek.behun@nic.cz>
* fs: btrfs: Introduce function to resolve path in one subvolumeQu Wenruo2020-09-072-1/+68
| | | | | | | | | | This patch introduces a new function, get_path_in_subvolume(), which resolves inode number into path inside a subvolume. This function will be later used for btrfs subvolume list functionality. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Marek Behún <marek.behun@nic.cz>
* fs: btrfs: Implement btrfs_file_read()Qu Wenruo2020-09-073-20/+176
| | | | | | | | | | | | | This version of btrfs_file_read() has the following new features: - Tries all mirrors - More handling on unaligned size - Better compressed extent handling The old implementation doesn't handle compressed extent with offset properly: we need to read out the whole compressed extent, then decompress the whole extent, and only then copy the requested part. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Marek Behún <marek.behun@nic.cz>
* fs: btrfs: Introduce lookup_data_extent() for later useQu Wenruo2020-09-071-0/+101
| | | | | | | | This implements lookup_data_extent() function for the incoming new implementation of btrfs_file_read(). Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Marek Behún <marek.behun@nic.cz>
* fs: btrfs: Introduce btrfs_read_extent_inline() and btrfs_read_extent_reg()Qu Wenruo2020-09-074-0/+205
| | | | | | | | These two functions are used to do sector aligned read, which will be later used to implement btrfs_file_read(). Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Marek Behún <marek.behun@nic.cz>
* fs: btrfs: Rename btrfs_file_read() and its callees to avoid name conflictsQu Wenruo2020-09-074-9/+9
| | | | | | | | Rename btrfs_file_read() and its callees to avoid name conflicts with the incoming new code. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Marek Behún <marek.behun@nic.cz>
* fs: btrfs: Use btrfs_lookup_path() to implement btrfs_exists() and btrfs_size()Qu Wenruo2020-09-071-17/+48
| | | | | | | | After this the only remaining function that still utilizes __btrfs_lookup_path() is btrfs_read(). Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Marek Behún <marek.behun@nic.cz>
* fs: btrfs: Use btrfs_iter_dir() to replace btrfs_readdir()Qu Wenruo2020-09-074-91/+144
| | | | | | | | | | | | | | | | | Use 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 boundary. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Marek Behún <marek.behun@nic.cz>
* fs: btrfs: Implement btrfs_lookup_path()Qu Wenruo2020-09-073-0/+360
| | | | | | | | | | | | | | This is the extent buffer based path lookup routine. To implement this, btrfs_lookup_dir_item() is crossported from btrfs-progs, and implements btrfs_lookup_path() from scratch. Unlike the existing __btrfs_lookup_path(), since btrfs_read_fs_root() will check whether a root is a orphan at read time, there is no need to check root backref, this makes the code a little easier to read. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Marek Behún <marek.behun@nic.cz>
* fs: btrfs: inode: Allow next_length() to return value > BTRFS_NAME_LENQu Wenruo2020-09-071-2/+6
| | | | | | | | | | | All 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 makes next_length() exit as soon as we're beyond BTRFS_NAME_LEN. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Marek Behún <marek.behun@nic.cz>
* fs: btrfs: Use btrfs_readlink() to implement __btrfs_readlink()Qu Wenruo2020-09-072-37/+65
| | | | | | | | | | The existing __btrfs_readlink() can be easily re-implemented using the extent buffer based btrfs_readlink(). This is the first step to re-implement U-Boot's btrfs code. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Marek Behún <marek.behun@nic.cz>
* fs: btrfs: Rename path resolve related functions to avoid name conflictsQu Wenruo2020-09-077-33/+43
| | | | | | | | | Since the old code is using __btrfs_path/__btrfs_root which is different from the regular extent buffer based one, we add "__" prefix for the old implementation to avoid name conflicts for the incoming crossport. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Marek Behún <marek.behun@nic.cz>
* fs: btrfs: Crossport open_ctree_fs_info() from btrfs-progsQu Wenruo2020-09-078-20/+579
| | | | | | | | | | | | | | | | | | | | open_ctree_fs_info() is the main entry point to open 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, U-Boot uses blk_desc and disk_partition_t. - Remove open_ctree flags There won't be multiple open ctree modes in U-Boot. Otherwise functions structures 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. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Marek Behún <marek.behun@nic.cz>
* fs: btrfs: Crossport btrfs_read_sys_array() and btrfs_read_chunk_tree()Qu Wenruo2020-09-075-3/+306
| | | | | | | | | | | | | These 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. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Marek Behún <marek.behun@nic.cz>
* fs: btrfs: Crossport btrfs_search_slot() from btrfs-progsQu Wenruo2020-09-072-7/+591
| | | | | | | | | | | | | | | | | | | | This patch copies the core function, btrfs_search_slot(), from btrfs-progs. This version has the following functionality removed: - The ability to COW tree block Related code is commented out, and can be enabled in the future. - The readahead functionality This is abused in kernel. Remove it completely. With the core function in place, btrfs developers should feel at home now. This also crossports supporting code like btrfs_previous_item() to ctree.[ch]. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Marek Behún <marek.behun@nic.cz>
* fs: btrfs: Crossport struct btrfs_root to ctree.hQu Wenruo2020-09-071-0/+17
| | | | | | | | Crossport struct btrfs_root to ctree.h from btrfs-progs, with write related members deleted. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Marek Behún <marek.behun@nic.cz>
* fs: btrfs: Rename btrfs_root to __btrfs_rootQu Wenruo2020-09-078-34/+34
| | | | | | | | This is to avoid naming conflicts between extent buffer based btrfs_root. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Marek Behún <marek.behun@nic.cz>
* fs: btrfs: Rename struct btrfs_path to struct __btrfs_pathQu Wenruo2020-09-079-44/+44
| | | | | | | | | | To avoid name conflicting between the extent buffer based btrfs_path from btrfs-progs, rename struct btrfs_path to struct __btrfs_path. Also rename btrfs_free_path() to __btrfs_free_path() to avoid conflicts. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Marek Behún <marek.behun@nic.cz>
* fs: btrfs: Crossport read_tree_block() from btrfs-progsQu Wenruo2020-09-075-8/+602
| | | | | | | | | | | | | This is the one of the basic stone function for btrfs, which: - Resolves the chunk mappings - Reads data from disk - Does various sanity check With read_tree_block(), we can finally crossport needed btrfs btree operations to U-Boot. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Marek Behún <marek.behun@nic.cz>
* fs: btrfs: Crossport volumes.[ch] from btrfs-progsQu Wenruo2020-09-075-1/+1081
| | | | | | | | | | | | | | | | | | This patch crossports 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. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Marek Behún <marek.behun@nic.cz> [trini: Use %zu in a debug print to avoid warning] Signed-off-by: Tom Rini <trini@konsulko.com>
* fs: btrfs: Crossport structure accessor into ctree.hQu Wenruo2020-09-073-95/+1064
| | | | | | | | | | | | This brings all structure accessors from btrfs-progs/ctree.h, as in kernel's ctree.h. All these accessors handle the endian convert at runtime, and since all of them are defined as static inline functions, those which aren't used won't take space in resulting binary. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Marek Behún <marek.behun@nic.cz>