From patchwork Sat May 6 14:42:56 2023 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: 90763 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1095523vqo; Sat, 6 May 2023 07:47:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4lKdkEP3+3c89yxbFAuWfSiv0ALjHvtSll/nycMW0lpkR0KNTOv+/P0Ido5W9U5TxD19rR X-Received: by 2002:a17:903:1110:b0:1ab:74c:bdf2 with SMTP id n16-20020a170903111000b001ab074cbdf2mr6501734plh.28.1683384477338; Sat, 06 May 2023 07:47:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1683384477; cv=pass; d=google.com; s=arc-20160816; b=L3NmVctYXQN5mnmOTJx4DE2zi9ZlgUDiI+SrrKrNFCKILCy/4KFxZt8TNWRLFqw9an KmOCKE0vePWdSFyCyRMm6S/YBQpfn83/8G88AT7vDnrugWt7J2bEfdTRTCji7lT1bxd3 ONN1B8cGkIxl6hchg44Vm1/5dL8xfqJurqw9nucUVAdgz9BwgQ+FYR1kY/76Kev5WG+U XdgCoA5ziP1mL/ICKjCsAwkaNHMC7BMk56MUtiKVt836gAtJ8PmwZQFVc1YQfbnSPlbc J5KU83WwYicbR1Wy954AG6cft+lzfmjwZfaJr6A/3AHMGpPd5fps1roQWo21efcznpe4 vDlA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=JpoWxn71jA/aAQkUlkXtZGYGcn76uK454MB0svTztNU=; b=k9rQxnPGu32KySEwJqBV5RijtATvscudqWFnxHuyHwfJFcQ+2LZyWnJJrppz9cM4bi xqmKtz+ZWo3N4bSXwmWxs/1S7QX/PxLd/76yg5EA/lz+1e4FQOCsRdTaDM2AIUlJVe9C pmsLKH/Ku/LE3C0Mff/1QHQFLRSkIRxQOiP5imO9xMjvyz6gtqT//XgFRn1t4lUN3cQz aDGcOoP/9b2UuOFew8b+i8PjzZfsKBPHPrdJUT0v9eW7t9Pp33QFZrsAyzEOjlYqREqW LhaW6j8YiMVDXJfrP8LGMcmA9YkZjFLcWowGkKYT6Q3X72pKSLev/JPOqIVNdSIPeO6J SUEQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=MskJ44mH; 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-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d64-20020a633643000000b0052c8234a858si4511406pga.168.2023.05.06.07.47.20; Sat, 06 May 2023 07:47:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=MskJ44mH; 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-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231830AbjEFOnR (ORCPT + 99 others); Sat, 6 May 2023 10:43:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229472AbjEFOnQ (ORCPT ); Sat, 6 May 2023 10:43:16 -0400 Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2122.outbound.protection.outlook.com [40.107.117.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C30C61A493 for ; Sat, 6 May 2023 07:43:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nd45oRosOZfQ0ZVMhJ/Lho+6KVHNawtFg4oN/80DSXjG90eaacQv5mjtFWPnDiBAkkvtMHy39K3B7xt7NqwMp4qUKRJRVUp9cbeRdmO77l9BbWdWlNrmpj5SpoGMwfZqlc7zaqEbbu1gMShoLiM+UNENBvn5330u1Ty3Mt+rVgFpw9+xnJV2I//g/KXq/SfV6U+Wy3NJnPci37PSONesx8odLonzBn2K988EqYj9EJeT4NoxfEDHqYw9KKFv3UP7w9Jxj8Ed8HkGy4oitQrdE5SxU2XFBz7PNOA91L7Y3w9mPdfc/fRrb6sj9Z6WhO3kqqNNWUc5mrzHktF2ZgqNfA== 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=JpoWxn71jA/aAQkUlkXtZGYGcn76uK454MB0svTztNU=; b=djfNdpEnJspWkLNhKRUykf36BH0cPhoVm48h3QlEHxnk11dQODg/XRxtf6LT1BUlwj1bds/7eVv1vHnZgWEOI9ohaSRPSU0zxnOB8z1cdevNowoK0nnOERy9vTrb1R0E+Sqp14KONwa/427290zwbtE9p7jxZ7qzOeeaJ9uX+H1wJQsX2Il5w1QYLJ1XBd0n8SI9wLwzT0Nb66Wrla/r1VQnWY+NYaUC6dU0nUoQ1wtrOt82Bt7yKzEMqQfd54ktaz1iKgF4BWBFR+fRS4zvVOwWmGIwitgZCN8tm/8WkYWMsDPPI5PW7Jhi7KK1T77E+f/ttCDqAmT2K94Gm9IfEA== 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=JpoWxn71jA/aAQkUlkXtZGYGcn76uK454MB0svTztNU=; b=MskJ44mHo3yl/BVLZVa5zx7eTi5qE7FBZatb0Q0RsIzgxX1rQ1uaP7N/cikiAGhxSvYtWo+sjeXmVFM5b1rgoOTgYnaApxhOSTyZHSsYPYp2ZggbYLcLA4MgIiDfCqywgutRX3SqP1Ni8vc11UiJI1HaTN9R8h+DCjutQ11A6N7IRED/ifN+rs+IAF9G7LZyKpg94LEHx6g5Z5Ma1MMQWDDu2LmewoMxqSr4hdyNBfhFCyoa+F9dSrZpx3Lm2h0UBqkcOOr9LVuG6LMtfsUXGRj6vY4CUjPoJOTyijDSUL8XkYB8pkeCEcs7VYXmTB/RPJV1UclYxWianlljq7Q1+w== 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 PUZPR06MB5818.apcprd06.prod.outlook.com (2603:1096:301:f1::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.29; Sat, 6 May 2023 14:43:10 +0000 Received: from SEZPR06MB5269.apcprd06.prod.outlook.com ([fe80::76d6:4828:7e80:2965]) by SEZPR06MB5269.apcprd06.prod.outlook.com ([fe80::76d6:4828:7e80:2965%7]) with mapi id 15.20.6363.029; Sat, 6 May 2023 14:43:10 +0000 From: Yangtao Li To: jaegeuk@kernel.org, chao@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Yangtao Li , Christophe JAILLET Subject: [PATCH v2 1/2] f2fs: move the conditional statement after holding the inode lock in f2fs_move_file_range() Date: Sat, 6 May 2023 22:42:56 +0800 Message-Id: <20230506144257.9611-1-frank.li@vivo.com> X-Mailer: git-send-email 2.39.0 X-ClientProxiedBy: SI1PR02CA0058.apcprd02.prod.outlook.com (2603:1096:4:1f5::9) To SEZPR06MB5269.apcprd06.prod.outlook.com (2603:1096:101:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEZPR06MB5269:EE_|PUZPR06MB5818:EE_ X-MS-Office365-Filtering-Correlation-Id: 50d597bf-4da3-44d9-3a18-08db4e4035cb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: S5zvXKl/HxnbwCnVItRJjppNNtHA07BSo6RsjWrTwwfiQZybpjUGUG9811ubqbWld/l4mnH1fXqWVwtfwQYFGRdJMoOa0VJBVTGi0VBcr/r7CCmyD6JI16CftSKxdsP6UtB/vG13sRykegbdRnf2UVW96USbPB/Xk8EvCkG3Ht5Ix9ruKdfP9eI3wJVsaHGFjItlPv/c01+5fJ10zr/WZ9c5rvs3TIpsRNaK6faN0NbStze/5Gk0A0ZB476J/k5XszmlXdIewF0bIyMZBLy+KhDcDVPTN1OUK0mxe1Su41kLSYFAS/lIyUmwmGZ3qSFt7gmsWTcOrO6vYVIRc2aPfMYdP+ChnTo+6KGyk3QMLfRSu6JnvTaI36jv6MceOx0FagQtQjVzVP0pyjDOxKAeKpZCyL7V4elZxEfTgOBei/AFQD7R/+cMWWj2osHoEfY8WB2Z+cmHHsEIRViaAewEkWizToLk8/FiYePL+wL65qWhjIrGCjRoxBj0FvrCYRoQNwOdkU3+6MhGk+B4zJjhgXov4BwCkSpOMjJ5z7kkXe7Njd1kYL84brQBBQbXTdKmIYinqRFqEjs6yZU4BpT8k2rRFxsUZC4VHenTaUbrTLHMTNs6Y6aHUBSlYWVPY+X4 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:(13230028)(4636009)(39860400002)(366004)(376002)(136003)(346002)(396003)(451199021)(8936002)(41300700001)(8676002)(5660300002)(2906002)(54906003)(66476007)(66946007)(66556008)(4326008)(316002)(478600001)(6486002)(52116002)(6666004)(83380400001)(6506007)(6512007)(1076003)(26005)(36756003)(86362001)(2616005)(186003)(38100700002)(38350700002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: QyMcQyF0Y7oOS8ZLZw3G8YXHoeWvOAvrZRys5v7wigPS+tU53GHNUYK0VitgxYiat1BeQt/DZSFqSF+I565W11f8ZZG7wkdh/Ldsqv8/YDxx1vlC29tMZiBmMptnCr4p9CmPlCvdSlwbxxUyOxJQmKVtfZUUwvZZcK7l5dIYy9nk/deWcSefnJRJKk7SzgCOFZarXSTc0psmjlg7sd5PqL7iAHcT8tmo2Zfdb2iUeY5hzO1YiJrMpEqMMMboQ2Uah5OlLWCs8WOqh0VmDf0Ke/wOX9ZaLw06nkXVblWbMTbgsa/pU+w3bGV7ZU6Z/2YNi/uZK2ueKd/cRTnCYG6EzpNVa8+kq4bl9S7JNPZLM4GwNih31Lsnb1qV+/Bb5nc8rTnhoL40o9RE4ipVqtQzvh4YJRjlzIk6EoXbfpYrV0ytYMYPUDEHW6rF/mmzDNFEPFAxWMJT0swbNT4+GIMOl4RhQeZraBJPdaW6OHtApe0kbh0wyvZE6PRdxi70vODeTwkB6yWTI/lqfRHJwQjUdR/+ldUMSw6kKRqQC2z0wRF8ADP3e9dJgfcGobMZM3KoZq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035cb X-MS-Exchange-CrossTenant-AuthSource: SEZPR06MB5269.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 May 2023 14:43:09.3020 (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: jwGmdlMcSiWieaLbNUEWzhZMFK3XCniHbcFQMUXIWyeu6cOorUd8Bt+IlOqaBaMTV1jkjBCtEPwNG19HW/nR6w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PUZPR06MB5818 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765145037010083749?= X-GMAIL-MSGID: =?utf-8?q?1765156561991842928?= For judging the inode flag state, the inode lock must be held. BTW, add compressd file check and to avoid 'if' nesting. Cc: Christophe JAILLET Fixes: 4dd6f977fc77 ("f2fs: support an ioctl to move a range of data blocks") Signed-off-by: Yangtao Li --- v2: -add unlock fs/f2fs/file.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 78aa8cff4b41..42a9b683118c 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -2790,9 +2790,6 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in, if (!S_ISREG(src->i_mode) || !S_ISREG(dst->i_mode)) return -EINVAL; - if (IS_ENCRYPTED(src) || IS_ENCRYPTED(dst)) - return -EOPNOTSUPP; - if (pos_out < 0 || pos_in < 0) return -EINVAL; @@ -2804,10 +2801,19 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in, } inode_lock(src); - if (src != dst) { + if (src != dst && !inode_trylock(dst)) { ret = -EBUSY; - if (!inode_trylock(dst)) - goto out; + goto out; + } + + if (IS_ENCRYPTED(src) || IS_ENCRYPTED(dst)) { + ret = -EOPNOTSUPP; + goto out_unlock; + } + + if (f2fs_compressed_file(src) || f2fs_compressed_file(dst)) { + ret = -EOPNOTSUPP; + goto out_unlock; } ret = -EINVAL; From patchwork Sat May 6 14:42:57 2023 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: 90764 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1117762vqo; Sat, 6 May 2023 08:30:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5Qqe59J0hsvqpIQQBrsQuiEAyehV/LIghQq6xLF3mJhmMRgL1+8jhLyZB4Hqs4UKVGcQdQ X-Received: by 2002:a05:6a21:999b:b0:f8:5cc:d869 with SMTP id ve27-20020a056a21999b00b000f805ccd869mr6242282pzb.35.1683387033903; Sat, 06 May 2023 08:30:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1683387033; cv=pass; d=google.com; s=arc-20160816; b=TyZ5C5Qq3jUYRDtEudTNHndYkF6fm/tCN6DSk9cM3Agj5DSgUQKayBueSPiZIkvG06 7/w2jb6GPgtjdkrjawbiP7z6quxc9zMq4h3zVsaBNm297e/qTzJngII/1rERmy6xHsCN pXDpSVUc5CUqGjhrWxfCCl2nv7u/5cbNkvlIigc31BQ3NMxrQ6k/0cTVBg0mPoaqmpWf +jTwQDJ9vm9ciT0jx45fQLn8hjCjkqTMuCcpoyQDjSv5ZV1gMf5p8F0BA+w1QVyxxyuT cWZBO4RQqlu/sET454VKF668gArc7rJkiQMifxMCECEDXvIbGHVh5c5fywF9L+CCaivp yYhw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=RMuSe6FEFxGDvX/sqWgJC3oZ5D78m4r6nwK/M2i36wM=; b=cRbWtKkgTLrGWYrUOWal9u1HHM2WqAkfMkHiVM0DAj0dAaDtHDKkjNYnZ0X/vZoF4N ORWH/aEkXXIy88jkGiZ8hXqHjK9BZ5fERqRVnjicyKaT+UzfuPGKdP4gJqWe7WDlTMrp y6AunJo49pPlnKb4c17lrUW+lv4nTpoD96wu9vifrNsl2g7I9GHoeldz5i9/W9Jr3+Nr AlKqFbUfS2bFBwgTUUDZBxqsKsN+Ol3RHcm+SCcuoEilGtUkndTEUzFmUFK0SGqBORoT b5NKevBgpx8LNyY5SkVsZvpnrjCSYJtPszTNQbDeOwS/Xr8Gg05lkpE/IC6k0H8BKKz0 4Ipw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=g5dcgSVL; 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-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e25-20020a633719000000b004fbd2a5db20si4394760pga.538.2023.05.06.08.30.18; Sat, 06 May 2023 08:30:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@vivo.com header.s=selector2 header.b=g5dcgSVL; 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-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=vivo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232621AbjEFOnU (ORCPT + 99 others); Sat, 6 May 2023 10:43:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231933AbjEFOnR (ORCPT ); Sat, 6 May 2023 10:43:17 -0400 Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2122.outbound.protection.outlook.com [40.107.117.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FBA51AED4 for ; Sat, 6 May 2023 07:43:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DB55EITw/PhE6n6DdsChgqpNCn5sNIImfl38ZDe2Z64fBIHET8HIgrlCU6QO9sMPY3t0qPvdRfrgqGiNMAbLl18Yf82yA1aWLv+drZj5Q7Qj01nccuHNcLn9JWgFtDRFt3HQuLLZDPIEkvD9usUE9oLrKeve4Cg0TQEOwzq+tovGIo4mqBFbQ3iLOVdZCuTOqUknJTkzcdDmCqv37nooCbNLLD1S8hRqZcpbL4sTtDd0t42A7CFI8nWYp/Ho079vBt6MpOntg9YgCUNdpF0TMMkSMvB8j7jtMd2uPRGkt/YiTjMvNb0xMLYV94qYIfex/iGwukYvRYwZiT+FPYyFmg== 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=RMuSe6FEFxGDvX/sqWgJC3oZ5D78m4r6nwK/M2i36wM=; b=ALHbEXxDgnOkYb9xRTWpZFoVg781ypFPZgMVerCpkkRPyyFHPH++PoY6BVUMZI66Fproi8KLZjQ6udVlWYt5U1KwfCmAFLnXp9UfBtbIYFax+NnyKnh/QMHgCsowDxmFRV0fkkEyYnIXKbw7OxBD0AhILoG87Nv8Yg96ZqP66yDy6kQchq0Lk5BNeE51lIjbiPhW16Kf269TgdAAYK1b/gsIs/JMdtbTP6XhH9YSYT+vnmBYxNBAWtSPmWWq9qEhRB+Qr1i96C+Mq3rrkhkMVDO3UdLNNFhsZU6kc4zjLa0EzQE0BTOWNT1vL1da7AOXLOSg+naDYFveMA30aTjdgA== 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=RMuSe6FEFxGDvX/sqWgJC3oZ5D78m4r6nwK/M2i36wM=; b=g5dcgSVLGalWzUqV0st6jQfb12w7tQNbWKC0ne8AJGZjsgFPKFBc2op8GG0QKyUWLBZHqOKCHXn58pwpiV1hgdmA3IrPRstqWqZ5bexZ+1avFiWKp1QKqQaQKdadQlhFCQbZ1hdnFI22XU/ShfF4NiFFrhnDtKSq2DtpVtKRhQp2kXsNoZ1mQhvL0yMhnDvugBNDHTwz9zqdyAPFHFbX+LvFzxMJD76kgY0F1i6UKOP9mk/olzbn1Svx2y9l2ixP1ePxnSGJm6xn75rmKDVFk5M13EPBJh65z2kzuy3fY/O3jEaI1W7BSsbCGR20MVjOmf9LhuiLeQ98Faa6SQ8Z7Q== 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 PUZPR06MB5818.apcprd06.prod.outlook.com (2603:1096:301:f1::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.29; Sat, 6 May 2023 14:43:11 +0000 Received: from SEZPR06MB5269.apcprd06.prod.outlook.com ([fe80::76d6:4828:7e80:2965]) by SEZPR06MB5269.apcprd06.prod.outlook.com ([fe80::76d6:4828:7e80:2965%7]) with mapi id 15.20.6363.029; Sat, 6 May 2023 14:43:11 +0000 From: Yangtao Li To: jaegeuk@kernel.org, chao@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Yangtao Li , Christophe JAILLET Subject: [PATCH v2 2/2] f2fs: move the conditional statement after holding the inode lock in f2fs_fallocate() Date: Sat, 6 May 2023 22:42:57 +0800 Message-Id: <20230506144257.9611-2-frank.li@vivo.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230506144257.9611-1-frank.li@vivo.com> References: <20230506144257.9611-1-frank.li@vivo.com> X-ClientProxiedBy: SI1PR02CA0058.apcprd02.prod.outlook.com (2603:1096:4:1f5::9) To SEZPR06MB5269.apcprd06.prod.outlook.com (2603:1096:101:78::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SEZPR06MB5269:EE_|PUZPR06MB5818:EE_ X-MS-Office365-Filtering-Correlation-Id: 1ef9b1c1-268b-4ce7-90db-08db4e403716 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SPEGXC3cvuV/dwoYYMEROvgvnBJtstvMElx8U2mxXtg1ry4T7B7z30VKR4/+VKLio0wim9csHrOnpRKEza9vgOuMz2Hds1EsbxBEyiXAHv4BtoCcxArQ7TkKM4O125R85TteGMfo6edvzsbWFtMqEB3q/TCjkhYsE3a2MPL8gucjA7iQAkjzoOAQfbiRS3k5Meb1mfxtVn+SMXPXjrWF2Ww5RB3l0YfiZuIKmnKvUxtTAjHULZ7BiWSUqt4Uo7mYdvpFFXdAoz50qmc9zt7dFctBqqaBUgQDCCZuiG8Ot5dwbd24e24uaT0JzJnO4fEJNVBiN6mvlyhKR0iWzR8rsq2IZnuk0TgfbeEGv13stna7ZDVQdBhN0f8z+RJR20BpMMaZu1uZjC6Jpmwc3NRX9gZjP3mnHunZfBTiZsF9LCRmSOJdKxWfAh+wj4EJen8v+rWtT1ZbIZK0VzrVKdiuSL9SuthdvmDLI3AsiCnA5nftPLz4SVXP94ZHlztLM/NGAQxOUpC4VuuK1zSrpxqSy9U+BLu6YZY9zFgzs3cnmpwWtB8S6LPhL3o1ezCdnh0EdkhMI7F0kkkDMHgKImVZbM9a+OPdG0Ni3ddmqMACtdqmgUAA8IdGe7bXt5BXDJd3 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:(13230028)(4636009)(39860400002)(366004)(376002)(136003)(346002)(396003)(451199021)(8936002)(41300700001)(8676002)(5660300002)(2906002)(54906003)(66476007)(66946007)(66556008)(4326008)(316002)(478600001)(6486002)(52116002)(6666004)(83380400001)(6506007)(6512007)(1076003)(26005)(36756003)(86362001)(2616005)(186003)(38100700002)(38350700002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: K7A6gPUT0wrpTxGSiiVutqxu/Sj6Vjy5lHVsuybi/trTUwM+2c8eU8i2+UrssC4tV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C0yOkThof2ksB7aw8ji2WObbVrh3kBYSTvnsdMLrFy5t7FsFqdfgakMLfSNlO3Dkr37ej5x4RxqUo0Aqr1u4hSDHcO2875kKPIFILd4fU5R2qu+CRWy+gzS0DFsgUifeY9NjL0vI8k8/e/N7yQG0H7O5VbqLEgaOphZKqovbx00FoT46D4rYVIuJcn4z9GmZ1irMvFGbQmfy3SPp1dZxIy1vEuwCkYNqm1BLowfV7xPZmA1D0MnzonQx9gkdeB+HmNoUrIti9vIQNqMBzxiyUVFbkpiyrpxb+xnlkK3YNLUZzc2mCdaKK5PIxV05YL9f3QjRqwO+9W23RJK2yUsTdBPNarxtr3YzWbK+Mrg0RPQQboKqeAxzztsiRS5jfQE8Rxvy8S2/0bVxSl+hlEVuWQEZjtcd+ln9p+hdH6Vq3Yw+HjvSDgaP4ycwuysg8YkOzVIb+x+C9G X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1ef9b1c1-268b-4ce7-90db-08db4e403716 X-MS-Exchange-CrossTenant-AuthSource: SEZPR06MB5269.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 May 2023 14:43:11.3666 (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: EjKB1tBwy1Y4JyibvcTFKWNr32UDbFjbr85gkYI+anEYWXQlf6dLgxs2ZrI/KYy3Tr479qn91dblGl4eoJxFGA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PUZPR06MB5818 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765159242280658807?= X-GMAIL-MSGID: =?utf-8?q?1765159242280658807?= For judging the inode flag state, the inode lock must be held. Cc: Christophe JAILLET Fixes: fcc85a4d86b5 ("f2fs crypto: activate encryption support for fs APIs") Signed-off-by: Yangtao Li --- v2: -add unlock fs/f2fs/file.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 42a9b683118c..0dbbcb406d3f 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -1801,9 +1801,18 @@ static long f2fs_fallocate(struct file *file, int mode, if (!S_ISREG(inode->i_mode)) return -EINVAL; + if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE | + FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_ZERO_RANGE | + FALLOC_FL_INSERT_RANGE)) + return -EOPNOTSUPP; + + inode_lock(inode); + if (IS_ENCRYPTED(inode) && - (mode & (FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_INSERT_RANGE))) + (mode & (FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_INSERT_RANGE))) { + inode_unlock(inode); return -EOPNOTSUPP; + } /* * Pinned file should not support partial truncation since the block @@ -1811,15 +1820,10 @@ static long f2fs_fallocate(struct file *file, int mode, */ if ((f2fs_compressed_file(inode) || f2fs_is_pinned_file(inode)) && (mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_COLLAPSE_RANGE | - FALLOC_FL_ZERO_RANGE | FALLOC_FL_INSERT_RANGE))) - return -EOPNOTSUPP; - - if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE | - FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_ZERO_RANGE | - FALLOC_FL_INSERT_RANGE)) + FALLOC_FL_ZERO_RANGE | FALLOC_FL_INSERT_RANGE))) { + inode_unlock(inode); return -EOPNOTSUPP; - - inode_lock(inode); + } ret = file_modified(file); if (ret)