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