1. 程式人生 > >ceph format2格式image

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 …………….