Skip to content

Commit 45c76a2

Browse files
Christoph HellwigChandan Babu R
authored andcommitted
xfs: return if_data from xfs_idata_realloc
Many of the xfs_idata_realloc callers need to set a local pointer to the just reallocated if_data memory. Return the pointer to simplify them a bit and use the opportunity to re-use krealloc for freeing if_data if the size hits 0. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: "Darrick J. Wong" <djwong@kernel.org> Reviewed-by: Dave Chinner <dchinner@redhat.com> Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
1 parent 6e145f9 commit 45c76a2

File tree

4 files changed

+22
-32
lines changed

4 files changed

+22
-32
lines changed

fs/xfs/libxfs/xfs_attr_leaf.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -690,8 +690,8 @@ xfs_attr_shortform_create(
690690
ASSERT(ifp->if_bytes == 0);
691691
if (ifp->if_format == XFS_DINODE_FMT_EXTENTS)
692692
ifp->if_format = XFS_DINODE_FMT_LOCAL;
693-
xfs_idata_realloc(dp, sizeof(*hdr), XFS_ATTR_FORK);
694-
hdr = ifp->if_data;
693+
694+
hdr = xfs_idata_realloc(dp, sizeof(*hdr), XFS_ATTR_FORK);
695695
memset(hdr, 0, sizeof(*hdr));
696696
hdr->totsize = cpu_to_be16(sizeof(*hdr));
697697
xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE | XFS_ILOG_ADATA);
@@ -767,8 +767,7 @@ xfs_attr_shortform_add(
767767

768768
offset = (char *)sfe - (char *)sf;
769769
size = xfs_attr_sf_entsize_byname(args->namelen, args->valuelen);
770-
xfs_idata_realloc(dp, size, XFS_ATTR_FORK);
771-
sf = ifp->if_data;
770+
sf = xfs_idata_realloc(dp, size, XFS_ATTR_FORK);
772771
sfe = (struct xfs_attr_sf_entry *)((char *)sf + offset);
773772

774773
sfe->namelen = args->namelen;

fs/xfs/libxfs/xfs_dir2_sf.c

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -466,12 +466,11 @@ xfs_dir2_sf_addname_easy(
466466
/*
467467
* Grow the in-inode space.
468468
*/
469-
xfs_idata_realloc(dp, xfs_dir2_sf_entsize(mp, sfp, args->namelen),
469+
sfp = xfs_idata_realloc(dp, xfs_dir2_sf_entsize(mp, sfp, args->namelen),
470470
XFS_DATA_FORK);
471471
/*
472472
* Need to set up again due to realloc of the inode data.
473473
*/
474-
sfp = dp->i_df.if_data;
475474
sfep = (xfs_dir2_sf_entry_t *)((char *)sfp + byteoff);
476475
/*
477476
* Fill in the new entry.
@@ -551,11 +550,8 @@ xfs_dir2_sf_addname_hard(
551550
* the data.
552551
*/
553552
xfs_idata_realloc(dp, -old_isize, XFS_DATA_FORK);
554-
xfs_idata_realloc(dp, new_isize, XFS_DATA_FORK);
555-
/*
556-
* Reset the pointer since the buffer was reallocated.
557-
*/
558-
sfp = dp->i_df.if_data;
553+
sfp = xfs_idata_realloc(dp, new_isize, XFS_DATA_FORK);
554+
559555
/*
560556
* Copy the first part of the directory, including the header.
561557
*/
@@ -820,15 +816,13 @@ xfs_dir2_sf_create(
820816
ASSERT(dp->i_df.if_bytes == 0);
821817
i8count = pino > XFS_DIR2_MAX_SHORT_INUM;
822818
size = xfs_dir2_sf_hdr_size(i8count);
819+
823820
/*
824-
* Make a buffer for the data.
825-
*/
826-
xfs_idata_realloc(dp, size, XFS_DATA_FORK);
827-
/*
828-
* Fill in the header,
821+
* Make a buffer for the data and fill in the header.
829822
*/
830-
sfp = dp->i_df.if_data;
823+
sfp = xfs_idata_realloc(dp, size, XFS_DATA_FORK);
831824
sfp->i8count = i8count;
825+
832826
/*
833827
* Now can put in the inode number, since i8count is set.
834828
*/
@@ -976,11 +970,12 @@ xfs_dir2_sf_removename(
976970
*/
977971
sfp->count--;
978972
dp->i_disk_size = newsize;
973+
979974
/*
980975
* Reallocate, making it smaller.
981976
*/
982-
xfs_idata_realloc(dp, newsize - oldsize, XFS_DATA_FORK);
983-
sfp = dp->i_df.if_data;
977+
sfp = xfs_idata_realloc(dp, newsize - oldsize, XFS_DATA_FORK);
978+
984979
/*
985980
* Are we changing inode number size?
986981
*/

fs/xfs/libxfs/xfs_inode_fork.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ xfs_iroot_realloc(
496496
* byte_diff -- the change in the number of bytes, positive or negative,
497497
* requested for the if_data array.
498498
*/
499-
void
499+
void *
500500
xfs_idata_realloc(
501501
struct xfs_inode *ip,
502502
int64_t byte_diff,
@@ -508,19 +508,15 @@ xfs_idata_realloc(
508508
ASSERT(new_size >= 0);
509509
ASSERT(new_size <= xfs_inode_fork_size(ip, whichfork));
510510

511-
if (byte_diff == 0)
512-
return;
513-
514-
if (new_size == 0) {
515-
kmem_free(ifp->if_data);
516-
ifp->if_data = NULL;
517-
ifp->if_bytes = 0;
518-
return;
511+
if (byte_diff) {
512+
ifp->if_data = krealloc(ifp->if_data, new_size,
513+
GFP_NOFS | __GFP_NOFAIL);
514+
if (new_size == 0)
515+
ifp->if_data = NULL;
516+
ifp->if_bytes = new_size;
519517
}
520518

521-
ifp->if_data = krealloc(ifp->if_data, new_size,
522-
GFP_NOFS | __GFP_NOFAIL);
523-
ifp->if_bytes = new_size;
519+
return ifp->if_data;
524520
}
525521

526522
/* Free all memory and reset a fork back to its initial state. */

fs/xfs/libxfs/xfs_inode_fork.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ int xfs_iformat_attr_fork(struct xfs_inode *, struct xfs_dinode *);
168168
void xfs_iflush_fork(struct xfs_inode *, struct xfs_dinode *,
169169
struct xfs_inode_log_item *, int);
170170
void xfs_idestroy_fork(struct xfs_ifork *ifp);
171-
void xfs_idata_realloc(struct xfs_inode *ip, int64_t byte_diff,
171+
void * xfs_idata_realloc(struct xfs_inode *ip, int64_t byte_diff,
172172
int whichfork);
173173
void xfs_iroot_realloc(struct xfs_inode *, int, int);
174174
int xfs_iread_extents(struct xfs_trans *, struct xfs_inode *, int);

0 commit comments

Comments
 (0)