From 3974bb30d573b5c840f496c9cca1c44e92d358bb Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 5 Jan 2016 09:00:32 -0500 Subject: [PATCH] os/bluestore: fix fiemap on object with no data Signed-off-by: Sage Weil --- src/os/bluestore/BlueStore.cc | 8 +++++--- src/test/objectstore/store_test.cc | 33 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 0d9fa24b1e2c5..c8e0e1e9711bb 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -2531,9 +2531,11 @@ int BlueStore::fiemap( ++bp; continue; } - // we are seeing a hole, time to add an entry to fiemap. - m[start] = offset - start; - dout(20) << __func__ << " out " << start << "~" << m[start] << dendl; + if (offset - start) { + // we are seeing a hole, time to add an entry to fiemap. + m[start] = offset - start; + dout(20) << __func__ << " out " << start << "~" << m[start] << dendl; + } offset += x_len; start = offset; len -= x_len; diff --git a/src/test/objectstore/store_test.cc b/src/test/objectstore/store_test.cc index 23073e3167c7b..4cb84934b657d 100644 --- a/src/test/objectstore/store_test.cc +++ b/src/test/objectstore/store_test.cc @@ -215,6 +215,39 @@ TEST_P(StoreTest, IORemount) { } } +TEST_P(StoreTest, FiemapEmpty) { + ObjectStore::Sequencer osr("test"); + coll_t cid; + int r = 0; + ghobject_t oid(hobject_t(sobject_t("fiemap_object", CEPH_NOSNAP))); + { + ObjectStore::Transaction t; + t.create_collection(cid, 0); + t.touch(cid, oid); + t.truncate(cid, oid, 100000); + r = store->apply_transaction(&osr, t); + ASSERT_EQ(r, 0); + } + { + bufferlist bl; + store->fiemap(cid, oid, 0, 100000, bl); + map m, e; + bufferlist::iterator p = bl.begin(); + ::decode(m, p); + cout << " got " << m << std::endl; + e[0] = 100000; + EXPECT_TRUE(m == e || m.empty()); + } + { + ObjectStore::Transaction t; + t.remove(cid, oid); + t.remove_collection(cid); + cerr << "remove collection" << std::endl; + r = store->apply_transaction(&osr, t); + ASSERT_EQ(r, 0); + } +} + TEST_P(StoreTest, SimpleMetaColTest) { ObjectStore::Sequencer osr("test"); coll_t cid; -- 2.39.5