Skip to content

Commit

Permalink
Check exclusive device access before probing metadata
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Rutkowski <[email protected]>
  • Loading branch information
Adam Rutkowski committed Jan 21, 2021
1 parent 5f65d93 commit 2b739d1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions casadm/cas_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2b739d1

Please sign in to comment.