Message ID | 20210809061244.1196573-22-hch@lst.de (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [01/30] iomap: fix a trivial comment typo in trace.h | expand |
On Mon, Aug 09, 2021 at 08:12:35AM +0200, Christoph Hellwig wrote: > Rewrite iomap_seek_data to use iomap_iter. > > Signed-off-by: Christoph Hellwig <hch@lst.de> Nice cleanup, Reviewed-by: Darrick J. Wong <djwong@kernel.org> --D > --- > fs/iomap/seek.c | 47 ++++++++++++++++++++++++----------------------- > 1 file changed, 24 insertions(+), 23 deletions(-) > > diff --git a/fs/iomap/seek.c b/fs/iomap/seek.c > index fed8f9005f9e46..a845c012b50c67 100644 > --- a/fs/iomap/seek.c > +++ b/fs/iomap/seek.c > @@ -56,47 +56,48 @@ iomap_seek_hole(struct inode *inode, loff_t pos, const struct iomap_ops *ops) > } > EXPORT_SYMBOL_GPL(iomap_seek_hole); > > -static loff_t > -iomap_seek_data_actor(struct inode *inode, loff_t start, loff_t length, > - void *data, struct iomap *iomap, struct iomap *srcmap) > +static loff_t iomap_seek_data_iter(const struct iomap_iter *iter, > + loff_t *hole_pos) > { > - loff_t offset = start; > + loff_t length = iomap_length(iter); > > - switch (iomap->type) { > + switch (iter->iomap.type) { > case IOMAP_HOLE: > return length; > case IOMAP_UNWRITTEN: > - offset = mapping_seek_hole_data(inode->i_mapping, start, > - start + length, SEEK_DATA); > - if (offset < 0) > + *hole_pos = mapping_seek_hole_data(iter->inode->i_mapping, > + iter->pos, iter->pos + length, SEEK_DATA); > + if (*hole_pos < 0) > return length; > - fallthrough; > + return 0; > default: > - *(loff_t *)data = offset; > + *hole_pos = iter->pos; > return 0; > } > } > > loff_t > -iomap_seek_data(struct inode *inode, loff_t offset, const struct iomap_ops *ops) > +iomap_seek_data(struct inode *inode, loff_t pos, const struct iomap_ops *ops) > { > loff_t size = i_size_read(inode); > - loff_t ret; > + struct iomap_iter iter = { > + .inode = inode, > + .pos = pos, > + .flags = IOMAP_REPORT, > + }; > + int ret; > > /* Nothing to be found before or beyond the end of the file. */ > - if (offset < 0 || offset >= size) > + if (pos < 0 || pos >= size) > return -ENXIO; > > - while (offset < size) { > - ret = iomap_apply(inode, offset, size - offset, IOMAP_REPORT, > - ops, &offset, iomap_seek_data_actor); > - if (ret < 0) > - return ret; > - if (ret == 0) > - return offset; > - offset += ret; > - } > - > + iter.len = size - pos; > + while ((ret = iomap_iter(&iter, ops)) > 0) > + iter.processed = iomap_seek_data_iter(&iter, &pos); > + if (ret < 0) > + return ret; > + if (iter.len) /* found data before EOF */ > + return pos; > /* We've reached the end of the file without finding data */ > return -ENXIO; > } > -- > 2.30.2 >
diff --git a/fs/iomap/seek.c b/fs/iomap/seek.c index fed8f9005f9e46..a845c012b50c67 100644 --- a/fs/iomap/seek.c +++ b/fs/iomap/seek.c @@ -56,47 +56,48 @@ iomap_seek_hole(struct inode *inode, loff_t pos, const struct iomap_ops *ops) } EXPORT_SYMBOL_GPL(iomap_seek_hole); -static loff_t -iomap_seek_data_actor(struct inode *inode, loff_t start, loff_t length, - void *data, struct iomap *iomap, struct iomap *srcmap) +static loff_t iomap_seek_data_iter(const struct iomap_iter *iter, + loff_t *hole_pos) { - loff_t offset = start; + loff_t length = iomap_length(iter); - switch (iomap->type) { + switch (iter->iomap.type) { case IOMAP_HOLE: return length; case IOMAP_UNWRITTEN: - offset = mapping_seek_hole_data(inode->i_mapping, start, - start + length, SEEK_DATA); - if (offset < 0) + *hole_pos = mapping_seek_hole_data(iter->inode->i_mapping, + iter->pos, iter->pos + length, SEEK_DATA); + if (*hole_pos < 0) return length; - fallthrough; + return 0; default: - *(loff_t *)data = offset; + *hole_pos = iter->pos; return 0; } } loff_t -iomap_seek_data(struct inode *inode, loff_t offset, const struct iomap_ops *ops) +iomap_seek_data(struct inode *inode, loff_t pos, const struct iomap_ops *ops) { loff_t size = i_size_read(inode); - loff_t ret; + struct iomap_iter iter = { + .inode = inode, + .pos = pos, + .flags = IOMAP_REPORT, + }; + int ret; /* Nothing to be found before or beyond the end of the file. */ - if (offset < 0 || offset >= size) + if (pos < 0 || pos >= size) return -ENXIO; - while (offset < size) { - ret = iomap_apply(inode, offset, size - offset, IOMAP_REPORT, - ops, &offset, iomap_seek_data_actor); - if (ret < 0) - return ret; - if (ret == 0) - return offset; - offset += ret; - } - + iter.len = size - pos; + while ((ret = iomap_iter(&iter, ops)) > 0) + iter.processed = iomap_seek_data_iter(&iter, &pos); + if (ret < 0) + return ret; + if (iter.len) /* found data before EOF */ + return pos; /* We've reached the end of the file without finding data */ return -ENXIO; }
Rewrite iomap_seek_data to use iomap_iter. Signed-off-by: Christoph Hellwig <hch@lst.de> --- fs/iomap/seek.c | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-)