]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ebofs trim_from_cache(object, start, len)
authorsageweil <sageweil@29311d96-e01e-0410-9327-a35deaab8ce9>
Mon, 5 Feb 2007 18:08:27 +0000 (18:08 +0000)
committersageweil <sageweil@29311d96-e01e-0410-9327-a35deaab8ce9>
Mon, 5 Feb 2007 18:08:27 +0000 (18:08 +0000)
git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@1077 29311d96-e01e-0410-9327-a35deaab8ce9

trunk/ceph/ebofs/BufferCache.cc
trunk/ceph/ebofs/BufferCache.h
trunk/ceph/ebofs/Ebofs.cc
trunk/ceph/ebofs/Ebofs.h
trunk/ceph/osd/ObjectStore.h

index cee7f2c12ce79789d82e1da4fe9265d163c55264..fa48c08b18a09122a11265ecf4750e1e52d26145 100644 (file)
@@ -530,6 +530,23 @@ int ObjectCache::scan_versions(block_t start, block_t len,
 }
 */
 
+void ObjectCache::touch_bottom(block_t bstart, block_t blast)
+{
+  for (map<block_t, BufferHead*>::iterator p = data.lower_bound(bstart);
+       p != data.end();
+       ++p) {
+    BufferHead *bh = p->second;
+    
+    // don't trim unless it's entirely in our range
+    if (bh->start() < bstart) continue;
+    if (bh->end() > blast) break;     
+    
+    dout(12) << "moving " << *bh << " to bottom of lru" << endl;
+    bc->touch_bottom(bh);  // move to bottom of lru list
+  }
+}  
+
+
 void ObjectCache::truncate(block_t blocks, version_t super_epoch)
 {
   dout(7) << "truncate " << object_id 
index 922c5e531ee566837b94f0f158f4f6e063fa688c..a9bf2a5c6a951f65f382ad611e9073a3cb687bf4 100644 (file)
@@ -405,6 +405,7 @@ class ObjectCache {
                 interval_set<block_t>& alloc,
                 map<block_t, BufferHead*>& hits,
                 version_t super_epoch);   // can write to these.
+  void touch_bottom(block_t bstart, block_t blast);
 
   BufferHead *split(BufferHead *bh, block_t off);
 
@@ -509,6 +510,12 @@ class BufferCache {
     } else
       lru_rest.lru_touch(bh);
   }
+  void touch_bottom(BufferHead *bh) {
+    if (bh->is_dirty()) {
+      lru_dirty.lru_bottouch(bh);
+    } else
+      lru_rest.lru_bottouch(bh);
+  }
   void remove_bh(BufferHead *bh) {
     bh->get_oc()->remove_bh(bh);
     stat_sub(bh);
index 64485b818e20421d40689019cb3279dcc719f94f..a190b83387385e3fbe06f2705dd8bf6a8ef9cf44 100644 (file)
@@ -1870,6 +1870,35 @@ int Ebofs::_is_cached(object_t oid, off_t off, size_t len)
   */
 }
 
+void Ebofs::trim_from_cache(object_t oid, off_t off, size_t len)
+{
+  ebofs_lock.Lock();
+  _trim_from_cache(oid, off, len);
+  ebofs_lock.Unlock();
+}
+
+void Ebofs::_trim_from_cache(object_t oid, off_t off, size_t len)
+{
+  Onode *on = 0;
+  if (onode_map.count(oid) == 0) {
+    dout(7) << "_trim_from_cache " << oid << " " << off << "~" << len << " ... onode not in cache  " << endl;
+    return; 
+  } 
+  
+  if (!on->have_oc()) 
+    return; // nothing is cached. 
+
+  // map to blocks
+  block_t bstart = off / EBOFS_BLOCK_SIZE;
+  block_t blast = (len+off-1) / EBOFS_BLOCK_SIZE;
+
+  ObjectCache *oc = on->get_oc(&bc);
+  oc->touch_bottom(bstart, blast);
+  
+  return;
+}
+
+
 int Ebofs::read(object_t oid, 
                 off_t off, size_t len,
                 bufferlist& bl)
@@ -2017,6 +2046,15 @@ unsigned Ebofs::apply_transaction(Transaction& t, Context *onsafe)
       }
       break;
 
+    case Transaction::OP_TRIMCACHE:
+      {
+        object_t oid = t.oids.front(); t.oids.pop_front();
+        off_t offset = t.offsets.front(); t.offsets.pop_front();
+        size_t len = t.lengths.front(); t.lengths.pop_front();
+        _trim_from_cache(oid, offset, len);
+      }
+      break;
+
     case Transaction::OP_TRUNCATE:
       {
         object_t oid = t.oids.front(); t.oids.pop_front();
index f19130a1aab2e26810386e0e42a342c835fe1abc..bf7311e1d4c93820b3cd23cf31ea3fbdf56cdddc 100644 (file)
@@ -245,6 +245,7 @@ class Ebofs : public ObjectStore {
   int is_cached(object_t oid, off_t off, size_t len);
 
   int write(object_t oid, off_t off, size_t len, bufferlist& bl, Context *onsafe);
+  void trim_from_cache(object_t oid, off_t off, size_t len);
   int truncate(object_t oid, off_t size, Context *onsafe=0);
   int truncate_front(object_t oid, off_t size, Context *onsafe=0);
   int remove(object_t oid, Context *onsafe=0);
@@ -306,6 +307,7 @@ private:
 
   bool _write_will_block();
   int _write(object_t oid, off_t off, size_t len, bufferlist& bl);
+  void _trim_from_cache(object_t oid, off_t off, size_t len);
   int _truncate(object_t oid, off_t size);
   int _truncate_front(object_t oid, off_t size);
   int _remove(object_t oid);
index d5ba667145e34da1e0e99bf2d874b7a2225485a5..7e416494690dbc50dff33f320db6c1c087de3765 100644 (file)
@@ -84,6 +84,8 @@ public:
     static const int OP_RMATTR =       16;  // oid, attrname
     static const int OP_CLONE =        17;  // oid, newoid
 
+    static const int OP_TRIMCACHE =    18;  // oid, offset, len
+
     static const int OP_MKCOLL =       20;  // cid
     static const int OP_RMCOLL =       21;  // cid
     static const int OP_COLL_ADD =     22;  // cid, oid
@@ -142,6 +144,13 @@ public:
       lengths.push_back(len);
       bls.push_back(bl);
     }
+    void trim_from_cache(object_t oid, off_t off, size_t len) {
+      int op = OP_TRIMCACHE;
+      ops.push_back(op);
+      oids.push_back(oid);
+      offsets.push_back(off);
+      lengths.push_back(len);
+    }
     void truncate(object_t oid, off_t off) {
       int op = OP_TRUNCATE;
       ops.push_back(op);
@@ -276,6 +285,15 @@ public:
         }
         break;
 
+      case Transaction::OP_TRIMCACHE:
+        {
+          object_t oid = t.oids.front(); t.oids.pop_front();
+          off_t offset = t.offsets.front(); t.offsets.pop_front();
+          size_t len = t.lengths.front(); t.lengths.pop_front();
+          trim_from_cache(oid, offset, len);
+        }
+        break;
+
       case Transaction::OP_TRUNCATE:
         {
           object_t oid = t.oids.front(); t.oids.pop_front();
@@ -428,6 +446,8 @@ public:
                     off_t offset, size_t len,
                     bufferlist& bl, 
                     Context *onsafe) = 0;//{ return -1; }
+  virtual void trim_from_cache(object_t oid, 
+                              off_t offset, size_t len) { }
 
   virtual int setattr(object_t oid, const char *name,
                       const void *value, size_t size,