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 Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CE100C47077 for ; Tue, 16 Jan 2024 18:29:45 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1rPoBz-00012I-L4; Tue, 16 Jan 2024 18:29:44 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rPoBv-00012A-3h for linux-f2fs-devel@lists.sourceforge.net; Tue, 16 Jan 2024 18:29:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=In-Reply-To:Content-Type:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=EyR0Y5pjk6Zki8RIwoLsgOJ9UDCyGm/8Wlqc/qGirjk=; b=CXjYNcWCvLZyrOmPUAfwtaUPc+ O1hF2AFa1dJ4Wvh/fsZu+J5/kIQs9k0f7ttINmkOHPAQVv08BaswK5jFGcKI3gyN94mxMDeVyqh/e SXyt2kki2cVti7VtDYsydFClnWWl1zuUyiE0IiGuz4m/vU5/8268K/d+N9PqJJSptOX8=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To :From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=EyR0Y5pjk6Zki8RIwoLsgOJ9UDCyGm/8Wlqc/qGirjk=; b=Ej93gyK010hkn/sUx4U61jDc81 R0zctldreRfEtHOGwT8Nocr+bsSQYryJeQ28tDxzyMh03x2b9EMWeUgqRrM6OSLkGjy7l2Alxr0Mo 3T2DzVviMPxiGf7DpGOmf+uGwgKjY4Ppve/BUcULMl8OdbOEzXLQMwhXC34ird4g6Y2Y=; Received: from dfw.source.kernel.org ([139.178.84.217]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1rPoBs-0007He-BY for linux-f2fs-devel@lists.sourceforge.net; Tue, 16 Jan 2024 18:29:38 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id C501D61324 for ; Tue, 16 Jan 2024 18:29:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7BA09C433C7; Tue, 16 Jan 2024 18:29:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705429765; bh=k0lm4Z5pZVIlvdj47Fd18SEn4w3dqXV3sFaKUhK4hEM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=qB6XfClOzBAfEBHRluVhODZXPZDeUZgArWeFPXFNr02Zdq1FLIGhIlKeH8VSrcb+Z s2CL8dfZW7zawGzP50trc+Nmo6XhMEc3ObvL8cH4OU6aROKEvrxyMyyqMykh7z4fe7 E/bgUXnEzautBuJ0TiaOCIz0DC7KdsFwm+2iCzt7mfuoKPtrODERpDjWqWnlLE286C 4y7fnad67uxrR47FOJsAHoVr85/4JS3U4o5alWlILPbEM/CfQm0QLMSHOnZHLG0dOu p0bf293g9y6vXpMOgp7e4zpjF8UerC3kEIKw9V81tuC0qkxDVwOZXtWQlJRWhdrQL8 eGlR0EiNS4dzg== Date: Tue, 16 Jan 2024 10:29:23 -0800 From: Jaegeuk Kim To: Chao Yu Message-ID: References: <20240111064406.2970205-1-chao@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240111064406.2970205-1-chao@kernel.org> X-Headers-End: 1rPoBs-0007He-BY Subject: Re: [f2fs-dev] [PATCH] f2fs: compress: fix to cover f2fs_disable_compressed_file() w/ i_sem X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net On 01/11, Chao Yu wrote: > - f2fs_disable_compressed_file > - check inode_has_data > - f2fs_file_mmap > - mkwrite > - f2fs_get_block_locked > : update metadata in compressed > inode's disk layout > - fi->i_flags &= ~F2FS_COMPR_FL > - clear_inode_flag(inode, FI_COMPRESSED_FILE); > > we should use i_sem lock to prevent above race case. > > Meanwhile, this patch adds i_size check to restrict compress inode > conversion condition. Sorry, what was the reason to check i_size? > > Fixes: 4c8ff7095bef ("f2fs: support data compression") > Signed-off-by: Chao Yu > --- > fs/f2fs/f2fs.h | 18 ++++++++++++++++-- > fs/f2fs/file.c | 5 ++--- > 2 files changed, 18 insertions(+), 5 deletions(-) > > diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h > index 74729db0b381..e2e0ca45f881 100644 > --- a/fs/f2fs/f2fs.h > +++ b/fs/f2fs/f2fs.h > @@ -4406,19 +4406,33 @@ static inline int set_compress_context(struct inode *inode) > #endif > } > > +static inline bool inode_has_data(struct inode *inode) > +{ > + return (S_ISREG(inode->i_mode) && > + (F2FS_HAS_BLOCKS(inode) || i_size_read(inode))); > +} > + > static inline bool f2fs_disable_compressed_file(struct inode *inode) > { > struct f2fs_inode_info *fi = F2FS_I(inode); > > - if (!f2fs_compressed_file(inode)) > + f2fs_down_write(&F2FS_I(inode)->i_sem); > + > + if (!f2fs_compressed_file(inode)) { > + f2fs_up_write(&F2FS_I(inode)->i_sem); > return true; > - if (S_ISREG(inode->i_mode) && F2FS_HAS_BLOCKS(inode)) > + } > + if (f2fs_is_mmap_file(inode) || inode_has_data(inode)) { > + f2fs_up_write(&F2FS_I(inode)->i_sem); > return false; > + } > > fi->i_flags &= ~F2FS_COMPR_FL; > stat_dec_compr_inode(inode); > clear_inode_flag(inode, FI_COMPRESSED_FILE); > f2fs_mark_inode_dirty_sync(inode, true); > + > + f2fs_up_write(&F2FS_I(inode)->i_sem); > return true; > } > > diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c > index 0e4c871d6aed..5e5df234eb92 100644 > --- a/fs/f2fs/file.c > +++ b/fs/f2fs/file.c > @@ -1926,8 +1926,7 @@ static int f2fs_setflags_common(struct inode *inode, u32 iflags, u32 mask) > > f2fs_down_write(&F2FS_I(inode)->i_sem); > if (!f2fs_may_compress(inode) || > - (S_ISREG(inode->i_mode) && > - F2FS_HAS_BLOCKS(inode))) { > + inode_has_data(inode)) { > f2fs_up_write(&F2FS_I(inode)->i_sem); > return -EINVAL; > } > @@ -4011,7 +4010,7 @@ static int f2fs_ioc_set_compress_option(struct file *filp, unsigned long arg) > goto out; > } > > - if (F2FS_HAS_BLOCKS(inode)) { > + if (inode_has_data(inode)) { > ret = -EFBIG; > goto out; > } > -- > 2.40.1 _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel