| Summary: | gpart(8) -a alignment silently overrides -b beginning option | ||||||
|---|---|---|---|---|---|---|---|
| Product: | Base System | Reporter: | Warren Block <wblock> | ||||
| Component: | bin | Assignee: | Andrey V. Elsukov <ae> | ||||
| Status: | Closed FIXED | ||||||
| Severity: | Affects Only Me | ||||||
| Priority: | Normal | ||||||
| Version: | Unspecified | ||||||
| Hardware: | Any | ||||||
| OS: | Any | ||||||
| Attachments: |
|
||||||
Responsible Changed From-To: freebsd-bugs->eadler I'll take it. 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
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
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. >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
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
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 over to committer State Changed From-To: open->patched Patched in head/. State Changed From-To: patched->closed Merged to stable/8 and stable/9. Thanks! |
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. Fix: If a -b value is given, compare it to the alignment value. Use if it matches the alignment, otherwise error out. 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.