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>
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>
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))
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
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
}
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
_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
+}
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
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_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][ow]_.*\$ && vg_name=$vg_name && lv_active=active")"
+ 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
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
total)
totalbytes
;;
+ detect)
+ detect
+ ;;
boot)
boot
;;
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"
total)
totalbytes
;;
+ detect)
+ detect
+ ;;
boot)
bootvols
;;
--- /dev/null
+#!/bin/sh
+
+uci -q get fstab.@uvol[0].initialized >/dev/null || uvol detect || true