diff options
author | Sage Weil <sage@newdream.net> | 2012-04-19 13:26:32 -0700 |
---|---|---|
committer | Sage Weil <sage@newdream.net> | 2012-04-20 16:51:01 -0700 |
commit | 81af4e86184b214d5b508944b48d11d1394dabdb (patch) | |
tree | bf5745cc37f1e9f908a63b0b89cd1fc8222be251 /src/librbd.cc | |
parent | b94d6a6cf459478b27539eb8eccd30e19a67bbc5 (diff) | |
download | ceph-81af4e86184b214d5b508944b48d11d1394dabdb.tar.gz |
librbd: make discard invalidate the range in cache
Fed this to test_librbd_fsx and it was happy.
Signed-off-by: Sage Weil <sage@newdream.net>
Diffstat (limited to 'src/librbd.cc')
-rw-r--r-- | src/librbd.cc | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/librbd.cc b/src/librbd.cc index 56057435959..2a9d6e62156 100644 --- a/src/librbd.cc +++ b/src/librbd.cc @@ -1538,12 +1538,22 @@ int discard(ImageCtx *ictx, uint64_t off, uint64_t len) ictx->lock.Unlock(); uint64_t left = len; + vector<ObjectExtent> v; + if (ictx->object_cacher) + v.reserve(end_block - start_block + 1); + for (uint64_t i = start_block; i <= end_block; i++) { ictx->lock.Lock(); string oid = get_block_oid(ictx->header, i); uint64_t block_ofs = get_block_ofs(ictx->header, off + total_write); ictx->lock.Unlock(); uint64_t write_len = min(block_size - block_ofs, left); + + if (ictx->object_cacher) { + v.push_back(ObjectExtent(oid, block_ofs, write_len)); + v.back().oloc.pool = ictx->data_ctx.get_id(); + } + librados::ObjectWriteOperation write_op; if (block_ofs == 0 && write_len == block_size) write_op.remove(); @@ -1557,6 +1567,10 @@ int discard(ImageCtx *ictx, uint64_t off, uint64_t len) total_write += write_len; left -= write_len; } + + if (ictx->object_cacher) + ictx->object_cacher->truncate_set(ictx->object_set, v); + return total_write; } @@ -1797,6 +1811,10 @@ int aio_discard(ImageCtx *ictx, uint64_t off, size_t len, AioCompletion *c) if (r < 0) return r; + vector<ObjectExtent> v; + if (ictx->object_cacher) + v.reserve(end_block - start_block + 1); + c->get(); for (uint64_t i = start_block; i <= end_block; i++) { ictx->lock.Lock(); @@ -1807,6 +1825,12 @@ int aio_discard(ImageCtx *ictx, uint64_t off, size_t len, AioCompletion *c) AioBlockCompletion *block_completion = new AioBlockCompletion(cct, c, off, len, NULL); uint64_t write_len = min(block_size - block_ofs, left); + + if (ictx->object_cacher) { + v.push_back(ObjectExtent(oid, block_ofs, write_len)); + v.back().oloc.pool = ictx->data_ctx.get_id(); + } + if (block_ofs == 0 && write_len == block_size) block_completion->write_op.remove(); else if (block_ofs + write_len == block_size) @@ -1827,6 +1851,9 @@ int aio_discard(ImageCtx *ictx, uint64_t off, size_t len, AioCompletion *c) } r = 0; done: + if (ictx->object_cacher) + ictx->object_cacher->truncate_set(ictx->object_set, v); + c->finish_adding_completions(); c->put(); |