rbd: unregister linger in watch sync routine

Move the code that unregisters an rbd device's lingering header
object watch request into rbd_dev_header_watch_sync(), so it
occurs in the same function that originally sets up that request.

Signed-off-by: Alex Elder <elder@inktank.com>
rbd: track object rather than osd request for watch

Switch to keeping track of the object request pointer rather than
the osd request used to watch the rbd image header object.

Signed-off-by: Alex Elder <elder@inktank.com>
rbd: decrement obj request count when deleting

Decrement the obj_request_count value when deleting an object
request from its image request's list.  Rearrange a few lines
in the surrounding code.

This resolves:
    http://tracker.ceph.com/issues/3959

Signed-off-by: Alex Elder <elder@inktank.com>
rbd: don't drop watch requests on completion

The new request code arranges to get a callback for every osd
request we submit (this was not the case previously).

We register a lingering object watch request for the header object
for each mapped rbd image.

If a connection problem occurs, the osd client will re-submit
lingering requests.  And each time such a request is re-submitted,
its callback function will get called again.

We therefore need to ensure the object request associated with the
lingering osd request stays valid, and the way to do that is to have
an extra reference to the lingering osd request.

So when a request to initiate a watch has completed, do not drop a
reference as one normally would.  Instead, hold off dropping that
reference until the request to tear down that watch request is done.

Also, only set the rbd device's watch_request pointer after the
watch request has been completed successfully, and clear the
pointer once it's been torn down.

This resolves:
    http://tracker.ceph.com/issues/3937

Signed-off-by: Alex Elder <elder@inktank.com>
rbd: define flags field, use it for exists flag

Define a new rbd device flags field, manipulated using bit
operations.  Replace the use of the current "exists" flag with a bit
in this new "flags" field.  Add a little commentary about the
"exists" flag, which does not need to be manipulated atomically.

Signed-off-by: Alex Elder <elder@inktank.com>
rbd: prevent open for image being removed

An open request for a mapped rbd image can arrive while removal of
that mapping is underway.  We need to prevent such an open request
from succeeding.  (It appears that Maciej Galkiewicz ran into this
problem.)

Define and use a "removing" flag to indicate a mapping is getting
removed.  Set it in the remove path after verifying nothing holds
the device open.  And check it in the open path before allowing the
open to proceed.  Acquire the rbd device's lock around each of these
spots to avoid any races accessing the flags and open_count fields.

This addresses:
    http://tracker.newdream.net/issues/3427

Reported-by:  Maciej Galkiewicz <maciejgalkiewicz@ragnarson.com>
Signed-off-by: Alex Elder <elder@inktank.com>
rbd: temp layering support

Pretend we support layering...

Signed-off-by: Alex Elder <elder@inktank.com>
rbd: probe the parent of an image if present

Call the probe function for the parent device.

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