From nobody@FreeBSD.org  Thu May  3 21:47:44 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 55260106566B
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  3 May 2012 21:47:44 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 3FF398FC0C
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  3 May 2012 21:47:44 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id q43Llhj0050960
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 3 May 2012 21:47:43 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id q43LlhWj050959;
	Thu, 3 May 2012 21:47:43 GMT
	(envelope-from nobody)
Message-Id: <201205032147.q43LlhWj050959@red.freebsd.org>
Date: Thu, 3 May 2012 21:47:43 GMT
From: Warren Block <wblock@wonkity.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: gpart(8) -a alignment silently overrides -b beginning option
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         167567
>Category:       bin
>Synopsis:       gpart(8) -a alignment silently overrides -b beginning option
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    ae
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu May 03 21:50:05 UTC 2012
>Closed-Date:    Fri May 11 04:06:04 UTC 2012
>Last-Modified:  Fri May 11 04:06:04 UTC 2012
>Originator:     Warren Block
>Release:        9-STABLE
>Organization:
>Environment:
FreeBSD lightning 9.0-STABLE FreeBSD 9.0-STABLE #0 r234953: Thu May  3 09:21:21 MDT 2012     root@lightning:/usr/obj/usr/src/sys/LIGHTNING  amd64
>Description:
When both the -a and -b options are given, -a overrides the value given by -b.

gpart add -t freebsd-ufs -a4k -b1m -s2g ada0

adds a partition that starts at the next available even multiple of 4k rather than at 1M.  If the -b value is an even multiple of the -a value, it should be used.  Otherwise, an error should be shown.
>How-To-Repeat:
gpart create -s gpt ada0
gpart add -t freebsd-boot -a4k -s512k ada0
gpart add -t freebsd-ufs -a4k -b1m -s2g ada0
gpart show ada0
=>      34  42680253  ada0  GPT  (20G)
        34         6        - free -  (3.0k)
        40      1024     1  freebsd-boot  (512k)
      1064   4194304     2  freebsd-ufs  (2.0G)
   4195368  38484919        - free -  (18G)

The freebsd-ufs partition should start at 2048, or 1M.
>Fix:
If a -b value is given, compare it to the alignment value.  Use if it matches the alignment, otherwise error out.

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->eadler 
Responsible-Changed-By: eadler 
Responsible-Changed-When: Fri May 4 00:49:05 UTC 2012 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=167567 

From: "Andrey V. Elsukov" <ae@FreeBSD.org>
To: Warren Block <wblock@wonkity.com>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: bin/167567: gpart(8) -a alignment silently overrides -b beginning
 option
Date: Fri, 04 May 2012 08:24:58 +0400

 On 04.05.2012 1:47, Warren Block wrote:
 >> Description:
 > When both the -a and -b options are given, -a overrides the value given by -b.
 > 
 > gpart add -t freebsd-ufs -a4k -b1m -s2g ada0
 > 
 > adds a partition that starts at the next available even multiple of 4k rather than at 1M.  If the -b value is an even multiple of the -a value, it should be used.  Otherwise, an error should be shown.
 >> How-To-Repeat:
 > gpart create -s gpt ada0
 > gpart add -t freebsd-boot -a4k -s512k ada0
 > gpart add -t freebsd-ufs -a4k -b1m -s2g ada0
 > gpart show ada0
 > =>      34  42680253  ada0  GPT  (20G)
 >         34         6        - free -  (3.0k)
 >         40      1024     1  freebsd-boot  (512k)
 >       1064   4194304     2  freebsd-ufs  (2.0G)
 >    4195368  38484919        - free -  (18G)
 > 
 > The freebsd-ufs partition should start at 2048, or 1M.
 
 You did request to create 4k aligned partition and gpart did it as you requested.
 ada0p2 starts from 1064 sector and it is aligned to 4k. If you want align it to 1m, try this command:
   gpart add -t freebsd-ufs -a1m -b1m -s2g ada0
 
 -- 
 WBR, Andrey V. Elsukov

