From patchwork Tue May 23 10:03:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 13252020 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38E87C77B75 for ; Tue, 23 May 2023 10:05:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236326AbjEWKEr (ORCPT ); Tue, 23 May 2023 06:04:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236269AbjEWKEq (ORCPT ); Tue, 23 May 2023 06:04:46 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7192A126 for ; Tue, 23 May 2023 03:04:42 -0700 (PDT) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34N6EoMH011162 for ; Tue, 23 May 2023 10:04:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-03-30; bh=JkUW1mrjjsaaDG9SHG3r6zU7U9IcDMLgY25r+GEG/ko=; b=BSNJbxBhOTIHw1jNijuY0edBcqnBWyVRYQkysPANZnhXGJnFZdlnB1hKBsNtwO9uuq3c PurmnUuD7xC4Ic1m7lBgOhWVXiaAsf23usL+SNgqpd+b1QNYm12mSxy14P8M9pPaD4uu Yf5pZNvA6QSDO9NHvYrZt6kRRRAu6mUlnaenR2Ds8z2fannm/by0iORLFBwxXWUvmuHg cYlJmvAdUX7ZnREfe5nlE86cI9bi8vIJ4Tnik3gefBZLLi3PCRFxImrW6MEV0fxkKPJI dvqRA7dywytQscQe6SBQZYkbzi1OjzE4fTC0eXauSqcqsQTKq6aipz0OuKVEjDX/1ElE IQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3qpp424r3e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 23 May 2023 10:04:42 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 34N8SYTH029085 for ; Tue, 23 May 2023 10:04:41 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2168.outbound.protection.outlook.com [104.47.55.168]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3qqk2am7gh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 23 May 2023 10:04:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=huoMHFWjONW8Dk93PJos/GOJvdnlNAJ5s2mbX1nXqJVZaLsojMh0zYEPBgjaCtkIuyIA6JDz6JbCDbZ6dwkaXj3VFihMIKfbMHXJ7iwJhJOzzxxZxQdEStb0i6Kcr0Q+osk8CV2w4+5cNfFRqfC297KTV7qlE0K+udRylbQQIGnZ5TgieFDl4QWKQDWeWKni2SZwuXka9pw9oYGYa9rXG4IodVF+Vz8b9abKywVUhWup/fslqR0n4t6rsDtO7j0InI/sH+g5QIfA++pNpibI0MtZeM3+OelPrK7RREWgizx1Ks6DqZlgptJI8LciaGoCKAdCj7EEmZ/aW023DBDjIQ== 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=JkUW1mrjjsaaDG9SHG3r6zU7U9IcDMLgY25r+GEG/ko=; b=mluoN02boJuGLW232y9tOVYHDiIl42DS9uWxGuJZj1G5zJZNJI1+yMyPqXSQvclR/u1+jMqqumNxkqpnH/fyvm0VX3xFluRUWLS3k5atS/mTtJAoW0/vX+4fDKy58LgvqyZLJlJPyU4TY/rV+nxFs+DawQWJih+kosa4xn/EOO2I1x5HWuCuF1oKOuKQfnXZOG+sLLc9EO0DiGtAnlyJwJH+YOJ/PZ1bkrwHOh16bYGcOcN23nLLq63b20gesbTc6La06vVGqHsnM2ZMHxm7lyMftQ14/gm4Ny+9uAybTDah0X+IAc+/24ra/JepX/1gqZzKBJWafiBQlsgFubXuqA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JkUW1mrjjsaaDG9SHG3r6zU7U9IcDMLgY25r+GEG/ko=; b=y4ae/XvI42416SPzznxnGhicL79sdn+k7CFFH1Y753mSqjG37O+DojGliieQNnpxMW16hX3v/Z4l0R1Hoo9pCxDnrfv7KtO7CNJ3QO4a36NkMQTdiU9lchxbRKcA2fOwo7/EGTwv8LZH7+IenXxVk81ZiFI49b3tQyaLOBIgE7A= Received: from PH0PR10MB5706.namprd10.prod.outlook.com (2603:10b6:510:148::10) by SJ0PR10MB4416.namprd10.prod.outlook.com (2603:10b6:a03:2ae::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6411.28; Tue, 23 May 2023 10:04:39 +0000 Received: from PH0PR10MB5706.namprd10.prod.outlook.com ([fe80::bc67:ac75:2c91:757e]) by PH0PR10MB5706.namprd10.prod.outlook.com ([fe80::bc67:ac75:2c91:757e%7]) with mapi id 15.20.6411.028; Tue, 23 May 2023 10:04:39 +0000 From: Anand Jain To: linux-btrfs@vger.kernel.org Cc: Anand Jain Subject: [PATCH 6/9] btrfs: refactor with memcmp_fsid_fs_devices helper Date: Tue, 23 May 2023 18:03:20 +0800 Message-Id: X-Mailer: git-send-email 2.39.2 In-Reply-To: References: X-ClientProxiedBy: SG2PR06CA0222.apcprd06.prod.outlook.com (2603:1096:4:68::30) To PH0PR10MB5706.namprd10.prod.outlook.com (2603:10b6:510:148::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH0PR10MB5706:EE_|SJ0PR10MB4416:EE_ X-MS-Office365-Filtering-Correlation-Id: 95e389e5-d42f-4d54-1148-08db5b751ecc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: r6VubQ2RaHhrCUzAvxowUksQuAs984hI5UwziUEEAAEHpujHBy9XmOPZ9HVlHJjGeJGExplwG2LHGDdc1N1kjGTEU24Qqrrx46pUVB16Hff2Bu8PyMGszYVT86+m9uiOjp32DWrs/yAEuruiZxXo7c3Jw5ZSWO7Eiw99XTfhCLdb3dQ8XF/xc1pajUwW/Ouf4cS1JJm7ceOfI5khWBBCkGoX1dscUxNEsnTDnNLvO1mhsSnMZu6+b2LlRiIfjw/yXfBFG1D+qG13AyHGapXNblbw3vaX4j+2OoVBxX3ea06mv4zs4YdGYHEjCYkKF8zJnGICGOW5KS91yPE1EYeJ5AjHnpctaNSurcCyTGR34pi8bLDpTTkaTayjTFZu5gvKcZ6DSsjbXLr6LTnw4ff3OBaVS4tgolXUP5HeXo0x/2IvhPkkudTjcy+t3GNTA8NeuAOG9hfszV4jED50uFkVs+Cvme22OVlxDV76Pjtv90TemazYMWNIgXvei8YtE1NW17N4N7jUtQUYpNyb9YEFSpfWd3U9Qs3K725XbHRfa31iQxQzCxoxP9jS4tgnNVp8 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR10MB5706.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(396003)(39860400002)(136003)(376002)(366004)(346002)(451199021)(8936002)(8676002)(5660300002)(186003)(26005)(6512007)(6506007)(41300700001)(44832011)(107886003)(83380400001)(38100700002)(478600001)(86362001)(66946007)(66556008)(66476007)(316002)(4326008)(6916009)(2616005)(6666004)(36756003)(2906002)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 23c8gBS2KVdJykTToM1B63Ea11U4U0vvApaBMJ+lyCJb3kG9PKGVhtpID/LS+Mr0/QsIdEHr6SOmafcsrpBGBCyf25ZeTKTnfY+OdexkqdtzZ8H5tt9ZLhLAVnPDECvh25uU8OGjUOGIzFfc6GqfOByzkxgebgHDjRRWnX1D/XnPfVrBARFTTPs/FEaNX2kHpAUOIzF3rTQdPzFXCbgqAB+bk1Oo1z/Q6QGyk5Dj3Bkoqy/UdfkVIONhMIOhRbILlfv0jLiMydy224/rHXzEC2iwLx35gJVYsYSJCrMuVznGhYdpAccuJKLzZGK50Hpg4zN3noVSUI0zksXcXNzrl02x1912meedA0VcOjP9UqMGtEWk311SDqGraksdAr/YvoM9FOO9siNQsqHzKTeVUSwVjD2Lmra+T1qVJnJzOFzpcdIMNL+jTKvzpG2d2CJu8sQ8DpiVoBlACV3ce5P2KzG0JqINbqMu0YxmCYSFo7DB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chxqFu5qCtS2jMxc9Z51iWXZKH4WOxwsrs X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: AZWcOMlWKr0ff4m3KRK9t2DaxLx2moN7JHkBim5HZ9vih2+67iAg5Fqq33pUXbIFC5WqxpWPH3xpg1+B4Hd0Ku59rFmnIWLn+NRM7ZYT+Aforjo0aUFmEVEezsDHLWU/m8CLlrf3b61R9T16kIzX5KbuJey+CgaunTChX30lZOzoc6/KCl0s/hJ3gXXNHGt2bVdJ5JszKrXeQWe4jBmVQMYRDD3NDi4Q2aeC8YEB4P/Orwlp1enRRs+1DOkWWP6jOBpXmFgCi6tRGRTgg7b5zubRkOxOw0lVuAp00d9nWzmTvHOi42ZANf0FAe7MSU7Iqg0D4YNUjJAwXZ+sxMExRc5Ay89zRuBN3j3J4mOBdc950d0OFflotSnaLxodpm0yjM0yaWyrK8TEFhzi4asHRdVL4wtC/FbPEQVyD04UHBlV4ssPvO2Tz6hH1FHEbz+GsFI+fLZpPMV2mApTz9DfBxsggazGLLLaBRT755rLJbED4HydMmT4tAWtlytYiUzKDdo2qiahRAuAtAsowqzGm4kVEJIluXyEqXMZGs8SPThjrQQW2PY38Ipv96ToZOWJynO5t0YbY0cRV9eLTBV8RjEwBltVMPYrbFsHXfvGmNi3q7Ic1pvXTdCqJocbzu5W7+541aw7S6/rZPcoUknKZ6svz54ZWYobxrnyklW1909cCq+kiZsnTzZSYHR7fqjnV212x1HUKzYwf0WnIvObnHDxKCMEEfVAKWf+kqx4/fOfXR8rGfnAY7TEnN+UcFGxr4y7nBJGE1/jhLNIIIm/sg== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 95e389e5-d42f-4d54-1148-08db5b751ecc X-MS-Exchange-CrossTenant-AuthSource: PH0PR10MB5706.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 May 2023 10:04:39.2235 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: y6l4/2eJKf3voZ9bNPwQP2zXbT/29MIJkt29hv8lmFN8RZDHVXDu4MBTc1uWrjZs5sZgEeXz5OZGwEqhx+Apyg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4416 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-23_06,2023-05-23_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305230082 X-Proofpoint-ORIG-GUID: AH9oHUmFgeSYMRTi6fdLUK0e142xV0So X-Proofpoint-GUID: AH9oHUmFgeSYMRTi6fdLUK0e142xV0So Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Refactor the functions find_fsid() and find_fsid_with_metadata_uuid(), as they currently share a common set of code to compare the fsid and metadata_uuid. Create a common helper function, memcmp_fsid_fs_devices(). Signed-off-by: Anand Jain --- fs/btrfs/volumes.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 95b87e9a0a73..8738c8027421 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -427,6 +427,22 @@ void __exit btrfs_cleanup_fs_uuids(void) } } +static bool memcmp_fsid_fs_devices(struct btrfs_fs_devices *fs_devices, + const u8 *fsid, const u8 *metadata_fsid) +{ + if (memcmp(fsid, fs_devices->fsid, BTRFS_FSID_SIZE) != 0) + return false; + + if (!metadata_fsid) + return true; + + if (memcmp(metadata_fsid, fs_devices->metadata_uuid, BTRFS_FSID_SIZE) != + 0) + return false; + + return true; +} + static noinline struct btrfs_fs_devices *find_fsid( const u8 *fsid, const u8 *metadata_fsid) { @@ -436,15 +452,8 @@ static noinline struct btrfs_fs_devices *find_fsid( /* Handle non-split brain cases */ list_for_each_entry(fs_devices, &fs_uuids, fs_list) { - if (metadata_fsid) { - if (memcmp(fsid, fs_devices->fsid, BTRFS_FSID_SIZE) == 0 - && memcmp(metadata_fsid, fs_devices->metadata_uuid, - BTRFS_FSID_SIZE) == 0) - return fs_devices; - } else { - if (memcmp(fsid, fs_devices->fsid, BTRFS_FSID_SIZE) == 0) - return fs_devices; - } + if (memcmp_fsid_fs_devices(fs_devices, fsid, metadata_fsid)) + return fs_devices; } return NULL; } @@ -462,14 +471,15 @@ static struct btrfs_fs_devices *find_fsid_with_metadata_uuid( * at all and the CHANGING_FSID_V2 flag set. */ list_for_each_entry(fs_devices, &fs_uuids, fs_list) { - if (fs_devices->fsid_change && - memcmp(disk_super->metadata_uuid, fs_devices->fsid, - BTRFS_FSID_SIZE) == 0 && - memcmp(fs_devices->fsid, fs_devices->metadata_uuid, - BTRFS_FSID_SIZE) == 0) { + if (!fs_devices->fsid_change) + continue; + + if (memcmp_fsid_fs_devices(fs_devices, + disk_super->metadata_uuid, + fs_devices->fsid)) return fs_devices; - } } + /* * Handle scanned device having completed its fsid change but * belonging to a fs_devices that was created by a device that