/* Zone information array */
struct xarray zones;
- struct dmz_sb sb[3];
+ struct dmz_sb sb[2];
unsigned int mblk_primary;
unsigned int sb_version;
u64 sb_gen;
/*
* Check super block.
*/
-static int dmz_check_sb(struct dmz_metadata *zmd, unsigned int set)
+static int dmz_check_sb(struct dmz_metadata *zmd, struct dmz_sb *dsb,
+ bool tertiary)
{
- struct dmz_super *sb = zmd->sb[set].sb;
- struct dmz_dev *dev = zmd->sb[set].dev;
+ struct dmz_super *sb = dsb->sb;
+ struct dmz_dev *dev = dsb->dev;
unsigned int nr_meta_zones, nr_data_zones;
u32 crc, stored_crc;
u64 gen;
DMZ_META_VER, zmd->sb_version);
return -EINVAL;
}
- if ((zmd->sb_version < 1) && (set == 2)) {
+ if (zmd->sb_version < 2 && tertiary) {
dmz_dev_err(dev, "Tertiary superblocks are not supported");
return -EINVAL;
}
return -ENXIO;
}
- if (set == 2) {
+ if (tertiary) {
/*
* Generation number should be 0, but it doesn't
* really matter if it isn't.
/*
* Read the first or second super block from disk.
*/
-static int dmz_read_sb(struct dmz_metadata *zmd, unsigned int set)
+static int dmz_read_sb(struct dmz_metadata *zmd, struct dmz_sb *sb, int set)
{
dmz_zmd_debug(zmd, "read superblock set %d dev %s block %llu",
- set, zmd->sb[set].dev->name,
- zmd->sb[set].block);
+ set, sb->dev->name, sb->block);
- return dmz_rdwr_block(zmd->sb[set].dev, REQ_OP_READ,
- zmd->sb[set].block, zmd->sb[set].mblk->page);
+ return dmz_rdwr_block(sb->dev, REQ_OP_READ,
+ sb->block, sb->mblk->page);
}
/*
zmd->sb[1].zone = dmz_get(zmd, zone_id + 1);
zmd->sb[1].dev = zmd->sb[0].dev;
for (i = 1; i < zmd->nr_rnd_zones; i++) {
- if (dmz_read_sb(zmd, 1) != 0)
+ if (dmz_read_sb(zmd, &zmd->sb[1], 1) != 0)
break;
if (le32_to_cpu(zmd->sb[1].sb->magic) == DMZ_MAGIC)
return 0;
}
/*
- * Read the first or second super block from disk.
+ * Read a super block from disk.
*/
-static int dmz_get_sb(struct dmz_metadata *zmd, unsigned int set)
+static int dmz_get_sb(struct dmz_metadata *zmd, struct dmz_sb *sb, int set)
{
struct dmz_mblock *mblk;
int ret;
if (!mblk)
return -ENOMEM;
- zmd->sb[set].mblk = mblk;
- zmd->sb[set].sb = mblk->data;
+ sb->mblk = mblk;
+ sb->sb = mblk->data;
/* Read super block */
- ret = dmz_read_sb(zmd, set);
+ ret = dmz_read_sb(zmd, sb, set);
if (ret) {
dmz_free_mblock(zmd, mblk);
- zmd->sb[set].mblk = NULL;
+ sb->mblk = NULL;
return ret;
}
/* Read and check the primary super block */
zmd->sb[0].block = dmz_start_block(zmd, zmd->sb[0].zone);
zmd->sb[0].dev = dmz_zone_to_dev(zmd, zmd->sb[0].zone);
- ret = dmz_get_sb(zmd, 0);
+ ret = dmz_get_sb(zmd, &zmd->sb[0], 0);
if (ret) {
dmz_dev_err(zmd->sb[0].dev, "Read primary super block failed");
return ret;
}
- ret = dmz_check_sb(zmd, 0);
+ ret = dmz_check_sb(zmd, &zmd->sb[0], false);
/* Read and check secondary super block */
if (ret == 0) {
}
zmd->sb[1].block = dmz_start_block(zmd, zmd->sb[1].zone);
zmd->sb[1].dev = zmd->sb[0].dev;
- ret = dmz_get_sb(zmd, 1);
+ ret = dmz_get_sb(zmd, &zmd->sb[1], 1);
} else
ret = dmz_lookup_secondary_sb(zmd);
return ret;
}
- ret = dmz_check_sb(zmd, 1);
+ ret = dmz_check_sb(zmd, &zmd->sb[1], false);
if (ret == 0)
sb_good[1] = true;
"Using super block %u (gen %llu)",
zmd->mblk_primary, zmd->sb_gen);
- if ((zmd->sb_version > 1) && zmd->sb[2].zone) {
- zmd->sb[2].block = dmz_start_block(zmd, zmd->sb[2].zone);
- zmd->sb[2].dev = dmz_zone_to_dev(zmd, zmd->sb[2].zone);
- ret = dmz_get_sb(zmd, 2);
- if (ret) {
- dmz_dev_err(zmd->sb[2].dev,
- "Read tertiary super block failed");
- return ret;
+ if (zmd->sb_version > 1) {
+ int i;
+ struct dmz_sb *sb;
+
+ sb = kzalloc(sizeof(struct dmz_sb), GFP_KERNEL);
+ if (!sb)
+ return -ENOMEM;
+ for (i = 1; i < zmd->nr_devs; i++) {
+ sb->block = 0;
+ sb->zone = dmz_get(zmd, zmd->dev[i].zone_offset);
+ sb->dev = &zmd->dev[i];
+ if (!dmz_is_meta(sb->zone)) {
+ dmz_dev_err(sb->dev,
+ "Tertiary super block zone %u not marked as metadata zone",
+ sb->zone->id);
+ ret = -EINVAL;
+ goto out_kfree;
+ }
+ ret = dmz_get_sb(zmd, sb, i + 1);
+ if (ret) {
+ dmz_dev_err(sb->dev,
+ "Read tertiary super block failed");
+ dmz_free_mblock(zmd, sb->mblk);
+ goto out_kfree;
+ }
+ ret = dmz_check_sb(zmd, sb, true);
+ dmz_free_mblock(zmd, sb->mblk);
+ if (ret == -EINVAL)
+ goto out_kfree;
}
- ret = dmz_check_sb(zmd, 2);
- if (ret == -EINVAL)
- return ret;
+ out_kfree:
+ kfree(sb);
}
- return 0;
+ return ret;
}
/*
zmd->sb[0].zone = zone;
}
}
- if (zmd->nr_devs > 1 && !zmd->sb[2].zone) {
- /* Tertiary superblock zone */
- zmd->sb[2].zone = zone;
+ if (zmd->nr_devs > 1 && num == 0) {
+ /*
+ * Tertiary superblock zones are always at the
+ * start of the zoned devices, so mark them
+ * as metadata zone.
+ */
+ set_bit(DMZ_META, &zone->flags);
}
}
-
return 0;
}
}
set_bit(DMZ_META, &zone->flags);
}
- if (zmd->sb[2].zone) {
- zone = dmz_get(zmd, zmd->sb[2].zone->id);
- if (!zone) {
- dmz_zmd_err(zmd,
- "Tertiary metadata zone not present");
- ret = -ENXIO;
- goto err;
- }
- set_bit(DMZ_META, &zone->flags);
- }
/* Load mapping table */
ret = dmz_load_mapping(zmd);
if (ret)