From patchwork Tue Mar 1 19:13:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 1599479 X-Patchwork-Delegate: zajec5@gmail.com 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; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=WpczUQKA; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=XX+t6NMf; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 4K7Rmh2ZtMz9sG3 for ; Wed, 2 Mar 2022 06:16:02 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=9HbNdzoxf9Fc4xQQT0C5R69BIQdf+kQl+QeJkxzTmPo=; b=WpczUQKA9l57oL RSc+RkakYBIBkSH0FXwrRxYHjKaXOzrKTgKGMMQ/Rsco7ZIaUPArVk2wkJHYWBblVDGDT/JjCEZnD x1HyY+gBSm6Z/8zE69+J5lwEyhZ/+sG9RUBrwnMGVTeiDmZdMgbdno5HcaF3xj+pKd2DEt8Q+QoD0 cr1+CTRCczhflvOFwNMKnr6Y6WTuufPG0pXVUB+6umCWNDeolFB/LHKzOoeYtM4fWLqmwjM/MCWyi b9YU2gPBpJ5tNnvaDg5/YivxX3e5aPNbRs0EZ4aqa+E9I+cCtcTaB49VTF0LgwJtTDsh1U6p8keH0 XwY4TQ07ZBpytrGi+KKA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nP7wL-000GFU-8u; Tue, 01 Mar 2022 19:13:41 +0000 Received: from mail-lf1-x131.google.com ([2a00:1450:4864:20::131]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nP7wH-000GEm-RF for openwrt-devel@lists.openwrt.org; Tue, 01 Mar 2022 19:13:39 +0000 Received: by mail-lf1-x131.google.com with SMTP id y24so28568783lfg.1 for ; Tue, 01 Mar 2022 11:13:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=cwYUsSH/ZBddgT3UVV6S8Xan3eIw/JFCane5TuDH4m8=; b=XX+t6NMfFHZgT3Oma7uxd1qNBgACHmlENc0pktv9B2k0gVIXemkBngKk5tzWkBxvM6 xJUuX/2xpH8QSQson0gv+Kpko5c4DZzQrEtlcTIr3Lh3ii0ughh5JgTXdLT/yBkOpxLA mvWwLEwM8yLcRtZweRiISj8DMmmLPKzvPLFv1S7PnRrXLHcum2TbXfi/wVBr0345vAUA wFS4pJSNrR9Rj8znhSB/qY0u96B6qFoO8vUay+CscMYtnXqm4VJPBYM7jPeXphyY6FDI BKtQDZ7K5WDJJIGGjvpc2mNSA677dr0FqHG34N1oTHCnJVDesP/PtOkRytxlkiLlZbpV C5Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=cwYUsSH/ZBddgT3UVV6S8Xan3eIw/JFCane5TuDH4m8=; b=gnYj/HFEXozC5TUD0/ZuFcHcFPI6+X46/rWqApJq4aXz+YeeADHftC6FOCipngvwcS v3fSZ0QGLjDvYACjG6KLoAPqdwI2W5j+pWyj24ghBiw2vdkOAe04rrkx9KUenYaD84LD im81oLvSggO5V+U9xIJ6rJ8PnxgGdqBRIjO1JI2T79InFqsronocdxm79Te5w1DI1HYO 4PYd9xWYTi0U47HGX/Ct9EvJFVPwQS5LySTd1i9htMYKzJnBiR9MctBSWfZ2Br/jypOX +RB2JyezpXKLJO+NVF7DOUcUDnBNUV4L99aJG1Scv+tL0JBNBrlcLtEkV1BzkvwMaDsS u9BQ== X-Gm-Message-State: AOAM533CDMAVnyuWzeN9vay871Qoczq6fAvfBh/SObFT7bSuOKx9dnnx 9zeeTfZxkVmtsx776ZWEZ6mIuRLNFbY= X-Google-Smtp-Source: ABdhPJzQ++qfZQJCzTcTxoB2ZKgqboeQgLCHDp3fUp+uJdtJsQGRmXBULJc7mHG8f9PfyBYDlaNP/A== X-Received: by 2002:a19:7b04:0:b0:443:add9:fdf5 with SMTP id w4-20020a197b04000000b00443add9fdf5mr16244704lfc.265.1646162015438; Tue, 01 Mar 2022 11:13:35 -0800 (PST) Received: from localhost.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id g1-20020a19e041000000b00443131b3efcsm1630113lfj.284.2022.03.01.11.13.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Mar 2022 11:13:35 -0800 (PST) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: openwrt-devel@lists.openwrt.org Cc: Koen Vandeputte , Richard Weinberger , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Subject: [PATCH] kernel: force atomic renames in ubifs Date: Tue, 1 Mar 2022 20:13:29 +0100 Message-Id: <20220301191329.22329-1-zajec5@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220301_111337_912936_4A00DC62 X-CRM114-Status: GOOD ( 15.90 ) X-Spam-Score: 0.1 (/) X-Spam-Report: =?unknown-8bit?q?Spam_detection_software=2C_running_on_the_sy?= =?unknown-8bit?q?stem_=22bombadil=2Einfradead=2Eorg=22=2C?= =?unknown-8bit?q?_has_NOT_identified_this_incoming_email_as_spam=2E__The_ori?= =?unknown-8bit?q?ginal?= =?unknown-8bit?q?_message_has_been_attached_to_this_so_you_can_view_it_or_la?= =?unknown-8bit?q?bel?= =?unknown-8bit?q?_similar_future_email=2E__If_you_have_any_questions=2C_see?= =?unknown-8bit?q?_the_administrator_of_that_system_for_details=2E?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_Content_preview=3A__From=3A_Rafa=C5=82_Mi=C5=82ecki_This_d?= =?unknown-8bit?q?eals_with_user-spaces_apps_that?= =?unknown-8bit?q?_don=27t_handle_all_syncing_correctly=2E_It_prevents_user_e?= =?unknown-8bit?q?nding_up_with_an_empty?= =?unknown-8bit?q?_file=2E_Signed-off-by=3A_Rafa=C5=82_Mi=C5=82ecki_---_=2E?= =?unknown-8bit?q?=2E=2E/510-ubifs-force-atomic-renames=2Epatch?= =?unknown-8bit?q?_=7C_46_+++++++++++++++++++_=2E=2E=2E/510-ubifs-force-atomi?= =?unknown-8bit?q?c-renames=2Epatch_=7C_46_+++++++++++++++++++?= =?unknown-8bit?b?IDIgZmlsZXMgY2hhbmdlZCwgOTIgaW5zZXJ0aW9ucyggWy4uLl0g?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_Content_analysis_details=3A___=280=2E1_points=2C_5=2E0_req?= =?unknown-8bit?q?uired=29?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_pts_rule_name______________description?= =?unknown-8bit?q?_----_----------------------_------------------------------?= =?unknown-8bit?q?--------------------?= =?unknown-8bit?q?_-0=2E0_RCVD=5FIN=5FDNSWL=5FNONE_____RBL=3A_Sender_listed_a?= =?unknown-8bit?q?t_https=3A//www=2Ednswl=2Eorg/=2C?= =?unknown-8bit?q?_no_trust?= =?unknown-8bit?b?IFsyYTAwOjE0NTA6NDg2NDoyMDowOjA6MDoxMzEgbGlzdGVkIGluXQ==?= =?unknown-8bit?b?IFtsaXN0LmRuc3dsLm9yZ10=?= =?unknown-8bit?q?_-0=2E0_SPF=5FPASS_______________SPF=3A_sender_matches_SPF_?= =?unknown-8bit?q?record?= =?unknown-8bit?q?_0=2E0_SPF=5FHELO=5FNONE__________SPF=3A_HELO_does_not_publ?= =?unknown-8bit?q?ish_an_SPF_Record?= =?unknown-8bit?q?_0=2E0_FREEMAIL=5FFROM__________Sender_email_is_commonly_ab?= =?unknown-8bit?q?used_enduser_mail?= =?unknown-8bit?q?_provider?= =?unknown-8bit?q?_=5Bzajec5=5Bat=5Dgmail=2Ecom=5D?= =?unknown-8bit?q?_0=2E2_FREEMAIL=5FENVFROM=5FEND=5FDIGIT_Envelope-from_freem?= =?unknown-8bit?q?ail_username_ends?= =?unknown-8bit?q?_in_digit?= =?unknown-8bit?q?_=5Bzajec5=5Bat=5Dgmail=2Ecom=5D?= =?unknown-8bit?q?_-0=2E1_DKIM=5FVALID=5FAU__________Message_has_a_valid_DKIM?= =?unknown-8bit?q?_or_DK_signature_from?= =?unknown-8bit?q?_author=27s_domain?= =?unknown-8bit?q?_-0=2E1_DKIM=5FVALID_____________Message_has_at_least_one_v?= =?unknown-8bit?q?alid_DKIM_or_DK_signature?= =?unknown-8bit?q?_0=2E1_DKIM=5FSIGNED____________Message_has_a_DKIM_or_DK_si?= =?unknown-8bit?q?gnature=2C_not_necessarily?= =?unknown-8bit?q?_valid?= =?unknown-8bit?q?_-0=2E1_DKIM=5FVALID=5FEF__________Message_has_a_valid_DKIM?= =?unknown-8bit?q?_or_DK_signature_from?= =?unknown-8bit?q?_envelope-from_domain?= X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org From: Rafał Miłecki This deals with user-spaces apps that don't handle all syncing correctly. It prevents user ending up with an empty file. Signed-off-by: Rafał Miłecki --- .../510-ubifs-force-atomic-renames.patch | 46 +++++++++++++++++++ .../510-ubifs-force-atomic-renames.patch | 46 +++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 target/linux/generic/pending-5.10/510-ubifs-force-atomic-renames.patch create mode 100644 target/linux/generic/pending-5.4/510-ubifs-force-atomic-renames.patch diff --git a/target/linux/generic/pending-5.10/510-ubifs-force-atomic-renames.patch b/target/linux/generic/pending-5.10/510-ubifs-force-atomic-renames.patch new file mode 100644 index 0000000000..80f5f1b910 --- /dev/null +++ b/target/linux/generic/pending-5.10/510-ubifs-force-atomic-renames.patch @@ -0,0 +1,46 @@ +From: Richard Weinberger +Date: Mon, 28 Feb 2022 16:07:41 +0100 +Subject: [PATCH] ubifs: force atomic renames +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Before actual rename make sure that the old inode data has been flash +written. This is similar to what other filesystems do and workarounds +bugs in some user-space apps. + +With this change updating file using tmpfile & rename() will never +result in losing all content e.g. on power cut. + +Signed-off-by: Rafał Miłecki +--- + fs/ubifs/dir.c | 18 ++++++++++++++---- + 1 file changed, 14 insertions(+), 4 deletions(-) + +--- a/fs/ubifs/dir.c ++++ b/fs/ubifs/dir.c +@@ -1287,10 +1287,20 @@ static int do_rename(struct inode *old_d + return err; + } + +- if (unlink && is_dir) { +- err = ubifs_check_dir_empty(new_inode); +- if (err) +- return err; ++ if (unlink) { ++ if (is_dir) { ++ err = ubifs_check_dir_empty(new_inode); ++ if (err) ++ return err; ++ } else { ++ err = filemap_fdatawrite(old_inode->i_mapping); ++ if (err) ++ return err; ++ ++ err = ubifs_sync_wbufs_by_inode(c, old_inode); ++ if (err) ++ return err; ++ } + } + + err = fscrypt_setup_filename(old_dir, &old_dentry->d_name, 0, &old_nm); diff --git a/target/linux/generic/pending-5.4/510-ubifs-force-atomic-renames.patch b/target/linux/generic/pending-5.4/510-ubifs-force-atomic-renames.patch new file mode 100644 index 0000000000..30bc686854 --- /dev/null +++ b/target/linux/generic/pending-5.4/510-ubifs-force-atomic-renames.patch @@ -0,0 +1,46 @@ +From: Richard Weinberger +Date: Mon, 28 Feb 2022 16:07:41 +0100 +Subject: [PATCH] ubifs: force atomic renames +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Before actual rename make sure that the old inode data has been flash +written. This is similar to what other filesystems do and workarounds +bugs in some user-space apps. + +With this change updating file using tmpfile & rename() will never +result in losing all content e.g. on power cut. + +Signed-off-by: Rafał Miłecki +--- + fs/ubifs/dir.c | 18 ++++++++++++++---- + 1 file changed, 14 insertions(+), 4 deletions(-) + +--- a/fs/ubifs/dir.c ++++ b/fs/ubifs/dir.c +@@ -1295,10 +1295,20 @@ static int do_rename(struct inode *old_d + return err; + } + +- if (unlink && is_dir) { +- err = ubifs_check_dir_empty(new_inode); +- if (err) +- return err; ++ if (unlink) { ++ if (is_dir) { ++ err = ubifs_check_dir_empty(new_inode); ++ if (err) ++ return err; ++ } else { ++ err = filemap_fdatawrite(old_inode->i_mapping); ++ if (err) ++ return err; ++ ++ err = ubifs_sync_wbufs_by_inode(c, old_inode); ++ if (err) ++ return err; ++ } + } + + err = fscrypt_setup_filename(old_dir, &old_dentry->d_name, 0, &old_nm);