ceph/ceph — pull request #2212 by yuyuyu101 (2014-08-06 06:27:55+00:00)
Title: Draft: Librbd objectmap

CDS BP: librbd: shared flag, object map(https://wiki.ceph.com/Planning/Blueprints/Submissions/librbd%3A_shared_flag%2C_object_map)

-- ImageIndex --
ImageIndex is aimed to hold each object's location info which avoid
extra checking for none-existing object. It's only used when image flags
exists LIBRBD_CREATE_SHARED. Otherwise, ImageIndex will become gawp and
has no effect.

Each object has three state:
1. UNKNOWN: default value, it will follow origin path
2. LOCAL: imply this object is local, don't need to lookup parent image
3. PARENT: imply this object is in the parent image, don't need to read
from local image

Note: ImageIndex isn't full sync to real data all the time. Because the
transformation {"unknown" -> "local", "unknown" -> "parent"} are safe.
So We only need to handle with the exception when ImageIndex implies
this object is "parent" but the real data is "local". There exists three
methods to solve it:
1. flush `state_map` every time when "parent" -> "local" happened
2. as we know, parent image is frozen and never change `state_map`, so
we will read current image object all the time in sprint of the object
state and trust the parent image's state. In other word, when opening
the *current* image, all "parent" objects will be transformed to
"unknown".

Here choose to implement method 2. This method only allow 2 read ops
in one read request at max and without overhead.

1. When creating new image, it will mark all objects as "local"
2. When clone from image, it will mark all objects as "parent"
3. When write(or modified op) a object, it will mark this object as
"local"
4. When creating snapshot, image index will be freeze and save it as the
index of the snapshot
5. When reading object, the current image object will be always read in
spite of the state. And the parent image's object will be checked and
trust the state.