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+UrssC4tVI2ZTeEeZ8yBYy/gFBSDRTiZd7qh1PVqDtCYHhpcmV6H/dUiAVDzPoiSGNwjbgcJQhE2qPc3Bj3OKyMoTpykpTSxIno6fTgRHxaovwEtBtTEqMAXVQGpm4QulQrvozxmS8+0tsgMoFr1i8prw5e19xo5d3K2YmnHzDRC7caOOCis1kFeUt8wBQP4nc4b5HgZI6ItADdrb8C8VzZNdKH++nhL/zC2zL6oc0ZOe8PGgBwAZwy0o2U91SDAZF4oRTOqjXvNQKWHS7hbwheEIZYpkYv/YJs4abm07L4wZhHVbmmKI2Njee+tt1lHsoER97UHV4gLLpoVDUhqsDEBD40fqyCFnZuN4fRAqFmE+JiShbTbgqPqktVmwN4xXEhMT7v5NhtO0RXlC26WGe4tuInG24EA+LNOQFkdLd+qsIC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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)