From: joe.lawrence@redhat.com (Joe Lawrence)
Subject: [PATCH v3] selftests/livepatch: introduce tests
Date: Tue, 24 Apr 2018 11:50:28 -0400 [thread overview]
Message-ID: <c3f1a6b8-5eba-84e1-9d0b-8009c9087022@redhat.com> (raw)
Message-ID: <20180424155028.wlC7x7F-8f5K8KPilbm4494WBk0OcaEorWB_ZL9Snrk@z> (raw)
In-Reply-To: <20180423144317.too6ucui37m7oj7y@redhat.com>
On 04/23/2018 10:43 AM, Joe Lawrence wrote:
> On Fri, Apr 20, 2018@02:56:05PM +0200, Libor Pechacek wrote:
>> On Thu 12-04-18 10:54:31, Joe Lawrence wrote:
>>> + fi
>>> + echo "$ret" > /dev/kmsg
>>> +}
>>> +
>>> +# unload_mod(modname) - unload a kernel module
>>> +# modname - module name to unload
>>> +function unload_mod() {
>>> + local mod="$1"
>>> +
>>> + # Wait for module reference count to clear ...
>>> + local i=0
>>> + while [[ $(cat /sys/module/"$mod"/refcnt) != "0" ]]; do
>>> + i=$((i+1))
>>> + if [[ $i -eq $MAX_RETRIES ]]; then
>>> + die "failed to unload module $mod (refcnt)"
>>> + fi
>>> + sleep $RETRY_INTERVAL
>>> + done
>>
>> The repeating pattern of "while <some test>; do <count>; if <count beyond max
>> retries>; then <die>..." seems to ask for encapsulation.
>>
>
> Yeah I definitely agree. I think at some point I had acquired
> bash-fatigue; I wasn't sure how to cleanly wrap <some test> around that
> extra logic. In C, I could do something clever with macros or a
> callback function. My bash scripting isn't great, so I copied and
> pasted my way through it. Suggestions welcome.
>
Okay, here's what I came up with... first off, do you prefer this kind
of transition check vs. looking only at a specific module?
# check_transition() - verify that no livepatch transition in effect
function check_transition() {
grep -q '^1$' /sys/kernel/livepatch/*/transition 2>/dev/null
}
then wrap the retry/timeout logic like:
# retry_cmd(cmd) - loop a command until it is successful or
# $MAX_RETRIES, sleeping $RETRY_INTERVAL in
# between tries
# cmd - command and its arguments to run
function retry_cmd() {
local cmd="$*"
local i=0
while eval "$cmd"; do
i=$((i+1))
[[ $i -eq $MAX_RETRIES ]] && return 1
sleep $RETRY_INTERVAL
done
return 0
}
and the callers to something like:
# wait_for_transition() - wait until all livepatch transitions clear
function wait_for_transition() {
retry_cmd check_transition ||
die "failed to complete transition"
}
I can create similar check() functions to eval for sysfs file existence,
file content, reference count, etc. to remove all the other
retry/timeout loops.
Regards,
-- Joe
--
To unsubscribe from this list: send the line "unsubscribe linux-kselftest" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2018-04-24 15:50 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-12 14:54 [PATCH v3] Add livepatch kselftests joe.lawrence
2018-04-12 14:54 ` Joe Lawrence
2018-04-12 14:54 ` [PATCH v3] selftests/livepatch: introduce tests joe.lawrence
2018-04-12 14:54 ` Joe Lawrence
2018-04-12 21:36 ` jpoimboe
2018-04-12 21:36 ` Josh Poimboeuf
2018-04-13 11:20 ` mbenes
2018-04-13 11:20 ` Miroslav Benes
2018-04-13 20:52 ` joe.lawrence
2018-04-13 20:52 ` Joe Lawrence
2018-04-16 11:33 ` mbenes
2018-04-16 11:33 ` Miroslav Benes
2018-04-16 15:02 ` pmladek
2018-04-16 15:02 ` Petr Mladek
2018-04-17 8:06 ` mbenes
2018-04-17 8:06 ` Miroslav Benes
2018-04-17 13:25 ` joe.lawrence
2018-04-17 13:25 ` Joe Lawrence
2018-04-16 12:49 ` pmladek
2018-04-16 12:49 ` Petr Mladek
2018-04-20 12:56 ` lpechacek
2018-04-20 12:56 ` Libor Pechacek
2018-04-23 14:43 ` joe.lawrence
2018-04-23 14:43 ` Joe Lawrence
2018-04-24 15:50 ` joe.lawrence [this message]
2018-04-24 15:50 ` Joe Lawrence
2018-04-24 17:19 ` lpechacek
2018-04-24 17:19 ` Libor Pechacek
2018-04-24 17:35 ` lpechacek
2018-04-24 17:35 ` Libor Pechacek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c3f1a6b8-5eba-84e1-9d0b-8009c9087022@redhat.com \
--to=joe.lawrence@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).