uvol: update to version 0.4
Create UCI fstab mount sections for existing volumes on firstboot. Introduce special handling for volumes with non-[:alnum:] prefix: - do not create UCI sections for these 'hidden' volumes - create UCI section for '.uxc' special volume with target /var/state/uxc to be used for uxc config. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
This commit is contained in:
parent
28ed2b82c5
commit
6276e8b2ae
5 changed files with 147 additions and 22 deletions
|
@ -1,7 +1,7 @@
|
|||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=uvol
|
||||
PKG_VERSION:=0.3
|
||||
PKG_VERSION:=0.4
|
||||
PKG_RELEASE:=$(AUTORELEASE)
|
||||
|
||||
PKG_MAINTAINER:=Daniel Golle <daniel@makrotopia.org>
|
||||
|
@ -64,12 +64,13 @@ define Package/autopart/install
|
|||
endef
|
||||
|
||||
define Package/uvol/install
|
||||
$(INSTALL_DIR) $(1)/etc/init.d $(1)/usr/libexec/uvol $(1)/usr/sbin $(1)/lib/functions
|
||||
$(INSTALL_DIR) $(1)/etc/init.d $(1)/usr/libexec/uvol $(1)/usr/sbin $(1)/lib/functions $(1)/etc/uci-defaults
|
||||
$(INSTALL_BIN) ./files/uvol.init $(1)/etc/init.d/uvol
|
||||
$(INSTALL_BIN) ./files/common.sh $(1)/lib/functions/uvol.sh
|
||||
$(INSTALL_BIN) ./files/ubi.sh $(1)/usr/libexec/uvol/20-ubi.sh
|
||||
$(INSTALL_BIN) ./files/lvm.sh $(1)/usr/libexec/uvol/50-lvm.sh
|
||||
$(INSTALL_BIN) ./files/uvol $(1)/usr/sbin
|
||||
$(INSTALL_BIN) ./files/uvol.defaults $(1)/etc/uci-defaults/90-uvol-restore-uci
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,autopart))
|
||||
|
|
|
@ -11,15 +11,27 @@ uvol_uci_add() {
|
|||
local volname="$1"
|
||||
local devname="$2"
|
||||
local mode="$3"
|
||||
local autofs uuid uciname
|
||||
local autofs=0
|
||||
local target="/var/run/uvol/$volname"
|
||||
local uuid uciname
|
||||
|
||||
uciname=${volname//-/_}
|
||||
[ "$mode" = "ro" ] && autofs=1
|
||||
uciname="${volname//[-.]/_}"
|
||||
uciname="${uciname//[!([:alnum:]_)]}"
|
||||
uuid="$(/sbin/block info | grep "^$2" | xargs -n 1 echo | grep "^UUID=.*")"
|
||||
[ "$uuid" ] || return 22
|
||||
_uvol_init_spooldir
|
||||
uuid="${uuid:5}"
|
||||
autofs=0
|
||||
[ "$mode" = "ro" ] && autofs=1
|
||||
|
||||
case "$uciname" in
|
||||
"_uxc")
|
||||
target="/var/state/uxc"
|
||||
;;
|
||||
"_"*)
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
|
||||
_uvol_init_spooldir
|
||||
if [ -e "${UCI_SPOOLDIR}/remove-$1" ]; then
|
||||
rm "${UCI_SPOOLDIR}/remove-$1"
|
||||
fi
|
||||
|
@ -27,11 +39,10 @@ uvol_uci_add() {
|
|||
cat >"${UCI_SPOOLDIR}/add-$1" <<EOF
|
||||
set fstab.$uciname=mount
|
||||
set fstab.$uciname.uuid=$uuid
|
||||
set fstab.$uciname.target=/var/run/uvol/$volname
|
||||
set fstab.$uciname.target=$target
|
||||
set fstab.$uciname.options=$mode
|
||||
set fstab.$uciname.autofs=$autofs
|
||||
set fstab.$uciname.enabled=1
|
||||
commit fstab
|
||||
EOF
|
||||
}
|
||||
|
||||
|
@ -39,7 +50,8 @@ uvol_uci_remove() {
|
|||
local volname="$1"
|
||||
local uciname
|
||||
|
||||
uciname=${volname//-/_}
|
||||
uciname="${volname//-/_}"
|
||||
uciname="${uciname//[!([:alnum:]_)]}"
|
||||
if [ -e "${UCI_SPOOLDIR}/add-$1" ]; then
|
||||
rm "${UCI_SPOOLDIR}/add-$1"
|
||||
return
|
||||
|
@ -47,20 +59,25 @@ uvol_uci_remove() {
|
|||
_uvol_init_spooldir
|
||||
cat >"${UCI_SPOOLDIR}/remove-$1" <<EOF
|
||||
delete fstab.$uciname
|
||||
commit fstab
|
||||
EOF
|
||||
}
|
||||
|
||||
uvol_uci_commit() {
|
||||
local volname="$1"
|
||||
local ucibatch
|
||||
|
||||
if [ -e "${UCI_SPOOLDIR}/add-$1" ]; then
|
||||
uci batch < "${UCI_SPOOLDIR}/add-$1"
|
||||
rm "${UCI_SPOOLDIR}/add-$1"
|
||||
elif [ -e "${UCI_SPOOLDIR}/remove-$1" ]; then
|
||||
uci batch < "${UCI_SPOOLDIR}/remove-$1"
|
||||
rm "${UCI_SPOOLDIR}/remove-$1"
|
||||
fi
|
||||
for ucibatch in "${UCI_SPOOLDIR}/"*"-$volname"${volname+*} ; do
|
||||
[ -e "$ucibatch" ] || break
|
||||
uci batch < "$ucibatch"
|
||||
[ $? -eq 0 ] && rm "$ucibatch"
|
||||
done
|
||||
|
||||
uci commit fstab
|
||||
return $?
|
||||
}
|
||||
|
||||
uvol_uci_init() {
|
||||
uci -q get fstab.@uvol[0] && return
|
||||
uci add fstab uvol
|
||||
uci set fstab.@uvol[-1].initialized=1
|
||||
}
|
||||
|
|
|
@ -177,8 +177,8 @@ activatevol() {
|
|||
return 22
|
||||
;;
|
||||
*)
|
||||
[ "$lv_active" = "active" ] && return 0
|
||||
uvol_uci_commit "$1"
|
||||
[ "$lv_active" = "active" ] && return 0
|
||||
lvm_cmd lvchange -k n "$lv_full_name" || return $?
|
||||
lvm_cmd lvchange -a y "$lv_full_name" || return $?
|
||||
return 0
|
||||
|
@ -319,10 +319,37 @@ listvols() {
|
|||
done
|
||||
}
|
||||
|
||||
boot() {
|
||||
local reports rep lv lvs lv_name lv_dm_path lv_mode volname
|
||||
|
||||
detect() {
|
||||
local reports rep lv lvs lv_name lv_full_name lv_mode volname devname lv_skip_activation
|
||||
local temp_up=""
|
||||
|
||||
json_init
|
||||
json_load "$(lvs -o lv_name,lv_dm_path -S "lv_name=~^[rw][ow]_.*\$ && vg_name=$vg_name && lv_active=active")"
|
||||
json_load "$(lvs -o lv_full_name -S "lv_name=~^[rw][owp]_.*\$ && vg_name=$vg_name && lv_skip_activation!=0")"
|
||||
json_select report
|
||||
json_get_keys reports
|
||||
for rep in $reports; do
|
||||
json_select "$rep"
|
||||
json_select lv
|
||||
json_get_keys lvs
|
||||
for lv in $lvs; do
|
||||
json_select "$lv"
|
||||
json_get_vars lv_full_name
|
||||
echo "lvchange -a y $lv_full_name"
|
||||
lvm_cmd lvchange -k n "$lv_full_name"
|
||||
lvm_cmd lvchange -a y "$lv_full_name"
|
||||
temp_up="$temp_up $lv_full_name"
|
||||
json_select ..
|
||||
done
|
||||
json_select ..
|
||||
break
|
||||
done
|
||||
sleep 1
|
||||
|
||||
uvol_uci_init
|
||||
|
||||
json_init
|
||||
json_load "$(lvs -o lv_name,lv_dm_path -S "lv_name=~^[rw][owp]_.*\$ && vg_name=$vg_name")"
|
||||
json_select report
|
||||
json_get_keys reports
|
||||
for rep in $reports; do
|
||||
|
@ -334,11 +361,25 @@ boot() {
|
|||
json_get_vars lv_name lv_dm_path
|
||||
lv_mode="${lv_name:0:2}"
|
||||
lv_name="${lv_name:3}"
|
||||
echo uvol_uci_add "$lv_name" "/dev/$(getdev "$lv_name")" "$lv_mode"
|
||||
uvol_uci_add "$lv_name" "/dev/$(getdev "$lv_name")" "$lv_mode"
|
||||
json_select ..
|
||||
done
|
||||
json_select ..
|
||||
break
|
||||
done
|
||||
|
||||
uvol_uci_commit
|
||||
|
||||
for lv_full_name in $temp_up; do
|
||||
echo "lvchange -a n $lv_full_name"
|
||||
lvm_cmd lvchange -a n "$lv_full_name"
|
||||
lvm_cmd lvchange -k y "$lv_full_name"
|
||||
done
|
||||
}
|
||||
|
||||
boot() {
|
||||
true ; # nothing to do, lvm does it all for us
|
||||
}
|
||||
|
||||
exportpv
|
||||
|
@ -354,6 +395,9 @@ case "$cmd" in
|
|||
total)
|
||||
totalbytes
|
||||
;;
|
||||
detect)
|
||||
detect
|
||||
;;
|
||||
boot)
|
||||
boot
|
||||
;;
|
||||
|
|
|
@ -230,6 +230,63 @@ bootvols() {
|
|||
done
|
||||
}
|
||||
|
||||
detect() {
|
||||
local volname voldev volmode voldev fstype tmpdev=""
|
||||
for voldir in "/sys/devices/virtual/ubi/${ubidev}/${ubidev}_"*; do
|
||||
read -r volname < "$voldir/name"
|
||||
voldev="$(basename "$voldir")"
|
||||
fstype=
|
||||
case "$volname" in
|
||||
uvol-r[od]-*)
|
||||
if ! [ -e "/dev/ubiblock${voldev:3}" ]; then
|
||||
ubiblock --create "/dev/$voldev" || return $?
|
||||
fi
|
||||
case "$volname" in
|
||||
uvol-rd-*)
|
||||
tmpdev="$tmpdev $voldev"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
continue
|
||||
;;
|
||||
esac
|
||||
volmode="${volname:5:2}"
|
||||
volname="${volname:8}"
|
||||
done
|
||||
|
||||
uvol_uci_init
|
||||
|
||||
for voldir in "/sys/devices/virtual/ubi/${ubidev}/${ubidev}_"*; do
|
||||
read -r volname < "$voldir/name"
|
||||
voldev="$(basename "$voldir")"
|
||||
case "$volname" in
|
||||
uvol-[rw][wod]*)
|
||||
true
|
||||
;;
|
||||
*)
|
||||
continue
|
||||
;;
|
||||
esac
|
||||
volmode="${volname:5:2}"
|
||||
volname="${volname:8}"
|
||||
case "$volmode" in
|
||||
"ro" | "rd")
|
||||
uvol_uci_add "$volname" "/dev/ubiblock${voldev:3}" "ro"
|
||||
;;
|
||||
"rw" | "wd")
|
||||
uvol_uci_add "$volname" "/dev/${voldev}" "rw"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
uvol_uci_commit
|
||||
|
||||
for voldev in $tmpdev ; do
|
||||
ubiblock --remove "/dev/$voldev" || return $?
|
||||
done
|
||||
}
|
||||
|
||||
case "$cmd" in
|
||||
align)
|
||||
echo "$ebsize"
|
||||
|
@ -240,6 +297,9 @@ case "$cmd" in
|
|||
total)
|
||||
totalbytes
|
||||
;;
|
||||
detect)
|
||||
detect
|
||||
;;
|
||||
boot)
|
||||
bootvols
|
||||
;;
|
||||
|
|
3
utils/uvol/files/uvol.defaults
Normal file
3
utils/uvol/files/uvol.defaults
Normal file
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
uci -q get fstab.@uvol[0].initialized >/dev/null || uvol detect || true
|
Loading…
Reference in a new issue