Commit 3d99a1ce authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Darrick J. Wong

iomap: switch iomap_swapfile_activate to use iomap_iter

Switch iomap_swapfile_activate 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 c4740bf1
...@@ -88,13 +88,9 @@ static int iomap_swapfile_fail(struct iomap_swapfile_info *isi, const char *str) ...@@ -88,13 +88,9 @@ static int iomap_swapfile_fail(struct iomap_swapfile_info *isi, const char *str)
* swap only cares about contiguous page-aligned physical extents and makes no * swap only cares about contiguous page-aligned physical extents and makes no
* distinction between written and unwritten extents. * distinction between written and unwritten extents.
*/ */
static loff_t iomap_swapfile_activate_actor(struct inode *inode, loff_t pos, static loff_t iomap_swapfile_iter(const struct iomap_iter *iter,
loff_t count, void *data, struct iomap *iomap, struct iomap *iomap, struct iomap_swapfile_info *isi)
struct iomap *srcmap)
{ {
struct iomap_swapfile_info *isi = data;
int error;
switch (iomap->type) { switch (iomap->type) {
case IOMAP_MAPPED: case IOMAP_MAPPED:
case IOMAP_UNWRITTEN: case IOMAP_UNWRITTEN:
...@@ -125,12 +121,12 @@ static loff_t iomap_swapfile_activate_actor(struct inode *inode, loff_t pos, ...@@ -125,12 +121,12 @@ static loff_t iomap_swapfile_activate_actor(struct inode *inode, loff_t pos,
isi->iomap.length += iomap->length; isi->iomap.length += iomap->length;
} else { } else {
/* Otherwise, add the retained iomap and store this one. */ /* Otherwise, add the retained iomap and store this one. */
error = iomap_swapfile_add_extent(isi); int error = iomap_swapfile_add_extent(isi);
if (error) if (error)
return error; return error;
memcpy(&isi->iomap, iomap, sizeof(isi->iomap)); memcpy(&isi->iomap, iomap, sizeof(isi->iomap));
} }
return count; return iomap_length(iter);
} }
/* /*
...@@ -141,16 +137,19 @@ int iomap_swapfile_activate(struct swap_info_struct *sis, ...@@ -141,16 +137,19 @@ int iomap_swapfile_activate(struct swap_info_struct *sis,
struct file *swap_file, sector_t *pagespan, struct file *swap_file, sector_t *pagespan,
const struct iomap_ops *ops) const struct iomap_ops *ops)
{ {
struct inode *inode = swap_file->f_mapping->host;
struct iomap_iter iter = {
.inode = inode,
.pos = 0,
.len = ALIGN_DOWN(i_size_read(inode), PAGE_SIZE),
.flags = IOMAP_REPORT,
};
struct iomap_swapfile_info isi = { struct iomap_swapfile_info isi = {
.sis = sis, .sis = sis,
.lowest_ppage = (sector_t)-1ULL, .lowest_ppage = (sector_t)-1ULL,
.file = swap_file, .file = swap_file,
}; };
struct address_space *mapping = swap_file->f_mapping; int ret;
struct inode *inode = mapping->host;
loff_t pos = 0;
loff_t len = ALIGN_DOWN(i_size_read(inode), PAGE_SIZE);
loff_t ret;
/* /*
* Persist all file mapping metadata so that we won't have any * Persist all file mapping metadata so that we won't have any
...@@ -160,16 +159,11 @@ int iomap_swapfile_activate(struct swap_info_struct *sis, ...@@ -160,16 +159,11 @@ int iomap_swapfile_activate(struct swap_info_struct *sis,
if (ret) if (ret)
return ret; return ret;
while (len > 0) { while ((ret = iomap_iter(&iter, ops)) > 0)
ret = iomap_apply(inode, pos, len, IOMAP_REPORT, iter.processed = iomap_swapfile_iter(&iter, &iter.iomap, &isi);
ops, &isi, iomap_swapfile_activate_actor); if (ret < 0)
if (ret <= 0)
return ret; return ret;
pos += ret;
len -= ret;
}
if (isi.iomap.length) { if (isi.iomap.length) {
ret = iomap_swapfile_add_extent(&isi); ret = iomap_swapfile_add_extent(&isi);
if (ret) if (ret)
......
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