Ceph RBD image map rules

代码定义

Ceph版本:Hammer 0.94.5

1
2
3
4
5
6
7
8
/* New-style rbd image 'foo' consists of objects
* rbd_id.foo - id of image
* rbd_header.<id> - image metadata
* rbd_object_map.<id> - optional image object map
* rbd_data.<id>.00000000
* rbd_data.<id>.00000001
* ... - data
*/

从中可以看出一个rbd image会对应至少4个文件:

  1. rbd_id.foo - foo为image的name
  2. rbd_header.<id>
  3. rbd_object_map.<id>
  4. rbd_data.<id>.00000000

选择一个image

1
2
# rbd ls volumes
volume-5ba95c5d-287b-429f-aadb-b72e990122ad

查看rbd_id文件

获取image的id

1
2
3
4
5
6
7
8
9
10
# ceph osd map volumes rbd_id.volume-5ba95c5d-287b-429f-aadb-b72e990122ad
osdmap e3001 pool 'volumes' (2) object 'rbd_id.volume-5ba95c5d-287b-429f-aadb-b72e990122ad' -> pg 2.49c908b (2.8b) -> up ([13,15], p13) acting ([13,15], p13)

在osd节点上找到image对应的文件:
# find . -name "*volume-5ba95c5d-287b-429f-aadb-b72e990122ad*"
./ceph-15/current/2.8b_head/rbd\uid.volume-5ba95c5d-287b-429f-aadb-b72e990122ad__head_049C908B__2

# cat ./ceph-15/current/2.8b_head/rbd\\uid.volume-5ba95c5d-287b-429f-aadb-b72e990122ad__head_049C908B__2

13cd1213ee70

上面13cd1213ee70即为image的id

查看rbd_id文件的attr

1
2
3
# rados -p volumes listxattr rbd_id.volume-5ba95c5d-287b-429f-aadb-b72e990122ad
# rados -p volumes getxattr rbd_id.volume-5ba95c5d-287b-429f-aadb-b72e990122ad attr
error getting xattr volumes/rbd_id.volume-5ba95c5d-287b-429f-aadb-b72e990122ad/attr: (61) No data available

rbd_id文件并没有设置attr

查看rbd_header文件

1
2
3
4
5
6
7
8
# ceph osd map volumes rbd_header.13cd1213ee70
osdmap e3001 pool 'volumes' (2) object 'rbd_header.13cd1213ee70' -> pg 2.57c27b74 (2.374) -> up ([5,11], p5) acting ([5,11], p5)

# find . -name "*header.13cd1213ee70*"
./ceph-5/current/2.374_head/rbd\uheader.13cd1213ee70__head_57C27B74__2

# ll ./ceph-5/current/2.374_head/rbd\\uheader.13cd1213ee70__head_57C27B74__2
-rw-r--r-- 1 root root 0 Oct 29 17:13 ./ceph-5/current/2.374_head/rbd\uheader.13cd1213ee70__head_57C27B74__2

创建rbd的时候,image-format的解释如下:

1
2
3
--image-format <format-number>     format to use when creating an image
format 1 is the original format (default)
format 2 supports cloning
  1. old_format格式

    调用顺序为:create_v1() --> init_rbd_header(),里面会把image的metadata写入rbd_headerobject里。

  2. new_format格式

    rbd_header object的size为0,而image的metadata存在omap里。

貌似file的xattr只在有snap的时候才会设置,clone后会清除,需要验证。
xattr主要用来给CephFS提供XATTR数据存放

查看rbd_header的attr

1
2
3
# rados -p volumes listxattr rbd_header.13cd1213ee70
# rados -p volumes getxattr rbd_header.13cd1213ee70 attr
error getting xattr volumes/rbd_header.13cd1213ee70/attr: (61) No data available

rbd_header文件并没有设置attr

查看rbd_header的omapvalue

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# rados -p volumes listomapvals rbd_header.13cd1213ee70
features
value: (8 bytes) :
0000 : 03 00 00 00 00 00 00 00 : ........

object_prefix
value: (25 bytes) :
0000 : 15 00 00 00 72 62 64 5f 64 61 74 61 2e 31 33 63 : ....rbd_data.13c
0010 : 64 31 32 31 33 65 65 37 30 : d1213ee70

order
value: (1 bytes) :
0000 : 19 : .

size
value: (8 bytes) :
0000 : 00 00 00 00 32 00 00 00 : ....2...

snap_seq
value: (8 bytes) :
0000 : 00 00 00 00 00 00 00 00 : ........
1
2
3
4
5
6
7
8
9
# rados -p volumes listomapkeys rbd_header.13cd1213ee70
features
object_prefix
order
size
snap_seq

# rados -p volumes getomapheader rbd_header.13cd1213ee70
header (0 bytes) :

从rbd_directory中查看信息

rbd_directory里包含了pool里所有image的信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# rados -p volumes listomapvals rbd_directory
id_13cd1213ee70
value: (47 bytes) :
0000 : 2b 00 00 00 76 6f 6c 75 6d 65 2d 35 62 61 39 35 : +...volume-5ba95
0010 : 63 35 64 2d 32 38 37 62 2d 34 32 39 66 2d 61 61 : c5d-287b-429f-aa
0020 : 64 62 2d 62 37 32 65 39 39 30 31 32 32 61 64 : db-b72e990122ad

name_volume-5ba95c5d-287b-429f-aadb-b72e990122ad
value: (16 bytes) :
0000 : 0c 00 00 00 31 33 63 64 31 32 31 33 65 65 37 30 : ....13cd1213ee70

# rados -p volumes listomapkeys rbd_directory
id_13cd1213ee70
name_volume-5ba95c5d-287b-429f-aadb-b72e990122ad

# rados -p volumes getomapheader rbd_directory
header (0 bytes) :

查看rbd_data文件

查看该image的其中一个object的存放信息:

1
2
3
4
5
6
7
8
获取映射关系
# ceph osd map volumes rbd_header.13cd1213ee70.0000000000000ac3
osdmap e3001 pool 'volumes' (2) object 'rbd_data.13cd1213ee70.0000000000000ac3' -> pg 2.bc79817 (2.17) -> up ([6,12], p6) acting ([6,12], p6)

在对应osd上找到上面的数据objects,命名规则介绍如下:
# find . -name "*13cd1213ee70.0000000000000ac3*"
./ceph-12/current/2.17_head/rbd\udata.13cd1213ee70.0000000000000ac3__head_0BC79817__2
rbd_data <id> <slice num> head <HASH> <pool id>
支持原创