From 9d542dca629e561b6235ff4fd4943881472246ad Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Fri, 19 Apr 2019 16:32:53 +0200 Subject: [PATCH] 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 --- sa_common.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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; -- 2.40.0