Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 9 Jun 2013 19:13:31 +0100
From:      "Steven Hartland" <killing@multiplay.co.uk>
To:        "Hiroki Sato" <hrs@FreeBSD.org>
Cc:        rc@FreeBSD.org, zfs-devel@FreeBSD.org
Subject:   Re: Feeback on patch to add ZFS support to mdconfig rc.d scripts
Message-ID:  <5E2843FF4724492FBF2A29E43B698385@multiplay.co.uk>
References:  <B5D8F93BF50D4D57BF31A4B2FCBA7621@multiplay.co.uk> <20130609.041903.541782050134731313.hrs@allbsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
----- Original Message ----- 
From: "Hiroki Sato" <hrs@FreeBSD.org>
> I think this should be separated into adding non-fs md support into
> rc.d/mdconfig and on-the-fly zpool creation/import into rc.d/zfs
> since the rc.d/mdconfig script does not (and should not) depend on
> zfs.ko module.
>
> rc.d/mdconfig is located before mountcritlocal, so probably
> rc.d/zfs_md or something is needed just after rc.d/mdconfig2.

Thanks for that Hiroki. If I understand correctly that your only
concern is the zfs module dependency? If so then its easier to make
that a dynamic dependency using a prestart.

Updated patch attached, which does just that.

Does this look better?

    Regards
    Steve

================================================
This e.mail is private and confidential between Multiplay (UK) Ltd. and the person or entity to whom it is addressed. In the event of misdirection, the recipient is prohibited from using, copying, printing or otherwise disseminating it or any information contained in it. 

