diff mbox

[09/24] dm cache metadata: check the metadata version when reading the superblock

Message ID 1382639437-27007-10-git-send-email-snitzer@redhat.com (mailing list archive)
State Superseded, archived
Delegated to: Mike Snitzer
Headers show

Commit Message

Mike Snitzer Oct. 24, 2013, 6:30 p.m. UTC
From: Joe Thornber <ejt@redhat.com>

Need to check the version to verify on-disk metadata is supported.

Signed-off-by: Joe Thornber <ejt@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
---
 drivers/md/dm-cache-metadata.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

Comments

Alasdair G Kergon Oct. 25, 2013, 5:07 p.m. UTC | #1
On Thu, Oct 24, 2013 at 02:30:22PM -0400, Mike Snitzer wrote:
> From: Joe Thornber <ejt@redhat.com>

> +++ b/drivers/md/dm-cache-metadata.c
> @@ -20,7 +20,13 @@

> + * defines a range of metadata versions that this module can handle.

> +{
> +	uint32_t metadata_version = le32_to_cpu(disk_super->version);

+

> +	if (metadata_version < MIN_CACHE_VERSION || metadata_version > MAX_CACHE_VERSION) {
> +		DMERR("kernel does not support this version of cache metadata (%u)",
> +		      metadata_version);

- Also state the range supported?
   "Cache metadata version %u found, but only versions between %u and %u supported."

Alasdair

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
Mike Snitzer Oct. 25, 2013, 7:53 p.m. UTC | #2
On Fri, Oct 25 2013 at  1:07pm -0400,
Alasdair G Kergon <agk@redhat.com> wrote:

> On Thu, Oct 24, 2013 at 02:30:22PM -0400, Mike Snitzer wrote:
> > From: Joe Thornber <ejt@redhat.com>
> 
> > +++ b/drivers/md/dm-cache-metadata.c
> > @@ -20,7 +20,13 @@
> 
> > + * defines a range of metadata versions that this module can handle.
> 
> > +{
> > +	uint32_t metadata_version = le32_to_cpu(disk_super->version);
> 
> +
> 
> > +	if (metadata_version < MIN_CACHE_VERSION || metadata_version > MAX_CACHE_VERSION) {
> > +		DMERR("kernel does not support this version of cache metadata (%u)",
> > +		      metadata_version);
> 
> - Also state the range supported?
>    "Cache metadata version %u found, but only versions between %u and %u supported."

Done.

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
diff mbox

Patch

diff --git a/drivers/md/dm-cache-metadata.c b/drivers/md/dm-cache-metadata.c
index 2262b4e..c409c1a 100644
--- a/drivers/md/dm-cache-metadata.c
+++ b/drivers/md/dm-cache-metadata.c
@@ -20,7 +20,13 @@ 
 
 #define CACHE_SUPERBLOCK_MAGIC 06142003
 #define CACHE_SUPERBLOCK_LOCATION 0
-#define CACHE_VERSION 1
+
+/*
+ * defines a range of metadata versions that this module can handle.
+ */
+#define MIN_CACHE_VERSION 1
+#define MAX_CACHE_VERSION 1
+
 #define CACHE_METADATA_CACHE_SIZE 64
 
 /*
@@ -134,6 +140,18 @@  static void sb_prepare_for_write(struct dm_block_validator *v,
 						      SUPERBLOCK_CSUM_XOR));
 }
 
+static int check_metadata_version(struct cache_disk_superblock *disk_super)
+{
+	uint32_t metadata_version = le32_to_cpu(disk_super->version);
+	if (metadata_version < MIN_CACHE_VERSION || metadata_version > MAX_CACHE_VERSION) {
+		DMERR("kernel does not support this version of cache metadata (%u)",
+		      metadata_version);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
 static int sb_check(struct dm_block_validator *v,
 		    struct dm_block *b,
 		    size_t sb_block_size)
@@ -164,7 +182,7 @@  static int sb_check(struct dm_block_validator *v,
 		return -EILSEQ;
 	}
 
-	return 0;
+	return check_metadata_version(disk_super);
 }
 
 static struct dm_block_validator sb_validator = {
@@ -270,7 +288,7 @@  static int __write_initial_superblock(struct dm_cache_metadata *cmd)
 	disk_super->flags = 0;
 	memset(disk_super->uuid, 0, sizeof(disk_super->uuid));
 	disk_super->magic = cpu_to_le64(CACHE_SUPERBLOCK_MAGIC);
-	disk_super->version = cpu_to_le32(CACHE_VERSION);
+	disk_super->version = cpu_to_le32(MAX_CACHE_VERSION);
 	memset(disk_super->policy_name, 0, sizeof(disk_super->policy_name));
 	memset(disk_super->policy_version, 0, sizeof(disk_super->policy_version));
 	disk_super->policy_hint_size = 0;