From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25C6EC4360F for ; Fri, 15 Feb 2019 02:14:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DB6C121934 for ; Fri, 15 Feb 2019 02:14:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1550196849; bh=LyGBOZ3QpH1V44siLjQLa+ddIvvbnfqpkmWCnoZVtno=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=D6fy1K0zI4upr6hFZRnAb91MoIMxmJCdoMgp8WCinJGmpc8mEtIjHmf81lOWNQkAD S3j+Wqq2p90ibbSqNkrF9wEoL0ZDwuQXBpRBML9Ka4a5PTUP6HXoWr2ByyFTTN43c7 PPAF5iZRjccy9/cdqkSHo0TqnKGtJpRlcMzIiusk= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391546AbfBOCOH (ORCPT ); Thu, 14 Feb 2019 21:14:07 -0500 Received: from mail.kernel.org ([198.145.29.99]:53930 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405034AbfBOCOA (ORCPT ); Thu, 14 Feb 2019 21:14:00 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 10918206BA; Fri, 15 Feb 2019 02:13:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1550196839; bh=LyGBOZ3QpH1V44siLjQLa+ddIvvbnfqpkmWCnoZVtno=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vO5j86DMMgrop7cc3O25C+jK6cZUqrqMfhQ6lb/c2t4pRJ5tm0tEEB5ttk1ofqRXZ U6ATKzxsgEYGK/YBGQPwqC1NcNWyn6h3dk6QannUr7PzThD5eNuo9R0HVj1tidM1HE M3ASD2uvd4VpwLZDahh16+IsA2gSd+afdG/dwYhQ= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: =?UTF-8?q?Ernesto=20A=2E=20Fern=C3=A1ndez?= , Jens Axboe , Sasha Levin , linux-fsdevel@vger.kernel.org Subject: [PATCH AUTOSEL 4.14 26/40] direct-io: allow direct writes to empty inodes Date: Thu, 14 Feb 2019 21:12:59 -0500 Message-Id: <20190215021313.178476-26-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190215021313.178476-1-sashal@kernel.org> References: <20190215021313.178476-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ernesto A. Fernández [ Upstream commit 8b9433eb4de3c26a9226c981c283f9f4896ae030 ] On a DIO_SKIP_HOLES filesystem, the ->get_block() method is currently not allowed to create blocks for an empty inode. This confusion comes from trying to bit shift a negative number, so check the size of the inode first. The problem is most visible for hfsplus, because the fallback to buffered I/O doesn't happen and the write fails with EIO. This is in part the fault of the module, because it gives a wrong return value on ->get_block(); that will be fixed in a separate patch. Reviewed-by: Jeff Moyer Reviewed-by: Jan Kara Signed-off-by: Ernesto A. Fernández Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- fs/direct-io.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/direct-io.c b/fs/direct-io.c index 40567501015f..2c90d541f527 100644 --- a/fs/direct-io.c +++ b/fs/direct-io.c @@ -658,6 +658,7 @@ static int get_more_blocks(struct dio *dio, struct dio_submit *sdio, unsigned long fs_count; /* Number of filesystem-sized blocks */ int create; unsigned int i_blkbits = sdio->blkbits + sdio->blkfactor; + loff_t i_size; /* * If there was a memory error and we've overwritten all the @@ -687,8 +688,8 @@ static int get_more_blocks(struct dio *dio, struct dio_submit *sdio, */ create = dio->op == REQ_OP_WRITE; if (dio->flags & DIO_SKIP_HOLES) { - if (fs_startblk <= ((i_size_read(dio->inode) - 1) >> - i_blkbits)) + i_size = i_size_read(dio->inode); + if (i_size && fs_startblk <= (i_size - 1) >> i_blkbits) create = 0; } -- 2.19.1