1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the COPYING file, which can be found at the root of the source code *
* distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*-------------------------------------------------------------------------
*
* Created: H5Ftest.c
* Jan 3 2007
* Quincey Koziol
*
* Purpose: File testing routines.
*
*-------------------------------------------------------------------------
*/
/****************/
/* Module Setup */
/****************/
#include "H5Fmodule.h" /* This source code file is part of the H5F module */
#define H5F_TESTING /* Suppress warning about H5F testing funcs */
#define H5G_FRIEND /* Suppress error about including H5Gpkg.h */
#define H5G_TESTING /* Suppress warning about H5G testing funcs */
#define H5SM_FRIEND /* Suppress error about including H5SMpkg.h */
#define H5SM_TESTING /* Suppress warning about H5SM testing funcs */
/***********/
/* Headers */
/***********/
#include "H5private.h" /* Generic Functions */
#include "H5FDprivate.h" /* File Drivers */
#include "H5CXprivate.h" /* API Contexts */
#include "H5Eprivate.h" /* Error handling */
#include "H5Fpkg.h" /* File access */
#include "H5Gpkg.h" /* Groups */
#include "H5Iprivate.h" /* IDs */
#include "H5SMpkg.h" /* Shared object header messages */
#include "H5MMprivate.h" /* Memory management */
#include "H5VLprivate.h" /* Virtual Object Layer */
/****************/
/* Local Macros */
/****************/
/******************/
/* Local Typedefs */
/******************/
/********************/
/* Package Typedefs */
/********************/
/********************/
/* Local Prototypes */
/********************/
static herr_t H5F__vfd_swmr_decode_md_hdr(int md_fd, H5FD_vfd_swmr_md_header *md_hdr);
static herr_t H5F__vfd_swmr_decode_md_idx(int md_fd, H5FD_vfd_swmr_md_header *md_hdr,
H5FD_vfd_swmr_md_index *md_idx);
static herr_t H5F__vfd_swmr_verify_md_hdr_and_idx(H5F_t *f, H5FD_vfd_swmr_md_header *md_hdr,
H5FD_vfd_swmr_md_index *md_idx, unsigned num_entries,
H5FD_vfd_swmr_idx_entry_t *index);
/*********************/
/* Package Variables */
/*********************/
/*****************************/
/* Library Private Variables */
/*****************************/
/* Declare external the free list for H5FD_vfd_swmr_idx_entry_t */
H5FL_SEQ_EXTERN(H5FD_vfd_swmr_idx_entry_t);
/*******************/
/* Local Variables */
/*******************/
/*-------------------------------------------------------------------------
* Function: H5F__get_sohm_mesg_count_test
*
* Purpose: Retrieve the number of shared messages of a given type in a file
*
* Return: SUCCEED/FAIL
*
* Programmer: Quincey Koziol
* Jan 3, 2007
*
*-------------------------------------------------------------------------
*/
herr_t
H5F__get_sohm_mesg_count_test(hid_t file_id, unsigned type_id, size_t *mesg_count)
{
H5F_t * file; /* File info */
hbool_t api_ctx_pushed = FALSE; /* Whether API context pushed */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* Check arguments */
if (NULL == (file = (H5F_t *)H5VL_object_verify(file_id, H5I_FILE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file")
/* Push API context */
if (H5CX_push() < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "can't set API context")
api_ctx_pushed = TRUE;
/* Retrieve count for message type */
if (H5SM__get_mesg_count_test(file, type_id, mesg_count) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "can't retrieve shared message count")
done:
if (api_ctx_pushed && H5CX_pop(FALSE) < 0)
HDONE_ERROR(H5E_FILE, H5E_CANTRESET, FAIL, "can't reset API context")
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5F__get_sohm_mesg_count_test() */
/*-------------------------------------------------------------------------
* Function: H5F__check_cached_stab_test
*
* Purpose: Check that a file's superblock contains a cached symbol
* table entry, that the entry matches that in the root
* group's object header, and check that the addresses are
* valid.
*
* Return: SUCCEED/FAIL
*
* Programmer: Neil Fortner
* Mar 31, 2009
*
*-------------------------------------------------------------------------
*/
herr_t
H5F__check_cached_stab_test(hid_t file_id)
{
H5F_t * file; /* File info */
hbool_t api_ctx_pushed = FALSE; /* Whether API context pushed */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* Check arguments */
if (NULL == (file = (H5F_t *)H5VL_object_verify(file_id, H5I_FILE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file")
/* Push API context */
if (H5CX_push() < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTSET, FAIL, "can't set API context")
api_ctx_pushed = TRUE;
/* Verify the cached stab info */
if (H5G__verify_cached_stab_test(H5G_oloc(file->shared->root_grp), file->shared->sblock->root_ent) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "unable to verify cached symbol table info")
done:
if (api_ctx_pushed && H5CX_pop(FALSE) < 0)
HDONE_ERROR(H5E_FILE, H5E_CANTRESET, FAIL, "can't reset API context")
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5F__check_cached_stab_test() */
/*-------------------------------------------------------------------------
* Function: H5F__get_maxaddr_test
*
* Purpose: Retrieve the maximum address for a file
*
* Return: SUCCEED/FAIL
*
* Programmer: Quincey Koziol
* Jun 10, 2009
*
*-------------------------------------------------------------------------
*/
herr_t
H5F__get_maxaddr_test(hid_t file_id, haddr_t *maxaddr)
{
H5F_t *file; /* File info */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* Check arguments */
if (NULL == (file = (H5F_t *)H5VL_object_verify(file_id, H5I_FILE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file")
/* Retrieve maxaddr for file */
*maxaddr = file->shared->maxaddr;
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5F__get_maxaddr_test() */
/*-------------------------------------------------------------------------
* Function: H5F__get_sbe_addr_test
*
* Purpose: Retrieve the address of a superblock extension's object header
* for a file
*
* Return: SUCCEED/FAIL
*
* Programmer: Quincey Koziol
* Jul 10, 2016
*
*-------------------------------------------------------------------------
*/
herr_t
H5F__get_sbe_addr_test(hid_t file_id, haddr_t *sbe_addr)
{
H5F_t *file; /* File info */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* Check arguments */
if (NULL == (file = (H5F_t *)H5VL_object_verify(file_id, H5I_FILE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file")
/* Retrieve maxaddr for file */
*sbe_addr = file->shared->sblock->ext_addr;
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5F__get_sbe_addr_test() */
/*-------------------------------------------------------------------------
* Function: H5F__same_file_test
*
* Purpose: Check if two file IDs refer to the same underlying file.
*
* Return: SUCCEED/FAIL
*
* Programmer: Quincey Koziol
* Oct 13, 2018
*
*-------------------------------------------------------------------------
*/
htri_t
H5F__same_file_test(hid_t file_id1, hid_t file_id2)
{
H5F_t *file1, *file2; /* File info */
htri_t ret_value = FAIL; /* Return value */
FUNC_ENTER_PACKAGE
/* Check arguments */
if (NULL == (file1 = (H5F_t *)H5VL_object_verify(file_id1, H5I_FILE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file")
if (NULL == (file2 = (H5F_t *)H5VL_object_verify(file_id2, H5I_FILE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file")
/* If they are using the same underlying "shared" file struct, they are the same file */
ret_value = (file1->shared == file2->shared);
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5F__same_file_test() */
/*-------------------------------------------------------------------------
* Function: H5F__reparse_file_lock_variable_test
*
* Purpose: Re-parse the file locking environment variable.
*
* Since getenv(3) is fairly expensive, we only parse it once,
* when the library opens. This test function is used to
* re-parse the environment variable after we've changed it
* with setnev(3).
*
* Return: SUCCEED/FAIL
*
* Programmer: Dana Robinson
* Summer 2020
*
*-------------------------------------------------------------------------
*/
herr_t
H5F__reparse_file_lock_variable_test(void)
{
herr_t ret_value = SUCCEED;
FUNC_ENTER_PACKAGE
/* Check the file locking environment variable */
if (H5F__parse_file_lock_env_var(&use_locks_env_g) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTGET, FAIL, "unable to parse file locking environment variable")
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5F__reparse_file_lock_variable_test() */
/*
* VFD SWMR tests
*/
/*-------------------------------------------------------------------------
* Function: H5F__vfd_swmr_writer_create_open_flush_test
*
* Purpose: Verify info in the header and index when:
* (1) creating an HDF5 file
* (2) opening an existing HDF5 file
* (3) flushing an HDF5 file
*
* Open the metadata file
* Verify the file size is as expected (md_pages_reserved)
* For file create:
* --No header magic is found
* For file open or file flush:
* --Read and decode the header and index in the metadata file
* --Verify info in the header and index read from
* the metadata file is as expected (empty index)
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
herr_t
H5F__vfd_swmr_writer_create_open_flush_test(hid_t file_id, hbool_t file_create)
{
H5F_t * f; /* File pointer */
h5_stat_t stat_buf; /* Buffer for stat info */
H5FD_vfd_swmr_md_header md_hdr; /* Header for the metadata file */
H5FD_vfd_swmr_md_index md_idx; /* Indedx for the metadata file */
int md_fd = -1; /* The metadata file descriptor */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* Check arguments */
if (NULL == (f = (H5F_t *)H5VL_object_verify(file_id, H5I_FILE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file")
/* Open the metadata file */
if ((md_fd = HDopen(f->shared->vfd_swmr_config.md_file_path, O_RDONLY)) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "error opening metadata file")
/* Verify the minimum size for the metadata file */
if (HDstat(f->shared->vfd_swmr_config.md_file_path, &stat_buf) < 0)
HGOTO_ERROR(H5E_FILE, H5E_BADFILE, FAIL, "unable to stat the metadata file")
if (file_create) { /* Creating file */
if (stat_buf.st_size != 0)
HGOTO_ERROR(H5E_FILE, H5E_READERROR, FAIL, "metadata file should be empty for file create")
}
else { /* Opening or flushing the file */
HDmemset(&md_hdr, 0, sizeof(H5FD_vfd_swmr_md_header));
HDmemset(&md_idx, 0, sizeof(H5FD_vfd_swmr_md_index));
/* Decode the header */
if (H5F__vfd_swmr_decode_md_hdr(md_fd, &md_hdr) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTDECODE, FAIL, "error decoding header in the metadata file")
/* Decode the index */
if (H5F__vfd_swmr_decode_md_idx(md_fd, &md_hdr, &md_idx) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTDECODE, FAIL, "error decoding index in the metadata file")
/* Verify info in header and index read from the metadata file */
if (H5F__vfd_swmr_verify_md_hdr_and_idx(f, &md_hdr, &md_idx, 0, NULL) < 0)
HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL,
"incorrect info found in header and index of the metadata file")
}
done:
/* Free the index entries */
if (!file_create && md_idx.entries) {
HDassert(md_idx.num_entries);
H5MM_free(md_idx.entries);
}
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5F__vfd_swmr_writer_create_open_flush_test() */
/*-------------------------------------------------------------------------
* Function: H5F__vfd_swmr_decode_md_hdr
*
* Purpose: Decode header and verify header magic
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
static herr_t
H5F__vfd_swmr_decode_md_hdr(int md_fd, H5FD_vfd_swmr_md_header *md_hdr)
{
uint64_t index_length;
uint8_t image[H5FD_MD_HEADER_SIZE]; /* Buffer for the header image */
uint8_t *p = NULL; /* Points to the image */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
p = image;
/* Seek to the beginning of the file */
if (HDlseek(md_fd, (HDoff_t)H5FD_MD_HEADER_OFF, SEEK_SET) < 0)
HGOTO_ERROR(H5E_FILE, H5E_SEEKERROR, FAIL, "error seeking metadata file")
/* Read the header */
if (HDread(md_fd, image, H5FD_MD_HEADER_SIZE) < 0)
HGOTO_ERROR(H5E_FILE, H5E_READERROR, FAIL, "error reading metadata file")
/* Verify magic for header */
if (HDmemcmp(p, H5FD_MD_HEADER_MAGIC, (size_t)H5_SIZEOF_MAGIC) != 0)
HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "does not find header magic in the metadata file")
p += H5_SIZEOF_MAGIC;
/* Deserialize fs_page_size, tick_num, index_offset, index_length */
UINT32DECODE(p, md_hdr->fs_page_size);
UINT64DECODE(p, md_hdr->tick_num);
UINT64DECODE(p, md_hdr->index_offset);
UINT64DECODE(p, index_length);
if (index_length > SIZE_MAX)
HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "index is too long")
md_hdr->index_length = (size_t)index_length;
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* H5F__vfd_swmr_decode_md_hdr() */
/*-------------------------------------------------------------------------
* Function: H5F__vfd_swmr_decode_md_idx
*
* Purpose: Decode index and verify index magic
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
static herr_t
H5F__vfd_swmr_decode_md_idx(int md_fd, H5FD_vfd_swmr_md_header *md_hdr, H5FD_vfd_swmr_md_index *md_idx)
{
uint8_t *image = NULL; /* Points to the buffer for the index image */
uint8_t *p = NULL; /* Points to the image */
unsigned i; /* Local index variable */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* Allocate buffer for the index image */
if (NULL == (image = H5MM_malloc(md_hdr->index_length)))
HGOTO_ERROR(H5E_FILE, H5E_CANTALLOC, FAIL, "memory allocation failed for index on disk buffer")
p = image;
/* Seek to the position of the index */
if (HDlseek(md_fd, (HDoff_t)md_hdr->index_offset, SEEK_SET) < 0)
HGOTO_ERROR(H5E_FILE, H5E_SEEKERROR, FAIL, "unable to seek in metadata file")
/* Read the index */
if (HDread(md_fd, image, md_hdr->index_length) < (int64_t)md_hdr->index_length)
HGOTO_ERROR(H5E_FILE, H5E_READERROR, FAIL, "error in reading the header in metadata file")
/* Verify magic for index */
if (HDmemcmp(p, H5FD_MD_INDEX_MAGIC, H5_SIZEOF_MAGIC) != 0)
HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "no header magic in the metadata file")
p += H5_SIZEOF_MAGIC;
/* Deserialize tick_num and num_entries */
UINT64DECODE(p, md_idx->tick_num);
UINT32DECODE(p, md_idx->num_entries);
/* Deserialize index entries */
if (md_idx->num_entries) {
md_idx->entries = H5MM_calloc(md_idx->num_entries * sizeof(md_idx->entries[0]));
/* Allocate memory for the index entries */
if (NULL == md_idx->entries)
HGOTO_ERROR(H5E_FILE, H5E_CANTALLOC, FAIL, "memory allocation failed for index entries")
/* Decode index entries */
for (i = 0; i < md_idx->num_entries; i++) {
UINT32DECODE(p, md_idx->entries[i].hdf5_page_offset);
UINT32DECODE(p, md_idx->entries[i].md_file_page_offset);
UINT32DECODE(p, md_idx->entries[i].length);
UINT32DECODE(p, md_idx->entries[i].checksum);
} /* end for */
} /* end if */
done:
/* Free the buffer */
if (image)
H5MM_free(image);
if (ret_value < 0) {
/* Free the index entries */
if (md_idx->entries) {
HDassert(md_idx->num_entries);
H5MM_free(md_idx->entries);
}
}
FUNC_LEAVE_NOAPI(ret_value)
} /* H5F__vfd_swmr_decode_md_idx() */
/*-------------------------------------------------------------------------
* Function: H5F__vfd_swmr_verify_md_hdr_idx_test
*
* Purpose: Verify the header and index in the metadata file:
* --fs_page_size in md header is the same as that stored in "f"
* --index_length in md header is as indicated by num_entries
* --index_offset in md header is right after the header
* --number of entries in md index is num_entries
* --entries in md index is as indicated by num_entries and index
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
static herr_t
H5F__vfd_swmr_verify_md_hdr_and_idx(H5F_t *f, H5FD_vfd_swmr_md_header *md_hdr, H5FD_vfd_swmr_md_index *md_idx,
unsigned num_entries, H5FD_vfd_swmr_idx_entry_t *index)
{
unsigned i; /* Local index variable */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* Verify fs_page_size read from header in the metadata file is fs_page_size in f */
if (md_hdr->fs_page_size != f->shared->fs_page_size)
HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "incorrect fs_page_size read from metadata file")
/* Verify index_length read from header in the metadata file is the size of num_entries index */
if (md_hdr->index_length != H5FD_MD_INDEX_SIZE(num_entries))
HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "incorrect index_length read from metadata file")
/* Verify index_offset read from header in the metadata file is the size of md header */
if (md_hdr->index_offset != H5FD_MD_HEADER_SIZE)
HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "incorrect index_offset read from metadata file")
/* Verify num_entries read from index in the metadata file is num_entries */
if (md_idx->num_entries != num_entries)
HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "incorrect num_entries read from metadata file")
/* Verify empty/non-empty index entries */
if (num_entries == 0) {
/* Verify the index is empty */
if (md_idx->entries != NULL)
HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "incorrect entries in index")
}
else {
/* Verify entries */
for (i = 0; i < num_entries; i++) {
if (md_idx->entries[i].length != index[i].length)
HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "incorrect length read from metadata file")
if (md_idx->entries[i].hdf5_page_offset != index[i].hdf5_page_offset)
HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL,
"incorrect hdf5_page_offset read from metadata file")
if (md_idx->entries[i].md_file_page_offset != index[i].md_file_page_offset)
HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL,
"incorrect md_file_page_offset read from metadata file")
if (md_idx->entries[i].checksum != index[i].checksum)
HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "incorrect checksum read from metadata file")
}
}
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* H5F__vfd_swmr_verify_md_hdr_and_idx() */
/*-------------------------------------------------------------------------
* Function: H5F__count_shadow_defrees
*
* Purpose:
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
static unsigned
H5F__count_shadow_defrees(shadow_defree_queue_t *shadow_defrees)
{
shadow_defree_t *shadow_defree;
unsigned count = 0;
FUNC_ENTER_PACKAGE_NOERR
TAILQ_FOREACH(shadow_defree, shadow_defrees, link)
count++;
FUNC_LEAVE_NOAPI(count)
}
/*-------------------------------------------------------------------------
* Function: H5F__vfd_swmr_writer_md_test
*
* Purpose: Update the metadata file with the input index and verify
* the following:
* --info read from the metadata file is as indicated by
* the input: num_entries, index
* --# of entries on the delayed list is as indicated by
* the input: nshadow_defrees
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
herr_t
H5F__vfd_swmr_writer_md_test(hid_t file_id, unsigned num_entries, H5FD_vfd_swmr_idx_entry_t *index,
unsigned nshadow_defrees)
{
H5F_t * f; /* File pointer */
int md_fd = -1; /* The metadata file descriptor */
H5FD_vfd_swmr_md_header md_hdr; /* Header for the metadata file */
H5FD_vfd_swmr_md_index md_idx; /* Index for the metadata file */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
HDmemset(&md_hdr, 0, sizeof(H5FD_vfd_swmr_md_header));
HDmemset(&md_idx, 0, sizeof(H5FD_vfd_swmr_md_index));
/* Check arguments */
if (NULL == (f = (H5F_t *)H5VL_object_verify(file_id, H5I_FILE)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file")
/* Update the metadata file with the input index */
if (H5F_update_vfd_swmr_metadata_file(f, num_entries, index) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTALLOC, FAIL, "error updating the md file with the index")
/* Verify the number of entries in the delayed list is as expected */
if (H5F__count_shadow_defrees(&f->shared->shadow_defrees) == nshadow_defrees)
HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "incorrect # of entries in the delayed list")
/* Open the metadata file */
if ((md_fd = HDopen(f->shared->vfd_swmr_config.md_file_path, O_RDONLY)) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "error opening metadata file")
/* Decode the header in the metadata file */
if (H5F__vfd_swmr_decode_md_hdr(md_fd, &md_hdr) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTDECODE, FAIL, "error decoding header in the metadata file")
/* Decode the index in the metadata file */
if (H5F__vfd_swmr_decode_md_idx(md_fd, &md_hdr, &md_idx) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTOPENFILE, FAIL, "error decoding index in the metadata file")
/* Verify info read from the metadata file is the same as the input index */
if (H5F__vfd_swmr_verify_md_hdr_and_idx(f, &md_hdr, &md_idx, num_entries, index) < 0)
HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL,
"incorrect info found in header and index of the metadata file")
done:
/* Free the index entries */
if (md_idx.entries) {
HDassert(md_idx.num_entries);
H5MM_free(md_idx.entries);
}
FUNC_LEAVE_NOAPI(ret_value)
} /* H5F__vfd_swmr_writer_md_test() */
|