diff mbox series

[v2] mm, swap: disallow swapon() on zoned block devices

Message ID 20191015085814.637837-1-naohiro.aota@wdc.com (mailing list archive)
State New, archived
Headers show
Series [v2] mm, swap: disallow swapon() on zoned block devices | expand

Commit Message

Naohiro Aota Oct. 15, 2019, 8:58 a.m. UTC
A zoned block device consists of a number of zones. Zones are either
conventional and accepting random writes or sequential and requiring that
writes be issued in LBA order from each zone write pointer position. For
the write restriction, zoned block devices are not suitable for a swap
device. Disallow swapon on them.

Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
---
v2: add comments according to Christoph's feedback, reformat chengelog.
---
 mm/swapfile.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Christoph Hellwig Oct. 15, 2019, 9:06 a.m. UTC | #1
On Tue, Oct 15, 2019 at 05:58:14PM +0900, Naohiro Aota wrote:
> A zoned block device consists of a number of zones. Zones are either
> conventional and accepting random writes or sequential and requiring that
> writes be issued in LBA order from each zone write pointer position. For
> the write restriction, zoned block devices are not suitable for a swap
> device. Disallow swapon on them.
> 
> Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
> ---
> v2: add comments according to Christoph's feedback, reformat chengelog.
> ---
>  mm/swapfile.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index dab43523afdd..f2c4224d1f8a 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -2887,6 +2887,14 @@ static int claim_swapfile(struct swap_info_struct *p, struct inode *inode)
>  		error = set_blocksize(p->bdev, PAGE_SIZE);
>  		if (error < 0)
>  			return error;
> +		/*
> +		 * Zoned block device contains zones that have
> +		 * sequential write only restriction. For the restriction,
> +		 * zoned block devices are not suitable for a swap device.
> +		 * Disallow them here.
> +		 */
> +		if (blk_queue_is_zoned(p->bdev->bd_queue))

Please use up all 80 chars per line  Otherwise this looks fine:

Reviewed-by: Christoph Hellwig <hch@lst.de>
Andrew Morton Oct. 15, 2019, 8:43 p.m. UTC | #2
On Tue, 15 Oct 2019 02:06:41 -0700 Christoph Hellwig <hch@infradead.org> wrote:

> > +		/*
> > +		 * Zoned block device contains zones that have
> > +		 * sequential write only restriction. For the restriction,
> > +		 * zoned block devices are not suitable for a swap device.
> > +		 * Disallow them here.
> > +		 */
> > +		if (blk_queue_is_zoned(p->bdev->bd_queue))
> 
> Please use up all 80 chars per line  Otherwise this looks fine:

I redid the text a bit as well.

--- a/mm/swapfile.c~mm-swap-disallow-swapon-on-zoned-block-devices-fix
+++ a/mm/swapfile.c
@@ -2888,10 +2888,9 @@ static int claim_swapfile(struct swap_in
 		if (error < 0)
 			return error;
 		/*
-		 * Zoned block device contains zones that have
-		 * sequential write only restriction. For the restriction,
-		 * zoned block devices are not suitable for a swap device.
-		 * Disallow them here.
+		 * Zoned block devices contain zones that have a sequential
+		 * write only restriction.  Hence zoned block devices are not
+		 * suitable for swapping.  Disallow them here.
 		 */
 		if (blk_queue_is_zoned(p->bdev->bd_queue))
 			return -EINVAL;
diff mbox series

Patch

diff --git a/mm/swapfile.c b/mm/swapfile.c
index dab43523afdd..f2c4224d1f8a 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -2887,6 +2887,14 @@  static int claim_swapfile(struct swap_info_struct *p, struct inode *inode)
 		error = set_blocksize(p->bdev, PAGE_SIZE);
 		if (error < 0)
 			return error;
+		/*
+		 * Zoned block device contains zones that have
+		 * sequential write only restriction. For the restriction,
+		 * zoned block devices are not suitable for a swap device.
+		 * Disallow them here.
+		 */
+		if (blk_queue_is_zoned(p->bdev->bd_queue))
+			return -EINVAL;
 		p->flags |= SWP_BLKDEV;
 	} else if (S_ISREG(inode->i_mode)) {
 		p->bdev = inode->i_sb->s_bdev;