Pass down the information should we encrypt the page at os0file.cc

when page compression and google encryption is used.
This commit is contained in:
Jan Lindström 2015-01-09 12:30:59 +02:00 committed by Sergei Golubchik
commit e2e809860e
28 changed files with 425 additions and 249 deletions

View file

@ -1006,6 +1006,7 @@ buf_block_init(
block->page.comp_buf = NULL; block->page.comp_buf = NULL;
block->page.comp_buf_free = NULL; block->page.comp_buf_free = NULL;
block->page.key_version = 0; block->page.key_version = 0;
block->page.encrypt_later = false;
block->modify_clock = 0; block->modify_clock = 0;
@ -3498,6 +3499,7 @@ buf_page_init_low(
bpage->comp_buf = NULL; bpage->comp_buf = NULL;
bpage->comp_buf_free = NULL; bpage->comp_buf_free = NULL;
bpage->key_version = 0; bpage->key_version = 0;
bpage->encrypt_later = false;
HASH_INVALIDATE(bpage, hash); HASH_INVALIDATE(bpage, hash);
#if defined UNIV_DEBUG_FILE_ACCESSES || defined UNIV_DEBUG #if defined UNIV_DEBUG_FILE_ACCESSES || defined UNIV_DEBUG
@ -5609,6 +5611,8 @@ buf_page_encrypt_before_write(
buf_page_t* bpage, /*!< in/out: buffer page to be flushed */ buf_page_t* bpage, /*!< in/out: buffer page to be flushed */
const byte* src_frame) /*!< in: src frame */ const byte* src_frame) /*!< in: src frame */
{ {
bpage->encrypt_later = false;
if (srv_encrypt_tables == FALSE) { if (srv_encrypt_tables == FALSE) {
/* Encryption is disabled */ /* Encryption is disabled */
return const_cast<byte*>(src_frame); return const_cast<byte*>(src_frame);
@ -5669,7 +5673,8 @@ buf_page_encrypt_before_write(
ut_ad(key_version == 0 || key_version >= bpage->key_version); ut_ad(key_version == 0 || key_version >= bpage->key_version);
bpage->key_version = key_version; bpage->key_version = key_version;
} else { } else {
// We do compression and encryption later on os0file.cc /** Compression and encryption is done later at os0file.cc */
bpage->encrypt_later = true;
dst_frame = (byte *)src_frame; dst_frame = (byte *)src_frame;
} }

View file

@ -521,10 +521,18 @@ buf_dblwr_process()
ulint zip_size = fil_space_get_zip_size(space_id); ulint zip_size = fil_space_get_zip_size(space_id);
/* Read in the actual page from the file */ /* Read in the actual page from the file */
fil_io(OS_FILE_READ, true, space_id, zip_size, fil_io(OS_FILE_READ,
page_no, 0, true,
zip_size ? zip_size : UNIV_PAGE_SIZE, space_id,
read_buf, NULL, 0, 0); zip_size,
page_no,
0,
zip_size ? zip_size : UNIV_PAGE_SIZE,
read_buf,
NULL,
0,
0,
false);
if (fil_space_verify_crypt_checksum(read_buf, zip_size)) { if (fil_space_verify_crypt_checksum(read_buf, zip_size)) {
/* page is encrypted and checksum is OK */ /* page is encrypted and checksum is OK */
@ -576,10 +584,18 @@ buf_dblwr_process()
doublewrite buffer to the intended doublewrite buffer to the intended
position */ position */
fil_io(OS_FILE_WRITE, true, space_id, fil_io(OS_FILE_WRITE,
zip_size, page_no, 0, true,
zip_size ? zip_size : UNIV_PAGE_SIZE, space_id,
page, NULL, 0, 0); zip_size,
page_no,
0,
zip_size ? zip_size : UNIV_PAGE_SIZE,
page,
NULL,
0,
0,
false);
ib_logf(IB_LOG_LEVEL_INFO, ib_logf(IB_LOG_LEVEL_INFO,
"Recovered the page from" "Recovered the page from"
@ -595,11 +611,18 @@ buf_dblwr_process()
zeroes, while a valid copy is zeroes, while a valid copy is
available in dblwr buffer. */ available in dblwr buffer. */
fil_io(OS_FILE_WRITE, true, space_id, fil_io(OS_FILE_WRITE,
zip_size, page_no, 0, true,
zip_size ? zip_size space_id,
: UNIV_PAGE_SIZE, zip_size,
page, NULL, 0, 0); page_no,
0,
zip_size ? zip_size : UNIV_PAGE_SIZE,
page,
NULL,
0,
0,
false);
} }
} }
} }
@ -621,9 +644,9 @@ buf_dblwr_process()
memset(buf, 0, bytes); memset(buf, 0, bytes);
fil_io(OS_FILE_WRITE, true, TRX_SYS_SPACE, 0, fil_io(OS_FILE_WRITE, true, TRX_SYS_SPACE, 0,
buf_dblwr->block1, 0, bytes, buf, NULL, NULL, 0); buf_dblwr->block1, 0, bytes, buf, NULL, NULL, 0, false);
fil_io(OS_FILE_WRITE, true, TRX_SYS_SPACE, 0, fil_io(OS_FILE_WRITE, true, TRX_SYS_SPACE, 0,
buf_dblwr->block2, 0, bytes, buf, NULL, NULL, 0); buf_dblwr->block2, 0, bytes, buf, NULL, NULL, 0, false);
ut_free(unaligned_buf); ut_free(unaligned_buf);
} }
@ -828,12 +851,18 @@ buf_dblwr_write_block_to_datafile(
void * frame = buf_page_get_frame(bpage); void * frame = buf_page_get_frame(bpage);
if (bpage->zip.data) { if (bpage->zip.data) {
fil_io(flags, sync, buf_page_get_space(bpage), fil_io(flags,
buf_page_get_zip_size(bpage), sync,
buf_page_get_page_no(bpage), 0, buf_page_get_space(bpage),
buf_page_get_zip_size(bpage), buf_page_get_zip_size(bpage),
frame, buf_page_get_page_no(bpage),
(void*) bpage, 0, bpage->newest_modification); 0,
buf_page_get_zip_size(bpage),
frame,
(void*) bpage,
0,
bpage->newest_modification,
bpage->encrypt_later);
return; return;
} }
@ -843,12 +872,18 @@ buf_dblwr_write_block_to_datafile(
ut_a(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE); ut_a(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE);
buf_dblwr_check_page_lsn(block->frame); buf_dblwr_check_page_lsn(block->frame);
fprintf(stderr, "JAN: space %lu page_type %lu\n", buf_block_get_space(block), fil_io(flags,
mach_read_from_2((byte *)frame+FIL_PAGE_TYPE)); sync,
buf_block_get_space(block),
fil_io(flags, sync, buf_block_get_space(block), 0, 0,
buf_block_get_page_no(block), 0, UNIV_PAGE_SIZE, buf_block_get_page_no(block),
frame, (void*) block, (ulint *)&bpage->write_size, bpage->newest_modification ); 0,
UNIV_PAGE_SIZE,
frame,
(void*) block,
(ulint *)&bpage->write_size,
bpage->newest_modification,
bpage->encrypt_later);
} }
/********************************************************************//** /********************************************************************//**
@ -942,7 +977,7 @@ try_again:
fil_io(OS_FILE_WRITE, true, TRX_SYS_SPACE, 0, fil_io(OS_FILE_WRITE, true, TRX_SYS_SPACE, 0,
buf_dblwr->block1, 0, len, buf_dblwr->block1, 0, len,
(void*) write_buf, NULL, 0, 0); (void*) write_buf, NULL, 0, 0, false);
if (buf_dblwr->first_free <= TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) { if (buf_dblwr->first_free <= TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) {
/* No unwritten pages in the second block. */ /* No unwritten pages in the second block. */
@ -958,7 +993,7 @@ try_again:
fil_io(OS_FILE_WRITE, true, TRX_SYS_SPACE, 0, fil_io(OS_FILE_WRITE, true, TRX_SYS_SPACE, 0,
buf_dblwr->block2, 0, len, buf_dblwr->block2, 0, len,
(void*) write_buf, NULL, 0, 0); (void*) write_buf, NULL, 0, 0, false);
flush: flush:
/* increment the doublewrite flushed pages counter */ /* increment the doublewrite flushed pages counter */
@ -1187,17 +1222,31 @@ retry:
memset(buf_dblwr->write_buf + UNIV_PAGE_SIZE * i memset(buf_dblwr->write_buf + UNIV_PAGE_SIZE * i
+ zip_size, 0, UNIV_PAGE_SIZE - zip_size); + zip_size, 0, UNIV_PAGE_SIZE - zip_size);
fil_io(OS_FILE_WRITE, true, TRX_SYS_SPACE, 0, fil_io(OS_FILE_WRITE,
offset, 0, UNIV_PAGE_SIZE, true,
(void*) (buf_dblwr->write_buf TRX_SYS_SPACE, 0,
+ UNIV_PAGE_SIZE * i), NULL, 0, bpage->newest_modification); offset,
0,
UNIV_PAGE_SIZE,
(void*) (buf_dblwr->write_buf + UNIV_PAGE_SIZE * i),
NULL,
0,
bpage->newest_modification,
bpage->encrypt_later);
} else { } else {
/* It is a regular page. Write it directly to the /* It is a regular page. Write it directly to the
doublewrite buffer */ doublewrite buffer */
fil_io(OS_FILE_WRITE, true, TRX_SYS_SPACE, 0, fil_io(OS_FILE_WRITE,
offset, 0, UNIV_PAGE_SIZE, true,
frame, TRX_SYS_SPACE, 0,
NULL, 0, bpage->newest_modification); offset,
0,
UNIV_PAGE_SIZE,
frame,
NULL,
0,
bpage->newest_modification,
bpage->encrypt_later);
} }
/* Now flush the doublewrite buffer data to disk */ /* Now flush the doublewrite buffer data to disk */

View file

