From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 7FD403A450F for ; Mon, 3 Aug 2026 07:24:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785741879; cv=none; b=azYKvKlC8U8dFohYWnW1YE18uV6Tc9alEx/MNcOPJrt3a48cWk+WxK6MuDtRcrLlOgQHT403Y36nJrnWAGuK5XpUrutjHsjw3vdUev9W8OQB51trMzRx6A7uwildNUN1NkxOGBqFotGhokoL74g9B9+m/vx+xcJKYhucLKWwrYs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785741879; c=relaxed/simple; bh=24193pErrbJPN5FkAjHp2rdxm1E/XIbMbv+HnXc32NU=; h=Message-ID:Date:MIME-Version:Cc:Subject:To:References:From: In-Reply-To:Content-Type; b=obokBFxqS5qbBnIfjWdFAShCIo4ze+KFQtCvq2mujtHPAFfXlxNte+fkDjyeAjOEuSNd1Sw0qH1e3pYua30QDRJCHunpG18f+g4D35GKZKBZKepeERYAUggoUli4BjZcwHy25351ttWMZiJUXrtbshNeneBR+tRnq4yDS2G/5Pk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=goaP1/PQ; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="goaP1/PQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C48D1F000E9; Mon, 3 Aug 2026 07:24:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785741878; bh=HIWeIPBHtqygcH9dc8Dyn7uwP/WCc0x8+3zAwDyNAdU=; h=Date:Cc:Subject:To:References:From:In-Reply-To; b=goaP1/PQKF5SvFooAI/SymyLO3nAqRGQBR8U+ZuCVFFb0jXewtZegif84QKcCYc5G CrOcLw6ZCcG/Z8tg2KUvYgjXvpOIjiPaYmLwwXxUhDeZ+fGfsKvGI88mkksniepsw5 WNphIWQ+QLYQ/AeN7cfOuEMXJzus5nrizuFG6kgGM4mzvW/2rLmrmWwcnSVgOB4fty u9Jo4E5q00zPaTrQ1/5BPP/h6UFYOlEVWGXT5vb+skbSBy8q0l32CXuyLWNS57FgBJ hNOhesn4BfM6DHUILVFuzs6JGHosuOpRz6k3rM785onuOSV2Kfbd+sExTTzqgP0g0S 1sUQfCOHPNT9w== Message-ID: Date: Mon, 3 Aug 2026 15:24:34 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: chao@kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, qiwenjie@xiaomi.com, stable@kernel.org Subject: Re: [PATCH] f2fs: keep pinned fallocate failures section-aligned To: Wenjie Qi , jaegeuk@kernel.org References: <20260723133617.3841286-1-qiwenjie@xiaomi.com> Content-Language: en-US From: Chao Yu In-Reply-To: <20260723133617.3841286-1-qiwenjie@xiaomi.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 7/23/26 21:36, Wenjie Qi wrote: > Pinned fallocate allocates one section at a time. If f2fs_map_blocks() > fails after allocating part of the current section, the error path still > adds the partial length to expanded and clears FADVISE_TRUNC_BIT. A failed > fallocate can then leave a pinned file with a non-section-aligned size. Do you have a reproducer? maybe inject memory allocation failure? Thanks, > > Count only complete sections on failure and keep FADVISE_TRUNC_BIT set > until the failed section preallocation has been removed. > > Fixes: f5a53edcf01e ("f2fs: support aligned pinned file") > Cc: stable@kernel.org > Signed-off-by: Wenjie Qi > --- > fs/f2fs/file.c | 17 ++++++++++++++--- > 1 file changed, 14 insertions(+), 3 deletions(-) > > diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c > index c54897a25981..83af73f3831e 100644 > --- a/fs/f2fs/file.c > +++ b/fs/f2fs/file.c > @@ -1966,11 +1966,12 @@ static int f2fs_expand_inode_data(struct inode *inode, loff_t offset, > > map.m_seg_type = CURSEG_COLD_DATA_PINNED; > err = f2fs_map_blocks(inode, &map, F2FS_GET_BLOCK_PRE_DIO); > - file_dont_truncate(inode); > + if (!err) > + file_dont_truncate(inode); > > f2fs_up_write(&sbi->pin_sem); > > - expanded += map.m_len; > + expanded += err ? rounddown(map.m_len, sec_blks) : map.m_len; > sec_len -= map.m_len; > map.m_lblk += map.m_len; > if (!err && sec_len) > @@ -1986,7 +1987,7 @@ static int f2fs_expand_inode_data(struct inode *inode, loff_t offset, > pgoff_t last_off; > > if (!expanded) > - return err; > + goto out; > > last_off = pg_start + expanded - 1; > > @@ -2004,6 +2005,16 @@ static int f2fs_expand_inode_data(struct inode *inode, loff_t offset, > f2fs_i_size_write(inode, new_size); > } > > +out: > + if (err && f2fs_is_pinned_file(inode) && file_should_truncate(inode)) { > + f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); > + filemap_invalidate_lock(inode->i_mapping); > + if (!f2fs_truncate(inode)) > + file_dont_truncate(inode); > + filemap_invalidate_unlock(inode->i_mapping); > + f2fs_up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); > + } > + > return err; > } >