From patchwork Thu Dec 12 11:01:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Su Yue X-Patchwork-Id: 11287907 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 00D15930 for ; Thu, 12 Dec 2019 11:01:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C7C262077B for ; Thu, 12 Dec 2019 11:01:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QgnBPjbM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728945AbfLLLBk (ORCPT ); Thu, 12 Dec 2019 06:01:40 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:35923 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728871AbfLLLBj (ORCPT ); Thu, 12 Dec 2019 06:01:39 -0500 Received: by mail-pg1-f196.google.com with SMTP id k3so979539pgc.3 for ; Thu, 12 Dec 2019 03:01:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lCXGc/wSJhn4wzphnffaLhuDhHbrWuw4a01//wlA3rw=; b=QgnBPjbMbZsEb7rWFYgAATgcEvm7TNsNazJpkpIQ98oyqM0Gdxn9sAIvELvP0+SBTt GE/5Qh98MsDLN+HiuUc8xeETw+j2pE8n9Aaqv/Q3krBOpNE6TS4JsvHdhIrpBnHg0JHJ BkBNSj3QcpDv/HiB4ByxQ4RCP3ESXEc0or9i4zloYyMBwRk3xh3rIYp92JRjnAHgBx8z PIpEJoN/kzHARUptG5btPQ44rAzJPuCJjKhXZAnyZexX5RVnqGAHt722bTovavV7YPvu NYTN3XXffHrC3syGeKPkvhePWxzZdVxxZ/JaCfy5zjYhXnrlTSjWHYP+CLs+0JMWxJBu EaBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lCXGc/wSJhn4wzphnffaLhuDhHbrWuw4a01//wlA3rw=; b=a2COamEyulJeMflqmZywqtO3CQMXGMXoS/RaTJzGz9fPtIE1o5N7OhQYwBFgEvwddP oqZ//SPMM+JvsGbYjVRrv0fnoloVP2O7OHzcDbNlaiisxfbi3EP+PKI15ukdsw7pcyM8 /WkWN3x7TUl3wjHYWKa3/SlB5EusQvdz4hQ3B4zCytN76EdWhme18ba4t7muf/um/OrO KnQvv0/0G6vAVdLbYuYA3WXjYbneUkNMNPvJ4Iklovgg3xoaANiy6XLXMJsQa1MxKLab r8/BcoT53L9CpZ9d4VHeOcnDMEJW+HCfVQ6la/p3vh2LjrR66ScoSZ6tzrdNvEvP9YN2 tiVg== X-Gm-Message-State: APjAAAV7KQKdysRhcAlKIFr+GbK4Cl2W/CBSYc8Wld6XDBqs44wFcMrR gOTKFy6dGI5SvEOEkaCy6d22eXRuVXc= X-Google-Smtp-Source: APXvYqx4bzdO8rCWCz0CLckrVwuwr0VL4+opDaVYXn+joDt3acp46LY0w1pwdhIxFoxFesDdLMjJyA== X-Received: by 2002:a65:6842:: with SMTP id q2mr9973911pgt.345.1576148498487; Thu, 12 Dec 2019 03:01:38 -0800 (PST) Received: from p.lan ([45.58.38.246]) by smtp.gmail.com with ESMTPSA id w11sm6682387pfn.4.2019.12.12.03.01.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Dec 2019 03:01:38 -0800 (PST) From: damenly.su@gmail.com X-Google-Original-From: Damenly_Su@gmx.com To: linux-btrfs@vger.kernel.org Cc: Su Yue Subject: [PATCH 1/6] btrfs: metadata_uuid: fix failed assertion due to unsuccessful device scan Date: Thu, 12 Dec 2019 19:01:27 +0800 Message-Id: <20191212110132.11063-2-Damenly_Su@gmx.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122.2) In-Reply-To: <20191212110132.11063-1-Damenly_Su@gmx.com> References: <20191212110132.11063-1-Damenly_Su@gmx.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Su Yue While running misc-tests/034 of btrfs-progs, easy to hit: ====================================================================== [ 1318.749685] BTRFS: device fsid 55abf31c-6b3a-47ad-8711-cfd5a249dd4c devid 2 transid 8 /dev/loop0 scanned by systemd-udevd (3530) [ 1318.846791] BTRFS: device fsid 55abf31c-6b3a-47ad-8711-cfd5a249dd4c devid 2 transid 8 /dev/loop0 scanned by systemd-udevd (3530) [ 1318.847812] BTRFS: device fsid 55abf31c-6b3a-47ad-8711-cfd5a249dd4c devid 2 transid 8 /dev/loop0 scanned by mount (3540) [ 1318.901278] assertion failed: !memcmp(fs_info->fs_devices->fsid, fs_info->super_copy->fsid, BTRFS_FSID_SIZE), in fs/btrfs/disk-io.c:2874 [ 1318.901499] ------------[ cut here ]------------ [ 1318.901503] kernel BUG at fs/btrfs/ctree.h:3118! [ 1318.901582] invalid opcode: 0000 [#1] PREEMPT SMP KASAN NOPTI [ 1318.901644] CPU: 4 PID: 3540 Comm: mount Tainted: G O 5.5.0-rc1-custom+ #41 [ 1318.901720] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 0.0.0 02/06/2015 [ 1318.901836] RIP: 0010:assfail.constprop.0+0x1c/0x1e [btrfs] [ 1318.901894] Code: 00 00 44 89 c0 5b 41 5c 41 5d 41 5e 5d c3 55 89 f1 48 c7 c2 40 13 0f c1 48 89 fe 48 c7 c7 00 1b 0f c1 48 89 e5 e8 3e 12 0f dc <0f> 0b e8 93 01 39 dc be 56 03 00 00 48 c7 c7 a0 1b 0f c1 e8 cc ff [ 1318.902069] RSP: 0018:ffff88814fea76e0 EFLAGS: 00010282 [ 1318.902124] RAX: 000000000000007c RBX: ffff88814d862400 RCX: 0000000000000000 [ 1318.902191] RDX: 0000000000000001 RSI: 0000000000000008 RDI: ffffed1029fd4ecf [ 1318.902259] RBP: ffff88814fea76e0 R08: 000000000000007c R09: ffffed102b3fe719 [ 1318.902326] R10: ffffed102b3fe718 R11: ffff888159ff38c7 R12: ffff8881398ac000 [ 1318.902394] R13: ffff888145742930 R14: ffff88812f56e000 R15: ffff88812f56e000 [ 1318.902464] FS: 00007f0753032500(0000) GS:ffff888159e00000(0000) knlGS:0000000000000000 [ 1318.902539] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 1318.902595] CR2: 0000560357a9c018 CR3: 00000001502d4000 CR4: 0000000000340ee0 [ 1318.903852] Call Trace: [ 1318.904958] open_ctree+0x166c/0x373e [btrfs] [ 1318.906029] ? congestion_wait+0x2d0/0x2d0 [ 1318.907500] ? wb_init+0x31e/0x400 [ 1318.908699] ? close_ctree+0x52b/0x52b [btrfs] [ 1318.909734] btrfs_mount_root.cold+0xe/0x118 [btrfs] [ 1318.910764] ? btrfs_decode_error+0x40/0x40 [btrfs] [ 1318.911784] ? vfs_parse_fs_string+0xdc/0x130 [ 1318.912798] ? rcu_read_lock_sched_held+0xa1/0xd0 [ 1318.913835] ? rcu_read_lock_bh_held+0xb0/0xb0 [ 1318.914878] ? legacy_parse_param+0x75/0x340 [ 1318.915946] ? __lookup_constant+0x54/0x90 [ 1318.917005] ? debug_lockdep_rcu_enabled.part.0+0x1a/0x30 [ 1318.918099] ? kfree+0x2fd/0x360 [ 1318.919233] ? btrfs_decode_error+0x40/0x40 [btrfs] [ 1318.920361] legacy_get_tree+0x89/0xd0 [ 1318.921480] vfs_get_tree+0x52/0x140 [ 1318.922625] fc_mount+0x14/0x70 [ 1318.923713] vfs_kern_mount.part.0+0x78/0x90 [ 1318.924789] vfs_kern_mount+0x13/0x20 [ 1318.925885] btrfs_mount+0x1f3/0xb30 [btrfs] [ 1318.926922] ? sched_clock_cpu+0x1b/0x130 [ 1318.927936] ? find_held_lock+0x95/0xb0 [ 1318.928964] ? btrfs_remount+0x7e0/0x7e0 [btrfs] [ 1318.929939] ? vfs_parse_fs_string+0xdc/0x130 [ 1318.930875] ? vfs_parse_fs_string+0xdc/0x130 [ 1318.931784] ? rcu_read_lock_sched_held+0xa1/0xd0 [ 1318.932651] ? rcu_read_lock_bh_held+0xb0/0xb0 [ 1318.933497] ? legacy_parse_param+0x75/0x340 [ 1318.934327] ? __lookup_constant+0x54/0x90 [ 1318.935173] ? debug_lockdep_rcu_enabled.part.0+0x1a/0x30 [ 1318.936023] ? kfree+0x2fd/0x360 [ 1318.937372] ? cap_capable+0xb3/0xf0 [ 1318.938323] ? btrfs_remount+0x7e0/0x7e0 [btrfs] [ 1318.939126] legacy_get_tree+0x89/0xd0 [ 1318.939921] ? legacy_get_tree+0x89/0xd0 [ 1318.940687] vfs_get_tree+0x52/0x140 [ 1318.941431] do_mount+0xe01/0x1220 [ 1318.942189] ? rcu_read_lock_bh_held+0xb0/0xb0 [ 1318.942935] ? copy_mount_string+0x20/0x20 [ 1318.943690] ? __kasan_check_write+0x14/0x20 [ 1318.944438] ? memdup_user+0x52/0x90 [ 1318.945190] ksys_mount+0x82/0xd0 [ 1318.945921] __x64_sys_mount+0x67/0x80 [ 1318.946640] do_syscall_64+0x79/0xe0 [ 1318.947364] entry_SYSCALL_64_after_hwframe+0x49/0xbe [ 1318.948109] RIP: 0033:0x7f07531b5e4e [ 1318.948851] Code: 48 8b 0d 35 00 0c 00 f7 d8 64 89 01 48 83 c8 ff c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 49 89 ca b8 a5 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 02 00 0c 00 f7 d8 64 89 01 48 [ 1318.951249] RSP: 002b:00007ffeffa9c9f8 EFLAGS: 00000246 ORIG_RAX: 00000000000000a5 [ 1318.952119] RAX: ffffffffffffffda RBX: 00007f07532dc204 RCX: 00007f07531b5e4e [ 1318.952988] RDX: 0000560357a97430 RSI: 0000560357a96230 RDI: 0000560357a93500 [ 1318.953867] RBP: 0000560357a932f0 R08: 0000000000000000 R09: 0000560357a990e0 [ 1318.954757] R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 [ 1318.955638] R13: 0000560357a93500 R14: 0000560357a97430 R15: 0000560357a932f0 [ 1318.956540] Modules linked in: btrfs(O) xor zstd_decompress zstd_compress raid6_pq loop mousedev nls_iso8859_1 nls_cp437 vfat fat iTCO_wdt crct10dif_pclmul iTCO_vendor_support snd_hda_codec_generic crc32_pclmul crc32c_intel ghash_clmulni_intel snd_hda_intel snd_intel_dspcfg snd_hda_codec snd_hwdep snd_hda_core snd_pcm input_leds snd_timer led_class psmouse pcspkr aesni_intel i2c_i801 snd intel_agp glue_helper crypto_simd cryptd soundcore lpc_ich intel_gtt rtc_cmos qemu_fw_cfg agpgart evdev mac_hid ip_tables x_tables xfs sr_mod cdrom sd_mod dm_mod virtio_scsi virtio_balloon virtio_rng virtio_blk virtio_console rng_core virtio_net net_failover failover ahci serio_raw libahci atkbd libps2 libata scsi_mod virtio_pci virtio_ring virtio i8042 serio [last unloaded: btrfs] [ 1318.965122] ---[ end trace 51f0adac8fc1fe76 ]--- ====================================================================== Acutally, there are two devices in the fs. Device 2 with FSID_CHANGING_V2 allocated a fs_devices. But, device 1 found the fs_devices but failed to be added into since fs_devices->opened ( the thread is doing mount device 1). But device 1's fsid was copied to fs_devices->fsid then the assertion failed. The solution is that only if a new device was added into a existing fs_device, then the fs_devices->fsid is allowed to be rewritten. Fixes: 7a62d0f07377 ("btrfs: Handle one more split-brain scenario during fsid change") Signed-off-by: Su Yue --- fs/btrfs/volumes.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index d8e5560db285..9efa4123c335 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -732,6 +732,9 @@ static noinline struct btrfs_device *device_list_add(const char *path, BTRFS_FEATURE_INCOMPAT_METADATA_UUID); bool fsid_change_in_progress = (btrfs_super_flags(disk_super) & BTRFS_SUPER_FLAG_CHANGING_FSID_V2); + bool fs_devices_found = false; + + *new_device_added = false; if (fsid_change_in_progress) { if (!has_metadata_uuid) { @@ -772,24 +775,11 @@ static noinline struct btrfs_device *device_list_add(const char *path, device = NULL; } else { + fs_devices_found = true; + mutex_lock(&fs_devices->device_list_mutex); device = btrfs_find_device(fs_devices, devid, disk_super->dev_item.uuid, NULL, false); - - /* - * If this disk has been pulled into an fs devices created by - * a device which had the CHANGING_FSID_V2 flag then replace the - * metadata_uuid/fsid values of the fs_devices. - */ - if (has_metadata_uuid && fs_devices->fsid_change && - found_transid > fs_devices->latest_generation) { - memcpy(fs_devices->fsid, disk_super->fsid, - BTRFS_FSID_SIZE); - memcpy(fs_devices->metadata_uuid, - disk_super->metadata_uuid, BTRFS_FSID_SIZE); - - fs_devices->fsid_change = false; - } } if (!device) { @@ -912,6 +902,22 @@ static noinline struct btrfs_device *device_list_add(const char *path, } } + /* + * If the new added disk has been pulled into an fs devices created by + * a device which had the CHANGING_FSID_V2 flag then replace the + * metadata_uuid/fsid values of the fs_devices. + */ + if (*new_device_added && fs_devices_found && + has_metadata_uuid && fs_devices->fsid_change && + found_transid > fs_devices->latest_generation) { + memcpy(fs_devices->fsid, disk_super->fsid, + BTRFS_FSID_SIZE); + memcpy(fs_devices->metadata_uuid, + disk_super->metadata_uuid, BTRFS_FSID_SIZE); + + fs_devices->fsid_change = false; + } + /* * Unmount does not free the btrfs_device struct but would zero * generation along with most of the other members. So just update From patchwork Thu Dec 12 11:01:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Su Yue X-Patchwork-Id: 11287909 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 28601138D for ; Thu, 12 Dec 2019 11:01:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 05DB02077B for ; Thu, 12 Dec 2019 11:01:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="uVUuUebf" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728948AbfLLLBm (ORCPT ); Thu, 12 Dec 2019 06:01:42 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:34013 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728871AbfLLLBm (ORCPT ); Thu, 12 Dec 2019 06:01:42 -0500 Received: by mail-pf1-f194.google.com with SMTP id l127so586330pfl.1 for ; Thu, 12 Dec 2019 03:01:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Djxe/PPl0LbZU+pLhTDhmQ7+WDv6iuRyef6eSJ8l57Q=; b=uVUuUebfOhFA7gVOzVjdoMco2K18biNK+xWc4/4cY5yULiGuYAGNUU8VAD4d2iib6m 3MrN6MHjYgxL4yhMmAz2wGEo6wSgCOHzhvl9IXB2WUTZxzewORIjgYtwTii+fQKYfwvX CkTUkf1PzGgPuO9Odv7g4nVCm4SIJJltPMa5iGkd63UUp2mi2rUuIpVgTZLwdubEKV9B vM/VWVAYJHiIz8M0Gv0UOL5FKijHpEU4+4aAGzdJH+kvPr4PXykdgT8ZoJ806FeofJfj dg8hhshcN5rTRTj4dz8y5BskoNYudCedFX3pfXUDRdphGjDlxXEysZLB3F6r/hkFsnaq y5Ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Djxe/PPl0LbZU+pLhTDhmQ7+WDv6iuRyef6eSJ8l57Q=; b=BbIRHb2Hjc/1h35YpXw9mboIb2XOS+gR36lySnbhPAFOBDlhyXpRqhNSYd9VP3MQVJ sPTX0u0dqGG7rpAuNSkcCtSGEZ0ucYK+62wAMmpW6eAtzSU1Vaf2X4MvJfYpdJW51Ysr XatGalPOi8zIGNamlc9YMHGQriGE53bUo2wdu5Hq7i8b+ya6uGlhGLU+RIeTK540D5wD g8JGEWagegpRRJTWQeK9cyfshnWZADinPcA4Yq6u5u0XtMzyNzqFK5yUwLxBCU48twY8 bhk3keTp1vEwITYZUIxFU0CpLhkE7wYzDsDnqrw5sneqJ5OyOpZ6zgJGxflOXGZltBSn znmA== X-Gm-Message-State: APjAAAW2aIfUfKd7ENkJBGdLUWN1khmVaTF6/EsGt8wi5s7EzkgRPgzl hbryTTSKqfeFgzFfsdAFeQpV4XDuzYM= X-Google-Smtp-Source: APXvYqx49cUFV8KJ3kXZysaQikGe4SXC172YzF+kfwfl3K//R+ihgyRicq+WiYsxuIe2UrYd/fW5gA== X-Received: by 2002:aa7:8ad9:: with SMTP id b25mr9075793pfd.70.1576148500546; Thu, 12 Dec 2019 03:01:40 -0800 (PST) Received: from p.lan ([45.58.38.246]) by smtp.gmail.com with ESMTPSA id w11sm6682387pfn.4.2019.12.12.03.01.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Dec 2019 03:01:40 -0800 (PST) From: damenly.su@gmail.com X-Google-Original-From: Damenly_Su@gmx.com To: linux-btrfs@vger.kernel.org Cc: Su Yue Subject: [PATCH 2/6] btrfs: metadata_uuid: move split-brain handling from fs_id() to new function Date: Thu, 12 Dec 2019 19:01:28 +0800 Message-Id: <20191212110132.11063-3-Damenly_Su@gmx.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122.2) In-Reply-To: <20191212110132.11063-1-Damenly_Su@gmx.com> References: <20191212110132.11063-1-Damenly_Su@gmx.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Su Yue The parameter @metadata_fsid of fs_id() is not NULL while scanned device has metadata_uuid but not changing. Obviously, the cases handling part in fs_id() is for this situation. Move the logic into new function find_fsid_changing_metadata_uuid(). Signed-off-by: Su Yue --- fs/btrfs/volumes.c | 78 ++++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 9efa4123c335..b08b06a89a77 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -438,40 +438,6 @@ static noinline struct btrfs_fs_devices *find_fsid( ASSERT(fsid); - if (metadata_fsid) { - /* - * Handle scanned device having completed its fsid change but - * belonging to a fs_devices that was created by first scanning - * a device which didn't have its fsid/metadata_uuid changed - * 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(metadata_fsid, fs_devices->fsid, - BTRFS_FSID_SIZE) == 0 && - memcmp(fs_devices->fsid, fs_devices->metadata_uuid, - BTRFS_FSID_SIZE) == 0) { - return fs_devices; - } - } - /* - * Handle scanned device having completed its fsid change but - * belonging to a fs_devices that was created by a device that - * has an outdated pair of fsid/metadata_uuid and - * CHANGING_FSID_V2 flag set. - */ - list_for_each_entry(fs_devices, &fs_uuids, fs_list) { - if (fs_devices->fsid_change && - memcmp(fs_devices->metadata_uuid, - fs_devices->fsid, BTRFS_FSID_SIZE) != 0 && - memcmp(metadata_fsid, fs_devices->metadata_uuid, - BTRFS_FSID_SIZE) == 0) { - return fs_devices; - } - } - } - - /* 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 @@ -712,6 +678,46 @@ static struct btrfs_fs_devices *find_fsid_changed( return NULL; } + +static struct btrfs_fs_devices *find_fsid_changing_metada_uuid( + struct btrfs_super_block *disk_super) +{ + struct btrfs_fs_devices *fs_devices; + + /* + * Handle scanned device having completed its fsid change but + * belonging to a fs_devices that was created by first scanning + * a device which didn't have its fsid/metadata_uuid changed + * 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) { + return fs_devices; + } + } + /* + * Handle scanned device having completed its fsid change but + * belonging to a fs_devices that was created by a device that + * has an outdated pair of fsid/metadata_uuid and + * CHANGING_FSID_V2 flag set. + */ + list_for_each_entry(fs_devices, &fs_uuids, fs_list) { + if (fs_devices->fsid_change && + memcmp(fs_devices->metadata_uuid, + fs_devices->fsid, BTRFS_FSID_SIZE) != 0 && + memcmp(disk_super->metadata_uuid, fs_devices->metadata_uuid, + BTRFS_FSID_SIZE) == 0) { + return fs_devices; + } + } + + return find_fsid(disk_super->fsid, disk_super->metadata_uuid); +} + /* * Add new device to list of registered devices * @@ -751,13 +757,11 @@ static noinline struct btrfs_device *device_list_add(const char *path, fs_devices = find_fsid_changed(disk_super); } } else if (has_metadata_uuid) { - fs_devices = find_fsid(disk_super->fsid, - disk_super->metadata_uuid); + fs_devices = find_fsid_changing_metada_uuid(disk_super); } else { fs_devices = find_fsid(disk_super->fsid, NULL); } - if (!fs_devices) { if (has_metadata_uuid) fs_devices = alloc_fs_devices(disk_super->fsid, From patchwork Thu Dec 12 11:01:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Su Yue X-Patchwork-Id: 11287911 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6B8DB138D for ; Thu, 12 Dec 2019 11:01:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4A826214D8 for ; Thu, 12 Dec 2019 11:01:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="R527+kuN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728951AbfLLLBo (ORCPT ); Thu, 12 Dec 2019 06:01:44 -0500 Received: from mail-pl1-f181.google.com ([209.85.214.181]:45512 "EHLO mail-pl1-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728871AbfLLLBo (ORCPT ); Thu, 12 Dec 2019 06:01:44 -0500 Received: by mail-pl1-f181.google.com with SMTP id w7so430876plz.12 for ; Thu, 12 Dec 2019 03:01:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pO/g9bUT2hETdxppuk7HxjTtqbNbIc8YIlIdCsaytvw=; b=R527+kuNtq3Sh39bZ2SbdT0YgnJq3IZsYn8TCipcLiFKg0kgOO38ryL3HK5hX4dYG3 qu8APz0V/eNtm2c+IP95uLUnpVySBiAVGY+x40qGCPql3JIsRu6QU+VliCzDD7LsMcH0 h80AqwxS7TC/i7qF8dxRbcSAWaSDzdazw28jl80gYK68SBePENJzySkgGHG0xk3rw4Ij NKFQaHtXywa6GgApMgWKn4PBdF/s+HJ0KMu3OO83te2AP6A7DLBEKHAidcgcodLIQJzs 8rHy+hdk/VGJWmy9GciPW1Xh1NN0gG6TRlwh0BpJ/k5ratNM0LmLnKykbPAmiMpWJECg 2TrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pO/g9bUT2hETdxppuk7HxjTtqbNbIc8YIlIdCsaytvw=; b=bkEt1S/dD5+VV53YC/8Syjm2AolFI+JUIpOUtHOld9THZDr94HyWx6Xj3/CySTwLoP zVpVJypXJFj560kRvMXIt4/WPUX2jrqhe4EtclGHHlegsOmpvAFGls9Z7nGBSq35D+dU tMmMq5ypKOc16sJQu+RmWMuvBJl/D+Qx+WNF6C8U8rsFAJC448QS61sLA0OP2vJGtiUR vtjRk5a+AgTxDMy3gEft/B+X1azA0Ff4C1eoVICwSVccMiOfKjX92w1hsawN39nbsu43 mZrilKgdLB7mULsewaSc4/VZDMwzz8jg3XMAkaXfebp1TP/kryZE+wuV3n3laDDp0GIt yujw== X-Gm-Message-State: APjAAAV6iQCYnY2nQgB3QlE8exVVT6OWnczVhaINRHbX3bl1HIEpbOK6 dnI2w+PPOgr3XAiwffutEjOQSzI2LMM= X-Google-Smtp-Source: APXvYqxoQBxpd/FSEYWjT3kJPqSVXeBk+P3FH9IIc4DCPmuJTcKaHjToSWca0ldWqFhyEk8v1MGP4Q== X-Received: by 2002:a17:902:fe8d:: with SMTP id x13mr8949195plm.232.1576148503050; Thu, 12 Dec 2019 03:01:43 -0800 (PST) Received: from p.lan ([45.58.38.246]) by smtp.gmail.com with ESMTPSA id w11sm6682387pfn.4.2019.12.12.03.01.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Dec 2019 03:01:42 -0800 (PST) From: damenly.su@gmail.com X-Google-Original-From: Damenly_Su@gmx.com To: linux-btrfs@vger.kernel.org Cc: Su Yue Subject: [PATCH 3/6] btrfs: split-brain case for scanned changing device with INCOMPAT_METADATA_UUID Date: Thu, 12 Dec 2019 19:01:29 +0800 Message-Id: <20191212110132.11063-4-Damenly_Su@gmx.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122.2) In-Reply-To: <20191212110132.11063-1-Damenly_Su@gmx.com> References: <20191212110132.11063-1-Damenly_Su@gmx.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Su Yue This patch adds the case for scanned changing device with INCOMPAT_METADATA_UUID. For this situation, the origin code only handles the case the devices already pulled into disk with INCOMPAT_METADATA_UUID set. There is an another case that the successful changed devices synced without INCOMPAT_METADATA_UUID. So add the check of Heather fsid of scanned device equals metadata_uuid of fs_devices which is with INCOMPAT_METADATA_UUID feature. Signed-off-by: Su Yue --- fs/btrfs/volumes.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index b08b06a89a77..61b4a107bb58 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -654,7 +654,6 @@ static struct btrfs_fs_devices *find_fsid_inprogress( return NULL; } - static struct btrfs_fs_devices *find_fsid_changed( struct btrfs_super_block *disk_super) { @@ -663,9 +662,14 @@ static struct btrfs_fs_devices *find_fsid_changed( /* * Handles the case where scanned device is part of an fs that had * multiple successful changes of FSID but curently device didn't - * observe it. Meaning our fsid will be different than theirs. + * observe it. + * + * Case 1: the devices already changed still owns the feature, their + * fsid must differ from the disk_super->fsid. */ list_for_each_entry(fs_devices, &fs_uuids, fs_list) { + if (fs_devices->fsid_change) + continue; if (memcmp(fs_devices->metadata_uuid, fs_devices->fsid, BTRFS_FSID_SIZE) != 0 && memcmp(fs_devices->metadata_uuid, disk_super->metadata_uuid, @@ -676,7 +680,26 @@ static struct btrfs_fs_devices *find_fsid_changed( } } - return NULL; + /* + * Case 2: the synced devices doesn't have the metadata_uuid feature. + * NOTE: the fs_devices has same metadata_uuid and fsid in memory, but + * they differs in disk, because fs_id is copied to + * fs_devices->metadata_id while alloc_fs_devices if no metadata + * feature. + */ + list_for_each_entry(fs_devices, &fs_uuids, fs_list) { + if (memcmp(fs_devices->metadata_uuid, fs_devices->fsid, + BTRFS_FSID_SIZE) == 0 && + memcmp(fs_devices->fsid, disk_super->metadata_uuid, + BTRFS_FSID_SIZE) == 0 && !fs_devices->fsid_change) + return fs_devices; + } + + /* + * Okay, can't found any fs_devices already synced, back to + * search devices unchanged or changing like the device. + */ + return find_fsid(disk_super->fsid, disk_super->metadata_uuid); } static struct btrfs_fs_devices *find_fsid_changing_metada_uuid( From patchwork Thu Dec 12 11:01:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Su Yue X-Patchwork-Id: 11287913 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 30ED9138D for ; Thu, 12 Dec 2019 11:01:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0FD7A2173E for ; Thu, 12 Dec 2019 11:01:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lYHnLSa8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728953AbfLLLBr (ORCPT ); Thu, 12 Dec 2019 06:01:47 -0500 Received: from mail-pj1-f66.google.com ([209.85.216.66]:39563 "EHLO mail-pj1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728871AbfLLLBr (ORCPT ); Thu, 12 Dec 2019 06:01:47 -0500 Received: by mail-pj1-f66.google.com with SMTP id v93so882897pjb.6 for ; Thu, 12 Dec 2019 03:01:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AI0BdMmmWTRIKTqPcqoA73oojnJqj0oYN0qY9MI7B5I=; b=lYHnLSa8FQk8Lj9wYy3eAaRTvsByXxZ9LsS00O/etHagR64MH9LsiBS2aKUXB9R1b/ KvB26eoXXISk1TxBvcl604lzAAdTRlHkid4qTcyQVZaR2opSI0p9FtJdaanNjNTAHC5+ pv/fLzzwnxqk7osaHJ7eNgtmxmhIipyx0G+KZSdM26DSLtjDw376sCnDJ4dqxxqZfV/o vc+f2hR5iBgBzdl6Ow9bSTadB9mHSVu2nC3r9cy5cQOh2nnO/uW4Eqnod+LMyhHuNtSk h+0yvYKyM+DomcmzGwv9ZWedkYsDzKYe1+6EDuihb7859BMghMuPdlzuahxCwEkmCsI9 zl8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AI0BdMmmWTRIKTqPcqoA73oojnJqj0oYN0qY9MI7B5I=; b=gGeO7w7Mrz1LwWERg78reIkNJcd8nAu6Xo9WsD7miseSiXge2aLY8DAoJPXhCo1ex9 JBwGsl1AWlP+UPo1CFcN14VSQg9I1kUpqoafmiKDxdb2OMvxxGhB4XDm9vcf5bX1wMcY /I/L7zi4+v6Xf1wOZ1ndn3xOc/0OmVTu1zIjpY7CPNrzh/Z/OvXhbTEhYGzX6sJxmYc8 vUjcdyYCYZQ3YswZhpVYaEy+jQInIWlmyKUmwKpbKBBFKjQkf26MpEWZc4NHF30PIJiR mCa1EHwwu5P41Se8te6Eq5keHZ/mbuCORpkJZQpvbG37hOlUzpW6wr5C6RNnOmX1PWIr IbBg== X-Gm-Message-State: APjAAAXz7R6AwPPlC4nato8Lg3ZzcIgv3kl75hOm+VvvKcgPcHksMykU zbSZiEsaUCvy0dJdgyzuiBygOGIV1Hc= X-Google-Smtp-Source: APXvYqx5qSi5vF96OYgpjO6pxXUzSYWLcAvGvR77tfxhxSe0jiICgWc8y7TQKK5NGM0BSd7h05T0vw== X-Received: by 2002:a17:902:b208:: with SMTP id t8mr8996489plr.38.1576148506003; Thu, 12 Dec 2019 03:01:46 -0800 (PST) Received: from p.lan ([45.58.38.246]) by smtp.gmail.com with ESMTPSA id w11sm6682387pfn.4.2019.12.12.03.01.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Dec 2019 03:01:45 -0800 (PST) From: damenly.su@gmail.com X-Google-Original-From: Damenly_Su@gmx.com To: linux-btrfs@vger.kernel.org Cc: Su Yue Subject: [PATCH 4/6] btrfs: split-brain case for scanned changed device without INCOMPAT_METADATA_UUID Date: Thu, 12 Dec 2019 19:01:30 +0800 Message-Id: <20191212110132.11063-5-Damenly_Su@gmx.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122.2) In-Reply-To: <20191212110132.11063-1-Damenly_Su@gmx.com> References: <20191212110132.11063-1-Damenly_Su@gmx.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Su Yue This patch adds the case for scanned not changing device without INCOMPAT_METADATA_UUID. For this situation, the origin code only handles the case the devices already pulled into disk with INCOMPAT_METADATA_UUID set. There is an another case that the successful changed devices synced without INCOMPAT_METADATA_UUID. And the scanned device is the exactly changed one. So we should check if there is any changing fs_devices with INCOMPAT_METADATA_UUID. Signed-off-by: Su Yue --- fs/btrfs/volumes.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 61b4a107bb58..faf9cdd14f33 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -741,6 +741,35 @@ static struct btrfs_fs_devices *find_fsid_changing_metada_uuid( return find_fsid(disk_super->fsid, disk_super->metadata_uuid); } +static struct btrfs_fs_devices *find_fsid_changing( + struct btrfs_super_block *disk_super) +{ + struct btrfs_fs_devices *fs_devices; + + /* + * Handles the case where scanned device is part of an fs that had + * multiple successful changes of FSID but currently device didn't + * observe it. + * Since the scanned devices does not own the metadata_uuid feature, + * fsid and metadata_uuid of the changing devices must differ, and + * their metadata_uuid must be same as disk_super->fsid. + */ + list_for_each_entry(fs_devices, &fs_uuids, fs_list) { + if (!fs_devices->fsid_change) + continue; + if (memcmp(fs_devices->fsid, fs_devices->metadata_uuid, + BTRFS_FSID_SIZE) != 0 && + memcmp(fs_devices->metadata_uuid, disk_super->fsid, + BTRFS_FSID_SIZE) == 0) + return fs_devices; + } + + /* + * Back to find newer fs_devices is changeing or some in same stage. + */ + return find_fsid(disk_super->fsid, NULL); +} + /* * Add new device to list of registered devices * @@ -782,7 +811,7 @@ static noinline struct btrfs_device *device_list_add(const char *path, } else if (has_metadata_uuid) { fs_devices = find_fsid_changing_metada_uuid(disk_super); } else { - fs_devices = find_fsid(disk_super->fsid, NULL); + fs_devices = find_fsid_changing(disk_super); } if (!fs_devices) { From patchwork Thu Dec 12 11:01:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Su Yue X-Patchwork-Id: 11287915 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ADB53138D for ; Thu, 12 Dec 2019 11:01:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8BAEC214D8 for ; Thu, 12 Dec 2019 11:01:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FLTlN9OM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728956AbfLLLBt (ORCPT ); Thu, 12 Dec 2019 06:01:49 -0500 Received: from mail-pj1-f67.google.com ([209.85.216.67]:40833 "EHLO mail-pj1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728871AbfLLLBt (ORCPT ); Thu, 12 Dec 2019 06:01:49 -0500 Received: by mail-pj1-f67.google.com with SMTP id s35so884758pjb.7 for ; Thu, 12 Dec 2019 03:01:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fOGXbamTK5rFzTs2n1dxg+HTJ06AVL9Ez7fnVK8dDno=; b=FLTlN9OMZlBCSw3B02KZ4SGfK2rWzHzOdmwYkSN8lZtFJdkLaYfHRSdNhJVZmaVxwp WvO6sr0oLRsaCByFn4Y5mPIk8hh+NXLA+LVR62AxP5S9YuPHo3n+Z4+9rwh1cxeWr/aE onA2X0HYIXOAN5ukV9PFR/xZiYuSTeO0BsSpfisHYbkKLqGA0RxRoFsQw/9AzrZ7e8PI uz9izCXykcqEeCD5hpeGKzmVjuJ1xSUY5y7r+/+5Kli7MCOTU0tSNam0QjJltDAa1lMt Am7RoRI3Oaboa41R4hi0Mz+tTzUsAShIZ7nvqjWCUnlO1N5axJ+MnY3eHv2oG7KPxRVh 9KPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fOGXbamTK5rFzTs2n1dxg+HTJ06AVL9Ez7fnVK8dDno=; b=PXVzjb/8F5iu++TNYTrkWgQZB8HRX2ANcaYSpBHtRA3fIQSRgXqdk2eenVqvBWO3hO 7+djWGxBH133AA392eN6vinVpkbUesgEVGSMjX6qd5zda4NorozDVQnzo5n7coCNjs6P kV0mDoGirnabySd9SFrx+jPGmoEbb5f0osWTnkqShPxG8RYSQ5V/fhUfxvwQEAsOYgs3 b8zmMwehwnyvKAZCmT5+Kev78thxbABQOlpp++U7Gzaz7pQk/PIQC3rq6QDDrEf1Nm5F ERdSpobncZ5kb3IpPm/PJ3meRbWHoIESLtI1MH6LZzzIEQgwJASE69NsntUSvDdaGxln v9/g== X-Gm-Message-State: APjAAAVWoqf+5Q1NbiT79VtxxrI02oWH3JjHmL2566vh/Q/Dej8TJnVx TJytPKgyq/6o7FmB8dRI7Ga14qTA1FM= X-Google-Smtp-Source: APXvYqxZQiB0sQ+oMqifTtfqAnKfRhhlOPS5kbtM8uCZOG5UBEEZ5ehik6u767pEBo+Aoe4GN0fg7g== X-Received: by 2002:a17:90a:30a4:: with SMTP id h33mr9154540pjb.50.1576148507895; Thu, 12 Dec 2019 03:01:47 -0800 (PST) Received: from p.lan ([45.58.38.246]) by smtp.gmail.com with ESMTPSA id w11sm6682387pfn.4.2019.12.12.03.01.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Dec 2019 03:01:47 -0800 (PST) From: damenly.su@gmail.com X-Google-Original-From: Damenly_Su@gmx.com To: linux-btrfs@vger.kernel.org Cc: Su Yue Subject: [PATCH 5/6] btrfs: copy fsid and metadata_uuid for pulled disk without INCOMPAT_METADATA_UUID Date: Thu, 12 Dec 2019 19:01:31 +0800 Message-Id: <20191212110132.11063-6-Damenly_Su@gmx.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122.2) In-Reply-To: <20191212110132.11063-1-Damenly_Su@gmx.com> References: <20191212110132.11063-1-Damenly_Su@gmx.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Su Yue Since a scanned device may be the device pulled into disk without metadata_uuid feature, there may already be changing devices there. Here copy fsid and metadata_uuid for above case. Signed-off-by: Su Yue --- fs/btrfs/volumes.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index faf9cdd14f33..b21ab45e76a0 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -964,13 +964,16 @@ static noinline struct btrfs_device *device_list_add(const char *path, * metadata_uuid/fsid values of the fs_devices. */ if (*new_device_added && fs_devices_found && - has_metadata_uuid && fs_devices->fsid_change && + fs_devices->fsid_change && found_transid > fs_devices->latest_generation) { memcpy(fs_devices->fsid, disk_super->fsid, BTRFS_FSID_SIZE); - memcpy(fs_devices->metadata_uuid, - disk_super->metadata_uuid, BTRFS_FSID_SIZE); - + if (has_metadata_uuid) + memcpy(fs_devices->metadata_uuid, + disk_super->metadata_uuid, BTRFS_FSID_SIZE); + else + memcpy(fs_devices->metadata_uuid, + disk_super->fsid, BTRFS_FSID_SIZE); fs_devices->fsid_change = false; } From patchwork Thu Dec 12 11:01:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Su Yue X-Patchwork-Id: 11287917 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C9BAC930 for ; Thu, 12 Dec 2019 11:01:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A7DFA214D8 for ; Thu, 12 Dec 2019 11:01:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Gimf+KjZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728959AbfLLLBw (ORCPT ); Thu, 12 Dec 2019 06:01:52 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:35945 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728871AbfLLLBv (ORCPT ); Thu, 12 Dec 2019 06:01:51 -0500 Received: by mail-pg1-f193.google.com with SMTP id k3so979822pgc.3 for ; Thu, 12 Dec 2019 03:01:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=59UI6eXW81Pq8dMMDIyUGxde96zaKk4qTYtmTH4SICs=; b=Gimf+KjZ+x2I3hrDKRvjL9NRVBeQeaEXfxY005vBVTE9sf7Dee71oWm5N6XgQpajPv lyY+vzkh2H+bbxZS++Ikle670+JkGwGxqz2P79/F5rowGpkzkEgvmuMOAyxZFgyFBVLj 8wmthCB8cwfc92qP04PNIF0dXmGh1qOhhP8vGwM8nmm+DmllCyTdbaCzlCcp36gdDZWG 5kZLFQBXJ4QBcRJYxO8NtJyGya+zzwB6xQIZw182Jy4n3GgeohrlxcEDYZm9OKBk8tPA tHSWev7aovRMgH231SBbwyIYjLKBFHoQt5SPjn1t/WcfP8NCQcW6lojHGJiD51i9iHUW oCmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=59UI6eXW81Pq8dMMDIyUGxde96zaKk4qTYtmTH4SICs=; b=uXEx31KGwfJGsTB5V38ltHQkZD/ZeNzN0L+vcmcB+L+b1uQIIw+rPvamEudRbuw+9u m26Id3S+Qxb5YWlYE0tyJ4KBEr5LaZCZfH/5d22+ccd9b5QDo/tWxEEJ8YEOPaVltpLB tIcqG3X/ZHJhWLKMHy9BlGq72ogZPX7TiZtsNafbbQLpBzZqJJIZFnpDoueM7HgLUrgw bt+IfwO8X8OJxMHDQlcH0eTE1jFcTUbWtE+N04/3SHmfW80pEfEORhmC9TdcPUM2Hy+H giBfpg1ZUzlEheEdKGE38JtXIRl4C07p6MimpykIme4GftRaohBKHvXnK4DDp0Vj8ER4 vbMA== X-Gm-Message-State: APjAAAUBIasJmwOe3iXpXJaapXJnpsVqljWknS/uNiU27OvxtdFM4pZw 1yh2YnSTOv3lrt40yRiGdcfxax1nMWA= X-Google-Smtp-Source: APXvYqzJFIsCU5dSuniUvj9qrK3GehpBE0E5sfw79LtvBWztALgOcgQknjXnTPh51x1CEF2MLaglEA== X-Received: by 2002:a63:fa04:: with SMTP id y4mr9785836pgh.413.1576148510307; Thu, 12 Dec 2019 03:01:50 -0800 (PST) Received: from p.lan ([45.58.38.246]) by smtp.gmail.com with ESMTPSA id w11sm6682387pfn.4.2019.12.12.03.01.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Dec 2019 03:01:49 -0800 (PST) From: damenly.su@gmail.com X-Google-Original-From: Damenly_Su@gmx.com To: linux-btrfs@vger.kernel.org Cc: Su Yue Subject: [PATCH 6/6] btrfs: metadata_uuid: move partly logic into find_fsid_inprogress() Date: Thu, 12 Dec 2019 19:01:32 +0800 Message-Id: <20191212110132.11063-7-Damenly_Su@gmx.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122.2) In-Reply-To: <20191212110132.11063-1-Damenly_Su@gmx.com> References: <20191212110132.11063-1-Damenly_Su@gmx.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Su Yue The partly logic can be moved into find_fsid_inprogress() to make code for fs_devices finding looks more elegant. Signed-off-by: Su Yue --- fs/btrfs/volumes.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index b21ab45e76a0..7e05f96b1575 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -636,6 +636,7 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices, /* * Handle scanned device having its CHANGING_FSID_V2 flag set and the fs_devices * being created with a disk that has already completed its fsid change. + * Or it might belong to fs with no UUID changes in effect, handle both. */ static struct btrfs_fs_devices *find_fsid_inprogress( struct btrfs_super_block *disk_super) @@ -651,7 +652,7 @@ static struct btrfs_fs_devices *find_fsid_inprogress( } } - return NULL; + return find_fsid(disk_super->fsid, NULL); } static struct btrfs_fs_devices *find_fsid_changed( @@ -795,19 +796,10 @@ static noinline struct btrfs_device *device_list_add(const char *path, *new_device_added = false; if (fsid_change_in_progress) { - if (!has_metadata_uuid) { - /* - * When we have an image which has CHANGING_FSID_V2 set - * it might belong to either a filesystem which has - * disks with completed fsid change or it might belong - * to fs with no UUID changes in effect, handle both. - */ + if (!has_metadata_uuid) fs_devices = find_fsid_inprogress(disk_super); - if (!fs_devices) - fs_devices = find_fsid(disk_super->fsid, NULL); - } else { + else fs_devices = find_fsid_changed(disk_super); - } } else if (has_metadata_uuid) { fs_devices = find_fsid_changing_metada_uuid(disk_super); } else {