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" |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 17 | #include "xfs_rmap_item.h" |
| 18 | #include "xfs_log.h" |
Darrick J. Wong | 9c19464 | 2016-08-03 12:16:05 +1000 | [diff] [blame] | 19 | #include "xfs_rmap.h" |
Darrick J. Wong | a5155b8 | 2019-11-02 09:40:53 -0700 | [diff] [blame] | 20 | #include "xfs_error.h" |
Darrick J. Wong | 07590a9 | 2020-05-01 16:00:49 -0700 | [diff] [blame] | 21 | #include "xfs_log_priv.h" |
Darrick J. Wong | 86ffa47 | 2020-05-01 16:00:45 -0700 | [diff] [blame] | 22 | #include "xfs_log_recover.h" |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 23 | |
Darrick J. Wong | 182696f | 2021-10-12 11:09:23 -0700 | [diff] [blame] | 24 | struct kmem_cache *xfs_rui_cache; |
| 25 | struct kmem_cache *xfs_rud_cache; |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 26 | |
Darrick J. Wong | cba0cca | 2020-05-01 16:00:51 -0700 | [diff] [blame] | 27 | static const struct xfs_item_ops xfs_rui_item_ops; |
| 28 | |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 29 | static inline struct xfs_rui_log_item *RUI_ITEM(struct xfs_log_item *lip) |
| 30 | { |
| 31 | return container_of(lip, struct xfs_rui_log_item, rui_item); |
| 32 | } |
| 33 | |
Darrick J. Wong | 07590a9 | 2020-05-01 16:00:49 -0700 | [diff] [blame] | 34 | STATIC void |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 35 | xfs_rui_item_free( |
| 36 | struct xfs_rui_log_item *ruip) |
| 37 | { |
| 38 | if (ruip->rui_format.rui_nextents > XFS_RUI_MAX_FAST_EXTENTS) |
| 39 | kmem_free(ruip); |
| 40 | else |
Darrick J. Wong | 182696f | 2021-10-12 11:09:23 -0700 | [diff] [blame] | 41 | kmem_cache_free(xfs_rui_cache, ruip); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 42 | } |
| 43 | |
Dave Chinner | 0612d11 | 2018-04-02 20:08:27 -0700 | [diff] [blame] | 44 | /* |
| 45 | * Freeing the RUI requires that we remove it from the AIL if it has already |
| 46 | * been placed there. However, the RUI may not yet have been placed in the AIL |
| 47 | * when called by xfs_rui_release() from RUD processing due to the ordering of |
| 48 | * committed vs unpin operations in bulk insert operations. Hence the reference |
| 49 | * count to ensure only the last caller frees the RUI. |
| 50 | */ |
Darrick J. Wong | cba0cca | 2020-05-01 16:00:51 -0700 | [diff] [blame] | 51 | STATIC void |
Dave Chinner | 0612d11 | 2018-04-02 20:08:27 -0700 | [diff] [blame] | 52 | xfs_rui_release( |
| 53 | struct xfs_rui_log_item *ruip) |
| 54 | { |
| 55 | ASSERT(atomic_read(&ruip->rui_refcount) > 0); |
| 56 | if (atomic_dec_and_test(&ruip->rui_refcount)) { |
Brian Foster | 6558792 | 2020-05-06 13:25:23 -0700 | [diff] [blame] | 57 | xfs_trans_ail_delete(&ruip->rui_item, SHUTDOWN_LOG_IO_ERROR); |
Dave Chinner | 0612d11 | 2018-04-02 20:08:27 -0700 | [diff] [blame] | 58 | xfs_rui_item_free(ruip); |
| 59 | } |
| 60 | } |
| 61 | |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 62 | STATIC void |
| 63 | xfs_rui_item_size( |
| 64 | struct xfs_log_item *lip, |
| 65 | int *nvecs, |
| 66 | int *nbytes) |
| 67 | { |
Darrick J. Wong | cd00158 | 2016-09-19 10:24:27 +1000 | [diff] [blame] | 68 | struct xfs_rui_log_item *ruip = RUI_ITEM(lip); |
| 69 | |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 70 | *nvecs += 1; |
Darrick J. Wong | cd00158 | 2016-09-19 10:24:27 +1000 | [diff] [blame] | 71 | *nbytes += xfs_rui_log_format_sizeof(ruip->rui_format.rui_nextents); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | /* |
| 75 | * This is called to fill in the vector of log iovecs for the |
| 76 | * given rui log item. We use only 1 iovec, and we point that |
| 77 | * at the rui_log_format structure embedded in the rui item. |
| 78 | * It is at this point that we assert that all of the extent |
| 79 | * slots in the rui item have been filled. |
| 80 | */ |
| 81 | STATIC void |
| 82 | xfs_rui_item_format( |
| 83 | struct xfs_log_item *lip, |
| 84 | struct xfs_log_vec *lv) |
| 85 | { |
| 86 | struct xfs_rui_log_item *ruip = RUI_ITEM(lip); |
| 87 | struct xfs_log_iovec *vecp = NULL; |
| 88 | |
| 89 | ASSERT(atomic_read(&ruip->rui_next_extent) == |
| 90 | ruip->rui_format.rui_nextents); |
| 91 | |
| 92 | ruip->rui_format.rui_type = XFS_LI_RUI; |
| 93 | ruip->rui_format.rui_size = 1; |
| 94 | |
| 95 | 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] | 96 | xfs_rui_log_format_sizeof(ruip->rui_format.rui_nextents)); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | /* |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 100 | * The unpin operation is the last place an RUI is manipulated in the log. It is |
| 101 | * either inserted in the AIL or aborted in the event of a log I/O error. In |
| 102 | * either case, the RUI transaction has been successfully committed to make it |
| 103 | * this far. Therefore, we expect whoever committed the RUI to either construct |
| 104 | * and commit the RUD or drop the RUD's reference in the event of error. Simply |
| 105 | * drop the log's RUI reference now that the log is done with it. |
| 106 | */ |
| 107 | STATIC void |
| 108 | xfs_rui_item_unpin( |
| 109 | struct xfs_log_item *lip, |
| 110 | int remove) |
| 111 | { |
| 112 | struct xfs_rui_log_item *ruip = RUI_ITEM(lip); |
| 113 | |
| 114 | xfs_rui_release(ruip); |
| 115 | } |
| 116 | |
| 117 | /* |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 118 | * The RUI has been either committed or aborted if the transaction has been |
| 119 | * cancelled. If the transaction was cancelled, an RUD isn't going to be |
| 120 | * constructed and thus we free the RUI here directly. |
| 121 | */ |
| 122 | STATIC void |
Christoph Hellwig | ddf9205 | 2019-06-28 19:27:32 -0700 | [diff] [blame] | 123 | xfs_rui_item_release( |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 124 | struct xfs_log_item *lip) |
| 125 | { |
Christoph Hellwig | ddf9205 | 2019-06-28 19:27:32 -0700 | [diff] [blame] | 126 | xfs_rui_release(RUI_ITEM(lip)); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 127 | } |
| 128 | |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 129 | /* |
| 130 | * Allocate and initialize an rui item with the given number of extents. |
| 131 | */ |
Darrick J. Wong | 07590a9 | 2020-05-01 16:00:49 -0700 | [diff] [blame] | 132 | STATIC struct xfs_rui_log_item * |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 133 | xfs_rui_init( |
| 134 | struct xfs_mount *mp, |
| 135 | uint nextents) |
| 136 | |
| 137 | { |
| 138 | struct xfs_rui_log_item *ruip; |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 139 | |
| 140 | ASSERT(nextents > 0); |
Darrick J. Wong | cd00158 | 2016-09-19 10:24:27 +1000 | [diff] [blame] | 141 | if (nextents > XFS_RUI_MAX_FAST_EXTENTS) |
Tetsuo Handa | 707e0dd | 2019-08-26 12:06:22 -0700 | [diff] [blame] | 142 | ruip = kmem_zalloc(xfs_rui_log_item_sizeof(nextents), 0); |
Darrick J. Wong | cd00158 | 2016-09-19 10:24:27 +1000 | [diff] [blame] | 143 | else |
Darrick J. Wong | 182696f | 2021-10-12 11:09:23 -0700 | [diff] [blame] | 144 | ruip = kmem_cache_zalloc(xfs_rui_cache, |
Carlos Maiolino | 32a2b11 | 2020-07-22 09:23:10 -0700 | [diff] [blame] | 145 | GFP_KERNEL | __GFP_NOFAIL); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 146 | |
| 147 | xfs_log_item_init(mp, &ruip->rui_item, XFS_LI_RUI, &xfs_rui_item_ops); |
| 148 | ruip->rui_format.rui_nextents = nextents; |
| 149 | ruip->rui_format.rui_id = (uintptr_t)(void *)ruip; |
| 150 | atomic_set(&ruip->rui_next_extent, 0); |
| 151 | atomic_set(&ruip->rui_refcount, 2); |
| 152 | |
| 153 | return ruip; |
| 154 | } |
| 155 | |
| 156 | /* |
| 157 | * Copy an RUI format buffer from the given buf, and into the destination |
| 158 | * RUI format structure. The RUI/RUD items were designed not to need any |
| 159 | * special alignment handling. |
| 160 | */ |
Darrick J. Wong | 07590a9 | 2020-05-01 16:00:49 -0700 | [diff] [blame] | 161 | STATIC int |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 162 | xfs_rui_copy_format( |
| 163 | struct xfs_log_iovec *buf, |
| 164 | struct xfs_rui_log_format *dst_rui_fmt) |
| 165 | { |
| 166 | struct xfs_rui_log_format *src_rui_fmt; |
| 167 | uint len; |
| 168 | |
| 169 | src_rui_fmt = buf->i_addr; |
Darrick J. Wong | cd00158 | 2016-09-19 10:24:27 +1000 | [diff] [blame] | 170 | len = xfs_rui_log_format_sizeof(src_rui_fmt->rui_nextents); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 171 | |
Darrick J. Wong | a5155b8 | 2019-11-02 09:40:53 -0700 | [diff] [blame] | 172 | if (buf->i_len != len) { |
| 173 | XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, NULL); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 174 | return -EFSCORRUPTED; |
Darrick J. Wong | a5155b8 | 2019-11-02 09:40:53 -0700 | [diff] [blame] | 175 | } |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 176 | |
Darrick J. Wong | cd00158 | 2016-09-19 10:24:27 +1000 | [diff] [blame] | 177 | memcpy(dst_rui_fmt, src_rui_fmt, len); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 178 | return 0; |
| 179 | } |
| 180 | |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 181 | static inline struct xfs_rud_log_item *RUD_ITEM(struct xfs_log_item *lip) |
| 182 | { |
| 183 | return container_of(lip, struct xfs_rud_log_item, rud_item); |
| 184 | } |
| 185 | |
| 186 | STATIC void |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 187 | xfs_rud_item_size( |
| 188 | struct xfs_log_item *lip, |
| 189 | int *nvecs, |
| 190 | int *nbytes) |
| 191 | { |
| 192 | *nvecs += 1; |
Darrick J. Wong | 722e251 | 2016-08-03 12:28:43 +1000 | [diff] [blame] | 193 | *nbytes += sizeof(struct xfs_rud_log_format); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | /* |
| 197 | * This is called to fill in the vector of log iovecs for the |
| 198 | * given rud log item. We use only 1 iovec, and we point that |
| 199 | * at the rud_log_format structure embedded in the rud item. |
| 200 | * It is at this point that we assert that all of the extent |
| 201 | * slots in the rud item have been filled. |
| 202 | */ |
| 203 | STATIC void |
| 204 | xfs_rud_item_format( |
| 205 | struct xfs_log_item *lip, |
| 206 | struct xfs_log_vec *lv) |
| 207 | { |
| 208 | struct xfs_rud_log_item *rudp = RUD_ITEM(lip); |
| 209 | struct xfs_log_iovec *vecp = NULL; |
| 210 | |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 211 | rudp->rud_format.rud_type = XFS_LI_RUD; |
| 212 | rudp->rud_format.rud_size = 1; |
| 213 | |
| 214 | 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] | 215 | sizeof(struct xfs_rud_log_format)); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | /* |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 219 | * The RUD is either committed or aborted if the transaction is cancelled. If |
| 220 | * the transaction is cancelled, drop our reference to the RUI and free the |
| 221 | * RUD. |
| 222 | */ |
| 223 | STATIC void |
Christoph Hellwig | ddf9205 | 2019-06-28 19:27:32 -0700 | [diff] [blame] | 224 | xfs_rud_item_release( |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 225 | struct xfs_log_item *lip) |
| 226 | { |
| 227 | struct xfs_rud_log_item *rudp = RUD_ITEM(lip); |
| 228 | |
Christoph Hellwig | ddf9205 | 2019-06-28 19:27:32 -0700 | [diff] [blame] | 229 | xfs_rui_release(rudp->rud_ruip); |
Darrick J. Wong | 182696f | 2021-10-12 11:09:23 -0700 | [diff] [blame] | 230 | kmem_cache_free(xfs_rud_cache, rudp); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 231 | } |
| 232 | |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 233 | static const struct xfs_item_ops xfs_rud_item_ops = { |
Christoph Hellwig | 9ce632a | 2019-06-28 19:27:32 -0700 | [diff] [blame] | 234 | .flags = XFS_ITEM_RELEASE_WHEN_COMMITTED, |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 235 | .iop_size = xfs_rud_item_size, |
| 236 | .iop_format = xfs_rud_item_format, |
Christoph Hellwig | ddf9205 | 2019-06-28 19:27:32 -0700 | [diff] [blame] | 237 | .iop_release = xfs_rud_item_release, |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 238 | }; |
| 239 | |
Christoph Hellwig | 3cfce1e | 2019-06-28 19:29:41 -0700 | [diff] [blame] | 240 | static struct xfs_rud_log_item * |
Christoph Hellwig | 60883447 | 2019-06-28 19:27:36 -0700 | [diff] [blame] | 241 | xfs_trans_get_rud( |
| 242 | struct xfs_trans *tp, |
Darrick J. Wong | 722e251 | 2016-08-03 12:28:43 +1000 | [diff] [blame] | 243 | struct xfs_rui_log_item *ruip) |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 244 | { |
Christoph Hellwig | 60883447 | 2019-06-28 19:27:36 -0700 | [diff] [blame] | 245 | struct xfs_rud_log_item *rudp; |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 246 | |
Darrick J. Wong | 182696f | 2021-10-12 11:09:23 -0700 | [diff] [blame] | 247 | rudp = kmem_cache_zalloc(xfs_rud_cache, GFP_KERNEL | __GFP_NOFAIL); |
Christoph Hellwig | 60883447 | 2019-06-28 19:27:36 -0700 | [diff] [blame] | 248 | xfs_log_item_init(tp->t_mountp, &rudp->rud_item, XFS_LI_RUD, |
| 249 | &xfs_rud_item_ops); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 250 | rudp->rud_ruip = ruip; |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 251 | rudp->rud_format.rud_rui_id = ruip->rui_format.rui_id; |
| 252 | |
Christoph Hellwig | 60883447 | 2019-06-28 19:27:36 -0700 | [diff] [blame] | 253 | xfs_trans_add_item(tp, &rudp->rud_item); |
Darrick J. Wong | 5880f2d7 | 2016-08-03 12:04:45 +1000 | [diff] [blame] | 254 | return rudp; |
| 255 | } |
Darrick J. Wong | 9e88b5d | 2016-08-03 12:09:48 +1000 | [diff] [blame] | 256 | |
Christoph Hellwig | 3cfce1e | 2019-06-28 19:29:41 -0700 | [diff] [blame] | 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); |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | /* |
| 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. |
| 304 | */ |
| 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) |
| 317 | { |
| 318 | int error; |
| 319 | |
| 320 | error = xfs_rmap_finish_one(tp, type, owner, whichfork, startoff, |
| 321 | startblock, blockcount, state, pcur); |
| 322 | |
| 323 | /* |
| 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 |
| 329 | */ |
| 330 | tp->t_flags |= XFS_TRANS_DIRTY; |
| 331 | set_bit(XFS_LI_DIRTY, &rudp->rud_item.li_flags); |
| 332 | |
| 333 | return error; |
| 334 | } |
| 335 | |
| 336 | /* Sort rmap intents by AG. */ |
| 337 | static int |
| 338 | xfs_rmap_update_diff_items( |
| 339 | void *priv, |
Sami Tolvanen | 4f0f586 | 2021-04-08 11:28:34 -0700 | [diff] [blame] | 340 | const struct list_head *a, |
| 341 | const struct list_head *b) |
Christoph Hellwig | 3cfce1e | 2019-06-28 19:29:41 -0700 | [diff] [blame] | 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 | |
Christoph Hellwig | 3cfce1e | 2019-06-28 19:29:41 -0700 | [diff] [blame] | 353 | /* Log rmap updates in the intent item. */ |
| 354 | STATIC void |
| 355 | xfs_rmap_update_log_item( |
| 356 | struct xfs_trans *tp, |
Christoph Hellwig | c1f0918 | 2020-04-30 12:52:20 -0700 | [diff] [blame] | 357 | struct xfs_rui_log_item *ruip, |
| 358 | struct xfs_rmap_intent *rmap) |
Christoph Hellwig | 3cfce1e | 2019-06-28 19:29:41 -0700 | [diff] [blame] | 359 | { |
Christoph Hellwig | 3cfce1e | 2019-06-28 19:29:41 -0700 | [diff] [blame] | 360 | uint next_extent; |
| 361 | struct xfs_map_extent *map; |
| 362 | |
Christoph Hellwig | 3cfce1e | 2019-06-28 19:29:41 -0700 | [diff] [blame] | 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); |
| 380 | } |
| 381 | |
Christoph Hellwig | 13a8333 | 2020-04-30 12:52:21 -0700 | [diff] [blame] | 382 | static struct xfs_log_item * |
Christoph Hellwig | c1f0918 | 2020-04-30 12:52:20 -0700 | [diff] [blame] | 383 | xfs_rmap_update_create_intent( |
| 384 | struct xfs_trans *tp, |
| 385 | struct list_head *items, |
Christoph Hellwig | d367a86 | 2020-04-30 12:52:20 -0700 | [diff] [blame] | 386 | unsigned int count, |
| 387 | bool sort) |
Christoph Hellwig | c1f0918 | 2020-04-30 12:52:20 -0700 | [diff] [blame] | 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); |
Christoph Hellwig | d367a86 | 2020-04-30 12:52:20 -0700 | [diff] [blame] | 396 | if (sort) |
| 397 | list_sort(mp, items, xfs_rmap_update_diff_items); |
Christoph Hellwig | c1f0918 | 2020-04-30 12:52:20 -0700 | [diff] [blame] | 398 | list_for_each_entry(rmap, items, ri_list) |
| 399 | xfs_rmap_update_log_item(tp, ruip, rmap); |
Christoph Hellwig | 13a8333 | 2020-04-30 12:52:21 -0700 | [diff] [blame] | 400 | return &ruip->rui_item; |
Christoph Hellwig | c1f0918 | 2020-04-30 12:52:20 -0700 | [diff] [blame] | 401 | } |
| 402 | |
Christoph Hellwig | 3cfce1e | 2019-06-28 19:29:41 -0700 | [diff] [blame] | 403 | /* Get an RUD so we can process all the deferred rmap updates. */ |
Christoph Hellwig | f09d167 | 2020-04-30 12:52:22 -0700 | [diff] [blame] | 404 | static struct xfs_log_item * |
Christoph Hellwig | 3cfce1e | 2019-06-28 19:29:41 -0700 | [diff] [blame] | 405 | xfs_rmap_update_create_done( |
| 406 | struct xfs_trans *tp, |
Christoph Hellwig | 13a8333 | 2020-04-30 12:52:21 -0700 | [diff] [blame] | 407 | struct xfs_log_item *intent, |
Christoph Hellwig | 3cfce1e | 2019-06-28 19:29:41 -0700 | [diff] [blame] | 408 | unsigned int count) |
| 409 | { |
Christoph Hellwig | f09d167 | 2020-04-30 12:52:22 -0700 | [diff] [blame] | 410 | return &xfs_trans_get_rud(tp, RUI_ITEM(intent))->rud_item; |
Christoph Hellwig | 3cfce1e | 2019-06-28 19:29:41 -0700 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | /* Process a deferred rmap update. */ |
| 414 | STATIC int |
| 415 | xfs_rmap_update_finish_item( |
| 416 | struct xfs_trans *tp, |
Christoph Hellwig | f09d167 | 2020-04-30 12:52:22 -0700 | [diff] [blame] | 417 | struct xfs_log_item *done, |
Christoph Hellwig | 3cfce1e | 2019-06-28 19:29:41 -0700 | [diff] [blame] | 418 | struct list_head *item, |
Christoph Hellwig | 3ec1b26 | 2020-04-30 12:52:22 -0700 | [diff] [blame] | 419 | struct xfs_btree_cur **state) |
Christoph Hellwig | 3cfce1e | 2019-06-28 19:29:41 -0700 | [diff] [blame] | 420 | { |
| 421 | struct xfs_rmap_intent *rmap; |
| 422 | int error; |
| 423 | |
| 424 | rmap = container_of(item, struct xfs_rmap_intent, ri_list); |
Christoph Hellwig | f09d167 | 2020-04-30 12:52:22 -0700 | [diff] [blame] | 425 | error = xfs_trans_log_finish_rmap_update(tp, RUD_ITEM(done), |
Christoph Hellwig | 3ec1b26 | 2020-04-30 12:52:22 -0700 | [diff] [blame] | 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); |
Darrick J. Wong | f3c799c | 2021-10-12 14:11:01 -0700 | [diff] [blame] | 430 | kmem_cache_free(xfs_rmap_intent_cache, rmap); |
Christoph Hellwig | 3cfce1e | 2019-06-28 19:29:41 -0700 | [diff] [blame] | 431 | return error; |
| 432 | } |
| 433 | |
Christoph Hellwig | 3cfce1e | 2019-06-28 19:29:41 -0700 | [diff] [blame] | 434 | /* Abort all pending RUIs. */ |
| 435 | STATIC void |
| 436 | xfs_rmap_update_abort_intent( |
Christoph Hellwig | 13a8333 | 2020-04-30 12:52:21 -0700 | [diff] [blame] | 437 | struct xfs_log_item *intent) |
Christoph Hellwig | 3cfce1e | 2019-06-28 19:29:41 -0700 | [diff] [blame] | 438 | { |
Christoph Hellwig | 13a8333 | 2020-04-30 12:52:21 -0700 | [diff] [blame] | 439 | xfs_rui_release(RUI_ITEM(intent)); |
Christoph Hellwig | 3cfce1e | 2019-06-28 19:29:41 -0700 | [diff] [blame] | 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); |
Darrick J. Wong | f3c799c | 2021-10-12 14:11:01 -0700 | [diff] [blame] | 450 | kmem_cache_free(xfs_rmap_intent_cache, rmap); |
Christoph Hellwig | 3cfce1e | 2019-06-28 19:29:41 -0700 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | const struct xfs_defer_op_type xfs_rmap_update_defer_type = { |
| 454 | .max_items = XFS_RUI_MAX_FAST_EXTENTS, |
Christoph Hellwig | 3cfce1e | 2019-06-28 19:29:41 -0700 | [diff] [blame] | 455 | .create_intent = xfs_rmap_update_create_intent, |
| 456 | .abort_intent = xfs_rmap_update_abort_intent, |
Christoph Hellwig | 3cfce1e | 2019-06-28 19:29:41 -0700 | [diff] [blame] | 457 | .create_done = xfs_rmap_update_create_done, |
| 458 | .finish_item = xfs_rmap_update_finish_item, |
Christoph Hellwig | 3ec1b26 | 2020-04-30 12:52:22 -0700 | [diff] [blame] | 459 | .finish_cleanup = xfs_rmap_finish_one_cleanup, |
Christoph Hellwig | 3cfce1e | 2019-06-28 19:29:41 -0700 | [diff] [blame] | 460 | .cancel_item = xfs_rmap_update_cancel_item, |
| 461 | }; |
| 462 | |
Darrick J. Wong | dda7ba6 | 2020-11-29 16:33:36 -0800 | [diff] [blame] | 463 | /* Is this recovered RUI ok? */ |
| 464 | static inline bool |
| 465 | xfs_rui_validate_map( |
| 466 | struct xfs_mount *mp, |
| 467 | struct xfs_map_extent *rmap) |
| 468 | { |
Dave Chinner | 38c26bf | 2021-08-18 18:46:37 -0700 | [diff] [blame] | 469 | if (!xfs_has_rmapbt(mp)) |
Darrick J. Wong | da5de11 | 2020-11-29 16:33:39 -0800 | [diff] [blame] | 470 | return false; |
| 471 | |
Darrick J. Wong | c447ad6 | 2020-11-29 16:33:37 -0800 | [diff] [blame] | 472 | if (rmap->me_flags & ~XFS_RMAP_EXTENT_FLAGS) |
| 473 | return false; |
Darrick J. Wong | dda7ba6 | 2020-11-29 16:33:36 -0800 | [diff] [blame] | 474 | |
Darrick J. Wong | dda7ba6 | 2020-11-29 16:33:36 -0800 | [diff] [blame] | 475 | switch (rmap->me_flags & XFS_RMAP_EXTENT_TYPE_MASK) { |
| 476 | case XFS_RMAP_EXTENT_MAP: |
| 477 | case XFS_RMAP_EXTENT_MAP_SHARED: |
| 478 | case XFS_RMAP_EXTENT_UNMAP: |
| 479 | case XFS_RMAP_EXTENT_UNMAP_SHARED: |
| 480 | case XFS_RMAP_EXTENT_CONVERT: |
| 481 | case XFS_RMAP_EXTENT_CONVERT_SHARED: |
| 482 | case XFS_RMAP_EXTENT_ALLOC: |
| 483 | case XFS_RMAP_EXTENT_FREE: |
Darrick J. Wong | dda7ba6 | 2020-11-29 16:33:36 -0800 | [diff] [blame] | 484 | break; |
| 485 | default: |
Darrick J. Wong | c447ad6 | 2020-11-29 16:33:37 -0800 | [diff] [blame] | 486 | return false; |
Darrick J. Wong | dda7ba6 | 2020-11-29 16:33:36 -0800 | [diff] [blame] | 487 | } |
Darrick J. Wong | c447ad6 | 2020-11-29 16:33:37 -0800 | [diff] [blame] | 488 | |
| 489 | if (!XFS_RMAP_NON_INODE_OWNER(rmap->me_owner) && |
| 490 | !xfs_verify_ino(mp, rmap->me_owner)) |
| 491 | return false; |
| 492 | |
Darrick J. Wong | 33005fd | 2020-12-04 13:28:35 -0800 | [diff] [blame] | 493 | if (!xfs_verify_fileext(mp, rmap->me_startoff, rmap->me_len)) |
Darrick J. Wong | c447ad6 | 2020-11-29 16:33:37 -0800 | [diff] [blame] | 494 | return false; |
| 495 | |
Darrick J. Wong | 67457eb | 2020-12-04 13:20:00 -0800 | [diff] [blame] | 496 | return xfs_verify_fsbext(mp, rmap->me_startblock, rmap->me_len); |
Darrick J. Wong | dda7ba6 | 2020-11-29 16:33:36 -0800 | [diff] [blame] | 497 | } |
| 498 | |
Darrick J. Wong | 9e88b5d | 2016-08-03 12:09:48 +1000 | [diff] [blame] | 499 | /* |
| 500 | * Process an rmap update intent item that was recovered from the log. |
| 501 | * We need to update the rmapbt. |
| 502 | */ |
Darrick J. Wong | cba0cca | 2020-05-01 16:00:51 -0700 | [diff] [blame] | 503 | STATIC int |
Darrick J. Wong | 96b60f8 | 2020-05-01 16:00:55 -0700 | [diff] [blame] | 504 | xfs_rui_item_recover( |
| 505 | struct xfs_log_item *lip, |
Darrick J. Wong | e6fff81 | 2020-09-25 17:39:37 -0700 | [diff] [blame] | 506 | struct list_head *capture_list) |
Darrick J. Wong | 9e88b5d | 2016-08-03 12:09:48 +1000 | [diff] [blame] | 507 | { |
Darrick J. Wong | 96b60f8 | 2020-05-01 16:00:55 -0700 | [diff] [blame] | 508 | struct xfs_rui_log_item *ruip = RUI_ITEM(lip); |
Darrick J. Wong | 9e88b5d | 2016-08-03 12:09:48 +1000 | [diff] [blame] | 509 | struct xfs_map_extent *rmap; |
Darrick J. Wong | 9c19464 | 2016-08-03 12:16:05 +1000 | [diff] [blame] | 510 | struct xfs_rud_log_item *rudp; |
Darrick J. Wong | 9c19464 | 2016-08-03 12:16:05 +1000 | [diff] [blame] | 511 | struct xfs_trans *tp; |
| 512 | struct xfs_btree_cur *rcur = NULL; |
Darrick J. Wong | e6fff81 | 2020-09-25 17:39:37 -0700 | [diff] [blame] | 513 | struct xfs_mount *mp = lip->li_mountp; |
Darrick J. Wong | 96b60f8 | 2020-05-01 16:00:55 -0700 | [diff] [blame] | 514 | enum xfs_rmap_intent_type type; |
| 515 | xfs_exntst_t state; |
Darrick J. Wong | 96b60f8 | 2020-05-01 16:00:55 -0700 | [diff] [blame] | 516 | int i; |
| 517 | int whichfork; |
| 518 | int error = 0; |
Darrick J. Wong | 9e88b5d | 2016-08-03 12:09:48 +1000 | [diff] [blame] | 519 | |
Darrick J. Wong | 9e88b5d | 2016-08-03 12:09:48 +1000 | [diff] [blame] | 520 | /* |
| 521 | * First check the validity of the extents described by the |
| 522 | * RUI. If any are bad, then assume that all are bad and |
| 523 | * just toss the RUI. |
| 524 | */ |
| 525 | for (i = 0; i < ruip->rui_format.rui_nextents; i++) { |
Darrick J. Wong | dda7ba6 | 2020-11-29 16:33:36 -0800 | [diff] [blame] | 526 | if (!xfs_rui_validate_map(mp, |
| 527 | &ruip->rui_format.rui_extents[i])) { |
| 528 | XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, |
| 529 | &ruip->rui_format, |
| 530 | sizeof(ruip->rui_format)); |
Darrick J. Wong | 895e196 | 2019-11-06 09:17:43 -0800 | [diff] [blame] | 531 | return -EFSCORRUPTED; |
Darrick J. Wong | dda7ba6 | 2020-11-29 16:33:36 -0800 | [diff] [blame] | 532 | } |
Darrick J. Wong | 9e88b5d | 2016-08-03 12:09:48 +1000 | [diff] [blame] | 533 | } |
| 534 | |
Darrick J. Wong | b31c2bd | 2018-02-22 14:41:25 -0800 | [diff] [blame] | 535 | error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, |
| 536 | mp->m_rmap_maxlevels, 0, XFS_TRANS_RESERVE, &tp); |
Darrick J. Wong | 9c19464 | 2016-08-03 12:16:05 +1000 | [diff] [blame] | 537 | if (error) |
| 538 | return error; |
Darrick J. Wong | 722e251 | 2016-08-03 12:28:43 +1000 | [diff] [blame] | 539 | rudp = xfs_trans_get_rud(tp, ruip); |
Darrick J. Wong | 9c19464 | 2016-08-03 12:16:05 +1000 | [diff] [blame] | 540 | |
| 541 | for (i = 0; i < ruip->rui_format.rui_nextents; i++) { |
Darrick J. Wong | e127faf | 2016-08-03 12:29:32 +1000 | [diff] [blame] | 542 | rmap = &ruip->rui_format.rui_extents[i]; |
Darrick J. Wong | 9c19464 | 2016-08-03 12:16:05 +1000 | [diff] [blame] | 543 | state = (rmap->me_flags & XFS_RMAP_EXTENT_UNWRITTEN) ? |
| 544 | XFS_EXT_UNWRITTEN : XFS_EXT_NORM; |
| 545 | whichfork = (rmap->me_flags & XFS_RMAP_EXTENT_ATTR_FORK) ? |
| 546 | XFS_ATTR_FORK : XFS_DATA_FORK; |
| 547 | switch (rmap->me_flags & XFS_RMAP_EXTENT_TYPE_MASK) { |
| 548 | case XFS_RMAP_EXTENT_MAP: |
| 549 | type = XFS_RMAP_MAP; |
| 550 | break; |
Darrick J. Wong | ceeb9c8 | 2016-10-03 09:11:48 -0700 | [diff] [blame] | 551 | case XFS_RMAP_EXTENT_MAP_SHARED: |
| 552 | type = XFS_RMAP_MAP_SHARED; |
| 553 | break; |
Darrick J. Wong | 9c19464 | 2016-08-03 12:16:05 +1000 | [diff] [blame] | 554 | case XFS_RMAP_EXTENT_UNMAP: |
| 555 | type = XFS_RMAP_UNMAP; |
| 556 | break; |
Darrick J. Wong | ceeb9c8 | 2016-10-03 09:11:48 -0700 | [diff] [blame] | 557 | case XFS_RMAP_EXTENT_UNMAP_SHARED: |
| 558 | type = XFS_RMAP_UNMAP_SHARED; |
| 559 | break; |
Darrick J. Wong | 9c19464 | 2016-08-03 12:16:05 +1000 | [diff] [blame] | 560 | case XFS_RMAP_EXTENT_CONVERT: |
| 561 | type = XFS_RMAP_CONVERT; |
| 562 | break; |
Darrick J. Wong | 3f165b3 | 2016-10-03 09:11:48 -0700 | [diff] [blame] | 563 | case XFS_RMAP_EXTENT_CONVERT_SHARED: |
| 564 | type = XFS_RMAP_CONVERT_SHARED; |
| 565 | break; |
Darrick J. Wong | 9c19464 | 2016-08-03 12:16:05 +1000 | [diff] [blame] | 566 | case XFS_RMAP_EXTENT_ALLOC: |
| 567 | type = XFS_RMAP_ALLOC; |
| 568 | break; |
| 569 | case XFS_RMAP_EXTENT_FREE: |
| 570 | type = XFS_RMAP_FREE; |
| 571 | break; |
| 572 | default: |
Darrick J. Wong | a5155b8 | 2019-11-02 09:40:53 -0700 | [diff] [blame] | 573 | XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, NULL); |
Darrick J. Wong | 9c19464 | 2016-08-03 12:16:05 +1000 | [diff] [blame] | 574 | error = -EFSCORRUPTED; |
| 575 | goto abort_error; |
| 576 | } |
| 577 | error = xfs_trans_log_finish_rmap_update(tp, rudp, type, |
| 578 | rmap->me_owner, whichfork, |
| 579 | rmap->me_startoff, rmap->me_startblock, |
| 580 | rmap->me_len, state, &rcur); |
Darrick J. Wong | 43059d5 | 2021-08-06 11:06:35 -0700 | [diff] [blame] | 581 | if (error == -EFSCORRUPTED) |
| 582 | XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, |
| 583 | rmap, sizeof(*rmap)); |
Darrick J. Wong | 9c19464 | 2016-08-03 12:16:05 +1000 | [diff] [blame] | 584 | if (error) |
| 585 | goto abort_error; |
| 586 | |
| 587 | } |
| 588 | |
| 589 | xfs_rmap_finish_one_cleanup(tp, rcur, error); |
Darrick J. Wong | 512edfa | 2021-09-16 17:28:07 -0700 | [diff] [blame] | 590 | return xfs_defer_ops_capture_and_commit(tp, capture_list); |
Darrick J. Wong | 9c19464 | 2016-08-03 12:16:05 +1000 | [diff] [blame] | 591 | |
| 592 | abort_error: |
| 593 | xfs_rmap_finish_one_cleanup(tp, rcur, error); |
| 594 | xfs_trans_cancel(tp); |
Darrick J. Wong | 9e88b5d | 2016-08-03 12:09:48 +1000 | [diff] [blame] | 595 | return error; |
| 596 | } |
Darrick J. Wong | 86ffa47 | 2020-05-01 16:00:45 -0700 | [diff] [blame] | 597 | |
Darrick J. Wong | 154c733 | 2020-05-01 16:00:54 -0700 | [diff] [blame] | 598 | STATIC bool |
| 599 | xfs_rui_item_match( |
| 600 | struct xfs_log_item *lip, |
| 601 | uint64_t intent_id) |
| 602 | { |
| 603 | return RUI_ITEM(lip)->rui_format.rui_id == intent_id; |
| 604 | } |
| 605 | |
Darrick J. Wong | 4e919af | 2020-09-27 16:18:13 -0700 | [diff] [blame] | 606 | /* Relog an intent item to push the log tail forward. */ |
| 607 | static struct xfs_log_item * |
| 608 | xfs_rui_item_relog( |
| 609 | struct xfs_log_item *intent, |
| 610 | struct xfs_trans *tp) |
| 611 | { |
| 612 | struct xfs_rud_log_item *rudp; |
| 613 | struct xfs_rui_log_item *ruip; |
| 614 | struct xfs_map_extent *extp; |
| 615 | unsigned int count; |
| 616 | |
| 617 | count = RUI_ITEM(intent)->rui_format.rui_nextents; |
| 618 | extp = RUI_ITEM(intent)->rui_format.rui_extents; |
| 619 | |
| 620 | tp->t_flags |= XFS_TRANS_DIRTY; |
| 621 | rudp = xfs_trans_get_rud(tp, RUI_ITEM(intent)); |
| 622 | set_bit(XFS_LI_DIRTY, &rudp->rud_item.li_flags); |
| 623 | |
| 624 | ruip = xfs_rui_init(tp->t_mountp, count); |
| 625 | memcpy(ruip->rui_format.rui_extents, extp, count * sizeof(*extp)); |
| 626 | atomic_set(&ruip->rui_next_extent, count); |
| 627 | xfs_trans_add_item(tp, &ruip->rui_item); |
| 628 | set_bit(XFS_LI_DIRTY, &ruip->rui_item.li_flags); |
| 629 | return &ruip->rui_item; |
| 630 | } |
| 631 | |
Darrick J. Wong | cba0cca | 2020-05-01 16:00:51 -0700 | [diff] [blame] | 632 | static const struct xfs_item_ops xfs_rui_item_ops = { |
| 633 | .iop_size = xfs_rui_item_size, |
| 634 | .iop_format = xfs_rui_item_format, |
| 635 | .iop_unpin = xfs_rui_item_unpin, |
| 636 | .iop_release = xfs_rui_item_release, |
| 637 | .iop_recover = xfs_rui_item_recover, |
Darrick J. Wong | 154c733 | 2020-05-01 16:00:54 -0700 | [diff] [blame] | 638 | .iop_match = xfs_rui_item_match, |
Darrick J. Wong | 4e919af | 2020-09-27 16:18:13 -0700 | [diff] [blame] | 639 | .iop_relog = xfs_rui_item_relog, |
Darrick J. Wong | cba0cca | 2020-05-01 16:00:51 -0700 | [diff] [blame] | 640 | }; |
| 641 | |
Darrick J. Wong | 07590a9 | 2020-05-01 16:00:49 -0700 | [diff] [blame] | 642 | /* |
| 643 | * This routine is called to create an in-core extent rmap update |
| 644 | * item from the rui format structure which was logged on disk. |
| 645 | * It allocates an in-core rui, copies the extents from the format |
| 646 | * structure into it, and adds the rui to the AIL with the given |
| 647 | * LSN. |
| 648 | */ |
| 649 | STATIC int |
| 650 | xlog_recover_rui_commit_pass2( |
| 651 | struct xlog *log, |
| 652 | struct list_head *buffer_list, |
| 653 | struct xlog_recover_item *item, |
| 654 | xfs_lsn_t lsn) |
| 655 | { |
| 656 | int error; |
| 657 | struct xfs_mount *mp = log->l_mp; |
| 658 | struct xfs_rui_log_item *ruip; |
| 659 | struct xfs_rui_log_format *rui_formatp; |
| 660 | |
| 661 | rui_formatp = item->ri_buf[0].i_addr; |
| 662 | |
| 663 | ruip = xfs_rui_init(mp, rui_formatp->rui_nextents); |
| 664 | error = xfs_rui_copy_format(&item->ri_buf[0], &ruip->rui_format); |
| 665 | if (error) { |
| 666 | xfs_rui_item_free(ruip); |
| 667 | return error; |
| 668 | } |
| 669 | atomic_set(&ruip->rui_next_extent, rui_formatp->rui_nextents); |
Darrick J. Wong | 07590a9 | 2020-05-01 16:00:49 -0700 | [diff] [blame] | 670 | /* |
Darrick J. Wong | 86a3717 | 2020-05-01 16:00:54 -0700 | [diff] [blame] | 671 | * Insert the intent into the AIL directly and drop one reference so |
| 672 | * that finishing or canceling the work will drop the other. |
Darrick J. Wong | 07590a9 | 2020-05-01 16:00:49 -0700 | [diff] [blame] | 673 | */ |
Darrick J. Wong | 86a3717 | 2020-05-01 16:00:54 -0700 | [diff] [blame] | 674 | xfs_trans_ail_insert(log->l_ailp, &ruip->rui_item, lsn); |
Darrick J. Wong | 07590a9 | 2020-05-01 16:00:49 -0700 | [diff] [blame] | 675 | xfs_rui_release(ruip); |
| 676 | return 0; |
| 677 | } |
| 678 | |
Darrick J. Wong | 86ffa47 | 2020-05-01 16:00:45 -0700 | [diff] [blame] | 679 | const struct xlog_recover_item_ops xlog_rui_item_ops = { |
| 680 | .item_type = XFS_LI_RUI, |
Darrick J. Wong | 07590a9 | 2020-05-01 16:00:49 -0700 | [diff] [blame] | 681 | .commit_pass2 = xlog_recover_rui_commit_pass2, |
Darrick J. Wong | 86ffa47 | 2020-05-01 16:00:45 -0700 | [diff] [blame] | 682 | }; |
| 683 | |
Darrick J. Wong | 07590a9 | 2020-05-01 16:00:49 -0700 | [diff] [blame] | 684 | /* |
| 685 | * This routine is called when an RUD format structure is found in a committed |
| 686 | * transaction in the log. Its purpose is to cancel the corresponding RUI if it |
| 687 | * was still in the log. To do this it searches the AIL for the RUI with an id |
| 688 | * equal to that in the RUD format structure. If we find it we drop the RUD |
| 689 | * reference, which removes the RUI from the AIL and frees it. |
| 690 | */ |
| 691 | STATIC int |
| 692 | xlog_recover_rud_commit_pass2( |
| 693 | struct xlog *log, |
| 694 | struct list_head *buffer_list, |
| 695 | struct xlog_recover_item *item, |
| 696 | xfs_lsn_t lsn) |
| 697 | { |
| 698 | struct xfs_rud_log_format *rud_formatp; |
Darrick J. Wong | 07590a9 | 2020-05-01 16:00:49 -0700 | [diff] [blame] | 699 | |
| 700 | rud_formatp = item->ri_buf[0].i_addr; |
| 701 | ASSERT(item->ri_buf[0].i_len == sizeof(struct xfs_rud_log_format)); |
Darrick J. Wong | 07590a9 | 2020-05-01 16:00:49 -0700 | [diff] [blame] | 702 | |
Darrick J. Wong | 154c733 | 2020-05-01 16:00:54 -0700 | [diff] [blame] | 703 | xlog_recover_release_intent(log, XFS_LI_RUI, rud_formatp->rud_rui_id); |
Darrick J. Wong | 07590a9 | 2020-05-01 16:00:49 -0700 | [diff] [blame] | 704 | return 0; |
| 705 | } |
| 706 | |
Darrick J. Wong | 86ffa47 | 2020-05-01 16:00:45 -0700 | [diff] [blame] | 707 | const struct xlog_recover_item_ops xlog_rud_item_ops = { |
| 708 | .item_type = XFS_LI_RUD, |
Darrick J. Wong | 07590a9 | 2020-05-01 16:00:49 -0700 | [diff] [blame] | 709 | .commit_pass2 = xlog_recover_rud_commit_pass2, |
Darrick J. Wong | 86ffa47 | 2020-05-01 16:00:45 -0700 | [diff] [blame] | 710 | }; |