Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id ; Sun, 9 Dec 2001 22:59:58 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id ; Sun, 9 Dec 2001 22:59:47 -0500 Received: from ikura.fe.dis.titech.ac.jp ([131.112.171.65]:29824 "HELO ikura.fe.dis.titech.ac.jp") by vger.kernel.org with SMTP id ; Sun, 9 Dec 2001 22:59:36 -0500 Date: Mon, 10 Dec 2001 12:59:32 +0900 Message-ID: From: GOTO Masanori To: marcelo@conectiva.com.br, torvalds@transmeta.com Cc: linux-kernel@vger.kernel.org, gotom@debian.org, andrea@suse.de Subject: Re: [PATCH] direct IO breaks root filesystem In-Reply-To: In your message of "Sun, 09 Dec 2001 00:24:20 +0900" In-Reply-To: User-Agent: Wanderlust/2.2.15 (More Than Words) EMIKO/1.13.9 (Euglena tripteris) FLIM/1.13.2 (Kasanui) APEL/10.2 MULE XEmacs/21.1 (patch 10) (Capitol Reef) (i386-debian-linux) MIME-Version: 1.0 (generated by EMIKO 1.13.9 - "Euglena tripteris") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org 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/