[tarantool-patches] [PATCH 1/2] sql: refactor SQLITE_IOERR_ error codes
AlexeyIvushkin
ivushkinalex at gmail.com
Tue Oct 2 23:50:34 MSK 2018
From: Morgan-iv <ivushkinalex at gmail.com>
Remove error codes with prefix SQLITE_IOERR_ that only defined,
but don't used anywhere.
Replace '#define' macro with enum statement in implementation of
SQLITE_IOERR_ error codes
Remove unused function xDelete from sqlite3_vfs interface and its
implementation, unixDelete. Also remove function openDirectory, used
only in unixDelete
Part of #3315
---
src/box/sql/main.c | 42 -----------------------
src/box/sql/os_unix.c | 88 -------------------------------------------------
src/box/sql/sqliteInt.h | 43 +++++++++---------------
3 files changed, 15 insertions(+), 158 deletions(-)
diff --git a/src/box/sql/main.c b/src/box/sql/main.c
index 782f994..532d324 100644
--- a/src/box/sql/main.c
+++ b/src/box/sql/main.c
@@ -784,12 +784,6 @@ sqlite3ErrName(int rc)
case SQLITE_IOERR_WRITE:
zName = "SQLITE_IOERR_WRITE";
break;
- case SQLITE_IOERR_FSYNC:
- zName = "SQLITE_IOERR_FSYNC";
- break;
- case SQLITE_IOERR_DIR_FSYNC:
- zName = "SQLITE_IOERR_DIR_FSYNC";
- break;
case SQLITE_IOERR_TRUNCATE:
zName = "SQLITE_IOERR_TRUNCATE";
break;
@@ -802,54 +796,18 @@ sqlite3ErrName(int rc)
case SQLITE_IOERR_RDLOCK:
zName = "SQLITE_IOERR_RDLOCK";
break;
- case SQLITE_IOERR_DELETE:
- zName = "SQLITE_IOERR_DELETE";
- break;
case SQLITE_IOERR_NOMEM:
zName = "SQLITE_IOERR_NOMEM";
break;
case SQLITE_IOERR_ACCESS:
zName = "SQLITE_IOERR_ACCESS";
break;
- case SQLITE_IOERR_CHECKRESERVEDLOCK:
- zName = "SQLITE_IOERR_CHECKRESERVEDLOCK";
- break;
- case SQLITE_IOERR_LOCK:
- zName = "SQLITE_IOERR_LOCK";
- break;
case SQLITE_IOERR_CLOSE:
zName = "SQLITE_IOERR_CLOSE";
break;
- case SQLITE_IOERR_DIR_CLOSE:
- zName = "SQLITE_IOERR_DIR_CLOSE";
- break;
- case SQLITE_IOERR_SHMOPEN:
- zName = "SQLITE_IOERR_SHMOPEN";
- break;
- case SQLITE_IOERR_SHMSIZE:
- zName = "SQLITE_IOERR_SHMSIZE";
- break;
- case SQLITE_IOERR_SHMLOCK:
- zName = "SQLITE_IOERR_SHMLOCK";
- break;
- case SQLITE_IOERR_SHMMAP:
- zName = "SQLITE_IOERR_SHMMAP";
- break;
- case SQLITE_IOERR_SEEK:
- zName = "SQLITE_IOERR_SEEK";
- break;
- case SQLITE_IOERR_DELETE_NOENT:
- zName = "SQLITE_IOERR_DELETE_NOENT";
- break;
- case SQLITE_IOERR_MMAP:
- zName = "SQLITE_IOERR_MMAP";
- break;
case SQLITE_IOERR_GETTEMPPATH:
zName = "SQLITE_IOERR_GETTEMPPATH";
break;
- case SQLITE_IOERR_CONVPATH:
- zName = "SQLITE_IOERR_CONVPATH";
- break;
case SQLITE_NOTFOUND:
zName = "SQLITE_NOTFOUND";
break;
diff --git a/src/box/sql/os_unix.c b/src/box/sql/os_unix.c
index b8816e0..5de722d 100644
--- a/src/box/sql/os_unix.c
+++ b/src/box/sql/os_unix.c
@@ -990,53 +990,6 @@ unixWrite(sqlite3_file * id, const void *pBuf, int amt, sqlite3_int64 offset)
}
/*
- * Open a file descriptor to the directory containing file zFilename.
- * If successful, *pFd is set to the opened file descriptor and
- * SQLITE_OK is returned. If an error occurs, either SQLITE_NOMEM
- * or SQLITE_CANTOPEN is returned and *pFd is set to an undefined
- * value.
- *
- * The directory file descriptor is used for only one thing - to
- * fsync() a directory to make sure file creation and deletion events
- * are flushed to disk. Such fsyncs are not needed on newer
- * journaling filesystems, but are required on older filesystems.
- *
- * This routine can be overridden using the xSetSysCall interface.
- * The ability to override this routine was added in support of the
- * chromium sandbox. Opening a directory is a security risk (we are
- * told) so making it overrideable allows the chromium sandbox to
- * replace this routine with a harmless no-op. To make this routine
- * a no-op, replace it with a stub that returns SQLITE_OK but leaves
- * *pFd set to a negative number.
- *
- * If SQLITE_OK is returned, the caller is responsible for closing
- * the file descriptor *pFd using close().
- */
-static int
-openDirectory(const char *zFilename, int *pFd)
-{
- int ii;
- int fd;
- char zDirname[MAX_PATHNAME + 1];
-
- sqlite3_snprintf(MAX_PATHNAME, zDirname, "%s", zFilename);
- for (ii = (int)strlen(zDirname); ii > 0 && zDirname[ii] != '/'; ii--) ;
- if (ii > 0) {
- zDirname[ii] = '\0';
- } else {
- if (zDirname[0] != '/')
- zDirname[0] = '.';
- zDirname[1] = 0;
- }
- fd = robust_open(zDirname, O_RDONLY | O_BINARY, 0);
-
- *pFd = fd;
- if (fd >= 0)
- return SQLITE_OK;
- return unixLogError(SQLITE_CANTOPEN_BKPT, "openDirectory", zDirname);
-}
-
-/*
* This function is called to handle the SQLITE_FCNTL_SIZE_HINT
* file-control operation. Enlarge the database to nBytes in size
* (rounded up to the next chunk-size). If the database is already
@@ -1923,46 +1876,6 @@ unixOpen(sqlite3_vfs * pVfs, /* The VFS for which this is the xOpen method */
}
/*
- * Delete the file at zPath. If the dirSync argument is true, fsync()
- * the directory after deleting the file.
- */
-static int
-unixDelete(sqlite3_vfs * NotUsed, /* VFS containing this as the xDelete method */
- const char *zPath, /* Name of file to be deleted */
- int dirSync /* If true, fsync() directory after deleting file */
- )
-{
- int rc = SQLITE_OK;
- UNUSED_PARAMETER(NotUsed);
- if (unlink(zPath) == (-1)) {
- if (errno == ENOENT) {
- rc = SQLITE_IOERR_DELETE_NOENT;
- } else {
- rc = unixLogError(SQLITE_IOERR_DELETE, "unlink", zPath);
- }
- return rc;
- }
-#ifndef SQLITE_DISABLE_DIRSYNC
- if ((dirSync & 1) != 0) {
- int fd;
- rc = openDirectory(zPath, &fd);
- if (rc == SQLITE_OK) {
- struct stat buf;
- if (fstat(fd, &buf)) {
- rc = unixLogError(SQLITE_IOERR_DIR_FSYNC,
- "fsync", zPath);
- }
- robust_close(0, fd, __LINE__);
- } else {
- assert(rc == SQLITE_CANTOPEN);
- rc = SQLITE_OK;
- }
- }
-#endif
- return rc;
-}
-
-/*
* Write nBuf bytes of random data to the supplied buffer zBuf.
*/
static int
@@ -2076,7 +1989,6 @@ unixGetLastError(sqlite3_vfs * NotUsed, int NotUsed2, char *NotUsed3)
VFSNAME, /* zName */ \
(void*)&FINDER, /* pAppData */ \
unixOpen, /* xOpen */ \
- unixDelete, /* xDelete */ \
unixRandomness, /* xRandomness */ \
unixSleep, /* xSleep */ \
NULL, /* xCurrentTime */ \
diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h
index 53188e7..00c0309 100644
--- a/src/box/sql/sqliteInt.h
+++ b/src/box/sql/sqliteInt.h
@@ -336,7 +336,6 @@ struct sqlite3_vfs {
void *pAppData; /* Pointer to application-specific data */
int (*xOpen) (sqlite3_vfs *, const char *zName, sqlite3_file *,
int flags, int *pOutFlags);
- int (*xDelete) (sqlite3_vfs *, const char *zName, int syncDir);
int (*xRandomness) (sqlite3_vfs *, int nByte, char *zOut);
int (*xSleep) (sqlite3_vfs *, int microseconds);
int (*xCurrentTime) (sqlite3_vfs *, double *);
@@ -605,33 +604,21 @@ sqlite3_exec(sqlite3 *, /* An open database */
void *, /* 1st argument to callback */
char **errmsg /* Error msg written here */
);
-#define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8))
-#define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8))
-#define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8))
-#define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8))
-#define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8))
-#define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8))
-#define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8))
-#define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8))
-#define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8))
-#define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8))
-#define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8))
-#define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8))
-#define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8))
-#define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8))
-#define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15<<8))
-#define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8))
-#define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8))
-#define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8))
-#define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8))
-#define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8))
-#define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8))
-#define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
-#define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8))
-#define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8))
-#define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8))
-#define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8))
-#define SQLITE_IOERR_VNODE (SQLITE_IOERR | (27<<8))
+
+enum sql_ioerr_code {
+ SQLITE_IOERR_READ = (SQLITE_IOERR | (1<<8)),
+ SQLITE_IOERR_SHORT_READ = (SQLITE_IOERR | (2<<8)),
+ SQLITE_IOERR_WRITE = (SQLITE_IOERR | (3<<8)),
+ SQLITE_IOERR_TRUNCATE = (SQLITE_IOERR | (4<<8)),
+ SQLITE_IOERR_FSTAT = (SQLITE_IOERR | (5<<8)),
+ SQLITE_IOERR_UNLOCK = (SQLITE_IOERR | (6<<8)),
+ SQLITE_IOERR_RDLOCK = (SQLITE_IOERR | (7<<8)),
+ SQLITE_IOERR_NOMEM = (SQLITE_IOERR | (8<<8)),
+ SQLITE_IOERR_ACCESS = (SQLITE_IOERR | (9<<8)),
+ SQLITE_IOERR_CLOSE = (SQLITE_IOERR | (10<<8)),
+ SQLITE_IOERR_GETTEMPPATH = (SQLITE_IOERR | (11<<8))
+};
+
#define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8))
#define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8))
#define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8))
--
2.7.4
More information about the Tarantool-patches
mailing list