From: "Andrey V. Elsukov" <ae@FreeBSD.org>
To: Warren Block <wblock@wonkity.com>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: bin/167567: gpart(8) -a alignment silently overrides -b beginning
 option
Date: Fri, 04 May 2012 08:27:40 +0400

 On 04.05.2012 1:47, Warren Block wrote:
 >> Fix:
 > If a -b value is given, compare it to the alignment value.  Use if it matches the alignment,
 > otherwise error out.
 
 If you don't want align your partition - don't use -a option, just use both -b and -s. :)
 
 -- 
 WBR, Andrey V. Elsukov

From: Warren Block <wblock@wonkity.com>
To: "Andrey V. Elsukov" <ae@FreeBSD.org>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: bin/167567: gpart(8) -a alignment silently overrides -b beginning
 option
Date: Fri, 4 May 2012 07:10:28 -0600 (MDT)

 On Fri, 4 May 2012, Andrey V. Elsukov wrote:
 
 > On 04.05.2012 1:47, Warren Block wrote:
 >>> Description:
 >> When both the -a and -b options are given, -a overrides the value given by -b.
 >>
 >> gpart add -t freebsd-ufs -a4k -b1m -s2g ada0
 >>
 >> adds a partition that starts at the next available even multiple of 4k rather than at 1M.  If the -b value is an even multiple of the -a value, it should be used.  Otherwise, an error should be shown.
 >>> How-To-Repeat:
 >> gpart create -s gpt ada0
 >> gpart add -t freebsd-boot -a4k -s512k ada0
 >> gpart add -t freebsd-ufs -a4k -b1m -s2g ada0
 >> gpart show ada0
 >> =>      34  42680253  ada0  GPT  (20G)
 >>         34         6        - free -  (3.0k)
 >>         40      1024     1  freebsd-boot  (512k)
 >>       1064   4194304     2  freebsd-ufs  (2.0G)
 >>    4195368  38484919        - free -  (18G)
 >>
 >> The freebsd-ufs partition should start at 2048, or 1M.
 >
 > You did request to create 4k aligned partition and gpart did it as you requested.
 > ada0p2 starts from 1064 sector and it is aligned to 4k.
 
 The command said "create a 4k aligned partition that begins at 1M", but 
 the second part was ignored.  At least, it could say "-a option given, 
 -b value ignored".  But more useful to the user, and more consistent 
 with the options, would be to use the -b value given if it is an 
 even multiple of the alignment value, or error out if it is not.
 
 > If you want align it to 1m, try this command:
 >  gpart add -t freebsd-ufs -a1m -b1m -s2g ada0
 
 Thank you, that works.  But that does not give the ability to create an 
 aligned partition at an arbitrary (but aligned) starting position.

From: "Andrey V. Elsukov" <bu7cher@yandex.ru>
To: bug-followup@FreeBSD.org, wblock@wonkity.com
Cc:  
Subject: Re: bin/167567: gpart(8) -a alignment silently overrides -b beginning
 option
Date: Fri, 04 May 2012 17:49:30 +0400

 >The command said "create a 4k aligned partition that begins at 1M", but
 >the second part was ignored. At least, it could say "-a option given,
 >-b value ignored".
 
 Man page says:
 -a alignment  If specified, then gpart utility tries to align
               *start offset* and partition *size* to be multiple of
               alignment value.
 
 so i don't think that it does something wrong.
 
 -- 
 WBR, Andrey V. Elsukov

From: "Andrey V. Elsukov" <ae@FreeBSD.org>
To: bug-followup@FreeBSD.org, wblock@wonkity.com
Cc:  
Subject: Re: bin/167567: gpart(8) -a alignment silently overrides -b beginning
 option
