From 5f65d93a3608de8bb5d9a2353c241eb6e223216d Mon Sep 17 00:00:00 2001 From: Adam Rutkowski Date: Wed, 20 Jan 2021 18:39:09 +0100 Subject: [PATCH] Replace cache started check with exclusive open in zero superblock. This check covers the previous case (cache started) as well as other potential incorrect usages of the command. Also now the check is made exactly at the moment of opening the device to write to. Signed-off-by: Adam Rutkowski --- casadm/cas_lib.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/casadm/cas_lib.c b/casadm/cas_lib.c index d1bb0250f..6d57640b5 100644 --- a/casadm/cas_lib.c +++ b/casadm/cas_lib.c @@ -2923,13 +2923,6 @@ int zero_md(const char *cache_device){ } close(fd); - /* don't delete metadata if cache is in use */ - if (check_cache_already_added(cache_device) == FAILURE) { - cas_printf(LOG_ERR, "Cache device '%s' is already used as cache. " - "Please stop cache to clear metadata.\n", cache_device); - return FAILURE; - } - result = _check_cache_device(cache_device, &cmd_info); if (result == FAILURE) { cas_printf(LOG_ERR, "Failed to retrieve device's information.\n"); @@ -2942,9 +2935,11 @@ int zero_md(const char *cache_device){ return FAILURE; } - fd = open(cache_device, O_WRONLY | O_SYNC); + fd = open(cache_device, O_WRONLY | O_SYNC | O_EXCL); if (fd < 0) { - cas_printf(LOG_ERR, "Error while opening '%s' to purge metadata.\n", cache_device); + cas_printf(LOG_ERR, "Error while opening '%s'exclusively. This can be due to\n" + "cache instance running on this device. In such case please\n" + "stop the cache and try again.\n", cache_device); return FAILURE; }