From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dmitry Monakhov Subject: [PATCH] direct_io: Allow partial writes Date: Tue, 6 Apr 2010 18:47:23 +0400 Message-ID: <1270565243-29698-1-git-send-email-dmonakhov@openvz.org> Cc: akpm@linux-foundation.org, npiggin@suse.de, Dmitry Monakhov To: linux-fsdevel@vger.kernel.org Return-path: Received: from mail-bw0-f209.google.com ([209.85.218.209]:48202 "EHLO mail-bw0-f209.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754474Ab0DFOrs (ORCPT ); Tue, 6 Apr 2010 10:47:48 -0400 Received: by bwz1 with SMTP id 1so3685142bwz.21 for ; Tue, 06 Apr 2010 07:47:46 -0700 (PDT) Sender: linux-fsdevel-owner@vger.kernel.org List-ID: Current direct io allocation behavior is inconvenient. Partial writes are not supported. If we try to issue 10Mb chunk, but only 5Mb is available then we will allocate thees 5Mb until ENOSPC, and then drop such space and return ENOSPC. Partial success was rejected because it wasn't obvious how to distinguish non fatal errors (ENOSPC,EDQUOT,ENOMEM, etc) from fatal ones (EIO,EFAULT, and so on). But in fact there are only two sources of fatal error: 1) from bi_end_io and result in EIO and saved to dio->io_error 2) from get_user_pages_fast and saved to dio->page_errors In case of partial write it is safe to ignore error code because in case of fatal error it will be restored and returned to caller from dio_complete(). Signed-off-by: Dmitry Monakhov --- fs/direct-io.c | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-) diff --git a/fs/direct-io.c b/fs/direct-io.c index e82adc2..1298dc3 100644 --- a/fs/direct-io.c +++ b/fs/direct-io.c @@ -230,7 +230,13 @@ static int dio_complete(struct dio *dio, loff_t offset, int ret) if (dio->result) { transferred = dio->result; - + /* + * Ignore non fatal error if some data was written. + * Fatal error was saved in dio structure and will be + * restored later at the bottom of the function. + */ + if (dio->rw & WRITE) + ret = 0; /* Check for short read case */ if ((dio->rw == READ) && ((offset + transferred) > dio->i_size)) transferred = dio->i_size - offset; -- 1.6.6.1