Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 8 Feb 2017 08:37:44 +0000 (UTC)
From:      Ravi Pokala <rpokala@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r313433 - stable/10/usr.sbin/bsdinstall/partedit
Message-ID:  <201702080837.v188bir1055373@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: rpokala
Date: Wed Feb  8 08:37:43 2017
New Revision: 313433
URL: https://svnweb.freebsd.org/changeset/base/313433

Log:
  MFC r304142: ensure stripe size is non-zero multiple of 4096
  
  Ensure that the sector size is a multiple of 4096 to avoid creating
  unaligned partitions when the actual sector size is hidden from us.
  
  NOTE: This change was MFCed to stable/11 months ago as as r304448; I'm just
  MFCing it back one more stream.

Modified:
  stable/10/usr.sbin/bsdinstall/partedit/gpart_ops.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/usr.sbin/bsdinstall/partedit/gpart_ops.c
==============================================================================
--- stable/10/usr.sbin/bsdinstall/partedit/gpart_ops.c	Wed Feb  8 08:35:05 2017	(r313432)
+++ stable/10/usr.sbin/bsdinstall/partedit/gpart_ops.c	Wed Feb  8 08:37:43 2017	(r313433)
@@ -795,6 +795,7 @@ gpart_max_free(struct ggeom *geom, intma
 {
 	struct gconfig *gc;
 	struct gprovider *pp, **providers;
+	intmax_t sectorsize, stripesize, offset;
 	intmax_t lastend;
 	intmax_t start, end;
 	intmax_t maxsize, maxstart;
@@ -845,12 +846,25 @@ gpart_max_free(struct ggeom *geom, intma
 
 	pp = LIST_FIRST(&geom->lg_consumer)->lg_provider;
 
-	/* Compute beginning of new partition and maximum available space */
-	if (pp->lg_stripesize > 0 &&
-	    (maxstart*pp->lg_sectorsize % pp->lg_stripesize) != 0) {
-		intmax_t offset = (pp->lg_stripesize -
-		    ((maxstart*pp->lg_sectorsize) % pp->lg_stripesize)) /
-		    pp->lg_sectorsize;
+	/*
+	 * Round the start and size of the largest available space up to
+	 * the nearest multiple of the adjusted stripe size.
+	 *
+	 * The adjusted stripe size is the least common multiple of the
+	 * actual stripe size, or the sector size if no stripe size was
+	 * reported, and 4096.  The reason for this is that contemporary
+	 * disks often have 4096-byte physical sectors but report 512
+	 * bytes instead for compatibility with older / broken operating
+	 * systems and BIOSes.  For the same reasons, virtualized storage
+	 * may also report a 512-byte stripe size, or none at all.
+	 */
+	sectorsize = pp->lg_sectorsize;
+	if ((stripesize = pp->lg_stripesize) == 0)
+		stripesize = sectorsize;
+	while (stripesize % 4096 != 0)
+		stripesize *= 2;
+	if ((offset = maxstart * sectorsize % stripesize) != 0) {
+		offset = (stripesize - offset) / sectorsize;
 		maxstart += offset;
 		maxsize -= offset;
 	}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201702080837.v188bir1055373>