为什么我在尝试挂​​载已卸载的文件系统时会出现“文件存在”错误?

为什么我在尝试挂​​载已卸载的文件系统时会出现“文件存在”错误?

非常感谢帮助。

我有一个热插拔 USB C 3.1 5 盘位存储设备(https://www.amazon.com/dp/B07VMK6ND7/ref=cm_sw_r_cp_taa_BETlFb399BQF4)连接到 Debian 盒子。

第 2 个托架是用于冗余的 4tb raid 1 镜像 btrfs,第三个设备是 luks/DM-crypt 备份驱动器,我与它交换,第四个设备用于异地备份。

真正的热插拔不适用于该主机控制器。我要做的就是通过卸载来关闭 2 个活动安装点(只是常规的,没有惰性或强制)。工作正常。我使用 hdparm 降低、停放和睡眠驱动器,然后为了更好地从内核中删除设备(如果我跳过此步骤,也会发生同样的情况)。我使用电源按钮关闭设备。然后我拿出我的驱动器。

第二天,我将另一个驱动器带回来,然后将其放入,打开驱动器电源,然后主要的 2 个 raid btrfs 被重新分配新的设备块(sda 到 sdc 等)。然后,我尝试挂载 raid 并收到“文件存在”错误,就像文件系统仍然挂载在某处,但事实并非如此。我已经向 smartd 发送了 SIGHUP,从内核中删除了设备,然后将它们扫描回来,但无济于事。

当然,重新启动可以解决所有问题,但这不是 Linux 处理此类问题的方式。这不像是内核升级。它只是比更换 USB 闪存驱动器更先进一点。

非常感谢您的想法。下面的 Bash 代码。

# lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:32   0  3.7T  0 disk /srv/dev-disk-by-id-usb-External_USB3.0_DISK01_20170331000C3-0-1/
sdb           8:48   0  3.7T  0 disk
sdc           8:64   0  3.7T  0 disk
mmcblk0     179:0    0 29.7G  0 disk
├─mmcblk0p1 179:1    0  256M  0 part /boot
└─mmcblk0p2 179:2    0 29.5G  0 part /

# umount /dev/sda
# lsblk
lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:32   0  3.7T  0 disk
sdb           8:48   0  3.7T  0 disk
sdc           8:64   0  3.7T  0 disk
mmcblk0     179:0    0 29.7G  0 disk
├─mmcblk0p1 179:1    0  256M  0 part /boot
└─mmcblk0p2 179:2    0 29.5G  0 part /

# hdparm -y /dev/sd*
... (completes without error)
# echo 1 > /sys/block/sd*/device/delete
... (completes without error)

在这里,我关闭设备电源并更换备份驱动器,然后重新启动。

# pkill -SIGHUP smartd
... (completes without error)

# lsblk 
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sdc           8:32   0  3.7T  0 disk
sdd           8:48   0  3.7T  0 disk
sde           8:64   0  3.7T  0 disk
mmcblk0     179:0    0 29.7G  0 disk
├─mmcblk0p1 179:1    0  256M  0 part /boot
└─mmcblk0p2 179:2    0 29.5G  0 part /

# mount | grep sd # no /dev/sd* mounted anywhere
cgroup2 on /sys/fs/cgroup/unified type cgroup2 (rw,nosuid,nodev,noexec,relatime,nsdelegate)
nfsd on /proc/fs/nfsd type nfsd (rw,relatime)

# mount /dev/sdc /mnt/backup
mount: /mnt/backup: mount(2) system call failed: File exists
# 
# hdparm -y /dev/sd*
... (completes without error)
# echo 1 > /sys/block/sd*/device/delete
... (completes without error)
# pkill -SIGHUP smartd
# lsblk               
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
mmcblk0     179:0    0 29.7G  0 disk
├─mmcblk0p1 179:1    0  256M  0 part /boot
└─mmcblk0p2 179:2    0 29.5G  0 part /
# echo "- - -" > /sys/class/scsi_host/host1/scan
# lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sdc           8:32   0  3.7T  0 disk
sdd           8:48   0  3.7T  0 disk
sde           8:64   0  3.7T  0 disk
mmcblk0     179:0    0 29.7G  0 disk
├─mmcblk0p1 179:1    0  256M  0 part /boot
└─mmcblk0p2 179:2    0 29.5G  0 part /
# mount /dev/sdc /mnt/backup
mount: /mnt/backup: mount(2) system call failed: File exists
# dmesg -T | tail -n40
[Fri Aug  7 23:39:08 2020] sd 1:0:0:2: [sde] Attached SCSI disk
[Fri Aug  7 23:39:08 2020] BTRFS warning (device sda): duplicate device fsid:devid for f4cbf27f-8fb6-48be-87a3-d42023ab2eb7:2 old:/dev/sdb new:/dev/sdd
[Fri Aug  7 23:39:08 2020] BTRFS warning (device sda): duplicate device fsid:devid for f4cbf27f-8fb6-48be-87a3-d42023ab2eb7:2 old:/dev/sdb new:/dev/sdd
[Fri Aug  7 23:39:08 2020] BTRFS warning (device sda): duplicate device fsid:devid for f4cbf27f-8fb6-48be-87a3-d42023ab2eb7:1 old:/dev/sda new:/dev/sdc
[Sat Aug  8 11:28:05 2020] BTRFS warning (device sda): duplicate device fsid:devid for f4cbf27f-8fb6-48be-87a3-d42023ab2eb7:1 old:/dev/sda new:/dev/sdc
[Sat Aug  8 18:59:57 2020] BTRFS error (device sda): bdev /dev/sdb errs: wr 1, rd 0, flush 0, corrupt 0, gen 0
[Sat Aug  8 18:59:57 2020] BTRFS error (device sda): bdev /dev/sda errs: wr 1, rd 0, flush 0, corrupt 0, gen 0
[Sat Aug  8 18:59:57 2020] BTRFS error (device sda): bdev /dev/sdb errs: wr 2, rd 0, flush 0, corrupt 0, gen 0
[Sat Aug  8 18:59:57 2020] BTRFS error (device sda): bdev /dev/sda errs: wr 2, rd 0, flush 0, corrupt 0, gen 0
[Sat Aug  8 18:59:57 2020] BTRFS error (device sda): bdev /dev/sdb errs: wr 3, rd 0, flush 0, corrupt 0, gen 0
[Sat Aug  8 18:59:57 2020] BTRFS error (device sda): bdev /dev/sda errs: wr 3, rd 0, flush 0, corrupt 0, gen 0
[Sat Aug  8 18:59:57 2020] BTRFS error (device sda): bdev /dev/sdb errs: wr 4, rd 0, flush 0, corrupt 0, gen 0
[Sat Aug  8 18:59:57 2020] BTRFS error (device sda): bdev /dev/sda errs: wr 4, rd 0, flush 0, corrupt 0, gen 0
[Sat Aug  8 18:59:57 2020] BTRFS error (device sda): bdev /dev/sdb errs: wr 5, rd 0, flush 0, corrupt 0, gen 0
[Sat Aug  8 18:59:57 2020] BTRFS error (device sda): bdev /dev/sda errs: wr 5, rd 0, flush 0, corrupt 0, gen 0
[Sat Aug  8 18:59:57 2020] BTRFS: error (device sda) in btrfs_commit_transaction:2268: errno=-5 IO failure (Error while writing out transaction)
[Sat Aug  8 18:59:57 2020] BTRFS info (device sda): forced readonly
[Sat Aug  8 18:59:57 2020] BTRFS warning (device sda): Skipping commit of aborted transaction.
[Sat Aug  8 18:59:57 2020] BTRFS: error (device sda) in cleanup_transaction:1860: errno=-5 IO failure
[Sat Aug  8 18:59:57 2020] BTRFS info (device sda): delayed_refs has NO entry
[Sun Aug  9 18:10:24 2020] usb 2-1: new SuperSpeed Gen 1 USB device number 4 using xhci_hcd
[Sun Aug  9 18:10:24 2020] usb 2-1: New USB device found, idVendor=174c, idProduct=55aa, bcdDevice= 1.00
[Sun Aug  9 18:10:24 2020] usb 2-1: New USB device strings: Mfr=2, Product=3, SerialNumber=1
[Sun Aug  9 18:10:24 2020] usb 2-1: Product: Ugreen Storage Device
[Sun Aug  9 18:10:24 2020] usb 2-1: Manufacturer: Ugreen
[Sun Aug  9 18:10:24 2020] usb 2-1: SerialNumber: 093458F298A9
[Sun Aug  9 18:10:24 2020] scsi host2: uas
[Sun Aug  9 18:10:24 2020] scsi 2:0:0:0: Direct-Access     KINGSTON  SA400M8120G     0    PQ: 0 ANSI: 6
[Sun Aug  9 18:10:24 2020] sd 2:0:0:0: [sdf] 234441648 512-byte logical blocks: (120 GB/112 GiB)
[Sun Aug  9 18:10:24 2020] sd 2:0:0:0: [sdf] Write Protect is off
[Sun Aug  9 18:10:24 2020] sd 2:0:0:0: [sdf] Mode Sense: 43 00 00 00
[Sun Aug  9 18:10:24 2020] sd 2:0:0:0: [sdf] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[Sun Aug  9 18:10:24 2020] sd 2:0:0:0: Attached scsi generic sg3 type 0
[Sun Aug  9 18:10:24 2020] sd 2:0:0:0: [sdf] Optimal transfer size 33553920 bytes
[Sun Aug  9 18:10:24 2020]  sdf: sdf1
[Sun Aug  9 18:10:24 2020] sd 2:0:0:0: [sdf] Attached SCSI disk
[Sun Aug  9 18:20:06 2020] BTRFS warning (device sda): duplicate device fsid:devid for f4cbf27f-8fb6-48be-87a3-d42023ab2eb7:1 old:/dev/sda new:/dev/sdc
[Sun Aug  9 18:22:34 2020] BTRFS warning (device sda): duplicate device fsid:devid for f4cbf27f-8fb6-48be-87a3-d42023ab2eb7:1 old:/dev/sda new:/dev/sdc
[Sun Aug  9 18:22:55 2020] BTRFS warning (device sda): duplicate device fsid:devid for f4cbf27f-8fb6-48be-87a3-d42023ab2eb7:1 old:/dev/sda new:/dev/sdc
[Sun Aug  9 18:23:25 2020] BTRFS warning (device sda): duplicate device fsid:devid for f4cbf27f-8fb6-48be-87a3-d42023ab2eb7:1 old:/dev/sda new:/dev/sdc

对于 strace,请参阅https://pastebin.com/UBhccxxY

答案1

这是因为 BTRFS 缓存了有关设备文件系统(特别是 UUID)的一些信息。当 BTRFS 设备出现在不同的设备节点时,内核模块会感到困惑,因为 UUID 不再符合其应有的想法。如果您btrfs device scan --forget在尝试挂载之前运行,它将导致内核删除有关所有过时文件系统的信息。看btrfs 设备手册页在“扫描”子命令下。

相关内容