/
file_access.rs
1822 lines (1628 loc) · 57.3 KB
/
file_access.rs
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
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//! File access properties.
/*
Not supported due to complexity combined with low likelihood of ever being used:
- Low level direct VFD access: H5P{set,get}_driver, H5Pget_driver_info
- Direct file image API: H5P{set,get}_file_image, H5P{set,get}_file_image_callbacks
- Custom file access property lists in multi/family drivers
- Interfacing directly with multi/family parts via types/offsets
*/
use std::fmt::{self, Debug};
use std::iter;
use std::mem;
use std::ops::Deref;
use std::ptr;
use bitflags::bitflags;
use hdf5_sys::h5ac::{
H5AC_cache_config_t, H5AC_METADATA_WRITE_STRATEGY__DISTRIBUTED,
H5AC_METADATA_WRITE_STRATEGY__PROCESS_0_ONLY, H5AC__CURR_CACHE_CONFIG_VERSION,
H5AC__MAX_TRACE_FILE_NAME_LEN,
};
use hdf5_sys::h5c::{H5C_cache_decr_mode, H5C_cache_flash_incr_mode, H5C_cache_incr_mode};
use hdf5_sys::h5f::{H5F_close_degree_t, H5F_mem_t, H5F_FAMILY_DEFAULT};
use hdf5_sys::h5fd::H5FD_MEM_NTYPES;
use hdf5_sys::h5fd::{
H5FD_LOG_ALL, H5FD_LOG_FILE_IO, H5FD_LOG_FILE_READ, H5FD_LOG_FILE_WRITE, H5FD_LOG_FLAVOR,
H5FD_LOG_FREE, H5FD_LOG_LOC_IO, H5FD_LOG_LOC_READ, H5FD_LOG_LOC_SEEK, H5FD_LOG_LOC_WRITE,
H5FD_LOG_META_IO, H5FD_LOG_NUM_IO, H5FD_LOG_NUM_READ, H5FD_LOG_NUM_SEEK, H5FD_LOG_NUM_TRUNCATE,
H5FD_LOG_NUM_WRITE, H5FD_LOG_TIME_CLOSE, H5FD_LOG_TIME_IO, H5FD_LOG_TIME_OPEN,
H5FD_LOG_TIME_READ, H5FD_LOG_TIME_SEEK, H5FD_LOG_TIME_STAT, H5FD_LOG_TIME_TRUNCATE,
H5FD_LOG_TIME_WRITE, H5FD_LOG_TRUNCATE,
};
use hdf5_sys::h5p::{
H5Pcreate, H5Pget_alignment, H5Pget_cache, H5Pget_driver, H5Pget_fapl_core, H5Pget_fapl_family,
H5Pget_fapl_multi, H5Pget_fclose_degree, H5Pget_gc_references, H5Pget_mdc_config,
H5Pget_meta_block_size, H5Pget_sieve_buf_size, H5Pget_small_data_block_size, H5Pset_alignment,
H5Pset_cache, H5Pset_fapl_core, H5Pset_fapl_family, H5Pset_fapl_log, H5Pset_fapl_multi,
H5Pset_fapl_sec2, H5Pset_fapl_split, H5Pset_fapl_stdio, H5Pset_fclose_degree,
H5Pset_gc_references, H5Pset_mdc_config, H5Pset_meta_block_size, H5Pset_sieve_buf_size,
H5Pset_small_data_block_size,
};
#[cfg(h5_have_direct)]
use hdf5_sys::h5p::{H5Pget_fapl_direct, H5Pset_fapl_direct};
#[cfg(feature = "mpio")]
use hdf5_sys::h5p::{H5Pget_fapl_mpio, H5Pset_fapl_mpio};
#[cfg(hdf5_1_10_1)]
use hdf5_sys::h5ac::{H5AC_cache_image_config_t, H5AC__CACHE_IMAGE__ENTRY_AGEOUT__NONE};
#[cfg(hdf5_1_10_2)]
use hdf5_sys::h5f::H5F_libver_t;
#[cfg(all(hdf5_1_10_0, h5_have_parallel))]
use hdf5_sys::h5p::{
H5Pget_all_coll_metadata_ops, H5Pget_coll_metadata_write, H5Pset_all_coll_metadata_ops,
H5Pset_coll_metadata_write,
};
#[cfg(hdf5_1_8_13)]
use hdf5_sys::h5p::{H5Pget_core_write_tracking, H5Pset_core_write_tracking};
#[cfg(hdf5_1_8_7)]
use hdf5_sys::h5p::{H5Pget_elink_file_cache_size, H5Pset_elink_file_cache_size};
#[cfg(hdf5_1_10_1)]
use hdf5_sys::h5p::{
H5Pget_evict_on_close, H5Pget_mdc_image_config, H5Pget_page_buffer_size, H5Pset_evict_on_close,
H5Pset_mdc_image_config, H5Pset_page_buffer_size,
};
#[cfg(hdf5_1_10_2)]
use hdf5_sys::h5p::{H5Pget_libver_bounds, H5Pset_libver_bounds};
#[cfg(hdf5_1_10_0)]
use hdf5_sys::h5p::{
H5Pget_mdc_log_options, H5Pget_metadata_read_attempts, H5Pset_mdc_log_options,
H5Pset_metadata_read_attempts,
};
#[cfg(h5_have_direct)]
use crate::globals::H5FD_DIRECT;
#[cfg(feature = "mpio")]
use crate::globals::H5FD_MPIO;
use crate::globals::{
H5FD_CORE, H5FD_FAMILY, H5FD_LOG, H5FD_MULTI, H5FD_SEC2, H5FD_STDIO, H5P_FILE_ACCESS,
};
use crate::internal_prelude::*;
/// File access properties.
#[repr(transparent)]
pub struct FileAccess(Handle);
impl ObjectClass for FileAccess {
const NAME: &'static str = "file access property list";
const VALID_TYPES: &'static [H5I_type_t] = &[H5I_GENPROP_LST];
fn from_handle(handle: Handle) -> Self {
FileAccess(handle)
}
fn handle(&self) -> &Handle {
&self.0
}
fn validate(&self) -> Result<()> {
let class = self.class()?;
if class != PropertyListClass::FileAccess {
fail!("expected file access property list, got {:?}", class);
}
Ok(())
}
}
impl Debug for FileAccess {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let _e = silence_errors();
let mut formatter = f.debug_struct("FileAccess");
formatter.field("alignment", &self.alignment());
formatter.field("chunk_cache", &self.chunk_cache());
formatter.field("fclose_degree", &self.fclose_degree());
formatter.field("gc_references", &self.gc_references());
formatter.field("small_data_block_size", &self.small_data_block_size());
#[cfg(hdf5_1_10_2)]
formatter.field("libver_bounds", &self.libver_bounds());
#[cfg(hdf5_1_8_7)]
formatter.field("elink_file_cache_size", &self.elink_file_cache_size());
formatter.field("meta_block_size", &self.meta_block_size());
#[cfg(hdf5_1_10_1)]
formatter.field("page_buffer_size", &self.page_buffer_size());
#[cfg(hdf5_1_10_1)]
formatter.field("evict_on_close", &self.evict_on_close());
#[cfg(hdf5_1_10_1)]
formatter.field("mdc_image_config", &self.mdc_image_config());
formatter.field("sieve_buf_size", &self.sieve_buf_size());
#[cfg(hdf5_1_10_0)]
formatter.field("metadata_read_attempts", &self.metadata_read_attempts());
#[cfg(hdf5_1_10_0)]
formatter.field("mdc_log_options", &self.mdc_log_options());
#[cfg(all(hdf5_1_10_0, h5_have_parallel))]
formatter.field("all_coll_metadata_ops", &self.all_coll_metadata_ops());
#[cfg(all(hdf5_1_10_0, h5_have_parallel))]
formatter.field("coll_metadata_write", &self.coll_metadata_write());
formatter.field("mdc_config", &self.mdc_config());
formatter.field("driver", &self.driver());
formatter.finish()
}
}
impl Deref for FileAccess {
type Target = PropertyList;
fn deref(&self) -> &PropertyList {
unsafe { self.transmute() }
}
}
impl PartialEq for FileAccess {
fn eq(&self, other: &Self) -> bool {
<PropertyList as PartialEq>::eq(self, other)
}
}
impl Eq for FileAccess {}
impl Clone for FileAccess {
fn clone(&self) -> Self {
unsafe { self.deref().clone().cast() }
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct CoreDriver {
pub increment: usize,
pub filebacked: bool,
#[cfg(hdf5_1_8_13)]
pub write_tracking: usize,
}
impl Default for CoreDriver {
fn default() -> Self {
Self {
increment: 1024 * 1024,
filebacked: false,
#[cfg(hdf5_1_8_13)]
write_tracking: 0,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct FamilyDriver {
pub member_size: usize,
}
impl Default for FamilyDriver {
fn default() -> Self {
Self { member_size: H5F_FAMILY_DEFAULT as _ }
}
}
bitflags! {
pub struct LogFlags: u64 {
const TRUNCATE = H5FD_LOG_TRUNCATE;
const META_IO = H5FD_LOG_META_IO;
const LOC_READ = H5FD_LOG_LOC_READ;
const LOC_WRITE = H5FD_LOG_LOC_WRITE;
const LOC_SEEK = H5FD_LOG_LOC_SEEK;
const LOC_IO = H5FD_LOG_LOC_IO;
const FILE_READ = H5FD_LOG_FILE_READ;
const FILE_WRITE = H5FD_LOG_FILE_WRITE;
const FILE_IO = H5FD_LOG_FILE_IO;
const FLAVOR = H5FD_LOG_FLAVOR;
const NUM_READ = H5FD_LOG_NUM_READ;
const NUM_WRITE = H5FD_LOG_NUM_WRITE;
const NUM_SEEK = H5FD_LOG_NUM_SEEK;
const NUM_TRUNCATE = H5FD_LOG_NUM_TRUNCATE;
const NUM_IO = H5FD_LOG_NUM_IO;
const TIME_OPEN = H5FD_LOG_TIME_OPEN;
const TIME_STAT = H5FD_LOG_TIME_STAT;
const TIME_READ = H5FD_LOG_TIME_READ;
const TIME_WRITE = H5FD_LOG_TIME_WRITE;
const TIME_SEEK = H5FD_LOG_TIME_SEEK;
const TIME_TRUNCATE = H5FD_LOG_TIME_TRUNCATE;
const TIME_CLOSE = H5FD_LOG_TIME_CLOSE;
const TIME_IO = H5FD_LOG_TIME_IO;
const FREE = H5FD_LOG_FREE;
const ALL = H5FD_LOG_ALL;
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct LogOptions {
logfile: Option<String>,
flags: LogFlags,
buf_size: usize,
}
impl Default for LogOptions {
fn default() -> Self {
Self { logfile: None, flags: LogFlags::LOC_IO, buf_size: 0 }
}
}
static FD_MEM_TYPES: &'static [H5F_mem_t] = &[
H5F_mem_t::H5FD_MEM_DEFAULT,
H5F_mem_t::H5FD_MEM_SUPER,
H5F_mem_t::H5FD_MEM_BTREE,
H5F_mem_t::H5FD_MEM_DRAW,
H5F_mem_t::H5FD_MEM_GHEAP,
H5F_mem_t::H5FD_MEM_LHEAP,
H5F_mem_t::H5FD_MEM_OHDR,
];
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct MultiFile {
pub name: String,
pub addr: u64,
}
impl MultiFile {
pub fn new(name: &str, addr: u64) -> Self {
Self { name: name.into(), addr }
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct MultiLayout {
pub mem_super: u8,
pub mem_btree: u8,
pub mem_draw: u8,
pub mem_gheap: u8,
pub mem_lheap: u8,
pub mem_object: u8,
}
impl Default for MultiLayout {
fn default() -> Self {
Self { mem_super: 0, mem_btree: 1, mem_draw: 2, mem_gheap: 3, mem_lheap: 4, mem_object: 5 }
}
}
impl MultiLayout {
pub(crate) fn get(&self, index: usize) -> &u8 {
match index {
0 => &self.mem_super,
1 => &self.mem_btree,
2 => &self.mem_draw,
3 => &self.mem_gheap,
4 => &self.mem_lheap,
5 => &self.mem_object,
_ => unreachable!(),
}
}
pub(crate) fn get_mut(&mut self, index: usize) -> &mut u8 {
match index {
0 => &mut self.mem_super,
1 => &mut self.mem_btree,
2 => &mut self.mem_draw,
3 => &mut self.mem_gheap,
4 => &mut self.mem_lheap,
5 => &mut self.mem_object,
_ => unreachable!(),
}
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct MultiDriver {
pub files: Vec<MultiFile>,
pub layout: MultiLayout,
pub relax: bool,
}
impl Default for MultiDriver {
fn default() -> Self {
let m = u64::max_value() / 6;
let files = vec![
MultiFile::new("%s-s.h5", 0 * m),
MultiFile::new("%s-b.h5", 1 * m),
MultiFile::new("%s-r.h5", 2 * m),
MultiFile::new("%s-g.h5", 3 * m),
MultiFile::new("%s-l.h5", 4 * m),
MultiFile::new("%s-o.h5", 5 * m),
];
Self { files, layout: MultiLayout::default(), relax: false }
}
}
impl MultiDriver {
pub(crate) fn validate(&self) -> Result<()> {
let n = self.files.len();
if self.files.is_empty() || n > 6 {
fail!("invalid number of multi files: {} (expected 1-6)", n);
}
let mut used = iter::repeat(false).take(n).collect::<Vec<_>>();
for i in 0..6 {
let j = *self.layout.get(i) as usize;
if j >= n {
fail!("invalid multi layout index: {} (expected 0-{})", j, n - 1);
}
used[j] = true;
}
if !used.iter().all(|x| *x) {
fail!("invalid multi layout: some files are unused");
}
Ok(())
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct SplitDriver {
pub meta_ext: String,
pub raw_ext: String,
}
impl Default for SplitDriver {
fn default() -> Self {
Self { meta_ext: ".meta".into(), raw_ext: ".raw".into() }
}
}
impl SplitDriver {
pub(crate) fn from_multi(drv: &MultiDriver) -> Option<Self> {
let mut layout = MultiLayout {
mem_super: 0,
mem_btree: 0,
mem_draw: 1,
mem_gheap: 0,
mem_lheap: 0,
mem_object: 0,
};
if cfg!(hdf5_1_8_10) {
layout.mem_gheap = 1; // was changed in 1.8.10
}
let is_split = drv.relax
&& drv.layout == layout
&& drv.files.len() == 2
&& drv.files[0].addr == 0
&& drv.files[1].addr == u64::max_value() / 2
&& drv.files[0].name.starts_with("%s")
&& drv.files[1].name.starts_with("%s");
if !is_split {
None
} else {
Some(SplitDriver {
meta_ext: drv.files[0].name[2..].into(),
raw_ext: drv.files[1].name[2..].into(),
})
}
}
}
#[cfg(feature = "mpio")]
mod mpio {
use std::mem;
use mpi_sys::{MPI_Comm, MPI_Info};
use super::{c_int, Result};
#[derive(Debug)]
pub struct MpioDriver {
pub comm: MPI_Comm,
pub info: MPI_Info,
}
macro_rules! mpi_exec {
($func:ident, $($arg:tt)*) => (
if unsafe { mpi_sys::$func($($arg)*) } != mpi_sys::MPI_SUCCESS as _ {
fail!("{} failed", stringify!($func));
}
);
}
impl MpioDriver {
pub(crate) fn try_new(comm: MPI_Comm, info: Option<MPI_Info>) -> Result<Self> {
let mut comm_dup = unsafe { mem::zeroed() };
let mut info_dup = unsafe { mem::zeroed() };
mpi_exec!(MPI_Comm_dup, comm, &mut comm_dup);
if let Some(info) = info {
mpi_exec!(MPI_Info_dup, info, &mut info_dup);
} else {
mpi_exec!(MPI_Info_create, &mut info_dup);
}
Ok(Self { comm: comm_dup, info: info_dup })
}
}
impl Clone for MpioDriver {
fn clone(&self) -> Self {
unsafe {
let mut comm_dup = mem::zeroed();
mpi_sys::MPI_Comm_dup(self.comm, &mut comm_dup);
let mut info_dup = mem::zeroed();
mpi_sys::MPI_Info_dup(self.info, &mut info_dup);
Self { comm: comm_dup, info: info_dup }
}
}
}
impl Drop for MpioDriver {
fn drop(&mut self) {
let mut finalized: c_int = 1;
unsafe {
let code = mpi_sys::MPI_Finalized(&mut finalized);
if code == mpi_sys::MPI_SUCCESS as _ && finalized == 0 {
mpi_sys::MPI_Info_free(&mut self.info);
mpi_sys::MPI_Comm_free(&mut self.comm);
}
}
}
}
}
#[cfg(feature = "mpio")]
pub use self::mpio::*;
#[cfg(h5_have_direct)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct DirectDriver {
pub alignment: usize,
pub block_size: usize,
pub cbuf_size: usize,
}
#[cfg(h5_have_direct)]
impl Default for DirectDriver {
fn default() -> Self {
Self { alignment: 4096, block_size: 4096, cbuf_size: 16 * 1024 * 1024 }
}
}
#[derive(Clone, Debug)]
pub enum FileDriver {
Sec2,
Stdio,
Log,
Core(CoreDriver),
Family(FamilyDriver),
Multi(MultiDriver),
Split(SplitDriver),
#[cfg(feature = "mpio")]
Mpio(MpioDriver),
#[cfg(h5_have_direct)]
Direct(DirectDriver),
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum FileCloseDegree {
Default,
Weak,
Semi,
Strong,
}
impl Default for FileCloseDegree {
fn default() -> Self {
FileCloseDegree::Default
}
}
impl From<H5F_close_degree_t> for FileCloseDegree {
fn from(cd: H5F_close_degree_t) -> Self {
match cd {
H5F_close_degree_t::H5F_CLOSE_WEAK => FileCloseDegree::Weak,
H5F_close_degree_t::H5F_CLOSE_SEMI => FileCloseDegree::Semi,
H5F_close_degree_t::H5F_CLOSE_STRONG => FileCloseDegree::Strong,
_ => FileCloseDegree::Default,
}
}
}
impl Into<H5F_close_degree_t> for FileCloseDegree {
fn into(self) -> H5F_close_degree_t {
match self {
FileCloseDegree::Weak => H5F_close_degree_t::H5F_CLOSE_WEAK,
FileCloseDegree::Semi => H5F_close_degree_t::H5F_CLOSE_SEMI,
FileCloseDegree::Strong => H5F_close_degree_t::H5F_CLOSE_STRONG,
_ => H5F_close_degree_t::H5F_CLOSE_DEFAULT,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Alignment {
pub threshold: u64,
pub alignment: u64,
}
impl Default for Alignment {
fn default() -> Self {
Self { threshold: 1, alignment: 1 }
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct ChunkCache {
pub nslots: usize,
pub nbytes: usize,
pub w0: f64,
}
impl Default for ChunkCache {
fn default() -> Self {
Self { nslots: 521, nbytes: 1024 * 1024, w0: 0.75 }
}
}
impl Eq for ChunkCache {}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct PageBufferSize {
pub buf_size: usize,
pub min_meta_perc: u32,
pub min_raw_perc: u32,
}
impl Default for PageBufferSize {
fn default() -> Self {
Self { buf_size: 0, min_meta_perc: 0, min_raw_perc: 0 }
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum CacheIncreaseMode {
Off,
Threshold,
}
impl From<H5C_cache_incr_mode> for CacheIncreaseMode {
fn from(mode: H5C_cache_incr_mode) -> Self {
use self::{CacheIncreaseMode::*, H5C_cache_incr_mode::*};
match mode {
H5C_incr__threshold => Threshold,
_ => Off,
}
}
}
impl Into<H5C_cache_incr_mode> for CacheIncreaseMode {
fn into(self) -> H5C_cache_incr_mode {
use self::{CacheIncreaseMode::*, H5C_cache_incr_mode::*};
match self {
Threshold => H5C_incr__threshold,
_ => H5C_incr__off,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum FlashIncreaseMode {
Off,
AddSpace,
}
impl From<H5C_cache_flash_incr_mode> for FlashIncreaseMode {
fn from(mode: H5C_cache_flash_incr_mode) -> Self {
use self::{FlashIncreaseMode::*, H5C_cache_flash_incr_mode::*};
match mode {
H5C_flash_incr__add_space => AddSpace,
_ => Off,
}
}
}
impl Into<H5C_cache_flash_incr_mode> for FlashIncreaseMode {
fn into(self) -> H5C_cache_flash_incr_mode {
use self::{FlashIncreaseMode::*, H5C_cache_flash_incr_mode::*};
match self {
AddSpace => H5C_flash_incr__add_space,
_ => H5C_flash_incr__off,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum CacheDecreaseMode {
Off,
Threshold,
AgeOut,
AgeOutWithThreshold,
}
impl From<H5C_cache_decr_mode> for CacheDecreaseMode {
fn from(mode: H5C_cache_decr_mode) -> Self {
use self::{CacheDecreaseMode::*, H5C_cache_decr_mode::*};
match mode {
H5C_decr__threshold => Threshold,
H5C_decr__age_out => AgeOut,
H5C_decr__age_out_with_threshold => AgeOutWithThreshold,
_ => Off,
}
}
}
impl Into<H5C_cache_decr_mode> for CacheDecreaseMode {
fn into(self) -> H5C_cache_decr_mode {
use self::{CacheDecreaseMode::*, H5C_cache_decr_mode::*};
match self {
Threshold => H5C_decr__threshold,
AgeOut => H5C_decr__age_out,
AgeOutWithThreshold => H5C_decr__age_out_with_threshold,
_ => H5C_decr__off,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum MetadataWriteStrategy {
ProcessZeroOnly,
Distributed,
}
impl Default for MetadataWriteStrategy {
fn default() -> Self {
MetadataWriteStrategy::Distributed
}
}
impl From<c_int> for MetadataWriteStrategy {
fn from(strategy: c_int) -> Self {
use self::MetadataWriteStrategy::*;
match strategy {
H5AC_METADATA_WRITE_STRATEGY__DISTRIBUTED => Distributed,
_ => ProcessZeroOnly,
}
}
}
impl Into<c_int> for MetadataWriteStrategy {
fn into(self) -> c_int {
use self::MetadataWriteStrategy::*;
match self {
Distributed => H5AC_METADATA_WRITE_STRATEGY__DISTRIBUTED,
_ => H5AC_METADATA_WRITE_STRATEGY__PROCESS_0_ONLY,
}
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct MetadataCacheConfig {
pub rpt_fcn_enabled: bool,
pub open_trace_file: bool,
pub close_trace_file: bool,
pub trace_file_name: String,
pub evictions_enabled: bool,
pub set_initial_size: bool,
pub initial_size: usize,
pub min_clean_fraction: f64,
pub max_size: usize,
pub min_size: usize,
pub epoch_length: i64,
pub incr_mode: CacheIncreaseMode,
pub lower_hr_threshold: f64,
pub increment: f64,
pub apply_max_increment: bool,
pub max_increment: usize,
pub flash_incr_mode: FlashIncreaseMode,
pub flash_multiple: f64,
pub flash_threshold: f64,
pub decr_mode: CacheDecreaseMode,
pub upper_hr_threshold: f64,
pub decrement: f64,
pub apply_max_decrement: bool,
pub max_decrement: usize,
pub epochs_before_eviction: i32,
pub apply_empty_reserve: bool,
pub empty_reserve: f64,
pub dirty_bytes_threshold: usize,
pub metadata_write_strategy: MetadataWriteStrategy,
}
impl Eq for MetadataCacheConfig {}
impl Default for MetadataCacheConfig {
fn default() -> Self {
let min_clean_fraction = if cfg!(h5_have_parallel) { 0.3_f32 } else { 0.01_f32 };
let flash_multiple = if cfg!(h5_have_parallel) { 1.0_f32 } else { 1.4_f32 };
Self {
rpt_fcn_enabled: false,
open_trace_file: false,
close_trace_file: false,
trace_file_name: "".into(),
evictions_enabled: true,
set_initial_size: true,
initial_size: 1 << 21,
min_clean_fraction: min_clean_fraction as _,
max_size: 1 << 25,
min_size: 1 << 20,
epoch_length: 50_000,
incr_mode: CacheIncreaseMode::Threshold,
lower_hr_threshold: 0.9_f32 as _,
increment: 2.0,
apply_max_increment: true,
max_increment: 1 << 22,
flash_incr_mode: FlashIncreaseMode::AddSpace,
flash_multiple: flash_multiple as _,
flash_threshold: 0.25,
decr_mode: CacheDecreaseMode::AgeOutWithThreshold,
upper_hr_threshold: 0.999_f32 as _,
decrement: 0.9_f32 as _,
apply_max_decrement: true,
max_decrement: 1 << 20,
epochs_before_eviction: 3,
apply_empty_reserve: true,
empty_reserve: 0.1_f32 as _,
dirty_bytes_threshold: 1 << 18,
metadata_write_strategy: MetadataWriteStrategy::default(),
}
}
}
impl Into<H5AC_cache_config_t> for MetadataCacheConfig {
fn into(self) -> H5AC_cache_config_t {
const N: usize = H5AC__MAX_TRACE_FILE_NAME_LEN;
let mut trace_file_name: [c_char; N + 1] = unsafe { mem::zeroed() };
string_to_fixed_bytes(&self.trace_file_name, &mut trace_file_name[..N]);
H5AC_cache_config_t {
version: H5AC__CURR_CACHE_CONFIG_VERSION,
rpt_fcn_enabled: self.rpt_fcn_enabled as _,
open_trace_file: self.open_trace_file as _,
close_trace_file: self.close_trace_file as _,
trace_file_name,
evictions_enabled: self.evictions_enabled as _,
set_initial_size: self.set_initial_size as _,
initial_size: self.initial_size as _,
min_clean_fraction: self.min_clean_fraction as _,
max_size: self.max_size as _,
min_size: self.min_size as _,
epoch_length: self.epoch_length as _,
incr_mode: self.incr_mode.into(),
lower_hr_threshold: self.lower_hr_threshold as _,
increment: self.increment as _,
apply_max_increment: self.apply_max_increment as _,
max_increment: self.max_increment as _,
flash_incr_mode: self.flash_incr_mode.into(),
flash_multiple: self.flash_multiple as _,
flash_threshold: self.flash_threshold as _,
decr_mode: self.decr_mode.into(),
upper_hr_threshold: self.upper_hr_threshold as _,
decrement: self.decrement as _,
apply_max_decrement: self.apply_max_decrement as _,
max_decrement: self.max_decrement as _,
epochs_before_eviction: self.epochs_before_eviction as _,
apply_empty_reserve: self.apply_empty_reserve as _,
empty_reserve: self.empty_reserve as _,
dirty_bytes_threshold: self.dirty_bytes_threshold as _,
metadata_write_strategy: self.metadata_write_strategy.into(),
}
}
}
impl From<H5AC_cache_config_t> for MetadataCacheConfig {
fn from(mdc: H5AC_cache_config_t) -> Self {
const N: usize = H5AC__MAX_TRACE_FILE_NAME_LEN;
let trace_file_name = string_from_fixed_bytes(&mdc.trace_file_name, N);
Self {
rpt_fcn_enabled: mdc.rpt_fcn_enabled > 0,
open_trace_file: mdc.open_trace_file > 0,
close_trace_file: mdc.close_trace_file > 0,
trace_file_name,
evictions_enabled: mdc.evictions_enabled > 0,
set_initial_size: mdc.set_initial_size > 0,
initial_size: mdc.initial_size as _,
min_clean_fraction: mdc.min_clean_fraction as _,
max_size: mdc.max_size as _,
min_size: mdc.min_size as _,
epoch_length: mdc.epoch_length as _,
incr_mode: mdc.incr_mode.into(),
lower_hr_threshold: mdc.lower_hr_threshold as _,
increment: mdc.increment as _,
apply_max_increment: mdc.apply_max_increment > 0,
max_increment: mdc.max_increment as _,
flash_incr_mode: mdc.flash_incr_mode.into(),
flash_multiple: mdc.flash_multiple as _,
flash_threshold: mdc.flash_threshold as _,
decr_mode: mdc.decr_mode.into(),
upper_hr_threshold: mdc.upper_hr_threshold as _,
decrement: mdc.decrement as _,
apply_max_decrement: mdc.apply_max_decrement > 0,
max_decrement: mdc.max_decrement as _,
epochs_before_eviction: mdc.epochs_before_eviction as _,
apply_empty_reserve: mdc.apply_empty_reserve > 0,
empty_reserve: mdc.empty_reserve as _,
dirty_bytes_threshold: mdc.dirty_bytes_threshold as _,
metadata_write_strategy: mdc.metadata_write_strategy.into(),
}
}
}
#[cfg(hdf5_1_10_1)]
mod cache_image_config {
use super::*;
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct CacheImageConfig {
pub generate_image: bool,
pub save_resize_status: bool,
pub entry_ageout: i32,
}
impl Default for CacheImageConfig {
fn default() -> Self {
CacheImageConfig {
generate_image: false,
save_resize_status: false,
entry_ageout: H5AC__CACHE_IMAGE__ENTRY_AGEOUT__NONE,
}
}
}
impl Into<H5AC_cache_image_config_t> for CacheImageConfig {
fn into(self) -> H5AC_cache_image_config_t {
H5AC_cache_image_config_t {
version: H5AC__CURR_CACHE_CONFIG_VERSION,
generate_image: self.generate_image as _,
save_resize_status: self.save_resize_status as _,
entry_ageout: self.entry_ageout as _,
}
}
}
impl From<H5AC_cache_image_config_t> for CacheImageConfig {
fn from(config: H5AC_cache_image_config_t) -> Self {
Self {
generate_image: config.generate_image > 0,
save_resize_status: config.save_resize_status > 0,
entry_ageout: config.entry_ageout as _,
}
}
}
}
#[cfg(hdf5_1_10_1)]
pub use self::cache_image_config::*;
#[cfg(hdf5_1_10_0)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CacheLogOptions {
pub is_enabled: bool,
pub location: String,
pub start_on_access: bool,
}
#[cfg(hdf5_1_10_0)]
impl Default for CacheLogOptions {
fn default() -> Self {
Self { is_enabled: false, location: "".into(), start_on_access: false }
}
}
#[cfg(hdf5_1_10_2)]
mod libver {
use super::*;
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum LibraryVersion {
Earliest = 0,
V18 = 1,
V110 = 2,
}
impl LibraryVersion {
pub fn is_earliest(self) -> bool {
self == LibraryVersion::Earliest
}
pub const fn latest() -> Self {
LibraryVersion::V110
}
}
impl Into<H5F_libver_t> for LibraryVersion {
fn into(self) -> H5F_libver_t {
use self::{H5F_libver_t::*, LibraryVersion::*};
match self {
V18 => H5F_LIBVER_V18,
V110 => H5F_LIBVER_V110,
_ => H5F_LIBVER_EARLIEST,
}
}
}
impl From<H5F_libver_t> for LibraryVersion {
fn from(libver: H5F_libver_t) -> Self {
use self::{H5F_libver_t::*, LibraryVersion::*};
match libver {
H5F_LIBVER_V18 => V18,
H5F_LIBVER_V110 => V110,
_ => Earliest,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct LibVerBounds {
pub low: LibraryVersion,
pub high: LibraryVersion,
}
impl Default for LibVerBounds {
fn default() -> Self {
Self { low: LibraryVersion::Earliest, high: LibraryVersion::latest() }
}
}
}
#[cfg(hdf5_1_10_2)]
pub use self::libver::*;
/// Builder used to create file access property list.
#[derive(Clone, Debug, Default)]
pub struct FileAccessBuilder {
file_driver: Option<FileDriver>,
log_options: LogOptions,
#[cfg(hdf5_1_8_13)]
write_tracking: Option<usize>,
fclose_degree: Option<FileCloseDegree>,
alignment: Option<Alignment>,
chunk_cache: Option<ChunkCache>,
#[cfg(hdf5_1_8_7)]
elink_file_cache_size: Option<u32>,
meta_block_size: Option<u64>,
#[cfg(hdf5_1_10_1)]
page_buffer_size: Option<PageBufferSize>,
sieve_buf_size: Option<usize>,
#[cfg(hdf5_1_10_1)]
evict_on_close: Option<bool>,
#[cfg(hdf5_1_10_0)]
metadata_read_attempts: Option<u32>,
mdc_config: Option<MetadataCacheConfig>,
#[cfg(hdf5_1_10_1)]
mdc_image_config: Option<CacheImageConfig>,
#[cfg(hdf5_1_10_0)]
mdc_log_options: Option<CacheLogOptions>,
#[cfg(all(hdf5_1_10_0, h5_have_parallel))]
all_coll_metadata_ops: Option<bool>,
#[cfg(all(hdf5_1_10_0, h5_have_parallel))]
coll_metadata_write: Option<bool>,
gc_references: Option<bool>,
small_data_block_size: Option<u64>,
#[cfg(hdf5_1_10_2)]
libver_bounds: Option<LibVerBounds>,
}
impl FileAccessBuilder {
/// Creates a new file access property list builder.
pub fn new() -> Self {
Self::default()
}
/// Creates a new builder from an existing property list.
pub fn from_plist(plist: &FileAccess) -> Result<Self> {
let mut builder = Self::default();
builder.fclose_degree(plist.get_fclose_degree()?);
let v = plist.get_alignment()?;
builder.alignment(v.threshold, v.alignment);
let v = plist.get_chunk_cache()?;
builder.chunk_cache(v.nslots, v.nbytes, v.w0);
let drv = plist.get_driver()?;
builder.driver(&drv);
builder.gc_references(plist.get_gc_references()?);
builder.small_data_block_size(plist.get_small_data_block_size()?);