libceph: fix off-by-one bug in ceph_encode_filepath()

There is a BUG_ON() call that doesn't account for the single byte
structure version at the start of an encoded filepath in
ceph_encode_filepath().  Fix that.

Signed-off-by: Alex Elder <elder@inktank.com>
rbd: use rbd_dev consistently

Most variables that represent a (struct rbd_device) are named
"rbd_dev", but in some cases "dev" is used instead.  Change all
the "dev" references so they use "rbd_dev" consistently, to make it
clear from the name that we're working with an RBD device (as
opposed to, for example, a (struct device)).  Similarly, change
the name of the "dev" field in (struct rbd_notify_info) to be
"rbd_dev".

Signed-off-by: Alex Elder <elder@inktank.com>
rbd: rename some fields in struct rbd_dev

Rename some fields in struct rbd_dev, in hopes of aiding clarity:
    obj         --> image_name
    obj_len     --> image_name_len
    obj_md_name --> hedaer_name

Also rename a related symbol name:
    RBD_MAX_MD_NAME_LEN --> RBD_MAX_HEADER_NAME_LEN

Signed-off-by: Alex Elder <elder@inktank.com>
rbd: more symbol renames

Rename variables named "obj" which represent object names so they're
consistenly named "object_name".

Rename the "cls" and "method" parameters in rbd_req_sync_exec()
to be "class_name" and "method_name", and make similar changes
to the names of local variables in that function representing
the lengths of those names.

Signed-off-by: Alex Elder <elder@inktank.com>
rbd: even more symbol renames

Use the name "ceph_opts" consistently (rather than just "opt") for
pointers to a ceph_options structure.

Change the few spots that don't use "rbd_opts" for a rbd_options
pointer to match the rest.

Signed-off-by: Alex Elder <elder@inktank.com>
rbd: add a "rbd_format=" option

Add support for specifying a particular RBD image format version.
For now we only support format 1 (which is the "old"/original
version).  This is in preparation for supporting format 2 images.

Signed-off-by: Alex Elder <elder@inktank.com>
rbd: activate RBD image format 2 support

Activate the code that supports format 2 RBD images, by allowing new
RBD devices using that format to be mapped.

Signed-off-by: Alex Elder <elder@inktank.com>
libceph: define ceph_decode_string()

There is no string decoding function defined in <decode.h>.  This
function is a little different from the others in that the length
of the encoded string is not known a priori.  So the interface is
defined a bit like snprintf(), where the value returned indicates
the space required--even if it's more than the space allotted.

Signed-off-by: Alex Elder <elder@inktank.com>
rbd: make rbd_create_rw_ops() return a pointer

Either rbd_create_rw_ops() will succeed, or it will fail because a
memory allocation failed.  Have it just return a valid pointer or
null rather than stuffing a pointer into a provided address and
returning an errno.

Signed-off-by: Alex Elder <elder@inktank.com>
rbd: kill num_reply parameters

Several functions include a num_reply parameter, but it is never
used.  Just get rid of it everywhere--it seems to be something
that never got fully implemented.

Signed-off-by: Alex Elder <elder@inktank.com>
rbd: always pass ops array to rbd_req_sync_op()

All of the callers of rbd_req_sync_op() except one pass a non-null
"ops" pointer.  The only one that does not is rbd_req_sync_read(),
which passes CEPH_OSD_OP_READ as its "opcode" and, CEPH_OSD_FLAG_READ
for "flags".

By allocating the ops array in rbd_req_sync_read() and moving the
special case code for the null ops pointer into it, it becomes
clear that much of that code is not even necessary.

In addition, the "opcode" argument to rbd_req_sync_op() is never
actually used, so get rid of that.

Signed-off-by: Alex Elder <elder@inktank.com>
rbd: fix leak in rbd_get_client()

If an error happens creating a new rbd client in rbd_get_client(),
the ceph options structure created earlier in the function needs
to be destroyed.  This was not being done.  Fix it, rearranging
a little code to avoid duplication.

Signed-off-by: Alex Elder <elder@inktank.com>
rbd: pass flags to rbd_req_sync_exec()

In order to allow both read request and write requests to be
initiated using rbd_req_sync_exec(), add an OSD flags value
which can be passed down to rbd_req_sync_op().  Rename the "data"
and "len" parameters to be more clear that they represent data
that is outbound.

At this point, this function is still only used (and works) for
write requests.

Signed-off-by: Alex Elder <elder@inktank.com>
rbd: support data returned from OSD methods

An OSD object method call can be made using rbd_req_sync_exec().
Until now this has only been used for creating a new RBD snapshot,
and that has only required sending data out, not receiving anything
back from the OSD.

We will now need to get data back from an OSD on a method call, so
add parameters to rbd_req_sync_exec() that allow a buffer into
which returned data should be placed, along with its size.

Previously, rbd_req_sync_exec() passed a null pointer and zero
size to rbd_req_sync_op(); change this so the new inbound buffer
information is provided instead.

Rename the "buf" and "len" parameters in rbd_req_sync_op() to
make it more obvious they are describing inbound data.

This also includes a bonus change in rbd_req_sync_notify_ack(),
where a local variable was needlessly being used to hold a null
pointer.

Signed-off-by: Alex Elder <elder@inktank.com>
rbd: assign header name later

Move the assignment of the header name for an rbd image a bit latetr.

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

This is a big dump patch that's not even working right now.
It's basically a bunch of code I'm experimenting with while
I try to figure out what to send and what to get back from
the RBD server on the format 2 images.

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