From nobody@FreeBSD.org  Thu Jan 31 22:34:31 2008
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 D740616A421
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 31 Jan 2008 22:34:31 +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 D635113C457
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 31 Jan 2008 22:34:31 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m0VMWegt057382
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 31 Jan 2008 22:32:40 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.2/8.14.1/Submit) id m0VMWef1057381;
	Thu, 31 Jan 2008 22:32:40 GMT
	(envelope-from nobody)
Message-Id: <200801312232.m0VMWef1057381@www.freebsd.org>
Date: Thu, 31 Jan 2008 22:32:40 GMT
From: James Snow <snow@teardrop.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] UFS volumes on ZVOLs cannot be fsck'd at boot
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         120194
>Category:       conf
>Synopsis:       [patch] UFS volumes on ZVOLs cannot be fsck'd at boot
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    pjd
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jan 31 22:40:01 UTC 2008
>Closed-Date:    Tue Sep 22 12:42:16 UTC 2009
>Last-Modified:  Tue Sep 22 12:42:16 UTC 2009
>Originator:     James Snow
>Release:        7.0-RC1
>Organization:
>Environment:
FreeBSD zfs0 7.0-RC1 FreeBSD 7.0-RC1 #0: Thu Jan 31 15:42:56 EST 2008     snow@zfs0:/usr/obj/usr/src/sys/GENERIC  amd64
>Description:
UFS volumes created on ZVOLs (as demonstrated in the FreeBSD ZFS
Wiki: http://wiki.freebsd.org/ZFSQuickStartGuide) cannot be fsck'd by
the current boot process.

In the current boot process, fsck runs before zfs, which runs before
mountlate.  If a UFS/ZVOL mount point is in /etc/fstab with pass# set to
a non-zero value, even in 'late' is set, the boot process will abort.
>How-To-Repeat:
(Assuming ZFS is enabled and a zpool called 'tank' exists...)

zfs create -V1g tank/ufs
newfs /dev/zvol/tank/ufs
echo "/dev/zvol/tank/ufs /mnt ufs rw,late 2 2" >> /etc/fstab
shutdown -r now
>Fix:
Patches provided by swell.k@gmail.com:

--- /usr/src/etc/rc.d/hostid
+++ /etc/rc.d/hostid
@@ -28,7 +28,7 @@
 #

 # PROVIDE: hostid
-# REQUIRE: root
+# REQUIRE: early
 # BEFORE: mountcritlocal
 # KEYWORD: nojail

--- /usr/src/etc/rc.d/zfs
+++ /etc/rc.d/zfs
@@ -4,7 +4,7 @@
 #

 # PROVIDE: zfs
-# REQUIRE: mountcritlocal
+# REQUIRE: hostid

This puts /etc/rc.d/zfs before /etc/rc.d/fsck, which solves the problem.

Patch attached with submission follows:

--- /usr/src/etc/rc.d/hostid
+++ /etc/rc.d/hostid
@@ -28,7 +28,7 @@
 #

 # PROVIDE: hostid
-# REQUIRE: root
+# REQUIRE: early
 # BEFORE: mountcritlocal
 # KEYWORD: nojail

--- /usr/src/etc/rc.d/zfs
+++ /etc/rc.d/zfs
@@ -4,7 +4,7 @@
 #

 # PROVIDE: zfs
-# REQUIRE: mountcritlocal
+# REQUIRE: hostid


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-rc 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Fri Feb 1 01:39:40 UTC 2008 
Responsible-Changed-Why:  
Over to maintainer(s). 

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

From: Thomas Backman <serenity@exscape.org>
To: bug-followup@FreeBSD.org,
 freebsd-rc@freebsd.org
Cc:  
Subject: Re: conf/120194: [patch] UFS volumes on ZVOLs cannot be fsck'd at boot
Date: Sun, 26 Jul 2009 13:49:42 +0200

 This bug is still relevant and unfixed as of 8.0-BETA2, although I ran  
 into it by being unable to mount ZVOLs using fstab, since /dev/zvol is  
 populated after mountcritlocal runs.
 My fix was to move ZFS to before mountcritlocal, since the root is  
 already mounted R/W, but I suppose this fix is even better since it  
 solves the fsck problem as well, which I haven't ran in to yet.
 It would be nice to see this easy fix implemented!
 
 Regards,
 Thomas
Responsible-Changed-From-To: freebsd-rc->pjd 
Responsible-Changed-By: pjd 
Responsible-Changed-When: pon 27 lip 14:46:39 2009 UTC 
Responsible-Changed-Why:  
I'll take this one. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=120194 
State-Changed-From-To: open->patched 
State-Changed-By: pjd 
State-Changed-When: ro 29 lip 05:29:08 2009 UTC 
State-Changed-Why:  
I fixed the issue in HEAD. Thanks for the report. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: conf/120194: commit references a PR
Date: Wed, 29 Jul 2009 05:24:07 +0000 (UTC)

 Author: pjd
 Date: Wed Jul 29 05:23:52 2009
 New Revision: 195938
 URL: http://svn.freebsd.org/changeset/base/195938
 
 Log:
   Currently there is a problem with fscking UFS file systems created on
   top of ZVOLs. The problem is that rc.d/fsck runs before rc.d/zfs. The
   latter makes ZVOLs to appear in /dev/. In such case rc.d/fsck cannot
   find devfs entry and aborts. We cannot simply move rc.d/zfs before
   rc.d/fsck, because we first want kern.hostid to be configured (by
   rc.d/hostid). If we won't wait (hostid will be 0) we can reuse disks
   which are in use by different systems (eg. in SAN/NAS environment).
   We also cannot move rc.d/hostid before rc.d/fsck, because rc.d/hostid on
   first system start stores generated kern.hostuuid in /etc/hostid file,
   so it needs root file system to be mounted read-write.
   
   The fix is to split rc.d/hostid so that rc.d/hostid (which will now run
   before rc.d/fsck) only generates hostid and sets up sysctls, but doesn't
   touch root file system and rc.d/hostid_save (which is run after
   rc.d/root) and only creates /etc/hostid file.
   
   With that in place, we can move ZVOL initialization to dedicated
   rc.d/zvol script which runs before rc.d/fsck.
   
   PR:		conf/120194
   Reported by:	James Snow <snow@teardrop.org>
   Reviewed by:	brooks
   Approved by:	re (kib)
   MFC after:	2 weeks
 
 Added:
   head/etc/rc.d/hostid_save   (contents, props changed)
   head/etc/rc.d/zvol   (contents, props changed)
 Modified:
   head/etc/rc.d/Makefile
   head/etc/rc.d/hostid
   head/etc/rc.d/zfs
 
 Modified: head/etc/rc.d/Makefile
 ==============================================================================
 --- head/etc/rc.d/Makefile	Wed Jul 29 00:39:46 2009	(r195937)
 +++ head/etc/rc.d/Makefile	Wed Jul 29 05:23:52 2009	(r195938)
 @@ -13,7 +13,7 @@ FILES=	DAEMON FILESYSTEMS LOGIN NETWORKI
  	fsck ftp-proxy ftpd \
  	gbde geli geli2 gssd \
  	hcsecd \
 -	hostapd hostid hostname \
 +	hostapd hostid hostid_save hostname \
  	inetd initrandom \
  	ip6addrctl ip6fw ipfilter ipfs ipfw ipmon \
  	ipnat ipsec ipxrouted \
 @@ -40,7 +40,7 @@ FILES=	DAEMON FILESYSTEMS LOGIN NETWORKI
  	watchdogd wpa_supplicant \
  	ypbind yppasswdd ypserv \
  	ypset ypupdated ypxfrd \
 -	zfs
 +	zfs zvol
  
  .if ${MK_OPENSSH} != "no"
  FILES+=	sshd
 
 Modified: head/etc/rc.d/hostid
 ==============================================================================
 --- head/etc/rc.d/hostid	Wed Jul 29 00:39:46 2009	(r195937)
 +++ head/etc/rc.d/hostid	Wed Jul 29 05:23:52 2009	(r195938)
 @@ -28,8 +28,7 @@
  #
  
  # PROVIDE: hostid
 -# REQUIRE: root
 -# BEFORE: mountcritlocal
 +# BEFORE: fsck
  # KEYWORD: nojail
  
  . /etc/rc.subr
 @@ -68,7 +67,7 @@ hostid_hardware()
  	esac
  }
  
 -hostid_reset()
 +hostid_generate()
  {
  	# First look for UUID in hardware.
  	uuid=`hostid_hardware`
 @@ -76,12 +75,17 @@ hostid_reset()
  		# If not found, fall back to software-generated UUID.
  		uuid=`uuidgen`
  	fi
 +	hostid_set $uuid
 +}
 +
 +hostid_reset()
 +{
 +	hostid_generate
  	# Store newly generated UUID in ${hostid_file}.
  	echo $uuid > ${hostid_file}
  	if [ $? -ne 0 ]; then
  		warn "could not store hostuuid in ${hostid_file}."
  	fi
 -	hostid_set $uuid
  }
  
  hostid_start()
 @@ -91,7 +95,7 @@ hostid_start()
  		hostid_set `cat ${hostid_file}`
  	else
  		# No hostid file, generate UUID.
 -		hostid_reset
 +		hostid_generate
  	fi
  }
  
 
 Added: head/etc/rc.d/hostid_save
 ==============================================================================
 --- /dev/null	00:00:00 1970	(empty, because file is newly added)
 +++ head/etc/rc.d/hostid_save	Wed Jul 29 05:23:52 2009	(r195938)
 @@ -0,0 +1,29 @@
 +#!/bin/sh
 +#
 +# $FreeBSD$
 +#
 +
 +# PROVIDE: hostid_save
 +# REQUIRE: root
 +# BEFORE: mountcritlocal
 +# KEYWORD: nojail
 +
 +. /etc/rc.subr
 +
 +name="hostid_save"
 +start_cmd="hostid_save"
 +stop_cmd=":"
 +rcvar="hostid_enable"
 +
 +hostid_save()
 +{
 +	if [ ! -r ${hostid_file} ]; then
 +		$SYSCTL_N kern.hostuuid > ${hostid_file}
 +		if [ $? -ne 0 ]; then
 +			warn "could not store hostuuid in ${hostid_file}."
 +		fi
 +	fi
 +}
 +
 +load_rc_config $name
 +run_rc_command "$1"
 
 Modified: head/etc/rc.d/zfs
 ==============================================================================
 --- head/etc/rc.d/zfs	Wed Jul 29 00:39:46 2009	(r195937)
 +++ head/etc/rc.d/zfs	Wed Jul 29 05:23:52 2009	(r195938)
 @@ -23,21 +23,11 @@ zfs_start_jail()
  
  zfs_start_main()
  {
 -	zfs volinit
  	zfs mount -a
  	zfs share -a
  	if [ ! -r /etc/zfs/exports ]; then
  		touch /etc/zfs/exports
  	fi
 -	# Enable swap on ZVOLs with property org.freebsd:swap=on.
 -	zfs list -H -o org.freebsd:swap,name -t volume | \
 -	while read state name; do
 -		case "${state}" in
 -		[oO][nN])
 -			swapon /dev/zvol/${name}
 -			;;
 -		esac
 -	done
  }
  
  zfs_start()
 @@ -58,18 +48,8 @@ zfs_stop_jail()
  
  zfs_stop_main()
  {
 -	# Disable swap on ZVOLs with property org.freebsd:swap=on.
 -	zfs list -H -o org.freebsd:swap,name -t volume | \
 -	while read state name; do
 -		case "${state}" in
 -		[oO][nN])
 -			swapoff /dev/zvol/${name}
 -			;;
 -		esac
 -	done
  	zfs unshare -a
  	zfs unmount -a
 -	zfs volfini
  }
  
  zfs_stop()
 
 Added: head/etc/rc.d/zvol
 ==============================================================================
 --- /dev/null	00:00:00 1970	(empty, because file is newly added)
 +++ head/etc/rc.d/zvol	Wed Jul 29 05:23:52 2009	(r195938)
 @@ -0,0 +1,48 @@
 +#!/bin/sh
 +#
 +# $FreeBSD$
 +#
 +
 +# PROVIDE: zvol
 +# REQUIRE: hostid
 +# BEFORE: fsck
 +# KEYWORD: nojail
 +
 +. /etc/rc.subr
 +
 +name="zvol"
 +rcvar="zfs_enable"
 +start_cmd="zvol_start"
 +stop_cmd="zvol_stop"
 +required_modules="zfs"
 +
 +zvol_start()
 +{
 +	zfs volinit
 +	# Enable swap on ZVOLs with property org.freebsd:swap=on.
 +	zfs list -H -o org.freebsd:swap,name -t volume | \
 +	while read state name; do
 +		case "${state}" in
 +		[oO][nN])
 +			swapon /dev/zvol/${name}
 +			;;
 +		esac
 +	done
 +}
 +
 +zvol_stop()
 +{
 +	# Disable swap on ZVOLs with property org.freebsd:swap=on.
 +	zfs list -H -o org.freebsd:swap,name -t volume | \
 +	while read state name; do
 +		case "${state}" in
 +		[oO][nN])
 +			swapoff /dev/zvol/${name}
 +			;;
 +		esac
 +	done
 +	zfs volfini
 +}
 +
 +load_rc_config $name
 +run_rc_command "$1"
 _______________________________________________
 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"
 
State-Changed-From-To: patched->closed 
State-Changed-By: pjd 
State-Changed-When: wto 22 wrz 2009 12:41:10 UTC 
State-Changed-Why:  
Fix merged to stable/8. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=120194 
>Unformatted:
