Skip to content

Commit

Permalink
MDEV-19335 Remove buf_page_t::encrypted
Browse files Browse the repository at this point in the history
The field buf_page_t::encrypted was added in MDEV-8588.
It was made mostly redundant in MDEV-12699. Remove the field.
  • Loading branch information
Thirunarayanan authored and dr-m committed Oct 9, 2019
1 parent 24232ec commit c65cb24
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 77 deletions.
4 changes: 1 addition & 3 deletions extra/mariabackup/fil_cur.cc
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,9 @@ static bool page_is_corrupted(const byte *page, ulint page_no,

memcpy(tmp_page, page, page_size);

bool decrypted = false;
if (!space->crypt_data
|| space->crypt_data->type == CRYPT_SCHEME_UNENCRYPTED
|| !fil_space_decrypt(space, tmp_frame, tmp_page,
&decrypted)) {
|| !fil_space_decrypt(space, tmp_frame, tmp_page)) {
return true;
}

Expand Down
82 changes: 21 additions & 61 deletions storage/innobase/buf/buf0buf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -589,12 +589,6 @@ static bool buf_page_decrypt_after_read(buf_page_t* bpage, fil_space_t* space)
<< mach_read_from_4(
FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION
+ dst_frame);
/* Mark page encrypted in case it should be. */
if (space->crypt_data->type
!= CRYPT_SCHEME_UNENCRYPTED) {
bpage->encrypted = true;
}

return false;
}

Expand All @@ -605,8 +599,7 @@ static bool buf_page_decrypt_after_read(buf_page_t* bpage, fil_space_t* space)
ut_d(fil_page_type_validate(dst_frame));

