1 /* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
6 * Allocation reservations function prototypes and structures.
8 * Copyright (C) 2010 Novell. All rights reserved.
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public
12 * License version 2 as published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
20 #ifndef OCFS2_RESERVATIONS_H
21 #define OCFS2_RESERVATIONS_H
23 #include <linux/rbtree.h>
25 #define OCFS2_DEFAULT_RESV_LEVEL 4
26 #define OCFS2_MAX_RESV_LEVEL 9
27 #define OCFS2_MIN_RESV_LEVEL 0
29 struct ocfs2_alloc_reservation
{
30 struct rb_node r_node
;
32 unsigned int r_start
; /* Begining of current window */
33 unsigned int r_len
; /* Length of the window */
35 unsigned int r_last_len
; /* Length of most recent alloc */
36 unsigned int r_last_start
; /* Start of most recent alloc */
37 struct list_head r_lru
; /* LRU list head */
42 #define OCFS2_RESV_FLAG_INUSE 0x01 /* Set when r_node is part of a btree */
43 #define OCFS2_RESV_FLAG_TMP 0x02 /* Temporary reservation, will be
44 * destroyed immedately after use */
45 #define OCFS2_RESV_FLAG_DIR 0x04 /* Reservation is for an unindexed
48 struct ocfs2_reservation_map
{
49 struct rb_root m_reservations
;
52 struct ocfs2_super
*m_osb
;
54 /* The following are not initialized to meaningful values until a disk
55 * bitmap is provided. */
56 u32 m_bitmap_len
; /* Number of valid
59 struct list_head m_lru
; /* LRU of reservations
64 void ocfs2_resv_init_once(struct ocfs2_alloc_reservation
*resv
);
66 #define OCFS2_RESV_TYPES (OCFS2_RESV_FLAG_TMP|OCFS2_RESV_FLAG_DIR)
67 void ocfs2_resv_set_type(struct ocfs2_alloc_reservation
*resv
,
71 * ocfs2_resv_discard() - truncate a reservation
73 * @resv: the reservation to truncate.
75 * After this function is called, the reservation will be empty, and
76 * unlinked from the rbtree.
78 void ocfs2_resv_discard(struct ocfs2_reservation_map
*resmap
,
79 struct ocfs2_alloc_reservation
*resv
);
83 * ocfs2_resmap_init() - Initialize fields of a reservations bitmap
84 * @resmap: struct ocfs2_reservation_map to initialize
85 * @obj: unused for now
86 * @ops: unused for now
87 * @max_bitmap_bytes: Maximum size of the bitmap (typically blocksize)
89 * Only possible return value other than '0' is -ENOMEM for failure to
90 * allocation mirror bitmap.
92 int ocfs2_resmap_init(struct ocfs2_super
*osb
,
93 struct ocfs2_reservation_map
*resmap
);
96 * ocfs2_resmap_restart() - "restart" a reservation bitmap
97 * @resmap: reservations bitmap
98 * @clen: Number of valid bits in the bitmap
99 * @disk_bitmap: the disk bitmap this resmap should refer to.
101 * Re-initialize the parameters of a reservation bitmap. This is
102 * useful for local alloc window slides.
104 * This function will call ocfs2_trunc_resv against all existing
105 * reservations. A future version will recalculate existing
106 * reservations based on the new bitmap.
108 void ocfs2_resmap_restart(struct ocfs2_reservation_map
*resmap
,
109 unsigned int clen
, char *disk_bitmap
);
112 * ocfs2_resmap_uninit() - uninitialize a reservation bitmap structure
113 * @resmap: the struct ocfs2_reservation_map to uninitialize
115 void ocfs2_resmap_uninit(struct ocfs2_reservation_map
*resmap
);
118 * ocfs2_resmap_resv_bits() - Return still-valid reservation bits
119 * @resmap: reservations bitmap
120 * @resv: reservation to base search from
121 * @cstart: start of proposed allocation
122 * @clen: length (in clusters) of proposed allocation
124 * Using the reservation data from resv, this function will compare
125 * resmap and resmap->m_disk_bitmap to determine what part (if any) of
126 * the reservation window is still clear to use. If resv is empty,
127 * this function will try to allocate a window for it.
129 * On success, zero is returned and the valid allocation area is set in cstart
132 * Returns -ENOSPC if reservations are disabled.
134 int ocfs2_resmap_resv_bits(struct ocfs2_reservation_map
*resmap
,
135 struct ocfs2_alloc_reservation
*resv
,
136 int *cstart
, int *clen
);
139 * ocfs2_resmap_claimed_bits() - Tell the reservation code that bits were used.
140 * @resmap: reservations bitmap
141 * @resv: optional reservation to recalulate based on new bitmap
142 * @cstart: start of allocation in clusters
143 * @clen: end of allocation in clusters.
145 * Tell the reservation code that bits were used to fulfill allocation in
146 * resmap. The bits don't have to have been part of any existing
147 * reservation. But we must always call this function when bits are claimed.
148 * Internally, the reservations code will use this information to mark the
149 * reservations bitmap. If resv is passed, it's next allocation window will be
152 void ocfs2_resmap_claimed_bits(struct ocfs2_reservation_map
*resmap
,
153 struct ocfs2_alloc_reservation
*resv
,
154 u32 cstart
, u32 clen
);
156 #endif /* OCFS2_RESERVATIONS_H */