]> sourceware.org Git - lvm2.git/commitdiff
dmfilemapd: update file block count at daemon start
authorBryn M. Reeves <bmr@redhat.com>
Wed, 7 Jun 2017 18:26:09 +0000 (19:26 +0100)
committerBryn M. Reeves <bmr@redhat.com>
Tue, 13 Jun 2017 18:46:41 +0000 (19:46 +0100)
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().

daemons/dmfilemapd/dmfilemapd.c

index 2637bd299a1161330a2fc0411910a28c70f08f7a..0dbdefc5b1fc9ffc23c9562cf4aa20fd068b1fa0 100644 (file)
@@ -357,30 +357,33 @@ static int _parse_args(int argc, char **argv, struct filemap_monitor *fm)
        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;
 
        if (fm->fd < 0) {
                log_error("Filemap fd is not open.");
-               return -1;
+               return 0;
        }
 
        if (fstat(fm->fd, &buf)) {
                log_error("Failed to fstat filemap file descriptor.");
-               return -1;
+               return 0;
        }
 
-       blocks = buf.st_blocks;
+       fm->blocks = buf.st_blocks;
 
-       /* first check? */
-       if (fm->blocks < 0)
-               old_blocks = buf.st_blocks;
-       else
-               old_blocks = fm->blocks;
+       return 1;
+}
 
-       fm->blocks = blocks;
+static int _filemap_fd_check_changed(struct filemap_monitor *fm)
+{
+       int64_t old_blocks;
+
+       old_blocks = fm->blocks;
+
+       if (!_filemap_fd_update_blocks(fm))
+               return -1;
 
        return (fm->blocks != old_blocks);
 }
@@ -714,6 +717,9 @@ static int _dmfilemapd(struct filemap_monitor *fm)
        if (!_filemap_monitor_set_notify(fm))
                goto bad;
 
+       if (!_filemap_fd_update_blocks(fm))
+               goto bad;
+
        if (!dm_stats_list(dms, DM_STATS_ALL_PROGRAMS)) {
                log_error("Failed to list stats handle.");
                goto bad;
This page took 0.043608 seconds and 5 git commands to generate.