From patchwork Tue Apr 30 12:49:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13648940 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1764917592 for ; Tue, 30 Apr 2024 12:49:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481375; cv=none; b=Cl+ql4BWzLrTTvUZPVsl28xvoP+KWjQa0wIIMUH6qDOdXDKubKvwbXZdz69sTJx8uzZZcRwW+qM/He990I9kl0Bnh39Ch/n0GN3Ac5gFSUxJ6yAopQbpPgDqmVpN+VINqnofLO90K+qpG4veys+ssgkKHCkLzn5pj5q9uLW8Kpo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481375; c=relaxed/simple; bh=eoQ5gqVXvqU3uu7dDEab9mQ9Q0+tYZ6YiC/VLv94c0Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NBhQTxj4kdSEnA8QTcGCsm7tDF7ttsu45JHV0JQDBdBMJXbqypXK6e/bp3sYmtHAdlUX7DLeWMXAxh/Z6XHSP5F/WqM6l4YKFZinvzsxudTUlehFtUMmjLAoi6J5DeSCHAUXbuIrJVQFY8lRp77Hg2mF2q67Tr4hRtWU5CgQpIg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=Fq2NdotW; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Fq2NdotW" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=nq/mQZNeKj6QPJVC9FZM3pY1xkMO08H4j7VRRXBq5tc=; b=Fq2NdotWl0EAgNiPyRWex8WwFu BWlWDZAkV2HYpPtwhx6FXfQQkWA83lGSfCEIlJv8VUVKw9Uui8knhcg4gVrAQUy5FgtZAETWfoYJ4 ZNW7Dg7cIseUb92Ltp9YZQ2p7eHSnp/6gc5ra31QkdvaaEmubxC6Sdt2Z/um5g7ZKYs4lpoDacbkv TkE7rMfIf9IpkRGTz+gCrAqYgmGqHnjzTQfgJCJ2FdhOYRlbCdgt7mryUQT9qXDZWexqBmEjgXvU7 881/JXEAHG7y3UtVpT7rd4m2AyWZ2ogk6ZSIg5ku4LHZuRouegTkDcFARqQuA+a1U6SJ8J3ITj9PU aqqRQeww==; Received: from [2001:4bb8:188:7ba8:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1mvM-00000006Ngf-2aD8; Tue, 30 Apr 2024 12:49:33 +0000 From: Christoph Hellwig To: Chandan Babu R , "Darrick J. Wong" Cc: linux-xfs@vger.kernel.org Subject: [PATCH 01/16] xfs: allow non-empty forks in xfs_bmap_local_to_extents_empty Date: Tue, 30 Apr 2024 14:49:11 +0200 Message-Id: <20240430124926.1775355-2-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240430124926.1775355-1-hch@lst.de> References: <20240430124926.1775355-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Currently xfs_bmap_local_to_extents_empty expects the caller to set the for size to 0, which implies freeing if_data. That is highly suboptimal because the callers need the data in the local fork so that they can copy it to the newly allocated extent. Change xfs_bmap_local_to_extents_empty to return the old fork data and clear if_bytes to zero instead and let the callers free the memory for the local fork, which allows them to access the data directly while formatting the extent format data. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_bmap.c | 13 +++++++------ fs/xfs/libxfs/xfs_bmap.h | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index 6053f5e5c71eec..eb826fae8fd878 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c @@ -754,31 +754,32 @@ xfs_bmap_extents_to_btree( /* * Convert a local file to an extents file. - * This code is out of bounds for data forks of regular files, - * since the file data needs to get logged so things will stay consistent. - * (The bmap-level manipulations are ok, though). + * + * Returns the content of the old data fork, which needs to be freed by the + * caller. */ -void +void * xfs_bmap_local_to_extents_empty( struct xfs_trans *tp, struct xfs_inode *ip, int whichfork) { struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork); + void *old_data = ifp->if_data; ASSERT(whichfork != XFS_COW_FORK); ASSERT(ifp->if_format == XFS_DINODE_FMT_LOCAL); - ASSERT(ifp->if_bytes == 0); ASSERT(ifp->if_nextents == 0); xfs_bmap_forkoff_reset(ip, whichfork); ifp->if_data = NULL; + ifp->if_bytes = 0; ifp->if_height = 0; ifp->if_format = XFS_DINODE_FMT_EXTENTS; xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); + return old_data; } - int /* error */ xfs_bmap_local_to_extents( xfs_trans_t *tp, /* transaction pointer */ diff --git a/fs/xfs/libxfs/xfs_bmap.h b/fs/xfs/libxfs/xfs_bmap.h index e98849eb9bbae3..6e0b6081bf3aa5 100644 --- a/fs/xfs/libxfs/xfs_bmap.h +++ b/fs/xfs/libxfs/xfs_bmap.h @@ -178,7 +178,7 @@ void xfs_trim_extent(struct xfs_bmbt_irec *irec, xfs_fileoff_t bno, unsigned int xfs_bmap_compute_attr_offset(struct xfs_mount *mp); int xfs_bmap_add_attrfork(struct xfs_trans *tp, struct xfs_inode *ip, int size, int rsvd); -void xfs_bmap_local_to_extents_empty(struct xfs_trans *tp, +void *xfs_bmap_local_to_extents_empty(struct xfs_trans *tp, struct xfs_inode *ip, int whichfork); int xfs_bmap_local_to_extents(struct xfs_trans *tp, struct xfs_inode *ip, xfs_extlen_t total, int *logflagsp, int whichfork, From patchwork Tue Apr 30 12:49:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13648941 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 64BD917592 for ; Tue, 30 Apr 2024 12:49:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481378; cv=none; b=eN2i4+ecXgeaTdhpE5lQKSNApzjNWy+SiOiBvyF4KBO6W6SZW8V4fOStKw+szhyS1uHz8OHINgRrjxk93m1UmvANKkPwzsW4bf0eZ9HrZk5N48JhMES77+piClAErQZlNEpNN8iystQ3YAGiQrdGAZRCWg2+cLciMcyqdoEcMYw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481378; c=relaxed/simple; bh=Nj0KQSP2or/BYhco4R1AYYdKwLNT7oPK7WPasV/y3ss=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=V/s2w3UX53Mwpalz67IqXwQC4VpwomqNMJUcDzIb7OSS7Z5MUvpzQYIV9JhLs+QeWQekGOm4fEeVJ3xF4EIfFKkxcMZlo81INbRZ96lCFA5g7D5O1F5+CeznQ29alHVcLWKar6c1ZXI7g8SfPiIsQDI27+U2QdzTdgkn+PKZmTU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=Hgp9uluT; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Hgp9uluT" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=5LQ2P1FJwur0I5RhelJJlGdQPcGdcQneF/YA8zVwlHI=; b=Hgp9uluTMTb8IbSUUo7gdwujqS AJbqDUjxei3bC48rn7ETWUaaJ5Tk6DzNEuQR5qzN1+XLykes46lZtkqrgR32HgX5gvH8SQDFxAhcv 1i2dQhttxjNB+ETPiCuSwryle9HVnAgDZPEz9QsXTs761RERa9zuX4g8TG0XtnbEhrTMPYV7JUgRX MMaWcD5b/YYYSE1uB9jPR3oRNpiMjAVh83NP0t+oq35GM7N+tc9tg3VuLfVAPb4R8h5tvOY/JNQWK X9J/mM7UFcDOHDvobe6SIxc8985+XWPPs9ByUphRBHzZyorxCOcd0eok8p1QNB88ZiSb2G2mWRlKt vLksJ+VA==; Received: from [2001:4bb8:188:7ba8:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1mvP-00000006Ngv-25t3; Tue, 30 Apr 2024 12:49:36 +0000 From: Christoph Hellwig To: Chandan Babu R , "Darrick J. Wong" Cc: linux-xfs@vger.kernel.org Subject: [PATCH 02/16] xfs: remove an extra buffer allocation in xfs_attr_shortform_to_leaf Date: Tue, 30 Apr 2024 14:49:12 +0200 Message-Id: <20240430124926.1775355-3-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240430124926.1775355-1-hch@lst.de> References: <20240430124926.1775355-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Make use of the new ability to call xfs_bmap_local_to_extents_empty on a non-empty local fork to reuse the old inode fork data to build the leaf block to replace the local temporary buffer. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_attr_leaf.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c index b9e98950eb3d81..d9285614d7c21b 100644 --- a/fs/xfs/libxfs/xfs_attr_leaf.c +++ b/fs/xfs/libxfs/xfs_attr_leaf.c @@ -942,24 +942,16 @@ xfs_attr_shortform_to_leaf( struct xfs_da_args *args) { struct xfs_inode *dp = args->dp; - struct xfs_ifork *ifp = &dp->i_af; - struct xfs_attr_sf_hdr *sf = ifp->if_data; + struct xfs_attr_sf_hdr *sf; struct xfs_attr_sf_entry *sfe; - int size = be16_to_cpu(sf->totsize); struct xfs_da_args nargs; - char *tmpbuffer; int error, i; xfs_dablk_t blkno; struct xfs_buf *bp; trace_xfs_attr_sf_to_leaf(args); - tmpbuffer = kmalloc(size, GFP_KERNEL | __GFP_NOFAIL); - memcpy(tmpbuffer, ifp->if_data, size); - sf = (struct xfs_attr_sf_hdr *)tmpbuffer; - - xfs_idata_realloc(dp, -size, XFS_ATTR_FORK); - xfs_bmap_local_to_extents_empty(args->trans, dp, XFS_ATTR_FORK); + sf = xfs_bmap_local_to_extents_empty(args->trans, dp, XFS_ATTR_FORK); bp = NULL; error = xfs_da_grow_inode(args, &blkno); @@ -1003,7 +995,7 @@ xfs_attr_shortform_to_leaf( } error = 0; out: - kfree(tmpbuffer); + kfree(sf); return error; } From patchwork Tue Apr 30 12:49:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13648942 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C9EB17592 for ; Tue, 30 Apr 2024 12:49:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481380; cv=none; b=l+yAInUgwyRkvLL7FJjW5/B4OmQw7Orhe3gEFX/AWGeCLXNWBnbAgL99MRbr8kxa5nxTsTbQY7Rr4yUpKCFxyona/C7tOhwTyZNpOM6r1CSeeBBC41RcwG6LWLd7MMCLpfr6YJiquUcR7I2Q9if/7bObhpT3M/8/NZ6I9xpavIw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481380; c=relaxed/simple; bh=ByQ2paw3lCvCs8m2RawGJZ1dbquqkvo3DwpcSPRpl1Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nZWvx674XAk02bsexB8nhXrf5Mtdcl11kIkSOlv43HDE407+/OO6tMiFvqTNSZhy8QWge9OTriswLk7+uXB8jHvjsgTHtVYljuyuWeebm1WECFQdByrBlrtg6n3jX+qppxnsmgciz9Mo3Dezt9zpMmTlE86L+IpYFkR058LROq0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=bSYLkvHP; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="bSYLkvHP" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=Lw1QlIlo8n8YbxYcxV2TWEHM4cqB42SUKvArEpT37GE=; b=bSYLkvHPO2OTYOOLljRv2qo6P1 i3rODwS4zR6ymo+vNaUQRsBGp5VBckGjbcv0ZzqZfTnqWVSNypfLGhnj7qNrF+MycsdgPGl6XVFCy Bi2c1zL4iPsNnlK537YjN3/U0WW1hgwJZy74fQeYeWFdo7sVhK+NznJ8ycciE6SCP/bY8sKNqNU3w b/jvQJIRO4z6wsgZijjXkYH0oKyzW+fUImLervSDnq2HarLqCjBiW8UZrLXPeP0T8NTT2hBwVR5oh Jglbz2VK3905DLS+bVjIP7P2Pfd5U/w8KDVPTsUAZ1O2sxiSncWKowtzuwaFBWs7dHNWDsYj6faGU uBl5vxzw==; Received: from [2001:4bb8:188:7ba8:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1mvS-00000006NhT-37O1; Tue, 30 Apr 2024 12:49:39 +0000 From: Christoph Hellwig To: Chandan Babu R , "Darrick J. Wong" Cc: linux-xfs@vger.kernel.org Subject: [PATCH 03/16] xfs: rationalize dir2_sf entry condition asserts Date: Tue, 30 Apr 2024 14:49:13 +0200 Message-Id: <20240430124926.1775355-4-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240430124926.1775355-1-hch@lst.de> References: <20240430124926.1775355-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Various routines dealing with shortform directories have a similar pre-condition ASSERT boilerplate that does look a bit weird. Remove the assert that the inode fork is non-NULL as it doesn't buy anything over the NULL pointer dereference if it is. Remove the duplicate i_disk_size ASSERT that uses the less precise location of the parent inode number over the one using xfs_dir2_sf_hdr_size(). Remove the if_nextents assert in xfs_dir2_sf_to_block as that is implied by the local formt (and not checked by the other functions either). Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_dir2_block.c | 4 ---- fs/xfs/libxfs/xfs_dir2_sf.c | 12 ++---------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/fs/xfs/libxfs/xfs_dir2_block.c b/fs/xfs/libxfs/xfs_dir2_block.c index 0f93ed1a4a74f4..035a54dbdd7586 100644 --- a/fs/xfs/libxfs/xfs_dir2_block.c +++ b/fs/xfs/libxfs/xfs_dir2_block.c @@ -1105,12 +1105,8 @@ xfs_dir2_sf_to_block( trace_xfs_dir2_sf_to_block(args); ASSERT(ifp->if_format == XFS_DINODE_FMT_LOCAL); - ASSERT(dp->i_disk_size >= offsetof(struct xfs_dir2_sf_hdr, parent)); - ASSERT(ifp->if_bytes == dp->i_disk_size); - ASSERT(oldsfp != NULL); ASSERT(dp->i_disk_size >= xfs_dir2_sf_hdr_size(oldsfp->i8count)); - ASSERT(dp->i_df.if_nextents == 0); /* * Copy the directory into a temporary buffer. diff --git a/fs/xfs/libxfs/xfs_dir2_sf.c b/fs/xfs/libxfs/xfs_dir2_sf.c index 17a20384c8b719..1cd5228e1ce6af 100644 --- a/fs/xfs/libxfs/xfs_dir2_sf.c +++ b/fs/xfs/libxfs/xfs_dir2_sf.c @@ -378,9 +378,7 @@ xfs_dir2_sf_addname( ASSERT(xfs_dir2_sf_lookup(args) == -ENOENT); ASSERT(dp->i_df.if_format == XFS_DINODE_FMT_LOCAL); - ASSERT(dp->i_disk_size >= offsetof(struct xfs_dir2_sf_hdr, parent)); ASSERT(dp->i_df.if_bytes == dp->i_disk_size); - ASSERT(sfp != NULL); ASSERT(dp->i_disk_size >= xfs_dir2_sf_hdr_size(sfp->i8count)); /* * Compute entry (and change in) size. @@ -855,9 +853,7 @@ xfs_dir2_sf_lookup( xfs_dir2_sf_check(args); ASSERT(dp->i_df.if_format == XFS_DINODE_FMT_LOCAL); - ASSERT(dp->i_disk_size >= offsetof(struct xfs_dir2_sf_hdr, parent)); ASSERT(dp->i_df.if_bytes == dp->i_disk_size); - ASSERT(sfp != NULL); ASSERT(dp->i_disk_size >= xfs_dir2_sf_hdr_size(sfp->i8count)); /* * Special case for . @@ -920,21 +916,19 @@ xfs_dir2_sf_removename( struct xfs_inode *dp = args->dp; struct xfs_mount *mp = dp->i_mount; struct xfs_dir2_sf_hdr *sfp = dp->i_df.if_data; + int oldsize = dp->i_disk_size; int byteoff; /* offset of removed entry */ int entsize; /* this entry's size */ int i; /* shortform entry index */ int newsize; /* new inode size */ - int oldsize; /* old inode size */ xfs_dir2_sf_entry_t *sfep; /* shortform directory entry */ trace_xfs_dir2_sf_removename(args); ASSERT(dp->i_df.if_format == XFS_DINODE_FMT_LOCAL); - oldsize = (int)dp->i_disk_size; - ASSERT(oldsize >= offsetof(struct xfs_dir2_sf_hdr, parent)); ASSERT(dp->i_df.if_bytes == oldsize); - ASSERT(sfp != NULL); ASSERT(oldsize >= xfs_dir2_sf_hdr_size(sfp->i8count)); + /* * Loop over the old directory entries. * Find the one we're deleting. @@ -1028,9 +1022,7 @@ xfs_dir2_sf_replace( trace_xfs_dir2_sf_replace(args); ASSERT(dp->i_df.if_format == XFS_DINODE_FMT_LOCAL); - ASSERT(dp->i_disk_size >= offsetof(struct xfs_dir2_sf_hdr, parent)); ASSERT(dp->i_df.if_bytes == dp->i_disk_size); - ASSERT(sfp != NULL); ASSERT(dp->i_disk_size >= xfs_dir2_sf_hdr_size(sfp->i8count)); /* From patchwork Tue Apr 30 12:49:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13648943 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C3FC617592 for ; Tue, 30 Apr 2024 12:49:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481384; cv=none; b=jrnEiX4gFvHTFENlV0CTw7qT9XZKMx+gVygqVyM51T7g7A5NcxGpFG2tzx0ArNbX1mMt8vARKy7mPhzSYX7w8duLyKnH8gXnsTVJ/Fy4/OBJb8XYUMIvzrMHlomDl40Zk15WRewq6OPwXvG5Ce79INAnN/FmOUkHJA/KVN8VZPY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481384; c=relaxed/simple; bh=m6TfcAivtkNsXb5m3ky1zNIqFo4rSu+Df/iGS05CrzE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ppbYc48Dv7GbNOgj4nESkvvarmak6qVMu8SmU6VN3qMfW2TUetn4OT8M7kk7GLQSsfNINEO9SwFEvLLN/5EnefAq7JhJfNt5x1x9EBf5nIMV3p3dP8AYj0qvcDV4Rderni5PmC+uiLDNb0RIg2NjTmuYTBQN6Uv7QWYx53V1OMc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=ygaUgecu; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="ygaUgecu" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=ssTVYyVxAIprN1PwSjqvWdkwMf8c4cTYqGlxowoPPgs=; b=ygaUgecurr5HET5YHzuuNfoCz5 2WM5uOaOXGU1mxk+gKavX5yNg1qLEPLoI1EBkZhaIHUsCL7jbzsg4d4+tPw4dg+VmY6wuZ3642NTB WPCSCXqL436+ZDx19O762IiayEcnxbrX9gr5qWWEb2uu1OMg+4OcmNU82EDcgTIoJ+4nIYWWLwNKN JaJ/fdqsxftRUVGdXGZnEOmTgwyJNImDbrM3ncLrXMpZ7iwx/ZQzuJ1amjasrdn3jgrXs6eXgz97+ xt6eWRYygjLhMwyac+0XJBRSUzlJ3IYnk0bsVlzjDYKAO4IuliMxYXZRuUMH6DgVZZ1nFYWzClkPM UVxAoz5g==; Received: from [2001:4bb8:188:7ba8:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1mvV-00000006NiA-2VEB; Tue, 30 Apr 2024 12:49:42 +0000 From: Christoph Hellwig To: Chandan Babu R , "Darrick J. Wong" Cc: linux-xfs@vger.kernel.org Subject: [PATCH 04/16] xfs: remove an extra buffer allocation in xfs_dir2_sf_to_block Date: Tue, 30 Apr 2024 14:49:14 +0200 Message-Id: <20240430124926.1775355-5-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240430124926.1775355-1-hch@lst.de> References: <20240430124926.1775355-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Make use of the new ability to call xfs_bmap_local_to_extents_empty on a non-empty local fork to reuse the old inode fork data to build the directory block to replace the local temporary buffer. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_dir2_block.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/fs/xfs/libxfs/xfs_dir2_block.c b/fs/xfs/libxfs/xfs_dir2_block.c index 035a54dbdd7586..20d4e86e14ab08 100644 --- a/fs/xfs/libxfs/xfs_dir2_block.c +++ b/fs/xfs/libxfs/xfs_dir2_block.c @@ -1097,8 +1097,7 @@ xfs_dir2_sf_to_block( int newoffset; /* offset from current entry */ unsigned int offset = geo->data_entry_offset; xfs_dir2_sf_entry_t *sfep; /* sf entry pointer */ - struct xfs_dir2_sf_hdr *oldsfp = ifp->if_data; - xfs_dir2_sf_hdr_t *sfp; /* shortform header */ + struct xfs_dir2_sf_hdr *sfp = ifp->if_data; __be16 *tagp; /* end of data entry */ struct xfs_name name; @@ -1106,17 +1105,10 @@ xfs_dir2_sf_to_block( ASSERT(ifp->if_format == XFS_DINODE_FMT_LOCAL); ASSERT(ifp->if_bytes == dp->i_disk_size); - ASSERT(dp->i_disk_size >= xfs_dir2_sf_hdr_size(oldsfp->i8count)); + ASSERT(dp->i_disk_size >= xfs_dir2_sf_hdr_size(sfp->i8count)); - /* - * Copy the directory into a temporary buffer. - * Then pitch the incore inode data so we can make extents. - */ - sfp = kmalloc(ifp->if_bytes, GFP_KERNEL | __GFP_NOFAIL); - memcpy(sfp, oldsfp, ifp->if_bytes); + sfp = xfs_bmap_local_to_extents_empty(tp, dp, XFS_DATA_FORK); - xfs_idata_realloc(dp, -ifp->if_bytes, XFS_DATA_FORK); - xfs_bmap_local_to_extents_empty(tp, dp, XFS_DATA_FORK); dp->i_disk_size = 0; /* From patchwork Tue Apr 30 12:49:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13648944 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5FE4217592 for ; Tue, 30 Apr 2024 12:49:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481386; cv=none; b=ojPFEh9ptiKWg9exIhy5ROXv3jFMyL6voaHt4722FGmP/0RTyih/gNwqk3a8HKcM8xZCpgwoL9+dPNoMiGSrSUBP8+2Xiu4POtl8Z5don6zmTjojp+XlmXqOLY616csnWz3EwRGXAhVesX/YB88LmIYyZgfCy+j68M4gARTfyxo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481386; c=relaxed/simple; bh=TC5TkAOofh1IkDr7pP/Aa39/OyAv6TzQ8lp0q3H8wm0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UuYMOPzznM7mHPeDzE5Hzr7cAB2yfFDttcakbBLi9AlojmNE7taBpC/jSN7J8Vyche8+1UphZCAVope9KAff+ONjPlt2gTna9+6B2Zy4eTCdc5HjLae8N1IkcDL/RhSLBkI6+7e2gsXW5uLMCBvgxbRNvGjM9g5iBDmPPN+gREs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=J8Go+qpN; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="J8Go+qpN" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=aYhOywS1kMSN/f9+6kUT/enpURKtzoSQL+SDjUldOTg=; b=J8Go+qpNEXppq7dgr3f+mnFTDk iRtgFM8q6Wi1/biK7aXZc9b16MW7i3FNOwqzzTloIMf8oUaL5mhlyNyclqMgpEIcLz9b4KYNqwndi YcMvNqYVcRHpoSwVfOGtzYiB85IzGoejFD7J8GzryyTCyU4W470cjmRpDgwcpVBaBeathUVBMr3qU QlRkwMsUCyHDkWIAnLC6CRTrFly20MWDcXz4jy1jo2Mp64aF4TgkYH/mwJuncxTEQytBdlop2+P9r 6SvDw2/ChXl/6d2J7siNBnKM5+OB+WDh3yW2gvXdSCEHFaO+KR3pGU59fNbFNrpu9CawEGsb5I4u8 U8dL7kyw==; Received: from [2001:4bb8:188:7ba8:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1mvY-00000006Nit-2sSP; Tue, 30 Apr 2024 12:49:45 +0000 From: Christoph Hellwig To: Chandan Babu R , "Darrick J. Wong" Cc: linux-xfs@vger.kernel.org Subject: [PATCH 05/16] xfs: move the "does it fit" check into xfs_dir2_block_to_sf Date: Tue, 30 Apr 2024 14:49:15 +0200 Message-Id: <20240430124926.1775355-6-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240430124926.1775355-1-hch@lst.de> References: <20240430124926.1775355-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html All callers of xfs_dir2_block_to_sf first check if the block format directory would actually fit into the short format. Move this code into xfs_dir2_block_to_sf and rename the function to xfs_dir2_try_block_to_sf. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_dir2_block.c | 24 ++---------------------- fs/xfs/libxfs/xfs_dir2_priv.h | 5 +---- fs/xfs/libxfs/xfs_dir2_sf.c | 25 +++++++++++++++++-------- fs/xfs/libxfs/xfs_exchmaps.c | 8 +------- 4 files changed, 21 insertions(+), 41 deletions(-) diff --git a/fs/xfs/libxfs/xfs_dir2_block.c b/fs/xfs/libxfs/xfs_dir2_block.c index 20d4e86e14ab08..378d3aefdd9ced 100644 --- a/fs/xfs/libxfs/xfs_dir2_block.c +++ b/fs/xfs/libxfs/xfs_dir2_block.c @@ -795,8 +795,6 @@ xfs_dir2_block_removename( int error; /* error return value */ int needlog; /* need to log block header */ int needscan; /* need to fixup bestfree */ - xfs_dir2_sf_hdr_t sfh; /* shortform header */ - int size; /* shortform size */ xfs_trans_t *tp; /* transaction pointer */ trace_xfs_dir2_block_removename(args); @@ -845,17 +843,8 @@ xfs_dir2_block_removename( if (needlog) xfs_dir2_data_log_header(args, bp); xfs_dir3_data_check(dp, bp); - /* - * See if the size as a shortform is good enough. - */ - size = xfs_dir2_block_sfsize(dp, hdr, &sfh); - if (size > xfs_inode_data_fork_size(dp)) - return 0; - /* - * If it works, do the conversion. - */ - return xfs_dir2_block_to_sf(args, bp, size, &sfh); + return xfs_dir2_try_block_to_sf(args, bp); } /* @@ -944,7 +933,6 @@ xfs_dir2_leaf_to_block( xfs_mount_t *mp; /* file system mount point */ int needlog; /* need to log data header */ int needscan; /* need to scan for bestfree */ - xfs_dir2_sf_hdr_t sfh; /* shortform header */ int size; /* bytes used */ __be16 *tagp; /* end of entry (tag) */ int to; /* block/leaf to index */ @@ -1058,15 +1046,7 @@ xfs_dir2_leaf_to_block( error = xfs_da_shrink_inode(args, args->geo->leafblk, lbp); if (error) return error; - - /* - * Now see if the resulting block can be shrunken to shortform. - */ - size = xfs_dir2_block_sfsize(dp, hdr, &sfh); - if (size > xfs_inode_data_fork_size(dp)) - return 0; - - return xfs_dir2_block_to_sf(args, dbp, size, &sfh); + return xfs_dir2_try_block_to_sf(args, dbp); } /* diff --git a/fs/xfs/libxfs/xfs_dir2_priv.h b/fs/xfs/libxfs/xfs_dir2_priv.h index 3befb32509fa44..1e4401f9ec936e 100644 --- a/fs/xfs/libxfs/xfs_dir2_priv.h +++ b/fs/xfs/libxfs/xfs_dir2_priv.h @@ -167,10 +167,7 @@ uint8_t xfs_dir2_sf_get_ftype(struct xfs_mount *mp, struct xfs_dir2_sf_entry *sfep); struct xfs_dir2_sf_entry *xfs_dir2_sf_nextentry(struct xfs_mount *mp, struct xfs_dir2_sf_hdr *hdr, struct xfs_dir2_sf_entry *sfep); -extern int xfs_dir2_block_sfsize(struct xfs_inode *dp, - struct xfs_dir2_data_hdr *block, struct xfs_dir2_sf_hdr *sfhp); -extern int xfs_dir2_block_to_sf(struct xfs_da_args *args, struct xfs_buf *bp, - int size, xfs_dir2_sf_hdr_t *sfhp); +int xfs_dir2_try_block_to_sf(struct xfs_da_args *args, struct xfs_buf *bp); extern int xfs_dir2_sf_addname(struct xfs_da_args *args); extern int xfs_dir2_sf_create(struct xfs_da_args *args, xfs_ino_t pino); extern int xfs_dir2_sf_lookup(struct xfs_da_args *args); diff --git a/fs/xfs/libxfs/xfs_dir2_sf.c b/fs/xfs/libxfs/xfs_dir2_sf.c index 1cd5228e1ce6af..fad3fd28175368 100644 --- a/fs/xfs/libxfs/xfs_dir2_sf.c +++ b/fs/xfs/libxfs/xfs_dir2_sf.c @@ -163,7 +163,7 @@ xfs_dir2_sf_put_ftype( * space currently present in the inode. If it won't fit, the output * size is too big (but not accurate). */ -int /* size for sf form */ +static int /* size for sf form */ xfs_dir2_block_sfsize( xfs_inode_t *dp, /* incore inode pointer */ xfs_dir2_data_hdr_t *hdr, /* block directory data */ @@ -250,15 +250,12 @@ xfs_dir2_block_sfsize( } /* - * Convert a block format directory to shortform. - * Caller has already checked that it will fit, and built us a header. + * Try to convert a block format directory to shortform. */ int /* error */ -xfs_dir2_block_to_sf( +xfs_dir2_try_block_to_sf( struct xfs_da_args *args, /* operation arguments */ - struct xfs_buf *bp, - int size, /* shortform directory size */ - struct xfs_dir2_sf_hdr *sfhp) /* shortform directory hdr */ + struct xfs_buf *bp) { struct xfs_inode *dp = args->dp; struct xfs_mount *mp = dp->i_mount; @@ -267,8 +264,20 @@ xfs_dir2_block_to_sf( struct xfs_dir2_sf_entry *sfep; /* shortform entry */ struct xfs_dir2_sf_hdr *sfp; /* shortform directory header */ unsigned int offset = args->geo->data_entry_offset; + struct xfs_dir2_sf_hdr sfh; + int size; unsigned int end; + /* + * See if it would fit into the shortform format. If not we are done. + */ + size = xfs_dir2_block_sfsize(dp, bp->b_addr, &sfh); + if (size > xfs_inode_data_fork_size(dp)) + return 0; + + /* + * It would fit into the shortform formt, do the conversion now. + */ trace_xfs_dir2_block_to_sf(args); /* @@ -277,7 +286,7 @@ xfs_dir2_block_to_sf( * the block and copy the formatted data into the inode literal area. */ sfp = kmalloc(mp->m_sb.sb_inodesize, GFP_KERNEL | __GFP_NOFAIL); - memcpy(sfp, sfhp, xfs_dir2_sf_hdr_size(sfhp->i8count)); + memcpy(sfp, &sfh, xfs_dir2_sf_hdr_size(sfh.i8count)); /* * Loop over the active and unused entries. Stop when we reach the diff --git a/fs/xfs/libxfs/xfs_exchmaps.c b/fs/xfs/libxfs/xfs_exchmaps.c index 2021396651de27..bca6b6b0985464 100644 --- a/fs/xfs/libxfs/xfs_exchmaps.c +++ b/fs/xfs/libxfs/xfs_exchmaps.c @@ -463,9 +463,7 @@ xfs_exchmaps_dir_to_sf( .trans = tp, .owner = xmi->xmi_ip2->i_ino, }; - struct xfs_dir2_sf_hdr sfh; struct xfs_buf *bp; - int size; int error = 0; if (xfs_dir2_format(&args, &error) != XFS_DIR2_FMT_BLOCK) @@ -475,11 +473,7 @@ xfs_exchmaps_dir_to_sf( if (error) return error; - size = xfs_dir2_block_sfsize(xmi->xmi_ip2, bp->b_addr, &sfh); - if (size > xfs_inode_data_fork_size(xmi->xmi_ip2)) - return 0; - - return xfs_dir2_block_to_sf(&args, bp, size, &sfh); + return xfs_dir2_try_block_to_sf(&args, bp); } /* Convert inode2's remote symlink target back to shortform, if possible. */ From patchwork Tue Apr 30 12:49:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13648945 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D07E17592 for ; Tue, 30 Apr 2024 12:49:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481389; cv=none; b=XKSvraHOAIHLU667Ilk3kwl9ha8rW8dzDfxxOy1eBE07/DGTZcr0OmdrXKhkZJ+dFNkIz0OHXd2JXE9oUZ000qnED4Y5BFCYaL7Ju9BdBKNviCzdH6EkJuSg2xBuMcGduHHssHl5ZDSOaSYTgC9Noc56+HhDPVv6m31Dewhuxqc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481389; c=relaxed/simple; bh=cxUryCxKCKTWbh6yKAX4PK8gIXz9Iniq1MZAjgN/S0o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=evzTtba1842KDbUy+9ShypjauYbpwwzuJH/KPoN5ls2jaySn3ClW86XzAh3yr2uP6gqaP+BAUVi9zZw1RGe7b1patKswdxAdw2SOYEvYHp1J0yREGFDne68FxNzdYLy8EUrRqGgy9dQFbYDAVX3sIhKaEqXmw1FSqs9mdrihXs0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=v2bSO5QQ; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="v2bSO5QQ" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=JdP1xE0/Yffrrsz7zq7/Ib4Nuvl59nzDz49qauCStqE=; b=v2bSO5QQUZwBHSp6gBFPw83vYQ aIt+hQUOQSC2VSQ7pab0gT00GUUhGjDTRVpo+F5xQ9mZNtBq3tKVurIvVekmT3RKSNb/dM4Tsyllc 7YyRKqj+0vk7d+dDbZpaXpyGZlt8Tq+ruxKS+9AFfgEEHtZF/d99zdnPxPBXiHXu70jUus/KyUIkF cNhZ0pSiVn0E7R4AHGNa0UsZ7tB+lgExvieGuJjd/o1u3+fjwoq0tp4amHoHRw/dMV4niitoAPyjU EDvqnnqr6g4RavzuCrML9JiwXjXDwffyrcANYEDCYkazmNYb/vvCObXWV2IbT6RrEDvlymeemOlhc zXHmmsew==; Received: from [2001:4bb8:188:7ba8:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1mvb-00000006NjR-2Ec3; Tue, 30 Apr 2024 12:49:48 +0000 From: Christoph Hellwig To: Chandan Babu R , "Darrick J. Wong" Cc: linux-xfs@vger.kernel.org Subject: [PATCH 06/16] xfs: remove the buffer allocation size in xfs_dir2_try_block_to_sf Date: Tue, 30 Apr 2024 14:49:16 +0200 Message-Id: <20240430124926.1775355-7-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240430124926.1775355-1-hch@lst.de> References: <20240430124926.1775355-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html We've already calculated the size of the short form directory in the size variable when checking if it fits. Use that for the temporary buffer allocation instead of overallocating to the inode size. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_dir2_sf.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/xfs/libxfs/xfs_dir2_sf.c b/fs/xfs/libxfs/xfs_dir2_sf.c index fad3fd28175368..d02f1ddb1da92c 100644 --- a/fs/xfs/libxfs/xfs_dir2_sf.c +++ b/fs/xfs/libxfs/xfs_dir2_sf.c @@ -281,11 +281,11 @@ xfs_dir2_try_block_to_sf( trace_xfs_dir2_block_to_sf(args); /* - * Allocate a temporary destination buffer the size of the inode to - * format the data into. Once we have formatted the data, we can free - * the block and copy the formatted data into the inode literal area. + * Allocate a temporary destination buffer to format the data into. + * Once we have formatted the data, we can free the block and copy the + * formatted data into the inode literal area. */ - sfp = kmalloc(mp->m_sb.sb_inodesize, GFP_KERNEL | __GFP_NOFAIL); + sfp = kmalloc(size, GFP_KERNEL | __GFP_NOFAIL); memcpy(sfp, &sfh, xfs_dir2_sf_hdr_size(sfh.i8count)); /* From patchwork Tue Apr 30 12:49:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13648946 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 380C117592 for ; Tue, 30 Apr 2024 12:49:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481392; cv=none; b=bdRPmAn86WV1tqnQ6F9l6cpDdzenwS3EtZPQNkc2iM+tn92cN3VEy+akR5b9JUf3DBn4abR3TcvopuJ+aHu6iM+x17NOBZhw30jYn3n5zriL/+ifMvV7vBr2IxucBBiHn2tWdBEr0O80PvOGQG1gFfz4+ze+HyrCsOKm5SfUyn8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481392; c=relaxed/simple; bh=u9YZB8FGk6Am7O7JHcwfAWKntKFwuhI43eORmhSQLKQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=PQXFINR+vFGmvd+XZCYIb0Tma/COrZyvqDhwqzlBx0W6TteunXcDCPlT46D1A6hgUFNQCFr5/uh1HjJbfjo0azDLTmaf5YuEXZoJDMl5y1tfkhpXrbH7P+8gphdguKDhR/qdCWLSt9hRaHboieCSlUTBxaBev01DgMyuR5uMffY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=paeig1GA; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="paeig1GA" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=vOu9lzLJUWogYnk+hj7DAdg4UfzYN6tFCJ5qrJMnBxs=; b=paeig1GAR4fXScKKifa8D6q4Cj OsHerB89r6hZkzkDJYUXaYZtvBqWvnsJgFBekvNs7P0PPkjqLCsgO5y+4pTD4YAeuP8DLymNpSCRY YX8FL3U6whZgUFimgYl+8QlVzzhEXOR3jkdtnQWErUr1CrlK3MjPlxFduJor+HUw+sBIut2xtuY9Y ANrUfVozV1Ck2EUEvUPVaLcl6U864SamvHePUFR92LTE6670nsVATY4002IqR+gyA1GgnBKXOjOJs /mqWM8K6DAS7JwphtOaRv07J+VzIxmZ7P8oTRr8onG34y3SR08d8SymZBlErEsvoLl7KA1bTJnkrW WDb78Rkw==; Received: from [2001:4bb8:188:7ba8:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1mve-00000006NkR-1XEd; Tue, 30 Apr 2024 12:49:50 +0000 From: Christoph Hellwig To: Chandan Babu R , "Darrick J. Wong" Cc: linux-xfs@vger.kernel.org Subject: [PATCH 07/16] xfs: remove a superfluous memory allocation in xfs_dir2_block_to_sf Date: Tue, 30 Apr 2024 14:49:17 +0200 Message-Id: <20240430124926.1775355-8-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240430124926.1775355-1-hch@lst.de> References: <20240430124926.1775355-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Transfer the temporary buffer allocation to the inode fork instead of copying to it. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_dir2_sf.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/fs/xfs/libxfs/xfs_dir2_sf.c b/fs/xfs/libxfs/xfs_dir2_sf.c index d02f1ddb1da92c..164ae1684816b6 100644 --- a/fs/xfs/libxfs/xfs_dir2_sf.c +++ b/fs/xfs/libxfs/xfs_dir2_sf.c @@ -281,9 +281,8 @@ xfs_dir2_try_block_to_sf( trace_xfs_dir2_block_to_sf(args); /* - * Allocate a temporary destination buffer to format the data into. - * Once we have formatted the data, we can free the block and copy the - * formatted data into the inode literal area. + * Allocate the shortform buffer now. It will be transferred to the + * inode fork once we are done. */ sfp = kmalloc(size, GFP_KERNEL | __GFP_NOFAIL); memcpy(sfp, &sfh, xfs_dir2_sf_hdr_size(sfh.i8count)); @@ -341,25 +340,23 @@ xfs_dir2_try_block_to_sf( error = xfs_dir2_shrink_inode(args, args->geo->datablk, bp); if (error) { ASSERT(error != -ENOSPC); + kfree(sfp); goto out; } /* - * The buffer is now unconditionally gone, whether - * xfs_dir2_shrink_inode worked or not. - * - * Convert the inode to local format and copy the data in. + * Update the data fork format and transfer buffer ownership to the + * inode fork. */ - ASSERT(dp->i_df.if_bytes == 0); - xfs_init_local_fork(dp, XFS_DATA_FORK, sfp, size); dp->i_df.if_format = XFS_DINODE_FMT_LOCAL; + dp->i_df.if_data = sfp; + dp->i_df.if_bytes = size; dp->i_disk_size = size; logflags |= XFS_ILOG_DDATA; xfs_dir2_sf_check(args); out: xfs_trans_log_inode(args->trans, dp, logflags); - kfree(sfp); return error; } From patchwork Tue Apr 30 12:49:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13648947 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5FD4E17592 for ; Tue, 30 Apr 2024 12:49:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481395; cv=none; b=qG+nS4EnIl0hTaTdB+GkjcJcSH8+FjTIHNhHB5r7yF934vHlpam+mYNP3o6gGNXYhQT/r9u6+gjgU9V+ot0Y04CoGnkr8/knDs+qDLBKnvES8ohH9UCyPTisd/GJNdgATiEO272YbWGXLsRgLZcrwIVXBhLTHgAOa4ERhkHZWg0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481395; c=relaxed/simple; bh=KsVmBDpk8WE90z/wLz9LIoytIBOPszCnUVulQOeZKh8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nJdxRxgrcOYYNV514nVMWU0rkXcSXL4p7qnsm+UzeVwXGezC1p4R1NZmyBXYvomE8ZC+qp5swJctI7eWTqwXUEQoxtMMdFZSFN463pugei8fvbniyxWn2Kx2SDYHSmwedK7zwQdNFUbeg7ipXC/SyVWJNfDxcmUOqxiU059NCdo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=LLAKE2zp; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="LLAKE2zp" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=K02Q8RNmVx6CULPgX5Hpgse4SZ9DfpqYV4NAYsFaQQI=; b=LLAKE2zpsQdAHus1KNRipnUCwX crI/zx1ztWR2Pev4rnh58Ap3Ei7VoJNyWhyriJCJNDpzYv62QG35FTwY8QaWNz7hmmOQFJj4IVFtY 2Kz4tIF+kxfzEqHexq4zwxjdWsYlD6urYELvDZUMpO66eeYEIteMTJ/GLvTEUIbMFlXjaLfQhnRut NgXMT19tEuoaLKbX45LmQpLRLQ+K05TUZnzqH9VhYlKd4TtUob4jJlhXfV+8Pt3OsnwA+f3xLz8Q0 6XxiOWa2iEVvO7pEh9Fe4Rj3bKOM2zPWi5sRd//nXPuUwzZuyW4JdxA0jv8QfpFl8we09nCatxzi7 fyM5zutQ==; Received: from [2001:4bb8:188:7ba8:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1mvh-00000006Nl1-1E1k; Tue, 30 Apr 2024 12:49:53 +0000 From: Christoph Hellwig To: Chandan Babu R , "Darrick J. Wong" Cc: linux-xfs@vger.kernel.org Subject: [PATCH 08/16] xfs: remove a superfluous memory allocation in xfs_dir2_sf_toino8 Date: Tue, 30 Apr 2024 14:49:18 +0200 Message-Id: <20240430124926.1775355-9-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240430124926.1775355-1-hch@lst.de> References: <20240430124926.1775355-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Transfer the temporary buffer allocation to the inode fork instead of copying to it. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_dir2_sf.c | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/fs/xfs/libxfs/xfs_dir2_sf.c b/fs/xfs/libxfs/xfs_dir2_sf.c index 164ae1684816b6..87552c01260a1c 100644 --- a/fs/xfs/libxfs/xfs_dir2_sf.c +++ b/fs/xfs/libxfs/xfs_dir2_sf.c @@ -1205,36 +1205,25 @@ xfs_dir2_sf_toino8( struct xfs_inode *dp = args->dp; struct xfs_mount *mp = dp->i_mount; struct xfs_dir2_sf_hdr *oldsfp = dp->i_df.if_data; - char *buf; /* old dir's buffer */ + int oldsize = dp->i_df.if_bytes; int i; /* entry index */ int newsize; /* new inode size */ xfs_dir2_sf_entry_t *oldsfep; /* old sf entry */ - int oldsize; /* old inode size */ xfs_dir2_sf_entry_t *sfep; /* new sf entry */ xfs_dir2_sf_hdr_t *sfp; /* new sf directory */ trace_xfs_dir2_sf_toino8(args); - /* - * Copy the old directory to the buffer. - * Then nuke it from the inode, and add the new buffer to the inode. - * Don't want xfs_idata_realloc copying the data here. - */ - oldsize = dp->i_df.if_bytes; - buf = kmalloc(oldsize, GFP_KERNEL | __GFP_NOFAIL); ASSERT(oldsfp->i8count == 0); - memcpy(buf, oldsfp, oldsize); + /* * Compute the new inode size (nb: entry count + 1 for parent) */ newsize = oldsize + (oldsfp->count + 1) * XFS_INO64_DIFF; - xfs_idata_realloc(dp, -oldsize, XFS_DATA_FORK); - xfs_idata_realloc(dp, newsize, XFS_DATA_FORK); - /* - * Reset our pointers, the data has moved. - */ - oldsfp = (xfs_dir2_sf_hdr_t *)buf; - sfp = dp->i_df.if_data; + + dp->i_df.if_data = sfp = kmalloc(newsize, GFP_KERNEL | __GFP_NOFAIL); + dp->i_df.if_bytes = newsize; + /* * Fill in the new header. */ @@ -1257,10 +1246,8 @@ xfs_dir2_sf_toino8( xfs_dir2_sf_put_ftype(mp, sfep, xfs_dir2_sf_get_ftype(mp, oldsfep)); } - /* - * Clean up the inode. - */ - kfree(buf); + + kfree(oldsfp); dp->i_disk_size = newsize; xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE | XFS_ILOG_DDATA); } From patchwork Tue Apr 30 12:49:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13648948 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 199BD17592 for ; Tue, 30 Apr 2024 12:49:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481398; cv=none; b=SehPOzXu9fYoLyZ+EyHIT5z6XorMYU12pC2Lpi0Uk3hp2wQuPpZ+wUuA4vhC8+vtSuVuXZ0Ng/ZRyWOrEe958djE7eRd1ZvpHt0ZBMa4Qct8HwaNJTFffPJr7qU5OQRuQio35wh4mQhVXEBqofVnRJS4raSqN8kvAQWw9yc8uNI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481398; c=relaxed/simple; bh=pJZkmzBr6ISQVwMBPLCNPrm6haWfEf4TKJ79y0a21HQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tGbKkWpvesK1vSs+tmDiXVXq0apsoLh/Um7yQMhH41eO67pgxAXBz1UvByU57JaaYRz9YeDUdK5RrbwPFJ1A20cQZcoa6zSAIk8d4xOS7zvut47beOq2uqKPR1o6NKU7hsNoEo9QpPLqoWWdH33H0NprdCxqZQsPalFNJ5C3D9Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=vFwDRFBP; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="vFwDRFBP" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=J91CyDJKyKV4tKglaK1Z1i9F/2QJIGaKXeKDn5QuaVM=; b=vFwDRFBPowmT7TYgBs1MUKOjXb O6/HVlUMglDLnIscjB5Rq4haJoSldFFkAWa0ADpvjCy4tZwA6SzDCGlwo/sN8dP+UlVgx9rfkTqo6 RDvooCwwexxnLPJBbXN5a25blKtTBGB03MosBAjgA8v51PAWVFSbeWMES8pu53+3JEowEQjk2XDky +vtJxWVRXf2dC3D22gIFnCfS/BlOSvl3EvGnZZ/Y7eeKr8rERgvqFvzv/YGwTqQj4UITvRftRuxDZ 5MEWRAz5OcFD9OSYXRdPJOrzQsNHd+VDb+2o6y75fO/AMhuQrOu8D6A28f8orVVVNl2h6OQd2ls6X 24JHHUFg==; Received: from [2001:4bb8:188:7ba8:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1mvk-00000006NlK-1X8u; Tue, 30 Apr 2024 12:49:56 +0000 From: Christoph Hellwig To: Chandan Babu R , "Darrick J. Wong" Cc: linux-xfs@vger.kernel.org Subject: [PATCH 09/16] xfs: remove a superfluous memory allocation in xfs_dir2_sf_toino4 Date: Tue, 30 Apr 2024 14:49:19 +0200 Message-Id: <20240430124926.1775355-10-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240430124926.1775355-1-hch@lst.de> References: <20240430124926.1775355-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Transfer the temporary buffer allocation to the inode fork instead of copying to it. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_dir2_sf.c | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/fs/xfs/libxfs/xfs_dir2_sf.c b/fs/xfs/libxfs/xfs_dir2_sf.c index 87552c01260a1c..3b6d6dda92f29f 100644 --- a/fs/xfs/libxfs/xfs_dir2_sf.c +++ b/fs/xfs/libxfs/xfs_dir2_sf.c @@ -1133,36 +1133,25 @@ xfs_dir2_sf_toino4( struct xfs_inode *dp = args->dp; struct xfs_mount *mp = dp->i_mount; struct xfs_dir2_sf_hdr *oldsfp = dp->i_df.if_data; - char *buf; /* old dir's buffer */ + int oldsize = dp->i_df.if_bytes; int i; /* entry index */ int newsize; /* new inode size */ xfs_dir2_sf_entry_t *oldsfep; /* old sf entry */ - int oldsize; /* old inode size */ xfs_dir2_sf_entry_t *sfep; /* new sf entry */ xfs_dir2_sf_hdr_t *sfp; /* new sf directory */ trace_xfs_dir2_sf_toino4(args); - /* - * Copy the old directory to the buffer. - * Then nuke it from the inode, and add the new buffer to the inode. - * Don't want xfs_idata_realloc copying the data here. - */ - oldsize = dp->i_df.if_bytes; - buf = kmalloc(oldsize, GFP_KERNEL | __GFP_NOFAIL); ASSERT(oldsfp->i8count == 1); - memcpy(buf, oldsfp, oldsize); + /* * Compute the new inode size. */ newsize = oldsize - (oldsfp->count + 1) * XFS_INO64_DIFF; - xfs_idata_realloc(dp, -oldsize, XFS_DATA_FORK); - xfs_idata_realloc(dp, newsize, XFS_DATA_FORK); - /* - * Reset our pointers, the data has moved. - */ - oldsfp = (xfs_dir2_sf_hdr_t *)buf; - sfp = dp->i_df.if_data; + + dp->i_df.if_data = sfp = kmalloc(newsize, GFP_KERNEL | __GFP_NOFAIL); + dp->i_df.if_bytes = newsize; + /* * Fill in the new header. */ @@ -1185,10 +1174,8 @@ xfs_dir2_sf_toino4( xfs_dir2_sf_put_ftype(mp, sfep, xfs_dir2_sf_get_ftype(mp, oldsfep)); } - /* - * Clean up the inode. - */ - kfree(buf); + + kfree(oldsfp); dp->i_disk_size = newsize; xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE | XFS_ILOG_DDATA); } From patchwork Tue Apr 30 12:49:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13648949 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1FE88171096 for ; Tue, 30 Apr 2024 12:50:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481401; cv=none; b=iCMYoo67R69aRgAqzaP0ktV10E9lkDmAlj5VZHfO3uFf3yyIkZUr7KvH/izt/jRNv68zF2CnzhnNy2rZHv5PsUkIpZpsbGIB+sMIHjdtJk7M6anYJrCyYXgxrxQ6MAnH3FYYslQnnde81znS532qlBSnQYhqmbTGf/h8jLPV8+A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481401; c=relaxed/simple; bh=Tg1yzlGJFBz4oR19sUBymvIseE8UJ9sT5iIGfV/GbeQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DJiQvJfIVA54MIYj4hdwbluokib/eS5Qxi5r1xumwxBTwUDNnQqfmy+lL3eygmqTIVWYcrewsxpRGWa8c2wI6HJ5g6lZpRd+xiU9beLR5HcyoaIbRBP+PjUezdYFEzWDgp0EOfVsv475B9R+rlvP3e3pvNBprZomJbMFsIkXtZk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=OAOVLa68; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="OAOVLa68" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=6oqexfbvenAiAelP7Qw382h+gwFKlIzCmN8NYMQ0SW4=; b=OAOVLa68aPRcjI4KCJH7SLZXpA U1di1hLA8P4xbvZNs4ct4zj2vR+Ybt0JUV8FvbA+u2SsTetjJbn5EmnbvYOeSq/JagT3GilffiWBD Dp9POh7rv1E3EMdQNvt883vZGQm/ps0SocqbmL8UVy+Cd/w0TPagunc/DWfX0TftvxpmaI8NzwPaW YzNrPuwpuJez3rlvLKR2VeK9/WwPh5poAX5eg7QFa3qp6ahp2/Pri6msht/paPWrM82jV6KC4LBT3 9QuYbvqJ9BdC6nEVX8qLMn4gcNXxWw8aEr73KMojBZklAp8XJmDYOc8W49Svzraxcl8vWG5xW3GY4 7T4ieMMA==; Received: from [2001:4bb8:188:7ba8:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1mvn-00000006NmF-0en8; Tue, 30 Apr 2024 12:49:59 +0000 From: Christoph Hellwig To: Chandan Babu R , "Darrick J. Wong" Cc: linux-xfs@vger.kernel.org Subject: [PATCH 10/16] xfs: optimize removing the last 8-byte inode from a shortform directory Date: Tue, 30 Apr 2024 14:49:20 +0200 Message-Id: <20240430124926.1775355-11-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240430124926.1775355-1-hch@lst.de> References: <20240430124926.1775355-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html When removing the last 8-byte inode, xfs_dir2_sf_removename calls xfs_dir2_sf_toino4 after removing the entry. This is rather inefficient as it causes two buffer realloacations. Instead of that pass a bool argument to xfs_dir2_sf_toino4 so that it can remove the entry pointed to by args as part of the conversion and use that to shortcut the process. Signed-off-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_dir2_sf.c | 41 ++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/fs/xfs/libxfs/xfs_dir2_sf.c b/fs/xfs/libxfs/xfs_dir2_sf.c index 3b6d6dda92f29f..21e04594606b89 100644 --- a/fs/xfs/libxfs/xfs_dir2_sf.c +++ b/fs/xfs/libxfs/xfs_dir2_sf.c @@ -34,7 +34,7 @@ static void xfs_dir2_sf_check(xfs_da_args_t *args); #define xfs_dir2_sf_check(args) #endif /* DEBUG */ -static void xfs_dir2_sf_toino4(xfs_da_args_t *args); +static void xfs_dir2_sf_toino4(struct xfs_da_args *args, bool remove); static void xfs_dir2_sf_toino8(xfs_da_args_t *args); int @@ -935,6 +935,15 @@ xfs_dir2_sf_removename( ASSERT(dp->i_df.if_bytes == oldsize); ASSERT(oldsize >= xfs_dir2_sf_hdr_size(sfp->i8count)); + /* + * If this is the last 8-byte, directly convert to the 4-byte format + * and just skip the removed entry when building the new fork. + */ + if (args->inumber > XFS_DIR2_MAX_SHORT_INUM && sfp->i8count == 1) { + xfs_dir2_sf_toino4(args, true); + return 0; + } + /* * Loop over the old directory entries. * Find the one we're deleting. @@ -980,10 +989,8 @@ xfs_dir2_sf_removename( * Are we changing inode number size? */ if (args->inumber > XFS_DIR2_MAX_SHORT_INUM) { - if (sfp->i8count == 1) - xfs_dir2_sf_toino4(args); - else - sfp->i8count--; + ASSERT(sfp->i8count > 1); + sfp->i8count--; } xfs_dir2_sf_check(args); xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE | XFS_ILOG_DDATA); @@ -1087,7 +1094,7 @@ xfs_dir2_sf_replace( if (i == sfp->count) { ASSERT(args->op_flags & XFS_DA_OP_OKNOENT); if (i8elevated) - xfs_dir2_sf_toino4(args); + xfs_dir2_sf_toino4(args, false); return -ENOENT; } } @@ -1100,7 +1107,7 @@ xfs_dir2_sf_replace( * And the old count was one, so need to convert to small. */ if (sfp->i8count == 1) - xfs_dir2_sf_toino4(args); + xfs_dir2_sf_toino4(args, false); else sfp->i8count--; } @@ -1128,7 +1135,8 @@ xfs_dir2_sf_replace( */ static void xfs_dir2_sf_toino4( - xfs_da_args_t *args) /* operation arguments */ + struct xfs_da_args *args, + bool remove) { struct xfs_inode *dp = args->dp; struct xfs_mount *mp = dp->i_mount; @@ -1148,6 +1156,8 @@ xfs_dir2_sf_toino4( * Compute the new inode size. */ newsize = oldsize - (oldsfp->count + 1) * XFS_INO64_DIFF; + if (remove) + newsize -= xfs_dir2_sf_entsize(mp, oldsfp, args->namelen); dp->i_df.if_data = sfp = kmalloc(newsize, GFP_KERNEL | __GFP_NOFAIL); dp->i_df.if_bytes = newsize; @@ -1166,11 +1176,22 @@ xfs_dir2_sf_toino4( i < sfp->count; i++, sfep = xfs_dir2_sf_nextentry(mp, sfp, sfep), oldsfep = xfs_dir2_sf_nextentry(mp, oldsfp, oldsfep)) { + xfs_ino_t ino = xfs_dir2_sf_get_ino(mp, oldsfp, oldsfep); + + /* + * Just skip over the entry that is removed if there is one. + */ + if (remove && args->inumber == ino) { + oldsfep = xfs_dir2_sf_nextentry(mp, oldsfp, oldsfep); + sfp->count--; + if (++i == sfp->count) + break; + } + sfep->namelen = oldsfep->namelen; memcpy(sfep->offset, oldsfep->offset, sizeof(sfep->offset)); memcpy(sfep->name, oldsfep->name, sfep->namelen); - xfs_dir2_sf_put_ino(mp, sfp, sfep, - xfs_dir2_sf_get_ino(mp, oldsfp, oldsfep)); + xfs_dir2_sf_put_ino(mp, sfp, sfep, ino); xfs_dir2_sf_put_ftype(mp, sfep, xfs_dir2_sf_get_ftype(mp, oldsfep)); } From patchwork Tue Apr 30 12:49:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13648950 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C11A42AA5 for ; Tue, 30 Apr 2024 12:50:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481404; cv=none; b=EkyUS6IPn3ECL8wfzEPnk1Eo21LHEkabRlBkELaFhGbS9JuspR1Z/yQVR455XlvyQnOcD2E5gGCey53fgqbpvHnVenGKZjYHcyt7VNLp6pceB2Q6A0LsAdAm1QS/7SQmFyoVVpKiqxsIFnhtJ3s9aZYnN4gDxdTEpmJ74xvd5TU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481404; c=relaxed/simple; bh=FzY/3Qr09bgxYTuyh+tM22eVA4qyLDsTZuKT1bUYjeg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gjkpRWEJKVXqSg1g/5SJl4DKa3lRNh1eOPrRbe4ey/M6vMWojaW7DjNnLFGynGhQ68wFBEzDhbCnXpFaJYX7aXwnwq0oBnCphL88triiO7Dq7OAf412PC73gvCX0jyt4j5GfT6k3arDiZDhFlTiM4Van2sMQ00A3Ni0CeZF/X7M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=wiXmTltI; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="wiXmTltI" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=tUZhw11I4Qd5Ll72R+8T1RodFkECbuidGFWdPFV4hH8=; b=wiXmTltID89v3jIIZP+jV4Jd8V VCzoXMNevtbPwinaYPD1dBUmDJSiUnDJgaklZDpoYvH5Ee3xVbiKM91FtRm3pjvblxLI3y6+hynyQ fK0736tRaxQfV0/DNlZiJKBsmdgBT6CnqleNKYZK7TgtP86x55k4nKQ0W72Xurwhha/8J8ztUXZVe 7VEw0iOhNxGkU3NZ6+RSZRDt92rtlyjPrZzZaviWlJq1jSrAYsW1Oq8galRnlPvQYIbhTk1ZA+dkq OK1Whag6sao4LM+XaIBFKEhzJkqkPSy+1HqOSOOMkjjBcrxuyMFuywHtR8K1M17xvxr7s141XASHM pewWRkTQ==; Received: from [2001:4bb8:188:7ba8:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1mvq-00000006Nmu-1KBl; Tue, 30 Apr 2024 12:50:02 +0000 From: Christoph Hellwig To: Chandan Babu R , "Darrick J. Wong" Cc: linux-xfs@vger.kernel.org Subject: [PATCH 11/16] xfs: add xfs_dir2_block_overhead helper Date: Tue, 30 Apr 2024 14:49:21 +0200 Message-Id: <20240430124926.1775355-12-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240430124926.1775355-1-hch@lst.de> References: <20240430124926.1775355-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Add a common helper for the calculation of the overhead when converting a shortform to block format directory. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_dir2_block.c | 4 ++-- fs/xfs/libxfs/xfs_dir2_priv.h | 12 ++++++++++++ fs/xfs/libxfs/xfs_dir2_sf.c | 12 ++++-------- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/fs/xfs/libxfs/xfs_dir2_block.c b/fs/xfs/libxfs/xfs_dir2_block.c index 378d3aefdd9ced..a19744cb43ca0c 100644 --- a/fs/xfs/libxfs/xfs_dir2_block.c +++ b/fs/xfs/libxfs/xfs_dir2_block.c @@ -1109,8 +1109,8 @@ xfs_dir2_sf_to_block( /* * Compute size of block "tail" area. */ - i = (uint)sizeof(*btp) + - (sfp->count + 2) * (uint)sizeof(xfs_dir2_leaf_entry_t); + i = xfs_dir2_block_overhead(sfp->count); + /* * The whole thing is initialized to free by the init routine. * Say we're using the leaf and tail area. diff --git a/fs/xfs/libxfs/xfs_dir2_priv.h b/fs/xfs/libxfs/xfs_dir2_priv.h index 1e4401f9ec936e..bfbc73251f275a 100644 --- a/fs/xfs/libxfs/xfs_dir2_priv.h +++ b/fs/xfs/libxfs/xfs_dir2_priv.h @@ -205,4 +205,16 @@ xfs_dahash_t xfs_dir2_hashname(struct xfs_mount *mp, enum xfs_dacmp xfs_dir2_compname(struct xfs_da_args *args, const unsigned char *name, int len); +/* + * Overhead if we converted a shortform directory to block format. + * + * The extra two entries are because "." and ".." don't have real entries in + * the shortform format. + */ +static inline unsigned int xfs_dir2_block_overhead(unsigned int count) +{ + return (count + 2) * sizeof(struct xfs_dir2_leaf_entry) + + sizeof(struct xfs_dir2_block_tail); +} + #endif /* __XFS_DIR2_PRIV_H__ */ diff --git a/fs/xfs/libxfs/xfs_dir2_sf.c b/fs/xfs/libxfs/xfs_dir2_sf.c index 21e04594606b89..1e1dcdf83b8f95 100644 --- a/fs/xfs/libxfs/xfs_dir2_sf.c +++ b/fs/xfs/libxfs/xfs_dir2_sf.c @@ -629,9 +629,7 @@ xfs_dir2_sf_addname_pick( * Calculate data bytes used excluding the new entry, if this * was a data block (block form directory). */ - used = offset + - (sfp->count + 3) * (uint)sizeof(xfs_dir2_leaf_entry_t) + - (uint)sizeof(xfs_dir2_block_tail_t); + used = offset + xfs_dir2_block_overhead(sfp->count + 1); /* * If it won't fit in a block form then we can't insert it, * we'll go back, convert to block, then try the insert and convert @@ -691,9 +689,7 @@ xfs_dir2_sf_check( } ASSERT(i8count == sfp->i8count); ASSERT((char *)sfep - (char *)sfp == dp->i_disk_size); - ASSERT(offset + - (sfp->count + 2) * (uint)sizeof(xfs_dir2_leaf_entry_t) + - (uint)sizeof(xfs_dir2_block_tail_t) <= args->geo->blksize); + ASSERT(offset + xfs_dir2_block_overhead(sfp->count)); } #endif /* DEBUG */ @@ -782,8 +778,8 @@ xfs_dir2_sf_verify( return __this_address; /* Make sure this whole thing ought to be in local format. */ - if (offset + (sfp->count + 2) * (uint)sizeof(xfs_dir2_leaf_entry_t) + - (uint)sizeof(xfs_dir2_block_tail_t) > mp->m_dir_geo->blksize) + if (offset + xfs_dir2_block_overhead(sfp->count) > + mp->m_dir_geo->blksize) return __this_address; return NULL; From patchwork Tue Apr 30 12:49:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13648951 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35A6617592 for ; Tue, 30 Apr 2024 12:50:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481407; cv=none; b=U9oh3+57LHmfX8UTfx+AoQRIiBf93tWxnxW4SGqfvdaokKfCn2HO6MuAxJhntBTL3TnKGtTbn768RFIH5d8UmznBGQwqmZtQva5GuIPLN8JfWXbyRKY0uTVPliE7D6MxUCUBvbB5EkrokjCEY3puPBXHlY5cr+VqHlg89K8pYHk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481407; c=relaxed/simple; bh=eRcU4iIIY57N4vn62f6u7OXzLWWgVe8Oknqlh12TEjg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ndI6FAO0Coa+QSBQUy/q6DgU3j54DqOINTaIOljEuUHVlvTS8ZTgEXoytE/oxY+1I2m7FQV3cK1J3z2o03vM5Y4xu8OgFCqhuWRR8PVK86NCuzvXXSYug9ri9sE8voCVpOQsv/SnblcR3o/pAW6LGYuN/ZwwDLUz94/lNo3Sgcg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=esMwyAr3; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="esMwyAr3" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=hAxpc4jiPSEvUyDRqmT+Unkp8CiVyVygMLF9vfEjJH8=; b=esMwyAr3Ib2L5Y2BWNsFv8YX7t 40Z38yb/tDwZ6CTRLoa3lmEogjCGzaeyW5/ojP3sMEZATakb97P7dLyLz9S5OIQ8E7HNPkrz0PLoZ tseUiPMhcsgVjj13nlcOQnC7kJho4hJkXyYfvvZx145Lae7QB+sGvfQddd2VSKsfRLVcxhOmf3vqj DN1mZ3cvjfE4EWRENVEWY9Z1iW7TSeMR3aUj6G1BmXKlm1Fd6BtAOsJmpObkW56o27RimqqyE6qLZ TwN7oLxL9m5nN8uac+1fbI2IW4xPFhjdpHp+SOTK3REK8R/wEezhhnouyhneA5tn5voLgg6/JAfdR aoNT7ImA==; Received: from [2001:4bb8:188:7ba8:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1mvt-00000006NnT-1a6w; Tue, 30 Apr 2024 12:50:05 +0000 From: Christoph Hellwig To: Chandan Babu R , "Darrick J. Wong" Cc: linux-xfs@vger.kernel.org Subject: [PATCH 12/16] xfs: factor out a xfs_dir2_sf_addname_common helper Date: Tue, 30 Apr 2024 14:49:22 +0200 Message-Id: <20240430124926.1775355-13-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240430124926.1775355-1-hch@lst.de> References: <20240430124926.1775355-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Move the common code between the easy and hard cases into a common helper. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_dir2_sf.c | 48 +++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/fs/xfs/libxfs/xfs_dir2_sf.c b/fs/xfs/libxfs/xfs_dir2_sf.c index 1e1dcdf83b8f95..43e1090082b45d 100644 --- a/fs/xfs/libxfs/xfs_dir2_sf.c +++ b/fs/xfs/libxfs/xfs_dir2_sf.c @@ -360,6 +360,27 @@ xfs_dir2_try_block_to_sf( return error; } +static void +xfs_dir2_sf_addname_common( + struct xfs_da_args *args, + struct xfs_dir2_sf_entry *sfep, + xfs_dir2_data_aoff_t offset, + bool objchange) +{ + struct xfs_inode *dp = args->dp; + struct xfs_mount *mp = dp->i_mount; + struct xfs_dir2_sf_hdr *sfp = dp->i_df.if_data; + + sfep->namelen = args->namelen; + xfs_dir2_sf_put_offset(sfep, offset); + memcpy(sfep->name, args->name, sfep->namelen); + xfs_dir2_sf_put_ino(mp, sfp, sfep, args->inumber); + xfs_dir2_sf_put_ftype(mp, sfep, args->filetype); + sfp->count++; + if (args->inumber > XFS_DIR2_MAX_SHORT_INUM && !objchange) + sfp->i8count++; +} + /* * Add a name to a shortform directory. * There are two algorithms, "easy" and "hard" which we decide on @@ -476,21 +497,7 @@ xfs_dir2_sf_addname_easy( * Need to set up again due to realloc of the inode data. */ sfep = (xfs_dir2_sf_entry_t *)((char *)sfp + byteoff); - /* - * Fill in the new entry. - */ - sfep->namelen = args->namelen; - xfs_dir2_sf_put_offset(sfep, offset); - memcpy(sfep->name, args->name, sfep->namelen); - xfs_dir2_sf_put_ino(mp, sfp, sfep, args->inumber); - xfs_dir2_sf_put_ftype(mp, sfep, args->filetype); - - /* - * Update the header and inode. - */ - sfp->count++; - if (args->inumber > XFS_DIR2_MAX_SHORT_INUM) - sfp->i8count++; + xfs_dir2_sf_addname_common(args, sfep, offset, false); dp->i_disk_size = new_isize; xfs_dir2_sf_check(args); } @@ -562,17 +569,12 @@ xfs_dir2_sf_addname_hard( nbytes = (int)((char *)oldsfep - (char *)oldsfp); memcpy(sfp, oldsfp, nbytes); sfep = (xfs_dir2_sf_entry_t *)((char *)sfp + nbytes); + /* * Fill in the new entry, and update the header counts. */ - sfep->namelen = args->namelen; - xfs_dir2_sf_put_offset(sfep, offset); - memcpy(sfep->name, args->name, sfep->namelen); - xfs_dir2_sf_put_ino(mp, sfp, sfep, args->inumber); - xfs_dir2_sf_put_ftype(mp, sfep, args->filetype); - sfp->count++; - if (args->inumber > XFS_DIR2_MAX_SHORT_INUM && !objchange) - sfp->i8count++; + xfs_dir2_sf_addname_common(args, sfep, offset, objchange); + /* * If there's more left to copy, do that. */ From patchwork Tue Apr 30 12:49:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13648952 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C467A17592 for ; Tue, 30 Apr 2024 12:50:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481409; cv=none; b=u8fO19RO6/Sz03V+DNrrN82xGHSUiSQADj00XPugsc/oJ+IWkYtTMSLVA6NWZl3YEQKedHyhDQTZA6S7fdfmDNpH4i6aQhdGBeki5rRuRWCTpkxVq0W6lJVlUhHsiTF/dwDjbU5zn8D6JeqiPi6w/7Mf44Fn9k8KTN5XxXACK/s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481409; c=relaxed/simple; bh=KPOSobdFkerCSfJbqro8mOllXms6vtzwTDwYeMzTLuI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=V595dkp8qhCbJU2rVdJDE7ODGjufbulri1Wd3t/YxXY8HSA8iUCt6Z6dvoa6kYiXDD6dvgCytNBOu1VhMBpCO46k7Yofjs8svYzaR8hlkKkrXuySbbGd/DPQUlve6j2IYInxe7k5YzgfeF0CRlO8R1+kGE5IwEF/2DQ3/P/14vI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=g15/CVyA; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="g15/CVyA" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=0PQ7PESzKuPBQt0IS2ScfQ84wdpyn7pNlRDUpcZD9cA=; b=g15/CVyAjV+R0XkVqFCAjeJZMn pwpq/o+JZF6NI4BDj8u74Ly72ZPMIp+795GB/bQG1/0AMwXjxaj/Q1DuMuxDiVS0rUo3epF1np0V5 0yZp4OGNLFU7mdtm5imbw+D12dYAsFlb5wv+sUH4Vz40yyPdziGYuxLjBD/z433rqg3YHRhyM2Tdk l1nUN+KAxxdMcKLq/kZKzjdttl3qpK9akh8sOaUWWNh+05CE+GzEuXhhc+J6WfZ8Zt8hcwil/Ix+C Im+JcrqWF9Oy2Fxwdv4IjSIytucoGskEQd4ZXepaT3HPfs68ZI3HvdLo2ILJ0X+lMz6sgTK9ENgZS QYc9ExdQ==; Received: from [2001:4bb8:188:7ba8:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1mvw-00000006NoV-06jx; Tue, 30 Apr 2024 12:50:08 +0000 From: Christoph Hellwig To: Chandan Babu R , "Darrick J. Wong" Cc: linux-xfs@vger.kernel.org Subject: [PATCH 13/16] xfs: move common code into xfs_dir2_sf_addname Date: Tue, 30 Apr 2024 14:49:23 +0200 Message-Id: <20240430124926.1775355-14-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240430124926.1775355-1-hch@lst.de> References: <20240430124926.1775355-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Move updating the inode size and the call to xfs_dir2_sf_check from xfs_dir2_sf_addname_easy and xfs_dir2_sf_addname_hard into xfs_dir2_sf_addname. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_dir2_sf.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/fs/xfs/libxfs/xfs_dir2_sf.c b/fs/xfs/libxfs/xfs_dir2_sf.c index 43e1090082b45d..a9d614dfb9e43b 100644 --- a/fs/xfs/libxfs/xfs_dir2_sf.c +++ b/fs/xfs/libxfs/xfs_dir2_sf.c @@ -465,6 +465,9 @@ xfs_dir2_sf_addname( xfs_dir2_sf_toino8(args); xfs_dir2_sf_addname_hard(args, objchange, new_isize); } + + dp->i_disk_size = new_isize; + xfs_dir2_sf_check(args); xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE | XFS_ILOG_DDATA); return 0; } @@ -498,8 +501,6 @@ xfs_dir2_sf_addname_easy( */ sfep = (xfs_dir2_sf_entry_t *)((char *)sfp + byteoff); xfs_dir2_sf_addname_common(args, sfep, offset, false); - dp->i_disk_size = new_isize; - xfs_dir2_sf_check(args); } /* @@ -583,8 +584,6 @@ xfs_dir2_sf_addname_hard( memcpy(sfep, oldsfep, old_isize - nbytes); } kfree(buf); - dp->i_disk_size = new_isize; - xfs_dir2_sf_check(args); } /* From patchwork Tue Apr 30 12:49:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13648953 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D71F17592 for ; Tue, 30 Apr 2024 12:50:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481413; cv=none; b=FcyrfCHkHLvJlxuA7+oha2d94gclS2983non8FHbS6am0zQzenw6K32deQiwcTv4a+XQRpzpTywEJWqMMHJ4Rgz/slKV00tvPisgzTMAwdoarPGEQjcV4jkQFKwYm3KHdk3nFP6Z1tizqMEV+TMk8H6bE79deH3OTqWqroZQwSk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481413; c=relaxed/simple; bh=wnKZz6PesFc1bNHR2T8aZJyBgeHFVosjIKjh2uUPbHs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tPWJXIxtp7HlhPBtR3WawCEh7CEK5U+Kmp6jLNhwlRFgQSF7ErUw1OY6hdZBYGShtel9vAiasoOBYrqCzlPXieaV/GBc85k2eH93nIPvHhq1dsWL9B09qh+tBeX83Db5kWHXJLQ6+uZUOp6ZFUOlAuKtnuGPEpIap/rqMDKTEOk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=UyfK+790; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="UyfK+790" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=l1IAur0Kb3O1OPp+F06u++cBxau47NGB/nujCLuXRq8=; b=UyfK+7908swztp5RFLP1lQoBy3 kYV+UQ60wB3kmpkN5h2BFzhHMLU09e8X5cwj2HPxVg1TJxa3EUxv82HR4fFq8hJfQ+6uOqzZXa7bm T5JrUY0A2K/ovOEp2MWj1s3mFk/HVZHuw4kYZvwhtFsBQMmPH8mwkHNNK2oSZPpzVGUKLNFeYoCv4 BHuvn0l7dOSbKyNR0iYZKtB0sW5kP1ZIQzhCqrXr3PHJL8BTfkkCIBLAamRmjEvfzyfGJjRdrs25g 5s/nfh6I5Lalk0m0tSVMxZU1qUK+LJeunVjbTib9EfZ0gXM7IvDTugkOalfdyAnM9NQBreOEsMv0G prAMdwmA==; Received: from [2001:4bb8:188:7ba8:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1mvz-00000006Np2-1KBN; Tue, 30 Apr 2024 12:50:11 +0000 From: Christoph Hellwig To: Chandan Babu R , "Darrick J. Wong" Cc: linux-xfs@vger.kernel.org Subject: [PATCH 14/16] xfs: optimize adding the first 8-byte inode to a shortform directory Date: Tue, 30 Apr 2024 14:49:24 +0200 Message-Id: <20240430124926.1775355-15-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240430124926.1775355-1-hch@lst.de> References: <20240430124926.1775355-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html When adding a new entry to a shortform directory we have to convert the format of the entire inode fork if the new entry is the first 8-byte inode number. Instead of allocating a new buffer to convert the format, and then possible another one when doing an insert in the middle of the directory, simply add the new entry while converting the format and avoid the extra allocation. For this to work, xfs_dir2_sf_addname_pick also has to return the offset for the hard case, but this is entirely trivial. Signed-off-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_dir2_sf.c | 46 +++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/fs/xfs/libxfs/xfs_dir2_sf.c b/fs/xfs/libxfs/xfs_dir2_sf.c index a9d614dfb9e43b..02aa176348a795 100644 --- a/fs/xfs/libxfs/xfs_dir2_sf.c +++ b/fs/xfs/libxfs/xfs_dir2_sf.c @@ -35,7 +35,8 @@ static void xfs_dir2_sf_check(xfs_da_args_t *args); #endif /* DEBUG */ static void xfs_dir2_sf_toino4(struct xfs_da_args *args, bool remove); -static void xfs_dir2_sf_toino8(xfs_da_args_t *args); +static void xfs_dir2_sf_toino8(struct xfs_da_args *args, + xfs_dir2_data_aoff_t offset); int xfs_dir2_sf_entsize( @@ -450,6 +451,16 @@ xfs_dir2_sf_addname( */ if (args->op_flags & XFS_DA_OP_JUSTCHECK) return 0; + + /* + * If we need convert to 8-byte inodes, piggy back adding the new entry + * to the rewrite of the fork to fit the large inode number. + */ + if (objchange) { + xfs_dir2_sf_toino8(args, offset); + return 0; + } + /* * Do it the easy way - just add it at the end. */ @@ -461,8 +472,6 @@ xfs_dir2_sf_addname( */ else { ASSERT(pick == 2); - if (objchange) - xfs_dir2_sf_toino8(args); xfs_dir2_sf_addname_hard(args, objchange, new_isize); } @@ -622,6 +631,8 @@ xfs_dir2_sf_addname_pick( for (i = 0; i < sfp->count; i++) { if (!holefit) holefit = offset + size <= xfs_dir2_sf_get_offset(sfep); + if (holefit) + *offsetp = offset; offset = xfs_dir2_sf_get_offset(sfep) + xfs_dir2_data_entsize(mp, sfep->namelen); sfep = xfs_dir2_sf_nextentry(mp, sfp, sfep); @@ -1053,7 +1064,7 @@ xfs_dir2_sf_replace( /* * Still fits, convert to 8-byte now. */ - xfs_dir2_sf_toino8(args); + xfs_dir2_sf_toino8(args, 0); i8elevated = 1; sfp = dp->i_df.if_data; } else @@ -1205,7 +1216,8 @@ xfs_dir2_sf_toino4( */ static void xfs_dir2_sf_toino8( - xfs_da_args_t *args) /* operation arguments */ + struct xfs_da_args *args, + xfs_dir2_data_aoff_t new_offset) { struct xfs_inode *dp = args->dp; struct xfs_mount *mp = dp->i_mount; @@ -1213,6 +1225,7 @@ xfs_dir2_sf_toino8( int oldsize = dp->i_df.if_bytes; int i; /* entry index */ int newsize; /* new inode size */ + unsigned int newent_size; xfs_dir2_sf_entry_t *oldsfep; /* old sf entry */ xfs_dir2_sf_entry_t *sfep; /* new sf entry */ xfs_dir2_sf_hdr_t *sfp; /* new sf directory */ @@ -1225,6 +1238,18 @@ xfs_dir2_sf_toino8( * Compute the new inode size (nb: entry count + 1 for parent) */ newsize = oldsize + (oldsfp->count + 1) * XFS_INO64_DIFF; + if (new_offset) { + /* + * Account for the bytes actually used. + */ + newsize += xfs_dir2_sf_entsize(mp, oldsfp, args->namelen); + + /* + * But for the offset calculation use the bigger data entry + * format. + */ + newent_size = xfs_dir2_data_entsize(mp, args->namelen); + } dp->i_df.if_data = sfp = kmalloc(newsize, GFP_KERNEL | __GFP_NOFAIL); dp->i_df.if_bytes = newsize; @@ -1250,6 +1275,17 @@ xfs_dir2_sf_toino8( xfs_dir2_sf_get_ino(mp, oldsfp, oldsfep)); xfs_dir2_sf_put_ftype(mp, sfep, xfs_dir2_sf_get_ftype(mp, oldsfep)); + + /* + * If there is a new entry to add it once we reach the specified + * offset. + */ + if (new_offset && + new_offset == xfs_dir2_sf_get_offset(sfep) + newent_size) { + sfep = xfs_dir2_sf_nextentry(mp, sfp, sfep); + xfs_dir2_sf_addname_common(args, sfep, new_offset, + true); + } } kfree(oldsfp); From patchwork Tue Apr 30 12:49:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13648954 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5735D17592 for ; Tue, 30 Apr 2024 12:50:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481416; cv=none; b=ephPw1OCSfYElxIMy6t3hFRIP6Gz8FkrYeSmHKyS8n2lLLroHxHKXg28fQObuFcDOXg/Ey1fZqGqBUVaFYYyRW4V6AGPQef+gR+jjYzzywk9oaJhi7vlrdubWrEkz8Bc6fK1A4O8PpZP6c1ETnM4wG32joih+GUjwrkjHR4xHNU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481416; c=relaxed/simple; bh=q2mjVVO9RhrRhvlgEwLGwSlI5NEiZrOCsJBvRgDpr1o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=j3EqrhUBPdjFIPyQtJ6UO+8DPz0HNANSJn81QiXGAuyrizQi6PxxVSSoh3xV97LDOw3fN1rANd5Fv6AaEQzn+bMgIg2soBrsSYLtaNqG70jh318MYngmG4XwHuT9F9mLaY7ogafIHewP2mOhtkzY+Ht4bJDyAAWqSFrYW70vyFs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=L5JverHt; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="L5JverHt" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=g/fj3jy8+ER9HT70acDD7+o7o55GjEr4z2n5TBRRayE=; b=L5JverHt/YhmfwiWISnWnFyMo+ 6feTnL8JxxSN4jQIfIW3nGcoIiP20jbvAVmA9cQTqS/bMxbTbEVSehDdJSSsDViSyMlXDFV0CGRYD W8XIZb25IKv4uy3rurvUZdTMsHdiPfZZB7gn+fcGbpIYonVNpHXIVI62CVymvHKerZsUyWofSzzXx 5olKo37Y5YPXbc4bzxi9b0ypSNIUPn5l721lW/Fo3kc5dQsQg/wu6CrqOudcI2NS0KvchcNK2aD95 qWMuzykiJKxENHgb4JD+q974SO0O2KnsDFqXzfcdBcgtkUSDMhKVyo9erYEt8eXJ1bk9+7MNIfFNB XwF6j65A==; Received: from [2001:4bb8:188:7ba8:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1mw2-00000006Nps-14lR; Tue, 30 Apr 2024 12:50:14 +0000 From: Christoph Hellwig To: Chandan Babu R , "Darrick J. Wong" Cc: linux-xfs@vger.kernel.org Subject: [PATCH 15/16] xfs: move the block format conversion out of line in xfs_dir2_sf_addname Date: Tue, 30 Apr 2024 14:49:25 +0200 Message-Id: <20240430124926.1775355-16-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240430124926.1775355-1-hch@lst.de> References: <20240430124926.1775355-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Move the code to convert to the block format and add the entry to the end of xfs_dir2_sf_addname instead of the current very hard to read compound statement in the middle of the function. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_dir2_sf.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/fs/xfs/libxfs/xfs_dir2_sf.c b/fs/xfs/libxfs/xfs_dir2_sf.c index 02aa176348a795..0598465357cc3a 100644 --- a/fs/xfs/libxfs/xfs_dir2_sf.c +++ b/fs/xfs/libxfs/xfs_dir2_sf.c @@ -426,26 +426,16 @@ xfs_dir2_sf_addname( } new_isize = (int)dp->i_disk_size + incr_isize; + /* - * Won't fit as shortform any more (due to size), - * or the pick routine says it won't (due to offset values). + * Too large to fit into the inode fork or too large offset? */ - if (new_isize > xfs_inode_data_fork_size(dp) || - (pick = - xfs_dir2_sf_addname_pick(args, objchange, &sfep, &offset)) == 0) { - /* - * Just checking or no space reservation, it doesn't fit. - */ - if ((args->op_flags & XFS_DA_OP_JUSTCHECK) || args->total == 0) - return -ENOSPC; - /* - * Convert to block form then add the name. - */ - error = xfs_dir2_sf_to_block(args); - if (error) - return error; - return xfs_dir2_block_addname(args); - } + if (new_isize > xfs_inode_data_fork_size(dp)) + goto convert; + pick = xfs_dir2_sf_addname_pick(args, objchange, &sfep, &offset); + if (pick == 0) + goto convert; + /* * Just checking, it fits. */ @@ -479,6 +469,17 @@ xfs_dir2_sf_addname( xfs_dir2_sf_check(args); xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE | XFS_ILOG_DDATA); return 0; + +convert: + /* + * Just checking or no space reservation, it doesn't fit. + */ + if ((args->op_flags & XFS_DA_OP_JUSTCHECK) || args->total == 0) + return -ENOSPC; + error = xfs_dir2_sf_to_block(args); + if (error) + return error; + return xfs_dir2_block_addname(args); } /* From patchwork Tue Apr 30 12:49:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13648955 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 75E5D42AA5 for ; Tue, 30 Apr 2024 12:50:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481420; cv=none; b=ZberLzBgCKKcsDY9F75Vpf9Qnl+2PigHey5zuTBJ2dSesgtmDIaU7uaD9AxLDTah3r71Sx8e6Q5BDbjvWxsDduSwfJGw//xC6pxZPpFpIAN0ldswiq7H8iww6+2zvJXs/c0mOtkc6KQAFeDO6ts0gle6OlD13hfP0q1/4LaEdQU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714481420; c=relaxed/simple; bh=zfnKd/wIYI+TDuvG5INONhBPxdsN72cEzE6YcfivMrg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uOg9L0HZMrHtjScf307Zk+NidJ62oo4OffwdtG1Z9wiHXf1JG653wI29mKIab6fFo4caGeTLTUwsgfjrbFxXH3Sk1dMQejsLJaSBpgb/25NJ0ZO3JbGLGeXVi+BX9mR+ZXcknw+7AjjNI0/eUjlQNKvcn/YblS+lCYXeNuEr7gk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=A8S1fHau; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="A8S1fHau" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; 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=UJJuEFFCz1rtkUn3hOHRKDOGptVCuwe26tDtiG6DPV8=; b=A8S1fHaur3HXA9gf/2AMUO1I/Y RiMjEfY/3VSgflC1z2vWH5L5AL7hGAzs80qFyG0xO4Gjt8HcOWGZjQIc0oyAv28LzLBWsI2I2YG3k aP7sEVR8s1BFGLxVFzf+R+zdfI4q+E8ogTlPN8Zla8pCtCF15gG4nrEPRHYyrbN6InfFNaFDnUGh4 Qk2qFk0AqDJA3LkcmxxDWWQk/sLoaOvbd4NlWjmD34IUU0qIuRhr+MPl94gMDV/xz3lzmjdueonvl Xac0KSJUg3TRjjgtXkysWhGa5js2HafCoiXp5F3nZAU05zHarRyt5vB5mslaCiD9X1j7qjOdkrR3v /p/4VaYQ==; Received: from [2001:4bb8:188:7ba8:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1mw5-00000006Nqh-2NCv; Tue, 30 Apr 2024 12:50:18 +0000 From: Christoph Hellwig To: Chandan Babu R , "Darrick J. Wong" Cc: linux-xfs@vger.kernel.org Subject: [PATCH 16/16] xfs: make the hard case in xfs_dir2_sf_addname less hard Date: Tue, 30 Apr 2024 14:49:26 +0200 Message-Id: <20240430124926.1775355-17-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240430124926.1775355-1-hch@lst.de> References: <20240430124926.1775355-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html xfs_dir2_sf_addname tries and easy addition first where the new entry is added to an end and a new higher offset is allocated to it. If an arbitrary limit on the offset is trigger it goes down the "hard" path and instead looks for a hole in the offset space, which then also implies inserting the new entry in the middle as the entries are sorted by the d_offset offset. The code to add an entry the hard way is way to complicated and inefficient as it duplicates the linear search of the directory to find the entry, full frees the old inode fork data and reallocates it just to copy data into it from a temporary buffer. Rewrite all this to use the offset from the initial scan, do the usual idata realloc and then just move the entries past the insertion point out of the way in place using memmove. This also happens to allow sharing the code entirely with the easy case. Signed-off-by: Christoph Hellwig Reviewed-by: Darrick J. Wong --- fs/xfs/libxfs/xfs_dir2_sf.c | 319 ++++++++++-------------------------- 1 file changed, 89 insertions(+), 230 deletions(-) diff --git a/fs/xfs/libxfs/xfs_dir2_sf.c b/fs/xfs/libxfs/xfs_dir2_sf.c index 0598465357cc3a..4ba93835dd847f 100644 --- a/fs/xfs/libxfs/xfs_dir2_sf.c +++ b/fs/xfs/libxfs/xfs_dir2_sf.c @@ -16,18 +16,6 @@ #include "xfs_dir2_priv.h" #include "xfs_trace.h" -/* - * Prototypes for internal functions. - */ -static void xfs_dir2_sf_addname_easy(xfs_da_args_t *args, - xfs_dir2_sf_entry_t *sfep, - xfs_dir2_data_aoff_t offset, - int new_isize); -static void xfs_dir2_sf_addname_hard(xfs_da_args_t *args, int objchange, - int new_isize); -static int xfs_dir2_sf_addname_pick(xfs_da_args_t *args, int objchange, - xfs_dir2_sf_entry_t **sfepp, - xfs_dir2_data_aoff_t *offsetp); #ifdef DEBUG static void xfs_dir2_sf_check(xfs_da_args_t *args); #else @@ -361,6 +349,61 @@ xfs_dir2_try_block_to_sf( return error; } +static xfs_dir2_data_aoff_t +xfs_dir2_sf_addname_pick_offset( + struct xfs_da_args *args, + unsigned int *byteoffp) +{ + struct xfs_inode *dp = args->dp; + struct xfs_mount *mp = dp->i_mount; + struct xfs_dir2_sf_hdr *sfp = dp->i_df.if_data; + xfs_dir2_data_aoff_t offset = args->geo->data_first_offset; + struct xfs_dir2_sf_entry *sfep = xfs_dir2_sf_firstentry(sfp); + unsigned int data_size = + xfs_dir2_data_entsize(mp, args->namelen); + unsigned int data_overhead = + xfs_dir2_block_overhead(sfp->count + 1); + xfs_dir2_data_aoff_t hole_offset = 0; + unsigned int byteoff = 0; + unsigned int i; + + /* + * Scan the directory to find the last offset and find a suitable + * hole that we can use if needed. + */ + for (i = 0; i < sfp->count; i++) { + if (!hole_offset && + offset + data_size <= xfs_dir2_sf_get_offset(sfep)) { + hole_offset = offset; + byteoff = (void *)sfep - dp->i_df.if_data; + } + offset = xfs_dir2_sf_get_offset(sfep) + + xfs_dir2_data_entsize(mp, sfep->namelen); + sfep = xfs_dir2_sf_nextentry(mp, sfp, sfep); + } + + /* + * If just appending the entry would make the offset too large, use the + * first hole that fits it if there is one or else give up and convert + * to block format. + * + * Note that "too large" here is a completely arbitrary limit. The + * offset is logical concept not related to the physical byteoff and + * there is no fundamental underlying limit to it. But it has been + * encoded in asserts and verifiers for a long time so we have to + * respect it. + */ + if (offset + data_size + data_overhead > args->geo->blksize) { + if (!hole_offset) + return 0; + *byteoffp = byteoff; + return hole_offset; + } + + *byteoffp = dp->i_disk_size; + return offset; +} + static void xfs_dir2_sf_addname_common( struct xfs_da_args *args, @@ -384,23 +427,29 @@ xfs_dir2_sf_addname_common( /* * Add a name to a shortform directory. - * There are two algorithms, "easy" and "hard" which we decide on - * before changing anything. - * Convert to block form if necessary, if the new entry won't fit. + * + * Shortform directories are always tighty packed, and we simply allocate + * a new higher offset and add the entry at the end. + * + * While we could search for a hole in the offset space there really isn't + * much of a a point in doing so and complicating the algorithm. + * + * Convert to block form if the new entry won't fit. */ -int /* error */ +int xfs_dir2_sf_addname( - xfs_da_args_t *args) /* operation arguments */ + struct xfs_da_args *args) { struct xfs_inode *dp = args->dp; + struct xfs_mount *mp = dp->i_mount; struct xfs_dir2_sf_hdr *sfp = dp->i_df.if_data; - int error; /* error return value */ - int incr_isize; /* total change in size */ - int new_isize; /* size after adding name */ - int objchange; /* changing to 8-byte inodes */ - xfs_dir2_data_aoff_t offset = 0; /* offset for new entry */ - int pick; /* which algorithm to use */ - xfs_dir2_sf_entry_t *sfep = NULL; /* shortform entry */ + struct xfs_dir2_sf_entry *sfep; + xfs_dir2_data_aoff_t offset; + unsigned int entsize; + unsigned int new_isize; + unsigned int byteoff; + bool objchange = false; + int error; trace_xfs_dir2_sf_addname(args); @@ -408,11 +457,12 @@ xfs_dir2_sf_addname( ASSERT(dp->i_df.if_format == XFS_DINODE_FMT_LOCAL); ASSERT(dp->i_df.if_bytes == dp->i_disk_size); ASSERT(dp->i_disk_size >= xfs_dir2_sf_hdr_size(sfp->i8count)); + /* - * Compute entry (and change in) size. + * Compute entry size and new inode size. */ - incr_isize = xfs_dir2_sf_entsize(dp->i_mount, sfp, args->namelen); - objchange = 0; + entsize = xfs_dir2_sf_entsize(mp, sfp, args->namelen); + new_isize = dp->i_disk_size + entsize; /* * Do we have to change to 8 byte inodes? @@ -421,19 +471,17 @@ xfs_dir2_sf_addname( /* * Yes, adjust the inode size. old count + (parent + new) */ - incr_isize += (sfp->count + 2) * XFS_INO64_DIFF; - objchange = 1; + new_isize += (sfp->count + 2) * XFS_INO64_DIFF; + objchange = true; } - new_isize = (int)dp->i_disk_size + incr_isize; - /* * Too large to fit into the inode fork or too large offset? */ if (new_isize > xfs_inode_data_fork_size(dp)) goto convert; - pick = xfs_dir2_sf_addname_pick(args, objchange, &sfep, &offset); - if (pick == 0) + offset = xfs_dir2_sf_addname_pick_offset(args, &byteoff); + if (!offset) goto convert; /* @@ -451,20 +499,17 @@ xfs_dir2_sf_addname( return 0; } + sfp = xfs_idata_realloc(dp, entsize, XFS_DATA_FORK); + sfep = dp->i_df.if_data + byteoff; + /* - * Do it the easy way - just add it at the end. - */ - if (pick == 1) - xfs_dir2_sf_addname_easy(args, sfep, offset, new_isize); - /* - * Do it the hard way - look for a place to insert the new entry. - * Convert to 8 byte inode numbers first if necessary. + * If we're inserting in the middle, move the tail out of the way first. */ - else { - ASSERT(pick == 2); - xfs_dir2_sf_addname_hard(args, objchange, new_isize); + if (byteoff < dp->i_disk_size) { + memmove(sfep, (void *)sfep + entsize, + dp->i_disk_size - byteoff); } - + xfs_dir2_sf_addname_common(args, sfep, offset, objchange); dp->i_disk_size = new_isize; xfs_dir2_sf_check(args); xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE | XFS_ILOG_DDATA); @@ -482,192 +527,6 @@ xfs_dir2_sf_addname( return xfs_dir2_block_addname(args); } -/* - * Add the new entry the "easy" way. - * This is copying the old directory and adding the new entry at the end. - * Since it's sorted by "offset" we need room after the last offset - * that's already there, and then room to convert to a block directory. - * This is already checked by the pick routine. - */ -static void -xfs_dir2_sf_addname_easy( - xfs_da_args_t *args, /* operation arguments */ - xfs_dir2_sf_entry_t *sfep, /* pointer to new entry */ - xfs_dir2_data_aoff_t offset, /* offset to use for new ent */ - int new_isize) /* new directory size */ -{ - struct xfs_inode *dp = args->dp; - struct xfs_mount *mp = dp->i_mount; - struct xfs_dir2_sf_hdr *sfp = dp->i_df.if_data; - int byteoff = (int)((char *)sfep - (char *)sfp); - - /* - * Grow the in-inode space. - */ - sfp = xfs_idata_realloc(dp, xfs_dir2_sf_entsize(mp, sfp, args->namelen), - XFS_DATA_FORK); - /* - * Need to set up again due to realloc of the inode data. - */ - sfep = (xfs_dir2_sf_entry_t *)((char *)sfp + byteoff); - xfs_dir2_sf_addname_common(args, sfep, offset, false); -} - -/* - * Add the new entry the "hard" way. - * The caller has already converted to 8 byte inode numbers if necessary, - * in which case we need to leave the i8count at 1. - * Find a hole that the new entry will fit into, and copy - * the first part of the entries, the new entry, and the last part of - * the entries. - */ -/* ARGSUSED */ -static void -xfs_dir2_sf_addname_hard( - xfs_da_args_t *args, /* operation arguments */ - int objchange, /* changing inode number size */ - int new_isize) /* new directory size */ -{ - struct xfs_inode *dp = args->dp; - struct xfs_mount *mp = dp->i_mount; - int add_datasize; /* data size need for new ent */ - char *buf; /* buffer for old */ - int eof; /* reached end of old dir */ - int nbytes; /* temp for byte copies */ - xfs_dir2_data_aoff_t new_offset; /* next offset value */ - xfs_dir2_data_aoff_t offset; /* current offset value */ - int old_isize; /* previous size */ - xfs_dir2_sf_entry_t *oldsfep; /* entry in original dir */ - xfs_dir2_sf_hdr_t *oldsfp; /* original shortform dir */ - xfs_dir2_sf_entry_t *sfep; /* entry in new dir */ - xfs_dir2_sf_hdr_t *sfp; /* new shortform dir */ - - /* - * Copy the old directory to the stack buffer. - */ - old_isize = (int)dp->i_disk_size; - buf = kmalloc(old_isize, GFP_KERNEL | __GFP_NOFAIL); - oldsfp = (xfs_dir2_sf_hdr_t *)buf; - memcpy(oldsfp, dp->i_df.if_data, old_isize); - /* - * Loop over the old directory finding the place we're going - * to insert the new entry. - * If it's going to end up at the end then oldsfep will point there. - */ - for (offset = args->geo->data_first_offset, - oldsfep = xfs_dir2_sf_firstentry(oldsfp), - add_datasize = xfs_dir2_data_entsize(mp, args->namelen), - eof = (char *)oldsfep == &buf[old_isize]; - !eof; - offset = new_offset + xfs_dir2_data_entsize(mp, oldsfep->namelen), - oldsfep = xfs_dir2_sf_nextentry(mp, oldsfp, oldsfep), - eof = (char *)oldsfep == &buf[old_isize]) { - new_offset = xfs_dir2_sf_get_offset(oldsfep); - if (offset + add_datasize <= new_offset) - break; - } - /* - * Get rid of the old directory, then allocate space for - * the new one. We do this so xfs_idata_realloc won't copy - * the data. - */ - xfs_idata_realloc(dp, -old_isize, XFS_DATA_FORK); - sfp = xfs_idata_realloc(dp, new_isize, XFS_DATA_FORK); - - /* - * Copy the first part of the directory, including the header. - */ - nbytes = (int)((char *)oldsfep - (char *)oldsfp); - memcpy(sfp, oldsfp, nbytes); - sfep = (xfs_dir2_sf_entry_t *)((char *)sfp + nbytes); - - /* - * Fill in the new entry, and update the header counts. - */ - xfs_dir2_sf_addname_common(args, sfep, offset, objchange); - - /* - * If there's more left to copy, do that. - */ - if (!eof) { - sfep = xfs_dir2_sf_nextentry(mp, sfp, sfep); - memcpy(sfep, oldsfep, old_isize - nbytes); - } - kfree(buf); -} - -/* - * Decide if the new entry will fit at all. - * If it will fit, pick between adding the new entry to the end (easy) - * or somewhere else (hard). - * Return 0 (won't fit), 1 (easy), 2 (hard). - */ -/*ARGSUSED*/ -static int /* pick result */ -xfs_dir2_sf_addname_pick( - xfs_da_args_t *args, /* operation arguments */ - int objchange, /* inode # size changes */ - xfs_dir2_sf_entry_t **sfepp, /* out(1): new entry ptr */ - xfs_dir2_data_aoff_t *offsetp) /* out(1): new offset */ -{ - struct xfs_inode *dp = args->dp; - struct xfs_mount *mp = dp->i_mount; - int holefit; /* found hole it will fit in */ - int i; /* entry number */ - xfs_dir2_data_aoff_t offset; /* data block offset */ - xfs_dir2_sf_entry_t *sfep; /* shortform entry */ - struct xfs_dir2_sf_hdr *sfp = dp->i_df.if_data; - int size; /* entry's data size */ - int used; /* data bytes used */ - - size = xfs_dir2_data_entsize(mp, args->namelen); - offset = args->geo->data_first_offset; - sfep = xfs_dir2_sf_firstentry(sfp); - holefit = 0; - /* - * Loop over sf entries. - * Keep track of data offset and whether we've seen a place - * to insert the new entry. - */ - for (i = 0; i < sfp->count; i++) { - if (!holefit) - holefit = offset + size <= xfs_dir2_sf_get_offset(sfep); - if (holefit) - *offsetp = offset; - offset = xfs_dir2_sf_get_offset(sfep) + - xfs_dir2_data_entsize(mp, sfep->namelen); - sfep = xfs_dir2_sf_nextentry(mp, sfp, sfep); - } - /* - * Calculate data bytes used excluding the new entry, if this - * was a data block (block form directory). - */ - used = offset + xfs_dir2_block_overhead(sfp->count + 1); - /* - * If it won't fit in a block form then we can't insert it, - * we'll go back, convert to block, then try the insert and convert - * to leaf. - */ - if (used + (holefit ? 0 : size) > args->geo->blksize) - return 0; - /* - * If changing the inode number size, do it the hard way. - */ - if (objchange) - return 2; - /* - * If it won't fit at the end then do it the hard way (use the hole). - */ - if (used + size > args->geo->blksize) - return 2; - /* - * Do it the easy way. - */ - *sfepp = sfep; - *offsetp = offset; - return 1; -} - #ifdef DEBUG /* * Check consistency of shortform directory, assert if bad.