]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
*** empty log message ***
authorsage <sage@29311d96-e01e-0410-9327-a35deaab8ce9>
Tue, 21 Feb 2006 19:37:21 +0000 (19:37 +0000)
committersage <sage@29311d96-e01e-0410-9327-a35deaab8ce9>
Tue, 21 Feb 2006 19:37:21 +0000 (19:37 +0000)
git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@662 29311d96-e01e-0410-9327-a35deaab8ce9

ceph/ebofs/Allocator.cc
ceph/ebofs/Allocator.h

index a0d92512e97718d1c1caba28898b9f74bd9ca289..e1dd8de38863296b7e65ab2c8516595cbc0de680 100644 (file)
@@ -64,12 +64,13 @@ void Allocator::dump_freelist()
 }
 
 
-int Allocator::find(Extent& ex, int bucket, block_t num, block_t near, bool fwdonly)
+int Allocator::find(Extent& ex, int bucket, block_t num, block_t near, int dir)
 {
   Table<block_t,block_t>::Cursor cursor(fs->free_tab[bucket]);
   bool found = false;
 
-  if (fs->free_tab[bucket]->find( near, cursor ) >= 0) {
+  if ((dir == DIR_ANY || dir == DIR_FWD) && 
+         fs->free_tab[bucket]->find( near, cursor ) >= 0) {
        // look to the right
        do {
          if (cursor.current().value >= num)
@@ -77,7 +78,8 @@ int Allocator::find(Extent& ex, int bucket, block_t num, block_t near, bool fwdo
        } while (!found && cursor.move_right() > 0);
   }
 
-  if (!found && !fwdonly) {
+  if ((dir == DIR_ANY || dir == DIR_BACK) && 
+         !found) {
        // look to the left
        fs->free_tab[bucket]->find( near, cursor );
 
@@ -99,10 +101,10 @@ int Allocator::allocate(Extent& ex, block_t num, block_t near)
 {
   dump_freelist();
 
-  bool fwd = false;
+  int dir = DIR_ANY; // no dir
   if (near == NEAR_LAST_FWD) {
        near = last_pos;
-       fwd = true;
+       dir = DIR_FWD;  // fwd
   }
   else if (near == NEAR_LAST)
        near = last_pos;
@@ -113,7 +115,7 @@ int Allocator::allocate(Extent& ex, block_t num, block_t near)
 
        // look for contiguous extent
        for (bucket = pick_bucket(num); bucket < EBOFS_NUM_FREE_BUCKETS; bucket++) {
-         if (find(ex, bucket, num, near, fwd) >= 0) {
+         if (find(ex, bucket, num, near, dir) >= 0) {
                // yay!
                
                // remove original
@@ -162,8 +164,8 @@ int Allocator::allocate(Extent& ex, block_t num, block_t near)
          }
        }
 
-       if (!fwd) break;
-       fwd = false;
+       if (dir == DIR_BACK || dir == DIR_ANY) break;
+       dir = DIR_BACK;
   }
 
   // ok, find partial extent instead.
index bc61cad9e205d1cf999bb89fd23183d04a3679d5..5229863476219ebc1e525a4856192c92f3a1278a 100644 (file)
@@ -26,6 +26,10 @@ public:
   const static block_t NEAR_LAST = 0;     
   const static block_t NEAR_LAST_FWD = 1;   
   
+  const static int DIR_ANY = 0;
+  const static int DIR_FWD = 2;
+  const static int DIR_BACK = 1;
+
 protected:
   Ebofs *fs;
   block_t      last_pos;
@@ -44,7 +48,7 @@ protected:
        return b;
   }
 
-  int find(Extent& ex, int bucket, block_t num, block_t near, bool fwdonly=false);
+  int find(Extent& ex, int bucket, block_t num, block_t near, int dir = DIR_ANY);
 
   void dump_freelist();