-
Notifications
You must be signed in to change notification settings - Fork 4
/
H5VLprovnc.c
5677 lines (4626 loc) · 187 KB
/
H5VLprovnc.c
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
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* 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://support.hdfgroup.org/ftp/HDF5/releases. *
* If you do not have access to either file, you may request a copy from *
* [email protected]. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* Purpose: This is a "PROVENANCE" VOL connector, which forwards each
* VOL callback to an underlying connector.
*
* It is designed as an example VOL connector for developers to
* use when creating new connectors, especially connectors that
* are outside of the HDF5 library. As such, it should _NOT_
* include _any_ private HDF5 header files. This connector should
* therefore only make public HDF5 API calls and use standard C /
* POSIX calls.
*/
/* Header files needed */
/* (Public HDF5 and standard C / POSIX only) */
#include <assert.h>
#include <pthread.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
#include "hdf5.h"
#include "hdf5dev.h"
#include "H5VLprovnc.h"
/**********/
/* Macros */
/**********/
/* Whether to display log messge when callback is invoked */
/* (Uncomment to enable) */
/* #define ENABLE_PROVNC_LOGGING */
/* Hack for missing va_copy() in old Visual Studio editions
* (from H5win2_defs.h - used on VS2012 and earlier)
*/
#if defined(_WIN32) && defined(_MSC_VER) && (_MSC_VER < 1800)
#define va_copy(D,S) ((D) = (S))
#endif
#define STAT_FUNC_MOD 733//a reasonably big size to avoid expensive collision handling, make sure it works with 62 function names.
//H5PL_type_t H5PLget_plugin_type(void) {return H5PL_TYPE_FILTER;}
//const void *H5PLget_plugin_info(void) {return &H5VL_provenance_cls;}
/************/
/* Typedefs */
/************/
typedef struct H5VL_prov_dataset_info_t dataset_prov_info_t;
typedef struct H5VL_prov_group_info_t group_prov_info_t;
typedef struct H5VL_prov_datatype_info_t datatype_prov_info_t;
typedef struct H5VL_prov_attribute_info_t attribute_prov_info_t;
typedef struct H5VL_prov_file_info_t file_prov_info_t;
typedef struct ProvenanceHelper {
/* Provenance properties */
char* prov_file_path;
FILE* prov_file_handle;
Prov_level prov_level;
char* prov_line_format;
char user_name[32];
int pid;
pthread_t tid;
char proc_name[64];
int ptr_cnt;
int opened_files_cnt;
file_prov_info_t* opened_files;//linkedlist,
} prov_helper_t;
typedef struct H5VL_provenance_t {
hid_t under_vol_id; /* ID for underlying VOL connector */
void *under_object; /* Info object for underlying VOL connector */
H5I_type_t my_type; /* obj type, dataset, datatype, etc. */
prov_helper_t *prov_helper; /* pointer shared among all layers, one per process. */
void *generic_prov_info; /* Pointer to a class-specific prov info struct. */
/* Should be cast to layer-specific type before use, */
/* such as file_prov_info, dataset_prov_info. */
} H5VL_provenance_t;
/* The PROVENANCE VOL wrapper context */
typedef struct H5VL_provenance_wrap_ctx_t {
prov_helper_t *prov_helper; /* shared pointer */
hid_t under_vol_id; /* VOL ID for under VOL */
void *under_wrap_ctx; /* Object wrapping context for under VOL */
file_prov_info_t *file_info;
unsigned long file_no;
hid_t dtype_id; /* only used by datatype */
} H5VL_provenance_wrap_ctx_t;
//======================================= statistics =======================================
//typedef struct H5VL_prov_t {
// void *under_object;
// char* func_name;
// int func_cnt;//stats
//} H5VL_prov_t;
struct H5VL_prov_file_info_t {//assigned when a file is closed, serves to store stats (copied from shared_file_info)
prov_helper_t* prov_helper; //pointer shared among all layers, one per process.
char* file_name;
unsigned long file_no;
#ifdef H5_HAVE_PARALLEL
// Only present for parallel HDF5 builds
MPI_Comm mpi_comm; // Copy of MPI communicator for file
MPI_Info mpi_info; // Copy of MPI info for file
hbool_t mpi_comm_info_valid; // Indicate that MPI Comm & Info are valid
#endif /* H5_HAVE_PARALLEL */
int ref_cnt;
/* Currently open objects */
int opened_datasets_cnt;
dataset_prov_info_t *opened_datasets;
int opened_grps_cnt;
group_prov_info_t *opened_grps;
int opened_dtypes_cnt;
datatype_prov_info_t *opened_dtypes;
int opened_attrs_cnt;
attribute_prov_info_t *opened_attrs;
/* Statistics */
int ds_created;
int ds_accessed;
int grp_created;
int grp_accessed;
int dtypes_created;
int dtypes_accessed;
file_prov_info_t *next;
};
// Common provenance information, for all objects
typedef struct H5VL_prov_object_info_t {
prov_helper_t *prov_helper; //pointer shared among all layers, one per process.
file_prov_info_t *file_info; // Pointer to file info for object's file
H5O_token_t token; // Unique ID within file for object
char *name; // Name of object within file
// (possibly NULL and / or non-unique)
int ref_cnt; // # of references to this prov info
} object_prov_info_t;
struct H5VL_prov_dataset_info_t {
object_prov_info_t obj_info; // Generic prov. info
// Must be first field in struct, for
// generic upcasts to work
H5T_class_t dt_class; //data type class
H5S_class_t ds_class; //data space class
H5D_layout_t layout;
unsigned int dimension_cnt;
hsize_t dimensions[H5S_MAX_RANK];
size_t dset_type_size;
hsize_t dset_space_size; //unsigned long long
hsize_t total_bytes_read;
hsize_t total_bytes_written;
hsize_t total_read_time;
hsize_t total_write_time;
int dataset_read_cnt;
int dataset_write_cnt;
#ifdef H5_HAVE_PARALLEL
int ind_dataset_read_cnt;
int ind_dataset_write_cnt;
int coll_dataset_read_cnt;
int coll_dataset_write_cnt;
int broken_coll_dataset_read_cnt;
int broken_coll_dataset_write_cnt;
#endif /* H5_HAVE_PARALLEL */
int access_cnt;
dataset_prov_info_t *next;
};
struct H5VL_prov_group_info_t {
object_prov_info_t obj_info; // Generic prov. info
// Must be first field in struct, for
// generic upcasts to work
int func_cnt;//stats
// int group_get_cnt;
// int group_specific_cnt;
group_prov_info_t *next;
};
typedef struct H5VL_prov_link_info_t {
int link_get_cnt;
int link_specific_cnt;
} link_prov_info_t;
struct H5VL_prov_datatype_info_t {
object_prov_info_t obj_info; // Generic prov. info
// Must be first field in struct, for
// generic upcasts to work
hid_t dtype_id;
int datatype_commit_cnt;
int datatype_get_cnt;
datatype_prov_info_t *next;
};
struct H5VL_prov_attribute_info_t {
object_prov_info_t obj_info; // Generic prov. info
// Must be first field in struct, for
// generic upcasts to work
int func_cnt;//stats
attribute_prov_info_t *next;
};
unsigned long TOTAL_PROV_OVERHEAD;
unsigned long TOTAL_NATIVE_H5_TIME;
unsigned long PROV_WRITE_TOTAL_TIME;
unsigned long FILE_LL_TOTAL_TIME; //record file linked list overhead
unsigned long DS_LL_TOTAL_TIME; //dataset
unsigned long GRP_LL_TOTAL_TIME; //group
unsigned long DT_LL_TOTAL_TIME; //datatype
unsigned long ATTR_LL_TOTAL_TIME; //attribute
static prov_helper_t* PROV_HELPER = NULL;
//======================================= statistics =======================================
/********************* */
/* Function prototypes */
/********************* */
/* Helper routines */
static H5VL_provenance_t *H5VL_provenance_new_obj(void *under_obj,
hid_t under_vol_id, prov_helper_t* helper);
static herr_t H5VL_provenance_free_obj(H5VL_provenance_t *obj);
/* "Management" callbacks */
static herr_t H5VL_provenance_init(hid_t vipl_id);
static herr_t H5VL_provenance_term(void);
static void *H5VL_provenance_info_copy(const void *info);
static herr_t H5VL_provenance_info_cmp(int *cmp_value, const void *info1, const void *info2);
static herr_t H5VL_provenance_info_free(void *info);
static herr_t H5VL_provenance_info_to_str(const void *info, char **str);
static herr_t H5VL_provenance_str_to_info(const char *str, void **info);
static void *H5VL_provenance_get_object(const void *obj);
static herr_t H5VL_provenance_get_wrap_ctx(const void *obj, void **wrap_ctx);
static void *H5VL_provenance_wrap_object(void *under_under_in, H5I_type_t obj_type, void *wrap_ctx);
static void *H5VL_provenance_unwrap_object(void *under);
static herr_t H5VL_provenance_free_wrap_ctx(void *obj);
/* Attribute callbacks */
static void *H5VL_provenance_attr_create(void *obj, const H5VL_loc_params_t *loc_params,
const char *name, hid_t type_id, hid_t space_id, hid_t acpl_id,
hid_t aapl_id, hid_t dxpl_id, void **req);
static void *H5VL_provenance_attr_open(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t aapl_id, hid_t dxpl_id, void **req);
static herr_t H5VL_provenance_attr_read(void *attr, hid_t mem_type_id, void *buf, hid_t dxpl_id, void **req);
static herr_t H5VL_provenance_attr_write(void *attr, hid_t mem_type_id, const void *buf, hid_t dxpl_id, void **req);
static herr_t H5VL_provenance_attr_get(void *obj, H5VL_attr_get_args_t *args, hid_t dxpl_id, void **req);
static herr_t H5VL_provenance_attr_specific(void *obj, const H5VL_loc_params_t *loc_params, H5VL_attr_specific_args_t *args, hid_t dxpl_id, void **req);
static herr_t H5VL_provenance_attr_optional(void *obj, H5VL_optional_args_t *args, hid_t dxpl_id, void **req);
static herr_t H5VL_provenance_attr_close(void *attr, hid_t dxpl_id, void **req);
/* Dataset callbacks */
static void *H5VL_provenance_dataset_create(void *obj, const H5VL_loc_params_t *loc_params,
const char *ds_name, hid_t lcpl_id, hid_t type_id, hid_t space_id,
hid_t dcpl_id, hid_t dapl_id, hid_t dxpl_id, void **req);
static void *H5VL_provenance_dataset_open(void *obj, const H5VL_loc_params_t *loc_params, const char *ds_name, hid_t dapl_id, hid_t dxpl_id, void **req);
static herr_t H5VL_provenance_dataset_read(void *dset, hid_t mem_type_id, hid_t mem_space_id,
hid_t file_space_id, hid_t plist_id, void *buf, void **req);
static herr_t H5VL_provenance_dataset_write(void *dset, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, hid_t plist_id, const void *buf, void **req);
static herr_t H5VL_provenance_dataset_get(void *dset, H5VL_dataset_get_args_t *args, hid_t dxpl_id, void **req);
static herr_t H5VL_provenance_dataset_specific(void *obj, H5VL_dataset_specific_args_t *args, hid_t dxpl_id, void **req);
static herr_t H5VL_provenance_dataset_optional(void *obj, H5VL_optional_args_t *args, hid_t dxpl_id, void **req);
static herr_t H5VL_provenance_dataset_close(void *dset, hid_t dxpl_id, void **req);
/* Datatype callbacks */
static void *H5VL_provenance_datatype_commit(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t type_id, hid_t lcpl_id, hid_t tcpl_id, hid_t tapl_id, hid_t dxpl_id, void **req);
static void *H5VL_provenance_datatype_open(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t tapl_id, hid_t dxpl_id, void **req);
static herr_t H5VL_provenance_datatype_get(void *dt, H5VL_datatype_get_args_t *args, hid_t dxpl_id, void **req);
static herr_t H5VL_provenance_datatype_specific(void *obj, H5VL_datatype_specific_args_t *args, hid_t dxpl_id, void **req);
static herr_t H5VL_provenance_datatype_optional(void *obj, H5VL_optional_args_t *args, hid_t dxpl_id, void **req);
static herr_t H5VL_provenance_datatype_close(void *dt, hid_t dxpl_id, void **req);
/* File callbacks */
static void *H5VL_provenance_file_create(const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id, hid_t dxpl_id, void **req);
static void *H5VL_provenance_file_open(const char *name, unsigned flags, hid_t fapl_id, hid_t dxpl_id, void **req);
static herr_t H5VL_provenance_file_get(void *file, H5VL_file_get_args_t *args, hid_t dxpl_id, void **req);
static herr_t H5VL_provenance_file_specific(void *file, H5VL_file_specific_args_t *args, hid_t dxpl_id, void **req);
static herr_t H5VL_provenance_file_optional(void *file, H5VL_optional_args_t *args, hid_t dxpl_id, void **req);
static herr_t H5VL_provenance_file_close(void *file, hid_t dxpl_id, void **req);
/* Group callbacks */
static void *H5VL_provenance_group_create(void *obj, const H5VL_loc_params_t *loc_params,
const char *name, hid_t lcpl_id, hid_t gcpl_id, hid_t gapl_id, hid_t dxpl_id, void **req);
static void *H5VL_provenance_group_open(void *obj, const H5VL_loc_params_t *loc_params, const char *name, hid_t gapl_id, hid_t dxpl_id, void **req);
static herr_t H5VL_provenance_group_get(void *obj, H5VL_group_get_args_t *args, hid_t dxpl_id, void **req);
static herr_t H5VL_provenance_group_specific(void *obj, H5VL_group_specific_args_t *args, hid_t dxpl_id, void **req);
static herr_t H5VL_provenance_group_optional(void *obj, H5VL_optional_args_t *args, hid_t dxpl_id, void **req);
static herr_t H5VL_provenance_group_close(void *grp, hid_t dxpl_id, void **req);
/* Link callbacks */
static herr_t H5VL_provenance_link_create(H5VL_link_create_args_t *args,
void *obj, const H5VL_loc_params_t *loc_params, hid_t lcpl_id, hid_t lapl_id,
hid_t dxpl_id, void **req);
static herr_t H5VL_provenance_link_copy(void *src_obj, const H5VL_loc_params_t *loc_params1, void *dst_obj, const H5VL_loc_params_t *loc_params2, hid_t lcpl_id, hid_t lapl_id, hid_t dxpl_id, void **req);
static herr_t H5VL_provenance_link_move(void *src_obj, const H5VL_loc_params_t *loc_params1, void *dst_obj, const H5VL_loc_params_t *loc_params2, hid_t lcpl_id, hid_t lapl_id, hid_t dxpl_id, void **req);
static herr_t H5VL_provenance_link_get(void *obj, const H5VL_loc_params_t *loc_params, H5VL_link_get_args_t *args, hid_t dxpl_id, void **req);
static herr_t H5VL_provenance_link_specific(void *obj, const H5VL_loc_params_t *loc_params, H5VL_link_specific_args_t *args, hid_t dxpl_id, void **req);
static herr_t H5VL_provenance_link_optional(void *obj, const H5VL_loc_params_t *loc_params, H5VL_optional_args_t *args, hid_t dxpl_id, void **req);
/* Object callbacks */
static void *H5VL_provenance_object_open(void *obj, const H5VL_loc_params_t *loc_params, H5I_type_t *obj_to_open_type, hid_t dxpl_id, void **req);
static herr_t H5VL_provenance_object_copy(void *src_obj, const H5VL_loc_params_t *src_loc_params, const char *src_name, void *dst_obj, const H5VL_loc_params_t *dst_loc_params, const char *dst_name, hid_t ocpypl_id, hid_t lcpl_id, hid_t dxpl_id, void **req);
static herr_t H5VL_provenance_object_get(void *obj, const H5VL_loc_params_t *loc_params, H5VL_object_get_args_t *args, hid_t dxpl_id, void **req);
static herr_t H5VL_provenance_object_specific(void *obj, const H5VL_loc_params_t *loc_params, H5VL_object_specific_args_t *args, hid_t dxpl_id, void **req);
static herr_t H5VL_provenance_object_optional(void *obj, const H5VL_loc_params_t *loc_params, H5VL_optional_args_t *args, hid_t dxpl_id, void **req);
/* Container/connector introspection callbacks */
static herr_t H5VL_provenance_introspect_get_cap_flags(const void *info, unsigned *cap_flags);
static herr_t H5VL_provenance_introspect_opt_query(void *obj, H5VL_subclass_t cls, int opt_type, uint64_t *flags);
/* Async request callbacks */
static herr_t H5VL_provenance_request_wait(void *req, uint64_t timeout, H5VL_request_status_t *status);
static herr_t H5VL_provenance_request_notify(void *obj, H5VL_request_notify_t cb, void *ctx);
static herr_t H5VL_provenance_request_cancel(void *req, H5VL_request_status_t *status);
static herr_t H5VL_provenance_request_specific(void *req, H5VL_request_specific_args_t *args);
static herr_t H5VL_provenance_request_optional(void *req, H5VL_optional_args_t *args);
static herr_t H5VL_provenance_request_free(void *req);
/* Blob callbacks */
static herr_t H5VL_provenance_blob_put(void *obj, const void *buf, size_t size, void *blob_id, void *ctx);
static herr_t H5VL_provenance_blob_get(void *obj, const void *blob_id, void *buf, size_t size, void *ctx);
static herr_t H5VL_provenance_blob_specific(void *obj, void *blob_id, H5VL_blob_specific_args_t *args);
static herr_t H5VL_provenance_blob_optional(void *obj, void *blob_id, H5VL_optional_args_t *args);
/* Token callbacks */
static herr_t H5VL_provenance_token_cmp(void *obj, const H5O_token_t *token1, const H5O_token_t *token2, int *cmp_value);
static herr_t H5VL_provenance_token_to_str(void *obj, H5I_type_t obj_type, const H5O_token_t *token, char **token_str);
static herr_t H5VL_provenance_token_from_str(void *obj, H5I_type_t obj_type, const char *token_str, H5O_token_t *token);
/* Catch-all optional callback */
static herr_t H5VL_provenance_optional(void *obj, H5VL_optional_args_t *args, hid_t dxpl_id, void **req);
/*******************/
/* Local variables */
/*******************/
/* PROVENANCE VOL connector class struct */
static const H5VL_class_t H5VL_provenance_cls = {
H5VL_VERSION, /* VOL class struct version */
(H5VL_class_value_t)H5VL_PROVNC_VALUE, /* value */
H5VL_PROVNC_NAME, /* name */
H5VL_PROVNC_VERSION, /* version */
0, /* capability flags */
H5VL_provenance_init, /* initialize */
H5VL_provenance_term, /* terminate */
{ /* info_cls */
sizeof(H5VL_provenance_info_t), /* info size */
H5VL_provenance_info_copy, /* info copy */
H5VL_provenance_info_cmp, /* info compare */
H5VL_provenance_info_free, /* info free */
H5VL_provenance_info_to_str, /* info to str */
H5VL_provenance_str_to_info, /* str to info */
},
{ /* wrap_cls */
H5VL_provenance_get_object, /* get_object */
H5VL_provenance_get_wrap_ctx, /* get_wrap_ctx */
H5VL_provenance_wrap_object, /* wrap_object */
H5VL_provenance_unwrap_object, /* unwrap_object */
H5VL_provenance_free_wrap_ctx, /* free_wrap_ctx */
},
{ /* attribute_cls */
H5VL_provenance_attr_create, /* create */
H5VL_provenance_attr_open, /* open */
H5VL_provenance_attr_read, /* read */
H5VL_provenance_attr_write, /* write */
H5VL_provenance_attr_get, /* get */
H5VL_provenance_attr_specific, /* specific */
H5VL_provenance_attr_optional, /* optional */
H5VL_provenance_attr_close /* close */
},
{ /* dataset_cls */
H5VL_provenance_dataset_create, /* create */
H5VL_provenance_dataset_open, /* open */
H5VL_provenance_dataset_read, /* read */
H5VL_provenance_dataset_write, /* write */
H5VL_provenance_dataset_get, /* get */
H5VL_provenance_dataset_specific, /* specific */
H5VL_provenance_dataset_optional, /* optional */
H5VL_provenance_dataset_close /* close */
},
{ /* datatype_cls */
H5VL_provenance_datatype_commit, /* commit */
H5VL_provenance_datatype_open, /* open */
H5VL_provenance_datatype_get, /* get_size */
H5VL_provenance_datatype_specific, /* specific */
H5VL_provenance_datatype_optional, /* optional */
H5VL_provenance_datatype_close /* close */
},
{ /* file_cls */
H5VL_provenance_file_create, /* create */
H5VL_provenance_file_open, /* open */
H5VL_provenance_file_get, /* get */
H5VL_provenance_file_specific, /* specific */
H5VL_provenance_file_optional, /* optional */
H5VL_provenance_file_close /* close */
},
{ /* group_cls */
H5VL_provenance_group_create, /* create */
H5VL_provenance_group_open, /* open */
H5VL_provenance_group_get, /* get */
H5VL_provenance_group_specific, /* specific */
H5VL_provenance_group_optional, /* optional */
H5VL_provenance_group_close /* close */
},
{ /* link_cls */
H5VL_provenance_link_create, /* create */
H5VL_provenance_link_copy, /* copy */
H5VL_provenance_link_move, /* move */
H5VL_provenance_link_get, /* get */
H5VL_provenance_link_specific, /* specific */
H5VL_provenance_link_optional, /* optional */
},
{ /* object_cls */
H5VL_provenance_object_open, /* open */
H5VL_provenance_object_copy, /* copy */
H5VL_provenance_object_get, /* get */
H5VL_provenance_object_specific, /* specific */
H5VL_provenance_object_optional, /* optional */
},
{ /* introspect_cls */
NULL, /* get_conn_cls */
H5VL_provenance_introspect_get_cap_flags, /* get_cap_flags */
H5VL_provenance_introspect_opt_query, /* opt_query */
},
{ /* request_cls */
H5VL_provenance_request_wait, /* wait */
H5VL_provenance_request_notify, /* notify */
H5VL_provenance_request_cancel, /* cancel */
H5VL_provenance_request_specific, /* specific */
H5VL_provenance_request_optional, /* optional */
H5VL_provenance_request_free /* free */
},
{ /* blobs_cls */
H5VL_provenance_blob_put, /* put */
H5VL_provenance_blob_get, /* get */
H5VL_provenance_blob_specific, /* specific */
H5VL_provenance_blob_optional /* optional */
},
{ /* token_cls */
H5VL_provenance_token_cmp, /* cmp */
H5VL_provenance_token_to_str, /* to_str */
H5VL_provenance_token_from_str /* from_str */
},
H5VL_provenance_optional /* optional */
};
H5PL_type_t H5PLget_plugin_type(void) {return H5PL_TYPE_VOL;}
const void *H5PLget_plugin_info(void) {return &H5VL_provenance_cls;}
/* The connector identification number, initialized at runtime */
static hid_t prov_connector_id_global = H5I_INVALID_HID;
prov_helper_t* prov_helper_init( char* file_path, Prov_level prov_level, char* prov_line_format);
int prov_write(prov_helper_t* helper_in, const char* msg, unsigned long duration);
/* Local routine prototypes */
static hid_t dataset_get_type(void *under_dset, hid_t under_vol_id, hid_t dxpl_id);
static hid_t dataset_get_space(void *under_dset, hid_t under_vol_id, hid_t dxpl_id);
static hid_t dataset_get_dcpl(void *under_dset, hid_t under_vol_id, hid_t dxpl_id);
static ssize_t attr_get_name(void *under_obj, hid_t under_vol_id, hid_t dxpl_id,
size_t buf_size, void *buf);
datatype_prov_info_t *new_dtype_info(file_prov_info_t* root_file,
const char *name, H5O_token_t token);
dataset_prov_info_t *new_dataset_info(file_prov_info_t *root_file,
const char *name, H5O_token_t token);
group_prov_info_t *new_group_info(file_prov_info_t *root_file,
const char *name, H5O_token_t token);
attribute_prov_info_t *new_attribute_info(file_prov_info_t *root_file,
const char *name, H5O_token_t token);
file_prov_info_t *new_file_info(const char* fname, unsigned long file_no);
void dtype_info_free(datatype_prov_info_t* info);
void file_info_free(file_prov_info_t* info);
void group_info_free(group_prov_info_t* info);
void dataset_info_free(dataset_prov_info_t* info);
void attribute_info_free(attribute_prov_info_t *info);
void dataset_stats_prov_write(const dataset_prov_info_t* ds_info);
void file_stats_prov_write(const file_prov_info_t* file_info);
void datatype_stats_prov_write(const datatype_prov_info_t* dt_info);
void group_stats_prov_write(const group_prov_info_t* grp_info);
void attribute_stats_prov_write(const attribute_prov_info_t *attr_info);
void prov_helper_teardown(prov_helper_t* helper);
void file_ds_created(file_prov_info_t* info);
void file_ds_accessed(file_prov_info_t* info);
datatype_prov_info_t *add_dtype_node(file_prov_info_t *file_info,
H5VL_provenance_t *dtype, const char *obj_name, H5O_token_t token);
int rm_dtype_node(prov_helper_t *helper, void *under, hid_t under_vol_id, datatype_prov_info_t *dtype_info);
group_prov_info_t *add_grp_node(file_prov_info_t *root_file,
H5VL_provenance_t *upper_o, const char *obj_name, H5O_token_t token);
int rm_grp_node(prov_helper_t *helper, void *under_obj, hid_t under_vol_id, group_prov_info_t *grp_info);
attribute_prov_info_t *add_attr_node(file_prov_info_t *root_file,
H5VL_provenance_t *attr, const char *obj_name, H5O_token_t token);
int rm_attr_node(prov_helper_t *helper, void *under_obj, hid_t under_vol_id, attribute_prov_info_t *attr_info);
file_prov_info_t* add_file_node(prov_helper_t* helper, const char* file_name, unsigned long file_no);
int rm_file_node(prov_helper_t* helper, unsigned long file_no);
file_prov_info_t* _search_home_file(unsigned long obj_file_no);
dataset_prov_info_t* add_dataset_node(unsigned long obj_file_no, H5VL_provenance_t *dset, H5O_token_t token,
file_prov_info_t* file_info_in, const char* ds_name, hid_t dxpl_id, void** req);
int rm_dataset_node(prov_helper_t *helper, void *under_obj, hid_t under_vol_id, dataset_prov_info_t *dset_info);
void ptr_cnt_increment(prov_helper_t* helper);
void ptr_cnt_decrement(prov_helper_t* helper);
void get_time_str(char *str_out);
dataset_prov_info_t* new_ds_prov_info(void* under_object, hid_t vol_id, H5O_token_t token,
file_prov_info_t* file_info, const char* ds_name, hid_t dxpl_id, void **req);
void _new_loc_pram(H5I_type_t type, H5VL_loc_params_t *lparam);
static int get_native_info(void *obj, H5I_type_t target_obj_type, hid_t connector_id,
hid_t dxpl_id, H5O_info2_t *oinfo);
static int get_native_file_no(const H5VL_provenance_t *file_obj, unsigned long *file_num_out);
herr_t provenance_file_setup(const char* str_in, char* file_path_out, Prov_level* level_out, char* format_out);
H5VL_provenance_t* _fake_obj_new(file_prov_info_t* root_file, hid_t under_vol_id);
void _fake_obj_free(H5VL_provenance_t* obj);
H5VL_provenance_t* _obj_wrap_under(void* under, H5VL_provenance_t* upper_o,
const char *name, H5I_type_t type, hid_t dxpl_id, void** req);
H5VL_provenance_t* _file_open_common(void* under, hid_t vol_id, const char* name);
unsigned int genHash(const char *msg);
void _dic_init(void);
void _dic_print(void);
void _dic_free(void);
void _preset_dic_print(void);
static
unsigned long get_time_usec(void) {
struct timeval tp;
gettimeofday(&tp, NULL);
return (unsigned long)((1000000 * tp.tv_sec) + tp.tv_usec);
}
datatype_prov_info_t *new_dtype_info(file_prov_info_t* root_file,
const char *name, H5O_token_t token)
{
datatype_prov_info_t *info;
info = (datatype_prov_info_t *)calloc(1, sizeof(datatype_prov_info_t));
info->obj_info.prov_helper = PROV_HELPER;
info->obj_info.file_info = root_file;
info->obj_info.name = name ? strdup(name) : NULL;
info->obj_info.token = token;
return info;
}
dataset_prov_info_t *new_dataset_info(file_prov_info_t *root_file,
const char *name, H5O_token_t token)
{
dataset_prov_info_t *info;
info = (dataset_prov_info_t *)calloc(1, sizeof(dataset_prov_info_t));
info->obj_info.prov_helper = PROV_HELPER;
info->obj_info.file_info = root_file;
info->obj_info.name = name ? strdup(name) : NULL;
info->obj_info.token = token;
return info;
}
group_prov_info_t *new_group_info(file_prov_info_t *root_file,
const char *name, H5O_token_t token)
{
group_prov_info_t *info;
info = (group_prov_info_t *)calloc(1, sizeof(group_prov_info_t));
info->obj_info.prov_helper = PROV_HELPER;
info->obj_info.file_info = root_file;
info->obj_info.name = name ? strdup(name) : NULL;
info->obj_info.token = token;
return info;
}
attribute_prov_info_t *new_attribute_info(file_prov_info_t *root_file,
const char *name, H5O_token_t token)
{
attribute_prov_info_t *info;
info = (attribute_prov_info_t *)calloc(1, sizeof(attribute_prov_info_t));
info->obj_info.prov_helper = PROV_HELPER;
info->obj_info.file_info = root_file;
info->obj_info.name = name ? strdup(name) : NULL;
info->obj_info.token = token;
return info;
}
file_prov_info_t* new_file_info(const char* fname, unsigned long file_no)
{
file_prov_info_t *info;
info = (file_prov_info_t *)calloc(1, sizeof(file_prov_info_t));
info->file_name = fname ? strdup(fname) : NULL;
info->prov_helper = PROV_HELPER;
info->file_no = file_no;
return info;
}
void dtype_info_free(datatype_prov_info_t* info)
{
if(info->obj_info.name)
free(info->obj_info.name);
free(info);
}
void file_info_free(file_prov_info_t* info)
{
#ifdef H5_HAVE_PARALLEL
// Release MPI Comm & Info, if they are valid
if(info->mpi_comm_info_valid) {
if(MPI_COMM_NULL != info->mpi_comm)
MPI_Comm_free(&info->mpi_comm);
if(MPI_INFO_NULL != info->mpi_info)
MPI_Info_free(&info->mpi_info);
}
#endif /* H5_HAVE_PARALLEL */
if(info->file_name)
free(info->file_name);
free(info);
}
void group_info_free(group_prov_info_t* info)
{
if(info->obj_info.name)
free(info->obj_info.name);
free(info);
}
void dataset_info_free(dataset_prov_info_t* info)
{
if(info->obj_info.name)
free(info->obj_info.name);
free(info);
}
void attribute_info_free(attribute_prov_info_t* info)
{
if(info->obj_info.name)
free(info->obj_info.name);
free(info);
}
void dataset_stats_prov_write(const dataset_prov_info_t* ds_info){
if(!ds_info){
// printf("dataset_stats_prov_write(): ds_info is NULL.\n");
return;
}
// printf("Dataset name = %s,\ndata type class = %d, data space class = %d, data space size = %llu, data type size =%zu.\n",
// ds_info->dset_name, ds_info->dt_class, ds_info->ds_class, (unsigned long long)ds_info->dset_space_size, ds_info->dset_type_size);
// printf("Dataset is %u dimensions.\n", ds_info->dimension_cnt);
// printf("Dataset is read %d time, %llu bytes in total, costs %llu us.\n", ds_info->dataset_read_cnt, ds_info->total_bytes_read, ds_info->total_read_time);
// printf("Dataset is written %d time, %llu bytes in total, costs %llu us.\n", ds_info->dataset_write_cnt, ds_info->total_bytes_written, ds_info->total_write_time);
}
//not file_prov_info_t!
void file_stats_prov_write(const file_prov_info_t* file_info) {
if(!file_info){
// printf("file_stats_prov_write(): ds_info is NULL.\n");
return;
}
//printf("H5 file closed, %d datasets are created, %d datasets are accessed.\n", file_info->ds_created, file_info->ds_accessed);
}
void datatype_stats_prov_write(const datatype_prov_info_t* dt_info) {
if(!dt_info){
//printf("datatype_stats_prov_write(): ds_info is NULL.\n");
return;
}
//printf("Datatype name = %s, commited %d times, datatype get is called %d times.\n", dt_info->dtype_name, dt_info->datatype_commit_cnt, dt_info->datatype_get_cnt);
}
void group_stats_prov_write(const group_prov_info_t* grp_info) {
if(!grp_info){
//printf("group_stats_prov_write(): grp_info is NULL.\n");
return;
}
//printf("group_stats_prov_write() is yet to be implemented.\n");
}
void attribute_stats_prov_write(const attribute_prov_info_t *attr_info) {
if(!attr_info){
//printf("attribute_stats_prov_write(): attr_info is NULL.\n");
return;
}
//printf("attribute_stats_prov_write() is yet to be implemented.\n");
}
void prov_verify_open_things(int open_files, int open_dsets)
{
if(PROV_HELPER) {
assert(open_files == PROV_HELPER->opened_files_cnt);
/* Check opened datasets */
if(open_files > 0) {
file_prov_info_t* opened_file;
int total_open_dsets = 0;
opened_file = PROV_HELPER->opened_files;
while(opened_file) {
total_open_dsets += opened_file->opened_datasets_cnt;
opened_file = opened_file->next;
}
assert(open_dsets == total_open_dsets);
}
}
}
// need to be fixed if the function got called
void prov_dump_open_things(FILE *f)
{
if(PROV_HELPER) {
file_prov_info_t *opened_file;
unsigned file_count = 0;
fprintf(f, "# of open files: %d\n", PROV_HELPER->opened_files_cnt);
/* Print opened files */
opened_file = PROV_HELPER->opened_files;
while(opened_file) {
dataset_prov_info_t *opened_dataset;
unsigned dset_count = 0;
fprintf(f, "file #%u: info ptr = %p, name = '%s', fileno = %lu\n", file_count, (void *)opened_file, opened_file->file_name, opened_file->file_no);
fprintf(f, "\tref_cnt = %d\n", opened_file->ref_cnt);
/* Print opened datasets */
fprintf(f, "\topened_datasets_cnt = %d\n", opened_file->opened_datasets_cnt);
opened_dataset = opened_file->opened_datasets;
while(opened_dataset) {
// need to be fixed if the function got called
// fprintf(f, "\t\tdataset #%u: name = '%s', objno = %llu\n", dset_count, opened_dataset->obj_info.name, (unsigned long long)opened_dataset->obj_info.objno);
fprintf(f, "\t\t\tfile_info ptr = %p\n", (void *)opened_dataset->obj_info.file_info);
fprintf(f, "\t\t\tref_cnt = %d\n", opened_dataset->obj_info.ref_cnt);
dset_count++;
opened_dataset = opened_dataset->next;
}
fprintf(f, "\topened_grps_cnt = %d\n", opened_file->opened_grps_cnt);
fprintf(f, "\topened_dtypes_cnt = %d\n", opened_file->opened_dtypes_cnt);
fprintf(f, "\topened_attrs_cnt = %d\n", opened_file->opened_attrs_cnt);
file_count++;
opened_file = opened_file->next;
}
}
else
fprintf(f, "PROV_HELPER not initialized\n");
}
prov_helper_t * prov_helper_init( char* file_path, Prov_level prov_level, char* prov_line_format)
{
prov_helper_t* new_helper = (prov_helper_t *)calloc(1, sizeof(prov_helper_t));
if(prov_level >= 2) {//write to file
if(!file_path){
printf("prov_helper_init() failed, provenance file path is not set.\n");
return NULL;
}
}
new_helper->prov_file_path = strdup(file_path);
new_helper->prov_line_format = strdup(prov_line_format);
new_helper->prov_level = prov_level;
new_helper->pid = getpid();
new_helper->tid = pthread_self();
new_helper->opened_files = NULL;
new_helper->opened_files_cnt = 0;
getlogin_r(new_helper->user_name, 32);
if(new_helper->prov_level == File_only || new_helper->prov_level == File_and_print)
new_helper->prov_file_handle = fopen(new_helper->prov_file_path, "a");
_dic_init();
return new_helper;
}
void prov_helper_teardown(prov_helper_t* helper){
if(helper){// not null
char pline[512];
sprintf(pline,
"TOTAL_PROV_OVERHEAD %lu\n"
"TOTAL_NATIVE_H5_TIME %lu\n"
"PROV_WRITE_TOTAL_TIME %lu\n"
"FILE_LL_TOTAL_TIME %lu\n"
"DS_LL_TOTAL_TIME %lu\n"
"GRP_LL_TOTAL_TIME %lu\n"
"DT_LL_TOTAL_TIME %lu\n"
"ATTR_LL_TOTAL_TIME %lu\n",
TOTAL_PROV_OVERHEAD,
TOTAL_NATIVE_H5_TIME,
PROV_WRITE_TOTAL_TIME,
FILE_LL_TOTAL_TIME,
DS_LL_TOTAL_TIME,
GRP_LL_TOTAL_TIME,
DT_LL_TOTAL_TIME,
ATTR_LL_TOTAL_TIME);
switch(helper->prov_level){
case File_only:
fputs(pline, helper->prov_file_handle);
break;
case File_and_print:
fputs(pline, helper->prov_file_handle);
printf("%s", pline);
break;
case Print_only:
printf("%s", pline);
break;
case Level3:
case Level4:
case Disabled:
case Default:
default:
break;
}
if(helper->prov_level == File_only || helper->prov_level ==File_and_print){//no file
fflush(helper->prov_file_handle);
fclose(helper->prov_file_handle);
}
if(helper->prov_file_path)
free(helper->prov_file_path);
if(helper->prov_line_format)
free(helper->prov_line_format);
free(helper);
_dic_free();
}
}
void file_ds_created(file_prov_info_t *info)
{
assert(info);
if(info)
info->ds_created++;
}
//counting how many times datasets are opened in a file.
//Called by a DS
void file_ds_accessed(file_prov_info_t* info)
{
assert(info);
if(info)
info->ds_accessed++;
}
datatype_prov_info_t * add_dtype_node(file_prov_info_t *file_info,
H5VL_provenance_t *dtype, const char *obj_name, H5O_token_t token)
{
unsigned long start = get_time_usec();
datatype_prov_info_t *cur;
int cmp_value;
assert(file_info);
// Find datatype in linked list of opened datatypes
cur = file_info->opened_dtypes;
while (cur) {
if (H5VLtoken_cmp(dtype->under_object, dtype->under_vol_id,
&(cur->obj_info.token), &token, &cmp_value) < 0)
fprintf(stderr, "H5VLtoken_cmp error");
if (cmp_value == 0)
break;
cur = cur->next;
}
if(!cur) {
// Allocate and initialize new datatype node
cur = new_dtype_info(file_info, obj_name, token);
// Increment refcount on file info
file_info->ref_cnt++;
// Add to linked list
cur->next = file_info->opened_dtypes;
file_info->opened_dtypes = cur;
file_info->opened_dtypes_cnt++;
}
// Increment refcount on datatype
cur->obj_info.ref_cnt++;
DT_LL_TOTAL_TIME += (get_time_usec() - start);
return cur;
}
int rm_dtype_node(prov_helper_t *helper, void *under, hid_t under_vol_id, datatype_prov_info_t *dtype_info)
{
unsigned long start = get_time_usec();
file_prov_info_t *file_info;
datatype_prov_info_t *cur;
datatype_prov_info_t *last;
int cmp_value;
// Decrement refcount
dtype_info->obj_info.ref_cnt--;
// If refcount still >0, leave now
if(dtype_info->obj_info.ref_cnt > 0)
return dtype_info->obj_info.ref_cnt;
// Refcount == 0, remove datatype from file info
file_info = dtype_info->obj_info.file_info;
assert(file_info);
assert(file_info->opened_dtypes);
cur = file_info->opened_dtypes;
last = cur;
while(cur) {
if (H5VLtoken_cmp(under, under_vol_id, &(cur->obj_info.token),
&(dtype_info->obj_info.token), &cmp_value) < 0)
fprintf(stderr, "H5VLtoken_cmp error");
if (cmp_value == 0) {
//special case: first node is the target, ==cur
if(cur == file_info->opened_dtypes)
file_info->opened_dtypes = file_info->opened_dtypes->next;
else
last->next = cur->next;
dtype_info_free(cur);
file_info->opened_dtypes_cnt--;
if(file_info->opened_dtypes_cnt == 0)
assert(file_info->opened_dtypes == NULL);
// Decrement refcount on file info
DT_LL_TOTAL_TIME += (get_time_usec() - start);
rm_file_node(helper, file_info->file_no);
return 0;
}
last = cur;
cur = cur->next;
}
DT_LL_TOTAL_TIME += (get_time_usec() - start);
//node not found.
return -1;
}
group_prov_info_t *add_grp_node(file_prov_info_t *file_info,
H5VL_provenance_t *upper_o, const char *obj_name, H5O_token_t token)
{
group_prov_info_t *cur;
unsigned long start = get_time_usec();
assert(file_info);
int cmp_value;
// Find group in linked list of opened groups
cur = file_info->opened_grps;
while (cur) {
if (H5VLtoken_cmp(upper_o->under_object, upper_o->under_vol_id,
&(cur->obj_info.token), &token, &cmp_value) < 0)
fprintf(stderr, "H5VLtoken_cmp error");
if (cmp_value == 0)
break;
cur = cur->next;
}
if(!cur) {
// Allocate and initialize new group node
cur = new_group_info(file_info, obj_name, token);
// Increment refcount on file info
file_info->ref_cnt++;
// Add to linked list