ceph: truncate snap id explicitly in ceph_getattr()

In ceph_getattr(), a ceph inode's snapshot id is returned in the
stat buffer's dev field.  That field is (at the moment anyway)
a 32-bit value, while a snapshot id is 64 bits.  This means that
if the snapshot id happens reach 2^32 or more, the value passed
to the user will be truncated.  This currently happens silently.

Do the truncation explicitly, to make it obvious that it is
occurring, and issue a warning if it ever does occur.

Signed-off-by: Alex Elder <elder@dreamhost.com>
ceph: fix some ceph_decode_need() calls

There are spots where ceph_decode_need() or ceph_encode_need() is
called with the wrong sizes, or not called when it should be.  In
some cases calling a "safe" decode operation is sufficient, but
otherwise change the code so the correct and intended overrun
safety checks are being made.

Move the accounting for the data copied into a ceph_pg_pool out
of osdmap_decode() and osdmap_apply_incremental() and into
__decode_pool() where the it actually gets "consumed."

Define ceph_encode_8_safe()--it's the only one missing from an
otherwise pretty complete set, and it was needed in one spot.

While in there, insert some whitespace to tidy up the alignment of
the line-terminating backslashes in some of the macro definitions.
Signed-off-by: Alex Elder <elder@dreamhost.com>
ceph: kill off ceph_vinop() macro

The macro ceph_vinop() takes a Linux inode and expands it into a
(ceph inode number, ceph snapshot id) pair.  It is used in
printf-style formats, together with a format string (%llx.%llx).

This expansion can be confusing, making the code appear to have a
mismatch between the number of format specifiers and the number of
things to be formatted.  There exists a pair of concise functions to
extract the inode and snapshot id: ceph_ino() and ceph_snap().

Replace all uses of ceph_vinop() with calls to those to functions
instead.

Signed-off-by: Alex Elder <elder@dreamhost.com>
ceph: use %llu for formatting all ceph inode numbers

A ceph inode number is a 64-bit unsigned value.  Make everywhere
that uses printf-style formatting consistently use %llu (or %llx) to
format them, and be explicit about casting the formatted value to
the (unsigned long long) type.

Signed-off-by: Alex Elder <elder@dreamhost.com>
ceph: use %llu for formatting all snapshot ids

A ceph snapshot id is a 64-bit unsigned value.  Make everywhere that
uses printf-style formatting consistently use %llu (or %llx) to
format them, and be explicit about casting the formatted value to
the (unsigned long long) type.

Signed-off-by: Alex Elder <elder@dreamhost.com>
ceph: use ceph_encode_need() where appropriate

There are a number of spots where ceph_decode_need() is used in a
context where we're doing encoding.  Convert these to use
ceph_encode_need().  The result is the same, but the code as written
was clearly wrong.  Convert a few functions so they use
ceph_encode_need() rather than open-coding its equivalent.
Finally, rearrange ceph_build_auth_request() so the "safe"
check is always done before any encoding is done.

Signed-off-by: Alex Elder <elder@dreamhost.com>
ceph: use safe decode calls when appropriate

Use ceph_decode_<sz>_safe() in spots where there are calls to
ceph_decode_need(<sz>) followed immediately by ceph_decode_<sz>().

Signed-off-by: Alex Elder <elder@dreamhost.com>
ceph: always use sizeof in ceph_decode_need() calls

In some cases plain integers are used in computing the number
of bytes neede in ceph_decode_need() and ceph_encode_need().
Put in place sizeof operators to make it clearer where the
numbers are coming from.

Signed-off-by: Alex Elder <elder@dreamhost.com>
ceph: kill encode_pagelist*() routines

There is a set of routines defined in <include/linux/pagelist.h>
that encapsulate encoding integral values and appending them to a
pagelist.  Two of them are never used, and the other three are
only used within "mds_client.c", and the remaining ones are
used exactly once apiece.

Get rid of these functions and replace their uses with their
open coded equivalent at their call sites.

The real motivation for doing this is that having these defined in
"pagelist.h" results in header file dependency problems in some
upcoming patches.

Signed-off-by: Alex Elder <elder@dreamhost.com>
ceph: define ceph_ino_t to represent ceph inode numbers

Define ceph_ino_t to be an opaque type representing a ceph inode
number.  Make use of it everywhere appropriate to more clearly show
which objects are actually ceph inode numbers (and not simply
arbitrary unsigned 64-bit values).  This includes explicitly casting
the reserved values for the root and .ceph directory inodes to this
type.

To further enforce the abstraction, define macros le64_to_ino(), and
ino_to_le64() for converting between on-disk/over-the-wire ceph
inodes (stored as type _le64) and in-core ceph_ino_t.  Define
ceph_encode_ino_safe() and ceph_decode_ino_safe() as well (though
only the encode function is used), for translating between in-core
ceph inodes and their representation in messages.

Signed-off-by: Alex Elder <elder@dreamhost.com>
ceph: use ceph_snapid_t to represent ceph snapshot ids

The type ceph_snapid_t is defined in <linux/ceph/rados.h> but it's
never used.  It's currently defined to have little-endian byte
order.

This is a useful type name, so change its definition to have CPU
byte order.  Use it.  everywhere appropriate to more clearly show
which objects are actually snapshot id's (and not simply arbitrary
unsigned 64-bit values).

To further enforce the abstraction, define macros le64_to_snapid(),
and snapid_to_le64() for converting between on-disk/over-the-wire
snapshot id's (stored as type _le64) and in-core ceph_snapid_t.
Define ceph_encode_snapid_safe() and ceph_decode_snapid_safe() as
well, for translating between in-core snapshot id's and their
representation in messages.

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