From nobody@FreeBSD.org  Thu Sep  2 15:34:30 2010
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 AC262106571F
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  2 Sep 2010 15:34:30 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 9B7CA8FC1E
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  2 Sep 2010 15:34:30 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o82FYUtu050051
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 2 Sep 2010 15:34:30 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o82FYU0P050050;
	Thu, 2 Sep 2010 15:34:30 GMT
	(envelope-from nobody)
Message-Id: <201009021534.o82FYU0P050050@www.freebsd.org>
Date: Thu, 2 Sep 2010 15:34:30 GMT
From: Josh Paetzel <jpaetzel@FreeBSD.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [PATCH] /etc/periodic/daily/800.scrub-zfs errors with faulted zpools
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         150228
>Category:       conf
>Synopsis:       [patch] periodic(8): fix daily/800.scrub-zfs errors with faulted zpools
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    jpaetzel
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Sep 02 15:40:06 UTC 2010
>Closed-Date:    Sun Jan 23 17:14:08 UTC 2011
>Last-Modified:  Fri Jan 28 18:30:09 UTC 2011
>Originator:     Josh Paetzel
>Release:        9.0-CURRENT
>Organization:
>Environment:
FreeBSD tcbug.ixsystems.com 9.0-CURRENT FreeBSD 9.0-CURRENT #2: Mon Jul 12 22:22:49 CDT 2010     jpaetzel@ix.tcbug.org:/usr/obj/usr/src/sys/IX  amd64
>Description:
800.scrub-zfs is a periodic script you can enable to perform periodic scrubs of ZFS filesystems.  If you have faulted zpools the script generates sh errors due to some of the zpool commands generating no output.

Faulted zpools can happen for reasons other than hardware failure, for example if you use ZFS on removable devices when they are unplugged zpool status will show them as faulted.
>How-To-Repeat:
Put ZFS on a removable device, export and detach it from the system.
# echo 'daily_scrub_zfs_enable="YES"' >> /etc/periodic.conf
# /etc/periodic/daily/800.scrub-zfs
>Fix:
Apply attached patch

Patch attached with submission follows:

Index: 800.scrub-zfs
===================================================================
--- 800.scrub-zfs	(revision 212149)
+++ 800.scrub-zfs	(working copy)
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# $FreeBSD$
+# $FreeBSD: src/etc/periodic/daily/800.scrub-zfs,v 1.1 2010/06/15 08:58:16 netchild Exp $
 #
 
 # If there is a global system configuration file, suck it in.
@@ -24,13 +24,17 @@
 
 	for pool in ${daily_scrub_zfs_pools}; do
 		# sanity check
-		zpool list ${pool} >/dev/null 2>&1
+		_status=`zpool list ${pool} | sed -n -e '$p'` >/dev/null 2>&1
 		if [ $? -ne 0 ]; then
 			echo "   WARNING: pool '${pool}' specified in"
 			echo "            '/etc/periodic.conf:daily_scrub_zfs_pools'"
 			echo "            does not exist"
 			continue
 		fi
+		if echo ${_status} | grep FAULTED >/dev/null 2>&1; then
+			echo "Skipping faulted pool: ${pool}"
+			continue
+		fi
 
 		# successful only if there is at least one pool to scrub
 		rc=0


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->jpaetzel 
Responsible-Changed-By: jpaetzel 
Responsible-Changed-When: Sun Jan 23 14:37:28 UTC 2011 
Responsible-Changed-Why:  
I'll take it 

