On Thu, Apr 04, 2019 at 02:45:29PM +0800, Qu Wenruo wrote:
> 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 for 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 makes 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 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 this extent modification.
> 
> This patch doesn't touch any code, but provides the basis for incoming
> refactors.
> 
> Signed-off-by: Qu Wenruo <w...@suse.com>
> ---
>  fs/btrfs/delayed-ref.h | 116 +++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 116 insertions(+)
> 
> diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h
> index 70606da440aa..8eb5b3576759 100644
> --- a/fs/btrfs/delayed-ref.h
> +++ b/fs/btrfs/delayed-ref.h
> @@ -176,6 +176,90 @@ struct btrfs_delayed_ref_root {
>       u64 qgroup_to_skip;
>  };
>  
> +enum btrfs_ref_type {
> +     BTRFS_REF_NOT_SET,
> +     BTRFS_REF_DATA,
> +     BTRFS_REF_METADATA,
> +     BTRFS_REF_LAST,
> +};
> +
> +struct btrfs_data_ref {
> +     /* For EXTENT_DATA_REF */
> +
> +     /* Root who refers to this data extent */
> +     u64 ref_root;
> +
> +     /* Inode who refers to this data extent */
> +     u64 ino;
> +
> +     /*
> +      * file_offset - extent_offset
> +      *
> +      * file_offset is the key.offset of the EXTENT_DATA key.
> +      * extent_offset is btrfs_file_extent_offset() of the EXTENT_DATA data.
> +      */
> +     u64 offset;
> +};
> +
> +struct btrfs_tree_ref {
> +     /*
> +      * Level of this tree block
> +      *
> +      * Shared for skinny (TREE_BLOCK_REF) and normal tree ref.
> +      */
> +     int level;
> +
> +     /*
> +      * Root who refers to this tree block.
> +      *
> +      * For TREE_BLOCK_REF (skinny metadata, either inline or keyed)
> +      */
> +     u64 root;
> +
> +     /* For non-skinny metadata, no special member needed */
> +};
> +
> +struct btrfs_ref {

The structure name sounds a bit generic, but I think we can keep it
short. There are no other btrfs-specific references that could be
confused, there are 'backrefs', 'delayed-refs' all refering to the
b-tree references.

> +     enum btrfs_ref_type type;
> +     int action;
> +
> +     /*
> +      * Only use parent pointers as backref (SHARED_BLOCK_REF or
> +      * SHARED_DATA_REF) for this extent and its children.
> +      * Set for reloc trees.
> +      */
> +     bool only_backreferences:1;

No bool bitfields please, wasn't this mentioned last time?

Reply via email to