From patchwork Sun Dec 31 22:26:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13507874 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 027CDC129 for ; Sun, 31 Dec 2023 22:26:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JZP30MPF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C526AC433C7; Sun, 31 Dec 2023 22:26:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704061576; bh=Rn5v4hyNUfcTEKle0V5AL0YcuF6daFPt46UFO58HEq4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=JZP30MPFwSgs11+mcYTtWCXYFCUKIv9sAef7wLzgTr9Ar7jGXKTn/8GhcxGK+N2fq P1kdO1Sk4N2GHc6kGpl5aqaQA2tBppiSbOaXYu/5W2iNtIntyVabWs7aFHo0fgZ2Wa 3jJmQ3ifc1zl3O/7C6mBQszUxP8MVaDSIgMjePACu8N1QBH5N9B6s6/bEEanOWt2Ym 23Tnn/sE1waQ0H/FMYtHiFGmQYgcIaRFZsVFlUB/nhw5YRhlHXlXTZgnka/AOrrX51 kIXjoBJfo9couldum3T68PuczbARktY7xi903l6nGYZRQ4oy1loi7huqUvUphzPn6A U3cAgohTm+vcw== Date: Sun, 31 Dec 2023 14:26:16 -0800 Subject: [PATCH 1/4] xfs: move xfs_symlink_remote.c declarations to xfs_symlink_remote.h From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <170404995894.1795978.5913633219255532151.stgit@frogsfrogsfrogs> In-Reply-To: <170404995879.1795978.16481180835947373560.stgit@frogsfrogsfrogs> References: <170404995879.1795978.16481180835947373560.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Move declarations for libxfs symlink functions into a separate header file like we do for most everything else. Signed-off-by: Darrick J. Wong --- include/libxfs.h | 1 + libxfs/xfs_bmap.c | 1 + libxfs/xfs_inode_fork.c | 1 + libxfs/xfs_shared.h | 13 ------------- libxfs/xfs_symlink_remote.c | 2 +- libxfs/xfs_symlink_remote.h | 22 ++++++++++++++++++++++ 6 files changed, 26 insertions(+), 14 deletions(-) create mode 100644 libxfs/xfs_symlink_remote.h diff --git a/include/libxfs.h b/include/libxfs.h index 43fb5425796..16667b9d8b3 100644 --- a/include/libxfs.h +++ b/include/libxfs.h @@ -84,6 +84,7 @@ struct iomap; #include "xfs_refcount.h" #include "xfs_btree_staging.h" #include "xfs_rtbitmap.h" +#include "xfs_symlink_remote.h" #ifndef ARRAY_SIZE #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index d6cb466d63f..54db35bc398 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -32,6 +32,7 @@ #include "xfs_rtbitmap.h" #include "xfs_health.h" #include "defer_item.h" +#include "xfs_symlink_remote.h" struct kmem_cache *xfs_bmap_intent_cache; diff --git a/libxfs/xfs_inode_fork.c b/libxfs/xfs_inode_fork.c index 5f45a1f1240..46da5edfb11 100644 --- a/libxfs/xfs_inode_fork.c +++ b/libxfs/xfs_inode_fork.c @@ -24,6 +24,7 @@ #include "xfs_types.h" #include "xfs_errortag.h" #include "xfs_health.h" +#include "xfs_symlink_remote.h" struct kmem_cache *xfs_ifork_cache; diff --git a/libxfs/xfs_shared.h b/libxfs/xfs_shared.h index 518ea9456eb..7509c1406a3 100644 --- a/libxfs/xfs_shared.h +++ b/libxfs/xfs_shared.h @@ -137,19 +137,6 @@ void xfs_log_get_max_trans_res(struct xfs_mount *mp, #define XFS_ICHGTIME_CHG 0x2 /* inode field change timestamp */ #define XFS_ICHGTIME_CREATE 0x4 /* inode create timestamp */ - -/* - * Symlink decoding/encoding functions - */ -int xfs_symlink_blocks(struct xfs_mount *mp, int pathlen); -int xfs_symlink_hdr_set(struct xfs_mount *mp, xfs_ino_t ino, uint32_t offset, - uint32_t size, struct xfs_buf *bp); -bool xfs_symlink_hdr_ok(xfs_ino_t ino, uint32_t offset, - uint32_t size, struct xfs_buf *bp); -void xfs_symlink_local_to_remote(struct xfs_trans *tp, struct xfs_buf *bp, - struct xfs_inode *ip, struct xfs_ifork *ifp); -xfs_failaddr_t xfs_symlink_shortform_verify(void *sfp, int64_t size); - /* Computed inode geometry for the filesystem. */ struct xfs_ino_geometry { /* Maximum inode count in this filesystem. */ diff --git a/libxfs/xfs_symlink_remote.c b/libxfs/xfs_symlink_remote.c index cf894b5276a..a989ce2f3f2 100644 --- a/libxfs/xfs_symlink_remote.c +++ b/libxfs/xfs_symlink_remote.c @@ -13,7 +13,7 @@ #include "xfs_mount.h" #include "xfs_inode.h" #include "xfs_trans.h" - +#include "xfs_symlink_remote.h" /* * Each contiguous block has a header, so it is not just a simple pathlen diff --git a/libxfs/xfs_symlink_remote.h b/libxfs/xfs_symlink_remote.h new file mode 100644 index 00000000000..c6f621a0ec0 --- /dev/null +++ b/libxfs/xfs_symlink_remote.h @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2000-2005 Silicon Graphics, Inc. + * Copyright (c) 2013 Red Hat, Inc. + * All Rights Reserved. + */ +#ifndef __XFS_SYMLINK_REMOTE_H +#define __XFS_SYMLINK_REMOTE_H + +/* + * Symlink decoding/encoding functions + */ +int xfs_symlink_blocks(struct xfs_mount *mp, int pathlen); +int xfs_symlink_hdr_set(struct xfs_mount *mp, xfs_ino_t ino, uint32_t offset, + uint32_t size, struct xfs_buf *bp); +bool xfs_symlink_hdr_ok(xfs_ino_t ino, uint32_t offset, + uint32_t size, struct xfs_buf *bp); +void xfs_symlink_local_to_remote(struct xfs_trans *tp, struct xfs_buf *bp, + struct xfs_inode *ip, struct xfs_ifork *ifp); +xfs_failaddr_t xfs_symlink_shortform_verify(void *sfp, int64_t size); + +#endif /* __XFS_SYMLINK_REMOTE_H */ From patchwork Sun Dec 31 22:26:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13507875 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 8A43FC127 for ; Sun, 31 Dec 2023 22:26:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eij0gyec" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A12FC433C7; Sun, 31 Dec 2023 22:26:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704061592; bh=NiXPCmVco1aWO6DMQibfNuuGzdpqWcSGtG9Bjvw3zms=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=eij0gyecc8Lvs4zvM+Tay7kLg6KGl5KrZ/ESw8syJdg45ccOMCYJpChnO6CBbLkXY 5v9GMmNvpoXyEhtZ8PvF+/Lui7BgcbfvYTk7GCZgU1zH0GFbh/43fXfpKP/PqTg8VD WzVrdGp+YtLhKeclI/PiiKa99BJ1zGFpjQfpkILnstPXi+hzm5M/o/r+TzEoIUlS4B aEBTUWPFJjf+Y5v/WTb8cxD6M9qGmEoCQavmpHfJc8IjzHHSp06j/9U/mBDlExUP04 3booVXJOb4hQ2Hy79QEChvfiBCal9E/eaYhmZBD5LnCrBwZo2ilpai0WRL2aZDk0vL BKYE0prM9J/0g== Date: Sun, 31 Dec 2023 14:26:31 -0800 Subject: [PATCH 2/4] xfs: move remote symlink target read function to libxfs From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <170404995907.1795978.7021937513451333513.stgit@frogsfrogsfrogs> In-Reply-To: <170404995879.1795978.16481180835947373560.stgit@frogsfrogsfrogs> References: <170404995879.1795978.16481180835947373560.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Move xfs_readlink_bmap_ilocked to xfs_symlink_remote.c so that the swapext code can use it to convert a remote format symlink back to shortform format after a metadata repair. While we're at it, fix a broken printf prefix. Signed-off-by: Darrick J. Wong --- libxfs/xfs_symlink_remote.c | 77 +++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_symlink_remote.h | 1 + 2 files changed, 78 insertions(+) diff --git a/libxfs/xfs_symlink_remote.c b/libxfs/xfs_symlink_remote.c index a989ce2f3f2..8f251ae6799 100644 --- a/libxfs/xfs_symlink_remote.c +++ b/libxfs/xfs_symlink_remote.c @@ -14,6 +14,9 @@ #include "xfs_inode.h" #include "xfs_trans.h" #include "xfs_symlink_remote.h" +#include "xfs_bit.h" +#include "xfs_bmap.h" +#include "xfs_health.h" /* * Each contiguous block has a header, so it is not just a simple pathlen @@ -224,3 +227,77 @@ xfs_symlink_shortform_verify( return __this_address; return NULL; } + +/* Read a remote symlink target into the buffer. */ +int +xfs_symlink_remote_read( + struct xfs_inode *ip, + char *link) +{ + struct xfs_mount *mp = ip->i_mount; + struct xfs_bmbt_irec mval[XFS_SYMLINK_MAPS]; + struct xfs_buf *bp; + xfs_daddr_t d; + char *cur_chunk; + int pathlen = ip->i_disk_size; + int nmaps = XFS_SYMLINK_MAPS; + int byte_cnt; + int n; + int error = 0; + int fsblocks = 0; + int offset; + + ASSERT(xfs_isilocked(ip, XFS_ILOCK_SHARED | XFS_ILOCK_EXCL)); + + fsblocks = xfs_symlink_blocks(mp, pathlen); + error = xfs_bmapi_read(ip, 0, fsblocks, mval, &nmaps, 0); + if (error) + goto out; + + offset = 0; + for (n = 0; n < nmaps; n++) { + d = XFS_FSB_TO_DADDR(mp, mval[n].br_startblock); + byte_cnt = XFS_FSB_TO_B(mp, mval[n].br_blockcount); + + error = xfs_buf_read(mp->m_ddev_targp, d, BTOBB(byte_cnt), 0, + &bp, &xfs_symlink_buf_ops); + if (xfs_metadata_is_sick(error)) + xfs_inode_mark_sick(ip, XFS_SICK_INO_SYMLINK); + if (error) + return error; + byte_cnt = XFS_SYMLINK_BUF_SPACE(mp, byte_cnt); + if (pathlen < byte_cnt) + byte_cnt = pathlen; + + cur_chunk = bp->b_addr; + if (xfs_has_crc(mp)) { + if (!xfs_symlink_hdr_ok(ip->i_ino, offset, + byte_cnt, bp)) { + xfs_inode_mark_sick(ip, XFS_SICK_INO_SYMLINK); + error = -EFSCORRUPTED; + xfs_alert(mp, +"symlink header does not match required off/len/owner (0x%x/0x%x,0x%llx)", + offset, byte_cnt, ip->i_ino); + xfs_buf_relse(bp); + goto out; + + } + + cur_chunk += sizeof(struct xfs_dsymlink_hdr); + } + + memcpy(link + offset, cur_chunk, byte_cnt); + + pathlen -= byte_cnt; + offset += byte_cnt; + + xfs_buf_relse(bp); + } + ASSERT(pathlen == 0); + + link[ip->i_disk_size] = '\0'; + error = 0; + + out: + return error; +} diff --git a/libxfs/xfs_symlink_remote.h b/libxfs/xfs_symlink_remote.h index c6f621a0ec0..bb83a8b8dfa 100644 --- a/libxfs/xfs_symlink_remote.h +++ b/libxfs/xfs_symlink_remote.h @@ -18,5 +18,6 @@ bool xfs_symlink_hdr_ok(xfs_ino_t ino, uint32_t offset, void xfs_symlink_local_to_remote(struct xfs_trans *tp, struct xfs_buf *bp, struct xfs_inode *ip, struct xfs_ifork *ifp); xfs_failaddr_t xfs_symlink_shortform_verify(void *sfp, int64_t size); +int xfs_symlink_remote_read(struct xfs_inode *ip, char *link); #endif /* __XFS_SYMLINK_REMOTE_H */ From patchwork Sun Dec 31 22:26:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13507876 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 78EC5C127 for ; Sun, 31 Dec 2023 22:26:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="D5l52FHD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0CA0C433C7; Sun, 31 Dec 2023 22:26:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704061607; bh=lxv1oBXs7Ze2vo+f5TIabdXm49WMh08atYEcKU/LJUU=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=D5l52FHDqHGHYsV2xi/nUc+cwg9fT0BSGHk1mIeGgcbDVNRUPUN9fVV6i4y0xEZep qvwdvqc27cX4iikCKF0UKYg9uxOVMg69REAjCPC9Nk4XuCjLUJVB/5pnA0C45AAQ/F 5G5qdaBmoVdvB/XCRFkIeAPunkwKn94C5PfjwJ065RAOqynLtjwFz9vG0en/ElZGd1 HKJN7fOL2oPrtNuQ4P4+Pg4l6Rb/E6/08MLO7gmKCD2G3vW1QdsD3BDT6R/sxEC3yY Vm3e0JyjbYj/ZO+ue1lvX8mA2jHE6gwUYPFsv0CU0YO28uX4jSISJezg6Zltg9bmzs 6Pe98rxjdMT+A== Date: Sun, 31 Dec 2023 14:26:47 -0800 Subject: [PATCH 3/4] xfs: move symlink target write function to libxfs From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <170404995920.1795978.17625575929393364513.stgit@frogsfrogsfrogs> In-Reply-To: <170404995879.1795978.16481180835947373560.stgit@frogsfrogsfrogs> References: <170404995879.1795978.16481180835947373560.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Move xfs_symlink_write_target to xfs_symlink_remote.c so that kernel and mkfs can share the same function. Signed-off-by: Darrick J. Wong --- libxfs/xfs_symlink_remote.c | 76 +++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_symlink_remote.h | 3 ++ 2 files changed, 79 insertions(+) diff --git a/libxfs/xfs_symlink_remote.c b/libxfs/xfs_symlink_remote.c index 8f251ae6799..2f3aca8d02b 100644 --- a/libxfs/xfs_symlink_remote.c +++ b/libxfs/xfs_symlink_remote.c @@ -301,3 +301,79 @@ xfs_symlink_remote_read( out: return error; } + +/* Write the symlink target into the inode. */ +int +xfs_symlink_write_target( + struct xfs_trans *tp, + struct xfs_inode *ip, + const char *target_path, + int pathlen, + xfs_fsblock_t fs_blocks, + uint resblks) +{ + struct xfs_bmbt_irec mval[XFS_SYMLINK_MAPS]; + struct xfs_mount *mp = tp->t_mountp; + const char *cur_chunk; + struct xfs_buf *bp; + xfs_daddr_t d; + int byte_cnt; + int nmaps; + int offset = 0; + int n; + int error; + + /* + * If the symlink will fit into the inode, write it inline. + */ + if (pathlen <= xfs_inode_data_fork_size(ip)) { + xfs_init_local_fork(ip, XFS_DATA_FORK, target_path, pathlen); + + ip->i_disk_size = pathlen; + ip->i_df.if_format = XFS_DINODE_FMT_LOCAL; + xfs_trans_log_inode(tp, ip, XFS_ILOG_DDATA | XFS_ILOG_CORE); + return 0; + } + + nmaps = XFS_SYMLINK_MAPS; + error = xfs_bmapi_write(tp, ip, 0, fs_blocks, XFS_BMAPI_METADATA, + resblks, mval, &nmaps); + if (error) + return error; + + ip->i_disk_size = pathlen; + xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); + + cur_chunk = target_path; + offset = 0; + for (n = 0; n < nmaps; n++) { + char *buf; + + d = XFS_FSB_TO_DADDR(mp, mval[n].br_startblock); + byte_cnt = XFS_FSB_TO_B(mp, mval[n].br_blockcount); + error = xfs_trans_get_buf(tp, mp->m_ddev_targp, d, + BTOBB(byte_cnt), 0, &bp); + if (error) + return error; + bp->b_ops = &xfs_symlink_buf_ops; + + byte_cnt = XFS_SYMLINK_BUF_SPACE(mp, byte_cnt); + byte_cnt = min(byte_cnt, pathlen); + + buf = bp->b_addr; + buf += xfs_symlink_hdr_set(mp, ip->i_ino, offset, byte_cnt, + bp); + + memcpy(buf, cur_chunk, byte_cnt); + + cur_chunk += byte_cnt; + pathlen -= byte_cnt; + offset += byte_cnt; + + xfs_trans_buf_set_type(tp, bp, XFS_BLFT_SYMLINK_BUF); + xfs_trans_log_buf(tp, bp, 0, (buf + byte_cnt - 1) - + (char *)bp->b_addr); + } + ASSERT(pathlen == 0); + return 0; +} diff --git a/libxfs/xfs_symlink_remote.h b/libxfs/xfs_symlink_remote.h index bb83a8b8dfa..a63bd38ae4f 100644 --- a/libxfs/xfs_symlink_remote.h +++ b/libxfs/xfs_symlink_remote.h @@ -19,5 +19,8 @@ void xfs_symlink_local_to_remote(struct xfs_trans *tp, struct xfs_buf *bp, struct xfs_inode *ip, struct xfs_ifork *ifp); xfs_failaddr_t xfs_symlink_shortform_verify(void *sfp, int64_t size); int xfs_symlink_remote_read(struct xfs_inode *ip, char *link); +int xfs_symlink_write_target(struct xfs_trans *tp, struct xfs_inode *ip, + const char *target_path, int pathlen, xfs_fsblock_t fs_blocks, + uint resblks); #endif /* __XFS_SYMLINK_REMOTE_H */ From patchwork Sun Dec 31 22:27:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13507877 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 0768FC12B for ; Sun, 31 Dec 2023 22:27:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CFtPIR7q" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87EBAC433C7; Sun, 31 Dec 2023 22:27:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704061623; bh=ZTd2UT1daDsUjkfL4PkfqO0+ghYOP3GqBexuFcU/2L4=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=CFtPIR7qfwNW6y3TH+houOEpjQR0b5wNcBFReIkj21/fWKM1kOHq6lXDSA/dOZD+q zzBRG27wBk4qNPUvzWTq/bAFZYAlVIXlLb5IO7rVqso9dqlGUFTuVF1f/nuIbi+Z4V GwJTw7arGwJimlZIocmBM+TzoWd23YXydxoh5hV2QbRQoC5DmtHAw3Lvse9cP+85pd 8KTM2p2q6kOdjX9QVby4ZxZKnM3ztREseE//hLGBVRHFRNK3mcLToy/XnsY6hflzxs SdJHMDcbnw1iH6i/YcbBgra+r0IYtEEGn0BSfACk//KfeR9BQOIfAxgv4tgLLcjq06 aOxWDxbi5GvGA== Date: Sun, 31 Dec 2023 14:27:03 -0800 Subject: [PATCH 4/4] mkfs: use libxfs to create symlinks From: "Darrick J. Wong" To: djwong@kernel.org, cem@kernel.org Cc: linux-xfs@vger.kernel.org Message-ID: <170404995933.1795978.7292049559517439041.stgit@frogsfrogsfrogs> In-Reply-To: <170404995879.1795978.16481180835947373560.stgit@frogsfrogsfrogs> References: <170404995879.1795978.16481180835947373560.stgit@frogsfrogsfrogs> User-Agent: StGit/0.19 Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Darrick J. Wong Now that we've grabbed the kernel-side symlink writing function, use it to create symbolic links from protofiles. Signed-off-by: Darrick J. Wong --- libxfs/libxfs_api_defs.h | 1 + mkfs/proto.c | 72 ++++++++++++++++++++++++---------------------- 2 files changed, 39 insertions(+), 34 deletions(-) diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h index 2a8e09db0bf..a5b3baaa476 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -228,6 +228,7 @@ #define xfs_sb_version_to_features libxfs_sb_version_to_features #define xfs_symlink_blocks libxfs_symlink_blocks #define xfs_symlink_hdr_ok libxfs_symlink_hdr_ok +#define xfs_symlink_write_target libxfs_symlink_write_target #define xfs_trans_add_item libxfs_trans_add_item #define xfs_trans_alloc_empty libxfs_trans_alloc_empty diff --git a/mkfs/proto.c b/mkfs/proto.c index f8e00c4b56f..0f2facbc32e 100644 --- a/mkfs/proto.c +++ b/mkfs/proto.c @@ -16,8 +16,6 @@ static char *getstr(char **pp); static void fail(char *msg, int i); static struct xfs_trans * getres(struct xfs_mount *mp, uint blocks); static void rsvfile(xfs_mount_t *mp, xfs_inode_t *ip, long long len); -static int newfile(xfs_trans_t *tp, xfs_inode_t *ip, int symlink, int logit, - char *buf, int len); static char *newregfile(char **pp, int *len); static void rtinit(xfs_mount_t *mp); static void rtfreesp_init(struct xfs_mount *mp); @@ -243,31 +241,42 @@ rsvfile( fail(_("committing space for a file failed"), error); } -static int -newfile( - xfs_trans_t *tp, - xfs_inode_t *ip, - int symlink, - int logit, - char *buf, - int len) +static void +writesymlink( + struct xfs_trans *tp, + struct xfs_inode *ip, + char *buf, + int len) { - struct xfs_buf *bp; - xfs_daddr_t d; - int error; - int flags; - xfs_bmbt_irec_t map; - xfs_mount_t *mp; - xfs_extlen_t nb; - int nmap; + struct xfs_mount *mp = tp->t_mountp; + xfs_extlen_t nb = XFS_B_TO_FSB(mp, len); + int error; + + error = -libxfs_symlink_write_target(tp, ip, buf, len, nb, nb); + if (error) { + fprintf(stderr, + _("%s: error %d creating symlink to '%s'.\n"), progname, error, buf); + exit(1); + } +} + +static void +writefile( + struct xfs_trans *tp, + struct xfs_inode *ip, + char *buf, + int len) +{ + struct xfs_bmbt_irec map; + struct xfs_mount *mp; + struct xfs_buf *bp; + xfs_daddr_t d; + xfs_extlen_t nb; + int nmap; + int error; - flags = 0; mp = ip->i_mount; - if (symlink && len <= xfs_inode_data_fork_size(ip)) { - libxfs_init_local_fork(ip, XFS_DATA_FORK, buf, len); - ip->i_df.if_format = XFS_DINODE_FMT_LOCAL; - flags = XFS_ILOG_DDATA; - } else if (len > 0) { + if (len > 0) { int bcount; nb = XFS_B_TO_FSB(mp, len); @@ -289,7 +298,7 @@ newfile( exit(1); } d = XFS_FSB_TO_DADDR(mp, map.br_startblock); - error = -libxfs_trans_get_buf(logit ? tp : NULL, mp->m_dev, d, + error = -libxfs_trans_get_buf(NULL, mp->m_dev, d, nb << mp->m_blkbb_log, 0, &bp); if (error) { fprintf(stderr, @@ -301,15 +310,10 @@ newfile( bcount = BBTOB(bp->b_length); if (len < bcount) memset((char *)bp->b_addr + len, 0, bcount - len); - if (logit) - libxfs_trans_log_buf(tp, bp, 0, bcount - 1); - else { - libxfs_buf_mark_dirty(bp); - libxfs_buf_relse(bp); - } + libxfs_buf_mark_dirty(bp); + libxfs_buf_relse(bp); } ip->i_disk_size = len; - return flags; } static char * @@ -491,7 +495,7 @@ parseproto( &creds, fsxp, &ip); if (error) fail(_("Inode allocation failed"), error); - flags |= newfile(tp, ip, 0, 0, buf, len); + writefile(tp, ip, buf, len); if (buf) free(buf); libxfs_trans_ijoin(tp, pip, 0); @@ -575,7 +579,7 @@ parseproto( &creds, fsxp, &ip); if (error) fail(_("Inode allocation failed"), error); - flags |= newfile(tp, ip, 1, 1, buf, len); + writesymlink(tp, ip, buf, len); libxfs_trans_ijoin(tp, pip, 0); xname.type = XFS_DIR3_FT_SYMLINK; newdirent(mp, tp, pip, &xname, ip->i_ino);