From owner-freebsd-rc@FreeBSD.ORG Sun Jun 9 18:13:36 2013 Return-Path: Delivered-To: rc@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id EB925710; Sun, 9 Jun 2013 18:13:36 +0000 (UTC) (envelope-from prvs=18721298a7=killing@multiplay.co.uk) Received: from mail1.multiplay.co.uk (mail1.multiplay.co.uk [85.236.96.23]) by mx1.freebsd.org (Postfix) with ESMTP id 317E51819; Sun, 9 Jun 2013 18:13:35 +0000 (UTC) Received: from r2d2 ([82.69.141.170]) by mail1.multiplay.co.uk (mail1.multiplay.co.uk [85.236.96.23]) (MDaemon PRO v10.0.4) with ESMTP id md50004232324.msg; Sun, 09 Jun 2013 19:13:35 +0100 X-Spam-Processed: mail1.multiplay.co.uk, Sun, 09 Jun 2013 19:13:35 +0100 (not processed: message from valid local sender) X-MDDKIM-Result: neutral (mail1.multiplay.co.uk) X-MDRemoteIP: 82.69.141.170 X-Return-Path: prvs=18721298a7=killing@multiplay.co.uk X-Envelope-From: killing@multiplay.co.uk Message-ID: <5E2843FF4724492FBF2A29E43B698385@multiplay.co.uk> From: "Steven Hartland" To: "Hiroki Sato" References: <20130609.041903.541782050134731313.hrs@allbsd.org> Subject: Re: Feeback on patch to add ZFS support to mdconfig rc.d scripts Date: Sun, 9 Jun 2013 19:13:31 +0100 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0570_01CE6545.6E1C99C0" 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: rc@FreeBSD.org, 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: Sun, 09 Jun 2013 18:13:37 -0000 This is a multi-part message in MIME format. ------=_NextPart_000_0570_01CE6545.6E1C99C0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit ----- Original Message ----- From: "Hiroki Sato" > 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. ------=_NextPart_000_0570_01CE6545.6E1C99C0 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-09 18:02:08.037511687 +0000=0A= @@ -35,9 +35,28 @@=0A= name=3D"mdconfig"=0A= stop_cmd=3D"mdconfig_stop"=0A= start_cmd=3D"mdconfig_start"=0A= -start_precmd=3D'[ -n "${_mdconfig_list}" ]'=0A= +start_precmd=3D"mdconfig_prestart"=0A= required_modules=3D"geom_md:g_md"=0A= =0A= +mdconfig_prestart()=0A= +{=0A= + local _mp=0A= +=0A= + if [ -z "${_mdconfig_list}" ]; then=0A= + return 1=0A= + fi=0A= +=0A= + for _md in ${_mdconfig_list}; do=0A= + eval _zpool=3D\$mdconfig_${_md}_zfs_pool=0A= + if [ -n "${_zpool}" ]; then=0A= + required_modules=3D"$required_modules zfs"=0A= + break=0A= + fi=0A= + done=0A= +=0A= + return 0=0A= +}=0A= +=0A= is_readonly()=0A= {=0A= local _mp _ret=0A= @@ -61,6 +80,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 +112,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 +142,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,14 +174,26 @@=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= _fsck_cmd=3D":"=0A= elif checkyesno background_fsck; then=0A= - _fsck_cmd=3D"fsck -F"=0A= + _fsck_cmd=3D"fsck -t ufs -F"=0A= else=0A= - _fsck_cmd=3D"fsck"=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= @@ -143,7 +203,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 +220,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-09 18:03:39.055114045 +0000=0A= @@ -36,9 +36,28 @@=0A= name=3D"mdconfig2"=0A= stop_cmd=3D"mdconfig2_stop"=0A= start_cmd=3D"mdconfig2_start"=0A= -start_precmd=3D'[ -n "${_mdconfig2_list}" ]'=0A= +start_precmd=3D"mdconfig2_prestart"=0A= required_modules=3D"geom_md:g_md"=0A= =0A= +mdconfig2_prestart()=0A= +{=0A= + local _mp=0A= +=0A= + if [ -z "${_mdconfig2_list}" ]; then=0A= + return 1=0A= + fi=0A= +=0A= + for _md in ${_mdconfig2_list}; do=0A= + eval _zpool=3D\$mdconfig_${_md}_zfs_pool=0A= + if [ -n "${_zpool}" ]; then=0A= + required_modules=3D"$required_modules zfs"=0A= + break=0A= + fi=0A= + done=0A= +=0A= + return 0=0A= +}=0A= +=0A= is_readonly()=0A= {=0A= local _mp _ret=0A= @@ -62,6 +81,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 +117,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 +181,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_0570_01CE6545.6E1C99C0-- From owner-freebsd-rc@FreeBSD.ORG Mon Jun 10 09:26:19 2013 Return-Path: Delivered-To: rc@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 0C2E4958; Mon, 10 Jun 2013 09:26:19 +0000 (UTC) (envelope-from hrs@FreeBSD.org) Received: from mail.allbsd.org (gatekeeper.allbsd.org [IPv6:2001:2f0:104:e001::32]) by mx1.freebsd.org (Postfix) with ESMTP id 4020116CC; Mon, 10 Jun 2013 09:26:18 +0000 (UTC) Received: from alph.d.allbsd.org (p2175-ipbf701funabasi.chiba.ocn.ne.jp [122.25.209.175]) (authenticated bits=128) by mail.allbsd.org (8.14.5/8.14.5) with ESMTP id r5A9Q0kw021751 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 10 Jun 2013 18:26:10 +0900 (JST) (envelope-from hrs@FreeBSD.org) Received: from localhost (localhost [127.0.0.1]) (authenticated bits=0) by alph.d.allbsd.org (8.14.5/8.14.5) with ESMTP id r5A9PveY087034; Mon, 10 Jun 2013 18:25:59 +0900 (JST) (envelope-from hrs@FreeBSD.org) Date: Mon, 10 Jun 2013 18:25:18 +0900 (JST) Message-Id: <20130610.182518.138879193135244843.hrs@allbsd.org> To: killing@multiplay.co.uk Subject: Re: Feeback on patch to add ZFS support to mdconfig rc.d scripts From: Hiroki Sato In-Reply-To: <5E2843FF4724492FBF2A29E43B698385@multiplay.co.uk> References: <20130609.041903.541782050134731313.hrs@allbsd.org> <5E2843FF4724492FBF2A29E43B698385@multiplay.co.uk> X-PGPkey-fingerprint: BDB3 443F A5DD B3D0 A530 FFD7 4F2C D3D8 2793 CF2D X-Mailer: Mew version 6.5 on Emacs 24.3 / Mule 6.0 (HANACHIRUSATO) Mime-Version: 1.0 Content-Type: Multipart/Signed; protocol="application/pgp-signature"; micalg=pgp-sha1; boundary="--Security_Multipart0(Mon_Jun_10_18_25_18_2013_749)--" Content-Transfer-Encoding: 7bit X-Virus-Scanned: clamav-milter 0.97.4 at gatekeeper.allbsd.org X-Virus-Status: Clean X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (mail.allbsd.org [133.31.130.32]); Mon, 10 Jun 2013 18:26:11 +0900 (JST) X-Spam-Status: No, score=-93.8 required=13.0 tests=CONTENT_TYPE_PRESENT, FAKEDWORD_BACKQUOTE,ONLY1HOPDIRECT,QENCPTR1,RCVD_IN_PBL,SAMEHELOBY2HOP, USER_IN_WHITELIST autolearn=no version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on gatekeeper.allbsd.org Cc: rc@FreeBSD.org, 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: Mon, 10 Jun 2013 09:26:19 -0000 ----Security_Multipart0(Mon_Jun_10_18_25_18_2013_749)-- Content-Type: Multipart/Mixed; boundary="--Next_Part(Mon_Jun_10_18_25_18_2013_246)--" Content-Transfer-Encoding: 7bit ----Next_Part(Mon_Jun_10_18_25_18_2013_246)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit "Steven Hartland" wrote in <5E2843FF4724492FBF2A29E43B698385@multiplay.co.uk>: ki> ----- Original Message ----- ki> From: "Hiroki Sato" ki> > I think this should be separated into adding non-fs md support into ki> > rc.d/mdconfig and on-the-fly zpool creation/import into rc.d/zfs ki> > since the rc.d/mdconfig script does not (and should not) depend on ki> > zfs.ko module. ki> > ki> > rc.d/mdconfig is located before mountcritlocal, so probably ki> > rc.d/zfs_md or something is needed just after rc.d/mdconfig2. ki> ki> Thanks for that Hiroki. If I understand correctly that your only ki> concern is the zfs module dependency? If so then its easier to make ki> that a dynamic dependency using a prestart. Not only that. What I am concerned about is adding ZFS support into rc.d/mdconfig makes mount sequence in rc.d script more complicated. Currently, /etc/rc.d/mdconfig runs, /etc/fstab is parsed, and then "zfs mount -a" is done in rc.d/zfs. The rc.d scripts is not good at handling dependency, so mounting/unmounting ZFS datasets in multiple scripts make difficult to use these scripts separetely at run time while probably they work fine at boot time. If we support md-backed zpool, "rc.d/zfs stop" should also handle unmounting all of ZFS datasets and destroy the md devices, for example, because it is responsible for stopping the ZFS and its related functionality. This is difficult to realize by using only rc.d scripts, I created and attached a prototype to add ZFS support directly to mount_mfs(8). Does this satisfy your needs? Just adding /etc/fstab entry like the following, md-backed zpools are automatically created and mounted via rc.d/mountcritlocal. If it is too early, "late" flag can be used as other file systems. Unmounting them is handled only by rc.d/zfs in this case. The mount options in an fstab entry look a bit odd because most of letters are already used in mount_mfs(8), but they are flexible to support zpool's command-line arguments. ---- # /etc/fstab examples: # # create swap-backed md and zpool "poola" on it, and then mount it on /a. md /a mfs rw,-s1g,-zpoola,-kcompression:on,-kexec:off 0 0 # # create vnode-backed md and zpool "poolb" on it, and then mount it on /b. md /b mfs rw,-s1g,-zpoolb,-F/var/tmp/zero 0 0 # # import (-P flag) a zpool "zpoolc" on vnode-backed md "/var/tmp/zero". # Mountpoint is automatically determined (/c is ignored). md /c mfs rw,-s1g,-zpoolc,-F/var/tmp/zero,-P 0 0 # # import a zpool "zpoold" on vnode-backed md at rc.d/mountlate stage. # Mountpoint is automatically determined (/d is ignored). md /d mfs rw,-s1g,-zpoold,-F/var/tmp/zero,-P,late 0 0 ---- The following command line should work with the above example: # mount /a # sh /etc/rc.d/zfs stop -- Hiroki ----Next_Part(Mon_Jun_10_18_25_18_2013_246)-- Content-Type: Text/X-Patch; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="mdmfs_zfs_support.20130610-1.diff" Index: etc/rc.d/zfs =================================================================== --- etc/rc.d/zfs (revision 251176) +++ etc/rc.d/zfs (working copy) @@ -48,6 +48,26 @@ zfs_stop_main() { + # Export md-backed zpools and destroy the md devices if any + while read dev mt fstype opt; do + case $dev:$opt in + \#*) # skip comment line + ;; + md:*,-F/*,-z*|md:*,-z*,-F/*) + opt=${opt##*,-z} + poolname=${opt%%,*} + # Check if $poolname exists. + df -t zfs $poolname > /dev/null 2>&1 || continue + set -- `zpool list -Hv $poolname` + if zpool export $poolname && mdconfig -d -u $9; then + : + else + warn "Cannot unmount zpool $poolname." + fi + ;; + esac + done < /etc/fstab + zfs unshare -a zfs unmount -a } Index: sbin/mdmfs/mdmfs.8 =================================================================== --- sbin/mdmfs/mdmfs.8 (revision 251176) +++ sbin/mdmfs/mdmfs.8 (working copy) @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd September 4, 2011 +.Dd June 10, 2013 .Dt MDMFS 8 .Os .Sh NAME @@ -46,6 +46,7 @@ .Op Fl F Ar file .Op Fl f Ar frag-size .Op Fl i Ar bytes +.Op Fl k Ar zfs-filesystem-property:value .Op Fl m Ar percent-free .Op Fl n Ar rotational-positions .Op Fl O Ar optimization @@ -54,6 +55,8 @@ .Op Fl s Ar size .Op Fl v Ar version .Op Fl w Ar user : Ns Ar group +.Op Fl z Ar zfs-zpoolname +.Op Fl Z Ar zfs-property:value .Ar md-device .Ar mount-point .Sh DESCRIPTION @@ -263,6 +266,36 @@ .It Fl X Print what command will be run before running it, and other assorted debugging information. +.It Fl z Ar zfs-zpoolname +Specify to use ZFS and the pool name as +.Ar zfs-zpoolname . +When this is specified, +parameters for +.Xr newfs 8 +are ignored except for a +.Fl P +flag. +.It Fl Z Ar zfs-property:value +Specify zpool property. +This will be passed to +.Xr zpool 8 +utility as +.Fl o Ar zfs-property=value . +The default value is +.Fl Z Ar cechefile:none . +.It Fl k Ar zfs-filesystem-property:value +Specify zfs property. +This will be passed to +.Xr zpool 8 +utility as +.Fl O Ar zfs-filesystem-property=value . +The default values are +.Fl k Ar atime:off , +.Fl k Ar primarycache:none , +and +.Fl k Ar sync:disabled +for swap-backed disk, +and none for vnode-backed disk. .El .Pp The @@ -289,6 +322,13 @@ .Xr newfs 8 as .Fl o . +The values in +.Fl z , +.Fl Z , +and +.Fl k +options are passed to +.Xr zpool 8 . The .Fl o option is passed to Index: sbin/mdmfs/mdmfs.c =================================================================== --- sbin/mdmfs/mdmfs.c (revision 251176) +++ sbin/mdmfs/mdmfs.c (working copy) @@ -81,6 +81,8 @@ static void do_mount(const char *, const char *); static void do_mtptsetup(const char *, struct mtpt_info *); static void do_newfs(const char *); +static void do_zpool(const char *, const char *, const char *, + const enum md_types, int); static void extract_ugid(const char *, struct mtpt_info *); static int run(int *, const char *, ...) __printflike(2, 3); static void usage(void); @@ -90,11 +92,11 @@ { struct mtpt_info mi; /* Mountpoint info. */ char *mdconfig_arg, *newfs_arg, /* Args to helper programs. */ - *mount_arg; + *mount_arg, *zpool_arg; enum md_types mdtype; /* The type of our memory disk. */ bool have_mdtype; - bool detach, softdep, autounit, newfs; - char *mtpoint, *unitstr; + bool detach, softdep, autounit, newfs, zfs; + char *mtpoint, *unitstr, *poolname; char *p; int ch; void *set; @@ -106,6 +108,7 @@ softdep = true; autounit = false; newfs = true; + zfs = false; have_mdtype = false; mdtype = MD_SWAP; mdname = MD_NAME; @@ -118,6 +121,7 @@ */ mdconfig_arg = strdup(""); newfs_arg = strdup(""); + zpool_arg = strdup(""); mount_arg = strdup(""); /* If we were started as mount_mfs or mfs, imply -C. */ @@ -129,7 +133,7 @@ } while ((ch = getopt(argc, argv, - "a:b:Cc:Dd:E:e:F:f:hi:LlMm:NnO:o:Pp:Ss:tUv:w:X")) != -1) + "a:B:b:Cc:Dd:E:e:F:f:hi:k:LlMm:NnO:o:Pp:Ss:tUv:w:Xz:Z:")) != -1) switch (ch) { case 'a': argappend(&newfs_arg, "-a %s", optarg); @@ -171,6 +175,14 @@ case 'i': argappend(&newfs_arg, "-i %s", optarg); break; + case 'k': + if (zfs != true) + errx(1, "-z poolname required first"); + p = optarg; + while ((p = strchr(p, ':')) != NULL) + p[0] = (char)'='; + argappend(&zpool_arg, "-O %s", optarg); + break; case 'L': loudsubs = true; break; @@ -231,6 +243,18 @@ case 'X': debug = true; break; + case 'z': + poolname = strdup(optarg); + zfs = true; + break; + case 'Z': + if (zfs != true) + errx(1, "-z poolname required first"); + p = optarg; + while ((p = strchr(p, ':')) != NULL) + p[0] = (char)'='; + argappend(&zpool_arg, "-o %s", optarg); + break; default: usage(); } @@ -272,9 +296,13 @@ do_mdconfig_attach_au(mdconfig_arg, mdtype); else do_mdconfig_attach(mdconfig_arg, mdtype); - if (newfs) - do_newfs(newfs_arg); - do_mount(mount_arg, mtpoint); + if (zfs) + do_zpool(zpool_arg, poolname, mtpoint, mdtype, newfs); + else { + if (newfs) + do_newfs(newfs_arg); + do_mount(mount_arg, mtpoint); + } do_mtptsetup(mtpoint, &mi); return (0); @@ -514,6 +542,63 @@ } /* + * Put a zpool on the memory disk. When vnode is specified, try to import + * zpool. + */ +static void +do_zpool(const char *args, const char *poolname, const char *mtpoint, + const enum md_types mdtype, int newfs) +{ + const char *cmd; + const char *addargs; + char mtarg[PATH_MAX + 10]; + char mdarg[PATH_MAX + 10]; + int rv; + + switch (mdtype) { + case MD_SWAP: + case MD_MALLOC: + cmd = "create"; + /* A set of reasonable default parameters. */ + addargs = " -o cachefile=none " + "-O primarycache=none " + "-O sync=disabled "; + snprintf(mtarg, sizeof(mtarg), " -m %s" , mtpoint); + mtarg[sizeof(mtarg) - 1] = '\0'; + snprintf(mdarg, sizeof(mdarg), " /dev/%s%d" , mdname, unit); + mdarg[sizeof(mdarg) - 1] = '\0'; + break; + case MD_VNODE: + /* Ignore return code. */ + run(NULL, "%s export %s", _PATH_ZPOOL, poolname); + + if (newfs) { + cmd = "create"; + /* Override the existing pool. */ + addargs = " -f -o cachefile=none"; + snprintf(mtarg, sizeof(mtarg), " -m %s" , mtpoint); + mtarg[sizeof(mtarg) - 1] = '\0'; + snprintf(mdarg, sizeof(mdarg), " /dev/%s%d" , mdname, + unit); + mdarg[sizeof(mdarg) - 1] = '\0'; + } else { + cmd = "import"; + addargs = " -o cachefile=none"; + mtarg[0] = '\0'; + mdarg[0] = '\0'; + } + break; + default: + abort(); + } + + rv = run(NULL, "%s %s%s%s%s %s%s", + _PATH_ZPOOL, cmd, addargs, args, mtarg, poolname, mdarg); + if (rv) + errx(1, "zpool exited with error code %d", rv); +} + +/* * 'str' should be a user and group name similar to the last argument * to chown(1); i.e., a user, followed by a colon, followed by a * group. The user and group in 'str' may be either a [ug]id or a Index: include/paths.h =================================================================== --- include/paths.h (revision 251176) +++ include/paths.h (working copy) @@ -88,6 +88,7 @@ #define _PATH_UFSSUSPEND "/dev/ufssuspend" #define _PATH_VI "/usr/bin/vi" #define _PATH_WALL "/usr/bin/wall" +#define _PATH_ZPOOL "/sbin/zpool" /* Provide trailing slash, since mostly used for building pathnames. */ #define _PATH_DEV "/dev/" ----Next_Part(Mon_Jun_10_18_25_18_2013_246)---- ----Security_Multipart0(Mon_Jun_10_18_25_18_2013_749)-- Content-Type: application/pgp-signature Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.13 (FreeBSD) iEYEABECAAYFAlG1m34ACgkQTyzT2CeTzy0OKgCfRLFGzjAuf/MPKmBSBzZILRd1 GQQAn1vs/zlIGHU5zZLVqzB+HO3WaRBx =26qm -----END PGP SIGNATURE----- ----Security_Multipart0(Mon_Jun_10_18_25_18_2013_749)---- From owner-freebsd-rc@FreeBSD.ORG Mon Jun 10 11:06:54 2013 Return-Path: Delivered-To: freebsd-rc@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id EE67E6F for ; Mon, 10 Jun 2013 11:06:54 +0000 (UTC) (envelope-from owner-bugmaster@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) by mx1.freebsd.org (Postfix) with ESMTP id DF9B71C96 for ; Mon, 10 Jun 2013 11:06:54 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.7/8.14.7) with ESMTP id r5AB6sVK097084 for ; Mon, 10 Jun 2013 11:06:54 GMT (envelope-from owner-bugmaster@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.7/8.14.7/Submit) id r5AB6s7Y097082 for freebsd-rc@FreeBSD.org; Mon, 10 Jun 2013 11:06:54 GMT (envelope-from owner-bugmaster@FreeBSD.org) Date: Mon, 10 Jun 2013 11:06:54 GMT Message-Id: <201306101106.r5AB6s7Y097082@freefall.freebsd.org> X-Authentication-Warning: freefall.freebsd.org: gnats set sender to owner-bugmaster@FreeBSD.org using -f From: FreeBSD bugmaster To: freebsd-rc@FreeBSD.org Subject: Current problem reports assigned to freebsd-rc@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: Mon, 10 Jun 2013 11:06:55 -0000 Note: to view an individual PR, use: http://www.freebsd.org/cgi/query-pr.cgi?pr=(number). The following is a listing of current problems submitted by FreeBSD users. These represent problem reports covering all versions including experimental development code and obsolete releases. S Tracker Resp. Description -------------------------------------------------------------------------------- o conf/177217 rc [patch] rc.d/ddb -- squelch warning when ddb_enable=ye o conf/177089 rc ntpd startup script does not work well o conf/176347 rc [rc.conf] [patch] Add support for firewall deny lists o conf/176181 rc [rc.subr] rc.subr emitting warnings for non-defined xx o conf/175311 rc [patch] add "dump" fs type support to rc.d/dumpon o conf/175105 rc /etc/rc.d/* and more: syntax 'return_boolean_cmd && do o conf/175079 rc [rc.subr] [patch] rc.subr poorly handles recursive run o bin/173153 rc [rc.d] [patch] $netwait_ip should be more parallel o conf/172787 rc [rc.conf] FreeBSD 9.x broken alias syntax on vlan inte o conf/172532 rc [rc] [patch] service routing restart always fails o conf/169047 rc [rc.subr] [patch] /etc/rc.subr not checking some scrip o bin/168544 rc [patch] [rc]: addswap-mounted swapfiles cause panic on o conf/167566 rc [rc.d] [patch] ipdivert module loading vs. ipfw rc.d o o conf/166484 rc [rc] [patch] rc.initdiskless patch for different major o conf/165769 rc [rc][jai][ipv6] IPv6 Initialization on external iface o conf/164393 rc [rc.d] restarting netif with static addresses doesn't o conf/163508 rc [rc.subr] [patch] Add "enable" and "disable" commands o conf/163488 rc Confusing explanation in defaults/rc.conf o conf/163321 rc [rc.conf] [patch] allow _fib syntax in rc.conf o conf/162642 rc .sh scripts in /usr/local/etc/rc.d get executed, not s o conf/161107 rc [rc] stop_boot in mountcritlocal usage is incorrect. o conf/160403 rc [rc] [patch] concurrently running rc-scripts during bo o conf/160240 rc rc.d/mdconfig and mdconfig2 should autoset $_type to v o conf/159846 rc [rc.conf] routing_stop_inet6() logic doesn't handle ip o conf/158557 rc [patch] /etc/rc.d/pf broken messages o conf/158127 rc [patch] remount_optional option in rc.initdiskless doe o conf/153666 rc [rc.d][patch] mount filesystems from fstab over zfs da o conf/153200 rc post-boot /etc/rc.d/network_ipv6 start can miss neighb o conf/153123 rc [rc] [patch] add gsched rc file to automatically inser o conf/150474 rc [patch] rc.d/accounting: Add ability to set location o o conf/149867 rc [PATCH] rc.d script to manage multiple FIBS (kern opti o conf/149831 rc [PATCH] add support to /etc/rc.d/jail for delegating Z o conf/148656 rc rc.firewall(8): {oip} and {iip} variables in rc.firewa o conf/147685 rc [rc.d] [patch] new feature for /etc/rc.d/fsck o conf/147444 rc [rc.d] [patch] /etc/rc.d/zfs stop not called on reboot o conf/146053 rc [patch] [request] shutdown of jails breaks inter-jail o conf/145399 rc [patch] rc.d scripts are unable to start/stop programs o conf/145009 rc [patch] rc.subr(8): rc.conf should allow mac label con o conf/143637 rc [patch] ntpdate(8) support for ntp-servers supplied by o conf/143085 rc [patch] ftp-proxy(8) rc(8) with multiple instances a conf/142973 rc [jail] [patch] Strange counter init value in jail rc o conf/142434 rc [patch] Add cpuset(1) support to rc.subr(8) o conf/142304 rc rc.conf(5): mdconfig and mdconfig2 rc.d scripts lack e o conf/141909 rc rc.subr(8): [patch] add rc.conf.d support to /usr/loca o conf/141678 rc [patch] A minor enhancement to how /etc/rc.d/jail dete o conf/140440 rc [patch] allow local command files in rc.{suspend,resum o conf/140261 rc [patch] Improve flexibility of mdconfig2 startup scrip p conf/138208 rc [rc.d] [patch] Making rc.firewall (workstation) IPv6 a o conf/137271 rc [rc.d] Cannot update /etc/host.conf when root filesyst o conf/136624 rc [rc.d] sysctl variables for ipnat are not applied on b o conf/134918 rc [patch] rc.subr fails to detect perl daemons o conf/134660 rc [patch] rc-script for initializing ng_netflow+ng_ipfw o conf/134333 rc PPP configuration problem in the rc.d scripts in combi o conf/133890 rc [patch] sshd(8): add multiple profiles to the rc.d scr o conf/128299 rc [patch] /etc/rc.d/geli does not mount partitions using o conf/126392 rc [patch] rc.conf ifconfig_xx keywords cannot be escaped o conf/124747 rc [patch] savecore can't create dump from encrypted swap o conf/124248 rc [jail] [patch] add support for nice value for rc.d/jai o conf/123734 rc [patch] Chipset VIA CX700 requires extra initializatio o conf/123222 rc [patch] Add rtprio(1)/idprio(1) support to rc.subr(8). o conf/122968 rc [rc.d] /etc/rc.d/addswap: md swapfile multiplication a o conf/122477 rc [patch] /etc/rc.d/mdconfig and mdconfig2 are ignoring o conf/122170 rc [patch] [request] New feature: notify admin via page o o kern/121566 rc [nfs] [request] [patch] ethernet iface should be broug a conf/119874 rc [patch] "/etc/rc.d/pf reload" fails if there are macro o conf/119076 rc [patch] [rc.d] /etc/rc.d/netif tries to remove alias a o bin/118325 rc [patch] [request] new periodic script to test statuses f conf/118255 rc savecore never finding kernel core dumps (rcorder prob f conf/117935 rc [patch] ppp fails to start at boot because of missing f conf/113915 rc [ndis] [patch] ndis wireless driver fails to associate o conf/108589 rc rtsol(8) fails due to default ipfw rules o conf/106009 rc [ppp] [patch] [request] Fix pppoed startup script to p f conf/105689 rc [ppp] [request] syslogd starts too late at boot f conf/105145 rc [ppp] [patch] [request] add redial function to rc.d/pp f conf/104549 rc [patch] rc.d/nfsd needs special _find_processes functi o conf/102700 rc [geli] [patch] Add encrypted /tmp support to GELI/GBDE o conf/93815 rc [patch] Adds in the ability to save ipfw rules to rc.d f conf/92523 rc [patch] allow rc scripts to kill process after a timeo o conf/89870 rc [patch] [request] make netif verbose rc.conf toggle a conf/88913 rc [patch] wrapper support for rc.subr o conf/85819 rc [patch] script allowing multiuser mode in spite of fsc o kern/81006 rc ipnat not working with tunnel interfaces on startup o conf/77663 rc Suggestion: add /etc/rc.d/addnetswap after addcritremo o conf/73677 rc [patch] add support for powernow states to power_profi a conf/58939 rc [patch] dumb little hack for /etc/rc.firewall{,6} f conf/56934 rc [patch] rc.firewall rules for natd expect an interface f conf/13775 rc multi-user boot may hang in NIS environment 87 problems total. From owner-freebsd-rc@FreeBSD.ORG Wed Jun 12 16:45:12 2013 Return-Path: Delivered-To: freebsd-rc@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 6C1E7497; Wed, 12 Jun 2013 16:45:12 +0000 (UTC) (envelope-from crees@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) by mx1.freebsd.org (Postfix) with ESMTP id 444CF1D03; Wed, 12 Jun 2013 16:45:12 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.7/8.14.7) with ESMTP id r5CGjCr5052905; Wed, 12 Jun 2013 16:45:12 GMT (envelope-from crees@freefall.freebsd.org) Received: (from crees@localhost) by freefall.freebsd.org (8.14.7/8.14.7/Submit) id r5CGjCt2052904; Wed, 12 Jun 2013 16:45:12 GMT (envelope-from crees) Date: Wed, 12 Jun 2013 16:45:12 GMT Message-Id: <201306121645.r5CGjCt2052904@freefall.freebsd.org> To: wblock@FreeBSD.org, crees@FreeBSD.org, freebsd-rc@FreeBSD.org From: crees@FreeBSD.org Subject: Re: bin/168544: [patch] [rc]: addswap-mounted swapfiles cause panic on shutdown 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: Wed, 12 Jun 2013 16:45:12 -0000 Synopsis: [patch] [rc]: addswap-mounted swapfiles cause panic on shutdown State-Changed-From-To: open->patched State-Changed-By: crees State-Changed-When: Wed Jun 12 16:44:55 UTC 2013 State-Changed-Why: Fixed in head http://www.freebsd.org/cgi/query-pr.cgi?pr=168544 From owner-freebsd-rc@FreeBSD.ORG Wed Jun 12 16:50:01 2013 Return-Path: Delivered-To: freebsd-rc@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id AAD0D611 for ; Wed, 12 Jun 2013 16:50:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) by mx1.freebsd.org (Postfix) with ESMTP id 8C2641DC2 for ; Wed, 12 Jun 2013 16:50:01 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.7/8.14.7) with ESMTP id r5CGo146053065 for ; Wed, 12 Jun 2013 16:50:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.7/8.14.7/Submit) id r5CGo1aV053048; Wed, 12 Jun 2013 16:50:01 GMT (envelope-from gnats) Date: Wed, 12 Jun 2013 16:50:01 GMT Message-Id: <201306121650.r5CGo1aV053048@freefall.freebsd.org> To: freebsd-rc@FreeBSD.org Cc: From: dfilter@FreeBSD.ORG (dfilter service) Subject: Re: bin/168544: commit references a PR X-BeenThere: freebsd-rc@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: dfilter service 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: Wed, 12 Jun 2013 16:50:01 -0000 The following reply was made to PR bin/168544; it has been noted by GNATS. From: dfilter@FreeBSD.ORG (dfilter service) To: bug-followup@FreeBSD.org Cc: Subject: Re: bin/168544: commit references a PR Date: Wed, 12 Jun 2013 16:44:26 +0000 (UTC) Author: crees (doc,ports committer) Date: Wed Jun 12 16:44:17 2013 New Revision: 251660 URL: http://svnweb.freebsd.org/changeset/base/251660 Log: Clean up swapfile memory disk on shutdown Make the md unit number configurable so that it can be predicted PR: bin/168544 Submitted by: wblock (based on) Approved by: kevlo Modified: head/etc/defaults/rc.conf head/etc/rc.d/addswap Modified: head/etc/defaults/rc.conf ============================================================================== --- head/etc/defaults/rc.conf Wed Jun 12 16:13:05 2013 (r251659) +++ head/etc/defaults/rc.conf Wed Jun 12 16:44:17 2013 (r251660) @@ -33,6 +33,7 @@ always_force_depends="NO" # Set to check # running during boot (can increase boot time). swapfile="NO" # Set to name of swapfile if aux swapfile desired. +swapfile_mdunit="99" # Swapfile md(4) unit number created by mdconfig(8). apm_enable="NO" # Set to YES to enable APM BIOS functions (or NO). apmd_enable="NO" # Run apmd to handle APM event from userland. apmd_flags="" # Flags to apmd (if enabled). Modified: head/etc/rc.d/addswap ============================================================================== --- head/etc/rc.d/addswap Wed Jun 12 16:13:05 2013 (r251659) +++ head/etc/rc.d/addswap Wed Jun 12 16:44:17 2013 (r251660) @@ -8,13 +8,13 @@ # PROVIDE: addswap # REQUIRE: FILESYSTEMS kld # BEFORE: netif -# KEYWORD: nojail +# KEYWORD: nojail shutdown . /etc/rc.subr name="addswap" start_cmd="addswap_start" -stop_cmd=":" +stop_cmd="addswap_stop" addswap_start() { @@ -23,8 +23,43 @@ addswap_start() ;; *) if [ -w "${swapfile}" ]; then - echo "Adding ${swapfile} as additional swap" - mdev=`mdconfig -a -t vnode -f ${swapfile}` && swapon /dev/${mdev} + check_startmsgs && echo "Adding ${swapfile} as additional swap" + + if [ -n "${swapfile_mdunit}" ]; then + mdev="/dev/md${swapfile_mdunit#md}" + mdconfig -a -t vnode -f "${swapfile}" -u ${swapfile_mdunit} + else + mdev="/dev/`mdconfig -a -t vnode -f "${swapfile}"`" + fi + + if [ $? -eq 0 ]; then + swapon ${mdev} + else + echo "error creating swapfile device" + fi + fi + ;; + esac +} + +addswap_stop() +{ + case ${swapfile} in + [Nn][Oo] | '') + ;; + *) + if [ -n "${swapfile_mdunit}" ]; then + mdev="/dev/md${swapfile_mdunit#md}" + else + mdev="/dev/`mdconfig -lv | grep "${swapfile}" | cut -f1`" + swapfile_mdunit=${mdev#md} + fi + if [ -n "${swapfile_mdunit}" ]; then + swapctl -l | grep -q ${mdev} + if [ $? -eq 0 ]; then + echo "Dismounting swapfile ${swapfile}" + swapoff ${mdev} && mdconfig -d -u ${swapfile_mdunit} + fi fi ;; esac _______________________________________________ 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" From owner-freebsd-rc@FreeBSD.ORG Sat Jun 15 16:01:30 2013 Return-Path: Delivered-To: freebsd-rc@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 2B10DAB8 for ; Sat, 15 Jun 2013 16:01:30 +0000 (UTC) (envelope-from hrs@FreeBSD.org) Received: from mail.allbsd.org (gatekeeper.allbsd.org [IPv6:2001:2f0:104:e001::32]) by mx1.freebsd.org (Postfix) with ESMTP id 3CD1C1C6D for ; Sat, 15 Jun 2013 16:01:24 +0000 (UTC) Received: from alph.d.allbsd.org (p3086-ipbf906funabasi.chiba.ocn.ne.jp [122.26.46.86]) (authenticated bits=128) by mail.allbsd.org (8.14.5/8.14.5) with ESMTP id r5FG16tO089535 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 16 Jun 2013 01:01:16 +0900 (JST) (envelope-from hrs@FreeBSD.org) Received: from localhost (localhost [127.0.0.1]) (authenticated bits=0) by alph.d.allbsd.org (8.14.5/8.14.5) with ESMTP id r5FG14sa083605; Sun, 16 Jun 2013 01:01:06 +0900 (JST) (envelope-from hrs@FreeBSD.org) Date: Sun, 16 Jun 2013 00:59:41 +0900 (JST) Message-Id: <20130616.005941.1489449431438337467.hrs@allbsd.org> To: freebsd-rc@FreeBSD.org Subject: range spec support in ifconfig_IF_aliasN From: Hiroki Sato X-PGPkey-fingerprint: BDB3 443F A5DD B3D0 A530 FFD7 4F2C D3D8 2793 CF2D X-Mailer: Mew version 6.5 on Emacs 24.3 / Mule 6.0 (HANACHIRUSATO) Mime-Version: 1.0 Content-Type: Multipart/Signed; protocol="application/pgp-signature"; micalg=pgp-sha1; boundary="--Security_Multipart0(Sun_Jun_16_00_59_41_2013_553)--" Content-Transfer-Encoding: 7bit X-Virus-Scanned: clamav-milter 0.97.4 at gatekeeper.allbsd.org X-Virus-Status: Clean X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (mail.allbsd.org [133.31.130.32]); Sun, 16 Jun 2013 01:01:17 +0900 (JST) X-Spam-Status: No, score=-88.0 required=13.0 tests=CONTENT_TYPE_PRESENT, DIRECTOCNDYN,DYN_PBL,FAKEDWORD_BACKQUOTE,FAKEDWORD_ZERO,ONLY1HOPDIRECT, QENCPTR1,QENCPTR2,RCVD_IN_PBL,SAMEHELOBY2HOP,USER_IN_WHITELIST,WEIRD_QUOTING autolearn=no version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on gatekeeper.allbsd.org Cc: kpaasial@gmail.com 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, 15 Jun 2013 16:01:30 -0000 ----Security_Multipart0(Sun_Jun_16_00_59_41_2013_553)-- Content-Type: Multipart/Mixed; boundary="--Next_Part(Sun_Jun_16_00_59_41_2013_325)--" Content-Transfer-Encoding: 7bit ----Next_Part(Sun_Jun_16_00_59_41_2013_325)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hi all, Can anyone test the attached patch? It implements range specification for IPv6 address block like 2001:db8:1::1-5 in rc.conf $ifconfig* variable. This arises as a feature request repeatedly (conf/174225, for example). Adding ipv6_addrs_IF similar to ipv4_addrs_IF is possible, but I think adding range spec support in ifconfig_IF_alisesN is easier for users to understand and we should not add new variables which are specific to an address family. After applying the patch, all of the following will work: ifconfig_em0="inet 192.168.0.1" # IPv4 configuration ifconfig_em0_ipv6="inet6 2001:db8::1/64" # IPv6 configuration ipv4_addr_em0="10.2.1.1-10" # IPv4 address range spec. Now deprecated. ifconfig_em0_alias0="inet6 2001:db8:5::1 prefixlen 70" # IPv6 alias. ifconfig_em0_alias1="inet 10.2.2.1/24" # IPv4 alias with range spec (backward compat). ifconfig_em0_alias2="10.3.1.1-10/32" # IPv4 alias with range spec. ifconfig_em0_alias3="inet6 2001:db8:20-2f::1/64" # IPv6 alias with range spec. # ifconfig_IF_aliases is just like ifconfig_IF_aliasN. # It can have all of entries in one line. ifconfig_em0_aliases="inet 10.3.3.201-204/24 inet6 2001:db8:210-213::1/64 inet 10.1.1.1/24" ipv6_ifconfig_em0_alias0="inet6 2001:db8:f::1/64" # IPv6 alias (backward compat) ipv6_ifconfig_em0_alias1="2001:db8:f:1::1/64" # IPv6 alias (backward compat) This example should include all possible combinations of the existing variables to configure IP aliases. There should be no functional degradation. The differences are: 1. ifconfig_IF_aliasN supports address range specification. 2. ifconfig_IF_aliases has been added. I think ipv4_addr_IF should be deprecated in favor of ifconfig_IF_aliaseN. The implementation includes re-factoring the alias handing in a address family independent manner and IPv6 DAD treatment due to multiple address configurations in a short period. Also, range specification in IPv6 can generate a lot of addresses, so the number of expanded address is limited to 31 (set as _IPEXPANDMAX at the top of network.subr) per entry. -- Hiroki ----Next_Part(Sun_Jun_16_00_59_41_2013_325)-- Content-Type: Text/X-Patch; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="if_aliases_20130616-1.diff" Index: etc/network.subr =================================================================== --- etc/network.subr (revision 251659) +++ etc/network.subr (working copy) @@ -24,7 +24,11 @@ # # $FreeBSD$ # +IFCONFIG_CMD="/sbin/ifconfig" +# Maximum number of addresses expanded from a address range specification. +_IPEXPANDMAX=31 + # # Subroutines commonly used from network startup scripts. # Requires that rc.conf be loaded first. @@ -94,7 +98,7 @@ # ifconfig_IF ifconfig_args=`ifconfig_getargs $1` if [ -n "${ifconfig_args}" ]; then - eval ifconfig $1 ${ifconfig_args} + eval ${IFCONFIG_CMD} $1 ${ifconfig_args} _cfg=0 fi @@ -122,7 +126,7 @@ esac if [ -n "${_ipv6_opts}" ]; then - ifconfig $1 inet6 ${_ipv6_opts} + ${IFCONFIG_CMD} $1 inet6 ${_ipv6_opts} fi # ifconfig_IF_ipv6 @@ -136,8 +140,8 @@ ifconfig_args="inet6 ${ifconfig_args}" ;; esac - ifconfig $1 inet6 -ifdisabled - eval ifconfig $1 ${ifconfig_args} + ${IFCONFIG_CMD} $1 inet6 -ifdisabled + eval ${IFCONFIG_CMD} $1 ${ifconfig_args} _cfg=0 fi @@ -145,7 +149,7 @@ # ipv6_prefix_hostid_addr_common(). ifconfig_args=`get_if_var $1 ipv6_prefix_IF` if [ -n "${ifconfig_args}" ]; then - ifconfig $1 inet6 -ifdisabled + ${IFCONFIG_CMD} $1 inet6 -ifdisabled _cfg=0 fi @@ -154,14 +158,14 @@ if [ -n "${ifconfig_args}" ]; then warn "\$ipv6_ifconfig_$1 is obsolete." \ " Use ifconfig_$1_ipv6 instead." - ifconfig $1 inet6 -ifdisabled - eval ifconfig $1 inet6 ${ifconfig_args} + ${IFCONFIG_CMD} $1 inet6 -ifdisabled + eval ${IFCONFIG_CMD} $1 inet6 ${ifconfig_args} _cfg=0 fi fi if [ ${_cfg} -eq 0 ]; then - ifconfig $1 up + ${IFCONFIG_CMD} $1 up fi if wpaif $1; then @@ -171,7 +175,7 @@ if dhcpif $1; then if [ $_cfg -ne 0 ] ; then - ifconfig $1 up + ${IFCONFIG_CMD} $1 up fi if syncdhcpif $1; then /etc/rc.d/dhclient start $1 @@ -202,7 +206,7 @@ fi if ifexists $1; then - ifconfig $1 down + ${IFCONFIG_CMD} $1 down _cfg=0 fi @@ -539,7 +543,7 @@ ifexists() { [ -z "$1" ] && return 1 - ifconfig -n $1 > /dev/null 2>&1 + ${IFCONFIG_CMD} -n $1 > /dev/null 2>&1 } # ipv4_up if @@ -554,11 +558,10 @@ if [ "${_if}" = "lo0" ]; then ifconfig_args=`get_if_var ${_if} ifconfig_IF` if [ -z "${ifconfig_args}" ]; then - ifconfig ${_if} inet 127.0.0.1/8 alias + ${IFCONFIG_CMD} ${_if} inet 127.0.0.1/8 alias fi fi - ifalias_up ${_if} inet && _ret=0 - ipv4_addrs_common ${_if} alias && _ret=0 + ifalias ${_if} inet alias && _ret=0 return $_ret } @@ -575,7 +578,7 @@ return 0 fi - ifalias_up ${_if} inet6 && _ret=0 + ifalias ${_if} inet6 alias && _ret=0 ipv6_prefix_hostid_addr_common ${_if} alias && _ret=0 ipv6_accept_rtadv_up ${_if} && _ret=0 @@ -591,8 +594,10 @@ _ifs="^" _ret=1 - inetList="`ifconfig ${_if} | grep 'inet ' | tr "\n" "$_ifs"`" + ifalias ${_if} inet -alias && _ret=0 + inetList="`${IFCONFIG_CMD} ${_if} | grep 'inet ' | tr "\n" "$_ifs"`" + oldifs="$IFS" IFS="$_ifs" for _inet in $inetList ; do @@ -602,15 +607,12 @@ _inet=`expr "$_inet" : '.*\(inet \([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}\).*'` IFS="$oldifs" - ifconfig ${_if} ${_inet} delete + ${IFCONFIG_CMD} ${_if} ${_inet} delete IFS="$_ifs" _ret=0 done IFS="$oldifs" - ifalias_down ${_if} inet && _ret=0 - ipv4_addrs_common ${_if} -alias && _ret=0 - return $_ret } @@ -629,9 +631,9 @@ ipv6_accept_rtadv_down ${_if} && _ret=0 ipv6_prefix_hostid_addr_common ${_if} -alias && _ret=0 - ifalias_down ${_if} inet6 && _ret=0 + ifalias ${_if} inet6 -alias && _ret=0 - inetList="`ifconfig ${_if} | grep 'inet6 ' | tr "\n" "$_ifs"`" + inetList="`${IFCONFIG_CMD} ${_if} | grep 'inet6 ' | tr "\n" "$_ifs"`" oldifs="$IFS" IFS="$_ifs" @@ -642,7 +644,7 @@ _inet6=`expr "$_inet6" : '.*\(inet6 \([0-9a-f:]*\)\).*'` IFS="$oldifs" - ifconfig ${_if} ${_inet6} -alias + ${IFCONFIG_CMD} ${_if} ${_inet6} -alias IFS="$_ifs" _ret=0 done @@ -651,234 +653,349 @@ return $_ret } -# ipv4_addrs_common if action -# Evaluate the ifconfig_if_ipv4 arguments for interface $if and -# use $action to add or remove IPv4 addresses from $if. -ipv4_addrs_common() -{ - local _ret _if _action _cidr _cidr_addr - local _ipaddr _netmask _range _ipnet _iplow _iphigh _ipcount - _ret=1 - _if=$1 - _action=$2 - - # get ipv4-addresses - cidr_addr=`get_if_var $_if ipv4_addrs_IF` - - for _cidr in ${cidr_addr}; do - _ipaddr=${_cidr%%/*} - _netmask="/"${_cidr##*/} - _range=${_ipaddr##*.} - _ipnet=${_ipaddr%.*} - _iplow=${_range%-*} - _iphigh=${_range#*-} - - # clear netmask when removing aliases - if [ "${_action}" = "-alias" ]; then - _netmask="" - fi - - _ipcount=${_iplow} - while [ "${_ipcount}" -le "${_iphigh}" ]; do - eval "ifconfig ${_if} ${_action} ${_ipnet}.${_ipcount}${_netmask}" - _ipcount=$((${_ipcount}+1)) - _ret=0 - - # only the first ipaddr in a subnet need the real netmask - if [ "${_action}" != "-alias" ]; then - _netmask="/32" - fi - done - done - - return $_ret -} - -# ifalias_up if af -# Configure aliases for network interface $if. +# ifalias if af action +# Configure or remove aliases for network interface $if. # It returns 0 if at least one alias was configured or -# 1 if there were none. +# removed, or 1 if there were none. # -ifalias_up() +ifalias() { local _ret _ret=1 + afexists $2 || return $_ret + case "$2" in - inet) - _ret=`ifalias_ipv4_up "$1"` + inet|inet6) + ifalias_af_common $1 $2 $3 && _ret=0 ;; - inet6) - _ret=`ifalias_ipv6_up "$1"` - ;; esac return $_ret } -# ifalias_ipv4_up if -# Helper function for ifalias_up(). Handles IPv4. +# ifalias_expand_addr af action addr +# Expand address range ("N-M") specification in addr. +# "addr" must not include an address-family keyword. +# The results will include an address-family keyword. # -ifalias_ipv4_up() +ifalias_expand_addr() { - local _ret alias ifconfig_args - _ret=1 - # ifconfig_IF_aliasN which starts with "inet" - alias=0 - while : ; do - ifconfig_args=`get_if_var $1 ifconfig_IF_alias${alias}` - case "${ifconfig_args}" in - inet\ *) - ifconfig $1 ${ifconfig_args} alias && _ret=0 - ;; - inet6\ *) - ;; - "") - break - ;; - *) - warn "\$ifconfig_$1_alias${alias} needs " \ - "\"inet\" keyword for an IPv4 address." - ifconfig $1 ${ifconfig_args} alias && _ret=0 - ;; - esac - alias=$((${alias} + 1)) - done - - return $_ret + afexists $1 || return + ifalias_expand_addr_$1 $2 $3 } -# ifalias_ipv6_up if -# Helper function for ifalias_up(). Handles IPv6. +# ifalias_expand_addr_inet action addr +# Helper function for ifalias_expand_addr(). Handles IPv4. # -ifalias_ipv6_up() +ifalias_expand_addr_inet() { - local _ret alias ifconfig_args - _ret=1 + local _action _arg _cidr _cidr_addr + local _ipaddr _plen _range _iphead _iptail _iplow _iphigh _ipcount + local _retstr _c + _action=$1 + _arg=$2 + _retstr= - # ifconfig_IF_aliasN which starts with "inet6" - alias=0 - while : ; do - ifconfig_args=`get_if_var $1 ifconfig_IF_alias${alias}` - case "${ifconfig_args}" in - inet6\ *) - ifconfig $1 ${ifconfig_args} alias && _ret=0 - ;; - "") - break - ;; + case $_action:$_arg in + *:*--*) return ;; # invalid + tmp:*) echo $_arg && return ;; # already expanded + tmp:*-*) _action="alias" ;; # to be expanded + *:*-*) ;; # to be expanded + *:*) echo inet $_arg && return ;; # already expanded + esac + + for _cidr in $_arg; do + _ipaddr=${_cidr%%/*} + _plen=${_cidr##*/} + # When subnet prefix length is not specified, use /32. + case $_plen in + $_ipaddr) _plen=32 ;; # "/" character not found esac - alias=$((${alias} + 1)) - done - # backward compatibility: ipv6_ifconfig_IF_aliasN. - alias=0 - while : ; do - ifconfig_args=`get_if_var $1 ipv6_ifconfig_IF_alias${alias}` - case "${ifconfig_args}" in - "") - break + OIFS=$IFS + IFS=. set -- $_ipaddr + _range= + _iphead= + _iptail= + for _c in $@; do + case $_range:$_c in + :[0-9]*-[0-9]*) + _range=$_c ;; - *) - ifconfig $1 inet6 ${ifconfig_args} alias && _ret=0 - warn "\$ipv6_ifconfig_$1_alias${alias} is obsolete." \ - " Use ifconfig_$1_aliasN instead." + :*) + _iphead="${_iphead}${_iphead:+.}${_c}" ;; - esac - alias=$((${alias} + 1)) + *:*) + _iptail="${_iptail}${_iptail:+.}${_c}" + ;; + esac + done + IFS=$OIFS + _iplow=${_range%-*} + _iphigh=${_range#*-} + + # clear netmask when removing aliases + if [ "$_action" = "-alias" ]; then + _plen="" + fi + + _ipcount=$_iplow + while [ "$_ipcount" -le "$_iphigh" ]; do + _retstr="${_retstr} ${_iphead}${_iphead:+.}${_ipcount}${_iptail:+.}${_iptail}${_plen:+/}${_plen}" + if [ $_ipcount -gt $(($_iplow + $_IPEXPANDMAX)) ]; then + warn "Range specification is too large (${_iphead}${_iphead:+.}${_iplow}${_iptail:+.}${_iptail}-${_iphead}${_iphead:+.}${_iphigh}${_iptail:+.}${_iptail}). ${_iphead}${_iphead:+.}${_iplow}${_iptail:+.}${_iptail}-${_iphead}${_iphead:+.}${_ipcount}${_iptail:+.}${_iptail} was processed." + break + else + _ipcount=$(($_ipcount + 1)) + fi + # Forcibly set /32 for remaining aliases. + _plen=32 + done done - return $_ret + for _c in $_retstr; do + ifalias_expand_addr_inet $_action $_c + done } -# ifalias_down if af -# Remove aliases for network interface $if. -# It returns 0 if at least one alias was removed or -# 1 if there were none. +# ifalias_expand_addr_inet6 action addr +# Helper function for ifalias_expand_addr(). Handles IPv6. # -ifalias_down() +ifalias_expand_addr_inet6() { - local _ret - _ret=1 + local _action _arg _cidr _cidr_addr + local _ipaddr _plen _ipleft _ipright _iplow _iphigh _ipcount + local _ipv4part + local _retstr _c + _action=$1 + _arg=$2 + _retstr= - case "$2" in - inet) - _ret=`ifalias_ipv4_down "$1"` - ;; - inet6) - _ret=`ifalias_ipv6_down "$1"` - ;; + case $_action:$_arg in + *:*--*) return ;; # invalid + tmp:*) echo $_arg && return ;; + tmp:*-*) _action="alias" ;; + *:*-*) ;; + *:*) echo inet6 $_arg && return ;; esac - return $_ret + for _cidr in $_arg; do + _ipaddr="${_cidr%%/*}" + _plen="${_cidr##*/}" + + case $_action:$_ipaddr:$_cidr in + -alias:*:*) unset _plen ;; + *:$_cidr:$_ipaddr) unset _plen ;; + esac + + if [ "${_ipaddr%:*.*.*.*}" = "$_ipaddr" ]; then + # Handle !v4mapped && !v4compat addresses. + + # The default prefix length is 64. + case $_ipaddr:$_cidr in + $_cidr:$_ipaddr) _plen="64" ;; + esac + _ipleft=${_ipaddr%-*} + _ipright=${_ipaddr#*-} + _iplow=${_ipleft##*:} + _iphigh=${_ipright%%:*} + _ipleft=${_ipleft%:*} + _ipright=${_ipright#*:} + + if [ "$_iphigh" = "$_ipright" ]; then + unset _ipright + else + _ipright=:$_ipright + fi + + if [ -n "$_iplow" -a -n "$_iphigh" ]; then + _iplow=$((0x$_iplow)) + _iphigh=$((0x$_iphigh)) + _ipcount=$_iplow + while [ $_ipcount -le $_iphigh ]; do + _r=`printf "%s:%04x%s%s" \ + $_ipleft $_ipcount $_ipright \ + ${_plen:+/}$_plen` + _retstr="$_retstr $_r" + if [ $_ipcount -gt $(($_iplow + $_IPEXPANDMAX)) ] + then + warn "Range specification is too large $(printf '(%s:%04x%s-%s:%04x%s)' $_ipleft $_iplow $_ipright $_ipleft $_iphigh $_ipright). $(printf '%s:%04x%s-%s:%04x%s' $_ipleft $_iplow $_ipright $_ipleft $_ipcount $_ipright) was processed." + break + else + _ipcount=$(($_ipcount + 1)) + fi + done + else + _retstr="${_ipaddr}${_plen:+/}${_plen}" + fi + + for _c in $_retstr; do + ifalias_expand_addr_inet6 $_action $_c + done + else + # v4mapped/v4compat should handle as an IPv4 alias + _ipv4part=${_ipaddr##*:} + + # Adjust prefix length if any. If not, set the + # default prefix length as 32. + case $_ipaddr:$_cidr in + $_cidr:$_ipaddr) _plen=32 ;; + *) _plen=$(($_plen - 96)) ;; + esac + + _retstr=`ifalias_expand_addr_inet \ + tmp ${_ipv4part}${_plen:+/}${_plen}` + for _c in $_retstr; do + ifalias_expand_addr_inet $_action $_c + done + fi + done } -# ifalias_ipv4_down if -# Helper function for ifalias_down(). Handles IPv4. +# ifalias_af_common_handler if af action args +# Helper function for ifalias_af_common(). # -ifalias_ipv4_down() +ifalias_af_common_handler() { - local _ret alias ifconfig_args + local _ret _if _af _action _args _c _tmpargs + _ret=1 + _if=$1 + _af=$2 + _action=$3 + shift 3 + _args=$* - # ifconfig_IF_aliasN which starts with "inet" - alias=0 - while : ; do - ifconfig_args=`get_if_var $1 ifconfig_IF_alias${alias}` - case "${ifconfig_args}" in - inet\ *) - ifconfig $1 ${ifconfig_args} -alias && _ret=0 + case $_args in + ${_af}\ *) ;; + *) return ;; + esac + + _tmpargs= + for _c in $_args; do + case $_c in + ${_af}) + case $_tmpargs in + ${_af}\ *-*) + ifalias_af_common_handler $_if $_af $_action \ + `ifalias_expand_addr $_af $_action ${_tmpargs#${_af}\ }` ;; - "") - break + ${_af}\ *) + ${IFCONFIG_CMD} $_if $_tmpargs $_action && _ret=0 ;; + esac + _tmpargs=$_af + ;; + *) + _tmpargs="$_tmpargs $_c" + ;; esac - alias=$((${alias} + 1)) done + # Process the last component if any. + if [ -n "$_tmpargs}" ]; then + case $_tmpargs in + ${_af}\ *-*) + ifalias_af_common_handler $_if $_af $_action \ + `ifalias_expand_addr $_af $_action ${_tmpargs#${_af}\ }` + ;; + ${_af}\ *) + ${IFCONFIG_CMD} $_if $_tmpargs $_action && _ret=0 + ;; + esac + fi return $_ret } -# ifalias_ipv6_down if -# Helper function for ifalias_down(). Handles IPv6. +# ifalias_af_common if af action +# Helper function for ifalias(). # -ifalias_ipv6_down() +ifalias_af_common() { - local _ret alias ifconfig_args + local _ret _if _af _action alias ifconfig_args _aliasn _c _tmpargs _iaf + _ret=1 + _aliasn= + _if=$1 + _af=$2 + _action=$3 - # ifconfig_IF_aliasN which starts with "inet6" + # ifconfig_IF_aliasN which starts with $_af alias=0 while : ; do - ifconfig_args=`get_if_var $1 ifconfig_IF_alias${alias}` - case "${ifconfig_args}" in - inet6\ *) - ifconfig $1 ${ifconfig_args} -alias && _ret=0 + ifconfig_args=`get_if_var $_if ifconfig_IF_alias${alias}` + _iaf= + case $ifconfig_args in + inet\ *) _iaf=inet ;; + inet6\ *) _iaf=inet6 ;; + ipx\ *) _iaf=ipx ;; + esac + + case ${_af}:${_action}:${_iaf}:"${ifconfig_args}" in + ${_af}:*:${_af}:*) + _aliasn="$_aliasn $ifconfig_args" ;; - "") + ${_af}:*:"":"") break ;; + inet:alias:"":*) + _aliasn="$_aliasn inet $ifconfig_args" + warn "\$ifconfig_${_if}_alias${alias} needs " \ + "\"inet\" keyword for an IPv4 address." esac - alias=$((${alias} + 1)) + alias=$(($alias + 1)) done # backward compatibility: ipv6_ifconfig_IF_aliasN. - alias=0 - while : ; do - ifconfig_args=`get_if_var $1 ipv6_ifconfig_IF_alias${alias}` - case "${ifconfig_args}" in - "") - break + case $_af in + inet6) + alias=0 + while : ; do + ifconfig_args=`get_if_var $_if ipv6_ifconfig_IF_alias${alias}` + case ${_action}:"${ifconfig_args}" in + *:"") + break ;; + alias:*) + _aliasn="${_aliasn} inet6 ${ifconfig_args}" + warn "\$ipv6_ifconfig_${_if}_alias${alias} " \ + "is obsolete. Use ifconfig_$1_aliasN " \ + "instead." + ;; + esac + alias=$(($alias + 1)) + done + esac + + # backward compatibility: ipv4_addrs_IF. + for _tmpargs in `get_if_var $_if ipv4_addrs_IF`; do + _aliasn="$_aliasn inet $_tmpargs" + done + + # Handle ifconfig_IF_aliases, ifconfig_IF_aliasN, and the others. + _tmpargs= + for _c in `get_if_var $_if ifconfig_IF_aliases` $_aliasn; do + case $_c in + inet|inet6|ipx) + case $_tmpargs in + ${_af}\ *) + eval ifalias_af_common_handler $_if $_af $_action $_tmpargs && _ret=0 + ;; + esac + _tmpargs=$_c + ;; *) - ifconfig $1 inet6 ${ifconfig_args} -alias && _ret=0 - warn "\$ipv6_ifconfig_$1_alias${alias} is obsolete." \ - " Use ifconfig_$1_aliasN instead." - ;; + _tmpargs="$_tmpargs $_c" esac - alias=$((${alias} + 1)) done + # Process the last component + case $_tmpargs in + ${_af}\ *) + ifalias_af_common_handler $_if $_af $_action $_tmpargs && _ret=0 + ;; + esac return $_ret } @@ -899,14 +1016,32 @@ hostid=${hostid%\%*} for j in ${prefix}; do - address=$j\:${hostid} - ifconfig ${_if} inet6 ${address} prefixlen 64 ${_action} + # The default prefixlen is 64. + plen=${j#*/} + case $j:$plen in + $plen:$j) plen=64 ;; + *) j=${j%/*} ;; + esac + # Normalize the last part by removing ":" + j=${j%:*} + j=${j%:} + OIFS=$IFS; IFS=":"; set -- $j; nj=$#; IFS=$OIFS + OIFS=$IFS; IFS=":"; set -- $hostid; nh=$#; IFS=$OIFS + if [ $(($nj + $nh)) -eq 8 ]; then + address=$j\:$hostid + else + address=$j\::$hostid + fi + + ${IFCONFIG_CMD} ${_if} inet6 ${address} \ + prefixlen $plen ${_action} + # if I am a router, add subnet router # anycast address (RFC 2373). if checkyesno ipv6_gateway_enable; then - ifconfig ${_if} inet6 $j:: prefixlen 64 \ - ${_action} anycast + ${IFCONFIG_CMD} ${_if} inet6 $j:: \ + prefixlen $plen ${_action} anycast fi done fi @@ -918,7 +1053,7 @@ ipv6_accept_rtadv_up() { if ipv6_autoconfif $1; then - ifconfig $1 inet6 accept_rtadv up + ${IFCONFIG_CMD} $1 inet6 accept_rtadv up if ! checkyesno rtsold_enable; then rtsol ${rtsol_flags} $1 fi @@ -930,7 +1065,7 @@ ipv6_accept_rtadv_down() { if ipv6_autoconfif $1; then - ifconfig $1 inet6 -accept_rtadv + ${IFCONFIG_CMD} $1 inet6 -accept_rtadv fi } @@ -975,7 +1110,7 @@ # create_args_IF for ifn in ${cloned_interfaces}; do - ifconfig ${ifn} create `get_if_var ${ifn} create_args_IF` + ${IFCONFIG_CMD} ${ifn} create `get_if_var ${ifn} create_args_IF` if [ $? -eq 0 ]; then _list="${_list}${_prefix}${ifn}" [ -z "$_prefix" ] && _prefix=' ' @@ -995,7 +1130,7 @@ _list= for ifn in ${cloned_interfaces}; do - ifconfig -n ${ifn} destroy + ${IFCONFIG_CMD} -n ${ifn} destroy if [ $? -eq 0 ]; then _list="${_list}${_prefix}${ifn}" [ -z "$_prefix" ] && _prefix=' ' @@ -1022,16 +1157,16 @@ debug_flags="`get_if_var $child wlandebug_IF`" if expr $child : 'wlan[0-9][0-9]*$' >/dev/null 2>&1; then - ifconfig $child create ${create_args} && cfg=0 + ${IFCONFIG_CMD} $child create ${create_args} && cfg=0 if [ -n "${debug_flags}" ]; then wlandebug -i $child ${debug_flags} fi else - i=`ifconfig wlan create ${create_args}` + i=`${IFCONFIG_CMD} wlan create ${create_args}` if [ -n "${debug_flags}" ]; then wlandebug -i $i ${debug_flags} fi - ifconfig $i name $child && cfg=0 + ${IFCONFIG_CMD} $i name $child && cfg=0 fi if autoif $child; then ifn_start $child @@ -1049,14 +1184,14 @@ if expr $child : '[1-9][0-9]*$' >/dev/null 2>&1; then child="${ifn}.${child}" create_args=`get_if_var $child create_args_IF` - ifconfig $child create ${create_args} && cfg=0 + ${IFCONFIG_CMD} $child create ${create_args} && cfg=0 else create_args="vlandev $ifn `get_if_var $child create_args_IF`" if expr $child : 'vlan[0-9][0-9]*$' >/dev/null 2>&1; then - ifconfig $child create ${create_args} && cfg=0 + ${IFCONFIG_CMD} $child create ${create_args} && cfg=0 else - i=`ifconfig vlan create ${create_args}` - ifconfig $i name $child && cfg=0 + i=`${IFCONFIG_CMD} vlan create ${create_args}` + ${IFCONFIG_CMD} $i name $child && cfg=0 fi fi if autoif $child; then @@ -1080,7 +1215,7 @@ if ! ifexists $child; then continue fi - ifconfig -n $child destroy && cfg=0 + ${IFCONFIG_CMD} -n $child destroy && cfg=0 done child_vlans=`get_if_var $ifn vlans_IF` @@ -1091,7 +1226,7 @@ if ! ifexists $child; then continue fi - ifconfig -n $child destroy && cfg=0 + ${IFCONFIG_CMD} -n $child destroy && cfg=0 done return ${cfg} @@ -1138,13 +1273,13 @@ ;; *) if expr $i : 'gif[0-9][0-9]*$' >/dev/null 2>&1; then - ifconfig $i create >/dev/null 2>&1 + ${IFCONFIG_CMD} $i create >/dev/null 2>&1 else - gif=`ifconfig gif create` - ifconfig $gif name $i + gif=`${IFCONFIG_CMD} gif create` + ${IFCONFIG_CMD} $gif name $i fi - ifconfig $i tunnel ${peers} - ifconfig $i up + ${IFCONFIG_CMD} $i tunnel ${peers} + ${IFCONFIG_CMD} $i up ;; esac done @@ -1210,7 +1345,7 @@ # ifconfig_IF_ipx ifconfig_args=`_ifconfig_getargs $ifn ipx` if [ -n "${ifconfig_args}" ]; then - ifconfig ${ifn} ${ifconfig_args} + ${IFCONFIG_CMD} ${ifn} ${ifconfig_args} return 0 fi @@ -1227,7 +1362,7 @@ _if=$1 _ifs="^" _ret=1 - ipxList="`ifconfig ${_if} | grep 'ipx ' | tr "\n" "$_ifs"`" + ipxList="`${IFCONFIG_CMD} ${_if} | grep 'ipx ' | tr "\n" "$_ifs"`" oldifs="$IFS" IFS="$_ifs" @@ -1238,7 +1373,7 @@ _ipx=`expr "$_ipx" : '.*\(ipx [0-9a-h]\{1,8\}H*\.[0-9a-h]\{1,12\}\).*'` IFS="$oldifs" - ifconfig ${_if} ${_ipx} delete + ${IFCONFIG_CMD} ${_if} ${_ipx} delete IFS="$_ifs" _ret=0 done @@ -1255,10 +1390,10 @@ local _if _ifname # ifconfig_IF_name - for _if in `ifconfig -l`; do + for _if in `${IFCONFIG_CMD} -l`; do _ifname=`get_if_var $_if ifconfig_IF_name` if [ ! -z "$_ifname" ]; then - ifconfig $_if name $_ifname + ${IFCONFIG_CMD} $_if name $_ifname fi done @@ -1290,7 +1425,7 @@ _tmplist= case ${network_interfaces} in [Aa][Uu][Tt][Oo]) - _autolist="`ifconfig -l`" + _autolist="`${IFCONFIG_CMD} -l`" _lo= for _if in ${_autolist} ; do if autoif $_if; then @@ -1398,7 +1533,7 @@ { local media - case `ifconfig $1 2>/dev/null` in + case `${IFCONFIG_CMD} $1 2>/dev/null` in *media:?Ethernet*) media=Ethernet ;; esac @@ -1410,25 +1545,27 @@ # If flag is defined, tentative ones will be excluded. network6_getladdr() { - local proto addr rest - ifconfig $1 2>/dev/null | while read proto addr rest; do - case ${proto} in - inet6) - case ${addr} in - fe80::*) - if [ -z "$2" ]; then - echo ${addr} - return - fi - case ${rest} in - *tentative*) - continue - ;; - *) - echo ${addr} - return - esac - esac + local _if _flag proto addr rest + _if=$1 + _flag=$2 + + ${IFCONFIG_CMD} $_if 2>/dev/null | while read proto addr rest; do + case "${proto}/${addr}/${_flag}/${rest}" in + inet6/fe80::*//*) + echo ${addr} + ;; + inet6/fe80:://*tentative*) # w/o flag + sleep `${SYSCTL_N} net.inet6.ip6.dad_count` + network6_getladdr $_if $_flags + ;; + inet6/fe80::/*/*tentative*) # w/ flag + echo ${addr} + ;; + *) + continue + ;; esac + + return done } Index: share/man/man5/rc.conf.5 =================================================================== --- share/man/man5/rc.conf.5 (revision 251584) +++ share/man/man5/rc.conf.5 (working copy) @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd June 9, 2013 +.Dd June 15, 2013 .Dt RC.CONF 5 .Os .Sh NAME @@ -1124,44 +1124,59 @@ .Xr ifconfig 8 while the order of the other arguments is preserved. .Pp -One can configure more than one IPv4 address with the -.Va ipv4_addrs_ Ns Aq Ar interface -variable. -One or more IP addresses must be provided in Classless Inter-Domain -Routing (CIDR) address notation, whose last byte can be a range like -192.0.2.5-23/24. -In this case the address 192.0.2.5 will be configured with the +It is possible to add IP alias entries using +.Xr ifconfig 8 +syntax with the address family keyword such as +.Li inet . +Assuming that the interface in question was +.Li ed0 , +it might look something like this: +.Bd -literal +ifconfig_ed0_alias0="inet 127.0.0.253 netmask 0xffffffff" +ifconfig_ed0_alias1="inet 127.0.0.254 netmask 0xffffffff" +.Ed +.Pp +It also possible to configure multiple IP addresses in Classless +Inter-Domain Routing (CIDR) address notation, +whose each address component can be a range like +.Li inet 192.0.2.5-23/24 +or +.Li inet6 2001:db8:1-f::1/64 . +.Pp +In the case of +.Li 192.0.2.5-23/24 , +the address 192.0.2.5 will be configured with the netmask /24 and the addresses 192.0.2.6 to 192.0.2.23 with the non-conflicting netmask /32 as explained in the .Xr ifconfig 8 alias section. +Note that this special netmask handling is only for +.Li inet , +not for the other address families such as +.Li inet6 . +.Pp With the interface in question being .Li ed0 , an example could look like: .Bd -literal -ipv4_addrs_ed0="192.0.2.129/27 192.0.2.1-5/28" +ifconfig_ed0_alias2="inet 192.0.2.129/27" +ifconfig_ed0_alias3="inet 192.0.2.1-5/28" .Ed .Pp -It is also possible to add IP alias entries using -.Xr ifconfig 8 -syntax with the -.Dq Li inet -keyword. -Assuming that the interface in question was -.Li ed0 , -it might look -something like this: -.Bd -literal -ifconfig_ed0_alias0="inet 127.0.0.253 netmask 0xffffffff" -ifconfig_ed0_alias1="inet 127.0.0.254 netmask 0xffffffff" -.Ed +and so on. .Pp -And so on. +Note that +.Va ipv4_addrs_ Ns Aq Ar interface +variable was supported for IPv4 CIDR address notation. +It is now deprecated because the functionality was integrated into +.Va ifconfig_ Ns Ao Ar interface Ac Ns Va _alias Ns Aq Ar n +though +.Va ipv4_addrs_ Ns Aq Ar interface +is still supported for backward compatibility. +.Pp For each .Va ifconfig_ Ns Ao Ar interface Ac Ns Va _alias Ns Aq Ar n -entry with the -.Dq Li inet -keyword that is found, +entry with an address family keyword, its contents are passed to .Xr ifconfig 8 . Execution stops at the first unsuccessful access, so if @@ -1182,6 +1197,18 @@ Due to this difficult to manage behavior, the .Va ifconfig_ Ns Ao Ar interface Ac Ns Va _alias Ns Aq Ar n form is deprecated. +There is +.Va ifconfig_ Ns Ao Ar interface Ac Ns Va _aliases +variable, which has the same functionality as +.Va ifconfig_ Ns Ao Ar interface Ac Ns Va _alias Ns Aq Ar n +and can have all of entries in a variable like the following: +.Bd -literal +ifconfig_ed0_aliases="\\ + inet 127.0.0.251 netmask 0xffffffff \\ + inet 127.0.0.252 netmask 0xffffffff \\ + inet 127.0.0.253 netmask 0xffffffff \\ + inet 127.0.0.254 netmask 0xffffffff" +.Ed .Pp If the .Pa /etc/start_if. Ns Aq Ar interface ----Next_Part(Sun_Jun_16_00_59_41_2013_325)---- ----Security_Multipart0(Sun_Jun_16_00_59_41_2013_553)-- Content-Type: application/pgp-signature Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.13 (FreeBSD) iEUEABECAAYFAlG8j20ACgkQTyzT2CeTzy1SbgCYz2DaayPEuTRee288fK0gYLjC xgCeNCGFQiwFCsS9v3PUbYk+rQBsXd4= =PYKu -----END PGP SIGNATURE----- ----Security_Multipart0(Sun_Jun_16_00_59_41_2013_553)----