Skip to content

Commit b34b95e

Browse files
committed
Merge tag 'iomap-5.13-merge-2' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
Pull iomap update from Darrick Wong: "A single patch to the iomap code, which augments what gets logged when someone tries to swapon an unacceptable swap file. (Yes, this is a continuation of the swapfile drama from last season...)" * tag 'iomap-5.13-merge-2' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux: iomap: improve the warnings from iomap_swapfile_activate
2 parents a4f7fae + ad89b66 commit b34b95e

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

fs/iomap/swapfile.c

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ struct iomap_swapfile_info {
1818
uint64_t highest_ppage; /* highest physical addr seen (pages) */
1919
unsigned long nr_pages; /* number of pages collected */
2020
int nr_extents; /* extent count */
21+
struct file *file;
2122
};
2223

2324
/*
@@ -70,6 +71,18 @@ static int iomap_swapfile_add_extent(struct iomap_swapfile_info *isi)
7071
return 0;
7172
}
7273

74+
static int iomap_swapfile_fail(struct iomap_swapfile_info *isi, const char *str)
75+
{
76+
char *buf, *p = ERR_PTR(-ENOMEM);
77+
78+
buf = kmalloc(PATH_MAX, GFP_KERNEL);
79+
if (buf)
80+
p = file_path(isi->file, buf, PATH_MAX);
81+
pr_err("swapon: file %s %s\n", IS_ERR(p) ? "<unknown>" : p, str);
82+
kfree(buf);
83+
return -EINVAL;
84+
}
85+
7386
/*
7487
* Accumulate iomaps for this swap file. We have to accumulate iomaps because
7588
* swap only cares about contiguous page-aligned physical extents and makes no
@@ -89,28 +102,20 @@ static loff_t iomap_swapfile_activate_actor(struct inode *inode, loff_t pos,
89102
break;
90103
case IOMAP_INLINE:
91104
/* No inline data. */
92-
pr_err("swapon: file is inline\n");
93-
return -EINVAL;
105+
return iomap_swapfile_fail(isi, "is inline");
94106
default:
95-
pr_err("swapon: file has unallocated extents\n");
96-
return -EINVAL;
107+
return iomap_swapfile_fail(isi, "has unallocated extents");
97108
}
98109

99110
/* No uncommitted metadata or shared blocks. */
100-
if (iomap->flags & IOMAP_F_DIRTY) {
101-
pr_err("swapon: file is not committed\n");
102-
return -EINVAL;
103-
}
104-
if (iomap->flags & IOMAP_F_SHARED) {
105-
pr_err("swapon: file has shared extents\n");
106-
return -EINVAL;
107-
}
111+
if (iomap->flags & IOMAP_F_DIRTY)
112+
return iomap_swapfile_fail(isi, "is not committed");
113+
if (iomap->flags & IOMAP_F_SHARED)
114+
return iomap_swapfile_fail(isi, "has shared extents");
108115

109116
/* Only one bdev per swap file. */
110-
if (iomap->bdev != isi->sis->bdev) {
111-
pr_err("swapon: file is on multiple devices\n");
112-
return -EINVAL;
113-
}
117+
if (iomap->bdev != isi->sis->bdev)
118+
return iomap_swapfile_fail(isi, "outside the main device");
114119

115120
if (isi->iomap.length == 0) {
116121
/* No accumulated extent, so just store it. */
@@ -139,6 +144,7 @@ int iomap_swapfile_activate(struct swap_info_struct *sis,
139144
struct iomap_swapfile_info isi = {
140145
.sis = sis,
141146
.lowest_ppage = (sector_t)-1ULL,
147+
.file = swap_file,
142148
};
143149
struct address_space *mapping = swap_file->f_mapping;
144150
struct inode *inode = mapping->host;

0 commit comments

Comments
 (0)