From: Joe Lawrence <joe.lawrence@redhat.com>
To: Libor Pechacek <lpechacek@suse.cz>
Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
live-patching@vger.kernel.org, Jiri Kosina <jikos@kernel.org>,
Artem Savkov <asavkov@redhat.com>,
Josh Poimboeuf <jpoimboe@redhat.com>,
Petr Mladek <pmladek@suse.com>, Miroslav Benes <mbenes@suse.cz>,
Nicolai Stange <nstange@suse.de>
Subject: Re: [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)
In-Reply-To: <20180423144317.too6ucui37m7oj7y@redhat.com>
On 04/23/2018 10:43 AM, Joe Lawrence wrote:
> On Fri, Apr 20, 2018 at 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
next prev parent reply other threads:[~2018-04-24 15:50 UTC|newest]
Thread overview: 15+ 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 ` [PATCH v3] selftests/livepatch: introduce tests Joe Lawrence
2018-04-12 21:36 ` Josh Poimboeuf
2018-04-13 11:20 ` Miroslav Benes
2018-04-13 20:52 ` Joe Lawrence
2018-04-16 11:33 ` Miroslav Benes
2018-04-16 15:02 ` Petr Mladek
2018-04-17 8:06 ` Miroslav Benes
2018-04-17 13:25 ` Joe Lawrence
2018-04-16 12:49 ` Petr Mladek
2018-04-20 12:56 ` Libor Pechacek
2018-04-23 14:43 ` Joe Lawrence
2018-04-24 15:50 ` Joe Lawrence [this message]
2018-04-24 17:19 ` Libor Pechacek
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 \
--cc=asavkov@redhat.com \
--cc=jikos@kernel.org \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=lpechacek@suse.cz \
--cc=mbenes@suse.cz \
--cc=nstange@suse.de \
--cc=pmladek@suse.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
all inboxes | Powered by JetHome®