Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp207092imj; Thu, 14 Feb 2019 18:41:55 -0800 (PST) X-Google-Smtp-Source: AHgI3IZj2G6duaBu7VQpMgWVIyX/DhVYgrqdI35rCqxa36atE1rssg/5dz4MCzMbamRvZjkjqsa7 X-Received: by 2002:a17:902:2a0a:: with SMTP id i10mr7488842plb.323.1550198515841; Thu, 14 Feb 2019 18:41:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550198515; cv=none; d=google.com; s=arc-20160816; b=XCjcjyiLuZo5jiEYQzmMrrr/40qZWB6O6HJlEzOWNd0avsDjYDqZG3XeFh6a5q1W0U rWRZAlTUwmYBWqF9QXmK/belP/EOedAl2iv7EcVJXnQFrBVInCZdAsAIPS9gmHbgNj0/ SzBEgqA1TRZqavfwzeupNlHRPQJAzajpoeG4n34DSw5hGCip5rYQH/Ha+MHU0UGc5QE7 pLnfRz5zT92wZ+Mz0uyiSOFNeXh2qtOeczft059yQmnd2xNvogqI/Fg9Q7DGH7dxyxV9 QdFmNJytauUhIn+GqROGEnTEE4jcmg0ZFY8i2hCkTcO38bPzC3oqdsrbTFafTRHau9N5 gHCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=d4TCmJ1WuQ3byMxZf5pprWjQTYMuFAUI9+86MRNYWao=; b=l5D+1MxIbXxIG1Vwj+pX0MW06oz+VZoO9FRI3fKdQViflAzqZuxl1E1hEWr8pWITX9 eyEVSC+baOYS5FenRenGev3Uhjz+ES7CAxIUwtllB0VnbGdKsBLsmArinKIfzwP3K5aX PpcEBU2o2qTu7ECge2Xd9I7TR3i/RoQa8rcKPrk4jJC3HBTRExm68IyfSU6HsHpXEOdS C1sSIgm/dRjf/iVDkayj24dFmrU/e+0EKtqoDkVr0gma476BrqaoKrrvArieHoU/Z2Hr mKzDInChB7aly/Qr7uQ3H1tz6DJNgSRCmkAidIGpAOOHFK6emrcpQaqgkSUAggDo9qmX WFcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JkJzdfFk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a2si3830178pgw.264.2019.02.14.18.41.39; Thu, 14 Feb 2019 18:41:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JkJzdfFk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390278AbfBOCKV (ORCPT + 99 others); Thu, 14 Feb 2019 21:10:21 -0500 Received: from mail.kernel.org ([198.145.29.99]:50390 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390248AbfBOCKR (ORCPT ); Thu, 14 Feb 2019 21:10:17 -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 C892D222D0; Fri, 15 Feb 2019 02:10:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1550196616; bh=xgDfpH2l43JGOkzUTQ7lPb7C8kiridv7NZFQqC7pwJA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JkJzdfFkhWcTfdz+dxUpwicdRZL6BqmhHDaoXoiCSY/3lxAHLeOvog9EnshYUO5p7 sDfM3FQDdnU1LJTPFh1d6CKfsir8ez/yWJ6/dfFx+AuRxiBRuxd0m4tg/Pu7ofOk/O HGixPbHf2jDNKFpGLp8AbwjuSKIXshaUGDkkNUTQ= 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.20 48/77] direct-io: allow direct writes to empty inodes Date: Thu, 14 Feb 2019 21:08:26 -0500 Message-Id: <20190215020855.176727-48-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190215020855.176727-1-sashal@kernel.org> References: <20190215020855.176727-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 41a0e97252ae..7d3f2c1d141d 100644 --- a/fs/direct-io.c +++ b/fs/direct-io.c @@ -679,6 +679,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 @@ -708,8 +709,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