Bug 918612 - Stop masking the underlying Sqlite VFS version in the Telemetry VFS. r=bent
authorMarco Bonardo <mbonardo@mozilla.com>
Wed, 23 Oct 2013 14:58:06 +0200
changeset 165612 ff5a19df4bed1bbb2c515de7d0bd388dcdb4b623
parent 165611 53382ea36e36910b61329897a5bbc88d6e425048
child 165613 d91823b449d10871c3504247adf4b99907f4ac3e
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbent
bugs918612
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 918612 - Stop masking the underlying Sqlite VFS version in the Telemetry VFS. r=bent
storage/src/TelemetryVFS.cpp
--- a/storage/src/TelemetryVFS.cpp
+++ b/storage/src/TelemetryVFS.cpp
@@ -10,16 +10,22 @@
 #include "sqlite3.h"
 #include "nsThreadUtils.h"
 #include "mozilla/Util.h"
 #include "mozilla/dom/quota/PersistenceType.h"
 #include "mozilla/dom/quota/QuotaManager.h"
 #include "mozilla/dom/quota/QuotaObject.h"
 #include "mozilla/IOInterposer.h"
 
+// The last VFS version for which this file has been updated.
+#define LAST_KNOWN_VFS_VERSION 3
+
+// The last io_methods version for which this file has been updated.
+#define LAST_KNOWN_IOMETHODS_VERSION 3
+
 /**
  * This preference is a workaround to allow users/sysadmins to identify
  * that the profile exists on an NFS share whose implementation
  * is incompatible with SQLite's default locking implementation.
  * Bug 433129 attempted to automatically identify such file-systems, 
  * but a reliable way was not found and it was determined that the fallback 
  * locking is slower than POSIX locking, so we do not want to do it by default.
 */
@@ -395,45 +401,50 @@ xOpen(sqlite3_vfs* vfs, const char *zNam
 
   rc = orig_vfs->xOpen(orig_vfs, zName, p->pReal, flags, pOutFlags);
   if( rc != SQLITE_OK )
     return rc;
   if( p->pReal->pMethods ){
     sqlite3_io_methods *pNew = new sqlite3_io_methods;
     const sqlite3_io_methods *pSub = p->pReal->pMethods;
     memset(pNew, 0, sizeof(*pNew));
-    // If you update this version number, you must add appropriate IO methods
-    // for any methods added in the version change.
-    pNew->iVersion = 3;
-    MOZ_ASSERT(pNew->iVersion >= pSub->iVersion);
+    // If the io_methods version is higher than the last known one, you should
+    // update this VFS adding appropriate IO methods for any methods added in
+    // the version change.
+    pNew->iVersion = pSub->iVersion;
+    MOZ_ASSERT(pNew->iVersion <= LAST_KNOWN_IOMETHODS_VERSION);
     pNew->xClose = xClose;
     pNew->xRead = xRead;
     pNew->xWrite = xWrite;
     pNew->xTruncate = xTruncate;
     pNew->xSync = xSync;
     pNew->xFileSize = xFileSize;
     pNew->xLock = xLock;
     pNew->xUnlock = xUnlock;
     pNew->xCheckReservedLock = xCheckReservedLock;
     pNew->xFileControl = xFileControl;
     pNew->xSectorSize = xSectorSize;
     pNew->xDeviceCharacteristics = xDeviceCharacteristics;
-    // Methods added in version 2.
-    pNew->xShmMap = pSub->xShmMap ? xShmMap : 0;
-    pNew->xShmLock = pSub->xShmLock ? xShmLock : 0;
-    pNew->xShmBarrier = pSub->xShmBarrier ? xShmBarrier : 0;
-    pNew->xShmUnmap = pSub->xShmUnmap ? xShmUnmap : 0;
-    // Methods added in version 3.
-    // SQLite 3.7.17 calls these methods without checking for nullptr first,
-    // so we always define them.  Verify that we're not going to call
-    // nullptrs, though.
-    MOZ_ASSERT(pSub->xFetch);
-    pNew->xFetch = xFetch;
-    MOZ_ASSERT(pSub->xUnfetch);
-    pNew->xUnfetch = xUnfetch;
+    if (pNew->iVersion >= 2) {
+      // Methods added in version 2.
+      pNew->xShmMap = pSub->xShmMap ? xShmMap : 0;
+      pNew->xShmLock = pSub->xShmLock ? xShmLock : 0;
+      pNew->xShmBarrier = pSub->xShmBarrier ? xShmBarrier : 0;
+      pNew->xShmUnmap = pSub->xShmUnmap ? xShmUnmap : 0;
+    }
+    if (pNew->iVersion >= 3) {
+      // Methods added in version 3.
+      // SQLite 3.7.17 calls these methods without checking for nullptr first,
+      // so we always define them.  Verify that we're not going to call
+      // nullptrs, though.
+      MOZ_ASSERT(pSub->xFetch);
+      pNew->xFetch = xFetch;
+      MOZ_ASSERT(pSub->xUnfetch);
+      pNew->xUnfetch = xUnfetch;
+    }
     pFile->pMethods = pNew;
   }
   return rc;
 }
 
 int
 xDelete(sqlite3_vfs* vfs, const char *zName, int syncDir)
 {
@@ -567,40 +578,44 @@ sqlite3_vfs* ConstructTelemetryVFS()
     expected_vfs = vfs->zName && !strcmp(vfs->zName, EXPECTED_VFS);
   }
   if (!expected_vfs) {
     return nullptr;
   }
 
   sqlite3_vfs *tvfs = new ::sqlite3_vfs;
   memset(tvfs, 0, sizeof(::sqlite3_vfs));
