From e23342cb0e72c2f7e74fd123ae9cc6a2ddacc827 Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Fri, 3 Sep 2021 14:51:51 +0200 Subject: [PATCH] Update metadata in passive mode Signed-off-by: Robert Baldyga --- src/ocf_cache.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/ocf_cache.c b/src/ocf_cache.c index d3e0476..2ad47b3 100644 --- a/src/ocf_cache.c +++ b/src/ocf_cache.c @@ -251,6 +251,7 @@ void *ocf_cache_get_priv(ocf_cache_t cache) struct ocf_cache_volume_io_priv { struct ocf_io *io; struct ctx_data_t *data; + env_atomic remaining; }; struct ocf_cache_volume { @@ -266,8 +267,14 @@ static inline ocf_cache_t ocf_volume_to_cache(ocf_volume_t volume) static void ocf_cache_volume_io_complete(struct ocf_io *vol_io, int error) { + struct ocf_cache_volume_io_priv *priv; struct ocf_io *io = vol_io->priv1; + priv = ocf_io_get_priv(io); + + if (env_atomic_dec_return(&priv->remaining)) + return; + ocf_io_put(vol_io); ocf_io_end(io, error); } @@ -306,9 +313,16 @@ static int ocf_cache_volume_prepare_vol_io(struct ocf_io *io, static void ocf_cache_volume_submit_io(struct ocf_io *io) { + struct ocf_cache_volume_io_priv *priv; struct ocf_io *vol_io; + ocf_cache_t cache; int result; + cache = ocf_volume_to_cache(ocf_io_get_volume(io)); + priv = ocf_io_get_priv(io); + + env_atomic_set(&priv->remaining, 2); + result = ocf_cache_volume_prepare_vol_io(io, &vol_io); if (result) { ocf_io_end(io, result); @@ -316,14 +330,30 @@ static void ocf_cache_volume_submit_io(struct ocf_io *io) } ocf_volume_submit_io(vol_io); + + result = ocf_metadata_passive_update(cache, io); + if (result) { + ocf_cache_log(cache, log_crit, + "Metadata update error (error=%d)!\n", result); + } + + if (env_atomic_dec_return(&priv->remaining)) + return; + + ocf_io_put(vol_io); + ocf_io_end(io, 0); } static void ocf_cache_volume_submit_flush(struct ocf_io *io) { + struct ocf_cache_volume_io_priv *priv; struct ocf_io *vol_io; int result; + priv = ocf_io_get_priv(io); + env_atomic_set(&priv->remaining, 1); + result = ocf_cache_volume_prepare_vol_io(io, &vol_io); if (result) { ocf_io_end(io, result); @@ -336,9 +366,13 @@ static void ocf_cache_volume_submit_flush(struct ocf_io *io) static void ocf_cache_volume_submit_discard(struct ocf_io *io) { + struct ocf_cache_volume_io_priv *priv; struct ocf_io *vol_io; int result; + priv = ocf_io_get_priv(io); + env_atomic_set(&priv->remaining, 1); + result = ocf_cache_volume_prepare_vol_io(io, &vol_io); if (result) { ocf_io_end(io, result);