]> granicus.if.org Git - sysstat/commitdiff
sar: Better detect if a disk has been unregistered then registered again
authorSebastien GODARD <sysstat@users.noreply.github.com>
Fri, 19 Apr 2019 14:32:53 +0000 (16:32 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Fri, 19 Apr 2019 14:32:53 +0000 (16:32 +0200)
If a disk was mounted read-only then sar might not detect that a disk
had been unregistered then registered again. This is because detection
is based on counters (like number of written sectors) going down. Yet
with a read-only device, the number of written sectors is always 0 and
is never decremented.

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
sa_common.c

index 093f58896329bff557cbfb928f7bc9868af47488..0b38a4be8a1add81adda8e7fcd765664776f56d7 100644 (file)
@@ -1089,11 +1089,14 @@ int check_disk_reg(struct activity *a, int curr, int ref, int pos)
                         * is that the disk has been unregistered and a new disk inserted.
                         * If only one or two have decreased then the likelyhood
                         * is that the counter has simply wrapped.
+                        * Don't take into account a counter if its previous value was 0
+                        * (this may be a read-only device, or a kernel that doesn't
+                        * support discard stats yet...)
                         */
                        if ((sdc->nr_ios < sdp->nr_ios) &&
-                           (sdc->rd_sect < sdp->rd_sect) &&
-                           (sdc->wr_sect < sdp->wr_sect) &&
-                           (sdc->dc_sect < sdp->dc_sect))
+                           (!sdp->rd_sect || (sdc->rd_sect < sdp->rd_sect)) &&
+                           (!sdp->wr_sect || (sdc->wr_sect < sdp->wr_sect)) &&
+                           (!sdp->dc_sect || (sdc->dc_sect < sdp->dc_sect)))
                                /* Same device registered again */
                                return -2;