Dave Chinner | 0b61f8a | 2018-06-05 19:42:14 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2000-2005 Silicon Graphics, Inc. |
| 4 | * Copyright (c) 2013 Red Hat, Inc. |
| 5 | * All Rights Reserved. |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 6 | */ |
| 7 | #include "xfs.h" |
| 8 | #include "xfs_fs.h" |
Dave Chinner | 70a9883 | 2013-10-23 10:36:05 +1100 | [diff] [blame] | 9 | #include "xfs_shared.h" |
Dave Chinner | 239880e | 2013-10-23 10:50:10 +1100 | [diff] [blame] | 10 | #include "xfs_format.h" |
| 11 | #include "xfs_log_format.h" |
| 12 | #include "xfs_trans_resv.h" |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 13 | #include "xfs_bit.h" |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 14 | #include "xfs_mount.h" |
Dave Chinner | 5706278 | 2013-10-15 09:17:51 +1100 | [diff] [blame] | 15 | #include "xfs_da_format.h" |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 16 | #include "xfs_da_btree.h" |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 17 | #include "xfs_inode.h" |
Dave Chinner | a4fbe6a | 2013-10-23 10:51:50 +1100 | [diff] [blame] | 18 | #include "xfs_attr_remote.h" |
Dave Chinner | 239880e | 2013-10-23 10:50:10 +1100 | [diff] [blame] | 19 | #include "xfs_trans.h" |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 20 | #include "xfs_bmap.h" |
| 21 | #include "xfs_attr.h" |
| 22 | #include "xfs_attr_leaf.h" |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 23 | #include "xfs_quota.h" |
Dave Chinner | 4bceb18 | 2013-10-29 22:11:51 +1100 | [diff] [blame] | 24 | #include "xfs_dir2.h" |
Darrick J. Wong | a5155b8 | 2019-11-02 09:40:53 -0700 | [diff] [blame] | 25 | #include "xfs_error.h" |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 26 | |
| 27 | /* |
Darrick J. Wong | e8db2aa | 2020-01-07 16:11:45 -0800 | [diff] [blame^] | 28 | * Invalidate any incore buffers associated with this remote attribute value |
| 29 | * extent. We never log remote attribute value buffers, which means that they |
| 30 | * won't be attached to a transaction and are therefore safe to mark stale. |
| 31 | * The actual bunmapi will be taken care of later. |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 32 | */ |
| 33 | STATIC int |
Darrick J. Wong | e8db2aa | 2020-01-07 16:11:45 -0800 | [diff] [blame^] | 34 | xfs_attr3_rmt_stale( |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 35 | struct xfs_inode *dp, |
| 36 | xfs_dablk_t blkno, |
| 37 | int blkcnt) |
| 38 | { |
| 39 | struct xfs_bmbt_irec map; |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 40 | xfs_dablk_t tblkno; |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 41 | int tblkcnt; |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 42 | int nmap; |
| 43 | int error; |
| 44 | |
| 45 | /* |
| 46 | * Roll through the "value", invalidating the attribute value's |
| 47 | * blocks. |
| 48 | */ |
| 49 | tblkno = blkno; |
| 50 | tblkcnt = blkcnt; |
| 51 | while (tblkcnt > 0) { |
| 52 | /* |
| 53 | * Try to remember where we decided to put the value. |
| 54 | */ |
| 55 | nmap = 1; |
| 56 | error = xfs_bmapi_read(dp, (xfs_fileoff_t)tblkno, tblkcnt, |
| 57 | &map, &nmap, XFS_BMAPI_ATTRFORK); |
Darrick J. Wong | e8db2aa | 2020-01-07 16:11:45 -0800 | [diff] [blame^] | 58 | if (error) |
Eric Sandeen | d99831f | 2014-06-22 15:03:54 +1000 | [diff] [blame] | 59 | return error; |
Darrick J. Wong | e8db2aa | 2020-01-07 16:11:45 -0800 | [diff] [blame^] | 60 | if (XFS_IS_CORRUPT(dp->i_mount, nmap != 1)) |
| 61 | return -EFSCORRUPTED; |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 62 | |
| 63 | /* |
Darrick J. Wong | e8db2aa | 2020-01-07 16:11:45 -0800 | [diff] [blame^] | 64 | * Mark any incore buffers for the remote value as stale. We |
| 65 | * never log remote attr value buffers, so the buffer should be |
| 66 | * easy to kill. |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 67 | */ |
Darrick J. Wong | e8db2aa | 2020-01-07 16:11:45 -0800 | [diff] [blame^] | 68 | error = xfs_attr_rmtval_stale(dp, &map, 0); |
| 69 | if (error) |
| 70 | return error; |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 71 | |
| 72 | tblkno += map.br_blockcount; |
| 73 | tblkcnt -= map.br_blockcount; |
| 74 | } |
| 75 | |
Eric Sandeen | d99831f | 2014-06-22 15:03:54 +1000 | [diff] [blame] | 76 | return 0; |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | /* |
| 80 | * Invalidate all of the "remote" value regions pointed to by a particular |
| 81 | * leaf block. |
| 82 | * Note that we must release the lock on the buffer so that we are not |
| 83 | * caught holding something that the logging code wants to flush to disk. |
| 84 | */ |
| 85 | STATIC int |
| 86 | xfs_attr3_leaf_inactive( |
| 87 | struct xfs_trans **trans, |
| 88 | struct xfs_inode *dp, |
| 89 | struct xfs_buf *bp) |
| 90 | { |
| 91 | struct xfs_attr_leafblock *leaf; |
| 92 | struct xfs_attr3_icleaf_hdr ichdr; |
| 93 | struct xfs_attr_leaf_entry *entry; |
| 94 | struct xfs_attr_leaf_name_remote *name_rmt; |
| 95 | struct xfs_attr_inactive_list *list; |
| 96 | struct xfs_attr_inactive_list *lp; |
| 97 | int error; |
| 98 | int count; |
| 99 | int size; |
| 100 | int tmp; |
| 101 | int i; |
Christoph Hellwig | dbd329f1 | 2019-06-28 19:27:29 -0700 | [diff] [blame] | 102 | struct xfs_mount *mp = bp->b_mount; |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 103 | |
| 104 | leaf = bp->b_addr; |
Brian Foster | 2f66124 | 2015-04-13 11:26:02 +1000 | [diff] [blame] | 105 | xfs_attr3_leaf_hdr_from_disk(mp->m_attr_geo, &ichdr, leaf); |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 106 | |
| 107 | /* |
| 108 | * Count the number of "remote" value extents. |
| 109 | */ |
| 110 | count = 0; |
| 111 | entry = xfs_attr3_leaf_entryp(leaf); |
| 112 | for (i = 0; i < ichdr.count; entry++, i++) { |
| 113 | if (be16_to_cpu(entry->nameidx) && |
| 114 | ((entry->flags & XFS_ATTR_LOCAL) == 0)) { |
| 115 | name_rmt = xfs_attr3_leaf_name_remote(leaf, i); |
| 116 | if (name_rmt->valueblk) |
| 117 | count++; |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | /* |
| 122 | * If there are no "remote" values, we're done. |
| 123 | */ |
| 124 | if (count == 0) { |
| 125 | xfs_trans_brelse(*trans, bp); |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | /* |
| 130 | * Allocate storage for a list of all the "remote" value extents. |
| 131 | */ |
| 132 | size = count * sizeof(xfs_attr_inactive_list_t); |
Tetsuo Handa | 707e0dd | 2019-08-26 12:06:22 -0700 | [diff] [blame] | 133 | list = kmem_alloc(size, 0); |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 134 | |
| 135 | /* |
| 136 | * Identify each of the "remote" value extents. |
| 137 | */ |
| 138 | lp = list; |
| 139 | entry = xfs_attr3_leaf_entryp(leaf); |
| 140 | for (i = 0; i < ichdr.count; entry++, i++) { |
| 141 | if (be16_to_cpu(entry->nameidx) && |
| 142 | ((entry->flags & XFS_ATTR_LOCAL) == 0)) { |
| 143 | name_rmt = xfs_attr3_leaf_name_remote(leaf, i); |
| 144 | if (name_rmt->valueblk) { |
| 145 | lp->valueblk = be32_to_cpu(name_rmt->valueblk); |
| 146 | lp->valuelen = xfs_attr3_rmt_blocks(dp->i_mount, |
| 147 | be32_to_cpu(name_rmt->valuelen)); |
| 148 | lp++; |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | xfs_trans_brelse(*trans, bp); /* unlock for trans. in freextent() */ |
| 153 | |
| 154 | /* |
| 155 | * Invalidate each of the "remote" value extents. |
| 156 | */ |
| 157 | error = 0; |
| 158 | for (lp = list, i = 0; i < count; i++, lp++) { |
Darrick J. Wong | e8db2aa | 2020-01-07 16:11:45 -0800 | [diff] [blame^] | 159 | tmp = xfs_attr3_rmt_stale(dp, lp->valueblk, lp->valuelen); |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 160 | if (error == 0) |
| 161 | error = tmp; /* save only the 1st errno */ |
| 162 | } |
| 163 | |
| 164 | kmem_free(list); |
| 165 | return error; |
| 166 | } |
| 167 | |
| 168 | /* |
| 169 | * Recurse (gasp!) through the attribute nodes until we find leaves. |
| 170 | * We're doing a depth-first traversal in order to invalidate everything. |
| 171 | */ |
| 172 | STATIC int |
| 173 | xfs_attr3_node_inactive( |
Christoph Hellwig | 51908ca | 2019-11-08 14:57:48 -0800 | [diff] [blame] | 174 | struct xfs_trans **trans, |
| 175 | struct xfs_inode *dp, |
| 176 | struct xfs_buf *bp, |
| 177 | int level) |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 178 | { |
Christoph Hellwig | 2911edb | 2019-11-20 09:46:05 -0800 | [diff] [blame] | 179 | struct xfs_mount *mp = dp->i_mount; |
Christoph Hellwig | 51908ca | 2019-11-08 14:57:48 -0800 | [diff] [blame] | 180 | struct xfs_da_blkinfo *info; |
| 181 | xfs_dablk_t child_fsb; |
| 182 | xfs_daddr_t parent_blkno, child_blkno; |
| 183 | struct xfs_buf *child_bp; |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 184 | struct xfs_da3_icnode_hdr ichdr; |
Christoph Hellwig | 51908ca | 2019-11-08 14:57:48 -0800 | [diff] [blame] | 185 | int error, i; |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 186 | |
| 187 | /* |
| 188 | * Since this code is recursive (gasp!) we must protect ourselves. |
| 189 | */ |
| 190 | if (level > XFS_DA_NODE_MAXDEPTH) { |
| 191 | xfs_trans_brelse(*trans, bp); /* no locks for later trans */ |
Darrick J. Wong | a5155b8 | 2019-11-02 09:40:53 -0700 | [diff] [blame] | 192 | xfs_buf_corruption_error(bp); |
Darrick J. Wong | c2414ad | 2019-10-28 16:12:34 -0700 | [diff] [blame] | 193 | return -EFSCORRUPTED; |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 194 | } |
| 195 | |
Christoph Hellwig | 51908ca | 2019-11-08 14:57:48 -0800 | [diff] [blame] | 196 | xfs_da3_node_hdr_from_disk(dp->i_mount, &ichdr, bp->b_addr); |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 197 | parent_blkno = bp->b_bn; |
| 198 | if (!ichdr.count) { |
| 199 | xfs_trans_brelse(*trans, bp); |
| 200 | return 0; |
| 201 | } |
Christoph Hellwig | 51908ca | 2019-11-08 14:57:48 -0800 | [diff] [blame] | 202 | child_fsb = be32_to_cpu(ichdr.btree[0].before); |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 203 | xfs_trans_brelse(*trans, bp); /* no locks for later trans */ |
| 204 | |
| 205 | /* |
| 206 | * If this is the node level just above the leaves, simply loop |
| 207 | * over the leaves removing all of them. If this is higher up |
| 208 | * in the tree, recurse downward. |
| 209 | */ |
| 210 | for (i = 0; i < ichdr.count; i++) { |
| 211 | /* |
| 212 | * Read the subsidiary block to see what we have to work with. |
| 213 | * Don't do this in a transaction. This is a depth-first |
| 214 | * traversal of the tree so we may deal with many blocks |
| 215 | * before we come back to this one. |
| 216 | */ |
Christoph Hellwig | 02c57f0 | 2019-11-20 09:46:04 -0800 | [diff] [blame] | 217 | error = xfs_da3_node_read(*trans, dp, child_fsb, &child_bp, |
Brian Foster | a53efbd | 2017-10-17 14:16:28 -0700 | [diff] [blame] | 218 | XFS_ATTR_FORK); |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 219 | if (error) |
Eric Sandeen | d99831f | 2014-06-22 15:03:54 +1000 | [diff] [blame] | 220 | return error; |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 221 | |
Brian Foster | a53efbd | 2017-10-17 14:16:28 -0700 | [diff] [blame] | 222 | /* save for re-read later */ |
| 223 | child_blkno = XFS_BUF_ADDR(child_bp); |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 224 | |
Brian Foster | a53efbd | 2017-10-17 14:16:28 -0700 | [diff] [blame] | 225 | /* |
| 226 | * Invalidate the subtree, however we have to. |
| 227 | */ |
| 228 | info = child_bp->b_addr; |
| 229 | switch (info->magic) { |
| 230 | case cpu_to_be16(XFS_DA_NODE_MAGIC): |
| 231 | case cpu_to_be16(XFS_DA3_NODE_MAGIC): |
| 232 | error = xfs_attr3_node_inactive(trans, dp, child_bp, |
| 233 | level + 1); |
| 234 | break; |
| 235 | case cpu_to_be16(XFS_ATTR_LEAF_MAGIC): |
| 236 | case cpu_to_be16(XFS_ATTR3_LEAF_MAGIC): |
| 237 | error = xfs_attr3_leaf_inactive(trans, dp, child_bp); |
| 238 | break; |
| 239 | default: |
Darrick J. Wong | a5155b8 | 2019-11-02 09:40:53 -0700 | [diff] [blame] | 240 | xfs_buf_corruption_error(child_bp); |
Brian Foster | a53efbd | 2017-10-17 14:16:28 -0700 | [diff] [blame] | 241 | xfs_trans_brelse(*trans, child_bp); |
Darrick J. Wong | a5155b8 | 2019-11-02 09:40:53 -0700 | [diff] [blame] | 242 | error = -EFSCORRUPTED; |
Brian Foster | a53efbd | 2017-10-17 14:16:28 -0700 | [diff] [blame] | 243 | break; |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 244 | } |
Brian Foster | a53efbd | 2017-10-17 14:16:28 -0700 | [diff] [blame] | 245 | if (error) |
| 246 | return error; |
| 247 | |
| 248 | /* |
| 249 | * Remove the subsidiary block from the cache and from the log. |
| 250 | */ |
Christoph Hellwig | 2911edb | 2019-11-20 09:46:05 -0800 | [diff] [blame] | 251 | child_bp = xfs_trans_get_buf(*trans, mp->m_ddev_targp, |
| 252 | child_blkno, |
| 253 | XFS_FSB_TO_BB(mp, mp->m_attr_geo->fsbcount), 0); |
| 254 | if (!child_bp) |
| 255 | return -EIO; |
| 256 | error = bp->b_error; |
| 257 | if (error) { |
| 258 | xfs_trans_brelse(*trans, child_bp); |
Brian Foster | a53efbd | 2017-10-17 14:16:28 -0700 | [diff] [blame] | 259 | return error; |
Christoph Hellwig | 2911edb | 2019-11-20 09:46:05 -0800 | [diff] [blame] | 260 | } |
Brian Foster | a53efbd | 2017-10-17 14:16:28 -0700 | [diff] [blame] | 261 | xfs_trans_binval(*trans, child_bp); |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 262 | |
| 263 | /* |
| 264 | * If we're not done, re-read the parent to get the next |
| 265 | * child block number. |
| 266 | */ |
| 267 | if (i + 1 < ichdr.count) { |
Christoph Hellwig | 51908ca | 2019-11-08 14:57:48 -0800 | [diff] [blame] | 268 | struct xfs_da3_icnode_hdr phdr; |
| 269 | |
Christoph Hellwig | 02c57f0 | 2019-11-20 09:46:04 -0800 | [diff] [blame] | 270 | error = xfs_da3_node_read_mapped(*trans, dp, |
| 271 | parent_blkno, &bp, XFS_ATTR_FORK); |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 272 | if (error) |
| 273 | return error; |
Christoph Hellwig | 51908ca | 2019-11-08 14:57:48 -0800 | [diff] [blame] | 274 | xfs_da3_node_hdr_from_disk(dp->i_mount, &phdr, |
| 275 | bp->b_addr); |
| 276 | child_fsb = be32_to_cpu(phdr.btree[i + 1].before); |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 277 | xfs_trans_brelse(*trans, bp); |
| 278 | } |
| 279 | /* |
| 280 | * Atomically commit the whole invalidate stuff. |
| 281 | */ |
Christoph Hellwig | 411350d | 2017-08-28 10:21:03 -0700 | [diff] [blame] | 282 | error = xfs_trans_roll_inode(trans, dp); |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 283 | if (error) |
| 284 | return error; |
| 285 | } |
| 286 | |
| 287 | return 0; |
| 288 | } |
| 289 | |
| 290 | /* |
| 291 | * Indiscriminately delete the entire attribute fork |
| 292 | * |
| 293 | * Recurse (gasp!) through the attribute nodes until we find leaves. |
| 294 | * We're doing a depth-first traversal in order to invalidate everything. |
| 295 | */ |
Eric Sandeen | 0d5a75e | 2016-06-01 17:38:15 +1000 | [diff] [blame] | 296 | static int |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 297 | xfs_attr3_root_inactive( |
| 298 | struct xfs_trans **trans, |
| 299 | struct xfs_inode *dp) |
| 300 | { |
Christoph Hellwig | 2911edb | 2019-11-20 09:46:05 -0800 | [diff] [blame] | 301 | struct xfs_mount *mp = dp->i_mount; |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 302 | struct xfs_da_blkinfo *info; |
| 303 | struct xfs_buf *bp; |
| 304 | xfs_daddr_t blkno; |
| 305 | int error; |
| 306 | |
| 307 | /* |
| 308 | * Read block 0 to see what we have to work with. |
| 309 | * We only get here if we have extents, since we remove |
| 310 | * the extents in reverse order the extent containing |
| 311 | * block 0 must still be there. |
| 312 | */ |
Christoph Hellwig | 02c57f0 | 2019-11-20 09:46:04 -0800 | [diff] [blame] | 313 | error = xfs_da3_node_read(*trans, dp, 0, &bp, XFS_ATTR_FORK); |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 314 | if (error) |
| 315 | return error; |
| 316 | blkno = bp->b_bn; |
| 317 | |
| 318 | /* |
| 319 | * Invalidate the tree, even if the "tree" is only a single leaf block. |
| 320 | * This is a depth-first traversal! |
| 321 | */ |
| 322 | info = bp->b_addr; |
| 323 | switch (info->magic) { |
| 324 | case cpu_to_be16(XFS_DA_NODE_MAGIC): |
| 325 | case cpu_to_be16(XFS_DA3_NODE_MAGIC): |
| 326 | error = xfs_attr3_node_inactive(trans, dp, bp, 1); |
| 327 | break; |
| 328 | case cpu_to_be16(XFS_ATTR_LEAF_MAGIC): |
| 329 | case cpu_to_be16(XFS_ATTR3_LEAF_MAGIC): |
| 330 | error = xfs_attr3_leaf_inactive(trans, dp, bp); |
| 331 | break; |
| 332 | default: |
Darrick J. Wong | c2414ad | 2019-10-28 16:12:34 -0700 | [diff] [blame] | 333 | error = -EFSCORRUPTED; |
Darrick J. Wong | a5155b8 | 2019-11-02 09:40:53 -0700 | [diff] [blame] | 334 | xfs_buf_corruption_error(bp); |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 335 | xfs_trans_brelse(*trans, bp); |
| 336 | break; |
| 337 | } |
| 338 | if (error) |
| 339 | return error; |
| 340 | |
| 341 | /* |
| 342 | * Invalidate the incore copy of the root block. |
| 343 | */ |
Christoph Hellwig | 2911edb | 2019-11-20 09:46:05 -0800 | [diff] [blame] | 344 | bp = xfs_trans_get_buf(*trans, mp->m_ddev_targp, blkno, |
| 345 | XFS_FSB_TO_BB(mp, mp->m_attr_geo->fsbcount), 0); |
| 346 | if (!bp) |
| 347 | return -EIO; |
| 348 | error = bp->b_error; |
| 349 | if (error) { |
| 350 | xfs_trans_brelse(*trans, bp); |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 351 | return error; |
Christoph Hellwig | 2911edb | 2019-11-20 09:46:05 -0800 | [diff] [blame] | 352 | } |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 353 | xfs_trans_binval(*trans, bp); /* remove from cache */ |
| 354 | /* |
| 355 | * Commit the invalidate and start the next transaction. |
| 356 | */ |
Christoph Hellwig | 411350d | 2017-08-28 10:21:03 -0700 | [diff] [blame] | 357 | error = xfs_trans_roll_inode(trans, dp); |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 358 | |
| 359 | return error; |
| 360 | } |
| 361 | |
Dave Chinner | 6dfe5a0 | 2015-05-29 07:40:08 +1000 | [diff] [blame] | 362 | /* |
| 363 | * xfs_attr_inactive kills all traces of an attribute fork on an inode. It |
| 364 | * removes both the on-disk and in-memory inode fork. Note that this also has to |
| 365 | * handle the condition of inodes without attributes but with an attribute fork |
| 366 | * configured, so we can't use xfs_inode_hasattr() here. |
| 367 | * |
| 368 | * The in-memory attribute fork is removed even on error. |
| 369 | */ |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 370 | int |
Dave Chinner | 6dfe5a0 | 2015-05-29 07:40:08 +1000 | [diff] [blame] | 371 | xfs_attr_inactive( |
| 372 | struct xfs_inode *dp) |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 373 | { |
Dave Chinner | 6dfe5a0 | 2015-05-29 07:40:08 +1000 | [diff] [blame] | 374 | struct xfs_trans *trans; |
| 375 | struct xfs_mount *mp; |
Dave Chinner | 6dfe5a0 | 2015-05-29 07:40:08 +1000 | [diff] [blame] | 376 | int lock_mode = XFS_ILOCK_SHARED; |
| 377 | int error = 0; |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 378 | |
| 379 | mp = dp->i_mount; |
| 380 | ASSERT(! XFS_NOT_DQATTACHED(mp, dp)); |
| 381 | |
Dave Chinner | 6dfe5a0 | 2015-05-29 07:40:08 +1000 | [diff] [blame] | 382 | xfs_ilock(dp, lock_mode); |
| 383 | if (!XFS_IFORK_Q(dp)) |
| 384 | goto out_destroy_fork; |
| 385 | xfs_iunlock(dp, lock_mode); |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 386 | |
Dave Chinner | 6dfe5a0 | 2015-05-29 07:40:08 +1000 | [diff] [blame] | 387 | lock_mode = 0; |
Christoph Hellwig | 253f491 | 2016-04-06 09:19:55 +1000 | [diff] [blame] | 388 | |
| 389 | error = xfs_trans_alloc(mp, &M_RES(mp)->tr_attrinval, 0, 0, 0, &trans); |
Dave Chinner | 6dfe5a0 | 2015-05-29 07:40:08 +1000 | [diff] [blame] | 390 | if (error) |
Christoph Hellwig | 253f491 | 2016-04-06 09:19:55 +1000 | [diff] [blame] | 391 | goto out_destroy_fork; |
Dave Chinner | 6dfe5a0 | 2015-05-29 07:40:08 +1000 | [diff] [blame] | 392 | |
| 393 | lock_mode = XFS_ILOCK_EXCL; |
Dave Chinner | 6dfe5a0 | 2015-05-29 07:40:08 +1000 | [diff] [blame] | 394 | xfs_ilock(dp, lock_mode); |
| 395 | |
| 396 | if (!XFS_IFORK_Q(dp)) |
| 397 | goto out_cancel; |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 398 | |
| 399 | /* |
| 400 | * No need to make quota reservations here. We expect to release some |
| 401 | * blocks, not allocate, in the common case. |
| 402 | */ |
| 403 | xfs_trans_ijoin(trans, dp, 0); |
| 404 | |
Brian Foster | f66bf04 | 2015-06-23 08:47:20 +1000 | [diff] [blame] | 405 | /* |
| 406 | * Invalidate and truncate the attribute fork extents. Make sure the |
| 407 | * fork actually has attributes as otherwise the invalidation has no |
| 408 | * blocks to read and returns an error. In this case, just do the fork |
| 409 | * removal below. |
| 410 | */ |
| 411 | if (xfs_inode_hasattr(dp) && |
| 412 | dp->i_d.di_aformat != XFS_DINODE_FMT_LOCAL) { |
Dave Chinner | 6dfe5a0 | 2015-05-29 07:40:08 +1000 | [diff] [blame] | 413 | error = xfs_attr3_root_inactive(&trans, dp); |
| 414 | if (error) |
| 415 | goto out_cancel; |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 416 | |
Dave Chinner | 6dfe5a0 | 2015-05-29 07:40:08 +1000 | [diff] [blame] | 417 | error = xfs_itruncate_extents(&trans, dp, XFS_ATTR_FORK, 0); |
| 418 | if (error) |
| 419 | goto out_cancel; |
| 420 | } |
| 421 | |
| 422 | /* Reset the attribute fork - this also destroys the in-core fork */ |
| 423 | xfs_attr_fork_remove(dp, trans); |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 424 | |
Christoph Hellwig | 7039331 | 2015-06-04 13:48:08 +1000 | [diff] [blame] | 425 | error = xfs_trans_commit(trans); |
Dave Chinner | 6dfe5a0 | 2015-05-29 07:40:08 +1000 | [diff] [blame] | 426 | xfs_iunlock(dp, lock_mode); |
Eric Sandeen | d99831f | 2014-06-22 15:03:54 +1000 | [diff] [blame] | 427 | return error; |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 428 | |
Dave Chinner | 6dfe5a0 | 2015-05-29 07:40:08 +1000 | [diff] [blame] | 429 | out_cancel: |
Christoph Hellwig | 4906e21 | 2015-06-04 13:47:56 +1000 | [diff] [blame] | 430 | xfs_trans_cancel(trans); |
Dave Chinner | 6dfe5a0 | 2015-05-29 07:40:08 +1000 | [diff] [blame] | 431 | out_destroy_fork: |
| 432 | /* kill the in-core attr fork before we drop the inode lock */ |
| 433 | if (dp->i_afp) |
| 434 | xfs_idestroy_fork(dp, XFS_ATTR_FORK); |
| 435 | if (lock_mode) |
| 436 | xfs_iunlock(dp, lock_mode); |
Eric Sandeen | d99831f | 2014-06-22 15:03:54 +1000 | [diff] [blame] | 437 | return error; |
Dave Chinner | fde2227 | 2013-08-12 20:49:39 +1000 | [diff] [blame] | 438 | } |