From nobody Wed Apr 8 21:37:45 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5C60C38A02 for ; Fri, 28 Oct 2022 17:03:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229602AbiJ1RDs (ORCPT ); Fri, 28 Oct 2022 13:03:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230478AbiJ1RD3 (ORCPT ); Fri, 28 Oct 2022 13:03:29 -0400 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBDAE23081F; Fri, 28 Oct 2022 10:01:50 -0700 (PDT) Received: from relayfre-01.paragon-software.com (unknown [172.30.72.12]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 89070218D; Fri, 28 Oct 2022 16:59:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1666976349; bh=XLfhoLoajHMwxGkqzmutjSB0VcGNCexWxhovGxocDdI=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=EW2if9qksfM9ykb5vJ5T+0epiSG1fwqImLSQsTlJXDYcjNtWFffwQuMOhGlyFwRV8 VyTKUkkN4oTsHM//ZvfVw2hmDlygOYMwAJUFN7E4DLDOQSSqhrx3TGENdqSlXxyMJy 98HF+7e+WzRPqSSKloFrys6uA4apCN55EYB98MAM= Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayfre-01.paragon-software.com (Postfix) with ESMTPS id 840D71D2B; Fri, 28 Oct 2022 17:01:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1666976508; bh=XLfhoLoajHMwxGkqzmutjSB0VcGNCexWxhovGxocDdI=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=mMpJm5c+GkKRzjGX0HSF3iwKVFVVaYBhnyggovRXyg/bn0Q1waIULI89IHvQKUZfy c9dux2uNyDKICPgAHOZoz7hV3QHScHHxPG5wNixtPzXr7ThG5Gaf2e8qH6OKH0H46h QdPYy//F6Ip7e8rnGz801aOnM9hgNHAPKDdr/m9o= Received: from [172.30.8.65] (172.30.8.65) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Fri, 28 Oct 2022 20:01:48 +0300 Message-ID: Date: Fri, 28 Oct 2022 20:01:47 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: [PATCH 01/14] fs/ntfs3: Fixing work with sparse clusters Content-Language: en-US From: Konstantin Komarov To: CC: , References: In-Reply-To: Content-Transfer-Encoding: quoted-printable X-Originating-IP: [172.30.8.65] X-ClientProxiedBy: vdlg-exch-02.paragon-software.com (172.30.1.105) To vdlg-exch-02.paragon-software.com (172.30.1.105) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8"; format="flowed" Simplify logic in ntfs_extend_initialized_size, ntfs_sparse_cluster and ntfs_fallocate. Signed-off-by: Konstantin Komarov --- fs/ntfs3/file.c | 45 ++++++++++++--------------------------------- fs/ntfs3/inode.c | 7 ++++++- 2 files changed, 18 insertions(+), 34 deletions(-) diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c index 4f2ffc7ef296..96ba3f5a8470 100644 --- a/fs/ntfs3/file.c +++ b/fs/ntfs3/file.c @@ -128,25 +128,9 @@ static int ntfs_extend_initialized_size(struct file *f= ile, goto out; =20 if (lcn =3D=3D SPARSE_LCN) { - loff_t vbo =3D (loff_t)vcn << bits; - loff_t to =3D vbo + ((loff_t)clen << bits); - - if (to <=3D new_valid) { - ni->i_valid =3D to; - pos =3D to; - goto next; - } - - if (vbo < pos) { - pos =3D vbo; - } else { - to =3D (new_valid >> bits) << bits; - if (pos < to) { - ni->i_valid =3D to; - pos =3D to; - goto next; - } - } + pos =3D ((loff_t)clen + vcn) << bits; + ni->i_valid =3D pos; + goto next; } } =20 @@ -279,8 +263,9 @@ void ntfs_sparse_cluster(struct inode *inode, struct pa= ge *page0, CLST vcn, { struct address_space *mapping =3D inode->i_mapping; struct ntfs_sb_info *sbi =3D inode->i_sb->s_fs_info; - u64 vbo =3D (u64)vcn << sbi->cluster_bits; - u64 bytes =3D (u64)len << sbi->cluster_bits; + u8 cluster_bits =3D sbi->cluster_bits; + u64 vbo =3D (u64)vcn << cluster_bits; + u64 bytes =3D (u64)len << cluster_bits; u32 blocksize =3D 1 << inode->i_blkbits; pgoff_t idx0 =3D page0 ? page0->index : -1; loff_t vbo_clst =3D vbo & sbi->cluster_mask_inv; @@ -329,11 +314,10 @@ void ntfs_sparse_cluster(struct inode *inode, struct = page *page0, CLST vcn, =20 zero_user_segment(page, from, to); =20 - if (!partial) { - if (!PageUptodate(page)) - SetPageUptodate(page); - set_page_dirty(page); - } + if (!partial) + SetPageUptodate(page); + flush_dcache_page(page); + set_page_dirty(page); =20 if (idx !=3D idx0) { unlock_page(page); @@ -341,7 +325,6 @@ void ntfs_sparse_cluster(struct inode *inode, struct pa= ge *page0, CLST vcn, } cond_resched(); } - mark_inode_dirty(inode); } =20 /* @@ -588,11 +571,7 @@ static long ntfs_fallocate(struct file *file, int mode= , loff_t vbo, loff_t len) u32 frame_size; loff_t mask, vbo_a, end_a, tmp; =20 - err =3D filemap_write_and_wait_range(mapping, vbo, end - 1); - if (err) - goto out; - - err =3D filemap_write_and_wait_range(mapping, end, LLONG_MAX); + err =3D filemap_write_and_wait_range(mapping, vbo, LLONG_MAX); if (err) goto out; =20 @@ -693,7 +672,7 @@ static long ntfs_fallocate(struct file *file, int mode,= loff_t vbo, loff_t len) goto out; =20 if (is_supported_holes) { - CLST vcn_v =3D ni->i_valid >> sbi->cluster_bits; + CLST vcn_v =3D bytes_to_cluster(sbi, ni->i_valid); CLST vcn =3D vbo >> sbi->cluster_bits; CLST cend =3D bytes_to_cluster(sbi, end); CLST lcn, clen; diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c index e9cf00d14733..f487d36c9b78 100644 --- a/fs/ntfs3/inode.c +++ b/fs/ntfs3/inode.c @@ -645,7 +645,12 @@ static noinline int ntfs_get_block_vbo(struct inode *i= node, u64 vbo, bh->b_size =3D block_size; off =3D vbo & (PAGE_SIZE - 1); set_bh_page(bh, page, off); - ll_rw_block(REQ_OP_READ, 1, &bh); + + lock_buffer(bh); + bh->b_end_io =3D end_buffer_read_sync; + get_bh(bh); + submit_bh(REQ_OP_READ, bh); + wait_on_buffer(bh); if (!buffer_uptodate(bh)) { err =3D -EIO; --=20 2.37.0