diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/H5Tref.c | 99 | ||||
-rw-r--r-- | src/H5VLcallback.c | 68 | ||||
-rw-r--r-- | src/H5VLconnector.h | 3 | ||||
-rw-r--r-- | src/H5VLnative_file.c | 13 |
4 files changed, 152 insertions, 31 deletions
diff --git a/src/H5Tref.c b/src/H5Tref.c index 20c6e41..ad00761 100644 --- a/src/H5Tref.c +++ b/src/H5Tref.c @@ -280,10 +280,12 @@ static size_t H5T__ref_mem_getsize(H5VL_object_t H5_ATTR_UNUSED *src_file, const void *src_buf, size_t H5_ATTR_UNUSED src_size, H5VL_object_t *dst_file, hbool_t *dst_copy) { - H5F_t *src_f; - H5F_t *dst_f; H5VL_object_t *vol_obj = NULL; const H5R_ref_priv_t *src_ref = (const H5R_ref_priv_t *)src_buf; + hbool_t files_equal = FALSE; + char file_name_buf_static[256]; + char *file_name_buf_dyn = NULL; + ssize_t file_name_len; unsigned flags = 0; size_t ret_value = 0; @@ -296,27 +298,43 @@ H5T__ref_mem_getsize(H5VL_object_t H5_ATTR_UNUSED *src_file, const void *src_buf if(NULL == (vol_obj = H5VL_vol_object(src_ref->loc_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "invalid location identifier") - /* We should assert here that the terminal connector is H5VL_NATIVE once - * there is a facility to do so -NAF 2019/10/30 */ - - /* Retrieve files from VOL objects */ - if(NULL == (src_f = (H5F_t *)H5VL_object_data(vol_obj))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "invalid VOL object") - if(NULL == (dst_f = (H5F_t *)H5VL_object_data(dst_file))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "invalid VOL object") - /* Set external flag if referenced file is not destination file */ - flags |= (src_f->shared != dst_f->shared) ? H5R_IS_EXTERNAL : 0; + if(H5VL_file_specific(vol_obj, H5VL_FILE_IS_EQUAL, H5P_DATASET_XFER_DEFAULT, NULL, dst_file, &files_equal) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTCOMPARE, 0, "can't check if files are equal") + flags |= files_equal ? H5R_IS_EXTERNAL : 0; /* Force re-calculating encoding size if any flags are set */ if(flags || !src_ref->encode_size) { /* Pass the correct encoding version for the selection depending on the * file libver bounds, this is later retrieved in H5S hyper encode */ - if(src_ref->type == (int8_t)H5R_DATASET_REGION2) - H5CX_set_libver_bounds(dst_f); + if(src_ref->type == (int8_t)H5R_DATASET_REGION2) { + /* Temporary hack to check if this is the native connector. We need to + * add a way to check if the terminal connector is native. For now this + * will break passthroughs, but it's needed for other VOL connectors to + * work. -NAF */ + if(dst_file->connector->cls->value == H5VL_NATIVE_VALUE) { + H5F_t *dst_f; + + if(NULL == (dst_f = (H5F_t *)H5VL_object_data(dst_file))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "invalid VOL object") + H5CX_set_libver_bounds(dst_f); + } /* end if */ + else + H5CX_set_libver_bounds(NULL); + } /* end if */ + + /* Get file name */ + if(H5VL_file_get(vol_obj, H5VL_FILE_GET_NAME, H5P_DATASET_XFER_DEFAULT, NULL, sizeof(file_name_buf_static), file_name_buf_static, &file_name_len) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, 0, "can't get file name") + if(file_name_len >= (ssize_t)sizeof(file_name_buf_static)) { + if(NULL == (file_name_buf_dyn = (char *)H5MM_malloc((size_t)file_name_len + 1))) + HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, 0, "can't allocate space for file name") + if(H5VL_file_get(vol_obj, H5VL_FILE_GET_NAME, H5P_DATASET_XFER_DEFAULT, NULL, (size_t)file_name_len + 1, file_name_buf_dyn, &file_name_len) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, 0, "can't get file name") + } /* end if */ /* Determine encoding size */ - if(H5R__encode(H5F_ACTUAL_NAME(src_f), src_ref, NULL, &ret_value, flags) < 0) + if(H5R__encode(file_name_buf_dyn ? file_name_buf_dyn : file_name_buf_static, src_ref, NULL, &ret_value, flags) < 0) HGOTO_ERROR(H5E_REFERENCE, H5E_CANTENCODE, 0, "unable to determine encoding size") } else { /* Can do a direct copy and skip blob decoding */ @@ -328,6 +346,8 @@ H5T__ref_mem_getsize(H5VL_object_t H5_ATTR_UNUSED *src_file, const void *src_buf } done: + H5MM_xfree(file_name_buf_dyn); + FUNC_LEAVE_NOAPI(ret_value) } /* end H5T__ref_mem_getsize() */ @@ -346,10 +366,12 @@ H5T__ref_mem_read(H5VL_object_t H5_ATTR_UNUSED *src_file, const void *src_buf, size_t H5_ATTR_UNUSED src_size, H5VL_object_t *dst_file, void *dst_buf, size_t dst_size) { - H5F_t *src_f; - H5F_t *dst_f; H5VL_object_t *vol_obj = NULL; const H5R_ref_priv_t *src_ref = (const H5R_ref_priv_t *)src_buf; + hbool_t files_equal = FALSE; + char file_name_buf_static[256]; + char *file_name_buf_dyn = NULL; + ssize_t file_name_len; unsigned flags = 0; herr_t ret_value = SUCCEED; @@ -365,25 +387,41 @@ H5T__ref_mem_read(H5VL_object_t H5_ATTR_UNUSED *src_file, const void *src_buf, if(NULL == (vol_obj = H5VL_vol_object(src_ref->loc_id))) HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "invalid location identifier") - /* We should assert here that the terminal connector is H5VL_NATIVE once - * there is a facility to do so -NAF 2019/10/30 */ - - /* Retrieve files from VOL objects */ - if(NULL == (src_f = (H5F_t *)H5VL_object_data(vol_obj))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "invalid VOL object") - if(NULL == (dst_f = (H5F_t *)H5VL_object_data(dst_file))) - HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "invalid VOL object") - /* Set external flag if referenced file is not destination file */ - flags |= (src_f->shared != dst_f->shared) ? H5R_IS_EXTERNAL : 0; + if(H5VL_file_specific(vol_obj, H5VL_FILE_IS_EQUAL, H5P_DATASET_XFER_DEFAULT, NULL, dst_file, &files_equal) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTCOMPARE, FAIL, "can't check if files are equal") + flags |= files_equal ? H5R_IS_EXTERNAL : 0; /* Pass the correct encoding version for the selection depending on the * file libver bounds, this is later retrieved in H5S hyper encode */ - if(src_ref->type == (int8_t)H5R_DATASET_REGION2) - H5CX_set_libver_bounds(dst_f); + if(src_ref->type == (int8_t)H5R_DATASET_REGION2) { + /* Temporary hack to check if this is the native connector. We need to + * add a way to check if the terminal connector is native. For now this + * will break passthroughs, but it's needed for other VOL connectors to + * work. -NAF */ + if(dst_file->connector->cls->value == H5VL_NATIVE_VALUE) { + H5F_t *dst_f; + + if(NULL == (dst_f = (H5F_t *)H5VL_object_data(dst_file))) + HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, 0, "invalid VOL object") + H5CX_set_libver_bounds(dst_f); + } /* end if */ + else + H5CX_set_libver_bounds(NULL); + } /* end if */ + + /* Get file name */ + if(H5VL_file_get(vol_obj, H5VL_FILE_GET_NAME, H5P_DATASET_XFER_DEFAULT, NULL, sizeof(file_name_buf_static), file_name_buf_static, &file_name_len) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, 0, "can't get file name") + if(file_name_len >= (ssize_t)sizeof(file_name_buf_static)) { + if(NULL == (file_name_buf_dyn = (char *)H5MM_malloc((size_t)file_name_len + 1))) + HGOTO_ERROR(H5E_RESOURCE, H5E_CANTALLOC, 0, "can't allocate space for file name") + if(H5VL_file_get(vol_obj, H5VL_FILE_GET_NAME, H5P_DATASET_XFER_DEFAULT, NULL, (size_t)file_name_len + 1, file_name_buf_dyn, &file_name_len) < 0) + HGOTO_ERROR(H5E_REFERENCE, H5E_CANTGET, 0, "can't get file name") + } /* end if */ /* Encode reference */ - if(H5R__encode(H5F_ACTUAL_NAME(src_f), src_ref, (unsigned char *)dst_buf, &dst_size, flags) < 0) + if(H5R__encode(file_name_buf_dyn ? file_name_buf_dyn : file_name_buf_static, src_ref, (unsigned char *)dst_buf, &dst_size, flags) < 0) HGOTO_ERROR(H5E_REFERENCE, H5E_CANTENCODE, FAIL, "Cannot encode reference") done: @@ -827,3 +865,4 @@ H5T_ref_reclaim(void *elem, const H5T_t *dt) done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5T_ref_reclaim() */ + diff --git a/src/H5VLcallback.c b/src/H5VLcallback.c index 8d7368b..b20494a 100644 --- a/src/H5VLcallback.c +++ b/src/H5VLcallback.c @@ -101,6 +101,8 @@ static void * H5VL__file_open(const H5VL_class_t *cls, const char *name, unsigned flags, hid_t fapl_id, hid_t dxpl_id, void **req); static herr_t H5VL__file_get(void *obj, const H5VL_class_t *cls, H5VL_file_get_t get_type, hid_t dxpl_id, void **req, va_list arguments); +static herr_t H5VL__file_specific_wrap_va_list(void *obj, const H5VL_class_t *cls, + H5VL_file_specific_t specific_type, hid_t dxpl_id, void **req, ...); static herr_t H5VL__file_specific(void *obj, const H5VL_class_t *cls, H5VL_file_specific_t specific_type, hid_t dxpl_id, void **req, va_list arguments); static herr_t H5VL__file_optional(void *obj, const H5VL_class_t *cls, hid_t dxpl_id, @@ -2989,6 +2991,43 @@ done: /*------------------------------------------------------------------------- + * Function: H5VL__file_specific_wrap_va_list + * + * Purpose: Perform File specific operations through the VOL. Just + * starts a va_list and passes it to the connector's + * callback. Needed when the VOL layer needs to replace one + * of the variable arguments. + * + * Return: Success: Non-negative + * Failure: Negative + * + *------------------------------------------------------------------------- + */ +static herr_t +H5VL__file_specific_wrap_va_list(void *obj, const H5VL_class_t *cls, + H5VL_file_specific_t specific_type, hid_t dxpl_id, void **req, ...) +{ + va_list arguments; /* Argument list passed from the API call */ + herr_t ret_value = SUCCEED; /* Return value */ + + FUNC_ENTER_STATIC + + /* Start access to the varargs, so they are available in all situations below */ + HDva_start(arguments, req); + + /* Call the corresponding VOL callback */ + if((cls->file_cls.specific)(obj, specific_type, dxpl_id, req, arguments) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTOPERATE, FAIL, "file specific failed") + +done: + /* End access to the va_list */ + HDva_end(arguments); + + FUNC_LEAVE_NOAPI(ret_value) +} /* end H5VL__file_specific_wrap_va_list() */ + + +/*------------------------------------------------------------------------- * Function: H5VL__file_specific * * Purpose: Perform File specific operations through the VOL @@ -3010,6 +3049,35 @@ H5VL__file_specific(void *obj, const H5VL_class_t *cls, H5VL_file_specific_t spe if(NULL == cls->file_cls.specific) HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "VOL connector has no 'file specific' method") + /* Special handling for file is equal */ + if(specific_type == H5VL_FILE_IS_EQUAL) { + va_list tmp_args; /* Argument list passed from the API call */ + H5VL_object_t *vol_obj2; /* Second VOL object */ + hbool_t *is_equal; /* Output variable */ + int cmp_value; /* Comparison result */ + + /* Get parameters */ + HDva_copy(tmp_args, arguments); + vol_obj2 = HDva_arg(tmp_args, H5VL_object_t *); + is_equal = HDva_arg(tmp_args, hbool_t *); + HDva_end(tmp_args); + + HDassert(vol_obj2); + + /* Compare connector classes */ + if(H5VL_cmp_connector_cls(&cmp_value, cls, vol_obj2->connector->cls) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTCOMPARE, FAIL, "can't compare connector classes") + + /* If the classes are different the files are different */ + if(cmp_value) + *is_equal = FALSE; + else + /* Make callback (need to extract data from vol_obj2 and redo the + * va_list) */ + if(H5VL__file_specific_wrap_va_list(obj, cls, specific_type, dxpl_id, req, vol_obj2->data, is_equal) < 0) + HGOTO_ERROR(H5E_VOL, H5E_CANTOPERATE, FAIL, "file specific failed") + } /* end if */ + /* Call the corresponding VOL callback */ if((cls->file_cls.specific)(obj, specific_type, dxpl_id, req, arguments) < 0) HGOTO_ERROR(H5E_VOL, H5E_CANTOPERATE, FAIL, "file specific failed") diff --git a/src/H5VLconnector.h b/src/H5VLconnector.h index 0012eeb..f0925bf 100644 --- a/src/H5VLconnector.h +++ b/src/H5VLconnector.h @@ -122,7 +122,8 @@ typedef enum H5VL_file_specific_t { H5VL_FILE_MOUNT, /* Mount a file */ H5VL_FILE_UNMOUNT, /* Unmount a file */ H5VL_FILE_IS_ACCESSIBLE, /* Check if a file is accessible */ - H5VL_FILE_DELETE /* Delete a file */ + H5VL_FILE_DELETE, /* Delete a file */ + H5VL_FILE_IS_EQUAL /* Check if two files are the same */ } H5VL_file_specific_t; /* types for group GET callback */ diff --git a/src/H5VLnative_file.c b/src/H5VLnative_file.c index 3bda0b8..588d59f 100644 --- a/src/H5VLnative_file.c +++ b/src/H5VLnative_file.c @@ -418,6 +418,19 @@ H5VL__native_file_specific(void *obj, H5VL_file_specific_t specific_type, break; } + /* Check if two files are the same */ + case H5VL_FILE_IS_EQUAL: + { + H5F_t *file2 = (H5F_t *)HDva_arg(arguments, void *); + hbool_t *is_equal = HDva_arg(arguments, hbool_t *); + + if(!obj || !file2) + *is_equal = FALSE; + else + *is_equal = (((H5F_t *)obj)->shared == file2->shared); + break; + } + default: HGOTO_ERROR(H5E_VOL, H5E_UNSUPPORTED, FAIL, "invalid specific operation") } /* end switch */ |