iomap: swapfile tweaks
v2 cover iomap: swapfile tweaks
From: Omar Sandoval <[email protected]>
Changes from v1:
- Added patch 1 to provide more useful error messages (suggested by me) and move the bdev check (suggested by Christoph)
- Changed patch 2 to simply delete the hole check, since it will be caught by the mapped || unwritten check below
Based on xfs-linux/for-next. Thanks!
Omar Sandoval (2):
iomap: provide more useful errors for invalid swap files
iomap: don't allow holes in swapfiles
fs/iomap.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-)
Signature · 1 line
2.17.0
PATCH v2 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 | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-)
fs/iomap.c +22 -15
@@ -1218,22 +1218,32 @@ static loff_t iomap_swapfile_activate_actor(struct inode *inode, loff_t pos,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 ) || + iomap->addr ==IOMAP_NULL_ADDR ) { +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; +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 ; + } +if (iomap->flags &IOMAP_F_DATA_INLINE ) { +pr_err ("swapon: file is inline\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 +1260,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 v2 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
@@ -1214,10 +1214,6 @@ static loff_t iomap_swapfile_activate_actor(struct inode *inode, loff_t pos,struct iomap_swapfile_info *isi = data;int error; -/* Skip holes. */ -if (iomap->type ==IOMAP_HOLE ) - goto out; -/* Only real or unwritten extents. */ if ((iomap->type !=IOMAP_MAPPED && iomap->type !=IOMAP_UNWRITTEN ) || iomap->addr ==IOMAP_NULL_ADDR ) {
@@ -1258,7 +1254,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 v2 1/2] iomap: provide more useful errors for invalid swap files
In reply to Omar SandovalQuoted 10 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.
Signed-off-by Omar Sandoval <[email protected]>
Looks ok,
--D
Quoted 70 lines
--- fs/iomap.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-)fs/iomap.c +22
-15@@ -1218,22 +1218,32 @@ static loff_t iomap_swapfile_activate_actor(struct inode *inode, loff_t pos,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 ) || + iomap->addr ==IOMAP_NULL_ADDR ) { +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; +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 ; + } +if (iomap->flags &IOMAP_F_DATA_INLINE ) { +pr_err ("swapon: file is inline\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 +1260,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 · 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
Re: [PATCH v2 1/2] iomap: provide more useful errors for invalid swap files
In reply to Omar Sandovalfs/iomap.c static loff_t iomap_swapfile_activate_actor(struct inode *inode, loff_t pos, · line 1226
Quoted 5 lines · Omar Sandoval
fs/iomap.c +5
-0+if ((iomap->type !=IOMAP_MAPPED && iomap->type !=IOMAP_UNWRITTEN ) || + iomap->addr ==IOMAP_NULL_ADDR ) { +pr_err ("swapon: file has unallocated extents\n" ); +return -EINVAL ; + }
The two are really different cases - IOMAP_NULL_ADDR shouldn't really happen for any of the above. Although we might have to move the inline check before the type check above for the message to make sense.
I have a patch in the local queue that makes inline a type instead of a flag, btw as it really isn't a flag.
Re: [PATCH v2 1/2] iomap: provide more useful errors for invalid swap files
Quoted 11 lines · Christoph Hellwig
Review
Quoted 5 lines · Omar Sandoval
(quoted diff) +5
-0+ if ((iomap->type != IOMAP_MAPPED && iomap->type != IOMAP_UNWRITTEN) || + iomap->addr == IOMAP_NULL_ADDR) { + pr_err("swapon: file has unallocated extents\n"); + return -EINVAL; + }The two are really different cases -
IOMAP_NULL_ADDRshouldn't really happen for any of the above. Although we might have to move the inline check before the type check above for the message to make sense.
Quoted 2 lines
I have a patch in the local queue that makes inline a type instead of a flag, btw as it really isn't a flag.
So something like this, moving the inline check and removing the hole check since that doesn't make sense for mapped or unwritten? Then the inline flag check can be converted to a type check.
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 ; }/*
Re: [PATCH v2 1/2] iomap: provide more useful errors for invalid swap files
Quoted 12 lines · Omar Sandoval
Quoted 11 lines · Christoph Hellwig
fs/iomap.c static loff_t iomap_swapfile_activate_actor(struct inode *inode, loff_t pos, · line 1231
Quoted 5 lines · Omar Sandoval
fs/iomap.c +5
-0+if ((iomap->type !=IOMAP_MAPPED && iomap->type !=IOMAP_UNWRITTEN ) || + iomap->addr ==IOMAP_NULL_ADDR ) { +pr_err ("swapon: file has unallocated extents\n" ); +return -EINVAL ; + }The two are really different cases -
IOMAP_NULL_ADDRshouldn't really happen for any of the above. Although we might have to move the inline check before the type check above for the message to make sense.
Quoted 6 lines
Quoted 2 lines
I have a patch in the local queue that makes inline a type instead of a flag, btw as it really isn't a flag.
So something like this, moving the inline check and removing the hole check since that doesn't make sense for mapped or unwritten? Then the inline flag check can be converted to a type check.
Yes, this looks great!
Re: [PATCH v2 1/2] iomap: provide more useful errors for invalid swap files
Quoted 13 lines · Christoph Hellwig
Quoted 12 lines · Omar Sandoval
Quoted 11 lines · Christoph Hellwig
fs/iomap.c static loff_t iomap_swapfile_activate_actor(struct inode *inode, loff_t pos, · line 1231
Quoted 5 lines · Omar Sandoval
fs/iomap.c +5
-0+if ((iomap->type !=IOMAP_MAPPED && iomap->type !=IOMAP_UNWRITTEN ) || + iomap->addr ==IOMAP_NULL_ADDR ) { +pr_err ("swapon: file has unallocated extents\n" ); +return -EINVAL ; + }The two are really different cases -
IOMAP_NULL_ADDRshouldn't really happen for any of the above. Although we might have to move the inline check before the type check above for the message to make sense.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
I have a patch in the local queue that makes inline a type instead of a flag, btw as it really isn't a flag.
That's what I thought -- we only see NULL_ADDR for holes and delalloc extents, and we already check for both of those. But I didn't see anything in iomap.h expressly saying that, so I decided to be defensive and check it anyway.
IOWs it would be helpful to have a little more documentation about which flags go together, particularly for things like IOMAP_F_BOUNDARY that don't have any meaning in xfs.
Quoted 5 lines
Quoted 3 lines
So something like this, moving the inline check and removing the hole check since that doesn't make sense for mapped or unwritten? Then the inline flag check can be converted to a type check.
Yes, this looks great!
Yeah, the v3 patch looks ok.
--D
Quoted 4 lines
--
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
Re: [PATCH v2 1/2] iomap: provide more useful errors for invalid swap files
Quoted 7 lines · Darrick J. Wong
That's what I thought -- we only see
NULL_ADDRfor holes and delalloc extents, and we already check for both of those. But I didn't see anything iniomap.hexpressly saying that, so I decided to be defensive and check it anyway.IOWs it would be helpful to have a little more documentation about which flags go together,
patches welcome :)
Quoted 2 lines
particularly for things like
IOMAP_F_BOUNDARYthat don't have any meaning in xfs.
Yikes, how did that even end in the tree? That whole boundary thing already made little sene on buffer heads, and even less so in the generic iomap code. I think we just need to allocate a few flags for fs specific uses and move it into gfs2.