Commit 0b60be16 authored by Christophe JAILLET's avatar Christophe JAILLET Committed by Mikulas Patocka

dm: Constify struct dm_block_validator

'struct dm_block_validator' are not modified in these drivers.

Constifying this structure moves some data to a read-only section, so
increase overall security.

On a x86_64, with allmodconfig, as an example:

Before:
======
   text	   data	    bss	    dec	    hex	filename
  32047	    920	     16	  32983	   80d7	drivers/md/dm-cache-metadata.o

After:
=====
   text	   data	    bss	    dec	    hex	filename
  32075	    896	     16	  32987	   80db	drivers/md/dm-cache-metadata.o
Signed-off-by: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
parent fb098768
...@@ -170,7 +170,7 @@ struct dm_cache_metadata { ...@@ -170,7 +170,7 @@ struct dm_cache_metadata {
*/ */
#define SUPERBLOCK_CSUM_XOR 9031977 #define SUPERBLOCK_CSUM_XOR 9031977
static void sb_prepare_for_write(struct dm_block_validator *v, static void sb_prepare_for_write(const struct dm_block_validator *v,
struct dm_block *b, struct dm_block *b,
size_t sb_block_size) size_t sb_block_size)
{ {
...@@ -195,7 +195,7 @@ static int check_metadata_version(struct cache_disk_superblock *disk_super) ...@@ -195,7 +195,7 @@ static int check_metadata_version(struct cache_disk_superblock *disk_super)
return 0; return 0;
} }
static int sb_check(struct dm_block_validator *v, static int sb_check(const struct dm_block_validator *v,
struct dm_block *b, struct dm_block *b,
size_t sb_block_size) size_t sb_block_size)
{ {
...@@ -228,7 +228,7 @@ static int sb_check(struct dm_block_validator *v, ...@@ -228,7 +228,7 @@ static int sb_check(struct dm_block_validator *v,
return check_metadata_version(disk_super); return check_metadata_version(disk_super);
} }
static struct dm_block_validator sb_validator = { static const struct dm_block_validator sb_validator = {
.name = "superblock", .name = "superblock",
.prepare_for_write = sb_prepare_for_write, .prepare_for_write = sb_prepare_for_write,
.check = sb_check .check = sb_check
......
...@@ -163,7 +163,7 @@ struct dm_clone_metadata { ...@@ -163,7 +163,7 @@ struct dm_clone_metadata {
/* /*
* Superblock validation. * Superblock validation.
*/ */
static void sb_prepare_for_write(struct dm_block_validator *v, static void sb_prepare_for_write(const struct dm_block_validator *v,
struct dm_block *b, size_t sb_block_size) struct dm_block *b, size_t sb_block_size)
{ {
struct superblock_disk *sb; struct superblock_disk *sb;
...@@ -177,7 +177,7 @@ static void sb_prepare_for_write(struct dm_block_validator *v, ...@@ -177,7 +177,7 @@ static void sb_prepare_for_write(struct dm_block_validator *v,
sb->csum = cpu_to_le32(csum); sb->csum = cpu_to_le32(csum);
} }
static int sb_check(struct dm_block_validator *v, struct dm_block *b, static int sb_check(const struct dm_block_validator *v, struct dm_block *b,
size_t sb_block_size) size_t sb_block_size)
{ {
struct superblock_disk *sb; struct superblock_disk *sb;
...@@ -220,7 +220,7 @@ static int sb_check(struct dm_block_validator *v, struct dm_block *b, ...@@ -220,7 +220,7 @@ static int sb_check(struct dm_block_validator *v, struct dm_block *b,
return 0; return 0;
} }
static struct dm_block_validator sb_validator = { static const struct dm_block_validator sb_validator = {
.name = "superblock", .name = "superblock",
.prepare_for_write = sb_prepare_for_write, .prepare_for_write = sb_prepare_for_write,
.check = sb_check .check = sb_check
......
...@@ -196,7 +196,7 @@ struct superblock_disk { ...@@ -196,7 +196,7 @@ struct superblock_disk {
* Superblock validation * Superblock validation
*-------------------------------------------------------------- *--------------------------------------------------------------
*/ */
static void sb_prepare_for_write(struct dm_block_validator *v, static void sb_prepare_for_write(const struct dm_block_validator *v,
struct dm_block *b, struct dm_block *b,
size_t sb_block_size) size_t sb_block_size)
{ {
...@@ -221,7 +221,7 @@ static int check_metadata_version(struct superblock_disk *disk) ...@@ -221,7 +221,7 @@ static int check_metadata_version(struct superblock_disk *disk)
return 0; return 0;
} }
static int sb_check(struct dm_block_validator *v, static int sb_check(const struct dm_block_validator *v,
struct dm_block *b, struct dm_block *b,
size_t sb_block_size) size_t sb_block_size)
{ {
...@@ -254,7 +254,7 @@ static int sb_check(struct dm_block_validator *v, ...@@ -254,7 +254,7 @@ static int sb_check(struct dm_block_validator *v,
return check_metadata_version(disk); return check_metadata_version(disk);
} }
static struct dm_block_validator sb_validator = { static const struct dm_block_validator sb_validator = {
.name = "superblock", .name = "superblock",
.prepare_for_write = sb_prepare_for_write, .prepare_for_write = sb_prepare_for_write,
.check = sb_check .check = sb_check
......
...@@ -249,7 +249,7 @@ struct dm_thin_device { ...@@ -249,7 +249,7 @@ struct dm_thin_device {
*/ */
#define SUPERBLOCK_CSUM_XOR 160774 #define SUPERBLOCK_CSUM_XOR 160774
static void sb_prepare_for_write(struct dm_block_validator *v, static void sb_prepare_for_write(const struct dm_block_validator *v,
struct dm_block *b, struct dm_block *b,
size_t block_size) size_t block_size)
{ {
...@@ -261,7 +261,7 @@ static void sb_prepare_for_write(struct dm_block_validator *v, ...@@ -261,7 +261,7 @@ static void sb_prepare_for_write(struct dm_block_validator *v,
SUPERBLOCK_CSUM_XOR)); SUPERBLOCK_CSUM_XOR));
} }
static int sb_check(struct dm_block_validator *v, static int sb_check(const struct dm_block_validator *v,
struct dm_block *b, struct dm_block *b,
size_t block_size) size_t block_size)
{ {
...@@ -294,7 +294,7 @@ static int sb_check(struct dm_block_validator *v, ...@@ -294,7 +294,7 @@ static int sb_check(struct dm_block_validator *v,
return 0; return 0;
} }
static struct dm_block_validator sb_validator = { static const struct dm_block_validator sb_validator = {
.name = "superblock", .name = "superblock",
.prepare_for_write = sb_prepare_for_write, .prepare_for_write = sb_prepare_for_write,
.check = sb_check .check = sb_check
......
...@@ -38,7 +38,7 @@ struct array_block { ...@@ -38,7 +38,7 @@ struct array_block {
*/ */
#define CSUM_XOR 595846735 #define CSUM_XOR 595846735
static void array_block_prepare_for_write(struct dm_block_validator *v, static void array_block_prepare_for_write(const struct dm_block_validator *v,
struct dm_block *b, struct dm_block *b,
size_t size_of_block) size_t size_of_block)
{ {
...@@ -50,7 +50,7 @@ static void array_block_prepare_for_write(struct dm_block_validator *v, ...@@ -50,7 +50,7 @@ static void array_block_prepare_for_write(struct dm_block_validator *v,
CSUM_XOR)); CSUM_XOR));
} }
static int array_block_check(struct dm_block_validator *v, static int array_block_check(const struct dm_block_validator *v,
struct dm_block *b, struct dm_block *b,
size_t size_of_block) size_t size_of_block)
{ {
...@@ -77,7 +77,7 @@ static int array_block_check(struct dm_block_validator *v, ...@@ -77,7 +77,7 @@ static int array_block_check(struct dm_block_validator *v,
return 0; return 0;
} }
static struct dm_block_validator array_validator = { static const struct dm_block_validator array_validator = {
.name = "array", .name = "array",
.prepare_for_write = array_block_prepare_for_write, .prepare_for_write = array_block_prepare_for_write,
.check = array_block_check .check = array_block_check
......
...@@ -345,7 +345,7 @@ void *dm_block_data(struct dm_block *b) ...@@ -345,7 +345,7 @@ void *dm_block_data(struct dm_block *b)
EXPORT_SYMBOL_GPL(dm_block_data); EXPORT_SYMBOL_GPL(dm_block_data);
struct buffer_aux { struct buffer_aux {
struct dm_block_validator *validator; const struct dm_block_validator *validator;
int write_locked; int write_locked;
#ifdef CONFIG_DM_DEBUG_BLOCK_MANAGER_LOCKING #ifdef CONFIG_DM_DEBUG_BLOCK_MANAGER_LOCKING
...@@ -441,7 +441,7 @@ dm_block_t dm_bm_nr_blocks(struct dm_block_manager *bm) ...@@ -441,7 +441,7 @@ dm_block_t dm_bm_nr_blocks(struct dm_block_manager *bm)
static int dm_bm_validate_buffer(struct dm_block_manager *bm, static int dm_bm_validate_buffer(struct dm_block_manager *bm,
struct dm_buffer *buf, struct dm_buffer *buf,
struct buffer_aux *aux, struct buffer_aux *aux,
struct dm_block_validator *v) const struct dm_block_validator *v)
{ {
if (unlikely(!aux->validator)) { if (unlikely(!aux->validator)) {
int r; int r;
...@@ -467,7 +467,7 @@ static int dm_bm_validate_buffer(struct dm_block_manager *bm, ...@@ -467,7 +467,7 @@ static int dm_bm_validate_buffer(struct dm_block_manager *bm,
return 0; return 0;
} }
int dm_bm_read_lock(struct dm_block_manager *bm, dm_block_t b, int dm_bm_read_lock(struct dm_block_manager *bm, dm_block_t b,
struct dm_block_validator *v, const struct dm_block_validator *v,
struct dm_block **result) struct dm_block **result)
{ {
struct buffer_aux *aux; struct buffer_aux *aux;
...@@ -500,7 +500,7 @@ int dm_bm_read_lock(struct dm_block_manager *bm, dm_block_t b, ...@@ -500,7 +500,7 @@ int dm_bm_read_lock(struct dm_block_manager *bm, dm_block_t b,
EXPORT_SYMBOL_GPL(dm_bm_read_lock); EXPORT_SYMBOL_GPL(dm_bm_read_lock);
int dm_bm_write_lock(struct dm_block_manager *bm, int dm_bm_write_lock(struct dm_block_manager *bm,
dm_block_t b, struct dm_block_validator *v, dm_block_t b, const struct dm_block_validator *v,
struct dm_block **result) struct dm_block **result)
{ {
struct buffer_aux *aux; struct buffer_aux *aux;
...@@ -536,7 +536,7 @@ int dm_bm_write_lock(struct dm_block_manager *bm, ...@@ -536,7 +536,7 @@ int dm_bm_write_lock(struct dm_block_manager *bm,
EXPORT_SYMBOL_GPL(dm_bm_write_lock); EXPORT_SYMBOL_GPL(dm_bm_write_lock);
int dm_bm_read_try_lock(struct dm_block_manager *bm, int dm_bm_read_try_lock(struct dm_block_manager *bm,
dm_block_t b, struct dm_block_validator *v, dm_block_t b, const struct dm_block_validator *v,
struct dm_block **result) struct dm_block **result)
{ {
struct buffer_aux *aux; struct buffer_aux *aux;
...@@ -569,7 +569,7 @@ int dm_bm_read_try_lock(struct dm_block_manager *bm, ...@@ -569,7 +569,7 @@ int dm_bm_read_try_lock(struct dm_block_manager *bm,
} }
int dm_bm_write_lock_zero(struct dm_block_manager *bm, int dm_bm_write_lock_zero(struct dm_block_manager *bm,
dm_block_t b, struct dm_block_validator *v, dm_block_t b, const struct dm_block_validator *v,
struct dm_block **result) struct dm_block **result)
{ {
int r; int r;
......
...@@ -51,12 +51,14 @@ dm_block_t dm_bm_nr_blocks(struct dm_block_manager *bm); ...@@ -51,12 +51,14 @@ dm_block_t dm_bm_nr_blocks(struct dm_block_manager *bm);
*/ */
struct dm_block_validator { struct dm_block_validator {
const char *name; const char *name;
void (*prepare_for_write)(struct dm_block_validator *v, struct dm_block *b, size_t block_size); void (*prepare_for_write)(const struct dm_block_validator *v,
struct dm_block *b, size_t block_size);
/* /*
* Return 0 if the checksum is valid or < 0 on error. * Return 0 if the checksum is valid or < 0 on error.
*/ */
int (*check)(struct dm_block_validator *v, struct dm_block *b, size_t block_size); int (*check)(const struct dm_block_validator *v,
struct dm_block *b, size_t block_size);
}; };
/*----------------------------------------------------------------*/ /*----------------------------------------------------------------*/
...@@ -73,11 +75,11 @@ struct dm_block_validator { ...@@ -73,11 +75,11 @@ struct dm_block_validator {
* written back to the disk sometime after dm_bm_unlock is called. * written back to the disk sometime after dm_bm_unlock is called.
*/ */
int dm_bm_read_lock(struct dm_block_manager *bm, dm_block_t b, int dm_bm_read_lock(struct dm_block_manager *bm, dm_block_t b,
struct dm_block_validator *v, const struct dm_block_validator *v,
struct dm_block **result); struct dm_block **result);
int dm_bm_write_lock(struct dm_block_manager *bm, dm_block_t b, int dm_bm_write_lock(struct dm_block_manager *bm, dm_block_t b,
struct dm_block_validator *v, const struct dm_block_validator *v,
struct dm_block **result); struct dm_block **result);
/* /*
...@@ -85,7 +87,7 @@ int dm_bm_write_lock(struct dm_block_manager *bm, dm_block_t b, ...@@ -85,7 +87,7 @@ int dm_bm_write_lock(struct dm_block_manager *bm, dm_block_t b,
* available immediately. * available immediately.
*/ */
int dm_bm_read_try_lock(struct dm_block_manager *bm, dm_block_t b, int dm_bm_read_try_lock(struct dm_block_manager *bm, dm_block_t b,
struct dm_block_validator *v, const struct dm_block_validator *v,
struct dm_block **result); struct dm_block **result);
/* /*
...@@ -93,7 +95,7 @@ int dm_bm_read_try_lock(struct dm_block_manager *bm, dm_block_t b, ...@@ -93,7 +95,7 @@ int dm_bm_read_try_lock(struct dm_block_manager *bm, dm_block_t b,
* overwrite the block completely. It saves a disk read. * overwrite the block completely. It saves a disk read.
*/ */
int dm_bm_write_lock_zero(struct dm_block_manager *bm, dm_block_t b, int dm_bm_write_lock_zero(struct dm_block_manager *bm, dm_block_t b,
struct dm_block_validator *v, const struct dm_block_validator *v,
struct dm_block **result); struct dm_block **result);
void dm_bm_unlock(struct dm_block *b); void dm_bm_unlock(struct dm_block *b);
......
...@@ -138,7 +138,7 @@ static inline uint64_t value64(struct btree_node *n, uint32_t index) ...@@ -138,7 +138,7 @@ static inline uint64_t value64(struct btree_node *n, uint32_t index)
*/ */
int lower_bound(struct btree_node *n, uint64_t key); int lower_bound(struct btree_node *n, uint64_t key);
extern struct dm_block_validator btree_node_validator; extern const struct dm_block_validator btree_node_validator;
/* /*
* Value type for upper levels of multi-level btrees. * Value type for upper levels of multi-level btrees.
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#define BTREE_CSUM_XOR 121107 #define BTREE_CSUM_XOR 121107
static void node_prepare_for_write(struct dm_block_validator *v, static void node_prepare_for_write(const struct dm_block_validator *v,
struct dm_block *b, struct dm_block *b,
size_t block_size) size_t block_size)
{ {
...@@ -29,7 +29,7 @@ static void node_prepare_for_write(struct dm_block_validator *v, ...@@ -29,7 +29,7 @@ static void node_prepare_for_write(struct dm_block_validator *v,
BTREE_CSUM_XOR)); BTREE_CSUM_XOR));
} }
static int node_check(struct dm_block_validator *v, static int node_check(const struct dm_block_validator *v,
struct dm_block *b, struct dm_block *b,
size_t block_size) size_t block_size)
{ {
...@@ -81,7 +81,7 @@ static int node_check(struct dm_block_validator *v, ...@@ -81,7 +81,7 @@ static int node_check(struct dm_block_validator *v,
return 0; return 0;
} }
struct dm_block_validator btree_node_validator = { const struct dm_block_validator btree_node_validator = {
.name = "btree_node", .name = "btree_node",
.prepare_for_write = node_prepare_for_write, .prepare_for_write = node_prepare_for_write,
.check = node_check .check = node_check
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
*/ */
#define INDEX_CSUM_XOR 160478 #define INDEX_CSUM_XOR 160478
static void index_prepare_for_write(struct dm_block_validator *v, static void index_prepare_for_write(const struct dm_block_validator *v,
struct dm_block *b, struct dm_block *b,
size_t block_size) size_t block_size)
{ {
...@@ -34,7 +34,7 @@ static void index_prepare_for_write(struct dm_block_validator *v, ...@@ -34,7 +34,7 @@ static void index_prepare_for_write(struct dm_block_validator *v,
INDEX_CSUM_XOR)); INDEX_CSUM_XOR));
} }
static int index_check(struct dm_block_validator *v, static int index_check(const struct dm_block_validator *v,
struct dm_block *b, struct dm_block *b,
size_t block_size) size_t block_size)
{ {
...@@ -59,7 +59,7 @@ static int index_check(struct dm_block_validator *v, ...@@ -59,7 +59,7 @@ static int index_check(struct dm_block_validator *v,
return 0; return 0;
} }
static struct dm_block_validator index_validator = { static const struct dm_block_validator index_validator = {
.name = "index", .name = "index",
.prepare_for_write = index_prepare_for_write, .prepare_for_write = index_prepare_for_write,
.check = index_check .check = index_check
...@@ -72,7 +72,7 @@ static struct dm_block_validator index_validator = { ...@@ -72,7 +72,7 @@ static struct dm_block_validator index_validator = {
*/ */
#define BITMAP_CSUM_XOR 240779 #define BITMAP_CSUM_XOR 240779
static void dm_bitmap_prepare_for_write(struct dm_block_validator *v, static void dm_bitmap_prepare_for_write(const struct dm_block_validator *v,
struct dm_block *b, struct dm_block *b,
size_t block_size) size_t block_size)
{ {
...@@ -84,7 +84,7 @@ static void dm_bitmap_prepare_for_write(struct dm_block_validator *v, ...@@ -84,7 +84,7 @@ static void dm_bitmap_prepare_for_write(struct dm_block_validator *v,
BITMAP_CSUM_XOR)); BITMAP_CSUM_XOR));
} }
static int dm_bitmap_check(struct dm_block_validator *v, static int dm_bitmap_check(const struct dm_block_validator *v,
struct dm_block *b, struct dm_block *b,
size_t block_size) size_t block_size)
{ {
...@@ -109,7 +109,7 @@ static int dm_bitmap_check(struct dm_block_validator *v, ...@@ -109,7 +109,7 @@ static int dm_bitmap_check(struct dm_block_validator *v,
return 0; return 0;
} }
static struct dm_block_validator dm_sm_bitmap_validator = { static const struct dm_block_validator dm_sm_bitmap_validator = {
.name = "sm_bitmap", .name = "sm_bitmap",
.prepare_for_write = dm_bitmap_prepare_for_write, .prepare_for_write = dm_bitmap_prepare_for_write,
.check = dm_bitmap_check, .check = dm_bitmap_check,
......
...@@ -237,7 +237,7 @@ int dm_tm_commit(struct dm_transaction_manager *tm, struct dm_block *root) ...@@ -237,7 +237,7 @@ int dm_tm_commit(struct dm_transaction_manager *tm, struct dm_block *root)
EXPORT_SYMBOL_GPL(dm_tm_commit); EXPORT_SYMBOL_GPL(dm_tm_commit);
int dm_tm_new_block(struct dm_transaction_manager *tm, int dm_tm_new_block(struct dm_transaction_manager *tm,
struct dm_block_validator *v, const struct dm_block_validator *v,
struct dm_block **result) struct dm_block **result)
{ {
int r; int r;
...@@ -266,7 +266,7 @@ int dm_tm_new_block(struct dm_transaction_manager *tm, ...@@ -266,7 +266,7 @@ int dm_tm_new_block(struct dm_transaction_manager *tm,
} }
static int __shadow_block(struct dm_transaction_manager *tm, dm_block_t orig, static int __shadow_block(struct dm_transaction_manager *tm, dm_block_t orig,
struct dm_block_validator *v, const struct dm_block_validator *v,
struct dm_block **result) struct dm_block **result)
{ {
int r; int r;
...@@ -306,7 +306,7 @@ static int __shadow_block(struct dm_transaction_manager *tm, dm_block_t orig, ...@@ -306,7 +306,7 @@ static int __shadow_block(struct dm_transaction_manager *tm, dm_block_t orig,
} }
int dm_tm_shadow_block(struct dm_transaction_manager *tm, dm_block_t orig, int dm_tm_shadow_block(struct dm_transaction_manager *tm, dm_block_t orig,
struct dm_block_validator *v, struct dm_block **result, const struct dm_block_validator *v, struct dm_block **result,
int *inc_children) int *inc_children)
{ {
int r; int r;
...@@ -331,7 +331,7 @@ int dm_tm_shadow_block(struct dm_transaction_manager *tm, dm_block_t orig, ...@@ -331,7 +331,7 @@ int dm_tm_shadow_block(struct dm_transaction_manager *tm, dm_block_t orig,
EXPORT_SYMBOL_GPL(dm_tm_shadow_block); EXPORT_SYMBOL_GPL(dm_tm_shadow_block);
int dm_tm_read_lock(struct dm_transaction_manager *tm, dm_block_t b, int dm_tm_read_lock(struct dm_transaction_manager *tm, dm_block_t b,
struct dm_block_validator *v, const struct dm_block_validator *v,
struct dm_block **blk) struct dm_block **blk)
{ {
if (tm->is_clone) { if (tm->is_clone) {
......
...@@ -64,7 +64,7 @@ int dm_tm_commit(struct dm_transaction_manager *tm, struct dm_block *superblock) ...@@ -64,7 +64,7 @@ int dm_tm_commit(struct dm_transaction_manager *tm, struct dm_block *superblock)
* Zeroes the new block and returns with write lock held. * Zeroes the new block and returns with write lock held.
*/ */
int dm_tm_new_block(struct dm_transaction_manager *tm, int dm_tm_new_block(struct dm_transaction_manager *tm,
struct dm_block_validator *v, const struct dm_block_validator *v,
struct dm_block **result); struct dm_block **result);
/* /*
...@@ -84,7 +84,7 @@ int dm_tm_new_block(struct dm_transaction_manager *tm, ...@@ -84,7 +84,7 @@ int dm_tm_new_block(struct dm_transaction_manager *tm,
* it locked when you call this. * it locked when you call this.
*/ */
int dm_tm_shadow_block(struct dm_transaction_manager *tm, dm_block_t orig, int dm_tm_shadow_block(struct dm_transaction_manager *tm, dm_block_t orig,
struct dm_block_validator *v, const struct dm_block_validator *v,
struct dm_block **result, int *inc_children); struct dm_block **result, int *inc_children);
/* /*
...@@ -92,7 +92,7 @@ int dm_tm_shadow_block(struct dm_transaction_manager *tm, dm_block_t orig, ...@@ -92,7 +92,7 @@ int dm_tm_shadow_block(struct dm_transaction_manager *tm, dm_block_t orig,
* on it outstanding then it'll block. * on it outstanding then it'll block.
*/ */
int dm_tm_read_lock(struct dm_transaction_manager *tm, dm_block_t b, int dm_tm_read_lock(struct dm_transaction_manager *tm, dm_block_t b,
struct dm_block_validator *v, const struct dm_block_validator *v,
struct dm_block **result); struct dm_block **result);
void dm_tm_unlock(struct dm_transaction_manager *tm, struct dm_block *b); void dm_tm_unlock(struct dm_transaction_manager *tm, struct dm_block *b);
......
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