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=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,UNPARSEABLE_RELAY, USER_AGENT_GIT autolearn=ham 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 34A08C282DA for ; Wed, 17 Apr 2019 20:04:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0E2D221773 for ; Wed, 17 Apr 2019 20:04:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732104AbfDQUEw (ORCPT ); Wed, 17 Apr 2019 16:04:52 -0400 Received: from out30-56.freemail.mail.aliyun.com ([115.124.30.56]:42970 "EHLO out30-56.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725848AbfDQUEw (ORCPT ); Wed, 17 Apr 2019 16:04:52 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R431e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04423;MF=bo.liu@linux.alibaba.com;NM=1;PH=DS;RN=2;SR=0;TI=SMTPD_---0TPaWqQN_1555531487; Received: from localhost(mailfrom:bo.liu@linux.alibaba.com fp:SMTPD_---0TPaWqQN_1555531487) by smtp.aliyun-inc.com(127.0.0.1); Thu, 18 Apr 2019 04:04:48 +0800 From: Liu Bo To: linux-fsdevel@vger.kernel.org Cc: Miklos Szeredi Subject: [PATCH] fuse: do not write whole page while page straddles i_size Date: Thu, 18 Apr 2019 04:04:40 +0800 Message-Id: <20190417200441.90291-1-bo.liu@linux.alibaba.com> X-Mailer: git-send-email 2.20.1.2.gb21ebb6 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Xiaoguang Wang If page straddles i_size and we write the whole page, the fuse user-space filesystem may extend file size, it will confuse users. Before this patch: xfs_io -t -f \ -c "truncate 5120" \ -c "pwrite -S 0x58 0 5120" \ -c "mmap -rw 0 5120" \ -c "mwrite -S 0x59 2048 3072" \ -c "close" \ testfile testfile's length will be 8192 bytes, with this patch, testfile's length will be 5120 bytes. Signed-off-by: Xiaoguang Wang Signed-off-by: Liu Bo --- fs/fuse/file.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 06096b60f1df..44e76b00e985 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -1863,6 +1863,8 @@ static int fuse_writepages_fill(struct page *page, struct page *tmp_page; bool is_writeback; int err; + loff_t size; + unsigned int len; if (!data->ff) { err = -EIO; @@ -1940,7 +1942,12 @@ static int fuse_writepages_fill(struct page *page, copy_highpage(tmp_page, page); req->pages[req->num_pages] = tmp_page; req->page_descs[req->num_pages].offset = 0; - req->page_descs[req->num_pages].length = PAGE_SIZE; + size = i_size_read(inode); + if (page->index == size >> PAGE_SHIFT) + len = size & ~PAGE_MASK; + else + len = PAGE_SIZE; + req->page_descs[req->num_pages].length = len; inc_wb_stat(&inode_to_bdi(inode)->wb, WB_WRITEBACK); inc_node_page_state(tmp_page, NR_WRITEBACK_TEMP); -- 2.20.1.2.gb21ebb6