btrfs: add BTRFS_IOC_ENCODED_READ ioctl
authorOmar Sandoval <osandov@fb.com>
Thu, 10 Oct 2019 00:59:07 +0000 (17:59 -0700)
committerDavid Sterba <dsterba@suse.com>
Tue, 15 Feb 2022 15:54:50 +0000 (16:54 +0100)
commitf8fdec1e3aeb23801edc56d78f9439776d151c06
treee89e38094009f26d4d80bc57116df1df248d504f
parent6032db9d6ec81c5dcadd96d1363179f30b5069b9
btrfs: add BTRFS_IOC_ENCODED_READ ioctl

There are 4 main cases:

1. Inline extents: we copy the data straight out of the extent buffer.
2. Hole/preallocated extents: we fill in zeroes.
3. Regular, uncompressed extents: we read the sectors we need directly
   from disk.
4. Regular, compressed extents: we read the entire compressed extent
   from disk and indicate what subset of the decompressed extent is in
   the file.

This initial implementation simplifies a few things that can be improved
in the future:

- We hold the inode lock during the operation.
- Cases 1, 3, and 4 allocate temporary memory to read into before
  copying out to userspace.
- We don't do read repair, because it turns out that read repair is
  currently broken for compressed data.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/ctree.h
fs/btrfs/inode.c
fs/btrfs/ioctl.c