]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: _do_zero_tail_extent helper
authorSage Weil <sage@redhat.com>
Mon, 28 Mar 2016 17:23:56 +0000 (13:23 -0400)
committerSage Weil <sage@redhat.com>
Wed, 30 Mar 2016 15:23:15 +0000 (11:23 -0400)
We do this from both _do_truncate and _do_write.  No
functional change here.

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

index 45a1b2f45acbb5a396348bfc3b90a56a3e7702bc..4add5a1bcd7c8bec759fd58a9065165ca34e9c2c 100644 (file)
@@ -5447,22 +5447,14 @@ int BlueStore::_do_write(
 
   bp = o->onode.seek_extent(orig_offset);
 
-  // zero tail of previous existing extent?
-  // (this happens if the old eof was partway through a previous extent,
-  // and we implicitly zero the rest of it by writing to a larger offset.)
   if (orig_offset > o->onode.size) {
-    uint64_t end = ROUND_UP_TO(o->onode.size, block_size);
-    map<uint64_t, bluestore_extent_t>::iterator pp = o->onode.find_extent(end);
-    if (orig_offset > end &&
-       pp != o->onode.block_map.end() &&
+    // zero tail of previous existing extent?
+    map<uint64_t, bluestore_extent_t>::iterator pp =
+      o->onode.find_extent(o->onode.size);
+    if (pp != o->onode.block_map.end() &&
        pp != bp) {
       assert(pp->first < bp->first);
-      uint64_t x_off = end - pp->first;
-      uint64_t x_len = pp->second.length - x_off;
-      dout(10) << __func__ << " zero tail " << x_off << "~" << x_len
-              << " of prior extent " << pp->first << ": " << pp->second
-              << dendl;
-      bdev->aio_zero(pp->second.offset + x_off, x_len, &txc->ioc);
+      _do_zero_tail_extent(txc, o, orig_offset, pp);
     }
   }
 
@@ -5757,6 +5749,36 @@ int BlueStore::_zero(TransContext *txc,
   return r;
 }
 
+void BlueStore::_do_zero_tail_extent(
+  TransContext *txc,
+  OnodeRef& o,
+  uint64_t offset,
+  map<uint64_t, bluestore_extent_t>::iterator pp)
+{
+  const uint64_t block_size = bdev->get_block_size();
+  const uint64_t block_mask = ~(block_size - 1);
+
+  assert(offset > o->onode.size);
+  assert(pp != o->onode.block_map.end());
+
+  // we currently assume that any partial tail block is always zeroed
+  uint64_t end = ROUND_UP_TO(o->onode.size, block_size);
+
+  // we assume the caller will handle any partial block they start with
+  offset &= block_mask;
+
+  // zero tail of previous existing extent?
+  // (this happens if the old eof was partway through a previous extent,
+  // and we implicitly zero the rest of it by writing to a larger offset.)
+  if (offset > end) {
+    uint64_t x_off = end - pp->first;
+    uint64_t x_len = pp->second.length - x_off;
+    dout(10) << __func__ << " zero tail " << x_off << "~" << x_len
+            << " of prior extent " << pp->first << ": " << pp->second
+            << dendl;
+    bdev->aio_zero(pp->second.offset + x_off, x_len, &txc->ioc);
+  }
+}
 
 int BlueStore::_do_zero(TransContext *txc,
                        CollectionRef& c,
@@ -5778,20 +5800,11 @@ int BlueStore::_do_zero(TransContext *txc,
   uint64_t block_size = bdev->get_block_size();
   map<uint64_t,bluestore_extent_t>::iterator bp = o->onode.seek_extent(offset);
 
-  // zero tail of previous existing extent?
-  // (this happens if the old eof was partway through a previous extent,
-  // and we implicitly zero the rest of it by writing to a larger offset.)
   if (offset > o->onode.size) {
-    uint64_t end = ROUND_UP_TO(o->onode.size, block_size);
-    map<uint64_t, bluestore_extent_t>::iterator pp = o->onode.find_extent(end);
-    if (offset > end &&
-       pp != o->onode.block_map.end()) {
-      uint64_t x_off = end - pp->first;
-      uint64_t x_len = pp->second.length - x_off;
-      dout(10) << __func__ << " zero tail " << x_off << "~" << x_len
-              << " of prior extent " << pp->first << ": " << pp->second
-              << dendl;
-      bdev->aio_zero(pp->second.offset + x_off, x_len, &txc->ioc);
+    map<uint64_t, bluestore_extent_t>::iterator pp =
+      o->onode.find_extent(o->onode.size);
+    if (pp != o->onode.block_map.end()) {
+      _do_zero_tail_extent(txc, o, offset, pp);
     }
   }
 
index 124c06c938072b3d6b93e8d7091f1d8a8cb3b5a9..c311951cedd801528fde1dc0c48690a7f1476d2c 100644 (file)
@@ -898,6 +898,11 @@ private:
                     CollectionRef &c,
                     OnodeRef o,
                     uint64_t offset, uint64_t length);
+  void _do_zero_tail_extent(
+    TransContext *txc,
+    OnodeRef& o,
+    uint64_t offset,
+    map<uint64_t, bluestore_extent_t>::iterator pp);
   int _do_zero(TransContext *txc,
               CollectionRef& c,
               OnodeRef& o,