From ady@enterprisebsd.rofug.ro  Sat Feb  2 22:27:38 2008
Return-Path: <ady@enterprisebsd.rofug.ro>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id E4F8816A421
	for <FreeBSD-gnats-submit@freebsd.org>; Sat,  2 Feb 2008 22:27:38 +0000 (UTC)
	(envelope-from ady@enterprisebsd.rofug.ro)
Received: from bartok.rofug.ro (bartok.rofug.ro [80.86.106.65])
	by mx1.freebsd.org (Postfix) with ESMTP id 846D713C4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Sat,  2 Feb 2008 22:27:38 +0000 (UTC)
	(envelope-from ady@enterprisebsd.rofug.ro)
Received: from enterprisebsd.rofug.ro (unknown [80.86.111.37])
	by bartok.rofug.ro (Postfix) with ESMTP id 1B6A533C32;
	Sat,  2 Feb 2008 23:54:32 +0200 (EET)
Received: (from ady@localhost)
	by enterprisebsd.rofug.ro (8.14.1/8.14.1/Submit) id m12LsVbG070370;
	Sat, 2 Feb 2008 23:54:31 +0200 (EET)
	(envelope-from ady)
Message-Id: <200802022154.m12LsVbG070370@enterprisebsd.rofug.ro>
Date: Sat, 2 Feb 2008 23:54:31 +0200 (EET)
From: Adrian Penisoara <ady@freebsd.ady.ro>
Reply-To: Adrian Penisoara <ady@freebsd.ady.ro>
To: FreeBSD-gnats-submit@freebsd.org
Cc: ady@freebsd.ady.ro
Subject: [PATCH] Split ZFS volume startup / ease ZFS swap volumes management
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         120228
>Category:       conf
>Synopsis:       [zfs] [patch] Split ZFS volume startup / ease ZFS swap volumes management
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    pjd
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Feb 02 22:30:00 UTC 2008
>Closed-Date:    Wed Sep 09 18:31:25 UTC 2009
>Last-Modified:  Wed Sep 09 18:31:25 UTC 2009
>Originator:     Adrian Penisoara
>Release:        FreeBSD 7.0-PRERELEASE
>Organization:
EnterpriseBSD.info
>Environment:

FreeBSD fbsd7-devel 7.0-PRERELEASE FreeBSD 7.0-PRERELEASE #1: Wed Jan  2 20:25:02 EET 2008     root@fbsd7-devel:/build/obj/build/src/sys/TEST  i386

>Description:

Management for ZFS swap volumes is "hardcoded" into /etc/rc.d/zfs script. This
should be decoupled from ZFS initialization and relinquished back to normal
swap init script.

Moreover, ZFS volumes should be initialized early in the boot sequence for
other services like swapspace to make use of them.
>How-To-Repeat:

 Currently ZFS volumes are started late and ZFS swapspace is managed from the
/etc/rc.d/zfs initialization script.

>Fix:

Split ZFS initialization in half, initializing the ZFS volumes early in the
boot sequence. ZFS volume backed swap should be mounted as usual from 
/etc/fstab using the /dev/zvol/* entries. Care must be taken for the swapspace
to be deactivated before taking down the [ZFS] volumes.

 Patch below -- please use "patch -p3".


diff -ruN .zfs/snapshot/RELENG_7_01Jan08/etc/rc.d/Makefile .zfs/snapshot/RELENG_7_01Jan08_6_zfs_rc.d_fixup/etc/rc.d/Makefile
--- .zfs/snapshot/RELENG_7_01Jan08/etc/rc.d/Makefile	2007-12-29 22:32:47.960389378 +0200
+++ .zfs/snapshot/RELENG_7_01Jan08_6_zfs_rc.d_fixup/etc/rc.d/Makefile	2008-01-06 22:24:39.201293236 +0200
@@ -41,7 +41,7 @@
 	watchdogd wpa_supplicant \
 	ypbind yppasswdd ypserv \
 	ypset ypupdated ypxfrd \
-	zfs
+	zfs zfsvolumes
 
 .if ${MK_OPENSSH} != "no"
 FILES+=	sshd
diff -ruN .zfs/snapshot/RELENG_7_01Jan08/etc/rc.d/swap1 .zfs/snapshot/RELENG_7_01Jan08_6_zfs_rc.d_fixup/etc/rc.d/swap1
--- .zfs/snapshot/RELENG_7_01Jan08/etc/rc.d/swap1	2007-12-29 22:32:48.145332158 +0200
+++ .zfs/snapshot/RELENG_7_01Jan08_6_zfs_rc.d_fixup/etc/rc.d/swap1	2008-01-04 05:28:45.716495161 +0200
@@ -12,7 +12,7 @@
 
 name="swap1"
 start_cmd='swapon -a'
-stop_cmd=':'
+stop_cmd='swapoff -a'
 
 load_rc_config swap
 run_rc_command "$1"
diff -ruN .zfs/snapshot/RELENG_7_01Jan08/etc/rc.d/zfs .zfs/snapshot/RELENG_7_01Jan08_6_zfs_rc.d_fixup/etc/rc.d/zfs
--- .zfs/snapshot/RELENG_7_01Jan08/etc/rc.d/zfs	2007-12-29 22:32:48.170309354 +0200
+++ .zfs/snapshot/RELENG_7_01Jan08_6_zfs_rc.d_fixup/etc/rc.d/zfs	2008-01-04 05:29:06.989747209 +0200
@@ -23,21 +23,11 @@
 
 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_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()
diff -ruN .zfs/snapshot/RELENG_7_01Jan08/etc/rc.d/zfsvolumes .zfs/snapshot/RELENG_7_01Jan08_6_zfs_rc.d_fixup/etc/rc.d/zfsvolumes
--- .zfs/snapshot/RELENG_7_01Jan08/etc/rc.d/zfsvolumes	1970-01-01 02:00:00.000000000 +0200
+++ .zfs/snapshot/RELENG_7_01Jan08_6_zfs_rc.d_fixup/etc/rc.d/zfsvolumes	2008-01-04 05:29:10.017642374 +0200
@@ -0,0 +1,18 @@
+#!/bin/sh
+#
+# $FreeBSD: src/etc/rc.d/zfs,v 1.5 2007/04/22 20:55:08 pjd Exp $
+#
+
+# PROVIDE: zfsvolumes disks
+# KEYWORD: nojail shutdown
+
+. /etc/rc.subr
+
+name="zfs"
+rcvar="zfs_enable"
+start_cmd="zfs volinit"
+stop_cmd="zfs volfini"
+required_modules="zfs"
+
+load_rc_config $name
+run_rc_command "$1"
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-rc 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Sun Feb 3 00:55:24 UTC 2008 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=120228 
State-Changed-From-To: open->closed 
State-Changed-By: pjd 
State-Changed-When: ro 9 wrz 2009 18:14:21 UTC 
State-Changed-Why:  
Thank you for your patch, but I already committed something along those line. 
rc.d/zfs script was broken and there is now also rc.d/zvol script. It was 
created so ZVOL-based file systems can be mounted from /etc/fstab. 
Using ZVOL property to setup swap was intended - ZFS file systems are also not 
mounted from /etc/fstab. All in all using ZVOL for swap is unreliable anyway. 


Responsible-Changed-From-To: freebsd-rc->pjd 
Responsible-Changed-By: pjd 
Responsible-Changed-When: ro 9 wrz 2009 18:14:21 UTC 
Responsible-Changed-Why:  
I'll take this one. 

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