Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1054865rbb; Sun, 25 Feb 2024 17:40:31 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUf9je1yuTt7W5XYHgzOp8mdnQQOkgVF53lDyn8ZdPHSkuXmAbFi9LHbRcaUskKx5a4fp8U5dmJJ/bXS6tIh5tMAQzE4EZh0+alzwcyGg== X-Google-Smtp-Source: AGHT+IEIGehuY8fnQq5WmAUG8HECgVyBb40oYCohlqyfNN2wH2tmzLakn7f/cIlBgHvxk9cQWzKs X-Received: by 2002:a17:906:360a:b0:a3e:ce27:15a2 with SMTP id q10-20020a170906360a00b00a3ece2715a2mr5909975ejb.28.1708911631553; Sun, 25 Feb 2024 17:40:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708911631; cv=pass; d=google.com; s=arc-20160816; b=v8pB+d3GVID3jPWNxKH6a40jAIdG9V9XUSdB1L/Jxz2qRbj2GLtvhbELrpah0sh8yu rmbJu24GTNPtCuA+tDn2OzHj9BrUmPyKGFkK4L7UiAY2HmDk+m/Xb6xkucLqfBTqYkwS Evkog/EEPbNMK3pAODfSeKxc1piRW6Z1heIOAtktfra4XmtKmdnEeMy+BojQY4b11dfq KgbqR3eLDtvA1MtapcKDgInoO1JOyPEuMJT+eDwkgvX+DHapXWfM2/GQ0K2fyArNuDEY u4h4L4BUUwc/cCwSZESfDOIBa+/EGSEZqHiBOGk6W2a6a7t8RNvLn+KPptfMy+3ZFWR3 Q0yg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=zY7ouNNa2QIAEupKHSsH+1xHoaicvB+P7SO3Dy2ujgQ=; fh=JHbjnW+VXWSAqdhQMKTNBvj4K0WgcN3F0BFlcvodaVE=; b=fONAtFtfoNwJm7CkEKScSK1nXoKABE5G4DMztcGyTPcLqPd/JXfnjicMkZXMgLsmcv c5ibNtXpXaFOnPw1QYDwVQCDZG8Zq1PDtfnkoh9BITz0api1vNQbyDrFhoXoe1vESiLD JQ8NW9xkNggu2uj13D7Uxx9swcfjq86IWm4Vo6u6jNzy/YwX9/S/jD8skz4nJdjZWpg9 gSBEzdh0TjDI13rfu3BRb/1Keg2zIzTeMRGP0zyO2IJAYpKY5E/kJUNc9FFgRa6/H5yp SeJOaB7PWFZqDF6uWUuSd4KcRCxtIOuGfCc14ODtP3kZ64JTkQq3X7BNLDgLJERU5lDv kdOQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KrNjPLsG; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80385-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80385-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id lg19-20020a170906f89300b00a3e977ab053si1566116ejb.941.2024.02.25.17.40.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 17:40:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80385-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=@kernel.org header.s=k20201202 header.b=KrNjPLsG; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-80385-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80385-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 3F90E1F217FD for ; Mon, 26 Feb 2024 01:40:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DA78C15E97; Mon, 26 Feb 2024 01:40:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KrNjPLsG" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 0D51E14AB2 for ; Mon, 26 Feb 2024 01:40:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708911621; cv=none; b=Hjrk1tPwdPbYig/m17FuSLYoZYF2m91m9YIqVTpLLUuJlGXYnqJ5hisW1K2LOOQg20rBoNn58ep/Jfl9nr4mJBNehOQxq75Wy7YoWmxKnFEopb61LnDRxQDH2anzD9V0w5hGhU/i0FpTcoF70gHBeI6I/2C7jSC4XJzkKcOtc4k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708911621; c=relaxed/simple; bh=E+V1Y4RQYIY8ckr4RlbF6c3RFkZOqY1GrMDaYw72cxE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=bCFLu0VNTWZupDzlmWEgcq3q6aewHLn0WHjvMFhjjaEitQ3sW/6wWxoTqwOFxB2ZIv06p2RoTus7y2BRe2DOHZsAXn2Y7yNXRNVSp37E2K2qQ2n82iE52fHdHQrHdjH32MAXUZsZciyElk2X+6ET1L6KzEJZD6A7S4ojLIJXrNg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KrNjPLsG; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4A5D2C433F1; Mon, 26 Feb 2024 01:40:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708911620; bh=E+V1Y4RQYIY8ckr4RlbF6c3RFkZOqY1GrMDaYw72cxE=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=KrNjPLsGKW+WDzp1mlaF7lz3WHQC+OTR01ypNb7let1Gi5PcJWumQ24Yer40nXFFw U9oAnFIbKgH54Nbrd0X2KDy4bDTVdXKb5+19bei6CzSBTE0JVPSRZu0y4A7f4WK+59 iZvr/6ZVmEmQLghSf1uAZBQO6FccfOrYq74Yx0Rkmc7I6zWUJhmGBkx6BdhKr5YErr rCtA0QjYYSVZkUS4+ay4pvq4eGI7AhmYdIlbyJkoR1m3Z02O0cpRI+qDo10nFRoRKv pL+1MMeE0BZ36tP7ZvJkUtVFfFKOMIwCU0eQExuQvrYNsomJ3dJP+68WRRx2mmlbUK gpquzszhZWWiA== Message-ID: Date: Mon, 26 Feb 2024 09:40:15 +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 Subject: Re: [PATCH] f2fs: compress: reserve blocks on released compress inode while writing Content-Language: en-US To: Yangtao Li , Jaegeuk Kim Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org References: <20240110091009.138206-1-frank.li@vivo.com> From: Chao Yu In-Reply-To: <20240110091009.138206-1-frank.li@vivo.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2024/1/10 17:10, Yangtao Li wrote: > Reserve blocks on released compress inode while writing, so > compressed files with released space are allowed to be rewritten. > > Signed-off-by: Yangtao Li > --- > fs/f2fs/file.c | 86 ++++++++++++++++++++++++++++++-------------------- > 1 file changed, 51 insertions(+), 35 deletions(-) > > diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c > index 15dabeac4690..749b5af17141 100644 > --- a/fs/f2fs/file.c > +++ b/fs/f2fs/file.c > @@ -3612,39 +3612,15 @@ static int reserve_compress_blocks(struct dnode_of_data *dn, pgoff_t count) > return reserved_blocks; > } > > -static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg) > +static int f2fs_reserve_file(struct inode *inode, unsigned int *blocks) f2fs_do_reserve_compress_blocks()? > { > - struct inode *inode = file_inode(filp); > struct f2fs_sb_info *sbi = F2FS_I_SB(inode); > pgoff_t page_idx = 0, last_idx; > unsigned int reserved_blocks = 0; > int ret; > > - if (!f2fs_sb_has_compression(F2FS_I_SB(inode))) > - return -EOPNOTSUPP; > - > - if (!f2fs_compressed_file(inode)) > - return -EINVAL; > - > - if (f2fs_readonly(sbi->sb)) > - return -EROFS; > - > - ret = mnt_want_write_file(filp); > - if (ret) > - return ret; > - > - if (atomic_read(&F2FS_I(inode)->i_compr_blocks)) > - goto out; > - > f2fs_balance_fs(F2FS_I_SB(inode), true); > > - inode_lock(inode); > - > - if (!is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { > - ret = -EINVAL; > - goto unlock_inode; > - } > - > f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); > filemap_invalidate_lock(inode->i_mapping); > > @@ -3688,14 +3664,8 @@ static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg) > clear_inode_flag(inode, FI_COMPRESS_RELEASED); > inode->i_ctime = current_time(inode); > f2fs_mark_inode_dirty_sync(inode, true); > - } > -unlock_inode: > - inode_unlock(inode); > -out: > - mnt_drop_write_file(filp); > - > - if (ret >= 0) { > - ret = put_user(reserved_blocks, (u64 __user *)arg); > + if (blocks) > + *blocks = reserved_blocks; > } else if (reserved_blocks && > atomic_read(&F2FS_I(inode)->i_compr_blocks)) { > set_sbi_flag(sbi, SBI_NEED_FSCK); > @@ -3710,6 +3680,49 @@ static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg) > return ret; > } > > +static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg) > +{ > + struct inode *inode = file_inode(filp); > + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); > + unsigned int reserved_blocks = 0; > + int ret; > + > + if (!f2fs_sb_has_compression(F2FS_I_SB(inode))) > + return -EOPNOTSUPP; > + > + if (!f2fs_compressed_file(inode)) > + return -EINVAL; > + > + if (f2fs_readonly(sbi->sb)) > + return -EROFS; > + > + ret = mnt_want_write_file(filp); > + if (ret) > + return ret; > + > + if (atomic_read(&F2FS_I(inode)->i_compr_blocks)) > + goto out; > + > + inode_lock(inode); > + > + if (!is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { > + ret = -EINVAL; > + goto unlock_inode; > + } > + > + ret = f2fs_reserve_file(inode, &reserved_blocks); > + > +unlock_inode: > + inode_unlock(inode); > +out: > + mnt_drop_write_file(filp); > + > + if (ret >= 0) > + ret = put_user(reserved_blocks, (u64 __user *)arg); > + > + return ret; > +} > + > static int f2fs_secure_erase(struct block_device *bdev, struct inode *inode, > pgoff_t off, block_t block, block_t len, u32 flags) > { > @@ -4412,8 +4425,11 @@ static ssize_t f2fs_write_checks(struct kiocb *iocb, struct iov_iter *from) > if (IS_IMMUTABLE(inode)) > return -EPERM; > > - if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) > - return -EPERM; > + if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { > + err = f2fs_reserve_file(inode, NULL); How about reserving blocks after generic_write_checks() in f2fs_file_write_iter()? Thanks, > + if (err < 0) > + return err; > + } > > count = generic_write_checks(iocb, from); > if (count <= 0)