linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iomap: don't allow holes in swapfiles
@ 2018-05-16  6:45 Omar Sandoval
  2018-05-16 15:50 ` Darrick J. Wong
  2018-05-16 16:23 ` Christoph Hellwig
  0 siblings, 2 replies; 8+ messages in thread
From: Omar Sandoval @ 2018-05-16  6:45 UTC (permalink / raw)
  To: Darrick J . Wong, linux-xfs; +Cc: linux-fsdevel, Jan Kara

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")
Signed-off-by: Omar Sandoval <osandov@fb.com>
---
Hey, Darrick, I noticed this while writing up a generic xfstest to test
that the Btrfs swap support patches don't allow a swapfile with holes.
It'd be nice if we were all consistent :) This is based on
xfs-linux/for-next. Feel free to fold it in to your patch or apply it
separately as you see fit. Thanks!

 fs/iomap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/iomap.c b/fs/iomap.c
index d193390a1c20..ba559adaa327 100644
--- a/fs/iomap.c
+++ b/fs/iomap.c
@@ -1214,9 +1214,9 @@ static loff_t iomap_swapfile_activate_actor(struct inode *inode, loff_t pos,
 	struct iomap_swapfile_info *isi = data;
 	int error;
 
-	/* Skip holes. */
+	/* No holes. */
 	if (iomap->type == IOMAP_HOLE)
-		goto out;
+		goto err;
 
 	/* Only one bdev per swap file. */
 	if (iomap->bdev != isi->sis->bdev)
-- 
2.17.0

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] iomap: don't allow holes in swapfiles
  2018-05-16  6:45 [PATCH] iomap: don't allow holes in swapfiles Omar Sandoval
@ 2018-05-16 15:50 ` Darrick J. Wong
  2018-05-16 15:51   ` Christoph Hellwig
  2018-05-16 16:23 ` Christoph Hellwig
  1 sibling, 1 reply; 8+ messages in thread
From: Darrick J. Wong @ 2018-05-16 15:50 UTC (permalink / raw)
  To: Omar Sandoval; +Cc: linux-xfs, linux-fsdevel, Jan Kara

On Tue, May 15, 2018 at 11:45:38PM -0700, 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")
> Signed-off-by: Omar Sandoval <osandov@fb.com>
> ---
> Hey, Darrick, I noticed this while writing up a generic xfstest to test
> that the Btrfs swap support patches don't allow a swapfile with holes.
> It'd be nice if we were all consistent :) This is based on
> xfs-linux/for-next. Feel free to fold it in to your patch or apply it
> separately as you see fit. Thanks!

I sent a testcase of my own ("generic: test swapfile creation,
activation, and deactivation") a while back; would you mind sending out
yours so we can combine them into a single testcase?

>  fs/iomap.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/iomap.c b/fs/iomap.c
> index d193390a1c20..ba559adaa327 100644
> --- a/fs/iomap.c
> +++ b/fs/iomap.c
> @@ -1214,9 +1214,9 @@ static loff_t iomap_swapfile_activate_actor(struct inode *inode, loff_t pos,
>  	struct iomap_swapfile_info *isi = data;
>  	int error;
>  
> -	/* Skip holes. */
> +	/* No holes. */
>  	if (iomap->type == IOMAP_HOLE)
> -		goto out;
> +		goto err;

Ok.  I agree that it looks weird to mount a swap file with holes, so I
guess the least-surprise principle applies here and we should emulate
the old behavior completely.

Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>

--D

>  
>  	/* Only one bdev per swap file. */
>  	if (iomap->bdev != isi->sis->bdev)
> -- 
> 2.17.0
> 
> --
> 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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] iomap: don't allow holes in swapfiles
  2018-05-16 15:50 ` Darrick J. Wong
@ 2018-05-16 15:51   ` Christoph Hellwig
  2018-05-16 15:56     ` Darrick J. Wong
  0 siblings, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2018-05-16 15:51 UTC (permalink / raw)
  To: Darrick J. Wong
  Cc: Omar Sandoval, linux-xfs, linux-fsdevel, Jan Kara, Aleksei Besogonov

On Wed, May 16, 2018 at 08:50:00AM -0700, Darrick J. Wong wrote:
> > Hey, Darrick, I noticed this while writing up a generic xfstest to test
> > that the Btrfs swap support patches don't allow a swapfile with holes.
> > It'd be nice if we were all consistent :) This is based on
> > xfs-linux/for-next. Feel free to fold it in to your patch or apply it
> > separately as you see fit. Thanks!
> 
> I sent a testcase of my own ("generic: test swapfile creation,
> activation, and deactivation") a while back; would you mind sending out
> yours so we can combine them into a single testcase?

Wasn't the desire to support holes the rationale for the Aleksei
version of the iomap swapfile patch?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] iomap: don't allow holes in swapfiles
  2018-05-16 15:51   ` Christoph Hellwig
@ 2018-05-16 15:56     ` Darrick J. Wong
  2018-05-16 16:19       ` Omar Sandoval
  0 siblings, 1 reply; 8+ messages in thread
From: Darrick J. Wong @ 2018-05-16 15:56 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Omar Sandoval, linux-xfs, linux-fsdevel, Jan Kara, Aleksei Besogonov

On Wed, May 16, 2018 at 08:51:46AM -0700, Christoph Hellwig wrote:
> On Wed, May 16, 2018 at 08:50:00AM -0700, Darrick J. Wong wrote:
> > > Hey, Darrick, I noticed this while writing up a generic xfstest to test
> > > that the Btrfs swap support patches don't allow a swapfile with holes.
> > > It'd be nice if we were all consistent :) This is based on
> > > xfs-linux/for-next. Feel free to fold it in to your patch or apply it
> > > separately as you see fit. Thanks!
> > 
> > I sent a testcase of my own ("generic: test swapfile creation,
> > activation, and deactivation") a while back; would you mind sending out
> > yours so we can combine them into a single testcase?
> 
> Wasn't the desire to support holes the rationale for the Aleksei
> version of the iomap swapfile patch?

Ah, so it was.  FWIW I'm not sure why you'd /want/ a holey swapfile?

TBH my motivation for iomap swapfile is purely to remove bmap callers. :)

--D

> --
> 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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] iomap: don't allow holes in swapfiles
  2018-05-16 15:56     ` Darrick J. Wong
@ 2018-05-16 16:19       ` Omar Sandoval
  2018-05-16 16:24         ` Christoph Hellwig
  0 siblings, 1 reply; 8+ messages in thread
From: Omar Sandoval @ 2018-05-16 16:19 UTC (permalink / raw)
  To: Darrick J. Wong
  Cc: Christoph Hellwig, linux-xfs, linux-fsdevel, Jan Kara, Aleksei Besogonov

On Wed, May 16, 2018 at 08:56:38AM -0700, Darrick J. Wong wrote:
> On Wed, May 16, 2018 at 08:51:46AM -0700, Christoph Hellwig wrote:
> > On Wed, May 16, 2018 at 08:50:00AM -0700, Darrick J. Wong wrote:
> > > > Hey, Darrick, I noticed this while writing up a generic xfstest to test
> > > > that the Btrfs swap support patches don't allow a swapfile with holes.
> > > > It'd be nice if we were all consistent :) This is based on
> > > > xfs-linux/for-next. Feel free to fold it in to your patch or apply it
> > > > separately as you see fit. Thanks!
> > > 
> > > I sent a testcase of my own ("generic: test swapfile creation,
> > > activation, and deactivation") a while back; would you mind sending out
> > > yours so we can combine them into a single testcase?

Sure thing, I have a small pile of tests. I'm still working on some
Btrfs-specific ones, but I can send out the generic ones and we can
figure out how to merge them.

> > Wasn't the desire to support holes the rationale for the Aleksei
> > version of the iomap swapfile patch?
> 
> Ah, so it was.  FWIW I'm not sure why you'd /want/ a holey swapfile?

>From reading the old thread, it looks like Aleksei just wanted
fallocated swap files to work: "I've traced the problem to bmap(), used
in generic_swapfile_activate call, which returns 0 for blocks inside
holes created by fallocate". Are holes in that sense are different from
actual holes in the iomap sense?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] iomap: don't allow holes in swapfiles
  2018-05-16  6:45 [PATCH] iomap: don't allow holes in swapfiles Omar Sandoval
  2018-05-16 15:50 ` Darrick J. Wong
@ 2018-05-16 16:23 ` Christoph Hellwig
  2018-05-16 16:26   ` Omar Sandoval
  1 sibling, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2018-05-16 16:23 UTC (permalink / raw)
  To: Omar Sandoval; +Cc: Darrick J . Wong, linux-xfs, linux-fsdevel, Jan Kara

>  
> -	/* Skip holes. */
> +	/* No holes. */
>  	if (iomap->type == IOMAP_HOLE)
> -		goto out;
> +		goto err;

If we end up not allowing holes this check can just be removed
entirely.  We already check for the allow types below.  I have to
admit I would move that type check above the bdev check, though.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] iomap: don't allow holes in swapfiles
  2018-05-16 16:19       ` Omar Sandoval
@ 2018-05-16 16:24         ` Christoph Hellwig
  0 siblings, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2018-05-16 16:24 UTC (permalink / raw)
  To: Omar Sandoval
  Cc: Darrick J. Wong, Christoph Hellwig, linux-xfs, linux-fsdevel,
	Jan Kara, Aleksei Besogonov

On Wed, May 16, 2018 at 09:19:55AM -0700, Omar Sandoval wrote:
> > > Wasn't the desire to support holes the rationale for the Aleksei
> > > version of the iomap swapfile patch?
> > 
> > Ah, so it was.  FWIW I'm not sure why you'd /want/ a holey swapfile?
> 
> >From reading the old thread, it looks like Aleksei just wanted
> fallocated swap files to work: "I've traced the problem to bmap(), used
> in generic_swapfile_activate call, which returns 0 for blocks inside
> holes created by fallocate".

Oh, that makes more sense.

> Are holes in that sense are different from
> actual holes in the iomap sense?

Unwritten extents aren't actually holes in any sense, so they are
very different and should work with the iomap swapfile code.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] iomap: don't allow holes in swapfiles
  2018-05-16 16:23 ` Christoph Hellwig
@ 2018-05-16 16:26   ` Omar Sandoval
  0 siblings, 0 replies; 8+ messages in thread
From: Omar Sandoval @ 2018-05-16 16:26 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Darrick J . Wong, linux-xfs, linux-fsdevel, Jan Kara

On Wed, May 16, 2018 at 09:23:29AM -0700, Christoph Hellwig wrote:
> >  
> > -	/* Skip holes. */
> > +	/* No holes. */
> >  	if (iomap->type == IOMAP_HOLE)
> > -		goto out;
> > +		goto err;
> 
> If we end up not allowing holes this check can just be removed
> entirely.  We already check for the allow types below.  I have to
> admit I would move that type check above the bdev check, though.

True, although I wonder if we should be logging more specific error
messages instead of a generic "not a valid swap file" message. At least
for my Btrfs patches, that's what I do. I'll send a v2 with a second
patch doing that.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-05-16 16:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-16  6:45 [PATCH] iomap: don't allow holes in swapfiles Omar Sandoval
2018-05-16 15:50 ` Darrick J. Wong
2018-05-16 15:51   ` Christoph Hellwig
2018-05-16 15:56     ` Darrick J. Wong
2018-05-16 16:19       ` Omar Sandoval
2018-05-16 16:24         ` Christoph Hellwig
2018-05-16 16:23 ` Christoph Hellwig
2018-05-16 16:26   ` Omar Sandoval

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).