From patchwork Mon Sep 11 04:38:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Hilliard X-Patchwork-Id: 1832103 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=eOpYe7LE; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=W752ryKw; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2607:f8b0:4864:20::13d; helo=mail-il1-x13d.google.com; envelope-from=swupdate+bncbcl4hcw73qcbbpnt7ktqmgqeoowk4yy@googlegroups.com; receiver=patchwork.ozlabs.org) Received: from mail-il1-x13d.google.com (mail-il1-x13d.google.com [IPv6:2607:f8b0:4864:20::13d]) (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 4RkYr44NBMz1yhL for ; Mon, 11 Sep 2023 14:38:27 +1000 (AEST) Received: by mail-il1-x13d.google.com with SMTP id e9e14a558f8ab-34bbbec7e6bsf25096245ab.2 for ; Sun, 10 Sep 2023 21:38:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1694407102; cv=pass; d=google.com; s=arc-20160816; b=C4dGuBvJtozXQW7NuZ4UUgKOj7VJMqRstoRq6K/p3KXcqQmJUvaPSy4WKIiw+0CQHS YCENuDyxRMEwbYjcddEnwBJkr5DDNuEsvjo+Cu5Wi6O0yv1/hZy68sgjN6cGzOBVodrW grlt+DaS7govOGEjX78mhNgrYvpCsL0pGMn0IxSMaiKHTQWna3Plege9hxaBa2CatPhf +6Khzxa4GPfVJQOaCyruInNfzhTx48cotcZJv1PoaUJ3X4MgR8DsmnbK0h8nh3eX8Wq3 Jy3y6j+fRnVpVd14ZY+435fGcrPBaqDI93gr6AN6SnFbxAKvAFDndxkG35LteKw4rgIO WERQ== 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:dkim-signature; bh=gJb+GiKbfh/Fe4rEwF1JQqOlNi2UvdIs6zUIoXrEqTI=; fh=KPrAw848PoyEggiIX82ubXk7sJG2UD396EeWf1FQVUo=; b=Wq4NRxmCFhBokqlW0kkFcde4sw6td3Nb0y+dlfgpa40HEI6qypP3q9VNLZcvjU4BlS mxl39spaQW8fBo9tUADHQBpHuj7qE7Xs+risGtPxqwx8MZBCgmFU7LWvsou6R++jDVot 6p91Qi6FixP0tG3ZGTwsmBHpVY2+gax+p3jnfzjm/Q87PTC/ptVAk/Qt5sPVi5FlOpmh /g/i+ucnI7kL5TCnsvUmfqGPvrXqfqcl+0SP5VsXs01OLwZhtE/zUGabCzNUgsH7DLtG 8bR0ELvapMGyNZtkwoFrSJk7L0MpurqIklSmOrW4nautRflXvbOMDbKV1i6gKqjd/dRS V6RA== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=TR9Q3McF; spf=pass (google.com: domain of james.hilliard1@gmail.com designates 2607:f8b0:4864:20::130 as permitted sender) smtp.mailfrom=james.hilliard1@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20230601; t=1694407102; x=1695011902; 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:message-id:date:subject:cc:to:from :sender:from:to:cc:subject:date:message-id:reply-to; bh=gJb+GiKbfh/Fe4rEwF1JQqOlNi2UvdIs6zUIoXrEqTI=; b=eOpYe7LEmk2x046pdpDyXhrfdNaH3bzrKRhIXXbVVaM7Sg/wZGSTrnrXyYMjqoJpnt 5KWYQ9V+T4cKcECFfe+Xs6fJF9D/qVED6LMx2ZAEIsMbHvdK8r+bCUsNO7b5NLp4yCOA ioWyyyW328R2gApS9yyAi9cgKwPYgT0+E222IumCdinoY3OlZfNr7i8PPckmQPEsphfI QNRYWD5Ov1oTBJ31iXSzBNj2AoynnHkVDxmwjmoCIOH0uXSDD2GFuVi6IxR1U5wz/2Bi +TIQ8AA++cEWOy4KwdP11566vO0exVD9701BzypRGvlDJbJcPqJ3dS1C789iWwrFJknE 211A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694407102; x=1695011902; 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:message-id:date:subject:cc:to:from :from:to:cc:subject:date:message-id:reply-to; bh=gJb+GiKbfh/Fe4rEwF1JQqOlNi2UvdIs6zUIoXrEqTI=; b=W752ryKwwHsGtuyj7JkW+pPHSY35pjIrpl+/733I8x3k0BZjZsK/nIftqFjtekNnGy bQDYHgQL/1d21hMyZO+N5PaQcg8Ail64oUwTzikpGKO7QwIR5KkEL0jZjLcyrd6IAjXS 1erBU1+piLNLE7l4aG/LARRCyZ1/025kdun2oWnLZCnm4BNPnMWU7sSGQY8GV1KzXy/W ywWwGS+dL65wL+Heodishq1q2hUIkmgRBc1FIfY7W4eH8zNYByO+I8jeK693JAsg3THv +BU3MQhK8N/3Sin6eiP74cGuqAaFIlvnFNiglnqojWLPKs22Qw2aPaB7FZeyT0kTFwBC fnZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694407102; x=1695011902; 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 :message-id:date:subject:cc:to:from:x-beenthere:x-gm-message-state :sender:from:to:cc:subject:date:message-id:reply-to; bh=gJb+GiKbfh/Fe4rEwF1JQqOlNi2UvdIs6zUIoXrEqTI=; b=fdGPuSFxZYK2WgsihgDUBVvaxlxqjfF5KsT+HmciflCUgTGu0FYw9It3m7kkCuyd4s PcjxzPMAC+43rd6mRUwqysns7pe5NWxMUtXbKOxt9WrQ7mw46DfkyCay7J3VgeY9sjgh SNuPRsPUulk8LgcociSS6LIJmZj3ltjTgQyPW82Dw82f4QG5NTEvZzTiyzsGS7uYT8I6 IyYGW+ukYaDl1kTDcOOqJ6N9N8/vD58q2aZixF3TzKQiCv+k5vft/7Sk2lU2uTNszqEm fKvUSF/4RVPsZWteymokZ+UW2ZV63Wlp6eiMp4vVsKrEvGLTzjUch2vt+Efsqh4/SWh1 3KiA== Sender: swupdate@googlegroups.com X-Gm-Message-State: AOJu0YzJbhnNcuBe+50vRuJozBfJpUmNHxvNmdjEnkxDdXq6dTx3RSty ScJioOZQ14Rv4MWGW0zARtc= X-Google-Smtp-Source: AGHT+IEXoDHcFyTmdJ7ZmmwX/6ailSjjYf16ThDeO3ojiZ7D/GwHY8AmKQmfgqItjXfy6NZkYqDwwg== X-Received: by 2002:a05:6e02:1a04:b0:346:f30:ad58 with SMTP id s4-20020a056e021a0400b003460f30ad58mr12358261ild.24.1694407102437; Sun, 10 Sep 2023 21:38:22 -0700 (PDT) X-BeenThere: swupdate@googlegroups.com Received: by 2002:a92:7613:0:b0:34f:219d:8985 with SMTP id r19-20020a927613000000b0034f219d8985ls913196ilc.2.-pod-prod-07-us; Sun, 10 Sep 2023 21:38:21 -0700 (PDT) X-Received: by 2002:a5d:834a:0:b0:795:8805:137e with SMTP id q10-20020a5d834a000000b007958805137emr10104275ior.10.1694407101289; Sun, 10 Sep 2023 21:38:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694407101; cv=none; d=google.com; s=arc-20160816; b=J5i97I+G/wyCMxdYcUYd/P4gzhRnBkVDD+Sd9n7TPZb/IIJytfJaI5/dAi40lD4dc1 uU4la9I1tGbQVLWcWubyD9xHFMguqq4J2HvXldG2AKDe8PJ8BhW+KXPT4s2pHnZrGRei +9zAIavMEMLnmoMkbHlV47fm1iLhGuQa343iYSccWVgUNrCydKWz0xW4CPmSmE5AW7GI ufbrVX8f3hXhi91fiUGD0qqcSHGSAcB8hEMoZZOmMCIn5g1a8NtVBNEUoyT7u+cOldTG XhF7+2G/3JFvwmCINMPnD8gsisAScGIgIIYB+GEqbFUZ2ltvBEGyNbZMXD7V97zCj9OS TwBw== 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:dkim-signature; bh=9By488IP6d3u5azA5I3KEKAzkJrt+FvngkYYNYw402k=; fh=KPrAw848PoyEggiIX82ubXk7sJG2UD396EeWf1FQVUo=; b=TPvd8PukDM9chad61UBGofOOzjq/8rwqJ27Qf5OwmAgi/JtAoiJGhzJxsa2miCuAK1 qKefLzt5oFd86ByM8bu+HoaTY6Nk033uWRpFGPgVP8OdmFv7azNo1qbn8oWWRmQr6eDN sHxIqaQjJP5TZXn52NoywEJUFvkMT+0V0tLbM3Xojxnwn5tjTbScHdobEFOQww18rECg RhcKcd0Fu+Enh2RnJ/zmYdgQzdeuwjdF47468264Vklpt4xVt667j7Nqva650X6EGYUq joFlxvVRiWyWQN00zO+Lyc2dHRmyXeOOGECq3Y01hDhaS9QwoNhqDKLlIQ77hNEsJLzj RWYQ== ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=TR9Q3McF; spf=pass (google.com: domain of james.hilliard1@gmail.com designates 2607:f8b0:4864:20::130 as permitted sender) smtp.mailfrom=james.hilliard1@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-il1-x130.google.com (mail-il1-x130.google.com. [2607:f8b0:4864:20::130]) by gmr-mx.google.com with ESMTPS id ay15-20020a5d9d8f000000b0079186e18eb9si869501iob.3.2023.09.10.21.38.21 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 10 Sep 2023 21:38:21 -0700 (PDT) Received-SPF: pass (google.com: domain of james.hilliard1@gmail.com designates 2607:f8b0:4864:20::130 as permitted sender) client-ip=2607:f8b0:4864:20::130; Received: by mail-il1-x130.google.com with SMTP id e9e14a558f8ab-34e2be5679dso15022285ab.1 for ; Sun, 10 Sep 2023 21:38:21 -0700 (PDT) X-Received: by 2002:a05:6e02:e09:b0:348:d5fc:fed with SMTP id a9-20020a056e020e0900b00348d5fc0fedmr7755995ilk.32.1694407100447; Sun, 10 Sep 2023 21:38:20 -0700 (PDT) Received: from james-x399.localdomain (97-118-182-107.hlrn.qwest.net. [97.118.182.107]) by smtp.gmail.com with ESMTPSA id f14-20020a92cb4e000000b0034cb0abb579sm2110145ilq.49.2023.09.10.21.38.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Sep 2023 21:38:19 -0700 (PDT) From: James Hilliard To: swupdate@googlegroups.com Cc: James Hilliard Subject: [swupdate] [PATCH 1/1] handlers: ubivol: add rename fallback for replace property Date: Sun, 10 Sep 2023 22:38:10 -0600 Message-Id: <20230911043810.2270507-1-james.hilliard1@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Original-Sender: james.hilliard1@gmail.com X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=TR9Q3McF; spf=pass (google.com: domain of james.hilliard1@gmail.com designates 2607:f8b0:4864:20::130 as permitted sender) smtp.mailfrom=james.hilliard1@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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: , The replace property currently requires the volume name to be replaced to have already been created, however this creates a problem for cases where we are doing an initial image installation but still want the replace behavior to function normally when the volume name already exists. To handle these cases simply rename the volume to the replace target instead of erroring out. Signed-off-by: James Hilliard --- handlers/ubivol_handler.c | 46 +++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/handlers/ubivol_handler.c b/handlers/ubivol_handler.c index f9acf2d..3c90b01 100644 --- a/handlers/ubivol_handler.c +++ b/handlers/ubivol_handler.c @@ -58,17 +58,20 @@ static struct ubi_part *search_volume_global(const char *str) * @vol2: pointer to ubi_vol_info pointer. Will be set to point to the * to-be-replaced volume in case a volume is found and the * request is legal. Otherwise it is set to NULL. + * @rename: pointer to new target volume name pointer. * * Return: 0 if replace valid or no replace found. Otherwise <0. */ static int check_replace(struct img_type *img, struct ubi_vol_info *vol1, - struct ubi_vol_info **vol2) + struct ubi_vol_info **vol2, + char **rename) { char *tmpvol_name; struct ubi_part *tmpvol; *vol2 = NULL; + *rename = NULL; tmpvol_name = dict_get_value(&img->properties, "replaces"); if (tmpvol_name == NULL) @@ -77,8 +80,9 @@ static int check_replace(struct img_type *img, tmpvol = search_volume_global(tmpvol_name); if (!tmpvol) { - ERROR("replace: unable to find a volume %s", tmpvol_name); - return -1; + INFO("replace: unable to find a volume %s, will rename", tmpvol_name); + *rename = tmpvol_name; + return 0; } /* check whether on same device */ @@ -128,6 +132,34 @@ static int swap_volnames(libubi_t libubi, return ubi_rnvols(libubi, masternode, &rnvol); } +/** + * rename_vol - rename the given volume + * @vol: volume + * @name: new volume name + * + * Return: 0 if OK, <0 otherwise + */ +static int rename_vol(libubi_t libubi, + struct ubi_vol_info *vol, + char *name) +{ + struct ubi_rnvol_req rnvol; + char masternode[64]; + + snprintf(masternode, sizeof(masternode), + "/dev/ubi%d", vol->dev_num); + + TRACE("replace: rename UBI volume %s to %s on %s", + vol->name, name, masternode); + + rnvol.ents[0].vol_id = vol->vol_id; + rnvol.ents[0].name_len = strlen(name); + strcpy(rnvol.ents[0].name, name); + rnvol.count = 1; + + return ubi_rnvols(libubi, masternode, &rnvol); +} + /** * check_ubi_alwaysremove - check the property always-remove for this image * @img: image information @@ -147,6 +179,7 @@ static int update_volume(libubi_t libubi, struct img_type *img, char node[64]; int err; char sbuf[128]; + char *rn_vol; struct ubi_vol_info *repl_vol; bytes = get_output_size(img, true); @@ -184,7 +217,7 @@ static int update_volume(libubi_t libubi, struct img_type *img, } /* check replace property */ - if(check_replace(img, vol, &repl_vol)) + if(check_replace(img, vol, &repl_vol, &rn_vol)) return -1; fdout = open(node, O_RDWR); @@ -215,6 +248,11 @@ static int update_volume(libubi_t libubi, struct img_type *img, if(err) ERROR("replace: failed to swap volume names %s<->%s: %d", vol->name, repl_vol->name, err); + } else if (rn_vol) { + err = rename_vol(libubi, vol, rn_vol); + if(err) + ERROR("replace: failed to rename %s to %s: %d", + vol->name, rn_vol, err); } close(fdout);