]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: make tail cache a bit smarter
authorSage Weil <sage@redhat.com>
Mon, 16 May 2016 00:30:44 +0000 (20:30 -0400)
committerSage Weil <sage@redhat.com>
Wed, 1 Jun 2016 15:38:49 +0000 (11:38 -0400)
This is really a stop-gap.  Since we are doing reads in the pre-commit
write path, we need to have some sort of buffer cache so that a sequence
of writes in the same transaction can remain coherent (the second write
must "read" the first write in order to fill out the chunk).

Signed-off-by: Sage Weil <sage@redhat.com>
src/os/bluestore/BlueStore.cc

index 4ca926f0996b12ac8a455b704fa3a5f91107081b..8ae9697b786dfe1cab7e9da5188b2de906923685 100644 (file)
@@ -5267,22 +5267,35 @@ void BlueStore::_do_write_small(
   bufferlist bl;
   blp.copy(length, bl);
 
-  // use tail cache?  only worry about a perfect append for now.
-  // (fixme: we could also handle near-appends that fall within the
-  // same block or read_block or whatever.)
-  if (offset == o->onode.size &&
+  // use tail cache?
+  if (offset >= o->onode.size &&
       o->tail_bl.length() &&
-      offset == o->tail_offset + o->tail_bl.length()) {
-    // use tail?
-    bufferlist t = o->tail_bl;
-    t.claim_append(bl);
-    bl.swap(t);
-    offset -= o->tail_bl.length();
-    length += o->tail_bl.length();
-    dout(10) << __func__ << "  using tail_bl 0x" << std::hex
-            << o->tail_offset << "~0x" << o->tail_bl.length()
-            << ", write is now 0x" << offset << "~0x" << length
-            << std::dec << dendl;
+      offset > o->tail_offset) {
+    uint64_t tend = o->tail_offset + o->tail_bl.length();
+    uint64_t tlen = 0, zlen = 0;
+    if (offset <= tend) {
+      tlen = offset - o->tail_offset;
+      zlen = 0;
+    } else if (offset < ROUND_UP_TO(tend, min_alloc_size)) {
+      tlen = o->tail_bl.length();
+      zlen = offset - tend;
+    }
+    if (tlen || zlen) {
+      bufferlist t;
+      t.substr_of(o->tail_bl, 0, tlen);
+      if (zlen) {
+       t.append_zero(zlen);
+      }
+      t.claim_append(bl);
+      bl.swap(t);
+      offset -= tlen + zlen;
+      length += tlen + zlen;
+      dout(10) << __func__ << "  using tail_bl 0x" << std::hex
+              << o->tail_offset << "~0x" << tlen
+              << ", 0x" << zlen
+              << " zeros, write is now 0x" << offset << "~0x" << length
+              << std::dec << dendl;
+    }
   }
 
   // look for an existing mutable blob we can use