Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2209841pxa; Mon, 24 Aug 2020 08:08:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3/2sC4sJ8F3EvjWUFvkwe/L0u+dWkvXqIOYMXPEmfmG1r1rsFn8jmvarI5p1rdrg/X3sO X-Received: by 2002:a17:906:cb86:: with SMTP id mf6mr6278086ejb.415.1598281704752; Mon, 24 Aug 2020 08:08:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598281704; cv=none; d=google.com; s=arc-20160816; b=ZdOcpLeq/qQHQreNWGl0p6dJssp/kfMMMx3TP+VodVOZNcHbckPFlQiYVFZzD9t4w2 Xa1P6Wr4oJLiw/FOrO33PRwa9FQUyUTH9KA1sIb+KmaTFx08Gv7Vi8lAqmEraVq5CTQN JfNAIl1aNl2BZg7R3w0ACWRPqGEnnJRaTLtrnbwmUQyEc0lE60p7Yi91feC7ZdEBzl8b ndarnhB52F0G6Wl4HfptqhCVi43sCHDxB1kQVFk9nkgjSC2OOhtGkQ3kl9INX0e9/bwV DgeJ+xyEumdNLinz7QMMjG3CLO/bJ2CBb9kpFVKz3OH4JmrGSwsp9G1vT732Ub/rz7DQ Jrug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Yhj50m+yp5TG5axwoQvzJyWGAe0F2L0Acoom68/W02k=; b=xib6IGNJkvMUYa1TKE+SFdz5uWCYluBSjlt1LrJFnlTj1/Qfq7anBJp/F5cbeVvCg2 7pp0ww+WrtBZx4m66p7A++VI+PwLQ5tb319zwliPkP+CrPXZqY64PuDDgMVyi3mK1qwy 6TWSj4ApnCOUDvRK5TIfcq3whJMYxAI2iyHHtYGxYnbKTdCVLBwAGjrNeLP7zIGUrzqw IokULMDXxFzIn1VMBj6iJ7GhNpxQGlAaDN32eMTL81evhG+LHSlUGk+VlH42uzC3T9lY PhidJlPUNa9qqQZg4maViAT3foa3TTOY0FEDbTISnqhuqdQddaa198ivwCXCCl5UkRAs YW1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bCEyP7JR; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f22si3222145ejw.397.2020.08.24.08.07.52; Mon, 24 Aug 2020 08:08:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=bCEyP7JR; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726519AbgHXPFw (ORCPT + 99 others); Mon, 24 Aug 2020 11:05:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:26858 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725999AbgHXPFu (ORCPT ); Mon, 24 Aug 2020 11:05:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1598281542; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Yhj50m+yp5TG5axwoQvzJyWGAe0F2L0Acoom68/W02k=; b=bCEyP7JR2+zatoM6x1SzU5tzJqBpVqjH55LynMoZ7O4xW5hhr3t02PKfwoq9ZpQWqiwzUJ fe2ICZ6L3F7o9uqZboRXmlszJPcQM9N5BZg7jJO12iSu6KuIYraQJocug2AUvXSeQ0I39V mpjHp7ktW7afR+y7+vy8QTmFZ6R5LMw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-523-xnuSWAn2Oy6gixe8uJnLUw-1; Mon, 24 Aug 2020 11:05:39 -0400 X-MC-Unique: xnuSWAn2Oy6gixe8uJnLUw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 106711007463 for ; Mon, 24 Aug 2020 15:05:39 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.74.8.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6D7BF6FDB6; Mon, 24 Aug 2020 15:05:37 +0000 (UTC) From: Kenneth D'souza To: linux-nfs@vger.kernel.org Cc: kdsouza@redhat.com, SteveD@redhat.com Subject: [PATCH] nfs-iostat: divide by zero with fresh mount Date: Mon, 24 Aug 2020 20:35:35 +0530 Message-Id: <20200824150535.15224-1-kdsouza@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org When an export is freshly mounted, /proc/self/mountstats displays age = 0. This causes nfs-iostat to divide by zero throwing an error. When we have age = 0, other stats are greater than 0, so we'll set age = 1 and print the relevant stats. This will prevent a backtrace like this from occurring if nfsiostat is run. nfsiostat -s 1 Traceback (most recent call last): File "/usr/sbin/nfsiostat", line 662, in iostat_command(prog) File "/usr/sbin/nfsiostat", line 644, in iostat_command print_iostat_summary(old_mountstats, mountstats, devices, sample_time, options) File "/usr/sbin/nfsiostat", line 490, in print_iostat_summary devicelist.sort(key=lambda x: stats[x].ops(time), reverse=True) File "/usr/sbin/nfsiostat", line 490, in devicelist.sort(key=lambda x: stats[x].ops(time), reverse=True) File "/usr/sbin/nfsiostat", line 383, in ops return (sends / sample_time) ZeroDivisionError: float division by zero Signed-off-by: Kenneth D'souza --- tools/nfs-iostat/nfs-iostat.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/nfs-iostat/nfs-iostat.py b/tools/nfs-iostat/nfs-iostat.py index 5556f692..0c6c6dda 100755 --- a/tools/nfs-iostat/nfs-iostat.py +++ b/tools/nfs-iostat/nfs-iostat.py @@ -383,6 +383,8 @@ class DeviceData: sends = float(self.__rpc_data['rpcsends']) if sample_time == 0: sample_time = float(self.__nfs_data['age']) + if sample_time == 0: + sample_time = 1; return (sends / sample_time) def display_iostats(self, sample_time, which): -- 2.21.3