Symlink
為什麼 udev 連接兩個符號連結?
我的發行版是 SLES 12 SP 2。
我現在使用 DRBD(分佈式複制塊設備)。下面是一個 drbd 資源的配置範例。
resource HA1dat { device /dev/drbd1; disk /dev/mqdat/HA1; meta-disk internal; on srv0 { address 192.168.174.10:7000; node-id 0; } on srv1 { address 192.168.174.11:7000; node-id 1; } on srv9 { address 192.168.174.19:7000; node-id 2; } connection-mesh { hosts srv0 srv1 srv9; } }
將此資源啟動為 drbd 設備後,通常會創建以下對象。
brw-rw---- 1 root disk 147, 1 Feb 13 19:41 /dev/drbd1 lrwxrwxrwx 1 root root 14 Feb 13 19:41 /dev/drbd/by-res/HA1dat/0 -> ../../../drbd1 lrwxrwxrwx 1 root root 14 Feb 13 19:41 /dev/drbd/by-disk/mqdat/HA1 -> ../../../drbd1
這些是塊設備本身和指向它的兩個符號連結。
這是正確的行為!
在其他一些伺服器(相同的分佈)上,行為是不同的。drbd 資源的配置非常相似。
resource LN0N001Edat { device /dev/drbd1; disk /dev/data1vg/LN0N001E_lv; meta-disk internal; on sedcmmwd0030 { address xxx.yyy.zzz.83:7000; node-id 0; } on sedcmmwd0040 { address xxx.yyy.zzz.99:7000; node-id 1; } on sedcmmwd0050 { address xxx.yyy.zzz.100:7000; node-id 2; } connection-mesh { hosts sedcmmwd0030 sedcmmwd0040 sedcmmwd0050; } }
啟動此資源後,僅創建塊設備和一個連結。
brw-rw---- 1 root disk 147, 1 Mar 2 09:49 /dev/drbd1 lrwxrwxrwx 1 root root 23 Mar 2 09:49 /dev/drbd/by-res/LN0N001Edat/0_drbd/by-disk/data1vg/LN0N001E_lv -> ../../../../../../drbd1
這就是問題!此連結是兩個預期連結的串聯。我不知道,為什麼它們被連接起來。
該連結由 udev 創建。以下輸出顯示了 udev 在這些節點上所做的差異。
行為正確的伺服器
juser@srv0:~> udevadm info /dev/drbd1 P: /devices/virtual/block/drbd1 N: drbd1 S: drbd/by-disk/mqdat/HA1 S: drbd/by-res/HA1dat/0 E: DEVICE=drbd1 E: DEVLINKS=/dev/drbd/by-res/HA1dat/0 /dev/drbd/by-disk/mqdat/HA1 E: DEVNAME=/dev/drbd1 E: DEVPATH=/devices/virtual/block/drbd1 E: DEVTYPE=disk E: MAJOR=147 E: MINOR=1 E: SUBSYSTEM=block E: SYMLINK=drbd/by-res/HA1dat/0 drbd/by-disk/mqdat/HA1 E: TAGS=:systemd: E: USEC_INITIALIZED=12263844870
有問題的伺服器
root@sedcmmwd0030:/root : udevadm info /dev/drbd1 P: /devices/virtual/block/drbd1 N: drbd1 S: drbd/by-res/LN0N001Edat/0_drbd/by-disk/data1vg/LN0N001E_lv E: DEVICE=drbd1 E: DEVLINKS=/dev/drbd/by-res/LN0N001Edat/0_drbd/by-disk/data1vg/LN0N001E_lv E: DEVNAME=/dev/drbd1 E: DEVPATH=/devices/virtual/block/drbd1 E: DEVTYPE=disk E: MAJOR=147 E: MINOR=1 E: SUBSYSTEM=block E: SYMLINK=drbd/by-res/LN0N001Edat/0 drbd/by-disk/data1vg/LN0N001E_lv E: TAGS=:systemd: E: USEC_INITIALIZED=1212108486973
SYMLINK 行仍然是正確的。差異從 DEVLINKS 行開始。
在這兩種情況下,drbd 的規則是相同的 cat /usr/lib/udev/rules.d/65-drbd.rules # 此文件包含創建命名 DRBD 設備的規則。
SUBSYSTEM!="block", GOTO="drbd_end" KERNEL!="drbd*", GOTO="drbd_end" IMPORT{program}="/sbin/drbdadm sh-udev minor-%m" # Use symlink from the environment if available ENV{SYMLINK}!="", SYMLINK="$env{SYMLINK}", GOTO="have_symlink" # Legacy rules for older DRBD 8.3 & 8.4 when drbdadm sh-udev did not yet export SYMLINK ENV{DISK}!="", SYMLINK+="drbd/by-disk/$env{DISK}" ENV{RESOURCE}!="", SYMLINK+="drbd/by-res/$env{RESOURCE}" LABEL="have_symlink" ENV{DEVICE}=="drbd_?*", SYMLINK+="$env{DEVICE}" LABEL="drbd_end"
有人對錯誤連結的創建有解釋嗎?
DRBD 的 udev 規則來自 drbd-utils。您安裝了哪個版本的 DRBD 實用程序?
最新版本 9.2.2 包含附加規則以及來自開發人員的評論,看起來它可能會解決您的問題:
# This file contains the rules to create named DRBD devices. SUBSYSTEM!="block", GOTO="drbd_end" KERNEL!="drbd*", GOTO="drbd_end" IMPORT{program}="@sbindir@/drbdadm sh-udev minor-%m" # Use symlink from the environment if available # some udev version thought it was a good idea to change a long established # default of string_escape=none to string_escape=replace :-/ # therefore, recent enough drbdadm will no longer export space separated lists. ENV{SYMLINK_BY_DISK}!="", SYMLINK+="$env{SYMLINK_BY_DISK}" ENV{SYMLINK_BY_RES}!="", SYMLINK+="$env{SYMLINK_BY_RES}", GOTO="have_symlink" ENV{SYMLINK}!="", OPTIONS+="string_escape=none", SYMLINK="$env{SYMLINK}", GOTO="have_symlink" # Legacy rules for older DRBD 8.3 & 8.4 when drbdadm sh-udev did not yet export SYMLINK ENV{DISK}!="", SYMLINK+="drbd/by-disk/$env{DISK}" ENV{RESOURCE}!="", SYMLINK+="drbd/by-res/$env{RESOURCE}" LABEL="have_symlink" ENV{DEVICE}=="drbd_?*", SYMLINK+="$env{DEVICE}" LABEL="drbd_end"