From patchwork Thu Jan 26 18:04:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Moyer X-Patchwork-Id: 138005 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 182A5B6EF1 for ; Fri, 27 Jan 2012 05:18:03 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752255Ab2AZSSA (ORCPT ); Thu, 26 Jan 2012 13:18:00 -0500 Received: from mx1.redhat.com ([209.132.183.28]:16264 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751624Ab2AZSSA (ORCPT ); Thu, 26 Jan 2012 13:18:00 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q0QIHOEl005847 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 26 Jan 2012 13:17:36 -0500 Received: from segfault.boston.devel.redhat.com (segfault.boston.devel.redhat.com [10.16.60.26]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q0QI4MYT028468; Thu, 26 Jan 2012 13:04:22 -0500 From: Jeff Moyer To: Jan Kara Cc: linux-ext4@vger.kernel.org Subject: Re: [patch|rfc] ext4: fix race between unwritten extent conversion and truncate References: <20120126170209.GE17113@quack.suse.cz> X-PGP-KeyID: 1F78E1B4 X-PGP-CertKey: F6FE 280D 8293 F72C 65FD 5A58 1FF8 A7CA 1F78 E1B4 X-PCLoadLetter: What the f**k does that mean? Date: Thu, 26 Jan 2012 13:04:22 -0500 In-Reply-To: <20120126170209.GE17113@quack.suse.cz> (Jan Kara's message of "Thu, 26 Jan 2012 18:02:09 +0100") Message-ID: User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Jan Kara writes: >> --- a/fs/ext4/fsync.c >> +++ b/fs/ext4/fsync.c >> @@ -104,7 +104,7 @@ int ext4_flush_completed_IO(struct inode *inode) >> * queue work. >> */ >> spin_unlock_irqrestore(&ei->i_completed_io_lock, flags); >> - ret = ext4_end_io_nolock(io); >> + ret = ext4_end_io_nolock(io, false); > This is wrong. i_completed_io_list contains work items for both direct > and buffered IO. Just in ext4_flush_completed_IO() we process the list > synchronously while ext4_end_io_work() processes the list in the > background. So what you have to do is store in ext4_io_end_t whether the IO > was direct or not and then use that in ext4_end_io_nolock() function. OK, thanks for the review. Is the following what you had in mind? If so, I'll repost with a proper header. Cheers, Jeff Signed-off-by: Jeff Moyer --- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 513004f..2d55d7c 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -184,6 +184,7 @@ struct mpage_da_data { #define EXT4_IO_END_UNWRITTEN 0x0001 #define EXT4_IO_END_ERROR 0x0002 #define EXT4_IO_END_QUEUED 0x0004 +#define EXT4_IO_END_DIRECT 0x0008 struct ext4_io_page { struct page *p_page; diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index feaa82f..f6dc02b 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -2795,9 +2795,6 @@ out: /* queue the work to convert unwritten extents to written */ queue_work(wq, &io_end->work); - - /* XXX: probably should move into the real I/O completion handler */ - inode_dio_done(inode); } static void ext4_end_io_buffer_write(struct buffer_head *bh, int uptodate) @@ -2921,9 +2918,12 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb, iocb->private = NULL; EXT4_I(inode)->cur_aio_dio = NULL; if (!is_sync_kiocb(iocb)) { - iocb->private = ext4_init_io_end(inode, GFP_NOFS); - if (!iocb->private) + ext4_io_end_t *io_end = + ext4_init_io_end(inode, GFP_NOFS); + if (!io_end) return -ENOMEM; + io_end->flag |= EXT4_IO_END_DIRECT; + iocb->private = io_end; /* * we save the io structure for current async * direct IO, so that later ext4_map_blocks() diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c index 4758518..9e1b8eb 100644 --- a/fs/ext4/page-io.c +++ b/fs/ext4/page-io.c @@ -110,6 +110,8 @@ int ext4_end_io_nolock(ext4_io_end_t *io) if (io->iocb) aio_complete(io->iocb, io->result, 0); + if (io->flag & EXT4_IO_END_DIRECT) + inode_dio_done(inode); /* Wake up anyone waiting on unwritten extent conversion */ if (atomic_dec_and_test(&EXT4_I(inode)->i_aiodio_unwritten)) wake_up_all(ext4_ioend_wq(io->inode));