Date: Sat, 8 Jun 2013 19:44:45 +0100 From: "Steven Hartland" <smh@freebsd.org> To: <rc@freebsd.org> Cc: zfs-devel@FreeBSD.org Subject: Feeback on patch to add ZFS support to mdconfig rc.d scripts Message-ID: <B5D8F93BF50D4D57BF31A4B2FCBA7621@multiplay.co.uk>
next in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
Attached is a patch which adds ZFS support to the
mdconfig rc.d scritps along with some other little
fixes while I was there.
Our use case for this here is to create a ZFS pool
on a swap backed node for temporary data which supports
all the cool features of ZFS, for us thats compression.
Possible enhancements, suggested by pjd in IRC include
default flags such as:-o cachefile=none
Current summary:-
=======
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
=======
I've tested on a number of configs including:-
mdconfig_md0="-t swap -s 12g"
mdconfig_md0_zfs_pool="tmpfs"
mdconfig_md0_zfs_flags="-m /mnt -o cachefile=none -O compression=on -O atime=off -O exec=off -O primarycache=none -O
sync=disabled"
mdconfig_md1="-f /data/test.vnode"
mdconfig_md1_zfs_pool="vnodefs"
mdconfig_md1_zfs_flags="-m /root/vnode -o cachefile=none"
mdconfig_md2="-f /data/test2.vnode"
mdconfig_md3="-s 12g" # Should error, didn't before.
What do people think?
Regards
steve
[-- 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-08 16:24:06.092215311 +0000
@@ -61,6 +61,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 +93,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 +123,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,6 +155,18 @@
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
@@ -143,7 +184,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 +201,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-08 17:28:02.079420674 +0000
@@ -62,6 +62,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 +98,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 +162,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?B5D8F93BF50D4D57BF31A4B2FCBA7621>
