/* * __remove_file_check -- * Check if the file is currently open before removing it. */ static inline void __remove_file_check(WT_SESSION_IMPL *session, const char *name) { #ifdef HAVE_DIAGNOSTIC WT_CONNECTION_IMPL *conn; WT_FH *fh; uint64_t bucket; conn = S2C(session); WT_ASSERT(session, !F_ISSET(conn, WT_CONN_READONLY)); fh = NULL; bucket = __wt_hash_city64(name, strlen(name)) % WT_HASH_ARRAY_SIZE; /* * Check if the file is open: it's an error if it is, since a higher * level should have closed it before removing. */ __wt_spin_lock(session, &conn->fh_lock); TAILQ_FOREACH(fh, &conn->fhhash[bucket], hashq) if (strcmp(name, fh->name) == 0) break; __wt_spin_unlock(session, &conn->fh_lock); WT_ASSERT(session, fh == NULL); #else WT_UNUSED(session); WT_UNUSED(name); #endif }
/* * __wt_block_salvage_valid -- * Let salvage know if a block is valid. */ int __wt_block_salvage_valid(WT_SESSION_IMPL *session, WT_BLOCK *block, uint8_t *addr, size_t addr_size, int valid) { wt_off_t offset; uint32_t size, cksum; WT_UNUSED(session); WT_UNUSED(addr_size); /* * Crack the cookie. * If the upper layer took the block, move past it; if the upper layer * rejected the block, move past an allocation size chunk and free it. */ WT_RET(__wt_block_buffer_to_addr(block, addr, &offset, &size, &cksum)); if (valid) block->slvg_off = offset + size; else { WT_RET(__wt_block_off_free( session, block, offset, (wt_off_t)block->allocsize)); block->slvg_off = offset + block->allocsize; } return (0); }
static void wt_open_corrupt(const char *sfx) { WT_CONNECTION *conn; int ret; char buf[1024]; #ifdef HAVE_ATTACH WT_UNUSED(buf); WT_UNUSED(conn); WT_UNUSED(ret); WT_UNUSED(sfx); #else conn = NULL; if (sfx != NULL) testutil_check(__wt_snprintf(buf, sizeof(buf), "%s.%s", home, sfx)); else testutil_check(__wt_snprintf(buf, sizeof(buf), "%s", home)); ret = wiredtiger_open(buf, &event_handler, NULL, &conn); /* * Not all out of sync combinations lead to corruption. We keep * the previous checkpoint in the file so some combinations of * future or old turtle files and metadata files will succeed. */ if (ret != WT_TRY_SALVAGE && ret != 0) fprintf(stderr, "OPEN_CORRUPT: wiredtiger_open returned %d\n", ret); testutil_assert(ret == WT_TRY_SALVAGE || ret == 0); #endif exit (EXIT_SUCCESS); }
/* * __txn_log_recover -- * Roll the log forward to recover committed changes. */ static int __txn_log_recover(WT_SESSION_IMPL *session, WT_ITEM *logrec, WT_LSN *lsnp, void *cookie, int firstrecord) { WT_RECOVERY *r; const uint8_t *end, *p; uint64_t txnid; uint32_t rectype; r = cookie; p = LOG_SKIP_HEADER(logrec->data); end = (const uint8_t *)logrec->data + logrec->size; WT_UNUSED(firstrecord); /* First, peek at the log record type. */ WT_RET(__wt_logrec_read(session, &p, end, &rectype)); switch (rectype) { case WT_LOGREC_CHECKPOINT: if (r->metadata_only) WT_RET(__wt_txn_checkpoint_logread( session, &p, end, &r->ckpt_lsn)); break; case WT_LOGREC_COMMIT: WT_RET(__wt_vunpack_uint(&p, WT_PTRDIFF(end, p), &txnid)); WT_UNUSED(txnid); WT_RET(__txn_commit_apply(r, lsnp, &p, end)); break; } return (0); }
/* * __wt_block_addr_invalid -- * Return an error code if an address cookie is invalid. */ int __wt_block_addr_invalid(WT_SESSION_IMPL *session, WT_BLOCK *block, const uint8_t *addr, size_t addr_size, bool live) { wt_off_t offset; uint32_t checksum, size; WT_UNUSED(session); WT_UNUSED(addr_size); WT_UNUSED(live); /* Crack the cookie. */ WT_RET( __wt_block_buffer_to_addr(block, addr, &offset, &size, &checksum)); #ifdef HAVE_DIAGNOSTIC /* * In diagnostic mode, verify the address isn't on the available list, * or for live systems, the discard list. */ WT_RET(__wt_block_misplaced( session, block, "addr-valid", offset, size, live)); #endif /* Check if the address is past the end of the file. */ return (offset + size > block->size ? EINVAL : 0); }
/* * __win_fs_rename -- * Rename a file. */ static int __win_fs_rename(WT_FILE_SYSTEM *file_system, WT_SESSION *wt_session, const char *from, const char *to, uint32_t flags) { DWORD windows_error; WT_SESSION_IMPL *session; WT_UNUSED(file_system); WT_UNUSED(flags); session = (WT_SESSION_IMPL *)wt_session; /* * Check if file exists since Windows does not override the file if * it exists. */ if (GetFileAttributesA(to) != INVALID_FILE_ATTRIBUTES) if (DeleteFileA(to) == FALSE) { windows_error = __wt_getlasterror(); __wt_errx(session, "%s: file-rename: DeleteFileA: %s", to, __wt_formatmessage(session, windows_error)); return (__wt_map_windows_error(windows_error)); } if (MoveFileA(from, to) == FALSE) { windows_error = __wt_getlasterror(); __wt_errx(session, "%s to %s: file-rename: MoveFileA: %s", from, to, __wt_formatmessage(session, windows_error)); return (__wt_map_windows_error(windows_error)); } return (0); }
/* * __conn_add_compressor -- * WT_CONNECTION->add_compressor method. */ static int __conn_add_compressor(WT_CONNECTION *wt_conn, const char *name, WT_COMPRESSOR *compressor, const char *config) { WT_CONNECTION_IMPL *conn; WT_DECL_RET; WT_NAMED_COMPRESSOR *ncomp; WT_SESSION_IMPL *session; WT_UNUSED(name); WT_UNUSED(compressor); conn = (WT_CONNECTION_IMPL *)wt_conn; CONNECTION_API_CALL(conn, session, add_compressor, config, cfg); WT_UNUSED(cfg); WT_ERR(__wt_calloc_def(session, 1, &ncomp)); WT_ERR(__wt_strdup(session, name, &ncomp->name)); ncomp->compressor = compressor; __wt_spin_lock(session, &conn->api_lock); TAILQ_INSERT_TAIL(&conn->compqh, ncomp, q); __wt_spin_unlock(session, &conn->api_lock); ncomp = NULL; err: __wt_free(session, ncomp); API_END_NOTFOUND_MAP(session, ret); }
/* * __posix_sys_fallocate -- * Linux fallocate call (system call version). */ static int __posix_sys_fallocate(WT_FILE_HANDLE *file_handle, WT_SESSION *wt_session, wt_off_t offset, wt_off_t len) { #if defined(__linux__) && defined(SYS_fallocate) WT_DECL_RET; WT_FILE_HANDLE_POSIX *pfh; WT_UNUSED(wt_session); pfh = (WT_FILE_HANDLE_POSIX *)file_handle; /* * Try the system call for fallocate even if the C library wrapper was * not found. The system call actually exists in the kernel for some * Linux versions (RHEL 5.5), but not in the version of the C library. * This allows it to work everywhere the kernel supports it. */ WT_SYSCALL_RETRY(syscall(SYS_fallocate, pfh->fd, 0, offset, len), ret); return (ret); #else WT_UNUSED(file_handle); WT_UNUSED(wt_session); WT_UNUSED(offset); WT_UNUSED(len); return (ENOTSUP); #endif }
/* * __win_fs_remove -- * Remove a file. */ static int __win_fs_remove(WT_FILE_SYSTEM *file_system, WT_SESSION *wt_session, const char *name, uint32_t flags) { DWORD windows_error; WT_DECL_ITEM(name_wide); WT_DECL_RET; WT_SESSION_IMPL *session; WT_UNUSED(file_system); WT_UNUSED(flags); session = (WT_SESSION_IMPL *)wt_session; WT_RET(__wt_to_utf16_string(session, name, &name_wide)); if (DeleteFileW(name_wide->data) == FALSE) { windows_error = __wt_getlasterror(); ret = __wt_map_windows_error(windows_error); __wt_err(session, ret, "%s: file-remove: DeleteFileW: %s", name, __wt_formatmessage(session, windows_error)); WT_ERR(ret); } err: __wt_scr_free(session, &name_wide); return (ret); }
/* * __fstream_printf_notsup -- * ANSI C vfprintf unsupported. */ static int __fstream_printf_notsup( WT_SESSION_IMPL *session, WT_FSTREAM *fstr, const char *fmt, va_list ap) { WT_UNUSED(fmt); WT_UNUSED(ap); WT_RET_MSG(session, ENOTSUP, "%s: printf", fstr->name); }
/* * __session_checkpoint -- * WT_SESSION->checkpoint method. */ static int __session_checkpoint(WT_SESSION *wt_session, const char *config) { WT_UNUSED(wt_session); WT_UNUSED(config); return (ENOTSUP); }
/* * __handle_error_verbose -- * Verbose WT_EVENT_HANDLER->handle_error implementation: send to stderr. */ static int __handle_error_verbose(WT_EVENT_HANDLER *handler, int error, const char *errmsg) { WT_UNUSED(handler); WT_UNUSED(error); return (fprintf(stderr, "%s\n", errmsg) < 0 ? EIO : 0); }
/* * __wt_cursor_modify_notsup -- * Unsupported cursor modify. */ int __wt_cursor_modify_notsup(WT_CURSOR *cursor, WT_MODIFY *entries, int nentries) { WT_UNUSED(entries); WT_UNUSED(nentries); return (__wt_cursor_notsup(cursor)); }
/* * __wt_cursor_equals_notsup -- * Unsupported cursor equality. */ int __wt_cursor_equals_notsup(WT_CURSOR *cursor, WT_CURSOR *other, int *equalp) { WT_UNUSED(other); WT_UNUSED(equalp); return (__wt_cursor_notsup(cursor)); }
/* * __wt_cursor_compare_notsup -- * Unsupported cursor comparison. */ int __wt_cursor_compare_notsup(WT_CURSOR *a, WT_CURSOR *b, int *cmpp) { WT_UNUSED(b); WT_UNUSED(cmpp); return (__wt_cursor_notsup(a)); }
/* * __session_rollback_transaction -- * WT_SESSION->rollback_transaction method. */ static int __session_rollback_transaction(WT_SESSION *wt_session, const char *config) { WT_UNUSED(wt_session); WT_UNUSED(config); return (ENOTSUP); }
/* * __bm_free_readonly -- * Free a block of space to the underlying file; readonly version. */ static int __bm_free_readonly(WT_BM *bm, WT_SESSION_IMPL *session, const uint8_t *addr, size_t addr_size) { WT_UNUSED(addr); WT_UNUSED(addr_size); return (__bm_readonly(bm, session)); }
/* * __bm_salvage_next_readonly -- * Return the next block from the file; readonly version. */ static int __bm_salvage_next_readonly(WT_BM *bm, WT_SESSION_IMPL *session, uint8_t *addr, size_t *addr_sizep, bool *eofp) { WT_UNUSED(addr); WT_UNUSED(addr_sizep); WT_UNUSED(eofp); return (__bm_readonly(bm, session)); }
/* * __handle_message_default -- * Default WT_EVENT_HANDLER->handle_message implementation: send to stdout. */ static int __handle_message_default(WT_EVENT_HANDLER *handler, WT_SESSION *session, const char *message) { WT_UNUSED(handler); WT_UNUSED(session); return (printf("%s\n", message) >= 0 && fflush(stdout) == 0 ? 0 : __wt_errno()); }
/* * __handle_close_default -- * Default WT_EVENT_HANDLER->handle_close implementation: ignore. */ static int __handle_close_default(WT_EVENT_HANDLER *handler, WT_SESSION *wt_session, WT_CURSOR *cursor) { WT_UNUSED(handler); WT_UNUSED(wt_session); WT_UNUSED(cursor); return (0); }
static int handle_error(WT_EVENT_HANDLER *handler, WT_SESSION *session, int error, const char *errmsg) { WT_UNUSED(handler); WT_UNUSED(session); WT_UNUSED(error); return (fprintf(stderr, "%s\n", errmsg) < 0 ? -1 : 0); }
/* * __bm_compact_page_skip_readonly -- * Return if a page is useful for compaction; readonly version. */ static int __bm_compact_page_skip_readonly(WT_BM *bm, WT_SESSION_IMPL *session, const uint8_t *addr, size_t addr_size, bool *skipp) { WT_UNUSED(addr); WT_UNUSED(addr_size); WT_UNUSED(skipp); return (__bm_readonly(bm, session)); }
/* * __bm_salvage_valid_readonly -- * Inform salvage a block is valid; readonly version. */ static int __bm_salvage_valid_readonly(WT_BM *bm, WT_SESSION_IMPL *session, uint8_t *addr, size_t addr_size, bool valid) { WT_UNUSED(addr); WT_UNUSED(addr_size); WT_UNUSED(valid); return (__bm_readonly(bm, session)); }
/* * __bm_checkpoint_readonly -- * Write a buffer into a block, creating a checkpoint; readonly version. */ static int __bm_checkpoint_readonly(WT_BM *bm, WT_SESSION_IMPL *session, WT_ITEM *buf, WT_CKPT *ckptbase, bool data_cksum) { WT_UNUSED(buf); WT_UNUSED(ckptbase); WT_UNUSED(data_cksum); return (__bm_readonly(bm, session)); }
/* * __handle_error_default -- * Default WT_EVENT_HANDLER->handle_error implementation: send to stderr. */ static int __handle_error_default(WT_EVENT_HANDLER *handler, WT_SESSION *session, int error, const char *errmsg) { WT_UNUSED(handler); WT_UNUSED(session); WT_UNUSED(error); return (fprintf(stderr, "%s\n", errmsg) >= 0 && fflush(stderr) == 0 ? 0 : __wt_errno()); }
/* * __wt_fallocate -- * Allocate space for a file handle. */ int __wt_fallocate( WT_SESSION_IMPL *session, WT_FH *fh, wt_off_t offset, wt_off_t len) { WT_UNUSED(session); WT_UNUSED(fh); WT_UNUSED(offset); WT_UNUSED(len); return (ENOTSUP); }
/* * __bm_write_readonly -- * Write a buffer into a block, returning the block's address cookie; * readonly version. */ static int __bm_write_readonly(WT_BM *bm, WT_SESSION_IMPL *session, WT_ITEM *buf, uint8_t *addr, size_t *addr_sizep, bool data_cksum) { WT_UNUSED(buf); WT_UNUSED(addr); WT_UNUSED(addr_sizep); WT_UNUSED(data_cksum); return (__bm_readonly(bm, session)); }
/* * __handle_progress_default -- * Default WT_EVENT_HANDLER->handle_progress implementation: ignore. */ static int __handle_progress_default(WT_EVENT_HANDLER *handler, WT_SESSION *wt_session, const char *operation, uint64_t progress) { WT_UNUSED(handler); WT_UNUSED(wt_session); WT_UNUSED(operation); WT_UNUSED(progress); return (0); }
/* * __wt_fallocate -- * Allocate space for a file handle. */ int __wt_fallocate( WT_SESSION_IMPL *session, WT_FH *fh, wt_off_t offset, wt_off_t len) { WT_ASSERT(session, !F_ISSET(S2C(session), WT_CONN_READONLY)); WT_UNUSED(session); WT_UNUSED(fh); WT_UNUSED(offset); WT_UNUSED(len); return (ENOTSUP); }
static int handle_message(WT_EVENT_HANDLER *handler, WT_SESSION *session, const char *message) { WT_UNUSED(handler); WT_UNUSED(session); if (g.logfp != NULL) return (fprintf(g.logfp, "%s\n", message) < 0 ? -1 : 0); return (printf("%s\n", message) < 0 ? -1 : 0); }