Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 Oracle. All Rights Reserved. |
| 3 | * |
| 4 | * Author: Darrick J. Wong <darrick.wong@oracle.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version 2 |
| 9 | * of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it would be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write the Free Software Foundation, |
| 18 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. |
| 19 | */ |
| 20 | #include "xfs.h" |
| 21 | #include "xfs_fs.h" |
| 22 | #include "xfs_format.h" |
| 23 | #include "xfs_log_format.h" |
| 24 | #include "xfs_trans_resv.h" |
Darrick J. Wong | 9e88b5d | 2016-08-03 12:09:48 +1000 | [diff] [blame] | 25 | #include "xfs_bit.h" |
Darrick J. Wong | b31c2bd | 2018-02-22 14:41:25 -0800 | [diff] [blame] | 26 | #include "xfs_shared.h" |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 27 | #include "xfs_mount.h" |
Darrick J. Wong | 9c19464 | 2016-08-03 12:16:05 +1000 | [diff] [blame] | 28 | #include "xfs_defer.h" |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 29 | #include "xfs_trans.h" |
| 30 | #include "xfs_trans_priv.h" |
| 31 | #include "xfs_buf_item.h" |
| 32 | #include "xfs_rmap_item.h" |
| 33 | #include "xfs_log.h" |
Darrick J. Wong | 9c19464 | 2016-08-03 12:16:05 +1000 | [diff] [blame] | 34 | #include "xfs_rmap.h" |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 35 | |
| 36 | |
| 37 | kmem_zone_t *xfs_rui_zone; |
| 38 | kmem_zone_t *xfs_rud_zone; |
| 39 | |
| 40 | static inline struct xfs_rui_log_item *RUI_ITEM(struct xfs_log_item *lip) |
| 41 | { |
| 42 | return container_of(lip, struct xfs_rui_log_item, rui_item); |
| 43 | } |
| 44 | |
| 45 | void |
| 46 | xfs_rui_item_free( |
| 47 | struct xfs_rui_log_item *ruip) |
| 48 | { |
| 49 | if (ruip->rui_format.rui_nextents > XFS_RUI_MAX_FAST_EXTENTS) |
| 50 | kmem_free(ruip); |
| 51 | else |
| 52 | kmem_zone_free(xfs_rui_zone, ruip); |
| 53 | } |
| 54 | |
Dave Chinner | 0612d11 | 2018-04-02 20:08:27 -0700 | [diff] [blame] | 55 | /* |
| 56 | * Freeing the RUI requires that we remove it from the AIL if it has already |
| 57 | * been placed there. However, the RUI may not yet have been placed in the AIL |
| 58 | * when called by xfs_rui_release() from RUD processing due to the ordering of |
| 59 | * committed vs unpin operations in bulk insert operations. Hence the reference |
| 60 | * count to ensure only the last caller frees the RUI. |
| 61 | */ |
| 62 | void |
| 63 | xfs_rui_release( |
| 64 | struct xfs_rui_log_item *ruip) |
| 65 | { |
| 66 | ASSERT(atomic_read(&ruip->rui_refcount) > 0); |
| 67 | if (atomic_dec_and_test(&ruip->rui_refcount)) { |
| 68 | xfs_trans_ail_remove(&ruip->rui_item, SHUTDOWN_LOG_IO_ERROR); |
| 69 | xfs_rui_item_free(ruip); |
| 70 | } |
| 71 | } |
| 72 | |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 73 | STATIC void |
| 74 | xfs_rui_item_size( |
| 75 | struct xfs_log_item *lip, |
| 76 | int *nvecs, |
| 77 | int *nbytes) |
| 78 | { |
Darrick J. Wong | cd00158 | 2016-09-19 10:24:27 +1000 | [diff] [blame] | 79 | struct xfs_rui_log_item *ruip = RUI_ITEM(lip); |
| 80 | |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 81 | *nvecs += 1; |
Darrick J. Wong | cd00158 | 2016-09-19 10:24:27 +1000 | [diff] [blame] | 82 | *nbytes += xfs_rui_log_format_sizeof(ruip->rui_format.rui_nextents); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | /* |
| 86 | * This is called to fill in the vector of log iovecs for the |
| 87 | * given rui log item. We use only 1 iovec, and we point that |
| 88 | * at the rui_log_format structure embedded in the rui item. |
| 89 | * It is at this point that we assert that all of the extent |
| 90 | * slots in the rui item have been filled. |
| 91 | */ |
| 92 | STATIC void |
| 93 | xfs_rui_item_format( |
| 94 | struct xfs_log_item *lip, |
| 95 | struct xfs_log_vec *lv) |
| 96 | { |
| 97 | struct xfs_rui_log_item *ruip = RUI_ITEM(lip); |
| 98 | struct xfs_log_iovec *vecp = NULL; |
| 99 | |
| 100 | ASSERT(atomic_read(&ruip->rui_next_extent) == |
| 101 | ruip->rui_format.rui_nextents); |
| 102 | |
| 103 | ruip->rui_format.rui_type = XFS_LI_RUI; |
| 104 | ruip->rui_format.rui_size = 1; |
| 105 | |
| 106 | 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] | 107 | xfs_rui_log_format_sizeof(ruip->rui_format.rui_nextents)); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | /* |
| 111 | * Pinning has no meaning for an rui item, so just return. |
| 112 | */ |
| 113 | STATIC void |
| 114 | xfs_rui_item_pin( |
| 115 | struct xfs_log_item *lip) |
| 116 | { |
| 117 | } |
| 118 | |
| 119 | /* |
| 120 | * The unpin operation is the last place an RUI is manipulated in the log. It is |
| 121 | * either inserted in the AIL or aborted in the event of a log I/O error. In |
| 122 | * either case, the RUI transaction has been successfully committed to make it |
| 123 | * this far. Therefore, we expect whoever committed the RUI to either construct |
| 124 | * and commit the RUD or drop the RUD's reference in the event of error. Simply |
| 125 | * drop the log's RUI reference now that the log is done with it. |
| 126 | */ |
| 127 | STATIC void |
| 128 | xfs_rui_item_unpin( |
| 129 | struct xfs_log_item *lip, |
| 130 | int remove) |
| 131 | { |
| 132 | struct xfs_rui_log_item *ruip = RUI_ITEM(lip); |
| 133 | |
| 134 | xfs_rui_release(ruip); |
| 135 | } |
| 136 | |
| 137 | /* |
| 138 | * RUI items have no locking or pushing. However, since RUIs are pulled from |
| 139 | * the AIL when their corresponding RUDs are committed to disk, their situation |
| 140 | * is very similar to being pinned. Return XFS_ITEM_PINNED so that the caller |
| 141 | * will eventually flush the log. This should help in getting the RUI out of |
| 142 | * the AIL. |
| 143 | */ |
| 144 | STATIC uint |
| 145 | xfs_rui_item_push( |
| 146 | struct xfs_log_item *lip, |
| 147 | struct list_head *buffer_list) |
| 148 | { |
| 149 | return XFS_ITEM_PINNED; |
| 150 | } |
| 151 | |
| 152 | /* |
| 153 | * The RUI has been either committed or aborted if the transaction has been |
| 154 | * cancelled. If the transaction was cancelled, an RUD isn't going to be |
| 155 | * constructed and thus we free the RUI here directly. |
| 156 | */ |
| 157 | STATIC void |
| 158 | xfs_rui_item_unlock( |
| 159 | struct xfs_log_item *lip) |
| 160 | { |
| 161 | if (lip->li_flags & XFS_LI_ABORTED) |
Dave Chinner | 0612d11 | 2018-04-02 20:08:27 -0700 | [diff] [blame] | 162 | xfs_rui_release(RUI_ITEM(lip)); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | /* |
| 166 | * The RUI is logged only once and cannot be moved in the log, so simply return |
| 167 | * the lsn at which it's been logged. |
| 168 | */ |
| 169 | STATIC xfs_lsn_t |
| 170 | xfs_rui_item_committed( |
| 171 | struct xfs_log_item *lip, |
| 172 | xfs_lsn_t lsn) |
| 173 | { |
| 174 | return lsn; |
| 175 | } |
| 176 | |
| 177 | /* |
| 178 | * The RUI dependency tracking op doesn't do squat. It can't because |
| 179 | * it doesn't know where the free extent is coming from. The dependency |
| 180 | * tracking has to be handled by the "enclosing" metadata object. For |
| 181 | * example, for inodes, the inode is locked throughout the extent freeing |
| 182 | * so the dependency should be recorded there. |
| 183 | */ |
| 184 | STATIC void |
| 185 | xfs_rui_item_committing( |
| 186 | struct xfs_log_item *lip, |
| 187 | xfs_lsn_t lsn) |
| 188 | { |
| 189 | } |
| 190 | |
| 191 | /* |
| 192 | * This is the ops vector shared by all rui log items. |
| 193 | */ |
| 194 | static const struct xfs_item_ops xfs_rui_item_ops = { |
| 195 | .iop_size = xfs_rui_item_size, |
| 196 | .iop_format = xfs_rui_item_format, |
| 197 | .iop_pin = xfs_rui_item_pin, |
| 198 | .iop_unpin = xfs_rui_item_unpin, |
| 199 | .iop_unlock = xfs_rui_item_unlock, |
| 200 | .iop_committed = xfs_rui_item_committed, |
| 201 | .iop_push = xfs_rui_item_push, |
| 202 | .iop_committing = xfs_rui_item_committing, |
| 203 | }; |
| 204 | |
| 205 | /* |
| 206 | * Allocate and initialize an rui item with the given number of extents. |
| 207 | */ |
| 208 | struct xfs_rui_log_item * |
| 209 | xfs_rui_init( |
| 210 | struct xfs_mount *mp, |
| 211 | uint nextents) |
| 212 | |
| 213 | { |
| 214 | struct xfs_rui_log_item *ruip; |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 215 | |
| 216 | ASSERT(nextents > 0); |
Darrick J. Wong | cd00158 | 2016-09-19 10:24:27 +1000 | [diff] [blame] | 217 | if (nextents > XFS_RUI_MAX_FAST_EXTENTS) |
| 218 | ruip = kmem_zalloc(xfs_rui_log_item_sizeof(nextents), KM_SLEEP); |
| 219 | else |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 220 | ruip = kmem_zone_zalloc(xfs_rui_zone, KM_SLEEP); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 221 | |
| 222 | xfs_log_item_init(mp, &ruip->rui_item, XFS_LI_RUI, &xfs_rui_item_ops); |
| 223 | ruip->rui_format.rui_nextents = nextents; |
| 224 | ruip->rui_format.rui_id = (uintptr_t)(void *)ruip; |
| 225 | atomic_set(&ruip->rui_next_extent, 0); |
| 226 | atomic_set(&ruip->rui_refcount, 2); |
| 227 | |
| 228 | return ruip; |
| 229 | } |
| 230 | |
| 231 | /* |
| 232 | * Copy an RUI format buffer from the given buf, and into the destination |
| 233 | * RUI format structure. The RUI/RUD items were designed not to need any |
| 234 | * special alignment handling. |
| 235 | */ |
| 236 | int |
| 237 | xfs_rui_copy_format( |
| 238 | struct xfs_log_iovec *buf, |
| 239 | struct xfs_rui_log_format *dst_rui_fmt) |
| 240 | { |
| 241 | struct xfs_rui_log_format *src_rui_fmt; |
| 242 | uint len; |
| 243 | |
| 244 | src_rui_fmt = buf->i_addr; |
Darrick J. Wong | cd00158 | 2016-09-19 10:24:27 +1000 | [diff] [blame] | 245 | len = xfs_rui_log_format_sizeof(src_rui_fmt->rui_nextents); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 246 | |
| 247 | if (buf->i_len != len) |
| 248 | return -EFSCORRUPTED; |
| 249 | |
Darrick J. Wong | cd00158 | 2016-09-19 10:24:27 +1000 | [diff] [blame] | 250 | memcpy(dst_rui_fmt, src_rui_fmt, len); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 251 | return 0; |
| 252 | } |
| 253 | |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 254 | static inline struct xfs_rud_log_item *RUD_ITEM(struct xfs_log_item *lip) |
| 255 | { |
| 256 | return container_of(lip, struct xfs_rud_log_item, rud_item); |
| 257 | } |
| 258 | |
| 259 | STATIC void |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 260 | xfs_rud_item_size( |
| 261 | struct xfs_log_item *lip, |
| 262 | int *nvecs, |
| 263 | int *nbytes) |
| 264 | { |
| 265 | *nvecs += 1; |
Darrick J. Wong | 722e251 | 2016-08-03 12:28:43 +1000 | [diff] [blame] | 266 | *nbytes += sizeof(struct xfs_rud_log_format); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | /* |
| 270 | * This is called to fill in the vector of log iovecs for the |
| 271 | * given rud log item. We use only 1 iovec, and we point that |
| 272 | * at the rud_log_format structure embedded in the rud item. |
| 273 | * It is at this point that we assert that all of the extent |
| 274 | * slots in the rud item have been filled. |
| 275 | */ |
| 276 | STATIC void |
| 277 | xfs_rud_item_format( |
| 278 | struct xfs_log_item *lip, |
| 279 | struct xfs_log_vec *lv) |
| 280 | { |
| 281 | struct xfs_rud_log_item *rudp = RUD_ITEM(lip); |
| 282 | struct xfs_log_iovec *vecp = NULL; |
| 283 | |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 284 | rudp->rud_format.rud_type = XFS_LI_RUD; |
| 285 | rudp->rud_format.rud_size = 1; |
| 286 | |
| 287 | 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] | 288 | sizeof(struct xfs_rud_log_format)); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | /* |
| 292 | * Pinning has no meaning for an rud item, so just return. |
| 293 | */ |
| 294 | STATIC void |
| 295 | xfs_rud_item_pin( |
| 296 | struct xfs_log_item *lip) |
| 297 | { |
| 298 | } |
| 299 | |
| 300 | /* |
| 301 | * Since pinning has no meaning for an rud item, unpinning does |
| 302 | * not either. |
| 303 | */ |
| 304 | STATIC void |
| 305 | xfs_rud_item_unpin( |
| 306 | struct xfs_log_item *lip, |
| 307 | int remove) |
| 308 | { |
| 309 | } |
| 310 | |
| 311 | /* |
| 312 | * There isn't much you can do to push on an rud item. It is simply stuck |
| 313 | * waiting for the log to be flushed to disk. |
| 314 | */ |
| 315 | STATIC uint |
| 316 | xfs_rud_item_push( |
| 317 | struct xfs_log_item *lip, |
| 318 | struct list_head *buffer_list) |
| 319 | { |
| 320 | return XFS_ITEM_PINNED; |
| 321 | } |
| 322 | |
| 323 | /* |
| 324 | * The RUD is either committed or aborted if the transaction is cancelled. If |
| 325 | * the transaction is cancelled, drop our reference to the RUI and free the |
| 326 | * RUD. |
| 327 | */ |
| 328 | STATIC void |
| 329 | xfs_rud_item_unlock( |
| 330 | struct xfs_log_item *lip) |
| 331 | { |
| 332 | struct xfs_rud_log_item *rudp = RUD_ITEM(lip); |
| 333 | |
| 334 | if (lip->li_flags & XFS_LI_ABORTED) { |
| 335 | xfs_rui_release(rudp->rud_ruip); |
Darrick J. Wong | 722e251 | 2016-08-03 12:28:43 +1000 | [diff] [blame] | 336 | kmem_zone_free(xfs_rud_zone, rudp); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 337 | } |
| 338 | } |
| 339 | |
| 340 | /* |
| 341 | * When the rud item is committed to disk, all we need to do is delete our |
| 342 | * reference to our partner rui item and then free ourselves. Since we're |
| 343 | * freeing ourselves we must return -1 to keep the transaction code from |
| 344 | * further referencing this item. |
| 345 | */ |
| 346 | STATIC xfs_lsn_t |
| 347 | xfs_rud_item_committed( |
| 348 | struct xfs_log_item *lip, |
| 349 | xfs_lsn_t lsn) |
| 350 | { |
| 351 | struct xfs_rud_log_item *rudp = RUD_ITEM(lip); |
| 352 | |
| 353 | /* |
| 354 | * Drop the RUI reference regardless of whether the RUD has been |
| 355 | * aborted. Once the RUD transaction is constructed, it is the sole |
| 356 | * responsibility of the RUD to release the RUI (even if the RUI is |
| 357 | * aborted due to log I/O error). |
| 358 | */ |
| 359 | xfs_rui_release(rudp->rud_ruip); |
Darrick J. Wong | 722e251 | 2016-08-03 12:28:43 +1000 | [diff] [blame] | 360 | kmem_zone_free(xfs_rud_zone, rudp); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 361 | |
| 362 | return (xfs_lsn_t)-1; |
| 363 | } |
| 364 | |
| 365 | /* |
| 366 | * The RUD dependency tracking op doesn't do squat. It can't because |
| 367 | * it doesn't know where the free extent is coming from. The dependency |
| 368 | * tracking has to be handled by the "enclosing" metadata object. For |
| 369 | * example, for inodes, the inode is locked throughout the extent freeing |
| 370 | * so the dependency should be recorded there. |
| 371 | */ |
| 372 | STATIC void |
| 373 | xfs_rud_item_committing( |
| 374 | struct xfs_log_item *lip, |
| 375 | xfs_lsn_t lsn) |
| 376 | { |
| 377 | } |
| 378 | |
| 379 | /* |
| 380 | * This is the ops vector shared by all rud log items. |
| 381 | */ |
| 382 | static const struct xfs_item_ops xfs_rud_item_ops = { |
| 383 | .iop_size = xfs_rud_item_size, |
| 384 | .iop_format = xfs_rud_item_format, |
| 385 | .iop_pin = xfs_rud_item_pin, |
| 386 | .iop_unpin = xfs_rud_item_unpin, |
| 387 | .iop_unlock = xfs_rud_item_unlock, |
| 388 | .iop_committed = xfs_rud_item_committed, |
| 389 | .iop_push = xfs_rud_item_push, |
| 390 | .iop_committing = xfs_rud_item_committing, |
| 391 | }; |
| 392 | |
| 393 | /* |
| 394 | * Allocate and initialize an rud item with the given number of extents. |
| 395 | */ |
| 396 | struct xfs_rud_log_item * |
| 397 | xfs_rud_init( |
| 398 | struct xfs_mount *mp, |
Darrick J. Wong | 722e251 | 2016-08-03 12:28:43 +1000 | [diff] [blame] | 399 | struct xfs_rui_log_item *ruip) |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 400 | |
| 401 | { |
| 402 | struct xfs_rud_log_item *rudp; |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 403 | |
Darrick J. Wong | 722e251 | 2016-08-03 12:28:43 +1000 | [diff] [blame] | 404 | rudp = kmem_zone_zalloc(xfs_rud_zone, KM_SLEEP); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 405 | xfs_log_item_init(mp, &rudp->rud_item, XFS_LI_RUD, &xfs_rud_item_ops); |
| 406 | rudp->rud_ruip = ruip; |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 407 | rudp->rud_format.rud_rui_id = ruip->rui_format.rui_id; |
| 408 | |
| 409 | return rudp; |
| 410 | } |
Darrick J. Wong | 9e88b5d | 2016-08-03 12:09:48 +1000 | [diff] [blame] | 411 | |
| 412 | /* |
| 413 | * Process an rmap update intent item that was recovered from the log. |
| 414 | * We need to update the rmapbt. |
| 415 | */ |
| 416 | int |
| 417 | xfs_rui_recover( |
| 418 | struct xfs_mount *mp, |
| 419 | struct xfs_rui_log_item *ruip) |
| 420 | { |
| 421 | int i; |
| 422 | int error = 0; |
| 423 | struct xfs_map_extent *rmap; |
| 424 | xfs_fsblock_t startblock_fsb; |
| 425 | bool op_ok; |
Darrick J. Wong | 9c19464 | 2016-08-03 12:16:05 +1000 | [diff] [blame] | 426 | struct xfs_rud_log_item *rudp; |
| 427 | enum xfs_rmap_intent_type type; |
| 428 | int whichfork; |
| 429 | xfs_exntst_t state; |
| 430 | struct xfs_trans *tp; |
| 431 | struct xfs_btree_cur *rcur = NULL; |
Darrick J. Wong | 9e88b5d | 2016-08-03 12:09:48 +1000 | [diff] [blame] | 432 | |
| 433 | ASSERT(!test_bit(XFS_RUI_RECOVERED, &ruip->rui_flags)); |
| 434 | |
| 435 | /* |
| 436 | * First check the validity of the extents described by the |
| 437 | * RUI. If any are bad, then assume that all are bad and |
| 438 | * just toss the RUI. |
| 439 | */ |
| 440 | for (i = 0; i < ruip->rui_format.rui_nextents; i++) { |
Darrick J. Wong | e127faf | 2016-08-03 12:29:32 +1000 | [diff] [blame] | 441 | rmap = &ruip->rui_format.rui_extents[i]; |
Darrick J. Wong | 9e88b5d | 2016-08-03 12:09:48 +1000 | [diff] [blame] | 442 | startblock_fsb = XFS_BB_TO_FSB(mp, |
| 443 | XFS_FSB_TO_DADDR(mp, rmap->me_startblock)); |
| 444 | switch (rmap->me_flags & XFS_RMAP_EXTENT_TYPE_MASK) { |
| 445 | case XFS_RMAP_EXTENT_MAP: |
Darrick J. Wong | 0e07c03 | 2016-10-03 09:11:47 -0700 | [diff] [blame] | 446 | case XFS_RMAP_EXTENT_MAP_SHARED: |
Darrick J. Wong | 9e88b5d | 2016-08-03 12:09:48 +1000 | [diff] [blame] | 447 | case XFS_RMAP_EXTENT_UNMAP: |
Darrick J. Wong | 0e07c03 | 2016-10-03 09:11:47 -0700 | [diff] [blame] | 448 | case XFS_RMAP_EXTENT_UNMAP_SHARED: |
Darrick J. Wong | 9e88b5d | 2016-08-03 12:09:48 +1000 | [diff] [blame] | 449 | case XFS_RMAP_EXTENT_CONVERT: |
Darrick J. Wong | 0e07c03 | 2016-10-03 09:11:47 -0700 | [diff] [blame] | 450 | case XFS_RMAP_EXTENT_CONVERT_SHARED: |
Darrick J. Wong | 9e88b5d | 2016-08-03 12:09:48 +1000 | [diff] [blame] | 451 | case XFS_RMAP_EXTENT_ALLOC: |
| 452 | case XFS_RMAP_EXTENT_FREE: |
| 453 | op_ok = true; |
| 454 | break; |
| 455 | default: |
| 456 | op_ok = false; |
| 457 | break; |
| 458 | } |
Darrick J. Wong | e127faf | 2016-08-03 12:29:32 +1000 | [diff] [blame] | 459 | if (!op_ok || startblock_fsb == 0 || |
| 460 | rmap->me_len == 0 || |
| 461 | startblock_fsb >= mp->m_sb.sb_dblocks || |
| 462 | rmap->me_len >= mp->m_sb.sb_agblocks || |
Darrick J. Wong | 9e88b5d | 2016-08-03 12:09:48 +1000 | [diff] [blame] | 463 | (rmap->me_flags & ~XFS_RMAP_EXTENT_FLAGS)) { |
| 464 | /* |
| 465 | * This will pull the RUI from the AIL and |
| 466 | * free the memory associated with it. |
| 467 | */ |
| 468 | set_bit(XFS_RUI_RECOVERED, &ruip->rui_flags); |
| 469 | xfs_rui_release(ruip); |
| 470 | return -EIO; |
| 471 | } |
| 472 | } |
| 473 | |
Darrick J. Wong | b31c2bd | 2018-02-22 14:41:25 -0800 | [diff] [blame] | 474 | error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, |
| 475 | mp->m_rmap_maxlevels, 0, XFS_TRANS_RESERVE, &tp); |
Darrick J. Wong | 9c19464 | 2016-08-03 12:16:05 +1000 | [diff] [blame] | 476 | if (error) |
| 477 | return error; |
Darrick J. Wong | 722e251 | 2016-08-03 12:28:43 +1000 | [diff] [blame] | 478 | rudp = xfs_trans_get_rud(tp, ruip); |
Darrick J. Wong | 9c19464 | 2016-08-03 12:16:05 +1000 | [diff] [blame] | 479 | |
| 480 | for (i = 0; i < ruip->rui_format.rui_nextents; i++) { |
Darrick J. Wong | e127faf | 2016-08-03 12:29:32 +1000 | [diff] [blame] | 481 | rmap = &ruip->rui_format.rui_extents[i]; |
Darrick J. Wong | 9c19464 | 2016-08-03 12:16:05 +1000 | [diff] [blame] | 482 | state = (rmap->me_flags & XFS_RMAP_EXTENT_UNWRITTEN) ? |
| 483 | XFS_EXT_UNWRITTEN : XFS_EXT_NORM; |
| 484 | whichfork = (rmap->me_flags & XFS_RMAP_EXTENT_ATTR_FORK) ? |
| 485 | XFS_ATTR_FORK : XFS_DATA_FORK; |
| 486 | switch (rmap->me_flags & XFS_RMAP_EXTENT_TYPE_MASK) { |
| 487 | case XFS_RMAP_EXTENT_MAP: |
| 488 | type = XFS_RMAP_MAP; |
| 489 | break; |
Darrick J. Wong | ceeb9c8 | 2016-10-03 09:11:48 -0700 | [diff] [blame] | 490 | case XFS_RMAP_EXTENT_MAP_SHARED: |
| 491 | type = XFS_RMAP_MAP_SHARED; |
| 492 | break; |
Darrick J. Wong | 9c19464 | 2016-08-03 12:16:05 +1000 | [diff] [blame] | 493 | case XFS_RMAP_EXTENT_UNMAP: |
| 494 | type = XFS_RMAP_UNMAP; |
| 495 | break; |
Darrick J. Wong | ceeb9c8 | 2016-10-03 09:11:48 -0700 | [diff] [blame] | 496 | case XFS_RMAP_EXTENT_UNMAP_SHARED: |
| 497 | type = XFS_RMAP_UNMAP_SHARED; |
| 498 | break; |
Darrick J. Wong | 9c19464 | 2016-08-03 12:16:05 +1000 | [diff] [blame] | 499 | case XFS_RMAP_EXTENT_CONVERT: |
| 500 | type = XFS_RMAP_CONVERT; |
| 501 | break; |
Darrick J. Wong | 3f165b3 | 2016-10-03 09:11:48 -0700 | [diff] [blame] | 502 | case XFS_RMAP_EXTENT_CONVERT_SHARED: |
| 503 | type = XFS_RMAP_CONVERT_SHARED; |
| 504 | break; |
Darrick J. Wong | 9c19464 | 2016-08-03 12:16:05 +1000 | [diff] [blame] | 505 | case XFS_RMAP_EXTENT_ALLOC: |
| 506 | type = XFS_RMAP_ALLOC; |
| 507 | break; |
| 508 | case XFS_RMAP_EXTENT_FREE: |
| 509 | type = XFS_RMAP_FREE; |
| 510 | break; |
| 511 | default: |
| 512 | error = -EFSCORRUPTED; |
| 513 | goto abort_error; |
| 514 | } |
| 515 | error = xfs_trans_log_finish_rmap_update(tp, rudp, type, |
| 516 | rmap->me_owner, whichfork, |
| 517 | rmap->me_startoff, rmap->me_startblock, |
| 518 | rmap->me_len, state, &rcur); |
| 519 | if (error) |
| 520 | goto abort_error; |
| 521 | |
| 522 | } |
| 523 | |
| 524 | xfs_rmap_finish_one_cleanup(tp, rcur, error); |
Darrick J. Wong | 9e88b5d | 2016-08-03 12:09:48 +1000 | [diff] [blame] | 525 | set_bit(XFS_RUI_RECOVERED, &ruip->rui_flags); |
Darrick J. Wong | 9c19464 | 2016-08-03 12:16:05 +1000 | [diff] [blame] | 526 | error = xfs_trans_commit(tp); |
| 527 | return error; |
| 528 | |
| 529 | abort_error: |
| 530 | xfs_rmap_finish_one_cleanup(tp, rcur, error); |
| 531 | xfs_trans_cancel(tp); |
Darrick J. Wong | 9e88b5d | 2016-08-03 12:09:48 +1000 | [diff] [blame] | 532 | return error; |
| 533 | } |