Show
Ignore:
Timestamp:
07/09/08 15:26:36 (5 months ago)
Author:
mwhitworth
Message:

Add to journal code. Support for per-journal threads, flushing of metadata, and start of commit code.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • Whitix/branches/fs/fs/journal/transaction.c

    r756 r759  
    1818 
    1919#include <fs/journal.h> 
     20#include <fs/vfs.h> 
    2021#include <module.h> 
    2122#include <print.h> 
     
    5152        ret->state=JTRANS_RUNNING; 
    5253        ret->transId=journal->transSequence++; 
     54        ret->expires=currTime.seconds+JOURN_COMMIT_INTERVAL; 
     55 
     56        /* TODO: Move to constructor. */ 
     57        INIT_LIST_HEAD(&ret->reservedList); 
     58        INIT_LIST_HEAD(&ret->metaDataList); 
    5359 
    5460        /* TODO: Set up timer. */ 
     
    148154SYMBOL_EXPORT(JournalStart); 
    149155 
     156int JournalStop(struct JournalHandle* handle) 
     157{ 
     158        struct JournalTrans* trans=handle->transaction; 
     159        struct Journal* journal=trans->journal; 
     160 
     161        currThread->currHandle=NULL; 
     162 
     163        trans->updates--; 
     164        trans->outstandingBlocks-=handle->numBlocks; 
     165 
     166        if (!trans->updates) 
     167        { 
     168                /* Wake up waiters. */ 
     169        } 
     170 
     171        if (handle->sync == 1 || currTime.seconds >= trans->expires) 
     172        { 
     173                int id=trans->transId; 
     174 
     175                JournalStartCommit(journal, trans); 
     176 
     177                if (handle->sync == 1) 
     178                        JournalWaitCommit(journal, id); 
     179        } 
     180 
     181        MemCacheFree(journHandleCache, handle); 
     182 
     183        return 0; 
     184} 
     185 
     186SYMBOL_EXPORT(JournalStop); 
     187 
     188void JournalFileBuffer(struct JournalHead* head, struct JournalTrans* trans, int type) 
     189{ 
     190        struct ListHead* list; 
     191 
     192        /* Already filed? */ 
     193        if (head->transaction && head->list == type) 
     194                return; 
     195 
     196        /*  
     197         * It's already in this transaction, but on a different list, so we remove it 
     198         * before adding it to the other list. 
     199         */ 
     200 
     201        if (head->transaction == trans && head->list > 0 && head->list != type) 
     202                ListRemove(&head->next); 
     203 
     204        switch (type) 
     205        { 
     206                case JOURN_RESERVED: 
     207                        list=&trans->reservedList; 
     208                        break; 
     209 
     210                case JOURN_METADATA: 
     211                        list=&trans->metaDataList; 
     212                        break; 
     213 
     214                default: 
     215                        KePrint("FileBuffer: handle %d!\n", type); 
     216                        return; 
     217        } 
     218 
     219        ListAddTail(&head->next, list); 
     220        head->list=type; 
     221} 
     222 
    150223/* Intent to modify a buffer for metadata update. */ 
    151224 
     
    158231        head=JournalAddHeader(buffer); 
    159232 
     233        JournalLock(journal); 
     234 
     235        /* Check if buffer is locked. */ 
     236 
     237        if (!head->transaction) 
     238        { 
     239                head->transaction=trans; 
     240                JournalFileBuffer(head, trans, JOURN_RESERVED); 
     241        } 
     242 
     243        JournalUnlock(journal); 
     244 
    160245        return 0; 
    161246} 
    162247 
    163248SYMBOL_EXPORT(JournalGetWriteAccess); 
     249 
     250int JournalDirtyMetadata(struct JournalHandle* handle, struct Buffer* buffer) 
     251{ 
     252        struct JournalTrans* trans=handle->transaction; 
     253        struct Journal* journal=trans->journal; 
     254        struct JournalHead* head=BufferToJournHead(buffer); 
     255 
     256        JournalLock(journal); 
     257 
     258        JournalFileBuffer(head, trans, JOURN_METADATA); 
     259 
     260        JournalUnlock(journal); 
     261 
     262        return 0; 
     263} 
     264 
     265SYMBOL_EXPORT(JournalDirtyMetadata); 
     266 
     267int JournalForceCommit(struct Journal* journal) 
     268{ 
     269        struct JournalHandle* handle; 
     270 
     271        handle=JournalStart(journal, 1); 
     272 
     273        handle->sync=1; 
     274 
     275        /* The sync forces the commit to disk. */ 
     276        JournalStop(handle); 
     277 
     278        return 0; 
     279} 
     280 
     281SYMBOL_EXPORT(JournalForceCommit);