Skip to content

Commit

Permalink
Brings the native implementation of H5Fdelete() from Bitbucket (#524)
Browse files Browse the repository at this point in the history
* Committing clang-format changes

* Brings the native VFD H5Fdelete() implementation from Bitbucket

Only brings the 'del' callbacks, not the 'open/close' scheme.

* Formatter changes

* Committing clang-format changes

* Fixes direct VFD callback name

* Removes UNUSED macro from family API call

* Adds barrier and rank 0 check to MPI-I/O VFD delete

* Revert "Adds barrier and rank 0 check to MPI-I/O VFD delete"

This reverts commit 909765f.

* Revert "Revert "Adds barrier and rank 0 check to MPI-I/O VFD delete""

This reverts commit 9b04bef.

* Adds a second barrier after the delete in MPI-I/O VFD

* Only delete files in the core VFD when the backing store flag is set

* Fixes string issues in multi VFD

Also, h5test.c cleanup code now uses H5Fdelete().

* Formatted source

* Rework fapl checks for MPI-I/O VFD delete callback

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and lrknox committed May 3, 2021
1 parent 42d2a48 commit 38d1b12
Show file tree
Hide file tree
Showing 24 changed files with 713 additions and 201 deletions.
34 changes: 34 additions & 0 deletions src/H5FD.c
Original file line number Diff line number Diff line change
Expand Up @@ -1886,3 +1886,37 @@ H5FDdriver_query(hid_t driver_id, unsigned long *flags /*out*/)
done:
FUNC_LEAVE_API(ret_value)
} /* end H5FDdriver_query() */

/*-------------------------------------------------------------------------
* Function: H5FDdelete
*
* Purpose: Deletes a file
*
* Return: Non-negative on success/Negative on failure
*
*-------------------------------------------------------------------------
*/
herr_t
H5FDdelete(const char *filename, hid_t fapl_id)
{
herr_t ret_value = SUCCEED;

FUNC_ENTER_API(FAIL)
H5TRACE2("e", "*si", filename, fapl_id);

/* Check arguments */
if (!filename || !*filename)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "no file name specified")

if (H5P_DEFAULT == fapl_id)
fapl_id = H5P_FILE_ACCESS_DEFAULT;
else if (TRUE != H5P_isa_class(fapl_id, H5P_FILE_ACCESS))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file access property list")

/* Call private function */
if (H5FD_delete(filename, fapl_id) < 0)
HGOTO_ERROR(H5E_VFL, H5E_CANTDELETEFILE, FAIL, "unable to delete file")

done:
FUNC_LEAVE_API(ret_value)
} /* end H5FDdelete() */
35 changes: 35 additions & 0 deletions src/H5FDcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ static herr_t H5FD__core_flush(H5FD_t *_file, hid_t dxpl_id, hbool_t closing);
static herr_t H5FD__core_truncate(H5FD_t *_file, hid_t dxpl_id, hbool_t closing);
static herr_t H5FD__core_lock(H5FD_t *_file, hbool_t rw);
static herr_t H5FD__core_unlock(H5FD_t *_file);
static herr_t H5FD__core_delete(const char *filename, hid_t fapl_id);

