]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
os/bluestore: dedup is_allocated() and is_unallocated() of bluestore_blob_t
authorxie xingguo <xie.xingguo@zte.com.cn>
Wed, 14 Jun 2017 06:05:06 +0000 (14:05 +0800)
committerxie xingguo <xie.xingguo@zte.com.cn>
Thu, 15 Jun 2017 09:11:23 +0000 (17:11 +0800)
Signed-off-by: xie xingguo <xie.xingguo@zte.com.cn>
src/os/bluestore/bluestore_types.h

index f55342ffe114f674658a975c2804ba60e4ddcd88..8e2b77aeb4c48217872b819190e5b76bb2703938 100644 (file)
@@ -635,8 +635,10 @@ public:
     return p->offset + x_off;
   }
 
-  /// return true if the entire range is allocated (mapped to extents on disk)
-  bool is_allocated(uint64_t b_off, uint64_t b_len) const {
+  // validate whether or not the status of pextents within the given range
+  // meets the requirement(allocated or unallocated).
+  bool _validate_range(uint64_t b_off, uint64_t b_len,
+                       bool require_allocated) const {
     auto p = extents.begin();
     assert(p != extents.end());
     while (b_off >= p->length) {
@@ -647,11 +649,12 @@ public:
     b_len += b_off;
     while (b_len) {
       assert(p != extents.end());
-      if (!p->is_valid()) {
-       return false;
+      if (require_allocated != p->is_valid()) {
+        return false;
       }
+
       if (p->length >= b_len) {
-       return true;
+        return true;
       }
       b_len -= p->length;
       ++p;
@@ -659,29 +662,16 @@ public:
     assert(0 == "we should not get here");
   }
 
+  /// return true if the entire range is allocated
+  /// (mapped to extents on disk)
+  bool is_allocated(uint64_t b_off, uint64_t b_len) const {
+    return _validate_range(b_off, b_len, true);
+  }
+
   /// return true if the entire range is unallocated
-  ///  (not mapped to extents on disk)
+  /// (not mapped to extents on disk)
   bool is_unallocated(uint64_t b_off, uint64_t b_len) const {
-    auto p = extents.begin();
-    assert(p != extents.end());
-    while (b_off >= p->length) {
-      b_off -= p->length;
-      ++p;
-      assert(p != extents.end());
-    }
-    b_len += b_off;
-    while (b_len) {
-      assert(p != extents.end());
-      if (p->is_valid()) {
-       return false;
-      }
-      if (p->length >= b_len) {
-       return true;
-      }
-      b_len -= p->length;
-      ++p;
-    }
-    assert(0 == "we should not get here");
+    return _validate_range(b_off, b_len, false);
   }
 
   /// return true if the logical range has never been used