在我开发项目出现有时插拔tf,内核打印如下错误提示:
/dev/mmcblk0p1 on /mnt/mmcblk0p1 type ext4 (rw,relatime,data=ordered)
root@LeWiFi:~# mount /dev/mmcblk0p2 /mnt/mmcblk0p2
[ 1463.152000] EXT4-fs (mmcblk0p2): couldn't mount as ext3 due to feature incompatibilities
[ 1463.160000] EXT4-fs (mmcblk0p2): couldn't mount as ext2 due to feature incompatibilities
[ 1463.172000] ------------[ cut here ]------------
[ 1463.176000] n+0x154/0x1b0()
[ 1463.184000] proc_dir_entry 'ext4/mmcblk0p2' already registered
[ 1463.188000] Modules linked in: mt7603e(O) mt76x2e(O) iptable_nat xt_CHAOS(O) nf_nat_ipv4 nf_conntrack_ipv4 ipt_MASQUERADE xt_u32 xt_time xt_tcpudp xt_tcpmss xt_string xt_statistic xt_state xt_socket xt_recent xt_quota2(O) xt_quota xt_psd(O) xt_pkttype xt_owner xt_nat xt_multiport xt_mark xt_mac xt_lscan(O) xt_limit xt_length2(O) xt_length xt_layer7 xt_ipv4options(O) xt_iprange xt_ipp2p(O) xt_iface(O) xt_hl xt_helper xt_hashlimit xt_geoip(O) xt_fuzzy(O) xt_esp xt_ecn xt_dscp xt_conntrack xt_connmark xt_connlimit xt_connbytes xt_condition(O) xt_comment xt_addrtype xt_TPROXY xt_TEE xt_TCPMSS xt_TARPIT(O) xt_SYSRQ(O) xt_STEAL(O) xt_REDIRECT xt_RAWNAT(O) xt_NFQUEUE xt_NFLOG xt_NETMAP xt_LUA(O) xt_LOGMARK(O) xt_LOG xt_IPMARK(O) xt_HL xt_DSCP xt_DNETMAP(O) xt_DHCPMAC(O) xt_DELUDE(O) xt_CT xt_CLASSIFY xt_ACCOUNT(O) ts_kmp ts_fsm ts_bm ralink_wdt qcserial nfnetlink_queue nfnetlink_log nf_tproxy_core nf_nat nf_defrag_ipv4 _ppp iptable_raw iptable_mangle iptable_filter ipt_ah ipt_ULOG ipt_REJECT ipt_ECN compat_xtables(O) cdc_eem arptable_filter arpt_mangle arp_tables act_skbedit act_mirred em_u32 cls_u32 cls_tcindex cls_flow cls_route cls_fw sch_hfsc sch_ingress xt_set(O) ip_set_list_set(O) ip_set_hash_netport(O) ip_set_hash_netiface(O) ip_set_hash_net(O) ip_set_hash_ipportnet(O) ip_set_hash_ipportip(O) ip_set_hash_ipport(O) ip_set_hash_ip(O) ip_set_bitmap_port(O) ip_set_bitmap_ipmac(O) ip_set_bitmap_ip(O) ip_set(O) nfnetlink ip6t_REJECT ip6table_raw ip6table_mangle ip6table_filter ip6_tables nf_conntrack_ipv6 nf_conntrack ip_tables x_tables nf_defrag_ipv6 pppoatm ip_gre gre _netlink _core ip_tunnel tun autofs4 br2684 atm sdhci_pltfm sdhci uhci_hcd ohci_hcd [last unloaded: mt76x2e]
[ 1463.336000] CPU: 2 PID: 23540 Comm: mount Tainted: G W O 3.10.14 #49
[ 1463.344000] Stack : 80644072 00000040 00005bf4 00000002 8057398c 00000040 8056900c 805e5d27
00005bf4 00000002 80643818 9ad3a670 00008000 9afad400 99c23d00 804b4c9c
805f18d0 8002a910 00000003 00000000 8056ad64 99c23a8c 99c23a8c 8056900c
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 99c23a20
...
[ 1463.380000] Call Trace:
[ 1463.384000] [<8000aec0>] show_stack+0x64/0x7c
[ 1463.388000] [<8002aab4>] warn_slowpath_common+0x78/0xa8
[ 1463.392000] [<8002ab10>] warn_slowpath_fmt+0x2c/0x38
[ 1463.396000] [<80126750>] proc_register+0x154/0x1b0
[ 1463.404000] [<801268c8>] proc_mkdir_data+0x54/0x84
[ 1463.408000] [<80156128>] ext4_fill_super+0x13a0/0x31ac
[ 1463.412000]
[ 1463.412000] ---[ end trace 0e3500c4db498654 ]---
[ 1463.420000] ------------[ cut here ]------------
[ 1463.424000] WARNING: at fs/proc/generic.c:356 proc_register+0x154/0x1b0()
[ 1463.432000] proc_dir_entry 'jbd2/mmcblk0p2-8' already registered
[ 1463.440000] Modules linked in: mt7603e(O) mt76x2e(O) iptable_nat xt_CHAOS(O) nf_nat_ipv4 nf_conntrack_ipv4 ipt_MASQUERADE xt_u32 xt_time xt_tcpudp xt_tcpmss xt_string xt_statistic xt_state xt_socket xt_recent xt_quota2(O) xt_quota xt_psd(O) xt_pkttype xt_owner xt_nat xt_multiport xt_mark xt_mac xt_lscan(O) xt_limit xt_length2(O) xt_length xt_layer7 xt_ipv4options(O) xt_iprange xt_ipp2p(O) xt_iface(O) xt_hl xt_helper xt_hashlimit xt_geoip(O) xt_fuzzy(O) xt_esp xt_ecn xt_dscp xt_conntrack xt_connmark xt_connlimit xt_connbytes xt_condition(O) xt_comment xt_addrtype xt_TPROXY xt_TEE xt_TCPMSS xt_TARPIT(O) xt_SYSRQ(O) xt_STEAL(O) xt_REDIRECT xt_RAWNAT(O) xt_NFQUEUE xt_NFLOG xt_NETMAP xt_LUA(O) xt_LOGMARK(O) xt_LOG xt_IPMARK(O) xt_HL xt_DSCP xt_DNETMAP(O) xt_DHCPMAC(O) xt_DELUDE(O) xt_CT xt_CLASSIFY xt_ACCOUNT(O) ts_kmp ts_fsm ts_bm ralink_wdt qcserial nfnetlink_queue nfnetlink_log nf_tproxy_core nf_nat nf_defrag_ipv4 _ppp iptable_raw iptable_mangle iptable_filter ipt_ah ipt_ULOG ipt_REJECT ipt_ECN compat_xtables(O) cdc_eem arptable_filter arpt_mangle arp_tables act_skbedit act_mirred em_u32 cls_u32 cls_tcindex cls_flow cls_route cls_fw sch_hfsc sch_ingress xt_set(O) ip_set_list_set(O) ip_set_hash_netport(O) ip_set_hash_netiface(O) ip_set_hash_net(O) ip_set_hash_ipportnet(O) ip_set_hash_ipportip(O) ip_set_hash_ipport(O) ip_set_hash_ip(O) ip_set_bitmap_port(O) ip_set_bitmap_ipmac(O) ip_set_bitmap_ip(O) ip_set(O) nfnetlink ip6t_REJECT ip6table_raw ip6table_mangle ip6table_filter ip6_tables nf_conntrack_ipv6 nf_conntrack ip_tables x_tables nf_defrag_ipv6 pppoatm ip_gre gre _netlink _core ip_tunnel tun autofs4 br2684 atm sdhci_pltfm sdhci uhci_hcd ohci_hcd [last unloaded: mt76x2e]
[ 1463.588000] CPU: 2 PID: 23540 Comm: mount Tainted: G W O 3.10.14 #49
[ 1463.596000] Stack : 80644072 00000040 00005bf4 00000002 8057398c 00000040 8056900c 805e5d27
00005bf4 00000002 80643818 9ad3a670 00000000 9b9a4860 99c23d00 804b4c9c
805f18d0 8002a910 00000003 00000000 8056ad64 99c23a34 99c23a34 8056900c
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 99c239c8
...
[ 1463.632000] Call Trace:
[ 1463.636000] [<8000aec0>] show_stack+0x64/0x7c
[ 1463.640000] [<8002aab4>] warn_slowpath_common+0x78/0xa8
[ 1463.644000] [<8002ab10>] warn_slowpath_fmt+0x2c/0x38
[ 1463.648000] [<80126750>] proc_register+0x154/0x1b0
[ 1463.652000] [<801268c8>] proc_mkdir_data+0x54/0x84
[ 1463.660000] [<8018a484>] jbd2_stats_proc_init+0x20/0x58
[ 1463.664000] [<8018cf20>] jbd2_journal_init_inode+0xd8/0x1d8
[ 1463.668000] [<801570bc>] ext4_fill_super+0x2334/0x31ac
[ 1463.676000]
[ 1463.676000] ---[ end trace 0e3500c4db498655 ]---
[ 1463.688000] ------------[ cut here ]------------
[ 1463.692000] WARNING: at fs/sysfs/dir.c:530 sysfs_add_one+0xbc/0xec()
[ 1463.696000] sysfs: cannot create duplicate filename '/fs/ext4/mmcblk0p2'
[ 1463.704000] Modules linked in: mt7603e(O) mt76x2e(O) iptable_nat xt_CHAOS(O) nf_nat_ipv4 nf_conntrack_ipv4 ipt_MASQUERADE xt_u32 xt_time xt_tcpudp xt_tcpmss xt_string xt_statistic xt_state xt_socket xt_recent xt_quota2(O) xt_quota xt_psd(O) xt_pkttype xt_owner xt_nat xt_multiport xt_mark xt_mac xt_lscan(O) xt_limit xt_length2(O) xt_length xt_layer7 xt_ipv4options(O) xt_iprange xt_ipp2p(O) xt_iface(O) xt_hl xt_helper xt_hashlimit xt_geoip(O) xt_fuzzy(O) xt_esp xt_ecn xt_dscp xt_conntrack xt_connmark xt_connlimit xt_connbytes xt_condition(O) xt_comment xt_addrtype xt_TPROXY xt_TEE xt_TCPMSS xt_TARPIT(O) xt_SYSRQ(O) xt_STEAL(O) xt_REDIRECT xt_RAWNAT(O) xt_NFQUEUE xt_NFLOG xt_NETMAP xt_LUA(O) xt_LOGMARK(O) xt_LOG xt_IPMARK(O) xt_HL xt_DSCP xt_DNETMAP(O) xt_DHCPMAC(O) xt_DELUDE(O) xt_CT xt_CLASSIFY xt_ACCOUNT(O) ts_kmp ts_fsm ts_bm ralink_wdt qcserial nfnetlink_queue nfnetlink_log nf_tproxy_core nf_nat nf_defrag_ipv4 _ppp iptable_raw iptable_mangle iptable_filter ipt_ah ipt_ULOG ipt_REJECT ipt_ECN compat_xtables(O) cdc_eem arptable_filter arpt_mangle arp_tables act_skbedit act_mirred em_u32 cls_u32 cls_tcindex cls_flow cls_route cls_fw sch_hfsc sch_ingress xt_set(O) ip_set_list_set(O) ip_set_hash_netport(O) ip_set_hash_netiface(O) ip_set_hash_net(O) ip_set_hash_ipportnet(O) ip_set_hash_ipportip(O) ip_set_hash_ipport(O) ip_set_hash_ip(O) ip_set_bitmap_port(O) ip_set_bitmap_ipmac(O) ip_set_bitmap_ip(O) ip_set(O) nfnetlink ip6t_REJECT ip6table_raw ip6table_mangle ip6table_filter ip6_tables nf_conntrack_ipv6 nf_conntrack ip_tables x_tables nf_defrag_ipv6 pppoatm ip_gre gre _netlink _core ip_tunnel tun autofs4 br2684 atm sdhci_pltfm sdhci uhci_hcd ohci_hcd [last unloaded: mt76x2e]
[ 1463.856000] CPU: 2 PID: 23540 Comm: mount Tainted: G W O 3.10.14 #49
[ 1463.864000] Stack : 80644072 00000040 00005bf4 00000002 80574530 00000040 8056900c 805e5d27
00005bf4 00000002 80643818 9ad3a670 00000000 00001000 99c23d00 804b4c9c
805f18d0 8002a910 00000003 00000000 8056ad64 99c239d4 99c239d4 8056900c
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 99c23968
...
[ 1463.900000] Call Trace:
[ 1463.904000] [<8000aec0>] show_stack+0x64/0x7c
[ 1463.908000] [<8002aab4>] warn_slowpath_common+0x78/0xa8
[ 1463.912000] [<8002ab10>] warn_slowpath_fmt+0x2c/0x38
[ 1463.916000] [<80132324>] sysfs_add_one+0xbc/0xec
[ 1463.920000] [<801325e4>] create_dir+0x74/0x148
[ 1463.924000] [<80132ba8>] sysfs_create_dir+0xa8/0x108
[ 1463.932000] [<80271f60>] kobject_add_internal+0xa8/0x244
[ 1463.936000] [<80272474>] kobject_init_and_add+0x50/0x7c
[ 1463.940000] [<80157b34>] ext4_fill_super+0x2dac/0x31ac
[ 1463.948000]
[ 1463.948000] ---[ end trace 0e3500c4db498656 ]---
[ 1463.952000] ------------[ cut here ]------------
[ 1463.956000] WARNING: at lib/kobject.c:196 kobject_add_internal+0x234/0x244()
[ 1463.964000] kobject_add_internal failed for mmcblk0p2 with -EEXIST, don't try to register things with the same name in the same directory.
[ 1463.976000] Modules linked in: mt7603e(O) mt76x2e(O) iptable_nat xt_CHAOS(O) nf_nat_ipv4 nf_conntrack_ipv4 ipt_MASQUERADE xt_u32 xt_time xt_tcpudp xt_tcpmss xt_string xt_statistic xt_state xt_socket xt_recent xt_quota2(O) xt_quota xt_psd(O) xt_pkttype xt_owner xt_nat xt_multiport xt_mark xt_mac xt_lscan(O) xt_limit xt_length2(O) xt_length xt_layer7 xt_ipv4options(O) xt_iprange xt_ipp2p(O) xt_iface(O) xt_hl xt_helper xt_hashlimit xt_geoip(O) xt_fuzzy(O) xt_esp xt_ecn xt_dscp xt_conntrack xt_connmark xt_connlimit xt_connbytes xt_condition(O) xt_comment xt_addrtype xt_TPROXY xt_TEE xt_TCPMSS xt_TARPIT(O) xt_SYSRQ(O) xt_STEAL(O) xt_REDIRECT xt_RAWNAT(O) xt_NFQUEUE xt_NFLOG xt_NETMAP xt_LUA(O) xt_LOGMARK(O) xt_LOG xt_IPMARK(O) xt_HL xt_DSCP xt_DNETMAP(O) xt_DHCPMAC(O) xt_DELUDE(O) xt_CT xt_CLASSIFY xt_ACCOUNT(O) ts_kmp ts_fsm ts_bm ralink_wdt qcserial nfnetlink_queue nfnetlink_log nf_tproxy_core nf_nat nf_defrag_ipv4 _ppp iptable_raw iptable_mangle iptable_filter ipt_ah ipt_ULOG ipt_REJECT ipt_ECN compat_xtables(O) cdc_eem arptable_filter arpt_mangle arp_tables act_skbedit act_mirred em_u32 cls_u32 cls_tcindex cls_flow cls_route cls_fw sch_hfsc sch_ingress xt_set(O) ip_set_list_set(O) ip_set_hash_netport(O) ip_set_hash_netiface(O) ip_set_hash_net(O) ip_set_hash_ipportnet(O) ip_set_hash_ipportip(O) ip_set_hash_ipport(O) ip_set_hash_ip(O) ip_set_bitmap_port(O) ip_set_bitmap_ipmac(O) ip_set_bitmap_ip(O) ip_set(O) nfnetlink ip6t_REJECT ip6table_raw ip6table_mangle ip6table_filter ip6_tables nf_conntrack_ipv6 nf_conntrack ip_tables x_tables nf_defrag_ipv6 pppoatm ip_gre gre _netlink _core ip_tunnel tun autofs4 br2684 atm sdhci_pltfm sdhci uhci_hcd ohci_hcd [last unloaded: mt76x2e]
[ 1464.128000] CPU: 2 PID: 23540 Comm: mount Tainted: G W O 3.10.14 #49
[ 1464.136000] Stack : 80644072 00000040 00005bf4 00000002 805914dc 00000040 8056900c 805e5d27
00005bf4 00000002 80643818 9ad3a670 00000000 00001000 99c23d00 804b4c9c
805f18d0 8002a910 00000003 00000000 8056ad64 99c23a6c 99c23a6c 8056900c
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000 00000000 99c23a00
...
[ 1464.172000] Call Trace:
[ 1464.172000] [<8000aec0>] show_stack+0x64/0x7c
[ 1464.176000] [<8002aab4>] warn_slowpath_common+0x78/0xa8
[ 1464.184000] [<8002ab10>] warn_slowpath_fmt+0x2c/0x38
[ 1464.188000] [<802720ec>] kobject_add_internal+0x234/0x244
[ 1464.192000] [<80272474>] kobject_init_and_add+0x50/0x7c
[ 1464.196000] [<80157b34>] ext4_fill_super+0x2dac/0x31ac
[ 1464.204000]
[ 1464.204000] ---[ end trace 0e3500c4db498657 ]---
[ 1464.208000] EXT4-fs (mmcblk0p2): mount failed
根本原因:Linux内核对文件系统目录和文件路径进行了缓冲(加快文件浏览速度)。在拔除TF卡时候没有把他umnount掉导致内核没有release资源。
过 程:
对于sd/mmc/tf卡,设备和挂载点是固定的。对应关系如下:
/dev/mmcblk0p1 /mnt/mmcblk0p1
/dev/mmcblk0p2 /mnt/mmcblk0p2
/dev/mmcblk0px /mnt/mmcblk0px
成功挂载设备自动生成proc资源。
/proc/fs/ext4/mmcblk0p1
/proc/fs/ext4/mmcblk0p2
/proc/fs/ext4/mmcblk0px
在拔除TF卡时候,不umnount,导致内核没有release资源
/dev/mmcblk0p1及/proc/fs/ext4/mmcblk0p1
/dev/mmcblk0p2及/proc/fs/ext4/mmcblk0p2
/dev/mmcblk0px及/proc/fs/ext4/mmcblk0px
但是拔除TF卡后,umount总是失败。再次跟踪,是因为一个进程打开了TF文件,导致内核一直保留该文件handle;
而umount时内核要同步文件,同步失败导致umount失败。我把该进程kill掉,再次umount ok。再次插入sd/mmc/tf卡正常自动mount。
解决办法:为了解决这个问题。启动一个后台服务,检测到卡拔出后,关闭打开TF文件的进程,umount卡的挂载点。后续插入sd/mmc/tf卡即正常mount。
延 伸:为什么USB磁盘插拔无这个问题呢?那是因为对于USB磁盘,内核如果发现某个设备/dev/sdax被占用,
会自动向后使用设备/dev/sdbx作为驱动设备。它的驱动设备不是固定的。