Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp608922lqb; Wed, 17 Apr 2024 06:16:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVEMvSiioiK3nKwsp6ppjH5OyvGBwDbbt7wbH8o8dLQuekZB8NYxPlG0wMZ20ocA8B4IIm4yRvNF4i8GJ0dSQqVmuDS+8rBE+3HfjRVHg== X-Google-Smtp-Source: AGHT+IHuLEYejWDnXmozwOm1sktk/2PuuTKzx3R+oECL+CuMj/tRbELod2UDkwPpEK9PbFvQapl3 X-Received: by 2002:a17:906:489a:b0:a52:6cb1:7fa7 with SMTP id v26-20020a170906489a00b00a526cb17fa7mr4120199ejq.52.1713359811933; Wed, 17 Apr 2024 06:16:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713359811; cv=pass; d=google.com; s=arc-20160816; b=0bSGKt4Bsy2X8Ctp6lsteHieNUg7LStzITpUQSf4+TTBBJRonPVDtpcOJNf016+vh4 F3elKreLp31vS9CJ3h3kfUPPgTP0X1lEJSp96HcwFnlrpZiWxyRxKRTyVoIrMOy+rTiY 4zrBlS0qER/0CWScMdugz7KdXX6eWKNG9kYWJfMEEn+8Hxe/z//igX0ZozdkfovDe9EH Cca7rWd8F6sNWuTTMY9g+bE1hotgczqUi8clM1E2fKqDO6ZO3xpnD+8g3p7zQC0AAUGm QFl6cnrL6Y72Kb998i7yeLG7D7EmtVLZqU1CoFLKip4A00blxizfeW6mkT3dFsmU7GP1 joow== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:content-language:references :to:from:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=faaEBEoPf/qjweIscSis0xJmfoKEHMCDLYFkHEvEXk4=; fh=zpYi+jzbV23oc4qopJmiA3iay75E2bBh64Re5HvBJvQ=; b=zFUl5G72Usqu1vAkoTMzgUBMoDiBVKi/5x+vc+m3foGNtNwNuNfRpftkUyEqFzBlkZ EAkDfugPLYHoKB71c3sJ38HRzng0zazL+uSHAXyx9gbM/OT4lLR2KkFUU6P50JuUp3ND wbKpdNx0D+NKlIJZTpeHcA0rpsx4fsn1ygRf1pEyTbAd3VApcJBXfDUI5tgva+P/dDR/ An72MIlAu28DfEjfEcqFJC1pBRqGU4uxDR43k4iFFjkDnlGmngqP/vWhK0lrwtT4v6cS 4i0UYQTuIJwWty9qiaMGBtNl2imhZSpzD4v0R42c1y3Ga6KmLgCrj7WEFlseRZ2AfRkn MHyg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=ZSxgI9cI; arc=pass (i=1 spf=pass spfdomain=paragon-software.com dkim=pass dkdomain=paragon-software.com dmarc=pass fromdomain=paragon-software.com); spf=pass (google.com: domain of linux-kernel+bounces-148515-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-148515-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id x25-20020a170906711900b00a5222c66fa3si6443145ejj.241.2024.04.17.06.16.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 06:16:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-148515-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=ZSxgI9cI; arc=pass (i=1 spf=pass spfdomain=paragon-software.com dkim=pass dkdomain=paragon-software.com dmarc=pass fromdomain=paragon-software.com); spf=pass (google.com: domain of linux-kernel+bounces-148515-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-148515-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 92EF51F21D2E for ; Wed, 17 Apr 2024 13:08:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 26BD113DBAA; Wed, 17 Apr 2024 13:08:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b="ZSxgI9cI" Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 26D1EEDC; Wed, 17 Apr 2024 13:08:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=35.157.23.187 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713359293; cv=none; b=nWcdrdkeBgn1XIzt86i0+WHjjzKv8KRpOylO6yA0QkxdXSxt1Gj9+jnHmSPkdBB0l9hJOfSA6UJ+9IMFJFn9vC5vsg3KQyG4ae1G1zqAYfinr6Q/rwam9JGncBn6CHpGxFX/GV9tcwnQf/pHijWnNFC1vKLslsqqyUd3Q3yK/14= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713359293; c=relaxed/simple; bh=zB4pDB+1MwPVDU5eslMh2SAruBxdLfRVPm21RrqBJOk=; h=Message-ID:Date:MIME-Version:Subject:From:To:References: In-Reply-To:Content-Type; b=VOi9wwHYYbTm+bby6glEE//tOM60y0NHXsggJpbMMKeyCDmksXTvmxgLMAGPsF2Q6PM5IQvLuug23U36BweciRSqGUeUr0vr6hxLsgZPIyDLD8RydIaz+vllX9wKrvSfJRRObAsdnwxmxHArmMgIvceljT3zoR9BVXo6nt6csGc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=paragon-software.com; spf=pass smtp.mailfrom=paragon-software.com; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b=ZSxgI9cI; arc=none smtp.client-ip=35.157.23.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=paragon-software.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=paragon-software.com Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 5F0522126; Wed, 17 Apr 2024 13:00:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1713358839; bh=faaEBEoPf/qjweIscSis0xJmfoKEHMCDLYFkHEvEXk4=; h=Date:Subject:From:To:References:In-Reply-To; b=ZSxgI9cIaMLzufguDdMhDaTI3J8+HnDoz4+5IjcR3oUp9M5HhLKFny1SPVrrgY70A oSVN3Y35fsiaKKwq0I5inOGCPBuwWF8M5dpypn05UDn0Kyz006FzeeaV9ONqdU2jdp AMEJOf/gkEJEBdF+DsuvEGpGetrLxfKsuXZj8gm8= Received: from [192.168.211.39] (192.168.211.39) 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; Wed, 17 Apr 2024 16:08:08 +0300 Message-ID: Date: Wed, 17 Apr 2024 16:08:07 +0300 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 08/11] fs/ntfs3: Always make file nonresident if fallocate (xfstest 438) From: Konstantin Komarov To: , LKML , Linux-fsdevel References: <6c99c1bd-448d-4301-8404-50df34e8df8e@paragon-software.com> Content-Language: en-US In-Reply-To: <6c99c1bd-448d-4301-8404-50df34e8df8e@paragon-software.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: vdlg-exch-02.paragon-software.com (172.30.1.105) To vdlg-exch-02.paragon-software.com (172.30.1.105) Signed-off-by: Konstantin Komarov ---  fs/ntfs3/attrib.c  | 32 ++++++++++++++++++++++++++++++++  fs/ntfs3/file.c    |  9 +++++++++  fs/ntfs3/ntfs_fs.h |  1 +  3 files changed, 42 insertions(+) diff --git a/fs/ntfs3/attrib.c b/fs/ntfs3/attrib.c index 7aadf5010999..aedae36b91d0 100644 --- a/fs/ntfs3/attrib.c +++ b/fs/ntfs3/attrib.c @@ -2558,3 +2558,35 @@ int attr_insert_range(struct ntfs_inode *ni, u64 vbo, u64 bytes)      goto out;  } + +/* + * attr_force_nonresident + * + * Convert default data attribute into non resident form. + */ +int attr_force_nonresident(struct ntfs_inode *ni) +{ +    int err; +    struct ATTRIB *attr; +    struct ATTR_LIST_ENTRY *le = NULL; +    struct mft_inode *mi; + +    attr = ni_find_attr(ni, NULL, &le, ATTR_DATA, NULL, 0, NULL, &mi); +    if (!attr) { +        ntfs_bad_inode(&ni->vfs_inode, "no data attribute"); +        return -ENOENT; +    } + +    if (attr->non_res) { +        /* Already non resident. */ +        return 0; +    } + +    down_write(&ni->file.run_lock); +    err = attr_make_nonresident(ni, attr, le, mi, +                    le32_to_cpu(attr->res.data_size), +                    &ni->file.run, &attr, NULL); +    up_write(&ni->file.run_lock); + +    return err; +} \ No newline at end of file diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c index 5418662c80d8..fce8ea098d60 100644 --- a/fs/ntfs3/file.c +++ b/fs/ntfs3/file.c @@ -578,6 +578,15 @@ static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)          /* Check new size. */          u8 cluster_bits = sbi->cluster_bits; +        /* Be sure file is non resident. */ +        if (is_resident(ni)) { +            ni_lock(ni); +            err = attr_force_nonresident(ni); +            ni_unlock(ni); +            if (err) +                goto out; +        } +          /* generic/213: expected -ENOSPC instead of -EFBIG. */          if (!is_supported_holes) {              loff_t to_alloc = new_size - inode_get_bytes(inode); diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h index 3db6a61f61dc..00dec0ec5648 100644 --- a/fs/ntfs3/ntfs_fs.h +++ b/fs/ntfs3/ntfs_fs.h @@ -452,6 +452,7 @@ int attr_allocate_frame(struct ntfs_inode *ni, CLST frame, size_t compr_size,  int attr_collapse_range(struct ntfs_inode *ni, u64 vbo, u64 bytes);  int attr_insert_range(struct ntfs_inode *ni, u64 vbo, u64 bytes);  int attr_punch_hole(struct ntfs_inode *ni, u64 vbo, u64 bytes, u32 *frame_size); +int attr_force_nonresident(struct ntfs_inode *ni);  /* Functions from attrlist.c */  void al_destroy(struct ntfs_inode *ni); -- 2.34.1