Changeset View
Changeset View
Standalone View
Standalone View
libexec/rc/rc.d/growfs
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | |||||
. /etc/rc.subr | . /etc/rc.subr | ||||
name="growfs" | name="growfs" | ||||
desc="Grow root partition to fill device" | desc="Grow root partition to fill device" | ||||
start_cmd="growfs_start" | start_cmd="growfs_start" | ||||
stop_cmd=":" | stop_cmd=":" | ||||
rcvar="growfs_enable" | rcvar="growfs_enable" | ||||
growfs_get_diskdev () | |||||
{ | |||||
local _search=${1} | |||||
sysctl -b kern.geom.conftxt | | |||||
while read x1 _type _dev line | |||||
do | |||||
if [ "${_type}" = "DISK" -a -n "$(echo ${_search} | grep ${_dev})" ]; then | |||||
imp: "while read x1 _type _dev rest" above would obviate the need for his awkward construct here. | |||||
echo -n ${_dev} | |||||
Not Done Inline Actions${1} is a bit unclear from context. I'd recommend a local variable set at the top of this function to hold its value and give it some additional semantic meaning" imp: ${1} is a bit unclear from context. I'd recommend a local variable set at the top of this… | |||||
break | |||||
fi | |||||
done | |||||
} | |||||
growfs_start () | growfs_start () | ||||
{ | { | ||||
echo "Growing root partition to fill device" | echo "Growing root partition to fill device" | ||||
FSTYPE=$(mount -p | awk '{ if ( $2 == "/") { print $3 }}') | FSTYPE=$(mount -p | awk '{ if ( $2 == "/") { print $3 }}') | ||||
FSDEV=$(mount -p | awk '{ if ( $2 == "/") { print $1 }}') | FSDEV=$(mount -p | awk '{ if ( $2 == "/") { print $1 }}') | ||||
case "$FSTYPE" in | case "$FSTYPE" in | ||||
ufs) | ufs) | ||||
rootdev=${FSDEV#/dev/} | rootdev=${FSDEV#/dev/} | ||||
;; | ;; | ||||
zfs) | zfs) | ||||
pool=${FSDEV%%/*} | pool=${FSDEV%%/*} | ||||
rootdev=$(zpool list -v $pool | awk 'END { print $1 }') | rootdev=$(zpool list -v $pool | awk 'END { print $1 }') | ||||
;; | ;; | ||||
*) | *) | ||||
echo "Don't know how to grow root filesystem type: $FSTYPE" | echo "Don't know how to grow root filesystem type: $FSTYPE" | ||||
return | return | ||||
esac | esac | ||||
if [ x"$rootdev" = x"${rootdev%/*}" ]; then | if [ x"$rootdev" = x"${rootdev%/*}" ]; then | ||||
# raw device | # raw device | ||||
rawdev="$rootdev" | rawdev="$rootdev" | ||||
else | else | ||||
rawdev=$(glabel status | awk '$1 == "'"$rootdev"'" { print $3 }') | rawdev=$(glabel status | awk -v rootdev=$rootdev 'index(rootdev, $1) { print $3; }') | ||||
if [ x"$rawdev" = x"" ]; then | if [ x"$rawdev" = x"" ]; then | ||||
Not Done Inline ActionsThis quoting is awkard and error-prone. I'd suggest (glabel status | awk -v rootdev=$rootdev '{index(rootdev, $1) { print $3; }) instead since that's clearer and avoids the quoting and unquoting to get the variable substituted. imp: This quoting is awkard and error-prone.
I'd suggest `(glabel status | awk -v rootdev=$rootdev… | |||||
echo "Can't figure out device for: $rootdev" | echo "Can't figure out device for: $rootdev" | ||||
return | return | ||||
fi | fi | ||||
fi | fi | ||||
if [ x"diskid" = x"${rootdev%/*}" ]; then | |||||
search=$rootdev | |||||
else | |||||
search=$rawdev | |||||
fi | |||||
diskdev=$(growfs_get_diskdev ${search}) | |||||
if [ -z "${diskdev}" ]; then | |||||
diskdev=${rootdev} | |||||
fi | |||||
sysctl -b kern.geom.conftxt | awk ' | sysctl -b kern.geom.conftxt | awk ' | ||||
{ | { | ||||
lvl=$1 | lvl=$1 | ||||
device[lvl] = $3 | device[lvl] = $3 | ||||
type[lvl] = $2 | type[lvl] = $2 | ||||
idx[lvl] = $7 | idx[lvl] = $7 | ||||
parttype[lvl] = $13 | parttype[lvl] = $13 | ||||
if (dev == $3) { | if (dev == $3) { | ||||
Show All 12 Lines | for (i = 1; i <= lvl; i++) { | ||||
} | } | ||||
} | } | ||||
for (i = 1; i <= lvl; i++) { | for (i = 1; i <= lvl; i++) { | ||||
if (cmd[i]) | if (cmd[i]) | ||||
system(cmd[i]) | system(cmd[i]) | ||||
} | } | ||||
exit 0 | exit 0 | ||||
} | } | ||||
}' dev="$rawdev" | }' dev="$search" | ||||
gpart commit "$rootdev" | gpart commit "$diskdev" 2> /dev/null | ||||
case "$FSTYPE" in | case "$FSTYPE" in | ||||
ufs) | ufs) | ||||
growfs -y /dev/"$rootdev" | growfs -y /dev/"$rootdev" | ||||
;; | ;; | ||||
zfs) | zfs) | ||||
zpool online -e $pool $rootdev | zpool online -e $pool $rootdev | ||||
;; | ;; | ||||
esac | esac | ||||
} | } | ||||
load_rc_config $name | load_rc_config $name | ||||
run_rc_command "$1" | run_rc_command "$1" |
"while read x1 _type _dev rest" above would obviate the need for his awkward construct here.