From patchwork Mon Jun 3 08:55:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dominique Martinet X-Patchwork-Id: 1942760 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=kZ2cWTM7; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2607:f8b0:4864:20::b3f; helo=mail-yb1-xb3f.google.com; envelope-from=swupdate+bncbcwivbv7sugrbluk62zamgqet3sevui@googlegroups.com; receiver=patchwork.ozlabs.org) Received: from mail-yb1-xb3f.google.com (mail-yb1-xb3f.google.com [IPv6:2607:f8b0:4864:20::b3f]) (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 4Vt6yq23yZz20W0 for ; Mon, 3 Jun 2024 18:56:19 +1000 (AEST) Received: by mail-yb1-xb3f.google.com with SMTP id 3f1490d57ef6-dfa74682897sf4211023276.2 for ; Mon, 03 Jun 2024 01:56:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717404975; cv=pass; d=google.com; s=arc-20160816; b=HHm3jaWNDmXaNuf+AURUP7ho+/70xl6n0hPNiPJagEZ7PXqwthw1NgJlTj9M161NKo eY0m4z4J0Xdq+TkzSgjcCcfGMmxs7lJGI7DsEh2SgjSVvxxoLKzA1Fxle1frhvTN7r/U zCEDq6FddG/e8frVMRzEhewmqlp8Oi3UOY9CaePSEMnPmJkob9Xe+wFZpI13kETNRHlQ I0TYeSSflf8lnWYCSW4v6+VdNCaBqPhhsbVLEQlSYezIfTbUgAFrDrFm5zY7dOrKUTof m7hCAdBz4JpWxe8s2LHN/QjFDAxliSaJj0eWfqVZOKMCmGa5sm95HXPAszpkNu1cRn5U 8tjg== 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:references:in-reply-to :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=3pSLv/W//xwcKHSU/WF5evngccQ2ynXxwi6xGfb2lAw=; fh=RLEZtH0WctQlWUtXQHxadeo29nX3DgNAr2BnbPGuJws=; b=m7ePoRVZVi3ZpnmcSEQTBnXDPvD8Kv4BR3XD7jNAICISDcovKZZYbDGZ6743QM5ohL hhnJfZ7lkh//QmbvWlTXo7DHeC+i5P6dZg0JsyYdv7mefXS5YdxqscGS0NpOATH+DUot wbbSWX8Sabe1txqF92deWW2YrqjaPJPN5uJoiAbKMpz4fltIi7vdGYwUSYXpqQodGBdO mo45rAX2pqW/P3vF5/aKKB9lukQTFsfYZGPPqI/+RYLlVHQXhAYOGtoBkw/1CCaBjNXm EIZNBU/GNRpzCRipp3gGcfzAqH1oSLlpzvVOqHxpZ8DliukSZoLZC5y2DcS9b5DOzHw9 +qxA==; darn=patchwork.ozlabs.org ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@atmark-techno.com header.s=gw2_bookworm header.b=LGhNQNvG; dkim=pass header.i=@atmark-techno.com header.s=google header.b=Y7tcFr1Y; spf=pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) smtp.mailfrom=dominique.martinet@atmark-techno.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=atmark-techno.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20230601; t=1717404975; x=1718009775; 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:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:sender:from:to:cc:subject:date:message-id :reply-to; bh=3pSLv/W//xwcKHSU/WF5evngccQ2ynXxwi6xGfb2lAw=; b=kZ2cWTM74GkWODLVvFR27u+jXEwoKEMar6FxaWT1lueeBBRiA42461dbTPvHcF3FGP dmsnjynus4k5WhPRXYmdQUBfYhQo+gYbN6tiEj3QNIqzA9w2LYKkSy4MwkTxvnD9H8j7 Sda6EpHY7Tie20FAmrDLkI7naFTd/OR2nmq1bEdixZPI+8+AVkAnuzMa9SS1888tV7Il H6I/0P86beFXxs0pqM4WcV1nevH4GBRVUjpn+ZX9Uk8PTFe6ZQmp+vZX9labpZKhF+74 41WJtJOKS+WdMFp9eKS9VQT0dLIW/NCF3vzDu7jO6y3ehvi/y3nQvhTPVffKpo1dTSHB 1acQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717404975; x=1718009775; 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: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=3pSLv/W//xwcKHSU/WF5evngccQ2ynXxwi6xGfb2lAw=; b=mZKekSDL3Oi9wc6wYAerSuGrLm9jDi8mYsslJgK1rdpZcRsexO679ov4zRowhm2IVM kbXGH1mA1skZhWt9MjqSj936zrrj6fagkXJ5k+sabvknT7kWpnD10T1uFLkK5QzzuTdR 8O/aU7K2dDTjz+J9MuFYESl1Cg9Y/i1wSe4aolD1UCTRx/64aXjPjwG5//4/pfuVR+kr e1A0NGwBQuWQAJ+9QkoXI468Cewk794yQY9tJ6TddEpJSdycLuaW4kCx0J3yszh2sxLz gjP7P5wH62riKI5b1uO64VkhaacvB9R8LrW568tppNpnNrmQfuxlLpkMf3OeZvCZ22Ke vmWw== Sender: swupdate@googlegroups.com X-Forwarded-Encrypted: i=2; AJvYcCW6uHQY0U2iwf74tThFj5mNJaGZq0/oIi5RJ0FdxuPtiaoKALUvPYp1mKjYPngQhuZNVNihqy7ZvXHZ1y9fQGI4gFZsiPoNtbrJtnq/PA== X-Gm-Message-State: AOJu0YyX+Ft4D326lcLoJM0DXy1KuXCVH2IdtNZ8oPIsQiW4MCUqyndq Ue7SWAUAz2ESzs8L1HlHBbX6RuAkWXijX4zyeG51NGL6npAS+T2d X-Google-Smtp-Source: AGHT+IF3wIIGvqLUysvRwd0aIPa4JlfjX5DMD6Szq/MJOn0XK4alfmAn0uu90P1i6rV3Ca2bB7Klyw== X-Received: by 2002:a25:ea54:0:b0:dfa:56e1:9eb5 with SMTP id 3f1490d57ef6-dfa73d91471mr7994453276.48.1717404975069; Mon, 03 Jun 2024 01:56:15 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a25:df04:0:b0:dfa:7878:d377 with SMTP id 3f1490d57ef6-dfa7878d671ls608213276.1.-pod-prod-01-us; Mon, 03 Jun 2024 01:56:13 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUX7aTInPST6yZSsJRu/UdRF5uRBrBbEx/xZjZYAVxENBpEHLurAuEnVlOcSqsuzf8Cs0garFK8vsxqNt2s9UKkukdKYvocbfqc X-Received: by 2002:a81:6c4d:0:b0:622:cf30:8204 with SMTP id 00721157ae682-62c7948d85emr80210687b3.0.1717404973413; Mon, 03 Jun 2024 01:56:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717404973; cv=none; d=google.com; s=arc-20160816; b=ErEVYSgynBcWOMuXN/LZgIjR2IE2iaAKmuSeUaGEsdCGFAK4qhJKyXNZgvrmocdxII pOGU4/incvcgYgbO1XrwEtTPZntmOHDMu8BosZ8jZwU5tMKPglZ1pKXoJSKxHiHBlNZp jpB/4a/i0bCDZagzB3fCdCDPWMKcPqQiiZumCUXzehdO9Z0TedSL0H4/mOH311Lxk9oh vrWhx2DPDZJ1JHH4ndcKHnoRXRzIcdkgfoUNuqnK0df+nwxSx98XIfbafgcrVt5c1EKp Cx7z3ouvq5zUn1sOUB466HTNyMgJFVrvauLtlOhgGnjY5zEGYiKXsrx0MvD8JMt3etQB 78yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature; bh=6cAglcd5Fda5QMHtnwgL/R6GMQPZXqiZScKCrA3wqks=; fh=wWX5PNiJ8hKjZAdKkTegS4/cCEbJRqqvNLCrrMByleg=; b=pHSfZCKdelijxaulJzCgeM8VoHzZaypUuRwT1pSxwLRpx7xIthQA5XNgkmv36QJYyZ LjxwteMY1/AP2CtXAX+N8i5qZVfOvfIim44DfhjKBFBAU7ERx8NZRCLibpTl9kYQ5iOD U933XADv7OW+zy2CqPNMEh/OgMlFVd+zYInyNqgxfJWJSRsJitu4Ul2foqB7p6OtD28z FHc+zDIVMNmA6pvE3yzsGhz2+NFog6xGSaxlqmAWpHVlKZSYfWuDSko2LSTm5ECaBc6o hJL15lr2hoiDG/2O0HcyHknpycxUJImRI+JKIigTxuk/G7ywv815wttM3KFsx1QEjeQq 4O5g==; dara=google.com ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@atmark-techno.com header.s=gw2_bookworm header.b=LGhNQNvG; dkim=pass header.i=@atmark-techno.com header.s=google header.b=Y7tcFr1Y; spf=pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) smtp.mailfrom=dominique.martinet@atmark-techno.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=atmark-techno.com Received: from gw2.atmark-techno.com (gw2.atmark-techno.com. [35.74.137.57]) by gmr-mx.google.com with ESMTPS id 00721157ae682-62c766dbcfdsi3930887b3.3.2024.06.03.01.56.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 01:56:13 -0700 (PDT) Received-SPF: pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) client-ip=35.74.137.57; Received: from gw2.atmark-techno.com (localhost [127.0.0.1]) by gw2.atmark-techno.com (Postfix) with ESMTP id 0225BA92 for ; Mon, 3 Jun 2024 17:56:11 +0900 (JST) Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by gw2.atmark-techno.com (Postfix) with ESMTPS id B324B933 for ; Mon, 3 Jun 2024 17:56:09 +0900 (JST) Received: by mail-pl1-f199.google.com with SMTP id d9443c01a7336-1f6582eca2bso12785865ad.1 for ; Mon, 03 Jun 2024 01:56:09 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCUEkyfa5LM1hR+vYqq65adZ6vIB8rvyYqinECkIJIrSdVNADCA43rOHMiDykyMPUQ86vJuWQnlOqUW2gYba+Rmta931R6XORUDY X-Received: by 2002:a17:902:d385:b0:1f6:24f3:5a8d with SMTP id d9443c01a7336-1f636ffd610mr77855185ad.26.1717404968659; Mon, 03 Jun 2024 01:56:08 -0700 (PDT) X-Received: by 2002:a17:902:d385:b0:1f6:24f3:5a8d with SMTP id d9443c01a7336-1f636ffd610mr77855085ad.26.1717404968260; Mon, 03 Jun 2024 01:56:08 -0700 (PDT) Received: from pc-0182.atmarktech (178.101.200.35.bc.googleusercontent.com. [35.200.101.178]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f632367201sm59714805ad.96.2024.06.03.01.56.07 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Jun 2024 01:56:07 -0700 (PDT) Received: from [::1] (helo=pc-0182.atmark.tech) by pc-0182.atmarktech with esmtp (Exim 4.96) (envelope-from ) id 1sE3U6-009riT-0d; Mon, 03 Jun 2024 17:56:06 +0900 From: Dominique Martinet To: stefano.babic@swupdate.org, swupdate@googlegroups.com Cc: Dominique Martinet Subject: [swupdate] [PATCH RFC 3/9] copyfile cleanup: use copyimage when we can Date: Mon, 3 Jun 2024 17:55:56 +0900 Message-Id: <20240603085602.2351411-4-dominique.martinet@atmark-techno.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240603085602.2351411-1-dominique.martinet@atmark-techno.com> References: <20240603085602.2351411-1-dominique.martinet@atmark-techno.com> MIME-Version: 1.0 X-Original-Sender: dominique.martinet@atmark-techno.com X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@atmark-techno.com header.s=gw2_bookworm header.b=LGhNQNvG; dkim=pass header.i=@atmark-techno.com header.s=google header.b=Y7tcFr1Y; spf=pass (google.com: domain of dominique.martinet@atmark-techno.com designates 35.74.137.57 as permitted sender) smtp.mailfrom=dominique.martinet@atmark-techno.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=atmark-techno.com 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: , There were a few handlers manually passing all the fields required for copyimage, use copyimage instead. lua was using img.checksum as a secondary hash, preserve this functionality by remembering the old img.checksum instead of passing a different checksum pointer. There is no intended functional change. Signed-off-by: Dominique Martinet --- corelib/lua_interface.c | 38 ++++++++------------------------------ handlers/delta_handler.c | 13 +------------ handlers/rdiff_handler.c | 13 +------------ 3 files changed, 10 insertions(+), 54 deletions(-) diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c index 03b74aed1cf2..10af0760c5f9 100644 --- a/corelib/lua_interface.c +++ b/corelib/lua_interface.c @@ -388,7 +388,7 @@ static int l_copy2file(lua_State *L) } struct img_type img = {}; - uint32_t checksum = 0; + uint32_t image_checksum = img.checksum; table2image(L, &img); if (check_same_file(img.fdin, fdout)) { @@ -397,18 +397,7 @@ static int l_copy2file(lua_State *L) lua_pushstring(L, "Output file path is same as input file temporary path"); goto copyfile_exit; } - int ret = copyfile(img.fdin, - &fdout, - img.size, - (unsigned long *)&img.offset, - img.seek, - 0, /* no skip */ - img.compressed, - &checksum, - img.sha256, - img.is_encrypted, - img.ivt_ascii, - NULL); + int ret = copyimage(&fdout, &img, NULL /* default write callback */); update_table(L, &img); lua_pop(L, 1); @@ -417,10 +406,10 @@ static int l_copy2file(lua_State *L) lua_pushstring(L, strerror(errno)); goto copyfile_exit; } - if ((img.checksum != 0) && (checksum != img.checksum)) { + if ((image_checksum != 0) && (image_checksum != img.checksum)) { lua_pushinteger(L, -1); lua_pushfstring(L, "Checksums WRONG! Computed 0x%d, should be 0x%d\n", - checksum, img.checksum); + img.checksum, image_checksum); goto copyfile_exit; } @@ -463,24 +452,13 @@ static int l_istream_read(lua_State* L) luaL_checktype(L, 2, LUA_TFUNCTION); struct img_type img = {}; - uint32_t checksum = 0; + uint32_t image_checksum = img.checksum; lua_pushvalue(L, 1); table2image(L, &img); lua_pop(L, 1); - int ret = copyfile(img.fdin, - L, - img.size, - (unsigned long *)&img.offset, - img.seek, - 0, /* no skip */ - img.compressed, - &checksum, - img.sha256, - img.is_encrypted, - img.ivt_ascii, - istream_read_callback); + int ret = copyimage(L, &img, istream_read_callback); lua_pop(L, 1); update_table(L, &img); @@ -491,10 +469,10 @@ static int l_istream_read(lua_State* L) lua_pushstring(L, strerror(errno)); return 2; } - if ((img.checksum != 0) && (checksum != img.checksum)) { + if ((image_checksum != 0) && (image_checksum != img.checksum)) { lua_pushinteger(L, -1); lua_pushfstring(L, "Checksums WRONG! Computed 0x%d, should be 0x%d\n", - checksum, img.checksum); + img.checksum, image_checksum); return 2; } lua_pushinteger(L, 0); diff --git a/handlers/delta_handler.c b/handlers/delta_handler.c index 8e7faa0ead02..5ec243ee01d9 100644 --- a/handlers/delta_handler.c +++ b/handlers/delta_handler.c @@ -999,18 +999,7 @@ static int install_delta(struct img_type *img, goto cleanup; } - ret = copyfile(img->fdin, - &mem_fd, - img->size, - (unsigned long *)&img->offset, - img->seek, - 0, - img->compressed, - &img->checksum, - img->sha256, - img->is_encrypted, - img->ivt_ascii, - NULL); + ret = copyimage(&mem_fd, img, NULL /* default write callback */); if (ret != 0) { ERROR("Error %d copying zchunk header, aborting.", ret); diff --git a/handlers/rdiff_handler.c b/handlers/rdiff_handler.c index e01a127bce50..3b01519ce80a 100644 --- a/handlers/rdiff_handler.c +++ b/handlers/rdiff_handler.c @@ -337,18 +337,7 @@ static int apply_rdiff_patch(struct img_type *img, rs_trace_to(rdiff_log); rdiff_state.job = rs_patch_begin(base_file_read_cb, rdiff_state.base_file); - ret = copyfile(img->fdin, - &rdiff_state, - img->size, - (unsigned long *)&img->offset, - img->seek, - 0, /* no skip */ - img->compressed, - &img->checksum, - img->sha256, - img->is_encrypted, - img->ivt_ascii, - apply_rdiff_chunk_cb); + ret = copyimage(&rdiff_state, img, apply_rdiff_chunk_cb); if (ret != 0) { ERROR("Error %d running rdiff job, aborting.", ret); goto cleanup;