Linux Device Mapper development
 help / color / mirror / Atom feed
From: Mikulas Patocka <mpatocka@redhat.com>
To: Mikulas Patocka <mpatocka@redhat.com>,
	Mike Snitzer <msnitzer@redhat.com>,
	"Alasdair G. Kergon" <agk@redhat.com>,
	Milan Broz <mbroz@redhat.com>
Cc: dm-devel@redhat.com
Subject: [patch 6/8] dm-integrity: use version 2 for separate metadata
Date: Tue, 01 May 2018 15:55:22 +0200	[thread overview]
Message-ID: <20180501135605.494171664@debian.vm> (raw)
In-Reply-To: 20180501135516.961417937@debian.vm

[-- Attachment #1: dm-integrity-sb-version.patch --]
[-- Type: text/plain, Size: 1901 bytes --]

Use version "2" in the superblock when data and metadata devices are
separate, so that the device is no accidentally read by older kernel
version.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>

---
 drivers/md/dm-integrity.c |   16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

Index: linux-2.6/drivers/md/dm-integrity.c
===================================================================
--- linux-2.6.orig/drivers/md/dm-integrity.c	2018-05-01 04:34:46.000000000 +0200
+++ linux-2.6/drivers/md/dm-integrity.c	2018-05-01 04:34:46.000000000 +0200
@@ -44,7 +44,8 @@
  */
 
 #define SB_MAGIC			"integrt"
-#define SB_VERSION			1
+#define SB_VERSION_1			1
+#define SB_VERSION_2			2
 #define SB_SECTORS			8
 #define MAX_SECTORS_PER_BLOCK		8
 
@@ -406,6 +407,14 @@ static void wraparound_section(struct dm
 		*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)
 {
 	struct dm_io_request io_req;
@@ -2380,7 +2389,6 @@ static int initialize_superblock(struct
 
 	memset(ic->sb, 0, SB_SECTORS << SECTOR_SHIFT);
 	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->log2_sectors_per_block = __ffs(ic->sectors_per_block);
 	if (ic->journal_mac_alg.alg_string)
@@ -2437,6 +2445,8 @@ try_smaller_buffer:
 
 	ic->sb->provided_data_sectors = cpu_to_le64(ic->provided_data_sectors);
 
+	sb_set_version(ic);
+
 	return 0;
 }
 
@@ -3133,7 +3143,7 @@ static int dm_integrity_ctr(struct dm_ta
 			should_write_sb = true;
 	}
 
-	if (ic->sb->version != SB_VERSION) {
+	if (!ic->sb->version || ic->sb->version > SB_VERSION_2) {
 		r = -EINVAL;
 		ti->error = "Unknown version";
 		goto bad;

  parent reply	other threads:[~2018-05-01 13:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-01 13:55 [patch 0/8] dm-integrity patches Mikulas Patocka
2018-05-01 13:55 ` [patch 1/8] dm-integrity: use kvfree Mikulas Patocka
2018-05-01 13:55 ` [patch 2/8] dm-integrity: change the variable suspending from bool to int Mikulas Patocka
2018-05-01 13:55 ` [patch 3/8] dm-integrity: report size in the status Mikulas Patocka
2018-05-01 13:55 ` [patch 4/8] dm-integrity: add ic->start in get_data_sector Mikulas Patocka
2018-05-01 13:55 ` [patch 5/8] dm-integrity: allow external devices Mikulas Patocka
2018-05-01 13:55 ` Mikulas Patocka [this message]
2018-05-01 13:55 ` [patch 7/8] dm-integrity: flush journal on suspend when using separate device Mikulas Patocka
2018-05-01 13:55 ` [patch 8/8] dm-integrity: recalculate checksums Mikulas Patocka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180501135605.494171664@debian.vm \
    --to=mpatocka@redhat.com \
    --cc=agk@redhat.com \
    --cc=dm-devel@redhat.com \
    --cc=mbroz@redhat.com \
    --cc=msnitzer@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox