Dave Chinner | 0b61f8a | 2018-06-05 19:42:14 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2000-2006 Silicon Graphics, Inc. |
| 4 | * Copyright (c) 2012-2013 Red Hat, Inc. |
| 5 | * All rights reserved. |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 6 | */ |
| 7 | #include "xfs.h" |
Dave Chinner | 239880e | 2013-10-23 10:50:10 +1100 | [diff] [blame] | 8 | #include "xfs_shared.h" |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 9 | #include "xfs_fs.h" |
Dave Chinner | 6ca1c90 | 2013-08-12 20:49:26 +1000 | [diff] [blame] | 10 | #include "xfs_format.h" |
Dave Chinner | 239880e | 2013-10-23 10:50:10 +1100 | [diff] [blame] | 11 | #include "xfs_log_format.h" |
| 12 | #include "xfs_trans_resv.h" |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 13 | #include "xfs_bit.h" |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 14 | #include "xfs_mount.h" |
Dave Chinner | 2b9ab5a | 2013-08-12 20:49:37 +1000 | [diff] [blame] | 15 | #include "xfs_dir2.h" |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 16 | #include "xfs_inode.h" |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 17 | #include "xfs_bmap.h" |
Dave Chinner | a4fbe6a | 2013-10-23 10:51:50 +1100 | [diff] [blame] | 18 | #include "xfs_bmap_btree.h" |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 19 | #include "xfs_quota.h" |
Darrick J. Wong | 5f213dd | 2019-11-06 17:19:33 -0800 | [diff] [blame] | 20 | #include "xfs_symlink.h" |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 21 | #include "xfs_trans_space.h" |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 22 | #include "xfs_trace.h" |
Dave Chinner | 239880e | 2013-10-23 10:50:10 +1100 | [diff] [blame] | 23 | #include "xfs_trans.h" |
Dave Chinner | b652afd | 2021-06-02 10:48:24 +1000 | [diff] [blame] | 24 | #include "xfs_ialloc.h" |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 25 | |
| 26 | /* ----- Kernel only functions below ----- */ |
Darrick J. Wong | 5da8f2f | 2017-06-16 11:00:15 -0700 | [diff] [blame] | 27 | int |
| 28 | xfs_readlink_bmap_ilocked( |
Dave Chinner | f948dd7 | 2013-04-03 16:11:19 +1100 | [diff] [blame] | 29 | struct xfs_inode *ip, |
| 30 | char *link) |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 31 | { |
Dave Chinner | f948dd7 | 2013-04-03 16:11:19 +1100 | [diff] [blame] | 32 | struct xfs_mount *mp = ip->i_mount; |
| 33 | struct xfs_bmbt_irec mval[XFS_SYMLINK_MAPS]; |
| 34 | struct xfs_buf *bp; |
| 35 | xfs_daddr_t d; |
| 36 | char *cur_chunk; |
Christoph Hellwig | 13d2c10 | 2021-03-29 11:11:40 -0700 | [diff] [blame] | 37 | int pathlen = ip->i_disk_size; |
Dave Chinner | f948dd7 | 2013-04-03 16:11:19 +1100 | [diff] [blame] | 38 | int nmaps = XFS_SYMLINK_MAPS; |
| 39 | int byte_cnt; |
| 40 | int n; |
| 41 | int error = 0; |
| 42 | int fsblocks = 0; |
| 43 | int offset; |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 44 | |
Christoph Hellwig | 29db250 | 2017-07-13 12:14:34 -0700 | [diff] [blame] | 45 | ASSERT(xfs_isilocked(ip, XFS_ILOCK_SHARED | XFS_ILOCK_EXCL)); |
| 46 | |
Dave Chinner | f948dd7 | 2013-04-03 16:11:19 +1100 | [diff] [blame] | 47 | fsblocks = xfs_symlink_blocks(mp, pathlen); |
| 48 | error = xfs_bmapi_read(ip, 0, fsblocks, mval, &nmaps, 0); |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 49 | if (error) |
| 50 | goto out; |
| 51 | |
Dave Chinner | f948dd7 | 2013-04-03 16:11:19 +1100 | [diff] [blame] | 52 | offset = 0; |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 53 | for (n = 0; n < nmaps; n++) { |
| 54 | d = XFS_FSB_TO_DADDR(mp, mval[n].br_startblock); |
| 55 | byte_cnt = XFS_FSB_TO_B(mp, mval[n].br_blockcount); |
| 56 | |
Darrick J. Wong | 0e3eccc | 2020-01-23 17:01:17 -0800 | [diff] [blame] | 57 | error = xfs_buf_read(mp->m_ddev_targp, d, BTOBB(byte_cnt), 0, |
| 58 | &bp, &xfs_symlink_buf_ops); |
| 59 | if (error) |
| 60 | return error; |
Dave Chinner | f948dd7 | 2013-04-03 16:11:19 +1100 | [diff] [blame] | 61 | byte_cnt = XFS_SYMLINK_BUF_SPACE(mp, byte_cnt); |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 62 | if (pathlen < byte_cnt) |
| 63 | byte_cnt = pathlen; |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 64 | |
Dave Chinner | f948dd7 | 2013-04-03 16:11:19 +1100 | [diff] [blame] | 65 | cur_chunk = bp->b_addr; |
Dave Chinner | 38c26bf | 2021-08-18 18:46:37 -0700 | [diff] [blame] | 66 | if (xfs_has_crc(mp)) { |
Eric Sandeen | bda65ef | 2014-04-14 19:05:43 +1000 | [diff] [blame] | 67 | if (!xfs_symlink_hdr_ok(ip->i_ino, offset, |
Dave Chinner | f948dd7 | 2013-04-03 16:11:19 +1100 | [diff] [blame] | 68 | byte_cnt, bp)) { |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 69 | error = -EFSCORRUPTED; |
Dave Chinner | f948dd7 | 2013-04-03 16:11:19 +1100 | [diff] [blame] | 70 | xfs_alert(mp, |
| 71 | "symlink header does not match required off/len/owner (0x%x/Ox%x,0x%llx)", |
| 72 | offset, byte_cnt, ip->i_ino); |
| 73 | xfs_buf_relse(bp); |
| 74 | goto out; |
| 75 | |
| 76 | } |
| 77 | |
| 78 | cur_chunk += sizeof(struct xfs_dsymlink_hdr); |
| 79 | } |
| 80 | |
Eric Sandeen | 2ac56d3 | 2015-06-22 09:42:48 +1000 | [diff] [blame] | 81 | memcpy(link + offset, cur_chunk, byte_cnt); |
Dave Chinner | f948dd7 | 2013-04-03 16:11:19 +1100 | [diff] [blame] | 82 | |
| 83 | pathlen -= byte_cnt; |
| 84 | offset += byte_cnt; |
| 85 | |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 86 | xfs_buf_relse(bp); |
| 87 | } |
Dave Chinner | f948dd7 | 2013-04-03 16:11:19 +1100 | [diff] [blame] | 88 | ASSERT(pathlen == 0); |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 89 | |
Christoph Hellwig | 13d2c10 | 2021-03-29 11:11:40 -0700 | [diff] [blame] | 90 | link[ip->i_disk_size] = '\0'; |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 91 | error = 0; |
| 92 | |
| 93 | out: |
| 94 | return error; |
| 95 | } |
| 96 | |
| 97 | int |
| 98 | xfs_readlink( |
Dave Chinner | f948dd7 | 2013-04-03 16:11:19 +1100 | [diff] [blame] | 99 | struct xfs_inode *ip, |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 100 | char *link) |
| 101 | { |
Dave Chinner | f948dd7 | 2013-04-03 16:11:19 +1100 | [diff] [blame] | 102 | struct xfs_mount *mp = ip->i_mount; |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 103 | xfs_fsize_t pathlen; |
| 104 | int error = 0; |
| 105 | |
| 106 | trace_xfs_readlink(ip); |
| 107 | |
Christoph Hellwig | 0779f4a | 2021-04-13 11:15:11 -0700 | [diff] [blame] | 108 | ASSERT(ip->i_df.if_format != XFS_DINODE_FMT_LOCAL); |
Christoph Hellwig | 30ee052 | 2016-04-06 07:53:29 +1000 | [diff] [blame] | 109 | |
Dave Chinner | 75c8c50f | 2021-08-18 18:46:53 -0700 | [diff] [blame] | 110 | if (xfs_is_shutdown(mp)) |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 111 | return -EIO; |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 112 | |
| 113 | xfs_ilock(ip, XFS_ILOCK_SHARED); |
| 114 | |
Christoph Hellwig | 13d2c10 | 2021-03-29 11:11:40 -0700 | [diff] [blame] | 115 | pathlen = ip->i_disk_size; |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 116 | if (!pathlen) |
| 117 | goto out; |
| 118 | |
Darrick J. Wong | 6eb0b8d | 2017-07-07 08:37:26 -0700 | [diff] [blame] | 119 | if (pathlen < 0 || pathlen > XFS_SYMLINK_MAXLEN) { |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 120 | xfs_alert(mp, "%s: inode (%llu) bad symlink length (%lld)", |
| 121 | __func__, (unsigned long long) ip->i_ino, |
| 122 | (long long) pathlen); |
| 123 | ASSERT(0); |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 124 | error = -EFSCORRUPTED; |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 125 | goto out; |
| 126 | } |
| 127 | |
| 128 | |
Darrick J. Wong | 5da8f2f | 2017-06-16 11:00:15 -0700 | [diff] [blame] | 129 | error = xfs_readlink_bmap_ilocked(ip, link); |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 130 | |
| 131 | out: |
| 132 | xfs_iunlock(ip, XFS_ILOCK_SHARED); |
| 133 | return error; |
| 134 | } |
| 135 | |
| 136 | int |
| 137 | xfs_symlink( |
Christoph Hellwig | f736d93 | 2021-01-21 14:19:58 +0100 | [diff] [blame] | 138 | struct user_namespace *mnt_userns, |
Dave Chinner | f948dd7 | 2013-04-03 16:11:19 +1100 | [diff] [blame] | 139 | struct xfs_inode *dp, |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 140 | struct xfs_name *link_name, |
| 141 | const char *target_path, |
| 142 | umode_t mode, |
Dave Chinner | f948dd7 | 2013-04-03 16:11:19 +1100 | [diff] [blame] | 143 | struct xfs_inode **ipp) |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 144 | { |
Dave Chinner | f948dd7 | 2013-04-03 16:11:19 +1100 | [diff] [blame] | 145 | struct xfs_mount *mp = dp->i_mount; |
| 146 | struct xfs_trans *tp = NULL; |
| 147 | struct xfs_inode *ip = NULL; |
| 148 | int error = 0; |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 149 | int pathlen; |
Dave Chinner | 58c9047 | 2015-02-23 22:38:08 +1100 | [diff] [blame] | 150 | bool unlock_dp_on_error = false; |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 151 | xfs_fileoff_t first_fsb; |
| 152 | xfs_filblks_t fs_blocks; |
| 153 | int nmaps; |
Dave Chinner | f948dd7 | 2013-04-03 16:11:19 +1100 | [diff] [blame] | 154 | struct xfs_bmbt_irec mval[XFS_SYMLINK_MAPS]; |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 155 | xfs_daddr_t d; |
| 156 | const char *cur_chunk; |
| 157 | int byte_cnt; |
| 158 | int n; |
Dave Chinner | e822261 | 2020-12-16 16:07:34 -0800 | [diff] [blame] | 159 | struct xfs_buf *bp; |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 160 | prid_t prid; |
Chandra Seetharaman | 113a568 | 2013-06-27 17:25:07 -0500 | [diff] [blame] | 161 | struct xfs_dquot *udqp = NULL; |
| 162 | struct xfs_dquot *gdqp = NULL; |
Chandra Seetharaman | 92f8ff7 | 2013-07-11 00:00:40 -0500 | [diff] [blame] | 163 | struct xfs_dquot *pdqp = NULL; |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 164 | uint resblks; |
Dave Chinner | b652afd | 2021-06-02 10:48:24 +1000 | [diff] [blame] | 165 | xfs_ino_t ino; |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 166 | |
| 167 | *ipp = NULL; |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 168 | |
| 169 | trace_xfs_symlink(dp, link_name); |
| 170 | |
Dave Chinner | 75c8c50f | 2021-08-18 18:46:53 -0700 | [diff] [blame] | 171 | if (xfs_is_shutdown(mp)) |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 172 | return -EIO; |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 173 | |
| 174 | /* |
| 175 | * Check component lengths of the target path name. |
| 176 | */ |
| 177 | pathlen = strlen(target_path); |
Darrick J. Wong | 6eb0b8d | 2017-07-07 08:37:26 -0700 | [diff] [blame] | 178 | if (pathlen >= XFS_SYMLINK_MAXLEN) /* total string too long */ |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 179 | return -ENAMETOOLONG; |
Dave Chinner | 43feeea | 2018-12-12 08:46:21 -0800 | [diff] [blame] | 180 | ASSERT(pathlen > 0); |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 181 | |
Zhi Yong Wu | 163467d | 2013-12-18 08:22:39 +0800 | [diff] [blame] | 182 | prid = xfs_get_initial_prid(dp); |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 183 | |
| 184 | /* |
| 185 | * Make sure that we have allocated dquot(s) on disk. |
| 186 | */ |
Christian Brauner | a65e58e | 2021-03-20 13:26:22 +0100 | [diff] [blame] | 187 | error = xfs_qm_vop_dqalloc(dp, mapped_fsuid(mnt_userns), |
| 188 | mapped_fsgid(mnt_userns), prid, |
Dwight Engen | 7aab1b2 | 2013-08-15 14:08:01 -0400 | [diff] [blame] | 189 | XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT, |
| 190 | &udqp, &gdqp, &pdqp); |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 191 | if (error) |
Dave Chinner | 58c9047 | 2015-02-23 22:38:08 +1100 | [diff] [blame] | 192 | return error; |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 193 | |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 194 | /* |
| 195 | * The symlink will fit into the inode data fork? |
| 196 | * There can't be any attributes so we get the whole variable part. |
| 197 | */ |
Christoph Hellwig | e9e2eae | 2020-03-18 08:15:10 -0700 | [diff] [blame] | 198 | if (pathlen <= XFS_LITINO(mp)) |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 199 | fs_blocks = 0; |
| 200 | else |
Dave Chinner | 321a958 | 2013-05-27 16:38:20 +1000 | [diff] [blame] | 201 | fs_blocks = xfs_symlink_blocks(mp, pathlen); |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 202 | resblks = XFS_SYMLINK_SPACE_RES(mp, link_name->len, fs_blocks); |
Christoph Hellwig | 253f491 | 2016-04-06 09:19:55 +1000 | [diff] [blame] | 203 | |
Darrick J. Wong | f2f7b9f | 2021-01-27 12:07:57 -0800 | [diff] [blame] | 204 | error = xfs_trans_alloc_icreate(mp, &M_RES(mp)->tr_symlink, udqp, gdqp, |
| 205 | pdqp, resblks, &tp); |
Christoph Hellwig | 4906e21 | 2015-06-04 13:47:56 +1000 | [diff] [blame] | 206 | if (error) |
Darrick J. Wong | f2f7b9f | 2021-01-27 12:07:57 -0800 | [diff] [blame] | 207 | goto out_release_dquots; |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 208 | |
Christoph Hellwig | 6552321 | 2016-11-30 14:33:25 +1100 | [diff] [blame] | 209 | xfs_ilock(dp, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT); |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 210 | unlock_dp_on_error = true; |
| 211 | |
| 212 | /* |
| 213 | * Check whether the directory allows new symlinks or not. |
| 214 | */ |
Christoph Hellwig | db07349 | 2021-03-29 11:11:44 -0700 | [diff] [blame] | 215 | if (dp->i_diflags & XFS_DIFLAG_NOSYMLINKS) { |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 216 | error = -EPERM; |
Dave Chinner | 58c9047 | 2015-02-23 22:38:08 +1100 | [diff] [blame] | 217 | goto out_trans_cancel; |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 218 | } |
| 219 | |
Chandan Babu R | f5d9274 | 2021-01-22 16:48:12 -0800 | [diff] [blame] | 220 | error = xfs_iext_count_may_overflow(dp, XFS_DATA_FORK, |
| 221 | XFS_IEXT_DIR_MANIP_CNT(mp)); |
| 222 | if (error) |
| 223 | goto out_trans_cancel; |
| 224 | |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 225 | /* |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 226 | * Allocate an inode for the symlink. |
| 227 | */ |
Dave Chinner | b652afd | 2021-06-02 10:48:24 +1000 | [diff] [blame] | 228 | error = xfs_dialloc(&tp, dp->i_ino, S_IFLNK, &ino); |
| 229 | if (!error) |
| 230 | error = xfs_init_new_inode(mnt_userns, tp, dp, ino, |
| 231 | S_IFLNK | (mode & ~S_IFMT), 1, 0, prid, |
| 232 | false, &ip); |
Dave Chinner | 58c9047 | 2015-02-23 22:38:08 +1100 | [diff] [blame] | 233 | if (error) |
| 234 | goto out_trans_cancel; |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 235 | |
| 236 | /* |
Dave Chinner | 58c9047 | 2015-02-23 22:38:08 +1100 | [diff] [blame] | 237 | * Now we join the directory inode to the transaction. We do not do it |
| 238 | * earlier because xfs_dir_ialloc might commit the previous transaction |
| 239 | * (and release all the locks). An error from here on will result in |
| 240 | * the transaction cancel unlocking dp so don't do it explicitly in the |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 241 | * error path. |
| 242 | */ |
Christoph Hellwig | 6552321 | 2016-11-30 14:33:25 +1100 | [diff] [blame] | 243 | xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL); |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 244 | unlock_dp_on_error = false; |
| 245 | |
| 246 | /* |
| 247 | * Also attach the dquot(s) to it, if applicable. |
| 248 | */ |
Chandra Seetharaman | 92f8ff7 | 2013-07-11 00:00:40 -0500 | [diff] [blame] | 249 | xfs_qm_vop_create_dqattach(tp, ip, udqp, gdqp, pdqp); |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 250 | |
Kaixu Xia | 57fd2d8 | 2020-04-22 21:54:31 -0700 | [diff] [blame] | 251 | resblks -= XFS_IALLOC_SPACE_RES(mp); |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 252 | /* |
| 253 | * If the symlink will fit into the inode, write it inline. |
| 254 | */ |
| 255 | if (pathlen <= XFS_IFORK_DSIZE(ip)) { |
Christoph Hellwig | 143f4ae | 2016-04-06 07:41:43 +1000 | [diff] [blame] | 256 | xfs_init_local_fork(ip, XFS_DATA_FORK, target_path, pathlen); |
| 257 | |
Christoph Hellwig | 13d2c10 | 2021-03-29 11:11:40 -0700 | [diff] [blame] | 258 | ip->i_disk_size = pathlen; |
Christoph Hellwig | f7e67b2 | 2020-05-18 10:28:05 -0700 | [diff] [blame] | 259 | ip->i_df.if_format = XFS_DINODE_FMT_LOCAL; |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 260 | xfs_trans_log_inode(tp, ip, XFS_ILOG_DDATA | XFS_ILOG_CORE); |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 261 | } else { |
Dave Chinner | f948dd7 | 2013-04-03 16:11:19 +1100 | [diff] [blame] | 262 | int offset; |
| 263 | |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 264 | first_fsb = 0; |
| 265 | nmaps = XFS_SYMLINK_MAPS; |
| 266 | |
| 267 | error = xfs_bmapi_write(tp, ip, first_fsb, fs_blocks, |
Brian Foster | a7beabe | 2018-07-11 22:26:25 -0700 | [diff] [blame] | 268 | XFS_BMAPI_METADATA, resblks, mval, &nmaps); |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 269 | if (error) |
Brian Foster | c8eac49 | 2018-07-24 13:43:13 -0700 | [diff] [blame] | 270 | goto out_trans_cancel; |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 271 | |
Kaixu Xia | 57fd2d8 | 2020-04-22 21:54:31 -0700 | [diff] [blame] | 272 | resblks -= fs_blocks; |
Christoph Hellwig | 13d2c10 | 2021-03-29 11:11:40 -0700 | [diff] [blame] | 273 | ip->i_disk_size = pathlen; |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 274 | xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); |
| 275 | |
| 276 | cur_chunk = target_path; |
Dave Chinner | f948dd7 | 2013-04-03 16:11:19 +1100 | [diff] [blame] | 277 | offset = 0; |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 278 | for (n = 0; n < nmaps; n++) { |
Dave Chinner | 321a958 | 2013-05-27 16:38:20 +1000 | [diff] [blame] | 279 | char *buf; |
Dave Chinner | f948dd7 | 2013-04-03 16:11:19 +1100 | [diff] [blame] | 280 | |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 281 | d = XFS_FSB_TO_DADDR(mp, mval[n].br_startblock); |
| 282 | byte_cnt = XFS_FSB_TO_B(mp, mval[n].br_blockcount); |
Darrick J. Wong | ce92464 | 2020-01-23 17:01:18 -0800 | [diff] [blame] | 283 | error = xfs_trans_get_buf(tp, mp->m_ddev_targp, d, |
| 284 | BTOBB(byte_cnt), 0, &bp); |
| 285 | if (error) |
Brian Foster | c8eac49 | 2018-07-24 13:43:13 -0700 | [diff] [blame] | 286 | goto out_trans_cancel; |
Dave Chinner | f948dd7 | 2013-04-03 16:11:19 +1100 | [diff] [blame] | 287 | bp->b_ops = &xfs_symlink_buf_ops; |
| 288 | |
| 289 | byte_cnt = XFS_SYMLINK_BUF_SPACE(mp, byte_cnt); |
Dave Chinner | 321a958 | 2013-05-27 16:38:20 +1000 | [diff] [blame] | 290 | byte_cnt = min(byte_cnt, pathlen); |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 291 | |
Dave Chinner | f948dd7 | 2013-04-03 16:11:19 +1100 | [diff] [blame] | 292 | buf = bp->b_addr; |
| 293 | buf += xfs_symlink_hdr_set(mp, ip->i_ino, offset, |
| 294 | byte_cnt, bp); |
| 295 | |
| 296 | memcpy(buf, cur_chunk, byte_cnt); |
| 297 | |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 298 | cur_chunk += byte_cnt; |
Dave Chinner | f948dd7 | 2013-04-03 16:11:19 +1100 | [diff] [blame] | 299 | pathlen -= byte_cnt; |
| 300 | offset += byte_cnt; |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 301 | |
Dave Chinner | daf7b79 | 2013-09-02 10:32:00 +1000 | [diff] [blame] | 302 | xfs_trans_buf_set_type(tp, bp, XFS_BLFT_SYMLINK_BUF); |
Dave Chinner | f948dd7 | 2013-04-03 16:11:19 +1100 | [diff] [blame] | 303 | xfs_trans_log_buf(tp, bp, 0, (buf + byte_cnt - 1) - |
| 304 | (char *)bp->b_addr); |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 305 | } |
Dave Chinner | 321a958 | 2013-05-27 16:38:20 +1000 | [diff] [blame] | 306 | ASSERT(pathlen == 0); |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 307 | } |
Christoph Hellwig | 13d2c10 | 2021-03-29 11:11:40 -0700 | [diff] [blame] | 308 | i_size_write(VFS_I(ip), ip->i_disk_size); |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 309 | |
| 310 | /* |
| 311 | * Create the directory entry for the symlink. |
| 312 | */ |
Brian Foster | 381eee6 | 2018-07-11 22:26:21 -0700 | [diff] [blame] | 313 | error = xfs_dir_createname(tp, dp, link_name, ip->i_ino, resblks); |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 314 | if (error) |
Brian Foster | c8eac49 | 2018-07-24 13:43:13 -0700 | [diff] [blame] | 315 | goto out_trans_cancel; |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 316 | xfs_trans_ichgtime(tp, dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); |
| 317 | xfs_trans_log_inode(tp, dp, XFS_ILOG_CORE); |
| 318 | |
| 319 | /* |
| 320 | * If this is a synchronous mount, make sure that the |
| 321 | * symlink transaction goes to disk before returning to |
| 322 | * the user. |
| 323 | */ |
Dave Chinner | 0560f31 | 2021-08-18 18:46:52 -0700 | [diff] [blame] | 324 | if (xfs_has_wsync(mp) || xfs_has_dirsync(mp)) |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 325 | xfs_trans_set_sync(tp); |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 326 | |
Christoph Hellwig | 7039331 | 2015-06-04 13:48:08 +1000 | [diff] [blame] | 327 | error = xfs_trans_commit(tp); |
Dave Chinner | 58c9047 | 2015-02-23 22:38:08 +1100 | [diff] [blame] | 328 | if (error) |
| 329 | goto out_release_inode; |
| 330 | |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 331 | xfs_qm_dqrele(udqp); |
| 332 | xfs_qm_dqrele(gdqp); |
Chandra Seetharaman | 92f8ff7 | 2013-07-11 00:00:40 -0500 | [diff] [blame] | 333 | xfs_qm_dqrele(pdqp); |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 334 | |
| 335 | *ipp = ip; |
| 336 | return 0; |
| 337 | |
Dave Chinner | 58c9047 | 2015-02-23 22:38:08 +1100 | [diff] [blame] | 338 | out_trans_cancel: |
Christoph Hellwig | 4906e21 | 2015-06-04 13:47:56 +1000 | [diff] [blame] | 339 | xfs_trans_cancel(tp); |
Dave Chinner | 58c9047 | 2015-02-23 22:38:08 +1100 | [diff] [blame] | 340 | out_release_inode: |
| 341 | /* |
| 342 | * Wait until after the current transaction is aborted to finish the |
| 343 | * setup of the inode and release the inode. This prevents recursive |
| 344 | * transactions and deadlocks from xfs_inactive. |
| 345 | */ |
| 346 | if (ip) { |
| 347 | xfs_finish_inode_setup(ip); |
Darrick J. Wong | 44a8736 | 2018-07-25 12:52:32 -0700 | [diff] [blame] | 348 | xfs_irele(ip); |
Dave Chinner | 58c9047 | 2015-02-23 22:38:08 +1100 | [diff] [blame] | 349 | } |
Darrick J. Wong | f2f7b9f | 2021-01-27 12:07:57 -0800 | [diff] [blame] | 350 | out_release_dquots: |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 351 | xfs_qm_dqrele(udqp); |
| 352 | xfs_qm_dqrele(gdqp); |
Chandra Seetharaman | 92f8ff7 | 2013-07-11 00:00:40 -0500 | [diff] [blame] | 353 | xfs_qm_dqrele(pdqp); |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 354 | |
| 355 | if (unlock_dp_on_error) |
Christoph Hellwig | 6552321 | 2016-11-30 14:33:25 +1100 | [diff] [blame] | 356 | xfs_iunlock(dp, XFS_ILOCK_EXCL); |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 357 | return error; |
| 358 | } |
| 359 | |
| 360 | /* |
| 361 | * Free a symlink that has blocks associated with it. |
Dave Chinner | 43feeea | 2018-12-12 08:46:21 -0800 | [diff] [blame] | 362 | * |
| 363 | * Note: zero length symlinks are not allowed to exist. When we set the size to |
| 364 | * zero, also change it to a regular file so that it does not get written to |
| 365 | * disk as a zero length symlink. The inode is on the unlinked list already, so |
| 366 | * userspace cannot find this inode anymore, so this change is not user visible |
| 367 | * but allows us to catch corrupt zero-length symlinks in the verifiers. |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 368 | */ |
Mark Tinguely | 725eb1e | 2013-06-17 15:35:57 -0500 | [diff] [blame] | 369 | STATIC int |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 370 | xfs_inactive_symlink_rmt( |
Brian Foster | 36b21dd | 2013-09-20 11:06:09 -0400 | [diff] [blame] | 371 | struct xfs_inode *ip) |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 372 | { |
Dave Chinner | e822261 | 2020-12-16 16:07:34 -0800 | [diff] [blame] | 373 | struct xfs_buf *bp; |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 374 | int done; |
| 375 | int error; |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 376 | int i; |
| 377 | xfs_mount_t *mp; |
| 378 | xfs_bmbt_irec_t mval[XFS_SYMLINK_MAPS]; |
| 379 | int nmaps; |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 380 | int size; |
| 381 | xfs_trans_t *tp; |
| 382 | |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 383 | mp = ip->i_mount; |
Christoph Hellwig | b2197a3 | 2021-04-13 11:15:12 -0700 | [diff] [blame] | 384 | ASSERT(!xfs_need_iread_extents(&ip->i_df)); |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 385 | /* |
| 386 | * We're freeing a symlink that has some |
| 387 | * blocks allocated to it. Free the |
| 388 | * blocks here. We know that we've got |
| 389 | * either 1 or 2 extents and that we can |
| 390 | * free them all in one bunmapi call. |
| 391 | */ |
Christoph Hellwig | daf8396 | 2020-05-18 10:27:22 -0700 | [diff] [blame] | 392 | ASSERT(ip->i_df.if_nextents > 0 && ip->i_df.if_nextents <= 2); |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 393 | |
Christoph Hellwig | 253f491 | 2016-04-06 09:19:55 +1000 | [diff] [blame] | 394 | error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp); |
| 395 | if (error) |
Brian Foster | 36b21dd | 2013-09-20 11:06:09 -0400 | [diff] [blame] | 396 | return error; |
Brian Foster | 36b21dd | 2013-09-20 11:06:09 -0400 | [diff] [blame] | 397 | |
| 398 | xfs_ilock(ip, XFS_ILOCK_EXCL); |
| 399 | xfs_trans_ijoin(tp, ip, 0); |
| 400 | |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 401 | /* |
Dave Chinner | 43feeea | 2018-12-12 08:46:21 -0800 | [diff] [blame] | 402 | * Lock the inode, fix the size, turn it into a regular file and join it |
| 403 | * to the transaction. Hold it so in the normal path, we still have it |
| 404 | * locked for the second transaction. In the error paths we need it |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 405 | * held so the cancel won't rele it, see below. |
| 406 | */ |
Christoph Hellwig | 13d2c10 | 2021-03-29 11:11:40 -0700 | [diff] [blame] | 407 | size = (int)ip->i_disk_size; |
| 408 | ip->i_disk_size = 0; |
Dave Chinner | 43feeea | 2018-12-12 08:46:21 -0800 | [diff] [blame] | 409 | VFS_I(ip)->i_mode = (VFS_I(ip)->i_mode & ~S_IFMT) | S_IFREG; |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 410 | xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); |
| 411 | /* |
| 412 | * Find the block(s) so we can inval and unmap them. |
| 413 | */ |
| 414 | done = 0; |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 415 | nmaps = ARRAY_SIZE(mval); |
Dave Chinner | f948dd7 | 2013-04-03 16:11:19 +1100 | [diff] [blame] | 416 | error = xfs_bmapi_read(ip, 0, xfs_symlink_blocks(mp, size), |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 417 | mval, &nmaps, 0); |
| 418 | if (error) |
Brian Foster | 36b21dd | 2013-09-20 11:06:09 -0400 | [diff] [blame] | 419 | goto error_trans_cancel; |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 420 | /* |
Dave Chinner | f948dd7 | 2013-04-03 16:11:19 +1100 | [diff] [blame] | 421 | * Invalidate the block(s). No validation is done. |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 422 | */ |
| 423 | for (i = 0; i < nmaps; i++) { |
Darrick J. Wong | ce92464 | 2020-01-23 17:01:18 -0800 | [diff] [blame] | 424 | error = xfs_trans_get_buf(tp, mp->m_ddev_targp, |
| 425 | XFS_FSB_TO_DADDR(mp, mval[i].br_startblock), |
| 426 | XFS_FSB_TO_BB(mp, mval[i].br_blockcount), 0, |
| 427 | &bp); |
| 428 | if (error) |
Brian Foster | c8eac49 | 2018-07-24 13:43:13 -0700 | [diff] [blame] | 429 | goto error_trans_cancel; |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 430 | xfs_trans_binval(tp, bp); |
| 431 | } |
| 432 | /* |
Darrick J. Wong | 2c3234d | 2016-08-03 11:19:29 +1000 | [diff] [blame] | 433 | * Unmap the dead block(s) to the dfops. |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 434 | */ |
Brian Foster | 2af5284 | 2018-07-11 22:26:25 -0700 | [diff] [blame] | 435 | error = xfs_bunmapi(tp, ip, 0, size, 0, nmaps, &done); |
Brian Foster | 36b21dd | 2013-09-20 11:06:09 -0400 | [diff] [blame] | 436 | if (error) |
Brian Foster | c8eac49 | 2018-07-24 13:43:13 -0700 | [diff] [blame] | 437 | goto error_trans_cancel; |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 438 | ASSERT(done); |
Dave Chinner | 3565b660 | 2018-05-09 07:49:09 -0700 | [diff] [blame] | 439 | |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 440 | /* |
Brian Foster | c8eac49 | 2018-07-24 13:43:13 -0700 | [diff] [blame] | 441 | * Commit the transaction. This first logs the EFI and the inode, then |
| 442 | * rolls and commits the transaction that frees the extents. |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 443 | */ |
Dave Chinner | 3565b660 | 2018-05-09 07:49:09 -0700 | [diff] [blame] | 444 | xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); |
Christoph Hellwig | 7039331 | 2015-06-04 13:48:08 +1000 | [diff] [blame] | 445 | error = xfs_trans_commit(tp); |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 446 | if (error) { |
Dave Chinner | 75c8c50f | 2021-08-18 18:46:53 -0700 | [diff] [blame] | 447 | ASSERT(xfs_is_shutdown(mp)); |
Brian Foster | 36b21dd | 2013-09-20 11:06:09 -0400 | [diff] [blame] | 448 | goto error_unlock; |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 449 | } |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 450 | |
| 451 | /* |
| 452 | * Remove the memory for extent descriptions (just bookkeeping). |
| 453 | */ |
| 454 | if (ip->i_df.if_bytes) |
| 455 | xfs_idata_realloc(ip, -ip->i_df.if_bytes, XFS_DATA_FORK); |
| 456 | ASSERT(ip->i_df.if_bytes == 0); |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 457 | |
Brian Foster | 36b21dd | 2013-09-20 11:06:09 -0400 | [diff] [blame] | 458 | xfs_iunlock(ip, XFS_ILOCK_EXCL); |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 459 | return 0; |
| 460 | |
Brian Foster | 36b21dd | 2013-09-20 11:06:09 -0400 | [diff] [blame] | 461 | error_trans_cancel: |
Christoph Hellwig | 4906e21 | 2015-06-04 13:47:56 +1000 | [diff] [blame] | 462 | xfs_trans_cancel(tp); |
Brian Foster | 36b21dd | 2013-09-20 11:06:09 -0400 | [diff] [blame] | 463 | error_unlock: |
| 464 | xfs_iunlock(ip, XFS_ILOCK_EXCL); |
Dave Chinner | 19de735 | 2013-04-03 16:11:18 +1100 | [diff] [blame] | 465 | return error; |
| 466 | } |
Mark Tinguely | 725eb1e | 2013-06-17 15:35:57 -0500 | [diff] [blame] | 467 | |
| 468 | /* |
| 469 | * xfs_inactive_symlink - free a symlink |
| 470 | */ |
| 471 | int |
| 472 | xfs_inactive_symlink( |
Brian Foster | 36b21dd | 2013-09-20 11:06:09 -0400 | [diff] [blame] | 473 | struct xfs_inode *ip) |
Mark Tinguely | 725eb1e | 2013-06-17 15:35:57 -0500 | [diff] [blame] | 474 | { |
| 475 | struct xfs_mount *mp = ip->i_mount; |
| 476 | int pathlen; |
| 477 | |
| 478 | trace_xfs_inactive_symlink(ip); |
| 479 | |
Dave Chinner | 75c8c50f | 2021-08-18 18:46:53 -0700 | [diff] [blame] | 480 | if (xfs_is_shutdown(mp)) |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 481 | return -EIO; |
Mark Tinguely | 725eb1e | 2013-06-17 15:35:57 -0500 | [diff] [blame] | 482 | |
Brian Foster | 36b21dd | 2013-09-20 11:06:09 -0400 | [diff] [blame] | 483 | xfs_ilock(ip, XFS_ILOCK_EXCL); |
Christoph Hellwig | 13d2c10 | 2021-03-29 11:11:40 -0700 | [diff] [blame] | 484 | pathlen = (int)ip->i_disk_size; |
Dave Chinner | 43feeea | 2018-12-12 08:46:21 -0800 | [diff] [blame] | 485 | ASSERT(pathlen); |
Mark Tinguely | 725eb1e | 2013-06-17 15:35:57 -0500 | [diff] [blame] | 486 | |
Dave Chinner | 43feeea | 2018-12-12 08:46:21 -0800 | [diff] [blame] | 487 | if (pathlen <= 0 || pathlen > XFS_SYMLINK_MAXLEN) { |
Mark Tinguely | 725eb1e | 2013-06-17 15:35:57 -0500 | [diff] [blame] | 488 | xfs_alert(mp, "%s: inode (0x%llx) bad symlink length (%d)", |
| 489 | __func__, (unsigned long long)ip->i_ino, pathlen); |
Brian Foster | 36b21dd | 2013-09-20 11:06:09 -0400 | [diff] [blame] | 490 | xfs_iunlock(ip, XFS_ILOCK_EXCL); |
Mark Tinguely | 725eb1e | 2013-06-17 15:35:57 -0500 | [diff] [blame] | 491 | ASSERT(0); |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame] | 492 | return -EFSCORRUPTED; |
Mark Tinguely | 725eb1e | 2013-06-17 15:35:57 -0500 | [diff] [blame] | 493 | } |
| 494 | |
Dave Chinner | 43feeea | 2018-12-12 08:46:21 -0800 | [diff] [blame] | 495 | /* |
| 496 | * Inline fork state gets removed by xfs_difree() so we have nothing to |
| 497 | * do here in that case. |
| 498 | */ |
Christoph Hellwig | 0779f4a | 2021-04-13 11:15:11 -0700 | [diff] [blame] | 499 | if (ip->i_df.if_format == XFS_DINODE_FMT_LOCAL) { |
Brian Foster | 36b21dd | 2013-09-20 11:06:09 -0400 | [diff] [blame] | 500 | xfs_iunlock(ip, XFS_ILOCK_EXCL); |
Mark Tinguely | 725eb1e | 2013-06-17 15:35:57 -0500 | [diff] [blame] | 501 | return 0; |
| 502 | } |
| 503 | |
Brian Foster | 36b21dd | 2013-09-20 11:06:09 -0400 | [diff] [blame] | 504 | xfs_iunlock(ip, XFS_ILOCK_EXCL); |
| 505 | |
Mark Tinguely | 725eb1e | 2013-06-17 15:35:57 -0500 | [diff] [blame] | 506 | /* remove the remote symlink */ |
Brian Foster | 36b21dd | 2013-09-20 11:06:09 -0400 | [diff] [blame] | 507 | return xfs_inactive_symlink_rmt(ip); |
Mark Tinguely | 725eb1e | 2013-06-17 15:35:57 -0500 | [diff] [blame] | 508 | } |