From patchwork Mon Oct 8 23:58:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ernesto_A=2E_Fern=C3=A1ndez?= X-Patchwork-Id: 10631731 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EFF3C933 for ; Mon, 8 Oct 2018 23:58:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E0D5E29629 for ; Mon, 8 Oct 2018 23:58:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D50022966E; Mon, 8 Oct 2018 23:58:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8229D29629 for ; Mon, 8 Oct 2018 23:58:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725887AbeJIHMm (ORCPT ); Tue, 9 Oct 2018 03:12:42 -0400 Received: from mail-qt1-f194.google.com ([209.85.160.194]:37242 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725803AbeJIHMm (ORCPT ); Tue, 9 Oct 2018 03:12:42 -0400 Received: by mail-qt1-f194.google.com with SMTP id d14-v6so14275385qto.4 for ; Mon, 08 Oct 2018 16:58:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding; bh=OabvvKyuwIz/fj0xYv32htVZzlRlh7m2cPXrdAwGyBw=; b=EQnpW1jFUqRBOxvJnw6MSC0XYXZwSgl75Y0DaamsXrh2qA9rzBFKoKRTrrwpDTiB/6 U81HGfquS7jKiEFDW4IwdW0wJ9SkI/YT2sMSJ/VdrF1RHsy7AFHZ7xe0O8c3IzSoGL1V 1rQYGG3XdOSjlKWiXVuBCR3cX3ZBqpywi5gZLI+4qSM+Ds9FZFghpOZMyPGkl9oAJMxh dWq+4fW4fwlVOZEipoMpRukxGrhlYgChgl1BfSBnpohml1mOXBSYnFf8f05c+fbwrS9N yC2iyvm9ExFytTkhDI3xuj/LEC4cqgWmDoot3tkqjnLb4/aq0HlaNjk5+qSdqCx0lem6 J4zA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding; bh=OabvvKyuwIz/fj0xYv32htVZzlRlh7m2cPXrdAwGyBw=; b=TLkNXfQejTZ/pRDIU4/mbVGzilLUzt6cuHHUfEOq4XwK+X2BxbAL5BQJW7i+S/rTem /S0HuXzLxOeGZBJnReHd7Sc/wXMDSMdUGzW5JzxNdkPOXwFjZUQ8pwsmpPemKQyD+9K4 ioqqb/oafDsg53IhQjyqw3u3peuJM1Oh47I79OpLDNAIFUIo/UsoyuGKGtkKx7MR8N/R /2dyEIt1D4/AlclLWG73i48bcwPiDR+7kkb230iAHVkegSY+WTYb42WBwwMY3eiMu4fi ikdQUfj7sZcsGObKDsVQ8Ufp7pHLAiqiGiBxcTN9JZsPrOoJcSGfeW7VpPck3KfnQFkv 1llg== X-Gm-Message-State: ABuFfogtGMK0uPQjTDk1ca/82ZFa4pTTEOESuPJOGZ4OVrxzpuQCTEex +LgKLiVxN2qf+6KjF3SZRBTZPQRg X-Google-Smtp-Source: ACcGV62UDhxqMU8Dw15wjbPNmyPfyEp8IiilKaNES4oTxYisWKt5PSCqmNPwOvuAmudqt9GIf6LoYA== X-Received: by 2002:a0c:c591:: with SMTP id a17-v6mr21680081qvj.183.1539043108892; Mon, 08 Oct 2018 16:58:28 -0700 (PDT) Received: from eaf ([181.47.179.0]) by smtp.gmail.com with ESMTPSA id d43-v6sm11550023qtd.69.2018.10.08.16.58.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Oct 2018 16:58:28 -0700 (PDT) Date: Mon, 8 Oct 2018 20:58:23 -0300 From: Ernesto =?utf-8?q?A=2E_Fern=C3=A1ndez?= To: linux-fsdevel@vger.kernel.org Cc: Alexander Viro Subject: [PATCH] direct-io: allow direct writes to empty inodes Message-ID: <20181008235823.5rpr4dqgriiacsvy@eaf> MIME-Version: 1.0 Content-Disposition: inline Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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. Signed-off-by: Ernesto A. Fernández Reviewed-by: Jan Kara --- 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 093fb54cd316..9a7b91a3b7a7 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; }