From patchwork Fri Dec 30 22:17:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085093 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB523C3DA7C for ; Sat, 31 Dec 2022 00:18:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235905AbiLaASA (ORCPT ); Fri, 30 Dec 2022 19:18:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235901AbiLaAR5 (ORCPT ); Fri, 30 Dec 2022 19:17:57 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1CB31CB3F for ; Fri, 30 Dec 2022 16:17:56 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3AE8361D1C for ; Sat, 31 Dec 2022 00:17:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B16CC4332B; Sat, 31 Dec 2022 00:17:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672445875; bh=OsNTwKmyPt/6sX/Y24yyL+dkkwQjblrRxSBJGns/kj4=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=oiB3vSZvunjckl5ygGzjCZocEMdKprVGy5XW3yEp37TDMTeqTeCn4cfuFzmW0GGpP Gqy70v354AiUUTnzMZxXPAFtoEtY+B+kcJE0ZhsEpopEXOHn8qHIObGjJ7GYTdo+WP vFyVuEnd/uQrDVLG4LbS27e3/fhouV+kITkTs0GHoFNFfswnioUnaLjhr7s9H58nrC Mv+gsIc1mjBEgHmd+Z5K/mBKp9enlKKjEKCSK5LVmZ21l6zFL9G5kK3eh9LmAN11P0 aYz1GbUofmI2iRFr6amxWIcXH/bAZCtvBPszkJd1Za6AWluVkZg73vklAi9MBIOZXO F8MVzktR+R8VQ== Subject: [PATCH 1/4] xfs: move xfs_symlink_remote.c declarations to xfs_symlink_remote.h From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:17:56 -0800 Message-ID: <167243867601.713532.6540985468566213398.stgit@magnolia> In-Reply-To: <167243867587.713532.17037228277541976894.stgit@magnolia> References: <167243867587.713532.17037228277541976894.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org 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 | 14 -------------- libxfs/xfs_symlink_remote.c | 2 +- libxfs/xfs_symlink_remote.h | 23 +++++++++++++++++++++++ 6 files changed, 27 insertions(+), 15 deletions(-) create mode 100644 libxfs/xfs_symlink_remote.h diff --git a/include/libxfs.h b/include/libxfs.h index 887f57b6171..d4b5d8e564d 100644 --- a/include/libxfs.h +++ b/include/libxfs.h @@ -79,6 +79,7 @@ struct iomap; #include "xfs_refcount_btree.h" #include "xfs_refcount.h" #include "xfs_btree_staging.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 edd3e81fd04..983eb7641fc 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -30,6 +30,7 @@ #include "xfs_ag_resv.h" #include "xfs_refcount.h" #include "xfs_health.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 9b0c786fab6..9d76a6b5c65 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 eaabfa52eda..5127fa88531 100644 --- a/libxfs/xfs_shared.h +++ b/libxfs/xfs_shared.h @@ -138,20 +138,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_sf_verify_struct(void *sfp, int64_t size); -xfs_failaddr_t xfs_symlink_shortform_verify(struct xfs_inode *ip); - /* 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 b9d446fba9a..e036a8f46fe 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..a58d536c8b8 --- /dev/null +++ b/libxfs/xfs_symlink_remote.h @@ -0,0 +1,23 @@ +// 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_sf_verify_struct(void *sfp, int64_t size); +xfs_failaddr_t xfs_symlink_shortform_verify(struct xfs_inode *ip); + +#endif /* __XFS_SYMLINK_REMOTE_H */ From patchwork Fri Dec 30 22:17:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085094 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 83DDBC4332F for ; Sat, 31 Dec 2022 00:18:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235900AbiLaASP (ORCPT ); Fri, 30 Dec 2022 19:18:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235902AbiLaASO (ORCPT ); Fri, 30 Dec 2022 19:18:14 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9B9D193DB for ; Fri, 30 Dec 2022 16:18:13 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 9144CB81E71 for ; Sat, 31 Dec 2022 00:18:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2697DC433D2; Sat, 31 Dec 2022 00:18:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672445891; bh=LYQsQKDp+Jj3S0IPuquQSixzvHFuFOpCnm6RUOPR+k8=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=JaTzFxFdDGlcZNYWapzZhCzCyHwHLHQ48627rNHjMUBUnhyMMdO8omR4wmKWJipI0 CUoNkn3LW1DDUrCkujw1QuJw3JIb/cUd5f6cDJqEM1K/emOmmHs8Q/DutoD7Lhmo5M twNUVW9x7VEvsy8Dor+FFZMzxrg6j8TooRff23WAEhXxzMS/2va+RxQcONPmK+p/bs Pz3gnQoULKUMhAeb1ZxwE0V7mUlbyoDCm5dPW/CEKhCG/xI97RC1pR+g7z6FF4cvTH ldP1HjI4GAByOwHBAwoWGJTzXKCtAVaF1oU+Y/UQL2E/501piwf+ei3Te+98J6k5ua M9VGvuaAdPfXQ== Subject: [PATCH 2/4] xfs: move remote symlink target read function to libxfs From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:17:56 -0800 Message-ID: <167243867614.713532.10935720562608290339.stgit@magnolia> In-Reply-To: <167243867587.713532.17037228277541976894.stgit@magnolia> References: <167243867587.713532.17037228277541976894.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org 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 modifier. 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 e036a8f46fe..db4955adc08 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 @@ -235,3 +238,77 @@ xfs_symlink_shortform_verify( return xfs_symlink_sf_verify_struct(ifp->if_u1.if_data, ifp->if_bytes); } + +/* 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 a58d536c8b8..7d3acaee0af 100644 --- a/libxfs/xfs_symlink_remote.h +++ b/libxfs/xfs_symlink_remote.h @@ -19,5 +19,6 @@ 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_sf_verify_struct(void *sfp, int64_t size); xfs_failaddr_t xfs_symlink_shortform_verify(struct xfs_inode *ip); +int xfs_symlink_remote_read(struct xfs_inode *ip, char *link); #endif /* __XFS_SYMLINK_REMOTE_H */ From patchwork Fri Dec 30 22:17:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085095 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE5CBC4332F for ; Sat, 31 Dec 2022 00:18:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235918AbiLaASb (ORCPT ); Fri, 30 Dec 2022 19:18:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235920AbiLaASa (ORCPT ); Fri, 30 Dec 2022 19:18:30 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 405981C912 for ; Fri, 30 Dec 2022 16:18:29 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E86A3B81E6F for ; Sat, 31 Dec 2022 00:18:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AFC09C433EF; Sat, 31 Dec 2022 00:18:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672445906; bh=J+zUtzlbXY0B9KWd54kAI+Uj9zv8xnIz5lPfpQSUdaE=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=H99TBUz6UPRHFmvm4d7OfHQXwZlU08yFCsErqE3H80Rg6JySLTAvS63nmjk8aVLqe gnK5PvI2FdAOoNcx1+o7KJ/HTkQvrRJAOpnOCHqUfnz5SIYnQ5lAJLxnPq9ZnMqJ4M nhBBdy0x9ICfhmYJeJF58M2PqEtgk5fljV/ri8svDse+TA1O8bn6aCyJrtFiToAgKV umc394zzFcagkaoONJaw9de/e/Lrdmc5PfGpCzW8jXddnxKhuosxKJ5mC6KT79KX5R PYNHDVWzF53A4UYevRPWfXK49RcBu9oqspUWQjq/SGL1zQ1PmK/s6scgSof3QNtoLd Se0rPJ10GpNjg== Subject: [PATCH 3/4] xfs: move symlink target write function to libxfs From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:17:56 -0800 Message-ID: <167243867628.713532.9910637855198073588.stgit@magnolia> In-Reply-To: <167243867587.713532.17037228277541976894.stgit@magnolia> References: <167243867587.713532.17037228277541976894.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org 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 db4955adc08..740db58d99c 100644 --- a/libxfs/xfs_symlink_remote.c +++ b/libxfs/xfs_symlink_remote.c @@ -312,3 +312,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 7d3acaee0af..d81461c06b6 100644 --- a/libxfs/xfs_symlink_remote.h +++ b/libxfs/xfs_symlink_remote.h @@ -20,5 +20,8 @@ void xfs_symlink_local_to_remote(struct xfs_trans *tp, struct xfs_buf *bp, xfs_failaddr_t xfs_symlink_sf_verify_struct(void *sfp, int64_t size); xfs_failaddr_t xfs_symlink_shortform_verify(struct xfs_inode *ip); 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 Fri Dec 30 22:17:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13085096 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0FA7C4332F for ; Sat, 31 Dec 2022 00:18:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235916AbiLaASq (ORCPT ); Fri, 30 Dec 2022 19:18:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235908AbiLaASp (ORCPT ); Fri, 30 Dec 2022 19:18:45 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A49817597 for ; Fri, 30 Dec 2022 16:18:43 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id EABEA61C52 for ; Sat, 31 Dec 2022 00:18:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 564BCC433D2; Sat, 31 Dec 2022 00:18:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672445922; bh=A8JxKZYwraW9UeedifutKM7UAN6dCYt4+n8qZzLhafs=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=kvN8sMIdbHdK0BhSEsILlbq0EJYxGv6WNmpJwNGqyZHC22PedN4lHQXrqxGtxm2WF zxmif3JPqLkchXG/AK0gWVzSLY4cOjlxLTlbk1iAO4fRM/J5RC4ZQWhq4sceB3BxOY ve0T4h2+8Wy6OMBS13DorOPlLJhaOUATQNI83VlMOD13S2EvF8JYWAFmqTB5dvAAJy QX9Xlp6YLUGuzCP2DujMkh/jDRtcH5yrv3qj/dU5F5idUdWELQWtaBQVkk+2wY7Bby B/slyE6GfOoZRU1bkxIiaWpKW5hNZQnrbXWG+9gFhzd3rOkF1w9e+OsqA4VkbSipGj RAVmZSeKkZ7Pg== Subject: [PATCH 4/4] mkfs: use libxfs to create symlinks From: "Darrick J. Wong" To: cem@kernel.org, djwong@kernel.org Cc: linux-xfs@vger.kernel.org Date: Fri, 30 Dec 2022 14:17:56 -0800 Message-ID: <167243867641.713532.4167978409051098779.stgit@magnolia> In-Reply-To: <167243867587.713532.17037228277541976894.stgit@magnolia> References: <167243867587.713532.17037228277541976894.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org 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 aa71914af97..81dfb10575d 100644 --- a/libxfs/libxfs_api_defs.h +++ b/libxfs/libxfs_api_defs.h @@ -209,6 +209,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 68ecdbf3632..bd306f95568 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 long filesize(int fd); @@ -217,31 +215,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); @@ -263,7 +272,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, @@ -275,15 +284,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 * @@ -459,7 +463,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); @@ -543,7 +547,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);