]> sourceware.org Git - lvm2.git/commitdiff
lvmetad: Check integrity of multiple metadata copies, i.e. ensure that seqno
authorPetr Rockai <prokai@redhat.com>
Mon, 25 Jul 2011 15:51:51 +0000 (15:51 +0000)
committerPetr Rockai <prokai@redhat.com>
Mon, 25 Jul 2011 15:51:51 +0000 (15:51 +0000)
equality implies metadata equality. Signal error in response to any update
requests that try to overwrite metadata without providing a higher seqno.

daemons/lvmetad/lvmetad-core.c

index 04f517dd1db811d2967a1853c96c9cc3bcdfc1ed..4dfb0a2770fa6809093ef0f575459071931f1c85 100644 (file)
@@ -95,6 +95,54 @@ static response vg_by_uuid(lvmetad_state *s, request r)
        return res;
 }
 
+/*
+ * TODO: Accept different flag permutations? Or else, ensure fixed ordering of
+ * flags in set_flag below (following the same order as we have in
+ * lib/format_text/flags.c).
+ */
+static int compare_value(struct config_value *a, struct config_value *b)
+{
+       if (a->type > b->type)
+               return 1;
+       if (a->type < b->type)
+               return -1;
+
+       switch (a->type) {
+       case CFG_STRING: return strcmp(a->v.str, b->v.str);
+       case CFG_FLOAT: return a->v.r == b->v.r;
+       case CFG_INT: return a->v.i == b->v.i;
+       case CFG_EMPTY_ARRAY: return 0;
+       }
+
+       if (a->next && b->next)
+               return compare_value(a->next, b->next);
+}
+
+static int compare_config(struct config_node *a, struct config_node *b)
+{
+       int result = 0;
+       if (a->v && b->v)
+               result = compare_value(a->v, b->v);
+       if (a->v && !b->v)
+               result = 1;
+       if (!a->v && b->v)
+               result = -1;
+       if (a->child && b->child)
+               result = compare_config(a->child, b->child);
+
+       if (result)
+               return result;
+
+       if (a->sib && b->sib)
+               result = compare_config(a->sib, b->sib);
+       if (a->sib && !b->sib)
+               result = 1;
+       if (!a->sib && b->sib)
+               result = -1;
+
+       return result;
+}
+
 /*
  * TODO: This set_flag function is pretty generic and might make sense in a
  * library here or there.
@@ -212,8 +260,10 @@ static int update_metadata(lvmetad_state *s, const char *_vgid, struct config_no
                goto out;
 
        if (seq == haveseq) {
-               // TODO: compare old->root with metadata to ensure equality
                retval = 1;
+               // TODO: disregard the MISSING_PV flag status in this comparison
+               if (compare_config(metadata, old->root))
+                       retval = 0;
                goto out;
        }
 
This page took 0.04017 seconds and 5 git commands to generate.