From owner-freebsd-rc@FreeBSD.ORG Sat Jun 8 18:44:51 2013 Return-Path: Delivered-To: rc@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 8F3E4482; Sat, 8 Jun 2013 18:44:51 +0000 (UTC) (envelope-from smh@freebsd.org) Received: from smtp1.multiplay.co.uk (smtp1.multiplay.co.uk [85.236.96.35]) by mx1.freebsd.org (Postfix) with ESMTP id 42C321FDA; Sat, 8 Jun 2013 18:44:48 +0000 (UTC) Received: by smtp1.multiplay.co.uk (Postfix, from userid 65534) id B53A120E7088A; Sat, 8 Jun 2013 18:44:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.multiplay.co.uk X-Spam-Level: X-Spam-Status: No, score=-2.5 required=8.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.3.1 Received: from r2d2 (82-69-141-170.dsl.in-addr.zen.co.uk [82.69.141.170]) by smtp1.multiplay.co.uk (Postfix) with ESMTPA id 1010C20E70847; Sat, 8 Jun 2013 18:44:44 +0000 (UTC) Message-ID: From: "Steven Hartland" To: Subject: Feeback on patch to add ZFS support to mdconfig rc.d scripts Date: Sat, 8 Jun 2013 19:44:45 +0100 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_02DE_01CE6480.A0B2FFC0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5931 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 Cc: zfs-devel@FreeBSD.org X-BeenThere: freebsd-rc@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Discussion related to /etc/rc.d design and implementation." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 Jun 2013 18:44:51 -0000 This is a multi-part message in MIME format. ------=_NextPart_000_02DE_01CE6480.A0B2FFC0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit 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 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 ------=_NextPart_000_02DE_01CE6480.A0B2FFC0 Content-Type: application/octet-stream; name="mdconfig-zfs.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="mdconfig-zfs.patch" Add ZFS pool creation support to mdconfig rc.d script=0A= =0A= Fix failure error redirection in mount check=0A= =0A= Fix invalid configuration detection enabling -t vnode=0A= to be skipped if -f is specified as supported=0A= by mdconfig.=0A= =0A= Fix fsck not working if mount point is not present in fstab.=0A= =0A= TODO: update rc.conf man page=0A= --- /etc/rc.d/mdconfig.orig 2013-06-08 00:55:48.599761883 +0000=0A= +++ /etc/rc.d/mdconfig 2013-06-08 16:24:06.092215311 +0000=0A= @@ -61,6 +61,29 @@=0A= fi=0A= }=0A= =0A= +get_opt()=0A= +{=0A= + local _flag _param _opt=0A= +=0A= + _flag=3D$1=0A= + _param=3D$2=0A= +=0A= + _opt=3D${_config##*-${_flag}\ }=0A= + if [ "${_opt}" =3D "${_config}" ]; then=0A= + _opt=3D""=0A= + else=0A= + _opt=3D${_opt%%\ *}=0A= + fi=0A= + eval _${_param}=3D${_opt}=0A= + debug "${_md} ${_param}=3D${_opt}"=0A= +=0A= + if [ -z "${_opt}" ]; then=0A= + return 0=0A= + fi=0A= +=0A= + return 1=0A= +}=0A= +=0A= init_variables()=0A= {=0A= local _i=0A= @@ -70,16 +93,20 @@=0A= _dev=3D"/dev/${_md}"=0A= eval _config=3D\$mdconfig_${_md}=0A= eval _newfs=3D\$mdconfig_${_md}_newfs=0A= + eval _zpool=3D\$mdconfig_${_md}_zfs_pool=0A= + eval _zflags=3D\$mdconfig_${_md}_zfs_flags=0A= =0A= - _type=3D${_config##*-t\ }=0A= - _type=3D${_type%%\ *}=0A= + get_opt "t" "type"=0A= + get_opt "f" "file"=0A= if [ -z "${_type}" ]; then=0A= - err 1 "You need to specify \"-t \" in mdconfig_${_md}"=0A= + if [ -n "${_file}" ]; then=0A= + _type=3D"vnode"=0A= + else=0A= + err 1 "You need to specify \"-t \" in mdconfig_${_md}"=0A= + fi=0A= fi=0A= =0A= if [ "${_type}" =3D "vnode" ]; then=0A= - _file=3D${_config##*-f\ }=0A= - _file=3D${_file%%\ *}=0A= if [ -z "${_file}" ]; then=0A= err 2 "You need to specify \"-f \" in mdconfig_${_md} for = vnode devices"=0A= fi=0A= @@ -96,11 +123,13 @@=0A= debug "${_md} file: ${_file}"=0A= debug "${_md} fs: ${_fs}"=0A= debug "${_md} newfs flags: ${_newfs}"=0A= + debug "${_md} ZFS pool: ${_zpool}"=0A= + debug "${_md} ZFS flags: ${_zflags}"=0A= }=0A= =0A= mdconfig_start()=0A= {=0A= - local _md _mp _config _type _dev _file _fs _newfs _fsck_cmd=0A= + local _md _mp _config _type _dev _file _fs _newfs _fsck_cmd _zpool = _zflags=0A= =0A= for _md in ${_mdconfig_list}; do=0A= init_variables ${_md}=0A= @@ -126,6 +155,18 @@=0A= echo "Creating ${_md} device failed, moving on."=0A= continue=0A= fi=0A= +=0A= + if [ -n "${_zpool}" ]; then=0A= + if [ "${_type}" =3D "vnode" ]; then=0A= + echo "Importing ZFS pool ${_zpool}."=0A= + zpool import ${_zpool}=0A= + else=0A= + echo "Creating ZFS pool ${_zpool}."=0A= + zpool create ${_zflags} ${_zpool} ${_md}=0A= + fi=0A= + continue=0A= + fi=0A= +=0A= # Skip fsck for uzip devices.=0A= if [ "${_type}" =3D "vnode" ]; then=0A= if [ "${_file}" !=3D "${_file%.uzip}" ]; then=0A= @@ -143,7 +184,8 @@=0A= else=0A= newfs ${_newfs} ${_dev} >/dev/null=0A= fi=0A= - if mount -d ${_dev} 2>&1 >/dev/null; then=0A= +=0A= + if mount -d ${_dev} >/dev/null 2>&1; then=0A= echo "Mounting ${_dev}."=0A= mount ${_dev}=0A= fi=0A= @@ -159,7 +201,12 @@=0A= init_variables ${_md}=0A= if [ "${_type}" !=3D "vnode" -o "${_fs}" =3D "/" ]; then=0A= for _i in `df ${_dev} 2>/dev/null`; do _mp=3D${_i}; done=0A= - if [ -z "${_mp}" -o "${_mp}" !=3D "${_mp%%%}" ]; then=0A= + if [ -n "${_zpool}" ]; then=0A= + if zpool list ${_zpool} >/dev/null 2>&1; then=0A= + echo "Exporting ZFS pool ${_zpool}."=0A= + zpool export ${_zpool}=0A= + fi=0A= + elif [ -z "${_mp}" -o "${_mp}" !=3D "${_mp%%%}" ]; then=0A= echo "Device ${_dev} isn't mounted."=0A= else=0A= echo "Umounting ${_dev}."=0A= --- /etc/rc.d/mdconfig2.orig 2013-06-08 16:33:49.583875813 +0000=0A= +++ /etc/rc.d/mdconfig2 2013-06-08 17:28:02.079420674 +0000=0A= @@ -62,6 +62,29 @@=0A= fi=0A= }=0A= =0A= +get_opt()=0A= +{=0A= + local _flag _param _opt=0A= +=0A= + _flag=3D$1=0A= + _param=3D$2=0A= +=0A= + _opt=3D${_config##*-${_flag}\ }=0A= + if [ "${_opt}" =3D "${_config}" ]; then=0A= + _opt=3D""=0A= + else=0A= + _opt=3D${_opt%%\ *}=0A= + fi=0A= + eval _${_param}=3D${_opt}=0A= + debug "${_md} ${_param}=3D${_opt}"=0A= +=0A= + if [ -z "${_opt}" ]; then=0A= + return 0=0A= + fi=0A= +=0A= + return 1=0A= +}=0A= +=0A= init_variables()=0A= {=0A= local _i=0A= @@ -75,16 +98,19 @@=0A= eval _perms=3D\$mdconfig_${_md}_perms=0A= eval _files=3D\$mdconfig_${_md}_files=0A= eval _populate=3D\$mdconfig_${_md}_cmd=0A= + eval _zpool=3D\$mdconfig_${_md}_zfs_pool=0A= =0A= - _type=3D${_config##*-t\ }=0A= - _type=3D${_type%%\ *}=0A= + get_opt "t" "type"=0A= + get_opt "f" "file"=0A= if [ -z "${_type}" ]; then=0A= - err 1 "You need to specify \"-t \" in mdconfig_${_md}"=0A= + if [ -n "${_file}" ]; then=0A= + _type=3D"vnode"=0A= + else=0A= + err 1 "You need to specify \"-t \" in mdconfig_${_md}"=0A= + fi=0A= fi=0A= =0A= if [ "${_type}" =3D "vnode" ]; then=0A= - _file=3D${_config##*-f\ }=0A= - _file=3D${_file%%\ *}=0A= if [ -z "${_file}" ]; then=0A= err 2 "You need to specify \"-f \" in mdconfig_${_md} for = vnode devices"=0A= fi=0A= @@ -136,26 +162,42 @@=0A= echo "Creating ${_md} device failed, moving on."=0A= continue=0A= fi=0A= - # Skip fsck for uzip devices.=0A= - if [ "${_file}" !=3D "${_file%.uzip}" ]; then=0A= - _fsck_cmd=3D":"=0A= - elif checkyesno background_fsck; then=0A= - _fsck_cmd=3D"fsck -F"=0A= +=0A= + if [ -n "${_zpool}" ]; then=0A= + if [ "${_type}" =3D "vnode" ]; then=0A= + echo "Importing ZFS pool ${_zpool}."=0A= + zpool import ${_zpool}=0A= + else=0A= + echo "Creating ZFS pool ${_zpool}."=0A= + zpool create ${_zflags} ${_zpool} ${_md}=0A= + fi=0A= else=0A= - _fsck_cmd=3D"fsck"=0A= - fi=0A= - if ! eval ${_fsck_cmd} -p ${_dev} >/dev/null; then=0A= - echo "Fsck failed on ${_dev}, not mounting the filesystem."=0A= - continue=0A= - fi=0A= - if mount -d ${_dev} >/dev/null 2>&1; then=0A= - echo "Mounting ${_dev}."=0A= - mount ${_dev}=0A= + # Skip fsck for uzip devices.=0A= + if [ "${_file}" !=3D "${_file%.uzip}" ]; then=0A= + _fsck_cmd=3D":"=0A= + elif checkyesno background_fsck; then=0A= + _fsck_cmd=3D"fsck -t ufs -F"=0A= + else=0A= + _fsck_cmd=3D"fsck -t ufs"=0A= + fi=0A= + if ! eval ${_fsck_cmd} -p ${_dev} >/dev/null; then=0A= + echo "Fsck failed on ${_dev}, not mounting the filesystem."=0A= + continue=0A= + fi=0A= + if mount -d ${_dev} >/dev/null 2>&1; then=0A= + echo "Mounting ${_dev}."=0A= + mount ${_dev}=0A= + fi=0A= fi=0A= fi=0A= =0A= - for _i in `df ${_dev} 2>/dev/null`; do _mp=3D${_i}; done=0A= - if [ ! -z "${_mp}" -a "${_mp}" =3D "${_mp%%%}" ]; then=0A= + if [ -n "${_zpool}" ]; then=0A= + _mp=3D`zfs list -H -o mountpoint ${_zpool} 2>/dev/null`=0A= + else=0A= + for _i in `df ${_dev} 2>/dev/null`; do _mp=3D${_i}; done=0A= + fi=0A= +=0A= + if [ -n "${_mp}" -a "${_mp}" =3D "${_mp%%%}" ]; then=0A= _mounted=3D"yes"=0A= fi=0A= =0A= ------=_NextPart_000_02DE_01CE6480.A0B2FFC0--