/src/hdf5/src/H5HFsection.c
Line | Count | Source |
1 | | /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
2 | | * Copyright by The HDF Group. * |
3 | | * All rights reserved. * |
4 | | * * |
5 | | * This file is part of HDF5. The full HDF5 copyright notice, including * |
6 | | * terms governing use, modification, and redistribution, is contained in * |
7 | | * the LICENSE file, which can be found at the root of the source code * |
8 | | * distribution tree, or in https://www.hdfgroup.org/licenses. * |
9 | | * If you do not have access to either file, you may request a copy from * |
10 | | * help@hdfgroup.org. * |
11 | | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
12 | | |
13 | | /* |
14 | | * Purpose: Free space section routines for fractal heaps |
15 | | */ |
16 | | |
17 | | /****************/ |
18 | | /* Module Setup */ |
19 | | /****************/ |
20 | | |
21 | | #include "H5HFmodule.h" /* This source code file is part of the H5HF module */ |
22 | | |
23 | | /***********/ |
24 | | /* Headers */ |
25 | | /***********/ |
26 | | #include "H5private.h" /* Generic Functions */ |
27 | | #include "H5Eprivate.h" /* Error handling */ |
28 | | #include "H5FLprivate.h" /* Free Lists */ |
29 | | #include "H5HFpkg.h" /* Fractal heaps */ |
30 | | #include "H5MMprivate.h" /* Memory management */ |
31 | | |
32 | | /****************/ |
33 | | /* Local Macros */ |
34 | | /****************/ |
35 | | |
36 | | /* Size of serialized indirect section information */ |
37 | | #define H5HF_SECT_INDIRECT_SERIAL_SIZE(h) \ |
38 | 0 | ((unsigned)(h)->heap_off_size /* Indirect block's offset in "heap space" */ \ |
39 | 0 | + (unsigned)2 /* Row */ \ |
40 | 0 | + (unsigned)2 /* Column */ \ |
41 | 0 | + (unsigned)2 /* # of entries */ \ |
42 | 0 | ) |
43 | | |
44 | | /******************/ |
45 | | /* Local Typedefs */ |
46 | | /******************/ |
47 | | |
48 | | /* Typedef for "class private" information for sections */ |
49 | | typedef struct { |
50 | | H5HF_hdr_t *hdr; /* Pointer to fractal heap header */ |
51 | | } H5HF_sect_private_t; |
52 | | |
53 | | /********************/ |
54 | | /* Package Typedefs */ |
55 | | /********************/ |
56 | | |
57 | | /********************/ |
58 | | /* Local Prototypes */ |
59 | | /********************/ |
60 | | |
61 | | /* Shared routines */ |
62 | | static herr_t H5FS__sect_init_cls(H5FS_section_class_t *cls, H5HF_hdr_t *hdr); |
63 | | static herr_t H5FS__sect_term_cls(H5FS_section_class_t *cls); |
64 | | static H5HF_free_section_t *H5FS__sect_node_new(unsigned sect_type, haddr_t sect_addr, hsize_t sect_size, |
65 | | H5FS_section_state_t state); |
66 | | static herr_t H5HF__sect_node_free(H5HF_free_section_t *sect, H5HF_indirect_t *parent); |
67 | | |
68 | | /* 'single' section routines */ |
69 | | static herr_t H5HF__sect_single_locate_parent(H5HF_hdr_t *hdr, bool refresh, H5HF_free_section_t *sect); |
70 | | static herr_t H5HF__sect_single_full_dblock(H5HF_hdr_t *hdr, H5HF_free_section_t *sect); |
71 | | |
72 | | /* 'single' section callbacks */ |
73 | | static herr_t H5HF__sect_single_add(H5FS_section_info_t **sect, unsigned *flags, void *udata); |
74 | | static H5FS_section_info_t *H5HF__sect_single_deserialize(const H5FS_section_class_t *cls, const uint8_t *buf, |
75 | | haddr_t sect_addr, hsize_t sect_size, |
76 | | unsigned *des_flags); |
77 | | static htri_t H5HF__sect_single_can_merge(const H5FS_section_info_t *sect1, const H5FS_section_info_t *sect2, |
78 | | void *udata); |
79 | | static herr_t H5HF__sect_single_merge(H5FS_section_info_t **sect1, H5FS_section_info_t *sect2, void *udata); |
80 | | static htri_t H5HF__sect_single_can_shrink(const H5FS_section_info_t *sect, void *udata); |
81 | | static herr_t H5HF__sect_single_shrink(H5FS_section_info_t **_sect, void *udata); |
82 | | static herr_t H5HF__sect_single_valid(const H5FS_section_class_t *cls, const H5FS_section_info_t *sect); |
83 | | |
84 | | /* 'row' section routines */ |
85 | | static H5HF_free_section_t *H5HF__sect_row_create(haddr_t sect_off, hsize_t sect_size, bool is_first, |
86 | | unsigned row, unsigned col, unsigned nentries, |
87 | | H5HF_free_section_t *under_sect); |
88 | | static herr_t H5HF__sect_row_first(H5HF_hdr_t *hdr, H5HF_free_section_t *sect); |
89 | | static herr_t H5HF__sect_row_parent_removed(H5HF_free_section_t *sect); |
90 | | static herr_t H5HF__sect_row_from_single(H5HF_hdr_t *hdr, H5HF_free_section_t *sect, H5HF_direct_t *dblock); |
91 | | static herr_t H5HF__sect_row_free_real(H5HF_free_section_t *sect); |
92 | | |
93 | | /* 'row' section callbacks */ |
94 | | static herr_t H5HF__sect_row_init_cls(H5FS_section_class_t *cls, void *udata); |
95 | | static herr_t H5HF__sect_row_term_cls(H5FS_section_class_t *cls); |
96 | | static herr_t H5HF__sect_row_serialize(const H5FS_section_class_t *cls, const H5FS_section_info_t *sect, |
97 | | uint8_t *buf); |
98 | | static H5FS_section_info_t *H5HF__sect_row_deserialize(const H5FS_section_class_t *cls, const uint8_t *buf, |
99 | | haddr_t sect_addr, hsize_t sect_size, |
100 | | unsigned *des_flags); |
101 | | static htri_t H5HF__sect_row_can_merge(const H5FS_section_info_t *sect1, const H5FS_section_info_t *sect2, |
102 | | void *udata); |
103 | | static herr_t H5HF__sect_row_merge(H5FS_section_info_t **sect1, H5FS_section_info_t *sect2, void *udata); |
104 | | static htri_t H5HF__sect_row_can_shrink(const H5FS_section_info_t *sect, void *udata); |
105 | | static herr_t H5HF__sect_row_shrink(H5FS_section_info_t **sect, void *udata); |
106 | | static herr_t H5HF__sect_row_free(H5FS_section_info_t *sect); |
107 | | static herr_t H5HF__sect_row_valid(const H5FS_section_class_t *cls, const H5FS_section_info_t *sect); |
108 | | static herr_t H5HF__sect_row_debug(const H5FS_section_info_t *sect, FILE *stream, int indent, int fwidth); |
109 | | |
110 | | /* 'indirect' section routines */ |
111 | | static H5HF_free_section_t *H5HF__sect_indirect_new(H5HF_hdr_t *hdr, haddr_t sect_off, hsize_t sect_size, |
112 | | H5HF_indirect_t *iblock, hsize_t iblock_off, unsigned row, |
113 | | unsigned col, unsigned nentries); |
114 | | static herr_t H5HF__sect_indirect_init_rows(H5HF_hdr_t *hdr, H5HF_free_section_t *sect, bool first_child, |
115 | | H5HF_free_section_t **first_row_sect, unsigned space_flags, |
116 | | unsigned start_row, unsigned start_col, unsigned end_row, |
117 | | unsigned end_col); |
118 | | static H5HF_free_section_t *H5HF__sect_indirect_for_row(H5HF_hdr_t *hdr, H5HF_indirect_t *iblock, |
119 | | H5HF_free_section_t *row_sect); |
120 | | static herr_t H5HF__sect_indirect_decr(H5HF_free_section_t *sect); |
121 | | static herr_t H5HF__sect_indirect_revive_row(H5HF_hdr_t *hdr, H5HF_free_section_t *sect); |
122 | | static herr_t H5HF__sect_indirect_revive(H5HF_hdr_t *hdr, H5HF_free_section_t *sect, |
123 | | H5HF_indirect_t *sect_iblock); |
124 | | static herr_t H5HF__sect_indirect_reduce_row(H5HF_hdr_t *hdr, H5HF_free_section_t *row_sect, |
125 | | bool *alloc_from_start); |
126 | | static herr_t H5HF__sect_indirect_reduce(H5HF_hdr_t *hdr, H5HF_free_section_t *sect, unsigned child_entry); |
127 | | static herr_t H5HF__sect_indirect_first(H5HF_hdr_t *hdr, H5HF_free_section_t *sect); |
128 | | static bool H5HF__sect_indirect_is_first(H5HF_free_section_t *sect); |
129 | | static H5HF_indirect_t *H5HF__sect_indirect_get_iblock(H5HF_free_section_t *sect); |
130 | | static hsize_t H5HF__sect_indirect_iblock_off(const H5HF_free_section_t *sect); |
131 | | static H5HF_free_section_t *H5HF__sect_indirect_top(H5HF_free_section_t *sect); |
132 | | static herr_t H5HF__sect_indirect_merge_row(H5HF_hdr_t *hdr, H5HF_free_section_t *sect1, |
133 | | H5HF_free_section_t *sect2); |
134 | | static herr_t H5HF__sect_indirect_build_parent(H5HF_hdr_t *hdr, H5HF_free_section_t *sect); |
135 | | static herr_t H5HF__sect_indirect_shrink(H5HF_hdr_t *hdr, H5HF_free_section_t *sect); |
136 | | static herr_t H5HF__sect_indirect_serialize(H5HF_hdr_t *hdr, const H5HF_free_section_t *sect, uint8_t *buf); |
137 | | static H5FS_section_info_t *H5HF__sect_indirect_deserialize(H5HF_hdr_t *hdr, const uint8_t *buf, |
138 | | haddr_t sect_addr, hsize_t sect_size, |
139 | | unsigned *des_flags); |
140 | | static herr_t H5HF__sect_indirect_free(H5HF_free_section_t *sect); |
141 | | static herr_t H5HF__sect_indirect_valid(const H5HF_hdr_t *hdr, const H5HF_free_section_t *sect); |
142 | | static herr_t H5HF__sect_indirect_debug(const H5HF_free_section_t *sect, FILE *stream, int indent, |
143 | | int fwidth); |
144 | | |
145 | | /* 'indirect' section callbacks */ |
146 | | static herr_t H5HF__sect_indirect_init_cls(H5FS_section_class_t *cls, void *udata); |
147 | | static herr_t H5HF__sect_indirect_term_cls(H5FS_section_class_t *cls); |
148 | | |
149 | | /*********************/ |
150 | | /* Package Variables */ |
151 | | /*********************/ |
152 | | |
153 | | /* Class info for "single" free space sections */ |
154 | | H5FS_section_class_t H5HF_FSPACE_SECT_CLS_SINGLE[1] = {{ |
155 | | /* Class variables */ |
156 | | H5HF_FSPACE_SECT_SINGLE, /* Section type */ |
157 | | 0, /* Extra serialized size */ |
158 | | H5FS_CLS_MERGE_SYM, /* Class flags */ |
159 | | NULL, /* Class private info */ |
160 | | |
161 | | /* Class methods */ |
162 | | NULL, /* Initialize section class */ |
163 | | NULL, /* Terminate section class */ |
164 | | |
165 | | /* Object methods */ |
166 | | H5HF__sect_single_add, /* Add section */ |
167 | | NULL, /* Serialize section */ |
168 | | H5HF__sect_single_deserialize, /* Deserialize section */ |
169 | | H5HF__sect_single_can_merge, /* Can sections merge? */ |
170 | | H5HF__sect_single_merge, /* Merge sections */ |
171 | | H5HF__sect_single_can_shrink, /* Can section shrink container?*/ |
172 | | H5HF__sect_single_shrink, /* Shrink container w/section */ |
173 | | H5HF__sect_single_free, /* Free section */ |
174 | | H5HF__sect_single_valid, /* Check validity of section */ |
175 | | NULL, /* Split section node for alignment */ |
176 | | NULL, /* Dump debugging for section */ |
177 | | }}; |
178 | | |
179 | | /* Class info for "first row" free space sections */ |
180 | | /* (Same as "normal" row sections, except they also act as a proxy for the |
181 | | * underlying indirect section |
182 | | */ |
183 | | H5FS_section_class_t H5HF_FSPACE_SECT_CLS_FIRST_ROW[1] = {{ |
184 | | /* Class variables */ |
185 | | H5HF_FSPACE_SECT_FIRST_ROW, /* Section type */ |
186 | | 0, /* Extra serialized size */ |
187 | | H5FS_CLS_MERGE_SYM, /* Class flags */ |
188 | | NULL, /* Class private info */ |
189 | | |
190 | | /* Class methods */ |
191 | | H5HF__sect_row_init_cls, /* Initialize section class */ |
192 | | H5HF__sect_row_term_cls, /* Terminate section class */ |
193 | | |
194 | | /* Object methods */ |
195 | | NULL, /* Add section */ |
196 | | H5HF__sect_row_serialize, /* Serialize section */ |
197 | | H5HF__sect_row_deserialize, /* Deserialize section */ |
198 | | H5HF__sect_row_can_merge, /* Can sections merge? */ |
199 | | H5HF__sect_row_merge, /* Merge sections */ |
200 | | H5HF__sect_row_can_shrink, /* Can section shrink container?*/ |
201 | | H5HF__sect_row_shrink, /* Shrink container w/section */ |
202 | | H5HF__sect_row_free, /* Free section */ |
203 | | H5HF__sect_row_valid, /* Check validity of section */ |
204 | | NULL, /* Split section node for alignment */ |
205 | | H5HF__sect_row_debug, /* Dump debugging for section */ |
206 | | }}; |
207 | | |
208 | | /* Class info for "normal row" free space sections */ |
209 | | H5FS_section_class_t H5HF_FSPACE_SECT_CLS_NORMAL_ROW[1] = {{ |
210 | | /* Class variables */ |
211 | | H5HF_FSPACE_SECT_NORMAL_ROW, /* Section type */ |
212 | | 0, /* Extra serialized size */ |
213 | | H5FS_CLS_MERGE_SYM | H5FS_CLS_SEPAR_OBJ | H5FS_CLS_GHOST_OBJ, /* Class flags */ |
214 | | NULL, /* Class private info */ |
215 | | |
216 | | /* Class methods */ |
217 | | H5HF__sect_row_init_cls, /* Initialize section class */ |
218 | | H5HF__sect_row_term_cls, /* Terminate section class */ |
219 | | |
220 | | /* Object methods */ |
221 | | NULL, /* Add section */ |
222 | | NULL, /* Serialize section */ |
223 | | NULL, /* Deserialize section */ |
224 | | NULL, /* Can sections merge? */ |
225 | | NULL, /* Merge sections */ |
226 | | NULL, /* Can section shrink container?*/ |
227 | | NULL, /* Shrink container w/section */ |
228 | | H5HF__sect_row_free, /* Free section */ |
229 | | H5HF__sect_row_valid, /* Check validity of section */ |
230 | | NULL, /* Split section node for alignment */ |
231 | | H5HF__sect_row_debug, /* Dump debugging for section */ |
232 | | }}; |
233 | | |
234 | | /* Class info for "indirect" free space sections */ |
235 | | /* (No object callbacks necessary - objects of this class should never be in |
236 | | * section manager) |
237 | | */ |
238 | | H5FS_section_class_t H5HF_FSPACE_SECT_CLS_INDIRECT[1] = {{ |
239 | | /* Class variables */ |
240 | | H5HF_FSPACE_SECT_INDIRECT, /* Section type */ |
241 | | 0, /* Extra serialized size */ |
242 | | H5FS_CLS_MERGE_SYM | H5FS_CLS_GHOST_OBJ, /* Class flags */ |
243 | | NULL, /* Class private info */ |
244 | | |
245 | | /* Class methods */ |
246 | | H5HF__sect_indirect_init_cls, /* Initialize section class */ |
247 | | H5HF__sect_indirect_term_cls, /* Terminate section class */ |
248 | | |
249 | | /* Object methods */ |
250 | | NULL, /* Add section */ |
251 | | NULL, /* Serialize section */ |
252 | | NULL, /* Deserialize section */ |
253 | | NULL, /* Can sections merge? */ |
254 | | NULL, /* Merge sections */ |
255 | | NULL, /* Can section shrink container?*/ |
256 | | NULL, /* Shrink container w/section */ |
257 | | NULL, /* Free section */ |
258 | | NULL, /* Check validity of section */ |
259 | | NULL, /* Split section node for alignment */ |
260 | | NULL, /* Dump debugging for section */ |
261 | | }}; |
262 | | |
263 | | /* Declare a free list to manage the H5HF_free_section_t struct */ |
264 | | H5FL_DEFINE_STATIC(H5HF_free_section_t); |
265 | | |
266 | | /*****************************/ |
267 | | /* Library Private Variables */ |
268 | | /*****************************/ |
269 | | |
270 | | /*******************/ |
271 | | /* Local Variables */ |
272 | | /*******************/ |
273 | | |
274 | | /*------------------------------------------------------------------------- |
275 | | * Function: H5FS__sect_init_cls |
276 | | * |
277 | | * Purpose: Initialize the common class structure |
278 | | * |
279 | | * Return: Success: non-negative |
280 | | * Failure: negative |
281 | | * |
282 | | *------------------------------------------------------------------------- |
283 | | */ |
284 | | static herr_t |
285 | | H5FS__sect_init_cls(H5FS_section_class_t *cls, H5HF_hdr_t *hdr) |
286 | 0 | { |
287 | 0 | H5HF_sect_private_t *cls_prvt; /* Pointer to class private info */ |
288 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
289 | |
|
290 | 0 | FUNC_ENTER_PACKAGE |
291 | | |
292 | | /* Check arguments. */ |
293 | 0 | assert(cls); |
294 | 0 | assert(!cls->cls_private); |
295 | | |
296 | | /* Allocate & initialize the class-private (i.e. private shared) information |
297 | | * for this type of section |
298 | | */ |
299 | 0 | if (NULL == (cls_prvt = (H5HF_sect_private_t *)H5MM_malloc(sizeof(H5HF_sect_private_t)))) |
300 | 0 | HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL, "memory allocation failed"); |
301 | 0 | cls_prvt->hdr = hdr; |
302 | 0 | cls->cls_private = cls_prvt; |
303 | | |
304 | | /* Increment reference count on heap header */ |
305 | 0 | if (H5HF__hdr_incr(hdr) < 0) |
306 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTINC, FAIL, "can't increment reference count on shared heap header"); |
307 | | |
308 | 0 | done: |
309 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
310 | 0 | } /* H5FS__sect_init_cls() */ |
311 | | |
312 | | /*------------------------------------------------------------------------- |
313 | | * Function: H5FS__sect_term_cls |
314 | | * |
315 | | * Purpose: Terminate the common class structure |
316 | | * |
317 | | * Return: Success: non-negative |
318 | | * Failure: negative |
319 | | * |
320 | | *------------------------------------------------------------------------- |
321 | | */ |
322 | | static herr_t |
323 | | H5FS__sect_term_cls(H5FS_section_class_t *cls) |
324 | 0 | { |
325 | 0 | H5HF_sect_private_t *cls_prvt; /* Pointer to class private info */ |
326 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
327 | |
|
328 | 0 | FUNC_ENTER_PACKAGE |
329 | | |
330 | | /* Check arguments. */ |
331 | 0 | assert(cls); |
332 | | |
333 | | /* Get pointer to class private info */ |
334 | 0 | cls_prvt = (H5HF_sect_private_t *)cls->cls_private; |
335 | | |
336 | | /* Decrement reference count on heap header */ |
337 | 0 | if (H5HF__hdr_decr(cls_prvt->hdr) < 0) |
338 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTDEC, FAIL, "can't decrement reference count on shared heap header"); |
339 | | |
340 | | /* Free the class private information */ |
341 | 0 | cls->cls_private = H5MM_xfree(cls_prvt); |
342 | |
|
343 | 0 | done: |
344 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
345 | 0 | } /* H5FS__sect_term_cls() */ |
346 | | |
347 | | /*------------------------------------------------------------------------- |
348 | | * Function: H5FS__sect_node_new |
349 | | * |
350 | | * Purpose: Allocate a free space section node of a particular type |
351 | | * |
352 | | * Return: Success: non-negative |
353 | | * |
354 | | * Failure: negative |
355 | | * |
356 | | *------------------------------------------------------------------------- |
357 | | */ |
358 | | static H5HF_free_section_t * |
359 | | H5FS__sect_node_new(unsigned sect_type, haddr_t sect_addr, hsize_t sect_size, H5FS_section_state_t sect_state) |
360 | 0 | { |
361 | 0 | H5HF_free_section_t *new_sect; /* New section */ |
362 | 0 | H5HF_free_section_t *ret_value = NULL; /* Return value */ |
363 | |
|
364 | 0 | FUNC_ENTER_PACKAGE |
365 | | |
366 | | /* Check arguments. */ |
367 | 0 | assert(H5_addr_defined(sect_addr)); |
368 | | |
369 | | /* Create free list section node */ |
370 | 0 | if (NULL == (new_sect = H5FL_MALLOC(H5HF_free_section_t))) |
371 | 0 | HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, |
372 | 0 | "memory allocation failed for direct block free list section"); |
373 | | |
374 | | /* Set the information passed in */ |
375 | 0 | new_sect->sect_info.addr = sect_addr; |
376 | 0 | new_sect->sect_info.size = sect_size; |
377 | | |
378 | | /* Set the section's class & state */ |
379 | 0 | new_sect->sect_info.type = sect_type; |
380 | 0 | new_sect->sect_info.state = sect_state; |
381 | | |
382 | | /* Set return value */ |
383 | 0 | ret_value = new_sect; |
384 | |
|
385 | 0 | done: |
386 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
387 | 0 | } /* H5FS__sect_node_new() */ |
388 | | |
389 | | /*------------------------------------------------------------------------- |
390 | | * Function: H5HF__sect_node_free |
391 | | * |
392 | | * Purpose: Free a section node |
393 | | * |
394 | | * Return: Success: non-negative |
395 | | * |
396 | | * Failure: negative |
397 | | * |
398 | | *------------------------------------------------------------------------- |
399 | | */ |
400 | | static herr_t |
401 | | H5HF__sect_node_free(H5HF_free_section_t *sect, H5HF_indirect_t *iblock) |
402 | 0 | { |
403 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
404 | |
|
405 | 0 | FUNC_ENTER_PACKAGE |
406 | |
|
407 | 0 | assert(sect); |
408 | | |
409 | | /* Release indirect block, if there was one */ |
410 | 0 | if (iblock) |
411 | 0 | if (H5HF__iblock_decr(iblock) < 0) |
412 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTDEC, FAIL, |
413 | 0 | "can't decrement reference count on section's indirect block"); |
414 | | |
415 | | /* Release the section */ |
416 | 0 | sect = H5FL_FREE(H5HF_free_section_t, sect); |
417 | |
|
418 | 0 | done: |
419 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
420 | 0 | } /* H5HF__sect_node_free() */ |
421 | | |
422 | | /*------------------------------------------------------------------------- |
423 | | * Function: H5HF__sect_single_new |
424 | | * |
425 | | * Purpose: Create a new 'single' section and return it to the caller |
426 | | * |
427 | | * Return: Pointer to new section on success/NULL on failure |
428 | | * |
429 | | *------------------------------------------------------------------------- |
430 | | */ |
431 | | H5HF_free_section_t * |
432 | | H5HF__sect_single_new(hsize_t sect_off, size_t sect_size, H5HF_indirect_t *parent, unsigned par_entry) |
433 | 0 | { |
434 | 0 | H5HF_free_section_t *sect = NULL; /* 'Single' free space section to add */ |
435 | 0 | H5HF_free_section_t *ret_value = NULL; /* Return value */ |
436 | |
|
437 | 0 | FUNC_ENTER_PACKAGE |
438 | | |
439 | | /* |
440 | | * Check arguments. |
441 | | */ |
442 | 0 | assert(sect_size); |
443 | | |
444 | | /* Create free space section node */ |
445 | 0 | if (NULL == |
446 | 0 | (sect = H5FS__sect_node_new(H5HF_FSPACE_SECT_SINGLE, sect_off, (hsize_t)sect_size, H5FS_SECT_LIVE))) |
447 | 0 | HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for single section"); |
448 | | |
449 | | /* Set the 'single' specific fields */ |
450 | 0 | sect->u.single.parent = parent; |
451 | 0 | if (sect->u.single.parent) { |
452 | 0 | if (H5HF__iblock_incr(sect->u.single.parent) < 0) |
453 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTINC, NULL, |
454 | 0 | "can't increment reference count on shared indirect block"); |
455 | 0 | } /* end if */ |
456 | 0 | sect->u.single.par_entry = par_entry; |
457 | | |
458 | | /* Set return value */ |
459 | 0 | ret_value = sect; |
460 | |
|
461 | 0 | done: |
462 | 0 | if (!ret_value && sect) { |
463 | | /* Release the section */ |
464 | 0 | sect = H5FL_FREE(H5HF_free_section_t, sect); |
465 | 0 | } /* end if */ |
466 | |
|
467 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
468 | 0 | } /* end H5HF__sect_single_new() */ |
469 | | |
470 | | /*------------------------------------------------------------------------- |
471 | | * Function: H5HF__sect_single_locate_parent |
472 | | * |
473 | | * Purpose: Locate the parent indirect block for a single section |
474 | | * |
475 | | * Return: Non-negative on success/Negative on failure |
476 | | * |
477 | | *------------------------------------------------------------------------- |
478 | | */ |
479 | | static herr_t |
480 | | H5HF__sect_single_locate_parent(H5HF_hdr_t *hdr, bool refresh, H5HF_free_section_t *sect) |
481 | 0 | { |
482 | 0 | H5HF_indirect_t *sec_iblock; /* Pointer to section indirect block */ |
483 | 0 | unsigned sec_entry; /* Entry within section indirect block */ |
484 | 0 | bool did_protect; /* Whether we protected the indirect block or not */ |
485 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
486 | |
|
487 | 0 | FUNC_ENTER_PACKAGE |
488 | | |
489 | | /* |
490 | | * Check arguments. |
491 | | */ |
492 | 0 | assert(hdr); |
493 | 0 | assert(hdr->man_dtable.curr_root_rows > 0); |
494 | 0 | assert(sect); |
495 | | |
496 | | /* Look up indirect block containing direct blocks for range */ |
497 | 0 | if (H5HF__man_dblock_locate(hdr, sect->sect_info.addr, &sec_iblock, &sec_entry, &did_protect, |
498 | 0 | H5AC__READ_ONLY_FLAG) < 0) |
499 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTCOMPUTE, FAIL, "can't compute row & column of section"); |
500 | | |
501 | | /* Increment reference count on indirect block that free section is in */ |
502 | 0 | if (H5HF__iblock_incr(sec_iblock) < 0) |
503 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTINC, FAIL, "can't increment reference count on shared indirect block"); |
504 | | |
505 | | /* Check for refreshing existing parent information */ |
506 | 0 | if (refresh) { |
507 | 0 | if (sect->u.single.parent) { |
508 | | /* Release hold on previous parent indirect block */ |
509 | 0 | if (H5HF__iblock_decr(sect->u.single.parent) < 0) |
510 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTDEC, FAIL, |
511 | 0 | "can't decrement reference count on section's indirect block"); |
512 | 0 | } /* end if */ |
513 | 0 | } /* end if */ |
514 | | |
515 | | /* Set the information for the section */ |
516 | 0 | sect->u.single.parent = sec_iblock; |
517 | 0 | sect->u.single.par_entry = sec_entry; |
518 | | |
519 | | /* Unlock indirect block */ |
520 | 0 | if (H5HF__man_iblock_unprotect(sec_iblock, H5AC__NO_FLAGS_SET, did_protect) < 0) |
521 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTUNPROTECT, FAIL, "unable to release fractal heap indirect block"); |
522 | 0 | sec_iblock = NULL; |
523 | |
|
524 | 0 | done: |
525 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
526 | 0 | } /* end H5HF__sect_single_locate_parent() */ |
527 | | |
528 | | /*------------------------------------------------------------------------- |
529 | | * Function: H5HF__sect_single_revive |
530 | | * |
531 | | * Purpose: Update the memory information for a 'single' free section |
532 | | * |
533 | | * Return: SUCCEED/FAIL |
534 | | * |
535 | | *------------------------------------------------------------------------- |
536 | | */ |
537 | | herr_t |
538 | | H5HF__sect_single_revive(H5HF_hdr_t *hdr, H5HF_free_section_t *sect) |
539 | 0 | { |
540 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
541 | |
|
542 | 0 | FUNC_ENTER_PACKAGE |
543 | | |
544 | | /* |
545 | | * Check arguments. |
546 | | */ |
547 | 0 | assert(hdr); |
548 | 0 | assert(sect); |
549 | 0 | assert(sect->sect_info.state == H5FS_SECT_SERIALIZED); |
550 | | |
551 | | /* Check for root direct block */ |
552 | 0 | if (hdr->man_dtable.curr_root_rows == 0) { |
553 | | /* Set the information for the section */ |
554 | 0 | assert(H5_addr_defined(hdr->man_dtable.table_addr)); |
555 | 0 | sect->u.single.parent = NULL; |
556 | 0 | sect->u.single.par_entry = 0; |
557 | 0 | } /* end if */ |
558 | 0 | else { |
559 | | /* Look up indirect block information for section */ |
560 | 0 | if (H5HF__sect_single_locate_parent(hdr, false, sect) < 0) |
561 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTGET, FAIL, "can't get section's parent info"); |
562 | 0 | } /* end else */ |
563 | | |
564 | | /* Section is "live" now */ |
565 | 0 | sect->sect_info.state = H5FS_SECT_LIVE; |
566 | |
|
567 | 0 | done: |
568 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
569 | 0 | } /* end H5HF__sect_single_revive() */ |
570 | | |
571 | | /*------------------------------------------------------------------------- |
572 | | * Function: H5HF__sect_single_dblock_info |
573 | | * |
574 | | * Purpose: Retrieve the direct block information for a single section |
575 | | * |
576 | | * Return: SUCCEED/FAIL |
577 | | * |
578 | | *------------------------------------------------------------------------- |
579 | | */ |
580 | | herr_t |
581 | | H5HF__sect_single_dblock_info(H5HF_hdr_t *hdr, const H5HF_free_section_t *sect, haddr_t *dblock_addr, |
582 | | size_t *dblock_size) |
583 | 0 | { |
584 | 0 | FUNC_ENTER_PACKAGE_NOERR |
585 | | |
586 | | /* |
587 | | * Check arguments. |
588 | | */ |
589 | 0 | assert(hdr); |
590 | 0 | assert(sect); |
591 | 0 | assert(sect->sect_info.type == H5HF_FSPACE_SECT_SINGLE); |
592 | 0 | assert(sect->sect_info.state == H5FS_SECT_LIVE); |
593 | 0 | assert(dblock_addr); |
594 | 0 | assert(dblock_size); |
595 | | |
596 | | /* Check for root direct block */ |
597 | 0 | if (hdr->man_dtable.curr_root_rows == 0) { |
598 | | /* Retrieve direct block info from heap header */ |
599 | 0 | assert(H5_addr_defined(hdr->man_dtable.table_addr)); |
600 | 0 | *dblock_addr = hdr->man_dtable.table_addr; |
601 | 0 | *dblock_size = hdr->man_dtable.cparam.start_block_size; |
602 | 0 | } /* end if */ |
603 | 0 | else { |
604 | | /* Retrieve direct block info from parent indirect block */ |
605 | 0 | *dblock_addr = sect->u.single.parent->ents[sect->u.single.par_entry].addr; |
606 | 0 | *dblock_size = |
607 | 0 | hdr->man_dtable.row_block_size[sect->u.single.par_entry / hdr->man_dtable.cparam.width]; |
608 | 0 | } /* end else */ |
609 | |
|
610 | 0 | FUNC_LEAVE_NOAPI(SUCCEED) |
611 | 0 | } /* end H5HF__sect_single_dblock_info() */ |
612 | | |
613 | | /*------------------------------------------------------------------------- |
614 | | * Function: H5HF__sect_single_reduce |
615 | | * |
616 | | * Purpose: Reduce the size of a single section (possibly freeing it) |
617 | | * and re-add it back to the free space manager for the heap |
618 | | * (if it hasn't been freed) |
619 | | * |
620 | | * Return: Non-negative on success/Negative on failure |
621 | | * |
622 | | *------------------------------------------------------------------------- |
623 | | */ |
624 | | herr_t |
625 | | H5HF__sect_single_reduce(H5HF_hdr_t *hdr, H5HF_free_section_t *sect, size_t amt) |
626 | 0 | { |
627 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
628 | |
|
629 | 0 | FUNC_ENTER_PACKAGE |
630 | | |
631 | | /* |
632 | | * Check arguments. |
633 | | */ |
634 | 0 | assert(hdr); |
635 | 0 | assert(sect); |
636 | 0 | assert(sect->sect_info.type == H5HF_FSPACE_SECT_SINGLE); |
637 | 0 | assert(sect->sect_info.state == H5FS_SECT_LIVE); |
638 | | |
639 | | /* Check for eliminating the section */ |
640 | 0 | if (sect->sect_info.size == amt) { |
641 | | /* Free single section */ |
642 | 0 | if (H5HF__sect_single_free((H5FS_section_info_t *)sect) < 0) |
643 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTRELEASE, FAIL, "can't free single section node"); |
644 | 0 | } /* end if */ |
645 | 0 | else { |
646 | | /* Adjust information for section */ |
647 | 0 | sect->sect_info.addr += amt; |
648 | 0 | sect->sect_info.size -= amt; |
649 | | |
650 | | /* Re-insert section node into heap's free space */ |
651 | 0 | if (H5HF__space_add(hdr, sect, 0) < 0) |
652 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "can't re-add single section to free space manager"); |
653 | 0 | } /* end else */ |
654 | | |
655 | 0 | done: |
656 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
657 | 0 | } /* end H5HF__sect_single_reduce() */ |
658 | | |
659 | | /*------------------------------------------------------------------------- |
660 | | * Function: H5HF__sect_single_full_dblock |
661 | | * |
662 | | * Purpose: Checks if a single section covers the entire direct block |
663 | | * that it resides in, and converts it to a row section if so |
664 | | * |
665 | | * Note: Does not convert a single section to a row section if the |
666 | | * single section is for a root direct block |
667 | | * |
668 | | * Return: Success: non-negative |
669 | | * Failure: negative |
670 | | * |
671 | | *------------------------------------------------------------------------- |
672 | | */ |
673 | | static herr_t |
674 | | H5HF__sect_single_full_dblock(H5HF_hdr_t *hdr, H5HF_free_section_t *sect) |
675 | 0 | { |
676 | 0 | haddr_t dblock_addr = HADDR_UNDEF; /* Section's direct block's address */ |
677 | 0 | size_t dblock_size = SIZE_MAX; /* Section's direct block's size */ |
678 | 0 | size_t dblock_overhead; /* Direct block's overhead */ |
679 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
680 | |
|
681 | 0 | FUNC_ENTER_PACKAGE |
682 | | |
683 | | /* Check arguments. */ |
684 | 0 | assert(sect); |
685 | 0 | assert(sect->sect_info.state == H5FS_SECT_LIVE); |
686 | 0 | assert(hdr); |
687 | | |
688 | | /* Retrieve direct block address from section */ |
689 | 0 | if (H5HF__sect_single_dblock_info(hdr, sect, &dblock_addr, &dblock_size) < 0) |
690 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTGET, FAIL, "can't retrieve direct block information"); |
691 | 0 | if (!H5_addr_defined(dblock_addr)) |
692 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTGET, FAIL, "can't retrieve data block address"); |
693 | 0 | if (SIZE_MAX == dblock_size) |
694 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTGET, FAIL, "can't retrieve data block size"); |
695 | | |
696 | | /* Check for section occupying entire direct block */ |
697 | | /* (and not the root direct block) */ |
698 | 0 | dblock_overhead = H5HF_MAN_ABS_DIRECT_OVERHEAD(hdr); |
699 | 0 | if ((dblock_size - dblock_overhead) == sect->sect_info.size && hdr->man_dtable.curr_root_rows > 0) { |
700 | 0 | H5HF_direct_t *dblock; /* Pointer to direct block for section */ |
701 | 0 | bool parent_removed; /* Whether the direct block parent was removed from the file */ |
702 | |
|
703 | 0 | if (NULL == (dblock = H5HF__man_dblock_protect(hdr, dblock_addr, dblock_size, sect->u.single.parent, |
704 | 0 | sect->u.single.par_entry, H5AC__NO_FLAGS_SET))) |
705 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTPROTECT, FAIL, "unable to load fractal heap direct block"); |
706 | 0 | assert(H5_addr_eq(dblock->block_off + dblock_overhead, sect->sect_info.addr)); |
707 | | |
708 | | /* Convert 'single' section into 'row' section */ |
709 | 0 | if (H5HF__sect_row_from_single(hdr, sect, dblock) < 0) |
710 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTCONVERT, FAIL, "can't convert single section into row section"); |
711 | | |
712 | | /* Destroy direct block */ |
713 | 0 | if (H5HF__man_dblock_destroy(hdr, dblock, dblock_addr, &parent_removed) < 0) |
714 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTRELEASE, FAIL, "can't release direct block"); |
715 | 0 | dblock = NULL; |
716 | | |
717 | | /* If the parent for this direct block was removed and the indirect |
718 | | * section is still "live", switch it to the "serialized" state. |
719 | | */ |
720 | 0 | if (parent_removed && H5FS_SECT_LIVE == sect->u.row.under->sect_info.state) |
721 | 0 | if (H5HF__sect_row_parent_removed(sect) < 0) |
722 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTUPDATE, FAIL, "can't update section info"); |
723 | 0 | } /* end if */ |
724 | | |
725 | 0 | done: |
726 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
727 | 0 | } /* H5HF__sect_single_full_dblock() */ |
728 | | |
729 | | /*------------------------------------------------------------------------- |
730 | | * Function: H5HF__sect_single_add |
731 | | * |
732 | | * Purpose: Perform any actions on section as it is added to free space |
733 | | * manager |
734 | | * |
735 | | * Return: Success: non-negative |
736 | | * Failure: negative |
737 | | * |
738 | | *------------------------------------------------------------------------- |
739 | | */ |
740 | | static herr_t |
741 | | H5HF__sect_single_add(H5FS_section_info_t **_sect, unsigned *flags, void *_udata) |
742 | 0 | { |
743 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
744 | |
|
745 | 0 | FUNC_ENTER_PACKAGE |
746 | | |
747 | | /* Don't need to check section if we are deserializing, because it should |
748 | | * have already been checked when it was first added |
749 | | */ |
750 | 0 | if (!(*flags & H5FS_ADD_DESERIALIZING)) { |
751 | 0 | H5HF_free_section_t **sect = (H5HF_free_section_t **)_sect; /* Fractal heap free section */ |
752 | 0 | H5HF_sect_add_ud_t *udata = (H5HF_sect_add_ud_t *)_udata; /* User callback data */ |
753 | 0 | H5HF_hdr_t *hdr = udata->hdr; /* Fractal heap header */ |
754 | | |
755 | | /* Sanity check */ |
756 | 0 | assert(sect); |
757 | 0 | assert(hdr); |
758 | | |
759 | | /* Check if single section covers entire direct block it's in */ |
760 | | /* (converts to row section possibly) */ |
761 | 0 | if (H5HF__sect_single_full_dblock(hdr, (*sect)) < 0) |
762 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTCONVERT, FAIL, "can't check/convert single section"); |
763 | | |
764 | | /* Set the "returned space" flag if the single section was changed |
765 | | * into a row section, so the "merging & shrinking" algorithm |
766 | | * gets executed in the free space manager |
767 | | */ |
768 | 0 | if ((*sect)->sect_info.type != H5HF_FSPACE_SECT_SINGLE) |
769 | 0 | *flags |= H5FS_ADD_RETURNED_SPACE; |
770 | 0 | } /* end if */ |
771 | | |
772 | 0 | done: |
773 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
774 | 0 | } /* H5HF__sect_single_add() */ |
775 | | |
776 | | /*------------------------------------------------------------------------- |
777 | | * Function: H5HF__sect_single_deserialize |
778 | | * |
779 | | * Purpose: Deserialize a buffer into a "live" single section |
780 | | * |
781 | | * Return: Success: non-negative |
782 | | * Failure: negative |
783 | | * |
784 | | *------------------------------------------------------------------------- |
785 | | */ |
786 | | static H5FS_section_info_t * |
787 | | H5HF__sect_single_deserialize(const H5FS_section_class_t H5_ATTR_UNUSED *cls, |
788 | | const uint8_t H5_ATTR_UNUSED *buf, haddr_t sect_addr, hsize_t sect_size, |
789 | | unsigned H5_ATTR_UNUSED *des_flags) |
790 | 0 | { |
791 | 0 | H5HF_free_section_t *new_sect; /* New section */ |
792 | 0 | H5FS_section_info_t *ret_value = NULL; /* Return value */ |
793 | |
|
794 | 0 | FUNC_ENTER_PACKAGE |
795 | | |
796 | | /* Check arguments. */ |
797 | 0 | assert(H5_addr_defined(sect_addr)); |
798 | 0 | assert(sect_size); |
799 | | |
800 | | /* Create free list section node */ |
801 | 0 | if (NULL == |
802 | 0 | (new_sect = H5FS__sect_node_new(H5HF_FSPACE_SECT_SINGLE, sect_addr, sect_size, H5FS_SECT_SERIALIZED))) |
803 | 0 | HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "allocation failed for direct block free list section"); |
804 | | |
805 | | /* Set return value */ |
806 | 0 | ret_value = (H5FS_section_info_t *)new_sect; |
807 | |
|
808 | 0 | done: |
809 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
810 | 0 | } /* H5HF__sect_single_deserialize() */ |
811 | | |
812 | | /*------------------------------------------------------------------------- |
813 | | * Function: H5HF__sect_single_can_merge |
814 | | * |
815 | | * Purpose: Can two sections of this type merge? |
816 | | * |
817 | | * Note: Second section must be "after" first section |
818 | | * |
819 | | * Return: Success: non-negative (true/false) |
820 | | * |
821 | | * Failure: negative |
822 | | * |
823 | | *------------------------------------------------------------------------- |
824 | | */ |
825 | | static htri_t |
826 | | H5HF__sect_single_can_merge(const H5FS_section_info_t *_sect1, const H5FS_section_info_t *_sect2, |
827 | | void H5_ATTR_UNUSED *_udata) |
828 | 0 | { |
829 | 0 | const H5HF_free_section_t *sect1 = (const H5HF_free_section_t *)_sect1; /* Fractal heap free section */ |
830 | 0 | const H5HF_free_section_t *sect2 = (const H5HF_free_section_t *)_sect2; /* Fractal heap free section */ |
831 | 0 | htri_t ret_value = false; /* Return value */ |
832 | |
|
833 | 0 | FUNC_ENTER_PACKAGE_NOERR |
834 | | |
835 | | /* Check arguments. */ |
836 | 0 | assert(sect1); |
837 | 0 | assert(sect2); |
838 | 0 | assert(sect1->sect_info.type == sect2->sect_info.type); /* Checks "MERGE_SYM" flag */ |
839 | 0 | assert(H5_addr_lt(sect1->sect_info.addr, sect2->sect_info.addr)); |
840 | | |
841 | | /* Check if second section adjoins first section */ |
842 | | /* (This can only occur within a direct block, due to the direct block |
843 | | * overhead at the beginning of a block, so no need to check if sections |
844 | | * are actually within the same direct block) |
845 | | */ |
846 | 0 | if (H5_addr_eq(sect1->sect_info.addr + sect1->sect_info.size, sect2->sect_info.addr)) |
847 | 0 | HGOTO_DONE(true); |
848 | | |
849 | 0 | done: |
850 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
851 | 0 | } /* H5HF__sect_single_can_merge() */ |
852 | | |
853 | | /*------------------------------------------------------------------------- |
854 | | * Function: H5HF__sect_single_merge |
855 | | * |
856 | | * Purpose: Merge two sections of this type |
857 | | * |
858 | | * Note: Second section always merges into first node |
859 | | * |
860 | | * Return: Success: non-negative |
861 | | * |
862 | | * Failure: negative |
863 | | * |
864 | | *------------------------------------------------------------------------- |
865 | | */ |
866 | | static herr_t |
867 | | H5HF__sect_single_merge(H5FS_section_info_t **_sect1, H5FS_section_info_t *_sect2, void *_udata) |
868 | 0 | { |
869 | 0 | H5HF_free_section_t **sect1 = (H5HF_free_section_t **)_sect1; /* Fractal heap free section */ |
870 | 0 | H5HF_free_section_t *sect2 = (H5HF_free_section_t *)_sect2; /* Fractal heap free section */ |
871 | 0 | H5HF_sect_add_ud_t *udata = (H5HF_sect_add_ud_t *)_udata; /* User callback data */ |
872 | 0 | H5HF_hdr_t *hdr = udata->hdr; /* Fractal heap header */ |
873 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
874 | |
|
875 | 0 | FUNC_ENTER_PACKAGE |
876 | | |
877 | | /* Check arguments. */ |
878 | 0 | assert(sect1); |
879 | 0 | assert((*sect1)->sect_info.type == H5HF_FSPACE_SECT_SINGLE); |
880 | 0 | assert(sect2); |
881 | 0 | assert(sect2->sect_info.type == H5HF_FSPACE_SECT_SINGLE); |
882 | 0 | assert(H5_addr_eq((*sect1)->sect_info.addr + (*sect1)->sect_info.size, sect2->sect_info.addr)); |
883 | | |
884 | | /* Add second section's size to first section */ |
885 | 0 | (*sect1)->sect_info.size += sect2->sect_info.size; |
886 | | |
887 | | /* Get rid of second section */ |
888 | 0 | if (H5HF__sect_single_free((H5FS_section_info_t *)sect2) < 0) |
889 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTRELEASE, FAIL, "can't free section node"); |
890 | | |
891 | | /* Check to see if we should revive first section */ |
892 | 0 | if ((*sect1)->sect_info.state != H5FS_SECT_LIVE) |
893 | 0 | if (H5HF__sect_single_revive(hdr, (*sect1)) < 0) |
894 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "can't revive single free section"); |
895 | | |
896 | | /* Check if single section covers entire direct block it's in */ |
897 | | /* (converts to row section possibly) */ |
898 | 0 | if (H5HF__sect_single_full_dblock(hdr, (*sect1)) < 0) |
899 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTCONVERT, FAIL, "can't check/convert single section"); |
900 | | |
901 | 0 | done: |
902 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
903 | 0 | } /* H5HF__sect_single_merge() */ |
904 | | |
905 | | /*------------------------------------------------------------------------- |
906 | | * Function: H5HF__sect_single_can_shrink |
907 | | * |
908 | | * Purpose: Can this section shrink the container? |
909 | | * |
910 | | * Note: This isn't actually shrinking the heap (since that's already |
911 | | * been done) as much as it's cleaning up _after_ the heap |
912 | | * shrink. |
913 | | * |
914 | | * Return: Success: non-negative (true/false) |
915 | | * |
916 | | * Failure: negative |
917 | | * |
918 | | *------------------------------------------------------------------------- |
919 | | */ |
920 | | static htri_t |
921 | | H5HF__sect_single_can_shrink(const H5FS_section_info_t *_sect, void *_udata) |
922 | 0 | { |
923 | 0 | const H5HF_free_section_t *sect = (const H5HF_free_section_t *)_sect; /* Fractal heap free section */ |
924 | 0 | H5HF_sect_add_ud_t *udata = (H5HF_sect_add_ud_t *)_udata; /* User callback data */ |
925 | 0 | H5HF_hdr_t *hdr = udata->hdr; /* Fractal heap header */ |
926 | 0 | htri_t ret_value = false; /* Return value */ |
927 | |
|
928 | 0 | FUNC_ENTER_PACKAGE_NOERR |
929 | | |
930 | | /* Check arguments. */ |
931 | 0 | assert(sect); |
932 | | |
933 | | /* Check for section occupying entire root direct block */ |
934 | | /* (We shouldn't ever have a single section that occupies an entire |
935 | | * direct block, unless it's in the root direct block (because it |
936 | | * would have been converted into a row section, if there was an |
937 | | * indirect block that covered it) |
938 | | */ |
939 | 0 | if (hdr->man_dtable.curr_root_rows == 0) { |
940 | 0 | size_t dblock_size; /* Section's direct block's size */ |
941 | 0 | size_t dblock_overhead; /* Direct block's overhead */ |
942 | |
|
943 | 0 | dblock_size = hdr->man_dtable.cparam.start_block_size; |
944 | 0 | dblock_overhead = H5HF_MAN_ABS_DIRECT_OVERHEAD(hdr); |
945 | 0 | if ((dblock_size - dblock_overhead) == sect->sect_info.size) |
946 | 0 | HGOTO_DONE(true); |
947 | 0 | } /* end if */ |
948 | 0 | else { |
949 | | /* We shouldn't have a situation where the 'next block' iterator |
950 | | * is moved before a direct block that still has objects within it. |
951 | | */ |
952 | 0 | assert(hdr->man_iter_off > sect->sect_info.addr); |
953 | 0 | HGOTO_DONE(false); |
954 | 0 | } /* end else */ |
955 | | |
956 | 0 | done: |
957 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
958 | 0 | } /* H5HF__sect_single_can_shrink() */ |
959 | | |
960 | | /*------------------------------------------------------------------------- |
961 | | * Function: H5HF__sect_single_shrink |
962 | | * |
963 | | * Purpose: Shrink container with section |
964 | | * |
965 | | * Return: Success: non-negative |
966 | | * |
967 | | * Failure: negative |
968 | | * |
969 | | *------------------------------------------------------------------------- |
970 | | */ |
971 | | static herr_t |
972 | | H5HF__sect_single_shrink(H5FS_section_info_t **_sect, void *_udata) |
973 | 0 | { |
974 | 0 | H5HF_free_section_t **sect = (H5HF_free_section_t **)_sect; /* Fractal heap free section */ |
975 | 0 | H5HF_sect_add_ud_t *udata = (H5HF_sect_add_ud_t *)_udata; /* User callback data */ |
976 | 0 | H5HF_hdr_t *hdr = udata->hdr; /* Fractal heap header */ |
977 | 0 | H5HF_direct_t *dblock; /* Pointer to direct block for section */ |
978 | 0 | haddr_t dblock_addr = HADDR_UNDEF; /* Section's direct block's address */ |
979 | 0 | size_t dblock_size = SIZE_MAX; /* Section's direct block's size */ |
980 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
981 | |
|
982 | 0 | FUNC_ENTER_PACKAGE |
983 | | |
984 | | /* Check arguments. */ |
985 | 0 | assert(sect); |
986 | 0 | assert(*sect); |
987 | 0 | assert((*sect)->sect_info.type == H5HF_FSPACE_SECT_SINGLE); |
988 | | |
989 | | /* Check to see if we should revive section */ |
990 | 0 | if ((*sect)->sect_info.state != H5FS_SECT_LIVE) |
991 | 0 | if (H5HF__sect_single_revive(hdr, (*sect)) < 0) |
992 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "can't revive single free section"); |
993 | | |
994 | | /* Retrieve direct block address from section */ |
995 | 0 | if (H5HF__sect_single_dblock_info(hdr, (*sect), &dblock_addr, &dblock_size) < 0) |
996 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTGET, FAIL, "can't retrieve direct block information"); |
997 | 0 | if (!H5_addr_defined(dblock_addr)) |
998 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTGET, FAIL, "can't retrieve data block address"); |
999 | 0 | if (SIZE_MAX == dblock_size) |
1000 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTGET, FAIL, "can't retrieve data block size"); |
1001 | | |
1002 | | /* Protect the direct block for the section */ |
1003 | | /* (should be a root direct block) */ |
1004 | 0 | assert(dblock_addr == hdr->man_dtable.table_addr); |
1005 | 0 | if (NULL == (dblock = H5HF__man_dblock_protect(hdr, dblock_addr, dblock_size, (*sect)->u.single.parent, |
1006 | 0 | (*sect)->u.single.par_entry, H5AC__NO_FLAGS_SET))) |
1007 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTPROTECT, FAIL, "unable to load fractal heap direct block"); |
1008 | 0 | assert(H5_addr_eq(dblock->block_off + dblock_size, (*sect)->sect_info.addr + (*sect)->sect_info.size)); |
1009 | | |
1010 | | /* Get rid of section */ |
1011 | 0 | if (H5HF__sect_single_free((H5FS_section_info_t *)*sect) < 0) |
1012 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTRELEASE, FAIL, "can't free section node"); |
1013 | | |
1014 | | /* Destroy direct block */ |
1015 | 0 | if (H5HF__man_dblock_destroy(hdr, dblock, dblock_addr, NULL) < 0) |
1016 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTRELEASE, FAIL, "can't release direct block"); |
1017 | 0 | dblock = NULL; |
1018 | | |
1019 | | /* Indicate that the section has been released */ |
1020 | 0 | *sect = NULL; |
1021 | |
|
1022 | 0 | done: |
1023 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1024 | 0 | } /* H5HF__sect_single_shrink() */ |
1025 | | |
1026 | | /*------------------------------------------------------------------------- |
1027 | | * Function: H5HF__sect_single_free |
1028 | | * |
1029 | | * Purpose: Free a 'single' section node |
1030 | | * |
1031 | | * Return: Success: non-negative |
1032 | | * |
1033 | | * Failure: negative |
1034 | | * |
1035 | | *------------------------------------------------------------------------- |
1036 | | */ |
1037 | | herr_t |
1038 | | H5HF__sect_single_free(H5FS_section_info_t *_sect) |
1039 | 0 | { |
1040 | 0 | H5HF_free_section_t *sect = (H5HF_free_section_t *)_sect; /* Pointer to section to free */ |
1041 | 0 | H5HF_indirect_t *parent = NULL; /* Parent indirect block for section */ |
1042 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1043 | |
|
1044 | 0 | FUNC_ENTER_PACKAGE |
1045 | | |
1046 | | /* Check arguments. */ |
1047 | 0 | assert(sect); |
1048 | | |
1049 | | /* Check for live reference to an indirect block */ |
1050 | 0 | if (sect->sect_info.state == H5FS_SECT_LIVE) |
1051 | | /* Get parent indirect block, if there was one */ |
1052 | 0 | if (sect->u.single.parent) |
1053 | 0 | parent = sect->u.single.parent; |
1054 | | |
1055 | | /* Release the section */ |
1056 | 0 | if (H5HF__sect_node_free(sect, parent) < 0) |
1057 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTRELEASE, FAIL, "can't free section node"); |
1058 | | |
1059 | 0 | done: |
1060 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1061 | 0 | } /* H5HF__sect_single_free() */ |
1062 | | |
1063 | | /*------------------------------------------------------------------------- |
1064 | | * Function: H5HF__sect_single_valid |
1065 | | * |
1066 | | * Purpose: Check the validity of a section |
1067 | | * |
1068 | | * Return: Success: non-negative |
1069 | | * Failure: negative |
1070 | | * |
1071 | | *------------------------------------------------------------------------- |
1072 | | */ |
1073 | | static herr_t |
1074 | | H5HF__sect_single_valid(const H5FS_section_class_t H5_ATTR_UNUSED *cls, const H5FS_section_info_t *_sect) |
1075 | 0 | { |
1076 | 0 | const H5HF_free_section_t *sect = (const H5HF_free_section_t *)_sect; /* Pointer to section to check */ |
1077 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1078 | |
|
1079 | 0 | FUNC_ENTER_PACKAGE |
1080 | | |
1081 | | /* Check arguments. */ |
1082 | 0 | assert(sect); |
1083 | |
|
1084 | 0 | if (sect->sect_info.state == H5FS_SECT_LIVE) { |
1085 | | /* Check if this section is not in a direct block that is the root direct block */ |
1086 | | /* (not enough information to check on a single section in a root direct block) */ |
1087 | 0 | if (sect->u.single.parent != NULL) { |
1088 | 0 | H5HF_indirect_t *iblock; /* Indirect block that section's direct block resides in */ |
1089 | 0 | haddr_t dblock_addr = HADDR_UNDEF; /* Direct block address */ |
1090 | 0 | size_t dblock_size = SIZE_MAX; /* Direct block size */ |
1091 | 0 | unsigned dblock_status = 0; /* Direct block's status in the metadata cache */ |
1092 | 0 | size_t H5_ATTR_NDEBUG_UNUSED dblock_overhead; /* Direct block's overhead */ |
1093 | 0 | herr_t H5_ATTR_NDEBUG_UNUSED status; /* Generic status value */ |
1094 | | |
1095 | | /* Sanity check settings for section's direct block's parent */ |
1096 | 0 | iblock = sect->u.single.parent; |
1097 | 0 | assert(H5_addr_defined(iblock->ents[sect->u.single.par_entry].addr)); |
1098 | | |
1099 | | /* Retrieve direct block address from section */ |
1100 | 0 | if (H5HF__sect_single_dblock_info(iblock->hdr, (const H5HF_free_section_t *)sect, &dblock_addr, |
1101 | 0 | &dblock_size) < 0) |
1102 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTGET, FAIL, "can't retrieve direct block information"); |
1103 | 0 | if (!H5_addr_defined(dblock_addr)) |
1104 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTGET, FAIL, "can't retrieve data block address"); |
1105 | 0 | if (SIZE_MAX == dblock_size) |
1106 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTGET, FAIL, "can't retrieve data block size"); |
1107 | 0 | assert(H5_addr_eq(iblock->ents[sect->u.single.par_entry].addr, dblock_addr)); |
1108 | | |
1109 | | /* Check if the section is actually within the heap */ |
1110 | 0 | assert(sect->sect_info.addr < iblock->hdr->man_iter_off); |
1111 | | |
1112 | | /* Check that the direct block has been merged correctly */ |
1113 | 0 | dblock_overhead = H5HF_MAN_ABS_DIRECT_OVERHEAD(iblock->hdr); |
1114 | 0 | assert((sect->sect_info.size + dblock_overhead) < dblock_size); |
1115 | | |
1116 | | /* Check the direct block's status in the metadata cache */ |
1117 | 0 | status = H5AC_get_entry_status(iblock->hdr->f, dblock_addr, &dblock_status); |
1118 | 0 | assert(status >= 0); |
1119 | | |
1120 | | /* If the direct block for the section isn't already protected, |
1121 | | * protect it here in order to check single section's sanity |
1122 | | * against it. |
1123 | | */ |
1124 | 0 | if (!(dblock_status & H5AC_ES__IS_PROTECTED)) { |
1125 | 0 | H5HF_direct_t *dblock; /* Direct block for section */ |
1126 | | |
1127 | | /* Protect the direct block for the section */ |
1128 | 0 | dblock = H5HF__man_dblock_protect(iblock->hdr, dblock_addr, dblock_size, iblock, |
1129 | 0 | sect->u.single.par_entry, H5AC__READ_ONLY_FLAG); |
1130 | 0 | assert(dblock); |
1131 | | |
1132 | | /* Sanity check settings for section */ |
1133 | 0 | assert(dblock_size == dblock->size); |
1134 | 0 | assert(dblock->size > sect->sect_info.size); |
1135 | 0 | assert(H5_addr_lt(dblock->block_off, sect->sect_info.addr)); |
1136 | 0 | assert(H5_addr_ge((dblock->block_off + dblock->size), |
1137 | 0 | (sect->sect_info.addr + sect->sect_info.size))); |
1138 | | |
1139 | | /* Release direct block */ |
1140 | 0 | status = H5AC_unprotect(iblock->hdr->f, H5AC_FHEAP_DBLOCK, dblock_addr, dblock, |
1141 | 0 | H5AC__NO_FLAGS_SET); |
1142 | 0 | assert(status >= 0); |
1143 | 0 | } /* end if */ |
1144 | 0 | } /* end if */ |
1145 | 0 | } /* end if */ |
1146 | | |
1147 | 0 | done: |
1148 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1149 | 0 | } /* H5HF__sect_single_valid() */ |
1150 | | |
1151 | | /*------------------------------------------------------------------------- |
1152 | | * Function: H5HF__sect_row_create |
1153 | | * |
1154 | | * Purpose: Create a new 'row' section |
1155 | | * |
1156 | | * Return: Success: pointer to new section |
1157 | | * |
1158 | | * Failure: NULL |
1159 | | * |
1160 | | *------------------------------------------------------------------------- |
1161 | | */ |
1162 | | static H5HF_free_section_t * |
1163 | | H5HF__sect_row_create(haddr_t sect_off, hsize_t sect_size, bool is_first, unsigned row, unsigned col, |
1164 | | unsigned nentries, H5HF_free_section_t *under_sect) |
1165 | 0 | { |
1166 | 0 | H5HF_free_section_t *sect = NULL; /* 'Row' section created */ |
1167 | 0 | H5HF_free_section_t *ret_value = NULL; /* Return value */ |
1168 | |
|
1169 | 0 | FUNC_ENTER_PACKAGE |
1170 | | |
1171 | | /* Check arguments. */ |
1172 | 0 | assert(sect_size); |
1173 | 0 | assert(nentries); |
1174 | 0 | assert(under_sect); |
1175 | | |
1176 | | /* Create 'row' free space section node */ |
1177 | | /* ("inherits" underlying indirect section's state) */ |
1178 | 0 | if (NULL == (sect = H5FS__sect_node_new( |
1179 | 0 | (unsigned)(is_first ? H5HF_FSPACE_SECT_FIRST_ROW : H5HF_FSPACE_SECT_NORMAL_ROW), |
1180 | 0 | sect_off, sect_size, under_sect->sect_info.state))) |
1181 | 0 | HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for row section"); |
1182 | | |
1183 | | /* Set the 'row' specific fields */ |
1184 | 0 | sect->u.row.under = under_sect; |
1185 | 0 | sect->u.row.row = row; |
1186 | 0 | sect->u.row.col = col; |
1187 | 0 | sect->u.row.num_entries = nentries; |
1188 | 0 | sect->u.row.checked_out = false; |
1189 | | |
1190 | | /* Set return value */ |
1191 | 0 | ret_value = sect; |
1192 | |
|
1193 | 0 | done: |
1194 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1195 | 0 | } /* H5HF__sect_row_create() */ |
1196 | | |
1197 | | /*------------------------------------------------------------------------- |
1198 | | * Function: H5HF__sect_row_from_single |
1199 | | * |
1200 | | * Purpose: Convert a 'single' section into a 'row' section |
1201 | | * |
1202 | | * Return: Non-negative on success/Negative on failure |
1203 | | * |
1204 | | *------------------------------------------------------------------------- |
1205 | | */ |
1206 | | static herr_t |
1207 | | H5HF__sect_row_from_single(H5HF_hdr_t *hdr, H5HF_free_section_t *sect, H5HF_direct_t *dblock) |
1208 | 0 | { |
1209 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1210 | |
|
1211 | 0 | FUNC_ENTER_PACKAGE |
1212 | | |
1213 | | /* |
1214 | | * Check arguments. |
1215 | | */ |
1216 | 0 | assert(hdr); |
1217 | 0 | assert(sect); |
1218 | 0 | assert(dblock); |
1219 | | |
1220 | | /* Convert 'single' section information to 'row' section info */ |
1221 | 0 | sect->sect_info.addr = dblock->block_off; |
1222 | 0 | sect->sect_info.type = H5HF_FSPACE_SECT_FIRST_ROW; |
1223 | 0 | sect->u.row.row = dblock->par_entry / hdr->man_dtable.cparam.width; |
1224 | 0 | sect->u.row.col = dblock->par_entry % hdr->man_dtable.cparam.width; |
1225 | 0 | sect->u.row.num_entries = 1; |
1226 | 0 | sect->u.row.checked_out = false; |
1227 | | |
1228 | | /* Create indirect section that underlies the row section */ |
1229 | 0 | if (NULL == (sect->u.row.under = H5HF__sect_indirect_for_row(hdr, dblock->parent, sect))) |
1230 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTCREATE, FAIL, "serializing row section not supported yet"); |
1231 | | |
1232 | | /* Release single section's hold on underlying indirect block */ |
1233 | 0 | if (H5HF__iblock_decr(dblock->parent) < 0) |
1234 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTDEC, FAIL, "can't decrement reference count on shared indirect block"); |
1235 | | |
1236 | 0 | done: |
1237 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1238 | 0 | } /* end H5HF__sect_row_from_single() */ |
1239 | | |
1240 | | /*------------------------------------------------------------------------- |
1241 | | * Function: H5HF__sect_row_revive |
1242 | | * |
1243 | | * Purpose: Update the memory information for a 'row' free section |
1244 | | * |
1245 | | * Return: Non-negative on success/Negative on failure |
1246 | | * |
1247 | | *------------------------------------------------------------------------- |
1248 | | */ |
1249 | | herr_t |
1250 | | H5HF__sect_row_revive(H5HF_hdr_t *hdr, H5HF_free_section_t *sect) |
1251 | 0 | { |
1252 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1253 | |
|
1254 | 0 | FUNC_ENTER_PACKAGE |
1255 | | |
1256 | | /* |
1257 | | * Check arguments. |
1258 | | */ |
1259 | 0 | assert(hdr); |
1260 | 0 | assert(sect); |
1261 | 0 | assert(sect->u.row.under); |
1262 | | |
1263 | | /* If the indirect section's iblock has been removed from the cache, but the |
1264 | | * section is still marked as "live", switch it to the "serialized" state. |
1265 | | */ |
1266 | 0 | if ((H5FS_SECT_LIVE == sect->u.row.under->sect_info.state) && |
1267 | 0 | (true == sect->u.row.under->u.indirect.u.iblock->removed_from_cache)) |
1268 | 0 | if (H5HF__sect_row_parent_removed(sect) < 0) |
1269 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTUPDATE, FAIL, "can't update section info"); |
1270 | | |
1271 | | /* Pass along "revive" request to underlying indirect section */ |
1272 | | /* (which will mark this section as "live") */ |
1273 | 0 | if (H5HF__sect_indirect_revive_row(hdr, sect->u.row.under) < 0) |
1274 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTREVIVE, FAIL, "can't revive indirect section"); |
1275 | 0 | assert(sect->sect_info.state == H5FS_SECT_LIVE); |
1276 | |
|
1277 | 0 | done: |
1278 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1279 | 0 | } /* end H5HF__sect_row_revive() */ |
1280 | | |
1281 | | /*------------------------------------------------------------------------- |
1282 | | * Function: H5HF__sect_row_reduce |
1283 | | * |
1284 | | * Purpose: Reduce the size of a row section (possibly freeing it) |
1285 | | * and re-add it back to the free space manager for the heap |
1286 | | * (if it hasn't been freed) |
1287 | | * |
1288 | | * Return: Non-negative on success/Negative on failure |
1289 | | * |
1290 | | *------------------------------------------------------------------------- |
1291 | | */ |
1292 | | herr_t |
1293 | | H5HF__sect_row_reduce(H5HF_hdr_t *hdr, H5HF_free_section_t *sect, unsigned *entry_p) |
1294 | 0 | { |
1295 | 0 | bool alloc_from_start; /* Whether to allocate from the end of the row */ |
1296 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1297 | |
|
1298 | 0 | FUNC_ENTER_PACKAGE |
1299 | | |
1300 | | /* |
1301 | | * Check arguments. |
1302 | | */ |
1303 | 0 | assert(hdr); |
1304 | 0 | assert(sect); |
1305 | 0 | assert(sect->sect_info.type == H5HF_FSPACE_SECT_FIRST_ROW || |
1306 | 0 | sect->sect_info.type == H5HF_FSPACE_SECT_NORMAL_ROW); |
1307 | 0 | assert(sect->sect_info.state == H5FS_SECT_LIVE); |
1308 | 0 | assert(entry_p); |
1309 | | |
1310 | | /* Mark the row as checked out from the free space manager */ |
1311 | 0 | assert(sect->u.row.checked_out == false); |
1312 | 0 | sect->u.row.checked_out = true; |
1313 | | |
1314 | | /* Forward row section to indirect routines, to handle reducing underlying indirect section */ |
1315 | 0 | alloc_from_start = false; |
1316 | 0 | if (H5HF__sect_indirect_reduce_row(hdr, sect, &alloc_from_start) < 0) |
1317 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTSHRINK, FAIL, "can't reduce underlying section"); |
1318 | | |
1319 | | /* Determine entry allocated */ |
1320 | 0 | *entry_p = (sect->u.row.row * hdr->man_dtable.cparam.width) + sect->u.row.col; |
1321 | 0 | if (!alloc_from_start) |
1322 | 0 | *entry_p += (sect->u.row.num_entries - 1); |
1323 | | |
1324 | | /* Check for eliminating the section */ |
1325 | 0 | if (sect->u.row.num_entries == 1) { |
1326 | | /* Free row section */ |
1327 | 0 | if (H5HF__sect_row_free((H5FS_section_info_t *)sect) < 0) |
1328 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTRELEASE, FAIL, "can't free row section node"); |
1329 | 0 | } /* end if */ |
1330 | 0 | else { |
1331 | | /* Check whether to allocate from the beginning or end of the row */ |
1332 | 0 | if (alloc_from_start) { |
1333 | | /* Adjust section start */ |
1334 | 0 | sect->sect_info.addr += hdr->man_dtable.row_block_size[sect->u.row.row]; |
1335 | 0 | sect->u.row.col++; |
1336 | 0 | } /* end else */ |
1337 | | |
1338 | | /* Adjust span of blocks covered */ |
1339 | 0 | sect->u.row.num_entries--; |
1340 | | |
1341 | | /* Check the row back in */ |
1342 | 0 | sect->u.row.checked_out = false; |
1343 | | |
1344 | | /* Add 'row' section back to free space list */ |
1345 | 0 | if (H5HF__space_add(hdr, sect, 0) < 0) |
1346 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "can't re-add indirect section to free space manager"); |
1347 | 0 | } /* end else */ |
1348 | | |
1349 | 0 | done: |
1350 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1351 | 0 | } /* end H5HF__sect_row_reduce() */ |
1352 | | |
1353 | | /*------------------------------------------------------------------------- |
1354 | | * Function: H5HF__sect_row_first |
1355 | | * |
1356 | | * Purpose: Make row a "first row" |
1357 | | * |
1358 | | * Return: Non-negative on success/Negative on failure |
1359 | | * |
1360 | | *------------------------------------------------------------------------- |
1361 | | */ |
1362 | | static herr_t |
1363 | | H5HF__sect_row_first(H5HF_hdr_t *hdr, H5HF_free_section_t *sect) |
1364 | 0 | { |
1365 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1366 | |
|
1367 | 0 | FUNC_ENTER_PACKAGE |
1368 | | |
1369 | | /* Sanity check */ |
1370 | 0 | assert(hdr); |
1371 | 0 | assert(sect); |
1372 | 0 | assert(sect->sect_info.type == H5HF_FSPACE_SECT_NORMAL_ROW); |
1373 | | |
1374 | | /* If the row is already checked out from the free space manager, just |
1375 | | * change it's class directly and the free space manager will adjust when |
1376 | | * it is checked back in. |
1377 | | */ |
1378 | 0 | if (sect->u.row.checked_out) |
1379 | 0 | sect->sect_info.type = H5HF_FSPACE_SECT_FIRST_ROW; |
1380 | 0 | else |
1381 | | /* Change row section to be the "first row" */ |
1382 | 0 | if (H5HF__space_sect_change_class(hdr, sect, H5HF_FSPACE_SECT_FIRST_ROW) < 0) |
1383 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTSET, FAIL, "can't set row section to be first row"); |
1384 | | |
1385 | 0 | done: |
1386 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1387 | 0 | } /* end H5HF__sect_row_first() */ |
1388 | | |
1389 | | /*------------------------------------------------------------------------- |
1390 | | * Function: H5HF__sect_row_get_iblock |
1391 | | * |
1392 | | * Purpose: Retrieve the indirect block for a row section |
1393 | | * |
1394 | | * Return: Pointer to indirect block on success/NULL on failure |
1395 | | * |
1396 | | *------------------------------------------------------------------------- |
1397 | | */ |
1398 | | H5HF_indirect_t * |
1399 | | H5HF__sect_row_get_iblock(H5HF_free_section_t *sect) |
1400 | 0 | { |
1401 | 0 | H5HF_indirect_t *ret_value = NULL; /* Return value */ |
1402 | |
|
1403 | 0 | FUNC_ENTER_PACKAGE_NOERR |
1404 | | |
1405 | | /* |
1406 | | * Check arguments. |
1407 | | */ |
1408 | 0 | assert(sect); |
1409 | 0 | assert(sect->sect_info.type == H5HF_FSPACE_SECT_FIRST_ROW || |
1410 | 0 | sect->sect_info.type == H5HF_FSPACE_SECT_NORMAL_ROW); |
1411 | 0 | assert(sect->sect_info.state == H5FS_SECT_LIVE); |
1412 | |
|
1413 | 0 | ret_value = H5HF__sect_indirect_get_iblock(sect->u.row.under); |
1414 | |
|
1415 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1416 | 0 | } /* end H5HF__sect_row_get_iblock() */ |
1417 | | |
1418 | | /*------------------------------------------------------------------------- |
1419 | | * Function: H5HF__sect_row_parent_removed |
1420 | | * |
1421 | | * Purpose: Update the information for a row and its parent indirect |
1422 | | * when an indirect block is removed from the metadata cache. |
1423 | | * |
1424 | | * Return: Non-negative on success / Negative on failure |
1425 | | * |
1426 | | *------------------------------------------------------------------------- |
1427 | | */ |
1428 | | static herr_t |
1429 | | H5HF__sect_row_parent_removed(H5HF_free_section_t *sect) |
1430 | 0 | { |
1431 | 0 | hsize_t tmp_iblock_off; /* Indirect block offset for row */ |
1432 | 0 | unsigned u; /* Local index value */ |
1433 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1434 | |
|
1435 | 0 | FUNC_ENTER_PACKAGE |
1436 | | |
1437 | | /* Check arguments */ |
1438 | 0 | assert(sect); |
1439 | | |
1440 | | /* Get a copy of the indirect block's offset before decrementing refcount on it */ |
1441 | 0 | tmp_iblock_off = sect->u.row.under->u.indirect.u.iblock->block_off; |
1442 | | |
1443 | | /* Decrement the refcount on the indirect block, since serialized sections don't hold a reference */ |
1444 | 0 | if (H5HF__iblock_decr(sect->u.row.under->u.indirect.u.iblock) < 0) |
1445 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTDEC, FAIL, "can't decrement reference count on shared indirect block"); |
1446 | | |
1447 | | /* Switch indirect block info to serialized form */ |
1448 | | /* (Overwrites iblock pointer in the indirect section) */ |
1449 | 0 | sect->u.row.under->u.indirect.u.iblock_off = tmp_iblock_off; |
1450 | 0 | sect->u.row.under->u.indirect.iblock_entries = 0; |
1451 | | |
1452 | | /* Loop over derived row sections and mark them all as 'live' now */ |
1453 | 0 | for (u = 0; u < sect->u.row.under->u.indirect.dir_nrows; u++) |
1454 | 0 | sect->u.row.under->u.indirect.dir_rows[u]->sect_info.state = H5FS_SECT_SERIALIZED; |
1455 | | |
1456 | | /* Mark the indirect section as serialized now */ |
1457 | 0 | sect->u.row.under->sect_info.state = H5FS_SECT_SERIALIZED; |
1458 | | |
1459 | | /* Mark the row section as serialized now */ |
1460 | 0 | sect->sect_info.state = H5FS_SECT_SERIALIZED; |
1461 | |
|
1462 | 0 | done: |
1463 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1464 | 0 | } /* end H5HF__sect_row_parent_removed() */ |
1465 | | |
1466 | | /*------------------------------------------------------------------------- |
1467 | | * Function: H5HF__sect_row_init_cls |
1468 | | * |
1469 | | * Purpose: Initialize the "row" section class structure |
1470 | | * |
1471 | | * Note: Since 'row' sections are proxies for 'indirect' sections, this |
1472 | | * routine forwards call to 'indirect' class initialization |
1473 | | * |
1474 | | * Return: Success: non-negative |
1475 | | * |
1476 | | * Failure: negative |
1477 | | * |
1478 | | *------------------------------------------------------------------------- |
1479 | | */ |
1480 | | static herr_t |
1481 | | H5HF__sect_row_init_cls(H5FS_section_class_t *cls, void *_udata) |
1482 | 0 | { |
1483 | 0 | H5HF_hdr_t *hdr = (H5HF_hdr_t *)_udata; /* Fractal heap header */ |
1484 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1485 | |
|
1486 | 0 | FUNC_ENTER_PACKAGE |
1487 | | |
1488 | | /* Check arguments. */ |
1489 | 0 | assert(cls); |
1490 | 0 | assert(hdr); |
1491 | | |
1492 | | /* Call common class initialization */ |
1493 | 0 | if (H5FS__sect_init_cls(cls, hdr) < 0) |
1494 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "can't initialize common section class"); |
1495 | | |
1496 | | /* First row sections actually are proxies for indirection sections on disk */ |
1497 | 0 | if (cls->type == H5HF_FSPACE_SECT_FIRST_ROW) |
1498 | 0 | cls->serial_size = H5HF_SECT_INDIRECT_SERIAL_SIZE(hdr); |
1499 | 0 | else |
1500 | 0 | cls->serial_size = 0; |
1501 | |
|
1502 | 0 | done: |
1503 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1504 | 0 | } /* H5HF__sect_row_init_cls() */ |
1505 | | |
1506 | | /*------------------------------------------------------------------------- |
1507 | | * Function: H5HF__sect_row_term_cls |
1508 | | * |
1509 | | * Purpose: Terminate the "row" section class structure |
1510 | | * |
1511 | | * Note: Since 'row' sections are proxies for 'indirect' sections, this |
1512 | | * routine forwards call to 'indirect' class termination |
1513 | | * |
1514 | | * Return: Success: non-negative |
1515 | | * |
1516 | | * Failure: negative |
1517 | | * |
1518 | | *------------------------------------------------------------------------- |
1519 | | */ |
1520 | | static herr_t |
1521 | | H5HF__sect_row_term_cls(H5FS_section_class_t *cls) |
1522 | 0 | { |
1523 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1524 | |
|
1525 | 0 | FUNC_ENTER_PACKAGE |
1526 | | |
1527 | | /* Check arguments. */ |
1528 | 0 | assert(cls); |
1529 | | |
1530 | | /* Call common class termination */ |
1531 | 0 | if (H5FS__sect_term_cls(cls) < 0) |
1532 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTRELEASE, FAIL, "can't terminate common section class"); |
1533 | | |
1534 | 0 | done: |
1535 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1536 | 0 | } /* H5HF__sect_row_term_cls() */ |
1537 | | |
1538 | | /*------------------------------------------------------------------------- |
1539 | | * Function: H5HF__sect_row_serialize |
1540 | | * |
1541 | | * Purpose: Serialize a "live" row section into a buffer |
1542 | | * |
1543 | | * Return: Success: non-negative |
1544 | | * |
1545 | | * Failure: negative |
1546 | | * |
1547 | | *------------------------------------------------------------------------- |
1548 | | */ |
1549 | | static herr_t |
1550 | | H5HF__sect_row_serialize(const H5FS_section_class_t *cls, const H5FS_section_info_t *_sect, uint8_t *buf) |
1551 | 0 | { |
1552 | 0 | H5HF_hdr_t *hdr; /* Fractal heap header */ |
1553 | 0 | const H5HF_free_section_t *sect = (const H5HF_free_section_t *)_sect; |
1554 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1555 | |
|
1556 | 0 | FUNC_ENTER_PACKAGE |
1557 | | |
1558 | | /* Check arguments. */ |
1559 | 0 | assert(cls); |
1560 | 0 | assert(buf); |
1561 | 0 | assert(sect); |
1562 | 0 | assert(sect->sect_info.type == H5HF_FSPACE_SECT_FIRST_ROW); |
1563 | 0 | assert(sect->sect_info.addr == sect->u.row.under->sect_info.addr); |
1564 | | |
1565 | | /* Forward to indirect routine to serialize underlying section */ |
1566 | 0 | hdr = ((H5HF_sect_private_t *)(cls->cls_private))->hdr; |
1567 | 0 | if (H5HF__sect_indirect_serialize(hdr, sect->u.row.under, buf) < 0) |
1568 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTSERIALIZE, FAIL, |
1569 | 0 | "can't serialize row section's underlying indirect section"); |
1570 | | |
1571 | 0 | done: |
1572 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1573 | 0 | } /* H5HF__sect_row_serialize() */ |
1574 | | |
1575 | | /*------------------------------------------------------------------------- |
1576 | | * Function: H5HF__sect_row_deserialize |
1577 | | * |
1578 | | * Purpose: Deserialize a buffer into a "live" row section |
1579 | | * |
1580 | | * Note: Actually this routine just forwards to the 'indirect' |
1581 | | * deserialize routine, which creates the row section. |
1582 | | * |
1583 | | * Return: Success: non-negative |
1584 | | * |
1585 | | * Failure: negative |
1586 | | * |
1587 | | *------------------------------------------------------------------------- |
1588 | | */ |
1589 | | static H5FS_section_info_t * |
1590 | | H5HF__sect_row_deserialize(const H5FS_section_class_t *cls, const uint8_t *buf, haddr_t sect_addr, |
1591 | | hsize_t sect_size, unsigned *des_flags) |
1592 | 0 | { |
1593 | 0 | H5HF_hdr_t *hdr; /* Fractal heap header */ |
1594 | 0 | H5FS_section_info_t *ret_value = NULL; /* Return value */ |
1595 | |
|
1596 | 0 | FUNC_ENTER_PACKAGE |
1597 | | |
1598 | | /* Check arguments. */ |
1599 | 0 | assert(cls); |
1600 | 0 | assert(buf); |
1601 | 0 | assert(H5_addr_defined(sect_addr)); |
1602 | 0 | assert(sect_size); |
1603 | | |
1604 | | /* Forward to indirect routine to deserialize underlying section */ |
1605 | 0 | hdr = ((H5HF_sect_private_t *)(cls->cls_private))->hdr; |
1606 | 0 | if (NULL == (ret_value = H5HF__sect_indirect_deserialize(hdr, buf, sect_addr, sect_size, des_flags))) |
1607 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTDECODE, NULL, |
1608 | 0 | "can't deserialize row section's underlying indirect section"); |
1609 | | |
1610 | 0 | done: |
1611 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1612 | 0 | } /* H5HF__sect_row_deserialize() */ |
1613 | | |
1614 | | /*------------------------------------------------------------------------- |
1615 | | * Function: H5HF__sect_row_can_merge |
1616 | | * |
1617 | | * Purpose: Can two sections of this type merge? |
1618 | | * |
1619 | | * Note: Second section must be "after" first section |
1620 | | * |
1621 | | * Return: Success: non-negative (true/false) |
1622 | | * |
1623 | | * Failure: negative |
1624 | | * |
1625 | | *------------------------------------------------------------------------- |
1626 | | */ |
1627 | | static htri_t |
1628 | | H5HF__sect_row_can_merge(const H5FS_section_info_t *_sect1, const H5FS_section_info_t *_sect2, |
1629 | | void H5_ATTR_UNUSED *_udata) |
1630 | 0 | { |
1631 | 0 | const H5HF_free_section_t *sect1 = (const H5HF_free_section_t *)_sect1; /* Fractal heap free section */ |
1632 | 0 | const H5HF_free_section_t *sect2 = (const H5HF_free_section_t *)_sect2; /* Fractal heap free section */ |
1633 | 0 | H5HF_free_section_t *top_indir_sect1, *top_indir_sect2; /* Top indirect section for each row */ |
1634 | 0 | htri_t ret_value = false; /* Return value */ |
1635 | |
|
1636 | 0 | FUNC_ENTER_PACKAGE_NOERR |
1637 | | |
1638 | | /* Check arguments. */ |
1639 | 0 | assert(sect1); |
1640 | 0 | assert(sect1->sect_info.type == H5HF_FSPACE_SECT_FIRST_ROW); |
1641 | 0 | assert(sect2); |
1642 | 0 | assert(sect1->sect_info.type == sect2->sect_info.type); /* Checks "MERGE_SYM" flag */ |
1643 | 0 | assert(H5_addr_lt(sect1->sect_info.addr, sect2->sect_info.addr)); |
1644 | | |
1645 | | /* Get the top indirect section underlying each row */ |
1646 | 0 | top_indir_sect1 = H5HF__sect_indirect_top(sect1->u.row.under); |
1647 | 0 | assert(top_indir_sect1); |
1648 | 0 | top_indir_sect2 = H5HF__sect_indirect_top(sect2->u.row.under); |
1649 | 0 | assert(top_indir_sect2); |
1650 | | |
1651 | | /* Check if second section shares the same underlying indirect block as |
1652 | | * the first section, but doesn't already have same underlying indirect |
1653 | | * section. |
1654 | | */ |
1655 | 0 | if (top_indir_sect1 != top_indir_sect2) |
1656 | 0 | if (H5HF__sect_indirect_iblock_off(sect1->u.row.under) == |
1657 | 0 | H5HF__sect_indirect_iblock_off(sect2->u.row.under)) |
1658 | | /* Check if second section adjoins first section */ |
1659 | 0 | if (H5_addr_eq((top_indir_sect1->sect_info.addr + top_indir_sect1->u.indirect.span_size), |
1660 | 0 | top_indir_sect2->sect_info.addr)) |
1661 | 0 | HGOTO_DONE(true); |
1662 | | |
1663 | 0 | done: |
1664 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1665 | 0 | } /* H5HF__sect_row_can_merge() */ |
1666 | | |
1667 | | /*------------------------------------------------------------------------- |
1668 | | * Function: H5HF__sect_row_merge |
1669 | | * |
1670 | | * Purpose: Merge two sections of this type |
1671 | | * |
1672 | | * Note: Second section always merges into first node |
1673 | | * |
1674 | | * Return: Success: non-negative |
1675 | | * |
1676 | | * Failure: negative |
1677 | | * |
1678 | | *------------------------------------------------------------------------- |
1679 | | */ |
1680 | | static herr_t |
1681 | | H5HF__sect_row_merge(H5FS_section_info_t **_sect1, H5FS_section_info_t *_sect2, void *_udata) |
1682 | 0 | { |
1683 | 0 | H5HF_free_section_t **sect1 = (H5HF_free_section_t **)_sect1; /* Fractal heap free section */ |
1684 | 0 | H5HF_free_section_t *sect2 = (H5HF_free_section_t *)_sect2; /* Fractal heap free section */ |
1685 | 0 | H5HF_sect_add_ud_t *udata = (H5HF_sect_add_ud_t *)_udata; /* User callback data */ |
1686 | 0 | H5HF_hdr_t *hdr = udata->hdr; /* Fractal heap header */ |
1687 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1688 | |
|
1689 | 0 | FUNC_ENTER_PACKAGE |
1690 | | |
1691 | | /* Check arguments. */ |
1692 | 0 | assert(sect1); |
1693 | 0 | assert((*sect1)->sect_info.type == H5HF_FSPACE_SECT_FIRST_ROW); |
1694 | 0 | assert(sect2); |
1695 | 0 | assert(sect2->sect_info.type == H5HF_FSPACE_SECT_FIRST_ROW); |
1696 | | |
1697 | | /* Check if second section is past end of "next block" iterator */ |
1698 | 0 | if (sect2->sect_info.addr >= hdr->man_iter_off) { |
1699 | 0 | H5HF_free_section_t *top_indir_sect; /* Top indirect section for row */ |
1700 | | |
1701 | | /* Get the top indirect section underlying second row section */ |
1702 | 0 | top_indir_sect = H5HF__sect_indirect_top(sect2->u.row.under); |
1703 | | |
1704 | | /* Shrink away underlying indirect section */ |
1705 | 0 | if (H5HF__sect_indirect_shrink(hdr, top_indir_sect) < 0) |
1706 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTSHRINK, FAIL, "can't shrink underlying indirect section"); |
1707 | 0 | } /* end if */ |
1708 | 0 | else |
1709 | | /* Merge rows' underlying indirect sections together */ |
1710 | 0 | if (H5HF__sect_indirect_merge_row(hdr, (*sect1), sect2) < 0) |
1711 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTMERGE, FAIL, "can't merge underlying indirect sections"); |
1712 | | |
1713 | 0 | done: |
1714 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1715 | 0 | } /* H5HF__sect_row_merge() */ |
1716 | | |
1717 | | /*------------------------------------------------------------------------- |
1718 | | * Function: H5HF__sect_row_can_shrink |
1719 | | * |
1720 | | * Purpose: Can this section shrink the container? |
1721 | | * |
1722 | | * Note: This isn't actually shrinking the heap (since that's already |
1723 | | * been done) as much as it's cleaning up _after_ the heap |
1724 | | * shrink. |
1725 | | * |
1726 | | * Return: Success: non-negative (true/false) |
1727 | | * |
1728 | | * Failure: negative |
1729 | | * |
1730 | | *------------------------------------------------------------------------- |
1731 | | */ |
1732 | | static htri_t |
1733 | | H5HF__sect_row_can_shrink(const H5FS_section_info_t *_sect, void H5_ATTR_UNUSED *_udata) |
1734 | 0 | { |
1735 | 0 | const H5HF_free_section_t *sect = (const H5HF_free_section_t *)_sect; /* Fractal heap free section */ |
1736 | 0 | H5HF_sect_add_ud_t *udata = (H5HF_sect_add_ud_t *)_udata; /* User callback data */ |
1737 | 0 | H5HF_hdr_t *hdr = udata->hdr; /* Fractal heap header */ |
1738 | 0 | htri_t ret_value = false; /* Return value */ |
1739 | |
|
1740 | 0 | FUNC_ENTER_PACKAGE_NOERR |
1741 | | |
1742 | | /* Check arguments. */ |
1743 | 0 | assert(sect); |
1744 | 0 | assert(sect->sect_info.type == H5HF_FSPACE_SECT_FIRST_ROW); |
1745 | | |
1746 | | /* Check if section is past end of "next block" iterator */ |
1747 | 0 | if (sect->sect_info.addr >= hdr->man_iter_off) |
1748 | 0 | HGOTO_DONE(true); |
1749 | | |
1750 | 0 | done: |
1751 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1752 | 0 | } /* H5HF__sect_row_can_shrink() */ |
1753 | | |
1754 | | /*------------------------------------------------------------------------- |
1755 | | * Function: H5HF__sect_row_shrink |
1756 | | * |
1757 | | * Purpose: Shrink container with section |
1758 | | * |
1759 | | * Return: Success: non-negative |
1760 | | * |
1761 | | * Failure: negative |
1762 | | * |
1763 | | *------------------------------------------------------------------------- |
1764 | | */ |
1765 | | static herr_t |
1766 | | H5HF__sect_row_shrink(H5FS_section_info_t **_sect, void *_udata) |
1767 | 0 | { |
1768 | 0 | H5HF_free_section_t **sect = (H5HF_free_section_t **)_sect; /* Fractal heap free section */ |
1769 | 0 | H5HF_free_section_t *top_indir_sect; /* Top indirect section for row */ |
1770 | 0 | H5HF_sect_add_ud_t *udata = (H5HF_sect_add_ud_t *)_udata; /* User callback data */ |
1771 | 0 | H5HF_hdr_t *hdr = udata->hdr; /* Fractal heap header */ |
1772 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1773 | |
|
1774 | 0 | FUNC_ENTER_PACKAGE |
1775 | | |
1776 | | /* Check arguments. */ |
1777 | 0 | assert(sect); |
1778 | 0 | assert(*sect); |
1779 | 0 | assert((*sect)->sect_info.type == H5HF_FSPACE_SECT_FIRST_ROW); |
1780 | | |
1781 | | /* Get the top indirect section underlying each row */ |
1782 | 0 | top_indir_sect = H5HF__sect_indirect_top((*sect)->u.row.under); |
1783 | | |
1784 | | /* Shrink away underlying indirect section */ |
1785 | 0 | if (H5HF__sect_indirect_shrink(hdr, top_indir_sect) < 0) |
1786 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTSHRINK, FAIL, "can't shrink underlying indirect section"); |
1787 | | |
1788 | | /* Indicate that the section has been released */ |
1789 | 0 | *sect = NULL; |
1790 | |
|
1791 | 0 | done: |
1792 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1793 | 0 | } /* H5HF__sect_row_shrink() */ |
1794 | | |
1795 | | /*------------------------------------------------------------------------- |
1796 | | * Function: H5HF__sect_row_free_real |
1797 | | * |
1798 | | * Purpose: Free a 'row' section node |
1799 | | * |
1800 | | * Return: Success: non-negative |
1801 | | * |
1802 | | * Failure: negative |
1803 | | * |
1804 | | *------------------------------------------------------------------------- |
1805 | | */ |
1806 | | static herr_t |
1807 | | H5HF__sect_row_free_real(H5HF_free_section_t *sect) |
1808 | 0 | { |
1809 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1810 | |
|
1811 | 0 | FUNC_ENTER_PACKAGE |
1812 | |
|
1813 | 0 | assert(sect); |
1814 | | |
1815 | | /* Release the section */ |
1816 | 0 | if (H5HF__sect_node_free(sect, NULL) < 0) |
1817 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTRELEASE, FAIL, "can't free section node"); |
1818 | | |
1819 | 0 | done: |
1820 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1821 | 0 | } /* H5HF__sect_row_free_real() */ |
1822 | | |
1823 | | /*------------------------------------------------------------------------- |
1824 | | * Function: H5HF__sect_row_free |
1825 | | * |
1826 | | * Purpose: Free a 'row' section node |
1827 | | * |
1828 | | * Return: Success: non-negative |
1829 | | * |
1830 | | * Failure: negative |
1831 | | * |
1832 | | *------------------------------------------------------------------------- |
1833 | | */ |
1834 | | static herr_t |
1835 | | H5HF__sect_row_free(H5FS_section_info_t *_sect) |
1836 | 0 | { |
1837 | 0 | H5HF_free_section_t *sect = (H5HF_free_section_t *)_sect; /* Pointer to section to free */ |
1838 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
1839 | |
|
1840 | 0 | FUNC_ENTER_PACKAGE |
1841 | |
|
1842 | 0 | assert(sect); |
1843 | 0 | assert(sect->u.row.under); |
1844 | | |
1845 | | /* Decrement the ref. count on the row section's underlying indirect section */ |
1846 | 0 | if (H5HF__sect_indirect_decr(sect->u.row.under) < 0) |
1847 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTRELEASE, FAIL, "can't detach section node"); |
1848 | | |
1849 | | /* Release the section */ |
1850 | 0 | if (H5HF__sect_row_free_real(sect) < 0) |
1851 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTRELEASE, FAIL, "can't free section node"); |
1852 | | |
1853 | 0 | done: |
1854 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1855 | 0 | } /* H5HF__sect_row_free() */ |
1856 | | |
1857 | | /*------------------------------------------------------------------------- |
1858 | | * Function: H5HF__sect_row_valid |
1859 | | * |
1860 | | * Purpose: Check the validity of a section |
1861 | | * |
1862 | | * Return: Success: non-negative |
1863 | | * Failure: negative |
1864 | | * |
1865 | | *------------------------------------------------------------------------- |
1866 | | */ |
1867 | | static herr_t |
1868 | | H5HF__sect_row_valid(const H5FS_section_class_t *cls, const H5FS_section_info_t *_sect) |
1869 | 0 | { |
1870 | 0 | H5HF_sect_private_t *cls_prvt; /* Pointer to class private info */ |
1871 | 0 | const H5HF_hdr_t *hdr; /* Fractal heap header */ |
1872 | 0 | const H5HF_free_section_t *sect = (const H5HF_free_section_t *)_sect; /* Pointer to section to check */ |
1873 | 0 | const H5HF_free_section_t *indir_sect; /* Pointer to underlying indirect section */ |
1874 | 0 | unsigned H5_ATTR_NDEBUG_UNUSED indir_idx; /* Index of row in underlying indirect section's row array */ |
1875 | |
|
1876 | 0 | FUNC_ENTER_PACKAGE_NOERR |
1877 | | |
1878 | | /* Basic sanity check */ |
1879 | 0 | assert(cls); |
1880 | 0 | assert(sect); |
1881 | | |
1882 | | /* Retrieve class private information */ |
1883 | 0 | cls_prvt = (H5HF_sect_private_t *)cls->cls_private; |
1884 | 0 | hdr = cls_prvt->hdr; |
1885 | | |
1886 | | /* Sanity checking on the row */ |
1887 | 0 | assert(sect->u.row.under); |
1888 | 0 | assert(sect->u.row.num_entries); |
1889 | 0 | assert(sect->u.row.checked_out == false); |
1890 | 0 | indir_sect = sect->u.row.under; |
1891 | 0 | indir_idx = sect->u.row.row - indir_sect->u.indirect.row; |
1892 | 0 | assert(indir_sect->u.indirect.dir_rows[indir_idx] == sect); |
1893 | | |
1894 | | /* Check if the section is actually within the heap */ |
1895 | 0 | assert(sect->sect_info.addr < hdr->man_iter_off); |
1896 | | |
1897 | | /* Different checking for different kinds of rows */ |
1898 | 0 | if (sect->sect_info.type == H5HF_FSPACE_SECT_FIRST_ROW) { |
1899 | 0 | H5HF_free_section_t *top_indir_sect; /* Top indirect section for row */ |
1900 | | |
1901 | | /* Some extra sanity checks on the row */ |
1902 | 0 | assert(sect->u.row.row == indir_sect->u.indirect.row); |
1903 | | |
1904 | | /* Get the top indirect section underlying row */ |
1905 | 0 | top_indir_sect = H5HF__sect_indirect_top(sect->u.row.under); |
1906 | | |
1907 | | /* Check that the row's underlying indirect section is valid */ |
1908 | 0 | H5HF__sect_indirect_valid(hdr, top_indir_sect); |
1909 | 0 | } /* end if */ |
1910 | |
|
1911 | 0 | FUNC_LEAVE_NOAPI(SUCCEED) |
1912 | 0 | } /* H5HF__sect_row_valid() */ |
1913 | | |
1914 | | /*------------------------------------------------------------------------- |
1915 | | * Function: H5HF__sect_row_debug |
1916 | | * |
1917 | | * Purpose: Dump debugging information about an row free space section |
1918 | | * |
1919 | | * Return: Success: non-negative |
1920 | | * Failure: negative |
1921 | | * |
1922 | | *------------------------------------------------------------------------- |
1923 | | */ |
1924 | | static herr_t |
1925 | | H5HF__sect_row_debug(const H5FS_section_info_t *_sect, FILE *stream, int indent, int fwidth) |
1926 | 0 | { |
1927 | 0 | const H5HF_free_section_t *sect = (const H5HF_free_section_t *)_sect; /* Section to dump info */ |
1928 | |
|
1929 | 0 | FUNC_ENTER_PACKAGE_NOERR |
1930 | | |
1931 | | /* Check arguments. */ |
1932 | 0 | assert(sect); |
1933 | | |
1934 | | /* Print indirect section information */ |
1935 | 0 | fprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, "Row:", sect->u.row.row); |
1936 | 0 | fprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, "Column:", sect->u.row.col); |
1937 | 0 | fprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, "Number of entries:", sect->u.row.num_entries); |
1938 | | |
1939 | | /* If this is a first row section display information about underlying indirect section */ |
1940 | 0 | if (sect->sect_info.type == H5HF_FSPACE_SECT_FIRST_ROW) { |
1941 | | /* Print indirect section header */ |
1942 | 0 | fprintf(stream, "%*s%-*s\n", indent, "", fwidth, "Underlying indirect section:"); |
1943 | |
|
1944 | 0 | H5HF__sect_indirect_debug(sect->u.row.under, stream, indent + 3, MAX(0, fwidth - 3)); |
1945 | 0 | } /* end if */ |
1946 | |
|
1947 | 0 | FUNC_LEAVE_NOAPI(SUCCEED) |
1948 | 0 | } /* H5HF__sect_row_debug() */ |
1949 | | |
1950 | | /*------------------------------------------------------------------------- |
1951 | | * Function: H5HF__sect_indirect_iblock_off |
1952 | | * |
1953 | | * Purpose: Get the offset of the indirect block for the section |
1954 | | * |
1955 | | * Return: Offset of indirect block in "heap space" (can't fail) |
1956 | | * |
1957 | | *------------------------------------------------------------------------- |
1958 | | */ |
1959 | | static hsize_t |
1960 | | H5HF__sect_indirect_iblock_off(const H5HF_free_section_t *sect) |
1961 | 0 | { |
1962 | 0 | hsize_t ret_value = 0; /* Return value */ |
1963 | |
|
1964 | 0 | FUNC_ENTER_PACKAGE_NOERR |
1965 | | |
1966 | | /* |
1967 | | * Check arguments. |
1968 | | */ |
1969 | 0 | assert(sect); |
1970 | |
|
1971 | 0 | ret_value = sect->sect_info.state == H5FS_SECT_LIVE ? sect->u.indirect.u.iblock->block_off |
1972 | 0 | : sect->u.indirect.u.iblock_off; |
1973 | |
|
1974 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
1975 | 0 | } /* end H5HF__sect_indirect_iblock_off() */ |
1976 | | |
1977 | | /*------------------------------------------------------------------------- |
1978 | | * Function: H5HF__sect_indirect_top |
1979 | | * |
1980 | | * Purpose: Get the "top" indirect section |
1981 | | * |
1982 | | * Return: Pointer to the top indirect section (can't fail) |
1983 | | * |
1984 | | *------------------------------------------------------------------------- |
1985 | | */ |
1986 | | static H5HF_free_section_t * |
1987 | | H5HF__sect_indirect_top(H5HF_free_section_t *sect) |
1988 | 0 | { |
1989 | 0 | H5HF_free_section_t *ret_value = NULL; /* Return value */ |
1990 | |
|
1991 | 0 | FUNC_ENTER_PACKAGE_NOERR |
1992 | | |
1993 | | /* |
1994 | | * Check arguments. |
1995 | | */ |
1996 | 0 | assert(sect); |
1997 | |
|
1998 | 0 | if (sect->u.indirect.parent) |
1999 | 0 | ret_value = H5HF__sect_indirect_top(sect->u.indirect.parent); |
2000 | 0 | else |
2001 | 0 | ret_value = sect; |
2002 | |
|
2003 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
2004 | 0 | } /* end H5HF__sect_indirect_top() */ |
2005 | | |
2006 | | /*------------------------------------------------------------------------- |
2007 | | * Function: H5HF__sect_indirect_init_cls |
2008 | | * |
2009 | | * Purpose: Initialize the "indirect" class structure |
2010 | | * |
2011 | | * Return: Success: non-negative |
2012 | | * |
2013 | | * Failure: negative |
2014 | | * |
2015 | | *------------------------------------------------------------------------- |
2016 | | */ |
2017 | | static herr_t |
2018 | | H5HF__sect_indirect_init_cls(H5FS_section_class_t *cls, void *_udata) |
2019 | 0 | { |
2020 | 0 | H5HF_hdr_t *hdr = (H5HF_hdr_t *)_udata; /* Fractal heap header */ |
2021 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
2022 | |
|
2023 | 0 | FUNC_ENTER_PACKAGE |
2024 | | |
2025 | | /* Check arguments. */ |
2026 | 0 | assert(cls); |
2027 | 0 | assert(hdr); |
2028 | | |
2029 | | /* Call to common class initialization */ |
2030 | 0 | if (H5FS__sect_init_cls(cls, hdr) < 0) |
2031 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "can't initialize common section class"); |
2032 | | |
2033 | | /* Set the size of all serialized objects of this class of sections */ |
2034 | 0 | cls->serial_size = H5HF_SECT_INDIRECT_SERIAL_SIZE(hdr); |
2035 | |
|
2036 | 0 | done: |
2037 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
2038 | 0 | } /* H5HF__sect_indirect_init_cls() */ |
2039 | | |
2040 | | /*------------------------------------------------------------------------- |
2041 | | * Function: H5HF__sect_indirect_term_cls |
2042 | | * |
2043 | | * Purpose: Terminate the "indirect" class structure |
2044 | | * |
2045 | | * Return: Success: non-negative |
2046 | | * |
2047 | | * Failure: negative |
2048 | | * |
2049 | | *------------------------------------------------------------------------- |
2050 | | */ |
2051 | | static herr_t |
2052 | | H5HF__sect_indirect_term_cls(H5FS_section_class_t *cls) |
2053 | 0 | { |
2054 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
2055 | |
|
2056 | 0 | FUNC_ENTER_PACKAGE |
2057 | | |
2058 | | /* Check arguments. */ |
2059 | 0 | assert(cls); |
2060 | | |
2061 | | /* Call common class termination */ |
2062 | 0 | if (H5FS__sect_term_cls(cls) < 0) |
2063 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTRELEASE, FAIL, "can't terminate common section class"); |
2064 | | |
2065 | 0 | done: |
2066 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
2067 | 0 | } /* H5HF__sect_indirect_term_cls() */ |
2068 | | |
2069 | | /*------------------------------------------------------------------------- |
2070 | | * Function: H5HF__sect_indirect_new |
2071 | | * |
2072 | | * Purpose: Create a new 'indirect' section for other routines to finish |
2073 | | * initializing. |
2074 | | * |
2075 | | * Return: Non-negative on success/Negative on failure |
2076 | | * |
2077 | | *------------------------------------------------------------------------- |
2078 | | */ |
2079 | | static H5HF_free_section_t * |
2080 | | H5HF__sect_indirect_new(H5HF_hdr_t *hdr, haddr_t sect_off, hsize_t sect_size, H5HF_indirect_t *iblock, |
2081 | | hsize_t iblock_off, unsigned row, unsigned col, unsigned nentries) |
2082 | 0 | { |
2083 | 0 | H5HF_free_section_t *sect = NULL; /* 'Indirect' free space section to add */ |
2084 | 0 | H5HF_free_section_t *ret_value = NULL; /* Return value */ |
2085 | |
|
2086 | 0 | FUNC_ENTER_PACKAGE |
2087 | | |
2088 | | /* |
2089 | | * Check arguments. |
2090 | | */ |
2091 | 0 | assert(hdr); |
2092 | 0 | assert(nentries); |
2093 | | |
2094 | | /* Create free space section node */ |
2095 | 0 | if (NULL == (sect = H5FS__sect_node_new(H5HF_FSPACE_SECT_INDIRECT, sect_off, sect_size, |
2096 | 0 | (iblock ? H5FS_SECT_LIVE : H5FS_SECT_SERIALIZED)))) |
2097 | 0 | HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for indirect section"); |
2098 | | |
2099 | | /* Set the 'indirect' specific fields */ |
2100 | 0 | if (iblock) { |
2101 | 0 | sect->u.indirect.u.iblock = iblock; |
2102 | 0 | sect->u.indirect.iblock_entries = hdr->man_dtable.cparam.width * sect->u.indirect.u.iblock->max_rows; |
2103 | 0 | if (H5HF__iblock_incr(sect->u.indirect.u.iblock) < 0) |
2104 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTINC, NULL, |
2105 | 0 | "can't increment reference count on shared indirect block"); |
2106 | 0 | } /* end if */ |
2107 | 0 | else { |
2108 | 0 | sect->u.indirect.u.iblock_off = iblock_off; |
2109 | 0 | sect->u.indirect.iblock_entries = 0; |
2110 | 0 | } /* end else */ |
2111 | 0 | sect->u.indirect.row = row; |
2112 | 0 | sect->u.indirect.col = col; |
2113 | 0 | sect->u.indirect.num_entries = nentries; |
2114 | | |
2115 | | /* Compute span size of indirect section */ |
2116 | 0 | sect->u.indirect.span_size = H5HF__dtable_span_size(&hdr->man_dtable, row, col, nentries); |
2117 | 0 | assert(sect->u.indirect.span_size > 0); |
2118 | | |
2119 | | /* This indirect section doesn't (currently) have a parent */ |
2120 | 0 | sect->u.indirect.parent = NULL; |
2121 | 0 | sect->u.indirect.par_entry = 0; |
2122 | | |
2123 | | /* Set return value */ |
2124 | 0 | ret_value = sect; |
2125 | |
|
2126 | 0 | done: |
2127 | 0 | if (!ret_value && sect) { |
2128 | | /* Release the section */ |
2129 | 0 | sect = H5FL_FREE(H5HF_free_section_t, sect); |
2130 | 0 | } /* end if */ |
2131 | |
|
2132 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
2133 | 0 | } /* end H5HF__sect_indirect_new() */ |
2134 | | |
2135 | | /*------------------------------------------------------------------------- |
2136 | | * Function: H5HF__sect_indirect_for_row |
2137 | | * |
2138 | | * Purpose: Create the underlying indirect section for a new row section |
2139 | | * |
2140 | | * Return: Non-negative on success/Negative on failure |
2141 | | * |
2142 | | *------------------------------------------------------------------------- |
2143 | | */ |
2144 | | static H5HF_free_section_t * |
2145 | | H5HF__sect_indirect_for_row(H5HF_hdr_t *hdr, H5HF_indirect_t *iblock, H5HF_free_section_t *row_sect) |
2146 | 0 | { |
2147 | 0 | H5HF_free_section_t *sect = NULL; /* 'Indirect' free space section to add */ |
2148 | 0 | H5HF_free_section_t *ret_value = NULL; /* Return value */ |
2149 | |
|
2150 | 0 | FUNC_ENTER_PACKAGE |
2151 | | |
2152 | | /* |
2153 | | * Check arguments. |
2154 | | */ |
2155 | 0 | assert(hdr); |
2156 | 0 | assert(iblock); |
2157 | 0 | assert(row_sect); |
2158 | 0 | assert(row_sect->u.row.row < hdr->man_dtable.max_direct_rows); |
2159 | | |
2160 | | /* Create free space section node */ |
2161 | 0 | if (NULL == (sect = H5HF__sect_indirect_new(hdr, row_sect->sect_info.addr, row_sect->sect_info.size, |
2162 | 0 | iblock, iblock->block_off, row_sect->u.row.row, |
2163 | 0 | row_sect->u.row.col, row_sect->u.row.num_entries))) |
2164 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, NULL, "can't create indirect section"); |
2165 | | |
2166 | | /* Set # of direct rows covered */ |
2167 | 0 | sect->u.indirect.dir_nrows = 1; |
2168 | | |
2169 | | /* Allocate space for the derived row sections */ |
2170 | 0 | if (NULL == |
2171 | 0 | (sect->u.indirect.dir_rows = (H5HF_free_section_t **)H5MM_malloc(sizeof(H5HF_free_section_t *)))) |
2172 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_NOSPACE, NULL, "allocation failed for row section pointer array"); |
2173 | | |
2174 | | /* Attach the new row section to indirect section */ |
2175 | 0 | sect->u.indirect.dir_rows[0] = row_sect; |
2176 | 0 | sect->u.indirect.rc = 1; |
2177 | | |
2178 | | /* No indirect rows in current section */ |
2179 | 0 | sect->u.indirect.indir_nents = 0; |
2180 | 0 | sect->u.indirect.indir_ents = NULL; |
2181 | | |
2182 | | /* Set return value */ |
2183 | 0 | ret_value = sect; |
2184 | |
|
2185 | 0 | done: |
2186 | 0 | if (!ret_value && sect) |
2187 | 0 | if (H5HF__sect_indirect_free(sect) < 0) |
2188 | 0 | HDONE_ERROR(H5E_HEAP, H5E_CANTRELEASE, NULL, "can't free indirect section node"); |
2189 | |
|
2190 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
2191 | 0 | } /* end H5HF__sect_indirect_for_row() */ |
2192 | | |
2193 | | /*------------------------------------------------------------------------- |
2194 | | * Function: H5HF__sect_indirect_init_rows |
2195 | | * |
2196 | | * Purpose: Initialize the derived row sections for a newly created |
2197 | | * indirect section |
2198 | | * |
2199 | | * Return: Non-negative on success/Negative on failure |
2200 | | * |
2201 | | *------------------------------------------------------------------------- |
2202 | | */ |
2203 | | static herr_t |
2204 | | H5HF__sect_indirect_init_rows(H5HF_hdr_t *hdr, H5HF_free_section_t *sect, bool first_child, |
2205 | | H5HF_free_section_t **first_row_sect, unsigned space_flags, unsigned start_row, |
2206 | | unsigned start_col, unsigned end_row, unsigned end_col) |
2207 | 0 | { |
2208 | 0 | hsize_t curr_off; /* Offset of new section in "heap space" */ |
2209 | 0 | size_t dblock_overhead; /* Direct block's overhead */ |
2210 | 0 | unsigned row_entries; /* # of entries in row */ |
2211 | 0 | unsigned row_col; /* Column within current row */ |
2212 | 0 | unsigned curr_entry; /* Current entry within indirect section */ |
2213 | 0 | unsigned curr_indir_entry; /* Current indirect entry within indirect section */ |
2214 | 0 | unsigned curr_row; /* Current row within indirect section */ |
2215 | 0 | unsigned dir_nrows; /* # of direct rows in indirect section */ |
2216 | 0 | unsigned u; /* Local index variable */ |
2217 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
2218 | |
|
2219 | 0 | FUNC_ENTER_PACKAGE |
2220 | | |
2221 | | /* |
2222 | | * Check arguments. |
2223 | | */ |
2224 | 0 | assert(sect); |
2225 | 0 | assert(sect->u.indirect.span_size > 0); |
2226 | | |
2227 | | /* Reset reference count for indirect section */ |
2228 | | /* (Also reset the direct & indirect row pointers */ |
2229 | 0 | sect->u.indirect.rc = 0; |
2230 | 0 | sect->u.indirect.dir_rows = NULL; |
2231 | 0 | sect->u.indirect.indir_ents = NULL; |
2232 | | |
2233 | | /* Set up direct block information, if necessary */ |
2234 | 0 | if (start_row < hdr->man_dtable.max_direct_rows) { |
2235 | 0 | unsigned max_direct_row; /* Max. direct row covered */ |
2236 | | |
2237 | | /* Compute max. direct row covered by indirect section */ |
2238 | 0 | max_direct_row = MIN(end_row, (hdr->man_dtable.max_direct_rows - 1)); |
2239 | | |
2240 | | /* Compute # of direct rows covered */ |
2241 | 0 | dir_nrows = (max_direct_row - start_row) + 1; |
2242 | | |
2243 | | /* Don't set the of direct rows in section yet, so sanity |
2244 | | * checking works (enabled in free section manager, with H5FS_DEBUG |
2245 | | * macro) correctly. |
2246 | | */ |
2247 | 0 | sect->u.indirect.dir_nrows = 0; |
2248 | | |
2249 | | /* Allocate space for the derived row sections */ |
2250 | 0 | if (NULL == (sect->u.indirect.dir_rows = |
2251 | 0 | (H5HF_free_section_t **)H5MM_malloc(sizeof(H5HF_free_section_t *) * dir_nrows))) |
2252 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_NOSPACE, FAIL, "allocation failed for row section pointer array"); |
2253 | 0 | } /* end if */ |
2254 | 0 | else { |
2255 | | /* No rows of direct blocks covered, reset direct row information */ |
2256 | 0 | dir_nrows = 0; |
2257 | 0 | sect->u.indirect.dir_nrows = 0; |
2258 | 0 | } /* end else */ |
2259 | | |
2260 | | /* Set up indirect block information, if necessary */ |
2261 | 0 | if (end_row >= hdr->man_dtable.max_direct_rows) { |
2262 | 0 | unsigned indirect_start_row; /* Row to start indirect entries on */ |
2263 | 0 | unsigned indirect_start_col; /* Column to start indirect entries on */ |
2264 | 0 | unsigned indirect_start_entry; /* Index of starting indirect entry */ |
2265 | 0 | unsigned indirect_end_entry; /* Index of ending indirect entry */ |
2266 | | |
2267 | | /* Compute starting indirect entry */ |
2268 | 0 | if (start_row < hdr->man_dtable.max_direct_rows) { |
2269 | 0 | indirect_start_row = hdr->man_dtable.max_direct_rows; |
2270 | 0 | indirect_start_col = 0; |
2271 | 0 | } /* end if */ |
2272 | 0 | else { |
2273 | 0 | indirect_start_row = start_row; |
2274 | 0 | indirect_start_col = start_col; |
2275 | 0 | } /* end else */ |
2276 | 0 | indirect_start_entry = (indirect_start_row * hdr->man_dtable.cparam.width) + indirect_start_col; |
2277 | | |
2278 | | /* Compute ending indirect entry */ |
2279 | 0 | indirect_end_entry = (end_row * hdr->man_dtable.cparam.width) + end_col; |
2280 | | |
2281 | | /* Compute # of indirect entries covered */ |
2282 | 0 | sect->u.indirect.indir_nents = (indirect_end_entry - indirect_start_entry) + 1; |
2283 | | |
2284 | | /* Allocate space for the child indirect sections */ |
2285 | 0 | if (NULL == (sect->u.indirect.indir_ents = (H5HF_free_section_t **)H5MM_malloc( |
2286 | 0 | sizeof(H5HF_free_section_t *) * sect->u.indirect.indir_nents))) |
2287 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_NOSPACE, FAIL, "allocation failed for indirect section pointer array"); |
2288 | 0 | } /* end if */ |
2289 | 0 | else { |
2290 | | /* No indirect block entries covered, reset indirect row information */ |
2291 | 0 | sect->u.indirect.indir_nents = 0; |
2292 | 0 | } /* end else */ |
2293 | | |
2294 | | /* Set up initial row information */ |
2295 | 0 | if (start_row == end_row) |
2296 | 0 | row_entries = (end_col - start_col) + 1; |
2297 | 0 | else |
2298 | 0 | row_entries = hdr->man_dtable.cparam.width - start_col; |
2299 | 0 | row_col = start_col; |
2300 | | |
2301 | | /* Loop over creating the sections covered by this indirect section */ |
2302 | 0 | curr_off = sect->sect_info.addr; |
2303 | 0 | curr_entry = (start_row * hdr->man_dtable.cparam.width) + start_col; |
2304 | 0 | curr_row = 0; |
2305 | 0 | curr_indir_entry = 0; |
2306 | 0 | dblock_overhead = H5HF_MAN_ABS_DIRECT_OVERHEAD(hdr); |
2307 | 0 | for (u = start_row; u <= end_row; u++, curr_row++) { |
2308 | 0 | if (u < hdr->man_dtable.max_direct_rows) { |
2309 | 0 | H5HF_free_section_t *row_sect = NULL; /* 'Row' free space section to add */ |
2310 | | |
2311 | | /* Create 'row' free space section node */ |
2312 | 0 | if (NULL == (row_sect = H5HF__sect_row_create( |
2313 | 0 | curr_off, (hdr->man_dtable.row_block_size[u] - dblock_overhead), first_child, u, |
2314 | 0 | row_col, row_entries, sect))) |
2315 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTCREATE, FAIL, "creation failed for child row section"); |
2316 | | |
2317 | | /* Add new row section to array for indirect section */ |
2318 | 0 | sect->u.indirect.dir_rows[curr_row] = row_sect; |
2319 | | |
2320 | | /* Check to see if we should grab the first row section instead of adding it immediately */ |
2321 | 0 | if (first_row_sect) |
2322 | 0 | *first_row_sect = row_sect; |
2323 | 0 | else |
2324 | | /* Add new row section to free space manager for the heap */ |
2325 | 0 | if (H5HF__space_add(hdr, row_sect, space_flags) < 0) |
2326 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "can't add row section to free space"); |
2327 | | |
2328 | | /* Increment reference count for underlying indirect section */ |
2329 | 0 | sect->u.indirect.rc++; |
2330 | | |
2331 | | /* Advance the offset to the next section */ |
2332 | 0 | curr_off += row_entries * hdr->man_dtable.row_block_size[u]; |
2333 | | |
2334 | | /* Advance the current entry to the next row*/ |
2335 | 0 | curr_entry += row_entries; |
2336 | | |
2337 | | /* Reset the 'first child' parameters */ |
2338 | 0 | first_child = false; |
2339 | 0 | first_row_sect = NULL; |
2340 | 0 | } /* end if */ |
2341 | 0 | else { |
2342 | 0 | H5HF_indirect_t *child_iblock; /* Child indirect block */ |
2343 | 0 | H5HF_free_section_t *child_sect; /* Child 'indirect' section to add */ |
2344 | 0 | unsigned child_nrows; /* Number of child rows in indirect blocks for this row */ |
2345 | 0 | unsigned child_nentries; /* Number of child entries in indirect blocks for this row */ |
2346 | 0 | unsigned v; /* Local index variable */ |
2347 | | |
2348 | | /* Compute info about row's indirect blocks for child section */ |
2349 | 0 | child_nrows = H5HF__dtable_size_to_rows(&hdr->man_dtable, hdr->man_dtable.row_block_size[u]); |
2350 | 0 | child_nentries = child_nrows * hdr->man_dtable.cparam.width; |
2351 | | |
2352 | | /* Add an indirect section for each indirect block in the row */ |
2353 | 0 | for (v = 0; v < row_entries; v++) { |
2354 | 0 | bool did_protect = false; /* Whether we protected the indirect block or not */ |
2355 | | |
2356 | | /* Try to get the child section's indirect block, if it's available */ |
2357 | 0 | if (sect->sect_info.state == H5FS_SECT_LIVE) { |
2358 | 0 | haddr_t child_iblock_addr; /* Child indirect block's address on disk */ |
2359 | | |
2360 | | /* Get the address of the child indirect block */ |
2361 | 0 | if (H5HF__man_iblock_entry_addr(sect->u.indirect.u.iblock, curr_entry, |
2362 | 0 | &child_iblock_addr) < 0) |
2363 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTGET, FAIL, |
2364 | 0 | "unable to retrieve child indirect block's address"); |
2365 | | |
2366 | | /* If the child indirect block's address is defined, protect it */ |
2367 | 0 | if (H5_addr_defined(child_iblock_addr)) { |
2368 | 0 | if (NULL == (child_iblock = H5HF__man_iblock_protect( |
2369 | 0 | hdr, child_iblock_addr, child_nrows, sect->u.indirect.u.iblock, |
2370 | 0 | curr_entry, false, H5AC__NO_FLAGS_SET, &did_protect))) |
2371 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTPROTECT, FAIL, |
2372 | 0 | "unable to protect fractal heap indirect block"); |
2373 | 0 | } /* end if */ |
2374 | 0 | else |
2375 | 0 | child_iblock = NULL; |
2376 | 0 | } /* end if */ |
2377 | 0 | else |
2378 | 0 | child_iblock = NULL; |
2379 | | |
2380 | | /* Create free space section node */ |
2381 | 0 | if (NULL == (child_sect = H5HF__sect_indirect_new(hdr, curr_off, (hsize_t)0, child_iblock, |
2382 | 0 | curr_off, 0, 0, child_nentries))) |
2383 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "can't create indirect section"); |
2384 | | |
2385 | | /* Initialize rows for new indirect section */ |
2386 | 0 | if (H5HF__sect_indirect_init_rows(hdr, child_sect, first_child, first_row_sect, space_flags, |
2387 | 0 | 0, 0, (child_nrows - 1), |
2388 | 0 | (hdr->man_dtable.cparam.width - 1)) < 0) |
2389 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "can't initialize indirect section"); |
2390 | | |
2391 | | /* If we have a valid child indirect block, release it now */ |
2392 | | /* (will be pinned, if rows reference it) */ |
2393 | 0 | if (child_iblock) |
2394 | 0 | if (H5HF__man_iblock_unprotect(child_iblock, H5AC__NO_FLAGS_SET, did_protect) < 0) |
2395 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTUNPROTECT, FAIL, |
2396 | 0 | "unable to release fractal heap indirect block"); |
2397 | | |
2398 | | /* Attach child section to this section */ |
2399 | 0 | child_sect->u.indirect.parent = sect; |
2400 | 0 | child_sect->u.indirect.par_entry = curr_entry; |
2401 | 0 | sect->u.indirect.indir_ents[curr_indir_entry] = child_sect; |
2402 | 0 | sect->u.indirect.rc++; |
2403 | | |
2404 | | /* Advance the offset for the next section */ |
2405 | 0 | curr_off += hdr->man_dtable.row_block_size[u]; |
2406 | | |
2407 | | /* Advance to the next entry */ |
2408 | 0 | curr_entry++; |
2409 | 0 | curr_indir_entry++; |
2410 | | |
2411 | | /* Reset the 'first child' parameters */ |
2412 | 0 | first_child = false; |
2413 | 0 | first_row_sect = NULL; |
2414 | 0 | } /* end for */ |
2415 | 0 | } /* end else */ |
2416 | | |
2417 | | /* Compute the # of entries for the next row */ |
2418 | 0 | if (u < (end_row - 1)) |
2419 | 0 | row_entries = hdr->man_dtable.cparam.width; |
2420 | 0 | else |
2421 | 0 | row_entries = end_col + 1; |
2422 | | |
2423 | | /* Reset column for all other rows */ |
2424 | 0 | row_col = 0; |
2425 | 0 | } /* end for */ |
2426 | | |
2427 | | /* Set the final # of direct rows in section */ |
2428 | 0 | sect->u.indirect.dir_nrows = dir_nrows; |
2429 | | |
2430 | | /* Make certain we've tracked the section's dependents correctly */ |
2431 | 0 | assert(sect->u.indirect.rc == (sect->u.indirect.indir_nents + sect->u.indirect.dir_nrows)); |
2432 | |
|
2433 | 0 | done: |
2434 | 0 | if (ret_value < 0) { |
2435 | 0 | if (sect->u.indirect.indir_ents) |
2436 | 0 | H5MM_xfree(sect->u.indirect.indir_ents); |
2437 | 0 | if (sect->u.indirect.dir_rows) |
2438 | 0 | H5MM_xfree(sect->u.indirect.dir_rows); |
2439 | 0 | } /* end if */ |
2440 | |
|
2441 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
2442 | 0 | } /* end H5HF__sect_indirect_init_rows() */ |
2443 | | |
2444 | | /*------------------------------------------------------------------------- |
2445 | | * Function: H5HF__sect_indirect_add |
2446 | | * |
2447 | | * Purpose: Add a new 'indirect' section to the free space manager for this |
2448 | | * heap |
2449 | | * |
2450 | | * Return: Non-negative on success/Negative on failure |
2451 | | * |
2452 | | *------------------------------------------------------------------------- |
2453 | | */ |
2454 | | herr_t |
2455 | | H5HF__sect_indirect_add(H5HF_hdr_t *hdr, H5HF_indirect_t *iblock, unsigned start_entry, unsigned nentries) |
2456 | 0 | { |
2457 | 0 | H5HF_free_section_t *sect = NULL; /* 'Indirect' free space section to add */ |
2458 | 0 | H5HF_free_section_t *first_row_sect = NULL; /* First row section in new indirect section */ |
2459 | 0 | hsize_t sect_off; /* Offset of section in heap space */ |
2460 | 0 | unsigned start_row; /* Start row in indirect block */ |
2461 | 0 | unsigned start_col; /* Start column in indirect block */ |
2462 | 0 | unsigned end_entry; /* End entry in indirect block */ |
2463 | 0 | unsigned end_row; /* End row in indirect block */ |
2464 | 0 | unsigned end_col; /* End column in indirect block */ |
2465 | 0 | unsigned u; /* Local index variable */ |
2466 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
2467 | |
|
2468 | 0 | FUNC_ENTER_PACKAGE |
2469 | | |
2470 | | /* |
2471 | | * Check arguments. |
2472 | | */ |
2473 | 0 | assert(hdr); |
2474 | 0 | assert(iblock); |
2475 | 0 | assert(nentries); |
2476 | | |
2477 | | /* Compute starting column & row */ |
2478 | 0 | start_row = start_entry / hdr->man_dtable.cparam.width; |
2479 | 0 | start_col = start_entry % hdr->man_dtable.cparam.width; |
2480 | | |
2481 | | /* Compute end column & row */ |
2482 | 0 | end_entry = (start_entry + nentries) - 1; |
2483 | 0 | end_row = end_entry / hdr->man_dtable.cparam.width; |
2484 | 0 | end_col = end_entry % hdr->man_dtable.cparam.width; |
2485 | | |
2486 | | /* Initialize information for rows skipped over */ |
2487 | 0 | sect_off = iblock->block_off; |
2488 | 0 | for (u = 0; u < start_row; u++) |
2489 | 0 | sect_off += hdr->man_dtable.row_block_size[u] * hdr->man_dtable.cparam.width; |
2490 | 0 | sect_off += hdr->man_dtable.row_block_size[start_row] * start_col; |
2491 | | |
2492 | | /* Create free space section node */ |
2493 | 0 | if (NULL == (sect = H5HF__sect_indirect_new(hdr, sect_off, (hsize_t)0, iblock, iblock->block_off, |
2494 | 0 | start_row, start_col, nentries))) |
2495 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "can't create indirect section"); |
2496 | | |
2497 | | /* Initialize rows for new indirect section */ |
2498 | 0 | if (H5HF__sect_indirect_init_rows(hdr, sect, true, &first_row_sect, H5FS_ADD_SKIP_VALID, start_row, |
2499 | 0 | start_col, end_row, end_col) < 0) |
2500 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "can't initialize indirect section"); |
2501 | 0 | assert(first_row_sect); |
2502 | | |
2503 | | /* Now that underlying indirect section is consistent, add first row |
2504 | | * section to free space manager for the heap |
2505 | | */ |
2506 | 0 | if (H5HF__space_add(hdr, first_row_sect, H5FS_ADD_RETURNED_SPACE) < 0) |
2507 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "can't add row section to free space"); |
2508 | | |
2509 | 0 | done: |
2510 | 0 | if (ret_value < 0 && sect) |
2511 | 0 | if (H5HF__sect_indirect_free(sect) < 0) |
2512 | 0 | HDONE_ERROR(H5E_HEAP, H5E_CANTRELEASE, FAIL, "can't free indirect section node"); |
2513 | |
|
2514 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
2515 | 0 | } /* end H5HF__sect_indirect_add() */ |
2516 | | |
2517 | | /*------------------------------------------------------------------------- |
2518 | | * Function: H5HF__sect_indirect_decr |
2519 | | * |
2520 | | * Purpose: Decrement ref. count on indirect section |
2521 | | * |
2522 | | * Return: Non-negative on success/Negative on failure |
2523 | | * |
2524 | | *------------------------------------------------------------------------- |
2525 | | */ |
2526 | | static herr_t |
2527 | | H5HF__sect_indirect_decr(H5HF_free_section_t *sect) |
2528 | 0 | { |
2529 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
2530 | |
|
2531 | 0 | FUNC_ENTER_PACKAGE |
2532 | | |
2533 | | /* |
2534 | | * Check arguments. |
2535 | | */ |
2536 | 0 | assert(sect); |
2537 | 0 | assert(sect->u.indirect.rc); |
2538 | | |
2539 | | /* Decrement ref. count for indirect section */ |
2540 | 0 | sect->u.indirect.rc--; |
2541 | | |
2542 | | /* If the indirect section's ref. count drops to zero, free the section */ |
2543 | 0 | if (sect->u.indirect.rc == 0) { |
2544 | 0 | H5HF_free_section_t *par_sect; /* Parent indirect section */ |
2545 | | |
2546 | | /* Preserve pointer to parent indirect section when freeing this section */ |
2547 | 0 | par_sect = sect->u.indirect.parent; |
2548 | | |
2549 | | /* Free indirect section */ |
2550 | 0 | if (H5HF__sect_indirect_free(sect) < 0) |
2551 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTRELEASE, FAIL, "can't free indirect section node"); |
2552 | | |
2553 | | /* Decrement ref. count on indirect section's parent */ |
2554 | 0 | if (par_sect) |
2555 | 0 | if (H5HF__sect_indirect_decr(par_sect) < 0) |
2556 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTRELEASE, FAIL, |
2557 | 0 | "can't decrement ref. count on parent indirect section"); |
2558 | 0 | } /* end if */ |
2559 | | |
2560 | 0 | done: |
2561 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
2562 | 0 | } /* end H5HF__sect_indirect_decr() */ |
2563 | | |
2564 | | /*------------------------------------------------------------------------- |
2565 | | * Function: H5HF__sect_indirect_revive_row |
2566 | | * |
2567 | | * Purpose: Update the memory information for a 'indirect' free section |
2568 | | * |
2569 | | * Return: Non-negative on success/Negative on failure |
2570 | | * |
2571 | | *------------------------------------------------------------------------- |
2572 | | */ |
2573 | | static herr_t |
2574 | | H5HF__sect_indirect_revive_row(H5HF_hdr_t *hdr, H5HF_free_section_t *sect) |
2575 | 0 | { |
2576 | 0 | H5HF_indirect_t *sec_iblock; /* Pointer to section indirect block */ |
2577 | 0 | bool did_protect; /* Whether we protected the indirect block or not */ |
2578 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
2579 | |
|
2580 | 0 | FUNC_ENTER_PACKAGE |
2581 | | |
2582 | | /* |
2583 | | * Check arguments. |
2584 | | */ |
2585 | 0 | assert(hdr); |
2586 | 0 | assert(sect); |
2587 | 0 | assert(sect->sect_info.state == H5FS_SECT_SERIALIZED); |
2588 | | |
2589 | | /* Look up indirect block containing indirect blocks for section */ |
2590 | 0 | if (H5HF__man_dblock_locate(hdr, sect->sect_info.addr, &sec_iblock, NULL, &did_protect, |
2591 | 0 | H5AC__READ_ONLY_FLAG) < 0) |
2592 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTCOMPUTE, FAIL, "can't compute row & column of section"); |
2593 | | |
2594 | | /* Review the section */ |
2595 | 0 | if (H5HF__sect_indirect_revive(hdr, sect, sec_iblock) < 0) |
2596 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTREVIVE, FAIL, "can't revive indirect section"); |
2597 | | |
2598 | 0 | done: |
2599 | | /* Unlock indirect block */ |
2600 | 0 | if (sec_iblock && H5HF__man_iblock_unprotect(sec_iblock, H5AC__NO_FLAGS_SET, did_protect) < 0) |
2601 | 0 | HDONE_ERROR(H5E_HEAP, H5E_CANTUNPROTECT, FAIL, "unable to release fractal heap indirect block"); |
2602 | |
|
2603 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
2604 | 0 | } /* end H5HF__sect_indirect_revive_row() */ |
2605 | | |
2606 | | /*------------------------------------------------------------------------- |
2607 | | * Function: H5HF__sect_indirect_revive |
2608 | | * |
2609 | | * Purpose: Update the memory information for a 'indirect' free section |
2610 | | * |
2611 | | * Return: Non-negative on success/Negative on failure |
2612 | | * |
2613 | | *------------------------------------------------------------------------- |
2614 | | */ |
2615 | | static herr_t |
2616 | | H5HF__sect_indirect_revive(H5HF_hdr_t *hdr, H5HF_free_section_t *sect, H5HF_indirect_t *sect_iblock) |
2617 | 0 | { |
2618 | 0 | unsigned u; /* Local index variable */ |
2619 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
2620 | |
|
2621 | 0 | FUNC_ENTER_PACKAGE |
2622 | | |
2623 | | /* |
2624 | | * Check arguments. |
2625 | | */ |
2626 | 0 | assert(hdr); |
2627 | 0 | assert(sect); |
2628 | 0 | assert(sect->sect_info.state == H5FS_SECT_SERIALIZED); |
2629 | 0 | assert(sect_iblock); |
2630 | | |
2631 | | /* Increment reference count on indirect block that free section is in */ |
2632 | 0 | if (H5HF__iblock_incr(sect_iblock) < 0) |
2633 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTDEC, FAIL, "can't decrement reference count on shared indirect block"); |
2634 | | |
2635 | | /* Set the pointer to the section's indirect block */ |
2636 | 0 | sect->u.indirect.u.iblock = sect_iblock; |
2637 | | |
2638 | | /* Set the number of entries in the indirect block */ |
2639 | 0 | sect->u.indirect.iblock_entries = hdr->man_dtable.cparam.width * sect->u.indirect.u.iblock->max_rows; |
2640 | | |
2641 | | /* Section is "live" now */ |
2642 | 0 | sect->sect_info.state = H5FS_SECT_LIVE; |
2643 | | |
2644 | | /* Loop over derived row sections and mark them all as 'live' now */ |
2645 | 0 | for (u = 0; u < sect->u.indirect.dir_nrows; u++) |
2646 | 0 | sect->u.indirect.dir_rows[u]->sect_info.state = H5FS_SECT_LIVE; |
2647 | | |
2648 | | /* Revive parent indirect section, if there is one */ |
2649 | 0 | if (sect->u.indirect.parent && sect->u.indirect.parent->sect_info.state == H5FS_SECT_SERIALIZED) |
2650 | 0 | if (H5HF__sect_indirect_revive(hdr, sect->u.indirect.parent, sect->u.indirect.u.iblock->parent) < 0) |
2651 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTREVIVE, FAIL, "can't revive indirect section"); |
2652 | | |
2653 | 0 | done: |
2654 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
2655 | 0 | } /* end H5HF__sect_indirect_revive() */ |
2656 | | |
2657 | | /*------------------------------------------------------------------------- |
2658 | | * Function: H5HF__sect_indirect_reduce_row |
2659 | | * |
2660 | | * Purpose: Remove a block from an indirect section (possibly freeing it) |
2661 | | * and re-add it back to the free space manager for the heap |
2662 | | * (if it hasn't been freed) |
2663 | | * |
2664 | | * Return: Non-negative on success/Negative on failure |
2665 | | * |
2666 | | *------------------------------------------------------------------------- |
2667 | | */ |
2668 | | static herr_t |
2669 | | H5HF__sect_indirect_reduce_row(H5HF_hdr_t *hdr, H5HF_free_section_t *row_sect, bool *alloc_from_start) |
2670 | 0 | { |
2671 | 0 | H5HF_free_section_t *sect; /* Indirect section underlying row section */ |
2672 | 0 | unsigned row_start_entry; /* Entry for first block covered in row section */ |
2673 | 0 | unsigned row_end_entry; /* Entry for last block covered in row section */ |
2674 | 0 | unsigned row_entry; /* Entry to allocate in row section */ |
2675 | 0 | unsigned start_entry; /* Entry for first block covered */ |
2676 | 0 | unsigned start_row; /* Start row in indirect block */ |
2677 | 0 | unsigned start_col; /* Start column in indirect block */ |
2678 | 0 | unsigned end_entry; /* Entry for last block covered */ |
2679 | 0 | unsigned end_row; /* End row in indirect block */ |
2680 | 0 | H5HF_free_section_t *peer_sect = NULL; /* Peer indirect section */ |
2681 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
2682 | |
|
2683 | 0 | FUNC_ENTER_PACKAGE |
2684 | | |
2685 | | /* |
2686 | | * Check arguments. |
2687 | | */ |
2688 | 0 | assert(hdr); |
2689 | 0 | assert(row_sect); |
2690 | | |
2691 | | /* Compute starting & ending information for row section */ |
2692 | 0 | row_start_entry = (row_sect->u.row.row * hdr->man_dtable.cparam.width) + row_sect->u.row.col; |
2693 | 0 | row_end_entry = (row_start_entry + row_sect->u.row.num_entries) - 1; |
2694 | | |
2695 | | /* Compute starting & ending information for indirect section */ |
2696 | 0 | sect = row_sect->u.row.under; |
2697 | 0 | start_row = sect->u.indirect.row; |
2698 | 0 | start_col = sect->u.indirect.col; |
2699 | 0 | start_entry = (start_row * hdr->man_dtable.cparam.width) + start_col; |
2700 | 0 | end_entry = (start_entry + sect->u.indirect.num_entries) - 1; |
2701 | 0 | end_row = end_entry / hdr->man_dtable.cparam.width; |
2702 | | |
2703 | | /* Additional sanity check */ |
2704 | 0 | assert(sect->u.indirect.span_size > 0); |
2705 | 0 | assert(sect->u.indirect.iblock_entries > 0); |
2706 | 0 | assert(sect->u.indirect.dir_nrows > 0); |
2707 | 0 | assert(sect->u.indirect.dir_rows); |
2708 | 0 | assert(sect->u.indirect.dir_rows[(row_sect->u.row.row - start_row)] == row_sect); |
2709 | | |
2710 | | /* Check if we should allocate from end of indirect section */ |
2711 | 0 | if (row_end_entry == end_entry && start_row != end_row) { |
2712 | 0 | *alloc_from_start = false; |
2713 | 0 | row_entry = row_end_entry; |
2714 | 0 | } /* end if */ |
2715 | 0 | else { |
2716 | 0 | *alloc_from_start = true; |
2717 | 0 | row_entry = row_start_entry; |
2718 | 0 | } /* end else */ |
2719 | | |
2720 | | /* Check if we have a parent section to be detached from */ |
2721 | 0 | if (sect->u.indirect.parent) { |
2722 | 0 | bool is_first; /* Flag to indicate that this section is the first section in hierarchy */ |
2723 | | |
2724 | | /* Check if this section is the first section */ |
2725 | 0 | is_first = H5HF__sect_indirect_is_first(sect); |
2726 | | |
2727 | | /* Remove this indirect section from parent indirect section */ |
2728 | 0 | if (H5HF__sect_indirect_reduce(hdr, sect->u.indirect.parent, sect->u.indirect.par_entry) < 0) |
2729 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTSHRINK, FAIL, "can't reduce parent indirect section"); |
2730 | 0 | sect->u.indirect.parent = NULL; |
2731 | 0 | sect->u.indirect.par_entry = 0; |
2732 | | |
2733 | | /* If we weren't the first section, set "first row" for this indirect section */ |
2734 | 0 | if (!is_first) |
2735 | 0 | if (H5HF__sect_indirect_first(hdr, sect) < 0) |
2736 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "can't make new 'first row' for indirect section"); |
2737 | 0 | } /* end if */ |
2738 | | |
2739 | | /* Adjust indirect section's span size */ |
2740 | 0 | sect->u.indirect.span_size -= row_sect->sect_info.size; |
2741 | | |
2742 | | /* Check how to adjust section for allocated entry */ |
2743 | 0 | if (sect->u.indirect.num_entries > 1) { |
2744 | 0 | if (row_entry == start_entry) { |
2745 | | /* Adjust section start */ |
2746 | 0 | sect->sect_info.addr += hdr->man_dtable.row_block_size[sect->u.indirect.row]; |
2747 | | |
2748 | | /* Adjust block coordinates of span */ |
2749 | 0 | sect->u.indirect.col++; |
2750 | 0 | if (sect->u.indirect.col == hdr->man_dtable.cparam.width) { |
2751 | 0 | assert(row_sect->u.row.num_entries == 1); |
2752 | | |
2753 | | /* Adjust section's span information */ |
2754 | 0 | sect->u.indirect.row++; |
2755 | 0 | sect->u.indirect.col = 0; |
2756 | | |
2757 | | /* Adjust direct row information */ |
2758 | 0 | sect->u.indirect.dir_nrows--; |
2759 | | |
2760 | | /* Adjust direct row sections for indirect section */ |
2761 | 0 | if (sect->u.indirect.dir_nrows > 0) { |
2762 | 0 | assert(sect->u.indirect.dir_rows); |
2763 | 0 | memmove(§->u.indirect.dir_rows[0], §->u.indirect.dir_rows[1], |
2764 | 0 | sect->u.indirect.dir_nrows * sizeof(H5HF_free_section_t *)); |
2765 | 0 | assert(sect->u.indirect.dir_rows[0]); |
2766 | | |
2767 | | /* Make new "first row" in indirect section */ |
2768 | 0 | if (row_sect->sect_info.type == H5HF_FSPACE_SECT_FIRST_ROW) |
2769 | 0 | if (H5HF__sect_row_first(hdr, sect->u.indirect.dir_rows[0]) < 0) |
2770 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, |
2771 | 0 | "can't make new 'first row' for indirect section"); |
2772 | 0 | } /* end if */ |
2773 | 0 | else { |
2774 | | /* Sanity check */ |
2775 | 0 | assert(sect->u.indirect.indir_nents > 0); |
2776 | 0 | assert(sect->u.indirect.indir_ents); |
2777 | | |
2778 | | /* Eliminate direct rows for this section */ |
2779 | 0 | sect->u.indirect.dir_rows = (H5HF_free_section_t **)H5MM_xfree(sect->u.indirect.dir_rows); |
2780 | | |
2781 | | /* Make new "first row" in indirect section */ |
2782 | 0 | if (row_sect->sect_info.type == H5HF_FSPACE_SECT_FIRST_ROW) |
2783 | 0 | if (H5HF__sect_indirect_first(hdr, sect->u.indirect.indir_ents[0]) < 0) |
2784 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, |
2785 | 0 | "can't make new 'first row' for child indirect section"); |
2786 | 0 | } /* end else */ |
2787 | 0 | } /* end if */ |
2788 | | |
2789 | | /* Adjust number of entries covered */ |
2790 | 0 | sect->u.indirect.num_entries--; |
2791 | 0 | } /* end if */ |
2792 | 0 | else if (row_entry == end_entry) { |
2793 | 0 | unsigned new_end_row; /* New end row for entries */ |
2794 | | |
2795 | | /* Sanity check */ |
2796 | 0 | assert(sect->u.indirect.indir_nents == 0); |
2797 | 0 | assert(sect->u.indirect.indir_ents == NULL); |
2798 | | |
2799 | | /* Adjust number of entries covered */ |
2800 | 0 | sect->u.indirect.num_entries--; |
2801 | | |
2802 | | /* Check for eliminating a direct row */ |
2803 | 0 | new_end_row = ((start_entry + sect->u.indirect.num_entries) - 1) / hdr->man_dtable.cparam.width; |
2804 | 0 | assert(new_end_row <= end_row); |
2805 | 0 | if (new_end_row < end_row) { |
2806 | 0 | assert(new_end_row == (end_row - 1)); |
2807 | 0 | sect->u.indirect.dir_nrows--; |
2808 | 0 | } /* end if */ |
2809 | 0 | } /* end if */ |
2810 | 0 | else { |
2811 | 0 | H5HF_indirect_t *iblock; /* Pointer to indirect block for this section */ |
2812 | 0 | hsize_t iblock_off; /* Section's indirect block's offset in "heap space" */ |
2813 | 0 | unsigned peer_nentries; /* Number of entries in new peer indirect section */ |
2814 | 0 | unsigned peer_dir_nrows; /* Number of direct rows in new peer indirect section */ |
2815 | 0 | unsigned new_start_row; /* New starting row for current indirect section */ |
2816 | 0 | unsigned u; /* Local index variable */ |
2817 | | |
2818 | | /* Sanity checks */ |
2819 | 0 | assert(row_sect->u.row.col == 0); |
2820 | 0 | assert(row_sect->u.row.row > 0); |
2821 | 0 | assert(row_sect->u.row.row < hdr->man_dtable.max_direct_rows); |
2822 | 0 | assert(row_sect->u.row.num_entries == hdr->man_dtable.cparam.width); |
2823 | 0 | assert(row_sect->sect_info.type == H5HF_FSPACE_SECT_NORMAL_ROW); |
2824 | | |
2825 | | /* Compute basic information about peer & current indirect sections */ |
2826 | 0 | new_start_row = row_sect->u.row.row; |
2827 | 0 | peer_nentries = row_entry - start_entry; |
2828 | 0 | peer_dir_nrows = new_start_row - start_row; |
2829 | | |
2830 | | /* Get indirect block information for peer */ |
2831 | 0 | if (sect->sect_info.state == H5FS_SECT_LIVE) { |
2832 | 0 | iblock = sect->u.indirect.u.iblock; |
2833 | 0 | iblock_off = sect->u.indirect.u.iblock->block_off; |
2834 | 0 | } /* end if */ |
2835 | 0 | else { |
2836 | 0 | iblock = NULL; |
2837 | 0 | iblock_off = sect->u.indirect.u.iblock_off; |
2838 | 0 | } /* end else */ |
2839 | | |
2840 | | /* Create peer indirect section */ |
2841 | 0 | if (NULL == |
2842 | 0 | (peer_sect = H5HF__sect_indirect_new(hdr, sect->sect_info.addr, sect->sect_info.size, iblock, |
2843 | 0 | iblock_off, start_row, start_col, peer_nentries))) |
2844 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "can't create indirect section"); |
2845 | | |
2846 | | /* Set up direct row & indirect entry information for peer section */ |
2847 | 0 | peer_sect->u.indirect.indir_nents = 0; |
2848 | 0 | peer_sect->u.indirect.indir_ents = NULL; |
2849 | 0 | peer_sect->u.indirect.dir_nrows = peer_dir_nrows; |
2850 | 0 | if (NULL == (peer_sect->u.indirect.dir_rows = (H5HF_free_section_t **)H5MM_malloc( |
2851 | 0 | sizeof(H5HF_free_section_t *) * peer_dir_nrows))) |
2852 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, FAIL, "allocation failed for row section pointer array"); |
2853 | | |
2854 | | /* Transfer row sections between current & peer sections */ |
2855 | 0 | H5MM_memcpy(&peer_sect->u.indirect.dir_rows[0], §->u.indirect.dir_rows[0], |
2856 | 0 | (sizeof(H5HF_free_section_t *) * peer_dir_nrows)); |
2857 | 0 | memmove(§->u.indirect.dir_rows[0], §->u.indirect.dir_rows[peer_dir_nrows], |
2858 | 0 | (sizeof(H5HF_free_section_t *) * (sect->u.indirect.dir_nrows - peer_dir_nrows))); |
2859 | 0 | sect->u.indirect.dir_nrows -= peer_dir_nrows; |
2860 | 0 | assert(row_sect == sect->u.indirect.dir_rows[0]); |
2861 | | |
2862 | | /* Re-target transferred row sections to point to new underlying indirect section */ |
2863 | 0 | for (u = 0; u < peer_dir_nrows; u++) |
2864 | 0 | peer_sect->u.indirect.dir_rows[u]->u.row.under = peer_sect; |
2865 | | |
2866 | | /* Change first row section in indirect section to be the "first row" */ |
2867 | | /* (But we don't have to tell the free space manager about it, |
2868 | | * because the row section is "checked out" from the free space |
2869 | | * manager currently. |
2870 | | */ |
2871 | 0 | row_sect->sect_info.type = H5HF_FSPACE_SECT_FIRST_ROW; |
2872 | | |
2873 | | /* Adjust reference counts for current & peer sections */ |
2874 | 0 | peer_sect->u.indirect.rc = peer_dir_nrows; |
2875 | 0 | sect->u.indirect.rc -= peer_dir_nrows; |
2876 | | |
2877 | | /* Transfer/update cached information about indirect block */ |
2878 | 0 | peer_sect->u.indirect.iblock_entries = sect->u.indirect.iblock_entries; |
2879 | 0 | peer_sect->u.indirect.span_size = row_sect->sect_info.addr - peer_sect->sect_info.addr; |
2880 | | |
2881 | | /* Update information for current section */ |
2882 | 0 | sect->sect_info.addr = row_sect->sect_info.addr + hdr->man_dtable.row_block_size[new_start_row]; |
2883 | 0 | sect->u.indirect.span_size -= |
2884 | 0 | peer_sect->u.indirect.span_size; /* (span for row section has already been removed) */ |
2885 | 0 | sect->u.indirect.row = new_start_row; |
2886 | 0 | sect->u.indirect.col = row_sect->u.row.col + 1; |
2887 | 0 | sect->u.indirect.num_entries -= |
2888 | 0 | (peer_nentries + 1); /* Transferred entries, plus the entry allocated out of the row */ |
2889 | | |
2890 | | /* Make certain we've tracked the sections' dependents correctly */ |
2891 | 0 | assert(sect->u.indirect.rc == (sect->u.indirect.indir_nents + sect->u.indirect.dir_nrows)); |
2892 | 0 | assert(peer_sect->u.indirect.rc == |
2893 | 0 | (peer_sect->u.indirect.indir_nents + peer_sect->u.indirect.dir_nrows)); |
2894 | | |
2895 | | /* Reset the peer_sect variable, to indicate that it has been hooked into the data structures |
2896 | | * correctly and shouldn't be freed */ |
2897 | 0 | peer_sect = NULL; |
2898 | 0 | } /* end else */ |
2899 | 0 | } /* end if */ |
2900 | 0 | else { |
2901 | | /* Decrement count of entries & rows */ |
2902 | 0 | sect->u.indirect.num_entries--; |
2903 | 0 | sect->u.indirect.dir_nrows--; |
2904 | 0 | assert(sect->u.indirect.dir_nrows == 0); |
2905 | | |
2906 | | /* Eliminate direct rows for this section */ |
2907 | 0 | sect->u.indirect.dir_rows = (H5HF_free_section_t **)H5MM_xfree(sect->u.indirect.dir_rows); |
2908 | 0 | } /* end else */ |
2909 | | |
2910 | 0 | done: |
2911 | | /* Free allocated peer_sect. Note that this is necessary for all failures until peer_sect is linked |
2912 | | * into the main free space structures (via the direct blocks), and the reference count is updated. */ |
2913 | 0 | if (peer_sect) { |
2914 | | /* Sanity check - we should only be here if an error occurred */ |
2915 | 0 | assert(ret_value < 0); |
2916 | |
|
2917 | 0 | if (H5HF__sect_indirect_free(peer_sect) < 0) |
2918 | 0 | HDONE_ERROR(H5E_HEAP, H5E_CANTRELEASE, FAIL, "can't free indirect section node"); |
2919 | 0 | } /* end if */ |
2920 | |
|
2921 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
2922 | 0 | } /* end H5HF__sect_indirect_reduce_row() */ |
2923 | | |
2924 | | /*------------------------------------------------------------------------- |
2925 | | * Function: H5HF__sect_indirect_reduce |
2926 | | * |
2927 | | * Purpose: Reduce the size of a indirect section (possibly freeing it) |
2928 | | * and re-add it back to the free space manager for the heap |
2929 | | * (if it hasn't been freed) |
2930 | | * |
2931 | | * Return: Non-negative on success/Negative on failure |
2932 | | * |
2933 | | *------------------------------------------------------------------------- |
2934 | | */ |
2935 | | static herr_t |
2936 | | H5HF__sect_indirect_reduce(H5HF_hdr_t *hdr, H5HF_free_section_t *sect, unsigned child_entry) |
2937 | 0 | { |
2938 | 0 | unsigned start_entry; /* Entry for first block covered */ |
2939 | 0 | unsigned start_row; /* Start row in indirect block */ |
2940 | 0 | unsigned start_col; /* Start column in indirect block */ |
2941 | 0 | unsigned end_entry; /* Entry for last block covered */ |
2942 | 0 | unsigned end_row; /* End row in indirect block */ |
2943 | 0 | H5HF_free_section_t *peer_sect = NULL; /* Peer indirect section */ |
2944 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
2945 | |
|
2946 | 0 | FUNC_ENTER_PACKAGE |
2947 | | |
2948 | | /* |
2949 | | * Check arguments. |
2950 | | */ |
2951 | 0 | assert(hdr); |
2952 | 0 | assert(sect); |
2953 | 0 | assert(sect->u.indirect.span_size > 0); |
2954 | 0 | assert(sect->u.indirect.iblock_entries > 0); |
2955 | | |
2956 | | /* Compute starting & ending information for indirect section */ |
2957 | 0 | start_row = sect->u.indirect.row; |
2958 | 0 | start_col = sect->u.indirect.col; |
2959 | 0 | start_entry = (start_row * hdr->man_dtable.cparam.width) + start_col; |
2960 | 0 | end_entry = (start_entry + sect->u.indirect.num_entries) - 1; |
2961 | 0 | end_row = end_entry / hdr->man_dtable.cparam.width; |
2962 | | |
2963 | | /* Check how to adjust section for allocated entry */ |
2964 | 0 | if (sect->u.indirect.num_entries > 1) { |
2965 | | /* Check if we have a parent section to be detached from */ |
2966 | 0 | if (sect->u.indirect.parent) { |
2967 | 0 | bool is_first; /* Flag to indicate that this section is the first section in hierarchy */ |
2968 | | |
2969 | | /* Check if this section is the first section */ |
2970 | 0 | is_first = H5HF__sect_indirect_is_first(sect); |
2971 | | |
2972 | | /* Reduce parent indirect section */ |
2973 | 0 | if (H5HF__sect_indirect_reduce(hdr, sect->u.indirect.parent, sect->u.indirect.par_entry) < 0) |
2974 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTSHRINK, FAIL, "can't reduce parent indirect section"); |
2975 | 0 | sect->u.indirect.parent = NULL; |
2976 | 0 | sect->u.indirect.par_entry = 0; |
2977 | | |
2978 | | /* If we weren't the first section, set "first row" for this indirect section */ |
2979 | 0 | if (!is_first) |
2980 | 0 | if (H5HF__sect_indirect_first(hdr, sect) < 0) |
2981 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, |
2982 | 0 | "can't make new 'first row' for indirect section"); |
2983 | 0 | } /* end if */ |
2984 | | |
2985 | | /* Check if we can allocate from start of indirect section */ |
2986 | 0 | if (child_entry == start_entry) { |
2987 | | /* Sanity check */ |
2988 | 0 | assert(sect->u.indirect.dir_nrows == 0); |
2989 | 0 | assert(sect->u.indirect.dir_rows == NULL); |
2990 | 0 | assert(sect->u.indirect.indir_nents > 0); |
2991 | 0 | assert(sect->u.indirect.indir_ents); |
2992 | | |
2993 | | /* Adjust section start */ |
2994 | 0 | sect->sect_info.addr += hdr->man_dtable.row_block_size[start_row]; |
2995 | | |
2996 | | /* Adjust span of blocks covered */ |
2997 | 0 | sect->u.indirect.col++; |
2998 | 0 | if (sect->u.indirect.col == hdr->man_dtable.cparam.width) { |
2999 | 0 | sect->u.indirect.row++; |
3000 | 0 | sect->u.indirect.col = 0; |
3001 | 0 | } /* end if */ |
3002 | 0 | sect->u.indirect.num_entries--; |
3003 | 0 | sect->u.indirect.span_size -= hdr->man_dtable.row_block_size[start_row]; |
3004 | | |
3005 | | /* Adjust indirect entry information */ |
3006 | 0 | sect->u.indirect.indir_nents--; |
3007 | 0 | memmove(§->u.indirect.indir_ents[0], §->u.indirect.indir_ents[1], |
3008 | 0 | sect->u.indirect.indir_nents * sizeof(H5HF_free_section_t *)); |
3009 | 0 | assert(sect->u.indirect.indir_ents[0]); |
3010 | | |
3011 | | /* Make new "first row" in new first indirect child section */ |
3012 | 0 | if (H5HF__sect_indirect_first(hdr, sect->u.indirect.indir_ents[0]) < 0) |
3013 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, |
3014 | 0 | "can't make new 'first row' for child indirect section"); |
3015 | 0 | } /* end if */ |
3016 | 0 | else if (child_entry == end_entry) { |
3017 | | /* Sanity check */ |
3018 | 0 | assert(sect->u.indirect.indir_nents > 0); |
3019 | 0 | assert(sect->u.indirect.indir_ents); |
3020 | | |
3021 | | /* Adjust span of blocks covered */ |
3022 | 0 | sect->u.indirect.num_entries--; |
3023 | 0 | sect->u.indirect.span_size -= hdr->man_dtable.row_block_size[end_row]; |
3024 | | |
3025 | | /* Adjust indirect entry information */ |
3026 | 0 | sect->u.indirect.indir_nents--; |
3027 | 0 | if (sect->u.indirect.indir_nents == 0) |
3028 | 0 | sect->u.indirect.indir_ents = (H5HF_free_section_t **)H5MM_xfree(sect->u.indirect.indir_ents); |
3029 | 0 | } /* end if */ |
3030 | 0 | else { |
3031 | 0 | H5HF_indirect_t *iblock; /* Pointer to indirect block for this section */ |
3032 | 0 | hsize_t iblock_off; /* Section's indirect block's offset in "heap space" */ |
3033 | 0 | haddr_t peer_sect_addr; /* Address of new peer section in "heap space" */ |
3034 | 0 | unsigned peer_nentries; /* Number of entries in new peer indirect section */ |
3035 | 0 | unsigned peer_start_row; /* Starting row for new peer indirect section */ |
3036 | 0 | unsigned peer_start_col; /* Starting column for new peer indirect section */ |
3037 | 0 | unsigned child_row; /* Row where child entry is located */ |
3038 | 0 | unsigned new_nentries; /* New number of entries for current indirect section */ |
3039 | 0 | unsigned u; /* Local index variable */ |
3040 | | |
3041 | | /* Sanity check */ |
3042 | 0 | assert(sect->u.indirect.indir_nents > 0); |
3043 | 0 | assert(sect->u.indirect.indir_ents); |
3044 | | |
3045 | | /* Compute basic information about peer & current indirect sections */ |
3046 | 0 | peer_nentries = end_entry - child_entry; |
3047 | 0 | peer_start_row = (child_entry + 1) / hdr->man_dtable.cparam.width; |
3048 | 0 | peer_start_col = (child_entry + 1) % hdr->man_dtable.cparam.width; |
3049 | 0 | child_row = child_entry / hdr->man_dtable.cparam.width; |
3050 | 0 | new_nentries = sect->u.indirect.num_entries - (peer_nentries + 1); |
3051 | 0 | assert(child_row >= hdr->man_dtable.max_direct_rows); |
3052 | | |
3053 | | /* Get indirect block information for peer */ |
3054 | 0 | if (sect->sect_info.state == H5FS_SECT_LIVE) { |
3055 | 0 | iblock = sect->u.indirect.u.iblock; |
3056 | 0 | iblock_off = sect->u.indirect.u.iblock->block_off; |
3057 | 0 | } /* end if */ |
3058 | 0 | else { |
3059 | 0 | iblock = NULL; |
3060 | 0 | iblock_off = sect->u.indirect.u.iblock_off; |
3061 | 0 | } /* end else */ |
3062 | | |
3063 | | /* Update the number of entries in current section & calculate it's span size */ |
3064 | | /* (Will use this to compute the section address for the peer section */ |
3065 | 0 | sect->u.indirect.num_entries = new_nentries; |
3066 | 0 | sect->u.indirect.span_size = H5HF__dtable_span_size(&hdr->man_dtable, sect->u.indirect.row, |
3067 | 0 | sect->u.indirect.col, new_nentries); |
3068 | 0 | assert(sect->u.indirect.span_size > 0); |
3069 | | |
3070 | | /* Compute address of peer indirect section */ |
3071 | 0 | peer_sect_addr = sect->sect_info.addr; |
3072 | 0 | peer_sect_addr += sect->u.indirect.span_size; |
3073 | 0 | peer_sect_addr += hdr->man_dtable.row_block_size[child_row]; |
3074 | | |
3075 | | /* Create peer indirect section */ |
3076 | 0 | if (NULL == (peer_sect = H5HF__sect_indirect_new(hdr, peer_sect_addr, sect->sect_info.size, |
3077 | 0 | iblock, iblock_off, peer_start_row, |
3078 | 0 | peer_start_col, peer_nentries))) |
3079 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "can't create indirect section"); |
3080 | | |
3081 | | /* Set up direct row & indirect entry information for peer section */ |
3082 | 0 | peer_sect->u.indirect.dir_nrows = 0; |
3083 | 0 | peer_sect->u.indirect.dir_rows = NULL; |
3084 | 0 | peer_sect->u.indirect.indir_nents = peer_nentries; |
3085 | 0 | if (NULL == (peer_sect->u.indirect.indir_ents = (H5HF_free_section_t **)H5MM_malloc( |
3086 | 0 | sizeof(H5HF_free_section_t *) * peer_nentries))) |
3087 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTALLOC, FAIL, |
3088 | 0 | "allocation failed for indirect section pointer array"); |
3089 | | |
3090 | | /* Transfer child indirect sections between current & peer sections */ |
3091 | 0 | H5MM_memcpy(&peer_sect->u.indirect.indir_ents[0], |
3092 | 0 | §->u.indirect.indir_ents[sect->u.indirect.indir_nents - peer_nentries], |
3093 | 0 | (sizeof(H5HF_free_section_t *) * peer_nentries)); |
3094 | 0 | sect->u.indirect.indir_nents -= (peer_nentries + 1); /* Transferred blocks, plus child entry */ |
3095 | | |
3096 | | /* Eliminate indirect entries for this section, if appropriate */ |
3097 | 0 | if (sect->u.indirect.indir_nents == 0) |
3098 | 0 | sect->u.indirect.indir_ents = (H5HF_free_section_t **)H5MM_xfree(sect->u.indirect.indir_ents); |
3099 | | |
3100 | | /* Re-target transferred row sections to point to new underlying indirect section */ |
3101 | 0 | for (u = 0; u < peer_nentries; u++) |
3102 | 0 | peer_sect->u.indirect.indir_ents[u]->u.indirect.parent = peer_sect; |
3103 | | |
3104 | | /* Adjust reference counts for current & peer sections */ |
3105 | 0 | peer_sect->u.indirect.rc = peer_nentries; |
3106 | 0 | sect->u.indirect.rc -= peer_nentries; |
3107 | | |
3108 | | /* Transfer cached information about indirect block */ |
3109 | 0 | peer_sect->u.indirect.iblock_entries = sect->u.indirect.iblock_entries; |
3110 | | |
3111 | | /* Make certain we've tracked the sections' dependents correctly */ |
3112 | | /* (Note modified on current section's ref. count, since we haven't |
3113 | | * detached the child section yet) |
3114 | | */ |
3115 | 0 | assert((sect->u.indirect.rc - 1) == (sect->u.indirect.indir_nents + sect->u.indirect.dir_nrows)); |
3116 | 0 | assert(peer_sect->u.indirect.rc == |
3117 | 0 | (peer_sect->u.indirect.indir_nents + peer_sect->u.indirect.dir_nrows)); |
3118 | | |
3119 | | /* Make new "first row" in peer section */ |
3120 | 0 | if (H5HF__sect_indirect_first(hdr, peer_sect->u.indirect.indir_ents[0]) < 0) |
3121 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, |
3122 | 0 | "can't make new 'first row' for peer indirect section"); |
3123 | | |
3124 | | /* Reset the peer_sect variable, to indicate that it has been hooked into the data structures |
3125 | | * correctly and shouldn't be freed */ |
3126 | 0 | peer_sect = NULL; |
3127 | 0 | } /* end else */ |
3128 | 0 | } /* end if */ |
3129 | 0 | else { |
3130 | | /* Decrement count of entries & indirect entries */ |
3131 | 0 | sect->u.indirect.num_entries--; |
3132 | 0 | sect->u.indirect.indir_nents--; |
3133 | 0 | assert(sect->u.indirect.indir_nents == 0); |
3134 | | |
3135 | | /* Eliminate indirect entries for this section */ |
3136 | 0 | sect->u.indirect.indir_ents = (H5HF_free_section_t **)H5MM_xfree(sect->u.indirect.indir_ents); |
3137 | 0 | } /* end else */ |
3138 | | |
3139 | | /* Decrement # of sections which depend on this row */ |
3140 | | /* (Must be last as section can be freed) */ |
3141 | 0 | if (H5HF__sect_indirect_decr(sect) < 0) |
3142 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTRELEASE, FAIL, "can't decrement section's ref. count "); |
3143 | | |
3144 | 0 | done: |
3145 | | /* Free allocated peer_sect. Note that this is necessary for all failures until peer_sect is linked |
3146 | | * into the main free space structures (via the direct blocks), and the reference count is updated. */ |
3147 | 0 | if (peer_sect) { |
3148 | | /* Sanity check - we should only be here if an error occurred */ |
3149 | 0 | assert(ret_value < 0); |
3150 | |
|
3151 | 0 | if (H5HF__sect_indirect_free(peer_sect) < 0) |
3152 | 0 | HDONE_ERROR(H5E_HEAP, H5E_CANTRELEASE, FAIL, "can't free indirect section node"); |
3153 | 0 | } /* end if */ |
3154 | |
|
3155 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
3156 | 0 | } /* end H5HF__sect_indirect_reduce() */ |
3157 | | |
3158 | | /*------------------------------------------------------------------------- |
3159 | | * Function: H5HF__sect_indirect_is_first |
3160 | | * |
3161 | | * Purpose: Check if indirect section is first in all parents |
3162 | | * |
3163 | | * Return: Non-negative (true/false) on success/<can't fail> |
3164 | | * |
3165 | | *------------------------------------------------------------------------- |
3166 | | */ |
3167 | | static bool |
3168 | | H5HF__sect_indirect_is_first(H5HF_free_section_t *sect) |
3169 | 0 | { |
3170 | 0 | bool ret_value = false; /* Return value */ |
3171 | |
|
3172 | 0 | FUNC_ENTER_PACKAGE_NOERR |
3173 | | |
3174 | | /* Sanity check */ |
3175 | 0 | assert(sect); |
3176 | | |
3177 | | /* Recurse to parent */ |
3178 | 0 | if (sect->u.indirect.parent) { |
3179 | 0 | if (sect->sect_info.addr == sect->u.indirect.parent->sect_info.addr) |
3180 | 0 | ret_value = H5HF__sect_indirect_is_first(sect->u.indirect.parent); |
3181 | 0 | } /* end if */ |
3182 | 0 | else |
3183 | 0 | ret_value = true; |
3184 | |
|
3185 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
3186 | 0 | } /* end H5HF__sect_indirect_is_first() */ |
3187 | | |
3188 | | /*------------------------------------------------------------------------- |
3189 | | * Function: H5HF__sect_indirect_first |
3190 | | * |
3191 | | * Purpose: Make new 'first row' for indirect section |
3192 | | * |
3193 | | * Return: Non-negative on success/Negative on failure |
3194 | | * |
3195 | | *------------------------------------------------------------------------- |
3196 | | */ |
3197 | | static herr_t |
3198 | | H5HF__sect_indirect_first(H5HF_hdr_t *hdr, H5HF_free_section_t *sect) |
3199 | 0 | { |
3200 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
3201 | |
|
3202 | 0 | FUNC_ENTER_PACKAGE |
3203 | | |
3204 | | /* Sanity check */ |
3205 | 0 | assert(hdr); |
3206 | 0 | assert(sect); |
3207 | | |
3208 | | /* Check if this indirect section has direct block rows */ |
3209 | 0 | if (sect->u.indirect.dir_nrows > 0) { |
3210 | | /* Sanity checks */ |
3211 | 0 | assert(sect->u.indirect.row == 0); |
3212 | 0 | assert(sect->u.indirect.col == 0); |
3213 | 0 | assert(sect->u.indirect.dir_rows); |
3214 | 0 | assert(sect->u.indirect.dir_rows[0]); |
3215 | | |
3216 | | /* Change first row section in indirect section to be the "first row" */ |
3217 | 0 | if (H5HF__sect_row_first(hdr, sect->u.indirect.dir_rows[0]) < 0) |
3218 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTSET, FAIL, "can't set row section to be first row"); |
3219 | 0 | } /* end if */ |
3220 | 0 | else { |
3221 | | /* Sanity checks */ |
3222 | 0 | assert(sect->u.indirect.indir_nents > 0); |
3223 | 0 | assert(sect->u.indirect.indir_ents); |
3224 | 0 | assert(sect->u.indirect.indir_ents[0]); |
3225 | | |
3226 | | /* Forward to first child indirect section */ |
3227 | 0 | if (H5HF__sect_indirect_first(hdr, sect->u.indirect.indir_ents[0]) < 0) |
3228 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTSET, FAIL, "can't set child indirect section to be first row"); |
3229 | 0 | } /* end else */ |
3230 | | |
3231 | 0 | done: |
3232 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
3233 | 0 | } /* end H5HF__sect_indirect_first() */ |
3234 | | |
3235 | | /*------------------------------------------------------------------------- |
3236 | | * Function: H5HF__sect_indirect_get_iblock |
3237 | | * |
3238 | | * Purpose: Retrieve the indirect block for a indirect section |
3239 | | * |
3240 | | * Return: Pointer to indirect block on success/NULL on failure |
3241 | | * |
3242 | | *------------------------------------------------------------------------- |
3243 | | */ |
3244 | | static H5HF_indirect_t * |
3245 | | H5HF__sect_indirect_get_iblock(H5HF_free_section_t *sect) |
3246 | 0 | { |
3247 | 0 | FUNC_ENTER_PACKAGE_NOERR |
3248 | | |
3249 | | /* |
3250 | | * Check arguments. |
3251 | | */ |
3252 | 0 | assert(sect); |
3253 | 0 | assert(sect->sect_info.type == H5HF_FSPACE_SECT_INDIRECT); |
3254 | 0 | assert(sect->sect_info.state == H5FS_SECT_LIVE); |
3255 | |
|
3256 | 0 | FUNC_LEAVE_NOAPI(sect->u.indirect.u.iblock) |
3257 | 0 | } /* end H5HF__sect_indirect_get_iblock() */ |
3258 | | |
3259 | | /*------------------------------------------------------------------------- |
3260 | | * Function: H5HF__sect_indirect_merge_row |
3261 | | * |
3262 | | * Purpose: Merge two sections of this type |
3263 | | * |
3264 | | * Note: Second section always merges into first node |
3265 | | * |
3266 | | * Return: Success: non-negative |
3267 | | * |
3268 | | * Failure: negative |
3269 | | * |
3270 | | *------------------------------------------------------------------------- |
3271 | | */ |
3272 | | static herr_t |
3273 | | H5HF__sect_indirect_merge_row(H5HF_hdr_t *hdr, H5HF_free_section_t *row_sect1, H5HF_free_section_t *row_sect2) |
3274 | 0 | { |
3275 | 0 | H5HF_free_section_t *sect1 = NULL, *sect2 = NULL; /* Indirect sections underlying row sections */ |
3276 | 0 | unsigned start_entry1; /* Start entry for section #1 */ |
3277 | 0 | unsigned start_row1, start_col1; /* Starting row & column for section #1 */ |
3278 | 0 | unsigned end_entry1; /* End entry for section #1 */ |
3279 | 0 | unsigned end_row1; /* Ending row for section #1 */ |
3280 | 0 | unsigned start_row2; /* Starting row for section #2 */ |
3281 | 0 | bool merged_rows; /* Flag to indicate that rows was merged together */ |
3282 | 0 | unsigned u; /* Local index variable */ |
3283 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
3284 | |
|
3285 | 0 | FUNC_ENTER_PACKAGE |
3286 | | |
3287 | | /* Sanity check parameters */ |
3288 | 0 | assert(hdr); |
3289 | 0 | assert(row_sect1); |
3290 | 0 | assert(row_sect1->u.row.under); |
3291 | 0 | assert(row_sect2); |
3292 | 0 | assert(row_sect2->u.row.under); |
3293 | 0 | assert(row_sect2->sect_info.type == H5HF_FSPACE_SECT_FIRST_ROW); |
3294 | | |
3295 | | /* Set up indirect section information */ |
3296 | 0 | if (NULL == (sect1 = H5HF__sect_indirect_top(row_sect1->u.row.under))) |
3297 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTGET, FAIL, "can't retrieve pointer to sections"); |
3298 | 0 | if (NULL == (sect2 = H5HF__sect_indirect_top(row_sect2->u.row.under))) |
3299 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTGET, FAIL, "can't retrieve pointer to sections"); |
3300 | | |
3301 | | /* Sanity check some assumptions about the indirect sections */ |
3302 | 0 | assert(sect1->u.indirect.span_size > 0); |
3303 | 0 | assert(sect2->u.indirect.span_size > 0); |
3304 | | |
3305 | | /* Set up span information */ |
3306 | 0 | start_row1 = sect1->u.indirect.row; |
3307 | 0 | start_col1 = sect1->u.indirect.col; |
3308 | 0 | start_entry1 = (start_row1 * hdr->man_dtable.cparam.width) + start_col1; |
3309 | 0 | end_entry1 = (start_entry1 + sect1->u.indirect.num_entries) - 1; |
3310 | 0 | end_row1 = end_entry1 / hdr->man_dtable.cparam.width; |
3311 | 0 | start_row2 = sect2->u.indirect.row; |
3312 | | |
3313 | | /* Check for direct sections in second section */ |
3314 | | /* (second indirect section can be parent of indirect section for second |
3315 | | * row, and thus have no row sections of it's own) |
3316 | | */ |
3317 | 0 | if (sect2->u.indirect.dir_nrows > 0) { |
3318 | 0 | hsize_t sect1_iblock_off, sect2_iblock_off; /* Offset of indirect block underlying row section */ |
3319 | 0 | unsigned new_dir_nrows1; /* New value for number of direct rows in first section */ |
3320 | 0 | unsigned src_row2; /* Source row for copying from second section */ |
3321 | 0 | unsigned nrows_moved2; /* Number of rows to move from second section to first */ |
3322 | | |
3323 | | /* Sanity check child row assumptions */ |
3324 | | /* (second indirect section should be at top of equal or deeper |
3325 | | * hier. of row/indirect sections, so if second indirect section |
3326 | | * has child row sections, first indirect section _must_ have |
3327 | | * them also) |
3328 | | */ |
3329 | 0 | assert(sect1->u.indirect.dir_nrows > 0); |
3330 | 0 | assert(sect1->u.indirect.dir_rows); |
3331 | | |
3332 | | /* Get the offsets for the indirect blocks under the rows */ |
3333 | 0 | if (H5FS_SECT_LIVE == row_sect1->u.row.under->sect_info.state) |
3334 | 0 | sect1_iblock_off = row_sect1->u.row.under->u.indirect.u.iblock->block_off; |
3335 | 0 | else |
3336 | 0 | sect1_iblock_off = row_sect1->u.row.under->u.indirect.u.iblock_off; |
3337 | 0 | if (H5FS_SECT_LIVE == row_sect2->u.row.under->sect_info.state) |
3338 | 0 | sect2_iblock_off = row_sect2->u.row.under->u.indirect.u.iblock->block_off; |
3339 | 0 | else |
3340 | 0 | sect2_iblock_off = row_sect2->u.row.under->u.indirect.u.iblock_off; |
3341 | | |
3342 | | /* Check for sections sharing a row in the same underlying indirect block */ |
3343 | 0 | if (sect1_iblock_off == sect2_iblock_off && end_row1 == start_row2) { |
3344 | 0 | H5HF_free_section_t *last_row_sect1; /* Last row in first indirect section */ |
3345 | | |
3346 | | /* Locate the last row section in first indirect section, if we don't already have it */ |
3347 | 0 | if (row_sect1->u.row.row != end_row1) |
3348 | 0 | last_row_sect1 = sect1->u.indirect.dir_rows[sect1->u.indirect.dir_nrows - 1]; |
3349 | 0 | else |
3350 | 0 | last_row_sect1 = row_sect1; |
3351 | 0 | assert(last_row_sect1); |
3352 | 0 | assert(last_row_sect1->u.row.row == end_row1); |
3353 | | |
3354 | | /* Adjust info for first row section, to absorb second row section */ |
3355 | 0 | assert((last_row_sect1->u.row.col + last_row_sect1->u.row.num_entries) == row_sect2->u.row.col); |
3356 | 0 | last_row_sect1->u.row.num_entries += row_sect2->u.row.num_entries; |
3357 | | |
3358 | | /* Set up parameters for transfer of rows */ |
3359 | 0 | src_row2 = 1; |
3360 | 0 | nrows_moved2 = sect2->u.indirect.dir_nrows - 1; |
3361 | 0 | new_dir_nrows1 = (sect1->u.indirect.dir_nrows + sect2->u.indirect.dir_nrows) - 1; |
3362 | | |
3363 | | /* Indicate that the rows were merged */ |
3364 | 0 | merged_rows = true; |
3365 | 0 | } /* end if */ |
3366 | 0 | else { |
3367 | | |
3368 | | /* Set up parameters for transfer of rows */ |
3369 | 0 | src_row2 = 0; |
3370 | 0 | nrows_moved2 = sect2->u.indirect.dir_nrows; |
3371 | 0 | new_dir_nrows1 = sect1->u.indirect.dir_nrows + sect2->u.indirect.dir_nrows; |
3372 | | |
3373 | | /* Indicate that the rows were _not_ merged */ |
3374 | 0 | merged_rows = false; |
3375 | 0 | } /* end else */ |
3376 | | |
3377 | | /* Check if we need to move additional rows */ |
3378 | 0 | if (nrows_moved2 > 0) { |
3379 | 0 | H5HF_free_section_t **new_dir_rows; /* Pointer to new array of direct row pointers */ |
3380 | | |
3381 | | /* Extend the first section's row array */ |
3382 | 0 | if (NULL == (new_dir_rows = (H5HF_free_section_t **)H5MM_realloc( |
3383 | 0 | sect1->u.indirect.dir_rows, sizeof(H5HF_free_section_t *) * new_dir_nrows1))) |
3384 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_NOSPACE, FAIL, "allocation failed for row section pointer array"); |
3385 | 0 | sect1->u.indirect.dir_rows = new_dir_rows; |
3386 | | |
3387 | | /* Transfer the second section's rows to first section */ |
3388 | 0 | H5MM_memcpy(§1->u.indirect.dir_rows[sect1->u.indirect.dir_nrows], |
3389 | 0 | §2->u.indirect.dir_rows[src_row2], |
3390 | 0 | (sizeof(H5HF_free_section_t *) * nrows_moved2)); |
3391 | | |
3392 | | /* Re-target the row sections moved from second section */ |
3393 | 0 | for (u = sect1->u.indirect.dir_nrows; u < new_dir_nrows1; u++) |
3394 | 0 | sect1->u.indirect.dir_rows[u]->u.row.under = sect1; |
3395 | | |
3396 | | /* Adjust reference counts to account for transferred rows */ |
3397 | 0 | sect1->u.indirect.rc += nrows_moved2; |
3398 | 0 | sect2->u.indirect.rc -= nrows_moved2; |
3399 | | |
3400 | | /* Update information for first section */ |
3401 | 0 | sect1->u.indirect.dir_nrows = new_dir_nrows1; |
3402 | 0 | } /* end if */ |
3403 | 0 | } /* end if */ |
3404 | 0 | else |
3405 | | /* Indicate that the rows were _not_ merged */ |
3406 | 0 | merged_rows = false; |
3407 | | |
3408 | | /* Check for indirect sections in second section */ |
3409 | 0 | if (sect2->u.indirect.indir_nents > 0) { |
3410 | 0 | unsigned new_indir_nents1; /* New value for number of indirect entries in first section */ |
3411 | | |
3412 | | /* Some sanity checks on second indirect section */ |
3413 | 0 | assert(sect2->u.indirect.rc > 0); |
3414 | 0 | assert(sect2->u.indirect.indir_nents > 0); |
3415 | 0 | assert(sect2->u.indirect.indir_ents); |
3416 | | |
3417 | | /* Set up parameters for transfer of entries */ |
3418 | 0 | new_indir_nents1 = sect1->u.indirect.indir_nents + sect2->u.indirect.indir_nents; |
3419 | | |
3420 | | /* Check if first section can just take over second section's memory buffer */ |
3421 | 0 | if (sect1->u.indirect.indir_ents == NULL) { |
3422 | 0 | sect1->u.indirect.indir_ents = sect2->u.indirect.indir_ents; |
3423 | 0 | sect2->u.indirect.indir_ents = NULL; |
3424 | 0 | } /* end if */ |
3425 | 0 | else { |
3426 | 0 | H5HF_free_section_t **new_indir_ents; /* Pointer to new array of indirect entries */ |
3427 | | |
3428 | | /* Extend the first section's entry array */ |
3429 | 0 | if (NULL == (new_indir_ents = (H5HF_free_section_t **)H5MM_realloc( |
3430 | 0 | sect1->u.indirect.indir_ents, sizeof(H5HF_free_section_t *) * new_indir_nents1))) |
3431 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_NOSPACE, FAIL, "allocation failed for row section pointer array"); |
3432 | 0 | sect1->u.indirect.indir_ents = new_indir_ents; |
3433 | | |
3434 | | /* Transfer the second section's entries to first section */ |
3435 | 0 | H5MM_memcpy(§1->u.indirect.indir_ents[sect1->u.indirect.indir_nents], |
3436 | 0 | §2->u.indirect.indir_ents[0], |
3437 | 0 | (sizeof(H5HF_free_section_t *) * sect2->u.indirect.indir_nents)); |
3438 | 0 | } /* end else */ |
3439 | | |
3440 | | /* Re-target the child indirect sections moved from second section */ |
3441 | 0 | for (u = sect1->u.indirect.indir_nents; u < new_indir_nents1; u++) |
3442 | 0 | sect1->u.indirect.indir_ents[u]->u.indirect.parent = sect1; |
3443 | | |
3444 | | /* Adjust reference counts for transferred child indirect sections */ |
3445 | 0 | sect1->u.indirect.rc += sect2->u.indirect.indir_nents; |
3446 | 0 | sect2->u.indirect.rc -= sect2->u.indirect.indir_nents; |
3447 | | |
3448 | | /* Update information for first section */ |
3449 | 0 | sect1->u.indirect.indir_nents = new_indir_nents1; |
3450 | 0 | } /* end if */ |
3451 | | |
3452 | | /* Update information for first section */ |
3453 | 0 | sect1->u.indirect.num_entries += sect2->u.indirect.num_entries; |
3454 | 0 | sect1->u.indirect.span_size += sect2->u.indirect.span_size; |
3455 | | |
3456 | | /* Make certain we've tracked the first section's dependents correctly */ |
3457 | 0 | assert(sect1->u.indirect.rc == (sect1->u.indirect.indir_nents + sect1->u.indirect.dir_nrows)); |
3458 | | |
3459 | | /* Wrap up, freeing or re-inserting second row section */ |
3460 | | /* (want this to be after the first indirect section is consistent again) */ |
3461 | 0 | if (merged_rows) { |
3462 | | /* Release second row section */ |
3463 | | /* (indirectly releases second indirect section, since all of it's |
3464 | | * other dependents are gone) |
3465 | | */ |
3466 | 0 | assert(sect2->u.indirect.rc == 1); |
3467 | 0 | if (H5HF__sect_row_free((H5FS_section_info_t *)row_sect2) < 0) |
3468 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTRELEASE, FAIL, "can't free row section"); |
3469 | 0 | } /* end if */ |
3470 | 0 | else { |
3471 | | /* Decrement ref. count on second indirect section's parent */ |
3472 | 0 | assert(sect2->u.indirect.rc == 0); |
3473 | 0 | if (sect2->u.indirect.parent) |
3474 | 0 | if (H5HF__sect_indirect_decr(sect2->u.indirect.parent) < 0) |
3475 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTRELEASE, FAIL, |
3476 | 0 | "can't decrement ref. count on parent indirect section"); |
3477 | | |
3478 | | /* Free second indirect section */ |
3479 | 0 | if (H5HF__sect_indirect_free(sect2) < 0) |
3480 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTRELEASE, FAIL, "can't free indirect section node"); |
3481 | | |
3482 | | /* Re-add the second section's first row */ |
3483 | | /* (it's already been added to first indirect section, but it's been removed |
3484 | | * from the free space manager and needs to be re-added) |
3485 | | */ |
3486 | 0 | row_sect2->sect_info.type = H5HF_FSPACE_SECT_NORMAL_ROW; |
3487 | 0 | if (H5HF__space_add(hdr, row_sect2, H5FS_ADD_SKIP_VALID) < 0) |
3488 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "can't re-add second row section to free space"); |
3489 | 0 | } /* end else */ |
3490 | | |
3491 | | /* Check if we can create parent indirect section for first section */ |
3492 | | /* (i.e. merged indirect sections cover an entire indirect block) */ |
3493 | 0 | if (sect1->u.indirect.iblock_entries == sect1->u.indirect.num_entries) { |
3494 | | /* Build parent section for fully populated indirect section */ |
3495 | 0 | assert(sect1->u.indirect.parent == NULL); |
3496 | 0 | if (H5HF__sect_indirect_build_parent(hdr, sect1) < 0) |
3497 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTCREATE, FAIL, "can't create parent for full indirect section"); |
3498 | 0 | } /* end if */ |
3499 | | |
3500 | 0 | done: |
3501 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
3502 | 0 | } /* end H5HF__sect_indirect_merge_row() */ |
3503 | | |
3504 | | /*------------------------------------------------------------------------- |
3505 | | * Function: H5HF__sect_indirect_build_parent |
3506 | | * |
3507 | | * Purpose: Build a parent indirect section for a full indirect section |
3508 | | * |
3509 | | * Return: Success: non-negative |
3510 | | * Failure: negative |
3511 | | * |
3512 | | *------------------------------------------------------------------------- |
3513 | | */ |
3514 | | static herr_t |
3515 | | H5HF__sect_indirect_build_parent(H5HF_hdr_t *hdr, H5HF_free_section_t *sect) |
3516 | 0 | { |
3517 | 0 | H5HF_indirect_t *par_iblock; /* Indirect block for parent section */ |
3518 | 0 | H5HF_free_section_t *par_sect = NULL; /* Parent indirect section */ |
3519 | 0 | hsize_t par_block_off; /* Offset of parent's block */ |
3520 | 0 | unsigned par_row, par_col; /* Row & column in parent indirect section */ |
3521 | 0 | unsigned par_entry; /* Entry within parent indirect section */ |
3522 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
3523 | |
|
3524 | 0 | FUNC_ENTER_PACKAGE |
3525 | | |
3526 | | /* Sanity check parameters */ |
3527 | 0 | assert(hdr); |
3528 | 0 | assert(sect); |
3529 | 0 | assert(H5FS_SECT_LIVE == sect->sect_info.state); |
3530 | 0 | assert(sect->u.indirect.span_size > 0); |
3531 | 0 | assert(sect->u.indirect.iblock_entries > 0); |
3532 | 0 | assert(sect->u.indirect.iblock_entries == sect->u.indirect.num_entries); |
3533 | 0 | assert(sect->u.indirect.u.iblock); |
3534 | 0 | assert(sect->u.indirect.parent == NULL); |
3535 | | |
3536 | | /* Get information for creating parent indirect section */ |
3537 | 0 | if (sect->u.indirect.u.iblock->parent) { |
3538 | 0 | par_entry = sect->u.indirect.u.iblock->par_entry; |
3539 | 0 | par_iblock = sect->u.indirect.u.iblock->parent; |
3540 | 0 | par_block_off = par_iblock->block_off; |
3541 | 0 | } /* end if */ |
3542 | 0 | else { |
3543 | | /* Retrieve the information for the parent block */ |
3544 | 0 | if (H5HF__man_iblock_parent_info(hdr, sect->sect_info.addr, &par_block_off, &par_entry) < 0) |
3545 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTGET, FAIL, "can't get block entry"); |
3546 | 0 | par_iblock = NULL; |
3547 | 0 | } /* end else */ |
3548 | | |
3549 | | /* Compute row & column for block in parent */ |
3550 | 0 | par_row = par_entry / hdr->man_dtable.cparam.width; |
3551 | 0 | par_col = par_entry % hdr->man_dtable.cparam.width; |
3552 | 0 | assert(par_row >= hdr->man_dtable.max_direct_rows); |
3553 | | |
3554 | | /* Create parent indirect section */ |
3555 | 0 | if (NULL == (par_sect = H5HF__sect_indirect_new(hdr, sect->sect_info.addr, sect->sect_info.size, |
3556 | 0 | par_iblock, par_block_off, par_row, par_col, 1))) |
3557 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, FAIL, "can't create indirect section"); |
3558 | | |
3559 | | /* No rows of direct blocks covered in parent, reset direct row information */ |
3560 | 0 | par_sect->u.indirect.dir_nrows = 0; |
3561 | 0 | par_sect->u.indirect.dir_rows = NULL; |
3562 | | |
3563 | | /* Allocate space for the child indirect sections */ |
3564 | 0 | par_sect->u.indirect.indir_nents = 1; |
3565 | 0 | if (NULL == (par_sect->u.indirect.indir_ents = |
3566 | 0 | (H5HF_free_section_t **)H5MM_malloc(sizeof(H5HF_free_section_t *)))) |
3567 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_NOSPACE, FAIL, "allocation failed for indirect section pointer array"); |
3568 | | |
3569 | | /* Attach sections together */ |
3570 | 0 | sect->u.indirect.parent = par_sect; |
3571 | 0 | sect->u.indirect.par_entry = par_entry; |
3572 | 0 | par_sect->u.indirect.indir_ents[0] = sect; |
3573 | 0 | par_sect->u.indirect.rc = 1; |
3574 | |
|
3575 | 0 | done: |
3576 | 0 | if (ret_value < 0) |
3577 | 0 | if (par_sect && H5HF__sect_indirect_free(par_sect) < 0) |
3578 | 0 | HDONE_ERROR(H5E_HEAP, H5E_CANTRELEASE, FAIL, "can't free indirect section node"); |
3579 | |
|
3580 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
3581 | 0 | } /* end H5HF__sect_indirect_build_parent() */ |
3582 | | |
3583 | | /*------------------------------------------------------------------------- |
3584 | | * Function: H5HF__sect_indirect_shrink |
3585 | | * |
3586 | | * Purpose: "Shrink" container w/section |
3587 | | * |
3588 | | * Return: Success: non-negative |
3589 | | * Failure: negative |
3590 | | * |
3591 | | *------------------------------------------------------------------------- |
3592 | | */ |
3593 | | static herr_t |
3594 | | H5HF__sect_indirect_shrink(H5HF_hdr_t *hdr, H5HF_free_section_t *sect) |
3595 | 0 | { |
3596 | 0 | unsigned u; /* Local index variable */ |
3597 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
3598 | |
|
3599 | 0 | FUNC_ENTER_PACKAGE |
3600 | | |
3601 | | /* Sanity check parameters */ |
3602 | 0 | assert(hdr); |
3603 | 0 | assert(sect); |
3604 | | |
3605 | | /* Sanity check some assumptions about the indirect section */ |
3606 | 0 | assert(sect->u.indirect.dir_nrows > 0 || sect->u.indirect.indir_nents > 0); |
3607 | | |
3608 | | /* Walk through direct rows, freeing them */ |
3609 | 0 | for (u = 0; u < sect->u.indirect.dir_nrows; u++) { |
3610 | | /* Remove the normal rows from free space manager */ |
3611 | 0 | if (sect->u.indirect.dir_rows[u]->sect_info.type != H5HF_FSPACE_SECT_FIRST_ROW) { |
3612 | 0 | assert(sect->u.indirect.dir_rows[u]->sect_info.type == H5HF_FSPACE_SECT_NORMAL_ROW); |
3613 | 0 | if (H5HF__space_remove(hdr, sect->u.indirect.dir_rows[u]) < 0) |
3614 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTREMOVE, FAIL, "can't remove section from heap free space"); |
3615 | 0 | } /* end if */ |
3616 | | |
3617 | | /* Release the row section */ |
3618 | 0 | if (H5HF__sect_row_free_real(sect->u.indirect.dir_rows[u]) < 0) |
3619 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTRELEASE, FAIL, "can't free child section node"); |
3620 | 0 | } /* end for */ |
3621 | | |
3622 | | /* Walk through indirect entries, freeing them (recursively) */ |
3623 | 0 | for (u = 0; u < sect->u.indirect.indir_nents; u++) |
3624 | 0 | if (H5HF__sect_indirect_shrink(hdr, sect->u.indirect.indir_ents[u]) < 0) |
3625 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTRELEASE, FAIL, "can't free child section node"); |
3626 | | |
3627 | | /* Free the indirect section itself */ |
3628 | 0 | if (H5HF__sect_indirect_free(sect) < 0) |
3629 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTRELEASE, FAIL, "can't free indirect section node"); |
3630 | | |
3631 | 0 | done: |
3632 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
3633 | 0 | } /* end H5HF__sect_indirect_shrink() */ |
3634 | | |
3635 | | /*------------------------------------------------------------------------- |
3636 | | * Function: H5HF__sect_indirect_serialize |
3637 | | * |
3638 | | * Purpose: Serialize a "live" indirect section into a buffer |
3639 | | * |
3640 | | * Return: Success: non-negative |
3641 | | * |
3642 | | * Failure: negative |
3643 | | * |
3644 | | *------------------------------------------------------------------------- |
3645 | | */ |
3646 | | static herr_t |
3647 | | H5HF__sect_indirect_serialize(H5HF_hdr_t *hdr, const H5HF_free_section_t *sect, uint8_t *buf) |
3648 | 0 | { |
3649 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
3650 | |
|
3651 | 0 | FUNC_ENTER_PACKAGE |
3652 | | |
3653 | | /* Check arguments. */ |
3654 | 0 | assert(hdr); |
3655 | 0 | assert(sect); |
3656 | 0 | assert(buf); |
3657 | | |
3658 | | /* Check if this indirect section has a parent & forward if this section is first */ |
3659 | 0 | if (sect->u.indirect.parent) { |
3660 | 0 | if (sect->sect_info.addr == sect->u.indirect.parent->sect_info.addr) |
3661 | 0 | if (H5HF__sect_indirect_serialize(hdr, sect->u.indirect.parent, buf) < 0) |
3662 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTSERIALIZE, FAIL, |
3663 | 0 | "can't serialize indirect section's parent indirect section"); |
3664 | 0 | } /* end if */ |
3665 | 0 | else { |
3666 | | /* Indirect range's indirect block's block offset */ |
3667 | 0 | if (sect->sect_info.state == H5FS_SECT_LIVE) { |
3668 | 0 | assert(sect->u.indirect.u.iblock); |
3669 | 0 | UINT64ENCODE_VAR(buf, sect->u.indirect.u.iblock->block_off, hdr->heap_off_size); |
3670 | 0 | } /* end if */ |
3671 | 0 | else |
3672 | 0 | UINT64ENCODE_VAR(buf, sect->u.indirect.u.iblock_off, hdr->heap_off_size); |
3673 | | |
3674 | | /* Indirect range's row */ |
3675 | 0 | UINT16ENCODE(buf, sect->u.indirect.row); |
3676 | | |
3677 | | /* Indirect range's column */ |
3678 | 0 | UINT16ENCODE(buf, sect->u.indirect.col); |
3679 | | |
3680 | | /* Indirect range's # of entries */ |
3681 | 0 | UINT16ENCODE(buf, sect->u.indirect.num_entries); |
3682 | 0 | } /* end else */ |
3683 | | |
3684 | 0 | done: |
3685 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
3686 | 0 | } /* H5HF__sect_indirect_serialize() */ |
3687 | | |
3688 | | /*------------------------------------------------------------------------- |
3689 | | * Function: H5HF__sect_indirect_deserialize |
3690 | | * |
3691 | | * Purpose: Deserialize a buffer into a "live" indirect section |
3692 | | * |
3693 | | * Return: Success: non-negative |
3694 | | * Failure: negative |
3695 | | * |
3696 | | *------------------------------------------------------------------------- |
3697 | | */ |
3698 | | static H5FS_section_info_t * |
3699 | | H5HF__sect_indirect_deserialize(H5HF_hdr_t *hdr, const uint8_t *buf, haddr_t sect_addr, hsize_t sect_size, |
3700 | | unsigned *des_flags) |
3701 | 0 | { |
3702 | 0 | H5HF_free_section_t *new_sect; /* New indirect section */ |
3703 | 0 | hsize_t iblock_off; /* Indirect block's offset */ |
3704 | 0 | unsigned start_row; /* Indirect section's start row */ |
3705 | 0 | unsigned start_col; /* Indirect section's start column */ |
3706 | 0 | unsigned nentries; /* Indirect section's number of entries */ |
3707 | 0 | unsigned start_entry; /* Start entry in indirect block */ |
3708 | 0 | unsigned end_entry; /* End entry in indirect block */ |
3709 | 0 | unsigned end_row; /* End row in indirect block */ |
3710 | 0 | unsigned end_col; /* End column in indirect block */ |
3711 | 0 | H5FS_section_info_t *ret_value = NULL; /* Return value */ |
3712 | |
|
3713 | 0 | FUNC_ENTER_PACKAGE |
3714 | | |
3715 | | /* Check arguments. */ |
3716 | 0 | assert(hdr); |
3717 | 0 | assert(buf); |
3718 | 0 | assert(H5_addr_defined(sect_addr)); |
3719 | 0 | assert(sect_size); |
3720 | | |
3721 | | /* Indirect range's indirect block's block offset */ |
3722 | 0 | UINT64DECODE_VAR(buf, iblock_off, hdr->heap_off_size); |
3723 | | |
3724 | | /* Indirect section's row */ |
3725 | 0 | UINT16DECODE(buf, start_row); |
3726 | | |
3727 | | /* Indirect section's column */ |
3728 | 0 | UINT16DECODE(buf, start_col); |
3729 | | |
3730 | | /* Indirect section's # of entries */ |
3731 | 0 | UINT16DECODE(buf, nentries); |
3732 | | |
3733 | | /* Create free space section node */ |
3734 | 0 | if (NULL == (new_sect = H5HF__sect_indirect_new(hdr, sect_addr, sect_size, NULL, iblock_off, start_row, |
3735 | 0 | start_col, nentries))) |
3736 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, NULL, "can't create indirect section"); |
3737 | | |
3738 | | /* Compute start entry */ |
3739 | 0 | start_entry = (start_row * hdr->man_dtable.cparam.width) + start_col; |
3740 | | |
3741 | | /* Compute end column & row */ |
3742 | 0 | end_entry = (start_entry + nentries) - 1; |
3743 | 0 | end_row = end_entry / hdr->man_dtable.cparam.width; |
3744 | 0 | end_col = end_entry % hdr->man_dtable.cparam.width; |
3745 | | |
3746 | | /* Initialize rows for new indirect section */ |
3747 | 0 | if (H5HF__sect_indirect_init_rows(hdr, new_sect, true, NULL, H5FS_ADD_DESERIALIZING, |
3748 | 0 | new_sect->u.indirect.row, new_sect->u.indirect.col, end_row, |
3749 | 0 | end_col) < 0) |
3750 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTINIT, NULL, "can't initialize indirect section"); |
3751 | | |
3752 | | /* Indicate that this section shouldn't be added to free space manager's list */ |
3753 | 0 | *des_flags |= H5FS_DESERIALIZE_NO_ADD; |
3754 | | |
3755 | | /* Set return value */ |
3756 | 0 | ret_value = (H5FS_section_info_t *)new_sect; |
3757 | |
|
3758 | 0 | done: |
3759 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
3760 | 0 | } /* H5HF__sect_indirect_deserialize() */ |
3761 | | |
3762 | | /*------------------------------------------------------------------------- |
3763 | | * Function: H5HF__sect_indirect_free |
3764 | | * |
3765 | | * Purpose: Free a 'indirect' section node |
3766 | | * |
3767 | | * Return: Success: non-negative |
3768 | | * |
3769 | | * Failure: negative |
3770 | | * |
3771 | | *------------------------------------------------------------------------- |
3772 | | */ |
3773 | | static herr_t |
3774 | | H5HF__sect_indirect_free(H5HF_free_section_t *sect) |
3775 | 0 | { |
3776 | 0 | H5HF_indirect_t *iblock = NULL; /* Indirect block for section */ |
3777 | 0 | herr_t ret_value = SUCCEED; /* Return value */ |
3778 | |
|
3779 | 0 | FUNC_ENTER_PACKAGE |
3780 | |
|
3781 | 0 | assert(sect); |
3782 | | |
3783 | | /* Release the memory for tracking direct rows */ |
3784 | 0 | sect->u.indirect.dir_rows = (H5HF_free_section_t **)H5MM_xfree(sect->u.indirect.dir_rows); |
3785 | | |
3786 | | /* Release the memory for tracking indirect entries */ |
3787 | 0 | sect->u.indirect.indir_ents = (H5HF_free_section_t **)H5MM_xfree(sect->u.indirect.indir_ents); |
3788 | | |
3789 | | /* Check for live reference to an indirect block */ |
3790 | 0 | if (sect->sect_info.state == H5FS_SECT_LIVE) |
3791 | | /* Get indirect block, if there was one */ |
3792 | 0 | if (sect->u.indirect.u.iblock) |
3793 | 0 | iblock = sect->u.indirect.u.iblock; |
3794 | | |
3795 | | /* Release the sections */ |
3796 | 0 | if (H5HF__sect_node_free(sect, iblock) < 0) |
3797 | 0 | HGOTO_ERROR(H5E_HEAP, H5E_CANTRELEASE, FAIL, "can't free section node"); |
3798 | | |
3799 | 0 | done: |
3800 | 0 | FUNC_LEAVE_NOAPI(ret_value) |
3801 | 0 | } /* H5HF__sect_indirect_free() */ |
3802 | | |
3803 | | /*------------------------------------------------------------------------- |
3804 | | * Function: H5HF__sect_indirect_valid |
3805 | | * |
3806 | | * Purpose: Check the validity of a section |
3807 | | * |
3808 | | * Return: Success: non-negative |
3809 | | * Failure: negative |
3810 | | * |
3811 | | *------------------------------------------------------------------------- |
3812 | | */ |
3813 | | static herr_t |
3814 | | H5HF__sect_indirect_valid(const H5HF_hdr_t *hdr, const H5HF_free_section_t *sect) |
3815 | 0 | { |
3816 | 0 | unsigned start_row; /* Row for first block covered */ |
3817 | 0 | unsigned start_col; /* Column for first block covered */ |
3818 | 0 | unsigned start_entry; /* Entry for first block covered */ |
3819 | 0 | unsigned end_row; /* Row for last block covered */ |
3820 | 0 | unsigned end_entry; /* Entry for last block covered */ |
3821 | 0 | unsigned u; /* Local index variable */ |
3822 | |
|
3823 | 0 | FUNC_ENTER_PACKAGE_NOERR |
3824 | | |
3825 | | /* Sanity check arguments */ |
3826 | 0 | assert(hdr); |
3827 | 0 | assert(sect); |
3828 | | |
3829 | | /* Compute starting entry, column & row */ |
3830 | 0 | start_row = sect->u.indirect.row; |
3831 | 0 | start_col = sect->u.indirect.col; |
3832 | 0 | start_entry = (start_row * hdr->man_dtable.cparam.width) + start_col; |
3833 | | |
3834 | | /* Compute ending entry, column & row */ |
3835 | 0 | end_entry = (start_entry + sect->u.indirect.num_entries) - 1; |
3836 | 0 | end_row = end_entry / hdr->man_dtable.cparam.width; |
3837 | | |
3838 | | /* Sanity check any direct rows */ |
3839 | 0 | if (sect->u.indirect.dir_nrows > 0) { |
3840 | 0 | unsigned dir_nrows; /* Number of direct rows in section */ |
3841 | 0 | unsigned max_dir_row; /* Maximum direct row in section */ |
3842 | | |
3843 | | /* Check for indirect rows in section */ |
3844 | 0 | if (end_row >= hdr->man_dtable.max_direct_rows) |
3845 | 0 | max_dir_row = hdr->man_dtable.max_direct_rows - 1; |
3846 | 0 | else |
3847 | 0 | max_dir_row = end_row; |
3848 | | |
3849 | | /* Iterate over direct rows, checking pointer references */ |
3850 | 0 | dir_nrows = (max_dir_row - start_row) + 1; |
3851 | 0 | assert(dir_nrows == sect->u.indirect.dir_nrows); |
3852 | 0 | for (u = 0; u < dir_nrows; u++) { |
3853 | 0 | const H5HF_free_section_t H5_ATTR_NDEBUG_UNUSED *tmp_row_sect; /* Pointer to row section */ |
3854 | |
|
3855 | 0 | tmp_row_sect = sect->u.indirect.dir_rows[u]; |
3856 | 0 | assert(tmp_row_sect->sect_info.type == H5HF_FSPACE_SECT_FIRST_ROW || |
3857 | 0 | tmp_row_sect->sect_info.type == H5HF_FSPACE_SECT_NORMAL_ROW); |
3858 | 0 | assert(tmp_row_sect->u.row.under == sect); |
3859 | 0 | assert(tmp_row_sect->u.row.row == (start_row + u)); |
3860 | 0 | if (u > 0) { |
3861 | 0 | const H5HF_free_section_t H5_ATTR_NDEBUG_UNUSED *tmp_row_sect2; /* Pointer to row section */ |
3862 | |
|
3863 | 0 | tmp_row_sect2 = sect->u.indirect.dir_rows[u - 1]; |
3864 | 0 | assert(tmp_row_sect2->u.row.row < tmp_row_sect->u.row.row); |
3865 | 0 | assert(H5_addr_lt(tmp_row_sect2->sect_info.addr, tmp_row_sect->sect_info.addr)); |
3866 | 0 | assert(tmp_row_sect2->sect_info.size <= tmp_row_sect->sect_info.size); |
3867 | 0 | } /* end if */ |
3868 | 0 | } /* end for */ |
3869 | 0 | } /* end if */ |
3870 | | |
3871 | | /* Sanity check any indirect entries */ |
3872 | 0 | if (sect->u.indirect.indir_nents > 0) { |
3873 | | /* Basic sanity checks */ |
3874 | 0 | if (sect->sect_info.state == H5FS_SECT_LIVE) { |
3875 | 0 | assert(sect->u.indirect.iblock_entries); |
3876 | 0 | assert(sect->u.indirect.indir_nents <= sect->u.indirect.iblock_entries); |
3877 | 0 | } /* end if */ |
3878 | 0 | assert(sect->u.indirect.indir_ents); |
3879 | | |
3880 | | /* Sanity check each child indirect section */ |
3881 | 0 | for (u = 0; u < sect->u.indirect.indir_nents; u++) { |
3882 | 0 | const H5HF_free_section_t *tmp_child_sect; /* Pointer to child indirect section */ |
3883 | |
|
3884 | 0 | tmp_child_sect = sect->u.indirect.indir_ents[u]; |
3885 | 0 | assert(tmp_child_sect->sect_info.type == H5HF_FSPACE_SECT_INDIRECT); |
3886 | 0 | assert(tmp_child_sect->u.indirect.parent == sect); |
3887 | 0 | if (u > 0) { |
3888 | 0 | const H5HF_free_section_t H5_ATTR_NDEBUG_UNUSED |
3889 | 0 | *tmp_child_sect2; /* Pointer to child indirect section */ |
3890 | |
|
3891 | 0 | tmp_child_sect2 = sect->u.indirect.indir_ents[u - 1]; |
3892 | 0 | assert(H5_addr_lt(tmp_child_sect2->sect_info.addr, tmp_child_sect->sect_info.addr)); |
3893 | 0 | } /* end if */ |
3894 | | |
3895 | | /* Recursively check child indirect section */ |
3896 | 0 | H5HF__sect_indirect_valid(hdr, tmp_child_sect); |
3897 | 0 | } /* end for */ |
3898 | 0 | } /* end if */ |
3899 | |
|
3900 | 0 | FUNC_LEAVE_NOAPI(SUCCEED) |
3901 | 0 | } /* H5HF__sect_indirect_valid() */ |
3902 | | |
3903 | | /*------------------------------------------------------------------------- |
3904 | | * Function: H5HF__sect_indirect_debug |
3905 | | * |
3906 | | * Purpose: Dump debugging information about an indirect free space section |
3907 | | * |
3908 | | * Return: Success: non-negative |
3909 | | * |
3910 | | * Failure: negative |
3911 | | * |
3912 | | *------------------------------------------------------------------------- |
3913 | | */ |
3914 | | static herr_t |
3915 | | H5HF__sect_indirect_debug(const H5HF_free_section_t *sect, FILE *stream, int indent, int fwidth) |
3916 | 0 | { |
3917 | 0 | FUNC_ENTER_PACKAGE_NOERR |
3918 | | |
3919 | | /* Check arguments. */ |
3920 | 0 | assert(sect); |
3921 | | |
3922 | | /* Print indirect section information */ |
3923 | 0 | fprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, "Row:", sect->u.indirect.row); |
3924 | 0 | fprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, "Column:", sect->u.indirect.col); |
3925 | 0 | fprintf(stream, "%*s%-*s %u\n", indent, "", fwidth, "Number of entries:", sect->u.indirect.num_entries); |
3926 | |
|
3927 | 0 | FUNC_LEAVE_NOAPI(SUCCEED) |
3928 | 0 | } /* H5HF__sect_indirect_debug() */ |