ext4: don't allow ext4_free_blocks() to fail due to ENOMEM
authorTheodore Ts'o <tytso@mit.edu>
Sat, 13 Jul 2013 04:40:35 +0000 (00:40 -0400)
committerBen Hutchings <ben@decadent.org.uk>
Fri, 2 Aug 2013 20:14:55 +0000 (22:14 +0200)
commit e7676a704ee0a1ef71a6b23760b5a8f6896cb1a1 upstream.

The filesystem should not be marked inconsistent if ext4_free_blocks()
is not able to allocate memory.  Unfortunately some callers (most
notably ext4_truncate) don't have a way to reflect an error back up to
the VFS.  And even if we did, most userspace applications won't deal
with most system calls returning ENOMEM anyway.

Reported-by: Nagachandra P <nagachandra@gmail.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
[bwh: Backported to 3.2: adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
fs/ext4/mballoc.c

index 9243103..9b8c131 100644 (file)
@@ -4696,11 +4696,16 @@ do_more:
                 * blocks being freed are metadata. these blocks shouldn't
                 * be used until this transaction is committed
                 */
+       retry:
                new_entry = kmem_cache_alloc(ext4_free_ext_cachep, GFP_NOFS);
                if (!new_entry) {
-                       ext4_mb_unload_buddy(&e4b);
-                       err = -ENOMEM;
-                       goto error_return;
+                       /*
+                        * We use a retry loop because
+                        * ext4_free_blocks() is not allowed to fail.
+                        */
+                       cond_resched();
+                       congestion_wait(BLK_RW_ASYNC, HZ/50);
+                       goto retry;
                }
                new_entry->start_cluster = bit;
                new_entry->group  = block_group;