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