| .. | .. |
|---|
| 14 | 14 | #include "xfs_defer.h" |
|---|
| 15 | 15 | #include "xfs_trans.h" |
|---|
| 16 | 16 | #include "xfs_trans_priv.h" |
|---|
| 17 | | -#include "xfs_buf_item.h" |
|---|
| 18 | 17 | #include "xfs_rmap_item.h" |
|---|
| 19 | 18 | #include "xfs_log.h" |
|---|
| 20 | 19 | #include "xfs_rmap.h" |
|---|
| 21 | | - |
|---|
| 20 | +#include "xfs_error.h" |
|---|
| 21 | +#include "xfs_log_priv.h" |
|---|
| 22 | +#include "xfs_log_recover.h" |
|---|
| 22 | 23 | |
|---|
| 23 | 24 | kmem_zone_t *xfs_rui_zone; |
|---|
| 24 | 25 | kmem_zone_t *xfs_rud_zone; |
|---|
| 26 | + |
|---|
| 27 | +static const struct xfs_item_ops xfs_rui_item_ops; |
|---|
| 25 | 28 | |
|---|
| 26 | 29 | static inline struct xfs_rui_log_item *RUI_ITEM(struct xfs_log_item *lip) |
|---|
| 27 | 30 | { |
|---|
| 28 | 31 | return container_of(lip, struct xfs_rui_log_item, rui_item); |
|---|
| 29 | 32 | } |
|---|
| 30 | 33 | |
|---|
| 31 | | -void |
|---|
| 34 | +STATIC void |
|---|
| 32 | 35 | xfs_rui_item_free( |
|---|
| 33 | 36 | struct xfs_rui_log_item *ruip) |
|---|
| 34 | 37 | { |
|---|
| 35 | 38 | if (ruip->rui_format.rui_nextents > XFS_RUI_MAX_FAST_EXTENTS) |
|---|
| 36 | 39 | kmem_free(ruip); |
|---|
| 37 | 40 | else |
|---|
| 38 | | - kmem_zone_free(xfs_rui_zone, ruip); |
|---|
| 41 | + kmem_cache_free(xfs_rui_zone, ruip); |
|---|
| 39 | 42 | } |
|---|
| 40 | 43 | |
|---|
| 41 | 44 | /* |
|---|
| .. | .. |
|---|
| 45 | 48 | * committed vs unpin operations in bulk insert operations. Hence the reference |
|---|
| 46 | 49 | * count to ensure only the last caller frees the RUI. |
|---|
| 47 | 50 | */ |
|---|
| 48 | | -void |
|---|
| 51 | +STATIC void |
|---|
| 49 | 52 | xfs_rui_release( |
|---|
| 50 | 53 | struct xfs_rui_log_item *ruip) |
|---|
| 51 | 54 | { |
|---|
| 52 | 55 | ASSERT(atomic_read(&ruip->rui_refcount) > 0); |
|---|
| 53 | 56 | if (atomic_dec_and_test(&ruip->rui_refcount)) { |
|---|
| 54 | | - xfs_trans_ail_remove(&ruip->rui_item, SHUTDOWN_LOG_IO_ERROR); |
|---|
| 57 | + xfs_trans_ail_delete(&ruip->rui_item, SHUTDOWN_LOG_IO_ERROR); |
|---|
| 55 | 58 | xfs_rui_item_free(ruip); |
|---|
| 56 | 59 | } |
|---|
| 57 | 60 | } |
|---|
| .. | .. |
|---|
| 94 | 97 | } |
|---|
| 95 | 98 | |
|---|
| 96 | 99 | /* |
|---|
| 97 | | - * Pinning has no meaning for an rui item, so just return. |
|---|
| 98 | | - */ |
|---|
| 99 | | -STATIC void |
|---|
| 100 | | -xfs_rui_item_pin( |
|---|
| 101 | | - struct xfs_log_item *lip) |
|---|
| 102 | | -{ |
|---|
| 103 | | -} |
|---|
| 104 | | - |
|---|
| 105 | | -/* |
|---|
| 106 | 100 | * The unpin operation is the last place an RUI is manipulated in the log. It is |
|---|
| 107 | 101 | * either inserted in the AIL or aborted in the event of a log I/O error. In |
|---|
| 108 | 102 | * either case, the RUI transaction has been successfully committed to make it |
|---|
| .. | .. |
|---|
| 121 | 115 | } |
|---|
| 122 | 116 | |
|---|
| 123 | 117 | /* |
|---|
| 124 | | - * RUI items have no locking or pushing. However, since RUIs are pulled from |
|---|
| 125 | | - * the AIL when their corresponding RUDs are committed to disk, their situation |
|---|
| 126 | | - * is very similar to being pinned. Return XFS_ITEM_PINNED so that the caller |
|---|
| 127 | | - * will eventually flush the log. This should help in getting the RUI out of |
|---|
| 128 | | - * the AIL. |
|---|
| 129 | | - */ |
|---|
| 130 | | -STATIC uint |
|---|
| 131 | | -xfs_rui_item_push( |
|---|
| 132 | | - struct xfs_log_item *lip, |
|---|
| 133 | | - struct list_head *buffer_list) |
|---|
| 134 | | -{ |
|---|
| 135 | | - return XFS_ITEM_PINNED; |
|---|
| 136 | | -} |
|---|
| 137 | | - |
|---|
| 138 | | -/* |
|---|
| 139 | 118 | * The RUI has been either committed or aborted if the transaction has been |
|---|
| 140 | 119 | * cancelled. If the transaction was cancelled, an RUD isn't going to be |
|---|
| 141 | 120 | * constructed and thus we free the RUI here directly. |
|---|
| 142 | 121 | */ |
|---|
| 143 | 122 | STATIC void |
|---|
| 144 | | -xfs_rui_item_unlock( |
|---|
| 123 | +xfs_rui_item_release( |
|---|
| 145 | 124 | struct xfs_log_item *lip) |
|---|
| 146 | 125 | { |
|---|
| 147 | | - if (test_bit(XFS_LI_ABORTED, &lip->li_flags)) |
|---|
| 148 | | - xfs_rui_release(RUI_ITEM(lip)); |
|---|
| 126 | + xfs_rui_release(RUI_ITEM(lip)); |
|---|
| 149 | 127 | } |
|---|
| 150 | | - |
|---|
| 151 | | -/* |
|---|
| 152 | | - * The RUI is logged only once and cannot be moved in the log, so simply return |
|---|
| 153 | | - * the lsn at which it's been logged. |
|---|
| 154 | | - */ |
|---|
| 155 | | -STATIC xfs_lsn_t |
|---|
| 156 | | -xfs_rui_item_committed( |
|---|
| 157 | | - struct xfs_log_item *lip, |
|---|
| 158 | | - xfs_lsn_t lsn) |
|---|
| 159 | | -{ |
|---|
| 160 | | - return lsn; |
|---|
| 161 | | -} |
|---|
| 162 | | - |
|---|
| 163 | | -/* |
|---|
| 164 | | - * The RUI dependency tracking op doesn't do squat. It can't because |
|---|
| 165 | | - * it doesn't know where the free extent is coming from. The dependency |
|---|
| 166 | | - * tracking has to be handled by the "enclosing" metadata object. For |
|---|
| 167 | | - * example, for inodes, the inode is locked throughout the extent freeing |
|---|
| 168 | | - * so the dependency should be recorded there. |
|---|
| 169 | | - */ |
|---|
| 170 | | -STATIC void |
|---|
| 171 | | -xfs_rui_item_committing( |
|---|
| 172 | | - struct xfs_log_item *lip, |
|---|
| 173 | | - xfs_lsn_t lsn) |
|---|
| 174 | | -{ |
|---|
| 175 | | -} |
|---|
| 176 | | - |
|---|
| 177 | | -/* |
|---|
| 178 | | - * This is the ops vector shared by all rui log items. |
|---|
| 179 | | - */ |
|---|
| 180 | | -static const struct xfs_item_ops xfs_rui_item_ops = { |
|---|
| 181 | | - .iop_size = xfs_rui_item_size, |
|---|
| 182 | | - .iop_format = xfs_rui_item_format, |
|---|
| 183 | | - .iop_pin = xfs_rui_item_pin, |
|---|
| 184 | | - .iop_unpin = xfs_rui_item_unpin, |
|---|
| 185 | | - .iop_unlock = xfs_rui_item_unlock, |
|---|
| 186 | | - .iop_committed = xfs_rui_item_committed, |
|---|
| 187 | | - .iop_push = xfs_rui_item_push, |
|---|
| 188 | | - .iop_committing = xfs_rui_item_committing, |
|---|
| 189 | | -}; |
|---|
| 190 | 128 | |
|---|
| 191 | 129 | /* |
|---|
| 192 | 130 | * Allocate and initialize an rui item with the given number of extents. |
|---|
| 193 | 131 | */ |
|---|
| 194 | | -struct xfs_rui_log_item * |
|---|
| 132 | +STATIC struct xfs_rui_log_item * |
|---|
| 195 | 133 | xfs_rui_init( |
|---|
| 196 | 134 | struct xfs_mount *mp, |
|---|
| 197 | 135 | uint nextents) |
|---|
| .. | .. |
|---|
| 201 | 139 | |
|---|
| 202 | 140 | ASSERT(nextents > 0); |
|---|
| 203 | 141 | if (nextents > XFS_RUI_MAX_FAST_EXTENTS) |
|---|
| 204 | | - ruip = kmem_zalloc(xfs_rui_log_item_sizeof(nextents), KM_SLEEP); |
|---|
| 142 | + ruip = kmem_zalloc(xfs_rui_log_item_sizeof(nextents), 0); |
|---|
| 205 | 143 | else |
|---|
| 206 | | - ruip = kmem_zone_zalloc(xfs_rui_zone, KM_SLEEP); |
|---|
| 144 | + ruip = kmem_cache_zalloc(xfs_rui_zone, |
|---|
| 145 | + GFP_KERNEL | __GFP_NOFAIL); |
|---|
| 207 | 146 | |
|---|
| 208 | 147 | xfs_log_item_init(mp, &ruip->rui_item, XFS_LI_RUI, &xfs_rui_item_ops); |
|---|
| 209 | 148 | ruip->rui_format.rui_nextents = nextents; |
|---|
| .. | .. |
|---|
| 219 | 158 | * RUI format structure. The RUI/RUD items were designed not to need any |
|---|
| 220 | 159 | * special alignment handling. |
|---|
| 221 | 160 | */ |
|---|
| 222 | | -int |
|---|
| 161 | +STATIC int |
|---|
| 223 | 162 | xfs_rui_copy_format( |
|---|
| 224 | 163 | struct xfs_log_iovec *buf, |
|---|
| 225 | 164 | struct xfs_rui_log_format *dst_rui_fmt) |
|---|
| .. | .. |
|---|
| 230 | 169 | src_rui_fmt = buf->i_addr; |
|---|
| 231 | 170 | len = xfs_rui_log_format_sizeof(src_rui_fmt->rui_nextents); |
|---|
| 232 | 171 | |
|---|
| 233 | | - if (buf->i_len != len) |
|---|
| 172 | + if (buf->i_len != len) { |
|---|
| 173 | + XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, NULL); |
|---|
| 234 | 174 | return -EFSCORRUPTED; |
|---|
| 175 | + } |
|---|
| 235 | 176 | |
|---|
| 236 | 177 | memcpy(dst_rui_fmt, src_rui_fmt, len); |
|---|
| 237 | 178 | return 0; |
|---|
| .. | .. |
|---|
| 275 | 216 | } |
|---|
| 276 | 217 | |
|---|
| 277 | 218 | /* |
|---|
| 278 | | - * Pinning has no meaning for an rud item, so just return. |
|---|
| 279 | | - */ |
|---|
| 280 | | -STATIC void |
|---|
| 281 | | -xfs_rud_item_pin( |
|---|
| 282 | | - struct xfs_log_item *lip) |
|---|
| 283 | | -{ |
|---|
| 284 | | -} |
|---|
| 285 | | - |
|---|
| 286 | | -/* |
|---|
| 287 | | - * Since pinning has no meaning for an rud item, unpinning does |
|---|
| 288 | | - * not either. |
|---|
| 289 | | - */ |
|---|
| 290 | | -STATIC void |
|---|
| 291 | | -xfs_rud_item_unpin( |
|---|
| 292 | | - struct xfs_log_item *lip, |
|---|
| 293 | | - int remove) |
|---|
| 294 | | -{ |
|---|
| 295 | | -} |
|---|
| 296 | | - |
|---|
| 297 | | -/* |
|---|
| 298 | | - * There isn't much you can do to push on an rud item. It is simply stuck |
|---|
| 299 | | - * waiting for the log to be flushed to disk. |
|---|
| 300 | | - */ |
|---|
| 301 | | -STATIC uint |
|---|
| 302 | | -xfs_rud_item_push( |
|---|
| 303 | | - struct xfs_log_item *lip, |
|---|
| 304 | | - struct list_head *buffer_list) |
|---|
| 305 | | -{ |
|---|
| 306 | | - return XFS_ITEM_PINNED; |
|---|
| 307 | | -} |
|---|
| 308 | | - |
|---|
| 309 | | -/* |
|---|
| 310 | 219 | * The RUD is either committed or aborted if the transaction is cancelled. If |
|---|
| 311 | 220 | * the transaction is cancelled, drop our reference to the RUI and free the |
|---|
| 312 | 221 | * RUD. |
|---|
| 313 | 222 | */ |
|---|
| 314 | 223 | STATIC void |
|---|
| 315 | | -xfs_rud_item_unlock( |
|---|
| 224 | +xfs_rud_item_release( |
|---|
| 316 | 225 | struct xfs_log_item *lip) |
|---|
| 317 | 226 | { |
|---|
| 318 | 227 | struct xfs_rud_log_item *rudp = RUD_ITEM(lip); |
|---|
| 319 | 228 | |
|---|
| 320 | | - if (test_bit(XFS_LI_ABORTED, &lip->li_flags)) { |
|---|
| 321 | | - xfs_rui_release(rudp->rud_ruip); |
|---|
| 322 | | - kmem_zone_free(xfs_rud_zone, rudp); |
|---|
| 229 | + xfs_rui_release(rudp->rud_ruip); |
|---|
| 230 | + kmem_cache_free(xfs_rud_zone, rudp); |
|---|
| 231 | +} |
|---|
| 232 | + |
|---|
| 233 | +static const struct xfs_item_ops xfs_rud_item_ops = { |
|---|
| 234 | + .flags = XFS_ITEM_RELEASE_WHEN_COMMITTED, |
|---|
| 235 | + .iop_size = xfs_rud_item_size, |
|---|
| 236 | + .iop_format = xfs_rud_item_format, |
|---|
| 237 | + .iop_release = xfs_rud_item_release, |
|---|
| 238 | +}; |
|---|
| 239 | + |
|---|
| 240 | +static struct xfs_rud_log_item * |
|---|
| 241 | +xfs_trans_get_rud( |
|---|
| 242 | + struct xfs_trans *tp, |
|---|
| 243 | + struct xfs_rui_log_item *ruip) |
|---|
| 244 | +{ |
|---|
| 245 | + struct xfs_rud_log_item *rudp; |
|---|
| 246 | + |
|---|
| 247 | + rudp = kmem_cache_zalloc(xfs_rud_zone, GFP_KERNEL | __GFP_NOFAIL); |
|---|
| 248 | + xfs_log_item_init(tp->t_mountp, &rudp->rud_item, XFS_LI_RUD, |
|---|
| 249 | + &xfs_rud_item_ops); |
|---|
| 250 | + rudp->rud_ruip = ruip; |
|---|
| 251 | + rudp->rud_format.rud_rui_id = ruip->rui_format.rui_id; |
|---|
| 252 | + |
|---|
| 253 | + xfs_trans_add_item(tp, &rudp->rud_item); |
|---|
| 254 | + return rudp; |
|---|
| 255 | +} |
|---|
| 256 | + |
|---|
| 257 | +/* Set the map extent flags for this reverse mapping. */ |
|---|
| 258 | +static void |
|---|
| 259 | +xfs_trans_set_rmap_flags( |
|---|
| 260 | + struct xfs_map_extent *rmap, |
|---|
| 261 | + enum xfs_rmap_intent_type type, |
|---|
| 262 | + int whichfork, |
|---|
| 263 | + xfs_exntst_t state) |
|---|
| 264 | +{ |
|---|
| 265 | + rmap->me_flags = 0; |
|---|
| 266 | + if (state == XFS_EXT_UNWRITTEN) |
|---|
| 267 | + rmap->me_flags |= XFS_RMAP_EXTENT_UNWRITTEN; |
|---|
| 268 | + if (whichfork == XFS_ATTR_FORK) |
|---|
| 269 | + rmap->me_flags |= XFS_RMAP_EXTENT_ATTR_FORK; |
|---|
| 270 | + switch (type) { |
|---|
| 271 | + case XFS_RMAP_MAP: |
|---|
| 272 | + rmap->me_flags |= XFS_RMAP_EXTENT_MAP; |
|---|
| 273 | + break; |
|---|
| 274 | + case XFS_RMAP_MAP_SHARED: |
|---|
| 275 | + rmap->me_flags |= XFS_RMAP_EXTENT_MAP_SHARED; |
|---|
| 276 | + break; |
|---|
| 277 | + case XFS_RMAP_UNMAP: |
|---|
| 278 | + rmap->me_flags |= XFS_RMAP_EXTENT_UNMAP; |
|---|
| 279 | + break; |
|---|
| 280 | + case XFS_RMAP_UNMAP_SHARED: |
|---|
| 281 | + rmap->me_flags |= XFS_RMAP_EXTENT_UNMAP_SHARED; |
|---|
| 282 | + break; |
|---|
| 283 | + case XFS_RMAP_CONVERT: |
|---|
| 284 | + rmap->me_flags |= XFS_RMAP_EXTENT_CONVERT; |
|---|
| 285 | + break; |
|---|
| 286 | + case XFS_RMAP_CONVERT_SHARED: |
|---|
| 287 | + rmap->me_flags |= XFS_RMAP_EXTENT_CONVERT_SHARED; |
|---|
| 288 | + break; |
|---|
| 289 | + case XFS_RMAP_ALLOC: |
|---|
| 290 | + rmap->me_flags |= XFS_RMAP_EXTENT_ALLOC; |
|---|
| 291 | + break; |
|---|
| 292 | + case XFS_RMAP_FREE: |
|---|
| 293 | + rmap->me_flags |= XFS_RMAP_EXTENT_FREE; |
|---|
| 294 | + break; |
|---|
| 295 | + default: |
|---|
| 296 | + ASSERT(0); |
|---|
| 323 | 297 | } |
|---|
| 324 | 298 | } |
|---|
| 325 | 299 | |
|---|
| 326 | 300 | /* |
|---|
| 327 | | - * When the rud item is committed to disk, all we need to do is delete our |
|---|
| 328 | | - * reference to our partner rui item and then free ourselves. Since we're |
|---|
| 329 | | - * freeing ourselves we must return -1 to keep the transaction code from |
|---|
| 330 | | - * further referencing this item. |
|---|
| 301 | + * Finish an rmap update and log it to the RUD. Note that the transaction is |
|---|
| 302 | + * marked dirty regardless of whether the rmap update succeeds or fails to |
|---|
| 303 | + * support the RUI/RUD lifecycle rules. |
|---|
| 331 | 304 | */ |
|---|
| 332 | | -STATIC xfs_lsn_t |
|---|
| 333 | | -xfs_rud_item_committed( |
|---|
| 334 | | - struct xfs_log_item *lip, |
|---|
| 335 | | - xfs_lsn_t lsn) |
|---|
| 305 | +static int |
|---|
| 306 | +xfs_trans_log_finish_rmap_update( |
|---|
| 307 | + struct xfs_trans *tp, |
|---|
| 308 | + struct xfs_rud_log_item *rudp, |
|---|
| 309 | + enum xfs_rmap_intent_type type, |
|---|
| 310 | + uint64_t owner, |
|---|
| 311 | + int whichfork, |
|---|
| 312 | + xfs_fileoff_t startoff, |
|---|
| 313 | + xfs_fsblock_t startblock, |
|---|
| 314 | + xfs_filblks_t blockcount, |
|---|
| 315 | + xfs_exntst_t state, |
|---|
| 316 | + struct xfs_btree_cur **pcur) |
|---|
| 336 | 317 | { |
|---|
| 337 | | - struct xfs_rud_log_item *rudp = RUD_ITEM(lip); |
|---|
| 318 | + int error; |
|---|
| 319 | + |
|---|
| 320 | + error = xfs_rmap_finish_one(tp, type, owner, whichfork, startoff, |
|---|
| 321 | + startblock, blockcount, state, pcur); |
|---|
| 338 | 322 | |
|---|
| 339 | 323 | /* |
|---|
| 340 | | - * Drop the RUI reference regardless of whether the RUD has been |
|---|
| 341 | | - * aborted. Once the RUD transaction is constructed, it is the sole |
|---|
| 342 | | - * responsibility of the RUD to release the RUI (even if the RUI is |
|---|
| 343 | | - * aborted due to log I/O error). |
|---|
| 324 | + * Mark the transaction dirty, even on error. This ensures the |
|---|
| 325 | + * transaction is aborted, which: |
|---|
| 326 | + * |
|---|
| 327 | + * 1.) releases the RUI and frees the RUD |
|---|
| 328 | + * 2.) shuts down the filesystem |
|---|
| 344 | 329 | */ |
|---|
| 345 | | - xfs_rui_release(rudp->rud_ruip); |
|---|
| 346 | | - kmem_zone_free(xfs_rud_zone, rudp); |
|---|
| 330 | + tp->t_flags |= XFS_TRANS_DIRTY; |
|---|
| 331 | + set_bit(XFS_LI_DIRTY, &rudp->rud_item.li_flags); |
|---|
| 347 | 332 | |
|---|
| 348 | | - return (xfs_lsn_t)-1; |
|---|
| 333 | + return error; |
|---|
| 349 | 334 | } |
|---|
| 350 | 335 | |
|---|
| 351 | | -/* |
|---|
| 352 | | - * The RUD dependency tracking op doesn't do squat. It can't because |
|---|
| 353 | | - * it doesn't know where the free extent is coming from. The dependency |
|---|
| 354 | | - * tracking has to be handled by the "enclosing" metadata object. For |
|---|
| 355 | | - * example, for inodes, the inode is locked throughout the extent freeing |
|---|
| 356 | | - * so the dependency should be recorded there. |
|---|
| 357 | | - */ |
|---|
| 336 | +/* Sort rmap intents by AG. */ |
|---|
| 337 | +static int |
|---|
| 338 | +xfs_rmap_update_diff_items( |
|---|
| 339 | + void *priv, |
|---|
| 340 | + struct list_head *a, |
|---|
| 341 | + struct list_head *b) |
|---|
| 342 | +{ |
|---|
| 343 | + struct xfs_mount *mp = priv; |
|---|
| 344 | + struct xfs_rmap_intent *ra; |
|---|
| 345 | + struct xfs_rmap_intent *rb; |
|---|
| 346 | + |
|---|
| 347 | + ra = container_of(a, struct xfs_rmap_intent, ri_list); |
|---|
| 348 | + rb = container_of(b, struct xfs_rmap_intent, ri_list); |
|---|
| 349 | + return XFS_FSB_TO_AGNO(mp, ra->ri_bmap.br_startblock) - |
|---|
| 350 | + XFS_FSB_TO_AGNO(mp, rb->ri_bmap.br_startblock); |
|---|
| 351 | +} |
|---|
| 352 | + |
|---|
| 353 | +/* Log rmap updates in the intent item. */ |
|---|
| 358 | 354 | STATIC void |
|---|
| 359 | | -xfs_rud_item_committing( |
|---|
| 360 | | - struct xfs_log_item *lip, |
|---|
| 361 | | - xfs_lsn_t lsn) |
|---|
| 355 | +xfs_rmap_update_log_item( |
|---|
| 356 | + struct xfs_trans *tp, |
|---|
| 357 | + struct xfs_rui_log_item *ruip, |
|---|
| 358 | + struct xfs_rmap_intent *rmap) |
|---|
| 362 | 359 | { |
|---|
| 360 | + uint next_extent; |
|---|
| 361 | + struct xfs_map_extent *map; |
|---|
| 362 | + |
|---|
| 363 | + tp->t_flags |= XFS_TRANS_DIRTY; |
|---|
| 364 | + set_bit(XFS_LI_DIRTY, &ruip->rui_item.li_flags); |
|---|
| 365 | + |
|---|
| 366 | + /* |
|---|
| 367 | + * atomic_inc_return gives us the value after the increment; |
|---|
| 368 | + * we want to use it as an array index so we need to subtract 1 from |
|---|
| 369 | + * it. |
|---|
| 370 | + */ |
|---|
| 371 | + next_extent = atomic_inc_return(&ruip->rui_next_extent) - 1; |
|---|
| 372 | + ASSERT(next_extent < ruip->rui_format.rui_nextents); |
|---|
| 373 | + map = &ruip->rui_format.rui_extents[next_extent]; |
|---|
| 374 | + map->me_owner = rmap->ri_owner; |
|---|
| 375 | + map->me_startblock = rmap->ri_bmap.br_startblock; |
|---|
| 376 | + map->me_startoff = rmap->ri_bmap.br_startoff; |
|---|
| 377 | + map->me_len = rmap->ri_bmap.br_blockcount; |
|---|
| 378 | + xfs_trans_set_rmap_flags(map, rmap->ri_type, rmap->ri_whichfork, |
|---|
| 379 | + rmap->ri_bmap.br_state); |
|---|
| 363 | 380 | } |
|---|
| 364 | 381 | |
|---|
| 365 | | -/* |
|---|
| 366 | | - * This is the ops vector shared by all rud log items. |
|---|
| 367 | | - */ |
|---|
| 368 | | -static const struct xfs_item_ops xfs_rud_item_ops = { |
|---|
| 369 | | - .iop_size = xfs_rud_item_size, |
|---|
| 370 | | - .iop_format = xfs_rud_item_format, |
|---|
| 371 | | - .iop_pin = xfs_rud_item_pin, |
|---|
| 372 | | - .iop_unpin = xfs_rud_item_unpin, |
|---|
| 373 | | - .iop_unlock = xfs_rud_item_unlock, |
|---|
| 374 | | - .iop_committed = xfs_rud_item_committed, |
|---|
| 375 | | - .iop_push = xfs_rud_item_push, |
|---|
| 376 | | - .iop_committing = xfs_rud_item_committing, |
|---|
| 382 | +static struct xfs_log_item * |
|---|
| 383 | +xfs_rmap_update_create_intent( |
|---|
| 384 | + struct xfs_trans *tp, |
|---|
| 385 | + struct list_head *items, |
|---|
| 386 | + unsigned int count, |
|---|
| 387 | + bool sort) |
|---|
| 388 | +{ |
|---|
| 389 | + struct xfs_mount *mp = tp->t_mountp; |
|---|
| 390 | + struct xfs_rui_log_item *ruip = xfs_rui_init(mp, count); |
|---|
| 391 | + struct xfs_rmap_intent *rmap; |
|---|
| 392 | + |
|---|
| 393 | + ASSERT(count > 0); |
|---|
| 394 | + |
|---|
| 395 | + xfs_trans_add_item(tp, &ruip->rui_item); |
|---|
| 396 | + if (sort) |
|---|
| 397 | + list_sort(mp, items, xfs_rmap_update_diff_items); |
|---|
| 398 | + list_for_each_entry(rmap, items, ri_list) |
|---|
| 399 | + xfs_rmap_update_log_item(tp, ruip, rmap); |
|---|
| 400 | + return &ruip->rui_item; |
|---|
| 401 | +} |
|---|
| 402 | + |
|---|
| 403 | +/* Get an RUD so we can process all the deferred rmap updates. */ |
|---|
| 404 | +static struct xfs_log_item * |
|---|
| 405 | +xfs_rmap_update_create_done( |
|---|
| 406 | + struct xfs_trans *tp, |
|---|
| 407 | + struct xfs_log_item *intent, |
|---|
| 408 | + unsigned int count) |
|---|
| 409 | +{ |
|---|
| 410 | + return &xfs_trans_get_rud(tp, RUI_ITEM(intent))->rud_item; |
|---|
| 411 | +} |
|---|
| 412 | + |
|---|
| 413 | +/* Process a deferred rmap update. */ |
|---|
| 414 | +STATIC int |
|---|
| 415 | +xfs_rmap_update_finish_item( |
|---|
| 416 | + struct xfs_trans *tp, |
|---|
| 417 | + struct xfs_log_item *done, |
|---|
| 418 | + struct list_head *item, |
|---|
| 419 | + struct xfs_btree_cur **state) |
|---|
| 420 | +{ |
|---|
| 421 | + struct xfs_rmap_intent *rmap; |
|---|
| 422 | + int error; |
|---|
| 423 | + |
|---|
| 424 | + rmap = container_of(item, struct xfs_rmap_intent, ri_list); |
|---|
| 425 | + error = xfs_trans_log_finish_rmap_update(tp, RUD_ITEM(done), |
|---|
| 426 | + rmap->ri_type, rmap->ri_owner, rmap->ri_whichfork, |
|---|
| 427 | + rmap->ri_bmap.br_startoff, rmap->ri_bmap.br_startblock, |
|---|
| 428 | + rmap->ri_bmap.br_blockcount, rmap->ri_bmap.br_state, |
|---|
| 429 | + state); |
|---|
| 430 | + kmem_free(rmap); |
|---|
| 431 | + return error; |
|---|
| 432 | +} |
|---|
| 433 | + |
|---|
| 434 | +/* Abort all pending RUIs. */ |
|---|
| 435 | +STATIC void |
|---|
| 436 | +xfs_rmap_update_abort_intent( |
|---|
| 437 | + struct xfs_log_item *intent) |
|---|
| 438 | +{ |
|---|
| 439 | + xfs_rui_release(RUI_ITEM(intent)); |
|---|
| 440 | +} |
|---|
| 441 | + |
|---|
| 442 | +/* Cancel a deferred rmap update. */ |
|---|
| 443 | +STATIC void |
|---|
| 444 | +xfs_rmap_update_cancel_item( |
|---|
| 445 | + struct list_head *item) |
|---|
| 446 | +{ |
|---|
| 447 | + struct xfs_rmap_intent *rmap; |
|---|
| 448 | + |
|---|
| 449 | + rmap = container_of(item, struct xfs_rmap_intent, ri_list); |
|---|
| 450 | + kmem_free(rmap); |
|---|
| 451 | +} |
|---|
| 452 | + |
|---|
| 453 | +const struct xfs_defer_op_type xfs_rmap_update_defer_type = { |
|---|
| 454 | + .max_items = XFS_RUI_MAX_FAST_EXTENTS, |
|---|
| 455 | + .create_intent = xfs_rmap_update_create_intent, |
|---|
| 456 | + .abort_intent = xfs_rmap_update_abort_intent, |
|---|
| 457 | + .create_done = xfs_rmap_update_create_done, |
|---|
| 458 | + .finish_item = xfs_rmap_update_finish_item, |
|---|
| 459 | + .finish_cleanup = xfs_rmap_finish_one_cleanup, |
|---|
| 460 | + .cancel_item = xfs_rmap_update_cancel_item, |
|---|
| 377 | 461 | }; |
|---|
| 378 | | - |
|---|
| 379 | | -/* |
|---|
| 380 | | - * Allocate and initialize an rud item with the given number of extents. |
|---|
| 381 | | - */ |
|---|
| 382 | | -struct xfs_rud_log_item * |
|---|
| 383 | | -xfs_rud_init( |
|---|
| 384 | | - struct xfs_mount *mp, |
|---|
| 385 | | - struct xfs_rui_log_item *ruip) |
|---|
| 386 | | - |
|---|
| 387 | | -{ |
|---|
| 388 | | - struct xfs_rud_log_item *rudp; |
|---|
| 389 | | - |
|---|
| 390 | | - rudp = kmem_zone_zalloc(xfs_rud_zone, KM_SLEEP); |
|---|
| 391 | | - xfs_log_item_init(mp, &rudp->rud_item, XFS_LI_RUD, &xfs_rud_item_ops); |
|---|
| 392 | | - rudp->rud_ruip = ruip; |
|---|
| 393 | | - rudp->rud_format.rud_rui_id = ruip->rui_format.rui_id; |
|---|
| 394 | | - |
|---|
| 395 | | - return rudp; |
|---|
| 396 | | -} |
|---|
| 397 | 462 | |
|---|
| 398 | 463 | /* |
|---|
| 399 | 464 | * Process an rmap update intent item that was recovered from the log. |
|---|
| 400 | 465 | * We need to update the rmapbt. |
|---|
| 401 | 466 | */ |
|---|
| 402 | | -int |
|---|
| 403 | | -xfs_rui_recover( |
|---|
| 404 | | - struct xfs_mount *mp, |
|---|
| 405 | | - struct xfs_rui_log_item *ruip) |
|---|
| 467 | +STATIC int |
|---|
| 468 | +xfs_rui_item_recover( |
|---|
| 469 | + struct xfs_log_item *lip, |
|---|
| 470 | + struct list_head *capture_list) |
|---|
| 406 | 471 | { |
|---|
| 407 | | - int i; |
|---|
| 408 | | - int error = 0; |
|---|
| 472 | + struct xfs_rui_log_item *ruip = RUI_ITEM(lip); |
|---|
| 409 | 473 | struct xfs_map_extent *rmap; |
|---|
| 410 | | - xfs_fsblock_t startblock_fsb; |
|---|
| 411 | | - bool op_ok; |
|---|
| 412 | 474 | struct xfs_rud_log_item *rudp; |
|---|
| 413 | | - enum xfs_rmap_intent_type type; |
|---|
| 414 | | - int whichfork; |
|---|
| 415 | | - xfs_exntst_t state; |
|---|
| 416 | 475 | struct xfs_trans *tp; |
|---|
| 417 | 476 | struct xfs_btree_cur *rcur = NULL; |
|---|
| 418 | | - |
|---|
| 419 | | - ASSERT(!test_bit(XFS_RUI_RECOVERED, &ruip->rui_flags)); |
|---|
| 477 | + struct xfs_mount *mp = lip->li_mountp; |
|---|
| 478 | + xfs_fsblock_t startblock_fsb; |
|---|
| 479 | + enum xfs_rmap_intent_type type; |
|---|
| 480 | + xfs_exntst_t state; |
|---|
| 481 | + bool op_ok; |
|---|
| 482 | + int i; |
|---|
| 483 | + int whichfork; |
|---|
| 484 | + int error = 0; |
|---|
| 420 | 485 | |
|---|
| 421 | 486 | /* |
|---|
| 422 | 487 | * First check the validity of the extents described by the |
|---|
| .. | .. |
|---|
| 446 | 511 | rmap->me_len == 0 || |
|---|
| 447 | 512 | startblock_fsb >= mp->m_sb.sb_dblocks || |
|---|
| 448 | 513 | rmap->me_len >= mp->m_sb.sb_agblocks || |
|---|
| 449 | | - (rmap->me_flags & ~XFS_RMAP_EXTENT_FLAGS)) { |
|---|
| 450 | | - /* |
|---|
| 451 | | - * This will pull the RUI from the AIL and |
|---|
| 452 | | - * free the memory associated with it. |
|---|
| 453 | | - */ |
|---|
| 454 | | - set_bit(XFS_RUI_RECOVERED, &ruip->rui_flags); |
|---|
| 455 | | - xfs_rui_release(ruip); |
|---|
| 456 | | - return -EIO; |
|---|
| 457 | | - } |
|---|
| 514 | + (rmap->me_flags & ~XFS_RMAP_EXTENT_FLAGS)) |
|---|
| 515 | + return -EFSCORRUPTED; |
|---|
| 458 | 516 | } |
|---|
| 459 | 517 | |
|---|
| 460 | 518 | error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, |
|---|
| .. | .. |
|---|
| 495 | 553 | type = XFS_RMAP_FREE; |
|---|
| 496 | 554 | break; |
|---|
| 497 | 555 | default: |
|---|
| 556 | + XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, NULL); |
|---|
| 498 | 557 | error = -EFSCORRUPTED; |
|---|
| 499 | 558 | goto abort_error; |
|---|
| 500 | 559 | } |
|---|
| .. | .. |
|---|
| 508 | 567 | } |
|---|
| 509 | 568 | |
|---|
| 510 | 569 | xfs_rmap_finish_one_cleanup(tp, rcur, error); |
|---|
| 511 | | - set_bit(XFS_RUI_RECOVERED, &ruip->rui_flags); |
|---|
| 512 | | - error = xfs_trans_commit(tp); |
|---|
| 513 | | - return error; |
|---|
| 570 | + return xfs_defer_ops_capture_and_commit(tp, NULL, capture_list); |
|---|
| 514 | 571 | |
|---|
| 515 | 572 | abort_error: |
|---|
| 516 | 573 | xfs_rmap_finish_one_cleanup(tp, rcur, error); |
|---|
| 517 | 574 | xfs_trans_cancel(tp); |
|---|
| 518 | 575 | return error; |
|---|
| 519 | 576 | } |
|---|
| 577 | + |
|---|
| 578 | +STATIC bool |
|---|
| 579 | +xfs_rui_item_match( |
|---|
| 580 | + struct xfs_log_item *lip, |
|---|
| 581 | + uint64_t intent_id) |
|---|
| 582 | +{ |
|---|
| 583 | + return RUI_ITEM(lip)->rui_format.rui_id == intent_id; |
|---|
| 584 | +} |
|---|
| 585 | + |
|---|
| 586 | +/* Relog an intent item to push the log tail forward. */ |
|---|
| 587 | +static struct xfs_log_item * |
|---|
| 588 | +xfs_rui_item_relog( |
|---|
| 589 | + struct xfs_log_item *intent, |
|---|
| 590 | + struct xfs_trans *tp) |
|---|
| 591 | +{ |
|---|
| 592 | + struct xfs_rud_log_item *rudp; |
|---|
| 593 | + struct xfs_rui_log_item *ruip; |
|---|
| 594 | + struct xfs_map_extent *extp; |
|---|
| 595 | + unsigned int count; |
|---|
| 596 | + |
|---|
| 597 | + count = RUI_ITEM(intent)->rui_format.rui_nextents; |
|---|
| 598 | + extp = RUI_ITEM(intent)->rui_format.rui_extents; |
|---|
| 599 | + |
|---|
| 600 | + tp->t_flags |= XFS_TRANS_DIRTY; |
|---|
| 601 | + rudp = xfs_trans_get_rud(tp, RUI_ITEM(intent)); |
|---|
| 602 | + set_bit(XFS_LI_DIRTY, &rudp->rud_item.li_flags); |
|---|
| 603 | + |
|---|
| 604 | + ruip = xfs_rui_init(tp->t_mountp, count); |
|---|
| 605 | + memcpy(ruip->rui_format.rui_extents, extp, count * sizeof(*extp)); |
|---|
| 606 | + atomic_set(&ruip->rui_next_extent, count); |
|---|
| 607 | + xfs_trans_add_item(tp, &ruip->rui_item); |
|---|
| 608 | + set_bit(XFS_LI_DIRTY, &ruip->rui_item.li_flags); |
|---|
| 609 | + return &ruip->rui_item; |
|---|
| 610 | +} |
|---|
| 611 | + |
|---|
| 612 | +static const struct xfs_item_ops xfs_rui_item_ops = { |
|---|
| 613 | + .iop_size = xfs_rui_item_size, |
|---|
| 614 | + .iop_format = xfs_rui_item_format, |
|---|
| 615 | + .iop_unpin = xfs_rui_item_unpin, |
|---|
| 616 | + .iop_release = xfs_rui_item_release, |
|---|
| 617 | + .iop_recover = xfs_rui_item_recover, |
|---|
| 618 | + .iop_match = xfs_rui_item_match, |
|---|
| 619 | + .iop_relog = xfs_rui_item_relog, |
|---|
| 620 | +}; |
|---|
| 621 | + |
|---|
| 622 | +/* |
|---|
| 623 | + * This routine is called to create an in-core extent rmap update |
|---|
| 624 | + * item from the rui format structure which was logged on disk. |
|---|
| 625 | + * It allocates an in-core rui, copies the extents from the format |
|---|
| 626 | + * structure into it, and adds the rui to the AIL with the given |
|---|
| 627 | + * LSN. |
|---|
| 628 | + */ |
|---|
| 629 | +STATIC int |
|---|
| 630 | +xlog_recover_rui_commit_pass2( |
|---|
| 631 | + struct xlog *log, |
|---|
| 632 | + struct list_head *buffer_list, |
|---|
| 633 | + struct xlog_recover_item *item, |
|---|
| 634 | + xfs_lsn_t lsn) |
|---|
| 635 | +{ |
|---|
| 636 | + int error; |
|---|
| 637 | + struct xfs_mount *mp = log->l_mp; |
|---|
| 638 | + struct xfs_rui_log_item *ruip; |
|---|
| 639 | + struct xfs_rui_log_format *rui_formatp; |
|---|
| 640 | + |
|---|
| 641 | + rui_formatp = item->ri_buf[0].i_addr; |
|---|
| 642 | + |
|---|
| 643 | + ruip = xfs_rui_init(mp, rui_formatp->rui_nextents); |
|---|
| 644 | + error = xfs_rui_copy_format(&item->ri_buf[0], &ruip->rui_format); |
|---|
| 645 | + if (error) { |
|---|
| 646 | + xfs_rui_item_free(ruip); |
|---|
| 647 | + return error; |
|---|
| 648 | + } |
|---|
| 649 | + atomic_set(&ruip->rui_next_extent, rui_formatp->rui_nextents); |
|---|
| 650 | + /* |
|---|
| 651 | + * Insert the intent into the AIL directly and drop one reference so |
|---|
| 652 | + * that finishing or canceling the work will drop the other. |
|---|
| 653 | + */ |
|---|
| 654 | + xfs_trans_ail_insert(log->l_ailp, &ruip->rui_item, lsn); |
|---|
| 655 | + xfs_rui_release(ruip); |
|---|
| 656 | + return 0; |
|---|
| 657 | +} |
|---|
| 658 | + |
|---|
| 659 | +const struct xlog_recover_item_ops xlog_rui_item_ops = { |
|---|
| 660 | + .item_type = XFS_LI_RUI, |
|---|
| 661 | + .commit_pass2 = xlog_recover_rui_commit_pass2, |
|---|
| 662 | +}; |
|---|
| 663 | + |
|---|
| 664 | +/* |
|---|
| 665 | + * This routine is called when an RUD format structure is found in a committed |
|---|
| 666 | + * transaction in the log. Its purpose is to cancel the corresponding RUI if it |
|---|
| 667 | + * was still in the log. To do this it searches the AIL for the RUI with an id |
|---|
| 668 | + * equal to that in the RUD format structure. If we find it we drop the RUD |
|---|
| 669 | + * reference, which removes the RUI from the AIL and frees it. |
|---|
| 670 | + */ |
|---|
| 671 | +STATIC int |
|---|
| 672 | +xlog_recover_rud_commit_pass2( |
|---|
| 673 | + struct xlog *log, |
|---|
| 674 | + struct list_head *buffer_list, |
|---|
| 675 | + struct xlog_recover_item *item, |
|---|
| 676 | + xfs_lsn_t lsn) |
|---|
| 677 | +{ |
|---|
| 678 | + struct xfs_rud_log_format *rud_formatp; |
|---|
| 679 | + |
|---|
| 680 | + rud_formatp = item->ri_buf[0].i_addr; |
|---|
| 681 | + ASSERT(item->ri_buf[0].i_len == sizeof(struct xfs_rud_log_format)); |
|---|
| 682 | + |
|---|
| 683 | + xlog_recover_release_intent(log, XFS_LI_RUI, rud_formatp->rud_rui_id); |
|---|
| 684 | + return 0; |
|---|
| 685 | +} |
|---|
| 686 | + |
|---|
| 687 | +const struct xlog_recover_item_ops xlog_rud_item_ops = { |
|---|
| 688 | + .item_type = XFS_LI_RUD, |
|---|
| 689 | + .commit_pass2 = xlog_recover_rud_commit_pass2, |
|---|
| 690 | +}; |
|---|