1*8719aaaeSJosef Bacik /* SPDX-License-Identifier: GPL-2.0 */ 2*8719aaaeSJosef Bacik 3*8719aaaeSJosef Bacik #ifndef BTRFS_SPACE_INFO_H 4*8719aaaeSJosef Bacik #define BTRFS_SPACE_INFO_H 5*8719aaaeSJosef Bacik 6*8719aaaeSJosef Bacik struct btrfs_space_info { 7*8719aaaeSJosef Bacik spinlock_t lock; 8*8719aaaeSJosef Bacik 9*8719aaaeSJosef Bacik u64 total_bytes; /* total bytes in the space, 10*8719aaaeSJosef Bacik this doesn't take mirrors into account */ 11*8719aaaeSJosef Bacik u64 bytes_used; /* total bytes used, 12*8719aaaeSJosef Bacik this doesn't take mirrors into account */ 13*8719aaaeSJosef Bacik u64 bytes_pinned; /* total bytes pinned, will be freed when the 14*8719aaaeSJosef Bacik transaction finishes */ 15*8719aaaeSJosef Bacik u64 bytes_reserved; /* total bytes the allocator has reserved for 16*8719aaaeSJosef Bacik current allocations */ 17*8719aaaeSJosef Bacik u64 bytes_may_use; /* number of bytes that may be used for 18*8719aaaeSJosef Bacik delalloc/allocations */ 19*8719aaaeSJosef Bacik u64 bytes_readonly; /* total bytes that are read only */ 20*8719aaaeSJosef Bacik 21*8719aaaeSJosef Bacik u64 max_extent_size; /* This will hold the maximum extent size of 22*8719aaaeSJosef Bacik the space info if we had an ENOSPC in the 23*8719aaaeSJosef Bacik allocator. */ 24*8719aaaeSJosef Bacik 25*8719aaaeSJosef Bacik unsigned int full:1; /* indicates that we cannot allocate any more 26*8719aaaeSJosef Bacik chunks for this space */ 27*8719aaaeSJosef Bacik unsigned int chunk_alloc:1; /* set if we are allocating a chunk */ 28*8719aaaeSJosef Bacik 29*8719aaaeSJosef Bacik unsigned int flush:1; /* set if we are trying to make space */ 30*8719aaaeSJosef Bacik 31*8719aaaeSJosef Bacik unsigned int force_alloc; /* set if we need to force a chunk 32*8719aaaeSJosef Bacik alloc for this space */ 33*8719aaaeSJosef Bacik 34*8719aaaeSJosef Bacik u64 disk_used; /* total bytes used on disk */ 35*8719aaaeSJosef Bacik u64 disk_total; /* total bytes on disk, takes mirrors into 36*8719aaaeSJosef Bacik account */ 37*8719aaaeSJosef Bacik 38*8719aaaeSJosef Bacik u64 flags; 39*8719aaaeSJosef Bacik 40*8719aaaeSJosef Bacik /* 41*8719aaaeSJosef Bacik * bytes_pinned is kept in line with what is actually pinned, as in 42*8719aaaeSJosef Bacik * we've called update_block_group and dropped the bytes_used counter 43*8719aaaeSJosef Bacik * and increased the bytes_pinned counter. However this means that 44*8719aaaeSJosef Bacik * bytes_pinned does not reflect the bytes that will be pinned once the 45*8719aaaeSJosef Bacik * delayed refs are flushed, so this counter is inc'ed every time we 46*8719aaaeSJosef Bacik * call btrfs_free_extent so it is a realtime count of what will be 47*8719aaaeSJosef Bacik * freed once the transaction is committed. It will be zeroed every 48*8719aaaeSJosef Bacik * time the transaction commits. 49*8719aaaeSJosef Bacik */ 50*8719aaaeSJosef Bacik struct percpu_counter total_bytes_pinned; 51*8719aaaeSJosef Bacik 52*8719aaaeSJosef Bacik struct list_head list; 53*8719aaaeSJosef Bacik /* Protected by the spinlock 'lock'. */ 54*8719aaaeSJosef Bacik struct list_head ro_bgs; 55*8719aaaeSJosef Bacik struct list_head priority_tickets; 56*8719aaaeSJosef Bacik struct list_head tickets; 57*8719aaaeSJosef Bacik /* 58*8719aaaeSJosef Bacik * tickets_id just indicates the next ticket will be handled, so note 59*8719aaaeSJosef Bacik * it's not stored per ticket. 60*8719aaaeSJosef Bacik */ 61*8719aaaeSJosef Bacik u64 tickets_id; 62*8719aaaeSJosef Bacik 63*8719aaaeSJosef Bacik struct rw_semaphore groups_sem; 64*8719aaaeSJosef Bacik /* for block groups in our same type */ 65*8719aaaeSJosef Bacik struct list_head block_groups[BTRFS_NR_RAID_TYPES]; 66*8719aaaeSJosef Bacik wait_queue_head_t wait; 67*8719aaaeSJosef Bacik 68*8719aaaeSJosef Bacik struct kobject kobj; 69*8719aaaeSJosef Bacik struct kobject *block_group_kobjs[BTRFS_NR_RAID_TYPES]; 70*8719aaaeSJosef Bacik }; 71*8719aaaeSJosef Bacik 72*8719aaaeSJosef Bacik static inline bool btrfs_mixed_space_info(struct btrfs_space_info *space_info) 73*8719aaaeSJosef Bacik { 74*8719aaaeSJosef Bacik return ((space_info->flags & BTRFS_BLOCK_GROUP_METADATA) && 75*8719aaaeSJosef Bacik (space_info->flags & BTRFS_BLOCK_GROUP_DATA)); 76*8719aaaeSJosef Bacik } 77*8719aaaeSJosef Bacik 78*8719aaaeSJosef Bacik #endif /* BTRFS_SPACE_INFO_H */ 79