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