[Pacemaker] SysInfo_mem_units()

Andrew Beekhof andrew at beekhof.net
Wed Jul 7 05:16:21 EDT 2010


On Wed, Jul 7, 2010 at 8:53 AM, Simon Horman <horms at verge.net.au> wrote:
> On Wed, Jul 07, 2010 at 08:27:17AM +0200, Andrew Beekhof wrote:
>> On Wed, Jul 7, 2010 at 6:17 AM, Simon Horman <horms at verge.net.au> wrote:
>> > Hi,
>> >
>> > I am currently pondering the SysInfo_mem_units() function
>> > of sources/SysInfo (with a view to turning it into awk to
>> > avoid bashisms[1]).
>> >
>> > Basically the function seems to look at the unit of the input,
>> > leave it as if if the unit is G, divide it by 1024 if its M[bB]?
>> > or divide it by 1024^2 if the unit is k[B]?. It then does some rounding.
>> >
>> > On the unit handling side of things I am puzzled by the following code,
>> > particularly the inner if [ $mem != ${mem/./} ] portion. It seems to
>> > handle the x.yG case. But the logic seems to lead to the following result:
>> >
>> > xG => x
>> > x.yG => 1024x + w*y
>> >
>> > Surely the latter should be x.yG => x + (w*y/1024).
>> > Also, surely this logic also applies equally to other units.
>
> Can you comment on this?

Oh I probably just messed up. In any case, your awk version wont have
this problem.

>
>> >
>> >    if [ ${mem:$memlen:1} = "G" ]; then
>> >        mem="${mem:0:$memlen}"
>> >        if [ $mem != ${mem/./} ]; then
>> >            mem_before=${mem/.*/}
>> >            mem_after=${mem/*./}
>> >            mem=$[mem_before*1024]
>> >            if [ ${#mem_after} = 0 ]; then
>> >                :
>> >            elif [ ${#mem_after} = 1 ]; then
>> >                mem=$[mem+100*$mem_after]
>> >            elif [ ${#mem_after} = 2 ]; then
>> >                mem=$[mem+10*$mem_after]
>> >            elif [ ${#mem_after} = 3 ]; then
>> >                mem=$[mem+$mem_after]
>> >            else
>> >                mem_after=${mem_after:0:3}
>> >                mem=$[mem+$mem_after]
>> >            fi
>> >        fi
>> >    elif [ ${mem:$memlen:1} = "M" ]; then
>> >
>> >
>> > [1] I also struggle to care about this bashism crusade. But its
>>
>> yeah, me too. but it also means that when people send patches I don't
>> care enough to argue against them.
>>
>> >    something that Debian has decided matters, so I'm doing
>> >    this with my debian-ha-maintainer member hat on.
>> >
>> >    The following hunk illustrates how I think SysInfo_hdd_units() can
>> >    be handled. The awk version seems rather nicer or at least rather
>> >    shorter than the original.
>>
>> agreed.  do you have a tree i can pull this from?
>> that or can you resend as a hg export so you can get the proper attribution :-)
>
> I was planning to send it as part of a larger patch (a bit later).
> But I can send it by itself (sooner) if you prefer.

No hurry, whenever you're ready :-)




More information about the Pacemaker mailing list