Skip to content

RFC Btrfs: add interface for writing compressed extent directly

Omar Sandoval linux-btrfs 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest5 patches 17 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5Btrfs: use correct count in btrfs_file_write_iter()fs/btrfs/file.c+2 -11 reply
2/5Btrfs: treat RWF_{,D}SYNC writes as sync for CRCsfs/btrfs/file.c+1 -14 replies
3/5Btrfs: stop clearing EXTENT_DIRTY in inode I/O treefs/btrfs/extent_io.c fs/btrfs/file.c fs/btrfs/free-space-cache.c +3 more+30 -471 reply
4/5fs: export rw_verify_area()fs/internal.h fs/read_write.c include/linux/fs.h+2 -51 reply
5/5Btrfs: add ioctl for directly writing compressed datafs/btrfs/compression.c fs/btrfs/compression.h fs/btrfs/ctree.h +4 more+380 -158 replies

Reviews trailers per patch

4 of 5 patches have a Reviewed-by or Acked-by.

PatchJosef Bacik
1/5R-b
2/5R-b
3/5R-b
4/5R-b
5/5

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [RFC PATCH 0/5] Btrfs: add interface for writing compressed extent directly

From: Omar Sandoval <[email protected]>

Hello,

This series adds a way to write compressed data directly to Btrfs. The intended use case is making send/receive on compressed file systems more efficient; however, the interface is general enough that it could be used in other scenarios. Patch 5 is the main change; see that for more details.

Patches 1-3 are small fixes/cleanups that I ran into while implementing this; they should go in regardless of the remainder of the series. Patch 4 exports a required VFS interface.

An example program and test case are available at [1].

To preemptively address a few concerns:

- Writing arbitrary, untrusted data which we feed to the decompression algorithm can be a security risk. For that reason, the ioctl is restricted to CAP_SYS_ADMIN. The Btrfs code is properly hardened against invalid compressed data/incorrect lengths, and the compression libraries are mature, but better safe than sorry for now.
- If the user is writing their own compressed data rather than just blindly feeding in something from btrfs send, they need to know some implementation details about the compression format. For zlib, there are no special requirements. For zstd, a non-default compression parameter must be used. For lzo, we have our own wrapper format since lzo doesn't have a standard wrapper format. It feels a little wrong to expose these details, but they are part of the on-disk format, so they must be stable regardless.
- The permissions checks duplicated from the VFS code are fairly minimal.

This series is based on misc-next.

This is an RFC, so please, comment away.

Thanks!

1: https://github.com/osandov/xfstests/tree/btrfs-compressed-write

Omar Sandoval (5):
Btrfs: use correct count in btrfs_file_write_iter()
Btrfs: treat RWF_{,D}SYNC writes as sync for CRCs
Btrfs: stop clearing EXTENT_DIRTY in inode I/O tree
fs: export rw_verify_area()
Btrfs: add ioctl for directly writing compressed data

 fs/btrfs/compression.c       |   6 +-
 fs/btrfs/compression.h       |  14 +--
 fs/btrfs/ctree.h             |  12 ++
 fs/btrfs/extent_io.c         |   6 +-
 fs/btrfs/file.c              |  22 ++--
 fs/btrfs/free-space-cache.c  |   9 +-
 fs/btrfs/inode.c             | 232 +++++++++++++++++++++++++++++++----
 fs/btrfs/ioctl.c             | 101 ++++++++++++++-
 fs/btrfs/tests/inode-tests.c |  12 +-
 fs/internal.h                |   5 -
 fs/read_write.c              |   1 +
 include/linux/fs.h           |   1 +
 include/uapi/linux/btrfs.h   |  63 ++++++++++
 13 files changed, 415 insertions(+), 69 deletions(-)
Signature · 1 line
2.17.1