summaryrefslogtreecommitdiffstats
path: root/src/H5VLiod_util.c
blob: 806e87789e5087740fe4579b0b445ecbbc86a871 (plain)
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
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by The HDF Group.                                               *
 * Copyright by the Board of Trustees of the University of Illinois.         *
 * All rights reserved.                                                      *
 *                                                                           *
 * This file is part of HDF5.  The full HDF5 copyright notice, including     *
 * terms governing use, modification, and redistribution, is contained in    *
 * the files COPYING and Copyright.html.  COPYING can be found at the root   *
 * of the source code distribution tree; Copyright.html can be found at the  *
 * root level of an installed copy of the electronic HDF5 document set and   *
 * is linked from the top-level documents page.  It can also be found at     *
 * http://hdfgroup.org/HDF5/doc/Copyright.html.  If you do not have          *
 * access to either file, you may request a copy from help@hdfgroup.org.     *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#define H5G_PACKAGE		/*suppress error about including H5Gpkg   */

#include "H5Gpkg.h"		/* Groups		  		*/
#include "H5Sprivate.h"		/* Dataspaces		  		*/
#include "H5WBprivate.h"        /* Wrapped Buffers                      */
#include "H5VLiod_server.h"

#ifdef H5_HAVE_EFF

static H5I_type_t H5VL__iod_get_h5_obj_type(iod_obj_id_t oid, iod_handle_t coh, 
                                            iod_trans_id_t rtid, uint32_t cs_scope);

/*
 * Programmer:  Mohamad Chaarawi <chaarawi@hdfgroup.gov>
 *              February, 2013
 *
 * Purpose:	The IOD plugin server utility routines.
 */


/*-------------------------------------------------------------------------
 * Function:	H5VL_iod_server_traverse
 *
 * Purpose: 
 *     Function to Traverse the path in IOD KV objects given the
 *     starting location ID, object handle, and path name. This walks
 *     through the IOD KV objects to get to the last component in the
 *     path. The last component is not opened. Usually this is called when
 *     creating an object. The Function returns the iod ID and object
 *     handle of the before to last component, and the last component
 *     string, if the user requests it.
 *
 * Return:	Success:	SUCCEED 
 *		Failure:	Negative
 *
 *-------------------------------------------------------------------------
 */
herr_t 
H5VL_iod_server_traverse(iod_handle_t coh, iod_obj_id_t loc_id, iod_handles_t loc_handle, 
                         const char *path, iod_trans_id_t wtid, iod_trans_id_t rtid, 
                         hbool_t create_interm_grps, uint32_t cs_scope,
                         /* out */char **last_comp, /* out */iod_obj_id_t *iod_id, 
                         /* out */iod_handles_t *iod_oh)
{
    char comp_buf[1024];     /* Temporary buffer for path components */
    char *comp;              /* Pointer to buffer for path components */
    H5WB_t *wb = NULL;       /* Wrapped buffer for temporary buffer */
    size_t nchars;	     /* component name length	*/
    iod_handles_t cur_oh;
    iod_handle_t prev_oh;
    iod_obj_id_t cur_id;
    iod_ret_t ret;
    herr_t ret_value = SUCCEED;

    /* Creating intermediate groups is not supported for now */
    assert(FALSE == create_interm_grps);

    cur_oh.rd_oh.cookie = loc_handle.rd_oh.cookie;
    cur_oh.wr_oh.cookie = loc_handle.wr_oh.cookie;
    cur_id = loc_id;

    /* open the current group */
    if(cur_oh.rd_oh.cookie == IOD_OH_UNDEFINED) {
        if (iod_obj_open_read(coh, loc_id, wtid, NULL, &cur_oh.rd_oh, NULL) < 0)
            HGOTO_ERROR_FF(FAIL, "can't open current group");
    }

    /* Wrap the local buffer for serialized header info */
    if(NULL == (wb = H5WB_wrap(comp_buf, sizeof(comp_buf))))
        HGOTO_ERROR_FF(FAIL, "can't wrap buffer")
    /* Get a pointer to a buffer that's large enough  */
    if(NULL == (comp = (char *)H5WB_actual(wb, (HDstrlen(path) + 1))))
        HGOTO_ERROR_FF(FAIL, "can't get actual buffer")

    /* Traverse the path */
    while((path = H5G__component(path, &nchars)) && *path) {
        const char *s;                  /* Temporary string pointer */
        iod_size_t kv_size;
        H5VL_iod_link_t value;

        /* Copy the component path into a null-terminated buffer. */
	HDmemcpy(comp, path, nchars);
	comp[nchars] = '\0';

	/*
	 * The special path `.' is a no-op.
	 */
	if('.' == comp[0] && !comp[1]) {
	    path += nchars;
	    continue;
	} /* end if */

        /* Check if this is the last component of the path */
        if(!((s = H5G__component(path + nchars, NULL)) && *s)) {
            if(last_comp) {
                *last_comp = HDstrdup(comp);
            }
            break;
        }

        kv_size = sizeof(H5VL_iod_link_t);

        prev_oh.cookie = cur_oh.rd_oh.cookie;

        /* lookup next object in the current group */
        ret = H5VL_iod_get_metadata(cur_oh.rd_oh, rtid, H5VL_IOD_LINK, 
                                    comp, cs_scope, NULL, &value);
        if(SUCCEED != ret)
            HGOTO_ERROR_FF(ret, "failed to get link value");

        /* if this a soft link, traverse the link value if the ID is undefined */
        if(H5L_TYPE_SOFT == value.link_type) {
            if('/' == *value.u.symbolic_name) {
                cur_id = ROOT_ID;
            }

            /* Traverse Path and open the target object */
            ret = H5VL_iod_server_open_path(coh, cur_id, cur_oh, value.u.symbolic_name, 
                                            rtid, cs_scope, &cur_id, &cur_oh);
            if(SUCCEED != ret)
                HGOTO_ERROR_FF(ret, "failed to traverse object path");

            free(value.u.symbolic_name);
        }
        else
            cur_id = value.u.iod_id;

        /* Close previous read handle unless it is the original one */
        if(loc_handle.rd_oh.cookie != prev_oh.cookie) {
            ret = iod_obj_close(prev_oh, NULL, NULL);
            if(ret < 0)
                HGOTO_ERROR_FF(ret, "failed to close IOD object");
        }

        /* open the current group */
        ret = iod_obj_open_read(coh, cur_id, rtid, NULL, &cur_oh.rd_oh, NULL);
        if(ret < 0)
            HGOTO_ERROR_FF(ret, "failed to open IOD object");

	/* Advance to next component in string */
	path += nchars;
    } /* end while */

    /* Release temporary component buffer */
    if(wb && H5WB_unwrap(wb) < 0)
        HGOTO_ERROR_FF(FAIL, "can't release wrapped buffer");

    *iod_id = cur_id;
    (*iod_oh).rd_oh.cookie = cur_oh.rd_oh.cookie;

    if(cur_id != loc_id ||
       loc_handle.wr_oh.cookie == IOD_OH_UNDEFINED) {
        /* open a write handle on the ID. */
        ret = iod_obj_open_write(coh, cur_id, wtid, NULL, &cur_oh.wr_oh, NULL);
        if(ret < 0)
            HGOTO_ERROR_FF(ret, "can't open IOD object");
    }
        
    (*iod_oh).wr_oh.cookie = cur_oh.wr_oh.cookie;

done:
    return ret_value;
}


