diff mbox

[2/2,V2] ext4: don't bump nr_to_write if LONG_MAX

Message ID 4C7D0FAB.9070501@redhat.com
State Accepted, archived
Headers show

Commit Message

Eric Sandeen Aug. 31, 2010, 2:20 p.m. UTC
In some cases we can reach ext4_da_writepages() with
wbc->nr_to_write == LONG_MAX, !range_cyclic, and range_whole=1;
in this case we will try to bump it up by a factor of 8, which
leads to a desired_nr_to_write value of -8.

We still get through the logic without actually changing
wbc->nr_to_write because the other tests which would change
it don't trip due to the negative value, but it seems dangerous
to overflow  desired_nr_to_write in the interim, it's not an 
obvious situation.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

(V2 minor commit message edits)



--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Eric Sandeen Sept. 3, 2010, 9:37 p.m. UTC | #1
Eric Sandeen wrote:
> In some cases we can reach ext4_da_writepages() with
> wbc->nr_to_write == LONG_MAX, !range_cyclic, and range_whole=1;
> in this case we will try to bump it up by a factor of 8, which
> leads to a desired_nr_to_write value of -8.

Sorry Ted, hold off on this, it should have been LLONG_MAX of course,
and I'm still looking for one other bit of brokennes I see.

The 1/2 patch should be good though.

-Eric

> We still get through the logic without actually changing
> wbc->nr_to_write because the other tests which would change
> it don't trip due to the negative value, but it seems dangerous
> to overflow  desired_nr_to_write in the interim, it's not an 
> obvious situation.
> 
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> ---
> 
> (V2 minor commit message edits)
> 
> diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
> index 93497f6..2e72a4a 100644
> --- a/fs/ext4/inode.c
> +++ b/fs/ext4/inode.c
> @@ -3004,9 +3004,11 @@ static int ext4_da_writepages(struct address_space *mapping,
>  	 * sbi->max_writeback_mb_bump whichever is smaller.
>  	 */
>  	max_pages = sbi->s_max_writeback_mb_bump << (20 - PAGE_CACHE_SHIFT);
> -	if (!range_cyclic && range_whole)
> -		desired_nr_to_write = wbc->nr_to_write * 8;
> -	else
> +	if (!range_cyclic && range_whole) {
> +		desired_nr_to_write = wbc->nr_to_write;
> +		if (desired_nr_to_write != LONG_MAX)
> +			desired_nr_to_write *= 8;
> +	} else
>  		desired_nr_to_write = ext4_num_dirty_pages(inode, index,
>  							   max_pages);
>  	if (desired_nr_to_write > max_pages)
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 93497f6..2e72a4a 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -3004,9 +3004,11 @@  static int ext4_da_writepages(struct address_space *mapping,
 	 * sbi->max_writeback_mb_bump whichever is smaller.
 	 */
 	max_pages = sbi->s_max_writeback_mb_bump << (20 - PAGE_CACHE_SHIFT);
-	if (!range_cyclic && range_whole)
-		desired_nr_to_write = wbc->nr_to_write * 8;
-	else
+	if (!range_cyclic && range_whole) {
+		desired_nr_to_write = wbc->nr_to_write;
+		if (desired_nr_to_write != LONG_MAX)
+			desired_nr_to_write *= 8;
+	} else
 		desired_nr_to_write = ext4_num_dirty_pages(inode, index,
 							   max_pages);
 	if (desired_nr_to_write > max_pages)