From patchwork Sat Aug 10 08:28:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: zhangshida X-Patchwork-Id: 1971135 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=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Tn6sFyUm; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=150.107.74.76; helo=mail.ozlabs.org; envelope-from=srs0=osxr=pj=vger.kernel.org=linux-ext4+bounces-3693-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (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 4Wgv7g4kB5z1yXn for ; Sat, 10 Aug 2024 18:28:47 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Wgv7f3WLGz4x3d for ; Sat, 10 Aug 2024 18:28:46 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Wgv7f3TWzz4x5G; Sat, 10 Aug 2024 18:28:46 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Tn6sFyUm; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=linux-ext4+bounces-3693-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4Wgv7f1FkPz4x3d for ; Sat, 10 Aug 2024 18:28:46 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id C3E09282407 for ; Sat, 10 Aug 2024 08:28:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C545214D283; Sat, 10 Aug 2024 08:28:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Tn6sFyUm" X-Original-To: linux-ext4@vger.kernel.org Received: from mail-ua1-f43.google.com (mail-ua1-f43.google.com [209.85.222.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D5E6314C583; Sat, 10 Aug 2024 08:28:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723278509; cv=none; b=p8Ar6z90U9+3+LZheLt+ykzLlNFtpPywdPlwoy8iOniOT41nXGt+58Qb0GIkBucr9ELepY+5corHL+qOfZSog+m7dC5cLkePR2256fUNOiObV2wJlmcyHsc+Up4l2X4kwJFAeg2dmPGTL1bpoSWG3EfuVxKq0zcuBu4vJj5svA4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723278509; c=relaxed/simple; bh=wdiNS1NVUsFCdpAPH1x17L4nOv4E184Rt48nedcpfLc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=Xmjd63SdrwPVmwQ/PbkjTKXBEaT8jn2HtC9prr/lpFcmUT3ANVAtDnciqTY3GA7rRuLaBVc7hJTzB5FYd677FjiZUwdOIGdyzf1TERin51AfQJSNh0qXhYoPy1Hy8htFdh0TGf+bzMIwCR/6NIhBODkQAUcIQsZeRUOuDKSBrKk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Tn6sFyUm; arc=none smtp.client-ip=209.85.222.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ua1-f43.google.com with SMTP id a1e0cc1a2514c-8223f0614b6so919175241.2; Sat, 10 Aug 2024 01:28:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723278507; x=1723883307; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OfkinVOCRqqx14ba0QNxtd1YpB4MXEXYboXHawxHb8w=; b=Tn6sFyUmQK5ydGXmJsZsHjRRWEOKLDyB2QXvstKX0jsYXqK88WOQPyL0NdK6f2wIgY Ap+HAggYepiJboSfUgy3m+4crcovcXAtqpxKrvVZgwuddNPn+21vKYIABMwtwfN2qIJS 7i/2rmqFoRttTF5uzEKdUTkXjoMnkIYfSt0/D1P07oox3JkaqBuVq49PUFfJR+26V5QR WbacDJtIUIDSCWazeQGWjqVr3H/g/7/OmZHfP5IqjOFS2SqN86d+U4UKyQgppGpjg290 bqpRBJHkTAXXrIqZuSLuMWM2vkmLNrmGg95UCVeBrtWvw7rV4CThpq8WDNiwhBOo4/qT NpAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723278507; x=1723883307; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OfkinVOCRqqx14ba0QNxtd1YpB4MXEXYboXHawxHb8w=; b=pCJmolxNfaV7sWQVEIFVbj9wrvRUHK8xBHHZONlFNjW7gvZczzMTqdk6ttg0zoNdCl 0xDmBxt75fxeDeuO35hQHZG92qIjT+vC433MIHvJvcEVmmrWL6847Y7qIwfwWA30kt6o PGQMCTFd//9tZKrF0PHJaL4ww2E+lKsmYPjgLUiJCVcrRw5o6edWuCPSL5reqU2ZWyVp h2wTXUNT05AaW93Ol2DiBwQMpo5YuXgu7gAEsWtNHIeXJhhg2b4Hu/uhiKFm+6GCbxGE UiogDGCdkzx84nL5/2W+yoypo+FN1Q/1aL+wB6ajgWPg4/YBXclaWZTL4BKPFCynLJxj mEyA== X-Forwarded-Encrypted: i=1; AJvYcCUMmBjzsvZ8r0qVNyentB6aMZ2COLU1yuGtiXH3y/n5Msvelhd9JjIAgjJEjbJshJ2dCATFtTlLVvtjN78kDO3VARtJql4FGiYfCtfs X-Gm-Message-State: AOJu0YxQ2fQybqbfG3FFEuh2DMVURI0Fz/RpnA+MA4LINHxbk0XsMo8J UOOFydElnMX+tItUTx1lPZzgKueLlnikyyWfr0lX/Ztzva+BWI9g X-Google-Smtp-Source: AGHT+IE4NUkWyiiqXdmtF6hIKBPZSxvvNxOTXmRN0m6q3gBBFnHullZGiSnvAfG2e7BLe8Qrnxl/JQ== X-Received: by 2002:a05:6102:3f47:b0:48f:a858:2b52 with SMTP id ada2fe7eead31-495d860b1e4mr6043346137.29.1723278506604; Sat, 10 Aug 2024 01:28:26 -0700 (PDT) Received: from localhost.localdomain ([163.53.18.10]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-710e5a8c454sm854092b3a.180.2024.08.10.01.28.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Aug 2024 01:28:26 -0700 (PDT) From: zhangshida X-Google-Original-From: zhangshida To: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.com Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, zhangshida@kylinos.cn, starzhangzsd@gmail.com, Jan Kara Subject: [PATCH v3 1/3] ext4: hoist ext4_block_write_begin and replace the __block_write_begin Date: Sat, 10 Aug 2024 16:28:12 +0800 Message-Id: <20240810082814.3709867-2-zhangshida@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240810082814.3709867-1-zhangshida@kylinos.cn> References: <20240810082814.3709867-1-zhangshida@kylinos.cn> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Shida Zhang Using __block_write_begin() make it inconvenient to journal the user data dirty process. We can't tell the block layer maintainer, ‘Hey, we want to trace the dirty user data in ext4, can we add some special code for ext4 in __block_write_begin?’:P So use ext4_block_write_begin() instead. The two functions are basically doing the same thing except for the fscrypt related code. Narrow the scope of CONFIG_FS_ENCRYPTION so as to allow ext4_block_write_begin() to function like __block_write_begin when the config is disabled. And hoist the ext4_block_write_begin so that it can be used in other files. Suggested-by: Jan Kara Signed-off-by: Shida Zhang --- fs/ext4/ext4.h | 2 ++ fs/ext4/inline.c | 10 +++++----- fs/ext4/inode.c | 23 ++++++----------------- 3 files changed, 13 insertions(+), 22 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 08acd152261e..5f8257b68190 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -3851,6 +3851,8 @@ static inline int ext4_buffer_uptodate(struct buffer_head *bh) return buffer_uptodate(bh); } +extern int ext4_block_write_begin(struct folio *folio, loff_t pos, unsigned len, + get_block_t *get_block); #endif /* __KERNEL__ */ #define EFSBADCRC EBADMSG /* Bad CRC detected */ diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c index e7a09a99837b..0a1a8431e281 100644 --- a/fs/ext4/inline.c +++ b/fs/ext4/inline.c @@ -601,10 +601,10 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping, goto out; if (ext4_should_dioread_nolock(inode)) { - ret = __block_write_begin(&folio->page, from, to, - ext4_get_block_unwritten); + ret = ext4_block_write_begin(folio, from, to, + ext4_get_block_unwritten); } else - ret = __block_write_begin(&folio->page, from, to, ext4_get_block); + ret = ext4_block_write_begin(folio, from, to, ext4_get_block); if (!ret && ext4_should_journal_data(inode)) { ret = ext4_walk_page_buffers(handle, inode, @@ -856,8 +856,8 @@ static int ext4_da_convert_inline_data_to_extent(struct address_space *mapping, goto out; } - ret = __block_write_begin(&folio->page, 0, inline_size, - ext4_da_get_block_prep); + ret = ext4_block_write_begin(folio, 0, inline_size, + ext4_da_get_block_prep); if (ret) { up_read(&EXT4_I(inode)->xattr_sem); folio_unlock(folio); diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 941c1c0d5c6e..6b15805ca88b 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1041,9 +1041,8 @@ int do_journal_get_write_access(handle_t *handle, struct inode *inode, return ret; } -#ifdef CONFIG_FS_ENCRYPTION -static int ext4_block_write_begin(struct folio *folio, loff_t pos, unsigned len, - get_block_t *get_block) +int ext4_block_write_begin(struct folio *folio, loff_t pos, unsigned len, + get_block_t *get_block) { unsigned from = pos & (PAGE_SIZE - 1); unsigned to = from + len; @@ -1119,7 +1118,9 @@ static int ext4_block_write_begin(struct folio *folio, loff_t pos, unsigned len, } if (unlikely(err)) { folio_zero_new_buffers(folio, from, to); - } else if (fscrypt_inode_uses_fs_layer_crypto(inode)) { + } +#ifdef CONFIG_FS_ENCRYPTION + else if (fscrypt_inode_uses_fs_layer_crypto(inode)) { for (i = 0; i < nr_wait; i++) { int err2; @@ -1131,10 +1132,10 @@ static int ext4_block_write_begin(struct folio *folio, loff_t pos, unsigned len, } } } +#endif return err; } -#endif /* * To preserve ordering, it is essential that the hole instantiation and @@ -1216,19 +1217,11 @@ static int ext4_write_begin(struct file *file, struct address_space *mapping, /* In case writeback began while the folio was unlocked */ folio_wait_stable(folio); -#ifdef CONFIG_FS_ENCRYPTION if (ext4_should_dioread_nolock(inode)) ret = ext4_block_write_begin(folio, pos, len, ext4_get_block_unwritten); else ret = ext4_block_write_begin(folio, pos, len, ext4_get_block); -#else - if (ext4_should_dioread_nolock(inode)) - ret = __block_write_begin(&folio->page, pos, len, - ext4_get_block_unwritten); - else - ret = __block_write_begin(&folio->page, pos, len, ext4_get_block); -#endif if (!ret && ext4_should_journal_data(inode)) { ret = ext4_walk_page_buffers(handle, inode, folio_buffers(folio), from, to, @@ -2961,11 +2954,7 @@ static int ext4_da_write_begin(struct file *file, struct address_space *mapping, if (IS_ERR(folio)) return PTR_ERR(folio); -#ifdef CONFIG_FS_ENCRYPTION ret = ext4_block_write_begin(folio, pos, len, ext4_da_get_block_prep); -#else - ret = __block_write_begin(&folio->page, pos, len, ext4_da_get_block_prep); -#endif if (ret < 0) { folio_unlock(folio); folio_put(folio); From patchwork Sat Aug 10 08:28:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhangshida X-Patchwork-Id: 1971136 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=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=OI7U16Jo; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=150.107.74.76; helo=mail.ozlabs.org; envelope-from=srs0=1taz=pj=vger.kernel.org=linux-ext4+bounces-3694-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wgv866ttMz1yXn for ; Sat, 10 Aug 2024 18:29:10 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Wgv865zf8z4x3d for ; Sat, 10 Aug 2024 18:29:10 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Wgv865xcBz4x5G; Sat, 10 Aug 2024 18:29:10 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=OI7U16Jo; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=linux-ext4+bounces-3694-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [IPv6:2604:1380:45d1:ec00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4Wgv862knqz4x3d for ; Sat, 10 Aug 2024 18:29:10 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 823A71C20C8D for ; Sat, 10 Aug 2024 08:29:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2E98314E2C2; Sat, 10 Aug 2024 08:28:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OI7U16Jo" X-Original-To: linux-ext4@vger.kernel.org Received: from mail-oa1-f51.google.com (mail-oa1-f51.google.com [209.85.160.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 51D8A14D43D; Sat, 10 Aug 2024 08:28:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723278513; cv=none; b=dnVEOhs5U1nhM0uc7FAYTWBtjietuXKZBbMf0RyZHGUNxXpoOLFRnPvY3XiF6E/WXsuWUxMD6B6AnWsFjpPxJ75v9LIy7lmjjE2P/pY0oAL+2UCj0zwQ8RkesjWi253eKwBj2GotO2uSYL1ottgo3krK7alqfmWurBDD4fRtvFU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723278513; c=relaxed/simple; bh=RkuvIMkclvFPD0SfbQ0lukE1nGNH6KOgpTMJO2EH9vE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oHN/RwqHaU38Dun6L4hGSAcJHeknUXUMj+Ljcr0hnNliCo/z+3DragMudNmLq+W0q5h6JSKeD5r30LrGvQ7TLT4kL7p154Y5eDWMFxU6Ez2zdd+Nq2X3W8p6OYY0/aG4fWEr9o5S8GuAtQzBaL/1ygJ9rAlUZRLMUGsqMR5JZto= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=OI7U16Jo; arc=none smtp.client-ip=209.85.160.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oa1-f51.google.com with SMTP id 586e51a60fabf-2689e7a941fso1893398fac.3; Sat, 10 Aug 2024 01:28:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723278510; x=1723883310; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=z1fH1Ho4GcX3EGjEBqcsALQduBlTVXsfPzay7ElzmRk=; b=OI7U16JoCcBYkfcNyHMjeIssxSWqXFnC10XgkBUPVul4UtSYvIrnwz9ecaKiR1czOv 28DgODmY/DNNxYM75XA58bNz7qYBiCDToZmrOjBiLCuCSlZmyqCI35QWpxfp0aB+pqc9 uFvdiqL2i82rnEw3zBA1mYF7OSyeetVqnm8un+GYdMv/6WVf2ku+wJErjPn6Heq6h2wr ZzfeYmg+JExmWvh1cXVfsouhaDXQz0ouZsVJOPnmnfDLsU2Otc7jP1w+RfgbCQXqcxaK 6tSsDjL73V8eQOpzgjFDuWYP2F47Q6/DqdqypenyMazgRY73QPQvz+6ywgAnH5pe3DIS yRrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723278510; x=1723883310; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=z1fH1Ho4GcX3EGjEBqcsALQduBlTVXsfPzay7ElzmRk=; b=bWb8nMIGex6RxqNPOcvB258+5IJOJ1OFSDyaLJkYx5WGd5O14B6YU1qbxBlIDvv0IE 118neJYOVZwEAJ3MI9tiRIrN5ssjGG8PLVleS2+drFtSeElsaBp2cOXSzR6x0qX8uzaW EkHwpbRWeQmNIsktdqPJ5pwW2ZOc9GgepJtmQt5WDvbZdVMhtGc1ko3IQhZTIO+Wkt27 6+kXBPG9YTabxfnxa1MYvNy7cHVYgxUEU1vxEKRoR7YGGhVmjmctBDx8OB7vP444KUzM rLxJyLMyaOfYdJhkXrqYkdXMeE0eeNY0jbHhDm2tp0LP90GiB85Y/zM8aaY378WH9DwN gyOw== X-Forwarded-Encrypted: i=1; AJvYcCUsVTq3J6RYtKPn3HMZEsZD6/7R6vMJapV9BrBfu7fg2Qf0xNi3PNN+U9V1FBK63YHvvFDwkE2WRu7h7uQnhJEsmhrD7ic+UJnj8St2 X-Gm-Message-State: AOJu0Yy3t4mmd/Ix0R2SbQh/KQxpDfaeF4ON4kldGMQHq6C8SkEOxVyH rxiD87eGJKo3sjHI8rL0zNB8QltuY5M+VEKKYLtyZlfs0Q9+EsUK X-Google-Smtp-Source: AGHT+IEzsxubHbJF6CWVozJ9oM3cep1yA8YrhjqmeIrMsateIHoyAtM/9NuUqRuSb+yVAM/rm5ksYA== X-Received: by 2002:a05:6870:3282:b0:261:1339:1cb9 with SMTP id 586e51a60fabf-26c62f21d48mr5160013fac.35.1723278510219; Sat, 10 Aug 2024 01:28:30 -0700 (PDT) Received: from localhost.localdomain ([163.53.18.10]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-710e5a8c454sm854092b3a.180.2024.08.10.01.28.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Aug 2024 01:28:29 -0700 (PDT) From: zhangshida X-Google-Original-From: zhangshida To: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.com Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, zhangshida@kylinos.cn, starzhangzsd@gmail.com, Baolin Liu , Jan Kara Subject: [PATCH v3 2/3] ext4: fix a potential assertion failure due to improperly dirtied buffer Date: Sat, 10 Aug 2024 16:28:13 +0800 Message-Id: <20240810082814.3709867-3-zhangshida@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240810082814.3709867-1-zhangshida@kylinos.cn> References: <20240810082814.3709867-1-zhangshida@kylinos.cn> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Shida Zhang On an old kernel version(4.19, ext3, data=journal, pagesize=64k), an assertion failure will occasionally be triggered by the line below: ----------- jbd2_journal_commit_transaction { ... J_ASSERT_BH(bh, !buffer_dirty(bh)); /* * The buffer on BJ_Forget list and not jbddirty means ... } ----------- The same condition may also be applied to the lattest kernel version. When blocksize < pagesize and we truncate a file, there can be buffers in the mapping tail page beyond i_size. These buffers will be filed to transaction's BJ_Forget list by ext4_journalled_invalidatepage() during truncation. When the transaction doing truncate starts committing, we can grow the file again. This calls __block_write_begin() which allocates new blocks under these buffers in the tail page we go through the branch: if (buffer_new(bh)) { clean_bdev_bh_alias(bh); if (folio_test_uptodate(folio)) { clear_buffer_new(bh); set_buffer_uptodate(bh); mark_buffer_dirty(bh); continue; } ... } Hence buffers on BJ_Forget list of the committing transaction get marked dirty and this triggers the jbd2 assertion. Teach ext4_block_write_begin() to properly handle files with data journalling by avoiding dirtying them directly. Instead of folio_zero_new_buffers() we use ext4_journalled_zero_new_buffers() which takes care of handling journalling. We also don't need to mark new uptodate buffers as dirty in ext4_block_write_begin(). That will be either done either by block_commit_write() in case of success or by folio_zero_new_buffers() in case of failure. Reported-by: Baolin Liu Suggested-by: Jan Kara Signed-off-by: Shida Zhang --- fs/ext4/ext4.h | 3 ++- fs/ext4/inline.c | 7 ++++--- fs/ext4/inode.c | 30 ++++++++++++++++++++++-------- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 5f8257b68190..b653bd423b11 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -3851,7 +3851,8 @@ static inline int ext4_buffer_uptodate(struct buffer_head *bh) return buffer_uptodate(bh); } -extern int ext4_block_write_begin(struct folio *folio, loff_t pos, unsigned len, +extern int ext4_block_write_begin(handle_t *handle, struct folio *folio, + loff_t pos, unsigned len, get_block_t *get_block); #endif /* __KERNEL__ */ diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c index 0a1a8431e281..8d5599d5af27 100644 --- a/fs/ext4/inline.c +++ b/fs/ext4/inline.c @@ -601,10 +601,11 @@ static int ext4_convert_inline_data_to_extent(struct address_space *mapping, goto out; if (ext4_should_dioread_nolock(inode)) { - ret = ext4_block_write_begin(folio, from, to, + ret = ext4_block_write_begin(handle, folio, from, to, ext4_get_block_unwritten); } else - ret = ext4_block_write_begin(folio, from, to, ext4_get_block); + ret = ext4_block_write_begin(handle, folio, from, to, + ext4_get_block); if (!ret && ext4_should_journal_data(inode)) { ret = ext4_walk_page_buffers(handle, inode, @@ -856,7 +857,7 @@ static int ext4_da_convert_inline_data_to_extent(struct address_space *mapping, goto out; } - ret = ext4_block_write_begin(folio, 0, inline_size, + ret = ext4_block_write_begin(NULL, folio, 0, inline_size, ext4_da_get_block_prep); if (ret) { up_read(&EXT4_I(inode)->xattr_sem); diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 6b15805ca88b..4c34827da56e 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -49,6 +49,11 @@ #include +static void ext4_journalled_zero_new_buffers(handle_t *handle, + struct inode *inode, + struct folio *folio, + unsigned from, unsigned to); + static __u32 ext4_inode_csum(struct inode *inode, struct ext4_inode *raw, struct ext4_inode_info *ei) { @@ -1041,7 +1046,8 @@ int do_journal_get_write_access(handle_t *handle, struct inode *inode, return ret; } -int ext4_block_write_begin(struct folio *folio, loff_t pos, unsigned len, +int ext4_block_write_begin(handle_t *handle, struct folio *folio, + loff_t pos, unsigned len, get_block_t *get_block) { unsigned from = pos & (PAGE_SIZE - 1); @@ -1055,6 +1061,7 @@ int ext4_block_write_begin(struct folio *folio, loff_t pos, unsigned len, struct buffer_head *bh, *head, *wait[2]; int nr_wait = 0; int i; + bool should_journal_data = ext4_should_journal_data(inode); BUG_ON(!folio_test_locked(folio)); BUG_ON(from > PAGE_SIZE); @@ -1083,11 +1090,11 @@ int ext4_block_write_begin(struct folio *folio, loff_t pos, unsigned len, err = get_block(inode, block, bh, 1); if (err) break; + if (should_journal_data) + do_journal_get_write_access(handle, inode, bh); if (buffer_new(bh)) { if (folio_test_uptodate(folio)) { - clear_buffer_new(bh); set_buffer_uptodate(bh); - mark_buffer_dirty(bh); continue; } if (block_end > to || block_start < from) @@ -1117,7 +1124,11 @@ int ext4_block_write_begin(struct folio *folio, loff_t pos, unsigned len, err = -EIO; } if (unlikely(err)) { - folio_zero_new_buffers(folio, from, to); + if (should_journal_data) + ext4_journalled_zero_new_buffers(handle, inode, folio, + from, to); + else + folio_zero_new_buffers(folio, from, to); } #ifdef CONFIG_FS_ENCRYPTION else if (fscrypt_inode_uses_fs_layer_crypto(inode)) { @@ -1218,10 +1229,11 @@ static int ext4_write_begin(struct file *file, struct address_space *mapping, folio_wait_stable(folio); if (ext4_should_dioread_nolock(inode)) - ret = ext4_block_write_begin(folio, pos, len, + ret = ext4_block_write_begin(handle, folio, pos, len, ext4_get_block_unwritten); else - ret = ext4_block_write_begin(folio, pos, len, ext4_get_block); + ret = ext4_block_write_begin(handle, folio, pos, len, + ext4_get_block); if (!ret && ext4_should_journal_data(inode)) { ret = ext4_walk_page_buffers(handle, inode, folio_buffers(folio), from, to, @@ -2954,7 +2966,8 @@ static int ext4_da_write_begin(struct file *file, struct address_space *mapping, if (IS_ERR(folio)) return PTR_ERR(folio); - ret = ext4_block_write_begin(folio, pos, len, ext4_da_get_block_prep); + ret = ext4_block_write_begin(NULL, folio, pos, len, + ext4_da_get_block_prep); if (ret < 0) { folio_unlock(folio); folio_put(folio); @@ -6208,7 +6221,8 @@ vm_fault_t ext4_page_mkwrite(struct vm_fault *vmf) if (folio_pos(folio) + len > size) len = size - folio_pos(folio); - err = __block_write_begin(&folio->page, 0, len, ext4_get_block); + err = ext4_block_write_begin(handle, folio, 0, len, + ext4_get_block); if (!err) { ret = VM_FAULT_SIGBUS; if (ext4_journal_folio_buffers(handle, folio, len)) From patchwork Sat Aug 10 08:28:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhangshida X-Patchwork-Id: 1971137 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=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=TMOnmKtl; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=mail.ozlabs.org; envelope-from=srs0=zak6=pj=vger.kernel.org=linux-ext4+bounces-3695-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (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 4Wgv8T3q2yz1yXn for ; Sat, 10 Aug 2024 18:29:29 +1000 (AEST) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Wgv8T3h3Jz4x3d for ; Sat, 10 Aug 2024 18:29:29 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4Wgv8T3fYNz4x5G; Sat, 10 Aug 2024 18:29:29 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=TMOnmKtl; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:4601:e00::3; helo=am.mirrors.kernel.org; envelope-from=linux-ext4+bounces-3695-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [IPv6:2604:1380:4601:e00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4Wgv8T03k8z4x3d for ; Sat, 10 Aug 2024 18:29:29 +1000 (AEST) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id E2F641F21A92 for ; Sat, 10 Aug 2024 08:29:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6AC1A15358F; Sat, 10 Aug 2024 08:28:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TMOnmKtl" X-Original-To: linux-ext4@vger.kernel.org Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C10261514E2; Sat, 10 Aug 2024 08:28:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723278517; cv=none; b=mqJeYphflGQ95BvfT6DE+eZkslDHgGsX8KthX4TxZLscfYqFbqtkCvpnkisKKPkqgQYaa5nTZ7EexIVyW9JBzkEpORg7bBDKal9/r6/wXOu6o0YE3wNrNx0XdTKRe69hFOI5FcXk0PNfcxPSHhL2GMCHaYVq0XtJi+QkF1D6hhM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723278517; c=relaxed/simple; bh=pgVoWRfxgQs6Hha/2qLVeJyPGpJ96P+XjQIWWOGJFXg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=c8T3fQAsAEFCvnxUl001CoVvk9j3FcmOSGUEd1FO4mRxYNt9WE+JXdYGwDtyvq+vf5NPEHsQI6ehXIz7enjRpC5KHg5HPIEeobfz1Lu6MtQPj76OxtnUfepJ3KR2kZVJhnF8NnMcywCnML+m1G6lqaVjJ4ZOUxc00j02WrMNxgA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=TMOnmKtl; arc=none smtp.client-ip=209.85.210.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-70d18112b60so1823505b3a.1; Sat, 10 Aug 2024 01:28:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723278515; x=1723883315; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=adNFyWjIXtMjUcXG11VGomGh7BHR8ZvgxWwTiurTFvU=; b=TMOnmKtlq85YkVvida9HrOBEO696fRpHOXhfiJ+OCcf4yssYrAGeLQZgDbOF+/iIpS Yydkqi4rDGMvOxXpbDzARWqH3ZBswCCNHY99RcCi4MyJw9LsLY3G15UXm8L7iQU4Tl2D Mpx02fwPu1m3Vj3sJvf0cJ0igDpc/iWN27gGxU7NMceHjeJScgZ/AseRT0BV2YOJBrU1 jEDiLqIsceHkkvi3O43A6wXjX/1t1rDOuRYA3qiR8yoR+xKUJG/BJXA6xIN7U/v8w+S7 42SxTGyvHb92VQaNnBpRJLpifByFRigL24+mmA9lUBsItp7ec8CeLB0GOhIRf7KHtwFq vbiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723278515; x=1723883315; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=adNFyWjIXtMjUcXG11VGomGh7BHR8ZvgxWwTiurTFvU=; b=QKzQxs4iJifBsALPwBcHOY1RNpu1nDmb7pTe5uD+vYZUWhYOiqOOY6Giw/kspMXJfQ jJVYf1eOq826vL3Fv90U+nC284aQsFEsJja9074mRw10srbJ528QQZ70Vpk9+iVwXhoa rJHqSvPPEgYCKokO+YRkrDDjiOLOAqcKrX1+tHmu13u0k1m573unYR3sNpBNCAJ5H4bi DR0yUPeEMJWNcFlTHWbe1wT4sYi09s6s0NGbchzeAVPaGeQvJGGtoswT77uJHekNthlP ihE6DkOuv1VmrsQcIAIGL67rTl0brv7qZ+bLLQfypMU+EKCuKiAAkLNVl92ouKQvX5A6 Eb/A== X-Forwarded-Encrypted: i=1; AJvYcCVpIQnkPcNNSO3WBZ1iI8SpRgzbkV4TR//H08/N6qbYGd0AJp2ksoHl2CPQ4GUEV1k78hSiiWUCsO+OBt8=@vger.kernel.org X-Gm-Message-State: AOJu0YzjgyOiq44mTgUQh+UpMVOyfAbzaUmOLirITyAhOTtml+pRIB9G tfWuCiKNA1ge5mnaTeQOuJdnFhq+2iglM97NYdK24wAWtPWreHcS X-Google-Smtp-Source: AGHT+IFR72KuXHFDYfNVANkWiU3aZvT48F4qXTFGZyp86Cy2+d7Yk4ks6c5rk6vIcD+Fj6ABmrgakg== X-Received: by 2002:aa7:8d53:0:b0:705:d6ad:2495 with SMTP id d2e1a72fcca58-710cc90db8cmr11683860b3a.12.1723278514878; Sat, 10 Aug 2024 01:28:34 -0700 (PDT) Received: from localhost.localdomain ([163.53.18.10]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-710e5a8c454sm854092b3a.180.2024.08.10.01.28.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Aug 2024 01:28:34 -0700 (PDT) From: zhangshida X-Google-Original-From: zhangshida To: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.com Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, zhangshida@kylinos.cn, starzhangzsd@gmail.com Subject: [RFC PATCH v3 3/3] ext4: remove the superfluous things left by __block_write_begin Date: Sat, 10 Aug 2024 16:28:14 +0800 Message-Id: <20240810082814.3709867-4-zhangshida@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240810082814.3709867-1-zhangshida@kylinos.cn> References: <20240810082814.3709867-1-zhangshida@kylinos.cn> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Shida Zhang This kinda revert the commit 56d35a4cd13e("ext4: Fix dirtying of journalled buffers in data=journal mode") made by Jan 14 years ago. Now that the whole __block_write_begin and improperly dirty things were removed from the code. Remove the related code, too. Now we get a better and cleaner world! Signed-off-by: Shida Zhang --- fs/ext4/inode.c | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 4c34827da56e..cb6de9921655 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1023,27 +1023,13 @@ static int ext4_dirty_journalled_data(handle_t *handle, struct buffer_head *bh) int do_journal_get_write_access(handle_t *handle, struct inode *inode, struct buffer_head *bh) { - int dirty = buffer_dirty(bh); - int ret; + ASSERT(!buffer_dirty(bh)); if (!buffer_mapped(bh) || buffer_freed(bh)) return 0; - /* - * __block_write_begin() could have dirtied some buffers. Clean - * the dirty bit as jbd2_journal_get_write_access() could complain - * otherwise about fs integrity issues. Setting of the dirty bit - * by __block_write_begin() isn't a real problem here as we clear - * the bit before releasing a page lock and thus writeback cannot - * ever write the buffer. - */ - if (dirty) - clear_buffer_dirty(bh); BUFFER_TRACE(bh, "get write access"); - ret = ext4_journal_get_write_access(handle, inode->i_sb, bh, + return ext4_journal_get_write_access(handle, inode->i_sb, bh, EXT4_JTR_NONE); - if (!ret && dirty) - ret = ext4_dirty_journalled_data(handle, bh); - return ret; } int ext4_block_write_begin(handle_t *handle, struct folio *folio, @@ -1246,7 +1232,7 @@ static int ext4_write_begin(struct file *file, struct address_space *mapping, folio_unlock(folio); /* - * __block_write_begin may have instantiated a few blocks + * ext4_block_write_begin may have instantiated a few blocks * outside i_size. Trim these off again. Don't need * i_size_read because we hold i_rwsem. *