Description
HARDLINK_SCOPE uses Lstat() to check st_nlink for determining whether torrent files are linked to an external library. This works for traditional hardlinks (same inode, nlink increments) but does not detect reflinks/block clones.
On ZFS with block cloning enabled (and other CoW filesystems like btrfs with cp --reflink), deduplication tools like fclones dedupe create reflinks that share physical disk blocks but maintain separate inodes with independent nlink counts. These files are invisible to the current hardlink detection.
Impact
- Torrents whose files are reflinked to the media library are classified as
HARDLINK_SCOPE != outside_qbittorrent
- Automation rules using
HARDLINK_SCOPE (e.g., noHL tagging, share limits, cleanup rules) incorrectly treat reflinked torrents as having no library connection
- This can lead to premature cleanup of torrents that are still serving the media library via reflinks
Current Workaround
Switch deduplication from reflink mode to hardlink mode (e.g., fclones link instead of fclones dedupe). This creates traditional hardlinks that Lstat() can detect, but loses the CoW benefits of reflinks (independent metadata, separate file lifecycle).
Suggested Enhancement
Consider detecting reflinks in addition to hardlinks when building the hardlink index. Possible approaches:
ficlone / FICLONE ioctl — Check if two files share extents (filesystem-dependent)
- Compare file content hashes — Expensive but filesystem-agnostic
filefrag / FIEMAP ioctl — Compare physical block mappings to detect shared extents on supported filesystems (btrfs, ZFS, XFS)
- Document the limitation — At minimum, note in the HARDLINK_SCOPE documentation that reflinks are not detected
Environment
- ZFS 2.2.9 with block cloning enabled
fclones dedupe (reflink mode) for deduplication
- qui develop branch
Description
HARDLINK_SCOPEusesLstat()to checkst_nlinkfor determining whether torrent files are linked to an external library. This works for traditional hardlinks (same inode, nlink increments) but does not detect reflinks/block clones.On ZFS with block cloning enabled (and other CoW filesystems like btrfs with
cp --reflink), deduplication tools likefclones dedupecreate reflinks that share physical disk blocks but maintain separate inodes with independent nlink counts. These files are invisible to the current hardlink detection.Impact
HARDLINK_SCOPE != outside_qbittorrentHARDLINK_SCOPE(e.g., noHL tagging, share limits, cleanup rules) incorrectly treat reflinked torrents as having no library connectionCurrent Workaround
Switch deduplication from reflink mode to hardlink mode (e.g.,
fclones linkinstead offclones dedupe). This creates traditional hardlinks thatLstat()can detect, but loses the CoW benefits of reflinks (independent metadata, separate file lifecycle).Suggested Enhancement
Consider detecting reflinks in addition to hardlinks when building the hardlink index. Possible approaches:
ficlone/FICLONEioctl — Check if two files share extents (filesystem-dependent)filefrag/FIEMAPioctl — Compare physical block mappings to detect shared extents on supported filesystems (btrfs, ZFS, XFS)Environment
fclones dedupe(reflink mode) for deduplication