Introduce on_init/on_deinit ops in ocf_volume interface

Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
Robert Baldyga 2022-05-13 20:02:33 +02:00 committed by Jan Musial
parent 67024ebdb3
commit c9ea68f3bf
2 changed files with 28 additions and 1 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright(c) 2012-2021 Intel Corporation * Copyright(c) 2012-2022 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
@ -82,6 +82,24 @@ struct ocf_volume_ops {
*/ */
void (*submit_write_zeroes)(struct ocf_io *io); void (*submit_write_zeroes)(struct ocf_io *io);
/**
* @brief Volume initialization callback, called when volume object
* is being initialized
*
* @param[in] volume Volume
*
* @return Zero on success, otherwise error code
*/
int (*on_init)(ocf_volume_t volume);
/**
* @brief Volume deinitialization callback, called when volume object
* is being deinitialized
*
* @param[in] volume Volume
*/
void (*on_deinit)(ocf_volume_t volume);
/** /**
* @brief Open volume * @brief Open volume
* *

View File

@ -133,6 +133,12 @@ int ocf_volume_init(ocf_volume_t volume, ocf_volume_type_t type,
volume->uuid.size = uuid->size; volume->uuid.size = uuid->size;
if (volume->type->properties->ops.on_init) {
ret = volume->type->properties->ops.on_init(volume);
if (ret)
goto err;
}
return 0; return 0;
err: err:
@ -150,6 +156,9 @@ void ocf_volume_deinit(ocf_volume_t volume)
{ {
OCF_CHECK_NULL(volume); OCF_CHECK_NULL(volume);
if (volume->type && volume->type->properties->ops.on_deinit)
volume->type->properties->ops.on_deinit(volume);
env_free(volume->priv); env_free(volume->priv);
volume->priv = NULL; volume->priv = NULL;