librbd: add {rbd_}list_children() methods

These iterate over all pools and check for children of a
particular snapshot.

Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
Reviewed-by: Dan Mick <dan.mick@inktank.com>
rbd: add "children" command, update cli test files

Fixes: #2720
Signed-off-by: Dan Mick <dan.mick@inktank.com>
Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
librbd: prevent racing clone and snap unprotect

If the following sequence of events occured,
a clone could be created of an unprotected snapshot:

1. A: begin clone - check that snap foo is protected
2. B: rbd unprotect snap foo
3. B: check that all pools have no clones of foo
4. B: unprotect snap foo
5. A: finish creating clone of foo, add it as a child

To stop this from happening, check at the beginning and end of
cloning that the parent snapshot is protected. If it is not,
or checking protection status fails (possibly because the parent
snapshot was removed), remove the clone and return an error.

Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
rbd: add --format option

This chooses whether to use the original (supported by krbd)
or the new (supports layering) format.

Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
doc: clarify rbd man page (esp. layering)

* a clone's size can't be overridden
* note which commands require format 2
* clarify details of copy
* add examples for cloning
* add pool to map example for consistency
* fix a couple warnings and re-sync man page with rst

Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
librbd: fix delete[]

CID 716902: Non-array delete for scalars (DELETE_ARRAY)
At (15): Deleting array variable "buf" with non-array delete in "delete buf".

Signed-off-by: Sage Weil <sage@inktank.com>
librbd, cls_rbd: close snapshot creation race with old format

If two clients created a snapshot at the same time, the one with the
higher snapshot id might be created first, so the lower snapshot id
would be added to the snapshot context and the snaphot seq would be
set to the lower one.

Instead of allowing this to happen, return -ESTALE if the snapshot id
is lower than the currently stored snapshot sequence number. On the
client side, get a new id and retry if this error is encountered.

Backport: argonaut
Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
Reviewed-by: Sage Weil <sage@inktank.com>
rbd: make --pool/--image args easier to understand for import

There's no need to set the default pool in set_pool_image_name - this
is done later, in a way that doesn't ignore --pool if --dest-pool
is not specified.

This means --pool and --image can be used with import, just like
the rest of the commands. Without this change, --dest and --dest-pool
had to be used, and --pool would be silently ignored for rbd import.

Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
qa: test args for rbd import

Make sure that --pool/--dest-pool and --image/--dest all work
interchangeably.

Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
rbd: only open the destination pool for import

Otherwise importing into another pool when the default pool, rbd,
doesn't exist results in an error trying to open the rbd pool.

Reported-by: Sébastien Han <han.sebastien@gmail.com>
Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
cls_lock: specify librados namespace explicitly

librados namespace was not specified, hence required including
source files to add using namespace. This fixes it.

Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
cls_lock: fix some spacing

Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
cls_lock_client: clean up reference parameters

These should all be const. The remaining reference parameters
will be converted to pointers in another commit.

Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
cls_lock_client: change modified reference parameters to pointers

This makes it clear which parameters are modified,
as our style guide states.

Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
cls_lock_client: fix indentation

Add indentation settings to header, and reindent.

Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
cls_lock_client: return error when decoding fails

Library code shouldn't be using cerr either.

Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
cls_lock_types: add missing include

msg_types defines entity-related types used here.

Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
cls_lock_client: add ObjectOperation-based get_lock_info

This will be used by librbd to grab lock info along with
the rest of its header information in a single request.

Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
librbd: use generic cls_lock instead of cls_rbd's locking

Update the librbd locking api to make more sense:
 * Add an optional tag to shared locking
 * only make shared vs exclusive different functions in the user-visible api
 * return a list of structs instead of a set of pairs
 * fix incorrect range checking in the C api
 * rename locks to lockers to be consistent with the generic locking class
 * rename other_locker parameter to client, to match the list_lockers usage

Fixes: #2952
Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
qa: update rbd tests and runner

* no longer need to wait for watch timeout since #2948 was fixed
* use --format 2 instead of --new-format
* add test_cls_rbd to run-rbd-tests script

Signed-off-by: Josh Durgin <josh.durgin@inktank.com>