diff --git a/inc/ocf_volume.h b/inc/ocf_volume.h index 3d71e70..f6b26f6 100644 --- a/inc/ocf_volume.h +++ b/inc/ocf_volume.h @@ -1,5 +1,5 @@ /* - * Copyright(c) 2012-2021 Intel Corporation + * Copyright(c) 2012-2022 Intel Corporation * SPDX-License-Identifier: BSD-3-Clause */ @@ -82,6 +82,24 @@ struct ocf_volume_ops { */ 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 * diff --git a/src/ocf_volume.c b/src/ocf_volume.c index dfd5df3..f335ece 100644 --- a/src/ocf_volume.c +++ b/src/ocf_volume.c @@ -133,6 +133,12 @@ int ocf_volume_init(ocf_volume_t volume, ocf_volume_type_t type, 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; err: @@ -150,6 +156,9 @@ void ocf_volume_deinit(ocf_volume_t 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); volume->priv = NULL;