iomap: swapfile tweaks
v3 cover iomap: swapfile tweaks
From: Omar Sandoval <[email protected]>
Changes from v2:
- Move up inline flag check, which Christoph is going to turn into a type at some point
- Remove null address check, since it doesn't make sense for IOMAP_MAPPED or IOMAP_UNWRITTEN
Omar Sandoval (2):
iomap: provide more useful errors for invalid swap files
iomap: don't allow holes in swapfiles
fs/iomap.c | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-)
Signature · 1 line
2.17.0
PATCH v3 1/2 iomap: provide more useful errors for invalid swap files
From: Omar Sandoval <[email protected]>
Currently, for an invalid swap file, we print the same error message regardless of the reason. This isn't very useful for an admin, who will likely want to know why exactly they can't use their swap file. So, let's add specific error messages for each reason, and also move the bdev check after the flags checks, since the latter are more fundamental.
--- fs/iomap.c | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-)
fs/iomap.c +24 -16
@@ -1214,26 +1214,37 @@ static loff_t iomap_swapfile_activate_actor(struct inode *inode, loff_t pos,struct iomap_swapfile_info *isi = data;int error; +/* No inline data. */ +if (iomap->flags &IOMAP_F_DATA_INLINE ) { +pr_err ("swapon: file is inline\n" ); +return -EINVAL ; + } +/* Skip holes. */ if (iomap->type ==IOMAP_HOLE ) goto out; -/* Only one bdev per swap file. */ -if (iomap->bdev != isi->sis->bdev) - goto err; -/* Only real or unwritten extents. */ -if (iomap->type !=IOMAP_MAPPED && iomap->type !=IOMAP_UNWRITTEN ) - goto err; +if (iomap->type !=IOMAP_MAPPED && iomap->type !=IOMAP_UNWRITTEN ) { +pr_err ("swapon: file has unallocated extents\n" ); +return -EINVAL ; + } -/* No uncommitted metadata or shared blocks or inline data. */ -if (iomap->flags & (IOMAP_F_DIRTY |IOMAP_F_SHARED | -IOMAP_F_DATA_INLINE )) - goto err; +/* No uncommitted metadata or shared blocks. */ +if (iomap->flags &IOMAP_F_DIRTY ) { +pr_err ("swapon: file is not committed\n" ); +return -EINVAL ; + } +if (iomap->flags &IOMAP_F_SHARED ) { +pr_err ("swapon: file has shared extents\n" ); +return -EINVAL ; + } -/* No null physical addresses. */ -if (iomap->addr ==IOMAP_NULL_ADDR ) - goto err; +/* Only one bdev per swap file. */ +if (iomap->bdev != isi->sis->bdev) { +pr_err ("swapon: file is on multiple devices\n" ); +return -EINVAL ; + }if (isi->iomap.length ==0 ) {/* No accumulated extent, so just store it. */
@@ -1250,9 +1261,6 @@ static loff_t iomap_swapfile_activate_actor(struct inode *inode, loff_t pos, } out:return count; -err: -pr_err ("swapon: file cannot be used for swap\n" ); -return -EINVAL ; }/*
Signature · 1 line
2.17.0
PATCH v3 2/2 iomap: don't allow holes in swapfiles
In reply to Omar SandovalFrom: Omar Sandoval <[email protected]>
generic_swapfile_activate() doesn't allow holes, so we should be consistent here. This is also a bit safer: if the user creates a swapfile with, say, truncate -s $SIZE followed by mkswap, they should really get an error and not much less swap space than they expected. swapon(8) will error out before calling swapon(2) if the file has holes, anyways.
--- fs/iomap.c | 5 ----- 1 file changed, 5 deletions(-)
fs/iomap.c +0 -5
@@ -1220,10 +1220,6 @@ static loff_t iomap_swapfile_activate_actor(struct inode *inode, loff_t pos,return -EINVAL ; } -/* Skip holes. */ -if (iomap->type ==IOMAP_HOLE ) - goto out; -/* Only real or unwritten extents. */ if (iomap->type !=IOMAP_MAPPED && iomap->type !=IOMAP_UNWRITTEN ) {pr_err ("swapon: file has unallocated extents\n" );
@@ -1259,7 +1255,6 @@ static loff_t iomap_swapfile_activate_actor(struct inode *inode, loff_t pos,return error;memcpy (&isi->iomap, iomap,sizeof (isi->iomap)); } -out:return count; }
Signature · 1 line
2.17.0
Re: [PATCH v3 1/2] iomap: provide more useful errors for invalid swap files
In reply to Omar SandovalLooks good,
Re: [PATCH v3 2/2] iomap: don't allow holes in swapfiles
In reply to Omar SandovalLooks good,
And now lets get the series merged quickly so that I can rebase my iomap series on top of this :)
Re: [PATCH v3 1/2] iomap: provide more useful errors for invalid swap files
In reply to Omar SandovalQuoted 11 lines · Omar Sandoval
From: Omar Sandoval <[email protected]>
Currently, for an invalid swap file, we print the same error message regardless of the reason. This isn't very useful for an admin, who will likely want to know why exactly they can't use their swap file. So, let's add specific error messages for each reason, and also move the bdev check after the flags checks, since the latter are more fundamental.
Reviewed-by Darrick J. Wong <[email protected]>Signed-off-by Omar Sandoval <[email protected]>
Yup, looks good to me. You can add:
Honza
Quoted 72 lines
--- fs/iomap.c | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-)fs/iomap.c +24
-16@@ -1214,26 +1214,37 @@ static loff_t iomap_swapfile_activate_actor(struct inode *inode, loff_t pos,struct iomap_swapfile_info *isi = data;int error; +/* No inline data. */ +if (iomap->flags &IOMAP_F_DATA_INLINE ) { +pr_err ("swapon: file is inline\n" ); +return -EINVAL ; + } +/* Skip holes. */ if (iomap->type ==IOMAP_HOLE ) goto out; -/* Only one bdev per swap file. */ -if (iomap->bdev != isi->sis->bdev) - goto err; -/* Only real or unwritten extents. */ -if (iomap->type !=IOMAP_MAPPED && iomap->type !=IOMAP_UNWRITTEN ) - goto err; +if (iomap->type !=IOMAP_MAPPED && iomap->type !=IOMAP_UNWRITTEN ) { +pr_err ("swapon: file has unallocated extents\n" ); +return -EINVAL ; + } -/* No uncommitted metadata or shared blocks or inline data. */ -if (iomap->flags & (IOMAP_F_DIRTY |IOMAP_F_SHARED | -IOMAP_F_DATA_INLINE )) - goto err; +/* No uncommitted metadata or shared blocks. */ +if (iomap->flags &IOMAP_F_DIRTY ) { +pr_err ("swapon: file is not committed\n" ); +return -EINVAL ; + } +if (iomap->flags &IOMAP_F_SHARED ) { +pr_err ("swapon: file has shared extents\n" ); +return -EINVAL ; + } -/* No null physical addresses. */ -if (iomap->addr ==IOMAP_NULL_ADDR ) - goto err; +/* Only one bdev per swap file. */ +if (iomap->bdev != isi->sis->bdev) { +pr_err ("swapon: file is on multiple devices\n" ); +return -EINVAL ; + }if (isi->iomap.length ==0 ) {/* No accumulated extent, so just store it. */ @@ -1250,9 +1261,6 @@ static loff_t iomap_swapfile_activate_actor(struct inode *inode, loff_t pos, } out:return count; -err: -pr_err ("swapon: file cannot be used for swap\n" ); -return -EINVAL ; }/* Signature · 1 line
2.17.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH v3 2/2] iomap: don't allow holes in swapfiles
In reply to Omar SandovalQuoted 9 lines · Omar Sandoval
From: Omar Sandoval <[email protected]>
generic_swapfile_activate()doesn't allow holes, so we should be consistent here. This is also a bit safer: if the user creates a swapfile with, say, truncate -s $SIZE followed by mkswap, they should really get an error and not much less swap space than they expected. swapon(8) will error out before calling swapon(2) if the file has holes, anyways.
Quoted 3 lines
Fixes 9d93388b0afe ("iomap: add a swapfile activation function")Reviewed-by Darrick J. Wong <[email protected]>Signed-off-by Omar Sandoval <[email protected]>
Good catch. You can add:
Honza
Quoted 30 lines
--- fs/iomap.c | 5 ----- 1 file changed, 5 deletions(-)fs/iomap.c +0
-5@@ -1220,10 +1220,6 @@ static loff_t iomap_swapfile_activate_actor(struct inode *inode, loff_t pos,return -EINVAL ; } -/* Skip holes. */ -if (iomap->type ==IOMAP_HOLE ) - goto out; -/* Only real or unwritten extents. */ if (iomap->type !=IOMAP_MAPPED && iomap->type !=IOMAP_UNWRITTEN ) {pr_err ("swapon: file has unallocated extents\n" );@@ -1259,7 +1255,6 @@ static loff_t iomap_swapfile_activate_actor(struct inode *inode, loff_t pos,return error;memcpy (&isi->iomap, iomap,sizeof (isi->iomap)); } -out:return count; }Signature · 1 line
2.17.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 9 lines · Omar Sandoval
From: Omar Sandoval <[email protected]>
Changes from v2:
- Move up inline flag check, which Christoph is going to turn into a type at some point
- Remove null address check, since it doesn't make sense forIOMAP_MAPPEDorIOMAP_UNWRITTEN
Quoted 5 lines
Omar Sandoval (2):
iomap: provide more useful errors for invalid swap files
iomap: don't allow holes in swapfilesfs/iomap.c | 43 +++++++++++++++++++++++--------------------
Tested ok overnight, so:
--D
Quoted 9 lines
1 file changed, 23 insertions(+), 20 deletions(-)Signature · 6 lines
2.17.0 -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html