LVM + lvmlockd (clvm replacement)
source code
1 | https://sourceware.org/git/?p=lvm2.git |
🚨prepare
❗操作之后需要把之前冗余的
activate的 lv 都设置成inactive1
2
3
4
5flite
lvscan | grep '/csi-lvm/' | grep -v inactive
deactivate duplicate pv
lvchange -an /dev/csi-lvm/pvc-xxx
install
1 | sanlock and lvmlocked |
lvmlocked
enable locked
1
2vim /etc/lvm/lvm.conf
use_lvmlockd = 1check
1
lvmconfig --type current global/use_lvmlockd
restart lvmlockd
1
systemctl restart lvmlockd
sanlock
config host id
1
2
3
4
5vim /etc/lvm/lvmlocal.conf
local {
# Replace <nodeNum> with the unique integer for this node (e.g., 1, 2, 3...)
host_id = <nodeNum>
}Restart
1
2
3systemctl restart sanlock
sleep 8
systemctl restart lvmlockd
first node
Convert VG to sanlock
config sanlock
1
(optional) lvchange -an csi-lvm
skip global lockspace
1
2
3
4
5
6
7vgchange --lock-type sanlock --lockopt skipgl csi-lvm
print
WARNING: skipping global lock in lvmlockd.
Logical volume "lvmlock" created.
device-mapper: remove ioctl on (253:9) failed: Device or resource busy
Volume group "csi-lvm" successfully changed
Start the Lockspace
Activate the lockspace for newly converted VG.This allows the local lvmlockd to manage it.
1 | vgchange --lock-start csi-lvm |
Enable the Global Lock
1 | enable |
other node
Start the Lockspace
1 | vgchange --lock-start csi-lvm |
init lock
1 | lvcreate -L 10G -n lv-temp-1 csi-lvm |
best practices
查看当前节点持有的锁
1 | sanlock client status |
check lvmlockd status
1 | systemctl status lvmlockd |
配置新增节点
- step1: 配置
nvmeof-connect服务 - step2: 配置
sanlock和lvmlockd服务 - step3: 启动
csi-lvmlocking
troubleshooting
lvscan 提示 Skipping global lock: storage failed for sanlock leases
issue:服务端nvmeof配置重置之后,且客户端在运行sanlock和lvmlockd服务前提下, 执行 lvscan提示
1 | Skipping global lock: storage failed for sanlock leases |
issue:check sanlock serivce by systemctl status sanlock
1 | Feb 28 10:38:28 ccit-k8s-worker-51 sanlock[2977932]: 2026-02-28 10:38:28 8280483 [2978414]: s1 delta_renew read rv -2 offset 0 /dev/mapper/csi--lvm-lvmlock |
solution:
1 | stop sanlock service |
lvscan 提示 Global lock failed: error -221
1 | systemctl restart sanlock lvmlockd, 报错解决参考下文 “restart sanlock lvmlockd 服务 failed” |
trigger troubleshooting
restart sanlock lvmlockd 服务 failed
issue
1 | Feb 10 16:25:33 ccit-k8s-worker-7 systemd[1]: sanlock.service: Unit process 1116433 (sanlock) remains running after unit stopped. |
solution
1 | kill sanlock and lvmlockd process |
lock-start 提示 lockspace not found or started…
issue: Skipping global lock: lockspace not found or started, VG csi-lvm start failed: lock manager sanlock is not running
solution: Clean Up Stale Device Mapper Entries
1 | List DM devices |