Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2000-2005 Silicon Graphics, Inc. |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 3 | * Copyright (c) 2013 Red Hat, Inc. |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 4 | * All Rights Reserved. |
| 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 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it would be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write the Free Software Foundation, |
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | #include "xfs.h" |
| 20 | #include "xfs_fs.h" |
Dave Chinner | 632b89e | 2013-10-29 22:11:58 +1100 | [diff] [blame] | 21 | #include "xfs_shared.h" |
Dave Chinner | a4fbe6a | 2013-10-23 10:51:50 +1100 | [diff] [blame] | 22 | #include "xfs_format.h" |
Dave Chinner | 239880e | 2013-10-23 10:50:10 +1100 | [diff] [blame] | 23 | #include "xfs_log_format.h" |
| 24 | #include "xfs_trans_resv.h" |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 25 | #include "xfs_bit.h" |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 26 | #include "xfs_sb.h" |
| 27 | #include "xfs_ag.h" |
| 28 | #include "xfs_mount.h" |
Dave Chinner | 5706278 | 2013-10-15 09:17:51 +1100 | [diff] [blame] | 29 | #include "xfs_da_format.h" |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 30 | #include "xfs_da_btree.h" |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 31 | #include "xfs_inode.h" |
| 32 | #include "xfs_alloc.h" |
Dave Chinner | 239880e | 2013-10-23 10:50:10 +1100 | [diff] [blame] | 33 | #include "xfs_trans.h" |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 34 | #include "xfs_inode_item.h" |
| 35 | #include "xfs_bmap.h" |
Dave Chinner | 6898811 | 2013-08-12 20:49:42 +1000 | [diff] [blame] | 36 | #include "xfs_bmap_util.h" |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 37 | #include "xfs_attr.h" |
| 38 | #include "xfs_attr_leaf.h" |
| 39 | #include "xfs_attr_remote.h" |
| 40 | #include "xfs_trans_space.h" |
| 41 | #include "xfs_trace.h" |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 42 | #include "xfs_cksum.h" |
| 43 | #include "xfs_buf_item.h" |
Dave Chinner | a4fbe6a | 2013-10-23 10:51:50 +1100 | [diff] [blame] | 44 | #include "xfs_error.h" |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 45 | |
| 46 | #define ATTR_RMTVALUE_MAPSIZE 1 /* # of map entries at once */ |
| 47 | |
| 48 | /* |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 49 | * Each contiguous block has a header, so it is not just a simple attribute |
| 50 | * length to FSB conversion. |
| 51 | */ |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 52 | int |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 53 | xfs_attr3_rmt_blocks( |
| 54 | struct xfs_mount *mp, |
| 55 | int attrlen) |
| 56 | { |
Dave Chinner | 551b382 | 2013-05-21 18:02:02 +1000 | [diff] [blame] | 57 | if (xfs_sb_version_hascrc(&mp->m_sb)) { |
| 58 | int buflen = XFS_ATTR3_RMT_BUF_SPACE(mp, mp->m_sb.sb_blocksize); |
| 59 | return (attrlen + buflen - 1) / buflen; |
| 60 | } |
| 61 | return XFS_B_TO_FSB(mp, attrlen); |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 62 | } |
| 63 | |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 64 | /* |
| 65 | * Checking of the remote attribute header is split into two parts. The verifier |
| 66 | * does CRC, location and bounds checking, the unpacking function checks the |
| 67 | * attribute parameters and owner. |
| 68 | */ |
| 69 | static bool |
| 70 | xfs_attr3_rmt_hdr_ok( |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 71 | void *ptr, |
| 72 | xfs_ino_t ino, |
| 73 | uint32_t offset, |
| 74 | uint32_t size, |
| 75 | xfs_daddr_t bno) |
| 76 | { |
| 77 | struct xfs_attr3_rmt_hdr *rmt = ptr; |
| 78 | |
| 79 | if (bno != be64_to_cpu(rmt->rm_blkno)) |
| 80 | return false; |
| 81 | if (offset != be32_to_cpu(rmt->rm_offset)) |
| 82 | return false; |
| 83 | if (size != be32_to_cpu(rmt->rm_bytes)) |
| 84 | return false; |
| 85 | if (ino != be64_to_cpu(rmt->rm_owner)) |
| 86 | return false; |
| 87 | |
| 88 | /* ok */ |
| 89 | return true; |
| 90 | } |
| 91 | |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 92 | static bool |
| 93 | xfs_attr3_rmt_verify( |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 94 | struct xfs_mount *mp, |
| 95 | void *ptr, |
| 96 | int fsbsize, |
| 97 | xfs_daddr_t bno) |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 98 | { |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 99 | struct xfs_attr3_rmt_hdr *rmt = ptr; |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 100 | |
| 101 | if (!xfs_sb_version_hascrc(&mp->m_sb)) |
| 102 | return false; |
| 103 | if (rmt->rm_magic != cpu_to_be32(XFS_ATTR3_RMT_MAGIC)) |
| 104 | return false; |
| 105 | if (!uuid_equal(&rmt->rm_uuid, &mp->m_sb.sb_uuid)) |
| 106 | return false; |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 107 | if (be64_to_cpu(rmt->rm_blkno) != bno) |
| 108 | return false; |
| 109 | if (be32_to_cpu(rmt->rm_bytes) > fsbsize - sizeof(*rmt)) |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 110 | return false; |
| 111 | if (be32_to_cpu(rmt->rm_offset) + |
Jie Liu | bba719b | 2014-01-01 19:28:03 +0800 | [diff] [blame] | 112 | be32_to_cpu(rmt->rm_bytes) > XATTR_SIZE_MAX) |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 113 | return false; |
| 114 | if (rmt->rm_owner == 0) |
| 115 | return false; |
| 116 | |
| 117 | return true; |
| 118 | } |
| 119 | |
| 120 | static void |
| 121 | xfs_attr3_rmt_read_verify( |
| 122 | struct xfs_buf *bp) |
| 123 | { |
| 124 | struct xfs_mount *mp = bp->b_target->bt_mount; |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 125 | char *ptr; |
| 126 | int len; |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 127 | xfs_daddr_t bno; |
Dave Chinner | c2c4c47 | 2014-06-06 15:21:45 +1000 | [diff] [blame] | 128 | int blksize = mp->m_attr_geo->blksize; |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 129 | |
| 130 | /* no verification of non-crc buffers */ |
| 131 | if (!xfs_sb_version_hascrc(&mp->m_sb)) |
| 132 | return; |
| 133 | |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 134 | ptr = bp->b_addr; |
| 135 | bno = bp->b_bn; |
| 136 | len = BBTOB(bp->b_length); |
Dave Chinner | c2c4c47 | 2014-06-06 15:21:45 +1000 | [diff] [blame] | 137 | ASSERT(len >= blksize); |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 138 | |
| 139 | while (len > 0) { |
Dave Chinner | c2c4c47 | 2014-06-06 15:21:45 +1000 | [diff] [blame] | 140 | if (!xfs_verify_cksum(ptr, blksize, XFS_ATTR3_RMT_CRC_OFF)) { |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame^] | 141 | xfs_buf_ioerror(bp, -EFSBADCRC); |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 142 | break; |
| 143 | } |
Dave Chinner | c2c4c47 | 2014-06-06 15:21:45 +1000 | [diff] [blame] | 144 | if (!xfs_attr3_rmt_verify(mp, ptr, blksize, bno)) { |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame^] | 145 | xfs_buf_ioerror(bp, -EFSCORRUPTED); |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 146 | break; |
| 147 | } |
Dave Chinner | c2c4c47 | 2014-06-06 15:21:45 +1000 | [diff] [blame] | 148 | len -= blksize; |
| 149 | ptr += blksize; |
| 150 | bno += BTOBB(blksize); |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 151 | } |
| 152 | |
Eric Sandeen | ce5028c | 2014-02-27 15:23:10 +1100 | [diff] [blame] | 153 | if (bp->b_error) |
| 154 | xfs_verifier_error(bp); |
| 155 | else |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 156 | ASSERT(len == 0); |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | static void |
| 160 | xfs_attr3_rmt_write_verify( |
| 161 | struct xfs_buf *bp) |
| 162 | { |
| 163 | struct xfs_mount *mp = bp->b_target->bt_mount; |
| 164 | struct xfs_buf_log_item *bip = bp->b_fspriv; |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 165 | char *ptr; |
| 166 | int len; |
| 167 | xfs_daddr_t bno; |
Dave Chinner | c2c4c47 | 2014-06-06 15:21:45 +1000 | [diff] [blame] | 168 | int blksize = mp->m_attr_geo->blksize; |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 169 | |
| 170 | /* no verification of non-crc buffers */ |
| 171 | if (!xfs_sb_version_hascrc(&mp->m_sb)) |
| 172 | return; |
| 173 | |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 174 | ptr = bp->b_addr; |
| 175 | bno = bp->b_bn; |
| 176 | len = BBTOB(bp->b_length); |
Dave Chinner | c2c4c47 | 2014-06-06 15:21:45 +1000 | [diff] [blame] | 177 | ASSERT(len >= blksize); |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 178 | |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 179 | while (len > 0) { |
Dave Chinner | c2c4c47 | 2014-06-06 15:21:45 +1000 | [diff] [blame] | 180 | if (!xfs_attr3_rmt_verify(mp, ptr, blksize, bno)) { |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame^] | 181 | xfs_buf_ioerror(bp, -EFSCORRUPTED); |
Eric Sandeen | ce5028c | 2014-02-27 15:23:10 +1100 | [diff] [blame] | 182 | xfs_verifier_error(bp); |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 183 | return; |
| 184 | } |
| 185 | if (bip) { |
| 186 | struct xfs_attr3_rmt_hdr *rmt; |
| 187 | |
| 188 | rmt = (struct xfs_attr3_rmt_hdr *)ptr; |
| 189 | rmt->rm_lsn = cpu_to_be64(bip->bli_item.li_lsn); |
| 190 | } |
Dave Chinner | c2c4c47 | 2014-06-06 15:21:45 +1000 | [diff] [blame] | 191 | xfs_update_cksum(ptr, blksize, XFS_ATTR3_RMT_CRC_OFF); |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 192 | |
Dave Chinner | c2c4c47 | 2014-06-06 15:21:45 +1000 | [diff] [blame] | 193 | len -= blksize; |
| 194 | ptr += blksize; |
| 195 | bno += BTOBB(blksize); |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 196 | } |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 197 | ASSERT(len == 0); |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | const struct xfs_buf_ops xfs_attr3_rmt_buf_ops = { |
| 201 | .verify_read = xfs_attr3_rmt_read_verify, |
| 202 | .verify_write = xfs_attr3_rmt_write_verify, |
| 203 | }; |
| 204 | |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 205 | STATIC int |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 206 | xfs_attr3_rmt_hdr_set( |
| 207 | struct xfs_mount *mp, |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 208 | void *ptr, |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 209 | xfs_ino_t ino, |
| 210 | uint32_t offset, |
| 211 | uint32_t size, |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 212 | xfs_daddr_t bno) |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 213 | { |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 214 | struct xfs_attr3_rmt_hdr *rmt = ptr; |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 215 | |
| 216 | if (!xfs_sb_version_hascrc(&mp->m_sb)) |
| 217 | return 0; |
| 218 | |
| 219 | rmt->rm_magic = cpu_to_be32(XFS_ATTR3_RMT_MAGIC); |
| 220 | rmt->rm_offset = cpu_to_be32(offset); |
| 221 | rmt->rm_bytes = cpu_to_be32(size); |
| 222 | uuid_copy(&rmt->rm_uuid, &mp->m_sb.sb_uuid); |
| 223 | rmt->rm_owner = cpu_to_be64(ino); |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 224 | rmt->rm_blkno = cpu_to_be64(bno); |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 225 | |
| 226 | return sizeof(struct xfs_attr3_rmt_hdr); |
| 227 | } |
| 228 | |
| 229 | /* |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 230 | * Helper functions to copy attribute data in and out of the one disk extents |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 231 | */ |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 232 | STATIC int |
| 233 | xfs_attr_rmtval_copyout( |
| 234 | struct xfs_mount *mp, |
| 235 | struct xfs_buf *bp, |
| 236 | xfs_ino_t ino, |
| 237 | int *offset, |
| 238 | int *valuelen, |
Dave Chinner | 836a94a | 2013-08-12 20:49:44 +1000 | [diff] [blame] | 239 | __uint8_t **dst) |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 240 | { |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 241 | char *src = bp->b_addr; |
| 242 | xfs_daddr_t bno = bp->b_bn; |
| 243 | int len = BBTOB(bp->b_length); |
Dave Chinner | c2c4c47 | 2014-06-06 15:21:45 +1000 | [diff] [blame] | 244 | int blksize = mp->m_attr_geo->blksize; |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 245 | |
Dave Chinner | c2c4c47 | 2014-06-06 15:21:45 +1000 | [diff] [blame] | 246 | ASSERT(len >= blksize); |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 247 | |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 248 | while (len > 0 && *valuelen > 0) { |
| 249 | int hdr_size = 0; |
Dave Chinner | c2c4c47 | 2014-06-06 15:21:45 +1000 | [diff] [blame] | 250 | int byte_cnt = XFS_ATTR3_RMT_BUF_SPACE(mp, blksize); |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 251 | |
Dave Chinner | c5c249b | 2013-08-12 20:49:43 +1000 | [diff] [blame] | 252 | byte_cnt = min(*valuelen, byte_cnt); |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 253 | |
| 254 | if (xfs_sb_version_hascrc(&mp->m_sb)) { |
Eric Sandeen | 6d0081a | 2014-04-14 18:58:29 +1000 | [diff] [blame] | 255 | if (!xfs_attr3_rmt_hdr_ok(src, ino, *offset, |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 256 | byte_cnt, bno)) { |
| 257 | xfs_alert(mp, |
| 258 | "remote attribute header mismatch bno/off/len/owner (0x%llx/0x%x/Ox%x/0x%llx)", |
| 259 | bno, *offset, byte_cnt, ino); |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame^] | 260 | return -EFSCORRUPTED; |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 261 | } |
| 262 | hdr_size = sizeof(struct xfs_attr3_rmt_hdr); |
| 263 | } |
| 264 | |
| 265 | memcpy(*dst, src + hdr_size, byte_cnt); |
| 266 | |
| 267 | /* roll buffer forwards */ |
Dave Chinner | c2c4c47 | 2014-06-06 15:21:45 +1000 | [diff] [blame] | 268 | len -= blksize; |
| 269 | src += blksize; |
| 270 | bno += BTOBB(blksize); |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 271 | |
| 272 | /* roll attribute data forwards */ |
| 273 | *valuelen -= byte_cnt; |
| 274 | *dst += byte_cnt; |
| 275 | *offset += byte_cnt; |
| 276 | } |
| 277 | return 0; |
| 278 | } |
| 279 | |
| 280 | STATIC void |
| 281 | xfs_attr_rmtval_copyin( |
| 282 | struct xfs_mount *mp, |
| 283 | struct xfs_buf *bp, |
| 284 | xfs_ino_t ino, |
| 285 | int *offset, |
| 286 | int *valuelen, |
Dave Chinner | 836a94a | 2013-08-12 20:49:44 +1000 | [diff] [blame] | 287 | __uint8_t **src) |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 288 | { |
| 289 | char *dst = bp->b_addr; |
| 290 | xfs_daddr_t bno = bp->b_bn; |
| 291 | int len = BBTOB(bp->b_length); |
Dave Chinner | c2c4c47 | 2014-06-06 15:21:45 +1000 | [diff] [blame] | 292 | int blksize = mp->m_attr_geo->blksize; |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 293 | |
Dave Chinner | c2c4c47 | 2014-06-06 15:21:45 +1000 | [diff] [blame] | 294 | ASSERT(len >= blksize); |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 295 | |
| 296 | while (len > 0 && *valuelen > 0) { |
| 297 | int hdr_size; |
Dave Chinner | c2c4c47 | 2014-06-06 15:21:45 +1000 | [diff] [blame] | 298 | int byte_cnt = XFS_ATTR3_RMT_BUF_SPACE(mp, blksize); |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 299 | |
| 300 | byte_cnt = min(*valuelen, byte_cnt); |
| 301 | hdr_size = xfs_attr3_rmt_hdr_set(mp, dst, ino, *offset, |
| 302 | byte_cnt, bno); |
| 303 | |
| 304 | memcpy(dst + hdr_size, *src, byte_cnt); |
| 305 | |
| 306 | /* |
| 307 | * If this is the last block, zero the remainder of it. |
| 308 | * Check that we are actually the last block, too. |
| 309 | */ |
Dave Chinner | c2c4c47 | 2014-06-06 15:21:45 +1000 | [diff] [blame] | 310 | if (byte_cnt + hdr_size < blksize) { |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 311 | ASSERT(*valuelen - byte_cnt == 0); |
Dave Chinner | c2c4c47 | 2014-06-06 15:21:45 +1000 | [diff] [blame] | 312 | ASSERT(len == blksize); |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 313 | memset(dst + hdr_size + byte_cnt, 0, |
Dave Chinner | c2c4c47 | 2014-06-06 15:21:45 +1000 | [diff] [blame] | 314 | blksize - hdr_size - byte_cnt); |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | /* roll buffer forwards */ |
Dave Chinner | c2c4c47 | 2014-06-06 15:21:45 +1000 | [diff] [blame] | 318 | len -= blksize; |
| 319 | dst += blksize; |
| 320 | bno += BTOBB(blksize); |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 321 | |
| 322 | /* roll attribute data forwards */ |
| 323 | *valuelen -= byte_cnt; |
| 324 | *src += byte_cnt; |
| 325 | *offset += byte_cnt; |
| 326 | } |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | /* |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 330 | * Read the value associated with an attribute from the out-of-line buffer |
| 331 | * that we stored it in. |
| 332 | */ |
| 333 | int |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 334 | xfs_attr_rmtval_get( |
| 335 | struct xfs_da_args *args) |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 336 | { |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 337 | struct xfs_bmbt_irec map[ATTR_RMTVALUE_MAPSIZE]; |
| 338 | struct xfs_mount *mp = args->dp->i_mount; |
| 339 | struct xfs_buf *bp; |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 340 | xfs_dablk_t lblkno = args->rmtblkno; |
Dave Chinner | 836a94a | 2013-08-12 20:49:44 +1000 | [diff] [blame] | 341 | __uint8_t *dst = args->value; |
Dave Chinner | 8275cdd | 2014-05-06 07:37:31 +1000 | [diff] [blame] | 342 | int valuelen; |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 343 | int nmap; |
| 344 | int error; |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 345 | int blkcnt = args->rmtblkcnt; |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 346 | int i; |
| 347 | int offset = 0; |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 348 | |
| 349 | trace_xfs_attr_rmtval_get(args); |
| 350 | |
| 351 | ASSERT(!(args->flags & ATTR_KERNOVAL)); |
Dave Chinner | 8275cdd | 2014-05-06 07:37:31 +1000 | [diff] [blame] | 352 | ASSERT(args->rmtvaluelen == args->valuelen); |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 353 | |
Dave Chinner | 8275cdd | 2014-05-06 07:37:31 +1000 | [diff] [blame] | 354 | valuelen = args->rmtvaluelen; |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 355 | while (valuelen > 0) { |
| 356 | nmap = ATTR_RMTVALUE_MAPSIZE; |
| 357 | error = xfs_bmapi_read(args->dp, (xfs_fileoff_t)lblkno, |
Dave Chinner | 551b382 | 2013-05-21 18:02:02 +1000 | [diff] [blame] | 358 | blkcnt, map, &nmap, |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 359 | XFS_BMAPI_ATTRFORK); |
| 360 | if (error) |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 361 | return error; |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 362 | ASSERT(nmap >= 1); |
| 363 | |
| 364 | for (i = 0; (i < nmap) && (valuelen > 0); i++) { |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 365 | xfs_daddr_t dblkno; |
| 366 | int dblkcnt; |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 367 | |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 368 | ASSERT((map[i].br_startblock != DELAYSTARTBLOCK) && |
| 369 | (map[i].br_startblock != HOLESTARTBLOCK)); |
| 370 | dblkno = XFS_FSB_TO_DADDR(mp, map[i].br_startblock); |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 371 | dblkcnt = XFS_FSB_TO_BB(mp, map[i].br_blockcount); |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 372 | error = xfs_trans_read_buf(mp, NULL, mp->m_ddev_targp, |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 373 | dblkno, dblkcnt, 0, &bp, |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 374 | &xfs_attr3_rmt_buf_ops); |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 375 | if (error) |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 376 | return error; |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 377 | |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 378 | error = xfs_attr_rmtval_copyout(mp, bp, args->dp->i_ino, |
| 379 | &offset, &valuelen, |
| 380 | &dst); |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 381 | xfs_buf_relse(bp); |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 382 | if (error) |
| 383 | return error; |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 384 | |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 385 | /* roll attribute extent map forwards */ |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 386 | lblkno += map[i].br_blockcount; |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 387 | blkcnt -= map[i].br_blockcount; |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 388 | } |
| 389 | } |
| 390 | ASSERT(valuelen == 0); |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 391 | return 0; |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | /* |
| 395 | * Write the value associated with an attribute into the out-of-line buffer |
| 396 | * that we have defined for it. |
| 397 | */ |
| 398 | int |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 399 | xfs_attr_rmtval_set( |
| 400 | struct xfs_da_args *args) |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 401 | { |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 402 | struct xfs_inode *dp = args->dp; |
| 403 | struct xfs_mount *mp = dp->i_mount; |
| 404 | struct xfs_bmbt_irec map; |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 405 | xfs_dablk_t lblkno; |
| 406 | xfs_fileoff_t lfileoff = 0; |
Dave Chinner | 836a94a | 2013-08-12 20:49:44 +1000 | [diff] [blame] | 407 | __uint8_t *src = args->value; |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 408 | int blkcnt; |
| 409 | int valuelen; |
| 410 | int nmap; |
| 411 | int error; |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 412 | int offset = 0; |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 413 | |
| 414 | trace_xfs_attr_rmtval_set(args); |
| 415 | |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 416 | /* |
| 417 | * Find a "hole" in the attribute address space large enough for |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 418 | * us to drop the new attribute's value into. Because CRC enable |
| 419 | * attributes have headers, we can't just do a straight byte to FSB |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 420 | * conversion and have to take the header space into account. |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 421 | */ |
Dave Chinner | 8275cdd | 2014-05-06 07:37:31 +1000 | [diff] [blame] | 422 | blkcnt = xfs_attr3_rmt_blocks(mp, args->rmtvaluelen); |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 423 | error = xfs_bmap_first_unused(args->trans, args->dp, blkcnt, &lfileoff, |
| 424 | XFS_ATTR_FORK); |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 425 | if (error) |
| 426 | return error; |
| 427 | |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 428 | args->rmtblkno = lblkno = (xfs_dablk_t)lfileoff; |
| 429 | args->rmtblkcnt = blkcnt; |
| 430 | |
| 431 | /* |
| 432 | * Roll through the "value", allocating blocks on disk as required. |
| 433 | */ |
| 434 | while (blkcnt > 0) { |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 435 | int committed; |
| 436 | |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 437 | /* |
| 438 | * Allocate a single extent, up to the size of the value. |
| 439 | */ |
| 440 | xfs_bmap_init(args->flist, args->firstblock); |
| 441 | nmap = 1; |
| 442 | error = xfs_bmapi_write(args->trans, dp, (xfs_fileoff_t)lblkno, |
| 443 | blkcnt, |
| 444 | XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA, |
| 445 | args->firstblock, args->total, &map, &nmap, |
| 446 | args->flist); |
| 447 | if (!error) { |
| 448 | error = xfs_bmap_finish(&args->trans, args->flist, |
| 449 | &committed); |
| 450 | } |
| 451 | if (error) { |
| 452 | ASSERT(committed); |
| 453 | args->trans = NULL; |
| 454 | xfs_bmap_cancel(args->flist); |
Eric Sandeen | d99831f | 2014-06-22 15:03:54 +1000 | [diff] [blame] | 455 | return error; |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | /* |
| 459 | * bmap_finish() may have committed the last trans and started |
| 460 | * a new one. We need the inode to be in all transactions. |
| 461 | */ |
| 462 | if (committed) |
| 463 | xfs_trans_ijoin(args->trans, dp, 0); |
| 464 | |
| 465 | ASSERT(nmap == 1); |
| 466 | ASSERT((map.br_startblock != DELAYSTARTBLOCK) && |
| 467 | (map.br_startblock != HOLESTARTBLOCK)); |
| 468 | lblkno += map.br_blockcount; |
| 469 | blkcnt -= map.br_blockcount; |
| 470 | |
| 471 | /* |
| 472 | * Start the next trans in the chain. |
| 473 | */ |
| 474 | error = xfs_trans_roll(&args->trans, dp); |
| 475 | if (error) |
Eric Sandeen | d99831f | 2014-06-22 15:03:54 +1000 | [diff] [blame] | 476 | return error; |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | /* |
| 480 | * Roll through the "value", copying the attribute value to the |
| 481 | * already-allocated blocks. Blocks are written synchronously |
| 482 | * so that we can know they are all on disk before we turn off |
| 483 | * the INCOMPLETE flag. |
| 484 | */ |
| 485 | lblkno = args->rmtblkno; |
Dave Chinner | 26f7144 | 2013-05-21 18:02:03 +1000 | [diff] [blame] | 486 | blkcnt = args->rmtblkcnt; |
Dave Chinner | 8275cdd | 2014-05-06 07:37:31 +1000 | [diff] [blame] | 487 | valuelen = args->rmtvaluelen; |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 488 | while (valuelen > 0) { |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 489 | struct xfs_buf *bp; |
| 490 | xfs_daddr_t dblkno; |
| 491 | int dblkcnt; |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 492 | |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 493 | ASSERT(blkcnt > 0); |
| 494 | |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 495 | xfs_bmap_init(args->flist, args->firstblock); |
| 496 | nmap = 1; |
| 497 | error = xfs_bmapi_read(dp, (xfs_fileoff_t)lblkno, |
Dave Chinner | 26f7144 | 2013-05-21 18:02:03 +1000 | [diff] [blame] | 498 | blkcnt, &map, &nmap, |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 499 | XFS_BMAPI_ATTRFORK); |
| 500 | if (error) |
Eric Sandeen | d99831f | 2014-06-22 15:03:54 +1000 | [diff] [blame] | 501 | return error; |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 502 | ASSERT(nmap == 1); |
| 503 | ASSERT((map.br_startblock != DELAYSTARTBLOCK) && |
| 504 | (map.br_startblock != HOLESTARTBLOCK)); |
| 505 | |
| 506 | dblkno = XFS_FSB_TO_DADDR(mp, map.br_startblock), |
Dave Chinner | 26f7144 | 2013-05-21 18:02:03 +1000 | [diff] [blame] | 507 | dblkcnt = XFS_FSB_TO_BB(mp, map.br_blockcount); |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 508 | |
Dave Chinner | 26f7144 | 2013-05-21 18:02:03 +1000 | [diff] [blame] | 509 | bp = xfs_buf_get(mp->m_ddev_targp, dblkno, dblkcnt, 0); |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 510 | if (!bp) |
Dave Chinner | 2451337 | 2014-06-25 14:58:08 +1000 | [diff] [blame^] | 511 | return -ENOMEM; |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 512 | bp->b_ops = &xfs_attr3_rmt_buf_ops; |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 513 | |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 514 | xfs_attr_rmtval_copyin(mp, bp, args->dp->i_ino, &offset, |
| 515 | &valuelen, &src); |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 516 | |
| 517 | error = xfs_bwrite(bp); /* GROT: NOTE: synchronous write */ |
| 518 | xfs_buf_relse(bp); |
| 519 | if (error) |
| 520 | return error; |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 521 | |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 522 | |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 523 | /* roll attribute extent map forwards */ |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 524 | lblkno += map.br_blockcount; |
Dave Chinner | 26f7144 | 2013-05-21 18:02:03 +1000 | [diff] [blame] | 525 | blkcnt -= map.br_blockcount; |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 526 | } |
| 527 | ASSERT(valuelen == 0); |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 528 | return 0; |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | /* |
| 532 | * Remove the value associated with an attribute by deleting the |
| 533 | * out-of-line buffer that it is stored on. |
| 534 | */ |
| 535 | int |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 536 | xfs_attr_rmtval_remove( |
| 537 | struct xfs_da_args *args) |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 538 | { |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 539 | struct xfs_mount *mp = args->dp->i_mount; |
| 540 | xfs_dablk_t lblkno; |
| 541 | int blkcnt; |
| 542 | int error; |
| 543 | int done; |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 544 | |
| 545 | trace_xfs_attr_rmtval_remove(args); |
| 546 | |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 547 | /* |
Dave Chinner | 58a7228 | 2013-05-21 18:02:04 +1000 | [diff] [blame] | 548 | * Roll through the "value", invalidating the attribute value's blocks. |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 549 | */ |
| 550 | lblkno = args->rmtblkno; |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 551 | blkcnt = args->rmtblkcnt; |
| 552 | while (blkcnt > 0) { |
| 553 | struct xfs_bmbt_irec map; |
| 554 | struct xfs_buf *bp; |
| 555 | xfs_daddr_t dblkno; |
| 556 | int dblkcnt; |
| 557 | int nmap; |
Dave Chinner | 58a7228 | 2013-05-21 18:02:04 +1000 | [diff] [blame] | 558 | |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 559 | /* |
| 560 | * Try to remember where we decided to put the value. |
| 561 | */ |
| 562 | nmap = 1; |
| 563 | error = xfs_bmapi_read(args->dp, (xfs_fileoff_t)lblkno, |
Dave Chinner | 58a7228 | 2013-05-21 18:02:04 +1000 | [diff] [blame] | 564 | blkcnt, &map, &nmap, XFS_BMAPI_ATTRFORK); |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 565 | if (error) |
Eric Sandeen | d99831f | 2014-06-22 15:03:54 +1000 | [diff] [blame] | 566 | return error; |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 567 | ASSERT(nmap == 1); |
| 568 | ASSERT((map.br_startblock != DELAYSTARTBLOCK) && |
| 569 | (map.br_startblock != HOLESTARTBLOCK)); |
| 570 | |
| 571 | dblkno = XFS_FSB_TO_DADDR(mp, map.br_startblock), |
Dave Chinner | 58a7228 | 2013-05-21 18:02:04 +1000 | [diff] [blame] | 572 | dblkcnt = XFS_FSB_TO_BB(mp, map.br_blockcount); |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 573 | |
| 574 | /* |
| 575 | * If the "remote" value is in the cache, remove it. |
| 576 | */ |
Dave Chinner | 58a7228 | 2013-05-21 18:02:04 +1000 | [diff] [blame] | 577 | bp = xfs_incore(mp->m_ddev_targp, dblkno, dblkcnt, XBF_TRYLOCK); |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 578 | if (bp) { |
| 579 | xfs_buf_stale(bp); |
| 580 | xfs_buf_relse(bp); |
| 581 | bp = NULL; |
| 582 | } |
| 583 | |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 584 | lblkno += map.br_blockcount; |
Dave Chinner | 58a7228 | 2013-05-21 18:02:04 +1000 | [diff] [blame] | 585 | blkcnt -= map.br_blockcount; |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | /* |
| 589 | * Keep de-allocating extents until the remote-value region is gone. |
| 590 | */ |
| 591 | lblkno = args->rmtblkno; |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 592 | blkcnt = args->rmtblkcnt; |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 593 | done = 0; |
| 594 | while (!done) { |
Dave Chinner | 7bc0dc2 | 2013-05-21 18:02:08 +1000 | [diff] [blame] | 595 | int committed; |
| 596 | |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 597 | xfs_bmap_init(args->flist, args->firstblock); |
| 598 | error = xfs_bunmapi(args->trans, args->dp, lblkno, blkcnt, |
| 599 | XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA, |
| 600 | 1, args->firstblock, args->flist, |
| 601 | &done); |
| 602 | if (!error) { |
| 603 | error = xfs_bmap_finish(&args->trans, args->flist, |
| 604 | &committed); |
| 605 | } |
| 606 | if (error) { |
| 607 | ASSERT(committed); |
| 608 | args->trans = NULL; |
| 609 | xfs_bmap_cancel(args->flist); |
Dave Chinner | d2e448d | 2013-04-03 16:11:28 +1100 | [diff] [blame] | 610 | return error; |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | /* |
| 614 | * bmap_finish() may have committed the last trans and started |
| 615 | * a new one. We need the inode to be in all transactions. |
| 616 | */ |
| 617 | if (committed) |
| 618 | xfs_trans_ijoin(args->trans, args->dp, 0); |
| 619 | |
| 620 | /* |
| 621 | * Close out trans and start the next one in the chain. |
| 622 | */ |
| 623 | error = xfs_trans_roll(&args->trans, args->dp); |
| 624 | if (error) |
Eric Sandeen | d99831f | 2014-06-22 15:03:54 +1000 | [diff] [blame] | 625 | return error; |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 626 | } |
Eric Sandeen | d99831f | 2014-06-22 15:03:54 +1000 | [diff] [blame] | 627 | return 0; |
Dave Chinner | 95920cd | 2013-04-03 16:11:27 +1100 | [diff] [blame] | 628 | } |