From nobody@FreeBSD.org  Fri Jul  1 06:05:20 2011
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 3EE441065672
	for <freebsd-gnats-submit@FreeBSD.org>; 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 <freebsd-gnats-submit@FreeBSD.org>; 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 <freebsd-gnats-submit@FreeBSD.org>; 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 <josh.carroll@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Enhance periodic 800.scrub-zfs script to handle scrub -s
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         158551
>Category:       conf
>Synopsis:       [patch] 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:  Fri Jul 01 07:18:57 UTC 2011
>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 <poolname> then zpool scrub -s <poolname> 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:
