• Qu Wenruo's avatar
    btrfs: delayed-ref: Introduce better documented delayed ref structures · b28b1f0c
    Qu Wenruo authored
    Current delayed ref interface has several problems:
    
    - Longer and longer parameter lists
      bytenr
      num_bytes
      parent
      ---------- so far so good
      ref_root
      owner
      offset
      ---------- I don't feel good now
    
    - Different interpretation of the same parameter
    
      Above @owner for data ref is inode number (u64),
      while for tree ref, it's level (int).
    
      They are even in different size range.
      For level we only need 0 ~ 8, while for ino it's
      BTRFS_FIRST_FREE_OBJECTID ~ BTRFS_LAST_FREE_OBJECTID.
    
      And @offset doesn't even make sense for tree ref.
    
      Such parameter reuse may look clever as an hidden union, but it
      destroys code readability.
    
    To solve both problems, we introduce a new structure, btrfs_ref to solve
    them:
    
    - Structure instead of long parameter list
      This makes later expansion easier, and is better documented.
    
    - Use btrfs_ref::type to distinguish data and tree ref
    
    - Use proper union to store data/tree ref specific structures.
    
    - Use separate functions to fill data/tree ref data, with a common generic
      function to fill common bytenr/num_bytes members.
    
    All parameters will find its place in btrfs_ref, and an extra member,
    @real_root, inspired by ref-verify code, is newly introduced for later
    qgroup code, to record which tree is triggered by this extent modification.
    
    This patch doesn't touch any code, but provides the basis for further
    refactoring.
    Signed-off-by: default avatarQu Wenruo <wqu@suse.com>
    Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
    Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
    b28b1f0c
delayed-ref.h 10.5 KB