aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2017-01-09 10:38:39 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-01-12 05:39:40 -0500
commit49dc19915d3b0893a698a2d78f732beaff119a4d (patch)
tree7768a9e28068497b9d216a62a432edfab3d64577 /fs
parentb49ef758f6003a7ed0afb37b33fc96e238752497 (diff)
xfs: new inode extent list lookup helpers
commit 93533c7855c3c78c8a900cac65c8d669bb14935d upstream. xfs_iext_lookup_extent looks up a single extent at the passed in offset, and returns the extent covering the area, or the one behind it in case of a hole, as well as the index of the returned extent in arguments, as well as a simple bool as return value that is set to false if no extent could be found because the offset is behind EOF. It is a simpler replacement for xfs_bmap_search_extent that leaves looking up the rarely needed previous extent to the caller and has a nicer calling convention. xfs_iext_get_extent is a helper for iterating over the extent list, it takes an extent index as input, and returns the extent at that index in it's expanded form in an argument if it exists. The actual return value is a bool whether the index is valid or not. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Brian Foster <bfoster@redhat.com> Signed-off-by: Dave Chinner <david@fromorbit.com> Cc: Christoph Hellwig <hch@lst.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/xfs/libxfs/xfs_inode_fork.c46
-rw-r--r--fs/xfs/libxfs/xfs_inode_fork.h6
2 files changed, 52 insertions, 0 deletions
diff --git a/fs/xfs/libxfs/xfs_inode_fork.c b/fs/xfs/libxfs/xfs_inode_fork.c
index 5fbe24c31679..222e103356c6 100644
--- a/fs/xfs/libxfs/xfs_inode_fork.c
+++ b/fs/xfs/libxfs/xfs_inode_fork.c
@@ -2003,3 +2003,49 @@ xfs_ifork_init_cow(
2003 ip->i_cformat = XFS_DINODE_FMT_EXTENTS; 2003 ip->i_cformat = XFS_DINODE_FMT_EXTENTS;
2004 ip->i_cnextents = 0; 2004 ip->i_cnextents = 0;
2005} 2005}
2006
2007/*
2008 * Lookup the extent covering bno.
2009 *
2010 * If there is an extent covering bno return the extent index, and store the
2011 * expanded extent structure in *gotp, and the extent index in *idx.
2012 * If there is no extent covering bno, but there is an extent after it (e.g.
2013 * it lies in a hole) return that extent in *gotp and its index in *idx
2014 * instead.
2015 * If bno is beyond the last extent return false, and return the index after
2016 * the last valid index in *idxp.
2017 */
2018bool
2019xfs_iext_lookup_extent(
2020 struct xfs_inode *ip,
2021 struct xfs_ifork *ifp,
2022 xfs_fileoff_t bno,
2023 xfs_extnum_t *idxp,
2024 struct xfs_bmbt_irec *gotp)
2025{
2026 struct xfs_bmbt_rec_host *ep;
2027
2028 XFS_STATS_INC(ip->i_mount, xs_look_exlist);
2029
2030 ep = xfs_iext_bno_to_ext(ifp, bno, idxp);
2031 if (!ep)
2032 return false;
2033 xfs_bmbt_get_all(ep, gotp);
2034 return true;
2035}
2036
2037/*
2038 * Return true if there is an extent at index idx, and return the expanded
2039 * extent structure at idx in that case. Else return false.
2040 */
2041bool
2042xfs_iext_get_extent(
2043 struct xfs_ifork *ifp,
2044 xfs_extnum_t idx,
2045 struct xfs_bmbt_irec *gotp)
2046{
2047 if (idx < 0 || idx >= xfs_iext_count(ifp))
2048 return false;
2049 xfs_bmbt_get_all(xfs_iext_get_ext(ifp, idx), gotp);
2050 return true;
2051}
diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h
index 8bf112e29aa1..7fb8365326d1 100644
--- a/fs/xfs/libxfs/xfs_inode_fork.h
+++ b/fs/xfs/libxfs/xfs_inode_fork.h
@@ -182,6 +182,12 @@ void xfs_iext_irec_compact_pages(struct xfs_ifork *);
182void xfs_iext_irec_compact_full(struct xfs_ifork *); 182void xfs_iext_irec_compact_full(struct xfs_ifork *);
183void xfs_iext_irec_update_extoffs(struct xfs_ifork *, int, int); 183void xfs_iext_irec_update_extoffs(struct xfs_ifork *, int, int);
184 184
185bool xfs_iext_lookup_extent(struct xfs_inode *ip,
186 struct xfs_ifork *ifp, xfs_fileoff_t bno,
187 xfs_extnum_t *idxp, struct xfs_bmbt_irec *gotp);
188bool xfs_iext_get_extent(struct xfs_ifork *ifp, xfs_extnum_t idx,
189 struct xfs_bmbt_irec *gotp);
190
185extern struct kmem_zone *xfs_ifork_zone; 191extern struct kmem_zone *xfs_ifork_zone;
186 192
187extern void xfs_ifork_init_cow(struct xfs_inode *ip); 193extern void xfs_ifork_init_cow(struct xfs_inode *ip);