diff mbox

btrfs: fix return value check of btrfs_start_transaction()

Message ID 4D392265.1020003@jp.fujitsu.com (mailing list archive)
State New, archived
Headers show

Commit Message

Tsutomu Itoh Jan. 21, 2011, 6:06 a.m. UTC
None
diff mbox

Patch

diff -urNp linux-2.6.38-rc1/fs/btrfs/transaction.c linux-2.6.38-rc1.new/fs/btrfs/transaction.c
--- linux-2.6.38-rc1/fs/btrfs/transaction.c	2011-01-19 08:14:02.000000000 +0900
+++ linux-2.6.38-rc1.new/fs/btrfs/transaction.c	2011-01-21 14:08:02.000000000 +0900
@@ -22,6 +22,7 @@ 
 #include <linux/writeback.h>
 #include <linux/pagemap.h>
 #include <linux/blkdev.h>
+#include <linux/ratelimit.h>
 #include "ctree.h"
 #include "disk-io.h"
 #include "transaction.h"
@@ -175,6 +176,25 @@  static int may_wait_transaction(struct b
 	return 0;
 }
 
+#define MAX_ITERATIONS 10
+
+static struct btrfs_trans_handle *alloc_trans_handle(void)
+{
+	struct btrfs_trans_handle *ret;
+	int i = 0;
+
+	ret = kmem_cache_alloc(btrfs_trans_handle_cachep, GFP_NOFS);
+	if (!ret) {
+		pr_notice_ratelimited("ENOMEM in %s, retrying.\n", __func__);
+		do {
+			yield();
+			ret = kmem_cache_alloc(btrfs_trans_handle_cachep,
+						GFP_NOFS);
+		} while (!ret && i++ < MAX_ITERATIONS);
+	}
+	return ret;
+}
+
 static struct btrfs_trans_handle *start_transaction(struct btrfs_root *root,
 						    u64 num_items, int type)
 {
@@ -185,7 +205,7 @@  static struct btrfs_trans_handle *start_
 	if (root->fs_info->fs_state & BTRFS_SUPER_FLAG_ERROR)
 		return ERR_PTR(-EROFS);
 again:
-	h = kmem_cache_alloc(btrfs_trans_handle_cachep, GFP_NOFS);
+	h = alloc_trans_handle();
 	if (!h)
 		return ERR_PTR(-ENOMEM);