From mboxrd@z Thu Jan 1 00:00:00 1970 From: Al Viro Subject: Re: [RFC] write(2) semantics wrt return values and current position Date: Wed, 8 Apr 2015 20:24:50 +0100 Message-ID: <20150408192450.GQ889@ZenIV.linux.org.uk> References: <20150406153641.GL889@ZenIV.linux.org.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Linus Torvalds , Trond Myklebust , Christoph Hellwig , Dave Chinner , Theodore Ts'o , Miklos Szeredi , Oleg Drokin , Joseph Qi , Joel Becker , Mark Fasheh To: linux-fsdevel@vger.kernel.org Return-path: Received: from zeniv.linux.org.uk ([195.92.253.2]:59840 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932219AbbDHTZj (ORCPT ); Wed, 8 Apr 2015 15:25:39 -0400 Content-Disposition: inline In-Reply-To: <20150406153641.GL889@ZenIV.linux.org.uk> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Mon, Apr 06, 2015 at 05:02:31PM +0100, Al Viro wrote: 7) commit 3a83b342c87e6d21290de8dc76ec20a67821261d Author: Joseph Qi Date: Mon Feb 16 16:00:09 2015 -0800 ocfs2: complete the rest request through buffer io appears to be very odd. Look: written = generic_file_direct_write(iocb, from, *ppos); - if (written < 0) { + if (written < 0 || written == count) { ret = written; goto out_dio; } + + /* + * for completing the rest of the request. + */ + *ppos += written; ppos here is &iocb->ki_pos. Now, take a look at the end of generic_file_direct_write(): if (written > 0) { pos += written; iov_iter_advance(from, written); if (pos > i_size_read(inode) && !S_ISBLK(inode->i_mode)) { i_size_write(inode, pos); mark_inode_dirty(inode); } iocb->ki_pos = pos; } out: return written; In other words, after short write done by ->direct_IO(), we end up incrementing position by *twice* the amount written by it. And if it's short, but not empty, we appear to be buggered... Unless I hear "Al, you idiot, it's doing the right thing, here's what you've missed: ...", I'm going to take that increment in ocfs2_file_write_iter() out, and send it to Linus for 4.0 - it's post-3.19 regression.