Skip to content

Commit a8414fa

Browse files
committed
Merge tag 'xfs-iomap-for-linus-4.8-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/dgc/linux-xfs
Pull xfs and iomap fixes from Dave Chinner: "Changes in this update: Regression fixes for XFS changes introduce in 4.8-rc1: - buffer IO accounting assert failure - ENOSPC block accounting reservation issue - DAX IO path page cache invalidation fix - rmapbt on-disk block count in agf - correct classification of rmap block type when updating AGFL. - iomap support for attribute fork mapping Regression fixes for iomap infrastructure in 4.8-rc1: - fiemap: honor FIEMAP_FLAG_SYNC - fiemap: implement FIEMAP_FLAG_XATTR support to fix XFS regression - make mark_page_accessed and pagefault_disable usage consistent with other IO paths" * tag 'xfs-iomap-for-linus-4.8-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/dgc/linux-xfs: xfs: remove OWN_AG rmap when allocating a block from the AGFL xfs: (re-)implement FIEMAP_FLAG_XATTR xfs: simplify xfs_file_iomap_begin iomap: mark ->iomap_end as optional iomap: prepare iomap_fiemap for attribute mappings iomap: fiemap should honor the FIEMAP_FLAG_SYNC flag iomap: remove superflous pagefault_disable from iomap_write_actor iomap: remove superflous mark_page_accessed from iomap_write_actor xfs: store rmapbt block count in the AGF xfs: don't invalidate whole file on DAX read/write xfs: fix bogus space reservation in xfs_iomap_write_allocate xfs: don't assert fail on non-async buffers on ioacct decrement
2 parents 3f318b3 + 32438cf commit a8414fa

File tree

11 files changed

+119
-28
lines changed

11 files changed

+119
-28
lines changed

