From owner-freebsd-bugs@FreeBSD.ORG Fri Jul 1 06:10:06 2011 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1458D1065672 for ; Fri, 1 Jul 2011 06:10:06 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id E5E648FC13 for ; Fri, 1 Jul 2011 06:10:05 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id p616A5i6037648 for ; Fri, 1 Jul 2011 06:10:05 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id p616A5K5037647; Fri, 1 Jul 2011 06:10:05 GMT (envelope-from gnats) Resent-Date: Fri, 1 Jul 2011 06:10:05 GMT Resent-Message-Id: <201107010610.p616A5K5037647@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Josh Carroll Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3EE441065672 for ; Fri, 1 Jul 2011 06:05:20 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22]) by mx1.freebsd.org (Postfix) with ESMTP id 151D18FC12 for ; Fri, 1 Jul 2011 06:05:20 +0000 (UTC) Received: from red.freebsd.org (localhost [127.0.0.1]) by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p6165J4Q069126 for ; Fri, 1 Jul 2011 06:05:19 GMT (envelope-from nobody@red.freebsd.org) Received: (from nobody@localhost) by red.freebsd.org (8.14.4/8.14.4/Submit) id p6165JSh069125; Fri, 1 Jul 2011 06:05:19 GMT (envelope-from nobody) Message-Id: <201107010605.p6165JSh069125@red.freebsd.org> Date: Fri, 1 Jul 2011 06:05:19 GMT From: Josh Carroll To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: misc/158551: Enhance periodic 800.scrub-zfs script to handle scrub -s X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Jul 2011 06:10:06 -0000 >Number: 158551 >Category: misc >Synopsis: Enhance periodic 800.scrub-zfs script to handle scrub -s >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Fri Jul 01 06:10:05 UTC 2011 >Closed-Date: >Last-Modified: >Originator: Josh Carroll >Release: 8.2-RELEASE-p2 >Organization: n/a >Environment: FreeBSD pflog.net 8.2-RELEASE-p2 FreeBSD 8.2-RELEASE-p2 #0 r223479M: Mon Jun 27 11:14:32 PDT 2011 root@pflog.net:/usr/obj/usr/src/sys/PFLOG amd64 >Description: Currently, the periodic script to scrub all zpools looks at the last scrub date via zpool history, but it does not consider cases where a scrub was stopped with zpool scrub -s. For example, consider the zpool history of all scrubs for a zpool like this: 2011-06-05.03:08:27 zpool scrub data 2011-06-13.03:03:50 zpool scrub data 2011-06-19.22:28:49 zpool scrub data 2011-06-19.22:41:49 zpool scrub -s data With the existing logic, the script would consider the last scrub date to be "2011-06-19.22:28:49". However, that particular scrub was stopped, so the last fully completed scrub was actually on "2011-06-13.03:03:50". I have updated the 800.scrub-zfs periodic script to understand when a scrub operation was stopped. As of now, scrub -s will not generate a history entry if a zpool scrub -s is issued while no scrub is in progress. So there is no risk of two scrub -s appearing sequentially. The attached patch handles more than one scrub/scrub -s in a row, e.g. something like this: 2011-06-05.03:08:27 zpool scrub data 2011-06-13.03:03:50 zpool scrub data 2011-06-19.22:28:49 zpool scrub data 2011-06-19.22:41:49 zpool scrub -s data 2011-06-25.03:08:27 zpool scrub data 2011-06-29.03:11:49 zpool scrub -s data It would properly set the last successful scrub date to "2011-06-13.03:03:50". The attached patch is against the 800.scrub-zfs from HEAD, but it should apply cleanly to 8.2-RELEASE and 8.2-STABLE as well. Thanks! Josh >How-To-Repeat: Issue a zpool scrub then zpool scrub -s and the periodic script will think the last successful scrub was today, instead of the last uninterrupted scrub. >Fix: See attached patch. Patch attached with submission follows: --- 800.scrub-zfs.orig 2011-06-30 22:52:01.291279403 -0700 +++ 800.scrub-zfs 2011-06-30 22:52:08.707039940 -0700 @@ -51,10 +51,11 @@ _pool_threshold=${daily_scrub_zfs_default_threshold} fi - _last_scrub=$(zpool history ${pool} | \ - egrep "^[0-9\.\:\-]{19} zpool scrub ${pool}\$" | tail -1 |\ - cut -d ' ' -f 1) - if [ -z "${_last_scrub}" ]; then + _last_successful_scrub=$(zpool history ${pool} | \ + egrep "^[0-9\.\:\-]{19} zpool scrub( -s | )${pool}\$" | \ + awk 'BEGIN { scrub1="" }; /zpool scrub -s/{ scrub1=scrub2 }; \ + /zpool scrub/ && ! / -s /{ scrub2=scrub1; scrub1=$1 }; END { print scrub1 }') + if [ -z "${_last_successful_scrub}" ]; then # creation time of the pool if no scrub was done _last_scrub=$(zpool history ${pool} | \ sed -ne '2s/ .*$//p') >Release-Note: >Audit-Trail: >Unformatted: