[v2,1/2] f2fs: move the conditional statement after holding the inode lock in f2fs_move_file_range()
Message ID | 20230506144257.9611-1-frank.li@vivo.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> 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 <rfc822;baris.duru.linux@gmail.com> + 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 <rfc822;linux-kernel@vger.kernel.org>); 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 <linux-kernel@vger.kernel.org>; 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 <frank.li@vivo.com> To: jaegeuk@kernel.org, chao@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Yangtao Li <frank.li@vivo.com>, Christophe JAILLET <christophe.jaillet@wanadoo.fr> 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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/mmzDNFEPFAxWMJT0swb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gy0aKPhVfRe3RcQ5D+3irfjUchwLMX1k0UReQjcb7Bcl6XzF X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 50d597bf-4da3-44d9-3a18-08db4e4035cb 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: <linux-kernel.vger.kernel.org> 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?= |
Series |
[v2,1/2] f2fs: move the conditional statement after holding the inode lock in f2fs_move_file_range()
|
|
Commit Message
李扬韬
May 6, 2023, 2:42 p.m. UTC
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 <christophe.jaillet@wanadoo.fr>
Fixes: 4dd6f977fc77 ("f2fs: support an ioctl to move a range of data blocks")
Signed-off-by: Yangtao Li <frank.li@vivo.com>
---
v2:
-add unlock
fs/f2fs/file.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
Comments
On 2023/5/6 22:42, Yangtao Li wrote: > For judging the inode flag state, the inode lock must be held. > BTW, add compressd file check and to avoid 'if' nesting. Please describe what's the detail problem if we check the flag w/o inode lock. Can we use one single patch to fix all similar issues? Thanks, > > Cc: Christophe JAILLET <christophe.jaillet@wanadoo.fr> > Fixes: 4dd6f977fc77 ("f2fs: support an ioctl to move a range of data blocks") > Signed-off-by: Yangtao Li <frank.li@vivo.com> > --- > 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;
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;