aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVishal Verma <vishal.l.verma@intel.com>2015-07-29 16:58:08 -0400
committerDan Williams <dan.j.williams@intel.com>2015-08-14 13:43:04 -0400
commitab45e7632717b811e0786e46ca5ad279cb731b66 (patch)
tree84a669c9fb6c9889ba7b17976acf5b50c08bbd54
parentfbde1414acc0440024083bf0c391b259bcfc4826 (diff)
libnvdimm, btt: consolidate arena validation
Use arena_is_valid as a common routine for checking the validity of an info block from both discover_arenas, and nd_btt_probe. As a result, don't check for validity of the BTT's UUID, and lbasize. The checksum in the BTT info block guarantees self-consistency, and when we're called from nd_btt_probe, we don't have a valid uuid or lbasize available to check against. Also cleanup to return a bool instead of an int. Signed-off-by: Vishal Verma <vishal.l.verma@intel.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
-rw-r--r--drivers/nvdimm/btt.c28
-rw-r--r--drivers/nvdimm/btt.h3
-rw-r--r--drivers/nvdimm/btt_devs.c42
3 files changed, 37 insertions, 36 deletions
diff --git a/drivers/nvdimm/btt.c b/drivers/nvdimm/btt.c
index 87e6a96a6c19..6567746aa315 100644
--- a/drivers/nvdimm/btt.c
+++ b/drivers/nvdimm/btt.c
@@ -583,32 +583,6 @@ static void free_arenas(struct btt *btt)
583} 583}
584 584
585/* 585/*
586 * This function checks if the metadata layout is valid and error free
587 */
588static int arena_is_valid(struct nd_btt *nd_btt, struct btt_sb *super)
589{
590 u64 checksum;
591
592 if (memcmp(super->uuid, nd_btt->uuid, 16))
593 return 0;
594
595 checksum = le64_to_cpu(super->checksum);
596 super->checksum = 0;
597 if (checksum != nd_btt_sb_checksum(super))
598 return 0;
599 super->checksum = cpu_to_le64(checksum);
600
601 if (nd_btt->lbasize != le32_to_cpu(super->external_lbasize))
602 return 0;
603
604 /* TODO: figure out action for this */
605 if ((le32_to_cpu(super->flags) & IB_FLAG_ERROR_MASK) != 0)
606 dev_info(&nd_btt->dev, "Found arena with an error flag\n");
607
608 return 1;
609}
610
611/*
612 * This function reads an existing valid btt superblock and 586 * This function reads an existing valid btt superblock and
613 * populates the corresponding arena_info struct 587 * populates the corresponding arena_info struct
614 */ 588 */
@@ -665,7 +639,7 @@ static int discover_arenas(struct btt *btt)
665 if (ret) 639 if (ret)
666 goto out; 640 goto out;
667 641
668 if (!arena_is_valid(btt->nd_btt, super)) { 642 if (!nd_btt_arena_is_valid(btt->nd_btt, super)) {
669 if (remaining == btt->rawsize) { 643 if (remaining == btt->rawsize) {
670 btt->init_state = INIT_NOTFOUND; 644 btt->init_state = INIT_NOTFOUND;
671 dev_info(to_dev(arena), "No existing arenas\n"); 645 dev_info(to_dev(arena), "No existing arenas\n");
diff --git a/drivers/nvdimm/btt.h b/drivers/nvdimm/btt.h
index 75b0d80a6bd9..b2f8651e5395 100644
--- a/drivers/nvdimm/btt.h
+++ b/drivers/nvdimm/btt.h
@@ -182,4 +182,7 @@ struct btt {
182 int init_state; 182 int init_state;
183 int num_arenas; 183 int num_arenas;
184}; 184};
185
186bool nd_btt_arena_is_valid(struct nd_btt *nd_btt, struct btt_sb *super);
187
185#endif 188#endif
diff --git a/drivers/nvdimm/btt_devs.c b/drivers/nvdimm/btt_devs.c
index 6ac8c0fea3ec..18e0663e922c 100644
--- a/drivers/nvdimm/btt_devs.c
+++ b/drivers/nvdimm/btt_devs.c
@@ -342,6 +342,38 @@ struct device *nd_btt_create(struct nd_region *nd_region)
342 return dev; 342 return dev;
343} 343}
344 344
345/**
346 * nd_btt_arena_is_valid - check if the metadata layout is valid
347 * @nd_btt: device with BTT geometry and backing device info
348 * @super: pointer to the arena's info block being tested
349 *
350 * Check consistency of the btt info block with itself by validating
351 * the checksum.
352 *
353 * Returns:
354 * false for an invalid info block, true for a valid one
355 */
356bool nd_btt_arena_is_valid(struct nd_btt *nd_btt, struct btt_sb *super)
357{
358 u64 checksum;
359
360 if (memcmp(super->signature, BTT_SIG, BTT_SIG_LEN) != 0)
361 return false;
362
363 checksum = le64_to_cpu(super->checksum);
364 super->checksum = 0;
365 if (checksum != nd_btt_sb_checksum(super))
366 return false;
367 super->checksum = cpu_to_le64(checksum);
368
369 /* TODO: figure out action for this */
370 if ((le32_to_cpu(super->flags) & IB_FLAG_ERROR_MASK) != 0)
371 dev_info(&nd_btt->dev, "Found arena with an error flag\n");
372
373 return true;
374}
375EXPORT_SYMBOL(nd_btt_arena_is_valid);
376
345/* 377/*
346 * nd_btt_sb_checksum: compute checksum for btt info block 378 * nd_btt_sb_checksum: compute checksum for btt info block
347 * 379 *
@@ -364,8 +396,6 @@ EXPORT_SYMBOL(nd_btt_sb_checksum);
364static int __nd_btt_probe(struct nd_btt *nd_btt, 396static int __nd_btt_probe(struct nd_btt *nd_btt,
365 struct nd_namespace_common *ndns, struct btt_sb *btt_sb) 397 struct nd_namespace_common *ndns, struct btt_sb *btt_sb)
366{ 398{
367 u64 checksum;
368
369 if (!btt_sb || !ndns || !nd_btt) 399 if (!btt_sb || !ndns || !nd_btt)
370 return -ENODEV; 400 return -ENODEV;
371 401
@@ -375,14 +405,8 @@ static int __nd_btt_probe(struct nd_btt *nd_btt,
375 if (nvdimm_namespace_capacity(ndns) < SZ_16M) 405 if (nvdimm_namespace_capacity(ndns) < SZ_16M)
376 return -ENXIO; 406 return -ENXIO;
377 407
378 if (memcmp(btt_sb->signature, BTT_SIG, BTT_SIG_LEN) != 0) 408 if (!nd_btt_arena_is_valid(nd_btt, btt_sb))
379 return -ENODEV;
380
381 checksum = le64_to_cpu(btt_sb->checksum);
382 btt_sb->checksum = 0;
383 if (checksum != nd_btt_sb_checksum(btt_sb))
384 return -ENODEV; 409 return -ENODEV;
385 btt_sb->checksum = cpu_to_le64(checksum);
386 410
387 nd_btt->lbasize = le32_to_cpu(btt_sb->external_lbasize); 411 nd_btt->lbasize = le32_to_cpu(btt_sb->external_lbasize);
388 nd_btt->uuid = kmemdup(btt_sb->uuid, 16, GFP_KERNEL); 412 nd_btt->uuid = kmemdup(btt_sb->uuid, 16, GFP_KERNEL);