How to find the image-format type of image in ceph ?

In previous article (How to perform various operation using rbd in ceph ?) we have seen that we were getting error while creating clone from the snapshot of image created with format 1.

I thought of digging more into it. How can we verify whats the type of format used for the image ?

Type 1 : Image created without specifying any format, by default its created with format 1. You can see that in below output.

[root@ceph-m3 ~]# rbd -p pool2 info foo
rbd image ‘foo’:
size 1024 MB in 256 objects
order 22 (4096 kB objects)
block_name_prefix: rb.0.3685.2ae8944a
format: 1                                                                    <<<<<<

With format 1 we can create the snapshot of image but from the snapshot we can’t create the clone. Because, it doesn’t support the layering feature.

Type 2 : Image created with specifying the format type. I have created image by specifying the format 2.

[root@ceph-m3 ~]#  rbd create –image-format 2 -p pool2 foonew –size 500
[root@ceph-m3 ~]# rbd -p pool2 info foonew
rbd image ‘foonew’:
size 500 MB in 125 objects
order 22 (4096 kB objects)
block_name_prefix: rbd_data.36ba74b0dc51
format: 2                                     <<<<<<
features: layering                       <<<<<<

It supports the layering feature. We can create the clone from snapshot of image.

If you want to convert existing image to different format, I didn’t find any elegant method for it, only thing I found is to export and import the image the different format.

My image is foo of type format 1. I am importing this image to a file.

[root@ceph-m3 ~]# rbd export pool2/foo@snap10 /tmp/image1
Exporting image: 100% complete…done.

Importing the same image in format 2. In below command we have not specified the pool name hence it will go default pool rbd.

[root@ceph-m3 ~]# rbd import –image-format 2 /tmp/image1
Importing image: 100% complete…done.

But the image is converted into format2. Notice the name of image is also not mentioned hence taking the filename as the image name.

[root@ceph-m3 ~]# rbd -p rbd info image1
rbd image ‘image1’:
size 1024 MB in 256 objects
order 22 (4096 kB objects)
block_name_prefix: rbd_data.379e74b0dc51
format: 2
features: layering

In below example I am specifying the pool and image name. As we are already having image with name foo in pool2 hence below command is getting fail. We need to import the image with different name.

[root@ceph-m3 ~]# rbd import -p pool2 –image-format 2 /tmp/image1 foo
rbd: image creation failed
Importing image: 0% complete…failed.
rbd: import failed: (17) File exists
2015-04-23 10:52:35.088374 7f0178a957c0 -1 librbd: rbd image foo already exists

Eventually I imported the image using name foo1 instead of foo in pool2.

[root@ceph-m3 ~]# rbd import -p pool2 –image-format 2 /tmp/image1 foo1
Importing image: 100% complete…done.

Below is the information which I have found from official ceph website.

--image-format format
Specifies which object layout to use. The default is 1.

  • format 1 – Use the original format for a new rbd image. This format is understood by all versions of librbd and the kernel rbd module, but does not support newer features like cloning.
  • format 2 – Use the second rbd format, which is supported by librbd and kernel since version 3.11 (except for striping). This adds support for cloning and is more easily extensible to allow more features in the future.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s