doc: add JavaDoc to Sphinx

Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
doc: fix warning in JavaDoc
librbd: complete Context on error from ObjectCacher::readx

We were immediately completing for positive (successful) returns, but not
on error.  Do errors too, so that we don't drop ENOENT.

Signed-off-by: Sage Weil <sage@inktank.com>
librbd/AioCompletion: ensure read result assembly happens last

When reading from the cache, we can have a situation where each AioRead
completes as it is added to the completion, causing the final buffer
assembly to happen before the other requests are added.  It needs to run
only after we are finished adding requests.  Move it into a helper and
ensure it is only called when pending_count == 0 *and* building == false.

Signed-off-by: Sage Weil <sage@inktank.com>
osdc/Striper: more debug

Signed-off-by: Sage Weil <sage@inktank.com>
osdc/WritebackHandler: add may_copy_on_write()

Implement a new method to tell us whether a read to a particular region
could be affected by a write-triggered copy-on-write.

Signed-off-by: Sage Weil <sage@inktank.com>
librbd: remove parent logic from reads beneath the cache

Make reads beneath the cache (in the WritebackHandler) read the plain
objects beneath us.  Let the read-from-parent logic *above* the cache
handle the layering logic.

Signed-off-by: Sage Weil <sage@inktank.com>
osdc/ObjectCacher: add object exists flag

Clear it (set to false) on ENOENT.

Reset it (to true) on discard().
Reset it (to true) on write completion.
Reset it (to true) on release.

Signed-off-by: Sage Weil <sage@inktank.com>
osdc/ObjectCacher: clear complete if may-cow and !exists

If the object doesn't/didn't exist, and we finish a write, and the write
may have triggered a copy-on-write, clear the complete flag, since there
may be new data beneath us that we didn't see before.

Signed-off-by: Sage Weil <sage@inktank.com>
osdc/ObjectCacher: remove BufferHeads on ENOENT

If we try a read and the object doesn't exist, toss out the BufferHead
(instead of keeping useless ZERO bh's around).

Signed-off-by: Sage Weil <sage@inktank.com>
osdc/ObjectCacher: return ENOENT

If we are given a single ObjectExtent, and the object doesn't exist,
and we don't have any dirty|tx buffers, return ENOENT to the caller.

This lets librbd's layering logic do its thing.

Signed-off-by: Sage Weil <sage@inktank.com>
osdc/ObjectCacher: trigger copy-on-write before read

If we are trying to read from an object, and it doesn't exist, but we have
dirty buffers, and a write could trigger copy-on-write, then flush our
write first to trigger the copy-on-write before we proceed with the read.
This ensures that a pattern like

CLONE
WRITE 0~10  (into cache)
READ  10~20

will flush the write and trigger a cow so that the read will see parent
data.

Signed-off-by: Sage Weil <sage@inktank.com>
test_librbd: add additoinal clone test

Test that reads will trigger a cow both when overlapping and not
overlapping with buffered writes.

Signed-off-by: Sage Weil <sage@inktank.com>
osdc/ObjectCacher: wake all rx waiters on ENOENT

If we discover an object doesn't exist, wake all rx waiters at the same
time.  This prevents a situation like:

- read extent A
- read extent B
- reply from A, ENOENT, exists=false
- read extent B (again), immediately tell caller ENOENT
- reply from B, ENOENT, tell caller ENOENT

Fixes: #3435
Signed-off-by: Sage Weil <sage@inktank.com>
librbd: better debug output

Signed-off-by: Sage Weil <sage@inktank.com>
librbd: fix memory leak on read

We were leaking the rados completion, which includes a reference to actual
data.

Fixes: #3445
Signed-off-by: Sage Weil <sage@inktank.com>
librbd: no need to scan snapshots for parents during remove

At this point we already know no snapshots exist.

Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
librbd: take parent lock when examining fields it protects

This hasn't actually caused any problems, I just noticed
while looking through the code.

Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
client: fix path_walk for directory symlinks

Signed-off-by: Sage Weil <sage@inktank.com>
client: simplify/fix symlink loop check

Checking that we visit a symlink isn't correct; for example, the below is
valid, and we visit /b twice.

 /a/b -> c
 /a/c/d -> /a/b

In order to do this "correctly", I think we would need to track the pairs
of paths and symlinks we are resolving.  But, reading the man pages,
ELOOP is actually just defined as traversing more than MAXSYMLINKS syms.
(It appears to be 20 on my machine.)

Just do that instead.

Signed-off-by: Sage Weil <sage@inktank.com>