diff mbox series

[v2] fs: btrfs: support sparse extents

Message ID 20200330164842.12391-1-marek.behun@nic.cz
State Accepted
Commit 48180e15d3eaff51b1da30a90bc64b7acba8fb51
Delegated to: Tom Rini
Headers show
Series [v2] fs: btrfs: support sparse extents | expand

Commit Message

Marek Behun March 30, 2020, 4:48 p.m. UTC
When logical address of a regular extent is 0, the extent is sparse and
consists of all zeros.

Without this when sparse extents are used in a file reading fails with
  Cannot map logical address 0 to physical

Signed-off-by: Marek Behún <marek.behun@nic.cz>
---
 fs/btrfs/extent-io.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Tom Rini April 21, 2020, 12:25 p.m. UTC | #1
On Mon, Mar 30, 2020 at 06:48:42PM +0200, Marek Behún wrote:

> When logical address of a regular extent is 0, the extent is sparse and
> consists of all zeros.
> 
> Without this when sparse extents are used in a file reading fails with
>   Cannot map logical address 0 to physical
> 
> Signed-off-by: Marek Behún <marek.behun@nic.cz>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/fs/btrfs/extent-io.c b/fs/btrfs/extent-io.c
index 66d0e1c7d6..2e4599cf64 100644
--- a/fs/btrfs/extent-io.c
+++ b/fs/btrfs/extent-io.c
@@ -78,6 +78,12 @@  u64 btrfs_read_extent_reg(struct btrfs_path *path,
 	if (size > dlen - offset)
 		size = dlen - offset;
 
+	/* sparse extent */
+	if (extent->disk_bytenr == 0) {
+		memset(out, 0, size);
+		return size;
+	}
+
 	physical = btrfs_map_logical_to_physical(extent->disk_bytenr);
 	if (physical == -1ULL)
 		return -1ULL;