]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: fix fiemap on object with no data
authorSage Weil <sage@redhat.com>
Tue, 5 Jan 2016 14:00:32 +0000 (09:00 -0500)
committerSage Weil <sage@redhat.com>
Fri, 8 Jan 2016 18:10:18 +0000 (13:10 -0500)
Signed-off-by: Sage Weil <sage@redhat.com>
src/os/bluestore/BlueStore.cc
src/test/objectstore/store_test.cc

index 0d9fa24b1e2c591e55f96a20d8d68c811341d2cf..c8e0e1e9711bbb615e7e08597c140098db56e8a6 100644 (file)
@@ -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;
index 23073e3167c7ba64bf4c4b2840a3a36e84664fa6..4cb84934b657dd83964ff791ce1644695cee7e9a 100644 (file)
@@ -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<uint64_t,uint64_t> 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;