1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

dev-cache: Improve open device check messages.

This commit is contained in:
Alasdair G Kergon 2014-04-04 01:39:42 +01:00
parent c16c1a9f70
commit 3f0f558786
2 changed files with 18 additions and 9 deletions

View File

@ -763,26 +763,32 @@ int dev_cache_init(struct cmd_context *cmd)
return 0;
}
/*
* Returns number of devices still open.
*/
static int _check_for_open_devices(int close_immediate)
{
struct device *dev;
struct dm_hash_node *n;
int r = 0;
int num_open = 0;
dm_hash_iterate(n, _cache.names) {
dev = (struct device *) dm_hash_get_data(_cache.names, n);
if (dev->fd >= 0) {
log_error("Device '%s' has been left open (%d).",
log_error("Device '%s' has been left open (%d remaining references).",
dev_name(dev), dev->open_count);
r++;
num_open++;
if (close_immediate)
dev_close_immediate(dev);
}
}
return r;
return num_open;
}
/*
* Returns number of devices left open.
*/
int dev_cache_check_for_open_devices(void)
{
return _check_for_open_devices(0);
@ -790,11 +796,11 @@ int dev_cache_check_for_open_devices(void)
int dev_cache_exit(void)
{
int cnt = 0;
int num_open = 0;
if (_cache.names)
if ((cnt = _check_for_open_devices(1)) > 0)
log_error(INTERNAL_ERROR "%d device(s) have been closed.", cnt);
if ((num_open = _check_for_open_devices(1)) > 0)
log_error(INTERNAL_ERROR "%d device(s) were left open and have been closed.", num_open);
if (_cache.preferred_names_matcher)
_cache.preferred_names_matcher = NULL;
@ -814,7 +820,7 @@ int dev_cache_exit(void)
dm_list_init(&_cache.dirs);
dm_list_init(&_cache.files);
return (cnt == 0);
return (!num_open);
}
int dev_cache_add_dir(const char *path)

View File

@ -36,8 +36,11 @@ struct dev_filter {
*/
struct cmd_context;
int dev_cache_init(struct cmd_context *cmd);
int dev_cache_check_for_open_devices(void);
int dev_cache_exit(void);
/*
* Returns number of open devices.
*/
int dev_cache_check_for_open_devices(void);
/* Trigger(1) or avoid(0) a scan */
void dev_cache_scan(int do_scan);