1.配置客户端ceph.conf
#vim /ect/ceph/ceph.conf
在[client]添加:
admin socket=/var/run/ceph/rbd-$pid.asok
log file = /var/log/ceph/ceph.client.admin.log
rbd cache = true
rbd cache size = 134217728
备注:貌似在ceph0.80.7,rbd-cache 默认打开。
2.定义disk.xml
<disk type='network' device='disk'>
<driver name='qemu' cache='writeback'/>
<auth username='libvirt'>
<secret type='ceph' uuid='2d833661-e55a-de95-bf0e-6d7d30e329c7'/>
</auth>
<source protocol='rbd' name='libvirt-pool/new-libvirt-image:debug_rbd=20:debug_objectcacher=20:log_file=/tmp/qemu-rbd.log'>
<host name='10.20.15.156' port='6789'/>
</source>
<target dev='vda' bus='virtio'/>
<shareable/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</disk>
备注:在使用rbd-cache,需要显示的指出:
cache='writeback'
以防止rbd-cache数据丢失。
3.将设备热插拔到虚拟机
# virsh attach-device ubuntu device.xml –persistent
5. 重启虚拟机
在/tmp/qemu-rbd.log找到rbdcache的调试信息
2015-03-12 09:48:51.734444 7fbb2a3c6700 11 objectcacher flusher 2048 / 134217728: 0 tx, 0 rx, 2048 clean, 0 dirty (16777216 target, 25165824 max)
2015-03-12 09:48:52.734553 7fbb2a3c6700 11 objectcacher flusher 2048 / 134217728: 0 tx, 0 rx, 2048 clean, 0 dirty (16777216 target, 25165824 max)
2015-03-12 09:48:53.734657 7fbb2a3c6700 11 objectcacher flusher 2048 / 134217728: 0 tx, 0 rx, 2048 clean, 0 dirty (16777216 target, 25165824 max)
2015-03-12 09:48:54.734796 7fbb2a3c6700 11 objectcacher flusher 2048 / 134217728: 0 tx, 0 rx, 2048 clean, 0 dirty (16777216 target, 25165824 max)
2015-03-12 09:48:55.734958 7fbb2a3c6700 11 objectcacher flusher 2048 / 134217728: 0 tx, 0 rx, 2048 clean, 0 dirty (16777216 target, 25165824 max)
2015-03-12 09:48:56.576418 7fbb296c0700 20 librbd: aio_read 0x7fbb447d5d60 completion 0x7fbad001b280 [0,512]
2015-03-12 09:48:56.576476 7fbb296c0700 20 librbd: ictx_check 0x7fbb447d5d60
2015-03-12 09:48:56.576523 7fbb296c0700 20 librbd: oid rb.0.dff3.2ae8944a.000000000000 0~512 from [0,512]
2015-03-12 09:48:56.576542 7fbb296c0700 10 objectcacher readx extent(rb.0.dff3.2ae8944a.000000000000 (0) in @12 0~512 -> [0,512])
2015-03-12 09:48:56.576559 7fbb296c0700 10 objectcacher.object(rb.0.dff3.2ae8944a.000000000000/head) map_read rb.0.dff3.2ae8944a.000000000000 0~512
2015-03-12 09:48:56.576573 7fbb296c0700 20 objectcacher.object(rb.0.dff3.2ae8944a.000000000000/head) map_read hit bh[ 0x7fbb447da690 0~2048 0x7fbb447da400 (2048) v 0 clean firstbyte=88] waiters = {}
2015-03-12 09:48:56.576590 7fbb296c0700 10 objectcacher readx hit bh bh[ 0x7fbb447da690 0~2048 0x7fbb447da400 (2048) v 0 clean firstbyte=88] waiters = {}
2015-03-12 09:48:56.576600 7fbb296c0700 10 objectcacher readx rmap opos 0: bh[ 0x7fbb447da690 0~2048 0x7fbb447da400 (2048) v 0 clean firstbyte=88] waiters = {} +0 frag 0~512 +0~512
2015-03-12 09:48:56.576624 7fbb296c0700 10 objectcacher readx has all buffers
2015-03-12 09:48:56.576633 7fbb296c0700 10 objectcacher readx adding buffer len 512 at 0
2015-03-12 09:48:56.576641 7fbb296c0700 10 objectcacher readx result is 512
2015-03-12 09:48:56.576649 7fbb296c0700 20 objectcacher readx done 0x7fbad0035580 512
2015-03-12 09:48:56.576667 7fbb296c0700 10 objectcacher trim start: bytes: max 134217728 clean 2048, objects: max 138 current 1
2015-03-12 09:48:56.576677 7fbb296c0700 10 objectcacher trim finish: max 134217728 clean 2048, objects: max 138 current 1
2015-03-12 09:48:56.576689 7fbb296c0700 20 librbd::AioRequest: should_complete 0x7fbad0035440 rb.0.dff3.2ae8944a.000000000000 0~512 r = 512
2015-03-12 09:48:56.576699 7fbb296c0700 10 librbd::AioCompletion: C_AioRead::finish() 0x7fbad001b3e0 r = 512
2015-03-12 09:48:56.576707 7fbb296c0700 10 librbd::AioCompletion: got {} for [0,512] bl 512
2015-03-12 09:48:56.576725 7fbb296c0700 20 librbd::AioCompletion: AioCompletion::complete_request() 0x7fbad001b280 complete_cb=0x7fbb43c94c50 pending 1
2015-03-12 09:48:56.576738 7fbb296c0700 20 librbd::AioCompletion: AioCompletion::finish_adding_requests 0x7fbad001b280 pending 0
2015-03-12 09:48:56.576748 7fbb296c0700 20 librbd::AioCompletion: AioCompletion::finalize() 0x7fbad001b280 rval 512 read_buf 0x7fbad005f400 read_bl 0
2015-03-12 09:48:56.576762 7fbb296c0700 20 librbd::AioCompletion: AioCompletion::finalize() copied resulting 512 bytes to 0x7fbad005f400
2015-03-12 09:48:56.735107 7fbb2a3c6700 11 objectcacher flusher 2048 / 134217728: 0 tx, 0 rx, 2048 clean, 0 dirty (16777216 target, 25165824 max)
2015-03-12 09:48:57.735222 7fbb2a3c6700 11 objectcacher flusher 2048 / 134217728: 0 tx, 0 rx, 2048 clean, 0 dirty (16777216 target, 25165824 max)
2015-03-12 09:48:58.735321 7fbb2a3c6700 11 objectcacher flusher 2048 / 134217728: 0 tx, 0 rx, 2048 clean, 0 dirty (16777216 target, 25165824 max)
2015-03-12 09:48:59.735391 7fbb2a3c6700 11 objectcacher flusher 2048 / 134217728: 0 tx, 0 rx, 2048 clean, 0 dirty (16777216 target, 25165824 max)
2015-03-12 09:49:00.735481 7fbb2a3c6700 11 objectcacher flusher 2048 / 134217728: 0 tx, 0 rx, 2048 clean, 0 dirty (16777216 target, 25165824 max)
通过日志加源码就很容易理解rbd-cache的实现了。