From nobody Tue May 7 11:41:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) client-ip=216.205.24.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1585436615; cv=none; d=zohomail.com; s=zohoarc; b=IPBqBKR0QEgNEQrw7DpUks7YMkkGx4qA1PWpvAEljq20LVV1b67hh4uImFSKaBKGCKVMe+b8mtP8r8D3H7TJmqdSRWdgJj5ibfK+922NYvsJ70rTFEiPmN3O6cYZnCBduiGsAckmKOx86sWAJxwAgP2s2e962PXUEo0g3Y2LuFk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585436615; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:To; bh=d0kXcwLvWQqgqDwWH3xfpCg3brYYjIpJa+QnI/Y9t/g=; b=bQRwPh6UHA6AXyGWpLJhSGFhVdPoikqB1NJv2DsF3wwLS5NyC2KaoLh41Kh17qiUnn2cm/uffXXFLT9/iwCiLEmWLJDmRwP+DGjTgjwXYPKE5rhCIqTTF6jEgZDm+u9PHmxCbD2sKkGMQI44DCCymMz3U1E9dY36IfBnbc6dxow= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [216.205.24.74]) by mx.zohomail.com with SMTPS id 15854366153441004.886785806538; Sat, 28 Mar 2020 16:03:35 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-267-MKO9rYZaOWeMMmBAODPT_A-1; Sat, 28 Mar 2020 19:03:31 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4CC7B800D50; Sat, 28 Mar 2020 23:03:23 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7B43494B42; Sat, 28 Mar 2020 23:03:17 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 362171809567; Sat, 28 Mar 2020 23:03:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02SN36k0019729 for ; Sat, 28 Mar 2020 19:03:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id 08A342166B2D; Sat, 28 Mar 2020 23:03:06 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 028012166B2E for ; Sat, 28 Mar 2020 23:03:03 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 97D918FF662 for ; Sat, 28 Mar 2020 23:03:03 +0000 (UTC) Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-359-dlX-bC3fMUOS9Ka7CRsyfw-1; Sat, 28 Mar 2020 19:03:01 -0400 Received: by mail-pg1-f194.google.com with SMTP id 142so6666380pgf.11; Sat, 28 Mar 2020 16:03:00 -0700 (PDT) Received: from localhost.localdomain ([116.73.70.204]) by smtp.gmail.com with ESMTPSA id 1sm6728985pjo.10.2020.03.28.16.02.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Mar 2020 16:02:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585436613; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=d0kXcwLvWQqgqDwWH3xfpCg3brYYjIpJa+QnI/Y9t/g=; b=STyvHgpICwG9c077y816/VTDLvf6HDcMoFBKXRLTdsM2Q9WY1hDwtFZy61ezdgoPJVoepI PZESEDNXrwnd601OEYyyXpz/P1A9FmazyituZ3c/czZJROScZceekNDpI/RRBn0LDHtBGv OqKDur8lym3kinitZX7eO1cETmdvzx0= X-MC-Unique: MKO9rYZaOWeMMmBAODPT_A-1 X-MC-Unique: dlX-bC3fMUOS9Ka7CRsyfw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=we1oFVoxz+zBjlk8/HAe+SpQ8po3jHsyCR5ZbXpkoNI=; b=pCKQgtBXnjjvAwWHQptzT72ttjMl7iq1C9IbFHk6AKHMjjH1Rhf2oRDZTKmTrDnGZ+ mqz56fwWlgC77vexQE3TH7Y/3wz22QEtsOI5Wfx78zqGKkI0flxOOBw/GU3d5FEsRp6P 2HA0jpjwJsGWXci+dlJVhfxF+Oa+dxcHAsOvR92McTsKmiZoQm7HtVHhgda1XAYUk0dJ yVYOKOCu0LgBZht17hdcTdJB+TzNxCM6GpyRDp+bm/pW7+T2qdvT7rAMWQrGFlH6tBW7 dCUREGQh9qMPd33DpAtz+QY5uDGVheWFNjOf1VPtuG0/Skfpnm4S3zyMjn8vQXhP2yrO s8cA== X-Gm-Message-State: ANhLgQ37tSSExZ4VxgeKKJaXla7Dm0nNduB6v2NFwjg8inlbF0FmNpiQ n64eStZAelvRg35Lay/Cpkxo+lcGk3M= X-Google-Smtp-Source: ADFU+vs7W2YOxRRvhfLHhU3m0asiao1PBWDsdq8cTbS/V1OF3Op0DzDcdj5U+B46ATUILtBTPDk3Sw== X-Received: by 2002:aa7:99d1:: with SMTP id v17mr6345282pfi.165.1585436579256; Sat, 28 Mar 2020 16:02:59 -0700 (PDT) From: Prathamesh Chavan To: libvir-list@redhat.com Subject: [PATCH] tools: variables clean-up in libvirt-guests script Date: Sun, 29 Mar 2020 04:32:52 +0530 Message-Id: <20200328230252.22328-1-pc44800@gmail.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 02SN36k0019729 X-loop: libvir-list@redhat.com Cc: mkletzan@redhat.com, Prathamesh Chavan X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 2 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Redeclared variables in script functions marked as local. Variables `guest_running` and `guests_shutting_down` in the functions 'guest_is_on` and `check_guests_shutdown` were untouched, as the functions returned values in these variables. Signed-off-by: Prathamesh Chavan --- I'm submitting this as my BiteSizedTask for GSoC'20 I've cc'd Martin Kletzander, as he is mentor for this task, and to ensure that the needful was done by me. After running `make check`, I received "PASS: 98 and SKIP: 7" as the result. Travis-ci build report can be found at [1]. For my project, 'Introducing job control to the storage driver', right now I'm going through the `/src/qemu/THREADS.txt` as well as previous work done by Tucker DiNapoli during GSoC'14, as well as the proposal of Taowei Luo for GSoC'15. Their email threads are surely helping me get a better picture of the project. Apart from this, please let me know if there is anything else, which could help me with this project. Thansk! [1]: https://travis-ci.org/github/pratham-pc/libvirt/builds/668209157 tools/libvirt-guests.sh.in | 104 +++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 50 deletions(-) diff --git a/tools/libvirt-guests.sh.in b/tools/libvirt-guests.sh.in index a881f6266e..90a18fee49 100644 --- a/tools/libvirt-guests.sh.in +++ b/tools/libvirt-guests.sh.in @@ -65,7 +65,7 @@ retval() { # If URI is "default" virsh is called without the "-c" argument # (using libvirt's default connection) run_virsh() { - uri=3D$1 + local uri=3D$1 shift =20 if [ "x$uri" =3D xdefault ]; then @@ -86,7 +86,7 @@ run_virsh_c() { # check if URI is reachable test_connect() { - uri=3D$1 + local uri=3D$1 =20 if run_virsh "$uri" connect 2>/dev/null; then return 0; @@ -103,8 +103,8 @@ test_connect() # --transient: list only transient guests # [none]: list both persistent and transient guests list_guests() { - uri=3D$1 - persistent=3D$2 + local uri=3D$1 + local persistent=3D$2 =20 list=3D$(run_virsh_c "$uri" list --uuid $persistent) if [ $? -ne 0 ]; then @@ -118,8 +118,8 @@ list_guests() { # guest_name URI UUID # return name of guest UUID on URI guest_name() { - uri=3D$1 - uuid=3D$2 + local uri=3D$1 + local uuid=3D$2 =20 run_virsh "$uri" domname "$uuid" 2>/dev/null } @@ -128,8 +128,8 @@ guest_name() { # check if guest UUID on URI is running # Result is returned by variable "guest_running" guest_is_on() { - uri=3D$1 - uuid=3D$2 + local uri=3D$1 + local uuid=3D$2 =20 guest_running=3Dfalse id=3D$(run_virsh "$uri" domid "$uuid") @@ -161,13 +161,13 @@ start() { return 0 fi =20 - isfirst=3Dtrue - bypass=3D - sync_time=3Dfalse + local isfirst=3Dtrue + local bypass=3D + local sync_time=3Dfalse test "x$BYPASS_CACHE" =3D x0 || bypass=3D--bypass-cache test "x$SYNC_TIME" =3D x0 || sync_time=3Dtrue while read uri list; do - configured=3Dfalse + local configured=3Dfalse set -f for confuri in $URIS; do set +f @@ -186,7 +186,7 @@ start() { =20 eval_gettext "Resuming guests on \$uri URI..."; echo for guest in $list; do - name=3D$(guest_name "$uri" "$guest") + local name=3D$(guest_name "$uri" "$guest") eval_gettext "Resuming guest \$name: " if guest_is_on "$uri" "$guest"; then if "$guest_running"; then @@ -217,17 +217,17 @@ start() { # was saved. suspend_guest() { - uri=3D$1 - guest=3D$2 + local uri=3D$1 + local guest=3D$2 =20 - name=3D$(guest_name "$uri" "$guest") - label=3D$(eval_gettext "Suspending \$name: ") - bypass=3D - slept=3D0 + local name=3D$(guest_name "$uri" "$guest") + local label=3D$(eval_gettext "Suspending \$name: ") + local bypass=3D + local slept=3D0 test "x$BYPASS_CACHE" =3D x0 || bypass=3D--bypass-cache printf '%s...\n' "$label" run_virsh "$uri" managedsave $bypass "$guest" >/dev/null & - virsh_pid=3D$! + local virsh_pid=3D$! while true; do sleep 1 kill -0 "$virsh_pid" >/dev/null 2>&1 || break @@ -251,15 +251,17 @@ suspend_guest() # was successfully shutdown or the timeout defined by $SHUTDOWN_TIMEOUT ex= pired. shutdown_guest() { - uri=3D$1 - guest=3D$2 + local uri=3D$1 + local guest=3D$2 =20 - name=3D$(guest_name "$uri" "$guest") + local name=3D$(guest_name "$uri" "$guest") eval_gettext "Starting shutdown on guest: \$name" echo retval run_virsh "$uri" shutdown "$guest" >/dev/null || return - timeout=3D$SHUTDOWN_TIMEOUT - check_timeout=3Dfalse + local timeout=3D$SHUTDOWN_TIMEOUT + local check_timeout=3Dfalse + local format=3D + local slept=3D if [ $timeout -gt 0 ]; then check_timeout=3Dtrue format=3D$(eval_gettext "Waiting for guest %s to shut down, %d sec= onds left\n") @@ -300,8 +302,8 @@ shutdown_guest() # was issued to libvirt to allow parallel shutdown. shutdown_guest_async() { - uri=3D$1 - guest=3D$2 + local uri=3D$1 + local guest=3D$2 =20 name=3D$(guest_name "$uri" "$guest") eval_gettext "Starting shutdown on guest: \$name" @@ -323,8 +325,8 @@ guest_count() # Result is returned in "guests_shutting_down" check_guests_shutdown() { - uri=3D$1 - guests_to_check=3D$2 + local uri=3D$1 + local guests_to_check=3D$2 =20 guests_shutting_down=3D for guest in $guests_to_check; do @@ -344,16 +346,16 @@ check_guests_shutdown() # a shutdown complete notice for guests that have finished print_guests_shutdown() { - uri=3D$1 - before=3D$2 - after=3D$3 + local uri=3D$1 + local before=3D$2 + local after=3D$3 =20 for guest in $before; do case " $after " in *" $guest "*) continue;; esac =20 - name=3D$(guest_name "$uri" "$guest") + local name=3D$(guest_name "$uri" "$guest") if [ -n "$name" ]; then eval_gettext "Shutdown of guest \$name complete." echo @@ -365,12 +367,14 @@ print_guests_shutdown() # Shutdown guests GUESTS on machine URI in parallel shutdown_guests_parallel() { - uri=3D$1 - guests=3D$2 - - on_shutdown=3D - check_timeout=3Dfalse - timeout=3D$SHUTDOWN_TIMEOUT + local uri=3D$1 + local guests=3D$2 + + local on_shutdown=3D + local check_timeout=3Dfalse + local timeout=3D$SHUTDOWN_TIMEOUT + local slept=3D + local format=3D if [ $timeout -gt 0 ]; then check_timeout=3Dtrue format=3D$(eval_gettext "Waiting for %d guests to shut down, %d se= conds left\n") @@ -382,7 +386,7 @@ shutdown_guests_parallel() while [ -n "$guests" ] && [ $(guest_count "$on_shutdown") -lt "$PARALLEL_SHUTDOWN" ]; = do set -- $guests - guest=3D$1 + local guest=3D$1 shift guests=3D$* if [ -z "$(echo $on_shutdown | grep $guest)" ] && @@ -394,9 +398,9 @@ shutdown_guests_parallel() sleep 1 =20 set -- $guests - guestcount=3D$# + local guestcount=3D$# set -- $on_shutdown - shutdowncount=3D$# + local shutdowncount=3D$# =20 if $check_timeout; then if [ $(($timeout % 5)) -eq 0 ]; then @@ -415,7 +419,7 @@ shutdown_guests_parallel() fi fi =20 - on_shutdown_prev=3D$on_shutdown + local on_shutdown_prev=3D$on_shutdown check_guests_shutdown "$uri" "$on_shutdown" on_shutdown=3D"$guests_shutting_down" print_guests_shutdown "$uri" "$on_shutdown_prev" "$on_shutdown" @@ -428,8 +432,8 @@ stop() { # last stop was not followed by start [ -f "$LISTFILE" ] && return 0 =20 - suspending=3Dtrue - if [ "x$ON_SHUTDOWN" =3D xshutdown ]; then + local suspending=3Dtrue + if [ "/x$ON_SHUTDOWN" =3D xshutdown ]; then suspending=3Dfalse if [ $SHUTDOWN_TIMEOUT -lt 0 ]; then gettext "SHUTDOWN_TIMEOUT must be equal or greater than 0" @@ -448,9 +452,9 @@ stop() { =20 eval_gettext "Running guests on \$uri URI: " =20 - list=3D$(list_guests "$uri") + local list=3D$(list_guests "$uri") if [ $? -eq 0 ]; then - empty=3Dtrue + local empty=3Dtrue for uuid in $list; do "$empty" || printf ", " printf %s "$(guest_name "$uri" "$uuid")" @@ -464,9 +468,9 @@ stop() { fi =20 if "$suspending"; then - transient=3D$(list_guests "$uri" "--transient") + local transient=3D$(list_guests "$uri" "--transient") if [ $? -eq 0 ]; then - empty=3Dtrue + local empty=3Dtrue for uuid in $transient; do if "$empty"; then eval_gettext "Not suspending transient guests on U= RI: \$uri: " @@ -563,7 +567,7 @@ rh_status() { # usage [val] # Display usage string, then exit with VAL (defaults to 2). usage() { - program_name=3D$0 + local program_name=3D$0 eval_gettext "Usage: \$program_name {start|stop|status|restart|"\ "condrestart|try-restart|reload|force-reload|gueststatus|shutdown}"; echo exit ${1-2} --=20 2.17.1