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 X-Spam-Level: X-Spam-Status: No, score=-8.6 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99077C3F2D1 for ; Thu, 5 Mar 2020 00:29:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 639CF21556 for ; Thu, 5 Mar 2020 00:29:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583368193; bh=Wz53iSrHoH12eaO1ZzdY27GsNfIgPY1/Udu6PPk+MbU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:List-ID:From; b=AVe1P9wArkPbBIuAt1ws8S343SVON/AxOsaB6SfRCAfgfcxgGnLir+hnxow5LIuSJ MUyvk96iH/msXDbrfjcFjaJ9+gXqO26Wrzjue1if+bzcN8doxaF/tiHEhlZSj4Jwi3 e/4U09IC79jLQwB/yS0QRgofIfeJhETMXz73l6Dk= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388629AbgCEA3w (ORCPT ); Wed, 4 Mar 2020 19:29:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:51492 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388509AbgCEA3v (ORCPT ); Wed, 4 Mar 2020 19:29:51 -0500 Received: from localhost (unknown [104.132.1.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3983220870; Thu, 5 Mar 2020 00:29:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583368191; bh=Wz53iSrHoH12eaO1ZzdY27GsNfIgPY1/Udu6PPk+MbU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=JURF8BgDpWX7KcSMfRxLCARa08Ys/3368WqhVu3K4ty01k+Zst5eILUwNvCHwsQtG e+9BXd4/G1WlsuXPIRf8WzeW5cOyVxnVwo+rfiKRFHZd9CxdAh6RFm0cx5zp8dw74n Zf7G7JXoqOwszsAR9BrNCaL8hvMyTInkHf5m/ftY= Date: Wed, 4 Mar 2020 16:29:50 -0800 From: Jaegeuk Kim To: Chao Yu Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, chao@kernel.org Subject: Re: [PATCH v2] f2fs: introduce F2FS_IOC_RELEASE_COMPRESS_BLOCKS Message-ID: <20200305002950.GA193721@google.com> References: <20200227112621.126505-1-yuchao0@huawei.com> <20200227183052.GA55284@google.com> <8cb4552e-e6a2-e57b-1baa-40171e53e120@huawei.com> <20200304182635.GA87370@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200304182635.GA87370@google.com> User-Agent: Mutt/1.12.2 (2019-09-21) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/04, Jaegeuk Kim wrote: > On 02/28, Chao Yu wrote: > > On 2020/2/28 2:30, Jaegeuk Kim wrote: > > > On 02/27, Chao Yu wrote: > > >> There are still reserved blocks on compressed inode, this patch > > >> introduce a new ioctl to help release reserved blocks back to > > >> filesystem, so that userspace can reuse those freed space. BTW, this patch makes i_blocks breakages. Could you please check? > > > > > > Hmm, once we release the blocks, what happens if we remove the immutable > > > bit back? > > > > Oh, if we allow to overwrite on compress file, i_blocks and real physical blocks > > usage may be inconsistent? > > > > So if we need to support above scenario, should we add another ioctl interface > > to rollback all compress inode status: > > - add reserved blocks in dnode blocks > > - increase i_compr_blocks, i_blocks, total_valid_block_count > > - remove immutable > > I think that'd be doable. > > > > > Thanks, > > > > > > > >> > > >> Signed-off-by: Chao Yu > > >> --- > > >> v2: > > >> - set inode as immutable in ioctl. > > >> fs/f2fs/f2fs.h | 6 +++ > > >> fs/f2fs/file.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++++- > > >> 2 files changed, 141 insertions(+), 1 deletion(-) > > >> > > >> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h > > >> index 23b93a116c73..4a02edc2454b 100644 > > >> --- a/fs/f2fs/f2fs.h > > >> +++ b/fs/f2fs/f2fs.h > > >> @@ -427,6 +427,8 @@ static inline bool __has_cursum_space(struct f2fs_journal *journal, > > >> #define F2FS_IOC_PRECACHE_EXTENTS _IO(F2FS_IOCTL_MAGIC, 15) > > >> #define F2FS_IOC_RESIZE_FS _IOW(F2FS_IOCTL_MAGIC, 16, __u64) > > >> #define F2FS_IOC_GET_COMPRESS_BLOCKS _IOR(F2FS_IOCTL_MAGIC, 17, __u64) > > >> +#define F2FS_IOC_RELEASE_COMPRESS_BLOCKS \ > > >> + _IOR(F2FS_IOCTL_MAGIC, 18, __u64) > > >> > > >> #define F2FS_IOC_GET_VOLUME_NAME FS_IOC_GETFSLABEL > > >> #define F2FS_IOC_SET_VOLUME_NAME FS_IOC_SETFSLABEL > > >> @@ -3956,6 +3958,10 @@ static inline void f2fs_i_compr_blocks_update(struct inode *inode, > > >> { > > >> int diff = F2FS_I(inode)->i_cluster_size - blocks; > > >> > > >> + /* don't update i_compr_blocks if saved blocks were released */ > > >> + if (!add && !F2FS_I(inode)->i_compr_blocks) > > >> + return; > > >> + > > >> if (add) { > > >> F2FS_I(inode)->i_compr_blocks += diff; > > >> stat_add_compr_blocks(inode, diff); > > >> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c > > >> index 37c1147eb244..b8f01ee9d698 100644 > > >> --- a/fs/f2fs/file.c > > >> +++ b/fs/f2fs/file.c > > >> @@ -550,6 +550,7 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count) > > >> bool compressed_cluster = false; > > >> int cluster_index = 0, valid_blocks = 0; > > >> int cluster_size = F2FS_I(dn->inode)->i_cluster_size; > > >> + bool released = !F2FS_I(dn->inode)->i_compr_blocks; > > >> > > >> if (IS_INODE(dn->node_page) && f2fs_has_extra_attr(dn->inode)) > > >> base = get_extra_isize(dn->inode); > > >> @@ -588,7 +589,9 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count) > > >> clear_inode_flag(dn->inode, FI_FIRST_BLOCK_WRITTEN); > > >> > > >> f2fs_invalidate_blocks(sbi, blkaddr); > > >> - nr_free++; > > >> + > > >> + if (released && blkaddr != COMPRESS_ADDR) > > >> + nr_free++; > > >> } > > >> > > >> if (compressed_cluster) > > >> @@ -3403,6 +3406,134 @@ static int f2fs_get_compress_blocks(struct file *filp, unsigned long arg) > > >> return put_user(blocks, (u64 __user *)arg); > > >> } > > >> > > >> +static int release_compress_blocks(struct dnode_of_data *dn, pgoff_t count) > > >> +{ > > >> + struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode); > > >> + unsigned int released_blocks = 0; > > >> + int cluster_size = F2FS_I(dn->inode)->i_cluster_size; > > >> + > > >> + while (count) { > > >> + int compr_blocks = 0; > > >> + block_t blkaddr = f2fs_data_blkaddr(dn); > > >> + int i; > > >> + > > >> + if (blkaddr != COMPRESS_ADDR) { > > >> + dn->ofs_in_node += cluster_size; > > >> + goto next; > > >> + } > > >> + > > >> + for (i = 0; i < cluster_size; i++, dn->ofs_in_node++) { > > >> + blkaddr = f2fs_data_blkaddr(dn); > > >> + > > >> + if (__is_valid_data_blkaddr(blkaddr)) { > > >> + compr_blocks++; > > >> + if (unlikely(!f2fs_is_valid_blkaddr(sbi, blkaddr, > > >> + DATA_GENERIC_ENHANCE))) > > >> + return -EFSCORRUPTED; > > >> + } > > >> + > > >> + if (blkaddr != NEW_ADDR) > > >> + continue; > > >> + > > >> + dn->data_blkaddr = NULL_ADDR; > > >> + f2fs_set_data_blkaddr(dn); > > >> + } > > >> + > > >> + f2fs_i_compr_blocks_update(dn->inode, compr_blocks, false); > > >> + dec_valid_block_count(sbi, dn->inode, > > >> + cluster_size - compr_blocks); > > >> + > > >> + released_blocks += cluster_size - compr_blocks; > > >> +next: > > >> + count -= cluster_size; > > >> + } > > >> + > > >> + return released_blocks; > > >> +} > > >> + > > >> +static int f2fs_release_compress_blocks(struct file *filp, unsigned long arg) > > >> +{ > > >> + struct inode *inode = file_inode(filp); > > >> + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); > > >> + pgoff_t page_idx = 0, last_idx; > > >> + unsigned int released_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 (!F2FS_I(inode)->i_compr_blocks) > > >> + goto out; > > >> + > > >> + f2fs_balance_fs(F2FS_I_SB(inode), true); > > >> + > > >> + inode_lock(inode); > > >> + > > >> + if (!IS_IMMUTABLE(inode)) { > > >> + F2FS_I(inode)->i_flags |= F2FS_IMMUTABLE_FL; > > >> + f2fs_set_inode_flags(inode); > > >> + inode->i_ctime = current_time(inode); > > >> + f2fs_mark_inode_dirty_sync(inode, true); > > >> + } > > >> + > > >> + down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); > > >> + down_write(&F2FS_I(inode)->i_mmap_sem); > > >> + > > >> + last_idx = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE); > > >> + > > >> + while (page_idx < last_idx) { > > >> + struct dnode_of_data dn; > > >> + pgoff_t end_offset, count; > > >> + > > >> + set_new_dnode(&dn, inode, NULL, NULL, 0); > > >> + ret = f2fs_get_dnode_of_data(&dn, page_idx, LOOKUP_NODE); > > >> + if (ret) { > > >> + if (ret == -ENOENT) { > > >> + page_idx = f2fs_get_next_page_offset(&dn, > > >> + page_idx); > > >> + ret = 0; > > >> + continue; > > >> + } > > >> + break; > > >> + } > > >> + > > >> + end_offset = ADDRS_PER_PAGE(dn.node_page, inode); > > >> + count = min(end_offset - dn.ofs_in_node, last_idx - page_idx); > > >> + > > >> + ret = release_compress_blocks(&dn, count); > > >> + > > >> + f2fs_put_dnode(&dn); > > >> + > > >> + if (ret < 0) > > >> + break; > > >> + > > >> + page_idx += count; > > >> + released_blocks += ret; > > >> + } > > >> + > > >> + up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); > > >> + up_write(&F2FS_I(inode)->i_mmap_sem); > > >> + > > >> + inode_unlock(inode); > > >> +out: > > >> + mnt_drop_write_file(filp); > > >> + > > >> + if (!ret) > > >> + ret = put_user(released_blocks, (u64 __user *)arg); > > >> + > > >> + return ret; > > >> +} > > >> + > > >> long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) > > >> { > > >> if (unlikely(f2fs_cp_error(F2FS_I_SB(file_inode(filp))))) > > >> @@ -3483,6 +3614,8 @@ long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) > > >> return f2fs_set_volume_name(filp, arg); > > >> case F2FS_IOC_GET_COMPRESS_BLOCKS: > > >> return f2fs_get_compress_blocks(filp, arg); > > >> + case F2FS_IOC_RELEASE_COMPRESS_BLOCKS: > > >> + return f2fs_release_compress_blocks(filp, arg); > > >> default: > > >> return -ENOTTY; > > >> } > > >> @@ -3643,6 +3776,7 @@ long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) > > >> case F2FS_IOC_GET_VOLUME_NAME: > > >> case F2FS_IOC_SET_VOLUME_NAME: > > >> case F2FS_IOC_GET_COMPRESS_BLOCKS: > > >> + case F2FS_IOC_RELEASE_COMPRESS_BLOCKS: > > >> break; > > >> default: > > >> return -ENOIOCTLCMD; > > >> -- > > >> 2.18.0.rc1 > > > . > > > 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 X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1959BC3F2D1 for ; Thu, 5 Mar 2020 00:30:07 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id BB3D720870 for ; Thu, 5 Mar 2020 00:30:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sourceforge.net header.i=@sourceforge.net header.b="G1Oj54n2"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sf.net header.i=@sf.net header.b="QAhwpywj"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="JURF8BgD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BB3D720870 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-f2fs-devel-bounces@lists.sourceforge.net Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1j9eOs-0008Gk-1G; Thu, 05 Mar 2020 00:30:06 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1j9eOo-0008GB-88 for linux-f2fs-devel@lists.sourceforge.net; Thu, 05 Mar 2020 00:30:02 +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=IC6Crw5XIdYzBxjNDfLujONHefetO1U1XljX8FMhX7M=; b=G1Oj54n24trfnx/UXmDRExbqMz +ZthHnOK/8cVWZWWAma7fy7AdQE0WT1F1ogd/EHOyWHc6lMyp0h0X3gbLziyoBgx7g/1ALEf2DYqJ Tyz8liekruUfnaDT3tUTB3purtwqcXQqV//wtWHnGQDojoYz6pGPdW/9D2tiJVVWmYbg=; 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=IC6Crw5XIdYzBxjNDfLujONHefetO1U1XljX8FMhX7M=; b=QAhwpywjgph6TNn3PJpnvtP4DU HnYGdngyKcCH9fZ6ebZFERN7ZJxM0E37PJdwBKMBg2voD+IGInniEMsEDzDIDC8ebf1AGRaPF42Jt q0OA5wo2B1apTGsQ7bv/bbKJGXjSf0L/Cp9rq9y88HDLO2uIMwj0KP6ihrfn4RVI+r+g=; Received: from mail.kernel.org ([198.145.29.99]) by sfi-mx-4.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1j9eOl-00GoNo-AN for linux-f2fs-devel@lists.sourceforge.net; Thu, 05 Mar 2020 00:30:02 +0000 Received: from localhost (unknown [104.132.1.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3983220870; Thu, 5 Mar 2020 00:29:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583368191; bh=Wz53iSrHoH12eaO1ZzdY27GsNfIgPY1/Udu6PPk+MbU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=JURF8BgDpWX7KcSMfRxLCARa08Ys/3368WqhVu3K4ty01k+Zst5eILUwNvCHwsQtG e+9BXd4/G1WlsuXPIRf8WzeW5cOyVxnVwo+rfiKRFHZd9CxdAh6RFm0cx5zp8dw74n Zf7G7JXoqOwszsAR9BrNCaL8hvMyTInkHf5m/ftY= Date: Wed, 4 Mar 2020 16:29:50 -0800 From: Jaegeuk Kim To: Chao Yu Message-ID: <20200305002950.GA193721@google.com> References: <20200227112621.126505-1-yuchao0@huawei.com> <20200227183052.GA55284@google.com> <8cb4552e-e6a2-e57b-1baa-40171e53e120@huawei.com> <20200304182635.GA87370@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200304182635.GA87370@google.com> User-Agent: Mutt/1.12.2 (2019-09-21) X-Headers-End: 1j9eOl-00GoNo-AN Subject: Re: [f2fs-dev] [PATCH v2] f2fs: introduce F2FS_IOC_RELEASE_COMPRESS_BLOCKS 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 03/04, Jaegeuk Kim wrote: > On 02/28, Chao Yu wrote: > > On 2020/2/28 2:30, Jaegeuk Kim wrote: > > > On 02/27, Chao Yu wrote: > > >> There are still reserved blocks on compressed inode, this patch > > >> introduce a new ioctl to help release reserved blocks back to > > >> filesystem, so that userspace can reuse those freed space. BTW, this patch makes i_blocks breakages. Could you please check? > > > > > > Hmm, once we release the blocks, what happens if we remove the immutable > > > bit back? > > > > Oh, if we allow to overwrite on compress file, i_blocks and real physical blocks > > usage may be inconsistent? > > > > So if we need to support above scenario, should we add another ioctl interface > > to rollback all compress inode status: > > - add reserved blocks in dnode blocks > > - increase i_compr_blocks, i_blocks, total_valid_block_count > > - remove immutable > > I think that'd be doable. > > > > > Thanks, > > > > > > > >> > > >> Signed-off-by: Chao Yu > > >> --- > > >> v2: > > >> - set inode as immutable in ioctl. > > >> fs/f2fs/f2fs.h | 6 +++ > > >> fs/f2fs/file.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++++- > > >> 2 files changed, 141 insertions(+), 1 deletion(-) > > >> > > >> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h > > >> index 23b93a116c73..4a02edc2454b 100644 > > >> --- a/fs/f2fs/f2fs.h > > >> +++ b/fs/f2fs/f2fs.h > > >> @@ -427,6 +427,8 @@ static inline bool __has_cursum_space(struct f2fs_journal *journal, > > >> #define F2FS_IOC_PRECACHE_EXTENTS _IO(F2FS_IOCTL_MAGIC, 15) > > >> #define F2FS_IOC_RESIZE_FS _IOW(F2FS_IOCTL_MAGIC, 16, __u64) > > >> #define F2FS_IOC_GET_COMPRESS_BLOCKS _IOR(F2FS_IOCTL_MAGIC, 17, __u64) > > >> +#define F2FS_IOC_RELEASE_COMPRESS_BLOCKS \ > > >> + _IOR(F2FS_IOCTL_MAGIC, 18, __u64) > > >> > > >> #define F2FS_IOC_GET_VOLUME_NAME FS_IOC_GETFSLABEL > > >> #define F2FS_IOC_SET_VOLUME_NAME FS_IOC_SETFSLABEL > > >> @@ -3956,6 +3958,10 @@ static inline void f2fs_i_compr_blocks_update(struct inode *inode, > > >> { > > >> int diff = F2FS_I(inode)->i_cluster_size - blocks; > > >> > > >> + /* don't update i_compr_blocks if saved blocks were released */ > > >> + if (!add && !F2FS_I(inode)->i_compr_blocks) > > >> + return; > > >> + > > >> if (add) { > > >> F2FS_I(inode)->i_compr_blocks += diff; > > >> stat_add_compr_blocks(inode, diff); > > >> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c > > >> index 37c1147eb244..b8f01ee9d698 100644 > > >> --- a/fs/f2fs/file.c > > >> +++ b/fs/f2fs/file.c > > >> @@ -550,6 +550,7 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count) > > >> bool compressed_cluster = false; > > >> int cluster_index = 0, valid_blocks = 0; > > >> int cluster_size = F2FS_I(dn->inode)->i_cluster_size; > > >> + bool released = !F2FS_I(dn->inode)->i_compr_blocks; > > >> > > >> if (IS_INODE(dn->node_page) && f2fs_has_extra_attr(dn->inode)) > > >> base = get_extra_isize(dn->inode); > > >> @@ -588,7 +589,9 @@ void f2fs_truncate_data_blocks_range(struct dnode_of_data *dn, int count) > > >> clear_inode_flag(dn->inode, FI_FIRST_BLOCK_WRITTEN); > > >> > > >> f2fs_invalidate_blocks(sbi, blkaddr); > > >> - nr_free++; > > >> + > > >> + if (released && blkaddr != COMPRESS_ADDR) > > >> + nr_free++; > > >> } > > >> > > >> if (compressed_cluster) > > >> @@ -3403,6 +3406,134 @@ static int f2fs_get_compress_blocks(struct file *filp, unsigned long arg) > > >> return put_user(blocks, (u64 __user *)arg); > > >> } > > >> > > >> +static int release_compress_blocks(struct dnode_of_data *dn, pgoff_t count) > > >> +{ > > >> + struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode); > > >> + unsigned int released_blocks = 0; > > >> + int cluster_size = F2FS_I(dn->inode)->i_cluster_size; > > >> + > > >> + while (count) { > > >> + int compr_blocks = 0; > > >> + block_t blkaddr = f2fs_data_blkaddr(dn); > > >> + int i; > > >> + > > >> + if (blkaddr != COMPRESS_ADDR) { > > >> + dn->ofs_in_node += cluster_size; > > >> + goto next; > > >> + } > > >> + > > >> + for (i = 0; i < cluster_size; i++, dn->ofs_in_node++) { > > >> + blkaddr = f2fs_data_blkaddr(dn); > > >> + > > >> + if (__is_valid_data_blkaddr(blkaddr)) { > > >> + compr_blocks++; > > >> + if (unlikely(!f2fs_is_valid_blkaddr(sbi, blkaddr, > > >> + DATA_GENERIC_ENHANCE))) > > >> + return -EFSCORRUPTED; > > >> + } > > >> + > > >> + if (blkaddr != NEW_ADDR) > > >> + continue; > > >> + > > >> + dn->data_blkaddr = NULL_ADDR; > > >> + f2fs_set_data_blkaddr(dn); > > >> + } > > >> + > > >> + f2fs_i_compr_blocks_update(dn->inode, compr_blocks, false); > > >> + dec_valid_block_count(sbi, dn->inode, > > >> + cluster_size - compr_blocks); > > >> + > > >> + released_blocks += cluster_size - compr_blocks; > > >> +next: > > >> + count -= cluster_size; > > >> + } > > >> + > > >> + return released_blocks; > > >> +} > > >> + > > >> +static int f2fs_release_compress_blocks(struct file *filp, unsigned long arg) > > >> +{ > > >> + struct inode *inode = file_inode(filp); > > >> + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); > > >> + pgoff_t page_idx = 0, last_idx; > > >> + unsigned int released_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 (!F2FS_I(inode)->i_compr_blocks) > > >> + goto out; > > >> + > > >> + f2fs_balance_fs(F2FS_I_SB(inode), true); > > >> + > > >> + inode_lock(inode); > > >> + > > >> + if (!IS_IMMUTABLE(inode)) { > > >> + F2FS_I(inode)->i_flags |= F2FS_IMMUTABLE_FL; > > >> + f2fs_set_inode_flags(inode); > > >> + inode->i_ctime = current_time(inode); > > >> + f2fs_mark_inode_dirty_sync(inode, true); > > >> + } > > >> + > > >> + down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); > > >> + down_write(&F2FS_I(inode)->i_mmap_sem); > > >> + > > >> + last_idx = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE); > > >> + > > >> + while (page_idx < last_idx) { > > >> + struct dnode_of_data dn; > > >> + pgoff_t end_offset, count; > > >> + > > >> + set_new_dnode(&dn, inode, NULL, NULL, 0); > > >> + ret = f2fs_get_dnode_of_data(&dn, page_idx, LOOKUP_NODE); > > >> + if (ret) { > > >> + if (ret == -ENOENT) { > > >> + page_idx = f2fs_get_next_page_offset(&dn, > > >> + page_idx); > > >> + ret = 0; > > >> + continue; > > >> + } > > >> + break; > > >> + } > > >> + > > >> + end_offset = ADDRS_PER_PAGE(dn.node_page, inode); > > >> + count = min(end_offset - dn.ofs_in_node, last_idx - page_idx); > > >> + > > >> + ret = release_compress_blocks(&dn, count); > > >> + > > >> + f2fs_put_dnode(&dn); > > >> + > > >> + if (ret < 0) > > >> + break; > > >> + > > >> + page_idx += count; > > >> + released_blocks += ret; > > >> + } > > >> + > > >> + up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); > > >> + up_write(&F2FS_I(inode)->i_mmap_sem); > > >> + > > >> + inode_unlock(inode); > > >> +out: > > >> + mnt_drop_write_file(filp); > > >> + > > >> + if (!ret) > > >> + ret = put_user(released_blocks, (u64 __user *)arg); > > >> + > > >> + return ret; > > >> +} > > >> + > > >> long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) > > >> { > > >> if (unlikely(f2fs_cp_error(F2FS_I_SB(file_inode(filp))))) > > >> @@ -3483,6 +3614,8 @@ long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) > > >> return f2fs_set_volume_name(filp, arg); > > >> case F2FS_IOC_GET_COMPRESS_BLOCKS: > > >> return f2fs_get_compress_blocks(filp, arg); > > >> + case F2FS_IOC_RELEASE_COMPRESS_BLOCKS: > > >> + return f2fs_release_compress_blocks(filp, arg); > > >> default: > > >> return -ENOTTY; > > >> } > > >> @@ -3643,6 +3776,7 @@ long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) > > >> case F2FS_IOC_GET_VOLUME_NAME: > > >> case F2FS_IOC_SET_VOLUME_NAME: > > >> case F2FS_IOC_GET_COMPRESS_BLOCKS: > > >> + case F2FS_IOC_RELEASE_COMPRESS_BLOCKS: > > >> break; > > >> default: > > >> return -ENOIOCTLCMD; > > >> -- > > >> 2.18.0.rc1 > > > . > > > _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel