Changeset 1132 for Whitix

Show
Ignore:
Timestamp:
10/14/08 19:37:00 (1 month ago)
Author:
mwhitworth
Message:

Add a global numDirty integer to help with flushing blocks to disk.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • Whitix/branches/keobject/fs/vfs/bcache.c

    r1094 r1132  
    1818 
    1919#include <typedefs.h> 
     20#include <malloc.h> 
    2021#include <fs/vfs.h> 
    2122#include <error.h> 
     
    4041DWORD cacheSize=0; 
    4142extern struct DevClass storageClass; 
     43int numDirty=0; 
    4244 
    4345static void BufferWait(struct Buffer* buffer); 
     
    238240                KePrint("BlockSendRequest: error (%d) reading %u\n",err,request->sector); 
    239241                err=-EIO; 
    240         }        
     242        } 
     243         
     244//      if (request->type == REQUEST_WRITE && request->sector < 10) 
     245//              KePrint("(%u) ", request->sector); 
    241246 
    242247        return err; 
     
    325330int BlockWrite(struct StorageDevice* device,struct Buffer* buffer) 
    326331{ 
     332        if (!(buffer->flags & (1 << BUFFER_DIRTY))) 
     333                numDirty++; 
     334 
    327335        /* Just signal that the buffer is dirty, and let BufferFlusher write it to disk in the near future as an update */ 
    328336        buffer->flags |= (1 << BUFFER_DIRTY); 
    329337 
    330         if (bufferFlusher) 
    331                 ThrResumeThread(bufferFlusher); 
    332  
     338        if (numDirty == 1) 
     339        { 
     340                if (bufferFlusher) 
     341                        ThrResumeThread(bufferFlusher); 
     342        } 
     343         
    333344        return 0; 
    334345} 
     
    384395{ 
    385396        DWORD flags, i; 
    386         struct Buffer* buff; 
     397        struct Buffer* buff, *buff2; 
     398 
     399//      KePrint("BlockSyncDevice(%s), numDirty = %d\n", KeObjGetName(&device->device.object), numDirty); 
    387400 
    388401        IrqSaveFlags(flags); 
     
    393406 
    394407                /* Write all the blocks belonging to device to disk */ 
    395                 ListForEachEntry(buff, head, list) 
     408                ListForEachEntrySafe(buff, buff2, head, list) 
    396409                { 
    397410                        if (BufferDirty(buff)) 
    398411                        { 
     412                                --numDirty; 
    399413                                /* For each block, call the respective StorageDevice write function */ 
    400414                                DoBlockWrite(buff->device,buff); 
     
    411425int BlockSyncAll() 
    412426{ 
    413 //      struct StorageDevice* sDevice; 
    414  
    415         /* Sync all vnodes */ 
    416 //      extern void VNodeSyncAll(); 
    417 //      VNodeSyncAll(); 
    418  
    419427        struct StorageDevice* sDevice; 
    420428        struct KeObject* object, *object2; 
     
    460468        while (1) 
    461469        { 
    462                 ThrSuspendThread(currThread); 
    463                 ThrSchedule(); 
     470                if (!numDirty) 
     471                { 
     472                        ThrSuspendThread(currThread); 
     473                        ThrSchedule(); 
     474                } 
    464475                 
    465476                BlockSyncAll(); 
     
    477488        struct ListHead* head=BUFFER_HASH(buffer->device, buffer->blockNum); 
    478489 
    479         ListAdd(&buffer->list, head); 
     490        ListAddTail(&buffer->list, head); 
    480491} 
    481492