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.0 required=3.0 tests=BAD_ENC_HEADER,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,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 593BCC43381 for ; Mon, 4 Mar 2019 08:25:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 295A520823 for ; Mon, 4 Mar 2019 08:25:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1551687954; bh=ugzjylJRrkDOy1zqJeOZhJETgi2HcWvkSWrLI6rt1kk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=R1GbKwG9VTucBDsctlEHFPxLefI8WdpZd2A8DghUs0SnZ/kYbpHH2h9RgE94uT+sb HXDXAZZqfq4cxIy0hQhc3+qAZr8hl0WJ0AoNny8pvqyIM+s4RWWtURYymQBCDsDWzY w1NPQ707igWEdmkYZkwdcTZ4EfMSS81L9bt54QeA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726708AbfCDIZr (ORCPT ); Mon, 4 Mar 2019 03:25:47 -0500 Received: from mail.kernel.org ([198.145.29.99]:45224 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726639AbfCDIZ0 (ORCPT ); Mon, 4 Mar 2019 03:25:26 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C150A20823; Mon, 4 Mar 2019 08:25:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1551687926; bh=ugzjylJRrkDOy1zqJeOZhJETgi2HcWvkSWrLI6rt1kk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QqszO6UXps27LVmRZ6plHOHfXdXXzTLvxX2sPaPYKKHpMIr9N/2ePopzoa2jvJ6IJ BYfr0sJszMxRIWPfFrzpYmY2LyqQO2Q0sibgfnsFyhUTWAL6Z7R7b+duHqt6Fy+POy jIp7PCwwwG2qC2z7G/7vsdlEb5iIV3R1/JKK7LAY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jeff Moyer , Jan Kara , "=?UTF-8?q?Ernesto=20A . =20Fern=C3=A1ndez?=" , Jens Axboe , Sasha Levin Subject: [PATCH 4.14 31/52] direct-io: allow direct writes to empty inodes Date: Mon, 4 Mar 2019 09:22:29 +0100 Message-Id: <20190304081618.955279776@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190304081617.159014799@linuxfoundation.org> References: <20190304081617.159014799@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ [ 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 40567501015f2..2c90d541f5275 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