fs/iomap.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,11 @@ iomap_apply(struct inode *inode, loff_t pos, loff_t length, unsigned flags,
8484
* Now the data has been copied, commit the range we've copied. This
8585
* should not fail unless the filesystem has had a fatal error.
8686
*/
87-
ret = ops->iomap_end(inode, pos, length, written > 0 ? written : 0,
88-
flags, &iomap);
87+
if (ops->iomap_end) {
88+
ret = ops->iomap_end(inode, pos, length,
89+
written > 0 ? written : 0,
90+
flags, &iomap);
91+
}
8992

9093
return written ? written : ret;
9194
}
@@ -194,12 +197,9 @@ iomap_write_actor(struct inode *inode, loff_t pos, loff_t length, void *data,
194197
if (mapping_writably_mapped(inode->i_mapping))
195198
flush_dcache_page(page);
196199

197-
pagefault_disable();
198200
copied = iov_iter_copy_from_user_atomic(page, i, offset, bytes);
199-
pagefault_enable();
200201

201202
flush_dcache_page(page);
202-
mark_page_accessed(page);
203203

204204
status = iomap_write_end(inode, pos, bytes, copied, page);
205205
if (unlikely(status < 0))
@@ -470,13 +470,18 @@ int iomap_fiemap(struct inode *inode, struct fiemap_extent_info *fi,
470470
if (ret)
471471
return ret;
472472

473-
ret = filemap_write_and_wait(inode->i_mapping);
474-
if (ret)
475-
return ret;
473+
if (fi->fi_flags & FIEMAP_FLAG_SYNC) {
474+
ret = filemap_write_and_wait(inode->i_mapping);
475+
if (ret)
476+
return ret;
477+
}
476478

477479
while (len > 0) {
478480
ret = iomap_apply(inode, start, len, 0, ops, &ctx,
479481
iomap_fiemap_actor);
482+
/* inode with no (attribute) mapping will give ENOENT */
483+
if (ret == -ENOENT)
484+
break;
480485
if (ret < 0)
481486
return ret;
482487
if (ret == 0)

fs/xfs/libxfs/xfs_alloc.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,6 +1582,7 @@ xfs_alloc_ag_vextent_small(
15821582
xfs_extlen_t *flenp, /* result length */
15831583
int *stat) /* status: 0-freelist, 1-normal/none */
15841584
{
1585+
struct xfs_owner_info oinfo;
15851586
int error;
15861587
xfs_agblock_t fbno;
15871588
xfs_extlen_t flen;
@@ -1624,6 +1625,18 @@ xfs_alloc_ag_vextent_small(
16241625
error0);
16251626
args->wasfromfl = 1;
16261627
trace_xfs_alloc_small_freelist(args);
1628+
1629+
/*
1630+
* If we're feeding an AGFL block to something that
1631+
* doesn't live in the free space, we need to clear
1632+
* out the OWN_AG rmap.
1633+
*/
1634+
xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_AG);
1635+
error = xfs_rmap_free(args->tp, args->agbp, args->agno,
1636+
fbno, 1, &oinfo);
1637+
if (error)
1638+
goto error0;
1639+
16271640
*stat = 0;
16281641
return 0;
16291642
}
@@ -2264,6 +2277,7 @@ xfs_alloc_log_agf(
22642277
offsetof(xfs_agf_t, agf_longest),
22652278
offsetof(xfs_agf_t, agf_btreeblks),
22662279
offsetof(xfs_agf_t, agf_uuid),
2280+
offsetof(xfs_agf_t, agf_rmap_blocks),
22672281
sizeof(xfs_agf_t)
22682282
};
22692283

fs/xfs/libxfs/xfs_format.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -640,12 +640,15 @@ typedef struct xfs_agf {
640640
__be32 agf_btreeblks; /* # of blocks held in AGF btrees */
641641
uuid_t agf_uuid; /* uuid of filesystem */
642642

643+
__be32 agf_rmap_blocks; /* rmapbt blocks used */
644+
__be32 agf_padding; /* padding */
645+
643646
/*
644647
* reserve some contiguous space for future logged fields before we add
645648
* the unlogged fields. This makes the range logging via flags and
646649
* structure offsets much simpler.
647650
*/
648-
__be64 agf_spare64[16];
651+
__be64 agf_spare64[15];
649652

650653
/* unlogged fields, written during buffer writeback. */
651654
__be64 agf_lsn; /* last write sequence */
@@ -670,7 +673,8 @@ typedef struct xfs_agf {
670673
#define XFS_AGF_LONGEST 0x00000400
671674
#define XFS_AGF_BTREEBLKS 0x00000800
672675
#define XFS_AGF_UUID 0x00001000
673-
#define XFS_AGF_NUM_BITS 13
676+
#define XFS_AGF_RMAP_BLOCKS 0x00002000
677+
#define XFS_AGF_NUM_BITS 14
674678
#define XFS_AGF_ALL_BITS ((1 << XFS_AGF_NUM_BITS) - 1)
675679

676680
#define XFS_AGF_FLAGS \
@@ -686,7 +690,8 @@ typedef struct xfs_agf {
686690
{ XFS_AGF_FREEBLKS, "FREEBLKS" }, \
687691
{ XFS_AGF_LONGEST, "LONGEST" }, \
688692
{ XFS_AGF_BTREEBLKS, "BTREEBLKS" }, \
689-
{ XFS_AGF_UUID, "UUID" }
693+
{ XFS_AGF_UUID, "UUID" }, \
694+
{ XFS_AGF_RMAP_BLOCKS, "RMAP_BLOCKS" }
690695

691696
/* disk block (xfs_daddr_t) in the AG */
692697
#define XFS_AGF_DADDR(mp) ((xfs_daddr_t)(1 << (mp)->m_sectbb_log))

fs/xfs/libxfs/xfs_rmap_btree.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ xfs_rmapbt_alloc_block(
9898
union xfs_btree_ptr *new,
9999
int *stat)
100100
{
101+
struct xfs_buf *agbp = cur->bc_private.a.agbp;
102+
struct xfs_agf *agf = XFS_BUF_TO_AGF(agbp);
101103
int error;
102104
xfs_agblock_t bno;
103105

@@ -124,6 +126,8 @@ xfs_rmapbt_alloc_block(
124126

125127
xfs_trans_agbtree_delta(cur->bc_tp, 1);
126128
new->s = cpu_to_be32(bno);
129+
be32_add_cpu(&agf->agf_rmap_blocks, 1);
130+
xfs_alloc_log_agf(cur->bc_tp, agbp, XFS_AGF_RMAP_BLOCKS);
127131

128132
XFS_BTREE_TRACE_CURSOR(cur, XBT_EXIT);
129133
*stat = 1;
@@ -143,6 +147,8 @@ xfs_rmapbt_free_block(
143147
bno = xfs_daddr_to_agbno(cur->bc_mp, XFS_BUF_ADDR(bp));
144148
trace_xfs_rmapbt_free_block(cur->bc_mp, cur->bc_private.a.agno,
145149
bno, 1);
150+
be32_add_cpu(&agf->agf_rmap_blocks, -1);
151+
xfs_alloc_log_agf(cur->bc_tp, agbp, XFS_AGF_RMAP_BLOCKS);
146152
error = xfs_alloc_put_freelist(cur->bc_tp, agbp, NULL, bno, 1);
147153
if (error)
148154
return error;

fs/xfs/xfs_buf.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ xfs_buf_ioacct_dec(
115115
if (!(bp->b_flags & _XBF_IN_FLIGHT))
116116
return;
117117

118-
ASSERT(bp->b_flags & XBF_ASYNC);
119118
bp->b_flags &= ~_XBF_IN_FLIGHT;
120119
percpu_counter_dec(&bp->b_target->bt_io_count);
121120
}

fs/xfs/xfs_file.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,9 +741,20 @@ xfs_file_dax_write(
741741
* page is inserted into the pagecache when we have to serve a write
742742
* fault on a hole. It should never be dirtied and can simply be
743743
* dropped from the pagecache once we get real data for the page.
744+
*
745+
* XXX: This is racy against mmap, and there's nothing we can do about
746+
* it. dax_do_io() should really do this invalidation internally as
747+
* it will know if we've allocated over a holei for this specific IO and
748+
* if so it needs to update the mapping tree and invalidate existing
749+
* PTEs over the newly allocated range. Remove this invalidation when
750+
* dax_do_io() is fixed up.
744751
*/
745752
if (mapping->nrpages) {
746-
ret = invalidate_inode_pages2(mapping);
753+
loff_t end = iocb->ki_pos + iov_iter_count(from) - 1;
754+
755+
ret = invalidate_inode_pages2_range(mapping,
756+
iocb->ki_pos >> PAGE_SHIFT,
757+
end >> PAGE_SHIFT);
747758
WARN_ON_ONCE(ret);
748759
}
749760

fs/xfs/xfs_fsops.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ xfs_growfs_data_private(
248248
agf->agf_roots[XFS_BTNUM_RMAPi] =
249249
cpu_to_be32(XFS_RMAP_BLOCK(mp));
250250
agf->agf_levels[XFS_BTNUM_RMAPi] = cpu_to_be32(1);
251+
agf->agf_rmap_blocks = cpu_to_be32(1);
251252
}
252253

253254
agf->agf_flfirst = cpu_to_be32(1);

fs/xfs/xfs_iomap.c

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -715,12 +715,16 @@ xfs_iomap_write_allocate(
715715
* is in the delayed allocation extent on which we sit
716716
* but before our buffer starts.
717717
*/
718-
719718
nimaps = 0;
720719
while (nimaps == 0) {
721720
nres = XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK);
722-
723-
error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, nres,
721+
/*
722+
* We have already reserved space for the extent and any
723+
* indirect blocks when creating the delalloc extent,
724+
* there is no need to reserve space in this transaction
725+
* again.
726+
*/
727+
error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, 0,
724728
0, XFS_TRANS_RESERVE, &tp);
725729
if (error)
726730
return error;
@@ -1037,20 +1041,14 @@ xfs_file_iomap_begin(
10371041
return error;
10381042

10391043
trace_xfs_iomap_alloc(ip, offset, length, 0, &imap);
1040-
xfs_bmbt_to_iomap(ip, iomap, &imap);
1041-
} else if (nimaps) {
1042-
xfs_iunlock(ip, XFS_ILOCK_EXCL);
1043-
trace_xfs_iomap_found(ip, offset, length, 0, &imap);
1044-
xfs_bmbt_to_iomap(ip, iomap, &imap);
10451044
} else {
1045+
ASSERT(nimaps);
1046+
10461047
xfs_iunlock(ip, XFS_ILOCK_EXCL);
1047-
trace_xfs_iomap_not_found(ip, offset, length, 0, &imap);
1048-
iomap->blkno = IOMAP_NULL_BLOCK;
1049-
iomap->type = IOMAP_HOLE;
1050-
iomap->offset = offset;
1051-
iomap->length = length;
1048+
trace_xfs_iomap_found(ip, offset, length, 0, &imap);
10521049
}
10531050

1051+
xfs_bmbt_to_iomap(ip, iomap, &imap);
10541052
return 0;
10551053
}
10561054

@@ -1112,3 +1110,48 @@ struct iomap_ops xfs_iomap_ops = {
11121110
.iomap_begin = xfs_file_iomap_begin,
11131111
.iomap_end = xfs_file_iomap_end,
11141112
};
1113+
1114+
static int
1115+
xfs_xattr_iomap_begin(
1116+
struct inode *inode,
1117+
loff_t offset,
1118+
loff_t length,
1119+
unsigned flags,
1120+
struct iomap *iomap)
1121+
{
1122+
struct xfs_inode *ip = XFS_I(inode);
1123+
struct xfs_mount *mp = ip->i_mount;
1124+
xfs_fileoff_t offset_fsb = XFS_B_TO_FSBT(mp, offset);
1125+
xfs_fileoff_t end_fsb = XFS_B_TO_FSB(mp, offset + length);
1126+
struct xfs_bmbt_irec imap;
1127+
int nimaps = 1, error = 0;
1128+
unsigned lockmode;
1129+
1130+
if (XFS_FORCED_SHUTDOWN(mp))
1131+
return -EIO;
1132+
1133+
lockmode = xfs_ilock_data_map_shared(ip);
1134+
1135+
/* if there are no attribute fork or extents, return ENOENT */
1136+
if (XFS_IFORK_Q(ip) || !ip->i_d.di_anextents) {
1137+
error = -ENOENT;
1138+
goto out_unlock;
1139+
}
1140+
1141+
ASSERT(ip->i_d.di_aformat != XFS_DINODE_FMT_LOCAL);
1142+
error = xfs_bmapi_read(ip, offset_fsb, end_fsb - offset_fsb, &imap,
1143+
&nimaps, XFS_BMAPI_ENTIRE | XFS_BMAPI_ATTRFORK);
1144+
out_unlock:
1145+
xfs_iunlock(ip, lockmode);
1146+
1147+
if (!error) {
1148+
ASSERT(nimaps);
1149+
xfs_bmbt_to_iomap(ip, iomap, &imap);
1150+
}
1151+
1152+
return error;
1153+
}
1154+
1155+
struct iomap_ops xfs_xattr_iomap_ops = {
1156+
.iomap_begin = xfs_xattr_iomap_begin,
1157+
};

fs/xfs/xfs_iomap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ void xfs_bmbt_to_iomap(struct xfs_inode *, struct iomap *,
3535
struct xfs_bmbt_irec *);
3636

3737
extern struct iomap_ops xfs_iomap_ops;
38+
extern struct iomap_ops xfs_xattr_iomap_ops;
3839

3940
#endif /* __XFS_IOMAP_H__*/

fs/xfs/xfs_iops.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,14 @@ xfs_vn_fiemap(
10091009
int error;
10101010

10111011
xfs_ilock(XFS_I(inode), XFS_IOLOCK_SHARED);
1012-
error = iomap_fiemap(inode, fieinfo, start, length, &xfs_iomap_ops);
1012+
if (fieinfo->fi_flags & FIEMAP_FLAG_XATTR) {
1013+
fieinfo->fi_flags &= ~FIEMAP_FLAG_XATTR;
1014+
error = iomap_fiemap(inode, fieinfo, start, length,
1015+
&xfs_xattr_iomap_ops);
1016+
} else {
1017+
error = iomap_fiemap(inode, fieinfo, start, length,
1018+
&xfs_iomap_ops);
1019+
}
10131020
xfs_iunlock(XFS_I(inode), XFS_IOLOCK_SHARED);
10141021

10151022
return error;

fs/xfs/xfs_trace.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,6 @@ DEFINE_IOMAP_EVENT(xfs_get_blocks_alloc);
12981298
DEFINE_IOMAP_EVENT(xfs_get_blocks_map_direct);
12991299
DEFINE_IOMAP_EVENT(xfs_iomap_alloc);
13001300
DEFINE_IOMAP_EVENT(xfs_iomap_found);
1301-
DEFINE_IOMAP_EVENT(xfs_iomap_not_found);
13021301

13031302
DECLARE_EVENT_CLASS(xfs_simple_io_class,
13041303
TP_PROTO(struct xfs_inode *ip, xfs_off_t offset, ssize_t count),

0 commit comments

Comments
 (0)