In the event of misdirection, illegible or incomplete transmission please telephone +44 845 868 1337
or return the E.mail to postmaster@multiplay.co.uk.
[-- Attachment #2 --]
Add ZFS pool creation support to mdconfig rc.d script

Fix failure error redirection in mount check

Fix invalid configuration detection enabling -t vnode
to be skipped if -f <file> is specified as supported
by mdconfig.

Fix fsck not working if mount point is not present in fstab.

TODO: update rc.conf man page
--- /etc/rc.d/mdconfig.orig	2013-06-08 00:55:48.599761883 +0000
+++ /etc/rc.d/mdconfig	2013-06-09 18:02:08.037511687 +0000
@@ -35,9 +35,28 @@
 name="mdconfig"
 stop_cmd="mdconfig_stop"
 start_cmd="mdconfig_start"
-start_precmd='[ -n "${_mdconfig_list}" ]'
+start_precmd="mdconfig_prestart"
 required_modules="geom_md:g_md"
 
+mdconfig_prestart()
+{
+	local _mp
+
+	if [ -z "${_mdconfig_list}" ]; then
+		return 1
+	fi
+
+	for _md in ${_mdconfig_list}; do
+		eval _zpool=\$mdconfig_${_md}_zfs_pool
+		if [ -n "${_zpool}" ]; then
+			required_modules="$required_modules zfs"
+			break
+		fi
+	done
+
+	return 0
+}
+
 is_readonly()
 {
 	local _mp _ret
@@ -61,6 +80,29 @@
 	fi
 }
 
+get_opt()
+{
+	local _flag _param _opt
+
+	_flag=$1
+	_param=$2
+
+	_opt=${_config##*-${_flag}\ }
+	if [ "${_opt}" = "${_config}" ]; then
+		_opt=""
+	else
+		_opt=${_opt%%\ *}
+	fi
+	eval _${_param}=${_opt}
+	debug "${_md} ${_param}=${_opt}"
+
+	if [ -z "${_opt}" ]; then
+		return 0
+	fi
+
+	return 1
+}
+
 init_variables()
 {
 	local _i
@@ -70,16 +112,20 @@
 	_dev="/dev/${_md}"
 	eval _config=\$mdconfig_${_md}
 	eval _newfs=\$mdconfig_${_md}_newfs
+	eval _zpool=\$mdconfig_${_md}_zfs_pool
+	eval _zflags=\$mdconfig_${_md}_zfs_flags
 
-	_type=${_config##*-t\ }
-	_type=${_type%%\ *}
+	get_opt "t" "type"
+	get_opt "f" "file"
 	if [ -z "${_type}" ]; then
-		err 1 "You need to specify \"-t <type>\" in mdconfig_${_md}"
+		if [ -n "${_file}" ]; then
+			_type="vnode"
+		else
+			err 1 "You need to specify \"-t <type>\" in mdconfig_${_md}"
+		fi
 	fi
 
 	if [ "${_type}" = "vnode" ]; then
-		_file=${_config##*-f\ }
-		_file=${_file%%\ *}
 		if [ -z "${_file}" ]; then
 			err 2 "You need to specify \"-f <file>\" in mdconfig_${_md} for vnode devices"
 		fi
@@ -96,11 +142,13 @@
 	debug "${_md} file: ${_file}"
 	debug "${_md} fs: ${_fs}"
 	debug "${_md} newfs flags: ${_newfs}"
+	debug "${_md} ZFS pool: ${_zpool}"
+	debug "${_md} ZFS flags: ${_zflags}"
 }
 
 mdconfig_start()
 {
-	local _md _mp _config _type _dev _file _fs _newfs _fsck_cmd
+	local _md _mp _config _type _dev _file _fs _newfs _fsck_cmd _zpool _zflags
 
 	for _md in ${_mdconfig_list}; do
 		init_variables ${_md}
@@ -126,14 +174,26 @@
 				echo "Creating ${_md} device failed, moving on."
 				continue
 			fi
+
+			if [ -n "${_zpool}" ]; then
+				if [ "${_type}" = "vnode" ]; then
+					echo "Importing ZFS pool ${_zpool}."
+					zpool import ${_zpool}
+				else
+					echo "Creating ZFS pool ${_zpool}."
+					zpool create ${_zflags} ${_zpool} ${_md}
+				fi
+				continue
+			fi
+
 			# Skip fsck for uzip devices.
 			if [ "${_type}" = "vnode" ]; then
 				if [ "${_file}" != "${_file%.uzip}" ]; then
 					_fsck_cmd=":"
 				elif checkyesno background_fsck; then
-					_fsck_cmd="fsck -F"
+					_fsck_cmd="fsck -t ufs -F"
 				else
-					_fsck_cmd="fsck"
+					_fsck_cmd="fsck -t ufs"
 				fi
 				if ! eval ${_fsck_cmd} -p ${_dev} >/dev/null; then
 					echo "Fsck failed on ${_dev}, not mounting the filesystem."
@@ -143,7 +203,8 @@
 			else
 				newfs ${_newfs} ${_dev} >/dev/null
 			fi
-			if mount -d ${_dev} 2>&1 >/dev/null; then
+
+			if mount -d ${_dev} >/dev/null 2>&1; then
 				echo "Mounting ${_dev}."
 				mount ${_dev}
 			fi
@@ -159,7 +220,12 @@
 		init_variables ${_md}
 		if [ "${_type}" != "vnode" -o "${_fs}" = "/" ]; then
 			for _i in `df ${_dev} 2>/dev/null`; do _mp=${_i}; done
-			if [ -z "${_mp}" -o "${_mp}" != "${_mp%%%}" ]; then
+			if [ -n "${_zpool}" ]; then
+				if zpool list ${_zpool} >/dev/null 2>&1; then
+					echo "Exporting ZFS pool ${_zpool}."
+					zpool export ${_zpool}
+				fi
+			elif [ -z "${_mp}" -o "${_mp}" != "${_mp%%%}" ]; then
 				echo "Device ${_dev} isn't mounted."
 			else
 				echo "Umounting ${_dev}."
--- /etc/rc.d/mdconfig2.orig	2013-06-08 16:33:49.583875813 +0000
+++ /etc/rc.d/mdconfig2	2013-06-09 18:03:39.055114045 +0000
@@ -36,9 +36,28 @@
 name="mdconfig2"
 stop_cmd="mdconfig2_stop"
 start_cmd="mdconfig2_start"
-start_precmd='[ -n "${_mdconfig2_list}" ]'
+start_precmd="mdconfig2_prestart"
 required_modules="geom_md:g_md"
 
+mdconfig2_prestart()
+{
+	local _mp
+
+	if [ -z "${_mdconfig2_list}" ]; then
+		return 1
+	fi
+
+	for _md in ${_mdconfig2_list}; do
+		eval _zpool=\$mdconfig_${_md}_zfs_pool
+		if [ -n "${_zpool}" ]; then
+			required_modules="$required_modules zfs"
+			break
+		fi
+	done
+
+	return 0
+}
+
 is_readonly()
 {
 	local _mp _ret
@@ -62,6 +81,29 @@
 	fi
 }
 
+get_opt()
+{
+	local _flag _param _opt
+
+	_flag=$1
+	_param=$2
+
+	_opt=${_config##*-${_flag}\ }
+	if [ "${_opt}" = "${_config}" ]; then
+		_opt=""
+	else
+		_opt=${_opt%%\ *}
+	fi
+	eval _${_param}=${_opt}
+	debug "${_md} ${_param}=${_opt}"
+
+	if [ -z "${_opt}" ]; then
+		return 0
+	fi
+
+	return 1
+}
+
 init_variables()
 {
 	local _i
@@ -75,16 +117,19 @@
 	eval _perms=\$mdconfig_${_md}_perms
 	eval _files=\$mdconfig_${_md}_files
 	eval _populate=\$mdconfig_${_md}_cmd
+	eval _zpool=\$mdconfig_${_md}_zfs_pool
 
-	_type=${_config##*-t\ }
-	_type=${_type%%\ *}
+	get_opt "t" "type"
+	get_opt "f" "file"
 	if [ -z "${_type}" ]; then
-		err 1 "You need to specify \"-t <type>\" in mdconfig_${_md}"
+		if [ -n "${_file}" ]; then
+			_type="vnode"
+		else
+			err 1 "You need to specify \"-t <type>\" in mdconfig_${_md}"
+		fi
 	fi
 
 	if [ "${_type}" = "vnode" ]; then
-		_file=${_config##*-f\ }
-		_file=${_file%%\ *}
 		if [ -z "${_file}" ]; then
 			err 2 "You need to specify \"-f <file>\" in mdconfig_${_md} for vnode devices"
 		fi
@@ -136,26 +181,42 @@
 				echo "Creating ${_md} device failed, moving on."
 				continue
 			fi
-			# Skip fsck for uzip devices.
-			if [ "${_file}" != "${_file%.uzip}" ]; then
-				_fsck_cmd=":"
-			elif checkyesno background_fsck; then
-				_fsck_cmd="fsck -F"
+
+			if [ -n "${_zpool}" ]; then
+				if [ "${_type}" = "vnode" ]; then
+					echo "Importing ZFS pool ${_zpool}."
+					zpool import ${_zpool}
+				else
+					echo "Creating ZFS pool ${_zpool}."
+					zpool create ${_zflags} ${_zpool} ${_md}
+				fi
 			else
-				_fsck_cmd="fsck"
-			fi
-			if ! eval ${_fsck_cmd} -p ${_dev} >/dev/null; then
-				echo "Fsck failed on ${_dev}, not mounting the filesystem."
-				continue
-			fi
-			if mount -d ${_dev} >/dev/null 2>&1; then
-				echo "Mounting ${_dev}."
-				mount ${_dev}
+				# Skip fsck for uzip devices.
+				if [ "${_file}" != "${_file%.uzip}" ]; then
+					_fsck_cmd=":"
+				elif checkyesno background_fsck; then
+					_fsck_cmd="fsck -t ufs -F"
+				else
+					_fsck_cmd="fsck -t ufs"
+				fi
+				if ! eval ${_fsck_cmd} -p ${_dev} >/dev/null; then
+					echo "Fsck failed on ${_dev}, not mounting the filesystem."
+					continue
+				fi
+				if mount -d ${_dev} >/dev/null 2>&1; then
+					echo "Mounting ${_dev}."
+					mount ${_dev}
+				fi
 			fi
 		fi
 
-		for _i in `df ${_dev} 2>/dev/null`; do _mp=${_i}; done
-		if [ ! -z "${_mp}" -a "${_mp}" = "${_mp%%%}" ]; then
+		if [ -n "${_zpool}" ]; then
+			_mp=`zfs list -H -o mountpoint ${_zpool} 2>/dev/null`
+		else
+			for _i in `df ${_dev} 2>/dev/null`; do _mp=${_i}; done
+		fi
+
+		if [ -n "${_mp}" -a "${_mp}" = "${_mp%%%}" ]; then
 			_mounted="yes"
 		fi
 

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5E2843FF4724492FBF2A29E43B698385>