Skip to content

Commit

Permalink
Re-add device after zramctl --reset
Browse files Browse the repository at this point in the history
  • Loading branch information
vaeth committed Nov 21, 2016
1 parent 216be82 commit 43b5b4d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 34 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# ChangeLog for zram-init:

*zram-init-6.1.0:
Martin Väth <martin at mvath.de>:
- Re-add device after zramctl --reset

*zram-init-6.0.0:
Martin Väth <martin at mvath.de>:
- Add/remove devices if kernel supports it, see
Expand Down
80 changes: 46 additions & 34 deletions sbin/zram-init
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,30 @@ fi

devnode=/dev/zram$dev
zclass=/sys/class/zram-control

HotAdd() {
while :
do curradd=
exec 3<&0 && {
exec <"$zclass/hot_add" && \
read curradd || curradd=
exec 0<&3
exec 3<&-
}
IsNumeric "$curradd" || {
Warning "warning: hot_add failed for $devnode"
break
}
[ $curradd -lt $dev ] || break
done
sleep=0
while ! test -b "$devnode"
do sleep 1
sleep=$(( $sleep + 1 ))
[ $sleep -lt 5 ] || Fatal "failed to create $devnode"
done
}

if ! test -b "$devnode"
then $umount && exit
IsNumeric "${num:-0}" || Fatal "device count $num is not numeric"
Expand All @@ -176,50 +200,38 @@ then $umount && exit
[ $sleep -lt 5 ] || \
Fatal "cannot create $devnode: $zclass missing"
done
if ! test -b "$devnode"
then while :
do curradd=
exec 3<&0 && {
exec <"$zclass/hot_add" && \
read curradd || curradd=
exec 0<&3
exec 3<&-
}
IsNumeric "$curradd" || {
Warning "warning: hot_add failed for $devnode"
break
}
[ $curradd -lt $dev ] || break
done
sleep=0
while ! test -b "$devnode"
do sleep 1
sleep=$(( $sleep + 1 ))
[ $sleep -lt 5 ] || Fatal "failed to create $devnode"
done
fi
test -b "$devnode" || {
HotAdd
keep=:
}
fi
if ! $zramctl
then block=/sys/block/zram$dev
test -d "$block" || Fatal "cannot find $block"
fi

status=0
if ! $keep
then if $swap
then swapoff -- "$devnode" >/dev/null 2>&1
else ! $mount || umount -- "$devnode" >/dev/null 2>&1
fi && {
if $zramctl
then zramctl --reset -- "$devnode"
else SysCtl 1 "$block/reset" && {
! test -w "$zclass/hot_remove" || \
SysCtl "$device" "$zclass/hot_remove"
}
fi || Warning "warning: failed to reset zram$dev"
}
then swapoff -- "$devnode" >/dev/null 2>&1 || status=$?
elif $mount
then umount -- "$devnode" >/dev/null 2>&1 || status=$?
fi
if [ $status -eq 0 ]
then if $zramctl
then zramctl --reset -- "$devnode" || status=$?
else SysCtl 1 "$block/reset" || status=$?
if $umount && test -w "$zclass/hot_remove"
then SysCtl "$device" "$zclass/hot_remove" \
|| status=$?
fi
fi
[ $status -eq 0 ] || \
Warning "warning: failed to reset zram$dev"
fi
fi
status=$?
$umount && exit $status
test -b "$devnode" || HotAdd

if $zramctl
then eval "set -- a $zramctl_opt"
Expand Down

0 comments on commit 43b5b4d

Please sign in to comment.