extent_io.c (355a47ae7ebcf9d605aa809b259d380422e81b8d) extent_io.c (5911c8fe05c54c9f74a6467650e6493e4808cd01)
1// SPDX-License-Identifier: GPL-2.0
2
3#include <linux/bitops.h>
4#include <linux/slab.h>
5#include <linux/bio.h>
6#include <linux/mm.h>
7#include <linux/pagemap.h>
8#include <linux/page-flags.h>

--- 4528 unchanged lines hidden (view full) ---

4537 u64 disko = 0;
4538 u64 isize = i_size_read(inode);
4539 struct btrfs_key found_key;
4540 struct extent_map *em = NULL;
4541 struct extent_state *cached_state = NULL;
4542 struct btrfs_path *path;
4543 struct btrfs_root *root = BTRFS_I(inode)->root;
4544 struct fiemap_cache cache = { 0 };
1// SPDX-License-Identifier: GPL-2.0
2
3#include <linux/bitops.h>
4#include <linux/slab.h>
5#include <linux/bio.h>
6#include <linux/mm.h>
7#include <linux/pagemap.h>
8#include <linux/page-flags.h>

--- 4528 unchanged lines hidden (view full) ---

4537 u64 disko = 0;
4538 u64 isize = i_size_read(inode);
4539 struct btrfs_key found_key;
4540 struct extent_map *em = NULL;
4541 struct extent_state *cached_state = NULL;
4542 struct btrfs_path *path;
4543 struct btrfs_root *root = BTRFS_I(inode)->root;
4544 struct fiemap_cache cache = { 0 };
4545 struct ulist *roots;
4546 struct ulist *tmp_ulist;
4545 int end = 0;
4546 u64 em_start = 0;
4547 u64 em_len = 0;
4548 u64 em_end = 0;
4549
4550 if (len == 0)
4551 return -EINVAL;
4552
4553 path = btrfs_alloc_path();
4554 if (!path)
4555 return -ENOMEM;
4556 path->leave_spinning = 1;
4557
4547 int end = 0;
4548 u64 em_start = 0;
4549 u64 em_len = 0;
4550 u64 em_end = 0;
4551
4552 if (len == 0)
4553 return -EINVAL;
4554
4555 path = btrfs_alloc_path();
4556 if (!path)
4557 return -ENOMEM;
4558 path->leave_spinning = 1;
4559
4560 roots = ulist_alloc(GFP_KERNEL);
4561 tmp_ulist = ulist_alloc(GFP_KERNEL);
4562 if (!roots || !tmp_ulist) {
4563 ret = -ENOMEM;
4564 goto out_free_ulist;
4565 }
4566
4558 start = round_down(start, btrfs_inode_sectorsize(inode));
4559 len = round_up(max, btrfs_inode_sectorsize(inode)) - start;
4560
4561 /*
4562 * lookup the last file extent. We're not using i_size here
4563 * because there might be preallocation past i_size
4564 */
4565 ret = btrfs_lookup_file_extent(NULL, root, path,
4566 btrfs_ino(BTRFS_I(inode)), -1, 0);
4567 if (ret < 0) {
4568 btrfs_free_path(path);
4567 start = round_down(start, btrfs_inode_sectorsize(inode));
4568 len = round_up(max, btrfs_inode_sectorsize(inode)) - start;
4569
4570 /*
4571 * lookup the last file extent. We're not using i_size here
4572 * because there might be preallocation past i_size
4573 */
4574 ret = btrfs_lookup_file_extent(NULL, root, path,
4575 btrfs_ino(BTRFS_I(inode)), -1, 0);
4576 if (ret < 0) {
4577 btrfs_free_path(path);
4569 return ret;
4578 goto out_free_ulist;
4570 } else {
4571 WARN_ON(!ret);
4572 if (ret == 1)
4573 ret = 0;
4574 }
4575
4576 path->slots[0]--;
4577 btrfs_item_key_to_cpu(path->nodes[0], &found_key, path->slots[0]);

--- 92 unchanged lines hidden (view full) ---

4670 * As btrfs supports shared space, this information
4671 * can be exported to userspace tools via
4672 * flag FIEMAP_EXTENT_SHARED. If fi_extents_max == 0
4673 * then we're just getting a count and we can skip the
4674 * lookup stuff.
4675 */
4676 ret = btrfs_check_shared(root,
4677 btrfs_ino(BTRFS_I(inode)),
4579 } else {
4580 WARN_ON(!ret);
4581 if (ret == 1)
4582 ret = 0;
4583 }
4584
4585 path->slots[0]--;
4586 btrfs_item_key_to_cpu(path->nodes[0], &found_key, path->slots[0]);

--- 92 unchanged lines hidden (view full) ---

4679 * As btrfs supports shared space, this information
4680 * can be exported to userspace tools via
4681 * flag FIEMAP_EXTENT_SHARED. If fi_extents_max == 0
4682 * then we're just getting a count and we can skip the
4683 * lookup stuff.
4684 */
4685 ret = btrfs_check_shared(root,
4686 btrfs_ino(BTRFS_I(inode)),
4678 bytenr);
4687 bytenr, roots, tmp_ulist);
4679 if (ret < 0)
4680 goto out_free;
4681 if (ret)
4682 flags |= FIEMAP_EXTENT_SHARED;
4683 ret = 0;
4684 }
4685 if (test_bit(EXTENT_FLAG_COMPRESSED, &em->flags))
4686 flags |= FIEMAP_EXTENT_ENCODED;

--- 29 unchanged lines hidden (view full) ---

4716out_free:
4717 if (!ret)
4718 ret = emit_last_fiemap_cache(fieinfo, &cache);
4719 free_extent_map(em);
4720out:
4721 btrfs_free_path(path);
4722 unlock_extent_cached(&BTRFS_I(inode)->io_tree, start, start + len - 1,
4723 &cached_state);
4688 if (ret < 0)
4689 goto out_free;
4690 if (ret)
4691 flags |= FIEMAP_EXTENT_SHARED;
4692 ret = 0;
4693 }
4694 if (test_bit(EXTENT_FLAG_COMPRESSED, &em->flags))
4695 flags |= FIEMAP_EXTENT_ENCODED;

--- 29 unchanged lines hidden (view full) ---

4725out_free:
4726 if (!ret)
4727 ret = emit_last_fiemap_cache(fieinfo, &cache);
4728 free_extent_map(em);
4729out:
4730 btrfs_free_path(path);
4731 unlock_extent_cached(&BTRFS_I(inode)->io_tree, start, start + len - 1,
4732 &cached_state);
4733
4734out_free_ulist:
4735 ulist_free(roots);
4736 ulist_free(tmp_ulist);
4724 return ret;
4725}
4726
4727static void __free_extent_buffer(struct extent_buffer *eb)
4728{
4729 btrfs_leak_debug_del(&eb->leak_list);
4730 kmem_cache_free(extent_buffer_cache, eb);
4731}

--- 1274 unchanged lines hidden ---
4737 return ret;
4738}
4739
4740static void __free_extent_buffer(struct extent_buffer *eb)
4741{
4742 btrfs_leak_debug_del(&eb->leak_list);
4743 kmem_cache_free(extent_buffer_cache, eb);
4744}

--- 1274 unchanged lines hidden ---