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: drop a useless local variable

In rbd_req_sync_notify_ack(), a local variable was needlessly being
used to hold a null pointer.  Just pass NULL instead.

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

There is no string decoding function defined in <decode.h>, so this
defines one.

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>
libceph: define ceph_extract_encoded_string()

This adds a new utility routine which will return a dynamically-
allocated buffer containing a string that has been decoded from ceph
over-the-wire format.  It also returns the length of the string
if the address of a size variable is supplied to receive it.

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

Define a new function dup_token(), to be used during argument
parsing for making dynamically-allocated copies of tokens being
parsed.

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

Each rbd image has a name that forms the basis of all data objects
backing the device.  Old (format 1) images refer to this name as the
"block name," while new (format 2) images use the term "object
prefix" for this.

Change the field name in the in-core rbd image header structure to
reflect the more modern usage.  We intentionally keep the the name
"block_name" in the on-disk definition for format 1 image headers.

Signed-off-by: Alex Elder <elder@inktank.com>
rbd: dynamically allocate object prefix

There is no need to impose a small limit the length of the object
prefix recorded for an rbd image in a struct rbd_image_header.
Remove the limitation by allocating space for the object prefix
dynamically.

Signed-off-by: Alex Elder <elder@inktank.com>
rbd: don't store pool name in struct rbd_dev

An rbd device's pool name is used to specify the pool to use for an
rbd image when it gets mapped (via rbd_add()).  However, only the
pool id can be relied on to be invariant--the name of a pool can
change at any time.

This means that the name of the pool is potentially stale as soon as
the image is mapped, so it's a bad idea to record this information.
So only store the pool id, not its name, in an rbd_dev.

Here are a few specific notes about this change:
    - The "pool" name device attribute (/sys/bus/rbd/devices/<N>/pool)
      goes away.  In its place is a "pool_id" attribute that provide
      the numeric pool id for the rbd image.
    - rbd_add_parse_args() now returns a pointer to a dynamically-
      allocated copy of the pool name taken from the arguments.
    - rbd_add() has been changed to handle freeing the pool name,
      both in error cases and in the normal case after the pool id
      has been recorded.

Signed-off-by: Alex Elder <elder@inktank.com>
rbd: dynamically allocate image header name

There is no need to impose a small limit the length of the header
name recorded for an rbd image in a struct rbd_dev.  Remove the
limitation by allocating space for the header name dynamically.

Signed-off-by: Alex Elder <elder@inktank.com>
rbd: dynamically allocate image name

There is no need to impose a small limit the length of the rbd image
name recorded in a struct rbd_dev.  Remove the limitation by
allocating space for the image name dynamically.

Signed-off-by: Alex Elder <elder@inktank.com>
rbd: dynamically allocate snapshot name

There is no need to impose a small limit the length of the snapshot
name recorded for an rbd image in a struct rbd_dev.  Remove the
limitation by allocating space for the snapshot name dynamically.

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

An rbd image is not a single object, but a logical construct made up
of an aggregation of objects.

Rename some fields in struct rbd_dev, in hopes of reinforcing this.
    obj         --> image_name
    obj_len     --> image_name_len
    obj_md_name --> header_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: option 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: 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>