Open
Description
So to sum up, I think we can add back optimization via:
- if the file is on squashfs/erofs, then it's immutable (detectable via
statfs
- if the is sealed with
F_SEAL_WRITE
(prevent modifying of existing contents, shrinking and appending is allowed) andF_SEAL_SEAL
(not changing of seals), detectable viafcntl(fd, F_GET_SEALS)
- if it's on read-only btrfs subvolume (e.g. snapshot), likewise we can do the same for zfs, nilfs, bcachefs
- If the file is
/dev/zero
, or from other pseudo fs (e.g. procfs, sysfe), then I think we can assume it's immutable
Otherwise, we'd fallback to:
- read + write if the file is really small
- splice to an intermediate pipe with F_MOVE and then splice to the pipe without F_MOVE if the file is more than 1-2 pages
- if the fs supports reflink and file is really large, then we could create a O_TMPFILE on the system, copy_file_range to it and then splice it
Also, if the file is a named fifo, then just a splice without F_MOVE would work fine.
Originally posted by @NobodyXu in #108283 (comment)