ceph查询rbd的使用容量(快速)

ceph在Infernalis加入了一个功能是查询rbd的块设备的使用的大小,默认是可以查询的,但是无法快速查询,那么我们来看看这个功能是怎么开启的

ceph版本

root@lab8107:~/ceph# ceph -v
ceph version 9.2.0 (bb2ecea240f3a1d525bcb35670cb07bd1f0ca299)

创建RBD设备

我们先来创建一个rbd

root@lab8107:~/ceph# rbd create test --size 4000
root@lab8107:~/ceph# rbd info test
rbd image 'test':
size 4000 MB in 1000 objects
order 22 (4096 kB objects)
block_name_prefix: rbd_data.10305695d26a
format: 2
features: layering
flags:

进行RBD容量使用查询

我们来试一下rbd du命令

root@lab8107:~/ceph# rbd du test
warning: fast-diff map is not enabled for test. operation may be slow.
NAME PROVISIONED USED
test 4000M 0

可以看到有个提示需要开启fast-diff的属性

root@lab8107:~/ceph# rbd --help
···
Supported image features:
layering (+), striping (+), exclusive-lock (*), object-map (*), fast-diff (*), deep-flatten

(*) supports enabling/disabling on existing images
(+) enabled by default for new images if features are not specified

可以看到默认开启了 layering striping 属性,后面属性没有开启
我们看一下rbd的man page

root@lab8107:~/ceph# man rbd
···
--image-feature feature-name
Specifies which RBD format 2 feature should be enabled when creating an image. Multiple features can be enabled by repeating this option multiple times. The following features are supported:

· layering: layering support
· striping: striping v2 support
· exclusive-lock: exclusive locking support
· object-map: object map support (requires exclusive-lock)
· fast-diff: fast diff calculations (requires object-map)
· deep-flatten: snapshot flatten support

开启RBD属性

可以看到开启fast-diff 需要开启exclusive-lockobject-map 属性
那么依次开启就好了

root@lab8107:~/ceph# rbd  feature enable test  exclusive-lock
root@lab8107:~/ceph# rbd feature enable test object-map
root@lab8107:~/ceph# rbd feature enable test fast-diff
2016-03-24 21:17:23.822720 7f241a5447c0 -1 librbd::ObjectMap: error refreshing object map: (2) No such file or directory
2016-03-24 21:17:23.823191 7f241a5447c0 -1 librbd::ObjectMap: error refreshing object map: (2) No such file or directory

来查看下 rbd info

root@lab8107:~/ceph# rbd info test
2016-03-24 21:18:37.972235 7f9918a7d7c0 -1 librbd::ObjectMap: error refreshing object map: (2) No such file or directory
rbd image 'test':
size 4000 MB in 2016-03-24 21:18:37.972900 7f9918a7d7c0 -1 1000librbd::ObjectMap: error refreshing object map: (2) No such file or directory objects

order 22 (4096 kB objects)
block_name_prefix: rbd_data.10305695d26a
format: 2
features: layering, exclusive-lock, object-map, fast-diff
flags: object map invalid, fast diff invalid

我们可以看到又报错了,这个是因为是后开启object map,需要重建一下

root@lab8107:~/ceph# rbd  object-map rebuild  test  
2016-03-24 21:20:05.488515 7fa0141917c0 -1 librbd::ObjectMap: error refreshing object map: (2) No such file or directory
2016-03-24 21:20:05.489142 7fa0141917c0 -1 librbd::ObjectMap: error refreshing object map: (2) No such file or directory
2016-03-24 21:20:05.530344 7fa0141917c0 -1 librbd::ObjectMap: error refreshing object map: (2) No such file or directory
Object Map Rebuild: 100% complete...done.

再次查看下

root@lab8107:~/ceph# rbd info test
rbd image 'test':
size 4000 MB in 1000 objects
order 22 (4096 kB objects)
block_name_prefix: rbd_data.10305695d26a
format: 2
features: layering, exclusive-lock, object-map, fast-diff
flags:

已经可以了,我们来试下这个功能

root@lab8107:~/ceph# rbd du test
NAME PROVISIONED USED
test 4000M 0

好了,这个功能已经开启了,这个是对已经创建好的rbd,然后开启这个属性,那么如果不想这么麻烦,默认就开启,创建的时候就开启,有什么方法么,当然是有的

默认开启RBD容量快速查询的方法

root@lab8107:~/ceph# ceph --show-config|grep rbd_default_features
rbd_default_features = 3

查看下默认配置,这个是3,那么3是什么意思,3=1+2,这个是属性中常用的一种做法,给属性设置一个bit码,在配置的时候,只需要设置加起来的和
在RBD的属性里面:
属性.png-14.1kB

我们要开启 前五个属性那么就是 31
在ceph.conf中添加配置

rbd_default_features = 31

创建后不做任何操作直接查询

root@lab8107:~/ceph# rbd create test1 --size 1000
root@lab8107:~/ceph# rbd info test1
rbd image 'test1':
size 1000 MB in 250 objects
order 22 (4096 kB objects)
block_name_prefix: rbd_data.103c29f2280d
format: 2
features: layering, exclusive-lock, object-map, fast-diff
flags:
root@lab8107:~/ceph# rbd du test1
NAME PROVISIONED USED
test1 1000M 0

可以看到默认就把几个属性都开启好了,关于这个属性的开启就记录到这里,之前已经测试了一次

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!


支付宝