Date: Fri, 04 May 2012 18:11:10 +0400

 This is a multi-part message in MIME format.
 --------------000202040801000004000804
 Content-Type: text/plain; charset=KOI8-R
 Content-Transfer-Encoding: 7bit
 
 On 04.05.2012 17:49, Andrey V. Elsukov wrote:
 >> The command said "create a 4k aligned partition that begins at 1M", but
 >> the second part was ignored. At least, it could say "-a option given,
 >> -b value ignored".
 > 
 > Man page says:
 > -a alignment  If specified, then gpart utility tries to align
 >               *start offset* and partition *size* to be multiple of
 >               alignment value.
 > 
 > so i don't think that it does something wrong.
 
 I understood what do you mean. Can you try this patch?
 
 -- 
 WBR, Andrey V. Elsukov
 
 --------------000202040801000004000804
 Content-Type: text/plain;
  name="gpart_align_start.diff"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
  filename="gpart_align_start.diff"
 
 Index: head/sbin/geom/class/part/geom_part.c
 ===================================================================
 --- head/sbin/geom/class/part/geom_part.c	(revision 233835)
 +++ head/sbin/geom/class/part/geom_part.c	(working copy)
 @@ -538,6 +538,8 @@ gpart_autofill(struct gctl_req *req)
  		first = (off_t)strtoimax(s, NULL, 0) + 1;
  		a_first = ALIGNUP(first + offset, alignment);
  	}
 +	if (has_start && a_first < start)
 +		a_first = start;
  	if (a_first <= last) {
  		/* Free space [first-last] */
  		len = ALIGNDOWN(last - a_first + 1, alignment);
 
 --------------000202040801000004000804--

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/167567: commit references a PR
Date: Fri,  4 May 2012 19:49:38 +0000 (UTC)

 Author: ae
 Date: Fri May  4 19:49:24 2012
 New Revision: 235033
 URL: http://svn.freebsd.org/changeset/base/235033
 
 Log:
   Don't ignore start offset value when user specifies it together
   with alignment.
   
   PR:		bin/167567
   Tested by:	Warren Block
   MFC after:	1 week
 
 Modified:
   head/sbin/geom/class/part/geom_part.c
 
 Modified: head/sbin/geom/class/part/geom_part.c
 ==============================================================================
 --- head/sbin/geom/class/part/geom_part.c	Fri May  4 19:44:58 2012	(r235032)
 +++ head/sbin/geom/class/part/geom_part.c	Fri May  4 19:49:24 2012	(r235033)
 @@ -507,6 +507,8 @@ gpart_autofill(struct gctl_req *req)
  	grade = ~0ULL;
  	a_first = ALIGNUP(first + offset, alignment);
  	last = ALIGNDOWN(last + offset, alignment);
 +	if (a_first < start)
 +		a_first = start;
  	while ((pp = find_provider(gp, first)) != NULL) {
  		s = find_provcfg(pp, "start");
  		lba = (off_t)strtoimax(s, NULL, 0);
 @@ -536,7 +538,8 @@ gpart_autofill(struct gctl_req *req)
  
  		s = find_provcfg(pp, "end");
  		first = (off_t)strtoimax(s, NULL, 0) + 1;
 -		a_first = ALIGNUP(first + offset, alignment);
 +		if (first > a_first)
 +			a_first = ALIGNUP(first + offset, alignment);
  	}
  	if (a_first <= last) {
  		/* Free space [first-last] */
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
Responsible-Changed-From-To: eadler->ae 
Responsible-Changed-By: eadler 
Responsible-Changed-When: Fri May 4 21:47:44 UTC 2012 
Responsible-Changed-Why:  
over to committer 

http://www.freebsd.org/cgi/query-pr.cgi?pr=167567 
State-Changed-From-To: open->patched 
State-Changed-By: ae 
State-Changed-When: Sat May 5 08:51:18 UTC 2012 
State-Changed-Why:  
Patched in head/. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=167567 
State-Changed-From-To: patched->closed 
State-Changed-By: ae 
State-Changed-When: Fri May 11 04:05:38 UTC 2012 
State-Changed-Why:  
Merged to stable/8 and stable/9. Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=167567 
>Unformatted:
