Commit 1f9fc0b8 authored by Mikulas Patocka's avatar Mikulas Patocka Committed by Mike Snitzer

dm integrity: use version 2 for separate metadata

Use version "2" in the superblock when data and metadata devices are
separate, so that the device is not accidentally read by older kernel
version.
Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
parent 356d9d52
...@@ -44,7 +44,8 @@ ...@@ -44,7 +44,8 @@
*/ */
#define SB_MAGIC "integrt" #define SB_MAGIC "integrt"
#define SB_VERSION 1 #define SB_VERSION_1 1
#define SB_VERSION_2 2
#define SB_SECTORS 8 #define SB_SECTORS 8
#define MAX_SECTORS_PER_BLOCK 8 #define MAX_SECTORS_PER_BLOCK 8
...@@ -414,6 +415,14 @@ static void wraparound_section(struct dm_integrity_c *ic, unsigned *sec_ptr) ...@@ -414,6 +415,14 @@ static void wraparound_section(struct dm_integrity_c *ic, unsigned *sec_ptr)
*sec_ptr -= ic->journal_sections; *sec_ptr -= ic->journal_sections;
} }
static void sb_set_version(struct dm_integrity_c *ic)
{
if (ic->meta_dev)
ic->sb->version = SB_VERSION_2;
else
ic->sb->version = SB_VERSION_1;
}
static int sync_rw_sb(struct dm_integrity_c *ic, int op, int op_flags) static int sync_rw_sb(struct dm_integrity_c *ic, int op, int op_flags)
{ {
struct dm_io_request io_req; struct dm_io_request io_req;
...@@ -2432,7 +2441,6 @@ static int initialize_superblock(struct dm_integrity_c *ic, unsigned journal_sec ...@@ -2432,7 +2441,6 @@ static int initialize_superblock(struct dm_integrity_c *ic, unsigned journal_sec
memset(ic->sb, 0, SB_SECTORS << SECTOR_SHIFT); memset(ic->sb, 0, SB_SECTORS << SECTOR_SHIFT);
memcpy(ic->sb->magic, SB_MAGIC, 8); memcpy(ic->sb->magic, SB_MAGIC, 8);
ic->sb->version = SB_VERSION;
ic->sb->integrity_tag_size = cpu_to_le16(ic->tag_size); ic->sb->integrity_tag_size = cpu_to_le16(ic->tag_size);
ic->sb->log2_sectors_per_block = __ffs(ic->sectors_per_block); ic->sb->log2_sectors_per_block = __ffs(ic->sectors_per_block);
if (ic->journal_mac_alg.alg_string) if (ic->journal_mac_alg.alg_string)
...@@ -2489,6 +2497,8 @@ static int initialize_superblock(struct dm_integrity_c *ic, unsigned journal_sec ...@@ -2489,6 +2497,8 @@ static int initialize_superblock(struct dm_integrity_c *ic, unsigned journal_sec
ic->sb->provided_data_sectors = cpu_to_le64(ic->provided_data_sectors); ic->sb->provided_data_sectors = cpu_to_le64(ic->provided_data_sectors);
sb_set_version(ic);
return 0; return 0;
} }
...@@ -3193,7 +3203,7 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned argc, char **argv) ...@@ -3193,7 +3203,7 @@ static int dm_integrity_ctr(struct dm_target *ti, unsigned argc, char **argv)
should_write_sb = true; should_write_sb = true;
} }
if (ic->sb->version != SB_VERSION) { if (!ic->sb->version || ic->sb->version > SB_VERSION_2) {
r = -EINVAL; r = -EINVAL;
ti->error = "Unknown version"; ti->error = "Unknown version";
goto bad; goto bad;
......
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