Patchwork [V2,1/1] image_types.bbclass: Round up ROOTFS_SIZE after base_size check

login
register
mail settings
Submitter Andrei Gherzan
Date Sept. 12, 2012, 8:10 p.m.
Message ID <09795cfdec0b03e3c5e03b8bef431de0adad71e5.1347480378.git.andrei@gherzan.ro>
Download mbox | patch
Permalink /patch/36433/
State New
Headers show

Comments

Andrei Gherzan - Sept. 12, 2012, 8:10 p.m.
If we round up ROOTFS_SIZE to IMAGE_ROOTFS_ALIGNMENT before checking if
base_size is greater then IMAGE_ROOTFS_SIZE, we can end up adding an
unaligned value to IMAGE_ROOTFS_SIZE. Obviously, if
IMAGE_ROOTFS_EXTRA_SPACE was overwritten with an unaligned value. So
let's add the round up code after the base_size calculus and it's
comparison.

Signed-off-by: Andrei Gherzan <andrei@gherzan.ro>
---
 meta/classes/image_types.bbclass |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
Saul Wold - Sept. 12, 2012, 8:42 p.m.
On 09/12/2012 01:10 PM, Andrei Gherzan wrote:
> If we round up ROOTFS_SIZE to IMAGE_ROOTFS_ALIGNMENT before checking if
> base_size is greater then IMAGE_ROOTFS_SIZE, we can end up adding an
> unaligned value to IMAGE_ROOTFS_SIZE. Obviously, if
> IMAGE_ROOTFS_EXTRA_SPACE was overwritten with an unaligned value. So
> let's add the round up code after the base_size calculus and it's
> comparison.
>
> Signed-off-by: Andrei Gherzan <andrei@gherzan.ro>
> ---
>   meta/classes/image_types.bbclass |    7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/meta/classes/image_types.bbclass b/meta/classes/image_types.bbclass
> index d286eea..6c01b21 100644
> --- a/meta/classes/image_types.bbclass
> +++ b/meta/classes/image_types.bbclass
> @@ -82,9 +82,12 @@ runimagecmd () {
>   	# The base_size gets calculated:
>   	#  - initial size determined by `du -ks` of the IMAGE_ROOTFS
>   	#  - then multiplied by the IMAGE_OVERHEAD_FACTOR
> -	#  - then rounded up to IMAGE_ROOTFS_ALIGNMENT
>   	#  - finally tested against IMAGE_ROOTFS_SIZE
> -	ROOTFS_SIZE=`du -ks ${IMAGE_ROOTFS}|awk '{base_size = $1 * ${IMAGE_OVERHEAD_FACTOR} + ${IMAGE_ROOTFS_ALIGNMENT} - 1; base_size -= base_size % ${IMAGE_ROOTFS_ALIGNMENT}; print ((base_size > ${IMAGE_ROOTFS_SIZE} ? base_size : ${IMAGE_ROOTFS_SIZE}) + ${IMAGE_ROOTFS_EXTRA_SPACE}) }'`
> +	ROOTFS_SIZE=`du -ks ${IMAGE_ROOTFS}|awk '{base_size = $1 * ${IMAGE_OVERHEAD_FACTOR}; print ((base_size > ${IMAGE_ROOTFS_SIZE} ? base_size : ${IMAGE_ROOTFS_SIZE}) + ${IMAGE_ROOTFS_EXTRA_SPACE}) }'`
> +
> +	# Round up ROOTFS_SIZE to IMAGE_ROOTFS_ALIGNMENT
> +	ROOTFS_SIZE=`awk "BEGIN { rootfs_size = $ROOTFS_SIZE + ${IMAGE_ROOTFS_ALIGNMENT} - 1; rootfs_size -= rootfs_size % ${IMAGE_ROOTFS_ALIGNMENT}; print rootfs_size }"`
> +


AWK seems a little heavy weight here, now we are forking it twice, since 
we are already in awk above, can you not just continue the function from 
there instead, maybe with a END{} or something else?

Also will this guarantee an Integer result?
>   	${cmd}
>   	# Now create the needed compressed versions
>   	cd ${DEPLOY_DIR_IMAGE}/
>
Andrei Gherzan - Sept. 12, 2012, 10:45 p.m.
On Wed, Sep 12, 2012 at 11:42 PM, Saul Wold <sgw@linux.intel.com> wrote:

> On 09/12/2012 01:10 PM, Andrei Gherzan wrote:
>
>> If we round up ROOTFS_SIZE to IMAGE_ROOTFS_ALIGNMENT before checking if
>> base_size is greater then IMAGE_ROOTFS_SIZE, we can end up adding an
>> unaligned value to IMAGE_ROOTFS_SIZE. Obviously, if
>> IMAGE_ROOTFS_EXTRA_SPACE was overwritten with an unaligned value. So
>> let's add the round up code after the base_size calculus and it's
>> comparison.
>>
>> Signed-off-by: Andrei Gherzan <andrei@gherzan.ro>
>> ---
>>   meta/classes/image_types.**bbclass |    7 +++++--
>>   1 file changed, 5 insertions(+), 2 deletions(-)
>>
>> diff --git a/meta/classes/image_types.**bbclass
>> b/meta/classes/image_types.**bbclass
>> index d286eea..6c01b21 100644
>> --- a/meta/classes/image_types.**bbclass
>> +++ b/meta/classes/image_types.**bbclass
>> @@ -82,9 +82,12 @@ runimagecmd () {
>>         # The base_size gets calculated:
>>         #  - initial size determined by `du -ks` of the IMAGE_ROOTFS
>>         #  - then multiplied by the IMAGE_OVERHEAD_FACTOR
>> -       #  - then rounded up to IMAGE_ROOTFS_ALIGNMENT
>>         #  - finally tested against IMAGE_ROOTFS_SIZE
>> -       ROOTFS_SIZE=`du -ks ${IMAGE_ROOTFS}|awk '{base_size = $1 *
>> ${IMAGE_OVERHEAD_FACTOR} + ${IMAGE_ROOTFS_ALIGNMENT} - 1; base_size -=
>> base_size % ${IMAGE_ROOTFS_ALIGNMENT}; print ((base_size >
>> ${IMAGE_ROOTFS_SIZE} ? base_size : ${IMAGE_ROOTFS_SIZE}) +
>> ${IMAGE_ROOTFS_EXTRA_SPACE}) }'`
>> +       ROOTFS_SIZE=`du -ks ${IMAGE_ROOTFS}|awk '{base_size = $1 *
>> ${IMAGE_OVERHEAD_FACTOR}; print ((base_size > ${IMAGE_ROOTFS_SIZE} ?
>> base_size : ${IMAGE_ROOTFS_SIZE}) + ${IMAGE_ROOTFS_EXTRA_SPACE}) }'`
>> +
>> +       # Round up ROOTFS_SIZE to IMAGE_ROOTFS_ALIGNMENT
>> +       ROOTFS_SIZE=`awk "BEGIN { rootfs_size = $ROOTFS_SIZE +
>> ${IMAGE_ROOTFS_ALIGNMENT} - 1; rootfs_size -= rootfs_size %
>> ${IMAGE_ROOTFS_ALIGNMENT}; print rootfs_size }"`
>> +
>>
>
>
> AWK seems a little heavy weight here, now we are forking it twice, since
> we are already in awk above, can you not just continue the function from
> there instead, maybe with a END{} or something else?
>
> So, to be sure i understood. You want to have the whole routine in the
same awk right? I did it this way to make those steps a little clearer. But
indeed, this is a good idea in terms of performance.

Also will this guarantee an Integer result?
>
Will fix in V3. :)

Branch updated with v3.

ag

Patch

diff --git a/meta/classes/image_types.bbclass b/meta/classes/image_types.bbclass
index d286eea..6c01b21 100644
--- a/meta/classes/image_types.bbclass
+++ b/meta/classes/image_types.bbclass
@@ -82,9 +82,12 @@  runimagecmd () {
 	# The base_size gets calculated:
 	#  - initial size determined by `du -ks` of the IMAGE_ROOTFS
 	#  - then multiplied by the IMAGE_OVERHEAD_FACTOR
-	#  - then rounded up to IMAGE_ROOTFS_ALIGNMENT
 	#  - finally tested against IMAGE_ROOTFS_SIZE
-	ROOTFS_SIZE=`du -ks ${IMAGE_ROOTFS}|awk '{base_size = $1 * ${IMAGE_OVERHEAD_FACTOR} + ${IMAGE_ROOTFS_ALIGNMENT} - 1; base_size -= base_size % ${IMAGE_ROOTFS_ALIGNMENT}; print ((base_size > ${IMAGE_ROOTFS_SIZE} ? base_size : ${IMAGE_ROOTFS_SIZE}) + ${IMAGE_ROOTFS_EXTRA_SPACE}) }'`
+	ROOTFS_SIZE=`du -ks ${IMAGE_ROOTFS}|awk '{base_size = $1 * ${IMAGE_OVERHEAD_FACTOR}; print ((base_size > ${IMAGE_ROOTFS_SIZE} ? base_size : ${IMAGE_ROOTFS_SIZE}) + ${IMAGE_ROOTFS_EXTRA_SPACE}) }'`
+
+	# Round up ROOTFS_SIZE to IMAGE_ROOTFS_ALIGNMENT
+	ROOTFS_SIZE=`awk "BEGIN { rootfs_size = $ROOTFS_SIZE + ${IMAGE_ROOTFS_ALIGNMENT} - 1; rootfs_size -= rootfs_size % ${IMAGE_ROOTFS_ALIGNMENT}; print rootfs_size }"`
+
 	${cmd}
 	# Now create the needed compressed versions
 	cd ${DEPLOY_DIR_IMAGE}/