static const H5FD_class_t H5FD_core_g = {
"core", /* name */
Expand Down Expand Up @@ -181,6 +182,7 @@ static const H5FD_class_t H5FD_core_g = {
H5FD__core_truncate, /* truncate */
H5FD__core_lock, /* lock */
H5FD__core_unlock, /* unlock */
H5FD__core_delete, /* del */
H5FD_FLMAP_DICHOTOMY /* fl_map */
};

Expand Down Expand Up @@ -1708,3 +1710,36 @@ H5FD__core_unlock(H5FD_t *_file)
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD__core_unlock() */

/*-------------------------------------------------------------------------
* Function: H5FD__core_delete
*
* Purpose: Delete a file
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
static herr_t
H5FD__core_delete(const char *filename, hid_t fapl_id)
{
const H5FD_core_fapl_t *fa = NULL;
H5P_genplist_t * plist; /* Property list pointer */
herr_t ret_value = SUCCEED; /* Return value */

FUNC_ENTER_STATIC

HDassert(filename);

if (NULL == (plist = (H5P_genplist_t *)H5I_object(fapl_id)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file access property list")
if (NULL == (fa = (const H5FD_core_fapl_t *)H5P_peek_driver_info(plist)))
HGOTO_ERROR(H5E_PLIST, H5E_BADVALUE, FAIL, "bad VFL driver info")

if (fa->backing_store)
if (HDremove(filename) < 0)
HSYS_GOTO_ERROR(H5E_VFL, H5E_CANTDELETEFILE, FAIL, "unable to delete file")

done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD__core_delete() */
27 changes: 27 additions & 0 deletions src/H5FDdirect.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ static herr_t H5FD__direct_write(H5FD_t *_file, H5FD_mem_t type, hid_t fapl_id,
static herr_t H5FD__direct_truncate(H5FD_t *_file, hid_t dxpl_id, hbool_t closing);
static herr_t H5FD__direct_lock(H5FD_t *_file, hbool_t rw);
static herr_t H5FD__direct_unlock(H5FD_t *_file);
static herr_t H5FD__direct_delete(const char *filename, hid_t fapl_id);

static const H5FD_class_t H5FD_direct_g = {
"direct", /* name */
Expand Down Expand Up @@ -170,6 +171,7 @@ static const H5FD_class_t H5FD_direct_g = {
H5FD__direct_truncate, /* truncate */
H5FD__direct_lock, /* lock */
H5FD__direct_unlock, /* unlock */
H5FD__direct_delete, /* del */
H5FD_FLMAP_DICHOTOMY /* fl_map */
};

Expand Down Expand Up @@ -1380,4 +1382,29 @@ H5FD__direct_unlock(H5FD_t *_file)
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD__direct_unlock() */

/*-------------------------------------------------------------------------
* Function: H5FD__direct_delete
*
* Purpose: Delete a file
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
static herr_t
H5FD__direct_delete(const char *filename, hid_t H5_ATTR_UNUSED fapl_id)
{
herr_t ret_value = SUCCEED; /* Return value */

FUNC_ENTER_STATIC

HDassert(filename);

if (HDremove(filename) < 0)
HSYS_GOTO_ERROR(H5E_VFL, H5E_CANTDELETEFILE, FAIL, "unable to delete file")

done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD__direct_delete() */

#endif /* H5_HAVE_DIRECT */
147 changes: 120 additions & 27 deletions src/H5FDfamily.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,40 +101,42 @@ static herr_t H5FD__family_flush(H5FD_t *_file, hid_t dxpl_id, hbool_t closing)
static herr_t H5FD__family_truncate(H5FD_t *_file, hid_t dxpl_id, hbool_t closing);
static herr_t H5FD__family_lock(H5FD_t *_file, hbool_t rw);
static herr_t H5FD__family_unlock(H5FD_t *_file);
static herr_t H5FD__family_delete(const char *filename, hid_t fapl_id);

/* The class struct */
static const H5FD_class_t H5FD_family_g = {
"family", /* name */
HADDR_MAX, /* maxaddr */
H5F_CLOSE_WEAK, /* fc_degree */
"family", /* name */
HADDR_MAX, /* maxaddr */
H5F_CLOSE_WEAK, /* fc_degree */
H5FD__family_term, /* terminate */
H5FD__family_sb_size, /* sb_size */
H5FD__family_sb_encode, /* sb_encode */
H5FD__family_sb_decode, /* sb_decode */
sizeof(H5FD_family_fapl_t), /* fapl_size */
H5FD__family_fapl_get, /* fapl_get */
H5FD__family_fapl_copy, /* fapl_copy */
H5FD__family_fapl_free, /* fapl_free */
0, /* dxpl_size */
NULL, /* dxpl_copy */
NULL, /* dxpl_free */
H5FD__family_open, /* open */
H5FD__family_close, /* close */
H5FD__family_cmp, /* cmp */
H5FD__family_query, /* query */
NULL, /* get_type_map */
NULL, /* alloc */
NULL, /* free */
H5FD__family_get_eoa, /* get_eoa */
H5FD__family_set_eoa, /* set_eoa */
H5FD__family_get_eof, /* get_eof */
H5FD__family_sb_size, /* sb_size */
H5FD__family_sb_encode, /* sb_encode */
H5FD__family_sb_decode, /* sb_decode */
sizeof(H5FD_family_fapl_t), /* fapl_size */
H5FD__family_fapl_get, /* fapl_get */
H5FD__family_fapl_copy, /* fapl_copy */
H5FD__family_fapl_free, /* fapl_free */
0, /* dxpl_size */
NULL, /* dxpl_copy */
NULL, /* dxpl_free */
H5FD__family_open, /* open */
H5FD__family_close, /* close */
H5FD__family_cmp, /* cmp */
H5FD__family_query, /* query */
NULL, /* get_type_map */
NULL, /* alloc */
NULL, /* free */
H5FD__family_get_eoa, /* get_eoa */
H5FD__family_set_eoa, /* set_eoa */
H5FD__family_get_eof, /* get_eof */
H5FD__family_get_handle, /* get_handle */
H5FD__family_read, /* read */
H5FD__family_write, /* write */
H5FD__family_flush, /* flush */
H5FD__family_truncate, /* truncate */
H5FD__family_read, /* read */
H5FD__family_write, /* write */
H5FD__family_flush, /* flush */
H5FD__family_truncate, /* truncate */
H5FD__family_lock, /* lock */
H5FD__family_unlock, /* unlock */
H5FD__family_delete, /* del */
H5FD_FLMAP_DICHOTOMY /* fl_map */
};

Expand Down Expand Up @@ -1343,3 +1345,94 @@ H5FD__family_unlock(H5FD_t *_file)
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD__family_unlock() */

/*-------------------------------------------------------------------------
* Function: H5FD__family_delete
*
* Purpose: Delete a file
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
static herr_t
H5FD__family_delete(const char *filename, hid_t fapl_id)
{
H5P_genplist_t * plist;
const H5FD_family_fapl_t *fa;
hid_t memb_fapl_id = H5I_INVALID_HID;
unsigned current_member;
char * member_name = NULL;
char * temp = NULL;
herr_t delete_error = FAIL;
herr_t ret_value = SUCCEED;

FUNC_ENTER_STATIC

HDassert(filename);

/* Get the driver info (for the member fapl)
* The family_open call accepts H5P_DEFAULT, so we'll accept that here, too.
*/
if (H5P_FILE_ACCESS_DEFAULT == fapl_id)
memb_fapl_id = H5P_FILE_ACCESS_DEFAULT;
else {
if (NULL == (plist = (H5P_genplist_t *)H5I_object(fapl_id)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file access property list")
if (NULL == (fa = (const H5FD_family_fapl_t *)H5P_peek_driver_info(plist)))
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "bad family VFD driver info")
memb_fapl_id = fa->memb_fapl_id;
}

/* Allocate space for the string buffers */
if (NULL == (member_name = (char *)H5MM_malloc(H5FD_FAM_MEMB_NAME_BUF_SIZE)))
HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, FAIL, "unable to allocate member name")
if (NULL == (temp = (char *)H5MM_malloc(H5FD_FAM_MEMB_NAME_BUF_SIZE)))
HGOTO_ERROR(H5E_VFL, H5E_CANTALLOC, FAIL, "unable to allocate temporary member name")

/* Sanity check to make sure that generated names are unique */
HDsnprintf(member_name, H5FD_FAM_MEMB_NAME_BUF_SIZE, filename, 0);
HDsnprintf(temp, H5FD_FAM_MEMB_NAME_BUF_SIZE, filename, 1);
if (!HDstrcmp(member_name, temp))
HGOTO_ERROR(H5E_VFL, H5E_CANTDELETEFILE, FAIL, "provided file name cannot generate unique sub-files")

/* Delete all the family members */
current_member = 0;
while (1) {
/* Fix up the filename with the current member's number */
HDsnprintf(member_name, H5FD_FAM_MEMB_NAME_BUF_SIZE, filename, current_member);

/* Attempt to delete the member files. If the first file throws an error
* we always consider this an error. With subsequent member files, however,
* errors usually mean that we hit the last member file so we ignore them.
*
* Note that this means that any missing files in the family will leave
* undeleted members behind.
*/
H5E_BEGIN_TRY
{
delete_error = H5FD_delete(member_name, memb_fapl_id);
}
H5E_END_TRY;
if (FAIL == delete_error) {
if (0 == current_member)
HGOTO_ERROR(H5E_VFL, H5E_CANTDELETEFILE, FAIL, "unable to delete member file")
else
H5E_clear_stack(NULL);
break;
}
current_member++;
} /* end while */

done:
if (member_name)
H5MM_xfree(member_name);
if (temp)
H5MM_xfree(temp);

/* Don't close memb_fapl_id - We didn't bump its reference count since we're
* only using it in this call.
*/

FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD__family_delete() */
44 changes: 44 additions & 0 deletions src/H5FDint.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,47 @@ H5FD_driver_query(const H5FD_class_t *driver, unsigned long *flags /*out*/)

FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD_driver_query() */

/*-------------------------------------------------------------------------
* Function: H5FD_delete
*
* Purpose: Private version of H5FDdelete()
*
* Return: SUCCEED/FAIL
*
*-------------------------------------------------------------------------
*/
herr_t
H5FD_delete(const char *filename, hid_t fapl_id)
{
H5FD_class_t * driver; /* VFD for file */
H5FD_driver_prop_t driver_prop; /* Property for driver ID & info */
H5P_genplist_t * plist; /* Property list pointer */
herr_t ret_value = SUCCEED; /* Return value */

FUNC_ENTER_NOAPI(FAIL)

/* Sanity checks */
HDassert(filename);

/* Get file access property list */
if (NULL == (plist = (H5P_genplist_t *)H5I_object(fapl_id)))
HGOTO_ERROR(H5E_ARGS, H5E_BADTYPE, FAIL, "not a file access property list")

/* Get the VFD to open the file with */
if (H5P_peek(plist, H5F_ACS_FILE_DRV_NAME, &driver_prop) < 0)
HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, FAIL, "can't get driver ID & info")

/* Get driver info */
if (NULL == (driver = (H5FD_class_t *)H5I_object(driver_prop.driver_id)))
HGOTO_ERROR(H5E_VFL, H5E_BADVALUE, FAIL, "invalid driver ID in file access property list")
if (NULL == driver->del)
HGOTO_ERROR(H5E_VFL, H5E_UNSUPPORTED, FAIL, "file driver has no 'del' method")

/* Dispatch to file driver */
if ((driver->del)(filename, fapl_id))
HGOTO_ERROR(H5E_VFL, H5E_CANTDELETEFILE, FAIL, "delete failed")

done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD_delete() */
Loading

0 comments on commit 38d1b12

Please sign in to comment.