diff mbox

[v3,2/2] iomap: don't allow holes in swapfiles

Message ID cdb5dc22c56b30f693741361f6d6168f97f26bc1.1526493125.git.osandov@fb.com (mailing list archive)
State Accepted, archived
Headers show

Commit Message

Omar Sandoval May 16, 2018, 5:54 p.m. UTC
From: Omar Sandoval <osandov@fb.com>

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.

Fixes: 9d93388b0afe ("iomap: add a swapfile activation function")
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Omar Sandoval <osandov@fb.com>
---
 fs/iomap.c | 5 -----
 1 file changed, 5 deletions(-)

Comments

Christoph Hellwig May 16, 2018, 6:11 p.m. UTC | #1
Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

And now lets get the series merged quickly so that I can rebase my
iomap series on top of this :)
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jan Kara May 17, 2018, 8:59 a.m. UTC | #2
On Wed 16-05-18 10:54:11, Omar Sandoval wrote:
> From: Omar Sandoval <osandov@fb.com>
> 
> 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.
> 
> Fixes: 9d93388b0afe ("iomap: add a swapfile activation function")
> Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
> Signed-off-by: Omar Sandoval <osandov@fb.com>

Good catch. You can add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  fs/iomap.c | 5 -----
>  1 file changed, 5 deletions(-)
> 
> diff --git a/fs/iomap.c b/fs/iomap.c
> index 89517442e296..f2456d0d8ddd 100644
> --- a/fs/iomap.c
> +++ b/fs/iomap.c
> @@ -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;
>  }
>  
> -- 
> 2.17.0
>
diff mbox

Patch

diff --git a/fs/iomap.c b/fs/iomap.c
index 89517442e296..f2456d0d8ddd 100644
--- a/fs/iomap.c
+++ b/fs/iomap.c
@@ -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;
 }