/*-------------------------------------------------------------------------
 * Function:	H5VL_iod_server_open_path
 *
 * Purpose: Function to Traverse the path in IOD KV objects given the
 * starting location ID, object handle, and path name. This walks
 * through the IOD KV objects to get to the last component in the path
 * and opens the last component for read only, i.e. does not open the
 * wr_oh, but will set it to undefined. Usually this is called when
 * opening an object.
 *
 * Return:	Success:	SUCCEED 
 *		Failure:	Negative
 *
 *-------------------------------------------------------------------------
 */
herr_t 
H5VL_iod_server_open_path(iod_handle_t coh, iod_obj_id_t loc_id, iod_handles_t loc_handle, 
                          const char *path, iod_trans_id_t rtid, uint32_t cs_scope,
                          /*out*/iod_obj_id_t *iod_id, /*out*/iod_handles_t *iod_oh)
{
    char comp_buf[1024];     /* Temporary buffer for path components */
    char *comp;              /* Pointer to buffer for path components */
    H5WB_t *wb = NULL;       /* Wrapped buffer for temporary buffer */
    size_t nchars;	     /* component name length	*/
    iod_handles_t cur_oh;
    iod_handle_t prev_oh;
    iod_obj_id_t cur_id;
    iod_ret_t ret;
    herr_t ret_value = SUCCEED;

    cur_oh.rd_oh.cookie = loc_handle.rd_oh.cookie;
    cur_oh.wr_oh.cookie = loc_handle.wr_oh.cookie;
    cur_id = loc_id;

    if(cur_oh.rd_oh.cookie == IOD_OH_UNDEFINED) {
        /* open the current group */
        if (iod_obj_open_read(coh, loc_id, rtid, NULL, &cur_oh.rd_oh, NULL) < 0)
            HGOTO_ERROR_FF(FAIL, "can't open start location");
    }

    /* Wrap the local buffer for serialized header info */
    if(NULL == (wb = H5WB_wrap(comp_buf, sizeof(comp_buf))))
        HGOTO_ERROR_FF(FAIL, "can't wrap buffer")
    /* Get a pointer to a buffer that's large enough  */
    if(NULL == (comp = (char *)H5WB_actual(wb, (HDstrlen(path) + 1))))
        HGOTO_ERROR_FF(FAIL, "can't get actual buffer")

    /* Traverse the path */
    while((path = H5G__component(path, &nchars)) && *path) {
        iod_size_t kv_size;
        H5VL_iod_link_t value;

        /* Copy the component path into a null-terminated buffer. */
	HDmemcpy(comp, path, nchars);
	comp[nchars] = '\0';

	/*
	 * The special path `.' is a no-op.
	 */
	if('.' == comp[0] && !comp[1]) {
	    path += nchars;
	    continue;
	} /* end if */

        kv_size = sizeof(H5VL_iod_link_t);

        prev_oh.cookie = cur_oh.rd_oh.cookie;

        /* lookup next object in the current group */
        ret = H5VL_iod_get_metadata(cur_oh.rd_oh, rtid, H5VL_IOD_LINK, 
                                    comp, cs_scope, NULL, &value); 
        if(SUCCEED != ret) {
            /* Close previous handle unless it is the original one */
            if(loc_handle.rd_oh.cookie != prev_oh.cookie && 
               iod_obj_close(prev_oh, NULL, NULL) < 0)
                HGOTO_ERROR_FF(ret, "can't close current object handle");
            HGOTO_ERROR_FF(ret, "failed to retrieve link value");
        }

        /* if this a soft link, traverse the link value if the ID is undefined */
        if(H5L_TYPE_SOFT == value.link_type) {
            if('/' == *value.u.symbolic_name) {
                cur_id = ROOT_ID;
            }

            /* Traverse Path and open the target object */
            ret = H5VL_iod_server_open_path(coh, cur_id, cur_oh, value.u.symbolic_name, 
                                            rtid, cs_scope, &cur_id, &cur_oh);
            if(SUCCEED != ret)
                HGOTO_ERROR_FF(ret, "failed to traverse object path");

            free(value.u.symbolic_name);
        }
        else
            cur_id = value.u.iod_id;

        /* Close previous handle unless it is the original one */
        if(loc_handle.rd_oh.cookie != prev_oh.cookie && 
           iod_obj_close(prev_oh, NULL, NULL) < 0)
            HGOTO_ERROR_FF(FAIL, "can't close current object handle");

        /* open the current group */
        ret = iod_obj_open_read(coh, cur_id, rtid, NULL, &cur_oh.rd_oh, NULL);
        if(ret < 0)
            HGOTO_ERROR_FF(ret, "failed to open IOD object");

	/* Advance to next component in string */
	path += nchars;
    } /* end while */

    /* Release temporary component buffer */
    if(wb && H5WB_unwrap(wb) < 0)
        HGOTO_ERROR_FF(FAIL, "can't release wrapped buffer");

    *iod_id = cur_id;
    (*iod_oh).rd_oh.cookie = cur_oh.rd_oh.cookie;
    (*iod_oh).wr_oh.cookie = IOD_OH_UNDEFINED;

done:
    return ret_value;
}


/*-------------------------------------------------------------------------
 * Function:	H5VL_iod_get_file_desc
 *
 * Purpose: 
 *     Function to generate IOD hyperslab objects from HDF5
 *     dataspace selections. If hslabs is NULL, a count of the number of
 *     hslabs needed is returned in count.
 *
 * Return:	Success:	SUCCEED 
 *		Failure:	Negative
 *
 *-------------------------------------------------------------------------
 */