-  // If you update this version number, you must add appropriate VFS methods
-  // for any methods added in the version change.
-  tvfs->iVersion = 3;
-  MOZ_ASSERT(vfs->iVersion == tvfs->iVersion);
+  // If the VFS version is higher than the last known one, you should update
+  // this VFS adding appropriate methods for any methods added in the version
+  // change.
+  tvfs->iVersion = vfs->iVersion;
+  MOZ_ASSERT(vfs->iVersion <= LAST_KNOWN_VFS_VERSION);
   tvfs->szOsFile = sizeof(telemetry_file) - sizeof(sqlite3_file) + vfs->szOsFile;
   tvfs->mxPathname = vfs->mxPathname;
   tvfs->zName = "telemetry-vfs";
   tvfs->pAppData = vfs;
   tvfs->xOpen = xOpen;
   tvfs->xDelete = xDelete;
   tvfs->xAccess = xAccess;
   tvfs->xFullPathname = xFullPathname;
   tvfs->xDlOpen = xDlOpen;
   tvfs->xDlError = xDlError;
   tvfs->xDlSym = xDlSym;
   tvfs->xDlClose = xDlClose;
   tvfs->xRandomness = xRandomness;
   tvfs->xSleep = xSleep;
   tvfs->xCurrentTime = xCurrentTime;
   tvfs->xGetLastError = xGetLastError;
-  // Methods added in version 2.
-  tvfs->xCurrentTimeInt64 = xCurrentTimeInt64;
-  // Methods added in version 3.
-  tvfs->xSetSystemCall = xSetSystemCall;
-  tvfs->xGetSystemCall = xGetSystemCall;
-  tvfs->xNextSystemCall = xNextSystemCall;
-
+  if (tvfs->iVersion >= 2) {
+    // Methods added in version 2.
+    tvfs->xCurrentTimeInt64 = xCurrentTimeInt64;
+  }
+  if (tvfs->iVersion >= 3) {
+    // Methods added in version 3.
+    tvfs->xSetSystemCall = xSetSystemCall;
+    tvfs->xGetSystemCall = xGetSystemCall;
+    tvfs->xNextSystemCall = xNextSystemCall;
+  }
   return tvfs;
 }
 
 }
 }