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: =?utf-8?b?5p2O5oms6Z+s?= X-Patchwork-Id: 186722 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp664572dyi; Wed, 10 Jan 2024 01:00:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IFhH5HIGCgDnSAnJA9Aq2WmYAT6guWX3H1bJq8ybxytLtjtu9atG7HIGNNc/bUPqOLYWgtt X-Received: by 2002:a17:902:694c:b0:1d4:921c:be35 with SMTP id k12-20020a170902694c00b001d4921cbe35mr676744plt.70.1704877234383; Wed, 10 Jan 2024 01:00:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704877234; cv=pass; d=google.com; s=arc-20160816; b=OKqUQb56t9yvbrkrt3qsMuQvgvJEuYdIIAR/EomYkn9TMjLmxK/01+dIpPqEeSnUfN 54FmKLGGmp+VJFttKVnjyfSk9ybKPR+QQspOicO0ONF9wRTdFWEJ71EGqxdC1wMUImD8 9qRX3RncMdhUFO6L0T0fHrxWvWy8I22IP0ZbP3xFFvleAsISdVB8dkr1ZHsXdnUwhNAV zkVPPSLE9LC19b6INR4ehKuKjjQ2NWyEhBZuKH12eBVuRHkUvG45hBpYkklHcYW1xyel t32Ap9fgbPjgSGYzSk0La4+9i/o/83jz30h5F5SsZLGA+RaORobKAhiMxt1FQ+4V/Xs/ QCYQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :content-transfer-encoding:message-id:date:subject:cc:to:from :dkim-signature; bh=rtbclN8Jy24/ACtT2+yCilA0LOK9Ph27zza71V9+Ruc=; fh=VNAMAEaYEFQ0TTFYWcnMZkT4/7JxlyRr09/ygjVrGqI=; b=dZM2sWzeMoHhYRv1btw/tzoyu1ZND91LpJtCXEo1i9XCTSyaxiqi9RpcopVGoIIuV1 ndFAiLyrgqdiGu2PBbLx+PGBYeabdKKRZbq3ieVxPrVMTTZGHZOugxGDTzUbDn2qpiZX qgLw5rfYN3G7d5EQFFqTDgr6l8ohRQcFWd7xSEgD9kdin2U66/0AeaqJHO6Kg6yhwXVk BodtyQfJejBg/Pvd6SH64Ro04c7j0fNMcwoCDg2yb17mc0SQUDcizzDi7ERtkgaueN/5 Vs0I9wtv47K3+Nd3wMmj/BYrqbvsarScRs5A6KyhcKudnr8iIOceD0f1vTvuS+u/8rRM JGzw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=TUsp0rqa; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.com); spf=pass (google.com: domain of linux-kernel+bounces-21870-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21870-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id bj9-20020a170902850900b001cfc01dc055si3292098plb.57.2024.01.10.01.00.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 01:00:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-21870-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=TUsp0rqa; arc=pass (i=1 spf=pass spfdomain=vivo.com dkim=pass dkdomain=vivo.com dmarc=pass fromdomain=vivo.com); spf=pass (google.com: domain of linux-kernel+bounces-21870-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21870-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id A115F2856B1 for ; Wed, 10 Jan 2024 09:00:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C04183C47E; Wed, 10 Jan 2024 08:59:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=vivo.com header.i=@vivo.com header.b="TUsp0rqa" Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2090.outbound.protection.outlook.com [40.107.117.90]) (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 5A93D3987D for ; Wed, 10 Jan 2024 08:59:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=vivo.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=vivo.com 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 From: Yangtao Li To: Jaegeuk Kim , Chao Yu Cc: Yangtao Li , linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [PATCH] f2fs: compress: reserve blocks on released compress inode while writing 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) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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: ExB0O7UiGYOexeUc1UP3VVxJDC9FfAIgrtEfdcmfdwBtTT5suAH6vwwOB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duk/iiv/Yd9XK4bQRGxFGnUfOa9doiTQEKp7laI4twP+SMBBwJMaeKC1CdnosF6R5hEhHjy+q9vf34RFZqhK4MVm6npUa6DsmGyRy4USjE3JOyctybVcyTyW2pryR2D6oF2nkBTjYBM0+lB6MhwLdZrry+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-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787693350876582073 X-GMAIL-MSGID: 1787693350876582073 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)