dm zoned: fix the search for the secondary superblock

If the primary superblock of a volume formatted with dmzadm is
corrupted, dmz_lookup_secondary_sb() fails to find the valid secondary
one in two cases:

 - After the first iteration, sb[1].block is advanced to the next zone,
   but sb[1].zone is set to the zone that was just examined.  Unless
   the superblock is in the first zone that is searched, dmz_check_sb()
   then rejects it because it does not appear to be in the right zone.
   With 256 MiB zones, this affects volumes larger than about 8.8 TB,
   which need more than one zone per metadata set:

     Invalid superblock position (is 131072 expected 65536)

 - The number of random zones is used as the limit.  With multiple
   devices, the metadata is on the cache device instead, and nothing is
   searched at all if the zoned devices have no random zones.  Commit
   b38c0ad57f8e ("dm zoned: Fix metadata zone size check") fixed the
   same problem in dmz_check_sb().

Set the block and the zone together at the start of each iteration, and
use the number of cache zones if there are multiple devices.

This depends on the previous patch, which rejects superblocks that must
not be used for recovery.

Fixes: a92fbc446d1a ("dm zoned: convert to xarray")
Fixes: 34f5affd04c4 ("dm zoned: separate random and cache zones")
Cc: stable@vger.kernel.org
Signed-off-by: Yingjie Wang <x-professor@outlook.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
1 file changed