1 /* SPDX-License-Identifier: GPL-2.0-only */
5 * Allocation reservations function prototypes and structures.
7 * Copyright (C) 2010 Novell. All rights reserved.
10 #ifndef OCFS2_RESERVATIONS_H
11 #define OCFS2_RESERVATIONS_H
13 #include <linux/rbtree.h>
15 #define OCFS2_DEFAULT_RESV_LEVEL 2
16 #define OCFS2_MAX_RESV_LEVEL 9
17 #define OCFS2_MIN_RESV_LEVEL 0
19 struct ocfs2_alloc_reservation {
20 struct rb_node r_node;
22 unsigned int r_start; /* Beginning of current window */
23 unsigned int r_len; /* Length of the window */
25 unsigned int r_last_len; /* Length of most recent alloc */
26 unsigned int r_last_start; /* Start of most recent alloc */
27 struct list_head r_lru; /* LRU list head */
32 #define OCFS2_RESV_FLAG_INUSE 0x01 /* Set when r_node is part of a btree */
33 #define OCFS2_RESV_FLAG_TMP 0x02 /* Temporary reservation, will be
34 * destroyed immedately after use */
35 #define OCFS2_RESV_FLAG_DIR 0x04 /* Reservation is for an unindexed
38 struct ocfs2_reservation_map {
39 struct rb_root m_reservations;
42 struct ocfs2_super *m_osb;
44 /* The following are not initialized to meaningful values until a disk
45 * bitmap is provided. */
46 u32 m_bitmap_len; /* Number of valid
49 struct list_head m_lru; /* LRU of reservations
54 void ocfs2_resv_init_once(struct ocfs2_alloc_reservation *resv);
56 #define OCFS2_RESV_TYPES (OCFS2_RESV_FLAG_TMP|OCFS2_RESV_FLAG_DIR)
57 void ocfs2_resv_set_type(struct ocfs2_alloc_reservation *resv,
60 int ocfs2_dir_resv_allowed(struct ocfs2_super *osb);
63 * ocfs2_resv_discard() - truncate a reservation
65 * @resv: the reservation to truncate.
67 * After this function is called, the reservation will be empty, and
68 * unlinked from the rbtree.
70 void ocfs2_resv_discard(struct ocfs2_reservation_map *resmap,
71 struct ocfs2_alloc_reservation *resv);
75 * ocfs2_resmap_init() - Initialize fields of a reservations bitmap
76 * @resmap: struct ocfs2_reservation_map to initialize
77 * @obj: unused for now
78 * @ops: unused for now
79 * @max_bitmap_bytes: Maximum size of the bitmap (typically blocksize)
81 * Only possible return value other than '0' is -ENOMEM for failure to
82 * allocation mirror bitmap.
84 int ocfs2_resmap_init(struct ocfs2_super *osb,
85 struct ocfs2_reservation_map *resmap);
88 * ocfs2_resmap_restart() - "restart" a reservation bitmap
89 * @resmap: reservations bitmap
90 * @clen: Number of valid bits in the bitmap
91 * @disk_bitmap: the disk bitmap this resmap should refer to.
93 * Re-initialize the parameters of a reservation bitmap. This is
94 * useful for local alloc window slides.
96 * This function will call ocfs2_trunc_resv against all existing
97 * reservations. A future version will recalculate existing
98 * reservations based on the new bitmap.
100 void ocfs2_resmap_restart(struct ocfs2_reservation_map *resmap,
101 unsigned int clen, char *disk_bitmap);
104 * ocfs2_resmap_uninit() - uninitialize a reservation bitmap structure
105 * @resmap: the struct ocfs2_reservation_map to uninitialize
107 void ocfs2_resmap_uninit(struct ocfs2_reservation_map *resmap);
110 * ocfs2_resmap_resv_bits() - Return still-valid reservation bits
111 * @resmap: reservations bitmap
112 * @resv: reservation to base search from
113 * @cstart: start of proposed allocation
114 * @clen: length (in clusters) of proposed allocation
116 * Using the reservation data from resv, this function will compare
117 * resmap and resmap->m_disk_bitmap to determine what part (if any) of
118 * the reservation window is still clear to use. If resv is empty,
119 * this function will try to allocate a window for it.
121 * On success, zero is returned and the valid allocation area is set in cstart
124 * Returns -ENOSPC if reservations are disabled.
126 int ocfs2_resmap_resv_bits(struct ocfs2_reservation_map *resmap,
127 struct ocfs2_alloc_reservation *resv,
128 int *cstart, int *clen);
131 * ocfs2_resmap_claimed_bits() - Tell the reservation code that bits were used.
132 * @resmap: reservations bitmap
133 * @resv: optional reservation to recalulate based on new bitmap
134 * @cstart: start of allocation in clusters
135 * @clen: end of allocation in clusters.
137 * Tell the reservation code that bits were used to fulfill allocation in
138 * resmap. The bits don't have to have been part of any existing
139 * reservation. But we must always call this function when bits are claimed.
140 * Internally, the reservations code will use this information to mark the
141 * reservations bitmap. If resv is passed, it's next allocation window will be
142 * calculated. It also expects that 'cstart' is the same as we passed back
143 * from ocfs2_resmap_resv_bits().
145 void ocfs2_resmap_claimed_bits(struct ocfs2_reservation_map *resmap,
146 struct ocfs2_alloc_reservation *resv,
147 u32 cstart, u32 clen);
149 #endif /* OCFS2_RESERVATIONS_H */