From 2b739d116527514c39e18d99787016cd1afbf2c2 Mon Sep 17 00:00:00 2001 From: Adam Rutkowski Date: Thu, 21 Jan 2021 13:07:41 -0600 Subject: [PATCH] Check exclusive device access before probing metadata Signed-off-by: Adam Rutkowski --- casadm/cas_lib.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/casadm/cas_lib.c b/casadm/cas_lib.c index 6d57640b5..452ce0623 100644 --- a/casadm/cas_lib.c +++ b/casadm/cas_lib.c @@ -2915,10 +2915,12 @@ int zero_md(const char *cache_device){ int fd = 0; int result; - /* check if given cache device exists */ - fd = open(cache_device, O_RDONLY); + /* check if device is available */ + fd = open(cache_device, O_WRONLY | O_SYNC | O_EXCL); if (fd < 0) { - cas_printf(LOG_ERR, "Device '%s' not found.\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 " + "stop the cache and try again.\n", cache_device); return FAILURE; } close(fd);