@ -913,16 +913,17 @@ buf_flush_write_block_low(
if (!srv_use_doublewrite_buf || !buf_dblwr) { if (!srv_use_doublewrite_buf || !buf_dblwr) {
fil_io(OS_FILE_WRITE | OS_AIO_SIMULATED_WAKE_LATER, fil_io(OS_FILE_WRITE | OS_AIO_SIMULATED_WAKE_LATER,
sync, sync,
buf_page_get_space(bpage), buf_page_get_space(bpage),
zip_size, zip_size,
buf_page_get_page_no(bpage), buf_page_get_page_no(bpage),
0, 0,
zip_size ? zip_size : UNIV_PAGE_SIZE, zip_size ? zip_size : UNIV_PAGE_SIZE,
frame, frame,
bpage, bpage,
&bpage->write_size, &bpage->write_size,
bpage->newest_modification); bpage->newest_modification,
bpage->encrypt_later);
} else { } else {
/* InnoDB uses doublewrite buffer and doublewrite buffer /* InnoDB uses doublewrite buffer and doublewrite buffer
@ -943,7 +944,8 @@ buf_flush_write_block_low(
frame, frame,
bpage, bpage,
&bpage->write_size, &bpage->write_size,
bpage->newest_modification); bpage->newest_modification,
bpage->encrypt_later);
} else if (flush_type == BUF_FLUSH_SINGLE_PAGE) { } else if (flush_type == BUF_FLUSH_SINGLE_PAGE) {
buf_dblwr_write_single_page(bpage, sync); buf_dblwr_write_single_page(bpage, sync);
} else { } else {

View file

@ -184,17 +184,17 @@ buf_read_page_low(
if (zip_size) { if (zip_size) {
*err = fil_io(OS_FILE_READ | wake_later *err = fil_io(OS_FILE_READ | wake_later
| ignore_nonexistent_pages, | ignore_nonexistent_pages,
sync, space, zip_size, offset, 0, zip_size, sync, space, zip_size, offset, 0, zip_size,
frame, bpage, &bpage->write_size, 0); frame, bpage, &bpage->write_size, 0, false);
} else { } else {
ut_a(buf_page_get_state(bpage) == BUF_BLOCK_FILE_PAGE); ut_a(buf_page_get_state(bpage) == BUF_BLOCK_FILE_PAGE);
*err = fil_io(OS_FILE_READ | wake_later *err = fil_io(OS_FILE_READ | wake_later
| ignore_nonexistent_pages, | ignore_nonexistent_pages,
sync, space, 0, offset, 0, UNIV_PAGE_SIZE, sync, space, 0, offset, 0, UNIV_PAGE_SIZE,
frame, bpage, frame, bpage,
&bpage->write_size, 0); &bpage->write_size, 0, false);
} }
if (sync) { if (sync) {

View file

@ -621,13 +621,25 @@ fil_space_encrypt(ulint space, ulint offset, lsn_t lsn,
byte key[MY_AES_MAX_KEY_LENGTH]; byte key[MY_AES_MAX_KEY_LENGTH];
uint key_length; uint key_length;
ulint orig_page_type = mach_read_from_2(src_frame+FIL_PAGE_TYPE);
if (orig_page_type==FIL_PAGE_TYPE_FSP_HDR
|| orig_page_type==FIL_PAGE_TYPE_XDES
|| orig_page_type== FIL_PAGE_PAGE_ENCRYPTED
|| orig_page_type== FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED) {
//TODO: is this really needed ?
memcpy(dst_frame, src_frame, page_size);
return;
}
if (srv_encrypt_tables) { if (srv_encrypt_tables) {
crypt_data = fil_space_get_crypt_data(space); crypt_data = fil_space_get_crypt_data(space);
if (crypt_data == NULL) { if (crypt_data == NULL) {
//TODO: Is this really needed ? //TODO: Is this really needed ?
memcpy(dst_frame, src_frame, page_size); memcpy(dst_frame, src_frame, page_size);
return; return;
} }
fil_crypt_get_latest_key(key, &key_length, crypt_data, &key_version); fil_crypt_get_latest_key(key, &key_length, crypt_data, &key_version);
} else { } else {
key_version = encryption_key; key_version = encryption_key;
@ -646,9 +658,7 @@ fil_space_encrypt(ulint space, ulint offset, lsn_t lsn,
src_frame + FIL_PAGE_OFFSET); src_frame + FIL_PAGE_OFFSET);
mach_write_to_4(iv + 4, space_offset); mach_write_to_4(iv + 4, space_offset);
mach_write_to_8(iv + 8, lsn); mach_write_to_8(iv + 8, lsn);
} } else {
else
{
// take the iv from the key provider // take the iv from the key provider
int load_iv_rc = get_encryption_iv(key_version, (uchar *) iv, sizeof(iv)); int load_iv_rc = get_encryption_iv(key_version, (uchar *) iv, sizeof(iv));
@ -666,21 +676,10 @@ fil_space_encrypt(ulint space, ulint offset, lsn_t lsn,
} }
} }
ibool page_compressed = (mach_read_from_2(src_frame+FIL_PAGE_TYPE) == FIL_PAGE_PAGE_COMPRESSED); ibool page_compressed = (mach_read_from_2(src_frame+FIL_PAGE_TYPE) == FIL_PAGE_PAGE_COMPRESSED);
ibool page_encrypted = fil_space_is_page_encrypted(space); ibool page_encrypted = fil_space_is_page_encrypted(space);
ulint compression_alg = mach_read_from_8(src_frame+FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION); ulint compression_alg = mach_read_from_8(src_frame+FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION);
ulint orig_page_type = mach_read_from_2(src_frame+FIL_PAGE_TYPE);
if (orig_page_type==FIL_PAGE_TYPE_FSP_HDR
|| orig_page_type==FIL_PAGE_TYPE_XDES
|| orig_page_type== FIL_PAGE_PAGE_ENCRYPTED
|| orig_page_type== FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED) {
memcpy(dst_frame, src_frame, page_size);
return;
}
// copy page header // copy page header
memcpy(dst_frame, src_frame, FIL_PAGE_DATA); memcpy(dst_frame, src_frame, FIL_PAGE_DATA);
@ -711,7 +710,6 @@ fil_space_encrypt(ulint space, ulint offset, lsn_t lsn,
srclen = page_size - FIL_PAGE_DATA;; srclen = page_size - FIL_PAGE_DATA;;
} }
int rc = (* my_aes_encrypt_dynamic)(src, srclen, int rc = (* my_aes_encrypt_dynamic)(src, srclen,
dst, &dstlen, dst, &dstlen,
(unsigned char*)key, key_length, (unsigned char*)key, key_length,
@ -790,6 +788,7 @@ fil_space_check_encryption_read(
ulint space) /*!< in: tablespace id */ ulint space) /*!< in: tablespace id */
{ {
fil_space_crypt_t* crypt_data = fil_space_get_crypt_data(space); fil_space_crypt_t* crypt_data = fil_space_get_crypt_data(space);
if (crypt_data == NULL) if (crypt_data == NULL)
return false; return false;
@ -816,6 +815,7 @@ fil_space_decrypt(fil_space_crypt_t* crypt_data,
|| page_type == FIL_PAGE_PAGE_COMPRESSED); || page_type == FIL_PAGE_PAGE_COMPRESSED);
ulint orig_page_type=0; ulint orig_page_type=0;
if (page_type == FIL_PAGE_PAGE_ENCRYPTED) { if (page_type == FIL_PAGE_PAGE_ENCRYPTED) {
key_version = mach_read_from_2( key_version = mach_read_from_2(
src_frame + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION); src_frame + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION);
@ -847,7 +847,6 @@ fil_space_decrypt(fil_space_crypt_t* crypt_data,
mach_write_to_2(dst_frame+FIL_PAGE_TYPE, orig_page_type); mach_write_to_2(dst_frame+FIL_PAGE_TYPE, orig_page_type);
} }
// get key // get key
byte key[MY_AES_MAX_KEY_LENGTH]; byte key[MY_AES_MAX_KEY_LENGTH];
uint key_length; uint key_length;
@ -863,9 +862,7 @@ fil_space_decrypt(fil_space_crypt_t* crypt_data,
mach_write_to_4(iv + 0, space); mach_write_to_4(iv + 0, space);
mach_write_to_4(iv + 4, offset); mach_write_to_4(iv + 4, offset);
mach_write_to_8(iv + 8, lsn); mach_write_to_8(iv + 8, lsn);
} } else {
else
{
// take the iv from the key provider // take the iv from the key provider
int load_iv_rc = get_encryption_iv(key_version, (uchar *) iv, sizeof(iv)); int load_iv_rc = get_encryption_iv(key_version, (uchar *) iv, sizeof(iv));
@ -887,7 +884,6 @@ fil_space_decrypt(fil_space_crypt_t* crypt_data,
byte* dst = dst_frame + FIL_PAGE_DATA; byte* dst = dst_frame + FIL_PAGE_DATA;
uint32 dstlen; uint32 dstlen;
ulint srclen = page_size - (FIL_PAGE_DATA + FIL_PAGE_DATA_END); ulint srclen = page_size - (FIL_PAGE_DATA + FIL_PAGE_DATA_END);
ulint compressed_len; ulint compressed_len;
ulint compression_method; ulint compression_method;

View file

@ -284,7 +284,7 @@ fil_read(
actual page size does not decrease. */ actual page size does not decrease. */
{ {
return(fil_io(OS_FILE_READ, sync, space_id, zip_size, block_offset, return(fil_io(OS_FILE_READ, sync, space_id, zip_size, block_offset,
byte_offset, len, buf, message, write_size, 0)); byte_offset, len, buf, message, write_size, 0, false));
} }
/********************************************************************//** /********************************************************************//**
@ -316,12 +316,13 @@ fil_write(
operation for this page and if operation for this page and if
initialized we do not trim again if initialized we do not trim again if
actual page size does not decrease. */ actual page size does not decrease. */
lsn_t lsn) /* lsn of the newest modification */ lsn_t lsn, /*!< in: lsn of the newest modification */
bool encrypt_later) /*!< in: encrypt later ? */
{ {
ut_ad(!srv_read_only_mode); ut_ad(!srv_read_only_mode);
return(fil_io(OS_FILE_WRITE, sync, space_id, zip_size, block_offset, return(fil_io(OS_FILE_WRITE, sync, space_id, zip_size, block_offset,
byte_offset, len, buf, message, write_size, lsn)); byte_offset, len, buf, message, write_size, lsn, encrypt_later));
} }
/*******************************************************************//** /*******************************************************************//**
@ -614,6 +615,8 @@ fil_node_open_file(
ut_a(size_bytes != (os_offset_t) -1); ut_a(size_bytes != (os_offset_t) -1);
node->file_block_size = os_file_get_block_size(node->handle, node->name); node->file_block_size = os_file_get_block_size(node->handle, node->name);
space->file_block_size = node->file_block_size;
#ifdef UNIV_HOTBACKUP #ifdef UNIV_HOTBACKUP
if (space->id == 0) { if (space->id == 0) {
node->size = (ulint) (size_bytes / UNIV_PAGE_SIZE); node->size = (ulint) (size_bytes / UNIV_PAGE_SIZE);
@ -780,6 +783,7 @@ add_size:
if (node->file_block_size == 0) { if (node->file_block_size == 0) {
node->file_block_size = os_file_get_block_size(node->handle, node->name); node->file_block_size = os_file_get_block_size(node->handle, node->name);
space->file_block_size = node->file_block_size;
} }
ut_a(ret); ut_a(ret);
@ -1831,7 +1835,7 @@ fil_write_lsn_and_arch_no_to_file(
lsn); lsn);
err = fil_write(TRUE, space, 0, sum_of_sizes, 0, err = fil_write(TRUE, space, 0, sum_of_sizes, 0,
UNIV_PAGE_SIZE, buf, NULL, 0, lsn); UNIV_PAGE_SIZE, buf, NULL, 0, lsn, false);
} }
mem_free(buf1); mem_free(buf1);
@ -5151,6 +5155,7 @@ retry:
/* Determine correct file block size */ /* Determine correct file block size */
if (node->file_block_size == 0) { if (node->file_block_size == 0) {
node->file_block_size = os_file_get_block_size(node->handle, node->name); node->file_block_size = os_file_get_block_size(node->handle, node->name);
space->file_block_size = node->file_block_size;
} }
#ifdef HAVE_POSIX_FALLOCATE #ifdef HAVE_POSIX_FALLOCATE
@ -5211,7 +5216,7 @@ retry:
success = os_aio(OS_FILE_WRITE, OS_AIO_SYNC, success = os_aio(OS_FILE_WRITE, OS_AIO_SYNC,
node->name, node->handle, buf, node->name, node->handle, buf,
offset, page_size * n_pages, offset, page_size * n_pages,
node, NULL, 0, FALSE, 0, 0, 0, 0); node, NULL, 0, FALSE, 0, 0, 0, 0, false);
#endif /* UNIV_HOTBACKUP */ #endif /* UNIV_HOTBACKUP */
if (success) { if (success) {
os_has_said_disk_full = FALSE; os_has_said_disk_full = FALSE;
@ -5592,7 +5597,8 @@ fil_io(
operation for this page and if operation for this page and if
initialized we do not trim again if initialized we do not trim again if
actual page size does not decrease. */ actual page size does not decrease. */
lsn_t lsn) /* lsn of the newest modification */ lsn_t lsn, /*!< in: lsn of the newest modification */
bool encrypt_later) /*!< in: encrypt later ? */
{ {
ulint mode; ulint mode;
fil_space_t* space; fil_space_t* space;
@ -5820,7 +5826,8 @@ fil_io(
page_compression_level, page_compression_level,
page_encrypted, page_encrypted,
page_encryption_key, page_encryption_key,
lsn); lsn,
encrypt_later);
#endif /* UNIV_HOTBACKUP */ #endif /* UNIV_HOTBACKUP */

View file

@ -281,11 +281,10 @@ fil_compress_page(
/* read original page type */ /* read original page type */
orig_page_type = mach_read_from_2(buf + FIL_PAGE_TYPE); orig_page_type = mach_read_from_2(buf + FIL_PAGE_TYPE);
ut_ad(orig_page_type != 0);
/* Let's not compress file space header or /* Let's not compress file space header or
extent descriptor */ extent descriptor */
if (orig_page_type == FIL_PAGE_TYPE_FSP_HDR || if (orig_page_type == 0 ||
orig_page_type == FIL_PAGE_TYPE_FSP_HDR ||
orig_page_type == FIL_PAGE_TYPE_XDES || orig_page_type == FIL_PAGE_TYPE_XDES ||
orig_page_type == FIL_PAGE_PAGE_COMPRESSED || orig_page_type == FIL_PAGE_PAGE_COMPRESSED ||
orig_page_type == FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED) { orig_page_type == FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED) {

View file

@ -1566,6 +1566,8 @@ struct buf_page_t{
can be read while it's being flushed */ can be read while it's being flushed */
byte* comp_buf_free; /*!< for compression, allocated byte* comp_buf_free; /*!< for compression, allocated
buffer that is then alligned */ buffer that is then alligned */
bool encrypt_later; /*!< should we encrypt the page
at os0file.cc ? */
#ifndef UNIV_HOTBACKUP #ifndef UNIV_HOTBACKUP
buf_page_t* hash; /*!< node used in chaining to buf_page_t* hash; /*!< node used in chaining to

View file

@ -1,7 +1,7 @@
/***************************************************************************** /*****************************************************************************
Copyright (c) 1995, 2014, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 1995, 2014, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2013, 2014, SkySQL Ab. All Rights Reserved. Copyright (c) 2013, 2015, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software the terms of the GNU General Public License as published by the Free Software
@ -346,6 +346,7 @@ struct fil_space_t {
UT_LIST_NODE_T(fil_space_t) space_list; UT_LIST_NODE_T(fil_space_t) space_list;
/*!< list of all spaces */ /*!< list of all spaces */
fil_space_crypt_t* crypt_data; fil_space_crypt_t* crypt_data;
ulint file_block_size;/*!< file system block size */
ulint magic_n;/*!< FIL_SPACE_MAGIC_N */ ulint magic_n;/*!< FIL_SPACE_MAGIC_N */
}; };
@ -998,7 +999,8 @@ fil_io(
operation for this page and if operation for this page and if
initialized we do not trim again if initialized we do not trim again if
actual page size does not decrease. */ actual page size does not decrease. */
lsn_t lsn) /* lsn of the newest modification */ lsn_t lsn, /*!< in: lsn of the newest modification */
bool encrypt_later) /*!< in: should we encrypt the page */
__attribute__((nonnull(8))); __attribute__((nonnull(8)));
/**********************************************************************//** /**********************************************************************//**
Waits for an aio operation to complete. This function is used to write the Waits for an aio operation to complete. This function is used to write the

View file

@ -2,7 +2,7 @@
Copyright (c) 1995, 2013, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 1995, 2013, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2009, Percona Inc. Copyright (c) 2009, Percona Inc.
Copyright (c) 2013, SkySQL Ab. All Rights Reserved. Copyright (c) 2013, 2015, MariaDB Corporation.
Portions of this file contain modifications contributed and copyrighted Portions of this file contain modifications contributed and copyrighted
by Percona Inc.. Those modifications are by Percona Inc.. Those modifications are
@ -314,12 +314,12 @@ The wrapper functions have the prefix of "innodb_". */
# define os_aio(type, mode, name, file, buf, offset, \ # define os_aio(type, mode, name, file, buf, offset, \
n, message1, message2, write_size, \ n, message1, message2, write_size, \
page_compression, page_compression_level, \ page_compression, page_compression_level, \
page_encryption, page_encryption_key, lsn) \ page_encryption, page_encryption_key, lsn, encrypt) \
pfs_os_aio_func(type, mode, name, file, buf, offset, \ pfs_os_aio_func(type, mode, name, file, buf, offset, \
n, message1, message2, write_size, \ n, message1, message2, write_size, \
page_compression, page_compression_level, \ page_compression, page_compression_level, \
page_encryption, page_encryption_key, \ page_encryption, page_encryption_key, \
lsn, __FILE__, __LINE__) lsn, encrypt, __FILE__, __LINE__)
# define os_file_read(file, buf, offset, n, compressed) \ # define os_file_read(file, buf, offset, n, compressed) \
@ -363,11 +363,11 @@ to original un-instrumented file I/O APIs */
# define os_aio(type, mode, name, file, buf, offset, n, message1, \ # define os_aio(type, mode, name, file, buf, offset, n, message1, \
message2, write_size, page_compression, page_compression_level, \ message2, write_size, page_compression, page_compression_level, \
page_encryption, page_encryption_key, lsn) \ page_encryption, page_encryption_key, lsn, encrypt) \
os_aio_func(type, mode, name, file, buf, offset, n, \ os_aio_func(type, mode, name, file, buf, offset, n, \
message1, message2, write_size, \ message1, message2, write_size, \
page_compression, page_compression_level, \ page_compression, page_compression_level, \
page_encryption, page_encryption_key, lsn) page_encryption, page_encryption_key, lsn, encrypt)
# define os_file_read(file, buf, offset, n, compressed) \ # define os_file_read(file, buf, offset, n, compressed) \
os_file_read_func(file, buf, offset, n, compressed) os_file_read_func(file, buf, offset, n, compressed)
@ -787,9 +787,10 @@ pfs_os_aio_func(
level to be used */ level to be used */
ibool page_encryption, /*!< in: is page encryption used ibool page_encryption, /*!< in: is page encryption used
on this file space */ on this file space */
ulint page_encryption_key, /*!< page encryption ulint page_encryption_key, /*!< in: page encryption
key to be used */ key to be used */
lsn_t lsn, /* lsn of the newest modification */ lsn_t lsn, /*!< in: lsn of the newest modification */
bool encrypt_later, /*!< in: should we encrypt ? */
const char* src_file,/*!< in: file name where func invoked */ const char* src_file,/*!< in: file name where func invoked */
ulint src_line);/*!< in: line where the func invoked */ ulint src_line);/*!< in: line where the func invoked */
/*******************************************************************//** /*******************************************************************//**
@ -1170,9 +1171,10 @@ os_aio_func(
level to be used */ level to be used */
ibool page_encryption, /*!< in: is page encryption used ibool page_encryption, /*!< in: is page encryption used
on this file space */ on this file space */
ulint page_encryption_key, /*!< page encryption key ulint page_encryption_key, /*!< in: page encryption key
to be used */ to be used */
lsn_t lsn); /* lsn of the newest modification */ lsn_t lsn, /*!< in: lsn of the newest modification */
bool encrypt_later); /*!< in: should we encrypt ? */
/************************************************************************//** /************************************************************************//**
Wakes up all async i/o threads so that they know to exit themselves in Wakes up all async i/o threads so that they know to exit themselves in
shutdown. */ shutdown. */

View file

@ -222,13 +222,15 @@ pfs_os_aio_func(
actual page size does not decrease. */ actual page size does not decrease. */
ibool page_compression, /*!< in: is page compression used ibool page_compression, /*!< in: is page compression used
on this file space */ on this file space */
ulint page_compression_level, /*!< page compression ulint page_compression_level, /*!< in: page compression
level to be used */ level to be used */
ibool page_encryption, /*!< in: is page encryption used ibool page_encryption, /*!< in: is page encryption used
on this file space */ on this file space */
ulint page_encryption_key, /*!< page encryption ulint page_encryption_key, /*!< in: page encryption
key to be used */ key to be used */
lsn_t lsn, /* lsn of the newest modification */ lsn_t lsn, /*!< in: lsn of the newest
modification */
bool encrypt_later, /*!< in: encrypt later ? */
const char* src_file,/*!< in: file name where func invoked */ const char* src_file,/*!< in: file name where func invoked */
ulint src_line)/*!< in: line where the func invoked */ ulint src_line)/*!< in: line where the func invoked */
{ {
@ -246,7 +248,7 @@ pfs_os_aio_func(
result = os_aio_func(type, mode, name, file, buf, offset, result = os_aio_func(type, mode, name, file, buf, offset,
n, message1, message2, write_size, n, message1, message2, write_size,
page_compression, page_compression_level, page_compression, page_compression_level,
page_encryption, page_encryption_key, lsn); page_encryption, page_encryption_key, lsn, encrypt_later);
register_pfs_file_io_end(locker, n); register_pfs_file_io_end(locker, n);

View file

@ -1276,7 +1276,7 @@ log_group_file_header_flush(
(ulint) (dest_offset / UNIV_PAGE_SIZE), (ulint) (dest_offset / UNIV_PAGE_SIZE),
(ulint) (dest_offset % UNIV_PAGE_SIZE), (ulint) (dest_offset % UNIV_PAGE_SIZE),
OS_FILE_LOG_BLOCK_SIZE, OS_FILE_LOG_BLOCK_SIZE,
buf, group, 0, 0); buf, group, 0, 0, false);
srv_stats.os_log_pending_writes.dec(); srv_stats.os_log_pending_writes.dec();
} }
@ -1443,7 +1443,7 @@ loop:
fil_io(OS_FILE_WRITE | OS_FILE_LOG, true, group->space_id, 0, fil_io(OS_FILE_WRITE | OS_FILE_LOG, true, group->space_id, 0,
(ulint) (next_offset / UNIV_PAGE_SIZE), (ulint) (next_offset / UNIV_PAGE_SIZE),
(ulint) (next_offset % UNIV_PAGE_SIZE), write_len, buf, (ulint) (next_offset % UNIV_PAGE_SIZE), write_len, buf,
group, 0, 0); group, 0, 0, false);
srv_stats.os_log_pending_writes.dec(); srv_stats.os_log_pending_writes.dec();
@ -2011,7 +2011,7 @@ log_group_checkpoint(
write_offset / UNIV_PAGE_SIZE, write_offset / UNIV_PAGE_SIZE,
write_offset % UNIV_PAGE_SIZE, write_offset % UNIV_PAGE_SIZE,
OS_FILE_LOG_BLOCK_SIZE, OS_FILE_LOG_BLOCK_SIZE,
buf, ((byte*) group + 1), 0, 0); buf, ((byte*) group + 1), 0, 0, false);
ut_ad(((ulint) group & 0x1UL) == 0); ut_ad(((ulint) group & 0x1UL) == 0);
} }
@ -2093,7 +2093,7 @@ log_group_read_checkpoint_info(
fil_io(OS_FILE_READ | OS_FILE_LOG, true, group->space_id, 0, fil_io(OS_FILE_READ | OS_FILE_LOG, true, group->space_id, 0,
field / UNIV_PAGE_SIZE, field % UNIV_PAGE_SIZE, field / UNIV_PAGE_SIZE, field % UNIV_PAGE_SIZE,
OS_FILE_LOG_BLOCK_SIZE, log_sys->checkpoint_buf, NULL, 0, 0); OS_FILE_LOG_BLOCK_SIZE, log_sys->checkpoint_buf, NULL, 0, 0, false);
} }
/******************************************************//** /******************************************************//**
@ -2417,7 +2417,7 @@ loop:
fil_io(OS_FILE_READ | OS_FILE_LOG, sync, group->space_id, 0, fil_io(OS_FILE_READ | OS_FILE_LOG, sync, group->space_id, 0,
(ulint) (source_offset / UNIV_PAGE_SIZE), (ulint) (source_offset / UNIV_PAGE_SIZE),
(ulint) (source_offset % UNIV_PAGE_SIZE), (ulint) (source_offset % UNIV_PAGE_SIZE),
len, buf, NULL, 0, 0); len, buf, NULL, 0, 0, false);
if (recv_sys->recv_log_crypt_ver != UNENCRYPTED_KEY_VER && if (recv_sys->recv_log_crypt_ver != UNENCRYPTED_KEY_VER &&
!log_group_decrypt_after_read(group, buf, len)) !log_group_decrypt_after_read(group, buf, len))

View file

@ -3101,7 +3101,7 @@ recv_recovery_from_checkpoint_start_func(
fil_io(OS_FILE_READ | OS_FILE_LOG, true, max_cp_group->space_id, 0, fil_io(OS_FILE_READ | OS_FILE_LOG, true, max_cp_group->space_id, 0,
0, 0, LOG_FILE_HDR_SIZE, 0, 0, LOG_FILE_HDR_SIZE,
log_hdr_buf, max_cp_group, 0, 0); log_hdr_buf, max_cp_group, 0, 0, false);
if (0 == ut_memcmp(log_hdr_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP, if (0 == ut_memcmp(log_hdr_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP,
(byte*)"ibbackup", (sizeof "ibbackup") - 1)) { (byte*)"ibbackup", (sizeof "ibbackup") - 1)) {
@ -3132,7 +3132,7 @@ recv_recovery_from_checkpoint_start_func(
fil_io(OS_FILE_WRITE | OS_FILE_LOG, true, fil_io(OS_FILE_WRITE | OS_FILE_LOG, true,
max_cp_group->space_id, 0, max_cp_group->space_id, 0,
0, 0, OS_FILE_LOG_BLOCK_SIZE, 0, 0, OS_FILE_LOG_BLOCK_SIZE,
log_hdr_buf, max_cp_group, 0, 0); log_hdr_buf, max_cp_group, 0, 0, false);
} }
#ifdef UNIV_LOG_ARCHIVE #ifdef UNIV_LOG_ARCHIVE

View file

@ -260,6 +260,9 @@ struct os_aio_slot_t{
ulint file_block_size;/*!< file block size */ ulint file_block_size;/*!< file block size */
bool encrypt_later; /*!< should the page be encrypted
before write */
#ifdef WIN_ASYNC_IO #ifdef WIN_ASYNC_IO
HANDLE handle; /*!< handle object we need in the HANDLE handle; /*!< handle object we need in the
OVERLAPPED struct */ OVERLAPPED struct */
@ -4546,9 +4549,11 @@ os_aio_array_reserve_slot(
level to be used */ level to be used */
ibool page_encryption, /*!< in: is page encryption used ibool page_encryption, /*!< in: is page encryption used
on this file space */ on this file space */
ulint page_encryption_key, /*!< page encryption key ulint page_encryption_key, /*!< in: page encryption key
to be used */ to be used */
lsn_t lsn) /* lsn of the newest modification */ lsn_t lsn, /*!< in: lsn of the newest modification */
bool encrypt_later) /*!< in: should we encrypt before
writing the page */
{ {
os_aio_slot_t* slot = NULL; os_aio_slot_t* slot = NULL;
#ifdef WIN_ASYNC_IO #ifdef WIN_ASYNC_IO
@ -4635,7 +4640,6 @@ found:
slot->name = name; slot->name = name;
slot->len = len; slot->len = len;
slot->type = type; slot->type = type;
slot->buf = static_cast<byte*>(buf);
slot->offset = offset; slot->offset = offset;
slot->lsn = lsn; slot->lsn = lsn;
slot->io_already_done = FALSE; slot->io_already_done = FALSE;
@ -4646,6 +4650,7 @@ found:
slot->page_compression = page_compression; slot->page_compression = page_compression;
slot->page_encryption_key = page_encryption_key; slot->page_encryption_key = page_encryption_key;
slot->page_encryption = page_encryption; slot->page_encryption = page_encryption;
slot->encrypt_later = encrypt_later;
if (message1) { if (message1) {
slot->file_block_size = fil_node_get_block_size(message1); slot->file_block_size = fil_node_get_block_size(message1);
@ -4700,7 +4705,8 @@ found:
/* If the space is page encryption and this is write operation /* If the space is page encryption and this is write operation
then we encrypt the page */ then we encrypt the page */
if (message1 && type == OS_FILE_WRITE && page_encryption ) { if (message1 && type == OS_FILE_WRITE && (page_encryption == 1 || encrypt_later)) {
ut_a(page_encryption == 1 || srv_encrypt_tables == 1);
/* Release the array mutex while encrypting */ /* Release the array mutex while encrypting */
os_mutex_exit(array->mutex); os_mutex_exit(array->mutex);
@ -4724,6 +4730,8 @@ found:
os_mutex_enter(array->mutex); os_mutex_enter(array->mutex);
} }
slot->buf = static_cast<byte*>(buf);
#ifdef WIN_ASYNC_IO #ifdef WIN_ASYNC_IO
control = &slot->control; control = &slot->control;
control->Offset = (DWORD) offset & 0xFFFFFFFF; control->Offset = (DWORD) offset & 0xFFFFFFFF;
@ -5012,9 +5020,11 @@ os_aio_func(
level to be used */ level to be used */
ibool page_encryption, /*!< in: is page encryption used ibool page_encryption, /*!< in: is page encryption used
on this file space */ on this file space */
ulint page_encryption_key, /*!< page encryption key ulint page_encryption_key, /*!< in: page encryption key
to be used */ to be used */
lsn_t lsn) /* lsn of the newest modification */ lsn_t lsn, /*!< in: lsn of the newest modification */
bool encrypt_later) /*!< in: should we encrypt page
before write */
{ {
os_aio_array_t* array; os_aio_array_t* array;
os_aio_slot_t* slot; os_aio_slot_t* slot;
@ -5131,7 +5141,7 @@ try_again:
slot = os_aio_array_reserve_slot(type, array, message1, message2, file, slot = os_aio_array_reserve_slot(type, array, message1, message2, file,
name, buf, offset, n, write_size, name, buf, offset, n, write_size,
page_compression, page_compression_level, page_compression, page_compression_level,
page_encryption, page_encryption_key, lsn); page_encryption, page_encryption_key, lsn, encrypt_later);
if (type == OS_FILE_READ) { if (type == OS_FILE_READ) {
if (srv_use_native_aio) { if (srv_use_native_aio) {
@ -5169,6 +5179,7 @@ try_again:
buffer = buf; buffer = buf;
} }
} }
ret = WriteFile(file, buffer, (DWORD) n, &len, ret = WriteFile(file, buffer, (DWORD) n, &len,
&(slot->control)); &(slot->control));

View file

@ -1084,6 +1084,7 @@ buf_block_init(
block->page.comp_buf = NULL; block->page.comp_buf = NULL;
block->page.comp_buf_free = NULL; block->page.comp_buf_free = NULL;
block->page.key_version = 0; block->page.key_version = 0;
block->page.encrypt_later = false;
block->modify_clock = 0; block->modify_clock = 0;
@ -3587,6 +3588,7 @@ buf_page_init_low(
bpage->comp_buf = NULL; bpage->comp_buf = NULL;
bpage->comp_buf_free = NULL; bpage->comp_buf_free = NULL;
bpage->key_version = 0; bpage->key_version = 0;
bpage->encrypt_later = false;
HASH_INVALIDATE(bpage, hash); HASH_INVALIDATE(bpage, hash);
bpage->is_corrupt = FALSE; bpage->is_corrupt = FALSE;
@ -5793,6 +5795,8 @@ buf_page_encrypt_before_write(
buf_page_t* bpage, /*!< in/out: buffer page to be flushed */ buf_page_t* bpage, /*!< in/out: buffer page to be flushed */
const byte* src_frame) /*!< in: src frame */ const byte* src_frame) /*!< in: src frame */
{ {
bpage->encrypt_later = false;
if (srv_encrypt_tables == FALSE) { if (srv_encrypt_tables == FALSE) {
/* Encryption is disabled */ /* Encryption is disabled */
return const_cast<byte*>(src_frame); return const_cast<byte*>(src_frame);
@ -5853,7 +5857,8 @@ buf_page_encrypt_before_write(
ut_ad(key_version == 0 || key_version >= bpage->key_version); ut_ad(key_version == 0 || key_version >= bpage->key_version);
bpage->key_version = key_version; bpage->key_version = key_version;
} else { } else {
// We do compression and encryption later on os0file.cc /** Compression and encryption is done later at os0file.cc */
bpage->encrypt_later = true;
dst_frame = (byte *)src_frame; dst_frame = (byte *)src_frame;
} }

View file

@ -521,10 +521,18 @@ buf_dblwr_process()
ulint zip_size = fil_space_get_zip_size(space_id); ulint zip_size = fil_space_get_zip_size(space_id);
/* Read in the actual page from the file */ /* Read in the actual page from the file */
fil_io(OS_FILE_READ, true, space_id, zip_size, fil_io(OS_FILE_READ,
page_no, 0, true,
zip_size ? zip_size : UNIV_PAGE_SIZE, space_id,
read_buf, NULL, 0, 0); zip_size,
page_no,
0,
zip_size ? zip_size : UNIV_PAGE_SIZE,
read_buf,
NULL,
0,
0,
false);
if (fil_space_verify_crypt_checksum(read_buf, zip_size)) { if (fil_space_verify_crypt_checksum(read_buf, zip_size)) {
/* page is encrypted and checksum is OK */ /* page is encrypted and checksum is OK */
@ -576,10 +584,18 @@ buf_dblwr_process()
doublewrite buffer to the intended doublewrite buffer to the intended
position */ position */
fil_io(OS_FILE_WRITE, true, space_id, fil_io(OS_FILE_WRITE,
zip_size, page_no, 0, true,
zip_size ? zip_size : UNIV_PAGE_SIZE, space_id,
page, NULL, 0, 0); zip_size,
page_no,
0,
zip_size ? zip_size : UNIV_PAGE_SIZE,
page,
NULL,
0,
0,
false);
ib_logf(IB_LOG_LEVEL_INFO, ib_logf(IB_LOG_LEVEL_INFO,
"Recovered the page from" "Recovered the page from"
@ -595,11 +611,17 @@ buf_dblwr_process()
zeroes, while a valid copy is zeroes, while a valid copy is
available in dblwr buffer. */ available in dblwr buffer. */
fil_io(OS_FILE_WRITE, true, space_id, fil_io(OS_FILE_WRITE,
zip_size, page_no, 0, true,
zip_size ? zip_size space_id,
: UNIV_PAGE_SIZE, zip_size,
page, NULL, 0, 0); page_no, 0,
zip_size ? zip_size : UNIV_PAGE_SIZE,
page,
NULL,
0,
0,
false);
} }
} }
} }
@ -621,9 +643,9 @@ buf_dblwr_process()
memset(buf, 0, bytes); memset(buf, 0, bytes);
fil_io(OS_FILE_WRITE, true, TRX_SYS_SPACE, 0, fil_io(OS_FILE_WRITE, true, TRX_SYS_SPACE, 0,
buf_dblwr->block1, 0, bytes, buf, NULL, NULL, 0); buf_dblwr->block1, 0, bytes, buf, NULL, NULL, 0, false);
fil_io(OS_FILE_WRITE, true, TRX_SYS_SPACE, 0, fil_io(OS_FILE_WRITE, true, TRX_SYS_SPACE, 0,
buf_dblwr->block2, 0, bytes, buf, NULL, NULL, 0); buf_dblwr->block2, 0, bytes, buf, NULL, NULL, 0, false);
ut_free(unaligned_buf); ut_free(unaligned_buf);
} }
@ -828,13 +850,18 @@ buf_dblwr_write_block_to_datafile(
void * frame = buf_page_get_frame(bpage); void * frame = buf_page_get_frame(bpage);
if (bpage->zip.data) { if (bpage->zip.data) {
fil_io(flags, sync, buf_page_get_space(bpage), fil_io(flags,
buf_page_get_zip_size(bpage), sync,
buf_page_get_page_no(bpage), 0, buf_page_get_space(bpage),
buf_page_get_zip_size(bpage), buf_page_get_zip_size(bpage),
frame, buf_page_get_page_no(bpage),
(void*) bpage, 0, 0,
bpage->newest_modification); buf_page_get_zip_size(bpage),
frame,
(void*) bpage,
0,
bpage->newest_modification,
bpage->encrypt_later);
return; return;
} }
@ -844,10 +871,18 @@ buf_dblwr_write_block_to_datafile(
ut_a(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE); ut_a(buf_block_get_state(block) == BUF_BLOCK_FILE_PAGE);
buf_dblwr_check_page_lsn(block->frame); buf_dblwr_check_page_lsn(block->frame);
fil_io(flags, sync, buf_block_get_space(block), 0, fil_io(flags,
buf_block_get_page_no(block), 0, UNIV_PAGE_SIZE, sync,
frame, (void*) block, buf_block_get_space(block),
(ulint *)&bpage->write_size, bpage->newest_modification); 0,
buf_block_get_page_no(block),
0,
UNIV_PAGE_SIZE,
frame,
(void*) block,
(ulint *)&bpage->write_size,
bpage->newest_modification,
bpage->encrypt_later);
} }
/********************************************************************//** /********************************************************************//**
@ -939,9 +974,19 @@ try_again:
len = ut_min(TRX_SYS_DOUBLEWRITE_BLOCK_SIZE, len = ut_min(TRX_SYS_DOUBLEWRITE_BLOCK_SIZE,
buf_dblwr->first_free) * UNIV_PAGE_SIZE; buf_dblwr->first_free) * UNIV_PAGE_SIZE;
fil_io(OS_FILE_WRITE, true, TRX_SYS_SPACE, 0, fil_io(OS_FILE_WRITE,
buf_dblwr->block1, 0, len, true,
(void*) write_buf, NULL, 0, 0); TRX_SYS_SPACE,
0,
buf_dblwr->block1,
0,
len,
(void*)
write_buf,
NULL,
0,
0,
false);
if (buf_dblwr->first_free <= TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) { if (buf_dblwr->first_free <= TRX_SYS_DOUBLEWRITE_BLOCK_SIZE) {
/* No unwritten pages in the second block. */ /* No unwritten pages in the second block. */
@ -955,9 +1000,18 @@ try_again:
write_buf = buf_dblwr->write_buf write_buf = buf_dblwr->write_buf
+ TRX_SYS_DOUBLEWRITE_BLOCK_SIZE * UNIV_PAGE_SIZE; + TRX_SYS_DOUBLEWRITE_BLOCK_SIZE * UNIV_PAGE_SIZE;
fil_io(OS_FILE_WRITE, true, TRX_SYS_SPACE, 0, fil_io(OS_FILE_WRITE,
buf_dblwr->block2, 0, len, true,
(void*) write_buf, NULL, 0, 0); TRX_SYS_SPACE,
0,
buf_dblwr->block2,
0,
len,
(void*) write_buf,
NULL,
0,
0,
false);
flush: flush:
/* increment the doublewrite flushed pages counter */ /* increment the doublewrite flushed pages counter */
@ -1187,17 +1241,32 @@ retry:
memset(buf_dblwr->write_buf + UNIV_PAGE_SIZE * i memset(buf_dblwr->write_buf + UNIV_PAGE_SIZE * i
+ zip_size, 0, UNIV_PAGE_SIZE - zip_size); + zip_size, 0, UNIV_PAGE_SIZE - zip_size);
fil_io(OS_FILE_WRITE, true, TRX_SYS_SPACE, 0, fil_io(OS_FILE_WRITE,
offset, 0, UNIV_PAGE_SIZE, true,
(void*) (buf_dblwr->write_buf TRX_SYS_SPACE,
+ UNIV_PAGE_SIZE * i), NULL, 0,bpage->newest_modification); 0,
offset,
0,
UNIV_PAGE_SIZE,
(void*) (buf_dblwr->write_buf + UNIV_PAGE_SIZE * i),
NULL,
0,
bpage->newest_modification,
bpage->encrypt_later);
} else { } else {
/* It is a regular page. Write it directly to the /* It is a regular page. Write it directly to the
doublewrite buffer */ doublewrite buffer */
fil_io(OS_FILE_WRITE, true, TRX_SYS_SPACE, 0, fil_io(OS_FILE_WRITE,
offset, 0, UNIV_PAGE_SIZE, true,
frame, TRX_SYS_SPACE,
NULL, 0, bpage->newest_modification); 0,
offset,
0, UNIV_PAGE_SIZE,
frame,
NULL,
0,
bpage->newest_modification,
bpage->encrypt_later);
} }
/* Now flush the doublewrite buffer data to disk */ /* Now flush the doublewrite buffer data to disk */

View file

@ -955,16 +955,17 @@ buf_flush_write_block_low(
if (!srv_use_doublewrite_buf || !buf_dblwr) { if (!srv_use_doublewrite_buf || !buf_dblwr) {
fil_io(OS_FILE_WRITE | OS_AIO_SIMULATED_WAKE_LATER, fil_io(OS_FILE_WRITE | OS_AIO_SIMULATED_WAKE_LATER,
sync, sync,
buf_page_get_space(bpage), buf_page_get_space(bpage),
zip_size, zip_size,
buf_page_get_page_no(bpage), buf_page_get_page_no(bpage),
0, 0,
zip_size ? zip_size : UNIV_PAGE_SIZE, zip_size ? zip_size : UNIV_PAGE_SIZE,
frame, frame,
bpage, bpage,
&bpage->write_size, &bpage->write_size,
bpage->newest_modification); bpage->newest_modification,
bpage->encrypt_later);
} else { } else {
/* InnoDB uses doublewrite buffer and doublewrite buffer /* InnoDB uses doublewrite buffer and doublewrite buffer
is initialized. User can define do we use atomic writes is initialized. User can define do we use atomic writes
@ -975,16 +976,17 @@ buf_flush_write_block_low(
if (awrites == ATOMIC_WRITES_ON) { if (awrites == ATOMIC_WRITES_ON) {
fil_io(OS_FILE_WRITE | OS_AIO_SIMULATED_WAKE_LATER, fil_io(OS_FILE_WRITE | OS_AIO_SIMULATED_WAKE_LATER,
FALSE, FALSE,
buf_page_get_space(bpage), buf_page_get_space(bpage),
zip_size, zip_size,
buf_page_get_page_no(bpage), buf_page_get_page_no(bpage),
0, 0,
zip_size ? zip_size : UNIV_PAGE_SIZE, zip_size ? zip_size : UNIV_PAGE_SIZE,
frame, frame,
bpage, bpage,
&bpage->write_size, &bpage->write_size,
bpage->newest_modification); bpage->newest_modification,
bpage->encrypt_later);
} else if (flush_type == BUF_FLUSH_SINGLE_PAGE) { } else if (flush_type == BUF_FLUSH_SINGLE_PAGE) {
buf_dblwr_write_single_page(bpage, sync); buf_dblwr_write_single_page(bpage, sync);
} else { } else {

View file

@ -232,14 +232,14 @@ not_to_recover:
*err = _fil_io(OS_FILE_READ | wake_later *err = _fil_io(OS_FILE_READ | wake_later
| ignore_nonexistent_pages, | ignore_nonexistent_pages,
sync, space, zip_size, offset, 0, zip_size, sync, space, zip_size, offset, 0, zip_size,
frame, bpage, 0, trx, 0); frame, bpage, 0, trx, 0, false);
} else { } else {
ut_a(buf_page_get_state(bpage) == BUF_BLOCK_FILE_PAGE); ut_a(buf_page_get_state(bpage) == BUF_BLOCK_FILE_PAGE);
*err = _fil_io(OS_FILE_READ | wake_later *err = _fil_io(OS_FILE_READ | wake_later
| ignore_nonexistent_pages, | ignore_nonexistent_pages,
sync, space, 0, offset, 0, UNIV_PAGE_SIZE, sync, space, 0, offset, 0, UNIV_PAGE_SIZE,
frame, bpage, &bpage->write_size, trx, 0); frame, bpage, &bpage->write_size, trx, 0, false);
} }
if (sync) { if (sync) {

View file

@ -303,9 +303,8 @@ fil_crypt_get_latest_key(byte *dst, uint* key_length,
} }
return fil_crypt_get_key(dst, key_length, crypt_data, *version, false); return fil_crypt_get_key(dst, key_length, crypt_data, *version, false);
} else {
return fil_crypt_get_key(dst, key_length, NULL, *version, true);
} }
return fil_crypt_get_key(dst, key_length, NULL, *version, true);
} }
/****************************************************************** /******************************************************************
@ -622,13 +621,25 @@ fil_space_encrypt(ulint space, ulint offset, lsn_t lsn,
byte key[MY_AES_MAX_KEY_LENGTH]; byte key[MY_AES_MAX_KEY_LENGTH];
uint key_length; uint key_length;
ulint orig_page_type = mach_read_from_2(src_frame+FIL_PAGE_TYPE);
if (orig_page_type==FIL_PAGE_TYPE_FSP_HDR
|| orig_page_type==FIL_PAGE_TYPE_XDES
|| orig_page_type== FIL_PAGE_PAGE_ENCRYPTED
|| orig_page_type== FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED) {
//TODO: is this really needed ?
memcpy(dst_frame, src_frame, page_size);
return;
}
if (srv_encrypt_tables) { if (srv_encrypt_tables) {
crypt_data = fil_space_get_crypt_data(space); crypt_data = fil_space_get_crypt_data(space);
if (crypt_data == NULL) { if (crypt_data == NULL) {
//TODO: Is this really needed ? //TODO: Is this really needed ?
memcpy(dst_frame, src_frame, page_size); memcpy(dst_frame, src_frame, page_size);
return; return;
} }
fil_crypt_get_latest_key(key, &key_length, crypt_data, &key_version); fil_crypt_get_latest_key(key, &key_length, crypt_data, &key_version);
} else { } else {
key_version = encryption_key; key_version = encryption_key;
@ -647,9 +658,7 @@ fil_space_encrypt(ulint space, ulint offset, lsn_t lsn,
src_frame + FIL_PAGE_OFFSET); src_frame + FIL_PAGE_OFFSET);
mach_write_to_4(iv + 4, space_offset); mach_write_to_4(iv + 4, space_offset);
mach_write_to_8(iv + 8, lsn); mach_write_to_8(iv + 8, lsn);
} } else {
else
{
// take the iv from the key provider // take the iv from the key provider
int load_iv_rc = get_encryption_iv(key_version, (uchar *) iv, sizeof(iv)); int load_iv_rc = get_encryption_iv(key_version, (uchar *) iv, sizeof(iv));
@ -667,19 +676,9 @@ fil_space_encrypt(ulint space, ulint offset, lsn_t lsn,
} }
} }
ibool page_compressed = (mach_read_from_2(src_frame+FIL_PAGE_TYPE) == FIL_PAGE_PAGE_COMPRESSED); ibool page_compressed = (mach_read_from_2(src_frame+FIL_PAGE_TYPE) == FIL_PAGE_PAGE_COMPRESSED);
ibool page_encrypted = fil_space_is_page_encrypted(space); ibool page_encrypted = fil_space_is_page_encrypted(space);
ulint compression_alg = mach_read_from_8(src_frame+FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION); ulint compression_alg = mach_read_from_8(src_frame+FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION);
ulint orig_page_type = mach_read_from_2(src_frame+FIL_PAGE_TYPE);
if (orig_page_type==FIL_PAGE_TYPE_FSP_HDR
|| orig_page_type==FIL_PAGE_TYPE_XDES
|| orig_page_type== FIL_PAGE_PAGE_ENCRYPTED
|| orig_page_type== FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED) {
memcpy(dst_frame, src_frame, page_size);
return;
}
// copy page header // copy page header
memcpy(dst_frame, src_frame, FIL_PAGE_DATA); memcpy(dst_frame, src_frame, FIL_PAGE_DATA);
@ -708,7 +707,7 @@ fil_space_encrypt(ulint space, ulint offset, lsn_t lsn,
uint32 dstlen; uint32 dstlen;
if (page_compressed) { if (page_compressed) {
srclen = page_size - FIL_PAGE_DATA; srclen = page_size - FIL_PAGE_DATA;;
} }
int rc = (* my_aes_encrypt_dynamic)(src, srclen, int rc = (* my_aes_encrypt_dynamic)(src, srclen,
@ -789,6 +788,7 @@ fil_space_check_encryption_read(
ulint space) /*!< in: tablespace id */ ulint space) /*!< in: tablespace id */
{ {
fil_space_crypt_t* crypt_data = fil_space_get_crypt_data(space); fil_space_crypt_t* crypt_data = fil_space_get_crypt_data(space);
if (crypt_data == NULL) if (crypt_data == NULL)
return false; return false;
@ -815,6 +815,7 @@ fil_space_decrypt(fil_space_crypt_t* crypt_data,
|| page_type == FIL_PAGE_PAGE_COMPRESSED); || page_type == FIL_PAGE_PAGE_COMPRESSED);
ulint orig_page_type=0; ulint orig_page_type=0;
if (page_type == FIL_PAGE_PAGE_ENCRYPTED) { if (page_type == FIL_PAGE_PAGE_ENCRYPTED) {
key_version = mach_read_from_2( key_version = mach_read_from_2(
src_frame + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION); src_frame + FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION);
@ -846,7 +847,6 @@ fil_space_decrypt(fil_space_crypt_t* crypt_data,
mach_write_to_2(dst_frame+FIL_PAGE_TYPE, orig_page_type); mach_write_to_2(dst_frame+FIL_PAGE_TYPE, orig_page_type);
} }
// get key // get key
byte key[MY_AES_MAX_KEY_LENGTH]; byte key[MY_AES_MAX_KEY_LENGTH];
uint key_length; uint key_length;
@ -862,9 +862,7 @@ fil_space_decrypt(fil_space_crypt_t* crypt_data,
mach_write_to_4(iv + 0, space); mach_write_to_4(iv + 0, space);
mach_write_to_4(iv + 4, offset); mach_write_to_4(iv + 4, offset);
mach_write_to_8(iv + 8, lsn); mach_write_to_8(iv + 8, lsn);
} } else {
else
{
// take the iv from the key provider // take the iv from the key provider
int load_iv_rc = get_encryption_iv(key_version, (uchar *) iv, sizeof(iv)); int load_iv_rc = get_encryption_iv(key_version, (uchar *) iv, sizeof(iv));
@ -886,7 +884,6 @@ fil_space_decrypt(fil_space_crypt_t* crypt_data,
byte* dst = dst_frame + FIL_PAGE_DATA; byte* dst = dst_frame + FIL_PAGE_DATA;
uint32 dstlen; uint32 dstlen;
ulint srclen = page_size - (FIL_PAGE_DATA + FIL_PAGE_DATA_END); ulint srclen = page_size - (FIL_PAGE_DATA + FIL_PAGE_DATA_END);
ulint compressed_len; ulint compressed_len;
ulint compression_method; ulint compression_method;

View file

@ -287,7 +287,7 @@ fil_read(
actual page size does not decrease. */ actual page size does not decrease. */
{ {
return(fil_io(OS_FILE_READ, sync, space_id, zip_size, block_offset, return(fil_io(OS_FILE_READ, sync, space_id, zip_size, block_offset,
byte_offset, len, buf, message, write_size, 0)); byte_offset, len, buf, message, write_size, 0, false));
} }
/********************************************************************//** /********************************************************************//**
@ -319,12 +319,13 @@ fil_write(
operation for this page and if operation for this page and if
initialized we do not trim again if initialized we do not trim again if
actual page size does not decrease. */ actual page size does not decrease. */
lsn_t lsn) /* lsn of the newest modification */ lsn_t lsn, /*!< in: lsn of the newest modification */
bool encrypt_later) /*!< in: encrypt later ? */
{ {
ut_ad(!srv_read_only_mode); ut_ad(!srv_read_only_mode);
return(fil_io(OS_FILE_WRITE, sync, space_id, zip_size, block_offset, return(fil_io(OS_FILE_WRITE, sync, space_id, zip_size, block_offset,
byte_offset, len, buf, message, write_size, lsn)); byte_offset, len, buf, message, write_size, lsn, encrypt_later));
} }
/*******************************************************************//** /*******************************************************************//**
@ -617,6 +618,8 @@ fil_node_open_file(
ut_a(size_bytes != (os_offset_t) -1); ut_a(size_bytes != (os_offset_t) -1);
node->file_block_size = os_file_get_block_size(node->handle, node->name); node->file_block_size = os_file_get_block_size(node->handle, node->name);
space->file_block_size = node->file_block_size;
#ifdef UNIV_HOTBACKUP #ifdef UNIV_HOTBACKUP
if (space->id == 0) { if (space->id == 0) {
node->size = (ulint) (size_bytes / UNIV_PAGE_SIZE); node->size = (ulint) (size_bytes / UNIV_PAGE_SIZE);
@ -782,6 +785,7 @@ add_size:
if (node->file_block_size == 0) { if (node->file_block_size == 0) {
node->file_block_size = os_file_get_block_size(node->handle, node->name); node->file_block_size = os_file_get_block_size(node->handle, node->name);
space->file_block_size = node->file_block_size;
} }
ut_a(ret); ut_a(ret);
@ -1874,7 +1878,7 @@ fil_write_lsn_and_arch_no_to_file(
lsn); lsn);
err = fil_write(TRUE, space, 0, sum_of_sizes, 0, err = fil_write(TRUE, space, 0, sum_of_sizes, 0,
UNIV_PAGE_SIZE, buf, NULL, 0, 0); UNIV_PAGE_SIZE, buf, NULL, 0, 0, false);
} }
mem_free(buf1); mem_free(buf1);
@ -5189,6 +5193,7 @@ retry:
/* Determine correct file block size */ /* Determine correct file block size */
if (node->file_block_size == 0) { if (node->file_block_size == 0) {
node->file_block_size = os_file_get_block_size(node->handle, node->name); node->file_block_size = os_file_get_block_size(node->handle, node->name);
space->file_block_size = node->file_block_size;
} }
#ifdef HAVE_POSIX_FALLOCATE #ifdef HAVE_POSIX_FALLOCATE
@ -5248,7 +5253,7 @@ retry:
success = os_aio(OS_FILE_WRITE, OS_AIO_SYNC, success = os_aio(OS_FILE_WRITE, OS_AIO_SYNC,
node->name, node->handle, buf, node->name, node->handle, buf,
offset, page_size * n_pages, offset, page_size * n_pages,
node, NULL, space_id, NULL, 0, 0, 0, 0, 0, 0); node, NULL, space_id, NULL, 0, 0, 0, 0, 0, 0, false);
#endif /* UNIV_HOTBACKUP */ #endif /* UNIV_HOTBACKUP */
if (success) { if (success) {
os_has_said_disk_full = FALSE; os_has_said_disk_full = FALSE;
@ -5630,8 +5635,8 @@ _fil_io(
initialized we do not trim again if initialized we do not trim again if
actual page size does not decrease. */ actual page size does not decrease. */
trx_t* trx, trx_t* trx,
lsn_t lsn) /* lsn of the newest modification */ lsn_t lsn, /*!< in: lsn of the newest modification */
bool encrypt_later) /*!< in: encrypt later ? */
{ {
ulint mode; ulint mode;
fil_space_t* space; fil_space_t* space;
@ -5880,7 +5885,8 @@ _fil_io(
write_size, write_size,
page_encrypted, page_encrypted,
page_encryption_key, page_encryption_key,
lsn); lsn,
encrypt_later);
#else #else
/* In mysqlbackup do normal i/o, not aio */ /* In mysqlbackup do normal i/o, not aio */

View file

@ -283,7 +283,8 @@ fil_compress_page(
/* Let's not compress file space header or /* Let's not compress file space header or
extent descriptor */ extent descriptor */
if (orig_page_type == FIL_PAGE_TYPE_FSP_HDR || if (orig_page_type == 0 ||
orig_page_type == FIL_PAGE_TYPE_FSP_HDR ||
orig_page_type == FIL_PAGE_TYPE_XDES || orig_page_type == FIL_PAGE_TYPE_XDES ||
orig_page_type == FIL_PAGE_PAGE_COMPRESSED || orig_page_type == FIL_PAGE_PAGE_COMPRESSED ||
orig_page_type == FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED) { orig_page_type == FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED) {

View file

@ -1598,6 +1598,8 @@ struct buf_page_t{
can be read while it's being flushed */ can be read while it's being flushed */
byte* comp_buf_free; /*!< for compression, allocated byte* comp_buf_free; /*!< for compression, allocated
buffer that is then alligned */ buffer that is then alligned */
bool encrypt_later; /*!< should we encrypt the page
at os0file.cc ? */
#ifndef UNIV_HOTBACKUP #ifndef UNIV_HOTBACKUP
buf_page_t* hash; /*!< node used in chaining to buf_page_t* hash; /*!< node used in chaining to
buf_pool->page_hash or buf_pool->page_hash or

View file

@ -1,7 +1,7 @@
/***************************************************************************** /*****************************************************************************
Copyright (c) 1995, 2014, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 1995, 2014, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2013, 2014, SkySQL Ab. All Rights Reserved. Copyright (c) 2013, 2015, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software the terms of the GNU General Public License as published by the Free Software
@ -340,6 +340,7 @@ struct fil_space_t {
UT_LIST_NODE_T(fil_space_t) space_list; UT_LIST_NODE_T(fil_space_t) space_list;
/*!< list of all spaces */ /*!< list of all spaces */
fil_space_crypt_t* crypt_data; fil_space_crypt_t* crypt_data;
ulint file_block_size;/*!< file system block size */
ulint magic_n;/*!< FIL_SPACE_MAGIC_N */ ulint magic_n;/*!< FIL_SPACE_MAGIC_N */
}; };
@ -959,8 +960,8 @@ fil_space_get_n_reserved_extents(
Reads or writes data. This operation is asynchronous (aio). Reads or writes data. This operation is asynchronous (aio).
@return DB_SUCCESS, or DB_TABLESPACE_DELETED if we are trying to do @return DB_SUCCESS, or DB_TABLESPACE_DELETED if we are trying to do
i/o on a tablespace which does not exist */ i/o on a tablespace which does not exist */
#define fil_io(type, sync, space_id, zip_size, block_offset, byte_offset, len, buf, message, write_size, lsn) \ #define fil_io(type, sync, space_id, zip_size, block_offset, byte_offset, len, buf, message, write_size, lsn, encrypt) \
_fil_io(type, sync, space_id, zip_size, block_offset, byte_offset, len, buf, message, write_size, NULL, lsn) _fil_io(type, sync, space_id, zip_size, block_offset, byte_offset, len, buf, message, write_size, NULL, lsn, encrypt)
UNIV_INTERN UNIV_INTERN
dberr_t dberr_t
@ -997,7 +998,8 @@ _fil_io(
initialized we do not trim again if initialized we do not trim again if
actual page size does not decrease. */ actual page size does not decrease. */
trx_t* trx, trx_t* trx,
lsn_t lsn) /* lsn of the newest modification */ lsn_t lsn, /*!< in: lsn of the newest modification */
bool encrypt_later) /*!< in: encrypt later ? */
__attribute__((nonnull(8))); __attribute__((nonnull(8)));
/**********************************************************************//** /**********************************************************************//**

View file

@ -2,7 +2,7 @@
Copyright (c) 1995, 2013, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 1995, 2013, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2009, Percona Inc. Copyright (c) 2009, Percona Inc.
Copyright (c) 2013, SkySQL Ab. All Rights Reserved. Copyright (c) 2013, 2015, MariaDB Corporation.
Portions of this file contain modifications contributed and copyrighted Portions of this file contain modifications contributed and copyrighted
by Percona Inc.. Those modifications are by Percona Inc.. Those modifications are
@ -324,11 +324,11 @@ The wrapper functions have the prefix of "innodb_". */
# define os_aio(type, mode, name, file, buf, offset, \ # define os_aio(type, mode, name, file, buf, offset, \
n, message1, message2, space_id, \ n, message1, message2, space_id, \
trx, page_compressed, page_compression_level, write_size, \ trx, page_compressed, page_compression_level, write_size, \
page_encryption, page_encryption_key, lsn) \ page_encryption, page_encryption_key, lsn, encrypt) \
pfs_os_aio_func(type, mode, name, file, buf, offset, \ pfs_os_aio_func(type, mode, name, file, buf, offset, \
n, message1, message2, space_id, trx, \ n, message1, message2, space_id, trx, \
page_compressed, page_compression_level, write_size, \ page_compressed, page_compression_level, write_size, \
page_encryption, page_encryption_key, lsn, \ page_encryption, page_encryption_key, lsn, encrypt, \
__FILE__, __LINE__) __FILE__, __LINE__)
# define os_file_read(file, buf, offset, n, compressed) \ # define os_file_read(file, buf, offset, n, compressed) \
@ -378,11 +378,11 @@ to original un-instrumented file I/O APIs */
# define os_aio(type, mode, name, file, buf, offset, n, message1, \ # define os_aio(type, mode, name, file, buf, offset, n, message1, \
message2, space_id, trx, \ message2, space_id, trx, \
page_compressed, page_compression_level, write_size, \ page_compressed, page_compression_level, write_size, \
page_encryption, page_encryption_key, lsn) \ page_encryption, page_encryption_key, lsn, encrypt) \
os_aio_func(type, mode, name, file, buf, offset, n, \ os_aio_func(type, mode, name, file, buf, offset, n, \
message1, message2, space_id, trx, \ message1, message2, space_id, trx, \
page_compressed, page_compression_level, write_size, \ page_compressed, page_compression_level, write_size, \
page_encryption, page_encryption_key, lsn) page_encryption, page_encryption_key, lsn, encrypt)
# define os_file_read(file, buf, offset, n, compressed) \ # define os_file_read(file, buf, offset, n, compressed) \
os_file_read_func(file, buf, offset, n, NULL, compressed) os_file_read_func(file, buf, offset, n, NULL, compressed)
@ -812,9 +812,10 @@ pfs_os_aio_func(
actual page size does not decrease. */ actual page size does not decrease. */
ibool page_encryption, /*!< in: is page encryption used ibool page_encryption, /*!< in: is page encryption used
on this file space */ on this file space */
ulint page_encryption_key, /*!< page encryption ulint page_encryption_key, /*!< in: page encryption
key to be used */ key to be used */
lsn_t lsn, /* lsn of the newest modification */ lsn_t lsn, /*!< in: lsn of the newest modification */
bool encrypt_later, /*!< in: should we encrypt ? */
const char* src_file,/*!< in: file name where func invoked */ const char* src_file,/*!< in: file name where func invoked */
ulint src_line);/*!< in: line where the func invoked */ ulint src_line);/*!< in: line where the func invoked */
/*******************************************************************//** /*******************************************************************//**
@ -1204,10 +1205,10 @@ os_aio_func(
actual page size does not decrease. */ actual page size does not decrease. */
ibool page_encryption, /*!< in: is page encryption used ibool page_encryption, /*!< in: is page encryption used
on this file space */ on this file space */
ulint page_encryption_key, /*!< page encryption key ulint page_encryption_key, /*!< in: page encryption key
to be used */ to be used */
lsn_t lsn); /* lsn of the newest modification */ lsn_t lsn, /*!< in: lsn of the newest modification */
bool encrypt_later); /*!< in: should we encrypt ? */
/************************************************************************//** /************************************************************************//**
Wakes up all async i/o threads so that they know to exit themselves in Wakes up all async i/o threads so that they know to exit themselves in
shutdown. */ shutdown. */

View file

@ -222,7 +222,7 @@ pfs_os_aio_func(
trx_t* trx, trx_t* trx,
ibool page_compression, /*!< in: is page compression used ibool page_compression, /*!< in: is page compression used
on this file space */ on this file space */
ulint page_compression_level, /*!< page compression ulint page_compression_level, /*!< in: page compression
level to be used */ level to be used */
ulint* write_size,/*!< in/out: Actual write size initialized ulint* write_size,/*!< in/out: Actual write size initialized
after fist successfull trim after fist successfull trim
@ -231,10 +231,12 @@ pfs_os_aio_func(
actual page size does not decrease. */ actual page size does not decrease. */
ibool page_encryption, /*!< in: is page encryption used ibool page_encryption, /*!< in: is page encryption used
on this file space */ on this file space */
ulint page_encryption_key, /*!< page encryption ulint page_encryption_key, /*!< in: page encryption
key to be used */ key to be used */
lsn_t lsn, /* lsn of the newest modification */ lsn_t lsn, /*!< in: lsn of the newest
modification */
bool encrypt_later, /*!< in: encrypt later ? */
const char* src_file,/*!< in: file name where func invoked */ const char* src_file,/*!< in: file name where func invoked */
ulint src_line)/*!< in: line where the func invoked */ ulint src_line)/*!< in: line where the func invoked */
{ {
@ -252,7 +254,7 @@ pfs_os_aio_func(
result = os_aio_func(type, mode, name, file, buf, offset, result = os_aio_func(type, mode, name, file, buf, offset,
n, message1, message2, space_id, trx, n, message1, message2, space_id, trx,
page_compression, page_compression_level, write_size , page_compression, page_compression_level, write_size ,
page_encryption, page_encryption_key, lsn); page_encryption, page_encryption_key, lsn, encrypt_later);
register_pfs_file_io_end(locker, n); register_pfs_file_io_end(locker, n);

View file

@ -1384,7 +1384,7 @@ log_group_file_header_flush(
(ulint) (dest_offset / UNIV_PAGE_SIZE), (ulint) (dest_offset / UNIV_PAGE_SIZE),
(ulint) (dest_offset % UNIV_PAGE_SIZE), (ulint) (dest_offset % UNIV_PAGE_SIZE),
OS_FILE_LOG_BLOCK_SIZE, OS_FILE_LOG_BLOCK_SIZE,
buf, group, 0, 0); buf, group, 0, 0, false);
srv_stats.os_log_pending_writes.dec(); srv_stats.os_log_pending_writes.dec();
} }
@ -1551,7 +1551,7 @@ loop:
fil_io(OS_FILE_WRITE | OS_FILE_LOG, true, group->space_id, 0, fil_io(OS_FILE_WRITE | OS_FILE_LOG, true, group->space_id, 0,
(ulint) (next_offset / UNIV_PAGE_SIZE), (ulint) (next_offset / UNIV_PAGE_SIZE),
(ulint) (next_offset % UNIV_PAGE_SIZE), write_len, buf, (ulint) (next_offset % UNIV_PAGE_SIZE), write_len, buf,
group, 0, 0); group, 0, 0, false);
srv_stats.os_log_pending_writes.dec(); srv_stats.os_log_pending_writes.dec();
@ -2144,7 +2144,7 @@ log_group_checkpoint(
write_offset / UNIV_PAGE_SIZE, write_offset / UNIV_PAGE_SIZE,
write_offset % UNIV_PAGE_SIZE, write_offset % UNIV_PAGE_SIZE,
OS_FILE_LOG_BLOCK_SIZE, OS_FILE_LOG_BLOCK_SIZE,
buf, ((byte*) group + 1), 0, 0); buf, ((byte*) group + 1), 0, 0, false);
ut_ad(((ulint) group & 0x1UL) == 0); ut_ad(((ulint) group & 0x1UL) == 0);
} }
@ -2226,7 +2226,7 @@ log_group_read_checkpoint_info(
fil_io(OS_FILE_READ | OS_FILE_LOG, true, group->space_id, 0, fil_io(OS_FILE_READ | OS_FILE_LOG, true, group->space_id, 0,
field / UNIV_PAGE_SIZE, field % UNIV_PAGE_SIZE, field / UNIV_PAGE_SIZE, field % UNIV_PAGE_SIZE,
OS_FILE_LOG_BLOCK_SIZE, log_sys->checkpoint_buf, NULL, 0, 0); OS_FILE_LOG_BLOCK_SIZE, log_sys->checkpoint_buf, NULL, 0, 0, false);
} }
/******************************************************//** /******************************************************//**
@ -2639,7 +2639,7 @@ loop:
fil_io(OS_FILE_READ | OS_FILE_LOG, sync, group->space_id, 0, fil_io(OS_FILE_READ | OS_FILE_LOG, sync, group->space_id, 0,
(ulint) (source_offset / UNIV_PAGE_SIZE), (ulint) (source_offset / UNIV_PAGE_SIZE),
(ulint) (source_offset % UNIV_PAGE_SIZE), (ulint) (source_offset % UNIV_PAGE_SIZE),
len, buf, (type == LOG_ARCHIVE) ? &log_archive_io : NULL, 0, 0); len, buf, (type == LOG_ARCHIVE) ? &log_archive_io : NULL, 0, 0, false);
if (recv_sys->recv_log_crypt_ver != UNENCRYPTED_KEY_VER && if (recv_sys->recv_log_crypt_ver != UNENCRYPTED_KEY_VER &&
!log_group_decrypt_after_read(group, buf, len)) !log_group_decrypt_after_read(group, buf, len))
@ -2771,7 +2771,7 @@ log_group_archive_file_header_write(
dest_offset / UNIV_PAGE_SIZE, dest_offset / UNIV_PAGE_SIZE,
dest_offset % UNIV_PAGE_SIZE, dest_offset % UNIV_PAGE_SIZE,
2 * OS_FILE_LOG_BLOCK_SIZE, 2 * OS_FILE_LOG_BLOCK_SIZE,
buf, &log_archive_io, 0, 0); buf, &log_archive_io, 0, 0, false);
} }
/******************************************************//** /******************************************************//**
@ -2808,7 +2808,7 @@ log_group_archive_completed_header_write(
dest_offset % UNIV_PAGE_SIZE, dest_offset % UNIV_PAGE_SIZE,
OS_FILE_LOG_BLOCK_SIZE, OS_FILE_LOG_BLOCK_SIZE,
buf + LOG_FILE_ARCH_COMPLETED, buf + LOG_FILE_ARCH_COMPLETED,
&log_archive_io, 0, 0); &log_archive_io, 0, 0, false);
} }
/******************************************************//** /******************************************************//**
@ -2953,7 +2953,7 @@ loop:
(ulint) (next_offset / UNIV_PAGE_SIZE), (ulint) (next_offset / UNIV_PAGE_SIZE),
(ulint) (next_offset % UNIV_PAGE_SIZE), (ulint) (next_offset % UNIV_PAGE_SIZE),
ut_calc_align(len, OS_FILE_LOG_BLOCK_SIZE), buf, ut_calc_align(len, OS_FILE_LOG_BLOCK_SIZE), buf,
&log_archive_io, 0, 0); &log_archive_io, 0, 0, false);
start_lsn += len; start_lsn += len;
next_offset += len; next_offset += len;

View file

@ -2156,7 +2156,7 @@ recv_apply_log_recs_for_backup(void)
error = fil_io(OS_FILE_READ, true, error = fil_io(OS_FILE_READ, true,
recv_addr->space, zip_size, recv_addr->space, zip_size,
recv_addr->page_no, 0, zip_size, recv_addr->page_no, 0, zip_size,
block->page.zip.data, NULL, 0, 0); block->page.zip.data, NULL, 0, 0, false);
if (error == DB_SUCCESS if (error == DB_SUCCESS
&& !buf_zip_decompress(block, TRUE)) { && !buf_zip_decompress(block, TRUE)) {
exit(1); exit(1);
@ -2166,7 +2166,7 @@ recv_apply_log_recs_for_backup(void)
recv_addr->space, 0, recv_addr->space, 0,
recv_addr->page_no, 0, recv_addr->page_no, 0,
UNIV_PAGE_SIZE, UNIV_PAGE_SIZE,
block->frame, NULL, 0, 0); block->frame, NULL, 0, 0, false);
} }
if (error != DB_SUCCESS) { if (error != DB_SUCCESS) {
@ -2195,13 +2195,15 @@ recv_apply_log_recs_for_backup(void)
recv_addr->space, zip_size, recv_addr->space, zip_size,
recv_addr->page_no, 0, recv_addr->page_no, 0,
zip_size, zip_size,
block->page.zip.data, NULL, 0, 0); block->page.zip.data, NULL, 0, 0, false);
} else { } else {
error = fil_io(OS_FILE_WRITE, true, error = fil_io(OS_FILE_WRITE, true,
recv_addr->space, 0, recv_addr->space, 0,
recv_addr->page_no, 0, recv_addr->page_no, 0,
UNIV_PAGE_SIZE, UNIV_PAGE_SIZE,
block->frame, NULL, 0, 0); block->frame, NULL, 0,
block->latest_modification,
block->encrypt_later);
} }
skip_this_recv_addr: skip_this_recv_addr:
recv_addr = HASH_GET_NEXT(addr_hash, recv_addr); recv_addr = HASH_GET_NEXT(addr_hash, recv_addr);
@ -3175,7 +3177,7 @@ recv_recovery_from_checkpoint_start_func(
fil_io(OS_FILE_READ | OS_FILE_LOG, true, max_cp_group->space_id, 0, fil_io(OS_FILE_READ | OS_FILE_LOG, true, max_cp_group->space_id, 0,
0, 0, LOG_FILE_HDR_SIZE, 0, 0, LOG_FILE_HDR_SIZE,
log_hdr_buf, max_cp_group, 0, 0); log_hdr_buf, max_cp_group, 0, 0, false);
if (0 == ut_memcmp(log_hdr_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP, if (0 == ut_memcmp(log_hdr_buf + LOG_FILE_WAS_CREATED_BY_HOT_BACKUP,
(byte*)"ibbackup", (sizeof "ibbackup") - 1)) { (byte*)"ibbackup", (sizeof "ibbackup") - 1)) {
@ -3206,7 +3208,7 @@ recv_recovery_from_checkpoint_start_func(
fil_io(OS_FILE_WRITE | OS_FILE_LOG, true, fil_io(OS_FILE_WRITE | OS_FILE_LOG, true,
max_cp_group->space_id, 0, max_cp_group->space_id, 0,
0, 0, OS_FILE_LOG_BLOCK_SIZE, 0, 0, OS_FILE_LOG_BLOCK_SIZE,
log_hdr_buf, max_cp_group, 0, 0); log_hdr_buf, max_cp_group, 0, 0, false);
} }
log_hdr_log_block_size log_hdr_log_block_size
@ -3869,7 +3871,7 @@ ask_again:
/* Read the archive file header */ /* Read the archive file header */
fil_io(OS_FILE_READ | OS_FILE_LOG, true, group->archive_space_id, 0, fil_io(OS_FILE_READ | OS_FILE_LOG, true, group->archive_space_id, 0,
0, 0, 0, 0,
LOG_FILE_HDR_SIZE, buf, NULL, 0, 0); LOG_FILE_HDR_SIZE, buf, NULL, 0, 0, false);
/* Check if the archive file header is consistent */ /* Check if the archive file header is consistent */
@ -3943,7 +3945,7 @@ ask_again:
fil_io(OS_FILE_READ | OS_FILE_LOG, true, fil_io(OS_FILE_READ | OS_FILE_LOG, true,
group->archive_space_id, 0, group->archive_space_id, 0,
read_offset / UNIV_PAGE_SIZE, read_offset / UNIV_PAGE_SIZE,
read_offset % UNIV_PAGE_SIZE, len, buf, NULL, 0, 0); read_offset % UNIV_PAGE_SIZE, len, buf, NULL, 0, 0, false);
ret = recv_scan_log_recs( ret = recv_scan_log_recs(
(buf_pool_get_n_pages() (buf_pool_get_n_pages()

View file

@ -273,6 +273,7 @@ struct os_aio_slot_t{
lsn_t lsn; /* lsn of the newest modification */ lsn_t lsn; /* lsn of the newest modification */
ulint file_block_size;/*!< file block size */ ulint file_block_size;/*!< file block size */
bool encrypt_later; /*!< should we encrypt the page */
#ifdef LINUX_NATIVE_AIO #ifdef LINUX_NATIVE_AIO
struct iocb control; /* Linux control block for aio */ struct iocb control; /* Linux control block for aio */
@ -1982,6 +1983,9 @@ os_file_create_func(
#else #else
if (purpose == OS_FILE_AIO) { if (purpose == OS_FILE_AIO) {
bool encrypt_later; /*!< should the page be encrypted
before write */
#ifdef WIN_ASYNC_IO #ifdef WIN_ASYNC_IO
/* If specified, use asynchronous (overlapped) io and no /* If specified, use asynchronous (overlapped) io and no
buffering of writes in the OS */ buffering of writes in the OS */
@ -4663,7 +4667,9 @@ os_aio_array_reserve_slot(
operation for this page and if operation for this page and if
initialized we do not trim again if initialized we do not trim again if
actual page size does not decrease. */ actual page size does not decrease. */
lsn_t lsn) /* lsn of the newest modification */ lsn_t lsn, /*!< in: lsn of the newest
modification */
bool encrypt_later) /*!< in: should we encrypt the page */
{ {
os_aio_slot_t* slot = NULL; os_aio_slot_t* slot = NULL;
#ifdef WIN_ASYNC_IO #ifdef WIN_ASYNC_IO
@ -4755,15 +4761,14 @@ found:
slot->lsn = lsn; slot->lsn = lsn;
slot->io_already_done = FALSE; slot->io_already_done = FALSE;
slot->space_id = space_id; slot->space_id = space_id;
slot->page_compression_success = FALSE; slot->page_compression_success = FALSE;
slot->page_encryption_success = FALSE; slot->page_encryption_success = FALSE;
slot->write_size = write_size; slot->write_size = write_size;
slot->page_compression_level = page_compression_level; slot->page_compression_level = page_compression_level;
slot->page_compression = page_compression; slot->page_compression = page_compression;
slot->page_encryption_key = page_encryption_key; slot->page_encryption_key = page_encryption_key;
slot->page_encryption = page_encryption; slot->page_encryption = page_encryption;
slot->encrypt_later = encrypt_later;
if (message1) { if (message1) {
slot->file_block_size = fil_node_get_block_size(message1); slot->file_block_size = fil_node_get_block_size(message1);
@ -4819,7 +4824,7 @@ found:
/* If the space is page encryption and this is write operation /* If the space is page encryption and this is write operation
then we encrypt the page */ then we encrypt the page */
if (message1 && type == OS_FILE_WRITE && page_encryption ) { if (message1 && type == OS_FILE_WRITE && (page_encryption || encrypt_later)) {
/* Release the array mutex while encrypting */ /* Release the array mutex while encrypting */
os_mutex_exit(array->mutex); os_mutex_exit(array->mutex);
@ -4843,6 +4848,8 @@ found:
os_mutex_enter(array->mutex); os_mutex_enter(array->mutex);
} }
slot->buf = (byte *)buf;
#ifdef WIN_ASYNC_IO #ifdef WIN_ASYNC_IO
control = &slot->control; control = &slot->control;
control->Offset = (DWORD) offset & 0xFFFFFFFF; control->Offset = (DWORD) offset & 0xFFFFFFFF;
@ -5130,9 +5137,11 @@ os_aio_func(
actual page size does not decrease. */ actual page size does not decrease. */
ibool page_encryption, /*!< in: is page encryption used ibool page_encryption, /*!< in: is page encryption used
on this file space */ on this file space */
ulint page_encryption_key, /*!< page encryption key ulint page_encryption_key, /*!< in: page encryption key
to be used */ to be used */
lsn_t lsn) /* lsn of the newest modification */ lsn_t lsn, /*!< in: lsn of the newest modification */
bool encrypt_later) /*!< in: should we encrypt before
writing the page */
{ {
os_aio_array_t* array; os_aio_array_t* array;
os_aio_slot_t* slot; os_aio_slot_t* slot;
@ -5239,7 +5248,8 @@ try_again:
slot = os_aio_array_reserve_slot(type, array, message1, message2, file, slot = os_aio_array_reserve_slot(type, array, message1, message2, file,
name, buf, offset, n, space_id, name, buf, offset, n, space_id,
page_compression, page_compression_level, page_compression, page_compression_level,
page_encryption, page_encryption_key, write_size, lsn); page_encryption, page_encryption_key,
write_size, lsn, encrypt_later);
if (type == OS_FILE_READ) { if (type == OS_FILE_READ) {
if (srv_use_native_aio) { if (srv_use_native_aio) {