Skip to content

Commit 9e208aa

Browse files
committed
Merge tag 'xfs-5.4-fixes-3' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
Pull xfs fixes from Darrick Wong: "A couple of small code cleanups and bug fixes for rounding errors, metadata logging errors, and an extra layer of safeguards against leaking memory contents. - Fix a rounding error in the fallocate code - Minor code cleanups - Make sure to zero memory buffers before formatting metadata blocks - Fix a few places where we forgot to log an inode metadata update - Remove broken error handling that tried to clean up after a failure but still got it wrong" * tag 'xfs-5.4-fixes-3' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux: xfs: move local to extent inode logging into bmap helper xfs: remove broken error handling on failed attr sf to leaf change xfs: log the inode on directory sf to block format change xfs: assure zeroed memory buffers for certain kmem allocations xfs: removed unused error variable from xchk_refcountbt_rec xfs: remove unused flags arg from xfs_get_aghdr_buf() xfs: Fix tail rounding in xfs_alloc_file_space()
2 parents fb20da6 + aeea4b7 commit 9e208aa

File tree

10 files changed

+29
-31
lines changed

10 files changed

+29
-31
lines changed

fs/xfs/libxfs/xfs_ag.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@ xfs_get_aghdr_buf(
2828
struct xfs_mount *mp,
2929
xfs_daddr_t blkno,
3030
size_t numblks,
31-
int flags,
3231
const struct xfs_buf_ops *ops)
3332
{
3433
struct xfs_buf *bp;
3534

36-
bp = xfs_buf_get_uncached(mp->m_ddev_targp, numblks, flags);
35+
bp = xfs_buf_get_uncached(mp->m_ddev_targp, numblks, 0);
3736
if (!bp)
3837
return NULL;
3938

@@ -345,7 +344,7 @@ xfs_ag_init_hdr(
345344
{
346345
struct xfs_buf *bp;
347346

348-
bp = xfs_get_aghdr_buf(mp, id->daddr, id->numblks, 0, ops);
347+
bp = xfs_get_aghdr_buf(mp, id->daddr, id->numblks, ops);
349348
if (!bp)
350349
return -ENOMEM;
351350

fs/xfs/libxfs/xfs_attr_leaf.c

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -826,32 +826,17 @@ xfs_attr_shortform_to_leaf(
826826
sf = (xfs_attr_shortform_t *)tmpbuffer;
827827

828828
xfs_idata_realloc(dp, -size, XFS_ATTR_FORK);
829-
xfs_bmap_local_to_extents_empty(dp, XFS_ATTR_FORK);
829+
xfs_bmap_local_to_extents_empty(args->trans, dp, XFS_ATTR_FORK);
830830

831831
bp = NULL;
832832
error = xfs_da_grow_inode(args, &blkno);
833-
if (error) {
834-
/*
835-
* If we hit an IO error middle of the transaction inside
836-
* grow_inode(), we may have inconsistent data. Bail out.
837-
*/
838-
if (error == -EIO)
839-
goto out;
840-
xfs_idata_realloc(dp, size, XFS_ATTR_FORK); /* try to put */
841-
memcpy(ifp->if_u1.if_data, tmpbuffer, size); /* it back */
833+
if (error)
842834
goto out;
843-
}
844835

845836
ASSERT(blkno == 0);
846837
error = xfs_attr3_leaf_create(args, blkno, &bp);
847-
if (error) {
848-
/* xfs_attr3_leaf_create may not have instantiated a block */
849-
if (bp && (xfs_da_shrink_inode(args, 0, bp) != 0))
850-
goto out;
851-
xfs_idata_realloc(dp, size, XFS_ATTR_FORK); /* try to put */
852-
memcpy(ifp->if_u1.if_data, tmpbuffer, size); /* it back */
838+
if (error)
853839
goto out;
854-
}
855840

856841
memset((char *)&nargs, 0, sizeof(nargs));
857842
nargs.dp = dp;

fs/xfs/libxfs/xfs_bmap.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,7 @@ xfs_bmap_extents_to_btree(
792792
*/
793793
void
794794
xfs_bmap_local_to_extents_empty(
795+
struct xfs_trans *tp,
795796
struct xfs_inode *ip,
796797
int whichfork)
797798
{
@@ -808,6 +809,7 @@ xfs_bmap_local_to_extents_empty(
808809
ifp->if_u1.if_root = NULL;
809810
ifp->if_height = 0;
810811
XFS_IFORK_FMT_SET(ip, whichfork, XFS_DINODE_FMT_EXTENTS);
812+
xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
811813
}
812814

813815

@@ -840,7 +842,7 @@ xfs_bmap_local_to_extents(
840842
ASSERT(XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_LOCAL);
841843

842844
if (!ifp->if_bytes) {
843-
xfs_bmap_local_to_extents_empty(ip, whichfork);
845+
xfs_bmap_local_to_extents_empty(tp, ip, whichfork);
844846
flags = XFS_ILOG_CORE;
845847
goto done;
846848
}
@@ -887,7 +889,7 @@ xfs_bmap_local_to_extents(
887889

888890
/* account for the change in fork size */
889891
xfs_idata_realloc(ip, -ifp->if_bytes, whichfork);
890-
xfs_bmap_local_to_extents_empty(ip, whichfork);
892+
xfs_bmap_local_to_extents_empty(tp, ip, whichfork);
891893
flags |= XFS_ILOG_CORE;
892894

893895
ifp->if_u1.if_root = NULL;

fs/xfs/libxfs/xfs_bmap.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ void xfs_trim_extent(struct xfs_bmbt_irec *irec, xfs_fileoff_t bno,
182182
xfs_filblks_t len);
183183
int xfs_bmap_add_attrfork(struct xfs_inode *ip, int size, int rsvd);
184184
int xfs_bmap_set_attrforkoff(struct xfs_inode *ip, int size, int *version);
185-
void xfs_bmap_local_to_extents_empty(struct xfs_inode *ip, int whichfork);
185+
void xfs_bmap_local_to_extents_empty(struct xfs_trans *tp,
186+
struct xfs_inode *ip, int whichfork);
186187
void __xfs_bmap_add_free(struct xfs_trans *tp, xfs_fsblock_t bno,
187188
xfs_filblks_t len, const struct xfs_owner_info *oinfo,
188189
bool skip_discard);

fs/xfs/libxfs/xfs_dir2_block.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,7 @@ xfs_dir2_sf_to_block(
10961096
memcpy(sfp, oldsfp, ifp->if_bytes);
10971097

10981098
xfs_idata_realloc(dp, -ifp->if_bytes, XFS_DATA_FORK);
1099-
xfs_bmap_local_to_extents_empty(dp, XFS_DATA_FORK);
1099+
xfs_bmap_local_to_extents_empty(tp, dp, XFS_DATA_FORK);
11001100
dp->i_d.di_size = 0;
11011101

11021102
/*

fs/xfs/scrub/refcount.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ xchk_refcountbt_rec(
341341
xfs_extlen_t len;
342342
xfs_nlink_t refcount;
343343
bool has_cowflag;
344-
int error = 0;
345344

346345
bno = be32_to_cpu(rec->refc.rc_startblock);
347346
len = be32_to_cpu(rec->refc.rc_blockcount);
@@ -366,7 +365,7 @@ xchk_refcountbt_rec(
366365

367366
xchk_refcountbt_xref(bs->sc, bno, len, refcount);
368367

369-
return error;
368+
return 0;
370369
}
371370

372371
/* Make sure we have as many refc blocks as the rmap says. */

fs/xfs/xfs_bmap_util.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,7 @@ xfs_alloc_file_space(
864864
xfs_filblks_t allocatesize_fsb;
865865
xfs_extlen_t extsz, temp;
866866
xfs_fileoff_t startoffset_fsb;
867+
xfs_fileoff_t endoffset_fsb;
867868
int nimaps;
868869
int quota_flag;
869870
int rt;
@@ -891,7 +892,8 @@ xfs_alloc_file_space(
891892
imapp = &imaps[0];
892893
nimaps = 1;
893894
startoffset_fsb = XFS_B_TO_FSBT(mp, offset);
894-
allocatesize_fsb = XFS_B_TO_FSB(mp, count);
895+
endoffset_fsb = XFS_B_TO_FSB(mp, offset + count);
896+
allocatesize_fsb = endoffset_fsb - startoffset_fsb;
895897

896898
/*
897899
* Allocate file space until done or until there is an error

fs/xfs/xfs_buf.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,15 @@ xfs_buf_allocate_memory(
345345
unsigned short page_count, i;
346346
xfs_off_t start, end;
347347
int error;
348+
xfs_km_flags_t kmflag_mask = 0;
349+
350+
/*
351+
* assure zeroed buffer for non-read cases.
352+
*/
353+
if (!(flags & XBF_READ)) {
354+
kmflag_mask |= KM_ZERO;
355+
gfp_mask |= __GFP_ZERO;
356+
}
348357

349358
/*
350359
* for buffers that are contained within a single page, just allocate
@@ -354,7 +363,8 @@ xfs_buf_allocate_memory(
354363
size = BBTOB(bp->b_length);
355364
if (size < PAGE_SIZE) {
356365
int align_mask = xfs_buftarg_dma_alignment(bp->b_target);
357-
bp->b_addr = kmem_alloc_io(size, align_mask, KM_NOFS);
366+
bp->b_addr = kmem_alloc_io(size, align_mask,
367+
KM_NOFS | kmflag_mask);
358368
if (!bp->b_addr) {
359369
/* low memory - use alloc_page loop instead */
360370
goto use_alloc_page;

fs/xfs/xfs_log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,7 @@ xlog_alloc_log(
14431443
prev_iclog = iclog;
14441444

14451445
iclog->ic_data = kmem_alloc_io(log->l_iclog_size, align_mask,
1446-
KM_MAYFAIL);
1446+
KM_MAYFAIL | KM_ZERO);
14471447
if (!iclog->ic_data)
14481448
goto out_free_iclog;
14491449
#ifdef DEBUG

fs/xfs/xfs_log_recover.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ xlog_alloc_buffer(
127127
if (nbblks > 1 && log->l_sectBBsize > 1)
128128
nbblks += log->l_sectBBsize;
129129
nbblks = round_up(nbblks, log->l_sectBBsize);
130-
return kmem_alloc_io(BBTOB(nbblks), align_mask, KM_MAYFAIL);
130+
return kmem_alloc_io(BBTOB(nbblks), align_mask, KM_MAYFAIL | KM_ZERO);
131131
}
132132

133133
/*

0 commit comments

Comments
 (0)