lkml.org 
[lkml]   [2001]   [Dec]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH] direct IO breaks root filesystem
Hi,

Kernel both 2.4.16-pre7 and 2.5.1-pre8 have serious problem
when we use direct IO for the block device.
These kernel breaks my root filesystem which has /dev
(block device entry) when an application like dd write data
into /dev/sdXX (= not root filesystem's device).

My environment is:
/dev/hda root filesystem with /dev/ dir.
/dev/sda target direct io device
I lost my root filesystem with:
fd = open("/dev/sda", O_DIRECT);
write(fd, data, large_size);

The reason is that when kernel accesses /dev/sda with O_DIRECT,
blkdev_direct_IO() is called. But, it calls generic_direct_IO(),
and generic_direct_IO() calls brw_kiovec(..., inode->i_dev, ...).
If inode->i_dev is root filesystem, not target direct io device,
then inode->i_dev is used for root filesystem overwriting (= then
I lost my root file system...).

Here is patch, it was based some parts in 2.4.10 (and some 2.4.1x-aa).
In my test with this patch, it works well and
kernel does not break my root partition.

Linus and Marcelo, please apply this patch.

-- gotom

--- fs/block_dev.c.vanilla Sat Dec 8 22:46:15 2001
+++ fs/block_dev.c Mon Dec 10 10:45:20 2001
@@ -115,7 +115,25 @@

static int blkdev_direct_IO(int rw, struct inode * inode, struct kiobuf * iobuf, unsigned long blocknr, int blocksize)
{
- return generic_direct_IO(rw, inode, iobuf, blocknr, blocksize, blkdev_get_block);
+ int i, nr_blocks, retval;
+ unsigned long * blocks = iobuf->blocks;
+
+ nr_blocks = iobuf->length / blocksize;
+ /* build the blocklist */
+ for (i = 0; i < nr_blocks; i++, blocknr++) {
+ struct buffer_head bh;
+
+ retval = blkdev_get_block(inode, blocknr, &bh, 0);
+ if (retval)
+ goto out;
+
+ blocks[i] = bh.b_blocknr;
+ }
+
+ retval = brw_kiovec(rw, 1, &iobuf, inode->i_rdev, iobuf->blocks, blocksize);
+
+ out:
+ return retval;
}

static int blkdev_writepage(struct page * page)
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
\
 
 \ /
  Last update: 2005-03-22 13:18    [W:0.105 / U:6.460 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site