home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / kernel / lfs / lfsCacheBackend.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-19  |  5.3 KB  |  223 lines

  1. /* 
  2.  * lfsCacheBackend.c --
  3.  *
  4.  *    Routines for file cache backend of an LFS file system.
  5.  *
  6.  * Copyright 1990 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: /cdrom/src/kernel/Cvsroot/kernel/lfs/lfsCacheBackend.c,v 1.2 92/03/06 11:56:49 mgbaker Exp $ SPRITE (Berkeley)";
  18. #endif /* not lint */
  19.  
  20. #include <sprite.h>
  21. #include <lfsInt.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24.  
  25. static Fscache_BackendRoutines  lfsBackendRoutines = {
  26.         Fsdm_BlockAllocate,
  27.         Fsdm_FileTrunc,
  28.         Fsdm_FileBlockRead,
  29.         Fsdm_FileBlockWrite,
  30.         Lfs_ReallocBlock,
  31.         Lfs_StartWriteBack,
  32.  
  33. };
  34.  
  35. #define    LOCKPTR    &lfsPtr->cacheBackendLock
  36.  
  37.  
  38. /*
  39.  *----------------------------------------------------------------------
  40.  *
  41.  * LfsCacheBackendInit --
  42.  *
  43.  *    Initialized the cache backend of an LFS file system.
  44.  *
  45.  * Results:
  46.  *    None.
  47.  *
  48.  * Side effects:
  49.  *    None.
  50.  *
  51.  *----------------------------------------------------------------------
  52.  */
  53.  
  54. Fscache_Backend *
  55. LfsCacheBackendInit(lfsPtr)
  56.     Lfs        *lfsPtr;    /* LFS file system structure. */
  57. {
  58.     Sync_LockInitDynamic(&(lfsPtr->cacheBackendLock), "LfscacheBackendLock");
  59.     lfsPtr->writeBackActive = FALSE;
  60.     lfsPtr->writeBackMoreWork = FALSE;
  61.     lfsPtr->shutDownActive = FALSE;
  62.     lfsPtr->cacheBlocksReserved = 0;  /* Filled in at end of attach. */
  63.     return Fscache_RegisterBackend(&lfsBackendRoutines,(ClientData) lfsPtr, 0);
  64. }
  65.  
  66.  
  67. /*
  68.  *----------------------------------------------------------------------
  69.  *
  70.  * Lfs_StartWriteBack --
  71.  *
  72.  *    Request that the segment manager start the segment write sequence
  73.  *    for the specified file system.
  74.  *
  75.  * Results:
  76.  *    True is a backend backend was started.
  77.  *
  78.  * Side effects:
  79.  *    A write back process may be started.
  80.  *
  81.  *----------------------------------------------------------------------
  82.  */
  83.  
  84. Boolean
  85. Lfs_StartWriteBack(backendPtr, fileFsynced)
  86.     Fscache_Backend    *backendPtr; /* LFS file system backend. */
  87.     Boolean        fileFsynced;
  88.             /*
  89.              * Second parameter is for ASPLOS measurements and can be
  90.              * removed after all that's over.  Mary 2/14/92
  91.              */
  92. {
  93.     Lfs     *lfsPtr;    /* File system with data to write. */
  94.  
  95.     lfsPtr = (Lfs *) (backendPtr->clientData);
  96.  
  97.     LOCK_MONITOR;
  98.     /*
  99.      * This flag is only for ASPLOS measurements and can be removed after
  100.      * that's all over.  Mary 2/14/92.
  101.      */
  102.     if (fileFsynced) {
  103.     lfsPtr->controlFlags |= LFS_FILE_FSYNCED;
  104.     }
  105.     LFS_STATS_INC(lfsPtr->stats.backend.startRequests);
  106.     if (lfsPtr->writeBackActive) {
  107.     LFS_STATS_INC(lfsPtr->stats.backend.alreadyActive);
  108.     /*
  109.      * If we already have a SegmentWriteProcess active just set
  110.      * a bit indicating more work may be present.  This elimates the
  111.      * race been being notified for work while a WriteBack process
  112.      * is terminating.
  113.      */
  114.     lfsPtr->writeBackMoreWork = TRUE;
  115.     UNLOCK_MONITOR;
  116.     return FALSE;
  117.     }
  118.     lfsPtr->writeBackActive = TRUE;
  119.     Proc_CallFunc(LfsSegmentWriteProc, (ClientData) lfsPtr, 0);
  120.     UNLOCK_MONITOR;
  121.     return TRUE;
  122.  
  123. }
  124.  
  125. /*
  126.  *----------------------------------------------------------------------
  127.  *
  128.  * LfsStopWriteBack --
  129.  *
  130.  *    Stop cache writeback processing on the specified file system. 
  131.  *    This routine is called at file system shutdown time to wait
  132.  *    for the writeback processes to exit.
  133.  *
  134.  * Results:
  135.  *    None.
  136.  *
  137.  * Side effects:
  138.  *    None.
  139.  *
  140.  *----------------------------------------------------------------------
  141.  */
  142.  
  143. void
  144. LfsStopWriteBack(lfsPtr)
  145.     Lfs    *lfsPtr; /* File system to stop writeback for. */
  146. {
  147.     Time time;
  148.  
  149.     LOCK_MONITOR;
  150.     lfsPtr->shutDownActive = TRUE;
  151.     while (lfsPtr->writeBackActive) {
  152.     time.seconds = 1;
  153.     time.microseconds = 0;
  154.     Sync_WaitTime(time);
  155.     }
  156.     UNLOCK_MONITOR;
  157. }
  158.  
  159.  
  160. /*
  161.  *----------------------------------------------------------------------
  162.  *
  163.  * LfsMoreToWriteBack --
  164.  *
  165.  *    Check to see if we got another request for writeback.. 
  166.  *
  167.  * Results:
  168.  *    TRUE if we got request. FALSE otherwise.
  169.  *
  170.  * Side effects:
  171.  *    None.
  172.  *
  173.  *----------------------------------------------------------------------
  174.  */
  175.  
  176. Boolean
  177. LfsMoreToWriteBack(lfsPtr)
  178.     Lfs    *lfsPtr; /* File system to check for more work. */
  179. {
  180.  
  181.     LOCK_MONITOR;
  182.     if (lfsPtr->shutDownActive) {
  183.     lfsPtr->writeBackMoreWork = FALSE;
  184.     }
  185.     if (lfsPtr->writeBackMoreWork) {
  186.     lfsPtr->writeBackMoreWork = FALSE;
  187.     UNLOCK_MONITOR;
  188.     return TRUE;
  189.     }
  190.     lfsPtr->writeBackActive = FALSE;
  191.     lfsPtr->writeBackMoreWork = FALSE;
  192.     UNLOCK_MONITOR;
  193.     FscacheBackendIdle(lfsPtr->domainPtr->backendPtr);
  194.     return FALSE;
  195. }
  196.  
  197.  
  198. /*
  199.  *----------------------------------------------------------------------
  200.  *
  201.  * Lfs_ReallocBlock --
  202.  *
  203.  *    Allocate a new block on disk to replace the given block.  This is
  204.  *    intended to be used by the cache when it can't write out a block
  205.  *    because of a disk error.
  206.  *
  207.  * Results:
  208.  *     None
  209.  *
  210.  * Side effects:
  211.  *
  212.  *----------------------------------------------------------------------
  213.  */
  214. /*ARGSUSED*/
  215. void
  216. Lfs_ReallocBlock(data, callInfoPtr)
  217.     ClientData        data;            /* Block to move */
  218.     Proc_CallInfo    *callInfoPtr;    
  219. {
  220.     panic("Lfs_ReallocBlock called.\n");
  221. }
  222.  
  223.