]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Assemble: factor out ident_matches
authorNeilBrown <neilb@suse.de>
Mon, 22 Nov 2010 09:58:05 +0000 (20:58 +1100)
committerNeilBrown <neilb@suse.de>
Mon, 22 Nov 2010 09:58:05 +0000 (20:58 +1100)
This will help future patch, and we need to make "Assemble()" smaller
anyway.

Signed-off-by: NeilBrown <neilb@suse.de>
Assemble.c

index 6382fff0a54c588d36253e7210395906a3113f12..f39aaace7688a08a7889899a079f99962a6c5c5f 100644 (file)
@@ -70,6 +70,52 @@ static int is_member_busy(char *metadata_version)
        return busy;
 }
 
+static int ident_matches(struct mddev_ident_s *ident,
+                        struct mdinfo *content,
+                        struct supertype *tst,
+                        char *homehost,
+                        char *update, char *devname)
+{
+
+       if (ident->uuid_set && (!update || strcmp(update, "uuid")!= 0) &&
+           same_uuid(content->uuid, ident->uuid, tst->ss->swapuuid)==0) {
+               if (devname)
+                       fprintf(stderr, Name ": %s has wrong uuid.\n",
+                               devname);
+               return 0;
+       }
+       if (ident->name[0] && (!update || strcmp(update, "name")!= 0) &&
+           name_matches(content->name, ident->name, homehost)==0) {
+               if (devname)
+                       fprintf(stderr, Name ": %s has wrong name.\n",
+                               devname);
+               return 0;
+       }
+       if (ident->super_minor != UnSet &&
+           ident->super_minor != content->array.md_minor) {
+               if (devname)
+                       fprintf(stderr, Name ": %s has wrong super-minor.\n",
+                               devname);
+               return 0;
+       }
+       if (ident->level != UnSet &&
+           ident->level != content->array.level) {
+               if (devname)
+                       fprintf(stderr, Name ": %s has wrong raid level.\n",
+                               devname);
+               return 0;
+       }
+       if (ident->raid_disks != UnSet &&
+           ident->raid_disks!= content->array.raid_disks) {
+               if (devname)
+                       fprintf(stderr, Name ": %s requires wrong number of drives.\n",
+                               devname);
+               return 0;
+       }
+       return 1;
+}
+                        
+
 int Assemble(struct supertype *st, char *mddev,
             mddev_ident_t ident,
             mddev_dev_t devlist, char *backup_file,
@@ -365,41 +411,10 @@ int Assemble(struct supertype *st, char *mddev,
                        goto loop;
                }
 
-               if (ident->uuid_set && (!update || strcmp(update, "uuid")!= 0) &&
-                   same_uuid(content->uuid, ident->uuid, tst->ss->swapuuid)==0) {
-                       if (report_missmatch)
-                               fprintf(stderr, Name ": %s has wrong uuid.\n",
-                                       devname);
-                       goto loop;
-               }
-               if (ident->name[0] && (!update || strcmp(update, "name")!= 0) &&
-                    name_matches(content->name, ident->name, homehost)==0) {
-                       if (report_missmatch)
-                               fprintf(stderr, Name ": %s has wrong name.\n",
-                                       devname);
-                       goto loop;
-               }
-               if (ident->super_minor != UnSet &&
-                   ident->super_minor != content->array.md_minor) {
-                       if (report_missmatch)
-                               fprintf(stderr, Name ": %s has wrong super-minor.\n",
-                                       devname);
+               if (!ident_matches(ident, content, tst,
+                                  homehost, update,
+                                  report_missmatch ? devname : NULL))
                        goto loop;
-               }
-               if (ident->level != UnSet &&
-                   ident->level != content->array.level) {
-                       if (report_missmatch)
-                               fprintf(stderr, Name ": %s has wrong raid level.\n",
-                                       devname);
-                       goto loop;
-               }
-               if (ident->raid_disks != UnSet &&
-                   ident->raid_disks!= content->array.raid_disks) {
-                       if (report_missmatch)
-                               fprintf(stderr, Name ": %s requires wrong number of drives.\n",
-                                       devname);
-                       goto loop;
-               }
 
                if (tst->ss->container_content
                    && tst->loaded_container) {