herr_t 
H5VL_iod_get_file_desc(hid_t space_id, hssize_t *count, iod_hyperslab_t *hslabs)
{
    hssize_t num_descriptors = 0, n;
    int ndims = 0, i;
    herr_t ret_value = SUCCEED;

    /* get the rank of this dataspace */
    if((ndims = H5Sget_simple_extent_ndims(space_id)) < 0)
        HGOTO_ERROR_FF(FAIL, "unable to get dataspace dimesnsion");

    switch(H5Sget_select_type(space_id)) {
    case H5S_SEL_NONE:
        /* nothing selected */
        num_descriptors = 0;
        HGOTO_DONE_FF(SUCCEED);
    case H5S_SEL_ALL:
        /* The entire dataspace is selected, 1 large iod hyperslab is needed */
        num_descriptors = 1;

        if(NULL != hslabs) {
            hsize_t dims[H5S_MAX_RANK];

            /* get the dimensions sizes of the dataspace */
            if(H5Sget_simple_extent_dims(space_id, dims, NULL) < 0)
                HGOTO_ERROR_FF(FAIL, "unable to get dataspace dimesnsion sizes");
            /* populate the hyperslab */
            for(i=0 ; i<ndims ; i++) {
                hslabs[0].start[i] = 0;
                hslabs[0].block[i] = dims[i];
                hslabs[0].stride[i] = dims[i];
                hslabs[0].count[i] = 1;
            }
        }
        break;
    case H5S_SEL_POINTS:
        {
            /* we need a hyperslab element for each point */
            if((num_descriptors = H5Sget_select_elem_npoints(space_id)) < 0)
                HGOTO_ERROR_FF(FAIL, "invalid point selection");

            if(NULL != hslabs) {
                hsize_t *points = NULL;
                size_t point_count = 0;

                point_count = (hsize_t)num_descriptors * (unsigned int)ndims * sizeof(hsize_t);

                if(NULL == (points = (hsize_t *)malloc(point_count)))
                    HGOTO_ERROR_FF(FAIL, "can't allocate array for points coords");

                if(H5Sget_select_elem_pointlist(space_id, (hsize_t)0, 
                                                (hsize_t)num_descriptors, points) < 0)
                    HGOTO_ERROR_FF(FAIL, "Failed to retrieve point coordinates");

                /* populate the hyperslab */
                for(n=0 ; n<num_descriptors ; n++) {
                    hsize_t *cur_ptr = points; /* temp pointer into points array */

                    /* adjust the current pointer to the current point */
                    cur_ptr += n*ndims;
                    for(i=0 ; i<ndims ; i++) {
                        hslabs[n].start[i] = *(cur_ptr+i);
                        hslabs[n].count[i] = 1;
                        hslabs[n].block[i] = 1;
                        hslabs[n].stride[i] = hslabs[n].block[i];
                    }
                }

                free(points);
            }
            break;
        }
    case H5S_SEL_HYPERSLABS:
        {
            /* if the selection is a regular hyperslab
               selection, only 1 iod hyperslab object is
               needed */
            if(TRUE == H5Sselect_is_regular(space_id)) {
                num_descriptors = 1;

                if(NULL != hslabs) {
                    if(H5Sget_reg_hyperslab_params(space_id, 
                                                   hslabs[0].start, 
                                                   hslabs[0].stride,
                                                   hslabs[0].count,
                                                   hslabs[0].block) < 0)
                        HGOTO_ERROR_FF(FAIL, "Failed to retrieve hyperslab selection");
                    for(i=0 ; i<ndims ; i++) {
                        if(hslabs[0].stride[i] == 1)
                            hslabs[0].stride[i] = hslabs[0].block[i];
                    }
                }
            }
            /* Otherwise populate the hslabs by getting every block */
            else {
                if((num_descriptors = H5Sget_select_hyper_nblocks(space_id)) < 0)
                    HGOTO_ERROR_FF(FAIL, "invalid hyperslab selection");

                if(NULL != hslabs) {
                    hsize_t *blocks = NULL;
                    size_t block_count = 0;
                    hsize_t *cur_ptr;

                    block_count = (unsigned int)ndims * (hsize_t)num_descriptors * sizeof(hsize_t) * 2;

                    if(NULL == (blocks = (hsize_t *)malloc(block_count)))
                        HGOTO_ERROR_FF(FAIL, "can't allocate array for points coords");

                    if(H5Sget_select_hyper_blocklist(space_id, (hsize_t)0, 
                                                     (hsize_t)num_descriptors, blocks) < 0)
                        HGOTO_ERROR_FF(FAIL, "Failed to retrieve point coordinates");


                    cur_ptr = blocks; /* temp pointer into blocks array */
                    /* populate the hyperslab */
                    for(n=0 ; n<num_descriptors ; n++) {
                        /* adjust the current pointer to the current block */
                        cur_ptr += n*ndims*2;
                        for(i=0 ; i<ndims ; i++) {
                            hslabs[n].start[i] = *(cur_ptr+i);
                            hslabs[n].count[i] = 1;
                            hslabs[n].block[i] = *(cur_ptr+ndims+i) - hslabs[n].start[i] + 1;
                            hslabs[n].stride[i] = hslabs[n].block[i];
                        }
                    }

#if 0
                    fprintf(stderr, "Space contains %zu elements\n", 
                            (size_t)H5Sget_select_npoints(space_id));
                    for(n=0 ; n<num_descriptors ; n++) {
                        for(i=0 ; i<ndims ; i++) {
                            fprintf(stderr, "DIMS %d: %zu %zu %zu %zu\n", i,
                                    (size_t)hslabs[n].start[i],(size_t)hslabs[n].count[i],
                                    (size_t)hslabs[n].block[i],(size_t)hslabs[n].stride[i]);
                        }
                    }
#endif
                    free(blocks);
                }
            }
            break;
        }
    case H5S_SEL_ERROR:
    case H5S_SEL_N:
    default:
        HGOTO_ERROR_FF(FAIL, "Invalid Selection type");
    }

    *count = num_descriptors;

done:
    return ret_value;
}


/*-------------------------------------------------------------------------
 * Function:	H5VL_iod_insert_plist
 *
 * Purpose:     Function to insert a creation property list in an 
 *              IOD KV object.
 *
 * Return:	Success:	SUCCEED 
 *		Failure:	Negative
 *
 *-------------------------------------------------------------------------
 */
herr_t 
H5VL_iod_insert_plist(iod_handle_t oh, iod_trans_id_t tid, hid_t plist_id,
                      uint32_t cs_scope, iod_hint_list_t *hints, iod_event_t *event)
{
    char *key = NULL;
    void *value = NULL;
    iod_kv_t kv;
    size_t buf_size;
    iod_ret_t ret;
    herr_t ret_value = SUCCEED;

    /* insert group creation properties in Metadata KV */
    key = strdup(H5VL_IOD_KEY_OBJ_CPL);

    /* determine the buffer size needed to store the encoded plist */ 
    if(H5Pencode(plist_id,  NULL, &buf_size) < 0)
        HGOTO_ERROR_FF(FAIL, "failed to encode plist");
    if(NULL == (value = malloc (buf_size)))
        HGOTO_ERROR_FF(FAIL, "can't allocate plist buffer");
    /* encode plist */ 
    if(H5Pencode(plist_id, value, &buf_size) < 0)
        HGOTO_ERROR_FF(FAIL, "failed to encode plist");

    kv.key = (void *)key;
    kv.key_len = (iod_size_t)strlen(key) + 1;
    kv.value = value;
    kv.value_len = (iod_size_t)buf_size;

    if(cs_scope & H5_CHECKSUM_IOD) {
        iod_checksum_t cs[2];

        cs[0] = H5_checksum_crc64(kv.key, kv.key_len);
        cs[1] = H5_checksum_crc64(kv.value, kv.value_len);

#if H5_EFF_DEBUG 
        fprintf(stderr, "PLIST Checksums key = %016lX  value = %016lX\n", cs[0], cs[1]);
#endif

        ret = iod_kv_set(oh, tid, hints, &kv, cs, event);
        if(ret != 0)
            HGOTO_ERROR_FF(ret, "can't set KV pair for plist");
    }
    else {
        ret = iod_kv_set(oh, tid, hints, &kv, NULL, event);
        if(ret != 0)
            HGOTO_ERROR_FF(ret, "can't set KV pair for plist");
    }

done:
    if(key) {
        free(key); 
        key = NULL;
    }
    if(value) {
        free(value); 
        value = NULL;
    }

    return ret_value;
}


/*-------------------------------------------------------------------------
 * Function:	H5VL_iod_insert_link_count
 *
 * Purpose:     Function to insert the link count in an 
 *              IOD KV object.
 *
 * Return:	Success:	SUCCEED 
 *		Failure:	Negative
 *
 *-------------------------------------------------------------------------
 */