http://www.freebsd.org/cgi/query-pr.cgi?pr=150228 
State-Changed-From-To: open->closed 
State-Changed-By: jpaetzel 
State-Changed-When: Sun Jan 23 17:13:44 UTC 2011 
State-Changed-Why:  
Committed, thanks. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=150228 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: conf/150228: commit references a PR
Date: Sun, 23 Jan 2011 17:13:36 +0000 (UTC)

 Author: jpaetzel
 Date: Sun Jan 23 17:13:29 2011
 New Revision: 217755
 URL: http://svn.freebsd.org/changeset/base/217755
 
 Log:
   This script parses output of userland tools.  In the case of a faulted
   zpool the output causes the script to bail out with syntax errors.
   Since a scrub of a faulted zpool is pointless, just skip over any pools
   marked as such.
   
   PR:	conf/150228
   Submitted by:	jpaetzel
   Approved by:	kib (mentor)
   MFC after:	3 days
   MFC note:	only for RELENG_8
 
 Modified:
   head/etc/periodic/daily/800.scrub-zfs
 
 Modified: head/etc/periodic/daily/800.scrub-zfs
 ==============================================================================
 --- head/etc/periodic/daily/800.scrub-zfs	Sun Jan 23 16:28:44 2011	(r217754)
 +++ head/etc/periodic/daily/800.scrub-zfs	Sun Jan 23 17:13:29 2011	(r217755)
 @@ -24,13 +24,17 @@ case "$daily_scrub_zfs_enable" in
  
  	for pool in ${daily_scrub_zfs_pools}; do
  		# sanity check
 -		zpool list ${pool} >/dev/null 2>&1
 +		_status=$(zpool list ${pool} | sed -n -e '$p')
  		if [ $? -ne 0 ]; then
  			echo "   WARNING: pool '${pool}' specified in"
  			echo "            '/etc/periodic.conf:daily_scrub_zfs_pools'"
  			echo "            does not exist"
  			continue
  		fi
 +		if echo ${_status} | grep -q FAULTED; then
 +			echo "Skipping faulted pool: ${pool}"
 +			continue
 +		fi
  
  		# successful only if there is at least one pool to scrub
  		rc=0
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: conf/150228: commit references a PR
Date: Fri, 28 Jan 2011 18:25:59 +0000 (UTC)

 Author: jpaetzel
 Date: Fri Jan 28 18:25:51 2011
 New Revision: 218027
 URL: http://svn.freebsd.org/changeset/base/218027
 
 Log:
   MFC: r217755 r217822
   
   This script parses output of userland tools. In the case of a faulted
   zpool the output causes the script to bail out with syntax errors.
   Since a scrub of a faulted zpool is pointless, just skip over any
   pools marked as such.
   
   PR:	conf/150228
   Approved by:	kib (mentor)
 
 Modified:
   stable/8/etc/periodic/daily/800.scrub-zfs
 Directory Properties:
   stable/8/etc/   (props changed)
 
 Modified: stable/8/etc/periodic/daily/800.scrub-zfs
 ==============================================================================
 --- stable/8/etc/periodic/daily/800.scrub-zfs	Fri Jan 28 17:37:09 2011	(r218026)
 +++ stable/8/etc/periodic/daily/800.scrub-zfs	Fri Jan 28 18:25:51 2011	(r218027)
 @@ -5,6 +5,10 @@
  
  # If there is a global system configuration file, suck it in.
  #
 +
 +newline="
 +" # A single newline
 +
  if [ -r /etc/defaults/periodic.conf ]
  then
      . /etc/defaults/periodic.conf
 @@ -24,13 +28,19 @@ case "$daily_scrub_zfs_enable" in
  
  	for pool in ${daily_scrub_zfs_pools}; do
  		# sanity check
 -		zpool list ${pool} >/dev/null 2>&1
 +		_status=$(zpool list "${pool}" 2> /dev/null)
  		if [ $? -ne 0 ]; then
  			echo "   WARNING: pool '${pool}' specified in"
  			echo "            '/etc/periodic.conf:daily_scrub_zfs_pools'"
  			echo "            does not exist"
  			continue
  		fi
 +		_status=${_status##*$newline}
 +		case ${_status} in
 +		*FAULTED*)
 +			echo "Skipping faulted pool: ${pool}"
 +			continue ;;
 +		esac
  
  		# successful only if there is at least one pool to scrub
  		rc=0
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
