Commit f2fe6510 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-11679 Remove redundant function fsp_header_get_crypt_offset()

fsp_header_get_crypt_offset(): Remove.

xdes_arr_size(): Remove.

fsp_header_get_encryption_offset(): Make this an inline function.

The correctness of this change was ensured with the following patch
that ensures that the two functions returned the same value, only
differing by FSP_HEADER_OFFSET (38 bytes):

diff --git a/storage/innobase/fsp/fsp0fsp.cc b/storage/innobase/fsp/fsp0fsp.cc
index f2a4c6bf218..e96c788b7df 100644
--- a/storage/innobase/fsp/fsp0fsp.cc
+++ b/storage/innobase/fsp/fsp0fsp.cc
@@ -850,6 +850,7 @@ fsp_parse_init_file_page(
 	return(ptr);
 }

+static ulint fsp_header_get_encryption_offset(const page_size_t&);
 /**********************************************************************//**
 Initializes the fsp system. */
 void
@@ -868,6 +869,31 @@ fsp_init(void)
 #endif

 	/* Does nothing at the moment */
+
+	for (ulint sz = 4096; sz <= 65536; sz *= 2) {
+		ulint m;
+		if (sz <= 16384) {
+			for (ulint ph = 1024; ph <= sz; ph *= 2) {
+				const page_size_t ps(ph, sz, true);
+				ulint maria = fsp_header_get_crypt_offset(ps, &m),
+					oracle = fsp_header_get_encryption_offset(ps);
+				if (maria != oracle + 38) {
+					ib::error() << "zip size mismatch: "
+						    << maria << "!=" << oracle
+						    << "(" << ph <<","<<sz<<")"
+						    << m;
+				}
+			}
+		}
+		const page_size_t p(sz, sz, false);
+		ulint maria = fsp_header_get_crypt_offset(p, &m),
+			oracle = fsp_header_get_encryption_offset(p);
+		if (maria != oracle + 38) {
+			ib::error() << "size mismatch: "
+				    << maria << "!=" << oracle
+				    << "(" <<sz<<")" << m;
+		}
+	}
 }

 /**********************************************************************//**
parent 7bcae22b
......@@ -1179,10 +1179,11 @@ fil_crypt_start_encrypting_space(
/* 3 - compute location to store crypt data */
byte* frame = buf_block_get_frame(block);
ulint maxsize = 0;
ut_ad(crypt_data);
crypt_data->page0_offset =
fsp_header_get_crypt_offset(page_size, &maxsize);
crypt_data->page0_offset = FSP_HEADER_OFFSET
+ fsp_header_get_encryption_offset(page_size);
const ulint maxsize = page_size.logical()
- crypt_data->page0_offset - FIL_PAGE_DATA_END;
/* 4 - write crypt data to page 0 */
fil_space_write_crypt_data_low(crypt_data,
......@@ -2165,10 +2166,9 @@ fil_crypt_flush_space(
if (block && err == DB_SUCCESS) {
byte* frame = buf_block_get_frame(block);
ulint maxsize=0;
crypt_data->page0_offset =
fsp_header_get_crypt_offset(page_size, &maxsize);
crypt_data->page0_offset = FSP_HEADER_OFFSET
+ fsp_header_get_encryption_offset(page_size);
fil_space_write_crypt_data(space, frame,
crypt_data->page0_offset,
......
......@@ -6661,12 +6661,11 @@ fil_tablespace_iterate(
iter.n_io_buffers = n_io_buffers;
iter.page_size = callback.get_page_size().physical();
ulint crypt_data_offset = fsp_header_get_crypt_offset(
callback.get_page_size(), 0);
/* read (optional) crypt data */
iter.crypt_data = fil_space_read_crypt_data(
0, page, crypt_data_offset);
0, page, FSP_HEADER_OFFSET
+ fsp_header_get_encryption_offset(
callback.get_page_size()));
#ifdef MYSQL_ENCRYPTION
/* Set encryption info. */
......@@ -7612,8 +7611,9 @@ fil_space_get_crypt_data(
fil_read(page_id_t(space_id, 0), univ_page_size, 0, univ_page_size.physical(),
page);
ulint flags = fsp_header_get_flags(page);
ulint offset = fsp_header_get_crypt_offset(
page_size_t(flags), NULL);
ulint offset = FSP_HEADER_OFFSET
+ fsp_header_get_encryption_offset(
page_size_t(flags));
space->crypt_data = fil_space_read_crypt_data(space_id, page, offset);
ut_free(buf);
......
......@@ -368,9 +368,10 @@ Datafile::read_first_page(bool read_only_mode)
m_space_id = fsp_header_get_space_id(m_first_page);
}
const page_size_t page_sz = fsp_header_get_page_size(m_first_page);
ulint offset = fsp_header_get_crypt_offset(page_sz, NULL);
m_crypt_info = fil_space_read_crypt_data(m_space_id, m_first_page, offset);
m_crypt_info = fil_space_read_crypt_data(
m_space_id, m_first_page,
FSP_HEADER_OFFSET + fsp_header_get_encryption_offset(
fsp_header_get_page_size(m_first_page)));
return(err);
}
......
......@@ -890,29 +890,6 @@ fsp_header_init_fields(
}
#ifndef UNIV_HOTBACKUP
/** Get the offset of encrytion information in page 0.
@param[in] page_size page size.
@return offset on success, otherwise 0. */
static
ulint
fsp_header_get_encryption_offset(
const page_size_t& page_size)
{
ulint offset;
#ifdef UNIV_DEBUG
ulint left_size;
#endif
offset = XDES_ARR_OFFSET + XDES_SIZE * xdes_arr_size(page_size);
#ifdef UNIV_DEBUG
left_size = page_size.physical() - FSP_HEADER_OFFSET - offset
- FIL_PAGE_DATA_END;
ut_ad(left_size >= ENCRYPTION_INFO_SIZE_V2);
#endif
return offset;
}
#if 0 /* MySQL 5.7 Encryption */
/** Fill the encryption info.
......@@ -1180,9 +1157,11 @@ fsp_header_init(
}
}
ulint maxsize = 0;
ulint offset = fsp_header_get_crypt_offset(page_size, &maxsize);
fil_space_write_crypt_data(space_id, page, offset, maxsize, mtr);
ulint offset = FSP_HEADER_OFFSET
+ fsp_header_get_encryption_offset(page_size);
fil_space_write_crypt_data(space_id, page, offset,
page_size.logical()
- offset - FIL_PAGE_DATA_END, mtr);
return(true);
}
......@@ -4342,35 +4321,3 @@ fsp_page_is_free_func(
return xdes_mtr_get_bit(
descr, XDES_FREE_BIT, page_no % FSP_EXTENT_SIZE, mtr);
}
/**********************************************************************//**
Compute offset after xdes where crypt data can be stored
@return offset */
ulint
fsp_header_get_crypt_offset(
/*========================*/
const page_size_t& page_size,/*!< in: page size */
ulint* max_size) /*!< out: free space available for crypt data */
{
ulint pageno = 0;
/* compute first page_no that will have xdes stored on page != 0*/
for (ulint i = 0;
(pageno = xdes_calc_descriptor_page(page_size, i)) == 0; )
i++;
/* use pageno prior to this...i.e last page on page 0 */
ut_ad(pageno > 0);
pageno--;
ulint iv_offset = XDES_ARR_OFFSET +
XDES_SIZE * (1 + xdes_calc_descriptor_index(page_size, pageno));
if (max_size != NULL) {
/* return how much free space there is available on page */
*max_size = (page_size.logical() ? page_size.logical() : UNIV_PAGE_SIZE) -
(FSP_HEADER_OFFSET + iv_offset + FIL_PAGE_DATA_END);
}
return FSP_HEADER_OFFSET + iv_offset;
}
......@@ -361,6 +361,16 @@ fsp_header_get_encryption_key(
byte* iv,
page_t* page);
/** Get the byte offset of encryption information in page 0.
@param[in] ps page size
@return byte offset relative to FSP_HEADER_OFFSET */
inline MY_ATTRIBUTE((pure, warn_unused_result))
ulint
fsp_header_get_encryption_offset(const page_size_t& ps)
{
return XDES_ARR_OFFSET + XDES_SIZE * ps.physical() / FSP_EXTENT_SIZE;
}
/** Check the encryption key from the first page of a tablespace.
@param[in] fsp_flags tablespace flags
@param[in] page first page of a tablespace
......@@ -770,20 +780,6 @@ xdes_calc_descriptor_page(
const page_size_t& page_size,
ulint offset);
#endif /* !UNIV_INNOCHECKSUM */
/*********************************************************************//**
@return offset into fsp header where crypt data is stored */
UNIV_INTERN
ulint
fsp_header_get_crypt_offset(
/*========================*/
const page_size_t& page_size,/*!< in: page size */
ulint* max_size); /*!< out: free space after offset */
#ifndef UNIV_INNOCHECKSUM
/**********************************************************************//**
Checks if a single page is free.
@return true if free */
......
......@@ -337,15 +337,4 @@ xdes_calc_descriptor_page(
return(ut_2pow_round(offset, page_size.physical()));
}
/** Calculates the descriptor array size.
@param[in] page_size page size
@return size of descriptor array */
UNIV_INLINE
ulint
xdes_arr_size(
const page_size_t& page_size)
{
return(page_size.physical()/FSP_EXTENT_SIZE);
}
#endif /* !UNIV_INNOCHECKSUM */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment