linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ext4: Do not reserve clusters when fs doesn't support extents
@ 2013-11-28 11:42 Jan Kara
  2013-11-28 12:47 ` Geert Uytterhoeven
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jan Kara @ 2013-11-28 11:42 UTC (permalink / raw)
  To: Ted Tso; +Cc: linux-ext4, Geert Uytterhoeven, Jan Kara, Lukas Czerner

When filesystem doesn't support extents (like in ext2/3 compatibility
modes), there is no need to reserve any clusters. Space estimates for
writing are exact, hole punching doesn't need new metadata, and there
are no unwritten extents to convert.

This fixes a problem when filesystem still having some free space when
accessed with a native ext2/3 driver suddently reports ENOSPC when
accessed with ext4 driver.

Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
CC: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/ext4/super.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index c977f4e4e63b..0561713cd6d8 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -3316,11 +3316,19 @@ int ext4_calculate_overhead(struct super_block *sb)
 }
 
 
-static ext4_fsblk_t ext4_calculate_resv_clusters(struct ext4_sb_info *sbi)
+static ext4_fsblk_t ext4_calculate_resv_clusters(struct super_block *sb)
 {
 	ext4_fsblk_t resv_clusters;
 
 	/*
+	 * There's no need to reserve anything when we aren't using extents.
+	 * The space estimates are exact, there are no unwritten extents,
+	 * hole punching doesn't need new metadata... This is needed especially
+	 * to keep ext2/3 backward compatibility.
+	 */
+	if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_EXTENTS))
+		return 0;
+	/*
 	 * By default we reserve 2% or 4096 clusters, whichever is smaller.
 	 * This should cover the situations where we can not afford to run
 	 * out of space like for example punch hole, or converting
@@ -3328,7 +3336,8 @@ static ext4_fsblk_t ext4_calculate_resv_clusters(struct ext4_sb_info *sbi)
 	 * allocation would require 1, or 2 blocks, higher numbers are
 	 * very rare.
 	 */
-	resv_clusters = ext4_blocks_count(sbi->s_es) >> sbi->s_cluster_bits;
+	resv_clusters = ext4_blocks_count(EXT4_SB(sb)->s_es) >>
+			EXT4_SB(sb)->s_cluster_bits;
 
 	do_div(resv_clusters, 50);
 	resv_clusters = min_t(ext4_fsblk_t, resv_clusters, 4096);
@@ -4071,10 +4080,10 @@ no_journal:
 			 "available");
 	}
 
-	err = ext4_reserve_clusters(sbi, ext4_calculate_resv_clusters(sbi));
+	err = ext4_reserve_clusters(sbi, ext4_calculate_resv_clusters(sb));
 	if (err) {
 		ext4_msg(sb, KERN_ERR, "failed to reserve %llu clusters for "
-			 "reserved pool", ext4_calculate_resv_clusters(sbi));
+			 "reserved pool", ext4_calculate_resv_clusters(sb));
 		goto failed_mount4a;
 	}
 
-- 
1.8.1.4


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

* Re: [PATCH] ext4: Do not reserve clusters when fs doesn't support extents
  2013-11-28 11:42 [PATCH] ext4: Do not reserve clusters when fs doesn't support extents Jan Kara
@ 2013-11-28 12:47 ` Geert Uytterhoeven
  2013-11-29 12:01 ` Lukáš Czerner
  2013-12-09  2:13 ` Theodore Ts'o
  2 siblings, 0 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2013-11-28 12:47 UTC (permalink / raw)
  To: Jan Kara; +Cc: Ted Tso, linux-ext4, Lukas Czerner

Hi Jan,

On Thu, Nov 28, 2013 at 12:42 PM, Jan Kara <jack@suse.cz> wrote:
> When filesystem doesn't support extents (like in ext2/3 compatibility
> modes), there is no need to reserve any clusters. Space estimates for
> writing are exact, hole punching doesn't need new metadata, and there
> are no unwritten extents to convert.
>
> This fixes a problem when filesystem still having some free space when
> accessed with a native ext2/3 driver suddently reports ENOSPC when
> accessed with ext4 driver.

Thanks, fixed!

> Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
> CC: Lukas Czerner <lczerner@redhat.com>
> Signed-off-by: Jan Kara <jack@suse.cz>

Tested-by: Geert Uytterhoeven <geert@linux-m68k.org>

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH] ext4: Do not reserve clusters when fs doesn't support extents
  2013-11-28 11:42 [PATCH] ext4: Do not reserve clusters when fs doesn't support extents Jan Kara
  2013-11-28 12:47 ` Geert Uytterhoeven
@ 2013-11-29 12:01 ` Lukáš Czerner
  2013-12-09  2:13 ` Theodore Ts'o
  2 siblings, 0 replies; 4+ messages in thread
From: Lukáš Czerner @ 2013-11-29 12:01 UTC (permalink / raw)
  To: Jan Kara; +Cc: Ted Tso, linux-ext4, Geert Uytterhoeven

On Thu, 28 Nov 2013, Jan Kara wrote:

> Date: Thu, 28 Nov 2013 12:42:45 +0100
> From: Jan Kara <jack@suse.cz>
> To: Ted Tso <tytso@mit.edu>
> Cc: linux-ext4@vger.kernel.org, Geert Uytterhoeven <geert@linux-m68k.org>,
>     Jan Kara <jack@suse.cz>, Lukas Czerner <lczerner@redhat.com>
> Subject: [PATCH] ext4: Do not reserve clusters when fs doesn't support extents
> 
> When filesystem doesn't support extents (like in ext2/3 compatibility
> modes), there is no need to reserve any clusters. Space estimates for
> writing are exact, hole punching doesn't need new metadata, and there
> are no unwritten extents to convert.
> 
> This fixes a problem when filesystem still having some free space when
> accessed with a native ext2/3 driver suddently reports ENOSPC when
> accessed with ext4 driver.

Right, I forgot about that. Thanks!

Reviewed-by: Lukas Czerner <lczerner@redhat.com>

> 
> Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
> CC: Lukas Czerner <lczerner@redhat.com>
> Signed-off-by: Jan Kara <jack@suse.cz>
> ---
>  fs/ext4/super.c | 17 +++++++++++++----
>  1 file changed, 13 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index c977f4e4e63b..0561713cd6d8 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -3316,11 +3316,19 @@ int ext4_calculate_overhead(struct super_block *sb)
>  }
>  
>  
> -static ext4_fsblk_t ext4_calculate_resv_clusters(struct ext4_sb_info *sbi)
> +static ext4_fsblk_t ext4_calculate_resv_clusters(struct super_block *sb)
>  {
>  	ext4_fsblk_t resv_clusters;
>  
>  	/*
> +	 * There's no need to reserve anything when we aren't using extents.
> +	 * The space estimates are exact, there are no unwritten extents,
> +	 * hole punching doesn't need new metadata... This is needed especially
> +	 * to keep ext2/3 backward compatibility.
> +	 */
> +	if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_EXTENTS))
> +		return 0;
> +	/*
>  	 * By default we reserve 2% or 4096 clusters, whichever is smaller.
>  	 * This should cover the situations where we can not afford to run
>  	 * out of space like for example punch hole, or converting
> @@ -3328,7 +3336,8 @@ static ext4_fsblk_t ext4_calculate_resv_clusters(struct ext4_sb_info *sbi)
>  	 * allocation would require 1, or 2 blocks, higher numbers are
>  	 * very rare.
>  	 */
> -	resv_clusters = ext4_blocks_count(sbi->s_es) >> sbi->s_cluster_bits;
> +	resv_clusters = ext4_blocks_count(EXT4_SB(sb)->s_es) >>
> +			EXT4_SB(sb)->s_cluster_bits;
>  
>  	do_div(resv_clusters, 50);
>  	resv_clusters = min_t(ext4_fsblk_t, resv_clusters, 4096);
> @@ -4071,10 +4080,10 @@ no_journal:
>  			 "available");
>  	}
>  
> -	err = ext4_reserve_clusters(sbi, ext4_calculate_resv_clusters(sbi));
> +	err = ext4_reserve_clusters(sbi, ext4_calculate_resv_clusters(sb));
>  	if (err) {
>  		ext4_msg(sb, KERN_ERR, "failed to reserve %llu clusters for "
> -			 "reserved pool", ext4_calculate_resv_clusters(sbi));
> +			 "reserved pool", ext4_calculate_resv_clusters(sb));
>  		goto failed_mount4a;
>  	}
>  
> 

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

* Re: [PATCH] ext4: Do not reserve clusters when fs doesn't support extents
  2013-11-28 11:42 [PATCH] ext4: Do not reserve clusters when fs doesn't support extents Jan Kara
  2013-11-28 12:47 ` Geert Uytterhoeven
  2013-11-29 12:01 ` Lukáš Czerner
@ 2013-12-09  2:13 ` Theodore Ts'o
  2 siblings, 0 replies; 4+ messages in thread
From: Theodore Ts'o @ 2013-12-09  2:13 UTC (permalink / raw)
  To: Jan Kara; +Cc: linux-ext4, Geert Uytterhoeven, Lukas Czerner

On Thu, Nov 28, 2013 at 12:42:45PM +0100, Jan Kara wrote:
> When filesystem doesn't support extents (like in ext2/3 compatibility
> modes), there is no need to reserve any clusters. Space estimates for
> writing are exact, hole punching doesn't need new metadata, and there
> are no unwritten extents to convert.
> 
> This fixes a problem when filesystem still having some free space when
> accessed with a native ext2/3 driver suddently reports ENOSPC when
> accessed with ext4 driver.
> 
> Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
> CC: Lukas Czerner <lczerner@redhat.com>
> Signed-off-by: Jan Kara <jack@suse.cz>

Thanks, applied.  Given that distro's are using
CONFIG_EXT4_USE_FOR_EXT23, I'm going to queue this for the stable kernel.

			       	     	- Ted

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

end of thread, other threads:[~2013-12-09  2:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-28 11:42 [PATCH] ext4: Do not reserve clusters when fs doesn't support extents Jan Kara
2013-11-28 12:47 ` Geert Uytterhoeven
2013-11-29 12:01 ` Lukáš Czerner
2013-12-09  2:13 ` Theodore Ts'o

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