Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'xfs-misc-fixes-for-3.19-2' into for-next

Conflicts:
fs/xfs/xfs_iops.c

+270 -385
+25 -43
fs/xfs/libxfs/xfs_bmap.c
··· 5447 5447 struct xfs_btree_cur *cur, 5448 5448 int *logflags) /* output */ 5449 5449 { 5450 - struct xfs_ifork *ifp; 5451 5450 struct xfs_bmbt_irec got; 5452 5451 struct xfs_bmbt_irec left; 5453 5452 xfs_filblks_t blockcount; 5454 5453 int error, i; 5455 5454 5456 - ifp = XFS_IFORK_PTR(ip, whichfork); 5457 5455 xfs_bmbt_get_all(gotp, &got); 5458 5456 xfs_bmbt_get_all(leftp, &left); 5459 5457 blockcount = left.br_blockcount + got.br_blockcount; ··· 5484 5486 error = xfs_bmbt_lookup_eq(cur, got.br_startoff, got.br_startblock, 5485 5487 got.br_blockcount, &i); 5486 5488 if (error) 5487 - goto out_error; 5488 - XFS_WANT_CORRUPTED_GOTO(i == 1, out_error); 5489 + return error; 5490 + XFS_WANT_CORRUPTED_RETURN(i == 1); 5489 5491 5490 5492 error = xfs_btree_delete(cur, &i); 5491 5493 if (error) 5492 - goto out_error; 5493 - XFS_WANT_CORRUPTED_GOTO(i == 1, out_error); 5494 + return error; 5495 + XFS_WANT_CORRUPTED_RETURN(i == 1); 5494 5496 5495 5497 /* lookup and update size of the previous extent */ 5496 5498 error = xfs_bmbt_lookup_eq(cur, left.br_startoff, left.br_startblock, 5497 5499 left.br_blockcount, &i); 5498 5500 if (error) 5499 - goto out_error; 5500 - XFS_WANT_CORRUPTED_GOTO(i == 1, out_error); 5501 + return error; 5502 + XFS_WANT_CORRUPTED_RETURN(i == 1); 5501 5503 5502 5504 left.br_blockcount = blockcount; 5503 5505 5504 - error = xfs_bmbt_update(cur, left.br_startoff, left.br_startblock, 5505 - left.br_blockcount, left.br_state); 5506 - if (error) 5507 - goto out_error; 5508 - 5509 - return 0; 5510 - 5511 - out_error: 5512 - return error; 5506 + return xfs_bmbt_update(cur, left.br_startoff, left.br_startblock, 5507 + left.br_blockcount, left.br_state); 5513 5508 } 5514 5509 5515 5510 /* ··· 5532 5541 startoff = got.br_startoff - offset_shift_fsb; 5533 5542 5534 5543 /* delalloc extents should be prevented by caller */ 5535 - XFS_WANT_CORRUPTED_GOTO(!isnullstartblock(got.br_startblock), 5536 - out_error); 5544 + XFS_WANT_CORRUPTED_RETURN(!isnullstartblock(got.br_startblock)); 5537 5545 5538 5546 /* 5539 - * If this is the first extent in the file, make sure there's enough 5540 - * room at the start of the file and jump right to the shift as there's 5541 - * no left extent to merge. 5547 + * Check for merge if we've got an extent to the left, otherwise make 5548 + * sure there's enough room at the start of the file for the shift. 5542 5549 */ 5543 - if (*current_ext == 0) { 5544 - if (got.br_startoff < offset_shift_fsb) 5550 + if (*current_ext) { 5551 + /* grab the left extent and check for a large enough hole */ 5552 + leftp = xfs_iext_get_ext(ifp, *current_ext - 1); 5553 + xfs_bmbt_get_all(leftp, &left); 5554 + 5555 + if (startoff < left.br_startoff + left.br_blockcount) 5545 5556 return -EINVAL; 5546 - goto shift_extent; 5547 - } 5548 5557 5549 - /* grab the left extent and check for a large enough hole */ 5550 - leftp = xfs_iext_get_ext(ifp, *current_ext - 1); 5551 - xfs_bmbt_get_all(leftp, &left); 5552 - 5553 - if (startoff < left.br_startoff + left.br_blockcount) 5558 + /* check whether to merge the extent or shift it down */ 5559 + if (xfs_bmse_can_merge(&left, &got, offset_shift_fsb)) { 5560 + return xfs_bmse_merge(ip, whichfork, offset_shift_fsb, 5561 + *current_ext, gotp, leftp, cur, 5562 + logflags); 5563 + } 5564 + } else if (got.br_startoff < offset_shift_fsb) 5554 5565 return -EINVAL; 5555 5566 5556 - /* check whether to merge the extent or shift it down */ 5557 - if (!xfs_bmse_can_merge(&left, &got, offset_shift_fsb)) 5558 - goto shift_extent; 5559 - 5560 - return xfs_bmse_merge(ip, whichfork, offset_shift_fsb, *current_ext, 5561 - gotp, leftp, cur, logflags); 5562 - 5563 - shift_extent: 5564 5567 /* 5565 5568 * Increment the extent index for the next iteration, update the start 5566 5569 * offset of the in-core extent and update the btree if applicable. ··· 5571 5586 got.br_blockcount, &i); 5572 5587 if (error) 5573 5588 return error; 5574 - XFS_WANT_CORRUPTED_GOTO(i == 1, out_error); 5589 + XFS_WANT_CORRUPTED_RETURN(i == 1); 5575 5590 5576 5591 got.br_startoff = startoff; 5577 5592 return xfs_bmbt_update(cur, got.br_startoff, got.br_startblock, 5578 5593 got.br_blockcount, got.br_state); 5579 - 5580 - out_error: 5581 - return error; 5582 5594 } 5583 5595 5584 5596 /*
-4
fs/xfs/libxfs/xfs_da_btree.c
··· 512 512 struct xfs_buf *bp; 513 513 struct xfs_inode *dp; 514 514 struct xfs_trans *tp; 515 - struct xfs_mount *mp; 516 515 struct xfs_dir2_leaf *leaf; 517 516 xfs_dablk_t blkno; 518 517 int level; ··· 531 532 532 533 dp = args->dp; 533 534 tp = args->trans; 534 - mp = state->mp; 535 535 error = xfs_da_get_buf(tp, dp, blkno, -1, &bp, args->whichfork); 536 536 if (error) 537 537 return error; ··· 2338 2340 xfs_inode_t *dp; 2339 2341 int done, error, w, count; 2340 2342 xfs_trans_t *tp; 2341 - xfs_mount_t *mp; 2342 2343 2343 2344 trace_xfs_da_shrink_inode(args); 2344 2345 2345 2346 dp = args->dp; 2346 2347 w = args->whichfork; 2347 2348 tp = args->trans; 2348 - mp = dp->i_mount; 2349 2349 count = args->geo->fsbcount; 2350 2350 for (;;) { 2351 2351 /*
+16
fs/xfs/libxfs/xfs_dir2.c
··· 34 34 35 35 struct xfs_name xfs_name_dotdot = { (unsigned char *)"..", 2, XFS_DIR3_FT_DIR }; 36 36 37 + /* 38 + * @mode, if set, indicates that the type field needs to be set up. 39 + * This uses the transformation from file mode to DT_* as defined in linux/fs.h 40 + * for file type specification. This will be propagated into the directory 41 + * structure if appropriate for the given operation and filesystem config. 42 + */ 43 + const unsigned char xfs_mode_to_ftype[S_IFMT >> S_SHIFT] = { 44 + [0] = XFS_DIR3_FT_UNKNOWN, 45 + [S_IFREG >> S_SHIFT] = XFS_DIR3_FT_REG_FILE, 46 + [S_IFDIR >> S_SHIFT] = XFS_DIR3_FT_DIR, 47 + [S_IFCHR >> S_SHIFT] = XFS_DIR3_FT_CHRDEV, 48 + [S_IFBLK >> S_SHIFT] = XFS_DIR3_FT_BLKDEV, 49 + [S_IFIFO >> S_SHIFT] = XFS_DIR3_FT_FIFO, 50 + [S_IFSOCK >> S_SHIFT] = XFS_DIR3_FT_SOCK, 51 + [S_IFLNK >> S_SHIFT] = XFS_DIR3_FT_SYMLINK, 52 + }; 37 53 38 54 /* 39 55 * ASCII case-insensitive (ie. A-Z) support for directories that was
+140
fs/xfs/libxfs/xfs_dir2.h
··· 32 32 extern struct xfs_name xfs_name_dotdot; 33 33 34 34 /* 35 + * directory filetype conversion tables. 36 + */ 37 + #define S_SHIFT 12 38 + extern const unsigned char xfs_mode_to_ftype[]; 39 + 40 + /* 35 41 * directory operations vector for encode/decode routines 36 42 */ 37 43 struct xfs_dir_ops { ··· 182 176 extern const struct xfs_buf_ops xfs_dir3_leaf1_buf_ops; 183 177 extern const struct xfs_buf_ops xfs_dir3_free_buf_ops; 184 178 extern const struct xfs_buf_ops xfs_dir3_data_buf_ops; 179 + 180 + /* 181 + * Directory offset/block conversion functions. 182 + * 183 + * DB blocks here are logical directory block numbers, not filesystem blocks. 184 + */ 185 + 186 + /* 187 + * Convert dataptr to byte in file space 188 + */ 189 + static inline xfs_dir2_off_t 190 + xfs_dir2_dataptr_to_byte(xfs_dir2_dataptr_t dp) 191 + { 192 + return (xfs_dir2_off_t)dp << XFS_DIR2_DATA_ALIGN_LOG; 193 + } 194 + 195 + /* 196 + * Convert byte in file space to dataptr. It had better be aligned. 197 + */ 198 + static inline xfs_dir2_dataptr_t 199 + xfs_dir2_byte_to_dataptr(xfs_dir2_off_t by) 200 + { 201 + return (xfs_dir2_dataptr_t)(by >> XFS_DIR2_DATA_ALIGN_LOG); 202 + } 203 + 204 + /* 205 + * Convert byte in space to (DB) block 206 + */ 207 + static inline xfs_dir2_db_t 208 + xfs_dir2_byte_to_db(struct xfs_da_geometry *geo, xfs_dir2_off_t by) 209 + { 210 + return (xfs_dir2_db_t)(by >> geo->blklog); 211 + } 212 + 213 + /* 214 + * Convert dataptr to a block number 215 + */ 216 + static inline xfs_dir2_db_t 217 + xfs_dir2_dataptr_to_db(struct xfs_da_geometry *geo, xfs_dir2_dataptr_t dp) 218 + { 219 + return xfs_dir2_byte_to_db(geo, xfs_dir2_dataptr_to_byte(dp)); 220 + } 221 + 222 + /* 223 + * Convert byte in space to offset in a block 224 + */ 225 + static inline xfs_dir2_data_aoff_t 226 + xfs_dir2_byte_to_off(struct xfs_da_geometry *geo, xfs_dir2_off_t by) 227 + { 228 + return (xfs_dir2_data_aoff_t)(by & (geo->blksize - 1)); 229 + } 230 + 231 + /* 232 + * Convert dataptr to a byte offset in a block 233 + */ 234 + static inline xfs_dir2_data_aoff_t 235 + xfs_dir2_dataptr_to_off(struct xfs_da_geometry *geo, xfs_dir2_dataptr_t dp) 236 + { 237 + return xfs_dir2_byte_to_off(geo, xfs_dir2_dataptr_to_byte(dp)); 238 + } 239 + 240 + /* 241 + * Convert block and offset to byte in space 242 + */ 243 + static inline xfs_dir2_off_t 244 + xfs_dir2_db_off_to_byte(struct xfs_da_geometry *geo, xfs_dir2_db_t db, 245 + xfs_dir2_data_aoff_t o) 246 + { 247 + return ((xfs_dir2_off_t)db << geo->blklog) + o; 248 + } 249 + 250 + /* 251 + * Convert block (DB) to block (dablk) 252 + */ 253 + static inline xfs_dablk_t 254 + xfs_dir2_db_to_da(struct xfs_da_geometry *geo, xfs_dir2_db_t db) 255 + { 256 + return (xfs_dablk_t)(db << (geo->blklog - geo->fsblog)); 257 + } 258 + 259 + /* 260 + * Convert byte in space to (DA) block 261 + */ 262 + static inline xfs_dablk_t 263 + xfs_dir2_byte_to_da(struct xfs_da_geometry *geo, xfs_dir2_off_t by) 264 + { 265 + return xfs_dir2_db_to_da(geo, xfs_dir2_byte_to_db(geo, by)); 266 + } 267 + 268 + /* 269 + * Convert block and offset to dataptr 270 + */ 271 + static inline xfs_dir2_dataptr_t 272 + xfs_dir2_db_off_to_dataptr(struct xfs_da_geometry *geo, xfs_dir2_db_t db, 273 + xfs_dir2_data_aoff_t o) 274 + { 275 + return xfs_dir2_byte_to_dataptr(xfs_dir2_db_off_to_byte(geo, db, o)); 276 + } 277 + 278 + /* 279 + * Convert block (dablk) to block (DB) 280 + */ 281 + static inline xfs_dir2_db_t 282 + xfs_dir2_da_to_db(struct xfs_da_geometry *geo, xfs_dablk_t da) 283 + { 284 + return (xfs_dir2_db_t)(da >> (geo->blklog - geo->fsblog)); 285 + } 286 + 287 + /* 288 + * Convert block (dablk) to byte offset in space 289 + */ 290 + static inline xfs_dir2_off_t 291 + xfs_dir2_da_to_byte(struct xfs_da_geometry *geo, xfs_dablk_t da) 292 + { 293 + return xfs_dir2_db_off_to_byte(geo, xfs_dir2_da_to_db(geo, da), 0); 294 + } 295 + 296 + /* 297 + * Directory tail pointer accessor functions. Based on block geometry. 298 + */ 299 + static inline struct xfs_dir2_block_tail * 300 + xfs_dir2_block_tail_p(struct xfs_da_geometry *geo, struct xfs_dir2_data_hdr *hdr) 301 + { 302 + return ((struct xfs_dir2_block_tail *) 303 + ((char *)hdr + geo->blksize)) - 1; 304 + } 305 + 306 + static inline struct xfs_dir2_leaf_tail * 307 + xfs_dir2_leaf_tail_p(struct xfs_da_geometry *geo, struct xfs_dir2_leaf *lp) 308 + { 309 + return (struct xfs_dir2_leaf_tail *) 310 + ((char *)lp + geo->blksize - 311 + sizeof(struct xfs_dir2_leaf_tail)); 312 + } 185 313 186 314 #endif /* __XFS_DIR2_H__ */
-8
fs/xfs/libxfs/xfs_dir2_block.c
··· 350 350 int low; /* low index for binary srch */ 351 351 int lowstale; /* low stale index */ 352 352 int mid=0; /* midpoint for binary srch */ 353 - xfs_mount_t *mp; /* filesystem mount point */ 354 353 int needlog; /* need to log header */ 355 354 int needscan; /* need to rescan freespace */ 356 355 __be16 *tagp; /* pointer to tag value */ ··· 359 360 360 361 dp = args->dp; 361 362 tp = args->trans; 362 - mp = dp->i_mount; 363 363 364 364 /* Read the (one and only) directory block into bp. */ 365 365 error = xfs_dir3_block_read(tp, dp, &bp); ··· 613 615 xfs_inode_t *dp; /* incore inode */ 614 616 int ent; /* entry index */ 615 617 int error; /* error return value */ 616 - xfs_mount_t *mp; /* filesystem mount point */ 617 618 618 619 trace_xfs_dir2_block_lookup(args); 619 620 ··· 623 626 if ((error = xfs_dir2_block_lookup_int(args, &bp, &ent))) 624 627 return error; 625 628 dp = args->dp; 626 - mp = dp->i_mount; 627 629 hdr = bp->b_addr; 628 630 xfs_dir3_data_check(dp, bp); 629 631 btp = xfs_dir2_block_tail_p(args->geo, hdr); ··· 763 767 xfs_inode_t *dp; /* incore inode */ 764 768 int ent; /* block leaf entry index */ 765 769 int error; /* error return value */ 766 - xfs_mount_t *mp; /* filesystem mount point */ 767 770 int needlog; /* need to log block header */ 768 771 int needscan; /* need to fixup bestfree */ 769 772 xfs_dir2_sf_hdr_t sfh; /* shortform header */ ··· 780 785 } 781 786 dp = args->dp; 782 787 tp = args->trans; 783 - mp = dp->i_mount; 784 788 hdr = bp->b_addr; 785 789 btp = xfs_dir2_block_tail_p(args->geo, hdr); 786 790 blp = xfs_dir2_block_leaf_p(btp); ··· 843 849 xfs_inode_t *dp; /* incore inode */ 844 850 int ent; /* leaf entry index */ 845 851 int error; /* error return value */ 846 - xfs_mount_t *mp; /* filesystem mount point */ 847 852 848 853 trace_xfs_dir2_block_replace(args); 849 854 ··· 854 861 return error; 855 862 } 856 863 dp = args->dp; 857 - mp = dp->i_mount; 858 864 hdr = bp->b_addr; 859 865 btp = xfs_dir2_block_tail_p(args->geo, hdr); 860 866 blp = xfs_dir2_block_leaf_p(btp);
-10
fs/xfs/libxfs/xfs_dir2_leaf.c
··· 382 382 xfs_dir2_db_t ldb; /* leaf block's bno */ 383 383 xfs_dir2_leaf_t *leaf; /* leaf structure */ 384 384 xfs_dir2_leaf_tail_t *ltp; /* leaf's tail */ 385 - xfs_mount_t *mp; /* filesystem mount point */ 386 385 int needlog; /* need to log block header */ 387 386 int needscan; /* need to rescan bestfree */ 388 387 xfs_trans_t *tp; /* transaction pointer */ ··· 392 393 trace_xfs_dir2_block_to_leaf(args); 393 394 394 395 dp = args->dp; 395 - mp = dp->i_mount; 396 396 tp = args->trans; 397 397 /* 398 398 * Add the leaf block to the inode. ··· 622 624 int lfloghigh; /* high leaf logging index */ 623 625 int lowstale; /* index of prev stale leaf */ 624 626 xfs_dir2_leaf_tail_t *ltp; /* leaf tail pointer */ 625 - xfs_mount_t *mp; /* filesystem mount point */ 626 627 int needbytes; /* leaf block bytes needed */ 627 628 int needlog; /* need to log data header */ 628 629 int needscan; /* need to rescan data free */ ··· 636 639 637 640 dp = args->dp; 638 641 tp = args->trans; 639 - mp = dp->i_mount; 640 642 641 643 error = xfs_dir3_leaf_read(tp, dp, args->geo->leafblk, -1, &lbp); 642 644 if (error) ··· 1350 1354 xfs_dir2_leaf_t *leaf; /* leaf structure */ 1351 1355 xfs_dir2_leaf_entry_t *lep; /* leaf entry */ 1352 1356 xfs_dir2_leaf_tail_t *ltp; /* leaf tail structure */ 1353 - xfs_mount_t *mp; /* filesystem mount point */ 1354 1357 int needlog; /* need to log data header */ 1355 1358 int needscan; /* need to rescan data frees */ 1356 1359 xfs_dir2_data_off_t oldbest; /* old value of best free */ 1357 - xfs_trans_t *tp; /* transaction pointer */ 1358 1360 struct xfs_dir2_data_free *bf; /* bestfree table */ 1359 1361 struct xfs_dir2_leaf_entry *ents; 1360 1362 struct xfs_dir3_icleaf_hdr leafhdr; ··· 1366 1372 return error; 1367 1373 } 1368 1374 dp = args->dp; 1369 - tp = args->trans; 1370 - mp = dp->i_mount; 1371 1375 leaf = lbp->b_addr; 1372 1376 hdr = dbp->b_addr; 1373 1377 xfs_dir3_data_check(dp, dbp); ··· 1597 1605 int error; /* error return value */ 1598 1606 xfs_dir2_leaf_t *leaf; /* leaf structure */ 1599 1607 xfs_dir2_leaf_tail_t *ltp; /* leaf tail structure */ 1600 - xfs_mount_t *mp; /* filesystem mount point */ 1601 1608 xfs_trans_t *tp; /* transaction pointer */ 1602 1609 1603 1610 dp = args->dp; 1604 - mp = dp->i_mount; 1605 1611 tp = args->trans; 1606 1612 /* 1607 1613 * Read the offending data block. We need its buffer.
-12
fs/xfs/libxfs/xfs_dir2_node.c
··· 295 295 int i; /* leaf freespace index */ 296 296 xfs_dir2_leaf_t *leaf; /* leaf structure */ 297 297 xfs_dir2_leaf_tail_t *ltp; /* leaf tail structure */ 298 - xfs_mount_t *mp; /* filesystem mount point */ 299 298 int n; /* count of live freespc ents */ 300 299 xfs_dir2_data_off_t off; /* freespace entry value */ 301 300 __be16 *to; /* pointer to freespace entry */ ··· 304 305 trace_xfs_dir2_leaf_to_node(args); 305 306 306 307 dp = args->dp; 307 - mp = dp->i_mount; 308 308 tp = args->trans; 309 309 /* 310 310 * Add a freespace block to the directory. ··· 383 385 int lfloghigh; /* high leaf entry logging */ 384 386 int lfloglow; /* low leaf entry logging */ 385 387 int lowstale; /* previous stale entry */ 386 - xfs_mount_t *mp; /* filesystem mount point */ 387 - xfs_trans_t *tp; /* transaction pointer */ 388 388 struct xfs_dir3_icleaf_hdr leafhdr; 389 389 struct xfs_dir2_leaf_entry *ents; 390 390 391 391 trace_xfs_dir2_leafn_add(args, index); 392 392 393 393 dp = args->dp; 394 - mp = dp->i_mount; 395 - tp = args->trans; 396 394 leaf = bp->b_addr; 397 395 dp->d_ops->leaf_hdr_from_disk(&leafhdr, leaf); 398 396 ents = dp->d_ops->leaf_ents_p(leaf); ··· 1162 1168 xfs_dir2_leaf_entry_t *lep; /* leaf entry */ 1163 1169 int longest; /* longest data free entry */ 1164 1170 int off; /* data block entry offset */ 1165 - xfs_mount_t *mp; /* filesystem mount point */ 1166 1171 int needlog; /* need to log data header */ 1167 1172 int needscan; /* need to rescan data frees */ 1168 1173 xfs_trans_t *tp; /* transaction pointer */ ··· 1173 1180 1174 1181 dp = args->dp; 1175 1182 tp = args->trans; 1176 - mp = dp->i_mount; 1177 1183 leaf = bp->b_addr; 1178 1184 dp->d_ops->leaf_hdr_from_disk(&leafhdr, leaf); 1179 1185 ents = dp->d_ops->leaf_ents_p(leaf); ··· 1313 1321 xfs_da_args_t *args; /* operation arguments */ 1314 1322 xfs_dablk_t blkno; /* new leaf block number */ 1315 1323 int error; /* error return value */ 1316 - xfs_mount_t *mp; /* filesystem mount point */ 1317 1324 struct xfs_inode *dp; 1318 1325 1319 1326 /* ··· 1320 1329 */ 1321 1330 args = state->args; 1322 1331 dp = args->dp; 1323 - mp = dp->i_mount; 1324 1332 ASSERT(oldblk->magic == XFS_DIR2_LEAFN_MAGIC); 1325 1333 error = xfs_da_grow_inode(args, &blkno); 1326 1334 if (error) { ··· 2219 2229 xfs_inode_t *dp; /* incore directory inode */ 2220 2230 int error; /* error return code */ 2221 2231 xfs_dir2_free_t *free; /* freespace structure */ 2222 - xfs_mount_t *mp; /* filesystem mount point */ 2223 2232 xfs_trans_t *tp; /* transaction pointer */ 2224 2233 struct xfs_dir3_icfree_hdr freehdr; 2225 2234 2226 2235 dp = args->dp; 2227 - mp = dp->i_mount; 2228 2236 tp = args->trans; 2229 2237 /* 2230 2238 * Read the freespace block.
-140
fs/xfs/libxfs/xfs_dir2_priv.h
··· 20 20 21 21 struct dir_context; 22 22 23 - /* 24 - * Directory offset/block conversion functions. 25 - * 26 - * DB blocks here are logical directory block numbers, not filesystem blocks. 27 - */ 28 - 29 - /* 30 - * Convert dataptr to byte in file space 31 - */ 32 - static inline xfs_dir2_off_t 33 - xfs_dir2_dataptr_to_byte(xfs_dir2_dataptr_t dp) 34 - { 35 - return (xfs_dir2_off_t)dp << XFS_DIR2_DATA_ALIGN_LOG; 36 - } 37 - 38 - /* 39 - * Convert byte in file space to dataptr. It had better be aligned. 40 - */ 41 - static inline xfs_dir2_dataptr_t 42 - xfs_dir2_byte_to_dataptr(xfs_dir2_off_t by) 43 - { 44 - return (xfs_dir2_dataptr_t)(by >> XFS_DIR2_DATA_ALIGN_LOG); 45 - } 46 - 47 - /* 48 - * Convert byte in space to (DB) block 49 - */ 50 - static inline xfs_dir2_db_t 51 - xfs_dir2_byte_to_db(struct xfs_da_geometry *geo, xfs_dir2_off_t by) 52 - { 53 - return (xfs_dir2_db_t)(by >> geo->blklog); 54 - } 55 - 56 - /* 57 - * Convert dataptr to a block number 58 - */ 59 - static inline xfs_dir2_db_t 60 - xfs_dir2_dataptr_to_db(struct xfs_da_geometry *geo, xfs_dir2_dataptr_t dp) 61 - { 62 - return xfs_dir2_byte_to_db(geo, xfs_dir2_dataptr_to_byte(dp)); 63 - } 64 - 65 - /* 66 - * Convert byte in space to offset in a block 67 - */ 68 - static inline xfs_dir2_data_aoff_t 69 - xfs_dir2_byte_to_off(struct xfs_da_geometry *geo, xfs_dir2_off_t by) 70 - { 71 - return (xfs_dir2_data_aoff_t)(by & (geo->blksize - 1)); 72 - } 73 - 74 - /* 75 - * Convert dataptr to a byte offset in a block 76 - */ 77 - static inline xfs_dir2_data_aoff_t 78 - xfs_dir2_dataptr_to_off(struct xfs_da_geometry *geo, xfs_dir2_dataptr_t dp) 79 - { 80 - return xfs_dir2_byte_to_off(geo, xfs_dir2_dataptr_to_byte(dp)); 81 - } 82 - 83 - /* 84 - * Convert block and offset to byte in space 85 - */ 86 - static inline xfs_dir2_off_t 87 - xfs_dir2_db_off_to_byte(struct xfs_da_geometry *geo, xfs_dir2_db_t db, 88 - xfs_dir2_data_aoff_t o) 89 - { 90 - return ((xfs_dir2_off_t)db << geo->blklog) + o; 91 - } 92 - 93 - /* 94 - * Convert block (DB) to block (dablk) 95 - */ 96 - static inline xfs_dablk_t 97 - xfs_dir2_db_to_da(struct xfs_da_geometry *geo, xfs_dir2_db_t db) 98 - { 99 - return (xfs_dablk_t)(db << (geo->blklog - geo->fsblog)); 100 - } 101 - 102 - /* 103 - * Convert byte in space to (DA) block 104 - */ 105 - static inline xfs_dablk_t 106 - xfs_dir2_byte_to_da(struct xfs_da_geometry *geo, xfs_dir2_off_t by) 107 - { 108 - return xfs_dir2_db_to_da(geo, xfs_dir2_byte_to_db(geo, by)); 109 - } 110 - 111 - /* 112 - * Convert block and offset to dataptr 113 - */ 114 - static inline xfs_dir2_dataptr_t 115 - xfs_dir2_db_off_to_dataptr(struct xfs_da_geometry *geo, xfs_dir2_db_t db, 116 - xfs_dir2_data_aoff_t o) 117 - { 118 - return xfs_dir2_byte_to_dataptr(xfs_dir2_db_off_to_byte(geo, db, o)); 119 - } 120 - 121 - /* 122 - * Convert block (dablk) to block (DB) 123 - */ 124 - static inline xfs_dir2_db_t 125 - xfs_dir2_da_to_db(struct xfs_da_geometry *geo, xfs_dablk_t da) 126 - { 127 - return (xfs_dir2_db_t)(da >> (geo->blklog - geo->fsblog)); 128 - } 129 - 130 - /* 131 - * Convert block (dablk) to byte offset in space 132 - */ 133 - static inline xfs_dir2_off_t 134 - xfs_dir2_da_to_byte(struct xfs_da_geometry *geo, xfs_dablk_t da) 135 - { 136 - return xfs_dir2_db_off_to_byte(geo, xfs_dir2_da_to_db(geo, da), 0); 137 - } 138 - 139 - /* 140 - * Directory tail pointer accessor functions. Based on block geometry. 141 - */ 142 - static inline struct xfs_dir2_block_tail * 143 - xfs_dir2_block_tail_p(struct xfs_da_geometry *geo, struct xfs_dir2_data_hdr *hdr) 144 - { 145 - return ((struct xfs_dir2_block_tail *) 146 - ((char *)hdr + geo->blksize)) - 1; 147 - } 148 - 149 - static inline struct xfs_dir2_leaf_tail * 150 - xfs_dir2_leaf_tail_p(struct xfs_da_geometry *geo, struct xfs_dir2_leaf *lp) 151 - { 152 - return (struct xfs_dir2_leaf_tail *) 153 - ((char *)lp + geo->blksize - 154 - sizeof(struct xfs_dir2_leaf_tail)); 155 - } 156 - 157 23 /* xfs_dir2.c */ 158 24 extern int xfs_dir_ino_validate(struct xfs_mount *mp, xfs_ino_t ino); 159 25 extern int xfs_dir2_grow_inode(struct xfs_da_args *args, int space, 160 26 xfs_dir2_db_t *dbp); 161 27 extern int xfs_dir_cilookup_result(struct xfs_da_args *args, 162 28 const unsigned char *name, int len); 163 - 164 - #define S_SHIFT 12 165 - extern const unsigned char xfs_mode_to_ftype[]; 166 - 167 - extern unsigned char xfs_dir3_get_dtype(struct xfs_mount *mp, 168 - __uint8_t filetype); 169 29 170 30 171 31 /* xfs_dir2_block.c */
-10
fs/xfs/libxfs/xfs_dir2_sf.c
··· 452 452 xfs_dir2_sf_hdr_t *oldsfp; /* original shortform dir */ 453 453 xfs_dir2_sf_entry_t *sfep; /* entry in new dir */ 454 454 xfs_dir2_sf_hdr_t *sfp; /* new shortform dir */ 455 - struct xfs_mount *mp; 456 455 457 456 /* 458 457 * Copy the old directory to the stack buffer. 459 458 */ 460 459 dp = args->dp; 461 - mp = dp->i_mount; 462 460 463 461 sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data; 464 462 old_isize = (int)dp->i_d.di_size; ··· 537 539 xfs_inode_t *dp; /* incore directory inode */ 538 540 int holefit; /* found hole it will fit in */ 539 541 int i; /* entry number */ 540 - xfs_mount_t *mp; /* filesystem mount point */ 541 542 xfs_dir2_data_aoff_t offset; /* data block offset */ 542 543 xfs_dir2_sf_entry_t *sfep; /* shortform entry */ 543 544 xfs_dir2_sf_hdr_t *sfp; /* shortform structure */ ··· 544 547 int used; /* data bytes used */ 545 548 546 549 dp = args->dp; 547 - mp = dp->i_mount; 548 550 549 551 sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data; 550 552 size = dp->d_ops->data_entsize(args->namelen); ··· 609 613 int offset; /* data offset */ 610 614 xfs_dir2_sf_entry_t *sfep; /* shortform dir entry */ 611 615 xfs_dir2_sf_hdr_t *sfp; /* shortform structure */ 612 - struct xfs_mount *mp; 613 616 614 617 dp = args->dp; 615 - mp = dp->i_mount; 616 618 617 619 sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data; 618 620 offset = dp->d_ops->data_first_offset; ··· 1007 1013 int oldsize; /* old inode size */ 1008 1014 xfs_dir2_sf_entry_t *sfep; /* new sf entry */ 1009 1015 xfs_dir2_sf_hdr_t *sfp; /* new sf directory */ 1010 - struct xfs_mount *mp; 1011 1016 1012 1017 trace_xfs_dir2_sf_toino4(args); 1013 1018 1014 1019 dp = args->dp; 1015 - mp = dp->i_mount; 1016 1020 1017 1021 /* 1018 1022 * Copy the old directory to the buffer. ··· 1083 1091 int oldsize; /* old inode size */ 1084 1092 xfs_dir2_sf_entry_t *sfep; /* new sf entry */ 1085 1093 xfs_dir2_sf_hdr_t *sfp; /* new sf directory */ 1086 - struct xfs_mount *mp; 1087 1094 1088 1095 trace_xfs_dir2_sf_toino8(args); 1089 1096 1090 1097 dp = args->dp; 1091 - mp = dp->i_mount; 1092 1098 1093 1099 /* 1094 1100 * Copy the old directory to the buffer.
+24 -10
fs/xfs/libxfs/xfs_ialloc.c
··· 45 45 */ 46 46 static inline int 47 47 xfs_ialloc_cluster_alignment( 48 - xfs_alloc_arg_t *args) 48 + struct xfs_mount *mp) 49 49 { 50 - if (xfs_sb_version_hasalign(&args->mp->m_sb) && 51 - args->mp->m_sb.sb_inoalignmt >= 52 - XFS_B_TO_FSBT(args->mp, args->mp->m_inode_cluster_size)) 53 - return args->mp->m_sb.sb_inoalignmt; 50 + if (xfs_sb_version_hasalign(&mp->m_sb) && 51 + mp->m_sb.sb_inoalignmt >= 52 + XFS_B_TO_FSBT(mp, mp->m_inode_cluster_size)) 53 + return mp->m_sb.sb_inoalignmt; 54 54 return 1; 55 55 } 56 56 ··· 409 409 * but not to use them in the actual exact allocation. 410 410 */ 411 411 args.alignment = 1; 412 - args.minalignslop = xfs_ialloc_cluster_alignment(&args) - 1; 412 + args.minalignslop = xfs_ialloc_cluster_alignment(args.mp) - 1; 413 413 414 414 /* Allow space for the inode btree to split. */ 415 415 args.minleft = args.mp->m_in_maxlevels - 1; ··· 445 445 args.alignment = args.mp->m_dalign; 446 446 isaligned = 1; 447 447 } else 448 - args.alignment = xfs_ialloc_cluster_alignment(&args); 448 + args.alignment = xfs_ialloc_cluster_alignment(args.mp); 449 449 /* 450 450 * Need to figure out where to allocate the inode blocks. 451 451 * Ideally they should be spaced out through the a.g. ··· 474 474 args.type = XFS_ALLOCTYPE_NEAR_BNO; 475 475 args.agbno = be32_to_cpu(agi->agi_root); 476 476 args.fsbno = XFS_AGB_TO_FSB(args.mp, agno, args.agbno); 477 - args.alignment = xfs_ialloc_cluster_alignment(&args); 477 + args.alignment = xfs_ialloc_cluster_alignment(args.mp); 478 478 if ((error = xfs_alloc_vextent(&args))) 479 479 return error; 480 480 } ··· 629 629 } 630 630 631 631 /* 632 - * Is there enough free space for the file plus a block of 633 - * inodes? (if we need to allocate some)? 632 + * Check that there is enough free space for the file plus a 633 + * chunk of inodes if we need to allocate some. If this is the 634 + * first pass across the AGs, take into account the potential 635 + * space needed for alignment of inode chunks when checking the 636 + * longest contiguous free space in the AG - this prevents us 637 + * from getting ENOSPC because we have free space larger than 638 + * m_ialloc_blks but alignment constraints prevent us from using 639 + * it. 640 + * 641 + * If we can't find an AG with space for full alignment slack to 642 + * be taken into account, we must be near ENOSPC in all AGs. 643 + * Hence we don't include alignment for the second pass and so 644 + * if we fail allocation due to alignment issues then it is most 645 + * likely a real ENOSPC condition. 634 646 */ 635 647 ineed = mp->m_ialloc_blks; 648 + if (flags && ineed > 1) 649 + ineed += xfs_ialloc_cluster_alignment(mp); 636 650 longest = pag->pagf_longest; 637 651 if (!longest) 638 652 longest = pag->pagf_flcount > 0;
+10 -3
fs/xfs/xfs_buf.c
··· 1041 1041 struct work_struct *work) 1042 1042 { 1043 1043 struct xfs_buf *bp = 1044 - container_of(work, xfs_buf_t, b_iodone_work); 1044 + container_of(work, xfs_buf_t, b_ioend_work); 1045 1045 1046 1046 xfs_buf_ioend(bp); 1047 1047 } ··· 1050 1050 xfs_buf_ioend_async( 1051 1051 struct xfs_buf *bp) 1052 1052 { 1053 - INIT_WORK(&bp->b_iodone_work, xfs_buf_ioend_work); 1054 - queue_work(bp->b_target->bt_mount->m_buf_workqueue, &bp->b_iodone_work); 1053 + INIT_WORK(&bp->b_ioend_work, xfs_buf_ioend_work); 1054 + queue_work(bp->b_ioend_wq, &bp->b_ioend_work); 1055 1055 } 1056 1056 1057 1057 void ··· 1219 1219 * left over from previous use of the buffer (e.g. failed readahead). 1220 1220 */ 1221 1221 bp->b_error = 0; 1222 + 1223 + /* 1224 + * Initialize the I/O completion workqueue if we haven't yet or the 1225 + * submitter has not opted to specify a custom one. 1226 + */ 1227 + if (!bp->b_ioend_wq) 1228 + bp->b_ioend_wq = bp->b_target->bt_mount->m_buf_workqueue; 1222 1229 1223 1230 if (bp->b_flags & XBF_WRITE) { 1224 1231 if (bp->b_flags & XBF_SYNCIO)
+2 -1
fs/xfs/xfs_buf.h
··· 164 164 struct xfs_perag *b_pag; /* contains rbtree root */ 165 165 xfs_buftarg_t *b_target; /* buffer target (device) */ 166 166 void *b_addr; /* virtual address of buffer */ 167 - struct work_struct b_iodone_work; 167 + struct work_struct b_ioend_work; 168 + struct workqueue_struct *b_ioend_wq; /* I/O completion wq */ 168 169 xfs_buf_iodone_t b_iodone; /* I/O completion function */ 169 170 struct completion b_iowait; /* queue for I/O waiters */ 170 171 void *b_fspriv;
+1 -17
fs/xfs/xfs_dir2_readdir.c
··· 41 41 DT_FIFO, DT_SOCK, DT_LNK, DT_WHT, 42 42 }; 43 43 44 - unsigned char 44 + static unsigned char 45 45 xfs_dir3_get_dtype( 46 46 struct xfs_mount *mp, 47 47 __uint8_t filetype) ··· 54 54 55 55 return xfs_dir3_filetype_table[filetype]; 56 56 } 57 - /* 58 - * @mode, if set, indicates that the type field needs to be set up. 59 - * This uses the transformation from file mode to DT_* as defined in linux/fs.h 60 - * for file type specification. This will be propagated into the directory 61 - * structure if appropriate for the given operation and filesystem config. 62 - */ 63 - const unsigned char xfs_mode_to_ftype[S_IFMT >> S_SHIFT] = { 64 - [0] = XFS_DIR3_FT_UNKNOWN, 65 - [S_IFREG >> S_SHIFT] = XFS_DIR3_FT_REG_FILE, 66 - [S_IFDIR >> S_SHIFT] = XFS_DIR3_FT_DIR, 67 - [S_IFCHR >> S_SHIFT] = XFS_DIR3_FT_CHRDEV, 68 - [S_IFBLK >> S_SHIFT] = XFS_DIR3_FT_BLKDEV, 69 - [S_IFIFO >> S_SHIFT] = XFS_DIR3_FT_FIFO, 70 - [S_IFSOCK >> S_SHIFT] = XFS_DIR3_FT_SOCK, 71 - [S_IFLNK >> S_SHIFT] = XFS_DIR3_FT_SYMLINK, 72 - }; 73 57 74 58 STATIC int 75 59 xfs_dir2_sf_getdents(
+1
fs/xfs/xfs_export.c
··· 21 21 #include "xfs_trans_resv.h" 22 22 #include "xfs_mount.h" 23 23 #include "xfs_da_format.h" 24 + #include "xfs_da_btree.h" 24 25 #include "xfs_dir2.h" 25 26 #include "xfs_export.h" 26 27 #include "xfs_inode.h"
+2
fs/xfs/xfs_icache.c
··· 63 63 return NULL; 64 64 } 65 65 66 + XFS_STATS_INC(vn_active); 66 67 ASSERT(atomic_read(&ip->i_pincount) == 0); 67 68 ASSERT(!spin_is_locked(&ip->i_flags_lock)); 68 69 ASSERT(!xfs_isiflocked(ip)); ··· 129 128 /* asserts to verify all state is correct here */ 130 129 ASSERT(atomic_read(&ip->i_pincount) == 0); 131 130 ASSERT(!xfs_isiflocked(ip)); 131 + XFS_STATS_DEC(vn_active); 132 132 133 133 call_rcu(&VFS_I(ip)->i_rcu, xfs_inode_free_callback); 134 134 }
+2 -10
fs/xfs/xfs_inode.c
··· 2483 2483 xfs_fsblock_t first_block; 2484 2484 int cancel_flags; 2485 2485 int committed; 2486 - int link_zero; 2487 2486 uint resblks; 2488 - uint log_count; 2489 2487 2490 2488 trace_xfs_remove(dp, name); 2491 2489 ··· 2498 2500 if (error) 2499 2501 goto std_return; 2500 2502 2501 - if (is_dir) { 2503 + if (is_dir) 2502 2504 tp = xfs_trans_alloc(mp, XFS_TRANS_RMDIR); 2503 - log_count = XFS_DEFAULT_LOG_COUNT; 2504 - } else { 2505 + else 2505 2506 tp = xfs_trans_alloc(mp, XFS_TRANS_REMOVE); 2506 - log_count = XFS_REMOVE_LOG_COUNT; 2507 - } 2508 2507 cancel_flags = XFS_TRANS_RELEASE_LOG_RES; 2509 2508 2510 2509 /* ··· 2568 2573 error = xfs_droplink(tp, ip); 2569 2574 if (error) 2570 2575 goto out_trans_cancel; 2571 - 2572 - /* Determine if this is the last link while the inode is locked */ 2573 - link_zero = (ip->i_d.di_nlink == 0); 2574 2576 2575 2577 xfs_bmap_init(&free_list, &first_block); 2576 2578 error = xfs_dir_removename(tp, dp, name, ip->i_ino,
+6 -9
fs/xfs/xfs_iomap.c
··· 49 49 xfs_extlen_t extsize, 50 50 xfs_fileoff_t *last_fsb) 51 51 { 52 - xfs_fileoff_t new_last_fsb = 0; 53 52 xfs_extlen_t align = 0; 54 53 int eof, error; 55 54 ··· 66 67 else if (mp->m_dalign) 67 68 align = mp->m_dalign; 68 69 69 - if (align && XFS_ISIZE(ip) >= XFS_FSB_TO_B(mp, align)) 70 - new_last_fsb = roundup_64(*last_fsb, align); 70 + if (align && XFS_ISIZE(ip) < XFS_FSB_TO_B(mp, align)) 71 + align = 0; 71 72 } 72 73 73 74 /* ··· 75 76 * (when file on a real-time subvolume or has di_extsize hint). 76 77 */ 77 78 if (extsize) { 78 - if (new_last_fsb) 79 - align = roundup_64(new_last_fsb, extsize); 79 + if (align) 80 + align = roundup_64(align, extsize); 80 81 else 81 82 align = extsize; 82 - new_last_fsb = roundup_64(*last_fsb, align); 83 83 } 84 84 85 - if (new_last_fsb) { 85 + if (align) { 86 + xfs_fileoff_t new_last_fsb = roundup_64(*last_fsb, align); 86 87 error = xfs_bmap_eof(ip, new_last_fsb, XFS_DATA_FORK, &eof); 87 88 if (error) 88 89 return error; ··· 260 261 { 261 262 xfs_fileoff_t start_fsb; 262 263 xfs_filblks_t count_fsb; 263 - xfs_fsblock_t firstblock; 264 264 int n, error, imaps; 265 265 int found_delalloc = 0; 266 266 ··· 284 286 count_fsb = XFS_B_TO_FSB(mp, mp->m_super->s_maxbytes); 285 287 while (count_fsb > 0) { 286 288 imaps = nimaps; 287 - firstblock = NULLFSBLOCK; 288 289 error = xfs_bmapi_read(ip, start_fsb, count_fsb, imap, &imaps, 289 290 0); 290 291 if (error)
+1 -1
fs/xfs/xfs_iops.c
··· 35 35 #include "xfs_icache.h" 36 36 #include "xfs_symlink.h" 37 37 #include "xfs_da_btree.h" 38 - #include "xfs_dir2_priv.h" 38 + #include "xfs_dir2.h" 39 39 #include "xfs_trans_space.h" 40 40 41 41 #include <linux/capability.h>
-2
fs/xfs/xfs_itable.c
··· 348 348 int *done) /* 1 if there are more stats to get */ 349 349 { 350 350 xfs_buf_t *agbp; /* agi header buffer */ 351 - xfs_agi_t *agi; /* agi header data */ 352 351 xfs_agino_t agino; /* inode # in allocation group */ 353 352 xfs_agnumber_t agno; /* allocation group number */ 354 353 xfs_btree_cur_t *cur; /* btree cursor for ialloc btree */ ··· 398 399 error = xfs_ialloc_read_agi(mp, NULL, agno, &agbp); 399 400 if (error) 400 401 break; 401 - agi = XFS_BUF_TO_AGI(agbp); 402 402 /* 403 403 * Allocate and initialize a btree cursor for ialloc btree. 404 404 */
+4
fs/xfs/xfs_log.c
··· 1806 1806 XFS_BUF_ZEROFLAGS(bp); 1807 1807 XFS_BUF_ASYNC(bp); 1808 1808 bp->b_flags |= XBF_SYNCIO; 1809 + /* use high priority completion wq */ 1810 + bp->b_ioend_wq = log->l_mp->m_log_workqueue; 1809 1811 1810 1812 if (log->l_mp->m_flags & XFS_MOUNT_BARRIER) { 1811 1813 bp->b_flags |= XBF_FUA; ··· 1856 1854 bp->b_flags |= XBF_SYNCIO; 1857 1855 if (log->l_mp->m_flags & XFS_MOUNT_BARRIER) 1858 1856 bp->b_flags |= XBF_FUA; 1857 + /* use high priority completion wq */ 1858 + bp->b_ioend_wq = log->l_mp->m_log_workqueue; 1859 1859 1860 1860 ASSERT(XFS_BUF_ADDR(bp) <= log->l_logBBsize-1); 1861 1861 ASSERT(XFS_BUF_ADDR(bp) + BTOBB(count) <= log->l_logBBsize);
+1
fs/xfs/xfs_log_recover.c
··· 25 25 #include "xfs_sb.h" 26 26 #include "xfs_mount.h" 27 27 #include "xfs_da_format.h" 28 + #include "xfs_da_btree.h" 28 29 #include "xfs_inode.h" 29 30 #include "xfs_trans.h" 30 31 #include "xfs_log.h"
+1
fs/xfs/xfs_mount.c
··· 25 25 #include "xfs_sb.h" 26 26 #include "xfs_mount.h" 27 27 #include "xfs_da_format.h" 28 + #include "xfs_da_btree.h" 28 29 #include "xfs_inode.h" 29 30 #include "xfs_dir2.h" 30 31 #include "xfs_ialloc.h"
+2 -4
fs/xfs/xfs_super.c
··· 839 839 struct xfs_mount *mp) 840 840 { 841 841 mp->m_buf_workqueue = alloc_workqueue("xfs-buf/%s", 842 - WQ_MEM_RECLAIM|WQ_HIGHPRI|WQ_FREEZABLE, 1, 843 - mp->m_fsname); 842 + WQ_MEM_RECLAIM|WQ_FREEZABLE, 1, mp->m_fsname); 844 843 if (!mp->m_buf_workqueue) 845 844 goto out; 846 845 ··· 864 865 goto out_destroy_cil; 865 866 866 867 mp->m_log_workqueue = alloc_workqueue("xfs-log/%s", 867 - WQ_FREEZABLE, 0, mp->m_fsname); 868 + WQ_FREEZABLE|WQ_HIGHPRI, 0, mp->m_fsname); 868 869 if (!mp->m_log_workqueue) 869 870 goto out_destroy_reclaim; 870 871 ··· 1004 1005 clear_inode(inode); 1005 1006 XFS_STATS_INC(vn_rele); 1006 1007 XFS_STATS_INC(vn_remove); 1007 - XFS_STATS_DEC(vn_active); 1008 1008 1009 1009 xfs_inactive(ip); 1010 1010 }
+32 -101
fs/xfs/xfs_trans_buf.c
··· 227 227 return bp; 228 228 } 229 229 230 - #ifdef DEBUG 231 - xfs_buftarg_t *xfs_error_target; 232 - int xfs_do_error; 233 - int xfs_req_num; 234 - int xfs_error_mod = 33; 235 - #endif 236 - 237 230 /* 238 231 * Get and lock the buffer for the caller if it is not already 239 232 * locked within the given transaction. If it has not yet been ··· 248 255 struct xfs_buf **bpp, 249 256 const struct xfs_buf_ops *ops) 250 257 { 251 - xfs_buf_t *bp; 252 - xfs_buf_log_item_t *bip; 258 + struct xfs_buf *bp = NULL; 259 + struct xfs_buf_log_item *bip; 253 260 int error; 254 261 255 262 *bpp = NULL; 256 - if (!tp) { 257 - bp = xfs_buf_read_map(target, map, nmaps, flags, ops); 258 - if (!bp) 259 - return (flags & XBF_TRYLOCK) ? 260 - -EAGAIN : -ENOMEM; 261 - 262 - if (bp->b_error) { 263 - error = bp->b_error; 264 - xfs_buf_ioerror_alert(bp, __func__); 265 - XFS_BUF_UNDONE(bp); 266 - xfs_buf_stale(bp); 267 - xfs_buf_relse(bp); 268 - 269 - /* bad CRC means corrupted metadata */ 270 - if (error == -EFSBADCRC) 271 - error = -EFSCORRUPTED; 272 - return error; 273 - } 274 - #ifdef DEBUG 275 - if (xfs_do_error) { 276 - if (xfs_error_target == target) { 277 - if (((xfs_req_num++) % xfs_error_mod) == 0) { 278 - xfs_buf_relse(bp); 279 - xfs_debug(mp, "Returning error!"); 280 - return -EIO; 281 - } 282 - } 283 - } 284 - #endif 285 - if (XFS_FORCED_SHUTDOWN(mp)) 286 - goto shutdown_abort; 287 - *bpp = bp; 288 - return 0; 289 - } 290 - 291 263 /* 292 264 * If we find the buffer in the cache with this transaction 293 265 * pointer in its b_fsprivate2 field, then we know we already ··· 261 303 * If the buffer is not yet read in, then we read it in, increment 262 304 * the lock recursion count, and return it to the caller. 263 305 */ 264 - bp = xfs_trans_buf_item_match(tp, target, map, nmaps); 265 - if (bp != NULL) { 306 + if (tp) 307 + bp = xfs_trans_buf_item_match(tp, target, map, nmaps); 308 + if (bp) { 266 309 ASSERT(xfs_buf_islocked(bp)); 267 310 ASSERT(bp->b_transp == tp); 268 311 ASSERT(bp->b_fspriv != NULL); 269 312 ASSERT(!bp->b_error); 270 - if (!(XFS_BUF_ISDONE(bp))) { 271 - trace_xfs_trans_read_buf_io(bp, _RET_IP_); 272 - ASSERT(!XFS_BUF_ISASYNC(bp)); 273 - ASSERT(bp->b_iodone == NULL); 274 - XFS_BUF_READ(bp); 275 - bp->b_ops = ops; 313 + ASSERT(bp->b_flags & XBF_DONE); 276 314 277 - error = xfs_buf_submit_wait(bp); 278 - if (error) { 279 - if (!XFS_FORCED_SHUTDOWN(mp)) 280 - xfs_buf_ioerror_alert(bp, __func__); 281 - xfs_buf_relse(bp); 282 - /* 283 - * We can gracefully recover from most read 284 - * errors. Ones we can't are those that happen 285 - * after the transaction's already dirty. 286 - */ 287 - if (tp->t_flags & XFS_TRANS_DIRTY) 288 - xfs_force_shutdown(tp->t_mountp, 289 - SHUTDOWN_META_IO_ERROR); 290 - /* bad CRC means corrupted metadata */ 291 - if (error == -EFSBADCRC) 292 - error = -EFSCORRUPTED; 293 - return error; 294 - } 295 - } 296 315 /* 297 316 * We never locked this buf ourselves, so we shouldn't 298 317 * brelse it either. Just get out. 299 318 */ 300 319 if (XFS_FORCED_SHUTDOWN(mp)) { 301 320 trace_xfs_trans_read_buf_shut(bp, _RET_IP_); 302 - *bpp = NULL; 303 321 return -EIO; 304 322 } 305 - 306 323 307 324 bip = bp->b_fspriv; 308 325 bip->bli_recur++; ··· 289 356 } 290 357 291 358 bp = xfs_buf_read_map(target, map, nmaps, flags, ops); 292 - if (bp == NULL) { 293 - *bpp = NULL; 294 - return (flags & XBF_TRYLOCK) ? 295 - 0 : -ENOMEM; 359 + if (!bp) { 360 + if (!(flags & XBF_TRYLOCK)) 361 + return -ENOMEM; 362 + return tp ? 0 : -EAGAIN; 296 363 } 364 + 365 + /* 366 + * If we've had a read error, then the contents of the buffer are 367 + * invalid and should not be used. To ensure that a followup read tries 368 + * to pull the buffer from disk again, we clear the XBF_DONE flag and 369 + * mark the buffer stale. This ensures that anyone who has a current 370 + * reference to the buffer will interpret it's contents correctly and 371 + * future cache lookups will also treat it as an empty, uninitialised 372 + * buffer. 373 + */ 297 374 if (bp->b_error) { 298 375 error = bp->b_error; 376 + if (!XFS_FORCED_SHUTDOWN(mp)) 377 + xfs_buf_ioerror_alert(bp, __func__); 378 + bp->b_flags &= ~XBF_DONE; 299 379 xfs_buf_stale(bp); 300 - XFS_BUF_DONE(bp); 301 - xfs_buf_ioerror_alert(bp, __func__); 302 - if (tp->t_flags & XFS_TRANS_DIRTY) 380 + 381 + if (tp && (tp->t_flags & XFS_TRANS_DIRTY)) 303 382 xfs_force_shutdown(tp->t_mountp, SHUTDOWN_META_IO_ERROR); 304 383 xfs_buf_relse(bp); 305 384 ··· 320 375 error = -EFSCORRUPTED; 321 376 return error; 322 377 } 323 - #ifdef DEBUG 324 - if (xfs_do_error && !(tp->t_flags & XFS_TRANS_DIRTY)) { 325 - if (xfs_error_target == target) { 326 - if (((xfs_req_num++) % xfs_error_mod) == 0) { 327 - xfs_force_shutdown(tp->t_mountp, 328 - SHUTDOWN_META_IO_ERROR); 329 - xfs_buf_relse(bp); 330 - xfs_debug(mp, "Returning trans error!"); 331 - return -EIO; 332 - } 333 - } 378 + 379 + if (XFS_FORCED_SHUTDOWN(mp)) { 380 + xfs_buf_relse(bp); 381 + trace_xfs_trans_read_buf_shut(bp, _RET_IP_); 382 + return -EIO; 334 383 } 335 - #endif 336 - if (XFS_FORCED_SHUTDOWN(mp)) 337 - goto shutdown_abort; 338 384 339 - _xfs_trans_bjoin(tp, bp, 1); 385 + if (tp) 386 + _xfs_trans_bjoin(tp, bp, 1); 340 387 trace_xfs_trans_read_buf(bp->b_fspriv); 341 - 342 388 *bpp = bp; 343 389 return 0; 344 390 345 - shutdown_abort: 346 - trace_xfs_trans_read_buf_shut(bp, _RET_IP_); 347 - xfs_buf_relse(bp); 348 - *bpp = NULL; 349 - return -EIO; 350 391 } 351 392 352 393 /*