From e3747320cf7cecf9f977d3805d7980b08e5e63c0 Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Mon, 10 Jun 2019 22:53:35 -0400 Subject: [PATCH] BtrfsExtentWalker: use a buffer at least as large as a btrfs metadata page to avoid EOVERFLOW We are getting a lot of exceptions when an inline extent is too large for the TREE_SEARCH_V2 buffer. This disrupts ExtentWalker's extent boundary search when there is an inline extent at the beginning of a file: # fiemap foo Log 0x0..0x1000 Phy 0x0..0x1000 Flags FIEMAP_EXTENT_NOT_ALIGNED|FIEMAP_EXTENT_DATA_INLINE Log 0x1000..0x2000 Phy 0x7307f9000..0x7307fa000 Flags 0 Log 0x2000..0x3000 Phy 0x731078000..0x731079000 Flags 0 Log 0x3000..0x5000 Phy 0x73127d000..0x73127f000 Flags FIEMAP_EXTENT_ENCODED Log 0x5000..0x6000 Phy 0x73137a000..0x73137b000 Flags 0 Log 0x6000..0x7000 Phy 0x731683000..0x731684000 Flags 0 Log 0x7000..0x8000 Phy 0x73224f000..0x732250000 Flags 0 Log 0x8000..0x9000 Phy 0x7323c9000..0x7323ca000 Flags 0 Log 0x9000..0xb000 Phy 0x732425000..0x732427000 Flags FIEMAP_EXTENT_ENCODED Log 0xb000..0xc000 Phy 0x732598000..0x732599000 Flags 0 Log 0xc000..0xd000 Phy 0x7325d5000..0x7325d6000 Flags FIEMAP_EXTENT_LAST # fiewalk foo exception type std::system_error: BTRFS_IOC_TREE_SEARCH_V2: /tmp/foo at fs.cc:844: Value too large for defined data type Normally crawlers simply skip over inline extents, but ExtentWalker will seek backward from the first non-inline extent to confirm that it has an accurate starting block for the target extent. This fails when it encounters the first inline extent. strace reveals that buffer size is too small for the first extent, as seen here: ioctl(3, BTRFS_IOC_TREE_SEARCH_V2, {key={tree_id=258, min_objectid=78897856, max_objectid=UINT64_MAX, min_offset=0, max_offset=UINT64_MAX, min_transid=0, max_transid=UINT64_MAX, min_type=BTRFS_EXTENT_DATA_KEY, max_type=BTRFS_EXTENT_DATA_KEY, nr_items=16}, buf_size=1360} => {buf_size=1418}) = -1 EOVERFLOW (Value too large for defined data type) Fix this by increasing the buffer size until it can handle the largest possible object on the largest possible btrfs metadata page (65536 bytes). BtrfsExtentWalker already has optimizations to minimize the allocation cost, so we don't need any changes there. Signed-off-by: Zygo Blaxell --- lib/extentwalker.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/extentwalker.cc b/lib/extentwalker.cc index 5a1b91f..f79ef1e 100644 --- a/lib/extentwalker.cc +++ b/lib/extentwalker.cc @@ -470,7 +470,7 @@ namespace crucible { BtrfsExtentWalker::Vec BtrfsExtentWalker::get_extent_map(off_t pos) { - BtrfsIoctlSearchKey sk(sc_extent_fetch_max * (sizeof(btrfs_file_extent_item) + sizeof(btrfs_ioctl_search_header))); + BtrfsIoctlSearchKey sk(65536); if (!m_root_fd) { m_root_fd = m_fd; }