linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: linux-xfs@vger.kernel.org
Subject: [PATCH 01/14] xfs: new inode extent list lookup helpers
Date: Mon, 14 Nov 2016 18:12:32 +0100	[thread overview]
Message-ID: <1479143565-30615-2-git-send-email-hch@lst.de> (raw)
In-Reply-To: <1479143565-30615-1-git-send-email-hch@lst.de>

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>
---
 fs/xfs/libxfs/xfs_inode_fork.c | 46 ++++++++++++++++++++++++++++++++++++++++++
 fs/xfs/libxfs/xfs_inode_fork.h |  6 ++++++
 2 files changed, 52 insertions(+)

diff --git a/fs/xfs/libxfs/xfs_inode_fork.c b/fs/xfs/libxfs/xfs_inode_fork.c
index 5fbe24c..749fbfb 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(
 	ip->i_cformat = XFS_DINODE_FMT_EXTENTS;
 	ip->i_cnextents = 0;
 }
+
+/*
+ * Lookup the extent covering bno.
+ *
+ * If there is an extent covering bno return the extent index, and store the
+ * expanded extent structure in *gotp, and the extent indes in *idx.
+ * If there is no extent covering bno, but there is an extent after it (e.g.
+ * it lies in a hole) return that extent in *gotp and its index in *idx
+ * instead.
+ * If bno is beyond the last extent return false, and return the index after
+ * the last valid index in *idxp.
+ */
+bool
+xfs_iext_lookup_extent(
+	struct xfs_inode	*ip,
+	struct xfs_ifork	*ifp,
+	xfs_fileoff_t		bno,
+	xfs_extnum_t		*idxp,
+	struct xfs_bmbt_irec	*gotp)
+{
+	struct xfs_bmbt_rec_host *ep;
+
+	XFS_STATS_INC(ip->i_mount, xs_look_exlist);
+
+	ep = xfs_iext_bno_to_ext(ifp, bno, idxp);
+	if (!ep)
+		return false;
+	xfs_bmbt_get_all(ep, gotp);
+	return true;
+}
+
+/*
+ * Return true if there is an extent at index idx, and return the expanded
+ * extent structure at idx in that case.  Else return false.
+ */
+bool
+xfs_iext_get_extent(
+	struct xfs_ifork	*ifp,
+	xfs_extnum_t		idx,
+	struct xfs_bmbt_irec	*gotp)
+{
+	if (idx < 0 || idx >= xfs_iext_count(ifp))
+		return false;
+	xfs_bmbt_get_all(xfs_iext_get_ext(ifp, idx), gotp);
+	return true;
+}
diff --git a/fs/xfs/libxfs/xfs_inode_fork.h b/fs/xfs/libxfs/xfs_inode_fork.h
index 8bf112e..7fb8365 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 *);
 void		xfs_iext_irec_compact_full(struct xfs_ifork *);
 void		xfs_iext_irec_update_extoffs(struct xfs_ifork *, int, int);
 
+bool		xfs_iext_lookup_extent(struct xfs_inode *ip,
+			struct xfs_ifork *ifp, xfs_fileoff_t bno,
+			xfs_extnum_t *idxp, struct xfs_bmbt_irec *gotp);
+bool		xfs_iext_get_extent(struct xfs_ifork *ifp, xfs_extnum_t idx,
+			struct xfs_bmbt_irec *gotp);
+
 extern struct kmem_zone	*xfs_ifork_zone;
 
 extern void xfs_ifork_init_cow(struct xfs_inode *ip);
-- 
2.1.4


  reply	other threads:[~2016-11-14 17:12 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-14 17:12 new helpers to clean up extent tree lookups Christoph Hellwig
2016-11-14 17:12 ` Christoph Hellwig [this message]
2016-11-17 18:11   ` [PATCH 01/14] xfs: new inode extent list lookup helpers Brian Foster
2016-11-14 17:12 ` [PATCH 02/14] xfs: cleanup xfs_bmap_last_before Christoph Hellwig
2016-11-17 18:11   ` Brian Foster
2016-11-18  8:16     ` Christoph Hellwig
2016-11-14 17:12 ` [PATCH 03/14] xfs: use new extent lookup helpers in xfs_bmapi_read Christoph Hellwig
2016-11-17 18:11   ` Brian Foster
2016-11-14 17:12 ` [PATCH 04/14] xfs: use new extent lookup helpers in xfs_bmapi_write Christoph Hellwig
2016-11-17 18:12   ` Brian Foster
2016-11-14 17:12 ` [PATCH 05/14] xfs: use new extent lookup helpers in __xfs_bunmapi Christoph Hellwig
2016-11-17 18:12   ` Brian Foster
2016-11-14 17:12 ` [PATCH 06/14] xfs: remove prev argument to xfs_bmapi_reserve_delalloc Christoph Hellwig
2016-11-17 18:27   ` Brian Foster
2016-11-18  8:19     ` Christoph Hellwig
2016-11-18 13:19       ` Brian Foster
2016-11-14 17:12 ` [PATCH 07/14] xfs: use new extent lookup helpers xfs_file_iomap_begin_delay Christoph Hellwig
2016-11-17 18:33   ` Brian Foster
2016-11-18  8:20     ` Christoph Hellwig
2016-11-18 13:20       ` Brian Foster
2016-11-14 17:12 ` [PATCH 08/14] xfs: use new extent lookup helpers in __xfs_reflink_reserve_cow Christoph Hellwig
2016-11-17 19:07   ` Brian Foster
2016-11-14 17:12 ` [PATCH 09/14] xfs: cleanup xfs_reflink_find_cow_mapping Christoph Hellwig
2016-11-17 19:07   ` Brian Foster
2016-11-14 17:12 ` [PATCH 10/14] xfs: use new extent lookup helpers in xfs_reflink_trim_irec_to_next_cow Christoph Hellwig
2016-11-17 19:07   ` Brian Foster
2016-11-14 17:12 ` [PATCH 11/14] xfs: use new extent lookup helpers in xfs_reflink_cancel_cow_blocks Christoph Hellwig
2016-11-17 19:07   ` Brian Foster
2016-11-14 17:12 ` [PATCH 12/14] xfs: use new extent lookup helpers in xfs_reflink_end_cow Christoph Hellwig
2016-11-17 19:07   ` Brian Foster
2016-11-14 17:12 ` [PATCH 13/14] xfs: remove xfs_bmap_search_extents Christoph Hellwig
2016-11-17 19:12   ` Brian Foster
2016-11-14 17:12 ` [PATCH 14/14] xfs: remove NULLEXTNUM Christoph Hellwig
2016-11-17 19:12   ` Brian Foster
2016-11-19  0:21 ` new helpers to clean up extent tree lookups Eric Sandeen
2016-11-21 17:17   ` Christoph Hellwig
  -- strict thread matches above, loose matches on Subject: below --
2016-11-21 16:38 new helpers to clean up extent tree lookups V2 Christoph Hellwig
2016-11-21 16:38 ` [PATCH 01/14] xfs: new inode extent list lookup helpers Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1479143565-30615-2-git-send-email-hch@lst.de \
    --to=hch@lst.de \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).