From patchwork Thu Apr 7 07:09:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 1614259 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20210112 header.b=BbZYnivx; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::338; helo=mail-wm1-x338.google.com; envelope-from=swupdate+bncbcxploxj6ikrbmu4xkjamgqex2fhcxi@googlegroups.com; receiver=) Received: from mail-wm1-x338.google.com (mail-wm1-x338.google.com [IPv6:2a00:1450:4864:20::338]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KYsvY4LWtz9sGJ for ; Thu, 7 Apr 2022 17:09:44 +1000 (AEST) Received: by mail-wm1-x338.google.com with SMTP id r64-20020a1c2b43000000b0038b59eb1940sf3009251wmr.0 for ; Thu, 07 Apr 2022 00:09:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1649315378; cv=pass; d=google.com; s=arc-20160816; b=vdyTjl612lLuleyKIqbbTyGaGrKl2WC4YXSMF7L9smZWuqowMSUSO/6vSYDFUgmWj2 ruUT+cfz2vTIx6CStY7UnLnHWpAG5j1MICl5PY/JtaGpaIbZtNgM9K2AHpqQYOPgGe6x iVpYlzj2C5+u4h9xK16RN1z7+hO+GfifeOoJLq0cA0uxi1v6E+SexqlBbyfEE7oG4KNY uJ5r4DaB1e1cQYFLJdcBdTaIGFBAGSL444RIC30WFUq2HbsIwZbNBKhv0WRPd+6/OqtJ lJbZnZT0G67rnwWgwIDrhBNpNGIhT1c2GJxzxw7wlLJZPeND+q3vPmH/PXp5QGzJJNEr p2QA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:mime-version:message-id:date :subject:cc:to:from:sender:dkim-signature; bh=zGoYQQ6E/7DaPIHCRz1KC3dns4L1IfPJv4MR4IM2JwE=; b=MlFHHB2sIseJpPkBdgstWs3HBRmR1ahIDo+Fa1zd2rUMUCYhnfmoc4ZjHRNz40xOTr BT7IGlUfS7sAP81q3G3c+CMRJZuBL3spgPVwXHSkjhOWl2wbxW1NHxUwQV07FYxP4fYa ly2Xhjfatg2ZEHXMk7kOPux3i0CaeoaEEb9fsImoSkW7z4YWGbyPP17L9z1Kq/og6nn1 n2le+V8+gDMfXSbv1zm5lPNVs3X7AxsIgd9O0Rm9RnAWXZu/hV8fKrQNYaAkpg4e1vqq ZCT0KP6Kw3MyJrTK64L8CjIWz07WgCqCIXZJsEcIz5qpM2dw3mVvD5FH6aJObefrX+uh aEvA== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:mime-version :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=zGoYQQ6E/7DaPIHCRz1KC3dns4L1IfPJv4MR4IM2JwE=; b=BbZYnivxGI/twmqtNwdJZLzMzOJNpmQ1kZ4nSwwqNqPKDcH1OX9tdrHkJv9MoAaJYQ UHNTSJ7f2OXmSXK2hfoB4Dh0bRWQlY5HdPvbNaoVF/V25YzuGA+fqrHuQ5tPOKsUEuao TaDByn+EaNCxU3Vd3nV6IeLShAwICQZayhCsWFPoMOPvHCZNxCcRi4TOfYauJSis2uh6 BRt75DX5/aXy7dwoDzj0kGAtiCPIHTLm3bfC00RBJbLfgf63QKjCyW6sHysqLfVEnqLZ GtWCXee9A1MRmwHuhGEGNffh3vk/LpufHrcPD/143bnrEZPfMHpTo6PouGnQ15jVQHbR 8PUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=sender:x-gm-message-state:from:to:cc:subject:date:message-id :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post :list-help:list-archive:list-subscribe:list-unsubscribe; bh=zGoYQQ6E/7DaPIHCRz1KC3dns4L1IfPJv4MR4IM2JwE=; b=NQRk8B4Xw7sGj6krnDT+vCNmmWpr1Tm+Zlk57yQw8XI2AJYvFdwlcfEb2y7OtmENux apJlPgIph948TheRLB3SvmaWXMwRr1QAV6FOR4AnKHjnHDx3oXQnpZ/aZskCpfzdJm// /NfDUs1hs76GlqzD2MkNe4Keblvw4j7dgAiGmlAv/UEPs5Y+yZokzaKMw9gYKOswJG7q vtJC8LH2glGRNVpO42+g1A286a+vCqECnvKfoghrLWaruDvjSzTO4K7Y/nNKng+xf4eP ppKiHv/OR7kTf0OIFT4Y8Tf02HMxssJy7KoEa9IlZqNHTYfHox0xAAsW8EJnu2/KeZ9h xEtA== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOAM530eHRwWGwqhV2kj0unCbgAOmqPdywi7FoSHPwnn+bpVGLBC6TyF 5EDCZ1xEX76DKBgYwBab0AI= X-Google-Smtp-Source: ABdhPJxh/YeiZ0aNgznXx+u8gc8QH/GB+38Vry9SyMNt8+u1IIwRiXum6VzpEcQoSda4B4VtxYYLUA== X-Received: by 2002:a05:600c:190e:b0:38c:b1ea:f4ac with SMTP id j14-20020a05600c190e00b0038cb1eaf4acmr10731533wmq.70.1649315378563; Thu, 07 Apr 2022 00:09:38 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a05:600c:4e01:b0:38c:9f99:b05 with SMTP id b1-20020a05600c4e0100b0038c9f990b05ls3948874wmq.1.canary-gmail; Thu, 07 Apr 2022 00:09:37 -0700 (PDT) X-Received: by 2002:a05:600c:5113:b0:38d:d8f:67e9 with SMTP id o19-20020a05600c511300b0038d0d8f67e9mr10675720wms.107.1649315377717; Thu, 07 Apr 2022 00:09:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649315377; cv=none; d=google.com; s=arc-20160816; b=KTCk+TF6WAVM/sU3E0EZKCgGmJsb7Ipz188ugwldLPJODEziYicwW2HJS3i3Rm1Z55 IwaKOna+lY3MPcTGOs8HyK+q4WywYb3Pjxk82sSOqqOvG3KIh2jT+EVaiqnZFGmkFNhh UxK1llfOT3vEXpIAIz5jxMONKSZjmWXInjznfMbsIynvMFjBjpLoNeF/ZgqNSKuYdMS3 b0VrIApCY+uPUlrZ1j+7btS/oafuA818F3K50ttRFG8krHoQDNXeh35ei2PC4M4/GTZz V5mZ2Ji5SjJQdirlPZxf9HbTI1T4WEQmHBS5iY1l+zb+5ZWfcSCNi8cGzn3w9KrjAkos p3dQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from; bh=7iKBnPUem/Avn9ja+e7LjVzfHJ+b3wz6nSUWBAuHbA0=; b=qdGW1dvk00gYP5K6mhnftlZ5J928s+IydrVmeBJtPKJzD180iDmuJZ5fDlLxDi37Cz lP5OI12DHUY1MO3I/vnoy3H0ahnvl9L4IbviE+wKLqCML81HHJgKeOUowtmpgf/9wKsO Il5gjNdGt9kFdqAyibLrc8BwnOqxzY5XNsfItHY1di4iht8yzqoTWrkslv74l02uAFgC Nav0bfMT/vcrM4Loj518IOzDVzmfP2h9922o3qFncWpcIZvdY17u6kq+H5iVeL68uG82 T3S++besDBlEes4lIXnoKGJ+3W8MS1GJ+R6T7jSKR5TzrFGcBajao3dbVs/YPk6ern+Y DRzA== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Received: from mail-out.m-online.net (mail-out.m-online.net. [212.18.0.9]) by gmr-mx.google.com with ESMTPS id c2-20020a05600c0a4200b0038cac42709csi69874wmq.1.2022.04.07.00.09.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Apr 2022 00:09:37 -0700 (PDT) Received-SPF: neutral (google.com: 212.18.0.9 is neither permitted nor denied by domain of sbabic@denx.de) client-ip=212.18.0.9; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 4KYsvP3SQGz1r1Mk; Thu, 7 Apr 2022 09:09:37 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 4KYsvP3HxRz1qqkJ; Thu, 7 Apr 2022 09:09:37 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id ZijcqYy6d4lt; Thu, 7 Apr 2022 09:09:36 +0200 (CEST) Received: from babic.homelinux.org (host-88-217-136-221.customer.m-online.net [88.217.136.221]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPS; Thu, 7 Apr 2022 09:09:35 +0200 (CEST) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 55D5F4540B28; Thu, 7 Apr 2022 09:09:35 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id z9c_ayJDU-K8; Thu, 7 Apr 2022 09:09:32 +0200 (CEST) Received: from paperino.fritz.box (paperino.fritz.box [192.168.178.48]) by babic.homelinux.org (Postfix) with ESMTP id E05374540789; Thu, 7 Apr 2022 09:09:32 +0200 (CEST) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH V2] Set ustate when an update is started Date: Thu, 7 Apr 2022 09:09:31 +0200 Message-Id: <20220407070931.310272-1-sbabic@denx.de> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Original-Sender: sbabic@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 is neither permitted nor denied by domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , ustate is just set after an update with the result, but it was foreseen to set it to IN_PROGRESS, too, when an update runs. This information is really stored in the marker (recovery_status bootloader variable). However, the two variables are not set in an atomic way because they are used in different use cases (recovery_status in single-copy strategy). Align ustate to recovery_status, and set it when an update is started. A power-cut during an update can be detected by examining the value of the variable and this can be useful in some use cases (reporting a failed update due to a power-cut). Factorize code to set the variables in a separate function to make the code more readable. Signed-off-by: Stefano Babic --- Changes since V1: - spelling in commit message core/stream_interface.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/core/stream_interface.c b/core/stream_interface.c index 1c9853d..57a3192 100644 --- a/core/stream_interface.c +++ b/core/stream_interface.c @@ -495,6 +495,23 @@ no_copy_output: return ret; } +static bool update_transaction_state(struct swupdate_cfg *software, update_state_t newstate) +{ + if (!software->parms.dry_run && software->bootloader_transaction_marker) { + if (newstate == STATE_INSTALLED) + bootloader_env_unset(BOOTVAR_TRANSACTION); + else + bootloader_env_set(BOOTVAR_TRANSACTION, get_state_string(newstate)); + } + if (!software->parms.dry_run + && software->bootloader_state_marker + && save_state(newstate) != SERVER_OK) { + WARN("Cannot persistently store %s update state.", get_state_string(newstate)); + return false; + } + return true; +} + void *network_initializer(void *data) { int ret; @@ -605,34 +622,20 @@ void *network_initializer(void *data) * must be successful. Set we have * initiated an update */ - if (!software->parms.dry_run && software->bootloader_transaction_marker) { - bootloader_env_set(BOOTVAR_TRANSACTION, get_state_string(STATE_IN_PROGRESS)); - } + update_transaction_state(software, STATE_IN_PROGRESS); notify(RUN, RECOVERY_NO_ERROR, INFOLEVEL, "Installation in progress"); ret = install_images(software); if (ret != 0) { - if (!software->parms.dry_run && software->bootloader_transaction_marker) { - bootloader_env_set(BOOTVAR_TRANSACTION, get_state_string(STATE_FAILED)); - } + update_transaction_state(software, STATE_FAILED); notify(FAILURE, RECOVERY_ERROR, ERRORLEVEL, "Installation failed !"); inst.last_install = FAILURE; - if (!software->parms.dry_run - && software->bootloader_state_marker - && save_state(STATE_FAILED) != SERVER_OK) { - WARN("Cannot persistently store FAILED update state."); - } } else { /* * Clear the recovery variable to indicate to bootloader * that it is not required to start recovery again */ - if (!software->parms.dry_run && software->bootloader_transaction_marker) { - bootloader_env_unset(BOOTVAR_TRANSACTION); - } - if (!software->parms.dry_run - && software->bootloader_state_marker - && save_state(STATE_INSTALLED) != SERVER_OK) { + if (!update_transaction_state(software, STATE_INSTALLED)) { ERROR("Cannot persistently store INSTALLED update state."); notify(FAILURE, RECOVERY_ERROR, ERRORLEVEL, "Installation failed !"); inst.last_install = FAILURE;