herr_t 
H5VL_iod_insert_link_count(iod_handle_t oh, iod_trans_id_t tid, uint64_t count,
                           uint32_t cs_scope, iod_hint_list_t *hints, iod_event_t *event)
{
    char *key = NULL;
    iod_kv_t kv;
    iod_ret_t ret;
    herr_t ret_value = SUCCEED;

    key = strdup(H5VL_IOD_KEY_OBJ_LINK_COUNT);

    kv.key = (void *)key;
    kv.key_len = (iod_size_t)strlen(key) + 1;
    kv.value = &count;
    kv.value_len = sizeof(uint64_t);

    if(cs_scope & H5_CHECKSUM_IOD) {
        iod_checksum_t cs[2];

        cs[0] = H5_checksum_crc64(kv.key, kv.key_len);
        cs[1] = H5_checksum_crc64(kv.value, kv.value_len);

#if H5_EFF_DEBUG 
        fprintf(stderr, "Link Count Checksums key = %016lX  value = %016lX\n", cs[0], cs[1]);
#endif

        ret = iod_kv_set(oh, tid, hints, &kv, cs, event);
        if(ret != 0)
            HGOTO_ERROR_FF(ret, "can't set KV pair for link count");
    }
    else {
        ret = iod_kv_set(oh, tid, hints, &kv, NULL, event);
        if(ret != 0)
            HGOTO_ERROR_FF(ret, "can't set KV pair for link count");
    }

done:
    if(key) {
        free(key); 
        key = NULL;
    }
    return ret_value;
}


/*-------------------------------------------------------------------------
 * Function:	H5VL_iod_insert_object_type
 *
 * Purpose:     Function to insert the object type in an 
 *              IOD KV object.
 *
 * Return:	Success:	SUCCEED 
 *		Failure:	Negative
 *
 *-------------------------------------------------------------------------
 */
herr_t 
H5VL_iod_insert_object_type(iod_handle_t oh, iod_trans_id_t tid, H5I_type_t obj_type,
                            uint32_t cs_scope, iod_hint_list_t *hints, iod_event_t *event)
{
    char *key = NULL;
    iod_kv_t kv;
    iod_ret_t ret;
    herr_t ret_value = SUCCEED;

    key = strdup(H5VL_IOD_KEY_OBJ_TYPE);

    kv.key = (void *)key;
    kv.key_len = (iod_size_t)strlen(key) + 1;
    kv.value = &obj_type;
    kv.value_len = sizeof(int32_t);

    if(cs_scope & H5_CHECKSUM_IOD) {
        iod_checksum_t cs[2];

        cs[0] = H5_checksum_crc64(kv.key, kv.key_len);
        cs[1] = H5_checksum_crc64(kv.value, kv.value_len);

#if H5_EFF_DEBUG 
        fprintf(stderr, "Object Type Checksums key = %016lX  value = %016lX\n", cs[0], cs[1]);
#endif

        ret = iod_kv_set(oh, tid, hints, &kv, cs, event);
        if(ret != 0)
            HGOTO_ERROR_FF(ret, "can't set KV pair for object type");
    }
    else {
        ret = iod_kv_set(oh, tid, hints, &kv, NULL, event);
        if(ret != 0)
            HGOTO_ERROR_FF(ret, "can't set KV pair for object type");
    }

done:
    if(key) {
        free(key); 
        key = NULL;
    }
    return ret_value;
}


/*-------------------------------------------------------------------------
 * Function:	H5VL_iod_insert_datatype
 *
 * Purpose:     Function to insert a datatype in an 
 *              IOD KV object.
 *
 * Return:	Success:	SUCCEED 
 *		Failure:	Negative
 *
 *-------------------------------------------------------------------------
 */
herr_t 
H5VL_iod_insert_datatype(iod_handle_t oh, iod_trans_id_t tid, hid_t type_id,
                         uint32_t cs_scope, iod_hint_list_t *hints, iod_event_t *event)
{
    char *key = NULL;
    void *value = NULL;
    iod_kv_t kv;
    size_t buf_size;
    iod_ret_t ret;
    herr_t ret_value = SUCCEED;

    /* insert group creation properties in Metadata KV */
    key = strdup(H5VL_IOD_KEY_OBJ_DATATYPE);

    /* determine the buffer size needed to store the encoded type */ 
    if(H5Tencode(type_id,  NULL, &buf_size) < 0)
        HGOTO_ERROR_FF(FAIL, "failed to encode type");
    if(NULL == (value = malloc (buf_size)))
        HGOTO_ERROR_FF(FAIL, "can't allocate type buffer");
    /* encode type */ 
    if(H5Tencode(type_id, value, &buf_size) < 0)
        HGOTO_ERROR_FF(FAIL, "failed to encode type");

    kv.key = (void *)key;
    kv.key_len = (iod_size_t)strlen(key) + 1;
    kv.value = value;
    kv.value_len = (iod_size_t)buf_size;

    if(cs_scope & H5_CHECKSUM_IOD) {
        iod_checksum_t cs[2];

        cs[0] = H5_checksum_crc64(kv.key, kv.key_len);
        cs[1] = H5_checksum_crc64(kv.value, kv.value_len);

#if H5_EFF_DEBUG 
        fprintf(stderr, "Datatype Checksums key = %016lX  value = %016lX\n", cs[0], cs[1]);
#endif

        ret = iod_kv_set(oh, tid, hints, &kv, cs, event);
        if(ret != 0)
            HGOTO_ERROR_FF(ret, "can't set KV pair for datatype");
    }
    else {
        ret = iod_kv_set(oh, tid, hints, &kv, NULL, event);
        if(ret != 0)
            HGOTO_ERROR_FF(ret, "can't set KV pair for datatype");
    }

done:
    if(key) {
        free(key); 
        key = NULL;
    }
    if(value) {
        free(value); 
        value = NULL;
    }

    return ret_value;
}


/*-------------------------------------------------------------------------
 * Function:	H5VL_iod_insert_datatype_with_key
 *
 * Purpose:     Function to insert a datatype in an 
 *              IOD KV object.
 *
 * Return:	Success:	SUCCEED 
 *		Failure:	Negative
 *
 *-------------------------------------------------------------------------
 */
herr_t 
H5VL_iod_insert_datatype_with_key(iod_handle_t oh, iod_trans_id_t tid, hid_t type_id, 
                                  const char *key, uint32_t cs_scope, iod_hint_list_t *hints, 
                                  iod_event_t *event)
{
    void *value = NULL;
    iod_kv_t kv;
    size_t buf_size;
    iod_ret_t ret;
    herr_t ret_value = SUCCEED;

    /* determine the buffer size needed to store the encoded type */ 
    if(H5Tencode(type_id,  NULL, &buf_size) < 0)
        HGOTO_ERROR_FF(FAIL, "failed to encode type");
    if(NULL == (value = malloc (buf_size)))
        HGOTO_ERROR_FF(FAIL, "can't allocate type buffer");
    /* encode type */ 
    if(H5Tencode(type_id, value, &buf_size) < 0)
        HGOTO_ERROR_FF(FAIL, "failed to encode type");

    kv.key = (void *)key;
    kv.key_len = (iod_size_t)strlen(key) + 1;
    kv.value = value;
    kv.value_len = (iod_size_t)buf_size;

    if(cs_scope & H5_CHECKSUM_IOD) {
        iod_checksum_t cs[2];

        cs[0] = H5_checksum_crc64(kv.key, kv.key_len);
        cs[1] = H5_checksum_crc64(kv.value, kv.value_len);

#if H5_EFF_DEBUG 
        fprintf(stderr, "Map Datatype Checksums key = %016lX  value = %016lX\n", cs[0], cs[1]);
#endif

        ret = iod_kv_set(oh, tid, hints, &kv, cs, event);
        if(ret != 0)
            HGOTO_ERROR_FF(ret, "can't set KV pair for datatype");
    }
    else {
        ret = iod_kv_set(oh, tid, hints, &kv, NULL, event);
        if(ret != 0)
            HGOTO_ERROR_FF(ret, "can't set KV pair for datatype");
    }

done:
    if(value) {
        free(value); 
        value = NULL;
    }

    return ret_value;
}


