mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
dmfilemapd: update file block count at daemon start
The file block count stored in the filemap_monitor was lazily initialised at the time of the first check. This causes problems in the case that the file has been truncated between this time and the time the daemon started: the initial block count and current block count match and the daemon fails to detect a change. Separate the setting of the block count from the check and make a call to update the value at the start of _dmfilemapd().
This commit is contained in:
parent
744f2920db
commit
0cb628dfe2
@ -357,30 +357,33 @@ static int _parse_args(int argc, char **argv, struct filemap_monitor *fm)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _filemap_fd_check_changed(struct filemap_monitor *fm)
|
static int _filemap_fd_update_blocks(struct filemap_monitor *fm)
|
||||||
{
|
{
|
||||||
int64_t blocks, old_blocks;
|
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
|
|
||||||
if (fm->fd < 0) {
|
if (fm->fd < 0) {
|
||||||
log_error("Filemap fd is not open.");
|
log_error("Filemap fd is not open.");
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fstat(fm->fd, &buf)) {
|
if (fstat(fm->fd, &buf)) {
|
||||||
log_error("Failed to fstat filemap file descriptor.");
|
log_error("Failed to fstat filemap file descriptor.");
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
blocks = buf.st_blocks;
|
fm->blocks = buf.st_blocks;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int _filemap_fd_check_changed(struct filemap_monitor *fm)
|
||||||
|
{
|
||||||
|
int64_t old_blocks;
|
||||||
|
|
||||||
/* first check? */
|
|
||||||
if (fm->blocks < 0)
|
|
||||||
old_blocks = buf.st_blocks;
|
|
||||||
else
|
|
||||||
old_blocks = fm->blocks;
|
old_blocks = fm->blocks;
|
||||||
|
|
||||||
fm->blocks = blocks;
|
if (!_filemap_fd_update_blocks(fm))
|
||||||
|
return -1;
|
||||||
|
|
||||||
return (fm->blocks != old_blocks);
|
return (fm->blocks != old_blocks);
|
||||||
}
|
}
|
||||||
@ -714,6 +717,9 @@ static int _dmfilemapd(struct filemap_monitor *fm)
|
|||||||
if (!_filemap_monitor_set_notify(fm))
|
if (!_filemap_monitor_set_notify(fm))
|
||||||
goto bad;
|
goto bad;
|
||||||
|
|
||||||
|
if (!_filemap_fd_update_blocks(fm))
|
||||||
|
goto bad;
|
||||||
|
|
||||||
if (!dm_stats_list(dms, DM_STATS_ALL_PROGRAMS)) {
|
if (!dm_stats_list(dms, DM_STATS_ALL_PROGRAMS)) {
|
||||||
log_error("Failed to list stats handle.");
|
log_error("Failed to list stats handle.");
|
||||||
goto bad;
|
goto bad;
|
||||||
|
Loading…
Reference in New Issue
Block a user