ceph format2格式image

1、接上篇,这创建一个format 2格式的image
$rbd create rbd/format2_image_1G –image-format=2 -s 1G

2、显示image元数据信息:size,order,block_name_prefix,format,features,flag
$rbd info rbd/format2_image_1G
rbd image ‘format2_image_1G’:
size 1024 MB in 256 objects
order 22 (4096 kB objects)
block_name_prefix: rbd_data.11062ae8944a
format: 2
features: layering, exclusive-lock, object-map, fast-diff, deep-flatten
flags:

3、查看rados -p rbd ls.多出了4个文件:
$rados -p rbd ls
rbd_object_map.11062ae8944a
rbd_directory
rbd_id.format2_image_1G
rbd_header.11062ae8944a

4、解释下这几个文件的内容
rbd_object_map.11062ae8944a:
rbd_directory:存放如上所示包含所有image name和ID的映射关系
rbd_id.format2_image_1G:保存的是image的ID信息
rbd_header.11062ae8944a:保存的image的元数据信息,如size,features, order,object_prefix,snap_seq, parent等。

5、接着上一篇查看rbd_directory是否包含有image的name和id的映射关系。
$rados -p rbd listomapvals rbd_directory
id_11062ae8944a
value (20 bytes) :
00000000 10 00 00 00 66 6f 72 6d 61 74 32 5f 69 6d 61 67 |….format2_imag|
00000010 65 5f 31 47 |e_1G|
00000014

name_format2_image_1G
value (16 bytes) :
00000000 0c 00 00 00 31 31 30 36 32 61 65 38 39 34 34 61 |….11062ae8944a|
00000010
果然有id(id_11062ae8944a) 和name(name_format2_image_1G)的纪录

6、查看rbd_id.format2_image_1G内容
$rados -p rbd get rbd_id.format2_image_1G 1.txt

$xxd 1.txt
0000000: 0c00 0000 3131 3036 3261 6538 3934 3461 ….11062ae8944a

也可以到目录(dev/osd0/current/1.42_head/)下查看文件(rbd\uid.format2\uimage\u1G__head_4C843142__1 ):
$cd dev/osd0/current/1.42_head/

$xxd rbd\uid.format2\uimage\u1G__head_4C843142__1
0000000: 0c00 0000 3131 3036 3261 6538 3934 3461 ….11062ae8944a

7、查看rbd_header.11062ae8944a文件内容
$rados -p rbd listomapvals rbd_header.11062ae8944a
features
value (8 bytes) :
00000000 3d 00 00 00 00 00 00 00 |=…….|
00000008

object_prefix
value (25 bytes) :
00000000 15 00 00 00 72 62 64 5f 64 61 74 61 2e 31 31 30 |….rbd_data.110|
00000010 36 32 61 65 38 39 34 34 61 |62ae8944a|
00000019

order
value (1 bytes) :
00000000 16 |.|
00000001

size
value (8 bytes) :
00000000 00 00 00 40 00 00 00 00 |…@….|
00000008

snap_seq
value (8 bytes) :
00000000 00 00 00 00 00 00 00 00 |……..|
00000008

object_prefix:对象的名字前缀
order:用来计算block size的,比如22,那么块大小就是1<<22=4MB
size:对象大小,这里是8字节
snap_seq:快照编号,没有快照的时候是0

8、往这个image中写点数据,首先需要map这个image到rbd块设备。
$sudo rbd map rbd/format2_image_1G
rbd: sysfs write failed
RBD image feature set mismatch. You can disable features unsupported by the kernel with “rbd feature disable”.
In some cases useful info is found in syslog - try “dmesg | tail” or so.
rbd: map failed: (6) No such device or address

这里是由于format 2格式的image有些功能只有内核3.11以上才支持,而我当前的内核版本是3.10的版本,所以会报错不支持该 format的的一些特性。因为我创建image的时候默认打开了所有的特性功能feature.如:
$rbd info rbd/format2_image_1G
rbd image ‘format2_image_1G’:
size 1024 MB in 256 objects
order 22 (4096 kB objects)
block_name_prefix: rbd_data.11062ae8944a
format: 2
features: layering, exclusive-lock, object-map, fast-diff, deep-flatten
flags:
这里features: layering, exclusive-lock, object-map, fast-diff, deep-flatten功能全部开启了。
layering: 支持分层
striping: 支持条带化 v2
exclusive-lock: 支持独占锁
object-map: 支持对象映射(依赖 exclusive-lock )
fast-diff: 快速计算差异(依赖 object-map )
deep-flatten: 支持快照扁平化操作
journaling: 支持记录 IO 操作(依赖独占锁)
所以要想在内核3.10上map这个格式的image则需要在创建的时候进行设置关闭掉其他功能,只打开layering功能即可,目前3.10只支持layering功能,其他特性需要更高的版本。所以这里需要重新创建image。

$rbd create rbd/format2_image_1G –image-format 2 –image-feature layering -s 1G

$rbd info rbd/format2_image_1G

rbd image ‘format2_image_1G’:
size 1024 MB in 256 objects
order 22 (4096 kB objects)
block_name_prefix: rbd_data.11212ae8944a
format: 2
features: layering
flags:

9、map format2_image_1G
$sudo rbd map rbd/format2_image_1G
/dev/rbd0

10、写4K数据到format2_image_1G
$sudo dd if=./testfile of=/dev/rbd0 bs=4k count=1
0+1 records in
0+1 records out
26 bytes (26 B) copied, 0.0134987 s, 1.9 kB/s

$rados -p rbd ls
rbd_header.11212ae8944a
rbd_directory
rbd_id.format2_image_1G
rbd_data.11212ae8944a.0000000000000000
多了对象(4M)rbd_data.11212ae8944a.0000000000000000

11、获取对象内容,两种方式,一种是通过rados get到临时文件,一种是到目录下查看文件内容。
$rados -p rbd get rbd_data.11212ae8944a.0000000000000000 1.txt

$xxd 1.txt
0000000: 7468 6973 2069 7320 7465 7374 2066 696c this is test fil
0000010: 6520 636f 6e74 6578 740a 0000 0000 0000 e context…….
0000020: 0000 0000 0000 0000 0000 0000 0000 0000 …………….
0000030: 0000 0000 0000 0000 0000 0000 0000 0000 …………….
0000040: 0000 0000 0000 0000 0000 0000 0000 0000 …………….
0000050: 0000 0000 0000 0000 0000 0000 0000 0000 …………….

$cd dev/osd0/current/1.8d_head/

$xxd rbd\udata.11212ae8944a.0000000000000000__head_3498F58D__1
0000000: 7468 6973 2069 7320 7465 7374 2066 696c this is test fil
0000010: 6520 636f 6e74 6578 740a 0000 0000 0000 e context…….
0000020: 0000 0000 0000 0000 0000 0000 0000 0000 …………….
0000030: 0000 0000 0000 0000 0000 0000 0000 0000 …………….
0000040: 0000 0000 0000 0000 0000 0000 0000 0000 …………….
0000050: 0000 0000 0000 0000 0000 0000 0000 0000 …………….

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值