From: Sebastien GODARD Date: Fri, 19 Apr 2019 14:32:53 +0000 (+0200) Subject: sar: Better detect if a disk has been unregistered then registered again X-Git-Tag: v12.1.5~32 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9d542dca629e561b6235ff4fd4943881472246ad;p=sysstat sar: Better detect if a disk has been unregistered then registered again 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 --- diff --git a/sa_common.c b/sa_common.c index 093f588..0b38a4b 100644 --- a/sa_common.c +++ b/sa_common.c @@ -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;