From patchwork Mon Oct 16 16:57:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 1849481 X-Patchwork-Delegate: sbabic@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.a=rsa-sha256 header.s=20230601 header.b=U5S2KPUU; dkim-atps=neutral Authentication-Results: legolas.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+bncbaabbcwxwwuqmgqegfgq6da@googlegroups.com; receiver=patchwork.ozlabs.org) 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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4S8Nb44KjCz20Vq for ; Tue, 17 Oct 2023 03:57:52 +1100 (AEDT) Received: by mail-wm1-x338.google.com with SMTP id 5b1f17b1804b1-4077e9112b4sf12207155e9.2 for ; Mon, 16 Oct 2023 09:57:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697475467; cv=pass; d=google.com; s=arc-20160816; b=As/Z6DPjj2G96KZbAEb+8YItYUfFywrJTCkl/oX2noTVPyIWcCvq/0QXrpN5Br3Rp0 Gw3jko8ev0uXREH8FzQMGHmwTpBrJ8P839eq9+xTGvZX1Ed2l0OYj1fNmlRTev8HvpQC PP3fccGO+aFlVInJIUuaFL8X/djDWWe6RpE+YZBZC+bU+Pg/gTbZJnrtkQs/5Z9DMuwM 6RKQPErtB6L1AuR/vbyCp4+waFuBHXkPVT6/ENYTRNjI4khz/ycCiFOBfKGRBSoCeJR+ I81SAod5kRgcG4sdGWpS+nCCYb5ZLH/O7E9+ShwrBxxRnIEuuRU36KglGqO8vUzBRjhO L9cw== 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:ui-outboundreport:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=LhTI4QzhMLC+GHKTc5jX8aaer3wda/8Eij0wTO+StoI=; fh=TiEWcqMcKpHk5s7uErzpntoONrNfOXwKpI5P8bIlggk=; b=zUAGoPgFEpqcg1wvluKzB9yI/gcDrfjsNhkjF+bqNIRgRz/O8EKDq1HNNqFR8z+nRY uOdC+exeQ1AX0CTwGwbjSaPVKW3zGRjURc9nQYuJdBSiff7ImACs5f9nvn25QaFO8iEo IVvqMLNUyaYtI/Qz1NNwWErk7/Rd+hI+Xb44sZK4Q8pfHb9k361zW+Tc7/cysjVNl8iQ BP+pzVD9kPWimoCRNlWdiZyb8q+jgKHX7KyzXlBcEZ9CmBCkAh+yQX+7PqcmtxQxcgVT NGkjKEChj8ucEMBLJnoKSP4T0SZRdKiHUC/hFxBO5XPsrPy/e96nzkI2Y03mlxCJ5ra7 E+DA== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of stefano.babic@swupdate.org designates 217.72.192.73 as permitted sender) smtp.mailfrom=stefano.babic@swupdate.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20230601; t=1697475467; x=1698080267; darn=patchwork.ozlabs.org; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:x-original-authentication-results :x-original-sender:ui-outboundreport:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:sender:from:to:cc :subject:date:message-id:reply-to; bh=LhTI4QzhMLC+GHKTc5jX8aaer3wda/8Eij0wTO+StoI=; b=U5S2KPUUG4VcLwKwKbopS9W8YCayQiFbqcrNU3s0tLcvyjrBIL4HSd8g3mv3KuPZO6 nyu8tmT/8QZIvKkmAYP/1OZLQPPbLpAGu4XlFO5jtH0qxxAl6sfv1a8VVmztS+SUjNVM kNZE90W2z+DGoGRP9QrpbhZyd/1VaX9+VfX1k7mYfAie6glaLXCnVodP1iGeTVn+IfPB aEQ+IjqfzeDEhrtxB1IiearS9G5OPdTZPF+oDxEuglewW9JbGUPHJ+70xkXJCTCU/Wpt XmO4BpXpK7fbz3LFV35BLqUESJ/2jQEgU7VBincNGfrXjaPxUygAEqtjEnAYBMSJzB7n 9hLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697475467; x=1698080267; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender :ui-outboundreport:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:x-beenthere:x-gm-message-state:sender:from :to:cc:subject:date:message-id:reply-to; bh=LhTI4QzhMLC+GHKTc5jX8aaer3wda/8Eij0wTO+StoI=; b=L4V70JOedlKhi/5fHrXjlqDCQNNkDVzrSpFQYv6r1DyaR2VHpo0wNyZQvH1MWjAYm5 /HbNrn8MIZUSXg7dx6e4N3kM/3GAlIU0exT4rwr/mEVVj6BDOCCBVSHQSgPBBLCwFwVS 76WO1X5z8a6DEtA4WbPu4nYR4zvocuj9lub7ytVvYsHDvzPydVgxl9WWKr0ApuDbgqQ2 8F23JJXzAR77ROCcUtM4JU9EpBWeytYKxPTag7K7BaMrBHYEKXVxtlLOjUVm9cdXqT1Q CKLZ4NzEL7q2CwyFsnOqYN7lVL9MhJuR64diFwPttcKEizRVPmIt10pENCO1G7XCl7CT nOCQ== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOJu0YzlZNKSt7earp1qpK7I1LNtOF9nlS5/egqM2J7+r8KwqrzP379P OQ5Mp3HPjvYFoIL6qByvTUY= X-Google-Smtp-Source: AGHT+IGrvTFkMKDNVo++D3zF52dmWAs4hpHRdsaNGsWJ11y3ISHWN9y2DMsT6Xwj8J/B/FV2hM8oxg== X-Received: by 2002:a05:600c:2949:b0:405:82c0:d9d9 with SMTP id n9-20020a05600c294900b0040582c0d9d9mr30370974wmd.41.1697475466575; Mon, 16 Oct 2023 09:57:46 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a05:600c:1c8b:b0:404:76b3:f017 with SMTP id k11-20020a05600c1c8b00b0040476b3f017ls1128603wms.2.-pod-prod-06-eu; Mon, 16 Oct 2023 09:57:45 -0700 (PDT) X-Received: by 2002:a05:600c:2218:b0:406:535a:f558 with SMTP id z24-20020a05600c221800b00406535af558mr31031363wml.10.1697475465052; Mon, 16 Oct 2023 09:57:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697475465; cv=none; d=google.com; s=arc-20160816; b=uXtSH+Qjzo+NwNRJ32s/tlk8hQeznxSw8KTSazbzhLWKmwFlkvY4jAS9YrC6pIPlFE S7exOp0xRiSp3qhpurSiuDztbcS+8f1cpDQNbR1Bf1GAzoFddxCsjWl93vFt5L99lqY2 r/gRklMBELuxKVGGSaCtsdwnwTEkXCyjdeFY6V9Hr1aZsFYI2C91lIBUD3ZYQ/QDfcmM hrmZdlSC82AR5fb176rOcFRUFdU/NraT5KegeSYEkkSqBhrbIKiMRYHdOQ7O3tx1qvFO ApAljQrVFxPblx746g57h+Gch7fWp/BmdD5pvYc4mDIUxc/kp1tqKUdFIQ+PSWmFX3VD OgnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=ui-outboundreport:content-transfer-encoding:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from; bh=xeNOCsu6dnsuFlex0F7JTcBfb6aGw8tvCkoYWpHFlos=; fh=TiEWcqMcKpHk5s7uErzpntoONrNfOXwKpI5P8bIlggk=; b=Snyg0rPYktADSVSbyNqCJmdUy77kGyHpgUaceDgiRkP97T0BRMbpXpIsFIJSA3GJfr GKDv/OujTLbZpcNub1BMj97pWT1YkFliZUvozKE0NXKIlMXZMzxyTrfRvp/gAf8AF/gC RYQEM5lqudQzq5BqLH6EpNi9Mda7bnoGyEu5PbZ8N0Pd+XNq4mPfu23CGwq2kzm70wl8 dCoGyPXCyG0RisRnJrspl9bSVUr0MrxQywQjrwbaWD5pCsvGNZ67zVZmsX2rHugfX0jv 8MOF1uM5O2YG8yO5MyMc+vSqtt3YD6/kn5lCfVmXaHTzWYEU3ig+b+kimVVXdNg3n460 5M8g== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of stefano.babic@swupdate.org designates 217.72.192.73 as permitted sender) smtp.mailfrom=stefano.babic@swupdate.org Received: from mout.kundenserver.de (mout.kundenserver.de. [217.72.192.73]) by gmr-mx.google.com with ESMTPS id v6-20020a5d59c6000000b0032c8861a1d1si908451wry.4.2023.10.16.09.57.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 09:57:45 -0700 (PDT) Received-SPF: pass (google.com: domain of stefano.babic@swupdate.org designates 217.72.192.73 as permitted sender) client-ip=217.72.192.73; Received: from paperino.fritz.box ([88.217.136.221]) by mrelayeu.kundenserver.de (mreue109 [213.165.67.113]) with ESMTPSA (Nemesis) id 1N17gy-1rYnti2bpC-012Zm0; Mon, 16 Oct 2023 18:57:44 +0200 From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 08/12] hawkbit: use stored action_id instead of current Date: Mon, 16 Oct 2023 18:57:36 +0200 Message-Id: <20231016165740.1374614-8-stefano.babic@swupdate.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231016165740.1374614-1-stefano.babic@swupdate.org> References: <20231016165740.1374614-1-stefano.babic@swupdate.org> MIME-Version: 1.0 X-Provags-ID: V03:K1:kYhQnlXfr82JRzpO5Zc5k3oedkotRMFazN7U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V5Uh0ymn5qux3O66eNpxYSDW35l9IP2NiX0OdLFWWT6nNUwweUeUAsF/JRRDLj+EDkstGl htzyCiIz0tw0uQA== X-Original-Sender: stefano.babic@swupdate.org X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of stefano.babic@swupdate.org designates 217.72.192.73 as permitted sender) smtp.mailfrom=stefano.babic@swupdate.org 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: , This fixes an old bug with the following use case: - an operator starts a rollout on Hawkbit - SWUpdate will start the update and it will reboots the board - before coming up, the operator has cancelled the rolback, and started a new rollout. This is identified by a different "action_id". - when board boots again, SWUpdate needs to send the fallback. It asks Hawkbit for the action_id, and Hawkbit will report the action_id of the new rollout. - SWUpdate sends the feedback according to the action_id retrieved from the Hawkbit server. It sends the result of the previous rollout as it was the result of the current, that did not run. - As result, Hawkbit thinks the device has new software, but the device has a previous version because it reported the wrong feedback. To fix this, SWUpdate will store the action_id as SWUpdate's variable. After a restart, SWUpdate will take the value stored previously instead of the value reported by Hawkbit. Signed-off-by: Stefano Babic --- suricatta/server_hawkbit.c | 56 +++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/suricatta/server_hawkbit.c b/suricatta/server_hawkbit.c index faff70da..9b71987c 100644 --- a/suricatta/server_hawkbit.c +++ b/suricatta/server_hawkbit.c @@ -31,6 +31,7 @@ #include "parselib.h" #include "swupdate_settings.h" #include "swupdate_dict.h" +#include "swupdate_vars.h" #define INITIAL_STATUS_REPORT_WAIT_DELAY 10 @@ -854,6 +855,24 @@ static server_op_res_t handle_feedback(int action_id, server_op_res_t result, return SERVER_UPDATE_AVAILABLE; } +static void get_action_id_from_env(int *action_id) +{ + /* + * Retrieve the action_id if SWUpdate stored it + * during the update + * The current action_id on the server can be different if the operator + * cancelled a rollout and started a new one while SWUpdate was + * restarting. + * Get the acction_id that corresponds to the done update if it was + * stored. + */ + char *action_str = swupdate_vars_get("action_id", NULL); + if (action_str) { + *action_id = ustrtoull(action_str, NULL, 10); + TRACE("Stored action_id from previous run: %d", *action_id); + free(action_str); + } +} server_op_res_t server_handle_initial_state(update_state_t stateovrrd) { @@ -900,11 +919,17 @@ server_op_res_t server_handle_initial_state(update_state_t stateovrrd) server_op_res_t result; /* - * Retrieving current action id + * Try to retrieve current action id */ + channel_data_t channel_data = channel_data_defaults; - result = - server_get_deployment_info(server_hawkbit.channel, &channel_data, &action_id); + result = server_get_deployment_info(server_hawkbit.channel, + &channel_data, &action_id); + + /* + * Get action_id from env, if any + */ + get_action_id_from_env(&action_id); result = handle_feedback(action_id, result, state, reply_result, reply_execution, 1, &reply_message); @@ -1061,6 +1086,17 @@ server_op_res_t server_process_update_artifact(int action_id, json_object_array_length(json_data_artifact); int json_data_artifact_installed = 0; json_object *json_data_artifact_item = NULL; + + char *action_id_str; + if (asprintf(&action_id_str, "%d", action_id) == ENOMEM_ASPRINTF) { + ERROR("OOM reached when saving action_id"); + return SERVER_EERR; + } + if (swupdate_vars_set("action_id", action_id_str, NULL)) { + WARN("Action_id cannot be stored, do yourself"); + } + free(action_id_str); + for (int json_data_artifact_count = 0; json_data_artifact_count < json_data_artifact_max; json_data_artifact_count++) { @@ -1955,12 +1991,18 @@ static server_op_res_t server_activation_ipc(ipc_message *msg) json_object *json_data = json_get_path_key( json_root, (const char *[]){"id", NULL}); - if (json_data == NULL) { - ERROR("Got malformed JSON: Could not find action id"); - DEBUG("Got JSON: %s", json_object_to_json_string(json_data)); + + int action_id = -1; + if (json_data) { + action_id = json_object_get_int(json_data); + } else { + get_action_id_from_env(&action_id); + } + + if (action_id < 0) { + ERROR("No action_id passed into JSON message and no action:_id in env"); return SERVER_EERR; } - int action_id = json_object_get_int(json_data); json_data = json_get_path_key( json_root, (const char *[]){"status", NULL});