Commit 40670d18 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Darrick J. Wong

iomap: switch iomap_seek_hole to use iomap_iter

Rewrite iomap_seek_hole to use iomap_iter.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDarrick J. Wong <djwong@kernel.org>
Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
parent 6d8a1287
// SPDX-License-Identifier: GPL-2.0 // SPDX-License-Identifier: GPL-2.0
/* /*
* Copyright (C) 2017 Red Hat, Inc. * Copyright (C) 2017 Red Hat, Inc.
* Copyright (c) 2018 Christoph Hellwig. * Copyright (c) 2018-2021 Christoph Hellwig.
*/ */
#include <linux/module.h> #include <linux/module.h>
#include <linux/compiler.h> #include <linux/compiler.h>
...@@ -10,21 +10,20 @@ ...@@ -10,21 +10,20 @@
#include <linux/pagemap.h> #include <linux/pagemap.h>
#include <linux/pagevec.h> #include <linux/pagevec.h>
static loff_t static loff_t iomap_seek_hole_iter(const struct iomap_iter *iter,
iomap_seek_hole_actor(struct inode *inode, loff_t start, loff_t length, loff_t *hole_pos)
void *data, struct iomap *iomap, struct iomap *srcmap)
{ {
loff_t offset = start; loff_t length = iomap_length(iter);
switch (iomap->type) { switch (iter->iomap.type) {
case IOMAP_UNWRITTEN: case IOMAP_UNWRITTEN:
offset = mapping_seek_hole_data(inode->i_mapping, start, *hole_pos = mapping_seek_hole_data(iter->inode->i_mapping,
start + length, SEEK_HOLE); iter->pos, iter->pos + length, SEEK_HOLE);
if (offset == start + length) if (*hole_pos == iter->pos + length)
return length; return length;
fallthrough; return 0;
case IOMAP_HOLE: case IOMAP_HOLE:
*(loff_t *)data = offset; *hole_pos = iter->pos;
return 0; return 0;
default: default:
return length; return length;
...@@ -32,26 +31,28 @@ iomap_seek_hole_actor(struct inode *inode, loff_t start, loff_t length, ...@@ -32,26 +31,28 @@ iomap_seek_hole_actor(struct inode *inode, loff_t start, loff_t length,
} }
loff_t loff_t
iomap_seek_hole(struct inode *inode, loff_t offset, const struct iomap_ops *ops) iomap_seek_hole(struct inode *inode, loff_t pos, const struct iomap_ops *ops)
{ {
loff_t size = i_size_read(inode); 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. */ /* Nothing to be found before or beyond the end of the file. */
if (offset < 0 || offset >= size) if (pos < 0 || pos >= size)
return -ENXIO; return -ENXIO;
while (offset < size) { iter.len = size - pos;
ret = iomap_apply(inode, offset, size - offset, IOMAP_REPORT, while ((ret = iomap_iter(&iter, ops)) > 0)
ops, &offset, iomap_seek_hole_actor); iter.processed = iomap_seek_hole_iter(&iter, &pos);
if (ret < 0) if (ret < 0)
return ret; return ret;
if (ret == 0) if (iter.len) /* found hole before EOF */
break; return pos;
offset += ret; return size;
}
return offset;
} }
EXPORT_SYMBOL_GPL(iomap_seek_hole); EXPORT_SYMBOL_GPL(iomap_seek_hole);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment