From patchwork Wed Jan 10 09:10:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangtao Li X-Patchwork-Id: 13515839 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 300B8C3DA6E for ; Wed, 10 Jan 2024 09:14:27 +0000 (UTC) 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.95) (envelope-from ) id 1rNUfI-0005G8-8o; Wed, 10 Jan 2024 09:14:24 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rNUfG-0005Fv-Tk for linux-f2fs-devel@lists.sourceforge.net; Wed, 10 Jan 2024 09:14:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=MIME-Version:Content-Type:Content-Transfer-Encoding :Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=rtbclN8Jy24/ACtT2+yCilA0LOK9Ph27zza71V9+Ruc=; b=gH40BUwdGxuNvt6/3tjGery7AD qcd6dfzFkzs16qncD/7PjYAjIFR9wPAfvt6Zzv1VJ2qQE5O2Zux545SqoGazOp5LfKScZU7fVlimB 874V2sJivfdkRQSER4pOptQU7pZuWx5NMHDkplhDs2yXoa0swJSiBVGq3j/PuGW1Ilko=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:Content-ID:Content-Description:Resent-Date :Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=rtbclN8Jy24/ACtT2+yCilA0LOK9Ph27zza71V9+Ruc=; b=Y QTUimJ/dQHKuA/Jf9wA15v+AcnlPi+pAbZbjSduUCK6Kpcn0YX7E5dXJMXbFJBfRtcow+5e+ClrW7 k1EY1VOKEDDBqvEjz8iDgHMRL8+oZrrLKK3uqrHFJmCemsm5cU5kFwix2x6eHKqEppkYdvsiOCi+m rXf04nRx5Q7NVrrg=; Received: from mail-tyzapc01on2120.outbound.protection.outlook.com ([40.107.117.120] helo=APC01-TYZ-obe.outbound.protection.outlook.com) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1rNUfF-0008It-7a for linux-f2fs-devel@lists.sourceforge.net; Wed, 10 Jan 2024 09:14:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cTW+Nmz+wb70zlX/Fh/mT5Z3P3MApywBN0z0NpQB9Xkl+07aVJW7Mia6Ck9PjNXGMCUjHcGGAdf/KQm1jkFg/pri88za2kx5MYtG6gONWTd5pw8OymW/s+GYay1WDEnNenvDEPwSjZSoCYnoG6eHlJkCDDssvVC+4ySeCdi/jQk4VIgUe1EOm9StRO/TgnWM69ZalFwO5NDrD//A9P3l1Xbd1A3pORW5fey7ULtwHntVXZDkxmQJ5eg8t+bL0HndSKmGigs6RfvPKbrLNfQ3CZ1Ou6mJ0I7Opmqh7+1oXT1OZmKqfzulMcRiFCMkPrLVlol7JwMkiTmvtnAjKtpOcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=rtbclN8Jy24/ACtT2+yCilA0LOK9Ph27zza71V9+Ruc=; b=QJodKA8/zb1fLOGJ77ViPOYWGTye6eN9lkkakt4OCsuzN5bqaNNRNcJqIAfmM9MsRh4ODZcDkESmxbHSxDBrMJd8odqWTXkLRa4ez2L9SmzUClpV6wEKlh4uBa69u3GZHjJczTkY8VeeWPpHotPTbrVka5lEwzMMVNh+r3ouwNxk8WqJGFsbsYrTIRbmDOmNuzzUa2aAokWkbaBBqJrYKPBopuGtQkFFMSiT7IZxP6KlYLRg5XIbnGMcLTtlTHS2hNleO0lEMyK0xQZANNzWbQ6zBU4r1ni5dN8g0Bgj9aIviz/4d4Tso4uwzs159gjkWzLcMjmsJoyYlK7gp9Rxdg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=rtbclN8Jy24/ACtT2+yCilA0LOK9Ph27zza71V9+Ruc=; b=TUsp0rqacNh+zEm1J/BC2/gYwLQZv9k8c2O/EUcO17bbE3NpAe9MAq+Jt6UQWWSvmI3eouugZPHlxpDBeHBAVSHR/ibhrnssRy9PmXggmtApcit11ONu78qEOu3jFqeXb82J0n8HQBQViPsRGVhOB2HStfRBQ45JxqNRxsGHYucQsQOfTSH59nEKhhXVRKIvnWta9v9rRvbpTT0dHn8E/skzo3rFuuzfsjd7NwxEyTwxdYZGxyeNQyjalYo3VSdr3xpZWBIVBK0cI/IZDFixCb6Qo9yLjfYkcw8rc+eV1+89SLxubuCqfEgTc4ONrBJDFJJabJto9VJww+HaHye5Rg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from SEZPR06MB5269.apcprd06.prod.outlook.com (2603:1096:101:78::6) by JH0PR06MB7082.apcprd06.prod.outlook.com (2603:1096:990:68::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7159.23; Wed, 10 Jan 2024 08:59:44 +0000 Received: from SEZPR06MB5269.apcprd06.prod.outlook.com ([fe80::6e05:7a08:4656:761f]) by SEZPR06MB5269.apcprd06.prod.outlook.com ([fe80::6e05:7a08:4656:761f%4]) with mapi id 15.20.7159.020; Wed, 10 Jan 2024 08:59:44 +0000 To: Jaegeuk Kim , Chao Yu Date: Wed, 10 Jan 2024 02:10:08 -0700 Message-Id: <20240110091009.138206-1-frank.li@vivo.com> X-Mailer: git-send-email 2.25.1 X-ClientProxiedBy: SGXP274CA0014.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:b8::26) To SEZPR06MB5269.apcprd06.prod.outlook.com (2603:1096:101:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEZPR06MB5269:EE_|JH0PR06MB7082:EE_ X-MS-Office365-Filtering-Correlation-Id: ff5213ad-b0de-4aa6-2798-08dc11ba7d11 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Znhj9+JQOgwLzmuiaggT6lxyrCF/kIwhGAy2MMA/p6B7ilcf2oCe4pEbGoPrW/6QhoNqVMMrS+y0QARmrBAbVmjKxa+DdbL+L1snHv1ThMgkPKwxie5jwVOkrrTmqbQk713NTog0Y3HfBgXhAv7cnZWUJ5qh5jKR+5j3/y993usdNX4qlxNHKp6DAr+P7adCQfNr+2lB09CKR1acaYS5A6yJ99e74KaB7gGV4V68inQswj/NJ+edxO0ZTWrOw+QThQ0daHmU4tCQVzhQggviUj66vIcIgqLfIQkApwazHv+FW5m53RDmv6TeuLrFDNSU6jxmGy4o9cJxh9oqfoRTs6LF8WYk2hShZqpgfIscotkU89e0NXr13OVPxdQmvRfv1gBLTbAGrCqb5vRp21Dtcv+xilRoxU+mixBwDSt6rJIUcah2SyRqINTwaQh3E78jUSb71AsRmm8Q0g5TktjOgAhp3KtweEwNmlEJHmnwF0OW1cOXZ0FJ1E5H5pG37Dkb8ZWZG8F9Ek+J+qFrZSS7J4zk6YuJqhfs7Mqen2k4b23ZMWShP8Al8BygnJXklSdvt5sL8huUjl+6ygBOp9wUGH8lL8+P4625kEZ5+6Ma0OGyYSQ357Vfcb0e4KBIADrZ X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SEZPR06MB5269.apcprd06.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(366004)(39860400002)(136003)(346002)(396003)(376002)(230922051799003)(451199024)(186009)(1800799012)(64100799003)(478600001)(66556008)(83380400001)(66476007)(66946007)(52116002)(6506007)(6512007)(6666004)(41300700001)(36756003)(6486002)(26005)(1076003)(110136005)(316002)(2616005)(38100700002)(4326008)(8936002)(8676002)(5660300002)(86362001)(38350700005)(2906002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ExB0O7UiGYOexeUc1UP3VVxJDC9FfAIgrtEfdcmfdwBtTT5suAH6vwwOB110Tvt97l9syXiLtgWkJ5r+kefFGnm/dXvzq37XNJB0XUNpc0LRfAtx5to+CjgqxyOa8s55BPeqQVQrHMzoIUxX5V9uN3+Z/uzspeJjtPhfOzb0T6GlTasWZLlGQAo0C9uofd69KMpHkV/4sIPvwpYNY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p8O4xykTKr3QrqeSLZPg9ARyM9ZOQhK9XDue+5+gAdweJyHYpJ4o9eo8yrsjHzCabTTzniC1drIsvmW4RDsD0XhK0hHylgtlVhP8ObytdUy0WjEwrWsRe+rZ3ue9DA8NN5IwCPbU9mkUFNgxrNXcK6gSyT5fu1+dJA7/jK06e8Wuvyb4uEUnmk5oK7DoMta5LLoT7XTor8nhAqOYYL0E4An7p+R0viWOYhbDJ4J0vEsCYCXhr6+NmDoAz4ELN4NAFDTxvIABbfscfsA7JXfkSSW9px3scdGsXHtL0kFETgZuzZSoWMi7ACXlr X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: ff5213ad-b0de-4aa6-2798-08dc11ba7d11 X-MS-Exchange-CrossTenant-AuthSource: SEZPR06MB5269.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jan 2024 08:59:44.2226 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 7Uk4b9zyKh/l+PbkWONBMJgkLd6WwzchsO50g21Y79LrhMz+BZC2/NpqTq7sdxCAg7frls/zYSp/6SeJVuag7w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: JH0PR06MB7082 X-Headers-End: 1rNUfF-0008It-7a Subject: [f2fs-dev] [PATCH] f2fs: compress: reserve blocks on released compress inode while writing 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: , X-Patchwork-Original-From: Yangtao Li via Linux-f2fs-devel From: Yangtao Li Reply-To: Yangtao Li Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Yangtao Li Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net 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) { - 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); + if (err < 0) + return err; + } count = generic_write_checks(iocb, from); if (count <= 0)