rbd: fix an incorrect assertion condition

In rbd_img_obj_parent_read_full_callback() there is an assertion
intended to verify the size of the image request for a full parent
read was the size of the original request's target object.  But
assertion was looking at the parent image order rather than the
original one, and these values can differ.

Fix that.

Signed-off-by: Alex Elder <elder@inktank.com>
rbd: support reading parent page data

Currently, rbd_img_parent_read() assumes the incoming object request
contains bio data.  But if a layered image is part of a multi-layer
stack of images will result in read requests of page data to parent
images.

Fortunately, it's not hard to add support for page data.

Signed-off-by: Alex Elder <elder@inktank.com>
rbd: set mapping read-only flag in rbd_add()

The rbd_dev->mapping field for a parent image is not meaningful.
Since rbd_image_probe() is used both for images being mapped and
their parents, it doesn't make sense to set that flag in that
function.

So move the setting of the mapping.read_only flag out of
rbd_dev_image_probe() and into rbd_add() instead.

Signed-off-by: Alex Elder <elder@inktank.com>
rbd: only set up watch for mapped images

Any changes to parent images are immaterial to any mapped clone.
So there is no need to have a watch event registered on header
objects except for the header object of an image that is mapped.

We can't set up the watch request until we know the name of the
header object though.  So pass a flag to rbd_dev_image_probe() to
indicate whether this probe is for a mapping or for a parent image.

Change the second parameter to rbd_dev_header_watch_sync() be
Boolean while we're at it.

Signed-off-by: Alex Elder <elder@inktank.com>
rbd: clean up parent if clone image is flattened

A format 2 clone image can be the subject of a "flatten" operation,
during which all of its data gets "copied up" from its parent image,
leaving the image fully populated.  Once this is complete, the
clone's association with the parent is abolished.

Since this can occur when a clone is mapped, we need to detect when
it has occurred and handle it accordingly.  The first part of this
is detecting the disappearance of a layered image's parent, and
cleaning up the parent's data structures.

To accomplish this, get parent info for format 2 images on every
refresh (rather than just during the initial probe) to detect the
disappearance of the parent image.  If the parent disappears, clean
it up.  Encapsulate a piece of rbd_dev_unprobe() and reuse it for
this purpose.

Note about rbd_dev_unparent():
The next patch will be checking in a callback function whether a
parent has disappeared.  Callback functions are called without
holding the header mutex, so we need a way to synchronize this.  For
simplicity, we use the parent overlap field for this.  An image with
a parent overlap of 0 is for all intents and purposes not a layered
image, and no parent reads or (for writes) existence checks are
needed for its objects.  If we zero the parent overlap, the callback
functions can check for that and use that to indicate the object has
been flattened.  Add a memory barrier to ensure the result is
visible everywhere.

Signed-off-by: Alex Elder <elder@inktank.com>
rbd: re-submit read request for flattened clone

If a clone image gets flattened while a parent read request is
underway, the original rbd object request needs to be resubmitted.

The reason is that by the time we get the response to the parent
read request, the data read from the parent may be out of date.
In other words, we could see this sequence of events:

    rbd client                      parent image/osd
    ----------                      ----------------
    original object ENOENT;
        issue parent read
                                    respond to parent read
                                    child image flattened
    original image header refresh
             <--- original object written independently here
    parent read response received

Add code to rbd_img_parent_read_callback() to detect when a clone's
parent image has disappeared, and re-submit the original read
request in that case.

Signed-off-by: Alex Elder <elder@inktank.com>
rbd: re-submit write request for flattened clone

Add code to rbd_img_parent_read_full_callback() to detect when a
clone's parent image has disappeared, and re-submit the original
write request in that case.  (See the previous commit for more
reasoning about why this is appropriate.)

Rename some variables in rbd_img_obj_parent_read_full_callback()
to match the convention used in the previous patch.

Signed-off-by: Alex Elder <elder@inktank.com>
rbd: re-submit flattened write request (part 2)

Add code to rbd_img_obj_exists_callback() to detect when a clone's
parent image has disappeared, and re-submit the original write
request in that case.

Kill off some redundant assertions.

Signed-off-by: Alex Elder <elder@inktank.com>
rbd: show evidence we've re-submitted something

Print messages to prove we've run through the three paths
where an object request gets resubmitted due to a flattened
target image.

Signed-off-by: Alex Elder <elder@inktank.com>