Skip to content

Commit f2fe651

Browse files
committed
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 f2a4c6b..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; + } + } } /**********************************************************************//**
1 parent 7bcae22 commit f2fe651

File tree

6 files changed

+31
-98
lines changed

6 files changed

+31
-98
lines changed

storage/innobase/fil/fil0crypt.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,10 +1179,11 @@ fil_crypt_start_encrypting_space(
11791179

11801180
/* 3 - compute location to store crypt data */
11811181
byte* frame = buf_block_get_frame(block);
1182-
ulint maxsize = 0;
11831182
ut_ad(crypt_data);
1184-
crypt_data->page0_offset =
1185-
fsp_header_get_crypt_offset(page_size, &maxsize);
1183+
crypt_data->page0_offset = FSP_HEADER_OFFSET
1184+
+ fsp_header_get_encryption_offset(page_size);
1185+
const ulint maxsize = page_size.logical()
1186+
- crypt_data->page0_offset - FIL_PAGE_DATA_END;
11861187

11871188
/* 4 - write crypt data to page 0 */
11881189
fil_space_write_crypt_data_low(crypt_data,
@@ -2165,10 +2166,9 @@ fil_crypt_flush_space(
21652166

21662167
if (block && err == DB_SUCCESS) {
21672168
byte* frame = buf_block_get_frame(block);
2168-
ulint maxsize=0;
21692169

2170-
crypt_data->page0_offset =
2171-
fsp_header_get_crypt_offset(page_size, &maxsize);
2170+
crypt_data->page0_offset = FSP_HEADER_OFFSET
2171+
+ fsp_header_get_encryption_offset(page_size);
21722172

21732173
fil_space_write_crypt_data(space, frame,
21742174
crypt_data->page0_offset,

storage/innobase/fil/fil0fil.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6661,12 +6661,11 @@ fil_tablespace_iterate(
66616661
iter.n_io_buffers = n_io_buffers;
66626662
iter.page_size = callback.get_page_size().physical();
66636663

6664-
ulint crypt_data_offset = fsp_header_get_crypt_offset(
6665-
callback.get_page_size(), 0);
6666-
66676664
/* read (optional) crypt data */
66686665
iter.crypt_data = fil_space_read_crypt_data(
6669-
0, page, crypt_data_offset);
6666+
0, page, FSP_HEADER_OFFSET
6667+
+ fsp_header_get_encryption_offset(
6668+
callback.get_page_size()));
66706669

66716670
#ifdef MYSQL_ENCRYPTION
66726671
/* Set encryption info. */
@@ -7612,8 +7611,9 @@ fil_space_get_crypt_data(
76127611
fil_read(page_id_t(space_id, 0), univ_page_size, 0, univ_page_size.physical(),
76137612
page);
76147613
ulint flags = fsp_header_get_flags(page);
7615-
ulint offset = fsp_header_get_crypt_offset(
7616-
page_size_t(flags), NULL);
7614+
ulint offset = FSP_HEADER_OFFSET
7615+
+ fsp_header_get_encryption_offset(
7616+
page_size_t(flags));
76177617
space->crypt_data = fil_space_read_crypt_data(space_id, page, offset);
76187618
ut_free(buf);
76197619

storage/innobase/fsp/fsp0file.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,10 @@ Datafile::read_first_page(bool read_only_mode)
368368
m_space_id = fsp_header_get_space_id(m_first_page);
369369
}
370370

371-
const page_size_t page_sz = fsp_header_get_page_size(m_first_page);
372-
ulint offset = fsp_header_get_crypt_offset(page_sz, NULL);
373-
m_crypt_info = fil_space_read_crypt_data(m_space_id, m_first_page, offset);
371+
m_crypt_info = fil_space_read_crypt_data(
372+
m_space_id, m_first_page,
373+
FSP_HEADER_OFFSET + fsp_header_get_encryption_offset(
374+
fsp_header_get_page_size(m_first_page)));
374375

375376
return(err);
376377
}

storage/innobase/fsp/fsp0fsp.cc

Lines changed: 5 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -890,29 +890,6 @@ fsp_header_init_fields(
890890
}
891891

892892
#ifndef UNIV_HOTBACKUP
893-
/** Get the offset of encrytion information in page 0.
894-
@param[in] page_size page size.
895-
@return offset on success, otherwise 0. */
896-
static
897-
ulint
898-
fsp_header_get_encryption_offset(
899-
const page_size_t& page_size)
900-
{
901-
ulint offset;
902-
#ifdef UNIV_DEBUG
903-
ulint left_size;
904-
#endif
905-
906-
offset = XDES_ARR_OFFSET + XDES_SIZE * xdes_arr_size(page_size);
907-
#ifdef UNIV_DEBUG
908-
left_size = page_size.physical() - FSP_HEADER_OFFSET - offset
909-
- FIL_PAGE_DATA_END;
910-
911-
ut_ad(left_size >= ENCRYPTION_INFO_SIZE_V2);
912-
#endif
913-
914-
return offset;
915-
}
916893

917894
#if 0 /* MySQL 5.7 Encryption */
918895
/** Fill the encryption info.
@@ -1180,9 +1157,11 @@ fsp_header_init(
11801157
}
11811158
}
11821159

1183-
ulint maxsize = 0;
1184-
ulint offset = fsp_header_get_crypt_offset(page_size, &maxsize);
1185-
fil_space_write_crypt_data(space_id, page, offset, maxsize, mtr);
1160+
ulint offset = FSP_HEADER_OFFSET
1161+
+ fsp_header_get_encryption_offset(page_size);
1162+
fil_space_write_crypt_data(space_id, page, offset,
1163+
page_size.logical()
1164+
- offset - FIL_PAGE_DATA_END, mtr);
11861165

11871166
return(true);
11881167
}
@@ -4342,35 +4321,3 @@ fsp_page_is_free_func(
43424321
return xdes_mtr_get_bit(
43434322
descr, XDES_FREE_BIT, page_no % FSP_EXTENT_SIZE, mtr);
43444323
}
4345-
4346-
/**********************************************************************//**
4347-
Compute offset after xdes where crypt data can be stored
4348-
@return offset */
4349-
ulint
4350-
fsp_header_get_crypt_offset(
4351-
/*========================*/
4352-
const page_size_t& page_size,/*!< in: page size */
4353-
ulint* max_size) /*!< out: free space available for crypt data */
4354-
{
4355-
ulint pageno = 0;
4356-
/* compute first page_no that will have xdes stored on page != 0*/
4357-
4358-
for (ulint i = 0;
4359-
(pageno = xdes_calc_descriptor_page(page_size, i)) == 0; )
4360-
i++;
4361-
4362-
/* use pageno prior to this...i.e last page on page 0 */
4363-
ut_ad(pageno > 0);
4364-
pageno--;
4365-
4366-
ulint iv_offset = XDES_ARR_OFFSET +
4367-
XDES_SIZE * (1 + xdes_calc_descriptor_index(page_size, pageno));
4368-
4369-
if (max_size != NULL) {
4370-
/* return how much free space there is available on page */
4371-
*max_size = (page_size.logical() ? page_size.logical() : UNIV_PAGE_SIZE) -
4372-
(FSP_HEADER_OFFSET + iv_offset + FIL_PAGE_DATA_END);
4373-
}
4374-
4375-
return FSP_HEADER_OFFSET + iv_offset;
4376-
}

storage/innobase/include/fsp0fsp.h

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,16 @@ fsp_header_get_encryption_key(
361361
byte* iv,
362362
page_t* page);
363363

364+
/** Get the byte offset of encryption information in page 0.
365+
@param[in] ps page size
366+
@return byte offset relative to FSP_HEADER_OFFSET */
367+
inline MY_ATTRIBUTE((pure, warn_unused_result))
368+
ulint
369+
fsp_header_get_encryption_offset(const page_size_t& ps)
370+
{
371+
return XDES_ARR_OFFSET + XDES_SIZE * ps.physical() / FSP_EXTENT_SIZE;
372+
}
373+
364374
/** Check the encryption key from the first page of a tablespace.
365375
@param[in] fsp_flags tablespace flags
366376
@param[in] page first page of a tablespace
@@ -770,20 +780,6 @@ xdes_calc_descriptor_page(
770780
const page_size_t& page_size,
771781
ulint offset);
772782

773-
#endif /* !UNIV_INNOCHECKSUM */
774-
775-
/*********************************************************************//**
776-
@return offset into fsp header where crypt data is stored */
777-
UNIV_INTERN
778-
ulint
779-
fsp_header_get_crypt_offset(
780-
/*========================*/
781-
const page_size_t& page_size,/*!< in: page size */
782-
ulint* max_size); /*!< out: free space after offset */
783-
784-
785-
#ifndef UNIV_INNOCHECKSUM
786-
787783
/**********************************************************************//**
788784
Checks if a single page is free.
789785
@return true if free */

storage/innobase/include/fsp0fsp.ic

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -337,15 +337,4 @@ xdes_calc_descriptor_page(
337337

338338
return(ut_2pow_round(offset, page_size.physical()));
339339
}
340-
341-
/** Calculates the descriptor array size.
342-
@param[in] page_size page size
343-
@return size of descriptor array */
344-
UNIV_INLINE
345-
ulint
346-
xdes_arr_size(
347-
const page_size_t& page_size)
348-
{
349-
return(page_size.physical()/FSP_EXTENT_SIZE);
350-
}
351340
#endif /* !UNIV_INNOCHECKSUM */

0 commit comments

Comments
 (0)