From f9f17c1a5e86f5cea8be56075debcc4ac8b1cfbd Mon Sep 17 00:00:00 2001 From: jbjohnso Date: Wed, 19 May 2010 13:54:38 +0000 Subject: [PATCH] -Replace native math for 64 bit timestamp manipulation with bigint git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@6169 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/Utils.pm | 59 ++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/perl-xCAT/xCAT/Utils.pm b/perl-xCAT/xCAT/Utils.pm index 12186cb48..a2261a1d9 100644 --- a/perl-xCAT/xCAT/Utils.pm +++ b/perl-xCAT/xCAT/Utils.pm @@ -69,31 +69,40 @@ sub genUUID #two identical UUIDs is 4 in 10 octillion. my %args = @_; if ($args{mac}) { #if a mac address was supplied, generate a uuidv1 instead - use Config; - if ($Config{use64bitint}) { #do it the simple way - no warnings 'portable'; - use Time::HiRes qw/gettimeofday/; - my $sec; - my $usec; - ($sec,$usec) = gettimeofday(); - my $uuidtime=($sec*10000000)+($usec*10) + 0x01B21DD213814000; - my $timelow=$uuidtime&0xffffffff;# get lower 32bit - my $timemid=$uuidtime&0xffff00000000; - my $timehigh=$uuidtime&0xffff000000000000; - $timemid = $timemid>>32; - $timehigh=$timehigh>>48; - $timehigh = $timehigh | (1<<12); #add in version, don't bother stripping out the high bits since by the year 5236, none of this should matter - my $clockseq=rand(8191); #leave the top three bits alone. We could leave just top two bits, but it's unneeded - #also, randomness matters very little, as the time+mac is here - $clockseq = $clockseq | 0x8000; #RFC4122 variant - #time to assemble... - my $uuid=sprintf("%08x-%04x-%04x-%04x-",$timelow,$timemid,$timehigh,$clockseq); - my $mac = $args{mac}; - $mac =~ s/://g; - $mac = lc($mac); - $uuid .= $mac; - return $uuid; - } + use Math::BigInt; + no warnings 'portable'; + use Time::HiRes qw/gettimeofday/; + my $sec; + my $usec; + ($sec,$usec) = gettimeofday(); + my $uuidtime = Math::BigInt->new($sec); + $uuidtime->bmuladd('10000000',$usec*10); + $uuidtime->badd('0x01B21DD213814000'); + my $timelow=$uuidtime->copy(); + $timelow.band('0xffffffff');# get lower 32bit + my $timemid=$uuidtime->copy(); + $timemid.band('0xffff00000000'); + my $timehigh=$uuidtime->copy(); + $timehigh.band('0xffff000000000000'); + $timemid.brsft(32); + $timehigh.brsft(48); + $timehigh.bior('0x1000'); #add in version, don't bother stripping out the high bits since by the year 5236, none of this should matter + my $clockseq=rand(8191); #leave the top three bits alone. We could leave just top two bits, but it's unneeded + #also, randomness matters very little, as the time+mac is here + $clockseq = $clockseq | 0x8000; #RFC4122 variant + #time to assemble... + $timelow = $timelow->bstr(); + $timelow == 0; # doing numeric comparison induces perl to 'int'-ify it. Safe at this point as the subpieces are all sub-32 bit now + $timemid = $timemid->bstr(); + $timemid == 0; + $timehigh = $timehigh->bstr() + $timehigh == 0; + my $uuid=sprintf("%08x-%04x-%04x-%04x-",$timelow,$timemid,$timehigh,$clockseq); + my $mac = $args{mac}; + $mac =~ s/://g; + $mac = lc($mac); + $uuid .= $mac; + return $uuid; } srand(); #Many note this as bad practice, however, forks are going on.. my $uuid;