rbd锁引起kvm虚拟机无法启动的故障

前言

环境因为一些问题(网络,或者磁盘,或者其它各种异常),引起了集群的状态的一些变化,变化之后,集群的某些虚拟机正常某些虚拟机出现异常,异常现象就是无法启动
特别是win server2008 ,会一直卡在滚动条这里

这个问题很久前碰到过一个哥们出现过,他问我是否遇到过,这个之前遇到过一次无法启动的,通过导出导入的方式解决了,当时一直也没找到原因
这个哥们告诉我,通过关闭rbd的属性后,就可以正常启动了,当时就记了下,也没分析更深层次的原因
最近有一个环境因为时间过快,往回调整了十几分钟,集群出现mon选举,osd出现闪断以后,部分虚拟机出现无法启动的情况

问题分析

导入导出或者克隆基本可以判断数据是没有问题的,那么应该就是其它问题
通过关闭属性可以解决,那么大概能够定位到这几个属性相关的

1
features: layering, exclusive-lock, object-map, fast-diff, deep-flatten

而锁文件是最大的怀疑,之前处理ctdb的时候,就有过锁没有加上超时时间,然后ctdb挂掉以后,锁不会自动释放的问题,怀疑这个地方类似

我们的rbd的镜像如下

1
2
3
4
5
6
7
8
9
10
11
[root@lab101 vm]# rbd info rbd/windows-server-8-base-clone
rbd image 'windows-server-8-base-clone':
size 50GiB in 12800 objects
order 22 (4MiB objects)
block_name_prefix: rbd_data.102376b8b4567
format: 2
features: layering, exclusive-lock, object-map, fast-diff, deep-flatten
flags:
create_timestamp: Fri Dec 18 11:56:27 2020
parent: rbd/windows-server-8-base@for-clone
overlap: 50GiB

这个地方会有两个对象被上锁

1
2
3
4
[root@lab101 ceph]# rbd lock ls rbd/windows-server-8-base-clone
There is 1 exclusive lock on this image.
Locker ID Address
client.96545 auto 94013702760192 192.168.19.101:0/915896787

object_map的rbd_lock

1
2
[root@lab101 ceph]# rados -p rbd lock info rbd_object_map.102376b8b4567 rbd_lock
{"name":"rbd_lock","type":"exclusive","tag":"","lockers":[{"name":"client.96943","cookie":"","description":"","expiration":"0.000000","addr":"192.168.19.101:0/2231653745"}]}

header的rbd_lock,这个跟上面通过rbd lock查到的锁命令是同一个

1
2
[root@lab101 ceph]# rados -p rbd lock info rbd_header.102376b8b4567 rbd_lock
{"name":"rbd_lock","type":"exclusive","tag":"internal","lockers":[{"name":"client.96943","cookie":"auto 94009656832384","description":"","expiration":"0.000000","addr":"192.168.19.101:0/2231653745"}]}

复现问题

启动一个rbd的kvm,并且装上win server2008

1
/usr/libexec/qemu-kvm  -drive format=raw,file=rbd:rbd/windows-server-8-base-clone  -cdrom /home/vm/win2008.iso -m 8192 -vnc :0

这个启动后直接用vnc连接访问即可,然后使用一个循环测试写入工具在虚拟机里面进行循环读写,模拟正常的写入,我使用的是SANergy这个工具,使用循环写模式,可以做成iso,然后上面的-cdrom参数把文件穿透进去

准备一个至少两个物理节点的集群
节点一为mon,节点二的时间同步指向节点一,然后调整一的物理时间往后调整20分钟(也可以往前),这个集群会出现osd闪断的情况
正常情况下,这个时候windows会卡死的,如果没卡死,多操作几遍往后调整时间,目的就是把虚拟机卡死

我的环境通过资源管理器看到没有读写io了,强制停止kvm进程,无法停止就kill -9

我们恢复集群的状态,然后再次检查锁状态

