Received: by 10.192.165.148 with SMTP id m20csp4818186imm; Tue, 24 Apr 2018 08:53:09 -0700 (PDT) X-Google-Smtp-Source: AIpwx492YMbE6G9gjP+I5Ww45JwL3lQMcIr/IkzVz/a1QjIhG0rLf/Vg9L6ZECNk7b460sIurZLM X-Received: by 2002:a17:902:a5c2:: with SMTP id t2-v6mr25603135plq.360.1524585189203; Tue, 24 Apr 2018 08:53:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524585189; cv=none; d=google.com; s=arc-20160816; b=gvJBPeSPYDkFyfOV+fSKTiDrTnK8CO1o5ditNiWUZxotVSjHozgnKa59m9vfztsxUc 7m+uZ9HwWu9DdTBtZrW7Y7rPfh9fj06aem61u7xnrrISbj7FgA9eWcFfuO7mJh8zXJS2 9ExkY1jZSLqdkOkU9cJszmf5VeLPstF0h2sfyBKWARYVyqYRtMJ0NvJfOYq8BBD1nAjM PGywQ37hyOPhmutKcLHBBbo7GkfmatZYEXOtOnCGe+IKWgMKyl0TUOq+wcGnKoYCJs/W zO5sbXO3i1OyXreJUx/vTJTczI8jRi1GK2JrxhOb5orJWWN94wboKAhqnuolBMUJSYmE NeBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:references:cc:to:from:subject :arc-authentication-results; bh=k1W2oeAvba+dN/kJh+DEcDXJCwGJe+v9Y7cGnjFMIzY=; b=BZZ3s/dSm6H18+qPW8P9ixn34qCmJByfzOU9HnBqdHxHGFGeMLBXR5kqA+L8TSwR3Z TSa02YAGjGPTjtQnOUAMGdaIO+ykESg0eBlEfz67daLRka0go7ga9Jk1I7CuTD6ASbZQ 4FwPTS/7xcinSwRkVpf4P+IWpt3CRO1gsDjXfREZZUDK86i+12hiaih7H4KdjQTds4as DYZDx2eL6pyLleh/FPoVvuS6J3XwFhkUHocls6PJdykvGQL37sxkvBo+niZ4t+qElynK q5qsjlG5Tvwr48dKO7wSQNxwTqovfYipdju/mfhqZ+YW681eEz/vfbDbQN/SHaZjeltZ 04fg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y9si11856489pgr.180.2018.04.24.08.52.52; Tue, 24 Apr 2018 08:53:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751295AbeDXPuc (ORCPT + 99 others); Tue, 24 Apr 2018 11:50:32 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:52646 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750729AbeDXPua (ORCPT ); Tue, 24 Apr 2018 11:50:30 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 763AE427361F; Tue, 24 Apr 2018 15:50:29 +0000 (UTC) Received: from jlaw-desktop.bos.csb (dhcp-17-208.bos.redhat.com [10.18.17.208]) by smtp.corp.redhat.com (Postfix) with ESMTP id 16D2883B8C; Tue, 24 Apr 2018 15:50:29 +0000 (UTC) Subject: Re: [PATCH v3] selftests/livepatch: introduce tests From: Joe Lawrence To: Libor Pechacek Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, live-patching@vger.kernel.org, Jiri Kosina , Artem Savkov , Josh Poimboeuf , Petr Mladek , Miroslav Benes , Nicolai Stange References: <1523544871-29444-1-git-send-email-joe.lawrence@redhat.com> <1523544871-29444-2-git-send-email-joe.lawrence@redhat.com> <20180420125605.e4eye7ncukyivleh@fm.suse.cz> <20180423144317.too6ucui37m7oj7y@redhat.com> Organization: Red Hat Message-ID: Date: Tue, 24 Apr 2018 11:50:28 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: <20180423144317.too6ucui37m7oj7y@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 24 Apr 2018 15:50:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 24 Apr 2018 15:50:29 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'joe.lawrence@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 ; do ; if > retries>; then ..." 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 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