From 2b2787da49937702dbe7b33c6a915fabc5f0591a Mon Sep 17 00:00:00 2001
From: NeilBrown <neilb@suse.de>
Date: Wed, 28 Mar 2012 17:29:55 +1100
Subject: [PATCH] Add data_offset arg to ->validate_geometry.

This is needed to return correct available size.  It isn't
really used yet.

Signed-off-by: NeilBrown <neilb@suse.de>
---
 Create.c      |   13 +++++++------
 Manage.c      |    2 +-
 mdadm.h       |    1 +
 super-ddf.c   |   12 ++++++++++--
 super-gpt.c   |    1 +
 super-intel.c |   19 +++++++++++++------
 super-mbr.c   |    1 +
 super0.c      |    1 +
 super1.c      |    3 ++-
 9 files changed, 37 insertions(+), 16 deletions(-)

--- mdadm-3.2.6.orig/Create.c
+++ mdadm-3.2.6/Create.c
@@ -263,7 +263,8 @@ int Create(struct supertype *st, char *m
 		size &= ~(unsigned long long)(chunk - 1);
 	newsize = size * 2;
 	if (st && ! st->ss->validate_geometry(st, level, layout, raiddisks,
-					      &chunk, size*2, NULL, &newsize, verbose>=0))
+					      &chunk, size*2, -1LL, NULL,
+					      &newsize, verbose>=0))
 		return 1;
 
 	if (chunk && chunk != UnSet) {
@@ -345,8 +346,8 @@ int Create(struct supertype *st, char *m
 					layout = default_layout(st, level, verbose);
 				switch (st->ss->validate_geometry(
 						st, level, layout, raiddisks,
-						&chunk, size*2, dname, &freesize,
-						verbose > 0)) {
+						&chunk, size*2, -1LL, dname,
+						&freesize, verbose > 0)) {
 				case -1: /* Not valid, message printed, and not
 					  * worth checking any further */
 					exit(2);
@@ -381,8 +382,8 @@ int Create(struct supertype *st, char *m
 				layout = default_layout(st, level, 0);
 			if (!st->ss->validate_geometry(st, level, layout,
 						       raiddisks,
-						       &chunk, size*2, dname,
-						       &freesize,
+						       &chunk, size*2, -1LL,
+						       dname, &freesize,
 						       verbose >= 0)) {
 
 				fprintf(stderr,
@@ -488,7 +489,7 @@ int Create(struct supertype *st, char *m
 			/* size is meaningful */
 			if (!st->ss->validate_geometry(st, level, layout,
 						       raiddisks,
-						       &chunk, minsize*2,
+						       &chunk, minsize*2, -1LL,
 						       NULL, NULL, 0)) {
 				fprintf(stderr, Name ": devices too large for RAID level %d\n", level);
 				return 1;
--- mdadm-3.2.6.orig/Manage.c
+++ mdadm-3.2.6/Manage.c
@@ -721,7 +721,7 @@ int Manage_subdevs(char *devname, int fd
 			if (tst->ss->validate_geometry(
 				    tst, array.level, array.layout,
 				    array.raid_disks, NULL,
-				    ldsize >> 9, NULL, NULL, 0) == 0) {
+				    ldsize >> 9, -1LL, NULL, NULL, 0) == 0) {
 				if (!force) {
 					fprintf(stderr, Name
 						": %s is larger than %s can "
--- mdadm-3.2.6.orig/mdadm.h
+++ mdadm-3.2.6/mdadm.h
@@ -738,6 +738,7 @@ extern struct superswitch {
 	int (*validate_geometry)(struct supertype *st, int level, int layout,
 				 int raiddisks,
 				 int *chunk, unsigned long long size,
+				 long long data_offset,
 				 char *subdev, unsigned long long *freesize,
 				 int verbose);
 
--- mdadm-3.2.6.orig/super-ddf.c
+++ mdadm-3.2.6/super-ddf.c
@@ -2601,18 +2601,21 @@ static int
 validate_geometry_ddf_container(struct supertype *st,
 				int level, int layout, int raiddisks,
 				int chunk, unsigned long long size,
+				long long data_offset,
 				char *dev, unsigned long long *freesize,
 				int verbose);
 
 static int validate_geometry_ddf_bvd(struct supertype *st,
 				     int level, int layout, int raiddisks,
 				     int *chunk, unsigned long long size,
+				     long long data_offset,
 				     char *dev, unsigned long long *freesize,
 				     int verbose);
 
 static int validate_geometry_ddf(struct supertype *st,
 				 int level, int layout, int raiddisks,
 				 int *chunk, unsigned long long size,
+				 long long data_offset,
 				 char *dev, unsigned long long *freesize,
 				 int verbose)
 {
@@ -2635,7 +2638,8 @@ static int validate_geometry_ddf(struct
 		/* Must be a fresh device to add to a container */
 		return validate_geometry_ddf_container(st, level, layout,
 						       raiddisks, chunk?*chunk:0,
-						       size, dev, freesize,
+						       size, data_offset, dev,
+						       freesize,
 						       verbose);
 	}
 
@@ -2672,7 +2676,8 @@ static int validate_geometry_ddf(struct
 		 * Should make a distinction one day.
 		 */
 		return validate_geometry_ddf_bvd(st, level, layout, raiddisks,
-						 chunk, size, dev, freesize,
+						 chunk, size, data_offset, dev,
+						 freesize,
 						 verbose);
 	}
 	/* This is the first device for the array.
@@ -2731,6 +2736,7 @@ static int validate_geometry_ddf(struct
 			close(cfd);
 			return validate_geometry_ddf_bvd(st, level, layout,
 							 raiddisks, chunk, size,
+							 data_offset,
 							 dev, freesize,
 							 verbose);
 		}
@@ -2745,6 +2751,7 @@ static int
 validate_geometry_ddf_container(struct supertype *st,
 				int level, int layout, int raiddisks,
 				int chunk, unsigned long long size,
+				long long data_offset,
 				char *dev, unsigned long long *freesize,
 				int verbose)
 {
@@ -2779,6 +2786,7 @@ validate_geometry_ddf_container(struct s
 static int validate_geometry_ddf_bvd(struct supertype *st,
 				     int level, int layout, int raiddisks,
 				     int *chunk, unsigned long long size,
+				     long long data_offset,
 				     char *dev, unsigned long long *freesize,
 				     int verbose)
 {
--- mdadm-3.2.6.orig/super-gpt.c
+++ mdadm-3.2.6/super-gpt.c
@@ -194,6 +194,7 @@ static struct supertype *match_metadata_
 static int validate_geometry(struct supertype *st, int level,
 			     int layout, int raiddisks,
 			     int *chunk, unsigned long long size,
+			     long long data_offset,
 			     char *subdev, unsigned long long *freesize,
 			     int verbose)
 {
--- mdadm-3.2.6.orig/super-intel.c
+++ mdadm-3.2.6/super-intel.c
@@ -5283,7 +5283,9 @@ static int imsm_bbm_log_size(struct imsm
 #ifndef MDASSEMBLE
 static int validate_geometry_imsm_container(struct supertype *st, int level,
 					    int layout, int raiddisks, int chunk,
-					    unsigned long long size, char *dev,
+					    unsigned long long size,
+					    long long data_offset,
+					    char *dev,
 					    unsigned long long *freesize,
 					    int verbose)
 {
@@ -5353,7 +5355,7 @@ static int validate_geometry_imsm_contai
 		}
 	}
 
-	*freesize = avail_size_imsm(st, ldsize >> 9, -1);
+	*freesize = avail_size_imsm(st, ldsize >> 9, data_offset);
 	free_imsm(super);
 
 	return 1;
@@ -5922,7 +5924,9 @@ validate_geometry_imsm_orom(struct intel
  */
 static int validate_geometry_imsm_volume(struct supertype *st, int level,
 					 int layout, int raiddisks, int *chunk,
-					 unsigned long long size, char *dev,
+					 unsigned long long size,
+					 long long data_offset,
+					 char *dev,
 					 unsigned long long *freesize,
 					 int verbose)
 {
@@ -6205,6 +6209,7 @@ static int reserve_space(struct supertyp
 
 static int validate_geometry_imsm(struct supertype *st, int level, int layout,
 				  int raiddisks, int *chunk, unsigned long long size,
+				  long long data_offset,
 				  char *dev, unsigned long long *freesize,
 				  int verbose)
 {
@@ -6220,7 +6225,8 @@ static int validate_geometry_imsm(struct
 		/* Must be a fresh device to add to a container */
 		return validate_geometry_imsm_container(st, level, layout,
 							raiddisks,
-							chunk?*chunk:0, size,
+							chunk?*chunk:0,
+							size, data_offset,
 							dev, freesize,
 							verbose);
 	}
@@ -6263,6 +6269,7 @@ static int validate_geometry_imsm(struct
 		/* creating in a given container */
 		return validate_geometry_imsm_volume(st, level, layout,
 						     raiddisks, chunk, size,
+						     data_offset,
 						     dev, freesize, verbose);
 	}
 
@@ -6308,7 +6315,7 @@ static int validate_geometry_imsm(struct
 			close(cfd);
 			return validate_geometry_imsm_volume(st, level, layout,
 							     raiddisks, chunk,
-							     size, dev,
+							     size, data_offset, dev,
 							     freesize, 1)
 				? 1 : -1;
 		}
@@ -10052,7 +10059,7 @@ enum imsm_reshape_type imsm_analyze_chan
 				    imsm_layout,
 				    geo->raid_disks + devNumChange,
 				    &chunk,
-				    geo->size,
+				    geo->size, -1LL,
 				    0, 0, 1))
 		change = -1;
 
--- mdadm-3.2.6.orig/super-mbr.c
+++ mdadm-3.2.6/super-mbr.c
@@ -185,6 +185,7 @@ static struct supertype *match_metadata_
 static int validate_geometry(struct supertype *st, int level,
 			     int layout, int raiddisks,
 			     int *chunk, unsigned long long size,
+			     long long data_offset,
 			     char *subdev, unsigned long long *freesize,
 			     int verbose)
 {
--- mdadm-3.2.6.orig/super0.c
+++ mdadm-3.2.6/super0.c
@@ -1131,6 +1131,7 @@ static void free_super0(struct supertype
 static int validate_geometry0(struct supertype *st, int level,
 			      int layout, int raiddisks,
 			      int *chunk, unsigned long long size,
+			      long long data_offset,
 			      char *subdev, unsigned long long *freesize,
 			      int verbose)
 {
--- mdadm-3.2.6.orig/super1.c
+++ mdadm-3.2.6/super1.c
@@ -1788,6 +1788,7 @@ static void free_super1(struct supertype
 static int validate_geometry1(struct supertype *st, int level,
 			      int layout, int raiddisks,
 			      int *chunk, unsigned long long size,
+			      long long data_offset,
 			      char *subdev, unsigned long long *freesize,
 			      int verbose)
 {
@@ -1819,7 +1820,7 @@ static int validate_geometry1(struct sup
 	}
 	close(fd);
 
-	*freesize = avail_size1(st, ldsize >> 9, -1);
+	*freesize = avail_size1(st, ldsize >> 9, data_offset);
 	return 1;
 }
 #endif /* MDASSEMBLE */
