* [PATCH] Btrfs: cleanup pages properly when ENOMEM in compression
@ 2012-10-05 17:49 Josef Bacik
2012-10-05 20:06 ` David Sterba
0 siblings, 1 reply; 3+ messages in thread
From: Josef Bacik @ 2012-10-05 17:49 UTC (permalink / raw)
To: linux-btrfs
We were freeing non-existent pages which was causing a panic for a user who
was suffering from ENOMEM. This patch fixes the problem. Thanks,
Reported-by: Jérôme Poulin <jeromepoulin@gmail.com>
Signed-off-by: Josef Bacik <jbacik@fusionio.com>
---
fs/btrfs/compression.c | 12 +++++++++---
1 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index 43d1c5a..36eb5f2 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -577,6 +577,7 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
u64 em_start;
struct extent_map *em;
int ret = -ENOMEM;
+ int faili = 0;
u32 *sums;
tree = &BTRFS_I(inode)->io_tree;
@@ -626,8 +627,11 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
for (pg_index = 0; pg_index < nr_pages; pg_index++) {
cb->compressed_pages[pg_index] = alloc_page(GFP_NOFS |
__GFP_HIGHMEM);
- if (!cb->compressed_pages[pg_index])
+ if (!cb->compressed_pages[pg_index]) {
+ faili = pg_index - 1;
+ ret = -ENOMEM;
goto fail2;
+ }
}
cb->nr_pages = nr_pages;
@@ -713,8 +717,10 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
return 0;
fail2:
- for (pg_index = 0; pg_index < nr_pages; pg_index++)
- free_page((unsigned long)cb->compressed_pages[pg_index]);
+ while (faili >= 0) {
+ __free_page(cb->compressed_pages[pg_index]);
+ faili--;
+ }
kfree(cb->compressed_pages);
fail1:
--
1.7.7.6
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Btrfs: cleanup pages properly when ENOMEM in compression
2012-10-05 17:49 [PATCH] Btrfs: cleanup pages properly when ENOMEM in compression Josef Bacik
@ 2012-10-05 20:06 ` David Sterba
2012-10-05 20:32 ` David Sterba
0 siblings, 1 reply; 3+ messages in thread
From: David Sterba @ 2012-10-05 20:06 UTC (permalink / raw)
To: Josef Bacik; +Cc: linux-btrfs
On Fri, Oct 05, 2012 at 01:49:19PM -0400, Josef Bacik wrote:
> --- a/fs/btrfs/compression.c
> +++ b/fs/btrfs/compression.c
> @@ -577,6 +577,7 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
> u64 em_start;
> struct extent_map *em;
> int ret = -ENOMEM;
> + int faili = 0;
> u32 *sums;
>
> tree = &BTRFS_I(inode)->io_tree;
> @@ -626,8 +627,11 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
> for (pg_index = 0; pg_index < nr_pages; pg_index++) {
> cb->compressed_pages[pg_index] = alloc_page(GFP_NOFS |
> __GFP_HIGHMEM);
> - if (!cb->compressed_pages[pg_index])
> + if (!cb->compressed_pages[pg_index]) {
> + faili = pg_index - 1;
> + ret = -ENOMEM;
> goto fail2;
> + }
> }
> cb->nr_pages = nr_pages;
>
> @@ -713,8 +717,10 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
> return 0;
>
> fail2:
> - for (pg_index = 0; pg_index < nr_pages; pg_index++)
> - free_page((unsigned long)cb->compressed_pages[pg_index]);
> + while (faili >= 0) {
> + __free_page(cb->compressed_pages[pg_index]);
^^^^^^^^
s/pg_index/faili/
Also, faili (how do you pronounce that?) is initialized to 0, the while
loop will always fire (and burn a page), initialize it to -1.
Other than that, I like the fix, thanks.
> + faili--;
> + }
>
> kfree(cb->compressed_pages);
> fail1:
david
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-10-05 20:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-05 17:49 [PATCH] Btrfs: cleanup pages properly when ENOMEM in compression Josef Bacik
2012-10-05 20:06 ` David Sterba
2012-10-05 20:32 ` David Sterba
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).