/ Check-in [5bced239]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix some problems in the crash-test backend. (CVS 4256)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 5bced2392ad77aff0aa1ddea83f2ff9e3ffe28a8
User & Date: danielk1977 2007-08-21 13:07:47
Context
2007-08-21
13:11
Avoid journalling an extra page when a btree insert operation uses the 'quick-balance' trick. (CVS 4257) check-in: 0da48209 user: danielk1977 tags: trunk
13:07
Fix some problems in the crash-test backend. (CVS 4256) check-in: 5bced239 user: danielk1977 tags: trunk
10:44
Remove unnecessary #includes of "os.h". New mutex implementations. (CVS 4255) check-in: fbbd5bda user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os.c.

   229    229     if( makeDflt || vfsList==0 ){
   230    230       pVfs->pNext = vfsList;
   231    231       vfsList = pVfs;
   232    232     }else{
   233    233       pVfs->pNext = vfsList->pNext;
   234    234       pVfs->pNext = pVfs;
   235    235     }
          236  +  assert(vfsList);
   236    237     sqlite3_mutex_leave(mutex);
   237    238     return SQLITE_OK;
   238    239   }
   239    240   
   240    241   /*
   241    242   ** Unregister a VFS so that it is no longer accessible.
   242    243   */
   243    244   int sqlite3_vfs_unregister(sqlite3_vfs *pVfs){
   244    245     sqlite3_mutex *mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER);
   245    246     sqlite3_mutex_enter(mutex);
   246    247     vfsUnlink(pVfs);
          248  +  assert(vfsList);
   247    249     sqlite3_mutex_leave(mutex);
   248    250     return SQLITE_OK;
   249    251   }

