]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
DDF: add sanity checks in compare_super_ddf
authormwilck@arcor.de <mwilck@arcor.de>
Fri, 1 Mar 2013 22:28:31 +0000 (23:28 +0100)
committerNeilBrown <neilb@suse.de>
Mon, 4 Mar 2013 05:14:17 +0000 (16:14 +1100)
Besides container GUID, also check seqnum, physical and virtual
disk numbers, and check match between local and global sections.

Signed-off-by: Martin Wilck <mwilck@arcor.de>
Signed-off-by: NeilBrown <neilb@suse.de>
super-ddf.c

index 81649d4577b882c7454fec0c4a39cae4e6af9d42..8af4fba82c868d164aab9200903d91972153962d 100644 (file)
@@ -3369,6 +3369,9 @@ static int compare_super_ddf(struct supertype *st, struct supertype *tst)
         */
        struct ddf_super *first = st->sb;
        struct ddf_super *second = tst->sb;
+       struct dl *dl2;
+       struct vcl *vl2;
+       unsigned int max_vds, max_pds, pd, vd;
 
        if (!first) {
                st->sb = tst->sb;
@@ -3379,7 +3382,46 @@ static int compare_super_ddf(struct supertype *st, struct supertype *tst)
        if (memcmp(first->anchor.guid, second->anchor.guid, DDF_GUID_LEN) != 0)
                return 2;
 
+       if (first->anchor.seq != second->anchor.seq) {
+               dprintf("%s: sequence number mismatch %u/%u\n", __func__,
+                       __be32_to_cpu(first->anchor.seq),
+                       __be32_to_cpu(second->anchor.seq));
+               return 3;
+       }
+       if (first->max_part != second->max_part ||
+           first->phys->used_pdes != second->phys->used_pdes ||
+           first->virt->populated_vdes != second->virt->populated_vdes) {
+               dprintf("%s: PD/VD number mismatch\n", __func__);
+               return 3;
+       }
+
+       max_pds =  __be16_to_cpu(first->phys->used_pdes);
+       for (dl2 = second->dlist; dl2; dl2 = dl2->next) {
+               for (pd = 0; pd < max_pds; pd++)
+                       if (first->phys->entries[pd].refnum == dl2->disk.refnum)
+                               break;
+               if (pd == max_pds) {
+                       dprintf("%s: no match for disk %08x\n", __func__,
+                               __be32_to_cpu(dl2->disk.refnum));
+                       return 3;
+               }
+       }
+
+       max_vds = __be16_to_cpu(first->active->max_vd_entries);
+       for (vl2 = second->conflist; vl2; vl2 = vl2->next) {
+               if (vl2->conf.magic != DDF_VD_CONF_MAGIC)
+                       continue;
+               for (vd = 0; vd < max_vds; vd++)
+                       if (!memcmp(first->virt->entries[vd].guid,
+                                   vl2->conf.guid, DDF_GUID_LEN))
+                               break;
+               if (vd == max_vds) {
+                       dprintf("%s: no match for VD config\n", __func__);
+                       return 3;
+               }
+       }
        /* FIXME should I look at anything else? */
+
        return 0;
 }