summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKeith Bostic <keith@wiredtiger.com>2015-03-21 10:34:25 -0400
committerKeith Bostic <keith@wiredtiger.com>2015-03-21 10:34:25 -0400
commit15a5d8977b1bfb360a2cfb498c7f469c49d74cab (patch)
tree51a21d0561a95cfc518391b76721ec1f08f9bb77 /src
parent17d838b291b285d2a1510730412a9a4ba3e99bd3 (diff)
downloadmongo-15a5d8977b1bfb360a2cfb498c7f469c49d74cab.tar.gz
Pass __wt_close() a reference to the WT_FH memory, that way it gets
cleared and we don't have to do special handling in the caller's to decide whether or not we need to close on an error path, that is: ret = __wt_close(session, fh); fh = NULL; WT_ERR(ret); is no longer necessary to avoid multiple closes in error paths.
Diffstat (limited to 'src')
-rw-r--r--src/block/block_open.c6
-rw-r--r--src/conn/conn_api.c6
-rw-r--r--src/conn/conn_handle.c3
-rw-r--r--src/conn/conn_log.c2
-rw-r--r--src/conn/conn_open.c2
-rw-r--r--src/include/extern.h2
-rw-r--r--src/log/log.c25
-rw-r--r--src/meta/meta_turtle.c7
-rw-r--r--src/os_posix/os_open.c8
-rw-r--r--src/os_win/os_open.c8
10 files changed, 36 insertions, 33 deletions
diff --git a/src/block/block_open.c b/src/block/block_open.c
index 386186d6522..83df5556ac4 100644
--- a/src/block/block_open.c
+++ b/src/block/block_open.c
@@ -37,7 +37,7 @@ __wt_block_manager_truncate(
WT_ERR(__wt_fsync(session, fh));
/* Close the file handle. */
-err: WT_TRET(__wt_close(session, fh));
+err: WT_TRET(__wt_close(session, &fh));
return (ret);
}
@@ -67,7 +67,7 @@ __wt_block_manager_create(
WT_TRET(__wt_fsync(session, fh));
/* Close the file handle. */
- WT_TRET(__wt_close(session, fh));
+ WT_TRET(__wt_close(session, &fh));
/*
* If checkpoint syncing is enabled, some filesystems require that we
@@ -105,7 +105,7 @@ __block_destroy(WT_SESSION_IMPL *session, WT_BLOCK *block)
__wt_free(session, block->name);
if (block->fh != NULL)
- WT_TRET(__wt_close(session, block->fh));
+ WT_TRET(__wt_close(session, &block->fh));
__wt_spin_destroy(session, &block->live_lock);
diff --git a/src/conn/conn_api.c b/src/conn/conn_api.c
index 1c15ac3c620..d8aef13511a 100644
--- a/src/conn/conn_api.c
+++ b/src/conn/conn_api.c
@@ -997,8 +997,7 @@ __conn_config_file(WT_SESSION_IMPL *session,
/* Append it to the stack. */
__conn_config_append(cfg, cbuf->data);
-err: if (fh != NULL)
- WT_TRET(__wt_close(session, fh));
+err: WT_TRET(__wt_close(session, &fh));
return (ret);
}
@@ -1227,8 +1226,7 @@ err: /*
* We ignore the connection's lock file handle on error, it will be
* closed when the connection structure is destroyed.
*/
- if (fh != NULL)
- WT_TRET(__wt_close(session, fh));
+ WT_TRET(__wt_close(session, &fh));
__wt_spin_unlock(session, &__wt_process.spinlock);
return (ret);
diff --git a/src/conn/conn_handle.c b/src/conn/conn_handle.c
index 63bb9af5842..b212409be80 100644
--- a/src/conn/conn_handle.c
+++ b/src/conn/conn_handle.c
@@ -116,8 +116,7 @@ __wt_connection_destroy(WT_CONNECTION_IMPL *conn)
* underlying file-close code uses the mutex to guard lists of
* open files.
*/
- if (conn->lock_fh != NULL)
- WT_TRET(__wt_close(session, conn->lock_fh));
+ WT_TRET(__wt_close(session, &conn->lock_fh));
/* Remove from the list of connections. */
__wt_spin_lock(session, &__wt_process.spinlock);
diff --git a/src/conn/conn_log.c b/src/conn/conn_log.c
index 315e93c1875..cde80974b5f 100644
--- a/src/conn/conn_log.c
+++ b/src/conn/conn_log.c
@@ -327,7 +327,7 @@ __log_close_server(void *arg)
WT_ERR(__wt_fsync(session, close_fh));
__wt_spin_lock(session, &log->log_sync_lock);
locked = 1;
- WT_ERR(__wt_close(session, close_fh));
+ WT_ERR(__wt_close(session, &close_fh));
log->sync_lsn = close_end_lsn;
WT_ERR(__wt_cond_signal(session, log->log_sync_cond));
locked = 0;
diff --git a/src/conn/conn_open.c b/src/conn/conn_open.c
index 0a3d35ac0b1..86f62e176ad 100644
--- a/src/conn/conn_open.c
+++ b/src/conn/conn_open.c
@@ -149,7 +149,7 @@ __wt_connection_close(WT_CONNECTION_IMPL *conn)
__wt_errx(session,
"Connection has open file handles: %s", fh->name);
- WT_TRET(__wt_close(session, fh));
+ WT_TRET(__wt_close(session, &fh));
fh = SLIST_FIRST(&conn->fhlh);
}
diff --git a/src/include/extern.h b/src/include/extern.h
index ec961cf2035..e5da105d6fe 100644
--- a/src/include/extern.h
+++ b/src/include/extern.h
@@ -476,7 +476,7 @@ extern int __wt_writeunlock(WT_SESSION_IMPL *session, WT_RWLOCK *rwlock);
extern int __wt_rwlock_destroy(WT_SESSION_IMPL *session, WT_RWLOCK **rwlockp);
extern int __wt_once(void (*init_routine)(void));
extern int __wt_open(WT_SESSION_IMPL *session, const char *name, int ok_create, int exclusive, int dio_type, WT_FH **fhp);
-extern int __wt_close(WT_SESSION_IMPL *session, WT_FH *fh);
+extern int __wt_close(WT_SESSION_IMPL *session, WT_FH **fhp);
extern int __wt_absolute_path(const char *path);
extern const char *__wt_path_separator(void);
extern int __wt_has_priv(void);
diff --git a/src/log/log.c b/src/log/log.c
index d12ac13d762..a01ef40711b 100644
--- a/src/log/log.c
+++ b/src/log/log.c
@@ -585,7 +585,7 @@ __log_truncate(WT_SESSION_IMPL *session,
tmp_fh = log_fh;
log_fh = NULL;
WT_ERR(__wt_fsync(session, tmp_fh));
- WT_ERR(__wt_close(session, tmp_fh));
+ WT_ERR(__wt_close(session, &tmp_fh));
/*
* If we just want to truncate the current log, return and skip
@@ -609,11 +609,10 @@ __log_truncate(WT_SESSION_IMPL *session,
tmp_fh = log_fh;
log_fh = NULL;
WT_ERR(__wt_fsync(session, tmp_fh));
- WT_ERR(__wt_close(session, tmp_fh));
+ WT_ERR(__wt_close(session, &tmp_fh));
}
}
-err: if (log_fh != NULL)
- WT_TRET(__wt_close(session, log_fh));
+err: WT_TRET(__wt_close(session, &log_fh));
if (logfiles != NULL)
__wt_log_files_free(session, logfiles, logcount);
return (ret);
@@ -660,7 +659,7 @@ __wt_log_allocfile(
tmp_fh = log_fh;
log_fh = NULL;
WT_ERR(__wt_fsync(session, tmp_fh));
- WT_ERR(__wt_close(session, tmp_fh));
+ WT_ERR(__wt_close(session, &tmp_fh));
WT_ERR(__wt_verbose(session, WT_VERB_LOG,
"log_prealloc: rename %s to %s",
(char *)from_path->data, (char *)to_path->data));
@@ -671,8 +670,7 @@ __wt_log_allocfile(
err: __wt_scr_free(session, &from_path);
__wt_scr_free(session, &to_path);
- if (log_fh != NULL)
- WT_TRET(__wt_close(session, log_fh));
+ WT_TRET(__wt_close(session, &log_fh));
return (ret);
}
@@ -805,20 +803,20 @@ __wt_log_close(WT_SESSION_IMPL *session)
WT_RET(__wt_verbose(session, WT_VERB_LOG,
"closing old log %s", log->log_close_fh->name));
WT_RET(__wt_fsync(session, log->log_close_fh));
- WT_RET(__wt_close(session, log->log_close_fh));
+ WT_RET(__wt_close(session, &log->log_close_fh));
}
if (log->log_fh != NULL) {
WT_RET(__wt_verbose(session, WT_VERB_LOG,
"closing log %s", log->log_fh->name));
WT_RET(__wt_fsync(session, log->log_fh));
- WT_RET(__wt_close(session, log->log_fh));
+ WT_RET(__wt_close(session, &log->log_fh));
log->log_fh = NULL;
}
if (log->log_dir_fh != NULL) {
WT_RET(__wt_verbose(session, WT_VERB_LOG,
"closing log directory %s", log->log_dir_fh->name));
WT_RET(__wt_directory_sync_fh(session, log->log_dir_fh));
- WT_RET(__wt_close(session, log->log_dir_fh));
+ WT_RET(__wt_close(session, &log->log_dir_fh));
log->log_dir_fh = NULL;
}
return (0);
@@ -1230,7 +1228,7 @@ __log_read_internal(WT_SESSION_IMPL *session, WT_ITEM *record, WT_LSN *lsnp,
record->size = logrec->len;
WT_STAT_FAST_CONN_INCR(session, log_reads);
err:
- WT_TRET(__wt_close(session, log_fh));
+ WT_TRET(__wt_close(session, &log_fh));
return (ret);
}
@@ -1353,7 +1351,7 @@ advance:
/*
* If we read the last record, go to the next file.
*/
- WT_ERR(__wt_close(session, log_fh));
+ WT_ERR(__wt_close(session, &log_fh));
log_fh = NULL;
eol = 1;
/*
@@ -1481,8 +1479,7 @@ err: WT_STAT_FAST_CONN_INCR(session, log_scans);
ret = WT_NOTFOUND;
if (ret == ENOENT)
ret = 0;
- if (log_fh != NULL)
- WT_TRET(__wt_close(session, log_fh));
+ WT_TRET(__wt_close(session, &log_fh));
return (ret);
}
diff --git a/src/meta/meta_turtle.c b/src/meta/meta_turtle.c
index ce9e5878e00..fb64a66987e 100644
--- a/src/meta/meta_turtle.c
+++ b/src/meta/meta_turtle.c
@@ -312,9 +312,7 @@ __wt_turtle_update(
if (F_ISSET(S2C(session), WT_CONN_CKPT_SYNC))
WT_ERR(__wt_fsync(session, fh));
- ret = __wt_close(session, fh);
- fh = NULL;
- WT_ERR(ret);
+ WT_ERR(__wt_close(session, &fh));
WT_ERR(
__wt_rename(session, WT_METADATA_TURTLE_SET, WT_METADATA_TURTLE));
@@ -326,8 +324,7 @@ __wt_turtle_update(
err: WT_TRET(__wt_remove(session, WT_METADATA_TURTLE_SET));
}
- if (fh != NULL)
- WT_TRET(__wt_close(session, fh));
+ WT_TRET(__wt_close(session, &fh));
__wt_scr_free(session, &buf);
return (ret);
}
diff --git a/src/os_posix/os_open.c b/src/os_posix/os_open.c
index 1d8cb7023b6..33b07ed6a49 100644
--- a/src/os_posix/os_open.c
+++ b/src/os_posix/os_open.c
@@ -207,14 +207,20 @@ err: if (fh != NULL) {
* Close a file handle.
*/
int
-__wt_close(WT_SESSION_IMPL *session, WT_FH *fh)
+__wt_close(WT_SESSION_IMPL *session, WT_FH **fhp)
{
WT_CONNECTION_IMPL *conn;
WT_DECL_RET;
+ WT_FH *fh;
uint64_t bucket;
conn = S2C(session);
+ if (*fhp == NULL)
+ return (0);
+ fh = *fhp;
+ *fhp = NULL;
+
__wt_spin_lock(session, &conn->fh_lock);
if (fh == NULL || fh->ref == 0 || --fh->ref > 0) {
__wt_spin_unlock(session, &conn->fh_lock);
diff --git a/src/os_win/os_open.c b/src/os_win/os_open.c
index f146c732e85..4039bcb21e5 100644
--- a/src/os_win/os_open.c
+++ b/src/os_win/os_open.c
@@ -194,14 +194,20 @@ err: if (fh != NULL) {
* Close a file handle.
*/
int
-__wt_close(WT_SESSION_IMPL *session, WT_FH *fh)
+__wt_close(WT_SESSION_IMPL *session, WT_FH **fhp)
{
WT_CONNECTION_IMPL *conn;
WT_DECL_RET;
+ WT_FH *fh;
uint64_t bucket;
conn = S2C(session);
+ if (*fhp == NULL)
+ return (0);
+ fh = *fhp;
+ *fhp = NULL;
+
__wt_spin_lock(session, &conn->fh_lock);
if (fh == NULL || fh->ref == 0 || --fh->ref > 0) {
__wt_spin_unlock(session, &conn->fh_lock);