/* decrypt using crypt_buf to dst_frame */
if (!fil_space_decrypt(space, slot->crypt_buf,
dst_frame, &bpage->encrypted)) {
if (!fil_space_decrypt(space, slot->crypt_buf, dst_frame)) {
slot->release();
goto decrypt_failed;
}
Expand Down Expand Up @@ -1534,7 +1527,6 @@ buf_block_init(
block->page.buf_fix_count = 0;
block->page.io_fix = BUF_IO_NONE;
block->page.flush_observer = NULL;
block->page.encrypted = false;
block->page.real_size = 0;
block->page.write_size = 0;
block->modify_clock = 0;
Expand Down Expand Up @@ -4044,7 +4036,6 @@ buf_zip_decompress(
if (encrypted) {
ib::info() << "Row compressed page could be encrypted"
" with key_version " << key_version;
block->page.encrypted = true;
dict_set_encrypted_by_space(block->page.id.space());
} else {
dict_set_corrupted_by_space(block->page.id.space());
Expand Down Expand Up @@ -5248,7 +5239,6 @@ buf_page_init_low(
bpage->newest_modification = 0;
bpage->oldest_modification = 0;
bpage->write_size = 0;
bpage->encrypted = false;
bpage->real_size = 0;
bpage->slot = NULL;

Expand Down Expand Up @@ -5841,15 +5831,16 @@ buf_page_monitor(
}

/** Mark a table corrupted.
@param[in] bpage Corrupted page. */
static
void
buf_mark_space_corrupt(buf_page_t* bpage)
@param[in] bpage corrupted page
@param[in] space tablespace of the corrupted page */
ATTRIBUTE_COLD
static void buf_mark_space_corrupt(buf_page_t* bpage, const fil_space_t& space)
{
/* If block is not encrypted find the table with specified
space id, and mark it corrupted. Encrypted tables
are marked unusable later e.g. in ::open(). */
if (!bpage->encrypted) {
if (!space.crypt_data
|| space.crypt_data->type == CRYPT_SCHEME_UNENCRYPTED) {
dict_set_corrupted_by_space(bpage->id.space());
} else {
dict_set_encrypted_by_space(bpage->id.space());
Expand Down Expand Up @@ -5891,7 +5882,7 @@ buf_corrupt_page_release(buf_page_t* bpage, const fil_space_t* space)
mutex_exit(buf_page_get_mutex(bpage));

if (!srv_force_recovery) {
buf_mark_space_corrupt(bpage);
buf_mark_space_corrupt(bpage, *space);
}

/* After this point bpage can't be referenced. */
Expand Down Expand Up @@ -5921,41 +5912,27 @@ static dberr_t buf_page_check_corrupt(buf_page_t* bpage, fil_space_t* space)
byte* dst_frame = (bpage->zip.data) ? bpage->zip.data :
((buf_block_t*) bpage)->frame;
dberr_t err = DB_SUCCESS;
bool corrupted = false;

/* In buf_decrypt_after_read we have either decrypted the page if
page post encryption checksum matches and used key_id is found
from the encryption plugin. If checksum did not match page was
not decrypted and it could be either encrypted and corrupted
or corrupted or good page. If we decrypted, there page could
still be corrupted if used key does not match. */
const bool still_encrypted = mach_read_from_4(
const bool seems_encrypted = mach_read_from_4(
dst_frame + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION)
&& space->crypt_data
&& space->crypt_data->type != CRYPT_SCHEME_UNENCRYPTED
&& !bpage->encrypted
&& fil_space_verify_crypt_checksum(dst_frame, bpage->size);

if (!still_encrypted) {
/* If traditional checksums match, we assume that page is
not anymore encrypted. */
corrupted = buf_page_is_corrupted(
true, dst_frame, bpage->size, space);

if (!corrupted) {
bpage->encrypted = false;
} else {
err = DB_PAGE_CORRUPTED;
}
&& space->crypt_data->type != CRYPT_SCHEME_UNENCRYPTED;

/* If traditional checksums match, we assume that page is
not anymore encrypted. */
if (buf_page_is_corrupted(
true, dst_frame, bpage->size, space)) {
err = DB_PAGE_CORRUPTED;
}

/* Pages that we think are unencrypted but do not match the checksum
checks could be corrupted or encrypted or both. */
if (corrupted && !bpage->encrypted) {
/* An error will be reported by
buf_page_io_complete(). */
} else if (still_encrypted || (bpage->encrypted && corrupted)) {
bpage->encrypted = true;
if (seems_encrypted && err == DB_PAGE_CORRUPTED
&& bpage->id.page_no() != 0) {
err = DB_DECRYPTION_FAILED;

ib::error()
Expand Down Expand Up @@ -6017,7 +5994,6 @@ buf_page_io_complete(buf_page_t* bpage, bool dblwr, bool evict)
if (io_type == BUF_IO_READ) {
ulint read_page_no = 0;
ulint read_space_id = 0;
uint key_version = 0;
byte* frame = bpage->zip.data
? bpage->zip.data
: reinterpret_cast<buf_block_t*>(bpage)->frame;
Expand Down Expand Up @@ -6057,8 +6033,6 @@ buf_page_io_complete(buf_page_t* bpage, bool dblwr, bool evict)
read_page_no = mach_read_from_4(frame + FIL_PAGE_OFFSET);
read_space_id = mach_read_from_4(
frame + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID);
key_version = mach_read_from_4(
frame + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION);

if (bpage->id.space() == TRX_SYS_SPACE
&& buf_dblwr_page_inside(bpage->id.page_no())) {
Expand Down Expand Up @@ -6174,23 +6148,9 @@ buf_page_io_complete(buf_page_t* bpage, bool dblwr, bool evict)
&& fil_page_get_type(frame) == FIL_PAGE_INDEX
&& page_is_leaf(frame)) {

if (bpage->encrypted) {
ib::warn()
<< "Table in tablespace "
<< bpage->id.space()
<< " encrypted. However key "
"management plugin or used "
<< "key_version " << key_version
<< " is not found or"
" used encryption algorithm or method does not match."
" Can't continue opening the table.";
} else {

ibuf_merge_or_delete_for_page(
(buf_block_t*) bpage, bpage->id,
&bpage->size, TRUE);
}

ibuf_merge_or_delete_for_page(
(buf_block_t*) bpage, bpage->id,
&bpage->size, TRUE);
}

fil_space_release_for_io(space);
Expand Down
6 changes: 1 addition & 5 deletions storage/innobase/fil/fil0crypt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -793,21 +793,18 @@ Decrypt a page.
@param[in] space Tablespace
@param[in] tmp_frame Temporary buffer used for decrypting
@param[in,out] src_frame Page to decrypt
@param[out] decrypted true if page was decrypted
@return decrypted page, or original not encrypted page if decryption is
not needed.*/
UNIV_INTERN
byte*
fil_space_decrypt(
const fil_space_t* space,
byte* tmp_frame,
byte* src_frame,
bool* decrypted)
byte* src_frame)
{
dberr_t err = DB_SUCCESS;
byte* res = NULL;
const page_size_t page_size(space->flags);
*decrypted = false;

ut_ad(space->crypt_data != NULL && space->crypt_data->is_encrypted());
ut_ad(space->n_pending_ios > 0);
Expand All @@ -817,7 +814,6 @@ fil_space_decrypt(

if (err == DB_SUCCESS) {
if (encrypted) {
*decrypted = true;
/* Copy the decrypted page back to page buffer, not
really any other options. */
memcpy(src_frame, tmp_frame, page_size.physical());
Expand Down
4 changes: 1 addition & 3 deletions storage/innobase/ibuf/ibuf0ibuf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,8 @@ ibuf_header_page_get(
page_id_t(IBUF_SPACE_ID, FSP_IBUF_HEADER_PAGE_NO),
univ_page_size, RW_X_LATCH, mtr);


if (!block->page.encrypted) {
if (block) {
buf_block_dbg_add_level(block, SYNC_IBUF_HEADER);

page = buf_block_get_frame(block);
}

Expand Down
2 changes: 0 additions & 2 deletions storage/innobase/include/buf0buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -1468,8 +1468,6 @@ class buf_page_t {
if written again we check is TRIM
operation needed. */

bool encrypted; /*!< page is still encrypted */

ulint real_size; /*!< Real size of the page
Normal pages == UNIV_PAGE_SIZE
page compressed pages, payload
Expand Down
4 changes: 1 addition & 3 deletions storage/innobase/include/fil0crypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,16 +375,14 @@ Decrypt a page
@param[in] space Tablespace
@param[in] tmp_frame Temporary buffer used for decrypting
@param[in,out] src_frame Page to decrypt
@param[out] decrypted true if page was decrypted
@return decrypted page, or original not encrypted page if decryption is
not needed.*/
UNIV_INTERN
byte*
fil_space_decrypt(
const fil_space_t* space,
byte* tmp_frame,
byte* src_frame,
bool* decrypted)
byte* src_frame)
MY_ATTRIBUTE((warn_unused_result));

/******************************************************************
Expand Down

0 comments on commit c65cb24

Please sign in to comment.