Changes to src/test6.c.

   122    122   };
   123    123   
   124    124   struct CrashFile {
   125    125     const sqlite3_io_methods *pMethod;   /* Must be first */
   126    126     sqlite3_file *pRealFile;             /* Underlying "real" file handle */
   127    127     char *zName;
   128    128   
   129         -  /* Cache of the entire file. */
          129  +  /* Cache of the entire file. This is used to speed up OsRead() and 
          130  +  ** OsFileSize() calls. Although both could be done by traversing the
          131  +  ** write-list, in practice this is impractically slow.
          132  +  */
   130    133     int iSize;                           /* Size of file in bytes */
   131    134     int nData;                           /* Size of buffer allocated at zData */
   132    135     u8 *zData;                           /* Buffer containing file contents */
   133    136   };
   134    137   
   135    138   struct CrashGlobal {
   136    139     WriteBuffer *pWriteList;     /* Head of write-list */
................................................................................
   299    302   
   300    303   /*
   301    304   ** Close a crash-file.
   302    305   */
   303    306   static int cfClose(sqlite3_file *pFile){
   304    307     CrashFile *pCrash = (CrashFile *)pFile;
   305    308     writeListSync(pCrash, 0);
   306         -  sqlite3OsCloseFree(pCrash->pRealFile);
          309  +  sqlite3OsClose(pCrash->pRealFile);
   307    310     return SQLITE_OK;
   308    311   }
   309    312   
   310    313   /*
   311    314   ** Read data from a crash-file.
   312    315   */
   313    316   static int cfRead(
................................................................................
   450    453     cfDeviceCharacteristics       /* xDeviceCharacteristics */
   451    454   };
   452    455   
   453    456   /*
   454    457   ** Application data for the crash VFS
   455    458   */
   456    459   struct crashAppData {
   457         -  int (*xOpen)(void*,const char*,sqlite3_file*,int,int*); /* Original xOpen */
   458         -  void *pAppData;                                      /* Original pAppData */
          460  +  sqlite3_vfs *pOrig;                   /* Wrapped vfs structure */
   459    461   };
   460    462   
   461    463   /*
   462    464   ** Open a crash-file file handle. The vfs pVfs is used to open
   463    465   ** the underlying real file.
   464    466   **
   465    467   ** The caller will have allocated pVfs->szOsFile bytes of space
   466    468   ** at pFile. This file uses this space for the CrashFile structure
   467    469   ** and allocates space for the "real" file structure using 
   468    470   ** sqlite3_malloc(). The assumption here is (pVfs->szOsFile) is
   469    471   ** equal or greater than sizeof(CrashFile).
   470    472   */
   471         -static int sqlite3CrashFileOpen(
   472         -  sqlite3_vfs *pVfs,
          473  +static int cfOpen(
          474  +  void *pAppData,
   473    475     const char *zName,
   474    476     sqlite3_file *pFile,
   475    477     int flags,
   476    478     int *pOutFlags
   477    479   ){
          480  +  sqlite3_vfs *pVfs = (sqlite3_vfs *)pAppData;
   478    481     int rc;
   479         -  if( sqlite3CrashTestEnable ){
   480         -    CrashFile *pWrapper = (CrashFile *)pFile;
   481         -    sqlite3_file *pReal;
   482         -    assert(pVfs->szOsFile>=sizeof(CrashFile));
   483         -    memset(pWrapper, 0, sizeof(CrashFile));
   484         -    sqlite3CrashTestEnable = 0;
   485         -    rc = sqlite3OsOpenMalloc(pVfs, zName, &pReal, flags, pOutFlags);
   486         -    sqlite3CrashTestEnable = 1;
   487         -    if( rc==SQLITE_OK ){
   488         -      i64 iSize;
   489         -      pWrapper->pMethod = &CrashFileVtab;
   490         -      pWrapper->zName = (char *)zName;
   491         -      pWrapper->pRealFile = pReal;
   492         -      rc = sqlite3OsFileSize(pReal, &iSize);
   493         -      pWrapper->iSize = (int)iSize;
          482  +  CrashFile *pWrapper = (CrashFile *)pFile;
          483  +  sqlite3_file *pReal = &pWrapper[1];
          484  +
          485  +  memset(pWrapper, 0, sizeof(CrashFile));
          486  +  rc = sqlite3OsOpen(pVfs, zName, pReal, flags, pOutFlags);
          487  +
          488  +  if( rc==SQLITE_OK ){
          489  +    i64 iSize;
          490  +    pWrapper->pMethod = &CrashFileVtab;
          491  +    pWrapper->zName = (char *)zName;
          492  +    pWrapper->pRealFile = pReal;
          493  +    rc = sqlite3OsFileSize(pReal, &iSize);
          494  +    pWrapper->iSize = (int)iSize;
          495  +  }
          496  +  if( rc==SQLITE_OK ){
          497  +    pWrapper->nData = (4096 + pWrapper->iSize);
          498  +    pWrapper->zData = (char *)sqlite3_malloc(pWrapper->nData);
          499  +    if( pWrapper->zData ){
          500  +      memset(pWrapper->zData, 0, pWrapper->nData);
          501  +      rc = sqlite3OsRead(pReal, pWrapper->zData, pWrapper->iSize, 0); 
          502  +    }else{
          503  +      rc = SQLITE_NOMEM;
   494    504       }
   495         -    if( rc==SQLITE_OK ){
   496         -      pWrapper->nData = (4096 + pWrapper->iSize);
   497         -      pWrapper->zData = (char *)sqlite3_malloc(pWrapper->nData);
   498         -      if( pWrapper->zData ){
   499         -        memset(pWrapper->zData, 0, pWrapper->nData);
   500         -        rc = sqlite3OsRead(pReal, pWrapper->zData, pWrapper->iSize, 0); 
   501         -      }else{
   502         -        rc = SQLITE_NOMEM;
   503         -      }
   504         -    }
   505         -    if( rc!=SQLITE_OK && pWrapper->pMethod ){
   506         -      sqlite3OsClose(pFile);
   507         -    }
   508         -  }else{
   509         -    struct crashAppData *pData = (struct crashAppData*)pVfs->pAppData;
   510         -    rc = pData->xOpen(pData->pAppData, zName, pFile, flags, pOutFlags);
          505  +  }
          506  +  if( rc!=SQLITE_OK && pWrapper->pMethod ){
          507  +    sqlite3OsClose(pFile);
   511    508     }
   512    509     return rc;
   513    510   }
          511  +
          512  +static int cfDelete(void *pAppData, const char *zPath, int dirSync){
          513  +  sqlite3_vfs *pVfs = (sqlite3_vfs *)pAppData;
          514  +  return pVfs->xDelete(pVfs->pAppData, zPath, dirSync);
          515  +}
          516  +static int cfAccess(void *pAppData, const char *zPath, int flags){
          517  +  sqlite3_vfs *pVfs = (sqlite3_vfs *)pAppData;
          518  +  return pVfs->xAccess(pVfs->pAppData, zPath, flags);
          519  +}
          520  +static int cfGetTempName(void *pAppData, char *zBufOut){
          521  +  sqlite3_vfs *pVfs = (sqlite3_vfs *)pAppData;
          522  +  return pVfs->xGetTempName(pVfs->pAppData, zBufOut);
          523  +}
          524  +static int cfFullPathname(void *pAppData, const char *zPath, char *zPathOut){
          525  +  sqlite3_vfs *pVfs = (sqlite3_vfs *)pAppData;
          526  +  return pVfs->xFullPathname(pVfs->pAppData, zPath, zPathOut);
          527  +}
          528  +static void *cfDlOpen(void *pAppData, const char *zPath){
          529  +  sqlite3_vfs *pVfs = (sqlite3_vfs *)pAppData;
          530  +  return pVfs->xDlOpen(pVfs->pAppData, zPath);
          531  +}
          532  +static int cfRandomness(void *pAppData, int nByte, char *zBufOut){
          533  +  sqlite3_vfs *pVfs = (sqlite3_vfs *)pAppData;
          534  +  return pVfs->xRandomness(pVfs->pAppData, nByte, zBufOut);
          535  +}
          536  +static int cfSleep(void *pAppData, int nMicro){
          537  +  sqlite3_vfs *pVfs = (sqlite3_vfs *)pAppData;
          538  +  return pVfs->xSleep(pVfs->pAppData, nMicro);
          539  +}
          540  +static int cfCurrentTime(void *pAppData, double *pTimeOut){
          541  +  sqlite3_vfs *pVfs = (sqlite3_vfs *)pAppData;
          542  +  return pVfs->xCurrentTime(pVfs->pAppData, pTimeOut);
          543  +}
   514    544   
   515    545   /*
   516    546   ** tclcmd:   sqlite_crashparams ?OPTIONS? DELAY CRASHFILE
   517    547   **
   518    548   ** This procedure implements a TCL command that enables crash testing
   519    549   ** in testfixture.  Once enabled, crash testing cannot be disabled.
   520    550   **
................................................................................
   536    566     int objc,
   537    567     Tcl_Obj *CONST objv[]
   538    568   ){
   539    569     int i;
   540    570     int iDelay;
   541    571     const char *zCrashFile;
   542    572     int nCrashFile;
   543         -  static sqlite3_vfs crashVfs, *pOriginalVfs;
   544    573     static struct crashAppData appData;
   545    574   
   546         -  if( pOriginalVfs==0 ){
   547         -    pOriginalVfs = sqlite3_vfs_find(0);
   548         -    crashVfs = *pOriginalVfs;
   549         -    crashVfs.xOpen = sqlite3CrashFileOpen;
   550         -    crashVfs.vfsMutex = 0;
   551         -    crashVfs.nRef = 0;
   552         -    crashVfs.pAppData = &appData;
   553         -    appData.xOpen = pOriginalVfs->xOpen;
   554         -    appData.pAppData = pOriginalVfs->pAppData;
          575  +  static sqlite3_vfs crashVfs = {
          576  +    1,                  /* iVersion */
          577  +    0,                  /* szOsFile */
          578  +    0,                  /* mxPathname */
          579  +    0,                  /* nRef */
          580  +    0,                  /* vfsMutex */
          581  +    0,                  /* pNext */
          582  +    "crash",            /* zName */
          583  +    0,                  /* pAppData */
          584  +  
          585  +    cfOpen,               /* xOpen */
          586  +    cfDelete,             /* xDelete */
          587  +    cfAccess,             /* xAccess */
          588  +    cfGetTempName,        /* xGetTempName */
          589  +    cfFullPathname,       /* xFullPathname */
          590  +    cfDlOpen,             /* xDlOpen */
          591  +    0,                    /* xDlError */
          592  +    0,                    /* xDlSym */
          593  +    0,                    /* xDlClose */
          594  +    cfRandomness,         /* xRandomness */
          595  +    cfSleep,              /* xSleep */
          596  +    cfCurrentTime         /* xCurrentTime */
          597  +  };
          598  +
          599  +  if( crashVfs.pAppData==0 ){
          600  +    sqlite3_vfs *pOriginalVfs = sqlite3_vfs_find(0);
          601  +    crashVfs.xDlError = pOriginalVfs->xDlError;
          602  +    crashVfs.xDlSym = pOriginalVfs->xDlSym;
          603  +    crashVfs.xDlClose = pOriginalVfs->xDlClose;
          604  +    crashVfs.mxPathname = pOriginalVfs->mxPathname;
          605  +    crashVfs.pAppData = (void *)pOriginalVfs;
          606  +    crashVfs.szOsFile = sizeof(CrashFile) + pOriginalVfs->szOsFile;
   555    607       sqlite3_vfs_release(pOriginalVfs);
   556         -    sqlite3_vfs_unregister(pOriginalVfs);
          608  +    /* sqlite3_vfs_unregister(pOriginalVfs); */
   557    609       sqlite3_vfs_register(&crashVfs, 1);
   558    610     }
   559    611   
   560    612     int iDc = 0;
   561    613     int iSectorSize = 0;
   562    614     int setSectorsize = 0;
   563    615     int setDeviceChar = 0;