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