Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2494470rdb; Thu, 21 Sep 2023 23:21:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH4AWb29vVp9GhveuouXq2gYHbnp0Ti/Wu7Ojp1iVt0thyaqPA+8OevsKuJXhCyMzKPMmTr X-Received: by 2002:a05:6a00:c91:b0:68f:b8ca:b11 with SMTP id a17-20020a056a000c9100b0068fb8ca0b11mr7765800pfv.11.1695363708173; Thu, 21 Sep 2023 23:21:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695363708; cv=none; d=google.com; s=arc-20160816; b=Yn4zVItgJiOHMI9rSpkc4yuRCDL/urq+6z+UoZqv7Q8LdGbu4peVhR3o791xlVUYFR G6Dymb5BgKnQvDYteRz0rffY7uDjqvzUuqAlz/2+FmM416qRb01wAhLubj/6DSoirRS+ 4HcIhaaNWxwm0U5lBDNRMl+7uDnLeRARpp1r2A5avRpGg1n81pwjtKloRbqj9kdNl7vm nC7YKAdSyT13fnL/48a86lp3r5gkiT2R8oIKguPyPnQdf0CAfrniBP71d8i0K1JtT1Ln 7YhhxyT3Xr4FmsuYwEMTPo9aIxxv7pGEHpGpjMA6Dy/VK7G99OWn/3K1EuMLJXWbiX1N w4eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sOagZNuf5a1AJuwVUYKOAYZ0jbYyZkDR5exYYeeQdZg=; fh=c8NKFRvP9+Ml9XvzqG2nGqhVxTjW39J/I/tkc5xa6gs=; b=si5W+DGd7lyDylqcfc7W9/lIXkp1OvE1iU6UmZ/W7wnk+w5I27k0NOXoXZNeSWDKt9 2BL62YBA1PCIwkdrSRO8soPkjverXDRm1dh0VA4SxcQ1D9418xp0QNTfGVGUWoxqEQB8 DFRRA7TJ994TcQlZcleOMLndQx1HZMV0h1MBj4nzitX1LPVh73PY745LicGecRvaet2E yyvBAnMnhwR8V8FXVtx0O82pPUthiYgLIQuIRE9/m1xgT2ivS/JLWeW44Dc5aiK6G3BN 30jL1vp5t+PEuygTz75v77ZwPGbDdl0NzXS4AqDI1gBEZfT/Vi5SMbvOEpmqJLRsyHBl 5/Qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=qhUuPhLg; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id cq17-20020a056a00331100b0068faabd47fcsi3144074pfb.210.2023.09.21.23.21.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 23:21:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=qhUuPhLg; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id CFC578057E19; Thu, 21 Sep 2023 13:28:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230088AbjIUU2n (ORCPT + 99 others); Thu, 21 Sep 2023 16:28:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231881AbjIUU2V (ORCPT ); Thu, 21 Sep 2023 16:28:21 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF7F6659D; Thu, 21 Sep 2023 13:07:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=sOagZNuf5a1AJuwVUYKOAYZ0jbYyZkDR5exYYeeQdZg=; b=qhUuPhLgO1AQC/FRuI8FDpalpa 6+IRwXybfxE/U3BYnVUngAMdIhjgiVf7/6P/Fr3DbZiEBShREgJLlb3bGcy+n9LDvFJ/4JlDN9Aib yF7SHkBwOv1WBq0amITgy44JLwhX4tznPvdn06ByeKFqS5XDsWG7ImAb4UDe6pqZBRWDn6plYi5kg Pu88DODgFJg2Ksxznpkq5txxHnjVyNCAiWQgcSHTD2Vd3hqE8c/QAZe3d73hXO1g7pfJLdMjaZBRl aWexwUnI0s+UWnQbJatRBsGMNHzSzqH81Z1yvfsdIr9V/E8Ypr1JZT8+gXG36yDZOEaf9bQJ4L7ky f6mKqP+g==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qjPxk-00DrVt-3z; Thu, 21 Sep 2023 20:07:48 +0000 From: "Matthew Wilcox (Oracle)" To: Jan Kara Cc: "Matthew Wilcox (Oracle)" , linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Fabio M . De Francesco" Subject: [PATCH 07/10] ext2: Handle large block size directories in ext2_delete_entry() Date: Thu, 21 Sep 2023 21:07:44 +0100 Message-Id: <20230921200746.3303942-7-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230921200746.3303942-1-willy@infradead.org> References: <20230921200746.3303942-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 21 Sep 2023 13:28:48 -0700 (PDT) If the block size is > PAGE_SIZE, we need to calculate these offsets relative to the start of the folio, not the page. Signed-off-by: Matthew Wilcox (Oracle) --- fs/ext2/dir.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/fs/ext2/dir.c b/fs/ext2/dir.c index 2fc910e99234..7e75cfaa709c 100644 --- a/fs/ext2/dir.c +++ b/fs/ext2/dir.c @@ -586,16 +586,20 @@ int ext2_add_link (struct dentry *dentry, struct inode *inode) */ int ext2_delete_entry(struct ext2_dir_entry_2 *dir, struct page *page) { - struct inode *inode = page->mapping->host; - char *kaddr = (char *)((unsigned long)dir & PAGE_MASK); - unsigned from = offset_in_page(dir) & ~(ext2_chunk_size(inode)-1); - unsigned to = offset_in_page(dir) + - ext2_rec_len_from_disk(dir->rec_len); + struct folio *folio = page_folio(page); + struct inode *inode = folio->mapping->host; + size_t from, to; + char *kaddr; loff_t pos; - ext2_dirent *pde = NULL; - ext2_dirent *de = (ext2_dirent *)(kaddr + from); + ext2_dirent *de, *pde = NULL; int err; + from = offset_in_folio(folio, dir); + to = from + ext2_rec_len_from_disk(dir->rec_len); + kaddr = (char *)dir - from; + from &= ~(ext2_chunk_size(inode)-1); + de = (ext2_dirent *)(kaddr + from); + while ((char*)de < (char*)dir) { if (de->rec_len == 0) { ext2_error(inode->i_sb, __func__, @@ -606,18 +610,18 @@ int ext2_delete_entry(struct ext2_dir_entry_2 *dir, struct page *page) de = ext2_next_entry(de); } if (pde) - from = offset_in_page(pde); - pos = page_offset(page) + from; - lock_page(page); - err = ext2_prepare_chunk(page, pos, to - from); + from = offset_in_folio(folio, pde); + pos = folio_pos(folio) + from; + folio_lock(folio); + err = ext2_prepare_chunk(&folio->page, pos, to - from); if (err) { - unlock_page(page); + folio_unlock(folio); return err; } if (pde) pde->rec_len = ext2_rec_len_to_disk(to - from); dir->inode = 0; - ext2_commit_chunk(page, pos, to - from); + ext2_commit_chunk(&folio->page, pos, to - from); inode->i_mtime = inode_set_ctime_current(inode); EXT2_I(inode)->i_flags &= ~EXT2_BTREE_FL; mark_inode_dirty(inode); -- 2.40.1