Dave Chinner | 0b61f8a | 2018-06-05 19:42:14 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2016 Oracle. All Rights Reserved. |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 4 | * Author: Darrick J. Wong <darrick.wong@oracle.com> |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 5 | */ |
| 6 | #include "xfs.h" |
| 7 | #include "xfs_fs.h" |
| 8 | #include "xfs_format.h" |
| 9 | #include "xfs_log_format.h" |
| 10 | #include "xfs_trans_resv.h" |
Darrick J. Wong | 9e88b5d | 2016-08-03 12:09:48 +1000 | [diff] [blame] | 11 | #include "xfs_bit.h" |
Darrick J. Wong | b31c2bd | 2018-02-22 14:41:25 -0800 | [diff] [blame] | 12 | #include "xfs_shared.h" |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 13 | #include "xfs_mount.h" |
Darrick J. Wong | 9c19464 | 2016-08-03 12:16:05 +1000 | [diff] [blame] | 14 | #include "xfs_defer.h" |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 15 | #include "xfs_trans.h" |
| 16 | #include "xfs_trans_priv.h" |
| 17 | #include "xfs_buf_item.h" |
| 18 | #include "xfs_rmap_item.h" |
| 19 | #include "xfs_log.h" |
Darrick J. Wong | 9c19464 | 2016-08-03 12:16:05 +1000 | [diff] [blame] | 20 | #include "xfs_rmap.h" |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 21 | |
| 22 | |
| 23 | kmem_zone_t *xfs_rui_zone; |
| 24 | kmem_zone_t *xfs_rud_zone; |
| 25 | |
| 26 | static inline struct xfs_rui_log_item *RUI_ITEM(struct xfs_log_item *lip) |
| 27 | { |
| 28 | return container_of(lip, struct xfs_rui_log_item, rui_item); |
| 29 | } |
| 30 | |
| 31 | void |
| 32 | xfs_rui_item_free( |
| 33 | struct xfs_rui_log_item *ruip) |
| 34 | { |
| 35 | if (ruip->rui_format.rui_nextents > XFS_RUI_MAX_FAST_EXTENTS) |
| 36 | kmem_free(ruip); |
| 37 | else |
| 38 | kmem_zone_free(xfs_rui_zone, ruip); |
| 39 | } |
| 40 | |
Dave Chinner | 0612d11 | 2018-04-02 20:08:27 -0700 | [diff] [blame] | 41 | /* |
| 42 | * Freeing the RUI requires that we remove it from the AIL if it has already |
| 43 | * been placed there. However, the RUI may not yet have been placed in the AIL |
| 44 | * when called by xfs_rui_release() from RUD processing due to the ordering of |
| 45 | * committed vs unpin operations in bulk insert operations. Hence the reference |
| 46 | * count to ensure only the last caller frees the RUI. |
| 47 | */ |
| 48 | void |
| 49 | xfs_rui_release( |
| 50 | struct xfs_rui_log_item *ruip) |
| 51 | { |
| 52 | ASSERT(atomic_read(&ruip->rui_refcount) > 0); |
| 53 | if (atomic_dec_and_test(&ruip->rui_refcount)) { |
| 54 | xfs_trans_ail_remove(&ruip->rui_item, SHUTDOWN_LOG_IO_ERROR); |
| 55 | xfs_rui_item_free(ruip); |
| 56 | } |
| 57 | } |
| 58 | |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 59 | STATIC void |
| 60 | xfs_rui_item_size( |
| 61 | struct xfs_log_item *lip, |
| 62 | int *nvecs, |
| 63 | int *nbytes) |
| 64 | { |
Darrick J. Wong | cd00158 | 2016-09-19 10:24:27 +1000 | [diff] [blame] | 65 | struct xfs_rui_log_item *ruip = RUI_ITEM(lip); |
| 66 | |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 67 | *nvecs += 1; |
Darrick J. Wong | cd00158 | 2016-09-19 10:24:27 +1000 | [diff] [blame] | 68 | *nbytes += xfs_rui_log_format_sizeof(ruip->rui_format.rui_nextents); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | /* |
| 72 | * This is called to fill in the vector of log iovecs for the |
| 73 | * given rui log item. We use only 1 iovec, and we point that |
| 74 | * at the rui_log_format structure embedded in the rui item. |
| 75 | * It is at this point that we assert that all of the extent |
| 76 | * slots in the rui item have been filled. |
| 77 | */ |
| 78 | STATIC void |
| 79 | xfs_rui_item_format( |
| 80 | struct xfs_log_item *lip, |
| 81 | struct xfs_log_vec *lv) |
| 82 | { |
| 83 | struct xfs_rui_log_item *ruip = RUI_ITEM(lip); |
| 84 | struct xfs_log_iovec *vecp = NULL; |
| 85 | |
| 86 | ASSERT(atomic_read(&ruip->rui_next_extent) == |
| 87 | ruip->rui_format.rui_nextents); |
| 88 | |
| 89 | ruip->rui_format.rui_type = XFS_LI_RUI; |
| 90 | ruip->rui_format.rui_size = 1; |
| 91 | |
| 92 | xlog_copy_iovec(lv, &vecp, XLOG_REG_TYPE_RUI_FORMAT, &ruip->rui_format, |
Darrick J. Wong | cd00158 | 2016-09-19 10:24:27 +1000 | [diff] [blame] | 93 | xfs_rui_log_format_sizeof(ruip->rui_format.rui_nextents)); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | /* |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 97 | * The unpin operation is the last place an RUI is manipulated in the log. It is |
| 98 | * either inserted in the AIL or aborted in the event of a log I/O error. In |
| 99 | * either case, the RUI transaction has been successfully committed to make it |
| 100 | * this far. Therefore, we expect whoever committed the RUI to either construct |
| 101 | * and commit the RUD or drop the RUD's reference in the event of error. Simply |
| 102 | * drop the log's RUI reference now that the log is done with it. |
| 103 | */ |
| 104 | STATIC void |
| 105 | xfs_rui_item_unpin( |
| 106 | struct xfs_log_item *lip, |
| 107 | int remove) |
| 108 | { |
| 109 | struct xfs_rui_log_item *ruip = RUI_ITEM(lip); |
| 110 | |
| 111 | xfs_rui_release(ruip); |
| 112 | } |
| 113 | |
| 114 | /* |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 115 | * The RUI has been either committed or aborted if the transaction has been |
| 116 | * cancelled. If the transaction was cancelled, an RUD isn't going to be |
| 117 | * constructed and thus we free the RUI here directly. |
| 118 | */ |
| 119 | STATIC void |
Christoph Hellwig | ddf9205 | 2019-06-28 19:27:32 -0700 | [diff] [blame^] | 120 | xfs_rui_item_release( |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 121 | struct xfs_log_item *lip) |
| 122 | { |
Christoph Hellwig | ddf9205 | 2019-06-28 19:27:32 -0700 | [diff] [blame^] | 123 | xfs_rui_release(RUI_ITEM(lip)); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | /* |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 127 | * This is the ops vector shared by all rui log items. |
| 128 | */ |
| 129 | static const struct xfs_item_ops xfs_rui_item_ops = { |
| 130 | .iop_size = xfs_rui_item_size, |
| 131 | .iop_format = xfs_rui_item_format, |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 132 | .iop_unpin = xfs_rui_item_unpin, |
Christoph Hellwig | ddf9205 | 2019-06-28 19:27:32 -0700 | [diff] [blame^] | 133 | .iop_release = xfs_rui_item_release, |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 134 | }; |
| 135 | |
| 136 | /* |
| 137 | * Allocate and initialize an rui item with the given number of extents. |
| 138 | */ |
| 139 | struct xfs_rui_log_item * |
| 140 | xfs_rui_init( |
| 141 | struct xfs_mount *mp, |
| 142 | uint nextents) |
| 143 | |
| 144 | { |
| 145 | struct xfs_rui_log_item *ruip; |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 146 | |
| 147 | ASSERT(nextents > 0); |
Darrick J. Wong | cd00158 | 2016-09-19 10:24:27 +1000 | [diff] [blame] | 148 | if (nextents > XFS_RUI_MAX_FAST_EXTENTS) |
| 149 | ruip = kmem_zalloc(xfs_rui_log_item_sizeof(nextents), KM_SLEEP); |
| 150 | else |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 151 | ruip = kmem_zone_zalloc(xfs_rui_zone, KM_SLEEP); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 152 | |
| 153 | xfs_log_item_init(mp, &ruip->rui_item, XFS_LI_RUI, &xfs_rui_item_ops); |
| 154 | ruip->rui_format.rui_nextents = nextents; |
| 155 | ruip->rui_format.rui_id = (uintptr_t)(void *)ruip; |
| 156 | atomic_set(&ruip->rui_next_extent, 0); |
| 157 | atomic_set(&ruip->rui_refcount, 2); |
| 158 | |
| 159 | return ruip; |
| 160 | } |
| 161 | |
| 162 | /* |
| 163 | * Copy an RUI format buffer from the given buf, and into the destination |
| 164 | * RUI format structure. The RUI/RUD items were designed not to need any |
| 165 | * special alignment handling. |
| 166 | */ |
| 167 | int |
| 168 | xfs_rui_copy_format( |
| 169 | struct xfs_log_iovec *buf, |
| 170 | struct xfs_rui_log_format *dst_rui_fmt) |
| 171 | { |
| 172 | struct xfs_rui_log_format *src_rui_fmt; |
| 173 | uint len; |
| 174 | |
| 175 | src_rui_fmt = buf->i_addr; |
Darrick J. Wong | cd00158 | 2016-09-19 10:24:27 +1000 | [diff] [blame] | 176 | len = xfs_rui_log_format_sizeof(src_rui_fmt->rui_nextents); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 177 | |
| 178 | if (buf->i_len != len) |
| 179 | return -EFSCORRUPTED; |
| 180 | |
Darrick J. Wong | cd00158 | 2016-09-19 10:24:27 +1000 | [diff] [blame] | 181 | memcpy(dst_rui_fmt, src_rui_fmt, len); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 182 | return 0; |
| 183 | } |
| 184 | |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 185 | static inline struct xfs_rud_log_item *RUD_ITEM(struct xfs_log_item *lip) |
| 186 | { |
| 187 | return container_of(lip, struct xfs_rud_log_item, rud_item); |
| 188 | } |
| 189 | |
| 190 | STATIC void |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 191 | xfs_rud_item_size( |
| 192 | struct xfs_log_item *lip, |
| 193 | int *nvecs, |
| 194 | int *nbytes) |
| 195 | { |
| 196 | *nvecs += 1; |
Darrick J. Wong | 722e251 | 2016-08-03 12:28:43 +1000 | [diff] [blame] | 197 | *nbytes += sizeof(struct xfs_rud_log_format); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | /* |
| 201 | * This is called to fill in the vector of log iovecs for the |
| 202 | * given rud log item. We use only 1 iovec, and we point that |
| 203 | * at the rud_log_format structure embedded in the rud item. |
| 204 | * It is at this point that we assert that all of the extent |
| 205 | * slots in the rud item have been filled. |
| 206 | */ |
| 207 | STATIC void |
| 208 | xfs_rud_item_format( |
| 209 | struct xfs_log_item *lip, |
| 210 | struct xfs_log_vec *lv) |
| 211 | { |
| 212 | struct xfs_rud_log_item *rudp = RUD_ITEM(lip); |
| 213 | struct xfs_log_iovec *vecp = NULL; |
| 214 | |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 215 | rudp->rud_format.rud_type = XFS_LI_RUD; |
| 216 | rudp->rud_format.rud_size = 1; |
| 217 | |
| 218 | xlog_copy_iovec(lv, &vecp, XLOG_REG_TYPE_RUD_FORMAT, &rudp->rud_format, |
Darrick J. Wong | 722e251 | 2016-08-03 12:28:43 +1000 | [diff] [blame] | 219 | sizeof(struct xfs_rud_log_format)); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | /* |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 223 | * The RUD is either committed or aborted if the transaction is cancelled. If |
| 224 | * the transaction is cancelled, drop our reference to the RUI and free the |
| 225 | * RUD. |
| 226 | */ |
| 227 | STATIC void |
Christoph Hellwig | ddf9205 | 2019-06-28 19:27:32 -0700 | [diff] [blame^] | 228 | xfs_rud_item_release( |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 229 | struct xfs_log_item *lip) |
| 230 | { |
| 231 | struct xfs_rud_log_item *rudp = RUD_ITEM(lip); |
| 232 | |
Christoph Hellwig | ddf9205 | 2019-06-28 19:27:32 -0700 | [diff] [blame^] | 233 | xfs_rui_release(rudp->rud_ruip); |
| 234 | kmem_zone_free(xfs_rud_zone, rudp); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | /* |
| 238 | * When the rud item is committed to disk, all we need to do is delete our |
| 239 | * reference to our partner rui item and then free ourselves. Since we're |
| 240 | * freeing ourselves we must return -1 to keep the transaction code from |
| 241 | * further referencing this item. |
| 242 | */ |
| 243 | STATIC xfs_lsn_t |
| 244 | xfs_rud_item_committed( |
| 245 | struct xfs_log_item *lip, |
| 246 | xfs_lsn_t lsn) |
| 247 | { |
| 248 | struct xfs_rud_log_item *rudp = RUD_ITEM(lip); |
| 249 | |
| 250 | /* |
| 251 | * Drop the RUI reference regardless of whether the RUD has been |
| 252 | * aborted. Once the RUD transaction is constructed, it is the sole |
| 253 | * responsibility of the RUD to release the RUI (even if the RUI is |
| 254 | * aborted due to log I/O error). |
| 255 | */ |
| 256 | xfs_rui_release(rudp->rud_ruip); |
Darrick J. Wong | 722e251 | 2016-08-03 12:28:43 +1000 | [diff] [blame] | 257 | kmem_zone_free(xfs_rud_zone, rudp); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 258 | |
| 259 | return (xfs_lsn_t)-1; |
| 260 | } |
| 261 | |
| 262 | /* |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 263 | * This is the ops vector shared by all rud log items. |
| 264 | */ |
| 265 | static const struct xfs_item_ops xfs_rud_item_ops = { |
| 266 | .iop_size = xfs_rud_item_size, |
| 267 | .iop_format = xfs_rud_item_format, |
Christoph Hellwig | ddf9205 | 2019-06-28 19:27:32 -0700 | [diff] [blame^] | 268 | .iop_release = xfs_rud_item_release, |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 269 | .iop_committed = xfs_rud_item_committed, |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 270 | }; |
| 271 | |
| 272 | /* |
| 273 | * Allocate and initialize an rud item with the given number of extents. |
| 274 | */ |
| 275 | struct xfs_rud_log_item * |
| 276 | xfs_rud_init( |
| 277 | struct xfs_mount *mp, |
Darrick J. Wong | 722e251 | 2016-08-03 12:28:43 +1000 | [diff] [blame] | 278 | struct xfs_rui_log_item *ruip) |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 279 | |
| 280 | { |
| 281 | struct xfs_rud_log_item *rudp; |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 282 | |
Darrick J. Wong | 722e251 | 2016-08-03 12:28:43 +1000 | [diff] [blame] | 283 | rudp = kmem_zone_zalloc(xfs_rud_zone, KM_SLEEP); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 284 | xfs_log_item_init(mp, &rudp->rud_item, XFS_LI_RUD, &xfs_rud_item_ops); |
| 285 | rudp->rud_ruip = ruip; |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 286 | rudp->rud_format.rud_rui_id = ruip->rui_format.rui_id; |
| 287 | |
| 288 | return rudp; |
| 289 | } |
Darrick J. Wong | 9e88b5d | 2016-08-03 12:09:48 +1000 | [diff] [blame] | 290 | |
| 291 | /* |
| 292 | * Process an rmap update intent item that was recovered from the log. |
| 293 | * We need to update the rmapbt. |
| 294 | */ |
| 295 | int |
| 296 | xfs_rui_recover( |
| 297 | struct xfs_mount *mp, |
| 298 | struct xfs_rui_log_item *ruip) |
| 299 | { |
| 300 | int i; |
| 301 | int error = 0; |
| 302 | struct xfs_map_extent *rmap; |
| 303 | xfs_fsblock_t startblock_fsb; |
| 304 | bool op_ok; |
Darrick J. Wong | 9c19464 | 2016-08-03 12:16:05 +1000 | [diff] [blame] | 305 | struct xfs_rud_log_item *rudp; |
| 306 | enum xfs_rmap_intent_type type; |
| 307 | int whichfork; |
| 308 | xfs_exntst_t state; |
| 309 | struct xfs_trans *tp; |
| 310 | struct xfs_btree_cur *rcur = NULL; |
Darrick J. Wong | 9e88b5d | 2016-08-03 12:09:48 +1000 | [diff] [blame] | 311 | |
| 312 | ASSERT(!test_bit(XFS_RUI_RECOVERED, &ruip->rui_flags)); |
| 313 | |
| 314 | /* |
| 315 | * First check the validity of the extents described by the |
| 316 | * RUI. If any are bad, then assume that all are bad and |
| 317 | * just toss the RUI. |
| 318 | */ |
| 319 | for (i = 0; i < ruip->rui_format.rui_nextents; i++) { |
Darrick J. Wong | e127faf | 2016-08-03 12:29:32 +1000 | [diff] [blame] | 320 | rmap = &ruip->rui_format.rui_extents[i]; |
Darrick J. Wong | 9e88b5d | 2016-08-03 12:09:48 +1000 | [diff] [blame] | 321 | startblock_fsb = XFS_BB_TO_FSB(mp, |
| 322 | XFS_FSB_TO_DADDR(mp, rmap->me_startblock)); |
| 323 | switch (rmap->me_flags & XFS_RMAP_EXTENT_TYPE_MASK) { |
| 324 | case XFS_RMAP_EXTENT_MAP: |
Darrick J. Wong | 0e07c03 | 2016-10-03 09:11:47 -0700 | [diff] [blame] | 325 | case XFS_RMAP_EXTENT_MAP_SHARED: |
Darrick J. Wong | 9e88b5d | 2016-08-03 12:09:48 +1000 | [diff] [blame] | 326 | case XFS_RMAP_EXTENT_UNMAP: |
Darrick J. Wong | 0e07c03 | 2016-10-03 09:11:47 -0700 | [diff] [blame] | 327 | case XFS_RMAP_EXTENT_UNMAP_SHARED: |
Darrick J. Wong | 9e88b5d | 2016-08-03 12:09:48 +1000 | [diff] [blame] | 328 | case XFS_RMAP_EXTENT_CONVERT: |
Darrick J. Wong | 0e07c03 | 2016-10-03 09:11:47 -0700 | [diff] [blame] | 329 | case XFS_RMAP_EXTENT_CONVERT_SHARED: |
Darrick J. Wong | 9e88b5d | 2016-08-03 12:09:48 +1000 | [diff] [blame] | 330 | case XFS_RMAP_EXTENT_ALLOC: |
| 331 | case XFS_RMAP_EXTENT_FREE: |
| 332 | op_ok = true; |
| 333 | break; |
| 334 | default: |
| 335 | op_ok = false; |
| 336 | break; |
| 337 | } |
Darrick J. Wong | e127faf | 2016-08-03 12:29:32 +1000 | [diff] [blame] | 338 | if (!op_ok || startblock_fsb == 0 || |
| 339 | rmap->me_len == 0 || |
| 340 | startblock_fsb >= mp->m_sb.sb_dblocks || |
| 341 | rmap->me_len >= mp->m_sb.sb_agblocks || |
Darrick J. Wong | 9e88b5d | 2016-08-03 12:09:48 +1000 | [diff] [blame] | 342 | (rmap->me_flags & ~XFS_RMAP_EXTENT_FLAGS)) { |
| 343 | /* |
| 344 | * This will pull the RUI from the AIL and |
| 345 | * free the memory associated with it. |
| 346 | */ |
| 347 | set_bit(XFS_RUI_RECOVERED, &ruip->rui_flags); |
| 348 | xfs_rui_release(ruip); |
| 349 | return -EIO; |
| 350 | } |
| 351 | } |
| 352 | |
Darrick J. Wong | b31c2bd | 2018-02-22 14:41:25 -0800 | [diff] [blame] | 353 | error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, |
| 354 | mp->m_rmap_maxlevels, 0, XFS_TRANS_RESERVE, &tp); |
Darrick J. Wong | 9c19464 | 2016-08-03 12:16:05 +1000 | [diff] [blame] | 355 | if (error) |
| 356 | return error; |
Darrick J. Wong | 722e251 | 2016-08-03 12:28:43 +1000 | [diff] [blame] | 357 | rudp = xfs_trans_get_rud(tp, ruip); |
Darrick J. Wong | 9c19464 | 2016-08-03 12:16:05 +1000 | [diff] [blame] | 358 | |
| 359 | for (i = 0; i < ruip->rui_format.rui_nextents; i++) { |
Darrick J. Wong | e127faf | 2016-08-03 12:29:32 +1000 | [diff] [blame] | 360 | rmap = &ruip->rui_format.rui_extents[i]; |
Darrick J. Wong | 9c19464 | 2016-08-03 12:16:05 +1000 | [diff] [blame] | 361 | state = (rmap->me_flags & XFS_RMAP_EXTENT_UNWRITTEN) ? |
| 362 | XFS_EXT_UNWRITTEN : XFS_EXT_NORM; |
| 363 | whichfork = (rmap->me_flags & XFS_RMAP_EXTENT_ATTR_FORK) ? |
| 364 | XFS_ATTR_FORK : XFS_DATA_FORK; |
| 365 | switch (rmap->me_flags & XFS_RMAP_EXTENT_TYPE_MASK) { |
| 366 | case XFS_RMAP_EXTENT_MAP: |
| 367 | type = XFS_RMAP_MAP; |
| 368 | break; |
Darrick J. Wong | ceeb9c8 | 2016-10-03 09:11:48 -0700 | [diff] [blame] | 369 | case XFS_RMAP_EXTENT_MAP_SHARED: |
| 370 | type = XFS_RMAP_MAP_SHARED; |
| 371 | break; |
Darrick J. Wong | 9c19464 | 2016-08-03 12:16:05 +1000 | [diff] [blame] | 372 | case XFS_RMAP_EXTENT_UNMAP: |
| 373 | type = XFS_RMAP_UNMAP; |
| 374 | break; |
Darrick J. Wong | ceeb9c8 | 2016-10-03 09:11:48 -0700 | [diff] [blame] | 375 | case XFS_RMAP_EXTENT_UNMAP_SHARED: |
| 376 | type = XFS_RMAP_UNMAP_SHARED; |
| 377 | break; |
Darrick J. Wong | 9c19464 | 2016-08-03 12:16:05 +1000 | [diff] [blame] | 378 | case XFS_RMAP_EXTENT_CONVERT: |
| 379 | type = XFS_RMAP_CONVERT; |
| 380 | break; |
Darrick J. Wong | 3f165b3 | 2016-10-03 09:11:48 -0700 | [diff] [blame] | 381 | case XFS_RMAP_EXTENT_CONVERT_SHARED: |
| 382 | type = XFS_RMAP_CONVERT_SHARED; |
| 383 | break; |
Darrick J. Wong | 9c19464 | 2016-08-03 12:16:05 +1000 | [diff] [blame] | 384 | case XFS_RMAP_EXTENT_ALLOC: |
| 385 | type = XFS_RMAP_ALLOC; |
| 386 | break; |
| 387 | case XFS_RMAP_EXTENT_FREE: |
| 388 | type = XFS_RMAP_FREE; |
| 389 | break; |
| 390 | default: |
| 391 | error = -EFSCORRUPTED; |
| 392 | goto abort_error; |
| 393 | } |
| 394 | error = xfs_trans_log_finish_rmap_update(tp, rudp, type, |
| 395 | rmap->me_owner, whichfork, |
| 396 | rmap->me_startoff, rmap->me_startblock, |
| 397 | rmap->me_len, state, &rcur); |
| 398 | if (error) |
| 399 | goto abort_error; |
| 400 | |
| 401 | } |
| 402 | |
| 403 | xfs_rmap_finish_one_cleanup(tp, rcur, error); |
Darrick J. Wong | 9e88b5d | 2016-08-03 12:09:48 +1000 | [diff] [blame] | 404 | set_bit(XFS_RUI_RECOVERED, &ruip->rui_flags); |
Darrick J. Wong | 9c19464 | 2016-08-03 12:16:05 +1000 | [diff] [blame] | 405 | error = xfs_trans_commit(tp); |
| 406 | return error; |
| 407 | |
| 408 | abort_error: |
| 409 | xfs_rmap_finish_one_cleanup(tp, rcur, error); |
| 410 | xfs_trans_cancel(tp); |
Darrick J. Wong | 9e88b5d | 2016-08-03 12:09:48 +1000 | [diff] [blame] | 411 | return error; |
| 412 | } |