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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* 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 *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* Purpose: The Virtual Object Layer as described in documentation.
* The pupose is to provide an abstraction on how to access the
* underlying HDF5 container, whether in a local file with
* a specific file format, or remotely on other machines, etc...
*/
/****************/
/* Module Setup */
/****************/
#include "H5VLmodule.h" /* This source code file is part of the H5VL module */
/***********/
/* Headers */
/***********/
#include "H5private.h" /* Generic Functions */
#include "H5CXprivate.h" /* API Contexts */
#include "H5Eprivate.h" /* Error handling */
#include "H5FLprivate.h" /* Free lists */
#include "H5Iprivate.h" /* IDs */
#include "H5MMprivate.h" /* Memory management */
#include "H5PLprivate.h" /* Plugins */
#include "H5Tprivate.h" /* Datatypes */
#include "H5VLpkg.h" /* Virtual Object Layer */
/* VOL connectors */
#include "H5VLnative.h" /* Native VOL connector */
#include "H5VLpassthru.h" /* Pass-through VOL connector */
/****************/
/* Local Macros */
/****************/
/******************/
/* Local Typedefs */
/******************/
/* Object wrapping context info */
typedef struct H5VL_wrap_ctx_t {
unsigned rc; /* Ref. count for the # of times the context was set / reset */
const H5VL_t *connector; /* VOL connector for "outermost" class to start wrap */
void *obj_wrap_ctx; /* "wrap context" for outermost connector */
} H5VL_wrap_ctx_t;
/* Information needed for iterating over the registered VOL connector hid_t IDs.
* The name or value of the new VOL connector that is being registered is
* stored in the name (or value) field and the found_id field is initialized to
* H5I_INVALID_HID (-1). If we find a VOL connector with the same name / value,
* we set the found_id field to the existing ID for return to the function.
*/
typedef struct {
/* IN */
H5VL_get_connector_kind_t kind; /* Which kind of connector search to make */
union {
const char *name; /* The name of the VOL connector to check */
H5VL_class_value_t value; /* The value of the VOL connector to check */
} u;
/* OUT */
hid_t found_id; /* The connector ID, if we found a match */
} H5VL_get_connector_ud_t;
/********************/
/* Package Typedefs */
/********************/
/********************/
/* Local Prototypes */
/********************/
static herr_t H5VL__free_cls(H5VL_class_t *cls);
static int H5VL__get_connector_cb(void *obj, hid_t id, void *_op_data);
static herr_t H5VL__set_def_conn(void);
static void *H5VL__wrap_obj(void *obj, H5I_type_t obj_type);
static H5VL_object_t *H5VL__new_vol_obj(H5I_type_t type, void *object,
H5VL_t *vol_connector, hbool_t wrap_obj);
static void *H5VL__object(hid_t id, H5I_type_t obj_type);
/*********************/
/* Package Variables */
/*********************/
/* Package initialization variable */
hbool_t H5_PKG_INIT_VAR = FALSE;
/*****************************/
/* Library Private Variables */
/*****************************/
/*******************/
/* Local Variables */
/*******************/
/* VOL ID class */
static const H5I_class_t H5I_VOL_CLS[1] = {{
H5I_VOL, /* ID class value */
0, /* Class flags */
0, /* # of reserved IDs for class */
(H5I_free_t)H5VL__free_cls /* Callback routine for closing objects of this class */
}};
/* Declare a free list to manage the H5VL_class_t struct */
H5FL_DEFINE_STATIC(H5VL_class_t);
/* Declare a free list to manage the H5VL_t struct */
H5FL_DEFINE(H5VL_t);
/* Declare a free list to manage the H5VL_object_t struct */
H5FL_DEFINE(H5VL_object_t);
/* Declare a free list to manage the H5VL_wrap_ctx_t struct */
H5FL_DEFINE_STATIC(H5VL_wrap_ctx_t);
/* Default VOL connector */
static H5VL_connector_prop_t H5VL_def_conn_s = {-1, NULL};
/*-------------------------------------------------------------------------
* Function: H5VL_init_phase1
*
* Purpose: Initialize the interface from some other package. This should
* be followed with a call to H5VL_init_phase2 after the H5P
* interface is completely set up, finish setting up the H5VL
* information.
*
*
* Return: Success: Non-negative
* Failure: Negative
*
*-------------------------------------------------------------------------
*/
herr_t
H5VL_init_phase1(void)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(FAIL)
/* FUNC_ENTER() does all the work */
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL_init_phase1() */
/*-------------------------------------------------------------------------
* Function: H5VL_init_phase2
*
* Purpose: Finish initializing the interface from some other package.
*
* Note: This is broken out as a separate routine to avoid a circular
* reference with the H5P package.
*
* Return: Success: Non-negative
* Failure: Negative
*
*-------------------------------------------------------------------------
*/
herr_t
H5VL_init_phase2(void)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(FAIL)
/* Set up the default VOL connector in the default FAPL */
if(H5VL__set_def_conn() < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTSET, FAIL, "unable to set default VOL connector")
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL_init_phase2() */
/*-------------------------------------------------------------------------
* Function: H5VL__init_package
*
* Purpose: Initialize interface-specific information
*
* Return: Success: Non-negative
*
* Failure: Negative
*
*-------------------------------------------------------------------------
*/
herr_t
H5VL__init_package(void)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* Initialize the atom group for the VL IDs */
if(H5I_register_type(H5I_VOL_CLS) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, FAIL, "unable to initialize H5VL interface")
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL__init_package() */
/*-------------------------------------------------------------------------
* Function: H5VL_term_package
*
* Purpose: Terminate various H5VL objects
*
* Return: Success: Positive if anything was done that might
* affect other interfaces; zero otherwise.
* Failure: Negative
*
*-------------------------------------------------------------------------
*/
int
H5VL_term_package(void)
{
int n = 0;
FUNC_ENTER_NOAPI_NOINIT_NOERR
if(H5_PKG_INIT_VAR) {
if(H5VL_def_conn_s.connector_id > 0) {
/* Release the default VOL connector */
(void)H5VL_conn_free(&H5VL_def_conn_s);
H5VL_def_conn_s.connector_id = -1;
H5VL_def_conn_s.connector_info = NULL;
n++;
} /* end if */
else {
if(H5I_nmembers(H5I_VOL) > 0) {
/* Unregister all VOL connectors */
(void)H5I_clear_type(H5I_VOL, FALSE, FALSE);
n++;
} /* end if */
else {
/* Destroy the VOL connector ID group */
n += (H5I_dec_type_ref(H5I_VOL) > 0);
/* Mark interface as closed */
if(0 == n)
H5_PKG_INIT_VAR = FALSE;
} /* end else */
} /* end else */
} /* end if */
FUNC_LEAVE_NOAPI(n)
} /* end H5VL_term_package() */
/*-------------------------------------------------------------------------
* Function: H5VL__free_cls
*
* Purpose: Frees a file VOL class struct and returns an indication of
* success. This function is used as the free callback for the
* virtual object layer object identifiers
* (c.f.: H5VL_init_interface).
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
static herr_t
H5VL__free_cls(H5VL_class_t *cls)
{
herr_t ret_value = SUCCEED;
FUNC_ENTER_STATIC
/* Sanity check */
HDassert(cls);
/* Shut down the VOL connector */
if(cls->terminate && cls->terminate() < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTCLOSEOBJ, FAIL, "VOL connector did not terminate cleanly")
/* Release the class */
H5MM_xfree((void *)cls->name); /* Casting away const OK -QAK */
H5FL_FREE(H5VL_class_t, cls);
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL__free_cls() */
/*-------------------------------------------------------------------------
* Function: H5VL__get_connector_cb
*
* Purpose: Callback routine to search through registered VOLs
*
* Return: Success: H5_ITER_STOP if the class and op_data name
* members match. H5_ITER_CONT otherwise.
* Failure: Can't fail
*
* Programmer: Dana Robinson
* June 22, 2017
*
*-------------------------------------------------------------------------
*/
static int
H5VL__get_connector_cb(void *obj, hid_t id, void *_op_data)
{
H5VL_get_connector_ud_t *op_data = (H5VL_get_connector_ud_t *)_op_data; /* User data for callback */
H5VL_class_t *cls = (H5VL_class_t *)obj;
int ret_value = H5_ITER_CONT; /* Callback return value */
FUNC_ENTER_STATIC_NOERR
if(H5VL_GET_CONNECTOR_BY_NAME == op_data->kind) {
if(0 == HDstrcmp(cls->name, op_data->u.name)) {
op_data->found_id = id;
ret_value = H5_ITER_STOP;
} /* end if */
} /* end if */
else {
HDassert(H5VL_GET_CONNECTOR_BY_VALUE == op_data->kind);
if(cls->value == op_data->u.value) {
op_data->found_id = id;
ret_value = H5_ITER_STOP;
} /* end if */
} /* end else */
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL__get_connector_cb() */
/*-------------------------------------------------------------------------
* Function: H5VL__set_def_conn
*
* Purpose: Parses a string that contains the default VOL connector for
* the library.
*
* Note: Usually from the environment variable "HDF5_VOL_CONNECTOR",
* but could be from elsewhere.
*
* Return: Success: 0
* Failure: -1
*
* Programmer: Jordan Henderson
* November 2018
*
*-------------------------------------------------------------------------
*/
static herr_t
H5VL__set_def_conn(void)
{
H5P_genplist_t *def_fapl; /* Default file access property list */
H5P_genclass_t *def_fapclass; /* Default file access property class */
const char *env_var; /* Environment variable for default VOL connector */
char *buf = NULL; /* Buffer for tokenizing string */
hid_t connector_id = -1; /* VOL conntector ID */
void *vol_info = NULL; /* VOL connector info */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_STATIC
/* Sanity check */
HDassert(H5VL_def_conn_s.connector_id == (-1));
HDassert(H5VL_def_conn_s.connector_info == NULL);
/* Check for environment variable set */
env_var = HDgetenv("HDF5_VOL_CONNECTOR");
/* Only parse the string if it's set */
if(env_var && *env_var) {
char *lasts = NULL; /* Context pointer for strtok_r() call */
const char *tok = NULL; /* Token from strtok_r call */
htri_t connector_is_registered; /* Whether connector is already registered */
/* Duplicate the string to parse, as it is modified as we go */
if(NULL == (buf = H5MM_strdup(env_var)))
HGOTO_ERROR(H5E_VOL, H5E_CANTALLOC, FAIL, "can't allocate memory for environment variable string")
/* Get the first 'word' of the environment variable.
* If it's nothing (environment variable was whitespace) return error.
*/
if(NULL == (tok = HDstrtok_r(buf, " \t\n\r", &lasts)))
HGOTO_ERROR(H5E_VOL, H5E_BADVALUE, FAIL, "VOL connector environment variable set empty?")
/* First, check to see if the connector is already registered */
if((connector_is_registered = H5VL__is_connector_registered(tok)) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't check if VOL connector already registered")
else if(connector_is_registered) {
/* Retrieve the ID of the already-registered VOL connector */
if((connector_id = H5VL__get_connector_id(tok, FALSE)) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't get VOL connector ID")
} /* end else-if */
else {
/* Check for VOL connectors that ship with the library */
if(!HDstrcmp(tok, "native")) {
connector_id = H5VL_NATIVE;
if(H5I_inc_ref(connector_id, FALSE) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTINC, FAIL, "can't increment VOL connector refcount")
} /* end if */
else if(!HDstrcmp(tok, "pass_through")) {
connector_id = H5VL_PASSTHRU;
if(H5I_inc_ref(connector_id, FALSE) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTINC, FAIL, "can't increment VOL connector refcount")
} /* end else-if */
else {
/* Register the VOL connector */
/* (NOTE: No provisions for vipl_id currently) */
if((connector_id = H5VL__register_connector_by_name(tok, FALSE, H5P_DEFAULT)) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTREGISTER, FAIL, "can't register connector")
} /* end else */
} /* end else */
/* Was there any connector info specified in the environment variable? */
if(NULL != (tok = HDstrtok_r(NULL, " \t\n\r", &lasts)))
if(H5VL__connector_str_to_info(tok, connector_id, &vol_info) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTDECODE, FAIL, "can't deserialize connector info")
/* Set the default VOL connector */
H5VL_def_conn_s.connector_id = connector_id;
H5VL_def_conn_s.connector_info = vol_info;
} /* end if */
else {
/* Set the default VOL connector */
H5VL_def_conn_s.connector_id = H5_DEFAULT_VOL;
H5VL_def_conn_s.connector_info = NULL;
/* Increment the ref count on the default connector */
if(H5I_inc_ref(H5VL_def_conn_s.connector_id, FALSE) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTINC, FAIL, "can't increment VOL connector refcount")
} /* end else */
/* Get default file access pclass */
if(NULL == (def_fapclass = (H5P_genclass_t *)H5I_object(H5P_FILE_ACCESS)))
HGOTO_ERROR(H5E_VOL, H5E_BADATOM, FAIL, "can't find object for default file access property class ID")
/* Change the default VOL for the default file access pclass */
if(H5P_reset_vol_class(def_fapclass, &H5VL_def_conn_s) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTSET, FAIL, "can't set default VOL connector for default file access property class")
/* Get default file access plist */
if(NULL == (def_fapl = (H5P_genplist_t *)H5I_object(H5P_FILE_ACCESS_DEFAULT)))
HGOTO_ERROR(H5E_VOL, H5E_BADATOM, FAIL, "can't find object for default fapl ID")
/* Change the default VOL for the default FAPL */
if(H5P_set_vol(def_fapl, H5VL_def_conn_s.connector_id, H5VL_def_conn_s.connector_info) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTSET, FAIL, "can't set default VOL connector for default FAPL")
done:
/* Clean up on error */
if(ret_value < 0) {
if(vol_info)
if(H5VL_free_connector_info(connector_id, vol_info) < 0)
HDONE_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "can't free VOL connector info")
if(connector_id >= 0)
/* The H5VL_class_t struct will be freed by this function */
if(H5I_dec_ref(connector_id) < 0)
HDONE_ERROR(H5E_VOL, H5E_CANTDEC, FAIL, "unable to unregister VOL connector")
} /* end if */
/* Clean up */
H5MM_xfree(buf);
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL__set_def_conn() */
/*-------------------------------------------------------------------------
* Function: H5VL__wrap_obj
*
* Purpose: Wraps a library object with possible VOL connector wrappers, to
* match the VOL connector stack for the file.
*
* Return: Success: Wrapped object pointer
* Failure: NULL
*
* Programmer: Quincey Koziol
* Friday, October 7, 2018
*
*-------------------------------------------------------------------------
*/
static void *
H5VL__wrap_obj(void *obj, H5I_type_t obj_type)
{
H5VL_wrap_ctx_t *vol_wrap_ctx = NULL; /* Object wrapping context */
void *ret_value = NULL; /* Return value */
FUNC_ENTER_STATIC
/* Check arguments */
HDassert(obj);
/* Retrieve the VOL object wrapping context */
if(H5CX_get_vol_wrap_ctx((void **)&vol_wrap_ctx) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTGET, NULL, "can't get VOL object wrap context")
/* If there is a VOL object wrapping context, wrap the object */
if(vol_wrap_ctx) {
/* Wrap object, using the VOL callback */
if(NULL == (ret_value = H5VL_wrap_object(vol_wrap_ctx->connector->cls, vol_wrap_ctx->obj_wrap_ctx, obj, obj_type)))
HGOTO_ERROR(H5E_VOL, H5E_CANTGET, NULL, "can't wrap object")
} /* end if */
else
ret_value = obj;
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL__wrap_obj() */
/*-------------------------------------------------------------------------
* Function: H5VL__new_vol_obj
*
* Purpose: Creates a new VOL object, to use when registering an ID.
*
* Return: Success: VOL object pointer
* Failure: NULL
*
* Programmer: Quincey Koziol
* Friday, October 7, 2018
*
*-------------------------------------------------------------------------
*/
static H5VL_object_t *
H5VL__new_vol_obj(H5I_type_t type, void *object, H5VL_t *vol_connector, hbool_t wrap_obj)
{
H5VL_object_t *new_vol_obj = NULL; /* Pointer to new VOL object */
H5VL_object_t *ret_value = NULL; /* Return value */
FUNC_ENTER_STATIC
/* Check arguments */
HDassert(object);
HDassert(vol_connector);
/* Make sure type number is valid */
if(type != H5I_ATTR && type != H5I_DATASET && type != H5I_DATATYPE && type != H5I_FILE && type != H5I_GROUP)
HGOTO_ERROR(H5E_VOL, H5E_BADVALUE, NULL, "invalid type number")
/* Create the new VOL object */
if(NULL == (new_vol_obj = H5FL_CALLOC(H5VL_object_t)))
HGOTO_ERROR(H5E_VOL, H5E_CANTALLOC, NULL, "can't allocate memory for VOL object")
new_vol_obj->connector = vol_connector;
if(wrap_obj) {
if(NULL == (new_vol_obj->data = H5VL__wrap_obj(object, type)))
HGOTO_ERROR(H5E_VOL, H5E_CANTCREATE, NULL, "can't wrap library object")
} /* end if */
else
new_vol_obj->data = object;
/* Bump the reference count on the VOL connector */
vol_connector->nrefs++;
/* If this is a datatype, we have to hide the VOL object under the H5T_t pointer */
if(H5I_DATATYPE == type) {
if(NULL == (ret_value = (H5VL_object_t *)H5T_construct_datatype(new_vol_obj)))
HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, NULL, "can't construct datatype object")
} /* end if */
else
ret_value = (H5VL_object_t *)new_vol_obj;
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL__new_vol_obj() */
/*-------------------------------------------------------------------------
* Function: H5VL_conn_copy
*
* Purpose: Copy VOL connector ID & info.
*
* Note: This is an "in-place" copy.
*
* Return: Success: Non-negative
* Failure: Negative
*
*-------------------------------------------------------------------------
*/
herr_t
H5VL_conn_copy(H5VL_connector_prop_t *connector_prop)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(FAIL)
if(connector_prop) {
/* Copy the connector ID & info, if there is one */
if(connector_prop->connector_id > 0) {
/* Increment the reference count on connector ID and copy connector info */
if(H5I_inc_ref(connector_prop->connector_id, FALSE) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTINC, FAIL, "unable to increment ref count on VOL connector ID")
/* Copy connector info, if it exists */
if(connector_prop->connector_info) {
H5VL_class_t *connector; /* Pointer to connector */
void *new_connector_info = NULL; /* Copy of connector info */
/* Retrieve the connector for the ID */
if(NULL == (connector = (H5VL_class_t *)H5I_object(connector_prop->connector_id)))
HGOTO_ERROR(H5E_PLIST, H5E_BADTYPE, FAIL, "not a VOL connector ID")
/* Allocate and copy connector info */
if(H5VL_copy_connector_info(connector, &new_connector_info, connector_prop->connector_info) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTCOPY, FAIL, "connector info copy failed")
/* Set the connector info to the copy */
connector_prop->connector_info = new_connector_info;
} /* end if */
} /* end if */
} /* end if */
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL_conn_copy() */
/*-------------------------------------------------------------------------
* Function: H5VL_conn_free
*
* Purpose: Free VOL connector ID & info.
*
* Return: Success: Non-negative
* Failure: Negative
*
*-------------------------------------------------------------------------
*/
herr_t
H5VL_conn_free(const H5VL_connector_prop_t *connector_prop)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(FAIL)
if(connector_prop) {
/* Free the connector info (if it exists) and decrement the ID */
if(connector_prop->connector_id > 0) {
if(connector_prop->connector_info)
/* Free the connector info */
if(H5VL_free_connector_info(connector_prop->connector_id, (void *)connector_prop->connector_info) < 0) /* Casting away const OK - QAK */
HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "unable to release VOL connector info object")
/* Decrement reference count for connector ID */
if(H5I_dec_ref(connector_prop->connector_id) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTDEC, FAIL, "can't decrement reference count for connector ID")
} /* end if */
} /* end if */
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL_conn_free() */
/*-------------------------------------------------------------------------
* Function: H5VL_register
*
* Purpose: VOL-aware version of H5I_register. Constructs an H5VL_object_t
* from the passed-in object and registers that. Does the right
* thing with datatypes, which are complicated under the VOL.
*
* Return: Success: A valid HDF5 ID
* Failure: H5I_INVALID_HID
*
*-------------------------------------------------------------------------
*/
hid_t
H5VL_register(H5I_type_t type, void *object, H5VL_t *vol_connector, hbool_t app_ref)
{
H5VL_object_t *vol_obj = NULL; /* VOL object wrapper for library object */
hid_t ret_value = H5I_INVALID_HID; /* Return value */
FUNC_ENTER_NOAPI(H5I_INVALID_HID)
/* Check arguments */
HDassert(object);
HDassert(vol_connector);
/* Set up VOL object for the passed-in data */
/* (Does not wrap object, since it's from a VOL callback) */
if(NULL == (vol_obj = H5VL__new_vol_obj(type, object, vol_connector, FALSE)))
HGOTO_ERROR(H5E_VOL, H5E_CANTCREATE, FAIL, "can't create VOL object")
/* Register VOL object as _object_ type, for future object API calls */
if((ret_value = H5I_register(type, vol_obj, app_ref)) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to atomize handle")
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL_register() */
/*-------------------------------------------------------------------------
* Function: H5VL_register_using_existing_id
*
* Purpose: Registers an OBJECT in a TYPE with the supplied ID for it.
* This routine will check to ensure the supplied ID is not already
* in use, and ensure that it is a valid ID for the given type,
* but will NOT check to ensure the OBJECT is not already
* registered (thus, it is possible to register one object under
* multiple IDs).
*
* NOTE: Intended for use in refresh calls, where we have to close
* and re-open the underlying data, then hook the VOL object back
* up to the original ID.
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
herr_t
H5VL_register_using_existing_id(H5I_type_t type, void *object, H5VL_t *vol_connector, hbool_t app_ref, hid_t existing_id)
{
H5VL_object_t *new_vol_obj = NULL; /* Pointer to new VOL object */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(FAIL)
/* Check arguments */
HDassert(object);
HDassert(vol_connector);
/* Set up VOL object for the passed-in data */
/* (Wraps object, since it's a library object) */
if(NULL == (new_vol_obj = H5VL__new_vol_obj(type, object, vol_connector, TRUE)))
HGOTO_ERROR(H5E_VOL, H5E_CANTCREATE, FAIL, "can't create VOL object")
/* Call the underlying H5I function to complete the registration */
if(H5I_register_using_existing_id(type, new_vol_obj, app_ref, existing_id) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTREGISTER, FAIL, "can't register object under existing ID")
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL_register_using_existing_id() */
/*-------------------------------------------------------------------------
* Function: H5VL_register_using_vol_id
*
* Purpose: Utility function to create a user ID for an object created
* or opened through the VOL. Uses the VOL connector's ID to
* get the connector information instead of it being passed in.
*
* Return: Success: A valid HDF5 ID
* Failure: H5I_INVALID_HID
*
*-------------------------------------------------------------------------
*/
hid_t
H5VL_register_using_vol_id(H5I_type_t type, void *obj, hid_t connector_id, hbool_t app_ref)
{
H5VL_class_t *cls = NULL;
H5VL_t *connector = NULL; /* VOL connector struct */
hid_t ret_value = H5I_INVALID_HID;
FUNC_ENTER_NOAPI(FAIL)
/* Get the VOL class object from the connector's ID */
if(NULL == (cls = (H5VL_class_t *)H5I_object_verify(connector_id, H5I_VOL)))
HGOTO_ERROR(H5E_VOL, H5E_BADTYPE, H5I_INVALID_HID, "not a VOL connector ID")
/* Setup VOL info struct */
if(NULL == (connector = H5FL_CALLOC(H5VL_t)))
HGOTO_ERROR(H5E_VOL, H5E_CANTALLOC, H5I_INVALID_HID, "can't allocate VOL info struct")
connector->cls = cls;
connector->id = connector_id;
if(H5I_inc_ref(connector->id, FALSE) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTINC, H5I_INVALID_HID, "unable to increment ref count on VOL connector")
/* Get an ID for the VOL object */
if((ret_value = H5VL_register(type, obj, connector, app_ref)) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register object handle")
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL_register_using_vol_id() */
/*-------------------------------------------------------------------------
* Function: H5VL_free_object
*
* Purpose: Wrapper to unregister an object ID with a VOL aux struct
* and decrement ref count on VOL connector ID
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
herr_t
H5VL_free_object(H5VL_object_t *vol_obj)
{
herr_t ret_value = SUCCEED;
FUNC_ENTER_NOAPI(SUCCEED)
/* Check arguments */
HDassert(vol_obj);
vol_obj->connector->nrefs --;
if(0 == vol_obj->connector->nrefs) {
if(H5I_dec_ref(vol_obj->connector->id) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTDEC, FAIL, "unable to decrement ref count on VOL connector")
vol_obj->connector = H5FL_FREE(H5VL_t, vol_obj->connector);
} /* end if */
vol_obj = H5FL_FREE(H5VL_object_t, vol_obj);
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL_free_object() */
/*-------------------------------------------------------------------------
* Function: H5VL_register_connector
*
* Purpose: Registers a new VOL connector as a member of the virtual object
* layer class.
*
* Return: Success: A VOL connector ID which is good until the
* library is closed or the connector is unregistered.
*
* Failure: H5I_INVALID_HID
*
* Programmer: Dana Robinson
* June 22, 2017
*
*-------------------------------------------------------------------------
*/
hid_t
H5VL_register_connector(const void *_cls, hbool_t app_ref, hid_t vipl_id)
{
const H5VL_class_t *cls = (const H5VL_class_t *)_cls;
H5VL_class_t *saved = NULL;
hid_t ret_value = H5I_INVALID_HID;
FUNC_ENTER_NOAPI(H5I_INVALID_HID)
/* Check arguments */
HDassert(cls);
/* Copy the class structure so the caller can reuse or free it */
if(NULL == (saved = H5FL_MALLOC(H5VL_class_t)))
HGOTO_ERROR(H5E_VOL, H5E_CANTALLOC, H5I_INVALID_HID, "memory allocation failed for VOL connector class struct")
HDmemcpy(saved, cls, sizeof(H5VL_class_t));
if(NULL == (saved->name = H5MM_strdup(cls->name)))
HGOTO_ERROR(H5E_VOL, H5E_CANTALLOC, H5I_INVALID_HID, "memory allocation failed for VOL connector name")
/* Initialize the VOL connector */
if(cls->initialize && cls->initialize(vipl_id) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, H5I_INVALID_HID, "unable to init VOL connector")
/* Create the new class ID */
if((ret_value = H5I_register(H5I_VOL, saved, app_ref)) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register VOL connector ID")
done:
if(ret_value < 0 && saved) {
if(saved->name)
H5MM_xfree((void *)(saved->name)); /* Casting away const OK -QAK */
H5FL_FREE(H5VL_class_t, saved);
} /* end if */
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL_register_connector() */
/*-------------------------------------------------------------------------
* Function: H5VL__register_connector
*
* Purpose: Registers a new VOL connector as a member of the virtual object
* layer class.
*
* Return: Success: A VOL connector ID which is good until the
* library is closed or the connector is
* unregistered.
*
* Failure: H5I_INVALID_HID
*
* Programmer: Dana Robinson
* June 22, 2017
*
*-------------------------------------------------------------------------
*/
hid_t
H5VL__register_connector(const H5VL_class_t *cls, hbool_t app_ref, hid_t vipl_id)
{
H5VL_get_connector_ud_t op_data; /* Callback info for connector search */
hid_t ret_value = H5I_INVALID_HID; /* Return value */
FUNC_ENTER_PACKAGE
/* Set up op data for iteration */
op_data.kind = H5VL_GET_CONNECTOR_BY_NAME;
op_data.u.name = cls->name;
op_data.found_id = H5I_INVALID_HID;
/* Check if connector is already registered */
if(H5I_iterate(H5I_VOL, H5VL__get_connector_cb, &op_data, TRUE) < 0)
HGOTO_ERROR(H5E_VOL, H5E_BADITER, H5I_INVALID_HID, "can't iterate over VOL IDs")
/* Increment the ref count on the existing VOL connector ID, if it's already registered */
if(op_data.found_id != H5I_INVALID_HID) {
if(H5I_inc_ref(op_data.found_id, app_ref) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTINC, H5I_INVALID_HID, "unable to increment ref count on VOL connector")
ret_value = op_data.found_id;
} /* end if */
else {
/* Create a new class ID */
if((ret_value = H5VL_register_connector(cls, app_ref, vipl_id)) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register VOL connector")
} /* end else */
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL__register_connector() */
/*-------------------------------------------------------------------------
* Function: H5VL__register_connector_by_name
*
* Purpose: Registers a new VOL connector as a member of the virtual object
* layer class.
*
* Return: Success: A VOL connector ID which is good until the
* library is closed or the connector is
* unregistered.
*
* Failure: H5I_INVALID_HID
*
* Programmer: Dana Robinson
* June 22, 2017
*
*-------------------------------------------------------------------------
*/
hid_t
H5VL__register_connector_by_name(const char *name, hbool_t app_ref, hid_t vipl_id)
{
H5VL_get_connector_ud_t op_data; /* Callback info for connector search */
hid_t ret_value = H5I_INVALID_HID; /* Return value */
FUNC_ENTER_PACKAGE
/* Set up op data for iteration */
op_data.kind = H5VL_GET_CONNECTOR_BY_NAME;
op_data.u.name = name;
op_data.found_id = H5I_INVALID_HID;
/* Check if connector is already registered */
if(H5I_iterate(H5I_VOL, H5VL__get_connector_cb, &op_data, TRUE) < 0)
HGOTO_ERROR(H5E_VOL, H5E_BADITER, H5I_INVALID_HID, "can't iterate over VOL ids")
/* If connector alread registered, increment ref count on ID and return ID */
if(op_data.found_id != H5I_INVALID_HID) {
if(H5I_inc_ref(op_data.found_id, app_ref) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTINC, H5I_INVALID_HID, "unable to increment ref count on VOL connector")
ret_value = op_data.found_id;
} /* end if */
else {
H5PL_key_t key;
const H5VL_class_t *cls;
/* Try loading the connector */
key.vol.kind = H5VL_GET_CONNECTOR_BY_NAME;
key.vol.u.name = name;
if(NULL == (cls = (const H5VL_class_t *)H5PL_load(H5PL_TYPE_VOL, &key)))
HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, H5I_INVALID_HID, "unable to load VOL connector")
/* Register the connector we loaded */
if((ret_value = H5VL_register_connector(cls, app_ref, vipl_id)) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register VOL connector ID")
} /* end else */
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL__register_connector_by_name() */
/*-------------------------------------------------------------------------
* Function: H5VL__register_connector_by_value
*
* Purpose: Registers a new VOL connector as a member of the virtual object
* layer class.
*
* Return: Success: A VOL connector ID which is good until the
* library is closed or the connector is
* unregistered.
*
* Failure: H5I_INVALID_HID
*
* Programmer: Dana Robinson
* June 22, 2017
*
*-------------------------------------------------------------------------
*/
hid_t
H5VL__register_connector_by_value(H5VL_class_value_t value, hbool_t app_ref, hid_t vipl_id)
{
H5VL_get_connector_ud_t op_data; /* Callback info for connector search */
hid_t ret_value = H5I_INVALID_HID; /* Return value */
FUNC_ENTER_PACKAGE
/* Set up op data for iteration */
op_data.kind = H5VL_GET_CONNECTOR_BY_VALUE;
op_data.u.value = value;
op_data.found_id = H5I_INVALID_HID;
/* Check if connector is already registered */
if(H5I_iterate(H5I_VOL, H5VL__get_connector_cb, &op_data, TRUE) < 0)
HGOTO_ERROR(H5E_VOL, H5E_BADITER, H5I_INVALID_HID, "can't iterate over VOL ids")
/* If connector alread registered, increment ref count on ID and return ID */
if(op_data.found_id != H5I_INVALID_HID) {
if(H5I_inc_ref(op_data.found_id, app_ref) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTINC, H5I_INVALID_HID, "unable to increment ref count on VOL connector")
ret_value = op_data.found_id;
} /* end if */
else {
H5PL_key_t key;
const H5VL_class_t *cls;
/* Try loading the connector */
key.vol.kind = H5VL_GET_CONNECTOR_BY_VALUE;
key.vol.u.value = value;
if(NULL == (cls = (const H5VL_class_t *)H5PL_load(H5PL_TYPE_VOL, &key)))
HGOTO_ERROR(H5E_VOL, H5E_CANTINIT, H5I_INVALID_HID, "unable to load VOL connector")
/* Register the connector we loaded */
if((ret_value = H5VL_register_connector(cls, app_ref, vipl_id)) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to register VOL connector ID")
} /* end else */
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL__register_connector_by_value() */
/*-------------------------------------------------------------------------
* Function: H5VL__is_connector_registered
*
* Purpose: Checks if a connector with a particular name is registered.
*
* Return: Success: 0
* Failure: -1
*
* Programmer: Dana Robinson
* June 17, 2017
*
*-------------------------------------------------------------------------
*/
htri_t
H5VL__is_connector_registered(const char *name)
{
H5VL_get_connector_ud_t op_data; /* Callback info for connector search */
htri_t ret_value = FALSE; /* Return value */
FUNC_ENTER_PACKAGE
/* Set up op data for iteration */
op_data.kind = H5VL_GET_CONNECTOR_BY_NAME;
op_data.u.name = name;
op_data.found_id = H5I_INVALID_HID;
/* Find connector with name */
if(H5I_iterate(H5I_VOL, H5VL__get_connector_cb, &op_data, TRUE) < 0)
HGOTO_ERROR(H5E_VOL, H5E_BADITER, FAIL, "can't iterate over VOL connectors")
/* Found a connector with that name */
if(op_data.found_id != H5I_INVALID_HID)
ret_value = TRUE;
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL__is_connector_registered() */
/*-------------------------------------------------------------------------
* Function: H5VL__get_connector_id
*
* Purpose: Retrieves the ID for a registered VOL connector.
*
* Return: Positive if the VOL class has been registered
* Negative on error (if the class is not a valid class or not registered)
*
* Programmer: Dana Robinson
* June 17, 2017
*
*-------------------------------------------------------------------------
*/
hid_t
H5VL__get_connector_id(const char *name, hbool_t is_api)
{
H5VL_get_connector_ud_t op_data; /* Callback info for connector search */
hid_t ret_value = H5I_INVALID_HID; /* Return value */
FUNC_ENTER_PACKAGE
/* Set up op data for iteration */
op_data.kind = H5VL_GET_CONNECTOR_BY_NAME;
op_data.u.name = name;
op_data.found_id = H5I_INVALID_HID;
/* Find connector with name */
if(H5I_iterate(H5I_VOL, H5VL__get_connector_cb, &op_data, TRUE) < 0)
HGOTO_ERROR(H5E_VOL, H5E_BADITER, H5I_INVALID_HID, "can't iterate over VOL connectors")
/* Found a connector with that name */
if(op_data.found_id != H5I_INVALID_HID) {
if(H5I_inc_ref(op_data.found_id, is_api) < 0)
HGOTO_ERROR(H5E_FILE, H5E_CANTINC, H5I_INVALID_HID, "unable to increment ref count on VOL connector")
ret_value = op_data.found_id;
} /* end if */
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL__get_connector_id() */
/*-------------------------------------------------------------------------
* Function: H5VL__connector_str_to_info
*
* Purpose: Deserializes a string into a connector's info object
*
* Return: Success: Non-negative
* Failure: Negative
*
* Programmer: Quincey Koziol
* March 2, 2019
*
*-------------------------------------------------------------------------
*/
herr_t
H5VL__connector_str_to_info(const char *str, hid_t connector_id, void **info)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_PACKAGE
/* Only deserialize string, if it's non-NULL */
if(str) {
H5VL_class_t *cls; /* VOL connector's class struct */
/* Check args and get class pointer */
if(NULL == (cls = (H5VL_class_t *)H5I_object_verify(connector_id, H5I_VOL)))
HGOTO_ERROR(H5E_VOL, H5E_BADTYPE, FAIL, "not a VOL connector ID")
/* Allow the connector to deserialize info */
if(cls->info_cls.from_str) {
if((cls->info_cls.from_str)(str, info) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTUNSERIALIZE, FAIL, "can't deserialize connector info")
} /* end if */
else
*info = NULL;
} /* end if */
else
*info = NULL;
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL__connector_str_to_info() */
/*-------------------------------------------------------------------------
* Function: H5VL__get_connector_name
*
* Purpose: Private version of H5VLget_connector_name
*
* Return: Success: The length of the connector name
* Failure: Negative
*
*-------------------------------------------------------------------------
*/
ssize_t
H5VL__get_connector_name(hid_t id, char *name /*out*/, size_t size)
{
H5VL_object_t *vol_obj;
const H5VL_class_t *cls;
size_t len;
ssize_t ret_value = -1;
FUNC_ENTER_PACKAGE
/* get the object pointer */
if (NULL == (vol_obj = H5VL_vol_object(id)))
HGOTO_ERROR(H5E_VOL, H5E_BADTYPE, FAIL, "invalid VOL identifier")
cls = vol_obj->connector->cls;
len = HDstrlen(cls->name);
if(name) {
HDstrncpy(name, cls->name, MIN(len + 1, size));
if(len >= size)
name[size - 1] = '\0';
} /* end if */
/* Set the return value for the API call */
ret_value = (ssize_t)len;
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL__get_connector_name() */
/*-------------------------------------------------------------------------
* Function: H5VL_vol_object
*
* Purpose: Utility function to return the object pointer associated with
* a hid_t. This routine is the same as H5I_object for all types
* except for named datatypes, where the vol_obj is returned that
* is attached to the H5T_t struct.
*
* Return: Success: object pointer
* Failure: NULL
*
*-------------------------------------------------------------------------
*/
H5VL_object_t *
H5VL_vol_object(hid_t id)
{
void *obj = NULL;
H5I_type_t obj_type;
H5VL_object_t *ret_value = NULL;
FUNC_ENTER_NOAPI(NULL)
obj_type = H5I_get_type(id);
if (H5I_FILE == obj_type || H5I_GROUP == obj_type || H5I_ATTR == obj_type ||
H5I_DATASET == obj_type || H5I_DATATYPE == obj_type) {
/* Get the object */
if (NULL == (obj = H5I_object(id)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "invalid identifier")
/* if this is a datatype, get the VOL object attached to the H5T_t struct */
if (H5I_DATATYPE == obj_type)
if (NULL == (obj = H5T_get_named_type((H5T_t *)obj)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a named datatype")
} /* end if */
else
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "invalid identifier type to function")
ret_value = (H5VL_object_t *)obj;
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL_vol_object() */
/*-------------------------------------------------------------------------
* Function: H5VL_object_data
*
* Purpose: Correctly retrieve the 'data' field for a VOL object (H5VL_object),
* even for nested / stacked VOL connectors.
*
* Return: Success: object pointer
* Failure: NULL
*
*-------------------------------------------------------------------------
*/
void *
H5VL_object_data(const H5VL_object_t *vol_obj)
{
void *ret_value = NULL;
FUNC_ENTER_NOAPI_NOINIT_NOERR
/* Check for 'get_object' callback in connector */
if(vol_obj->connector->cls->wrap_cls.get_object)
ret_value = (vol_obj->connector->cls->wrap_cls.get_object)(vol_obj->data);
else
ret_value = vol_obj->data;
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL_object_data() */
/*-------------------------------------------------------------------------
* Function: H5VL__object
*
* Purpose: Internal function to return the VOL object pointer associated
* with an hid_t.
*
* Return: Success: object pointer
* Failure: NULL
*
*-------------------------------------------------------------------------
*/
static void *
H5VL__object(hid_t id, H5I_type_t obj_type)
{
H5VL_object_t *vol_obj = NULL;
void *ret_value = NULL;
FUNC_ENTER_STATIC
/* Get the underlying object */
switch(obj_type) {
case H5I_GROUP:
case H5I_DATASET:
case H5I_FILE:
case H5I_ATTR:
/* get the object */
if (NULL == (vol_obj = (H5VL_object_t *)H5I_object(id)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "invalid identifier")
break;
case H5I_DATATYPE:
{
H5T_t *dt = NULL;
/* get the object */
if (NULL == (dt = (H5T_t *)H5I_object(id)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "invalid identifier")
/* Get the actual datatype object that should be the vol_obj */
if (NULL == (vol_obj = H5T_get_named_type(dt)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "not a named datatype")
break;
}
case H5I_UNINIT:
case H5I_BADID:
case H5I_DATASPACE:
case H5I_VFL:
case H5I_VOL:
case H5I_GENPROP_CLS:
case H5I_GENPROP_LST:
case H5I_ERROR_CLASS:
case H5I_ERROR_MSG:
case H5I_ERROR_STACK:
case H5I_NTYPES:
default:
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "unknown data object type")
} /* end switch */
/* Set the return value */
ret_value = H5VL_object_data(vol_obj);
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL__object() */
/*-------------------------------------------------------------------------
* Function: H5VL_object
*
* Purpose: Utility function to return the VOL object pointer associated with
* a hid_t.
*
* Return: Success: object pointer
* Failure: NULL
*
*-------------------------------------------------------------------------
*/
void *
H5VL_object(hid_t id)
{
void *ret_value = NULL;
FUNC_ENTER_NOAPI(NULL)
/* Get the underlying object */
if(NULL == (ret_value = H5VL__object(id, H5I_get_type(id))))
HGOTO_ERROR(H5E_ARGS, H5E_CANTGET, NULL, "can't retrieve object for ID")
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL_object() */
/*-------------------------------------------------------------------------
* Function: H5VL_object_verify
*
* Purpose: Utility function to return the VOL object pointer associated
* with an identifier.
*
* Return: Success: object pointer
* Failure: NULL
*
*-------------------------------------------------------------------------
*/
void *
H5VL_object_verify(hid_t id, H5I_type_t obj_type)
{
void *ret_value = NULL;
FUNC_ENTER_NOAPI(NULL)
/* Check of ID of correct type */
if(obj_type != H5I_get_type(id))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, NULL, "invalid identifier")
/* Get the underlying object */
if(NULL == (ret_value = H5VL__object(id, obj_type)))
HGOTO_ERROR(H5E_ARGS, H5E_CANTGET, NULL, "can't retrieve object for ID")
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL_object_verify() */
/*-------------------------------------------------------------------------
* Function: H5VL_cmp_connector_cls
*
* Purpose: Compare VOL class for a connector
*
* Note: Sets *cmp_value positive if VALUE1 is greater than VALUE2,
* negative if VALUE2 is greater than VALUE1, and zero if VALUE1
* and VALUE2 are equal (like strcmp).
*
* Return: SUCCEED / FAIL
*
*-------------------------------------------------------------------------
*/
herr_t
H5VL_cmp_connector_cls(int *cmp_value, const H5VL_class_t *cls1, const H5VL_class_t *cls2)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(FAIL)
/* Sanity checks */
HDassert(cls1);
HDassert(cls2);
/* Compare connector "values" */
if(cls1->value < cls2->value) {
*cmp_value = -1;
HGOTO_DONE(SUCCEED)
} /* end if */
if(cls1->value > cls2->value) {
*cmp_value = 1;
HGOTO_DONE(SUCCEED)
} /* end if */
HDassert(cls1->value == cls2->value);
/* Compare connector names */
if(cls1->name == NULL && cls2->name != NULL) {
*cmp_value = -1;
HGOTO_DONE(SUCCEED)
} /* end if */
if(cls1->name != NULL && cls2->name == NULL) {
*cmp_value = 1;
HGOTO_DONE(SUCCEED)
} /* end if */
if(0 != (*cmp_value = HDstrcmp(cls1->name, cls2->name)))
HGOTO_DONE(SUCCEED)
/* Compare connector VOL API versions */
if(cls1->version < cls2->version) {
*cmp_value = -1;
HGOTO_DONE(SUCCEED)
} /* end if */
if(cls1->version > cls2->version) {
*cmp_value = 1;
HGOTO_DONE(SUCCEED)
} /* end if */
HDassert(cls1->version == cls2->version);
/* Compare connector info */
if(cls1->info_cls.size < cls2->info_cls.size) {
*cmp_value = -1;
HGOTO_DONE(SUCCEED)
} /* end if */
if(cls1->info_cls.size > cls2->info_cls.size) {
*cmp_value = 1;
HGOTO_DONE(SUCCEED)
} /* end if */
HDassert(cls1->info_cls.size == cls2->info_cls.size);
/* Set comparison value to 'equal' */
*cmp_value = 0;
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL_cmp_connector_cls() */
/*-------------------------------------------------------------------------
* Function: H5VL_set_vol_wrapper
*
* Purpose: Set up object wrapping context for current VOL connector
*
* Return: SUCCEED / FAIL
*
*-------------------------------------------------------------------------
*/
herr_t
H5VL_set_vol_wrapper(void *obj, const H5VL_t *connector)
{
H5VL_wrap_ctx_t *vol_wrap_ctx = NULL; /* Object wrapping context */
void *obj_wrap_ctx = NULL; /* VOL connector's wrapping context */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(FAIL)
/* Sanity checks */
HDassert(obj);
HDassert(connector);
/* Retrieve the VOL object wrap context */
if(H5CX_get_vol_wrap_ctx((void **)&vol_wrap_ctx) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't get VOL object wrap context")
/* Check for existing wrapping context */
if(NULL == vol_wrap_ctx) {
/* Check if the connector can create a wrap context */
if(connector->cls->wrap_cls.get_wrap_ctx) {
/* Sanity check */
HDassert(connector->cls->wrap_cls.free_wrap_ctx);
/* Get the wrap context from the connector */
if((connector->cls->wrap_cls.get_wrap_ctx)(obj, &obj_wrap_ctx) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't retrieve VOL connector's object wrap context")
} /* end if */
/* Allocate VOL object wrapper context */
if(NULL == (vol_wrap_ctx = H5FL_MALLOC(H5VL_wrap_ctx_t)))
HGOTO_ERROR(H5E_VOL, H5E_CANTALLOC, FAIL, "can't allocate VOL wrap context")
/* Set up VOL object wrapper context */
vol_wrap_ctx->rc = 1;;
vol_wrap_ctx->connector = connector;
vol_wrap_ctx->obj_wrap_ctx = obj_wrap_ctx;
} /* end if */
else
/* Incremeent ref count on existing wrapper context */
vol_wrap_ctx->rc++;
/* Save the wrapper context */
if(H5CX_set_vol_wrap_ctx(vol_wrap_ctx) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTSET, FAIL, "can't set VOL object wrap context")
done:
if(ret_value < 0 && vol_wrap_ctx)
/* Release object wrapping context */
H5FL_FREE(H5VL_wrap_ctx_t, vol_wrap_ctx);
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL_set_vol_wrapper() */
/*-------------------------------------------------------------------------
* Function: H5VL_reset_vol_wrapper
*
* Purpose: Reset object wrapping context for current VOL connector
*
* Return: SUCCEED / FAIL
*
*-------------------------------------------------------------------------
*/
herr_t
H5VL_reset_vol_wrapper(void)
{
H5VL_wrap_ctx_t *vol_wrap_ctx = NULL; /* Object wrapping context */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(FAIL)
/* Retrieve the VOL object wrap context */
if(H5CX_get_vol_wrap_ctx((void **)&vol_wrap_ctx) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTGET, FAIL, "can't get VOL object wrap context")
/* Check for VOL object wrap context */
if(NULL == vol_wrap_ctx)
HGOTO_ERROR(H5E_VOL, H5E_BADVALUE, FAIL, "no VOL object wrap context?")
/* Decrement ref count on wrapping context */
vol_wrap_ctx->rc--;
/* Release context if the ref count drops to zero */
if(0 == vol_wrap_ctx->rc) {
/* If there is a VOL connector object wrapping context, release it */
if(vol_wrap_ctx->obj_wrap_ctx) {
/* Release the VOL connector's object wrapping context */
if((*vol_wrap_ctx->connector->cls->wrap_cls.free_wrap_ctx)(vol_wrap_ctx->obj_wrap_ctx) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTRELEASE, FAIL, "unable to release connector's object wrapping context")
} /* end if */
/* Release object wrapping context */
H5FL_FREE(H5VL_wrap_ctx_t, vol_wrap_ctx);
/* Reset the wrapper context */
if(H5CX_set_vol_wrap_ctx(NULL) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTSET, FAIL, "can't set VOL object wrap context")
} /* end if */
else {
/* Save the updated wrapper context */
if(H5CX_set_vol_wrap_ctx(vol_wrap_ctx) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTSET, FAIL, "can't set VOL object wrap context")
} /* end else */
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL_reset_vol_wrapper() */
/*-------------------------------------------------------------------------
* Function: H5VL_wrap_register
*
* Purpose: Wrap an object and register an ID for it
*
* Return: SUCCEED / FAIL
*
*-------------------------------------------------------------------------
*/
hid_t
H5VL_wrap_register(H5I_type_t type, void *obj, hbool_t app_ref)
{
H5VL_wrap_ctx_t *vol_wrap_ctx = NULL; /* Object wrapping context */
void *new_obj; /* Newly wrapped object */
hid_t ret_value = H5I_INVALID_HID; /* Return value */
FUNC_ENTER_NOAPI(H5I_INVALID_HID)
/* Sanity check */
HDassert(obj);
/* If the datatype is already VOL-managed, the datatype's vol_obj
* field will get clobbered later, so disallow this.
*/
if(type == H5I_DATATYPE)
if(TRUE == H5T_already_vol_managed((const H5T_t *)obj))
HGOTO_ERROR(H5E_VOL, H5E_BADTYPE, H5I_INVALID_HID, "can't wrap an uncommitted datatype")
/* Wrap the object with VOL connector info */
if(NULL == (new_obj = H5VL__wrap_obj(obj, type)))
HGOTO_ERROR(H5E_VOL, H5E_CANTCREATE, H5I_INVALID_HID, "can't wrap library object")
/* Retrieve the VOL object wrapping context */
if(H5CX_get_vol_wrap_ctx((void **)&vol_wrap_ctx) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTGET, H5I_INVALID_HID, "can't get VOL object wrap context")
if(NULL == vol_wrap_ctx || NULL == vol_wrap_ctx->connector)
HGOTO_ERROR(H5E_VOL, H5E_BADVALUE, H5I_INVALID_HID, "VOL object wrap context or its connector is NULL???")
/* Get an ID for the object */
if((ret_value = H5VL_register_using_vol_id(type, new_obj, vol_wrap_ctx->connector->id, app_ref)) < 0)
HGOTO_ERROR(H5E_VOL, H5E_CANTREGISTER, H5I_INVALID_HID, "unable to get an ID for the object")
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5VL_wrap_register() */
|