Received: with ECARTIS (v1.0.0; list xfs); Fri, 15 Aug 2008 15:08:44 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.3.0-r574664 (2007-09-11) on oss.sgi.com X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.3.0-r574664 Received: from cuda.sgi.com (cuda1.sgi.com [192.48.168.28]) by oss.sgi.com (8.12.11.20060308/8.12.11/SuSE Linux 0.7) with ESMTP id m7FM8fcW022723 for ; Fri, 15 Aug 2008 15:08:41 -0700 X-ASG-Debug-ID: 1218838199-11fd00310000-NocioJ X-Barracuda-URL: http://cuda.sgi.com:80/cgi-bin/mark.cgi Received: from bombadil.infradead.org (localhost [127.0.0.1]) by cuda.sgi.com (Spam Firewall) with ESMTP id 58379F51F6B; Fri, 15 Aug 2008 15:09:59 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org [18.85.46.34]) by cuda.sgi.com with ESMTP id I5sBmWETOArJgkd2; Fri, 15 Aug 2008 15:09:59 -0700 (PDT) Received: from hch by bombadil.infradead.org with local (Exim 4.68 #1 (Red Hat Linux)) id 1KU7Uc-0002QA-PQ; Fri, 15 Aug 2008 22:09:58 +0000 Date: Fri, 15 Aug 2008 18:09:58 -0400 From: Christoph Hellwig To: Lachlan McIlroy Cc: xfs-dev , xfs-oss , akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org X-ASG-Orig-Subj: Re: [REVIEW] Prevent direct I/O from mapping extents beyond eof Subject: Re: [REVIEW] Prevent direct I/O from mapping extents beyond eof Message-ID: <20080815220958.GB13770@infradead.org> References: <48A50152.8020104@sgi.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <48A50152.8020104@sgi.com> User-Agent: Mutt/1.5.18 (2008-05-17) X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org See http://www.infradead.org/rpr.html X-Barracuda-Connect: bombadil.infradead.org[18.85.46.34] X-Barracuda-Start-Time: 1218838200 X-Barracuda-Bayes: INNOCENT GLOBAL 0.0000 1.0000 -2.0210 X-Barracuda-Virus-Scanned: by cuda.sgi.com at sgi.com X-Barracuda-Spam-Score: -2.02 X-Barracuda-Spam-Status: No, SCORE=-2.02 using per-user scores of TAG_LEVEL=2.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=2.1 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.1.2760 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-Virus-Scanned: ClamAV 0.91.2/8048/Fri Aug 15 05:56:27 2008 on oss.sgi.com X-Virus-Status: Clean X-archive-position: 17578 X-ecartis-version: Ecartis v1.0.0 Sender: xfs-bounce@oss.sgi.com Errors-to: xfs-bounce@oss.sgi.com X-original-sender: hch@infradead.org Precedence: bulk X-list: xfs On Fri, Aug 15, 2008 at 02:08:50PM +1000, Lachlan McIlroy wrote: > With the help from some tracing I found that we try to map extents beyond > eof when doing a direct I/O read. It appears that the way to inform the > generic direct I/O path (ie do_direct_IO()) that we have breached eof is > to return an unmapped buffer from xfs_get_blocks_direct(). This will cause > do_direct_IO() to jump to the hole handling code where is will check for > eof and then abort. > > This problem was found because a direct I/O read was trying to map beyond > eof and was encountering delayed allocations. The delayed allocations beyond > eof are speculative allocations and they didn't get converted when the direct > I/O flushed the file because there was only enough space in the current AG > to convert and write out the dirty pages within eof. Note that > xfs_iomap_write_allocate() wont necessarily convert all the delayed allocation > passed to it - it will return after allocating the first extent - so if the > delayed allocation extends beyond eof then it will stay that way. > > This change will detect a direct I/O read beyond eof: The change looks good to me, but I really think the direct I/O could should never send down requests like this down to the filesystems. akpm and -fsdevel Cc'ed. > --- a/fs/xfs/linux-2.6/xfs_aops.c 2008-08-15 13:30:03.000000000 +1000 > +++ b/fs/xfs/linux-2.6/xfs_aops.c 2008-08-11 16:51:07.000000000 +1000 > @@ -1338,6 +1338,10 @@ __xfs_get_blocks( > offset = (xfs_off_t)iblock << inode->i_blkbits; > ASSERT(bh_result->b_size >= (1 << inode->i_blkbits)); > size = bh_result->b_size; > + > + if (!create && direct && offset >= i_size_read(inode)) > + return 0; > + > error = xfs_iomap(XFS_I(inode), offset, size, > create ? flags : BMAPI_READ, &iomap, &niomap); > if (error) > > ---end quoted text---