]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
objectcacher: implement Object::discard()
authorSage Weil <sage@newdream.net>
Thu, 19 Apr 2012 23:15:17 +0000 (16:15 -0700)
committerSage Weil <sage@newdream.net>
Fri, 20 Apr 2012 23:51:01 +0000 (16:51 -0700)
Discard a range of bytes from an object.

Signed-off-by: Sage Weil <sage@newdream.net>
src/osdc/ObjectCacher.cc
src/osdc/ObjectCacher.h

index 0d3e7e6602b95ae89386f98ed4b83372882f55b4..25931dd8334020adafbfef1c0acf4c5dc85fd29a 100644 (file)
@@ -408,6 +408,40 @@ void ObjectCacher::Object::truncate(loff_t s)
   }
 }
 
+void ObjectCacher::Object::discard(loff_t off, loff_t len)
+{
+  ldout(oc->cct, 10) << "discard " << *this << " " << off << "~" << len << dendl;
+
+  map<loff_t, BufferHead*>::iterator p = data.lower_bound(off);
+  if (p != data.begin() &&
+      (p == data.end() || p->first > off)) {
+    p--;     // might overlap!
+    if (p->first + p->second->length() <= off)
+      p++;   // doesn't overlap.
+  }
+
+  while (p != data.end()) {
+    BufferHead *bh = p->second;
+    if (bh->start() >= off + len)
+      break;
+
+    // split bh at truncation point?
+    if (bh->start() < off) {
+      split(bh, off);
+      p++;
+      continue;
+    }
+
+    assert(bh->start() >= off);
+    if (bh->end() > off + len) {
+      split(bh, off + len);
+    }
+
+    p++;
+    oc->bh_remove(this, bh);
+  }
+}
+
 
 
 /*** ObjectCacher ***/
index 767f73c3abfdf13dbbd1a45df0e3362c55c69b77..800a8b7eecc782352b417ebaa5fccb7244e16472 100644 (file)
@@ -249,7 +249,7 @@ class ObjectCacher {
     BufferHead *map_write(OSDWrite *wr);
     
     void truncate(loff_t s);
-
+    void discard(loff_t off, loff_t len);
   };