uvol: fix emmitting ubus event when removing UBI volume
authorDaniel Golle <daniel@makrotopia.org>
Mon, 26 Apr 2021 18:19:10 +0000 (19:19 +0100)
committerDaniel Golle <daniel@makrotopia.org>
Mon, 26 Apr 2021 18:21:50 +0000 (19:21 +0100)
In case a volume which is down is removed, no ubus event needs to be
fired. Don't try.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
utils/uvol/files/ubi.sh
utils/uvol/files/uvol

index 0a1b73093cb432b11111b0847de79e3b17470127..2da7e309b8c8863c75e5941a65afd8911ce93264 100644 (file)
@@ -119,14 +119,14 @@ removevol() {
        local voldev=$(getdev "$@")
        local evdata
        [ "$voldev" ] || return 2
-       local volnum=${voldev#${ubidev}_}
        if vol_is_mode $voldev rw ; then
                evdata="{\"name\": \"$1\", \"action\": \"down\", \"device\": \"/dev/$voldev\"}"
-       elif vol_is_mode $voldev ro ; then
+       elif vol_is_mode $voldev ro && [ -e "/dev/ubiblock${voldev:3}" ]; then
                evdata="{\"name\": \"$1\", \"action\": \"down\", \"device\": \"/dev/ubiblock${voldev:3}\"}"
        fi
+       local volnum=${voldev#${ubidev}_}
        ubirmvol /dev/$ubidev -n $volnum || return $?
-       ubus send block.volume "$evdata"
+       [ "$evdata" ] && ubus send block.volume "$evdata"
 }
 
 activatevol() {
index a095b3efff386a8d1be55073b05a223a06a4f55b..4958d31ff481051395ffe1ce4be3acda35c2932b 100644 (file)
@@ -3,6 +3,7 @@
 # uvol prototype
 # future development roadmap (aka. to-do):
 # * re-implement in C (use libubox, execve lvm/ubi*)
+# * hash to validate volume while writing
 # * add atomic batch processing for use by container/package manager
 
 if [ -z "$1" ]; then cat <<EOF