diff mbox

[3/3] btrfs: fix panic caused by direct IO

Message ID 4CE358C7.3040902@cn.fujitsu.com (mailing list archive)
State New, archived
Headers show

Commit Message

Miao Xie Nov. 17, 2010, 4:23 a.m. UTC
None
diff mbox

Patch

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 32b68fa..341d080 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -5689,6 +5689,20 @@  static int __btrfs_submit_bio_start_direct_io(struct inode *inode, int rw,
 	return 0;
 }
 
+/*
+ * This function is used to check the chunk tree when doing direct IO because
+ * btrfs can't create bios that span stripes or chunks.
+ */
+static int btrfs_can_merge_page_dio(size_t size, struct inode *inode,
+				    struct bio *bio)
+{
+	struct btrfs_root *root = BTRFS_I(inode)->root;
+	struct btrfs_mapping_tree *map_tree;
+
+	map_tree = &root->fs_info->mapping_tree;
+	return __btrfs_can_merge_page_to_bio(map_tree, size, bio);
+}
+
 static void btrfs_submit_direct(int rw, struct bio *bio, struct inode *inode,
 				loff_t file_offset)
 {
@@ -5873,7 +5887,7 @@  static ssize_t btrfs_direct_IO(int rw, struct kiocb *iocb,
 	ret = __blockdev_direct_IO(rw, iocb, inode,
 		   BTRFS_I(inode)->root->fs_info->fs_devices->latest_bdev,
 		   iov, offset, nr_segs, btrfs_get_blocks_direct, NULL,
-		   btrfs_submit_direct, NULL, 0);
+		   btrfs_submit_direct, btrfs_can_merge_page_dio, 0);
 
 	if (ret < 0 && ret != -EIOCBQUEUED) {
 		clear_extent_bit(&BTRFS_I(inode)->io_tree, offset,