From patchwork Thu Aug 19 14:49:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Whitney X-Patchwork-Id: 1518708 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=OWbKqXTl; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Gr72w0hZbz9t0G for ; Fri, 20 Aug 2021 00:49:44 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238634AbhHSOuT (ORCPT ); Thu, 19 Aug 2021 10:50:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240596AbhHSOuR (ORCPT ); Thu, 19 Aug 2021 10:50:17 -0400 Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD8A2C061575 for ; Thu, 19 Aug 2021 07:49:40 -0700 (PDT) Received: by mail-qv1-xf2f.google.com with SMTP id cu12so2128397qvb.10 for ; Thu, 19 Aug 2021 07:49:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=304Ej8iokqbiYyAzlMvCH4vurNA8Qu6uG3/CblPnzts=; b=OWbKqXTlO5ShFPEHOHH9+5QNz3uUQe6UictEZ/g81+95pVqByvY8Hjc7QJgbJrgNez N9/1zDzrdZE42qYDy8Es9tjNXdQVJp8ODrBzfoG4wyd4/X1uTO2xsAxzAiH9B0Fu4lB7 Tqa1aIfR5ImJTj0VTYYeDzpDnDfKEjAdGyn+TdkNtUMtUJkMX+G0GBbtCqMPBKM6uVOA WWlYWkuSqjHQGJtXQN4L4IQgIsncfdajRz8Mun/lswKC8BJlsPNpQqeM4elC6Efc89jV eJLnIctBgIjuNZMwOY8JPbh0mbSphkZyiglA3iK6frqX0I6LhrciEaygcYoH02/wiHrh RL2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=304Ej8iokqbiYyAzlMvCH4vurNA8Qu6uG3/CblPnzts=; b=cJfh4ZQA0YZX49mtttAlgV1CGlJLmAXXt0az8VudlTJO7pSQjcNpUBWWOZqwf2iriw zfy8a9+IIwQ9sSw4jgHuQAkNY/o5p0s0ZKUtjvTq3sYh7NifuHg4d094tCRtoRV/A9vd /mQvnA1TfVpzwj7g7jS3EFc0k7x8kCHnLz17djZmN5LwH3Sf7HTvcXeW7T3a1PgB4nSU Xdv/+yJ8RsNAy2crcTN0Xw8yHeiy2s4cHiIMAjpISUeVAy3cfVYrIynzwPunYsLMFZfb Ez8CMlHsJyvsUdr8K2s1TlgegPhgxGZUJsGPdDVOptHM/k9kj4S3ex3Civ4OGLTwyOTq XasA== X-Gm-Message-State: AOAM533FMWl5+P1gm1Feao+AYDe2KwYLvuw/7e9aFGrC42b6YRmrGo/P LwHVnfm3gFR6b01f60MlqiTjU5pMg3A= X-Google-Smtp-Source: ABdhPJysE5XoMCDJTEMGFGNjHO49QnqAZYjkkTav6s8/tCN60w55E+xpVk0pcLOihOil5a6HQeCrtQ== X-Received: by 2002:a05:6214:54a:: with SMTP id ci10mr14824044qvb.19.1629384580002; Thu, 19 Aug 2021 07:49:40 -0700 (PDT) Received: from localhost.localdomain (c-73-60-226-25.hsd1.nh.comcast.net. [73.60.226.25]) by smtp.gmail.com with ESMTPSA id x21sm1684292qkf.76.2021.08.19.07.49.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Aug 2021 07:49:39 -0700 (PDT) From: Eric Whitney To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, Eric Whitney Subject: [PATCH 1/2] ext4: remove extent cache entries when truncating inline data Date: Thu, 19 Aug 2021 10:49:26 -0400 Message-Id: <20210819144927.25163-2-enwlinux@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210819144927.25163-1-enwlinux@gmail.com> References: <20210819144927.25163-1-enwlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Conditionally remove all cached extents belonging to an inode when truncating its inline data. It's only necessary to attempt to remove cached extents when a conversion from inline to extent storage has been initiated (!EXT4_STATE_MAY_INLINE_DATA). This avoids unnecessary es lock overhead in the more common inline case. Signed-off-by: Eric Whitney --- fs/ext4/inline.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c index 70cb64db33f7..49b0b4fcea6d 100644 --- a/fs/ext4/inline.c +++ b/fs/ext4/inline.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "ext4_jbd2.h" #include "ext4.h" @@ -1903,6 +1904,24 @@ int ext4_inline_data_truncate(struct inode *inode, int *has_inline) EXT4_I(inode)->i_disksize = i_size; if (i_size < inline_size) { + /* + * if there's inline data to truncate and this file was + * converted to extents after that inline data was written, + * the extent status cache must be cleared to avoid leaving + * behind stale delayed allocated extent entries + */ + if (!ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA)) { +retry: + err = ext4_es_remove_extent(inode, 0, EXT_MAX_BLOCKS); + if (err == -ENOMEM) { + cond_resched(); + congestion_wait(BLK_RW_ASYNC, HZ/50); + goto retry; + } + if (err) + goto out_error; + } + /* Clear the content in the xattr space. */ if (inline_size > EXT4_MIN_INLINE_DATA_SIZE) { if ((err = ext4_xattr_ibody_find(inode, &i, &is)) != 0) From patchwork Thu Aug 19 14:49:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Whitney X-Patchwork-Id: 1518709 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=YcGEqGzT; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4Gr72w5JQfz9t18 for ; Fri, 20 Aug 2021 00:49:44 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240595AbhHSOuU (ORCPT ); Thu, 19 Aug 2021 10:50:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240599AbhHSOuS (ORCPT ); Thu, 19 Aug 2021 10:50:18 -0400 Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 265A2C061757 for ; Thu, 19 Aug 2021 07:49:42 -0700 (PDT) Received: by mail-qv1-xf2f.google.com with SMTP id bl13so3731088qvb.5 for ; Thu, 19 Aug 2021 07:49:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/R+Y9ePoCEJzeGoqYlwN2k3Ux6yFtVnQItvv7scrCJ0=; b=YcGEqGzTTKPiOVmyV6+WG+ObyrqD6vUvaDwAUG+8SYzQmer+M7l4lVMpNhIAEbfqLJ zsYyMfxWFNGaRE0SyT3gjx8qeGzzVH/HJIlU8RmocvTIqqkU2WhcF6jcf8EcdZUuOkeV nyJMJO7JbC4vdUx2X4Yse9TJXfo2TB+dQgDtrWEWlsJ7a2UvJu69JnfaxO1rEyuQXsZM 1uJ0EJlUI90oSYBrF/1rUJZcfcdft5SoIgr/adQJTi9HjGKHM2EhnTQq0naNYL0UL/wb CBDR3r7xzyzyEMTZaX8vZTZ5o62Ngs03mRhlPHMjQyLIg1BgXQ7UBncAFGf/ppaT1FoL BQdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/R+Y9ePoCEJzeGoqYlwN2k3Ux6yFtVnQItvv7scrCJ0=; b=Oh0YAXppaU9EHk/aiiMJFS0dKiqV31gt45ll8+uPVbKmlVSV8qe0zCELl17gvZRzzo zo83QYOubPQjHqs86UudQUJCAD8uFjzQT+5U8qd6LhbXi1TSJNqN5Ao15MLPSaGBDscp NjlsDKW2dm6uR24VeHXwoH2wi894Y5p7O3esDIAVRz1wZToFPt1RgCzDIuXdIAjE/Ktb wIXfOo2HaQVfUvlviAgexuetcPoxq/JY83N1iXCbkqOufLPT6S/tLt2DHoksp3EqRqjq OOKUur99mb8pdzBoFbf9idappDDV20ENcce7TjpWiGYEWvdtwXCmdOa47XsDtP7vI0RZ U1oQ== X-Gm-Message-State: AOAM530XWmLmVZtHB+NCu0iAHc554Yi55zunF/IKLB4yEnaCL4ub5cvM k/Ye4APHZdCGkTFOUflYB8TIy6jUd8Y= X-Google-Smtp-Source: ABdhPJz7GpwWeKJwYBDxmFeEBsWE98Ji75xZZhZg7e0OYuONFJIAIIyXsGVhqD/w3XiT2ZI5d+OiUA== X-Received: by 2002:ad4:51c7:: with SMTP id p7mr14903791qvq.15.1629384581356; Thu, 19 Aug 2021 07:49:41 -0700 (PDT) Received: from localhost.localdomain (c-73-60-226-25.hsd1.nh.comcast.net. [73.60.226.25]) by smtp.gmail.com with ESMTPSA id x21sm1684292qkf.76.2021.08.19.07.49.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Aug 2021 07:49:41 -0700 (PDT) From: Eric Whitney To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, Eric Whitney Subject: [PATCH 2/2] ext4: enforce buffer head state assertion in ext4_da_map_blocks Date: Thu, 19 Aug 2021 10:49:27 -0400 Message-Id: <20210819144927.25163-3-enwlinux@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210819144927.25163-1-enwlinux@gmail.com> References: <20210819144927.25163-1-enwlinux@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Remove the code that re-initializes a buffer head with an invalid block number and BH_New and BH_Delay bits when a matching delayed and unwritten block has been found in the extent status cache. Replace it with assertions that verify the buffer head already has this state correctly set. The current code masked an inline data truncation bug that left stale entries in the extent status cache. With this change, generic/130 can be used to reproduce and detect that bug. Signed-off-by: Eric Whitney --- fs/ext4/inode.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index d8de607849df..c795184153d8 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1718,13 +1718,16 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, } /* - * Delayed extent could be allocated by fallocate. - * So we need to check it. + * the buffer head associated with a delayed and not unwritten + * block found in the extent status cache must contain an + * invalid block number and have its BH_New and BH_Delay bits + * set, reflecting the state assigned when the block was + * initially delayed allocated */ - if (ext4_es_is_delayed(&es) && !ext4_es_is_unwritten(&es)) { - map_bh(bh, inode->i_sb, invalid_block); - set_buffer_new(bh); - set_buffer_delay(bh); + if (ext4_es_is_delonly(&es)) { + BUG_ON(bh->b_blocknr != invalid_block); + BUG_ON(!buffer_new(bh)); + BUG_ON(!buffer_delay(bh)); return 0; }