1
2
3
4
5
6
[root@lab101 ceph]# cat /home/vm/checklock.sh 
rados -p rbd lock info rbd_object_map.102376b8b4567 rbd_lock
rados -p rbd lock info rbd_header.102376b8b4567 rbd_lock

[root@lab101 ceph]# sh /home/vm/checklock.sh
{"name":"rbd_lock","type":"exclusive","tag":"","lockers":[{"name":"client.96943","cookie":"","description":"","expiration":"0.000000","addr":"192.168.19.101:0/2231653745"}]}{"name":"rbd_lock","type":"exclusive","tag":"internal","lockers":[{"name":"client.96943","cookie":"auto 94009656832384","description":"","expiration":"0.000000","addr":"192.168.19.101:0/2231653745"}]}

可以看到居然还在

我们尝试启动虚拟机出现无法启动的情况

我们尝试删除锁
处理objectmap的锁

1
[root@lab101 ceph]# rados -p rbd lock break rbd_object_map.102376b8b4567 rbd_lock client.96943

处理header的锁

1
2
3
[root@lab101 ceph]# rados -p rbd lock break rbd_header.102376b8b4567 rbd_lock client.96943
ERROR: failed breaking lock: (2) No such file or directory
error 2: (2) No such file or directory

提示没有,比较奇怪,那尝试拿锁

1
2
3
[root@lab101 ceph]# rados -p rbd lock get rbd_header.102376b8b4567 rbd_lock client.96943
ERROR: failed locking: (16) Device or resource busy
error 16: (16) Device or resource busy

可以看到Device or resource busy 这个一般就是资源占用,无法释放的情况

我们用rbd的命令试下

1
2
3
4
5
6
[root@lab101 ceph]# rbd lock ls rbd/windows-server-8-base-clone
There is 1 exclusive lock on this image.
Locker ID Address
client.96943 auto 94009656832384 192.168.19.101:0/2231653745
[root@lab101 ceph]# rbd lock rm rbd/windows-server-8-base-clone "auto 94009656832384" client.96943
[root@lab101 ceph]# rbd lock ls rbd/windows-server-8-base-clone

可以看到这个是可以删除的

再次检查

1
2
[root@lab101 ceph]# sh /home/vm/checklock.sh 
{"name":"rbd_lock","type":"exclusive","tag":"","lockers":[]}{"name":"rbd_lock","type":"exclusive","tag":"internal","lockers":[]}[root@lab101 ceph]#

可以看到没有锁了

我们再次尝试启动

产生了新的锁文件了

1
2
3
{"name":"rbd_lock","type":"exclusive","tag":"","lockers":[]}{"name":"rbd_lock","type":"exclusive","tag":"internal","lockers":[]}[root@lab101 ceph]# 
[root@lab101 ceph]# sh /home/vm/checklock.sh
{"name":"rbd_lock","type":"exclusive","tag":"","lockers":[{"name":"client.97312","cookie":"","description":"","expiration":"0.000000","addr":"192.168.19.101:0/1322200836"}]}{"name":"rbd_lock","type":"exclusive","tag":"internal","lockers":[{"name":"client.97312","cookie":"auto 94532169500416","description":"","expiration":"0.000000","addr":"192.168.19.101:0/1322200836"}]}

从vnc里面可以看到桌面了

上面的是处理的方法之一,另外的一个方法是

1
2
rbd feature disable  rbd/windows-server-8-base-clone  exclusive-lock, object-map, fast-diff
rbd feature enable rbd/windows-server-8-base-clone exclusive-lock, object-map, fast-diff

建议是通过方法一进行处理,理论上方法二也没什么问题,其它几个属性如果正好需要用到的话,那么关闭后,开启下就行

总结

出问题总会是有原因的,如果我们提前抓到了问题,那么下次再遇到的时候就会从容的多,所以不要放弃解决问题,能够解决的问题都会成为你的经验