From ecbd9e8160e9de9cc28ad869d303506b1dc69715 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Wed, 21 Sep 2011 14:39:01 +1000 Subject: [PATCH] Create: improve messages from validate_geometry. When validate_geometry finds that we haven't committed to a metadata yet and that the subdev is a member of 'our' container, it needs to report any errors it finds as Create() cannot report them effectively. So make a slight change to the semantics of the 'verbose' flag and allow validate_geometry to report if it printed any error messages. Signed-off-by: NeilBrown --- Create.c | 18 ++++++++++++++---- mdadm.h | 6 ++++++ super-intel.c | 3 ++- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Create.c b/Create.c index 8d88aa1..79564c5 100644 --- a/Create.c +++ b/Create.c @@ -332,15 +332,25 @@ int Create(struct supertype *st, char *mddev, char *name = "default"; for(i=0; !st && superlist[i]; i++) { st = superlist[i]->match_metadata_desc(name); + if (!st) + continue; if (do_default_layout) layout = default_layout(st, level, verbose); - if (st && !st->ss->validate_geometry - (st, level, layout, raiddisks, - &chunk, size*2, dname, &freesize, - verbose > 0)) { + switch (st->ss->validate_geometry( + st, level, layout, raiddisks, + &chunk, size*2, dname, &freesize, + verbose > 0)) { + case -1: /* Not valid, message printed, and not + * worth checking any further */ + exit(2); + break; + case 0: /* Geometry not valid */ free(st); st = NULL; chunk = do_default_chunk ? UnSet : chunk; + break; + case 1: /* All happy */ + break; } } diff --git a/mdadm.h b/mdadm.h index bd3063b..8dd37d9 100644 --- a/mdadm.h +++ b/mdadm.h @@ -702,6 +702,12 @@ extern struct superswitch { * inter-device dependencies, it should record sufficient details * so these can be validated. * Both 'size' and '*freesize' are in sectors. chunk is KiB. + * Return value is: + * 1: everything is OK + * 0: not OK for some reason - if 'verbose', then error was reported. + * -1: st->sb was NULL, 'subdev' is a member of a container of this + * types, but array is not acceptable for some reason + * message was reported even if verbose is 0. */ int (*validate_geometry)(struct supertype *st, int level, int layout, int raiddisks, diff --git a/super-intel.c b/super-intel.c index e57d18f..e9d9af8 100644 --- a/super-intel.c +++ b/super-intel.c @@ -5369,7 +5369,8 @@ static int validate_geometry_imsm(struct supertype *st, int level, int layout, return validate_geometry_imsm_volume(st, level, layout, raiddisks, chunk, size, dev, - freesize, verbose); + freesize, 1) + ? 1 : -1; } }