/*-------------------------------------------------------------------------
 * Function:	H5VL_iod_insert_dataspace
 *
 * Purpose:     Function to insert a dataspace in an 
 *              IOD KV object.
 *
 * Return:	Success:	SUCCEED 
 *		Failure:	Negative
 *
 *-------------------------------------------------------------------------
 */
herr_t 
H5VL_iod_insert_dataspace(iod_handle_t oh, iod_trans_id_t tid, hid_t space_id,
                          uint32_t cs_scope, iod_hint_list_t *hints, iod_event_t *event)
{
    char *key = NULL;
    void *value = NULL;
    iod_kv_t kv;
    size_t buf_size;
    iod_ret_t ret;
    herr_t ret_value = SUCCEED;

    /* insert group creation properties in Metadata KV */
    key = strdup(H5VL_IOD_KEY_OBJ_DATASPACE);

    /* determine the buffer size needed to store the encoded space */ 
    if(H5Sencode(space_id,  NULL, &buf_size) < 0)
        HGOTO_ERROR_FF(FAIL, "failed to encode space");
    if(NULL == (value = malloc (buf_size)))
        HGOTO_ERROR_FF(FAIL, "can't allocate space buffer");
    /* encode space */ 
    if(H5Sencode(space_id, value, &buf_size) < 0)
        HGOTO_ERROR_FF(FAIL, "failed to encode space");

    kv.key = (void *)key;
    kv.key_len = (iod_size_t)strlen(key) + 1;
    kv.value = value;
    kv.value_len = (iod_size_t)buf_size;

    if(cs_scope & H5_CHECKSUM_IOD) {
        iod_checksum_t cs[2];

        cs[0] = H5_checksum_crc64(kv.key, kv.key_len);
        cs[1] = H5_checksum_crc64(kv.value, kv.value_len);

#if H5_EFF_DEBUG 
        fprintf(stderr, "Dataspace Checksums key = %016lX  value = %016lX\n", cs[0], cs[1]);
#endif

        ret = iod_kv_set(oh, tid, hints, &kv, cs, event);
        if(ret != 0)
            HGOTO_ERROR_FF(ret, "can't set KV pair for dataspace");
    }
    else {
        ret = iod_kv_set(oh, tid, hints, &kv, NULL, event);
        if(ret != 0)
            HGOTO_ERROR_FF(ret, "can't set KV pair for dataspace");
    }

done:
    if(key) {
        free(key); 
        key = NULL;
    }
    if(value) {
        free(value); 
        value = NULL;
    }

    return ret_value;
}


/*-------------------------------------------------------------------------
 * Function:	H5VL_iod_insert_new_link
 *
 * Purpose:     Function to insert a link to another object in an 
 *              IOD KV object.
 *
 * Return:	Success:	SUCCEED 
 *		Failure:	Negative
 *
 *-------------------------------------------------------------------------
 */
herr_t 
H5VL_iod_insert_new_link(iod_handle_t oh, iod_trans_id_t tid, const char *link_name,
                         H5L_type_t link_type, const void *link_val, uint32_t cs_scope, 
                         iod_hint_list_t *hints, iod_event_t *event)
{
    iod_kv_t kv;
    void  *value = NULL;
    uint8_t *val_ptr = NULL;
    size_t value_len;
    iod_ret_t ret;
    herr_t ret_value = SUCCEED;

    switch(link_type) {
        case H5L_TYPE_HARD:
            {
                value_len = sizeof(H5L_type_t) + sizeof(iod_obj_id_t);
                value = malloc(value_len);

                val_ptr = (uint8_t *)value;

                memcpy(val_ptr, &link_type, sizeof(H5L_type_t));
                memcpy(val_ptr+sizeof(H5L_type_t), link_val, sizeof(iod_obj_id_t));

                break;
            }
        case H5L_TYPE_SOFT:
            {
                value_len = sizeof(H5L_type_t) + strlen((const char *)link_val) + 1;
                value = malloc(value_len);

                val_ptr = (uint8_t *)value;

                memcpy(val_ptr, &link_type, sizeof(H5L_type_t));
                strcpy((char *)(val_ptr+sizeof(H5L_type_t)), (const char *)link_val);

                break;
            }
        case H5L_TYPE_ERROR:
        case H5L_TYPE_EXTERNAL:
        case H5L_TYPE_MAX:
        default:
            HGOTO_ERROR_FF(FAIL, "unsupported link type");
    }

    kv.key = (void *)link_name;
    kv.key_len = (iod_size_t)strlen(link_name) + 1;
    kv.value = value;
    kv.value_len = value_len;

    if(cs_scope & H5_CHECKSUM_IOD) {
        iod_checksum_t cs[2];

        cs[0] = H5_checksum_crc64(kv.key, kv.key_len);
        cs[1] = H5_checksum_crc64(kv.value, kv.value_len);

#if H5_EFF_DEBUG 
        fprintf(stderr, "Link Type Checksums key = %016lX  value = %016lX\n", cs[0], cs[1]);
#endif

        ret = iod_kv_set(oh, tid, hints, &kv, cs, event);
        if(ret != 0)
            HGOTO_ERROR_FF(ret, "can't set KV pair for link");
    }
    else {
        ret = iod_kv_set(oh, tid, hints, &kv, NULL, event);
        if(ret != 0)
            HGOTO_ERROR_FF(ret, "can't set KV pair for link");
    }

done:

    if(value)
        free(value);

    return ret_value;
}


/*-------------------------------------------------------------------------
 * Function:	H5VL_iod_get_metadata
 *
 * Purpose:     Function to retrieve a particular metadata value from an
 *              IOD KV object.
 *
 * Return:	Success:	SUCCEED 
 *		Failure:	Negative
 *
 *-------------------------------------------------------------------------
 */
herr_t 
H5VL_iod_get_metadata(iod_handle_t oh, iod_trans_id_t tid, H5VL_iod_metadata_t md_type,
                      const char *key, uint32_t cs_scope, iod_event_t *event, void *md_value)
{
    iod_size_t key_size = strlen(key) + 1;
    iod_size_t val_size = 0;
    void *value = NULL;
    iod_checksum_t *iod_cs = NULL;
    iod_ret_t ret;
    herr_t ret_value = SUCCEED;

    if(cs_scope & H5_CHECKSUM_IOD) {
        iod_cs = (iod_checksum_t *)malloc(sizeof(iod_checksum_t) * 2);
    }

    switch(md_type) {
    case H5VL_IOD_PLIST:
        {
            hid_t plist_id;

            ret = iod_kv_get_value(oh, tid, key, key_size, NULL, &val_size, NULL, event);
            if(ret != 0)
                HGOTO_ERROR_FF(ret, "plist lookup failed");

            if(NULL == (value = malloc((size_t)val_size)))
                HGOTO_ERROR_FF(FAIL, "can't allocate value buffer");

            ret = iod_kv_get_value(oh, tid, key, key_size, (char *)value, &val_size, iod_cs, event);
            if(ret != 0)
                HGOTO_ERROR_FF(ret, "plist lookup failed");

            if((plist_id = H5Pdecode(value)) < 0)
                HGOTO_ERROR_FF(FAIL, "failed to decode cpl");

            *((hid_t *)md_value) = plist_id;
            break;
        }
    case H5VL_IOD_LINK_COUNT:
        val_size = sizeof(uint64_t);
        if(NULL == (value = malloc((size_t)val_size)))
            HGOTO_ERROR_FF(FAIL, "can't allocate value buffer");

        ret = iod_kv_get_value(oh, tid, key, key_size, (char *)value, &val_size, iod_cs, event);
        if(ret != 0)
            HGOTO_ERROR_FF(ret, "link_count lookup failed");

        memcpy(md_value, value, val_size);
        break;
    case H5VL_IOD_DATATYPE:
        {
            hid_t type_id;

            ret = iod_kv_get_value(oh, tid, key, key_size, NULL, &val_size, NULL, event);
            if(ret != 0)
                HGOTO_ERROR_FF(ret, "datatype lookup failed");

            if(NULL == (value = malloc((size_t)val_size)))
                HGOTO_ERROR_FF(FAIL, "can't allocate value buffer");

            ret = iod_kv_get_value(oh, tid, key, key_size, (char *)value, &val_size, iod_cs, event);
            if(ret != 0)
                HGOTO_ERROR_FF(ret, "datatype lookup failed");

            if((type_id = H5Tdecode(value)) < 0)
                HGOTO_ERROR_FF(FAIL, "failed to decode datatype");

            *((hid_t *)md_value) = type_id;
            break;
        }
    case H5VL_IOD_DATASPACE:
        {
            hid_t space_id;

            ret = iod_kv_get_value(oh, tid, key, key_size, NULL, &val_size, NULL, event);
            if(ret != 0)
                HGOTO_ERROR_FF(ret, "dataspace lookup failed");

            if(NULL == (value = malloc((size_t)val_size)))
                HGOTO_ERROR_FF(FAIL, "can't allocate value buffer");

            ret = iod_kv_get_value(oh, tid, key, key_size, (char *)value, &val_size, iod_cs, event);
            if(ret != 0)
                HGOTO_ERROR_FF(ret, "dataspace lookup failed");

            if((space_id = H5Sdecode(value)) < 0)
                HGOTO_ERROR_FF(FAIL, "failed to decode dataspace");

            *((hid_t *)md_value) = space_id;
            break;
        }
    case H5VL_IOD_OBJECT_TYPE:
        val_size = sizeof(int32_t);
        if(NULL == (value = malloc((size_t)val_size)))
            HGOTO_ERROR_FF(FAIL, "can't allocate value buffer");

        ret = iod_kv_get_value(oh, tid, key, key_size, (char *)value, &val_size, iod_cs, event);
        if(ret != 0)
            HGOTO_ERROR_FF(ret, "object type lookup failed");

        memcpy(md_value, value, val_size);
        break;
    case H5VL_IOD_LINK:
        {
            H5VL_iod_link_t *iod_link = (H5VL_iod_link_t *)md_value;
            uint8_t *val_ptr;

            ret = iod_kv_get_value(oh, tid, key, key_size, NULL, &val_size, NULL, event);
            if(ret != 0) {
                fprintf(stderr, "failed to get link %s\n", key);
                HGOTO_ERROR_FF(ret, "link lookup failed");
            }

            if(NULL == (value = malloc((size_t)val_size)))
                HGOTO_ERROR_FF(FAIL, "can't allocate value buffer");

            ret = iod_kv_get_value(oh, tid, key, key_size, (char *)value, &val_size, iod_cs, event);
            if(ret != 0){
                fprintf(stderr, "failed to get link %s\n", key);
                HGOTO_ERROR_FF(ret, "link lookup failed");
            }

            val_ptr = (uint8_t *)value;

            iod_link->link_type = *((H5L_type_t *)val_ptr);
            val_ptr += sizeof(H5L_type_t);

            switch(iod_link->link_type) {
                case H5L_TYPE_HARD:
                    iod_link->u.iod_id = *((iod_obj_id_t *)val_ptr);
                    break;
                case H5L_TYPE_SOFT:
                    iod_link->u.symbolic_name = strdup((char *)val_ptr);
                    break;
                case H5L_TYPE_ERROR:
                case H5L_TYPE_EXTERNAL:
                case H5L_TYPE_MAX:
                default:
                    HGOTO_ERROR_FF(FAIL, "unsupported link type");
            }
            break;
        }
    default:
        HGOTO_ERROR_FF(FAIL, "invalide metadata type");
    }

    if(cs_scope & H5_CHECKSUM_IOD) {
        iod_checksum_t cs[2];

        cs[0] = H5_checksum_crc64(key, key_size);
        cs[1] = H5_checksum_crc64(value, val_size);

#if H5_EFF_DEBUG 
        fprintf(stderr, "Key CS iod = %016lX computed = %016lX\n", iod_cs[0], cs[0]);
        fprintf(stderr, "Value CS iod = %016lX computed = %016lX\n", iod_cs[1], cs[1]);
#endif
        if(iod_cs[0] != cs[0] || iod_cs[1] != cs[1])
            HGOTO_ERROR_FF(FAIL, "Corruption detected when reading metadata from IOD");
    }

done:
    if(value) {
        free(value); 
        value = NULL;
    }

    if(iod_cs) {
        free(iod_cs);
        iod_cs = NULL;
    }

    return ret_value;
}


/*-------------------------------------------------------------------------
 * Function:    H5VL__iod_server_adjust_buffer
 *
 * Checks datatypes to see if type conversion is required, if
 * yes, the buffer is resized accordingly.
 *
 * Return:	Success:	SUCCEED 
 *		Failure:	Negative
 *
 * Programmer:  Mohamad Chaarawi
 *              August, 2013
 *
 *-------------------------------------------------------------------------
 */
herr_t
H5VL__iod_server_adjust_buffer(hid_t mem_type_id, hid_t dset_type_id, size_t nelmts, 
                               hid_t UNUSED dxpl_id, na_bool_t is_coresident, size_t size, void **buf, 
                               hbool_t *is_vl_data, size_t *_buf_size)
{
    herr_t ret_value = SUCCEED;

    if(H5VL__iod_server_type_is_vl(dset_type_id, is_vl_data) < 0)
        HGOTO_ERROR_FF(FAIL, "failed to check dataype");

    if(!(*is_vl_data)) {
        hsize_t buf_size = 0;
        size_t mem_type_size, dset_type_size;

        /* retrieve source and destination datatype sizes for data conversion */
        mem_type_size = H5Tget_size(mem_type_id);
        dset_type_size = H5Tget_size(dset_type_id);

        /* adjust buffer size for data conversion */
        if(mem_type_size < dset_type_size) {
            buf_size = dset_type_size * nelmts;

            /* if we are coresident, and buffer extension is
               required, make a new buffer so we don't mess
               with the user buffer. */
            if(is_coresident) {
                void *new_buf = NULL;

                if(NULL == (new_buf = malloc((size_t)buf_size)))
                    HGOTO_ERROR_FF(FAIL, "Can't malloc new buffer for DT conversion");
                memcpy(new_buf, *buf, size);
                *buf = new_buf;
            }
            else {
                if(NULL == (*buf = realloc(*buf, (size_t)buf_size)))
                    HGOTO_ERROR_FF(FAIL, "Can't adjust buffer for DT conversion");
            }
#if H5_EFF_DEBUG
            fprintf(stderr, "Adjusted Buffer size for dt conversion from %zu to %lld\n", 
                    size, buf_size);
#endif
        }
        else {
            buf_size = mem_type_size * nelmts;
            if(buf_size != size)
                HGOTO_ERROR_FF(FAIL, "Incoming data size is not equal to expected size");
        }

        *_buf_size = buf_size;
    }
    else {
        *_buf_size = size;
    }

done:
    return ret_value;
} /* end H5VL__iod_server_adjust_buffer */


/*-------------------------------------------------------------------------
 * Function:    H5VL__iod_server_type_is_vl
 *
 *              Checks datatypes to see if it's Variable length.
 *
 * Return:	Success:	SUCCEED 
 *		Failure:	Negative
 *
 * Programmer:  Mohamad Chaarawi
 *              August, 2013
 *
 *-------------------------------------------------------------------------
 */
herr_t
H5VL__iod_server_type_is_vl(hid_t type_id, hbool_t *is_vl_data)
{
    herr_t ret_value = SUCCEED;

    switch(H5Tget_class(type_id)) {
        case H5T_STRING:
            if(H5Tis_variable_str(type_id)) {
                *is_vl_data = TRUE;
                break;
            }
        case H5T_INTEGER:
        case H5T_FLOAT:
        case H5T_TIME:
        case H5T_BITFIELD:
        case H5T_OPAQUE:
        case H5T_ENUM:
        case H5T_ARRAY:
        case H5T_NO_CLASS:
        case H5T_REFERENCE:
        case H5T_NCLASSES:
        case H5T_COMPOUND:
            *is_vl_data = FALSE;
            break;
        case H5T_VLEN:
            *is_vl_data = TRUE;
            break;
        default:
            HGOTO_ERROR_FF(FAIL, "unsupported datatype");
    }

done:
    return ret_value;
} /* end H5VL__iod_server_type_is_vl */


/*-------------------------------------------------------------------------
 * Function:	H5VL_iod_verify_scratch_pad
 *
 * Purpose:     Function to insert the link count in an 
 *              IOD KV object.
 *
 * Return:	Success:	SUCCEED 
 *		Failure:	Negative
 *
 *-------------------------------------------------------------------------
 */
herr_t 
H5VL_iod_verify_scratch_pad(scratch_pad *sp, iod_checksum_t iod_cs)
{
    iod_checksum_t computed_cs = 0;
    herr_t ret_value = SUCCEED;

    computed_cs = H5_checksum_crc64(sp, sizeof(scratch_pad));

    if(computed_cs != iod_cs) {
        fprintf(stderr, "Scratch pad integrity check failed. IOD cs = %"PRIu64", Computed cs = %"PRIu64"\n",
                iod_cs, computed_cs);
        ret_value = FAIL;
    }

    return ret_value;
} /* end H5VL_iod_verify_scratch_pad() */

herr_t
H5VL_iod_verify_kv_pair(void *key, iod_size_t key_size, void *value, iod_size_t val_size, 
                        iod_checksum_t *iod_cs)
{
    iod_checksum_t cs[2];
    herr_t ret_value = SUCCEED;

    cs[0] = H5_checksum_crc64(key, key_size);
    cs[1] = H5_checksum_crc64(value, val_size);

#if H5_EFF_DEBUG 
    fprintf(stderr, "Key CS iod = %016lX computed = %016lX\n", iod_cs[0], cs[0]);
    fprintf(stderr, "Value CS iod = %016lX computed = %016lX\n", iod_cs[1], cs[1]);
#endif

    if(iod_cs[0] != cs[0] && iod_cs[1] != cs[1])
        HGOTO_ERROR_FF(FAIL, "Corruption detected in IOD KV pair");

done:
    return ret_value;
} /* H5VL_iod_verify_kv_pair */


/*-------------------------------------------------------------------------
 * Function:	H5VL__iod_get_h5_obj_type
 *
 * Purpose:     Function to retrieve the HDF5 object type of an IOD object.
 *
 * Return:	Success:	SUCCEED 
 *		Failure:	Negative
 *
 *-------------------------------------------------------------------------
 */
static H5I_type_t 
H5VL__iod_get_h5_obj_type(iod_obj_id_t oid, iod_handle_t coh, iod_trans_id_t rtid, uint32_t cs_scope)
{
    iod_handle_t mdkv_oh, oh;
    H5I_type_t obj_type;
    iod_obj_type_t iod_type;
    herr_t ret_value = -1;

    iod_type = IOD_OBJID_GETTYPE(oid);

    if(IOD_OBJ_ARRAY == iod_type)
        obj_type = H5I_DATASET;
    else if(IOD_OBJ_BLOB == iod_type)
        obj_type = H5I_DATATYPE;
    else {
        scratch_pad sp;
        iod_checksum_t sp_cs = 0;

        if (iod_obj_open_read(coh, oid, rtid, NULL /*hints*/, &oh, NULL) < 0)
            HGOTO_ERROR_FF(FAIL, "can't open object");

        /* get scratch pad of the object */
        if(iod_obj_get_scratch(oh, rtid, &sp, &sp_cs, NULL) < 0)
            HGOTO_ERROR_FF(FAIL, "can't get scratch pad for object");
        if(sp_cs && (cs_scope & H5_CHECKSUM_IOD)) {
            /* verify scratch pad integrity */
            if(H5VL_iod_verify_scratch_pad(&sp, sp_cs) < 0)
                HGOTO_ERROR_FF(FAIL, "Scratch Pad failed integrity check");
        }

        /* open the metadata KV */
        if (iod_obj_open_read(coh, sp[0], rtid, NULL /*hints*/, &mdkv_oh, NULL) < 0)
            HGOTO_ERROR_FF(FAIL, "can't open MDKV");

        if(H5VL_iod_get_metadata(mdkv_oh, rtid, H5VL_IOD_OBJECT_TYPE, H5VL_IOD_KEY_OBJ_TYPE,
                                 cs_scope, NULL, &obj_type) < 0)
            HGOTO_ERROR_FF(FAIL, "failed to retrieve link count");

        if(iod_obj_close(mdkv_oh, NULL, NULL) < 0)
            HGOTO_ERROR_FF(FAIL, "can't close current object handle");
        if(iod_obj_close(oh, NULL, NULL) < 0)
            HGOTO_ERROR_FF(FAIL, "can't close current object handle");
    }

    ret_value = obj_type;

done:
    return ret_value;
} /* end H5VL__iod_get_h5_obj_type() */


/*-------------------------------------------------------------------------
 * Function:	H5VL_iod_server_iterate
 *
 * Purpose: 
 *
 * Return:	Success:	SUCCEED 
 *		Failure:	Negative
 *
 *-------------------------------------------------------------------------
 */
herr_t 
H5VL_iod_server_iterate(iod_handle_t coh, iod_obj_id_t obj_id, iod_trans_id_t rtid,
                        H5I_type_t obj_type, const char *link_name, const char *attr_name, 
                        uint32_t cs_scope, H5VL_iterate_op_t op, void *op_data)
{
    iod_handle_t obj_oh;
    herr_t ret;
    herr_t ret_value = SUCCEED;

    ret = (*op)(coh, obj_id, rtid, obj_type, link_name, attr_name, cs_scope, op_data);
    if(ret != 0)
        HGOTO_ERROR_FF(FAIL, "can't apply iterate callback on current object");

    if (iod_obj_open_read(coh, obj_id, rtid, NULL, &obj_oh, NULL) < 0)
        HGOTO_ERROR_FF(FAIL, "can't open current group");

    /* Get the object type, if it is not a group do not check for links */
    if(H5I_GROUP == obj_type || H5I_FILE == obj_type) {
        int num_entries = 0;

        /* Get the object ID and iterate into every member in the group */
        ret = iod_kv_get_num(obj_oh, rtid, &num_entries, NULL);
        if(ret != 0)
            HGOTO_ERROR_FF(FAIL, "can't get number of KV entries");

        if(0 != num_entries) {
            iod_kv_params_t *kvs = NULL;
            iod_kv_t *kv = NULL;
            iod_checksum_t *oid_cs = NULL;
            iod_ret_t *oid_ret = NULL;
            int i;

            kvs = (iod_kv_params_t *)malloc(sizeof(iod_kv_params_t) * (size_t)num_entries);
            kv = (iod_kv_t *)malloc(sizeof(iod_kv_t) * (size_t)num_entries);
            oid_cs = (iod_checksum_t *)malloc(sizeof(iod_checksum_t) * (size_t)num_entries);
            oid_ret = (iod_ret_t *)malloc(sizeof(iod_ret_t) * (size_t)num_entries);

            for(i=0 ; i<num_entries ; i++) {
                kv[i].key = malloc(IOD_KV_KEY_MAXLEN);
                kv[i].key_len = IOD_KV_KEY_MAXLEN;
                kvs[i].kv = &kv[i];
                kvs[i].cs = &oid_cs[i];
                kvs[i].ret = &oid_ret[i];
            }

            ret = iod_kv_list_key(obj_oh, rtid, NULL, 0, &num_entries, kvs, NULL);
            if(ret != 0)
                HGOTO_ERROR_FF(FAIL, "can't get list of keys");

            for(i=0 ; i<num_entries ; i++) {
                H5I_type_t otype;
                iod_obj_id_t oid;
                H5VL_iod_link_t value;

                /* lookup object in the current group */
                ret = H5VL_iod_get_metadata(obj_oh, rtid, H5VL_IOD_LINK, 
                                            (char *)(kv[i].key), cs_scope, NULL, &value);
                if(SUCCEED != ret)
                    HGOTO_ERROR_FF(ret, "failed to retrieve link value");

                if(H5L_TYPE_SOFT == value.link_type) {
                    continue;
                }
                else
                    oid = value.u.iod_id;

#if H5_EFF_DEBUG
                fprintf(stderr, "Iterating into %s OID %"PRIx64"\n", ((char *)kv[i].key), oid);
#endif

                /* Get the object type. */
                if((otype = H5VL__iod_get_h5_obj_type(oid, coh, rtid, cs_scope)) < 0)
                    HGOTO_ERROR_FF(FAIL, "can't get object type");

                if(H5VL_iod_server_iterate(coh, oid, rtid, otype, ((char *)kv[i].key), 
                                           NULL, cs_scope, op, op_data) < 0)
                    HGOTO_ERROR_FF(FAIL, "can't iterate into current object");
            }

            for(i=0 ; i<num_entries ; i++) {
                free(kv[i].key);
            }

            free(kv);
            free(oid_cs);
            free(oid_ret);
            free(kvs);
        }
    }

    ret_value = ret;

done:
    iod_obj_close(obj_oh, NULL, NULL);
    return ret_value;
} /* H5VL_iod_server_iterate */

void
print_iod_obj_map(iod_obj_map_t *obj_map)
{
    int i;
    uint32_t u;

    fprintf(stderr, "MAP: oid: %"PRIx64"   type: %d\n", obj_map->oid, obj_map->type);
    fprintf(stderr, "n_bb_loc %d:\n", obj_map->n_bb_loc);
    for (i = 0; i < obj_map->n_bb_loc ; i++) {
        iod_bb_loc_info_t *info = obj_map->bb_loc_infos[i];
        int j;

        fprintf(stderr, "Shadow path: %s  nrank = %d:\n", info->shadow_path, info->nrank);
        for(j=0 ; j<info->nrank; j++)
            fprintf(stderr, "%d ", info->direct_ranks[j]);
        fprintf(stderr, "\n");
    }
    fprintf(stderr, "n_central_loc %d:\n", obj_map->n_central_loc);
    for (i = 0; i < obj_map->n_central_loc ; i++) {
        iod_central_loc_info_t *info = obj_map->central_loc_infos[i];
        int j;

        fprintf(stderr, "Shard ID: %u  nrank = %d:\n", info->shard_id, info->nrank);
        for(j=0 ; j<info->nrank; j++)
            fprintf(stderr, "%d ", info->nearest_ranks[j]);
        fprintf(stderr, "\n");
    }
    switch(obj_map->type) {
    case IOD_OBJ_BLOB:
        {
            fprintf(stderr, "nranges = %d\n", obj_map->u_map.blob_map.n_range);
            for(u = 0; u < obj_map->u_map.blob_map.n_range ; u++) {
                fprintf(stderr, 
                        "offset: %"PRIu64"  length: %zu  location: %d  index: %d  nearest rank: %d\n",
                        obj_map->u_map.blob_map.blob_range[u].offset, 
                        obj_map->u_map.blob_map.blob_range[u].len,
                        obj_map->u_map.blob_map.blob_range[u].loc_type, 
                        obj_map->u_map.blob_map.blob_range[u].loc_index,
                        obj_map->u_map.blob_map.blob_range[u].nearest_rank);
            }
            break;
        }
    case IOD_OBJ_ARRAY:
        {
            fprintf(stderr, "nranges = %d\n", obj_map->u_map.array_map.n_range);
            for(u = 0; u < obj_map->u_map.array_map.n_range ; u++) {
                fprintf(stderr, 
                        "location: %d  index: %d  nearest rank: %d\n",
                        obj_map->u_map.array_map.array_range[u].loc_type,
                        obj_map->u_map.array_map.array_range[u].loc_index,
                        obj_map->u_map.array_map.array_range[u].nearest_rank);
                fprintf(stderr, "start [%"PRIu64"] end [%"PRIu64"]\n",
                        obj_map->u_map.array_map.array_range[u].start_cell[0],
                        obj_map->u_map.array_map.array_range[u].end_cell[0]);
            }
            break;
        }
        break;
    case IOD_OBJ_KV:
    case IOD_OBJ_INVALID:
    case IOD_OBJ_ANY:
    default:
        break;
    }
}
#if 0
herr_t
H5VL_iod_map_type_convert(hid_t src_id, hid_t dst_id, void *buf, size_t buf_size)
{
    H5T_class_t class;
    herr_t ret_value = SUCCEED;

    class = H5Tget_class(src_id);
    if(H5T_VLEN == class || (H5T_STRING == class && H5Tis_variable_str(src_id)))
        HGOTO_ERROR_FF(FAIL, "Can't convert VL or string types");

    class = H5Tget_class(dset_id);
    if(H5T_VLEN == class || (H5T_STRING == class && H5Tis_variable_str(dst_id)))
        HGOTO_ERROR_FF(FAIL, "Can't convert VL or string types");

    /* Check (and do) Type conversion on the Key */
    src_size = H5Tget_size(src_id);
    dst_size = H5Tget_size(dst_id);

    /* adjust buffer size for datatype conversion */
    if(src_size < dst_size) {
        new_size = dst_size;
        if(NULL == (*buf = realloc(*buf, new_size)))
            HGOTO_ERROR_FF(FAIL, "Can't adjust buffer for DT conversion");
    }
    else {
        new_size = src_size;
    }

    if(NULL == (key_buf = malloc((size_t)key_size)))
        HGOTO_ERROR_FF(FAIL, "can't allocate buffer");
    memcpy(key_buf, key.buf, src_size);

    if(H5Tconvert(src_id, dst_id, 1, key_buf, NULL, dxpl_id) < 0)
        HGOTO_ERROR_FF(FAIL, "data type conversion failed")

done:
    return ret_value;
}
#endif
#endif /* H5_HAVE_EFF */