#include <stdio.h>
#include <stdlib.h>
#include "hdf5.h"
int preprocess();
int create_then_close_file(const char* filename);
#define CHECK_ERR(A) { \
if((A) < 0) {\
printf("Error at %s:%d\n", __func__, __LINE__); \
nerrs ++; \
goto fn_exit; \
} \
}
int main(int argc, char *argv[])
{
int err = 0, nerrs=0;
hid_t native_vol_id = -1, passthru_vol_id = -1;
hid_t file_id = -1, dset_id = -1, fspace_id = -1, mspace_id = -1, fapl_id = -1;
H5VL_pass_through_info_t passthru_info;
hsize_t dims[3] = {4, 6, 24};
int buf[24] = {0};
// the following function creates 2 non-empty HDF5 files:
// exist.h5, test.h5
err = preprocess();
CHECK_ERR(err);
native_vol_id = H5VLget_connector_id_by_name(H5VL_NATIVE_NAME);
CHECK_ERR(native_vol_id);
passthru_vol_id = H5VL_pass_through_register();
CHECK_ERR(passthru_vol_id);
passthru_info.under_vol_id = native_vol_id;
passthru_info.under_vol_info = NULL;
// open test.h5 with modified pass_through VOL
fapl_id = H5Pcreate(H5P_FILE_ACCESS);
CHECK_ERR(fapl_id);
err = H5Pset_vol(fapl_id, passthru_vol_id, &passthru_info);
CHECK_ERR(err);
file_id = H5Fopen("test.h5", H5F_ACC_RDWR, fapl_id);
CHECK_ERR(file_id);
// read dataset "/dset" from test.h5
dset_id = H5Dopen2(file_id, "/dset", H5P_DEFAULT);
CHECK_ERR(dset_id);
fspace_id = H5Screate_simple (2, dims, dims);
CHECK_ERR(fspace_id);
mspace_id = H5Screate_simple (1, &dims[2], &dims[2]);
CHECK_ERR(mspace_id);
err = H5Dread(dset_id, H5T_NATIVE_INT, mspace_id, fspace_id, H5P_DEFAULT, buf);
CHECK_ERR (err)
for (int i = 0; i < 24; i++) {
printf("%d ", buf[i]);
}
printf("\n");
fn_exit:;
if (dset_id >= 0) {
H5Dclose(dset_id);
}
if (fspace_id >= 0) {
H5Sclose(fspace_id);
}
if (mspace_id >= 0) {
H5Sclose(mspace_id);
}
if (file_id >= 0) {
H5Fclose(file_id);
}
if (fapl_id >= 0) {
H5Pclose(fapl_id);
}
if (native_vol_id >= 0) {
H5VLclose(native_vol_id);
}
if (passthru_vol_id >= 0) {
H5VLclose(passthru_vol_id);
}
return 0;
}
// This function creates 2 HDF5 files
int preprocess() {
int err = 0, nerrs = 0, rank = 0;
err = create_then_close_file("exist.h5");
CHECK_ERR(err);
err = create_then_close_file("test.h5");
CHECK_ERR(err);
fn_exit:;
return nerrs;
}
int create_then_close_file(const char* filename) {
hid_t file_id = -1;
hid_t dataset_id = -1, dataspace_id = -1;
hsize_t dims[2] = {4, 6};
int nerrs = 0;
herr_t err;
int data[4][6] = {{1, 2, 3, 4, 5, 6},
{7, 8, 9, 10, 11, 12},
{13, 14, 15, 16, 17, 18},
{19, 20, 21, 22, 23, 24}};
file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
CHECK_ERR(file_id);
dataspace_id = H5Screate_simple(2, dims, NULL);
CHECK_ERR(dataspace_id);
dataset_id = H5Dcreate2(file_id, "/dset", H5T_STD_I32BE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
CHECK_ERR(dataset_id);
err = H5Dwrite(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
CHECK_ERR(err);
err = H5Dclose(dataset_id);
CHECK_ERR(err);
err = H5Sclose(dataspace_id);
CHECK_ERR(err);
err = H5Fclose(file_id);
CHECK_ERR(err);
fn_exit:;
return nerrs;
}
Describe the issue
When developing Log VOL, we encounter a problem that we cannot open a different file (say
exist.h5) inside the read call back that handles a read request to a file, saytest.h5. An error message complaining aboutnot a VOL connector IDwill occur. We'd like to know what is the correct way to open a different HDF5 file inside a VOL's dataset_read callback?Reproduce the issue
We can create a minimal VOL to reproduce the issue by modifying the existing HDF5 pass_through VOL. Only
H5VL_pass_through_dataset_readis modified.Click here to see modified H5VL_pass_through_dataset_read.
Modified codes are surrounded by bracket
{ // extra codes to reproduce the error.MY_CHECK_ERRis defined asClick here to see an application that triggers the error.
Click here to see a simple makefile
Click here to see the error message.
Additional context
We thought the problem was related to those lib_state calls so we also tried calling those functions at different places but with no luck (e.g calling
H5VLrestore_lib_stateright beforeH5VLfile_open).Platform