Skip to content

HARDLINK_SCOPE does not detect reflinks (ZFS block cloning / CoW filesystems) #1539

Description

@bakerboy448

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:

  1. ficlone / FICLONE ioctl — Check if two files share extents (filesystem-dependent)
  2. Compare file content hashes — Expensive but filesystem-agnostic
  3. filefrag / FIEMAP ioctl — Compare physical block mappings to detect shared extents on supported filesystems (btrfs, ZFS, XFS)
  4. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions